9

For space reasons I want to break up the contents of an itemize list into separate slides, which I have been doing without much problem using \only. However, the following minimal document complains that the label eq:formula is not defined:

\documentclass{beamer}
\begin{document}
\begin{frame}{Title}
 \begin{itemize}
 \only<1>{
  \item Item 1.
 }             % Comment 
 \only<2>{     % these lines
  \item Item 2, with equation
  \begin{equation}
   \label{eq:formula}
   xyz
  \end{equation}

  \item Item 3, with reference \eqref{eq:formula}.
 }
 \end{itemize}
\end{frame}
\end{document}

As you can see, it is clearly defined. The problem goes away if you comment out the marked lines (thus, printing everything on one slide). I see using \tracingmacros that there is a serious redefinition of \label in beamer, and as such it appears that this is a bug with detecting what slide the label is printed on.

Is that right, and what is the solution?

0

1 Answer 1

11

beamer's \label is also overlay-aware. Following \show\label (outside the frame environment), you'll notice

> \label=macro:
->\@ifnextchar <{\beamer@label }{\beamer@label <1>}

which implies \label{<stuff>} without an overlay specification defaults to \label<1>{\stuff>} making it only label on slide 1 by default. This, of course, motivates why having only a single slide makes the references work as expected. Consequently, use \label<2>{eq:formula} for the label to be active on slide 2.

Here's the complete MWE:

enter image description here

\documentclass{beamer}% http://ctan.org/pkg/beamer
\begin{document}
\begin{frame}{Title}
 \begin{itemize}
 \only<1>{%
  \item Item 1.
 }
 \only<2>{%
  \item Item 2, with equation
  \begin{equation}
   \label<2>{eq:formula}
   xyz
  \end{equation}

  \item Item 3, with reference \eqref{eq:formula}.
 }
 \end{itemize}
\end{frame}
\end{document}

True, it would be nice if \label was self-sufficiently slide-aware...

1
  • I see, not a bug but a feature :)
    – Ryan Reich
    Feb 15, 2012 at 2:13

You must log in to answer this question.

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