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.
- 259,911
- 34
- 706
- 1,036
- 109,596
3 Answers
Whether in math mode or not, I will
- always use
\numfromsiunitxfor 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!
- 36,086
-
1I 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 -
2I 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
-
@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
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}
- 757,742
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.
- 259,911
- 34
- 706
- 1,036
- 109,596
-
2I don't think you need
\makeat...here ;) Your explanation of the meaning of that command is incorrect, see here: http://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do – yo' Feb 10 '13 at 15:30 -
-
1
-
1Btw, shouldn't it be
\gdef.{{,}}so that it is an ordinary atom therefore tightly spaced? – yo' Feb 10 '13 at 16:28 -
1I accomplished this by loading icomma, but your solution also sounds good, thank you. – Henri Menke Feb 10 '13 at 19:25
.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