This is a follow-up question from Use tikz external feature with beamer \only . Andrew's answer there is excellent, and does the job (almost) perfectly.
The rough edge I have found was when I tried to use \tikzsetnextfilename together with it.
Why would I want to do that? Because in beamer, one might need to reorder one's slides, or to add an overlay, etc. In this case, most pictures will need to be regenerated, even if they weren't changed.
What is the problem? The following M(n)WE shows the usual way of using \tikzsetnextfilename.
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{external}
\makeatletter
\tikzset{
beamer externalizing/.style={%
execute at end picture={%
\tikzifexternalizing{%
\ifbeamer@anotherslide
\pgfexternalstorecommand{\string\global\string\beamer@anotherslidetrue}%
\fi
}{}%
}%
},
external/optimize=false
}
\makeatother
\tikzset{every picture/.style={beamer externalizing}}
\tikzexternalize
\begin{document}
\begin{frame}
\tikzsetnextfilename{figure}
\only<1>{Image 1:}
\only<2>{Image 2:}
\begin{tikzpicture}
\only<1>{\node {Overlay 1};}
\only<2>{\node {Overlay 2};}
\end{tikzpicture}
\end{frame}
\end{document}
This doesn't work. I'm not pro enough with latex, beamer and tikz mechanics, but I suspect that the problem is tikz externalize trying to generate the two pictures with the same file name.
And indeed, the following code snippet does work.
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{external}
\makeatletter
\tikzset{
beamer externalizing/.style={%
execute at end picture={%
\tikzifexternalizing{%
\ifbeamer@anotherslide
\pgfexternalstorecommand{\string\global\string\beamer@anotherslidetrue}%
\fi
}{}%
}%
},
external/optimize=false
}
\makeatother
\tikzset{every picture/.style={beamer externalizing}}
\tikzexternalize
\begin{document}
\begin{frame}
\only<1>{\tikzsetnextfilename{figure-1}}
\only<2>{\tikzsetnextfilename{figure-2}}
\only<1>{Image 1:}
\only<2>{Image 2:}
\begin{tikzpicture}
\only<1>{\node {Overlay 1};}
\only<2>{\node {Overlay 2};}
\end{tikzpicture}
\end{frame}
\end{document}
Now it is still far from perfect. For example, it requires to know precisely how many overlays are needed for every picture.
Hence the question : is there a better, more natural way of achieving this? If not, is there a way to make this method transparent to the user (so that he doesn't need to count the overlays himself)?
tikzwith the lazy up-to-date check, and assuming you force the regeneration by deleting the appropriate.pdf). – T. Verron Jun 16 '13 at 20:19\overlaynumbercommand is not a native command, but is defined in the link given, to keep things together! – Mathias Kure Jun 14 '18 at 23:23pgfplotswhen usinggnuplot contour. For some reason, it appears that the contours get computed for every single overlay - even for frames that do not even contain them! (Cf. https://tex.stackexchange.com/q/522643/119955) Do you have any idea what going on there? – Hyperplane Jan 05 '20 at 16:20gnuplot contourso I've no idea what's going on there. It looks as though you have asked a new question about it, which is the best way to get new ideas. – Andrew Stacey Jan 05 '20 at 20:43