![Obtendo um makefile válido do tikz-externalize ao usar `-output-directory` e input](https://rvso.com/image/400384/Obtendo%20um%20makefile%20v%C3%A1lido%20do%20tikz-externalize%20ao%20usar%20%60-output-directory%60%20e%20input.png)
O seguinte mwe produz um makefile inválido quando usado com a opção latexmk
de -output-directory
. (O exemplo é do pgfplots
manual)
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.tex
arquivo não está no build
diretório, executar o make
comando no build
diretório não funcionará; também executá-lo a partir do diretório "raiz" do projeto não funcionará, pois não existe mwe.figlist
lá.
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=./build
do 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 build
diretório com make -f mwe.makefile
.