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

Compare these two:


\unit{0.01 kilogram}
$ \unit{0.01 kilogram} $


I would naively expect these to produce very similar results, but the latter case—the one in math mode—we get an obnoxious looking space between the decimal point and the first 0. Observe:

enter image description here

What am I misunderstanding or doing wrong?

share|improve this question
up vote 7 down vote accepted

(I'm making this a separate answer because I think "it was broken, and this is how" and "it works now, and this is how" are conceptually different answers. Also because changing the answer would make the comments under it look odd.)

Your problem was actually a problem with the beta; this is fixed in the current Mark IV beta (2012.12.03 11:33). There are now three options to \setupmathematics[autopunctuation=...]:

  • autopunctuation=no — default TeX behaviour. Commas get a thin space, periods get nothing.
  • autopunctuation=yes — manual control for commas. Commas followed by a space get a thin space; periods, and commas followed by something else, do not.
  • autopunctuation=all — like yes, but the same behaviour for periods.

As for \unit{2.5} or \unit{2,5}: neither decimal marks nor digit separators get any unwanted spaces after them, no matter which one is the comma and which one the period. So that works all right again, as it did before the beta briefly broke.

Code illustrating the behaviour. The 'desired' column uses full spaces out of laziness.




\NC input  \NC desired \NC output  \NC \NR
\NC 2,5  \NC 2, 5 \NC $2,5$  \NC \NR
\NC 2, 5 \NC 2, 5 \NC $2, 5$ \NC \NR
\NC 2.5  \NC 2.5  \NC $2.5$  \NC \NR
\NC 2. 5 \NC 2.5  \NC $2. 5$ \NC \NR



\NC input  \NC desired \NC output  \NC \NR
\NC 2,5  \NC 2,5  \NC $2,5$  \NC \NR
\NC 2, 5 \NC 2, 5 \NC $2, 5$ \NC \NR
\NC 2.5  \NC 2.5  \NC $2.5$  \NC \NR
\NC 2. 5 \NC 2.5  \NC $2.5$  \NC \NR



\NC input  \NC desired \NC output  \NC \NR
\NC 2,5  \NC 2,5  \NC $2,5$  \NC \NR
\NC 2, 5 \NC 2, 5 \NC $2, 5$ \NC \NR
\NC 2.5  \NC 2.5  \NC $2.5$  \NC \NR
\NC 2. 5 \NC 2. 5 \NC $2. 5$ \NC \NR


Here's the results --- the image quality is not the best, but the (thin) spaces should still be visible.

behavior of autopunctuation settings for commas and periods with and without spaces

For completeness: the behaviour under Mark II.

  • Spaces are ignored.

  • Without \enablemathpunctuation (there is no \disablemathpunctuation):

    % default TeX behaviour
    2.5 or 2. 5 --> 2.5
    2,5 --> 2, 5
  • With \enablemathpunctuation:

    2.5 --> 2.5
    2,5 --> 2,5
share|improve this answer
Thanks for coming back to share this! – Daniel Lyons Dec 3 '12 at 19:18
My pleasure. Perhaps you could change the accepted answer to this one, as this one most accurately reflects the current state of affairs? – Esteis Dec 3 '12 at 23:33
Sure--I didn't realize I had that power. – Daniel Lyons Dec 3 '12 at 23:44

This is because autopunctuation is currently buggy. See also autopunctuation not working properly. The only difference between the questions is the symptom you describe. You are asking why math punctuation looks bad by default (i.e. when autopunctuation=no); mbork is asking why autopunctuation=yes does not do what he expects.

% this example uses \m{...} rather than $...$, 
% the result is identical, but \m{...} is preferred
\m{(2,5)} versus \m{(2, 5)} -- no, default
\m{(2.5)} versus \m{(2. 5)} -- no, default

\m{(2,5)} versus \m{(2, 5)} -- yes
\m{(2.5)} versus \m{(2. 5)} -- yes

show that autopunction=no leads to space after comma

To quote Aditya in the recent mailing list thread "A problem with autopunctuation":

[I would expect] autopunctuation [to behave] this: if comma is followed by a non-space, the comma should behave like an "ord"; if it is followed by a space, it should behave like a "punctuation". Clearly that is not happening.

That thread took place back at the start of this month, but the issue is still present in today's beta. I'll revive the issue in the mailing list.

share|improve this answer
This is a well known problem when the comma is used as a decimal separator as well as punctuation. My opinion is that no automatic setup can safely guard the user against this. The safest way out, I believe, is to properly segregate decimal numbers into the argument of a macro. – egreg Nov 30 '12 at 12:12
One more question then: it seems the \unit command circumvents the \setupmathematics[autopunctuation=yes] option. Is there a way I can make this look right? – Daniel Lyons Nov 30 '12 at 14:25
@DanielLyons As far as I know, the \unit command obeys the \setupmathematics[autopunctuation=yes] setup; whether that setup does something sensible at the moment is a separate matter, but $0.01$ and $\unit{0.01 kg}$ should give identical results. (Footnote: any autopunctuation rules operate on what \unit{...} outputs, actually.) Hans is currently working on fixing the autopunctuation behaviour. – Esteis Dec 2 '12 at 0:48
Thanks—I solved my problem by moving the value outside the unit: changing \unit{9.8 cm} into 9.8 \unit{cm}. – Daniel Lyons Dec 2 '12 at 7:07

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.