Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Until now I've been using standalone to produce cropped figures which are included with \includegraphics command in beamer presentations and articles (beamerarticle) compiled from same source file. Today I wanted to use standalone's possibility of also creating figures and not only including them but as soon as I include ignorenonframetext option for beamer class something breaks. I've read about beamer option for standalone.cls but i don't draw 'animated' figures so I think I don't need it.

Next you have a minimal working and not working example: it works with

\documentclass{article}
\usepackage{beamerarticle} 

or

\documentclass{beamer} 

but not if \documentclass[ignorenonframetext]{beamer} combines with \input{figure}. If instead of \input I place TiKZ code inside the frame works again even with ignorenonframetext.

%\documentclass{article}
%\usepackage{beamerarticle}
%\documentclass{beamer}
\documentclass[ignorenonframetext]{beamer}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{standalone}

\begin{filecontents}{figure.tex}
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw(0,0) rectangle (3,5);
\end{tikzpicture}
\end{document}
\end{filecontents}

\begin{document}
\begin{frame}[fragile]{Hello}
\input{figure}
\end{frame}
\end{document}

The error message says:

! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.5 \documentclass
                  [tikz]{standalone}
? e

Some final comments. I've used filecontents package to simplify the example, real figure files are independent one's. I don't know if frame option fragile is necessary or not. I've also tested with \mode<all> before \input as is suggested in \input{...} is ignored with beamer option ignorenonframetext but nothing changes.

Update

Although egreg answer is valid for the MWE, this was too minimal because as soon as a second nesting level is introduced, \sainput fails. Next you have a new not so minimal working example. In this case, main document \input a file which \input the standalone figure. Everything works with article+beamerarticle or beamer, but not with \documentclass[ignorenonframetext]{beamer}. In this last case, pdflatex finishes and *.log doesn't show any error except No pages of output. and resulting *.pdf has 0 size.

%\documentclass{article}
%\usepackage{beamerarticle}
%\documentclass[ignorenonframetext]{beamer}
\documentclass{beamer}
\usepackage{standalone}
\usepackage{tikz}
\usepackage{filecontents}

\makeatletter
\def\sainput{\let\documentclass\sa@documentclass\input}
\makeatother

\begin{filecontents}{figure.tex}
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw(0,0) rectangle (3,5);
\end{tikzpicture}
\end{document}
\end{filecontents}

\begin{filecontents}{doc.tex}
\begin{frame}{This is a frame}

Here, there is a TiKZ figure

\input{figure}
\end{frame}
\end{filecontents}

\begin{document}

\input{doc}

\end{document}
share|improve this question

1 Answer 1

The ignorenonframetext option messes up what standalone does for avoiding reading a preamble.

This seems to be a workaround:

\documentclass[ignorenonframetext]{beamer}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{standalone}

\begin{filecontents}{figure.tex}
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw(0,0) rectangle (3,5);
\end{tikzpicture}
\end{document}
\end{filecontents}

\makeatletter
\def\sainput{\let\documentclass\sa@documentclass\input}
\makeatother

\begin{document}

\begin{frame}{Hello}
\sainput{figure}
\end{frame}
\end{document}

I wouldn't redefine \input but if you're bold you can try

\makeatletter
\let\latexinput\input
\def\input{\let\documentclass\sa@documentclass\latexinput}
\makeatother

instead of the \makeatletter-\makeatother group as before and use \input{figure}.

share|improve this answer
    
Thank you, your solution works with the minimal example, but not when a second nesting level is introduced. I've updated my question. –  Ignasi Jul 28 '12 at 10:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.