5

I am trying to create a manual continuation annotation for my presentations (because I need more flexibility than provided by the automatic splitting feature of beamer).

What I thought of is, for each sequence of slides create a counter and then increment and print its value on each successive slide of the sequence.

If I do that "manually", everything works fine.

Then I tried to automate things a little bit more, as shown below. The countslides command takes an argument, constructs a counter using the argument for its name (if it does not exist) and then increments and prints its value.

Unfortunately, the code produces an error "Missing number, treated as zero" on the first slide (even though the result is correct). The error goes away if I remove the \pause command on this slide (or if I remove the \resetcounteronoverlays from my command definition, but I cannot afford this).

Maybe my code is wrong, but I cannot see how (and it has worked fine in all other cases).

\documentclass{beamer}
\usepackage{ifthen}
\begin{document}

\makeatletter
\newcommand{\countslides}[1]{%
  \ifthenelse{\expandafter\isundefined\csname c@cnt#1\endcsname}%
    {\newcounter{cnt#1}%
     \resetcounteronoverlays{cnt#1}%
    }%
    {}%
  \stepcounter{cnt#1}%
  {~\footnotesize (\arabic{cnt#1})}%
}
\makeatother

\begin{frame}
\frametitle{Hello \countslides{abc}}
A
\pause
B
\end{frame}

\begin{frame}
\frametitle{Bye \countslides{abc}}
C
\pause
D
\end{frame}

\end{document}
3
  • 1
    To a zeroth approximation, I'd guess: \newcounter is global. \pause will cause the frame contents to be typeset more than once. That sounds like something that could conflict. Commented Jul 19, 2013 at 16:58
  • Do you need fancy nesting of the continuation frames that would require you to have several counters for this? I'm seeing if we can just expose beamer's "continuation" mechanic to handle manual breaks. Commented Jul 19, 2013 at 17:10
  • @UlrichSchwarz I do have one situation where the sequence of slides is interrupted, so the simple splitting of beamer is not enough. Also I would like to implement a notation "(1/3)" on the title of the slides; I have done so using the totcount package with the above code, but I will see how this can be implemented using your (second) solution.
    – nplatis
    Commented Jul 21, 2013 at 6:56

2 Answers 2

3

Solution 0: if you can live with splitting off the initial definition:

\documentclass{beamer}

\makeatletter
\newcommand\countable[1]{%
  \newcounter{cnt#1}%
  \resetcounteronoverlays{cnt#1}%
}
\newcommand{\countslides}[1]{%
  \stepcounter{cnt#1}%
  {~\footnotesize (\arabic{cnt#1})}%
}
\makeatother
\begin{document}


\countable{abc}
\begin{frame}
\frametitle{Hello \countslides{abc}}
A
\pause
B
\end{frame}

\begin{frame}
\frametitle{Bye \countslides{abc}}
C
\pause
D
\end{frame}

\end{document}

A solution that strikes me as somewhat cleaner would be this: you give the frames in question the contgroup=... key, and they should all behave as if they were broken automatically, i.e. the normal continuation title templates are applied.

\documentclass{beamer}

\makeatletter

\newcommand\handlecontgroup[1]{%
  \only<1>{%
    \ifcsname ums@cntgroup@#1\endcsname
      \relax
    \else
      \expandafter\gdef\csname ums@cntgroup@#1\endcsname{0}%
    \fi
    \beamer@autobreakcount=\csname ums@cntgroup@#1\endcsname\relax
    \advance\beamer@autobreakcount by 1\relax
    \expandafter\xdef\csname ums@cntgroup@#1\endcsname{%
      \the\beamer@autobreakcount}%
  }%
}
\define@key{beamerframe}{contgroup}{\handlecontgroup{#1}}%
\makeatother
\begin{document}


\begin{frame}[contgroup=abc]
\frametitle{Hello}
A
\pause
B
\end{frame}

\begin{frame}[contgroup=abc]
\frametitle{Bye}
C
\pause
D
\end{frame}

\begin{frame}
\frametitle{Bye}
C
\pause
D
\end{frame}

\begin{frame}[contgroup=abc]
\frametitle{Bye}
C
\pause
D
\end{frame}

\end{document}
1
  • The first solution is simple and nice, but as a programmer I would always prefer to automate things as much as possible :-) so the second solution is indeed cleaner.
    – nplatis
    Commented Jul 21, 2013 at 6:59
0

Have you tried to remove \resetcounteronoverlays{cnt#1}, which is the source of the error "Missing number, treated as zero", and simply replace \stepcounter{cnt#1} by \only<1>{\stepcounter{cnt#1}}?

In my case, this dirty alternative code (using this trick) works

\makeatletter%
\newcommand*\ifcounter[1]{%
  \ifcsname c@#1\endcsname%
    \expandafter\@firstoftwo%
  \else%
    \expandafter\@secondoftwo%
  \fi}
\makeatother

\newcommand{\countslide}[1]{%
\ifcounter{#1}{
% clause for existing counter
}{%
% clause for non existing counter
\newcounter{#1}%
\regtotcounter{#1}%
}%
\only<1>{\addtocounter{#1}{1}}%
\arabic{#1}/\total{#1}%
}

and in the document

\begin{frame}{Title \countslide{abc}}
...
\end{frame}

Note: the \ifcounter command is not from me. I found it here

You must log in to answer this question.

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