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.

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?

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

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...

share|improve this answer
    
I see, not a bug but a feature :) –  Ryan Reich Feb 15 '12 at 2:13
add comment

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.