Recently I was working on a package (ytableau) and had a strange experience with the gather
environment in amsmath. Namely, it screws with \vtop
and, seemingly, with boxes that I reserve before entering the environment. Consider the following minimal test cases:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\newbox\mybox
\setbox\mybox=\vtop{\halign{&#\cr a & b \cr c \cr}}
ht = \the\ht\mybox, dp = \the\dp\mybox
\begin{gather}
ht = \the\ht\mybox, dp = \the\dp\mybox
\box\mybox
\end{gather}
\begin{gather}
\setbox\mybox=\vtop{\halign{&#\cr a & b \cr c \cr}}
ht = \the\ht\mybox, dp = \the\dp\mybox
\box\mybox
\end{gather}
\end{document}
The result should be as follows: you will see printed "ht = 6.94444pt, dp = 12.0pt" before the first gather
, but inside it you will see only ht = 0.0pt, dp = 0.0pt
. Where did my box go? If you insert the same diagnostic after gather
you will note that it does not come back.
In the second gather
, you will see "ht = 0.0pt, dp = 21.94444pt" and the \halign
will print an "a b" over a "c" as desired, but the whole thing will indeed be aligned so that the very top of the first line is at the very bottom of the text line established by the environment (compare with the other text and the label). Where did the height go? (Don't say "into the depth" :). )
This is really annoying because it absolutely violates what I understand \vtop
to do: put the baseline of the box at the baseline of the top interior box. Printing that same \halign
outside of gather
(in a \vtop
) puts the "a b" in the text, as it should be.
This bug does not arise inside align
. What did happen there (and in gather
) was that I found that some of my macros were being double-evaluated. Presumably the AMS environments read their contents twice to get the proper typesetting? Unfortunately, I can't conceive of how that would cause the second error (note that the numbers change even if you don't print the box).