Math & ScienceUsing SI units

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
latexforever
Posts: 120
Joined: Fri Nov 14, 2008 9:40 pm

Using SI units

Post by latexforever »

Hello everybody,

I have seen some packages for the writing of the SI (Système International) units in documents. I often write documents about Physics, so I have to use these units, but I simply wonder if it is important to use these packages or not. I also want to know how do the physicists, about this.

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Using SI units

Post by phi »

For simple expressions, it's not necessary:

Code: Select all

2 \cdot 10^{-3}\,\textup{kg}
But this method can become tedious, and it's often done wrong:

Code: Select all

2*10^{-3} kg
The latter means the multiplication of the variables k and g by 0.002, not 0.002 kilograms; furthermore, the multiplication sign is wrong. Packages for SI units help writing these expressions. A comprehensive package is siunitx, which could be used to simplify this quantity:

Code: Select all

\SI{2e-3}{kg}
The aim of siunitx is to replace eventually all existing unit formatting packages. It comes with an extensive manual that describes all features and also their correct application.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Using SI units

Post by localghost »

latexforever wrote:[...] I have seen some packages for the writing of the SI (Système International) units in documents. I often write documents about Physics, so I have to use these units, but I simply wonder if it is important to use these packages or not. I also want to know how do the physicists, about this. [...]
As a physicist, I feel directly addressed with this request. I also write lots of physical (and chemical) formulas. Not aware of any package, I started with formatting mathematical expressions containing units on my own. Since this can become very confused, I appreciate packages that save me a lot of time in typesetting this. I started with the simply structured units package and currently I'm using siunitx. The advantage of such packages is that they control things like text shape and spaces within the units and often simplify the input of number formats. You can rely on the fact that those packages typeset units as demanded.



Best regards
Thorsten¹
latexforever
Posts: 120
Joined: Fri Nov 14, 2008 9:40 pm

Using SI units

Post by latexforever »

Thanks for these very useful pieces of information. The package siunitx seems to be the most used one nowadays, and I also think it is better than the units package.
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: Using SI units

Post by josephwright »

Just to chime in as the author of siunitx. I do hope that is is "better" than the competition: this was the aim when writing it :-)
--
Joseph Wright
Joseph Wright
latexforever
Posts: 120
Joined: Fri Nov 14, 2008 9:40 pm

Using SI units

Post by latexforever »

Thanks, josephwright. It is really a good package. Just a question, if I may: when using

Code: Select all

\num
command, I've looked in the documentation of your package, but how do I always specify the decimal symbol to be the comma? I've seen

Code: Select all

decimalsymbol=comma
, but it seems not to work in my preamble. Here are my options:

Code: Select all

\usepackage[allowzeroexp=true,numdigits,obeymode=true,redefsymbols,textcelsius,textdegree,textminute,textmu,load={abbr,addn},decimalsymbol=comma]{siunitx}
.
But when I use:

Code: Select all

Calorie & $\cal$ & $\num{4,186}\SI{}{J}$\\
in my document (it is evidently in a tabular environment), I receive:
Invalid character `4,186' in numerical input. It is the same thing when I use a dot at the place of the comma. What's the matter? Thanks!
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: Using SI units

Post by phi »

What is the column type in your example? For guidelines about how to use siunitx for setting tabular material, please read sections 5 and 20.5 of the documentation.
latexforever
Posts: 120
Joined: Fri Nov 14, 2008 9:40 pm

Using SI units

Post by latexforever »

phi wrote:What is the column type in your example? For guidelines about how to use siunitx for setting tabular material, please read sections 5 and 20.5 of the documentation.
The problem is not only present in tabular environments. Even when I write

Code: Select all

$\num{4,186}\SI{}{J}$
in a text, it does not work (the

Code: Select all

\SI{}{J}$
does work).
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Using SI units

Post by phi »

The problem is the numdigits option, it expects a character string which is interpreted as digit list. If you don't provide a string, an empty one is taken and thus no character counts as digit. Just leave the entire option out.
Anyway, I recommend that you reread the siunitx documentation. A code like

Code: Select all

$\num{4,186}\SI{}{J}$
doesn't make any sense to me. Neither \num nor \SI require math mode, and the result is exactly the same without the dollar signs unless you use text figures (but in that case it would be better to redefine the mode option if required). \SI is meant for quantities composed of a number and a unit, it is useless if you don't provide a number, since in this case it's equivalent to \si which is the command intended to typeset units. Typography rules demand a small space between units and numbers, which your code lacks. After all, your code looks as if you wanted to write a simple quantity (4.186 joules); this shall be done using

Code: Select all

\SI{4,186}{J}
or

Code: Select all

\SI{4,186}{\joule}
Neither the math mode switches nor the separate \num command are required.
latexforever
Posts: 120
Joined: Fri Nov 14, 2008 9:40 pm

Re: Using SI units

Post by latexforever »

Thanks for your message.

In fact, I used dollars to test something. I was sure I hadn't understood something in the documentation of this package. I don't know why this wasn't clear to me.

Your explanations are clear, and I have understood. Anyway, I'll read a second time the package's documentation.

Thanks for your message.
Post Reply