| 1 |
%% |
| 2 |
%% This is file `lastpage-example.tex', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% lastpage.dtx (with options: `example') |
| 8 |
%% |
| 9 |
%% This is a generated file. |
| 10 |
%% |
| 11 |
%% Project: lastpage |
| 12 |
%% Version: 2025-08-14 v2.1h |
| 13 |
%% Info: Refers to last page's name |
| 14 |
%% |
| 15 |
%% Copyright (C) 2010 - 2025 by |
| 16 |
%% H.-Martin Muench <Martin dot Muench at Uni-Bonn dot de> |
| 17 |
%% Portions of code copyrighted by other people as marked. |
| 18 |
%% |
| 19 |
%% This work may be distributed and/or modified under the |
| 20 |
%% conditions of the LaTeX Project Public License, either |
| 21 |
%% version 1.3c of this license or (at your option) any later |
| 22 |
%% version. This version of this license is in |
| 23 |
%% https://www.latex-project.org/lppl/lppl-1-3c.txt |
| 24 |
%% and the latest version of this license is in |
| 25 |
%% https://www.latex-project.org/lppl.txt |
| 26 |
%% and version 1.3c or later is part of all distributions of |
| 27 |
%% LaTeX version 2005-12-01 or later. |
| 28 |
%% |
| 29 |
%% This work has the LPPL maintenance status "maintained". |
| 30 |
%% |
| 31 |
%% The Current Maintainer of this work is H.-Martin Muench. |
| 32 |
%% |
| 33 |
%% This package was invented by Jeffrey P. Goldberg. |
| 34 |
%% I thought that an enhancement was needed and therefore created the pageslts package, |
| 35 |
%% https://ctan.org/pkg/pageslts. Nevertheless, for compatibility with existing |
| 36 |
%% documents/packages as well as for the low amount of resources needed by the |
| 37 |
%% lastpage package (no new counter!), I updated this package. |
| 38 |
%% Thanks go to Jeffrey P. Goldberg for allowing me to do this. |
| 39 |
%% |
| 40 |
%% While this package allows for things like "Page slash thepage{} of slash pageref{LastPage}" |
| 41 |
%% to get "Page 7 of 9" or "Page VII of IX", |
| 42 |
%% the NUMBER of pages is nowadays available from the kernel |
| 43 |
%% (slash @abspage@last, slash thetotalpages, slash PreviousTotalPages), |
| 44 |
%% but with pages for example I to X and then 1 to 10, the number of pages would be "20", |
| 45 |
%% while the name of the last page is "10". Decide what you need/want! |
| 46 |
%% |
| 47 |
%% This work consists of the main source file lastpage.dtx, |
| 48 |
%% the README, and the derived files |
| 49 |
%% lastpage.sty, lastpage209.sty, lastpage2e.sty, |
| 50 |
%% lastpageclassic.sty, lastpagemodern.sty, |
| 51 |
%% lastpage.pdf, lastpage.ins, lastpage.drv, |
| 52 |
%% lastpage-example.tex, lastpage-example.pdf. |
| 53 |
%% |
| 54 |
%% In memoriam |
| 55 |
%% Claudia Simone Barth + 1996-01-30 |
| 56 |
%% Tommy Muench + 2014-01-02 |
| 57 |
%% Hans-Klaus Muench + 2014-08-24 |
| 58 |
%% |
| 59 |
\documentclass[british]{article}[2025/01/22]% v1.4n Standard LaTeX document class |
| 60 |
\makeatletter |
| 61 |
\usepackage[draft]{showkeys}[2024/05/23]% v3.21 Show cite and label keys (DPC, MH) |
| 62 |
%% Use final instead of draft to hide the keys. %% |
| 63 |
\usepackage[pdfpagelabels=true,hyperindex=false]{hyperref}[2025-07-12]% v7.01o |
| 64 |
\@ifpackageloaded{hyperref}{% Hypertext links for LaTeX |
| 65 |
\hypersetup{extension=pdf,% |
| 66 |
plainpages=false,% |
| 67 |
pdflang={en},% |
| 68 |
pdftitle={lastpage package example},% |
| 69 |
pdfauthor={H.-Martin Muench},% |
| 70 |
pdfsubject={Example for the lastpage package},% |
| 71 |
pdfkeywords={LaTeX, lastpage},% |
| 72 |
pdfview=Fit,% |
| 73 |
pdfstartview=Fit,% |
| 74 |
pdfpagelayout=SinglePage% |
| 75 |
}}{\usepackage{url}[2013/09/16]}% v3.4 Verb mode for urls, etc. |
| 76 |
\usepackage{lastpage}[2025/08/14]% v2.1h Refers to last page's name (HMM; JPG)] |
| 77 |
\renewcommand{\@evenfoot}{{% |
| 78 |
\normalsize\slshape \today\hfil \upshape % |
| 79 |
page \thepage{} of \pageref{LastPage}}} |
| 80 |
\renewcommand{\@oddfoot}{\@evenfoot} |
| 81 |
\makeatother |
| 82 |
\listfiles |
| 83 |
\begin{document} |
| 84 |
\pagenumbering{Roman} |
| 85 |
\section*{Example for lastpage} |
| 86 |
\markboth{Example for lastpage}{Example for lastpage} |
| 87 |
This example demonstrates the use of package\newline |
| 88 |
\textsf{lastpage}, v2.1h as of 2025-08-14 (HMM; JPG).\newline |
| 89 |
The package takes no options.\newline |
| 90 |
For more details please see the documentation!\newline |
| 91 |
|
| 92 |
\noindent \label{keys} To hide the \pageref{keys}{\qquad } use option |
| 93 |
\texttt{final} instead of \texttt{draft} with the \textsf{showkeys} |
| 94 |
package (or remove the package call from the preamble of |
| 95 |
this document).\newline |
| 96 |
|
| 97 |
\textbf{Hyperlinks or not:} If the \textsf{hyperref} package is loaded, |
| 98 |
the references are also hyperlinked:\newline |
| 99 |
\smallskip |
| 100 |
Last page's name (LastPage): \pageref{LastPage}\newline |
| 101 |
\noindent If the \textsf{hyperref} package is loaded, but the hyperlinks |
| 102 |
of the references shall be suppressed, \verb|\pageref*{...}| |
| 103 |
can be used:\newline |
| 104 |
\smallskip |
| 105 |
Last page's name (LastPage): \pageref*{LastPage}\newline |
| 106 |
|
| 107 |
\textbf{Trademarks} appear throughout this example without any |
| 108 |
trademark symbol; they are the property of their respective |
| 109 |
trademark owner. There is no intention of infringement; the |
| 110 |
usage is to the benefit of the trademark owner.\newline |
| 111 |
|
| 112 |
\textbf{Tip}: Use \textit{logical page numbers} |
| 113 |
for the display of the pdf (in Adobe Acrobat Reader 2024.005.20392: |
| 114 |
Edit $>$ Preferences $>$ Page Display $>$ |
| 115 |
Page Content and Information: Use logical page numbers)!\newline |
| 116 |
|
| 117 |
If you are more ambitious in respect to your aims with this package, |
| 118 |
you might want to have a look at the \textsf{pageslts} package:\newline |
| 119 |
\url{https://ctan.org/pkg/pageslts}. |
| 120 |
\bigskip |
| 121 |
|
| 122 |
\noindent The page (\verb|\thepage|): \thepage \newline |
| 123 |
Last page's name (LastPage): \pageref{LastPage} |
| 124 |
\newpage |
| 125 |
|
| 126 |
\noindent The page (\verb|\thepage|): \thepage \newline |
| 127 |
Last page's name (LastPage): \pageref{LastPage} |
| 128 |
|
| 129 |
\bigskip |
| 130 |
|
| 131 |
\noindent There was the question: |
| 132 |
|
| 133 |
\begin{quote} |
| 134 |
\begin{verbatim} |
| 135 |
\documentclass{article} |
| 136 |
\usepackage{hyperref} |
| 137 |
\usepackage{lastpage} |
| 138 |
\begin{document} |
| 139 |
\ifnum\thepage=\pageref{LastPage} foo \else bar \fi |
| 140 |
\end{document} |
| 141 |
\end{verbatim} |
| 142 |
|
| 143 |
producing the error |
| 144 |
\textquotedblleft missing number, treated as zero\textquotedblright. |
| 145 |
\end{quote} |
| 146 |
|
| 147 |
\noindent \verb|\pageref| inserts a hyperlink, \verb|\pageref{LastPage}| |
| 148 |
is not expandable and the code breaks.\newline |
| 149 |
The code does not generally work even without hyperref. |
| 150 |
|
| 151 |
\begin{quote} |
| 152 |
\begin{verbatim} |
| 153 |
\documentclass{article} |
| 154 |
\usepackage{hyperref} |
| 155 |
\usepackage{lastpage} |
| 156 |
\pagenumbering{Roman} |
| 157 |
\begin{document} |
| 158 |
\addtocounter{page}{8} |
| 159 |
\edef\here{\thepage} |
| 160 |
\makeatletter |
| 161 |
\ifx\here\lastpage@lastpage\relax foo\else bar\fi |
| 162 |
\makeatother |
| 163 |
\end{document} |
| 164 |
\end{verbatim} |
| 165 |
\end{quote} |
| 166 |
|
| 167 |
\noindent does work (two compilations needed), because \verb|\lastpage@lastpage| |
| 168 |
contains the name of the page, \mbox{example:} |
| 169 |
\begin{verbatim} |
| 170 |
Page \thepage{} is (not) page |
| 171 |
\makeatletter\lastpage@lastpage\makeatother. |
| 172 |
\end{verbatim} |
| 173 |
prints:\newline |
| 174 |
Page \thepage{} is (not) page |
| 175 |
\makeatletter\lastpage@lastpage\makeatother. |
| 176 |
\newline |
| 177 |
This can be broken for example by \verb|\pagenumbering{fnsymbol}| |
| 178 |
(because then \verb|\edef\here{\thepage}| does not work). |
| 179 |
\newpage |
| 180 |
|
| 181 |
\noindent The page (\verb|\thepage|): \thepage\newline |
| 182 |
Last page's name (LastPage): \pageref{LastPage} |
| 183 |
\bigskip |
| 184 |
|
| 185 |
With modern \LaTeX{} it is possible to say: |
| 186 |
\begin{quote} |
| 187 |
\begin{verbatim} |
| 188 |
\NeedsTeXFormat{LaTeX2e}[2024-11-01] |
| 189 |
\documentclass{article} |
| 190 |
\pagenumbering{fnsymbol} |
| 191 |
\begin{document} |
| 192 |
\addtocounter{page}{8}% |
| 193 |
\ExplSyntaxOn% |
| 194 |
\xdef\test{\numexpr\the\g_shipout_readonly_int +1\relax}% |
| 195 |
\ExplSyntaxOff% |
| 196 |
\ifnum\PreviousTotalPages=\test\relax% |
| 197 |
This is the last page.% |
| 198 |
\else% |
| 199 |
This is not the last page |
| 200 |
(or it is but \LaTeX{} needs another compilation run |
| 201 |
to detect this). |
| 202 |
\fi |
| 203 |
\end{document} |
| 204 |
\end{verbatim} |
| 205 |
\end{quote} |
| 206 |
|
| 207 |
\newpage |
| 208 |
\section*{The End} |
| 209 |
\noindent The page (\verb|\thepage|): \thepage \newline |
| 210 |
Last page's name (LastPage): \pageref{LastPage} |
| 211 |
\bigskip |
| 212 |
|
| 213 |
To see the content of the \texttt{enddocument/afterlastpage}-hook |
| 214 |
(for a recent \LaTeX-format!) use % without the \verb||, of course! |
| 215 |
\verb|\ShowHook{enddocument/afterlastpage}|. |
| 216 |
\end{document} |
| 217 |
\endinput |
| 218 |
%% |
| 219 |
%% End of file `lastpage-example.tex'. |