Does anyone know why I get error here? Analogous code works for document class "slides" in latex.

\newcommand{\sld}{\end{frame} \begin{frame}}
Test -- Page 1
Test -- Page 2

1 Answer 1


beamer's frame environment is very complicated, since it has to deal with the overlay specification - something inherent to beamer that the end-user rarely have to worry about. That is, you set what looks like a single frame environment, while beamer translates it into a number of slides (possibly).

beamer also reads the entire frame environment in order to manage multiple instances of it and technically misses your \sld's \end{frame}. Other document classes have other ways of managing this, since they don't provide/lack beamer overlay specification, and as such only processes frames once.

Here is a more lengthy and detailed discussion:

This procedure of taking "one thing" (a single frame environment) and replicating it into "multiple things" (numerous slides) requires beamer to grab the entire frame environment before starting to process it. We can see this "frame grabbing" when you look at certain components inside beamerbaseframe.sty:

% The frame environment (a trifle ugly...)

% Copyright notice: the following code is adapted from code from the
% amsmath package.


% Normally not executed; only in containsverbatim context:

\long\def\beamer@push@begins#1\begin#2{\ifx\end#2\else b\expandafter\beamer@push@begins\fi}
  \edef\beamer@begin@stack{\beamer@push@begins#1\begin\end \expandafter\@gobble\beamer@begin@stack}%
      \let\@next=\beamer@process@envbody % A little tricky! Note the grouping
      % ok, just expand it, presumably it will generate the desired \end{frame}

Note how \beamer@frameenv - fundamentally, the start of the frame environment, calls \beamer@process@envbody, which expands to \frame, which expands to \beamer@collect@@body. Further down we see that \beamer@collect@@body's parameter text is defined to include \end. More specifically,


This means that the macro grabs everything from the start of the environment up until \end into argument #1, and the environment name as the argument to \end in argument #2. At the stage of grabbing these arguments (not only are the category codes fixed, but also) TeX has to see a visible \end.

In your case, the only visible \end is that of the "second" frame. As such, what seems like two frames in your mind is considered a single frame in TeX's mind. And, with an odd \end{frame} (the expansion of \sld) that doesn't have an accompanying \begin{frame}, TeX complains.

  • Note that you see the same inability to 'hide' stuff inside macros with for example AMSmath's \begin{align}/\end{align} pair for a not dissimilar reason.
    – Joseph Wright
    Jan 17, 2014 at 8:20
  • Great explanation for a process that goes totally unadverted for the user and can cause a headache.
    – Jose Brox
    Mar 10, 2015 at 15:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .