[Tex/LaTex] How to avoid beamer counter incrementing

beamercounters

In Latex beamer, I've created a handout environment for slides that are for the produced handout only (ie. not to be shown on the viewer). It looks like this:

\newenvironment{handout}[2][1]{
   \begin{frame}<handout>[environment=handout,allowframebreaks]
}
{\end{frame}}

Key point in the above is:
1) <handout> ensures it is only visible on handout
2) allowframebreaks allows the handout to run over several slides.

OK so far. Only problem is that the framenumber counter (which is used to display page numbers) is incremented for each slide, which means that the handout material and the displayed material in the presentation gets out of sync. So I want to freeze the counter.

I tried simply to back up the current value of the framenumber counter to a temporary in the before part of the environment definition and reseting to that in the after part. That did however now work. Something like this:

\newenvironment{handout}[2][1]{
   \begin{frame}<handout>[environment=handout,allowframebreaks]
   \setcounter{backupcounter}{\value{framenumber}}
}
{\end{frame}\setcounter{framenumber}{\value{backupcounter}}}

So the question is basically, how do I avoid the counter incrementing over these slides?

Best Answer

Your solution works for me if you save the value of framenumber before starting the new frame (which makes it increase) like

\newenvironment{handout}{
   \setcounter{backupcounter}{\value{framenumber}}
   \begin{frame}<handout>[environment=handout,allowframebreaks]
}
{\end{frame}\setcounter{framenumber}{\value{backupcounter}}}