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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I encountered a strange spacing difference in the following example:




    number printer inside of fbox with -5e-5:



enter image description here

I know that \pgfmathprintnumber eventually uses \pgfutilensuremath which is defined by


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?

share|improve this question
This seems like a bug in pgfmath. The second spacing is incorrect: it printed like ${} -5\cdot 10^{-5}$, so I guess that pgfmath inserts an empty box somewhere. – Caramdir Oct 29 '11 at 17:03
Use \fbox{$$\pgfmathprintnumber{-5e-5}$$}??? – Chuang Oct 29 '11 at 17:03
@Chuang: Never use $$ .. $$, see Why is \[\] preferable to $$?. – Martin Scharrer Oct 29 '11 at 17:05
@Caramdir: Thanks and thanks. Should have tested that first. – Martin Scharrer Oct 29 '11 at 17:09
@Caramdir I would agree... this is probably a bug. And I am quite happy to hear that the second is the wrong choice. But: I traced through the number printer without any clue. I would appreciate any help of volunteers (seems I am blind here). – Christian Feuersänger Oct 29 '11 at 17:16
up vote 11 down vote accepted

This is a bug in pgfmath. In one place it delimits a group with {} instead of \begingroup ... \endgroup. So in the second version TeX sees the {} inside mathmode causing it to display a binary minus instead of a unary one (try ${}-5$; in the first version you get something like {}$-5$ and hence unary spacing).

The problematic groups are in \pgfmathfloatrounddisplaystyle@shared@impl@#1#2 and \pgfmathfloatrounddisplaystyle@shared@impl@@#1#2. So to fix it you can add

    \toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}%
    \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%

    \toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}%
    \pgfkeysgetvalue{/pgf/number format/@dec sep mark}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK
    \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 }%

to your document.

share|improve this answer
Excellent. That fixed it. I did not know there could be such problems in using these braces as group delimiters! Thanks for your help here. – Christian Feuersänger Oct 29 '11 at 17:27
@Christian: Neither did I until a few minutes ago. – Caramdir Oct 29 '11 at 17:29
Reported the bug: sourceforge.net/tracker/… – Caramdir Oct 29 '11 at 17:38
Ah - the bug report was actually unnessary: I am responsible for the number printer and I will commit the bugfix within the next minutes. – Christian Feuersänger Oct 29 '11 at 18:09
OK, is fixed now in PGF CVS. I found some more occurrences of the same problem in that file. – Christian Feuersänger Oct 29 '11 at 18:24

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.