如何在外部化的 tikz 中传递宏?

如何在外部化的 tikz 中传递宏?

tikzscale当我使用包在外部编译图形时遇到了问题。

最小工作环境如下。

main.tex:

\documentclass[\myopts]{IEEEtran}

\usepackage{lua-visual-debug}
\usepackage{tikzscale}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds,calc,patterns}
\usetikzlibrary{er}
\usepackage{tikz-3dplot}

\usepackage{pgfplots}
\usepackage{currfile}
\usepackage{lmodern}

\usetikzlibrary{shapes}
\usepgflibrary{shapes.geometric}

\usetikzlibrary{external}
\tikzexternalize[prefix=figure-build/]

% Use the package ifpdf to share one test document between pdflatex and latex
\usepackage{ifpdf}

\ifpdf
\else
    \tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"; dvips -E -o "\image".eps "\image".dvi; ps2pdf "\image".eps "\image".pdf;}}
\fi

\begin{document}

\begin{figure*}[bth]
    \includegraphics[height=3.25in,width=5.25in]{FileDef-Fig}
    \caption{\small {text}}
\end{figure*}

\end{document}

FileDef-Fig.tikz 文件的内容如下:

\begin{tikzpicture}
........
\end{tikzpicture}

main.tex通过以下方式编译此文件

pdflatex --shell-escape "\def\myopts{"conference,10pt"}\input{main}"

\myopts但是,该命令抱怨在日志文件中找不到该宏。

! Undefined control sequence.
<argument> \myopts

使用自动生成的命令编译该图时,在以下命令中报告此错误信息:

pdflatex -shell-escape \
         -halt-on-error \
         -interaction=batchmode \
         -jobname "figure-build/main-figure0" \
  "\def\tikzexternalrealjob{main} \input{main}"

我的问题是如何\def\myopts{...}在上面的pdflatex命令中添加以使其看起来像:

pdflatex -shell-escape \
         -halt-on-error \
         -interaction=batchmode \
         -jobname "figure-build/main-figure0" \
  "\def\myopts{...} \def\tikzexternalrealjob{main} \input{main}".

答案1

您也需要\myopts为外部进行设置system call

\string\def\string\myopts{\myopts}在 前面添加\texsource

写入\string\def,并且\myopts不扩展它们(或尝试扩展它们)。\myopts当然,第二个应该被扩展。

(顺便说一下,我曾经使用过

pdflatex --shell-escape "\def\myopts{conference,10pt}\input{<file name>}"

"定义中没有额外的内容\myopts。)

代码

\documentclass[\myopts]{IEEEtran}
\usepackage{tikzscale}
\usepackage{pgfplots}
\usepackage{lmodern}
\usetikzlibrary{external}
\tikzexternalize[prefix=figure-build/]

% Use the package ifpdf to share one test document between pdflatex and latex
\usepackage{ifpdf}

\ifpdf
  \tikzset{external/system call={%
    pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode
      -jobname "\image" "\string\def\string\myopts{\myopts}\texsource"}}
\else
  \tikzset{external/system call={%
    latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode
      -jobname "\image" "\string\def\string\myopts{\myopts}\texsource";
      dvips -E -o "\image".eps "\image".dvi; ps2pdf "\image".eps "\image".pdf;}}
\fi

\begin{document}
\begin{figure*}[bth]
    \includegraphics[height=3.25in,width=5.25in]{FileDef-Fig}
    \caption{\small {text}}
\end{figure*}
\end{document}

相关内容