# Comma in math mode

In some countries one use comma as decimal separator instead of a dot.

I ususally use:

%%%% Une vrai virgule pour les décimaux
\DeclareMathSymbol{@}{\mathord}{letters}{"3B}


and $3@2$ to obtain 3,2 instead of $3,2$ that gives 3, 2 <- a uggly useless space after comma

I just find this :

\mathcode\.="8000
{\catcode\.=\active
\gdef.{,}}


That replaces automatically a dot by a comma in math mode, but with the ungly useless space.

Is there a way to combine both technics to have an automatic sustitution with a proper comma ?

Edit Sorry !

It was obvious :

%%%% Une vrai virgule pour les décimaux
\DeclareMathSymbol{@}{\mathord}{letters}{"3B}
\mathcode\.="8000
{\catcode\.=\active
\gdef.{@}}


Could this code have boder effect ? Is there a better or other way to get this ?

• Try to use the siunitx package. Here you can define your decimal-seperator (Denmark uses comma here as well) and use \num{3,2} in order to express your values. Note that the package can do alot more, check out the docs.
– Argo
Apr 27 '14 at 8:30
• The localisation options for siunitx are set in the document preamble, and thus can be changed in one place. Alternately, you could move them to a .sty file. Apr 27 '14 at 8:39
• Please, take a look at tex.stackexchange.com/questions/154916/…
– user13907
Apr 27 '14 at 8:58
• Try \gdef.{{,}} instead of \gdef.{,} to get rid of the extra space. Apr 27 '14 at 9:02
• There is a package icomma, improving the math spacings for comma.
– user31729
Apr 27 '14 at 9:03

To answer your original question. You could redefine . to produce another symbol in math mode.

\DeclareMathSymbol{.}{\mathord}{letters}{"3B}


Here in a MWE

\documentclass{article}
\mathchardef\period=\mathcode.
\DeclareMathSymbol{.}{\mathord}{letters}{"3B}
\begin{document}
$3.2$
$3\period2$
\end{document}


• Yes, it's easier than using @ and because the only use of . in mathmode is decimal separator. Apr 28 '14 at 8:47
• \mathchardef\period=\mathcode. before \DeclareMathSymbol{.} is better, isn't it? Apr 28 '14 at 9:27
• @egreg Nifty, thank you :-) I added this to my solution. Apr 28 '14 at 9:35

This is more simple syntax which working only in mathmode:

\mathcode,="002C
`