Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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.

share|improve this answer
LuaTeX has \mathstyle, but strangely enough it's undefined in LuaLaTeX. – egreg Feb 21 '12 at 13:31
@egreg, so it does thanks, the luatex manual suggests \ifnum\mathstyle=\crampedtextstyle ought to work. – David Carlisle Feb 21 '12 at 13:36
@egreg: all luatex’s new commands are prefixed by \luatex in LuaLaTeX. – Khaled Hosny Feb 21 '12 at 13:48
Thanks. I think it's the solution. Can you copy the comment into the answer? I'll accept it. – Leo Liu Feb 21 '12 at 15:31

Here is the patch of \phantom for LuaLaTeX, based on David Carlisle's answer:



    \ifodd\luatexmathstyle % 1,3,5,7 for cramped styles



Then \phantom can detect cramped math styles

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.