16

I would like to use the pgfplots package along with gnuplot. However, I cannot get this to work if I compile using the -output-directory option. For example, if I have the following MWE:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\begin{tikzpicture}
    \begin{axis}
        \addplot gnuplot{x};
    \end{axis}
\end{tikzpicture}

\end{document}

If this is saved as test.tex and I compile with lualatex -shell-escape test.tex, it works fine. However, if I try to change the output directory, such a compiling with lualatex -shell-escape -output-directory=.. test.tex, then pgfplots cannot find the file test.pgf-plot.table which contains the gnuplot output. (The output directory .. was just to make this example as simple as possible.)

Is there a way to patch the command that reads gnuplot output to search for the file in the output directory instead of the current working directory?

  • 2
    Just my view ignore it: I usually avoid -output-directory when using gnuplottex,pstool -shell-escape applications due to foldernames,paths,synctex, etc... – texenthusiast Apr 18 '13 at 04:01
  • 2
    Having the same problem, I've investigated a bit. The call to gnuplot is in the function pgfplotgnuplot in the file tex/generic/pgf/modules/pgfmoduleplot.code.tex. The path of the corresponding files is based on \pgfplots@plot@filename in tex/generic/pgfplots/pgfplotscoordprocessing.code.tex; open questions: (1) how do we find out what -output-directory latex was run with? (2) should we make that directory gnuplot's CWD? – anonymous Nov 15 '13 at 00:13
  • See also pdftex - Access value of -output-directory - TeX - LaTeX Stack Exchange to get the value of -output-directory instead of hard coding it. – user202729 Nov 06 '21 at 02:16

1 Answers1

6

Digging around in the files, mentioned in @anonymous' comment, to find out what to patch, I spotted the following pgf-key. It can simply be overwritten in the preamble of the document.

\usepackage{pgfplots}
\pgfkeys{/pgf/plot/gnuplot call={cd build && gnuplot}}

Here the build directory is called 'build' and can of course be changed at your needs. The command concatenation && should work for Windows and Unix. While being the Unix syntax it works without complaining in Windows (tested).

  • 1
    Apart from hard coding the path like this it's also possible to ■ put the path in an environment variable, see https://tex.stackexchange.com/a/136137/250119 or ■ access value of output-directory, see https://tex.stackexchange.com/q/294931/250119 – user202729 Nov 05 '21 at 05:11