summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/appendixnumberbeamer/appendixnumberbeamer.sty
blob: 454ecd1455de843bdfca158e542c77bd32816fd3 (plain)
1
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
% vim:ft=plaintex:
%
%  Written and (C) by Jérôme Lelong <jerome.lelong@gmail.com>
%  2007 - 2016
% 
%  This program is free software; you can redistribute it and/or modify it
%  under the terms of the GNU General Public License as published by the
%  Free Software Foundation; either version 3 of the License, or (at your
%  option) any later version.
% 
%  This program is distributed in the hope that it will be useful, but
%  WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%  General Public License for more details.
% 
%  You should have received a copy of the GNU General Public License along
%  with this program.  If not, see <http://www.gnu.org/licenses/>. 
% 
%  This small piece of code fixes the frame numbering in beamer when using
%  an appendix such  that the slides of the appendix are not counted in the
%  total framenumber of the main part of the document. The total
%  framenumber counter is reset to 0 and starts counting again when
%  entering the appendix.
% 
%  Usage: \usepackage{appendixnumberbeamer}
%  and declare the appendix as usual using the \appendix command.


\makeatletter


\let\appendixtotalframenumber\empty
\def\mainend{-1}
\let\appendixorig\appendix

% Redefine the \appendix command:
%   - Reset the framenumber counter 
%   - Freeze the total framenumber for this first part of the document
\def\appendix{
  \xdef\mainend{\theframenumber}
  \immediate\write\@auxout{\string\global\string\@namedef{mainendframenumber}{\mainend}}
  \appendixorig
  \gdef\inserttotalframenumber{\appendixtotalframenumber}%
  \setcounter{framenumber}{0}
}

% To be called at the end of the document to fix the total framenumber in the
% main document and in the appendix.
\def\pageatend{
  \xdef\appendixend{\theframenumber}
  \ifnum\mainend>0%
  \immediate\write\@auxout{\string\global\string\@namedef{appendixtotalframenumber}{\appendixend}}%
  \immediate\write\@auxout{\string\global\string\@namedef{inserttotalframenumber}{\mainend}}%
  \immediate\write\@auxout{\string\@writefile{nav}{\noexpand \headcommand {%
        \noexpand \def\noexpand \inserttotalframenumber{\mainend}}}}%
  \immediate\write\@auxout{\string\@writefile{nav}{\noexpand \headcommand {%
        \noexpand \def\noexpand \appendixtotalframenumber{\appendixend}}}}%
  \else
  \fi
}


\AtEndDocument{\pageatend}
\makeatother