summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/cjw/cjw-latex.dtx
blob: 515dd7d3d0b7078ba402cdc5feb30712552e3268 (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
% \iffalse -*- LaTeX -*-
%
%   This is file `cjw-latex.dtx'.  You can run this file through
%   LaTeX2e to produce a DVI file of documentation.  The file
%   `cjw-latex.ins' should have come with this file.  Run it through
%   (La)TeX to extract the bundled macro files.
%
% \fi
\def\RCSinfo{$Id: cjw-latex.dtx,v 0.13 1998/09/01 15:54:20 cwynne Exp $}

\def\RCSsplit $#1: #2,v #3 #4 #5 #6 #7${
  \gdef\filename   {#2}
  \gdef\fileversion{#3}
  \gdef\filedate   {#4}
  \gdef\filetime   {#5}
  \gdef\fileauthor {#6}
  \gdef\filelocker {#7}}

\expandafter\RCSsplit\RCSinfo
%%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%  \CheckSum{0}
%
% \iffalse
%<*driver>

\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{cjw-latex.dtx}
    [\filedate\space v\fileversion\space
     Personal macros for LaTeX2e---CJW]

\documentclass{ltxdoc}
  \usepackage{cjwmacro}
    % We need math---call it with all options to make sure they work.
  \usepackage[derivs,integrals,physics]{cjwmath}

\GetFileInfo{cjw-ltr.dtx}
\EnableCrossrefs         
% \DisableCrossrefs     % Say \DisableCrossrefs if index is ready
% \OnlyDescription      % Comment out for implementation details
\RecordChanges

\begin{document}
  \DocInput{cjw-latex.dtx}
\end{document}
%</driver>
% \fi
%
% \DeclareRobustCommand{\cseq}[1]{\texttt{\bslash#1}}
% \DeclareRobustCommand{\pkg} [1]{\textsf{#1}}
% \DeclareRobustCommand{\env} [1]{\textsf{#1}}
%
% \renewcommand{\thefootnote}{\fnsymbol{footnote}}
%
% \title{The \pkg{cjw-latex} Macro Collection\thanks{%
%   This file has version \fileversion{} as of \filedate.}}
% \author{Colin J.~Wynne\thanks{E-Mail at:
%   \texttt{cwynne@mts.jhu.edu}, \texttt{cwynne@jhu.edu}\,.}}
% \date{\filedate}
%
% \maketitle
%
% \setcounter{StandardModuleDepth}{1}
%
% {\parskip 0pt         ^^A % This is the hack used by |doc.dtx|.
%                       ^^A % (bug in \LaTeX?)
%  \tableofcontents
% }
%
% \section*{Introduction}
%
% I have been a \TeX{} user for quite a long time now.  It was in my
% junior year in college, in 1992, that one of my friends and one of
% my math professors decided to warp my perception of reality and
% introduce me to Dr.~Knuth's wonderful creation.  In those days,
% Plain-\TeX{} was the tool of choice, we coded everything ourselves
% from primitives on up, logical markup was unknown, and \LaTeX{} was
% known as Lame-\TeX.  During my senior year I wrote an honors thesis
% in mathematics which required quite a lot of things not present in
% standard Plain-\TeX.  My macro files grew, and grew, and\dots
%
% In the year following my graduation, I converted myself to \LaTeX{},
% mostly because of the convergence my own personal modified
% ePlain/NFSS1/Plain format was having towards \LaTeX{} in terms of
% logical markup.  Most of macros were easily converted into
% \LaTeX{}-ese.  They got more complicated from there.
%
% So now I regularly write up papers, letters, mathematical problem
% sets, and just about anything else that uses the English language,
% in \LaTeX.  The macros have evolved quite a bit.  More has been
% added.  I took to using the |dtx| format for most of my input files,
% and finally decided to wrap my big three up into a single documented
% source file.
%
% I hope that these macros will prove useful to somebody out there,
% and if they do, feel free to buy me a beer next time you see me.  I
% have other |dtx| files available, including a modified \pkg{letter}
% class which also does German formal letters, and a package for doing
% outlines.  Any package of mine should be identifiable on your
% friendly neighborhood CTAN site with a name like
% \verb+cjw*.(dtx|ins)+.
%
% \section{General macros}
%
% \iffalse
%
\NeedsTeXFormat{LaTeX2e}
%<general>\ProvidesPackage{cjwmacro}
%<math>\ProvidesPackage{cjwmath}
%<deriv>\ProvidesFile{cjwderiv.tex}
%<integ>\ProvidesFile{cjwinteg.tex}
%<phys>\ProvidesFile{cjwphys.tex}
%<units>\ProvidesFile{cjwunits}
    [\filedate\space v\fileversion\space
%<general>     Personal macros for LaTeX2e---CJW]
%<math>     Math macros for LaTeX2e---CJW]
%<deriv>     Derivative macros for cjwmath.sty---CJW]
%<integ>     Integration macros for cjwmath.sty---CJW]
%<phys>     Physics macros for cjwmath.sty---CJW]
%<units>     Typesetting units in LaTeX2e---CJW]
%
%<*general>
%
%\fi
%
% I tend to organize my package files as follows---first come flow
% control structures for the package itself, usually in the form of
% new conditionals; then come the options; then comes the meat of the
% package in some sort of vaguely thought out order.  This package is
% no exception.  
%
% \subsection{Package initialization}
%
% Conditionals are usually used in conjunction with package options to
% provide conditional inclusion of certain code, either \emph{via} an
% \cseq{if}\dots{}\cseq{endif} block or using class options.  For this
% package, the subsystem in question is the inclusion of verbatim
% typeset files.
%    \begin{macrocode}
\newif\if@verbext       \@verbextfalse
%    \end{macrocode}
% Not surprisingly, this conditional is used directly by an option.
%    \begin{macrocode}
\DeclareOption{verbext}{\@verbexttrue}
%    \end{macrocode}
% I used to use options for the loading of additional packages.  In
% particular, when I used \pkg{psfig.new} which could not be handled
% as a \LaTeXe{} package, I did this.  Now that I use the \pkg{epsfig}
% package that comes with \LaTeXe, I simply issue a warning to
% include the package separately.
%    \begin{macrocode}
\DeclareOption{psfig}{%
  \PackageWarning{cjwmacro}%
    {Obsolete option \CurrentOption.  Use package `epsfig' instead.}}
%    \end{macrocode}
% Since, however, using \pkg{pstricks} requires several files, I still
% use a package option to take care of all of that.  This option
% checks for the existence of \emph{both} files before including
% either, hence the nested calls to \cseq{InputIfFileExists}.  A
% similar option is used for \pkg{pst-plot.tex}, since is not
% implemented as a package file.
%    \begin{macrocode}
\DeclareOption{pstricks}{%
  \InputIfFileExists{pstricks.sty}{%
  \InputIfFileExists{pst-node.tex}{}{%
    \PackageError{cjwmacro}{File `pst-node.sty' not found.}{}}}%
   {\PackageError{cjwmacro}{File `pstricks.sty' not found.}{}}}

\DeclareOption{psplot}{\InputIfFileExists{pst-plot.tex}{}{%
  \PackageError{cjwmacro}{File `pst-plot.tex' not found.}{}}}
%    \end{macrocode}
%
% The next two options are used to change behavior of some macros on
% draft as opposed to final copies.  Currently, only \cseq{ssbreak}
% has such a dependency, and in final form it uses the PS-Tricks
% package to typeset a nice section delimiter.  Note the use of
% \cseq{ExecuteOption} by the \pkg{final} option to make sure that
% PS-Tricks is, indeed, available.
%    \begin{macrocode}
% What to do for draft vs. final copy.
\DeclareOption{draft}{%  
  \def\ssbreakbar{\hbox to 2in{\hrulefill}}}
\DeclareOption{final}{%
  \ExecuteOptions{pstricks}  
  \def\ssbreakbar{%
    \psset{linewidth=0.4pt,unit=1in}%
    \pspicture(-2.5,-0.15)(2.5,0.15)%
      \qdisk(0,0){0.04}%
      \qdisk(0.33,0){0.02}%
      \qdisk(-0.33,0){0.02}%
      \pspolygon*(0.33,-0.02)(0.33,0.02)(1.75,0)%
      \pspolygon*(-0.33,-0.02)(-0.33,0.02)(-1.75,0)%
    \endpspicture}}
%    \end{macrocode}
%
% To finish off option handling, we declare a default (warn about
% unknown options), execute defaults, and process the passed option
% list. 
%    \begin{macrocode}
\DeclareOption*{%
  \PackageWarning{cjwmacro}{Unknown option `\CurrentOption'}}
\ExecuteOptions{draft}
\ProcessOptions
%    \end{macrocode}
%
% \subsection{General definitions}
%
% These general definitions set up some `meta-macros', to be used by
% other commands.
%
% One of the things I liked a lot about \TeX{} was the use of
% \cseq{let} to make aliases for existing commands without
% sacrificing much of the control sequence space.  In the spirit of
% \LaTeXe, however, I have implemented this thrice with name
% checking.  Analogously to the \cseq{newcommand}-like macros, we
% offer the following three:
%    \begin{macrocode}
\newcommand{\alias}       [2]{\@ifdefinable #1{\let #1 #2}}
\alias\realias\let
\newcommand{\providealias}[2]{\@ifundefined #1{\let #1 #2}}
%    \end{macrocode}
% Usage is, for example,
%   \begin{display}{l}
% \cseq{alias}\cseq{foo}\cseq{bar}
%   \end{display}
% which makes \cseq{foo} an alias for \cseq{bar}.  As expected,
% \cseq{alias} only works if the new name is currently undefined and
% \cseq{providealias} does nothing if its first argument is already
% defined.  Somewhat more lax than its counterpart
% \cseq{renewcommand}, \cseq{realias} does not care if its first
% argument is defined or not.  In essence, that command is used to
% unconditionally alias a command.  This is why, oddly enough,
% \cseq{realias} is itself just an alias of \cseq{let}.  Is this
% getting confusing yet?
%
% Next we input wholesale a few useful packages.  These are still in
% the spirit of meta-macros which define this section.  The first
% package, \pkg{amstext}, provides the \cseq{text} command, which
% basically puts its argument in text mode inside a box, but in the
% current style (textstyle, scriptstyle, etc.).  This is used later
% on.  The \pkg{xspace} package is used for control sequences which
% would encounter `the space problem' when expanded as is.
%    \begin{macrocode}
\RequirePackage{amstext}
\RequirePackage{xspace}
%    \end{macrocode}
% The command \cseq{intertext} from the \pkg{amsmath} package is quite
% useful, but I do not want to include that entire package unless it
% is necessary.  Therefore, I make sure that command is defined one
% way or another.  I also give it the alias \cseq{rem} since I am
% somewhat nostalgic about ancient forms of \textsf{\small BASIC}\dots{}
%    \begin{macrocode}
\providecommand{\intertext}[1]{\noalign{%
  \penalty\postdisplaypenalty\addvspace{ 0.5\belowdisplayskip}
  \vbox{\normalbaselines\noindent#1}%
  \penalty\predisplaypenalty\addvspace{0.5\abovedisplayskip}}}
\alias\rem\intertext
%    \end{macrocode}
%
% Next we define some font style names which will be used in some
% contexts later.  This is done to avoid hard-coding of certain styles
% and to allow as much customization as possible.
%    \begin{macrocode}
\providecommand{\pagenofont}    {\normalfont}
\providecommand{\declarefont}   {\normalfont\bfseries\mathversion{bold}}
\providecommand{\altdeclarefont}{\normalfont\itshape}
\providecommand{\captionfont}   {\normalfont\itshape}
\providecommand{\examplefont}   {\normalfont}
\providecommand{\altexamplefont}{\normalfont\itshape}
\providecommand{\labelfont}     {\normalfont\bfseries\mathversion{bold}}
\providecommand{\timelinefont}  {\normalfont}
\providecommand{\titlefont}     {\normalfont\bfseries\Large\mathversion{bold}}
\providecommand{\verbatimfont}  {\normalfont\ttfamily}
%    \end{macrocode}
%
% The next few commands are for programming convenience.  First we
% want to be able to swap the definitions of two control sequences.
%    \begin{macrocode}
\newcommand{\swapdef}[2]{{%
         \let \@tempa #1\relax
  \global\let #1      #2\relax
  \global\let #2      \@tempa}}
%    \end{macrocode}
% We also want to be able to do the same for lengths (or glue or
% whathaveyou).
%    \begin{macrocode}
\newcommand{\swapdim}[2]{{%
         \@tempdima #1\relax
  \global #1        #2\relax
  \global #2        \@tempdima}}
%    \end{macrocode}
% Next is a macro constructed from an exercise in \emph{The
% \TeX{}book}, which takes three control sequences and expands them in
% reverse order.
%    \begin{macrocode}
\newcommand{\expandthree}[2]{%
  \expandafter\expandafter\expandafter #1\expandafter #2}
%    \end{macrocode}
%
% This next macro is modified from code I received in the
% |comp.text.tex| newsgroup.  According to the e-mail in which I
% received it, the original source is a set of macros for
% \emph{TUGboat}.  It turns a number into an ordinal, finding the
% correct ordinal label which is set as a superscript.
%    \begin{macrocode}
\newcommand{\nth}[1]{{%
  \@tempcnta = #1\relax
  \ifnum \@tempcnta < 0\relax           % Make sure our number is
    \@tempcnta = -\@tempcnta            %   non-negative.
  \fi
  \ifnum \@tempcnta < 14\relax          % Deal first with the 
    \ifnum \@tempcnta > 10\relax        %   exceptions for 
      \def\@tempa{th}                   %   11, 12, and 13.
    \fi
  \else
    \loop \ifnum\@tempcnta > 9\relax    % Loop until the recursive
      \@tempcntb = \@tempcnta           %   remainder (mod 10) is
      \divide  \@tempcntb by  10\relax  %   a single digit in order
      \multiply\@tempcntb by  10\relax  %   to successfully satisfy
      \advance \@tempcnta by -\@tempcntb%   the ordinality test.
    \repeat
    \def\@tempa{\ifcase\@tempcnta       % Figure the proper label:
              th%                       %   0th
        \or   st%                       %   1st
        \or   nd%                       %   2nd
        \or   rd%                       %   3rd
        \else th%                       %   nth
      \fi}
  \fi
  #1\ensuremath{^{\text{\@tempa}}}}}    % Superscript the label in
                                        %   math mode.
%    \end{macrocode}
%
% Continuing in the vein of superscripts, we define two macros which
% put their arguments as sub- and superscripts in script-script
% style.  This was motivated by such things as derivative indices
% which look just plain ugly in script style.
%    \begin{macrocode}
\alias\sst\scriptscriptstyle
\newcommand{\ssp}[1]{^{\sst#1}}
\newcommand{\ssb}[1]{_{\sst#1}}
%    \end{macrocode}
%
% We now come to some very important and necessary macros, namely the
% creation of typeset sideways \textsf{\small ASCII} smiley
% faces. \smiley  Since I like to be as general as possible, I have
% also written  an \cseq{emote} macro for indicating
% emotions. \emote{smirk} 
%    \begin{macrocode}
\newcommand{\smiley}[1][\@smiley]{%
  \edef\@sf{\spacefactor=\the\spacefactor}%
  \unskip\spacefactor=1000\relax\space #1\@sf\xspace}
\newcommand{\@smiley}{%
  {\ttfamily\raise 0.078em\hbox{:}\kern-0.1em{-}\kern-0.1em{)}}}
\newcommand{\emote}[1]{%
  \smiley[\ensuremath{\langle}\emph{#1}\ensuremath{\rangle}]}
%    \end{macrocode}
%
% Since I learned the good habit of doing so at Washington and Lee, I
% often append pledges to my assignments.  The generic pledge is
% implemented as an environment.  It formerly took an argument, the
% date, but I decided that was superfluous, seeing as how the
% assignment headers set the date once.  Why risk inconsistency?  Much
% to my surprise, I found out that \LaTeXe's \cseq{maketitle} command
% unsets not only the date holder, but also the command which is used
% to set the date in the first place.  Anyhow, this means that the
% date \emph{does} need to be set, but I have left that to be done by
% the headers.  The \env{pledge} environment issues a warning if the
% date is not set.
%    \begin{macrocode}
\newenvironment{pledge}%
  {\ifx\@empty\@date
      \PackageWarning{cjwmacro}{Date is not set.}
   \fi
   \parskip=2pt \parindent=0pt\relax
   \null\vfill\begin{flushright}
     \itshape\small}
  {\\[5ex]\normalfont\footnotesize
     \makebox[2in]{\hrulefill}\quad\@date\\
     \makebox[2in]{Colin J.~Wynne}\quad{\hphantom{\@date}}\\
   \end{flushright}}
%    \end{macrocode}
% The old Washington and Lee pledge lives on in my macros\dots{}  It
% requires one argument, namely the type of assignment being pledged.
% The argument is optional, though, and a paper is assumed by default.
%    \begin{macrocode}
\newcommand{\wnlpledge}[1][paper]{%
  \ifx\@empty\@date
    \PackageWarning{cjwmacro}{Date is not set.}
  \fi
  \parskip=2pt \parindent=0pt\relax
  \null\vfill\begin{flushright}
    \itshape\small
    On my honour, I have neither given nor received\\
    any unacknowledged aid on this #1.\\[5ex]
    \normalfont\footnotesize
    \makebox[2in]{\hrulefill}\quad\@date\\
    \makebox[2in]{Colin J.~Wynne,~'94}\quad{\hphantom{\@date}}\\
  \end{flushright}}
%    \end{macrocode}
%
% As mentioned in the option section, there is a macro used to put
% fancy section delimiters into, say, a story.  The \cseq{ssbreak}
% command expects the type of delimiter, the \cseq{ssbreakbar}, to be
% defined.  Since either \pkg{draft} or \pkg{final} must be chosen as
% an option, this should be fine, but I have put a hopefully redundant
% command in just in case.
%    \begin{macrocode}
\newcommand{\ssbreak}{\bigskip
  \centerline{\ssbreakbar}\bigbreak}
\providecommand{\ssbreakbar}{}
%    \end{macrocode}
%
% \subsection{Box formatting}
%
% I have written some of my own commands for handling boxes.  The
% first thing I wanted was an analog of \cseq{mbox} or \cseq{hbox} for
% math mode.  The simple version---\cseq{mathbox} puts its argument into an
% \cseq{hbox}, in math mode, in the current style.  The second version
% is \cseq{Mathbox}, which takes two arguments, the first of which is
% put in the box and evaluated \emph{before} math mode is entered.
% This was done for a specific application where I needed to get the
% contents of the \cseq{mathbox} itself into boldface.  Of course,
% \cseq{boldmath} cannot be evaluated within math mode.  Note that the
% style is chosen by the \cseq{mathpalette} macro, and that the
% command \cseq{@mathbox} is essentially just a dummy to allow the
% proper expansion of \cseq{mathpalette}.
%    \begin{macrocode}
% \mathbox puts its argument into an \hbox, in math mode, with the
% current \...style.
\def\mathbox #1{\hbox{$\mathpalette\@mathbox{#1}$}}
\def\Mathbox #1#2{\hbox{#1$\mathpalette\@mathbox{#2}$}}
\def\@mathbox#1#2{#1#2}
%    \end{macrocode}
% Now, there is a reason why these are defined with \cseq{def} and not
% \cseq{newcommand}.  You see, what I really wanted to do was
% something like
%   \begin{verbatim}
% \newcommand{\mathbox}[2][]{%
%   \hbox{#1$\mathpalette\@mathbox{#1}$}}
% \newcommand{\@mathbox}[2]{#1#2}
%   \end{verbatim}
% in order to get optional arguments to my \cseq{mathbox}es.  The
% problem, though, is that I want to use this command in the context
% of |\box|$N$|=\mathbox{|\dots{}|}|, and for that to work, the first
% token in the expansion of \cseq{mathbox} \emph{must} be a
% |\|$?$|box| command.  The overhead imposed by \cseq{newcommand}
% precludes this.  So, I use the cheap hack until I figure out a more
% workable way of implementing what I really want.
%
% A more generically applicable box command is one which does unto
% width what \cseq{smash} does to height.  Hence \cseq{smush}:
%    \begin{macrocode}
\newcommand{\smush}{\relax
  \ifmmode
    \def\next{\mathpalette\math@smush}
  \else
    \let\next\make@smush
  \fi \next}
\newcommand{\make@smush}[1]{\setbox0=\hbox{#1}\fin@smush}
\newcommand{\math@smush}[2]{\setbox0=\hbox{$\m@th#1{#2}$}\fin@smush}
\newcommand{\fin@smush}{\wd0=0pt \box0 }
%    \end{macrocode}
%
% And finally, vaguely in the realm of boxes, we have struts.  Here I
% have defined some math struts of various sizes (corresponding to the
% various delimiter sizes on which they are based).
%    \begin{macrocode}
\newcommand{\bigmathstrut} {\vphantom{\big()}}
\newcommand{\biggmathstrut}{\vphantom{\bigg()}}
\newcommand{\Bigmathstrut} {\vphantom{\Big()}}
\newcommand{\Biggmathstrut}{\vphantom{\Bigg()}}
%    \end{macrocode}
%
% \subsection{Abbreviations, etc.}
%
% I have found myself using particular types of abbreviations quite
% often---often enough that I wanted control sequences for them,
% whence these first few specimens.
%    \begin{macrocode}
\newcommand{\ie}    {\emph{i.e.}\xspace}
\newcommand{\eg}    {\emph{e.g.}\xspace}
\newcommand{\heisst}{d.h\null.\xspace}          % \dh is taken.
%    \end{macrocode}
% Note the use of \cseq{xspace} so that explicit space need not be
% given afterward.  I did this mostly because I have never decided
% whether or not I want to use a comma after either of this.
%
% The second type of abbreviation is the initial, or should I say
% initials.  I finally settled on a style I like---two initials should
% be separated by a thinspace, and will of course need to have the
% spacefactor adjusted if at the end of a sentence (followed by a
% period, in particular).  Here is the implementation:
%    \begin{macrocode}
\newcommand{\initials}[2]{%
  \break@init #2
  \@ifdefinable #1{%
    \global\edef#1{%
      \noexpand\hbox{\@tempa.\noexpand\,\@tempb}%
      \noexpand\@ifnextchar.{\noexpand\@}{.\noexpand\xspace}}}}
\def\break@init #1.#2.{%
  \def\@tempa{#1}\def\@tempb{#2}}
%    \end{macrocode}
% What happens is this.  The \cseq{initials} command is given a
% control sequence name and the initials to be used.  The initials are
% broken on the periods and returned in the specified tokens.  Then,
% if the control sequence is available for definition, it is defined
% in such a way to make all the spacing and punctuation work out.
% Since the tokens need to be expanded back to the separate initials,
% an \cseq{edef} is required---at the same time, use of
% \cseq{noexpand} is made to keep things from going kablooie at
% definition time.  Here are some standard initials by way of usage
% example.
%    \begin{macrocode}
\initials{\UN}{U.N.}
\initials{\US}{U.S.}
\initials{\AI}{A.I.}
%    \end{macrocode}
%
% \subsection{Dates}
%
% I have had call to do a fair amount of \TeX{} in both English and
% German.  Therefore, in implementing the examples of date macros from
% \emph{The \TeX{}book}, I have provided for both languages.
%
%    \begin{macrocode}
% LaTeX style commands for date-parts, both English and German.
\providecommand{\theday}{\number\day\relax}
\providecommand{\themonth}{%
  \ifcase\month\or January\or February\or%
  March\or April\or May\or June\or July\or August\or%
  September\or October\or November\or December\fi}
\providecommand{\themonat}{%
  \ifcase\month\or Januar\or Februar\or%
  M\"arz\or April\or Mai\or Juni\or Juli\or August\or%
  September\or Oktober\or November\or Dezember\fi}
\providecommand{\theyear}{\number\year\relax}
%    \end{macrocode}
% Note that \cseq{today} is unconditionally defined by the following
% underhandedness. 
%    \begin{macrocode}
\providecommand{\today}{}
\renewcommand{\today}{\theday~\themonth, \theyear\xspace}
\providecommand{\heute}{}
\renewcommand{\heute}{den~\theday.\ \themonat\ \theyear\xspace}
  \alias\gdate\heute
%    \end{macrocode}
%
% \subsection{Page styles and titles}
%
% We are finally into the realm of more traditional package macros,
% namely creating some general page appearances.  Here I have
% redefined the \pkg{plain} pagestyle to take advantage of the
% \cseq{pagenofont} defined above.
%    \begin{macrocode}
\renewcommand{\ps@plain}{%
  \let\@mkboth  \@gobbletwo
  \let\@oddhead \@empty
  \let\@evenhead\@empty
  \def\@oddfoot{\pagenofont\hfil\thepage\hfil}
  \let\@evenfoot\@oddfoot}
%    \end{macrocode}
% The \pkg{topright} pagestyle has page numbers (strangely enough) at the top
% right of the page.
%    \begin{macrocode}
\newcommand{\ps@topright}{%
  \let\@mkboth  \@gobbletwo
  \def\@oddhead{\pagenofont\hfil\thepage}
  \let\@evenhead\@oddhead
  \let\@oddfoot \@empty
  \let\@evenfoot\@empty}
%    \end{macrocode}
%
% \subsection{Text formatting}
%
% \subsubsection{Timelines}
%
% A timeline is a long, running, two-column format used, for example,
% to do r\'esum\'es or vit\ae (or, if you are in Germany, a
% \emph{Lebenslauf}).  The idea is that a date (or some identifying
% information) appears at the left, and the content is given in the
% righthand column.  The usage is
%   \begin{display}{l}
% |\timeline[|\meta{pos}|]{|\meta{date}|}|
%   \end{display}
% where \meta{pos} is exactly the argument to \cseq{makebox}, the
% justification of the \meta{date} entry within the lefthand column.
% That column has length \cseq{timelineskip}, which can off course be
% set as desired.
%    \begin{macrocode}
\newlength{\timelineskip}
\setlength{\timelineskip}{1.75in}
%    \end{macrocode}
% The actual entries are not considered to be two separate columns.
% Rather, the first line is padded out to \cseq{timelineskip} with
% makebox, and following lines use a hanging indentation.  The control
% sequence \cseq{endtimeline} is defined trivially so that a timeline
% entry may be used as a \env{timeline} environment.
%    \begin{macrocode}
\newcommand{\timeline}[2][l]{%
  \noindent\hangindent=\timelineskip
  \makebox[\timelineskip][#1]{\timelinefont{#2}}\ignorespaces}
\let\endtimeline\relax
%    \end{macrocode}
%
%  \subsubsection{Mathematical declarations}
%
% In writing up mathematics, one often wishes to declare definitions,
% theorems, and so forth.  I have written generic declaration macros
% which can be customized for these uses.  Since I prefer to have all
% such things numbered seuqentially, they use a common counter, called
% \cseq{declare}, strangely enough.  They are numbered within sections
% if sections are being numbered.
%    \begin{macrocode}
\@ifundefined{c@section}
  {\newcounter{declare}}
  {\newcounter{declare}[section]
   \renewcommand{\thedeclare}{\thesection.\arabic{declare}}}
%    \end{macrocode}
% When declarations are numbered, it is sometime nice to have the
% declaration type and number appear uniformly wide throughout.  This
% is done by forcing the declaration to appear in a box of width
% \cseq{declareindent}.
%    \begin{macrocode}
\newlength{\declareindent}
  \setlength{\declareindent}{0pt}
%    \end{macrocode}
% We use some internal commands to specify exactly how the declaration
% is typeset.  In fact, we will be defining not only declaration, but
% an alternate declaration form so that two different methods may be
% used simultaneously in a document---\eg, when theorems and major
% results are to be italicized, but definitions and so forth are not.
%    \begin{macrocode}
\newcommand{\@declare}   [1]{{\declarefont#1:}\quad}
\newcommand{\@altdeclare}[1]{{\altdeclarefont#1:}\quad}
%    \end{macrocode}
% The generic declarations are environments, and are provided in both
% numbered (normal) and unnumbered (starred) forms.  The latter are
% more simple.
%    \begin{macrocode}
\newenvironment{declaration*}[1]%
  {\medbreak\noindent\ignorespaces
     \@declare{#1}\ignorespaces}%
  {\kern0pt\nobreak\smallskip}
\newenvironment{altdeclaration*}[1]%
  {\medbreak\noindent\ignorespaces
     \@altdeclare{#1}\ignorespaces}%
  {\kern0pt\nobreak\smallskip}
%    \end{macrocode}
% The numbered versions introduce nothing surprising, but are a tad
% more involved.
%    \begin{macrocode}
\newenvironment{declaration}[1]%
  {\medbreak\refstepcounter{declare}
     \noindent\ignorespaces
     \ifnum\declareindent = 0\relax%
       \@declare{\thedeclare\quad #1}
     \else
       \makebox[\declareindent]{\@declare{\thedeclare\hss #1}}
     \fi\ignorespaces}
  {\kern0pt\nobreak\smallskip}
\newenvironment{altdeclaration}[1]%
  {\medbreak\noindent\ignorespaces
     \refstepcounter{declare}
     \ifnum\declareindent = 0\relax
       \@altdeclare{\thedeclare\quad #1}
     \else
       \makebox[\declareindent]{\@altdeclare{\thedeclare\hss #1}}
     \fi\ignorespaces}
  {\kern0pt\nobreak\smallskip}
%    \end{macrocode}
% Now, because I am essentially lazy and do not want the extra typing
% needed for an environment, I have shortcuts, \cseq{declare} and
% \cseq{altdeclare}, as well as numbered versions \cseq{ndeclare} and
% \cseq{altndeclare}.  The first argument is passed to the
% corresponding environment, and the following paragraph is the body
% of the environment.
%    \begin{macrocode}
\def\declare    #1#2\par{%
  \begin{declaration*}{#1}#2\end{declaration*}\par}
\def\altdeclare #1#2\par{%
  \begin{altdeclaration*}{#1}#2\end{altdeclaration*}\par}
\def\ndeclare   #1#2\par{%
  \begin{declaration}{#1}#2\end{declaration}\par}
\def\altndeclare#1#2\par{%
  \begin{altdeclaration}{#1}#2\end{altdeclaration}\par}
%    \end{macrocode}
% Genreality is all well and good, but there are some stock
% declarations, given here in both numbered and unnumbered versions.
%    \begin{macrocode}
\providecommand{\corollary}   {\declare{Corollary}}
\providecommand{\definition}  {\declare{Definition}}
\providecommand{\lemma}       {\declare{Lemma}}
\providecommand{\proposition} {\declare{Proposition}}
\providecommand{\theorem}     {\declare{Theorem}}
\providecommand{\note}        {\altdeclare{Note}}

\providecommand{\ncorollary}  {\ndeclare{Corollary}}
\providecommand{\ndefinition} {\ndeclare{Definition}}
\providecommand{\nlemma}      {\ndeclare{Lemma}}
\providecommand{\nproposition}{\ndeclare{Proposition}}
\providecommand{\ntheorem}    {\ndeclare{Theorem}}
\providecommand{\nnote}       {\altndeclare{Note}}
%    \end{macrocode}
% In addition, the following German declaration (meaning a claim) is
% also defined.
%    \begin{macrocode}
\providecommand{\behaupt}	  {\declare{Behauptung}}
\providecommand{\nbehaupt}	  {\ndeclare{Behauptung}}
%    \end{macrocode}
% Finally, since one is not likely to mix numbered and unnumbered,
% here is a control sequence that will make sure everything is
% numbered. 
%    \begin{macrocode}
\newcommand{\allndeclares}{%
  \let\declare     \ndeclare
  \let\altdeclare  \altndeclare}
%    \end{macrocode}
%
% Now that we have propositions, claims, and theorems (oh my!), we
% want to be able to prove them.  The first step is to define a proof
% environment.  The environment simply sets up a label and some
% spacing.  The label is in |\altdeclarefont|.  The label is an
% optional argument which defaults to `Proof', oddly enough.
%    \begin{macrocode}
\newenvironment{proof}[1][Proof]%
  {\smallbreak\noindent{\altdeclarefont#1:}%
     \quad\ignorespaces}%
  {\qed}
%    \end{macrocode}
% Just in case you are prooving in German, we also have the following:
%    \begin{macrocode}
\newenvironment{beweis}[1][Beweis]%
  {\smallbreak\noindent{\altdeclarefont#1:}%
     \quad\ignorespaces}%
  {\qed}
%    \end{macrocode}
% Note that the end of a proof has the command |\qed|, which we will
% unconditionally define here.  This is adapted from \emph{The
% \TeX{}book}.  The idea is to right justify |\qedsymbol| on the line
% where |\qed| is invoked, unless there is not a comfortable amount of
% room.  That amount is given as 2\,em.  When this happens, the line
% is broken and the |\qedsymbol| appears flush right on the following
% line. 
%    \begin{macrocode}
\providecommand{\qed}{}
  \renewcommand{\qed}{%
    {\unskip\nobreak\hfil\penalty 50%
     \hskip 2em\hbox{}\nobreak\hfil\qedsymbol%
     \parfillskip=0pt \finalhyphendemerits=0 \par}}
%    \end{macrocode}
% The standard end-of-proof symbol is a box, but I prefer somewhat
% less ink.  I use \TeX's hollow diamond suit symbol (again
% unconditionally defined).
%    \begin{macrocode}
\providecommand{\qedsymbol}{}
  \renewcommand{\qedsymbol}{\lower 0.35ex\hbox{$\diamondsuit$}}
%    \end{macrocode}
% In case it is desired, the box symbol is defined as |\qedbox|, and
% then with a simple alias this can be used to end all proofs.
%    \begin{macrocode}
  \newcommand{\qedbox}{\vrule height4pt width3pt depth2pt}
%    \end{macrocode}
% Now we wish to define control sequences for some constructions
% commonly found in proofs.  I often find myself writing out proofs
% which require cases.  There are two types of cases.  Often I will
% want to have two cases, one for each definition of an equivalence
% for example.  In this case, the case delimiters will be something
% like |\then| and |\when| commands, and should be set in parentheses
% to mark them clearly.  The other type is the more general `Case
% $n$:' (where $n$, one hopes, will not be \emph{too} large).  To
% cover both of these, we use a fairly typical \LaTeX{} conceit:
%   \begin{display}{l}
% |\Case*{|\meta{case}|}|
%   \end{display}
% where the unstarred argument sets \meta{case} inside parentheses and
% the star supresses the parentheses.  A German alias is given.
%    \begin{macrocode}
\newcommand{\Case}{\@ifstar{\@starCase}{\@Case}}
\newcommand{\@starCase}[1]{\@@Case{#1}}
\newcommand{\@Case}[1]{\@@Case{(#1)}}
\newcommand{\@@Case}[1]{%
  \noindent{\declarefont#1}\quad\ignorespaces}
\alias\Fall\Case
%    \end{macrocode}
% And finally, just in case the proof is by contradiction, we have the
% following.
%    \begin{macrocode}
\newcommand{\contra}{\ensuremath{\Rightarrow\Leftarrow}}
%    \end{macrocode}
%
%
% \subsubsection{Problems and examples}
%
% In addition to declarations, and for subjects other than
% mathematics, one might want to provide examples and worked
% problems.  I implement examples as a separate environment (well,
% \emph{four} separate environments) so that they may have fonts
% distinct from declarations.
%    \begin{macrocode}
\newenvironment{example*}%
  {\@nameuse{declaration*}{Example}\examplefont}
  {\medbreak}
\newenvironment{altexample*}%
  {\@nameuse{declaration*}{Example}\examplefont}
  {\medbreak}
\newenvironment{example}%
  {\declaration{Example}\examplefont}
  {\medbreak}
\newenvironment{altexample}%
  {\declaration{Example}\examplefont}
  {\medbreak}
%    \end{macrocode}
%
% Problems are handled differently.  In my experience, problems do not
% appear in longwinded documents using sectioning, and so the counter
% need not be embedded.
%    \begin{macrocode}
\newcounter{problem}
  \setcounter{problem}{0}
\renewcommand{\theproblem}{\arabic{problem}}
\renewcommand{\p@problem}{}
%    \end{macrocode}
% Often when working a problem, one wishes to include a reference to
% the source.  This is accomplished via the \cseq{Page} macro.  Usage
% is 
%   \begin{display}{l}
% |\Page*[|\meta{author}|]{|\meta{pp}|}{|\meta{problem}|}|
%   \end{display}
% In the \LaTeX{} tradition, the standard command tries to outguess
% you by prepending a hash `\#' to the problem number, whereas the
% starred version omits this.  Thus, the standard version produces
%   \begin{display}{l}
% ([\meta{author},~]p.\,\meta{pp}, \#\meta{problem})
%   \end{display}
% and \cseq{Page*} leaves off the hash.  Notice that the space between
% author and page number is inserted by the macro.  The macro is
% defined robustly so that it can be used in moving arguments.
%    \begin{macrocode}
\DeclareRobustCommand{\Page}{%
  \@ifstar{\@Page{}}{\@Page{\#}}}
\def\@Page#1{%
  \@ifnextchar [{\@@Page{#1}}{\@@Page{#1}[]}}
\def\@@Page#1[#2]#3#4{%
  \def\@tempa{#2}%
  \ifx\@empty\@tempa%
    \let\@tempb\@tempa%
  \else%
    \edef\@tempb{\@tempa,~}%
  \fi%
  (\@tempb p.\,#3, #1{#4})}
%    \end{macrocode}
% 
% The statement of a problem is given in an environment, again so that
% font customization can be easily done.  The \env{statement}
% environment takes a single optional argument, which is typeset at
% the beginning of the statement in \cseq{altdeclarefont}.  The rest
% of the statement is in \cseq{declarefont}.  I use the optional
% argument to pass a \cseq{Page} reference most often---note, though,
% that if the optional argument to \cseq{Page} is used, the whole
% \cseq{Page} command should be put in braces sp that the square
% brackets of optional arguments do not get confused.
%    \begin{macrocode}
\newenvironment{statement}[1][\null]%
  {\def\@tempa{#1}\def\@tempb{\null}%
    \ifx\@tempa\@tempb%
      \def\@tempc{\null}%
    \else%
      \def\@tempc{\altdeclarefont\@tempa\quad}%
    \fi%
    \declarefont{\@tempc}\ignorespaces}
  {\removelastskip\nopagebreak\smallskip}
%    \end{macrocode}
% A problem, now, is basically just a wrapper for the statement.  It
% generates and sets the problem number, does some spacing, and the
% body of the \env{problem} environment becomes the body of the
% \env{statement}.  In essence, a \env{problem} is a numbered
% \env{statement}.   There is a starred version which does not do
% numbers and references---this just does the correct spacing and
% calls \env{statement}. Note that the problem number is set using a
% macro from the \pkg{cjw-outl} package.
%    \begin{macrocode}
\newenvironment{problem}%
  {\setcounter{equation}{0}%
    \gdef\theequation{\theproblem.\arabic{equation}}%
    \removelastskip\medbreak%
    \refstepcounter{problem}%
    \noindent\theoutlabel{\theproblem.}%
    \statement}
  {\endstatement}
\newenvironment{problem*}%
  {\removelastskip\medbreak%
   \noindent\statement}
  {\endstatement}
%    \end{macrocode}
% Since I have been known to write assignments in German, we provide
% the aliases to make an \env{aufgabe} environment.
%    \begin{macrocode}
\alias  \aufgabe   \problem
\realias\endaufgabe\endproblem
%    \end{macrocode}
% For parts and subparts of problems, the aliases are English and the
% main definitions are German because I wrote these while I was in
% Germany.  So, parts (\emph{Teile}) are numbered within problems and
% subparts (\emph{Subteile}) within parts.  The defaults for
% cross-referencing (the \cseq{p@} forms) are set, too.
%    \begin{macrocode}
\newcounter{teil} [problem]
\newcounter{steil}[teil]
\renewcommand{\theteil}  {(\alph{teil})}
  \renewcommand{\p@teil} {\theproblem}
\renewcommand{\thesteil} {(\roman{steil})}
  \renewcommand{\p@steil}{\p@teil\theteil}
%    \end{macrocode}
% The environment \env{part}/\env{teil} used to be implemented
% entirely in terms of the \pkg{cjw-outl} package, but that was a
% little bit of overkill, and made the numbering more difficult to
% implement.  I ought to one day implement problems/parts/subparts
% entirely in terms of the outline macros.  We'll see.
%
% Anyway, the current implementations still rely on some of the
% definitions from the \pkg{cjw-outl} package.  The
% \env{part}/\env{teil} environments take a single optional argument,
% namely the outline depth.  Level one starts the text flush left at
% the margin, which is usually where the \env{problem} is, hence a
% \env{part} should be at level two, and this is the default.  A more
% detailed explanation of the goings-on here can be found in
% \pkg{cjw-outl.dtx}. 
%    \begin{macrocode}
\newenvironment{teil}[1][2]%
  {\@tempcnta=#1\advance\@tempcnta by -1\relax
   \ifnum\@tempcnta < 1\relax
     \leftskip=0pt\relax
   \else
     \leftskip=\@tempcnta\outlindent
   \fi
   \refstepcounter{teil}
   \addvspace{\medskipamount}%
   \noindent\theoutlabel{\theteil}%
   \ignorespaces}
  {\par\smallbreak}
%    \end{macrocode}
% The default level for \env{ppart} or \env{steil}, the subpart
% environments, is three.
%    \begin{macrocode}
\newenvironment{steil}[1][3]%
  {\@tempcnta=#1\advance\@tempcnta by -1\relax
   \ifnum\@tempcnta < 1\relax
     \leftskip=0pt\relax
   \else
     \leftskip=\@tempcnta\outlindent
   \fi
   \refstepcounter{steil}
   \addvspace{\medskipamount}%
   \noindent\theoutlabel{\thesteil}%
   \ignorespaces}
  {\par\smallbreak}
%    \end{macrocode}
% English aliases are, of course, given.
%    \begin{macrocode}
\realias\part    \teil
\realias\endpart \endteil
\alias  \ppart   \steil
\realias\endppart\endsteil
%    \end{macrocode}
%
% \subsubsection{Footnotes}
%
% This is a simple modification to a standard \LaTeXe{} internal
% macro, because I prefer hanging indentation on my footnote text.
%    \begin{macrocode}
\long\def\@makefntext#1{%
  \parindent 1em\noindent\hangindent=\parindent%
  \hb@xt@    1em{\hss \llap{\@makefnmark} }#1}
%    \end{macrocode}
%
% \subsubsection{Text displays}
%
% I have turned the \cseq{begindisplay} and \cseq{enddisplay} macro
% pair from \emph{The \TeX{}book} (page~421) into a \LaTeX{}
% environment.  As with Knuth's macros, local definitions for use
% within the display can be given, in this case via the
% \env{display}'s optional argument.  Since the environment is
% implemented through the standard \env{tabular} environment, there is
% a mandatory argument specifying column layout.  Overall, usage is
%   \begin{display}{l}
% \cseq{begin}|{display}[|\meta{local}|]{|\meta{cols}|}|
%   \end{display}
% with local definitions \meta{local} and column descriptol
% \meta{col}.  (By the way, the previous display was created with the
% \env{display} environment\dots)
%
% The display's offset from the left margin is specified by
% \cseq{textdisplay indent}.  Default value is equal to
% \cseq{parindent}, and is therefore set below, after
% \cseq{parindent}. 
%    \begin{macrocode}
\newlength{\textdisplayindent}
%    \end{macrocode}
% The actual \env{display} environment uses the spacing and penalties
% of mathematical displays.
%    \begin{macrocode}
\newenvironment{display}[2][]
  {\vadjust{\penalty\predisplaypenalty}
   \@newline[\abovedisplayskip]%
   \begingroup%
     #1%
     \begin{tabular}{@{\null\hspace{\textdisplayindent}\null}#2}}
  {\end{tabular}\endgroup
   \vadjust{\penalty\postdisplaypenalty}
   \@newline[\belowdisplayskip]\ignorespaces}
%    \end{macrocode}
%
% \subsection{Verbatim inclusions}
%
% Since I only occassionally need to include verbatim files, the
% following macros need to be specifically included by a package
% option, as was mentioned above.
%    \begin{macrocode}
\if@verbext
%    \end{macrocode}
% For numbered inclusions, we need a line number counter.
%    \begin{macrocode}
\newcounter{vfline}
\renewcommand{\thevfline}{\arabic{vfline}}
%    \end{macrocode}
% We need the following command from \emph{The \TeX{}book}.
%    \begin{macrocode}
\providecommand{\uncatcodespecials}{%
  \def\do##1{\catcode`##1=12 }\dospecials}
%    \end{macrocode}
% The basic command is \cseq{verbfile} which takes an optional
% argument specifying the starting line number (default is one), and a
% mandatory argument which is, of course, the name of the file to
% include.  There is also \cseq{verbfilenolines} which does not number
% lines, and needs only the one mandatory argument.
%    \begin{macrocode}
\providecommand{\verbfile}[2][1]{%
  \par\begingroup\@vf@lines{#1}\input{#2}\relax\endgroup}
\providecommand{\verbfilenolines}[1]{%
  \par\begingroup\@vf@nolines\input{#1}\relax\endgroup}
%    \end{macrocode}
% In the manner of command which need to do \cseq{catcode} trickery,
% the above are primarily wrappers for the real commands.  The one
% problem with these as currently implemented is that they do not
% handle leading space in the included file.  Oh, well.
%    \begin{macrocode}
\newcommand{\@vf@lines}[1]{%
  \verbatimfont
  \setcounter{vfline}{#1}
    \addtocounter{vfline}{-1}
  \setlength{\parindent}{0pt}
  \setlength{\parskip}{0pt}
  \def\par{\leavevmode\endgraf}
  \obeylines \uncatcodespecials \obeyspaces
  \everypar{\null\stepcounter{vfline}%
    \llap{\scriptsize\thevfline\quad}\null}}
\newcommand{\@vf@nolines}{%
  \verbatimfont
  \setlength{\parindent}{0pt}
  \setlength{\parskip}{0pt}
  \def\par{\leavevmode\endgraf}
  \obeylines \uncatcodespecials \obeyspaces
  \everypar{\null}}
%    \end{macrocode}
% Now we end the inclusion conditional.
%    \begin{macrocode}
\fi
%    \end{macrocode}
%
% \subsection{Initialization}
%
% We use the \cseq{AtBeginDocument} command to set up some default
% values when the document is actually started.
%    \begin{macrocode}
\AtBeginDocument{%
  \setlength{\parindent}        {20pt}
  \setlength{\parskip}          { 2pt plus 1pt}
  \setlength{\textdisplayindent}{\parindent}}
%    \end{macrocode}
%
% \iffalse
%
%</general>
%
% \fi
%
%
% \section{Math macros}
%
% \iffalse
%
%<*math>
%
% \fi
%
% While some macros useful for typesetting mathematics have already
% been covered, none of them had to do with mathematical equations or
% symbols---they were macros for logical flow and delineation.  In
% this package, \pkg{cjwmath}, I have written macros which are
% specifically for typesetting the actual math---the vast majority of
% these macros, if not actually all of them, are meant to be used in
% math mode.
%
% \subsection{Package initialization}
%
% Since different papers require different types of math, I have again
% used the introduction of conditionals and package options to control
% what code is actually loaded.  The important one concerns use of the
% AMS math packages in AMS-\LaTeX.  This is included as an option to
% my package because some of my definitions depend upon whether the
% AMS macros are being used.  There are conditionals for including
% code for calculus (both derivatives and integrals) and some code for
% physics.
%    \begin{macrocode}
\newif \if@amsmath
\newif \if@derivatives
\newif \if@integrals
\newif \if@physics
%    \end{macrocode}
% There are options corresponding to each conditional.
%    \begin{macrocode}
\DeclareOption{amsmath}  {\@amsmathtrue}
\DeclareOption{derivs}   {\@derivativestrue}
\DeclareOption{integrals}{\@integralstrue}
\DeclareOption{physics}  {\@physicstrue}
%    \end{macrocode}
% There used to be another option for typesetting units.  While I
% originally included that code in this package directly, I found
% several occasions where I wanted units but not the rest of the math
% code.  Therefore, units are in a separate package, and the option
% now just reminds the user to input that package by itself.
%    \begin{macrocode}
\DeclareOption{units}{%
  \PackageWarning{cjwmath}%
    {Obsolete option \CurrentOption.  Use package `cjwunits' instead.}}
%    \end{macrocode}
% Finally, there is a default option, to warn about unknown options,
% and the passed option list is processed.
%    \begin{macrocode}
\DeclareOption*{%
  \PackageWarning{cjwmath}{Unknown option `\CurrentOption'}}
\ProcessOptions
%    \end{macrocode}
%
% This package depends upon the previous one.
%    \begin{macrocode}
\RequirePackage{cjwmacro}
%    \end{macrocode}
% It also uses the AMS fonts, for which we require \pkg{amssymb},
% which itself requires \pkg{amsfonts}.
%    \begin{macrocode}
\RequirePackage{amssymb}
%    \end{macrocode}
% Just in case things get screwy in \pkg{cjwmacro}---which they
% shouldn't, we explicitly require \pkg{amstext} here, too, for the
% \cseq{text} command.
%    \begin{macrocode}
\RequirePackage{amstext}
%    \end{macrocode}
% I much prefer the following package to AMS's own blackboard bold
% font. 
%    \begin{macrocode}
\RequirePackage{bbm}
%    \end{macrocode}
% If the \pkg{amsmath} option is specified, we load the package (which
% itself brings in a lot of other stuff).
%    \begin{macrocode}
\if@amsmath
  \RequirePackage{amsmath}
\fi
%    \end{macrocode}
%
% \subsection{Miscellaneous macros}
%
% Here is a package command which I have written to cover the
% shortcomings of AMS-\LaTeX's |\DeclareNewMathOperator| command.  In
% particular, I would like to be able to set different fonts for some
% operators.   The syntax is
%   \begin{display}{l}
% |\NewMathOp*[|\meta{font}|]{\cs}{|\meta{text}|}|
%   \end{display}
% The optional star makes an operator with limits.  The \meta{font}
% is, by default, |\operator@font|.  |\cs| is the name of the new
% mathop.  \meta{text} should be the printed version of the operator,
% but may also include, for example, extra kerning information, as in
%   \begin{display}{l}
% |\NewMathOp[\mathfrak]{\so}{o\kern 0pt}|
%   \end{display}
% The command should produce something robust.
%    \begin{macrocode}
\DeclareRobustCommand{\NewMathOp}{%
  \@ifstar{\@makenewop{\displaylimits}}
          {\@makenewop{\nolimits}}}
%    \end{macrocode}
% The first iteration applies a font if the optional argument is not
% given.
%    \begin{macrocode}
\def\@makenewop#1{%
  \@ifnextchar [{\@@makenewop{#1}}
    {\@@makenewop{#1}[\operator@font]}}
%    \end{macrocode}
% Finally, the net operator itself is declared robustly.  The
% arguments are, in order, either |\displaylimits| or |\nolimits|, the
% font, the control sequence, and the operator text.
%    \begin{macrocode}
\def\@@makenewop#1[#2]#3#4{%
  \DeclareRobustCommand{#3}{%
    \mathop{\kern\z@{#2{#4}}}#1}}
%    \end{macrocode}
%
% The next few macros have to do with things not specific to any
% particular flavor of mathematics.  For example, I like some of the
% alternate Greek characters more than the originals---notice how we
% cleverly required the \pkg{cjwmacro} package which gives us the
% \cseq{swapdef} command.
%    \begin{macrocode}
\swapdef{\epsilon}{\varepsilon}
% \swapdef{\theta}{\vartheta}
\swapdef{\rho}{\varrho}
%    \end{macrocode}
% I also like the empty set symbol from AMS, to which I also assign a
% German alias.
%    \begin{macrocode}
\swapdef{\nothing}{\varnothing}
\alias\leer\nothing
%    \end{macrocode}
%  The standard symbols `$\exists$' and `$\forall$' do not have
% satisfactory spacing, in my opinion, so I redefine them as
% relations.  Notice the aliasing so that the symbols' redefinition
% can be carried out regardless of current math fonts.
%    \begin{macrocode}
\alias\@@exists\exists
  \renewcommand{\exists}{\mathrel{\@@exists}}
\alias\@@forall\forall
  \renewcommand{\forall}{\mathrel{\@@forall}}
%    \end{macrocode}
% What \LaTeX{} cleverly calls \cseq{ni} (a backwards `$\in$') really
% ought to mean `such that,' hence I rename it:
%    \begin{macrocode}
\newcommand{\st}{\mathrel{\ni}}
%    \end{macrocode}
% Being essentially lazy, I also prefer to make a nice control
% sequence for some standard abbreviations.  One happens to be
% German (since in German it is more acceptable to use abbreviations
% of long phrases even in a more formal setting).
%    \begin{macrocode}
\newcommand{\WLOG}{Without loss of generality\xspace}
\newcommand{\Wlog}{without loss of generality\xspace}
\newcommand{\obda}{o.B.d.A.\xspace}
\newcommand{\fp}{floating-point\xspace}
%    \end{macrocode}
% The following two commands are simply for phantoms I often find
% myself using, for example to make alignments in arrays and matrices
% come out right.  The mnemonic is `phantom negative' or `phantom equals'.
%    \begin{macrocode}
\newcommand{\pneg}{\phantom{-}}
\newcommand{\peq}{\phantom{=}}
%    \end{macrocode}
% Going probably too far into the realm of generalization, here are
% some macros to set their arguments inside matching scaled delimiters
% of various sorts.
%    \begin{macrocode}
\newcommand{\anglebrackets}[1]{%
  \left\langle #1 \right\rangle}
\newcommand{\curlybrackets}[1]{%
  \left\{ #1 \right\}}
\newcommand{\squarebrackets}[1]{%
  \left[ #1 \right]}
\newcommand{\vertbrackets}[1]{%
  \left| #1 \right|}
\newcommand{\Vertbrackets}[1]{%
  \left\| #1 \right\|}
%    \end{macrocode}
% And now for something completely different---sometimes an operand
% should be left generic, but not in terms of a variable.  The usual
% way of accomplishing this is to place a small dot where the argument
% would otherwise go.  As I consider this to imply `no argument', the
% command is |\noarg|.
%    \begin{macrocode}
\newcommand{\noarg}{\,\cdot\,}
%    \end{macrocode}
% We end with a few things that should be fairly obvious.
%    \begin{macrocode}
\newcommand{\ee}[1]{\times10^{#1}}
\newcommand{\half}{\sfrac12}
\newcommand{\ninfty}{-\infty}
%    \end{macrocode}
% This is shorthand for function definitions, including an extra
% control sequence for some backwards compatibility and an alias to
% German.
%    \begin{macrocode}
\newcommand{\fcn}[2]{\colon{#1}\rightarrow{#2}}
  \newcommand{\mapping}[3]{{#1}\fkt{#2}{#3}}
\alias\fkt\fcn
%    \end{macrocode}
% Restrictions of functions:
%    \begin{macrocode}
\newcommand{\restr}[2][\big]{\kern -.1em #1|_{#2}}
%    \end{macrocode}
%
%
% \subsection{Combinatorics}
%
% The binomial coefficient $\choose{n}{k}$ is defined, depending on
% whether or not AMS-\LaTeX{} is being used.
%    \begin{macrocode}
\if@amsmath
  \realias\choose\binom
\else
  \renewcommand{\choose}[2]{{{#1}\atopwithdelims(){#2}}}
\fi
%    \end{macrocode}
% And lastly, we have the combinatorial doohickie which is read as
% `$n$ multichoose $k$', using doubled parentheses as delimiters.  I
% think this comes out looking right.
%    \begin{macrocode}
\newcommand{\mchoose}[2]{%
  \mathchoice%
   {\left(\kern-0.48em\choose{#1}{#2}\kern-0.48em\right)}
   {\left(\kern-0.30em
        \choose{\smash{#1}}{\smash{#2}}\kern-0.30em\right)}
   {\left(\kern-0.30em
        \choose{\smash{#1}}{\smash{#2}}\kern-0.30em\right)}
   {\left(\kern-0.30em
        \choose{\smash{#1}}{\smash{#2}}\kern-0.30em\right)}
  }
%    \end{macrocode}
% There is also the old-fashioned $\Comb{n}{k}$-type notation, as used
% both in English and in German.
%    \begin{macrocode}
\newcommand{\Comb}[2]{%                         %   C
  {}_{#1}{\operator@font C}_{#2}}               % #1 #2
\newcommand{\Komb}[2]{%                         %          #2
  {\operator@font Ko}_{#1}^{#2}}                %        Ko
\newcommand{\Kombun}[2]{\Komb{#1,\neq}{#2}}     %          #1
\newcommand{\Perm}[2]{%                         %                #2
  {\operator@font Pe}_{#1}^{#2}}                %              Pe
\newcommand{\Permun}[2]{\Perm{#1,\neq}{#2}}     %                #1
%    \end{macrocode}
%
% \subsection{Sets}
%
% The most important macro in this section is named, of course,
% |\set|.  The idea is to make sets which look like
%   \begin{displaymath}
% \set{x \in \R^2}{\norm{x}_p = 1 \forall p = 1,2,3,\ldots}.
%   \end{displaymath}
% That is, there should be scaled braces around two halves separated
% by a scaled logical delimiter, the vertical bar.  The problem with
% this is getting everything the same height, since the $\mid$
% specifier does not scale and there is no middle-counterpart to
% |\left|\dots|\right|.
%
% So, the command has the form:
%   \begin{display}{l}
% |\set[|\meta{mid}|]{|\meta{left}|}{|\meta{right}|}|
%   \end{display}
% The optional \meta{mid} specifies an alternate delimiter to use
% between the two definition halves of the set.  If it is left
% \emph{empty}, the null delimiter `.' will be assumed.  If anything
% at all appears in the optional argument, though, the first token
% \emph{must} be a delimiter, as it will immediately be preceded by a
% sizing macro.  For example, if you wish to use a colon to separate
% the definitions, use `|[.:]|' as the optional argument.  The
% mandatory \meta{left} and \meta{right} are simply the halves of the
% set definition.
%    \begin{macrocode}
\newcommand{\set}[3][|]{{%
  \newdimen\@tempdimd%
%    \end{macrocode}
% Each half is set in its own box, then the larger of the respective
% heights and depths are determined.
%    \begin{macrocode}
  \setbox0=\mathbox{#2}\@tempdima=\ht0 \@tempdimb=\dp0%
  \setbox0=\mathbox{#3}\@tempdimc=\ht0 \@tempdimd=\dp0%
  \ifdim\@tempdimc > \@tempdima
    \@tempdima=\@tempdimc
  \fi
  \ifdim\@tempdimd > \@tempdimb
    \@tempdimb=\@tempdimb
  \fi
%    \end{macrocode}
% We create an invisible rule with that height and depth, and make
% sure we have a valid delimiter if the optional argument is empty.
%    \begin{macrocode}
  \def\@tempa{\vrule width0pt height\@tempdima depth\@tempdimb}
  \def\@tempb{#1}
  \ifx\@empty\@tempb
    \def\@tempb{.}
  \fi
%    \end{macrocode}
% Finally, we use a null left delimiter to balance the middle
% delimiter, and then a left brace to balance the right brace.  The
% rule is set inside both pairs so that they scale identically.  Note
% the use of |\expandafter| so that when the first |\right| is
% expanded, it can grab the delimiter in |\@tempb|.
%    \begin{macrocode}
  \left.\left\{ \@tempa{#2} \,\expandafter\right\@tempb\,{#3} \right\} }}
%    \end{macrocode}
% For backwards compatibility, I make two aliases for |\set|; the old
% commands required the user to specify the larger side of the set
% definition in order to get sizing correct.
%    \begin{macrocode}
\alias\setl\set
\alias\setr\set
%    \end{macrocode}
%
% Here are some macros for typesetting sets symbolically.  First off,
% we might want to know how to typeset a level set.
%    \begin{macrocode}
\newcommand{\lvl}[2][\alpha]{\Gamma\ssb{#2}\ssp{(#1)}}
%    \end{macrocode}
% There are also fuzzy sets, and their corresponding level sets.
%    \begin{macrocode}
\if@amsmath
  \newcommand{\fset}[1]{\Tilde{#1}}
\else
    \newcommand{\fset}[1]{\tilde{#1}}
\fi
\newcommand{\flvl}[2][\alpha]{\lvl[#1]{\fset{#2}}}
%    \end{macrocode}
% For want of a better font, I will typeset set collections
% in |\mathcal|.
%    \begin{macrocode}
\alias\coll\mathcal
%    \end{macrocode}
%
% Finally, we deal with some set operators.
% \emph{The \TeX{}book} points out the difference between |\setminus|
% and |\backslash|.  I prefer to think of them as `set
% complementation' and `coset', respectively.
%    \begin{macrocode}
\alias\scomp\setminus
\alias\coset\backslash
%    \end{macrocode}
% The next macro attempts to create a symmetric difference operator.
% I don't like it, but I probably won't do better until I learn to
% make my own \textsf{M{\small ETAFONT}} characters\ldots
%    \begin{macrocode}
\newcommand{\symmdiff}{%
  \mathbin{\text{\footnotesize$\bigtriangleup$}}}
%    \end{macrocode}  
%
%
% \subsection{Sequences and series}
%
% Just a few macros are required for various sequences and series,
% mostly for indexing.  The best explanation is simply an example.
% The code
%   \begin{display}{l}
% |$y \in \seq{x_{ij}}$, where $i\inset{n}$, $j\inrange[0]{m}$|
%   \end{display}
% produces
%   \begin{display}{l}
% $y \in \seq{x_{ij}}$, where $i\inset{n}$, $j\inrange[0]{m}$.
%   \end{display}
% 
%    \begin{macrocode}
\newcommand{\seq}    [1]   {\curlybrackets{#1}}
\newcommand{\inset}  [2][1]{\in\{ #1,\ldots,#2 \}}
\newcommand{\inrange}[2][1]{ = #1,\ldots,#2}
%    \end{macrocode}
% 
%
% \subsection{Calculus}
%
% The calculus macros are relegated to auxiliary files, as I rarely
% need them.  
% 
% \subsubsection{Derivatives}
%
% We load the derivatives in if they are requested.
%    \begin{macrocode}
\if@derivatives
  \InputIfFileExists{cjwderiv.tex}{}{%
    \PackageWarning{cjwmath}{Option `cjwderiv.tex' not found.}
    \@@derivativesfalse}
\fi
%    \end{macrocode}
% This loads both simple and partial derivative macros.
%\iffalse
%</math>
%<*deriv>
%\fi
%
% The derivatives are all variations on the basic |\dd| macro, which
% should be fairly self explanatory.
%    \begin{macrocode}
\newcommand{\dd} [2]{\frac{d#1}{d#2}}
\newcommand{\ddt}[1]{\dd{#1}{t}}
\newcommand{\ddu}[1]{\dd{#1}{u}}
\newcommand{\ddv}[1]{\dd{#1}{v}}
\newcommand{\ddx}[1]{\dd{#1}{x}}
\newcommand{\ddy}[1]{\dd{#1}{y}}

\newcommand{\sdd} [2]{\frac{d^2#1}{d#2^2}}
\newcommand{\sddx}[1]{\sdd{#1}{x}}
\newcommand{\sddy}[1]{\sdd{#1}{y}}
\newcommand{\sddt}[1]{\sdd{#1}{t}}
\newcommand{\sddu}[1]{\sdd{#1}{u}}
\newcommand{\sddv}[1]{\sdd{#1}{v}}
%    \end{macrocode}
%
% \subsubsection{Partial derivatives}
%
% The partial derivatives are all variations on the theme of |\pard|,
% which is as |\dd|, replacing the $d$ with $\partial$.
%    \begin{macrocode}
\newcommand{\pard} [2]{\frac{\partial#1}{\partial#2}}
\newcommand{\pardx}[1]{\pard{#1}{x}}
\newcommand{\pardy}[1]{\pard{#1}{y}}
\newcommand{\pardz}[1]{\pard{#1}{z}}
\newcommand{\pardu}[1]{\pard{#1}{u}}
\newcommand{\pardv}[1]{\pard{#1}{v}}
\newcommand{\pardt}[1]{\pard{#1}{t}}

\newcommand{\spard} [2]{\frac{\partial^2#1}{\partial#2^2}}
\newcommand{\spardx}[1]{\spard{#1}{x}}
\newcommand{\spardy}[1]{\spard{#1}{y}}
\newcommand{\spardz}[1]{\spard{#1}{z}}
\newcommand{\spardu}[1]{\spard{#1}{u}}
\newcommand{\spardv}[1]{\spard{#1}{v}}
\newcommand{\spardt}[1]{\spard{#1}{t}}

\newcommand{\spardxy}[1]{\frac{\partial^2#1}{\partial x\partial y}}
\newcommand{\spardyx}[1]{\frac{\partial^2#1}{\partial y\partial x}}
\newcommand{\spardxz}[1]{\frac{\partial^2#1}{\partial x\partial z}}
\newcommand{\spardzx}[1]{\frac{\partial^2#1}{\partial z\partial x}}
\newcommand{\spardyz}[1]{\frac{\partial^2#1}{\partial y\partial z}}
\newcommand{\spardzy}[1]{\frac{\partial^2#1}{\partial z\partial y}}
%    \end{macrocode}
%\iffalse
%</deriv>
%<*math>
%\fi
%
% \subsubsection{Integrals}
%
% We load the integrals in if they are requested.
%    \begin{macrocode}
\if@integrals
  \InputIfFileExists{cjwinteg.tex}{}{%
    \PackageWarning{cjwmath}{Option `cjwinteg.tex' not found.}
    \@@integralsfalse}
\fi
%    \end{macrocode}
%\iffalse
%</math>
%<*integ>
%\fi
%
% The first macro is simply a variation of |\int| using the |\limits|
% macro. 
%    \begin{macrocode}
\def\integ{\mathop{\int}\limits}
%    \end{macrocode}
% Next we have a small shortcut for the differential at the end of an
% integral.  We work around \LaTeX's font encoding macro.
%    \begin{macrocode}
\alias\latex@d\d
  \renewcommand{\d}{\,d}
%    \end{macrocode}
% We have macros for double and triple integrals, with and without
% |\limits|.
%    \begin{macrocode}
\newcommand{\dint}{\int\!\!\!\int}
\newcommand{\dinteg}{\mathop{\int\!\!\!\int}\limits}
\newcommand{\tint}{\int\!\!\!\int\!\!\!\int}
\newcommand{\tinteg}{\mathop{\int\!\!\!\int\!\!\!\int}\limits}
%    \end{macrocode}
% To be honest, I have no idea why I wrote this one.  It is probably
% buried in a homework file of mine somewhere, but I'll be a fiddler
% crab if I can remember where\dots
%    \begin{macrocode}
\newcommand{\flushintlim}[1]{{\phantom{#1} #1}}
%    \end{macrocode}
%\iffalse
%</integ>
%<*math>
%\fi
%
% \subsection{Algebra}
%
% We define how to typeset an algebra.
%    \begin{macrocode}
\alias\alg\mathbbm
%    \end{macrocode}
%
% \subsubsection{Fields}
%
% A field will also be done in blackboard bold.
%    \begin{macrocode}
\alias\field\mathbbm
%    \end{macrocode}
% The following fields are defined.
%    \begin{macrocode}
\newcommand{\C}{\field{C}}      % Complex
\newcommand{\E}{\field{E}}      % Euclidean (also Evens)
%    \end{macrocode}
% Note that $\H$ is a \LaTeX{} accent, so we save it away before
% redefining it as a field.
%    \begin{macrocode}
\alias\latex@H\H                % Quaternions
  \renewcommand{\H}{\field{H}}	%   (Hamiltonian field)
\newcommand{\N}{\field{N}}	% Natural numbers
\newcommand{\Q}{\field{Q}}	% Rationals
\newcommand{\R}{\field{R}}	% Reals
% \newcommand{\Rn}[1][n]{\R^{#1}}
\newcommand{\Z}{\field{Z}}	% Integers
\newcommand{\pr}{\field{P}}	% Primes
%    \end{macrocode}
%
% \subsubsection{Groups}
%
% Remember |\NewMathOp|?  One use for it is in defining mathematical
% groups.  Here are a bunch.
%    \begin{macrocode}
% Groups are typeset as operators.
\NewMathOp           {\Aut}{Aut}	% Automorphisms
\NewMathOp           {\End}{End}	% Endomorphisms
\NewMathOp           {\GL}{GL}		% General Linear
\NewMathOp           {\Inn}{Inn}	% Inner products
\NewMathOp           {\Pin}{Pin}	% Pin
\NewMathOp           {\SL}{SL}		% Special Linear
\NewMathOp           {\SO}{SO}		% Special Orthogonal
\NewMathOp           {\SU}{SU}		% Special Unitary
\NewMathOp[\mathfrak]{\Sn}{S}		% Symmetric
\NewMathOp           {\Spin}{Spin}	% Spin
\NewMathOp           {\Sp}{Sp}		% Symplectic
\NewMathOp           {\Unit}{U\kern 0pt}% Unitary
\NewMathOp           {\Orth}{O\kern 0pt}% Orthogonal
\NewMathOp[\mathfrak]{\slin}{sl}        % Tangent group to SL
\NewMathOp[\mathfrak]{\so}{o\kern 0pt}  % skew orthogonal
\NewMathOp[\mathfrak]{\sp}{sp}          % skew symplectic
\NewMathOp[\mathfrak]{\su}{u\kern 0pt}  % skew hermitian
%    \end{macrocode}
%
% \subsubsection{Linear algebra}
%
% If matrices are to be typeset specially, we will use the |\mathcal| font.
%    \begin{macrocode}
\alias\mtx\mathcal
%    \end{macrocode}
% I have often seen the letter $\Theta$ used for the matrix of zeros.
% I like it that way.
%    \begin{macrocode}
\newcommand{\nullmtx}{\mtx\Theta}
%    \end{macrocode}
% Taken from Horn and Johnson, a matrix norm can be represented with a
% triple-bar delimiter.
%    \begin{macrocode}
\newcommand{\mnorm}[1]{%
  \left\vert\kern-0.9pt\left\vert\kern-0.9pt\left\vert #1
    \right\vert\kern-0.9pt\right\vert\kern-0.9pt\right\vert}
%    \end{macrocode}
% We define the Lie product of two matrices.
%    \begin{macrocode}
\newcommand{\lie}[1]{\squarebrackets{#1}}
%    \end{macrocode}
% There is an for the trace (Spur, auf Deutsch) of a matrix\dots
%    \begin{macrocode}
\NewMathOp{\Spur}{Spur}
\NewMathOp{\Tr}{Tr}
%    \end{macrocode}
% \dots as well as for diagonal matrices.
%    \begin{macrocode}
\NewMathOp{\Diag}{Diag}
%    \end{macrocode}
%
% This is a shortcut for putting delimiters around matrices.  With
% AMS-\LaTeX, we use an environment, taking as its two mandatory
% arguments the left and right delimiters, respectively.
%    \begin{macrocode}
\if@amsmath
  \newenvironment{arbmatrix}[2]%
    {\def\@tempa{#2}\left#1 \matrix}{\endmatrix \right\@tempa}
%    \end{macrocode}
% Without AMS, we use a command as does standard \LaTeX, and define
% some basic types.
%    \begin{macrocode}
\else
  \newcommand{\arbmatrix}[3]{\left#1 \matrix{#2} \right#3}
  \providecommand{\bmatrix}[1]{\arbmatrix[{#1}]}
  \providecommand{\vmatrix}[1]{\arbmatrix|{#1}|}
\fi
%    \end{macrocode}
%
% The next bit of code is used to enter sparse matrices which are
% often represented in the literature with an oversized zero marking
% the region of zeros.  This takes more than a bit of trickery in
% \LaTeX.  The oversized digit will be put in a box, which in most
% cases needs horizontal and/or vertical adjustment from the position
% where it is placed in the matrix by default.  The default vertical
% offset will be called |\numoffset|, and is set by default to the
% height of a |\Bigmathstrut|.
%    \begin{macrocode}
\newlength{\numoffset}
{\setbox0=\hbox{$\Bigmathstrut$}
 \@tempdima=0.8\ht0\relax
 \global\numoffset\@tempdima}
%    \end{macrocode}
% Occasionally, one might wish to use something other than a zero as
% the oversized digit.  We define a generic |\Number| macro to be
% used.  The usage is
%   \begin{display}{l}
% |\Number|\oarg{raise}\marg{num}
%   \end{display}
% where \meta{raise} is the amount by which the number is raised and
% \meta{num} is the number to be used.
%    \begin{macrocode}
\newcommand{\Number}[2][-\numoffset]{%
  \@tempdima=#1\relax
  \smash{\hbox{\raise\@tempdima\@bignumber{#2}}}}
%    \end{macrocode}
% The macros |\@bignumber| is called to do the dirty work of
% typesetting the number.
%    \begin{macrocode}
\newcommand{\@bignumber}[1]{\hbox{\LARGE$#1$}}
%    \end{macrocode}
% Now, the horizontal adjustment mentioned earlier usually refers to
% the need to have the large digit straddle two columns in a matrix.
% This is easily accomplished with |\multicolumn|.  Here things start
% to get ugly, though; |\multicolumn| must be the first thing after
% the |&| in the array.  But the reasonable way to include an optional
% argument to be passed through to |\Number| is to use the
% |\newcommand| feature, which ends up putting junk in the way---this
% is exactly the same problem which arose in writing |\mathbox|
% earlier.  Therefore, there are currently two separate commands, one
% which takes the optional argument, and one which doesn't.  I would
% really like to remedy this if I ever figure out how.
%    \begin{macrocode}
\def\bignumber    #1{\multicolumn{2}{c}{\Number{#1}}}
\def\Bignumber[#1]#2{\multicolumn{2}{c}{\Number[#1]{#2}}}
%    \end{macrocode}
% Here are some specific cases for using zero, as is most commonly the
% case.
%    \begin{macrocode}
\newcommand{\Zero}[1][-\numoffset]{\Number[#1]{0}}
\def\bigzero    {\bignumber{0}}
\def\Bigzero[#1]{\Bignumber[#1]{0}}
%    \end{macrocode}
% 
% From this we wish to construct various types of matrices.  Each
% variation will have two versions, depending on whether or not
% AMS-\LaTeX{} has been invoked.  Each version, though, has an
% optional argument which is what will be passed through as
% \meta{raise} to |\Bigzero|.  The names of each matrix are an attempt
% to indicate the layout.  For example, the command |\iidiagi| takes
% three mandatory arguments which will be the diagonal entries, the
% first two in the upper left, and the third in the lower right with
% |\ddots| separating them.  Likewise, we have |\idiagii| and
% |\idiagi|. 
%    \begin{macrocode}
\if@amsmath
  \newcommand{\iidiagi}[4][-\numoffset]{%       % 2     0       
    \begin{bmatrix}                             %   3           
       #2 &        &    \Bigzero[#1] \\         %     .         
          &     #3 &        &        \\         %       .       
      \Bigzero[#1] & \ddots &        \\         %   0     4     
          &        &        &    #4                             
    \end{bmatrix}}
  \newcommand{\idiagii}[4][-\numoffset]{%       % 2     0       
    \begin{bmatrix}                             %   .           
       #2 &        & \Bigzero[#1] \\            %     .         
          & \ddots &     &        \\            %       3       
      \Bigzero[#1] &  #3 &        \\            %   0     4     
          &        &     &    #4                                
    \end{bmatrix}}
  \newcommand{\idiagi}[3][-1.2pt]{%             % 2     0
    \begin{bmatrix}                             %   .
       #2 &         \Bigzero[#1] \\             %     .
          & \ddots  &            \\             %       .
      \Bigzero[#1]  &    #3                     %   0     3
    \end{bmatrix}}
\else
  \newcommand{\iidiagi}[4][-\numoffset]{%       % 2     0
    \matrix{%                                   %   3           
       #2 &        &    \Bigzero[#1] \\         %     .         
          &     #3 &        &        \\         %       .        
     \Bigzero[#1] & \ddots &        \\          %   0     4     
          &        &        &    #4}}                           
  \newcommand{\idiagii}[4][-\numoffset]{%                        
    \pmatrix{%                                  % 2     0       
       #2 &        & \Bigzero[#1] \\            %   .           
          & \ddots &     &        \\            %     .         
      \Bigzero[#1] &  #3 &        \\            %       3       
          &        &     &    #4}}              %   0     4
                                  %
  \newcommand{\idiagi}[3][-1.2pt]{%             % 2     0
    \pmatrix{%                                  %   .
       #2 &         \Bigzero[#1] \\             %     .
          & \ddots  &            \\             %       .
      \Bigzero[#1]  &    #3}}                   %   0     3
\fi                                             
%    \end{macrocode}
%
% We now wish to typeset the transpose of a matrix.  The most general
% form is
%   \begin{display}{l}
% |\@trans|\oarg{pre}\marg{post}
%   \end{display}
% which expands to `|^{|\meta{pre}|t|\meta{post}|}|'.  Next is
% |\trans| which takes a single optional argument for \meta{post} (no
% \meta{pre}).
%    \begin{macrocode}
\newcommand{\@trans}[2][]{^{#1\text{\normalfont\textsf{t}}#2}}
\newcommand{\trans} [1][]{\@trans[]{#1}}
%    \end{macrocode}
% Why?  I don't know---I needed |\trinv|, below, and decided to
% generalize.
%    \begin{macrocode}
\newcommand{\trinv}      {\@trans[-]{}}
%    \end{macrocode}
% For backwards compatibility, I have |\ct|\marg{mtx} to represent
% matrix \meta{mtx} as conjugated and transposed.
%    \begin{macrocode}
\newcommand{\ct}[1]{\conj{#1}\trans}
%    \end{macrocode}
%
% The next topic is vectors.  I prefer |\vec| to be logical markup as
% opposed to a specific accent.  Thus, I create an alias |\sarvec|
% (short arrow vector) for the original |\vec|, and another alias
% |\arvec| for a long arrow, which is just |\overrightarrow|.
%    \begin{macrocode}
\alias\sarvec\vec
\alias\arvec \overrightarrow
%    \end{macrocode}
% The actual typesetting I prefer for vectors (when I use anything at
% all) is boldface.  This requires the |\Mathbox| command defined
% earlier so that the argument can be set in a bold math version.
%    \begin{macrocode}
\renewcommand{\vec}[1]{\Mathbox{\boldmath}{#1}}
%    \end{macrocode}
% To typeset vectors in long form simply uses the |\matrix|
% command---but this depends, again, on whether AMS-\LaTeX{} is being
% used.  In either case, a single argument---the contents of the
% vector---is required.  Simply delimit with |\\| for column vectors
% and |&| for rows.
%    \begin{macrocode}
\if@amsmath
  \newcommand{\bvec}[1]{%
    \begin{bmatrix}#1\end{bmatrix}}
  \newcommand{\pvec}[1]{%
    \begin{pmatrix}#1\end{pmatrix}}
%    \end{macrocode}
% There are also two aliases for row vectors for backwards
% compatibility. 
%    \begin{macrocode}
  \alias\brvec\bvec
  \alias\prvec\pvec
\else  
  \newcommand{\bvec}[1]{\bmatrix{#1}}
  \newcommand{\pvec}[1]{\pmatrix{#1}}
% \newcommand{\bvec}[2][r]{%
%   \left[ \begin{array}{#1}#2\end{array} \right]}
% \newcommand{\pvec}[2][r]{%
%   \left( \begin{array}{#1}#2\end{array} \right)}
\fi
%    \end{macrocode}
% The null vector, like the null matrix, is given with $\theta$.
%    \begin{macrocode}
\newcommand{\nullvec}{\vec{0}}
%    \end{macrocode}
% Once we have vectors, we need dot products.  The simple version just
% puts its argument inside angled brackets.
%    \begin{macrocode}
\newcommand{\dotp}[1]{\anglebrackets{#1}}
%    \end{macrocode}
% If special vector notation is required, the two arguments should be
% separated by a comma (which should be the case anyway), and then
% each half is passed to |\vec|.
%    \begin{macrocode}
\newcommand{\vdotp}[1]{\@vdotp#1@@@}
\def\@vdotp #1,#2@@@{\dotp{\vec #1,\vec #2}}
%    \end{macrocode}
% 
% We define some other vector operators to go with the dot product.
% These are the curl, the divergence, and the Laplacian.  These are
% usually read as `del dot', `del cross', and `del squared', so the
% first thing to do is rename the |\nabla|(?).
%    \begin{macrocode}
\newcommand{\del}  {\vec\nabla}
%    \end{macrocode}
% \LaTeX{} defines |\div|, so we rename that and renew the command.
%    \begin{macrocode}
\alias\@@div\div
\renewcommand{\div}{\del\dot}
%    \end{macrocode}
% Finally, we have the other two.
%    \begin{macrocode}
\newcommand{\curl} {\del\cross}
\newcommand{\lapl} {\del^2}
%    \end{macrocode}
%
% In German texts, the linear hull is usually represented as a list of
% vectors in square brackets.
%    \begin{macrocode}
\alias\huelle\squarebrackets
%    \end{macrocode}
% 
% \subsection{Operators}
%
% This section is simply a gathering point for all sorts of
% mathematical operators---not in the |\NewMathOp| sense, like various
% groups defined above, but in the sense of mathematical doohickies
% which take one or two operands and give you something new.
%
% \subsubsection{Binary operators}
%
% What we have first is a whole bunch of names for the large, `x'-like
% times symbol.  In the case of specifying dimension (as in, a 4-by-3
% matrix), we declare it a |\mathord| so as not to invoke binary
% spacing.  Then |\mal| is simply German for `times', and |\cross| is
% the vector space (or group) product using the same symbol.
%    \begin{macrocode}
\newcommand{\by}{\mathord{\times}}
\alias\mal	\times
\alias\cross	\times
%    \end{macrocode}
% To indicate isomorphism, I have most often used an equals sign with
% a tilde above it.
%    \begin{macrocode}
\alias\iso	\simeq
%    \end{macrocode}
% This next one stretches the usefulness of aliasing by defining an
% operator for normal subgroups.
%    \begin{macrocode}
\alias\nsubgrp	\trianglelefteq
%    \end{macrocode}
% Next we specify a congruence symbol.
%    \begin{macrocode}
\realias\cong  	\equiv
%    \end{macrocode}
% In graph theory, we want a symbol for adjacency of nodes.
%    \begin{macrocode}
\alias\adj\leftrightarrow
%    \end{macrocode}
% We unconditionally define |\Box| to be a square operator symbol.
%    \begin{macrocode}
\providecommand{\Box}{}
\renewcommand{\Box}{\mathbin{\square}}
%    \end{macrocode}
% We give a number theoretic division relation, in English and
% German.
%    \begin{macrocode}
\newcommand{\teilt}{\mathbin{|}}
  \alias\divides\teilt
%    \end{macrocode}
% Once upon a time I wanted a `big dot' operator.
%    \begin{macrocode}
% \newcommand{\bdot}{\mathop{\lower0.33ex\hbox{\LARGE$\cdot$}}}
%    \end{macrocode}
% We can use \LaTeX's built-in |\stackrel| to create a definition
% relation. 
%    \begin{macrocode}
\newcommand{\defeq}{\stackrel{\text{def}}{=}}
%    \end{macrocode}
% The symbol I first saw used to indicate disjoint union was a union
% `cup' with a bar through the middle.  Using a naming convention
% similar to AMS-\LaTeX's |\Uplus| we get text and display versions.
%    \begin{macrocode}
\newcommand{\uminus}{%
  \,\,{\mathbin{\cup\kern-.6em{\raise.05em%
  \hbox{-\negthinspace-\kern-.25em-}}}}\,\,}
\newcommand{\Uminus}{%
  \mathop{\bigcup\kern-0.9em{\raise.05em%
  \hbox{-\negthinspace-\kern-.25em-}}}}
%    \end{macrocode}
% We define some handy names for various arrows.
%    \begin{macrocode}
\providecommand{\implies}{\;\Longrightarrow\;}
  \alias\then\implies
\if@amsmath
  \newcommand{\when}{\DOTSB \;\Longleftarrow \;}
\else
  \newcommand{\when}{\;\Longleftarrow \;}
\fi
%    \end{macrocode}
% The following can be used when tracing a series of implications
% through a multiline equation environment, for example.
%    \begin{macrocode}
\newcommand{\limplies}{\llap{$\implies$}\quad}
%    \end{macrocode}
% Based on \emph{The \TeX{}book}, I have written a `skewed' fraction,
% which uses a diagonal separator.
%    \begin{macrocode}
\newcommand{\sfrac}[2]{%
  \hbox{\kern 0.1em%
  \raise 0.5ex\hbox {\scriptsize$#1$}%
  \kern -0.1em $/$%
  \kern -0.15em%
  \lower 0.25ex\hbox {\scriptsize$#2$}}%
  \kern  0.2em}
%    \end{macrocode}
% If we are not using AMS-\LaTeX, the following well not yet be
% defined.
%    \begin{macrocode}
\providecommand{\tfrac}{\sfrac}
\providecommand{\dfrac}[2]{{{#1}\over{#2}}}
%    \end{macrocode}
%
%
% \subsubsection{Unary operators}
%
% I most often use the longer versions of various math accents, so I
% redefine them by default to be long.  The short ones are saved in a
% macro with identical name save for a prepended `s' (as we have
% already seen for |\arvec| and |\sarvec|).  The simple ones are bars,
% tildes, and hats.
%    \begin{macrocode}
\alias\sbar\bar
  \renewcommand{\bar}[1]{\overline{#1}}
\alias\stilde\tilde
  \alias\retilde\widetilde
\alias\shat\hat
  \realias\hat\widehat
%    \end{macrocode}
% We need something better than the default real- and imaginary-part
% macros. 
%    \begin{macrocode}
\renewcommand{\Im}{%
  \mathop{\mathfrak{Im}}}
\renewcommand{\Re}{%
  \mathop{\mathfrak{Re}}}
%    \end{macrocode}
% Complex conjugation is usually denoted by a bar.
%    \begin{macrocode}
\alias\conj  \bar
%    \end{macrocode}
% Inversion of various types is used often enough to warrant a control
% sequence.
%    \begin{macrocode}
\newcommand{\inv}{^{-1}}
%    \end{macrocode}
% To denote power sets, I have used to different alternatives.  The
% default is the standard |\wp| symbol---I don't know what it is
% supposed to be used for, but it can be modified for the task.  On
% the other hand, if we have a real math script font (as one might
% have if using my \pkg{callig} style\dots) we will certainly use
% that. 
%    \begin{macrocode}
\@ifundefined{mathscript}
  {\newcommand{\Pow}{\raise 0.4ex\Mathbox{\Large}{\wp}}}
  {\NewMathOp[\mathscript]{\Pow}{P}}
%    \end{macrocode}
% And what macro would be complete without a German alias?  (Auf
% Deutsch, die Potenzmenge.)
%    \begin{macrocode}
\alias\Pot\Pow
%    \end{macrocode}
% We can leave the letter `\/I\/' to computer scientists who don't
% know how to write an indicator function.  For our purposes, we want
% the neat-o-keen blackboard bold font.
%    \begin{macrocode}
\newcommand{\1}{\mathbbm{1}}
%    \end{macrocode}
%
% Next we have some trigonometric shortcuts.
%    \begin{macrocode}
\alias\acos\arccos
\alias\asin\arcsin
\alias\atan\arctan
%    \end{macrocode}
% Using our generic bracketing macros from earlier, we have absolute
% value, cardinality (order of a set), cyclic generators, and norms.
%    \begin{macrocode}
\alias\abs \vertbrackets
\alias\ord \abs
\alias\cyc \anglebrackets
\alias\norm\Vertbrackets
%    \end{macrocode}
% 
% Multiple sums are recurrent enough (no pun intended \smiley) to get
% macros.  We have double sums, triple sums, and $n$-fold sums.
%    \begin{macrocode}
\newcommand{\dsum}{\mathop{\sum\sum}\limits}
\newcommand{\tsum}{\mathop{\sum\sum\sum}\limits}
\newcommand{\nsum}{\mathop{\sum\sum\cdots\sum}\limits}
%    \end{macrocode}
%
% The next two macros indicate monotone limits, respectively ascending
% (mnemonic `limit up') and descending (you guessed it---`limit
% down').
%    \begin{macrocode}
\NewMathOp*{\ulim}{lim\raise0.4ex\mathbox{\mathord{\smash{\uparrow}}}}
\NewMathOp*{\dlim}{lim\raise0.4ex\mathbox{\mathord{\smash{\downarrow}}}}
%    \end{macrocode}
%
% 
% Finally we have the miscellany, where we can really go to town with
% |\NewMathOp|!  These should be pretty clear, unless you don't do
% math in German, in which case some will be pretty odd.
%    \begin{macrocode}
\NewMathOp*{\argmax}{arg\,max}          % arg min
\NewMathOp*{\argmin}{arg\,min}          % arg min
\NewMathOp {\Aff}   {Aff}               % Affine hull
\NewMathOp {\Bild}  {Bild}              % Bild
\NewMathOp {\Cone}  {Cone}              % Cone
\NewMathOp {\Conv}  {Conv}              % Convex hull
\NewMathOp {\Core}  {Core}              % Fuzzy set core
\NewMathOp {\diam}  {diam}              % diameter
\NewMathOp {\dom}   {dom}               % Domain
\NewMathOp {\Epi}   {Epi}               % Epigraph
\NewMathOp*{\esssup}{ess\,sup}          % Essential supremum
\NewMathOp {\fl}    {fl}                % float-point
\NewMathOp {\ggT}   {ggT}               % ggT
\NewMathOp {\Grad}  {Grad}              % Grad
\NewMathOp {\Hypo}  {Hypo}              % Hypograph
\NewMathOp {\Int}   {Int}               % Interior
\NewMathOp {\Kern}  {Kern}              % Kernel
\NewMathOp {\kgV}   {kgV}               % kgV
\NewMathOp {\Lin}   {Lin}               % Linear hull
\NewMathOp {\lcm}   {lcm}               % LCM
\NewMathOp {\Ord}   {Ord}               % order
\NewMathOp {\proj}  {proj}              % Projection
\NewMathOp {\Rang}  {Rang}              % Rang
\NewMathOp {\range} {range}             % Range
\NewMathOp {\Rank}  {Rank}              % Rank
\NewMathOp {\rot}   {rot}               % Rotation
\NewMathOp {\Span}  {Span}              % Span
\NewMathOp {\val}   {val}               % value
%    \end{macrocode}
% 
% 
% \subsection{Physics}
%
% Now, since physics is a subset of mathematics, physics macros are
% invoked from within the math macro file.
%    \begin{macrocode}
\if@physics
  \InputIfFileExists{cjwphys.tex}{}{%
    \PackageWarning{cjwmath}{Option `cjwphys.tex' not found.}
    \@@physicsfalse}
\fi
%    \end{macrocode}
%\iffalse
%</math>
%<*phys>
%\fi
%
% The only thing really specific to physics that I ever used---meaning
% not applicable in any more general mathematical setting---was the
% bra/ket notation.  Here we have bras (br\ae?), kets, and brakets,
% the latter of which bear uncoincidental resemblance to the |\set|
% macro.
%    \begin{macrocode}
\newcommand{\bra}[1]{\left\langle #1 \right|\,}
\newcommand{\ket}[1]{\,\left| #1 \right\rangle}

\newcommand{\braket}[2]{%
  \newdimen\@tempdimd%
  \setbox0=\mathbox{#1}\@tempdima=\ht0 \@tempdimb=\dp0%
  \setbox0=\mathbox{#2}\@tempdimc=\ht0 \@tempdimd=\dp0%
  \ifdim\@tempdimc > \@tempdima
    \@tempdima=\@tempdimc
  \fi
  \ifdim\@tempdimd > \@tempdimb
    \@tempdimb=\@tempdimb
  \fi
  \def\@tempa{\vrule width0pt height\@tempdima depth\@tempdimb}
  \left.\left\langle \@tempa{#1} \,\right|\,{#2} \right\rangle }
%    \end{macrocode}
%\iffalse
%</phys>
%<*math>
%\fi
%
%
% \subsection{Probability}
%
% Here comes that |\NewMathOp| thingie again.  First thing is to
% define some standard probabilistic operators, which really need to
% be typeset in an operator font in order not to look horrible.
%    \begin{macrocode}
\NewMathOp{\Prob} {P}                   % Probability operator
\NewMathOp{\Corr} {Corr}                % Correlation
\NewMathOp{\Cov}  {Cov}                 % Covariance
\NewMathOp{\Expct}{E}                   % Expectation
\NewMathOp{\SD}   {SD}                  % Standard Deviation.
\NewMathOp{\Var}  {Var}                 % Variance
%    \end{macrocode}
% Here is a macro to put inside of some of those operators where
% conditional events are being considered.
%    \begin{macrocode}
\newcommand{\given}{\,|\,}
%    \end{macrocode}
% Usually a single tilde, which as an operator bears the name of
% |\sim| in \LaTeX, indicates a distribution.  Hence, we make an
% alias.
%    \begin{macrocode}
\alias\distrib\sim
%    \end{macrocode}
% And coming back to |\NewMathOp|, we define some standard
% distributions\dots
%    \begin{macrocode}
\NewMathOp{\Bin} {Bin}                  % Binary dist.
  \newcommand{\Nbin}{-\!\Bin}           % Negative Binom.
\NewMathOp{\Exp} {Exp}                  % Exponential dist.
\NewMathOp{\Geom}{Geom}                 % Geometric dist.
\NewMathOp{\Norm}{Norm}                 % Normal dist.
\NewMathOp{\Poi} {Poi}                  % Poisson dist.
\NewMathOp{\Unif}{Unif}                 % Uniform dist.
%    \end{macrocode}
% \dots and the normal density and distribution functions (which might
% also be represented as $\Phi$ and $\phi$).
%    \begin{macrocode}
\NewMathOp[\mathfrak]{\Ndens}{N}
\NewMathOp[\mathfrak]{\Ndist}{n}
%    \end{macrocode}
% The last thing to do is create some macros for probabilistic modes
% of convergence.  We go, again, from the general to the specific.
%    \begin{macrocode}
\NewMathOp*{\@mapsto}{\mapstochar\rightarrow}
\newcommand{\@probconv}[1]{\mathrel{\@mapsto\limits^{1}}}
  \newcommand{\asconv}{\@probconv{a.s.}}        % Almost sure conv.
  \newcommand{\inprob}{\@probconv{P}}           % Conv. in probability
  \newcommand{\inlaw} {\@probconv{L}}           % Conv. in law
  \newcommand{\vague} {\@probconv{v}}           % Vague conv.
%    \end{macrocode}
%
% \iffalse
%
%</math>
%
% \fi
%
%
% \section{Units}
%
% \iffalse
%
%<*units>
%
% \fi
%
% The package \pkg{cjwunits} simply standardizes how to typeset units
% (or dimensions---things such as seconds, meters, and so forth).
% Most of the work is done by defining a pretty simple macro,
% |\unit|.  The rest is just a collection of standard units which may
% be invoked (meaning ones I have used, and therefore stuck into the
% file).
%
% \subsection{Package initialization}
%
% The initialization does most everything.  We first specify a font
% for the unit types.
%    \begin{macrocode}
\newcommand{\unitfont}{\operator@font}
%    \end{macrocode}
% Now the workhorse of the package is defined.  It is pretty
% foolproof, in that it can be invoked in or out of math, may or may
% not be followed by explicit space, and the font as defined above is
% pretty customizable.
%    \begin{macrocode}
\newcommand{\unit}[1]{\ensuremath{\,{\unitfont{#1}\kern\z@}}\xspace}
%    \end{macrocode}
%
% Now come the examples.
%
% \subsection{Distance}
%    \begin{macrocode}
\newcommand{\ang} {\unit{\AA}}                  % angstroms
  \alias\Ao\ang
\newcommand{\cm}  {\unit{cm}}                   % centimetres
\newcommand{\inch}{\unit{in}}                   % inches
\newcommand{\km}  {\unit{km}}                   % kilometres
\newcommand{\mi}  {\unit{mi}}                   % miles
\newcommand{\m}   {\unit{m}}                    % metres
%    \end{macrocode}
%
% \subsection{Electricity and magnetism}
%
%    \begin{macrocode}
\newcommand{\Hz}  {\unit{Hz}}                   % herz
\newcommand{\J}   {\unit{J}}                    % joules
\newcommand{\V}   {\unit{V}}                    % volts
\newcommand{\eV}  {\unit{eV}}                   % electron volts
\newcommand{\erg} {\unit{erg}}                  % ergs
%    \end{macrocode}
%
% \subsection{Mass}
%
%    \begin{macrocode}
\newcommand{\amu} {\unit{amu}}                  % atomic mass units
\newcommand{\gram}{\unit{g}}                    % grams
\newcommand{\kg}  {\unit{kg}}                   % kilograms
\newcommand{\Ton} {\unit{T}}                    % tons
\newcommand{\kT}  {\unit{kT}}                   % kilotons
\newcommand{\MT}  {\unit{MT}}                   % megatons
%    \end{macrocode}
%
% \subsection{Thermodynamics}
%
%    \begin{macrocode}
\newcommand{\kelv}{\unit{K}}                    % kelvins
%    \end{macrocode}
%
% \subsection{Time}
%
% It seems that |\sec| already means secant, so we need a preservation
% and renewal here.
%    \begin{macrocode}
\alias\secant\sec
\renewcommand{\sec} {\unit{s}}                  % seconds
%    \end{macrocode}
%
% \subsection{Velocity}
%
%    \begin{macrocode}
\newcommand{\cee} {\unit{c}}                    % speed o' light
%    \end{macrocode}
%
% \iffalse
%
%</units>
%
% \fi