[Tex/LaTex] Why use a package to typeset units

best practicessiunitxunits

I've seen a lot of posts about different packages for typesetting units and their relative strengths and weaknesses. Most posts seem to agree that the siunitx package is the most up to date package, but I haven't really figured out the advantages of using a package at all. What is the advantage of writing something like:

\SI{10}{\kilo\gram\meter\per\second\squared}

when you could just write:

kg m s$^-2$

Or for numbers, what's the difference between

\num{10}

and

10

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:

  1. 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.

  2. 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 as kg or s$^{-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 of s$^{-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. The siunitx 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."