summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pagerange/pagerange.sty
blob: c6be8784aec017d46d9df3d50fc5d497bbdac017 (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
231
232
233
234
235
236
237
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
% This is file 'pagerange.sty', version 0.5.                                %
%                                                                           %
% This work may be distributed and/or modified under the conditions         %
% of the LaTeX Project Public License, either version 1.3 of this           %
% license or any later version. The latest version of this license          %
% is in http://www.latex-project.org/lppl.txt and version 1.3 or later      %
% is part of all distributions of LaTeX version 2005/12/01 or later.        %
%                                                                           %
% The LPPL maintenance status of this software is 'author-maintained'.      %
%                                                                           %
% This software is provided 'as it is', without warranty of any kind,       %
% either expressed or implied, including, but not limited to, the           %
% implied warranties of merchantability and fitness for a particular        %
% purpose.                                                                  %
%                                                                           %
% Copyright (c) 2010 Ahmed Musa (a.musa@rocketmail.com).                    %
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
\begingroup
\catcode064 11\relax% @
\catcode123 01\relax% {
\catcode125 02\relax% }
\def\prg@tempa{\endgroup
  \edef\prg@restorecodes{%
    \catcode035 \the\catcode035\relax% #
    \catcode064 \the\catcode064\relax% @
    \catcode123 \the\catcode123\relax% {
    \catcode125 \the\catcode125\relax% }
    \catcode061 \the\catcode061\relax% =
    \catcode038 \the\catcode038\relax% &
  }%
}
\prg@tempa
\catcode061 12\relax% =
\catcode035 06\relax% #
\catcode064 11\relax% @
\catcode123 01\relax% {
\catcode125 02\relax% }
\catcode038 03\relax% &
\AtEndOfPackage{\prg@restorecodes}
\ProvidesPackage{pagerange}%
  [2010/02/04 v0.5 Split page ranges intelligently (Ahmed Musa)]
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\@ifpackageloaded{lastpage}{}{\RequirePackage{lastpage}[1994/06/25]}
\@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}[2008/08/13]}
\ifcase0%
  \ifx\eTeXversion\@undefined 1\else\ifnum\eTeXversion<\tw@ 1\fi\fi
\else
  \@latex@error{eTeX not loaded or old version.\MessageBreak
    This package requires eTeX version 2 or later.}\@ehc
\fi
\newcommand*\prg@ifdefinable[1]{%
  \edef\reserved@a{\expandafter\@gobble\string#1}%
  \begingroup
  \ifdefined#1%
    \aftergroup\@notdefinable
  \else
    \edef\reserved@b{\expandafter\@carcube\reserved@a xxx\@nil}%
    \ifx\reserved@b\@qend
      \aftergroup\@notdefinable
    \else
      \ifx\reserved@a\@qrelax
        \aftergroup\@notdefinable
      \else
        \aftergroup\@firstofone
      \fi
    \fi
  \fi
  \endgroup
}
\prg@ifdefinable\prg@protect@relax\relax
\prg@ifdefinable\prg@star@or@long\relax
\prg@ifdefinable\prg@pdef\relax
\prg@ifdefinable\prg@@def\relax
\def\prg@star@or@long#1{%
  \@ifstar{\let\prg@protect@relax\protected#1}%
    {\def\prg@protect@relax{\protected\long}#1}%
}
\let\prg@protect@relax\protected
\protected\def\prg@pdef{\prg@star@or@long\prg@@def}
\def\prg@@def#1{\prg@ifdefinable#1{\prg@protect@relax\def#1}}
\prg@pdef\prg@warn#1{\PackageWarningNoLine{pagerange}{#1}}
\prg@pdef\prg@err#1{\PackageError{pagerange}{#1}\@ehc}
\prg@ifdefinable\prg@tempcnta{\newcount\prg@tempcnta}
\prg@ifdefinable\prg@tempcntb{\newcount\prg@tempcntb}
\prg@ifdefinable\prg@tempcntc{\newcount\prg@tempcntc}
\def\prg@c@r#1#2{%
  \unless\ifx#2\null
    \prg@err{Inadmissible multiple arguments '\string#1\string#2'
      \MessageBreak for '\string\prg@ifdef' test}%
  \fi
}
\prg@ifdefinable\prg@ifdef\relax
\def\prg@ifdef#1{%
  \prg@c@r#1\null
  \csname @\ifdefined#1\expandafter first\else
    \expandafter second\fi oftwo\endcsname
}
\prg@ifdefinable\prg@ifundef\relax
\def\prg@ifundef#1{%
  \prg@ifdef{#1}{\csname @\ifx#1\relax\expandafter first\else
    \expandafter second\fi oftwo\endcsname}{\@firstoftwo}%
}
\def\prg@ifcsundef#1{\expandafter\prg@ifundef\csname#1\endcsname}
\prg@pdef*\prg@check@ifdef#1{%
  \prg@ifcsundef{#1}{}{%
    \prg@err{\expandafter\noexpand\csname#1\endcsname already defined}%
  }%
  \prg@check@ifdef
}
\prg@check@ifdef{pagerange}{pagestart}{pageend}{getpagenumber}%
  {pagerangeoptions}\iffalse\fi\fi\endcsname{}{}
\prg@pdef\prg@ifblank#1{\prg@ifbl@nk#1&&\@secondoftwo\@firstoftwo:}
\long\def\prg@ifbl@nk#1#2&#3#4#5:{#4}
\prg@pdef\prg@xifblank#1{\begingroup
  \protected@edef\prg@tempa{\endgroup\noexpand\prg@ifblank{#1}}%
  \prg@tempa
}
\prg@pdef\prg@ifmacro#1{%
  \begingroup
  \edef\prg@tempa{\endgroup
    \def\noexpand\getparameter####1\detokenize{macro}:####2&{%
      \noexpand\prg@ifblank{####2}{\noexpand\@secondoftwo}%
        {\noexpand\@firstoftwo}%
    }%
    \noexpand\expandafter\noexpand\getparameter%
    \noexpand\meaning\noexpand#1\detokenize{macro}:&%
  }\prg@tempa
}
\def\prg@ismacro@err#1{%
  \prg@err{%
    Illegal tie '#1'.\MessageBreak
    Note that the 'tie' has been expanded once\MessageBreak
    and may be different from what you submitted.\MessageBreak
    Perhaps you've used an active character as 'tie'
  }%
}
\define@cmdkey[KV]{pagerange}[prg@]{tie}[-]{%
  \edef\@tempa{\expandafter\noexpand\prg@tie}%
  \edef\prg@tie{\prg@tie}%
  \let\@@protect\protect\let\protect\@empty
  \expandafter\prg@ifmacro\expandafter{\prg@tie}{%
    \restore@protect\prg@ismacro@err\@tempa
  }{}%
  \restore@protect
}
\define@boolkey[KV]{pagerange}[prg@]{acceptempty}[true]{}
\define@cmdkey[KV]{pagerange}[prg@]{defaultfirstpage}[1]{}
\define@cmdkey[KV]{pagerange}[prg@]{defaultlastpage}%
  [\getpagenumber{LastPage}]{}
\DeclareOptionX*{\prg@warn{Unknown option '\CurrentOption' ignored}}
\ExecuteOptionsX<pagerange>{tie,defaultfirstpage,defaultlastpage}
\ProcessOptionsX*<pagerange>\relax
\long\def\pagerangeoptions#1{\setkeys[KV]{pagerange}{#1}}
\prg@pdef\prg@forall#1#2\do#3{%
  #3{#1}%
  \expandafter\ifx\expandafter\@empty\detokenize{#2}\@empty%
    \relax
  \else
    \prg@forall#2\do{#3}%
  \fi
}
\let\pagestart\@empty
\let\pageend\@empty
\prg@tempcntc=\z@
\prg@pdef*\prg@split@pagerange#1{%
  \def\reserved@a{#1}%
  \ifx\reserved@a\prg@tie
    \advance\prg@tempcntc\@ne
  \fi
  \ifnum\prg@tempcntc=\z@
    \g@addto@macro\pagestart{#1}%
  \else\ifnum\prg@tempcntc=\@ne
    \ifx\reserved@a\prg@tie\else
      \g@addto@macro\pageend{#1}%
    \fi
  \else\ifnum\prg@tempcntc>\@ne
    \prg@err{Multiple ties in page range.\MessageBreak
      Please use only one tie}%
  \fi\fi\fi
}
\prg@tempcnta=\z@\prg@tempcntb=\z@
\def\pagerange#1{%
  \let\pagestart\@empty
  \let\pageend\@empty
  \prg@tempcntc=\z@
  \prg@xifblank{#1}{%
    \ifprg@acceptempty
      \prg@warn{Blank page range supplied:\MessageBreak
        I've therefore set the range as 1-1 and continued}
      \let\pagestart\prg@defaultfirstpage
      \let\pageend\prg@defaultlastpage
    \else
      \prg@err{Blank page range.\MessageBreak
        If you really mean blank pagerange,\MessageBreak
        then also use 'acceptempty' boolean option
      }%
    \fi
  }{%
    \begingroup\edef\prg@tempa{\endgroup%
      \prg@forall#1\noexpand\do{\prg@split@pagerange}}%
    \prg@tempa
  }%
  \ifx\@empty\pagestart
    \ifnum\prg@tempcntc=\@ne
      \let\pagestart\prg@defaultfirstpage
    \fi
  \fi
  \prg@tempcnta=\number\pagestart\relax
  \ifx\@empty\pageend
    \prg@tempcntb=\@M
    \ifnum\prg@tempcntc=\@ne
      \let\pageend\prg@defaultlastpage
    \fi
  \else
    \prg@tempcntb=\number\pageend\relax
  \fi
  \ifnum\prg@tempcnta>\prg@tempcntb
    \prg@err{Inconsistent page range: Page \pageend\space > \pagestart}%
  \fi
}
\def\prg@carr#1#2#3\@nil{%
  \expandafter\ifx\expandafter\relax\detokenize{#3}\relax
    \prg@err{Problem with page reference}
  \fi
  #2%
}
\def\getpagenumber#1{%
  \prg@ifcsundef{r@#1}{\prg@defaultfirstpage}{%
    \expandafter\expandafter\expandafter\prg@carr
    \csname r@#1\endcsname\prg@defaultfirstpage\@nil
  }%
}

\endinput

%%% End of file pagerange.sty %%%