[Tex/LaTex] \phantom considering cramped style


In LaTeX2e, \phantom is defined as

  \ifv@ \ht\tw@\ht\z@ \dp\tw@\dp\z@\fi
  \ifh@ \wd\tw@\wd\z@\fi \box\tw@}

It means that, in math mode,


has the same size of


but differs from


since x^2 in \sqrt is in cramped mode.

I know that mathtools package provides a \cramped macro to solve the problem, but is there an automatical method?

Test code:

$\sqrt{x^A} \sqrt{\hbox{$x^A$}}$

$\sqrt{\phantom{\cramped{x^A}}} \sqrt{\phantom{x^A}}$ 

enter image description here

Best Answer

I think the answer is "no" even with e-tex primitives you can not detect this. Perhaps luatex can jump to the rescue?

With thanks to the commenters, this should be possible in luatex


or for lualatex


Note that as usual \over may cause some complications stopping the math style being detected, see \Ustack (\luatexUstack) in the luatex manual.

Related Question