summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/bigfoot/perpage.sty
blob: 6ddf546230e0d05a4f8e6fc069bcd2a06890b1dd (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
%%
%% This is file `perpage.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% perpage.dtx  (with options: `style')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from perpage.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file perpage.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%%
%% perpage is part of the bigfoot bundle for critical typesetting
%% Copyright 2002--2014  David Kastrup <dak@gnu.org>
%%
%% The license notice and corresponding source code for this file are
%% contained in perpage.dtx.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{perpage}[2014/10/25 2.0 Reset/sort counters per page]
\def\pp@cl@begin{\z@\z@ \begingroup}
\def\pp@cl@end{\afterassignment\pp@cl@end@ii \count@}
\def\pp@cl@end@ii{%
  \relax
  \expandafter\endgroup
  \ifnum\count@<\z@
    \expandafter\pp@cl@end@iii
  \fi}
\def\pp@cl@end@iii\stepcounter#1{}
\newcommand\AddAbsoluteCounter[1]
{\@ifundefined{c@abs#1}{%
    \expandafter\newcount\csname c@abs#1\endcsname
    \global\value{abs#1}\@ne
    \global\expandafter\let\csname cl@abs#1\endcsname\@empty
    \expandafter\xdef\csname theabs#1\endcsname{%
      \noexpand\number \csname c@abs#1\endcsname}%
    \global\@namedef{c@pabs@#1}{\pp@cl@begin
      \stepcounter{abs#1}%
      \pp@cl@end}%
    \@addtoreset{pabs@#1}{#1}}{}}
\AddAbsoluteCounter{page}
\def\theabspage{\ifx\thepage\relax
    \noexpand\theabspage
  \else
    \number\c@abspage
  \fi}
\newcommand*\MakePerPage[2][\@ne]{%
  \pp@makeperpage{#2}\c@pchk@{#1}}
\newcommand*\MakeSorted[1]{%
  \setcounter{#1}{\z@}%
  \pp@makeperpage{#1}\c@schk@{\@ne}}
\newcommand*\MakeSortedPerPage[2][\@ne]{%
  \pp@makeperpage{#2}\c@spchk@{#1}}
\@onlypreamble\MakePerPage
\@onlypreamble\MakeSorted
\@onlypreamble\MakeSortedPerPage
\def\pp@makeperpage#1#2#3{%
  \global\expandafter\mathchardef\csname c@pp@r@#1\endcsname=#3\relax
  \global\@namedef{c@pchk@#1}{#2{#1}}%
  \newcounter{pp@a@#1}%
  \setcounter{pp@a@#1}{#3}%
  \addtocounter{pp@a@#1}\m@ne
  \@addtoreset{pchk@#1}{#1}%
  \AtBeginDocument{\setcounter{pp@a@#1}\z@}%
  \edef\next{\noexpand\AtEndDocument
    {\noexpand\setcounter{pp@a@#1}{%
        \number\value{pp@a@#1}}}}\next}
\@onlypreamble\pp@makeperpage
\def\pp@chkvlist{%
  \ifcase
    \ifvmode
      \ifx\lastnodetype\@undefined
        \ifdim-\@m\p@=\prevdepth\ifdim\lastskip=\z@\ifnum\lastpenalty=\z@
          \@ne
        \fi\fi\fi
      \else
        \ifnum\lastnodetype=\m@ne \@ne \fi
      \fi
    \fi \z@
  \or
    \PackageWarning{perpage}{\string\stepcounter\space probably at start of
      vertical list:^^JYou might need to use \string\leavevmode\space
      before it to avoid vertical shifts}%
  \fi}
\def\pp@fetchctr#1{\expandafter\expandafter\expandafter\pp@fetchctrii
  \csname pp@r@#1@\number\value{pp@a@#1}\endcsname
  {}{}}

\global\let\theperpage\@empty

\def\pp@fetchctrii#1#2#3{\def\pp@label{#1}%
  \def\pp@page{#2}%
  \gdef\theperpage{#3}}
\def\c@pchk@#1{\pp@cl@begin
  \pp@fetchctr{#1}\let\next\pp@page
  \addtocounter{pp@a@#1}\@ne
  \pp@fetchctr{#1}%
  \ifcase\ifx\next\pp@page\else\@ne\fi
    \ifnum\value{#1}=\z@\@ne\fi\z@
  \else
    \setcounter{#1}{\value{pp@r@#1}}%
  \fi
  \pp@writectr\pp@pagectr{#1}{\noexpand\theabspage}}
\def\pp@writectr#1#2#3{\edef\next{%
    \string#1{#2}{\number\value{pp@a@#2}}{#3}{\noexpand\thepage}}%
  \pp@chkvlist
  \dimen@=\lastkern
  \ifdim\dimen@=\z@ \else \unkern\fi
  \count@=\lastpenalty
  \protected@write\@auxout{}{\next}%
  \ifdim\dimen@=\z@
    \penalty \ifnum\count@<\@M \@M \else \count@ \fi
  \else \kern\dimen@\fi
  \pp@cl@end}
\def\pp@labeldef#1#2#3#4#5{\@newl@bel{pp@r@#2}{#3}{{#1}{#4}{#5}}}
\def\pp@pagectr#1#2#3#4{\@ifundefined{c@pp@a@#1}{}{%
    \addtocounter{pp@a@#1}\@ne
    \expandafter\pp@labeldef\expandafter
      {\number\value{pp@a@#1}}{#1}{#2}{#3}{#4}}}
\def\c@schk@#1{\pp@cl@begin
  \addtocounter{pp@a@#1}\@ne
  \ifnum\value{#1}=\@ne
    \expandafter\xdef\csname pp@g@#1\endcsname{\number\value{pp@a@#1}}%
    \edef\next{\noexpand\AtEndDocument{\global\let
      \expandafter\noexpand\csname pp@g@#1@\number\value{pp@a@#1}\endcsname
      \relax}}\next
  \fi
  \pp@fetchctr{#1}%
  \ifx\pp@page\@empty
  \else \setcounter{#1}{\pp@label}\fi
  \pp@writectr\pp@spagectr{#1}{\csname pp@g@#1\endcsname}}%
\def\pp@spagectr#1#2#3#4{\@ifundefined{c@pp@a@#1}{}{%
    \count@0\csname pp@g@#1@#3\endcsname
    \advance\count@\@ne
    \expandafter\xdef\csname pp@g@#1@#3\endcsname{\number\count@}%
    \expandafter\pp@labeldef\expandafter
      {\number\count@}{#1}{#2}{#3}{#4}}}
\def\c@spchk@#1{\pp@cl@begin
  \addtocounter{pp@a@#1}\@ne
  \pp@fetchctr{#1}%
  \ifx\pp@page\@empty
  \else \setcounter{#1}{\pp@label}\fi
  \pp@writectr\pp@ppagectr{#1}{\noexpand\theabspage}}
\def\pp@ppagectr#1#2#3#4{\@ifundefined{c@pp@a@#1}{}{%
    \def\next{#3}%
    \expandafter\ifx\csname pp@page@#1\endcsname\next
      \addtocounter{pp@a@#1}\@ne
    \else
      \setcounter{pp@a@#1}{\value{pp@r@#1}}%
    \fi
    \global\expandafter\let\csname pp@page@#1\endcsname\next
    \expandafter\pp@labeldef\expandafter
      {\number\value{pp@a@#1}}{#1}{#2}{#3}{#4}}}
\AtBeginDocument{%
  \begingroup
    \@testdef{}{undefined}{}%
    \expandafter
  \endgroup
  \ifx\@undefined\relax
    \let\pp@@testdef\@testdef
    \def\@testdef#1#2#3{{\pp@@testdef{#1}{#2}{#3}%
        \if@tempswa\aftergroup\@tempswatrue\fi}}%
  \fi}
\endinput
%%
%% End of file `perpage.sty'.