0

Situation

I am compiling a document using the TikZ externalize library, and want to create my output in an output folder /out/, but have the TikZ externalize figures stored in a subfolder /out/figures/. The /out/ folder is specified by passing the -output-directory=[path to main.tex]/out argument to pdfLatex, and the /out/figures/ folder is specified using \tikzexternalize[prefix=out/figures/].

Expected behavior

All externalized files are created in the /out/figures/ folder.

Actual behavior

The figure.md5 file is created in the /out/out/figures/ folder, whereas all other externalized files are created in the /out/figures/ folder.

MWE

Run the following command:

pdflatex -output-directory=[path to main]/out -shell-escape main.tex

where main.tex contains:

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{external}
\tikzexternalize[prefix=out/figures/]

\usepackage[abspath]{currfile}
\getabspath{\jobname.log}

% Avoid having to create these folders manually
\IfFileExists{"\theabsdir out"}{}{\immediate\write18{mkdir "out"}}
\IfFileExists{"\theabsdir out/figures"}{}{\immediate\write18{mkdir "out/figures"}}
\IfFileExists{"\theabsdir out/out"}{}{\immediate\write18{mkdir "out/out"}}
\IfFileExists{"\theabsdir out/out/figures"}{}{\immediate\write18{mkdir "out/out/figures"}}

\begin{document}
\begin{figure}
    \tikzsetnextfilename{figure}
    \begin{tikzpicture}[domain=0:4]
        \draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9);
        \draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
        \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
        \draw[color=red] plot[id=x] function{x}
        node[right] {$f(x) =x$};
    \end{tikzpicture}
\end{figure}
\end{document}

Is there any way to make TikZ externalize create all externalized files in the same folder? Why is the prefix interpreted inconsistently by tikz externalize?

6
  • Related pgfplots - Error using tikz externalize: can't write md5 file - TeX - LaTeX Stack Exchange. It unfortunately only give a workaround to avoid the error, not actually fix the behavior. (although I guess providing absolute path to prefix might fix the issue)
    – user202729
    Jul 24, 2022 at 15:45
  • that is one of the reasons why I never use -output-directory. It gets rather difficult to sort out where you actually are and where files are searched and created. Jul 24, 2022 at 15:48
  • To be fair there are ways to implement the package such that output directory works correctly shell escape - In Luatex, how to know effective output directory? - TeX - LaTeX Stack Exchange , the packages just don't implement it.
    – user202729
    Jul 24, 2022 at 16:08
  • @user202729 you're right that providing an absolute path to prefix is a way to fix it, but getting the absolute path in Latex using currfile does not work great, and hardcoding it is not an option when sharing the Latex code.
    – Anne Poot
    Jul 26, 2022 at 15:37
  • One option is to tell the other people to not use output directory. currfile needs recorder option. As for the "does not work great" part there might be issue with slash/backslash difference & expansion issue; you can ask that instead
    – user202729
    Jul 26, 2022 at 16:17

0

You must log in to answer this question.

Browse other questions tagged .