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
|
% \def\fileversion{5.1}\def\filedate{2004/04/29}\def\docdate{2013/11/26}
%\iffalse These lines are necessary for the doc and docstrip utilities
%<*asciidocu>
%%#
%%# Author:
%%#
%%# M. V\"ath martin@mvath.de
%%#
%%# The author thanks
%%# David Kastrup <David.Kastrup@neuroinformatik.ruhr-uni-bochum.de>
%%#
%%# The package may be distributed and/or modified under the conditions of
%%# the LaTeX Project Public License (version 1.3c or later).
%%#############################################################################
%%#
%%# The TeX programmer's toolbox; enhanced version.
%%# This (La)TeX package provides some macros which are convenient for
%%# writing indices, glossaries, or other macros.
%%# It contains macros which support
%%#
%%# - implicit macros - a useful supplement to \index or varindex for
%%# writing glossaries or indices
%%# - fancy optional arguments
%%# - loops over tokenlists and itemlists
%%# - searching, splitting, and replacing
%%# - controlled expansion
%%# - redefinition of macros
%%# - concatenated macro names
%%#
%%#############################################################################
%%#
%%# This package was tested with plain TeX, LaTeX 2.09, and LaTeX 2e,
%%# and it should actually run with all TeX formats.
%%#
% If you have access to (reasonable new) docstrip TeXfiles, you should run
% tex/latex on the file
% `toolbox.ins'
% to produce the files `toolbox.sty', `toolbox.txt' and `toolbox.tex'.
% (In case `toolbox.ins' is lost: You can find its content in the last
% few lines of the file you are currently reading between the
% lines %<*insfile> and %</insfile>;
% BTW: You should name this file here `toolbox.dtx' before you run tex
% on toolbox.ins).
%
% The file `toolbox.txt' contains a `brief' (but complete) ascii
% documentation. If you have additionally access to LaTeX 2e, you may run
% latex on the generated file `toolbox.tex' to produce `toolbox.dvi' which
% contains a more luxury documentation.
%
% If you do not have access to the docstrip TeXfiles you may simply
% copy/rename this file here into
% `toolbox.sty'
% to use the package and read the ascii documentation in this file.
% The ascii documentation (the content of `toolbox.txt') consists of all
% lines in this file which start with %%# (this is the above block and another
% (very large) block which follows soon).
%
% But I do not recommended this, because TeX will need more time to read this
% longer file, and because there might be a (very slight) incompatibility if
% you use it (namely if you load `toolbox.sty' with some *extremely* strange
% catcodes).
% I recommend in this case instead to generate the file `toolbox.sty' as
% anything between the lines %<*package> and %</package> by hand.
% (This is not precisely the file which you get with the docstrip TeXfiles,
% but a reasonable good substitute. To speed up loading, you may also
% eliminate all lines starting with `% ' in `toolbox.sty').
% For your information: The file `toolbox.tex' produced by the docstrip
% TeXfiles is anything between the lines %<*driver> and %</driver>
% (with a line containing \endinput and two comment lines appended)
%
%
% In any case, you end up with the file `toolbox.sty'.
%
% If you can generate `toolbox.tex', you will probably want to stop
% reading now and instead read the `luxury' documentation in `toolbox.dvi'.
%
% Otherwise, you have to make due with the following ascii documentation.
%
%
% \fi\catcode\#14\relax\iffalse (This line is needed for the doc utility)
%
%%# To use toolbox, you have to put `toolbox.sty' in a path where TeX looks
%%# for its input files. The TeX documents using toolbox need the
%%# following modifications in their header:
%%#
%%# a) If you use LaTeX2.09, use toolbox as a style option, e.g.
%%# \documentstyle[toolbox]{article}
%%# or
%%# \documentstyle[toolbox,12pt]{article}
%%# b) If you use LaTeX2e, put in the preamble the command
%%# \usepackage{toolbox}
%%# c) If you use some other (non-LaTeX) format, you will probably have to
%%# insert a line like
%%# \catcode`\@=11\input toolbox.sty\catcode`\@=12\relax
%%#
%%# The only LaTeX-specific commands used in `toolbox.sty' are:
%%#
%%# \newcommand (only in the form \newcommand{\command}{} to ensure that
%%# \command was not defined before)
%%# \ProvidesPackage
%%# \typeout
%%#
%%# The above commands are used only if they are defined.
%%#
%%#
%%# Description of the provided macros:
%%#
%%# General remark: Many macros could appear in several sections.
%%# For example, \toolboxMakeDef and \toolboxSourround might be considered
%%# as macros which support redefinitions of macros. However, we put them
%%# in different sections which perhaps explain better their nature.
%%#
%%# Implicit macro definitions
%%# --------------------------
%%# What we mean by implicit macro definitions is probably best explained by
%%# the following examples which show the intended usage:
%%#
%%# (In the following examples, we always refer to the \index command. Note
%%# that it may be more convenient to use for indices the varindex package in
%%# addition - the documentation of varindex (release 2.3 or newer) gives
%%# additional hints and examples how these two (essentially independent)
%%# approaches can be combined in practice).
%%#
%%# Assume that you want to write an index for a book which has rather
%%# long and complicated \index entries. The first idea that one might have in
%%# this connection is to put the various \index commands at the beginning of
%%# the document into several macros (one for each \index entry), and to use
%%# just these macros in the main text. For example, one might want to write
%%# near the beginning of the document commands like
%%# \newcommand{\Start}{\index{finish or end}}
%%# \newcommand{\End}{\index{finish or end}}
%%# and then to use in the main text \Start and \End whenever a reference
%%# in the corresponding index to the current place is desired.
%%# However, this has two major disadvantages:
%%# 1. Unless you are very disciplinary with your macro names, it is easy to
%%# forget that \End writes an index entry. So the \End in the main text
%%# might be very confusing.
%%# 2. You cannot choose short and intuitive macro names for common phrases,
%%# because they are usually already reserved by TeX, LaTeX, or some
%%# packages.
%%#
%%# To avoid these problems, one may be very disciplinary and call the
%%# involved macros systematically e.g. \GlossaryStart \GlossaryEnd etc.
%%# However, this produces terrible long and unreadable macro names in the
%%# main text.
%%#
%%# The implicit macro definitions of "toolbox" provide a more convenient
%%# solution. The idea is that you do not use the corresponding macros directly
%%# but only implicitly by a call of other macros where your "macro name" is
%%# just an argument.
%%# Moreover, "toolbox" assists you in writing the corresponding definitions.
%%# For example, if you know that you want a set of macros which all expand
%%# into something of the form \index{...}, you can give a ``mask'' which
%%# contains this form, and you only have to fill in the changing content
%%# (similarly as for usual TeX macros with arguments, but the level of
%%# abstraction is one step higher).
%%# For the above task, you might use the command:
%%#
%%# \toolboxMakeDef{Glossary}{\index{#1}}
%%#
%%# The argument `Glossary' serves to distinguish independent definitions
%%# (this will become clear later). Its effect visible now is that it
%%# determines the name of the following macros which you can use after
%%# the above call:
%%#
%%# \NewGlossary{start-1}{start}
%%# \NewGlossary{start-2}{start or beginning}
%%# \NewGlossary{end}{finish or end}
%%#
%%# These command are now similar to the \newcommand definitions explained
%%# above. However, there is no name collision with the TeX-internal command
%%# \end. Of course, this means that you cannot just write \end in the main
%%# text to get the desired index entry. Instead, you have to write the more
%%# intuitive commands
%%#
%%# \Glossary{start-1}
%%# \Glossary{start-2}
%%# \Glossary{end}
%%#
%%# (again, the name \Glossary stems from our first call of \toolboxMakeDef).
%%# Note that e.g. \Glossary{start-1} expands not only to `start' but
%%# actually to \index{start} (because of our first call of \toolboxMakeDef).
%%# Note also that you can use symbols like - or numbers which are usually
%%# not allowed in TeX macro names.
%%#
%%# Of course, similarly as for \newcommand, you can also do other things with
%%# the macros. For example,
%%#
%%# \LetGlossary\tempname{end}
%%# \NewGlossary*{finish}\tempname
%%#
%%# will first define \tempname to expand to the same text as \Glossary{end},
%%# and then defines a new entry \Glossary{finish} to expand to the same text
%%# as \tempname. Hence, the above new lines make the calls \Glossary{end} and
%%# \Glossary{finish} equivalent.
%%#
%%# At the end of your list of \NewGlossary commands, you might want to put
%%#
%%# \toolboxFreeDef*{Glossary}
%%#
%%# The purpose of this command is that \NewGlossary cannot be used anymore
%%# (unless, of course, you define it again). So you cannot unintentionally
%%# add new entries to your glossary list (but you still can use \Glossary{...}
%%# to reference to the already produced entries).
%%# Moreover, the above command frees some memory which was needed for
%%# \NewGlossary to work.
%%#
%%# If you additionally want to free the memory used by \Glossary, you can use
%%#
%%# \toolboxFreeDef{Glossary}
%%#
%%# (without the `*'). This may be necessary, if you want to call again e.g.
%%#
%%# \toolboxMakeDef{Glossary}{\emph{#1}\index{#1}}
%%#
%%# (if you have not freed the memory for \Glossary before this repeated call,
%%# TeX will complain that \Glossary is already defined).
%%#
%%# Of course, it is possible to call \toolboxMakeDef with several different
%%# names, for example, for \Glossary, \SymbolList etc. Another application
%%# might be to use a different command to mark e.g.\ the main occurrence of
%%# some index entry or to output additionally the entry into the running text.
%%# We do this in the following example which simultaneously
%%# demonstrates that the names can also be constructed in another way:
%%#
%%# \toolboxMakeDef[Ind]{}{\index{#1}}
%%# \toolboxMakeDef[Ind]{Main}{\index{#1|textbf}}
%%# \toolboxMakeDef{OutInd}{#1}
%%#
%%# \IndNew{A}{A is a letter}
%%# \IndNewMain{A}{A is a letter}
%%# \NewOutInd{A}{\textbf{The letter A}\Ind{A}}
%%#
%%# After the above commands, you can use \Ind{A}, \IndMain{A}, and
%%# \OutInd{A} to produce the corresponding \index entry, the "main" \index
%%# entry (with a boldface page number), and the text \textbf{The letter A}
%%# with an additional entry into the index, respectively.
%%# Of course, it might usually be more convenient to define the \Ind and
%%# \IndMain" entries simultaneously, e.g. as follows
%%#
%%# \toolboxMakeDef[Ind]{}{#1}
%%# \toolboxMakeDef[Ind]{Main}{#1}
%%# \newcommand{\NewStandardInd}[2]{%
%%# \IndNew{#1}{\index{#2}}%
%%# \IndNewMain{#1}{\index{#2|textbf}}}
%%#
%%# \NewStandardInd{A}{A is a letter}
%%#
%%# This approach has the additional advantage that you can define exceptional
%%# cases "by hand" (e.g. if you want that for certain "main" index
%%# entries the page number is printed with "\textsl" instead of "\textbf").
%%# Since the motivation for implicit definitions now is hopefully clear,
%%# let us now describe in detail which commands are provided by "toolbox"
%%# for this purpose.
%%# As explained in the example, the main generic macro provided to this
%%# purpose is \toolboxMakeDef. Its call syntax is as follows:
%%#
%%# \toolboxMakeDef[Prefix]{Name}{ReplacementMask}
%%#
%%# (the argument [Prefix] is optional and by default empty).
%%# The above command generates new macros
%%#
%%# \PrefixNewName
%%# \PrefixRenewName
%%# \PrefixProvideName
%%# \PrefixDefName
%%# \PrefixLetName
%%# \PrefixName
%%#
%%# which in turn can be called as follows
%%#
%%# \PrefixNewName{something}{RememberText}
%%# \PrefixRenewName{something}{RememberText}
%%# \PrefixProvideName{something}{RememberText}
%%# \PrefixDefName{something}{RememberText}
%%# \PrefixNewName*{something}{\SomeMacro}
%%# \PrefixRenewName*{something}{\SomeMacro}
%%# \PrefixProvideName*{something}{\SomeMacro}
%%# \PrefixDefName*{something}{\SomeMacro}
%%# \PrefixLetName{\SomeMacro}{something}
%%# \PrefixName{something}
%%# \PrefixName*{something}
%%#
%%# These calls are in a sense similar to the respective commands
%%#
%%# \newcommand{\something}{RememberText}
%%# \renewcommand{\something}{RememberText}
%%# \providecommand{\something}{RememberText}
%%# \def\something{RememberText}
%%# \newcommand{\something}{}\let\something\SomeMacro
%%# \renewcommand{\something}{}\let\something\SomeMacro
%%# \@ifundefined\something{\let\something\SomeMacro}{}
%%# \let\something\SomeMacro
%%# \let\SomeMacro{\something}
%%# \something
%%# \something (but without error if \something is undefined).
%%#
%%# with the differences already pointed out before:
%%# 1. The macro name actually used is not \something. Instead, it is a name
%%# which does not conflict with any existing macro (except one
%%# generated previously by another \PrefixNewName, but in this case a
%%# descriptive error is reported). For this reason, it is not possible to
%%# use this macro directly but only indirectly by the call
%%# \PrefixName{something} (or with \PrefixLetName).
%%# 2. The replacement text is not `RememberText' but determined by
%%# ReplacementMask where every occurrence of #1 in ReplacementMask is
%%# replaced by RememberText (recall the examples). If you want to have the
%%# plain RememberText, use {#1} as ReplacementMask.
%%#
%%# Since toolbox 4.2 there is another slight difference: The symbol '#'
%%# is treated as usual and not as in a macro definition.
%%#
%%# \toolboxMakeDef gives an error message if the commands
%%# \Prefix... are already defined. If you intentionally want to
%%# change a previous definition, you have to call the command
%%#
%%# \toolboxFreeDef[Prefix]{Name}
%%#
%%# before. The latter not only lets all of the macros \Prefix... be
%%# \undefined, but also frees all other memory internally used by the
%%# corresponding call of \toolboxMakeDef
%%# (note, however, that the above command does not free the
%%# memory allocated before by calls of \PrefixNew... - to free the latter,
%%# you have to call subsequently e.g.
%%#
%%# \PrefixNewName*{...}{\undefined}
%%#
%%% before). There is also the command
%%#
%%# \toolboxFreeDef*[Prefix]{Name}
%%#
%%# which acts similarly as \toolboxFreeDef but which does not undefine the
%%# two macros \PrefixName and \PrefixLetName.
%%#
%%#
%%# Fancy optional argument parsing
%%# -------------------------------
%%# This section contains macros which are convenient if you e.g. write a
%%# package that contains macros which contain a lot of optional arguments
%%# and flags (like "*").
%%# Typically, to read such an optional argument or flag, you save
%%# the next token with \futurelet and then call a macro which decides what to
%%# do with the token read. Thus, a typical use of \futurelet looks like
%%#
%%# \def\MacroWithOptionalFlag{\futurelet\tokread\myscan}
%%#
%%# which will define \tokread to be the token *following* the macro
%%# \MacroWithOptionalFlag in the token stream and then execute \myscan.
%%# In this context, it is not very convenient that you are *forced*
%%# to define a macro \myscan: It could be more convenient if you could just
%%# write the *content* of \tokread (in braces) into the above definition.
%%# You can indeed do this if you replace \futurelet by \toolboxFuturelet:
%%#
%%# \toolboxFuturelet\token{argument}
%%#
%%# The call \toolboxFuturelet\token{\command} has precisely the same effect as
%%# \futurelet\token\command. The advantage of \toolboxFuturelet is that
%%# instead of a single \command one may use also a sequence of commands.
%%# Let us consider \MacroWithOptionalFlag as above. Assume that the user
%%# has called this macro in the form "\MacroWithOptionalFlag*" where the
%%# "*" is a flag which should cause your macro to do something slightly
%%# different. On some place in your macro definition you will have recognized
%%# (e.g. with \futurelet or \toolboxFuturelet) that a "*" is following
%%# in the calling sequence. So you now want to execute your action
%%# (whatever \MacroWithOptionalFlag is supposed to do).
%%# However, if you do not take special care, after this action, TeX will
%%# print a "*", because this is the next token on the token stream: \futurelet
%%# does not delete any tokens. So you have to "gobble" this token away.
%%# A rude way to do this is by using the macro \gobblenext as the last token
%%# in you macro which can be defined by
%%# \begin{verbatim}
%%# \def\gobblenext#1{}\end{verbatim}
%%# However, this has two major drawbacks:
%%#
%%# 1. This works for "*", but not for "{" or space tokens.
%%# For space tokens the situation is even worse, since TeX eats spaces
%%# around arguments, so sometimes space tokens might unexpectedly
%%# disappear.
%%# 2. It is not possible in this way to read another argument following
%%# the "*": Recall that \gobblenext must be the *last* token in your
%%# macro expansion, i.e. you have "lost control" after this call.
%%#
%%# The solution to these problems is instead of calling \gobblenext to use
%%# \toolboxGobbleNext as the last command in your call:
%%# You can pass it an argument which describes the action that
%%# you want to do *after* gobbling the next token ("*" in the above example)
%%# from the token stream. Thus
%%#
%%# \toolboxGobbleNext{cmd}
%%#
%%# erases the token following that command from the token stream and
%%# then executes cmd. This is similar to
%%# \def\toolboxGobbleNext#1#2{#1}
%%# with the difference that #2 is considered as a token and that no spaces
%%# are eaten.
%%# The effect is that e.g. the call
%%#
%%# Example:
%%# \toolboxGobbleNext{\foo}{{arg}
%%# is the same as \foo{arg} (the brace "{" is eaten in this example).
%%# As described earlier, the commands "\futurelet" or "\toolboxFuturelet" can
%%# be used to check for optional flags. Frequently you will only want
%%# to test for one particular flag and decide the next action on this flag.
%%# Of course, you can test the token found with \ifx...\f", but this has the
%%# disadvantage that some tokens (e.g. \fi) follow your action, which might
%%# be bad (recall that e.g. \toolboxGobbleNext must be the last command of
%%# your action, i.e. it would in the above examples not gobble the "*" but
%%# the "\fi" which is probably not what you want).
%%# The simplest solution is to use the command \toolboxIfNextToken which
%%# already has the test included. For example, to test for an optional "[",
%%# you can simply write
%%#
%%# \def\MacroWithOptionalBrace{\toolboxIfNextToken[{\yes}{\no}}
%%#
%%# and then the call "\MacroWithOptionalBrace[...]" will expand to "\yes[...]"
%%# while "\MacroWithOptionalBrace x" will expand to "\no x"
%%# (note that the brace is not gobbled - if you want the latter,
%%# use "\toolboxIfNextGobbling" described below).
%%# More precisely, the calling syntax of "\toolboxIfNextToken" is
%%#
%%# \toolboxIfNextToken{token}{IfPart}{ElsePart}
%%#
%%# The semantic is the following:
%%# If the token following this command is `token', then IfPart is executed,
%%# otherwise ElsePart. It is explicitly admissible that `token' is a space.
%%# To support further tests, \toolboxToken is \let to the token which follows
%%# the command. \toolboxToken is only a temporary token, i.e.
%%# it may also be modified by other commands of this package; in particular,
%%# you may also freely to modify \toolboxToken.
%%# The token \toolboxSpaceToken which is described later may be handy
%%# in connection with this command.
%%#
%%# In contrast to similar LaTeX2e macros much care has been taken
%%# that spaces are not eaten. This solves the following problem:
%%#
%%# Assume that you want to write a macro which should have the calling syntax
%%# "\mymacro{arg1}" or "\mymacro{arg1}[arg2]". You will probably implement
%%# \mymacro to read the first argument and then to look whether the next
%%# token is a "[". If you use the LaTeX2e macro to test for "[",
%%# then all spaces until the next non-space token would be gobbled which means
%%# that if you would use the LaTeX2e macros for the test, then the call
%%# "\mymacro{arg1} Text" would behave like "\mymacro{arg1}Text",
%%# i.e. the space is `mysteriously' lost. With the "toolbox" macros this
%%# does not happen. The `disadvantage' is that "\mymacro{arg1} [arg2]"
%%# is not the same as "\mymacro{arg1}[arg2]" (which is reasonable IMHO).
%%#
%%# Example:
%%#
%%# \def\mycmd#1{\toolboxIfNextToken[{\ParseOpt{#1}}{\NoOpt{#1}}}
%%# \def\ParseOpt#1[#2]{\OptAtEnd{#1}{#2}}
%%#
%%# After the above definition, \mycmd{arg} executes \NoOpt{arg} while
%%# \mycmd{arg}[optional] executes \OptAtEnd{arg}{optional}
%%# We point out once more that in the first call a space following
%%# \mycmd{arg} does not vanish (as would be the case if the LaTeX 2e macros
%%# would have been used).
%%# If \toolboxIfNextToken has found the required token, it does *not*
%%# gobble that token from the token stream. Of course, you can do this by
%%# yourself using the earlier described macro \toolboxGobbleNext. However,
%%# it is simpler to use
%%#
%%# \toolboxIfNextGobbling{token}{IfPart}{ElsePart}
%%#
%%# This command is analogous to \toolboxIfNextToken with the difference that
%%# in the case that the next token is the desired token, it is gobbled before
%%# IfPart is executed.
%%#
%%# Example:
%%#
%%# \def\myloop{\toolboxIfNextGobbling*\toolboxTokenLoop\toolboxLoop}
%%#
%%# This makes \myloop*... behave like \toolboxTokenLoop, and
%%# \myloop... (without *) behave like \toolboxLoop.
%%# The following macro is one which you may want to use in connection with
%%# LaTeX 2e optional arguments:
%%#
%%# \toolboxIfEmpty{arg}{IfPart}{ElsePart}
%%#
%%# The argument is not expand; it is only used to decide whether the
%%# {IfPart} or the {ElsePart} will be expanded.
%%# For further tests there are more involved macros:
%%#
%%# \toolboxIfx{arg}\macro{IfPart}{ElsePart}
%%#
%%# This tests via \ifx whether \def\Macro{arg} would give the definition
%%# of \macro.
%%#
%%# \toolboxIfX{arga}{argb}{IfPart}{ElsePart}
%%#
%%# This tests whether "arga" and "argb" are the same token sequences.
%%# If you want to avoid the \else and \fi commands to avoid certain side
%%# effects, you can use instead:
%%#
%%# \toolboxIfElse{ifcmd}{IfPart}{ElsePart}
%%#
%%# This is rather analogous to "ifcmd" IfPart \else ElsePart \fi
%%# but has everything in this line already eliminated from the tokenlist
%%# when IfPart resp. ElsePart are expanded.
%%#
%%# Loops over tokenlists and itemlists
%%# -----------------------------------
%%# \toolboxLoop{items}{action}
%%#
%%# This calls iteratively "action{#1}", where #1 runs over each item in the
%%# argument items. Here, an item is either a token or a group braced by {...}.
%%# In the latter case, the braces are lost. Spaces in items are ignored
%%# (unless they are braced). It is admissible that \action is not a single
%%# macro but instead a sequence of tokens.
%%# Examples follow below.
%%#
%%# The counterintuitive order of arguments is explained by the fact that the
%%# typical usage is
%%# \expandafter\toolboxLoop\expandafter{\MacroExpandingToItems}{action}
%%# which for swapped order of arguments could hardly be written.
%%# \toolboxLoop is not reentrant i.e. "action" may not expand
%%# to something which contains a call to \toolboxLoop. To enable such calls
%%# anyway, the command
%%#
%%# \toolboxLoopName{name}{items}{\action}
%%#
%%# is provided which is analogous to \toolboxLoop. This is also not reentrant,
%%# but in contrast to \toolboxLoop, calls with different `name' arguments can
%%# be used independently of each other, i.e. in the `action' part of a
%%# \toolboxLoop (or \toolboxLoopName) can be a call to \toolboxLoopName with
%%# a *different* `name'.
%%# In particular, using a counter in `name' one could easily implement
%%# even recursive calls. In this connection, it should be noted that
%%# `name' is expanded via \csname ... \endcsname, and so you may use
%%# constructs like \the\namecounter there.
%%# \toolboxTokenLoop{tokens}{\action}
%%#
%%# This is similar to \toolboxLoop: The command \action\toolboxToken
%%# is executed iteratively where \toolboxToken runs over each token in tokens.
%%# The important difference is that \toolboxToken is a token (instead of an
%%# item). In particular, \toolboxToken runs through every single token
%%# including spaces and braces.
%%# The token \toolboxSpaceToken which is described later may be handy
%%# in connection with this command.
%%#
%%# Example:
%%#
%%# \toolboxTokenLoop{Some text}{\kern0.1em}
%%#
%%# is the similar to "\kern0.1em S\kern0.1em o\kern0.1em m...", i.e. you
%%# get wider spacing between the letters of "Some text" (I do not claim that
%%# this is typographically a good idea).
%%#
%%# Note that you do not have to take special care about the space.
%%# With \toolboxLoop, you would have to mask the space e.g. with
%%#
%%# \toolboxLoop{Some{ }text}{\kern0.1em} or
%%# \toolboxLoop{Some\toolboxSpace text}{\kern0.1em}
%%#
%%# In contrast, \toolboxTokenLoop would behave differently here:
%%#
%%# \toolboxTokenLoop{Some{ }text}{\kern0.1em}
%%#
%%# would produce \kern0.1em S...\kern0.1em{\kern0.1em <space>\kern0.1em}...
%%# because the braces are simply considered as tokens.
%%# \toolboxTokenLoop is not reentrant. Analogously to \toolboxLoopName,
%%# independent versions can be generated by
%%#
%%# \toolboxTokenName{name}{tokens}{\action}
%%#
%%# Controlled expansion
%%# --------------------
%%# There are some occasions when you want more control over the expansion.
%%# E.g. you might want to concatenate the contents of two macros to a
%%# further macro or you want to expand a macro by one level but no full
%%# expansion. Usually you can get this effects with \expandafter, but if
%%# you expand several concatenated tokens in this way you either have to
%%# write a lot of \expandafter's or you have to define subsidiary macros
%%# that help you to \expandafter certain parts of macros. The macros in
%%# this section allow you to do this in the most generic way that I could
%%# implement.
%%# \toolboxDef\macrotodefine{argumentlist}
%%#
%%# This call is similar to
%%# \def\macrotodefine{argumentlist}
%%# with two important differences:
%%#
%%# For \toolboxDef, the argumentlist is expanded precisely by one level.
%%# argumentlist may not contain macros with parameters, and spaces on the
%%# highest level are ignored. If you want to force a space on a particular
%%# place, use the macro \toolboxSpace at this place
%%# (which is described later). Contrary to the usual \def, the symbol # is
%%# treated as a usual symbol.
%%#
%%# Example of usage:
%%# \toolboxDef\chain{\chain\toolboxSpace\after}
%%# This modifies the macro \chain such that a space and the content of the
%%# macro \after is appended at the end.
%%# \toolboxAppend\macrotodefine{arglist}
%%#
%%# This is equivalent to \toolboxDef\macrotodefine{\macrotodefine arglist}
%%#
%%# \toolboxSurround{ContentBefore}{ContentAfter}\macro
%%#
%%# This redefines \macro such that ContentBefore is put at the beginning
%%# and ContentAfter after the definition of \macro. So this is equivalent to
%%# \def\macro{ContentBefore * ContentAfter}
%%# where * is the old content of \macro. It is required that \macro is a
%%# usual macro without any arguments. If you want to patch more complicated
%%# macros, use the patch.doc package instead.
%%# The order of the arguments may appear strange, but it is convenient if
%%# ContentBefore or ContentAfter are macros which should be expanded with
%%# \expandafter.
%%# There is some subsidiary macro used in the implementation of the above
%%# macros which might be useful also in some other situations:
%%#
%%# \toolboxTokDef{argumentlist}\macrotodefine
%%#
%%# This call is similar to
%%# \def\macrotodefine{argumentlist}
%%# with the difference that the symbol # is stored as such.
%%# The order of the arguments has been swapped in order to simplify the
%%# application of \expandafter to the argumentlist.
%%#
%%# Searching, splitting, and replacing
%%# ----------------------------------
%%# \toolboxSplitAt{argument}{search}{\beforestring}{\afterstring}
%%#
%%# Here, \beforestring and \afterstring are arbitrary macro names,
%%# and search and argument are any sequences of tokens (which are in
%%# the following considered as `strings').
%%#
%%# This call scans the string `argument' for the first occurrence of `search'.
%%# The macros \beforestring and \afterstring are defined correspondingly
%%# such that \beforestring expands to the part before the first occurrence,
%%# and \afterstring to the part following the first occurrence.
%%# If `search' does not occur in `argument', \beforestring is defined to
%%# `argument', and \afterstring is \let \undefined.
%%#
%%# If \beforestring or \afterstring had already been defined before the
%%# call, the previous definition is tacitly overridden.
%%# It is explicitly allowed that \beforestring and \afterstring are the
%%# same names. In this case, the result has the meaning of \afterstring.
%%#
%%# It is guaranteed that braces {...} are *not* lost in `argument'.
%%# However, `search' may not contain any braces, and `argument' may contain
%%# only matching pairs of braces. Moreover, occurrences of `search' within a
%%# pair of braces in `argument' are not recognized.
%%#
%%# (The order of the arguments has been chosen in order to simplify the
%%# use of \expandafter).
%%#
%%# There are some restrictions for the strings in search. For example,
%%# the symbol '#' is not allowed.
%%#
%%# In the above call, the arguments may not run over several paragraphs.
%%# If you want the latter, you have to use the alternative call
%%#
%%# \toolboxSplitAt*{argument}{search}{\beforestring}{\afterstring}
%%#
%%# Example of usage:
%%#
%%# \def\examplemacro#1{\toolboxSplitAt{#1}{@}\testme\testme
%%# \ifx\testme\undefined
%%# ... (do this when #1 contains no `@' token)
%%# \fi}
%%#
%%# \toolboxMakeSplit{search}{command}
%%#
%%# If \toolboxSplitAt should be used several times with the same search
%%# string, it is much more effective to use the above call: This call
%%# defines a new macro \command (the name is determined by the second argument
%%# of \toolboxMakeSplit) which can be called in the form
%%#
%%# \command{argument}{\beforestring}{\afterstring}
%%#
%%# and which has the analogous meaning as \toolboxSplitAt (the argument
%%# {search} is implicitly fixed and taken from the call of
%%# \toolboxMakeSplit).
%%# It is explicitly admissible that the above macro \toolboxMakeSplit is
%%# used with an already existing command name. In this case, the previous
%%# definition of \command is tacitly overridden.
%%#
%%# The command created by \toolboxMakeSplit does not accept arguments which
%%# run over several paragraphs. If you want the latter, you have to create
%%# this command by the alternative call
%%#
%%# \toolboxMakeSplit*{search}{command}
%%#
%%# The command
%%# \toolboxFreeSplit{command}
%%# frees the memory used by a previous \toolboxMakeSplit (and lets \command
%%# again be undefined).
%%# The command
%%# \toolboxReplace{search}{replace}\macro
%%# replaces in \macro all occurences of {search} by {replace}.
%%# The same matches are found as in \toolboxSplitAt.
%%# If you need to search for the same text several times, it is faster
%%# to use the command
%%# \toolboxReplaceSplit{replace}\SplitCmd\macro
%%# where \SplitCmd is a command previously generated with \toolboxMakeSplit*
%%# according to your search string. (You could also use \toolboxMakeSplit
%%# to generate \SplitCmd, but then \macro should not contain any \par's).
%%#
%%# Redefinition of macros
%%# ----------------------
%%# \toolboxMakeHarmless{\macro}
%%#
%%# The above call redefines \macro such that it expands to an ASCII text
%%# containing the previous definition of \macro (i.e. the catcodes of \macro
%%# are changed).
%%# \toolboxDropBrace\variable
%%#
%%# drops possible outer braces in \variable. More precisely,
%%# if \variable expands to {content}, then \variable is redefined to
%%# content (without braces). Otherwise, nothing happens.
%%#
%%# \toolboxIf\comparison{DefinitionCommand}{\macro}...
%%#
%%# The above command allows conditional definitions.
%%# Here, {DefinitionCommand} is either \def, {\long\def}, \let, or some
%%# similar command like the LaTeX \newcommand. If the test
%%# \ifx\comparison\macro evaluates positive, then \macro is defined
%%# correspondingly. Otherwise, \macro is not changed.
%%#
%%# Examples:
%%#
%%# \toolboxIf\undefined\def\macro{....}
%%# \toolboxIf\undefined\let\macro...
%%# \toolboxIf\undefined{\long\def}\macro{....}
%%# \toolboxIf\undefined\newcommand{\macro}{....}
%%#
%%# are similar to \def\macro{...} resp. \let\macro... resp.
%%# \long\def\macro{...} resp. \newcommand{\macro}{...} with the difference
%%# that \macro is not changed if it was already defined.
%%# In this sense, \toolboxIf is a more flexible variant of \providecommand.
%%#
%%# \toolboxNewiftrue{name} or \toolboxNewiffalse{name}
%%#
%%# If the command \ifname was already introduced with \newif, then
%%# nothing happens. Otherwise \ifname is introduced similarly to
%%# \newif\ifname and set to `true' respectively `false'.
%%# In contrast to the corresponding command in TeX or LaTeX 2.09, this macro
%%# is not \outer!
%%# \toolboxNewifTrue{name} or \toolboxNewifFalse{name}
%%#
%%# are similar to \toolboxNewiftrue{name} and \toolboxNewiffalse{name},
%%# respectively, with the difference that \ifname is set unconditionally
%%# to `true' respectively `false'.
%%#
%%# Concatenated macro names
%%# ------------------------
%%# \toolboxLet\variable{macroname}
%%#
%%# The above command is analogous to \let\variable\macroname with the
%%# difference that macroname can also contain other tokens like numbers
%%# (it is obtained via \csname). Some converse to this command is
%%#
%%# \toolboxWithNr {number}\cmd{macro}
%%#
%%# which translates into \cmd\macronumber (here, `macro' and `number'
%%# are just concatenated and evaluated via \csname).
%%# Examples:
%%# \toolboxWithNr 1\let{name}\toolboxEmpty
%%# This is the same as \let\name1\toolboxEmpty
%%# (but such that \name1 is considered as a name, not as \name 1)
%%# \toolboxWithNr {10}\def{name}{Foo}
%%# This corresponds analogously to \def\name10{Foo}.
%%# \toolboxLet \mymacro{name\the\mycount}
%%# This is similar to \let\mymacro\namexx where xx is the content
%%# of the counter \mycount.
%%#
%%# Various
%%# -------
%%# The following macros have equivalents in most formats (like LaTeX2e).
%%# However, we do not want to rely too much on these formats, so we provide
%%# our own definitions.
%%# The macro
%%# \toolboxEmpty
%%# expands to nothing (usually, this is the same as \empty).
%%# Similarly, the macro
%%# \toolboxSpace
%%# expands to a space symbol (usually, this is the same as \space).
%%# The token
%%# \toolboxSpaceToken
%%# is \let a space token (usually, this is the same as \@sptoken).
%%# This token is convenient in tests of tokens
%%# (because it is hard to get a space there which is not eaten by the TeX
%%# parser, although sometimes also constructions like
%%# \expandafter\ifx\toolboxSpace\token can be used).
%%# Also the macros
%%# \toolboxFirstOfTwo
%%# \toolboxSecondOfTwo
%%# are provided which read two arguments and return only the first
%%# respectively second argument (usually, this is the same as
%%# \@firstoftwo respectively \@secondoftwo). Similarly,
%%# \toolboxGobbleArg{argument}
%%# just reads its argument and expands to nothing.
% This is the end of the ascii documentation
%</asciidocu>
%\fi\catcode\#6\relax
%
% \iffalse
%<*metainfo>
% \fi
% \def\basename{toolbox}
%% \CharacterTable
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%% Digits \0\1\2\3\4\5\6\7\8\9
%% Exclamation \! Double quote \" Hash (number) \#
%% Dollar \$ Percent \% Ampersand \&
%% Acute accent \' Left paren \( Right paren \)
%% Asterisk \* Plus \+ Comma \,
%% Minus \- Point \. Solidus \/
%% Colon \: Semicolon \; Less than \<
%% Equals \= Greater than \> Question mark \?
%% Commercial at \@ Left bracket \[ Backslash \\
%% Right bracket \] Circumflex \^ Underscore \_
%% Grave accent \` Left brace \{ Vertical bar \|
%% Right brace \} Tilde \~}
% \CheckSum{736}
% \iffalse
% \RecordChanges
% \fi
% \def\mypar{}
% \def\ChangesTab{}\let\orichanges\changes
% \def\changes#1#2#3{\orichanges{#1}{#2}{#3}
% \expandafter\def\expandafter\ChangesTab\expandafter{\ChangesTab
% \item[v#1 {\mdseries(\emph{#2})}] {#3.}}}
% \newcommand{\cmdcite}[1]{\texttt{\textbackslash#1}}
% \newcommand{\bracemeta}[1]{\texttt{\{}\meta{#1}\texttt{\}}}
% \newcommand{\cmdmeta}{\textbackslash\meta}
% \changes{5.1}{2013/11/26}{Update email, add license. Date/version remains the
% same since only commments and documentation are modified}
% \changes{5.1}{2004/04/29}{Added \cmdcite{toolboxReplace},
% \cmdcite{toolboxReplaceSplit}. Some corrections in the documentation.
% Added some forgotten \cmdcite{long}'s in the code.}
% \changes{4.4}{2003/10/07}{Added \cmdcite{toolboxIfEmpty},
% \cmdcite{toolboxIfx}, \cmdcite{toolboxIfX}, \cmdcite{toolboxIfElse}.
% Some corrections in the documentation}
% \changes{4.3}{2002/09/27}{Major enhancements in documentation: Added lots
% of examples and explanation about typical applications.
% Bugfix in \cmdcite{toolboxMakeDef}:
% \cmdmeta{Prefix}\texttt{Provide}\meta{Name} now behaves like
% \cmdcite{providecommand} as documented. The old meaning is now called
% \cmdmeta{Prefix}\texttt{Def}\meta{Name}.
% Introduced \cmdcite{toolboxGobbleArg}}
% \changes{4.2}{2001/09/26}{Treating \texttt{\#} properly now also in
% \cmdcite{toolboxMakeDef}}
% \changes{4.1}{2001/09/24}{Took more care of treating \texttt{\#} properly
% when this symbol occurs in arguments of certain macros (the treatment is
% not completely downward compatible; for this reason the major release
% number has been changed). For this reason,
% also the new macro \cmdcite{toolboxTokDef} is provided. I thank
% David Kastrup \texttt{<David.Kastrup@neuroinformatik.ruhr-uni-bochum.de>}
% for pointing out this problem (and a solution) to me}
% \changes{3.3}{2001/08/19}{Eliminated a bug in \cmdcite{toolboxMakeSplit*}}
% \changes{3.2}{2001/05/08}{Eliminated a serious bug in \cmdcite{toolboxIf}.
% Due to this bugfix, the usage of \cmdcite{toolboxIf} had to be slightly
% restricted}
% \changes{3.1}{2001/05/06}{Major advantage: \cmdcite{toolboxMakeDef}
% implemented.\mypar
% Reimplemented \cmdcite{newif} (apparently by mistake, this had been
% declared as \cmdcite{outer} in \TeX\ and \LaTeX 2.09 which caused an
% error during loading of \texttt{toolbox.sty}).
% For this reason, also \cmdcite{toolboxNewifTrue} and
% \cmdcite{toolboxNewifFalse} were introduced}
% \changes{2.1}{2001/04/30}{Introduced \cmdcite{toolboxIf},
% \cmdcite{toolboxAppend}, and \cmdcite{toolboxSurround}}
% \changes{2.0}{2001/04/08}{Many major enhancements and new tools:
% Added section (and corresponding macros)
% for fancy optional arguments. Made \cmdcite{toolboxLoop} semi-reentrant by
% introducing \cmdcite{toolboxLoopName}.
% Added \cmdcite{toolboxTokenLoop} and friends.
% Added \cmdcite{toolboxSpaceToken}.
% Made many macros \cmdcite{long} and added \cmdcite{long} versions
% of \cmdcite{toolboxSplitAt} and \cmdcite{toolboxMakeSplit}}
% \changes{1.0}{2001/03/29}{First release}
%
% \iffalse
%
% The following part is the code needed to compile the documentation.
% We do some trickery here, because we want that this file here could be used
% for *both*: Compiling the documentation *and* as `toolbox.sty'
% (if really required).
% Everything between the lines %<*driver> and %</driver>
% goes to the file `toolbox.tex'.
%
% \fi
\ifcat @a% If this test is positive, then `@' has letter catcode which means
% that this file is loaded as a style file (or as described in the
% install section of the documentation).
\def\TemporaryDummy{}
\else\long\def\TemporaryDummy{%
%
%
% \iffalse
%</metainfo>
%<*driver>
\documentclass{ltxdoc}
\OnlyDescription%% Comment this out, or
%%\AlsoImplementation%% uncomment this line, if you want to see the source.
%% If you want an index, uncomment one of the following lines.
%% After running latex a first time, you have to use
%% makeindex -s gind.ist toolbox
%% Then run latex again.
%%\CodelineIndex% comment this out if you want an index referring to codelines
%%\PageIndex% comment this out if you want an index referring to pages
%%\OldMakeindex% uncomment this line, if your MakeIndex is pre-v2.9
\setlength\hfuzz{15pt}
\hbadness=7000
\begin{document}
\DocInput{toolbox.dtx}
\end{document}
%</driver>
%<*metainfo>
% \fi
}
\fi\TemporaryDummy\let\TemporaryDummy\undefined
%
% \iffalse
% Personal macros used for the doc utility:
% \fi
% \MakeShortVerb{"}
% \newcommand{\filecite}[1]{\texttt{#1}}
% \newcommand{\nocomment}{}
% \newcommand{\myspace}{\texttt{\textvisiblespace}}
% \parindent0pt
% \title{The \texttt{toolbox} package\thanks
% {This package has version number \fileversion{}, last revised \filedate.
% The package may be distributed and/or modified under the conditions of the
% LaTeX Project Public License, either version 1.3c of this license or (at
% your option) any later version. The latest version of this license is in
% \texttt{http://www.latex-project.org/lppl.txt}, and version 1.3c or later
% is part of all distributions of LaTeX version 2005/12/01 or later.}}
% \author{Martin V\"ath\relax
%\thanks{\texttt{martin@mvath.de}}
%{}\thanks{The author thanks
%David Kastrup \texttt{<David.Kastrup@neuroinformatik.ruhr-uni-bochum.de>}.
%}}
% \date{\docdate}
% \maketitle\sloppy
% \begin{abstract}
% The \TeX\ programmer's toolbox; enhanced version.
% This package provides some macros which are convenient for writing
% indices, glossaries, or other macros. It contains macros which support
% \begin{itemize}
% \item implicit macros -- a useful supplement to \cmdcite{index} or
% \texttt{varindex} for writing glossaries or indices.
% \item fancy optional arguments
% \item loops over tokenlists and itemlists
% \item searching, splitting, and replacing
% \item controlled expansion
% \item redefinition of macros
% \item concatenated macro names
% \end{itemize}
% \end{abstract}
% You may copy this package freely, as long as you distribute only unmodified
% and complete versions.
% \tableofcontents
% \section{Changes}
%
% \begin{description}
% \def\mypar{\par}\ChangesTab
% \end{description}
%
% \section{Installation}
% This package was tested with \TeX, \LaTeX 2.09, and \LaTeXe, and it
% should actually run with all other \TeX\ formats.
% To use \filecite{toolbox}, you have to put the file \filecite{toolbox.sty}
% in a path where \TeX\ looks for its input files. The \TeX\ documents using
% \filecite{toolbox} need the following modifications in their header:
%
% \begin{itemize}
% \item If you use \LaTeXe, put in the preamble the command
% \begin{verbatim}
% \usepackage{toolbox}\end{verbatim}
%
% \item If you use \LaTeX 2.09, use \filecite{toolbox} as a style option, e.g.\
% \begin{verbatim}
% \documentstyle[toolbox]{article}\end{verbatim}
% or
% \begin{verbatim}
% \documentstyle[toolbox,12pt]{article}\end{verbatim}
%
% \item If you use some other (non-\LaTeX) format, you will probably have to
% insert a line like
% \begin{verbatim}
% \catcode`\@=11\input toolbox.sty\catcode`\@=12\relax\end{verbatim}
%
% \end{itemize}
%
% The only \LaTeX-specific commands used in \filecite{toolbox.sty} are:
%
% \begin{itemize}
% \item "\newcommand" (used only in the form "\newcommand{"\meta{command}"}{}"
% to ensure that \meta{command} was not defined before)
% \item "\ProvidesPackage"
% \item "\typeout"
% \end{itemize}
% The above commands are used only if they are defined.
% \section{Description of the macros}
%
% General remark: Many macros could appear in several sections.
% For example, "\toolboxMakeDef" and "\toolboxSourround" might be considered
% as macros which support redefinitions of macros. However, we put them
% in different sections which perhaps explain better their nature.
%
% \subsection{Implicit macro definitions}
%
% What we mean by implicit macro definitions is probably best explained by
% the following examples which show the intended usage:\par\bigskip
%
% (In the following examples, we always refer to the "\index" command. Note
% that it may be more convenient to use for indices the \filecite{varindex}
% package in addition -- the documentation of \filecite{varindex}
% (release 2.3 or newer) gives additional hints and examples how these two
% (essentially independent) approaches can be combined in practice).
% \par\bigskip
%
% Assume that you want to write an index for a book which has rather
% long and complicated "\index" entries. The first idea that one might have in
% this connection is to put the various "\index" commands at the beginning of
% the document into several macros (one for each "\index" entry), and to use
% just these macros in the main text. For example, one might want to write
% near the beginning of the document commands like
% \begin{verbatim}
% \newcommand{\Start}{\index{finish or end}}
% \newcommand{\End}{\index{finish or end}}\end{verbatim}
% and then to use in the main text "\Start" and "\End" whenever a reference
% in the corresponding index to the current place is desired.
% However, this has two major disadvantages:
% \begin{enumerate}
% \item It is easy to forget that "\End" writes an index entry.
% So the macro "\End" in the main text might be very confusing.
% \item You cannot choose short and intuitive macro names for common phrases,
% because they are usually already reserved by \TeX, \LaTeX, or some
% packages. For example, "\end" could not be used.
% \end{enumerate}
% To avoid these problems, one may be very disciplinary and call the
% involved macros systematically e.g.\ "\GlossaryStart" "\GlossaryEnd" etc.
% However, this produces terrible long and unreadable macro names in the main
% text.\par\bigskip
% The implicit macro definitions of \filecite{toolbox} provide a more
% convenient solution.
% The idea is that you do not use the corresponding macros directly but only
% implicitly by a call of other macros where your ``macro name'' is just an
% argument.\par
% Moreover, \filecite{toolbox} assists you in writing the corresponding
% definitions.
% For example, if you know that you want a set of macros which all expand
% into something of the form "\index{...}", you can give a ``mask'' which
% contains this form, and you only have to fill in the changing content
% (similarly as for usual \TeX\ macros with arguments, but the level of
% abstraction is one step higher).
% For the above task, you might use the command:
% \begin{verbatim}
% \toolboxMakeDef{Glossary}{\index{#1}}\end{verbatim}
%
% The argument "Glossary" serves to distinguish independent definitions
% (this will become clear later). Its effect visible now is that it
% determines the name of the following macros which you can use after
% the above call:
% \begin{verbatim}
% \NewGlossary{start-1}{start}
% \NewGlossary{start-2}{start or beginning}
% \NewGlossary{end}{finish or end}\end{verbatim}
%
% These command are now similar to the "\newcommand" definitions explained
% above. However, there is no name collision with the \TeX-internal command
% "\end". Of course, this means that you cannot just write "\end" in the main
% text to get the desired index entry. Instead, you have to write the more
% intuitive commands
% \begin{verbatim}
% \Glossary{start-1}
% \Glossary{start-2}
% \Glossary{end}\end{verbatim}
% (again, the name "\Glossary" stems from our first call of "\toolboxMakeDef").
% Note that e.g.\ "\Glossary{start-1}" expands not only to "start" but
% actually to "\index{start}" (because of our first call of
% "\toolboxMakeDef").\par
% Note also that you can use symbols like ``-'' or numbers which are
% usually not allowed in \TeX\ macro names.
%
% Of course, similarly as for "\newcommand", you can also do other things with
% the macros. For example,
% \begin{verbatim}
% \LetGlossary\tempname{end}
% \NewGlossary*{finish}\tempname\end{verbatim}
%
% will first define "\tempname" to expand to the same text as "\Glossary{end}",
% and then defines a new entry "\Glossary{finish}" to expand to the same text
% as "\tempname". Hence, the above two lines make the calls "\Glossary{end}"
% and "\Glossary{finish}" equivalent.
%
% At the end of your list of "\NewGlossary" commands, you might want to put
% \begin{verbatim}
% \toolboxFreeDef*{Glossary}\end{verbatim}
%
% The purpose of this command is that "\NewGlossary" cannot be used anymore
% (unless, of course, you define it again). So you cannot unintentionally
% add new entries to your glossary list (but you still can use "\Glossary{...}"
% to reference to the already produced entries).
% Moreover, the above command frees some memory which was needed for
% "\NewGlossary" to work.
%
% If you additionally want to free the memory used by "\Glossary", you can use
% \begin{verbatim}
% \toolboxFreeDef{Glossary}\end{verbatim}
%
% (without the "*"). This may be necessary, if you want to call again e.g.
% \begin{verbatim}
% \toolboxMakeDef{Glossary}{\emph{#1}\index{#1}}\end{verbatim}
%
% (if you have not freed the memory for "\Glossary" before this repeated call,
% \TeX\ will complain that "\Glossary" is already defined).\par\smallskip
%
% Of course, it is possible to call "\toolboxMakeDef" with several different
% names, for example, for "\Glossary", "\SymbolList" etc. Another application
% might be to use a different command to mark e.g.\ the main occurrence of
% some index entry or to output additionally the entry into the running text.
% We do this in the following example which simultaneously
% demonstrates that the names can also be constructed in another way:
% \begin{verbatim}
% \toolboxMakeDef[Ind]{}{\index{#1}}
% \toolboxMakeDef[Ind]{Main}{\index{#1|textbf}}
% \toolboxMakeDef{OutInd}{#1}
%
% \IndNew{A}{A is a letter}
% \IndNewMain{A}{A is a letter}
% \NewOutInd{A}{\textbf{The letter A}\Ind{A}}\end{verbatim}
% After the above commands, you can use "\Ind{A}", "\IndMain{A}", and
% "\OutInd{A}" to produce the corresponding "\index" entry, the ``main''
% "\index" entry (with a fat page number), and the text \textbf{The letter A}
% with an additional entry into the index, respectively.
% Of course, it might usually be more convenient to define the "\Ind" and
% "\IndMain" entries simultaneously, e.g.\ by the commands
% \begin{verbatim}
% \toolboxMakeDef[Ind]{}{#1}
% \toolboxMakeDef[Ind]{Main}{#1}
% \newcommand{\NewStandardInd}[2]{%
% \IndNew{#1}{\index{#2}}%
% \IndNewMain{#1}{\index{#2|textbf}}}
%
% \NewStandardInd{A}{A is a letter}\end{verbatim}
% This approach has the additional advantage that you can define exceptional
% cases ``by hand'' (e.g.\ if you want that for certain ``main'' index
% entries the page number is printed with "\textsl" instead of "\textbf").
% \bigskip
%
% Since the motivation for implicit definitions now is hopefully clear,
% let us now describe in detail which commands are provided by
% \filecite{toolbox} for this purpose.
% As explained in the example, the main generic macro provided to this
% purpose is \DescribeMacro{\toolboxMakeDef}"\toolboxMakeDef".
% Its call syntax is as follows:
% \begin{quote}
% "\toolboxMakeDef["\meta{Prefix}"]"\bracemeta{Name}\relax
%\bracemeta{Replacement mask}
% \end{quote}
% (the argument "["\meta{Prefix}"]" is optional and by default empty).
% The above command generates new macros
%
% \begin{quote}
% \cmdmeta{Prefix}"New"\meta{Name}\\
% \cmdmeta{Prefix}"Renew"\meta{Name}\\
% \cmdmeta{Prefix}"Provide"\meta{Name}\\
% \cmdmeta{Prefix}"Def"\meta{Name}\\
% \cmdmeta{Prefix}"Let"\meta{Name}\\
% \cmdmeta{Prefix}\meta{Name}
% \end{quote}
% which in turn can be called as follows:
% \begin{quote}
% \cmdmeta{Prefix}"New"\meta{Name}\bracemeta{something}\relax
%\bracemeta{text to remember}\\
% \cmdmeta{Prefix}"Renew"\meta{Name}\bracemeta{something}\relax
%\bracemeta{text to remember}\\
% \cmdmeta{Prefix}"Provide"\meta{Name}\bracemeta{something}\relax
%\bracemeta{text to remember}\\
% \cmdmeta{Prefix}"Def"\meta{Name}\bracemeta{something}\relax
%\bracemeta{text to remember}\\
% \cmdmeta{Prefix}"New"\meta{Name}"*"\bracemeta{something}\relax
%{\cmdmeta{SomeMacro}}\\
% \cmdmeta{Prefix}"Renew"\meta{Name}"*"\bracemeta{something}\relax
%{\cmdmeta{SomeMacro}}\\
% \cmdmeta{Prefix}"Provide"\meta{Name}"*"\bracemeta{something}\relax
%{\cmdmeta{SomeMacro}}\\
% \cmdmeta{Prefix}"Def"\meta{Name}"*"\bracemeta{something}\relax
%{\cmdmeta{SomeMacro}}\\
% \cmdmeta{Prefix}"Let"\meta{Name}{\cmdmeta{SomeMacro}}\bracemeta{something}\\
% \cmdmeta{Prefix}\meta{Name}\bracemeta{something}\\
% \cmdmeta{Prefix}\meta{Name}"*"\bracemeta{something}
% \end{quote}
% These calls are in a sense similar to the respective commands
% \begin{quote}
% "\newcommand{"\cmdmeta{something}"}"\bracemeta{text to remember}\\
% "\renewcommand{"\cmdmeta{something}"}"\bracemeta{text to remember}\\
% "\providecommand{"\cmdmeta{something}"}"\bracemeta{text to remember}\\
% "\def"\cmdmeta{something}\bracemeta{text to remember}\\
% "\newcommand{"\cmdmeta{something}"}{}"\relax
%"\let"\cmdmeta{something}\cmdmeta{SomeMacro}\\
% "\renewcommand{"\cmdmeta{something}"}{}"\relax
%"\let"\cmdmeta{something}\cmdmeta{SomeMacro}\\
% "\@ifundefined"\bracemeta{something}"{\let"\relax
%\cmdmeta{something}\cmdmeta{SomeMacro}"}{}"\\
% "\let"\cmdmeta{something}\cmdmeta{SomeMacro}\\
% "\let"\cmdmeta{SomeMacro}{\cmdmeta{something}}\\
% \cmdmeta{something}\\
% \cmdmeta{something} (but without error if \cmdmeta{something} is undefined)
% \end{quote}
% with the differences already pointed out before:
% \begin{enumerate}
% \item The macro name actually used is not \cmdmeta{something}.
% Instead, it is a name which does not conflict with any existing macro
% (except one generated previously by another \cmdmeta{Prefix}New\meta{Name},
% but in this case a descriptive error is reported).\par
% For this reason, it is not possible to use this macro directly but only
% indirectly by the call \cmdmeta{Prefix}\meta{Name}\bracemeta{something}
% (or with \cmdmeta{Prefix}Let\meta{Name}).
% \item The replacement text is not \meta{text to remember} but determined by
% \meta{Replacement Mask} where every occurrence of "#1" in
% \meta{Replacement Mask} is replaced by \meta{text to remember}
% (recall the examples). If you want to have the plain
% \meta{text to remember}, use "{#1}" as \meta{Replacement Mask}.
% \end{enumerate}
% Since \filecite{toolbox~4.2} there is another slight difference:
% The symbol "#" is treated as usual and not as in a macro definition.\par
%
% "\toolboxMakeDef" gives an error message if the commands
% \cmdmeta{Prefix}"..." are already defined. If you intentionally want to
% change a previous definition, you have to call the command
%
% \begin{quote}
% \DescribeMacro{\toolboxFreeDef}
% "\toolboxFreeDef["\meta{Prefix}"]"\bracemeta{Name}
% \end{quote}
% before. The latter not only lets all of the macros \cmdmeta{Prefix}"..." be
% "\undefined", but also frees all other memory internally used by the
% corresponding call of "\toolboxMakeDef"
% (note, however, that the above command does not free the
% memory allocated before by calls of \cmdmeta{Prefix}"New..." -- to free the
% latter, you have to call subsequently e.g.
% \begin{quote}
% \cmdmeta{Prefix}"New"\meta{Name}"*{"$\ldots$"}{\undefined}"
% \end{quote}
% before). There is also the command
% \begin{quote}
% "\toolboxFreeDef*["\meta{Prefix}"]"\bracemeta{Name}
% \end{quote}
% which acts similarly as "\toolboxFreeDef" but which does not undefine the
% two macros \cmdmeta{Prefix}\meta{Name} and \cmdmeta{Prefix}"Let"\meta{Name}.
%
% \subsection{Fancy optional argument parsing}
%
% This section contains macros which are convenient if you e.g.\ write a
% package that contains macros which contain a lot of optional arguments
% and flags (like "*").
% Typically, to read such an optional argument or flag, you save
% the next token with "\futurelet" and then call a macro which decides what to
% do with the token read. Thus, a typical use of "\futurelet" looks like
% \begin{verbatim}
% \def\MacroWithOptionalFlag{\futurelet\tokread\myscan}\end{verbatim}
% which will define "\tokread" to be the token \emph{following} the macro
% "\MacroWithOptionalFlag" in the token stream and then execute "\myscan".
% In this context, it is not very convenient that you
% are \emph{forced} to define a macro "\myscan": It could be more convenient
% if you could just write the \emph{content} of "\tokread" (in braces) into
% the above definition. You can indeed do this if you replace "\futurelet"
% by \DescribeMacro{\toolboxFuturelet}"\toolboxFuturelet":
%
% \begin{quote}
% "\toolboxFuturelet\token"\bracemeta{argument}
% \end{quote}
%
% The call "\toolboxFuturelet\token{\command}" has precisely the same
% effect as "\futurelet\token\command". The advantage of "\toolboxFuturelet"
% is that instead of a single "\command" one may use also a sequence of
% commands.\par
% Let us consider "\MacroWithOptionalFlag" as above. Assume that the user
% has called this macro in the form "\MacroWithOptionalFlag*" where the
% "*" is a flag which should cause your macro to do something slightly
% different. On some place in your macro definition you will have recognized
% (e.g.\ with "\futurelet" or "\toolboxFuturelet") that a "*" is following
% in the calling sequence. So you now want to execute your action
% (whatever "\MacroWithOptionalFlag" is supposed to do).
% However, if you do not take special care, after this action, \TeX\ will
% print a "*", because this is the next token on the token stream: "\futurelet"
% does not delete any tokens. So you have to ``gobble'' this token away.
% A rude way to do this is by using the macro "\gobblenext" as the last token
% in you macro which can be defined by
% \begin{verbatim}
% \def\gobblenext#1{}\end{verbatim}
% However, this has two major drawbacks:
% \begin{enumerate}
% \item This works for "*", but not for "{" or space tokens.
% For space tokens the situation is even worse, since \TeX\ eats spaces around
% arguments, so sometimes space tokens might unexpectedly disappear.
% \item It is not possible in this way to \emph{read} another argument
% following the "*": Recall that "\gobblenext" must be the \emph{last} token
% in your macro expansion, i.e.\ you have ``lost control'' after this call.
% \end{enumerate}
% The solution to these problems is instead of calling "\gobblenext" to use
% \DescribeMacro{\toolboxGobbleNext}"\toolboxGobbleNext" as the last command
% in your call: You can pass it an argument which describes the action that
% you want to do \emph{after} gobbling the next token
% ("*" in the above example) from the token stream. Thus
% \begin{quote}
% "\toolboxGobbleNext"\bracemeta{cmd}
% \end{quote}
% erases the token following that command from the token stream and
% then executes \meta{cmd}. This is similar to
% \begin{verbatim}
% \def\toolboxGobbleNext#1#2{#1}\end{verbatim}
% with the difference that "#2" is considered as a token and that no spaces
% are eaten.\par
% The effect is that e.g.\ the call
% \begin{verbatim}
% \toolboxGobbleNext{\foo}{{arg}\end{verbatim}
% is the same as "\foo{arg}" (the brace "{" is eaten in this example).\par
% As described earlier, the commands "\futurelet" or "\toolboxFuturelet" can
% be used to check for optional flags. Frequently you will only want
% to test for one particular flag and decide the next action on this flag.
% Of course, you can test the token found with "\ifx...\fi" but this has the
% disadvantage that some tokens (e.g.\ "\fi") follow your action, which might
% be bad (recall that e.g.\ "\toolboxGobbleNext" must be the last command of
% your action, i.e.\ it would in the above examples not gobble the "*" but
% the "\fi" which is probably not what you want).
% The simplest solution is to use the command
% \DescribeMacro{\toolboxIfNextToken}"\toolboxIfNextToken" which already
% has the test included. For example, to test for an optional "[", you can
% simply write
% \begin{verbatim}
% \def\MacroWithOptionalBrace{\toolboxIfNextToken[{\yes}{\no}}\end{verbatim}
% and then the call "\MacroWithOptionalBrace[...]" will expand to "\yes[...]"
% while "\MacroWithOptionalBrace x" will expand to "\no x" (note that the
% brace is not gobbled---if you want the latter, use "\toolboxIfNextGobbling"
% described below).\par
% More precisely, the calling syntax of "\toolboxIfNextToken" is
% \begin{quote}
% \DescribeMacro{\toolboxIfNextToken}
% "\toolboxIfNextToken"\bracemeta{token}\bracemeta{if}\bracemeta{else}
% \end{quote}
% The semantic is the following: If the token following this command is
% \meta{token}, then \meta{if} is executed, otherwise \meta{else}.
% It is explicitly admissible that \meta{token} is a space.
% To support further tests, \DescribeMacro{\toolboxToken}"\toolboxToken"
% is "\let" to the token which follows the command.
% "\toolboxToken" is only a temporary token,
% i.e.\ it may also be modified by other commands of this package;
% in particular, you may also freely modify "\toolboxToken".\par
% The token "\toolboxSpaceToken" which is described later may be handy
% in connection with this command.\par
% In contrast to similar \LaTeXe\ macros
% much care has been taken that spaces are not eaten. This solves the
% following problem:\par
%
% Assume that you want to write a macro which should have the calling syntax
% "\mymacro{arg1}" or "\mymacro{arg1}[arg2]". You will probably implement
% "\mymacro" to read the first argument and then to look whether the next
% token is a "[". If you use the \LaTeXe\ macro to test for "[",
% then all spaces until the next non-space token would be gobbled which means
% that if you would use the \LaTeXe\ macros for the test, then the call
% "\mymacro{arg1}"\myspace"Text" would behave like "\mymacro{arg1}Text",
% i.e.\ the space is ``mysteriously'' lost. With the \filecite{toolbox}
% macros this does not happen. The ``disadvantage'' is that
% "\mymacro{arg1}"\myspace"[arg2]" is not the same as
% "\mymacro{arg1}[arg2]" either (which is reasonable IMHO).
%
% Example:
% \begin{verbatim}
% \def\mycmd#1{\toolboxIfNextToken[{\ParseOpt{#1}}{\NoOpt{#1}}}
% \def\ParseOpt#1[#2]{\OptAtEnd{#1}{#2}}\end{verbatim}
% After the above definition, "\mycmd{arg}" executes "\NoOpt{arg}" while
% "\mycmd{arg}[optional]" executes "\OptAtEnd{arg}{optional}".
% We point out once more that in the first call a space following
% "\mycmd{arg}" does not vanish (as would be the case if the \LaTeXe\ macros
% would have been used).\par
% If "\toolboxIfNextToken" has found the required token, it does \emph{not}
% gobble that token from the token stream. Of course, you can do this by
% yourself using the earlier described macro "\toolboxGobbleNext". However,
% it is simpler to use
% \begin{quote}
% \DescribeMacro{\toolboxIfNextGobbling}
% "\toolboxIfNextGobbling"\bracemeta{token}\bracemeta{if}\bracemeta{else}
% \end{quote}
% This command is analogous to "\toolboxIfNextToken" with the difference that
% in the case that the next token is \meta{token}, it is gobbled before
% \meta{if} is executed.\par
%
% Example:
% \begin{verbatim}
% \def\my{\toolboxIfNextGobbling*\toolboxTokenLoop\toolboxLoop}\end{verbatim}
% This makes "\my*..." behave like "\toolboxTokenLoop..." and
% "\my..." (without "*") behave like "\toolboxLoop...".\par
% The following macro is one which you may want to use in connection with
% \LaTeX2e\ optional arguments:
%
% \begin{quote}
% \DescribeMacro{\toolboxIfEmpty}
% "\toolboxIfEmpty"\bracemeta{arg}\bracemeta{if}\bracemeta{else}
% \end{quote}
%
% \meta{arg} is not expand; it is only used to decide whether \meta{if} or
% \meta{else} will be expanded.\par
% For further tests there are more involved macros:
%
% \begin{quote}
% \DescribeMacro{\toolboxIfx}
% "\toolboxIfx"\bracemeta{arg}"\macro"\bracemeta{if}\bracemeta{else}
% \end{quote}
% This tests via "\ifx" whether "\def\Macro"\bracemeta{arg} would give
% the definition of "\macro".
%
% \begin{quote}
% \DescribeMacro{\toolboxIfX}
% "\toolboxIfX"\bracemeta{arg 1}\bracemeta{arg 2}\bracemeta{if}\bracemeta{else}
% \end{quote}
% This tests whether \meta{arg 1} and \meta{arg 2} are the same token
% sequences.\par
%
% If you want to avoid the "\else" and "\fi" commands to avoid certain side
% effects, you can use instead:
%
% \begin{quote}
% \DescribeMacro{\toolboxIfElse}
% "\toolboxIfElse"\bracemeta{ifcmd}\bracemeta{if}\bracemeta{else}
% \end{quote}
% This is rather analogous to \meta{ifcmd}\meta{if}"\else"\meta{else}"\fi"
% but has everything in this line already eliminated from the tokenlist when
% \meta{if} resp.\ \meta{else} are expanded.
% \subsection{Loops over tokenlists and itemlists}
%
% \begin{quote}
% \DescribeMacro{\toolboxLoop}
% "\toolboxLoop"\bracemeta{items}\bracemeta{action}
% \end{quote}
%
% This calls iteratively \meta{action}"{#1}", where "#1" runs over each item in
% \meta{items}. Here, an item is either a token or a group
% braced by "{...}".
% In the latter case, the braces are lost. Spaces in \meta{items} are ignored
% (unless they are braced). It is admissible that \meta{action} is not a single
% macro but instead a sequence of tokens.\par
% Examples follow below.\par
% The counterintuitive order of arguments is explained by the fact that the
% typical usage is
% \begin{quote}
% "\expandafter\toolboxLoop\expandafter{\ExpandingMacro}"\bracemeta{action}
% \end{quote}
% which for swapped order of arguments could hardly be written.\par
%
% "\toolboxLoop" is not reentrant, i.e.\ \bracemeta{action} may not expand
% to something which contains a call to "\toolboxLoop". To enable such calls
% anyway, the command
% \begin{quote}
% \DescribeMacro{\toolboxLoopName}
% "\toolboxLoopName"\bracemeta{name}\bracemeta{items}\bracemeta{action}
% \end{quote}
% is provided which is analogous to "\toolboxLoopName". This is also
% not reentrant, but in contrast to "\toolboxLoop",
% calls with different \meta{name} can
% be used independently of each other, i.e.\ in the \bracemeta{action} part
% of a "\toolboxLoop" (or "\toolboxLoopName") can be a call to
% "\toolboxLoopName" with a \emph{different} \meta{name} argument.
% In particular, using a counter in \meta{name}, one could easily implement
% even recursive calls. In this connection, it should be noted that
% \meta{name} is expanded via "\csname ... \endcsname", and so you may use
% constructs like "\the\namecounter" there.\par
% \begin{quote}
% \DescribeMacro{\toolboxTokenLoop}
% "\toolboxTokenLoop"\bracemeta{tokens}\bracemeta{action}
% \end{quote}
% This is similar to "\toolboxLoop": The command \meta{action}"\toolboxToken"
% is executed iteratively where "\toolboxToken" runs over each token in
% \meta{tokens}. The important difference is that "\toolboxToken" is a token
% (instead of an item). In particular, "\toolboxToken" runs through every
% single token including spaces and braces.\par
% The token "\toolboxSpaceToken" which is described later may be handy
% in connection with this command.\par
% Example:
% \begin{verbatim}
% \toolboxTokenLoop{Some text}{\kern0.1em}\end{verbatim}
% is the similar to "\kern0.1em S\kern0.1em o\kern0.1em m...", i.e.\ you
% get wider spacing between the letters of "Some text" (I do not claim that
% this is typographically a good idea).\par
%
% Note that you do not have to take special care about the space.
% With "\toolboxLoop", you would have to mask the space e.g.\ with
%
% \begin{verbatim}
% \toolboxLoop{Some{ }text}{\kern0.1em}\end{verbatim}
% or
% \begin{verbatim}
% \toolboxLoop{Some\toolboxSpace text}{\kern0.1em}\end{verbatim}
% In contrast, "\toolboxTokenLoop" would behave differently here:
% \begin{verbatim}
% \toolboxTokenLoop{Some{ }text}{\kern0.1em}\end{verbatim}
% would produce "\kern0.1em S...\kern0.1em{\kern0.1em"\myspace"\kern0.1em}..."
% because the braces are simply considered as tokens.
%
% "\toolboxTokenLoop" is not reentrant. Analogously to "\toolboxLoopName",
% independent versions can be generated by
% \begin{quote}
% \DescribeMacro{\toolboxTokenName}
% "\toolboxTokenName"\bracemeta{name}\bracemeta{tokens}\bracemeta{action}
% \end{quote}
% \subsection{Controlled expansion}
%
% There are some occasions when you want more control over the expansion.
% E.g.\ you might want to concatenate the contents of two macros to a
% further macro or you want to expand a macro by one level but no full
% expansion. Usually you can get this effects with "\expandafter", but if
% you expand several concatenated tokens in this way you either have to
% write a lot of "\expandafter"s or you have to define subsidiary macros
% that help you to "\expandafter" certain parts of macros. The macros in
% this section allow you to do this in the most generic way that I could
% implement.
%
% \begin{quote}
% \DescribeMacro{\toolboxDef}
% "\toolboxDef\macrotodefine"\bracemeta{argumentlist}
% \end{quote}
%
% This call is similar to
% \begin{quote}
% "\def\macrotodefine"\bracemeta{argumentlist}
% \end{quote}
% with two important differences:
%
% For "\toolboxDef", \meta{argumentlist} is expanded precisely by one level.
% \meta{argumentlist} may not contain macros with parameters, and spaces in the
% highest level are ignored. If you want to force a space on a particular
% place, use the macro \DescribeMacro{\toolboxSpace}"\toolboxSpace" at this
% place (which is described later). Contrary to the usual "\def", the
% symbol "#" is treated as a usual symbol.
%
% Example of usage:
% \begin{verbatim}
% \toolboxDef\chain{\chain\toolboxSpace\after}\end{verbatim}
% This modifies the macro "\chain" such that a space and the content of the
% macro "\after" is appended at the end.
%
% \begin{quote}
% \DescribeMacro{\toolboxAppend}
% "\toolboxAppend\macrotodefine"\bracemeta{argumentlist}
% \end{quote}
% This is equivalent to
% \begin{quote}
% "\toolboxDef\macrotodefine{\macrotodefine"\meta{argumentlist}"}"
% \end{quote}
% \par
% The macro
% \begin{quote}
% \DescribeMacro{\toolboxSurround}
% "\toolboxSurround"\bracemeta{content before}\bracemeta{content after}"\macro"
% \end{quote}
% redefines "\macro" such that \meta{content before} is put at the
% beginning and \meta{content after} after the definition of "\macro".
% So this is equivalent to
% \begin{quote}
% "\def\macro{"\meta{content before}\meta{old content of \cmdcite{macro}}\relax
%\meta{content after}"}"
% \end{quote}
% It is required that "\macro" is a usual macro without any arguments.
% If you want to patch more complicated macros, use the \filecite{patch.doc}
% package instead.
% The order of the arguments may appear strange, but it is convenient if
% \meta{content before} or \meta{content after} are macros which should be
% expanded with "\expandafter".
% There is some subsidiary macro used in the implementation of the above
% macros which might be useful also in some other situations:
%
% \begin{quote}
% \DescribeMacro{\toolboxTokDef}
% "\toolboxTokDef"\bracemeta{argumentlist}"\macrotodefine"
% \end{quote}
% This call is similar to
% \begin{quote}
% "\def\macrotodefine"\bracemeta{argumentlist}
% \end{quote}
% with the difference that the symbol "#" is stored as such.
% The order of the arguments has been swapped in order to simplify the
% application of "\expandafter" to \meta{argumentlist}.
%
% \subsection{Searching, splitting, and replacing}
%
% \begin{quote}
% \DescribeMacro{\toolboxSplitAt}
% "\toolboxSplitAt"\bracemeta{argument}\bracemeta{search}\relax
%"{\beforestring}{\afterstring}"
% \end{quote}
%
% Here, "\beforestring" and "\afterstring" are arbitrary macro names,
% and \meta{search} and \meta{argument} are any sequences of tokens (which
% are in the following considered as `strings').
%
% This call scans \meta{argument} for the first occurrence of \meta{search}.
% The macros "\beforestring" and "\afterstring" are defined correspondingly
% such that "\beforestring" expands to the part before the first occurrence,
% and "\afterstring" to the part following the first occurrence.
% If \meta{search} does not occur in \meta{argument}, "\beforestring" is
% defined to \meta{argument}, and "\afterstring" is "\let" "\undefined".
%
% If "\beforestring" or "\afterstring" had already been defined before the
% call, the previous definition is tacitly overridden.
% It is explicitly allowed that "\beforestring" and "\afterstring" are the
% same names. In this case, the result has the meaning of "\afterstring".
%
% It is guaranteed that braces "{...}" are \emph{not} lost in \meta{argument}.
% However, \meta{search} may not contain any braces, and \meta{argument} may
% contain only matching pairs of braces. Moreover, occurrences of \meta{search}
% within a pair of braces in \meta{argument} are not recognized.
%
% (The order of the arguments has been chosen in order to simplify the
% use of "\expandafter").
%
% There are some restrictions for the strings in search. For example,
% the symbol "#" is not allowed.
%
% In the above call, the arguments may not run over several paragraphs.
% If you want the latter, you have to use the alternative call
% \begin{quote}
% "\toolboxSplitAt*"\bracemeta{argument}\bracemeta{search}\relax
%"{\beforestring}{\afterstring}"
% \end{quote}
%
% Example of usage:
%
% \begin{verbatim}
% \def\examplemacro#1{\toolboxSplitAt{#1}{@}\testme\testme
% \ifx\testme\undefined
% ... (do this when #1 contains no `@' token)
% \fi}\end{verbatim}
%
% If "\toolboxSplitAt" should be used several times with the same
% \meta{search} string, it is much more efficient to use the following command:
%
% \begin{quote}
% \DescribeMacro{\toolboxMakeSplit}
% "\toolboxMakeSplit"\bracemeta{search}"{command}"
% \end{quote}
%
% This call defines a new macro "\command" (the name is determined by the
% second argument of "\toolboxMakeSplit") which can be called in the form
%
% \begin{quote}
% "\command"\bracemeta{argument}"{\beforestring}{\afterstring}"
% \end{quote}
%
% and which has the analogous meaning as "\SplitAt" (the argument
% \bracemeta{search} is implicitly fixed and taken from the call of
% "\toolboxMakeSplit").
% It is explicitly admissible that the above macro "\toolboxMakeSplit" is
% used with an already existing command name. In this case, the previous
% definition of "\command" is tacitly overridden.
%
% The command created by "\toolboxMakeSplit" does not accept arguments which
% run over several paragraphs. If you want the latter, you have to create
% this command by the alternative call
%
% \begin{quote}
% "\toolboxMakeSplit*"\bracemeta{search}"{command}"
% \end{quote}
% The command
% \begin{quote}
% "\toolboxFreeSplit"\bracemeta{command}
% \end{quote}
% frees the memory used by a previous "\toolboxMakeSplit" (and lets "\command"
% again be undefined).
% The command
% \begin{quote}
% \DescribeMacro{\toolboxReplace}
% "\toolboxReplace"\bracemeta{search}\bracemeta{replace}"\macro"
% \end{quote}
% replaces in "\macro" all occurences of \meta{search} by \meta{replace}.
% The same matches are found as in "\toolboxSplitAt".
% If you need to search for the same text several times, it is faster
% to use the command
% \begin{quote}
% \DescribeMacro{\toolboxReplaceSplit}
% "\toolboxReplaceSplit"\bracemeta{replace}"\SplitCmd\macro"
% \end{quote}
% where "\SplitCmd" is a command previously generated with "\toolboxMakeSplit*"
% according to your \meta{search} string. (You could also use
% "\toolboxMakeSplit" to generate "\SplitCmd", but then "\macro" should not
% contain any "\par"s).
% \subsection{Redefinition of macros}
%
%
% \begin{quote}
% \DescribeMacro{\toolboxMakeHarmless}
% "\toolboxMakeHarmless{\macro}"
% \end{quote}
%
% The above call redefines "\macro" such that it expands to an ASCII text
% containing the previous definition of "\macro" (i.e.\ the catcodes of
% "\macro" are changed).
% The call
% \begin{quote}
% \DescribeMacro{\toolboxDropBrace}
% "\toolboxDropBrace{\macro}"
% \end{quote}
% drops possible outer braces of "\macro". More precisely,
% if "\macro" expands to \bracemeta{content}, then "\macro" is redefined
% to \meta{content} (without braces). Otherwise, nothing happens.
% The command
% \begin{quote}
% \DescribeMacro{\toolboxIf}
% "\toolboxIf"\meta{comparison}\bracemeta{definition commands}\relax
%\cmdmeta{macro}$\ldots$
% \end{quote}
% allows conditional definitions. Here, \bracemeta{definition command}
% is either "\def", "{\long\def}", "\let", or some similar command like
% e.g.\ the \LaTeX\ "\newcommand". If the test
% "\ifx"\meta{comparison}\cmdmeta{macro} evaluates positive, then
% \cmdmeta{macro} is defined correspondingly. Otherwise, \cmdmeta{macro}
% is not changed.\par\smallskip
%
% \textbf{Examples:}
%
% \begin{verbatim}
% \toolboxIf\undefined\def\macro{....}
% \toolboxIf\undefined\let\macro...
% \toolboxIf\undefined{\long\def}\macro{....}
% \toolboxIf\undefined\newcommand{\macro}{....}\end{verbatim}
%
% are similar to "\def\macro{...}" resp.\ "\let\macro..."
% resp.\ "\long\def\macro{...}" resp.\ "\newcommand{\macro}" with the
% difference that "\macro" is not changed if it was already defined.
% In this sense, "\toolboxIf" is a more flexible variant of "\providecommand".
%
% The commands
% \begin{quote}
% \DescribeMacro{\toolboxNewiftrue}
% "\toolboxNewiftrue"\bracemeta{name}\\
% \DescribeMacro{\toolboxNewiffalse}
% "\toolboxNewiffalse"\bracemeta{name}
% \end{quote}
% test whether the command "\if"\meta{name} was already introduced with
% "\newif"; in this case nothing happens. Otherwise, "\if"\meta{name} is
% introduced similarly to "\newif\if"\meta{name} and set to "true"
% respectively "false".
% In contrast to the corresponding command in \TeX\ or \LaTeX 2.09, this macro
% is not "\outer"!
% \begin{quote}
% \DescribeMacro{\toolboxNewifTrue}
% "\toolboxNewifTrue"\bracemeta{name}\\
% \DescribeMacro{\toolboxNewifFalse}
% "\toolboxNewifFalse"\bracemeta{name}
% \end{quote}
% are similar to "\toolboxNewiftrue"\bracemeta{name} and
% "\toolboxNewiffalse"\bracemeta{name}, respectively,
% with the difference that "\if"\meta{name} is set unconditionally
% to "true" respectively "false".
% \subsection{Concatenated macro names}
%
% \begin{quote}
% \DescribeMacro{\toolboxLet}
% "\toolboxLet\variable"\bracemeta{macroname}
% \end{quote}
% The above command is analogous to "\let\variable\macroname" with the
% difference that \meta{macroname} can also contain other tokens like numbers
% (it is obtained via "\csname"). Some converse to this command is
%
% \begin{quote}
% "\toolboxWithNr"\bracemeta{number}"\command"\bracemeta{macro}
% \end{quote}
% which translates into "\command\macronumber" (here, \meta{macro} and
% \meta{number} are just concatenated and evaluated via "\csname").
% Examples:
% \begin{verbatim}
% \toolboxWithNr 1\let{name}\toolboxEmpty\end{verbatim}
% This is the same as "\let\name1\toolboxEmpty" (but such that "\name1" is
% considered as a name, not as "\name 1")
% \begin{verbatim}
% \toolboxWithNr {10}\def{name}{Foo}\end{verbatim}
% This corresponds analogously to "\def\name10{Foo}".
% \begin{verbatim}
% \toolboxLet\mymacro{name\the\mycount}\end{verbatim}
% This is similar to "\let\mymacro\namexx" where "xx" is the content
% of the counter "\mycount".
% \subsection{Various}
%
% The following macros have equivalents in most formats (like \LaTeXe).
% However, we do not want to rely too much on these formats, so we provide
% our own definitions.
% The macro
% \begin{quote}
% \DescribeMacro{\toolboxEmpty}"\toolboxEmpty"
% \end{quote}
% expands to nothing (usually, this is the same as "\empty").
% Similarly, the macro
% \begin{quote}
% \DescribeMacro{\toolboxSpace}"\toolboxSpace"
% \end{quote}
% expands to a space symbol (usually, this is the same as "\space").
% The token
% \begin{quote}
% \DescribeMacro{\toolboxSpaceToken}"\toolboxSpaceToken"
% \end{quote}
% is "\let" a space token (usually, this is the same as "\@sptoken").
% This token is convenient in tests of tokens
% (because it is hard to get a space there which is not eaten by the
% \TeX\ parser, although sometimes also constructions like
% \begin{verbatim}
% \expandafter\ifx\toolboxSpace\token\end{verbatim}
% can be used). Also the macros
% \begin{quote}
% \DescribeMacro{\toolboxFirstOfTwo}"\toolboxFirstOfTwo"\\
% \DescribeMacro{\toolboxSecondOfTwo}"\toolboxSecondOfTwo"
% \end{quote}
% are provided which read two arguments and return only the first
% respectively second argument (usually, this is the same as
% "\@firstoftwo" respectively "\@secondoftwo"). Similarly,
% \begin{quote}
% \DescribeMacro{\toolboxGobbleArg}
% "\toolboxGobbleArg"\bracemeta{argument}
% \end{quote}
% just reads its argument and expands to nothing.
% \iffalse
%</metainfo>
% \fi
% \iffalse--------------------------------------------------------------\fi
% \StopEventually{\PrintChanges}
% \section{Implementation}
%
% \iffalse--------------------------------------------------------------
%
%
%<*package>
% \fi
% \begin{macrocode}
%%
%% This file was generated by the docstrip utility from toolbox.dtx.
%% You may distribute this file only together with the source toolbox.dtx
%% (and if possible with toolbox.ins) and only if these files are unmodified.
%%
%% Author:
%%
%% M. V\"ath martin@mvath.de
%%
\ifx\typeout\undefined
\def\tbx@tmp{\immediate\write17}\expandafter\tbx@tmp
\else
\expandafter\typeout
\fi{toolbox.sty by M. Vaeth: The TeX Programmer's Toolbox 5.1}
%% First, some LaTeX support:
%% We inform LaTeX that this is a package, and we test whether we would
%% override some existing commands.
\ifx\ProvidesPackage\undefined\else
\ProvidesPackage{toolbox}[2004/04/29 v5.1]
\fi
\ifx\newcommand\undefined\else
\newcommand{\toolboxMakeDef}{}
\newcommand{\toolboxFreeDef}{}
\newcommand{\toolboxFuturelet}{}
\newcommand{\toolboxGobbleNext}{}
\newcommand{\toolboxIfNextToken}{}
\newcommand{\toolboxIfNextGobbling}{}
\newcommand{\toolboxIfEmpty}{}
\newcommand{\toolboxIfx}{}
\newcommand{\toolboxIfX}{}
\newcommand{\toolboxIfElse}{}
\newcommand{\toolboxLoop}{}
\newcommand{\toolboxLoopName}{}
\newcommand{\toolboxToken}{}
\newcommand{\toolboxTokenName}{}
\newcommand{\toolboxTokDef}{}
\newcommand{\toolboxDef}{}
\newcommand{\toolboxAppend}{}
\newcommand{\toolboxSplitAt}{}
\newcommand{\toolboxMakeSplit}{}
\newcommand{\toolboxFreeSplit}{}
\newcommand{\toolboxReplace}{}
\newcommand{\toolboxReplaceSplit}{}
\newcommand{\toolboxMakeHarmless}{}
\newcommand{\toolboxDropBrace}{}
\newcommand{\toolboxIf}{}
\newcommand{\toolboxNewiftrue}{}
\newcommand{\toolboxNewiffalse}{}
\newcommand{\toolboxLet}{}
\newcommand{\toolboxWithNr}{}
\newcommand{\toolboxEmpty}{}
\newcommand{\toolboxSpace}{}
\newcommand{\toolboxSpaceToken}{}
\newcommand{\toolboxFirstOfTwo}{}
\newcommand{\toolboxSecondOfTwo}{}
\newcommand{\toolboxGobbleArg}{}
\fi
% \end{macrocode}
% \subsection{Macros for various purposes}
% \begin{macro}{\toolboxSpace}\nocomment
% \begin{macrocode}
\def\toolboxEmpty{}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxSpace}\nocomment
% \begin{macrocode}
\def\toolboxSpace{ }
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxSpaceToken}
% We cannot just write
% \begin{verbatim*}\let\toolboxSpaceToken= \end{verbatim*}
% because then the space would be eaten by \TeX's parser.
% Also tries like
% \begin{verbatim}
% \expandafter\let\expandafter\toolboxSpaceToken\toolboxSpace\end{verbatim}
% do not work for similar reasons. In contrast,
% \begin{verbatim}
% \futurelet\toolboxSpaceToken{ }\end{verbatim}
% is possible (because the space is not `really' parsed at this time),
% but it would have the side effect that the group "{ }" is executed which
% forces a space output. We could artificially `eat' this output in some box.
% But we proceed differently by replacing "{ }" in
% the above call by an appropriate "\if...\fi". Of course, we have to take
% care that the space is not eaten too early.
% \begin{macrocode}
\expandafter
\futurelet\expandafter\toolboxSpaceToken\expandafter
\if\toolboxSpace\toolboxEmpty\toolboxEmpty\fi
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxFirstOfTwo}\nocomment
% \begin{macrocode}
\long\def\toolboxFirstOfTwo#1#2{#1}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxSecondOfTwo}\nocomment
% \begin{macrocode}
\long\def\toolboxSecondOfTwo#1#2{#2}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxGobbleArg}
% \begin{macrocode}
\long\def\toolboxGobbleArg#1{}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\tbx@toks}
% We need a temporary token list
% \begin{macrocode}
\toksdef\tbx@toks=0
% \end{macrocode}
% \end{macro}
%
% \subsection{Macros supporting implicit macro definitions}
%
% \begin{macro}{\toolboxMakeDef}\nocomment
% \begin{macrocode}
\def\toolboxMakeDef{\tbx@MakeNames\tbx@MakeDef}
% \end{macrocode}
% \begin{macro}{\tbx@MakeDef}
% The macros for "\toolboxMakeDef" are defined with
% \begin{quote}
% "\tbx@MakeDef\PrefixNewName\PrefixRenewName\PrefixProvideName%"\\
% " \PrefixDefName\PrefixLetName\PrefixName\tbx@e@Prefix@Name%"\\
% " "\bracemeta{Prefix}\bracemeta{Name}\bracemeta{Replacement Mask}
% \end{quote}
% Note that \meta{Replacement Mask} must be read implicitly, because it
% contains "#1" which is usually forbidden.
% The macro "\tbx@e@Prefix@Name" is defined as
% \begin{quote}
% "\tbx@long\def\tbx@e@Name#1"\bracemeta{Replacement Mask}
% \end{quote}
% The macros generated by
% \begin{quote}
% "\PrefixNewName"\bracemeta{something}"{"$\ldots$"...}"
% \end{quote}
% carry the names
% \begin{quote}
% "\tbx@l@"\meta{Prefix}"@"\meta{Name}"@"\meta{something}
% \end{quote}
% Observe that the symbol "@" has currently the exceptional letter catcode,
% so that there is no danger that the user mangles up the names (unless he
% uses "\makeatletter" which he should of course not do, usually).
% \makeatletter
% \begin{macrocode}
\def\tbx@MakeDef#1#2#3#4#5#6#7#8#9{%
\tbx@def#1{\toolboxIfNextGobbling*%
{\tbx@MakeNew\let{#8}{#9}}{\tbx@MakeNew\def{#8}{#9}}}%
\tbx@def#2{\toolboxIfNextGobbling*%
{\tbx@MakeRenew\let{#8}{#9}}{\tbx@MakeRenew\def{#8}{#9}}}%
\tbx@def#3{\toolboxIfNextGobbling*%
{\tbx@MakeProvide\let{#8}{#9}}{\tbx@MakeProvide\def{#8}{#9}}}%
\tbx@def#4{\toolboxIfNextGobbling*%
{\tbx@MakeForce\let{#8}{#9}}{\tbx@MakeForce\def{#8}{#9}}}%
\tbx@def#5##1##2{\expandafter
\tbx@MakeLet\csname tbx@l@#8@#9@##2\endcsname##1}%
\tbx@def#6{\toolboxIfNextGobbling*%
{\tbx@MakeUse\tbx@itemEnd{#8}{#9}}{\tbx@MakeUse\relax{#8}{#9}}}%
\long\def#7##1}
% \end{macrocode}
% \begin{macro}{\tbx@MakeNew}
% "\tbx@MakeNew"\bracemeta{mode}\relax
%\bracemeta{Prefix}\bracemeta{Name}\bracemeta{something}%
%\bracemeta{text to remember}
% \begin{macrocode}
\def\tbx@MakeNew#1#2#3#4{\expandafter
\ifx\csname tbx@l@#2@#3@#4\endcsname\relax\else
\errmessage{#2New#3: entry #4 already exists}%
\fi
\tbx@MakeForce{#1}{#2}{#3}{#4}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@MakeRenew}
% "\tbx@MakeRenew"\bracemeta{mode}\relax
%\bracemeta{Prefix}\bracemeta{Name}\bracemeta{something}%
%\bracemeta{text to remember}
% \begin{macrocode}
\def\tbx@MakeRenew#1#2#3#4{\expandafter
\ifx\csname tbx@l@#2@#3@#4\endcsname\relax
\errmessage{#2Renew#3: entry #4 was not defined before}%
\fi
\tbx@MakeForce{#1}{#2}{#3}{#4}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@MakeProvide}
% "\tbx@MakeProvide"\bracemeta{mode}\relax
%\bracemeta{Prefix}\bracemeta{Name}\bracemeta{something}%
%\bracemeta{text to remember}
% \begin{macrocode}
\def\tbx@MakeProvide#1#2#3#4#5{\expandafter
\ifx\csname tbx@l@#2@#3@#4\endcsname\relax
\tbx@MakeForce{#1}{#2}{#3}{#4}{#5}%
\fi}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@MakeForce}
% "\tbx@MakeForce"\bracemeta{mode}\relax
%\bracemeta{Prefix}\bracemeta{Name}\bracemeta{something}%
%\bracemeta{text to remember}
% \begin{macrocode}
\long\def\tbx@MakeForce#1#2#3#4#5{%
\ifx#1\let
\expandafter
\let\csname tbx@l@#2@#3@#4\endcsname#5%
\else
\expandafter
\tbx@MakeDoDef\csname tbx@l@#2@#3@#4\expandafter\endcsname
\csname tbx@e@#2@#3\endcsname{#5}%
\fi}
% \end{macrocode}
% \begin{macro}{\tbx@MakeDoDef}
% \begin{quote}
% "\tbx@MakeDoDef"\relax
%"\tbx@l@"\meta{Prefix}"@"\meta{Name}"@"\meta{something}"%"\\
%" \tbx@e@"\meta{Prefix}"@"\meta{Name}\bracemeta{text to remember}
% \end{quote}
% \begin{macrocode}
\long\def\tbx@MakeDoDef#1#2#3{\tbx@toks\expandafter{#2{#3}}%
\edef#1{\the\tbx@toks}}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\tbx@MakeLet}
% "\tbx@MakeLet"\cmdmeta{Prefix}"@"\meta{Name}"@"\meta{something}\relax
%\cmdmeta{something}
% \begin{macrocode}
\def\tbx@MakeLet#1#2{%
\ifx#1\relax
\let#2\undefined
\else
\let#2#1%
\fi}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@MakeUse}
% "\tbx@MakeUse"\bracemeta{mode}\relax
%\bracemeta{Prefix}\bracemeta{Name}\bracemeta{something}
% \begin{macrocode}
\def\tbx@MakeUse#1#2#3#4{%
\expandafter
\ifx\csname tbx@l@#2@#3@#4\endcsname#1%
\errmessage{Entry #4 was not defined with
#2New#3, #2Provide#3, or #2Def#3}%
\fi
\csname tbx@l@#2@#3@#4\endcsname}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@def}
% "\tbx@def" is similar to "\def", but existence is tested (via "\relax")
% \begin{macrocode}
\def\tbx@def#1{%
\ifx#1\relax\else
\errmessage{\string#1 is already defined}%
\fi
\def#1}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\toolboxFreeDef}\nocomment
% \begin{macrocode}
\def\toolboxFreeDef{\toolboxIfNextGobbling*%
{\tbx@MakeNames{\tbx@FreeDef\relax}}{\tbx@MakeNames{\tbx@FreeDef\undefined}}}
% \end{macrocode}
% \begin{macro}{\tbx@FreeDef}
% \begin{quote}
% "\tbx@FreeDef"\bracemeta{mode}"\PrefixNewName\PrefixRenewName%"\\
% " \PrefixProvideName\PrefixDefName\PrefixLetName\PrefixName"%\\
% " \tbx@e@Prefix@Name"\bracemeta{Prefix}\bracemeta{Name}
% \end{quote}
% The last two arguments are not needed, but we must gobble them.
% Since a macro can have at most 9 arguments, we must gobble the last one
% separately.
% \begin{macrocode}
\def\tbx@FreeDef#1#2#3#4#5#6#7#8#9{%
\let#2\undefined\let#3\undefined\let#4\undefined\let#5\undefined
\let#8\undefined
\ifx#1\undefined
\let#6\undefined\let#7\undefined
\fi\toolboxGobbleArg}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\tbx@MakeNames}
% The call
% \begin{quote}
% "\tbx@MakeNames"\bracemeta{commands}"["\meta{Prefix}"]"\bracemeta{Name}
% \end{quote}
% (where the "["\meta{Prefix}"]" argument is optional) expands to
% \begin{quote}
% \meta{commands}"\PrefixNewName\PrefixRenewName\PrefixProvideName%"\\
% " \PrefixLetName\PrefixName\tbx@e@Prefix@Name%"\\
% " "\bracemeta{Prefix}\bracemeta{Name}
% \end{quote}
% \begin{macrocode}
\def\tbx@MakeNames#1{\toolboxIfNextToken[%]
{\tbx@MakingNames{#1}}{\tbx@MakingNames{#1}[]}}
% \end{macrocode}
% \begin{macro}{\tbx@MakingNames}
% \begin{macrocode}
\def\tbx@MakingNames#1[#2]#3{\expandafter
\tbx@ListSwap\expandafter{%
\csname#2New#3\expandafter\endcsname
\csname#2Renew#3\expandafter\endcsname
\csname#2Provide#3\expandafter\endcsname
\csname#2Def#3\expandafter\endcsname
\csname#2Let#3\expandafter\endcsname
\csname#2#3\expandafter\endcsname
\csname tbx@e@#2@#3\endcsname{#2}{#3}}{#1}}
% \end{macrocode}
% \begin{macro}{\tbx@ListSwap}\nocomment
% \begin{macrocode}
\def\tbx@ListSwap#1#2{#2#1}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Macros supporting fancy optional argument parsing}
%
% \begin{macro}{\toolboxFuturelet}
% \begin{macrocode}
\long\def\toolboxFuturelet#1#2{\toolboxTokDef{#2}\tbx@tmp\futurelet#1\tbx@tmp}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxGobbleNext}
% \begin{macrocode}
\long\def\toolboxGobbleNext#1{\toolboxTokDef{#1}\tbx@tmp
\afterassignment\tbx@tmp
\let\toolboxToken= }% The space here is important to read spaces properly
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxIfNextToken}
% \begin{macrocode}
\long\def\toolboxIfNextToken#1#2#3{%
\toolboxFuturelet\toolboxToken{%
\ifx#1\toolboxToken
\expandafter\toolboxFirstOfTwo
\else
\expandafter\toolboxSecondOfTwo
\fi{#2}{#3}}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxIfNextGobbling}
% \begin{macrocode}
\long\def\toolboxIfNextGobbling#1#2#3{%
\toolboxIfNextToken{#1}{\toolboxGobbleNext{#2}}{#3}}
% \end{macrocode}
% \end{macro}
%
% \subsection{Macros supporting loops over tokenlists and itemlists}
%
% \begin{macro}{\toolboxLoop}
% "\toolboxLoop" just calls "\tbx@item" with the magic names
% "\tbx@i" and "\tbx@I".
% \begin{macrocode}
\long\def\toolboxLoop#1#2{\tbx@item\tbx@i\tbx@I{#1}{#2}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxLoopName}
% "\toolboxLoopName" calls "\tbx@item" with the magic names "\tbx@i@#1"
% and "\tbx@I#@1"
% \begin{macrocode}
\long\def\toolboxLoopName#1#2#3{\tbx@LoopName{#1}iI\tbx@item{#2}{#3}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@LoopName}
% \begin{verbatim}
% \tbx@LoopName{name}{x}{y}{\exec}\end{verbatim}
% is equivalent to
% \begin{verbatim}
% \exec\tbx@x@name\tbx@y@name\end{verbatim}
% \begin{macrocode}
\def\tbx@LoopName#1#2#3#4{%
\expandafter#4\csname tbx@#2@#1\expandafter\endcsname
\csname tbx@#3@#1\endcsname}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@item}
% The call
% \begin{quote}
% "\tbx@item{\MagicNameA}{\MagicNameB}"\bracemeta{items}\bracemeta{action}
% \end{quote}
% is the essential part of "\toolboxLoop". It has the same semantic with
% the only difference that the names "\MagicNameA" and "\MagicNameB" are used
% as temporary macros (they are the reason why "\tbx@item" is not reentrant).
% \begin{macrocode}
\long\def\tbx@item#1#2#3#4{%
\long\def#1##1{%
\toolboxTokDef{##1}\toolboxToken
\ifx\toolboxToken\tbx@itemEnd
\def#2{\let#1\undefined\let#2\undefined}%
\else
#4{##1}%
\fi
#2}%
\let#2#1%
#1#3\tbx@itemEnd}
% \end{macrocode}
% \begin{macro}{\tbx@itemEnd}
% "\tbx@itemEnd" is the magic token used to mark the end of the list in
% "\tbx@item".
% Of course, we could also use any other macro instead, but this is unique,
% even if we compare with "\ifx". Moreover, we want a short macro to
% avoid unnecessary redundancy in comparing with "\ifx".
% It appears not necessary to make this token change in recursions, because
% in each expansion of a list, the newest item will automatically be the
% earliest.
% \begin{macrocode}
\def\tbx@itemEnd{\tbx@itemEnd}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\toolboxTokenLoop}
% "\toolboxTokenLoop" just calls "\tbx@token" with the magic names
% "\tbx@t" and "\tbx@T".
% \begin{macrocode}
\long\def\toolboxTokenLoop#1#2{\tbx@token\tbx@t\tbx@T{#1}{#2}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxTokenLoopName}
% "\toolboxTokenLoopName" calls "\tbx@token" with the magic names "\tbx@t@#1"
% and "\tbx@T#@1"
% \begin{macrocode}
\long\def\toolboxTokenLoopName#1#2#3{\tbx@LoopName{#1}tT\tbx@token{#2}{#3}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@token}
% The call
% \begin{quote}
% "\tbx@token{\MagicNameA}{\MagicNameB}"\bracemeta{items}\bracemeta{action}
% \end{quote}
% is the essential part of "\toolboxTokenLoop". It has the same semantic with
% the only difference that the names "\MagicNameA" and "\MagicNameB" are used
% as temporary macros (they are the reason why "\tbx@token" is not reentrant).
% \begin{macrocode}
\long\def\tbx@token#1#2#3#4{%
\def#1{%
\ifx\toolboxToken\tbx@tokenEnd
\def#2{\let#1\undefined\let#2\undefined}%
\else
#4\toolboxToken
\fi
#2}%
\def#2{\afterassignment#1\let\toolboxToken= }%
#2#3\tbx@tokenEnd}
% \end{macrocode}
% \begin{macro}{\tbx@tokenEnd}
% "\tbx@tokenEnd" is the magic token used to mark the end of the list
% for "\tbx@token".
% The same remarks as for "\tbx@itemEnd" hold. However, it is not clear
% whether we could just use "\tbx@itemEnd" instead, because the scan rules
% for "\tbx@token" and "\tbx@item" are somewhat different, and thus it is
% not immediately clear whether in some fancy situations such lists (if
% called cross-wise) could overlap: I found no example, but I also did not
% put too much effort in finding one. In any case, we are on the sure side,
% if we just use a different token.
% \begin{macrocode}
\def\tbx@tokenEnd{\tbx@tokenEnd}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\toolboxIfEmpty}
% \begin{macrocode}
\long\def\toolboxIfEmpty#1{\toolboxIfx{#1}\toolboxEmpty}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxIfX}
% \begin{macrocode}
\long\def\toolboxIfX#1#2{\toolboxTokDef{#1}\tbx@ifx\toolboxIfx{#2}\tbx@ifx}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxIfx}
% \begin{macrocode}
\long\def\toolboxIfx#1#2{\toolboxTokDef{#1}\tbx@tmp
\toolboxIfElse{\ifx\tbx@tmp#2}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxIfElse}
% \begin{macrocode}
\long\def\toolboxIfElse#1{#1\expandafter
\toolboxFirstOfTwo\else\expandafter\toolboxSecondOfTwo\fi}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Macros supporting controlled expansion}
%
% \begin{macro}{\toolboxTokDef}\nocomment
% \begin{macrocode}
\long\def\toolboxTokDef#1#2{\tbx@toks{#1}\edef#2{\the\tbx@toks}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\toolboxDef}
% This is mainly a call of "\toolboxLoopName". It is slightly faster if we
% call "\tbx@item" immediately (and then we can also give magic names which do
% not clash with any other names). Also for time and memory reasons, we always
% assume that the temporary variable
% \begin{macro}{\tbx@odeftmp}
% "\tbx@odeftmp"
% \end{macro}
% is "\toolboxEmpty" at the beginning; we reset it to "\toolboxEmpty" at
% the end (so that the memory is freed).
% \begin{macrocode}
\def\toolboxDef#1#2{%
\tbx@item\tbx@odefa\tbx@odefb{#2}\tbx@odef
\let#1\tbx@odeftmp\let\tbx@odeftmp\toolboxEmpty}
\let\tbx@odeftmp\toolboxEmpty
% \end{macrocode}
% \begin{macro}{\tbx@odef}
% \begin{macrocode}
\long\def\tbx@odef#1{\expandafter\tbx@odefapp\expandafter{#1}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@odefapp}
% "\tbx@odefapp" appends its argument to "\tbx@odeftmp".
% \begin{macrocode}
\long\def\tbx@odefapp#1{\tbx@toks\expandafter{\tbx@odeftmp#1}%
\edef\tbx@odeftmp{\the\tbx@toks}}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\toolboxAppend}\nocomment
% \begin{macrocode}
\def\toolboxAppend#1#2{\toolboxDef#1{#1#2}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\toolboxSurround}\nocomment
% \begin{macrocode}
\long\def\toolboxSurround#1#2#3{\tbx@toks{#1}%
\tbx@toks\expandafter{\the\expandafter\tbx@toks#3#2}%
\edef#3{\the\tbx@toks}}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Macros supporting searching, splitting, and replacing}
%
% \begin{macro}{\toolboxMakeSplit}\nocomment
% \begin{macrocode}
\def\toolboxMakeSplit{%
\toolboxIfNextGobbling*\tbx@MakeLong\tbx@MakeShort}
% \end{macrocode}
%
% \begin{macro}{\tbx@Makelong}
% \begin{quote}
% "\tbx@Makelong"\bracemeta{search}"{cmd}"
% \end{quote}
% is the same as
% \begin{quote}
% "\tbx@DoSplitInstance{\cmd}{\tbx@cmd@spt}{\tbx@cmd@rst}"
%\bracemeta{search}"\long"
% \end{quote}
% \begin{macrocode}
\long\def\tbx@MakeLong#1#2{%
\tbx@SplitNames{#2}%
\expandafter
\tbx@DoSplitInstance\tbx@splt{#1}\long}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@MakeShort}
% "\tbx@Makeshort" is essentially the same as "\tbx@Makelong" (just that
% "\long" is missing, of course). We could have used the same macro with
% an additional argument, but it is more convenient for the user if this
% macro itself is not "\long" so that new paragraphs in the passed search
% string already give an error: It makes no sense to look for new paragraphs
% in texts which may not contain new paragraphs.
% \begin{macrocode}
\def\tbx@MakeShort#1#2{%
\tbx@SplitNames{#2}%
\expandafter
\tbx@DoSplitInstance\tbx@splt{#1}{}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\tbx@SplitNames}
% The call "\tbx@SplitNames{cmd}" is equivalent to
% \begin{verbatim}
% \def\tbx@splt{\cmd \tbx@cmd@spt \tbx@cmd@rst}\end{verbatim}
% \begin{macrocode}
\def\tbx@SplitNames#1{%
\expandafter
\def\expandafter\tbx@splt\expandafter{\csname#1\expandafter\endcsname
\csname tbx@#1@spt\expandafter\endcsname
\csname tbx@#1@rst\endcsname}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\tbx@DoSplitInstance}
% The call
% \begin{quote}
% "\tbx@DoSplitInstance{\cmd}{\tbx@cmd@spt}{\tbx@cmd@rst}"\bracemeta{search}
%\bracemeta{long}
% \end{quote}
% creates the instance "\cmd" which splits its argument at
% \bracemeta{search} (also "\tbx@cmd@spt" and "\tbx@cmd@rst" are created
% which are needed for "\cmd" to work). The argument \meta{long} must be
% either "\long" or empty, depending whether long definitions are desired.\par
% The difficulty in the definition of "\cmd" is to ensure that "{xxx}|{yyy}"
% splits into "{xxx}" and "{yyy}" \emph{with} braces (i.e., we have to
% find out whether there are braces which are eliminated by \TeX\ as
% `argument braces'). Actually, this problem occurs only for the part "{yyy}".
% We solve it by appending an "a" to \meta{argument}, i.e., we actually
% split the string "{xxx}|{yyy}a". Of course, we have to eliminate the
% trailing "a" at the end.
% \begin{macrocode}
\long\def\tbx@DoSplitInstance#1#2#3#4#5{%
#5\def#1##1##2##3{%
#2##2##3\toolboxEmpty##1#4#4@tbx@spt%
\ifx##3\toolboxEmpty
\let##3\undefined
\else
#3##3##1a@tbx@rst%
\fi
}%
#5\def#2##1##2##3#4##4#4##5@tbx@spt{\expandafter
\toolboxTokDef\expandafter{##3}##1\toolboxTokDef{##5}##2}%
#5\def#3##1##2#4##3@tbx@rst{\tbx@rememberlasta##3@tbx@dropa%
\tbx@defwithoutlasta##1##3@tbx@dropa}}
% \end{macrocode}
% \begin{macro}{\tbx@rememberlasta}
% The call
% \begin{quote}
% "\tbx@rememberlasta"\meta{arg}"@tbx@dropa"
% \end{quote}
% (no braces: The magic string "@tbx@dropa" is used to find the end of
% \meta{arg}) is only admissible, if the last token in \meta{arg} is an "a".
% In this case, \DescribeMacro{\tbx@droplasta}"\tbx@droplasta" is
% defined as \meta{arg} without the trailing "a" (but it may happen that
% \meta{arg} looses surrounding braces), and the corresponding string with the
% trailing "a" (possibly without surrounding braces) is saved into
% \DescribeMacro{\tbx@rebuilda}"\tbx@rebuilda".
% This macro is used by the instances created
% by "\tbx@DoSplitInstance".
% \begin{macrocode}
\long\def\tbx@rememberlasta#1a@tbx@dropa{\toolboxTokDef{#1}\tbx@droplasta
\toolboxTokDef{#1a}\tbx@rebuilda}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@defwithoutlasta}
% The call
% \begin{quote}
% "\tbx@defwithoutlasta{\afterstring}"\meta{arg}"@tbx@dropa"
% \end{quote}
% (no braces: The magic string "@tbx@dropa" is used to find the end of
% \meta{arg}) is only admissible, if the last token in \meta{arg} is an "a".
% If \meta{arg} coincides with "\tbx@rebuilda",
% then we know that we did not loose any braces, and we set "\afterstring"
% to the content of "\tbx@droplasta"; otherwise we lost braces and thus
% have additionally to surround the content of "\afterstring" by braces.
% \begin{macrocode}
\long\def\tbx@defwithoutlasta#1#2@tbx@dropa{\toolboxTokDef{#2}\tbx@originala
\ifx\tbx@originala\tbx@rebuilda
% \end{macrocode}
% Did we forget braces in "\tbx@rememberlasta"?
% \begin{macrocode}
\let#1\tbx@droplasta
\else
\expandafter\toolboxTokDef\expandafter{\expandafter{\tbx@droplasta}}#1%
\fi}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\toolboxFreeSplit}\nocomment
% \begin{macrocode}
\def\toolboxFreeSplit#1{%
\tbx@SplitNames{#1}%
\expandafter
\toolboxLoop\expandafter{\tbx@splt}\tbx@freeSplit}
% \end{macrocode}
% \begin{macro}{\tbx@freeSplit}\nocomment
% \begin{macrocode}
\def\tbx@freeSplit#1{\let#1\undefined}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\toolboxSplitAt}
% "\toolboxSplitAt" just calls "tbx@DoSplitInstance" with dummy temporary
% variables and then executes the corresponding command.
% \begin{macrocode}
\def\toolboxSplitAt{\toolboxIfNextGobbling*\tbx@SplitLong\tbx@SplitShort}
% \end{macrocode}
% \begin{macro}{\tbx@SplitLong}\nocomment
% \begin{macrocode}
\long\def\tbx@SplitLong#1#2#3#4{%
\tbx@DoSplitInstance\tbx@splt\tbx@splta\tbx@spltb{#2}\long
\tbx@splt{#1}{#3}{#4}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@SplitShort}
% We cannot use just an additional argument in "\tbx@SplitLong", because
% we really should use a non-"\long" macro to read the arguments.
% \begin{macrocode}
\def\tbx@SplitShort#1#2#3#4{%
\tbx@DoSplitInstance\tbx@splt\tbx@splta\tbx@spltb{#2}{}%
\tbx@splt{#1}{#3}{#4}}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\toolboxReplaceSplit}
% "\toolboxReplaceSplit"\bracemeta{replace}"\SplitCmd\macro"
% \begin{macrocode}
\long\def\toolboxReplaceSplit#1#2#3{%
\toolboxTokDef{#1}\tbx@reptext
\expandafter
\tbx@replace\expandafter{#3}{\let#3\toolboxEmpty}#3#2\tbx@reptext}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\tbx@replace}
% "\tbx@replace\bracemeta{text}\bracemeta{first}\macro\SplitCmd\Reptext"
% First executes \meta{first}.
% Then appends to "\macro" the content of \bracemeta{text} with the matches
% of "\SplitCmd" replaced by the content of "\Reptext".
% \begin{macrocode}
\long\def\tbx@replace#1#2#3#4#5{#2%
#4{#1}\tbx@repla\tbx@replb
\toolboxIfElse{\ifx\tbx@replb\undefined}%
{\toolboxDef#3{#3\tbx@repla}}%
{\toolboxDef#3{#3\tbx@repla#5}%
\expandafter\tbx@replace\expandafter{\tbx@replb}{}#3#4#5}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\toolboxReplace}
% "\toolboxReplace"\bracemeta{search}\bracemeta{replace}"\macro"
% just calls "tbx@DoSplitInstance" with dummy temporary variables
% and then executes "\toolboxReplaceSplit".
% \begin{macrocode}
\long\def\toolboxReplace#1#2{%
\tbx@DoSplitInstance\tbx@splt\tbx@splta\tbx@spltb{#1}\long
\toolboxReplaceSplit{#2}\tbx@splt}
% \end{macrocode}
% \end{macro}
%
% \subsection{Macros supporting redefinition of macros}
%
% \begin{macro}{\toolboxMakeHarmless}\nocomment
% \begin{macrocode}
\def\toolboxMakeHarmless#1{\edef#1{\tbx@Nearverbatim#1}}
% \end{macrocode}
% \begin{macro}{\tbx@Nearverbatim}\nocomment
% \begin{macrocode}
\def\tbx@Nearverbatim{\expandafter\tbx@Meaning\meaning}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@Meaning}\nocomment
% \begin{macrocode}
\long\def\tbx@Meaning#1>{}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\toolboxDropBrace}\nocomment
% \begin{macrocode}
\def\toolboxDropBrace#1{\expandafter\tbx@ForgetBrace#1@tbx@dropbrace#1}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@ForgetBrace}\nocomment
% \begin{macrocode}
\long\def\tbx@ForgetBrace#1@tbx@dropbrace#2{\toolboxTokDef{#1}#2}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\toolboxIf}\nocomment
% \begin{macrocode}
\long\def\toolboxIf#1#2#3{%
\ifx#1#3\def\tbx@tmp{#2#3}\else\def\tbx@tmp{#2\tbx@tmp}\fi\tbx@tmp}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\toolboxNewiftrue}\nocomment
% \begin{macrocode}
\def\toolboxNewiftrue#1{\tbx@newifexec{#1}{\csname#1true\endcsname}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxNewiffalse}\nocomment
% \begin{macrocode}
\def\toolboxNewiffalse#1{\tbx@newifexec{#1}{\csname#1false\endcsname}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxNewiftrue}\nocomment
% \begin{macrocode}
\def\toolboxNewifTrue#1{\tbx@newifexec{#1}{}\csname#1true\endcsname}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxNewiffalse}\nocomment
% \begin{macrocode}
\def\toolboxNewifFalse#1{\tbx@newifexec{#1}{}\csname#1false\endcsname}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\tbx@newifexec}
% \begin{quote}
% "\tbx@newifexec"\bracemeta{name}\bracemeta{initialization}
% \end{quote}
% If the command "\if"\meta{name} already exists, nothing happens.
% Otherwise, the commands \cmdmeta{name}"true" and \cmdmeta{name}"false" are
% created (similarly as by the \TeX\ command "\newif"), and afterwards
% \meta{initialization} is executed. Here, \meta{initialization} should be
% either \cmdmeta{name}"true" or \cmdmeta{name}"false"
% which then defines "\if"\meta{name} to the desired default.
% (It may also be empty if you do this initialization immediately afterwards).
% \meta{initialization} should not contain any potential "\if" tokens.\par
% One must be very careful in the implementation of this macro,
% because "\if"'s are parsed very strange by \TeX.
% However, if an "\if"-command is the first token following our only "\ifx",
% we do not run into problems. Moreover, the first parsing until "\fi" does
% not see any further "\if", because it is hidden in "\csname" which has not
% been expanded by this time.
% \begin{macrocode}
\def\tbx@newifexec#1#2{\expandafter
\ifx\csname if#1\endcsname\relax
\expandafter\tbx@newif\csname if#1\endcsname{#1}%
#2%
\fi}
% \end{macrocode}
% \begin{macro}{\tbx@newif}
% It is rather annoying that D.~E. Knuth has introduced the "\outer"
% directive:
% The sole purpose of that command is to cause problems and to force people
% to think how to get around these problems. It is especially irritating that
% the standard command "\newif" was (before \LaTeXe) defined with this
% attribute. To work in a normal way, we have to define "\newif" by hand
% in a sane way. It is simpler for us, if we do not only pass the name as a
% single token but additionally also the full name without "if".
% So our simpler "\newif" macro is called as follows:
% \begin{quote}
% "\tbx@newif"\cmdmeta{ifname}\bracemeta{name}
% \end{quote}
% This macro does \emph{not} define \cmdmeta{ifname}. But gets automatically
% defined after the first call of \cmdmeta{name}"true" or
% \cmdmeta{name}"false" which should of course happen immediately afterwards.
% \begin{macrocode}
\def\tbx@newif#1#2{%
\expandafter
\def\csname#2true\endcsname{\let#1\iftrue}%
\expandafter
\def\csname#2false\endcsname{\let#1\iffalse}}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Macros supporting concatenated macro names}
%
% \begin{macro}{\toolboxWithNr}\nocomment
% \begin{macrocode}
\def\toolboxWithNr#1#2#3{\expandafter#2\csname #3#1\endcsname}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\toolboxLet}\nocomment
% \begin{macrocode}
\def\toolboxLet#1#2{\expandafter\let\expandafter#1\csname #2\endcsname}
% \end{macrocode}
% \end{macro}
%
% \iffalse
%</package>
% \fi
% \Finale\PrintIndex
%
%
%
% \iffalse
%<*metainfo>
% \fi
\iffalse -------------------------------------------------------------
%
% Just in case that for some reason the file `toolbox.ins' got lost:
% The content of this file is between the lines %<*insfile> and %</insfile>.
%
%\iffalse
%</metainfo>
%<*insfile>
\def\batchfile{toolbox.ins}
\input docstrip.tex
\keepsilent
\nopreamble
\generateFile{toolbox.sty}{f}{\from{toolbox.dtx}{package}}
\generateFile{toolbox.txt}{f}{\from{toolbox.dtx}{asciidocu}}
\generateFile{toolbox.tex}{f}{\from{toolbox.dtx}{driver}}
%%\generateFile{toolbox.ins.dup}{f}{\from{toolbox.dtx}{insfile}}
\Msg{***************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the}
\Msg{* file 'toolbox.sty' into a directory searched by TeX.}
\Msg{*}
\Msg{*}
\Msg{* Run the file toolbox.tex through LaTeX to produce the}
\Msg{* documentation or read the ascii documentation in toolbox.txt}
\Msg{*}
\Msg{*}
\Msg{***************************************************************}
\endbatchfile
%</insfile>
%<*metainfo>
% \fi
\fi
% \iffalse
%</metainfo>
% \fi
\endinput
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "toolbox.tex"
%%% End:
|