Jesteś w: Start / Przedsięwzięcia/Projects / TeX Pearls / 2008 Pearls / david-kastrup / bachotex2008-david-kastrup-pearl1.tex

bachotex2008-david-kastrup-pearl1.tex

TeX document icon bachotex2008-david-kastrup-pearl1.tex — TeX document, 1 KB (1242 bytes)

Zawartość pliku

%%% fixing \vtop

\catcode`\|13
\def\stripit#1>{}
\def|#1|{{\tt\toks0{#1}\edef\next{\the\toks0}%
  \expandafter\stripit\meaning\next}\unskip}
|\vtop| happens to lose the correct top of line information when it
starts with a whatsit.  We can reconstitute this in the following
manner\footnote*{The trick here is to use |\vsplit| which pads the
followup box sufficiently to reach a given line height on the top
line. We essentially tell it to make this line fit |\maxdimen| minus
a safety margin and see how far it gets.  Then we remove the padding
with another split and start the box with a strut that establishes the
corrected height.}:

\def\fvtop#{\vtop\bgroup
  \setbox0\vbox\bgroup
  \aftergroup\fvboxii
  \let\next=}

\def\fvboxii{\setbox0\vtop{\break\unvbox0}%
  \dimen0=\maxdimen
  \ifdim\dp0>0pt \advance\dimen0-\dp0 \fi
  {\splittopskip\dimen0 \setbox0\vsplit0to0pt}%
  \advance\dimen0-\ht0%
  {\splittopskip-\maxdimen\setbox0\vsplit0to0pt}%
  \advance\dimen0\ht0%
  \hrule height\dimen0 depth-\dimen0
  \unvbox0
  \egroup}

\def\example{\hbox{First good line}%
\hbox{Second good line}%
\hbox{Third good line}}

\leavevmode
\vtop{\example}\vtop{\write-1{}\example}\fvtop{\write-1{}\example}
\end