forked from josephwright/siunitx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
siunitx.tex
3164 lines (2919 loc) · 115 KB
/
siunitx.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\iffalse meta-comment
File: siunitx.tex Copyright (C) 2014-2020 Joseph Wright
It may be distributed and/or modified under the conditions of the
LaTeX Project Public License (LPPL), either version 1.3c of this
license or (at your option) any later version. The latest version
of this license is in the file
https://www.latex-project.org/lppl.txt
This file is part of the "siunitx bundle" (The Work in LPPL)
and all files in that bundle must be distributed together.
The released version of this bundle is available from CTAN.
-----------------------------------------------------------------------
The development version of the bundle can be found at
https://github.com/josephwright/siunitx
for those people who are interested.
-----------------------------------------------------------------------
\fi
\documentclass{l3doc}
% The next line is needed so that \GetFileInfo will be able to pick up
% version data (quite apart from making the demos work).
\usepackage{siunitx}
\DeclareSIUnit\noop{\relax} % For printing prefixes
\DeclareSIPower\quartic\tothefourth{4} % For demos
\DeclareSIUnit\KWH{kWh}
\DeclareSIQualifier\polymer{pol}
\DeclareSIQualifier\catalyst{cat}
% Commands for this document
\usepackage{xparse}
\NewDocumentCommand\acro{m}{\textsc{#1}}
\NewDocumentCommand\email{m}{\href{mailto:#1}{\nolinkurl{#1}}}
\NewDocumentCommand\ext{m}{\texttt{.#1}}
\NewDocumentCommand\foreign{m}{\textit{#1}}
\NewDocumentCommand\opt{m}{\texttt{#1}}
% Tidy up the above in bookmarks
\makeatletter
\pdfstringdefDisableCommands{%
\let\acro\@firstofone
\let\ext\@firstofone
\let\foreign\@firstofone
\let\opt\@firstofone
}
\makeatother
\NewDocumentCommand\DescribePrefix{m}{%
#1 &
\cs{#1} &
\unit{\csname #1\endcsname\noop}
}
\NewDocumentCommand\DescribeUnit{O{#2}m}{%
#1 &
\cs{#2} &
\unit{\csname #2\endcsname}
}
% For creating code demonstrations
% This needs access to some code-level interfaces in listings
\usepackage{listings}
\makeatletter
\lst@RequireAspects{writefile}
\newsavebox\LaTeXdemo@box
\lstnewenvironment{LaTeXdemo}[1][code and example]
{%
\global\let\lst@intname\@empty
\edef\LaTeXdemo@end{%
\expandafter\noexpand\csname LaTeXdemo@@#1@end\endcsname
}%
\@nameuse{LaTeXdemo@@#1}%
}
{\LaTeXdemo@end}
\newcommand\LaTeXdemo@new[3]{%
\@namedef{LaTeXdemo@@#1}{#2}%
\@namedef{LaTeXdemo@@#1@end}{#3}%
}
\newcommand*\LaTeXdemo@common{%
\setkeys{lst}
{%
basicstyle = \small\ttfamily,
basewidth = 0.51em,
gobble = 2,
language = [LaTeX]{TeX},
}%
}
\newcount\LaTeXdemo@count
\newcommand*\LaTeXdemo@input{%
\catcode`\^^M = 10\relax
\input{\jobname-\number\LaTeXdemo@count.tmp}%
}
\LaTeXdemo@new{code and example}{%
\setbox\LaTeXdemo@box=\hbox\bgroup
\global\advance\LaTeXdemo@count by 1 %
\lst@BeginAlsoWriteFile{\jobname-\number\LaTeXdemo@count.tmp}%
\LaTeXdemo@common
}{%
\lst@EndWriteFile
\egroup
\begin{center}
\ifdim\wd\LaTeXdemo@box > 0.48\linewidth
\begin{minipage}{\linewidth}
\usebox\LaTeXdemo@box
\end{minipage}%
\par
\begin{minipage}{\linewidth}
\LaTeXdemo@input
\end{minipage}
\else
\begin{minipage}{0.48\linewidth}
\LaTeXdemo@input
\end{minipage}%
\hfil
\begin{minipage}{0.48\linewidth}
\usebox\LaTeXdemo@box
\end{minipage}%
\fi
\end{center}
}
\LaTeXdemo@new{code and float}{%
\global\advance\LaTeXdemo@count by 1 %
\lst@BeginAlsoWriteFile{\jobname-\number\LaTeXdemo@count.tmp}%
\LaTeXdemo@common
}{%
\lst@EndWriteFile
\LaTeXdemo@input
}
\LaTeXdemo@new{code only}{\LaTeXdemo@common}{}
\makeatother
% For demos
\usepackage[french,german,spanish,UKenglish]{babel}
\AtBeginDocument{\shorthandoff{:<>}}
\usepackage{translations}
\usepackage{cancel}
\usepackage{collcell}
\usepackage{sansmath}
\newlength{\mylength}
% For table demos
\usepackage{datatool}
\usepackage{multirow}
\usepackage[table]{xcolor}
% Has to come after xcolor
\usepackage{pgfplots}
\pgfplotsset{compat = 1.16, compat/show suggested version = false}
\usepackage{xfp}
% For the extra-long tables
\usepackage{xtab}
% Design changes
\usepackage{caption}
\makeatletter
\edef\@floatboxreset{%
\unexpanded\expandafter{\@floatboxreset}%
\noexpand\centering
}
\makeatother
\usepackage[osf]{mathpazo}
\hypersetup{hidelinks}
\begin{document}
\GetFileInfo{siunitx.sty}
\title{%
\pkg{siunitx} -- A comprehensive (SI) units package%
\thanks{This file describes \fileversion,
last revised \filedate.}%
}
\author{%
Joseph Wright%
\thanks{%
E-mail:
\href{mailto:joseph.wright@morningstar2.co.uk}
{joseph.wright@morningstar2.co.uk}%
}%
}
\date{Released \filedate}
\maketitle
\tableofcontents
\begin{abstract}
Physical quantities have both numbers and units, and each physical quantity
should be expressed as the product of a number and a unit. Typesetting
physical quantities requires care to ensure that the combined mathematical
meaning of the number--unit combination is clear. In particular, the SI units
system lays down a consistent set of units with rules on how these are to be
used. However, different countries and publishers have differing conventions
on the exact appearance of numbers (and units). The \pkg{siunitx} package
provides a set of tools for authors to typeset quantities in a consistent
way. The package has an extended set of configuration options which make it
possible to follow varying typographic conventions with the same input
syntax. The package includes automated processing of numbers and units, and
the ability to control tabular alignment of numbers.
\end{abstract}
\begin{documentation}
\section{Introduction}
The correct application of units of measurement is very important in technical
applications. For this reason, carefully-crafted definitions of a coherent
units system have been laid down by the \foreign{Conférence Génrale des
Poids et Mesures} (CGPM): this has resulted in the \foreign{Système
International d'Unités}~(SI). At the same time, typographic conventions for
correctly displaying both numbers and units exist to ensure that no loss of
meaning occurs in printed matter.
The \pkg{siunitx} package aims to provide a unified method for \LaTeX{} users
to typeset numbers and units correctly and easily. The design philosophy of
\pkg{siunitx} is to follow the agreed rules by default, but to allow variation
through option settings. In this way, users can use \pkg{siunitx} to follow the
requirements of publishers, co-authors, universities, \foreign{etc}.\ without
needing to alter the input at all.
\section{Using the \pkg{siunitx} package}
\subsection{Numbers}
\begin{function}{\num}
\begin{syntax}
\cs{num}\oarg{options}\marg{number}
\end{syntax}
\end{function}
Numbers are automatically formatted by the \cs{num} macro. This takes one
optional argument, \meta{options}, and one mandatory one, \meta{number}. The
contents of \meta{number} are automatically formatted. The formatter removes
both \enquote{soft} (\verb*| |) and \enquote{hard} spaces (|\,| and |~|),
automatically identifies exponents (as standard marked using |e|, |E|, |d| or
|D|) and adds the appropriate spacing of large numbers. With the standard
settings a leading zero is added before a decimal marker, if needed: both |.|
and "," are recognised as decimal markers.
\begin{LaTeXdemo}
\num{123} \\
\num{1234} \\
\num{12345} \\
\num{0.123} \\
\num{0,1234} \\
\num{.12345} \\
\num{3.45d-4} \\
\num{-e10}
\end{LaTeXdemo}
Note that numbers are parsed before typesetting, which does have a performance
overhead (only obvious with very large amounts of numerical input). The parser
understands a range of input syntaxes, as demonstrated above.
\begin{function}{\numlist}
\begin{syntax}
\cs{numlist}\oarg{options}\marg{numbers}
\end{syntax}
\end{function}
Lists of numbers may be processed using the \cs{numlist} function. Each
\meta{number} is given within the list of \meta{numbers} within a brace pair,
as the list can have a flexible length.
\begin{LaTeXdemo}
\numlist{10;30;50;70}
\end{LaTeXdemo}
\begin{function}{\numproduct}
\begin{syntax}
\cs{numproduct}\oarg{options}\marg{numbers}
\end{syntax}
\end{function}
Runs of products of numbers may be inserted using the \cs{numproduct} function.
This acts in the same way as \cs{num}, but inserts either a symbol or phrase
between the entries. The latter should be separated by |x| tokens.
\begin{LaTeXdemo}
\numproduct{10 x 30}
\end{LaTeXdemo}
\begin{function}{\numrange}
\begin{syntax}
\cs{numrange}\oarg{options}\marg{number1}\marg{number2}
\end{syntax}
\end{function}
Simple ranges of numbers can be handled using the \cs{numrange} function. This
acts in the same way as \cs{num}, but inserts a phrase or other text between
the two entries.
\begin{LaTeXdemo}
\numrange{10}{30}
\end{LaTeXdemo}
\subsection{Angles}
\begin{function}{\ang}
\begin{syntax}
\cs{ang}\oarg{options}\marg{angle}
\end{syntax}
\end{function}
Angles can be typeset using the \cs{ang} command. The \meta{angle} can be given
either as a decimal number or as a semi-colon separated list of degrees,
minutes and seconds, which is called \enquote{arc format} in this document. The
numbers which make up an angle are processed using the same system as other
numbers.
\begin{LaTeXdemo}
\ang{10} \\
\ang{12.3} \\
\ang{4,5} \\
\ang{1;2;3} \\
\ang{;;1} \\
\ang{+10;;} \\
\ang{-0;1;}
\end{LaTeXdemo}
\subsection{Units}
\begin{function}{\unit}
\begin{syntax}
\cs{unit}\oarg{options}\marg{unit}
\end{syntax}
\end{function}
The symbol for a unit can be typeset using the \cs{unit} macro: this provides
full control over output format for the unit. Like the \cs{num} macro,
\cs{unit} takes one optional and one mandatory argument. The unit formatting
system can accept two types of input. When the \meta{unit} contains literal
items (for example letters or numbers) then \pkg{siunitx} converts |.| and |~|
into inter-unit product and correctly positions sub- and superscripts specified
using |_| and |^|. The formatting methods will work with both math and text
mode.
\begin{LaTeXdemo}
\unit{kg.m/s^2} \\
\unit{g_{polymer}~mol_{cat}.s^{-1}}
\end{LaTeXdemo}
The second operation mode for the \cs{unit} macro is an \enquote{interpreted}
system, Here, each unit, SI multiple prefix and power is given a macro name.
These are entered in a method very similar to the reading of the unit name in
English.
\begin{LaTeXdemo}
\unit{\kilo\gram\metre\per\square\second} \\
\unit{\gram\per\cubic\centi\metre} \\
\unit{\square\volt\cubic\lumen\per\farad} \\
\unit{\metre\squared\per\gray\cubic\lux} \\
\unit{\henry\second}
\end{LaTeXdemo}
On its own, this is less convenient than the direct method, although it does
use meaning rather than appearance for input. However, the package allows you
to define new unit macros; a large number of pre-defined abbreviations are also
supplied. More importantly, by defining macros for units, instead of literal
input, new functionality is made available. By altering the settings used by
the package, the same input can yield a variety of different output formats.
For example, the \cs{per} macro can give reciprocal powers, slashes or be used
to construct units as fractions.
\begin{function}{\qty}
\begin{syntax}
\cs{qty}\oarg{options}\marg{number}\marg{unit}
\end{syntax}
\end{function}
Very often, numbers and units are given together. Formally, the value of a
quantity is the product of the number and the unit, the space being regarded as
a multiplication sign~\cite{SI:5.3.3}. The \cs{qty} macro combines the
functionality of \cs{num} and \cs{unit}, and makes this both possible and easy.
The \meta{number} and \meta{unit} arguments work exactly like those for the
\cs{num} and \cs{unit} macros, respectively.
\begin{LaTeXdemo}
\qty[mode = text]{1.23}{J.mol^{-1}.K^{-1}} \\
\qty{.23e7}{\candela} \\
\qty[per-mode = symbol]{1.99}{\per\kilogram} \\
\qty[per-mode = fraction]{1,345}{\coulomb\per\mole}
\end{LaTeXdemo}
It is possible to set up the unit macros to be available outside of the
\cs{qty} and \cs{unit} functions. This is not the standard behaviour as there
is the risk of name clashes (for example, \cs{bar} is used by other packages,
and several packages define \cs{degree}). Full details of using \enquote{stand
alone} units are found in \ref{sec:units:creating}.
\subsection{The unit macros}
The package always defines the basic set of SI units with macro names. This
includes the base SI units, the derived units with special names and the
prefixes. A small number of powers are also given pre-defined names. Full
details of units in the SI are available on-line~\cite{BIPM}.
The seven base SI units are always defined (Table~\ref{tab:unit:base}). In
addition, the macro \cs{meter} is available as an alias for \cs{metre}, for
users of US spellings. The full details of the base units are given in the SI
Brochure~\cite{SI:2.1}.
\begin{table}
\caption{SI base units.}
\label{tab:unit:base}
\begin{tabular}{@{}lll@{}}
\toprule
Unit & Command & Symbol \\
\midrule
\DescribeUnit{ampere} \\
\DescribeUnit{candela} \\
\DescribeUnit{kelvin} \\
\DescribeUnit{kilogram} \\
\DescribeUnit{metre} \\
\DescribeUnit{mole} \\
\DescribeUnit{second} \\
\bottomrule
\end{tabular}
\end{table}
The SI also lists a number of units which have special names and
symbols~\cite{SI:2.2.2}: these are listed in Table~\ref{tab:unit:derived}.
\begin{table}
\caption{Coherent derived units in the SI with special names and
symbols.}
\label{tab:unit:derived}
\begin{tabular}{@{}lll>{\qquad}lll@{}}
\toprule
Unit & Command & Symbol & Unit & Command & Symbol \\
\midrule
\DescribeUnit{becquerel} &
\DescribeUnit{newton} \\
\DescribeUnit[degree Celsius]{degreeCelsius} &
\DescribeUnit{ohm} \\
\DescribeUnit{coulomb} &
\DescribeUnit{pascal} \\
\DescribeUnit{farad} &
\DescribeUnit{radian} \\
\DescribeUnit{gray} &
\DescribeUnit{siemens} \\
\DescribeUnit{hertz} &
\DescribeUnit{sievert} \\
\DescribeUnit{henry} &
\DescribeUnit{steradian} \\
\DescribeUnit{joule} &
\DescribeUnit{tesla} \\
\DescribeUnit{lumen} &
\DescribeUnit{volt} \\
\DescribeUnit{katal} &
\DescribeUnit{watt} \\
\DescribeUnit{lux} &
\DescribeUnit{weber} \\
\bottomrule
\end{tabular}
\end{table}
In addition to the official SI units, \pkg{siunitx} also provides macros for a
number of units which are accepted for use in the SI although they are not SI
units. Table~\ref{tab:unit:accepted} lists the \enquote{accepted}
units~\cite{SI:T6}. Some units are fundamental physical quantities, and these
are non-SI but can be used within the SI
(Table~\ref{tab:unit:physical},~\cite{SI:T7}). There are also a set of non-SI
units which are used in certain defined circumstances
(Table~\ref{tab:unit:other}), although they are not necessarily officially
sanctioned~\cite{SI:T8}. Finally, for specialist applications, a range of
\acro{CGS} units are sanctioned (Table~\ref{tab:unit:CGS})~\cite{SI:T9}.
The command \cs{percent} is also provided for use in units: this is accepted
with the SI as detailed in Section~5.3.7 of the Brochure~\cite{SI:5.3.7}.
\begin{table}
\caption{Non-SI units accepted for use with the International System of
Units.}
\label{tab:unit:accepted}
\begin{tabular}{@{}lll@{}}
\toprule
Unit & Command & Symbol \\
\midrule
\DescribeUnit{day} \\
\DescribeUnit{degree} \\
\DescribeUnit{hectare} \\
\DescribeUnit{hour} \\
\DescribeUnit{litre} \\
& \cs{liter} & \unit{\liter} \\
\DescribeUnit[minute (plane angle)]{arcminute} \\
\DescribeUnit[minute (time)]{minute} \\
\DescribeUnit[second (plane angle)]{arcsecond} \\
\DescribeUnit{tonne} \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}
\caption{Non-SI units whose values in SI units must be obtained
experimentally.}
\label{tab:unit:physical}
\begin{tabular}{@{}lll@{}}
\toprule
Unit & Command & Symbol \\
\midrule
\DescribeUnit[astronomical unit]{astronomicalunit}\\
\DescribeUnit[atomic mass unit]{atomicmassunit} \\
\DescribeUnit[a.u.~of action]{auaction} \\
\DescribeUnit[a.u.~of charge]{aucharge} \\
\DescribeUnit[a.u.~of energy]{auenergy} \\
\DescribeUnit[a.u.~of length]{aulength} \\
\DescribeUnit[a.u.~of mass]{aumass} \\
\DescribeUnit[a.u.~of time]{autime} \\
\DescribeUnit{bohr} \\
\DescribeUnit{dalton} \\
\DescribeUnit{electronvolt} \\
\DescribeUnit{hartree} \\
\DescribeUnit[n.u.~of action]{nuaction} \\
\DescribeUnit[n.u.~of mass]{numass} \\
\DescribeUnit[n.u.~of speed]{nuspeed} \\
\DescribeUnit[n.u.~of time]{nutime} \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}
\caption{Other non-SI units.}
\label{tab:unit:other}
\begin{tabular}{@{}lll@{}}
\toprule
Unit & Command & Symbol \\
\midrule
\DescribeUnit[ångström]{angstrom} \\
\DescribeUnit{bar} \\
\DescribeUnit{barn} \\
\DescribeUnit{bel} \\
\DescribeUnit{decibel} \\
\DescribeUnit{knot} \\
\DescribeUnit[millimetre of mercury]{millimetremercury} \\
\DescribeUnit[nautical mile]{nauticalmile} \\
\DescribeUnit{neper} \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}
\caption{Non-SI units associated with the \acro{CGS}.}
\label{tab:unit:CGS}
\begin{tabular}{@{}lll@{}}
\toprule
Unit & Command & Symbol \\
\midrule
\DescribeUnit{dyne} \\
\DescribeUnit{erg} \\
\DescribeUnit{gal} \\
\DescribeUnit{gauss} \\
\DescribeUnit{maxwell} \\
\DescribeUnit{oersted} \\
\DescribeUnit{phot} \\
\DescribeUnit{poise} \\
\DescribeUnit{stilb} \\
\DescribeUnit{stokes} \\
\bottomrule
\end{tabular}
\end{table}
In addition to the units themselves, \pkg{siunitx} provides pre-defined macros
for all of the SI prefixes (Table~\ref{tab:unit:prefix})~\cite{SI:3.1}. The
spelling \enquote{\cs{deka}} is provided for US users as an alternative to
\cs{deca}.
\begin{table}
\caption{SI prefixes.}
\label{tab:unit:prefix}
\sisetup{table-number-alignment = right, table-format = 2}
\begin{tabular}{@{}llcS[table-format = -2]>{\qquad}llcS@{}}
\toprule
Prefix & Command & Symbol & \multicolumn{1}{l}{Power} &
Prefix & Command & Symbol & \multicolumn{1}{l@{}}{Power} \\
\midrule
\DescribePrefix{yocto} & -24 &
\DescribePrefix{deca} & 1 \\
\DescribePrefix{zepto} & -21 &
\DescribePrefix{hecto} & 2 \\
\DescribePrefix{atto} & -18 &
\DescribePrefix{kilo} & 3 \\
\DescribePrefix{femto} & -15 &
\DescribePrefix{mega} & 6 \\
\DescribePrefix{pico} & -12 &
\DescribePrefix{giga} & 9 \\
\DescribePrefix{nano} & -9 &
\DescribePrefix{tera} & 12 \\
\DescribePrefix{micro} & -6 &
\DescribePrefix{peta} & 15 \\
\DescribePrefix{milli} & -3 &
\DescribePrefix{exa} & 18 \\
\DescribePrefix{centi} & -2 &
\DescribePrefix{zetta} & 21 \\
\DescribePrefix{deci} & -1 &
\DescribePrefix{yotta} & 24 \\
\bottomrule
\end{tabular}
\end{table}
A small number of pre-defined powers are provided as macros. \cs{square} and
\cs{cubic} are intended for use before units, with \cs{squared} and \cs{cubed}
going after the unit.
\begin{LaTeXdemo}
\unit{\square\becquerel} \\
\unit{\joule\squared\per\lumen} \\
\unit{\cubic\lux\volt\tesla\cubed}
\end{LaTeXdemo}
Generic powers can be inserted on a one-off basis using the \cs{tothe} and
\cs{raiseto} macros. These are the only macros for units which take an
argument:
\begin{LaTeXdemo}
\unit{\henry\tothe{5}} \\
\unit{\raiseto{4.5}\radian}
\end{LaTeXdemo}
Reciprocal powers are indicated using the \cs{per} macro. This applies to the
next unit only, unless the \opt{sticky-per} option is turned on.
\begin{LaTeXdemo}
\unit{\joule\per\mole\per\kelvin} \\
\unit{\joule\per\mole\kelvin} \\
\unit{\per\henry\tothe{5}} \\
\unit{\per\square\becquerel}
\end{LaTeXdemo}
As for generic powers, generic qualifiers are also available using the \cs{of}
function:
\begin{LaTeXdemo}
\unit{\kilogram\of{metal}} \\
\qty[qualifier-mode = bracket]
{0.1}{\milli\mole\of{cat}\per\kilogram\of{prod}}
\end{LaTeXdemo}
When the \pkg{cancel} package is loaded, it is possible to \enquote{cancel out}
units using the \cs{cancel} macro. This applies to the next unit, in a similar
manner to a prefix. The \cs{highlight} macro is also available to selectively
color units. Both \cs{cancel} and \cs{highlight} are outside of the normal
semantic meaning of units, but are provided as they may be useful in some
cases.
\begin{LaTeXdemo}
\unit[per-mode = fraction]
{\cancel\kilogram\metre\per\cancel\kilogram\per\second} \\
\unit{\highlight{red}\kilogram\metre\per\second} \\
\unit[unit-color = purple]
{\highlight{blue}\kilogram\metre\per\second}
\end{LaTeXdemo}
\subsection{Unit abbreviations}
In addition to the \enquote{full} names, \pkg{siunitx} loads a set of
abbreviated versions of the SI units (Table~\ref{tab:unit:abbr}). The standard
\pkg{siunitx} settings only create these abbreviations within the scope of the
\cs{unit} and \cs{qty} functions, meaning that no clashes should occur (for
example with the standard \cs{pm} symbol).
\begin{center}
\label{tab:unit:abbr}
\tablefirsthead{%
\toprule
\multicolumn{1}{@{}l}{Unit} &
\multicolumn{1}{l}{Abbreviation} &
\multicolumn{1}{l@{}}{Symbol} \\
\midrule
}
\tablehead{%
\multicolumn{3}{@{}l@{}}{\emph{Continued from previous page}} \\
\toprule
\multicolumn{1}{@{}l}{Unit} &
\multicolumn{1}{l}{Abbreviation} &
\multicolumn{1}{l@{}}{Symbol} \\
\midrule
}
\tabletail{%
\bottomrule
\multicolumn{3}{@{}r@{}}{\emph{Continued on next page}} \\
}
\tablelasttail{\bottomrule}
\begin{xtabular}{@{}lcc@{}}
\DescribeUnit[femtogram]{fg} \\
\DescribeUnit[picogram]{pg} \\
\DescribeUnit[nanogram]{ng} \\
\DescribeUnit[microgram]{ug} \\
\DescribeUnit[milligram]{mg} \\
\DescribeUnit[gram]{g} \\
\DescribeUnit[kilogram]{kg} \\
\DescribeUnit[atomic mass unit]{amu} \\
\midrule
\DescribeUnit[picometre]{pm} \\
\DescribeUnit[nanometre]{nm} \\
\DescribeUnit[micrometre]{um} \\
\DescribeUnit[millimetre]{mm} \\
\DescribeUnit[centimetre]{cm} \\
\DescribeUnit[decimetre]{dm} \\
\DescribeUnit[metre]{m} \\
\DescribeUnit[kilometre]{km} \\
\midrule
\DescribeUnit[attosecond]{as} \\
\DescribeUnit[femtosecond]{fs} \\
\DescribeUnit[picosecond]{ps} \\
\DescribeUnit[nanosecond]{ns} \\
\DescribeUnit[microsecond]{us} \\
\DescribeUnit[millisecond]{ms} \\
\DescribeUnit[second]{s} \\
\midrule
\DescribeUnit[femtomole]{fmol} \\
\DescribeUnit[picomole]{pmol} \\
\DescribeUnit[nanomole]{nmol} \\
\DescribeUnit[micromole]{umol} \\
\DescribeUnit[millimole]{mmol} \\
\DescribeUnit[mole]{mol} \\
\DescribeUnit[kilomole]{kmol} \\
\midrule
\DescribeUnit[picoampere]{pA} \\
\DescribeUnit[nanoampere]{nA} \\
\DescribeUnit[microampere]{uA} \\
\DescribeUnit[milliampere]{mA} \\
\DescribeUnit[ampere]{A} \\
\DescribeUnit[kiloampere]{kA} \\
\midrule
\DescribeUnit[microlitre]{ul} \\
\DescribeUnit[millilitre]{ml} \\
\DescribeUnit[litre]{l} \\
\DescribeUnit[hectolitre]{hl} \\
\DescribeUnit[microliter]{uL} \\
\DescribeUnit[milliliter]{mL} \\
\DescribeUnit[liter]{L} \\
\DescribeUnit[hectoliter]{hL} \\
\midrule
\DescribeUnit[millihertz]{mHz} \\
\DescribeUnit[hertz]{Hz} \\
\DescribeUnit[kilohertz]{kHz} \\
\DescribeUnit[megahertz]{MHz} \\
\DescribeUnit[gigahertz]{GHz} \\
\DescribeUnit[terahertz]{THz} \\
\midrule
\DescribeUnit[millinewton]{mN} \\
\DescribeUnit[newton]{N} \\
\DescribeUnit[kilonewton]{kN} \\
\DescribeUnit[meganewton]{MN} \\
\midrule
\DescribeUnit[pascal]{Pa} \\
\DescribeUnit[kilopascal]{kPa} \\
\DescribeUnit[megapacal]{MPa} \\
\DescribeUnit[gigapascal]{GPa} \\
\midrule
\DescribeUnit[milliohm]{mohm} \\
\DescribeUnit[kilohm]{kohm} \\
\DescribeUnit[megohm]{Mohm} \\
\midrule
\DescribeUnit[picovolt]{pV} \\
\DescribeUnit[nanovolt]{nV} \\
\DescribeUnit[microvolt]{uV} \\
\DescribeUnit[millivolt]{mV} \\
\DescribeUnit[volt]{V} \\
\DescribeUnit[kilovolt]{kV} \\
\midrule
\DescribeUnit[watt]{W} \\
\DescribeUnit[microwatt]{uW} \\
\DescribeUnit[milliwatt]{mW} \\
\DescribeUnit[kilowatt]{kW} \\
\DescribeUnit[megawatt]{MW} \\
\DescribeUnit[gigawatt]{GW} \\
\DescribeUnit[joule]{J} \\
\DescribeUnit[microjoule]{uJ} \\
\DescribeUnit[millijoule]{mJ} \\
\DescribeUnit[kilojoule]{kJ} \\
\DescribeUnit[electronvolt]{eV} \\
\DescribeUnit[millielectronvolt]{meV} \\
\DescribeUnit[kiloelectronvolt]{keV} \\
\DescribeUnit[megaelectronvolt]{MeV} \\
\DescribeUnit[gigaelectronvolt]{GeV} \\
\DescribeUnit[teraelectronvolt]{TeV} \\
\DescribeUnit[kilowatt hour]{kWh} \\
\midrule
\DescribeUnit[farad]{F} \\
\DescribeUnit[femtofarad]{fF} \\
\DescribeUnit[picofarad]{pF} \\
\midrule
\DescribeUnit[kelvin]{K} \\
\midrule
\DescribeUnit[decibel]{dB} \\
\end{xtabular}
\end{center}
\subsection{Creating new macros}
The various macro components of a unit have to be defined before they can be
used. The package supplies a number of common definitions, but new definitions
are also possible. As the definition of a logical unit should remain the same
in a single document, these creation functions are all preamble-only.
\begin{function}{\DeclareSIUnit}
\begin{syntax}
\cs{DeclareSIUnit}\oarg{options}\marg{unit}\marg{symbol}
\end{syntax}
\end{function}
New units are produced using the \cs{DeclareSIUnit} macro. The \meta{symbol}
can contain literal input, other units, multiple prefixes, powers and \cs{per},
although literal text should not be intermixed with unit macros. Units can be
created with \meta{options} from the usual list understood by \pkg{siunitx},
and apply the specific unit macro only. The (first) optional argument to
\cs{qty} and \cs{unit} can be used to override the settings for the unit: an
example is the \cs{degree} unit.
\begin{LaTeXdemo}
\qty{3.1415}{\degree}
\end{LaTeXdemo}
This is declared in the package (effectively) as
\begin{LaTeXdemo}[code only]
\DeclareSIUnit[quantity-product = {}]
\degree{\text{\textdegree}}
\end{LaTeXdemo}
The spacing can still be altered at point of use:
\begin{LaTeXdemo}
\qty{67890}{\degree} \\
\qty[quantity-product = \,]{67890}{\degree}
\end{LaTeXdemo}
The meaning of a pre-defined unit can be altered by using \cs{DeclareSIUnit}
after loading \pkg{siunitx}. This will overwrite the original definition with
the newer version.
\begin{function}{\DeclareSIPrefix}
\begin{syntax}
\cs{DeclareSIPrefix}\marg{prefix}\marg{symbol}\marg{powers-ten}
\end{syntax}
\end{function}
The standard SI powers of ten are defined by the package, and are
described above. However, the user can define new prefixes with
\cs{DeclareSIPrefix}. For example, \cs{kilo} is defined
\begin{LaTeXdemo}[code only]
\DeclareSIPrefix\kilo{k}{3}
\end{LaTeXdemo}
\begin{function}{\DeclareSIPower}
\begin{syntax}
\cs{DeclareSIPower}\marg{symbol-before}\marg{symbol-after}\marg{power}
\end{syntax}
\end{function}
This function creates two symbols, one for use before a unit, the second
for use after a unit, both of which are equivalent to the \meta{power}.
For example, one might use
\begin{LaTeXdemo}[code only]
\DeclareSIPower\quartic\tothefourth{4}
\end{LaTeXdemo}
with the functions then used in the document as
\begin{LaTeXdemo}
\unit{\kilogram\tothefourth}\\
\unit{\quartic\metre}
\end{LaTeXdemo}
\begin{function}{\DeclareSIQualifier}
\begin{syntax}
\cs{DeclareSIQualifier}\marg{qualifier}\marg{symbol}
\end{syntax}
\end{function}
Following the syntax of the other macros, qualifiers are created with the
\cs{DeclareSIQualifier} command. In contrast to the other parts of a unit,
there are no pre-defined qualifiers. It is therefore entirely up to the user to
create these. For example, to identify the mass of a product created when using
a particular catalyst, the preamble could contain:
\begin{LaTeXdemo}[code only]
\DeclareSIQualifier\polymer{pol}
\DeclareSIQualifier\catalyst{cat}
\end{LaTeXdemo}
and then in the body the document could read
\begin{LaTeXdemo}
\qty{1.234}{\gram\polymer\per\mole\catalyst\per\hour}
\end{LaTeXdemo}
\subsection{Tabular material}
Aligning numbers in tabular content is handled by a new column type, the
\texttt{S} column. This new column type can align material using a number of
different strategies, with the aim of flexibility of output without needing to
alter the input. The method used as standard is to place the decimal marker in
the number at the centre of the cell and to align the material appropriately
(Table~\ref{tab:S:standard}).
\begin{LaTeXdemo}[code and float]
\begin{table}
\caption{Standard behaviour of the \texttt{S} column type.}
\label{tab:S:standard}
\begin{tabular}{S}
\toprule
{Some Values} \\
\midrule
2.3456 \\
34.2345 \\
-6.7835 \\
90.473 \\
5642.5 \\
1.2e3 \\
e4 \\
\bottomrule
\end{tabular}
\end{table}
\end{LaTeXdemo}
The \texttt{S} column will attempt to automatically detect material which
should be placed before or after a number, and will maintain the alignment of
the numerical data (Table~\ref{tab:S:extras}). If the material could be
mistaken for part of a number, it should be protected by braces. The use of
\cs{color} in a table cell will also be detected and will override any general
color applied by \pkg{siunitx}.
\begin{LaTeXdemo}[code and float]
\begin{table}
\caption{Detection of surrounding material in an \texttt{S}
column.}
\label{tab:S:extras}
\begin{tabular}{S[color = orange]}
\toprule
{Some Values} \\
\midrule
12.34 \\
\color{purple} 975,31 \\
44.268 \textsuperscript{\emph{a}} \\
\bottomrule
\end{tabular}
\end{table}
\end{LaTeXdemo}
\begin{function}{\tablenum}
\begin{syntax}
\cs{tablenum}\oarg{options}\marg{number}
\end{syntax}
\end{function}
Within more complex tables, aligned numbers may be desirable within the
argument of \cs{multicolumn} or \cs{multirow}.\footnote{Provided by the
\pkg{multirow} package} The \cs{tablenum} function is available to achieve
alignment in these situations: this is, in effect, a macro version of the
\texttt{S} column (Table~\ref{tab:tablenum}).
\begin{LaTeXdemo}[code and float]
\begin{table}
\caption{Controlling complex alignment with the \cs{tablenum}
macro.}
\label{tab:tablenum}
\begin{tabular}{@{}lr@{}}
\toprule
Heading & Heading \\
\midrule
Info & More info \\
Info & More info \\
\multicolumn{2}{c}{\tablenum[table-format = 4.4]{12,34}} \\
\multicolumn{2}{c}{\tablenum[table-format = 4.4]{333.5567}} \\
\multicolumn{2}{c}{\tablenum[table-format = 4.4]{4563.21}} \\
\bottomrule
\end{tabular}
\hfil
\begin{tabular}{@{}lr@{}}
\toprule
Heading & Heading \\
\midrule
\multirow{2}*{\tablenum{88,999}} & aaa \\
& bbb \\
\multirow{2}*{\tablenum{33,435}} & ccc \\
& ddd \\
\bottomrule
\end{tabular}
\end{table}
\end{LaTeXdemo}
\section{Package control options}
\subsection{The key--value control system}
The package uses a range of different key types:
\begin{description}
\item[\texttt{Choice}] Takes a limited number of choices, which are described
separately for each key.
\item[\texttt{Integer}] Requires a number as the argument.
\item[\texttt{Length}] Requires a length, either as a literal
value such as \texttt{2.0cm}, or stored as a \LaTeX{} length.
\item[\texttt{Literal}] A key which uses the value(s) given directly,
either to check input or in output.
\item[\texttt{Macro}] Requires a macro, which may need a single argument.
\item[\texttt{Math}] Similar to a \texttt{literal} option, but the input is
always used in math mode, irrespective of other \pkg{siunitx} settings.
Thus to text-mode only input must be placed inside the argument of a
\cs{text} macro.
\item[\texttt{Meta}] These are options which actually apply a number of
other options.
\item[\texttt{Switch}] These are on--off switches, and recognise \opt{true}
and \opt{false}. Giving just the key name also turns the key on.
\end{description}
The tables of option names use these descriptions to indicate how the keys
should be used.
\subsection{Printing}