Obtendo um makefile válido do tikz-externalize ao usar `-output-directory` e input

Obtendo um makefile válido do tikz-externalize ao usar `-output-directory` e input

O seguinte mwe produz um makefile inválido quando usado com a opção latexmkde -output-directory. (O exemplo é do pgfplotsmanual)

latexmk mwe.tex -output-directory=build

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize[mode=list and make]

\begin{document}

\input{tikz/figure.tikz}

\end{document}

e um arquivo emtikz/figure.tikz

\begin{figure}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{Our first external graphics example}
\end{figure}

com o makefile estando embuild/mwe.makefile

ALL_FIGURE_NAMES=$(shell cat mwe.figlist)
ALL_FIGURES=$(ALL_FIGURE_NAMES:%=%.pdf)

allimages: $(ALL_FIGURES)
    @echo All images exist now. Use make -B to re-generate them.

FORCEREMAKE:

include $(ALL_FIGURE_NAMES:%=%.dep)

%.dep:
    mkdir -p "$(dir $@)"
    touch "$@" # will be filled later.

mwe-figure0.pdf: 
    pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "mwe-figure0" "\def\tikzexternalrealjob{mwe}\input{mwe}"

mwe-figure0.pdf: mwe-figure0.md5

como o mwe.texarquivo não está no builddiretório, executar o makecomando no builddiretório não funcionará; também executá-lo a partir do diretório "raiz" do projeto não funcionará, pois não existe mwe.figlistlá.

Responder1

Esta solução é um truque sujo, por isso não a aceitarei, esperando que alguém dê uma resposta melhor.

Uma solução alternativa atual é modificar os comandos usados ​​para criar o makefile; essa ideia é deaquie modifique os comandos, incluindo mover para cima um diretóriocd .. &&e definindo o diretório de saída--output-directory=./builddo seguinte modo:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize[mode=list and make]

\tikzset{%
    external/system call={cd .. && pdflatex \tikzexternalcheckshellescape --halt-on-error --interaction=batchmode --output-directory=./build --jobname "\image" "\texsource"},
    /pgf/images/include external/.code={%
        \includegraphics{build/#1}%
    },
}
\begin{document}

\input{tikz/figure.tikz}

\end{document}

gerando o novo makefile


ALL_FIGURE_NAMES=$(shell cat mwe.figlist)
ALL_FIGURES=$(ALL_FIGURE_NAMES:%=%.pdf)

allimages: $(ALL_FIGURES)
        @echo All images exist now. Use make -B to re-generate them.

FORCEREMAKE:

include $(ALL_FIGURE_NAMES:%=%.dep)

%.dep:
        mkdir -p "$(dir $@)"
        touch "$@" # will be filled later.

mwe-figure0.pdf: 
        cd .. && pdflatex -shell-escape --halt-on-error --interaction=batchmode --output-directory=./build --jobname "mwe-figure0" "\def\tikzexternalrealjob{mwe}\input{mwe}"

mwe-figure0.pdf: mwe-figure0.md5

que agora pode ser compilado a partir do builddiretório com make -f mwe.makefile.

informação relacionada