summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/numprint/numprint032.dtx
blob: 7b8865986f0ffad4b1aecf6b39029ea74c3d7d0a (plain)
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
% \iffalse meta comment
% File: numprint032.dtx Copyright (C) 2000--2004 Harald Harders
% \fi
%
% \iffalse
%
%<*package>
\def\packagename{numprint}
\def\nprtfileversion{0.32}
\def\nprtfiledate{2003/09/18}
\def\nprtdocdate{2003/09/18}
%</package>
%<*driver>
\documentclass{ltxdoc}
\IfFileExists{numprint.sty}{\usepackage{numprint}
 \let\numprintSTYfound\active}{\GenericWarning{numprint.dtx}{Package
 file numprint.sty not found (Documentation will be messed up!^^J^^A
 Generate numprint.sty by (La)TeXing numprint.ins, process
 numprint.dtx again)^^J}\stop}
\usepackage{longtable}
\title{The \texttt{numprint} package\thanks{This file has version 
    \nprtfileversion\ last revised \nprtfiledate, documentation dated
    \nprtdocdate.}}
\author{Harald Harders\\\texttt{harald.harders@gmx.de}}
\date{File Date \nprtfiledate, Printed \today}
\npdecimalsign{.}%
\newlength{\tempdima}%
\makeatletter
\renewenvironment{table}[1][]{%
  \@float{table}[#1]%
  \centering%
  \setlength{\tempdima}{\abovecaptionskip}%
  \setlength{\abovecaptionskip}{\belowcaptionskip}%
  \setlength{\belowcaptionskip}{\tempdima}%
  }{%
\end@float
}
\makeatother
\EnableCrossrefs
\CodelineIndex
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
\DoNotIndex{\setcounter,\space,\if,\else,\fi,\empty,\@empty,\ifx,\fi}
\DoNotIndex{\ifnum,\fi,\expandafter}
\CodelineNumbered
\RecordChanges
%\CheckSum{1016}
\begin{document}
 \DocInput{numprint.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{0.01}{2000/08/30}{Changed to dtx format}
% \changes{0.08}{2001/01/08}{Preceed ``np'' to some commands due to
% incompatibility with babel french}
%
% \maketitle
% \begin{abstract}
% \noindent This package prints numbers with a separator every three
% digits and it convert numbers given as |12345.6e789| to
% $12\,345{,}6\cdot 10^{789}$.
% The decimal sign, the thousand separator, as well as the product
% sign can be changed by the user, e.g. to reach
% $12{,}345.6\times 10^{789}$.
% If an optional argument is given it is printed upright as unit.
% \changes{0.21}{2003/02/25}{Abstract changed}
% \end{abstract}
%
% \tableofcontents
%
% \section*{Copyright}
% Copyright 2000--2004 Harald Harders.
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
%
% \section{The user interface}
%
% To use this package place
% \begin{verbatim}
%\usepackage{numprint}
% \end{verbatim}
% in the preamble of your document. No options are necessary.
%
% \subsection{Print numbers in text and math mode}
%
% \DescribeMacro{\numprint}%
% The package provides the command \verb|\numprint[#1]{#2}| that prints
% the number given in the required argument. The number is printed in the
% active mode (math or text) so that an eventual chosen difference
% between mathematical and text numbers stays visible (e.g. by using
% the eco-package.
%
% Numbers may contain of these characters:
% ``|+-\pm0123456789.,eE|''. Either a ``,'' or a ''.'' can be used as
% decimal sign. No thousand separators are allowed in the
% argument. ``E'' or ``e'' is converted to $\cdot 10^{x}$.
% |\pm| produces a $\pm$.
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}%
% From version 0.30 on, \cs{numprint} is stricter with the argument.
% It tests wheather the argument contains of supported characters
% only.
%
% For example typing
% \begin{verbatim}
%\numprint{-123456}; \numprint[N/mm^2]{-123456}; \numprint{3,1415927e-3.1}
% \end{verbatim}
% leads to ``\numprint{-123456}; \numprint[N/mm^2]{-123456};
% \numprint{3,1415927e-3.1}''. Notice 
% that ``.'' and ``,'' can be mixed within one number.
%
% If no number is given before the exponential character ``e''
% resp. ``E'' a pure exponential format is generated.
% For example typing
% \begin{verbatim}
%\numprint{e4.3242}
% \end{verbatim}
% leads to ``\numprint{e4.3242}''.
% \changes{0.04}{2001/03/06}{Added support for pure $10^x$ format}%
%
% \changes{0.02}{2000/08/30}{Added optional argument for units}%
% If the optional argument is given it is printed as a unit in math
% mode with an upright font (\verb|\mathrm|). The space between the
% number and the unit is \verb|\,| by default. It can be changed using
% the command |\npunitseparator|.
%
% \DescribeMacro{\npthousandsep}%
% \DescribeMacro{\npthousandthpartsep}%
% \DescribeMacro{\npdecimalsign}%
% \DescribeMacro{\npproductsign}%
% By using the three commands \verb|\npthousandsep{#1}|,
% \verb|\npdecimalsign{#1}|, and
% \verb|\npproductsign{#1}|\footnote{These command did not have the
% ``np'' in older versions. This had to be changed in order to avoid
% an incompatibiliby with the french language of babel.} several
% separators can be changed. E.g.
% \begin{verbatim}
%\npdecimalsign{\ensuremath{\cdot}}\npthousandsep{,}\npproductsign{\times}%
%\numprint{-123456}; \numprint{3,1415927e-3.1}
% \end{verbatim}
% leads to ``{\npdecimalsign{\ensuremath{\cdot}}%
% \npthousandsep{,}\npproductsign{\times}%
% \numprint{-123456}; \numprint{3,1415927e-3.1}}''.
%
% \DescribeMacro{\global}%
% These commands change the behaviour of the \verb|\numprint| command
% only locally (inside the current group). By preceding \verb|\global| 
% the change can be made global inside a group. For example:
% \begin{verbatim}
%Local:
%\numprint{123e4},
%{\npproductsign{\times}\numprint{123e4}},
%\numprint{123e4}.
%Global:
%\numprint{123e4},
%{\global\npproductsign{\times}\numprint{123e4}},
%\numprint{123e4}
% \end{verbatim}
% leads to the following:
%
% \noindent Local:
% \numprint{123e4},
% {\npproductsign{\times}\numprint{123e4}},
% \numprint{123e4}.
% Global:
% \numprint{123e4},
% {\global\npproductsign{\times}\numprint{123e4}},
% \numprint{123e4}
% \npproductsign{\cdot}
%
% The current version has the following defaults:
% \begin{verbatim}
%\npthousandsep{\,}
%\npthousandthpartsep{\,}
%\npdecimalsign{,}
%\npproductsign{{}\cdot{}}
%\npunitseparator{\,}
% \end{verbatim}
% These will surely change in a new version when I add automatic
% international support. Then the defaults will by language dependent.
%
% \changes{0.31}{2003/09/16}{Describe automatic language-dependent
%   switch of decimal sign}%
% If you are using the |babel| package you may reach an automatic
% change of the parameters by using the \cs{addto} command of |babel|,
% e.g.:
% \begin{verbatim}
%\addto\extrasenglish{%
%  \npthousandsep{,}%
%  \npthousandthpartsep{,}%
%  \npdecimalsign{.}%
%  \npproductsign{{}\times{}}%
%}
%\addto\extrasngerman{%
%  \npthousandsep{\,}%
%  \npthousandthpartsep{\,}%
%  \npdecimalsign{,}%
%  \npproductsign{{}\cdot{}}%
%}
% \end{verbatim}
%
% \subsection{Change the behaviour}
% \subsubsection{Eliminate separators for four-digit numbers}
%
% \DescribeMacro{\fourdigitsep}%
% \DescribeMacro{\fourdigitnosep}%
% \changes{0.06}{2002/09/18}{Add description for not separating four
% digit numbers}%
% Some people want numbers with four digits not to be devided by a
% thousand separator.
% This can be achieved using the command |\fourdigitnosep|.
% You can switch back to separating with |\fourdigitsep|.
% An example:
% \begin{verbatim}
%\fourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
%\fourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$
% \end{verbatim}
% Leads to
% ``\fourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
% \fourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$''.
% Default values can be set by the package options |sepfour| and
% |nosepfour|.
%
% If a number has four digits before the decimal sign, but more than
% four digits after it, or vice versa, the fourth digit is seperated
% \emph{before and after} the digital sign for consistency. 
% An example:
% \begin{verbatim}
%\fourdigitnosep$\numprint{1234.1234}$, $\numprint{1234.12345}$,
%$\numprint{12345.1234}$
% \end{verbatim}
% Leads to
% ``\fourdigitnosep$\numprint{1234.1234}$, $\numprint{1234.12345}$,
% $\numprint{12345.1234}$''.
%
% \subsubsection{Add missing zeros before or after decimal sign}
%
% \DescribeMacro{\addmissingzero}%
% \DescribeMacro{\noaddmissingzero}%
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% Sometimes people let out a leading zero or a zero after the
% decimalsign, e.g. |123.| or |.123|. 
% Numprint can add the left out zero, when |\addmissingzero| is
% used. This behaviour can be switched of with |\noaddmissingzero|.
% Corresponding package options are |addmissingzero| and
% |noaddmissinzero|. Default is |addmissingzero|.
%
%
% \subsubsection[Rounding numbers]{Rounding numbers\footnote{This was
% an idea of Tilman Finke, tfinke@it-and-law.de}}%
% \changes{0.30}{2003/05/19}{Add rounding of numbers}%
%
% \DescribeMacro{\nprounddigits}%
% \DescribeMacro{\nproundexpdigits}%
% \DescribeMacro{\npnoround}%
% \DescribeMacro{\npnoroundexp}%
% By default, as many digits are printed after the decimal sign, as
% the \cs{numprint} command gets as argument.
% This behaviour can be changed to print a given number of digits
% where the number is rounded resp.\ filled with zeros.
% 
% This can be switched of using the
% \cs{nprounddigits\{\meta{\normalfont digits}\}} command for ordinary
% numbers and the \cs{nproundexpdigits\{\meta{\normalfont digits}\}}
% command for exponents.
% Rounding is switched off with \cs{npnoround} resp.\
% \cs{npnoroundexp}.
% For example,
% \begin{verbatim}
%\nprounddigits{2}$\numprint{1.123}$, $\numprint{1.149}$,
%$\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$ --
%\npnoround$\numprint{1.123}$, $\numprint{1.149}$,
%$\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$
% \end{verbatim}
% leads to
% ``\nprounddigits{2}$\numprint{1.123}$, $\numprint{1.149}$,
% $\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$ --
% \npnoround$\numprint{1.123}$, $\numprint{1.149}$,
% $\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$''
%
% \DescribeMacro{\npreplacenull}%
% \DescribeMacro{\npprintnull}%
% For amounts of money, sometimes a zero after the decimal sign is
% replaced by different signs, as for example ``---''. 
% If rounding is switched on, this can be done by calling
% \cs{npreplacenull\{\meta{\normalfont replacement}\}}, e.g.
% \begin{verbatim}
%\npreplacenull{\mbox{---}}
% \end{verbatim}
% Here, \cs{mbox} guarantees that ``---'' is printed in text mode.
% It can be switched off using \cs{npprintnull}.
%
%
% \subsection{Print aligned numbers in tabulars}%
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular
%   entries}%
%
% The aim of this function is to combine the functionality of the
% \verb|dcolumn| package with this one. This has not been achieved by
% this version. But a first step is done.
%
% \DescribeMacro{columntype n}
% \DescribeMacro{columntype N}
% This package defines two new column types \verb|n| and \verb|N|. The
% first one alignes the base number to the decimal sign, the second
% additionaly alignes the exponent.
% Use these commands like follows:
% \begin{verbatim}
%\begin{tabular}{|n{5}{3}|N{5}{3}{3}|}
%  \hline
%  \numprint{123.45e12.12}& \numprint{123.45e12.12}\\
%  \numprint{12345.678e123.123}& \numprint{12345.678e123.123}\\
%  \hline
%\end{tabular}
% \end{verbatim}
% This leads to\par
% \begin{tabular}{|n{5}{3}|N{5}{3}{3}|}
%   \hline
%   \numprint{123.45e12.12}& \numprint{123.45e12.12}\\
%   \numprint{12345.678e123.123}& \numprint{12345.678e123.123}\\
%   \hline
% \end{tabular}
%
% The first option defines the number of digits before the decimal
% sign, the second the number after.
% In case of the type \verb|N| the third option defines the number of
% digits before the decimal sign in the exponent.
% Unfortunately the number of digits can not be calculated
% automatically.
% Notice that the command \verb|\numprint| has to be written again in
% each tabular entry. This will hopefully be changed in a future version.
%
% \section{To Do}
%
% \begin{itemize}
% \item Add automatic international support using babel, german, or ngerman:
%
% German: \npdecimalsign{,}\npthousandsep{\,}\npproductsign{\cdot}%
% \numprint{3,1415927e-3.1}
%
% American: \npdecimalsign{.}\npthousandsep{,}\npproductsign{\times}%
% \numprint{3,1415927e-3.1}
% \item Combine the packages dcolumn and numprint.
% \item Fix spacing in aligned exponents (spacing is too large).
% \end{itemize}
%
% \StopEventually{\PrintChanges \PrintIndex}
%
%
% \section{The implementation}
% \iffalse
%<*package>
% \fi
% Heading of the package:
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{numprint032}[\nprtfiledate\space v\nprtfileversion\space
  Print numbers]
\message{Package `numprint032', Version \nprtfileversion\space of \nprtfiledate.}
\message{Compatiblity version of numprint for versions prior 1.00}
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Load package calc.sty for calculating widths of boxes.
%    \begin{macrocode}
\RequirePackage{calc}
%    \end{macrocode}
% Load package array.sty for the new column types.
%    \begin{macrocode}
\RequirePackage{array}
%    \end{macrocode}
% Define a boolean if the first digit is separated in a four digit
% number. Default is true for compatibility with older versions.
%    \begin{macrocode}
\newif\if@numsepfour
%    \end{macrocode}
% Define a command which helds the zero to be added if necessary.
%    \begin{macrocode}
\newcommand\@addmissingzero{}
%    \end{macrocode}
% \begin{macro}{\fourdigitsep}
% Switch separating of the fourth digit on.
%    \begin{macrocode}
\newcommand*{\fourdigitsep}{\@numsepfourtrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\fourdigitnosep}
% Switch separating of the fourth digit off.
%    \begin{macrocode}
\newcommand*{\fourdigitnosep}{\@numsepfourfalse}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\addmissingzero}
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% Add a missing zero before or after decimalsign.
%    \begin{macrocode}
\newcommand*{\addmissingzero}{\def\@addmissingzero{0}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\noaddmissingzero}
% Don't add a missing zero before or after decimalsign.
%    \begin{macrocode}
\newcommand*{\noaddmissingzero}{\def\@addmissingzero{}}%
%    \end{macrocode}
% \end{macro}
% Declare options. \verb|nosepfour| switches seperating of the fourth
% digit off, \verb|sepfour| switches it on. Default is on four
% compatibility reasons with older versions.
%    \begin{macrocode}
\DeclareOption{nosepfour}{\fourdigitnosep}
\DeclareOption{sepfour}{\fourdigitsep}
\DeclareOption{noaddmissingzero}{\noaddmissingzero}
\DeclareOption{addmissingzero}{\addmissingzero}
\ExecuteOptions{sepfour,addmissingzero}
\ProcessOptions\relax
%    \end{macrocode}
% Define commands to change the output of the \verb|\numprint|
% command.
%
% \begin{macro}{\npdecimalsign}
% Change the decimal sign. In English it is normally ``.'', in German
% ``,''.
% The additional pair of braces \verb|{}| prevents from inserting
% additional space in math mode, e.g. $1,2$ versus $1{,}2$.
%    \begin{macrocode}
\newcommand{\npdecimalsign}[1]{\def\nprt@decimal{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npthousandsep}
% Change the thousand separator. In English it often is ``,'', in
% German ``.'' or ``\,'' (\verb|\,|).
% Here again the additional \verb|{}| is used as above.
% This command changes both the sign before and after the comma. If
% you want a different sign after the comma you have to call
% \verb|\npthousandthpartsep| after \verb|\npthousandsep|.
%    \begin{macrocode}
\newcommand{\npthousandsep}[1]{\def\nprt@thousand{{#1}}%
  \def\nprt@thousandthpart{{#1}}}
%    \end{macrocode}
% \end{macro}%
% \begin{macro}{\npthousandthpartsep}
%    \begin{macrocode}
\newcommand{\npthousandthpartsep}[1]{\def\nprt@thousandthpart{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npproductsign}
% Change the product sign that is printed in numbers with exponent
% like $\numprint{123e4}$. Normally it is \verb|\cdot|. In American
% texts sometimes \verb|\times|.
% The two pairs of braces \verb|{}| ensure the correct spacing on the
% left and right side of the product sign, e.g. 3$\cdot$4 versus
% 3${}\cdot{}$4.
%    \begin{macrocode}
\newcommand{\npproductsign}[1]{\def\nprt@prod{\ensuremath{{}#1{}}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npunitseparator}
% Change the separator between number an unit.
% Here again the additional \verb|{}| is used as above.
% \changes{0.03}{2001/02/10}{Fixed bug with units}%
%    \begin{macrocode}
\newcommand{\npunitseparator}[1]{\def\nprt@unitsep{{#1}}}
%    \end{macrocode}
% \end{macro}
% Set the default values for the separators. They will surely change
% in a new version with automatic international support. At the moment 
% the defaults match the German language.
%    \begin{macrocode}
\npthousandsep{\,}%
\npthousandthpartsep{\,}%
\npdecimalsign{,}%
\npproductsign{{}\cdot{}}%
\npunitseparator{\,}%
%    \end{macrocode}
% \changes{0.30}{2003/05/19}{Add rounding of numbers}%
% \begin{macro}{\@fillnull}
% Defines command |#1| with a number of |#2| zeros filled.
%    \begin{macrocode}
\def\@fillnull#1#2{%
  \@tempcnta=0
  \loop
    \g@addto@macro{#1}{0}%
    \advance\@tempcnta by 1
  \ifnum\@tempcnta<#2
  \repeat
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprounddigits}
% Define a command that sets a count of digits after which the number
% is rounded.
% This command defines \cs{nprt@rounddigits} that stores the count and
% \cs{nprt@roundnull} that contains of \cs{nprt@rounddigits} ``0''
% digits.
%    \begin{macrocode}
\newcommand\nprounddigits[1]{%
  \def\nprt@rounddigits{#1}%
  \def\nprt@roundnull{}%
  \@fillnull{\nprt@roundnull}{#1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoround}
% A command to switch off rounding.
%    \begin{macrocode}
\newcommand\npnoround{\nprounddigits{-1}}
%    \end{macrocode}
% \end{macro}
% Don't round by default.
%    \begin{macrocode}
\npnoround
%    \end{macrocode}
% \begin{macro}{\nproundexpdigits}
% \begin{macro}{\npnoroundexp}
% The same for exponents.
%    \begin{macrocode}
\newcommand\nproundexpdigits[1]{%
  \def\nprt@roundexpdigits{#1}%
  \def\nprt@roundexpnull{}%
  \@fillnull{\nprt@roundexpnull}{#1}%
  }
\newcommand\npnoroundexp{\nproundexpdigits{-1}}
\npnoroundexp
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \changes{0.30}{2003/05/19}{Optionally replace zero after decimal sign}%
% \begin{macro}{\npreplacenull}
% Optionally, one or more zeros after the decimal sign can be replaced
% by other text, e.g.\ ``---'''.
%    \begin{macrocode}
\newcommand\npreplacenull[1]{\def\nprt@replacenull{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npprintnull}
% Switch off replacement, again.
%    \begin{macrocode}
\newcommand\npprintnull{\let\nprt@replacenull=\@empty}
%    \end{macrocode}
% \end{macro}
% Print the zero by default.
%    \begin{macrocode}
\npprintnull
%    \end{macrocode}
% Define the signs as commands. This is necessary to be able to
% compare them with other characters. 
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}%
%    \begin{macrocode}
\def\nprt@plus@test{+}
\def\nprt@minus@test{-}
\def\nprt@plusminus@test{\pm}
%    \end{macrocode}
% Define commands for printing the signs in math mode. This ensures
% that the printed signs really are signs and not hyphens. Compare
% ``-'' to ``\ensuremath{-}''.
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}%
%    \begin{macrocode}
\def\nprt@plus{\ensuremath{+}}
\def\nprt@minus{\ensuremath{-}}
\def\nprt@plusminus{\ensuremath{\pm}}
%    \end{macrocode}
% \begin{macro}{\nprt@printdigit}
% Print a digit. If this digit is a sign (\verb|+| or \verb|-|) it is
% printed in math mode, else it is printed in the active mode.
%    \begin{macrocode}
\def\nprt@printdigit#1{%
  \def\nprt@tmp{#1}%
  \ifx\nprt@tmp\nprt@plus@test
    \nprt@plus
  \else
    \ifx\nprt@tmp\nprt@minus@test
      \nprt@minus
    \else
      \ifx\nprt@tmp\nprt@plusminus@test
        \nprt@plusminus
      \else
        #1%
      \fi
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Define some booleans.
% \verb|\ifnprt@block| decides whether the number is centered to the
% decimal sign.
% \verb|\ifnprt@blockexp| does the same for the exponent.
% \verb|\ifnprt@exponent| is true when printing the exponent and false
% otherwise.
% \verb|\ifnprt@inmath| is set to true when using the command in math
% mode.
%    \begin{macrocode}
\newif\ifnprt@block
\newif\ifnprt@blockexp
\newif\ifnprt@exponent
\newif\ifnprt@inmath
%    \end{macrocode}
% \begin{macro}{\digits}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% With this command the user can switch to aligned printing.
% The first parameter stands for the digits before the decimal sign
% and the second for the digits after it.
%    \begin{macrocode}
\newcommand{\digits}[2]{%
  \xdef\nprt@blockbefore{#1}%
  \xdef\nprt@blockafter{#2}%
  \nprt@blocktrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nodigits}
% Switch back to normal printing.
%    \begin{macrocode}
\newcommand{\nodigits}{\nprt@blockfalse}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\exponentdigits}
% With this command the user can switch to aligned printing of the
% exponent.
% The parameter stands for the digits before the decimal sign.
%    \begin{macrocode}
\newcommand{\exponentdigits}[1]{%
  \xdef\nprt@blockexpbefore{#1}%
  \nprt@blockexptrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\noexponentdigits}
% Switch back to normal printing.
%    \begin{macrocode}
\newcommand{\noexponentdigits}{\nprt@blockexpfalse}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@three}
% Print up to three digits and call this command again recursively if there
% are more digits to print.
%
% The command must be called in a different way than normal \LaTeX\
% commands. Braces must not be used but at the end of the command
% list \verb|\@empty| has to appear in the source code. The command
% gets four arguments where the first three are single digits and the
% fourth contains the rest of the text preceding the \verb|\@empty|.
%    \begin{macrocode}
\def\nprt@three#1#2#3#4\@empty{%
%    \end{macrocode}
% Print the three digits.
%    \begin{macrocode}
  \nprt@printdigit#1%
  \nprt@printdigit#2%
  \nprt@printdigit#3%
%    \end{macrocode}
% Define a temporary variable containing the rest string for testing
% if there is a rest at all.
%    \begin{macrocode}
  \def\nprt@tmp{#4}%
  \ifx\nprt@tmp\empty
  \else
%    \end{macrocode}
% If there is a rest string insert the thousand separator \dots
%    \begin{macrocode}
    \nprt@thousand%
%    \end{macrocode}
% \dots\ and call this command recursively.
% Append enough \verb|\@empty| statements to ensure that the command
% gets four arguments.
%    \begin{macrocode}
    \nprt@three#4\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@threeafter}
% Print up to three digits and call this command again recursively if there
% are more digits to print. For use after the decimal sign.
%    \begin{macrocode}
\def\nprt@threeafter#1#2#3#4\@empty{%
%    \end{macrocode}
% Print the three digits.
%    \begin{macrocode}
  \nprt@printdigit#1%
  \nprt@printdigit#2%
  \nprt@printdigit#3%
%    \end{macrocode}
% Define a temporary variable containing the rest string for testing
% if there is a rest at all.
%    \begin{macrocode}
  \def\nprt@tmp{#4}%
  \ifx\nprt@tmp\empty
  \else
%    \end{macrocode}
% If there is a rest string insert the thousand separator \dots
%    \begin{macrocode}
    \nprt@thousandthpart%
%    \end{macrocode}
% \dots\ and call this command recursively.
% Append enough \verb|\@empty| statements to ensure that the command
% gets four arguments.
%    \begin{macrocode}
    \nprt@threeafter#4\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@two}
% Print two digits and call \verb|\nprt@three| if there
% are more digits to print. This command is maximally used once at the 
% beginning of the number when it contains 2, 5, 8, 11, \dots\ digits
% before the decimal sign. For a description have a look at
% \verb|\nprt@three|.
%    \begin{macrocode}
\def\nprt@two#1#2#3\@empty{%
  \nprt@printdigit#1%
  \nprt@printdigit#2%
  \def\nprt@tmp{#3}%
  \ifx\nprt@tmp\empty
  \else
    \nprt@thousand\nprt@three#3\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@one}
% Print one digit and call \verb|\nprt@three| if there
% are more digits to print. This command is maximally used once at the 
% beginning of the number when it contains 1, 4, 7, 10, \dots\ digits
% before the decimal sign. For a description watch \verb|\nprt@three|.
%    \begin{macrocode}
\def\nprt@one#1#2\@empty{%
  \nprt@printdigit#1%
  \def\nprt@tmp{#2}%
  \ifx\nprt@tmp\empty
  \else
%    \end{macrocode}
% Test if the first character was a sign. The thousand separator may
% only be printed if the first character is no sign.
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}%
%    \begin{macrocode}
    \def\nprt@tmp{#1}%
    \ifx\nprt@tmp\nprt@plus@test
    \else
      \ifx\nprt@tmp\nprt@minus@test
      \else
        \ifx\nprt@tmp\nprt@plusminus@test
        \else
          \nprt@thousand
        \fi
      \fi
    \fi
    \nprt@three#2\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% Define routines to test if a character is included in a string. If
% yes the command \verb|\nprt@tmp| returns a nonempty string. If the
% string does not contain the character \verb|\nprt@tmp| returns
% nothing. To achieve this functionality the commands have to be
% called in a special way. For example to test for a comma in a command
% \verb|\str| you have to write
% \verb|\nprt@commatest\str,\@empty|. So you always have to
% append the character you are searching for (e.g. \verb|,|) and
% \verb|\@empty| to your search string.
%    \begin{macrocode}
\def\nprt@exptest#1e#2\@empty{\gdef\nprt@tmp{#2}}
\def\nprt@Exptest#1E#2\@empty{\gdef\nprt@tmp{#2}}
\def\nprt@commatest#1,#2\@empty{\gdef\nprt@tmp{#2}}
\def\nprt@dottest#1.#2\@empty{\gdef\nprt@tmp{#2}}
%    \end{macrocode}
% \begin{macro}{\nprt@exp}
% Print number in the exponential format with an argument containing a 
% small ``e''. Call: \verb|\nprt@exp| number\verb|\@empty|,
% e.g. \verb|\nprt@exp 123.2e4,3\@empty|. Both numbers containing a comma or 
% a dot work.
%    \begin{macrocode}
\def\nprt@exp#1e#2\@empty{\expnumprint{#1}{#2}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@Exp}
% Print number in the exponential format with an argument containing a 
% capital ``E''. Call: \verb|\nprt@Exp| number\verb|\@empty|,
% e.g. \verb|\nprt@Exp 123.2E4,3\@empty|. Both numbers containing a comma or 
% a dot work.
%    \begin{macrocode}
\def\nprt@Exp#1E#2\@empty{\expnumprint{#1}{#2}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@comma}
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% Print a number without exponential part containing a comma. Call:
% \verb|\nprt@comma| number\verb|\@empty|, e.g. 
% \verb|\nprt@comma 123,2\@empty|.
%    \begin{macrocode}
\def\nprt@comma#1,#2\@empty{%
  \nprt@dotcomma{#1}{#2}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@dot}
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% Print a number without exponential part containing a comma. Call:
% \verb|\nprt@dot| number\verb|\@empty|, e.g.
% \verb|\nprt@dot 123.2\@empty|.
%    \begin{macrocode}
\def\nprt@dot#1.#2\@empty{%
  \nprt@dotcomma{#1}{#2}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@dotcomma}
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% \changes{0.30}{2003/05/19}{Add support for rounding}%
% Print a number without exponential part containing a dot or a comma. Call:
% \verb|\nprt@dotcomma{before}{after}|, e.g.\
% \verb|\nprt@dot{123}{2}|.
%    \begin{macrocode}
\def\nprt@dotcomma#1#2{%
  \begingroup
%    \end{macrocode}
% If \cs{nprt@dotcomma} is called for printing an exponent, copy the
% routines for exponents to the ordinary ones. This has to be done
% between \cs{begingroup} and \cs{endgroup} to preserve the normal
% settings.
%    \begin{macrocode}
  \ifnprt@exponent
    \edef\nprt@rounddigits{\nprt@roundexpdigits}%
    \edef\nprt@roundnull{\nprt@roundexpnull}%
  \fi
  \ifnum\nprt@rounddigits<0
%    \end{macrocode}
% If no rounding is done, just use the given arguments for printing.
%    \begin{macrocode}
    \def\nprt@charsbeforecomma{#1}%
    \def\nprt@charsaftercomma{#2}%
  \else
%    \end{macrocode}
% If rounding, do it.
% First, provide empty strings for the parts before and after the
% digit sign.
%    \begin{macrocode}
    \def\nprt@charsbeforecomma{}%
    \def\nprt@charsaftercomma{}%
%    \end{macrocode}
% Append enough zeros after the decimal sign that all digits are
% surely printed.
%    \begin{macrocode}
    \edef\zwei{#2\nprt@roundnull}%
%    \end{macrocode}
% Call the command \cs{nprt@roundaftercomma} that does the rounding
% for the part after the decimal sign.
%    \begin{macrocode}
    \expandafter\nprt@roundaftercomma\zwei\empty
%    \end{macrocode}
% If the first digit after the comma is rounded from 9 to 0, rounding
% has to be continued before the decimal sign by calling
% \cs{nprt@roundbeforecomma}.
%    \begin{macrocode}
    \if@@roundup
      \nprt@roundbeforecomma#1\empty
%    \end{macrocode}
% If the first digit has to be rounded from 9 to 0, a 1 has to be
% inserted before the number.
%    \begin{macrocode}
      \if@@roundup
        \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
          1\nprt@charsbeforecomma}%
      \fi
    \else
      \def\nprt@charsbeforecomma{#1}%
    \fi
  \fi
%    \end{macrocode}
% Count the digits after the comma.
%    \begin{macrocode}
  \nprt@@hassignfalse
  \expandafter\nprt@count\nprt@charsaftercomma\@empty\@empty\@empty
%    \end{macrocode}
% Copy the result which is stored in |nprt@digitsbeforedecimal| to
% |nprt@digitsafterdecimal|.
%    \begin{macrocode}
  \setcounter{nprt@digitsafterdecimal}{\thenprt@digitsbeforedecimal}%
%    \end{macrocode}
% Count the digits before the comma.
%    \begin{macrocode}
  \expandafter\nprt@hassign\nprt@charsbeforecomma\@empty\@empty
  \expandafter\nprt@count\nprt@charsbeforecomma\@empty\@empty\@empty
%    \end{macrocode}
% Typeset the digits before the comma.
%    \begin{macrocode}
  \ifnum\the\c@nprt@digitsbeforedecimal=0
    \@addmissingzero
  \else
    \expandafter\beforecomma\nprt@charsbeforecomma\@empty\@empty
  \fi
%    \end{macrocode}
% Typeset the part after the decimal sign, if necessary.
%    \begin{macrocode}
  \ifnum\nprt@rounddigits=0
  \else
%    \end{macrocode}
% Typeset the decimal sign.
%    \begin{macrocode}
    \nprt@decimal
%    \end{macrocode}
% Typeset the digits after the comma.
%    \begin{macrocode}
    \ifnum\the\c@nprt@digitsafterdecimal>0
      \aftercomma{\nprt@charsaftercomma}%
    \else
      \ifx\nprt@replacenull\@empty
        \@addmissingzero
      \else
        \nprt@replacenull
      \fi
    \fi
  \fi
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\expnumprint}
% Print number in the exponential format. This function is called by
% \verb|\nprt@exp| and \verb|\nprt@Exp|. It just calls
% \verb|\numprint| for the number itself, prints $\cdot 10$, and
% calls \verb|\numprint| for the exponent. It is distinguished between 
% text and math mode to ensure the usage of the right fonts.
% \changes{0.04}{2001/03/06}{Added support for pure $10^x$ format}%
%    \begin{macrocode}
\newcommand{\expnumprint}[2]{%
  \def\nprt@tmp{#1}%
  \ifx\nprt@tmp\@empty
    \nprt@exponenttrue
    \ifmmode
      10^{\numprint{#2}}%
    \else
      10\textsuperscript{\numprint{#2}}%
    \fi
  \else
    \ifmmode
      \numprint{#1}%
      \nprt@exponenttrue
      \nprt@prod 10^{\numprint{#2}}%
    \else
      \numprint{#1}%
      \nprt@exponenttrue
      \nprt@prod 10\textsuperscript{\numprint{#2}}%
    \fi
  \fi
  \nprt@exponentfalse
}
%    \end{macrocode}
% \end{macro}
% Define a macro that includes |\@empty|. This seems to be necesarry since
% the optional argument of |\numprint| is not expanded before printing it.
% \changes{0.22}{2003/02/27}{Bugfix with invalid spacing after the number}%
%    \begin{macrocode}
\def\nprt@empty{\@empty}%
%    \end{macrocode}
% \begin{macro}{\numprint}
% This is the main command of this package. It gets a number in the
% argument and prints it.
%    \begin{macrocode}
\DeclareRobustCommand*\numprint[2][\@empty]{%
%    \end{macrocode}
% \changes{0.32}{2003/09/28}{Reset the number of digits before and
%   after the decimal sign (Bugfix for nosepfour)}%
% Reset the number of digits before and after the decimal sign. 
% Without doing it, \texttt{nosepfour} is broken by one number with
% more than 4 digits.
%    \begin{macrocode}
  \setcounter{nprt@digitsafterdecimal}{0}%
  \setcounter{nprt@digitsbeforedecimal}{0}%
%    \end{macrocode}
% \changes{0.31}{2003/09/16}{Expand the mandatory argument of the
%   \cs{numprint} command before parsing it}%
% Expand argument first.
%    \begin{macrocode}
  \edef\nprt@marg{#2}%
%    \end{macrocode}
% Call \verb|\nprt@Exptest| to test the argument for an ``E''.
%    \begin{macrocode}
  \expandafter\nprt@Exptest\nprt@marg E\@empty
%    \end{macrocode}
% If the argument contains no ``E'' proceed here.
%    \begin{macrocode}
  \ifx\nprt@tmp\empty
%    \end{macrocode}
% Call \verb|\nprt@exptest| to test the argument for an ``e''.
%    \begin{macrocode}
    \expandafter\nprt@exptest\nprt@marg e\@empty
%    \end{macrocode}
% If the argument contains no ``e'' the argument contains a simple
% number. Then proceed here.
%    \begin{macrocode}
    \ifx\nprt@tmp\empty
%    \end{macrocode}
% Call \verb|\nprt@commatest| to test the argument for a ``,''.
%    \begin{macrocode}
      \expandafter\nprt@commatest\nprt@marg,\@empty
%    \end{macrocode}
% If the argument contains no ``,'' proceed here.
%    \begin{macrocode}
      \ifx\nprt@tmp\empty
%    \end{macrocode}
% Call \verb|\nprt@commatest| to test the argument for a ``.''.
%    \begin{macrocode}
        \expandafter\nprt@dottest\nprt@marg.\@empty
%    \end{macrocode}
% If the argument contains no ``.'' the number has no decimal
% places. Then proceed here.
%    \begin{macrocode}
        \ifx\nprt@tmp\empty
%    \end{macrocode}
% Count the digits of the integer number.
%    \begin{macrocode}
          \expandafter\nprt@hassign\nprt@marg\@empty
          \expandafter\nprt@count\nprt@marg\@empty\@empty\@empty
%    \end{macrocode}
% Print the number.
%    \begin{macrocode}
          \begingroup
%    \end{macrocode}
% If \cs{nprt@dotcomma} is called for printing an exponent, copy the
% routines for exponents to the ordinary ones. This has to be done
% between \cs{begingroup} and \cs{endgroup} to preserve the normal
% settings.
%    \begin{macrocode}
          \ifnprt@exponent
            \def\nprt@rounddigits{\nprt@roundexpdigits}%
            \def\nprt@roundnull{\nprt@roundexpnull}%
          \fi
%    \end{macrocode}
% If rounding is switched on with at least on digit, the part
% after the decimal sign has to be printed.
% Set the number of digits, then.
%    \begin{macrocode}
          \ifnum\nprt@rounddigits>0
            \setcounter{nprt@digitsafterdecimal}{\nprt@rounddigits}%
          \fi
%    \end{macrocode}
% Print the integer part.
%    \begin{macrocode}
          \expandafter\beforecomma\nprt@marg\@empty\@empty
%    \end{macrocode}
% Print the part after the decimal sign.
%    \begin{macrocode}
          \ifnum\nprt@rounddigits>0
            \nprt@decimal
            \aftercomma{\nprt@roundnull}%
          \fi
          \endgroup
%    \end{macrocode}
% If the argument contains a ``.'' proceed here.
% Call \verb|\nprt@dot| to print the whole number.
%    \begin{macrocode}
        \else
          \expandafter\nprt@dot\nprt@marg\@empty
        \fi
%    \end{macrocode}
% If the argument contains a ``,'' proceed here.
% Call \verb|\nprt@comma| to print the whole number.
%    \begin{macrocode}
      \else
        \expandafter\nprt@comma\nprt@marg\@empty
      \fi
%    \end{macrocode}
% If the argument contains a ``e'' proceed here.
% Call \verb|\nprt@exp| to print the whole number.
%    \begin{macrocode}
    \else
      \expandafter\nprt@exp\nprt@marg\@empty
    \fi
%    \end{macrocode}
% If the argument contains a ``E'' proceed here.
% Call \verb|\nprt@Exp| to print the whole number.
%    \begin{macrocode}
  \else
    \expandafter\nprt@Exp\nprt@marg\@empty
  \fi
%    \end{macrocode}
% \changes{0.02}{2000/08/30}{Added optional argument for units}%
% \changes{0.03}{2001/02/10}{Fixed bug with units}%
% \changes{0.20}{2003/02/24}{Fixed bug which made units fragile}%
% \changes{0.22}{2003/02/27}{Bugfix with invalid spacing after the number}%
% Handle optional argument and print the unit only when specified.
%    \begin{macrocode}
  \def\nprt@unit{#1}%
  \ifx\nprt@unit\nprt@empty
  \else
    \ensuremath{\nprt@unitsep\mathrm{\nprt@unit}}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Counters for counting digits: \verb|nprt@countblocks| counts number
% of blocks before the decimal sign. \verb|nprt@digitsfirstblock|
% counts the digits in the first block (0 to 2).
% \verb|nprt@digitsbeforedecimal| counts the total number of
% digits before the decimal sign.
%    \begin{macrocode}
\newcounter{nprt@countblocksbefore}%
\newcounter{nprt@digitsfirstblock}%
\newcounter{nprt@digitsafterdecimal}%
\newcounter{nprt@digitsbeforedecimal}%
%    \end{macrocode}
% \begin{macro}{nprt@hassign}
% Tests weather the first character of a string is not a digit.
%    \begin{macrocode}
\newif\ifnprt@@hassign
\def\nprt@hassign#1#2\@empty{%
  \ifnum-9>-1#1
    \nprt@@hassignfalse
  \else
    \nprt@@hassigntrue
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@count}
% Count the number of digits of the argument. This is done recursively 
% by taking one character of the string and counting the runs of this
% command. Every three digits the counter is resetted to zero because
% only the modulus (Rest??) of the number of digits devided by 3 is
% important.
%
% If the optional parameter contains anything other than
% \verb|\@empty| the number of digits after the comma is counted.
%    \begin{macrocode}
\def\nprt@count#1#2\@empty{%
  \setcounter{nprt@digitsbeforedecimal}{0}%
  \edef\nprt@arg{#1}%
%    \end{macrocode}
% Handle an empty argument.
%    \begin{macrocode}
  \ifx\nprt@arg\@empty
  \else
%    \end{macrocode}
% Count the digits.
%    \begin{macrocode}
    \ifnprt@@hassign
      \nprt@@count#2\@empty\@empty
    \else
      \nprt@@count#1#2\@empty\@empty
    \fi
  \fi
%    \end{macrocode}
%    \begin{macrocode}
  \setcounter{nprt@countblocksbefore}{\arabic{nprt@digitsbeforedecimal}/3}%
  \setcounter{nprt@digitsfirstblock}{%
    \arabic{nprt@digitsbeforedecimal}-3*\arabic{nprt@countblocksbefore}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@@count}
% \changes{0.32}{2003/09/28}{Only one error message per \cs{numprint}}%
% Do the counting itself.
%    \begin{macrocode}
\def\nprt@@count#1#2\@empty{%
  \ifnum-9>-1#1
    \addtocounter{nprt@digitsbeforedecimal}{1}%
    \def\nprt@tmp{#2}%
    \ifx\nprt@tmp\empty
    \else
      \nprt@@count#2\@empty\@empty
    \fi
  \else
    \PackageError{numprint}{Incorrect number format in
      \string\numprint}{%
      The main argument of the \string\numprint\space command may only
      be started\MessageBreak
      with \string"+\string", \string"-\string", or
      \string"\string\pm\string" and then contain of\MessageBreak
      digits \string"0\string" to \string"9\string",
      \string",\string", \string".\string", \string"e\string", and 
      \string"E\string".}%
%    \setcounter{nprt@digitsbeforedecimal}{-1}%
  \fi
%    \end{macrocode}
% Count number of characters
%    \begin{macrocode}
}
%    \end{macrocode}
% \end{macro}
% Print the digits before the decimal sign. Depending on the number of 
% digits either \verb|\nprt@one|, \verb|\nprt@two|, or
% \verb|\nprt@three| is called.
%    \begin{macrocode}
\newlength{\nprt@digitwidth}%
\newlength{\nprt@sepwidth}%
\newcounter{nprt@digitcount}%
\newcounter{nprt@sepcount}%
\newlength{\nprt@blockwidth}%
%    \end{macrocode}
% \begin{macro}{beforecomma}
% Prints the number before the decimal sign.
%    \begin{macrocode}
\def\beforecomma#1#2\@empty{%
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% If the number should be printed aligned generate a block with the
% correct size.
%    \begin{macrocode}
  \ifnprt@block
    \ifnprt@exponent
    \else
      \settowidth{\nprt@digitwidth}{1}%
      \settowidth{\nprt@sepwidth}{\nprt@thousand}%
      \setcounter{nprt@digitcount}{\nprt@blockbefore}%
      \setcounter{nprt@sepcount}{(\nprt@blockbefore-1)/3}%
      \setlength{\nprt@blockwidth}{%
        \arabic{nprt@digitcount}\nprt@digitwidth+%
        \arabic{nprt@sepcount}\nprt@sepwidth}%
%    \end{macrocode}
% If block length is four digits and fourth digit is not to be
% separated adjust new width.
%    \begin{macrocode}
      \if@numsepfour
      \else
        \ifnum\nprt@blockbefore=4
          \ifnum\nprt@blockafter<5
            \setlength{\nprt@blockwidth}{4\nprt@digitwidth}%
          \fi
        \fi
      \fi
%    \end{macrocode}
% If math mode switch to math mode again after invoking box.
%    \begin{macrocode}
      \ifmmode\nprt@inmathtrue\fi
      \makebox[\nprt@blockwidth][r]{%
      \ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs)
    \fi
  \fi
  \ifnprt@blockexp
    \ifnprt@exponent
      \settowidth{\nprt@digitwidth}{1}%
      \settowidth{\nprt@sepwidth}{\nprt@thousand}%
      \setcounter{nprt@digitcount}{\nprt@blockexpbefore}%
      \setcounter{nprt@sepcount}{(\nprt@blockexpbefore-1)/3}%
      \setlength{\nprt@blockwidth}{%
        \arabic{nprt@digitcount}\nprt@digitwidth+%
        \arabic{nprt@sepcount}\nprt@sepwidth}%
%    \end{macrocode}
% If block length is four digits and fourth digit is not to be
% separated adjust new width.
%    \begin{macrocode}
      \if@numsepfour
      \else
        \ifnum\nprt@blockexpbefore=4
          \setlength{\nprt@blockwidth}{4\nprt@digitwidth}%
        \fi
      \fi
      \ifmmode\nprt@inmathtrue\fi
      \makebox[\nprt@blockwidth][r]{%
%    \end{macrocode}
% asdf
% To do: correct font size (normalstyle, scriptstyle, scriptscriptstyle)
%    \begin{macrocode}
      \ifnprt@inmath$\scriptstyle\fi %$ (only for syntax highlighing in emacs)
    \fi
  \fi
%    \end{macrocode}
% \changes{0.31}{2003/09/16}{Bug Fix: With four-digit numbers, print
%   everything instead of first digit only}%
% Print the number itself.
%    \begin{macrocode}
  \ifnprt@@hassign
    \nprt@printdigit{#1}%
    \edef\nprt@tmp{#2}%
  \else
    \edef\nprt@tmp{#1#2}%
  \fi
  \ifnum\thenprt@digitsfirstblock=1
    \ifnum\thenprt@digitsbeforedecimal=4
      \if@numsepfour
        \expandafter\nprt@one\nprt@tmp\@empty\@empty\@empty
      \else
        \ifnum\thenprt@digitsafterdecimal<5
          \nprt@tmp\ignorespaces
        \else
          \expandafter\nprt@one\nprt@tmp\@empty\@empty\@empty
        \fi
      \fi
    \else
      \expandafter\nprt@one\nprt@tmp\@empty\@empty\@empty
    \fi
  \fi
  \ifnum\thenprt@digitsfirstblock=2
    \expandafter\nprt@two\nprt@tmp\@empty\@empty\@empty
  \fi
  \ifnum\thenprt@digitsfirstblock=0
    \expandafter\nprt@three\nprt@tmp\@empty\@empty\@empty\@empty
  \fi
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Close the block if necessary.
%    \begin{macrocode}
  \ifnprt@blockexp
    \ifnprt@exponent
      \ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs)
      }%
    \fi
  \fi
  \ifnprt@block
    \ifnprt@exponent
    \else
      \ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs)
      }%
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{aftercomma}
% Print the digits after the decimal sign.
%    \begin{macrocode}
\newcommand{\aftercomma}[1]{%
%    \end{macrocode}
% Count number of digits.
%    \begin{macrocode}
%  \expandafter\nprt@count\expandafter{#1}%
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% If the number should be printed aligned generate a block with the
% correct size.
%    \begin{macrocode}
  \ifnprt@block
    \ifnprt@exponent
    \else
      \settowidth{\nprt@digitwidth}{1}%
      \settowidth{\nprt@sepwidth}{\nprt@thousand}%
      \setcounter{nprt@digitcount}{\nprt@blockafter}%
      \setcounter{nprt@sepcount}{(\nprt@blockafter-1)/3}%
      \setlength{\nprt@blockwidth}{%
        \arabic{nprt@digitcount}\nprt@digitwidth+%
        \arabic{nprt@sepcount}\nprt@sepwidth}%
%    \end{macrocode}
% If block length is four digits and fourth digit is not to be
% separated adjust new width.
%    \begin{macrocode}
      \if@numsepfour
      \else
        \ifnum\nprt@blockafter=4
          \ifnum\nprt@blockbefore<5
            \setlength{\nprt@blockwidth}{4\nprt@digitwidth}%
          \fi
        \fi
      \fi
      \ifmmode\nprt@inmathtrue\fi
      \makebox[\nprt@blockwidth][l]{%
      \ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs)
    \fi
  \fi
%    \end{macrocode}
% If a zero after the decimal sign is replaced, don't test on 4 digits
% after comma.
% Therefor, set |nprt@digitsafterdecimalsign| to zero.
%    \begin{macrocode}
  \ifx\nprt@replacenull\@empty
  \else
    \ifnum#1=0
      \setcounter{nprt@digitsafterdecimal}{0}%
    \fi
  \fi
%    \end{macrocode}
% Print the number itself.
%    \begin{macrocode}
  \ifnum\thenprt@digitsafterdecimal=4
    \if@numsepfour
      \expandafter\nprt@threeafter#1\@empty\@empty\@empty
    \else
      \ifnum\thenprt@digitsbeforedecimal<5
        #1\ignorespaces
      \else
        \expandafter\nprt@threeafter#1\@empty\@empty\@empty
      \fi
    \fi
  \else
%    \end{macrocode}
% Replace the zero after the comma by \cs{nprt@replacenull} if this is
% wanted.
% Otherwise, print the digits.
%    \begin{macrocode}
    \ifx\nprt@replacenull\@empty
      \expandafter\nprt@threeafter#1\@empty\@empty\@empty
    \else
      \ifnum#1=0
        \nprt@replacenull
      \else
        \expandafter\nprt@threeafter#1\@empty\@empty\@empty
      \fi
    \fi
  \fi
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Close the block if necessary.
%    \begin{macrocode}
  \ifnprt@block
    \ifnprt@exponent
    \else
      \ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs)
      }%
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
% New counter which shows the digit position for finding the digit
% where to round.
%    \begin{macrocode}
\newcounter{nprt@position}
%    \end{macrocode}
% Boolean that shows if a 9 has been rounded to 0.
%    \begin{macrocode}
\newif\if@@roundup
%    \end{macrocode}
% Current digit to be able to add 1 to it.
%    \begin{macrocode}
\newcounter{nprt@thisdigit}
%    \end{macrocode}
% \begin{macro}{\nprt@roundaftercomma}
% Command that rounds at the argument |#1#2| at the digit
% \cs{nprt@rounddigits}.
% This routine calls itself recursively.
%    \begin{macrocode}
\def\nprt@roundaftercomma#1#2\empty{%
  \addtocounter{nprt@position}{1}%
  \edef\zwei{#2}%
  \ifx\zwei\empty
  \else
    \expandafter\ifnum\thenprt@position<\nprt@rounddigits
      \nprt@roundaftercomma#2\empty
    \else
      \nprt@roundup#2\empty
    \fi
  \fi
  \setcounter{nprt@thisdigit}{#1}%
  \if@@roundup
    \addtocounter{nprt@thisdigit}{1}%
    \ifnum\thenprt@thisdigit>9
      \@@rounduptrue
      \setcounter{nprt@thisdigit}{0}%
    \else
      \@@roundupfalse
    \fi
  \fi
  \expandafter\xdef\expandafter\nprt@charsaftercomma{%
    \thenprt@thisdigit\nprt@charsaftercomma}%
  \addtocounter{nprt@position}{-1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@roundup}
%    \begin{macrocode}
\def\nprt@roundup#1#2\empty{%
  \ifnum#1>4
    \@@rounduptrue
  \else
    \@@roundupfalse
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@roundbeforecomma}
%    \begin{macrocode}
\def\nprt@roundbeforecomma#1#2\empty{%
  \edef\zwei{#2}%
  \ifx\zwei\empty
  \else
    \nprt@roundbeforecomma#2\empty
  \fi
  \edef\eins{#1}%
%  \ifx\eins\nprt@minus@test
%    \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
%      #1\nprt@charsbeforecomma}%
%  \else
%    \setcounter{nprt@thisdigit}{#1}%
%    \if@@roundup
%      \addtocounter{nprt@thisdigit}{1}%
%      \ifnum\thenprt@thisdigit>9
%        \@@rounduptrue
%        \setcounter{nprt@thisdigit}{0}%
%      \else
%        \@@roundupfalse
%      \fi
%    \fi
  \ifnum-9>-1#1
    \setcounter{nprt@thisdigit}{#1}%
    \if@@roundup
      \addtocounter{nprt@thisdigit}{1}%
      \ifnum\thenprt@thisdigit>9
        \@@rounduptrue
        \setcounter{nprt@thisdigit}{0}%
      \else
        \@@roundupfalse
      \fi
    \fi
    \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
      \thenprt@thisdigit\nprt@charsbeforecomma}%
  \else
    \if@@roundup
      \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
        1\nprt@charsbeforecomma}%
      \@@roundupfalse
    \fi
    \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
      #1\nprt@charsbeforecomma}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% Define two new column types.
%
% The column type \verb|n| aligns the base number but not the exponent.
%    \begin{macrocode}
\newcolumntype{n}[2]{>{\digits{#1}{#2}$}l<{$\nodigits}}
%    \end{macrocode}
% Define two new column types.
%
% The column type \verb|n| aligns the base number as well as the exponent.
%    \begin{macrocode}
\newcolumntype{N}[3]{%
  >{\digits{#1}{#2}\exponentdigits{#3}$}l<{$\nodigits\noexponentdigits}}
%    \end{macrocode}
% \iffalse
%</package>
% \fi
% \Finale