When using tikz in a non-trivial document, the library external is necessary to make PDF build time acceptable (unless one makes a separate TikZ PDF for each figure).
Unfortunately, this library has a number of bugs, such as not working with Beamer overlays. There are fixes, such as this:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\makeatletter
\ifdefined\ifbeamer@anotherslide
\tikzset{
beamer externalising/.style={%
execute at end picture={%
\tikzifexternalizing{%
\ifbeamer@anotherslide
\pgfexternalstorecommand{\string\global\string\beamer@anotherslidetrue}%
\fi
}{}%
}%
}, external/optimize=false, every picture/.style={beamer externalising}
}
\fi
\makeatother
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node {A\qquad\ };
\pause
\node {B};
\end{tikzpicture}
\end{frame}
\end{document}
The TikZ picture has an overlay, due to the \pause command, and the output is properly generated because of the \tikzset{...} fix.
I would like to put this command in a separate .sty file, together with other general purpose hacks.
Of course, if I loaded the style file from a non-Beamer document, \ifbeamer@anotherslide would be undefined.
So I need to make the \tikzset{...} command conditional to the Beamer class loading and/or \ifbeamer@anotherslide being defined. I tried several things along these lines:
%%% hack.sty
\ifdefined\ifbeamer@anotherslide
\tikzset{
beamer externalising/.style={%
execute at end picture={%
\tikzifexternalizing{%
\ifbeamer@anotherslide
\pgfexternalstorecommand{\string\global\string\beamer@anotherslidetrue}%
\fi
}{}%
}}, external/optimize=false, every picture/.style={beamer externalising}
}
\fi
However, constructs like:
\ifdefined\iffoo
\iffoo
% do stuff
\fi
\fi
are illegal.
How can I have the \tikzset command above to be run only when it is necessary, that is, when there is a Beamer document using overlays, and not when other types of documents are used?
