Jesteś w: Start / Przedsięwzięcia/Projects / TeX Pearls / 2007 Pearls / heiko-oberdiek / ShipoutCurrentgrouplevel.tex


TeX document icon ShipoutCurrentgrouplevel.tex — TeX document, 1 KB (1866 bytes)

Zawartość pliku



  \texttt{\textbackslash #1}%

  Safe redefinition of \cs{shipout} (I)
  using \eTeX's \cs{currentgrouplevel}%
\author{Heiko Oberdiek}
\date{27th April 2007}


Goal: Redefine \cs{shipout} to do something with its box.

First we catch its box by \cs{setbox} and \cs{afterassignment}:
\shipout := \afterassignment\@Test
There are two different cases:
(a) \shipout\box0      -> \setbox\@Box=\box0 \@Test
(b) \shipout\vbox{...} -> \setbox\@Box=\vbox{\@Test ...}
In case (b) we want to postpone \cs{@Test} after the \cs{vbox} group
by \cs{aftergroup}. But how can we differentiate between these cases?

\eTeX's \cs{currentgrouplevel} helps:
\shipout := \edef\@Level{\the\currentgrouplevel}
\@Test   := \ifnum\@Level<\currentgrouplevel
The original \cs{shipout} ignores void boxes.
\@Output := \ifvoid\@Box
              % do something with box \@Box
(For completeness:)
This is one of the methods implemented by package \xpackage{atbegshi}.