17

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 ?

Tarass
  • 16,912
  • 4
    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 08:30
  • Does \num{3,2} change depending of the country you are? Is the result will be right for a Danish and for an English, each in his country ? I look for some thing automatic you put in your .sty that some one esle coud change and cherry on the cake with no special syntax. – Tarass Apr 27 '14 at 08:35
  • 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 08:39
  • That I understand. Once you typeset \num{3,2} as a Danish or a French, you'll see 3,2. How can an English see 3.2? Not from the pdf of course, but if I give him the .tex source. – Tarass Apr 27 '14 at 08:45
  • 2
    Please, take a look at http://tex.stackexchange.com/questions/154916/space-after-comma-in-units-package –  Apr 27 '14 at 08:58
  • 3
    Try \gdef.{{,}} instead of \gdef.{,} to get rid of the extra space. – Henri Menke Apr 27 '14 at 09:02
  • 2
    There is a package icomma, improving the math spacings for comma. –  Apr 27 '14 at 09:03
  • @HenriMenke But I steal it from you ;-) – Tarass Apr 27 '14 at 09:10
  • 2
    There's nor real "full" solution, for the simple reason that in some cases you want the comma to be ordinary (numbers) and in other cases (ordered pairs, for instance) to be punctuation. The icomma package does its best by checking what's next, but needs some help in certain cases. The best is to use \num. – egreg Apr 27 '14 at 09:41
  • AFAIK the only use of . is decimal separator, otherwise one uses \dots and so ever. In fact one could always use . as decimal separator in mathmode, and if one wants he should add the automatic substitution code in is preambule or .sty. Did I say something wrong ? ;-) – Tarass Apr 27 '14 at 10:50
  • One might as well say that some countries use a dot instead of a comma as decimal separator… ;) – Bernard Apr 27 '14 at 14:36
  • @HenriMenke There is a huge and amazing side effect with your 3 lines: \input{./file} gives ! LaTeX Error: File `,/file.tex' not found. – Tarass Apr 28 '14 at 08:03
  • 1
    @Tarass Changing catcodes will ALWAYS have its downsides. Better use @DavidCarlisle's solution \mathcode`\.=\mathcode`\,. – Henri Menke Apr 28 '14 at 08:10
  • @HenriMenke sounds better ;-) thank you. – Tarass Apr 28 '14 at 08:14
  • In addition to @Argo's comment, let me know that in Danish typography it is legal to use do as the decimal point in scientific contexts. That is what we recommend our users to do, because retrofitting a 50 pages thesis with \num etc takes a very long time. – daleif Apr 28 '14 at 09:42

2 Answers2

15

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

Henri Menke
  • 109,596
0

This is more simple syntax which working only in mathmode:

\mathcode`,="002C