summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/lastpage/lastpage.dtx
blob: 84653e15c66f8bf1e6ab140b5cbe9f1c7ec9ce15 (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
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
\def\filename{lastpage}
\def\fileversion{v0.1b}
\def\filedate{1994/06/25}
\def\docdate {1994/07/20}

% \CheckSum{33}
%% \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
%% Allow for things like |page \thepage\ of \pageref{LastPage}| to
%% get `page 5 of 23'
%\fi
%
% \DoNotIndex{\documentclass,\usepackage,\hfuzz,\small,\tt,\begin,\end}
% \DoNotIndex{\NeedsTeXFormat,\filedate,\fileversion,\DoNotIndex}
% \DoNotIndex{\def,\divide,\advance,\multiply}
% \DoNotIndex{\",\-,\H}
% \DoNotIndex{\ifthenelse,\and,\equal,\whiledo,\if,\fi}
% \DoNotIndex{\CodelineIndex,\EnableCrossrefs,\DisableCrossrefs}
% \DoNotIndex{\DocInput,\AltMacroFont}
% \DoNotIndex{\RecordChanges,\OnlyDescription}
%
% \title{The \texttt{lastpage} package\thanks{This file
%        has version number \fileversion, last
%        revised \filedate, documentation dated \docdate.}}
% \author{Jeff Goldberg\\
% \texttt{goldberg@nytud.hu}}
% \date{\docdate}
%
% \maketitle
%
%
% \begin{abstract}
%   This package puts the label \texttt{LastPage} into the
%   \texttt{.aux} file, allowing the user to use references
%   to the last page of a document.  This might be
%   particularly useful in places like headers or footers.
% \end{abstract}
%
% \section{Introduction}
%
% For various draft forms it is desirable to have a page reference
% to the last page so that page footers, for example, could contain
% something like ``page $N$ of $K$', where $N$ is the current page
% and $K$ is the last page.
% 
% This package defines a label, \texttt{LastPage}, which the user
% can refer to using the |\pageref| command.
% 
% \section{The user interface}
%
% Just load it with by placing
% \begin{verbatim}
% \usepackage{lastpage}
%\end{verbatim}
% in the preamble of your \LaTeXe\ source file.
%
%\DescribeMacro{LastPage}
% Once that is loaded, you will be able to make reference anywhere
% in your text to the label \texttt{LastPage}.  In particular you
% can either use the \textsf{fancyheadings} package, or your own
% redefinitions of the page headings and footings to get a reference
% to the last page, as in the example below.
% \begin{verbatim}
% \makeatletter
% \renewcommand{\@evenfoot}%
%    {\normalsize\slshape DRAFT \today\hfil
%     \upshape page {\thepage} of \pageref{LastPage}}
% \renewcommand{\@oddfoot}{\@evenfoot}
% \makeatother
%\end{verbatim}
% to get footers like ``\mbox{\textsl{DRAFT \today}\hspace{1cm}page 5 of 23}''
% into your document.  Or for text like,
% \begin{verbatim}
%   Hey, you don't write a \pageref{LastPage}~page letter every day,
%   you know.
%\end{verbatim}
% to get
% \begin{quote}
%   Hey, you don't write a 12~page letter every day,
%   you know.
% \end{quote}
% 
% \section{A few warnings}\label{sec:warn}
%
% This package uses the \LaTeXe\ directive of |\AtEndDocument|.  If
% you use other packages that do the same and actually put material
% at the end, then it is important to load \textsf{lastpage} after
% such other packages if you want the true last page.  That is
% if a package \textsf{xyzzy} uses |\AtEndDocument| to put
% out two pages of material at the end of the document, then
% to get the last page to be the page number of the second of those
% pages you need to load \textsf{lastpage} after \textsf{xyzzy} makes
% its call to |\AtEndDocument|
% 
% \subsection{Interaction with \textsf{endfloat}}\label{sec:endfloat}
%
% Version 2.0 (and earlier) of \textsf{endfloat} actually redefine
% the |\enddocument|, and so interfere drastically with the \LaTeXe\
% commands which make use of |\AtEndDocument|.  A newer version
% of \textsf{endfloat} exists
% in modern documentation form, which should be available from the same
% source where you received this file.
% 
% If you want your \texttt{LastPage} to label the last page of
% these end floats, you need to load \textsf{lastpage} after
% loading \textsf{endfloat}.  If, on the other hand, you want
% \texttt{LastPage} to refer to the last page, exclusive of the
% the floats at the end, then load in the reverse order.  For
% each of these, you will still need the modified version
% of \textsf{endfloat}.
%
% Other \LaTeX209 packages also seem to like to redefine |\enddocument|.
% In addition to the old \textsf{endfloat}, \textsf{harvard} comes to mind.
% All of these will need to be modified swiftly.  (How did these ever
% work together before? 
% I can't believe that nobody wanted harvard bibliography
% style and floats at the end before!)
%
% \subsection{General ordering and wish list}\label{sec:order}
%
% I believe that the output of a \LaTeXe\ run should be independent
% of the order in which package are loaded.  It would be possible
% to set this up, but it would take coordiniation of all package
% writers who use |\AtEndDocument|.  The actual call to |\AtEndDocument|
% would not occur during package loading, but some new command,
% like |\ExecuteAtEndDocument| would be called by the user after
% all such packages are loaded, with tags for each thing in the
% packages, so something like
% \begin{verbatim}
%   \usepackage{lastpage}
%   \usepackage{endfloat,xyzzy}
%   \ExecuteAtEndDocument{endfloat, xyzzy, lastpage}
%\end{verbatim}
% and the order of End Document material would be the \textsf{endfloat}
% material, followed by \textsf{xyzzy}, and finally by \textsf{lastpage}.
% 
% It is often the case that the same formats for which one
% must put tables and figure at the end, are the ones in which
% endnotes are also required.  If one wants to use \textsf{lastpage}
% here as well, then it is easy to get to three separate uses
% of |\AtEndDocument| (assuming one uses that for the endnotes as
% well).  Clearly it is not safe for any package writer or user
% to assume that no material will follow what they put into
% and |\AtEndDocument|.  This, in addition to the ordering, is
% a good reason to develop safe practices for use of this
% very powerful tool.
% 
% I will have to wait until someone else develops such a system, but
% I will gladly modify \textsf{lastpage} to comply with it.  Until then
% I will include a message
% which begins with \texttt{AED}
% in every usage of |\AtEndDocument|, and try to minimize any side
% effects my usage may have.
%
% \subsection{Ignorance is bliss}
%
% The author of this package is not only new to \LaTeXe, but also
% to \LaTeX209.  If I have duplicated something that already
% exists, forgive me.  I have always wanted this in \PlainTeX,
% but never had the robust cross referencing that \LaTeX\ provides.
% Now that I have made the big switch, I jumped at the chance
% to get this done.
%
%\StopEventually{\PrintIndex\PrintChanges}
%
% \section{The documentation driver file}
%
% The next bit of code contains the documentation driver file for
% \TeX{}, i.e., the file that will produce the documentation you are
% currently reading. It will be extracted from this file by the
% \texttt{docstrip} program, That is, run \LaTeX\ on \texttt{docstrip}
% and specify the \texttt{driver} option when \texttt{docstrip}
% asks for options.
%    \begin{macrocode}
%<*driver>
\documentclass[11pt]{ltxdoc}
\setlength\hfuzz{1pt}    % ignore slight overfulls
\CodelineIndex
\EnableCrossrefs
%\DisableCrossrefs   % Say \DisableCrossrefs if index is ready
%\RecordChanges       % Gather update information
%\OnlyDescription    % comment out for implementation details
\begin{document}
   \DocInput{lastpage.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%
% \section{The implementation}
%
% We start by checking if this file was already loaded. If not we
% identify the current version.
% \changes{v0.99a}{1994/06/17}{First shot}
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
%    \begin{macrocode}
\ProvidesPackage{lastpage}[\filedate\space\fileversion\space
             LaTeX2e package for refs to last page number (JPG)]
%    \end{macrocode}
%
% \begin{macro}{\lastpage@putlabel}
% Simply using |\label| wouldn't work; because labels wait
% for the output routines to work, and there may not be any
% more invocations of the output routines.
% To force the write out we need to do an |\immediate| write.
% Since the last page has been output, we are on the page after
% the last.  I subtract one from the page counter.  After the writeout
% I restore it again since there might be other things At the End
% of Document still to do.
%    \begin{macrocode} 
\def\lastpage@putlabel{\addtocounter{page}{-1}%
   \immediate\write\@auxout{\string
   \newlabel{LastPage}{{}{\thepage}}}%
   \addtocounter{page}{1}}
%    \end{macrocode}
% \end{macro}
%
%  The call to |\AtEndDocument| is simple.  I put in a |\message| to
% show what order thing are called done in (see section~\ref{sec:endfloat}).
%    \begin{macrocode} 
\AtEndDocument{%
   \message{AED: lastpage setting LastPage}%
   \clearpage\lastpage@putlabel}%
%</package>
%    \end{macrocode}
% 
% \section{Things to be done}\label{sec:todo}
%
% \begin{itemize}
% \item Allow user to specify a given page number.
% \item Allow user to specify a string other than \texttt{LastPage}
%       for the reference.
% \item Work on better order control as discussed in section~\ref{sec:order}.
% \item Work on general conventions for using |\AtEndDocument| generally.
%       (see section~\ref{sec:order}).
% \end{itemize}
% 
% \Finale
%
\endinput