I know there are a few packages related to typesetting units:
unitsdef
units
, which can be seen as a "base package" used byunitsdef
SIunits
siunitx
, which is the successor toSIunits
- maybe others? like
cjwunits
andhepunits
What is the difference between them? Do they also work inside Math mode? And, more importantly, which one should I use?
Suggestion for people trying to answer this question: show some examples of how to typeset both simple and complex units. For instance, try typesetting these items:
- 100 Celsius
- 3 x 10^5 km/s
- gravitational constant is measured in N m^2/kg^2
- 10 kHz = 1 s^{-4}
- sin(x) meters
I think these examples cover most needs when writing scientific texts: simple measurements (value + simple unit), values written in scientific notation, simple fractional units, complex fractional and squared units, units without any value accompanying them, units with arbitrary exponents, and arbitrary math code instead of a simple value.
Best Answer
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:\kilo\metre
rather thankm
: 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).Many packages have been written to address one or other aspect of this question. For example,
SIunits
is good at providing semantic input, whereasSIstyle
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 ofsiunitx
.As a demo, using the latest release of
siunitx
the following all show off the package: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, bothSIunits
andSIstyle
are depreciated: bug fixes only. Theunits
andunitsdef
packages have not been updated for many years.