
我有以下問題:一個包含多個章節的大型乳膠專案project.tex。對於每一章,我都有幾張 tikz 圖片,我想將它們外部化到資料夾 tikz_pdf 中。文件結構相應
home/chapter/chapter1/img/example_1.tikz
home/chapter/chapter1/img/example_2.tikz
home/project.tex
home/tikz_pdf
由於它是一個大項目,我想使用巨集自動外部化:
\includetikz{chapter/chapter1/img/example_1.tikz}
代替
\input{chapter/chapter1/img/example_1.tikz}
為了在 /tikz_pdf 中建立的 pdf 中獲得相同的 tikz 檔名。因此,「chapter/chapter1/img/example1.tikz」的外部化 pdf 應為「home/tikz_pdf/example1.pdf」 為此,我想使用一個可以應用的宏,例如:
\documentclass[12pt,lot, lof]{puthesis}
\usepackage{filemod}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/]
% THIS IS THE MACRO
\makeatletter
\DeclareRobustCommand{\includetikz}[1]{%
\begingroup
\def\textendash{-}%
\includetikz@parse{#1}%
\edef\includetikz@base{\detokenize\expandafter{\includetikz@base}}%
\tikzsetnextfilename{\filename@base}%
\input{#1}%
\endgroup
}
\makeatother
\begin{document}
\begin{figure}
\includetikz{chapter/chapter1/img/example_1.tikz}
\end{figure}
\begin{figure}
\includetikz{chapter/chapter1/img/example_2.tikz}
\end{figure}
\end{document}
然而,到目前為止的問題是,檔案名稱中的底線會導致 \input{#1} 只會導致缺少 $ 的錯誤。我已經嘗試使用 \input{\detokanize{#1}} 但沒有更好的結果。您知道如何解決這個問題嗎?多謝