![使用“-output-directory”和輸入時從 tikz-externalize 取得有效的 makefile](https://rvso.com/image/400384/%E4%BD%BF%E7%94%A8%E2%80%9C-output-directory%E2%80%9D%E5%92%8C%E8%BC%B8%E5%85%A5%E6%99%82%E5%BE%9E%20tikz-externalize%20%E5%8F%96%E5%BE%97%E6%9C%89%E6%95%88%E7%9A%84%20makefile.png)
latexmk
當與's-output-directory
選項一起使用時,以下 mwe 確實會產生無效的 makefile 。 (範例來自pgfplots
手冊)
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}
和下面的一個文件tikz/figure.tikz
\begin{figure}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{Our first external graphics example}
\end{figure}
makefile 位於build/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
由於該mwe.tex
檔案不在該目錄中,因此從該目錄build
執行命令將無法運作;從專案“根”目錄運行它也不起作用,因為那裡沒有。make
build
mwe.figlist
答案1
這個解決方案是一個骯髒的駭客,所以我不會接受它,希望有人提供更好的答案。
我目前的解決方法是修改用於建立 makefile 的命令;這個想法來自這裡並修改指令,包括上移目錄cd .. &&
並設定輸出目錄--output-directory=./build
如下:
\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}
產生新的 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
現在可以從build
目錄中建置make -f mwe.makefile
.