# pgfpages breakes tikzexternalize

I use tikz externalize to speed up the creation of huge beamer presentations for lectures. This works quite well, but if I use pgfpages to collect 2 slides on one a4-page for handouts, the externalized graphics are broken, because the pgfpages setting is also applied to them. See this example: (you need a graphics sub folder)

File with content:

\usepackage{tikz}
\usetikzlibrary{external}

\tikzexternalize[only named=true,
mode=list and make,
up to date check=md5,
prefix={graphics/}
]

\begin{document}
\begin{frame}
\tikzsetnextfilename{foo}
\begin{tikzpicture}
\draw node (){X};
\end{tikzpicture}
\end{frame}
\end{document}


File for beamer slides:

\documentclass[]{beamer}
\input{data}


File for handouts:

\documentclass[handout]{beamer}
\usepackage{pgfpages}
\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
\input{data}


to reproduce first build the slides and check the created pdf in the graphics subfolder, then delete it and create the handout version, the graphic produced then is a4-format and thus, when included wrong scaling.

I am not sure if there is a way around this, or if this should be considered a bug.

Right now my workaround is to first create the slides version, thus creating all the external files with correct scaling and creating the handouts afterwards without building graphics, because they already exist.

But to update one graphic and creating the handout, I always have to produce both documents to get the graphics right.

using a makefile like this:

hand.pdf: hand.tex data.tex beam.pdf
latexmk -pdf hand.tex
beam.pdf: beam.tex data.tex
${PDFLATEX} --shell-escape beam.tex${MAKE} -f beam.makefile
latexmk -pdf beam.tex


so, I set the dependency of the handout to include the slides. But I think the externalize mechanism should be more robust against pgfpages.