11

For my study of physics I have to do various lab reports. Normally I just process all my data using python, gnuplot or Mathematica and copy it from there to my TeX document. Unfortunately all these applications use the . (dot) as a decimal seperator. Because I study in Germany the german standard says that I have to use , (comma) as the decimal seperator. In most cases the supervisors of the lab are forgiving, but one of them told me to redo my whole lab report because of this. Now I don't want to search all the 15 pages to replace all dots with commas. I could have used a regular expression but this still implied editing the whole file.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Henri Menke
  • 109,596
  • Although it is very interesting (and quite useful), it does not pose a question. This is a Q&A site. So a better way would be to ask "How to change . to , in mathmode". Then you can yourself answer that question. Please see the discussion: http://meta.tex.stackexchange.com/questions/4/asking-a-question-and-answering-it-yourself-straight-away/5#5 – nickpapior Feb 10 '13 at 15:11
  • No problem. I just didn't find that question here so I thought it might be helpful for others if I share my solution. – Henri Menke Feb 10 '13 at 15:17
  • Great! This is much better! :) Also there is no need to sign of with your name. I have deleted that. – nickpapior Feb 10 '13 at 15:18

3 Answers3

15

Whether in math mode or not, I will

  • always use \num from siunitx for any numerical literals,
  • always use . for the decimal marker in the decimal literals,
  • but later set the global setting in the preamble to specify the decimal marker for the rendered output.
\documentclass{article}

\usepackage{siunitx}
\sisetup{
    %output-decimal-marker={,}% just uncomment if you want to use comma as the decimal marker!
}

\begin{document}
$\num{3.14}$ is not the value of $\pi$, \num{2.718281828} is not the value of $e$.
\end{document}

This mechanism makes your document portable!

  • 1
    I hate using , as the decimal marker because comma separated list becomes ambiguous. For example, what does (1,2,3,4) mean in the context of 3-dimensional point? In scientific purposes, we have to use . for the decimal marker! – kiss my armpit Feb 10 '13 at 15:53
  • 2
    I totally agree with you on that. The problem is that I needed the supervisors signature for this lab report. And in the lab not the truth is correct but what is signed by the supervisors :( – Henri Menke Feb 10 '13 at 16:19
  • 2
    @GarbageCollector This is not about hating, but about national typography rules. In Czech language, the rules are similar, and you get easily used to ; as a list seperator. With the proper spacing (tight around , and loose after ;) the result is just ok. – yo' Feb 10 '13 at 16:30
  • @tohecz: The typographic rules might be adopted without the scientific standards in mind. The countries using , as the decimal marker should change the rule because there is no benefit to keep. :-) – kiss my armpit Feb 10 '13 at 16:34
  • 2
    The countries using non-metric measurng systems should change it ;-) – Tobi Feb 10 '13 at 17:06
  • @Tobi: Does , as the decimal marker conform to the standard metric system? – kiss my armpit Feb 10 '13 at 17:09
  • 2
    @GarbageCollector No, but the imperial units are confusing (and ambiguous). In my opinion more than using ,; instead of .,. Since this discussion starts to be off-topic, this is my last comment here. – yo' Feb 10 '13 at 17:24
  • 1
    @GarbageCollector: ORLY;)? Imho, decimal comma is actually better than decimal point, since in handwriting the point is more easy to lose. Having a more visible sign is a significant benefit. (And btw, in print, since after the decimal comma there's no space and after the separator comma there's a thin space, you don't even have to resort to a semicolon.) – mbork Feb 10 '13 at 20:06
  • @mbork: A funny grammar arises, for example: "The 3 numbers are 1,2; 3,4; and 5,6; They are in decimal form." Let's compare it with "The 3 numbers are 1.2, 3.4, and 5.6; They are in decimal form." – kiss my armpit Feb 11 '13 at 00:50
14

It is perhaps less intrusive just to change the mathcode of . rather than globally define an active . to be a comma.

\mathcode`\.=\mathcode`\,

Would define . to be like , (as in the self-answer) If you want the . to be mathord so it os not followed by a thin space then you could use

\DeclareMathSymbol{.}{\mathord}{letters}{"3B}
David Carlisle
  • 757,742
7

The Trick

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

Explanation

But what does this do? I'll try to explain what the above code is doing. If I'm wrong please correct me.

\mathcode`\.="8000 makes the comma "active" in mathmode, i.e. everytime the compiler runs over a comma code is executed instead of a comma being typeset. {\catcode`\.=\active \gdef.{,}} is the code that gets executed in the beginning, where \catcode`\.=\active makes . active and then defines \gdef.{,} which substitutes the . with a ,. That's it!

Keep in mind that now EVERY . in mathmode is replaced with a ,. The code I presented doesn't care if the . you wrote is a decimal seperator of a full stop. If you want to type a full stop consider using \text{.}, or define yourself a macro.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Henri Menke
  • 109,596