As the author of siunitx
I have some idea about the relative strengths of the various alternatives. There are various things that need to be done for units:
- Semantic input of units, so
\kilo\metre
rather than km
: this allows special effects such as reformatting fractions 'on the go' (some people prefer to use literal input, and this ideally needs to be supported too).
- Formatting of numbers, for example dividing up digits into groups.
- Correctly presenting awkward symbols such as the micro symbol.
- Setting the font: many guidelines call for units to be in upright roman font with no bold or italic variation.
- Keeping numbers and units together (no space breaking)
Many packages have been written to address one or other aspect of this question. For example, SIunits
is good at providing semantic input, whereas SIstyle
focusses on correct typesetting but leaves the input to the user. On the other hand, unitsdef
sticks to doing only units and does not worry about other aspects.
The aim of the siunitx
package is to cover all of the requirements above, and to provide a way that package behaviour can be altered. Thus it uses a series of key-value options that will change how the output is formatted. The options can be applied to the entire document or to an individual piece of input. It also is designed to work in either math or text mode equally well. I have also been very careful to provide up to date advice about the internationally-agreed units in the documentation of siunitx
.
As a demo, using the latest release of siunitx
the following all show off the package:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{itemize}
\item \qty{100}{\degreeCelsius}
\item \qty{3e5}{\km\per\s} or \qty[per-mode = symbol]{3e5}{\km\per\s}
\item \unit{\newton\metre\squared\per\kilogram\squared} or
\unit[per-mode = symbol]{\newton\metre\squared\per\kilogram\squared}
\item \( \qty{10}{\kilo\hertz} = \qty{1}{\per\second\tothe{4}} \)
\item \qty[parse-numbers = false]{\sin(x)}{\metre}
\end{itemize}
\end{document}
There are a couple of notes to bear in mind if using siunitx
. First, it requires e-TeX, which can be an issue with some publishers (even over 10 years after it was finalised!). Secondly, the formatting does take up some time. There are settings to turn things off but it's always the case that working by hand will ultimately be faster. However, the upside of clearer and more flexible input is in my opinion worth it.
One other point is that siunitx
is under development, with bug fixes and new features (there is a list for v3.1). In contrast, both SIunits
and SIstyle
are depreciated: bug fixes only. The units
and unitsdef
packages have not been updated for many years.
Use the SIunits package. Note that SI units are to be typeset in roman type, not italics! And please don't mix information and units. “g C” (with a thin space) can mean only one thing, namely the product of the units gram and Coulomb. Mixing in information like C for carbon with the units is a cardinal sin. A major point of standardised units with a standardised notation is disambiguation – if you see an SI unit in a paper far from your own speciality you should still be able to understand what it means.
Please refer to the style guides at the NIST SI units home page for further details.
Best Answer
I came to this question thinking "yeah! Why?" but upon reading the currently extant comments and answer I have already changed my tune and am now tending the other way. What I realized, thinking about it and about my small interactions with this package, is that it provides much the same service within LaTeX as LaTeX (or even just TeX itself) provides for writing as a whole. To understand that point, consider the alternatives in communicating some math in writing via a computer:
Write it phonetically, as it were. Words are words, of course, but Greek letters are spelled out, or perhaps drawn in some ad-hoc ASCII art, and more complicated formulas are hacked together in an unspecified manner that may or may not be clear from context.
Write it in TeX, in which Greek letters are spelled out in macros, more complicated formulas are hacked together in some possibly awful manner...and then the result is "compiled" into a document making it all look like you had in mind, so no harm done if your source was a little more schematic than you'd have liked.
The
siunitx
package does exactly this, but instead of math formulas, it does SI-style units. Sure, one could write the same symbols that normally appear in such units askg
ors$^{-1}$
, but that can go wrong visually very easily depending on if the unit appears in math mode or not (just imagine how that affects the latter!), or if several units become crammed together, or (egreg's quite valid observation) broken across a line. Then you may decide that instead ofs$^{-1}$
you really want/s
for the unit of hertz, necessitating a global change of notation.These are all the kinds of problems that are handled in TeX by defining macros containing your preferred styles for
\kilogram
and\hertz
and so on. Thesiunitx
just organizes the whole project of defining these macros and their relationships to each other, and gives a lot of aesthetic options on top of it.Basically, it boils down to "Why would anyone want to program their document in the first place?", to which the answer is "It's easier to write well-structured documents that way."