Let's use a small example to use gnuplot to draw a nice function using tikz.

\draw plot[domain=-3:3,samples=100] function {sin(x)} ;

If I compile (using pdflatex or xelatex) it with --shell-escape, no problem.

BUT, if I compile with -ouput-directory=path, with path different from current directory with only the file.tex, it does not work (except if you previously compile it in current directory and keep some intermediate files).

I want to use the gnuplot functions of tikz, and I need to have separate output dir. How can I say to pgf/tikz that it can find the output files of gnuplot in the right directory ?


I realized the problem comes from the file

..../texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex on line 347 :

\immediate\pgfutil@write18{gnuplot \pgf@plotgnuplotfile}%

So it calls gnuplot without taking into account the fact that the file .gnuplot is not in current directory but in output directory. I juste don't know how to specify the output directory in this line. Is there a macro that contains the path of the output directory ?

EDIT 2 : I realized someone asked the same last question in 2011, and did not get a proper answer (only for luatex) on a mailing list. Does it mean there is no standard solution for pdflatex ?

EDIT 3 : I have the same problem with the package minted, so I wonder now if it's possible to use shell-escape commands and output-directory in the same time !

EDIT 4 : I just realized that someone asked the very same question on SE on using-pgfplots-and-gnuplot-and-compiling-with-output-directory and did not get a proper answer as well.

  • How do you compile pgfplots codes which have a gnuplot option? I am a windows user.
    – enthu
    Nov 11 '14 at 21:31
  • @EnthusiasticStudent I'm sorry, I'm not a windows user :)
    – Xoff
    Nov 11 '14 at 21:44

I add this answer to my own question, if someone got the same problem as me, but this is not a good answer, and I will not accept it.

I decided to use an environment variable that contains the output directory. I can retrieve the content of this variable into LaTeX (using this solution for example, but you need to use an absolute path for temporary files for the XeTeX version) and use it to patch the macros (in pgf for example) that need a patch to work with --output-directory.

This is not a good way to do it, but it works.

  • 1
    Assuming i have the path: How to patch what to get it working? Aug 2 '18 at 14:30

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.