| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% File: lastpage.dtx |
| 4 |
% Version: 2025-08-14 v2.1h |
| 5 |
% Info: Refers to last page's name |
| 6 |
% |
| 7 |
% Copyright © 2010 - 2025 by |
| 8 |
% H.-Martin Münch <Martin dot Muench at Uni-Bonn dot de> |
| 9 |
% Portions of code copyrighted by other people as marked. |
| 10 |
% |
| 11 |
% This package was invented by Jeffrey P. Goldberg. |
| 12 |
% I thought that an enhancement was needed and therefore created the pageslts package, |
| 13 |
% https://ctan.org/pkg/pageslts. Nevertheless, for compatibility with existing |
| 14 |
% documents/packages as well as for the low amount of resources needed by the |
| 15 |
% lastpage package (no new counter!), I updated this package. |
| 16 |
% Thanks go to Jeffrey P. Goldberg for allowing me to do this. |
| 17 |
% |
| 18 |
% While this package allows for things like "Page \thepage{} of \pageref{LastPage}" |
| 19 |
% to get "Page 7 of 9" or "Page VII of IX", |
| 20 |
% the NUMBER of pages is nowadays available from the kernel |
| 21 |
% (\@abspage@last, \thetotalpages, \PreviousTotalPages), |
| 22 |
% but with pages for example I to X and then 1 to 10, the number of pages would be~"20", |
| 23 |
% while the name of the last page is~"10". Decide what you need/want! |
| 24 |
% |
| 25 |
% This work may be distributed and/or modified under the |
| 26 |
% conditions of the LaTeX Project Public License, either |
| 27 |
% version 1.3c of this license or (at your option) any later |
| 28 |
% version. This version of this license is in |
| 29 |
% https://www.latex-project.org/lppl/lppl-1-3c.txt |
| 30 |
% and the latest version of this license is in |
| 31 |
% https://www.latex-project.org/lppl.txt |
| 32 |
% and version 1.3c or later is part of all distributions of |
| 33 |
% LaTeX version 2005-12-01 or later. |
| 34 |
% |
| 35 |
% This work has the LPPL maintenance status "maintained". |
| 36 |
% |
| 37 |
% The Current Maintainer of this work is H.-Martin Münch. |
| 38 |
% |
| 39 |
% This work consists of the main source file lastpage.dtx, |
| 40 |
% the README, and the derived files |
| 41 |
% lastpage.sty, lastpage209.sty, lastpage2e.sty, |
| 42 |
% lastpageclassic.sty, lastpagemodern.sty, |
| 43 |
% lastpage.pdf, lastpage.ins, lastpage.drv, |
| 44 |
% lastpage-example.tex, lastpage-example.pdf. |
| 45 |
% |
| 46 |
% "lastpage" is available on CTAN: |
| 47 |
% https://ctan.org/pkg/lastpage |
| 48 |
% |
| 49 |
% Also a TDS.ZIP file is provided that contains all the files |
| 50 |
% already sorted in a TDS tree: |
| 51 |
% https://mirror.ctan.org/install/macros/latex/contrib/lastpage.tds.zip |
| 52 |
% |
| 53 |
%<*ignore> |
| 54 |
\begingroup |
| 55 |
\catcode123=1 % |
| 56 |
\catcode125=2 % |
| 57 |
\def\x{LaTeX2e}% |
| 58 |
\expandafter\endgroup |
| 59 |
\ifcase 0\ifx\install y1\fi\expandafter |
| 60 |
\ifx\csname processbatchFile\endcsname\relax\else1\fi |
| 61 |
\ifx\fmtname\x\else 1\fi\relax |
| 62 |
\else\csname fi\endcsname |
| 63 |
%</ignore> |
| 64 |
%<*install> |
| 65 |
\input docstrip.tex |
| 66 |
\Msg{**********************************************************************} |
| 67 |
\Msg{* Installation *} |
| 68 |
\Msg{* Package: lastpage 2025-08-14 v2.1h Refers to last page's name (HMM)*} |
| 69 |
\Msg{**********************************************************************} |
| 70 |
|
| 71 |
\keepsilent |
| 72 |
\askforoverwritefalse |
| 73 |
|
| 74 |
\let\MetaPrefix\relax |
| 75 |
\preamble |
| 76 |
|
| 77 |
This is a generated file. |
| 78 |
|
| 79 |
Project: lastpage |
| 80 |
Version: 2025-08-14 v2.1h |
| 81 |
Info: Refers to last page's name |
| 82 |
|
| 83 |
Copyright (C) 2010 - 2025 by |
| 84 |
H.-Martin Muench <Martin dot Muench at Uni-Bonn dot de> |
| 85 |
Portions of code copyrighted by other people as marked. |
| 86 |
|
| 87 |
This work may be distributed and/or modified under the |
| 88 |
conditions of the LaTeX Project Public License, either |
| 89 |
version 1.3c of this license or (at your option) any later |
| 90 |
version. This version of this license is in |
| 91 |
https://www.latex-project.org/lppl/lppl-1-3c.txt |
| 92 |
and the latest version of this license is in |
| 93 |
https://www.latex-project.org/lppl.txt |
| 94 |
and version 1.3c or later is part of all distributions of |
| 95 |
LaTeX version 2005-12-01 or later. |
| 96 |
|
| 97 |
This work has the LPPL maintenance status "maintained". |
| 98 |
|
| 99 |
The Current Maintainer of this work is H.-Martin Muench. |
| 100 |
|
| 101 |
This package was invented by Jeffrey P. Goldberg. |
| 102 |
I thought that an enhancement was needed and therefore created the pageslts package, |
| 103 |
https://ctan.org/pkg/pageslts. Nevertheless, for compatibility with existing |
| 104 |
documents/packages as well as for the low amount of resources needed by the |
| 105 |
lastpage package (no new counter!), I updated this package. |
| 106 |
Thanks go to Jeffrey P. Goldberg for allowing me to do this. |
| 107 |
|
| 108 |
While this package allows for things like "Page slash thepage{} of slash pageref{LastPage}" |
| 109 |
to get "Page 7 of 9" or "Page VII of IX", |
| 110 |
the NUMBER of pages is nowadays available from the kernel |
| 111 |
(slash @abspage@last, slash thetotalpages, slash PreviousTotalPages), |
| 112 |
but with pages for example I to X and then 1 to 10, the number of pages would be "20", |
| 113 |
while the name of the last page is "10". Decide what you need/want! |
| 114 |
|
| 115 |
This work consists of the main source file lastpage.dtx, |
| 116 |
the README, and the derived files |
| 117 |
lastpage.sty, lastpage209.sty, lastpage2e.sty, |
| 118 |
lastpageclassic.sty, lastpagemodern.sty, |
| 119 |
lastpage.pdf, lastpage.ins, lastpage.drv, |
| 120 |
lastpage-example.tex, lastpage-example.pdf. |
| 121 |
|
| 122 |
In memoriam |
| 123 |
Claudia Simone Barth + 1996-01-30 |
| 124 |
Tommy Muench + 2014-01-02 |
| 125 |
Hans-Klaus Muench + 2014-08-24 |
| 126 |
|
| 127 |
\endpreamble |
| 128 |
\let\MetaPrefix\DoubleperCent |
| 129 |
|
| 130 |
\generate{% |
| 131 |
\file{lastpage.ins}{\from{lastpage.dtx}{install}}% |
| 132 |
\file{lastpage.drv}{\from{lastpage.dtx}{driver}}% |
| 133 |
\usedir{tex/latex/lastpage}% |
| 134 |
\file{lastpage.sty}{\from{lastpage.dtx}{package}}% |
| 135 |
\file{lastpage209.sty}{\from{lastpage.dtx}{lastpage209}}% |
| 136 |
\file{lastpage2e.sty}{\from{lastpage.dtx}{lastpage2e}}% |
| 137 |
\file{lastpageclassic.sty}{\from{lastpage.dtx}{lastpageclassic}}% |
| 138 |
\file{lastpagemodern.sty}{\from{lastpage.dtx}{lastpagemodern}}% |
| 139 |
\usedir{doc/latex/lastpage}% |
| 140 |
\file{lastpage-example.tex}{\from{lastpage.dtx}{example}}% |
| 141 |
} |
| 142 |
|
| 143 |
\catcode32=13\relax% active space |
| 144 |
\let =\space% |
| 145 |
\Msg{************************************************************************} |
| 146 |
\Msg{*} |
| 147 |
\Msg{* To finish the installation you have to move the following} |
| 148 |
\Msg{* file into a directory searched by TeX:} |
| 149 |
\Msg{*} |
| 150 |
\Msg{* lastpage.sty, lastpage209.sty, lastpage2e.sty,} |
| 151 |
\Msg{* lastpageclassic.sty, and lastpagemodern.sty} |
| 152 |
\Msg{*} |
| 153 |
\Msg{* To produce the documentation run the file `lastpage.drv'} |
| 154 |
\Msg{* through (pdf)LaTeX, e.g.} |
| 155 |
\Msg{* pdflatex lastpage.drv} |
| 156 |
\Msg{* makeindex -s gind.ist lastpage.idx} |
| 157 |
\Msg{* pdflatex lastpage.drv} |
| 158 |
\Msg{* makeindex -s gind.ist lastpage.idx} |
| 159 |
\Msg{* pdflatex lastpage.drv} |
| 160 |
\Msg{*} |
| 161 |
\Msg{* At least three runs are necessary e.g. to get the} |
| 162 |
\Msg{* references right!} |
| 163 |
\Msg{*} |
| 164 |
\Msg{* Happy TeXing!} |
| 165 |
\Msg{*} |
| 166 |
\Msg{************************************************************************} |
| 167 |
|
| 168 |
\endbatchfile |
| 169 |
%</install> |
| 170 |
%<*ignore> |
| 171 |
\fi |
| 172 |
%</ignore> |
| 173 |
% |
| 174 |
% \section{The documentation driver file} |
| 175 |
% |
| 176 |
% The next bit of code contains the documentation driver file for |
| 177 |
% \TeX , i.\,e., the file that will produce the documentation you |
| 178 |
% are currently reading. It will be extracted from this file by the |
| 179 |
% \texttt{docstrip} programme. That is, run \LaTeX{} on \texttt{docstrip} |
| 180 |
% and specify the \texttt{driver} option when \texttt{docstrip} |
| 181 |
% asks for options. |
| 182 |
% |
| 183 |
% \begin{macrocode} |
| 184 |
%<*driver> |
| 185 |
\NeedsTeXFormat{LaTeX2e}[2024-11-01] |
| 186 |
\ProvidesFile{lastpage.drv}[2025-08-14 v2.1h Refers to last page's name (HMM)] |
| 187 |
\documentclass{ltxdoc}[2024/02/08]% v2.1j Standard LaTeX documentation class |
| 188 |
\usepackage{holtxdoc}[2019/12/09]% v0.30 Private additional ltxdoc support (HO) |
| 189 |
\hypersetup{% |
| 190 |
pdfsubject={Refers to last page's name (HMM; JPG)},% |
| 191 |
pdfkeywords={LaTeX, lastpage, last page, page number, page name},% |
| 192 |
pdfencoding=auto,% |
| 193 |
pdflang={en},% |
| 194 |
breaklinks=true,% |
| 195 |
linktoc=all,% |
| 196 |
pdfstartview=FitH,% |
| 197 |
pdfpagelayout=OneColumn,% |
| 198 |
bookmarksnumbered=true,% |
| 199 |
bookmarksopen=true,% |
| 200 |
bookmarksopenlevel=2,% |
| 201 |
pdfmenubar=true,% |
| 202 |
pdftoolbar=true,% |
| 203 |
pdfwindowui=true,% |
| 204 |
pdfnewwindow=true% |
| 205 |
} |
| 206 |
\CodelineIndex |
| 207 |
\hyphenation{every-thing} |
| 208 |
\begin{document} |
| 209 |
\DocInput{lastpage.dtx}% |
| 210 |
\end{document} |
| 211 |
%</driver> |
| 212 |
% \end{macrocode} |
| 213 |
% \fi |
| 214 |
% |
| 215 |
% \GetFileInfo{lastpage.drv} |
| 216 |
% |
| 217 |
% \begingroup |
| 218 |
% \def\x{\#,\$,\^,\_,\~,\ ,\&,\{,\},\%}% |
| 219 |
% \makeatletter |
| 220 |
% \@onelevel@sanitize\x |
| 221 |
% \expandafter\endgroup |
| 222 |
% \expandafter\DoNotIndex\expandafter{\x} |
| 223 |
% \expandafter\DoNotIndex\expandafter{\string\ } |
| 224 |
% \begingroup |
| 225 |
% \makeatletter |
| 226 |
% \lccode`9=32\relax |
| 227 |
% \lowercase{%^^A |
| 228 |
% \edef\x{\noexpand\DoNotIndex{\@backslashchar9}}%^^A |
| 229 |
% }%^^A |
| 230 |
% \expandafter\endgroup\x |
| 231 |
% |
| 232 |
% \DoNotIndex{\@auxout,\@evenfoot,\@firstofone,\@firstoftwo,\@gobble@om,\@gobble@som,\@ifl@t@r,\IfFormatAtLeastF,\IfFormatAtLeastTF,% |
| 233 |
% \@ifpackagelater,\@ifpackageloaded,\IfPackageAtLeastF,\IfPackageLoadedF,\IfPackageLoadedT,\IfPackageLoadedTF,% |
| 234 |
% \@ifundefined,\@kernel@reserved@label@data,\@mainaux,\@number,\@oddfoot,% |
| 235 |
% \addtocounter,\AddToHook,\arabic,\begin,% |
| 236 |
% \bigskip,\clearpage,\csname,\detokenize,\documentclass,\EdefUnescapeString,\empty,\end,% |
| 237 |
% \endcsname,\enddocument,\expanded,\ExplSyntaxOff,\ExplSyntaxOn,\fmtversion,% |
| 238 |
% \g,\gdef,\glossary,\here,\hfil,\Hy@temp,\Hy@unicodefalse,\Hy@EveryPageAnchor,% |
| 239 |
% \hypersetup,\if,\if@filesw,\if@nobreak,\ifHy@hypertexnames,\ifHy@pageanchor,\ifHy@plainpages,% |
| 240 |
% \ifdim,\ifnum,\ifvmode,\ifx,\immediate,\index,\input,% |
| 241 |
% \label,\lastpage,\lastpage-example.tex,\lastpage.dtx,\lastpage.sty,\lastpagee.sty,% |
| 242 |
% \lastpageclassic.sty,\lastpagemodern.sty,\LaTeX,\LaTeX-kernel,\listfiles,% |
| 243 |
% \makeatletter,\makeatother,\markboth,\meaning,\mbox,\message,\MessageBreak,% |
| 244 |
% \NeedsTeXFormat,\newcommand,\newcounter,\newline,\newpage,\nobreak,% |
| 245 |
% \noindent,\normalsize,\numexpr,\origenddocument,\PackageError,\PackageNoteNoLine,\PackageWarning,% |
| 246 |
% \PackageWarningNoLine,\pagenumbering,\pageref,\pdfstringdef,\protect,\ProvidesPackage,% |
| 247 |
% \qquad,\renewcommand,\RequirePackage,\section,\ShowHook,\slshape,\smallskip,\space,\test,\textbf,% |
| 248 |
% \textit,\textquotedblleft,\textquotedblright,\textsf,\texttt,\the,\thepage,% |
| 249 |
% \today,\upshape,\url,\usepackage,\value,\verb,\wd,\write,\xlastpage@rmpage,\xxlastpage@rmpage} |
| 250 |
% |
| 251 |
% \title{The \xpackage{lastpage} package} |
| 252 |
% \author{H.-Martin Münch\\\xemail{Martin.Muench at Uni-Bonn.de}\\ |
| 253 |
% invented by Jeffrey P. Goldberg\\\xemail{jeffrey+news at goldmark.org}} |
| 254 |
% \date{2025-08-14 v2.1h} |
| 255 |
% \maketitle |
| 256 |
% |
| 257 |
% \begin{abstract} |
| 258 |
% \noindent This \LaTeX{} package puts the label \texttt{LastPage} |
| 259 |
% at the end of the document into the \xfile{.aux} file, |
| 260 |
% allowing the user to refer to the last page of a document. |
| 261 |
% This might be particularly useful in places like headers or footers.~--\newline |
| 262 |
% While this package allows for things like\newline |
| 263 |
% \hbox{\textquotedblleft Page} \hbox{|\thepage{}|} of |\pageref{LastPage}|\textquotedblright{} |
| 264 |
% to get \textquotedblleft Page 7 of 9\textquotedblright{} or |
| 265 |
% \textquotedblleft Page VII of IX\textquotedblright, |
| 266 |
% the \emph{number} of pages is nowadays available from the kernel |
| 267 |
% (|\@abspage@last|, |\thetotalpages|, |\PreviousTotalPages|), |
| 268 |
% but when more than one page numbering scheme is used |
| 269 |
% (for example pages I~to X and then 1~to 10, |
| 270 |
% thus number of pages \hbox{\textquotedblleft 20\textquotedblright ,} |
| 271 |
% but name of the last page \hbox{\textquotedblleft 10\textquotedblright ),} |
| 272 |
% or another package has output after this package, |
| 273 |
% or the page numbers exceed a certain range, |
| 274 |
% there might be problems, which can be solved by using the |
| 275 |
% \xpackage{pageslts} package instead. |
| 276 |
% \end{abstract} |
| 277 |
% |
| 278 |
% \bigskip |
| 279 |
% |
| 280 |
% \noindent Disclaimer for web links: The author is not responsible for any contents |
| 281 |
% referred to in this work unless having full knowledge of illegal contents. |
| 282 |
% If any damage occurs by the use of information presented there, |
| 283 |
% only the author of the respective pages might be liable, |
| 284 |
% not the one who has referred to those pages. |
| 285 |
% \newpage |
| 286 |
% \tableofcontents |
| 287 |
% |
| 288 |
% \section{Introduction} |
| 289 |
% \indent This \LaTeX{} package puts the label \texttt{LastPage} |
| 290 |
% (at end of the document via hook |enddocument/afterlastpage|, |
| 291 |
% for older formats via |\AtEndDocument|, for \LaTeX2.09{} via |
| 292 |
% redefining |\enddocument|) into the \xfile{aux} file, |
| 293 |
% allowing the user to refer to the last page of a document via |
| 294 |
% |\pageref{LastPage}|. This might be particularly useful |
| 295 |
% in places like headers or footers. |
| 296 |
% |
| 297 |
% \bigskip |
| 298 |
% |
| 299 |
% This package was invented by \textbf{Jeffrey P. Goldberg}, |
| 300 |
% and is now maintained by \textsc{H.-Martin Münch}. A~big |
| 301 |
% \textquotedblleft Thank you!\textquotedblright{} to |
| 302 |
% \textsc{Jeffrey P. Goldberg} for granting this. |
| 303 |
% |
| 304 |
% \bigskip |
| 305 |
% |
| 306 |
% If you are more ambitious in respect to your aims with this package, |
| 307 |
% you might want to have a look at the \xpackage{pageslts} package |
| 308 |
% (see section~\ref{sec:Alternatives}: Alternatives). |
| 309 |
% |
| 310 |
% \section{Usage} |
| 311 |
% \indent Just load the package placing |
| 312 |
% \begin{quote} |
| 313 |
% |\usepackage{lastpage}| |
| 314 |
% \end{quote} |
| 315 |
% \noindent in the preamble of your source file |
| 316 |
% (or |\input{lastpage.sty}| if |\usepackage| is unknown). |
| 317 |
% |
| 318 |
% \indent For example for various draft forms it is desirable to have a |
| 319 |
% page reference to the last page, so that e.\,g.\ page footers can |
| 320 |
% contain something like \textquotedblleft page $N$ of $K$\textquotedblright, |
| 321 |
% where $N$ is the current page and $K$ is the last page. Once the package |
| 322 |
% is loaded, anywhere in the text references can be made to the label |
| 323 |
% \texttt{LastPage}. In particular one can use the \xpackage{fancyhdr} |
| 324 |
% or \xpackage{nccfancyhdr} package, or redefinitions of the page headings |
| 325 |
% and footings to get a reference to the last page. |
| 326 |
% |
| 327 |
% \noindent In your document the code |
| 328 |
% \begin{verbatim} |
| 329 |
% \makeatletter |
| 330 |
% \renewcommand{\@evenfoot}{% |
| 331 |
% \normalsize\slshape DRAFT \today\hfil \upshape % |
| 332 |
% page \thepage{} of \pageref{LastPage}} |
| 333 |
% \renewcommand{\@oddfoot}{\@evenfoot} |
| 334 |
% \makeatother |
| 335 |
%\end{verbatim} |
| 336 |
% \noindent creates footers like\smallbreak |
| 337 |
% \textquotedblleft\mbox{\textsl{DRAFT \today}\hspace{1cm}page 7 of 9}\textquotedblright\smallbreak |
| 338 |
% \noindent in the compiled document (cf.~the \texttt{lastpage-example} file).\newline |
| 339 |
% If the \xpackage{hyperref} package is used, the references are hyperlinked |
| 340 |
% to their aims. If these hyperlinks shall be suppressed, |\pageref*{...}| |
| 341 |
% instead of |\pageref{...}| can be used.\bigbreak |
| 342 |
% |
| 343 |
% The \xpackage{lastpage} package does not provide the words |
| 344 |
% \textquotedblleft page\textquotedblright{} or \textquotedblleft of\textquotedblright{}, |
| 345 |
% but e.\,g.\ the \xclass{handout} class uses \textquotedblleft of\textquotedblright{} in |
| 346 |
% the definition of the footer. (In the \texttt{lastpage-example} also |
| 347 |
% |\@evenfoot| is redefined, but it is not the \xpackage{lastpage} \emph{package} |
| 348 |
% redefining this.) If you want to change \textquotedblleft page\textquotedblright{} or |
| 349 |
% \textquotedblleft of\textquotedblright{} (e.\,g.\ to another language), you therefore |
| 350 |
% have got to look in the used class/package(s)/preamble instead of in the |
| 351 |
% \xpackage{lastpage} package.\bigbreak |
| 352 |
% |
| 353 |
% If the total \emph{number} of pages of a document is needed, |
| 354 |
% the kernel already gives this by |\makeatletter\@abspage@last\makeatother|, |
| 355 |
% |\thetotalpages|, and |\PreviousTotalPages| (needing at least two compiler runs). |
| 356 |
% |
| 357 |
% \section{Some \textsc{Warnings}\label{sec:warn}} |
| 358 |
% \subsection{\texttt{\textbackslash AtEndDocument}\label{ssec:aed}} |
| 359 |
% \indent {\bfseries |\AtEndDocument| is not used by the \pkg{lastpagemodern.sty} |
| 360 |
% version of the lastpage package, requiring \LaTeX -format 2024-11-01 |
| 361 |
% or newer. Instead |\AddToHook{enddocument/afterlastpage}| is used |
| 362 |
% and the problem does not arise.} |
| 363 |
% \bigskip |
| 364 |
% |
| 365 |
% \pkg{lastpageclassic.sty} uses |\AtEndDocument| and |
| 366 |
% \pkg{lastpage209.sty} redefines \linebreak |\enddocument|. |
| 367 |
% The last two cases are problematic:\newline |
| 368 |
% The output of a \LaTeXe{} run is not independent of the order |
| 369 |
% in which the packages are loaded. It is often the case that the same |
| 370 |
% formats for which one must put tables and figure at the end, |
| 371 |
% are the ones in which endnotes are also required. |
| 372 |
% If one wants to use |\AtEndDocument| here as well (as done for |
| 373 |
% |\pageref{LastPage}|), then it is easy to get to three separate |
| 374 |
% uses of |\AtEndDocument| (assuming one uses this for the endnotes |
| 375 |
% as well). Clearly it is not safe for any package writer or user |
| 376 |
% to assume that no material will follow what they put into |
| 377 |
% |\AtEndDocument|. Therefore a message, which begins with |
| 378 |
% \texttt{AED}, is included in every usage of |\AtEndDocument|. |
| 379 |
% \xpackage{lastpage} uses |\AtEndDocument{|\ldots|\clearpage|\ldots|}|, thus\newline |
| 380 |
%|\usepackage{lastpage}|\ldots|\AtEndDocument{|\textit{something}|}| |
| 381 |
% will place \textit{something} after the |\clearpage|. To place it earlier, use\newline |
| 382 |
% |\AtEndDocument{|\textit{something}|}|\ldots|\usepackage{lastpage}|. |
| 383 |
% If the \textit{something} is not known before |\usepackage{lastpage}|, |
| 384 |
% you can use for example |
| 385 |
% \begin{verbatim} |
| 386 |
% ... |
| 387 |
% \def\beforeLastpageClearpage{\relax} |
| 388 |
% \AtEndDocument{\beforeLastpageClearpage} |
| 389 |
% \usepackage{lastpage} |
| 390 |
% \begin{document} |
| 391 |
% ... |
| 392 |
% \def\beforeLastpageClearpage{\textit{something}}% |
| 393 |
% ... |
| 394 |
% \end{document} |
| 395 |
% \end{verbatim} |
| 396 |
% (might need a protected and/or expanded |\def|). When |\clearpage| leads |
| 397 |
% to some output, |\clearpage\textit{something}| instead of |\textit{something}| |
| 398 |
% might be wanted. |
| 399 |
% \newpage |
| 400 |
% |
| 401 |
% \subsection{Interaction with ancient versions of the \xpackage{endfloat} package\label{sec:endfloat}} |
| 402 |
% |
| 403 |
% \indent {\bfseries |\AtEndDocument| is not used by the \pkg{lastpagemodern.sty} |
| 404 |
% version of the lastpage package, requiring \LaTeX -format 2024-11-01 |
| 405 |
% or newer. Instead |\AddToHook{enddocument/afterlastpage}| is used |
| 406 |
% and the problem does not arise.} |
| 407 |
% |
| 408 |
% \bigskip |
| 409 |
% The \emph{ancient} version~2.0 (and earlier; 2.0~from 1992; |
| 410 |
% current version at the time of updating this documentation: 2.7~from 2019) |
| 411 |
% of the \xpackage{endfloat} package actually redefined the |\enddocument| command, |
| 412 |
% and so interfered drastically with the \LaTeXe{} commands which make use of |
| 413 |
% |\AtEndDocument|. |
| 414 |
% If you want your \texttt{LastPage} to label the last page of these end floats, |
| 415 |
% you need to load \xpackage{lastpage} after loading \xpackage{endfloat} |
| 416 |
% (or use \texttt{VeryLastPage} from the \xpackage{pageslts} package instead). |
| 417 |
% If, on the other hand, you \emph{want} \texttt{LastPage} to refer |
| 418 |
% to the (not so) last page, exclusive of the floats at the end, |
| 419 |
% then load in the reverse order. Independent from the order of |
| 420 |
% \xpackage{lastpage} and \xpackage{endfloat}, you will still need |
| 421 |
% a version of \xpackage{endfloat} later than 2.0 from 1992. |
| 422 |
% |
| 423 |
% Other \LaTeX2.09{} (!) packages also seem to like to redefine |
| 424 |
% |\enddocument|. In addition to the old \xpackage{endfloat}, |
| 425 |
% \xpackage{harvard} comes to mind. All of these will need to be |
| 426 |
% modified swiftly. |
| 427 |
% |
| 428 |
% \subsection{Page name instead of page number} |
| 429 |
% When any page numbering scheme other than \texttt{arabic} is used |
| 430 |
% at the page, which |\pageref{LastPage}| refers to, the \textit{name} |
| 431 |
% and not the \textit{number} of the page is given. For example, |
| 432 |
% \texttt{Alph} page numbering scheme and $10$ pages will give \texttt{J} instead of 10, |
| 433 |
% \texttt{Roman} page numbering scheme and $10$ pages will give \texttt{X} instead of 10, |
| 434 |
% and so on.\newline |
| 435 |
% \indent (The \xpackage{pageslts} package puts |\lastpageref{LastPages}| |
| 436 |
% (with \textbf{s} at the end) at your disposal for remediation.) |
| 437 |
% |
| 438 |
% \subsection{No write access to the \xfile{aux} file} |
| 439 |
% Some packages (e.\,g.\ \xpackage{tikz} and \xpackage{selectp}) sometimes prevent |
| 440 |
% the output to the \xfile{aux} file. In that case a warning is issued. This is |
| 441 |
% no problem as long as there is another compilation run where the label to the |
| 442 |
% last page can be placed via the \xfile{aux} file. |
| 443 |
% |
| 444 |
% \subsection[Wrong last page number with \textgreater 1 page numbering scheme]{% |
| 445 |
% Wrong last page number with more than one page numbering scheme} |
| 446 |
% When more than one page numbering scheme is used, |
| 447 |
% \texttt{LastPage} does not give the total \textbf{number} of pages |
| 448 |
% (even if \texttt{arabic} is the page numbering scheme of that page). |
| 449 |
% For example, for a document with VI+36 pages, it gives |
| 450 |
% \textquotedblleft 36\textquotedblright{} as reference to the last page. |
| 451 |
% While this is correct, the total number of pages is $42$.\newline |
| 452 |
% If the total \emph{number} of pages of a document is needed, |
| 453 |
% the kernel already gives this by |\makeatletter\@abspage@last\makeatother|, |
| 454 |
% |\thetotalpages|, and |\PreviousTotalPages|. |
| 455 |
% The \xpackage{pageslts} package puts |\lastpageref{LastPages}| |
| 456 |
% (with \textbf{s} at the end) at your disposal for remediation, |
| 457 |
% giving the number of pages and linking to the last page, if linking is provided |
| 458 |
% for examaple by the \xpackage{hyperref} package. |
| 459 |
% |
| 460 |
% \subsection{\texttt{\textbackslash addtocounter\{page\}\{\ldots\} and % |
| 461 |
% \texttt{\textbackslash setcounter\{page\}\{\ldots\}}}} |
| 462 |
% When the page number was manipulated by |\addtocounter{page}{...}| or |
| 463 |
% |\setcounter{page}{...}|, \texttt{LastPage} does not give the total |
| 464 |
% \textbf{number} of pages (even if \texttt{arabic} is the page numbering |
| 465 |
% scheme of that page).\newline |
| 466 |
% The \xpackage{pageslts} package puts |\lastpageref{LastPages}| |
| 467 |
% (with \textbf{s} at the end) at your disposal for remediation: |
| 468 |
% \texttt{LastPages} ignores page number manipulation. Also |\@abspage@last|, |
| 469 |
% |\thetotalpages|, and |\PreviousTotalPages| from the kernel |
| 470 |
% are not influenced by page number manipulation. |
| 471 |
% |
| 472 |
% \subsection{Page number reset by \texttt{\textbackslash pagenumbering\{\ldots\}}} |
| 473 |
% At a page numbering change the page number is reset to one. |
| 474 |
% Therefore \texttt{LastPage} does not give the total \textbf{number} of pages |
| 475 |
% (even if \texttt{arabic} is the page numbering scheme of that page). |
| 476 |
% Furthermore, now two pages have the same name.\newline |
| 477 |
% The \xpackage{pageslts} package does not only put |
| 478 |
% |\lastpageref{LastPages}| (with \textbf{s} at the end) at your disposal |
| 479 |
% for remediation: \texttt{LastPages} also ignores page number manipulation. |
| 480 |
% It furthermore offers the option |pagecontinue| to continue the |
| 481 |
% page numbering, when |\pagenumbering{...}| is used. |
| 482 |
% |
| 483 |
% \subsection{Last pages of different page numbering schemes} |
| 484 |
% |\pageref{LastPage}| refers to the (maybe not so) last page of the last |
| 485 |
% page numbering scheme. References to the respective last page of the other |
| 486 |
% page numbering schemes are not provided.\newline |
| 487 |
% The \xpackage{pageslts} package does this with labels |
| 488 |
% \texttt{pagesLTS.<numbering scheme>}, where \texttt{<numbering scheme>} is |
| 489 |
% e.\,g.\ arabic, roman, Roman, alph, or Alph.\linebreak |
| 490 |
% For fnsymbol please use |\lastpageref{pagesLTS.fnsymbol}| instead of\newline |
| 491 |
% |\pageref{pagesLTS.fnsymbol}|. |
| 492 |
% |
| 493 |
% \subsection{Current page} |
| 494 |
% The command |\thepage| gives the \textbf{name} of the current page |
| 495 |
% in the current page numbering scheme, which is different from the |
| 496 |
% current total/absolute page number e.\,g.\ with a second |
| 497 |
% page numbering scheme, |\addtocounter{page}{...}|, or |\setcounter{page}{...}|, |
| 498 |
% and it will not be an arabic number at all, |
| 499 |
% if the current page numbering scheme is not arabic.\newline |
| 500 |
% The \xpackage{pageslts} package provides the command |
| 501 |
% |\theCurrentPage| and for the current number of pages in the current |
| 502 |
% page numbering scheme\newline |
| 503 |
% |\theCurrentPageLocal|. The kernel already provides the |
| 504 |
% number of pages, which have been shipped out, as |\the\ReadonlyShipoutCounter|. |
| 505 |
% The current page is always |ReadonlyShipoutCounter +1|. |
| 506 |
% |
| 507 |
% \subsection{First page} |
| 508 |
% There is no special label at the first page. |
| 509 |
% (This is the \textbf{last}\textsf{page} package, after all.)\newline |
| 510 |
% The \xpackage{pageslts} package creates a label \texttt{pagesLTS.0} |
| 511 |
% at the first page of the document. |
| 512 |
% |
| 513 |
% \subsection{Page counter overflow\label{ss:overflow}} |
| 514 |
% \indent \textquotedblleft The ranges of supported counter values are more or less |
| 515 |
% restricted. Only \cs{arabic} can be used with any counter value \TeX{} supports. |
| 516 |
% \begin{quote} |
| 517 |
% \catcode`\|=12 % |
| 518 |
% \begin{tabular}{@{}l|l|l|l@{}} |
| 519 |
% Presentation & Supported & Ignored & Error message\\ |
| 520 |
% command & domain & values & `Counter too large'\\ |
| 521 |
% \hline |
| 522 |
% \cs{arabic} |
| 523 |
% & \ttfamily -MAX..MAX & &\\ |
| 524 |
% \cs{roman}, \cs{Roman} |
| 525 |
% & \ttfamily 1..MAX & \ttfamily -MAX..0 &\\ |
| 526 |
% \cs{alph}, \cs{Alph} |
| 527 |
% & \ttfamily 1..26 & 0 & \ttfamily -MAX..-1, 27..MAX\\ |
| 528 |
% \cs{fnsymbol} |
| 529 |
% & \ttfamily 1..9 & 0 & \ttfamily -MAX..-1, 10..MAX\\ |
| 530 |
% \hline |
| 531 |
% \end{tabular}\\[1ex] |
| 532 |
% \texttt{MAX} = \texttt{2147483647} |
| 533 |
% \end{quote} |
| 534 |
% \textquotedblright\ (\xpackage{alphalph} package manual, 2019/12/09, v2.6, |
| 535 |
% first table, p.~2). |
| 536 |
% |
| 537 |
% \noindent When \textit{any} page is out of that range, there will be a counter overflow.\newline |
| 538 |
% \xpackage{lastpage} probably is not the right package to be asked |
| 539 |
% to correct this anyway, but the \xpackage{pageslts} package |
| 540 |
% (with appropriate options) can do this. |
| 541 |
% \pagebreak |
| 542 |
% |
| 543 |
% When MAX is exceeded via |
| 544 |
% |\setcounter{<name>}{| something greater than MAX (or smaller then $-$MAX) |}|, |
| 545 |
% then the error |
| 546 |
% \begin{quote} |
| 547 |
% \begin{verbatim} |
| 548 |
% ! Number too big. |
| 549 |
% I can only go up to 2147483647='17777777777="7FFFFFFF, |
| 550 |
% so I'm using that number instead of yours. |
| 551 |
% \end{verbatim} |
| 552 |
% \end{quote} |
| 553 |
% \vspace{-\baselineskip} |
| 554 |
% will arise. But if the counter has a value of $2\,147\,483\,647 = {}$MAX, |
| 555 |
% and |\addtocounter{<name>}{+1}| is tried, no error is issued, but |
| 556 |
% |\arabic{<name>}| prints $-2147483648$, and further |\addtocounter{<name>}{+1}|s |
| 557 |
% give $-2147483647$, $-2147483646$ and so on.\newline |
| 558 |
% For a counter value of $-2\,147\,483\,647 = -$MAX and |\addtocounter{<name>}{-1}|s |
| 559 |
% after $-2147483647$ it is printed $-2147483648$, $2147483647$, $2147483646$ and so on |
| 560 |
% (without any message in the \xfile{log} file about any possible issue). |
| 561 |
% |
| 562 |
% \subsection{Other packages manipulating \texttt{\textbackslash lastpage@putlabel}} |
| 563 |
% The \xpackage{revtex4} class redefines the |\lastpage@putlabel| command |
| 564 |
% to place a label |LastPage|.\newline |
| 565 |
% |\lastpage@putlabel| in the \xpackage{lastpage} package was replaced by |\lastpage@putl@bel|, |
| 566 |
% but the |LastPage| label could become defined more than once. |
| 567 |
% |
| 568 |
% \subsection{\texttt{\textbackslash pagenumbering\{fnsymbol\}}\label{subsec:fnsymbol}} |
| 569 |
% When using the foot-note-symbols as page numbers, |
| 570 |
% it can be necessary to declare in the document's preamble: |
| 571 |
% \DescribeMacro{\ProvideTextCommand} |
| 572 |
% \begin{verbatim} |
| 573 |
% \ProvideTextCommand{\textasteriskcentered}{PD1}{*} |
| 574 |
% \ProvideTextCommand{\textdagger}{PD1}{†} |
| 575 |
% %\ProvideTextCommand{\textdaggerdbl}{PD1}{‡)% seems to neither work nor be necessary |
| 576 |
% \ProvideTextCommand{\textsection}{PD1}{§} |
| 577 |
% \ProvideTextCommand{\textparagraph}{PD1}{¶} |
| 578 |
% \ProvideTextCommand{\textbardbl}{PD1}{‖} |
| 579 |
% \end{verbatim} |
| 580 |
% |
| 581 |
% \section{Alternatives\label{sec:Alternatives}} |
| 582 |
% There are similar packages, which do (or do not) similar things (or even more). |
| 583 |
% As I neither know what exactly you want to accomplish when using this package |
| 584 |
% (e.\,g.~page number vs. page name, hyperlinks or not), nor what resources |
| 585 |
% your system has (e.\,g.~\TeX, \LaTeX2e, $\varepsilon$-\TeX{}, \LaTeX-format as recent |
| 586 |
% as 2024-11-01 or newer), here is a list of some possible alternatives: |
| 587 |
% \begin{description} |
| 588 |
% \item[-]\DescribeMacro{pageslts} |
| 589 |
% The \xpackage{pageslts} package first started as a revision of this |
| 590 |
% \xpackage{lastpage} package, but I~thought that an enhancement was needed |
| 591 |
% to accomplish what the \xpackage{pageslts} package does. For backward |
| 592 |
% compatibility, a label named |LastPage| is provided. |
| 593 |
% Thus |\usepackage{lastpage}| can be replaced by\newline |
| 594 |
% |\usepackage[pagecontinue=false,alphMult=0,AlphMulti=0,|\newline |
| 595 |
% | fnsymbolmult=false,romanMult=false,RomanMulti=false]{pageslts}|,\newline |
| 596 |
% if the behaviour of the \xpackage{lastpage} package should be simulated. |
| 597 |
% The default options are\newline |
| 598 |
% |\usepackage[pagecontinue=true,alphMult=ab,AlphMulti=AB,|\newline |
| 599 |
% |fnsymbolmult=true,romanMult=true,RomanMulti=true]{pageslts}|.\newline |
| 600 |
% Benefits of \xpackage{pageslts} package (with appropriate options) are: |
| 601 |
% \begin{description} |
| 602 |
% \item[+] Labels \texttt{LastPage} (|\AddToHook{enddocument/afterlastpage}|, |
| 603 |
% formerly |\AtEndDocument|; same as the \xpackage{LastPage} package) and |
| 604 |
% \texttt{VeryLastPage} (also |\AddToHook{enddocument/afterlastpage}|, |
| 605 |
% but formerly\newline% |
| 606 |
% |\AfterLastShipout|), allowing the user to refer to the |
| 607 |
% (very) last page of a document. |
| 608 |
% \item[+] For example, when more than one page numbering scheme is used, |
| 609 |
% the label \mbox{\texttt{LastPage}\textbf{s}} gives the total \textit{number} of pages. |
| 610 |
% \item[+] At the last page of each page numbering scheme a label\newline |
| 611 |
% \texttt{pagesLTS.<numbering scheme>} is placed, where |
| 612 |
% \texttt{<numbering scheme>} is e.\,g.\ arabic, roman, Roman, alph, or Alph. |
| 613 |
% For fnsymbol please use |\lastpageref{pagesLTS.fnsymbol}| instead of\newline |
| 614 |
% |\pageref{pagesLTS.fnsymbol}|. |
| 615 |
% \item[+] When the same numbering scheme is used twice, the page numbers |
| 616 |
% are either reset to one or continued automatically, depending on the option |
| 617 |
% given when the package is called. |
| 618 |
% \item[+] The command |\theCurrentPage| prints the current total/absolute |
| 619 |
% page number -- in contrast to |\thepage|, which gives only the page |
| 620 |
% \textit{name} in the current page numbering scheme. |
| 621 |
% |\theCurrentPageLocal| gives the current number of pages in the current |
| 622 |
% page numbering scheme. |\thepage| and |\theCurrentPageLocal| are different |
| 623 |
% e.\,g.\ when |\addtocounter{page}{...}| or |\setcounter{page}{...}| were used. |
| 624 |
% \item[+] At the first page of the document a label \texttt{pagesLTS.0} is created. |
| 625 |
% \item[+] The \xpackage{alphalph} package is supported, i.\,e.\ % |
| 626 |
% page numbers alph or Alph $>26$ and fnsymbol $>9$ can be used |
| 627 |
% (with according options set). Even zero and negative page numbers can be used |
| 628 |
% with \texttt{arabic}, \texttt{alph}, \texttt{Alph}, \texttt{roman}, \texttt{Roman}, |
| 629 |
% and \texttt{fnsymbol} page numbering (with \xpackage{alphalph} package and |
| 630 |
% according options). |
| 631 |
% \end{description} |
| 632 |
% Further labels are provided for special cases.\newline |
| 633 |
% \url{https://ctan.org/pkg/pageslts} |
| 634 |
% |
| 635 |
% \item[-]\DescribeMacro{LaTeX-kernel} |
| 636 |
% The number of pages is nowadays available via |\@abspage@last|,\linebreak |
| 637 |
% |\thetotalpages|, and |\PreviousTotalPages| from the kernel, |
| 638 |
% but when more than one page numbering scheme is used |
| 639 |
% (for example pages I~to X and then 1~to 10, thus number of pages |
| 640 |
% \hbox{\textquotedblleft 20\textquotedblright ,} but name of the last page |
| 641 |
% \hbox{\textquotedblleft 10\textquotedblright ),} |
| 642 |
% or when or the fnsymbol page numbering scheme is used, or another package |
| 643 |
% has output after this package, or the page numbers exceed a certain range, |
| 644 |
% there might be issues. (Is the total number of pages wanted? Or is the name |
| 645 |
% of the last page sought?)\newline |
| 646 |
% |\the\ReadonlyShipoutCounter| contains the number of currently shipped out pages, |
| 647 |
% i.\,e.\ current page minus one. |
| 648 |
% |
| 649 |
% \item[-]\DescribeMacro{totpages} |
| 650 |
% The \xpackage{totpages} package provides a \texttt{totpages} label similar to |
| 651 |
% \texttt{LastPages}, but |\AtEndDocument| instead of hook |enddocument/afterlastpage| |
| 652 |
% of the \pkg{pageslts} package. |
| 653 |
% The \xpackage{totpages} package additionally computes the number of paper sheets |
| 654 |
% needed to (double) print the document (with one, two, three,\ldots{} pages on |
| 655 |
% one sheet of paper) (which can be achieved also with the \xpackage{papermas} package, |
| 656 |
% an extension of the \xpackage{pageslts} package, which further allows to compute |
| 657 |
% the mass of that printed version of the document, useful e.\,g.\ when sending it |
| 658 |
% by mail to determine the postage).\newline |
| 659 |
% \url{https://ctan.org/pkg/totpages} |
| 660 |
% |
| 661 |
% \item[-]\DescribeMacro{totalcount} |
| 662 |
% The \xpackage{totalcount} package provides |\totalpages|. |
| 663 |
% If there are only arabic page numbers consecutively running from 1 to the last page, |
| 664 |
% this works. But for example |
| 665 |
% |
| 666 |
% \begin{quote} |
| 667 |
%\begin{verbatim} |
| 668 |
%\documentclass{article} |
| 669 |
%\usepackage[page]{totalcount} |
| 670 |
%\pagenumbering{Roman} |
| 671 |
%\begin{document} |
| 672 |
%\addtocounter{page}{49} |
| 673 |
%Page \thepage{} of \totalpages |
| 674 |
%\end{document} |
| 675 |
%\end{verbatim} |
| 676 |
% \end{quote} |
| 677 |
% |
| 678 |
% prints \textquotedblleft Page L of 50\textquotedblright, |
| 679 |
% where the number of pages is one (and no hyperlink is provided to the |
| 680 |
% last page even if \xpackage{hyperref} is used).\newline |
| 681 |
% \url{https://ctan.org/pkg/totalcount} |
| 682 |
% |
| 683 |
% \item[-]\DescribeMacro{totcount} |
| 684 |
% The \xpackage{totcount} package provides the last value of a counter, thus also the value |
| 685 |
% of the \texttt{page} counter. You do not get a hyperlink to the last page, only the numerical |
| 686 |
% value of the last page name is given \mbox{(i.\,e.~X+72} pages gives 72 instead of 82 |
| 687 |
% as total number of pages), and the number of pages can be changed for example |
| 688 |
% by |\addtocounter|.\newline |
| 689 |
% \url{https://ctan.org/pkg/totcount} |
| 690 |
% |
| 691 |
% \item[-]\DescribeMacro{nofm} |
| 692 |
% \textquotedblleft There is a package \xpackage{nofm.sty} available, but some versions |
| 693 |
% of it are defective, and most don't work with \xpackage{fancyhdr} because they take over |
| 694 |
% the complete page layout.\textquotedblright{} (\textsc{Piet van Oostrum}: |
| 695 |
% Page layout in \LaTeX , March~2, 2004, section~16; fancyhdr.pdf)\newline |
| 696 |
% \xpackage{nofm} as of 1991/02/25 (without version number), available at\newline |
| 697 |
% \url{https://mirror.ctan.org/obsolete/macros/latex209/contrib/misc/nofm.sty},\newline |
| 698 |
% does not work with e.\,g.\ \xpackage{hyperref}, redefines |\enddocument| |
| 699 |
% as well as |\@oddhead|, |\@evenhead|, |\@oddfoot|, and |\@evenfoot|.\newline |
| 700 |
% If you know the (\url{https://CTAN.org}) location of a |
| 701 |
% \textbf{working}~(!) version, please send me an e-mail, thanks! |
| 702 |
% |
| 703 |
% \item[-]\DescribeMacro{count1to} |
| 704 |
% The \xpackage{count1to} package \textquotedblleft sets |\count1| to |\count8| |
| 705 |
% with the values of page to subparagraph. |\count9| is used to flag odd |
| 706 |
% pages. \ldots\ [T]he code for the TotalPages |
| 707 |
% label\textquotedblright\ (package manual, 2024-06-13) has been removed |
| 708 |
% from the current package version.\newline |
| 709 |
% \url{https://ctan.org/pkg/count1to} |
| 710 |
% |
| 711 |
% \item[-]\DescribeMacro{zref} |
| 712 |
% The \xpackage{zref} package \textquotedblleft implements an extensible referencing |
| 713 |
% system\textquotedblright\ (package manual, 2023-09-14).\newline |
| 714 |
% \url{https://ctan.org/pkg/zref} |
| 715 |
% |
| 716 |
% \item[-]\DescribeMacro{memoir} |
| 717 |
% The \xpackage{memoir} \emph{class} provides |\thelastpage| (page number printed |
| 718 |
% on last page) and |\thelastsheet| (number of pages).\newline |
| 719 |
% \url{https://ctan.org/pkg/memoir} |
| 720 |
% \end{description} |
| 721 |
% |
| 722 |
% \bigskip |
| 723 |
% |
| 724 |
% \noindent (You programmed or found another alternative, |
| 725 |
% which is available at\newline |
| 726 |
% \url{https://CTAN.org}? |
| 727 |
% OK, send an e-mail to me with the name, location at CTAN, |
| 728 |
% and a short notice, and I will probably include it in the list above.) |
| 729 |
% \newpage |
| 730 |
% |
| 731 |
% \section{Example} |
| 732 |
% \begin{macrocode} |
| 733 |
%<*example> |
| 734 |
\documentclass[british]{article}[2025/01/22]% v1.4n Standard LaTeX document class |
| 735 |
\makeatletter |
| 736 |
\usepackage[draft]{showkeys}[2024/05/23]% v3.21 Show cite and label keys (DPC, MH) |
| 737 |
%% Use final instead of draft to hide the keys. %% |
| 738 |
\usepackage[pdfpagelabels=true,hyperindex=false]{hyperref}[2025-07-12]% v7.01o |
| 739 |
\@ifpackageloaded{hyperref}{% Hypertext links for LaTeX |
| 740 |
\hypersetup{extension=pdf,% |
| 741 |
plainpages=false,% |
| 742 |
pdflang={en},% |
| 743 |
pdftitle={lastpage package example},% |
| 744 |
pdfauthor={H.-Martin Muench},% |
| 745 |
pdfsubject={Example for the lastpage package},% |
| 746 |
pdfkeywords={LaTeX, lastpage},% |
| 747 |
pdfview=Fit,% |
| 748 |
pdfstartview=Fit,% |
| 749 |
pdfpagelayout=SinglePage% |
| 750 |
}}{\usepackage{url}[2013/09/16]}% v3.4 Verb mode for urls, etc. |
| 751 |
\usepackage{lastpage}[2025/08/14]% v2.1h Refers to last page's name (HMM; JPG)] |
| 752 |
\renewcommand{\@evenfoot}{{% |
| 753 |
\normalsize\slshape \today\hfil \upshape % |
| 754 |
page \thepage{} of \pageref{LastPage}}} |
| 755 |
\renewcommand{\@oddfoot}{\@evenfoot} |
| 756 |
\makeatother |
| 757 |
\listfiles |
| 758 |
\begin{document} |
| 759 |
\pagenumbering{Roman} |
| 760 |
\section*{Example for lastpage} |
| 761 |
\markboth{Example for lastpage}{Example for lastpage} |
| 762 |
This example demonstrates the use of package\newline |
| 763 |
\textsf{lastpage}, v2.1h as of 2025-08-14 (HMM; JPG).\newline |
| 764 |
The package takes no options.\newline |
| 765 |
For more details please see the documentation!\newline |
| 766 |
|
| 767 |
\noindent \label{keys} To hide the \pageref{keys}{\qquad } use option |
| 768 |
\texttt{final} instead of \texttt{draft} with the \textsf{showkeys} |
| 769 |
package (or remove the package call from the preamble of |
| 770 |
this document).\newline |
| 771 |
|
| 772 |
\textbf{Hyperlinks or not:} If the \textsf{hyperref} package is loaded, |
| 773 |
the references are also hyperlinked:\newline |
| 774 |
\smallskip |
| 775 |
Last page's name (LastPage): \pageref{LastPage}\newline |
| 776 |
\noindent If the \textsf{hyperref} package is loaded, but the hyperlinks |
| 777 |
of the references shall be suppressed, \verb|\pageref*{...}| |
| 778 |
can be used:\newline |
| 779 |
\smallskip |
| 780 |
Last page's name (LastPage): \pageref*{LastPage}\newline |
| 781 |
|
| 782 |
\textbf{Trademarks} appear throughout this example without any |
| 783 |
trademark symbol; they are the property of their respective |
| 784 |
trademark owner. There is no intention of infringement; the |
| 785 |
usage is to the benefit of the trademark owner.\newline |
| 786 |
|
| 787 |
\textbf{Tip}: Use \textit{logical page numbers} |
| 788 |
for the display of the pdf (in Adobe Acrobat Reader 2024.005.20392: |
| 789 |
Edit $>$ Preferences $>$ Page Display $>$ |
| 790 |
Page Content and Information: Use logical page numbers)!\newline |
| 791 |
|
| 792 |
If you are more ambitious in respect to your aims with this package, |
| 793 |
you might want to have a look at the \textsf{pageslts} package:\newline |
| 794 |
\url{https://ctan.org/pkg/pageslts}. |
| 795 |
\bigskip |
| 796 |
|
| 797 |
\noindent The page (\verb|\thepage|): \thepage \newline |
| 798 |
Last page's name (LastPage): \pageref{LastPage} |
| 799 |
\newpage |
| 800 |
|
| 801 |
\noindent The page (\verb|\thepage|): \thepage \newline |
| 802 |
Last page's name (LastPage): \pageref{LastPage} |
| 803 |
|
| 804 |
\bigskip |
| 805 |
|
| 806 |
\noindent There was the question: |
| 807 |
|
| 808 |
\begin{quote} |
| 809 |
\begin{verbatim} |
| 810 |
\documentclass{article} |
| 811 |
\usepackage{hyperref} |
| 812 |
\usepackage{lastpage} |
| 813 |
\begin{document} |
| 814 |
\ifnum\thepage=\pageref{LastPage} foo \else bar \fi |
| 815 |
\end{document} |
| 816 |
\end{verbatim} |
| 817 |
|
| 818 |
producing the error |
| 819 |
\textquotedblleft missing number, treated as zero\textquotedblright. |
| 820 |
\end{quote} |
| 821 |
|
| 822 |
\noindent \verb|\pageref| inserts a hyperlink, \verb|\pageref{LastPage}| |
| 823 |
is not expandable and the code breaks.\newline |
| 824 |
The code does not generally work even without hyperref. |
| 825 |
|
| 826 |
\begin{quote} |
| 827 |
\begin{verbatim} |
| 828 |
\documentclass{article} |
| 829 |
\usepackage{hyperref} |
| 830 |
\usepackage{lastpage} |
| 831 |
\pagenumbering{Roman} |
| 832 |
\begin{document} |
| 833 |
\addtocounter{page}{8} |
| 834 |
\edef\here{\thepage} |
| 835 |
\makeatletter |
| 836 |
\ifx\here\lastpage@lastpage\relax foo\else bar\fi |
| 837 |
\makeatother |
| 838 |
\end{document} |
| 839 |
\end{verbatim} |
| 840 |
\end{quote} |
| 841 |
|
| 842 |
\noindent does work (two compilations needed), because \verb|\lastpage@lastpage| |
| 843 |
contains the name of the page, \mbox{example:} |
| 844 |
\begin{verbatim} |
| 845 |
Page \thepage{} is (not) page |
| 846 |
\makeatletter\lastpage@lastpage\makeatother. |
| 847 |
\end{verbatim} |
| 848 |
prints:\newline |
| 849 |
Page \thepage{} is (not) page |
| 850 |
\makeatletter\lastpage@lastpage\makeatother. |
| 851 |
\newline |
| 852 |
This can be broken for example by \verb|\pagenumbering{fnsymbol}| |
| 853 |
(because then \verb|\edef\here{\thepage}| does not work). |
| 854 |
\newpage |
| 855 |
|
| 856 |
\noindent The page (\verb|\thepage|): \thepage\newline |
| 857 |
Last page's name (LastPage): \pageref{LastPage} |
| 858 |
\bigskip |
| 859 |
|
| 860 |
With modern \LaTeX{} it is possible to say: |
| 861 |
\begin{quote} |
| 862 |
\begin{verbatim} |
| 863 |
\NeedsTeXFormat{LaTeX2e}[2024-11-01] |
| 864 |
\documentclass{article} |
| 865 |
\pagenumbering{fnsymbol} |
| 866 |
\begin{document} |
| 867 |
\addtocounter{page}{8}% |
| 868 |
\ExplSyntaxOn% |
| 869 |
\xdef\test{\numexpr\the\g_shipout_readonly_int +1\relax}% |
| 870 |
\ExplSyntaxOff% |
| 871 |
\ifnum\PreviousTotalPages=\test\relax% |
| 872 |
This is the last page.% |
| 873 |
\else% |
| 874 |
This is not the last page |
| 875 |
(or it is but \LaTeX{} needs another compilation run |
| 876 |
to detect this). |
| 877 |
\fi |
| 878 |
\end{document} |
| 879 |
\end{verbatim} |
| 880 |
\end{quote} |
| 881 |
|
| 882 |
\newpage |
| 883 |
\section*{The End} |
| 884 |
\noindent The page (\verb|\thepage|): \thepage \newline |
| 885 |
Last page's name (LastPage): \pageref{LastPage} |
| 886 |
\bigskip |
| 887 |
|
| 888 |
To see the content of the \texttt{enddocument/afterlastpage}-hook |
| 889 |
(for a recent \LaTeX-format!) use % without the \verb||, of course! |
| 890 |
\verb|\ShowHook{enddocument/afterlastpage}|. |
| 891 |
\end{document} |
| 892 |
%</example> |
| 893 |
% \end{macrocode} |
| 894 |
% \StopEventually{} |
| 895 |
% \newpage |
| 896 |
% |
| 897 |
% \section{The implementation} |
| 898 |
% \DescribeMacro{lastpage.sty} |
| 899 |
% We first need to determine whether we are on \TeX~2.09 or \LaTeX2e.\newline |
| 900 |
% (That line, which is too long for the documentation, reads:\newline |
| 901 |
% |\def\loadlastpage{\ProvidesPackage{lastpage}[2025/08/14 v2.1h lastpage:|\linebreak |
| 902 |
% | 2.09 or 2e? (HMM)]\relax\RequirePackage{lastpage2e}}|.) |
| 903 |
% |
| 904 |
% \begin{macrocode} |
| 905 |
%<*package> |
| 906 |
%% Part of the "lastpage" package |
| 907 |
%% loads either lastpage2.09.sty for TeX 2.09 or lastpage2e.sty for LaTeX 2e |
| 908 |
%% with code from https://groups.google.com/g/comp.text.tex/c/-Qmhj1ZI4xM |
| 909 |
\def\loadlastpage{\ProvidesPackage{lastpage}[2025/08/14 v2.1h lastpage: 2.09 or 2e? (HMM)]\relax\RequirePackage{lastpage2e}} |
| 910 |
\begingroup \expandafter \ifx \csname documentclass\endcsname\relax |
| 911 |
\endgroup \expandafter \input{lastpage209.sty} |
| 912 |
\else \endgroup \expandafter \loadlastpage |
| 913 |
\fi |
| 914 |
%</package> |
| 915 |
% \end{macrocode} |
| 916 |
% |
| 917 |
% \DescribeMacro{lastpage209.sty} |
| 918 |
% If we are on \TeX~2.09 (really?!), we load the 2.09 version \pkg{lastpage209.sty}: |
| 919 |
% |
| 920 |
% \begin{macrocode} |
| 921 |
%<*lastpage209> |
| 922 |
%% Part of the "lastpage" package |
| 923 |
%% FOR LaTeX 2.09 ONLY - FOR LaTeX 2e USE lastpage2e.sty |
| 924 |
%% This is lastpage209.sty invented by Jeffrey P. Goldberg, |
| 925 |
%% after Piet van Oostrum: Page layout in LaTeX, March 2, 2004, section 16; |
| 926 |
%% fancyhdr.pdf; lastpage209.sty maintained by H.-Martin Muench. |
| 927 |
\let\origenddocument=\enddocument% |
| 928 |
\def\enddocument{\clearpage% |
| 929 |
{\addtocounter{page}{-1}% |
| 930 |
\immediate\write\@mainaux{\string\newlabel{LastPage}{{}{\thepage}}}% |
| 931 |
}% |
| 932 |
\addtocounter{page}{+1}% |
| 933 |
\origenddocument% |
| 934 |
} |
| 935 |
%</lastpage209> |
| 936 |
% \end{macrocode} |
| 937 |
% |
| 938 |
% \DescribeMacro{lastpage2e.sty} |
| 939 |
% If |\documentclass| is known, we are in \LaTeXe{} -- but which one? |
| 940 |
% For modern versions with \eTeX{} and hook management etc. |
| 941 |
% we load version \pkg{lastpagemodern.sty}, otherwise |
| 942 |
% \pkg{lastpageclassic.sty}. We start off by checking that we are |
| 943 |
% loading into \LaTeXe{} and announcing the name and version of this package. |
| 944 |
% |
| 945 |
% \begin{macrocode} |
| 946 |
%<*lastpage2e> |
| 947 |
%% Part of the "lastpage" package |
| 948 |
\NeedsTeXFormat{LaTeX2e}[1994/12/01] |
| 949 |
\ProvidesPackage{lastpage2e}[2025/08/14 v2.1h % |
| 950 |
Decide which 2e lastpage version to use (HMM)] |
| 951 |
\@ifl@t@r\fmtversion{2024/06/01}{\RequirePackage{lastpagemodern}}{% |
| 952 |
\RequirePackage{lastpageclassic}} |
| 953 |
\message{^^J} |
| 954 |
%</lastpage2e> |
| 955 |
% \end{macrocode} |
| 956 |
% \newpage |
| 957 |
% |
| 958 |
% \DescribeMacro{lastpageclassic.sty} |
| 959 |
% In case of older \LaTeX-formats \pkg{lastpageclassic.sty} is loaded: |
| 960 |
% |
| 961 |
% \begin{macrocode} |
| 962 |
%<*lastpageclassic> |
| 963 |
%% Part of the "lastpage" package |
| 964 |
\NeedsTeXFormat{LaTeX2e}[1994/12/01] |
| 965 |
\ProvidesPackage{lastpageclassic}[2025/08/14 v2.1h % |
| 966 |
Refers to last page's name (HMM; JPG)] |
| 967 |
%% allows for things like "Page \thepage{} of \pageref{LastPage}" |
| 968 |
%% to get "Page 7 of 9" |
| 969 |
|
| 970 |
% \end{macrocode} |
| 971 |
% |
| 972 |
% \indent For comparisons, \textquotedblleft one\textquotedblright{} is defined |
| 973 |
% (|\@ne| does not work for this). |
| 974 |
% |
| 975 |
% \begin{macrocode} |
| 976 |
\gdef\lastpage@one{1} |
| 977 |
% \end{macrocode} |
| 978 |
% |
| 979 |
% We define |\lastpage@hyper|, |\lastpage@nameref|, |\lastpage@french|, and |
| 980 |
% |\lastpage@LTS| to be \textquotedblleft \texttt{0}\textquotedblright{}. |
| 981 |
% |
| 982 |
% \begin{macrocode} |
| 983 |
\gdef\lastpage@hyper{0} |
| 984 |
\gdef\lastpage@nameref{0} |
| 985 |
\gdef\lastpage@french{0} |
| 986 |
\gdef\lastpage@LTS{0} |
| 987 |
% \end{macrocode} |
| 988 |
% |
| 989 |
% We define |\lastpage@firstpage| to be \textquotedblleft \texttt{1}\textquotedblright{}, |
| 990 |
% and before re-definition via the \xfile{.aux} file, |
| 991 |
% |\lastpage@lastpage| and |\lastpage@lastpageHy| are unknown. |
| 992 |
% |
| 993 |
% \begin{macrocode} |
| 994 |
\gdef\lastpage@firstpage{1} |
| 995 |
\gdef\lastpage@lastpage{??} |
| 996 |
\gdef\lastpage@lastpageHy{??} |
| 997 |
|
| 998 |
% \end{macrocode} |
| 999 |
% |
| 1000 |
% \begin{macro}{\AtBeginDocument} |
| 1001 |
% \indent |\AtBeginDocument| we give a warning about ancient versions of the \pkg{endfloat} package. |
| 1002 |
% Then it is checked whether various packages are loaded. |
| 1003 |
% (|\@ifpackageloaded| cannot be used later than |\AtBeginDocument|.) |
| 1004 |
% If this is the case,\newline |
| 1005 |
% |\lastpage@<package abbreviation>| is defined as \texttt{1} |
| 1006 |
% (otherwise it stays~\texttt{0}). |
| 1007 |
% |
| 1008 |
% \begin{macrocode} |
| 1009 |
\AtBeginDocument{% |
| 1010 |
\@ifpackageloaded{endfloat}{% |
| 1011 |
\@ifpackagelater{endfloat}{1993/04/30}{\relax}{% |
| 1012 |
\PackageError{lastpage}{% |
| 1013 |
Incompatibility with outdated version of endfloat package}{% |
| 1014 |
lastpage is not fully compatible with a version\MessageBreak% |
| 1015 |
before 2.1 of the endfloat package,\MessageBreak% |
| 1016 |
because those versions redefined\MessageBreak% |
| 1017 |
the \string\enddocument\space command.}% |
| 1018 |
}}{}% |
| 1019 |
\@ifpackageloaded{tikz}{\gdef\lastpage@tikz{1}}{}% |
| 1020 |
\@ifpackageloaded{hyperref}{\gdef\lastpage@hyper{1}}{}% |
| 1021 |
\@ifpackageloaded{nameref}{\gdef\lastpage@nameref{1}}{}% |
| 1022 |
\@ifpackageloaded{french}{\gdef\lastpage@french{1}}{}% |
| 1023 |
\@ifpackageloaded{frenchle}{\gdef\lastpage@french{1}}{}% |
| 1024 |
\@ifpackageloaded{pagesLTS}{\gdef\lastpage@LTS{1}}{}% |
| 1025 |
\@ifpackageloaded{pageslts}{\gdef\lastpage@LTS{1}}{}% |
| 1026 |
% \end{macrocode} |
| 1027 |
% |
| 1028 |
% |\lastpage@putlabel|, used by older versions of this package, |
| 1029 |
% is redefined e.\,g.\ by \xpackage{revtex}, \xpackage{frenchle}, |
| 1030 |
% \xpackage{PPRcorners}, and old versions of \xpackage{hyperref}. |
| 1031 |
% While now |\lastpage@putl@bel| is used instead, \xpackage{revtex} |
| 1032 |
% could also define a label \texttt{LastPage}, |
| 1033 |
% which then would be multiply defined. (Which is no big issue, |
| 1034 |
% if it is associated with the same page.) Therefore we define |
| 1035 |
% |
| 1036 |
% \begin{macrocode} |
| 1037 |
\gdef\lastpage@putlabel{\relax}% |
| 1038 |
} |
| 1039 |
|
| 1040 |
% \end{macrocode} |
| 1041 |
% |
| 1042 |
% \noindent Because |\lastpage@putlabel| might be (re)defined later, |
| 1043 |
% depending on the order in which the packages are loaded, |
| 1044 |
% we will do this again |\AtEndDocument|. |
| 1045 |
% \end{macro} |
| 1046 |
% |
| 1047 |
% \begin{macro}{\lastpage@putl@bel} |
| 1048 |
% \indent This command does the writing of the label: |
| 1049 |
% |
| 1050 |
% \begin{macrocode} |
| 1051 |
\newcommand{\lastpage@putl@bel}{% |
| 1052 |
% \end{macrocode} |
| 1053 |
% |
| 1054 |
% |\AtBeginDocument| it is checked whether the \xpackage{hyperref} package is loaded,\newline |
| 1055 |
% |\@ifpackageloaded{hyperref}{\gdef\lastpage@hyper{1}}{}|.\newline |
| 1056 |
% |\@ifpackageloaded| cannot be used later than |\AtBeginDocument|.\newline |
| 1057 |
% User \textsc{Sebastian Bank} found and reported (Thanks!) a~case, when this check is not |
| 1058 |
% sufficient. Using a class with\newline |
| 1059 |
% |\usepackage{lastpage}|\newline |
| 1060 |
% |\AtBeginDocument{\usepackage{hyperref}}|\newline |
| 1061 |
% leads to failed detection of the \xpackage{hyperref} package, because |
| 1062 |
% |\AtBeginDocument| \textit{first} the check for \xpackage{hyperref} is performed, |
| 1063 |
% and \textit{then} \xpackage{hyperref} is loaded. As mentioned above, |
| 1064 |
% |\@ifpackageloaded| cannot be used later, so here we do not check for the |
| 1065 |
% \xpackage{hyperref} package again, but for its |\Hy@Warning| command. |
| 1066 |
% In version~1.2c of the \xpackage{lastpage} package, it was checked for |
| 1067 |
% the |\hyperref| command, but as it turned out, \xpackage{tcilatex} \textit{is} |
| 1068 |
% defining that. If some other package or user is defining |\Hy@Warning|, |
| 1069 |
% \xpackage{lastpage} will falsely assume, that \xpackage{hyperref} has been loaded, |
| 1070 |
% but in my humble opinion, defining |\Hy@Warning| does not make sense and |
| 1071 |
% is bad style (except definition by the \xpackage{hyperref} package itself, |
| 1072 |
% of course). |
| 1073 |
% |
| 1074 |
% \begin{macrocode} |
| 1075 |
\@ifundefined{Hy@Warning}{% hyperref not loaded |
| 1076 |
}{\gdef\lastpage@hyper{1}% hyperref loaded |
| 1077 |
}% |
| 1078 |
% \end{macrocode} |
| 1079 |
% |
| 1080 |
% If the \xpackage{pageslts} package is used, this \xpackage{lastpage} package is |
| 1081 |
% not needed at all. The \xpackage{LastPage} label would even be defined twice. |
| 1082 |
% Thus, if \xpackage{pageslts} is used, here nothing is done: |
| 1083 |
% |
| 1084 |
% \begin{macrocode} |
| 1085 |
\ifx\lastpage@LTS\lastpage@one% |
| 1086 |
\else% |
| 1087 |
% \end{macrocode} |
| 1088 |
% |
| 1089 |
% Otherwise the label is set:\newline |
| 1090 |
% We have got to distinguish whether \xpackage{hyperref} has been loaded or not: |
| 1091 |
% |
| 1092 |
% \begin{macrocode} |
| 1093 |
\ifx\lastpage@hyper\lastpage@one% |
| 1094 |
\lastpage@putlabelhyper% |
| 1095 |
\else% |
| 1096 |
% \end{macrocode} |
| 1097 |
% |
| 1098 |
% and also need to treat documents with \xpackage{nameref} differently: |
| 1099 |
% |
| 1100 |
% \begin{macrocode} |
| 1101 |
\ifx\lastpage@nameref\lastpage@one% |
| 1102 |
\lastpage@putlabelNR% |
| 1103 |
\else% |
| 1104 |
% \end{macrocode} |
| 1105 |
% |
| 1106 |
% When those packages have not been loaded, we just write the |
| 1107 |
% simple label into the \xfile{aux} file (and store the value of the page): |
| 1108 |
% |
| 1109 |
% \begin{macrocode} |
| 1110 |
\begingroup% |
| 1111 |
\addtocounter{page}{-1}% |
| 1112 |
\immediate\write\@auxout{\string\newlabel{LastPage}{{}{\thepage}}}% |
| 1113 |
\immediate\write\@auxout{\string\xdef\string\lastpage@lastpage{\thepage}}% |
| 1114 |
\immediate\write\@auxout{\string\gdef\string\lastpage@lastpageHy{}}% |
| 1115 |
\addtocounter{page}{+1}% |
| 1116 |
\endgroup% |
| 1117 |
\fi% |
| 1118 |
\fi% |
| 1119 |
\fi% |
| 1120 |
} |
| 1121 |
|
| 1122 |
% \end{macrocode} |
| 1123 |
% \end{macro} |
| 1124 |
% \newpage |
| 1125 |
% |
| 1126 |
% \begin{macro}{\lastpage@putlabelhyper}% |
| 1127 |
% \indent When \xpackage{hyperref} has been loaded, the label is set with the |
| 1128 |
% |\lastpage@putlabelhyper| command. If the \xpackage{hyperref} package is used, |
| 1129 |
% but page-anchors are disabled, the hyperlinking will not work. (The warning will |
| 1130 |
% also be shown, when only |\pageref*{LastPage}| is used (or neither one), |
| 1131 |
% but without messing with |\pageref| we cannot detect this.) |
| 1132 |
% |
| 1133 |
% \begin{macrocode} |
| 1134 |
\newcommand{\lastpage@putlabelhyper}{% |
| 1135 |
\ifHy@pageanchor% |
| 1136 |
\else% |
| 1137 |
\PackageWarningNoLine{lastpage}{% |
| 1138 |
The \string\pageref{LastPage} link does not work\MessageBreak% |
| 1139 |
using hyperref with disabled option `pageanchor'.\MessageBreak% |
| 1140 |
Better enable `pageanchor' or use\MessageBreak% |
| 1141 |
\string\pageref*{LastPage} (not generating a link)% |
| 1142 |
}% |
| 1143 |
\fi% |
| 1144 |
% \end{macrocode} |
| 1145 |
% |
| 1146 |
% Since the page has been put out, we are on the page \textit{after} that page. |
| 1147 |
% We therefore subtract one from the page counter. (For the compiler, |
| 1148 |
% this is equal to |\advance\c@page\m@ne|, but for human readers of the code |
| 1149 |
% it is probably easier to understand.) |
| 1150 |
% |
| 1151 |
% \begin{macrocode} |
| 1152 |
\begingroup% |
| 1153 |
\addtocounter{page}{-1}% |
| 1154 |
% \end{macrocode} |
| 1155 |
% |
| 1156 |
% Simply using |\label| for \texttt{LastPage} would not work, |
| 1157 |
% because labels wait for the output routines to work, and there |
| 1158 |
% may be no more invocations of the output routines. To force |
| 1159 |
% the write out, we need to do an |\immediate| write into the \xfile{aux} file. |
| 1160 |
% |
| 1161 |
% \begin{macrocode} |
| 1162 |
%% with code from \Hy@EveryPageAnchor of the hyperref package, |
| 1163 |
%% 2010/04/17 v6.80x; newer versions are available |
| 1164 |
\let\@number\@firstofone% |
| 1165 |
\ifHy@pageanchor% |
| 1166 |
\ifHy@hypertexnames% |
| 1167 |
\ifHy@plainpages% |
| 1168 |
\def\Hy@temp{\arabic{page}}% |
| 1169 |
\else% |
| 1170 |
\Hy@unicodefalse% |
| 1171 |
\ifnum \value{page}=1\relax% |
| 1172 |
% \end{macrocode} |
| 1173 |
% |
| 1174 |
% We do not count the pages ourselves, and so they could have been changed by |
| 1175 |
% e.\,g.\ |\pagenumbering{...}|, |\addtocounter{page}{...}|,\newline |
| 1176 |
% |\setcounter{page}{...}|. Thus the page might have the number one |
| 1177 |
% while not being the first page at all. Using the \xpackage{everyshi} |
| 1178 |
% package would help, but this package should not require other packages. |
| 1179 |
% The \xpackage{pageslts} package does a better handling.\newline |
| 1180 |
% We will make a mistake here at most once: |
| 1181 |
% |
| 1182 |
% \begin{macrocode} |
| 1183 |
\ifx \lastpage@firstpage\lastpage@one\relax% |
| 1184 |
\def\Hy@temp{\thepage}% |
| 1185 |
\gdef\lastpage@firstpage{0}% |
| 1186 |
\else% |
| 1187 |
\pdfstringdef\Hy@temp{\thepage}% |
| 1188 |
\fi% |
| 1189 |
\else% |
| 1190 |
\pdfstringdef\Hy@temp{\thepage}% |
| 1191 |
\fi% |
| 1192 |
\fi% |
| 1193 |
\else% |
| 1194 |
\def\Hy@temp{\the\Hy@pagecounter}% |
| 1195 |
\fi% |
| 1196 |
\fi% |
| 1197 |
\immediate\write\@auxout{% |
| 1198 |
\string\newlabel{LastPage}{{}{\thepage}{}{% |
| 1199 |
\ifHy@pageanchor page.\Hy@temp\fi}{}}% |
| 1200 |
}% |
| 1201 |
% \end{macrocode} |
| 1202 |
% |
| 1203 |
% We also save the values, so that we can later (next rerun) check, |
| 1204 |
% whether they have been saved in the \xfile{aux} file. |
| 1205 |
% |
| 1206 |
% \begin{macrocode} |
| 1207 |
\immediate\write\@auxout{\string\xdef\string\lastpage@lastpage{\thepage}}% |
| 1208 |
\ifHy@pageanchor% |
| 1209 |
\immediate\write\@auxout{\string\xdef\string\lastpage@lastpageHy{\Hy@temp}}% |
| 1210 |
\else% |
| 1211 |
\immediate\write\@auxout{\string\gdef\string\lastpage@lastpageHy{}}% |
| 1212 |
\fi% |
| 1213 |
% \end{macrocode} |
| 1214 |
% |
| 1215 |
% After the writeout we restore the page number again, |
| 1216 |
% since there might be other things still to be done. |
| 1217 |
% |
| 1218 |
% \begin{macrocode} |
| 1219 |
\addtocounter{page}{+1}% |
| 1220 |
\endgroup% |
| 1221 |
} |
| 1222 |
|
| 1223 |
% \end{macrocode} |
| 1224 |
% \end{macro} |
| 1225 |
% |
| 1226 |
% \begin{macro}{\lastpage@putlabelNR} |
| 1227 |
% \indent The \xpackage{nameref} package redefines |\label| to have five arguments |
| 1228 |
% instead of two, therefore\newline |
| 1229 |
% |\newlabel{LastPage}{{}{\thepage}{}{}{}}| |
| 1230 |
% instead of\newline |
| 1231 |
% |\newlabel{LastPage}{{}{\thepage}}| must be used: |
| 1232 |
% |
| 1233 |
% \begin{macrocode} |
| 1234 |
\newcommand{\lastpage@putlabelNR}{% |
| 1235 |
\begingroup% |
| 1236 |
\addtocounter{page}{-1}% |
| 1237 |
\immediate\write\@auxout{\string\newlabel{LastPage}{{}{\thepage}{}{}{}}}% |
| 1238 |
\immediate\write\@auxout{\string\xdef\string\lastpage@lastpage{\thepage}}% |
| 1239 |
\immediate\write\@auxout{\string\gdef\string\lastpage@lastpageHy{}}% |
| 1240 |
\addtocounter{page}{+1}% |
| 1241 |
\endgroup% |
| 1242 |
} |
| 1243 |
|
| 1244 |
% \end{macrocode} |
| 1245 |
% \end{macro} |
| 1246 |
% |
| 1247 |
% \begin{macro}{\lastpage@fileswtest} |
| 1248 |
% \indent Later it will be determined whether it is allowed to write |
| 1249 |
% to the \xfile{aux} file. If it was \emph{not} allowed, it is checked |
| 1250 |
% whether the label was already set via the \xfile{aux} file in some |
| 1251 |
% earlier compilation run. (There are packages where the document |
| 1252 |
% is compiled with access to the \xfile{aux} file, and then there is |
| 1253 |
% an additional compiler run, where the \xfile{aux} file cannot be changed, |
| 1254 |
% but in that run there is also no need to change it.) The \xpackage{tikz} |
| 1255 |
% package is somewhat different, therefore we only give a warning instead |
| 1256 |
% of an error (and hope that there is another compiler run where the |
| 1257 |
% \xfile{aux} file can be written). |
| 1258 |
% |
| 1259 |
% \begin{macrocode} |
| 1260 |
\newcommand{\lastpage@fileswtest}[2]{% |
| 1261 |
\edef\lastpage@testa{#1}% |
| 1262 |
\edef\lastpage@testb{#2}% |
| 1263 |
\ifx\lastpage@testa\lastpage@testb% |
| 1264 |
\else% |
| 1265 |
\ifx\lastpage@tikz\lastpage@one\relax% |
| 1266 |
\PackageWarning{lastpage}% |
| 1267 |
{The lastpage package was not allowed to write to an\MessageBreak% |
| 1268 |
.aux file. This package does not work without access\MessageBreak% |
| 1269 |
to an .aux file.\MessageBreak% |
| 1270 |
It is OK if the .aux file was already updated\MessageBreak% |
| 1271 |
by a previous compiler run\MessageBreak% |
| 1272 |
and would not have changed anyway.\MessageBreak% |
| 1273 |
}% |
| 1274 |
\else% |
| 1275 |
\PackageError{lastpage}{No auxiliary file allowed}% |
| 1276 |
{The lastpage package was not allowed to write to an .aux file.\MessageBreak% |
| 1277 |
This package does not work without access to an .aux file.\MessageBreak% |
| 1278 |
Press Ctrl+Z to exit.\MessageBreak% |
| 1279 |
But it is OK if the .aux file was already updated\MessageBreak% |
| 1280 |
by a previous compiler run\MessageBreak% |
| 1281 |
and would not have changed anyway.}% |
| 1282 |
\fi% |
| 1283 |
\fi% |
| 1284 |
} |
| 1285 |
|
| 1286 |
% \end{macrocode} |
| 1287 |
% \end{macro} |
| 1288 |
% |
| 1289 |
% \begin{macro}{\lastpage@fileswtestHy} |
| 1290 |
% \indent When the \xpackage{hyperref} package has been loaded, |
| 1291 |
% |\lastpage@lastpageHy| must be tested additionally. (And a |
| 1292 |
% |\newcommand| is needed, because |\ifHy@pageanchor| is not even |
| 1293 |
% defined when \xpackage{hyperref} has not been loaded.) |
| 1294 |
% |
| 1295 |
% \begin{macrocode} |
| 1296 |
\newcommand{\lastpage@fileswtestHy}{% |
| 1297 |
\ifHy@pageanchor% |
| 1298 |
\lastpage@fileswtest{\Hy@temp}{\lastpage@lastpageHy}% |
| 1299 |
\else% |
| 1300 |
\lastpage@fileswtest{\empty}{\lastpage@lastpageHy}% |
| 1301 |
\fi% |
| 1302 |
} |
| 1303 |
% \end{macrocode} |
| 1304 |
% \end{macro} |
| 1305 |
% |
| 1306 |
% \begin{macro}{\AtEndDocument} |
| 1307 |
% \indent |\AtEndDocument| we again (re)define |\lastpage@putlabel| |
| 1308 |
% to do nothing and check |\lastpage@lastpage|, |
| 1309 |
% whether it is still unchanged, which is OK for the first run only. |
| 1310 |
% |
| 1311 |
% \begin{macrocode} |
| 1312 |
|
| 1313 |
\AtEndDocument{% |
| 1314 |
\ifx\lastpage@LTS\lastpage@one% |
| 1315 |
\else% |
| 1316 |
\gdef\lastpage@putlabel{??}% |
| 1317 |
\ifx\lastpage@lastpage\lastpage@putlabel\relax% |
| 1318 |
\PackageWarning{lastpage}{Rerun to get the references right}% |
| 1319 |
\fi% |
| 1320 |
\fi% |
| 1321 |
\gdef\lastpage@putlabel{\relax}% |
| 1322 |
% \end{macrocode} |
| 1323 |
% |
| 1324 |
% It is checked whether writing to files is allowed |
| 1325 |
% (otherwise, only an error message is issued and nothing is done). |
| 1326 |
% |
| 1327 |
% \begin{macrocode} |
| 1328 |
\if@filesw% |
| 1329 |
% \end{macrocode} |
| 1330 |
% |
| 1331 |
% We put in a |\message| to show, in what order things (which were called) |
| 1332 |
% are done (see subsection~\ref{ssec:aed}). |
| 1333 |
% |
| 1334 |
% \begin{macrocode} |
| 1335 |
\message{^^JAED: lastpage setting LastPage^^J}% |
| 1336 |
% \end{macrocode} |
| 1337 |
% |
| 1338 |
% After this we issue a |\clearpage| to put out all floats, |
| 1339 |
% which are still floating, and place the \texttt{LastPage} label. |
| 1340 |
% Sometimes |\clearpage| might be undefined. |
| 1341 |
% |
| 1342 |
% \begin{macrocode} |
| 1343 |
\@ifundefined{clearpage}{\relax}{\clearpage}% |
| 1344 |
\ifx\lastpage@french\lastpage@one% french or frenchle loaded |
| 1345 |
\addtocounter{page}{+1}\lastpage@putl@bel\addtocounter{page}{-1}% |
| 1346 |
\else% neither one loaded |
| 1347 |
\lastpage@putl@bel% |
| 1348 |
\fi% |
| 1349 |
% \end{macrocode} |
| 1350 |
% |
| 1351 |
% When writing to files is not allowed, nothing can be done. But when |
| 1352 |
% the label was already set via the \xfile{aux} file, nothing needs |
| 1353 |
% to be done. We check for this with |\lastpage@fileswtest| and |
| 1354 |
% (if \xpackage{hyperref} has been loaded) |\lastpage@fileswtestHy|. |
| 1355 |
% |
| 1356 |
% \begin{macrocode} |
| 1357 |
\else% |
| 1358 |
\ifx\lastpage@LTS\lastpage@one% |
| 1359 |
\else% |
| 1360 |
\lastpage@fileswtest{\thepage}{\lastpage@lastpage}% |
| 1361 |
\ifx\lastpage@hyper\lastpage@one% |
| 1362 |
\lastpage@fileswtestHy% |
| 1363 |
\fi% |
| 1364 |
\fi% |
| 1365 |
\fi% |
| 1366 |
} |
| 1367 |
% \end{macrocode} |
| 1368 |
% \end{macro} |
| 1369 |
% \begin{macrocode} |
| 1370 |
%</lastpageclassic> |
| 1371 |
% \end{macrocode} |
| 1372 |
% \newpage |
| 1373 |
% |
| 1374 |
% \DescribeMacro{lastpagemodern.sty} |
| 1375 |
% In case of a recent \LaTeX-format, \pkg{lastpagemodern.sty} is loaded: |
| 1376 |
% |
| 1377 |
% \begin{macrocode} |
| 1378 |
%<*lastpagemodern> |
| 1379 |
%% Part of the "lastpage" package |
| 1380 |
\NeedsTeXFormat{LaTeX2e}[2024-11-01] |
| 1381 |
\ProvidesPackage{lastpagemodern}[2025-08-14 v2.1h % |
| 1382 |
Refers to last page's name (HMM; JPG)] |
| 1383 |
%% allows for things like "Page \thepage{} of \pageref{LastPage}" |
| 1384 |
%% to get "Page 7 of 9" or "Page VII of IX"; |
| 1385 |
%% the NUMBER of pages is available via \@abspage@last, but with pages |
| 1386 |
%% for example I to X and then 1 to 10, the number of pages would be "20", |
| 1387 |
%% while the name of the last page is "10". Decide what you need/want! |
| 1388 |
|
| 1389 |
% \end{macrocode} |
| 1390 |
% |
| 1391 |
% \indent While this is \xfile{lastpagemodern.sty}, it belongs to the \xpackage{lastpage} package, |
| 1392 |
% therefore its hook label shall be |lastpage|. |
| 1393 |
% |
| 1394 |
% \begin{macrocode} |
| 1395 |
\PushDefaultHookLabel{lastpage} |
| 1396 |
|
| 1397 |
% \end{macrocode} |
| 1398 |
% |
| 1399 |
% \indent For comparisons, \textquotedblleft one\textquotedblright{} is defined |
| 1400 |
% (|\@ne| does not work for this). |
| 1401 |
% |
| 1402 |
% \begin{macrocode} |
| 1403 |
\gdef\lastpage@one{1} |
| 1404 |
% \end{macrocode} |
| 1405 |
% |
| 1406 |
% We define |\lastpage@firstpage| to be \textquotedblleft \texttt{1}\textquotedblright{}, |
| 1407 |
% and before re-definition via the \xfile{.aux} file, |
| 1408 |
% |\lastpage@lastpage| and |\lastpage@lastpageHy| are unknown. |
| 1409 |
% |
| 1410 |
% \begin{macrocode} |
| 1411 |
\gdef\lastpage@firstpage{1} |
| 1412 |
\gdef\lastpage@lastpage{??} |
| 1413 |
\gdef\lastpage@lastpageHy{??} |
| 1414 |
|
| 1415 |
% \end{macrocode} |
| 1416 |
% |
| 1417 |
% \begin{macro}{\lastpage@IfNumericTF} |
| 1418 |
% |\lastpage@IfNumericTF| was needed to determine whether a page number was numeric or not. |
| 1419 |
% Although it is no longer used, I am reluctant to remove it because it may have been used |
| 1420 |
% in other places in documents. |
| 1421 |
% |
| 1422 |
% \begin{macrocode} |
| 1423 |
\newcommand\lastpage@gobbleminus[1]{\ifx-#1\else#1\fi} |
| 1424 |
% \end{macrocode} |
| 1425 |
% which is from \url{https://texfaq.org/FAQ-isitanum}, |
| 1426 |
% \begin{macrocode} |
| 1427 |
\newcounter{lastpagecount} |
| 1428 |
% \end{macrocode} |
| 1429 |
% and similar to \url{https://tex.stackexchange.com/a/12811/17119} |
| 1430 |
% \begin{macrocode} |
| 1431 |
\newcommand{\lastpage@IfNumericTF}[3]{% |
| 1432 |
\sbox\z@{\c@lastpagecount=0\lastpage@gobbleminus{#1}\relax}% |
| 1433 |
\ifdim\wd0>\z@\relax#3% is not numeric |
| 1434 |
\else#2% is numeric |
| 1435 |
\fi} |
| 1436 |
|
| 1437 |
% \end{macrocode} |
| 1438 |
% \end{macro} |
| 1439 |
% |
| 1440 |
% \DescribeMacro{\AddToHook\{begindocument/end\}} |
| 1441 |
% \indent |\lastpage@putlabel|, used by older versions of this package, |
| 1442 |
% is/was redefined by other packages. |
| 1443 |
% While now |\lastpage@putl@bel| is used instead, other packages |
| 1444 |
% could also define a label \texttt{LastPage}, |
| 1445 |
% which then would be multiply defined. (Which is no big issue, |
| 1446 |
% if it is associated with the same page.) Therefore we define |
| 1447 |
% |
| 1448 |
% \begin{macrocode} |
| 1449 |
\AddToHook{begindocument/end}{% |
| 1450 |
\IfPackageLoadedT{pageslts}{% |
| 1451 |
\PackageNoteNoLine{lastpage}{Packages pageslts and lastpage used.\MessageBreak% |
| 1452 |
lastpage is not necessary when loading pageslts}% |
| 1453 |
}% |
| 1454 |
\gdef\lastpage@putlabel{\relax}% |
| 1455 |
} |
| 1456 |
|
| 1457 |
% \end{macrocode} |
| 1458 |
% \pagebreak |
| 1459 |
% |
| 1460 |
% \begin{macro}{\protected@iwrite} |
| 1461 |
% \indent We need an |\immediate\protected@write|. Just |\immediate\write| had led to errors, |
| 1462 |
% for example when packages like \pkg{babel-greek} re-defined |\roman|\ % |
| 1463 |
% (thanks to \textsc{Ulrike Fischer} for the report). |
| 1464 |
% |
| 1465 |
% \begin{macrocode} |
| 1466 |
%% Code provided by Prof. Enrico Gregorio at https://tex.stackexchange.com/a/542425 |
| 1467 |
\long\def\protected@iwrite#1#2#3{% |
| 1468 |
\begingroup% |
| 1469 |
#2% |
| 1470 |
\let\protect\@unexpandable@protect% |
| 1471 |
\edef\reserved@a{\immediate\write#1{#3}}% |
| 1472 |
\reserved@a% |
| 1473 |
\endgroup% |
| 1474 |
\if@nobreak\ifvmode\nobreak\fi\fi% |
| 1475 |
} |
| 1476 |
|
| 1477 |
% \end{macrocode} |
| 1478 |
% \end{macro} |
| 1479 |
% |
| 1480 |
% \begin{macro}{\lastpage@makeHy} |
| 1481 |
% Just once we need the page from |\@currentHpage| without any \mbox{\textquotedblleft |page.|\textquotedblright :} |
| 1482 |
% \begin{macrocode} |
| 1483 |
\newcommand{\lastpage@makeHy}{% |
| 1484 |
% \end{macrocode} |
| 1485 |
% |\gdef\lastpage@Hy{}|, but that was already done before this command. |
| 1486 |
% \begin{macrocode} |
| 1487 |
\def\lastpage@Hptest{Doc-Start}% |
| 1488 |
\ifx\lastpage@Hptest\@currentHpage\relax% |
| 1489 |
\gdef\lastpage@Hy{\@currentHpage}% |
| 1490 |
\else% |
| 1491 |
\edef\lastpage@Hptest{\@currentHpage}% |
| 1492 |
\ifx\lastpage@Hptest\empty\relax% |
| 1493 |
% \end{macrocode} |
| 1494 |
% |\gdef\lastpage@Hy{}|, but that was already done before this command. |
| 1495 |
% \begin{macrocode} |
| 1496 |
\else% |
| 1497 |
\def\lastpage@Hptest{page.}% |
| 1498 |
\ifx\lastpage@Hptest\@currentHpage\relax |
| 1499 |
\def\lastpage@Hptest{\csname @fnsymbol\endcsname \c@page }% |
| 1500 |
\ifx\lastpage@Hptest\thepage\relax% |
| 1501 |
\ifnum\value{page}=3\else% |
| 1502 |
\PackageWarningNoLine{lastpage}{You should add a\MessageBreak |
| 1503 |
\string\ProvideTextCommand{...}{PD1}{...}\MessageBreak% |
| 1504 |
(see the lastpage package manual, 3.13 % |
| 1505 |
\string\pagenumbering{fnsymbol})\MessageBreak% |
| 1506 |
to your document's preamble}% |
| 1507 |
% \end{macrocode} |
| 1508 |
% See \autoref{subsec:fnsymbol}: \nameref{subsec:fnsymbol}, page~\pageref{subsec:fnsymbol}. |
| 1509 |
% \begin{macrocode} |
| 1510 |
\fi% |
| 1511 |
\fi% |
| 1512 |
\PackageWarningNoLine{lastpage}{% |
| 1513 |
\string\@currentHpage\space is\MessageBreak% |
| 1514 |
just "page." without number,\MessageBreak% |
| 1515 |
\string\lastpage@lastpageHy\space is now let empty}% |
| 1516 |
% \end{macrocode} |
| 1517 |
% |\gdef\lastpage@Hy{}|, but that was already done before this command. |
| 1518 |
% \begin{macrocode} |
| 1519 |
\else% |
| 1520 |
% \end{macrocode} |
| 1521 |
% |\@currentHpage| should be |page.<some number>|, |\lastpage@rmpage| removes the |
| 1522 |
% \mbox{\textquotedblleft |page.|\textquotedblright .} Next compilation run, |
| 1523 |
% |\lastpage@lastpageHy| gets defined via the \xfile{aux} file. |
| 1524 |
% If we arrived at this place, but the definition is still empty, |
| 1525 |
% then |\@currentHpage| has some unexpected content. |
| 1526 |
% \begin{macrocode} |
| 1527 |
\gdef\lastpage@Hy{\lastpage@rmpage{\@currentHpage}}% |
| 1528 |
\ifx\lastpage@lastpageHy\empty\relax% |
| 1529 |
\PackageWarningNoLine{lastpage}{% |
| 1530 |
\string\@currentHpage\space is\MessageBreak% |
| 1531 |
\meaning\@currentHpage\MessageBreak% |
| 1532 |
not beginning with "page.",\MessageBreak% |
| 1533 |
\string\lastpage@lastpageHy\space is now let empty}% |
| 1534 |
\fi\fi\fi\fi% |
| 1535 |
} |
| 1536 |
|
| 1537 |
% \end{macrocode} |
| 1538 |
% \end{macro} |
| 1539 |
% \begin{macro}{\lastpage@rmpage} |
| 1540 |
% |\lastpage@rmpage| removes the \mbox{\textquotedblleft |page.|\textquotedblright.} |
| 1541 |
% |
| 1542 |
% \begin{macrocode} |
| 1543 |
%% Code provided by David Carlisle at https://tex.stackexchange.com/a/721877 |
| 1544 |
\def\lastpage@rmpage#1{% |
| 1545 |
\expandafter\xlastpage@rmpage\expanded{#1}\xlastpage@rmpage page.% |
| 1546 |
\xlastpage@rmpage\xxlastpage@rmpage{#1}} |
| 1547 |
\def\xlastpage@rmpage #1page.#2\xlastpage@rmpage#3\xxlastpage@rmpage#4{% |
| 1548 |
\if$\detokenize{#1}$#2%\else#4 |
| 1549 |
\fi} |
| 1550 |
|
| 1551 |
% \end{macrocode} |
| 1552 |
% |\else#4| means, that it did not start with |page.|, and whatever it is, |
| 1553 |
% we cannot use this |#4| for |\lastpage@Hy|. |
| 1554 |
% \end{macro} |
| 1555 |
% |
| 1556 |
% \begin{macro}{\lastpage@putl@bel} |
| 1557 |
% \indent This command does the writing of the label. |
| 1558 |
% If the \xpackage{hyperref} package is used, but page-anchors are disabled, |
| 1559 |
% the hyperlinking will not work. (The warning will also be shown, when only |
| 1560 |
% |\pageref*{LastPage}| is used (or neither |\pageref{LastPage}| nor |\pageref*{LastPage}|), |
| 1561 |
% but without messing with |\pageref| we cannot detect this.) |
| 1562 |
% |
| 1563 |
% \begin{macrocode} |
| 1564 |
\newcommand{\lastpage@putl@bel}{% |
| 1565 |
\IfPackageLoadedT{hyperref}{% |
| 1566 |
\IfPackageAtLeastF{hyperref}{2024-10-30}{% |
| 1567 |
\PackageError{lastpage}{hyperref package version too old}{% |
| 1568 |
required version: 2024-10-30 or newer, found version:\MessageBreak% |
| 1569 |
\csname [email protected]\endcsname\MessageBreak% |
| 1570 |
Update hyperref or use lastpageclassic.sty instead of\MessageBreak% |
| 1571 |
lastpagemodern.sty!}}% |
| 1572 |
\ifHy@pageanchor\else% |
| 1573 |
\PackageWarningNoLine{lastpage}{% |
| 1574 |
The \string\pageref{LastPage} link does not work\MessageBreak% |
| 1575 |
using hyperref with disabled option `pageanchor'.\MessageBreak% |
| 1576 |
Better enable `pageanchor' or use\MessageBreak% |
| 1577 |
\string\pageref*{LastPage} (not generating a link)}% |
| 1578 |
\fi% |
| 1579 |
}% |
| 1580 |
\begingroup% |
| 1581 |
% \end{macrocode} |
| 1582 |
% |
| 1583 |
% \noindent Since the page has been put out, we are on the page \textit{after} that page. |
| 1584 |
% We therefore subtract one from the page counter. (For the compiler, |
| 1585 |
% this is equal to |\advance\c@page\m@ne|, but for human readers of the code |
| 1586 |
% it is probably easier to understand.) |
| 1587 |
% |
| 1588 |
% |\addtocounter{page}{-1}| |
| 1589 |
% |
| 1590 |
% \noindent But \LaTeX\ News issue 41, June 2025 (\LaTeX\ release 2025-06-01), |
| 1591 |
% \url{https://www.latex-project.org/news/latex2e-news/ltnews41.pdf}, |
| 1592 |
% tells us: \textquotedblleft Ensuring late |\write| commands aren’t lost % |
| 1593 |
% \ldots\ After the last page has been shipped out, we therefore force all further |\write| |
| 1594 |
% calls to be |\immediate|\textquotedblright, i.\,e.~it is done at the right page and |
| 1595 |
% we no longer need to go back one page. |
| 1596 |
% |
| 1597 |
% \begin{macrocode} |
| 1598 |
\IfFormatAtLeastF{2025-06-01}{\addtocounter{page}{-1}}% |
| 1599 |
% \end{macrocode} |
| 1600 |
% |
| 1601 |
% If the \xpackage{pageslts} package is used, this \xpackage{lastpage} package |
| 1602 |
% is not needed at all. The \xpackage{LastPage} label would even be defined twice. |
| 1603 |
% Thus, if \xpackage{pageslts} is used, here nothing is done. |
| 1604 |
% |
| 1605 |
% \begin{macrocode} |
| 1606 |
\IfPackageLoadedF{pageslts}{% |
| 1607 |
% \end{macrocode} |
| 1608 |
% |
| 1609 |
% |\@currentlabelname| \emph{should} have been sanitized, but sometimes it is not. |
| 1610 |
% Therefore we get rid of any possible |\label|, |\index| and |\glossary| contained here. |
| 1611 |
% This code is inside a |\begingroup|\ldots|\endgroup|, thus there is no need to save |
| 1612 |
% and later restore the original meaning of those commands. |
| 1613 |
% |
| 1614 |
% \begin{macrocode} |
| 1615 |
\let\label\@gobble@om% |
| 1616 |
\let\index\@gobble@som% |
| 1617 |
\let\glossary\@gobble@om% |
| 1618 |
% \end{macrocode} |
| 1619 |
% |
| 1620 |
% \noindent Simply using |\label| for \texttt{LastPage} would not work, |
| 1621 |
% because labels wait for the output routines to work, and there |
| 1622 |
% may be no more invocations of the output routines. |
| 1623 |
% (Additionally we just disabled |\label|.) |
| 1624 |
% To force the write out, we need to do an |\immediate| protected write |
| 1625 |
% into the \xfile{aux} file. |
| 1626 |
% |
| 1627 |
% \begin{macrocode} |
| 1628 |
\protected@iwrite\@auxout{}{\string\newlabel{LastPage}{% |
| 1629 |
{\@currentlabel}{\thepage}{\@currentlabelname}% |
| 1630 |
{\IfPackageLoadedTF{hyperref}{\ifHy@pageanchor\@currentHpage\fi% |
| 1631 |
}{\@currentHref}}% |
| 1632 |
{\@kernel@reserved@label@data}}% |
| 1633 |
}% |
| 1634 |
}% Otherwise pageslts writes the label for "LastPage". |
| 1635 |
% \end{macrocode} |
| 1636 |
% |
| 1637 |
% \noindent We also save the values, so that we can later (next rerun) check, |
| 1638 |
% whether they have been saved in the \xfile{aux} file. |
| 1639 |
% |
| 1640 |
% \begin{macrocode} |
| 1641 |
\protected@iwrite\@auxout{}{% |
| 1642 |
\string\gdef\string\lastpage@lastpage{\thepage}}% |
| 1643 |
\gdef\lastpage@Hy{}% |
| 1644 |
\IfPackageLoadedT{hyperref}{\ifHy@pageanchor\lastpage@makeHy\fi}% |
| 1645 |
\protected@iwrite\@auxout{}{% |
| 1646 |
\string\gdef\string\lastpage@lastpageHy{\lastpage@Hy}}% |
| 1647 |
% \end{macrocode} |
| 1648 |
% |
| 1649 |
% \noindent After the write-out we restore the page number again |
| 1650 |
% (if we changed it), since there might be other things still to be done. |
| 1651 |
% |
| 1652 |
% \begin{macrocode} |
| 1653 |
\IfFormatAtLeastF{2025-06-01}{\addtocounter{page}{+1}}% |
| 1654 |
\endgroup% |
| 1655 |
} |
| 1656 |
|
| 1657 |
% \end{macrocode} |
| 1658 |
% \end{macro} |
| 1659 |
% |
| 1660 |
% \begin{macro}{\lastpage@fileswtest} |
| 1661 |
% \indent \hspace*{2em}Later it will be determined whether it is allowed to write |
| 1662 |
% to the \xfile{aux} file. If it was \emph{not} allowed, it is checked |
| 1663 |
% whether the label was already set via the \xfile{aux} file in some |
| 1664 |
% earlier compilation run. (There are packages where the document |
| 1665 |
% is compiled with access to the \xfile{aux} file, and then there is |
| 1666 |
% an additional compiler run, where the \xfile{aux} file cannot be changed, |
| 1667 |
% but in that run there is also no need to change it.) The \xpackage{tikz} |
| 1668 |
% package is somewhat different, therefore we only give a warning instead |
| 1669 |
% of an error (and hope that there is another compiler run where the |
| 1670 |
% \xfile{aux} file can be written). |
| 1671 |
% |
| 1672 |
% \begin{macrocode} |
| 1673 |
\newcommand{\lastpage@fileswtest}[2]{% |
| 1674 |
\edef\lastpage@testa{#1}% |
| 1675 |
\edef\lastpage@testb{#2}% |
| 1676 |
\ifx\lastpage@testa\lastpage@testb% |
| 1677 |
\else% |
| 1678 |
\IfPackageLoadedTF{tikz}{% |
| 1679 |
\PackageWarning{lastpage}% |
| 1680 |
{The lastpage package was not allowed to write to an\MessageBreak% |
| 1681 |
.aux file. This package does not work without access\MessageBreak% |
| 1682 |
to an .aux file.\MessageBreak% |
| 1683 |
It is OK if the .aux file was already updated\MessageBreak% |
| 1684 |
by a previous compiler run\MessageBreak% |
| 1685 |
and would not have changed anyway.\MessageBreak% |
| 1686 |
}% |
| 1687 |
}{\PackageError{lastpage}{No auxiliary file allowed}% |
| 1688 |
{The lastpage package was not allowed to write to an .aux file.\MessageBreak% |
| 1689 |
This package does not work without access to an .aux file.\MessageBreak% |
| 1690 |
Press Ctrl+Z to exit.\MessageBreak% |
| 1691 |
But it is OK if the .aux file was already updated\MessageBreak% |
| 1692 |
by a previous compiler run\MessageBreak% |
| 1693 |
and would not have changed anyway.\MessageBreak% |
| 1694 |
}% |
| 1695 |
}% |
| 1696 |
\fi% |
| 1697 |
} |
| 1698 |
|
| 1699 |
% \end{macrocode} |
| 1700 |
% \end{macro} |
| 1701 |
% |
| 1702 |
% \begin{macro}{\lastpage@fileswtestHy} |
| 1703 |
% \indent \hspace*{2em}When the \xpackage{hyperref} package has been loaded, |
| 1704 |
% |\lastpage@lastpageHy| must be tested additionally. (And a |
| 1705 |
% |\newcommand| is needed, because |\ifHy@pageanchor| is not even |
| 1706 |
% defined when \xpackage{hyperref} has not been loaded.) |
| 1707 |
% |
| 1708 |
% \begin{macrocode} |
| 1709 |
\newcommand{\lastpage@fileswtestHy}{% |
| 1710 |
\ifHy@pageanchor% |
| 1711 |
\lastpage@fileswtest{\@currentHpage}{\@the@H@page}% |
| 1712 |
\else% |
| 1713 |
\lastpage@fileswtest{\empty}{\lastpage@lastpageHy}% |
| 1714 |
\fi% |
| 1715 |
} |
| 1716 |
|
| 1717 |
% \end{macrocode} |
| 1718 |
% \end{macro} |
| 1719 |
% |
| 1720 |
% \DescribeMacro{enddocument/afterlastpage} |
| 1721 |
% \indent |enddocument/afterlastpage| we again (re)define |\lastpage@putlabel| |
| 1722 |
% to do nothing, but first use it to check whether |\lastpage@lastpage| |
| 1723 |
% is still unchanged, which is OK for the first run only. |
| 1724 |
% |
| 1725 |
% \begin{macrocode} |
| 1726 |
\AddToHook{enddocument/afterlastpage}{% |
| 1727 |
\gdef\lastpage@putlabel{??}% |
| 1728 |
\ifx\lastpage@lastpage\lastpage@putlabel\relax% |
| 1729 |
\AddToHook{enddocument/info}{% |
| 1730 |
\PackageWarning{lastpage}{Rerun to get the references right}% |
| 1731 |
}% |
| 1732 |
\fi% |
| 1733 |
\gdef\lastpage@putlabel{\relax}% |
| 1734 |
% \end{macrocode} |
| 1735 |
% |
| 1736 |
% It is checked whether writing to files is allowed |
| 1737 |
% (otherwise, only an error message is issued and nothing is done). |
| 1738 |
% |
| 1739 |
% \begin{macrocode} |
| 1740 |
\if@filesw% |
| 1741 |
% \end{macrocode} |
| 1742 |
% |
| 1743 |
% We put in a |\message| to show, in what order things (which were called) are done. |
| 1744 |
% |
| 1745 |
% \begin{macrocode} |
| 1746 |
\message{^^Jenddocument/afterlastpage (AED): lastpage setting LastPage.^^J}% |
| 1747 |
\IfFormatAtLeastTF{2025-06-01}{\lastpage@putl@bel}{% |
| 1748 |
\IfPackageLoadedTF{french}{% |
| 1749 |
\addtocounter{page}{+1}\lastpage@putl@bel\addtocounter{page}{-1}% |
| 1750 |
}{\IfPackageLoadedTF{frenchle}{% |
| 1751 |
\addtocounter{page}{+1}\lastpage@putl@bel\addtocounter{page}{-1}% |
| 1752 |
}{\lastpage@putl@bel% |
| 1753 |
}% |
| 1754 |
}% |
| 1755 |
}% |
| 1756 |
\else% |
| 1757 |
% \end{macrocode} |
| 1758 |
% |
| 1759 |
% When writing to files is not allowed, nothing can be done. But when |
| 1760 |
% the label was already set via the \xfile{aux} file, nothing needs |
| 1761 |
% to be done. We check for this with |\lastpage@fileswtest| and |
| 1762 |
% (if \xpackage{hyperref} has been loaded) |\lastpage@fileswtestHy|. |
| 1763 |
% |
| 1764 |
% \begin{macrocode} |
| 1765 |
\lastpage@fileswtest{\thepage}{\lastpage@lastpage}% |
| 1766 |
\IfPackageLoadedT{hyperref}{\lastpage@fileswtestHy}% |
| 1767 |
\fi% |
| 1768 |
} |
| 1769 |
|
| 1770 |
% \end{macrocode} |
| 1771 |
% |
| 1772 |
% For \xfile{lastpagemodern.sty} we changed the default hook label to |lastpage| |
| 1773 |
% and need to stop the change at the end of the package. |
| 1774 |
% |
| 1775 |
% \begin{macrocode} |
| 1776 |
\PopDefaultHookLabel |
| 1777 |
%</lastpagemodern> |
| 1778 |
% \end{macrocode} |
| 1779 |
% \newpage |
| 1780 |
% |
| 1781 |
% \section{Installation} |
| 1782 |
% \subsection{Downloads\label{ss:Downloads}} |
| 1783 |
% Everything is available at \url{https://www.ctan.org}, |
| 1784 |
% but may need additional packages themselves. |
| 1785 |
% |
| 1786 |
% \DescribeMacro{lastpage.dtx} |
| 1787 |
% For unpacking the |lastpage.dtx| file and constructing the documentation it is required: |
| 1788 |
% \begin{description} |
| 1789 |
% \item[-] \TeX Format \LaTeXe{}: \url{https://www.CTAN.org} |
| 1790 |
% |
| 1791 |
% \item[-] document class \xclass{ltxdoc}, 2024/02/08, v2.1j, |
| 1792 |
% \url{https://ctan.org/pkg/ltxdoc} |
| 1793 |
% |
| 1794 |
% \item[-] package \xpackage{holtxdoc}, 2019/12/09, v0.30, |
| 1795 |
% \url{https://ctan.org/pkg/holtxdoc} |
| 1796 |
% \end{description} |
| 1797 |
% |
| 1798 |
% \DescribeMacro{lastpage.sty} |
| 1799 |
% The |lastpage.sty| (i.\,e.\ each document using the \xpackage{lastpage} package) |
| 1800 |
% requires: |
| 1801 |
% \begin{description} |
| 1802 |
% \item[-] \TeX, \url{https://www.CTAN.org} |
| 1803 |
% |
| 1804 |
% \item[-] package \xpackage{lastpage}, 2025-08-14, v2.1h, |
| 1805 |
% \url{https://ctan.org/pkg/lastpage} |
| 1806 |
% \end{description} |
| 1807 |
% |
| 1808 |
% \DescribeMacro{lastpage209.sty} |
| 1809 |
% The |lastpage209.sty| for \LaTeX2.09{} (i.\,e.\ each document using |
| 1810 |
% the \xpackage{lastpage209} package) requires: |
| 1811 |
% \begin{description} |
| 1812 |
% \item[-] \TeX-format \LaTeX{}, v2.09 |
| 1813 |
% |
| 1814 |
% \item[-] package \xpackage{lastpage209}, 2025-08-14, v2.1h, |
| 1815 |
% \url{https://ctan.org/pkg/lastpage} |
| 1816 |
% \end{description} |
| 1817 |
% and does not work with \xpackage{hyperref}, which needs \LaTeX2e{}.\smallskip |
| 1818 |
% |
| 1819 |
% \DescribeMacro{lastpage2e.sty} |
| 1820 |
% The |lastpage2e.sty| for \LaTeXe{} (i.\,e.\ each document using |
| 1821 |
% the \xpackage{lastpage2e} package) requires: |
| 1822 |
% \begin{description} |
| 1823 |
% \item[-] \TeX-format \LaTeXe{} 1994/12/01 or newer, |
| 1824 |
% \url{https://www.CTAN.org} |
| 1825 |
% |
| 1826 |
% \item[-] package \xpackage{lastpage}, 2025-08-14, v2.1h, |
| 1827 |
% \url{https://ctan.org/pkg/lastpage} |
| 1828 |
% \end{description} |
| 1829 |
% |
| 1830 |
% \DescribeMacro{lastpageclassic.sty} |
| 1831 |
% The |lastpageclassic.sty| for \LaTeXe{} (i.\,e.\ each document using |
| 1832 |
% the \xpackage{lastpageclassic} package) requires: |
| 1833 |
% \begin{description} |
| 1834 |
% \item[-] \TeX-format \LaTeXe{} between 1994/12/01 and 2024-05-31,\newline |
| 1835 |
% \url{https://www.CTAN.org} |
| 1836 |
% |
| 1837 |
% \item[-] package \xpackage{lastpage}, 2025-08-14, v2.1h, |
| 1838 |
% \url{https://ctan.org/pkg/lastpage} |
| 1839 |
% \end{description} |
| 1840 |
% and can use |
| 1841 |
% \begin{description} |
| 1842 |
% \item[-] package \xpackage{hyperref}, 2023-07-08, v7.01b, |
| 1843 |
% \url{https://ctan.org/pkg/hyperref}\newline |
| 1844 |
% (probably also some older and newer versions) |
| 1845 |
% \end{description} |
| 1846 |
% |
| 1847 |
% \DescribeMacro{lastpagemodern.sty} |
| 1848 |
% The |lastpagemodern.sty| for \LaTeXe{} (i.\,e.\ each document using |
| 1849 |
% the \xpackage{lastpagemodern} package) requires: |
| 1850 |
% \begin{description} |
| 1851 |
% \item[-] \TeX-format \LaTeXe{} 2024-11-01 or newer,\newline |
| 1852 |
% \url{https://www.CTAN.org} |
| 1853 |
% |
| 1854 |
% \item[-] package \xpackage{lastpage}, 2025-08-14, v2.1h, |
| 1855 |
% \url{https://ctan.org/pkg/lastpage} |
| 1856 |
% \end{description} |
| 1857 |
% and can use |
| 1858 |
% \begin{description} |
| 1859 |
% \item[-] package \xpackage{hyperref}, probably 2023-11-07 and newer |
| 1860 |
% (tested with: 2025-07-12, v7.01o), |
| 1861 |
% \url{https://ctan.org/pkg/hyperref} |
| 1862 |
% \end{description} |
| 1863 |
% \pagebreak |
| 1864 |
% |
| 1865 |
% \DescribeMacro{lastpage-example.tex} |
| 1866 |
% The |lastpage-example.tex| requires the same file as all |
| 1867 |
% documents using the \xpackage{lastpage} package, i.\,e. |
| 1868 |
% \begin{description} |
| 1869 |
% \item[-] package \xpackage{lastpage}, 2025-08-14, v2.1h, |
| 1870 |
% \url{https://ctan.org/pkg/lastpage}\newline |
| 1871 |
% (Well, it is the example file for this package, and because you are reading the |
| 1872 |
% documentation for the \xpackage{lastpage} package, it can be assumed that you already |
| 1873 |
% have some version of it -- is it the current one?) |
| 1874 |
% \end{description} |
| 1875 |
% and additionally: |
| 1876 |
% \begin{description} |
| 1877 |
% \item[-] class \xpackage{article}, 2025/01/22, v1.4n, from \xpackage{classes}: |
| 1878 |
% \url{https://ctan.org/pkg/classes} |
| 1879 |
% |
| 1880 |
% \item[-] package \xpackage{showkeys}, 2024-05-23, v3.21, |
| 1881 |
% \url{https://ctan.org/pkg/showkeys} |
| 1882 |
% |
| 1883 |
% \item[-] package \xpackage{hyperref}, 2025-07-12, v7.01o, |
| 1884 |
% \url{https://ctan.org/pkg/hyperref} |
| 1885 |
% \end{description} |
| 1886 |
% |
| 1887 |
% \DescribeMacro{Münch} |
| 1888 |
% A hyperlinked list of my (other) packages can be found at\newline |
| 1889 |
% \url{https://ctan.org/author/muench-hm}. |
| 1890 |
% |
| 1891 |
% \subsection{Package, unpacking TDS} |
| 1892 |
% \paragraph{Package.} This package is available on \url{https://www.CTAN.org}. |
| 1893 |
% \begin{description} |
| 1894 |
% \item[\url{https://mirror.ctan.org/macros/latex/contrib/lastpage/lastpage.dtx}]\hspace*{0.1cm} \newline |
| 1895 |
% The source file. |
| 1896 |
% \item[\url{https://mirror.ctan.org/macros/latex/contrib/lastpage/lastpage.pdf}]\hspace*{0.1cm} \newline |
| 1897 |
% The documentation. |
| 1898 |
% \item[\url{https://mirror.ctan.org/macros/latex/contrib/lastpage/lastpage-example.pdf}]\hspace*{0.1cm} |
| 1899 |
% The compiled example file, as it should look like. |
| 1900 |
% \item[\url{https://mirror.ctan.org/macros/latex/contrib/lastpage/README}]\hspace*{0.1cm} \newline |
| 1901 |
% The README file. |
| 1902 |
% \end{description} |
| 1903 |
% There is also a |lastpage.tds.zip| available: |
| 1904 |
% \begin{description} |
| 1905 |
% \item[\url{https://mirror.ctan.org/install/macros/latex/contrib/lastpage.tds.zip}]\hspace*{0.1cm} |
| 1906 |
% Everything in TDS compliant, compiled format. |
| 1907 |
% \end{description} |
| 1908 |
% which additionally contains\newline |
| 1909 |
% \begin{tabular}{ll} |
| 1910 |
% lastpage.ins & The \texttt{ins}tallation file.\\ |
| 1911 |
% lastpage.drv & The \mbox{\texttt{dr}i\texttt{v}er} to generate the documentation.\\ |
| 1912 |
% lastpage.sty & The \texttt{sty}le file.\\ |
| 1913 |
% lastpage209.sty & The \texttt{sty}le file for \LaTeX2.09{} \textbf{only}.\\ |
| 1914 |
% lastpage2e.sty & The \texttt{sty}le file to determine which 2e-style to use.\\ |
| 1915 |
% lastpageclassic.sty & The \texttt{sty}le file for older \LaTeX-formats.\\ |
| 1916 |
% lastpagemodern.sty & The \texttt{sty}le file for the recent \LaTeX-format.\\ |
| 1917 |
% lastpage-example.tex & The example file. |
| 1918 |
% \end{tabular} |
| 1919 |
% |
| 1920 |
% \bigskip |
| 1921 |
% |
| 1922 |
% \noindent For required other packages please see the preceding subsection. |
| 1923 |
% |
| 1924 |
% \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting |
| 1925 |
% \docstrip{} archive. The files are extracted by running the |
| 1926 |
% \xext{dtx} through \plainTeX : |
| 1927 |
% \begin{quote} |
| 1928 |
% \verb|tex lastpage.dtx| |
| 1929 |
% \end{quote} |
| 1930 |
% |
| 1931 |
% \noindent About generating the documentation see paragraph~\ref{GenDoc} below.\par |
| 1932 |
% |
| 1933 |
% \paragraph{TDS.} Now the different files must be moved into |
| 1934 |
% the different directories in your installation TDS tree |
| 1935 |
% (also known as \xfile{texmf} tree): |
| 1936 |
% \begin{quote} |
| 1937 |
% \def\t{^^A |
| 1938 |
% \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}} |
| 1939 |
% lastpage.sty & tex/latex/lastpage.sty\\ |
| 1940 |
% lastpage209.sty & tex/latex/lastpage.sty\\ |
| 1941 |
% lastpage2e.sty & tex/latex/lastpage.sty\\ |
| 1942 |
% lastpageclassic.sty & tex/latex/lastpage.sty\\ |
| 1943 |
% lastpagemodern.sty & tex/latex/lastpage.sty\\ |
| 1944 |
% lastpage.pdf & doc/latex/lastpage.pdf\\ |
| 1945 |
% lastpage-example.tex & doc/latex/lastpage-example.tex\\ |
| 1946 |
% lastpage-example.pdf & doc/latex/lastpage-example.pdf\\ |
| 1947 |
% lastpage.dtx & source/latex/lastpage.dtx |
| 1948 |
% \end{tabular}^^A |
| 1949 |
% }^^A |
| 1950 |
% \sbox0{\t}^^A |
| 1951 |
% \ifdim\wd0>\linewidth |
| 1952 |
% \begingroup |
| 1953 |
% \advance\linewidth by\leftmargin |
| 1954 |
% \advance\linewidth by\rightmargin |
| 1955 |
% \edef\x{\endgroup |
| 1956 |
% \def\noexpand\lw{\the\linewidth}^^A |
| 1957 |
% }\x |
| 1958 |
% \def\lwbox{^^A |
| 1959 |
% \leavevmode |
| 1960 |
% \hbox to \linewidth{^^A |
| 1961 |
% \kern-\leftmargin\relax |
| 1962 |
% \hss |
| 1963 |
% \usebox0 |
| 1964 |
% \hss |
| 1965 |
% \kern-\rightmargin\relax |
| 1966 |
% }^^A |
| 1967 |
% }^^A |
| 1968 |
% \ifdim\wd0>\lw |
| 1969 |
% \sbox0{\small\t}^^A |
| 1970 |
% \ifdim\wd0>\linewidth |
| 1971 |
% \ifdim\wd0>\lw |
| 1972 |
% \sbox0{\footnotesize\t}^^A |
| 1973 |
% \ifdim\wd0>\linewidth |
| 1974 |
% \ifdim\wd0>\lw |
| 1975 |
% \sbox0{\scriptsize\t}^^A |
| 1976 |
% \ifdim\wd0>\linewidth |
| 1977 |
% \ifdim\wd0>\lw |
| 1978 |
% \sbox0{\tiny\t}^^A |
| 1979 |
% \ifdim\wd0>\linewidth |
| 1980 |
% \lwbox |
| 1981 |
% \else |
| 1982 |
% \usebox0 |
| 1983 |
% \fi |
| 1984 |
% \else |
| 1985 |
% \lwbox |
| 1986 |
% \fi |
| 1987 |
% \else |
| 1988 |
% \usebox0 |
| 1989 |
% \fi |
| 1990 |
% \else |
| 1991 |
% \lwbox |
| 1992 |
% \fi |
| 1993 |
% \else |
| 1994 |
% \usebox0 |
| 1995 |
% \fi |
| 1996 |
% \else |
| 1997 |
% \lwbox |
| 1998 |
% \fi |
| 1999 |
% \else |
| 2000 |
% \usebox0 |
| 2001 |
% \fi |
| 2002 |
% \else |
| 2003 |
% \lwbox |
| 2004 |
% \fi |
| 2005 |
% \else |
| 2006 |
% \usebox0 |
| 2007 |
% \fi |
| 2008 |
% \end{quote} |
| 2009 |
% If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's |
| 2010 |
% TDS installing feature, then some files can already be in the right |
| 2011 |
% place, see the documentation of \docstrip. |
| 2012 |
% |
| 2013 |
% \subsection{Refresh file name databases} |
| 2014 |
% If your \TeX~distribution (\TeX\,Live, \mikTeX, \dots) relies on |
| 2015 |
% file name databases, you must refresh these. For example, \TeX\,Live\ users |
| 2016 |
% run \verb|texhash| or \verb|mktexlsr|. |
| 2017 |
% |
| 2018 |
% \subsection{Some details for the interested} |
| 2019 |
% \paragraph{Unpacking with \LaTeX.} |
| 2020 |
% The \xfile{.dtx} chooses its action depending on the format: |
| 2021 |
% \begin{description} |
| 2022 |
% \item[\plainTeX:] Run \docstrip\ and extract the files. |
| 2023 |
% \item[\LaTeX:] Generate the documentation. |
| 2024 |
% \end{description} |
| 2025 |
% If you insist on using \LaTeX\ for \docstrip\ (really, |
| 2026 |
% \docstrip\ does not need \LaTeX ), then inform the autodetect routine |
| 2027 |
% about your intention: |
| 2028 |
% \begin{quote} |
| 2029 |
% \verb|latex \let\install=y\input{lastpage.dtx}| |
| 2030 |
% \end{quote} |
| 2031 |
% Do not forget to quote the argument according to the demands |
| 2032 |
% of your shell. |
| 2033 |
% |
| 2034 |
% \paragraph{Generating the documentation.\label{GenDoc}} |
| 2035 |
% You can use both the \xfile{.dtx} or the \xfile{.drv} to generate |
| 2036 |
% the documentation. The process can be configured by a |
| 2037 |
% configuration file \xfile{ltxdoc.cfg}. For instance, put the following |
| 2038 |
% line into this file, if you want to have A4 as paper format: |
| 2039 |
% \begin{quote} |
| 2040 |
% \verb|\PassOptionsToClass{a4paper}{article}| |
| 2041 |
% \end{quote} |
| 2042 |
% |
| 2043 |
% \noindent An example follows how to generate the |
| 2044 |
% documentation with \pdfLaTeX : |
| 2045 |
% |
| 2046 |
% \begin{quote} |
| 2047 |
%\begin{verbatim} |
| 2048 |
%pdflatex lastpage.dtx |
| 2049 |
%makeindex -s gind.ist lastpage.idx |
| 2050 |
%pdflatex lastpage.dtx |
| 2051 |
%makeindex -s gind.ist lastpage.idx |
| 2052 |
%pdflatex lastpage.dtx |
| 2053 |
%\end{verbatim} |
| 2054 |
% \end{quote} |
| 2055 |
% |
| 2056 |
% \subsection{Compiling the example} |
| 2057 |
% The example file, \textsf{lastpage-example.tex}, can be compiled via\newline |
| 2058 |
% \indent |latex lastpage-example.tex|\newline |
| 2059 |
% or (recommended)\newline |
| 2060 |
% \indent |pdflatex lastpage-example.tex|\newline |
| 2061 |
% and will need at least two compiler runs to get all references right. |
| 2062 |
% |
| 2063 |
% \section{Acknowledgements} |
| 2064 |
% |
| 2065 |
% I (\textsc{H.-Martin Münch}) would like to thank |
| 2066 |
% \textsc{Jeffrey P. Goldberg} \mbox{(jeffrey+}\allowbreak news at goldmark dot org) for |
| 2067 |
% inventing the \xpackage{lastpage} package as well as for allowing me |
| 2068 |
% to update it. Further I would like to thank \textsc{Heiko Oberdiek} |
| 2069 |
% for providing a~lot~(!) of useful packages (from which I also learned everything |
| 2070 |
% I know about creating a file in \xfile{dtx} format, OK, say it: copying). |
| 2071 |
% Thanks to \textsc{David Carlisle} for the new code for |\lastpage@rmpage|. |
| 2072 |
% Thanks for bug reports go to \textsc{Ulrike Fischer} (several times), |
| 2073 |
% \textsc{Sebastian Bank}, \textsc{James Hedges}, \textsc{Mikhail Titov}, |
| 2074 |
% \textsc{Micha\l{} Herman}, \textsc{Matteo Gamboz}, \textsc{James Small}, |
| 2075 |
% and \textsc{Ioannis Tsoulos}. |
| 2076 |
% Thanks to \textsc{Sven Siegmund} for pointing out a necessary further |
| 2077 |
% explanation in the documentation. |
| 2078 |
% |
| 2079 |
% \phantomsection |
| 2080 |
% \begin{History}\label{History} |
| 2081 |
% \begin{Version}{1994/06/17 v0.99a} |
| 2082 |
% \item First shot by \textsc{Jeffrey P. Goldberg}. |
| 2083 |
% \end{Version} |
| 2084 |
% \begin{Version}{1994/06/25 v0.1b} |
| 2085 |
% \item Last version number created by \textsc{Jeffrey P. Goldberg}. |
| 2086 |
% \end{Version} |
| 2087 |
% \begin{Version}{1994/07/20 v0.1b (again)} |
| 2088 |
% \item Documentation updated by \textsc{Jeffrey P. Goldberg}.\newline |
| 2089 |
% The main source code of the \xpackage{lastpage} package 1994/07/20, |
| 2090 |
% v0.1b, was: |
| 2091 |
% \begin{verbatim} |
| 2092 |
% \NeedsTeXFormat{LaTeX2e}[1994/06/01] |
| 2093 |
% \ProvidesPackage{lastpage}[1994/07/20 v0.1b |
| 2094 |
% LaTeX2e package for refs to last page number (JPG)] |
| 2095 |
% \def\lastpage@putlabel{\addtocounter{page}{-1}% |
| 2096 |
% \immediate\write\@auxout{\string |
| 2097 |
% \newlabel{LastPage}{{}{\thepage}}}% |
| 2098 |
% \addtocounter{page}{1}} |
| 2099 |
% \AtEndDocument{% |
| 2100 |
% \message{AED: lastpage setting LastPage}% |
| 2101 |
% \clearpage\lastpage@putlabel}% |
| 2102 |
% \endinput |
| 2103 |
% \end{verbatim} |
| 2104 |
% and then the \xpackage{hyperref} package (2012/11/06, v6.83m) |
| 2105 |
% even redefined |\lastpage@putlabel|; the \xpackage{REV\TeX{}4} |
| 2106 |
% class 2022-06-05, v4.2f, still does this. |
| 2107 |
% \end{Version} |
| 2108 |
% \begin{Version}{2010/02/18 v1.1} |
| 2109 |
% \item Proposed |LastPages| label by \textsc{H.-Martin Münch} |
| 2110 |
% on \Newsgroup{comp.text.tex}, see e.\,g.\ % |
| 2111 |
% \url{https://groups.google.com/g/comp.text.tex/c/Ad8pO2Rw_HY/m/8EfHqT1JB0QJ}; |
| 2112 |
% now available in the \xpackage{pageslts} package. |
| 2113 |
% \end{Version} |
| 2114 |
% \begin{Version}{2010/07/29 v1.2a} |
| 2115 |
% \item Complete rewriting of the package; upgrade from \xpackage{fancyheadings} |
| 2116 |
% to \xpackage{fancyhdr} package, then removed the need for the |
| 2117 |
% \xpackage{fancyhdr} package at all. |
| 2118 |
% \item Included \textsf{lastpage209.sty} for \LaTeX2.09{}. |
| 2119 |
% \item Replacement of |\filedate|, |-version|, |-name|,\ldots{} because |
| 2120 |
% of \LaTeX{}~bug 2705:\newline |
| 2121 |
% Synopsis: Possible problem with |\fileversion| and |\filedate|\newline |
| 2122 |
% \url{https://www.latex-project.org/cgi-bin/ltxbugs2html?category=LaTeX&responsible=anyone&state=anything&keyword=lastpage&pr=latex/2705} |
| 2123 |
% \item Example |lastpage-example.tex|. |
| 2124 |
% \item Alternatives listing (section \ref{sec:Alternatives}). |
| 2125 |
% \item Listing of \TeX{} sources (subsection \ref{ss:Downloads}). |
| 2126 |
% \item Really a lot of details. |
| 2127 |
% \item Complete rewriting of the documentation. |
| 2128 |
% \item Everything in \texttt{DTX} framework. |
| 2129 |
% \item Included a |\CheckSum|. [Removed in v2.0a.] |
| 2130 |
% \item Complete rewriting of the README file. |
| 2131 |
% \end{Version} |
| 2132 |
% \begin{Version}{2010/08/12 v1.2b} |
| 2133 |
% \item Bug fix: |\@PackageInfoNoLine| is only available, |
| 2134 |
% if the \xpackage{hyperref} package is loaded. |
| 2135 |
% (Bug reported by \textsc{Ulrike Fischer}, thanks!) |
| 2136 |
% \item Bug fix: |\ifHy@pageanchor| etc. do not work without |
| 2137 |
% \xpackage{hyperref}, and |\else| related to |\ifHy@pageanchor| was |
| 2138 |
% wrongly associated with a preceding |\if|, and everything went wrong. |
| 2139 |
% Now everything should work again also without \xpackage{hyperref}. |
| 2140 |
% \item Renamed |\lastpage@putlabel| to |\lastpage@putl@bel| to get rid of |
| 2141 |
% the conflicts with other classes and packages and resulting |
| 2142 |
% multiple definitions of the \texttt{lastpage} label. |
| 2143 |
% \end{Version} |
| 2144 |
% \begin{Version}{2010/08/23 v1.2c} |
| 2145 |
% \item Bug fix: Additionally to checking for the \xpackage{hyperref} package |
| 2146 |
% |\AtBeginDocument|, when placing the \texttt{lastpage} label it is also |
| 2147 |
% checked for the |\hyperref| command, in case \xpackage{hyperref} was not |
| 2148 |
% loaded at |\begin{document}| yet. (Bug reported by \textsc{Sebastian Bank}, |
| 2149 |
% thanks!)\newline |
| 2150 |
% [\pkg{lastpagemodern.sty} just uses |\IfPackageLoadedT{hyperref}| and |
| 2151 |
% |\IfPackageLoadedTF{hyperref}|.] |
| 2152 |
% \item Changed the |\unit| definition (got rid of an old |\rm|). [Removed in v2.0a.] |
| 2153 |
% \item Changed |\lastpage@puthyperlabel| to |\lastpage@putlabelhyper| analogous to |
| 2154 |
% |\pagesLTS@putlabelhyper| of the \xpackage{pageslts} package. |
| 2155 |
% \item Updated version number and date of \xpackage{pagesLTS} package (especially |
| 2156 |
% for the check for outdated versions). [Removed in v2.0a.] |
| 2157 |
% \item Removed wrong \%\ from the driver file. |
| 2158 |
% \end{Version} |
| 2159 |
% \begin{Version}{2010/08/25 v1.2d} |
| 2160 |
% \item Bug fix: also \xpackage{tcilatex} defines the |\hyperref| command, |
| 2161 |
% therefore for \xpackage{hyperref} package detection this had to be |
| 2162 |
% changed to |\Hy@Warning|.\newline |
| 2163 |
% [\pkg{lastpagemodern.sty} just uses |\IfPackageLoadedTF{hyperref}|.] |
| 2164 |
% \end{Version} |
| 2165 |
% \begin{Version}{2010/09/12 v1.2e} |
| 2166 |
% \item \textsc{James Hedges} pointed out, that there was no instruction in the |
| 2167 |
% documentation about suppressing hyperlinks: added (also to the example). |
| 2168 |
% \item Diverse small changes. |
| 2169 |
% \end{Version} |
| 2170 |
% \begin{Version}{2010/09/24 v1.2f} |
| 2171 |
% \item Updated to version 2010/09/13 v6.81n of the \xpackage{hyperref} package. |
| 2172 |
% \item New version of REV\TeX{}4\ 2010/07/25, v4.1r, old problem. |
| 2173 |
% \item New version of \xpackage{pagesLTS} package, 2010/09/22, v1.1k. |
| 2174 |
% \item Moved the package from \texttt{.../latex/muench/lastpage/...} to\newline |
| 2175 |
% \texttt{.../latex/lastpage/...}. |
| 2176 |
% \end{Version} |
| 2177 |
% \begin{Version}{2011/02/01 v1.2g} |
| 2178 |
% \item Updated to version 2010/04/24 v0.19 of the \xpackage{holtxdoc} package. |
| 2179 |
% \item New version of \xpackage{pagesLTS} package, 2011/02/01, v1.1m. |
| 2180 |
% \item Updated to version 2010/12/16 v6.81z of the \xpackage{hyperref} package. |
| 2181 |
% \item Minor details. |
| 2182 |
% \end{Version} |
| 2183 |
% \begin{Version}{2011/07/03 v1.2h} |
| 2184 |
% \item The \xpackage{holtxdoc} package was fixed, therefore the warning |
| 2185 |
% in \xfile{drv} could be removed.~-- Adapted the style of this documentation |
| 2186 |
% to new \textsc{Oberdiek} \xfile{dtx} style. |
| 2187 |
% \item New versions of \xpackage{pagesLTS}, \xpackage{ulem}, \xpackage{hyperref}, |
| 2188 |
% \xpackage{papermas} packages. |
| 2189 |
% \item Corrected references in the README and manual. |
| 2190 |
% \end{Version} |
| 2191 |
% \begin{Version}{2011/08/08 v1.2i} |
| 2192 |
% \item The \xpackage{pagesLTS} package has been renamed to \xpackage{pageslts}: |
| 2193 |
% 2011/08/08, v1.2a. |
| 2194 |
% \item Some details. |
| 2195 |
% \end{Version} |
| 2196 |
% \begin{Version}{2011/08/31 v1.2j} |
| 2197 |
% \item Updated to \TeX{} Live 2011 (for compiling the documentation and example). |
| 2198 |
% \item New version of \xpackage{papermas} package, 2011/08/22, v1.0h. |
| 2199 |
% \item Adapted for the use together with packages, which sometimes prevent writing |
| 2200 |
% to the \xfile{aux} file. (Bug reported by \textsc{Mikhail Titov}.) |
| 2201 |
% \end{Version} |
| 2202 |
% \begin{Version}{2011/09/01 v1.2k} |
| 2203 |
% \item Fixed |\thepage{}| to \mbox{|\thepage{}|\textvisiblespace,} |
| 2204 |
% where there should be a space. |
| 2205 |
% \item New version of the \xpackage{hyperref} package, 2011/08/19, v6.82h, |
| 2206 |
% but still problem with links to pages with |
| 2207 |
% page-\textquotedblleft number\textquotedblright{} in \texttt{fnsymbol} |
| 2208 |
% pagenumbering scheme. [Fixed since v6.83m as of 2012/11/06.] |
| 2209 |
% \item Documentation update about \textquotedblleft No write access to the |
| 2210 |
% \xfile{aux} file\textquotedblright . |
| 2211 |
% \end{Version} |
| 2212 |
% \begin{Version}{2013/01/28 v1.2l} |
| 2213 |
% \item Updated to \TeX{} Live 2012 (for compiling the documentation and example). |
| 2214 |
% \item New versions of the packages |
| 2215 |
% \xpackage{endfloat}, \xpackage{holtxdoc}, \xpackage{hypdoc}, |
| 2216 |
% \xpackage{hyperref}, \xpackage{pageslts}, \xpackage{regstats}, |
| 2217 |
% \xpackage{ulem}, and \xpackage{zref} have become available. |
| 2218 |
% \item The \xpackage{nameref} package redefines |\label| to have five arguments |
| 2219 |
% instead of two, therefore |\newlabel{LastPage}{{}{\thepage}{}{}{}}| instead of |
| 2220 |
% |\newlabel{LastPage}{{}{\thepage}}| must be used. |
| 2221 |
% (Bug reported at \url{https://tex.stackexchange.com/q/95541}, |
| 2222 |
% thanks to \textsc{Micha\l{} Herman}!) Fixed.\newline |
| 2223 |
% [Since \LaTeX{} release 2023-06-01 five arguments are standard.] |
| 2224 |
% \end{Version} |
| 2225 |
% \begin{Version}{2015/03/29 v1.2m} |
| 2226 |
% \item Updated to \TeX{} Live 2014 (for compiling the documentation and example). |
| 2227 |
% \item Updates to really a lot of details in the documentation (manual \& README). |
| 2228 |
% \end{Version} |
| 2229 |
% \begin{Version}{2021/09/03 v1.2n} |
| 2230 |
% \item Updates to the documentation (manual \& README), to the example, and |
| 2231 |
% several small changes in code. |
| 2232 |
% \end{Version} |
| 2233 |
% \begin{Version}{2023-03-07 v2.0a} |
| 2234 |
% \item Removed use of \pkg{ulem}. |
| 2235 |
% \item Removed |\unit|. |
| 2236 |
% \item \pkg{lastpage} should now determine automatically, whether to load |
| 2237 |
% its \TeX~2.09 version, classic \LaTeX2e-version, or modern version |
| 2238 |
% with \eTeX, hook{-}man\-age\-ment etc. |
| 2239 |
% \item Converted to UTF-8. |
| 2240 |
% \item Updated to [then] current \LaTeX{} format 2022-11-01. |
| 2241 |
% \item Extensive updates to the documentation (manual \& README) and to the example. |
| 2242 |
% \end{Version} |
| 2243 |
% \begin{Version}{2023-04-12 v2.0b} |
| 2244 |
% \item Bug fix: What should have been |}}{}| was |}{}}|. |
| 2245 |
% Thanks to \textsc{Matteo Gamboz} for the bug report! |
| 2246 |
% \end{Version} |
| 2247 |
% \begin{Version}{2023-07-24 v2.0c} |
| 2248 |
% \item Since \LaTeX{} release 2023-06-01 labels have always five arguments. |
| 2249 |
% \item Removed the incompatibility warning regarding \pkg{endfloat} |
| 2250 |
% before 1994-06-01~(!) from \pkg{lastpagemodern.sty}. |
| 2251 |
% \item Replaced |\immediate\write| by a form of (pseudo-code!) |\immediate\protected@write|. |
| 2252 |
% (Thanks to \textsc{Ulrike Fischer} for the error report and solution!) |
| 2253 |
% \item Update of the |\lastpage@putl@bel| code to \pkg{hyperref} 2023-07-08, v7.01b, |
| 2254 |
% which now allows fnsymbol as page numbering scheme. |
| 2255 |
% \end{Version} |
| 2256 |
% \begin{Version}{2023-10-06 v2.0d} |
| 2257 |
% \item For plain arabic page numbers only, \pkg{lastpage} again writes the page number |
| 2258 |
% in a plain format in the label in the \xfile{aux} file, so that it can be extracted |
| 2259 |
% to perform calculations with it. |
| 2260 |
% \end{Version} |
| 2261 |
% \begin{Version}{2023-10-14 v2.0e} |
| 2262 |
% \item Replaced a |\PackageError| by |\PackageWarningNoLine| as suggested by \textsc{Ulrike Fischer}. |
| 2263 |
% \end{Version} |
| 2264 |
% \begin{Version}{2024-04-27 v2.1a} |
| 2265 |
% \item Utilizes the new |\@currentHpage| provided by the \LaTeX -kernel. |
| 2266 |
% \item The issue with |\thepage| (former |\lastpage@nonnumeric| command) has has been fixed |
| 2267 |
% at 2023-11-07, \url{https://github.com/latex3/hyperref/issues/303}. |
| 2268 |
% \item |\lastpage@IfNumericTF| is no longer needed, but has not been removed |
| 2269 |
% so as not to break older documents that use it in a different context. |
| 2270 |
% \end{Version} |
| 2271 |
% \begin{Version}{2024-07-03 v2.1b} |
| 2272 |
% \item The \xclass{beamer} class loads \xpackage{hyperref} partially, |
| 2273 |
% so that \xpackage{hyperref} is incorrectly detected as having been loaded. |
| 2274 |
% The defining operation for |\lastpage@Hy| has been changed to catch this |
| 2275 |
% and other different cases. |
| 2276 |
% \end{Version} |
| 2277 |
% \begin{Version}{2024-07-07 v2.1c} |
| 2278 |
% \item With help from \textsc{David Carlisle} |\lastpage@rmpage| no longer assumes |
| 2279 |
% |\@currentHpage| to begin with \mbox{\textquotedblleft |page.|\textquotedblright .} |
| 2280 |
% \end{Version} |
| 2281 |
% \begin{Version}{2024-11-24 v2.1d} |
| 2282 |
% \item The \xpackage{pageslts} package has been repaired, thus here the warnings have been removed. |
| 2283 |
% \item Several small changes in documentation and |lastpagemodern.sty| because of the updates |
| 2284 |
% of \LaTeX-format (to~2024-06-01), \xpackage{hyperref} package (to~2024-10-30, v7.01k), |
| 2285 |
% and \xpackage{pageslts} package (to~2024-11-20, v2.0a). |
| 2286 |
% \item Added a warning message about missing\newline |
| 2287 |
% |\ProvideTextCommand{...}{PD1}{...}|\newline |
| 2288 |
% (cf.~\autoref{subsec:fnsymbol}: \nameref{subsec:fnsymbol}, page~\pageref{subsec:fnsymbol}). |
| 2289 |
% \item Documentation section about alternatives rewritten. |
| 2290 |
% \end{Version} |
| 2291 |
% \begin{Version}{2025-01-27 v2.1e} |
| 2292 |
% \item Reorganized beginning of |\lastpage@makeHy|. |
| 2293 |
% \item Documentation update. |
| 2294 |
% \end{Version} |
| 2295 |
% \begin{Version}{2025-06-05 v2.1f} |
| 2296 |
% \item Since \LaTeX-format 2025-06-01 after shipping the last page all further |\write|s |
| 2297 |
% are made |\immediate|, making |\addtocounter{page}{-1}| and then |
| 2298 |
% |\addtocounter{page}{+1}| obsolete. |
| 2299 |
% \end{Version} |
| 2300 |
% \begin{Version}{2025-06-06 v2.1g} |
| 2301 |
% \item With the new kernel, special handling for packages \xpackage{french} and |
| 2302 |
% \xpackage{frenchle} must not be done. |
| 2303 |
% \end{Version} |
| 2304 |
% \begin{Version}{2025-08-14 v2.1h} |
| 2305 |
% \item Hook label for \xfile{lastpagemodern.sty} set to |lastpage|. |
| 2306 |
% \item Compatibility fix for package \xpackage{titlesec}. (Reported by \textsc{Ioannis Tsoulos}.) |
| 2307 |
% \end{Version} |
| 2308 |
% \end{History} |
| 2309 |
% \bigskip |
| 2310 |
% |
| 2311 |
% When you find a mistake or have a suggestion for an improvement of this package, |
| 2312 |
% please send an e-mail to the maintainer, thanks! (Please see BUG REPORTS in the README.) |
| 2313 |
% \pagebreak |
| 2314 |
% \PrintIndex |
| 2315 |
% \Finale |
| 2316 |
\endinput |