# Beamer overlays and counters: compiling loop

I tried to compile

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

\newcounter{xxslide}

\begin{document}
\begin{frame}
\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.

• The frame contents are compiled at each slide for overlay effects. So \addtocounter continuously adds 2 at each slide. Take the \addtocounter command out of the frame and it works. – percusse Jul 1 '12 at 11:42
• How do you "go to the next overlay"? Do you use a \pause, or how do you determine what the next overlay is? – diabonas Jul 1 '12 at 14:00

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}


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

Here is a solution based on the pgffor package (not sure of having get the point).

Code:

\documentclass{beamer}
\usepackage{pgffor}

\begin{document}
\begin{frame}
\foreach \xxslide in {1,3}{
\visible<\xxslide->{Text}
}
\newline
\visible<2>{Hello}
\end{frame}
\end{document}


Now you can control the overlays by inserting them as list.

• 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 current overlay. When I switch to the next overlay, I want to increment a counter that expresses the current overlay and then use \visible < xxslide, xxslide+5 > { blabla } commands. – Bruno Bauwens Jul 1 '12 at 12:33

Thanks Diabonas, a simple representation of my problem is to make a moving snake. The code is below:

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

\visible<.-.(3)>{\draw (#1) ellipse (0.5 and 0.5); \pause}
}

\begin{document}

\begin{frame}{A moving snake}
\begin{figure}
\begin{tikzpicture}