Debian Codegraph @

texmf-dist/source/latex/atbegshi/atbegshi.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: atbegshi.dtx
4 % Version: 2019/12/05 v1.19
5 % Info: At begin shipout hook
6 %
7 % Copyright (C)
8 % 2007-2011 Heiko Oberdiek
9 % 2016-2019 Oberdiek Package Support Group
10 % https://github.com/ho-tex/atbegshi/issues
11 %
12 % This work may be distributed and/or modified under the
13 % conditions of the LaTeX Project Public License, either
14 % version 1.3c of this license or (at your option) any later
15 % version. This version of this license is in
16 % https://www.latex-project.org/lppl/lppl-1-3c.txt
17 % and the latest version of this license is in
18 % https://www.latex-project.org/lppl.txt
19 % and version 1.3 or later is part of all distributions of
20 % LaTeX version 2005/12/01 or later.
21 %
22 % This work has the LPPL maintenance status "maintained".
23 %
24 % The Current Maintainers of this work are
25 % Heiko Oberdiek and the Oberdiek Package Support Group
26 % https://github.com/ho-tex/atbegshi/issues
27 %
28 % The Base Interpreter refers to any `TeX-Format',
29 % because some files are installed in TDS:tex/generic//.
30 %
31 % This work consists of the main source file atbegshi.dtx
32 % and the derived files
33 % atbegshi.sty, atbegshi.pdf, atbegshi.ins, atbegshi.drv,
34 % atbegshi-example1.tex, atbegshi-example2.tex,
35 % atbegshi-test1.tex, atbegshi-test2.tex, atbegshi-test3.tex.
36 %
37 % Distribution:
38 % CTAN:macros/latex/contrib/atbegshi/atbegshi.dtx
39 % CTAN:macros/latex/contrib/atbegshi/atbegshi.pdf
40 %
41 % Unpacking:
42 % (a) If atbegshi.ins is present:
43 % tex atbegshi.ins
44 % (b) Without atbegshi.ins:
45 % tex atbegshi.dtx
46 % (c) If you insist on using LaTeX
47 % latex \let\install=y\input{atbegshi.dtx}
48 % (quote the arguments according to the demands of your shell)
49 %
50 % Documentation:
51 % (a) If atbegshi.drv is present:
52 % latex atbegshi.drv
53 % (b) Without atbegshi.drv:
54 % latex atbegshi.dtx; ...
55 % The class ltxdoc loads the configuration file ltxdoc.cfg
56 % if available. Here you can specify further options, e.g.
57 % use A4 as paper format:
58 % \PassOptionsToClass{a4paper}{article}
59 %
60 % Programm calls to get the documentation (example):
61 % pdflatex atbegshi.dtx
62 % makeindex -s gind.ist atbegshi.idx
63 % pdflatex atbegshi.dtx
64 % makeindex -s gind.ist atbegshi.idx
65 % pdflatex atbegshi.dtx
66 %
67 % Installation:
68 % TDS:tex/generic/atbegshi/atbegshi.sty
69 % TDS:doc/latex/atbegshi/atbegshi.pdf
70 % TDS:doc/latex/atbegshi/atbegshi-example1.tex
71 % TDS:doc/latex/atbegshi/atbegshi-example2.tex
72 % TDS:source/latex/atbegshi/atbegshi.dtx
73 %
74 %<*ignore>
75 \begingroup
76 \catcode123=1 %
77 \catcode125=2 %
78 \def\x{LaTeX2e}%
79 \expandafter\endgroup
80 \ifcase 0\ifx\install y1\fi\expandafter
81 \ifx\csname processbatchFile\endcsname\relax\else1\fi
82 \ifx\fmtname\x\else 1\fi\relax
83 \else\csname fi\endcsname
84 %</ignore>
85 %<*install>
86 \input docstrip.tex
87 \Msg{************************************************************************}
88 \Msg{* Installation}
89 \Msg{* Package: atbegshi 2019/12/05 v1.19 At begin shipout hook (HO)}
90 \Msg{************************************************************************}
91
92 \keepsilent
93 \askforoverwritefalse
94
95 \let\MetaPrefix\relax
96 \preamble
97
98 This is a generated file.
99
100 Project: atbegshi
101 Version: 2019/12/05 v1.19
102
103 Copyright (C)
104 2007-2011 Heiko Oberdiek
105 2016-2019 Oberdiek Package Support Group
106
107 This work may be distributed and/or modified under the
108 conditions of the LaTeX Project Public License, either
109 version 1.3c of this license or (at your option) any later
110 version. This version of this license is in
111 https://www.latex-project.org/lppl/lppl-1-3c.txt
112 and the latest version of this license is in
113 https://www.latex-project.org/lppl.txt
114 and version 1.3 or later is part of all distributions of
115 LaTeX version 2005/12/01 or later.
116
117 This work has the LPPL maintenance status "maintained".
118
119 The Current Maintainers of this work are
120 Heiko Oberdiek and the Oberdiek Package Support Group
121 https://github.com/ho-tex/atbegshi/issues
122
123
124 The Base Interpreter refers to any `TeX-Format',
125 because some files are installed in TDS:tex/generic//.
126
127 This work consists of the main source file atbegshi.dtx
128 and the derived files
129 atbegshi.sty, atbegshi.pdf, atbegshi.ins, atbegshi.drv,
130 atbegshi-example1.tex, atbegshi-example2.tex,
131 atbegshi-test1.tex, atbegshi-test2.tex, atbegshi-test3.tex.
132
133 \endpreamble
134 \let\MetaPrefix\DoubleperCent
135
136 \generate{%
137 \file{atbegshi.ins}{\from{atbegshi.dtx}{install}}%
138 \file{atbegshi.drv}{\from{atbegshi.dtx}{driver}}%
139 \usedir{tex/generic/atbegshi}%
140 \file{atbegshi.sty}{\from{atbegshi.dtx}{package}}%
141 \usedir{doc/latex/atbegshi}%
142 \file{atbegshi-example1.tex}{\from{atbegshi.dtx}{example1}}%
143 \file{atbegshi-example2.tex}{\from{atbegshi.dtx}{example2}}%
144 }
145
146 \catcode32=13\relax% active space
147 \let =\space%
148 \Msg{************************************************************************}
149 \Msg{*}
150 \Msg{* To finish the installation you have to move the following}
151 \Msg{* file into a directory searched by TeX:}
152 \Msg{*}
153 \Msg{* atbegshi.sty}
154 \Msg{*}
155 \Msg{* To produce the documentation run the file `atbegshi.drv'}
156 \Msg{* through LaTeX.}
157 \Msg{*}
158 \Msg{* Happy TeXing!}
159 \Msg{*}
160 \Msg{************************************************************************}
161
162 \endbatchfile
163 %</install>
164 %<*ignore>
165 \fi
166 %</ignore>
167 %<*driver>
168 \NeedsTeXFormat{LaTeX2e}
169 \ProvidesFile{atbegshi.drv}%
170 [2019/12/05 v1.19 At begin shipout hook (HO)]%
171 \documentclass{ltxdoc}
172 \usepackage{holtxdoc}[2011/11/22]
173 \begin{document}
174 \DocInput{atbegshi.dtx}%
175 \end{document}
176 %</driver>
177 % \fi
178 %
179 %
180 %
181 % \GetFileInfo{atbegshi.drv}
182 %
183 % \title{The \xpackage{atbegshi} package}
184 % \date{2019/12/05 v1.19}
185 % \author{Heiko Oberdiek\thanks
186 % {Please report any issues at \url{https://github.com/ho-tex/atbegshi/issues}}}
187 %
188 % \maketitle
189 %
190 % \begin{abstract}
191 % This package is a modern reimplementation of package \xpackage{everyshi}
192 % without the burden of compatibility. It makes use of \eTeX's if available.
193 % Both \LaTeX\ and \plainTeX\ are supported.
194 % \end{abstract}
195 %
196 % \tableofcontents
197 %
198 % \section{Documentation}
199 %
200 % Package \xpackage{atbegshi} redefines \cs{shipout} to insert
201 % hooks for user code that is executed before the page is shipped out.
202 % The code may modify or even discard the output page.
203 % Three hooks are implemented:
204 % \begin{enumerate}
205 % \item A hook that is executed for every page, see\\
206 % \cs{AtBeginShipout}
207 % \item A hook that is executed for the next page only, see\\
208 % \cs{AtBeginShipoutNext}
209 % \item A hook that is only executed for the first page, see\\
210 % \cs{AtBeginShipoutFirst}
211 % \end{enumerate}
212 % The hooks are executed in this order. The following three macros
213 % provide the user interface for adding code to these hooks:
214 %
215 % \begin{declcs}{AtBeginShipout} \M{code}\\
216 % \cs{AtBeginShipoutBox}
217 % \end{declcs}
218 % Execute the \meta{code} for every page.
219 % The page contents is held in box register \cs{AtBeginShipoutBox}
220 % and may be modified. Use \cs{AtBeginShipoutDiscard} if you want to
221 % discard the page.
222 %
223 % \emph{Note:} Package \xpackage{everyshi} uses box register 255. With
224 % package \xpackage{atbegshi} you must use \cs{AtBeginShipoutBox} instead.
225 %
226 % If \LaTeX\ calls \cs{shipout} in \cs{@outputpage} (part of its output
227 % routine),
228 % the meaning of \cs{protect} is \cs{noexpand}. \LaTeX\ sets
229 % \cs{protect} to the appropriate \cs{@typeset@protect} in the box
230 % that is shipped out. This is too late for the hooks, they
231 % are called earlier in the redefined \cs{shipout}. Therefore
232 % package \xpackage{atbegshi} sets \cs{protect} to \cs{@typeset@protect}
233 % before it calls the hooks.
234 % (In \cs{EveryShipout} of package \xpackage{everyshi} the
235 % user is responsible for the correct setting of \cs{protect}.)
236 %
237 % \begin{declcs}{AtBeginShipoutNext} \M{code}
238 % \end{declcs}
239 % This reimplements package \xpackage{everyshi}'s \cs{AtNextShipout}.
240 % The \meta{code} is executed at shipout time of the next page only.
241 % It is just a convenience macro, it can be easily replaced by something
242 % like:
243 %\begin{quote}
244 %\begin{verbatim}
245 %\newcommand{\MyShipoutHook}{}%
246 %\AtBeginShipout{\MyShipoutHook}
247 %\gdef\MyShipoutHook{%
248 % ... do something with next page ...
249 % \gdef\MyShipoutHook{}%
250 % }
251 %\end{verbatim}
252 %\end{quote}
253 % (This can be necessary, if hook order does matter).
254 %
255 % \begin{declcs}{AtBeginShipoutFirst} \M{code}
256 % \end{declcs}
257 % This reimplements \LaTeX's \cs{AtBeginDvi}. This hook is
258 % usually used for \cs{special} commands that include PostScript
259 % header files. The \cs{code} is directly executed in a \cs{vbox}
260 % that is put at the beginning of the output page. Dealing with
261 % the output box \cs{AtBeginShipoutBox} is not necessary and
262 % not permitted here.
263 %
264 % \begin{declcs}{AtBeginShipoutDiscard}
265 % \end{declcs}
266 % This macro notifies package \xpackage{atbegshi} that
267 % the output page is discarded. The remaining hook code
268 % and the remaining hooks are not executed and the page is thrown away.
269 % Also \cs{deadcycles} is cleared to zero like an ordinary \cs{shipout}
270 % would do.
271 %
272 % \begin{declcs}{AtBeginShipoutInit}
273 % \end{declcs}
274 % Usually the redefinition of \cs{shipout} is delayed by
275 % \cs{AtBeginDocument} (if this macro exists). This can be
276 % too late, if other packages also redefines \cs{shipout}
277 % and the order does matter.
278 % \cs{AtBeginShipoutInit} forces the immediate redefinition
279 % of \cs{shipout}.
280 %
281 % \begin{declcs}{AtBeginShipoutAddToBox} \M{stuff}\\
282 % \cs{AtBeginShipoutAddToBoxForeground} \M{stuff}
283 % \end{declcs}
284 % A quite common use case is the addition of \cs{special}
285 % or other whatsits to the page output box. Macro
286 % \cs{AtBeginShipoutAddToBox} puts \meta{stuff} in a
287 % box with zeroed dimensions. The box with the \meta{stuff}
288 % is put in the upper left corner of the shipout box
289 % \cs{AtBeginShipoutBox}. Macro \cs{AtBeginShipoutAddToBox}
290 % puts the \meta{stuff} in the background, the other macro
291 % \cs{AtBeginShipoutAddToBoxForeground} in the foreground
292 % after the original shipout box contents is set.
293 %
294 % A void shipout box (that means a discarded page)
295 % remains void that means \meta{stuff} is ignored in this case.
296 % The box type of \cs{AtBeginShipoutBox} is preserved.
297 % Also the box nesting level for the original contents
298 % of \cs{AtBeginShipoutBox} remains, for example, to avoid trouble
299 % with links across pages in case of \hologo{pdfTeX}.
300 %
301 % \begin{declcs}{AtBeginShipoutUpperLeft} \M{background material}
302 % \end{declcs}
303 % This is a macro that puts material in the background of
304 % box \cs{AtBeginShipoutBox}.
305 % The \meta{background material} is set in an \cs{hbox}, the
306 % reference point is the upper left corner of the output page.
307 % In case of \pdfTeX\ in PDF mode, the settings of
308 % \cs{pdfhorigin} and \cs{pdfvorigin} are respected.
309 %
310 % The macro \cs{AtBeginShipoutUpperLeft} is intended to be used
311 % in one of the hook setting macros, such as
312 % \cs{AtBeginShipout}, \cs{AtBeginShipoutFirst}, or
313 % \cs{AtBeginShipoutNext}.
314 %
315 % For \LaTeX\ users the \meta{background material} is set
316 % inside a \texttt{picture} environment:
317 % \begin{quote}
318 % |\begin{picture}(0,0)|\\
319 % \mbox{}\quad |\setlength{\unitlength}{1pt}%|\\
320 % \mbox{}\quad \meta{background material}\\
321 % |\end{picture}|
322 % \end{quote}
323 %
324 % \begin{declcs}{AtBeginShipoutUpperLeftForeground} \M{foreground material}
325 % \end{declcs}
326 % See \cs{AtBeginShipoutUpperLeft}. The difference is that the material
327 % is put in the foreground.
328 %
329 % \begin{declcs}{AtBeginShipoutOriginalShipout} \meta{box}
330 % \end{declcs}
331 % It stores the meaning of \cs{shipout} at the time this package
332 % is loaded.
333 %
334 % \begin{declcs}{AtBeginShipoutBoxWidth}\\
335 % \cs{AtBeginShipoutBoxHeight}\\
336 % \cs{AtBeginShipoutBoxDepth}\\
337 % \end{declcs}
338 % These macros store the dimensions of the output box \cs{AtBeginShipoutBox}
339 % before the original shipout is called. If \cs{shipout} is not
340 % redefined before the package loading or the box dimensions
341 % are not changed by the redefined \cs{shipout}, these macros
342 % contain the dimensions of the shipout box. These values can be
343 % remembered by \cs{label} and \cs{ref}. For example, this is done
344 % by the package module \xpackage{zref-pagelayout} of project \xpackage{zref}.
345 % The dimensions of the shipout page can be used in some \hologo{TeX}
346 % engines (\hologo{pdfTeX} in PDF mode, \hologo{XeTeX}) to calculate
347 % the media size of the shipout page if \cs{pdfpagewidth} and
348 % \cs{pdfpageheight} are not set.
349 %
350 % \subsection{Examples}
351 %
352 % \subsubsection{Example: circle in background}
353 %
354 % In this example we put a circle in the background in the middle
355 % of the paper.
356 %
357 % \begin{macrocode}
358 %<*example1>
359 % \end{macrocode}
360 % \begin{macrocode}
361 \documentclass[a4paper]{article}
362 \usepackage{color}
363 \usepackage{atbegshi}
364 % \end{macrocode}
365 % Package \xpackage{picture} makes life a little easier, because
366 % we can now also use length specifications in |picture|'s commands.
367 % \begin{macrocode}
368 \usepackage{picture}
369 % \end{macrocode}
370 % Now we draw the circle in the middle of the paper.
371 % \cs{put} moves downwards, because the origin is at the top
372 % of the page, not at its bottom.
373 % \begin{macrocode}
374 \AtBeginShipout{%
375 \AtBeginShipoutUpperLeft{%
376 \put(0.5\paperwidth,-0.5\paperheight){\circle{10}}%
377 }%
378 }
379 \begin{document}
380 \section{Hello World}
381 \newpage
382 \AtBeginShipoutNext{%
383 \AtBeginShipoutUpperLeft{%
384 \color{red}%
385 \put(0,-0.5\paperheight){\line(1,0){\paperwidth}}%
386 \put(0.5\paperwidth, 0){\line(0,-1){\paperheight}}%
387 }%
388 }
389 Only on this page we add a red cross.
390 \newpage
391 This page has the circle only.
392 \par
393 \vspace{\fill}
394 The next page will be discarded.
395 \newpage
396 \AtBeginShipoutNext{%
397 \AtBeginShipoutDiscard
398 }
399 This page is discarded.
400 \newpage
401 The last page.
402 \end{document}
403 % \end{macrocode}
404 % \begin{macrocode}
405 %</example1>
406 % \end{macrocode}
407 %
408 % \subsubsection{Example: adding TrimBox for dvipdfmx}
409 %
410 % Now an example from ``real life'' follows. Someone from the mailing list
411 % for dvipdfmx wants to put a TrimBox on every page. If we use
412 % \cs{AtBeginShipout}, we have to put the \cs{special} inside the
413 % box \cs{AtBeginShipoutBox} that gets shipped out.
414 % \begin{macrocode}
415 %<*example2>
416 \documentclass{minimal}
417 \usepackage{atbegshi}
418 \usepackage[
419 dvipdfm,
420 paperwidth=630bp,
421 paperheight=810bp
422 ]{geometry}
423 \AtBeginShipout{%
424 \setbox\AtBeginShipoutBox=\hbox{%
425 \special{pdf: put @thispage <</TrimBox[9 9 621 801]>>}%
426 \box\AtBeginShipoutBox
427 }%
428 }
429 \begin{document}
430 First page
431 \newpage
432 Second page
433 \end{document}
434 %</example2>
435 % \end{macrocode}
436 % Remember, in \cs{AtBeginShipoutBoxFirst} the \cs{setbox} wrapper code
437 % is implicitly given and the \cs{special} is used directly.
438 %
439 % \section{Method of \cs{shipout} overloading}
440 %
441 % \subsection{\cs{shipout}}
442 %
443 % The \TeX\ primitive command \cs{shipout} takes a box specification
444 % and puts the box as a new page in the output file.
445 % There are two kinds of box specifications:
446 % \begin{description}
447 % \item[Direct boxes:]
448 % They are given by \cs{hbox}, \cs{vbox}, or \cs{vtop},\\
449 % e.g. |\shipout\hbox{Hello World}|.
450 % \item[Indirect boxes:]
451 % \cs{box} or \cs{copy} references a box register by number.
452 % The box register contains the contents of the box.
453 %
454 % \emph{Note:} \cs{box} also clears the box register globally.
455 % \end{description}
456 % Then we have to differentiate between void and empty boxes:
457 % \begin{description}
458 % \item[Void:]
459 % Initially or after \cs{box} there is no box in the box register.
460 % In this cases the box register is not empty, but \emph{void}.
461 % \item[Empty:]
462 % A box with empty contents, such as
463 % |\hbox{}| (= \cs{null}) or |\vbox{}| is an \emph{empty \cs{hbox}}
464 % or \emph{empty \cs{vbox}}. If a box register holds such a
465 % box, the box still exists, therefore the box register is
466 % \emph{not void}.
467 % \end{description}
468 %
469 % \subsection{\cs{afterassignment}}
470 %
471 % We want to overload \cs{shipout} to do something with the box.
472 % It is quite impossible to do this reliable by catching the box
473 % using macro arguments. The
474 % variety of box specifications is too large, Examples:
475 % \begin{quote}
476 % |\shipout\null|\\
477 % |\shipout\vbox{...}|\\
478 % |\shipout\vtop\bgroup ...\egroup|\\
479 % |\shipout\box255|
480 % \end{quote}
481 % Even worse, the braces don't need to be balanced:
482 % \begin{quote}
483 % |\shipout\hbox\bgroup}|\\
484 % |\shipout\vbox{\egroup|
485 % \end{quote}
486 % Happily TeX provides a reliable way via \cs{afterassignment}.
487 % It takes a macro name and executes it just after the assignment.
488 %
489 % Now we can redefine \cs{shipout}. The box specification that
490 % follows \cs{shipout} is catched by \cs{setbox}. This is an
491 % assignment to a box register. \cs{afterassignment}
492 % notifies \TeX, that we want to call \cs{@test} right after
493 % the assignment:
494 %\begin{quote}
495 %\begin{verbatim}
496 %\shipout :=
497 % \afterassignment\@test
498 % \setbox\mybox=
499 %\end{verbatim}
500 %\end{quote}
501 % We have seen different box specifications. Indirect boxes are easy
502 % to understand:
503 % \begin{quote}
504 % |\shipout\box0| $\Rightarrow$ |\setbox\mybox=\box0 |\fbox{\cs{@test}}
505 % \end{quote}
506 % However direct boxes can have arbitrary contents with lots of
507 % other assignments. It would be quite inpredictable if \TeX\ would
508 % put |\@test| after the first of such an assignment or after the
509 % box specification if the box lacks of assignments.
510 % Therefore \TeX\ puts |\@test| right at the beginning of the
511 % box specification, e.g:
512 % \begin{quote}
513 % |\shipout\hbox{Hello World}|\\
514 % $\Rightarrow$
515 % |\setbox\mybox=\hbox{|\fbox{\cs{@test}}| Hello World}|
516 % \end{quote}
517 %
518 % \subsection{Test for direct or indirect boxes}
519 %
520 % Now we want to execute \cs{@test}, but where are we?
521 % We can be after the completed box assignment, if \cs{shipout}
522 % was called with an indirect box. Or we are right at the beginning
523 % of a direct box.
524 %
525 % \subsubsection{With \eTeX}
526 %
527 % With the \eTeX's extensions the answer is very easy:
528 % Being inside the direct box means that we are inside a new group.
529 % The new primitive command \cs{currentgrouplevel} tells how
530 % deeply the groups are currently nested. Macro \cs{@test} just
531 % compares the previously stored group level with the current one:
532 %\begin{quote}
533 %\begin{verbatim}
534 %\shipout :=
535 % \edef\saved@grouplevel{\number\currentgrouplevel}
536 % \afterassignment\@test
537 % \setbox\mybox=
538 %
539 %\@test :=
540 % \ifnum\saved@grouplevel=\currentgrouplevel
541 % % case: indirect box, the assignment is completed
542 % \@output
543 % \else
544 % % case: direct box, we are inside the box
545 % \aftergroup\@outbox
546 % \fi
547 %\end{verbatim}
548 %\end{quote}
549 %
550 % \subsubsection{Without \eTeX}
551 %
552 % Life becomes complicate without \eTeX. We cannot ask the
553 % group level. However, if we are inside a direct box,
554 % the box register \cs{mybox} is not yet changed by \cs{setbox}.
555 % Thus we need a special initial value and compare
556 % it in \cs{@test} with the current value of the box.
557 %
558 % What can be used as initial value? Arbitrary box contents cannot
559 % be compared. \TeX\ only tells us a few properties:
560 % \begin{itemize}
561 % \item Box type:\cs{ifhbox}, \cs{ifvbox}
562 % \item Dimensions: \cs{wd}, \cs{ht}, \cs{dp}
563 % \item Voidness: \cs{ifvoid}
564 % \end{itemize}
565 % Unhappily all these qualities even combined are not sufficient
566 % for constructing an initial box value, because \cs{shipout} can be
567 % called with a box that is accidently just the same as the choosen
568 % initial value.
569 %
570 % Nevertheless we have two alternatives for an initial value:
571 % \begin{itemize}
572 % \item A box of some type with some funny settings that are
573 % unlikely to occur in real life, e.g a height of |4911sp-\maxdimen|.
574 % \item A void box.
575 % \end{itemize}
576 % A collision between this initial value and an indirect \cs{shipout}
577 % box with just the same value is possible.
578 % Then \cs{@test} will make a wrong decision that it is executed
579 % inside a direct box and delays \cs{@output} by \cs{aftergroup}.
580 % Thus \cs{@output} is not called at the place we want.
581 % In contrary, the result is an uncertainty about the place:
582 % \begin{itemize}
583 % \item \cs{shipout} is used in a group that perhaps closes some
584 % pages later. A bad place for \cs{@output}.
585 % \item Without a surrounding group \cs{aftergroup} effectively kills
586 % its argument.
587 % \end{itemize}
588 % In the first case of a box with special dimensions we can even loose
589 % the page. However in the case of the void box, this effect is even
590 % desired, because the original \cs{shipout} does not output void boxes.
591 % All we have to do is to ensure that our box \cs{mybox} is always
592 % void except for the phase when the overloaded \cs{shipout} is executed.
593 % And secondly we must keep this semantics of \cs{shipout} for the void case
594 % in our macros, namely \cs{@output}.
595 %\begin{quote}
596 %\begin{verbatim}
597 %\shipout :=
598 % % trick to get a void box \mybox
599 % \begingroup
600 % \setbox\mybox=\box\mybox
601 % \endgroup
602 % \afterassignment\@test
603 % \setbox\mybox=
604 %
605 %\@test :=
606 % \ifvoid\mybox
607 % \aftergroup\@output
608 % \else
609 % \@output
610 % \fi
611 %\end{verbatim}
612 %\end{quote}
613 % The nasty case is |\shipout\box\voidb@x| where the indirect box
614 % is void and that must not generate an output page.
615 % If a surrounding group is missing the output is ignored
616 % because of \cs{aftergroup}.
617 % Otherwise \@output is called some time
618 % later when the surrounding group closes.
619 % But \cs{mybox} is void outside the execution phase
620 % of the redefined \cs{shipout}. Also \cs{@output} checks for a
621 % void box and cancels the page output.
622 % The disadvantage remains that the hook in \cs{@output} is called
623 % for a page that will not be output.
624 %
625 % \subsubsection{\cs{lastkern} method}
626 %
627 % At the beginning of a new box, there is no \cs{kern}, the contents
628 % of the box is still empty and \cs{lastkern} returns 0\,pt.
629 % This can be used to distinguish between direct and indirect boxes:
630 % We execute \cs{setbox} in a box with a preceding non-zero kern.
631 % After an indirect box, \cs{lastkern} sees this kern, otherwise
632 % it returns 0\,pt.
633 %\begin{quote}
634 %\begin{verbatim}
635 %\shipout :=
636 % \begingroup
637 % \setbox\mybox=\hbox\bgroup
638 % \kern1pt
639 % \afterassignment\shipout@test
640 % \global\setbox\mybox=
641 %\@test :=
642 % \ifdim\lastkern=0pt
643 % % direct box
644 % \aftergroup\egroup
645 % \aftergroup\endgroup
646 % \aftergroup\@output
647 % \else
648 % \egroup
649 % \endgroup
650 % \@output
651 % \fi
652 %\end{verbatim}
653 %\end{quote}
654 % We have two \cs{setbox} commands. The first creates a controlled
655 % context box where we can safely insert a \cs{kern}. We get rid of
656 % this temporarily used context box by putting the local \cs{setbox}
657 % in a group.
658 %
659 % After the group we want to have our shipout box in \cs{mybox}.
660 % Therefore we use a global assignment here.
661 %
662 % \subsection{Output}
663 %
664 % With or without \eTeX\ we ensure the original behaviour of
665 % \cs{shipout} that void boxes do not generate output pages.
666 %
667 % Now we can place the hook \cs{@hook} for the user code that
668 % wants to manipulate the output box.
669 %\begin{quote}
670 %\begin{verbatim}
671 %\@output :=
672 % \ifvoid\mybox
673 % % cancel output of void box
674 % \else
675 % \@hook
676 % \ifvoid\mybox
677 % % user code in \@hook could has voided the box
678 % \else
679 % \original@shipout\box\mybox
680 % \fi
681 % \fi
682 %\end{verbatim}
683 %\end{quote}
684 %
685 % \subsection{Separate box register}
686 %
687 % So far we have said nothing about the box number of \cs{mybox}.
688 % The following case that outputs the same page twice
689 % shows that we are not free in the use
690 % of the box register:
691 % \begin{quote}
692 % |\shipout\copy<num> \shipout\box<num>|
693 % \end{quote}
694 % We manipulate the box by the hook and without \eTeX\ the box
695 % must even be voided. However, the use case above requires that
696 % the box contents does not change at all. Therefore we must
697 % reserve a separate box register to avoid collisions with
698 % user box registers.
699 %
700 % \emph{Note:} Box register number 255 is special for the output
701 % routine, because TeX complains if this box is not voided
702 % by the output routine.
703 % However, this requirement does not apply to \cs{shipout} at all.
704 % In fact \cs{shipout} does not change any box register. This is
705 % usually done by a call of \cs{box}, but the output routine
706 % can do it later \emph{after} invoking of \cs{shipout}.
707 %
708 % \subsection{Summary}
709 %
710 % \subsubsection{With \eTeX}
711 %
712 % Putting the pieces together we get for \eTeX:
713 %\begin{quote}
714 %\begin{verbatim}
715 %\newbox\mybox
716 %\let\original@shipout\shipout
717 %
718 %\shipout :=
719 % \edef\saved@grouplevel{\number\currentgrouplevel}
720 % \afterassignment\@test
721 % \setbox\mybox=
722 %
723 %\@test :=
724 % \ifnum\saved@grouplevel<\currentgrouplevel
725 % \expandafter\aftergroup
726 % \fi
727 % \@output
728 %
729 %\@output :=
730 % \ifvoid\mybox
731 % % cancel output of void box
732 % \else
733 % \@hook
734 % \ifvoid\mybox
735 % % user code in \@hook could have voided the box
736 % \else
737 % \original@shipout\box\mybox
738 % \fi
739 % \fi
740 %\end{verbatim}
741 %\end{quote}
742 %
743 % \subsubsection{Without \eTeX, traditional way}
744 %
745 % And for \TeX\ without \eTeX:
746 %\begin{quote}
747 %\begin{verbatim}
748 %\newbox\mybox
749 %\begingroup
750 % \setbox\mybox=\box\mybox % ensure \mybox is void
751 %\endgroup
752 %\let\original@shipout\shipout
753 %
754 %\shipout :=
755 % % trick to get a void box \mybox
756 % \begingroup
757 % \setbox\mybox=\box\mybox
758 % \endgroup
759 % \afterassignment\@test
760 % \setbox\mybox=
761 %
762 %\@test :=
763 % \ifvoid\mybox
764 % \expandafter\aftergroup
765 % \fi
766 % \@output
767 %
768 %\@output :=
769 % \ifvoid\mybox
770 % % cancel output of void box
771 % \else
772 % \@hook
773 % \ifvoid\mybox
774 % % user code in \@hook could have voided the box
775 % \else
776 % \original@shipout\box\mybox
777 % \fi
778 % \fi
779 %\end{verbatim}
780 %\end{quote}
781 %
782 % \subsubsection{\cs{lastkern} method}
783 %
784 % And for \TeX\ without \eTeX\ using the \cs{lastkern} method:
785 %\begin{quote}
786 %\begin{verbatim}
787 %\newbox\mybox
788 %\let\original@shipout\shipout
789 %
790 %\shipout :=
791 % \begingroup
792 % \setbox\mybox=\hbox\bgroup
793 % \kern1pt
794 % \afterassignment\@test
795 % \setbox\mybox=
796 %
797 %\@test :=
798 % \ifdim\lastkern=0pt
799 % \expandafter\aftergroup
800 % \fi
801 % \@output
802 %
803 %\@output :=
804 % \egroup
805 % \endgroup
806 % \ifvoid\mybox
807 % % cancel output of void box
808 % \else
809 % \@hook
810 % \ifvoid\mybox
811 % % user code in \@hook could have voided the box
812 % \else
813 % \original@shipout\box\mybox
814 % \fi
815 % \fi
816 %\end{verbatim}
817 %\end{quote}
818 %
819 %
820 % \StopEventually{
821 % }
822 %
823 % \section{Implementation}
824 %
825 % Package \xpackage{atbegshi} uses \eTeX's \cs{currentgrouplevel},
826 % if it is available. Otherwise the \cs{lastkern} method is used.
827 %
828 % \begin{macrocode}
829 %<*package>
830 % \end{macrocode}
831 %
832 % \subsection{Reload check and package identification}
833 % Reload check, especially if the package is not used with \LaTeX.
834 % \begin{macrocode}
835 \begingroup\catcode61\catcode48\catcode32=10\relax%
836 \catcode13=5 % ^^M
837 \endlinechar=13 %
838 \catcode35=6 % #
839 \catcode39=12 % '
840 \catcode44=12 % ,
841 \catcode45=12 % -
842 \catcode46=12 % .
843 \catcode58=12 % :
844 \catcode64=11 % @
845 \catcode123=1 % {
846 \catcode125=2 % }
847 \expandafter\let\expandafter\x\csname [email protected]\endcsname
848 \ifx\x\relax % plain-TeX, first loading
849 \else
850 \def\empty{}%
851 \ifx\x\empty % LaTeX, first loading,
852 % variable is initialized, but \ProvidesPackage not yet seen
853 \else
854 \expandafter\ifx\csname PackageInfo\endcsname\relax
855 \def\x#1#2{%
856 \immediate\write-1{Package #1 Info: #2.}%
857 }%
858 \else
859 \def\x#1#2{\PackageInfo{#1}{#2, stopped}}%
860 \fi
861 \x{atbegshi}{The package is already loaded}%
862 \aftergroup\endinput
863 \fi
864 \fi
865 \endgroup%
866 % \end{macrocode}
867 % Package identification:
868 % \begin{macrocode}
869 \begingroup\catcode61\catcode48\catcode32=10\relax%
870 \catcode13=5 % ^^M
871 \endlinechar=13 %
872 \catcode35=6 % #
873 \catcode39=12 % '
874 \catcode40=12 % (
875 \catcode41=12 % )
876 \catcode44=12 % ,
877 \catcode45=12 % -
878 \catcode46=12 % .
879 \catcode47=12 % /
880 \catcode58=12 % :
881 \catcode64=11 % @
882 \catcode91=12 % [
883 \catcode93=12 % ]
884 \catcode123=1 % {
885 \catcode125=2 % }
886 \expandafter\ifx\csname ProvidesPackage\endcsname\relax
887 \def\x#1#2#3[#4]{\endgroup
888 \immediate\write-1{Package: #3 #4}%
889 \xdef#1{#4}%
890 }%
891 \else
892 \def\x#1#2[#3]{\endgroup
893 #2[{#3}]%
894 \ifx#1\@undefined
895 \xdef#1{#3}%
896 \fi
897 \ifx#1\relax
898 \xdef#1{#3}%
899 \fi
900 }%
901 \fi
902 \expandafter\x\csname [email protected]\endcsname
903 \ProvidesPackage{atbegshi}%
904 [2019/12/05 v1.19 At begin shipout hook (HO)]%
905 % \end{macrocode}
906 %
907 % \subsection{Catcodes}
908 %
909 % \begin{macrocode}
910 \begingroup\catcode61\catcode48\catcode32=10\relax%
911 \catcode13=5 % ^^M
912 \endlinechar=13 %
913 \catcode123=1 % {
914 \catcode125=2 % }
915 \catcode64=11 % @
916 \def\x{\endgroup
917 \expandafter\edef\csname AtBegShi@AtEnd\endcsname{%
918 \endlinechar=\the\endlinechar\relax
919 \catcode13=\the\catcode13\relax
920 \catcode32=\the\catcode32\relax
921 \catcode35=\the\catcode35\relax
922 \catcode61=\the\catcode61\relax
923 \catcode64=\the\catcode64\relax
924 \catcode123=\the\catcode123\relax
925 \catcode125=\the\catcode125\relax
926 }%
927 }%
928 \x\catcode61\catcode48\catcode32=10\relax%
929 \catcode13=5 % ^^M
930 \endlinechar=13 %
931 \catcode35=6 % #
932 \catcode64=11 % @
933 \catcode123=1 % {
934 \catcode125=2 % }
935 \def\TMP@EnsureCode#1#2{%
936 \edef\AtBegShi@AtEnd{%
937 \AtBegShi@AtEnd
938 \catcode#1=\the\catcode#1\relax
939 }%
940 \catcode#1=#2\relax
941 }
942 \TMP@EnsureCode{40}{12}% (
943 \TMP@EnsureCode{41}{12}% )
944 \TMP@EnsureCode{44}{12}% ,
945 \TMP@EnsureCode{45}{12}% -
946 \TMP@EnsureCode{47}{12}% /
947 \TMP@EnsureCode{46}{12}% .
948 \TMP@EnsureCode{58}{12}% :
949 \TMP@EnsureCode{91}{12}% [
950 \TMP@EnsureCode{93}{12}% ]
951 \TMP@EnsureCode{94}{7}% ^(superscript)
952 \TMP@EnsureCode{96}{12}% `
953 \edef\AtBegShi@AtEnd{\AtBegShi@AtEnd\noexpand\endinput}
954 % \end{macrocode}
955 %
956 % \subsection{Preparations}
957 %
958 % \begin{macrocode}
959 \begingroup\expandafter\expandafter\expandafter\endgroup
960 \expandafter\ifx\csname RequirePackage\endcsname\relax
961 \def\TMP@RequirePackage#1[#2]{%
962 \begingroup\expandafter\expandafter\expandafter\endgroup
963 \expandafter\ifx\csname ver@#1.sty\endcsname\relax
964 \input #1.sty\relax
965 \fi
966 }%
967 \TMP@RequirePackage{infwarerr}[2007/09/09]%
968 \TMP@RequirePackage{ltxcmds}[2010/03/01]%
969 \else
970 \RequirePackage{infwarerr}[2007/09/09]%
971 \RequirePackage{ltxcmds}[2010/03/01]%
972 \fi
973 % \end{macrocode}
974 %
975 % \begin{macro}{\AtBegShi@CheckDefinable}
976 % \begin{macrocode}
977 \begingroup\expandafter\expandafter\expandafter\endgroup
978 \expandafter\ifx\csname @ifdefinable\endcsname\relax
979 \def\AtBegShi@CheckDefinable#1{%
980 \ifcase\ifx#1\relax
981 \ltx@one
982 \else
983 \ifx#1\@undefined
984 \ltx@one
985 \else
986 \ltx@zero
987 \fi
988 \fi
989 \@PackageError{atbegshi}{%
990 \string#1\space is already defined%
991 }\@ehd
992 \fi
993 }%
994 \else
995 \def\AtBegShi@CheckDefinable#1{%
996 \@ifdefinable{#1}{}%
997 }%
998 \fi
999 % \end{macrocode}
1000 % \end{macro}
1001 %
1002 % \begin{macro}{\ifAtBegShi@Discarded}
1003 % \begin{macrocode}
1004 \ltx@newif\ifAtBegShi@Discarded
1005 % \end{macrocode}
1006 % \end{macro}
1007 % \begin{macro}{\AtBeginShipoutDiscard}
1008 % \begin{macrocode}
1009 \AtBegShi@CheckDefinable\AtBeginShipoutDiscard
1010 \def\AtBeginShipoutDiscard{%
1011 \deadcycles=\ltx@zero
1012 \global\AtBegShi@Discardedtrue
1013 }
1014 % \end{macrocode}
1015 % \end{macro}
1016 %
1017 % \begin{macrocode}
1018 \begingroup\expandafter\expandafter\expandafter\endgroup
1019 \expandafter\ifx\csname currentgrouplevel\endcsname\relax
1020 \catcode`X=9 % ignore
1021 \catcode`E=14 % comment
1022 \else
1023 \catcode`X=14 % comment
1024 \catcode`E=9 % ignore
1025 \fi
1026 % \end{macrocode}
1027 %
1028 % \begin{macro}{\AtBegShi@Shipout}
1029 % \begin{macrocode}
1030 \def\AtBegShi@Shipout{%
1031 X \begingroup
1032 X \setbox\AtBeginShipoutBox=\hbox\bgroup
1033 X \kern\p@
1034 E \edef\AtBegShi@GroupLevel{\number\currentgrouplevel}%
1035 \afterassignment\AtBegShi@Test
1036 X \global
1037 \setbox\AtBeginShipoutBox=%
1038 }
1039 % \end{macrocode}
1040 % \end{macro}
1041 %
1042 % \begin{macro}{\AtBegShi@Test}
1043 % \begin{macrocode}
1044 \def\AtBegShi@Test{%
1045 X \ifdim\lastkern=0pt %
1046 E \ifnum\AtBegShi@GroupLevel<\currentgrouplevel
1047 \expandafter\aftergroup
1048 \fi
1049 \AtBegShi@Output
1050 }
1051 % \end{macrocode}
1052 % \end{macro}
1053 %
1054 % \begin{macro}{\AtBegShi@Output}
1055 % \begin{macrocode}
1056 \def\AtBegShi@Output{%
1057 X \egroup
1058 X \endgroup
1059 \ifvoid\AtBeginShipoutBox
1060 \@PackageWarning{atbegshi}{Ignoring void shipout box}%
1061 \else
1062 \let\AtBegShi@OrgProtect\protect
1063 \csname set@typeset@protect\endcsname
1064 \global\AtBegShi@Discardedfalse
1065 \AtBegShi@Hook
1066 \expandafter\gdef\expandafter\AtBegShi@HookNext
1067 \expandafter{\expandafter}%
1068 \AtBegShi@HookNext
1069 \ifAtBegShi@Discarded
1070 \@PackageInfoNoLine{atbegshi}{Shipout page discarded}%
1071 \global\AtBegShi@Discardedfalse
1072 \begingroup
1073 \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
1074 \endgroup
1075 \let\protect\AtBegShi@OrgProtect
1076 \else
1077 \AtBegShi@First
1078 \let\protect\AtBegShi@OrgProtect
1079 \AtBegShi@GetBoxSize\AtBeginShipoutBox
1080 \ltx@ifundefined{AtNextShipout}{%
1081 }{%
1082 \AtNextShipout{\AtBegShi@GetBoxSize\@cclv}%
1083 }%
1084 \AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox
1085 \fi
1086 \fi
1087 }
1088 % \end{macrocode}
1089 % \end{macro}
1090 %
1091 % \begin{macro}{\AtBegShi@GetBoxSize}
1092 % \begin{macrocode}
1093 \def\AtBegShi@GetBoxSize#1{%
1094 \xdef\AtBeginShipoutBoxWidth{\the\wd#1}%
1095 \xdef\AtBeginShipoutBoxHeight{\the\ht#1}%
1096 \xdef\AtBeginShipoutBoxDepth{\the\dp#1}%
1097 }
1098 % \end{macrocode}
1099 % \end{macro}
1100 % \begin{macro}{\AtBeginShipoutBoxWidth}
1101 % \begin{macrocode}
1102 \def\AtBeginShipoutBoxWidth{0pt}
1103 % \end{macrocode}
1104 % \end{macro}
1105 % \begin{macro}{\AtBeginShipoutBoxHeight}
1106 % \begin{macrocode}
1107 \def\AtBeginShipoutBoxHeight{0pt}
1108 % \end{macrocode}
1109 % \end{macro}
1110 % \begin{macro}{\AtBeginShipoutBoxDepth}
1111 % \begin{macrocode}
1112 \def\AtBeginShipoutBoxDepth{0pt}
1113 % \end{macrocode}
1114 % \end{macro}
1115 %
1116 % \begin{macrocode}
1117 \catcode`\X=11 %
1118 \catcode`\E=11 %
1119 % \end{macrocode}
1120 %
1121 % \begin{macro}{\AtBegShi@First}
1122 % \begin{macrocode}
1123 \def\AtBegShi@First{%
1124 \ifx\AtBegShi@HookFirst\ltx@empty
1125 \else
1126 \AtBeginShipoutAddToBox{\AtBegShi@HookFirst}%
1127 \fi
1128 \global\let\AtBegShi@First\ltx@empty
1129 \global\let\AtBeginShipoutFirst\AtBegShi@FirstDisabled
1130 }
1131 % \end{macrocode}
1132 % \end{macro}
1133 %
1134 % \begin{macro}{\AtBegShi@Hook}
1135 % \begin{macrocode}
1136 \gdef\AtBegShi@Hook{}
1137 % \end{macrocode}
1138 % \end{macro}
1139 % \begin{macro}{\AtBegShi@HookNext}
1140 % \begin{macrocode}
1141 \gdef\AtBegShi@HookNext{}
1142 % \end{macrocode}
1143 % \end{macro}
1144 % \begin{macro}{\AtBegShi@HookFirst}
1145 % \begin{macrocode}
1146 \gdef\AtBegShi@HookFirst{}
1147 % \end{macrocode}
1148 % \end{macro}
1149 % \begin{macro}{\AtBeginShipout}
1150 % \begin{macrocode}
1151 \AtBegShi@CheckDefinable\AtBeginShipout
1152 \def\AtBeginShipout{%
1153 \AtBegShi@AddHook\AtBegShi@Hook
1154 }
1155 % \end{macrocode}
1156 % \end{macro}
1157 % \begin{macro}{\AtBeginShipoutNext}
1158 % \begin{macrocode}
1159 \AtBegShi@CheckDefinable\AtBeginShipoutNext
1160 \def\AtBeginShipoutNext{%
1161 \AtBegShi@AddHook\AtBegShi@HookNext
1162 }
1163 % \end{macrocode}
1164 % \end{macro}
1165 % \begin{macro}{\AtBeginShipoutFirst}
1166 % \begin{macrocode}
1167 \AtBegShi@CheckDefinable\AtBeginShipoutFirst
1168 \def\AtBeginShipoutFirst{%
1169 \AtBegShi@AddTo\AtBegShi@HookFirst
1170 }
1171 % \end{macrocode}
1172 % \end{macro}
1173 % \begin{macro}{\AtBegShi@FirstDisabled}
1174 % \begin{macrocode}
1175 \long\def\AtBegShi@FirstDisabled#1{%
1176 \@PackageWarning{atbegshi}{%
1177 First page is already shipped out, ignoring\MessageBreak
1178 \string\AtBeginShipoutFirst
1179 }%
1180 }
1181 % \end{macrocode}
1182 % \end{macro}
1183 %
1184 % \begin{macro}{\AtBegShi@AddTo}
1185 % \begin{macrocode}
1186 \begingroup\expandafter\expandafter\expandafter\endgroup
1187 \expandafter\ifx\csname g@addto@macro\endcsname\relax
1188 \long\def\AtBegShi@AddTo#1#2{%
1189 \begingroup
1190 \toks\ltx@zero\expandafter{#1#2}%
1191 \xdef#1{\the\toks\ltx@zero}%
1192 \endgroup
1193 }%
1194 \else
1195 \let\AtBegShi@AddTo\g@addto@macro
1196 \fi
1197 % \end{macrocode}
1198 % \end{macro}
1199 %
1200 % \begin{macro}{\AtBegShi@AddHook}
1201 % \begin{macrocode}
1202 \long\def\AtBegShi@AddHook#1#2{%
1203 \AtBegShi@AddTo#1{\AtBegShi@Item{#2}}%
1204 }
1205 % \end{macrocode}
1206 % \end{macro}
1207 %
1208 % \begin{macro}{\AtBegShi@Item}
1209 % \begin{macrocode}
1210 \long\def\AtBegShi@Item#1{%
1211 \ifAtBegShi@Discarded
1212 \else
1213 #1%
1214 \ifAtBegShi@Discarded
1215 \else
1216 \ifvoid\AtBeginShipoutBox
1217 \@PackageWarning{atbegshi}{%
1218 Shipout box was voided by hook,\MessageBreak
1219 ignoring shipout box%
1220 }%
1221 \AtBeginShipoutDiscard
1222 \fi
1223 \fi
1224 \fi
1225 }
1226 % \end{macrocode}
1227 % \end{macro}
1228 %
1229 % \begin{macro}{\AtBeginShipoutInit}
1230 % \begin{macrocode}
1231 \AtBegShi@CheckDefinable\AtBeginShipoutInit
1232 \def\AtBeginShipoutInit{%
1233 \ltx@IfUndefined{newbox}{%
1234 \@PackageError{atbegshi}{%
1235 \string\AtBeginShipoutInit\space failed\MessageBreak
1236 because of missing \expandafter\string\csname newbox\endcsname
1237 }\@ehc
1238 }{%
1239 \csname newbox\endcsname\AtBeginShipoutBox
1240 \AtBegShi@CheckDefinable\AtBeginShipoutOriginalShipout
1241 \global\let\AtBeginShipoutOriginalShipout\shipout
1242 \global\let\shipout\AtBegShi@Shipout
1243 }%
1244 \gdef\AtBeginShipoutInit{}%
1245 }
1246 % \end{macrocode}
1247 % \end{macro}
1248 % \begin{macrocode}
1249 \begingroup\expandafter\expandafter\expandafter\endgroup
1250 \expandafter\ifx\csname AtBeginDocument\endcsname\relax
1251 \AtBeginShipoutInit
1252 \else
1253 \AtBeginDocument{\AtBeginShipoutInit}%
1254 \fi
1255 % \end{macrocode}
1256 %
1257 % \subsection{Additions to the shipout box}
1258 %
1259 % \begin{macro}{\AtBeginShipoutAddToBox}
1260 % \begin{macrocode}
1261 \def\AtBeginShipoutAddToBox#1{%
1262 \ifhbox\AtBeginShipoutBox
1263 \edef\AtBegShi@restore{%
1264 \hfuzz=\the\hfuzz\relax
1265 \hbadness=\the\hbadness\relax
1266 }%
1267 \hfuzz=1073741823sp\relax
1268 \hbadness=2147483647\relax
1269 \setbox\AtBeginShipoutBox=\hbox to \wd\AtBeginShipoutBox{%
1270 \setbox\ltx@zero=\hbox{%
1271 \begingroup
1272 \AtBegShi@restore
1273 #1%
1274 \endgroup
1275 }%
1276 \wd\ltx@zero=0pt\relax
1277 \ht\ltx@zero=0pt\relax
1278 \dp\ltx@zero=0pt\relax
1279 \raise\ht\AtBeginShipoutBox\copy\ltx@zero
1280 \unhcopy\AtBeginShipoutBox
1281 }%
1282 \AtBegShi@restore
1283 \else
1284 \ifvbox\AtBeginShipoutBox
1285 \edef\AtBegShi@restore{%
1286 \vfuzz=\the\vfuzz\relax
1287 \vbadness=\the\vbadness\relax
1288 \dimen\ltx@zero=\the\dimen\ltx@zero\relax
1289 }%
1290 \edef\AtBegShi@restorebox{%
1291 \ht\AtBeginShipoutBox=\the\ht\AtBeginShipoutBox\relax
1292 \dp\AtBeginShipoutBox=\the\dp\AtBeginShipoutBox\relax
1293 }%
1294 \vfuzz=1073741823sp\relax
1295 \vbadness=2147483647\relax
1296 \dimen\ltx@zero=\ht\AtBeginShipoutBox
1297 \advance\dimen\ltx@zero by \dp\AtBeginShipoutBox
1298 \setbox\AtBeginShipoutBox=\vbox to \dimen\ltx@zero{%
1299 \setbox\ltx@zero=\hbox{%
1300 \begingroup
1301 \AtBegShi@restore
1302 #1%
1303 \endgroup
1304 }%
1305 \wd\ltx@zero=0pt\relax
1306 \ht\ltx@zero=0pt\relax
1307 \dp\ltx@zero=0pt\relax
1308 \baselineskip=0pt\relax
1309 \lineskip=0pt\relax
1310 \lineskiplimit=0pt\relax
1311 \copy\ltx@zero
1312 \unvbox\AtBeginShipoutBox
1313 \kern0pt%
1314 }%
1315 \AtBegShi@restore
1316 \AtBegShi@restorebox
1317 \fi
1318 \fi
1319 }
1320 % \end{macrocode}
1321 % \end{macro}
1322 %
1323 % \begin{macro}{\AtBeginShipoutAddToBoxForeground}
1324 % \begin{macrocode}
1325 \def\AtBeginShipoutAddToBoxForeground#1{%
1326 \ifhbox\AtBeginShipoutBox
1327 \edef\AtBegShi@restore{%
1328 \hfuzz=\the\hfuzz\relax
1329 \hbadness=\the\hbadness\relax
1330 }%
1331 \hfuzz=1073741823sp\relax
1332 \hbadness=2147483647\relax
1333 \setbox\AtBeginShipoutBox=\hbox to \wd\AtBeginShipoutBox{%
1334 \unhcopy\AtBeginShipoutBox
1335 \kern-\wd\AtBeginShipoutBox
1336 \setbox\ltx@zero=\hbox{%
1337 \begingroup
1338 \AtBegShi@restore
1339 #1%
1340 \endgroup
1341 }%
1342 \wd\ltx@zero=0pt\relax
1343 \ht\ltx@zero=0pt\relax
1344 \dp\ltx@zero=0pt\relax
1345 \raise\ht\AtBeginShipoutBox\copy\ltx@zero
1346 \kern\wd\AtBeginShipoutBox
1347 }%
1348 \AtBegShi@restore
1349 \else
1350 \ifvbox\AtBeginShipoutBox
1351 \edef\AtBegShi@restore{%
1352 \vfuzz=\the\vfuzz\relax
1353 \vbadness=\the\vbadness\relax
1354 \dimen\ltx@zero=\the\dimen\ltx@zero\relax
1355 }%
1356 \edef\AtBegShi@restorebox{%
1357 \ht\AtBeginShipoutBox=\the\ht\AtBeginShipoutBox\relax
1358 \dp\AtBeginShipoutBox=\the\dp\AtBeginShipoutBox\relax
1359 }%
1360 \vfuzz=1073741823sp\relax
1361 \vbadness=2147483647\relax
1362 \dimen\ltx@zero=\ht\AtBeginShipoutBox
1363 \advance\dimen\ltx@zero by \dp\AtBeginShipoutBox
1364 \setbox\AtBeginShipoutBox=\vbox to \dimen\ltx@zero{%
1365 \setbox\ltx@zero=\hbox{%
1366 \begingroup
1367 \AtBegShi@restore
1368 #1%
1369 \endgroup
1370 }%
1371 \wd\ltx@zero=0pt\relax
1372 \ht\ltx@zero=0pt\relax
1373 \dp\ltx@zero=0pt\relax
1374 \baselineskip=0pt\relax
1375 \lineskip=0pt\relax
1376 \lineskiplimit=0pt\relax
1377 \unvbox\AtBeginShipoutBox
1378 \kern-\dimen\ltx@zero
1379 \copy\ltx@zero
1380 \kern\dimen\ltx@zero
1381 }%
1382 \AtBegShi@restore
1383 \AtBegShi@restorebox
1384 \fi
1385 \fi
1386 }
1387 % \end{macrocode}
1388 % \end{macro}
1389 %
1390 % \subsection{Positioning}
1391 %
1392 % \begin{macrocode}
1393 \begingroup\expandafter\expandafter\expandafter\endgroup
1394 \expandafter\ifx\csname RequirePackage\endcsname\relax
1395 \def\TMP@RequirePackage#1[#2]{%
1396 \begingroup\expandafter\expandafter\expandafter\endgroup
1397 \expandafter\ifx\csname ver@#1.sty\endcsname\relax
1398 \input #1.sty\relax
1399 \fi
1400 }%
1401 \TMP@RequirePackage{iftex}[2019/11/07]%
1402 \else
1403 \RequirePackage{iftex}[2019/11/07]%
1404 \fi
1405 % \end{macrocode}
1406 %
1407 % \begin{macrocode}
1408 \ifpdf
1409 \def\AtBegShi@horigin{%
1410 \ifx\pdfhorigin\@undefined\pdfvariable horigin\else\pdfhorigin\fi}%
1411 \def\AtBegShi@vorigin{%
1412 \ifx\pdfvorigin\@undefined\pdfvariable vorigin\else\pdfvorigin\fi}%
1413 \else
1414 \def\AtBegShi@horigin{72.27pt}%
1415 \def\AtBegShi@vorigin{72.27pt}%
1416 \fi
1417 % \end{macrocode}
1418 %
1419 % \begin{macrocode}
1420 \begingroup
1421 \ifcase
1422 \expandafter\ifx\csname picture\endcsname\relax
1423 1%
1424 \else
1425 \expandafter\ifx\csname endpicture\endcsname\relax
1426 1%
1427 \else
1428 0%
1429 \fi
1430 \fi
1431 \endgroup
1432 \def\AtBegShi@BeginPicture{%
1433 \begingroup
1434 \picture(0,0)\relax
1435 \begingroup\expandafter\expandafter\expandafter\endgroup
1436 \expandafter\ifx\csname unitlength\endcsname\relax
1437 \else
1438 \unitlength=1pt\relax
1439 \fi
1440 \ignorespaces
1441 }%
1442 \def\AtBegShi@EndPicture{%
1443 \endpicture
1444 \endgroup
1445 }%
1446 \else
1447 \endgroup
1448 \def\AtBegShi@BeginPicture{%
1449 \setbox\ltx@zero=\hbox\bgroup
1450 \begingroup
1451 \ignorespaces
1452 }%
1453 \def\AtBegShi@EndPicture{%
1454 \endgroup
1455 \egroup
1456 \ht\ltx@zero=0pt\relax
1457 \dp\ltx@zero=0pt\relax
1458 \copy\ltx@zero
1459 }%
1460 \fi
1461 % \end{macrocode}
1462 %
1463 % \begin{macro}{\AtBeginShipoutUpperLeft}
1464 % A surrounding \cs{rlap} is not necessary, because
1465 % the stuff is put in an \cs{hbox} with zero width.
1466 % \begin{macrocode}
1467 \def\AtBeginShipoutUpperLeft#1{%
1468 \AtBeginShipoutAddToBox{%
1469 \kern-\AtBegShi@horigin\relax
1470 \vbox to 0pt{%
1471 \kern-\AtBegShi@vorigin\relax
1472 \AtBegShi@BeginPicture
1473 #1%
1474 \AtBegShi@EndPicture
1475 \vss
1476 }%
1477 }%
1478 }
1479 % \end{macrocode}
1480 % \end{macro}
1481 %
1482 % \begin{macro}{\AtBeginShipoutUpperLeftForeground}
1483 % \begin{macrocode}
1484 \def\AtBeginShipoutUpperLeftForeground#1{%
1485 \AtBeginShipoutAddToBoxForeground{%
1486 \kern-\AtBegShi@horigin\relax
1487 \vbox to 0pt{%
1488 \kern-\AtBegShi@vorigin\relax
1489 \AtBegShi@BeginPicture
1490 #1%
1491 \AtBegShi@EndPicture
1492 \vss
1493 }%
1494 }%
1495 }
1496 % \end{macrocode}
1497 % \end{macro}
1498 %
1499 % \subsection{Patches}
1500 %
1501 % Patches for \LaTeX\ packages that redefine \cs{shipout}.
1502 % \LaTeX\ is now supposed to use \eTeX. Thus we do not patch,
1503 % without \LaTeX\ and \eTeX.
1504 % \begin{macrocode}
1505 \def\AtBegShi@AbortIfUndefined#1{%
1506 \begingroup\expandafter\expandafter\expandafter\endgroup
1507 \expandafter\ifx\csname#1\endcsname\relax
1508 \expandafter\AtBegShi@AtEnd
1509 \fi
1510 }
1511 \AtBegShi@AbortIfUndefined{currentgrouplevel}%
1512 \AtBegShi@AbortIfUndefined{AtBeginDocument}%
1513 \AtBegShi@AbortIfUndefined{@ifpackageloaded}%
1514 \AtBegShi@AbortIfUndefined{@ifclassloaded}%
1515 % \end{macrocode}
1516 %
1517 % \subsubsection{Package \xpackage{crop}}
1518 %
1519 % Fix of method and box.
1520 % \begin{macrocode}
1521 \def\AtBegShi@PatchCrop{%
1522 \begingroup
1523 \def\AtBegShi@Crop@shipout{%
1524 \afterassignment\CROP@ship
1525 \setbox\@cclv=%
1526 }%
1527 \def\AtBegShi@Crop@ship{%
1528 \ifvoid\@cclv
1529 \expandafter\aftergroup
1530 \fi
1531 \CROP@@ship
1532 }%
1533 \def\AtBegShi@Crop@shiplist{%
1534 \lineskip\z@
1535 \lineskiplimit\z@
1536 \baselineskip\z@
1537 \CROP@kernel
1538 \box\@cclv
1539 }%
1540 \def\AtBegShi@Crop@@ship{%
1541 \CROP@shipout\vbox{%
1542 \CROP@shiplist
1543 }%
1544 }%
1545 \ifx\AtBegShi@Crop@ship\CROP@ship
1546 \ifx\AtBegShi@Crop@shiplist\CROP@shiplist
1547 \ifx\AtBegShi@Crop@@ship\CROP@@ship
1548 \let\AtBegShi@found\relax
1549 \ifx\shipout\AtBegShi@Crop@shipout
1550 \def\AtBegShi@found{\shipout}%
1551 \else\ifx\AtBeginShipoutOriginalShipout\AtBegShi@Crop@shipout
1552 \def\AtBegShi@found{\AtBeginShipoutOriginalShipout}%
1553 \else\ifx\@EveryShipout@Org@Shipout\AtBegShi@Crop@shipout
1554 \def\AtBegShi@found{\@EveryShipout@Org@Shipout}%
1555 \else\ifx\GPTorg@shipout\AtBegShi@Crop@shipout
1556 \def\AtBegShi@found{\GPTorg@shipout}%
1557 \else\ifx\THBorg@shipout\AtBegShi@Crop@shipout
1558 \def\AtBegShi@found{\THBorg@shipout}%
1559 \else\ifx\mem@oldshipout\AtBegShi@Crop@shipout
1560 \def\AtBegShi@found{\mem@oldshipout}%
1561 \fi\fi\fi\fi\fi\fi
1562 \ifx\AtBegShi@found\relax
1563 \else
1564 \expandafter\endgroup
1565 \expandafter\def\AtBegShi@found{%
1566 \edef\AtBegShi@GroupLevel{\number\currentgrouplevel}%
1567 \afterassignment\CROP@ship
1568 \setbox\AtBeginShipoutBox=%
1569 }%
1570 \def\CROP@ship{%
1571 \ifnum\AtBegShi@GroupLevel=\currentgrouplevel
1572 \else
1573 \expandafter\aftergroup
1574 \fi
1575 \CROP@@ship
1576 }%
1577 \def\CROP@shiplist{%
1578 \lineskip 0pt\relax
1579 \lineskiplimit 0pt\relax
1580 \baselineskip 0pt\relax
1581 \CROP@kernel
1582 \box\AtBeginShipoutBox
1583 }%
1584 \def\CROP@@ship{%
1585 \ifvoid\AtBeginShipoutBox
1586 \else
1587 \setbox\AtBeginShipoutBox=\vbox{%
1588 \CROP@shiplist
1589 }%
1590 \AtBegShi@GetBoxSize\AtBeginShipoutBox
1591 \expandafter\CROP@shipout
1592 \expandafter\box
1593 \expandafter\AtBeginShipoutBox
1594 \fi
1595 }%
1596 \@PackageInfoNoLine{atbegshi}{Package `crop' patched}%
1597 \begingroup
1598 \fi
1599 \fi
1600 \fi
1601 \fi
1602 \endgroup
1603 \let\AtBegShi@PatchCrop\relax
1604 }
1605 \@ifpackageloaded{crop}{%
1606 \AtBegShi@PatchCrop
1607 }{%
1608 \AtBeginDocument{\AtBegShi@PatchCrop}%
1609 }
1610 % \end{macrocode}
1611 %
1612 % \subsubsection{Package \xpackage{everyshi}}
1613 %
1614 % Fix of method. Use of box 255 is not changed.
1615 % \begin{macrocode}
1616 \def\AtBegShi@PatchEveryshi{%
1617 \begingroup
1618 \long\def\AtBegShi@Everyshi@shipout{%
1619 \afterassignment\@EveryShipout@Test
1620 \global\setbox\@cclv= %
1621 }%
1622 \long\def\AtBegShi@Everyshi@Test{%
1623 \ifvoid\@cclv\relax
1624 \aftergroup\@EveryShipout@Output
1625 \else
1626 \@EveryShipout@Output
1627 \fi
1628 }%
1629 \ifx\AtBegShi@Everyshi@Test\@EveryShipout@Test
1630 \let\AtBegShi@found\relax
1631 \ifx\shipout\AtBegShi@Everyshi@shipout
1632 \def\AtBegShi@found{\shipout}%
1633 \else\ifx\AtBeginShipoutOriginalShipout\AtBegShi@Everyshi@shipout
1634 \def\AtBegShi@found{\AtBeginShipoutOriginalShipout}%
1635 \else\ifx\CROP@shipout\AtBegShi@Everyshi@shipout
1636 \def\AtBegShi@found{\CROP@shipout}%
1637 \else\ifx\GPTorg@shipout\AtBegShi@Everyshi@shipout
1638 \def\AtBegShi@found{\GPTorg@shipout}%
1639 \else\ifx\THBorg@shipout\AtBegShi@Everyshi@shipout
1640 \def\AtBegShi@found{\THBorg@shipout}%
1641 \else\ifx\mem@oldshipout\AtBegShi@Everyshi@shipout
1642 \def\AtBegShi@found{\mem@oldshipout}%
1643 \else
1644 \expandafter\ifx\csname @EveryShipout@Org@Shipout\endcsname
1645 \relax
1646 \ifx\@EveryShipout@Shipout\AtBegShi@Everyshi@shipout
1647 \def\AtBegShi@found{\@EveryShipout@Shipout}%
1648 \fi
1649 \fi
1650 \fi\fi\fi\fi\fi\fi
1651 \ifx\AtBegShi@found\relax
1652 \else
1653 \expandafter\endgroup
1654 \expandafter\def\AtBegShi@found{%
1655 \edef\AtBegShi@GroupLevel{\number\currentgrouplevel}%
1656 \afterassignment\@EveryShipout@Test
1657 \setbox\AtBeginShipoutBox=%
1658 }%
1659 \def\@EveryShipout@Test{%
1660 \ifnum\AtBegShi@GroupLevel=\currentgrouplevel
1661 \else
1662 \expandafter\aftergroup
1663 \fi
1664 \AtBegShi@Everyshi@Output
1665 }%
1666 \def\AtBegShi@Everyshi@Output{%
1667 \ifvoid\AtBeginShipoutBox
1668 \else
1669 \global\setbox\ltx@cclv\box\AtBeginShipoutBox
1670 \expandafter\@EveryShipout@Output
1671 \fi
1672 }%
1673 \@PackageInfoNoLine{atbegshi}{Package `everyshi' patched}%
1674 \begingroup
1675 \fi
1676 \fi
1677 \endgroup
1678 \let\AtBegShi@PatchEveryshi\relax
1679 }
1680 \@ifpackageloaded{everyshi}{%
1681 \AtBegShi@PatchEveryshi
1682 }{%
1683 \AtBeginDocument{\AtBegShi@PatchEveryshi}%
1684 }
1685 % \end{macrocode}
1686 %
1687 % \subsubsection{Class \xpackage{memoir}}
1688 %
1689 % Fix of method and box.
1690 % \begin{macrocode}
1691 \def\AtBegShi@PatchMemoir{%
1692 \begingroup
1693 \def\AtBegShi@Memoir@shipout{%
1694 \afterassignment\mem@shipi
1695 \setbox\@cclv=%
1696 }%
1697 \def\AtBegShi@Memoir@shipi{%
1698 \ifvoid\@cclv
1699 \expandafter\aftergroup
1700 \fi
1701 \mem@shipii
1702 }%
1703 \def\AtBegShi@Memoir@shipiiA{%
1704 \mem@oldshipout\vbox{%
1705 \trimmarks
1706 \unvbox\@cclv
1707 }%
1708 }%
1709 \def\AtBegShi@Memoir@shipiiB{%
1710 \ifvoid\@cclv
1711 \mem@oldshipout\box\@cclv
1712 \else
1713 \mem@oldshipout\vbox{%
1714 \trimmarks
1715 \unvbox\@cclv
1716 }%
1717 \fi
1718 }%
1719 \def\AtBegShi@Memoir@PatchAB{%
1720 \ifvoid\AtBeginShipoutBox
1721 \else
1722 \setbox\AtBeginShipoutBox=\vbox{%
1723 \trimmarks
1724 \ifvbox\AtBeginShipoutBox
1725 \unvbox\AtBeginShipoutBox
1726 \else
1727 \box\AtBeginShipoutBox
1728 \fi
1729 }%
1730 \AtBegShi@GetBoxSize\AtBeginShipoutBox
1731 \expandafter\mem@oldshipout
1732 \expandafter\box
1733 \expandafter\AtBeginShipoutBox
1734 \fi
1735 }%
1736 \def\AtBegShi@Memoir@shipiiC{% 2008/08/07 v1.6180339a
1737 \ifvoid\@cclv
1738 \mem@oldshipout\box\@cclv
1739 \else
1740 \ifshowtrims
1741 \mem@oldshipout\vbox{\trimmarks\unvbox\@cclv}%
1742 \else
1743 \mem@oldshipout\box\@cclv
1744 \fi
1745 \fi
1746 }%
1747 \def\AtBegShi@Memoir@shipiiD{% 2011/03/06 v3.6j
1748 \ifvoid\@cclv
1749 \mem@oldshipout\box\@cclv
1750 \else
1751 \ifshowtrims
1752 \mem@oldshipout\vbox{%
1753 \trimmarks
1754 \nointerlineskip
1755 \box\@cclv
1756 }%
1757 \else
1758 \mem@oldshipout\box\@cclv
1759 \fi
1760 \fi
1761 }%
1762 \def\AtBegShi@Memoir@PatchCD{%
1763 \ifvoid\AtBeginShipoutBox
1764 \else
1765 \ifshowtrims
1766 \setbox\AtBeginShipoutBox=\vbox{%
1767 \trimmarks
1768 \nointerlineskip
1769 \box\AtBeginShipoutBox
1770 }%
1771 \fi
1772 \AtBegShi@GetBoxSize\AtBeginShipoutBox
1773 \expandafter\mem@oldshipout
1774 \expandafter\box
1775 \expandafter\AtBeginShipoutBox
1776 \fi
1777 }%
1778 \ifx\AtBegShi@Memoir@shipi\mem@shipi
1779 \let\AtBegShi@found\ltx@one
1780 \ifx\AtBegShi@Memoir@shipiiA\mem@shipii
1781 \let\AtBegShi@found\ltx@zero
1782 \global\let\AtBegShi@Memoir@PatchX\AtBegShi@Memoir@PatchAB
1783 \else\ifx\AtBegShi@Memoir@shipiiB\mem@shipii
1784 \let\AtBegShi@found\ltx@zero
1785 \global\let\AtBegShi@Memoir@PatchX\AtBegShi@Memoir@PatchAB
1786 \else\ifx\AtBegShi@Memoir@shipiiC\mem@shipii
1787 \let\AtBegShi@found\ltx@zero
1788 \global\let\AtBegShi@Memoir@PatchX\AtBegShi@Memoir@PatchCD
1789 \else\ifx\AtBegShi@Memoir@shipiiD\mem@shipii
1790 \let\AtBegShi@found\ltx@zero
1791 \global\let\AtBegShi@Memoir@PatchX\AtBegShi@Memoir@PatchCD
1792 \fi\fi\fi\fi
1793 \ifcase\AtBegShi@found
1794 \let\AtBegShi@found\relax
1795 \ifx\shipout\AtBegShi@Memoir@shipout
1796 \def\AtBegShi@found{\shipout}%
1797 \else\ifx\AtBeginShipoutOriginalShipout\AtBegShi@Memoir@shipout
1798 \def\AtBegShi@found{\AtBeginShipoutOriginalShipout}%
1799 \else\ifx\CROP@shipout\AtBegShi@Memoir@shipout
1800 \def\AtBegShi@found{\CROP@shipout}%
1801 \else\ifx\GPTorg@shipout\AtBegShi@Memoir@shipout
1802 \def\AtBegShi@found{\GPTorg@shipout}%
1803 \else\ifx\THBorg@shipout\AtBegShi@Memoir@shipout
1804 \def\AtBegShi@found{\THBorg@shipout}%
1805 \else\ifx\@EveryShipout@Org@Shipout\AtBegShi@Memoir@shipout
1806 \def\AtBegShi@found{\@EveryShipout@Org@Shipout}%
1807 \fi\fi\fi\fi\fi\fi
1808 \ifx\AtBegShi@found\relax
1809 \else
1810 \expandafter\endgroup
1811 \expandafter\def\AtBegShi@found{%
1812 \edef\AtBegShi@GroupLevel{\number\currentgrouplevel}%
1813 \afterassignment\mem@shipi
1814 \setbox\AtBeginShipoutBox=%
1815 }%
1816 \def\mem@shipi{%
1817 \ifnum\AtBegShi@GroupLevel=\currentgrouplevel
1818 \else
1819 \expandafter\aftergroup
1820 \fi
1821 \mem@shipii
1822 }%
1823 \let\mem@shipii\AtBegShi@Memoir@PatchX
1824 \@PackageInfoNoLine{atbegshi}{Class `memoir' patched}%
1825 \begingroup
1826 \fi
1827 \fi
1828 \fi
1829 \endgroup
1830 \let\AtBegShi@PatchMemoir\relax
1831 }
1832 \@ifclassloaded{memoir}{%
1833 \AtBegShi@PatchMemoir
1834 }{%
1835 \AtBeginDocument{\AtBegShi@PatchMemoir}%
1836 }
1837 % \end{macrocode}
1838 %
1839 % \begin{macrocode}
1840 \AtBegShi@AtEnd%
1841 %</package>
1842 % \end{macrocode}
1843 %% \section{Installation}
1844 %
1845 % \subsection{Download}
1846 %
1847 % \paragraph{Package.} This package is available on
1848 % CTAN\footnote{\CTANpkg{atbegshi}}:
1849 % \begin{description}
1850 % \item[\CTAN{macros/latex/contrib/atbegshi/atbegshi.dtx}] The source file.
1851 % \item[\CTAN{macros/latex/contrib/atbegshi/atbegshi.pdf}] Documentation.
1852 % \end{description}
1853 %
1854 %
1855 % \paragraph{Bundle.} All the packages of the bundle `atbegshi'
1856 % are also available in a TDS compliant ZIP archive. There
1857 % the packages are already unpacked and the documentation files
1858 % are generated. The files and directories obey the TDS standard.
1859 % \begin{description}
1860 % \item[\CTANinstall{install/macros/latex/contrib/atbegshi.tds.zip}]
1861 % \end{description}
1862 % \emph{TDS} refers to the standard ``A Directory Structure
1863 % for \TeX\ Files'' (\CTANpkg{tds}). Directories
1864 % with \xfile{texmf} in their name are usually organized this way.
1865 %
1866 % \subsection{Bundle installation}
1867 %
1868 % \paragraph{Unpacking.} Unpack the \xfile{atbegshi.tds.zip} in the
1869 % TDS tree (also known as \xfile{texmf} tree) of your choice.
1870 % Example (linux):
1871 % \begin{quote}
1872 % |unzip atbegshi.tds.zip -d ~/texmf|
1873 % \end{quote}
1874 %
1875 % \subsection{Package installation}
1876 %
1877 % \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
1878 % \docstrip\ archive. The files are extracted by running the
1879 % \xfile{.dtx} through \plainTeX:
1880 % \begin{quote}
1881 % \verb|tex atbegshi.dtx|
1882 % \end{quote}
1883 %
1884 % \paragraph{TDS.} Now the different files must be moved into
1885 % the different directories in your installation TDS tree
1886 % (also known as \xfile{texmf} tree):
1887 % \begin{quote}
1888 % \def\t{^^A
1889 % \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
1890 % atbegshi.sty & tex/generic/atbegshi/atbegshi.sty\\
1891 % atbegshi.pdf & doc/latex/atbegshi/atbegshi.pdf\\
1892 % atbegshi-example1.tex & doc/latex/atbegshi/atbegshi-example1.tex\\
1893 % atbegshi-example2.tex & doc/latex/atbegshi/atbegshi-example2.tex\\
1894 % atbegshi.dtx & source/latex/atbegshi/atbegshi.dtx\\
1895 % \end{tabular}^^A
1896 % }^^A
1897 % \sbox0{\t}^^A
1898 % \ifdim\wd0>\linewidth
1899 % \begingroup
1900 % \advance\linewidth by\leftmargin
1901 % \advance\linewidth by\rightmargin
1902 % \edef\x{\endgroup
1903 % \def\noexpand\lw{\the\linewidth}^^A
1904 % }\x
1905 % \def\lwbox{^^A
1906 % \leavevmode
1907 % \hbox to \linewidth{^^A
1908 % \kern-\leftmargin\relax
1909 % \hss
1910 % \usebox0
1911 % \hss
1912 % \kern-\rightmargin\relax
1913 % }^^A
1914 % }^^A
1915 % \ifdim\wd0>\lw
1916 % \sbox0{\small\t}^^A
1917 % \ifdim\wd0>\linewidth
1918 % \ifdim\wd0>\lw
1919 % \sbox0{\footnotesize\t}^^A
1920 % \ifdim\wd0>\linewidth
1921 % \ifdim\wd0>\lw
1922 % \sbox0{\scriptsize\t}^^A
1923 % \ifdim\wd0>\linewidth
1924 % \ifdim\wd0>\lw
1925 % \sbox0{\tiny\t}^^A
1926 % \ifdim\wd0>\linewidth
1927 % \lwbox
1928 % \else
1929 % \usebox0
1930 % \fi
1931 % \else
1932 % \lwbox
1933 % \fi
1934 % \else
1935 % \usebox0
1936 % \fi
1937 % \else
1938 % \lwbox
1939 % \fi
1940 % \else
1941 % \usebox0
1942 % \fi
1943 % \else
1944 % \lwbox
1945 % \fi
1946 % \else
1947 % \usebox0
1948 % \fi
1949 % \else
1950 % \lwbox
1951 % \fi
1952 % \else
1953 % \usebox0
1954 % \fi
1955 % \end{quote}
1956 % If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
1957 % TDS installing feature, then some files can already be in the right
1958 % place, see the documentation of \docstrip.
1959 %
1960 % \subsection{Refresh file name databases}
1961 %
1962 % If your \TeX~distribution
1963 % (\TeX\,Live, \mikTeX, \dots) relies on file name databases, you must refresh
1964 % these. For example, \TeX\,Live\ users run \verb|texhash| or
1965 % \verb|mktexlsr|.
1966 %
1967 % \subsection{Some details for the interested}
1968 %
1969 % \paragraph{Unpacking with \LaTeX.}
1970 % The \xfile{.dtx} chooses its action depending on the format:
1971 % \begin{description}
1972 % \item[\plainTeX:] Run \docstrip\ and extract the files.
1973 % \item[\LaTeX:] Generate the documentation.
1974 % \end{description}
1975 % If you insist on using \LaTeX\ for \docstrip\ (really,
1976 % \docstrip\ does not need \LaTeX), then inform the autodetect routine
1977 % about your intention:
1978 % \begin{quote}
1979 % \verb|latex \let\install=y\input{atbegshi.dtx}|
1980 % \end{quote}
1981 % Do not forget to quote the argument according to the demands
1982 % of your shell.
1983 %
1984 % \paragraph{Generating the documentation.}
1985 % You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
1986 % the documentation. The process can be configured by the
1987 % configuration file \xfile{ltxdoc.cfg}. For instance, put this
1988 % line into this file, if you want to have A4 as paper format:
1989 % \begin{quote}
1990 % \verb|\PassOptionsToClass{a4paper}{article}|
1991 % \end{quote}
1992 % An example follows how to generate the
1993 % documentation with pdf\LaTeX:
1994 % \begin{quote}
1995 %\begin{verbatim}
1996 %pdflatex atbegshi.dtx
1997 %makeindex -s gind.ist atbegshi.idx
1998 %pdflatex atbegshi.dtx
1999 %makeindex -s gind.ist atbegshi.idx
2000 %pdflatex atbegshi.dtx
2001 %\end{verbatim}
2002 % \end{quote}
2003 %
2004 % \begin{History}
2005 % \begin{Version}{2007/04/17 v1.0}
2006 % \item
2007 % First version.
2008 % \end{Version}
2009 % \begin{Version}{2007/04/18 v1.1}
2010 % \item
2011 % New method based on \cs{lastkern} is used if \eTeX\ is missing.
2012 % \item
2013 % \cs{AtBeginShipoutDiscard} also resets \cs{deadcycles}.
2014 % \end{Version}
2015 % \begin{Version}{2007/04/19 v1.2}
2016 % \item
2017 % \cs{AtBeginShipoutEarly} removed for simplification reasons.
2018 % \item
2019 % Forgotten definition of \cs{AtBegShi@Info} added.
2020 % \item
2021 % Patches for packages \xpackage{crop} and \xpackage{everyshi}
2022 % and class \xclass{memoir} added.
2023 % \end{Version}
2024 % \begin{Version}{2007/04/26 v1.3}
2025 % \item
2026 % Use of package \xpackage{infwarerr}.
2027 % \item
2028 % Catcode section after generic header.
2029 % \end{Version}
2030 % \begin{Version}{2007/04/27 v1.4}
2031 % \item
2032 % Small optimizations.
2033 % \end{Version}
2034 % \begin{Version}{2007/06/06 v1.5}
2035 % \item
2036 % \cs{AtBeginShipoutUpperLeft} added.
2037 % \item
2038 % Example added.
2039 % \item
2040 % Fix in second test file for newer version of \xclass{memoir}.
2041 % \end{Version}
2042 % \begin{Version}{2007/09/09 v1.6}
2043 % \item
2044 % Catcode section rewritten.
2045 % \end{Version}
2046 % \begin{Version}{2008/07/18 v1.7}
2047 % \item
2048 % Documentation of \cs{AtBeginShipoutUpperLeft} fixed and extended.
2049 % \end{Version}
2050 % \begin{Version}{2008/07/19 v1.8}
2051 % \item
2052 % \cs{AtBeginShipoutUpperLeftForeground} added.
2053 % \end{Version}
2054 % \begin{Version}{2008/07/31 v1.9}
2055 % \item
2056 % Second example (TrimBox for dvipdfmx) added.
2057 % \item
2058 % No changes in package code.
2059 % \end{Version}
2060 % \begin{Version}{2009/12/02 v1.10}
2061 % \item
2062 % \cs{AtBeginShipoutOriginalShipout} added.
2063 % \item
2064 % Test file fixed.
2065 % \end{Version}
2066 % \begin{Version}{2010/03/01 v1.11}
2067 % \item
2068 % Compatibility with \iniTeX\ except for \cs{newbox}.
2069 % \end{Version}
2070 % \begin{Version}{2010/03/25 v1.12}
2071 % \item
2072 % \cs{AtBeginShipoutNext} can now be used inside
2073 % \cs{AtBeginShipoutNext}.
2074 % \end{Version}
2075 % \begin{Version}{2010/08/18 v1.13}
2076 % \item
2077 % Fixes for \cs{AtBegShi@CheckDefinable}.
2078 % \end{Version}
2079 % \begin{Version}{2010/12/02 v1.14}
2080 % \item
2081 % Remove the warning because of void box if the hook
2082 % calls \AtBeginShipoutDiscard.
2083 % \end{Version}
2084 % \begin{Version}{2011/01/30 v1.15}
2085 % \item
2086 % Already loaded package files are not input in \hologo{plainTeX}.
2087 % \end{Version}
2088 % \begin{Version}{2011/10/05 v1.16}
2089 % \item
2090 % \cs{AtBeginShipoutAddToBox}, \cs{AtBeginShipoutAddToBoxForeground} added.
2091 % \item
2092 % \cs{AtBeginShipoutBoxWidth}, \cs{AtBeginShipoutBoxHeight},
2093 % \cs{AtBeginShipoutBoxDepth} added.
2094 % \item
2095 % Updates for patches of class \xclass{memoir}.
2096 % \end{Version}
2097 % \begin{Version}{2016/05/16 v1.17}
2098 % \item
2099 % Documentation updates.
2100 % \end{Version}
2101 % \begin{Version}{2016/06/09 v1.18}
2102 % \item
2103 % Update for \cs{pdfhorigin} in new LuaTeX.
2104 % \end{Version}
2105 % \begin{Version}{2019/12/05 v1.19}
2106 % \item
2107 % Documentation updates.
2108 % \item
2109 % iftex package.
2110 % \end{Version}
2111 % \end{History}
2112 %
2113 % \PrintIndex
2114 %
2115 % \Finale
2116 \endinput