| 1 |
% \iffalse |
| 2 |
%% |
| 3 |
%% perpage is part of the bigfoot bundle for critical typesetting |
| 4 |
%% Copyright 2002--2014 David Kastrup <[email protected]> |
| 5 |
%% |
| 6 |
%% The license notice and corresponding source code for this file are |
| 7 |
%% contained in perpage.dtx. |
| 8 |
%% |
| 9 |
% This program is free software; you can redistribute it and/or modify |
| 10 |
% it under the terms of the GNU General Public License as published by |
| 11 |
% the Free Software Foundation; either version 2 of the License, or |
| 12 |
% (at your option) any later version. |
| 13 |
% |
| 14 |
% This program is distributed in the hope that it will be useful, |
| 15 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
% GNU General Public License for more details. |
| 18 |
% |
| 19 |
% You should have received a copy of the GNU General Public License |
| 20 |
% along with this program; if not, write to the Free Software |
| 21 |
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 |
% \fi |
| 23 |
% \CheckSum{396} |
| 24 |
% \GetFileInfo{perpage.sty} |
| 25 |
% \date{\filedate} |
| 26 |
% \author{David Kastrup\thanks{\texttt{[email protected]}}} |
| 27 |
% \title{The \texttt{perpage} package\\Version \fileversion} |
| 28 |
% \maketitle |
| 29 |
% \section{Description} |
| 30 |
% |
| 31 |
% The \texttt{perpage} package adds the ability to reset counters per |
| 32 |
% page and/or keep their occurences sorted in order of appearance on |
| 33 |
% the page. |
| 34 |
% |
| 35 |
% It works by attaching itself to the code for \cmd{\stepcounter} and |
| 36 |
% will then modify the given counter according to information written |
| 37 |
% to the |.aux| file, which means that multiple passes may be needed. |
| 38 |
% Since it uses the internals of the \cmd{\label} mechanism, the need |
| 39 |
% for additional passes will get announced by \LaTeX\ as ``labels may |
| 40 |
% have changed''. |
| 41 |
% |
| 42 |
% \DescribeMacro{\MakePerPage} |
| 43 |
% \begin{quote} |
| 44 |
% |\MakePerPage[2]{footnote}| |
| 45 |
% \end{quote} |
| 46 |
% will start footnote numbers with~2 on each page (the optional |
| 47 |
% argument defaults to~1). 2~might be a strange number, unless you |
| 48 |
% have used something like |
| 49 |
% \begin{quote} |
| 50 |
% |\renewcommand\thefootnote{\fnsymbol{footnote}}| |
| 51 |
% \end{quote} |
| 52 |
% and want to start off with a dagger. The starting value must not be |
| 53 |
% less than~1 so that the counter logic can detect the reset of a |
| 54 |
% counter |
| 55 |
% reliably.\footnote{This unfortunately means that you can't just use |
| 56 |
% \cmd{\alph} in order to get figures on page~10 numbered as ``10'', |
| 57 |
% ``10a'', ``10b''.} |
| 58 |
% It could be a good idea to redefine |\@cnterr| if you use a format |
| 59 |
% with limited range: at the first pass, footnotes are not reset |
| 60 |
% across pages and things like |\fnsymbol| will quickly run out of |
| 61 |
% characters to use. |
| 62 |
% |
| 63 |
% \DescribeMacro{\theperpage} |
| 64 |
% If you want to label things also on a per page base, for example |
| 65 |
% with |
| 66 |
% \begin{quote} |
| 67 |
% |\renewcommand{\thefigure}{\thepage-\arabic{figure}}| |
| 68 |
% \end{quote} |
| 69 |
% you'll have the problem that \cmd{\thepage} is updated |
| 70 |
% asynchronously with the real page, since \TeX\ does not know which |
| 71 |
% page the figure will end up. If you have used the |perpage| package |
| 72 |
% for modifying the figure counter, however, at the point where the |
| 73 |
% counter is incremented, the macro \cmd{\theperpage} will be set to |
| 74 |
% the correct value corresponding to the actual page location. Note |
| 75 |
% that this macro is shared between all counters, so advancing a |
| 76 |
% different counter under control of |perpage| will render |
| 77 |
% \cmd{\thefigure} incorrect. |
| 78 |
% |
| 79 |
% \DescribeMacro{\MakeSorted} |
| 80 |
% \begin{quote} |
| 81 |
% |\MakeSorted{figure}| |
| 82 |
% \end{quote} |
| 83 |
% will make the |figure| counter get `sorted': this means that counter |
| 84 |
% values will be assigned in order of appearance in the output, not in |
| 85 |
% order of appearance in the source code. For example, the order of |
| 86 |
% interspersed one- and two-column figures might get mixed up by |
| 87 |
% \LaTeX\ in the output. Making the counter sorted will fix the order |
| 88 |
% to match the order of appearance. A similar problem is when |
| 89 |
% ordinary footnotes are present in floating material (this does not |
| 90 |
% work in standard \LaTeX, but might do so when using |manyfoot.sty| |
| 91 |
% or |bigfoot.sty|): this might jumble their order in the output, and |
| 92 |
% making their counter sorted will make things appear fine again. |
| 93 |
% |
| 94 |
% While this would not fix the order in the table of figures, |
| 95 |
% fortunately the respective entries actually get written out in order |
| 96 |
% of appearance in the output anyway, so this indeed fixes the |
| 97 |
% problem. |
| 98 |
% |
| 99 |
% Manually setting the counter does not lead to reliable results in |
| 100 |
% general; as a special case, however, resetting it to zero is |
| 101 |
% recognized (this can also happen automatically when the counter is |
| 102 |
% dependent on some other counter). The point where it is reset in |
| 103 |
% the source code separates `count groups': everything in the source |
| 104 |
% before that point is assigned sorted numbers separately from |
| 105 |
% everything appearing behind it, and the sequence numbers start again |
| 106 |
% with~1 with the first item appearing in the output (not the source) |
| 107 |
% from the new count group. |
| 108 |
% |
| 109 |
% \DescribeMacro{\MakeSortedPerPage} |
| 110 |
% \begin{quote} |
| 111 |
% |\MakeSortedPerPage[2]{table}| |
| 112 |
% \end{quote} |
| 113 |
% will make the table numbers restart at 2 on each page \emph{and} |
| 114 |
% will keep them sorted, to boot. Introducing new count groups by |
| 115 |
% resetting the counter to~0 manually will not work, as it is not |
| 116 |
% clear how to handle count groups scattered between pages. You will |
| 117 |
% usually want to use something like |
| 118 |
% \begin{quote} |
| 119 |
% |\renewcommand{\thefigure}{\theperpage-\arabic{figure}}| |
| 120 |
% \end{quote} |
| 121 |
% to go along with a page-wise figure |
| 122 |
% number.\footnote{Note the use of \cmd{\theperpage} here, see above.} |
| 123 |
% Note that it would be quite silly to start the ranges with~2: this |
| 124 |
% is just an example for the optional argument in case that you ever |
| 125 |
% need it. |
| 126 |
% |
| 127 |
% \DescribeMacro{\AddAbsoluteCounter} |
| 128 |
% \begin{quote} |
| 129 |
% |\AddAbsoluteCounter{equation}| |
| 130 |
% \end{quote} |
| 131 |
% will create a counter |absequation| that will advance together with |
| 132 |
% the counter |equation| but will not get reset along with it. This |
| 133 |
% is not sorted into output order, but just runs along with the |
| 134 |
% sequence in the source file. As a special case, the counter |
| 135 |
% |abspage| is created in this manner and \cmd{\theabspage} is defined |
| 136 |
% as an arabic number that works in the same contexts as \cmd{\page} |
| 137 |
% (namely, gets properly deferred by \cmd{\protected@write}). |
| 138 |
% |
| 139 |
% \StopEventually{} |
| 140 |
% \section{The documentation driver} |
| 141 |
% This is the default driver for typesetting the docs. Running it |
| 142 |
% through as a separate file will include the code section. Running |
| 143 |
% the original |.dtx| file through will omit the code. |
| 144 |
% \begin{macrocode} |
| 145 |
%<*driver> |
| 146 |
\documentclass{ltxdoc} |
| 147 |
\usepackage{perpage} |
| 148 |
\MakePerPage{footnote} |
| 149 |
\begin{document} |
| 150 |
\OnlyDescription |
| 151 |
%<driver> \AlsoImplementation |
| 152 |
\DocInput{perpage.dtx} |
| 153 |
\end{document} |
| 154 |
%</driver> |
| 155 |
% \end{macrocode} |
| 156 |
% |
| 157 |
% \section{The package interfaces} |
| 158 |
% First identification. |
| 159 |
% \begin{macrocode} |
| 160 |
%<*style> |
| 161 |
\NeedsTeXFormat{LaTeX2e} |
| 162 |
\ProvidesPackage{perpage}[2014/10/25 2.0 Reset/sort counters per page] |
| 163 |
% \end{macrocode} |
| 164 |
% \begin{macro}{\pp@cl@begin} |
| 165 |
% \begin{macro}{\pp@cl@end} |
| 166 |
% These macros are considerable tricky. They are called as |
| 167 |
% artificial `dependent' counters when the counter they are hooked |
| 168 |
% into is advanced. The way in which those counters are called are |
| 169 |
% one of the following: |
| 170 |
% \begin{quote} |
| 171 |
% \begin{verbatim} |
| 172 |
% \def\@stpelt#1{\global\csname c@#1\endcsname \z@} |
| 173 |
% \end{verbatim} |
| 174 |
% \end{quote} |
| 175 |
% which is the default way of resetting a subordinate counter used |
| 176 |
% in \LaTeX, or |
| 177 |
% \begin{quote} |
| 178 |
% \begin{verbatim} |
| 179 |
% \def\@stpelt#1{\global\csname c@#1\endcsname \m@ne\stepcounter{#1}} |
| 180 |
% \end{verbatim} |
| 181 |
% \end{quote} |
| 182 |
% which is a little present from |fixltx2e.sty| as of 2014/05/01, |
| 183 |
% quite complicating this feat. |
| 184 |
% |
| 185 |
% The startup code swallows either |\global \advance| or |\global|. |
| 186 |
% \begin{macrocode} |
| 187 |
\def\pp@cl@begin{\z@\z@ \begingroup} |
| 188 |
% \end{macrocode} |
| 189 |
% The command used for ending our fake counters checks for the |
| 190 |
% |\m@ne| condition. We don't want to bump our auxiliary counters |
| 191 |
% twice, so we remove the following |\stepcounter| command. Things |
| 192 |
% will go haywire if there is none, of course. |
| 193 |
% \begin{macrocode} |
| 194 |
\def\pp@cl@end{\afterassignment\pp@cl@end@ii \count@} |
| 195 |
\def\pp@cl@end@ii{% |
| 196 |
\relax |
| 197 |
\expandafter\endgroup |
| 198 |
\ifnum\count@<\z@ |
| 199 |
\expandafter\pp@cl@end@iii |
| 200 |
\fi} |
| 201 |
\def\pp@cl@end@iii\stepcounter#1{} |
| 202 |
% \end{macrocode} |
| 203 |
% \end{macro} |
| 204 |
% \end{macro} |
| 205 |
% |
| 206 |
% \begin{macro}{\AddAbsoluteCounter} |
| 207 |
% adds a counter with prefix |abs| to a given counter. It typesets |
| 208 |
% as an arabic number and never gets reset. And it is advanced |
| 209 |
% whenever the unprefixed counter gets advanced. |
| 210 |
% \begin{macrocode} |
| 211 |
\newcommand\AddAbsoluteCounter[1] |
| 212 |
{\@ifundefined{c@abs#1}{% |
| 213 |
\expandafter\newcount\csname c@abs#1\endcsname |
| 214 |
\global\value{abs#1}\@ne |
| 215 |
\global\expandafter\let\csname cl@abs#1\endcsname\@empty |
| 216 |
\expandafter\xdef\csname theabs#1\endcsname{% |
| 217 |
\noexpand\number \csname c@abs#1\endcsname}% |
| 218 |
\global\@namedef{c@pabs@#1}{\pp@cl@begin |
| 219 |
\stepcounter{abs#1}% |
| 220 |
\pp@cl@end}% |
| 221 |
\@addtoreset{pabs@#1}{#1}}{}} |
| 222 |
% \end{macrocode} |
| 223 |
% \end{macro} |
| 224 |
% \begin{macro}{\c@perpage} |
| 225 |
% We now create the absolute counter |perpage|: |
| 226 |
% \begin{macrocode} |
| 227 |
\AddAbsoluteCounter{page} |
| 228 |
% \end{macrocode} |
| 229 |
% \end{macro} |
| 230 |
% \begin{macro}{\theabspage} |
| 231 |
% This has to be specially defined so that it will expand as late as |
| 232 |
% \cmd{\thepage} does. Several commands set the latter temporarily |
| 233 |
% to \cmd{\relax} in order to inhibit expansion, and we will more or |
| 234 |
% less imitate its behavior when found set in that manner. |
| 235 |
% \begin{macrocode} |
| 236 |
\def\theabspage{\ifx\thepage\relax |
| 237 |
\noexpand\theabspage |
| 238 |
\else |
| 239 |
\number\c@abspage |
| 240 |
\fi} |
| 241 |
% \end{macrocode} |
| 242 |
% \end{macro} |
| 243 |
% Here follow the three commands for defining counters per page: |
| 244 |
% \begin{macro}{\MakePerPage} |
| 245 |
% This creates a counter reset per page. An optional second |
| 246 |
% argument specifies the starting point of the sequence. |
| 247 |
% \begin{macrocode} |
| 248 |
\newcommand*\MakePerPage[2][\@ne]{% |
| 249 |
\pp@makeperpage{#2}\c@pchk@{#1}} |
| 250 |
% \end{macrocode} |
| 251 |
% \end{macro} |
| 252 |
% \begin{macro}{\MakeSorted} |
| 253 |
% This will create a counter sorted in appearance on the page. No |
| 254 |
% optional argument is given: set the counter to a desired starting |
| 255 |
% value manually if you need to. Resetting it to zero will start a |
| 256 |
% new count group, setting it to other values is probably not reliable. |
| 257 |
% \begin{macrocode} |
| 258 |
\newcommand*\MakeSorted[1]{% |
| 259 |
\setcounter{#1}{\z@}% |
| 260 |
\pp@makeperpage{#1}\c@schk@{\@ne}} |
| 261 |
% \end{macrocode} |
| 262 |
% \end{macro} |
| 263 |
% \begin{macro}{\MakeSortedPerPage} |
| 264 |
% This will create output in sorted order, reset on each page. Use |
| 265 |
% an optional argument to specify the starting value per page. This |
| 266 |
% must not be~0, unfortunately. |
| 267 |
% \begin{macrocode} |
| 268 |
\newcommand*\MakeSortedPerPage[2][\@ne]{% |
| 269 |
\pp@makeperpage{#2}\c@spchk@{#1}} |
| 270 |
% \end{macrocode} |
| 271 |
% \end{macro} |
| 272 |
% All of those must only occur in the preamble since we can't do the |
| 273 |
% initialization of the counter values otherwise. |
| 274 |
% \begin{macrocode} |
| 275 |
\@onlypreamble\MakePerPage |
| 276 |
\@onlypreamble\MakeSorted |
| 277 |
\@onlypreamble\MakeSortedPerPage |
| 278 |
% \end{macrocode} |
| 279 |
% \section{Internals} |
| 280 |
% |
| 281 |
% It works in the following manner: The basic work is done through |
| 282 |
% attaching help code to the counter's reset list. Each counter has |
| 283 |
% an associated absolute id that is counted through continuously and |
| 284 |
% is never reset, thus providing a unique frame of reference. Sorted |
| 285 |
% and perpage counters work by writing out information to the |
| 286 |
% |.aux| file. |
| 287 |
% |
| 288 |
% The information we maintain for each counter while processing the |
| 289 |
% source file are: |
| 290 |
% \begin{itemize} |
| 291 |
% \item The absolute counter id. |
| 292 |
% \item The last counter value so that we can check whether the |
| 293 |
% sequence has been interrupted. |
| 294 |
% \item The current scope id. |
| 295 |
% \item Its starting value. |
| 296 |
% \end{itemize} |
| 297 |
% |
| 298 |
% The information written to the file consists of: |
| 299 |
% \begin{itemize} |
| 300 |
% \item The absolute counter id. |
| 301 |
% \item The current scope id. |
| 302 |
% \item The scope's starting value. |
| 303 |
% \item The absolute counter id of a superior counter. |
| 304 |
% \end{itemize} |
| 305 |
% |
| 306 |
% Sorted counters work by writing out the current absolute id and |
| 307 |
% range id into the |.aux| file each time the counter gets incremented. |
| 308 |
% Whenever the counter is changed in a manner different from being |
| 309 |
% incremented, a new counter scope gets started. Each counter scope |
| 310 |
% has its own independently assigned counter numbers and is associated |
| 311 |
% with its absolute id starting value. So as each counter is |
| 312 |
% incremented, we write out the triple of current absolute id, counter |
| 313 |
% scope and initial value for the scope. Scope changes when a value |
| 314 |
% assigned from the file differs from the `natural' value. When the |
| 315 |
% file is read in, counter movements are tracked. Each counter that |
| 316 |
% does not have its `natural' value, is having a counter setting |
| 317 |
% recorded. |
| 318 |
% |
| 319 |
% The stuff works by adding a pseudo-reset counter to the counter's |
| 320 |
% dependent counter list. |
| 321 |
% |
| 322 |
% \begin{macro}{\pp@makeperpage} |
| 323 |
% This does the relevant things for modifying a counter. It defines |
| 324 |
% its reset value, it defines the correspoding absolute counter. |
| 325 |
% The absolute counter serves a double function: it is also used for |
| 326 |
% assigning numbers while reading the |.aux| file. For this purpose |
| 327 |
% it is assigned the initialized values here and in the enddocument |
| 328 |
% hook (which is called before rereading the |.aux| file and |
| 329 |
% checking for changed labels), while the counter is reset to zero |
| 330 |
% at the start of the document. |
| 331 |
% \begin{macrocode} |
| 332 |
\def\pp@makeperpage#1#2#3{% |
| 333 |
\global\expandafter\mathchardef\csname c@pp@r@#1\endcsname=#3\relax |
| 334 |
\global\@namedef{c@pchk@#1}{#2{#1}}% |
| 335 |
\newcounter{pp@a@#1}% |
| 336 |
\setcounter{pp@a@#1}{#3}% |
| 337 |
\addtocounter{pp@a@#1}\m@ne |
| 338 |
\@addtoreset{pchk@#1}{#1}% |
| 339 |
\AtBeginDocument{\setcounter{pp@a@#1}\z@}% |
| 340 |
\edef\next{\noexpand\AtEndDocument |
| 341 |
{\noexpand\setcounter{pp@a@#1}{% |
| 342 |
\number\value{pp@a@#1}}}}\next} |
| 343 |
\@onlypreamble\pp@makeperpage |
| 344 |
% \end{macrocode} |
| 345 |
% \end{macro} |
| 346 |
% \begin{macro}{\pp@chkvlist} |
| 347 |
% Check for an empty vertical list. If we have one, that is worth |
| 348 |
% warning about. |
| 349 |
% \begin{macrocode} |
| 350 |
\def\pp@chkvlist{% |
| 351 |
\ifcase |
| 352 |
\ifvmode |
| 353 |
\ifx\lastnodetype\@undefined |
| 354 |
\ifdim-\@m\p@=\prevdepth\ifdim\lastskip=\z@\ifnum\lastpenalty=\z@ |
| 355 |
\@ne |
| 356 |
\fi\fi\fi |
| 357 |
\else |
| 358 |
\ifnum\lastnodetype=\m@ne \@ne \fi |
| 359 |
\fi |
| 360 |
\fi \z@ |
| 361 |
\or |
| 362 |
\PackageWarning{perpage}{\string\stepcounter\space probably at start of |
| 363 |
vertical list:^^JYou might need to use \string\leavevmode\space |
| 364 |
before it to avoid vertical shifts}% |
| 365 |
\fi} |
| 366 |
% \end{macrocode} |
| 367 |
% \end{macro} |
| 368 |
% \begin{macro}{\pp@fetchctr} |
| 369 |
% \begin{macro}{\theperpage} |
| 370 |
% This fetches the counter information and puts it into |
| 371 |
% \cmd{\pp@label}, \cmd{\pp@page} and (globally) into |
| 372 |
% \cmd{\theperpage}. |
| 373 |
% \begin{macrocode} |
| 374 |
\def\pp@fetchctr#1{\expandafter\expandafter\expandafter\pp@fetchctrii |
| 375 |
\csname pp@r@#1@\number\value{pp@a@#1}\endcsname |
| 376 |
{}{}} |
| 377 |
|
| 378 |
\global\let\theperpage\@empty |
| 379 |
|
| 380 |
\def\pp@fetchctrii#1#2#3{\def\pp@label{#1}% |
| 381 |
\def\pp@page{#2}% |
| 382 |
\gdef\theperpage{#3}} |
| 383 |
% \end{macrocode} |
| 384 |
% \end{macro} |
| 385 |
% \end{macro} |
| 386 |
% Ok, let's put together all the stuff for the simplest case, counters |
| 387 |
% numbered per page without sorting: |
| 388 |
% \begin{macro}{\c@pchk@} |
| 389 |
% This is the code buried into to the reset list. When the reset |
| 390 |
% list is executed in the context of advancing a counter, we call |
| 391 |
% something like |
| 392 |
% \begin{verbatim} |
| 393 |
%\global\c@pchk@{countername}\z@ |
| 394 |
% \end{verbatim} |
| 395 |
% since the reset list expected a counter here instead of some |
| 396 |
% generic command. That is the reason we start off this command by |
| 397 |
% giving \cmd{\global} something to chew on. |
| 398 |
% \begin{macrocode} |
| 399 |
\def\c@pchk@#1{\pp@cl@begin |
| 400 |
% \end{macrocode} |
| 401 |
% Now we fetch the page value corresponding to the not yet adjusted |
| 402 |
% value of the absolute counter to see whether the previous counter |
| 403 |
% advance happened on the same page. |
| 404 |
% \begin{macrocode} |
| 405 |
\pp@fetchctr{#1}\let\next\pp@page |
| 406 |
\addtocounter{pp@a@#1}\@ne |
| 407 |
\pp@fetchctr{#1}% |
| 408 |
% \end{macrocode} |
| 409 |
% We compare the pages for current and last advance of the counter. |
| 410 |
% If they differ, we reset the counter to its starting value. We do |
| 411 |
% the same if the counter has been reset to zero manually, likely by |
| 412 |
% being in the reset list of some other counter. |
| 413 |
% \begin{macrocode} |
| 414 |
\ifcase\ifx\next\pp@page\else\@ne\fi |
| 415 |
\ifnum\value{#1}=\z@\@ne\fi\z@ |
| 416 |
\else |
| 417 |
\setcounter{#1}{\value{pp@r@#1}}% |
| 418 |
\fi |
| 419 |
\pp@writectr\pp@pagectr{#1}{\noexpand\theabspage}} |
| 420 |
% \end{macrocode} |
| 421 |
% \end{macro} |
| 422 |
% \begin{macro}{\pp@writectr} |
| 423 |
% This is the common ending of all pseudo reset counters. It writes |
| 424 |
% out an appropriate command to the |.aux| file with all required |
| 425 |
% information. We try to replicate any sentinel kerns or penalties. |
| 426 |
% \begin{macrocode} |
| 427 |
\def\pp@writectr#1#2#3{\edef\next{% |
| 428 |
\string#1{#2}{\number\value{pp@a@#2}}{#3}{\noexpand\thepage}}% |
| 429 |
\pp@chkvlist |
| 430 |
\dimen@=\lastkern |
| 431 |
\ifdim\dimen@=\z@ \else \unkern\fi |
| 432 |
\count@=\lastpenalty |
| 433 |
\protected@write\@auxout{}{\next}% |
| 434 |
\ifdim\dimen@=\z@ |
| 435 |
\penalty \ifnum\count@<\@M \@M \else \count@ \fi |
| 436 |
\else \kern\dimen@\fi |
| 437 |
\pp@cl@end} |
| 438 |
% \end{macrocode} |
| 439 |
% \end{macro} |
| 440 |
% \begin{macro}{\pp@labeldef} |
| 441 |
% This is a helper macro. |
| 442 |
% \begin{macrocode} |
| 443 |
\def\pp@labeldef#1#2#3#4#5{\@newl@bel{pp@r@#2}{#3}{{#1}{#4}{#5}}} |
| 444 |
% \end{macrocode} |
| 445 |
% \end{macro} |
| 446 |
% |
| 447 |
% \begin{macro}{\pp@pagectr} |
| 448 |
% This is the workhorse for normal per page counters. It is called |
| 449 |
% whenever the |.aux| file is read in and establishes the |
| 450 |
% appropriate information for each counter advancement in a |
| 451 |
% pseudolabel. |
| 452 |
% \begin{macrocode} |
| 453 |
\def\pp@pagectr#1#2#3#4{\@ifundefined{c@pp@a@#1}{}{% |
| 454 |
\addtocounter{pp@a@#1}\@ne |
| 455 |
\expandafter\pp@labeldef\expandafter |
| 456 |
{\number\value{pp@a@#1}}{#1}{#2}{#3}{#4}}} |
| 457 |
% \end{macrocode} |
| 458 |
% \end{macro} |
| 459 |
% \begin{macro}{\c@schk@} |
| 460 |
% This is called for implementing sorted counters. Sorted counters |
| 461 |
% maintain a ``count group'', and the values in each count group are |
| 462 |
% numbered independently from that of other count groups. Whenever |
| 463 |
% a counter is found to have been reset, it will start a new count |
| 464 |
% group. At the end of document, the count group counters need to |
| 465 |
% get reset, too, so that the check for changed |.aux| files will |
| 466 |
% still work. |
| 467 |
% \begin{macrocode} |
| 468 |
\def\c@schk@#1{\pp@cl@begin |
| 469 |
\addtocounter{pp@a@#1}\@ne |
| 470 |
\ifnum\value{#1}=\@ne |
| 471 |
\expandafter\xdef\csname pp@g@#1\endcsname{\number\value{pp@a@#1}}% |
| 472 |
\edef\next{\noexpand\AtEndDocument{\global\let |
| 473 |
\expandafter\noexpand\csname pp@g@#1@\number\value{pp@a@#1}\endcsname |
| 474 |
\relax}}\next |
| 475 |
\fi |
| 476 |
\pp@fetchctr{#1}% |
| 477 |
\ifx\pp@page\@empty |
| 478 |
\else \setcounter{#1}{\pp@label}\fi |
| 479 |
\pp@writectr\pp@spagectr{#1}{\csname pp@g@#1\endcsname}}% |
| 480 |
% \end{macrocode} |
| 481 |
% \end{macro} |
| 482 |
% \begin{macro}{\pp@spagectr} |
| 483 |
% This is the code advancing the respective value of the appropriate |
| 484 |
% count group and assigning the label. |
| 485 |
% \begin{macrocode} |
| 486 |
\def\pp@spagectr#1#2#3#4{\@ifundefined{c@pp@a@#1}{}{% |
| 487 |
\count@0\csname pp@g@#1@#3\endcsname |
| 488 |
\advance\count@\@ne |
| 489 |
\expandafter\xdef\csname pp@g@#1@#3\endcsname{\number\count@}% |
| 490 |
\expandafter\pp@labeldef\expandafter |
| 491 |
{\number\count@}{#1}{#2}{#3}{#4}}} |
| 492 |
% \end{macrocode} |
| 493 |
% \end{macro} |
| 494 |
% \begin{macro}{\c@spchk@} |
| 495 |
% And this finally is the counter advance code for sorted counters |
| 496 |
% per page. Basically, we just use one count group per page. |
| 497 |
% Resetting a counter manually will not introduce a new count group, |
| 498 |
% and it would be hard to decide what to do in case count groups and |
| 499 |
% page positions overlap. |
| 500 |
% \begin{macrocode} |
| 501 |
\def\c@spchk@#1{\pp@cl@begin |
| 502 |
\addtocounter{pp@a@#1}\@ne |
| 503 |
\pp@fetchctr{#1}% |
| 504 |
\ifx\pp@page\@empty |
| 505 |
\else \setcounter{#1}{\pp@label}\fi |
| 506 |
\pp@writectr\pp@ppagectr{#1}{\noexpand\theabspage}} |
| 507 |
% \end{macrocode} |
| 508 |
% \end{macro} |
| 509 |
% \begin{macro}{\pp@ppagectr} |
| 510 |
% \begin{macrocode} |
| 511 |
\def\pp@ppagectr#1#2#3#4{\@ifundefined{c@pp@a@#1}{}{% |
| 512 |
\def\next{#3}% |
| 513 |
\expandafter\ifx\csname pp@page@#1\endcsname\next |
| 514 |
\addtocounter{pp@a@#1}\@ne |
| 515 |
\else |
| 516 |
\setcounter{pp@a@#1}{\value{pp@r@#1}}% |
| 517 |
\fi |
| 518 |
\global\expandafter\let\csname pp@page@#1\endcsname\next |
| 519 |
\expandafter\pp@labeldef\expandafter |
| 520 |
{\number\value{pp@a@#1}}{#1}{#2}{#3}{#4}}} |
| 521 |
% \end{macrocode} |
| 522 |
% \end{macro} |
| 523 |
% \begin{macro}{\@testdef} |
| 524 |
% \LaTeX's current (2007) definition of this macro causes save stack |
| 525 |
% overflow. We fix this by an additional grouping. Delay to the |
| 526 |
% beginning of document to keep Babel happy. |
| 527 |
% \begin{macrocode} |
| 528 |
\AtBeginDocument{% |
| 529 |
\begingroup |
| 530 |
\@testdef{}{undefined}{}% |
| 531 |
\expandafter |
| 532 |
\endgroup |
| 533 |
\ifx\@undefined\relax |
| 534 |
\let\pp@@testdef\@testdef |
| 535 |
\def\@testdef#1#2#3{{\pp@@testdef{#1}{#2}{#3}% |
| 536 |
\if@tempswa\aftergroup\@tempswatrue\fi}}% |
| 537 |
\fi} |
| 538 |
%</style> |
| 539 |
% \end{macrocode} |
| 540 |
% \end{macro} |
| 541 |
% |
| 542 |
% \Finale |
| 543 |
% \endinput |
| 544 |
% Local Variables: |
| 545 |
% mode: doctex |
| 546 |
% TeX-master: "perpage.drv" |
| 547 |
% End: |