[Tex/LaTex] Beamer overlays and counters: compiling loop

beamercounters

I tried to compile

\documentclass{beamer}
\usepackage[english]{babel}

\newcounter{xxslide}

\begin{document}
\begin{frame}
  \addtocounter{xxslide}{2} 
  \visible<\value{xxslide}>{blabla}
\end{frame}
\end{document}

But the compiler generated an infinite amount of slides. How can I control number of overlays while programming a slide?

The point is that I'm making a complicated drawing. During the presentation things need to appear and disappear. I want to make macro's that say: show blabla during 5 overlays of a slide. Now, we go to the next overlay. Show blabla for the next 3 overlays and so on … When I switch to the next overlay, I want to increment a counter that expresses the number of the current overlay and then use \visible < xxslide, xxslide+5 > { blabla } commands.

Best Answer

I'm not quite sure how your drawing is structured at the moment, but from what I understand, you could use the \pause command in combination with the . (dot) overlay specification to achieve what you want:

\documentclass{beamer}
\begin{document}
\begin{frame}

Overlay number: \insertpagenumber

\visible<-.(3)>{This text is shown 3 overlays long, starting from overlay 1}\pause

\visible<-.(5)>{This text is shown 5 overlays long, starting from overlay 2}\pause

\visible<-.(2)>{This text is shown 2 overlays long, starting from overlay 3}

\end{frame}
\end{document}

resulting output, showing six overlays

(Click on the image to see it full-size.)

It works like this: Each time a \pause command is encountered, the counter beamerpauses is increased by one, starting from 1. The dot in an overlay specification returns the value of this counter minus one, without changing the counter itself. If followed by an optional offset in round brackets, it returns (beamerpauses - 1) + offset instead, again without affecting the counter itself.

Take for example the second \visible command in the above example: As it is preceded by one \pause, it is shown from the second overlay on. The dot in the overlay specification returns (2 - 1) + 5 = 6, so the text is shown until overlay number 6.

Like this, you can specify how long a certain element of your drawing should be visible in the overlay specification, while managing the order of their appearance using \pause commands.