summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/lastpage/lastpage-example.tex
blob: 14fc5deb30b93dcec6ae2c1de061dc9173a5fc86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
%%
%% 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: 2023-03-07 v2.0a
%% Info: Refers to last page's name
%% 
%% Copyright (C) 2010 - 2023 by
%%     H.-Martin Muench <Martin dot Muench at Uni-Bonn dot de>
%% 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 via slash @abspage@last from the kernel,
%% 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}[2022/07/02]% 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'.}}%
 }
\makeatother
\usepackage[draft]{showkeys}[2022/04/12]% v3.18 Show cite and label keys (DPC, MH)
%%      Use final instead of draft to hide the keys. %%
\usepackage{hyperref}[2023-02-07]% v7.00v Hypertext links for LaTeX
\hypersetup{extension=pdf,%
 plainpages=false,%
 pdfpagelabels=true,%
 hyperindex=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%
}
%% If hyperref is not used, the url package
%%   https://ctan.org/pkg/url
%% must be loaded for the \url used in this example:
%% \usepackage{url}
%% or just use \let\url\texttt for the one used url.
\usepackage{lastpage}[2023-03-07]% v2.0a
\makeatletter
\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.0a as of 2023-03-07 (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 2022.003.20322:
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, example:\newline
\verb|Page \thepage{} is page \makeatletter\lastpage@lastpage\makeatother.|%
\newline
prints:\newline
Page \thepage{} is page \makeatletter\lastpage@lastpage\makeatother.%
\newline
This can be broken for example by \verb|\pagenumbering{fnsymbol}|.
\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}[2022-11-01]
\documentclass{article}
\pagenumbering{fnsymbol}
\begin{document}
\addtocounter{page}{8}%
\makeatletter%
\ExplSyntaxOn%
\xdef\test{\numexpr\the\g_shipout_readonly_int +1\relax}%
\ExplSyntaxOff%
\ifnum \@abspage@last = \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
\makeatother
\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
\verb|\ShowHook{enddocument/afterlastpage}|.% without the \verb||, of course!
\end{document}
\endinput
%%
%% End of file `lastpage-example.tex'.