summaryrefslogtreecommitdiff
path: root/macros/lamstex/doc/wiz1.tex
blob: f6290477166d958803d6fa0ae9398c7c24a89cfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
\part Preliminaries\endpart

\chapter Introduction\label{INTRO}\endchapter


This manual is intended for 
 \tex\ wizards  pondering the
 intricacies of various \lamstex\
constructions, as well as for 
\tex nicians designing style files for \lamstex\ who need 
more detailed information than that provided by the \lamstex~Style File
Designers Manual.
Although certain points about \tex\ receive detailed explanation,
many sections presuppose
 considerable \tex pertise, which it would be impractical
to try to provide within the scope of this already lengthy manual.


Despite  the manual's lengthiness,
the division into
 chapters and sections allows specialized constructions used for
one part of \lamstex\ to be separated from those used in other parts. 
Of course, the various chapters are not completely independent,
and
 Part~I
 should probably be perused by everyone.



\section{\amstex\ Conventions\label{K}} We will not be analyzing
the file *amstex.tex* itself, since
a detailed description
of \amstex\ is given in the file *amstex.doc*.
Nevertheless, certain \amstex\
 conventions must be mentioned here, 
because they are used throughout 
*lamstex.tex*.

First of all, \amstex\ uses the ``scratch'' tokens *\next*, *\next@*, 
*\nextii@*, *\nextiii@*, \dots. In order to keep the number down, many
definitions will, for example, define *\nextiv@* back in terms of
*\next@*, *\nextii@*, etc.

The *amstex.doc* file mentions the peculiar contortions that are used to
avoid difficulties that might arise when a definition has a clause
like
**
\def\next@{ ... \next ... }
**
since
a previous *\futurelet\next* may have let *\next* be something that is
*\outer*.  

In \lamstex@, on the other hand, it is simply quite out of the question
to allow anything to be *\outer*.  Something like *\claim* can't be
outer, for example, because then things like *\newpre\claim* wouldn't work.
But even something like *\bye* can't be *\outer* because it might easily
occur right after a  point where \lamstex\ has to subject the next
token to some sort of test (see the small print notes
on  pages~\ref{BADOUTER} and ~\ref{BADOUTER2}).
Consequently, although we will continue to reserve *\next* as the token
of choice in all *\futurelet* constructions,
 we will finesse this whole problem by
 making sure that  {\it nothing\/} in \lamstex\ is *\outer*.

The only *\outer* things in *plain* \tex\ are 
the {\ninerm ASCII} form-feed~ *^^L*, the
*\new...* constructions (*\newcount*, *\newdimen*, \dots\,),
  the 
*\+* from the *\settabs* construction, the *\beginsection* and
*\proclaim* constructions, and *\bye*.  
\lamstex\ redefines *^^L*, the *\new...* constructions, 
  *\+*, and *\bye* so that they are not 
 *\outer*,  and it makes
 *\beginsection*
be undefined (\lamstex\ has 
its own system of ``heading levels''), while \amstex\ has already made
*\proclaim* be undefined (until a style file is read in).

It should be mentioned that
although we no longer have to worry about *\next* being  *\outer*,
some precautions are still in order---see page~\ref{NEWPRECAUTION}.

\medskip
Another \amstex\ convention involves constructions like
**
\if...\def\next@{\csa}\else\def\next@{\csb}\fi\next@
**
(It is assumed that the user of this manual understands why this is
required instead of simply *\if...\csa\else\csb\fi* whenever *\csa* or
*\csb* has an argument.) 

In TUG{\ninerm BOAT},
 Volume~8, No.~2,  Kabelschacht\pagelabel{KABEL}
points out that this can be replaced by
**
\if...\expandafter\csa\else\expandafter\csb\fi
**
We will call this the ``K-method''; it is often used without explicit
mention. (As pointed out in the *amstex.doc* file,
 however, this method is not always
valid or practicable).

\medskip
Another frequently used convention of \amstex\ is ``compressed format''.
We often have to make definitions of the form
\setbox0\hbox{\<something or other\>}
**
\def\cs{\futurelet\next\cs@}
\def\cs@{\ifx\next"copy0%
  \def\next@{...\cs@@...}\else
  \def\next@{...\cs@@@...}\fi
 \next@}
\def\cs@@{...}
\def\cs@@@{...}
**
But this uses up three new control sequence names, *\cs@*, *\cs@@*, and
*\cs@@@*, just for this one construction.  The ``compressed format''
uses the same names *\next@*, *\nextii@*, etc., over and over again,
simply redefining them within each definition:
**
\def\cs{%
 \def\next@{\ifx\next"copy0%
   \def\next@{...\nextii@...}\else
   \def\next@{...\nextiii@...}\fi
  \next@}%
 \def\nextii@{...}%
 \def\nextiii@{...}%
 \futurelet\next\next@}
**
Notice that the ``first'' clause *\futurelet\next\next@* has to be made
last (and, although it looks strange at first, it's perfectly legitimate
to have *\next@* defined in terms of *\next@* in this situation).

  Compressed format makes things go a little slower, since *\next@*,
etc., have to be redefined all the time, but seems worth it, especially since
it is usually used for major formatting constructions that introduce
a lot of
space anyway.

\medskip
\amstex\ also uses the construction
**
\Invalid@\controlseq
**
to make *\controlseq* give an error message. As explained in *amstex.doc*,
this is recommended for any control sequences (often discovered via a
*\futurelet*)
that function as ``syntax''
for other control sequences, and consequently shouldn't be encountered
on their own.

\section{Constructions from \amstex\label{AC}}
Some more specific \amstex\ code should also be mentioned.
\Litbox0=**
\ifx\amstexloaded@\relax\catcode`\@=\active
 \endinput\else\let\amstexloaded@=\relax\fi
**
First of all, the code 
$$
\vcenter{\box0} \tag "\style{\bf A}"
\pagelabel{A}
$$
appears
near the beginning of the *amstex.tex* file. This prevents the file
*amstex.tex*
from being loaded twice by making
*\amstexloaded@* be undefined if *amstex.tex* hasn't been loaded, but
*\relax* if it has. This is
a necessity because of the two lines
**
\let\ic@=\/
\def\/{\unskip\ic@} "8itcorr"8
**
that occur later (compare {\it The \tex book}, pp.~382@--383).


Testing *\amstexloaded@* also allows other macro packages to tell whether
*amstex.tex* has already been loaded, which is important for \lamstex@, as
we will see in the next chapter.


\amstex\  also
introduces two new counters, and a new token list,
**
\newcount\count@@
\newcount\count@@@
\toksdef\toks@@=2
**
in addition to the counter *\count@* and token list *\toks@*
provided by *plain.tex*; these
 are also used in \lamstex\ (see section~\Sref{LANDG} for the choice of~*2*
in the *\toksdef*).

Furthermore, \amstex\ introduces the abbreviations
**
\def\FN@{\futurelet\next}
"2
\def\DN@{\def\next@}
\def\DNii@{\def\nextii@}
"2
\def\RIfM@{\relax\ifmmode}     "8RIfM"8
\def\RIfMIfI@{\relax\ifmmode\ifinner}
"2
\def\setboxz@h{\setbox\z@\hbox}
\def\wdz@{\wd\z@}
\def\boxz@{\box\z@}
**
  These are used throughout \lamstex\ also. When we
show
*lamstex.tex* code, however,
we will  usually expand out these definitions,
to make things easier to read.
Similarly, certain control sequences from *plain*, like *\z@*, *\p@*,
etc.,
will usually be expanded out for the sake of readability.
Moreover, in 
constructions like
**
\count@=...
\let\next@=\relax
**
and so forth, we will often add the optional *=* signs that are normally
omitted in the code.


We will frequently use the \amstex\ control sequence *\eat@* defined by
**
\def\eat@#1{}
**

\amstex\ introduces the token *\space@* that has been *\let* equal to a
space. It is often used after 
**
\futurelet\next\foo
**
constructions where *\foo* has to do something special if the next 
token is a space.  In many cases, *\foo* must skip over that space, and
then  execute *\goo*. The standard \amstex\ way of doing this is
with the code
**
\ifx\next\space@\def\next@. {\goo}\else
 \def\next@.{\goo}\fi\next@. "8swallow"8
**
The *.* after the *\next@* makes the space `visible' to  \tex.


As we shall see in section~\Sref{FIX},  \lamstex\ introduces a
somewhat more economical approach to this problem.

By the way,  a case like this, where something
is part of the syntax for *\next@*, is one of the situations where
the K-method would not work.

\medskip
There are a few more \amstex\ devices that are important in \lamstex@, but
their discussion has been deferred until Chapter~\ref{CA}, since these devices
are actually additions intended for later versions of \amstex.


\section{Changes to \amstex; \CS{local} and \CS{global}
assignments\label{LANDG}}
Numerous lines
of *amstex.tex* have been deleted in *amstexl.tex* because they are not
used, or are modified, by *lamstex.tex*. Major changes of this sort are
discussed at the appropriate points.

There are also numerous small changes. For example, all *\relaxnext@*'s have
been omitted, since \lamstex\ no longer needs that device for dealing
with *\outer* constructions. 

One change was necessary to avoid a conflict:
 *\roman* is now used in \lamstex\ for a numbering control sequence,
whereas it
 previously had a different
 (extremely unlikely) use in \amstex@, as a control sequence to
be used in math to produce a roman letter. The latter has now been changed
from *\roman* to *\rom*. 

One other
change should be mentioned explicitly: near the beginning of *amstexl.tex*
the definitions
**
\def\height{height}  "8HWD"8
\def\width{width}
\def\depth{depth}
**
have been inserted, so that `*height*', `*width*' and `*depth*' can
be replaced by the corresponding single tokens in the specifications for
various *\hrules* and *\vrules*; these replacements save even more memory
space in *lamstex.tex*, where rules occur much more frequently.



Finally, I have now conscientiously adhered to {\it The \tex book\/}'s
 recommendations (see pages~301 and~346)
that assignments of variables either always be  global or
always be
local. In most cases, the necessary changes have been minor (like
changing some *\xdef*'s to *\edef*'s, or vice versa), but somewhat more
extensive changes were required to ensure that *\setbox*\,{\it n} is
 always
local for {\it n\/} even
and
global
for {\it n\/} odd; these changes occur in the definitions of
*\insplit@*, *\rendsplit@*, *\lendsplit@*, *\lmultline@@@*, 
*\rmultline@@@*, *\binrel@*, *\sideset@*, *\r@@t*, *\pmb@*, and perhaps
one or two other places.

We will exercise comparable care regarding assignments of variables\linebreak
throughout \lamstex.


\chapter Getting started with \lamstex\label{GETSTART}\endchapter

The first thing in *lamstex.tex*, after the  copyright notice,
is
\C**
\catcode`\@=11
**
to make *@* a letter, in order to create ``private'' control sequences that
the casual user  cannot type, as well as to access such private control
sequences from *plain.tex* and *amstexl.tex*.

We will always adhere to the
 convention introduced here, using horizontal lines
when we print
 actual
*lamstex.tex* code, as opposed to examples, pieces of code, etc.
We will often use different line breaks from the actual *lamstex.tex*
code, so that it will fit better on these printed pages. (It should also be
noted that when we give preliminary pieces of code we will often omit 
*%*~
signs  at the ends of lines, although they are meticulously added when needed
in the code itself.)


Since \lamstex\ is not supposed to be loaded unless \amstex\ has already been
loaded, the  next code,
\C**
\ifx\amstexloaded@\relax\else
 \errmessage{AmS-TeX must be loaded before LamS-TeX}\fi
** 
produces an error message if it hasn't---see the discussion of
the code  ({\bf A}) on page~\ref{A}.


We will adopt a different scheme for preventing  *lamstex.tex* from being
read in twice,
one that doesn't create a new control sequence name, by
using the fact that *lamstex.tex* will 
eventually define the control sequence
*\laxread@* (see page~\ref{lax}), while \amstex\ makes certain that
*\undefined* is always undefined (see *amstex.doc*):
\C**
\ifx\laxread@\undefined\else\catcode`\@=\active\endinput\fi
**


[Other  
 macro packages that need to know whether or not
\lamstex\ has been loaded can use a similar test, or, if the 
status of *\undefined* isn't clear, they can use the test
**
\expandafter\ifx\csname laxread@\endcsname\relax
**
which is false when \lamstex\ has been loaded, but true when it hasn't been
loaded, since the control sequence produced by 
*\csname...\endcsname* is given the value *\relax* if it hasn't already
been defined.]



Next we redefine *\err@* from \amstex\ to produce error messages saying
`*LamS-TeX error:*'
instead of `*AmS-TeX error*:'
\C**
\def\err@#1{\errmessage{LamS-TeX error: #1}}
**
*\Err@*, which is *\err@* with \amstex's ``default help message'', will
now also produce such error messages (see
section~\Sref{STER}).


As indicated in section~\Sref{K},
we redefine *^^L*, the *\new...* constructions, *\+*, and *\bye*
 from *plain* so that they are not
*\outer*,
\C**
\def^^L{\par}
\let\+=\tabalign
"2
\def\newcount{\alloc@0\count\countdef\insc@unt}
"2
\def\newdimen{\alloc@1\dimen\dimendef\insc@unt}
"2
\def\newskip{\alloc@2\skip\skipdef\insc@unt}
"2
\def\newmuskip{\alloc@3\muskip\muskipdef\@cclvi}
"2
\def\newbox{\alloc@4\box\chardef\insc@unt}
"2
\let\newtoks=\relax
\def\newhelp#1#2{\newtoks#1#1\expandafter{\csname#2\endcsname}}
\def\newtoks{\alloc@5\toks\toksdef\@cclvi}
"2
\def\newread{\alloc@6\read\chardef\sixt@@n}
"2
\def\newwrite{\alloc@7\write\chardef\sixt@@n}
"2
\def\newfam{\alloc@8\fam\chardef\sixt@@n}
"2
\def\newlanguage{\alloc@9\language\chardef\@cclvi}
"2
\def\newinsert#1{\global\advance\insc@unt by\m@ne
  \ch@ck0\insc@unt\count
  \ch@ck1\insc@unt\dimen
  \ch@ck2\insc@unt\skip
  \ch@ck4\insc@unt\box
"2
  \allocationnumber=\insc@unt
  \global\chardef#1=\allocationnumber
  \wlog{\string#1=\string\insert\the\allocationnumber}}
"2
\def\newif#1{\count@\escapechar \escapechar\m@ne
  \expandafter\expandafter\expandafter
   \edef\@if#1{true}{\let\noexpand#1=\noexpand\iftrue}%
"2
  \expandafter\expandafter\expandafter
   \edef\@if#1{false}{\let\noexpand#1=\noexpand\iffalse}%
  \@if#1{false}\escapechar\count@} % the condition starts out false
"slip
\def\bye{\par\vfill\supereject\end}
**
and then we
\C**
\let\beginsection=\undefined
**
to make *\beginsection*  undefined (see *amstex.doc*).

\small In *plain* \tex@, the *\let\newtoks=\relax* is inserted before
the definition of *\newhelp* so that *plain.tex* can be read in twice.
Even though we are not allowing *lamstex.tex* to be read in twice, this
is still required, since we read it in after *plain.tex*!
\endsmall



\chapter Changes to \amstex\label{CA}\endchapter



The next part of \lamstex\ contains various changes to \amstex@. Some of
the changes should,
and probably eventually will, be made in \amstex@, though they didn't get
included in
 \amstex~version *2*, while other changes are relevant only for \lamstex. 
(Further changes to \amstex\ will be made later, at the relevant points.)

\section{\CS{Err\@}\label{STER}}
\amstex's definition of *\Err@*, {\litindent=0pt
**
\def\Err@#1{\errhelp\defaulthelp@\errmessage{AmS-TeX error: #1}}
**
has been deleted in *amstexl.tex*,} because it 
can obviously be shortened to
\C**
\def\Err@#1{\errhelp\defaulthelp@\err@{#1}}
**


\section{\CS{atdef\@}\label{ATDEF}}
\amstex's original mechanism for defining the active *@* character 
can be
improved considerably.

First of all, we want the active *@* to mean
**
\futurelet\next\at@
**
the problem being that we need to make this definition while *@* is active
**
{\catcode`\@=\active
 \def@{...}
** 
even though we want to allow *@* as part of the control sequence name
 *\at@*.

Now we can easily name *\at@* even when *@* is active, as
**
\csname at\string@\endcsname
**
Of course, we can't simply say
**
\def@{\futurelet\next\csname at\string@\endcsname}
**
since *@* would then simply *\let\next=a*---we need to have the
combination
*\csname...\endcsname* expanded out before the *\futurelet\next* takes
effect. 

We could do this with
**
\def@{\def\next{\futurelet\next}\expandafter\next
  \csname at\string@\endcsname}
**
but that's somewhat unsatisfactory, since 
it requires the active~ *@* to make a
subsidiary definition each time it is used.

Another possibility is to use the triple *\expandafter* trick (see
{\it The \tex book}, page~374), which we will be using later on. But for the
present problem the simplest  
strategy is to use the code
**
 \edef\next{\gdef\noexpand@{\futurelet\noexpand\next  "8ATD"8
  \csname at\string@\endcsname}
 \next
**
Here the *\edef* makes *\next* mean
**
"9\gdef"9","9@"9{"9\futurelet"9","9\next"9\at@}
**
where the boxed control sequences are not expanded out either because they
are primitives or because they are preceded by *\noexpand*; the
*\csname..."allowbreak"0\endcsname* 
{\it is\/} expanded out in the *\edef*, but the
control sequence *\at@* that it expands to is made equal to *\relax*,
since *\at@* hasn't been defined previously---so *\at@*
isn't expanded further in the *\edef*. (Here we are using the fact that
*lamstex.tex* won't be read in twice [Chapter~\ref{GETSTART}].)

Consequently, when we then call *\next* we get this *\gdef*. Thus,
 to get
the desired definition of the active *@* we just need 
\C**
{\catcode`\@=\active
 \edef\next{\gdef\noexpand@{\futurelet\noexpand\next
  \csname at\string@\endcsname}}
 \next
}
**

The definition of *\at@* itself is now easy, with *@* back as a letter.
We will call the very same routine, *\at@@*,
 when the next token is a letter,
other character, or control sequence (or active character); for any other
type of token we will call *\at@@@*, which will be an error message: 
\C**
\def\at@{%
 \ifcat\noexpand\next a\let\next@=\at@@\else
 \ifcat\noexpand\next0\let\next@=\at@@\else
 \ifcat\noexpand\next\relax\let\next@=\at@@\else
 \let\next@=\at@@@\fi\fi\fi\next@}
**

The error message *\at@@@* is simply
\C**
\def\at@@@{\errhelp\athelp@\err@{Invalid use of @}}
**
using the help message *\athelp@* from \amstex@.


On the other hand,
 *\at@@* \<token\> will simply be the control sequence
\setbox0\hbox{\<token\>}
\setbox1\hbox{`}\setbox2\hbox{'}
**
"box1"0\"box0@at"box2
**
if it has been defined, or an error message otherwise. Here we put
quotes around *\*\<token\>*@at* to emphasize that it is a single
control word, even when \<token\> isn't a letter;\pagelabel{QTS1}
 in practice, of course,
such control words have to be constructed using
*\csname"allowbreak..."allowbreak\endcsname*: 
\C**
\def\at@@#1{\expandafter
 \ifx\csname\string#1@at\endcsname\relax
  \let\next@=\at@@@
 \else
  \def\next@{\csname\string#1@at\endcsname}%
 \fi
 \next@}
** 
Note that we use *\string#1* so that the token
*#1* can be a control sequence or
active character, as well as a letter or other character.




Finally,  *\atdef@*, the mechanism for defining the value of the
active *@* on various tokens, is the same as in \amstex@, except that we
add a
  *\string*:
\C**
\def\atdef@#1{\expandafter\def\csname\string#1@at\endcsname}
**

There are two noteworthy things about this redefinition: 
\list
\item The original definition of *\atdef@* remains in *amstexl.tex*, because
it is used for
**
     \atdef@;{...}       \atdef@,{...}
     \atdef@:{...}       \atdef@!{...}
     \atdef@?{...}       \atdef@.{...}
     \atdef@-{...}
**
These *\atdef@*'s
give the same results as the new *\atdef@* would give,
 since for these characters the *\string* is simply
redundant---once *@* is active, *@;* and *@:* and so forth
 will work just
as before.  
(The *\atdef@@\vert* is irrelevant:  it is deleted in
*amstexl.tex*, and not used in \lamstex@.)

\item Later in \lamstex\ we are going to make *""* active.  Nevertheless,
\amstex's
**
     \atdef@""
**
will still make the combination
*@""* work correctly,\pagelabel{SW}
 because *\string""* for *""* active  gives
the same result as \amstex's *""* when *""* is not active.  
Actually, we are going to give a new *\atdef@""* (section~\Sref{FIX}),
but that will be done before *""* is made active, so the same principle 
still applies.
\endlist



\section{Tests\label{TESTS}}
\amstex\ has the flag *\ifin@*, which is set only by the routine *\in@*,
a test to determine whether a particular token appears in any sequence; this
test,
 in turn, is used only by the routine *\tagin@* to check for the presence
of *\tag* in a sequence.
  \lamstex\ has numerous
tests that are always performed independently, so it is economical to have a
single flag that will be used by all of them; this flag will
 also replace *\ifin@*
from \amstex@. So  *amstexl.tex* 
deletes the line
**
\newif\ifin@
**
and in \lamstex\ we
 introduce the flag
\C**
\newif\iftest@
**


Moreover, in *amstexl.tex* 
we also delete
**
\def\in@#1#2{ . . . }
\def\tagin@#1{ . . . }
**
while in \lamstex\ we
  redefine the *\tagin@* routine so that instead of using
*\ifin@* it merely reproduces (an equivalent of) the definition:
\C**
\def\tagin@#1{\tagin@false
 \def\next@##1\tag##2##3\next@{\test@true
  \ifx\tagin@##2\test@false\fi}%
 \next@#1\tag\tagin@\next@
 \tagin@false\iftest@\tagin@true\fi}
**

\section{Spaces after control sequence names in error messages\label{SACN}}
Numerous
error messages in \amstex\ use constructions of the form
**
 . . . \string\controlseq\space . . .
**
to get a space after the control sequence
 *\controlseq* in the error message.  However, it
saves one token to instead use
**
 . . . \noexpand\controlseq . . .
**
---the *\noexpand* prevents expansion of *\controlseq*
in the error message, but we still
get a space after *\controlseq*. 

This device is used throughout \lamstex@, and the requisite changes were
also made directly in *amstexl.tex*, since they were so minor. 


\small
 The first change
occurs in
the definition of
*\define@*
where
**
\err@{\string\define\space must be . . . }
**
is replaced by
**
\err@{\noexpand\define must be . . . }
**
The next occurs in the definition
**
\define@@#1
**
which takes a control sequence *#1* as its argument, where, for example
\Litbox0=**
\err@{\string#1 is already defined}
**
$$\box0\tag"\style{\bf A}"$$
is changed to
**
\err@{\noexpand#1is already defined}
**
with no space before the `*is*', since it will appear when the error
message is given. [*amstex.tex* actually has 
**
\err@{\string#1\space is already defined}
**
which is unnecessary complicated, though it has the same number of
tokens as ({\bf A}).]


Similar replacements are made in the definitions of
**
\vmodeerr@#1
\mathmodeerr@#1
"2
\dmatherr@#1
"2
\nondmatherr@#1
"2
\onlydmatherr@#1
"2
\nonmatherr@#1
"2
\nonvmodeerr@#1
\textonlyfont@#1#2
**

Finally, in the definition of *\boldkey* (which is actually redefined
in *lamstex.tex*---see page~\ref{NEWBK}) the
**
\Err@{\string\boldkey\space can't ...}
**
is replaced by
**
\Err@{\noexpand\boldkey can't ...}
**
with a similar change for
 *\boldsymbol*.

Note, by the way, that these substitutions cannot be made in 
**
\newhelp\athelp
\newhelp\defahelp
**
which end up putting things inside *\csname...\endcsname*.
\endsmall



\section{Line breaking\label{LBK}}
The original \amstex\ definition of *\nolinebreak*
 had an extra element *\refskip@*,
 which was initially *\relax*, but which
was changed for the bibliography. In version~*2*,
that aspect of the bibliography macros (sections~\Sref{BASICD} and
~\Sref{BIBMACS}),
as well as the indexing macros (section~\Sref{IPAGE}),
  has been improved.  Consequently, the
four control sequences
**
\nolinebreak
\allowlinebreak
\linebreak
\newline
**
will all have something added; it will suffice to add the same thing,
which we will call *\lkerns@*, to the first three,
and
something that we will call *\nkerns@* to the fourth;
 like the old *\refskip@*,
these are both initially *\relax*.  The definitions of these four
line-breaking macros are deleted in *amstex.tex*, and we now add
the new definitions. They differ from the original definitions (see
*amstex.doc*) in the inclusion of  *\lkerns@* and *\nkerns@*;
however, these do not occur in quite the place that *\refskip@* occurred
in the original definition of *\nolinebreak*---that was, in fact, incorrect.
We have also simplified the definition of *\newline*---as indicated 
in *amstex.doc*, 
the case of *\newline\par* 
really isn't worth worrying about.
\C**
\let\lkerns@=\relax
"slip
\def\nolinebreak{\relax
 \ifmathmode@
  \mathmodeerr@\nolinebreak\else
"2
 \ifhmode
  \saveskip@=\lastskip \unskip
  \nobreak
  \ifdim\saveskip@ > 0pt \hskip\saveskip@\fi
  \lkerns@
 \else\vmodeerr@\nolinebreak\fi\fi}
"2
\def\allowlinebreak{\relax
 \ifmathmode@
  \mathmodeerr@\allowlinebreak\else
"2
 \ifhmode
  \saveskip@=\lastskip \unskip
  \allowbreak
  \ifdim\saveskip@ > 0pt \hskip\saveskip@\fi
  \lkerns@
 \else\vmodeerr@\allowlinebreak\fi\fi}
\def\linebreak{\relax
 \ifmathmode
  \mathmodeerr@\linebreak\else
"2
 \ifhmode
  \unskip\unkern\break\lkerns@
 \else\vmodeerr@\linebreak\fi\fi}
"slip
\let\nkerns@=\relax
"slip
\def\newline{\relax
 \ifmathmode
  \mathmodeerr@\newline\else
"2
 \ifhmode
  \unskip\unkern\null\hfill\break\nkerns@
 \else\vmodeerr@\newline\fi\fi}%
**


\section{\CS{alloc\@\@}, \CS{newcount\@}, and \CS{newbox\@}\label{NEWNEW}}
Near the beginning of
\amstex@, *\alloc@* is redefined so that it doesn't write anything to the
*.log* file, while the original definition is reinstated at the end.
This means that 
the *\new...* constructions used to create new counters, \<dimen\> registers,
etc., within the file
do not write anything to the *.log* file.

After redefining *\alloc@*, \amstex\ also uses
**
\let\alloc@@=\alloc@
**
to make *\alloc@@* {\it that\/} version of *\alloc@*, even if called
after *\alloc@* has been redefined at the end. 
In the definition of *\loadmsam*, for example, the code
**
 . . . 
\alloc@@8\fam\chardef\sixt@@n\msafam
 . . .
**
functions
as a replacement for *\newfam\msafam*; this not only gets around the problem
that *\newfam* is still *\outer* in \amstex@, it also ensures that
nothing gets written to the *.log* file even if *\loadmsam* is used
after *\alloc@* is restored to its old definition.

In the definition of *\accentedsymbol*, however, a non-outer *\newbox*
is needed, because it appears in a construction like
**
\expandafter\newbox\csname ... \endcsname
**
where we can't simply use the code for *\newbox*. So 
*amstex.tex* used *\newbox@* as a non-outer version of *\newbox*.
However, the \amstex\ definition,
**
\def\newbox@{\alloc@4\box\chardef\insc@unt}
**
because it used *\alloc@* rather than *\alloc@@*, wasn't really the right
choice anyway.

In \lamstex\ we rectify this situation.  First of all, the definitions of
*\newbox@* and *\accentedsymbol* are deleted in *amstexl.tex*.  Then in
*lamstex.tex*, we
\C**
\def\newbox@{\alloc@@4\box\chardef\insc@unt}
**
and also, for later use,
\C**
\def\newcount@{\alloc@@0\count\countdef\insc@unt}
**

Then we redefine *\accentedsymbol* using *\newbox@*. In addition, the
combination 
**
\expandafter\eat@\string
**
in the definition is replaced by *\exstring@*, since we will introduce
this as an abbreviation for that combination later (section~\Sref{CNT}) (we
also take the opportunity to eliminate two unnecessary *\expandafter*'s from
the original code):
\C**
\def\accentedsymbol#1#2{\expandafter
 \newbox@\csname\exstring@#1@box\endcsname
 \setbox\csname\exstring@#1@box\endcsname
  =\hbox{$\m@th#2$}%
 \define#1{\copy\csname\exstring@#1@box\endcsname{}}}
**

\section{Lists\label{LISTS}}
\amstex\ has two lists, *\alloclist@*, and *\fontlist@*,
of the type introduced in {\it The \tex book}, page~378, and it defines
*\rightappend@*,  which is like 
*\rightappenditem* from that page.

 *\alloclist@* is maintained for
the *\showallocations* command, which is really only for the use of
\tex nicians, and \lamstex\ dispenses with this feature, in order to save
space; consequently,
in *amstexl.tex* all material related
to *\alloclist@* is deleted.

*\fontlist@* is used for the *\syntax* command, which \lamstex\ retains,
but
for this list of control sequence names it is more efficient to use
a list of the type described on page~379 of {\it The \tex book}:
\setbox0\hbox{name$_{\text1}$}%
\setbox1\hbox{name$_{\text2}$}%
**
\\\"box0\\\"box1...
**
Several other lists of this sort will be used in \lamstex@; in some cases,
we will even have a list of the form *\\_",_",_\\_",_",_ ...*, where
*_",_",_* are not control sequence names.

In \lamstex\ we will still be using 
*\rightappend@* on occasion, but
we will also define
the routine *\rightadd@#1\to#2* to add *#1* to 
one of these simpler lists *#2*:
\C**
\def\rightadd@#1\to#2{\toks@={\\#1}\toks@@=\expandafter{#2}% "8atl"8
 \xdef#2{\the\toks@@\the\toks@}%
 \toks@={}\toks@@={}}
**

In *amstexl.tex*, the definition of *\fontlist@* is deleted,
and in \lamstex\ 
we instead define *\fontlist@* to be a list of this simpler sort:
\C**
\def\fontlist@{\\\tenrm\\\sevenrm\\\fiverm\\\teni\\\seveni
 \\\fivei\\\tensy\\\sevensy\\\fivesy\\\tenex\\\tenbf
 \\\sevenbf\\\fivebf\\\tensl\\\tenit}
**

Similarly, the definition of *\font@* is deleted in *amstexl.tex*
and replaced in \lamstex\ by
\C**
\def\font@#1=#2 {\rightadd@#1\to\fontlist@\font#1=#2 } "8FL"8
**
(Although *\font@* appears in *amstexl.tex*, it occurs only within
other definitions, so the definition can be deferred to *lamstex.tex*.)


Although,
as mentioned in section~\Sref{TESTS}, the test *\ifin@* has been deleted in
\linebreak
*amstexl.tex*, 
for a list *#1* of control sequences,
\setbox0\hbox{name$_{\text1}$}%
\setbox1\hbox{name$_{\text2}$}%
**
\\\"box0\\\"box1...
**
we will need another (simpler) test to 
determine whether a control sequence *#2* 
is in the list. Basically we want to use
**
"hskip-30pt\def\ismember@#1#2{\test@false\let\next@=#2%
"hskip-30pt {\def\\##1{\let\nextii@=##1\ifx\nextii@\next@\global\test@true\fi}#1}%
**
But since we normally set the flag *\iftest@* only locally, we don't want
to use a *\global\test@true* in this one situation (compare
section~\Sref{LANDG}).
 So instead we will use a
new 
scratch token, *\Next@*, for which we will always use *\global* assignments.
In addition, there are two further details that we will explore in a moment:
\pagelabel{GNXT}
\C**
\def\ismember@#1#2{"9\global\let\Next@=F"9\let\next@"9=" "9#2%  "8ismember"8
 {\def\\##1{\let\nextii@=##1\ifx\nextii@\next@
  "9\global\let\Next@=T"9\fi}#1}%
 \test@false\ifx\Next@ T\test@true\fi"9\let\next@=\relax"9}
**

This test
may compared with the test on page~379 of {\it The \tex book}. Using
*\let\next@* instead of *\def\next@*  allows the test
**
\ismember@#1\next
**
to be used after *\next* has been *\let* equal to some control sequence
by a *\futurelet*\pagelabel{ISFL}, which will be important 
in section~\Sref{ZZZ} (on some occasions 
we will also be using *\ismember@#1#2* when
*#2* is an explicit argument).
 But two precautions are then in order:


\bullist \item\pagelabel{NEEDEQ}
Although actual *lamstex.tex* code usually omits
*=* signs after *\let*'s, in the above code we need both the boxed *=*
sign {\it and the space after it\/}!
 Reason: Our *\futurelet* may have
*\let\next* be a space token, which is thus a \<space token\> in
the notation of {\it The \tex book}, page~269. According to the syntax
rule on page~277, one such space (but only one)
will be ignored after the *=* sign; if we simply had
**
\let\next@=#2{\def\\ ...
**
then the \<space token\> *#2* would be ignored, and
*\next@* would end up being the *{*, which would then disappear, causing
infinite confusion later on.

\item
Another important precaution is the *\let\next@=\relax* at the end. That is
needed because the *\futurelet\next* may have
*\let\next*  equal something
equivalent to *\iftrue* or *\iffalse*, so that *\next@* would then also
be equal to
*\iftrue* or *\iffalse*. If that situation were allowed to continue, havoc
might ensue the next time we used a macro containing *\next@* within it.
\endlist

As an example of this latter phenomenon,\pagelabel{NEWPRECAUTION}
 note that the original *plain* \tex\ 
  definitions
**
"hskip-30pt{\catcode`\'=\active \gdef'{^\bgroup\prim@s}}
"hskip-30pt\def\prim@s{\prime\futurelet\next\prim@m@s}
"hskip-30pt\def\pr@m@s{\ifx'\next\let\next\pr@@@s \else\ifx^\next\let\next\pr@@@t
"hskip-30pt \else\let\next\egroup\fi\fi\next}
"hskip-30pt . . . 
** 
 later had to be modified by changing *\pr@m@s* to
**
"hskip-30pt\def\pr@m@s{\ifx'\next\let\nxt\pr@@@s \else\ifx^\next\let\nxt\pr@@@t
"hskip-30pt \else\let\nxt\egroup\fi\fi\nxt}
**
For example, we might have
**
$a'\iffirstset x\else y \fi$
**
where *\iffirstset* is some user-defined construction, and then
the\linebreak *\futurelet\next* in
*\prim@s* 
would *\let\next=\iffirstset*.
Note that the appearance of 
*\next*
after an *\ifx* test 
causes no problem,
but its appearance within an *\if...* clause, even following
a *\let* or *\def*, would make things go haywire. Similarly, in the
definition of *\ismember@*, the
*\next@* appears in safe places.

To avoid such problems in general, after any *\futurelet* we will use
only the token *\next*, and otherwise
*\next* will not appear in any macros except
after *\ifx* tests (or *\ifcat* tests). One definition in *amstex.tex*
requires modification to adhere to this rule: the definition
**
"hskip-30pt\gdef\comment@@@#1\comment@@@{\ifx\next\comment@@@\let\next\comment@
"hskip-30pt \else\def\next{\oldcodes@\endlinechar=`\^^M\relax}%
"hskip-30pt \fi\next}
**
has been changed in *amstexl.tex* to
**
"hskip-30pt\gdef\comment@@@#1\comment@@@{\ifx\next\comment@@@\let\next@\comment@
"hskip-30pt \else\def\next@{\oldcodes@\endlinechar=`\^^M\relax}%
"hskip-30pt \fi\next@}
**




 \section{Skipping spaces in \CS{futurelet}'s\label{FIX}}
On page~\ref{swallow} we mentioned 
 \amstex's device for skipping over space
tokens in *\futurelet* constructions. Instead of using this device
directly, which requires somewhat long definitions each time, \lamstex\ uses a
special ``futurelet-next-skipping-spaces'' construction
**
\FNSS@\foo
**
which is like *\futurelet\next\foo*, except that any space tokens after
*\foo* will be discarded, and *\foo* will be applied after
*\next* has been *\let* equal to the
first non-space token after *\foo*.  *\FNSS@#1* begins
 by storing *#1* in
*\FNSS@@*, and then 
applies a *\futurelet\next* construction, calling *\FNSS@@@*, which
 then does the checking for a space:


\C**
\def\FNSS@#1{\let\FNSS@@=#1\futurelet\next\FNSS@@@}
"slip
\def\FNSS@@@{\ifx\next\space@
 \def\FNSS@@@@. {\futurelet\next\FNSS@@@}\else
 \def\FNSS@@@@.{\FNSS@@}\fi
 \FNSS@@@@.}
**
Thus, when *\next* happens to be a space, we swallow the space and call
the routine
*\futurelet\next\FNSS@@@* again, to get the next non-space token; 
when we do get a non-space token,
 we simply apply *\FNSS@@*, the argument of *\FNSS@*.

\medskip
The \amstex\ *\atdef@""* (see *amstex.doc*) is deleted from *amstexl.tex*,
because it
can be shortened
if we use
this *\FNSS@* to get the first non-space token after *@""*:
\C**
\atdef@""{\unskip
"2
 \def\next@{\ifx\next`\def\next@`{\futurelet\next\nextii@}%
  \else\ifx\next\lq\def\next@\lq{\futurelet\next\nextii@}%
  \else\def\next@####1{\futurelet\next\nextiii@}\fi\fi
  \next@}%
"2
 \def\nextii@{\ifx\next`\def\next@`{\sldl@``}%
  \else\ifx\next\lq\def\next@\lq{\sldl@``}%
  \else\def\next@{\dlsl@`}\fi\fi\next@}%
"2
 \def\nextiii@{\ifx\next'\def\next@'{\srdr@''}%
  \else\ifx\next\rq\def\next@\rq{\srdr@''}%
  \else\def\next@{\drsr@'}\fi\fi\next@}%
 \FNSS@\next@}
**

[In our definition of *\FNSS@@@* we used a new control sequence
*\FNSS@@@@* instead of using a scratch token like *\next@* 
to allow the use of *\FNSS@* 
 in such ``compressed format'' definitions.]

There is only one other definition in \amstex\ that
is (deleted from\linebreak *amstexl.tex* and)
shortened using *\FNSS@*:
\C**
\def\root{%
  \def\next@{\ifx\next\uproot\let\next@=\nextii@\else
"2
   \ifx\next\leftroot\let\next@=\nextiii@\else
"2
   \let\next@=\plainroot@\fi\fi\next@}%
"2
  \def\nextii@\uproot##1{\uproot@##1\relax\FNSS@\nextiv@}%
"2
  \def\nextiv@{\ifx\next\leftroot\let\next@=\nextv@\else
   \let\next@=\plainroot@\fi\next@}%
"2
  \def\nextv@\leftroot##1{\leftroot@##1\relax\plainroot@}%
"2
  \def\nextiii@\leftroot##1{\leftroot@##1\relax
   \FNSS@\nextvi@}%
"2
  \def\nextvi@{\ifx\next\uproot\let\next@=\nextvii@\else
   \let\next@=\plainroot@\fi\next@}%
"2
  \def\nextvii@\uproot##1{\uproot@##1\relax\plainroot@}%
  \bgroup\uproot@\z@\leftroot@\z@
 \FNSS@\next@}
**

 However, there are numerous places in \lamstex\ where
the use of *\FNSS@* will similarly save space, definitely make the extra
tokens used for *\FNSS@* worth while.
Note, moreover, that the above definition of *\root*
not only saves space, but also 
avoids introducing the scratch tokens
*\nextviii@* and *\nextix@* that occur in the
original definition,
but which occur nowhere else in \amstex.



\section{\CS{loop}\label{LOOP}}
The same article that introduced the ``K-method'' (page~\ref{KABEL})
also introduced a new definition of *plain* \tex's *\loop...\repeat*
mechanism, which we will use in \lamstex:
\C**
\def\loop#1\repeat{%
 \def\iterate{#1\relax\expandafter\iterate\fi}%
 \iterate\let\iterate=\relax}
**
This has the property that it allows constructions like
**
\loop _",_",_ \if...  _",_",_ \else  _",_",_ \repeat
**
where we repeat when the *\if...* test is {\it false\/} rather than
true, which will turn out to be useful at several points in \lamstex@.
\footnote{The alternative is to use
*\if... \test@false \else \test@true \fi  \iftest@ _",_",_ \repeat*.}

Corresponding to this redefinition of *\loop*, we add a new definition 
of *\gloop@* (which is used by the *\cfrac* construction):
\C**
\def\gloop@#1\repeat{%
 \gdef\iterate@{#1\relax\expandafter\iterate@\fi}%
 \iterate@\global\let\iterate@=\relax}
**
The main purpose of redefining *\gloop@* is so that it will use *\iterate@*
rather than *\iterate*, so that *\iterate* will only be given a local
definition, not both a local and a global one (compare section~\Sref{LANDG}).


In *amstexl.tex* we delete the line
**
\newif\ifbadans@
**
and the definition of *\printoptions*, because we can define *\printoptions*
in terms of *\iftest@* (section~\Sref{TESTS}).  We've deferred this
redefinition until now because it is also a little bit more convenient to
use this alternative *\loop* test:
\C**
\def\printoptions{\W@{Do you want S(yntax check),
  G(alleys) or P(ages)?^^JType S, G or P, follow by 
   <return>: }%
"2
 \loop
  \read -1 to\ans@
  \edef\next@{\def\noexpand\Ans@{\ans@}}%
   \uppercase\expandafter{\next@}%
  \ifx\Ans@\S@\global\test@true\syntax\else
  \ifx\Ans@\G@\global\test@true\galleys\else
  \ifx\Ans@\P@\global\test@true\else
  \global\test@false\fi\fi\fi
 \iftest@
 \else
  \W@{Type S, G or P, follow by <return>: }%
 \repeat}
**



\section{A l\'a fran\c cais\label{ALF}}Finally, 
certain changes are made to *amstex.tex*
to accommodate French styles that make some or all of
*;* and *:* and *!* and *?* into active characters. In this case, various
\amstex\ macros that involve tests like
**
\ifx\next!
**
need to be changed. 
\footnote{In addition, in *lamstex.tex* we  have the problem that certain
control sequences, notably those for commutative diagrams and tables, use
certain punctuation as part of their {\it syntax}. For example, the *\ds*
option for arrows in a commutative diagram is typed in the form
*\ds(h;v)* (see page~155 of the \lamstex~Manual).
If we make a definition
like
*\def\ds(#1;#2){...}*, then
\tex\ incorporates a type~*12*~ *;* as part of the
syntax for *\ds*. So in a document where *;* is active, the *;* that the user
types will not be recognized as the proper syntax element. The devices for
handling this problem will be discussed at the appropriate time (in
Volume~2).}  

Our goal is to allow
all necessary changes  to be indicated in a 
reasonably short file, say *french.tex*, which can
be read in {\it after\/} *lamstex.tex* (so that it can be loaded on top of a
\lamstex\ format file). 


The most reasonable approach is to have certain control sequences
that have been *\let* equal to the active punctuation symbols, so that
we can use these in an *\ifx\next...* test.  Of course, this can only 
be done after the active punctuation symbols have been defined, not in
*amstexl.tex*. To get around this problem, 
we will  insist that the definition of the active punctuation 
symbols
in *french.tex* are not made with an ordinary *\def*, but with
 a special *\APdef*, which will manage things properly for us.


For the control sequences that  will be *\let* equal to the active
punctuation symbols
we will use the following control words (which have to be
created using *\csname...\endcsname*):~
`*\A@;*' and `*\A@:*' and `*\A@?*' and ~`*\A@!'*. 
 We begin by
assigning the non-active characters as default values:
\C**
\expandafter\let\csname A@;\endcsname=;
\expandafter\let\csname A@:\endcsname=:
\expandafter\let\csname A@?\endcsname=?
\expandafter\let\csname A@!\endcsname=!
**

When 
**
\APdef:{ ... }
**
appears in *french.tex*, we want to (1)~\hbox{*\def:{ ... }*} and
(2)~*\let*`*\A@:*'*=:* (here,\pagelabel{QTS2}
 as on page~\ref{QTS1},
 we put quotes around *\A@:* to emphasize
that it is a single control word; in actual code  something
like
**
\expandafter\let\csname A@\string:\endcsname=:
**
will be needed).

To achieve this, we use
\C**
\def\APdef#1{\def\next@{\expandafter
 \let\csname A@\string#1\endcsname=#1}%
 \afterassignment\next@\def#1}
**
Thus, for example,
*\APdef:* defines *\next@* to mean
\setbox0\hbox{`*\A@:*'}
**
\let"box0=:
**
and after the assignment *\def:*, which swallows the following
\hbox{*{ ... }*}, we perform *\next@*, so that `*\A@:*' has now been 
*\let* equal to the active~*:*\,.

So, we can
produce
 control sequences that have the value of each active punctuation symbol
that may occur in a file,
assuming that *\APdef* has always been used in *french.tex*.


Now consider the original \amstex\ definition
**
\def\tdots@{\unskip
 \def\next@{$\m@th\mathinner{\ldotp\ldotp\ldotp}\,
"2
  \ifx\next,\,$\else\ifx\next.\,$\else
"2
  \ifx\next;\,$\else
"2
  \ifx\next:\,$\else
"2
  \ifx\next?\,$\else
"2
  \ifx\next!\,$\else
  $ \fi\fi\fi\fi\fi\fi}%
 \ \futurelet\next\next@}
**

We want to supplement this with *\ifx\next* tests that check whether
*\next* is an active punctuation symbol, in case *\tdots@* gets used in a
file where that is the case. 
We can do this with tests like
**
\expandafter\ifx\csname A@\string;\endcsname\next
**
 For greater
flexibility, when we encounter an active punctuation symbol
we will not necessarily insert the extra *\,* that the non-active symbol gets;
we will instead insert *\fextra@*, which by default is 
\C**
\let\fextra@=\,
**
(but which *french.tex* can redefine, if desired).

The original definition of *\tdots@* is deleted from *amstexl.tex*, and
a new definition is given in *lamstex.tex*:
\C**
\def\tdots@{\unskip
 \def\next@{$\m@th\mathinner{\ldotp\ldotp\ldotp}\,
  \ifx\next,\,$\else\ifx\next.\,$\else
"2
  \ifx\next;\,$\else
  "9\expandafter\ifx\csname A@\string;\endcsname\next"9
   "9\fextra@$\else"9
"2
  \ifx\next:\,$\else
  "9\expandafter\ifx\csname A@\string:\endcsname\next"9
   "9\fextra@$\else"9
"2
  \ifx\next?\,$\else
  "9\expandafter\ifx\csname A@\string?\endcsname\next"9
   "9\fextra@$\else"9
"2
  \ifx\next!\,$\else
  "9\expandafter\ifx\csname A@\string!\endcsname\next"9
   "9\fextra@$\else"9
  $ \fi\fi\fi\fi\fi\fi"9\fi\fi\fi\fi"9}%
 \ \futurelet\next\next@}
**

Similarly, the definition of *\extrap@* 
is deleted from *amstexl.tex*, and
in *lamstex.tex* we add
\C**
\def\extrap@#1{%
 \ifx\next,\def\next@{#1\,}\else
"2
 \ifx\next;\def\next@{#1\,}\else
 "9\expandafter\ifx\csname A@\string;\endcsname\next"9
  "9\def\next@{#1\fextra@}\else"9
"2
 \ifx\next.\def\next@{#1\,}\else\extra@
 \ifextra@\def\next@{#1\,}\else
 \let\next@"9="9#1\fi\fi\fi\fi"9\fi"9\next@}
**
The boxed *=* sign in this code
 is another case (compare page~\ref{NEEDEQ}) where
the  *=*~ sign  cannot be omitted, though now the reason
is different: we might have *#1* being an *=* sign!
There are similar required *=*'s in
 the (original) definitions
of
 *\boldsymbol@*, *\boldkeydots@*, and *\boldsymboldots@*, and
in the new definition of *\boldkey*, to follow. These *=* signs
and the one in the definition of *\ismember@* are the only ones that
actually occur after a *\let* in *lamstex.tex*.

Similarly, the definitions of *\dotsc* and *\keybin@* are deleted from
\linebreak
*amstexl.tex*, and in *lamstex.tex* we add
\C**
\def\dotsc{\def\next@{\ifx\next;\plainldots@\,\else
 "9\expandafter\ifx\csname A@\string;\endcsname\next"9
  "9\plainldots@\fextra@\else"9
  \ifx\next.\plainldots@\,\else\extra@\plainldots@
  \ifextra@\,\fi\fi\fi"9\fi"9}%
 \futurelet\next\next@}
"slip
\def\keybin@{\keybin@true  
 \ifx\next+\else\ifx\next=\else\ifx\next<\else
 \ifx\next>\else\ifx\next-\else\ifx\next"1\else
 \ifx\next:\else
 "9\expandafter\ifx\csname A@\string;\endcsname\next\else"9
 \keybin@false\fi\fi\fi\fi\fi\fi\fi"9\fi"9}
**

The definition of *\boldkey#1* is also deleted from
*amstexl.tex*.\pagelabel{NEWBK}  
In this
case, where we have a control sequence with an argument, rather than one
that has picked up the next token with a *\futurelet\next*, 
and where our tests are of the form
**
\ifx#1!
**
we have to start with
**
\let\next=#1
**
so that we can then use things like 
**
\expandafter\ifx\csname A@\string!\endcsname\next
**
to check for an active~*!*.
The new code is:
\C**
\def\boldkey#1{\ifcat\noexpand#1A%  
  \ifcmmibloaded@{\fam\cmmibfam#1}\else
   \Err@{First bold symbol font not loaded}\fi
"2
 \else
 \let\next"9="9#1%  
"2
 \ifx#1!\mathchar""5\bffam@21 \else
 "9\expandafter\ifx\csname A@\string!\endcsname\next"9
  "9\mathchar""5\bffam@21 \else"9
"2
 \ifx#1(\mathchar""4\bffam@28 \else
"2
 \ifx#1)\mathchar""5\bffam@29 \else
"2
 \ifx#1+\mathchar""2\bffam@2B \else
"2
 \ifx#1:\mathchar""3\bffam@3A \else
 "9\expandafter\ifx\csname A@\string:\endcsname\next"9
  "9\mathchar""3\bffam@3A \else"9 
"2
 \ifx#1;\mathchar""6\bffam@3B \else
 "9\expandafter\ifx\csname A@\string;\endcsname\next"9
  "9\mathchar""6\bffam@3B \else"9
"2
 \ifx#1=\mathchar""3\bffam@3D \else
"2
 \ifx#1?\mathchar""5\bffam@3F \else
 "9\expandafter\ifx\csname A@\string?\endcsname\next"9
  "9\mathchar""5\bffam@3F \else"9
"2
 \ifx#1[\mathchar""4\bffam@5B \else
"2
 \ifx#1]\mathchar""5\bffam@5D \else
"2
 \ifx#1,\mathchari@63B \else
"2
 \ifx#1-\mathcharii@200 \else
"2
 \ifx#1.\mathchari@03A \else
"2
 \ifx#1/\mathchari@03D \else
"2
 \ifx#1<\mathchari@33C \else
"2
 \ifx#1>\mathchari@33E \else
"2
 \ifx#1"1\mathcharii@203 \else
"2
 \ifx#1|\mathcharii@06A \else
"2
 \ifx#10\bold0\else\ifx#11\bold1\else\ifx#12\bold2\else
"2
 \ifx#13\bold3\else\ifx#14\bold4\else\ifx#15\bold5\else
"2
 \ifx#16\bold6\else\ifx#17\bold7\else\ifx#18\bold8\else
"2
 \ifx#19\bold9\else
  \Err@{\noexpand\boldkey can't be used with #1}%
 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi"9\fi\fi\fi\fi"9}
**



\chapter Numbering styles\endchapter

 Next we define the standard \lamstex\ numbering
styles: *\arabic*, *\alph*, *\Alph*,
*\roman*,  *\Roman*, and *\fnsymbol*.  

These numbering styles are meant to be 
applied to a {\it number}, not to a counter (in the \lamstex\ macros they
are
usually  applied to
*\number*\<counter\> for some \<counter\>).
*\arabic* is consequently quite trivial:
\C**
\def\arabic#1{#1}
**

The definition of *\alph#1* uses the fact that the 
lower-case letters a--z have positions
*97*--*122*
 (if some one were to design a perverse font for which this wasn't
true, then *\alph* would have to be defined differently).

*\alph* begins by setting the scratch counter 
*\count@* to the value of *#1*:
**
\def\alph#1{\count@=#1\relax
**
We always add the *\relax* as a precaution in such situations,
 even if it may not be strictly
necessary ({\it The \tex book}, page~208, recommends a space, but *\relax*
seems best, to avoid any anomalous situations where an unwanted space might
somehow intrude itself into the token stream).


Then we add *96* to the value of *\count@* and we print the character
\linebreak
*\char\count@*,
but we give an error
message if this would give us a character past *122* (this could easily
happen if some one caused the counter to be augmented more than 25~times):
\C**
\def\alph#1{\count@=#1\relax\advance\count@ by 96 
 \ifnum\count@>122 \Err@{\noexpand\alph invalid for 
  numbers > 26}\else\char\count@\fi}
**
(See section~\Sref{SACN} for the use of *\noexpand\alph* rather than
*\string\alph*.)



We don't bother giving an error message if *\count@* ends up having a value
less than *97*, 
since  reasonable
macros will normally start the counter for a particular
construction at *1*. (So there is the possibility that some one will
perversely *\Reset* some construction to *0*, say, and then have
*\alph* produce a left quotation mark *`*! If this really seems
bothersome,
another check can easily be added to the code.)

The definition 
\C**
\def\Alph#1{\count@=#1\relax\advance\count@ by 64 
  \ifnum\count@>90 \Err@{\noexpand\Alph invalid for 
  numbers > 26}\else\char\count@\fi}
**
is exactly analogous, using the fact that the letters A--Z should have the
positions *65*--*90*.

For *\roman* we just have to
\C**
\def\roman#1{\romannumeral#1\relax}
**
since \tex\ provides the *\romannumeral* primitive. (The *\relax* is
essential here; otherwise something like
*\roman{10}3* would be expanded into
*\romannumeral103*,
giving the  result `ciii'.)

But *\Roman* is more complicated,
\C**
\def\Roman#1{\uppercase\expandafter{\romannumeral#1}}
**
Here the *\expandafter* causes expansion after the left brace *{*. 
Without the *\expandafter*, something like *\Roman3* would become
**
\uppercase{\romannumeral3}
**
which is just 
*\romannumeral3*,
and thus  `iii'.  With the
 *\expandafter*, we get
\setbox0\hbox{\<expansion of {\tt\bs romannumeral3}\>}
**
\uppercase{"box0}
**
i.e., 
*\uppercase{iii}*,
or `III'.

Note that we don't need to add *\relax* after  the *#1* in 
his definition,
because *\romannumeral#1* is expanded within the
*\uppercase{...}*.

Finally, we have
the *\fnsymbol* numbering style. As the code below shows,
 *\fnsymbol#1* successively sets
\Reset\tag1
$$\align\hbox{\tt\bs count\@\@}&=\hbox{\tt\#1}\tag\\
\hbox{\tt\bs count\@}&=\left[\frac{\hbox{\tt\#1}-\hbox{1}}{\hbox{7}}
 \right]\tag\\
\hbox{\tt\bs count\@\@\@}&=\left[\frac{\hbox{\tt\#1}-\hbox{1}}{\hbox{7}}
\right]+\hbox{1}\tag\\
\hbox{\tt\bs count\@\@}&=\hbox{\tt\#1}-\hbox{7}
 \cdot\left[\frac{\hbox{\tt\#1}-\hbox{1}}{\hbox{7}}
   \right].\tag\endalign$$

Hence 
$$
\hbox{\tt\bs count\@\@}=\cases
 \hbox{1}&\hbox{for \tt\#1}=\hbox{1}, \hbox{8}, \hbox{15},\dotsc{}\\
 \hbox{2}&\hbox{for \tt\#1}=\hbox{2}, \hbox{9}, \hbox{16}, \dotsc{}\\
 \hdots\\
 \hbox{7}&\hbox{for \tt\#1}=\hbox{7}, \hbox{14}, \hbox{21}, \dotsc{}\\
\endcases$$
so *\count@@* tells which of the symbols
\ast, \dag,  \ddag, \P,
\S, $\|$, \# should be printed, namely,
\ast~ for $\hbox{\tt\bs count\@\@}=
\hbox{1}$,
\dag~ for $\hbox{\tt\bs count\@\@}=\hbox{2}$, etc.

On the other hand,
$$
\hbox{\tt\bs count\@\@\@}=\cases
 \hbox{1}&\hbox{for \tt\#1}=\hbox{1},\dots,\hbox{7}\\
 \hbox{2}&\hbox{for \tt\#1}=\hbox{8},\dots,\hbox{14}\\
 \hdots\endcases$$
so *\count@@@* is the number 
 of times that this  symbol  has to be printed.
To print the symbol this many times,
 we use a loop, initially setting the counter *\count@* to
*\count@@@*:
\C**
\def\fnsymbol#1{\count@=#1\relax
 \count@@=\count@ 
"2
 \advance\count@ by -1  \divide\count@ by 7 
"2
 \count@@@=\count@ \advance\count@@@ by 1
"2
 \multiply\count@ by 7 \advance\count@@ by -\count@ 
"2
 \count@=\count@@@
 {\loop
  \ifcase\count@@\or"1\or\dag\or\ddag\or\P\or\S\or
   \text{$\|$}\or\#\fi
  \advance\count@ by -1 \ifnum\count@>0 \repeat}}
**

\amstex\ has already defined *\dag*, *\ddag*, *\P*, and *\S*, so 
that they can be used either in text or in math mode, where they will
change size properly; *\text{$\|$}* simply does the same for the
$\|$ symbol (*\#* needs no special treatment).
Modifications of *\dag*, \dots\ may be necessary for fonts with different
layouts. 


 In the above definition we
 put the *\loop* inside a group just in case *\fnsymbol*
happens to be used inside some *\loop* itself,   a somewhat
finicky precaution, since
a nested *\loop* involving
*\fnsymbol* will 
never be produced by any \lamstex\ construction. The same
precaution will be used
for any \lamstex\ *\loop* that might conceivably occur within
another *\loop*.\pagelabel{POSSLOOP}




\chapter Printing cardinal and ordinal numbers\endchapter

This chapter is in some sense a companion to the previous one.


First we define *\cardnine@#1*
for printing the final part of the name of a cardinal number; it will be
applied to a counter with a value from *1*, \dots, *9*:
\C**
\def\cardnine@#1{\ifcase#1\or one\or two\or 
 three\or four\or five\or six\or seven\or eight\or nine\fi}
**

The number *10* will be used so often in the macros of this chapter
 that
we want to use *\newcount* to
introduce a counter having that value.

As we mentioned in section~\Sref{NEWNEW},
*amstex.tex* (and *amstexl.tex*) redefine
 *\alloc@*  so that it doesn't write anything to the *.log* 
file; and
**
\let\alloc@@=\alloc@
**
is used 
so that *\alloc@@* is {\it that\/} version of *\alloc@*, even if called
after *\alloc@* has been restored to the old definition from *plain*
\tex\ at the end.\pagelabel{NEWALLOC2}
We now want to reinstate the new definition until
the end of *lamstex.tex*. Instead of redefining it directly, we just have
to 
\C**
\let\alloc@=\alloc@@    "8NEWALLOC"8
**
since *\alloc@@* was permanently given the new definition.

Since *\newcount* is defined in terms of *\alloc@*, which we have just made
equivalent to *\alloc@@*, the next code
\C**
\newcount\ten@
\ten@=10
**
does not produce anything in the *.log* file of a file that has *\input
lamstex* (nor will any of the other *\new...* constructions to follow).

Although *\cardinal{...}* will normally be applied when *...* is
a number, to be on the safe side, we first safely store the value in
a counter,
**
\def\cardinal#1{\count@=#1\relax
**
and then proceed by cases. 
\C**
\def\cardinal#1{\count@=#1\relax
 \ifnum\count@>99 \number\count@
 \else
  \ifnum\count@=0 zero%
  \else
   \ifnum\count@<\ten@ \cardnine@\count@
   \else
    \ifnum\count@<20
     \advance\count@ by -\ten@
     \ifcase\count@ ten\or eleven\or twelve\or
      thirteen\or fourteen\or fifteen\or sixteen\or
      seventeen\or eighteen\or nineteen\fi
"2
    \else
     \count@@=\count@ \count@@@=\count@@
"2
     \divide\count@ by \ten@ \multiply\count@ by \ten@
     \advance\count@@@ by -\count@ 
     \divide\count@ by \ten@
"2
     \ifcase\count@\or\or twenty\or thirty\or forty
      \or fifty\or sixty\or seventy\or eighty\or ninety\fi
"2
     \ifnum\count@@@=0 \else-\cardnine@\count@@@\fi
    \fi
   \fi
  \fi
 \fi}
**

Thus, 
if $\hbox{*#1*}>\hbox{99}$, we simply typeset this number. 
If  $\hbox{*#1*}=\hbox{0}$,
we simply typeset `zero'. If $\hbox{0}<\hbox{*#1*}<\hbox{10}$, we just use
*\cardnine@* to print the number. For $\hbox{10}<\hbox{*#1*}<\hbox{20}$,
 we
must explicitly specify `ten', \dots, `nineteen'.

\Reset\tag1
Finally, for $\hbox{20}<\hbox{*#1*}<\hbox{99}$,
 we have to do a little calculation.
The next code successively  sets
$$\spreadlines\jot\align
\hbox{\tt\bs count\@\@\@}=\hbox{\tt\bs count\@\@}&=\hbox{\tt\#1}\tag\\
\allowdisplaybreak
\hbox{\tt\bs count\@}&=\hbox{10}\cdot\left[\frac{\hbox{\tt\#1}}{\hbox{10}}
 \right]\tag\\
\allowdisplaybreak
\split\hbox{\tt\bs count\@\@\@}&=\hbox{\tt\#1}-\hbox{10}\cdot
 \left[\frac{\hbox{\tt\#1}}{\hbox{10}}\right]\\
 &=\hbox{\tt\#1}\pmod{\hbox{10}}\endsplit\tag\\
\allowdisplaybreak
\hbox{\tt\bs count\@}&=\left[\frac{\hbox{\tt\#1}}{\hbox{10}}
 \right]\tag\endalign$$
The first part of the word for *#1* is `twenty' if $\hbox{\tt\#1}=
\hbox{20},\dots,\hbox{29}$, and hence *\count@=2*; it is `thirty' if
$\hbox{\tt\#1}=\hbox{30},\dots,\hbox{39}$, and hence *\count@=3*; etc.
  If $\hbox{*\count@@@*}=0$ the name is
complete; otherwise we must add `-one', `-two', \dots, depending on the
value of *\count@@@*.

\medskip

*\ordnine@*, for ordinal numbers, is
exactly analogous to *\cardnine@*:
\C**
\def\ordnine@#1{\ifcase#1\or first\or second\or
 third\or fourth\or fifth\or sixth\or seventh\or
 eighth\or ninth\fi}
**

The ordinal numbers $<\hbox{100}$  can be treated in a manner exactly like
the cardinal numbers.  But a problem arises for ordinal numbers like
`100th', `101st', `102nd', `103rd', \dots, `109th', `110th', `111th', 
`112th', \dots---now
the proper suffix depends not only on the last digit of the number, but
also  on whether the next-to-last digit is a~*1*. 


The routine *\ordsuffix@* selects the right suffix in these cases,
assuming that the number in question has been stored in *\count@*.
The first part of the routine below divides *\count@* by~10, and then
calculates *\count@@@* to be $\hbox{*\count@*}\pmod{\hbox{10}}$ 
[compare the
previous calculations for *\cardinal*].
If this is~1, so that
the next-to-last digit of the number in *\count@* was~1,
 `th' is selected. 
Because the original value of *\count@* is needed for the second part of the
routine, we need to store it in yet another counter, *\count@@@@*,
which we have to
declare.

This second part simply computes
*\count@@@* as $\hbox{*\count@*}\pmod{\hbox{10}}$
 [for the original value of
*\count@*]; if this second part of the routine ends up being invoked,
the correct choice of the suffix depends only on this value of *\count@@@*:
\C**
\newcount\count@@@@
"slip
\def\ordsuffix@{\count@@@@=\count@
 \divide\count@ by \ten@
 \count@@@=\count@ \count@@=\count@
"2
 \divide\count@@ by \ten@ \multiply\count@@ by \ten@ 
 \advance\count@@@ by -\count@@
"2
 \ifnum\count@@@=1 th%
"2
 \else
  \count@@@=\count@@@@
  \count@@=\count@@@@ 
  \divide\count@@ by \ten@ \multiply\count@@ by \ten@
  \advance\count@@@ by -\count@@
  \ifcase\count@@@ th\or st\or nd\or rd\else th\fi
 \fi}
**

*\nordinal* and *\spordinal*  are easy, since they are
 simply a number followed by
the proper suffix, or the suffix superscripted:
\C**
\def\nordinal#1{\count@=#1\relax\number\count@\ordsuffix@}
\def\spordinal#1{\count@=#1\relax\number\count@
  $^{\text{\ordsuffix@}$}
**

And *\ordinal* itself simply mimics *\cardinal*, using
*\ordsuffix@* for numbers $\ge\hbox{100}$:
\C**
\def\ordinal#1{\count@=#1\relax
 \ifnum\count@>99 \number\count@\ordsuffix@
 \else
"2
  \ifnum\count@=0 zeroth%
  \else
"2
    \ifnum\count@<\ten@ \ordnine@\count@
    \else
"2
     \ifnum\count@<20 \advance\count@ by -\ten@
      \ifcase\count@ tenth\or eleventh\or twelfth\or 
       thirteenth\or fourteenth\or fifteenth\or sixteenth\or
       seventeenth\or eighteenth\or nineteenth\fi
     \else
"2
      \count@@=\count@ 
      \divide\count@ by \ten@ \multiply\count@ by \ten@
      \count@@@=\count@@ \advance\count@@@ by -\count@ 
      \divide\count@ by \ten@
      \ifcase\count@\or\or twent\or thirt\or fort\or fift\or 
       sixt\or sevent\or eight\or ninet\fi
      \ifnum\count@@@=0 ieth\else y-\ordnine@\count@@@\fi
     \fi
    \fi
  \fi
 \fi}
**


\chapter Inhibiting expansion\label{noexpands}\endchapter

There are numerous situations where we want to suppress expansion, during
both *\write*'s and *\edef*'s or *\xdef*'s,
 of the
numbering control sequences *\arabic*, *\alph*, \dots\ as well as the
font change control sequences *\rm*, *\it*, *\bf*, 
\dots. The latter includes
*\smc*, which may not have been defined yet, so we take care of that
first:
\C**
\font@\tensmc=cmcsc10
\textonlyfont@\smc\tensmc
**
[For the details of *\font@* and *\textonlyfont@* see *amstex.doc*
(and also page~\ref{FL});
basically, this is like saying *\font\tensmc=cmcsc10* and
*\def\smc{\tensmc}*.]



We introduce a new token list
\C**
\newtoks\noexpandtoks@
**
which will be a  list of commands, and
then
*\noexpands@* will issue these commands by inserting this token list:
\C**
\noexpandtoks@={\let\arabic=\relax\let\alph=\relax
 \let\Alph=\relax\let\roman=\relax\let\Roman=\relax
 \let\fnsymbol=\relax\let\rm=\relax\let\it=\relax
 \let\bf=\relax\let\sl=\relax\let\smc=\relax
 \let\/=\relax\let\null=\relax}
"slip
\def\noexpands@{\the\noexpandtoks@}
**

It is easy to define the
construction *\Nonexpanding#1*, which is supposed to make
*\let#1=\relax* also be executed:
\footnote{In  version~*1* of \lamstex@, this was called *\Noexpand*,
but that seems too close to  *\noexpand* for comfort.}
\C**
\def\Nonexpanding#1{\global\noexpandtoks@
 =\expandafter{\the\noexpandtoks@\let#1=\relax}}
**

*\let\/=\relax* was added to *\noexpandtoks@*
 because *\/* will often occur in ``style''
commands (pages~\ref{ic1}, \ref{ic2}, \ref{tagit}, et al\.) that appear in
*\edef*'s or
*\xdef*'s and *\write*'s\pagelabel{IC} (pages~\ref{necc},
 \ref{GGGG},
 et al\.) and *\/* is
no longer a primitive in \amstex\ or \lamstex\ (page~\ref{itcorr}).
Similarly *\let\null=\relax* was added because *\null* sometimes occurs in
``style'' commands (see page~\ref{NULLSTYLE}, for example).


\chapter Invisibility\label{invis}\endchapter

\section{Invisible constructions}
All constructions that are supposed to be ``invisible'' (the most important
examples being
 *\label* and
*\pagelabel*)
 begin with
*\prevanish@*. If we are in horizontal mode, this
 sets *\saveskip@* (a glue register declared in \amstex)\ to
be the previous glue, and then removes that glue.
Otherwise, it simply sets *\saveskip@* to *0pt*.
\C**
\def\prevanish@{\saveskip@=0pt
 \ifhmode\saveskip@=\lastskip\unskip\fi}
**

``Invisible'' constructions end with *\postvanish@*, which puts back
the *\saveskip@* glue, if greater than zero;
\footnote{We don't want to add *\hskip\saveskip@* when *\savekskip@*
is zero, because that case can occur when there is {\it no\/} previous glue: 
adding *\hskip\saveskip@* might then allow a break where none was 
allowed before.}
 it must also look ahead to see if the
next token is a space, and swallow up that space if  the *\saveskip@* glue
was greater than zero:
\C**
\def\postvanish@{\ifdim\saveskip@>0pt\hskip\saveskip@\fi
 \futurelet\next\postvanish@@}
\def\postvanish@@{\def\next@.{}%
 \ifx\next\space@\ifdim\saveskip@>0pt\def\next@. {}\fi\fi 
  \next@.}
**
Here we use the method of page~\ref{swallow}.
Note that we {\it don't\/} want to use *\FNSS@* (section~\Sref{FIX})
in this special situation, since we want to eliminate the space only when
*\saveskip@* is greater than zero.

[It is important to note that *\saveskip@* appears only in these
definitions, except for certain \amstex\ constructions that
will not ever appear within an ``invisible'' construction. So we don't
 have to worry about the value of *\saveskip@* being clobbered before
*\postvanish@* is applied.]


These constructions allow us to define the general construction to make
anything ``invisible'':
\C**
\def\invisible#1{\prevanish@\ignorespaces#1\unskip
 \postvanish@}
**
(Notice that, because of the *\ignorespaces* and *\unskip*,
the remark in the \lamstex~Manual on page~32, lines~6--8, is incorrect.)


We will need a list, *\vanishlist@*, of all invisible constructions; this
will be a list of the sort discussed in section~\Sref{LISTS}.  We initialize
it as: 
\C**
\def\vanishlist@{\\\invisible}
**

\section{Special considerations for invisible constructions\label{ZZZ}}
 If we have a
construction like
**
\par
\invisible{...}" Some text
**
then the *\prevanish@* in *\invisible* sets *\saveskip@* to *0pt*.
Consequently, the *\postvanish@* will {\it not\/} delete the following
space token that precedes `*Some text*'. But this space token is ignored
in vertical mode ({\it The \tex book}, page~282), so we don't get an extra
space before ``Some text''.  

The situation is quite different, however, if we have
**
\par
\noindent \invisible{...}" Some text
**   
because now the space token is not ignored, since it is 
encountered in horizontal mode; consequently, we will get an extra space
before ``Some text''.

In \amstex\ and \lamstex@, the combination *\par\noindent* has the special
abbreviation *\flushpar*.  We can avoid this difficulty with invisible
constructions by redefining *\flushpar* as
**
\def\flushpar{\par\noindent\futurelet\next\pretendspace@}
**
where *\pretendspace@* simply inserts *\hskip-1pt\hskip1pt* (preceded by
*\nobreak* just as a precaution) when *\next* is something in
*\vanishlist@*: 
**
\def\pretendspace@{\ismember@\vanishlist@\next
 \iftest@\nobreak\hskip-1pt\hskip1pt\fi}
**
[A precautionary *\relax* after the *\hskip1pt* is not needed here---the
*\fi* will stop the scanning of *\hskip*.]

As a result of this definition, 
**
\flushpar\invisible{...}" "0
**
becomes
**
\par\noindent\nobreak\hskip-1pt\hskip1pt\invisible{...}" "0
**
(and similarly for *\flushpar\label{...}*, and any other ``invisible''
constructions
that we will eventually define, and add to *\vanishlist@*).

Consequently,
 the *\prevanish@* removes the *\hskip1pt* and then sets\linebreak
 *\saveskip@* to
*1pt*. Then the *\postvanish@* adds back the *\hskip1pt* once again,
canceling out the *\hskip-1pt*.  Moreover, since *\saveskip@* is now
positive, the space token after the *\invisible* will be thrown away, so
that *\invisible{...}* will really be invisible.
\footnote{If some one has typed *\define\foo{\invisible{...}}* and then
used *\flushpar\foo*, this presents no problem, since in this case no space
after *\foo* will appear. (But, of course, *\define\foo/{\invisible{...}}*
would make `*\flushpar\foo/" *' behave incorrectly; this didn't seem worth
worrying about!)}

Note, by the way, that *\ismember@* was defined in such a way that
 the test *\ismember@\vanishlist@\next* sets *\iftest@* to be true when
*\next* has been *\let* equal to a
 control sequence in *\vanishlist@*
(page~\ref{ISFL}).




[In the above definitions, 
it might seem that we could simply add the\linebreak
 *\hskip-1pt\hskip1pt* in all cases.
But that wouldn't quite work, because the next construction might begin with
an *\unskip* (e.g., *\linebreak* or *\dots*). Aside from such a case, however,
the *\hskip-1pt\hskip1pt* doesn't do any harm.\pagelabel{NOHARM}]

Since some users might type *\noindent* instead of *\flushpar*, we might
as well add the *\futurelet\next\pretendspace@* to *\noindent* also.
\C**
\let\noindent@=\noindent   "8NOIN"8
\def\noindent{\par\noindent@\futurelet\next\pretendspace@}
"slip
\def\pretendspace@{\ismember@\vanishlist@\next
 \iftest@\nobreak\hskip-1pt\hskip1pt\fi}
"slip
\let\flushpar=\noindent
**




\smallskip
*\pretendspace@* will be needed at several other points in \lamstex\ 
(sections~\Sref{pretend1}, \Sref{item}, et~ al.).
\medskip

In *amstexl.tex* we delete the definition of *\flushpar*, since
it will be replaced with this new definition. 

\chapter Special considerations for \CS{everypar}\label{EVPAR}\endchapter
Numerous \lamstex\ constructions use *\noindent@* to start an unindented
paragraph. If some
**
\everypar={...}
**
has been specified in the document, these unindented paragraphs would also
start with the *\everypar* tokens, which is normally not desired.

Although this might be regarded as a
 rather paranoid concern, since *\everypar*'s should
presumably be used only within some region of the document that contains only
text, \lamstex\ contains a special construction to deal with this problem.

First we introduce a new token list
\C**
\newtoks\everypartoks@
**
and then we define
\C**
\def\noindent@@{\par
 \everypartoks@=\expandafter{\the\everypar}\everypar={}%
 \noindent@\everypar=\expandafter{\the\everypartoks@}}
**
Thus, *\noindent@@* 
\list
\item ends the previous paragraph,
\item stores the current value of *\everypar* in *\everypartoks@*,
\item sets *\everypar* to be empty, and
\item starts an unindented paragraph, which
\item resets *\everypar* to its original value for the {\it next\/}
paragraph.
\endlist
Note that the original value of *\everypar* will {\it not\/} be inserted
before the *\noindent@*'ed paragraph, because it gets the value *{}*
that was current when the *\noindent@* was encountered.

In \lamstex@, *\noindent@@* will usually be used instead of *\noindent*, 
with a 
*\futurelet\next\pretendspace@*  added when an invisible construction might
follow. 



\chapter \CS{page}\label{PG}\endchapter

In \lamstex\ the control sequence *\page* can be manipulated like *\tag*,
*\claim*, etc. Thus, we can use *\Reset\page*, *\newpre\page*, \dots .
But we want *\page* by itself to give an error message:
\C**
\def\page{\Err@{\noexpand\page has no meaning by itself}}
**
(Again, see section~\Sref{SACN} for the use of *\noexpand*.)

As we will see in Chapter~\ref{LBL1}, associated with the \lamstex\
construction *\tag* we have
\setbox0\hbox{the counter associated with *\tag*}%
\setbox1\hbox{the ``pre'' material for *\tag*}%
\setbox2\hbox{the ``post'' material for *\tag*}%
\setbox3\hbox{the style for *\tag*}%
\setbox4\hbox{the numbering style for *\tag*}%
\setbox5\hbox{the font for *\tag*}%
**
\tag@C  "box0 
\tag@P  "box1
\tag@Q  "box2
\tag@S  "box3
\tag@N  "box4
\tag@F  "box5
**
Likewise, *\claim* and all other \lamstex\ constructions that can be given
a \<label\> have similar counters and control sequences associated with them.

At present, we simply want to consider the counter and control sequences
associated to *\page*.  For *\page@C* we just use *plain* \tex's 
*\pageno*
\C**
\let\page@C=\pageno
**
and then we introduce default values (*\empty* is defined in *plain.tex*
by *\def\empty{}*, so *\let\page@P=\empty* is just a briefer way of 
saying *\def\page@P{}*):
\C**
\let\page@P=\empty
\let\page@Q=\empty
"2
\def\page@S#1{#1\/} "8ic1"8
\def\page@F{\rm}
\def\page@N{\arabic}  % cannot be \let
**


The *\/* in *\page@S* might be useful if *\page@F* is ever chosen to be
a slanted font.

We want to have
*\def\page@F{\rm}* rather than *\let\page@F=\rm*, because *\rm* may
actually change definitions.\pagelabel{pagef}
  For example, 
**
\fontstyle\page{...}
**
 expands
out (page~\ref{FS}) to
**
{\page@F...}
**
and if we are in 9-point type at the time, we would expect to get 9-point
roman type, not the 10-point roman type that is in effect at the time that
*\page@F* is specified.

And, as we will see later (page~\ref{SUB}), it is even more critical
that we have *\def\page@N{\arabic}* rather than
*\let\page@N=\arabic*. 


\chapter Indexing\label{INDX}\endchapter

The indexing macros were placed next, because they use the
fact that *""* is active in \lamstex@, and we would like to get this
declared soon, so that any *""* appearing in other macros will refer to
this active *""*. Some of the methods used here will also be crucial in
Chapters~\ref{HLS} and ~\ref{PI}.

It should be noted that in version~*1* of \lamstex@, the index entries were
written to one file, with the extension~ *.ndx*, while the corresponding page
numbers were written to another file, with the
extension~*.npg*.\pagelabel{OLDV}  That has all
changed, however, and now the entry and the page number are written together 
to the *.ndx* file.  Similarly,
as we will see in Chapter~\ref{HLS}, heading levels will be written
together with their page
numbers in the *.toc* file, and as we'll see in Chapter~\ref{PI}, Figures,
Tables, etc., will be written together with their page numbers in one file.


\section{The {\tt.ndx} file}
We will need a flag,
\C**
\newif\ifindexing@
**
to tell whether an index file is being made.

*\indexfile* will (globally) set the flag *\ifindexing@* to be true
the first time it is used; it will also test this flag when called, so
that if it is called twice it will do nothing at all the second time.
The first time *\indexfile* is called, it should create a new
 output stream,
**
\newwrite\ndx@
**
associated with the file *\jobname.ndx* (where
*\jobname* will be `*foo*' when \tex\ is processing *foo.tex*).

Instead of using *\newwrite*,
we will just write the code for it instead, substituting *\alloc@@*
(page~\ref{NEWALLOC}) 
for
*\alloc@*:
\C**
\def\indexfile{\ifindexing@\else      "8INDEXFILE"8
 \alloc@@7\write\chardef\sixt@@n\ndx@  
 \immediate\openout\ndx@=\jobname.ndx
 \global\indexing@true\fi}
**
Then (compare section~\Sref{NEWNEW}),
since we used *\alloc@@* rather then *\alloc@*,
nothing will be written to the *.log* file,  even though
*\indexfile* is used after *\alloc@* itself has been redefined at the end
of *lamstex.tex*.

\section{\CS{indexproofing}}
We will need  an insertion class,  called *\margin@*,
for index entries that are to
appear in the margin if *\indexproofing* has been specified. So we would
like to say `*\newinsert\margin@*'.  But *\newinsert* is defined
differently than all other *\new...* constructions in 
*plain*, and it will
write something to the *.log* file, despite our redefinition of *\alloc@*.
So we instead simply restate everything from *plain*
in the definition of *\newinsert*
except for the
*\wlog* part:
\C**
\global\advance\insc@unt\m@ne
\ch@ck0\insc@unt\count
\ch@ck1\insc@unt\dimen
\ch@ck2\insc@unt\skip
\ch@ck4\insc@unt\box
\allocationnumber\insc@unt
\global\chardef\margin@\allocationnumber
**
Notice that although this takes up a lot of space in the file, it 
takes up hardly any space within \tex\ itself, just like
*\newinsert\margin@*.


We put no limit on the number of marginal notes on a page, and
they take up no space (compare {\it The \tex book}, page~415):
\C**
\dimen\margin@=\maxdimen
\count\margin@=0
\skip\margin@=0pt
**

The flag *\ifindexproofing@* will tell us whether *\indexproofing*
(and\slash or *\noindexproofing*) appears:
\C**
\newif\ifindexproofing@
\def\indexproofing{\indexproofing@true}
\def\noindexproofing{\indexproofing@false}
**


\section{Converting tokens to type {\tt 12}\label{UNMACRO}}
If a control sequence *\controlseq* has been defined by
\setbox0\hbox{\<parameter text\>}
\setbox1\hbox{\<replacement text\>}
**
\def\controlseq"box0{"box1}
**
(see {\it The \tex book}, page 203, for terminology), then the \tex\
primitive 
**
\meaning\controlseq
**
expands to
\setbox0\hbox{\<parameter text\>}
\setbox1\hbox{\<replacement text\>}
**
macro:"box0->"box1
**
where all non-space tokens are of type~*12*.  

The construction *\unmacro@* is used to store the \<parameter text\>
in *\macpar@* and the \<replacement text\> in *\macdef@*:
\C**
\def\unmacro@#1:#2->#3\unmacro@{\def\macpar@{#2}% 
 \def\macdef@{#3}}
**
In particular, if we 
**
\def\foo{#1}
**
where *#1* is  any text with balanced braces, and we do
**
\expandafter\unmacro@\meaning\foo\unmacro@
**
then
\footnote{There is no problem with *:* being part of the syntax of
*\unmacro@* even in a file where *:* has been made active (compare
section~\Sref{ALF}), because
 *\unmacro@* will always be used like this, to work on
some value of
*\meaning*.}
*\macdef@* will consist of *#1* {\it with all non-space
tokens converted to type~*12*}.

Some information is lost in the process: multiple spaces in *#1* coalesce to
single spaces in *\macdef@*,  control words in *#1* are followed by spaces
in *\macdef@* even if no spaces appear after them 
in *#1*, and line breaks in *#1*
 simply become spaces in *\macdef@*.
  So this method is not particularly useful for
literal mode, especially since it cannot be applied at all unless *#1* has
balanced braces.  Nevertheless, it alleviates considerably the problems
that arise when we want to *\write* the string *#1* to a file without having
control sequences expanded.  We simply have to write *\macdef@* instead!

More precisely, for some output stream, like *\ndx@*, instead of
using an\linebreak *\immediate\write* like
**
\immediate\write\ndx@{#1}
**
we can
**
\def\next@{#1}
\expandafter\unmacro@\meaning\next@\unmacro@
\immediate\write\ndx@{\macdef@}
**
For delayed *\write*'s we have to be more careful, since *\macdef@* may have
been redefined by the time the *\write* occurs.  Instead 
of
**
\write\ndx@{\macdef@}
**
we must use
**
\edef\next@{\write\ndx@{\macdef@}} "8WRITENDX"8
\next@
**
The *\nxd@* is not expanded in this *\edef*, since it was created with
*\chardef*; such control sequences aren't expanded in *\edef*'s.
\pagelabel{CHARDEFNE} Consequently, the *\edef* simply makes *\next@* mean
\setbox0\hbox{\<expansion of *\macdef@*\>}
**
\write\ndx@{"box0}
**
so that  *\next@* then produces this *\write*.

Notice that it is  irrelevant that we are writing type~*12* tokens
to the *.ndx* file: once they are written to that file their category codes
are completely irrelevant\pagelabel{wcodes}---if 
\tex\ reads this file later, they will simply
be given the category codes that are in force at the time.


\section{The \CS{starparts\@} and \CS{windex\@} routines}
In version *1* of \lamstex@, only invisible entries could have *"1* optional
entries, but now even visible entries can have them.  

We will use a construction *\starparts@#1* that determines if *#1* contains
a *"1* and defines
\setbox0\hbox{ to be }
\setbox1\hbox{all of *#1*}
\setbox2\hbox{the part of *#1* before the first *"1* (or all of *#1* if there
 is none)}
\setbox3\hbox{the part of *#1* after the first
 *"1* (or empty if there is none)}
**
"hskip-20pt\stari@    "copy0"0 "box1
"hskip-20pt\starii@   "copy0"0 "box2
"hskip-20pt\stariii@  "copy0"0 "box3
**
We begin by choosing the values that will hold when no *"1* appears:
**
"hskip-20pt\def\starparts@#1{\def\stari@{#1}\def\starii@{#1}\let\stariii@=\empty
 . . .
**
Then we perform a test that sets *\iftest@* to be true if *"1* appears in *#1*
and false if it doesn't (compare the definition of *\tagin@* in
section~\Sref{TESTS}):
**
\test@false
\def\next@##1"1##2##3\next@{\ifx\starparts@##2\test@false
 \else\test@true\fi}
\next@#1"1\starparts@\next@
**
If no *"1* appears we are done; otherwise we will have to call another
routine that separates the two parts:
\C**
\def\starparts@#1{\def\stari@{#1}\def\starii@{#1}%
 \let\stariii@=\empty
 \test@false
 \def\next@##1"1##2##3\next@{\ifx\starparts@##2\test@false
  \else\test@true\fi}%
 \next@#1"1\starparts@\next@
 \iftest@\def\next@{\starparts@@#1\starparts@@}%
 \else\let\next@=\relax\fi\next@}
"slip
\def\starparts@@#1"1#2\starparts@@{\def\starii@{#1}%
 \def\stariii@{"1#2}}
**

\medskip
Once our *""...""* and *""""...""* constructions, to be defined
in section~\Sref{MKI},
 have used *\starparts@*
to determine *\stari@*, *\starii@*, and *\stariii@*, we will use 
*\starii@* to typeset `*...*' in the case of a visible index entry, 
and then we will use
the
``write@-index'' routine *\windex@*.

When we are making an *.ndx* file, this routine will first
**
\expandafter\unmacro@\meaning\stari@\unmacro@
**
to convert `*...*' to type~*12* tokens. Then 
**
\edef\macdef@{\string""\macdef@\string""}
**
will add *""* at each end, for the sake of the *index* program; *\string""*
is needed since *""* will be active.

Then we will use the *\edef* of page~\ref{WRITENDX} to write these tokens
to the *.ndx* file.  This will be followed by the page number. Actually,
instead of writing just the page number, 
we  write 
four groups,
the first containing the page number, and the next
three containing the page numbering style, the ``pre-page'' material, and the
``post-page'' material (Chapter~\ref{PG}), 
**
\write\ndx@{{\number\pageno}{\page@N}{\page@P}{\page@Q}}
**
This allows the  *index* program to
 deal with all sorts of special page numbering possibilities.

In addition, when *\ifindexproofing@* has been set true, we want to
**
\insert\margin@{\hbox{\rm\vrule \height9pt \depth2pt
 \width0pt ...
**
where the *\hbox* begins with a ``strut'', designed to keep baselines of
successive entries 11~points apart (see page~\ref{HWD} for the use of
*\height*, \dots).
\footnote{Perhaps \pagelabel{STRUTINSERT}
 this is a good place to mention something that
tends to be obscured in discussions about struts. Most \tex nicians are
familiar with struts as the device that allows one to place 
one *\vbox*
 above another and still have the proper space between the
bottom baseline of the top *\vbox* and top baseline of the bottom
*\vbox*.
 The problem here is that \tex\ will normally
insert only
*\lineskip* space between the two boxes, since the baseline of
the second box is so far from the baseline of the first.
  But the situation with regard
to *\footnote*'s, or members of other insertion classes,
 is really quite different:
\tex\ inserts {\it no interline glue whatsoever\/} between two different
members of an insertion class ({\it The \tex book}, page~125). Thus,
even single line footnotes will be spaced incorrectly without struts!
(Struts are discussed further in section~\Sref{VF}.)}


This *\hbox* should contain all material before any *"1* in `*...*'
typeset
in *\rm*, but all material after the first *"1* should be converted to 
type~*12* tokens, and typeset in the *\tt* font,
\footnote{Other styles (compare Part~\ref{SFPART}) may use smaller print for
these side notes.}
 since it contains things
like *"1e\it*, which are not supposed to be acted upon, but merely convey
information to the *index* program.



This is all accomplished with the following code:
\C**
\def\windex@{\ifindexing@
 \expandafter\unmacro@\meaning\stari@\unmacro@
 \edef\macdef@{\string""\macdef@\string""}%
 \edef\next@{\write\ndx@{\macdef@}}\next@
 \write\ndx@{{\number\pageno}{\page@N}{\page@P}{\page@Q}}%   
 \fi
 \ifindexproofing@
  \ifx\stariii@\empty\else
   \expandafter\unmacro@\meaning\stariii@\unmacro@\fi
  \insert\margin@{\hbox{\rm\vrule \height9pt \depth2pt
   \width0pt \starii@
  \ifx\stariii@\empty\else\tt\macdef@\fi}}%
 \fi}
**

At the time that our *\write* is performed, we will want 
*\noexpands@* to be in effect, partly
 to prevent expansion of any font control sequences that might appear in
*\page@P* and *\page@Q*, but mainly because we want to be sure that
*\page@N* isn't expanded during the *\write*, since  the *index* program
expects to see a numbering control sequence in this second group.

 But there's no point putting
**
{\noexpands@
 \write\npg@{{\number\pageno}{\page@N}{\page@P}{\page@Q}}}
**
in our definition, because this delayed *\write* is simply added to the
main vertical list and does not take place until a *\shipout*.   Instead,
we will have to be careful to specify *\noexpands@* during any
*\shipout* (section~\Sref{SO}).\pagelabel{SUB1}

Nevertheless, this is an appropriate time to discuss the problems that
would be encountered if expansion were not prohibited.
Expansion  would clearly cause problems if *\page@N* is defined as *\alph*
or *\Alph*, but, in fact, for this particular *\write*,
 expansion would be a problem
even if *\page@N* is defined as *\arabic*, because 
  *\page@N* appears in a group by
itself---\tex\ would complain during the *\write* that
**
! Argument of \page@N has an extra }.
**

And here comes the most subtle point of all: If we 
 *\let\page@N=\arabic*, then our *\write* would not
put *\arabic* in place of *\page@N*, even if *\noexpands@* is in effect
when it takes place,
 and we would get the very same error
message.\pagelabel{SUB} That is
because *\page@N* would have the
{\it original\/} meaning of *\arabic*---although *\noexpands@* says
`*\let\arabic=\relax*', our *\page@N* would not be this *\arabic*!
On the other hand,
when we *\def\page@N{\arabic}*, the *\write* first expands *\page@N* to
(the current) *\arabic*, and then doesn't expand {\it this\/} *\arabic*
further.


\section{Indexing\label{MKI}}
 Now we are finally ready to make *""* active,
\C**
\catcode`\""=\active
**
and define the action of *""*.
As we have already noted (page~\ref{SW}),
the combination *@""* will still work when~ *""*~ is active.


First of all,
*""* will have to look ahead to see if it is followed by another
*""*, because this indicates an invisible entry:
\C**
\def""{\futurelet\next\quote@}
\def\quote@{\ifx\next""\expandafter\quote@@\else
 \expandafter\quote@@@\fi}
**
Note that we are using the ``K-method'' here (see section~\Sref{K}).


*\quote@@@*, the result when *""* isn't followed by
another *""*, so that we have a visible index entry, is simply defined as
\C**
\def\quote@@@#1""{\starparts@{#1}\starii@\windex@}
**
Thus, after *\starparts@* defines *\stari@*, *\starii@*, and *\stariii@*,
we typeset *\starii@*---the part before any *"1*---%
 and then  apply the ``write-index'' routine *\windex@*.

We should note that
as a consequence of the definition of *\quote@@@#1*, the indexed word
 *#1* may be followed by an *\insert* and/or a
 ``whatsit'', namely, the 
*\write* produced by *\windex@*.
But either an *\insert* or
a  ``whatsit'' can  appear {\it after\/}
a  word without suppressing hyphenation---%
 see {\it The \tex book}, third paragraph
from the bottom on page~454.   (This should be compared to the *\makexref*
macro on page~424 of {\it The \tex book}, where the *\insert*
appears {\it before\/} the word, and therefore suppresses hyphenation of
the word.)  Similarly, as we will see in a moment,
 an invisible index entry simply supplies an *\insert* and/or 
a *\write*. The warning on page~100 of the 
\lamstex~Manual
is therefore inaccurate: an invisible entry will suppress hyphenation of a
word only if it immediately precedes it, not if it follows it. Similarly, 
the warnings on pages~31 and~33 are inaccurate; only a *\label* or
*\pagelabel* immediately preceding a word will interfere with its
hyphenation---in particular, the example given on page~33 won't interfere
with hyphenation.

\medskip


*\quote@@* is not that much different from *\quote@*, except that we want it
to swallow the next *""*, and begin with *\prevanish@*, so that it will be
invisible:
\C**
\def\quote@@""#1""{\prevanish@\starparts@{#1}\windex@
 \futurelet\next\quote@@@@}
**
The *\futurelet\next\quote@@@@* is needed to see whether yet
another *""* occurs after the third *""* that caused all this to happen.
If a fourth *""* didn't occur, we insert the  *\postvanish@*,
and if a fourth *""* did occur, we simply swallow it up, and then
insert the
*\postvanish@*:
\C**
\def\quote@@@@{\ifx\next""\def\next@""{\postvanish@}\else
 \let\next@=\postvanish@\fi\next@}
**

\section{Changes to the \lamstex\ Manual}Because of changes in the indexing
macros, almost every caveat on page~101 of the \lamstex~Manual is wrong.


The first paragraph is wrong:
index entries within heading levels {\it will\/} show up in the margins when
*\indexproofing* has been specified. (Of course, one had better not
type something like
**
\HL1 ""Disappearing"" words\endHL
**
since *""Disappearing""* would then be interpreted as a ``quoted'' number for
*\HL1*\,! Something like *\HL1{}""Disappearing""* is needed.)

The third paragraph is wrong, because only the parts after the first *"1*
will be typeset in the typewrite font, with
 characters of type~*12*.

The fourth paragraph is wrong: *\""* can be used within an invisible entry.

The fifth paragraph is wrong: invisible entries can now appear anywhere.

It is true, as the final paragraph claims, that index entries in
*\footnote*'s 
won't appear in
the margin (they are *\insert*'s within an *\insert*, and won't migrate out).
However, no special efforts are required in the *\footnote* macros to get 
indexing to work within *\footnote*.

\section{Invisibility}
After all this, we  want to add *""* to *\vanishlist@*:
\C**
\rightadd@""\to\vanishlist@
**
This probably looks wrong, since it is only the double mark *""""* that
indicates an invisible entry, but 
**
\nobreak\hskip-1pt\hskip1pt""...""
**
and 
**
\nobreak\hskip-1pt\hskip1pt""""...""
**
will both work out just right: before the visible index entry *""...""*
the *\hskip-1pt\hskip1pt* will simply be irrelevant, while before an
invisible index entry *""""...""* it provides the right clues for the
*\prevanish@* called by *\quote@@* (compare 
page~\ref{NOHARM}).



\section{Other delimiters for index entries\label{OTHERD}}The 
use of *""* as a delimiter
for index entries conflicts with its use in German styles (this will
probably remain true even when the
international font layouts are in use, although then the *""* will
presumably no longer be active for German). However, it is not very hard to
set up other delimiters for this purpose.  

For example, suppose we want to use *<...>* delimiters, so that
**
Beauty<<beauty>> is <truth>.
**
will produce a index entry for *truth*, and an
 invisible index entry for *beauty*. 

For this, we could
**
\catcode`\<=\active
\let<=""  % we might as well continue using \quote@, ...
"slip
% \def""{...} if we have new definitions for German, or
% \catcode`\""=12 if "" should no longer be active
"slip
\def\windex@{\ifindexing@
 \expandafter\unmacro@\meaning\nextii@\unmacro@
 \xdef\nextii@{\string<\macdef@>}%
  . . .
 \fi}
"slip
\def\quote@{\ifx\next<\expandafter\quote@@\else
 \expandafter\quote@@@\fi}
\def\quote@@@#1>{\starparts@{#1}\starii@\windex@}
\def\quote@@<#1>{\prevanish\starparts@{#1}\windex@
 \futurelet\next\quote@@@@}
\def\quote@@@@{\ifx\next>\def\next@>{\postvanish@}\else
 \let\next@=\postvanish@\fi\next@}
**

The new version of the *index* program (see Chapter~\ref{IPROG}) now accepts
any delimiters in the *.ndx* file.  However, as Chapter~\ref{IPROG}
 points out,
for German alphabetization we
would probably want some modifications to deal with words with umlauts.

We should probably also remove *""* from *\vanishlist@*. There is no general
mechanism for removing something from *\vanishlist@*.  However, since
we know that *\vanishlist@* will be of the form
**
\\\invisible\\"" ...
**
we can
**
\def\next@\\\invisible\\""#1\next@{\def\vanishlist@{#1}}
\expandafter\next@\vanishlist@\next@
**
	
\small 
For consistency, it would probably be better to choose, once and for all,
index entry delimiters that could be used in all cases; *<...>* don't satisfy
that requirement, since Scandinavian keyboards have letters instead of *<*
and *>*. There aren't too many possibilities left, however! 
The only reasonable candidates are *_* and *|* (although *+* and *=* would
also be possible, if we insisted that people never used them outside of math
mode), and
**
Beauty||beauty|| is |truth|, truth beauty
**
doesn't look too bad.
  If only *|* weren't used for something else in German styles!)
\endsmall

\section{{\tt\bs idefine} and {\tt\bs iabbrev}\label{IDAA}}
A construction like
\setbox0\hbox{\<parameter text\>}\setbox1\hbox{\<replacement text\>}
**
\idefine\cs"copy0{"copy1}
**
has to 
**
\define\cs"copy0{"copy1}
**
and also send this definition
off to the *.ndx* file.

*\idefine* first 
 stores its argument, *\cs* say, in *\next@*, and also stores
*\noexpand\cs* in *\nextii@*, for later use:   %%%%%%%
**
 \def\next@{#1}\def\nextii@{\noexpand#1}%
**
Then we will apply the construction *\idefine@* once we
have suitably swallowed up the \<parameter text\> and \<replacement text\>:
\C**
\def\idefine#1{\def\next@{#1}\def\nextii@{\noexpand#1}%
 \afterassignment\idefine@\def\nextiii@}
**
Here the *\def\nextiii@* will cause the following \<parameter text\> and
\<replacement text\> to be digested into a definition of *\nextiii@*, after
which assignment we will apply *\idefine@*.

Since *\nextiii@* now has the definition that we want for *\cs*, 
the first thing *\idefine@* must do is to
**
\let\cs=\nextiii@
**
Since *\next@* was *\def*'ed to be *\cs*, we can do this with
**
\expandafter\let\next@=\nextiii@
**

Then, if we are indexing,
 we need to recover the \<parameter text\> and \<replacement text\>
for *\cs*, which is now that for *\nextiii@*.
So we use
**
\expandafter\unmacro@\meaning\nextiii@\unmacro@
**
[This  construction
 doesn't work if `*->*'  appears in the \<parameter text\> of a
definition, so let's hope no one ever makes such a definition.]

Now we want to write
\setbox0\hbox{\<parameter text\>}\setbox1\hbox{\<replacement text\>}
**
\define\cs"box0{"box1}
**
to the *.ndx* file. Since *\nextii@* was defined as *\noexpand\cs*,
we can do this with
**
\immediate\write\ndx@{\noexpand\define
 \nextii@\macpar@{\macdef@}}
**
---note that the *\write* will first expand *\nextii@* to
*\noexpand\cs*, and then replace this with *\cs*, unexpanded.
Since all tokens in *\macpar@* and *\macdef@* are type~12, we don't have
to worry about their
 expansion (and note the remark on page~\ref{wcodes}).



Thus, the definition of *\idefine@* reads:
\C**
\def\idefine@{\ifindexing@
 \expandafter\let\next@=\nextiii@
 \expandafter\unmacro@\meaning\nextiii@\unmacro@
  \immediate\write\ndx@{\noexpand\define\nextii@
   \macpar@{\macdef@}}\fi}
**

*\iabbrev* is  simpler.  Recall that *\iabbrev* must be used
in the form
**
\iabbrev"1\cs{...}
**
so we define
\C**
\def\iabbrev"1#1#2{\ifindexing@
 \toks@={#2}%
 \immediate\write\ndx@
  {\noexpand\abbrev"1\noexpand#1{\the\toks@}}\fi}
**