Repeating slides in a beamer presentation including original framenumber

With the beamer-class one can easily repeat frames using \againframe. In doing so the framenumber is increased by one. Very often this makes a lot of sense. However, I would like to give the impression that I really show the exact same frame once again. Therefore, the framenumber should also jump back.

Probably the following MWE makes my question more understandable:

\documentclass{beamer}

\useoutertheme{infolines}

\begin{document}

\newcounter{thisframenumber}
\setcounter{thisframenumber}{\value{framenumber}}
\begin{frame}[label=A]
    Frame A
\end{frame}

\begin{frame}
    Frame B
\end{frame}

% steps frame counter
\againframe{A}

% frame number from previous frame
\againframe[noframenumbering]{A}

% desired behavior
\newcounter{tmpframenumber}
\setcounter{tmpframenumber}{\value{framenumber}}
\setcounter{framenumber}{\value{thisframenumber}}
\againframe{A}
\setcounter{framenumber}{\value{tmpframenumber}}

\begin{frame}
    Frame C
\end{frame}

\end{document}

As you see, I found a solution how to achieve the desired behavior. Yet, this solution includes two \newcounter and four \setcounter commands. Is there a less cumbersome solution?

p.s. My dream would be an option for \againframe, like \againframe[originalframenumbering]{A}.

Solutions Collecting From Web of "Repeating slides in a beamer presentation including original framenumber"

Forget my comment.

Beamer provides four macros for this purpose

  • \beamer@savecounter: save the specific counter;
  • \beamer@restorecounter: restore the saved counter;
  • \beamer@labelsavecounter: save the specific counter under the label;
  • \beamer@labelrestorecounter: restore the saved counter.

So the remaining problem is:
where and how can I insert those \beamer@xxxxcounter{c@framenumber}?

First, you need a key oldframenumbering along with noframenumbering to indicate what number this \againframe should use.

Second, you need a continueframenumbering mechanism to restore c@framenumber in case oldframenumbering changes it. (I restore the number only if it is necessary. However you can always restore it.)

Third, since beamer handle the frame number within \beamer@@@@frame<#1>[#2] defined in beamerbaseframe.sty, I need to copy and modify its definition.

So I end up with:

\documentclass[handout,20pt]{beamer}
\useoutertheme{infolines}
\makeatletter

% replacing `noframenumbering' by oldframenumbering
\newif\ifbeamer@oldframenumbering
\beamer@oldframenumberingfalse
\define@key{beamerframe}{oldframenumbering}[true]{\beamer@oldframenumberingtrue}

% replacing `noframenumbering' by continueframenumbering
\newif\ifbeamer@continueframenumbering
\beamer@continueframenumberingfalse

% save framenumber w.r.t. labels
\define@key{beamerframe}{label}{
  \def\beamer@againname{#1}
  {\let\@elt\beamer@labelsavecounter\beamer@overlaycounterresets}
  %%% old definition ↑↑↑
  %%%new code ↓↓↓
  {
    \ifbeamer@continueframenumbering
      \beamer@restorecounter{c@framenumber}
    \fi
    \stepcounter{framenumber}\beamer@labelsavecounter{c@framenumber}\addtocounter{framenumber}{-1}
  }
}

% handling frame number
\def\beamer@@@@frame<#1>[#2]{%
  \framewidth\textwidth
  \beamer@savemode%
  \def\beamer@mode{\mode<all>}%
  \def\beamer@frametemplate{}%
  \def\beamer@againname{}%
  \def\beamer@undolabels{}%
  \def\beamer@cramped{}%
  \def\beamer@displaybreak{}%
  \setbox\beamer@footins=\box\voidb@x%
  \beamer@autobreakcount=0\relax%
  \beamer@autobreaklastheight=16000pt%
  \beamer@zoomcount=0\relax%
  \beamer@containsverbatimfalse%
  \beamer@isfragilefalse%
  \beamer@autobreakfalse%
  \beamer@shrinkfalse%
  \beamer@plainframefalse%
  \global\advance\beamer@zoomframecount by1\relax%
  \csname beamer@dosecondmode\beamer@defaultdosecondmode\endcsname%
  \ifbeamer@centered\setkeys{beamerframe}{c}\else\setkeys{beamerframe}{t}\fi%
  \setkeys{beamerframe}{environment=frame}%
  \setkeys{beamerframe}{#2}%
  \beamer@frametemplate%
  %%% old definition ↑↑↑
  %%% modified `oldframenumbering' code ↓↓↓
  \ifbeamer@noframenumbering
    \beamer@noframenumberingfalse
  \else
    \ifbeamer@continueframenumbering
      \beamer@continueframenumberingfalse
      \beamer@restorecounter{c@framenumber}
    \fi
    \ifbeamer@oldframenumbering
      \beamer@oldframenumberingfalse
      \beamer@continueframenumberingtrue
      \beamer@savecounter{c@framenumber}
      \beamer@labelrestorecounter{c@framenumber}
    \else 
      \stepcounter{framenumber}
    \fi
  \fi%
  %%% old definition ↓↓↓
  {\let\@elt\beamer@savecounter\beamer@overlaycounterresets}
  \gdef\beamer@framestartpage{}%
  \gdef\beamer@whichframes{#1}%
  \ifx\beamer@framerestriction\@undefined\else% restriction stuff
    \expandafter\beamer@checkifinlist\beamer@framerestriction\relax%
  \fi%
  \ifbeamer@inlecture%
  \else%
    \gdef\beamer@whichframes{all:0}%
  \fi%
  \ifx\beamer@againname\@empty%
    \beamer@slideinframe=0\relax%
    \beamer@anotherslidefalse%
    {\beamer@masterdecode{\beamer@whichframes}}%
    \ifbeamer@anotherslide%
        \let\beamer@howtotreatframe\beamer@doseveralframes%
      \ifbeamer@containsverbatim%
        \let\beamer@howtotreatframe\beamer@dosingleframe%
      \fi%
      \ifbeamer@autobreak%
        \let\beamer@howtotreatframe\beamer@autobreakframe%
      \fi%
      \ifbeamer@isfragile%
        \let\beamer@howtotreatframe\beamer@doexternalframe%
      \fi%
    \else% no slides in frame
      \let\beamer@howtotreatframe\beamer@donoframe%
    \fi%
  \else% again mode
    \let\beamer@howtotreatframe\beamer@doseveralframes%
    \ifbeamer@isfragile%
      \let\beamer@howtotreatframe\beamer@doexternalframe%
    \fi%
    \ifbeamer@containsverbatim
      \let\beamer@howtotreatframe\beamer@dosingleframe
    \fi
  \fi%
  \beamer@howtotreatframe}


\begin{document}
\makeatletter
\def\insertshortdate{\Huge\hspace*{-5cm}}\Huge

\frame[label=A]{Alfa}
\frame[label=B]{Bravo}
\againframe[oldframenumbering]{A}
\frame[label=C]{Charlie}
\againframe[oldframenumbering]{B}
\againframe[oldframenumbering]{A}
\frame[label=D]{Delta}
\againframe[oldframenumbering]{C}
\againframe[oldframenumbering]{B}
\againframe[oldframenumbering]{A}
\frame[label=E]{Echo}
\frame{Echo}
\againframe[oldframenumbering]{E}
\frame{Echo}

\saved@A@c@framenumber
\saved@B@c@framenumber
\saved@C@c@framenumber
\saved@D@c@framenumber
\saved@E@c@framenumber

\end{document}