15

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 ?

  • 2
    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
  • 2
    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. – ChrisS Apr 27 '14 at 8:39
  • 2
    Please, take a look at tex.stackexchange.com/questions/154916/… – user13907 Apr 27 '14 at 8:58
  • 3
    Try \gdef.{{,}} instead of \gdef.{,} to get rid of the extra space. – Henri Menke Apr 27 '14 at 9:02
  • 2
    There is a package icomma, improving the math spacings for comma. – user31729 Apr 27 '14 at 9:03
13

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}

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.