[Tex/LaTex] Beamer frame numbering in appendix

appendicesbeamernumberingpage-numbering

I have a beamer presentation in which I have some additional slides in an appendix. The additional slides are only there in case someone asks a specific question; I won't necessarily have to use any of them.

I am using a theme that prints both the current frame number and the total number of frames on the bottom of each page. My problem is that the total number of frames includes all of the "extra" frames I have in the appendix. Let's say I have 20 "real" frames and then 5 additional frames in the appendix. The problem now is that \inserttotalframenumber (which is what the theme uses to print the total number of frames) returns 25. This is misleading to the audience because I may never even present any of the 5 additional frames.

The ideal behavior would be for \inserttotalframenumber to return 20, not 25. If I did advance to one of the appendix frames then I would like the frame to be "26/25", "27/25", and so on. How can this be done?

Edit:

I see that \inserttotalframenumber is defined in beamerbasemisc.sty by writing the value of the \c@framenumber counter to the .aux file at the end of the document. I guess one way to achieve my desired behavior is to do something like

\AtEndDocument{
  \immediate\write\@auxout{\string\@writefile{nav}%
    {\noexpand\headcommand{\noexpand\def\noexpand\inserttotalframenumber{\insertframenumber}}}}
}

on the last "real" slide of my document. That seems like a bit of a hack though. Is there a better way?

Best Answer

I've used the following macros for this purpose:

\newcommand{\backupbegin}{
   \newcounter{framenumberappendix}
   \setcounter{framenumberappendix}{\value{framenumber}}
}
\newcommand{\backupend}{
   \addtocounter{framenumberappendix}{-\value{framenumber}}
   \addtocounter{framenumber}{\value{framenumberappendix}} 
}

The bonus slides are then put between the two commands:

\appendix
\backupbegin

\frame{\frametitle{One more thing}}

\backupend

This will get you the desired numbering, too.