TUGboat, Volume 39 (2018), No. 2

119
hopefully it will appear within a dayor two.
It has been suggested by themaintainer of the SIstyle packagethat integration of the two be would
worth considering. Other suggestions
have also been made in the newsgroupand by private mail. I am therefore
planning to review the existing
situation and see what improvements
are needed/desirable. As well as
SIunits and SIstyle, I am going tolook at numprint, units, unitsdef andhepunits for inspiration/points toconsider/etc.
So far, I have some outline ideas,
for example: ...

siunitx: Past, present and future
Joseph Wright
Abstract
The siunitx package provides a powerful toolkit for
typesetting numbers and units in LATEX. By incorporating detail about the agreed rules for presenting
scientific data, siunitx enables authors to concentrateon the meaning of their input and leave the package
to deal with the formatting. Here, I look at thebackground to the package, what led me from version 1 to version 2, and why version 3 is now underdevelopment.
1

Introduction

Typesetting units naturally lends itself, in TEX, tousing macro support. The formal rules for SI units [1]link unit names with unit symbols, and it’s not surprising that several authors have created packages
that tackle some or all of the subtleties involved. I’ve
detailed some of these issues and packages before,
when I last looked at siunitx for TUGboat [6]. Here,I’ll briefly recap some of those key points, then explore what is driving efforts toward a third versionof the package.
2

Early days

I soon had quite a list, and work on the new
package began in earnest, and by February 2008 thefirst testing release was out. After a little more work,and a rename, the first official version of siunitx hit
CTAN on the 16th of April 2008 [7].
3The core features of siunitx have been present fromthat first version, and are pretty well-known. I’dsummarise them as• Automatic, semantic formatting of quantities(numbers with units)• Parsing and manipulation of numbers• Control of printing of numbers, units andquantities• Alignment of numbers in tables• Unified key–value interface for controlling
options

Before siunitx, there were a variety of units-relatedpackages, including one called SIunits [3], which deals
with providing semantic macros for units. My involvement started when I followed up an apparentlyinnocuous post to comp.text.tex from Stefan Pinnow in November 2007, reporting a straightforward
bug
I want to report that \reciprocal,\rpsquare, \rpcubic, etc. output iswritten as "-1" instead of a $-1$, when
the package option "textstyle" is used.
I tried to contact Mr. Heldoorn, but hedidn’t answer until now. Does anyone
have an idea what to do?
Being young(ish) and foolish, after looking at
the bug itself and finding that SIunits was no longer
maintained, I volunteered to pick up the package.
Even more foolishly, I then followed up with thefollowing in November 2007:
As some of you may have noticed,
following a recent bug reportconcerning the SIunits package,
I have taken over as the package
maintainer. I have uploaded a bug fix
for the specific issue to CTAN, and so

Key features

For me, the package has always been about units,
and the fundamental idea that input such as\joule\per\mole\per\kelvincan give J mol−1 K−1 or molJ K or J/(mol K), depending on the settings in force. This idea has been there
since day one, and the code has carried throughmore-or-less unchanged.
4From version one to version two

Version one of siunitx worked well for delivering on
those key features. Releases progressed rapidly, culminating in version 1.4c in February 2010. However,adding new features was a problem: internally it wasa bit of a mess. For example, if you look at the oldcode you’ll see:• Internals other than unit parsing taken fromexisting packages and somewhat haphazard
siunitx: Past, present and future

120

TUGboat, Volume 39 (2018), No. 2• Sub-optimal key–value choices• Essentially no internal API• Poor self-coded loops• ...
Around this time, Will Robertson contacted
me to ask what I thought of the LATEX3 language
expl3 [4]. This was before I joined the LATEX team,and expl3 looked a bit different than today, but thecentral ideas were all there. I liked the ideas, but at
the time was a bit wary of loading an external library(and thus a dependency). So I started by picking
out the ideas and re-coding them in my development
setup for version two. It soon became clear that I
needed a lot of the ideas, and I realised that I’d bemuch better off just requiring expl3.
Work on the second version of siunitx took me
into expl3 programming, and asking the team for lotsof features. In particular, I wanted to have key–value
support built-in, rather than needing to use anotherpackage to do that. So I wrote some code, which
I called keys3, to solve the problem. It turned outthat was my application to join the team: it’s today
l3keys in expl3 itself!
The rewrite gave me a chance to significantly
revise internal API aspects, and to significantly improve performance. It also came of course with newfeatures for users, and completely new names forthe key–value interface. In the v2.0 release, I didn’t
include backward-compatibility: I soon learned, andthat’s been there since a few days after the second
generation release.
5

From version two to version three

Version two retains most of the features that version
one had, but as well as the good ones, it turns out itkeeps some of the bad ones too! In particular• Assumptions about fonts: OpenType, etc.
• No code-level API expl3• Internals still too messy• Testing the PDF documentation only
• Monolithic source• Still too slow
5.1

Font control

The font assumptions carry all the way through from
SIstyle [2], and which I adjusted only slightly. Theapproach currently used is
1. Detect current font type using LATEX internaldata
2. Insert everything inside \text
3. Apply \ensuremath inside the box
Joseph Wright

4. Perhaps apply \text again (for text modeoutput)
5. Force the font with e.g. \mathrm or \rmfamily
That requires a lot of work, and more importantly is unreliable: it’s not always easy to get theright font ‘inside’ the output section. It also fails
very badly with OpenType math mode fonts, wherethe ideas in classical TEX about math families simply
don’t apply. So there is a new approach: for version
three
1. Detect current font type using LATEX internaldata
2. Set any aspects that are needed
3. Only use an \mbox if math version has to bealteredThis ‘minimal change’ approach is much fasterthan the current one, and is much better at respecting
font changes. I’m still finalising compatibility forcurrent edge-case setups, but I believe the new code
is much preferable overall.
5.2

The code API and testing

The development of siunitx version two very muchparallels that of expl3 as a truly usable language: inthe time I’ve been using it, expl3 has gone from a setof clever experiments to a well-established approachto coding in TEX. But keeping all of siunitx up-todate with ideas has been tricky.
The biggest issue is that when I wrote the current release code, there were just user commands
such as \num and internal implementation. However,it’s now clear that each user command should havea documented code-level interface. Moreover, theseinterfaces should all be properly tested: the teamhave created l3build precisely for that [5]. Combining
these ideas, the new code will take the input\siunitx_unit_format:nN{ \joule \per \mole }\l_tmpa_tl\tl_show:N \l_tmpa_tl
and create as output> \l_tmpa_tl=\mathrm {J}\,\mathrm {mol}^{-1}
Notice that this is easy to test, and highlights anothernew idea: the parsing step should produce the sameresults as a user typing in the formatting ‘by hand’.
5.3

First alpha release

At the time of writing, the development of version
three has reached the first alpha stage: the code isusable but there are real gaps. Currently, all of thefollowing are working:TUGboat, Volume 39 (2018), No. 2121

• Core functionality:

Appendix: demos– Unit parsing and formatting– Real number formatting– Tabular columns• Existing API: \num, \SI, \si, S-column• New (experimental) document API: \unit, \qty

Simple number formatting:\num{123}\\
123\num{1234}\\1234\num{12345}\\12 345\num{0.123}\\0.123\num{0,1234} \\0.1234\num{.12345} \\0.123 45
3.45 × 10−4 \num{3.45d-4} \\\num{-e10}−1010

There are some big areas left to do, such as
multi-part numbers, ranges, lists and most importantly the compatibility layer for dealing with existing
documents. However, that is all relatively manageable, and I expect to be done around the end of theyear. So 2019 should see siunitx reach version 3.0.0,
and I hope retain its place as the units package forLATEX.
References[1] Bureau International des Poids et Mesures.
The international system of units (SI), 2010.
bipm.org/en/measurement-units/[2] D. Els. The SIstyle package, 2008.
ctan.org/pkg/sistyle

Angles:\ang{10}\\10◦\ang{12.3} \\12.3◦\ang{4,5}\\4.5◦\ang{1;2;3} \\1◦ 20 300\ang{;;1}\\100\ang{+10;;} \\10◦\ang{-0;1;}−0◦ 10Units as macros:
kg m s−2
g cm−32
V lm3 F−1
m2 Gy−1 lx3
Hs[3] M. Heldoorn and J. Wright. The SIunits
package: Consistent application of SI units,2007. ctan.org/pkg/siunits[4] LATEX Project. The expl3 package and LATEX3
programming, 2018. ctan.org/pkg/expl3[5] LATEX Project. l3build: Checking and building
packages, 2018. ctan.org/pkg/l3build[6] J. Wright. siunitx: A comprehensive (SI) units
package. TUGboat 32(1):95–98, 2011. tug.org/TUGboat/tb32-1/tb100wright-siunitx.pdf[7] J. Wright. siunitx — a comprehensive (SI) units
package, 2018. ctan.org/pkg/siunitx
 Joseph WrightMorning Star
2, Dowthorpe End
Earls Barton
Northampton NN6 0NH
United Kingdom
joseph dot wright (at)morningstar2.co.uk\si{\kilo\gram\metre\per\square\second} \\\si{\gram\per\cubic\centi\metre}\\\si{\square\volt\cubic\lumen\per\farad} \\\si{\metre\squared\per\gray\cubic\lux} \\\si{\henry\second}

Quantities:
1.23 J mol−1 K−1
0.23 × 107 cd
1.99/kgC
1.345 mol\SI[mode = text]{1.23}{J.mol^{-1}.K^{-1}} \\\SI{.23e7}{\candela} \\\SI[per-mode = symbol]{1.99}{\per\kilogram} \\\SI[per-mode = fraction]{1,345}{\coulomb\per\mole}siunitx: Past, present and future