summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/oberdiek/pagesel.dtx
blob: 2f9636d734c94b943ab7d6eb2454ab9219895e6e (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
% \iffalse meta-comment
%
% pagesel.dtx
%
% This file is part of the package `pagesel' for use with LaTeX2e.
%
% Function: Selecting shipout output pages.
%
% Copyright (C) 1999, 2003 Heiko Oberdiek.
%
% This program may be distributed and/or modified under
% the conditions of the LaTeX Project Public License,
% either version 1.2 of this license or (at your option)
% any later version. The latest version of this license
% is in
%   http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions
% of LaTeX version 1999/12/01 or later.
%
% Please send error reports and suggestions for improvements to
%   Heiko Oberdiek <oberdiek@uni-freiburg.de>.
%
%<*dtx>
          \ProvidesFile{pagesel.dtx}
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{pagesel}
%<driver>\ProvidesFile{pagesel.drv}
% \fi
%         \ProvidesFile{pagesel.dtx}
  [2003/06/05 v1.2 Selecting shipout output pages (HO)]
%
% \GetFileInfo{pagesel.dtx}
%
% \CheckSum{216}
%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
% \iffalse
%<*driver>
\documentclass{ltxdoc}
\usepackage{holtxdoc}
\begin{document}
   \DocInput{pagesel.dtx}
\end{document}
%</driver>
% \fi
%
% \DoNotIndex{\maxdimen,\\,\END}
% \DoNotIndex{\ifodd,\ifx,\ifnum}
%
% \newenvironment{param}{^^A
%   \newcommand{\entry}[1]{\meta{\###1}:&}^^A
%   \begin{tabular}[t]{@{}l@{ }l@{}}^^A
% }{^^A
%   \end{tabular}^^A
% }
%
% \newcommand*{\Option}[1]{\textsf{#1}}
%
% \SetupTitle{page,select,shipout,LaTeX}
% \maketitle
%
% \begin{abstract}
%    With this package single pages or page areas can be selected
%    for output.
% \end{abstract}
%
% \tableofcontents
%
% \section{Usage}
%    The package \Package{pagesel} is a \LaTeXe\ package:
%    \begin{quote}
%      |\usepackage|\oarg{options}|{pagesel}|
%    \end{quote}
%    (For plain\TeX\ and \LaTeX\,2.09 the similar package
%    \URL{\Package{selectp}}^^A
%    {ftp://ftp.dante.de/tex-archive/macros/latex209/contrib/misc/selectp.sty}
%    from \Email[Donald Arsenau]{asnd@triumf.ca} can be used.)
%
%    Depending on the options the package works in two modes:
%    \begin{enumerate}
%    \item If no page selecting option is present, so the package
%          ignores the other options and finishes itself. So no
%          page will be suppressed by the package and auxiliary files
%          will be written.
%    \item With at least one page selecting option the specified
%          pages are selected and the other are suppressed.
%          The default for this mode is that auxiliary will not be
%          overwritten. (This can be changed by an option.)
%    \end{enumerate}
%
% \subsection{Page selecting}
%    The package \Package{pagesel} sets up a new counter that is
%    incremented by each \cmd{\shipout}.
%    In this way the package counts the output pages regardless the value
%    of the page counter. So each page can individually by addressed,
%    even if there are several pages with the same page number.
%
% \subsubsection{Options\texorpdfstring{ for selecting pages}{}}
%    \begin{description}
%    \item[\Option{odd}:] The output pages must have an odd number.
%         All even output pages are suppressed. If there are no
%         page areas specified so all odd pages are print. With
%         page areas only the odd pages in this areas are selected.
%    \item[\Option{even}:] The opposite of option \Option{odd}.
%    \item[Page area:] A page area consists of three elements:
%         the starting output page number, an ``area'' hyphen, and
%         the output page number of the last page in this area.
%         Each component is optional, so there are four kinds
%         to spezify a page area:
%         \begin{description}
%         \item[\meta{m}\Option{-}\meta{n}:] All pages between
%              \meta{m} and \meta{n} inclusive.
%         \item[\Option{-}\meta{n}:] All pages until \meta{n} inclusive.
%         \item[\meta{m}\Option{-}:] The page area starts with \meta{m}
%              and all pages to the end of document are selected.
%         \item[\Option{-}:] All pages (not very useful).
%         \item[\meta{s}:] The single page \meta{s}.
%         \end{description}
%    \end{description}
%
% \subsubsection{Examples}
%    \newcommand*{\exam}[1]{\texttt{\strut[#1]}}
%    \begin{tabular}{ll}
%      Options & Output pages\\
%      \hline
%      \exam{1, 4, 9}&  1, 4, and 9\\
%      \exam{7-10, 3}&  3, 7, 8, 9, and 10\\
%      \exam{odd, 3-6}& 3, and 5\\
%      \exam{-4, 3, even, 7-8}& 2, 4, and 8\\
%    \end{tabular}
%
% \subsection{Auxiliary files}
%    If a page is suppressed, the \cmd{\write} commands are not
%    performed. Labels, index entries, or entries for the
%    table of contents aren't written. So it is likely that
%    the table of contents, registers, and lists are incomplete.
% \subsubsection{Options\texorpdfstring{ for handling auxiliary files}{}}
%    \begin{description}
%    \item[\Option{nofiles}:] This is the default. Auxiliary files are
%         read but not written or changed.
%    \item[\Option{nonofiles}/\Option{files}:] Auxiliary files are
%         written.
%    \end{description}
% \subsubsection{\texorpdfstring{Package }{}\Package{hyperref}}
%    In old versions of \Package{hyperref} [1999/04/12 v6.55] (and below)
%    there is a bug with \cmd{\nofiles}:
%    \begin{itemize}
%    \item Some ``garbage'' appears on terminal and in the log file.
%          This is harmless and can be ignored.
%    \item The outline auxiliary file \cmd{\jobname.out}, however,
%          is opened and truncated to zero bytes.
%          Version \ref{Hist10} of this package had
%          loaded a patch file \File{hypnofil.tex}, if it detects
%          \Package{hyperref} to get \cmd{\nofiles} work.
%
%          With the new version of \Package{hyperref} [1999/04/13 v6.56]
%          \cmd{\nofiles} works now. Therefore the workaround code
%          is no longer needed and removed.
%    \end{itemize}
%
% \Installation
%
% \StopEventually{}
%
% \section{Implementation}
% \subsection{Package}
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    If the package is loaded twice, the package code does not
%    work. So stop loading the package, if it is already loaded.
%    \begin{macrocode}
\@ifundefined{ps@makevoid}{}{%
  \PackageWarningNoLine{pagesel}{Package already loaded.}%
  \endinput
}
%    \end{macrocode}
%
%    \begin{macro}{\ps@makevoid}
%    Macro \cmd{\ps@makevoid} clears the output box. Because
%    nothing is shipped out and this is intended, we reduce
%    the counter \cmd{\deadcycles} in order to avoid problems, if
%    more than \cmd{\maxdeadcycles} pages are omitted.
%    \begin{macrocode}
\newcommand*{\ps@makevoid}{%
  \global\setbox\@cclv\copy\voidb@x
  \begingroup
    \count@=\deadcycles
    \advance\count@ by -1\relax
    \deadcycles=\count@
  \endgroup
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\ps@oddpages}
%    \begin{macrocode}
\newcommand*\ps@oddpages{0}
\DeclareOption{odd}{\renewcommand*\ps@oddpages{1}}
\DeclareOption{even}{\renewcommand*\ps@oddpages{2}}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macrocode}
\DeclareOption{nofiles}{\let\ps@nofiles\nofiles}
\DeclareOption{nonofiles}{\let\ps@nofiles\@empty}
\DeclareOption{files}{\let\ps@nofiles\@empty}
\ExecuteOptions{nofiles}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareOption*{%
  \begingroup
    \expandafter\ps@checkoption\CurrentOption-\END
    \edef\x{\endgroup\noexpand\ps@store{\ps@first}{\ps@last}}%
  \x
}
%    \end{macrocode}
%
%    \begin{macro}{\ps@checkoption}
%    \begin{macrocode}
\newcommand\ps@checkoption{}
\def\ps@checkoption#1-#2\END{%
  \ifx\\#2\\%
    \ifx\\#1\\%
      % empty option
      \def\ps@first{\maxdimen}%
      \def\ps@last{\maxdimen}%
    \else
      \edef\ps@first{#1}%
      \edef\ps@last{#1}%
    \fi
  \else
    \ifx\\#1\\%
      \def\ps@first{-\maxdimen}%
    \else
      \edef\ps@first{#1}%
    \fi
    \ps@checklast#2%
  \fi
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\ps@checklast}
%    \begin{macrocode}
\newcommand\ps@checklast{}
\def\ps@checklast#1-{%
  \ifx\\#1\\%
    \def\ps@last{\maxdimen}%
  \else
    \edef\ps@last{#1}%
  \fi
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\ps@store}
%    \begin{macrocode}
\newcommand*{\ps@store}[2]{%
  \expandafter\def\expandafter\ps@testlist\expandafter{%
    \ps@testlist\ps@pagetest{#1}{#2}%
  }%
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\ps@testlist}
%    \begin{macrocode}
\newcommand*\ps@testlist{}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
%    \begin{macrocode}
\begingroup
  \edef\x{%
    \ifnum\ps@oddpages>0 \relax\fi
    \ifx\ps@testlist\@empty\else\relax\fi
  }%
  \ifx\x\@empty
    \endgroup
    \PackageInfo{pagesel}{Nothing to do}
    \expandafter\endinput
  \fi
\endgroup
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{everyshi}
%    \end{macrocode}
%
%    \begin{macrocode}
\ps@nofiles
%    \end{macrocode}
%
%    \begin{macro}{\c@ps@count}
%    \begin{macrocode}
\newcounter{ps@count}
\setcounter{ps@count}{0}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\ps@ReturnAfterElseFi}
%    \begin{macro}{\ps@ReturnAfterFi}
%    \begin{macrocode}
\long\def\ps@ReturnAfterElseFi#1\else#2\fi{\fi#1}
\long\def\ps@ReturnAfterFi#1\fi{\fi#1}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%    \begin{macro}{\ps@ifinset}
%    \begin{macrocode}
\newcommand{\ps@ifinset}[4]{%
  \ifnum#1>\value{ps@count}%
    \ps@ReturnAfterElseFi{#4}%
  \else
    \ps@ReturnAfterFi{%
      \ifnum#2<\value{ps@count}%
        \ps@ReturnAfterElseFi{#4}%
      \else
        \ps@ReturnAfterFi{#3}%
      \fi
    }%
  \fi
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\ps@pagetest}
%    \begin{macrocode}
\newcommand*{\ps@pagetest}[2]{%
  \ps@ifinset{#1}{#2}{\let\ps@next\@empty}{}
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macrocode}
\EveryShipout{%
  \stepcounter{ps@count}%
  \let\ps@next\@empty
  \ifx\ps@testlist\@empty
  \else
    \let\ps@next\ps@makevoid
    \ps@testlist
  \fi
  \ifnum\ps@oddpages=1
    \ifodd\value{ps@count}%
    \else
      \let\ps@next\ps@makevoid
    \fi
  \fi
  \ifnum\ps@oddpages=2
    \ifodd\value{ps@count}%
      \let\ps@next\ps@makevoid
    \else
    \fi
  \fi
  \ps@next
}
%    \end{macrocode}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \StartHistory
% \HistVersion{1999/03/01 v0.9}
%   \begin{itemize}
%   \item The first version was built as a response to a question
%     of \Email[Dirk Kuypers]{dk@comnets.rwth-aachen.de},
%     published in the newsgroup
%     \href{news:de.comp.text.tex}{de.comp.text.tex}:\\
%     \URL{``Re: pdflatex nur fuer bestimmte Seiten?!?''}^^A
%     {http://www.dejanews.com/[ST_rn=ps]/getdoc.xp?AN=450111880}
%   \end{itemize}
% \HistVersion{1999/04/05 v1.0}\HistLabel{Hist10}
%   \begin{itemize}
%   \item Documentation added in dtx format.
%   \item Copyright: LPPL (\CTAN{macros/latex/base/lppl.txt})
%   \item Options |odd|, |even| added.
%   \item \cmd{\nofiles} added, bug fix for \Package{hyperref}.
%   \item Abort loading of package, if nothing to do.
%   \end{itemize}
% \HistVersion{1999/04/13 v1.1}
%   \begin{itemize}
%   \item \cmd{\nofiles} bug fix removed
%         because of \Package{hyperref} 6.55.
%   \item First CTAN release.
%   \end{itemize}
% \HistVersion{2003/06/05 v1.2}
%   \begin{itemize}
%   \item \cmd{\deadcyles} is decremented for omitted pages.
%   \item LPPL 1.2.
%   \end{itemize}
% \hfuzz10pt
% \PrintIndex
%
% \Finale
\endinput