[Tex/LaTex] How to use the standalone package in beamer

beamerstandalone

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?

Best Answer

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
        \advance\mycount by 1
    \repeat
    \endgroup
}

\begin{document}
  \begin{frame}
     \includestandalone{simpleframe}
  \end{frame}
\end{document}
Related Question