[Tex/LaTex] Defining \nextslide in overprint environment in beamer

beameroverlays

We all use the \onslide command inside the overprint environment in beamer. However, I find that assigning hard coded slide values, like \onslide<5> in this environment is really cumbersome. This situation becomes difficult whenever we have to insert a new slide in the middle of twenty some overlay slides. We have to manually renumber every subsequent slide after a new slide is inserted. That is why, I tried to define a \nextslide command in beamer.

The idea is very simple, the \nextslide command will increment a predefined counter and will use this value with the \onslide command.

\documentclass{beamer}

\newcounter{slidecounter}
\setcounter{slidecounter}{0}
\def\nextslide{\addtocounter{slidecounter}{1}\onslide<\value{slidecounter}>}

\begin{document}

\begin{frame}{Title}

  \begin{overprint}
    \nextslide
    On one

    \nextslide
    On two

  \end{overprint}

\end{frame}

\end{document}

I understand that I still need to implement resetting the counter at the start of overprint environment once I am successful with this part.

However, whenever I run the code with pdflatex, it keeps on generating page after page, which I have to interrupt with Ctrl-C.

[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2] [3] [4] [5]
[6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
[21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34]
[35] [36] [37] [38] [39] [40] [41] [42] [43] [44] [45] [46] [47] [48]
[49] [50] [51] [52] [53] [54] [55] [56] [57] [58] [59] [60] [61] [62]
[63] [64] [65] [66] [67] [68] [69] [70] [71] [72] [73] [74]^C !
Interruption. \pgfsysprotocol@literalbuffered …tocol@temp {{#1
\space }}\expandafter \pgf… l.20 \end{frame}
? x

The beamer code is too myriad for me to find out where this infinite loop is happening.

Any suggestion will be appreciated.

Best Answer

That's what the + overlay specification is made for (cf. the beamer user guide, section 9.6.4):

The effect of the +-sign is the following: You can use it in any overlay specification at any point where you would usually use a number. If a +-sign is encountered, it is replaced by the current value of the LaTeX counter beamerpauses, which is 1 at the beginning of the frame. Then the counter is increased by 1, though it is only increased once for every overlay specification, even if the specification contains multiple +-signs (they are replaced by the same number).

So your MWE can be solved with

\documentclass{beamer}
\begin{document}
\begin{frame}{Title}
  \begin{overprint}
    \onslide<+>
    On one
    \onslide<+>
    On two
    \onslide<+>
    On three
  \end{overprint}
\end{frame}
\end{document}
Related Question