在 Beamer 中外部化 pgfplots/gnuplots - 在文件名中包含“\jobname”

在 Beamer 中外部化 pgfplots/gnuplots - 在文件名中包含“\jobname”

我正在尝试将 外化pgfplotsgnuplot并将contour gnuplot内化beamer。为此,我正在使用visible on=<>的功能\usetikzlibrary{overlay-beamer-styles}(参见这个答案按用户丹尼尔)以及自动编号解决方案来自用户循环空间

然而,我注意到一个奇怪的行为,当我尝试通过更改为:来包含\jobname在文件名中时,第一次编译文档时我收到以下错误消息:{#1-\overlaynumber}{\jobname-#1-\overlaynumber}

system returned with code 256
===== The last system call resulted in an EMPTY output file. 
Maybe it is part of \ref. Rescheduling it for \end{document}. ========

并且文档或多或少是空的。(没有 则不会出现这种情况\jobname)。当我随后多次编译文档时,它开始包含图像。只有在 4 次编译之后,文档才完整。如何修复此错误?

MWE:(使用 编译pdflatex --shell-escape

\documentclass{beamer}
\usepackage{tikz, pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{external}
\usetikzlibrary{overlay-beamer-styles}

%% automatic beamer numbering
%\url{https://tex.stackexchange.com/q/119428/86}
\makeatletter
\newcommand*{\overlaynumber}{\number\beamer@slideinframe}
\tikzset{
  beamer externalizing/.style={%
    execute at end picture={%
      \tikzifexternalizing{%
        \ifbeamer@anotherslide
        \pgfexternalstorecommand{\string\global\string\beamer@anotherslidetrue}%
        \fi
      }{}%
    }%
  },
  external/optimize=false
}
\let\orig@tikzsetnextfilename=\tikzsetnextfilename
\renewcommand\tikzsetnextfilename[1]{\orig@tikzsetnextfilename{\jobname-#1-\overlaynumber}}
\makeatother

\tikzset{every picture/.style={beamer externalizing}}
\tikzexternalize[only named=true]

\begin{document}
\begin{frame}{pgfplots}
  \tikzsetnextfilename{pgfplots}
  \begin{tikzpicture}
  \begin{axis}
    \addplot[visible on=<1-3>] {x};
    \addplot[visible on=<2-3>] {exp(x)};
    \addplot[visible on=<3-3>] {x*x};
  \end{axis}
  \end{tikzpicture}
\end{frame}

\begin{frame}{gnuplot}
  \tikzsetnextfilename{gnuplot}
  \begin{tikzpicture}
  \begin{axis}
    \addplot[visible on=<1-3>] gnuplot{x};
    \addplot[visible on=<2-3>] gnuplot{exp(x)};
    \addplot[visible on=<3-3>] gnuplot{x*x};
  \end{axis}
  \end{tikzpicture}
\end{frame}

\begin{frame}{gnuplot contour}
  \tikzsetnextfilename{contour}
  \begin{tikzpicture}
  \begin{axis}[view={0}{90}, domain=-2:2]
    \addplot3[visible on=<1-3>,contour gnuplot={draw color=red,number=20, labels=false}] {x};
    \addplot3[visible on=<2-3>,contour gnuplot={draw color=blue,number=20, labels=false}] {y};
    \addplot3[visible on=<3-3>,contour gnuplot={draw color=black,number=20, labels=false}] {x^2+y^2};
  \end{axis}
  \end{tikzpicture}
\end{frame}
\end{document}

相关内容