# Space after comma in units package

I have a problem with using the units package. In my thesis I used it sometimes in math environment, sometimes not. Now I realized that there is an addition space after the comma in math mode. I think this is a problem of European and American writing of decimal comma and decimal point.

Can you tell me, how I can delete the space after the comma in the math environment?

\documentclass[12pt,a4paper]{scrbook}

\usepackage{units}

\begin{document}

$V=\unit[0,5]{V}$
\unit[0,5]{V}

\end{document}

• Noone uses unit anymore, switch to siunitx, it can be configured to use comma in the proper manner. Besides in some countries, even if comma is the standard decimal sign, it may still be legal to use the dot in scientific context – daleif Jan 19 '14 at 21:43
• Well, so I'm nobody... It's an very large document and it would take a lot of time to switch everything from units to siunitx. Is there any faster way instead of replacing everything? – Thomas Jan 19 '14 at 22:42
• @daleif I wish CTAN would indicate deprecations... – Raphael Jan 20 '14 at 10:26

If you want to use units, use the icomma package.

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{units,icomma}
\begin{document}
$V=\unit[0,5]{V}$
\unit[0,5]{V}
\end{document}


Reading your comments, you would like to keep your \unit command working. Lucky for you, LaTeX allows you to redefine command. Because \unit should behave as \SI when an optional argument is given and as \si when only a unit is given, some trickery is involved.

\documentclass[12pt,a4paper]{scrbook}

\usepackage{units}
\usepackage{siunitx}
\sisetup{output-decimal-marker = {,}}

\let\unit\relax
\DeclareRobustCommand{\unit}[2][]{
\if\relax\detokenize{#1}\relax
\si{#2}
\else
\SI{#1}{#2}
\fi}

\begin{document}
$V=\unit[0,5]{V}$
\unit[0,5]{V}
\end{document}


We first let the old \unitdo nothing. Then we redefine it as to behave like \si when the optional argument is empty, or as \SI when it is not.

• With xparse it's even easier: \NewDocumentCommand{\unit}{om}{\IfNoValueTF{#1}{\si{#2}}{\SI{#1}{#2}}} – egreg Jan 20 '14 at 9:55

As daleif says, use the siunitx package:

\documentclass{scrbook}

\usepackage[
locale = DE % Gives comma as decimal separator.
]{siunitx}

\begin{document}

$V = \SI{0.5}{\V}$

\end{document}


If you have to use units, then you can surround the comma with curly braces in math mode:

\documentclass[12pt,a4paper]{scrbook}
\usepackage{units}

\begin{document}

$V=\unit[0{,}5]{V}$
\unit[0,5]{V}

\end{document}