%% %% This is file `lastpage-example.tex', %% generated with the docstrip utility. %% %% The original source files were: %% %% lastpage.dtx (with options: `example') %% %% This is a generated file. %% %% Project: lastpage %% Version: 2024-04-27 v2.1a %% Info: Refers to last page's name %% %% Copyright (C) 2010 - 2024 by %% H.-Martin Muench %% Portions of code copyrighted by other people as marked. %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either %% version 1.3c of this license or (at your option) any later %% version. This version of this license is in %% https://www.latex-project.org/lppl/lppl-1-3c.txt %% and the latest version of this license is in %% https://www.latex-project.org/lppl.txt %% and version 1.3c or later is part of all distributions of %% LaTeX version 2005-12-01 or later. %% %% This work has the LPPL maintenance status "maintained". %% %% The Current Maintainer of this work is H.-Martin Muench. %% %% This package was invented by Jeffrey P. Goldberg. %% I thought that a replacement was needed and therefore created the pageslts package, %% https://ctan.org/pkg/pageslts %% . Nevertheless, for compatibility with existing documents/packages as well as for %% the low amount of resources needed by the lastpage package (no new counter!), %% I updated this package. %% Thanks go to Jeffrey P. Goldberg for allowing me to do this. %% %% While this package allows for things like "Page slash thepage{} of slash pageref{LastPage}" %% to get "Page 7 of 9" or "Page VII of IX", %% the NUMBER of pages is nowadays available from the kernel %% (slash @abspage@last, slash thetotalpages, slash PreviousTotalPages), %% but with pages for example I to X and then 1 to 10, the number of pages would be "20", %% while the name of the last page is "10". Decide what you need/want! %% %% This work consists of the main source file lastpage.dtx, %% the README, and the derived files %% lastpage.sty, lastpage209.sty, lastpage2e.sty, %% lastpageclassic.sty, lastpagemodern.sty, %% lastpage.pdf, lastpage.ins, lastpage.drv, %% lastpage-example.tex, lastpage-example.pdf. %% %% In memoriam %% Claudia Simone Barth + 1996-01-30 %% Tommy Muench + 2014-01-02 %% Hans-Klaus Muench + 2014-08-24 %% \documentclass[british]{article}[2023/05/17]% v1.4n Standard LaTeX document class \makeatletter \@ifl@t@r\fmtversion{2022/11/01}{% \AddToHook{enddocument/afterlastpage}[lastpage]{% \message{^^JLaTeX Info: Executing hook `enddocument/afterlastpage'.}}% }{\AtEndDocument{\message{^^JLaTeX Info: Executing hook `AtEndDocument'.}}% } \usepackage[draft]{showkeys}[2023/07/08]% v3.19 Show cite and label keys (DPC, MH) %% Use final instead of draft to hide the keys. %% \usepackage[pdfpagelabels=true,hyperindex=false]{hyperref}[2024-01-20]% v7.01h %% Hypertext links for LaTeX \hypersetup{extension=pdf,% plainpages=false,% pdflang={en},% pdftitle={lastpage package example},% pdfauthor={H.-Martin Muench},% pdfsubject={Example for the lastpage package},% pdfkeywords={LaTeX, lastpage},% pdfview=Fit,% pdfstartview=Fit,% pdfpagelayout=SinglePage% } \@ifpackageloaded{hyperref}{}{\usepackage{url}[2013/09/16]}% v3.4 \usepackage{lastpage}[2024/04/27]% v2.1a \renewcommand{\@evenfoot}{% \normalsize\slshape \today\hfil \upshape % page \thepage{} of \pageref{LastPage}} \renewcommand{\@oddfoot}{\@evenfoot} \makeatother \listfiles \begin{document} \pagenumbering{Roman} \section*{Example for lastpage} \markboth{Example for lastpage}{Example for lastpage} This example demonstrates the use of package\newline \textsf{lastpage}, v2.1a as of 2024-04-27 (HMM; JPG).\newline The package takes no options.\newline For more details please see the documentation!\newline \noindent \label{keys} To hide the \pageref{keys}{\qquad } use option \texttt{final} instead of \texttt{draft} with the \textsf{showkeys} package (or remove the package call from the preamble of this document).\newline \textbf{Hyperlinks or not:} If the \textsf{hyperref} package is loaded, the references are also hyperlinked:\newline \smallskip Last page's name (LastPage): \pageref{LastPage}\newline \noindent If the \textsf{hyperref} package is loaded, but the hyperlinks of the references shall be suppressed, \verb|\pageref*{...}| can be used:\newline \smallskip Last page's name (LastPage): \pageref*{LastPage}\newline \textbf{Trademarks} appear throughout this example without any trademark symbol; they are the property of their respective trademark owner. There is no intention of infringement; the usage is to the benefit of the trademark owner.\newline \textbf{Tip}: Use \textit{logical page numbers} for the display of the pdf (in Adobe Acrobat Reader 2024.002.20687: Edit $>$ Preferences $>$ Page Display $>$ Page Content and Information: Use logical page numbers)!\newline If you are more ambitious in respect to your aims with this package, you might want to have a look at the \textsf{pageslts} package:\newline \url{https://ctan.org/pkg/pageslts}. \bigskip \noindent The page (\verb|\thepage|): \thepage \newline Last page's name (LastPage): \pageref{LastPage} \newpage \noindent The page (\verb|\thepage|): \thepage \newline Last page's name (LastPage): \pageref{LastPage} \bigskip \noindent There was the question: \begin{quote} \begin{verbatim} \documentclass{article} \usepackage{hyperref} \usepackage{lastpage} \begin{document} \ifnum\thepage=\pageref{LastPage} foo \else bar \fi \end{document} \end{verbatim} producing the error \textquotedblleft missing number, treated as zero\textquotedblright. \end{quote} \noindent \verb|\pageref| inserts a hyperlink, \verb|\pageref{LastPage}| is not expandable and the code breaks.\newline The code does not generally work even without hyperref. \begin{quote} \begin{verbatim} \documentclass{article} \usepackage{hyperref} \usepackage{lastpage} \pagenumbering{Roman} \begin{document} \addtocounter{page}{8} \edef\here{\thepage} \makeatletter \ifx\here\lastpage@lastpage\relax foo\else bar\fi \makeatother \end{document} \end{verbatim} \end{quote} \noindent does work, because \verb|\lastpage@lastpage| contains the name of the page, \mbox{example:} \begin{verbatim} Page \thepage{} is (not) page \makeatletter\lastpage@lastpage\makeatother. \end{verbatim} prints:\newline Page \thepage{} is (not) page \makeatletter\lastpage@lastpage\makeatother. \newline This can be broken for example by \verb|\pagenumbering{fnsymbol}| (because then \verb|\edef\here{\thepage}| does not work). \newpage \noindent The page (\verb|\thepage|): \thepage\newline Last page's name (LastPage): \pageref{LastPage} \bigskip With modern \LaTeX{} it is possible to say: \begin{quote} \begin{verbatim} \NeedsTeXFormat{LaTeX2e}[2023-11-01] \documentclass{article} \pagenumbering{fnsymbol} \begin{document} \addtocounter{page}{8}% \ExplSyntaxOn% \xdef\test{\numexpr\the\g_shipout_readonly_int +1\relax}% \ExplSyntaxOff% \ifnum\PreviousTotalPages=\test\relax% This is the last page.% \else% This is not the last page (or it is but \LaTeX{} needs another compilation run to detect this). \fi \end{document} \end{verbatim} \end{quote} \newpage \section*{The End} \noindent The page (\verb|\thepage|): \thepage \newline Last page's name (LastPage): \pageref{LastPage} \bigskip To see the content of the \texttt{enddocument/afterlastpage}-hook (for a recent \LaTeX-format!) use % without the \verb||, of course! \verb|\ShowHook{enddocument/afterlastpage}|. \end{document} \endinput %% %% End of file `lastpage-example.tex'.