In a display, the denominator of a fraction is set in “cramped” \textstyle
, which can be emulated with \cramped[\textstyle]{...}
from the mathtools
package. But sometimes the emulation is perfect, while sometimes it shifts the denominator down. Why?
\documentclass{article}
\usepackage{color}
\usepackage{mathtools}
\newcommand\drawbaseline[1]{%
\ifvmode\leavevmode\fi
\rlap{{\color{red}\vrule width #1 height 0.1pt }}%
}
\begin{document}
The denominators line up in this example:
\[
\frac{k^{2^n}}{\drawbaseline{45pt}k^{2^n}}\quad
\frac{k^{2^n}}{\cramped[\textstyle]{k^{2^n}}}
\]
The denominators don't line up in this example:
\[
\frac{\int_a^b k^2 g(x) f(x)\,dx}%
{\drawbaseline{145pt}\!% <- cancels \, between \hbox{} and \mathop
\int_a^b k^2 f(x)\,dx}\quad
\frac{\int_a^b k^2 g(x) f(x)\,dx}%
{\cramped[\textstyle]{\int_a^b k^2 f(x)\,dx}}
\]
Why?
\end{document}
Added tex-core tag because I suspect this has something to do with the primitive \over
.
Added clarifications
The problem became clearer after @wipet’s answer and my digging through tex.web
and mathtools.dtx
. In the second display of my MWE above, the latter denominator has an excessive height of exactly 1.25\fontdimen8\textfont3
, which comes from \radical0 {...}
(which in turn is what \cramped
uses to emulate cramped styles).
Now, \cramped
does try to correct this excessive height (and is ususally successful), but any later unboxing will ruin such correction because the height information will be lost. This “unboxing” behaviour is, by mathtools
, referred to as
a most unfortunate TeX “feature.” (The faulty reboxing procedure.)
My original question “sometimes the emulation is perfect, while sometimes it shifts the denominator down” was only partially answered by @wipet. Why does TeX’s rebox
subroutine seemingly behave differently?
Since @wipet also proposed a solution (i.e., replacing \box\z@
with \hbox{\box\z@}
), I wondered if this was the best solution: Note that mathtools
’ existing code seems to suggest {}\box\z@
, which is a construction used in \mathXlap
and \crampedXlap
.