使用“-output-directory”和輸入時從 tikz-externalize 取得有效的 makefile

使用“-output-directory”和輸入時從 tikz-externalize 取得有效的 makefile

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執行命令將無法運作;從專案“根”目錄運行它也不起作用,因為那裡沒有。makebuildmwe.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.

相關內容