# How can I make sure tikzexternalize doesn't to externalize my beamer theme content?

Thanks to Ulrike and Cfr, there is now a working solution!

I'm still a bit curious though if it can be done in another way. Is there another way than surrounding included graphics with \tikzexternaldisable and \tikzexternalenable to make sure the beamer theme graphics aren't externalized?

I've have a customized theme in which I include a logo in the footline.

When I use tikzexternalize with the theme, which I sometimes do but not always, the logo is externalized unless I disable the externalization (\tikzexternaldisable). However, this fails if I haven't loaded the external library (since \tikzexternaldisable is an unknown command then).

How can I make sure the theme contents aren't externalized?

This MWE externalizes the footline logo:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{external}
\makeatletter
\defbeamertemplate*{footline}{SomeName}[1][]%
{%
\begin{beamercolorbox}[wd=\paperwidth,ht=.1\paperheight,#1]{logo in foot}%
\tikzexternaldisable %fails if external isn't loaded
%^replacing with \csname tikzexternaldisable \endcsname has same effect as commenting the line out
\tikz\draw[fill=blue] (0,0) rectangle (.9286484375\paperwidth,.05\paperheight);
\tikzexternalenable %fails if external isn't loaded
%^replacing with \csname tikzexternalenable \endcsname has same effect as commenting the line out
\end{beamercolorbox}%
}
\makeatother
\tikzexternalize %Externalizes all images unless I disable and enable it in the beamertemplate
%Best would be if I could tell the externalize library to only externalize images in some of the layers of a beamer frame
\author{John Smith}
\begin{document}
\maketitle
\begin{frame}
\tikz\draw (0,0) circle (10cm);
\end{frame}
\end{document}


I'm hoping there is some elegant beamer or tikz command/setting that doesn't require extra lines when inserting graphics into the theme. Let me know if something is unclear!

• If I did understand your question, you could use \csname tikzexternaldisable\endcsname in the theme. This will expand to \relax if the command is unknown, – Ulrike Fischer Feb 25 '16 at 13:13
• @UlrikeFischer That's a good idea, it should work. However, it doesn't seem to expand to \tikzexternaldisable and \tikzexternalenable as it should. I get the same result when replacing \tikzexternaldisable with \csname tikzexternaldisable\endcsname and \tikzexternalenable with \csname tikzexternalenable\endcsname as when I comment out the two lines (i.e. all the tikzpictures in the pdf are externalized). Am I missing something about how \csname--\endcsname works? – user49901 Feb 25 '16 at 13:27
• \AtBeginDocument{\providecommand\tikzexternaldisable{\relax}} in your preamble. If you load the library, this will do nothing. If you don't, it will ensure the command is defined to do nothing successfully. – cfr Feb 25 '16 at 13:44
• @cfr It works! Great! If you turn it into an answer I'll accept it, as long as some other elegant solution doesn't come along. The only slightly annoying thing with this approach is that I have to make sure the \tikzexternaldisable/\tikzexternalenable are around all included graphics in the theme. If I would locally add a sidebar with \setbeamertemplate{sidebar left}{\tikz\draw(0,0) -- (1,0) -- (1,1);} for example, it will be externalized since I forgot to disable and enable the externalization. – user49901 Feb 25 '16 at 14:01

One very simple method is to add

\AtBeginDocument{\providecommand\tikzexternaldisable{\relax}}


in your preamble. If you load the library, this will do nothing. If you don't, it will ensure the command is defined to do nothing successfully.

Other options would be, for example, to tell TikZ to externalise only pictures you explicitly name and to then name the pictures you want externalised.

Or you could modify Beamer's template setting/defining commands but since Beamer uses a variety of these in a variety of ways, you'd need to trace through what impact this might have.

I'm not entirely sure why you don't want the theme graphics externalised since you don't say. (I would have thought these would be prime candidates.)

• Great! Thanks for your help! I want to externalize pgfplots that take quite some time to compile. This also gives me the possibility to reuse them quickly in other projects. If the theme graphics are externalized, I get one .pdf for every slide in my presentation, it's not a big problem but a bit annoying to get for example 20 pdfs just containing the blue rectangle in the above MWE. Was my explanation understandable? – user49901 Feb 26 '16 at 12:43
• @Grimler OK. Yes. That makes sense. You could put the blue rectangle (or whatever) in a \savebox and then \usebox when defining the theme. That should stop them being recompiled repeatedly. – cfr Feb 26 '16 at 13:11