Debian Codegraph @

texmf-dist/doc/latex/pagerange/pagerange-guide.tex

raw
1 \documentclass[10pt,a4paper]{article}
2 \InputIfFileExists{pagerange-guide.cfg}{}{%
3 \errmessage{No file pagerange-guide.cfg}}
4 \pagestyle{fancyplain}
5
6 \begin{document}
7 \label{page:first}
8
9 \MakeShortVerb{\+}
10 \title{\textbf{The {\tt pagerange} Package}\\[1ex] Version 0.5}
11 \author{Ahmed Musa\\[.5ex]University of Central Lancashire\\
12 Preston, United Kingdom\\[1ex]\email{[email protected]}
13 }
14 \maketitle
15
16 \section{Introduction}
17 This package emerged from my desire to resolve page ranges in the +draftmark+ package, but it may be useful to other \texorlatex enthusiasts and users.
18
19 \section{Usage}
20
21 When a given page range +xx-yy+ (simple/plain characters) or +\pages+ (control sequence, \eg, +\def\pages{xx-yy}+) is submitted to the macro +\pagerange+ (\eg, +\pagerange{xx-yy}+ or +\pagerange\pages+), this package splits the range as +xx+ in the macro +\pagestart+ and +yy+ in +\pageend+. The counter equivalents of these are +\prg@cnta+ and +\prg@cntb+. The control sequence containing the page range (\eg, +\pages+) is fully expanded before the page range is split.
22
23 If you specify a range consisting of a hyphen (or any tie) but with one or two empty page numbers, the following will happen:
24 \begin{compactenum}[a)]
25 \item A range of the form ``+-34+'' is taken to mean pages +defaultfirstpage+ to 34. The default value of +defaultfirstpage+ is 1; it can be changed via +\pagerangeoptions+.
26 \item A range of the form ``+12-+'' is taken to mean page~12 to +defaultlastpage+, where the default value of +defaultlastpage+ is the document's last page.
27 \item A range of the form ``+-+'' (\ie, only hyphen and no pages) is taken to mean from +defaultfirstpage+ to +defaultlastpage+.
28 \item A blank page range (\ie, containing no argument and no hyphen/tie) is taken to mean the range +defaultfirstpage+ to +defaultlastpage+, or it may prompt a fatal error, depending on whether the boolean +acceptempty+ is set true or false (respectively).
29 \end{compactenum}
30
31 Page ranges containing more than one hyphen/tie cause fatal error.
32
33 If the upper limit of the page range is smaller than the lower limit, a fatal error is flagged.
34
35 The tie between the pages in the page range can be any single non-active character; its default is the hyphen character ``+-+''. It can be changed in the call to the package (\eg, +\usepackage[tie=*]{pagerange}+) or at any moment through +\pagerangeoptions{tie=*}+.
36
37 Because of the need for the last page of the document, at least~2 runs/passes are needed to obtain the correct last page.
38
39 This package has been tested with the +hyperref+ package, which redefines the label used by the +lastpage+ package.
40
41 \subsection{Using an active character as the ``tie''}
42
43 Active characters can't, unfortunately, be used as ties. The package easily terminates with a fatal error when an active character is passed as +tie+. It wouldn't be safe to change the catcode of an active character submitted as +tie+ through +\pagerangeoptions+, since at the time the macro +\pagerangeoptions+ is invoked, the page may already be in the process of being built.
44
45 To use an active character (say \string~) as a tie, it is necessary to first locally change its catcode, \eg, as follows:
46
47 \begin{pverbatim}
48 \begingroup
49 \catcode`\~=11
50 \pagerangeoptions{tie=~}
51 \pagerange{1~4}
52 \endgroup
53 \end{pverbatim}
54
55 which gives \pgresult{Pages 1 to 4}.
56
57 \section{Package options}\label{sec:package-options}
58 The package options are as follows:
59
60 \begin{tabularx}{\linewidth}{p{3cm}p{2.0cm}X}
61 \hline
62 \bf Option & \bf Default & \bf Meaning\\\hline
63 +tie+ & hyphen (+-+) & The tie that show the breakpoint for the page range.\\\hline
64 +acceptempty+ & +false+ & The boolean option that specifies if empty page ranges (\ie, no page numbers and no tie) submitted to the package should be accepted. If true, the page range is assumed to be from page~1 to the last page.\\\hline
65 +defaultfirstpage+ & +1+ & The default start page number, used as the starting page when no starting page number is specified by the user.\\\hline
66 +defaultlastpage+ & document's last page & The default last page number, used as the last page when no last page number is specified by the user.\\\hline
67 \end{tabularx}
68
69 \section{Examples}
70 \pgexample{}
71 The following
72
73 \begin{pverbatim}
74 \pagerange{123-456}
75 Pages~\pagestart\space to\space\pageend
76 \end{pverbatim}
77
78 \pagerange{123-456}
79 produces \pgresult{Pages~\pagestart\space to\space\pageend}.
80
81 \pgexample{}
82
83 The following
84
85 \begin{pverbatim}
86 \pagerange{12345-67890}
87 \end{pverbatim}
88
89 \pagerange{12345-67890}
90 produces \pgresult{Pages~\pagestart\space to\space\pageend}.
91
92 \pgexample{}
93 The following
94
95 \begin{pverbatim}
96 \pagerange{123-4567}
97 \end{pverbatim}
98
99 \pagerange{123-4567}
100 produces \pgresult{Pages~\pagestart\space to\space\pageend}.
101
102 \pgexample{}
103 The following
104
105 \begin{pverbatim}
106 \pagerange{600-601}
107 \end{pverbatim}
108
109 \pagerange{600-601}
110 produces \pgresult{Pages~\pagestart\space to\space\pageend}.
111
112 \pgexample{}
113 The following
114
115 \begin{pverbatim}
116 \pagerange{-34}
117 \end{pverbatim}
118
119 \pagerange{-34}
120 produces \pgresult{Pages~\pagestart\space to\space\pageend}.
121
122 \pgexample{No page numbers given}
123 The following
124
125 \begin{pverbatim}
126 \pagerange{-}
127 \end{pverbatim}
128
129 \pagerange{-}
130 \par\medskip\noindent
131 produces \pgresult{Pages~\pagestart\space to\space\pageend}.
132
133 \pgexample{}
134 The following logs a warning message or issues fatal error, depending on the status of +acceptempty+ option:
135
136 \begin{pverbatim}
137 \pagerange{}
138 \end{pverbatim}
139
140 %\pagerangeoptions{acceptempty}
141 %\pagerange{}
142 %Page~\pagestart\space to\space\pageend
143
144 \pgexample{}
145 The following fails because of multiple hyphens (ties):
146
147 \begin{pverbatim}
148 \pagerange{123-456-789}
149 \end{pverbatim}
150
151 %\pagerange{123-456-789}
152
153 \pgexample{}
154 The following fails because +\pagestart+ is larger than +\pageend+:
155
156 \begin{pverbatim}
157 \pagerange{34-12}
158 \end{pverbatim}
159
160 %\pagerange{34-12}
161
162 \pgexample{}
163 The following fails because +tie+ can't be active character:
164
165 \begin{pverbatim}
166 \pagerangeoptions{tie=~}
167 \end{pverbatim}
168
169 %\pagerangeoptions{tie=~}
170
171 \pgexample{}
172 For the same reason (\ie, the use of active character as +tie+), the following fails---although nested commands are permitted:
173
174 \begin{pverbatim}
175 \def\Xone{~}
176 \def\Xtwo{\Xone}
177 \pagerangeoptions{tie=\Xtwo}
178 \end{pverbatim}
179
180 %\def\Xone{~}
181 %\def\Xtwo{\Xone}
182 %\pagerangeoptions{tie=\Xtwo}
183
184 \pgexample{}
185 The following works because the +\pagerange+ is fully expanded before splitting:
186
187 \begin{pverbatim}
188 \def\Xone{-}
189 \def\Xtwo{\Xone}
190 \pagerange{22\Xtwo 23}
191 \end{pverbatim}
192
193 \def\Xone{-}
194 \def\Xtwo{\Xone}
195 \pagerange{22\Xtwo 23}
196 This produces \pgresult{Pages~\pagestart\space to\space\pageend}.
197
198 \pgexample{}
199 The following also works because the +\pagerange+ is fully expanded before splitting:
200
201 \begin{pverbatim}
202 \def\X{-}
203 \def\Y{2222}
204 \def\Z{3333}
205 \pagerange{\Y\X\Z}
206 \end{pverbatim}
207
208 \def\X{-}
209 \def\Y{2222}
210 \def\Z{3333}
211 \pagerange{\Y\X\Z}
212 This produces \pgresult{Pages~\pagestart\space to\space\pageend}.
213
214 \pgexample{}
215 The following also works because the +\pagerange+ and +tie+ are fully expanded before splitting page range:
216
217 \begin{pverbatim}
218 \def\X{-}
219 \pagerangeoptions{tie=\X}
220 \pagerange{123\X 234}
221 \end{pverbatim}
222
223 \def\X{-}
224 \pagerangeoptions{tie=\X}
225 \pagerange{123\X 234}
226 This produces \pgresult{Pages~\pagestart\space to\space\pageend}.
227
228 \pgexample{}
229 The following works because infinite nesting of +tie+ and +\pagerange+ are permitted:
230
231 \begin{pverbatim}
232 \def\Xone{-}
233 \def\Xtwo{\Xone}
234 \pagerangeoptions{tie=\Xtwo}
235 \pagerange{444\Xtwo 555}
236 \end{pverbatim}
237
238 \def\Xone{-}
239 \def\Xtwo{\Xone}
240 \pagerangeoptions{tie=\Xtwo}
241 \pagerange{444\Xtwo 555}
242 This yields \pgresult{Pages~\pagestart\space to\space\pageend}.
243
244 \pgexample{}
245 The following gives incorrect (in fact, weird) result because the prevailing +tie+ is not a star:
246
247 \begin{pverbatim}
248 \pagerange{33*44}
249 \end{pverbatim}
250
251 %\pagerange{33*44}
252 %It produces \pgresult{Pages~\pagestart\space to\space\pageend}.
253
254 \pgexample{}
255 The +tie+ can be changed to a star (or any non-active character) as follows:
256
257 \begin{pverbatim}
258 \pagerangeoptions{tie=*}
259 \pagerange{2233*3344}
260 \end{pverbatim}
261
262 \pagerangeoptions{tie=*}
263 \pagerange{2233*3344}
264 This correctly produces \pgresult{Pages~\pagestart\space to\space\pageend}.
265
266 \pgexample{}
267 In the following the +tie+ is changed to letter ``T'':
268
269 \begin{pverbatim}
270 \pagerangeoptions{tie=T}
271 \pagerange{1234T1235}
272 \end{pverbatim}
273
274 \pagerangeoptions{tie=T}
275 \pagerange{1234T1235}
276 It produces \pgresult{Pages~\pagestart\space to\space\pageend}.
277
278 \pgexample{}
279 The following
280
281 \begin{pverbatim}
282 \pagerangeoptions{tie=X}
283 \pagerange{2034X2135}
284 \end{pverbatim}
285
286 \pagerangeoptions{tie=X}
287 \pagerange{2034X2135}
288 correctly yields \pgresult{Pages~\pagestart\space to\space\pageend}.
289
290 \section{Using page labels}
291
292 From version 0.3 of the package, it has been possible to obtain page ranges from \LaTeX{} references, \eg, as in
293
294 \begin{pverbatim}
295 \label{page:label}
296 \pagerangeoptions{tie=-}
297 \let\getpage\getpagenumber
298 \pagerange{\getpage{page:first}-\getpage{page:last}},
299 \end{pverbatim}
300
301 \label{page:last}
302 \pagerangeoptions{tie=-}
303 \pagerange{\getpagenumber{page:first}-\getpagenumber{page:last}}
304 which yields \pgresult{Pages~\pagestart\space to\space\pageend}.
305
306 The command +\getpagenumber+ is provided in the package and may, in general, be used to convert page labels into page numbers even in expansion contexts, where +\pageref+ will normally fail. If the page label or reference is undefined, the default start page number (+defaultfirstpage+) is used. The +defaultfirstpage+ is a package option (see Section~\ref{sec:package-options}).
307
308 \end{document}