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}
  • I just found out about currfile, but it is not working yet. Maybe someone can give an example for this? – Jost Dec 5 '14 at 15:03
  • You may use \grapicspath form graphics (see p.10 of grfguide.pdf). – Paul Gaborit Dec 5 '14 at 15:05
  • Like adding \graphicspath{pics/} in main.tex? That does not work for me, same error of not finding test.png. – Jost Dec 5 '14 at 15:12
  • The correct syntax is \graphicspath{{./}{pics/}} (it is a list of paths). – Paul Gaborit Dec 5 '14 at 15:45
  • That works nicely. However, what if I want to plot data from a file residing in pics/? – Jost Dec 5 '14 at 16:46
0

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.