How to use the standalone package in beamer?

I have a beamer presentation that shows a lot of graphs (in the sense of graph theory) and it takes a lot to compile. I think that the standalone package might help me but I cannot see how. Let us say this is my main document (I'm using Emacs, and an updated vanilla TeX Live 2011 in Ubuntu 11.10):

\documentclass{beamer}
\usepackage[mode=buildnew]{standalone}

\begin{document}
\begin{frame}
%\includestandalone{simpleframe}
\input{simpleframe}
\end{frame}
\end{document}

%%% Local Variables:
%%% LaTeX-command: "latex -shell-escape"
%%% End:


and this is the file simpleframe.tex:

\documentclass[beamer]{standalone}

\begin{document}
\begin{standaloneframe}
\only<1>{One}
\only<2>{Two}
\end{standaloneframe}
\end{document}


Then:

• compiling simpleframe.tex is OK
• compiling the main file is OK as it is
• compiling the main file with \includestandalone only shows the first overlay, and with overfull boxes.

I would like the advantages of [mode=buildnew], and, isn't true that for that I need to use \includestandalone? How do I do that?

• Does \usepackage[mode=buildnew,group=false]{standalone} in the outer document fix it? May 9 '12 at 3:06
• @MikeRenfro No it doesn't, it does not seem to make any difference. And the manual says about group=false that "Note that this does not effects the \includestandalone macro which always will add a group." May 9 '12 at 3:34
• Weird, because I thought I had it working that way. Let me verify. May 9 '12 at 11:05
• @MikeRenfro: No, it's not a grouping issue, but because of the frame content being turned into an image. May 9 '12 at 11:29
• I may have inadvertently triggered a different build path by not having -shell-escape enabled. Regardless, I know I had a two-page PDF when I built the outer document, or I was hallucinating. May 9 '12 at 11:43

I'm the author of standalone. First, yes [mode=buildnew] needs \includestandalone. Files included with \input will not be affected by mode. Your problem here is that the standalone file is included as image with this mode and \includestandalone. This is done using \includegraphics which by default only picks the first page of a multi-page PDF. In order to make this work \includegraphics would need to reapply the overlay specifications in the standalone file, i.e. \includegraphics<1>[page=1]{...}, \includegraphics<2>[page=2]{...}, etc. This is currently not the case, but I will put it on the to-do list for the package.

I now created some code which will include all pages of the standalone PDF into beamer. It's just a simple proof-of-concept code and does not support everything, e.g. \graphicspath is not supported and the PDF is also not build by standalone.

Note that standalones beamer support is actually not meant for your application. Having the whole frame as image is not really the way to go. The problem is also that with beamer the standalone content is not cropped. You might want to look for a better way to improve compiling speed. Have a look at \includeonlyframes in the beamer manual.

\documentclass{beamer}
\usepackage[mode=buildnew]{standalone}

\newcount\mycount
\renewcommand\includestandalone[2][]{%
\begingroup
\pdfximage{#2.pdf}%
\chardef\npages\pdflastximagepages\relax
\mycount=1
\loop
\includegraphics<\the\mycount>[page=\the\mycount,#1]{#2.pdf}
\ifnum\mycount<\npages

• Thanks! I was thinking of producing one pdf for each frame (maybe multipage if there are overlays) and then the main file would just concatenate them all (as with pdfpages), so I see no need of cropping. But certainly I would like that when compiling the main file all modified frames would be built. I do not like the \includeonlyframes way since I would eventually have to compile all frames anyway. Hmm, if a LaTeX based way is not possible, maybe a Makefile with standalone frames and pdftk to concatenate the pdfs could be the way to go... May 10 '12 at 0:05
• Yes, concatenating them with pdfpages or a similar tool is a good way here. However, I think then final presentation could be compiled as normal, even if it takes several minutes, only the many compilations during the writing process are usually the culprit. May 10 '12 at 8:15