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
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
|
% \iffalse meta comment
% File: numprint.dtx Copyright (C) 2000--2005, 2007, 2008 Harald Harders
% \fi
%
% \iffalse
%
%<*driver>
\listfiles
\documentclass[ngerman,english,a4paper]{ltxdoc}
\usepackage[T1]{fontenc}
\IfFileExists{numprint.sty}{%
\usepackage[warning,debug,autolanguage,boldmath,np]{numprint}
}{%
\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
}
\IfFileExists{eco.sty}{%
\usepackage{eco}
\renewcommand*\ttdefault{cmtt}
}{%
\GenericWarning{numprint.dtx}{Package file eco.sty not found
(Documentation will be less clear than possible)}
}
\usepackage{longtable}
\usepackage{mathcomp}
\usepackage{babel}
\usepackage{url}
\usepackage{color}
\IfFileExists{booktabs.sty}{\usepackage{booktabs}}{%
\GenericWarning{numprint.dtx}{Package file booktabs.sty not
found. Documentation formatting will be poor}%
\def\toprule\hline
\def\midrule\hline
\def\bottomrule\hline}
\GlossaryPrologue{\section*{{Change History}}%
\markboth{{Change History}}{{Change History}}%
Since the version~1.00 is an entirely new implementation, the Change
History prior version~1.00 has been lost in this document. Have a
look to \texttt{numprint032.dtx} or \texttt{README} to get it.
}
\GetFileInfo{numprint.sty}
\title{The numprint package}
\author{Harald Harders\\\texttt{h.harders@tu-bs.de}}
\date{Version \fileversion, \filedate; printed \today}
\npdecimalsign{.}%
\newlength{\tempdima}%
\makeatletter
\renewenvironment{table}[1][]{%
\@float{table}[#1]%
\centering%
\setlength{\tempdima}{\abovecaptionskip}%
\setlength{\abovecaptionskip}{\belowcaptionskip}%
\setlength{\belowcaptionskip}{\tempdima}%
}{%
\end@float
}
\def\meta@font@select{\normalfont\itshape}
\makeatother
%%
\EnableCrossrefs
\CodelineIndex
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
\DoNotIndex{\setcounter,\space,\if,\else,\fi,\empty,\@empty,\ifx,\fi}
\DoNotIndex{\ifnum,\fi,\expandafter,\csname,\endcsname,\the}
\DoNotIndex{\MessageBreak,\message,\newlength,\newif,\xdef,\newcount}
\DoNotIndex{\begingroup,\endgroup,\,,\@tempcnta,\@tempdima,\advance}
\DoNotIndex{\ensuremath,\filedate,\fileversion,\docdate}
\DoNotIndex{\mathit,\mathrm,\mathsf,\nprt@tmp,\nprt@tmpnum,\relax}
\DoNotIndex{\protect,\renewcommand,\setlength,\settowidth,\stepcounter}
\DoNotIndex{\string}
\CodelineNumbered
\RecordChanges
\CheckSum{2257}
\begin{document}
\DocInput{numprint.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{1.38}{2008/02/17}{Replaced \cs{stepcounter} and
% \cs{addtocounter} by \cs{advance}
% because otherwhise, \cs{numprint} does not work inside
% \cs{ensuremath}\{\cs{text}\{\$\ldots\$\}\}.}%
% \changes{1.38}{2008/02/17}{Moved counters \cs{nprt@curpos} and
% \cs{nprt@rndpos} outside the macro definitions to avoid an overflow
% of counters}%
% \changes{1.37}{2007/01/08}{Add support for French}%
% \changes{1.37}{2007/01/08}{Add an own separator for \textcelsius}%
% \changes{1.37}{2007/01/08}{Use separator for percent also for permil}%
% \changes{1.36}{2005/07/12}{Add support for Dutch}%
% \changes{1.36}{2005/07/12}{Improve documentation}%
% \changes{1.35}{2005/07/11}{Support not to separate percent sign from
% number}%
% \changes{1.30}{2004/08/11}{Add the commands \cs{lenprint} and
% \cs{cntprint} that print lengths and counters.}%
% \changes{1.22}{2004/08/08}{Use \cs{npunitcommand} to typeset units}%
% \changes{1.21}{2004/08/01}{Add support for Portuguese}%
% \changes{1.20}{2004/07/27}{Remove the reduction in font sizes in
% documentation}%
% \changes{1.20}{2004/07/27}{Allow \cs{numprint\{-e5\}} in addition to
% \cs{numprint\{e5\}}}%
% \changes{1.20}{2004/07/27}{Add padding a number on the left side}%
% \changes{1.13}{2004/04/01}{Small fix in documentation}%
% \changes{1.12}{2004/02/12}{Adapt Makefile to \TeX Live}%
% \changes{1.11}{2003/11/09}{Avoid use of \cs{fileversion} etc.}%
% \changes{1.00}{2003/10/07}{Total new implementation}%
%
% \maketitle
% \begin{abstract}
% \noindent
% This package prints numbers with a separator every three digits and
% convert numbers given as |12345.6e789| to
% {\npstylegerman\numprint{12345,6e789}}.
% Numbers are printed in the current mode (text or math) in order to use
% the correct font.
%
% Many things, including the decimal sign, the thousand separator, as
% well as the product sign can be changed by the user, e.g., to reach
% \numprint{12,345.6e789}.
% If requested, numprint can round numbers to a given number of digits.
%
% If an optional argument is given it is printed upright as unit.
% Numbers can be rounded to a given number of digits.
%
% The package supports an automatic, language-dependent change of the
% number format.
%
% Tabular alignment using the |tabular|(|*|), |array|, |tabularx|, and
% |longtable| environments (similar to the |dcolumn| and |rccol| packages)
% is supported using all features of numprint. Additional text can be
% added before and after the formatted number.
%
% If you want to print numbers with different bases (octal,
% hexadecimal, etc.) use the |nbaseprt| package which comes with the
% |numprint| package.
% \end{abstract}
%
% \tableofcontents
%
% \section*{Copyright}
% Copyright 2000--2005, 2007, 2008 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*{Remarks}
%
% \begingroup
% \itshape
% \sloppypar
% The \cs{fourdigitsep}, \cs{fourdigitnosep},
% \cs{addmissingzero}, \cs{noaddmissingzero}, \cs{digits},
% \marginpar{\raggedleft\bfseries\Huge !}%
% \cs{nodigits}, \cs{exponentsdigits}, and \cs{noexponentdigits}
% commands have been renamed to \cs{npfourdigitsep},
% \cs{npfourdigitnosep}, \cs{npaddmissingzero},
% \cs{npnoaddmissingzero}, \cs{npdigits}, \cs{npnodigits},
% \cs{npexponentsdigits}, resp.\ \cs{npnoexponentdigits}.
%
% From version 1.00 to 1.10, the column types have been changed; see
% section~\ref{sec:tabular}.
% \marginpar{\raggedleft\bfseries\Huge !}%
% If you want to preserve the old column types, use the package option
% |oldcolumntypes|.
% \endgroup
%
% For typesetting this documentation, the usage of different font
% shapes has been reduced as much as possible in order to save disk
% memory and download times.
% Thus, for nearly all characters, the design size 10\,pt has been
% used.
% This reduced the size of the PDF file for version 1.10 from 858\,KB
% to 396\,KB.
% Please excuse that shortcoming in the typography.
%
%
% \section{Load the package}
%
% To use this package place
% \begin{verbatim}
%\usepackage{numprint}\end{verbatim}
% in the preamble of your document.
% No options are necessary but some are available.
% They are mentioned where their usage is described and in
% section~\ref{sec:package-options}.
%
% \section{Print numbers in text and math mode}
%
% \DescribeMacro{\numprint}%
% This package provides the command
% \cs{numprint\oarg{unit}\marg{number}} that prints the \meta{number}
% given in the required argument.
% The number is printed in the current mode (math or text mode) 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.,eEdD|''.
% Spaces, ``\cs{,}'' as well as ``\texttt{\~}'' in the argument are
% ignored.
% Either a ``|,|'' or a ''|.|'' can be used as decimal sign.
% By default, no thousand separators are allowed in the
% argument.\footnote{Section~\ref{sec:custom-parsing} describes how
% this can be changed.}
% ``|E|'', ``|e|'', ``|D|'', or ``|d|''\footnote{This is useful for
% FORTRAN produced numbers.} is converted to an exponential format
% (e.g., $x\cdot 10^{y}$ or $x\times 10^{y}$, depending on the
% format settings described later).
% ``|\pm|'' and ``|+-|'' produce a $\pm$.
%
% For example, typing
% \begin{verbatim}
%\numprint{-123456}; \numprint{\pm 123456}; \numprint{+-3,1415927e-3.1}\end{verbatim}
% leads to ``\numprint{-123456}; \numprint{\pm 123456};
% \numprint{+-3,1415927e-3.1}''.
% Notice that ``|.|'' and ``|,|'' can be mixed within one number and
% are converted to the chosen decimal sign for the output.
%
% The number is printed in the active mode (text mode resp.\ math
% mode).
% This may be important if the digits are different in text and math
% mode as in this document that uses old-style figures in text and
% lining figures in math mode.\footnote{This is only the case if the
% \texttt{eco} package is available on your system.}
% See the difference between
% ``\numprint{123456.134e123}'' and ``$\numprint{123456.134e123}$'',
% produced by
% \begin{verbatim}
%``\numprint{123456.134e123}'' and ``$\numprint{123456.134e123}$''\end{verbatim}
%
% If no number is given before the exponential characters ``|e|'',
% ``|E|'', ``|d|'', resp.\ ``|D|'', a pure exponential format is
% generated.
% For example, typing
% \begin{verbatim}
%\numprint{e4.3242}\end{verbatim}
% leads to ``\numprint{e4.3242}''.
% This also works with given signs, e.g.,
% \begin{verbatim}
%\numprint{-e4.3242}, \numprint{+-e4.3242} \end{verbatim}
% leads to ``\numprint{-e4.3242}, \numprint{+-e4.3242}''.
%
% Since \cs{numprint} expands the argument before typesetting it you
% may also use commands inside the argument, e.g.,
% \begin{verbatim}
%\def\numberbefore{1234}%
%\def\totalnumber{\numberbefore.5678}%
%\numprint{\totalnumber}\end{verbatim}
% leads to
% ``{\def\numberbefore{1234}\def\totalnumber
% {\numberbefore.5678}\numprint{\totalnumber}}''.
%
% If the optional argument is given it is printed as a \meta{unit} in
% math mode with an upright font (\verb|\mathrm|), e.g.,
% \begin{verbatim}
%\numprint[N/mm^2]{-123456}\end{verbatim}
% leads to ``\numprint[N/mm^2]{-123456}''.
%
% \changes{1.00}{2003/10/07}{Automatically don't separate degree sign
% from number}%
% By default, the space between the number and the unit is \cs{,}.
% One exception is the degree symbol which is typeset without a
% distance to the number, e.g., $\numprint[\tcdegree]{360}$ in
% contrast to $\numprint[\tccelsius]{273,15}$ (only a single degree
% symbol is typeset without a separator).
% The |numprint| package detects this automatically if the
% \cs{tcdegree} command of the |mathcomp| package, the \cs{textdegree}
% command of the |textcomp| package, or the \cs{degree} command of the
% |gensymb| package is used, e.g.,
% \begin{verbatim}
%\numprint[\tcdegree]{360}, \numprint[\degree]{360}\end{verbatim}
% Unfortunately, typing in the ``\texttt{\textdegree}'' sign directly
% cannot be detected (any help welcome).
%
% You can change the spacing between the number and units, percent
% signs, or degree symbols.
% Have a look to Section~\ref{sec:changing-output}.
%
%
% \changes{1.32}{2004/09/13}{Improve documentation about
% \texttt{textcomp} symbols}%
% If you want to use one of the |textcomp| symbols \textcelsius\
% (\cs{textcelsius}), \textohm\ (\cs{textohm}), \textmu\
% (\cs{textmu}), or \textperthousand\ (\cs{textperthousand})\ you have
% to load either the |mathcomp| or the |gensymb| package because the
% unit is printed in math mode.
% If you decide to use the |textomp| package use \cs{tc\meta{name}}
% instead of \cs{text\meta{name}}, e.g., \cs{tccelsius} instead of
% \cs{textcelsius}.
% If using |gensymb| just use \cs{\meta{name}}, e.g.,
% \cs{celsius}.\footnote{If you still use \cs{text\meta{name}}
% numprint uses \cs{tc\meta{name}} or \cs{\meta{name}} and generates a
% warning if one of these commands is available, and produces an error
% if not.}
%
%
% \DescribeMacro{\np}
% Since it is timeconsuming to type in the long command \cs{numprint}
% for every number in a text the shortcut \cs{np} can be defined by
% specifying the package option~\texttt{np}.
%
% By default, numbers are written in the format
% \begingroup
% \npstyledefault
% \numprint{12345,12345e12345},
% \endgroup
% for instance.
% This means, decimal sign ``\texttt{,}'', thousand
% separator ``\cs{,}'', and product sign
% ``\texttt{\{\}\cs{cdot}\{\}}''.
% This accords to German number formats and is a result of the history
% of this package.
% How you can change this is described in the following sections.
% Especially, have a look at the |autolanguage| package option in
% section~\ref{sec:international}.
%
%
% \subsection{Print counters and lengths}
%
% If you want to print a counter or a length, you may of course use
% \begin{verbatim}
%\numprint{\arabic{page}}\end{verbatim}
% resp.
% \begin{verbatim}
%\makeatletter
%\numprint[pt]{\strip@pt\textwidth}
%\makeatother\end{verbatim}
% But these methods are not really nice.
%
% \DescribeMacro{\cntprint}%
% For printing counters, you may use
% \cs{cntprint\oarg{unit}\marg{counter}} where \meta{unit} is an
% optional unit that is printed as by \cs{numprint}.
% \meta{counter} is the name of a \LaTeX\ counter, for example,
% \begin{verbatim}
%$\cntprint{page}$\end{verbatim}
% leads to ``$\cntprint{page}$''.
%
% \DescribeMacro{\lenprint}%
% Lengths can be printed using \cs{lenprint\oarg{unit}\marg{length}}.
% \meta{length} is the macro containing a \LaTeX\ length or a \TeX\
% dimension, e.g., \cs{textwidth}.
% \meta{unit} is a different thing here.
% If the unit is not given \cs{lenprint} uses \LaTeX's standard and
% prints the length in |pt|:
% \begin{verbatim}
%$\lenprint{\textwidth}$\end{verbatim}
% leads to ``$\lenprint{\textwidth}$''.
% Giving |pt| does not change anything.
% But if you use other units, e.g., |mm|, |cm|, or |in|, the length is
% written using the given unit:
% \begin{verbatim}
%$\lenprint[pt]{\textwidth}$,
%$\lenprint[in]{\textwidth}$,
%$\lenprint[bp]{\textwidth}$,
%$\lenprint[mm]{\textwidth}$,
%$\lenprint[cm]{3\textwidth}$\end{verbatim}
% gives ``$\lenprint[pt]{\textwidth}$,
% $\lenprint[in]{\textwidth}$,
% $\lenprint[bp]{\textwidth}$,
% $\lenprint[mm]{\textwidth}$,
% $\lenprint[cm]{3\textwidth}$''.
%
% As you can see in the example, it is also possible to specify a
% factor in the argument, e.g. |3\textwidth|.
% When printing lengths, it is often desirable not to print all
% decimal places.
% |numprint| can round numbers, described in section~\ref{sec:round}.
%
% \cs{lenprint} knows the units |pt|, |bp|, |in|, |ft|, |mm|, |cm|,
% |m|, and |km|.
% Section~\ref{sec:more-units} describes how to add or change units.
%
%
% \section{Customization}
%
% \subsection{Eliminate separators for four-digit numbers}
%
% At least in German it is common not to add a separator to four-digit
% numbers in non-technical texts, e.g., to typeset
% {\npfourdigitnosep``\numprint{1234}''} instead of ``\numprint{1234}'',
% but longer numbers are separated: ``\numprint{12345}''.
% If a number, in contrast, has less than five digits on one side of
% the decimal sign but five or more digits on the other side,
% separators are inserted on both sides, e.g.,
% {\npfourdigitnosep``\numprint{1234,1234}'' but
% ``\numprint{1234,12345}''}.
%
% \DescribeMacro{\npfourdigitsep}%
% \DescribeMacro{\npfourdigitnosep}%
% This behaviour can be achieved using the command
% \cs{npfourdigitnosep}.
% If using this switch inside a group the change is local.
% You can switch back to separating with \cs{npfourdigitsep}.
% An example:
% \begin{verbatim}
%\npfourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
%\npfourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$\end{verbatim}
% Leads to
% {``\npfourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
% \npfourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$''.}
% Default values can be set by the package options |sepfour| and
% |nosepfour|.
%
%
% \subsection{Add missing zeros before or after decimal sign}
%
% \DescribeMacro{\npaddmissingzero}%
% \DescribeMacro{\npnoaddmissingzero}%
% 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 \cs{addmissingzero} is
% used.
% If, however, no decimal sign is given, e.g., ``|123|'', no decimal
% sign or zero is appended.
% Adding zeros can be switched off with \cs{noaddmissingzero}.
% The corresponding package options are |addmissingzero| and
% |noaddmissinzero|.
% The default is |addmissingzero|.
%
%
% \subsection{Add a plus sign}%
% \changes{1.00}{2003/10/07}{Support for adding a plus to a number}%
%
% \DescribeMacro{\npaddplus}%
% \DescribeMacro{\npnoaddplus}%
% Using the \cs{npaddplus} command or the package option |addplus|, a
% plus sign can be added to a number that is specified without a
% sign.
% This can be switched off using \cs{npnoaddplus} resp.\ |noaddplus|.
%
% \DescribeMacro{\npaddplusexponent}%
% \DescribeMacro{\npnoaddplusexponent}%
% The commands \cs{npaddplusexponent} and \cs{npnoaddplusexponent}
% resp.\ the package options |addplusexponent| and |noaddplusexponent|
% do the same for the exponents that the commands/options described
% above do for the number.
%
%
% \subsection{Rounding numbers}%
% \label{sec:round}%
%
% \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 on using the
% \cs{nprounddigits\marg{digits}} command for ordinary
% numbers and the \cs{nproundexpdigits\marg{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}$''
%
%
% \subsection{Padding a number on the left side}%
%
% \DescribeMacro{\nplpadding}%
% \DescribeMacro{\npnolpadding}%
% Sometimes it is desireable to have a number of a fixed length with
% the missing digits filled with a character (mostly the character
% ``0'', so this is the default).
% This can be achieved calling
% \cs{nplpadding\oarg{character}\marg{digits}}.
% This affects only the mantissa, the part after the decimal sign and
% signs are not counted!
% If the orginal number has more digits than \meta{digits} no
% characters will be inserted.
% For example,
% \begin{verbatim}
%\nplpadding{6}%
%$\numprint{1234}$, $\numprint{-1234}$,
%$\numprint{12345678}$, $\numprint{1234.5678}$ --
%\nplpadding[x]{6}%
%$\numprint{1234}$, $\numprint{-1234}$,
%$\numprint{12345678}$, $\numprint{1234.5678}$\end{verbatim}
% leads to \begingroup
% ``\nplpadding{6}$\numprint{1234}$, $\numprint{-1234}$,
% $\numprint{12345678}$, $\numprint{1234.5678}$ --
% \nplpadding[x]{6}$\numprint{1234}$, $\numprint{-1234}$,
% $\numprint{12345678}$, $\numprint{1234.5678}$''
% \endgroup
%
% \cs{npnolpadding} switches padding off.
%
%
% \subsection{Replace zeros by other characters}
%
% \DescribeMacro{\npreplacenull}%
% \DescribeMacro{\npprintnull}%
% For amounts of money, sometimes a zero after the decimal sign is
% replaced by different symbols, as for example ``---''.
% This can be done by calling the command
% \cs{npreplacenull\marg{replacement}}, e.g.,
% \begin{verbatim}
%\npreplacenull{\mbox{---}}\end{verbatim}
% Here, \cs{mbox} guarantees that ``---'' is printed in text
% mode.\footnote{You should better use \texttt{amsmath} and the
% command \cs{text} which preserves the correct text size, too.}
%
% It can be switched off using \cs{npprintnull}.
%
%
% \subsection{Change the format of units}
%
% \DescribeMacro{\npunitcommand}%
% By default, the unit is printed in math mode with an upright font.
% This is reached by using the \cs{npunitcommand} macro which by
% default is defined as follows:
% \begin{verbatim}
%\newcommand*\npunitcommand[1]{\ensuremath{\mathrm{#1}}}\end{verbatim}
% If you want to change this, redefine the \cs{npunitcommand}.
% You really should use either \cs{ensuremath} or
% \cs{text}\footnote{Provided by \texttt{amsmath}.} to ensure math or
% text mode respectively.
% \cs{npunitcommand} has to take one mandatory argument.
%
% For example, a blue unit is reached by
% \begin{verbatim}
%\renewcommand*\npunitcommand[1]{\ensuremath{\color{blue}\mathrm{#1}}}\end{verbatim}
% And here is the result:
%\begingroup
%\renewcommand*\npunitcommand[1]{\ensuremath{\color{blue}\mathrm{#1}}}%
%\numprint[N/mm^2]{300}
%\endgroup
%
%
% \section{Add more units to \cs{lenprint}}%
% \label{sec:more-units}%
%
% \DescribeMacro{\npdefunit}%
% The command \cs{npdefunit\marg{unitname}\marg{unit}\marg{scale}} can
% be used to define new units or to redefine existing ones.
% For example, |mm| is defined as follows:
% \begin{verbatim}
%\npdefunit{mm}{mm}{0.35145980351}\end{verbatim}
% The first argument \meta{unitname} is the \LaTeX\ internal name that
% will be given as unit in the \cs{lenprint} command.
% The second argument \meta{unit} is the text that will be printed
% out.
%
% The \meta{scale} arises from the fact that the default unit
% $\mathrm{pt}$ is defined as $\np[pt]{1} = 1/\np[in]{72,27} =
% \np[in]{0,01383700013}$ and $\np[in]{1} = \np[mm]{25,4}$.
% Thus, $\np[pt]{1} = \np{0,01383700013} \times \np[mm]{25,4} =
% \np[mm]{0.35145980351}$.
% For defining a new unit, the factor from $\mathrm{pt}$ to the
% desired unit has to be calculated and given as third argument of
% \cs{npdefunit}.
% To redefine a unit with unchanged scale, use |*| instead.
% For example,
% \begin{verbatim}
%\npdefunit{in}{\!''}{*}\end{verbatim}
% redefines |in| to print $\mathrm{''}$ as unit instead of the default
% $\mathrm{in}$.
% The \cs{!} is used to remove the separator between number and unit
% (\cs{,}) again.
% This only works correctly if \cs{,} and \cs{!} use the same
% measure.
% \begin{verbatim}
%$\lenprint[in]{\textwidth}$,
%\npdefunit{in}{\!''}{*}%
%$\lenprint[in]{\textwidth}$\end{verbatim}
% leads to \begingroup
% ``$\lenprint[in]{\textwidth}$,
% \npdefunit{in}{\!''}{*}$\lenprint[in]{\textwidth}$''.
% \endgroup
%
%
%
% \section{International support}%
% \label{sec:international}%
% \changes{1.00}{2003/10/07}{Automatic support for different number
% formats in different languages}%
%
% As mentioned above, |numprint| uses German settings for numbers:
% thousand separator ``\cs{,}'', decimal sign ``\texttt{,}'', product
% sign ``\cs{cdot}'', unit separator \cs{,}, and no degree separator,
% by default.
% This will stay stable for compatibility with older versions even if
% its unlogical since the default language of \LaTeX\ is English.
%
% Using the package option |autolanguage| this can be fixed.
% If you are using this option without the |babel| package the
% settings are switched to English at \cs{begin\{document\}}.
% See Table~\ref{tab:defaults}.
%
% \begin{table}%
% \centering
% \caption{Default values for language settings}%
% \label{tab:defaults}%
% \begin{tabular}{lllllll}
% \toprule
% language& thousand& decimal& product& unit& percent& degree \\
% & sep.& sign& sign& sep.& sep.& sep. \\
% \midrule
% English& \texttt{,}& \texttt{.}& \cs{times}& \cs{,}& \cs{,}& none \\
% German& \cs{,}& \texttt{,}& \cs{cdot}& \cs{,}& \cs{,}& none \\
% Portuguese& \texttt{.}& \texttt{,}& \cs{cdot}& \cs{,}& \cs{,}& none \\
% Dutch& \cs{,}& \texttt{,}& \cs{cdot}& \cs{,}& none& none \\
% French& \texttt{\texttildelow}& \texttt{,}& \cs{cdot}& \cs{,}& \cs{,}& none \\
% \bottomrule
% \end{tabular}%
% \end{table}
%
% \DescribeMacro{\selectlanguage}
% If you are using the |babel| package in conjunction with the
% |autolanguage| package option, the behaviour of \cs{numprint} alters
% with the active language.
% If you, for instance, use
% \begin{verbatim}
%\selectlanguage{ngerman}\end{verbatim}
% the German settings are selected.
% If you then switch back to English, the English settings are active
% again.
%
% The current version supports English, German, Portuguese, Dutch, and
% French.
% Unfortunately, I don't really know how to write numbers in other
% languages than German.
% I am quite sure that the English version also is
% correct.\footnote{Maybe, the percent sign separator \cs{,} is not
% common, but I will leave its value unchanged to preserve
% compatibility with older versions.}
% But please help me to add other languages.
%
% If you want other settings than the default ones, listed in
% Table~\ref{tab:defaults}, please refer to
% Section~\ref{sec:advanced:international}.
%
% As long as |numprint| does not support your language you may add the
% definitions by yourself.
% How this can be done is also described in
% Section~\ref{sec:advanced:international}.
%
%
% \section{Print aligned numbers in tabulars}%
% \label{sec:tabular}%
% \changes{1.10}{2003/10/12}{New tabular alignment mechanism}%
%
% Aligning numbers in tabulars is providede by the \texttt{dcolumn}
% and \texttt{rccol} packages.
% But they have two disadvantages.
% First, they do not support typesetting numbers in the same way as
% \cs{numprint} does.
% Second, they force the numbers to be typeset in math mode.
% Thus, this packages provides own mechanisms to gain aligned
% numbers.
%
% In former versions up to 1.00, the align mechanism in tabulars has
% been somehow weak because the author had to repeat the \cs{numprint}
% call in every table cell.
% This has been improved in version~1.10.
% For compatibility reasons, the old column types |n| and |N| have
% been preserved if you specify the |oldcolumntypes| package option;
% they will be discussed in section~{sec:column:old}.
%
%
% \subsection{The new column types}%
% \label{sec:column:new}%
%
% \DescribeMacro{column type n}
% The |numprint| package provides the column type |n| that takes two
% mandatory arguments.
% They define the number of digits before and the number of digits
% after the decimal sign.
% The results can be seen in the left column of the tabular below.
% You can use this column type as the normal column types, e.g.,
% \begin{verbatim}
% \begin{tabular}{n{3}{4}n{4}{2}}\end{verbatim}
% The numbers are printed in a reserved space with the necessary width
% for the specified numbers, aligned at the decimal sign.
% If a column contains numbers that have an exponent it is appended
% left-aligned while the width of the column is extended by the
% required space.
% This is shown in the first column in the example below.
%
% If you, in addition, want to reserve space for digits in the
% exponent you can insert one (specify numbers of digits before the
% decimal sign) or two (number of digits before and after the decimal
% sign) optional arguments, as can be seen in columns 2 and 3 in the
% example below.
% If you reserve space for the exponent, too long exponents may exceed
% the tabular cell (as can be seen in the second column).
%
% This example tabular\footnote{The tabulars are ugly here. But the
% only important thing is to show the effects of the alignments.}
%\par\medskip\noindent
% {\tabcolsep0mm\small
% \begin{tabular}{|n{5}{3}|n[3]{5}{3}|n[3][1]{5}{3}|N{5}{3}|}
% \hline
% 123.45e12& 123.45e12& 123.45e12& 123.45e12 \\
% 12345.678e123& 12345.678e123& 12345.678e123& 12345.678e123 \\
% 123.45e12.3& 123.45e12.3& 123.45e12.3& 123.45e12.3 \\
% 12345.678e123.3& 12345.678e123.3& 12345.678e123.3& 12345.678e123.3 \\
% \hline
% \end{tabular}}
% \par\medskip\noindent
% is produced by the following code:
% \begin{verbatim}
%\tabcolsep0mm\small
%\begin{tabular}{|n{5}{3}|n[3]{5}{3}|n[3][1]{5}{3}|N{5}{3}|}
% \hline
% 123.45e12& 123.45e12& 123.45e12 & 123.45e12 \\
% 12345.678e123& 12345.678e123& 12345.678e123& 12345.678e123 \\
% 123.45e12.3& 123.45e12.3& 123.45e12.3& 123.45e12.3 \\
% 12345.678e123.3& 12345.678e123.3& 12345.678e123.3& 12345.678e123.3 \\
% \hline
%\end{tabular}\end{verbatim}
% The |n| column type prints the number in math mode.
% Thus, the first three columns in the example are printed with lining
% figures.
% \DescribeMacro{column type N}
% To print numbers in text mode, you can use the |N| column type as
% shown in column four of the tabular.\footnote{If you use a tabular
% environment that prints its arguments in math mode, e.g., the
% \texttt{array} environment, also \texttt{N} prints the numbers in
% math mode.}
% It takes the same arguments as the |n| column type.
%
% You may put additional text into tabular cells.
% The numprint package uses an algorithm to determine which part is
% the number and which is additional text.
% In order to preserve spaces and to use characters as text that could
% also be part of a number (e.g., digits or the characters ``e'',
% ``E'', ``d'', or ``D'') you have to enclose the text in
% braces, for example ``\texttt{\{hello\} 1234}'' instead of
% ``\texttt{hello 1234}''.
% (In some rare cases, even two pairs of braces is necessary.
% This is the case if you want to use a single character that may also
% be used in a number, e.g., ``\texttt{\{\{3\}\}
% 1234}''.\footnote{It is the same if the text starts with one of some
% special commands that normally don't occur at the beginning of
% tabular cells, \cs{end}, \cs{tabularnewline}, \cs{nprt@end},
% \cs{endtabular}, \cs{csname}, and \cs{relax}.})
% If you don't use these enclosing braces strange results may appear.
% For preceding text, you have to ensure that it has the same width
% for all lines of the same column.
% Have a look at the following example:
%\begin{verbatim}
%\begin{tabular}{n{2}{1}n{2}{1}n{2}{1}n[1]{2}{1}}
% \toprule
% {without braces}&
% {with braces}&
% {with braces and box}&
% \multicolumn{1}{l}{with braces, exp, and box}
% \\
% \midrule
% abc def 12,3e3 rt&
% {abc def } 12,3e3 { rt}&
% {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}&
% {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}
% \\
% more 45,1 txt&
% {more } 45,1 { txt}&
% {\npmakebox[abc def ][l]{more }} 45,1 { txt}&
% {\npmakebox[abc def ][l]{more }} 45,1 { txt}
% \\
% \midrule
% not blue 45,1 txt&
% {\color{blue}blue } 45,1 { txt}&
% {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}&
% {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}
% \\
% \bottomrule
%\end{tabular}
%\end{verbatim}
% The result looks as follows:
% \par\medskip\noindent
%{\footnotesize
%\begin{tabular}{n{2}{1}n{2}{1}n{2}{1}n[1]{2}{1}}
% \toprule
% {without braces}&
% {with braces}&
% {with braces and box}&
% \multicolumn{1}{l}{with braces, exp, and box}
% \\
% \midrule
% abc def 12,3e3 rt&
% {abc def } 12,3e3 { rt}&
% {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}&
% {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}
% \\
% more 45,1 txt&
% {more } 45,1 { txt}&
% {\npmakebox[abc def ][l]{more }} 45,1 { txt}&
% {\npmakebox[abc def ][l]{more }} 45,1 { txt}
% \\
% \midrule
% not blue 45,1 txt&
% {\color{blue}blue } 45,1 { txt}&
% {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}&
% {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}
% \\
% \bottomrule
%\end{tabular}}
% \par\medskip\noindent
% In the first column, the texts before and after the number are
% not enlosed by braces.
% Then, strange results appear:
% In the first line, ``\texttt{de}'' is interpreted as number.
% Thus, it is printed in math mode, and the rest of the cell,
% ``\texttt{f 12,3e3 rt}'' is printed as text, again.
% In the second line, the part ``\texttt{e 45,1}'' is printed as
% number.
%
% This strange behaviour can be avoided by enclosing the texts by
% braces, as mentioned above and shown in the second column.
% Thus, the texts are printed correctly.
% A space in the enclosed texts can separate the text from the number,
% as done in the example.
% Since the left texts have different widths the alignment of the
% numbers is broken, here.
%
% This can be fixed by putting the contents in boxes, using the
% \cs{makebox} or \cs{npmakebox} command, as shown in the third
% column.
% \DescribeMacro{\npmakebox}
% The \cs{npmakebox} has a similar syntax as the \cs{makebox} command
% but uses a text instead of a length to determine the width of the
% box: \cs{npmakebox\oarg{text 1}\oarg{justification}\marg{text 2}}.
% The command determines which width \meta{text 1} would have and
% typesets \meta{text 2} into a box of this width.
%
% If you put the preceding text in each line in such a box the number
% will be aligned as desired.
%
% Still, the text on the right-hand side of the numbers is not
% aligned.
% This can be fixed by specifying the number of digits of the
% exponent, as shown in the fourth column.
%
% The third line is a little bit different from the others.
% Here, not only text is inserted but also a command that changes the
% output of the numbers.
% Even such commands have to be enclosed by braces.
%
% \DescribeMacro{\multicolumn}
% For producing tabular cells that don't contain a number, you either
% have to enclose the cell contents by braces or to use the
% \cs{multicolumn} command as shown in the first line of the example
% above.
%
% If you want to print a line in bold letters using the \cs{boldmath}
% command in math resp.\ \cs{bfseries} in text mode the alignment is
% not correct anymore.
% This is due to the fact that the bold letters are wider than the
% normal ones.
% You can avoid that problem if the font family provides a bold font
% shape that has the same width as the normal one.
% For the Computer Modern fonts, such a font shape exists.
% In text mode, you can access it by using
% \changes{1.10}{2003/10/12}{Define math version \texttt{npbold}}%
% \begin{verbatim}
% \fontseries{b}\selectfont\end{verbatim}
% \DescribeMacro{\mathversion}
% \DescribeMacro{\npboldmath}
% If you also want to use that font in math mode, you may use the math
% version |npbold| by using \cs{mathversion\{npbold\}} or
% \cs{npboldmath}.
% In order to save memory, these commands and the |npbold| math
% version are only available if you call |numprint.sty| using the
% |boldmath| package option.
%
% An example:
% \begin{verbatim}
%\begin{tabular}{lN{12}{3}n{12}{3}}
% \toprule
% normal:&
% 123456123456.123e12&
% 123456123456.123e12
% \\
% bold:&
% {\fontseries{b}\selectfont} 123456123456.123e12&
% {\npboldmath} 123456123456.123e12
% \\
% bold extended:&
% {\bfseries} 123456123456.123e12&
% {\boldmath} 123456123456.123e12
% \\
% \bottomrule
%\end{tabular}\end{verbatim}
% This produces:
% \par\medskip\noindent
%{\small
%\begin{tabular}{lN{12}{3}n{12}{3}}
% \toprule
% normal:&
% 123456123456.123e12&
% 123456123456.123e12
% \\
% bold:&
% {\fontseries{b}\selectfont} 123456123456.123e12&
% {\npboldmath} 123456123456.123e12
% \\
% bold extended:&
% {\bfseries} 123456123456.123e12&
% {\boldmath} 123456123456.123e12
% \\
% \bottomrule
%\end{tabular}}
%\par\medskip
%
% If you want to add the same text or commands to all lines of a
% tabular column, you can use the ``|>|'' specifier in the declaration
% of the tabular column, as usual.
% You have to enclose its argument in an additional pair of braces, as
% shown in the example below.
% Unfortunately, the ``|<|'' specifier does not work properly.
% \DescribeMacro{\npafternum}
% Therefore, the \cs{npafternum} command is defined that takes one
% argument which is printed after the number.
% The following example shows text before and after the number:
% \begin{verbatim}
%\begin{tabular}{%
% >{{before \npafternum{ after}}}n[2]{12}{3}%
% >{{\nprounddigits{4}}}n{3}{4}%
% >{{\color{blue}}}n{12}{3}}
% \toprule
% 123456123456.123e12&
% 12.12345&
% 123456.23e1
% \\
% 12345.123e12&
% 12.1&
% 14561234.562e12
% \\
% \bottomrule
%\end{tabular}\end{verbatim}
% This produces:
% \par\medskip\noindent
%{\small
%\begin{tabular}{%
% >{{before \npafternum{ after}}}n[2]{12}{3}%
% >{{\nprounddigits{3}}}n{3}{3}%
% >{{\color{blue}}}n{8}{3}}
% \toprule
% 123456123456.123e12&
% 12.12353&
% 123456.23e1
% \\
% 12345.123e12&
% 12.1&
% 14561234.562e12
% \\
% \bottomrule
%\end{tabular}}
%\par\medskip
% As can be seen in the second column, numbers can be rounded in
% special columns by inserting \cs{nproundigits} into a ``|>|''
% specification.
% This can be said for all other commands that influence the format of
% numbers, too.
%
% \DescribeMacro{\npunit}
% Normally, units should not be typeset in the cells of a tabular.
% But if this is needed, it may be realized using the \cs{npunit}
% command, as shown here:
% \begin{verbatim}
%\begin{tabular}{>{{\npunit{N/mm^2}}}n{5}{3}}
% \toprule
% 12345.123\\
% 12.12\\
% {\npunit{psi}} 234.4\\
% 4.3\\
% \bottomrule
%\end{tabular}\end{verbatim}
% This produces:
% \par\medskip\noindent
%{\small
%\begin{tabular}{>{{\npunit{N/mm^2}}}n{5}{3}}
% \toprule
% 12345.123\\
% 12.12\\
% {\npunit{psi}} 234.4\\
% 4.3\\
% \bottomrule
%\end{tabular}}
%\par\medskip
%
% The tabular alignment of the |numprint| package has been tested with
% the |tabular|, |tabular*|, |array|, |tabularx|~\cite{carlisle1999a},
% and |longtable|~\cite{carlisle2000a} environments.
% It may or may not run with other packages and environments.
%
%
% \subsection{The old column types}%
% \label{sec:column:old}%
%
% \newcolumntype{m}[2]{>{\npdigits{#1}{#2}$}l<{$}}%
% \newcolumntype{M}[3]{>{\npdigits{#1}{#2}\npexponentdigits{#3}$}l<{$}}%
%
% \DescribeMacro{column type N}
% If the |oldcolumntype| package option is specified the column types
% |n| and |N| are defined differently than described in the previous
% section.
% \DescribeMacro{column type n}
% The |n| column type alignes the base number to the decimal sign, the
% |N| column type additionaly alignes the exponent.
%
% Use these commands as follows:
% \begin{verbatim}
%\tabcolsep0mm
%\begin{tabular}{|n{5}{3}|N{5}{3}{3}|}
% \hline
% \numprint{123.45e12}& \numprint{123.45e12}\\
% \numprint{12345.678e123}& \numprint{12345.678e123}\\
% \numprint{123.45e12.3}& \numprint{123.45e12.3}\\
% \numprint{12345.678e123.3}& \numprint{12345.678e123.3}\\
% \hline
%\end{tabular}\end{verbatim}
% This leads to\par\medskip\noindent
% {\tabcolsep0mm
% \begin{tabular}{|m{5}{3}|M{5}{3}{3}|}
% \hline
% \numprint{123.45e12}& \numprint{123.45e12}\\
% \numprint{12345.678e123}& \numprint{12345.678e123}\\
% \numprint{123.45e12.3}& \numprint{123.45e12.3}\\
% \numprint{12345.678e123.3}& \numprint{12345.678e123.3}\\
% \hline
% \end{tabular}}
% \medskip
%
% The first argument 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.
% It is not possible to define the numbers of digits after the decimal
% sign in the exponent; they are set to zero.
% Notice that the command \verb|\numprint| has to be written again in
% each tabular entry, using the old column types.
%
%
% \subsection{Alignment in normal text}%
%
% The alignment of the numbers in tabulars is realized by writing the
% number inside a box with the specified width.
% This functionality can also be used outside tabular environments.
% \DescribeMacro{\npdigits}
% The \cs{npdigits\marg{before}\marg{after}} command switches on the
% alignment of numbers printed by \cs{numprint}.
% The first argument defines the number of digits before the decimal
% sign while the second argument defines the number of digits after
% it for the mantissa.
% \DescribeMacro{\npexponentdigits}
% Since exponents are normally integer numbers the syntax of the
% corresponding \cs{npexponentdigits} command is slightly different.
% Its syntax is \cs{npexponentdigits\oarg{after}\marg{before}}.
% The mandatory argument defines the number of digits before the
% decimal sign of the exponent.
% If no optional argument is given, the number of digits after the
% decimal sign is set to zero.
% If it is given it defines the number of digits after the decimal
% sign.
%
% If the \cs{npdigits} or \cs{npexponentdigits} commands have been
% used inside a group the values are reset at the end of the group.
% \DescribeMacro{\npnodigits}
% \DescribeMacro{\npnoexponentdigits}
% Alignment can also be switched off using the \cs{npnodigits} resp.\
% \cs{npnoexponentdigits} commands.
%
%
% \section{Error messages etc.}
%
% By default, \cs{numprint} produces an error message if the argument
% uses some invalid characters or if the number format is invalid.
% Some people use \cs{numprint} to do strange things and thus use
% invalid arguments designedly.
% These people may switch off these error messages by using the
% package option |warning|.
%
% If you want some debug messages to be written into the log file, use
% the package option |debug|.
%
%
% \section{Advanced customization}%
% \label{sec:advanced}%
%
% \subsection{Changing the output}%
% \label{sec:changing-output}%
%
% Most of the things described in this section are not necessary to be
% done by hand because the feature ``automatic language support'',
% described in section~\ref{sec:international} does this
% automatically.
%
% \subsubsection{Without the \textmd{\texttt{autolanguage}} option}
%
% \DescribeMacro{\npthousandsep}%
% \DescribeMacro{\npthousandthpartsep}%
% \DescribeMacro{\npdecimalsign}%
% \DescribeMacro{\npproductsign}%
% By using the commands
% \cs{npdecimalsign\marg{Sign}},
% \cs{npthousandsep\marg{Separator}},
% \cs{npthousandthpartsep\marg{Separator}}, and
% \cs{npproductsign\marg{Sign}},\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 and symbols can be changed, e.g.,
% \begin{verbatim}
%\npdecimalsign{\ensuremath{\cdot}}\npthousandsep{,}\npproductsign{*}%
%\numprint{-123456}; \numprint{3,1415927e-3.2}\end{verbatim}
% leads to ``{\npdecimalsign{\ensuremath{\cdot}}%
% \npthousandsep{,}\npproductsign{*}%
% \numprint{-123456}; \numprint{3,1415927e-3.2}}''.
%
% The \cs{npthousandsep} both changes the separators before and after
% the decimal sign.
% If you want to use different separators, you have to call
% \cs{npthousandthpartsep} \emph{after} \cs{npthousandsep}.
%
% The separators as well as the decimal sign are typeset in the same
% mode as the number itself (math or text).
% If you want to guarantee a special mode, you have to use
% \cs{ensuremath} for math or either \cs{mbox}, \cs{textrm}, or
% \cs{text}\footnote{Provided by \texttt{amsmath}.} for text mode.
%
% The product sign, in contrast, is always printed in math mode.
% Thus, you don't have to add \cs{ensuremath} to use math commands.
%
% \DescribeMacro{\global}%
% If using these commands inside a group (|{|\ldots|}|,
% \cs{begingroup}\ldots\cs{endgroup}, or an environment)
% the behaviour of the \verb|\numprint| command is changed
% 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{\cdot}\numprint{123e4}},
%\numprint{123e4}.
%Global:
%\numprint{123e4},
%{\global\npproductsign{\cdot}\numprint{123e4}},
%\numprint{123e4}\end{verbatim}
% leads to the following:
%
% \noindent Local:
% \numprint{123e4},
% {\npproductsign{\cdot}\numprint{123e4}},
% \numprint{123e4}.
% Global:
% \numprint{123e4},
% {\npproductsign{\cdot}\numprint{123e4},
% \numprint{123e4}}
%
% The current version has the following defaults:
% \begin{verbatim}
%\npthousandsep{\,}
%\npdecimalsign{,}
%\npproductsign{\cdot}
%\npunitseparator{\,}\end{verbatim}
%
% \DescribeMacro{\npunitseparator}%
% The space between the number and the unit is ``\cs{,}'' by
% default. It can be changed using the command
% \cs{npunitseparator\marg{Separator}},
% e.g.,
% \begin{verbatim}
%\npunitseparator{~}\end{verbatim}
%
% \DescribeMacro{\npdegreeseparator}%
% By default, no space is added between the number an a degree symbol.
% You may specify a separator for that using
% \cs{npdegreeseparator\marg{Separator}}.
%
% \DescribeMacro{\npcelsiusseparator}%
% By default, the same space as for normal units is added between the
% number an \textcelsius.
% You may specify a different separator for that using
% \cs{npcelsiusseparator\marg{Separator}}.
% Note that \cs{tccentigrade} is not supported by |numprint|.
%
% \DescribeMacro{\nppercentseparator}%
% By default, the same space as for normal units is added between the
% number and a percent sign.
% You may specify a different separator for that using
% \cs{nppercentseparator\marg{Separator}}.
%
%
%
% \subsubsection{With the \textmd{\texttt{autolanguage}} option}%
% \label{sec:advanced:international}%
%
% If you are using the |autolanguage| option changes made with the
% commands described in the previous section get lost at the next
% change of the language or at \cs{begin\{document\}}.
% Thus, they cannot be used with this option in the way described
% there.
%
% Thus, you have to redefine the commands that set the
% language-dependent numprint settings.
% For each known language, a command \cs{npstyle\meta{language}} is
% defined that does the changes, e.g., \cs{npstyleenglish} for
% English.
% \DescribeMacro{\npstyleenglish}
% This command is defined as follows:
% \begin{verbatim}
%\newcommand*\npstyleenglish{%
% \npthousandsep{,}%
% \npdecimalsign{.}%
% \npproductsign{\times}%
% \npunitseparator{\,}%
% \npdegreeseparator{}%
% \npcelsiusseparator{\nprt@unitsep}%
% \nppercentseparator{\nprt@unitsep}%
%}\end{verbatim}
%
% If you want to use different settings for this language, you have
% two possibilities:
% \begin{enumerate}
% \item
% Copy the definition for \cs{npstyle\meta{language}} from the style
% file and change it according to your wishes, for
% example:\footnote{Notice that you have to use \cs{renewcommand*}
% instead of \cs{newcommand*}.}
% \begin{verbatim}
%\renewcommand*\npstyleenglish{%
% \npthousandsep{,}%
% \npdecimalsign{{\cdot}}%
% \npproductsign{\times}%
% \npunitseparator{\,}%
% \npdegreeseparator{}%
% \npcelsiusseparator{\nprt@unitsep}%
% \nppercentseparator{\nprt@unitsep}%
%}\end{verbatim}
% \item
% Another way to add different settings to a language is to use
% \cs{g@addto@macro} to append commands to an existing
% \cs{npstyle\meta{language}} command, e.g.,
% \begin{verbatim}
%\makeatletter
%\g@addto@macro\npstyleenglish{%
% \nppercentseparator{}%
%}%
%\makeatother\end{verbatim}
% This has the advantage that changes in the original command are not
% lost by using a copy.
% The disadvantage is that some commands may be called twice which is
% slightly slower.
% \end{enumerate}
% The changes take effect when the style command is called the next
% time; this is when the language is changed the next time or at
% \cs{begin\{document\}}.
%
%
% If the language you are using is not yet supported by |numprint| you
% may add support for it in the preamble of your document.
%
% \DescribeMacro{\npaddtolanguage}
% The simplest case is a language that uses the same settings as one
% of the languages, already supported.
% If, for instance, you want to use Danish with the same settings as
% German, you just have to add
% \begin{verbatim}
%\npaddtolanguage{danish}{german}\end{verbatim}
% to the preamble of your document.
%
% If you, instead, want to use different settings, define a
% corresponding style command.
% Let's take Danish as an example, again.
% Define a command \cs{npstyledanish} which defines
% everything you want to change against the default (I choose some
% strange values for clearness):
% \begin{verbatim}
%\newcommand*\npstyledanish{%
% \npthousandsep{.}%
% \npdecimalsign{\ensuremath{\cdot}}%
% \npproductsign{*}%
% \npunitseparator{~}%
% \npdegreeseparator{}%
% \npcelsiusseparator{\nprt@unitsep}%
% \nppercentseparator{\nprt@unitsep}%
%}\end{verbatim}
% In addition, append the call of this command to the
% language-switching command for Danish:
% \begin{verbatim}
%\npaddtolanguage{danish}{danish}\end{verbatim}
%
%
% \subsection{Changing the argument parsing}%
% \label{sec:custom-parsing}%
%
% It has been said above that thousand separators are not allowed in
% the argument of the \cs{numprint} command.
% This can be customized by the user.
%
% For most elements in the input, \cs{numprint} uses lists that
% contain the corresponding characters.
% \DescribeMacro{\nprt@dotlist}
% The macro \cs{nprt@dotlist} contains the characters interpreted as
% decimal signs.
% It is defined as followed:
% \begin{verbatim}
%\newcommand*\nprt@dotlist{.,}\end{verbatim}
% If you, for example, only want to allow the dot as decimal sign,
% redefined the list:
% \begin{verbatim}
%\renewcommand*\nprt@dotlist{.}\end{verbatim}
% If you want to do this in your document rather than in the
% configureation file \texttt{numprint.cfg}---see
% section~\ref{sec:configuration}--- you have to enclose this by
% \cs{makeatletter} and \cs{makeatother}.
%
% \DescribeMacro{\nprt@explist}%
% The \cs{nprt@explist} command contains the characters interpreted as
% delimiter between mantissa and exponent.
% By default it contains ``\texttt{eEdD}''.
% Redefine it as \cs{nprt@dotlist}.
%
% \DescribeMacro{\nprt@ignorelist}%
% The \cs{nprt@ignorelist} command contains a list of characters that
% are ignored in the input (in addition to spaces, ``\cs{,}'', and
% ``\texttt{\~}'').
% It is empty by default.
% If you, for example, only want to allow dots as decimal sign and
% commas may occur as thousand separators in the input, you may use
% following redefinition:
% \begin{verbatim}
%\renewcommand*\nprt@dotlist{.}
%\renewcommand*\nprt@ignorelist{,}\end{verbatim}
% Then, ``\texttt{,}'' is ignored in the input and ``\texttt{.}'' is
% interpreted as decimal sign.
% For example,
% \begin{verbatim}
%\makeatletter
%{\renewcommand*\nprt@dotlist{.}%
%\renewcommand*\nprt@ignorelist{,}%
%\numprint{12,234.123,45e1,2,3.0}}
%\makeatother\end{verbatim}
% leads to
% \makeatletter%
% {\def\nprt@dotlist{.}\def\nprt@ignorelist{,}``\numprint{12,234.123,45e1,2,3.0}}''.
% \makeatother
%
% \DescribeMacro{\nprt@signlist}%
% The \cs{nprt@signlist} command contains the list of known signs.
% By default, it is set to ``\texttt{+-}\cs{pm}''.
% You may change the list of accepted signs by redefining
% \cs{nprt@signlist}.
% If, for instance, the letter ``\texttt{*}'' is intended to be a
% sign, just type in
% \begin{verbatim}
%\renewcommand*\nprt@signlist{+-\pm *}\end{verbatim}
% This character is typeset when using it as sign.
% But this indicates one problem: The sign might differ between text
% and math mode, as show in the following example:
% {\makeatletter\def\nprt@signlist{+-\pm *}\makeatother
% In text mode, \cs{numprint\{*1234\}} occurs as ``\numprint{*1234}''
% while is is typeset as ``$\numprint{*1234}$'' in math mode.}
% To avoid that, you may define a command that prints the sign.
% This command must have a name according to
% \cs{nprt@list@\meta{sign}}.
% \DescribeMacro{\nprt@sign@*}%
% In this case, you have to define \cs{nprt@list@*}.
% Since the sign might be arbitrary characters, you should define the
% command as follows:
% \begin{verbatim}
%\expandafter\newcommand\csname nprt@sign@*\endcsname{\ensuremath{*}}\end{verbatim}
% {\makeatletter\expandafter\def\csname nprt@sign@*\endcsname{\ensuremath{*}}%
% \def\nprt@signlist{+-\pm *}\makeatother
% With this command, \cs{numprint\{*1234\}} occurs as
% ``\numprint{*1234}'' in text mode and as ``$\numprint{*1234}$'' in
% math mode.}
%
% Because of this mechanism to print a sign, it is not possible to use
% other macro names than \cs{pm} for signs.\footnote{\cs{pm} is
% handled separately.}
% You have to use single characters as the shown ``\texttt{*}''.
%
%
% \section{Some tricks}
%
% \subsection{Let the signs depend on the mode}
%
% \DescribeMacro{\nprt@sign@+}%
% \DescribeMacro{\nprt@sign@-}%
% \DescribeMacro{\nprt@sign@+-}%
% The default signs are typeset in math mode independently of the mode
% the number ist printed.
% If you are using a font in which the sings of text and math mode
% differ much, this may be unsatisfactory.
% Then, you can typeset different signs for text and math mode.
% Therefore, it is used that the default signs use the same macros as
% user signs, described in section~\ref{sec:custom-parsing}.
% They are defined as follows:
% \begin{verbatim}
%\expandafter\newcommand\csname nprt@sign@+\endcsname{\ensuremath{+}}
%\expandafter\newcommand\csname nprt@sign@-\endcsname{\ensuremath{-}}
%\expandafter\newcommand\csname nprt@sign@+-\endcsname{\ensuremath{\pm}}\end{verbatim}
% If you, for instance, don't want to use the math minus for numbers
% in text mode but another character, you may redefine
% \cs{nprt@sign@-}:
% \begin{verbatim}
%\expandafter\renewcommand\csname nprt@sign@-\endcsname{%
% \ifmmode -\else ---\fi}\end{verbatim}
%{\makeatletter\expandafter\def\csname nprt@sign@-\endcsname
% {\ifmmode -\else---\fi}\makeatother
% With this definition, \cs{numprint\{-1234\}} leads to
% ``\numprint{-1234}'' resp.\ ``$\numprint{-1234}$'' in text resp.\
% math mode.}
%
%
% \subsection{Typing negative numbers in red}%
% \label{sec:negative-red}%
%
% If you want to print negative number in red colors, you can use the
% \cs{nprt@sign@-} command, too.
% The following example shows how to do it:
% \begin{verbatim}
%\usepackage{color}
%\makeatletter
%\expandafter\renewcommand\csname nprt@sign@-\endcsname{%
% \color{red}\ensuremath{-}}
%\makeatother\end{verbatim}
% With this definition,
% \begin{verbatim}
%\numprint{1234}, \numprint{-1234},
%\numprint{1234e-123}, \numprint{-1234e123}.\end{verbatim}
% {\makeatletter\expandafter\def\csname nprt@sign@-\endcsname
% {\color{red}\ensuremath{-}}\makeatother
% leads to ``\numprint{1234}, \numprint{-1234}, \numprint{1234e-123},
% \numprint{-1234e123}.''}\footnote{Wheather you can see the effect in
% the output depends on the viewer; in PostScript and PDF the red
% color works, in many dvi viewers, it doesn't.}
% To avoid a negative exponent beeing printed in red for a positive
% mantissa, a hack is included in the page which is described in
% appendix~\ref{sec:code:main}, page~\pageref{page:code:color}.
%
%
%
% \subsection{Configuration file}%
% \label{sec:configuration}%
%
% If your \LaTeX\ installation provides a file \texttt{numprint.cfg}
% in the \TeX\ search path, it is loaded by \texttt{numprint.sty} as
% last action.
% Thus, you may add all changes and extensions, new languages for
% instance, into this file.
%
%
% \appendix
%
% \section{Compatiblity to older versions}
%
% In most cases, the user macros of this package (the macros not
% containing a ``|@|'' in their name) should be compatible to older
% versions.
% The parsing of the argument has been improved that some arguments of
% \cs{numprint} may be accepted or not in contrast to the older
% version.
%
% The spacing of aligned numbers has also been corrected.
% Thus, this is be incompatible to the older version if you are using
% alignment in the exponent or math environmens other than
% \cs{textstyle}.
%
%
% \section{Lists of options and commands}
%
% This section contains lists of all package options resp.\ available
% commands.
% Items that belong together and may be exclusive are printed in
% groups together.
%
% \subsection{Package options}%
% \label{sec:package-options}%
%
% \begingroup
% \newcommand*\default{$^{*}$}%
% The default values are marked by \default.
% \begin{longtable}[l]{%
% @{}>{\ttfamily}p{0.30\linewidth}@{}p{0.70\linewidth}@{}}
% warning& Produce warnings rather than error messages. \\
% error\default& Produce error messages rather than
% warnings. \\[\medskipamount]
% autolanguage& Switch the settings language dependent.\\
% noautolanguage\default& Fixed settings.\\[\medskipamount]
% sepfour\default& Separator for four-digit numbers.\\
% nosepfour& No separator for four-digit numbers.\\[\medskipamount]
% addmissingzero\default& Add missings zeros before or after the
% decimal sign.\\
% noaddmissingzero& Don't do that.\\[\medskipamount]
% addplus& Add a plus to a number without a sign.\\
% noaddplus\default& Don't do that.\\[\medskipamount]
% addplusexponent& Add a plus to a number without a sign in
% exponents.\\
% noaddplusexponent\default& Don't do that.\\[\medskipamount]
% oldcolumntypes& Define the old column types that need to use the
% \cs{numprint} inside the tabular.\\
% newcolumntypes\default& Use the new column types.\\[\medskipamount]
% boldmath& Define the \texttt{npbold} math version.\\[\medskipamount]
% np& Define the shortcut \cs{np} for
% \cs{numprint}.\\[\medskipamount]
% debug& Produce debug information in the log file.
% \end{longtable}
% \endgroup
%
% \subsection{Commands}
%
% \begin{longtable}[l]{%
% @{}>{\ttfamily \char`\\}p{0.3\linewidth}@{}p{0.7\linewidth}@{}}
% npfourdigitsep& Switch on separating four-digit numbers.\\
% npfourdigitnosep& Switch off separating four-digit
% numbers.\\[\medskipamount]
% npaddmissingzero& Switch on adding missings zeros before or after the
% decimal sign.\\
% npnoaddmissingzero& Switch off adding missings zeros before or after
% the decimal sign.\\[\medskipamount]
% npaddplus& Add a plus to a number without a sign.\\
% npnoaddplus& Don't do that.\\[\medskipamount]
% npaddplusexponent& Add a plus to the exponent when it has no sign.\\
% npnoaddplusexponent& Don't do that.\\[\medskipamount]
% np& Shortcut for \cs{numprint} (only available with package
% option~\texttt{np}).\\
% numprint& Typesets a number (the package's main
% command).\\[\medskipamount]
% npdecimalsign& Change the decimal sign.\\
% npthousandsep& Change the thousand separator (before and after the
% decimal sign).\\
% npthousandthpartsep& Change the thousand separator (only after the
% decimal sign).\\
% npproductsign& Change the product sign.\\
% npunitseparator& Change the separator between a number and a
% unit.\\
% npdegreeseparator& Change the separator between a number and a
% degree symbol.\\[\medskipamount]
% npcelsiusseparator& Change the separator between a number and
% \textcelsius.\\[\medskipamount]
% nppercentseparator& Change the separator between a number and a
% percent sign.\\[\medskipamount]
% nprounddigits& Declare how many digits will be printed after the
% decimal sign.\\
% npnoround& Switch off rounding and print numbers as given.\\
% nproundexpdigits& Declare how many digits will be printed after the
% decimal sign in the exponent.\\
% npnoroundexp& Switch off rounding for the
% exponent.\\[\medskipamount]
% nplpadding& Declare up to how many digits the number will be padded at
% the lefthand side. \\
% npnolpadding& Switch off padding. \\[\medskipamount]
% npreplacenull& Replace the after-decimal-sign part by another text
% if it is zero.\\
% npprintnull& Print zeros after the decimal sign.\\[\medskipamount]
% npdigits& Switch on aligned number printing with given digits before
% and after the decimal sign.\\
% npnodigits& Print numbers in a box that is as wide as needed by the
% number.\\
% npexponentdigits& Switch on aligned printing of the exponent.\\
% npnoexponentdigits& Switch alignment off for the
% exponent.\\[\medskipamount]
% npaddtolanguage& Adds language definitions to the extras section
% of a \texttt{babel} language.\\
% npstyledefault& Defines the settings in standard format.\\
% npstylegerman& Defines the German number format.\\
% npstyleenglish& Defines the English number
% format.\\[\medskipamount]
% npmakebox& Command similar to \cs{makebox} but with text instead
% of length in first optional argument.\\[\medskipamount]
% npboldmath& Bold math version with digits with the same width as
% normal digits.\\[\medskipamount]
% npafternum& Puts text after the number in
% tabulars.\\[\medskipamount]
% npunit& Sets the unit in tabulars.\\[\medskipamount]
% \end{longtable}
%
% \section{Known bugs}
%
% \begin{itemize}
% \item When aligning the exponent for tabulars, the distance between
% the ``10'' and the exponent is too small.
% \item Printing negative numbers in red does not work.
% Only the minus sign is printed in red.
% When was this bug introduced?
% \end{itemize}
%
% \section{To do}
%
% \begin{itemize}
% \item Add more languages to the automatic international support.
% \item Add support for ``|<|'' in tabular definitions.
% \item Avoid many of the temporary variables.
% \item Add support for numbers in tabulars that are right aligned or
% centered.
% \end{itemize}
%
% \section{Acknowledgements}
%
% \begin{itemize}
% \item
% Tilman Finke, had the idea of rounding numbers.
% \item
% Stephan Helma has implemented padding numbers on the left side.
% This function has been slightly changed by me.
% \item
% Portuguese support by Vilar Camara Neto and Luis.
% \item
% Dutch support by Ralph Hendriks.
% \item
% French support by Daniel Flipo.
% \item
% Ignacio Fern\'andez Galv\'an has reported a couple of bugs and
% suggestions (which parly still have to be implemented\ldots)
% \end{itemize}
%
% \begin{thebibliography}{1}
% \bibitem{carlisle1999a}
% Carlisle, David: \emph{The \texttt{tabularx} package},
% version~2.07, 1999.\newblock
% \url{CTAN:macros/latex/contrib/tabularx/}.
% \bibitem{carlisle2000a}
% Carlisle, David: \emph{The \texttt{longtable} package},
% version~4.10, 2000.\newblock
% \url{CTAN:macros/latex/contrib/longtable/}.
% \bibitem{guthoehrlein2000a}
% Guth\"ohrlein, Eckhart: \emph{The \texttt{rccol} package},
% version~1.1a, 2000.\newblock
% \url{CTAN:macros/latex/contrib/rccol/}.
% \end{thebibliography}
%
% \StopEventually{\PrintChanges \PrintIndex}
%
% \section{The implementation}
% \iffalse
%<*package>
% \fi
% Heading of the package:
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{numprint}
[2008/02/17 v1.38 Print numbers (HH)]
% \end{macrocode}
%
% \subsection{Load packages}
%
% \changes{1.33}{2004/11/19}{Avoid to use the \texttt{calc} package
% since it causes problems with many other packages}%
%
% Load package array.sty for the new column types.
% \begin{macrocode}
\RequirePackage{array}
% \end{macrocode}
% \changes{1.10}{2003/10/12}{Avoid use of \texttt{substr} package}%
%
% \subsection{Package options and settings}
%
% 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\ifnprt@numsepfour
% \end{macrocode}
% Show warnings or errors?
% \begin{macrocode}
\newif\ifnprt@errormessage
% \end{macrocode}
% Add missing zeros?
% \begin{macrocode}
\newif\ifnprt@addmissingzero
% \end{macrocode}
% Add missing plus signs?
% \begin{macrocode}
\newif\ifnprt@addplus@mantissa
\newif\ifnprt@addplus@exponent
% \end{macrocode}
% Switch the style depending on the language automatically?
% \begin{macrocode}
\newif\ifnprt@autolanguage
% \end{macrocode}
% Old or new column types?
% \begin{macrocode}
\newif\ifnprt@newcolumntype
% \end{macrocode}
% Declare new math type?
% \begin{macrocode}
\newif\ifnprt@npbold
% \end{macrocode}
% \begin{macro}{\npfourdigitsep}
% Switch separating of the fourth digit on.
% \begin{macrocode}
\newcommand*\npfourdigitsep{\nprt@numsepfourtrue}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npfourdigitnosep}
% Switch separating of the fourth digit off.
% \begin{macrocode}
\newcommand*\npfourdigitnosep{\nprt@numsepfourfalse}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npaddmissingzero}
% Add a missing zero before or after decimalsign.
% \begin{macrocode}
\newcommand*\npaddmissingzero{\nprt@addmissingzerotrue}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoaddmissingzero}
% Don't add a missing zero before or after decimalsign.
% \begin{macrocode}
\newcommand*\npnoaddmissingzero{\nprt@addmissingzerofalse}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npaddplus}
% Add a plus to the mantissa if no sign is given.
% \begin{macrocode}
\newcommand*\npaddplus{\nprt@addplus@mantissatrue}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoaddplus}
% Don't add a plus to the mantissa if no sign is given.
% \begin{macrocode}
\newcommand*\npnoaddplus{\nprt@addplus@mantissafalse}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npaddplusexponent}
% Add a plus to the exponent if no sign is given.
% \begin{macrocode}
\newcommand*\npaddplusexponent{\nprt@addplus@exponenttrue}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoaddplusexponent}
% Don't add a plus to the exponent if no sign is given.
% \begin{macrocode}
\newcommand*\npnoaddplusexponent{\nprt@addplus@exponentfalse}%
% \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}{\npfourdigitnosep}
\DeclareOption{sepfour}{\npfourdigitsep}
% \end{macrocode}
% Add missing zeros after decimal sign?
% \begin{macrocode}
\DeclareOption{noaddmissingzero}{\npnoaddmissingzero}
\DeclareOption{addmissingzero}{\npaddmissingzero}
% \end{macrocode}
% Add a plus sign to the mantissa if no sign is given?
% \begin{macrocode}
\DeclareOption{noaddplus}{\npnoaddplus}
\DeclareOption{addplus}{\npaddplus}
% \end{macrocode}
% Add a plus sign to the exponent if no sign is given?
% \begin{macrocode}
\DeclareOption{noaddplusexponent}{\npnoaddplusexponent}
\DeclareOption{addplusexponent}{\npaddplusexponent}
% \end{macrocode}
% Add missing zeros after decimal sign?
% \begin{macrocode}
\DeclareOption{noautolanguage}{\nprt@autolanguagefalse}
\DeclareOption{autolanguage}{\nprt@autolanguagetrue}
% \end{macrocode}
% \begin{macro}{\np}
% \changes{1.00}{2003/10/07}{Add shortcut for \cs{numprint}}%
% Define a shortcut for the \cs{numprint} command?
% \begin{macrocode}
\DeclareOption{np}{\newcommand*\np{\numprint}}
% \end{macrocode}
% \end{macro}
% Produce warnings or errors?
% \begin{macrocode}
\DeclareOption{oldcolumntypes}{\nprt@newcolumntypefalse}
\DeclareOption{newcolumntypes}{\nprt@newcolumntypetrue}
% \end{macrocode}
% Declare new math type?
% \begin{macrocode}
\DeclareOption{boldmath}{\nprt@npboldtrue}
% \end{macrocode}
% Produce warnings or errors?
% \begin{macrocode}
\DeclareOption{warning}{\nprt@errormessagefalse}
\DeclareOption{error}{\nprt@errormessagetrue}
% \end{macrocode}
% Generate some debug information to the log file?
% \begin{macrocode}
\newcommand*\nprt@debug[1]{}
\DeclareOption{debug}{%
\renewcommand*\nprt@debug[1]{\PackageInfo{numprint}{#1}}%
}
% \end{macrocode}
% Execute default options and the given options.
% \begin{macrocode}
\ExecuteOptions{sepfour,addmissingzero,error,noautolanguage,newcolumntypes}
\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 decimal
% sign.
% 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@separator@before{{#1}}%
\def\nprt@separator@after{{#1}}}
% \end{macrocode}
% \end{macro}%
% \begin{macro}{\npthousandthpartsep}
% Change the thousand separator after the decismal sign.
% \begin{macrocode}
\newcommand*\npthousandthpartsep[1]{\def\nprt@separator@after{{#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 and unit.
% Here again the additional \verb|{}| is used as above.
% \begin{macrocode}
\newcommand*\npunitseparator[1]{\def\nprt@unitsep{{#1}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npdegreeseparator}
% Change the separator between number and \textdegree.
% Here again the additional \verb|{}| is used as above.
% \begin{macrocode}
\newcommand*\npdegreeseparator[1]{\def\nprt@degreesep{{#1}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npcelsiusseparator}
% Change the separator between number and \textcelsius.
% Here again the additional \verb|{}| is used as above.
% \begin{macrocode}
\newcommand*\npcelsiusseparator[1]{\def\nprt@celsiussep{{#1}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nppercentseparator}
% Change the separator between number and \%.
% Here again the additional \verb|{}| is used as above.
% \begin{macrocode}
\newcommand*\nppercentseparator[1]{\def\nprt@percentsep{{#1}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@fillnull}
% Defines command |#1| with a number of |#2| zeros filled.
% This should reside in Sect.~\ref{sec:code:round} but is called
% before.
% \begin{macrocode}
\def\nprt@fillnull#1#2{%
\@tempcnta=-1
\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{}%
\nprt@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{}%
\nprt@fillnull{\nprt@roundexpnull}{#1}%
}
\newcommand\npnoroundexp{\nproundexpdigits{-1}}
\npnoroundexp
% \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\nplpadding}
% This command sets the total counts of digits a number should contain.
% The missing digits are filled with the character from the second
% argument (which is 0 by default).
% \begin{macrocode}
\newcommand\nplpadding[2][0]{%
\def\nprt@lpaddigits{#2}%
\def\nprt@lpadchar{#1}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npnolpadding}
% The command to switch of padding.
% \begin{macrocode}
\newcommand*\npnolpadding{\nplpadding[\@empty]{-1}}
% \end{macrocode}
% \end{macro}
% Don't pad by default.
% \begin{macrocode}
\npnolpadding
% \end{macrocode}
% \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}
% \begin{macro}{\npunitcommand}
% This command is used to typeset the unit.
% \begin{macrocode}
\newcommand*\npunitcommand[1]{\ensuremath{\mathrm{#1}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npdigits}
% 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}
\newif\ifnprt@mantissa@fixeddigits
\newcommand*\npdigits[2]{%
\edef\nprt@mantissa@fixeddigits@before{#1}%
\edef\nprt@mantissa@fixeddigits@after{#2}%
\nprt@mantissa@fixeddigitstrue
}
% \end{macrocode}
% Initialize the numbers.
% \begin{macrocode}
\def\nprt@mantissa@fixeddigits@before{-1}%
\def\nprt@mantissa@fixeddigits@after{-1}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npnodigits}
% Switch back to normal printing.
% \begin{macrocode}
\newcommand*\npnodigits{\nprt@mantissa@fixeddigitsfalse}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npexponentdigits}
% 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}
\newif\ifnprt@exponent@fixeddigits
\newcommand*\npexponentdigits[2][0]{%
\edef\nprt@exponent@fixeddigits@before{#2}%
\edef\nprt@exponent@fixeddigits@after{#1}%
\nprt@exponent@fixeddigitstrue
}
% \end{macrocode}
% Initialize the numbers.
% \begin{macrocode}
\def\nprt@exponent@fixeddigits@before{-1}%
\def\nprt@exponent@fixeddigits@after{-1}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoexponentdigits}
% Switch back to normal printing.
% \begin{macrocode}
\newcommand*\npnoexponentdigits{\nprt@exponent@fixeddigitsfalse}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Error and warning messages}
%
% Define a boolean which helps \cs{numprint} to detect errors.
% \begin{macrocode}
\newif\ifnprt@argumenterror
% \end{macrocode}
% \begin{macro}{\nprt@error}
% Define \cs{nprt@error\marg{Message}\marg{Help text}} which prints
% a warning resp.\ an error message, depending on the package options
% |warning| and |error|.
% \begin{macrocode}
\newcommand\nprt@error[2]{%
\ifnprt@errormessage
\PackageError{numprint}{#1}{#2}%
\else
\PackageWarning{numprint}{#1}%
\fi
% \end{macrocode}
% The boolean is set to ``true''.
% Then, \cs{numprint} knows that an error occured.
% \begin{macrocode}
\nprt@argumenterrortrue
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{String parsing}
%
% \changes{1.10}{2003/10/12}{Avoid use of \texttt{substr} package}%
% The \cs{IfCharInString} package does not work in the tabular
% alignment context.
% Thus, define an own command \cs{nprt@IfCharInString} that does the
% same.
% \begin{macro}{\nprt@charfound}
% \begin{macrocode}
\newif\ifnprt@charfound
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@IfCharInString}
% ????
% \begin{macrocode}
\newcommand*\nprt@IfCharInString[2]{%
\nprt@charfoundfalse
\begingroup
\def\nprt@searchfor{#1}%
\edef\nprt@argtwo{#2}%
\expandafter\nprt@@IfCharInString\nprt@argtwo\@empty\@empty
\endgroup
\ifnprt@charfound
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@@IfCharInString}
% ????
% \begin{macrocode}
\def\nprt@@IfCharInString#1#2\@empty{%
\def\nprt@argone{#1}%
\edef\nprt@argtwo{#2}%
\ifx\nprt@searchfor\nprt@argone
\global\nprt@charfoundtrue
\else
\ifx\nprt@argtwo\@empty
\else
\nprt@@IfCharInString#2\@empty
\fi
\fi
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Parsing of the \textmd{\cs{numprint}} argument}
%
% \begin{macro}{\nprt@plus@test}
% \begin{macro}{\nprt@minus@test}
% \begin{macro}{\nprt@plusminus@test}
% Define the signs as commands. This is necessary to be able to
% compare them with other characters.
% \begin{macrocode}
\newcommand*\nprt@plus@test{+}
\newcommand*\nprt@minus@test{-}
\newcommand*\nprt@plusminus@test{\pm}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\nprt@numberlist}
% \begin{macro}{\nprt@dotlist}
% \begin{macro}{\nprt@epxlist}
% \begin{macro}{\nprt@signlist}
% Define lists of valid characters for different elements of numbers
% for parsing the mandatory argument of the \cs{numprint} command.
% It has nothing to do with the output.
% \cs{nprt@numberlist} contains digits, \cs{nprt@dotlist} valid
% decimal signs, \cs{nprt@explist} the characters that start the
% exponent, and \cs{nprt@signlist} the valid signs, where
% ``\texttt{+-}'' as alias for ``\cs{pm}'' does not have to be
% specified seperately.
% \begin{macrocode}
\newcommand*\nprt@numberlist{0123456789}
\newcommand*\nprt@dotlist{.,}
\newcommand*\nprt@explist{eEdD}
\newcommand*\nprt@signlist{+-\pm}
\newcommand*\nprt@ignorelist{}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% Counters for the number of digits before and after the decimal sign
% of the mantissa.
% \begin{macrocode}
\newcounter{nprt@mantissa@digitsbefore}%
\newcounter{nprt@mantissa@digitsafter}%
% \end{macrocode}
% Counters for the number of digits before and after the decimal sign
% of the exponent.
% \begin{macrocode}
\newcounter{nprt@exponent@digitsbefore}%
\newcounter{nprt@exponent@digitsafter}%
% \end{macrocode}
% Boolean to store if an exponent will be printed.
% \begin{macrocode}
\newif\ifnprt@expfound
% \end{macrocode}
% Boolean to store if mantissa resp.\ exponent contain a decimal
% sign.
% \begin{macrocode}
\newif\ifnprt@mantissa@decimalfound
\newif\ifnprt@exponent@decimalfound
% \end{macrocode}
% \begin{macro}{\nprt@testsign}
% Define \cs{nprt@testsign\marg{Number type}\marg{Number}} which tests
% wheather a sign is given and then starts \cs{nprt@testnumber} (the
% call actually is done by \cs{nprt@@testsign}).
% \begin{macrocode}
\newcommand*\nprt@testsign[2]{%
% \end{macrocode}
% First, store the expanded arguments in macros.
% \begin{macrocode}
\edef\nprt@commandname{#1}%
\edef\nprt@tmp{#2}%
% \end{macrocode}
% Call the working command \cs{nprt@@testsign}.
% The large number of \cs{expandafter} calls is necessary to ensure
% that the second to fourth argument are already expanded (thus, |#2|
% and |#3| are single characters).
% Append enough \cs{@empty} to ensure the argument-end marker is found
% even for an empty number.
% \begin{macrocode}
\expandafter\nprt@@testsign\expandafter{%
\expandafter\nprt@commandname\expandafter}%
\nprt@tmp\@empty\@empty\@empty\@empty
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@@testsign}
% The first argument is the Number type (``mantissa'' or
% ``exponent'').
% Because it is longer than one character, it has to be enclosed in
% braces when calling this function (see the previous code line).
% The arguments |#2| to |#4| are the given number, where |#2| and |#3|
% contain of the first resp.\ second character of the number, while
% |#4| contains the rest.
% \begin{macrocode}
\def\nprt@@testsign#1#2#3#4\@empty{%
% \end{macrocode}
% Store the first argument to a macro.
% \begin{macrocode}
\edef\nprt@commandname{#1}%
% \end{macrocode}
% Define the macros that store the digits before respectivly after the
% decimal sign.
% They are filled digit by digit and start empty.
% \begin{macrocode}
\expandafter\xdef\csname nprt@#1@before\endcsname{\@empty}%
\expandafter\xdef\csname nprt@#1@after\endcsname{\@empty}%
% \end{macrocode}
% Yet, no digits are stored.
% \begin{macrocode}
\setcounter{nprt@#1@digitsbefore}{0}%
\setcounter{nprt@#1@digitsafter}{0}%
% \end{macrocode}
% Test wheather the first character of the number, |#2|, contains a
% sign symbol which is listed in \cs{nprt@signlist}.
% \begin{macrocode}
\nprt@IfCharInString{#2}{\nprt@signlist}{%
% \end{macrocode}
% If yes, store that sign in the command
% \cs{nprt@\meta{\#2}@sign}.
% \begin{macrocode}
\expandafter\xdef\csname nprt@#1@sign\endcsname{#2}%
% \end{macrocode}
% If the sign is a ``+'' the second character of the number may be a
% ``-'' to replace that combination by \cs{pm}.
% Thus, do an extra handling of that case.
% \begin{macrocode}
\expandafter\ifx\csname nprt@#1@sign\endcsname\nprt@plus@test
\def\nprt@tmp{#3}%
\ifx\nprt@tmp\nprt@minus@test
% \end{macrocode}
% The second character, |#3|, \emph{is} a ``-'', thus redefine
% \cs{nprt@\meta{\#2}@sign} to \cs{pm}.
% \begin{macrocode}
\expandafter\xdef\csname nprt@#1@sign\endcsname{+-}%
% \end{macrocode}
% The digits start at the third character of the number string which
% is |#4|.
% Start \cs{nprt@testnumber} to parse the digits of the number if a
% number is given after the given sign ``+-''.
% If not, empty \cs{nprt@\meta{\#1}} that \cs{numprint} can determine
% that only a sign has been given.
% \begin{macrocode}
\def\nprt@tmp{#4}%
\ifx\nprt@tmp\@empty
\expandafter\edef\csname nprt@#1\endcsname{\@empty}%
\else
\expandafter\nprt@testnumber\expandafter\nprt@commandname#4\@empty
\fi
\else
% \end{macrocode}
% If there is a single sign character ``+'', the digits start at |#3|.
% Start \cs{nprt@testnumber} to parse the digits of the number if a
% number is given after the given sign ``+''.
% If not, empty \cs{nprt@\meta{\#1}} that \cs{numprint} can determine
% that only a sign has been given.
% \begin{macrocode}
\ifx#3\@empty
\expandafter\edef\csname nprt@#1\endcsname{\@empty}%
\else
\expandafter\nprt@testnumber\expandafter\nprt@commandname#3#4\@empty
\fi
\fi
\else
% \end{macrocode}
% If the sign is a ``\cs{pm}'' store ``\texttt{+-} as sign.
% \begin{macrocode}
\expandafter\ifx\csname nprt@#1@sign\endcsname\nprt@plusminus@test
\expandafter\xdef\csname nprt@#1@sign\endcsname{+-}%
\fi
% \end{macrocode}
% If there is a single sign character other than ``+'', the digits
% start at |#3|.
% Start \cs{nprt@testnumber} to parse the digits of the number if a
% number is given after the given sign.
% If not, empty \cs{nprt@\meta{\#1}} that \cs{numprint} can determine
% that only a sign has been given.
% \begin{macrocode}
\ifx#3\@empty
\expandafter\edef\csname nprt@#1\endcsname{\@empty}%
\else
\expandafter\nprt@testnumber\expandafter\nprt@commandname#3#4\@empty
\fi
\fi
}{%
% \end{macrocode}
% If there is no sign, set \cs{nprt@\meta{\#2}@sign} empty.
% \begin{macrocode}
\expandafter\xdef\csname nprt@#1@sign\endcsname{\@empty}%
% \end{macrocode}
% The digits start at |#2|.
% Start \cs{nprt@testnumber} to parse the digits of the number.
% \begin{macrocode}
\expandafter\nprt@testnumber\expandafter\nprt@commandname#2#3#4\@empty
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@testnumber}
% As with \cs{nprt@@testsign}, the first argument is the Number type,
% while the second and third arguments contain the number.
% |#2| contains the first character of the remaining number string,
% |#3| the rest.
% \begin{macrocode}
\def\nprt@testnumber#1#2#3\@empty{%
% \end{macrocode}
% Store the arguments in macros.
% \begin{macrocode}
\edef\nprt@commandname{#1}%
\edef\nprt@argthree{#3}%
% \end{macrocode}
% Test wheather the current character is a valid character for a real
% number (say a digit or a decimal sign).
% \begin{macrocode}
\nprt@IfCharInString{#2}{\nprt@numberlist\nprt@dotlist}{%
% \end{macrocode}
% If this is the case, continue testing.
% If the current character is a decimal sign, set the boolean
% \cs{ifnprt@\meta{Number type}@decimalfound} that a decimal
% sign has been found.
% If this has been done before, the number contains two decimal signs
% which is not allowed, thus, generate an error message.
% \begin{macrocode}
\nprt@IfCharInString{#2}{\nprt@dotlist}{%
\csname ifnprt@#1@decimalfound\endcsname
\nprt@error{More than one decimal sign used}{The mantissa
or the exponent may only contain a maximum of one decimal
sign (one of the list `\nprt@dotlist')}%
\else
\csname nprt@#1@decimalfoundtrue\endcsname
\fi
}{%
% \end{macrocode}
% If the current character is no decimal sign it has to be a digit.
% If the decimal sign has been found before, this digit is in the real
% part of the number.
% Then, add it at the end of the after-decimal-sign part.
% Also, increase the number of found digits.
% \begin{macrocode}
\csname ifnprt@#1@decimalfound\endcsname
\expandafter\g@addto@macro\csname nprt@#1@after\endcsname{#2}%
\advance\csname c@nprt@#1@digitsafter\endcsname by 1\relax
\else
% \end{macrocode}
% If the decimal sign has not been found before, this digit is in the
% integer part of the number.
% Then, add it at the end of the before-decimal-sign part.
% \begin{macrocode}
\expandafter\g@addto@macro\csname nprt@#1@before\endcsname{#2}%
\advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
\fi
}%
% \end{macrocode}
% If the next character is not \cs{@empty} and thus, the end of the
% number is not reached, start \cs{nprt@testnumber} resursively to
% parse the next character.
% \begin{macrocode}
\ifx\nprt@argthree\@empty
\else
\expandafter\nprt@testnumber\expandafter\nprt@commandname#3\@empty
\fi
}{%
% \end{macrocode}
% The current character is neither a digit nor a decimal sign.
% Thus, it is a invalid character; produce an error message.
% \begin{macrocode}
\nprt@error{Invalid number format. Printing the
argument\MessageBreak
verbatim}{Something is wrong in the format of the number}%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@testcharacter}
% This macro parses the whole mandatory argument of \cs{numprint}.
% This means it is tested on invalid characters and on a mantissa and
% an exponent.
% The first argument is the current character while |#2| is the rest
% of the argument, not parsed yet.
% \begin{macrocode}
\def\nprt@testcharacter#1#2\@empty{%
% \end{macrocode}
% Store the second argument to a macro.
% \begin{macrocode}
\edef\nprt@argtwo{#2}%
% \end{macrocode}
% Test wheather the current character is a valid one.
% \begin{macrocode}
\nprt@IfCharInString{#1}{%
\nprt@numberlist\nprt@dotlist\nprt@explist\nprt@signlist\nprt@ignorelist}{%
% \end{macrocode}
% Yes, it is valid.
%
% Now, test wheather it is one of the ignored characters.
% \begin{macrocode}
\nprt@IfCharInString{#1}{\nprt@ignorelist}{%
\nprt@debug{Character `\noexpand#1' ignored}%
}{%
% \end{macrocode}
% Yes, it is valid.
%
% Now, test wheather it is one of the characters that start the
% exponent.
% If yes, set \cs{ifnprt@expfound} to ``true''.
% If in addition, this has been done before, you have used more than
% one exponent starting character; produce an error message.
% \begin{macrocode}
\nprt@IfCharInString{#1}{\nprt@explist}{%
\ifnprt@expfound
\nprt@error{Character for exponent (`\nprt@explist') used
more than once}{The argument of \string\numprint\space may
only contain one of following characters: `\nprt@explist'}%
\fi
\nprt@expfoundtrue
}{%
% \end{macrocode}
% If the current character is not an exponent-starting character it
% is either a part of the mantissa or the exponent, depending on
% wheather the exponent has been started before.
% Add the current character to the corresponding command that stores
% the mantissa resp.\ the exponent.
% \begin{macrocode}
\ifnprt@expfound
\g@addto@macro\nprt@exponent{#1}%
\else
\g@addto@macro\nprt@mantissa{#1}%
\fi
}%
}%
% \end{macrocode}
% If we have not reached the end of the argument, call
% \cs{nprt@testcharacter} recursively.
% \begin{macrocode}
\ifx\nprt@argtwo\@empty
\else
\nprt@testcharacter#2\@empty\@empty\@empty
\fi
}{%
% \end{macrocode}
% If the character is not valid produce an error message.
% \begin{macrocode}
\nprt@error{Invalid characters `#1' in mandatory argument
of\MessageBreak
\string\numprint. Allowed are\MessageBreak
`\nprt@numberlist\nprt@dotlist\nprt@explist\nprt@signlist\nprt@ignorelist'}{%
You may only use the specified characters in the argument.}%
}%
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Table alignment}
%
% \subsubsection{Aligned numbers, also for ordinary text}
%
% Define some lengths that help to calculate the width of a number.
% \begin{macrocode}
\newlength{\nprt@digitwidth}%
\newlength{\nprt@sepwidth}%
\newlength{\nprt@decimalwidth}%
\newlength{\nprt@blockwidth}%
% \end{macrocode}
% \begin{macro}{\nprt@calcblockwidth}
% Define \cs{nprt@calcblockwidth\marg{Number
% type}\marg{Position}\marg{Math mode}}, where
% \meta{Number type} is either ``mantissa'' or ``exponent'',
% \meta{Position} is the position relative to the decimal sign
% (``before'' or ``after''), \meta{Math mode} is a math mode command
% (\cs{displaystyle}, \cs{textstyle}, \cs{scriptstyle}, or
% \cs{scriptscriptstyle}).
%
% This macro calculates the width of a block if aligned output is
% requested.
% The resulted width is stored in the length \cs{nprt@blockwidth}.
% \begin{macrocode}
\newcommand*\nprt@calcblockwidth[3]{%
% \end{macrocode}
% Store the arguments in macros.
% \begin{macrocode}
\edef\nprt@argone{#1}%
\edef\nprt@argtwo{#2}%
\edef\nprt@argthree{#3}%
% \end{macrocode}
% Define a macro with the contents ``mantissa'' to be able to compare
% it.
% \begin{macrocode}
\edef\nprt@mantissaname{mantissa}%
% \end{macrocode}
% Define a macro with the contents ``after'' to be able to compare
% it.
% \begin{macrocode}
\edef\nprt@aftername{after}%
% \end{macrocode}
% If the width for the mantissa is to be calculated, enter this code
% part.
% \begin{macrocode}
\ifx\nprt@argone\nprt@mantissaname
% \end{macrocode}
% The width of the digits and separators changes between text and
% math mode.
% If math mode is active, proceed here.
% \begin{macrocode}
\ifmmode
% \end{macrocode}
% Calculate the width of digits.
% It is assumed that all digits have the same width as a zero.
% First, execute parameter \verb|#3| to switch to the current math
% style.
% This is be done that way since it is not possible to export length
% values from \cs{mathchoice}.
% \begin{macrocode}
\settowidth{\nprt@digitwidth}{$#3%
0$}%
% \end{macrocode}
% Calculate the width of the separators.
% This may differ from before and after the decimal sign.
% \begin{macrocode}
\settowidth{\nprt@sepwidth}{$#3%
\csname nprt@separator@#2\endcsname$}%
% \end{macrocode}
% Calculate the width of the decimal sign.
% \begin{macrocode}
\settowidth{\nprt@decimalwidth}{$#3%
\nprt@decimal$}%
\else
% \end{macrocode}
% Do the same for text mode.
% \begin{macrocode}
\settowidth{\nprt@digitwidth}{0}%
\settowidth{\nprt@sepwidth}{\csname nprt@separator@#2\endcsname}%
\settowidth{\nprt@decimalwidth}{\nprt@decimal}%
\fi
% \end{macrocode}
% The same for the exponent.
% \begin{macrocode}
\else
\ifmmode
\settowidth{\nprt@digitwidth}{$#3%
{}^{0}$}%
\settowidth{\nprt@sepwidth}{$#3%
{}^{\csname nprt@separator@#2\endcsname}$}%
\settowidth{\nprt@decimalwidth}{$#3%
{}^{\nprt@decimal}$}%
\else
\settowidth{\nprt@digitwidth}{\textsuperscript{0}}%
\settowidth{\nprt@sepwidth}{%
\textsuperscript{\csname nprt@separator@#2\endcsname}}%
\settowidth{\nprt@decimalwidth}{\textsuperscript{\nprt@decimal}}%
\fi
\fi
% \end{macrocode}
% Output to the log file.
% \begin{macrocode}
\nprt@debug{Widths for #1 #2 decimal sign
(\ifx\nprt@argthree\@empty text mode\else math mode #3\fi):\MessageBreak
digits \the\nprt@digitwidth,
separators \the\nprt@sepwidth,\MessageBreak
decimal sign \the\nprt@decimalwidth}%
% \end{macrocode}
% Produce a warning if the current number exceeds the reserved space.
% Signs ($+-\pm$) are not taken into account.
% \begin{macrocode}
\ifnum\csname nprt@#1@fixeddigits@#2\endcsname<%
\csname thenprt@#1@digits#2\endcsname
\PackageWarning{numprint}{#1 exceeds reserved space
#2\MessageBreak
decimal sign}%
\fi
% \end{macrocode}
% \changes{1.34}{2004/12/13}{Fix a bug invoked in version~1.33. Found
% by Stefan Salewski}%
% Calculate the width of the given number of digits without
% separators.
% \begin{macrocode}
\setlength{\nprt@blockwidth}{%
\csname nprt@#1@fixeddigits@#2\endcsname\nprt@digitwidth}%
% \end{macrocode}
% Calculate how many separators are put into the number.
% \begin{macrocode}
\setcounter{nprt@blockcnt}{\csname nprt@#1@fixeddigits@#2\endcsname}%
\advance\c@nprt@blockcnt by -1\relax
\divide\c@nprt@blockcnt 3%
% \end{macrocode}
% If four-digit length numbers are not separated, delete the number of
% separators again.
% \begin{macrocode}
\ifnprt@numsepfour
\else
\ifnum\csname nprt@#1@fixeddigits@before\endcsname<5
\ifnum\csname nprt@#1@fixeddigits@after\endcsname<5
\setcounter{nprt@blockcnt}{0}%
\fi
\fi
\fi
% \end{macrocode}
% Add the width of the separators to the width.
% \begin{macrocode}
\addtolength{\nprt@blockwidth}{\thenprt@blockcnt\nprt@sepwidth}%
% \end{macrocode}
% Add the width of the decimal sign to the width if it is after the
% decimal sign and there shall be digits after the decimal sign.
% \begin{macrocode}
\ifx\nprt@argtwo\nprt@aftername
\expandafter\ifnum\csname nprt@#1@fixeddigits@after\endcsname>0
\addtolength{\nprt@blockwidth}{\the\nprt@decimalwidth}%
\fi
\fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\npunit}
% The \cs{npunit} command takes as argument a unit that is printed in
% every cell of a table when using the (new) |n| or |N| column types.
% \begin{macrocode}
\newcommand*\npunit[1]{\def\nprt@unit{#1}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npnounit}
% Initialize \cs{nprt@unit}.
% \begin{macrocode}
\edef\nprt@unit{\@empty}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\npafternum}
% The \cs{npunit} command takes as argument some text that is printed
% after the number in every cell of a table when using the (new) |n|
% or |N| column types.
% \begin{macrocode}
\newcommand*\npafternum[1]{\def\nprt@afternum{#1}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@afternum}
% Initialize \cs{nprt@afternum}.
% \begin{macrocode}
\edef\nprt@afternum{\@empty}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npmakebox}
% \changes{1.10}{2003/10/12}{Declare \cs{npmakebox} command}%
% The \cs{npmakebox} is similar to the \cs{makebox} command but it
% takes a text as first optional argument instead of a length.
% The width of the box is calculated by the width of this text.
% \begin{macrocode}
\DeclareRobustCommand*\npmakebox{%
\@ifnextchar[% ]
{\nprt@makebox}{\makebox}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@makebox}
% The internal part of the \cs{npmakebox} command.
% \begin{macrocode}
\newcommand*\nprt@makebox{}
\def\nprt@makebox[#1]{%
\settowidth\@tempdima{#1}%
\makebox[\@tempdima]%
}
% \end{macrocode}
% \end{macro}
%
% \changes{1.10}{2003/10/12}{Define math version \texttt{npbold}}%
% Declare a bold math alphabet |npbold| that aligns with normal
% digits.
% \begin{macrocode}
\ifnprt@npbold
\DeclareMathVersion{npbold}
\SetSymbolFont{operators}{npbold}{OT1}{cmr} {b}{n}
\SetSymbolFont{letters} {npbold}{OML}{cmm} {b}{it}
\SetSymbolFont{symbols} {npbold}{OMS}{cmsy}{b}{n}
\SetMathAlphabet\mathsf{npbold}{OT1}{cmss}{b}{n}
\SetMathAlphabet\mathit{npbold}{OT1}{cmr}{b}{it}
% \end{macrocode}
% \begin{macro}{\npboldmath}
% Switch to that bold math alphabet.
% \begin{macrocode}
\def\npboldmath{\@nomath\npboldmath
\mathversion{npbold}}
\fi
% \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Auxilliary routines for the new column types}
%
% This code has been developed starting from the \texttt{rccol}
% package by Eckhart Guth\"ohrlein~\cite{guthoehrlein2000a}.
% Some small bugs of that package have been corrected here, too.
%
% \begin{macro}{\nprt@digittoks}
% Token list that will contain all characters of a tabular cell that
% are allowed for \cs{numprint}.
% \begin{macrocode}
\newtoks\nprt@digittoks
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@pretoks}
% Token list with all tokens before the number itself.
% \begin{macrocode}
\newtoks\nprt@pretoks
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@posttoks}
% Token list with all tokens after the number itself.
% \begin{macrocode}
\newtoks\nprt@posttoks
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifnprt@numfound}
% Has the number already been found in the parsing of the tabular
% cell?
% \begin{macrocode}
\newif\ifnprt@numfound
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@begin}
% This macro is executed at the begin of each tabular cell.
% \begin{macrocode}
\def\nprt@begin{%
% \end{macrocode}
% Initialize the tokens and macros.
% \begin{macrocode}
\nprt@digittoks={}%
\nprt@pretoks={}%
\nprt@posttoks={}%
\edef\nprt@unit{\@empty}%
\edef\nprt@afternum{\@empty}%
\nprt@numfoundfalse
% \end{macrocode}
% Set the allowed characters.
% This macro is made empty when the number itself is read-in totally.
% \begin{macrocode}
\edef\nprt@allowedchars{\nprt@numberlist\nprt@dotlist\nprt@explist
\nprt@signlist\nprt@ignorelist}%
% \end{macrocode}
% Start to parse the tabular cell.
% \begin{macrocode}
\nprt@getnexttok
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@saveothertok}
% Adds the current token to the list of tokens before or after the
% number.
% \begin{macrocode}
\def\nprt@saveothertok#1{%
\ifnprt@numfound
% \end{macrocode}
% If the number has already been found it is ended now.
% This is marked by clearing the list of allowed characters.
% \begin{macrocode}
\def\nprt@allowedchars{}%
\nprt@posttoks=\expandafter{\the\nprt@posttoks#1}%
\else
\nprt@pretoks=\expandafter{\the\nprt@pretoks#1}%
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@getnexttok}
% \changes{1.31}{2004/08/18}{Bugfix: The numprint column types did not
% like empty cells in the last column of a tabular}%
% Parse the tabular cell.
% The argument is the next token of the tabular cell.
% Inside this command, the end of the tabular cell is detected by
% different possibilities to end a cell.
% \begin{macrocode}
\def\nprt@getnexttok#1{%
% \end{macrocode}
% If the current token is \cs{tabularnewline} or |\\|
% (which is the same) the tabular cell is finished.
% \begin{macrocode}
\ifx\tabularnewline#1%
% \end{macrocode}
% Redefine the \cs{nprt@next} command that is called at the end of
% this command to execute the found \cs{tabularnewline} command.
% \begin{macrocode}
\let\nprt@next\tabularnewline
\else
% \end{macrocode}
% If this tabular cell is not in the last column and a |&| is found,
% the \cs{nprt@end} command is found that is inserted into this cell
% using the |<| specifier by the columnn types.
% \begin{macrocode}
\ifx\end#1%
% \end{macrocode}
% Redefine \cs{nprt@next} to execute \cs{nprt@end} at the end of this
% command.
% \begin{macrocode}
\let\nprt@next\end
\else
% \end{macrocode}
% If this is the last cell of the tabular, the \cs{end} part of
% \cs{end\{tabular\}} or \cs{end\{tabular*\}} is found.
% \begin{macrocode}
\ifx\nprt@end#1%
% \end{macrocode}
% Test wheather it is the normal or the star version of the
% environment.
% Is this really necessary?
% \begin{macrocode}
\let\nprt@next\nprt@end
\else
% \end{macrocode}
% If this is the last cell of the tabular and the tabular has been
% called using \cs{tabular} \ldots\ \cs{endtabular} instead of using
% the environment call, \cs{endtabular} is found.
% \begin{macrocode}
\ifx\endtabular#1%
\let\nprt@next\endtabular
\else
% \end{macrocode}
% For |tabularx|, a test on \cs{csname} has to be added.
% \begin{macrocode}
\ifx\csname#1%
\let\nprt@next\csname
\else
% \end{macrocode}
% If the last cell of a line is empty, \cs{relax} will be found.
% \begin{macrocode}
\ifx\relax#1%
\let\nprt@next\relax
\else
% \end{macrocode}
% If no command is found that ends the tabular cell, we are not yet at
% the end of the cell.
% Redefine \cs{nprt@next} to start this command recursively for
% parsing the next token.
% \begin{macrocode}
\let\nprt@next\nprt@getnexttok
% \end{macrocode}
% Test if this token is one of the allowed characters of a number.
% \begin{macrocode}
\nprt@IfCharInString{#1}{\nprt@allowedchars}{%
% \end{macrocode}
% If yes, append this character to the token list of the number and
% set the flag that the number has been found.
% \begin{macrocode}
\nprt@numfoundtrue
\nprt@digittoks=\expandafter{\the\nprt@digittoks#1}%
}{%
% \end{macrocode}
% If it is no character of a number, store it for the tokens before or
% after the number.
% \begin{macrocode}
\nprt@saveothertok{#1}%
}%
\fi % \relax
\fi % \csname
\fi % \endtabular
\fi % \nprt@end
\fi % \end
\fi % \tabularnewline
% \end{macrocode}
% Call the previously saved command (recursion or end of the tabular
% cell).
% \begin{macrocode}
\nprt@next
}
% \end{macrocode}
% Boolean to decide if math mode is active outside the tabular cell.
% This is true for the |array| environment.
% \begin{macrocode}
\newif\ifnprt@mathtabular
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@end}
% This macro is called at the end of each tabular cell.
% The arguments are used as follows: \meta{digits before},
% \meta{digits after} the decimal sign for the mantissa;
% \meta{digits before}, \meta{digits after} the decimal sign for the
% exponent; commands inserted \meta{before} and \meta{after} the
% \cs{numprint} command.
% The arguments five and six are empty for printing the number in text
% mode and contain ``|$|'' both for printing the number in math mode.
% \begin{macrocode}
\def\nprt@end#1#2#3#4#5#6{%
% \end{macrocode}
% First, print the tokens before the number.
% \begin{macrocode}
\the\nprt@pretoks
% \end{macrocode}
% Print the number in a group in order to save the tokens before and
% after the number to be influenced by its settings.
% \begin{macrocode}
\begingroup
% \end{macrocode}
% Set the digits for the alignment of the mantissa.
% \begin{macrocode}
% \npnodigits
\npdigits{#1}{#2}%
% \end{macrocode}
% Set the digits for the alignment of the exponent if given.
% If no number of digits is given, they are set negativ.
% \begin{macrocode}
\npnoexponentdigits
\ifnum#3<0
\nprt@debug{no exponent alignment in tabular}%
\else
\ifnum#4<0
\nprt@debug{exponent alignment in tabular with #3 digits}%
\npexponentdigits{#3}%
\else
\nprt@debug{exponent alignment in tabular with #3.#4 digits}%
\npexponentdigits[#4]{#3}%
\fi
\fi
% \end{macrocode}
% Omit the section that prints the number if no number has been
% given.
% \begin{macrocode}
\ifnprt@numfound
% \end{macrocode}
% Print the pre-command if defined.
% Since the pre-command is fixed to nothing or ``|$|'' to switch to
% math mode, this is only done if the math mode is not active,
% before.
% Set the boolean \cs{ifnprt@mathtabular} according to the previous
% status in order to close the math mode if necessary.
% \begin{macrocode}
\ifmmode
\nprt@mathtabulartrue
\else
\nprt@mathtabularfalse
#5%
\fi
% \end{macrocode}
% Print the number, with unit if one has been given.
% \begin{macrocode}
\ifx\nprt@unit\@empty
\numprint{\the\nprt@digittoks}%
\else
\numprint[\nprt@unit]{\the\nprt@digittoks}%
\fi
% \end{macrocode}
% Switch off math mode if it has not been active before.
% \begin{macrocode}
\ifnprt@mathtabular
\else
#6%
\fi
% \end{macrocode}
% Print a message to the log file if no number has been specified.
% \begin{macrocode}
\else
\PackageInfo{numprint}{No number in tabular cell}%
\fi
% \end{macrocode}
% Do the rest outside the group in order to prevent the post-texts
% from being formatted as the number.
% \begin{macrocode}
\endgroup
% \end{macrocode}
% Print the tokens after the number.
% \begin{macrocode}
\the\nprt@posttoks
% \end{macrocode}
% Print the contents defined with \cs{npafternum}.
% \begin{macrocode}
\ifx\nprt@afternum\@empty
\else
\nprt@afternum
\fi
}
% \end{macrocode}
% \end{macro}
%
%
% \subsubsection{New column types}
% \changes{1.10}{2003/10/12}{New tabular alignment mechanism}%
%
% Define the new column types.
% \begin{macrocode}
\ifnprt@newcolumntype
% \end{macrocode}
%
% Declare a new column type |N| which prints a number in text mode and
% does not need to repeat \cs{numprint} in each tabular cell.
% This is declared empty because all executing macros are redefined
% anyway.
% \begin{macrocode}
\newcolumntype{N}{}
% \end{macrocode}
% \begin{macro}{\NC@rewrite@N}
% Redefine this command to parse the declaration of the |N| column
% type to look for an optional argument.
% If none is given, set both optional arguments to ``|-1|''.
% \begin{macrocode}
\def\NC@rewrite@N{%
\nprt@digittoks{}%
\nprt@pretoks{}%
% \end{macrocode}
% If no optional argument is given, set both optional arguments to
% ``|-1|''.
% \begin{macrocode}
\@ifnextchar[{% ]
\nprt@rewrite@{}{}%
}{%
\nprt@rewrite@@{}{}{-1}[-1]%
}%
}
% \end{macrocode}
% \end{macro}
% Declare a new column type |n| which prints a number and does not
% need to repeat \cs{numprint} in each tabular cell.
% This is declared empty because all executing macros are redefined
% anyway.
% \begin{macrocode}
\newcolumntype{n}{}
% \end{macrocode}
% \begin{macro}{\NC@rewrite@n}
% Same as \cs{NC@rewrite@N}, but give ``|$|'' twice for math mode.
% \begin{macrocode}
\def\NC@rewrite@n{%
\nprt@digittoks{}%
\nprt@pretoks{}%
\@ifnextchar[{% ]
\nprt@rewrite@{$}{$}%
}{%
\nprt@rewrite@@{$}{$}{-1}[-1]%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@rewrite@}
% Look for the second optional argument.
% \begin{macrocode}
\def\nprt@rewrite@#1#2[#3]{%
\@ifnextchar[{%]
\nprt@rewrite@@{#1}{#2}{#3}%
}{%
\nprt@rewrite@@{#1}{#2}{#3}[-1]%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@rewrite@@}
% The arguments are used as follows:
% commands inserted \meta{before} and \meta{after} the
% \cs{numprint} command; \meta{digits before}, \meta{digits after} the
% decimal sign for the mantissa; \meta{digits before}, \meta{digits
% after} the decimal sign for the exponent.
% \begin{macrocode}
\def\nprt@rewrite@@#1#2#3[#4]#5#6{%
% \end{macrocode}
% Add the definition for the current column to the already made column
% definitions that are stored in \cs{@temptokena}.
% Before the column itself, the starting command for the parsing,
% \cs{nprt@begin}, is inserted.
% At the end of the column, start the final work, command
% \cs{nprt@end}.
% These commands shall not be expanded, yet.
% \begin{macrocode}
\edef\nprt@rewrite@scratch{\the\@temptokena
>{\noexpand\nprt@begin\noexpand\ignorespaces}l%
<{\noexpand\nprt@end{#5}{#6}{#3}{#4}{#1}{#2}}%
}%
% \end{macrocode}
% Set \cs{@temptokena} to the preceding and the current column
% definition.
% This is implicitely used by the |array| package.
% \begin{macrocode}
\@temptokena\expandafter{\nprt@rewrite@scratch}%
% \end{macrocode}
% Parse for next column in the definition.
% \begin{macrocode}
\NC@find
}
% \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Old column types for compatibility}
%
% Define the old column types.
% \begin{macrocode}
\else
% \end{macrocode}
% The column type \verb|n| aligns the base number but not the exponent.
% \begin{macrocode}
\newcolumntype{n}[2]{>{\npdigits{#1}{#2}$}l<{$}}
% \end{macrocode}
% The column type \verb|N| aligns the base number as well as the exponent.
% \begin{macrocode}
\newcolumntype{N}[3]{%
>{\npdigits{#1}{#2}\npexponentdigits{#3}$}l<{$}%
}
% \end{macrocode}
% End of column type section.
% \begin{macrocode}
\fi
% \end{macrocode}
%
%
% \subsection{Round numbers}%
% \label{sec:code:round}%
%
% Stores if the currenct digit has to be rounded up.
% \begin{macrocode}
\newif\ifnprt@roundup
% \end{macrocode}
% Declare the counter used inside \cs{nprt@round@after} and
% \cs{nprt@round@before}.
% \begin{macrocode}
\newcount\nprt@thisdigit
% \end{macrocode}
% \begin{macro}{\nprt@round@after}
% Does the rounding of the number after the decimal sign.
% The first argument contains the current digit, the second the rest
% of the number.
%
% This routine is a little bit complicated.
% It is called recursively.
% In the forward rund, it just counts the number of digits, it has
% parsed already.
% In the backward rund the rounding is done.
% \begin{macrocode}
\def\nprt@round@after#1#2\@empty{%
% \end{macrocode}
% Store the arguments in macros.
% \begin{macrocode}
\edef\nprt@argone{#1}%
\edef\nprt@argtwo{#2}%
% \end{macrocode}
% Count the parsed digits.
% \begin{macrocode}
\advance \nprt@curpos by 1
% \end{macrocode}
% If the end of the number is reached an internal error has been
% occured since enough zeros are appended to the number before.
% \begin{macrocode}
\ifx\nprt@argone\@empty
\nprt@error{Rounding: End of number has been reached}{This may
not happen}%
\else
% \end{macrocode}
% If the current digit is one behind the last digit to be printed it
% decides if the last printed digit is rounded or not.
% This decision is stored in \cs{ifnprt@roundup}.
% If this position is reached, stop the recursion.
% \begin{macrocode}
\ifnum\nprt@curpos>\nprt@rndpos
\ifnum\nprt@argone>4
\nprt@rounduptrue
\fi
\else
% \end{macrocode}
% The position has not been reached, yet.
% Thus, call this routine recursively.
% \begin{macrocode}
\expandafter\nprt@round@after#2\@empty\@empty
% \end{macrocode}
% The following lines are executed in the backward run when rounding.
%
% Store the current digit in a number in order to be able to calculate
% with it.
% \begin{macrocode}
\nprt@thisdigit=#1
% \end{macrocode}
% If this number is to be rounded up do it by advancing it by one.
% \begin{macrocode}
\ifnprt@roundup
\advance \nprt@thisdigit by 1
% \end{macrocode}
% Reset \cs{ifnprt@roundup} since the preceeding digit is not to be
% rounded, normally.
% \begin{macrocode}
\nprt@roundupfalse
% \end{macrocode}
% If the digit has been rounded from 9 to 10, it has to be a ``0'' and
% the preceeding digit has to be rounded up.
% \begin{macrocode}
\ifnum\nprt@thisdigit=10
\nprt@thisdigit=0
\nprt@rounduptrue
\fi
\fi
% \end{macrocode}
% Store the modificated current digit to the new number by putting it
% into \cs{nprt@newnum} before all digits that have been stored
% before.
% \begin{macrocode}
\expandafter\xdef\expandafter\nprt@newnum{%
\the\nprt@thisdigit\nprt@newnum}%
\fi
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@round@before}
% Does the rounding of the number after the decimal sign.
% The first argument contains the current digit, the second the rest
% of the number.
% This routine works as \cs{nprt@round@after} but stops at its end in
% contrast to a given number.
% \begin{macrocode}
\def\nprt@round@before#1#2\@empty{%
% \end{macrocode}
% Store the arguments.
% \begin{macrocode}
\edef\nprt@argone{#1}%
\edef\nprt@argtwo{#2}%
% \end{macrocode}
% Do the recursion until the end of the number.
% This routine does not have to decide wheather the number has to be
% rounded since it knows that by \cs{ifnprt@roundup}, set by
% \cs{nprt@round@after}.
% \begin{macrocode}
\ifx\nprt@argtwo\@empty
\else
\expandafter\nprt@round@before#2\@empty
\fi
% \end{macrocode}
% Store the current digit into a counter and use zero if the number
% before the decimal sign is empty.
% \begin{macrocode}
\ifx\nprt@argone\@empty
\nprt@thisdigit=0
\else
\nprt@thisdigit=#1
\fi
% \end{macrocode}
% Add one to the number if it has to be rounded.
% \begin{macrocode}
\ifnprt@roundup
\advance \nprt@thisdigit by 1
% \end{macrocode}
% Reset the rounding of the next number.
% \begin{macrocode}
\nprt@roundupfalse
% \end{macrocode}
% If rounded from 9 to 10, set this digit to ``0'' and give the
% information to the next digit.
% \begin{macrocode}
\ifnum\nprt@thisdigit=10
\nprt@thisdigit=0
\nprt@rounduptrue
\fi
\fi
% \end{macrocode}
% If the number is empty, the new number has to be added and the
% counter adjusted.
% \begin{macrocode}
\ifx\nprt@argone\@empty
\xdef\nprt@newnum{\the\nprt@thisdigit}%
% \stepcounter{nprt@\nprt@numname @digitsbefore}%
\advance\csname c@nprt@\nprt@numname @digitsbefore\endcsname 1\relax
\else
% \end{macrocode}
% Insert the current digit before the already stored digits in
% \cs{nprt@newnum}.
% \begin{macrocode}
\expandafter\xdef\expandafter\nprt@newnum{%
\the\nprt@thisdigit\nprt@newnum}%
\fi
}
% \end{macrocode}
% \end{macro}
% Two new counters for the round position and the current postion in
% \cs{nprt@round@after}.
% \begin{macrocode}
\newcount\nprt@curpos
\newcount\nprt@rndpos
% \end{macrocode}
% \begin{macro}{\nprt@round}
% Round a number.
% The first argument is the Number type (``mantissa'' resp.\
% ``exponent''), the second is the number of digits to be printed
% after the decimal sign.
% \begin{macrocode}
\newcommand*\nprt@round[2]{%
\begingroup
% \end{macrocode}
% Store the Number type for use in \cs{nprt@round@before} and
% \cs{nprt@round@after}.
% \begin{macrocode}
\edef\nprt@numname{#1}%
% \end{macrocode}
% If the number of printed digits after the decimal sign is negative,
% no rounding will be performed.
% \begin{macrocode}
\ifnum#2<0
\else
% \end{macrocode}
% Print a debug message.
% \begin{macrocode}
\nprt@debug{\string\nprt@round: Round after #2 digits for #1}%
% \end{macrocode}
% Set the number of digits after the decimal sign to the given value
% since this number of digits will be printed later.
% \begin{macrocode}
\setcounter{nprt@#1@digitsafter}{#2}%
% \end{macrocode}
% Append enough zeros to the after-decimal-sign part in order to have
% enough digits that \cs{nprt@round@after} will not reach the end of
% the number.
% \begin{macrocode}
\expandafter\g@addto@macro\csname nprt@#1@after\endcsname{%
\nprt@roundnull}%
% \end{macrocode}
% Set the number of digits after the decimal sign.
% \begin{macrocode}
\nprt@rndpos=#2
% \end{macrocode}
% Default not to round.
% \begin{macrocode}
\nprt@roundupfalse
% \end{macrocode}
% Define the ``working'' number for the subroutines.
% \begin{macrocode}
\edef\nprt@tmpnum{\csname nprt@#1@after\endcsname}%
% \end{macrocode}
% The new number starts empty and will be filled by
% \cs{nprt@round@after}.
% \begin{macrocode}
\edef\nprt@newnum{}%
% \end{macrocode}
% Do the rounding after the decimal sign.
% \begin{macrocode}
\expandafter\nprt@round@after\nprt@tmpnum\@empty\@empty
% \end{macrocode}
% Copy the new number after the decimal sign to the ``official''
% command storing it.
% \begin{macrocode}
\expandafter\xdef\csname nprt@#1@after\endcsname{\nprt@newnum}%
% \end{macrocode}
% If the integer part has to be modificated, too, do it.
% \begin{macrocode}
\ifnprt@roundup
% \end{macrocode}
% Copy the number to the working number.
% \begin{macrocode}
\edef\nprt@tmpnum{\csname nprt@#1@before\endcsname}%
% \end{macrocode}
% Clear the new number.
% \begin{macrocode}
\edef\nprt@newnum{}%
% \end{macrocode}
% Do the rounding before the decimal sign.
% \begin{macrocode}
\expandafter\nprt@round@before\nprt@tmpnum\@empty\@empty
% \end{macrocode}
% If the first digit has been rounded up from 9 a new digit ``1'' has
% to be inserted before the number.
% \begin{macrocode}
\ifnprt@roundup
\expandafter\xdef\expandafter\nprt@newnum{1\nprt@newnum}%
% \stepcounter{nprt@#1@digitsbefore}%
\advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
\fi
% \end{macrocode}
% Copy the new number before the decimal sign to the ``official''
% command storing it.
% \begin{macrocode}
\expandafter\xdef\csname nprt@#1@before\endcsname{\nprt@newnum}%
\fi
\fi
\endgroup
% \end{macrocode}
% Set the boolean for a found decimal sign according to the number of
% printed decimals.
% \begin{macrocode}
\ifnum#2<0
\else
% \end{macrocode}
% If rounded to no digits after the decimal sign, switch off printing
% of it.
% \begin{macrocode}
\ifnum#2=0
\csname nprt@#1@decimalfoundfalse\endcsname
\else
% \end{macrocode}
% If one or more digits are printed, a decimal sign has to be printed.
% \begin{macrocode}
\csname nprt@#1@decimalfoundtrue\endcsname
\fi
\fi
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@lpad}
% Pad a number with a character on the left side.
% The first argument contains the number, the second is the desired length
% and the third the padding character.
% \begin{macrocode}
\newcommand*\nprt@lpad[3]{%
% \end{macrocode}
% If the count of digits is negative, no padding will be performed.
% \begin{macrocode}
\ifnum#2<0
\else
% \end{macrocode}
% Print a debug message.
% \begin{macrocode}
\nprt@debug{\string\nprt@lpad: Padding #1 with #3 to a length of #2}%
% \end{macrocode}
% If the number has less than the desired length, add the padding character
% to the left and call this function recursively.
% \begin{macrocode}
\ifnum\csname thenprt@#1@digitsbefore\endcsname<#2
\expandafter\xdef\csname nprt@#1@before\endcsname{%
#3\csname nprt@#1@before\endcsname}%
% \stepcounter{nprt@#1@digitsbefore}%
\advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
\nprt@lpad{#1}{#2}{#3}%
\fi
\fi
}%
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Print the numbers}
%
% \begin{macro}{\nprt@sign@+}
% \begin{macro}{\nprt@sign@-}
% \begin{macro}{\nprt@sign@+-}
% Define commands for printing the signs in math mode. This ensures
% that the printed signs really are signs and not hyphens. Compare
% ``-'' to ``\ensuremath{-}''.
% \begin{macrocode}
\expandafter\newcommand\csname nprt@sign@+\endcsname{\ensuremath{+}}
\expandafter\newcommand\csname nprt@sign@-\endcsname{\ensuremath{-}}
\expandafter\newcommand\csname nprt@sign@+-\endcsname{\ensuremath{\pm}}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\nprt@printsign}
% Print a sign.
% The first argument contains the number type (``mantissa'' or
% ``exponent'').
% The second argument contains the sign as in source code.
% \begin{macrocode}
\newcommand*\nprt@printsign[2]{%
% \end{macrocode}
% Write sign to log file.
% \begin{macrocode}
\nprt@debug{\string\nprt@printsign: `#2'}%
% \end{macrocode}
% Set command in a group to prevent the defined macros from being
% global.
% \begin{macrocode}
\edef\nprt@marg{#2}%
% \end{macrocode}
% If a plus is to be added do it if no sign given.
% \begin{macrocode}
\csname ifnprt@addplus@#1\endcsname
\ifx\nprt@marg\@empty
\edef\nprt@marg{+}%
\fi
\fi
% \end{macrocode}
% Do nothing if still no sign given.
% \begin{macrocode}
\ifx\nprt@marg\@empty
\else
% \end{macrocode}
% If a macro \cs{nprt@sign@\meta{sign}} is defined for the given sign,
% e.g., \cs{nprt@sign@+}, print it; if not, print the sign itself.
% \changes{1.22}{2004/08/08}{Print sign in a group to avoid additional space
% for an operator (for nbaseprt)}%
% \begin{macrocode}
\@ifundefined{nprt@sign@\nprt@marg}{%
\PackageWarning{numprint}{%
Unknown sign `\nprt@marg'. Print as typed in}%
\nprt@marg
}{%
{\csname nprt@sign@\nprt@marg\endcsname}%
}%
\fi
}
% \end{macrocode}
% \end{macro}
% Internal counters for printing.
% \begin{macrocode}
\newcounter{nprt@digitsfirstblock}
\newcounter{nprt@blockcnt}
% \end{macrocode}
% Internal boolean.
% \begin{macrocode}
\newif\ifnprt@shortnumber
% \end{macrocode}
% \begin{macro}{\nprt@printbefore}
% Print the number before the decimal sign.
% The argument is the Number type (``mantissa'' or ``exponent'').
% When this macro is called, everything is parsed already.
% Thus, it is known wheather a decimal sign has been found, which and
% how many digits are before resp.\ after the decimal sign etc.
% \begin{macrocode}
\newcommand*\nprt@printbefore[1]{%
% \end{macrocode}
% If missing zeros shall be added and there is no digit before the
% decimal sign store that ``0'' into the corresponding command and
% store in the counter that the number of digits before the decimal
% sign is one, know.
% \begin{macrocode}
\ifnprt@addmissingzero
\ifnum\csname thenprt@#1@digitsbefore\endcsname=0
\expandafter\edef\csname nprt@#1@before\endcsname{0}%
% \stepcounter{nprt@#1@digitsbefore}%
\advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
\fi
\fi
% \end{macrocode}
% I'm not sure why I have added the group here.
% But it works and I won't change it, therefore.
% \begin{macrocode}
\begingroup
% \end{macrocode}
% Store the number to be printed in \cs{nprt@numbertoprint} in order
% to have simpler calls in this routine than using \cs{csname}\ldots
% \begin{macrocode}
\edef\nprt@numbertoprint{\csname nprt@#1@before\endcsname}%
% \end{macrocode}
% If four-digit numbers are not to be separated and both, the integer
% and the real parts, are shorter than 5 digits, set the boolean
% \cs{ifnprt@shortnumber} to ``true'' that the number is printed
% without separators, later.
% \begin{macrocode}
\ifnprt@numsepfour
\else
\ifnum\csname thenprt@#1@digitsbefore\endcsname<5
\ifnum\csname thenprt@#1@digitsafter\endcsname<5
\nprt@shortnumbertrue
\fi
\fi
\fi
% \end{macrocode}
% If the number is short according to the preceeding code, just print
% that number by calling \cs{nprt@numbertoprint}.
% \begin{macrocode}
\ifnprt@shortnumber
\nprt@numbertoprint
\else
% \end{macrocode}
% If the number will get separators, calculate how many separators
% will be inserted.
% \begin{macrocode}
% ganze Bloecke
\setcounter{nprt@blockcnt}{%
\csname thenprt@#1@digitsbefore\endcsname}%
\advance\c@nprt@blockcnt by -1\relax
\divide\c@nprt@blockcnt 3%
% \end{macrocode}
% Then, calculate how many digits are in the first block (one, two, or
% three).
% Use \cs{c@nprt@cntprint} as temporary variable.
% \begin{macrocode}
\setcounter{nprt@digitsfirstblock}{%
\csname thenprt@#1@digitsbefore\endcsname}%
\setcounter{nprt@cntprint}{\thenprt@blockcnt}%
\multiply \c@nprt@cntprint 3%
\advance\c@nprt@digitsfirstblock by -\thenprt@cntprint\relax
% \end{macrocode}
% Depending on that number, call \cs{nprt@printone},
% \cs{nprt@printtwo}, resp.\ \cs{nprt@printthree} which do what you
% may expect with that names.
% \begin{macrocode}
\ifnum\thenprt@digitsfirstblock=1
\expandafter\nprt@printone\nprt@numbertoprint\@empty
\else
\ifnum\thenprt@digitsfirstblock=2
\expandafter\nprt@printtwo\nprt@numbertoprint\@empty
\else
\ifnum\thenprt@digitsfirstblock=3
\expandafter\nprt@printthree\nprt@numbertoprint\@empty
\else
\ifnum\thenprt@digitsfirstblock=0
\else
\PackageError{numprint}{internal error}{}%
\fi
\fi
\fi
\fi
\fi
\endgroup
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printthree}
% Print three digits.
% If the command has not reached the end of the string, print a
% separator \cs{nprt@separator@before} and call this routine
% recursively.
% Surprisingly, this routine does not work if |#1#2#3| is the first
% command in some cases.
% Thus, \cs{def}cs{nprt@tmp} has been moved in front of it.
% Make sure that this works in all cases.
% Same applies for \cs{nprt@printtwo}, \cs{nprt@printone}, and
% \cs{nprt@printthreeafter}.
% \begin{macrocode}
\def\nprt@printthree#1#2#3#4\@empty{%
\def\nprt@tmp{#4}%
#1#2#3%
\ifx\nprt@tmp\empty
\else
\nprt@separator@before%
\nprt@printthree#4\@empty\@empty\@empty
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printtwo}
% The same but start with two instead of three digits.
% \begin{macrocode}
\def\nprt@printtwo#1#2#3\@empty{%
\def\nprt@tmp{#3}%
#1#2%
\ifx\nprt@tmp\empty
\else
\nprt@separator@before%
\nprt@printthree#3\@empty\@empty\@empty
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printone}
% The same but start with one instead of three digits.
% \begin{macrocode}
\def\nprt@printone#1#2\@empty{%
\def\nprt@tmp{#2}%
#1%
\ifx\nprt@tmp\empty
\else
\nprt@separator@before%
\nprt@printthree#2\@empty\@empty\@empty
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printafter}
% Print the number after the decimal sign.
% The argument is the Number type (``mantissa'' or ``exponent'').
% This macro works similarly as \cs{nprt@printbefore}.
% \begin{macrocode}
\newcommand*\nprt@printafter[1]{%
% \end{macrocode}
% If a missing zero shall be added do it if no digits are given after
% the decimal sign if a decimal sign has been given.
% If no decimal sign has been given, the number is pure integer and
% does not get a real part.
% \begin{macrocode}
\csname ifnprt@#1@decimalfound\endcsname
\ifnprt@addmissingzero
\ifnum\csname thenprt@#1@digitsafter\endcsname=0
\expandafter\edef\csname nprt@#1@after\endcsname{0}%
% \stepcounter{nprt@#1@digitsafter}%
\advance\csname c@nprt@#1@digitsafter\endcsname by 1\relax
\fi
\fi
% \end{macrocode}
% If a after-decimal zero will be replaced by another command but the
% real part is empty, put a ``0'' after the comma (same as
% ``addmissingzero'', but here it is just a hack in order to enable
% the replacement command to take effect later).
% \begin{macrocode}
\ifx\nprt@replacenull\@empty
\else
\ifnum\csname thenprt@#1@digitsafter\endcsname=0
\expandafter\edef\csname nprt@#1@after\endcsname{0}%
% \stepcounter{nprt@#1@digitsafter}%
\advance\csname c@nprt@#1@digitsafter\endcsname by 1\relax
\fi
\fi
\fi
% \end{macrocode}
% Store the number in \cs{nprt@numbertoprint} and continue only if it
% is not empty.
% \begin{macrocode}
\begingroup
\edef\nprt@numbertoprint{\csname nprt@#1@after\endcsname}%
\ifx\nprt@numbertoprint\@empty
\else
% \end{macrocode}
% Find out wheather separators have to be inserted.
% \begin{macrocode}
\ifnprt@numsepfour
\else
\ifnum\csname thenprt@#1@digitsbefore\endcsname<5
\ifnum\csname thenprt@#1@digitsafter\endcsname<5
\nprt@shortnumbertrue
\fi
\fi
\fi
% \end{macrocode}
% If a zero has to be replaced by a replacement text, and if the after
% comma part has the numerical value ``0'' (= it contains of zeros
% only), do the replacement.
% \begin{macrocode}
\ifx\nprt@replacenull\@empty
\else
\ifnum\nprt@numbertoprint=0
\nprt@shortnumbertrue
\edef\nprt@numbertoprint{\nprt@replacenull}%
\fi
\fi
% \end{macrocode}
% If the number is short (without separators) just print it.
% \begin{macrocode}
\ifnprt@shortnumber
\nprt@numbertoprint
\else
% \end{macrocode}
% Print the number with separators.
% The choice between different block sizes does not have to be done
% because the after-decimal-sign part starts with three-digit block
% from the left end.
% \begin{macrocode}
\expandafter\nprt@printthree@after%
\nprt@numbertoprint\@empty\@empty\@empty
\fi
\fi
\endgroup
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printthree@after}
% The same as \cs{nprt@printthree} but with another separator.
% \begin{macrocode}
\def\nprt@printthree@after#1#2#3#4\@empty{%
\def\nprt@tmp{#4}%
#1#2#3%
\ifx\nprt@tmp\empty
\else
\nprt@separator@after
\nprt@printthree@after#4\@empty\@empty\@empty
\fi
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{The main command}%
% \label{sec:code:main}%
%
% \begin{macro}{\numprint}
% The main macro of the package.
% The mandatory argument takes a number and prints it as described
% above.
% The optional argument may contain a unit which then is printed,
% too.
% \begin{macrocode}
\DeclareRobustCommand*\numprint[2][\@empty]{%
% \end{macrocode}
% Switch off the error flag.
% This should not be necessary but is done for stability reasons.
% \begin{macrocode}
\nprt@argumenterrorfalse
% \end{macrocode}
% Clear the mantissa and the exponent.
% \begin{macrocode}
\xdef\nprt@exponent{\@empty}%
\xdef\nprt@mantissa{\@empty}%
% \end{macrocode}
% Do everything inside a group to avoid defining too many temporary
% macros that are not deleted after the macro.
% \begin{macrocode}
\begingroup
% \end{macrocode}
% Store the mandatory argument into a macro.
% Redefine \cs{,} and |~| to do nothing as to ignore them.
% Because the argument is expanded this does not work with the ignore
% list for characters.
% This again has to be done inside a group to preserve the two macros
% for later usage.
% \begin{macrocode}
\begingroup
\def\,{}%
\catcode`\~=\active % tilde is active
\def~{}%
\xdef\nprt@marg{#2}%
\endgroup
% \end{macrocode}
% Don't expand the unit because that may cause trouble.
% \begin{macrocode}
\def\nprt@oarg{#1}%
% \end{macrocode}
% Declare some commands to detect empty arguments.
% \begin{macrocode}
\def\nprt@@empty{\@empty}%
\def\nprt@nix{}%
\def\nprt@nixleer{ }%
% \end{macrocode}
% Some debug information.
% \begin{macrocode}
\ifx\nprt@oarg\nprt@@empty
\nprt@debug{\string\numprint{\protect#2}}%
\else
\nprt@debug{\string\numprint[\protect#1]{\protect#2}}%
\fi
% \end{macrocode}
% Test for an empty mandatory argument.
% \begin{macrocode}
\ifx\nprt@marg\nprt@nix
\nprt@error{empty argument}{You have to specify a number in
the argument of \string\numprint}%
\fi
\ifx\nprt@marg\nprt@nixleer
\nprt@error{empty argument}{You have to specify a number in
the argument of \string\numprint}%
\fi
% \end{macrocode}
% Test wheather only valid characters have been used and devide the
% argument in the mantissa and the exponent.
% \begin{macrocode}
\expandafter\nprt@testcharacter\nprt@marg\@empty\@empty
% \end{macrocode}
% If there are invalid characters in the argument, just print the
% argument without formatting it.
% Redefine \cs{pm} to avoid an additional error in text mode.
% \begin{macrocode}
\ifnprt@argumenterror
\begingroup\def\pm{+-}#2\endgroup
\else
% \end{macrocode}
% If everything is okay, proceed with parsing.
%
% \changes{1.31}{2004/08/18}{Bugfix: \cs{numprint\{e123\}} reprinted the
% last used sign}%
% If the mantissa is empty don't work on it but reset the sign of the
% mantissa to avoid to reprint the old sign when using
% \cs{numprint\{e123\}}.
% If it is not empty, parse it for a sign and a number.
% \begin{macrocode}
\ifx\nprt@mantissa\@empty
\def\nprt@mantissa@sign{\@empty}%
\else
\nprt@testsign{mantissa}{\nprt@mantissa}%
\fi
% \end{macrocode}
% If the mantissa contains only a sign, \cs{nprt@mantissa} is set to
% \cs{@empty} and thus empty even if it wasn't 4 lines above.
% If the mantissa only contains of a sign and an exponent is given,
% everything is fine.
% If no exponent is given, the input format is invalid.
% \begin{macrocode}
\ifx\nprt@mantissa\@empty
\ifx\nprt@exponent\@empty
\nprt@error{Invalid number format. Printing the
argument\MessageBreak
verbatim}{Something is wrong in the format of the number}%
\else
\nprt@printsign{mantissa}{\nprt@mantissa@sign}%
\fi
\else
% \end{macrocode}
% Round the mantissa if necessary.
% \begin{macrocode}
\nprt@round{mantissa}{\nprt@rounddigits}%
% \end{macrocode}
% Pad the mantissa if necessary.
% \begin{macrocode}
\nprt@lpad{mantissa}{\nprt@lpaddigits}{\nprt@lpadchar}%
\fi
% \end{macrocode}
% If an exponent has been found, parse this like the mantissa.
% \begin{macrocode}
\ifnprt@expfound
% \end{macrocode}
% Test wheather an exponent character was given but no exponent.
% \begin{macrocode}
\ifx\nprt@exponent\@empty
\nprt@error{Empty exponent}{If you specify an exponent
using one of the characters `\nprt@explist' you
have\MessageBreak
to give an exponent, too.}%
\else
\nprt@testsign{exponent}{\nprt@exponent}%
\nprt@round{exponent}{\nprt@roundexpdigits}%
\fi
\fi
% \end{macrocode}
% If either the mantissa or the exponent produces an error, just print
% the argument as is.
% Redefine \cs{pm} to avoid an additional error in text mode.
% \begin{macrocode}
\ifnprt@argumenterror
\begingroup\def\pm{+-}#2\endgroup
\else
% \end{macrocode}
% Print the mantissa if present.
% \begin{macrocode}
\ifx\nprt@mantissa\@empty
\else
% \end{macrocode}
% Print the part before the decimal sign.
%
% If the number shall be printed in a box (table alignment) some
% special things have to be done.
% \begin{macrocode}
\ifnprt@mantissa@fixeddigits
\ifmmode
% \end{macrocode}
% In math mode, it must be decided which math style is active because
% the width of the box depends on that.
% The \cs{mathchoice} command does the formatting for all styles and
% typesets the active one then.
% \begin{macrocode}
\mathchoice{%
% \end{macrocode}
% Calculate the width of the block for the \cs{displaystyle}.
% \begin{macrocode}
\nprt@calcblockwidth{mantissa}{before}{\displaystyle}%
% \end{macrocode}
% Generate a box with the calculated width and the corresponding math
% style.
% \begin{macrocode}
\makebox[\the\nprt@blockwidth][r]{$\displaystyle
% \end{macrocode}
% Print the sign if present.
% \begin{macrocode}
\nprt@printsign{mantissa}{\nprt@mantissa@sign}%
% \end{macrocode}
% Print the integer part into the box.
% \begin{macrocode}
\nprt@printbefore{mantissa}$}%
}{%
% \end{macrocode}
% Do the same for \cs{textstyle}.
% \begin{macrocode}
\nprt@calcblockwidth{mantissa}{before}{\textstyle}%
\makebox[\the\nprt@blockwidth][r]{$\textstyle
\nprt@printsign{mantissa}{\nprt@mantissa@sign}%
\nprt@printbefore{mantissa}$}%
}{%
% \end{macrocode}
% Do the same for \cs{scriptstyle}.
% \begin{macrocode}
\nprt@calcblockwidth{mantissa}{before}{\scriptstyle}%
\makebox[\the\nprt@blockwidth][r]{$\scriptstyle
\nprt@printsign{mantissa}{\nprt@mantissa@sign}%
\nprt@printbefore{mantissa}$}%
}{%
% \end{macrocode}
% Do the same for \cs{scriptscriptstyle}.
% \begin{macrocode}
\nprt@calcblockwidth{mantissa}{before}{\scriptscriptstyle}%
\makebox[\the\nprt@blockwidth][r]{$\scriptscriptstyle
\nprt@printsign{mantissa}{\nprt@mantissa@sign}%
\nprt@printbefore{mantissa}$}%
}%
\else
% \end{macrocode}
% If the number is printed in text mode, the size is preserved inside
% the box.
% Thus, no hack as for math mode is necessary.
% \begin{macrocode}
\nprt@calcblockwidth{mantissa}{before}{\@empty}%
\makebox[\the\nprt@blockwidth][r]{%
\nprt@printsign{mantissa}{\nprt@mantissa@sign}%
\nprt@printbefore{mantissa}%
}%
\fi
\else
% \end{macrocode}
% If the number is printed without fixed width, just print it.
% \begin{macrocode}
\nprt@printsign{mantissa}{\nprt@mantissa@sign}%
\nprt@printbefore{mantissa}%
\fi
% \end{macrocode}
% Print the after-decimal-sign digits.
% This works exactly as the integer part.
% \begin{macrocode}
\ifnprt@mantissa@fixeddigits
\ifmmode
\mathchoice{%
\nprt@calcblockwidth{mantissa}{after}{\displaystyle}%
\makebox[\the\nprt@blockwidth][l]{$\displaystyle
\ifnprt@mantissa@decimalfound
\nprt@decimal
\fi
\nprt@printafter{mantissa}$}%
}{%
\nprt@calcblockwidth{mantissa}{after}{\textstyle}%
\makebox[\the\nprt@blockwidth][l]{$\textstyle
\ifnprt@mantissa@decimalfound
\nprt@decimal
\fi
\nprt@printafter{mantissa}$}%
}{%
\nprt@calcblockwidth{mantissa}{after}{\scriptstyle}%
\makebox[\the\nprt@blockwidth][l]{$\scriptstyle
\ifnprt@mantissa@decimalfound
\nprt@decimal
\fi
\nprt@printafter{mantissa}$}%
}{%
\nprt@calcblockwidth{mantissa}{after}{\scriptscriptstyle}%
\makebox[\the\nprt@blockwidth][l]{$\scriptscriptstyle
\ifnprt@mantissa@decimalfound
\nprt@decimal
\fi
\nprt@printafter{mantissa}$}%
}%
\else
\nprt@calcblockwidth{mantissa}{after}{\@empty}%
\makebox[\the\nprt@blockwidth][l]{%
\ifnprt@mantissa@decimalfound
\nprt@decimal
\fi
\nprt@printafter{mantissa}%
}%
\fi
\else
\ifnprt@mantissa@decimalfound
\nprt@decimal
\fi
\nprt@printafter{mantissa}%
\fi
\fi
% \end{macrocode}
% If an exponent is defined it has to be printed later.
% Therefore, define the command \cs{nprt@printexp} that just prints
% its argument.
% \begin{macrocode}
\ifnprt@expfound
\def\nprt@printexp##1{##1}%
% \end{macrocode}
% If a sign but no number has been given for the exponent
% \cs{nprt@exponent} is empty but \cs{ifnprt@expfound} true.
% Test for this case here.
% \begin{macrocode}
\ifx\nprt@exponent\@empty
\nprt@error{Invalid number format in
exponent. Printing\MessageBreak
garbage}{Something is wrong in the format of the exponent}%
\fi
\else
% \end{macrocode}
% If there is no exponent but digits reserved for it, define the
% \cs{nprt@printexp} so that is just needs that space but does not
% print anything.
% \begin{macrocode}
\ifnprt@exponent@fixeddigits
\def\nprt@printexp##1{\hphantom{##1}}%
\else
% \end{macrocode}
% If there is no exponent and no reserved digits, don't print the
% exponent.
% \begin{macrocode}
\def\nprt@printexp##1{}%
\fi
\fi
% \end{macrocode}
% If\label{page:code:color} negative numbers are printed in red (as
% shown in section~\ref{sec:negative-red}), a positive mantissa with a
% negative exponent would normally lead to a black mantissa with a
% red exponent.
% To avoid that the \cs{color} command is redefined to do nothing
% here.
% Do it in a group to restrain this to the exponent itself.
% \changes{1.22}{2004/08/08}{Restrain empty \cs{color} command to
% exponent}%
% \begin{macrocode}
\begingroup
\def\color##1{}%
% \end{macrocode}
% Call the command that either print the exponent, reserves space as
% it were printed or does nothing.
% \begin{macrocode}
\nprt@printexp{%
% \end{macrocode}
% If not mantissa is specified, print the short version, e.g.,
% $10^{123}$ and thus leave out the product sign.
% \begin{macrocode}
\ifx\nprt@mantissa\@empty
\else
% \end{macrocode}
% Print out the product sign, if there is a mantissa.
% \begin{macrocode}
\nprt@prod
\fi
% \end{macrocode}
% Print ``10'' and the exponent.
% This is different between text and math mode.
% \begin{macrocode}
\ifmmode 10^\else 10\expandafter\textsuperscript\fi{%
% \end{macrocode}
% Print the number before the decimal sign.
% As the mantissa.
% \begin{macrocode}
\ifnprt@exponent@fixeddigits
\ifmmode
\mathchoice{%
\nprt@calcblockwidth{exponent}{before}{\displaystyle}%
\makebox[\the\nprt@blockwidth][r]{$\displaystyle
\nprt@printsign{exponent}{\nprt@exponent@sign}%
\nprt@printbefore{exponent}$}%
}{%
\nprt@calcblockwidth{exponent}{before}{\textstyle}%
\makebox[\the\nprt@blockwidth][r]{$\textstyle
\nprt@printsign{exponent}{\nprt@exponent@sign}%
\nprt@printbefore{exponent}$}%
}{%
\nprt@calcblockwidth{exponent}{before}{\scriptstyle}%
\makebox[\the\nprt@blockwidth][r]{$\scriptstyle
\nprt@printsign{exponent}{\nprt@exponent@sign}%
\nprt@printbefore{exponent}$}%
}{%
\nprt@calcblockwidth{exponent}{before}{\scriptscriptstyle}%
\makebox[\the\nprt@blockwidth][r]{$\scriptscriptstyle
\nprt@printsign{exponent}{\nprt@exponent@sign}%
\nprt@printbefore{exponent}$}%
}%
\else
\nprt@calcblockwidth{exponent}{before}{\@empty}%
\makebox[\the\nprt@blockwidth][r]{%
\nprt@printsign{exponent}{\nprt@exponent@sign}%
\nprt@printbefore{exponent}%
}%
\fi
\else
\nprt@printsign{exponent}{\nprt@exponent@sign}%
\nprt@printbefore{exponent}%
\fi
% \end{macrocode}
% Produce a warning since this is uncommon in exponents.
% \begin{macrocode}
\ifnprt@exponent@decimalfound
\PackageWarning{numprint}{Non-integer exponent}%
\fi
% \end{macrocode}
% Print the part after the decimal sign.
% \begin{macrocode}
\ifnprt@exponent@fixeddigits
\ifmmode
\mathchoice{%
\nprt@calcblockwidth{exponent}{after}{\displaystyle}%
\makebox[\the\nprt@blockwidth][l]{$\displaystyle
\ifnprt@exponent@decimalfound
\nprt@decimal
\fi
\nprt@printafter{exponent}$}%
}{%
\nprt@calcblockwidth{exponent}{after}{\textstyle}%
\makebox[\the\nprt@blockwidth][l]{$\textstyle
\ifnprt@exponent@decimalfound
\nprt@decimal
\fi
\nprt@printafter{exponent}$}%
}{%
\nprt@calcblockwidth{exponent}{after}{\scriptstyle}%
\makebox[\the\nprt@blockwidth][l]{$\scriptstyle
\ifnprt@exponent@decimalfound
\nprt@decimal
\fi
\nprt@printafter{exponent}$}%
}{%
\nprt@calcblockwidth{exponent}{after}{\scriptscriptstyle}%
\makebox[\the\nprt@blockwidth][l]{$\scriptscriptstyle
\ifnprt@exponent@decimalfound
\nprt@decimal
\fi
\nprt@printafter{exponent}$}%
}%
\else
\nprt@calcblockwidth{exponent}{after}{\@empty}%
\makebox[\the\nprt@blockwidth][l]{%
\ifnprt@exponent@decimalfound
\nprt@decimal
\fi
\nprt@printafter{exponent}%
}%
\fi
\else
\ifnprt@exponent@decimalfound
\nprt@decimal
\fi
\nprt@printafter{exponent}%
\fi
}% 10^
}% \nprt@printexp
\endgroup
\fi
\fi
% \end{macrocode}
% If the unit is not empty, print it, too.
% \begin{macrocode}
\ifx\nprt@oarg\nprt@@empty
\else
% \end{macrocode}
% All units expect the degree symbol are separated from the number.
% Detect wheather the degree symbol is used.
%
% \changes{1.22}{2004/08/08}{Produce a warning rather than an error
% when using \cs{textdegree} as unit}%
% The \cs{textdegree} command is not useable in math mode.
% Redeclare it to generate a warning and to use \cs{tcdegree}
% instead.
% \begin{macrocode}
\def\textdegree{%
\PackageWarning{numprint}{The unit is typeset in mathmode. Use
\string\tcdegree\space of\MessageBreak
the mathcomp package or \string\degree\space of the
gensymb\MessageBreak
package}%
% \end{macrocode}
% Call \cs{tcdegree} via \cs{csname} in order to avoid a second error
% message if \cs{tcdegree} is not present (because of not loading
% |mathcomp.sty|.
% \begin{macrocode}
\csname tcdegree\endcsname
}%
% \end{macrocode}
% \changes{1.22}{2004/08/08}{Enable to use \cs{textcelsius},
% \cs{textohm}, \cs{textmu}, and \cs{textperthousand} in the unit}%
% \changes{1.32}{2004/09/13}{Produce an error rather than a warning
% when using \texttt{textcomp} symbols in the unit if
% \texttt{mathcomp} or \texttt{gensymb} is not loaded}%
% Handle \cs{textcelsius}, \cs{textohm}, \cs{textmu}, and
% \cs{textperthousand} in the same way as \cs{textdegree}.
% \begin{macrocode}
\def\nprt@PackageError##1##2{\PackageWarning{numprint}{##1}}%
\def\textcelsius{%
\begingroup
\@ifundefined{tccelsius}{\@ifundefined{celsius}{%
\def\nprt@PackageError####1####2{%
\PackageError{numprint}{####1}{####2}}%
}{\celsius}}{\tccelsius}%
\nprt@PackageError{The unit is typeset in
mathmode. Use \string\tccelsius\space of\MessageBreak
the mathcomp package or \string\celsius\space of the
gensymb\MessageBreak
package}{If you load the mathcomp package
\string\textcelsius\space is substituted by
\string\tccelsius. If you load the gensymb package
\string\textcelsius\space is substituted by \string\celsius.}%
\endgroup
}%
\def\textohm{%
\begingroup
\@ifundefined{tcohm}{\@ifundefined{ohm}{%
\def\nprt@PackageError####1####2{%
\PackageError{numprint}{####1}{####2}}%
}{\ohm}}{\tcohm}%
\nprt@PackageError{The unit is typeset in
mathmode. Use \string\tcohm\space of\MessageBreak
the mathcomp package or \string\ohm\space of the
gensymb\MessageBreak
package}{If you load the mathcomp package
\string\textohm\space is substituted by
\string\tcohm. If you load the gensymb package
\string\textohm\space is substituted by \string\ohm.}%
\endgroup
}%
\def\textmu{%
\begingroup
\@ifundefined{tcmu}{%
\def\nprt@PackageError####1####2{%
\PackageError{numprint}{####1}{####2}}%
}{\tcmu}%
\nprt@PackageError{The unit is typeset in
mathmode. Use \string\tcmu\space of\MessageBreak
the mathcomp package}{If you load the mathcomp package
\string\textmu\space is substituted by \string\tcmu.}%
\endgroup
}%
\def\textperthousand{%
\begingroup
\@ifundefined{tcperthousand}{\@ifundefined{perthousand}{%
\def\nprt@PackageError####1####2{%
\PackageError{numprint}{####1}{####2}}%
}{\perthousand}}{\tcperthousand}%
\nprt@PackageError{The unit is typeset in
mathmode. Use \string\tcperthousand\MessageBreak
of the mathcomp package or \string\perthousand\space of
the\MessageBreak
gensymb package}{If you load the mathcomp package
\string\textperthousand\space is substituted by
\string\tcperthousand. If you load the gensymb package
\string\textperthousand\space is substituted by
\string\perthousand.}%
\endgroup
}%
% \end{macrocode}
% If the unit is \cs{tcdegree} from the \texttt{mathcomp} package, the
% unit is a degree sign.
% Then print the separator \cs{nprt@degreesep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\tcdegree}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@degreesep}%
\else
% \end{macrocode}
% If the unit is \cs{degree} from the \texttt{gensymb} package, the
% unit is a degree sign.
% Then print the separator \cs{nprt@degreesep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\degree}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@degreesep}%
\else
% \end{macrocode}
% If the unit is \cs{textdegree} from the \texttt{textcomp} package, the
% unit is a degree sign.
% Then print the separator \cs{nprt@degreesep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\textdegree}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@degreesep}%
\else
% \end{macrocode}
% If the unit is \cs{tccelsius} from the \texttt{mathcomp} package, the
% unit is degree centigrade.
% Then print the separator \cs{nprt@celsiussep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\tccelsius}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@celsiussep}%
\else
% \end{macrocode}
% If the unit is \cs{celsius} from the \texttt{gensymb} package, the
% unit is degree centigrade.
% Then print the separator \cs{nprt@celsiussep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\celsius}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@celsiussep}%
\else
% \end{macrocode}
% If the unit is \cs{textcelsius} from the \texttt{textcomp} package, the
% unit is degree centigrade.
% Then print the separator \cs{nprt@celsiussep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\textcelsius}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@celsiussep}%
\else
% \end{macrocode}
% If the unit is \cs{\%}, the unit is a percent sign.
% Then print the separator \cs{nprt@percentsep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\%}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@percentsep}%
\else
% \end{macrocode}
% If the unit is \cs{tcperthousand} from the \texttt{mathcomp} package, the
% unit is a permil sign.
% Then print the separator \cs{nprt@percentsep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\tcperthousand}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@percentsep}%
\else
% \end{macrocode}
% If the unit is \cs{perthousand} from the \texttt{gensymb} package, the
% unit is a permil sign.
% Then print the separator \cs{nprt@percentsep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\perthousand}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@percentsep}%
\else
% \end{macrocode}
% If the unit is \cs{textperthousand} from the \texttt{textcomp} package, the
% unit is a permil sign.
% Then print the separator \cs{nprt@percentsep} instead of
% \cs{nprt@unitsep}.
% \begin{macrocode}
\def\nprt@tmpunit{\textperthousand}%
\ifx\nprt@oarg\nprt@tmpunit
\ensuremath{\nprt@percentsep}%
\else
% \end{macrocode}
% Else, print \cs{nprt@unitsep}.
% \begin{macrocode}
\ensuremath{\nprt@unitsep}%
\fi
\fi
\fi
\fi
\fi
\fi
\fi
\fi
\fi
\fi
% \end{macrocode}
% Finally, print the unit.
% \begin{macrocode}
\npunitcommand{\nprt@oarg}%
\fi
\endgroup
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Print lengths and counters}%
% \label{sec:code:lenprint}%
%
% \begin{macro}{\cntprint}
% The macro for printing counters.
% The mandatory argument takes a \LaTeX\ counter.
% The optional argument may contain a unit which is printed, too.
% \begin{macrocode}
\newcounter{nprt@cntprint}
\DeclareRobustCommand*\cntprint[2][\@empty]{%
\@ifundefined{c@#2}{\@nocounterr{#2}}{%
\numprint[#1]{\arabic{#2}}%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\lenprint}
% The macro for printing lengths.
% The mandatory argument takes a \TeX\ dimension or a counter.
% The optional argument may contain a unit that is used to convert the
% unit from |pt| to the given value and which then is printed, too.
% \begin{macrocode}
\DeclareRobustCommand*\lenprint[2][\@empty]{%
% \end{macrocode}
% Do everything in a group to avoid macros to resist outside.
% \begin{macrocode}
\begingroup
% \end{macrocode}
% Save the optional argument in \cs{nprt@oarg} and expand it.
% \begin{macrocode}
\edef\nprt@oarg{#1}%
% \end{macrocode}
% If no optional argument has been given, change it to |pt|.
% This cannot be done as default argument in the
% \cs{DeclareRobustCommand*} definition since printing of counters
% does not have |pt| as default.
% \begin{macrocode}
\edef\nprt@tmp{\@empty}%
\ifx\nprt@oarg\nprt@tmp
\def\nprt@oarg{pt}%
\fi
% \end{macrocode}
% If the chosen unit is not defined produce an error message and fall
% back to |pt|.
% \begin{macrocode}
\@ifundefined{nprt@factor@\nprt@oarg}{%
\PackageError{numprint}{Invalid unit `#1'}{%
The requested unit is not defined using \string\npdefunit.^^J%
Using `pt' instead.}%
\def\nprt@oarg{pt}%
}{}%
% \end{macrocode}
% For later printing, a length is used that is fixed to |pt| as
% length.
% If another unit has been chosen a fake length has to be calculated
% that is as many |pt| long as the original length is in the given
% unit.
% Thus, multiply the mandatory argument by the specific factor for the
% given unit.
% \begin{macrocode}
\setlength{\@tempdima}{#2}%
\setlength{\@tempdima}{\csname nprt@factor@\nprt@oarg\endcsname\@tempdima}%
% \end{macrocode}
% If the unit name for the given unit is not defined but the factor
% is an internal error has occured.
% Produce an error message.
% \begin{macrocode}
\@ifundefined{nprt@unit@\nprt@oarg}{%
\PackageError{numprint}{Unknown unit name `\nprt@oarg'}{%
Send a bug report to harald.harders@tu-bs.de with a short
example showing this bug.}%
}{%
% \end{macrocode}
% Store the unit name in \cs{nprt@oarg}.
% \begin{macrocode}
\edef\nprt@oarg{\csname nprt@unit@\nprt@oarg\endcsname}%
}%
% \end{macrocode}
% Finally, call \cs{numprint}.
% The two \cs{expandafter} are necessary since \cs{numprint} also uses
% \cs{nprt@oarg} and produces an infinite loop otherwise.
% \begin{macrocode}
\expandafter\numprint\expandafter[\nprt@oarg]{\strip@pt\@tempdima}%
\endgroup
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npdefunit}
% Define a new unit for usage with \cs{lenprint}.
% First argument: name in the sourcecode.
% Second argument: printed unit.
% Third argument: factor from |pt| to the new unit or |*| to preserve
% old factor.
% \begin{macrocode}
\newcommand*\npdefunit[3]{%
% \end{macrocode}
% If the third argument is not |*| define the factor for this unit in
% \cs{nprt@factor@\meta{\#1}}.
% \begin{macrocode}
\if#3*
\else
\expandafter\def\csname nprt@factor@#1\endcsname{#3}%
\fi
% \end{macrocode}
% Define the unit name for this unit in \cs{nprt@unit@\meta{\#1}}.
% \begin{macrocode}
\expandafter\def\csname nprt@unit@#1\endcsname{#2}%
}
% \end{macrocode}
% \end{macro}
% Declare the standard units.
% \cs{!} is used to delete the unit separator again.
% This is a hack and does not work in all cases correctly.
% \begin{macrocode}
\npdefunit{pt}{pt}{1.00000000000}
\npdefunit{bp}{bp}{0.99626400996}
\npdefunit{in}{in}{0.01383700013}
\npdefunit{ft}{ft}{0.00115308334}
\npdefunit{mm}{mm}{0.35145980351}
\npdefunit{cm}{cm}{0.03514598035}
\npdefunit{m}{m}{0.0003514598035}
\npdefunit{km}{km}{0.0000003514598035}
% \end{macrocode}
%
%
% \subsection{Internationalization}
%
% \begin{macro}{\nprt@ifundefined}
% The normal \cs{@ifundefined} command defines the tested macro as
% side effect.
% This command is better.
% Sometimes it will hopefully be unnecessary and supported by the
% standard (with a different name, of course).
% \begin{macrocode}
\newcommand*\nprt@ifundefined[1]{%
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname #1\endcsname\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@addto}
% Adds the code of the second argument to the macro defined in the
% first argument.
% This argument has to be specified without the preceeding backslash.
% The code is added only if the command is defined, already.
% \begin{macrocode}
\newcommand\nprt@addto[2]{%
\expandafter\nprt@ifundefined{#1}{}{%
\expandafter\addto\expandafter{\csname #1\endcsname}{#2}%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npaddtolanguage}
% Define \cs{npaddtolanguage\marg{Language}\marg{Language
% definitions}}.
% Adds the \meta{Language definitions} specified in argument two to
% the \meta{Language} of argument one.
% The language definitions have to be provided in a command with the
% name \cs{npstyle}\meta{Language definitions}.
% The switching-on command is added to \cs{extras\meta{Language}}
% while the switching-off command \cs{npstyledefault} is added to
% \cs{noextras\meta{Language}}.
%
% For example, \cs{npaddtolanguage\{UKenglish\}\{english\}} adds the
% command \cs{npstyleenglish} to \cs{extrasUKenglish} and
% \cs{npstyledefault} to \cs{noextrasUKenglish}.
%
% The \cs{npstyle\meta{Language definitions}} commands are described
% below.
% \begin{macrocode}
\newcommand\npaddtolanguage[2]{%
\nprt@addto{extras#1}{\csname npstyle#2\endcsname}%
\nprt@addto{noextras#1}{\npstyledefault}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npstyledefault}
% Set the default values for the separators.
% They are set to the German language because of compatibility with
% older versions.
% \begin{macrocode}
\newcommand*\npstyledefault{%
\npthousandsep{\,}%
\npdecimalsign{,}%
\npproductsign{\cdot}%
\npunitseparator{\,}%
\npdegreeseparator{}%
\npcelsiusseparator{\nprt@unitsep}%
\nppercentseparator{\nprt@unitsep}%
}
% \end{macrocode}
% \end{macro}
% Set the default settings (that are actually the same as German).
% \begin{macrocode}
\npstyledefault
% \end{macrocode}
% \begin{macro}{\npstylegerman}
% Sets the parameters to German habit.
% \begin{macrocode}
\newcommand*\npstylegerman{%
\npthousandsep{\,}%
\npdecimalsign{,}%
\npproductsign{\cdot}%
\npunitseparator{\,}%
\npdegreeseparator{}%
\npcelsiusseparator{\nprt@unitsep}%
\nppercentseparator{\nprt@unitsep}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npstyleenglish}
% Sets the parameters to English habit.
% \begin{macrocode}
\newcommand*\npstyleenglish{%
\npthousandsep{,}%
\npdecimalsign{.}%
\npproductsign{\times}%
\npunitseparator{\,}%
\npdegreeseparator{}%
\npcelsiusseparator{\nprt@unitsep}%
\nppercentseparator{\nprt@unitsep}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npstyleportuguese}
% \changes{1.37}{2007/01/08}{Change thousand separator for Portuguese
% from ``\cs{,}'' to ``\texttt{.}''}%
% Sets the parameters to Portuguese habit.
% \begin{macrocode}
\newcommand*\npstyleportuguese{%
\npthousandsep{.}%
\npdecimalsign{,}%
\npproductsign{\cdot}%
\npunitseparator{\,}%
\npdegreeseparator{}%
\npcelsiusseparator{\nprt@unitsep}%
\nppercentseparator{\nprt@unitsep}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npstyledutch}
% Sets the parameters to Dutch habit.
% \begin{macrocode}
\newcommand*\npstyledutch{%
\npthousandsep{\,}%
\npdecimalsign{,}%
\npproductsign{\cdot}%
\npunitseparator{\,}%
\npdegreeseparator{}%
\npcelsiusseparator{\nprt@unitsep}%
\nppercentseparator{}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\npstylefrench}
% Sets the parameters to French habit.
% \begin{macrocode}
\newcommand*\npstylefrench{%
\npthousandsep{~}%
\npdecimalsign{,}%
\npproductsign{\cdot}%
\npunitseparator{\,}%
\npdegreeseparator{}%
\npcelsiusseparator{\nprt@unitsep}%
\nppercentseparator{\nprt@unitsep}%
}
% \end{macrocode}
% \end{macro}
% Do the following actions at \cs{begin\{document\}} to ensure that it
% is done after loading \texttt{babel.sty} if it is loaded at all.
% \begin{macrocode}
\AtBeginDocument{%
% \end{macrocode}
% By default, automatic language support is switched off for
% compatiblity reasons.
% Proceed only if it is switched on.
% \begin{macrocode}
\ifnprt@autolanguage
% \end{macrocode}
% Automatic language support only works with babel.
% \begin{macrocode}
\@ifpackageloaded{babel}{%
% \end{macrocode}
% Adds the language settings to the known languages if they are
% provided by babel.
% The current version knows all German, English, Portuguese, Dutch,
% and French dialects.
% \begin{macrocode}
\npaddtolanguage{UKenglish}{english}%
\npaddtolanguage{USenglish}{english}%
\npaddtolanguage{afrikaans}{dutch}%
\npaddtolanguage{american}{english}%
\npaddtolanguage{austrian}{german}%
\npaddtolanguage{british}{english}%
\npaddtolanguage{canadian}{english}%
\npaddtolanguage{dutch}{dutch}%
\npaddtolanguage{english}{english}%
\npaddtolanguage{german}{german}%
\npaddtolanguage{naustrian}{german}%
\npaddtolanguage{ngerman}{german}%
\npaddtolanguage{brazil}{portuguese}%
\npaddtolanguage{brazilian}{portuguese}%
\npaddtolanguage{portuges}{portuguese}%
\npaddtolanguage{portuguese}{portuguese}%
\npaddtolanguage{francais}{french}%
\npaddtolanguage{canadien}{french}%
\npaddtolanguage{acadian}{french}%
\npaddtolanguage{french}{french}%
\npaddtolanguage{frenchb}{french}%
% \end{macrocode}
% Set the active language again to activate the extras section.
% \begin{macrocode}
\expandafter\selectlanguage\expandafter{\languagename}%
}{%
% \end{macrocode}
% If |babel| is not loaded but automatic language support is
% activated, switch to English as default:
% \begin{macrocode}
\npstyleenglish
}%
\fi
}
% \end{macrocode}
% Load configuration file if present.
% \begin{macrocode}
\InputIfFileExists{numprint.cfg}{%
\message{Configuration file `numprint.cfg' loaded.}%
}{%
\message{No configuration file `numprint.cfg' found.}%
}
% \end{macrocode}
% \begin{macro}{\nprt@renameerror}
% A command for producing an error message for redefined macros.
% \begin{macrocode}
\newcommand*\nprt@renameerror[1]{%
\expandafter\def\csname #1\endcsname{%
\PackageError{numprint}{This command has been renamed
to\MessageBreak
\string\np #1}{In order to avoid problems with other
packages and for consistency, this\MessageBreak
command has been renamed in this version.}%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\fourdigitsep}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npfourdigitsep}}%
% \begin{macro}{\fourdigitnosep}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npfourdigitnosep}}%
% \begin{macro}{\addmissingzero}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npaddmissingzero}}%
% \begin{macro}{\noaddmissingzero}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npnoaddmissingzero}}%
% \begin{macro}{\digits}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npdigits}}%
% \begin{macro}{\nodigits}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npnodigits}}%
% \begin{macro}{\exponentdigits}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npexponentdigits}}%
% \begin{macro}{\noexponentdigits}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npnoexponentdigits}}%
% Define replacements for the old commands that produce error
% messages.
% \begin{macrocode}
\nprt@renameerror{fourdigitsep}
\nprt@renameerror{fourdigitnosep}
\nprt@renameerror{addmissingzero}
\nprt@renameerror{noaddmissingzero}
\nprt@renameerror{digits}
\nprt@renameerror{nodigits}
\nprt@renameerror{exponentdigits}
\nprt@renameerror{noexponentdigits}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \iffalse
%</package>
% \fi
% \Finale
|