summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/oberdiek/atbegshi.dtx
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2007-04-22 17:14:12 +0000
committerKarl Berry <karl@freefriends.org>2007-04-22 17:14:12 +0000
commit3a0595042f7a56658ecc4a51fe68f2ab4312bc49 (patch)
tree4a9226c3e5b6e27b47ca17b9afc98b5d1d1d7601 /Master/texmf-dist/source/latex/oberdiek/atbegshi.dtx
parent64e0b27d1ebe077904838f130fc85b3b1981df2b (diff)
atbegshi 1.2 (oberdiek 20apr07)
git-svn-id: svn://tug.org/texlive/trunk@4170 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/oberdiek/atbegshi.dtx')
-rw-r--r--Master/texmf-dist/source/latex/oberdiek/atbegshi.dtx1644
1 files changed, 1644 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/latex/oberdiek/atbegshi.dtx b/Master/texmf-dist/source/latex/oberdiek/atbegshi.dtx
new file mode 100644
index 00000000000..37869feb4c8
--- /dev/null
+++ b/Master/texmf-dist/source/latex/oberdiek/atbegshi.dtx
@@ -0,0 +1,1644 @@
+% \iffalse meta-comment
+%
+% Copyright (C) 2007 by Heiko Oberdiek <oberdiek@uni-freiburg.de>
+%
+% 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 (at your option) 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.
+%
+% This work has the LPPL maintenance status "maintained".
+%
+% This Current Maintainer of this work is Heiko Oberdiek.
+%
+% This work consists of the main source file atbegshi.dtx
+% and the derived files
+% atbegshi.sty, atbegshi.pdf, atbegshi.ins, atbegshi.drv,
+% atbegshi-test1.tex, atbegshi-test2.tex.
+%
+% Distribution:
+% CTAN:macros/latex/contrib/oberdiek/atbegshi.dtx
+% CTAN:macros/latex/contrib/oberdiek/atbegshi.pdf
+%
+% Unpacking:
+% (a) If atbegshi.ins is present:
+% tex atbegshi.ins
+% (b) Without atbegshi.ins:
+% tex atbegshi.dtx
+% (c) If you insist on using LaTeX
+% latex \let\install=y\input{atbegshi.dtx}
+% (quote the arguments according to the demands of your shell)
+%
+% Documentation:
+% (a) If atbegshi.drv is present:
+% latex atbegshi.drv
+% (b) Without atbegshi.drv:
+% latex atbegshi.dtx; ...
+% The class ltxdoc loads the configuration file ltxdoc.cfg
+% if available. Here you can specify further options, e.g.
+% use A4 as paper format:
+% \PassOptionsToClass{a4paper}{article}
+%
+% Programm calls to get the documentation (example):
+% pdflatex atbegshi.dtx
+% makeindex -s gind.ist atbegshi.idx
+% pdflatex atbegshi.dtx
+% makeindex -s gind.ist atbegshi.idx
+% pdflatex atbegshi.dtx
+%
+% Installation:
+% TDS:tex/generic/oberdiek/atbegshi.sty
+% TDS:doc/latex/oberdiek/atbegshi.pdf
+% TDS:doc/latex/oberdiek/atbegshi-test1.tex
+% TDS:doc/latex/oberdiek/atbegshi-test2.tex
+% TDS:source/latex/oberdiek/atbegshi.dtx
+%
+%<*ignore>
+\begingroup
+ \def\x{LaTeX2e}%
+\expandafter\endgroup
+\ifcase 0\ifx\install y1\fi\expandafter
+ \ifx\csname processbatchFile\endcsname\relax\else1\fi
+ \ifx\fmtname\x\else 1\fi\relax
+\else\csname fi\endcsname
+%</ignore>
+%<*install>
+\input docstrip.tex
+\Msg{************************************************************************}
+\Msg{* Installation}
+\Msg{* Package: atbegshi 2007/04/19 v1.2 At begin shipout hook (HO)}
+\Msg{************************************************************************}
+
+\keepsilent
+\askforoverwritefalse
+
+\preamble
+
+This is a generated file.
+
+Copyright (C) 2007 by Heiko Oberdiek <oberdiek@uni-freiburg.de>
+
+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 (at your option) 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.
+
+This work has the LPPL maintenance status "maintained".
+
+This Current Maintainer of this work is Heiko Oberdiek.
+
+This work consists of the main source file atbegshi.dtx
+and the derived files
+ atbegshi.sty, atbegshi.pdf, atbegshi.ins, atbegshi.drv,
+ atbegshi-test1.tex, atbegshi-test2.tex.
+
+\endpreamble
+
+\generate{%
+ \file{atbegshi.ins}{\from{atbegshi.dtx}{install}}%
+ \file{atbegshi.drv}{\from{atbegshi.dtx}{driver}}%
+ \usedir{tex/generic/oberdiek}%
+ \file{atbegshi.sty}{\from{atbegshi.dtx}{package}}%
+ \usedir{doc/latex/oberdiek}%
+ \file{atbegshi-test1.tex}{\from{atbegshi.dtx}{test1}}%
+ \file{atbegshi-test2.tex}{\from{atbegshi.dtx}{test2}}%
+}
+
+\obeyspaces
+\Msg{************************************************************************}
+\Msg{*}
+\Msg{* To finish the installation you have to move the following}
+\Msg{* file into a directory searched by TeX:}
+\Msg{*}
+\Msg{* atbegshi.sty}
+\Msg{*}
+\Msg{* To produce the documentation run the file `atbegshi.drv'}
+\Msg{* through LaTeX.}
+\Msg{*}
+\Msg{* Happy TeXing!}
+\Msg{*}
+\Msg{************************************************************************}
+
+\endbatchfile
+%</install>
+%<*ignore>
+\fi
+%</ignore>
+%<*driver>
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesFile{atbegshi.drv}%
+ [2007/04/19 v1.2 At begin shipout hook (HO)]%
+\documentclass{ltxdoc}
+\usepackage{holtxdoc}
+\begin{document}
+ \DocInput{atbegshi.dtx}%
+\end{document}
+%</driver>
+% \fi
+%
+% \CheckSum{1176}
+%
+% \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 \~}
+%
+% \GetFileInfo{atbegshi.drv}
+%
+% \title{The \xpackage{atbegshi} package}
+% \date{2007/04/19 v1.2}
+% \author{Heiko Oberdiek\\\xemail{oberdiek@uni-freiburg.de}}
+%
+% \maketitle
+%
+% \begin{abstract}
+% This package is a modern reimplementation of package \xpackage{everyshi}
+% without the burden of compatibility. It makes use of \eTeX's if available.
+% Both \LaTeX\ and \plainTeX\ are supported.
+% \end{abstract}
+%
+% \tableofcontents
+%
+% \section{Documentation}
+%
+% Package \xpackage{atbegshi} redefines \cs{shipout} to insert
+% hooks for user code that is executed before the page is shipped out.
+% The code may modify or even discard the output page.
+% Three hooks are implemented:
+% \begin{enumerate}
+% \item A hook that is executed for every page, see\\
+% \cs{AtBeginShipout}
+% \item A hook that is executed for the next page only, see\\
+% \cs{AtBeginShipoutNext}
+% \item A hook that is only executed for the first page, see\\
+% \cs{AtBeginShipoutFirst}
+% \end{enumerate}
+% The hooks are executed in this order. The following three macros
+% provide the user interface for adding code to these hooks:
+%
+% \begin{declcs}{AtBeginShipout} \M{code}
+% \end{declcs}
+% Execute the \meta{code} for every page.
+% The page contents is held in box register \cs{AtBeginShipoutBox}
+% and may be modified. Use \cs{AtBeginShipoutDiscard} if you want to
+% discard the page.
+%
+% \emph{Note:} Package \xpackage{everyshi} uses box register 255. With
+% package \xpackage{atbegshi} you must use \cs{AtBeginShipoutBox} instead.
+%
+% If \LaTeX\ calls \cs{shipout} in \cs{@outputpage} (part of its output
+% routine),
+% the meaning of \cs{protect} is \cs{noexpand}. \LaTeX\ sets
+% \cs{protect} to the appropriate \cs{@typeset@protect} in the box
+% that is shipped out. This is too late for the hooks, they
+% are called earlier in the redefined \cs{shipout}. Therefore
+% package \xpackage{atbegshi} sets \cs{protect} to \cs{@typeset@protect}
+% before it calls the hooks.
+% (In \cs{EveryShipout} of package \xpackage{everyshi} the
+% user is responsible for the correct setting of \cs{protect}.)
+%
+% \begin{declcs}{AtBeginShipoutNext} \M{code}
+% \end{declcs}
+% This reimplements package \xpackage{everyshi}'s \cs{AtNextShipout}.
+% The \meta{code} is executed at shipout time of the next page only.
+% It is just a convenience macro, it can be easily replaced by something
+% like:
+%\begin{quote}
+%\begin{verbatim}
+%\newcommand{\MyShipoutHook}{}%
+%\AtBeginShipout{\MyShipoutHook}
+%\gdef\MyShipoutHook{%
+% ... do something with next page ...
+% \gdef\MyShipoutHook{}%
+% }
+%\end{verbatim}
+%\end{quote}
+% (This can be necessary, if hook order does matter).
+%
+% \begin{declcs}{AtBeginShipoutFirst} \M{code}
+% \end{declcs}
+% This reimplements \LaTeX's \cs{AtBeginDvi}. This hook is
+% usually used for \cs{special} commands that include PostScript
+% header files. The \cs{code} is directly executed in a \cs{vbox}
+% that is put at the beginning of the output page. Dealing with
+% the output box \cs{AtBeginShipoutBox} is not necessary and
+% not permitted here.
+%
+% \begin{declcs}{AtBeginShipoutDiscard}
+% \end{declcs}
+% This macro notifies package \xpackage{atbegshi} that
+% the output page is discarded. The remaining hook code
+% and the remaining hooks are not executed and the page is thrown away.
+% Also \cs{deadcycles} is cleared to zero like an ordinary \cs{shipout}
+% would do.
+%
+% \begin{declcs}{AtBeginShipoutInit}
+% \end{declcs}
+% Usually the redefinition of \cs{shipout} is delayed by
+% \cs{AtBeginDocument} (if this macro exists). This can be
+% too late, if other packages also redefines \cs{shipout}
+% and the order does matter.
+% \cs{AtBeginShipoutInit} forces the immediate redefinition
+% of \cs{shipout}.
+%
+% \section{Method of \cs{shipout} overloading}
+%
+% \subsection{\cs{shipout}}
+%
+% The \TeX\ primitive command \cs{shipout} takes a box specification
+% and puts the box as a new page in the output file.
+% There are two kinds of box specifications:
+% \begin{description}
+% \item[Direct boxes:]
+% They are given by \cs{hbox}, \cs{vbox}, or \cs{vtop},\\
+% e.g. |\shipout\hbox{Hello World}|.
+% \item[Indirect boxes:]
+% \cs{box} or \cs{copy} references a box register by number.
+% The box register contains the contents of the box.
+%
+% \emph{Note:} \cs{box} also clears the box register globally.
+% \end{description}
+% Then we have to differentiate between void and empty boxes:
+% \begin{description}
+% \item[Void:]
+% Initially or after \cs{box} there is no box in the box register.
+% In this cases the box register is not empty, but \emph{void}.
+% \item[Empty:]
+% A box with empty contents, such as
+% |\hbox{}| (= \cs{null}) or |\vbox{}| is an \emph{empty \cs{hbox}}
+% or \emph{empty \cs{vbox}}. If a box register holds such a
+% box, the box still exists, therefore the box register is
+% \emph{not void}.
+% \end{description}
+%
+% \subsection{\cs{afterassignment}}
+%
+% We want to overload \cs{shipout} to do something with the box.
+% It is quite impossible to do this reliable by catching the box
+% using macro arguments. The
+% variety of box specifications is too large, Examples:
+% \begin{quote}
+% |\shipout\null|\\
+% |\shipout\vbox{...}|\\
+% |\shipout\vtop\bgroup ...\egroup|\\
+% |\shipout\box255|
+% \end{quote}
+% Even worse, the braces don't need to be balanced:
+% \begin{quote}
+% |\shipout\hbox\bgroup}|\\
+% |\shipout\vbox{\egroup|
+% \end{quote}
+% Happily TeX provides a reliable way via \cs{afterassignment}.
+% It takes a macro name and executes it just after the assignment.
+%
+% Now we can redefine \cs{shipout}. The box specification that
+% follows \cs{shipout} is catched by \cs{setbox}. This is an
+% assignment to a box register. \cs{afterassignment}
+% notifies \TeX, that we want to call \cs{@test} right after
+% the assignment:
+%\begin{quote}
+%\begin{verbatim}
+%\shipout ->
+% \afterassignment\@test
+% \setbox\mybox=
+%\end{verbatim}
+%\end{quote}
+% We have seen different box specifications. Indirect boxes are easy
+% to understand:
+% \begin{quote}
+% |\shipout\box0| $\Rightarrow$ |\setbox\mybox=\box0 |\fbox{\cs{@test}}
+% \end{quote}
+% However direct boxes can have arbitrary contents with lots of
+% other assignments. It would be quite inpredictable if \TeX\ would
+% put |\@test| after the first of such an assignment or after the
+% box specification if the box lacks of assignments.
+% Therefore \TeX\ puts |\@test| right at the beginning of the
+% box specification, e.g:
+% \begin{quote}
+% |\shipout\hbox{Hello World}|\\
+% $\Rightarrow$
+% |\setbox\mybox=\hbox{|\fbox{\cs{@test}}| Hello World}|
+% \end{quote}
+%
+% \subsection{Test for direct or indirect boxes}
+%
+% Now we want to execute \cs{@test}, but where are we?
+% We can be after the completed box assignment, if \cs{shipout}
+% was called with an indirect box. Or we are right at the beginning
+% of a direct box.
+%
+% \subsubsection{With \eTeX}
+%
+% With the \eTeX's extensions the answer is very easy:
+% Being inside the direct box means that we are inside a new group.
+% The new primitive command \cs{currentgrouplevel} tells how
+% deeply the groups are currently nested. Macro \cs{@test} just
+% compares the previously stored group level with the current one:
+%\begin{quote}
+%\begin{verbatim}
+%\shipout ->
+% \edef\saved@grouplevel{\number\currentgrouplevel}
+% \afterassignment\@test
+% \setbox\mybox=
+%
+%\@test ->
+% \ifnum\saved@grouplevel=\currentgrouplevel
+% % case: indirect box, the assignment is completed
+% \@output
+% \else
+% % case: direct box, we are inside the box
+% \aftergroup\@outbox
+% \fi
+%\end{verbatim}
+%\end{quote}
+%
+% \subsubsection{Without \eTeX}
+%
+% Life becomes complicate without \eTeX. We cannot ask the
+% group level. However, if we are inside a direct box,
+% the box register \cs{mybox} is not yet changed by \cs{setbox}.
+% Thus we need a special initial value and compare
+% it in \cs{@test} with the current value of the box.
+%
+% What can be used as initial value? Arbitrary box contents cannot
+% be compared. \TeX\ only tells us a few properties:
+% \begin{itemize}
+% \item Box type:\cs{ifhbox}, \cs{ifvbox}
+% \item Dimensions: \cs{wd}, \cs{ht}, \cs{dp}
+% \item Voidness: \cs{ifvoid}
+% \end{itemize}
+% Unhappily all these qualities even combined are not sufficient
+% for constructing an initial box value, because \cs{shipout} can be
+% called with a box that is accidently just the same as the choosen
+% initial value.
+%
+% Nevertheless we have two alternatives for an initial value:
+% \begin{itemize}
+% \item A box of some type with some funny settings that are
+% unlikely to occur in real life, e.g a height of |4911sp-\maxdimen|.
+% \item A void box.
+% \end{itemize}
+% A collision between this initial value and an indirect \cs{shipout}
+% box with just the same value is possible.
+% Then \cs{@test} will make a wrong decision that it is executed
+% inside a direct box and delays \cs{@output} by \cs{aftergroup}.
+% Thus \cs{@output} is not called at the place we want.
+% In contrary, the result is an uncertainty about the place:
+% \begin{itemize}
+% \item \cs{shipout} is used in a group that perhaps closes some
+% pages later. A bad place for \cs{@output}.
+% \item Without a surrounding group \cs{aftergroup} effectively kills
+% its argument.
+% \end{itemize}
+% In the first case of a box with special dimensions we can even loose
+% the page. However in the case of the void box, this effect is even
+% desired, because the original \cs{shipout} does not output void boxes.
+% All we have to do is to ensure that our box \cs{mybox} is always
+% void except for the phase when the overloaded \cs{shipout} is executed.
+% And secondly we must keep this semantics of \cs{shipout} for the void case
+% in our macros, namely \cs{@output}.
+%\begin{quote}
+%\begin{verbatim}
+%\shipout ->
+% % trick to get a void box \mybox
+% \begingroup
+% \setbox\mybox=\box\mybox
+% \endgroup
+% \afterassignment\@test
+% \setbox\mybox=
+%
+%\@test ->
+% \ifvoid\mybox
+% \aftergroup\@output
+% \else
+% \@output
+% \fi
+%\end{verbatim}
+%\end{quote}
+% The nasty case is |\shipout\box\voidb@x| where the indirect box
+% is void and that must not generate an output page.
+% If a surrounding group is missing the output is ignored
+% because of \cs{aftergroup}.
+% Otherwise \@output is called some time
+% later when the surrounding group closes.
+% But \cs{mybox} is void outside the execution phase
+% of the redefined \cs{shipout}. Also \cs{@output} checks for a
+% void box and cancels the page output.
+% The disadvantage remains that the hook in \cs{@output} is called
+% for a page that will not be output.
+%
+% \subsubsection{\cs{lastkern} method}
+%
+% At the beginning of a new box, there is no \cs{kern}, the contents
+% of the box is still empty and \cs{lastkern} returns 0\,pt.
+% This can be used to distinguish between direct and indirect boxes:
+% We execute \cs{setbox} in a box with a preceding non-zero kern.
+% After an indirect box, \cs{lastkern} sees this kern, otherwise
+% it returns 0\,pt.
+%\begin{quote}
+%\begin{verbatim}
+%\shipout ->
+% \begingroup
+% \setbox\mybox=\hbox\bgroup
+% \kern1pt
+% \afterassignment\shipout@test
+% \global\setbox\mybox=
+%\@test ->
+% \ifdim\lastkern=0pt
+% % direct box
+% \aftergroup\egroup
+% \aftergroup\endgroup
+% \aftergroup\@output
+% \else
+% \egroup
+% \endgroup
+% \@output
+% \fi
+%\end{verbatim}
+%\end{quote}
+% We have two \cs{setbox} commands. The first creates a controlled
+% context box where we can safely insert a \cs{kern}. We get rid of
+% this temporarily used context box by putting the local \cs{setbox}
+% in a group.
+%
+% After the group we want to have our shipout box in \cs{mybox}.
+% Therefore we use a global assignment here.
+%
+% \subsection{Output}
+%
+% With or without \eTeX\ we ensure the original behaviour of
+% \cs{shipout} that void boxes do not generate output pages.
+%
+% Now we can place the hook \cs{@hook} for the user code that
+% wants to manipulate the output box.
+%\begin{quote}
+%\begin{verbatim}
+%\@output ->
+% \ifvoid\mybox
+% % cancel output of void box
+% \else
+% \@hook
+% \ifvoid\mybox
+% % user code in \@hook could has voided the box
+% \else
+% \original@shipout\box\mybox
+% \fi
+% \fi
+%\end{verbatim}
+%\end{quote}
+%
+% \subsection{Separate box register}
+%
+% So far we have said nothing about the box number of \cs{mybox}.
+% The following case that outputs the same page twice
+% shows that we are not free in the use
+% of the box register:
+% \begin{quote}
+% |\shipout\copy<num> \shipout\box<num>|
+% \end{quote}
+% We manipulate the box by the hook and without \eTeX\ the box
+% must even be voided. However, the use case above requires that
+% the box contents does not change at all. Therefore we must
+% reserve a separate box register to avoid collisions with
+% user box registers.
+%
+% \emph{Note:} Box register number 255 is special for the output
+% routine, because TeX complains if this box is not voided
+% by the output routine.
+% However, this requirement does not apply to \cs{shipout} at all.
+% In fact \cs{shipout} does not change any box register. This is
+% usually done by a call of \cs{box}, but the output routine
+% can do it later \emph{after} invoking of \cs{shipout}.
+%
+% \subsection{Summary}
+%
+% \subsubsection{With \eTeX}
+%
+% Putting the pieces together we get for \eTeX:
+%\begin{quote}
+%\begin{verbatim}
+%\newbox\mybox
+%\let\original@shipout\shipout
+%
+%\shipout ->
+% \edef\saved@grouplevel{\number\currentgrouplevel}
+% \afterassignment\@test
+% \setbox\mybox=
+%
+%\@test ->
+% \ifnum\saved@grouplevel=\currentgrouplevel
+% \@output
+% \else
+% \aftergroup\@output
+% \fi
+%
+%\@output ->
+% \ifvoid\mybox
+% % cancel output of void box
+% \else
+% \@hook
+% \ifvoid\mybox
+% % user code in \@hook could have voided the box
+% \else
+% \original@shipout\box\mybox
+% \fi
+% \fi
+%\end{verbatim}
+%\end{quote}
+%
+% \subsubsection{Without \eTeX}
+%
+% And for \TeX\ without \eTeX:
+%\begin{quote}
+%\begin{verbatim}
+%\newbox\mybox
+%\begingroup
+% \setbox\mybox=\box\mybox % ensure \mybox is void
+%\endgroup
+%\let\original@shipout\shipout
+%
+%\shipout ->
+% % trick to get a void box \mybox
+% \begingroup
+% \setbox\mybox=\box\mybox
+% \endgroup
+% \afterassignment\@test
+% \setbox\mybox=
+%
+%\@test ->
+% \ifvoid\mybox
+% \aftergroup\@output
+% \else
+% \@output
+% \fi
+%
+%\@output ->
+% \ifvoid\mybox
+% % cancel output of void box
+% \else
+% \@hook
+% \ifvoid\mybox
+% % user code in \@hook could have voided the box
+% \else
+% \original@shipout\box\mybox
+% \fi
+% \fi
+%\end{verbatim}
+%\end{quote}
+%
+% \subsubsection{\cs{lastkern} method}
+%
+% And for \TeX\ without \eTeX\ using the \cs{lastkern} method:
+%\begin{quote}
+%\begin{verbatim}
+%\newbox\mybox
+%\let\original@shipout\shipout
+%
+%\shipout ->
+% \begingroup
+% \setbox\mybox=\hbox\bgroup
+% \kern1pt
+% \afterassignment\@test
+% \setbox\mybox=
+%
+%\@test ->
+% \ifdim\lastkern=0pt
+% \aftergroup\egroup
+% \aftergroup\endgroup
+% \aftergroup\@output
+% \else
+% \egroup
+% \endgroup
+% \@output
+% \fi
+%
+%\@output ->
+% \ifvoid\mybox
+% % cancel output of void box
+% \else
+% \@hook
+% \ifvoid\mybox
+% % user code in \@hook could have voided the box
+% \else
+% \original@shipout\box\mybox
+% \fi
+% \fi
+%\end{verbatim}
+%\end{quote}
+%
+% \StopEventually{
+% }
+%
+% \section{Implementation}
+%
+% Package \xpackage{atbegshi} uses \eTeX's \cs{currentgrouplevel},
+% if it is available. Otherwise the \cs{lastkern} method is used.
+%
+% \begin{macrocode}
+%<*package>
+% \end{macrocode}
+%
+% \subsection{Catcodes}
+%
+% \begin{macrocode}
+\expandafter\edef\csname AtBegShi@End\endcsname{%
+ \catcode40 \the\catcode40\relax % (
+ \catcode41 \the\catcode41\relax % )
+ \catcode44 \the\catcode44\relax % ,
+ \catcode45 \the\catcode45\relax % -
+ \catcode46 \the\catcode46\relax % .
+ \catcode58 \the\catcode58\relax % :
+ \catcode61 \the\catcode61\relax % =
+ \catcode64 \the\catcode64\relax % @
+ \catcode94 \the\catcode94\relax % ^
+ \catcode96 \the\catcode96\relax % `
+ \noexpand\endinput
+}
+\catcode40 12 % (
+\catcode41 12 % )
+\catcode44 12 % ,
+\catcode45 12 % -
+\catcode46 12 % .
+\catcode58 12 % :
+\catcode61 12 % =
+\catcode64 11 % @
+\catcode94 7 % ^
+\catcode96 12 % `
+% \end{macrocode}
+%
+% \subsection{Reload check and package identification}
+% Reload check, especially if the package is not used with \LaTeX.
+% \begin{macrocode}
+\begingroup
+ \expandafter\let\expandafter\x\csname ver@atbegshi.sty\endcsname
+ \ifcase 0%
+ \ifx\x\relax % plain
+ \else
+ \ifx\x\empty % LaTeX
+ \else
+ 1%
+ \fi
+ \fi
+ \else
+ \expandafter\ifx\csname PackageInfo\endcsname\relax
+ \def\x#1#2{%
+ \immediate\write-1{Package #1 Info: #2.}%
+ }%
+ \else
+ \def\x#1#2{\PackageInfo{#1}{#2, stopped}}%
+ \fi
+ \x{atbegshi}{The package is already loaded}%
+ \endgroup
+ \expandafter\endinput
+ \fi
+\endgroup
+% \end{macrocode}
+% Package identification:
+% \begin{macrocode}
+\begingroup
+ \expandafter\ifx\csname ProvidesPackage\endcsname\relax
+ \def\x#1#2#3[#4]{\endgroup
+ \immediate\write-1{Package: #3 #4}%
+ \xdef#1{#4}%
+ }%
+ \else
+ \def\x#1#2[#3]{\endgroup
+ #2[{#3}]%
+ \ifx#1\relax
+ \xdef#1{#3}%
+ \fi
+ }%
+ \fi
+\expandafter\x\csname ver@atbegshi.sty\endcsname
+\ProvidesPackage{atbegshi}%
+ [2007/04/19 v1.2 At begin shipout hook (HO)]
+% \end{macrocode}
+%
+% \subsection{Preparations}
+%
+% \begin{macro}{\AtBegShi@Warning}
+% \begin{macrocode}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname PackageWarning\endcsname\relax
+ \def\AtBegShi@Warning#1{%
+ \begingroup
+ \newlinechar=10 %
+ \def\@spaces{\space\space\space\space}%
+ \def\MessageBreak{%
+ ^^J(atbegshi)\@spaces\@spaces\@spaces\@spaces
+ }%
+ \immediate\write16{%
+ ^^JPackage atbegshi Warning: #1 %
+ on input line \the\inputlineno.^^J%
+ }%
+ \endgroup
+ }%
+\else
+ \def\AtBegShi@Warning{%
+ \PackageWarning{atbegshi}%
+ }%
+\fi
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBegShi@Info}
+% \begin{macrocode}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname PackageInfo\endcsname\relax
+ \def\AtBegShi@Info#1{%
+ \begingroup
+ \newlinechar=10 %
+ \def\@spaces{\space\space\space\space}%
+ \def\MessageBreak{%
+ ^^J(atbegshi) \@spaces\@spaces\@spaces
+ }%
+ \immediate\write-1{%
+ ^^JPackage atbegshi Info: #1.^^J%
+ }%
+ \endgroup
+ }%
+\else
+ \def\AtBegShi@Info#1{%
+ \begingroup
+ \def\on@line{}%
+ \PackageInfo{atbegshi}{#1}%
+ \endgroup
+ }%
+\fi
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBegShi@CheckDefinable}
+% \begin{macrocode}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname @ifdefinable\endcsname\relax
+ \def\AtBegShi@CheckDefinable#1{%
+ \ifcase\ifx#1\relax
+ \@ne
+ \else
+ \ifx#1\@undefined
+ \@ne
+ \else
+ \z@
+ \fi
+ \fi
+ \errmessage{%
+ Package atbegshi: \string#1\space
+ is already defined%
+ }%
+ \endgroup
+ \fi
+ }%
+\else
+ \def\AtBegShi@CheckDefinable#1{%
+ \@ifdefinable{#1}{}%
+ }%
+\fi
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\newif\ifAtBegShi@Discarded
+% \end{macrocode}
+% \begin{macro}{\AtBeginShipoutDiscard}
+% \begin{macrocode}
+\AtBegShi@CheckDefinable\AtBeginShipoutDiscard
+\def\AtBeginShipoutDiscard{%
+ \deadcycles=\z@
+ \global\AtBegShi@Discardedtrue
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname currentgrouplevel\endcsname\relax
+ \catcode`X=9 % ignore
+ \catcode`E=14 % comment
+\else
+ \catcode`X=14 % comment
+ \catcode`E=9 % ignore
+\fi
+% \end{macrocode}
+%
+% \begin{macro}{\AtBegShi@Shipout}
+% \begin{macrocode}
+\def\AtBegShi@Shipout{%
+X \begingroup
+X \setbox\AtBeginShipoutBox=\hbox\bgroup
+X \kern\p@
+E \edef\AtBegShi@GroupLevel{\number\currentgrouplevel}%
+ \afterassignment\AtBegShi@Test
+X \global
+ \setbox\AtBeginShipoutBox=%
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBegShi@Test}
+% \begin{macrocode}
+\def\AtBegShi@Test{%
+X \ifdim\lastkern=\z@
+X \aftergroup\egroup
+X \aftergroup\endgroup
+X \expandafter\aftergroup
+X \else
+X \egroup
+X \endgroup
+E \ifnum\AtBegShi@GroupLevel=\currentgrouplevel
+E \else
+E \expandafter\aftergroup
+ \fi
+ \AtBegShi@Output
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\catcode`\X=11 %
+\catcode`\E=11 %
+% \end{macrocode}
+%
+% \begin{macro}{\AtBegShi@Output}
+% \begin{macrocode}
+\def\AtBegShi@Output{%
+ \ifvoid\AtBeginShipoutBox
+ \AtBegShi@Warning{Ignoring void shipout box}%
+ \else
+ \let\AtBegShi@OrgProtect\protect
+ \csname set@typeset@protect\endcsname
+ \global\AtBegShi@Discardedfalse
+ \AtBegShi@Hook
+ \AtBegShi@HookNext
+ \gdef\AtBegShi@HookNext{}%
+ \ifAtBegShi@Discarded
+ \AtBegShi@Info{Shipout page discarded}%
+ \global\AtBegShi@Discardedfalse
+ \begingroup
+ \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
+ \endgroup
+ \let\protect\AtBegShi@OrgProtect
+ \else
+ \AtBegShi@First
+ \let\protect\AtBegShi@OrgProtect
+ \AtBegShi@OrgShipout\box\AtBeginShipoutBox
+ \fi
+ \fi
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBegShi@First}
+% \begin{macrocode}
+\def\AtBegShi@First{%
+ \begingroup
+ \def\@empty{}%
+ \ifx\AtBegShi@HookFirst\@empty
+ \else
+ \setbox\z@=\vbox{%
+ \begingroup
+ \AtBegShi@HookFirst
+ \endgroup
+ }%
+ \wd\z@=\z@
+ \ht\z@=\z@
+ \dp\z@=\z@
+ \global\setbox\AtBeginShipoutBox=\vbox{%
+ \baselineskip\z@skip
+ \lineskip\z@skip
+ \lineskiplimit\z@
+ \copy\z@
+ \copy\AtBeginShipoutBox
+ }%
+ \fi
+ \global\let\AtBegShi@First\@empty
+ \global\let\AtBeginShipoutFirst\AtBegShi@FirstDisabled
+ \endgroup
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBegShi@Hook}
+% \begin{macrocode}
+\gdef\AtBegShi@Hook{}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\AtBegShi@HookNext}
+% \begin{macrocode}
+\gdef\AtBegShi@HookNext{}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\AtBegShi@HookFirst}
+% \begin{macrocode}
+\gdef\AtBegShi@HookFirst{}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\AtBeginShipout}
+% \begin{macrocode}
+\AtBegShi@CheckDefinable\AtBeginShipout
+\def\AtBeginShipout{%
+ \AtBegShi@AddHook\AtBegShi@Hook
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\AtBeginShipoutNext}
+% \begin{macrocode}
+\AtBegShi@CheckDefinable\AtBeginShipoutNext
+\def\AtBeginShipoutNext{%
+ \AtBegShi@AddHook\AtBegShi@HookNext
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\AtBeginShipoutFirst}
+% \begin{macrocode}
+\AtBegShi@CheckDefinable\AtBeginShipoutFirst
+\def\AtBeginShipoutFirst{%
+ \AtBegShi@AddTo\AtBegShi@HookFirst
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\AtBegShi@FirstDisabled}
+% \begin{macrocode}
+\long\def\AtBegShi@FirstDisabled#1{%
+ \AtBegShi@Warning{%
+ First page is already shipped out, ignoring\MessageBreak
+ \string\AtBeginShipoutFirst
+ }%
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBegShi@AddTo}
+% \begin{macrocode}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname g@addto@macro\endcsname\relax
+ \long\def\AtBegShi@AddTo#1#2{%
+ \begingroup
+ \toks\z@\expandafter{#1#2}%
+ \xdef#1{\the\toks\z@}%
+ \endgroup
+ }%
+\else
+ \let\AtBegShi@AddTo\g@addto@macro
+\fi
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBegShi@AddHook}
+% \begin{macrocode}
+\long\def\AtBegShi@AddHook#1#2{%
+ \AtBegShi@AddTo#1{\AtBegShi@Item{#2}}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBegShi@Item}
+% \begin{macrocode}
+\long\def\AtBegShi@Item#1{%
+ \ifAtBegShi@Discarded
+ \else
+ #1%
+ \ifvoid\AtBeginShipoutBox
+ \AtBegShi@Warning{%
+ Shipout box was voided by hook,\MessageBreak
+ ignoring shipout box%
+ }%
+ \AtBeginShipoutDiscard
+ \fi
+ \fi
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginShipoutInit}
+% \begin{macrocode}
+\AtBegShi@CheckDefinable\AtBeginShipoutInit
+\def\AtBeginShipoutInit{%
+ \csname newbox\endcsname\AtBeginShipoutBox
+ \AtBegShi@CheckDefinable\AtBegShi@OrgShipout
+ \global\let\AtBegShi@OrgShipout\shipout
+ \global\let\shipout\AtBegShi@Shipout
+ \gdef\AtBeginShipoutInit{}%
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macrocode}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname AtBeginDocument\endcsname\relax
+ \AtBeginShipoutInit
+\else
+ \AtBeginDocument{\AtBeginShipoutInit}%
+\fi
+% \end{macrocode}
+%
+% \subsection{Patches}
+%
+% Patches for \LaTeX\ packages that redefine \cs{shipout}.
+% \LaTeX\ is now supposed to use \eTeX. Thus we do not patch,
+% without \LaTeX\ and \eTeX.
+% \begin{macrocode}
+\def\AtBegShi@AbortIfUndefined#1{%
+ \begingroup\expandafter\expandafter\expandafter\endgroup
+ \expandafter\ifx\csname#1\endcsname\relax
+ \expandafter\AtBegShi@End
+ \fi
+}
+\AtBegShi@AbortIfUndefined{currentgrouplevel}
+\AtBegShi@AbortIfUndefined{AtBeginDocument}
+\AtBegShi@AbortIfUndefined{@ifpackageloaded}
+\AtBegShi@AbortIfUndefined{@ifclassloaded}
+% \end{macrocode}
+%
+% \subsubsection{Package \xpackage{crop}}
+%
+% Fix of method and box.
+% \begin{macrocode}
+\def\AtBegShi@PatchCrop{%
+ \begingroup
+ \def\AtBegShi@Crop@shipout{%
+ \afterassignment\CROP@ship
+ \setbox\@cclv=%
+ }%
+ \def\AtBegShi@Crop@ship{%
+ \ifvoid\@cclv
+ \expandafter\aftergroup
+ \fi
+ \CROP@@ship
+ }%
+ \def\AtBegShi@Crop@shiplist{%
+ \lineskip\z@
+ \lineskiplimit\z@
+ \baselineskip\z@
+ \CROP@kernel
+ \box\@cclv
+ }%
+ \def\AtBegShi@Crop@@ship{%
+ \CROP@shipout\vbox{%
+ \CROP@shiplist
+ }%
+ }%
+ \ifx\AtBegShi@Crop@ship\CROP@ship
+ \ifx\AtBegShi@Crop@shiplist\CROP@shiplist
+ \ifx\AtBegShi@Crop@@ship\CROP@@ship
+ \let\AtBegShi@found\relax
+ \ifx\shipout\AtBegShi@Crop@shipout
+ \def\AtBegShi@found{\shipout}%
+ \else\ifx\AtBegShi@OrgShipout\AtBegShi@Crop@shipout
+ \def\AtBegShi@found{\AtBegShi@OrgShipout}%
+ \else\ifx\@EveryShipout@Org@Shipout\AtBegShi@Crop@shipout
+ \def\AtBegShi@found{\@EveryShipout@Org@Shipout}%
+ \else\ifx\GPTorg@shipout\AtBegShi@Crop@shipout
+ \def\AtBegShi@found{\GPTorg@shipout}%
+ \else\ifx\THBorg@shipout\AtBegShi@Crop@shipout
+ \def\AtBegShi@found{\THBorg@shipout}%
+ \else\ifx\mem@oldshipout\AtBegShi@Crop@shipout
+ \def\AtBegShi@found{\mem@oldshipout}%
+ \fi\fi\fi\fi\fi\fi
+ \ifx\AtBegShi@found\relax
+ \else
+ \expandafter\endgroup
+ \expandafter\def\AtBegShi@found{%
+ \edef\AtBegShi@GroupLevel{\number\currentgrouplevel}%
+ \afterassignment\CROP@ship
+ \setbox\AtBeginShipoutBox=%
+ }%
+ \def\CROP@ship{%
+ \ifnum\AtBegShi@GroupLevel=\currentgrouplevel
+ \else
+ \expandafter\aftergroup
+ \fi
+ \CROP@@ship
+ }%
+ \def\CROP@shiplist{%
+ \lineskip\z@
+ \lineskiplimit\z@
+ \baselineskip\z@
+ \CROP@kernel
+ \box\AtBeginShipoutBox
+ }%
+ \def\CROP@@ship{%
+ \ifvoid\AtBeginShipoutBox
+ \else
+ \setbox\AtBeginShipoutBox=\vbox{%
+ \CROP@shiplist
+ }%
+ \expandafter\CROP@shipout
+ \expandafter\box
+ \expandafter\AtBeginShipoutBox
+ \fi
+ }%
+ \AtBegShi@Info{Package `crop' patched}%
+ \begingroup
+ \fi
+ \fi
+ \fi
+ \fi
+ \endgroup
+ \let\AtBegShi@PatchCrop\relax
+}
+\@ifpackageloaded{crop}{%
+ \AtBegShi@PatchCrop
+}{%
+ \AtBeginDocument{\AtBegShi@PatchCrop}%
+}
+% \end{macrocode}
+%
+% \subsubsection{Package \xpackage{everyshi}}
+%
+% Fix of method. Use of box 255 is not changed.
+% \begin{macrocode}
+\def\AtBegShi@PatchEveryshi{%
+ \begingroup
+ \long\def\AtBegShi@Everyshi@shipout{%
+ \afterassignment\@EveryShipout@Test
+ \global\setbox\@cclv= %
+ }%
+ \long\def\AtBegShi@Everyshi@Test{%
+ \ifvoid\@cclv\relax
+ \aftergroup\@EveryShipout@Output
+ \else
+ \@EveryShipout@Output
+ \fi
+ }%
+ \ifx\AtBegShi@Everyshi@Test\@EveryShipout@Test
+ \let\AtBegShi@found\relax
+ \ifx\shipout\AtBegShi@Everyshi@shipout
+ \def\AtBegShi@found{\shipout}%
+ \else\ifx\AtBegShi@OrgShipout\AtBegShi@Everyshi@shipout
+ \def\AtBegShi@found{\AtBegShi@OrgShipout}%
+ \else\ifx\CROP@shipout\AtBegShi@Everyshi@shipout
+ \def\AtBegShi@found{\CROP@shipout}%
+ \else\ifx\GPTorg@shipout\AtBegShi@Everyshi@shipout
+ \def\AtBegShi@found{\GPTorg@shipout}%
+ \else\ifx\THBorg@shipout\AtBegShi@Everyshi@shipout
+ \def\AtBegShi@found{\THBorg@shipout}%
+ \else\ifx\mem@oldshipout\AtBegShi@Everyshi@shipout
+ \def\AtBegShi@found{\mem@oldshipout}%
+ \else
+ \expandafter\ifx\csname @EveryShipout@Org@Shipout\endcsname
+ \relax
+ \ifx\@EveryShipout@Shipout\AtBegShi@Everyshi@shipout
+ \def\AtBegShi@found{\@EveryShipout@Shipout}%
+ \fi
+ \fi
+ \fi\fi\fi\fi\fi\fi
+ \ifx\AtBegShi@found\relax
+ \else
+ \expandafter\endgroup
+ \expandafter\def\AtBegShi@found{%
+ \edef\AtBegShi@GroupLevel{\number\currentgrouplevel}%
+ \afterassignment\@EveryShipout@Test
+ \setbox\AtBeginShipoutBox=%
+ }%
+ \def\@EveryShipout@Test{%
+ \ifnum\AtBegShi@GroupLevel=\currentgrouplevel
+ \else
+ \expandafter\aftergroup
+ \fi
+ \AtBegShi@Everyshi@Output
+ }%
+ \def\AtBegShi@Everyshi@Output{%
+ \ifvoid\AtBeginShipoutBox
+ \else
+ \global\setbox\@cclv\box\AtBeginShipoutBox
+ \expandafter\@EveryShipout@Output
+ \fi
+ }%
+ \AtBegShi@Info{Package `everyshi' patched}%
+ \begingroup
+ \fi
+ \fi
+ \endgroup
+ \let\AtBegShi@PatchEveryshi\relax
+}
+\@ifpackageloaded{everyshi}{%
+ \AtBegShi@PatchEveryshi
+}{%
+ \AtBeginDocument{\AtBegShi@PatchEveryshi}%
+}
+% \end{macrocode}
+%
+% \subsubsection{Class \xpackage{memoir}}
+%
+% Fix of method and box.
+% \begin{macrocode}
+\def\AtBegShi@PatchMemoir{%
+ \begingroup
+ \def\AtBegShi@Memoir@shipout{%
+ \afterassignment\mem@shipi
+ \setbox\@cclv=%
+ }%
+ \def\AtBegShi@Memoir@shipi{%
+ \ifvoid\@cclv
+ \expandafter\aftergroup
+ \fi
+ \mem@shipii
+ }%
+ \def\AtBegShi@Memoir@shipiiA{%
+ \mem@oldshipout\vbox{%
+ \trimmarks
+ \unvbox\@cclv
+ }%
+ }%
+ \def\AtBegShi@Memoir@shipiiB{%
+ \ifvoid\@cclv
+ \mem@oldshipout\box\@cclv
+ \else
+ \mem@oldshipout\vbox{%
+ \trimmarks
+ \unvbox\@cclv
+ }%
+ \fi
+ }%
+ \ifx\AtBegShi@Memoir@shipi\mem@shipi
+ \ifcase\ifx\AtBegShi@Memoir@shipiiA\mem@shipii
+ \z@
+ \else
+ \ifx\AtBegShi@Memoir@shipiiB\mem@shipii
+ \z@
+ \else
+ \@ne
+ \fi
+ \fi
+ \let\AtBegShi@found\relax
+ \ifx\shipout\AtBegShi@Memoir@shipout
+ \def\AtBegShi@found{\shipout}%
+ \else\ifx\AtBegShi@OrgShipout\AtBegShi@Memoir@shipout
+ \def\AtBegShi@found{\AtBegShi@OrgShipout}%
+ \else\ifx\CROP@shipout\AtBegShi@Memoir@shipout
+ \def\AtBegShi@found{\CROP@shipout}%
+ \else\ifx\GPTorg@shipout\AtBegShi@Memoir@shipout
+ \def\AtBegShi@found{\GPTorg@shipout}%
+ \else\ifx\THBorg@shipout\AtBegShi@Memoir@shipout
+ \def\AtBegShi@found{\THBorg@shipout}%
+ \else\ifx\@EveryShipout@Org@Shipout\AtBegShi@Memoir@shipout
+ \def\AtBegShi@found{\@EveryShipout@Org@Shipout}%
+ \fi\fi\fi\fi\fi\fi
+ \ifx\AtBegShi@found\relax
+ \else
+ \expandafter\endgroup
+ \expandafter\def\AtBegShi@found{%
+ \edef\AtBegShi@GroupLevel{\number\currentgrouplevel}%
+ \afterassignment\mem@shipi
+ \setbox\AtBeginShipoutBox=%
+ }%
+ \def\mem@shipi{%
+ \ifnum\AtBegShi@GroupLevel=\currentgrouplevel
+ \else
+ \expandafter\aftergroup
+ \fi
+ \mem@shipii
+ }%
+ \def\mem@shipii{%
+ \ifvoid\AtBeginShipoutBox
+ \else
+ \setbox\AtBeginShipoutBox=\vbox{%
+ \trimmarks
+ \ifvbox\AtBeginShipoutBox
+ \unvbox\AtBeginShipoutBox
+ \else
+ \box\AtBeginShipoutBox
+ \fi
+ }%
+ \expandafter\mem@oldshipout
+ \expandafter\box
+ \expandafter\AtBeginShipoutBox
+ \fi
+ }%
+ \AtBegShi@Info{Class `memoir' patched}%
+ \begingroup
+ \fi
+ \fi
+ \fi
+ \endgroup
+ \let\AtBegShi@PatchMemoir\relax
+}
+\@ifclassloaded{memoir}{%
+ \AtBegShi@PatchMemoir
+}{%
+ \AtBeginDocument{\AtBegShi@PatchMemoir}%
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\AtBegShi@End
+%</package>
+% \end{macrocode}
+%
+% \section{Test}
+%
+% \begin{macrocode}
+%<*test1>
+\input atbegshi.sty\relax
+\def\msg#{\immediate\write16}
+\msg{File: atbegshi-test1.tex 2007/04/19 v1.2 Test file for plain-TeX}
+\def\testmsg#1#2{%
+ \msg{}%
+ \msg{*** Test with box (#1), expected page output [#2]}%
+}
+
+\newbox\voidbox
+\def\void{\box\voidbox}
+\begingroup
+ \setbox\voidbox=\void
+\endgroup
+
+\count0=0\relax
+\AtBeginShipout{%
+ \global\advance\count0 by 1\relax
+ \msg{* Inside \string\AtBeginShipout: [\the\count0]}%
+}
+
+\AtBeginShipoutFirst{%
+ \msg{* Inside \string\AtBeginShipoutFirst}%
+ Hello World%
+}
+
+\testmsg{\string\null}{1}
+\shipout\null
+
+\AtBeginShipoutFirst{%
+ This is too late%
+}
+
+\testmsg{void}{}
+\shipout\void
+
+\testmsg{\string\copy255 (not void)}{2}
+\setbox255\hbox{\vrule height 10bp width 10bp}
+\shipout\copy255 %
+
+\testmsg{\string\copy255 (again)}{3}
+\shipout\copy255 %
+
+\testmsg{\string\box255}{4}
+\shipout\box255 %
+
+\testmsg{\string\box255 (again)}{}
+\shipout\box255 %
+
+\testmsg{\string\hbox}{5}
+\shipout\hbox{\vrule height 5bp width 20bp}
+
+\testmsg{\string\vbox}{6}
+\shipout\vbox{\hrule height 20bp width 5bp}
+
+\testmsg{\string\null, voided by hook}{}
+\def\VoidBox{%
+ \begingroup
+ \setbox\AtBeginShipoutBox=\box\AtBeginShipoutBox
+ \endgroup
+}
+\AtBeginShipout{\VoidBox}
+\shipout\null
+\def\VoidBox{}
+
+\msg{*** \string\begingroup}
+\begingroup
+ \testmsg{void}{}%
+ \shipout\void
+\msg{*** \string\endgroup}
+\endgroup
+
+\msg{*** \string\begingroup}
+\begingroup
+ \testmsg{void}{}%
+ \shipout\void
+ \testmsg{\string\null}{8}%
+ \shipout\null
+\msg{*** \string\endgroup}
+\endgroup
+
+\testmsg{output routine}{9}
+Hello World
+\vfill
+\eject
+
+\testmsg{\string\null\space(discarded)}{}
+\AtBeginShipout{%
+ \msg{* Inside \string\AtBeginShipout: DISCARD}%
+ \AtBeginShipoutDiscard
+}
+\shipout\null
+
+\end
+%</test1>
+% \end{macrocode}
+%
+% \begin{macrocode}
+%<*test2>
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesFile{atbegshi-test2.tex}[2007/04/19 v1.2 Test file for LaTeX]
+\RequirePackage{color}
+\pagecolor{yellow}
+\documentclass[a5paper,showtrims]{memoir}
+\usepackage{atbegshi}
+\AtBeginShipout{%
+ \setbox\AtBeginShipoutBox=\vbox{%
+ \vbox to 0pt{%
+ \kern-1.5in %
+ \hbox to 0pt{%
+ \kern-1.5in %
+ \color{blue}%
+ \rule{1in}{1in}%
+ \hss
+ }%
+ \vss
+ }%
+ \hrule
+ \hbox{\vrule\box\AtBeginShipoutBox\vrule}%
+ \hrule
+ }%
+}
+\usepackage{eso-pic}
+\makeatletter
+\@EveryShipout@Init
+\let\@EveryShipout@Init\relax
+\makeatother
+\AddToShipoutPicture{%
+ \hspace{.52\paperwidth}%
+ \colorbox{cyan}{%
+ \rule{0mm}{\paperheight}%
+ \hspace{.48\paperwidth}%
+ }%
+}
+\usepackage[color=red,cross,a4,center]{crop}
+\begin{document}
+\shipout\null
+\shipout\box\csname voidb@x\endcsname
+\section{Hello World}
+\end{document}
+%</test2>
+% \end{macrocode}
+% \section{Installation}
+%
+% \subsection{Download}
+%
+% \paragraph{Package.} This package is available on
+% CTAN\footnote{\url{ftp://ftp.ctan.org/tex-archive/}}:
+% \begin{description}
+% \item[\CTAN{macros/latex/contrib/oberdiek/atbegshi.dtx}] The source file.
+% \item[\CTAN{macros/latex/contrib/oberdiek/atbegshi.pdf}] Documentation.
+% \end{description}
+%
+%
+% \paragraph{Bundle.} All the packages of the bundle `oberdiek'
+% are also available in a TDS compliant ZIP archive. There
+% the packages are already unpacked and the documentation files
+% are generated. The files and directories obey the TDS standard.
+% \begin{description}
+% \item[\CTAN{macros/latex/contrib/oberdiek/oberdiek-tds.zip}]
+% \end{description}
+%
+% \subsection{Bundle installation}
+%
+% \paragraph{Unpacking.} Unpack the \xfile{oberdiek-tds.zip} in the
+% TDS tree (also known as \xfile{texmf} tree) of your choice.
+% Example (linux):
+% \begin{quote}
+% |unzip oberdiek-tds.zip -d ~/texmf|
+% \end{quote}
+%
+% \paragraph{Script installation.}
+% Check the directory \xfile{TDS:scripts/oberdiek/} for
+% scripts that need further installation steps.
+% Package \xpackage{attachfile2} comes with the Perl script
+% \xfile{pdfatfi.pl} that should be installed in such a way
+% that it can be called as \texttt{pdfatfi}.
+% Example (linux):
+% \begin{quote}
+% |chmod +x scripts/oberdiek/pdfatfi.pl|\\
+% |cp scripts/oberdiek/pdfatfi.pl /usr/local/bin/|
+% \end{quote}
+%
+% \subsection{Package installation}
+%
+% \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
+% \docstrip\ archive. The files are extracted by running the
+% \xfile{.dtx} through \plainTeX:
+% \begin{quote}
+% \verb|tex atbegshi.dtx|
+% \end{quote}
+%
+% \paragraph{TDS.} Now the different files must be moved into
+% the different directories in your installation TDS tree
+% (also known as \xfile{texmf} tree):
+% \begin{quote}
+% \sbox0{^^A
+% \begin{tabular}{@{}>{\ttfamily}l@{$\quad\rightarrow\quad$}>{\ttfamily}l@{}}
+% atbegshi.sty & tex/generic/oberdiek/atbegshi.sty\\
+% atbegshi.pdf & doc/latex/oberdiek/atbegshi.pdf\\
+% atbegshi-test1.tex & doc/latex/oberdiek/atbegshi-test1.tex\\
+% atbegshi-test2.tex & doc/latex/oberdiek/atbegshi-test2.tex\\
+% atbegshi.dtx & source/latex/oberdiek/atbegshi.dtx\\
+% \end{tabular}^^A
+% }%
+% \ifdim\wd0>\linewidth
+% \mbox{}\nobreak\hskip0pt minus\leftmargin
+% \usebox0
+% \nobreak\hskip0pt minus\rightmargin
+% \else
+% \usebox0
+% \fi
+% \end{quote}
+% If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
+% TDS installing feature, then some files can already be in the right
+% place, see the documentation of \docstrip.
+%
+% \subsection{Refresh file name databases}
+%
+% If your \TeX~distribution
+% (\teTeX, \mikTeX, \dots) relies on file name databases, you must refresh
+% these. For example, \teTeX\ users run \verb|texhash| or
+% \verb|mktexlsr|.
+%
+% \subsection{Some details for the interested}
+%
+% \paragraph{Attached source.}
+%
+% The PDF documentation on CTAN also includes the
+% \xfile{.dtx} source file. It can be extracted by
+% AcrobatReader 6 or higher. Another option is \textsf{pdftk},
+% e.g. unpack the file into the current directory:
+% \begin{quote}
+% \verb|pdftk atbegshi.pdf unpack_files output .|
+% \end{quote}
+%
+% \paragraph{Unpacking with \LaTeX.}
+% The \xfile{.dtx} chooses its action depending on the format:
+% \begin{description}
+% \item[\plainTeX:] Run \docstrip\ and extract the files.
+% \item[\LaTeX:] Generate the documentation.
+% \end{description}
+% If you insist on using \LaTeX\ for \docstrip\ (really,
+% \docstrip\ does not need \LaTeX), then inform the autodetect routine
+% about your intention:
+% \begin{quote}
+% \verb|latex \let\install=y\input{atbegshi.dtx}|
+% \end{quote}
+% Do not forget to quote the argument according to the demands
+% of your shell.
+%
+% \paragraph{Generating the documentation.}
+% You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
+% the documentation. The process can be configured by the
+% configuration file \xfile{ltxdoc.cfg}. For instance, put this
+% line into this file, if you want to have A4 as paper format:
+% \begin{quote}
+% \verb|\PassOptionsToClass{a4paper}{article}|
+% \end{quote}
+% An example follows how to generate the
+% documentation with pdf\LaTeX:
+% \begin{quote}
+%\begin{verbatim}
+%pdflatex atbegshi.dtx
+%makeindex -s gind.ist atbegshi.idx
+%pdflatex atbegshi.dtx
+%makeindex -s gind.ist atbegshi.idx
+%pdflatex atbegshi.dtx
+%\end{verbatim}
+% \end{quote}
+%
+% \begin{History}
+% \begin{Version}{2007/04/17 v1.0}
+% \item
+% First version.
+% \end{Version}
+% \begin{Version}{2007/04/18 v1.1}
+% \item
+% New method based on \cs{lastkern} is used if \eTeX\ is missing.
+% \item
+% \cs{AtBeginShipoutDiscard} also resets \cs{deadcycles}.
+% \end{Version}
+% \begin{Version}{2007/04/19 v1.2}
+% \item
+% \cs{AtBeginShipoutEarly} removed for simplification reasons.
+% \item
+% Forgotten definition of \cs{AtBegShi@Info} added.
+% \item
+% Patches for packages \xpackage{crop} and \xpackage{everyshi}
+% and class \xclass{memoir} added.
+% \end{Version}
+% \end{History}
+%
+% \PrintIndex
+%
+% \Finale
+\endinput