3

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?

enter image description here

\documentclass[12pt,a4paper]{scrbook}

\usepackage{units}

\begin{document}

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

\end{document}
  • 4
    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
5

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}

enter image description here

4

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.

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

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}

output

0

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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