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).

\newcommand{\negphantom}[1]{\settowidth{\dimen0}{$#1$}\hspace*{-\dimen0}}? – Henri Menke Jun 24 '16 at 09:39\newcommand{\negphantom}[1]{\ifmmode\settowidth{\dimen0}{$#1$}\else\settowidth{\dimen0}{#1}\fi\hspace*{-\dimen0}}– Henri Menke Jun 24 '16 at 09:40\mathchoicechecks for the current style, but I'm trying to get it to work – Carucel Jun 24 '16 at 09:49