![`-output-directory` と input を使用するときに tikz-externalize から有効な makefile を取得する](https://rvso.com/image/400384/%60-output-directory%60%20%E3%81%A8%20input%20%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B%E3%81%A8%E3%81%8D%E3%81%AB%20tikz-externalize%20%E3%81%8B%E3%82%89%E6%9C%89%E5%8A%B9%E3%81%AA%20makefile%20%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B.png)
次の mwe は、latexmk
の-output-directory
オプションを使用すると無効な 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}
メイクファイルは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}
新しいメイクファイルを生成する
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
。