import input pgfplots with relative paths

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.


Looking at this pgfplots' feature request, I found this old question. I once stumbled on this problem and found a solution (Unfortunately, I didn't documented where the solution came from, I guess not totally from myself). It's not exactly perfect but works. I define the following macro

\makeatletter
\def\relativepath{\import@path}
\makeatother

And use it every time I use a data file:

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

It's not perfect, I don't like adding the \relativepath macro, It is an import solution and not pgfplots but it does the job.

Edit

My solution dates back at least to this question.