[Tex/LaTex] Use tikz external feature with beamer \only

beamertikz-externaltikz-pgf

I would like to use the beamer \only with tikz while external is activated. The problem is, that the \only get ignored. (see also the MWE).

I would love to cache the tikz pictures, because it would definitely speed up the compile time.

\documentclass{beamer}
% main document, called main.tex
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize % activate!
\begin{document}

\begin{frame}
    \begin{tikzpicture}
        \node at (1,1) {test};
        \only<2>{\node at (2,2) {test2};}
    \end{tikzpicture}
\end{frame}

\end{document}

I tried the current version and also the cvs version (which is nicer because it uses checksums for the images).

Best Answer

The problem is that once the first graphics has been created, beamer is "blind": it does not know that a further slide has to be generated to fulfill the \only<2>.

I had the same problem some time ago... if I remember correctly, I solved it by adding \only<1-2> around the external picture:

\documentclass{beamer}
% main document, called main.tex
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize % activate!
\begin{document}

\begin{frame}
    \noindent % create a new paragraph here - otherwise, we might end up with different hspace.
    \only<1-2>{%
        \begin{tikzpicture}
            \node at (1,1) {test};
            \only<2>{\node at (2,2) {test2};}
        \end{tikzpicture}%
    }%
\end{frame}

\end{document}

This will create two external .pdf files. The idea is that the outer range <1-2> contains the maximal slide index.

Another solution might be to implement support for the combination external + beamer. If there is some beamer guy who can tell me which switch communicates the need to create a further picture to beamer, I could try to set it under certain conditions from within the external library.