summaryrefslogtreecommitdiff
path: root/info/impatient/macros.tex
blob: e3a84adac70ef0b0b53c6b4190594cc97471b04a (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
% This is part of the book TeX for the Impatient.
% Copyright (C) 2003 Paul W. Abrahams, Kathryn A. Hargreaves, Karl Berry.
% See file fdl.tex for copying conditions.
%
% Macros for typesetting TeX for the Impatient.
%
% These macros are being distributed without any warranty whatsoever.
% The level of commentary is that which we, the authors, found necessary
% for our own purposes. 
%
% ==========================================================================
%
% The macros use the term `chapter' for what in the book is called
% a `section', `section' for the book's `subsection', etc.  For purposes of
% defining macros it's convenient to think of the book as divided into
% chapters, but because of the nonsequential nature of the book we don't
% want to tell the readers that they are reading chapters.


% An embedded file should end with \byebye.
% 
\begingroup
\ifx \macsin\relax
   % In frontm.tex, we do \input macros several times, and we still want
   % the \byebye at the end to end the job.
   % So we \input inside a group in frontm, and make the assignment to
   % \endinput local.
   \aftergroup\let\aftergroup\byebye\aftergroup\endinput
   \aftergroup\endinput   % Don't read this file again.
\else
   \global\let\byebye = \end
   \global\let\macsin = \relax
\fi
\endgroup

% This must come before config.tex.
\input eplain

% Define configuration switches and then read their values.
% 
\newif\ifcenterpage \centerpagetrue
\newif\ifcompletebook
\newif\iffinal % true for the 2000dpi copy
\newif\ifmsdos
\newif\ifedgetabs \edgetabstrue
\newif\ifdvi \dvitrue % true if we want a .dvi file

%\xrefwarningfalse

% The config file contains settings for flags, e.g.,
%   \completebookfalse
% It can be empty as long as it exists.
\input config
\ifcompletebook \else\rewritetocfilefalse \fi
\edef\tempfile{\ifmsdos g:temp \else x \fi}
\ifx\setmodes\undefined\else\setmodes\fi % modify from command line input

% Certain defaults are forced by certain others.
%
\iffinal \centerpagetrue \edgetabstrue\fi

% Initial definitions.  (These should come before \input fonts.)
% 
\catcode`\@ = \letter % For the macro file only.

% We don't want register allocation information in the log,
% so we redefine the relevant macro from plain.tex.

\def\alloc@#1#2#3#4#5{\global\advance\count1#1 by 1
   \ch@ck#1#4#2%
   \allocationnumber=\count1#1  \global#3#5=\allocationnumber
}

% The fonts.  This should come before defining the new character control
% sequences that follow.
% 
\input fonts

\hyphenation{script-script base-line-skip no-base-line-skip line-skip
   line-skip-limit max-dead-cycles output-penalty no-inter-line-skip
   show-box-depth show-box-breadth if-hmode if-vmode if-mmode
   back-spaces back-space par-indent tracing-on-line}

{
   \catcode`\| = 0
   \catcode`\\ = \other
   |global|let|bsc = \   % \bsc is a true backslash character.
}

\let\\ = \bsc

\def\bslash{$\backslash$} % backslash suitable for printing
\let\shriek = !
\let\vbar = |
{
   \catcode `\[ = 1 \catcode `\] = 2 
   \catcode `\{ = \other \catcode `\} = \other
   \global\let\lbracechar = {
   \global\let\rbracechar = }
]
\def\blbrace{{\bt \{}}
\def\brbrace{{\bt \}}}

{
   \catcode`\ =\other% Notice no spaces at beginning of next line.
\gdef\otherspace{ }
}

\let\mathlbrace = \{  \let\mathrbrace = \}
{
   \catcode `\[ = 1 \catcode `\] = 2
   \catcode `\{ = \other \catcode `\} = \other
   \gdef\{[\ifmmode\mathlbrace\else [\bt {]\fi]
   \gdef\}[\ifmmode\mathrbrace\else [\bt }]\fi]
]


% These are for debugging (less drastically than \tracingall or \loggingall).
% 
\def\tron{\tracingmacros=2 \tracingcommands=2 \tracingonline=1}
\def\troff{\tracingmacros=0 \tracingcommands=0}

% \pagebreak should always cause a break, even if the resulting
% page is empty.
% 
\def\pagebreak{\null\vfill\eject}

% \linebreak causes a line break in chapter headings, but outside of that
% context we don't want it to do anything.
%
\let\linebreak = \relax


% Parameters.
% 
\parskip = 0pt plus 0.3pt
\newdimen\codefuzz \codefuzz = 10pt % for \csdisplay, \example
\hbadness = 4000
\vbadness = 8000
\hfuzz = 0.1pt % as in plain TeX
\vfuzz = 0.1pt % as in plain TeX
\exhyphenpenalty = 0 % we don't mind these
\widowpenalty = 10000 % these are very bad
\clubpenalty = 10000 % these are very bad too

% Page margins.
%
% Note that the \newdimens can't be within an \if or a \def
% because \newdimen is an \outer macro (thanks to DEK).
% 
\newdimen\insidemargin \newdimen\outsidemargin
\newdimen\topmargin \newdimen\bottommargin
\newdimen\headmargin
\newdimen\totalwidth \newdimen\totalheight
\newdimen\oddoffset \newdimen\evenoffset
\newif\ifnoheadline

% \totalwidth and \totalheight are the actual trim size of the book.
% \insidemargin, \outsidemargin, \topmargin, and \bottommargin are margins
% with respect to the pages of the book, not the draft 8 1/2 x 11 pages.
%

% This makes it so that we only have to cut twice on a page.
% 8.5" = 51.19125pc exactly.
% \totalwidth should = \outsidemargin + \insidemargin + \hsize.
% 
\totalwidth = 7.375in % 44.4159375pc = 7 3/8".
\outsidemargin = 8pc
\insidemargin = 10pc
\hsize = \totalwidth
\advance \hsize by -\outsidemargin
\advance \hsize by -\insidemargin
% \hsize should now be 26.4159375pc

% Now that we know \hsize, we can set \parfillskip to eliminate (most)
% widows. 
%
\parfillskip = .75\hsize plus .06\hsize minus .75\hsize


% \oddoffset and \evenoffset are the \hoffset values needed to
% align the left edge of the virtual page with the left edge of the
% draft paper (not the left edge of the book pages).
%
% The -1in below comes from the default margin, which the DVI driver must
% set at 1in.  Odd pages are on the left, even on the right.
% 
% First, align the left edge of the virtual page with the left edge of the
% draft page.
%
\oddoffset = -1in
\advance\oddoffset by \insidemargin
%
\evenoffset = -1in
\advance\evenoffset by \outsidemargin

% For centered pages, move the virtual page right by half the trim width.
%
\ifcenterpage
   \dimen0 = 8.5in
   \advance\dimen0 by -\totalwidth
   \divide\dimen0 by 2
   \advance\oddoffset by \dimen0
   \advance\evenoffset by \dimen0 

% For uncentered even-numbered pages, align the right edge of the virtual
% page with the right edge of the draft paper so that we can remove the trim
% of two-sided pages with a single cut.
%
\else
   \advance\evenoffset by 8.5in
   \advance\evenoffset by -\totalwidth
\fi

\hoffset = \oddoffset   % First page is numbered one.

% Now for the vertical, which is simpler, since it doesn't vary from
% page to page.
% 11" = 66.2475pc exactly.
% \totalheight should = \topmargin + \bottommargin + \vsize.
% 
\totalheight = 9.25in % 9 1/4" = 55.708125pc
\topmargin = 6pc      % Distance from top of page to baseline of text line 1
\bottommargin = 6pc   % Distance from last line to bottom of page.
\topskip = 2pc        % Distance from top of \box255 to baseline of text line 1
% \vsize                Distance from top of \box255 to last line of text.
% \headmargin           Distance from top of \box255 to top of page
% We'll place the headline just above \box255

\headmargin = \topmargin \advance \headmargin by -\topskip

\vsize = \totalheight
\advance \vsize by -\headmargin
\advance \vsize by -\bottommargin
% \vsize should now be 46.708125pc

\voffset = -1in % align top of logical page with top of physical page
\advance \voffset by \headmargin
\ifcenterpage
   \dimen0 = 11in
   \advance\dimen0 by -\totalheight
   \divide\dimen0 by 2
   \advance\voffset by \dimen0
\fi

\topskip = 2pc        % Distance from headline to first line of text.


% Other formatting parameters.
% 
% The basic increments we'll use in the layout.
% 
\def\setskip#1 = #2 {%
   \dimen0 = #2\baselineskip
   \csname #1skipamount\endcsname =
      \dimen0 plus .33\dimen0 minus .25\dimen0
   \ignorespaces
}
\newskip\greaterskipamount
\newskip\greatskipamount
\newskip\biggerskipamount
\newskip\medbigskipamount
\newskip\medsmallskipamount
\newskip\tinyskipamount

\setskip greater = 2.5
\setskip great = 2.0
\setskip bigger = 1.5
\setskip big = 1.0
\setskip medbig = .75
\setskip med = .5
\setskip medsmall = .375
\setskip small = .25
\setskip tiny = .125

\parindent = 1em
\newdimen\normalindent \normalindent = \parindent

\footnotemarkseparation = .16666em

\abovelistskip = \smallskipamount
\interitemskip = \tinyskipamount
\belowlistskip = \smallskipamount
\listleftindent = \parindent

% Displays involve text and math.  We don't want as much flexibility in
% the glue as plain.tex sets.
% 
\abovedisplayskip = \medsmallskipamount
\abovedisplayshortskip = 0pt plus 2pt
\belowdisplayskip = \medsmallskipamount
\belowdisplayshortskip = \belowdisplayskip

\newskip\intercapsuleskip   \intercapsuleskip = .75\tinyskipamount plus 0.4pt
\newdimen\capsulehangindent  \capsulehangindent = 2pc

\newskip\aboveconceptskip   \aboveconceptskip = \bigskipamount


\newskip\abovesectionskip    \abovesectionskip = \greaterskipamount
% No stretch or shrink below heads, according to A-W.
\newskip\belowsectionskip    \belowsectionskip = 1\biggerskipamount

\newskip\abovesubsectionskip   \abovesubsectionskip = \greatskipamount
\newskip\belowsubsectionskip   \belowsubsectionskip = 1\bigskipamount

\newskip\abovedescriptionskip   \abovedescriptionskip = \biggerskipamount
\newskip\belowdescriptionskip   \belowdescriptionskip = \medskipamount

\newskip\explainskip   \explainskip = \tinyskipamount
\newskip\exampleskip   \exampleskip = \smallskipamount

\def\interexampleskip{\vskip\medsmallskipamount}
\def\tinyskip{\vskip\tinyskipamount}

% Space in which a symbol is shown in a columnated list of commands.
\newdimen\symbolspace  \symbolspace = 14pt

% \colsindent is the indentation before material arranged in columns and
% displayed, as in the list of Greek letters.
\newskip\colsindent \colsindent = \parindent

% The indentation for page lists in the index that don't fit on one line.
\newdimen\indexpageindent   \indexpageindent = 1pc

% The indentation for subsidiary entries in the index. (Should be less
% than \indexpageindent.)
\newdimen\indexlevelindent   \indexlevelindent = .5pc 

\newskip\codebaselineskip   \codebaselineskip = \baselineskip

% Fill the previous page with blank space before a command.
%
\def\cmdbreak{\par\nobreak\vfil\penalty 1000\vfilneg\par}

% Penalties.
%
\newcount\conceptpenalty   \conceptpenalty = -1500
\newcount\intercmdnamepenalty   \intercmdnamepenalty = 300
\newcount\@intercmdnamepenalty  \@intercmdnamepenalty = \intercmdnamepenalty



% The output routine.
%
\output = {%
   \onepageout
   %
   % Odd pages are right-hand pages.
   % 
   % Note \pageno has been incremented when we get here -- it now refers
   % to the page number of the page about to be typeset, not the page
   % that we just shipped out.
   % 
   \ifodd\pageno   % \onepageout advances \pageno.
      \global\hoffset = \oddoffset
      \global\intercmdnamepenalty = 10000
   \else
      \global\hoffset = \evenoffset
      \global\intercmdnamepenalty = \@intercmdnamepenalty
   \fi
}

\ifdvi\else\output={%
   \setbox0=\box255\deadcycles=0
   \advancepageno
   \global\advance \truepage by 1
   \ifnum\outputpenalty>-20000\else \dosupereject \fi
   }
\fi

\def\onepageout{%
   \shipout\vbox{%
      \offinterlineskip % The page should have vertically abutting boxes.
      \ifodd\pageno
         \cropmargin = \insidemargin
      \else
         \cropmargin = \outsidemargin
      \fi
      \addcropmarks % Does not affect the position.
      \ifcenterpage \addtruepage \fi
      %
      \ifedgetabs \ifodd\pageno \ifnoheadline\else
         \edgetabs % Does not affect the position.
      \fi\fi\fi
      %
      \vbox to 0pt{\vskip-\headmargin \vskip-3.5pc
         \rightline{\sevenrm\timestamp}\vss}%
      %
      \smash{\line{\the\headline}}% Simplified \makeheadline.
      \pagebody
      \vskip 2\normalbaselineskip
      % The footline is needed on one page (for an example).
      \line{\the\footline}%
   }%
   % Now the rest from \plainoutput:
   \advancepageno
   \global\advance\truepage by 1
   \ifnum\outputpenalty>-20000\else \dosupereject \fi
} 

\footline = {\hfil}

% The headline always includes the name of the current chapter.  This
% goes on the inside.  If more information, such as the concept we're
% explaining, is included, it goes on the outside.
% 
\headline = {%
   % Produce the timestamp
   \ifnoheadline
      \hfil
      \global\noheadlinefalse
   \else
      \let\\ = \ignorespaces
      \ifodd \pageno  % Right-hand page.
         {\tenit \firstmark}\hfil {\tenbf \folio}%
      \else           % Left-hand page.
         {\tenbf \folio}%
         \hfil
         {\tenit
          \chaptername
          \ifnum\pageno>0\ifback\else
            \quad $\backslash$\quad\S\the\chapterno
          \fi\fi
         }%
      \fi
   \fi
}

% Sizes for cropmarks:
% 
\newdimen\cropthick  \cropthick = 0.4pt
\newdimen\crophsize  \crophsize = 1pc
\newdimen\cropvsize  \cropvsize = 1pc
\newdimen\cropoffset \cropoffset = .0625in

% Each of the following macros generates a quarter of a cropmark as
% a zero-size box at the center point of the cropmark.
% We want the cropmarks to be centered with respect to their thicknesses.

\def\vcropdown {\hbox to 0pt{%
   \kern -.5\cropthick
   \vbox to 0pt{%
      \vskip \cropoffset
      \hrule width\cropthick depth\cropvsize height0pt
      \vss}%
   \kern -.5\cropthick}%
}

\def\vcropup {\hbox to 0pt{%
   \kern -.5\cropthick
   \vbox to 0pt{%
      \vss
      \hrule width\cropthick depth\cropvsize height0pt
      \vskip \cropoffset}%
   \kern -.5\cropthick}%
}

\def\hcropright{\rlap{\kern\cropoffset\smash{%
   \vrule width\crophsize depth .5\cropthick height .5\cropthick}}}

\def\hcropleft{\llap{\smash{%
   \vrule width\crophsize depth .5\cropthick height .5\cropthick}%
   \kern\cropoffset}}

% \cropmargin will be set to the left margin on the current page.
% 
\newdimen\cropmargin
\def\cropline#1{\moveleft\cropmargin\hbox to \totalwidth{#1}}

% \addcropmarks adds the cropmarks to a page while leaving everything else
% alone.  It assumes we're positioned at the top of the page.

\def\addcropmarks{%
   \vbox to 0pt{%
      \offinterlineskip % contextually redundant but precautionary
      \vskip -\headmargin  % to get to logical top of page
      \ifcenterpage
         \cropline{\hcropleft\vcropup \hfil \vcropup\hcropright}
      \else
         \cropline{\hfil \vcropdown}%
      \fi
      \vskip\totalheight
      \ifcenterpage
         \cropline{\hcropleft\vcropdown \hfil \vcropdown\hcropright}%
      \else
         \cropline{\hcropright\hfil\hcropleft\vcropup\vcropdown\hcropright}%
      \fi
      \vss
}}

% \addtruepage adds a small page number near the upper right cropmark.
%
\newcount\truepage \truepage = 1
\def\addtruepage{%
   \vbox to 0pt{\vskip -\headmargin\vskip -2pc
      \moveleft\cropmargin\hbox to \totalwidth{%
         \twelvebf 
         \quad\TeX\ for the Impatient\hss
         N\raise 3.3pt\hbox{o} \the\truepage\quad}%
      \vss}%
}


% The mark information is output by \markinfo.
%
% We can use a different mark, e.g., a shorter heading, by calling
% \changemark.
% 
\newtoks\shortmark \shortmark = {}
\newif\ifchangemark

\def\markinfo#1{%
   \ifchangemark
      \mark{\the\shortmark}\changemarkfalse
   \else
      \mark{#1}%
   \fi
}

\def\changemark#1{\shortmark = {#1}\changemarktrue}


% ``Tabs'' down the side of the book.
% Say \nextedgetab to move the thing down to the next.
% Say \edgetabsfalse to turn them off.
% 
\newcount\numtabs  \numtabs = 7
\newdimen\edgetabjump  \edgetabjump = 0pt
\def\nextedgetab{%
   \advance\edgetabjump by \edgetabdepth
}

\def\settabdepth#1{%
   \edgetabdepth = #1
   \setbox\tabbox = \vbox to \edgetabdepth{%
      \leaders
      \vbox{\vskip \edgespacing
         \hrule width\edgetabwidth height0pt depth\edgethick}%
      \vfil}
}

\newskip\bigtab \newskip\smalltab
\newskip\edgetabdepth   
\newbox\tabbox

\bigtab = \totalheight    \divide\bigtab by \numtabs
\smalltab = .4\bigtab % five smalls make two bigs

\newdimen\edgetabin     \edgetabin = .25in
\newdimen\edgetabbleed  \edgetabbleed = .25in
\newdimen\edgetabwidth
   \edgetabwidth = \edgetabin
   \advance \edgetabwidth by \edgetabbleed
\newdimen\edgethick   \edgethick = .3pt % line thickness
\newdimen\edgespacing \edgespacing = .9pt % line spacing


\def\edgetabs{\vbox to 0pt{%
   \vskip-\headmargin
   \vskip\edgetabjump
   \hbox{%
      \hskip \hsize
      \hskip\outsidemargin
      \hskip-\edgetabin
      \copy\tabbox
      }%
   \vss
}}


% We can simplify \pagecontents (which is called by \pagebody) somewhat,
% since we don't have \topinserts.
% 
\def\pagecontents{%
   \unvbox255   % The main page contents.
   %
   \ifvoid\footins\else   % Footnotes are present.
      \vskip\skip\footins
      \footnoterule
      \unvbox\footins
   \fi
}


% The command chapters had a mini-index at the bottom of right-hand
% pages.  These definitions are the way to put entries into it.
% 
% \minref generates a reference for the mini-index, and prints the
% reference on the page, also.
% 
\def\minref#1{%
   #1% Print it on the page.
   % That's it, now.
}

% Mini-index entry without printing the argument on the page.
% Just ignore the argument now.
% 
\def\minrefs#1{%
   \ignorespaces
}

% This is used for producing the concept mini-index.
% 
\def\minrefsdelim#1\endmark{\minrefs{#1}}

% One last insertion-oriented thing:
% we always want numbered footnotes, as defined in eplain.
% We'll do them in 8-point type.
% 
\let\@plainfootnote = \footnote
\let\footnote = \numberedfootnote
\everyfootnote = {\footnotefonts}


% The \margin macro produces a marginal note at the same level as its call.
% It should only be used in a paragraph or in the main vertical list.
% It is nullified when we're printing the final copy.
%
\def\margin#1{%
   \ifhmode
      \vadjust{\printmarginnote{#1}}%
   \else
      \dimen0 = \prevdepth
      \prevdepth = -1000pt
      \printmarginnote{#1}%
      \prevdepth = \dimen0
   \fi
   \ignorespaces 
}

\def\printmarginnote#1{%
   \hbox to 0pt{%
      \hskip 1.1\hsize
      \vbox to 0pt{%
    \everypar = {}% Don't inherit hanging indentation.
    \hsize = 1in \rightskip = 0pt plus 1fil \noindent \sevenrm
    \let\tt = \eighttt
    \parfillskip = 0pt plus 1fil
    \baselineskip = 8pt #1%
         \vss
      }%
      \hss
   }%
}

%\iffinal
\iftrue
   \def\margin#1{\ignorespaces}
\fi


% Stuff to preserve page breaks inserted for the 2nd printing.
% This macro takes one ``argument''.
% 
\def\secondprinting{\afterassignment\finishsecondprinting \toks0 = }
\def\finishsecondprinting{\the\toks0}



% Parts of the book.
%
% 
% Chapters.
% 
\let\chaptername = \empty
\newcount\chapterno

\def\chaprule{\vrule depth3\baselineskip height1.5pc width1pt}

% Chapter openings should not have headlines.
% The text of each chapter starts on a right-hand page in the final
% book.  The facing page has an illustration.  This means that if the
% previous chapter ended on a left-hand (i.e., even) page, we have to
% eject an extra blank page.
% 
\outer\def\chapter#1 \par{%
   \ifcompletebook % Don't do the blank pages for proof copies.
      \blankpage % the illustration page
      % The first real chapter starts on page 1.
      \ifnum\pageno < 0 \pageno = 1 \fi
   \fi
   %
   \def\chaptername{#1}%
   \advance\chapterno by 1
   %
   \setbox0 = \hbox{\chapternumeralfont
                    \kern1pt
                    \expandafter\kernchapno\the\chapterno\empty
                    \kern3pt}%
   \vglue 0pt % But we get a \topskip of 2pc now.
   \nointerlineskip
   \leftline{%
      \ifback\else
         \vtop{%
            \copy0
            \vskip6pt
            \hrule width\wd0 height2.2pc
         }%
         \kern 16pt
      \fi
      \chapterfonts % to get \baselineskip now
      \chaprule
      \kern 6pt
      \vtop{%
         \def\linebreak{\hfil\break}%
         \noindent \chaptername}%
   }%
   \vskip 6pc plus.5pc minus.5pc
   \noheadlinetrue
   \toks0=\expandafter{\chaptername}
   \edef\writechaptertoc{%
     \noexpand\writenumberedtocentry{chapter}{\the\toks0}{\the\chapterno}%
   }%
   \writechaptertoc
   %
   % Use chaptername as first A-head (or only one).
   \mark{\chaptername}%
   \footnotenumber = 0 % Number footnotes from 1 in each chapter.
   \beginit{CHAPTER}%
   \noindent
   \ignorespaces
}

\def\endchapter{%
   \mark{\chaptername}% Use chapter name on last blank recto page
   \vfil\eject  % be sure everything's out before testing for recto
   \ifodd\pageno
      \message{Chapter ends on a verso page.}%
      \blankpage
   \fi
   \endit{CHAPTER}%
}
%
% \blankpage creates a blank page with no headline.
% In the final book, it just advances the page number.
% For the web edition, the blank pages serve no purpose except to keep
% the indexing correct.  I didn't want to rerun the index.
% 
\def\blankpage{%
   \iffinal
      \advancepageno
      \global \advance \truepage by 1
   \else
      \noheadlinetrue\pagebreak
   \fi
}

% This hokey little macro kerns between the numerals in the chapter
% number.  We want to kern more between `11' then otherwise; also, we
% want to remove the extra space before the chapter number, and after
% `11'.
% 
\def\kernchapno#1#2{%
   \ifx\empty#2\else \kern-3pt \fi
   #1%
   \ifx\empty#2\else
      \if1#2%
         \kern-.1em
      \else
         \kern-.05em
      \fi
   \fi
   #2%
   \if 1#2\kern-.1em\fi
}

% Sections.
% 
\newif\ifheading   % Avoid breaking after a heading.

% get section numbers for the fdl only, since it has internal references.
\let\fdlkludge=\empty

% The heading flag is turned on by headings and turned off
% at the start of a description.
% 
\outer\def\section#1 \par{%
   \par % be sure we're in vertical mode
   \saveskip = \lastskip % will be 0 if no skip
   \cmdbreak
   \combineskips\abovesectionskip
		\dimen0 = 2.5\baselineskip \advance\dimen0 by -\topskip
		\vskip -\dimen0
		\vglue \dimen0
   %
   {\sectionfonts \leftline{\fdlkludge #1}}%
   %
   \markinfo{#1}%
   \writetocentry{section}{#1}%
   \nobreak
   % Don't go into horizontal mode within the command descriptions.
   % 
   \vskip\belowsectionskip
   \ifcommands \else \noindent \fi
   \headingtrue
   \everypar = {\headingfalse \global\everypar = {}}%
      % only gets executed for \par in horizontal mode
   \ignorespaces
}


% Subsections.  We don't want a break at the glue if we were preceded by
% a \nobreak.
% 
\def\subsection#1 \par{%
   \par % be sure we're in vertical mode
   \saveskip = \lastskip % will be 0 if no skip
   \ifheading  % Did we just have \section?
      \nobreak
	\fi
   \combineskips\abovesubsectionskip
	\dimen0 = 2.5\baselineskip \advance\dimen0 by -\topskip
	\vskip -\dimen0
	\vglue \dimen0
   %
   {\subsectionfonts
      \leftline{\vrule width.5em height1.2ex depth.2ex \enspace #1}}%
   \writetocentry{subsection}{#1}%
   \nobreak
   % Don't go into horizontal mode within the command descriptions.
   \vskip\belowsubsectionskip
   \ifcommands \else \noindent \fi
   \headingtrue 
   \everypar = {\headingfalse \global\everypar = {}}%
      % only gets executed for \par in horizontal mode
   \ignorespaces
}

% \combineskips combines the current skip (#1) with the previous skip
% (which must be in \saveskip), and effectively skips by the larger of
% the two.
%
\newskip\saveskip
\def\combineskips#1{\ifdim\saveskip<#1\vskip-\saveskip \vskip#1\fi}



% List macros.
% 

% We want to use different names than eplain.
% 
\let\ulist = \unorderedlist
\let\endulist = \endunorderedlist
%
\let\olist = \numberedlist
\let\endolist = \endnumberedlist

\let\compact = \listcompact

% The \noindent here keeps us from getting indentation on the first line.
% It also makes the display into a `short' display, FYI.
% The \belowdisplayskip and \abovedisplayskip glue are inserted by the
% display.
% 
\long\def\display#1{%
   \ifvmode \noindent \fi
   $$\vtop{\everypar = {}\hsize = \displaywidth
      \parfillskip = 0pt plus 1fil % don't worry about widows
      \noindent #1\par\global\savedepth = \prevdepth}$$%
   \endgraf
   \prevdepth = \savedepth
}

% \vdisplay is like \display, except it's for vertical mode material.  Use it
% to avoid an unwanted initial lineskip.
% 
\long\def\vdisplay#1{%
   \ifvmode \noindent \fi
   $$\vtop{\everypar = {}\hsize = \displaywidth
      \parfillskip = 0pt plus 1fil % don't worry about widows
      #1\par\global\savedepth = \prevdepth}$$%
   \endgraf
   \prevdepth = \savedepth
}



% Indexing.
% Derived from Knuth's manmac macros.
% 
\newwrite\index

\immediate\openout\index = \jobname.idx
\newif\ifsilent

% We need ^ to be active temporarily, while we define it.
% 
{  \catcode`\^ = \active
%
\gdef^{%
   \ifmmode
      \let \nextaction = \sp
   \else
      \let \nextaction = \beginindexref
      \begingroup
      \catcode `| = \other \catcode `^ = \other
   \fi
   \nextaction
}}

\def\beginindexref{\futurelet\next\checksilence}

{% And for here, we need ^ to be deactivated
\catcode `^ = \other

\gdef\checksilence{%
   \if ^\next
      \silenttrue \let\nextaction = \secondhat
   \else
      \silentfalse \let\nextaction = \checkbar
   \fi
   \nextaction
}

% Eat the `^' that we saw would be the next token.
% 
\gdef\secondhat^{\checkbar}

} % end scope where ^ is \other

\def\checkbar{\futurelet\next\iswitch}

% Here we start reading the text of the actual index entry;
% we've determined whether it's silent or not.
% 
% We handle the following cases:
%      ^{alpha} and ^^{alpha}
%      ^|alpha| and ^^|alpha|
%      ^|\alpha| and ^^|\alpha|
% 
% When this is called, \next is either `|' or `{'.
%
\def\iswitch{%
   \ifx |\next
      \let \nextaction = \checkbackslash
   \else
      \let \nextaction = \normalidx
   \fi
   \nextaction
}

\def\checkbackslash|{%
   % within |...| we allow anything (but another |)
   \deactivate \catcode `\  = \other
   \futurelet\next\litidx
}

% The thing after the ^ is a |.  We have further checking to do -- is
% the next character a \?
% 
{ % reverse \ and /
\catcode`\/ = 0
\catcode`\\ = \other
/gdef/litidx{%
   /if \/next
      /expandafter/litidxA
   /else
      /expandafter/litidxB
   /fi
}

% The thing being indexed starts with a \.
% 
/gdef/litidxA \#1|{%
   /ctsidxref{#1}%
   /litidxswitch{/\#1}%
}

% The thing being indexed is just a word.
% 
/gdef/litidxB #1|{%
   /ttidxref{#1}%
   /litidxswitch{#1}%
}
}% end reversal of \ and /

% The thing after the ^ is not a |.
% 
\def\normalidx#1{%
   \ifsilent
      \aftergroup\ignorespaces
   \else
      #1%
   \fi
   \idxref{#1}%
   \endgroup % group started by \iswitch.
}

\def\litidxswitch#1{%
   \ifsilent
      \aftergroup\ignorespaces
   \else
      {\tt #1}%
   \fi 
   \endgroup % group started by \iswitch.
}



% Indexing macros for external use.

% \idxref generates an index entry for #1. If #1 contains any control
% sequences, they are treated literally.
% 
\def\idxref#1{\indexwrite{#1}N\ignorespaces}


% For creating an index entry for control space.
{\catcode `\ =\other
\gdef\blankidxref{\ctsidxref{ }}
}

% I removed this macro from eplain because \csname works as well, but
% since the macros below are already written to use it ...
\def\@tokstostring#1{\@ttsA#1 \@ttsmarkA}%
\let\tokstostring=\@tokstostring
\def\@ttsA#1 #2\@ttsmarkA{%
   \@ifempty{#1}\else
      \@ttsB #1\@ttsmarkB
      \@ifempty{#2}\else
         \@spacesub\@ttsA#2\@ttsmarkA
      \fi
   \fi
}%
\def\@ttsB#1{%
   \ifx #1\@ttsmarkB\else
      \string #1%
      \expandafter\@ttsB
   \fi
}%
\def\@ttsmarkB{\@ttsmarkB}% should never be expanded
%
\def\@spacesub{+}%
\let\spacesub = \@spacesub
%
\def\@ifempty#1{\@@ifempty #1\@emptymarkA\@emptymarkB}%
\def\@@ifempty#1#2\@emptymarkB{\ifx #1\@emptymarkA}%
\def\@emptymarkA{\@emptymarkA}% Again, so \ifx won't complain.

% #1 is the index term, #2 is the reference as in 
% Diacritical mark, see accent.

\def\idxsee#1#2{%
   \begingroup
   \def\spacesub{\otherspace}%
   \edef\nextaction{\write\index{\tokstostring{#1}::N::*\tokstostring{#2}}}%
   \nextaction
   \ignorespaces
\endgroup}


% \ttidxref generates an index entry for #1 in the program font.
% If #1 contains any control sequences, they are treated literally.
% 
\def\ttidxref#1{\indexwrite{#1}T\ignorespaces}


% \ctsidxref generates an index entry for a control sequence.  #1
% should not have a preceding backslash, so that the proper call for
% indexing \alpha is \ctsidxref{alpha}.
% 
\def\ctsidxref #1{\indexwrite{#1}C\ignorespaces}

% \indexchar is needed to generate index entries for three especially
% difficult single characters: {, }, and \.  They are blank-delimited.
% 
\def\indexchar{\begingroup \deactivate \indexcharA}
\def\indexcharA#1 {\indexwrite{#1}T\endgroup}

% \pix indicates that the next index entry is a principal one.
% 
\newif\ifpix
\def\pix{\global\pixtrue}

% \bix and \eix indicate that the next index entry begins or ends a
% range of pages.
%
\newif\ifbix \def\bix{\bixtrue}
\newif\ifeix \def\eix{\eixtrue}

% #1 is the text of the entry, #2 is N (normal), T (typewriter) or
% C (control sequence) or `cs' for now.
%
\def\indexwrite#1#2{\begingroup
   \def\spacesub{\otherspace}%
   \edef\tts{\tokstostring{#1}}%
   \edef\nextaction{\write\index{\tts::#2::\noexpand\number\noexpand\pageno
      \ifpix P\fi\ifbix B\fi\ifeix E\fi}}%
   \nextaction
   \global\pixfalse \global\bixfalse \global\eixfalse
\endgroup}

{\catcode `\^ = \other \gdef\twocarets{^^}}


% For generating index entries with weird characters, we need to deactivate
% them: { } blank \  and substitute [ ] ! for { } \ .  \recat does this.
% It should be enclosed in a group (which must end in `]').
\def\recat{%
   \aftergroup\ignorespaces
   \catcode `\! = 0 \catcode `[ = 1 \catcode `] = 2
   \catcode `\  = \other \deactivate
}



% Macros for the front matter.
%
% Space at the top of the frontmatter pages.
% 
\def\sinkage{\vglue 7pc \relax}

% And at the top of the backmatter pages.
% 
\def\backsinkage{\vglue 2pc \relax}

% \frontchapter doesn't care if we're on an even page or an odd page.
%
\def\frontchapter#1 \par{%
   \def\chaptername{#1}%
   \leftline{%
      \chapterfonts
      \chaprule
      \kern 6pt
      \vtop{%
         \def\linebreak{\hfil\break}%
         \noindent \chaptername}%
   }%
   \vskip 4pc
   \noheadlinetrue
   % Use chaptername as first A-head (or only one)
   \mark{\chaptername}%
   \noheadlinetrue
   \noindent \ignorespaces
}


% We are called from inside a group, so we can redefine the \toc... macros.
% 
\def\shortcontents{{%
   \firsttoctrue
   \backfalse
   \shorttocfonts
   \let\tocchapterentry = \shorttocchapter
   \let\tocsectionentry = \gobblethree
   \let\tocsubsectionentry = \gobblethree
   \halign{\hfil\strut##&\strut ##\hfil\cr
      \readtocfile
   \crcr}}%
   \pagebreak
   \global\backfalse
}

% #1 is the chapter name, #2 the chapter number, #3 the page number.
% 
\def\shorttocchapter#1#2#3{%
   \ifback\else#2\quad $\backslash$\quad\fi&#1\qquad 
   \raise3pt\hbox{\vrule height2pt width4pt depth2pt}$\,\,$#3\cr
}

% Yes, we read the entire contents (several pages) as one alignment.
% 
\def\contents{{%
   \firsttoctrue
   \backfalse
   \tocfonts
   \interlinepenalty = 100
   \halign{\hfil\strut##&\strut ##\hfil\cr
      \readtocfile
   \crcr}}%
   \pagebreak
   % We want to end the contents on a recto page, even if it's blank
   \ifodd\pageno\pagebreak\fi % leaves us on an even page.
   \global\backfalse
}

\newif\iffirsttoc

\def\tocchapterentry#1#2#3{%
   \iffirsttoc
      \global\firsttocfalse
   \else
      \noalign{\penalty-1000 \bigskip\smallskip}%
   \fi
   %
   \ifback\else\bf#2\quad $\backslash$\quad\fi
   &\bf#1\qquad\raise3pt\hbox{\vrule height2pt width4pt depth2pt}%
          $\,\,$#3\cr
   \noalign{\nobreak\vskip2pt}%
}

\def\tocsectionentry#1#2#3{%
   \noalign{\penalty-500 \vskip\medsmallskipamount}%
   &\it #1\quad \openbox$\,\,$\rm #3\cr
}

\def\tocsubsectionentry#1#2#3{%
   &\qquad #1\quad $\cdot\,$#3\cr
}

\def\openbox{\ht0 = 1.75pt \dp0 = 1.75pt \wd0 = 3.5pt
   \raise 2.75pt \makeblankbox{.2pt}{.2pt}%
}

\newif\ifback
% \ifback is true when we're doing the table of contents and are about
% to do the back matter.  It is also true just before we do the back matter
% chapters (really, only the index).
% 
\def\backmatter{\write\tocfile{\noexpand\setback}\backtrue}
\def\setback{\noalign{\bigskip\global\backtrue}}



% Macros for the examples chapter.
%
% \doexamples is called with the name of the examples file
% Each example is ended by ::: (including the last one)
% A line starting with ~ is executed in the output (without the ~)
% but dropped from the input.
% 
% Within the input, ! is an escape character, but {} are not recognized.
% This provides a limited control sequence capability, which is sufficient
% for delimited macros and therefore for cross-references (see \xrefdelim).
% !! stands for !.
% 
\def\endmark{:::}

\newif\ifnotatend  \newif\ifnotatendfile \newif\iftildeline
\newread\exfileA  \newread\exfileB  \newwrite\exfileC
\newcount\examplenumber

\def\doexamples#1{%
   % Here we assume that two read-only openings of the same file are OK.
   \immediate\openin\exfileA = #1
   \immediate\openin\exfileB = #1
   \loop
      \advance\examplenumber by 1
      \reader
      \ifx\holder\empty \notatendfilefalse \else \notatendfiletrue \fi
   \ifnotatendfile
      \dooneexample
   \repeat
}


% We want control sequences to be executed as the input of each example
% is formatted, but we don't want to execute them for the output of each
% example until we generate that output with an \input command.
% Therefore, we treat ! differently for \holder, which produces example
% input, and \holderA, which produces example output.
%
% We can't say \global\immediate\read, but \immediate is implied with \read.
% 
\def\reader{{\deactivate
   \catcode`\! = \other   % To execute control sequences on \input.
   \catcode`\^^M = 9     \global\read\exfileA to \holder
   %
   \catcode`\! = 0        % To execute control sequences right away.
   \obeyspaces \global\read\exfileB to \holderA
   }%
}

\def\dooneexample{{%
   % We want to mention \! in one of the examples:
   \edef\examplenum{\numbername\examplenumber}%

   \immediate\openout\exfileC = \tempfile

   \catcode`\| = \other   % No literal code in these examples.
   \chardef\! = `\! % !! means a literal ! character.


   % Collect the input page, as it is to be printed, in a box
   % At the same time, write out each line to \exfileC
   % We make the box 0pt tall to avoid problems with overfull pages.
   \setbox\xmpinput = \vbox to 0pt{%
      %
      \baselineskip = \codebaselineskip
      \loop
         \ifx\endmark\holder \notatendfalse \else\notatendtrue \fi
         \ifnotatend
            \expandafter\tildecheck\holder \empty \marker
               \iftildeline\else
               \leftline{\tt\frenchspacing \holderA \thinspace}%
               \immediate\write\exfileC{\holder}%
            \fi
            \reader
         \repeat
      \vss % reduce height to 0pt
      }% end \vtop

   \immediate\closeout\exfileC

   {%
      \maxdepth = \maxdimen % allow long input
      \vfill\eject
      \catcode`\! = 0
      \restoreplainTeX
      {%
        \let\eject = \relax \input\tempfile
        % Every example ends with \bye, but \bye is disabled in the main text.
        \vfill\par\penalty-10000
        \global\footline = {\hfil}%
      }%
      \box\xmpinput
   }%
}}

{
   \catcode `\~ = \other % So the \ifx works.
   \gdef\tildecheck#1#2\marker{%
      \ifx #1~%
         \immediate\write\exfileC {#2}\tildelinetrue
      \else
         \tildelinefalse
      \fi
   }
}

% This definition is more or less repeated verbatim in the first example
% in xmptext.tex.
% 
\def\xmpheader #1/#2{%
   {\exampletitlefonts \leftline{Example #1:\quad \bi#2}}%
   \vglue .5\baselineskip
   \count255 = \pageno
   \xdef\examplepage{\number\count255}%
   \markinfo{Example #1: #2}
   \ifrewritetocfile
      \write\tocfile{\string\tocsectionentry{#2}{}{\examplepage}}%
   \fi
}
% Let's number examples automatically; it makes it easier to move them
% around and add new ones.

\def\xmpnum{\number\examplenumber}

\newbox\xmpinput


% \negthin lets us put `\!' in examples.

\def\negthin{\ifmmode \mskip-\thinmuskip \else \char`\\ \char`\! \fi}

\def\xmpheaddef{see \xref{xmphead}}

\def\restoreplainTeX{%
   % Restore plain TeX's parameters (except for \hsize and \hoffset).
   \parindent = 20pt
   \parskip = 0pt plus 1pt
   \parfillskip = 0pt plus 1fil
   \hfuzz = 0.1pt
   \hbadness = 1000
   \abovedisplayskip=12pt plus 3pt minus 9pt
   \abovedisplayshortskip=0pt plus 3pt
   \belowdisplayskip=12pt plus 3pt minus 9pt
   \belowdisplayshortskip=7pt plus 3pt minus 4pt
   \everymath = {}%
   \everydisplay = {}%
   \centereddisplays
   \let\vfootnote = \@plainvfootnote
   \let\footnote = \@plainfootnote
   \let\tenrm = \oldtenrm
   \textfont0 = \tenrm
   \rm
   \ignorespaces
}%



% Macros for the concepts chapter.
% 
% 
% Start off the chapter.
% 
\def\beginconcepts{\openout\conceptfile = \jobname.ccs }
\def\endconcepts{\closeout\conceptfile}

\newwrite\conceptfile

% \concept produces a concept heading and also generates a crossreference
% suitable for the mini-index.  It even works for concepts with several words
% or containing control sequences like `\ascii'.
%
\def\concept#1 \par{%
   \par
   %k \cmdbreak
   \penalty\conceptpenalty\vskip\aboveconceptskip
   %k \vskip 0pt plus 1pt % allow a little more stretch
   \noindent
   % generate the index entry
   \ifconceptindex \else \global\indextoks = {\idxref{#1}}\fi
   \conceptindexfalse
   \pix\bix\the\indextoks
   %
   {\bt \let\it=\bti \unskip\null #1.\hskip1em plus.2em minus.2em }%
   \markinfo{#1}%
   \xrdef{#1}%
   \write\conceptfile{\string\doconcept{#1}{\number\pageno}}%
   \beginit{CONCEPT}%
   \nobreak
   \ignorespaces
}

\def\endconcept{%
   \par % always go to vertical mode here
   \eix\the\indextoks
   \endit{CONCEPT}%
   \ignorespaces
}

\def\doconcept#1#2{\hbox{#1\quad #2}}

% Sometimes we want to index a concept under some other name than the
% concept name, e.g., indexing `delimiter' as `delimiters'.  The
% \conceptindex macro lets us do this.
%
\newif\ifconceptindex
\newtoks\indextoks
\def\conceptindex#1{%
   \conceptindextrue
   \global\indextoks = {\idxref{#1}}%
   \ignorespaces
}


% Commands for cross-referencing within the concepts chapter.
% Each refterm has the form {a} or {a:b}, where b is the term to
% actually reference (e.g., \refterm{\PlainTeX:\plainTeX}).
% 
\def\refterm#1{%
   \reftermA #1:\endmark  % Parse the stuff.
   \expandafter\minrefsdelim\termtoref\endmark
   \relax % Cancel the \ignorespaces.
}%
\def\reftermA#1:{\reftermfirst{#1}\futurelet\next\reftermB}
\def\reftermB#1\endmark{\ifx\endmark \next \else \reftermsecond#1\fi}

\def\reftermfirst#1{#1\def\termtoref{#1}}
\def\reftermsecond#1:{\def\termtoref{#1}}%

% The defining sentence for a concept.
%
\def\defterm#1{{\it #1\/}}


% This macro prints the single page that will go on the back cover.
% 
\def\printconceptpage{%
   % Make sure this is considered an odd page.
   \ifodd\pageno\else\blankpage\fi
   \noheadlinetrue
   \advance\hsize by 2pc
   \vglue2pc % Plus a \topskip of 2pc.
   {\sectionfonts \leftline{List of concepts}}%
   \vskip\belowsectionskip
   {\conceptpagefonts
      \parindent=0pt
      \makecolumns 94/3:
      \input \jobname.ccs
      \vfil
      % Put the `logo' at the bottom of the page.
      \rightline{\thisbook}%
   }%
   \eject
}



% Macros for the commands chapters.
%
% \ifcommands is true when we're within \begindescriptions ...

\newif\ifcommands


% \begindescriptions should be called to start the actual control sequences.
%
\outer\def\begindescriptions{\beginit{DESCRIPTIONS}%
   % The following definitions are local to this chapter.
   % 
   \let\example = \commandexample
   \let\endexample = \endcommandexample
   \interlinepenalty = 50
   %
   \commandstrue
   \ignorespaces
}

% The \endgroup that \enddescriptions does must come after the page
% break, so the last page of descriptions will get a mini-index.
% 
\def\enddescriptions{%
   \vskip -\lastskip % undo the skip created by \enddesc
   \endit{DESCRIPTIONS}%
   \ignorespaces
}


% Begin or end the description of a control sequence or group thereof.
%
\def\begindesc{%
   \par % force vertical mode
   \saveskip = \lastskip % will be 0 if no skip
   \ifheading  % Did we just have \section or \subsection?
      \nobreak
   \else
      \cmdbreak
   \fi
   \combineskips\abovedescriptionskip
   \headingfalse
   \beginit{DESCRIPTION}%
   \beginit{COMMANDS}%
   % Each command name is set as a paragraph (for reasons I don't
   % remember, \leftline doesn't work because of the way the manuscript
   % was typed), and so \clubpenalty will be the penalty at the
   % interline glue (see p.96).
   \clubpenalty = \intercmdnamepenalty
   \parfillskip = 0pt plus 1fil
   \ignorespaces
}

\def\enddesc{%
   \nobreak % if we need a break, we'll get it from the next group opener
   \vskip\belowdescriptionskip
   \endit{DESCRIPTION}%
   \ignorespaces
}

% Begin the explanation of a control sequence.  Don't break at the
% space above the explanation, or the interline glue before the first line.
%
\def\explain{%
   \par
   \endit{COMMANDS}%
   \nobreak \vskip\explainskip
   \interlinepenalty = 50
   \nobreak \noindent
   \ignorespaces
}

% Here is how \example looks in the text:
% \example
%   ...
% |
% \produces
%   ...
% \endexample
%
% repeated an indefinite number of times.
% 
% We want to set the code of an example in a box so as to prevent it from
% being broken across pages.  By using \vtop we assure that the code is the
% right distance from the `Example:' line.  In order to keep the `produces:'
% the right distance from the last code line, we save the depth of that code
% line and then fool TeX into thinking that the \vtop has that depth by
% assigning it to \prevdepth.  If we didn't do this, the last line of the code
% would be too close to the `produces:' (as indeed it was in earlier versions
% of the book.
%
\newdimen\savedepth

{\makeactive|
\gdef\commandexample{% a.k.a. \example, inside \begindescriptions.
   \cmdbreak\vskip\exampleskip
   \leftline{\it Example:}%
   \nobreak % At the interline glue.
   \beginit{EXAMPLE}%
   \parfillskip = 0pt plus 1fil
   \hbox\bgroup\hskip\parindent\vtop\bgroup
      \begincs
      \let | = \endcode
      \advance\hsize by -\parindent
      \parindent = 0pt
      \bgroup\obeywhitespace
}}%

\def\endcode{%
   \egroup % end \obeywhitespace group
   \par\global\savedepth=\prevdepth
   \egroup % end inner \vbox
   \egroup % end outer \hbox
   \prevdepth = \savedepth
   \ignorespaces
}

% \dproduces should be used when the following material is a math
% display.
% 
\newif\ifexampledisplay
\def\dproduces{\global\exampledisplaytrue \produces}

\newif\ifproduces

% \produces puts its material into a vbox so it won't be broken.
% The material starts in VERTICAL MODE!  It uses the plainTeX conventions
% except that \parindent is 0pt.

\def\produces{%
   \producestrue
   \ifodd\pageno \par \nobreak \else \cmdbreak\fi
   \vskip\tinyskipamount
   \noindent {\it produces\ifexamplelog\ in the log\examplelogfalse\fi :}%
   \vadjust{\nobreak}% At the interline glue.
   \ifexampledisplay
      \centereddisplays
   \else
      \par\nobreak
      \advance\hsize by -\parindent
      \savedepth = \prevdepth
      \nointerlineskip
      \hbox\bgroup\hskip\normalindent
         \vtop\bgroup \restoreplainTeX \parindent = 0pt
         \prevdepth = \savedepth
   \fi
}%

% we need another ``produces'' form for when a command puts things in
% the log. In this case, the produces text also ends with a |.
%
\newif\ifexamplelog
{\makeactive|
\gdef\logproduces{\examplelogtrue\produces
   \begincs
   \def |{\endcode\producesfalse}%
   % Every line is set as a paragraph, so we get one \parindent for free.
   % But we also did \advance\leftskip in \produces, so now we have two.
   % We only want one.
   \advance\leftskip by -\parindent
   \bgroup\obeywhitespace
}}%

\def\nextexample{\endexample\interexampleskip\example}

\def\endcommandexample{%
   \par % force vertical mode, set previous paragraph
   \ifproduces \ifexampledisplay \global\exampledisplayfalse \else
      \global\savedepth = \prevdepth
      \egroup % Matches the \vtop in either the \produces or the \example.
      \egroup % Matches the \hbox in \producesbox.
      \global\producesfalse
      \par
      \prevdepth = \savedepth
   \fi\fi
   \endit{EXAMPLE}%
   \ignorespaces
}

\def\see{%
   \ifodd\pageno\nobreak\fi % don't put at the top of a verso page
   \vskip -\lastskip % should be \belowdescriptionskip
   \bigskip
   \noindent
    {\tenbi \spaceskip = 3.33pt plus 2pt minus 1.1pt
     \parfillskip = 0pt plus 1fil
     See also: %k \hskip 1em plus .5em minus .25em
    }%
    \ignorespaces
}%


\newif\ifxref \xreftrue

% \aux acts as a prefix to a \cts command, specifying that a
% cross-reference should not be generated.
% 
\def\aux{\xreffalse}

% So does \easy, which prints a hand, pointing at the control sequence.
% (The hand font doesn't define an em.)
% 
\newif\ifeasy
\let\easy = \easytrue 
\def\testeasy{\ifeasy\llap{\hand\ \kern 6pt}\easyfalse\fi}

% \cts typesets the beginning of a control sequence description, and
% generates an index entry and cross-reference definition for it.  The
% control sequence name must be delimited by a blank, since there may be
% parameters that follow.  The control sequence name can contain special
% characters; they are deactivated.  The initial \ must be omitted.
% 
\def\cts{\begingroup \deactivate \ctsA}
\def\ctsA#1 {\endgroup \ctsB{#1}}
\def\ctsB#1#2{%
   \ctsbasic{\\#1}{#2}%
   \ifxref \ctsxrdef{#1}\else \xreftrue \fi
   \pix\ctsidxref{#1}%
}

% \ctsx is like \cts, but separates the control sequence name and the
% text by more space. (`x' for `extra')
% 
\def\ctsx{\begingroup \deactivate \ctsxA}
\def\ctsxA#1 {\endgroup \ctsxB{#1}}
\def\ctsxB#1#2{%
   \ctsbasic{\\#1}{\quad #2}%
   \ifxref \ctsxrdef{#1}\else \xreftrue \fi
   \pix\ctsidxref{#1}%
}


% \ctscol is like \cts, but doesn't start a new paragraph.  It's used in
% in columns of cs's and their explanations.
%
\def\ctscol#1 #2{%
   {\bt \\#1}\quad #2%
   \ifxref \ctsxrdef{#1}\else \xreftrue \fi
   \pix\ctsidxref{#1}%
}

% \ctsbasic does the actual printing of a cs name.  It's needed on its
% own for `\ '.  It does not generate any index or cross-reference
% entries.  #1 is the command name, #2 some (possibly empty) text to go
% next to it.
% 
\def\ctsbasic#1#2{%
   \par
   \nobreak % At the \parskip glue the \noindent will produce.
   \noindent\testeasy {{\bt #1}\space #2}%
}

% \ctsxrdef generates a control sequence cross-reference definition.
% For example, `\ctsxrdef{@star}' generates a cross-reference definition
% for `\@star'.
% 
\def\ctsxrdef#1{\expandafter\xrdef\csname#1\endcsname}

% \ctsact prints an active character #1 and generates an index entry
% for it.  #1 is blank-delimited.  \ctsact does not generate a
% cross-reference definition.
% 
\def\ctsact{\begingroup \deactivate \ctsactA}
\def\ctsactA#1 {\endgroup
   \ctsbasic{#1}{}%
   \pix\ttidxref{#1}}

% \ctspecial prints a control sequence #1 and generates an index
% entry for it.  #1 is blank-delimited.  \ctspecial does not
% automatically generate a cross-reference definition, and so it's used
% for things like \newbox and \%.
%
\def\ctspecial{\begingroup \deactivate \ctspecialA}
\def\ctspecialA#1 {\endgroup
   \ctsbasic{\\#1}{}%
   \pix\ctsidxref{#1}%
}

% \ctspecialx is like \ctspecial, but leaves more space after its
% argument.  We want ` and ' to come from cmtt, instead of Optima, so we
% call \mapquotes before reading the argument.  This only affects the \`
% and \' descriptions.
% 
\def\ctspecialx{\begingroup \deactivate \mapquotes \ctspecialxA}
\def\ctspecialxA#1 {\endgroup
   \ctsbasic{\\#1}{}\quad
   \pix\ctsidxref{#1}%
}

% \ctsdisplay has a blank-delimited argument consisting of a control
% sequence such as alpha.  It produces $\alpha$ followed by \alpha.
% 
\def\ctsdisplay#1 {\basicdisplay {$\csname #1\endcsname$}{\\#1}%
   \ifxref\ctsxrdef{#1}\else\xreftrue\fi   \pix\ctsidxref {#1}}

% \ctsdoubledisplay has a blank-delimited argument consisting of a
% control sequence such as bigvee.  It produces $\bigvee$ and
% $\big\bigvee$ followed by \bigvee.
% 
\def\ctsdoubledisplay#1 {
   {%
      \symbolspace = 42pt
      \basicdisplay{$\csname #1\endcsname\quad
                     \displaystyle\csname #1\endcsname$\ddstrut}%
                   {\\#1}%
   }%
   \ifxref\ctsxrdef{#1}\else\xreftrue\fi
   \pix\ctsidxref{#1}%
}
\def\ddstrut{\vrule width0pt height15pt depth11pt}

% \ctsydisplay displays a control symbol.  #1 is a single character,
% which may be active.  #2 is the cross-reference label,
% blank-delimited.
% 
\def\ctsydisplay{\begingroup \deactivate\catcode`\|=\other \ctsydisplayA}
\def\ctsydisplayA#1 #2 {\endgroup
   \basicdisplay{$\csname\string#1\endcsname$}{\\#1}%
   \ifxref \ctsxrdef{#2}\else \xreftrue \fi
   \pix\ctsidxref{#1}%
}

% \actdisplay displays an active character. #1 is the character, and
% #2 is the cross-reference label, blank-delimited.
% 
\def\actdisplay{\begingroup\catcode `\|=\other\actdisplayA}
\def\actdisplayA#1 #2 {\endgroup
   \basicdisplay{$#1$}{\string#1}%
   \ifxref \xrdef{#2}\else \xreftrue \fi
   \pix\ttidxref{#1}%
}

% \basicdisplay does the actual typesetting of a control sequence name.
% for inside displays.
% 
\def\basicdisplay#1#2{\testeasy\hbox to \symbolspace{#1\hfil}{\bt #2}}

% Printing parameter and table entry headings.
%
\def\param#1{\printparam{#1}{parameter}}
\def\tblentry#1{\printparam{#1}{table entry}}
\def\printparam#1#2{\hskip1.5em [\kern3pt \<#1> #2\kern2pt]}

% Required braces.
%
\def\rqbraces#1{\{\hskip2pt#1\hskip2pt\}}

% Printing rulers.
% 
\def\1{\vrule height 0pt depth 2pt}
\def\2{\vrule height 0pt depth 4pt}
\def\3{\vrule height 0pt depth 6pt}
\def\4{\vrule height 0pt depth 8pt}
\def\ruler#1#2#3{{$\vcenter{\hrule\hbox{\4#1}}\,\,\rm#2\,{#3}$}}
\def\doruler{\par \noindent\ruler}
\def\tick#1{\hbox to .125in{\hfil#1}}
\def\8{\tick\1\tick\2\tick\1\tick\3\tick\1\tick\2\tick\1\tick\4}

% Macros for the capsule summary chapter.
% 
\def\begincapsum{\beginit{CAPSULE SUMMARY}%
   \let\bt = \tentt
   \bigskip
}

\def\endcapsum{\endit{CAPSULE SUMMARY}}

\newbox\@primitivebox \setbox\@primitivebox = \hbox{\tt *}
\newif\ifcs

\def\capline{\begingroup \deactivate\catcode `\| = \other \caplineA}
\def\caplineA#1 {\endgroup
   \begingroup
      \catcode `@ = \letter % for constructing labels
      \caplineB{#1}%
}

% Parameters of \caplineB:
%   #1 name of control sequence
%   #2 description
%   #3 * or empty
%   #4 xref or xref1:xref2 or empty

\def\caplineB#1#2#3#4{%
   \ifempty {#4}\temptrue\else\tempfalse\fi
   % \iftemp needed to avoid \if ... \else ... \fi nesting problems
   \ifcs
      \toks0 = {\caplineout{\\#1}{#2}{#3}}%
      \iftemp
         \toks1 = \expandafter{\csname #1\endcsname}%
      \else
         \toks1 = {#4}%
      \fi
      \edef\nextaction{\the\toks0 {\the\toks1}}%
      \nextaction
      \ctsidxref {#1}%
   \else
      % The \space makes one-character entries line up nicely.
      \caplineout{\space #1}{#2}{#3}{#4}%
      \ttidxref {#1}%
   \fi
   \endgroup
}

\newif\iftemp


% In a few cases we have two cross-references for a single control
% sequence.
%
\newif\ifcstwo

\def\capac{\cstwofalse\csfalse\capline}
\def\capactwo{\cstwotrue\csfalse\capline}
\def\capcs{\cstwofalse\cstrue\capline}
\def\capcstwo{\cstwotrue\cstrue\capline}

% \caplineout produces an output line (or several lines) for the capsule
% summary.  #1 is the command text, #2 is the description, #3 is either * or
% empty, and #4 is the cross-reference label.
% 
\def\caplineout#1#2#3#4{%
   \setbox0 = \ifempty {#3}\box\voidb@x \else \copy\@primitivebox\fi
   \vskip\intercapsuleskip
   % If we use \vbox here, a multi-line summary at the top of a page
   % will cause \topskip to disappear.
   % 
   \vtop{\noindent \hangindent = \capsulehangindent
      \spaceskip = 3.33pt plus 2pt minus 1.5pt
      \rightskip = 0pt plus 4em % a little more stretch
      \parfillskip = 0pt plus 1fil
      \llap{\box0}{\bt #1}% Bold typewriter for the cs name.
         \quad \hskip 0pt plus 1pt minus 1pt
         #2\unskip\ 
         (\ifcstwo \tworefs #4:\else \xref{#4}\fi)%
   }%
   \par
}

\def\tworefs#1:#2:{\xref{#1}, \xref{#2}}



% Macros for printing the index.
% 
% Set up to print it.
% 
\def\beginindex{%
   \doublecolumns
   \beginit{THE INDEX}
      \markinfo{\chaptername}%
      \indexfonts
      \parindent = 0pt
      \def\pp##1{{\it ##1}} % Principal entry.
      \def\c{,\thinspace\allowbreak}%
      \def\ic{,\quad}
      \def\see##1{.\quad{\it See} ##1 }
      \def\seealso##1{\hfil\break{\it See also} ##1 }
      \let\r = \romannumeral
      
      \raggedright
}

\def\endindex{\endit{THE INDEX}\singlecolumn}


% #1 is the level of this index entry minus 1 (i.e., 0 for a main
% entry), #2 is the index term, #3 is the kind of term
% (T for ttfont, C for control sequence, N for normal), and
% #4 is the list of pages.  The page list can have \pp (principal
% entry)in it, and each page is separated by \c.
% 
\def\indexentry#1#2#3#4{%
   \beginit{INDEX ENTRY}%
      \leftskip = #1\indexpageindent
      \par
      \leavevmode
      \hangindent = \indexlevelindent
      \ifx #3T%
         {\tt #2}% Typewriter.
      \else \ifx #3C%
         {\tt \llap{\\}#2}% Control sequence.
      \else
      % in normal entries, \b and \e enclose a group. ({ and } don't work.)
         {\let \b = \bgroup \let \e = \egroup #2}%
      \fi\fi
      #4% The list of pages.
      \par
   \endit{INDEX ENTRY}%
}

% Nah, let's forget printing the initial.
% 
\def\indexgroup#1{%
  \bigskip
}



% Code formatting.
% 
% 
% Turn off normally special characters.
% 
\def\deactivate{%
   \catcode`\\ = \other   \catcode`\{ = \other   \catcode`\} = \other
   \catcode`\$ = \other   \catcode`\& = \other   \catcode`\# = \other
   \catcode`\% = \other   \catcode`\~ = \other   \catcode`\^ = \other
   \catcode`\_ = \other
}

% It is convenient to have |...| mean print the ... verbatim, except for !.
% (But | should just be a vertical bar in math mode.)  This should be
% used only for inline code; returns inside |...| become spaces.
% 
\catcode`\| = \active
\def|{%
   \ifmmode
      \vert
   \else
      \begingroup
         \obeyspaces
         \begincs
         \let| = \endgroup
   \fi
}

% \csdisplay is similar, but it inserts glue before and after.
% It also is ended by |, so we have to redefine that.
% 
\def\csdisplay{%
   \par
   \nobreak % don't break above displays
   \vskip\abovedisplayskip
   \begingroup
      \interlinepenalty = 10000
      \obeywhitespace
      \begincs
      \def|{\endgroup\vskip\belowdisplayskip \noindent\ignorespaces}%
}

% \begincs does the setup for verbatim printing.  It does not confine
% its effects to a group.
% 
\def\begincs{%
   \hfuzz = \codefuzz
   \parfillskip = 0pt plus 1fil
   \parskip = 0pt % don't stretch interparagraph space within code displays
   \catcode`\! = 0
   \let\! = \exclam
   \let\| = \verticalbar
   \let\$ = $%
   \let\. = \empty  % Use !. to end a control sequence to be executed.
   \def\-{\discretionary{-}{}{}}% but allow explicit discretionary hyphens
   \tt \deactivate
}


\chardef\exclam = `\!
\chardef\verticalbar = `\|

% In math mode we want vertical bars and exclamation points to be
% regular characters again.
% 
\everymath = {\setmathchars}
\everydisplay = {\setmathchars}
\leftdisplays

\def\setmathchars{%
   \catcode`\| = \other  \catcode`\! = \other
   \let\{ = \lbrace  \let\} = \rbrace
}




% Some miscellanous macros.
% 
\def\anatomy{anatomy of \TeX}
\def\ascii{{\ninerm ASCII}}
\def\asciichar#1{$\langle \rm #1\rangle$}
\def\bblfile{{\tt .bbl} file}
\def\bibfile{{\tt .bib} file}
\def\bstfile{{\tt .bst} file}
\def\didotpt{did\^ot point}
\def\dvifile{{\tt .dvi} file}
\def\em{\thinspace {\rm em}}
\def\emph#1{{\it #1}\itcorr}  % Emphasize.
\def\ftp{{\tt ftp}}
\def\gffile{{\tt .gf} file}
\def\hand{{\handfont A}}
\def\ifatest{{\tt \\if} test}
\chardef\inches = "7D
\def\knuth#1{#1 of \texbook}
\let\Metafont = \MF
\def\Mperiod.{$M$\kern-1.6pt.}
\def\Mprimecomma,{$M'$\kern-3.5pt,}
\def\Mprimeperiod.{$M'$\kern-2.5pt.}
\def\mud{\thinspace {\rm mu}} % can't use \mu; it'a a Greek letter!
\def\newTeX{new \TeX}
\def\p{p.\thinspace}
\def\pkfile{{\tt .pk} file}
\def\plainTeX{plain \TeX}
\def\PlainTeX{Plain \TeX}
\def\pp{p\p}
\def\pt{\thinspace {\rm pt}}
\def\pxlfile{{\tt .pxl} file}
\def\tequiv{\unskip $\>\equiv\>$} % equivalence in text
\def\texbook{{\sl The \TeX book}\itcorr}
\let\tex@ = \TeX
\def\TeX{\tex@\null}
\def\TeXMeX{\TeX\ M\kern-.11em\lower .5ex\hbox{E}\kern-.125em X\null}%
\def\tfmfile{{\tt .tfm} file}
\def\thisbook{{\sl \TeX\ for the Impatient\/}}
\let\ths = \thinspace
\def\tminus{\unskip\allowbreak $\>-\>$\allowbreak} % minus in text
\def\tplus{\unskip\allowbreak $\>+\>$\allowbreak} % plus in text
\def\TUG{\TeX{} Users Group}
\def\Vcomma,{$V$\kern-2pt,}
\def\visiblespace{{\tentt \char'040}}
\def\Vperiod.{$V$\kern-2pt.}
\let\vs=\visiblespace
\def\xrefpg#1{page~\xrefn{#1}}

% \tighten attempts to shorten the number of lines occupied by a paragraph.
\def\tighten{\looseness=-1
   \spaceskip = .9\fontdimen2\font plus \fontdimen3\font
      minus 1.1\fontdimen4\font
}

% \itcorr can be used at the end of a macro that puts its argument in
% italics in order to produce an italic correction just when it's needed.
% It won't look inside a following macro call, however.

\def\itcorr{\futurelet\next\itcorrA}
\def\itcorrA{\ifx.\next\else\ifx,\next\else\/\fi\fi}


% Arrange N items in three columns.
% A right brace is needed at the end of the list to match the \bgroup.
% 
\def\threecolumns{\nobreak\vskip\abovedisplayskip\dothreecolumns}

\def\dothreecolumns#1 {\bgroup
   \parindent = 0pt
   \makecolumns #1/3:
}

% We don't want to make < an active character because then it cannot be used
% in \ifnum tests.  So, \<foo> denotes a nonterminal `foo'.
% 
\def\<#1>{$\langle${\rm\it \kern-.2pt #1\kern.65pt}$\rangle$}

\let\beginit = \environment
\let\endit = \endenvironment

\def\eatpar#1\par{}

% \needspace breaks out the page if there's less than #1 left on it.

\def\needspace#1{%
   \saveskip = \lastskip
   \par % force vertical mode
   \vfil
   \penalty 1000
   \vskip #1
   \penalty9999
   \par % exercise the page builder
   \vskip -#1 plus -1fil
   \vskip -\saveskip \vskip \saveskip % to restore \lastskip
}
   



% Expanded cross-referencing for various parts of the books.
% 

% Sometimes it is clearer to refer to a cross-reference as a control
% sequence.
% 
\def\ctsref{\begingroup \catcode`\@ = \letter \@ctsref}
\def\@ctsref#1{(\xref{#1})\endgroup}

\def\xrefdelim[#1]{page~\xrefn{#1}} % this form doesn't need braces

% This command comes at the beginning of chapters, after the \chapter
% command and before the text.  Hence the \par in the template
% and the \noindent
% 
\def\chapterdef#1#2\par{%
   \@writeaux{%
      \string\gdef\expandafter\string
         \csname#1_C\endcsname{\the\chapterno}}%
   \noindent
}

\def\chapternum#1{%
   \def\csn{#1_C}%
   \expandafter\ifx\csname\csn\endcsname \relax
      \expandafter\def\csname\csn\endcsname{`#1'}%
      \ifxrefwarning
         \message{Undefined chapter `#1'.}%
      \fi
   \fi
   \csname\csn\endcsname
}

\def\chapterref#1{Section~\chapternum{#1}}

\def\headcit#1#2{``{\rm #1}'' (\xref{#2})}

\def\conceptcit#1{\headcit{#1}{#1}}

\def\seeconcept#1{(see ``{\rm #1}'', \xref{#1})}




% Special types of pictures.
% 
% Glue pictures:
% 
\newdimen\glueboxwidth
\newdimen\boxdepth  \boxdepth = 3.5pc
\newskip\underlabel  \underlabel= .1\boxdepth % space under `width n'.
\def\squeezeglue{\glueboxwidth = .725\glueboxwidth}

\def\labelledbox#1 #2 #3{\vtop{%
   \hrule
   \hbox{%
      \vrule
      \hbox to #1{\hfil \vbox to #2{\vfil#3\vskip\underlabel}\hfil}%
      \vrule
   }%
   \hrule
}}%

% Make a picture of a box.
% 
\def\picbox#1 {%
   \glueboxwidth = #1pc \squeezeglue
   \vtop{%
      \hbox to \glueboxwidth{\strut \hfil {\it box}\hfil}%
      \labelledbox % Have to have spaces after the arguments.
         {\glueboxwidth}
         {\boxdepth}
         {\halign{\hfil##\hfil\cr width #1\cr}}%
    }%
}

% And of glue.
% 
\def\gluebox#1 #2 #3 #4 {\vtop{%
   \glueboxwidth = #4pc \squeezeglue
   \hbox to \glueboxwidth{\strut \hfil {\it glue}\hfil}%
   \nointerlineskip
   \kern2pt % to move the brace down a bit
   \hbox{$\overbrace{\hbox{\hskip\glueboxwidth}}$}%
   \kern-3pt % The \overbrace puts in 3pt below itself.
   \nointerlineskip
   \vbox to \boxdepth{%
      \hsize = \glueboxwidth
      \vskip 2pt
      \advance\baselineskip by -2pt
      \centerline{\strut size #1}%
      \centerline{stretch #2}%
      \centerline{shrink #3}%
      \centerline{width #4}%
      \vss
   }%
   \kern 1.5pt % I don't know why this is needed.
   \nointerlineskip
   \hbox{$\underbrace{\hbox{\hskip\glueboxwidth}}$}%
}}

\def\gluepicture#1 #2{{\ninerm
   \medskip 
   \vtop{%
      \setbox0 = \hbox{#2}% The glue and box pictures.
      \glueboxwidth = \wd0
      \leftline{\box0}%
      \kern 6pt
      \hbox to \glueboxwidth{\leftarrowfill{ width #1 }\rightarrowfill}%
   }%
   \medskip
}}

% Box pictures.
% 
% Set up a `reference point' and the macro for a labelled height, for use
% in forming pictures of boxes.
% 
\newbox\refpoint

\setbox\refpoint = \vbox to 0pt{%
   \kern-2.6pt
   \hbox to 0pt{\kern-2.2pt $\bullet$\hss}
   \vss
}%
   
\def\labelledheight#1#2{%
\vtop to #1{\offinterlineskip
   \setbox0=\hbox{#2}\skip0=\wd0
   \hbox to \skip0{\hss\tenex\char"78\hss}\kern-4pt
   {\cleaders\hbox to \skip0{\hss\tenex\char"3F\hss}\vfil}%
   \vskip1pt\box0\vskip1pt
   {\cleaders\hbox to \skip0{\hss\tenex\char"3F\hss}\vfil}%
   \kern -6pt\boxmaxdepth 0pt\hbox to \skip0{\hss\tenex\char"79\hss}}}



% Paul's updates -- no longer needed; we have converged.
% 
%\input paulmacs

% Read the cross-reference definitions.
% 
\readauxfile

\catcode`\@ = \other  % Make @ an `other' character again.
\catcode`\^ = \active % Make ^'s do indexing outside of math mode.