pgfplots icon indicating copy to clipboard operation
pgfplots copied to clipboard

search path does not include the path of the figure file

Open nschloe opened this issue 3 years ago • 2 comments

When using

table {data.dat};

the search path for data.dat includes ., the directory of the main TeX file. In many cases, the figure file is itself input from another directory, ./figures/ or so. In this case, one has to add

table [search path=./figures/] {data.dat};

That is unfortunate since now, the figure code depends on where it is included from.

It'd be great if the default search path included the directory of the file from where it was directly included.

nschloe avatar Aug 10 '21 13:08 nschloe

Yes, pgfplots does not search the input path (which should be fixed), but if you use \input LaTeX does not update \input@path and therefore pgfplots can't know from where a figure is input. So you'll need the import package and use

\import{figures/}{plot.tex}

instead of

\input{figures/plot.tex}

hmenke avatar Aug 13 '21 09:08 hmenke

Ad hoc workaround (probably misses corner cases)

\documentclass{article}
\usepackage{pgfplots}
\usepackage{import}
\begin{document}

\makeatletter
\long\def\pgfplotstable@graphicspathtoclist#1{%
  \ifx\relax#1%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {}{,#1\pgfplotstable@graphicspathtoclist}%
}
\expandafter\def\expandafter\pgfplotstable@get@search@path\expandafter{%
  \pgfplotstable@get@search@path
  \edef\pgfplotsretval{%
    \pgfplotsretval% the next line generates a leading comma
    \expandafter\pgfplotstable@graphicspathtoclist\input@path\relax
  }%
}
\makeatother

\import{figures/}{plot.tex}

\end{document}

hmenke avatar Aug 13 '21 10:08 hmenke