-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsiunitx-number.dtx
5014 lines (5013 loc) · 161 KB
/
siunitx-number.dtx
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-number.dtx Copyright (C) 2014-2019,2021-2024 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.
%
% -----------------------------------------------------------------------
%
%<*driver>
\documentclass{l3doc}
% Additional commands needed in this source
\ProvideDocumentCommand\email{m}{\href{mailto:#1}{\nolinkurl{#1}}}
\ProvideDocumentCommand\foreign{m}{\textit{#1}}
% The next line is needed so that \GetFileInfo will be able to pick up
% version data
\usepackage{siunitx}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{siunitx.sty}
%
% \title{^^A
% \pkg{siunitx-number} -- Parsing and formatting numbers^^A
% \thanks{This file describes \fileversion,
% last revised \filedate.}^^A
% }
%
% \author{^^A
% Joseph Wright^^A
% \thanks{^^A
% E-mail:
% \email{[email protected]}^^A
% }^^A
% }
%
% \date{Released \filedate}
%
% \maketitle
%
% \begin{documentation}
%
% This submodule is dedicated to parsing and formatting numbers. A small number
% of \LaTeXe{} math mode commands are assumed to be available as part of the
% formatted output. The sign commands \cs{mp}, \cs{pm}, \cs{ll}, \cs{le},
% \cs{gg} and \cs{ge} are used to replace two-character input; \cs{pm}
% is also required for the output of uncertainties, and \cs{sim} for
% approximate values. The standard settings require \cs{times}. For the display
% of colored negative numbers, the command \cs{color} is assumed to be
% available. Where the latter may apply, numbers should be printed inside a
% group: note that \TeX{} grouping is not added \emph{within} formatted numbers
% as they may need to be decomposed into parts (see
% \cs{siunitx_number_output:NN}). Such a color will be the \emph{first} part of
% the result, meaning that a test for an initial |\color| and following
% brace group may be used to detect/remove/adjust this part.
%
% \section{Formatting numbers}
%
% \begin{function}{\siunitx_number_parse:nN, \siunitx_number_parse:VN}
% \begin{syntax}
% \cs{siunitx_number_parse:nN} \Arg{number} \meta{tl~var}
% \end{syntax}
% Parses the \emph{number} and stores the resulting internal representation
% in the \meta{tl~var}. The parsing is influenced by the various key--value
% settings for numerical input. The \meta{number} should comprise a single
% real value, possibly with comparator, uncertainty and exponent parts.
% If the number is invalid, or if number parsing is disabled, the result will
% be an entirely empty \meta{tl~var}.
%
% The structure of a valid number is:
% \begin{quote}
% \marg{comparator}\marg{sign}\marg{integer}\marg{decimal}
% \marg{uncertainty}\\
% \marg{exponent sign}\marg{exponent}
% \end{quote}
% where the two sign parts must be single tokens if present, and all other
% components must be given in braces. The number will have at least one digit
% for either the \meta{integer} and \meta{exponent} parts. The
% \meta{uncertainty} part should either be blank or contain an
% \meta{identifier} (as a brace group), followed by one or more data entries.
% Valid uncertainty \meta{identifiers} currently are
% \begin{itemize}
% \item[\texttt{S}] A single symmetrical uncertainty (\foreign{e.g.}~a
% statistical standard uncertainty). The data item here is a single
% value representing the uncertainty in the least-significant digits.
% \item[\texttt{A}] A single unsymmetrical uncertainty. The data item here
% contains two brace groups, each using the same least-significant digit
% approach as the \texttt{S} type. The positive component is given first
% and the negative second, and neither has a sign.
% \item A combination of \texttt{S} and \texttt{A} entries, with one data
% item per entry. These are then iterated over to be output in order.
% \end{itemize}
% If a decimal marker should be explicitly recorded as present for a value
% with no decimal digits, the \meta{decimal} part should contain
% \cs{empty}.
% \end{function}
%
% \begin{function}{\siunitx_number_process:NN, \siunitx_number_process:cc}
% \begin{syntax}
% \cs{siunitx_number_process:N} \meta{tl~var1} \meta{tl~var2}
% \end{syntax}
% Applies a set of number processing operations to the \meta{internal
% number} stored in the \meta{tl~var1}, \foreign{viz.}~in order
% \begin{enumerate}
% \item Dropping uncertainty
% \item Converting to scientific mode (or similar)
% \item Rounding
% \item Dropping zero decimal part
% \item Forcing a minimum number of digits
% \end{enumerate}
% with the result stored in \meta{tl~var2}.
% \end{function}
%
% \begin{function}[EXP]
% {
% \siunitx_number_output:N, \siunitx_number_output:c
% \siunitx_number_output:n,
% \siunitx_number_output:NN, \siunitx_number_output:cN
% \siunitx_number_output:nN
% }
% \begin{syntax}
% \cs{siunitx_number_output:N} \meta{number}
% \cs{siunitx_number_output:NN} \meta{number} \meta{marker}
% \end{syntax}
% Formats the \meta{number} (in the \pkg{siunitx} internal format),
% producing the result in a form suitable for typesetting in math mode.
% The details for the formatting are controlled by a number of key--value
% options. Note that \emph{formatting} does not apply any manipulation
% (processing) to the number. This function is usable in an \texttt{e}-
% or \texttt{x}-type expansion, and further uncontrolled expansion is
% prevented by appropriate use of |\exp_not:n| internally.
%
% In the \texttt{NN} version, the \meta{marker} token is inserted at each
% possible alignment position in the output, \foreign{viz.}
% \begin{itemize}
% \item Between the comparator and the integer (\emph{before} any
% sign for the integer)
% \item Between the sign and the first digit of the integer
% \item Both sides of the decimal marker
% \item Both sides of the separated uncertainty sign (\foreign{i.e.}~after
% the decimal part and before any integer uncertainty part)
% \item Both sides of the decimal marker for a separated uncertainty
% \item Both sides of the multiplication symbol for the exponent part.
% \end{itemize}
%
% The \texttt{n} and \texttt{nN} version take a token list, which should
% be in the internal \pkg{siunitx} format.
% \end{function}
%
% \begin{function}{\siunitx_number_format:nN}
% \begin{syntax}
% \cs{siunitx_number_format:nN} \Arg{number} \meta{tl~var}
% \end{syntax}
% Carries out a combination of \cs{siunitx_number_parse:nN},
% \cs{siunitx_number_process:NN} and \cs{siunitx_number_output:N} using
% \texttt{x}-type expansion to place the result in the \meta{tl~var}. If
% \cs{l_siunitx_number_parse_bool} if \texttt{false}, the input is simply
% stored inside the \meta{tl~var} inside \cs{ensuremath}.
% \end{function}
%
% \begin{function}[EXP]
% {
% \siunitx_number_adjust_exponent:Nn ,
% \siunitx_number_adjust_exponent:nn ,
% \siunitx_number_adjust_exponent:Vn
% }
% \begin{syntax}
% \cs{siunitx_number_adjust_exponent:Nn} \meta{number} \Arg{fp~expr}
% \end{syntax}
% Adjusts the exponent of the \meta{number} (in internal format) by the
% \meta{fp~expr} and leaves the result in the input stream.
% \end{function}
%
% \begin{function}{\siunitx_number_normalize_symbols:N}
% \begin{syntax}
% \cs{siunitx_number_normalize_symbols:N} \meta{tl~var}
% \end{syntax}
% Replaces all multi-token signs and comparators in the \meta{tl~var}
% with their single-token equivalents. Replaces any active hyphen tokens
% with non-active versions.
% \end{function}
%
% \begin{function}[pTF, EXP]{\siunitx_if_number:n}
% \begin{syntax}
% \cs{siunitx_if_number_token:NTF} \Arg{tokens}
% \Arg{true code} \Arg{false code}
% \end{syntax}
% Determines if the \meta{tokens} form a valid number which can be fully
% parsed by \pkg{siunitx}.
% \end{function}
%
% \begin{function}[TF]{\siunitx_if_number_token:N}
% \begin{syntax}
% \cs{siunitx_if_number_token:NTF} \Arg{token}
% \Arg{true code} \Arg{false code}
% \end{syntax}
% Determines if the \meta{token} is valid in a number based on those
% tokens currently set up for detection in a number.
% \end{function}
%
% \begin{variable}{\l_siunitx_bracket_ambiguous_bool}
% A switch to control whether ambiguous numbers are bracketed: this can
% also be covered in quantity formatting by a setting there.
% \end{variable}
%
% \begin{variable}{\l_siunitx_number_parse_bool}
% A switch to control whether any parsing is attempted for numbers.
% \end{variable}
%
% \begin{variable}
% {
% \l_siunitx_number_comparator_tl ,
% \l_siunitx_number_exponent_tl ,
% \l_siunitx_number_sign_tl
% }
% The list of possible input comparators, exponent markers and signs.
% \end{variable}
%
% \begin{variable}
% {\l_siunitx_number_input_decimal_tl, \l_siunitx_number_output_decimal_tl}
% The list of possible input decimal marker(s), and the output marker.
% \end{variable}
%
% \subsection{Key--value options}
%
% The options defined by this submodule are available within the \pkg{l3keys}
% |siunitx| tree.
%
% \begin{function}{allow-uncertainty-breaks}
% \begin{syntax}
% |allow-uncertainty-breaks| = |true|\verb"|"|false|
% \end{syntax}
% Specifies whether breaks are permitted for a (separated) uncertainties. The
% standard setting is |true|.
% \end{function}
%
% \begin{function}{bracket-ambiguous-numbers}
% \begin{syntax}
% |bracket-ambiguous-numbers| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{bracket-negative-numbers}
% \begin{syntax}
% |bracket-negative-numbers| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{drop-exponent}
% \begin{syntax}
% |drop-exponent| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{drop-uncertainty}
% \begin{syntax}
% |drop-uncertainty| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{drop-zero-decimal}
% \begin{syntax}
% |drop-zero-decimal| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{evaluate-expression}
% \begin{syntax}
% |evaluate-expression| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{exponent-base}
% \begin{syntax}
% |exponent-base| = \meta{base}
% \end{syntax}
% \end{function}
%
% \begin{function}{exponent-mode}
% \begin{syntax}
% |exponent-mode| = |engineering|\verb"|"|fixed|\verb"|"|input|\verb"|"|scientific|\verb"|"|threshold|
% \end{syntax}
% Choice which determines whether numbers are converted to exponent form. The
% option |engineering| forces exponent form with an exponent which is the
% smallest power of three which gives a mantissa with an integer part. The
% option |fixed| uses a fixed exponent (set in |fixed-exponent|). The
% option |input| leaves the input unchanged (which will therefore produce an
% exponent only if the input contained one). The choice |scientific| gives
% an exponent with the mantissa~$m$ in the range $1 \le m < 10$. Finally,
% the option |threshold| will apply |scientific| if the exponent of input
% is outside of the range stored in |exponent-thresholds|. The standard
% setting is |input|.
% \end{function}
%
% \begin{function}{exponent-product}
% \begin{syntax}
% |exponent-product| = \meta{symbol}
% \end{syntax}
% \end{function}
%
% \begin{function}{expression}
% \begin{syntax}
% |expression| = \meta{expression}
% \end{syntax}
% \end{function}
%
% \begin{function}{fixed-exponent}
% \begin{syntax}
% |fixed-exponent| = \meta{exponent}
% \end{syntax}
% \end{function}
%
% \begin{function}
% {digit-group-size, digit-group-first-size, digit-group-other-size}
% \begin{syntax}
% |digit-group-number| = \meta{integer}
% \end{syntax}
% Sets the size of the block (the number of digits) used when grouping
% digits. The option |digit-group-first-size| applies to the first grouping,
% \foreign{i.e.}~immediately next to the decimal marker, while
% |digit-group-other-size| applies to all other groups. Both can be set
% using |digit-group-size|. The standard setting for both options is $3$.
% \end{function}
%
% \begin{function}{group-digits}
% \begin{syntax}
% |group-digits| = |all|\verb"|"|decimal|\verb"|"|integer|\verb"|"|none|
% \end{syntax}
% Choice to specify whether digits in a number are grouped. The option |none|
% entirely disables this, while |all| means that both the integer and decimal
% parts are grouped. The settings |integer| and |decimal| activate grouping
% for the relevant part only. The standard setting is |all|.
% \end{function}
%
% \begin{function}{group-minimum-digits}
% \begin{syntax}
% |group-minimum-digits| = \meta{value}
% \end{syntax}
% The number of digits that must be present in a numerical part (integer or
% decimal) before digit grouping is attempted. The standard setting is $4$.
% \end{function}
%
% \begin{function}{group-separator}
% \begin{syntax}
% |group-separator| = \meta{symbol}
% \end{syntax}
% Sets the symbol inserted between groups of digits. The standard setting is
% a thin space (\cs{,}).
% \end{function}
%
% \begin{function}{input-close-uncertainty}
% \begin{syntax}
% |input-close-uncertainty| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{input-comparators}
% \begin{syntax}
% |input-comparators| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{input-close-uncertainty}
% \begin{syntax}
% |input-close-uncertainty| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{input-decimal-markers}
% \begin{syntax}
% |input-decimal-markers| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{input-digits}
% \begin{syntax}
% |input-digits| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{input-exponent-markers}
% \begin{syntax}
% |input-exponent-markers| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{input-open-uncertainty}
% \begin{syntax}
% |input-open-uncertainty| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{input-signs}
% \begin{syntax}
% |input-signs| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{input-uncertainty-signs}
% \begin{syntax}
% |input-uncertainty-signs| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{input-uncertainty-divider}
% \begin{syntax}
% |input-uncertainty-divider| = \meta{tokens}
% \end{syntax}
% \end{function}
%
% \begin{function}{minimum-decimal-digits}
% \begin{syntax}
% |minimum-decimal-digits| = \meta{min}
% \end{syntax}
% \end{function}
%
% \begin{function}{minimum-integer-digits}
% \begin{syntax}
% |minimum-integer-digits| = \meta{min}
% \end{syntax}
% \end{function}
%
% \begin{function}{negative-color}
% \begin{syntax}
% |negative-color| = \meta{color}
% \end{syntax}
% \end{function}
%
% \begin{function}{output-close-uncertainty}
% \begin{syntax}
% |output-close-uncertainty| = \meta{symbol}
% \end{syntax}
% \end{function}
%
% \begin{function}{output-decimal-marker}
% \begin{syntax}
% |output-decimal-marker| = \meta{symbol}
% \end{syntax}
% \end{function}
%
% \begin{function}{output-open-uncertainty}
% \begin{syntax}
% |output-open-uncertainty| = \meta{symbol}
% \end{syntax}
% \end{function}
%
% \begin{function}{parse-numbers}
% \begin{syntax}
% |parse-numbers| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}
% {
% print-implicit-plus ,
% print-mantissa-implicit-plus ,
% print-exponent-implicit-plus
% }
% \begin{syntax}
% |print-implicit-plus| = |true|\verb"|"|false|
% |print-mantissa-implicit-plus| = |true|\verb"|"|false|
% |print-exponent-implicit-plus| = |true|\verb"|"|false|
% \end{syntax}
% Controls whether the plus sign implicit in a positive number is printed;
% this can be controlled at the level of the mantissa or exponent, or
% can be activated for both.
% \end{function}
%
% \begin{function}{print-unity-mantissa}
% \begin{syntax}
% |print-unity-mantissa| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{print-zero-exponent}
% \begin{syntax}
% |print-zero-exponent| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{print-zero-integer}
% \begin{syntax}
% |print-zero-integer| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{retain-explicit-plus}
% \begin{syntax}
% |retain-explicit-plus| = |true|\verb"|"|false|
% \end{syntax}
% Switch which determines if an explicit |+| is retained as a sign when
% parsing. The standard setting is |false|.
% \end{function}
%
% \begin{function}{retain-explicit-decimal-marker}
% \begin{syntax}
% |retain-explicit-decimal-marker| = |true|\verb"|"|false|
% \end{syntax}
% Switch which determines if an explicit decimal marker is retained when
% parsing a number where there is no decimal part to a number
% (\foreign{i.e.}~whether to differentiate |10| and |10.|). The standard
% setting is |false|.
% \end{function}
%
% \begin{function}{retain-negative-zero}
% \begin{syntax}
% |retain-negative-zero| = |true|\verb"|"|false|
% \end{syntax}
% Switch which determines if a negative sign is retained where the value of
% a parsed number is exactly zero. The standard setting is |false|.
% \end{function}
%
% \begin{function}{retain-zero-uncertainty}
% \begin{syntax}
% |retain-zero-uncertainty| = |true|\verb"|"|false|
% \end{syntax}
% Switch which determines if an entirely zero uncertainty part is retained
% on parsing, or whether this is normalised to remove the uncertainty.
% The standard setting is |false|.
% \end{function}
%
% \begin{function}{round-direction}
% \begin{syntax}
% |round-direction| = |down|\verb"|"|nearest|\verb"|"|up|
% \end{syntax}
% Choice which determines how values are rounded. The setting
% |up| means that the value is always rounded away from zero, whereas the
% setting |down| means that the value will be rounded toward zero. The
% setting |nearest| means that the value will be rounded to the nearest
% (either up or down), taking account of the setting of |round-half|.
% The standard setting is |nearest|.
% \end{function}
%
% \begin{function}{round-half}
% \begin{syntax}
% |round-half| = |even|\verb"|"|up|
% \end{syntax}
% Choice which determines how values of exactly half are rounded. The setting
% |up| means that the value is always rounded away from zero, whereas the
% setting |even| means that the value will be rounded to the closes even
% number. The standard setting is |up|.
% \end{function}
%
% \begin{function}{round-minimum}
% \begin{syntax}
% |round-minimum| = \meta{min}
% \end{syntax}
% Literal which sets a minimum value below which rounded values will be
% replaced by this value and a |>| or |<|, as appropriate for the sign of
% the value. The standard setting is empty, \foreign{i.e.}~there is no
% minimum.
% \end{function}
%
% \begin{function}{round-mode}
% \begin{syntax}
% |round-mode| = |figures|\verb"|"|none|\verb"|"|places|\verb"|"|uncertainty|
% \end{syntax}
% Choice which specifies the rounding approach used for numbers. The choice
% |figures| means that values are rounding to the number of significant
% figures specified by |round-precision|. The setting |places| rounds to
% |round-precision| interpreted as a number of decimal places: this may be
% negative (rounding to an integer). The setting |none| disables rounding.
% The setting |uncertainty| first rounds the uncertainty to the number of
% significant figures specified by |round-precision|, then rounds the main
% value such that its accuracy is correctly specified by this updated
% uncertainty. The standard setting is |none|.
% \end{function}
%
% \begin{function}{round-pad}
% \begin{syntax}
% |round-pad| = |true|\verb"|"|false|
% \end{syntax}
% Switch which specifies if values should be padded to the required number
% length when rounding to a number of decimal places. The standard setting is
% |true|.
% \end{function}
%
% \begin{function}{round-precision}
% \begin{syntax}
% |round-precision| = \meta{precision}
% \end{syntax}
% Integer specifying the number of digits used as a target when rounding:
% this may be interpreted as decimal places or significant figures,
% depending on active |round-mode|. The standard setting is $2$.
% \end{function}
%
% \begin{function}{round-zero-positive}
% \begin{syntax}
% |round-zero-positive| = |true|\verb"|"|false|
% \end{syntax}
% Switch to control whether a value rounded to zero is regarded as a positive
% number if the input was negative. The standard setting is |true|.
% \end{function}
%
% \begin{function}{simplify-uncertainty}
% \begin{syntax}
% |simplify-uncertainty| = |true|\verb"|"|false|
% \end{syntax}
% Switch to control whether uncertainties given with two equal components
% are printed as a single value.
% \end{function}
%
% \begin{function}{tight-spacing}
% \begin{syntax}
% |tight-spacing| = |true|\verb"|"|false|
% \end{syntax}
% \end{function}
%
% \begin{function}{uncertainty-descriptor-mode}
% \begin{syntax}
% |uncertainty-descriptor| = |bracket|\verb"|"|bracket-separator|\verb"|"|separator|\verb"|"|subscript|
% \end{syntax}
% Selects how uncertainty descriptors are formatted: a choice from the
% options |bracket|, |text| and |subscript|. The option |bracket| wraps the
% descriptor in parenthesis, |bracket-separator| does the same but also
% includes a separator between the uncertainty and opening bracket,
% |separator| places the descriptor after the uncertainty and a separator,
% and |subscript| formats the descriptor as a subscript. The
% standard setting is |bracket-separator|.
% \end{function}
%
% \begin{function}{uncertainty-descriptor-separator}
% \begin{syntax}
% |uncertainty-descriptor-separator| = \meta{separator}
% \end{syntax}
% Separateor inserted between the uncertainty and descriptor when one is
% required by |uncertainty-separator-mode|. The standard setting is
% \verb*|\ |.
% \end{function}
%
% \begin{function}{uncertainty-descriptors}
% \begin{syntax}
% |uncertainty-descriptors| = \meta{clist}
% \end{syntax}
% Stores the list of descriptors used when there are multiple uncertainty
% components given. This is not used when there is only a single uncertainty
% component present. The standard setting is |empty|.
% \end{function}
%
% \begin{function}{uncertainty-mode}
% \begin{syntax}
% |uncertainty-mode| = |compact|\verb"|"|compact-marker|\verb"|"|full|\verb"|"|separate|
% \end{syntax}
% Switch to determine how single symmetrical uncertainties are formatted.
% When this is set to |separate|, the uncertainty is printed as an entirely
% separate number preceded by \cs{pm}. Other settings all place the
% uncertainty in parentheses directly attached to the main value. The
% standard setting of |compact| prints digits of uncertainty in the
% least-significant digits. It does \emph{not} print a decimal marker if the
% uncertainty crosses the decimal. The setting |full| prints the full value
% of the uncertainty. The setting |compact-marker| is available to print in
% the |compact| style except where the uncertainty crosses the decimal, in
% which case the |full| style is used. The standard setting is |compact|.
% \end{function}
%
% \begin{function}{uncertainty-round-direction}
% \begin{syntax}
% |uncertainty-round-direction| = |down|\verb"|"|nearest|\verb"|"|up|
% \end{syntax}
% Choice which determines how uncertainty values are rounded. The setting
% |up| means that the uncertainty is always rounded away from zero, whereas
% the setting |down| means that the uncertainty will be rounded toward zero.
% The setting |nearest| means that the uncertainty will be rounded to the
% nearest (either up or down), taking account of the setting of |round-half|.
% The standard setting is |nearest|.
% \end{function}
%
% \begin{function}{uncertainty-separator}
% \begin{syntax}
% |uncertainty-separator| = \meta{separator}
% \end{syntax}
% Stores the separator used between the main value and uncertainty when using
% the |compact| or |compact-marker| style setting for |uncertainty-mode|.
% \end{function}
%
% \begin{function}{zero-decimal-as-symbol}
% \begin{syntax}
% |zero-decimal-as-symbol| = |true|\verb"|"|false|
% \end{syntax}
% Switch to determine if an entirely zero decimal part is replaced by a
% symbol. Does not apply if the decimal part is marked as entirely absent.
% \end{function}
%
% \begin{function}{zero-symbol}
% \begin{syntax}
% |zero-symbol| = \meta{symbol}
% \end{syntax}
% Material printed when a zero numerical component is replaced by a symbol.
% \end{function}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{siunitx-number} implementation}
%
% Start the \pkg{DocStrip} guards.
% \begin{macrocode}
%<*package>
% \end{macrocode}
%
% Identify the internal prefix.
% \begin{macrocode}
%<@@=siunitx_number>
% \end{macrocode}
%
% \subsection{Initial set-up}
%
% Variants not provided by \pkg{expl3}.
% \begin{macrocode}
\cs_generate_variant:Nn \keys_set:nn { nx }
\cs_generate_variant:Nn \tl_if_blank:nTF { e }
\cs_generate_variant:Nn \tl_if_in:NnTF { NV }
\cs_generate_variant:Nn \tl_if_in:nnTF { nV }
\cs_generate_variant:Nn \tl_remove_all:Nn { NV }
\cs_generate_variant:Nn \tl_replace_all:Nnn { NnV }
% \end{macrocode}
%
% \begin{variable}{\l_@@_tmp_tl}
% Scratch space.
% \begin{macrocode}
\tl_new:N \l_@@_tmp_tl
% \end{macrocode}
% \end{variable}
%
% \subsection{Main formatting routine}
%
% \begin{variable}{\l_@@_outputted_tl}
% A token list for the final formatted result: may or may not be generated
% by the parser, depending on settings which are active.
% \begin{macrocode}
\tl_new:N \l_@@_outputted_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_siunitx_number_parse_bool}
% Tracks whether to parse numbers: public as this may affect other
% behaviors.
% \begin{macrocode}
\tl_new:N \l_siunitx_number_parse_bool
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_siunitx_number_parse_bool}
% Top-level options.
% \begin{macrocode}
\keys_define:nn { siunitx }
{
parse-numbers .bool_set:N = \l_siunitx_number_parse_bool
}
% \end{macrocode}
% \end{variable}
%
% \begin{macro}{\siunitx_number_format:nN}
% \begin{macrocode}
\cs_new_protected:Npn \siunitx_number_format:nN #1#2
{
\group_begin:
\bool_if:NTF \l_siunitx_number_parse_bool
{
\siunitx_number_parse:nN {#1} \l_@@_parsed_tl
\tl_if_empty:NF \l_@@_parsed_tl
{
\siunitx_number_process:NN \l_@@_parsed_tl \l_@@_parsed_tl
\tl_set:Nx \l_@@_outputted_tl
{ \siunitx_number_output:N \l_@@_parsed_tl }
}
}
{ \tl_set:Nn \l_@@_outputted_tl { \ensuremath {#1} } }
\exp_args:NNNV \group_end:
\tl_set:Nn #2 \l_@@_outputted_tl
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Parsing numbers}
%
% Before numbers can be manipulated or formatted they need to be parsed into
% an internal form. In particular, if multiple code paths are to be avoided,
% it is necessary to do such parsing even for relatively simple cases such
% as converting |1e10| to |1 \times 10^{10}|.
%
% Storing the result of such parsing can be done in a number of ways. In the
% first version of \pkg{siunitx} a series of separate data stores were used.
% This is potentially quite fast (as recovery of items relies only on \TeX{}'s
% hash table) but makes managing the various data entries somewhat tedious and
% error-prone. For version two of the package, a single data structure
% (property list) was used for each part of the parsed number. Whilst this is
% easy to manage and extend, it is somewhat slower as at a \TeX{} level there
% are repeated pack--unpack steps. In particular, the fact that there are a
% limited number of items to track for a \enquote{number} means that a more
% efficient approach is desirable (contrast parsing units, which is open-ended
% and therefore fits well with using a property list).
%
% In this release, the structure of a valid number is:
% \begin{quote}
% \marg{comparator}\meta{sign}\marg{integer}\marg{decimal}
% \marg{uncertainty}\\
% \meta{exponent sign}\marg{exponent}
% \end{quote}
% where all components must be given in braces. \emph{All} of the components
% must be present in a stored number (\foreign{i.e.}~at the end of parsing).
%
% A non-empty \meta{uncertainty} must contain one leading brace group
% containing an identifier, then zero or more brace groups which contain
% the uncertainty data. In this release, the known uncertainty types are
% \begin{itemize}
% \item \texttt{A}: An unsymmetrical uncertainty made up of two values.
% Each is stored as uncertainty in significant digits, with no radix point
% in the stored value. The two parts are stored within one brace group,
% within which are two brace groups: the first contains the positive
% component, the second the negative component. Neither component has a
% sign.
% \item \texttt{S}: A symmetrical statistical uncertainty made up of
% a single value. These are stored as uncertainty in significant digits,
% with no radix point in the stored value.
% \end{itemize}
%
% \begin{variable}{\l_siunitx_number_input_decimal_tl}
% The input decimal markers(s).
% \begin{macrocode}
\tl_new:N \l_siunitx_number_input_decimal_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}
% {
% \l_@@_expression_bool ,
% \l_@@_input_uncert_close_tl ,
% \l_siunitx_number_input_comparator_tl ,
% \l_@@_input_digit_tl ,
% \l_siunitx_number_input_exponent_tl ,
% \l_@@_input_ignore_tl ,
% \l_@@_input_uncert_open_tl ,
% \l_@@_input_uncert_divide_tl ,
% \l_siunitx_number_input_sign_tl ,
% \l_@@_input_uncert_sign_tl ,
% \l_@@_explicit_decimal_bool ,
% \l_@@_explicit_plus_bool ,
% \l_@@_negative_zero_bool ,
% \l_@@_zero_uncert_bool
% }
% \begin{macro}[EXP]{\@@_expression:n}
% Options which determine the various valid parts of a parsed number.
% \begin{macrocode}
\keys_define:nn { siunitx }
{
evaluate-expression .bool_set:N =
\l_@@_expression_bool ,
expression .code:n =
\cs_set:Npn \@@_expression:n ##1 {#1} ,
input-close-uncertainty .tl_set:N =
\l_@@_input_uncert_close_tl ,
input-comparators .tl_set:N =
\l_siunitx_number_input_comparator_tl ,
input-decimal-markers .tl_set:N =
\l_siunitx_number_input_decimal_tl ,
input-digits .tl_set:N =
\l_@@_input_digit_tl ,
input-exponent-markers .tl_set:N =
\l_siunitx_number_input_exponent_tl ,
input-ignore .tl_set:N =
\l_@@_input_ignore_tl ,
input-open-uncertainty .tl_set:N =
\l_@@_input_uncert_open_tl ,
input-signs .tl_set:N =
\l_siunitx_number_input_sign_tl ,
input-uncertainty-signs .code:n =
{
\tl_set:Nn \l_@@_input_uncert_sign_tl {#1}
\tl_map_inline:nn {#1}
{
\tl_if_in:NnF \l_siunitx_number_input_sign_tl {##1}
{ \tl_put_right:Nn \l_siunitx_number_input_sign_tl {##1} }
}
} ,
input-uncertainty-divider .tl_set:N =
\l_@@_input_uncert_divide_tl ,
parse-numbers .bool_set:N =
\l_siunitx_number_parse_bool ,
retain-explicit-decimal-marker .bool_set:N =
\l_@@_explicit_decimal_bool ,
retain-explicit-plus .bool_set:N =
\l_@@_explicit_plus_bool ,
retain-negative-zero .bool_set:N =
\l_@@_negative_zero_bool ,
retain-zero-uncertainty .bool_set:N =
\l_@@_zero_uncert_bool
}
\cs_new:Npn \@@_expression:n #1 { }
\tl_new:N \l_@@_input_uncert_sign_tl
% \end{macrocode}
% \end{macro}
% \end{variable}
%
% \begin{variable}{\l_@@_arg_tl}
% The input argument or a part thereof, depending on the position in
% the parsing routine.
% \begin{macrocode}
\tl_new:N \l_@@_arg_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_comparator_tl}
% A comparator, if found, is held here.
% \begin{macrocode}
\tl_new:N \l_@@_comparator_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_exponent_tl}
% The exponent part of a parsed number. It is easiest to find this
% relatively early in the parsing process, but as it needs to go at
% the end of the internal format is held separately until required.
% \begin{macrocode}
\tl_new:N \l_@@_exponent_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_flex_tl}
% In a number with an uncertainty, the exact meaning of a second part is
% not fully resolved until parsing is complete. That is handled using
% this \enquote{flexible} store.
% \begin{macrocode}
\tl_new:N \l_@@_flex_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_parsed_tl}
% The number parsed into internal format.
% \begin{macrocode}
\tl_new:N \l_@@_parsed_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_input_tl}
% The numerical input exactly as given by the user.
% \begin{macrocode}
\tl_new:N \l_@@_input_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_partial_tl}
% To avoid needing to worry about the fact that the final data stores are
% somewhat tricky to add to token-by-token, a simple store is used to build
% up the parsed part of a number before transferring in one go.
% \begin{macrocode}
\tl_new:N \l_@@_partial_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}
% {
% \l_@@_tolerance_tl ,
% \l_@@_uncert_tl ,
% \l_@@_uncert_offset_int,
% \l_@@_uncert_types_tl
% }
% To allow multiple uncertainties, we want to build this up as possibly
% multiple entries. For asymmetrical uncertainties/tolerances, we need
% an additional store.
% \begin{macrocode}
\tl_new:N \l_@@_tolerance_tl
\tl_new:N \l_@@_uncert_tl
\int_new:N \l_@@_uncert_offset_int
\tl_new:N \l_@@_uncert_types_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_validate_bool}
% Used to set up for validation with no error production.
% \begin{macrocode}
\bool_new:N \l_@@_validate_bool
% \end{macrocode}
% \end{variable}
%
% \begin{macro}{\siunitx_number_normalize_symbols:N}
% \begin{macro}{\@@_normalize_aux:nN}
% \begin{macro}{\@@_normalize_actives:N}
% \begin{variable}{\c_@@_normalize_tl}