1

I have a standalone mytikz.tikz picture which loads test.png. Both reside in the folder pics/. My main.tex, which uses tikzscale to load mytikz.tikz, is in the parent folder. Loading the test.png fails, when compiling main.tex, as the path is wrong. Somehow main.tex needs to know about the pics/ path. How do I achieve this, while still keeping the standalone functionality?

A similar problem arises, if e.g. common color definitions are used, say in pics/mycolors.tex, which are then loaded in mytikz.tikz via \input{mycolors.tex}.

The matter is further complicated, when trying to plot data from a file in pics/. How do I convey the correct path name to main.tex in this case?

Contents of main.tex:

%main.tex \documentclass{book} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{tikzscale} \usepackage{standalone} \begin{document} \begin{figure} \includegraphics[width=\textwidth]{pics/mytikz.tikz} \caption{includegraphics full width} \label{fig:tikz} \end{figure} \end{document} 

Contents of pics/mytikz.tikz:

%mytikz.tikz \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{tikzscale} %\input{mycolors.tex} \begin{document} \begin{tikzpicture} \begin{axis}[ xmin=-1,xmax=1,ymin=-1,ymax=1, ] \addplot graphics [ xmin=0,xmax=1,ymin=0,ymax=1, ] {test.png}; \end{axis} \end{tikzpicture} \end{document} 
5
  • I just found out about currfile, but it is not working yet. Maybe someone can give an example for this? Commented Dec 5, 2014 at 15:03
  • You may use \grapicspath form graphics (see p.10 of grfguide.pdf). Commented Dec 5, 2014 at 15:05
  • Like adding \graphicspath{pics/} in main.tex? That does not work for me, same error of not finding test.png. Commented Dec 5, 2014 at 15:12
  • The correct syntax is \graphicspath{{./}{pics/}} (it is a list of paths). Commented Dec 5, 2014 at 15:45
  • That works nicely. However, what if I want to plot data from a file residing in pics/? Commented Dec 5, 2014 at 16:46

1 Answer 1

1

Manual inclusion of currfile

Simple addition of \usepackage{currfile} at the beginning of main and picture file, as described in currfile's manual does not solve my problem.

I instead opted for manually adding \currfiledir whenever a relative path in some pics\ folder is needed. This retains the advantages of a standalone picture, which can also be compiled from the main file.

There is a problem with common color definitions, which may reside in the parent folder. They have to be included in the standalone picture as well as when compiling the main file. I have solved this by checking for an empty \parentfiledir, in which case the file is loaded as I usually would from the .tikz file.

The result looks like this:

Contents of main.tex:

%main.tex \documentclass{book} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{tikzscale} \usepackage{standalone} \usepackage{currfile} \input{mycolors.tex} \begin{document} \begin{figure} \includegraphics[width=\textwidth]{pics/mytikz.tikz} \caption{includegraphics full width} \label{fig:tikz} \end{figure} \end{document} 

Contents of pics/mytikz.tikz:

%mytikz.tikz \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{tikzscale} \usepackage{currfile} \ifdef{\parentfiledir}{%if }{%else \input{../mycolors.tex}% }% \begin{document} \begin{tikzpicture} \begin{axis}[ xmin=-1,xmax=1,ymin=-1,ymax=1, ] \addplot graphics [ xmin=0,xmax=1,ymin=0,ymax=1, ] {\currfiledir test.png}; \addplot table [x index={0},y index={1}] {\currfiledir data.out}; \end{axis} \end{tikzpicture} \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.