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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
|
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \iffalse meta-comment
%
% DocStrip file for ionumbers package
%
% Copyright 2007-2009,2011,2012,2014
% Christian Schneider <software(at)chschneider(dot)eu>
%
% idea and parts of this package based on: ziffer.sty v2.1
% Copyright Martin Vaeth <vaeth@mathematik.uni-wuerzburg.de>
%
% ion@addto@macro: identical to l@addto@macro from koma-script
% bundle v2.9t
% Copyright 1994-2004 Markus Kohm and Frank Neukam
%
% Thanks to Martin Vaeth and Markus Kohm for permitting to use their
% code in this package. Please do not bother Martin, Markus, or Frank
% with questions or bugs concering this package!
%
% This file is part of ionumbers.
%
% ionumbers is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License version 3 as
% published by the Free Software Foundation, not any later version.
%
% ionumbers is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with ionumbers. If not, see <http://www.gnu.org/licenses/>.
%
% WARNING: THIS IS ALPHA SOFTWARE AND MAY CONTAIN SERIOUS BUGS!
%
% \fi
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{ionumbers}
%<package> [2014/04/06 v0.3.3 restyle numbers in math mode]
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{ionumbers}
\usepackage{hyperref}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%
% modified description environment
\newcommand{\listmark}{$\bullet$}
\newcommand{\listlengths}{%
\setlength{\parsep}{0pt}%
\setlength{\itemsep}{0pt}%
\setlength{\leftmargin}{10.5em}%
\setlength{\rightmargin}{0pt}%
\setlength{\labelsep}{1em}%
\setlength{\labelwidth}{9.5em}}
\newenvironment{mydescription}{%
\begin{list}{\listmark}{\listlengths}%
}{%
\end{list}%
}
%
\begin{document}
\DocInput{ionumbers.dtx}
\end{document}
%</driver>
% \fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \changes{v0.2.0-alpha}{2008/10/27}{initial .dtx version}
% \changes{v0.2.1-alpha}{2008/11/02}{replaced website by e-mail address in all
% fields containing contact information}
% \changes{v0.2.2-alpha}{2008/12/21}{fixed problem with single digit numbers
% without \{\}-grouping; conflict with \textsf{amsmath}/\textsf{amsopn}
% documented and handled with warning messages; thanks to Robert N\"{u}rnberg
% for reporting these two problems}
% \changes{v0.2.3-alpha}{2008/12/21}{saved one \texttt{\textbackslash if} and
% made sign/digit macros a bit clearer}
% \changes{v0.2.4-alpha}{2009/07/18}{fixed bug with curly braces in
% \texttt{\textbackslash ion@problem@package} macro; thanks to Lars for
% reporting this problem}
% \changes{v0.3.0-alpha}{2011/06/09}{added options for variable grouping
% lengths; extended \LaTeX{} test file}
% \changes{v0.3.1-alpha}{2011/06/15}{fix in Makefile of package}
% \changes{v0.3.2-alpha}{2012/08/20}{added examples of usage}
% \changes{v0.3.3}{2014/04/06}{fixed problem when changing the font,
% e.\,g., when loading the \textsf{MnSymbol} package; the original character
% definitions are not hard-coded anymore, but copied
% from the definitions at the beginning of the document; thanks to Michael
% Sebastian Hitziger for his bug report}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \CheckSum{0}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \GetFileInfo{ionumbers.sty}
%
% \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
% \DoNotIndex{\@ne}
% \DoNotIndex{\advance,\begingroup,\catcode,\closein}
% \DoNotIndex{\closeout,\day,\def,\edef,\else,\empty,\endgroup}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \title{The \textsf{ionumbers} package\thanks{This document corresponds
% to \textsf{ionumbers}~\fileversion, dated~\filedate. Copyright
% 2007--2009,2011,2012,2014 Christian Schneider
% \texttt{<software(at)chschneider(dot)eu>}, \url{http://chschneider.eu}.}}
% \author{Christian Schneider\\ \texttt{<software(at)chschneider(dot)eu>}}
%
% \maketitle
%
% \begin{center}
% \large\textbf{\textsf{Warning: Use with caution and on your own risk!
% Check output!}}
% \end{center}
%
% \tableofcontents
% \clearpage
%
% \begin{abstract}
% \textsf{ionumbers} stands for `input/output numbers'.
%
% This package restyles numbers in math mode. If a number in the input file
% is written, e.g., as |$3,231.44$| as commonly used in English texts, this
% package is able to restyle it to be output as `$3\,231{,}44$' as commonly
% used in German texts (and vice versa). This may be very useful, if you have
% a large table and want to include it in texts with different output
% conventions without the need of changing the table.
%
% Furthermore this package can automatically group digits left to the decimal
% separator (\emph{thousands}) and right to the decimal separator
% (\emph{thousandths}) without the need of specifing commas (English) or
% points (German) as separators. E.g., the input |$1234.567890$| can be
% output as `$1\,234.\,567\,890$'. By default, thousands/thousandths are
% grouped in triplets, but the grouping length is configurable, which is
% useful for numerical data.
%
% Finally, an |e| starts the exponent of the number. For example, |$21e6$|
% may be output as `$26\times10\,^{6}$'.
% \end{abstract}
%
% \section{Details of number handling}
%
% \subsection{General rules}
%
% Every input \emph{in math mode} consisting of the following characters is
% treated by this package: |.,+-0123456789|. These characters get macro
% definitions. A number is any combination of these characters without
% anything---not even white spaces---in between them. There are two
% exceptions/special cases:
%
% \begin{enumerate}
% \item The separator characters |.| and |,| are not treated as part of the
% number at its end. This avoids problems with comma-separated lists
% (see below).
% \item The sign characters |+| and |-| will only be considered as part of
% the number, if they appear at the begining of a number.
% \end{enumerate}
%
% The lower case letter |e| plays a special role. An |e| immediatly following a
% number (as defined above) can be configured as begining of the exponential
% part. The letter |e| will be eaten from the input in this case and
% substituted by some configurable output. The next number following this |e|
% in the same group (even with other characters inbetween the |e| and the
% number) will be treated as exponential part and grouped with curly braces
% |{}|.
%
% It is a good practice to always add a space before/after each number such that
% \textsf{ionumbers} knows the beginning/end of a number and does not
% misinterpret other input as part of it.
% Below, you will find a couple of examples that might lead to surprising
% output, if this rule is not followed.
%
% \subsection{Caveats}
%
% \emph{Comma-separated lists} of numbers must be input with a space after
% each comma to prevent |,| to be treated as part of the number. An example is
% the list |1, 2, 3, \ldots|, where the commas are not part of in the numbers.
% Note, however, that the commas are treated as part of the numbers in the first
% two appearances in |1,2,3,\ldots|, as the commas are immediately followed
% by a digit. Depending on the configuration, this may lead to strange spaces
% between the numbers, disappearing commas etc.
%
% If you use \emph{indexes consisting of four or more digits} together
% with automatic grouping of thousands, the grouping will also apply to the
% indexes. So |a_{1234}| might be output as $a_{1,234}$. The simplest way to
% prevent undesired automatic grouping is to insert a space after each digit,
% e.\,g., as in |a_{1 2 3 4}|.
%
% Please be aware that the first decimal separator of a number marks the
% begining of the thousandths part of a number; every part of a number
% appearing left to the first decimal separator is the thousands part. That is
% why, the input |$1.234.567$| with (only) the package option
% |autothousandths=true| (|.| is the decimal separator; options will be
% explained later) will lead to `$1.234.\,567$' in the output. Note the small
% space after the second point as a result of |234.567| being treated as
% thousandths part. The thousandths separator---by default a small space---will
% be output between the third and fourth digit of the thousandths part; the
% additional point from the input will not be omitted. The input is
% \emph{syntactically incorrect} (there must not be two decimal separators in
% one number!) and the output is \emph{not} a bug.
%
% The number following an |e| which has started the exponential part is treated
% as exponential part, \emph{even if there is arbitrary input inbetween}.
% Hence, the input |$1e \Pi 2| with package option |exponent=timestento| (will
% be explained later) leads to a superscript |2| in the output. In some cases,
% e.\,g., |$1e \sqrt 2$| or |$1e^2$| with
% |e| configured as begining of the exponential part, even an error occurs.
% Again, the input is \emph{syntactically incorrect} and you might want to
% prevent |e| from being treated as start of the exponential part by adding
% a space: |$1 e \sqrt 2$| or |$1 e^2$|.
%
% In some rare cases, e.\,g., |$\sqrt ,$| or |$a^.$|, the usage of point and
% comma without curly braces |{}| around them will lead to an error. In these
% cases please add curly braces |{}| around the point or comma. (The
% \textsf{ziffer} package has the same problem, by the way.)
%
% \section{Conflicts with other packages}
%
% This package potentially conflicts with any other package that defines a
% macro for any of the following characters: |.,+-0123456789|
%
% There are tests for these cases and warning or error messages may be output.
% Please load \textsf{ionumbers} as \emph{last package} to be able to detect as
% many conflicts as possible. As there is no way to detect conflicts in any
% case, please report any package known to conflict with \textsf{ionumbers} to
% the author.
%
% Packages known to conflict with \textsf{ionumbers} are:
% \begin{mydescription}
% \item[\textsf{ziffer}] this package can be replaced by \textsf{ionumbers}
% except for \textsf{ziffer}'s special handling of |--| enabled by
% |\ZifferStrichAn|
% \item[\textsf{dcolumn}] workaround: disable \textsf{ionumbers} for tabulars
% (e.\,g., put them inside |\ionumbersoff|\marg{\ldots})
% \item[\textsf{amsmath}/\textsf{amsopn}] load \textsf{ionumbers} as last
% package and disable \textsf{ionumbers} for |\operatorname|\marg{\ldots}
% (e.\,g., put it inside\\
% |\ionumbersoff|\marg{\ldots})
% \end{mydescription}
%
% \section{Usage}
%
% Package options are used to globally configure a default behaviour of
% \textsf{ionumbers} for the whole document. These options usually consist
% of a \meta{key}|=|\meta{value} pair. Local changes from this global
% configuration for arbitrary parts of the document can be applied with special
% commands.
%
% \subsection{Package options concerning the separators in the input}
% \label{sec:in}
%
% The following options configure the meaning of separators in the \LaTeX{}
% input file:
% \begin{mydescription}
% \item[\texttt{comma}=\meta{value}] comma `|,|' will be treated as
% \meta{value}
% \item[\texttt{point}=\meta{value}] point `|.|' will be treated as
% \meta{value}
% \end{mydescription}
%
% The following \meta{value}s can be chosen for both of them:
% \begin{mydescription}
% \item[\texttt{ignore}] the separator will be ignored (no output)
% \item[\texttt{decimal}] decimal separator (separating the thousands from
% the thousandths part of a number)
% \item[\texttt{thousands}] thousands separator (used for grouping of
% thousands part)
% \item[\texttt{default}] default behaviour of \textsf{ionumbers}
% (|decimal| for |point|; |thousands| for |comma|)
% \end{mydescription}
%
% The separator for exponents is always the lowercase letter |e|. A
% thousandths separator does not exist in input files; such a separator will
% only be output, if automatic grouping of the thousandths part is enabled (see
% below).
%
% \subsection{Package options concerning the separators in the output}
% \label{sec:out}
%
% The previously described options assign a \emph{meaning} to separators in
% the input file. The \emph{output} of the \emph{meanings} is configured via
% the following options:
% \begin{mydescription}
% \item[\texttt{thousands}=\meta{value}] thousands separator will be output as
% \meta{value}
% \item[\texttt{decimal}=\meta{value}] decimal separator will be output as
% \meta{value}
% \item[\texttt{thousandths}=\meta{value}] thousandths separator will be
% \meta{value}
% \item[\texttt{exponent}=\meta{value}] exponent separator will be output as
% \meta{value}
% \end{mydescription}
%
% The list of valid \meta{value}s for |thousands|, |decimal|, and |thousandths|
% is:
% \begin{mydescription}
% \item[\texttt{none}] will be ignored (no output)
% \item[\texttt{point}] normal point; this is the default point without
% \textsf{ionumbers}
% \item[\texttt{comma}] normal comma
% \item[\texttt{punctpoint}] punctuation point (point followed by small space)
% \item[\texttt{punctcomma}] punctuation comma (point followed by small
% space); this is the default comma without \textsf{ionumbers}
% \item[\texttt{apostrophe}] apostrophe (actually |$^\prime$|; \emph{not} for
% |decimal|)
% \item[\texttt{phantom}] space with width of a point (|$\phantom{.}$|;
% \emph{not} for |decimal|)
% \item[\texttt{space}] small space (|$\,$|; \emph{not} for |decimal|)
% \item[\texttt{default}] default behaviour of \textsf{ionumbers}
% (|punctcomma| for |thousands|; |point| for |decimal|; |space| for
% |thousandths|)
% \end{mydescription}
%
% If a number is handled as exponent, it will be put into curly braces |{}|
% for correct output of, e.\,g., signs without spacing around them (mathord).
% In the following list of valid \meta{value}s for |exponent| a number
% immediatly following an |e| will be handled as exponent, unless specified
% otherwise:
% \begin{mydescription}
% \item[\texttt{none}] will be ignored (not output; following number
% \emph{not} handled as exponent)
% \item[\texttt{original}] a simple character `e' (following number
% \emph{not} handled as exponent)
% \item[\texttt{ite/itE}] italic lower/upper case letter `e'
% \item[\texttt{rme/rmE}] roman lower/upper case letter `e'
% \item[\texttt{timestento}] |$\times10\,$| with following number output as
% superscript
% \item[\texttt{cdottento}] |$\cdot10\,$| with following number output as
% superscript
% \item[\texttt{wedge}] |$^\wedge$|
% \item[\texttt{default}] default behaviour of \textsf{ionumbers} (|original|)
% \end{mydescription}
%
% \subsection{Package options concerning automatic grouping}
% \label{sec:auto}
%
% Automatic grouping is a feature that automatically adds the thousands and
% thousandths separator, respectively. The separator will by default be added
% after each triplet of digits, but this may be changed (see below). Automatic
% grouping can be enable or disabled with the
% following options:
% \begin{mydescription}
% \item[\texttt{autothousands}=\meta{value}] automatic grouping of thousands
% (digits left to decimal separator)
% \item[\texttt{autothousandths}=\meta{value}] automatic grouping of
% thousandths (digits right to decimal separator)
% \end{mydescription}
%
% The grouping length for the thousands and thousandths, respectively, can be
% changed be the following options:
% \begin{mydescription}
% \item[\texttt{grplenthousands}=\meta{number}] group lengths for thousands
% (\meta{number} must be smaller than |10|; defaults to |3|)
% \item[\texttt{grplenthousandths}=\meta{number}] group lengths for thousandths
% (\meta{number} must be smaller than |10|; defaults to |3|)
% \end{mydescription}
%
% The available \meta{value}s are |true| and |false| (default).
%
% Notes on automatic grouping:
% \begin{enumerate}
% \item Grouping of thousandths requires |autothousandths=true| in any case,
% as there is no thousandths separator for explicitly specifing separations
% in the input.
% \item Automatic grouping of thousands will be skipped in a number, if it
% contains a thousands separator in the input.
% \end{enumerate}
%
% \subsection{Local style changes}
%
% \DescribeMacro{\ionumbersstyle}
% The command |\ionumbersstyle|\marg{option list} changes the global style
% definitions as specified as package options for the rest of the group.
% The \meta{option list} may contain any of the package options described in
% sections~\ref{sec:in}--\ref{sec:auto}. An additional \meta{value} for all
% \meta{key}s is available inside |\ionumbersstyle| to switch back to the
% configuration specified as package options: |reset|.
%
% \DescribeMacro{\ionumbersresetstyle}
% The command |\ionumbersresetstyle| resets all \meta{value}s to the
% configuration specified as package options. Actually, it is only a shorthand
% for\\
% |\ionumbersstyle{comma=reset,point=reset,decimal=reset,...}|.
%
% \subsection{User-defined values for output separators}
% \label{sec:defs}
%
% A user may specify further output separators. Any user-defined \meta{value}s
% for |thousands|, |decimal|, |thousandths|, and |exponent| can be used like
% the built-in options in section~\ref{sec:out}.
%
% \DescribeMacro{\newionumbersthousands}
% \DescribeMacro{\newionumbersdecimal}
% \DescribeMacro{\newionumbersthousandths}
% \DescribeMacro{\newionumbersexponent}
% The command |\newionumbersthousands|\marg{value}\marg{definition} has two
% mandatory arguments. The first one is the name of the newly defined
% \meta{value} for the |thousands| \meta{key} and the second one its
% definition. The commands |\newionumbersdecimal|, |\newionumbersthousandths|,
% and |\newionumbersexponent| work the same way for the |decimal|,
% |thousandths|, and |exponent| \meta{key}, respectively. There is a starred
% version of |\newionumbersexponent| (called |\newionumbersexponent*|) that
% typesets the following number as superscript.
%
% \DescribeMacro{\renewionumbersthousands}
% \DescribeMacro{\renewionumbersdecimal}
% \DescribeMacro{\renewionumbersthousandths}
% \DescribeMacro{\renewionumbersexponent}
% To redefine an existing \meta{key} definition there are |\renew...| versions
% of the previously described commands.
%
% Notes on definitions:
% \begin{enumerate}
% \item All \meta{definition}s are set inside |\ionumbersoff| (see
% section~\ref{sec:feat}). This means that numbers appearing in the
% \meta{definition}s are not treated by this package.
% \item The value |curr| has an internal meaning and should \emph{not} be
% defined/redefined by the user.
% \end{enumerate}
%
% \subsection{Enabling and disabling features}
% \label{sec:feat}
%
% \DescribeMacro{\ionumbers}
% The command |\ionumbers| makes comma, point, signs, and digits active in math
% mode. This is equivalent to enabling the features of this package. This
% command applies to the end of the current group.
%
% \DescribeMacro{\endionumbers}
% To disable the features by making comma, point, signs, and digits inactive
% again the command |\endionumbers| can be used. This command applies to the
% end of the current group.
%
% \DescribeMacro{\ionumbersoff}
% The command |\ionumbersoff|\marg{stuff} disables the features only for
% \meta{stuff}.
%
% \section{License}
%
% \textsf{ionumbers} is free software: you can redistribute it and/or
% modify it under the terms of the GNU General Public License version~3 as
% published by the Free Software Foundation, not any later version.
%
% \textsf{ionumbers} is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
% Public License for more details.
%
% You should have received a copy of the GNU General Public License along with
% ionumbers. If not, see \texttt{<http://www.gnu.org/licenses/>}.
%
% \section{Acknowledgements}
%
% The idea and parts of this package are based on \textsf{ziffer.sty}~v2.1 by
% Martin V\"ath \texttt{<vaeth@mathematik.uni-wuerzburg.de>}.
%
% Furthermore the |\l@addto@macro| (with changed name) from
% \textsf{koma-script bundle}~v2.9t by Markus Kohm and Frank Neukam is
% used in this package.
%
% Thanks to Martin V\"ath and Markus Kohm for permitting to use their code in
% this package.
%
% \section{Bugs, problems, and suggestions}
%
% Please report bugs and problems or send suggestions for this package to
% Christian Schneider. Check for updates before reporting bugs at the website
% mentioned above. Do \emph{not} bother Martin V\"ath, Markus Kohm, or Frank
% Neukam with bugs, problems or suggestions concerning this package!
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \section{Implementation}
%
% The implementation is briefly described in this section. First of all, we
% need the \textsf{keyval} package for \meta{key}|=|\meta{value} options:
% \begin{macrocode}
\RequirePackage{keyval}
% \end{macrocode}
%
% ---------------------------------------------------------------------
%
% \subsection{Default/global configuration}
%
% In principle the definitions of all available \meta{key'}|=|\meta{value'}
% pairs is contained in the internal macros |\ion@|\meta{key'}|@|\meta{value'}.
% Setting a package option \meta{key}|=|\meta{value} defines
% |\ion@|\meta{key}|@reset| to be |\ion@|\meta{key}|@|\meta{value}.
%
% The following |if|s will be required to remember, if automatic grouping is
% enabled. The counts will be required for the grouping lengths.
% \begin{macrocode}
\newif\ifion@autothousands
\newif\ifion@autothousandths
\newcount\ion@grplenthousands
\newcount\ion@grplenthousandths
% \end{macrocode}
%
% The next macro will be used for syntax checks of numerical arguments.
% \begin{macrocode}
\newcommand*{\ion@grplencheck}[1]{%
\ifnum#1>9%
\PackageError{ionumbers}%
{Group length argument too large (#1).\MessageBreak%
Grouping lengths must be smaller than 10.}{}%
\fi%
}
% \end{macrocode}
%
% These shorthands are used to define the \meta{key}s for package options
% and set their \meta{value}s using \textsf{keyval}, respectively.
% \begin{macrocode}
\newcommand*\ion@defpackopts{\define@key{ion@packopts}}
\newcommand*\ion@setpackopts{\setkeys{ion@packopts}}
% \end{macrocode}
%
% Next the \meta{key}s are defined.
% \begin{macrocode}
\ion@defpackopts{comma}{%
\def\ion@comma@reset{\csname ion@comma@#1\endcsname}%
\def\ion@aftercomma@reset{\csname ion@aftercomma@#1\endcsname}}
\ion@defpackopts{point}{%
\def\ion@point@reset{\csname ion@point@#1\endcsname}%
\def\ion@afterpoint@reset{\csname ion@afterpoint@#1\endcsname}}
\ion@defpackopts{decimal}{\def\ion@decimal@reset{%
\csname ion@decimal@#1\endcsname}}
\ion@defpackopts{thousands}{\def\ion@thousands@reset{%
\csname ion@thousands@#1\endcsname}}
\ion@defpackopts{thousandths}{\def\ion@thousandths@reset{%
\csname ion@thousandths@#1\endcsname}}
\ion@defpackopts{exponent}{\def\ion@exponent@reset{%
\csname ion@exponent@#1\endcsname}}
\ion@defpackopts{autothousands}[true]{\def\ion@autothousandsreset{%
\csname ion@autothousands#1\endcsname}\ion@autothousandsreset}
\ion@defpackopts{autothousandths}[true]{\def\ion@autothousandthsreset{%
\csname ion@autothousandths#1\endcsname}\ion@autothousandthsreset}
\ion@defpackopts{grplenthousands}{\ion@grplencheck{#1}%
\def\ion@grplenthousandsreset{\ion@grplenthousands=#1}%
\ion@grplenthousandsreset}
\ion@defpackopts{grplenthousandths}{\ion@grplencheck{#1}%
\def\ion@grplenthousandthsreset{\ion@grplenthousandths=#1}%
\ion@grplenthousandthsreset}
% \end{macrocode}
%
% Finally, the default \meta{value}s are set and---if specified by the user as
% package option---overwritten with the user's configuration.
% \begin{macrocode}
\ion@setpackopts{comma=default,point=default,thousands=default,%
decimal=default,thousandths=default,exponent=default,autothousands=false,%
autothousandths=false,grplenthousands=3,grplenthousandths=3}
\DeclareOption*{\expandafter\ion@setpackopts\expandafter{\CurrentOption}}
\ProcessOptions\relax
% \end{macrocode}
%
% ---------------------------------------------------------------------
%
% \subsection{Local style changes}
%
% The currently active configuration of a \meta{key} is stored in the macro
% |\ion@|\meta{key}|@curr|. The |\ion@|\meta{key}|@curr| macros for all
% \meta{key}s are defined using the mechanism for local configuration changes.
%
% The local options are defined and set---analogous to the package option
% case---with two shorthands using \textsf{keyval}. The latter is
% publically available to the user.
% \begin{macrocode}
\newcommand*\ion@deflocopts{\define@key{ion@locopts}}
% \end{macrocode}
% \begin{macro}{\ionumberstyle}
% \begin{macrocode}
\newcommand*\ionumbersstyle[1]{\setkeys{ion@locopts}{#1}}
% \end{macrocode}
% \end{macro}
%
% Now the \meta{key}s for the local options are defined (just as in the case of
% the package options):
% \begin{macrocode}
\ion@deflocopts{comma}{%
\def\ion@comma@curr{\csname ion@comma@#1\endcsname}%
\def\ion@aftercomma@curr{\csname ion@aftercomma@#1\endcsname}}
\ion@deflocopts{point}{%
\def\ion@point@curr{\csname ion@point@#1\endcsname}%
\def\ion@afterpoint@curr{\csname ion@afterpoint@#1\endcsname}}
\ion@deflocopts{decimal}{\def\ion@decimal@curr{%
\csname ion@decimal@#1\endcsname}}
\ion@deflocopts{thousands}{\def\ion@thousands@curr{%
\csname ion@thousands@#1\endcsname}}
\ion@deflocopts{thousandths}{\def\ion@thousandths@curr{%
\csname ion@thousandths@#1\endcsname}}
\ion@deflocopts{exponent}{\def\ion@exponent@curr{%
\csname ion@exponent@#1\endcsname}}
\ion@deflocopts{autothousands}[true]{\csname ion@autothousands#1\endcsname}
\ion@deflocopts{autothousandths}[true]{\csname ion@autothousandths#1\endcsname}
\ion@deflocopts{grplenthousands}{%
\def\@tempa{#1}%
\def\@tempb{reset}%
\ifx\@tempa\@tempb%
\ion@grplenthousandsreset%
\else%
\ion@grplencheck{#1}%
\ion@grplenthousands=#1%
\fi%
}
\ion@deflocopts{grplenthousandths}{%
\def\@tempa{#1}%
\def\@tempb{reset}%
\ifx\@tempa\@tempb%
\ion@grplenthousandthsreset%
\else%
\ion@grplencheck{#1}%
\ion@grplenthousandths=#1%
\fi%
}
% \end{macrocode}
%
% Finally, the command for resetting all \meta{key}s is defined.
% \begin{macro}{\ionumbersresetstyle}
% \begin{macrocode}
\newcommand*\ionumbersresetstyle{%
\ionumbersstyle{comma=reset,point=reset,thousands=reset,%
decimal=reset,thousandths=reset,exponent=reset,autothousands=reset,%
autothousandths=reset,grplenthousands=reset,grplenthousandths=reset}}
% \end{macrocode}
% \end{macro}
% This command is issued at the end of the package to make the configuration
% of the package options active (and have no undefined |\ion@|\meta{key}|@curr|
% macros).
% \begin{macrocode}
\AtEndOfPackage{\ionumbersresetstyle}
% \end{macrocode}
%
% ---------------------------------------------------------------------
%
% \subsection{User-defined values for output separators}
%
% The commands for user-defined \meta{value}s for output separators just
% (re)define the internal macro |\ion@|\meta{key}|@|\meta{value} storing
% the definition for the \meta{key}|=|\meta{value} pair.
%
% \begin{macro}{\newionumbersthousands}
% \begin{macrocode}
\newcommand*\newionumbersthousands[2]{\expandafter\newcommand%
\expandafter*\csname ion@thousands@#1\endcsname{\ionumbersoff{#2}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\newionumbersdecimal}
% \begin{macrocode}
\newcommand*\newionumbersdecimal[2]{\expandafter\newcommand%
\expandafter*\csname ion@decimal@#1\endcsname{\ionumbersoff{#2}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\newionumbersthousandths}
% \begin{macrocode}
\newcommand*\newionumbersthousandths[2]{\expandafter\newcommand%
\expandafter*\csname ion@thousandths@#1\endcsname{\ionumbersoff{#2}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\newionumbersexponent}
% \begin{macrocode}
\newcommand*\newionumbersexponent{%
\@ifstar{\newionumbersexponent@@}{\newionumbersexponent@}}
\newcommand*\newionumbersexponent@[2]{\expandafter\newcommand%
\expandafter*\csname ion@exponent@#1\endcsname{\ionumbersoff{#2}}}
\newcommand*\newionumbersexponent@@[2]{\expandafter\newcommand%
\expandafter*\csname ion@exponent@#1\endcsname{\ionumbersoff{#2}%
\ion@exponent@superscripttrue}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\renewionumbersthousands}
% \begin{macrocode}
\newcommand*\renewionumbersthousands[2]{\expandafter\renewcommand%
\expandafter*\csname ion@thousands@#1\endcsname{\ionumbersoff{#2}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\renewionumbersdecimal}
% \begin{macrocode}
\newcommand*\renewionumbersdecimal[2]{\expandafter\renewcommand%
\expandafter*\csname ion@decimal@#1\endcsname{\ionumbersoff{#2}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\renewionumbersthousandths}
% \begin{macrocode}
\newcommand*\renewionumbersthousandths[2]{\expandafter\renewcommand%
\expandafter*\csname ion@thousandths@#1\endcsname{\ionumbersoff{#2}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\renewionumbersexponent}
% \begin{macrocode}
\newcommand*\renewionumbersexponent{%
\@ifstar{\renewionumbersexponent@@}{\renewionumbersexponent@}}
\newcommand*\renewionumbersexponent@[2]{\expandafter\renewcommand%
\expandafter*\csname ion@exponent@#1\endcsname{\ionumbersoff{#2}%
\ion@currnum@exponent}}
\newcommand*\renewionumbersexponent@@[2]{\expandafter\renewcommand%
\expandafter*\csname ion@exponent@#1\endcsname{\ionumbersoff{#2}%
\ion@currnum@exponent\ion@exponent@superscripttrue}}
% \end{macrocode}
% \end{macro}
%
% ---------------------------------------------------------------------
%
% \subsection{Internal macros holding definitions for \meta{key}=\meta{value}
% pairs}
%
% First of all, macros with the original character definitions are defined.
% \begin{macrocode}
\AtBeginDocument{
\mathchardef\ion@point@original=\the\mathcode`.
\mathchardef\ion@comma@original=\the\mathcode`,
\mathchardef\ion@plus@original=\the\mathcode`+
\mathchardef\ion@minus@original=\the\mathcode`-
\mathchardef\ion@zero@original=\the\mathcode`0
\mathchardef\ion@one@original=\the\mathcode`1
\mathchardef\ion@two@original=\the\mathcode`2
\mathchardef\ion@three@original=\the\mathcode`3
\mathchardef\ion@four@original=\the\mathcode`4
\mathchardef\ion@five@original=\the\mathcode`5
\mathchardef\ion@six@original=\the\mathcode`6
\mathchardef\ion@seven@original=\the\mathcode`7
\mathchardef\ion@eight@original=\the\mathcode`8
\mathchardef\ion@nine@original=\the\mathcode`9
\mathchardef\ion@e@original=\the\mathcode`e
\mathchardef\ion@E@original=\the\mathcode`E
}
% \end{macrocode}
%
% Here the |\ion@|\meta{key}|@|\meta{value} macros are defined, begining with
% the definitions for the comma as input separator.
% \begin{macrocode}
\def\ion@comma@ignore{}
\def\ion@comma@decimal{\ion@decimal@curr}
\def\ion@comma@thousands{\ion@thousands@curr}
\def\ion@comma@default{\ion@comma@thousands}
% \end{macrocode}
% The macros |\ion@comma@|\meta{value} contain the output for a comma appearing
% in the input. Actually, a second set of |\ion@|aftercomma|@|\meta{value}
% macros is required containing commands to be issued whenever a comma appears.
% If comma is the decimal separator, the appearance of comma in the input will
% mean that input of the thousands part is complete and the thousandths
% thousandths part starts (|\ion@beforedecimalfalse| must be issued). If comma
% is the thousands separator, the automatic grouping of thousands will be
% switched of for that number (|\ion@noexplicitthousandsfalse| must be issued).
% \begin{macrocode}
\def\ion@aftercomma@ignore{}
\def\ion@aftercomma@decimal{\ion@beforedecimalfalse}
\def\ion@aftercomma@thousands{\ion@noexplicitthousandsfalse}
\def\ion@aftercomma@default{\ion@aftercomma@thousands}
% \end{macrocode}
%
% An analogous set of macros is defined for the point as input separator.
% \begin{macrocode}
\def\ion@point@ignore{}
\def\ion@point@decimal{\ion@decimal@curr}
\def\ion@point@thousands{\ion@thousands@curr}
\def\ion@point@default{\ion@point@decimal}
% \end{macrocode}
% For the same reasons as mentioned before a set of
% |\ion@|afterpoint|@|\meta{value} macros is required.
% \begin{macrocode}
\def\ion@afterpoint@ignore{}
\def\ion@afterpoint@decimal{\ion@beforedecimalfalse}
\def\ion@afterpoint@thousands{\ion@noexplicitthousandsfalse}
\def\ion@afterpoint@default{\ion@afterpoint@decimal}
% \end{macrocode}
%
% Next the definitions for the decimal output separator, \ldots
% \begin{macrocode}
\def\ion@decimal@point{\mathord{\ion@point@original}}
\def\ion@decimal@comma{\mathord{\ion@comma@original}}
\def\ion@decimal@punctpoint{\mathpunct{\ion@decimal@point}}
\def\ion@decimal@punctcomma{\mathpunct{\ion@decimal@comma}}
\def\ion@decimal@default{\ion@decimal@point}
% \end{macrocode}
%
% \ldots{} the thousands output separator, \ldots
% \begin{macrocode}
\def\ion@thousands@none{}
\def\ion@thousands@point{\mathord{\ion@point@original}}
\def\ion@thousands@comma{\mathord{\ion@comma@original}}
\def\ion@thousands@punctpoint{\mathpunct{\ion@decimal@point}}
\def\ion@thousands@punctcomma{\mathpunct{\ion@decimal@comma}}
\def\ion@thousands@apostrophe{^\prime}
\def\ion@thousands@phantom{\phantom{\ion@point@original}}
\def\ion@thousands@space{\,}
\def\ion@thousands@default{\ion@thousands@punctcomma}
% \end{macrocode}
%
% \ldots{} the thousandths output separator, \ldots
% \begin{macrocode}
\def\ion@thousandths@none{}
\def\ion@thousandths@point{\mathord{\ion@point@original}}
\def\ion@thousandths@comma{\mathord{\ion@comma@original}}
\def\ion@thousandths@punctpoint{\mathpunct{\ion@decimal@point}}
\def\ion@thousandths@punctcomma{\mathpunct{\ion@decimal@comma}}
\def\ion@thousandths@apostrophe{^\prime}
\def\ion@thousandths@phantom{\phantom{\ion@point@original}}
\def\ion@thousandths@space{\,}
\def\ion@thousandths@default{\ion@thousandths@space}
% \end{macrocode}
%
% \ldots{} and the exponent output separator are given.
% \begin{macrocode}
\def\ion@exponent@none{}
\def\ion@exponent@original{\ion@e@original}
\def\ion@exponent@ite{\mathit{\ion@e@original}\ion@currnum@exponenttrue}
\def\ion@exponent@itE{\mathit{\ion@E@original}\ion@currnum@exponenttrue}
\def\ion@exponent@rme{\mathrm{\ion@e@original}\ion@currnum@exponenttrue}
\def\ion@exponent@rmE{\mathrm{\ion@E@original}\ion@currnum@exponenttrue}
\def\ion@exponent@timestento{\times10\,\ion@currnum@exponenttrue%
\ion@exponent@superscripttrue}
\def\ion@exponent@cdottento{\cdot10\,\ion@currnum@exponenttrue%
\ion@exponent@superscripttrue}
\def\ion@exponent@wedge{^\wedge\ion@currnum@exponenttrue}
\def\ion@exponent@default{\ion@exponent@original}
% \end{macrocode}
%
% ---------------------------------------------------------------------
%
% \subsection{Enabling and disabling features}
%
% The following helper macros make different subsets of |.,+-0123456789|
% active.
% \begin{macrocode}
\def\ion@separators@active{\catcode`\,=\active\catcode`\.=\active\relax}
\def\ion@signs@active{\catcode`\+=\active\catcode`\-=\active\relax}
\def\ion@digits@active{\catcode`\,=\active\catcode`\.=\active%
\catcode`\0=\active\catcode`\1=\active\catcode`\2=\active%
\catcode`\3=\active\catcode`\4=\active\catcode`\5=\active%
\catcode`\6=\active\catcode`\7=\active\catcode`\8=\active%
\catcode`\9=\active\relax}
% \end{macrocode}
%
% An analogous set of macros makes subsets of these characters active/inactive
% in math mode.
% \begin{macrocode}
\def\ion@separators@math@active{\mathcode`,="8000\mathcode`.="8000\relax}
\def\ion@signs@math@active{\mathcode`+="8000\mathcode`-="8000\relax}
\def\ion@digits@math@active{\mathcode`0="8000\mathcode`1="8000\mathcode`2="8000%
\mathcode`3="8000\mathcode`4="8000\mathcode`5="8000\mathcode`6="8000%
\mathcode`7="8000\mathcode`8="8000\mathcode`9="8000\relax}
\def\ion@separators@math@inactive{%
\mathcode`,=\the\ion@comma@original%
\mathcode`.=\the\ion@point@original%
\relax}
\def\ion@signs@math@inactive{%
\mathcode`+=\the\ion@plus@original%
\mathcode`-=\the\ion@minus@original%
\relax}
\def\ion@digits@math@inactive{%
\mathcode`0=\the\ion@zero@original%
\mathcode`1=\the\ion@one@original%
\mathcode`2=\the\ion@two@original%
\mathcode`3=\the\ion@three@original%
\mathcode`4=\the\ion@four@original%
\mathcode`5=\the\ion@five@original%
\mathcode`6=\the\ion@six@original%
\mathcode`7=\the\ion@seven@original%
\mathcode`8=\the\ion@eight@original%
\mathcode`9=\the\ion@nine@original%
\relax}
% \end{macrocode}
%
% Next the user interface for making |.,+-0123456789| active/inactive follows.
% \begin{macro}{\ionumbers}
% \begin{macrocode}
\def\ionumbers{\ion@separators@math@active\ion@signs@math@active%
\ion@digits@math@active}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\endionumbers}
% \begin{macrocode}
\def\endionumbers{\ion@separators@math@inactive\ion@signs@math@inactive%
\ion@digits@math@inactive}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ionumbersoff}
% \begin{macrocode}
\newcommand\ionumbersoff[1]{\begingroup\endionumbers#1\ionumbers\endgroup}
% \end{macrocode}
% \end{macro}
%
% Of course, at the begining of the document the charactars shall be active
% by default.
% \begin{macrocode}
\AtBeginDocument{\ionumbers}
% \end{macrocode}
%
% ---------------------------------------------------------------------
%
% \subsection{Definitions of active characters}
%
% The macro definitions for the characters |.,+-0123456789| are hold in the
% following macros. Number processing works by looking at the next character
% and performing one or more from the following actions:
% \begin{itemize}
% \item the currently configured output for the character will be added to
% the end of |\ion@currnum| by |\ion@currnum@append|;
% |\ion@currnum| stores the currently processed number
% \item only for comma/point: the corresponding |after...| macro will be
% issued
% \item the currently processed number will be output via
% |\ion@currnum@output|
% \item the |e| will be eaten and replaced by its configured output
% \end{itemize}
% The conditions in the macro definitions should be self-explanatory for each
% character. The extra |\ion@startnumber| is required to avoid problems with
% input like |$a_0$| or |$\sqrt 2$|, where curly braces around |0| and |2| have
% been omitted.
% \begin{macrocode}
\def\ion@comma{%
\ion@ifnextdigit{%
\ion@currnum@append*{\ion@comma@curr}\ion@aftercomma@curr%
}{%
\ion@ifnextseparator{%
\ion@currnum@append*{\ion@comma@curr}\ion@aftercomma@curr%
\@warning{Too many separators}%
}{%
\ion@ifnextchar e{%
\ion@currnum@append*{\ion@comma@curr}\ion@aftercomma@curr%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output\ion@comma@original%
}%
}%
}%
}
\def\ion@point{%
\ion@ifnextdigit{%
\ion@currnum@append*{\ion@point@curr}\ion@afterpoint@curr%
}{%
\ion@ifnextseparator{%
\ion@currnum@append*{\ion@point@curr}\ion@afterpoint@curr%
\@warning{Too many separators}%
}{%
\ion@ifnextchar e{%
\ion@currnum@append*{\ion@point@curr}\ion@afterpoint@curr%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output\ion@point@original%
}%
}%
}%
}
\def\ion@plus{%
\ion@iffirstchar{%
\ion@plus@original%
}{%
\ion@currnum@append*{\ion@plus@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextsign{%
\@warning{Too many signs}%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@minus{%
\ion@iffirstchar{%
\ion@minus@original%
}{%
\ion@currnum@append*{\ion@minus@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextsign{%
\@warning{Too many signs}%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@zero{%
\ion@iffirstchar{%
\ion@zero@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@zero@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@one{%
\ion@iffirstchar{%
\ion@one@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@one@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@two{%
\ion@iffirstchar{%
\ion@two@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@two@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@three{%
\ion@iffirstchar{%
\ion@three@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@three@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@four{%
\ion@iffirstchar{%
\ion@four@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@four@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@five{%
\ion@iffirstchar{%
\ion@five@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@five@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@six{%
\ion@iffirstchar{%
\ion@six@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@six@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@seven{%
\ion@iffirstchar{%
\ion@seven@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@seven@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@eight{%
\ion@iffirstchar{%
\ion@eight@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@eight@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
\def\ion@nine{%
\ion@iffirstchar{%
\ion@nine@original\ion@currnum@append{}%
}{%
\ion@currnum@append{\ion@nine@original}%
}%
\ion@ifnextdigit{%
%% nothing
}{%
\ion@ifnextseparator{%
%% nothing
}{%
\ion@ifnextchar e{%
\ion@currnum@output\ion@exponent@curr\@gobble%
}{%
\ion@currnum@output%
}%
}%
}%
}
% \end{macrocode}
%
% The macro |\ion@define@charmacros| is used to assign the above macros to the
% (active) characters |.,+-0123456789|. It will be executed later in the
% conflict test section.
% \begin{macrocode}
\begingroup
\ion@separators@active\ion@signs@active\ion@digits@active
\gdef\ion@define@charmacros{%
\global\let,=\ion@comma%
\global\let.=\ion@point%
\global\let+=\ion@plus%
\global\let-=\ion@minus%
\global\let0=\ion@zero%
\global\let1=\ion@one%
\global\let2=\ion@two%
\global\let3=\ion@three%
\global\let4=\ion@four%
\global\let5=\ion@five%
\global\let6=\ion@six%
\global\let7=\ion@seven%
\global\let8=\ion@eight%
\global\let9=\ion@nine%
}
\endgroup
% \end{macrocode}
%
% If one of |+-0123456789| is the first character of a number and this number
% not part of an exponent, then argument `1' will be used; otherwise argument
% `2' will be used. This macro is required to handle single characters not
% grouped in curly braces |{}| in expressions like |$a^0$| or |$\sqrt 2$|
% correctly.
% \begin{macrocode}
\def\ion@iffirstchar#1#2{%
\ifion@currnum@exponent%
#2%
\else%
\ifion@currnum@firstchar%
#1%
\else
#2%
\fi%
\fi%
\ion@currnum@firstcharfalse%
}
% \end{macrocode}
%
% Now the macros for the conditions in the above definitions follow. There are
% tests for a digit |0123456789|, \ldots
% \begin{macrocode}
\long\def\ion@ifnextdigit#1#2{%
\def\reserved@a{#1}%
\def\reserved@b{#2}%
\futurelet\@let@token\ion@ifnextdigit@}
\def\ion@ifnextdigit@{%
\ifx\@let@token1\let\reserved@c\reserved@a\else%
\ifx\@let@token2\let\reserved@c\reserved@a\else%
\ifx\@let@token3\let\reserved@c\reserved@a\else%
\ifx\@let@token4\let\reserved@c\reserved@a\else%
\ifx\@let@token5\let\reserved@c\reserved@a\else%
\ifx\@let@token6\let\reserved@c\reserved@a\else%
\ifx\@let@token7\let\reserved@c\reserved@a\else%
\ifx\@let@token8\let\reserved@c\reserved@a\else%
\ifx\@let@token9\let\reserved@c\reserved@a\else%
\ifx\@let@token0\let\reserved@c\reserved@a\else%
\let\reserved@c\reserved@b%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\reserved@c}
% \end{macrocode}
%
% \ldots{} for a separator |.,|, \ldots
% \begin{macrocode}
\long\def\ion@ifnextseparator#1#2{%
\def\reserved@a{#1}%
\def\reserved@b{#2}%
\futurelet\@let@token\ion@ifnextseparator@}
\def\ion@ifnextseparator@{%
\ifx\@let@token,\let\reserved@c\reserved@a\else%
\ifx\@let@token.\let\reserved@c\reserved@a\else%
\let\reserved@c\reserved@b%
\fi%
\fi%
\reserved@c}
% \end{macrocode}
%
% \ldots{} and for a sign |+-| as next character.
% \begin{macrocode}
\long\def\ion@ifnextsign#1#2{%
\def\reserved@a{#1}%
\def\reserved@b{#2}%
\futurelet\@let@token\ion@ifnextsign@}
\def\ion@ifnextsign@{%
\ifx\@let@token+\let\reserved@c\reserved@a\else%
\ifx\@let@token-\let\reserved@c\reserved@a\else%
\let\reserved@c\reserved@b%
\fi%
\fi%
\reserved@c}
% \end{macrocode}
%
% An additional test for an arbitrary character is also added. It obeys white
% spaces in contrast to \LaTeX{}'s |\@ifnextchar|.
% \begin{macrocode}
\long\def\ion@ifnextchar#1#2#3{%
\let\reserved@d=#1%
\def\reserved@a{#2}%
\def\reserved@b{#3}%
\futurelet\@let@token\ion@ifnextchar@}
\def\ion@ifnextchar@{%
\ifx\@let@token\reserved@d%
\let\reserved@c\reserved@a%
\else%
\let\reserved@c\reserved@b%
\fi%
\reserved@c}
% \end{macrocode}
%
% ---------------------------------------------------------------------
%
% \subsection{Test for conflicts with other packages}
%
% First of all we test for some packages known to conflict with
% \textsf{ionumbers}. This will be done by checking at the begining of the
% document, if one of these packages has been loaded and an error/warning will
% be issued.
% \begin{macrocode}
\newcommand*{\ion@conflict@package}[1]{%
\@ifpackageloaded{#1}{%
\PackageError{ionumbers}%
{Packages #1 and ionumbers conflict!\MessageBreak%
Do not load both packages in the same document}{}%
}{}%
}
\newcommand*{\ion@problem@package}[2]{%
\@ifpackageloaded{#1}{%
\PackageWarning{ionumbers}%
{Loading #1 and ionumbers is problematic!\MessageBreak#2}%
}{}%
}
\AtBeginDocument{%
\ion@conflict@package{ziffer}%
\ion@problem@package{dcolumn}{Use `tabular's inside \string\ionumbersoff}%
\ion@problem@package{amsmath}{Load ionumbers after amsmath}%
\ion@problem@package{amsmath}{Use \string\operatorname\space inside
\string\ionumbersoff}%
\ion@problem@package{amsopn}{Use \string\operatorname\space inside
\string\ionumbersoff}%
}
% \end{macrocode}
%
% Next the characters |.,+-0123456789| are checked for macro definitions (by
% other packages). This way conflicts with other packages may be detected with
% some probability (but only if the conflicting package has already been
% loaded).
% \begin{macrocode}
\newcommand*\ion@conflict@definedtest[1]{%
\ifx#1\@undefined\else\PackageWarning{ionumbers}%
{Potential conflict with other package(s) detected.\MessageBreak%
`\string#1' has already been defined. I will redefine it.\MessageBreak%
This might break other package(s)!\MessageBreak}\fi}
\begingroup
\ion@separators@active\ion@signs@active\ion@digits@active
\ion@conflict@definedtest{,}
\ion@conflict@definedtest{.}
\ion@conflict@definedtest{+}
\ion@conflict@definedtest{-}
\ion@conflict@definedtest{0}
\ion@conflict@definedtest{1}
\ion@conflict@definedtest{2}
\ion@conflict@definedtest{3}
\ion@conflict@definedtest{4}
\ion@conflict@definedtest{5}
\ion@conflict@definedtest{6}
\ion@conflict@definedtest{7}
\ion@conflict@definedtest{8}
\ion@conflict@definedtest{9}
\endgroup
% \end{macrocode}
%
% After the above test the definitions of the characters of
% \textsf{ionumbers} can be applied.
% \begin{macrocode}
\ion@define@charmacros
% \end{macrocode}
%
% Additionally, \textsf{ionumbers} tests for redefinitions of the macros
% of the characters at the begining of the document.
% \begin{macrocode}
\newcommand*{\ion@conflict@redefinedtest}[2]{%
\ifx#1#2\else\PackageWarning{ionumbers}%
{Potential conflict with other package(s) detected.\MessageBreak%
`\string#1' has been redefined. This might break ionumbers!\MessageBreak}%
\fi}
\begingroup
\ion@separators@active\ion@signs@active\ion@digits@active
\gdef\ion@conflict@redefinedtest@macro{%
\ion@conflict@redefinedtest{,}{\ion@comma}%
\ion@conflict@redefinedtest{.}{\ion@point}%
\ion@conflict@redefinedtest{+}{\ion@plus}%
\ion@conflict@redefinedtest{-}{\ion@minus}%
\ion@conflict@redefinedtest{0}{\ion@zero}%
\ion@conflict@redefinedtest{1}{\ion@one}%
\ion@conflict@redefinedtest{2}{\ion@two}%
\ion@conflict@redefinedtest{3}{\ion@three}%
\ion@conflict@redefinedtest{4}{\ion@four}%
\ion@conflict@redefinedtest{5}{\ion@five}%
\ion@conflict@redefinedtest{6}{\ion@six}%
\ion@conflict@redefinedtest{7}{\ion@seven}%
\ion@conflict@redefinedtest{8}{\ion@eight}%
\ion@conflict@redefinedtest{9}{\ion@nine}%
}
\endgroup
\AtBeginDocument{\ion@conflict@redefinedtest@macro}
% \end{macrocode}
%
% ---------------------------------------------------------------------
%
% \subsection{Commands for current number}
%
% Numbers are processed by first storing one character after the other in an
% internal macro to be able to automatically group digits. The basic idea when
% adding single characters is
% \begin{itemize}
% \item remember, whether we are processing the thousands or the thousandths
% part of a number (|\ifion@beforedecimal|)
% \item calculate the number of digits processed modulo 3 plus 1 in the
% current part and
% \begin{itemize}
% \item for the thousands part: add |\ion@thousands@sepa| for 1,
% |\ion@thousands@sepb| for 2, |\ion@thousands@sepc| for 3, \ldots{}
% after a digit
% \item for the thousandths part: add |\ion@thousandths@sep| after each
% third digit
% \end{itemize}
% \end{itemize}
% The macros |\ion@thousands@sep...| and |\ion@thousandths@sep| are empty by
% default. Before outputting the number, the number of digits in the thousands
% part is known and the correct |\ion@thousands@sep...| macro can be set to the
% thousands separator for correct grouping.
%
% First of all, the |if|s, counters and empty separator macros are initialized.
% \begin{macrocode}
\newif\ifion@currnum@firstchar\ion@currnum@firstchartrue
\newif\ifion@beforedecimal\ion@beforedecimaltrue
\newif\ifion@noexplicitthousands\ion@noexplicitthousandstrue
\newif\ifion@currnum@exponent\ion@currnum@exponentfalse
\newif\ifion@exponent@superscript\ion@exponent@superscriptfalse
\newcount\ion@thousands@currpos\ion@thousands@currpos=0
\newcount\ion@thousandths@currpos\ion@thousandths@currpos=0
\def\ion@currnum{}
\def\ion@thousands@sepa{}
\def\ion@thousands@sepb{}
\def\ion@thousands@sepc{}
\def\ion@thousands@sepd{}
\def\ion@thousands@sepe{}
\def\ion@thousands@sepf{}
\def\ion@thousands@sepg{}
\def\ion@thousands@seph{}
\def\ion@thousands@sepi{}
\def\ion@thousandths@sep{}
% \end{macrocode}
%
% The macro |\ion@currnum@append| adds the character in its argument to the
% end of |\ion@currnum|. In the starred version adding of an empty separator
% macros is omitted.
% \begin{macrocode}
\newcommand{\ion@currnum@append}{%
\ion@currnum@firstcharfalse%
\@ifstar{\ion@currnum@append@@}{\ion@currnum@append@}%
}
\newcommand*{\ion@currnum@append@@}[1]{%
\ion@addto@macro{\ion@currnum}{#1}%
}
\newcommand*{\ion@currnum@append@}[1]{%
\ifion@beforedecimal%
%% push back (empty) separator and character
\ifcase\ion@thousands@currpos%
\ion@addto@macro{\ion@currnum}{#1}%
\or%
\ion@addto@macro{\ion@currnum}{\ion@thousands@sepa#1}%
\or%
\ion@addto@macro{\ion@currnum}{\ion@thousands@sepb#1}%
\or%
\ion@addto@macro{\ion@currnum}{\ion@thousands@sepc#1}%
\or%
\ion@addto@macro{\ion@currnum}{\ion@thousands@sepd#1}%
\or%
\ion@addto@macro{\ion@currnum}{\ion@thousands@sepe#1}%
\or%
\ion@addto@macro{\ion@currnum}{\ion@thousands@sepf#1}%
\or%
\ion@addto@macro{\ion@currnum}{\ion@thousands@sepg#1}%
\or%
\ion@addto@macro{\ion@currnum}{\ion@thousands@seph#1}%
\or%
\ion@addto@macro{\ion@currnum}{\ion@thousands@sepi#1}%
\fi%
%% advance thousands counter
\advance\ion@thousands@currpos by1\relax%
\ifnum\ion@thousands@currpos>\ion@grplenthousands%
\ion@thousands@currpos=1%
\fi%
\else%
%% push back (empty) separator and character
\ifnum\ion@thousandths@currpos=\ion@grplenthousandths%
\ion@addto@macro{\ion@currnum}{\ion@thousandths@sep#1}%
\else%
\ion@addto@macro{\ion@currnum}{#1}%
\fi%
%% advance thousandths counter
\advance\ion@thousandths@currpos by1\relax%
\ifnum\ion@thousandths@currpos>\ion@grplenthousandths%
\ion@thousandths@currpos=1%
\fi%
\fi%
}
% \end{macrocode}
%
% The |\ion@currnum@output| macro defines the empty separator macros (depending
% on the current configuration), outputs the current number, and resets
% everything for the next number.
% \begin{macrocode}
\newcommand*{\ion@currnum@output}{%
\begingroup%
%% set automatic thousands separator
\ifion@autothousands%
\ifion@noexplicitthousands%
\ifcase\ion@thousands@currpos%
%% do nothing
\or%
\def\ion@thousands@sepa{\ion@thousands@curr}%
\or%
\def\ion@thousands@sepb{\ion@thousands@curr}%
\or%
\def\ion@thousands@sepc{\ion@thousands@curr}%
\or%
\def\ion@thousands@sepd{\ion@thousands@curr}%
\or%
\def\ion@thousands@sepe{\ion@thousands@curr}%
\or%
\def\ion@thousands@sepf{\ion@thousands@curr}%
\or%
\def\ion@thousands@sepg{\ion@thousands@curr}%
\or%
\def\ion@thousands@seph{\ion@thousands@curr}%
\or%
\def\ion@thousands@sepi{\ion@thousands@curr}%
\fi%
\fi%
\fi%
%% set automatic thousandths separator
\ifion@autothousandths%
\def\ion@thousandths@sep{\ion@thousandths@curr}%
\fi%
%% output number
\ifion@currnum@exponent%
\ifion@exponent@superscript%
^{\ion@currnum}%
\else%
{\ion@currnum}%
\fi%
\else
\ion@currnum%
\fi
\endgroup%
%% reset stuff for next number
\ion@thousands@currpos=0%
\ion@thousandths@currpos=0%
\def\ion@currnum{}%
\ion@currnum@firstchartrue%
\ion@beforedecimaltrue%
\ion@noexplicitthousandstrue%
\ion@currnum@exponentfalse%
\ion@exponent@superscriptfalse%
}
% \end{macrocode}
%
% This macro is identical to |\l@addto@macro| from \textsf{koma-script bundle}.
% \begin{macrocode}
\newcommand{\ion@addto@macro}[2]{%
\begingroup\toks@\expandafter{#1#2}%
\edef\@tempa{\endgroup\def\noexpand#1{\the\toks@}}%
\@tempa}
% \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \Finale
%
\endinput
|