The following code produces a negative phantom (from the comment in this answer):
\newcommand{\negphantom}[1]{\settowidth{\dimen0}{#1}\hspace*{-\dimen0}}
However, when used inside an equation like
$$a\negphantom{\inf_{t>0}t^2}b$$
I get an error. The solution is to do
$$a\negphantom{$\inf_{t>0}t^2$}b$$
Is it possible to define negphantom
in such a way that it respects being inside an equation or not? (the latter solution is not perfect, since the \inf
is not in displaystyle).
Best Answer
You check for math mode and then use
\mathpalette
:Now that we're sure the space is correct in all cases, we can remove the debugging bits and write down the final definition: