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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
|
% \iffalse
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
%<*driver>
\ProvidesFile{totpages.drv}
[2003/02/05 v1.10 Driver for Totpages Package (muewi)]
\documentclass{ltxdoc}
\usepackage{url}
\usepackage{totpages}
\usepackage[toc]{multitoc}
\GetFileInfo{totpages.sty}
\EnableCrossrefs
\CodelineIndex % Index code by line number
\RecordChanges % Changelog go .gls
\OnlyDescription % comment out for implementation details
\setcounter{IndexColumns}{2}
%%\OldMakeIndex % use if your MakeIndex is pre-v2.9
\begin{document}
\setcounter{page}{1234}
\DocInput{totpages.dtx}
\end{document}
%</driver>
%
% Copyright (c) [1999] by Wilhelm M\"uller. All rights reserved.
%
% This program may be redistributed and/or modified under the terms
% of the LaTeX Project Public License, either version 1.1 of this
% license, or (at your option) any later version.
% The latest version of this license is in
% CTAN:macros/latex/base/lppl.txt.
%
% For error reports in case of UNCHANGED versions see totpages.ins
%
% \fi
%
% \CheckSum{109}
%
%% \CharacterTable
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%% Digits \0\1\2\3\4\5\6\7\8\9
%% Exclamation \! Double quote \" Hash (number) \#
%% Dollar \$ Percent \% Ampersand \&
%% Acute accent \' Left paren \( Right paren \)
%% Asterisk \* Plus \+ Comma \,
%% Minus \- Point \. Solidus \/
%% Colon \: Semicolon \; Less than \<
%% Equals \= Greater than \> Question mark \?
%% Commercial at \@ Left bracket \[ Backslash \\
%% Right bracket \] Circumflex \^ Underscore \_
%% Grave accent \` Left brace \{ Vertical bar \|
%% Right brace \} Tilde \~}
%%
%% \iffalse meta-comment
%% ===================================================================
%% @LaTeX-style-file{
%% author = {Wilhelm M\"uller},
%% version = "1.00",
%% date = "14 July 1999",
%% filename = "totpages.sty",
%% address = {Wilhelm M\"uller
%% Am Wall 139
%% D-28195 Bremen
%% telephone = "+49-421-1692525",
%% email = "muewi@acm.org",
% codetable = "ISO/ASCII",
% keywords = "LaTeX, pages",
% supported = "yes",
%% docstring = "LaTeX package which sets count1 to the total
%% number of pages in the document.
%% Uses the everyshi package."
%
%% }
%% ===================================================================
%% \fi
%
% \changes{v1.00}{1999/07/14}{Initial Version}
% \changes{v1.10}{2003/02/05}{Fixed hook into hyperref}
%
% \DoNotIndex{\@empty,\@firstofone,\addtocounter,\arabic}
% \DoNotIndex{\begingroup,\countdef,\def,\edef,\else,\endgroup}
% \DoNotIndex{\fi,\ifx,\immediate,\let,\MessageBreak}
% \DoNotIndex{\newcommand,\newcounter,\newif}
% \DoNotIndex{\ref,\relax,\stepcounter,\string,\textlatin}
% \DoNotIndex{\the,\thepage,\undefined,\write}
% \DoNotIndex{\ifHy@pageanchor,\if@filesw,\ifHy@hypertexnames}
% \DoNotIndex{\ifHy@plainpages,\Hy@temp,\Hy@pagecounter}
%
% \newcommand*{\Count}[1]{\texttt{\bslash{}count#1}}
% \newcommand*{\package}[1]{\textsf{#1}}
% \newcommand*{\ftype}[1]{\textsl{#1}}
% \newcommand*{\NEWfeature}[1]{% stolen frm ltxguide.cls
% \hskip 1sp \marginpar{\small\sffamily\raggedright
% New feature\\#1}}
%
% ^^A^^A We need to document a label -- we do this by using the macros for
% ^^A^^A environments and changing the macros for the index entries.
% \makeatletter
% \renewcommand*{\SpecialEnvIndex}[1]{^^A
% \@bsphack\index{\string#1^^A
% \actualchar\string\verb\quotechar*\verbatimchar
% \string#1\verbatimchar
% \encapchar usage}\@esphack}
% \renewcommand*{\SpecialMainEnvIndex}[1]{^^A
% \@bsphack\special@index{\string#1\actualchar
% \string\verb\quotechar*\verbatimchar
% \string#1\verbatimchar\encapchar main}%
% \@esphack}
% \makeatother
%
% ^^A -----------------------------
%
% \title{\unskip
% The \package{totpages} package^^A
% \thanks{^^A
% The version number of this file is \fileversion,
% last revised \filedate.}
% }
% \author{Wilhelm M\"uller\\[0.5ex]
% \normalsize Am Wall 139\\
% \normalsize D-28195 Bremen\\
% \normalsize muewi@acm.org
% }
% \date{\filedate}
% \maketitle
%
% ^^A -----------------------------
%
%
% \begin{abstract}
% \noindent This package counts the total number of pages shipped
% out to the \ftype{dvi} file. The counter itself may be shipped out, too,
% allowing page access by absolute page numbers, or it may be just
% a regular \LaTeX\ counter.
%
% The value that counter had at the end of the previous \LaTeX\ run
% may be referenced as |\ref{TotPages}|, the (\LaTeX) page number it appears
% on as |\pageref{TotPages}|. This allows sentences like
% ``This document contains \ref{TotPages} pages,
% the last one being no.~\pageref{TotPages}.'' to be produced automatically.
%
% This package can be used with with the package \package{hyperref}, producing
% a hyperlink to the last page---though this is not of much use as most hypertext
% readers allow direct access to the last page anyway.
% \end{abstract}
%
% \pagestyle{headings}
%
% ^^A -----------------------------
%
% \tableofcontents
%
% ^^A -----------------------------
%
% \section{Introduction}
% ^^A
% Printing only part of a \ftype{dvi} file can be difficult or impossible if pages in different
% parts of the document have the same number---e.\,g. in the
% frontmatter and the first text pages (iii vs. 3).
%
% \TeX{} provides an easy solution to this problem: whenever a page
% has been completed by the output routine and is being shipped out to
% the \ftype{dvi} file,
% it displayes the values of \Count{0} to \Count{9},
% with trailing zeroes suppressed,
% (e.\,g., \texttt{[1002.0.3]}) and writes them to the \ftype{log} and
% \ftype{dvi} files, cf.\ \cite[p.~119]{KnuthTeXa}.
% So,
% if you have a \ftype{dvi} driver which allows page selection by other counters
% than \Count{0}, you will be able to refer to absolute page numbers
% when you make use of this package.
%
% \section{Using \package{totpages}}
% ^^A
% \DescribeEnv{TotPages}
% Keeping a count of the absolute page number makes it
% possible to provide the \emph{total} number of pages of the
% document (as opposed to the ``number'' on the last page provided
% by the \package{lastpage} package, cf.\ \cite{package:lastpage}).
%
% References to the counter itself won't make much sense since it is updated
% asynchronously whenever an actual shipout occurs.
% But by referencing the label |TotPages| (with |\ref{TotPages}|)
% you get the total number of pages the document had at the end
% of the previous run
% of \LaTeX. If, for some reason, you want to know what page number \LaTeX\
% actually (would have) printed, you may use |\pageref{TotPages}|.
%
% \DescribeMacro{\theTotPages}
% What is actually printed by |\ref{TotPages}| is the result of the
% macro |\theTotPages|, which normally is simply |\arabic{TotPages}|, but
% may be redefined to anything (sensible)
% somewhere before |\end{document}|.
%
% If you want to use this package, you should load \package{totpages}
% as the \emph{last} package in your document because it
% executes some code at |\end{document}| and has to be sure that its
% code is the last code to be executed there.\footnote{See
% \cite{package:lastpage} for a discussion of problems.}
%
% You \emph{must not} use \package{count1to} or \package{lastpage}
% together with this package. Package \package{count1to} provides additional
% functionality, but will not co-operate with \package{hyperref}, whereas
% any use of \package{lastpage} is covered by \package{totpages}.
% If you try to use one (or both) of these packages together with
% \package{totpages}, you will receive an error message at
% |\begin{document}|. I don't think that something really bad will happen
% if you ignore it (unless you use \package{count1to} together with
% \package{hyperref}), but I won't guarantee anything.
%
%
%
% ^^A -----------------------------
%
% \section{Options}
% \DescribeEnv{dvi}
% \DescribeEnv{nodvi}
% With Option |dvi| (the default), \Count{1} is used for the absolute
% page counter. This value is put into the \ftype{dvi} file and may be
% used by the \ftype{dvi} driver.
%
% Option |nodvi| uses a regular \LaTeX\ counter which will not
% show up elsewhere.
%
% No matter what counter is used, its name will always be |TotPages|,
% e.\,g. if you want to change its format to roman (why would you want
% to do this???).
%
% ^^A
%
%
%
% ^^A -----------------------------
%
% \section{Required packages}
% ^^A
% This package needs the \package{everyshi}
% package \cite{package:everyshi}.
%
%
% ^^A -----------------------------
%
% \StopEventually{^^A
%
% ^^A -----------------------------
%
% \section{Acknowledgements}
% ^^A
% This packages uses ideas inspired by
% Martin Schr\"oder's \package{count1to}
% package \cite{package:count1to}, Jeff Goldberg's \package{lastpage}
% package \cite{package:lastpage}, and the \package{lastpage} support
% contained in Sebastian Rahtz's \package{hyperref}
% package \cite{package:hyperref}.
%
%
% ^^A -----------------------------
%
% \begin{thebibliography}{HHHHHHHH\,1}
% \raggedright
% \bibitem[Goldberg]{package:lastpage}
% Jeff Goldberg.
% \newblock The \package{lastpage}-package.
% \newblock \url{CTAN: tex-archive/macros/latex/contrib/other/lastpage/}.
% \newblock \LaTeXe{} package.
% \bibitem[Knuth]{KnuthTeXa}
% Donald~E.\ Knuth.
% \newblock \emph{The {\TeX}Book}, volume~A of \emph{Computers
% and Typesetting}.
% \newblock Addison-Wes\-ley, 1986.
% \newblock Tenth printing, revised, June 1990.
% \bibitem[Rahtz]{package:hyperref}
% Sebastian Rahtz.
% \newblock Hypertext marks in \LaTeX.
% \newblock \url{CTAN: tex-archive/macros/latex/contrib/supported/hyperref/}.
% \newblock \LaTeXe{} package.
% \bibitem[Schr\"oder\,1]{package:count1to}
% Martin Schr\"oder.
% \newblock The \package{count1to} package.
% \newblock \url{CTAN: tex-archive/macros/latex/contrib/supported/ms/count1to.dtx}.
% \newblock \LaTeXe{} package.
% \bibitem[Schr\"oder\,2]{package:everyshi}
% Martin Schr\"oder.
% \newblock The \package{everyshi} package.
% \newblock \url{CTAN: tex-archive/macros/latex/contrib/supported/ms/everyshi.dtx}.
% \newblock \LaTeXe{} package.
% \end{thebibliography}
%
% }
%
%
% ^^A -----------------------------
%
% \section{The implementation}
% ^^A
% \setlength{\parindent}{0pt}
% We need the \package{everyshi} package.
% \begin{macrocode}
%<*package>
\ProvidesPackage{totpages}
[1999/07/13 v1.00 Totpages Package (muewi)]
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\RequirePackage{everyshi}[1994/12/09]
% \end{macrocode}
%
% The user can decide if the absolute page number should
% go to the \ftype{dvi} file or not, the default being yes:
% \begin{macrocode}
\newif\ifTotPagesToDvi\TotPagesToDvitrue
\DeclareOption{dvi}{\TotPagesToDvitrue}
\DeclareOption{nodvi}{\TotPagesToDvifalse}
\ProcessOptions*\relax
% \end{macrocode}
%
% \begin{environment}{TotPages}
% If the counter is to go to the \ftype{dvi} file, we have to use a
% fixed count register: \Count{1}. (For this to work, we have to copy
% a few internals from latex.ltx.) Otherwise, we'll just use a
% conventional \LaTeX\ counter.
% \begin{macrocode}
\ifTotPagesToDvi
\countdef\c@TotPages=1 \c@TotPages=0
\let\cl@TotPages\@empty
\newcommand\theTotPages{\arabic{TotPages}}
\else
\newcounter{TotPages}
\fi
% \end{macrocode}
% To save a bit of space,
% the control sequences for the options are removed.
% \begin{macrocode}
\let\ifTotPagesToDvi\undefined
\let\TotPagesToDvitrue\undefined
\let\TotPagesToDvifalse\undefined
% \end{macrocode}
% When shipout occurs, we step the counter.
% \begin{macrocode}
\EveryShipout{\stepcounter{TotPages}}
% \end{macrocode}
% Nothing outside this package should mess with that counter, of course.---
% At the beginning of the document, we should be able to find out
% what packages are used and warn about some we aren't sure we can
% co-operate with:
%
% \begin{macrocode}
\AtBeginDocument{%
\@ifpackageloaded{count1to}{%
\PackageError{totpages}{%
Can't use both, count1to and totpages}{%
You should read the documentation of these packages and\MessageBreak
decide which one is more appropriate for your intentions.}
}{}%
\@ifpackageloaded{lastpage}{%
\PackageError{totpages}{%
Can't use both, lastpage and totpages}{%
You should read the documentation of these packages and\MessageBreak
decide which one is more appropriate for your intentions.}
}{}%
% \end{macrocode}
% We define a command which will be executed at the end of the document,
% but if anybody did it already, we simply hope they did it right.
% \begin{macrocode}
\ifx\undefined\TotPages@putlabel
% \end{macrocode}
% If the package \package{hyperref} is used,
% we think we know what to do to produce a correct hyperlink label.
% (This code was obtained from the \package{lastpage} support of
% \package{hyperref} itself.)
% \begin{macrocode}
\@ifpackageloaded{hyperref}{%
\ifx\undefined\Hy@WarningNoLine
\let\Hy@WarningNoLine\hyper@warn
\fi
\ifHy@pageanchor
\else
\Hy@WarningNoLine{%
The \string\ref{TotPages} link doesn't work\MessageBreak
with disabled option `pageanchor'%
}%
\fi
\def\TotPages@putlabel{%
\addtocounter{page}{-1}%
\if@filesw
\begingroup
\let\@number\@firstofone
\ifHy@pageanchor
\ifHy@hypertexnames
\ifHy@plainpages
\def\Hy@temp{\arabic{page}}%
\else
\let\textlatin\@firstofone
\edef\Hy@temp{\thepage}%
\fi
\else
\def\Hy@temp{\the\Hy@pagecounter}%
\fi
\fi
\immediate\write\@mainaux{%
\string\newlabel
{TotPages}{{\theTotPages}{\thepage}{}{%
\ifHy@pageanchor page.\Hy@temp\fi}{}}%
}%
\endgroup
\fi
\addtocounter{page}{1}%
}%
% \end{macrocode}
% Otherwise, we just put a label here, but |\label| may refer
% to some random counter just stepped some time ago, so we have
% produce it ourselves.
% \begin{macrocode}
}{%
\def\TotPages@putlabel{%
\addtocounter{page}{-1}%
\immediate\write\@mainaux{%
\string\newlabel{TotPages}{{\theTotPages}{\thepage}}%
}%
\addtocounter{page}{1}%
}%
}%
\fi
}
% \end{macrocode}
% Before we write the value to the auxfile we call a \cs{clearpage}
% to force all pending floats to be output.
% To do this we have to be sure to be the \emph{last} macro called by
% \cs{AtEndDocument}---but this is nearly impossible to assure,
% so we try to do our very best and set our
% entry for \cs{AtEndDocument} at |\begin{document}| by using
% \cs{AtBeginDocument}.
% \begin{macrocode}
\AtBeginDocument{%
\AtEndDocument{%
% \end{macrocode}
% The label \texttt{TotPages} is put onto the last page
% of the document and holds the total number of pages of the
% document, i.\,e., the value of |TotPages|.
% \begin{macrocode}
\clearpage
\TotPages@putlabel
}%
}
% \end{macrocode}
% \end{environment}
% \begin{macrocode}
%</package>
% \end{macrocode}
%
% ^^A -----------------------------
%
% \Finale
%
% \PrintChanges\PrintIndex
% ^^A Make sure that the index is not printed twice
% ^^A (ltxdoc.cfg might have a second \PrintIndex command)
% \let\PrintChanges\relax
% \let\PrintIndex\relax
|