[Tex/LaTex] import input pgfplots with relative paths

filesystem-accessincludepgfplots

The package import makes it posible to \input (and \include) a .tex document which itself \input (or \includegraphics etc.) stuff using relative paths. I was hoping that this also would work with the \addplot file in pgfplots, but it does not. Is there a way to use relative paths in pgfplots?


Failing example: Place main.tex anywhere and edit path to fig.tex. – File fig.tex, input.tex and plot.dat in same directory. I can compile the standalone fig.tex, but main.tex can not find plot.dat.

main.tex

\documentclass{article}
\usepackage{import}
\usepackage{standalone}
\usepackage{pgfplots}
\begin{document}
mainMain
\import{\absolute\path\to\fig.tex}{fig.tex}
\end{document}

fig.tex

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\input{input.tex}  %this is ok
\begin{tikzpicture}
  \begin{axis}
    \addplot file {plot.dat};  %this is not working
  \end{axis}
\end{tikzpicture}
\end{document}

input.tex

anything

plot.dat

1   2

Best Answer

Pgfplots processes input files line-by-line, a requirement which is impossible using \input or \include. Consequently, pgfplots uses \read (a low level TeX macro) for the job.

The requested feature is unsupported by pgfplots and would need to be implemented.

Note that while it is not programmatically supported by pgfplots, you could still modify the TEXINPUTS variable (i.e. the file search path used by TeX globally): this would also allow pgfplots to find your file. This is particularly simple on a unix system (does someone know if miktex also respects this variable?). The main idea here would be to set the environment variable to /your/path:/your/other/path: . Note the final colon (:): it tells TeX to append the system pathes at this location.