Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

in my language it's typical to write comma in numbers instead of a dot (12,34 instead of 12.34). However, if I write ",", it automatically inserts space right after the comma. To overcome this, I have to write "{,}" instead. Is is possible to somehow convince latex to write "," instead of "." in mathmode? Thanks for all your suggestions.

share|improve this question
    
Welcome to TeX.SX!](meta.tex.stackexchange.com/q/1436) Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. The packages icomma or siunitx may be of use to you! –  Christian Hupfer Sep 2 at 18:50
3  
Prefer siunitx over icomma please. Especially if you want to typeset some units, you will love to have it. –  Johannes_B Sep 2 at 18:55
    
There's also numprint that is babel-aware. –  Bernard Sep 2 at 18:58
2  
Your language is Czech as I can see from your profile. You can see page 41 of the book "TeX pro pragmatiky" math.feld.cvut.cz/olsak/tpp.html the paragraph "Desetinná čárka místo tečky". –  wipet Sep 2 at 20:05

3 Answers 3

up vote 4 down vote accepted

Is i[t] possible to somehow convince latex to write "," instead of "." in mathmode?

Yes, it's possible to convince LaTeX to print a comma with no space around it while you write with a usual dot. E.g., 2.718 will print 2,718 with the correct spacing. If you want the usual comma (with a space after it) you need to write a comma rather than a dot, e.g., (x,y) \in \mathbb{R}^2 will print something like (1, 2) ∈ ℝ².

You only need the line @wipet said

\mathcode`\.=`\,

My original answer, which is much larger is this one

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

This defines . to be “math active”, so inside of math mode, LaTeX will look at its active definition and use it. So, I define . to be a \mathord{,} which is what you want, with no spaces. Of course you need, as I said before, to write the dot, and it will be printed in the .pdf as a comma correctly spaced.

share|improve this answer
2  
There exists more simple solution: \mathcode`.=`,. Then $3.1415$ prints 3,1415 with correct spacing. –  wipet Sep 2 at 19:55
    
@wipet Didn't know that. –  Manuel Sep 2 at 19:59
    
@wipet - Can you think of any downsides to making . a math-active character? –  Mico Sep 2 at 20:03
    
I mean that the effect is the same. –  wipet Sep 2 at 20:08
    
@Manuel - Can you think of downsides to making . a math-active character? –  Mico Sep 2 at 20:15

You have two well-established options:

  • Load the siunitx package with the option output-decimal-marker={,}, and then write \num{123,456}. The option to treat , as the decimal marker carries over to numbers typeset in tables if the package's S column type is specified.

    \documentclass{article}
    \usepackage[output-decimal-marker={,}]{siunitx}  
    \begin{document}
    \num{123,456}
    \end{document}
    

    The instruction \num works in text and math mode. The package's other commands that can typeset numbers (and units, as in \SI{9,81}{\newton\per\second\squared}) also works in both modes.

    You didn't mention your language, but in case it's German you could also load the siunitx package with the option locale=DE. Doing so will automatically invoke the rule to typeset the decimal marker as a comma. As of September 2014, the package offers five language/region localizations: DE, FR, UK, US, and ZA (South Africa). If you'd offer to provide information to create a new localization (CZ, say), I'm sure the maintainer of the siunitx package would be delighted to hear from you.

  • Back on the subject of typesetting numbers in tables, you could also use the dcolumn package and define your own column type, say d, as follows:

    \newcolumntype{d}[1]{,,{#1}}
    

    Then, in a tabular or array environment, use a column specification such as d{2.5} to inform LaTeX that the numbers in that column can have up to 2 digits before the decimal marker and 5 digits after the marker, which has been set to be a comma.

share|improve this answer
1  
I would suggest to test first if there is a locale for the used language. Like locale=DE. –  Johannes_B Sep 2 at 19:15
    
@Johannes_B - Thanks. I've added a paragraph to mention the locale=.. possibility. –  Mico Sep 2 at 19:19
1  
If I understand the question, the OP want to do less typing than {,} especially only dot. And you suggest to do more typing: \num{1,2} (four characters more than {,}). –  wipet Sep 3 at 8:03
    
@wipet - I'm absolutely no good at mind-reading, that's for sure. My impression, though, is that the OP would prefer to keep using commas as decimal markers in both input and output. The capabilities of dcolumn's d column type and siunitx's S column type for tabular material certainly make it easy to use commas as input decimal markers, without having to do anything special about the numbers (such as using a \num wrapper). And, if the numbers come in conjunction with units, then \SI{<number>}{<unit>} requires no extra typing either, whether commas or periods are used on input. –  Mico Sep 3 at 8:35
1  
@Tom83B Trust me, it works: \documentclass{article} \usepackage[locale=DE]{siunitx} \begin{document} \num{12,35} \end{document} –  Johannes_B Sep 3 at 14:32

Well, if you only want to suppress the space, you can write $12{,}34$. This is what I mostly do if I feel that siunitx is an overkill (I'm a mathematician, I rarely work with units, however, I do work with floats).

share|improve this answer
    
If you work a lot with tabular and array environments, you should definitely acquaint yourself -- if you haven't already done so long ago... -- with the capabilities of the S column type of the siunitx package and the d column type of the dcolumn package. –  Mico Sep 2 at 20:06
    
@Mico I'm aware of that, thanks. –  tohecz Sep 2 at 20:07
    
@tohecz -- Yeah, I kind of suspected you were aware of it. :-) –  Mico Sep 2 at 20:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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