I encountered a strange spacing difference in the following example:
\documentclass{article}
\usepackage{tikz}
\begin{document}
number printer inside of fbox with -5e-5:
\fbox{\pgfmathprintnumber{-5e-5}}
\fbox{$\pgfmathprintnumber{-5e-5}$}
\end{document}

I know that \pgfmathprintnumber eventually uses \pgfutilensuremath which is defined by
\def\pgfutilensuremath#1{%
\ifmmode#1\else$#1$\fi
}
The question is: how can I get consistent behavior? More precisely: how can I change \fbox{\pgfmathprintnumber{-5e-5}} (i.e. change \pgfmathprintnumber) such that it does the same as the other statement (the other way round is not my use case).
Note that this actually a regression in pgfplots: version 1.4 used the second approach whereas version 1.5 uses the first. I would like to keep the first, but with the spacing of the second.
Could it be related to TeX's strategy to look for the next following char after $ to see if it might be a $$? If so, how can I avoid it?
${} -5\cdot 10^{-5}$, so I guess that pgfmath inserts an empty box somewhere. – Caramdir Oct 29 '11 at 17:03\fbox{$$\pgfmathprintnumber{-5e-5}$$}??? – Chuang Oct 29 '11 at 17:03$$ .. $$, see Why is\[…\]preferable to$$?. – Martin Scharrer Oct 29 '11 at 17:05\fbox{$\pgfmathprintnumber{-5e-5}$}the fbox is not in mathmode so the conditional goes to the\elsepart, therefore you inserting an extra$and you end up with math display mode within thefbox. Chuang hit the nail on the head? – yannisl Oct 29 '11 at 17:21$is actually the start of a$$-- and there are much more tokens between the involved math shifts. Thus, it switches to math mode and the\ifmmodeshould be true. – Christian Feuersänger Oct 29 '11 at 17:30