summaryrefslogtreecommitdiff
path: root/info/dickimaw/src/novices/dickimaw-novices.tex
blob: 0b1ce901b1ce38fa71f49b2c434390e5a024097f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
% This is part of the source code for "LaTeX for Complete Novices"
% It includes some code that was used to generate other formats of
% this tutorial that aren't included in this distribution. That code
% will be skipped by the current class settings.

% arara: pdflatex
% arara: bibtex
% arara: makeglossaries
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: makeindex: { style: novices-index.ist }
% arara: pdflatex
% arara: pdflatex
% arara: pdflatex
% arara: pdflatex
% arara: makeindex: { style: novices-index.ist }
% arara: pdflatex

% Multiple pdflatex runs are required to ensure the flow frame switches occur
% correctly before and after the summary and index
\documentclass[report]{novices}

\usepackage{fancybox}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing}
\usepackage{caption,subcaption}
\usepackage{makeidx}
\usepackage{alltt}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{pifont}

\usepackage{cmap}

\usepackage[utf8]{inputenc}
\usepackage[math]{anttor}
\usepackage{libris}
\renewcommand*{\ttdefault}{txtt}

\newcommand*{\docdate}{\formatdate{25}{9}{2012}}

\authordetails{1970}{Talbot}{Nicola L.~C.}
\title[LaTeX for Complete Novices]{\LaTeX\ for Complete Novices}
\version{1.4}
\edition{1}
\volume{1}
\series{The Dickimaw \LaTeX\ Series}
\seriesurl{http://www.dickimaw-books.com/latex/}
\affiliation
 {Dickimaw Books}
 {http://www.dickimaw-books.com/}
 {Saxlingham Nethergate}
\keywords{LaTeX,beginners,introduction,typesetting}
\subject{LaTeX}
\date{\docdate}

\html{\input{htmlonly}}

\makeindex
\makeglossaries

\input{keywords}
\input{glsentries}

\newacr{ctan}{CTAN}
 {the Comprehensive \TeX\ Archive Network}
 {http://mirror.ctan.org/}

\newacr{tug}{TUG}%
 {\TeX\ User Group}%
 {http://tug.org/}

\newacr{uktug}{UK TUG}%
 {UK \TeX\ User Group}%
 {http://uk.tug.org/}

\newacr{ukfaq}{UK FAQ}%
 {UK List of \TeX\ Frequently Asked Questions}%
 {http://www.tex.ac.uk/faq}

\newacrx{tds}{TDS}{\TeX\ Directory Structure}

\newacrnocite{gui}{GUI}{graphical user interface}

\definecolor{midgray}{gray}{0.4}

\indexpreamble{\latexhtml{Page numbers}{Locations} in \textit{italic} indicate the primary
reference. \latexhtml{Page numbers}{Locations} in \textbf{bold} indicate the entry
definition in the summary.}

\newcommand{\xtableref}[1]{\objectref{Table}{#1}}

% \figconts[graphics opts]{image}{caption}{label}
\newcommand{\figconts}[4][]{%
  \begin{makeimage}\end{makeimage}\figuretop{#4}
  \centering
  \incPgfOrGraphics[#1]{#2}%
  #3% caption
  \label{#4}%
}

\newcommand{\latexbook}{\emph{\LaTeX: A Document Preparation System}~\cite{lamport94}}
\newcommand{\latexcomp}{\emph{The \LaTeX\ Companion}~\cite{goossens94}}
\newcommand{\latexguide}{\emph{A Guide to \LaTeX}~\cite{kopka95}}
\newcommand{\latexgraphic}{\emph{The \LaTeX\ Graphics Companion}~\cite{goossens97}}
\newcommand{\latexweb}{\emph{The \LaTeX\ Web Companion}~\cite{goossens99}}

\newcommand{\baseurl}{http://www.dickimaw-books.com}
\newcommand{\packageurl}{\baseurl/latex/packages}
\newcommand{\exerciseurl}{\baseurl/latex/novices/html/exercises}

\newcommand{\pderiv}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\e}{\mathrm{e}}

\newcommand{\koma}{KOMA-Script}

\newcommand*{\backcovertext}{If you choose to buy a copy of this book, 
Dickimaw Books asks for your support through buying the Dickimaw
Books edition to help cover costs.}

\copyrighttext{%
  Copyright \textcopyright\ 2004  Nicola L.~C. Talbot

  Permission is granted to copy, distribute and/or modify this
  document under the terms of the GNU Free Documentation License,
  Version 1.2 or any later version published by the Free Software
  Foundation; with no Invariant Sections, no Front-Cover Texts, and
  one Back-Cover Text: \dq{\backcovertext} A copy of the license is included in
  the section entitled \htmlref{\dq{GNU Free Documentation
  License}}{sec:fdl}.

  \doifnotbook
  {%
     The base URL for this document is: \url{\baseurl/latex/novices/}
  }%
}

\renewcommand{\glossaryname}{Summary}

\begin{document}
\maketitle

\frontmatter
\setcounter{tocdepth}{2}
\setnode{contents}
\tableofcontents
\setnode{listoffigures}
\listoffigures
\setnode{listoftables}
\listoftables

\setnode{listofexercises}
\listofexercises

\mainmatter

%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{introduction}
\chapter{Introduction}
\label{ch:intro}

The aim of this book is to introduce \LaTeX\ to a non-technical
person.  \LaTeX\ is excellent for producing professional looking
documents, however it is a \emph{language} not a word 
processor\faq{Why is TeX not a WYSIWYG system?}{notWYSIWYG}, so
it can take a bit of getting used to, particularly if you have never
had any experience using programming languages.  

\LaTeX\ does take a while to learn, so why should you use it? Here are
a few reasons but it is not an exhaustive list:

\LaTeX\ is far better at typesetting mathematical equations
than word processors. I~wrote my Ph.D. thesis back in the days of
\LaTeX2.09 (the old version of \LaTeX) and given the high quantity of
mathematics that I~had to typeset, it would have taken me considerably
longer to write it in a word processor, and the resulting document
wouldn't have looked nearly as good. Even Microsoft have
acknowledged \glsterm{tex}'s high-quality mathematical
typography~\cite{sargentiii}.

\xminisec{Example:}
Here's an equation taken from some kernel survival analysis:
\begin{result}[latexintromaths.html]
\newcommand{\me}{\mathrm{e}}
\newcommand{\pfrac}[2]{\frac{\partial #1}{\partial #2}}
\[
\pfrac{^2\mathcal{L}}{{z_i^\rho}^2} =
-\pfrac{\rho_i}{z_i^\rho}\left(\pfrac{v_i}{\rho_i}\frac{\me^{v_i}}{1-\me^{v_i}}
+v_i\frac{\me^{v_i}\pfrac{v_i}{\rho_i}(1-\me^{v_i})+\me^{2v_i}\pfrac{v_i}{\rho_i}}{(1-\me^{v_i})^2}\right)
\]
\end{result}
(You can find out how to create this equation \latexhtml{on
page~\pageref{introeq} in \sectionref{sec:delimiters}}{\htmlref{later}{introeq}}.)

That's all very well and good if you want to typeset some equations,
but if your work doesn't involve maths, does that mean that \LaTeX\
is not for you? Although I~am a mathematician, I~have written plenty
of documents with no maths in at all, including prose, poetry,
newsletters, posters and brochures, but I~still opt for \LaTeX\
because using \LaTeX\ ensures consistent formatting, and the style
of the document can be completely changed by simply using a
different \glsterm{cls}, or loading additional \htmlref{packages}{sec:packages}. This
means that I~can concentrate on writing the document, rather than
worrying about how it will look. It also means that if, after having
written a 200 page document, I~then find that I~need to change all
the figure captions so that they are labelled \dq{Fig} instead of
\dq{Figure}, all I~need to do is edit a single line, rather than
going through 200 pages to individually edit every single figure
caption.\footnote{Sure, you could use a search and replace function,
but a sweeping replace-all can have unexpected side effects. For
example, your document may include the sentence, \dq{Figures from
the last quarter showed improvement}, which would get changed to,
\dq{Figs from the last quarter showed improvement}.}

Serious fiction writers are taught never to remind the reader that
they're reading a book. Poor formatting is just as much a reminder
of this as authorial intrusion.

\LaTeX\ makes it very easy to cross-reference chapters, sections,
equations, figures, tables etc, and it also makes it very easy to
generate a table of contents, list of figures, list of tables,
index, glossary\footnote{Glossaries are covered in \latexthesis.}\ and 
bibliography. You don't need to worry about numbering anything,
as this is done automatically, which means that you can insert new
sections or swap sections around without having to worry about
updating all the section numbering etc. Furthermore, if you use
\BiBTeX\footnote{Automating bibliographies is covered in
\latexthesis.}\ in combination with \LaTeX, and you have, say, 100
or more citations, it doesn't matter if you are then told that the
citations have to be re-ordered (say, in order of citation rather
than alphabetically). All that is required is a minor edit to change
the appropriate style file rather than ploughing through the entire
document changing all the citations by hand.

When you are editing a document using a word processor, the
word processor has to work out how to reformat the document every time
you type something.  If you have a large document with a great many
inserted objects (such as figures and equations), the response to
keyboard input can become very slow.  You may find that after typing
a few words you will have to wait until the computer catches up
before you can see what you have typed.  With \LaTeX\ you type in your
code using an ordinary text editor.  The document 
doesn't get formatted until you pass it to \LaTeX, which means that 
you are not slowed down by constant reformatting.

Lastly, there's the fact that \LaTeX\ follows certain typographical
rules, so you can leave most of the typesetting to \LaTeX. You
rarely need to worry about minor things such as
\glstext{intersentencespacing}. The default is English spacing, but
if you have a publisher who disapproves of this, you can switch if
off with a single command. (See \sectionref{sec:intersentencespacing}.)

\LaTeX\ will also automatically deal with
f-ligatures.\footnote{Ligatures can be suppressed using the
\isty{microtype} package if necessary} That is, if any of the
following combination of letters are found: \texttt{fl},
\texttt{ffl}, \texttt{ff}, \texttt{fi}, \texttt{ffi}, they will
automatically be converted into the corresponding ligatures:
% Using CMR as the ligatures are more noticeable than with anttor.
% make latex2html convert this text into an image
\makeimg{fl ligature}{\cmr{fl}},
\makeimg{ffl ligature}{\cmr{ffl}},
\makeimg{ff ligature}{\cmr{ff}},
\makeimg{fi ligature}{\cmr{fi}},
\makeimg{ffi ligature}{\cmr{ffi}}.
  Note the difference between
\makeimg{fl-ligature u ffi-ligature e r}{\cmr{fluffier}} (2
ligatures) and \makeimg{fluffier}{\cmr{f{}l{}uf{}f{}i{}er}} (no ligatures).  These
points may seem minor but they all contribute towards the impact of
the entire document.  When writing technical documents, the
presentation as well as the content is important.  All too often
examiners or referees are put off reading a document because it is
badly formatted.  This provokes an immediate negative reaction and
provides little desire to look favourably upon your work.

To give you an idea of what you can do with \LaTeX, this book was
written in \LaTeX.\footnote{The source code is available at
\url{\baseurl/latex/novices/}, but it really is
\emph{not} the place to start if you are a beginner, as it contains
\LaTeX\ and \glsterm{perl} code beyond the scope of this tutorial.}  The PDF
versions (including \ifbookorother{this}{the} paperback version) were generated using PDF\LaTeX\ and \appname{makeindex} and
the HTML version was generated using the
\latexhtml
 {\LaTeX2HTML\footnote{\url{http://www.latex2html.org/}}}%
 {\htmladdnormallink{\LaTeX2HTML}{http://www.latex2html.org/}}%
\faq{Conversion from (La)TeX to HTML}{LaTeX2HTML} converter. 

For more reasons as to why you might want to use \LaTeX\ instead
of a word processor, have a look at
\ifbookorother
  {\url{http://www.ctan.org/what_is_tex.html\#whytex}.}%
  {\htmladdnormallink{Why TeX?}{http://www.ctan.org/what_is_tex.html\#whytex}}

\setnode{texdoc}
\section{Class and Package Documentation}
\label{sec:texdoc}

There are hundreds of \htmlref{classes}{sec:cls} and
\htmlref{packages}{sec:packages} available on \gls{ctan}. These are
made available by many volunteers. Some provide detailed
documentation to accompany their contribution, while others only
provide a few notes in a README file or comments in the source
files. This book only provides an introductory
look at a small selection of these contributions. If you want
further details on how to use a particular class or package you
should check the documentation that accompanies it. You can use the
\iappname{texdoc} application to search for the documentation. This
is a command line application, which means you need a terminal or
command prompt (see \sectionref{sec:terminal}).

To use \appname{texdoc}, you need to
type (at the command prompt) \appname{texdoc} followed by a space followed by the name of
the class or package you want information about. 
For example, to read the \icls{memoir}
documentation, type the following at the \htmlref{command prompt}{sec:terminal} (press the
return/enter key \enter\ at the end of the line):
\begin{verbatim}
texdoc memoir
\end{verbatim}
Some packages come with more than one set of documentation. For
example, the \isty{glossaries} package comes with the main user
manual, a short guide for beginners and the documented code for
advanced users. Just doing
\begin{verbatim}
texdoc glossaries
\end{verbatim}
will display the advanced documented code. To list all available
documentation for a package, use the \texttt{-l} option:
\begin{verbatim}
texdoc -l glossaries
\end{verbatim}
Then type the number corresponding to the file you want to view. If
you can remember the file name (for example \texttt{glossaries-user}) 
you can type that next time you want to view it:
\begin{verbatim}
texdoc glossaries-user
\end{verbatim}
There is also a \glsterm{perl}/Tk-based \gls{gui} called \iappname{texdoctk},
which is distributed with \texdistro{TeX~Live},
that you can use instead of \appname{texdoc} if you can't work out
how to use a \glsterm{terminal} or prefer a \gls*{gui} approach.

Failing that, you can also check on \gls{ctan} using the URL
\texttt{ctan.org\slash pkg\slash}\meta{name}, where \meta{name} is the name of
the package or class. For example, if you want to look up the
documentation for the \icls{memoir} package, you can find it at
\url{http://ctan.org/pkg/memoir} or go to
\url{http://mirror.ctan.org/} and search for the package or class.

Another alternative recently made available is to use the URL
\texttt{texdoc.net\slash pkg\slash}\meta{name}. For example, 
\url{http://texdoc.net/pkg/memoir} will 
fetch the documentation for the \icls{memoir} class.

However, it's better to use \appname{texdoc} or \appname{texdoctk} to 
read the documentation installed with the
class or package on your computer to ensure it
matches the installed class or package version.

Note that it is important to remember that the \glsterm{tex} world is mostly
supported by volunteers. \gls{ctan} itself is maintained by a very small
group (currently two people). It's not like a commercial company
with 24/7 support and hundreds of paid employees constantly updating
the software. At its core, \TeX\ is a community effort. While some
volunteers actively maintain and update their classes or packages,
some people move on to other things and stop maintaining their work.
Occasionally, if the class or package is popular, someone else
might take over maintenance. There is no dedicated helpdesk to go
to, but there are many ways of getting help, see
\appendixref{ch:help}

\setnode{overview}
\section{Overview}

This document is structured as follows:

\begin{description}

\item[\chapterref{ch:def}]
defines terms that will be used throughout this document.  I
strongly suggest that you look through this
\latexhtml{chapter}{section} before you start so that you understand
the terminology used in this document. At the very least, you should
read the first part that details how corresponding input and output
is displayed in this document\dash you need to understand the
difference between \dq{input} (source code) and \dq{output} (how the
source code will appear in the typeset document).\html{ Note that it
is not always possible to reproduce an exact replica of the output
in the HTML version, so if in doubt, look at one of the PDF versions
instead, which can be downloaded from this 
book's \htmladdnormallink{home page}{../index.html}.}

\item[\chapterref{ch:tex2pdf}] details the software that you will
need to use \LaTeX\ and describes how to use the software.

\item[\chapterref{ch:simpledoc}] shows you how to create a very
basic document.  

\item[\chapterref{ch:sections}] 
shows you how to create chapters and other sectional units so that
you end up with a fully structured document.

\item[\chapterref{ch:graphicx}]
shows you how to include external image files and how to scale and
rotate text.

\item[\chapterref{ch:floats}]
describes how to create figures and tables.

\item[\chapterref{ch:newcom}]
describes how to define your own commands, and redefine existing
commands.

\item[\chapterref{ch:maths}] describes how
to typeset mathematics.  

\item[\chapterref{ch:newenv}] describes how to define new
environments.  

\item[\chapterref{ch:counters}]
discusses how numbers are stored in counters, how to change their
values, and how to define your own counter.

\item[\appendixref{ch:installsty}] shows you how
to download and install additional
packages that weren't installed with your \TeX\ distribution.

\item[\appendixref{ch:errors}]
documents possible errors you may encounter, and gives advice on how
to fix them.

\item[\appendixref{ch:help}] gives pointers on where to go for help.

\end{description}

Throughout this document there are pointers to related topics
in the \gls{ukfaq}.
\latexhtml{These are displayed in the margin in
square brackets, as illustrated on the 
\ifbookorother{\ifthispageodd{right}{left}}{right}.}{%
These are displayed in the text like this:}%
\faq{What is LaTeX?}{latex} You may find these resources useful in
answering related questions that are not covered in this 
book.
\begin{latexonly}
\doifbook{%
  To find the resources, go to \url{http://www.tex.ac.uk/faq} and
  either look for the question title in the list, or enter a keyword
  in the search field.%
}

This book and associated files, including  
solutions to the exercises, are available on-line at:
\url{\baseurl/latex/novices/}. 
\doifnotbook
{%
  The links in this document are colour-coded: internal links are 
  blue, external links are magenta.
}%
\end{latexonly}

\setnode{reading}
\section{Recommended Reading}

This document is designed as an introductory text, not a
comprehensive guide.  For further reading try some of the
following\faq{Books on LaTeX}{latex-books}:

\latexbook\ is the user guide and reference manual for \LaTeX, and
is a good basic text for anyone starting out, however it doesn't
cover AMS\TeX\faq{What are the AMS packages?}{AMSpkg}, so anyone who
needs to typeset more than basic mathematics may prefer either
\latexguide\ or \latexcomp.  Both these books cover AMS\TeX,
\iBiBTeX\ and \appname{makeindex}.

In the same series as \emph{The \LaTeX\ Companion}, there is also 
\latexgraphic\ which details how to illustrate
documents with \LaTeX\ and PostScript, including a chapter on colour
(coloured text, background, tables and slides).  This is recommended
to anyone who is contemplating heavy use of graphics, but you do need
a basic knowledge of \LaTeX\ before delving into it.  

The final book in the \dq{Companion} series which you may find useful
is \latexweb. This is recommended for those interested in creating
documents for the web, either as HTML or PDF.  It details how
to convert \LaTeX\ documents into HTML using various applications
such as \appname{LaTeX2HTML} and \appname{TeX4ht}, and how to create
PDF documents using \iPDFLaTeX\faq{What is PDFTeX?}{whatpdftex},
including how to create active links within your document using the
\isty{hyperref} package.

There are two new \LaTeX\ books that I haven't read but have
been recommended to me: \emph{\LaTeX\ Beginner's
Guide}~\cite{kottwitz} and \emph{\LaTeX\ and
Friends}~\cite{vandongen}.

Note that the \gls{uktug} has a 25\% book discount scheme
for members. See \url{http://uk.tug.org/membership} for more details
of that and other associated benefits. If you're not in the
UK, have a look at \url{http://www.tug.org/usergroups.html} to see
if there is a local user group in your area.

There is also a wealth of \LaTeX-related information on the
Internet\faq{How to get help}{gethelp}. \reportlinebreak\Gls{ctan} is a good place
to start. You can check the on-line catalogue~\cite{texcat} for
information about available software and, as mentioned earlier, there is also the list of
\htmladdnormallink{frequently asked
questions}{http://www.tex.ac.uk/faq} which I~recommend you try if
you have any queries. See also \appendixref{ch:help}

%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{definitions}
\printkeywords
\html{\input{novices.hkls}}


\glsaddall[types=keywords]

%%%%%%%%%%%%%%%%%%%%%% SOURCE TO PDF %%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{fromsource2output}
\chapter{From Source Code to Typeset Output}
\label{ch:tex2pdf}

Every time you want to create or edit a \LaTeX\ document, there are three
basic steps you will always need to follow:

\begin{enumerate}
\item\label{itm:step1} Write or edit the \gls{source}.

\item\label{itm:step2} Pass the source code to the \iappname{latex} or \iappname{pdflatex} application (\dq{\LaTeX\ the document}).

\begin{itemize}
\item If there are any error messages, return to \objectref{Step}{itm:step1}.
\item If there are no error messages, a 
\glslink{output}{PDF file}\indexPDF\ is created.
\end{itemize}

\item\label{itm:step3} View the \glslink{output}{PDF file} to check
the result.  If you need to modify your document, go back to
\objectref{Step}{itm:step1}. 
\end{enumerate}

You will therefore need:

\begin{enumerate}
\item A text editor  (to perform \objectref{Step}{itm:step1}). For
example \iappnamelink[,]{Vim}{http://www.vim.org/} 
\iappnamelink{Emacs}{http://www.gnu.org/software/emacs/} or
\iappnamelink[.]{Gedit}{http://projects.gnome.org/gedit/}

\refstepcounter{object}\label{obj:MiKTeX}%
\item The \gls{tex} software\faq{(La)TeX for different
machines}{TeXsystems} (to perform \objectref{Step}{itm:step2}). If
you don't already have \TeX\ on your machine, you will need to
install it. The most convenient way to do this is
to install from the \TeX\ Collection DVD ROM, which is distributed
to all \gls{tug} members, but you can also download and install free
\TeX\ distributions, such as \itexdistro{TeX~Live},
\itexdistro{MiKTeX} or \itexdistro{MacTeX}, from the Internet (see
\xpageref{below}{obj:install}).  There is also \itexdistro{proTeXt},
an enhancement of \texdistro{MiKTeX} that aims to be an
easy-to-install \TeX\ Distribution.  For more information including
up-to-date links, go to \url{http://www.ctan.org/starter.html}.

\item A PDF viewer (to perform
\objectref{Step}{itm:step3}). For example 
\iappnamelink[,]{Adobe Reader}{http://www.adobe.com/} 
\iappnamelink[,]{Sumatra}{http://blog.kowalczyk.info/software/sumatrapdf/free-pdf-reader.html}
\iappnamelink{Evince}{http://projects.gnome.org/evince/} or
\iappnamelink[.]{Okular}{http://okular.kde.org/}

\end{enumerate}

This can be rather complicated for a beginner, especially for those
with no experience writing computer code. Fortunately, there are
some all-in-one applications (often called a \keyword{front-end})
that provide a text editor (for \objectref{Step}{itm:step1}),
buttons or menu items to run the \appname{latex} or
\appname{pdflatex} \glslink{terminal}{command-line application} (for
\objectref{Step}{itm:step2}) and, in some cases, a viewer to perform
\objectref{Step}{itm:step3}.

\sectionref[The next section]{sec:texworks} describes one such front-end called
\iappnamelink[.]{TeXWorks}{http://www.tug.org/texworks/} I~have chosen
to describe TeXWorks because it is a free, cross-platform
application. Binaries are available for Microsoft Windows, Mac~OS~X
and GNU/Linux. The screen shots of TeXWorks in this
book were taken from the Linux version running
under Fedora. If you run TeXWorks on other operating systems, it may
have a slightly different look, but it has the same functionality.

New versions of \texdistro{TeX~Live} and \texdistro{MiKTeX} include TeXWorks for MS~Windows,
and new versions of \texdistro{MacTeX} include TeXWorks for Mac~OS~X users.
GNU/Linux users can use their Add\slash Remove Software utility to 
install TeXWorks. Alternatively, you can download TeXWorks by
following the links provided at \url{http://www.tug.org/texworks/}.

\refstepcounter{object}\label{obj:install}%
If you're confused by all the options, let's keep
things as simple as possible:

\begin{itemize}

\item MS~Windows:

 You have a choice between \texdistro{MiKTeX} (or \texdistro{proTeXt}) and 
 \texdistro{TeX~Live}. \texdistro{MiKTeX} provides a
 smaller and quicker installation, but the downside is that you may
 not have the classes or packages you want to use. \texdistro{MiKTeX} can
 install these whenever you try to \LaTeX\ a document that uses them, 
 but you need an Internet connection while it does this. 
 \texdistro{TeX~Live} installs everything, so it takes longer and needs 
 more space, but you should have the majority of packages and classes that you need.

 \begin{description}

   \item[TeX~Live:]\mbox{}

   \begin{enumerate}
    \item Fetch and unpack
     \url{http://mirror.ctan.org/systems/texlive/tlnet/install-tl.zip}

    \item Run \iappname{install-tl} and follow the instructions.
     This can take an hour or more.
   \end{enumerate}

   \item[proTeXt:]\mbox{}

   \begin{enumerate}
    \item Go to \url{http://tug.org/protext/}

    \item Click on the \dq{download the self-extract protext.exe} link
     to download and run the executable.
   \end{enumerate}

   \item[MiKTeX:]\mbox{}

   \begin{enumerate}
    \item Go to \url{http://www.miktex.org/}

    \item In the left-hand panel, there is a link to the download page
     for the latest version. At time of writing, it is \texdistro{MiKTeX}~2.9.
     Click on that link.

    \item Scroll down to the section \dq{Installing a basic
      \texdistro{MiKTeX} system}.

    \item If you're happy with the selected mirror location, click on the 
      \dq{Download} button.

    \item Run the executable.
   \end{enumerate}
 \end{description}

\item Mac~OS~X:

 \begin{enumerate}
  \item Go to \url{http://tug.org/mactex/}

  \item Follow the instructions on that page.
 \end{enumerate}

\item GNU/Linux:

 \begin{enumerate}
  \item Fetch and unpack
    \url{http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz}

  \item Follow the instructions at
    \url{http://tug.org/texlive/quickinstall.html}

  \item Once \texdistro{TeX~Live} has finished installing, run your
   system's \dq{Add\slash Remove Software} tool.

  \item Find \dq{texworks}, select the newest version and install.
 \end{enumerate}

\end{itemize}

If you run into problems, there are mailing lists at
\url{http://tug.org/mailman/listinfo/tex-live} and
\url{http://docs.miktex.org/manual/lists.html} for
\itexdistro{TeX~Live} and \itexdistro{MiKTeX}, and
\itexdistro{MacTeX} help at \url{http://www.tug.org/mactex/help/}.
There is also a list of places where you can ask for help in
\appendixref{ch:help}.

%%%%%%%%%%%%%%%%%%% TeXWorks %%%%%%%%%%%%%%%%%%%%%

\setnode{texworks}
\section{TeXWorks}
\label{sec:texworks}

Hopefully you've managed to successfully install \gls{tex} and TeXWorks as
described \latexhtml{above}{in the \htmlref{previous
section}{ch:tex2pdf}}, so let's test it out.

First run TeXWorks. On Windows, you can access it via the
\menu{Start} menu. On GNU/Linux, it's probably located in
\menu{Applications}\menuto\menu{Office}, or you can type
\iappname{texworks} in a \gls{terminal}. You should now see the TeXWorks
window. The button marked
with a grey triangle in a green circle is the build or typeset function. It
runs the application in the drop-down list next to it. This is set to
pdfLaTeX, which is what we want for now.

It's a good idea to switch on the syntax highlighting, if it isn't
already on. This is done via the \menu{Format}\menuto\menu{Syntax
Coloring} sub-menu. Make sure the \menu{LaTeX} item is selected.

Next, type in the following sample source code, as shown in \figureref{fig:texworks2}
(the commands used here will be described in more detail in
\chapterref{ch:simpledoc}):
\begin{code}
\begin{verbatim}
\documentclass{scrartcl}

\begin{document}

This is an example document.

\end{document}
\end{verbatim}
\end{code}
\textbf{Pay close attention to the backslashes at the start of each
command name.} If you find the font is a bit too small for you,
you can make it larger using the \menu{Format}\menuto\menu{Font} menu item.
\emph{This doesn't affect the font size in your PDF file, just the
font size of your code.} This displays the \dq{Select Font} dialog
box. Set the font size as appropriate.

Then save the document, using the
\menu{File}\menuto\menu{Save As} menu item. I~called my document
\texttt{example1.tex} (remember the \texttt{.tex} extension and
stick to file names that only consist of alphabetical characters,
digits and hyphens\dash don't uses spaces or underscores).

\begin{figure}[htbp]
\figconts
  {pictures/texworks2}
  {%
    \caption[Source Code for an Example Document]{Source Code for an 
     Example Document. (Syntax highlighting switched on.)}%
  }%
  {fig:texworks2}
\end{figure}

Now that you have saved the file, you can run pdfLaTeX. Make sure
the drop-down list next to the build button has \dq{pdfLaTeX}
selected and click on the build button. If all goes well, a new
window should open displaying the typeset document
(\figureref{fig:texworks3}).

\begin{figure}[htbp]
\figconts
  {pictures/texworks3}
  {%
    \caption{The Typeset Document}
  }%
  {fig:texworks3}
\end{figure}

\begin{figure}[htbp]
\figconts
  {pictures/texworks4}
  {%
    \caption{The Source Code Has a Misspelt Command}
  }%
  {fig:texworks4}
\end{figure}

Now let's see what happens if there is an error in the source code.
In \figureref{fig:texworks4} I~have misspelt the
\glsni{documentclass} command. This time, when I~click on the
build button, I~get the error message:
\begin{verbatim}
! Undefined control sequence.
l.1 \documentclas
                 {scrartcl}
?
\end{verbatim}
(Shown in \figureref{fig:texworks5}.)

\begin{figure}[htbp]
\figconts
  {pictures/texworks5-annote}
  {%
     \caption{An Error Message is Displayed}%
  }%
  {fig:texworks5}
\end{figure}


Here \dq{Undefined control sequence} means an unrecognised command,
and below that message, \dq{\texttt{l.1}} means the error was encountered on
line~1. An input line at the bottom of the window has appeared with a
cursor. \LaTeX\ is in interactive mode
and is awaiting a response. There are several responses, but I'm
only going to mention two of them:
\begin{enumerate}
\item Type \texttt{h} and press the Return/Enter key \enter. This displays
a short help message and awaits a new response (see
\figureref{fig:texworks6}).

\item Type \texttt{x} and press Return/Enter. This aborts the
\LaTeX\ run.
\end{enumerate}

Notice that the green circle button with the grey triangle has turned
into a red stop button. This button can be used to abort the
process instead of typing \texttt{x}.

\begin{figure}[htbp]
\figconts
  {pictures/texworks6}
  {%
    \caption{A Short Help Message}%
  }%
  {fig:texworks6}
\end{figure}

Now, there is a second tab at the bottom of the TeXWork's window
(\figureref{fig:texworks7}). This lists the error message and
provides a link to the line where the error occurred. Clicking on
this link highlights line~1. Next I~need to fix the error by
correcting the spelling of the command. Once it's fixed, I~can click
on the build button.

\begin{figure}[htbp]
\figconts
  {pictures/texworks7}
  {%
    \caption{Error Tab}%
  }%
  {fig:texworks7}
\end{figure}

Here's another error you might encounter: I'm now going to misspell
the class name. It should be \texttt{scrartcl}, but in
\figureref{fig:texworks8} it has been misspelt. This time, when I
click on the build button, I~get the error:
\begin{verbatim}
! LaTeX Error: File `scrartc.cls' not found.
\end{verbatim}
I~have two choices: type in the correct name on the line below
\dq{Enter file name:} or I~can abort the process using the red abort
button. In either case I~need to go back and fix the error in my
code.

\begin{figure}[htbp]
\figconts
  {pictures/texworks8}
  {%
   \caption{Misspelt Class File}%
  }%
  {fig:texworks8}
\end{figure}


%%%%%%%%%%%%% CREATING A SIMPLE DOCUMENT %%%%%%%%%%%%%%%%%%

\setnode{simpledoc}
\chapter{Creating a Simple Document}
\label{ch:simpledoc}

Having installed and tested the software, let's now look at how to
actually write the \gls{source}.  The very first line of any document that you create must have
the \gls{command}:
\begin{definition}
\gls{documentclass}\oarg{\meta{option-list}}\marg{\meta{class-name}}
\end{definition}%
This tells \LaTeX\ what type of document you want to create
(for example an article, a technical report or correspondence).  The
\glsni{documentclass} command takes one \gls{mandatory}, \meta{class-name},
that specifies the \gls{cls}.

There are many class files available, and some publishers,
institutions or journals provide their own custom classes (for
example, the \icls{jmlr} class for the Journal of Machine Learning
Research). Popular classes include \icls{memoir} (for books and
reports) and those supplied in the \koma\ bundle (for books,
reports, articles and correspondence). There's also \icls{beamer}
(for presentations) as well as classes for typesetting exams,
flashcards, concert programmes etc. For simplicity, this
book will concentrate on three of the
\koma\ classes \icls{scrartcl} (for articles), \icls{scrreprt}
(for technical reports, theses etc) and \icls{scrbook} (for books).

We'll start with a very simple document, so let's use the
\icls{scrartcl} class file.  In this case the very first line of the
\gls{source} should be:
\begin{codeS}
\glsni{documentclass}\marg{scrartcl}
\end{codeS}
The \glsni{documentclass} command also takes an 
\gls{optional}, \meta{option-list},
which should be a comma separated list of options to be passed to the
class file.  This allows you to override the class file defaults.
For example, the \icls{scrartcl} class file by default uses A4 
paper, but if you are in the USA you will probably want to use
letter paper.  This can be achieved
using the option \clsopt{letterpaper}.  So you would need to edit the
above line to:
\begin{codeS}
\glsni{documentclass}\oarg{letterpaper}\marg{scrartcl}
\end{codeS}
\refstepcounter{object}\label{obj:sizeopt}%
Let's change another option.  The normal font size is \clsopt{11pt}
by default, but we have the option to change it, so let's use
\clsopt{12pt}:
\begin{codeS}
\glsni{documentclass}\oarg{letterpaper,12pt}\marg{scrartcl}
\end{codeS}
You can also change your document so that it is in a two-column
format using the \clsopt{twocolumn} option:
\begin{codeS}
\glsni{documentclass}\oarg{letterpaper,12pt,twocolumn}\marg{scrartcl}
\end{codeS}

After deciding what type of document you want, you now need to specify
the contents of the document.  This is done inside the \gls{env-document}
\gls{environment}.  The document is started with the
command:
\begin{codeS}
\glsni{begin}\marg{document}
\end{codeS}
and ended with
\begin{codeS}
\glsni{end}\marg{document}
\end{codeS}
(\LaTeX\ stops reading the file when it reaches the above line, so
anything occurring after it is ignored.)

My \gls{source} now looks like:
\begin{code}
\glsni{documentclass}[12pt]\marg{scrartcl}\newline
\mbox{}\newline
\glsni{begin}\marg{document}\newline
\mbox{}\newline
\glsni{end}\marg{document}
\end{code}
Every document you create must have this form.  You can't simply
start typing the document text.  You must first specify
your class file\indexCLS, and then place the contents of the document
inside the \glsni{env-document} environment.\screenpagebreak

So far so good, but at the moment we have an empty document, so we
won't get any output.  Let's now put some text into our document:
\begin{code}
\begin{alltt}
\glsni{documentclass}\oarg{12pt}\marg{scrartcl}

\glsni{begin}\marg{document}

This is a simple document.
Here is the first paragraph.

Here is the second paragraph. As you
can       see it's 
a rather 
short paragraph, but not as short as the previous one.

\glsni{end}\marg{document}
\end{alltt}
\end{code}

\xminisec{Top Five Mistakes Made by New Users}
I first started teaching \LaTeX\ in 1998, and these are the most
common errors I've seen when people start learning \LaTeX:
\begin{enumerate}
\item Missing out the backslash \glsni{backslashchar} at the start
of one or more of the \glspl{command}.

\item Using a forward slash \glsni{slashchar} instead of a backslash
\glsni{backslashchar}.

\item Forgetting \texttt{\glsni{end}\marg{document}}.

\item Misspelling \dq{document} (in
\texttt{\glsni{begin}\marg{document}} and
\texttt{\glsni{end}\marg{document}}).

\item Missing a closing brace \glsni{rightbracechar}.

\end{enumerate}
If you encounter any problems when you start out, go through that check list first.
Then check \appendixref{ch:errors}.

Whenever you start a new document, always type in the
\glsni{documentclass}, \texttt{\glsni{begin}\marg{document}} and
\texttt{\glsni{end}\marg{document}} commands first
(\figureref{fig:newdoc-1}). Then move your cursor between the
\glsni{begin} and \glsni{end} lines and type the document text
(\figureref{fig:newdoc-2}).

\begin{figure}[htbp]
\figconts
  {pictures/newdoc-1}
  {%
    \caption[Starting a New Document (1)]{Starting a New Document: 
    always type these three lines first.}%
  }%
  {fig:newdoc-1}

\ifscreenorother
{%
  \end{figure}
  \begin{figure}[htbp]
}%
{%
  \strut
}

\figconts
  {pictures/newdoc-2}
  {%
    \caption[Starting a New Document (2)]{Starting a New Document: 
     move the cursor inside the \glsni{env-document} environment and 
     start typing the document text.}%
  }%
  {fig:newdoc-2}
\end{figure}

\begin{exercise}{Simple Document}{ex:simpledoc}

Try typing the code in the above example into TeXWorks or the editor
of your choice (see \chapterref[the previous section]{ch:tex2pdf} if
you can't remember what to do.) You can also \download{simpledoc} a
copy of this file, but I~recommend that you try typing it in to give
yourself some practice.

Things to note while you are typing: firstly, when you press the
return character at the end of a line this end-of-line character is
converted into a space in the \gls{output}.  So the
fact that I~have some very ragged lines in my \gls{source} has
no effect on the final result. (Note that some front-ends will 
reformat your lines as you type.) Whereas a completely blank line
will be converted into a paragraph break (\gls{par} has the same
effect).

Secondly, multiple \Index{spaces} are converted into a single space,
so the large gap between the words \dq{\texttt{can}} and \dq{\texttt{see}} is
no different from having a single space.

Once you have typed up your \gls{source}, save your file 
(called, for example, \texttt{exercise1.tex}), and run PDF\LaTeX\ as described in 
\sectionref{sec:texworks}. If all goes well, TeXWorks should display
the resulting PDF file in a new window, usually alongside the window
containing the source code.

\xminisec{Notes:}
\begin{enumerate}

\item Each paragraph automatically starts with an indentation in the
PDF.

\item There is no blank line between the paragraphs in the PDF
document. (See what happens if you add the \koma\ class option
\scrclsopt[full]{parskip}:
\begin{codeS}
\glsni{documentclass}\oarg{12pt,parskip=full}\marg{scrartcl}
\end{codeS}
and rebuild the PDF.)

\item Move the mouse over one of paragraphs in the PDF viewer and
pop-up the context menu (usually a right mouse click). Select
\menu{Jump to Source}. The window containing the source code should
now gain the focus and the line of code matching the typeset line you clicked on
in the PDF should now be highlighted.

\end{enumerate}

\end{exercise}

%%%%%%%%%%%%%%%%%% Simple Commands %%%%%%%%%%%%%%%%%%

\setnode{simplecommands}
\section{Using Simple Commands}
\label{sec:simple}

\faq{Typesetting all those TeX-related logos}{logos}Now let's try
adding a few simple \glspl{command} to our
document. The command \gls{LaTeX} produces the
\makeimg{ALT=LaTeX}{\LaTeX} logo and the command \gls{today} prints
the current date. \LaTeX\ always ignores any spaces that follow a
command name that consists of letters, as it uses the space to
indicate the end of the command name. This means that if we want a
space to occur immediately after the command, we need to explicitly
say so using the command \gls{spacesym} (recall from
\ifscreenorother{\htmlref{earlier}{obj:visiblespace}}{page~\pageref{obj:visiblespace}}
\gls{visiblespace} indicates a space character). So, for example:
\begin{codeS}
\glsni{LaTeX}\glsni{spacesym}logo
\end{codeS}%
produces the output:
\begin{resultS}[LaTeX logo]
\LaTeX\ logo
\end{resultS}%
Some people when starting out can get a bit confused by this and
read it as the entity \dq{\cmdname{LaTeX}\cmdname{}} whereas it is
in fact two commands: \dq{\cmdname{LaTeX}} (print the \LaTeX\ logo)
followed \dq{\cmdname{\ }} (print a space.)

Let's also try using a command that takes an 
\gls{argument}.  The command 
\begin{definition}
\gls{footnote}\refstepcounter{object}\label{cmd:footnote}\marg{\meta{text}}
\end{definition}%
takes one argument that specifies the text that should
appear in the footnote.  This command must be placed where you want
the footnote marker to appear.

\begin{exercise}{Using Simple Commands}{ex:simple}

Edit the document you created in \exerciseref{ex:simpledoc},
so that it looks like the following: (You can \download{simple} it if
you like, but again it is better if you try typing it in yourself.)
\begin{bcode}
\glsni{documentclass}\oarg{12pt}\marg{scrartcl}\newline
\mbox{}\newline
\glsni{begin}\marg{document}\newline
\mbox{}\newline
This is a simple \glsni{LaTeX}\glsni{spacesym}document.
Here is the first paragraph.\newline
\mbox{}\newline
Here is the second paragraph\glsni{footnote}\marg{with a footnote}. 
As you can see it's a rather short paragraph, but not 
as short as the previous one. This document was 
created on: \glsni{today}.\newline
\glsni{end}\marg{document}
\end{bcode}

Now \htmlref{\LaTeX\ your document}{ch:tex2pdf} and view the result.
(Remember to check \appendixref{ch:errors}
if you have a problem.) You should see the \LaTeX\ logo, the footnote
marker and the current date.  If you scroll down to the bottom of the
page, you should see the footnote.
\end{exercise}

%%%%%%%%%%%%%%%%%%%%%%%%%% PACKAGES %%%%%%%%%%%%%%%%%%%%%%%%

\setnode{packages}
\section{Packages}
\label{sec:packages}

Packages\indexSTY\ are files with the extension \texttt{.sty} that
either define new \glspl{command} or redefine
existing commands\faq{What are LaTeX classes and packages?}{clsvpkg}.
They're like a type of add-on or plug-in. Most of the commonly used
packages should have been installed when you installed your \gls{tex}
distribution (see \chapterref{ch:tex2pdf}).
\appendixref{ch:installsty} covers how to install new packages.
Most packages come with documentation that can be accessed using the
\iappname{texdoc} application described in \sectionref{sec:texdoc}.

Packages are loaded in the \gls{preamble} (after
\gls{documentclass} and before \glsni{begin}\marg{document}) using
\begin{definition}
\gls{usepackage}\oarg{\meta{option list}}\marg{\meta{package}}
\end{definition}
where \meta{package} is the name of the package and \meta{option
list} is a list of comma-separated options. For example, to load the
package \isty{graphicx} with the \istyopt{graphicx}{draft} option:
\begin{codeS}
\glsni{usepackage}\oarg{draft}\marg{graphicx}
\end{codeS}
Any applicable class options are also passed to packages, so in
\begin{code}
\gls{documentclass}\oarg{draft}\marg{scrartcl}\newline
\glsni{usepackage}\marg{graphicx}
\end{code}
the \clsopt{draft} option is set for both the \icls{scrartcl} class
and the \isty{graphicx} package.

You can specify more than one package in the argument of
\glsni{usepackage}, where each package name is separated by a
comma. For example:
\begin{codeS}
\glsni{usepackage}\marg{amsmath,amsfonts}
\end{codeS}
The \isty{graphicx} package is covered in \chapterref{ch:graphicx}
and the \isty{amsmath} package is covered in \chapterref{ch:maths},
so let's start out with a~relatively simple example.

\setnode{datetime}
\subsection{Changing the Format of
\latexhtml{\texorpdfstring{\protect\cmdname{today}}{\protect\textbackslash
today}}{\protect\cmdname{today}}}
\label{sec:today}

In the \htmlref{previous exercise}{ex:simple}, we used the
\gls{today} command to produce the current date. By default, this
command displays the date in US format. To illustrate how to use
packages, this section will look at how to use the \isty{datetime}
package to change the way that \gls{today} displays the date.

The \isty{datetime} package has various options that can be used to
change the format of \gls{today}.  For example, by default the
\isty{datetime} package redefines \gls{today} to display the
date in the form: {\showdowtrue\longdate
\renewcommand{\fmtord}[1]{\textsuperscript{#1}}\docdate}. The option
\istyopt{datetime}{short} will produce an abbreviated form, (for
example {\shortdate\docdate}) and the option \istyopt{datetime}{nodayofweek}
won't display the day of the week (for example
{\showdowfalse\docdate}).
For those who don't like the raised ordinal, there is the
\istyopt{datetime}{level} option.
These can be passed as a comma separated list in the
\gls{optional} to the
\gls{usepackage} command.  It is also possible to use a
declaration instead. For example, to redefine \gls{today} to
display the date in the form {\ddmmyyyydate\docdate}, you can either do
\begin{codeS}
\glsni{usepackage}\oarg{ddmmyyyy}\marg{datetime}
\end{codeS}%
or
\begin{code}
\begin{alltt}
\glsni{usepackage}\marg{datetime}
\gls{ddmmyyyydate}
\end{alltt}
\end{code}

The \isty{datetime} package also defines the command
\begin{definition}
\gls{currenttime}
\end{definition}
which displays the current time, where again
the format can be changed by the package options. So the option
\istyopt{datetime}{12hr} will cause \glsni{currenttime} to display
the date in 12 hour format (for example, \ampmtime) and the option
\istyopt{datetime}{24hr} will cause \glsni{currenttime} to display
the date in 24 hour format (for example, \xxivtime).

\begin{exercise}{Using the datetime Package}{ex:datetime}

Edit your document from \exerciseref{ex:simple} so that it uses the \isty{datetime}
package. Experiment with the different package options, for example
\begin{codeS}
\glsni{usepackage}\oarg{short,nodayofweek,level,12hr}\marg{datetime}
\end{codeS}
and add the current time
\begin{codeS}
This document was created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}.
\end{codeS}
You can \downloadorview{datetime} an example.
For a full list \isty{datetime} of package options, see the
\sty{datetime} \htmlref{documentation}{sec:texdoc}.
\latex{(Refer to \sectionref{sec:texdoc} on how to find package
documentation.)}

\end{exercise}

%%%%%%%%%%%%%%%%%%%%%% Special Characters %%%%%%%%%%%%%%%%%%%%

\setnode{symbols}
\section{Special Characters and Symbols}
\label{sec:chars}

You can use most of the standard characters that you find on your keyboard, but the 
10 symbols shown in \tableref{tab:specialchars} have a special
meaning.

\begin{table}[htbp]
\caption{Special Characters}
\label{tab:specialchars}
\centering
\begin{makeimage}\end{makeimage}
\glsi{leftbracechar} \glsi{rightbracechar} 
\glsi{percentchar}
\glsi{ampchar} 
\glsi{dollarchar} 
\glsi{hashchar} 
\glsi{underscorechar}
\glsi{circumchar} 
\glsi{tildechar} 
\glsi{backslashchar}
\end{table}

We have already used the curly braces \gls{leftbracechar} and
\gls{rightbracechar}. The percent symbol \gls{percentchar} is a
comment character. Everything from the percent symbol up to the end
of line is ignored by \LaTeX. This means you can have comments in
your \gls{source} to remind you what a particular part of your code
is doing. We have also used the backslash symbol
\glsni{backslashchar} which indicates that we are using a \LaTeX\
command, as in \glstext{LaTeX} or \glstext{today}. The meaning of
the other special characters will be covered later.

So what do you do if you want one of these symbols to actually appear
in your document? \faq{Where can I find the symbol for
\ldots?}{symbols} \tableref{tab:symbols} lists commands that produce
these and other symbols\faq{How to get copyright, trademark,
etc}{tradesyms}. Note that some of the commands have short cuts, such
as \glsni{emdash} instead of \glsni{textemdash} and
\glsni{questiondown} instead of \glsni{textquestiondown}.

The symbol \texttt{`} is the backtick (or grave) symbol, as
opposed to the apostrophe symbol~\texttt{'}.  \latexhtml{The backtick
symbol usually looks like~\texttt{\`{}} on a keyboard, and on}{On}
most UK keyboards it is situated to the left of the \texttt{1}~key.
The opening double quote is created using two adjacent backtick
symbols and the closing double quote with two adjacent
apostrophe symbols. This gives 66 and 99 style quotes, which you
wouldn't get using the double quote symbol on your keyboard.

Note that the symbols \gls{barchar} \gls{ltchar} and \gls{gtchar} have to
be created using \glsni{textbar}, \glsni{textless} and
\glsni{textgreater} when in normal text mode. If you try to enter
them using the corresponding keyboard characters you may get
\makeimg{em dash}{\textemdash} \makeimg{upside down exclamation
mark}{\textexclamdown} and \makeimg{upside down question
mark}{\textquestiondown}. (They do however work if you are in
\htmlref{maths mode}{ch:maths}.\footnote{There are also some text
fonts that will display them correctly, but don't rely on it.}) The
slash character \gls{text.slash} may be used directly, as in
\dq{\texttt{and\glsni{text.slash}or}}, but no line break will be permitted at the slash,
whereas \glsni{slash} (as in \dq{\texttt{and\glsni{slash}\glsni{visiblespace}or}}) will allow a
line break at that point.

\begin{table}[htbp]
\caption{Symbols}
\label{tab:symbols}
\centering
\begin{latexonly}
\begin{tabular}{@{}ll@{\hspace{4\tabcolsep}}ll@{\hspace{4\tabcolsep}}ll@{}}
\begin{inlinedef}\gls{textbackslash}\end{inlinedef} & \textbackslash&
\begin{inlinedef}\gls{slash}\end{inlinedef} & \slash &
\begin{inlinedef}\gls{textgreater}\end{inlinedef} & \textgreater \\
\begin{inlinedef}\gls{textasciicircum}\end{inlinedef} & \textasciicircum & 
\begin{inlinedef}\gls{dollar}\end{inlinedef} & \$ &
\begin{inlinedef}\gls{textbar}\end{inlinedef} & \textbar \\
\begin{inlinedef}\gls{textasciitilde}\end{inlinedef} & \textasciitilde&
\begin{inlinedef}\gls{leftbrace}\end{inlinedef} & \{ &
\begin{inlinedef}\gls{textless}\end{inlinedef} & \textless \\
\begin{inlinedef}\gls{pounds}\end{inlinedef} & \pounds &
\begin{inlinedef}\gls{rightbrace}\end{inlinedef} & \} &
\begin{inlinedef}\gls{dag}\end{inlinedef} & \dag \\
\begin{inlinedef}\gls{textregistered}\end{inlinedef}& 
\textregistered&
\begin{inlinedef}\gls{hash}\end{inlinedef} & \# &
\begin{inlinedef}\gls{ddag}\end{inlinedef} & \ddag \\
\begin{inlinedef}\gls{texttrademark}\end{inlinedef} & \texttrademark &
\begin{inlinedef}\gls{percent}\end{inlinedef} & \% &
\begin{inlinedef}\gls{quoteright}\end{inlinedef}
or \begin{inlinedef}\gls{textquoteright}\end{inlinedef} & \textquoteright\\
\begin{inlinedef}\gls{copyright}\end{inlinedef} & \copyright &
\begin{inlinedef}\gls{amp}\end{inlinedef} & \& &
\begin{inlinedef}\gls{quoteleft}\end{inlinedef} 
or \begin{inlinedef}\gls{textquoteleft}\end{inlinedef} & \textquoteleft \\
\begin{inlinedef}\gls{textbullet}\end{inlinedef} & \textbullet & 
\begin{inlinedef}\gls{i}\end{inlinedef} & \i & 
\begin{inlinedef}\gls{quotedblright}\end{inlinedef}
or \begin{inlinedef}\gls{textquotedblright}\end{inlinedef} & \textquotedblright\\
\begin{inlinedef}\gls{questiondown}\end{inlinedef}
or \begin{inlinedef}\gls{textquestiondown}\end{inlinedef} & ?` &
\begin{inlinedef}\gls{j}\end{inlinedef} & \dotlessj & 
\begin{inlinedef}\gls{quotedblleft}\end{inlinedef} 
or \begin{inlinedef}\gls{textquotedblleft}\end{inlinedef} & \textquotedblleft\\
\begin{inlinedef}\gls{exclamdown}\end{inlinedef}
or \begin{inlinedef}\gls{textexclamdown}\end{inlinedef} & !` &
\begin{inlinedef}\gls{dash}\end{inlinedef} & - &
\begin{inlinedef}\gls{endash}\end{inlinedef}
or \begin{inlinedef}\gls{textendash}\end{inlinedef} & \textendash \\
\begin{inlinedef}\gls{emdash}\end{inlinedef}
or \begin{inlinedef}\gls{textemdash}\end{inlinedef} & \textemdash &
\begin{inlinedef}\gls{S}\end{inlinedef} & \S &
\begin{inlinedef}\gls{textperiodcentered}\end{inlinedef} &
\textperiodcentered\\
\begin{inlinedef}\gls{ldots}\end{inlinedef} & \ldots  &
\begin{inlinedef}\gls{P}\end{inlinedef} & \P &
\begin{inlinedef}\gls{underscore}\end{inlinedef} 
or \begin{inlinedef}\gls{textunderscore}\end{inlinedef}& \_ 
\end{tabular}
\end{latexonly}
\begin{htmlonly}
\begin{tabular}{ll|ll}
\begin{inlinedef}\gls{textbackslash}\end{inlinedef} &
\textbackslash&
\begin{inlinedef}\gls{underscore}\end{inlinedef}\space 
or \begin{inlinedef}\gls{textunderscore}\end{inlinedef}& \_ \\
\begin{inlinedef}\gls{dash}\end{inlinedef} & - &
\begin{inlinedef}\gls{endash}\end{inlinedef}\space
or \begin{inlinedef}\gls{textendash}\end{inlinedef} & \makeimg{en dash character}{\textendash} \\
\begin{inlinedef}\gls{emdash}\end{inlinedef}\space  
or \begin{inlinedef}\gls{textemdash}\end{inlinedef} & \makeimg{em dash character}{\textemdash} &
\begin{inlinedef}\gls{P}\end{inlinedef} & \P \\
\begin{inlinedef}\gls{textasciicircum}\end{inlinedef} & \textasciicircum & 
\begin{inlinedef}\gls{dollar}\end{inlinedef} & \$ \\
\begin{inlinedef}\gls{S}\end{inlinedef} & \S &
\begin{inlinedef}\gls{textasciitilde}\end{inlinedef} & \textasciitilde\\
\begin{inlinedef}\gls{leftbrace}\end{inlinedef} & \{ &
\begin{inlinedef}\gls{ldots}\end{inlinedef} & \ldots \\
\begin{inlinedef}\gls{pounds}\end{inlinedef} & \pounds &
\begin{inlinedef}\gls{rightbrace}\end{inlinedef} & \} \\
\begin{inlinedef}\gls{dag}\end{inlinedef} & 
\makeimg{dagger symbol}{\dag} &
\begin{inlinedef}\gls{questiondown}\end{inlinedef}\space  
or \begin{inlinedef}\gls{textquestiondown}\end{inlinedef} & 
\makeimg{upside-down question mark}{?`} \\
\begin{inlinedef}\gls{textregistered}\end{inlinedef}& 
\makeimg{registered symbol}{\textregistered}&
\begin{inlinedef}\gls{hash}\end{inlinedef} & \# \\
\begin{inlinedef}\gls{ddag}\end{inlinedef} & 
\makeimg{double dagger symbol}{\ddag} &
\begin{inlinedef}\gls{exclamdown}\end{inlinedef}\space  
or \begin{inlinedef}\gls{textexclamdown}\end{inlinedef} & 
\makeimg{upside-down exclamation mark}{!`} \\
\begin{inlinedef}\gls{texttrademark}\end{inlinedef} & \texttrademark &
\begin{inlinedef}\gls{percent}\end{inlinedef} & \% \\
\begin{inlinedef}\gls{quoteright}\end{inlinedef}\space  
or \begin{inlinedef}\gls{textquoteright}\end{inlinedef} &
\makeimg{closing single quote}{\textquoteright}&
\begin{inlinedef}\gls{quotedblright}\end{inlinedef}\space  
or \begin{inlinedef}\gls{textquotedblright}\end{inlinedef} &
\makeimg{closing double quote}{\textquotedblright}\\
\begin{inlinedef}\gls{copyright}\end{inlinedef} & \copyright &
\begin{inlinedef}\gls{amp}\end{inlinedef} & \& \\
\begin{inlinedef}\gls{quoteleft}\end{inlinedef}\space  
or \begin{inlinedef}\gls{textquoteleft}\end{inlinedef} &
\makeimg{opening single quote}{\textquoteleft} &
\begin{inlinedef}\gls{quotedblleft}\end{inlinedef}\space  
or \begin{inlinedef}\gls{textquotedblleft}\end{inlinedef} &
\makeimg{opening double quote}{\textquotedblleft}\\
\begin{inlinedef}\gls{textbullet}\end{inlinedef} & \makeimg{bullet point}{\textbullet} & 
\begin{inlinedef}\gls{i}\end{inlinedef} & \makeimg{dotless i}{\i} \\ 
\begin{inlinedef}\gls{j}\end{inlinedef} & \makeimg{dotless j}{\dotlessj} & 
\begin{inlinedef}\gls{textbar}\end{inlinedef} & \textbar\\
\begin{inlinedef}\gls{textperiodcentered}\end{inlinedef} &
\middot &
\begin{inlinedef}\gls{textless}\end{inlinedef} & \textless\\
\begin{inlinedef}\gls{textgreater}\end{inlinedef} & \textgreater&
\begin{inlinedef}\gls{slash}\end{inlinedef} & / \\
\end{tabular}
\end{htmlonly}

\end{table}

Ligatures and special symbols are shown in \tableref{tab:ligatures}.
(Note that, as mentioned in the \htmlref{introduction}{ch:intro}, the
f-ligatures are automatically converted.)  When using a command in
the middle of a word, take care that the command doesn't run into the
rest of the word.  For example, the British spelling of the word
man\oe{}uvre has an
\latexhtml{\oe}{oe}-ligature in the middle of it.
You will get an error if you try:
\begin{alltt}\wrong
man\cmdname{oe}uvre
\end{alltt}
as \LaTeX\ will interpret it as the command
\verb|\oeuvre| which doesn't exist.

There are several ways to code this in \LaTeX:
\begin{enumerate}

\item Place a space after the command:
\begin{codeS}
man\glsni{oe}\glsni{visiblespace}uvre
\end{codeS}

\item Place an empty brace after the command:
\begin{codeS}
man\glsni{oe}\marg{}uvre
\end{codeS}

\item Group the command:
\begin{codeS}
man\marg{\glsni{oe}}uvre
\end{codeS}
(This can adversely affect the kerning so is best avoided.)

\end{enumerate}

\begin{table}[htbp]
\caption[Ligatures and Special Symbols]{Ligatures and Special Symbols (Computer Modern Font)}
\label{tab:ligatures}
\centering
\begin{tabular}{ll@{\hspace{3\tabcolsep}}ll@{\hspace{3\tabcolsep}}ll@{\hspace{3\tabcolsep}}ll}
\gls{AE} & 
  \makeimg{upper case AE ligature}{\fontfamily{cmr}\selectfont\AE} &
\gls{ae} & 
  \makeimg{lower case ae ligature}{\fontfamily{cmr}\selectfont\ae} &
\gls{OE} & 
  \makeimg{upper case OE ligature}{\fontfamily{cmr}\selectfont\OE} &
\gls{oe} & 
  \makeimg{lower case oe ligature}{\fontfamily{cmr}\selectfont\oe}\\
\Indextt{fi} & 
  \makeimg{fi ligature}{\fontfamily{cmr}\selectfont fi} &
\Indextt{ffi} & 
  \makeimg{ffi ligature}{\fontfamily{cmr}\selectfont ffi} &
\Indextt{fl} & 
  \makeimg{fl ligature}{\fontfamily{cmr}\selectfont fl} &
\Indextt{ffl} & 
  \makeimg{ffl ligature}{\fontfamily{cmr}\selectfont ffl}\\
\gls{AA} & \makeimg{upper case A ring}{\fontfamily{cmr}\selectfont\AA} &
\gls{aa} & \makeimg{lower case a ring}{\fontfamily{cmr}\selectfont\aa} &
\gls{L} & \makeimg{upper case L with a stroke}{\fontfamily{cmr}\selectfont\L} &
\gls{l} & \makeimg{lower case l with a stroke}{\fontfamily{cmr}\selectfont\l}\\
\gls{O} & \makeimg{upper case slashed O}{\fontfamily{cmr}\selectfont\O}&
\gls{o} & \makeimg{lower case slashed o}{\fontfamily{cmr}\selectfont\o} &
\gls{SS} & \makeimg{upper case Eszett}{\fontfamily{cmr}\selectfont\SS} &
\gls{ss} & \makeimg{lower case eszett}{\fontfamily{cmr}\selectfont\ss}
\end{tabular}
\end{table}

\refstepcounter{object}\label{obj:accents}%
English speakers are by and large very lackadaisical when it comes
to accents, but accents affect pronunciation, and so are just as
important as the correct spelling. There is a big difference
between putting your knife into someone's p\^at\'e (meat paste), and
putting your knife into someone's pate (head)!

Accented letters are created by specifying which accent you want, and
the letter on which to put the accent.  The accent commands are
listed in \xtableref{tab:accents}, and each command takes one
\gls{mandatory}.  The command indicates
what accent to use, and the argument indicates the letter on which to put
the accent.

You may have noticed in \tableref{tab:symbols} the commands \gls{i}
and \gls{j} which produce a dotless i and j (\i\ and \dotlessj).
With old versions of \LaTeX\ (or \TeX) an accent over a normal
\dq{i} or \dq{j} left the original dot in, which is incorrect, so a
dotless \dq{\i} or \dq{\dotlessj} were required. With modern
distributions, an accented \dq{i} or \dq{j} is correctly rendered.

\bookpagebreak
\xminisec{Example:}
\begin{code}
It's na\glsni{doublequote}ive to think that eating mouldy 
p\glsni{circum}at\glsni{acute}e won't result in food poisoning.
\end{code}%
Result:
\begin{resultS}[naive.html]
It's na\"{\i}ve to think that eating mouldy p\^at\'e won't result in food poisoning.
\end{resultS}%

\begin{table}[htbp]
\caption{Accent Commands}
\label{tab:accents}
\centering
\begin{tabular}{llc@{\hspace{3\tabcolsep}}llc}
\toprule
  & \multicolumn{2}{c@{\hspace{3\tabcolsep}}}{Example} &
  & \multicolumn{2}{c}{Example} \\
 Definition & Input & Output & Definition & Input & Output\\\midrule
\begin{inlinedef}\gls{acute}\marg{\meta{object}}\end{inlinedef} &
\verb|\'{c}| & \makeimg{c with an acute accent}{\'{c}} &
\begin{inlinedef}\gls{macron}\marg{\meta{object}}\end{inlinedef} &
\verb|\={c}| & \makeimg{c with a macron accent}{\={c}} \\
\begin{inlinedef}\gls{grave}\marg{\meta{object}}\end{inlinedef} &
\verb|\`{c}| & \makeimg{c with a grave accent}{\`{c}} &
\begin{inlinedef}\gls{period}\marg{\meta{object}}\end{inlinedef} &
\verb|\.{c}| & \makeimg{c with a dot over it}{\.{c}} \\
\begin{inlinedef}\gls{circum}\marg{\meta{object}}\end{inlinedef} &
\verb|\^{c}| & \makeimg{c with a circumflex}{\^{c}} &
\begin{inlinedef}\gls{tilde}\marg{\meta{object}}\end{inlinedef} &
\verb|\~{c}| & \makeimg{c with a tilde above}{\~{c}} \\
\begin{inlinedef}\gls{doublequote}\marg{\meta{object}}\end{inlinedef} &
\verb|\"{c}| & \makeimg{c with an umlaut}{\"{c}} &
\begin{inlinedef}\gls{v}\marg{\meta{object}}\end{inlinedef} &
\verb|\v{c}| & \makeimg{c with a caron accent}{\v{c}} \\
\begin{inlinedef}\gls{u}\marg{\meta{object}}\end{inlinedef} &
\verb|\u{c}| & \makeimg{c with a breve accent over it}{\u{c}} &
\begin{inlinedef}\gls{H}\marg{\meta{object}}\end{inlinedef} &
\verb|\H{c}| & \makeimg{c with double acute accent}{\H{c}} \\
\begin{inlinedef}\gls{t}\marg{\meta{object}}\end{inlinedef} &
\verb|\t{xy}| & \makeimg{x and y with a tie over them}{\t{xy}} &
\begin{inlinedef}\gls{c}\marg{\meta{object}}\end{inlinedef} &
\verb|\c{c}| & \makeimg{c with a cedilla}{\c{c}}\\
\begin{inlinedef}\gls{d}\marg{\meta{object}}\end{inlinedef} &
\verb|\d{c}| & \makeimg{c with a dot under it}{\d{c}} &
\begin{inlinedef}\gls{b}\marg{\meta{object}}\end{inlinedef} &
\verb|\b{c}| & \makeimg{c with a bar under it}{\b{c}}\\
\begin{inlinedef}\gls{r}\marg{\meta{object}}\end{inlinedef} &
\verb|\r{c}| & \makeimg{c with a ring above}{\r{c}} & & &\\
\bottomrule
\end{tabular}
\end{table}

This book only covers a very small subset of available symbol
commands. If the command you want isn't here, try Scott~Pakin's
comprehensive symbol list~\cite{pakin09}. Another useful resource is
\iappnamelink[.]{detexify}{http://detexify.kirelabs.org/classify.html}

\setnode{inputenc}
\subsection{The \sty{inputenc} Package}
\label{sec:inputenc}

Instead of using the accent and ligature commands described
\htmlref{above}{sec:chars}, you can use the \isty{inputenc} package
and enter the character directly, but you must ensure you match the
encoding with that used by your text editor. For example, this book
uses UTF8 encoding so I~have loaded the \sty{inputenc} package in
the \glsterm{preamble} with the \istyopt{inputenc}{utf8} option:
\begin{codeS}
\glsni{usepackage}\oarg{utf8}\marg{inputenc}
\end{codeS}
Note that it's a good idea to also use the \isty{fontenc} package as
well. For example, if you want to use Type~1 fonts:
\begin{code}
\begin{alltt}
\glsni{usepackage}\oarg{T1}\marg{fontenc}
\glsni{usepackage}\oarg{utf8}\marg{inputenc}
\end{alltt}
\end{code}

Returning to an earlier example, 
I~can directly enter the Unicode character (U+0153) for the
lower case \oe\ ligature:
\bookpagebreak
% actually I can't do it because latex2html won't like it, but lets
% pretend I have
\begin{codeS}
man\oe uvre
\end{codeS}
Note that if you are collaborating on a document and you want to
use this approach, you must ensure that all your co-authors use the
same input encoding. For example, suppose you decide to use
ISO~Latin~1 encoding (\istyopt{inputenc}{latin1} option):
\begin{codeS}
\glsni{usepackage}\oarg{latin1}\marg{inputenc}
\end{codeS}
but your co-author is using a UTF-8 editor and types:
\begin{codeS}
na\"ive
\end{codeS}
where \texttt{\"i} is the Unicode character U+00EF\@. UTF-8 characters
use one to four 8-bit bytes whereas ISO Latin~1 uses an 8-bit
single-byte character set. So the U+00EF binary sequence is
interpreted by ISO Latin~1 encoding as two characters: \~A\ (0xC3)
and \={ } (0xAF)\@.  Therefore the resulting PDF file will end up
containing the rather odd looking:
\begin{flushleft}\wrong
na\~A\={ }ve
\end{flushleft}\html{\par}%
(If you are using TeXWorks, you can set your preferred encoding
using \menu{Edit}\menuto\menu{Preferences} and select the \dq{Editor} tab 
where there is an \dq{Encoding} setting. Make sure this setting
matches the \isty{inputenc} option you use in your document.)

\begin{exercise}{Using Special Characters}{ex:spchar}
Start a new file in TeXworks, and
see if you can write the source code to create the output below.
\doifnotbook{(Ignore any \gls{hyphenation} that may appear below, \LaTeX\ does
that automatically where necessary, see \sectionref{sec:hyphenation}. Likewise, 
ignore where the line breaks occur, except for the paragraph break.) }Choose 
whether you want to use the \isty{inputenc} package or if you
want to use commands such as \gls{c}, but in either case you need to
be careful of the \htmlref{special characters}{tab:specialchars}\doifbook{\ 
listed in \tableref{tab:specialchars}}.

\begin{result}[spcharex.html]\setlength{\parindent}{1.5em}%
Item \#1: Our travel expenditure came to \$2000.00 
\& our equipment expenditure came
to \pounds 100.00 plus VAT @ 17.5\%.

Chlo\"e collected Zo\"e from the cr\`eche. They stopped to
admire the fa\c{c}ade of a new caf\'e and then went to a matin\'ee.
\end{result}

You can \downloadorview{spchar} the source code if you can't work out
how to do it, and remember to check \appendixref{ch:errors} if you have a problem.

\end{exercise}

%%%%%%%%%%%%%%%%%%%%%%%%% Lists %%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{lists}
\section{Lists}
\label{sec:lists}

Now you've had a go at using some \glspl{command},
let's use some \glspl{environment}\latex{ (recall
\sectionref{sec:environment})}. A good example of environments are the list
making environments. There are three basic list making environments:
\glsni{env-itemize} (for unordered lists),
\glsni{env-enumerate} (for ordered lists) and
\glsni{env-description} (for lists where you want to specify
your own label.)

In each of these environments, each item in the list must be started
with the command: 
\begin{definition}
\gls{item}\oarg{\meta{marker}}
\end{definition}
The optional argument \meta{marker} can be used to override 
the default marker for that particular item. (For example, to replace
the bullet point for an individual item in an \htmlref{unordered
list}{sec:itemize} to make that item stand out from all the other
items.) We will be looking at how to change the default marker
in \sectionref{sec:renewcom}.

\xminisec{Related \gls{ukfaq} topics:}
\begin{itemize}
\item \faqlink{Perhaps a missing \cmdname{item}?}{errmissitem}
\item \faqlink{Fancy enumeration lists}{enumerate}
\item \faqlink{How to adjust list spacing}{complist}
\item \faqlink{Interrupting enumerated lists}{interruptlist}
\item \faqlink{\dq{Too deeply nested}}{toodeep}
\end{itemize}

%---------------------- Itemize --------------------------

\setnode{itemize}
\subsection{Unordered Lists}
\label{sec:itemize}

Unordered lists are created using the \gls{env-itemize} environment.

\xminisec{Example:}
\begin{code}
\glsni{begin}\marg{itemize}\newline
\glsni{item} Animal\newline
\glsni{item} Vegetable\newline
\glsni{item} Mineral\newline
\glsni{end}\marg{itemize}
\end{code}
\begin{result}[itemize.html]
\begin{itemize}
\item Animal
\item Vegetable
\item Mineral
\end{itemize}
\end{result}

\xminisec{Another Example:}

Changing the default markers is covered in \sectionref{sec:renewcom}, 
but it's also possible to override the default marker for a
particular item, as in this example (recall the double-dagger
symbol command \gls{ddag} from \tableref{tab:symbols}):
\begin{code}
\glsni{begin}\marg{itemize}\newline
\glsni{item} Animal\newline
\glsni{item}\oarg{\glsni{ddag}} Vegetable\newline
\glsni{item} Mineral\newline
\glsni{end}\marg{itemize}
\end{code}%
\begin{result}[itemizedag.html]
\begin{itemize}
\item Animal
\item[\ddag] Vegetable
\item Mineral
\end{itemize}
\end{result}

Be careful about using square brackets
\gls{text.opensq}\gls{text.closesq} inside an optional
argument. Grouping is required, as in:
\begin{code}
\glsni{begin}\marg{itemize}\newline
\glsni{item} Animal\newline
\glsni{item}\oarg{\marg{\gls{text.opensq}X\gls{text.closesq}}} Vegetable\newline
\glsni{item} Mineral\newline
\glsni{end}\marg{itemize}
\end{code}%
\begin{result}[itemizesqbr.html]
\begin{itemize}
\item Animal
\item[{[X]}] Vegetable
\item Mineral
\end{itemize}
\end{result}
Similarly if the item starts with an open square bracket
\glsni{opensq}, as in:
\begin{code}
\glsni{begin}\marg{itemize}\newline
\glsni{item} Animal\newline
\glsni{item} \marg{\gls{text.opensq}sic\gls{text.closesq}} Wegetable\newline
\glsni{item} Mineral\newline
\glsni{end}\marg{itemize}
\end{code}
\begin{result}[itemizetextsqbr.html]
\begin{itemize}
\item Animal
\item {[sic]} Wegetable
\item Mineral
\end{itemize}
\end{result}

\setnode{nesteditemize}
\subsubsection{Nested Lists}
\label{sec:nesteditemise}

It is also possible to nest \glsni{env-itemize} environments.
The following example has three levels, each using its own default marker.

\begin{code}
\glsni{begin}\marg{itemize}\newline
\glsni{item} Animal\newline
\glsni{begin}\marg{itemize}\newline
\glsni{item} Mammals\newline
\glsni{item} Birds\newline
\glsni{item} Reptiles. For example:\newline
\glsni{begin}\marg{itemize}\newline
\glsni{item} dinosaurs\newline
\glsni{item} crocodiles\newline
\glsni{end}\marg{itemize}\newline
\glsni{end}\marg{itemize}\newline
\glsni{item} Vegetable\newline
\glsni{begin}\marg{itemize}\newline
\glsni{item} Cultivated\newline
\glsni{item} Wild\newline
\glsni{end}\marg{itemize}\newline
\glsni{item} Mineral\newline
\glsni{end}\marg{itemize}
\end{code}
\begin{result}[nesteditemize.html]
\begin{itemize}
\item Animal
\begin{itemize}
\item Mammals
\item Birds
\item Reptiles. For example:
\begin{itemize}
\item dinosaurs
\item crocodiles
\end{itemize}
\end{itemize}
\item Vegetable
\begin{itemize}
\item Cultivated
\item Wild
\end{itemize}
\item Mineral
\end{itemize}
\end{result}

You might have noticed the code in the above example is a little
difficult to read. Each new list item starts a new paragraph, so it
doesn't matter if we have blank lines before each item. Also, recall
from \chapterref{ch:def} that spaces at the start of each line of
code are ignored, so it's possible to make the code more readable
without affecting the final result:

\begin{code}
\begin{alltt}
\glsni{begin}\marg{itemize}

   \glsni{item} Animal

   \glsni{begin}\marg{itemize}

      \glsni{item} Mammals

      \glsni{item} Birds

      \glsni{item} Reptiles. For example:

      \glsni{begin}\marg{itemize}

         \glsni{item} dinosaurs

         \glsni{item} crocodiles

       \glsni{end}\marg{itemize}

   \glsni{end}\marg{itemize}

   \glsni{item} Vegetable

   \glsni{begin}\marg{itemize}

      \glsni{item} Cultivated

      \glsni{item} Wild

   \glsni{end}\marg{itemize}

   \glsni{item} Mineral

\glsni{end}\marg{itemize}
\end{alltt}
\end{code}

It's now a little easier to see which \verb|\begin{itemize}| matches
up with the corresponding \verb|\end{itemize}|.

\xminisec{Example (Four Levels)}

This example has four levels, which is the maximum allowed by most
classes.

\begin{code}
\begin{alltt}
\glsni{begin}\marg{itemize}
 \glsni{item} Animal

 \glsni{begin}\marg{itemize}
   \glsni{item} Mammal

   \glsni{begin}\marg{itemize}
    \glsni{item} Placental

    \glsni{item} Monotreme

    \glsni{begin}\marg{itemize}
      \glsni{item} Platypus
    \glsni{end}\marg{itemize}

    \glsni{item} Marsupial

    \glsni{begin}\marg{itemize}
     \glsni{item} Kangaroo

     \glsni{item} Koala
    \glsni{end}\marg{itemize}
   \glsni{end}\marg{itemize}

   \glsni{item} Reptile
 \glsni{end}\marg{itemize}

 \glsni{item} Vegetable

 \glsni{item} Mineral
\glsni{end}\marg{itemize}
\end{alltt}
\end{code}
\begin{result}[fourlevelitemize.html]
\begin{itemize}
 \item Animal
 \begin{itemize}
   \item Mammal

   \begin{itemize}
    \item Placental

    \item Monotreme
    \begin{itemize}
      \item Platypus
    \end{itemize}


    \item Marsupial

    \begin{itemize}
     \item Kangaroo

     \item Koala
    \end{itemize}
   \end{itemize}

   \item Reptile
 \end{itemize}

 \item Vegetable

 \item Mineral
\end{itemize}
\end{result}

If you try adding a further level, \LaTeX\ will give a \dq{Too
deeply nested} error.

%---------------- Enumerate -------------------------

\setnode{enumerate}
\subsection{Ordered Lists}
\label{sec:enumerate}

Ordered lists are created using the \gls{env-enumerate} 
environment.
It has exactly the same format as the \gls{env-itemize} environment
described \htmlref{above}{sec:itemize}.

We can use the same example as before, only this time use
\glsni{env-enumerate} instead of \gls{env-itemize}.

\begin{code}
\begin{alltt}
\glsni{begin}\marg{enumerate}
  \glsni{item} Animal
  \glsni{item} Vegetable
  \glsni{item} Mineral
\glsni{end}\marg{enumerate}
\end{alltt}
\end{code}%
The above input will produce the following output:
\begin{result}[enumerate.html]
\begin{enumerate}
\item Animal
\item Vegetable
\item Mineral
\end{enumerate}
\end{result}

As before, the marker for a particular item can be overridden:
\begin{code}
\glsni{begin}\marg{enumerate}\newline
\strut~~\glsni{item} Animal\newline
\strut~~\glsni{item}\oarg{\marg{\gls{text.opensq}X\gls{text.closesq}}} Vegetable\newline
\strut~~\glsni{item} Mineral\newline
\glsni{end}\marg{enumerate}
\end{code}%
\begin{result}[enumeratesqbr.html]
\begin{enumerate}
\item Animal
\item[{[X]}] Vegetable
\item Mineral
\end{enumerate}
\end{result}

\xminisec{Example (Nested):}

As with the \gls{env-itemize} environment, most classes allow a
maximum of four nested \gls{env-enumerate} environments.

\begin{code}
\begin{alltt}
\glsni{begin}\marg{enumerate}
 \glsni{item} Animal

 \glsni{begin}\marg{enumerate}
   \glsni{item} Mammal

   \glsni{begin}\marg{enumerate}
    \glsni{item} Placental

    \glsni{item} Monotreme

    \glsni{begin}\marg{enumerate}
      \glsni{item} Platypus
    \glsni{end}\marg{enumerate}

    \glsni{item} Marsupial

    \glsni{begin}\marg{enumerate}
     \glsni{item} Kangaroo

     \glsni{item} Koala
    \glsni{end}\marg{enumerate}
   \glsni{end}\marg{enumerate}

   \glsni{item} Reptile
 \glsni{end}\marg{enumerate}

 \glsni{item} Vegetable

 \glsni{item} Mineral
\glsni{end}\marg{enumerate}
\end{alltt}
\end{code}
\begin{result}[nestedenumerate.html]
\begin{enumerate}
 \item Animal
 \begin{enumerate}
   \item Mammal

   \begin{enumerate}
    \item Placental

    \item Monotreme
    \begin{enumerate}
      \item Platypus
    \end{enumerate}


    \item Marsupial

    \begin{enumerate}
     \item Kangaroo

     \item Koala
    \end{enumerate}
   \end{enumerate}

   \item Reptile
 \end{enumerate}

 \item Vegetable

 \item Mineral
\end{enumerate}
\end{result}

%--------------------- Description -------------------------

\setnode{description}
\subsection{Description Environment}
\label{sec:description}

The \gls{env-description} environment has the same format as
the \gls{env-itemize} environment described in
\sectionref{sec:itemize}, only this time you need to
specify a marker as an \gls{optional} to
the \gls{item} command, since there is no default marker
for this environment. The marker may be a textual label, and most
classes will typeset it in bold. The \koma\ classes, such as
\icls{scrartcl}, default to a bold sans-serif font, as illustrated
in this next example:

\begin{code}
\begin{alltt}
\glsni{begin}\marg{description}
  \glsni{item}\oarg{Animal} Living being

  \glsni{item}\oarg{Vegetable} Plant
 
  \glsni{item}\oarg{Mineral} Natural inorganic substance
\glsni{end}\marg{description}
\end{alltt}
\end{code}
\begin{result}[description.html]
\dodescriptionexample
\end{result}

The \koma\ classes provide a way of changing the font style in
the \glsni{env-description} label markers. (The font changing commands
\glsni{normalfont} and \glsni{scshape} will be covered in 
\sectionref{sec:fonts}, and the \koma\ command
\glsni{addtokomafont} in \sectionref{sec:section}.)

\begin{code}
\begin{alltt}
\glsni{addtokomafont}\marg{descriptionlabel}\marg{\glsni{normalfont}\glsni{scshape}}
\glsni{begin}\marg{description}
  \glsni{item}\oarg{Animal} Living being

  \glsni{item}\oarg{Vegetable} Plant

  \glsni{item}\oarg{Mineral} Natural inorganic substance
\glsni{end}\marg{description}
\end{alltt}
\end{code}
\begin{result}[descriptionkoma.html]
% Make sure LaTeX2HTML doesn't think this should be the same
% image as the previous example
\dodescriptionkomaexample
\end{result}

It is possible to nest all the listing environments, as long as you
don't exceed four \gls{env-itemize} and four \gls{env-enumerate}
environments. The \gls{env-description} environment has no
restriction on the number of times it can be nested. However, just
because you can do something, doesn't mean you should. In general
it's best to avoid an excessively complicated block of text in your
document.

\xminisec{Example (Assorted Nesting):}

This example uses each of the listing environments described above.

\bookpagebreak
\begin{code}
\begin{alltt}
\glsni{begin}\marg{description}

   \glsni{item}\oarg{Animal} Living being

   \glsni{begin}\marg{itemize}

      \glsni{item} Mammals

      \glsni{item} Birds

      \glsni{item} Reptiles. For example:

      \glsni{begin}\marg{enumerate}

         \glsni{item} dinosaurs

         \glsni{item} crocodiles

       \glsni{end}\marg{enumerate}

   \glsni{end}\marg{itemize}

   \glsni{item}\oarg{Vegetable} Plant

   \glsni{begin}\marg{itemize}

      \glsni{item} Cultivated. For example:

      \glsni{begin}\marg{enumerate}

         \glsni{item} Carrots

         \glsni{item} Broccoli

         \glsni{item} Potatoes

      \glsni{end}\marg{enumerate}

      \glsni{item} Wild

   \glsni{end}\marg{itemize}

   \glsni{item}\oarg{Mineral} Natural inorganic substance

\glsni{end}\marg{description}
\end{alltt}
\end{code}

\begin{result}[nestedlists.html]
\begin{description}

   \item[Animal] Living being

   \begin{itemize}

      \item Mammals

      \item Birds

      \item Reptiles. For example:
      \begin{enumerate}

         \item dinosaurs

         \item crocodiles

       \end{enumerate}

   \end{itemize}

   \item[Vegetable] Plant

   \begin{itemize}

      \item Cultivated. For example:

      \begin{enumerate}

         \item Carrots

         \item Broccoli

         \item Potatoes

      \end{enumerate}


      \item Wild

   \end{itemize}

   \item[Mineral] Natural inorganic substance

\end{description}
\end{result}

\begin{exercise}{Lists}{ex:lists}

Try writing the \gls{source} that will create
the output shown below.

\begin{result}[listex.html]
\begin{description}
\item[Village] A small collection of dwelling places.
Examples:
\begin{enumerate}
\item Marlingford
\item Saxlingham Nethergate
\end{enumerate}

\item[Town] A large collection of dwelling places.
Examples:
\begin{enumerate}
\item Great Yarmouth
\item Beccles
\end{enumerate}

\item[City] A large town, usually containing a cathedral.
Examples:
\begin{enumerate}
\item Norwich
\item Birmingham
\item London
\end{enumerate}
\end{description}
\end{result}\bookpagebreak
You can \downloadorview{lists} the answer if you can't work out how to do it.

\end{exercise}

%%%%%%%%%%%%%%%%%% Font Changing Commands %%%%%%%%%%%%%%%%%%%%%%

\setnode{fontcommands}
\section{Fonts}
\label{sec:fonts}

\LaTeX\ uses Donald~Knuth's Computer Modern fonts by
default\faq{Using PostScript fonts with TeX}{usepsfont}. This
supplies three font families: serif, sans-serif and a typewriter (or
monospaced) font (as well as the maths
fonts which are discussed in
\sectionref{sec:mathsfonts}). With each font family, you can
change the shape and weight, as well as the size.

\reportpagebreak
\setnode{fontstyle}
\subsection{Changing the Font Style}
\label{sec:fontstyle}

There are two basic ways of changing fonts: you can either change
the font for a small selection of text, for example, if you want to
\emph{emphasize} a word, or you may wish to change the font \dq{from
this point onwards}. The \glspl{command} shown in
\tableref{tab:fontsI} are of the first type (text-block
commands\index{command!text-block|hyperpage}), whereas those shown
in \tableref{tab:fontsII} are of the second type\dash a
\gls{declaration} (or modal command\index{command!modal|hyperpage}).

\xminisec{Note:}

\warning Don't be tempted to use \cmdname{bf}, \cmdname{md}, \cmdname{it}, 
\cmdname{sl}, \cmdname{sc}, \cmdname{sf}, \cmdname{tt} or \cmdname{rm}. 
These commands are \textbf{obsolete}~\cite{l2tabu}.\faq{What's wrong with \cmdname{bf}, \cmdname{it}
etc.?}{2letterfontcmd}

If you use an italic or slanted font declaration, such as
\glsni{itshape}, you will need to add an \keyword{italic correction}
\gls{itcorr} at the end of the block of text, when the last letter
of the sloping text leans too far over. This isn't necessary for
text-block commands, such as \glsni{textit}, just for the modal
commands. The effect is more noticeable when part of a word is
stressed, particularly with certain fonts.

\xminisec{Example:}

In the code below, the first instance of \dq{repeated} doesn't have an italic
correction but the second does: 
\begin{codeS}
\marg{\glsni{itshape} repeated}ly \marg{\glsni{itshape}
repeated\glsni{itcorr}}ly
\end{codeS}%
Using Computer Modern:
\begin{resultS}[repeatedly repeatedly]\fontfamily{cmr}\selectfont
{\itshape repeated}ly {\itshape repeated\/}ly
\end{resultS}
Using Helvetica:
\begin{resultS}[repeatedly repeatedly]\fontfamily{phv}\selectfont
{\itshape repeated}ly {\itshape repeated\/}ly
\end{resultS}
Using Antykwa Toru\'nska typeface:
\begin{resultS}[repeatedly repeatedly]
{\itshape repeated}ly {\itshape repeated\/}ly
\end{resultS}

\begin{table}[tp]
\caption{Font Changing Text-Block Commands}
\label{tab:fontsI}
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\bfseries Command & \bfseries Example Input & \bfseries Corresponding output\\
& & (Computer Modern)\\
\midrule
\begin{inlinedef}\gls{textrm}\marg{\meta{text}}\end{inlinedef} &
\verb|\textrm{roman} text| & \makeimg{Roman text}{\fontfamily{cmr}\selectfont{\fontfamily{cmr}\selectfont roman} text}\\
\begin{inlinedef}\gls{textsf}\marg{\meta{text}}\end{inlinedef} &
\verb|\textsf{sans serif} text| & \makeimg{sans serif text}{\fontfamily{cmr}\selectfont{\fontfamily{cmss}\selectfont sans serif} text}\\
\begin{inlinedef}\gls{texttt}\marg{\meta{text}}\end{inlinedef} &
\verb|\texttt{typewriter} text| & \makeimg{typewriter text}{\fontfamily{cmr}\selectfont{\fontfamily{cmtt}\selectfont typewriter} text}\\[5pt]
\begin{inlinedef}\gls{textmd}\marg{\meta{text}}\end{inlinedef} &
\verb|\textmd{medium} text| & \makeimg{medium text}{\fontfamily{cmr}\selectfont\textmd{medium} text}\\
\begin{inlinedef}\gls{textbf}\marg{\meta{text}}\end{inlinedef} &
\verb|\textbf{bold} text| & \makeimg{bold text}{\fontfamily{cmr}\selectfont\textbf{bold} text}\\[5pt]
\begin{inlinedef}\gls{textup}\marg{\meta{text}}\end{inlinedef} &
\verb|\textup{upright} text| & \makeimg{upright text}{\fontfamily{cmr}\selectfont\textup{upright} text}\\
\begin{inlinedef}\gls{textit}\marg{\meta{text}}\end{inlinedef} &
\verb|\textit{italic} text| & \makeimg{italic text}{\fontfamily{cmr}\selectfont\textit{italic} text}\\
\begin{inlinedef}\gls{textsl}\marg{\meta{text}}\end{inlinedef} &
\verb|\textsl{slanted} text| & \makeimg{slanted text}{\fontfamily{cmr}\selectfont\textsl{slanted} text}\\[5pt]
\begin{inlinedef}\gls{textsc}\marg{\meta{text}}\end{inlinedef} &
\verb|\textsc{Small Caps} text| &
\makeimg{Small Caps text}{\fontfamily{cmr}\selectfont\textsc{Small Caps} text}\\
\begin{inlinedef}\gls{emph}\marg{\meta{text}}\end{inlinedef} &
\verb|\emph{emphasized} text| &
\makeimg{emphasized text}{\fontfamily{cmr}\selectfont\emph{emphasized} text}\\[5pt]
\begin{inlinedef}\gls{textnormal}\marg{\meta{text}}\end{inlinedef} &
\verb|\textnormal{default} text| &
\makeimg{default text}{\fontfamily{cmr}\selectfont default text}
\\\bottomrule
\end{tabular}
\end{table}

Note that if you want to typeset an URL, rather than using
\glsni{texttt} it is better to use\bookpagebreak
\begin{definition}
\gls{url}\marg{\meta{address}}
\end{definition}
which is defined in the \isty{url} package. For example:
\begin{codeS}%
\begin{alltt}
\glsni{url}\marg{http://theoval.cmp.uea.ac.uk/\glsnl{tildechar}nlct/}
\end{alltt}
\end{codeS}
produces:
\begin{resultS}[http://theoval.cmp.uea.ac.uk/\tildesym nlct/]
% simulate to prevent link, which might confuse the reader into
% thinking links automatically occur.
\texttt{http://theoval.cmp.uea.ac.uk/\tildesym nlct/}
\end{resultS}
(Note there is no need to do anything with the \gls{tildechar}
(tilde) \htmlref{special character}{sec:chars} if you use it in the argument of \glsni{url}.)

\begin{table}[hbtp]
\caption{Font Changing Declarations}
\label{tab:fontsII}
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\bfseries Declaration & \bfseries Example Input & \bfseries Corresponding output\\
& & (Computer Modern)\\
\midrule
\begin{inlinedef}\gls{rmfamily}\end{inlinedef} &
\verb|\rmfamily roman text| &
\makeimg{Roman text}{\fontfamily{cmr}\selectfont roman text}\\
\begin{inlinedef}\gls{sffamily}\end{inlinedef} &
\verb|\sffamily sans serif text| &
\makeimg{sans serif text}{\fontfamily{cmss}\selectfont sans serif text}\\
\begin{inlinedef}\gls{ttfamily}\end{inlinedef} &
\verb|\ttfamily typewriter text| &
\makeimg{typewriter text}{\fontfamily{cmtt}\selectfont typewriter text}\\[5pt]
\begin{inlinedef}\gls{mdseries}\end{inlinedef} &
\verb|\mdseries medium text| &
\makeimg{medium text}{\fontfamily{cmr}\selectfont\mdseries medium text}\\
\begin{inlinedef}\gls{bfseries}\end{inlinedef} &
\verb|\bfseries bold text| &
\makeimg{bold text}{\fontfamily{cmr}\selectfont\bfseries bold text}\\[5pt]
\begin{inlinedef}\gls{upshape}\end{inlinedef} &
\verb|\upshape upright text| &
\makeimg{upright text}{\fontfamily{cmr}\selectfont\upshape upright text}\\
\begin{inlinedef}\gls{itshape}\end{inlinedef} &
\verb|\itshape italic text| &
\makeimg{italic text}{\fontfamily{cmr}\selectfont\itshape italic text}\\
\begin{inlinedef}\gls{slshape}\end{inlinedef} &
\verb|\slshape slanted text| &
\makeimg{slanted text}{\fontfamily{cmr}\selectfont\slshape slanted text}\\
\begin{inlinedef}\gls{scshape}\end{inlinedef} &
\verb|\scshape Small Caps text| &
\makeimg{Small Caps text}{\fontfamily{cmr}\selectfont\scshape Small Caps text}\\[5pt]
\begin{inlinedef}\gls{em}\end{inlinedef} &
\verb|\em emphasized text| & 
\makeimg{emphasized text}{\fontfamily{cmr}\selectfont\em emphasized text}\\[5pt]
\begin{inlinedef}\gls{normalfont}\end{inlinedef} &
\verb|\normalfont default text| &
\makeimg{default text}{\fontfamily{cmr}\selectfont default text}
\\\bottomrule
\end{tabular}

\end{table}

\refstepcounter{object}\label{obj:fontenv}\Glspl{environment} can be used instead.
Each \gls{environment} has the same name as its corresponding
declaration, but \emph{without} the preceding backslash. For example:
\begin{codeS}
\begin{alltt}
\glsni{begin}\marg{sffamily}Some sans-serif text.\glsni{end}\marg{sffamily}
\end{alltt}
\end{codeS}%
yields:
\begin{resultS}[Some sans-serif text.]
\begin{sffamily}Some sans-serif text.\end{sffamily}
\end{resultS}

You can combine a font family with a given shape and weight using
a variety of methods.

\xminisec{Examples:}

\begin{enumerate}
\item Localised declarations:

\begin{codeS}
\marg{\glsni{sffamily}\glsni{slshape} Some slanted sans-serif text.}
\end{codeS}

\item Declarations that later get explicitly reset:

\begin{codeS}
\glsni{sffamily}\glsni{slshape} Some slanted sans-serif
text.\glsni{normalfont}
\end{codeS}

\bookpagebreak
\item Mixing text-block and modal commands:

\begin{codeS}
\glsni{textsf}\marg{\glsni{slshape} Some slanted sans-serif text.}
\end{codeS}

\item Nested commands:

\begin{codeS}
\glsni{textsf}\marg{\glsni{textsl}\marg{Some slanted sans-serif text.}}
\end{codeS}

\item Mixing environments and declarations:

\begin{code}
\glsni{begin}\marg{sffamily}\glsni{slshape} Some slanted sans-serif 
text.\glsni{end}\marg{sffamily}
\end{code}
\end{enumerate}

All of the above produce the same output:
\begin{resultS}[Some slanted sans-serif text.]
\textsf{\slshape Some slanted sans-serif text.}
\end{resultS}

\faq{Warning: \dq{Font shape \ldots\ not
available}}{fontunavail}Note that some combinations are not
available, in which case \LaTeX\ will give a warning message, and
will substitute the font for what it considers to be the closest
available match.

\xminisec{Example:}
\begin{codeS}
\glsni{textsc}\marg{\glsni{bfseries} Text}
\end{codeS}
With the Antykwa Toru\'nska typeface, this appears as:
\begin{resultS}[Text (in bold small caps)]
\textsc{\bfseries Text}
\end{resultS}\bookpagebreak\noindent
whereas with Computer Modern, the result is:
\begin{resultS}[Text (in bold)]\fontfamily{cmr}\selectfont
\textsc{\bfseries Text}
\end{resultS}
This is because Computer Modern doesn't have a bold small-caps
font, so it just uses bold. \LaTeX\ gives the following warning:
\begin{verbatim}
LaTeX Font Warning: Font shape `T1/cmr/b/sc' undefined
(Font)              using `T1/cmr/b/n' instead on input line 2792.
\end{verbatim}
Most sans-serif fonts don't provide a small-caps variant, so 
\begin{codeS}
\glsni{textsf}\marg{\glsni{scshape} Text}
\end{codeS}
will either appear in regular sans-serif or small-caps serif,
depending on the font in use. Using Libris sans-serif the result is:
\begin{resultS}[Text (in sans-serif)]
\textsf{\scshape Text}
\end{resultS}
whereas using Computer Modern Sans, the result is:
\begin{resultS}[Text (in small caps)]
\fontfamily{cmss}
\scshape Text
\end{resultS}

\setnode{emph}
\subsubsection{Emphasizing Words or Phrases}
\label{sec:emph}

The \gls{command} \gls{emph},
the \gls{declaration} \gls{em} and the
\gls{environment} \gls{env-em} behave slightly
differently to the corresponding \gls{textit} command,
\gls{itshape} declaration and \gls{env-itshape} environment.
The latter group simply use an italic font, whereas the former will toggle
between sloping and upright.  So if the surrounding font is upright
then \gls{emph}, \gls{em} and \glsni{env-em} will use the
sloping font, but if the surrounding font is italic or slanted,
\gls{emph}, \gls{em} and \glsni{env-em} will use an upright
font.  This is particularly useful in abstracts where the
\Index{abstract} font varies between \glspl{cls}.  It is recommended that if your intention
is to emphasize something, you should use \gls{emph} etc.\ rather
than \gls{textit} etc.\screenpagebreak

\xminisec{Examples:}
\begin{enumerate}
\item Emphasized text in upright surrounding:
\begin{codeS}
Some \glsni{emph}\marg{emphasized} text.
\end{codeS}%
yields
\begin{resultS}[Some emphasized text.]
Some \emph{emphasized} text.
\end{resultS}

\item Emphasized text in italic surrounding:
\begin{codeS}
\marg{\glsni{itshape} Some \glsni{emph}\marg{emphasized} text.}
\end{codeS}%
yields
\begin{resultS}[Some emphasized text]
{\itshape Some \emph{emphasized} text.}
\end{resultS}

\bookpagebreak
\item Emphasized text in upright sans-serif surrounding:
\begin{codeS}
\marg{\glsni{sffamily} Some \glsni{emph}\marg{emphasized} text.}
\end{codeS}%
yields
\begin{resultS}[Some emphasized text]
{\sffamily Some \emph{emphasized} text.}
\end{resultS}
\end{enumerate}

\setnode{fontsize}
\subsection{Changing the Font Size}
\label{sec:fontsize}

When you start writing a document, you need to decide what the base
font size should be. The \koma\ classes default to 11pt, but this can
be changed using the class options \scrclsopt{8pt}, \scrclsopt{9pt},
\clsopt{10pt}, \clsopt{12pt}, \scrclsopt{14pt}, \scrclsopt{17pt} or
\scrclsopt{20pt}.

You can then change the font size \emph{relative to} the base size,
using one of the declarations shown in \tableref{tab:fontsize}. That
way, if you later decide to change the normal font size from, say,
11pt to 12pt, all you need do is change the class option (see
\latexhtml{page~\pageref{obj:sizeopt}}{\htmlref{earlier}{obj:sizeopt}})
and re-run \LaTeX. Note that there are no equivalent text-block
commands.

\begin{table}[tbhp]
\caption{Font Size Changing Declarations}
\label{tab:fontsize}
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\bfseries Declaration & \bfseries Example Input & 
\bfseries Corresponding Output\\
\midrule
\begin{inlinedef}\gls{tiny}\end{inlinedef} &
\verb|\tiny tiny text| & \makeimg{tiny text}{\tiny tiny text}\\
\begin{inlinedef}\gls{scriptsize}\end{inlinedef} &
\verb|\scriptsize script size| &
\makeimg{script size}{\scriptsize script size}\\
\begin{inlinedef}\gls{footnotesize}\end{inlinedef} &
\verb|\footnotesize footnote size| &
\makeimg{footnote size}{\footnotesize footnote size}\\
\begin{inlinedef}\gls{small}\end{inlinedef} &
\verb|\small small text| &
\makeimg{small text}{\small small text}\\
\begin{inlinedef}\gls{normalsize}\end{inlinedef} &
\verb|\normalsize normal size| &
\makeimg{normal size}{\normalsize normal size}\\
\begin{inlinedef}\gls{large}\end{inlinedef} &
\verb|\large large text| &
\makeimg{large text}{\large large text}\\
\begin{inlinedef}\gls{Large}\end{inlinedef} &
\verb|\Large even larger| &
\makeimg{even larger}{\Large even larger}\\
\begin{inlinedef}\gls{LARGE}\end{inlinedef} &
\verb|\LARGE larger still| &
\makeimg{larger still}{\LARGE larger still}\\
\begin{inlinedef}\gls{huge}\end{inlinedef} &
\verb|\huge huge| & \makeimg{huge}{\huge huge}\\
\begin{inlinedef}\gls{Huge}\end{inlinedef} &
\verb|\Huge extra huge| &
\makeimg{extra huge}{\Huge extra huge}
\\\bottomrule
\end{tabular}

\end{table}

Again, \glspl{environment} can be used instead, where
each \gls{environment} has the same name as its corresponding
declaration, but \emph{without} the preceding backslash.
Font environments may be nested, for example:%
\indexEnv{itshape}\indexEnv{Large}
\begin{code}
\glsni{begin}\marg{itshape} Some italic text.
\glsni{begin}\marg{Large}This text is large.\glsni{end}\marg{Large}
\glsni{end}\marg{itshape} Back to normal.
\end{code}%
Output:
\begin{resultS}[Some italic text. This text is large. Back to
normal.]
\begin{itshape} Some italic text.
\begin{Large}This text is large.\end{Large}
\end{itshape}
Back to normal.
\end{resultS}

\setnode{documentfonts}
\subsection{Changing Document Fonts}
\label{sec:changingfonts}

\faq{Choice of scalable outline fonts}{psfchoice}What if you don't
want to use the default Computer Modern fonts? Some publishers and
institutions insist on a combination of Times Roman (serif),
Helvetica (sans-serif) and Courier (typewriter). To do this, you can
load the following packages:
\begin{description}
\item[\isty{mathptmx}] (Times) Only affects \gls{rmfamily} and
\gls{textrm}.

\item[\isty{helvet}] (Helvetica) Only affects \gls{sffamily} and
\gls{textsf}.

\item[\isty{courier}] (Courier) Only affects \gls{ttfamily}
and \gls{texttt}.
\end{description}

\xminisec{Notes:}

\begin{enumerate}

\item \warning Don't be tempted to use the \sty{times} package. It's
obsolete~\cite{l2tabu}. Use \isty{mathptmx} instead.

\item Although Times and Helvetica are commonly used together, they
don't match, as illustrated below (temporarily switching from this
book's fonts to Times and Helvetica):
\begin{codeS}
\glsni{rmfamily} xx \glsni{sffamily} xx
\end{codeS}
Results in:
\begin{resultS}[xx xx]
\fontfamily{ptm}\selectfont xx \fontfamily{phv}\selectfont xx
\end{resultS}
The first two x's are in Times Roman and the second two are in
Helvetica, which are somewhat larger. To compensate for this you
need to scale the Helvetica font using the \istyopt{helvet}{scaled}
option:
\begin{alltt}
\glsni{usepackage}\oarg{scaled=0.9}\marg{helvet}
\end{alltt}

\item Loading \isty{helvet} or \isty{courier} doesn't change the
default font family. Consider the following:
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{usepackage}\marg{helvet}

\glsni{begin}\marg{document}
This is a sample document.
\glsni{end}\marg{document}
\end{alltt}
Here, the text \dq{This is a sample document} will be typeset in
Computer Modern Roman. This is because \gls{rmfamily} is the default
font and \isty{helvet} only affects \gls{sffamily}, which hasn't
been used. (See \sectionref{sec:renewcom} to find out how to change
the default font family.)
\end{enumerate}
\latexhtml{This book}{The PDF version of this document} has used the following packages:
\begin{alltt}
\glsni{usepackage}\oarg{T1}\marg{fontenc}
\glsni{usepackage}\oarg{math}\marg{anttor}
\glsni{usepackage}\marg{libris}
\end{alltt}
The \isty{fontenc} package is used to switch to Type~1 font
encoding\faq{Why bother with \sty{inputenc} and \sty{fontenc}?}{why-inp-font},
the \isty{anttor} package is used to set the serif family to Antykwa
Toru\'nska typeface, and the \isty{libris} package is used to set
the sans-serif family to the Libris ADF typeface.

\begin{exercise}{Fonts}{ex:fonts}

Go back to the document you created in \exerciseref{ex:simpledoc} and
change the first paragraph to a large bold font and the second
paragraph to normal size italic.  Emphasize the words \dq{simple} and
\dq{short}.  (Again, you can \downloadorview{fonts} the solution.)

If you like, you can try experimenting with loading
different font packages, such as \isty{mathptmx}, to change the
default typeface. The \LaTeX\ Font Catalogue~\cite{fontcat} provides
a useful list of fonts, although you may not have all of them
installed.
\end{exercise}

%%%%%%%%%%%%%% Aligning Material in Rows and Columns %%%%%%%%%%%%%%%%

\setnode{tabular}
\section{Aligning Material in Rows and Columns}
\label{sec:tabular}

Text can be aligned in rows and columns using the \gls{env-tabular}
environment.
\begin{definition}
\glsni{begin}\marg{tabular}\oarg{\meta{pos}}\marg{\meta{column specifiers}}
\end{definition}%
This \glsterm{environment} has a
\glsterm{mandatory} \meta{column specifiers}
that specifies how to align each column. Within \meta{column
specifiers}, there must be a specifier for each column. The three
basic are: \texttt{r} (right aligned), \texttt{l} (left aligned) and
\texttt{c} (centred).
(Make sure you don't confuse \texttt{l} (the letter \dq{ell}) with \texttt{1} 
(the digit one).)
The optional argument \meta{pos} is covered 
\latexhtml{in \sectionref{sec:boxes}}{\htmlref{later}{sec:boxes}}.

\xminisec{Example:}
Three columns (\underline{l}eft, \underline{c}entred, \underline{c}entred):
\begin{codeS}
\glsni{begin}\marg{tabular}\marg{lcc}
\end{codeS} 

\xminisec{Another Example:}
Four columns (\underline{l}eft, \underline{c}entred, \underline{c}entred, \underline{r}ight):
\begin{codeS}
\glsni{begin}\marg{tabular}\marg{lccr}
\end{codeS} 

The \texttt{r}, \texttt{l} and \texttt{c} specifiers don't allow
line breaks or paragraphs within a cell. It's not a good idea to
have too much text in a cell, but if it's required you can use
\begin{definition}
p\marg{\meta{width}}
\end{definition}
which indicates a paragraph cell of the given width.

\xminisec{Example:}
Three columns (\underline{p}aragraph of width 1in,
\underline{c}entred, \underline{r}ight):
\begin{codeS}
\glsni{begin}\marg{tabular}\marg{p\marg{1in}cr}
\end{codeS}
The paragraph cell will be formatted fully justified, which is often
inappropriate for a narrow block of text. The \isty{array} package
provides
\begin{definition}
\gls{gtcol}\marg{\meta{declaration}}
\end{definition}
which can be used directly in front of the \texttt{l}, \texttt{c},
\texttt{r} or \texttt{p} column specifiers. This inserts
\meta{declaration} in front of the entries for that column, so it
can be used to insert, say, \gls{raggedright}.

\xminisec{Example:}
Three columns, the first \underline{l}eft justified where each entry
is in bold, the second a \underline{p}aragraph column of width 1in set to
ragged right and the third \underline{c}entered:
\begin{codeS}
\glsni{begin}\marg{tabular}\marg{\glsni{gtcol}\marg{\glsni{bfseries}}l\glsni{gtcol}\marg{\glsni{raggedright}}p\marg{1in}c}
\end{codeS}

The \isty{array} package also provides
\begin{definition}
\gls{ltcol}\marg{\meta{declaration}}
\end{definition}
which can be used directly after the \texttt{l}, \texttt{c},
\texttt{r} or \texttt{p} column specifiers. This inserts
\meta{declaration} after the entries for that column.

\xminisec{Inter-Column Gap:}

The gap between columns is given by twice the value of the
\gls{length} register:
\begin{definition}
\gls{tabcolsep}
\end{definition}
A gap of \glsni{tabcolsep} is
also inserted before the first column and after the last column.
This length can be changed using one of the commands described in
\sectionref{sec:length}. For example:
\begin{codeS}
\gls{setlength}\marg{\glsni{tabcolsep}}\marg{4pt}
\end{codeS}
This will put an 8pt gap between columns and a 4pt gap before the
first column and after the last column.

The column specifiers can also include:
\begin{definition}
\gls{atchar}\marg{\meta{inter-column text}}
\end{definition}
This inserts \meta{inter-column text} at that place on each row of
the table, replacing the default inter-column gap.

\xminisec{Example:}

Suppose we want a centred first column, a right justified second
column and a left justified third column with a dot between the
second and third columns:
\begin{codeS}
\begin{alltt}
\glsni{begin}\marg{tabular}\marg{cr\glsni{atchar}\marg{.}l}
\end{alltt}
\end{codeS}
Alternatively, you may want a larger gap between groups of columns,
for example, two groups of three left justified columns:
\begin{codeS}
\begin{alltt}
\glsni{begin}\marg{tabular}\marg{lll\glsni{atchar}\marg{\glsni{hspace}\marg{4\glsni{tabcolsep}}}lll}
\end{alltt}
\end{codeS}
This uses the command:
\begin{definition}
\gls{hspace}\marg{\meta{length}}
\end{definition}
which inserts a horizontal space of a given \gls{length}. In this
case, four times the value of \glsni{tabcolsep}. This makes the gap
between the third and fourth columns twice as wide as the gap
between the other columns.

\setnode{rowscols}
\subsection{Column and Row Separation}
\label{sec:rowscols}

Remember the \latexhtml{special characters mentioned in
\sectionref{sec:chars}}{\htmlref{special characters}{sec:chars}}?
The ampersand character \gls{ampchar} is used to separate column
entries. Rows are separated using:
\begin{definition}
\gls{tab.dbbackslashchar}\oarg{\meta{vertical space}}
\end{definition}
where \meta{vertical space} is extra vertical spacing between rows,
if required. There is also a longer equivalent:
\begin{definition}
\gls{tabularnewline}
\end{definition}
\faq{Alignment tab changed to \cmdname{cr}}{altabcr}%
If you have used something like
\texttt{\gls{gtcol}\marg{\gls{raggedright}}p\marg{\meta{length}}}
as the specifier for your last column, you must use
\glsni{tabularnewline} instead of \glsni{tab.dbbackslashchar}
to indicate the row break otherwise you will get the following
error:
\begin{verbatim}
! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate
\end{verbatim}
\screenpagebreak

\xminisec{Example:} 

Let's have two columns, the first left justified and the second right justified:
\begin{code}
\glsni{begin}\marg{tabular}\marg{lr}\newline
Video \glsni{ampchar}
8.99\glsni{tab.dbbackslashchar}\newline
CD \glsni{ampchar} 9.11\glsni{tab.dbbackslashchar}\newline
DVD \glsni{ampchar}
15.00\glsni{tab.dbbackslashchar}\newline
Total \glsni{ampchar} 33.10\newline
\glsni{end}\marg{tabular}
\end{code}

\begin{result}[tabular1.html]
\begin{tabular}{lr}
Video & 8.99\\
CD & 9.11\\
DVD & 15.00\\
Total & 33.10
\end{tabular}
\end{result}%
Recall from \chapterref{ch:def} that \LaTeX\ ignores spaces at the start of a line and
treats multiple spaces as a single space, so I~could just have
easily done:
\begin{code}
\glsni{begin}\marg{tabular}\marg{lr}\newline
\strut~~Video \glsni{ampchar} 8.99\glsni{tab.dbbackslashchar}\newline
\strut~~CD~~~~\glsni{ampchar} 9.11\glsni{tab.dbbackslashchar}\newline
\strut~~DVD~~~\glsni{ampchar} 15.00\glsni{tab.dbbackslashchar}\newline
\strut~~Total \glsni{ampchar} 33.10\newline
\glsni{end}\marg{tabular}
\end{code}%
and still have got the same result, but now the code is easier to
read.

Entries form implicit \glsing{group}, so
\glspl{declaration} made
within a \gls{env-tabular} environment only have an effect up to the
next \gls{ampchar} or \gls{tab.dbbackslashchar}.  

\xminisec{Example:}
\begin{code}
\glsni{begin}\marg{tabular}\marg{lr}\newline
\strut~~Video~\glsni{ampchar} 8.99\glsni{tab.dbbackslashchar}\newline
\strut~~CD~~~~\glsni{ampchar} 9.11\glsni{tab.dbbackslashchar}\newline
\strut~~DVD~~~\glsni{ampchar}
15.00\glsni{tab.dbbackslashchar}\newline
\strut~~\glsni{bfseries} Total \glsni{ampchar} 33.10\newline
\glsni{end}\marg{tabular}
\end{code}%
Output:\screenpagebreak
\begin{result}[Image: as the previous example except that the word
Total has appeared in bold]
\begin{tabular}{lr}
Video & 8.99\\
CD & 9.11\\
DVD & 15.00\\
\bfseries Total & 33.10
\end{tabular}
\end{result}%
Let's add an extra column and a header row:
\begin{code}\obeyspaces
\glsni{begin}\marg{tabular}\marg{lrr}\newline
\strut~~Item~~\glsni{ampchar} ex VAT \glsni{ampchar} inc
VAT\glsni{tab.dbbackslashchar}\newline
\strut~~Video~\glsni{ampchar}~~~8.99 \glsni{ampchar}~~10.56 \glsni{tab.dbbackslashchar}\newline
\strut~~CD~~~~\glsni{ampchar}~~~9.11 \glsni{ampchar}~~10.70 \glsni{tab.dbbackslashchar}\newline
\strut~~DVD~~~\glsni{ampchar}~~15.00 \glsni{ampchar}~~17.63 \glsni{tab.dbbackslashchar}\newline
\strut~~\glsni{bfseries} Total \glsni{ampchar}~~33.10 \glsni{ampchar}~~39.89\newline
\glsni{end}\marg{tabular}
\end{code}%
Output:
\begin{result}[tabular2.html]
\begin{tabular}{lrr}
Item  & ex VAT & inc VAT\\ 
Video & 8.99 & 10.56\\
CD & 9.11 & 10.70\\
DVD & 15.00 & 17.63\\
\bfseries Total & 33.10 & 39.89
\end{tabular}
\end{result}%

\xminisec{Example (Aligning on a Decimal Point):}

\label{xmp:decpt}If you want to align on the decimal point, it's best to use the
\isty{siunitx} package. That's beyond the scope of this
book, but for simple data this can be achieved
using the \gls{atchar} inter-column specifier. For example:
\begin{code}\obeyspaces
\glsni{begin}\marg{tabular}\marg{lr\glsni{atchar}\marg{.}l}\newline
\strut~~Video \glsni{ampchar} 8 \glsni{ampchar} 99\glsni{tab.dbbackslashchar}\newline
\strut~~CD~~~~\glsni{ampchar} 9 \glsni{ampchar} 11\glsni{tab.dbbackslashchar}\newline
\strut~~DVD~~~\glsni{ampchar} 15 \glsni{ampchar} 00\glsni{tab.dbbackslashchar}\newline
\strut~~\glsni{bfseries} Total \glsni{ampchar} 33 \glsni{ampchar} 10\newline
\glsni{end}\marg{tabular}
\end{code}%
Output:\reportpagebreak
\begin{result}[Image: as the second example but the decimal points
are aligned]
\begin{tabular}{lr@{.}l}
Video & 8 & 99\\
CD & 9 & 11\\
DVD & 15 & 00\\
\bfseries Total & 33 & 10
\end{tabular}
\end{result}%

\setnode{multicolumn}
\subsection{Spanning Columns}
\label{sec:multicolumn}

You may have noticed I~omitted the column headers in the \htmlref{above
example}{xmp:decpt}. \faq{Merging cells in
a column of a table}{multirow}
The problem with rewriting the table using 
\texttt{r\glsni{atchar}\marg{.}l} to align the decimal point is that the header
now needs to span the last two columns.
This can be done using the command:
\begin{definition}
\gls{multicolumn}\marg{\meta{cols spanned}}\marg{\meta{col specifier}}\marg{\meta{text}}
\end{definition}%
The first \gls{mandatory} \meta{cols spanned} is the number of
columns you want to span, the second argument \meta{col specifier}
indicates how to align this column-spanning entry, the third
argument \meta{text} indicates what should go in this entry. Note
that \meta{col specifier} should only have a single column
specifier, such as \texttt{\marg{c}} or \texttt{\marg{r}}.  We can
use \glsni{multicolumn} to modify an earlier example as
follows:\screenpagebreak
\begin{code}
\glsni{begin}\marg{tabular}\marg{lrr}\newline
\strut~~~~~~~~\glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{Price (\glsni{pounds})}\glsni{tab.dbbackslashchar}\newline
\strut~~Item~~\glsni{ampchar} ex VAT \glsni{ampchar} inc
VAT\glsni{tab.dbbackslashchar}\newline
\strut~~Video~\glsni{ampchar}~~~8.99 \glsni{ampchar}~~10.56 \glsni{tab.dbbackslashchar}\newline
\strut~~CD~~~~\glsni{ampchar}~~~9.11 \glsni{ampchar}~~10.70 \glsni{tab.dbbackslashchar}\newline
\strut~~DVD~~~\glsni{ampchar}~~15.00 \glsni{ampchar}~~17.63 \glsni{tab.dbbackslashchar}\newline
\strut~~\glsni{bfseries} Total \glsni{ampchar}~~33.10 \glsni{ampchar}~~39.89\newline
\glsni{end}\marg{tabular}
\end{code}%
Output:
\begin{result}[tabular2multicol.html]
\begin{tabular}{lrr}
 & \multicolumn{2}{c}{Price (\pounds)}\\
Item  & ex VAT & inc VAT\\ 
Video & 8.99 & 10.56\\
CD & 9.99 & 11.74\\
DVD & 15.00 & 17.63\\
\bfseries Total & 33.98 & 39.93
\end{tabular}
\end{result}%
Here we are spanning two columns, so the first argument to \glsni{multicolumn} is \verb|{2}|,
we want the entry centred, so the second argument is \verb|{c}| and the text to go in this entry 
is simply \texttt{\marg{Price (\gls{pounds})}}.

\faq{How to alter the alignment
of tabular cells}{tabcellalign}The \glsni{multicolumn} command can also be used to override
the alignment of individual entries.  Consider
the following example:
\begin{code}
\glsni{begin}\marg{tabular}\marg{lrr}\newline
\strut~~~~~~~~~~\glsni{ampchar} Year1   \glsni{ampchar} Year2
\glsni{tab.dbbackslashchar}\newline
Travel~~~~\glsni{ampchar} 100,000 \glsni{ampchar}
110,000\glsni{tab.dbbackslashchar}\newline
Equipment \glsni{ampchar} 50,000  \glsni{ampchar} 60,000\newline
\glsni{end}\marg{tabular}
\end{code}
Output:
\begin{result}[tabular3.html]
\begin{tabular}{lrr}
 & Year1 & Year2 \\
Travel & 100,000 & 110,000\\
Equipment & 50,000 & 60,000
\end{tabular}
\end{result}%
In this example, the headers \dq{Year1} and \dq{Year2} would look
better centred, but the rest of the entries in the second
and third columns look best right aligned.  We can
use \glsni{multicolumn} to span just one column, and
use the second argument of \glsni{multicolumn} to override
the column specification:
\begin{code}
\glsni{begin}\marg{tabular}\marg{lrr}\newline
\strut~~~~~~~~~~\glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1}\newline
\strut~~~~~~~~~~\glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar}\newline
Travel~~~~\glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar}\newline
Equipment \glsni{ampchar} 50,000  \glsni{ampchar} 60,000\newline
\glsni{end}\marg{tabular}
\end{code}
Output:
\begin{result}[Image: as the previous example except that the words
'Year1' and 'Year2' have been centred in their columns]
\begin{tabular}{lrr}
 & \multicolumn{1}{c}{Year1} & \multicolumn{1}{c}{Year2} \\
Travel & 100,000 & 110,000\\
Equipment & 50,000 & 60,000
\end{tabular}
\end{result}

\setnode{tabrules}
\subsection{Rules}
\label{sec:rules}

In general, vertical rules are considered superfluous~\cite{oxford}.
Although Turabian~\cite{turabian96} allows for the possibility of
vertical rules for tabulated material containing more than two
columns but still advises against having too many and deprecates
the use of them at either end.

Horizontal rules may be used at the top and bottom of the
tabulated material, but other horizontal rules should be kept to a
minimum. In general, the top and bottom rule should be thicker than
the mid rules.

The \isty{booktabs} package provides:
\begin{definition}
\gls{toprule}\oarg{\meta{wd}}
\end{definition}
for the top horizontal rule,
\begin{definition}
\gls{bottomrule}\oarg{\meta{wd}}
\end{definition}
for the bottom horizontal rule, and
\begin{definition}
\gls{midrule}\oarg{\meta{wd}}
\end{definition}
for horizontal rules in between rows, such as after the header row.

These commands should all go at the start of the appropriate row.
This means that if you want a bottom rule, you need to add
\gls{tab.dbbackslashchar} followed by \glsni{bottomrule} at the end of
the tabulated material.

\xminisec{Example:}
\begin{code}
\glsni{begin}\marg{tabular}\marg{lrr}\newline
\glsni{toprule}\newline
\strut~~~~~~~~~~\glsni{ampchar}
\glsni{multicolumn}\marg{1}\marg{c}\marg{Year1}\newline
\strut~~~~~~~~~~\glsni{ampchar}
\glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}%
\glsni{tab.dbbackslashchar}\newline
\glsni{midrule}\newline
Travel~~~~\glsni{ampchar} 100,000 \glsni{ampchar}
110,000\glsni{tab.dbbackslashchar}\newline
Equipment \glsni{ampchar} 50,000  \glsni{ampchar} 60,000%
\glsni{tab.dbbackslashchar}\newline
\glsni{bottomrule}\newline
\glsni{end}\marg{tabular}
\end{code}
results in:
\begin{result}[Image: as previous example but with horizontal rules
at the start and end and between the first and second rows.]
\begin{tabular}{lrr}
\toprule
          & \multicolumn{1}{c}{Year1} 
          & \multicolumn{1}{c}{Year2} \\
\midrule
Travel    & 100,000 & 110,000\\
Equipment & 50,000  & 60,000
\\\bottomrule
\end{tabular}
\end{result}

The thickness of the top and bottom rule is given by
the \gls{length} register \booklinebreak\gls{heavyrulewidth}, and the thickness of
the mid rule is given by the \gls{length} register
\gls{lightrulewidth}. These rule thicknesses can be overridden using the
optional argument \meta{wd} for \glsni{toprule}, \glsni{midrule}
and \glsni{bottomrule}.

\begin{exercise}{Aligning Material}{ex:tabular}
Go back to the document you created in \exerciseref{ex:simple} (and later modified in \exerciseref{ex:datetime}),
and add the following: 
\begin{result}[tabex.html]
\begin{tabular}{lrr}
 & \multicolumn{2}{c}{\bfseries Expenditure (\pounds)}\\
 & \multicolumn{1}{c}{Year1} & \multicolumn{1}{c}{Year2} \\
\bfseries Travel & 100,000 & 110,000\\
\bfseries Equipment & 50,000 & 60,000
\end{tabular}
\end{result}

Note that the \gls{env-tabular} environment
doesn't create a caption, all it does is arrange its contents in
rows and columns. You can find out how to turn your
\gls{env-tabular} environment into a table 
in \sectionref{sec:tables}.

You can \downloadorview{tabular} the solution to this exercise. (Remember to check
\appendixref{ch:errors} if you encounter an error message.)
\end{exercise}

For more information about using the \gls{env-tabular} environment see \latexbook,
\latexguide\ or \latexcomp.  \emph{The \LaTeX\ Companion} also describes how
to span rows using the \isty{multirow}
\htmlref{package}{sec:packages}.  For information on how to create
coloured tables using the \isty{colortbl}
\htmlref{package}{sec:packages}, see \latexgraphic.

\xminisec{Related \gls{ukfaq} topics:}
\begin{itemize}
\item \faqlink{How to change a whole row of a table}{wholerow}
\item \faqlink{Merging cells in a column of a table}{multirow}
\item \faqlink{Fixed width tables}{fixwidtab}
\item \faqlink{Variable-width columns in tables}{varwidcol}
\item \faqlink{Spacing lines in tables}{struttab}
\end{itemize}

%%%%%%%%%%%%%%%% Boxes and Mini-Pages %%%%%%%%%%%%%%%%%%%

\setnode{boxes}
\section{Boxes and Mini-Pages}
\label{sec:boxes}

\gls{tex} views everything on a page as a form of box. Each box has an
associated width, height and depth, and the boxes are placed together
on the page with \keyword{glue}. This is reminiscent of the days
of manual typesetting, where each letter or symbol was on a wooden
block, and the wooden blocks were glued in place. The simplest form
of box is a single letter. Some letters, such as \dq{a} only have a
height and width, whereas other letters, such as \dq{y} have a
height, width and depth (see \figureref{fig:letterbox}).

\begin{figure}[htbp]
\figconts[alt=Image of the letters y and a illustrating their
height depth and width. The letter a has zero depth as it does not
extend below the baseline.]
  {pictures/letterbox}%
  {%
    \caption{\texorpdfstring{\protect\TeX}{TeX}\protect\space Views Each Letter as a Box}%
  }%
  {fig:letterbox}%
\end{figure}

For example, the phrase \dq{cabbages and peas} is made up of 15 boxes:
\begin{center}
\makeimg{c a b b a g e s a n d p e a s}{\setlength{\fboxsep}{0.5pt}%
\setlength{\fboxrule}{0.1pt}\LARGE
\fbox{c}\fbox{a}\fbox{b}\fbox{b}\fbox{a}%
\fbox{g}\fbox{e}\fbox{s}~\fbox{a}\fbox{n}\fbox{d}~\fbox{p}\fbox{e}%
\fbox{a}\fbox{s}}
\end{center}
whereas the word \dq{cauliflower} consists of 10 boxes:\footnote{The 
fl-ligature is a single character, and so is one box not
two.}
\begin{center}
\makeimg{c a u l i fl-ligature o u r}{\setlength{\fboxsep}{0.5pt}%
\setlength{\fboxrule}{0.1pt}\LARGE
\fbox{c}\fbox{a}\fbox{u}\fbox{l}\fbox{i}%
\fbox{fl}\fbox{o}\fbox{w}\fbox{e}\fbox{r}}
\end{center}

More complicated boxes are made up of smaller boxes. We have already
encountered one of these more complicated boxes: the 
\gls{env-tabular} environment, discussed in the 
\htmlref{previous section}{sec:tabular}. This type of box is called
a \keyword{horizontal box}, which means that it can go in a line
of text. For example:
\begin{code}\obeyspaces
Here is some text.\newline
\glsni{begin}\marg{tabular}\marg{cc}\newline
A \glsni{ampchar} B\glsni{tab.dbbackslashchar}\newline
C \glsni{ampchar} D\newline
\glsni{end}\marg{tabular}\newline
The rest of the line.
\end{code}
produces:
\begin{result}[Image illustrating the typeset output: the tabulated
material is centred vertically within the line of text.]
Here is some text.
\begin{tabular}{cc}
A & B\\
C & D
\end{tabular}
The rest of the line.
\end{result}
Recall from \htmlref{the previous section}{sec:tabular} that the 
\gls{env-tabular} environment had an optional argument
\meta{pos}. This governs the vertical alignment when the
\gls{env-tabular} environment occurs within a line of text.
This can be one of \texttt{c} (centred\dash the default, as illustrated
above), \texttt{t} (top) and \texttt{b} (bottom). For example,
\begin{code}\obeyspaces
Here is some text.\newline
\glsni{begin}\marg{tabular}\oarg{b}\marg{cc}\newline
A \glsni{ampchar} B\glsni{tab.dbbackslashchar}\newline
C \glsni{ampchar} D\newline
\glsni{end}\marg{tabular}\newline
The rest of the line.
\end{code}%
produces:
\begin{result}[Image illustrating the typeset output: the last row
of the tabulated material rests on the baseline of the text outside it.]
Here is some text.
\begin{tabular}[b]{cc}
A & B\\
C & D
\end{tabular}
The rest of the line.
\end{result}

Since a box can't be broken across a line of text, you can use
the box making command:
\begin{definition}
\gls{mbox}\marg{\meta{text}}
\end{definition}
to prevent \meta{text} from spanning a line break.

\xminisec{Example:}
Compare:
\begin{code}
\gls{raggedright}
Some text at the beginning of a paragraph. Some
text in the middle of the paragraph. Some more text.
\glsni{par}
\end{code}
\begin{result}[Image of typeset output: paragraph is left-justified]
\raggedright
Some text at the beginning of a paragraph. Some text in the
middle of the paragraph. Some more text.
\par
\end{result}
with:
\begin{code}
\gls{raggedright}
Some text at the beginning of a paragraph. \glsni{mbox}\marg{Some
text in the middle of the paragraph.} Some more text.
\glsni{par}
\end{code}
\begin{result}[Image of typeset output: line break occurs at the
start of the second sentence leaving a large white space at the end
of the first line.]
\raggedright
Some text at the beginning of a paragraph. \mbox{Some text in the
middle of the paragraph.} Some more text.
\par
\end{result}
(If \gls{raggedright} had not been used, the text in the \glsni{mbox}
would've spilt out over the edge of the page.)

Another type of box which can again be placed in a line of text,
is the \gls{env-minipage} environment.
\begin{definition}
\glsni{begin}\marg{minipage}\oarg{\meta{pos}}\oarg{\meta{height}}%
\marg{\meta{width}}
\end{definition}
As the name suggests, this environment creates a \dq{mini-page}
of the given width.

\xminisec{Example:}
\begin{code}
Some text.\newline
\glsni{begin}\marg{minipage}\marg{2in}\newline
This is a mini-page. The text inside
it is formatted as usual.\newline
\mbox{}\newline
Paragraph breaks can also be used, but 
there is no indentation by default\gls{footnote}\marg{and 
this is how a footnote appears}.\newline
\glsni{end}\marg{minipage}\newline
The rest of the line.
\end{code}%
which produces:\reportpagebreak
\begin{result}[Image: the contents of the minipage including
footnote have been typeset in a rectangular block within the outer
line of text.]
Some text.
\begin{minipage}{2in}
This is a mini-page. The text inside
it is formatted as usual.

Paragraph breaks can also be used, but 
there is no indentation by default\mpexfootnote{and 
this is how a footnote appears}.
\end{minipage}
The rest of the line.
\end{result}

You can optionally specify a height, and how
the mini-page is aligned with the rest of the text. As with
the \gls{env-tabular} environment, the alignment
option \meta{pos} can be one of \texttt{t} (top), \texttt{c} (centred)
or \texttt{b} (bottom). The default is \texttt{c}, which is why
the above example has the mini-page centred vertically. This
can be changed, for example:
\begin{code}
Some text.\newline
\glsni{begin}\marg{minipage}\oarg{t}\marg{2in}\newline
This is a mini-page. The text inside
it is formatted as usual.\newline
\mbox{}\newline
Paragraph breaks can also be used, but 
there is no indentation by default\gls{footnote}\marg{and 
this is how a footnote appears}.\newline
\glsni{end}\marg{minipage}\newline
The rest of the line.
\end{code}
which produces
\begin{result}[Image: as previous example but the first line of the
minipage is aligned with the outer text.]
\begin{makeimage}
Some text.
\begin{minipage}[t]{2in}
This is a mini-page. The text inside
it is formatted as usual.

Paragraph breaks can also be used, but 
there is no indentation by default\mpexfootnote{and this
is how a footnote appears}.
\end{minipage}
The rest of the line.
\end{makeimage}
\end{result}

Note that the width can be specified relative to the current
line width, using the \gls{length} register \gls{linewidth}. For example,
\begin{alltt}
\glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}
\end{alltt}
will start a mini-page that is half the width of the current
line.

There is also a corresponding command
\begin{definition}
\gls{parbox}\oarg{\meta{pos}}\oarg{\meta{height}}%
\marg{\meta{width}}\marg{\meta{text}}
\end{definition}%
which behaves in a similar way. So the above example can be 
rewritten using a \glsni{parbox}:
\begin{code}
Some text.\newline
\glsni{parbox}[t]\marg{2in}\marg{This is a parbox. 
The text inside
it is formatted as usual.\newline
\mbox{}\newline
Paragraph breaks can also be used, but 
there is no indentation by default.}\newline
The rest of the line.
\end{code}
which produces
\begin{result}[Image: as previous example but without a footnote]
Some text.
\parbox[t]{2in}{This is a parbox. 
The text inside
it is formatted as usual.

Paragraph breaks can also be used, but 
there is no indentation by default.}
The rest of the line.
\end{result}
You may have noticed that the \gls{footnote} command has
not been used in the above example.  The \glsni{parbox} command 
is more restricted than the
\gls{env-minipage} environment, so you can't use the 
\gls{footnote} command in it. There are also certain 
environments, such as the 
\htmlref{list-making
environments}{sec:lists}\latex{\ifscreenorother{}{\ 
described in \sectionref{sec:lists}}}, that can be
used in a \gls{env-minipage} but not in a \glsni{parbox}.

\setnode{fbox}
\subsection{Framed Boxes}
\label{sec:fbox}

Recall the \gls{framebox} command described in \sectionref{sec:optional}:
\begin{definition}
\glsni{framebox}\oarg{\meta{width}}\oarg{\meta{align}}\marg{\meta{text}}
\end{definition}
This treats \meta{text} as a box of width \meta{width} and puts a frame around it.
The second optional argument may be one of: \texttt{c} (centred
contents), \texttt{l} (left-aligned contents), \texttt{r}
(right-aligned contents).

\xminisec{Example:}

\begin{codeS}
Some \glsni{framebox}\oarg{2in}\marg{framed} text.
\end{codeS}
\begin{resultS}[Some framed text (the word 'framed' is inside a 2
inch wide box)]
Some \framebox[2in]{framed} text.
\end{resultS}

There is a shorter related command with no optional arguments:
\begin{definition}
\gls{fbox}\marg{\meta{text}}
\end{definition}

The \isty{fancybox} package provides some additional framing
commands:
\begin{definition}
\gls{shadowbox}\marg{\meta{text}}
\end{definition}
Puts a shadow-style frame around its contents:\bookpagebreak
\begin{codeS}
Some \glsni{shadowbox}\marg{framed} text.
\end{codeS}
\begin{resultS}[Some framed text (the word 'framed' is in a 
box with a shadow)]
Some \shadowbox{framed} text.
\end{resultS}

\begin{definition}
\gls{doublebox}\marg{\meta{text}}
\end{definition}
Puts a double-lined frame around its contents:
\begin{codeS}
Some \glsni{doublebox}\marg{framed} text.
\end{codeS}
\begin{resultS}[Some framed text (the word 'framed' is in a 
box with a double lined frame)]
Some \doublebox{framed} text.
\end{resultS}

\begin{definition}
\gls{ovalbox}\marg{\meta{text}}
\end{definition}
Puts a thin-lined oval frame around its contents:
\begin{codeS}
Some \glsni{ovalbox}\marg{framed} text.
\end{codeS}
\begin{resultS}[Some framed text (the word 'framed' is in a 
a box with rounded corners)]
Some \ovalbox{framed} text.
\end{resultS}

\begin{definition}
\gls{Ovalbox}\marg{\meta{text}}
\end{definition}
Puts a thick-lined oval frame around its contents:

\begin{codeS}
Some \glsni{Ovalbox}\marg{framed} text.
\end{codeS}
\begin{resultS}[Some framed text (the word 'framed' is in a 
a thick bordered box with rounded corners)]
Some \Ovalbox{framed} text.
\end{resultS}

If you want a different frame effect, you will need to use a
graphical package, such as \isty{pgf}/\isty{tikz}.

\xminisec{Example:}

This example uses commands beyond the scope of this book,
but gives you an idea of what's possible.

\begin{code}
\begin{verbatim}
\documentclass{scrartcl}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

Some
\begin{tikzpicture}[baseline=(n.base),decoration=bumps]
\node[draw,ellipse,decorate] (n) {framed};
\end{tikzpicture}
text.

\end{document}
\end{verbatim}
\end{code}
\begin{resultS}[Some framed text (the word 'framed' is in a 
decorated with a wiggly border)]
Some
\begin{tikzpicture}[baseline=(n.base),decoration=bumps]
\node[draw,ellipse,decorate] (n) {framed};
\end{tikzpicture}
text.
\end{resultS}

For further details, see the \isty{pgf} \htmlref{documentation}{sec:texdoc}. 

\xminisec{Related \gls{ukfaq} topics:}
\begin{itemize}
\item \faqlink{Automatic sizing of minipage}{varwidth}
\item \faqlink{Float(s) lost}{fllost}
\item \faqlink{Perhaps a missing \cmdname{item}?}{errmissitem}
\end{itemize}

%%%%%%%%%%%%%%%%% CHAPTERS, SECTIONS ETC %%%%%%%%%%%%%%%%%%%%%%%

\setnode{structure}
\chapter{Structuring Your Document}
\label{ch:sections}

Let's go back to the document we modified in \exerciseref{ex:tabular}.
In this \latexhtml{chapter}{section} we shall edit that document
step by step until we have a fully-fledged document with title,
abstract, table of contents, sections etc.

%%%%%%%%%%%%%%%%%% Maketitle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{title}
\section{Author and Title Information}
\label{sec:title}

The term \keyword{title page} is used to indicate the author, title and
date information that can appear either on the front cover by itself
or along the top of the first page of text.  In order to do this, you
must first specify the information.  Once this information has been
specified it can then be displayed.

The author, title and date are entered using the 
\glspl{command}:
\begin{definition}
\gls{author}\marg{\meta{author names}}
\\%\end{definition}
%\begin{definition}
\gls{title}\marg{\meta{title text}}
\\%\end{definition}
%\begin{definition}
\gls{date}\marg{\meta{document date}}
\end{definition}%
The \koma\ classes also define:
\begin{definition}
\gls{titlehead}\marg{\meta{Title heading}}\\
\gls{subject}\marg{\meta{Subject}}\\
\gls{subtitle}\marg{\meta{Subtitle}}\\
\gls{publishers}\marg{\meta{Publisher}}
\end{definition}

\faq{The style of document titles}{titlsty}All these title-related
commands only \emph{store} information, they don't actually display
anything. These commands can be put in the \gls{preamble}. With most
classes, you will typically need to use at least \glsni{author} and
\glsni{title}.

Once you have used these commands, you can then
display the information using the command:\refstepcounter{object}\label{obj:maketitle}
\begin{definition}
\gls{maketitle}
\end{definition}
This command should be placed where you want the title page to
appear, which is normally at the start of the \gls{env-document}
environment.

Note that if you don't use the \glsni{date} command, the current 
date will be inserted.  If you want no date to appear, you need to 
specify an empty argument:
\begin{codeS}
\glsni{date}\marg{}
\end{codeS}
\bookpagebreak
Multiple authors should be separated by the command \gls{and}.
For example:
\begin{code}
\begin{alltt}
\glsni{author}\marg{A. Jones\glsni{tab.dbbackslashchar}University of Somewhere \glsni{and}
B. Smith\glsni{tab.dbbackslashchar}University of Somewhere Else}
\end{alltt}
\end{code}%
Within these titling fields, you can also use the command:
\begin{definition}
\gls{thanks}\marg{text}
\end{definition}%
which produces a special type of footnote. For example:
\begin{codeS}
\glsni{title}\marg{A Great Project\glsni{thanks}\marg{funded by XYZ}}
\end{codeS}%
Note that the footnote marker produced using \glsni{thanks}
is considered to have zero width, so if it occurs in the middle
of a line, rather than the end, you will need to insert some
extra space using \gls{spacesym} (backslash space).
The argument of \glsni{thanks} is a \glslink{fragile}{moving 
argument}\index{argument!moving|hyperpage}.

\begin{exercise}{Creating Title Pages}{ex:title}

Try editing the document you modified in \exerciseref{ex:tabular} to
include title information.  Modifications are illustrated in bold
\modification{like this}:

\begin{bcode}
\begin{alltt}
\glsni{documentclass}\oarg{12pt}\marg{scrartcl}

\glsni{usepackage}\marg{datetime}

\modification{\glsni{title}\marg{A Simple Document}}
\modification{\glsni{author}\marg{Me}}

\glsni{begin}\marg{document}

\modification{\glsni{maketitle}}

This is a simple \glsni{LaTeX}\glsni{spacesym}document.
Here is the first paragraph.

Here is the second paragraph\glsni{footnote}\marg{with a footnote}.
As you can see it's a rather short paragraph, but not
as short as the previous one. This document was
created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}.

\glsni{begin}\marg{tabular}\marg{lrr}
 \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar}
 \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar}
\glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar}
\glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000
\glsni{end}\marg{tabular}

\glsni{end}\marg{document}
\end{alltt}
\end{bcode}

You can \download{title} this document.
\end{exercise}

%%%%%%%%%%%%%%%%%%%%%%%%% Abstract %%%%%%%%%%%%%%%%%%%%%%%%

\setnode{abstr}
\section{Abstract}
\label{sec:abstract}

The \gls{env-abstract} \glsterm{environment} is used to
create an \Index{abstract} for the document\faq{1-column abstract in
2-column document}{onecolabs}.  The way in which the
abstract is formatted depends on the class file\indexCLS.  The
\icls{scrreprt} class file will put the abstract on a page by itself,
some class files will indent the abstract and some will typeset the
abstract in italic.  Note also that some class files (such as
\icls{scrbook}) don't have an \glsni{env-abstract}
environment.  Abstracts traditionally go at the start of the document
after the title, so the \glsni{env-abstract} environment should go
after the \gls{maketitle} command.

\begin{exercise}{Creating an Abstract}{ex:abstr}

Try editing your document so that it has an abstract:
Modifications are illustrated \modification{like this}:

\begin{bcode}
\begin{alltt}
\glsni{documentclass}\oarg{12pt}\marg{scrartcl}

\glsni{usepackage}\marg{datetime}

\glsni{title}\marg{A Simple Document}
\glsni{author}\marg{Me}

\glsni{begin}\marg{document}

\glsni{maketitle}

\modification{\glsni{begin}\marg{abstract}}
\modification{A brief document to illustrate how to use \glsni{LaTeX}.}
\modification{\glsni{end}\marg{abstract}}

This is a simple \glsni{LaTeX}\glsni{spacesym}document.
Here is the first paragraph.

Here is the second paragraph\glsni{footnote}\marg{with a footnote}.
As you can see it's a rather short paragraph, but not
as short as the previous one. This document was
created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}.

\glsni{begin}\marg{tabular}\marg{lrr}
 \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar}
 \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar}
\glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar}
\glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000
\glsni{end}\marg{tabular}


\glsni{end}\marg{document}
\end{alltt}
\end{bcode}

You can \download{abstr} this document.
\end{exercise}

%%%%%%%%%%%%%%%%% Sections, Subsections etc %%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{sectionunits}
\section{Chapters, Sections, Subsections \ldots}
\label{sec:section}

Chapters, sections, subsections etc can be inserted using the
commands:
\begin{definition}
\gls{part}\oarg{\meta{short title}}\marg{\meta{title}}\\
\gls{chapter}\oarg{\meta{short title}}\marg{\meta{title}}\\
\gls{section}\oarg{\meta{short title}}\marg{\meta{title}}\\
\gls{subsection}\oarg{\meta{short title}}\marg{\meta{title}}\\
\gls{subsubsection}\oarg{\meta{short title}}\marg{\meta{title}}\\
\gls{paragraph}\oarg{\meta{short title}}\marg{\meta{title}}\\
\gls{subparagraph}\oarg{\meta{short title}}\marg{\meta{title}}
\end{definition}%
All these commands have a \latexhtml{moving argument (see
\sectionref{sec:fragile})}{\glslink{fragile}{moving
argument}\index{argument!moving|hyperpage}}, so fragile commands will need to
be protected using \gls{protect}. \faq{How to create a
\cmdname{subsubsub\-section}}{subsubsub}The final two commands in the
above list, \glsni{paragraph} and \glsni{subparagraph}, represent
subsubsubsections and subsubsubsubsections, although most
\glspl{cls} typeset their arguments as unnumbered running titles.

Note that the availability of these commands depends on the
\gls{cls} you are using. For example, the \icls{scrartcl} class
file that we have been using is designed for articles, so the
\glsni{chapter} command is not defined in that class, whereas it is
defined in the \icls{scrreprt} and \icls{scrbook} class files.

Each of the commands above has a \gls{mandatory} \meta{title} and an
\gls{optional} \meta{short title}. The mandatory argument
\meta{title} is simply the title of the chapter\slash section\slash subsection
etc. For
example:
\begin{codeS}
\glsni{section}\marg{Introduction}
\end{codeS}%
If you are using the \icls{scrartcl} class file, the output will look 
like:
\begin{resultS}[Image: The text '1 Introduction' is typeset in a
large bold font]
\textbf{\sffamily\Large 1\quad Introduction}
\end{resultS}%
Note that you don't specify the section number as \LaTeX\ does this
automatically.  This means that you can insert a new section or
chapter or swap sections around or even change a section to a
subsection etc, without having to worry about updating all the
section numbers\faq{The style of section headings}{secthead}.

\renewcommand{\fmtord}[1]{\textsuperscript{#1}}%
If you are using a class file\indexCLS\ that contains chapters as
well as sections, the section number will depend on the chapter.  So,
for example, the current section is the \ordinal{section}\ section
of chapter~\arabic{chapter}, so the section number is \thesection.
\faq{Why are my sections numbered 0.1 ...?}{zerochap}(Note that if
you are using a class file where the section number depends on the
chapter number, you must have a \gls{chapter} command before your
first \gls{section} command, otherwise your section numbers will
come out as 0.1, 0.2 etc.)

Unnumbered chapters/sections etc are produced by placing an 
asterisk \texttt{*} after the command name.  For example:
\begin{codeS}
\glsni{chapter}*\marg{Acknowledgements}
\end{codeS}

You can switch to appendices using the 
command
\begin{definition}
\gls{appendix}
\end{definition}%
then continue using \gls{chapter}, \gls{section} 
etc\faq{Appendixes}{appendix}.  For example (using the \icls{scrreprt} class file):
\begin{code}
\begin{alltt}
\glsni{appendix}
\glsni{chapter}\marg{Derivations}
Some derivations.

\glsni{chapter}\marg{Tables}
Some tables.
\end{alltt}
\end{code}

\xminisec{Note:}
The \koma\ classes have another type of sectioning command:
\begin{definition}
\gls{minisec}\marg{\meta{heading}}
\end{definition}\screenpagebreak
This provides an unnumbered heading not associated with any of the
structuring levels. For example, the above was produce using:
\begin{code}
\begin{alltt}
\glsni{minisec}\marg{Note:}
The \koma\ classes have another type of sectioning command:
\end{alltt}
\end{code}
The next note below was produced using:
\begin{code}
\begin{alltt}
\glsni{minisec}\marg{Important Note:}
If you want to change the font style used by headings, 
\glsni{emph}\marg{\glsni{bfseries} do not} use font declarations in the sectioning
command arguments.
\end{alltt}
\end{code}

\xminisec{Important Note:}
If you want to change the font style used by headings, 
\emph{\bfseries do not} use font declarations in the sectioning command
arguments. Don't do, for example:
\begin{alltt}\wrong
\glsni{chapter}\marg{\glsni{itshape} Introduction}
\end{alltt}
The \koma\ classes provide the command:
\begin{definition}
\gls{addtokomafont}\marg{\meta{element}}\marg{\meta{commands}}
\end{definition}
where \meta{element} is the name of a structuring element (no
backslash) and \meta{commands} is the list of font changing
declarations (see \tableref{tab:fontsII}) to apply to that element style.
For example, \latexhtml{this book}{the PDF version of this document}
uses the commands:
\begin{code}
\begin{alltt}
\glsni{addtokomafont}\marg{section}\marg{\glsni{rmfamily}\glsni{bfseries}}
\glsni{addtokomafont}\marg{minisec}\marg{\glsni{rmfamily}\glsni{bfseries}\glsni{scshape}}
\end{alltt}
\end{code}

\begin{exercise}{Creating Chapters, Sections etc}{ex:section}

Let's try editing our document so that it now has chapters, sections
and an appendix.  Since the \icls{scrartcl} class file doesn't have
chapters, let's change to the \icls{scrreprt} class.  Changes from our
previous document are shown \modification{like this}.

\begin{bcode}%
\begin{alltt}
\glsni{documentclass}\oarg{12pt}\marg{\modification{scrreprt}}

\glsni{usepackage}\marg{datetime}

\glsni{title}\marg{A Simple Document}
\glsni{author}\marg{Me}

\glsni{begin}\marg{document}
\glsni{maketitle}

\glsni{begin}\marg{abstract}
A brief document to illustrate how to use \glsni{LaTeX}.
\glsni{end}\marg{abstract}

\modification{\glsni{chapter}\marg{Introduction}}

\modification{\glsni{section}\marg{The First Section}}
This is a simple \glsni{LaTeX}\glsni{spacesym}document.
Here is the first paragraph.

\modification{\glsni{section}\marg{The Next Section}}
Here is the second paragraph\glsni{footnote}\marg{with a footnote}. 
As you can see it's a rather short paragraph, but not 
as short as the previous one. This document was 
created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}.

\modification{\glsni{chapter}\marg{Another Chapter}}

\modification{Here\textquoteright{}s another very interesting chapter.}
\modification{We\textquoteright{}re going to put a picture here later.}

\modification{\glsni{chapter}*\marg{Acknowledgements}}

\modification{I would like to acknowledge all those}
\modification{very helpful people who have assisted me in my work.}

\modification{\glsni{appendix}}

\modification{\glsni{chapter}\marg{Tables}}
\modification{We will turn this tabular environment into a table later.}

\glsni{begin}\marg{tabular}\marg{lrr}
 \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar}
 \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar}
\glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar}
\glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000
\glsni{end}\marg{tabular}

\glsni{end}\marg{document}
\end{alltt}
\end{bcode}

(You can \download{section} a copy of this file if you like, but
I~recommend that you try editing the file yourself to give you
practice.)
\end{exercise}

%%%%%%%%%%%%%%%%%%% Table of Contents %%%%%%%%%%%%%%%%%%%%%%%%

\setnode{toc}
\section{Creating a Table of Contents}
\label{sec:toc}

Once you have all your \htmlref{sectioning commands}{sec:section},
such as \gls{chapter} and \gls{section},
you can create a table of contents with the command
\begin{definition}
\gls{tableofcontents}
\end{definition}%
This command should go where you want your table of
contents to appear (usually after \gls{maketitle}).\faq{The format of the
Table of Contents, etc}{tocloft} The \koma\ classes provide two
options that govern the format of the table of contents:
\scrclsopt[graduated]{toc} and \scrclsopt[flat]{toc}. The first is the
default and indents the different sectioning levels. The second
doesn't use any indentation.

\xminisec{Example:}

\begin{codeS}
\glsni{documentclass}\oarg{12pt,toc=flat}\marg{scrreprt}
\end{codeS}

You may recall from \htmlref{the previous section}{sec:section} that
the sectioning commands all had an optional argument \meta{short
title}.  If your chapter or section title is particularly long\faq{My
section title is too wide for the page header}{runheadtoobig}, you
can use \meta{short title} to specify a shorter title that should go
in the table of contents.\footnote{\label{ftn:header}and in the page header, depending
on the page style.}  The longer title (given by the other
argument \meta{title}) will still appear in the section heading in
the main part of the document.

\LaTeX\ processes all source code sequentially, so when it first
encounters the \glsni{tableofcontents} command, it doesn't yet
know anything about the chapters, sections etc.  So the first time
the \htmlref{document is \LaTeX{}ed}{ch:tex2pdf} the necessary
information is written to the table of contents 
(\texttt{.toc})\indexTOC\ file (see \sectionref{sec:auxiliary}).  The subsequent pass reads the
information in from the \texttt{.toc}\indexTOC\ file, and generates
the table of contents.  You will therefore need to \LaTeX\ your
document twice to make sure that the table of contents is
up-to-date\faq{Numbers too large in table of contents,
etc}{tocloftwrong}.

\xminisec{Adding Extra Information}

The \htmlref{starred versions}{itm:starredcommand} of the sectional 
commands (such as \glsnl{chapter}\texttt{*})
don't get added to the table of contents. It may be that you want to
add it, in which case you need to use
\begin{definition}
\gls{addcontentsline}\marg{\meta{toc}}\marg{\meta{section
unit}}\marg{\meta{text}}
\end{definition}
after the heading. The first argument \meta{toc} is the file
extension without the dot. As mentioned above, the table of contents
file has the extension \texttt{.toc}, so the first argument should
be \texttt{toc} (\htmlref{later}{ch:floats}\latex{ in \chapterref{ch:floats}}, 
we'll be adding a list of figures and a list of tables, and those
have file extensions \texttt{.lof}\indexLOF\ and \texttt{.lot}\indexLOT, respectively).
The second argument \meta{section unit} is the name of the section
unit. This is just the name of the relevant sectioning command
\emph{without} the backslash. The final argument \meta{text} is the
entry text. For example (using \icls{scrreprt} class):
\begin{code}
\gls{chapter}*\marg{Acknowledgments}\newline
\glsni{addcontentsline}\marg{toc}\marg{chapter}\marg{Acknowledgements}
\end{code}

\begin{exercise}{Creating a Table of Contents}{ex:toc}

Try modifying your document so that it has a table of contents.
Modifications from the previous exercise are illustrated 
\modification{like this}:
\begin{bcode}
\begin{alltt}
\glsni{documentclass}\oarg{12pt}\marg{scrreprt}

\glsni{usepackage}\marg{datetime}

\glsni{title}\marg{A Simple Document}
\glsni{author}\marg{Me}

\glsni{begin}\marg{document}

\glsni{maketitle}

\modification{\glsni{tableofcontents}}

\glsni{begin}\marg{abstract}
A brief document to illustrate how to use \glsni{LaTeX}.
\glsni{end}\marg{abstract}

\glsni{chapter}\marg{Introduction}

\glsni{section}\marg{The First Section}

This is a simple \glsni{LaTeX}\glsni{spacesym}document.  Here is the first paragraph.

\glsni{section}\marg{The Next Section}

Here is the second paragraph\glsni{footnote}\marg{with a footnote}. 
As you can see it's a rather short paragraph, but not 
as short as the previous one. This document was 
created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}.

\glsni{chapter}\marg{Another Chapter}

Here's another very interesting chapter.
We're going to put a picture here later.

\glsni{chapter}*\marg{Acknowledgements}

I would like to acknowledge all those
very helpful people who have assisted
me in my work.

\glsni{appendix}
\glsni{chapter}\marg{Tables}

We will turn this tabular environment into a table later.

\glsni{begin}\marg{tabular}\marg{lrr}
 \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar}
 \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar}
\glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar}
\glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000
\glsni{end}\marg{tabular}


\glsni{end}\marg{document}
\end{alltt}
\end{bcode}

If your table of contents doesn't come out right, try \LaTeX{}ing it
again.  (Again, you can \download{toc} this file.)

You might want to try experimenting with the
\scrclsopt[flat]{toc} class options to
see what difference it makes:
\begin{codeS}
\glsni{documentclass}\oarg{12pt,toc=flat}\marg{scrreprt}
\end{codeS}

\end{exercise}

%%%%%%%%%%%%%%%%% Cross-Referencing %%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{crossref}
\section{Cross-Referencing}
\label{sec:crossref}

We have already seen that \LaTeX\ takes care of all the numbering for
the chapters etc, but what happens if you want to refer to a chapter
or section?  There's no point leaving \LaTeX\ to automatically
generate the section numbers if you have to keep track of them all,
and change all your cross-references every time you add a new
section.  Fortunately \LaTeX\ provides a way to generate the correct
number. All you have to do is label the part of the document you want
to reference, and then refer to this label when you want to
cross-reference it\faq{Referring to labels in other
documents}{extref}.  \LaTeX\ will then determine the correct number
that needs to be inserted at that point.

The first part, labelling the place you want to reference, is done 
using the command:
\begin{definition}
\gls{label}\marg{\meta{string}}
\end{definition}\refstepcounter{object}\label{obj:label}%
The \gls{argument} \meta{string} should be a
unique textual label.  This label can be anything you like as long as
it is unique, but it's a good idea to make it something obvious
so that, firstly, you can remember the label when you want to 
use it, and secondly, when you read through your code at some later
date, it's immediately apparent to you to which part of the
document you are referring.  People tend to have their own conventions
for labelling.  I usually start the label with two or three letters
that signify what type of thing I'm labelling.  For example, if I'm
labelling a chapter I'll start with \texttt{ch}, if I'm labelling a
section I'll start with \texttt{sec}. 

\xminisec{Examples:}

\begin{enumerate}
\item Labelling a chapter:

\begin{code}
\begin{alltt}
\glsni{chapter}\marg{Introduction}
\glsni{label}\marg{ch:intro}
\end{alltt}
\end{code}

\item Labelling a section:

\begin{code}
\begin{alltt}
\glsni{section}\marg{Technical Details}
\glsni{label}\marg{sec:details}
\end{alltt}
\end{code}
\end{enumerate}

Note that the \glsni{label} command doesn't produce any text, it
simply assigns a label.  You can now refer to that object
using the command:
\begin{definition}
\gls{ref}\marg{\meta{string}}
\end{definition}
which will produce the relevant number.

\xminisec{Example:}
\begin{codeS}
See Section \glsni{ref}\marg{sec:results} for an analysis
of the results.
\end{codeS}
\refstepcounter{object}\label{cmd:tilde}%
It is a typographical convention that you should never
start a new line with a number.  For example,
if you have the text \dq{Chapter~1} the \dq{1} must
be on the same line as the \dq{Chapter}.  We can 
do this by using an \keyword{unbreakable space}, which will
put a space but won't allow \LaTeX\ to break the line at
that point.  This is done using the tilde (\gls{tildechar}) 
\htmlref{special character}{sec:chars},
so the example above should actually be:\bookpagebreak
\begin{codeS}
See Section\glsni{tildechar}\glsni{ref}\marg{sec:results} for an analysis
of the results.
\end{codeS}
There is a similar command to reference the page number:
\begin{definition}
\gls{pageref}\marg{\meta{string}}
\end{definition}

\xminisec{Example:}
\begin{code}
See Chapter\glsni{tildechar}\glsni{ref}\marg{ch:def} on
page\glsni{tildechar}\glsni{pageref}\marg{ch:def} for a list of definitions.
\end{code}
The label \texttt{ch:def} obviously needs to
be defined somewhere:
\begin{code}
\begin{alltt}
\glsni{chapter}\marg{Definitions}
\glsni{label}\marg{ch:def}
\end{alltt}
\end{code}
In fact, I~have done this in my source code for \chapterref[the
definitions section]{ch:def} of this document, so the above example
would look like:
\begin{resultS}[See Chapter 2 on page 8 for a list of definitions]
See Chapter~\ref*{ch:def} on
page~\pageref*{ch:def} for a list of definitions.
\end{resultS}

\faq{Referring to things by their name}{nameref}%
It's not just chapters and sections that you can reference, most of
the numbers that \LaTeX\ automatically generates can be
cross-referenced. 

\xminisec{Example:} 
The source code for footnote~\ref{ftn:header} \latexhtml{on
page~\pageref{ftn:header}}{in \sectionref{sec:toc}} is:
\begin{code}
\glsni{footnote}\marg{\glsni{label}\marg{ftn:header}and in the page header, depending
on the page style}
\end{code}
\latexhtml{and it was referenced above using:}{and can be referenced
using:}
\begin{code}
The source code for footnote\glsni{tildechar}\glsni{ref}\marg{ftn:header} on
page\glsni{tildechar}\glsni{pageref}\marg{ftn:header} is:
\end{code}

The \isty{varioref} package provides a more convenient way of doing this using the
command:
\begin{definition}
\gls{vref}\marg{\meta{label}}
\end{definition}
This is like \gls{ref} but also adds information about the location, 
such as \dq{on page~\meta{n}} or \dq{on the following page}, if the
corresponding \gls{label} occurs on a different page, so the above
example can be changed to:
\begin{codeS}
The source code for footnote\glsni{tildechar}\glsni{vref}\marg{ftn:header} is:
\end{codeS}
\begin{latexonly}
\ifscreenorother
{%
which produces
\begin{resultS}
The source code for footnote~\vref{ftn:header} is:
\end{resultS}
}%
{%
\bookpagebreak\noindent which still produces
\begin{resultS}
The source code for footnote~\vref{ftn:header} is:
\end{resultS}
Compare with a reference to one of the labels in the next example:
\begin{codeS}
See step\glsni{tildechar}\cmdname{vref}\marg{itm:edit}.
\end{codeS}
which produces:
\begin{resultS}
See step~\vref{itm:edit}.
\end{resultS}
}%
\end{latexonly}
\begin{htmlonly}
which produces
\begin{resultS}[The source code for footnote 5.1 on page 110 is:]
The source code for footnote~\vref{ftn:header} is:
\end{resultS}
\end{htmlonly}

\xminisec{Caveat:}
You can run into trouble if the \glsni{vref} command occurs on a
page break. When it tries to insert the location information, such
as \dq{on the next page}, the information is no longer correct. This
can cause an \dq{Infinite loop} error. When this happens, either
edit your paragraph so the reference no longer falls on the page
break or use \gls{ref} instead of \glsni{vref} for that instance.

\xminisec{Another Example:}

The \gls{env-enumerate} environment \latex{\ifscreenorother{}{described 
in \sectionref{sec:enumerate} }}%
automatically numbers the items within an ordered list, so it's
possible to label list items. Recall the numbered list of
instructions at the start of
\chapterref{ch:tex2pdf}. Here's the code:

\begin{code}[0.9\linewidth]
\begin{alltt}
\glsni{begin}\marg{enumerate}

   \glsni{item}\glsni{label}\marg{itm:edit} Write or edit the source code.

   \glsni{item} Pass the source code to the \glsni{texttt}\marg{latex} or \glsni{texttt}\marg{pdflatex} 
        application (``\glsni{LaTeX}\glsni{spacesym}the document'').

      \glsni{begin}\marg{itemize}

         \glsni{item} If there are any error messages, 
               return to Step\glsni{tildechar}\glsni{ref}\marg{itm:edit}.

         \glsni{item} If there are no error messages, a PDF file
               is created, go to Step\glsni{tildechar}\glsni{ref}\marg{itm:view}.
      \glsni{end}\marg{itemize}

   \glsni{item}\glsni{label}\marg{itm:view} View the PDF file to check the result.

\glsni{end}\marg{enumerate}
\end{alltt}
\end{code}
Output:
\begin{result}[enumerateref.html]
\begin{enumerate}

   \item\label{itm:edit} Write or edit the source code.

   \item Pass the source code to the \texttt{latex} or \texttt{pdflatex} application 
        (\dq{\LaTeX\ the document}).

      \begin{itemize}

         \item If there are any error messages, 
               return to Step~\ref*{itm:edit}.

         \item If there are no error messages, a PDF file
               is created, go to Step~\ref*{itm:view}.
      \end{itemize}

   \item\label{itm:view} View the PDF file to check the result.

\end{enumerate}
\end{result}

The \gls{ref} and \gls{pageref} commands may come before or
after the corresponding \gls{label} command.  As with the table
of contents, \LaTeX\ first writes out all the cross-referencing
information to another file (the \iauxfile, see \sectionref{sec:auxiliary}) and then reads it in the
next time, so you will need to \LaTeX\ your document twice to get
everything up-to-date.

If the references aren't up-to-date, you will see the following
message at the end of the \LaTeX\ run:
\begin{verbatim}
LaTeX Warning: Label(s) may have changed. 
Rerun to get cross-references right.
\end{verbatim}
The following warning
\begin{verbatim}
LaTeX Warning: There were undefined references.
\end{verbatim}
means that \LaTeX\ found a reference to a label that
does not appear in the auxiliary file\indexAUX.  This could
mean that it's a new label, and the warning
will go away the next time you \LaTeX\ your document,
or it could mean that either you've forgotten to
define your label with the \gls{label} command,
or you've simply misspelt the label. The undefined references
will show up as two question marks \doublequestionmark\ in the \gls{output}.

\faq{\dq{Rerun} messages won't go away}{rerun}Very occasionally, if you have cross-references
and a table of contents, you might have to \LaTeX\ 
your document three times to get everything up to
date.  Just check to see if the \texttt{Label(s) may have changed}
warning appears.

If you find it inconvenient having to remember to click the typeset
button twice, you can use \iappname{latexmk}. This will run \LaTeX\
the required number of times to ensure the document is up-to-date.
To do this in TeXWorks, change the drop-down menu to \dq{LaTeXmk}, as
illustrated in \figureref{fig:latexmk}. Note that \appname{latexmk}
is a \gls{perl} script, so you need to make sure you have
\iappname{perl} installed (see \sectionref{sec:perl}).

\begin{figure}[htbp]
\figconts
 {pictures/texworks-latexmk}
 {%
   \caption{Selecting LaTeXmk in TeXWorks}
 }%
 {fig:latexmk}
\end{figure}

If \appname{latexmk} isn't listed in the drop-down menu, you can add
it via \menu{Edit}\menuto\menu{Preferences}. This opens the dialog
box shown in \figureref{fig:texworks-pref}. You can add a new tool
as follows:

\begin{enumerate}
\item To the right of the box
labelled \dq{Processing Tools} there is a button marked with a plus
(+) sign. Click on it to open the tool configuration dialog, shown
in \figureref{fig:texworks-toolconfig}.

\item Fill in the name \dq{LaTeXmk} in the box labelled \dq{Name} and either type
in the location of \appname{latexmk} in the box labelled \dq{Program} 
or use the \dq{Browse} button to locate it on your filing system.
(See \figureref{fig:texworks-toolconfig2}.) This will vary depending
on your operating system and \gls{tex}-distribution, but it will
probably be in a subdirectory (folder) called \texttt{bin} somewhere
in the \gls*{tex}-distribution tree.

\item There are lots of options that can be passed to
\appname{latexmk}, but if you want to produce PDF output you need to
add \texttt{-pdf} as an argument. This is done by clicking on the
button marked with a plus to the right of the \dq{Arguments} box and
type \texttt{-pdf}, as shown in \figureref{fig:texworks-toolconfig3}.

\item Another argument needs to be added that specifies the
basename of the \LaTeX\ file. This is done by again clicking on the
plus button and typing \verb|$basename|, as shown in
\figureref{fig:texworks-toolconfig4} .

\item Click on \dq{OK} to close the Tool Configuration dialog.

\item If you want to set \appname{latexmk} to be your default
processing tool, you can select it from the drop-down list labelled
\dq{Default}.

\item Click \dq{OK} when you're done.
\end{enumerate}

\begin{figure}[htbp]
\figconts
 {pictures/texworks-preferences}
 {%
    \caption{TeXWorks Preferences}
 }
 {fig:texworks-pref} 
\end{figure}

\begin{figure}[htbp]
\figconts
 {pictures/texworks-toolconfig1}
 {%
    \caption{Tool Configuration Dialog}
 }
 {fig:texworks-toolconfig} 
\end{figure}

\begin{figure}[htbp]
\figconts
 {pictures/texworks-toolconfig2}
 {%
    \caption{Tool Configuration Dialog: set the name and program
location}
 }
 {fig:texworks-toolconfig2} 
\end{figure}

\begin{figure}[htbp]
\figconts
 {pictures/texworks-toolconfig3}
 {%
    \caption{Tool Configuration Dialog: adding \protect\texttt{-pdf} argument}
 }
 {fig:texworks-toolconfig3} 
\end{figure}

\begin{figure}[htbp]
\figconts
 {pictures/texworks-toolconfig4}
 {%
    \caption{Tool Configuration Dialog: adding \protect\texttt{\$basename} argument}
 }
 {fig:texworks-toolconfig4} 
\end{figure}

\begin{exercise}{Cross-Referencing}{ex:crossref}

Try modifying your code so that it has cross-references.
Again, changes made from the previous exercise are
illustrated \modification{like this}:
\begin{bcode}
\begin{alltt}
\glsni{documentclass}\oarg{12pt}\marg{scrreprt}

\glsni{usepackage}\marg{datetime}

\glsni{title}\marg{A Simple Document}
\glsni{author}\marg{Me}

\glsni{begin}\marg{document}

\glsni{maketitle}

\glsni{tableofcontents}

\glsni{begin}\marg{abstract}
A brief document to illustrate how to use \glsni{LaTeX}.
\glsni{end}\marg{abstract}

\glsni{chapter}\marg{Introduction}
\modification{\glsni{label}\marg{ch:intro}}

\glsni{section}\marg{The First Section}

This is a simple \glsni{LaTeX}\glsni{spacesym}document.  Here is the first paragraph.
\modification{The next chapter is Chapter\glsni{tildechar}\glsni{ref}\marg{ch:another}}
\modification{and is on page\glsni{tildechar}\glsni{pageref}\marg{ch:another}.}
\modification{The next section is Section\glsni{tildechar}\glsni{ref}\marg{sec:next}.}

\glsni{section}\marg{The Next Section}
\modification{\glsni{label}\marg{sec:next}}

Here is the second paragraph\glsni{footnote}\marg{with a footnote}. 
As you can see it's a rather short paragraph, but not 
as short as the previous one. This document was 
created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}.

\glsni{chapter}\marg{Another Chapter}
\modification{\glsni{label}\marg{ch:another}}

Here's another very interesting chapter.
We're going to put a picture here later.
\modification{See Chapter\glsni{tildechar}\glsni{ref}\marg{ch:intro} for an }
\modification{introduction.}

\glsni{chapter}*\marg{Acknowledgements}

I would like to acknowledge all those
very helpful people who have assisted
me in my work.

\glsni{appendix}
\glsni{chapter}\marg{Tables}

We will turn this tabular environment into a table later.

\glsni{begin}\marg{tabular}\marg{lrr}
 \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar}
 \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar}
\glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar}
\glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000
\glsni{end}\marg{tabular}

\glsni{end}\marg{document}
\end{alltt}
\end{bcode}
(You can \download{crossref} a copy of this file.)

\end{exercise}

%%%%%%%%%%%%%%%%%%%% Bibliography %%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{biblio}
\section{Creating a Bibliography}
\label{sec:bib}

If you have a large number of citations in your document, it's best
to use an external bibliographic application\faq{Creating a BibTeX
bibliography file}{buildbib}, such as \iappname{bibtex} or
\iappname{biber}. However, that is beyond the scope of this
book (see, instead, \latexguide, \latexcomp\
or \latexthesis). Therefore this section just gives a brief
explanation of the \gls{env-thebibliography} environment, which is
usually automatically generated using \appname{bibtex} or
\appname{biber}.

\begin{definition}
\glsni{begin}\marg{thebibliography}\marg{\meta{widest tag}}
\end{definition}
This environment is very similar to the list making environments described
in \sectionref{sec:lists}, but instead of \gls{item} use 
\begin{definition}
\gls{bibitem}\oarg{\meta{tag}}\marg{\meta{key}}
\end{definition}%
where \meta{key} is a unique keyword that identifies this
item.  Your keyword can be anything you like, but as with
\glsni{label} I~recommend that you use
a short memorable keyword. I~tend to use the first author's surname
followed by the year of publication. 

The bibliography heading depends on the class file you are using.
Most of the article-style classes, such as \icls{scrreprt}, use
\glsi{refname} (which produces \dq{\refname}) in an unnumbered
section, whereas the report and book-styles, such as \icls{scrreprt}
and \icls{scrbook}, use \glsi{bibname} (which produces
\dq{\bibname}) in an unnumbered chapter. See
\tableref{tab:textlab} for the list of the common textual label
commands.

Most class files don't automatically add the bibliography to the
table of contents. The \koma\ classes provide the
\scrclsopt{bibliography} option. This can be
\scrclsopt[totoc]{bibliography} (an unnumbered unit added to the
table of contents), for example,
\begin{codeS}
\glsni{documentclass}\oarg{bibliography=totoc}\marg{scrreprt}
\end{codeS}
or \scrclsopt[totocnumbered]{bibliography} (a
numbered unit added to the table of contents), for example,
\begin{codeS}
\glsni{documentclass}\oarg{bibliography=totocnumbered}\marg{scrreprt}
\end{codeS}
If you're not using
one of the \koma\ classes, consult the 
\htmlref{documentation}{sec:texdoc} for your class to see if
there is an equivalent option. Failing that, you can use
\gls{addcontentsline} (described in \sectionref{sec:toc}).
For example (using a class that defines chapters):
\begin{code}
\glsni{addcontentsline}\marg{toc}\marg{chapter}\marg{\glsni{bibname}}\\
\glsni{begin}\marg{bibliography}\marg{1}
\end{code}

\xminisec{Example:}
(This example uses the command \gls{LaTeXe} which produces the
\LaTeXe\ logo. This indicates the current version of \LaTeX\ rather
than the old 2.09 version.)\footnote{If a friend or colleague gives
you a file containing \cmdname{documentstyle} instead of \cmdname{documentclass}
they are nearly 20~years out of date.}
The class style in use is \cls{scrbook}, so the title is
given by \glsni{bibname} (\dq{Bibliography}).
\begin{code}
\glsni{begin}\marg{thebibliography}\marg{3}\newline
\glsni{bibitem}\marg{lamport94} \glsni{quotedblleft}\glsni{LaTeX}: a document preparation 
system\glsni{quotedblright}, Leslie Lamport, 2nd edition (updated for 
\glsni{LaTeXe}), Addison-Wesley (1994).\newline
\mbox{}\newline
\glsni{bibitem}\marg{kopka95} \glsni{quotedblleft}A Guide to \glsni{LaTeX}: document 
preparation for beginners and advanced users\glsni{quotedblright}, 
Helmut Kopka and Patrick W. Daly, Addison-Wesley (1995).\newline
\mbox{}\newline
\glsni{bibitem}\marg{goossens94} \glsni{quotedblleft}The 
\glsni{LaTeX}\glsni{spacesym}Companion\glsni{quotedblright}, 
Michel Goossens, Frank Mittelbach and
Alexander Samarin, Addison-Wesley, (1994).\newline
\mbox{}\newline
\glsni{end}\marg{thebibliography}
\end{code}
\begin{result}[references.html]
\dobibexamplenumbered
\end{result}

You can cite an item in your bibliography with the command
\begin{definition}
\gls{cite}\oarg{\meta{text}}\marg{\meta{key list}}
\end{definition}%

\bookpagebreak
\xminisec{Example:}
\begin{code}
\begin{alltt}
For more information about writing bibliographies see 
Goossens \glsni{emph}\marg{et al.}\glsni{tildechar}\glsni{cite}\marg{goossens94}.
\end{alltt}
\end{code}%
Output:
\begin{resultS}[cite.html]
For more information about writing
bibliographies see 
Goossens \emph{et al.}~[3].
\end{resultS}
If you want to cite multiple works, use 
a comma-separated list:
\begin{code}
\begin{alltt}
For more information about writing bibliographies 
see\glsni{tildechar}\glsni{cite}\marg{kopka95,goossens94}.
\end{alltt}
\end{code}%
Output:
\begin{resultS}[mcite.html]
For more information about writing bibliographies 
see~[2,3].
\end{resultS}
The \gls{optional} \meta{text} to
the \glsni{cite} command can be used to add text to the
citation.  

\xminisec{Example:}
\begin{code}
\begin{alltt}
For more information about writing bibliographies see 
Goossens \glsni{emph}\marg{et al.}\glsni{tildechar}\glsni{cite}\oarg{Chapter~13}\marg{goossens94}.
\end{alltt}
\end{code}%
Output:
\begin{result}[chcite.html]
For more information about writing bibliographies see 
Goossens \emph{et al.}~[3, Chapter~13].
\end{result}

The \gls{env-thebibliography} environment has
a \gls{mandatory}:
\begin{definition}
\glsni{begin}\marg{thebibliography}\marg{\meta{widest tag}}
\end{definition}%
The argument \meta{widest tag} is the widest tag in the list of
entries.  This helps \LaTeX\ to align the references correctly.  In
the example above, the tags appeared as: [1], [2] and [3], and [3]
is the widest so that was used as the argument. These tags can be
changed from the default numbers to something else using
the optional argument to the \gls{bibitem} command. 

\xminisec{Example (Textual Tags):}

This example uses the \gls{optional} of \gls{bibitem} to use textual
rather than numerical tags.  The widest tag is [Goossens 1994]
so that is chosen to be the argument of the \gls{env-thebibliography}
environment:
\begin{code}
\glsni{begin}\marg{thebibliography}\marg{Goossens 1994}\newline
\mbox{}\newline
\glsni{bibitem}[Lamport 1994]\marg{lamport94} 
\glsni{quotedblleft}\glsni{LaTeX}\cmdname{ } : a document 
preparation system\glsni{quotedblright}, Leslie Lamport, 2nd edition 
(updated for \glsni{LaTeXe}), Addison-Wesley (1994).\newline
\mbox{}\newline
\glsni{bibitem}[Kopka 1995]\marg{kopka95} 
\glsni{quotedblleft}A Guide to \glsni{LaTeX}: document 
preparation for beginners and advanced users\glsni{quotedblright}, Helmut Kopka 
and Patrick W. Daly, Addison-Wesley (1995).\newline
\mbox{}\newline
\glsni{bibitem}[Goossens 1994]\marg{goossens94} 
\glsni{quotedblleft}The \glsni{LaTeX}\glsni{spacesym}Companion\glsni{quotedblright}, 
Michel Goossens, Frank Mittelbach and
Alexander Samarin, Addison-Wesley, (1994).\newline
\mbox{}\newline
\glsni{end}\marg{thebibliography}
\end{code}
\begin{result}[references2.html]
\dobibexamplelabelled
\end{result}

\begin{exercise}{Creating a Bibliography}{ex:biblio}

Try adding the following chapter to your document:
\begin{code}
\glsni{chapter}\marg{Recommended Reading}

For a basic introduction to \glsni{LaTeX}\glsni{spacesym}see
Lamport\glsni{tildechar}\glsni{cite}\marg{lamport94}. For
more detailed information about \glsni{LaTeX}\glsni{spacesym}and
associated applications, consult Kopka and
Daly\glsni{tildechar}\glsni{cite}\marg{kopka95} or Goossens
\glsni{emph}\marg{et
al}\glsni{tildechar}\glsni{cite}\marg{goossens94}.
\end{code}% 
and also add the bibliography shown above to the end of your
document. You can \downloadorview{biblio} the solution, but have a
go by yourself first. Remember that, as before, you will need to
\LaTeX\ the document twice to get the references up-to-date, unless
you're using \iappname{latexmk} (as described in
\sectionref{sec:crossref}) in which case it will be done
automatically.

\end{exercise}

%%%%%%%%%%%%%%%%%%%%%%%%% Page Styles %%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{pagestyle}
\section{Page Styles and Page Numbering}
\label{sec:pagestyle}

You may have noticed that the documents you have created
have all had their page numbers automatically inserted 
at the foot of most of the pages\faq{Page numbering 
\dq{\meta{n} of \meta{m}}}{nofm}.  If you have created the document
that has gradually been modified over the previous few
sections, you may have noticed that the title page has
no header or footer, the table of contents starts on page~1,
the abstract page has no page number, and the pages after
the abstract start on page~1 and continue incrementally
onwards from that point.  All the page numbers are Arabic
numerals.  This can be changed using the command:
\begin{definition}
\gls{pagenumbering}\marg{\meta{style}}
\end{definition}%
where \meta{style} can be one of:
\begin{fwlist}{\pagenumberingfmt{arabic}}
\fwitem{\ipagenumbering{arabic}} Arabic numerals (1, 2, 3, \ldots)
\fwitem{\ipagenumbering{roman}} Lower case Roman numerals (i, ii, iii, \ldots)
\fwitem{\ipagenumbering{Roman}} Upper case Roman numerals (I, II, III, \ldots)
\fwitem{\ipagenumbering{alph}} Lower case alphabetical characters (a, b, c, \ldots)
\fwitem{\ipagenumbering{Alph}} Upper case alphabetical characters (A, B, C, \ldots)
\end{fwlist}

Traditionally, the front matter (table of contents, list of figures
etc) should have lower case Roman numeral page numbering, while the
main matter should be in Arabic numerals\faq{Page numbering by
chapter}{pagebychap}.  

\xminisec{Example:}
\begin{code}
\begin{alltt}
\glsni{author}\marg{Me}
\glsni{title}\marg{A Simple Document}
\glsni{maketitle}

\glsni{pagenumbering}\marg{roman}
\glsni{tableofcontents}

\glsni{begin}\marg{abstract}
This is the abstract.
\glsni{end}\marg{abstract}

\glsni{pagenumbering}\marg{arabic}
\glsni{chapter}\marg{Introduction}
\end{alltt}
\end{code}

The \icls{scrbook} class provides:
\begin{definition}
\gls{frontmatter}
\end{definition}
which switches to lower case Roman numeral page numbering, and
\begin{definition}
\gls{mainmatter}
\end{definition}
which switches to Arabic numeral page numbering.
These two declarations also
change the way the sectioning units, such as \gls{chapter} and
\gls{section}, appear.  The former, \glsni{frontmatter},
suppresses the numbering (regardless of whether or not you've used
the \htmlref{starred version}{itm:starredcommand} of the sectioning commands). The latter,
\glsni{mainmatter}, switches the numbering back on (unless
otherwise suppressed by using the starred sectioning commands). 
In addition, \icls{scrbook} provides
\begin{definition}
\gls{backmatter}
\end{definition}
which doesn't affect the page numbering but, like \glsni{frontmatter}, suppresses the 
sectional unit numbering.

\xminisec{Note:}

The \gls{env-abstract} environment isn't defined by the \icls{scrbook} class, as 
a book summary is usually incorporated into an introductory section.

\xminisec{Example:}

\begin{code}
\begin{alltt}
\glsni{documentclass}\oarg{12pt}\marg{scrbook}

\glsni{title}\marg{A Simple Document}
\glsni{author}\marg{Me}

\glsni{begin}\marg{document}
\glsni{maketitle}

\glsni{frontmatter}
\glsni{tableofcontents}

\glsni{chapter}\marg{Summary}
A brief document to
illustrate how to use \glsni{LaTeX}.

\glsni{mainmatter}

\glsni{chapter}\marg{Introduction}
\glsni{label}\marg{ch:intro}

\glsni{end}\marg{document}
\end{alltt}
\end{code}

The headers and footers can be changed using the command
\begin{definition}
\gls{pagestyle}\marg{\meta{style}}
\end{definition}%
Individual pages can be changed using
\begin{definition}
\gls{thispagestyle}\marg{\meta{style}}
\end{definition}%
Standard styles are:
\begin{fwlist}{myheadings}
\fwitem{\ipagestyle{empty}} No header or footer. 
\fwitem{\ipagestyle{plain}} Header empty, page number in footer.
\fwitem{\ipagestyle{headings}}  Header contains page number and various information, 
 footer empty. 
\fwitem{\ipagestyle{myheadings}} Header specified by user, footer empty.
\end{fwlist}

If the \ipagestyle{myheadings} style is used, the header information
can be specified using:
\begin{definition}
\gls{markboth}\marg{\meta{left head}}\marg{\meta{right head}}
\end{definition}%
if the \clsopt{twoside} option has been passed to the
\gls{cls} (default for \icls{scrbook}), or
\begin{definition}
\gls{markright}\marg{\meta{right head}}
\end{definition}%
if the \clsopt{oneside} option has been passed to the \gls{cls}
(default for \icls{scrartcl} and \icls{scrreprt}).

The \icls{scrreprt} class file uses the \pagestylefmt{empty} style
for the \Index{title} and \Index{abstract} pages and
\pagestylefmt{plain} for the first page of each new chapter.  By
default the remaining pages are also \pagestylefmt{plain}, but
these can be changed using the \glsni{pagestyle} command.
The \icls{scrbook} class defaults to the \pagestylefmt{headings}
style instead of \pagestylefmt{plain}.

\faq{Alternative head- and footlines in LaTeX}{fancyhdr}%
The \koma\ bundle provides a way to define new page
styles, but that's beyond the scope of this introductory tutorial. 
See the \koma\ documentation for further details if you are
interested.

\casemedia
 {% A4
  This book mostly uses the \pagestylefmt{headings} page style and the
  \icls{scrbook} class with the 
  \clsopt{oneside} option, so there is no difference between odd and
  even page headers, whereas the paperback version uses the
  \clsopt{twoside} option, so the odd pages display the chapter
   number and title and the even pages display the current section
   header and title. The on-screen PDF version of this book uses a page style 
  I~defined myself that incorporates a navigation bar in the footer.
 }%
 {% screen
   This screen version of the book uses a page style I~defined myself
   that incorporates a navigation bar in the footer. 
   The \htmladdnormallink{A4 version}{\baseurl/latex/novices/novices-a4.pdf} mostly uses
   the \pagestylefmt{headings} page style. If you look at it, you
   will see that the chapter number and title appear on the top left and
   the page number appears in the top right of most pages.  The 
   \clsopt{oneside} option was used, so there is no difference between
   the formatting of odd and even numbered pages. Whereas the paperback
   version uses the \clsopt{twoside} option so the odd and even page
   headers are different.
 }
 {% book
  This book mostly\footnote{I made some modifications to the page style 
  for the footers in the summary and index.}\ uses the \pagestylefmt{headings} 
  page style and the \icls{scrbook} class with the 
  \clsopt{twoside} option, so the odd and even page headers are
  different, whereas the A4 PDF version (available from
  \url{\baseurl/}) uses the \clsopt{oneside} option, so the odd and
  even page headers are the same.
  The on-screen PDF version of this book uses a page style 
  I~defined myself that incorporates a navigation bar in the footer.
 }
 {% html
   The \htmladdnormallink{A4
   version}{\baseurl/latex/novices/novices-a4.pdf} of this book
   mostly uses the \pagestylefmt{headings} page style.  If you look at it, you
   will see that the chapter number and title appear on the top left and
   the page number appears in the top right of most pages.  The 
   \clsopt{oneside} option was used, so there is no difference between
   the formatting of odd and even numbered pages. Whereas the paperback
   version uses the \clsopt{twoside} option, so the odd pages display the chapter
   number and title and the even pages display the current section
   header and title.
   The \htmladdnormallink{on-screen PDF
   version}{\baseurl/latex/novices/novices-screen.pdf} of this book
   uses a page style I~defined myself that incorporates a navigation bar
   in the footer. 
 }

\begin{exercise}{Page Styles and Page Numbering}{ex:pagestyle}

Try modifying your code so that it uses the \icls{scrbook} class,
\gls{frontmatter} and \gls{mainmatter}. Replace the
\gls{env-abstract} environment with an unnumbered chapter, as shown
below. Again, changes made from the previous document are illustrated
\modification{like this}:\screenpagebreak
\begin{bcode}
\begin{alltt}
\glsni{documentclass}\oarg{12pt}\marg{\modification{scrbook}}

\glsni{usepackage}\marg{datetime}

\modification{\glsni{pagestyle}\marg{headings}}

\glsni{title}\marg{A Simple Document}
\glsni{author}\marg{Me}

\glsni{begin}\marg{document}

\glsni{maketitle}

\modification{\glsni{frontmatter}}
\glsni{tableofcontents}

\modification{\glsni{chapter}\marg{Summary}}
A brief document to
illustrate how to use \glsni{LaTeX}.

\modification{\glsni{mainmatter}}

\glsni{chapter}\marg{Introduction}
\glsni{label}\marg{ch:intro}

\glsni{section}\marg{The First Section}

This is a simple \glsni{LaTeX}\glsni{spacesym}document.
Here is the first paragraph.
The next chapter is Chapter\glsni{tildechar}\glsni{ref}\marg{ch:another}
and is on page\glsni{tildechar}\glsni{pageref}\marg{ch:another}.
The next section is Section\glsni{tildechar}\glsni{ref}\marg{sec:next}.

\glsni{percentchar} Rest of document unchanged but 
\glsni{percentchar} omitted for brevity.
\glsni{end}\marg{document}
\end{alltt}
\end{bcode}
(You can \downloadorview{pagestyle} the edited
document.)

\end{exercise}

%%%%%%%%%%%%%%%%%%%%%%% babel %%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{babel}
\section{Multi-Lingual Support: using the 
\texorpdfstring{\sty{babel}}{babel} package}
\label{sec:babel}

You may have noticed that the \gls{tableofcontents} and
\gls{chapter} commands have produced English words like
\dq{Contents} and \dq{Chapter}\faq{How to change LaTeX's \dq{fixed
names}}{fixnam}. If you are writing in another language, this is not
appropriate. In this case, you can use the \isty{babel} package,
and specify which language you will be using, either as an option to
the \isty{babel} package, or as an option to the class file\faq{Using
a new language with Babel}{newlang}.  If you are writing in more than
one language, list all the languages that you will be using where
the last named language is the default language\faq{Parallel
setting of text}{parallel}. For example:
\begin{alltt}
\glsni{usepackage}\oarg{english,french}\marg{babel}
\end{alltt}
or
\begin{alltt}
\glsni{documentclass}\oarg{english,french}\marg{scrreprt}
\glsni{usepackage}\marg{babel}
\end{alltt}
You can then switch between the named languages either using the 
\gls{declaration}:
\begin{definition}
\gls{selectlanguage}\marg{\meta{language}}
\end{definition}%
or the \gls{env-otherlanguage} \glsterm{environment}:
\begin{definition}
\glsni{begin}\marg{otherlanguage}\marg{\meta{language}}
\end{definition}%
These will affect all translations, including the date format
and predefined names like \dq{Chapter}. This also changes the
\gls{hyphenation} patterns.\latex{ (See \sectionref{sec:hyphenation}.)}

If you only want to set a short section of text in a different
language, without affecting the date format or predefined names,
then you can either use the command:
\begin{definition}
\gls{foreignlanguage}\marg{\meta{language}}\marg{\meta{text}}
\end{definition}%
or the starred version of the \glsni{env-otherlanguage} environment:
\begin{definition}
\glsni{begin}\marg{otherlanguage*}\marg{\meta{language}}
\end{definition}%
You can test to see if a given language is currently selected
using:
\begin{definition}
\gls{iflanguage}\marg{\meta{language}}\marg{\meta{true text}}%
\marg{\meta{false text}}
\end{definition}%

\xminisec{Example:}
\begin{code}
\begin{alltt}
\glsni{documentclass}\oarg{UKenglish,USenglish,french}\marg{scrartcl}
\glsni{percentchar} french is the last named option, so that's the current language

\glsni{usepackage}\oarg{T1}\marg{fontenc}
\glsni{usepackage}\oarg{utf8}\marg{inputenc}
\glsni{usepackage}\marg{babel}

\glsni{begin}\marg{document}
Ce texte est en fran\glsni{c}\marg{c}ais. La date aujourd'hui est: \glsni{today}.

\glsni{selectlanguage}\marg{USenglish}
This text is in US English. Today's date is: \glsni{today}.

\glsni{selectlanguage}\marg{UKenglish}
This text is in UK English. Today's date is: \glsni{today}.
\glsni{end}\marg{document}
\end{alltt}
\end{code}
Result:
\begin{result}[babel.html]
Ce texte est en fran\c{c}ais. La date aujourd'hui est~: 
{\datefrench\docdate}.

This text is in US English. Today's date is: {\usdate\docdate}.

This text is in UK English. Today's date is: {\ukenglishdate\docdate}.
\end{result}

\xminisec{Note:}
\warning If you are using the \istyopt{babel}{french} option, the
colon character (\Indextt{:}) is made active (that is, it's turned
into a special character) so if you are writing in French it's best
not to use a colon in labels (so where I've used, say,
\texttt{ch:def} you may need to change the colon to something else).

%%%%%%%%%%%%%%%%%%%%%%%% graphicx %%%%%%%%%%%%%%%%%%%

\setnode{graphicx}
\chapter{The \texorpdfstring{\sty{graphicx}}{graphicx} Package}
\label{ch:graphicx}

It is possible to generate images using \LaTeX\ commands\faq{Drawing
with TeX}{drawing} (See the \isty{pgf}\slash\isty{tikz} package or
\latexgraphic) however most people find it easier to create a
picture in some other application, and include that file into their
\LaTeX\ document.

PDF\LaTeX\ can insert PDF, PNG and JPG image files into your
document. If your image file is in a different format, you may be
able to find an application to convert it. \faq{Spawning programs
from (La)TeX: \cmdname{write}18}{spawnprog}Modern
\gls{tex}-distributions can automatically convert EPS\indexEPS\
files to PDF during the \LaTeX\ run using the \gls{perl} script
\iappname{epstopdf}. If your \gls{tex}-distribution doesn't support
this, you can convert your EPS file using \appname{epstopdf}
explicitly. For example, if you have an EPS image called, say,
\texttt{sample-image.eps}, you can convert it to a PDF image called
\texttt{sample-image.pdf}, by using the following command in a
\glslink{terminal}{terminal or command prompt}:
\begin{verbatim}
epstopdf sample-image.eps
\end{verbatim}
or (full path name may be required)
\begin{verbatim}
perl epstopdf sample-image.eps
\end{verbatim}

To insert an image file into your document, you first need to specify that 
you want to use the \isty{graphicx} package. So the following must 
go in the \gls{preamble}:
\begin{codeS}
\glsni{usepackage}\marg{graphicx}
\end{codeS}
The image can then be included in your document using the command
\begin{definition}
\gls{includegraphics}\oarg{\meta{key-val options}}\marg{\meta{filename}}
\end{definition}
where \meta{filename} is the name of your image file \emph{without the file
extension}\faq{\dq{Modern} graphics file names}{grffilenames}, and
\meta{key-val options} is a comma-separated list of options that can be
used to change the way the image is displayed. Note that if you have an 
image where the file name contain spaces or multiple dots, you need to
use the \isty{grffile} package:
\begin{codeS}
\glsni{usepackage}\marg{graphicx,grffile}
\end{codeS}

\xminisec{Example:} 

Suppose you had a file called \texttt{shapes.pdf}, then to
include it in your document you would do:
\begin{codeS}
\glsni{includegraphics}\marg{shapes}
\end{codeS}%
which would produce:
\begin{resultS*}
\incGraphics[alt=Image of some shapes]{pictures/shapes}
\end{resultS*}

You can specify a full or relative pathname, but you must use a
forward slash \gls{dir.slash} as the directory divider, even if you are using
Windows. For example:
\begin{codeS}
\glsni{includegraphics}\marg{pictures\glsni{dir.slash}shapes}
\end{codeS}
means the file \texttt{pictures/shapes.pdf} on Unix-type systems,
and it means the file \texttt{pictures\backslashsym shapes.pdf} on
Windows.\footnote{Or \texttt{shapes.png} or \texttt{shapes.jpg} or
\texttt{shapes.eps}. The example assumes a PDF image file.} This is
mainly because the backslash character is a \LaTeX\ special
character indicating a command, but it also helps portability
between platforms.

You can specify the order of the file types to look for with the command
\begin{definition}
\gls{DeclareGraphicsExtensions}\marg{\meta{ext-list}}
\end{definition}%
where \meta{ext-list} is a comma-separated list of extensions.  
For example, 
you might want to search first for PDF files, then for PNG files,
then for JPG files and finally for EPS files:
\begin{codeS}
\glsni{DeclareGraphicsExtensions}\marg{.pdf,.png,.jpg,.eps}
\end{codeS}%
The default for \iPDFLaTeX\ is:
\begin{flushleft}\ttfamily
.png\comma .pdf\comma .jpg\comma .mps\comma .jpeg\comma .jbig2\comma .jb2\comma .PNG\comma .PDF\comma .JPG\comma .JPEG\comma .JBIG2\comma .JB2\comma .eps
\end{flushleft}

The \gls{optional} \meta{key-val options}
should be a comma-separated list of
\meta{key}\texttt{=}\meta{value} pairs. Common options are:

\begin{fwlist}{\ikeyvalopt{includegraphics}{trim}=\meta{l} \meta{b} \meta{r} \meta{t}}
\fwitem{\ikeyvalopt{includegraphics}{angle}=\meta{\mathorit{x}}} rotate the image
by \degrees{x} anticlockwise.

\fwitem{\ikeyvalopt{includegraphics}{width}=\meta{length}} scale the image so that the
width is \meta{length}.  (Remember to specify the
\htmlref{units}{tab:units}.)

\fwitem{\ikeyvalopt{includegraphics}{height}=\meta{length}}  scale the image so that the
height is \meta{length}.  (Remember to specify the
\htmlref{units}{tab:units}.)

\fwitem{\ikeyvalopt{includegraphics}{scale}=\meta{value}} Scale the image by \meta{value}

\fwitem{\ikeyvalopt{includegraphics}{trim}=\meta{l} \meta{b} \meta{r} \meta{t}}  Specifies
the amount to remove from each side.  For example
\begin{codeS}
 \glsni{includegraphics}\oarg{trim=1 2 3 4}\marg{shapes}
\end{codeS}
crops the image by 1bp from the left, 2bp from the bottom, 3bp from
the right and 4bp from the top. (Recall the \iunit{bp}{big point} unit
from \tableref{tab:units}.)\reportpagebreak

\fwitem{\ikeyvalopt{includegraphics}{draft}}  Don't actually print the image, just draw a
box of the same size and print the filename inside it. 

\end{fwlist}

\xminisec{Example:}

This example first rotates the image by \degrees{45} anticlockwise,
then scales it so that the width is 1~inch.

\begin{codeS}
\glsni{includegraphics}\oarg{angle=45,width=1in}\marg{shapes}
\end{codeS}

\begin{resultS}[Image of shapes rotated then scaled]
\includegraphics[angle=45,width=1in]{pictures/shapes}
\end{resultS}

Note that this isn't the same as scaling and then rotating:
\begin{codeS}
\glsni{includegraphics}\oarg{width=1in,angle=45}\marg{shapes}
\end{codeS}

\begin{resultS}[Image of shapes scaled then rotated]
\includegraphics[width=1in,angle=45]{pictures/shapes}
\end{resultS}

You can also scale an image relative to the text area using the
\gls{length} registers \gls{textwidth} and \gls{textheight}. For
example, to scale a portrait image so that its height is
three-quarters of the text area height, you can do:
\begin{codeS}
\glsni{includegraphics}\oarg{height=0.75\glsni{textheight}}\marg{shapes}
\end{codeS}
or to scale a landscape image so that its width is half the text
area width, you can do:
\begin{codeS}
\glsni{includegraphics}\oarg{height=0.5\glsni{textwidth}}\marg{shapes}
\end{codeS}

\xminisec{Note:}

The \gls{includegraphics} command is another form of box (see
\sectionref{sec:boxes}), and can be used in the middle of a line of
text, just like the \gls{env-tabular} environment. See
\sectionref{sec:figures} to find out how to put the image in a
figure with a caption.

\xminisec{Example:}

\refstepcounter{object}\label{example:inlinegraphic}%
Recall the \iunit{ex}{relative unit} unit of measure from
\tableref{tab:units}. This can be used to scale
an image relative to the font size:
\begin{code}
An image can be inserted into a line
of text like this:
\glsni{includegraphics}\oarg{height=2ex}\marg{shapes}
\end{code}
\begin{resultS}[Image of typeset output: the included image has been
scaled so that it fits into the line of text]
An image can be inserted into a line
of text like this:
\includegraphics[height=2ex]{pictures/shapes}
\end{resultS}

\setnode{graphictrans}
\section{Graphical Transformations}
\label{sec:graphtrans}

The \isty{graphicx} package also provides commands to rotate, resize, 
reflect and scale text.  They are as follows:
\begin{definition}
\gls{rotatebox}\oarg{\meta{option list}}\marg{\meta{angle}}\marg{\meta{text}}
\end{definition}
Rotates \meta{text} by \meta{angle} (degrees anti-clockwise by
default). The optional argument \meta{option list} is a
comma-separated list of any of the following options:

\begin{itemize}
  \item \ikeyvalopt{rotatebox}{units}=\meta{number}

    The number of units in one full anti-clockwise rotation. So
    \texttt{units=-360} means that \meta{angle} specifies degrees
    clockwise whereas \texttt{units=6.283185} means that
    \meta{angle} is in radians.

  \item \ikeyvalopt{rotatebox}{origin}=\meta{label}

    The point of rotation.
    The value \meta{label} may contain one from either or both of
    the two lists: \texttt{lrc} (left, right, centre) and \texttt{tbB}
    (top, bottom, baseline). Alternatively the origin may be
    specified using the following two keys:

  \item \ikeyvalopt{rotatebox}{x}=\meta{dimen}

  \item \ikeyvalopt{rotatebox}{y}=\meta{dimen}
\end{itemize}

\xminisec{Example:}
\begin{code}
\begin{alltt}
base line
\glsni{rotatebox}\marg{45}\marg{Some text}
\glsni{rotatebox}\oarg{units=-360}\marg{45}\marg{Some text}
\glsni{rotatebox}\oarg{units=-360,origin=rB}\marg{45}\marg{Some text}
\glsni{rotatebox}\oarg{x=3em,y=3em}\marg{45}\marg{Some text}
base line
\end{alltt}
\end{code}\screenpagebreak
\begin{result}[Image of typeset output: each occurrence of 'Some text' has been rotated]
base line
\rotatebox{45}{Some text}
\rotatebox[units=-360]{45}{Some text}
\rotatebox[units=-360,origin=rB]{45}{Some text}
\rotatebox[x=3em,y=3em]{45}{Some text}
base line
\end{result}

\begin{definition}
\gls{scalebox}\marg{\meta{h scale}}\oarg{\meta{v scale}}\marg{\meta{text}}
\end{definition}
Scales \meta{text} by \meta{h scale} in both directions if \meta{v
scale} omitted, otherwise scales \meta{text} by \meta{h scale}
horizontally and \meta{y scale} vertically.

\xminisec{Example:}
\begin{codeS}
\glsni{scalebox}\marg{0.8}\marg{Some text}
\end{codeS}
\begin{resultS}[Some text (scaled by a factor of 0.8)]
\scalebox{0.8}{Some text}
\end{resultS}
Compare with:
\begin{codeS}
\glsni{scalebox}\marg{0.8}\oarg{1.2}\marg{Some text}
\end{codeS}
\begin{resultS}[Some text (aspect ratio changed)]
\scalebox{0.8}[1.2]{Some text}
\end{resultS}

\begin{definition}
\gls{reflectbox}\marg{\meta{text}}
\end{definition}
Reflects \meta{text} (equivalent to \glsni{scalebox}\marg{-1}\oarg{1}\marg{\meta{text}}).

\xminisec{Example:}
\begin{codeS}
\glsni{reflectbox}\marg{Some text}
\end{codeS}
\begin{resultS}[Some text (mirror image)]
\reflectbox{Some text}
\end{resultS}

\begin{definition}
\gls{resizebox}\marg{\meta{h length}}\marg{\meta{v length}}\marg{\meta{text}}
\end{definition}
Scales \meta{text} so that it is \meta{h length} wide and \meta{v
length} high. To preserve the aspect ratio, use \gls{resizebox.exclamchar}
instead of one of the dimensions.

\xminisec{Example:}
\begin{code}
\begin{alltt}
\glsni{resizebox}\marg{12mm}\marg{1cm}\marg{Some text}
\glsni{resizebox}\marg{\glsni{resizebox.exclamchar}}\marg{1cm}\marg{Some text}
\end{alltt}
\end{code}%
\begin{resultS}[Image of typeset output: two instances of 'Some text' scaled with and without changing the aspect ratio.]
\dohtmlcolorbox{%
\resizebox{12mm}{1cm}{Some text}
\resizebox{!}{1cm}{Some text}
}
\end{resultS}

\setnode{graphicxoptions}
\section{Package Options}

The \isty{graphicx} package can have the following options passed to 
it:
\begin{fwlist}{\optfmt{hiderotate}}
\fwitem{\mdseries \istyopt{graphicx}{draft}} Don't actually display the
images, just print the filename in a box of the correct size.  This
is useful if you want to print out a draft copy of a document to
check the text rather than the images.

\fwitem{\mdseries \istyopt{graphicx}{final}} Opposite of 
\istyopt{graphicx}{draft} (default).

\fwitem{\mdseries \istyopt{graphicx}{hiderotate}} Don't show rotated
text.

\fwitem{\mdseries \istyopt{graphicx}{hidescale}} Don't show scaled text.

\end{fwlist}

Remember that relevant options passed to the class file\indexCLS\ also 
affect packages.

\xminisec{Example (Draft Mode):}

Draft mode helps to speed up compilation of a large document when
you are editing the text. In the preamble:
\begin{codeS}
\glsni{usepackage}\oarg{draft}\marg{graphicx}
\end{codeS}
or
\begin{code}
\begin{alltt}
\glsni{documentclass}\oarg{draft}\marg{scrbook}

\glsni{usepackage}\marg{graphicx}
\end{alltt}
\end{code}
Later in the document:
\begin{codeS}
\glsni{includegraphics}\oarg{width=1in,angle=45}\marg{pictures/shapes}
\end{codeS}
\begin{resultS}[Only bounding box and file name drawn]
 \incGraphics{pictures/draftimage}
\end{resultS}

\begin{exercise}{Using the \sty{graphicx} Package}{ex:graphicx}

Download the image file
\htmladdnormallink{\texttt{shapes.pdf}}{\exerciseurl/shapes.pdf}%
\latex{ from \url{\exerciseurl/}} (or create your own image),
and include it into your document. (You
can \downloadorview{graphicx} an example solution.)
\end{exercise}

\bookpagebreak\screenpagebreak
For more information on the \isty{graphicx} package see
\latexgraphic\ or the \isty{graphicx} documentation.

\xminisec{Related \gls{ukfaq} topics:}
\begin{itemize}
\item \faqlink{How to import graphics into (La)TeX documents}{impgraph}
\item \faqlink{Imported graphics in PDFLaTeX}{pdftexgraphics}
\item \faqlink{Imported graphics in dvips}{dvipsgraphics}
\item \faqlink{Imported graphics in dvipdfm}{dvipdfmgraphics}
\item \faqlink{Importing graphics from \dq{somewhere else}}{graphicspath}
\item \faqlink{Portable imported graphics}{graph-pspdf}
\item \faqlink{Repeated graphics in a document}{repeatgrf}
\item \faqlink{Limit the width of imported graphics}{grmaxwidth}
\item \faqlink{Top-aligning imported graphics}{topgraph}
\item \faqlink{Labelling graphics}{labelfig}
\item \faqlink{Graphics division by zero}{divzero}
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%% FLOATS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{floats}
\chapter{Floats}
\label{ch:floats}

Figures and tables are referred to as \dq{floats} because they are
\emph{floated} to the nearest location. This prevents ugly large
spaces appearing on the page if there isn't enough room for the
figure or table before the page break. Floats have a caption and
associated number\faq{The style of captions}{captsty}. It is
customary for captions to appear at the bottom of figures but at the
top of tables~\cite{turabian96,oxford}.

For both figures and tables, the caption is generated using the 
command:
\begin{definition}
\gls{caption}\oarg{\meta{short caption}}\marg{\meta{text}}
\end{definition}%
Note that the \cmdname{caption} command has a
moving argument\index{argument!moving|hyperpage}, so
\glspl{fragile}\faq{Footnotes in captions}{ftncapt} will need to be
protected using \gls{protect}.  The \glsterm{optional}
\meta{short caption} is used to provide an alternative shorter
caption for the list of figures or list of tables, akin to the
optional argument to the \htmlref{sectioning
commands}{sec:section}\latex{\ifscreenorother{}{\ described in
\sectionref{sec:section}}}.

\xminisec{Note:}

Although the \glsni{caption} command can have an optional
short title, in general, captions should be brief. They should not
contain lots of description or background detail~\cite{turabian96}.
That type of information should be placed in the main text not the
caption.

\xminisec{Positioning:}

\refstepcounter{object}\label{obj:positioning}%
\faq{Wide figures in two-column documents}{widefigs}Both the 
\glsni{env-figure} and \glsni{env-table} environments have
an optional argument \meta{placement specifiers}, which indicates
permissible locations for the float. This may be a combination of
\texttt{h} (\dq{here}), \texttt{t} (top), \texttt{b} (bottom) and
\texttt{p} (page of floats.) Note that this only gives a general
guideline as to where the float will end up. The final location is
governed by other factors, such as space left on the page and the
proportion of text to floats on the page. If you omit one or more of the
placement specifiers, then you are prohibiting the float from being
placed in that location. A common mistake is to do
\begin{alltt}
\wrong\glsni{begin}\marg{figure}\oarg{h}
\end{alltt}
which says \dq{I~want the figure here and it can't go anywhere
else!} If the figure \emph{can't} be placed exactly here (for
example, there may not be enough room on the page), then you have
given it no alternative location, which can result in this and all
subsequent figures being dumped at the end of the chapter or
document, or can result in a fatal error when running
\LaTeX\faq{\dq{Too many unprocessed floats}}{tmupfl}. You may be
able to manage with only one of the other options, for example,
\begin{alltt}
\glsni{begin}\marg{figure}\oarg{t}
\end{alltt}
(In fact, modern \TeX\ distributions now replace \oarg{h} with
\oarg{t} if the float can't be placed.)
However, if you have a large number of floats it is advisable to
provide as many options as possible:
\begin{alltt}
\glsni{begin}\marg{figure}\oarg{htbp}
\end{alltt}
Similarly for tables.

If you are absolutely adamant that an image must go \dq{right here},
then it's not a float, and you shouldn't be using the 
\glsni{env-figure} environment. It's just a horizontal box, like the
example \xpageref{earlier}{example:inlinegraphic}. Similarly for
tabulated material.

It's worth bearing in mind what the Oxford Style Manual~\cite{oxford} has to say:
\begin{quote}
\dq{Text must not be read into it so as to give [the figure] an
explicit and fixed introduction, for example \sq{in the following
figure}: the final placement is determined by page breaks, which
cannot be anticipated before setting, and this makes rewording the
text necessary if the illustration does not fit the make-up of the
page.}
\end{quote}
Turabian~\cite{turabian96} gives the same advice (and reiterates it for 
figures):
\begin{quote}
\dq{All text references to a table should be by a number, not by an
introductory phrase such as \sq{in the following table}.}
\end{quote}

\setnode{figures}
\section{Figures}
\label{sec:figures}

Figures are created using the \gls{env-figure} environment.
\begin{definition}
\glsni{begin}\marg{figure}\oarg{\meta{placement specifiers}}
\end{definition}%
This environment may contain one or more captions (specified, as
described \htmlref{above}{ch:floats}, with
the \glsni{caption} command) but page breaks are not allowed in the
contents of a \glsni{env-figure} environment. The optional argument
\meta{placement specifiers} is as described
\htmlref{above}{obj:positioning}.

Recall from \chapterref{ch:graphicx} that we
can include an image in our document with
the command \gls{includegraphics} defined in the \isty{graphicx}
package.  We can put our
\htmladdnormallink{\texttt{shapes.pdf}}{\exerciseurl/shapes.pdf} image
into a figure as follows:
\begin{code}
\glsni{begin}\marg{figure}\oarg{htbp}\newline
\strut~~\glsni{includegraphics}\marg{shapes}\newline
\strut~~\glsni{caption}\marg{Some Shapes}\newline
\glsni{end}\marg{figure}
\end{code}%
So far so good, but our picture needs to be centred.  This can
be done using the \gls{centering} declaration mentioned in
\sectionref{sec:declaration}:
\begin{code}
\glsni{begin}\marg{figure}\oarg{htbp}\newline
\strut~~\glsni{centering}\newline
\strut~~\glsni{includegraphics}\marg{shapes}\newline
\strut~~\glsni{caption}\marg{Some Shapes}\newline
\glsni{end}\marg{figure}
\end{code}
The \gls{caption} command generates a number, just like
\gls{section}, so we can
\htmlref{cross-reference}{sec:crossref} it with \gls{ref} and
\gls{label}.  First, let's label the figure:
\begin{code}
\glsni{begin}\marg{figure}\oarg{htbp}\newline
\strut~~\glsni{centering}\newline
\strut~~\glsni{includegraphics}\marg{shapes}\newline
\strut~~\glsni{caption}\marg{Some Shapes}\newline
\strut~~\glsni{label}\marg{fig:shapes}\newline
\glsni{end}\marg{figure}
\end{code}%
Now we can reference it:
\begin{codeS}
Figure\glsni{tildechar}\glsni{ref}\marg{fig:shapes} shows some shapes.
\end{codeS}%
(As \htmlref{before}{cmd:tilde} we use \gls{tildechar}
to make an unbreakable space.)  This produces the following output
in the text:
\begin{resultS}[Figure 7.1 shows some shapes.]
Figure~\ref*{fig:shapes} shows some shapes.
\end{resultS}%
and produces \figureref{fig:shapes}.

\begin{figure}[hbtp]
\figconts
  {pictures/shapes}
  {%
    \caption{Some Shapes}%
  }%
  {fig:shapes}
\end{figure}

\xminisec{Important Note:}

If you want to change the caption font, \textbf{\em don't} do, e.g.:
\begin{alltt}
\wrong\glsni{caption}\marg{\gls{bfseries} Some Shapes}
\end{alltt}
Recall \gls{addtokomafont} from \sectionref{sec:section}. This can
also be used to change the fonts used by the caption.\bookpagebreak
\begin{alltt}
\correct\glsni{addtokomafont}\marg{caption}\marg{\glsni{bfseries}}
\end{alltt}
Similarly for the caption label. For example:
\begin{codeS}
\glsni{addtokomafont}\marg{captionlabel}\marg{\glsni{scshape}}
\end{codeS}

\xminisec{List of Figures}

Just as we were able to generate a \htmlref{table of
contents}{sec:toc} using \gls{tableofcontents}, we can also
generate a list of figures using the command
\begin{definition}
\gls{listoffigures}
\end{definition}
This creates a file with the extension \texttt{.lof}\indexLOF\ (see
\sectionref{sec:auxiliary}).
As with \reportlinebreak\glsni{tableofcontents} you will need to \LaTeX\ your document twice to
get the list of figures up-to-date, unless
you're using \iappname{latexmk} (as described in
\sectionref{sec:crossref}) in which case it will be done
automatically.

\begin{exercise}{Creating Figures}{ex:figures}

If you did \exerciseref{ex:graphicx}, you should have a document
with an image in it. You now need to put this image into a
\gls{env-figure} environment. Remember to centre the image, and give
the figure a caption. Next, try labelling the figure and referencing
it in the text. You could also put in a list of figures after the
table of contents.
You can \downloadorview{figures} an example.

\end{exercise}

\setnode{sidebysidefigs}
\subsection{Side-By-Side Figures}
\label{sec:sidebysidefigs}

Recall at the start of \sectionref{sec:figures}, I mentioned that
the \gls{env-figure} environment may contain one or more captions.
In most cases, you'll just have a single caption per
\glsni{env-figure} environment, but sometimes you may want to have
two figures side-by-side, in which case you'll need two captions
within the same \gls{env-figure} environment in order to keep the
figures together.

To do this, we can use the 
\gls{env-minipage} environment, which was covered 
in \sectionref{sec:boxes}. Recall that 
the \gls*{env-minipage} environment creates a 
\Index{horizontal box}, which means that two mini-pages can
be placed side-by-side on the same line. All you need to do 
now, is place one image and caption in one mini-page, and the
other image and caption in the neighbouring mini-page. (Do you remember what effect is obtained
by placing a \htmlref{percent symbol}{obj:suppresseol} at the end of a
line?)\doifbook{\footnote{See page~\pageref{obj:suppresseol}.}}\bookpagebreak
\begin{code}
\glsni{begin}\marg{figure}\oarg{htbp}\newline
\strut~\glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}\newline
\strut~~\glsni{centering}\newline
\strut~~\glsni{includegraphics}\marg{circle}\newline
\strut~~\glsni{caption}\marg{A Circle}\newline
\strut~~\glsni{label}\marg{fig:circle}\newline
\strut~\glsni{end}\marg{minipage}\glsni{percentchar}\newline
\strut~\glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}\newline
\strut~~\glsni{centering}\newline
\strut~~\glsni{includegraphics}\marg{rectangle}\newline
\strut~~\glsni{caption}\marg{A Rectangle}\newline
\strut~~\glsni{label}\marg{fig:rectangle}\newline
\strut~\glsni{end}\marg{minipage}\newline
\glsni{end}\marg{figure}
\end{code}%
\latex{The above code produces 
Figures~\ref{fig:circle-sbs} and~\vref{fig:rectangle-sbs}. }Note that each
mini-page uses \gls{centering} to centre its contents, and the
label is also placed in the same mini-page, after the
\gls{caption} command. If the \gls{label} was not in the same
\htmlref{scope}{sec:group} as the \gls{caption}, the
cross-reference would be incorrect.

A common mistake when trying to create side-by-side figures is
to do:
\begin{alltt}
\glsni{begin}\marg{figure}[htbp]
 \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}
  \glsni{centering}
  \glsni{includegraphics}\marg{circle}
  \glsni{caption}\marg{A Circle}
  \glsni{label}\marg{fig:circle}
 \glsni{end}\marg{minipage}
\wrong
 \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}
  \glsni{centering}
  \glsni{includegraphics}\marg{rectangle}
  \glsni{caption}\marg{A Rectangle}
  \glsni{label}\marg{fig:rectangle}
 \glsni{end}\marg{minipage}
\glsni{end}\marg{figure}
\end{alltt}
This produces one figure on top of the other, instead of
side-by-side\html{, as illustrated in \figureref{fig:circle-sbs} and
\figureref{fig:rectangle-sbs}}. This is because the blank
line indicates a paragraph break, so each minipage is in a separate
paragraph, so it's not possible for them to be on the same line.

If you want a bit of spacing in your code to make it more readable,
use \gls{percentchar} to comment out the paragraph break. For
example:
\begin{alltt}
\glsni{end}\marg{minipage}%
\correct\glsni{percentchar}
\glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}
\end{alltt}


\begin{figure}[htbp]
  \begin{makeimage}\end{makeimage}
  \begin{minipage}{0.5\linewidth}
    \figuretop{fig:circle-sbs}
    \centering
    \incGraphics[alt=Image of a circle]{pictures/circle}
    \caption{A Circle}
    \label{fig:circle-sbs}
  \end{minipage}%
  \begin{minipage}{0.5\linewidth}
    \figuretop{fig:rectangle-sbs}
    \centering
    \incGraphics[alt=Image of a rectangle]{pictures/rectangle}
    \caption{A Rectangle}
    \label{fig:rectangle-sbs}
  \end{minipage}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%% Tables %%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{tables}
\section{Tables}
\label{sec:tables}

Tables are produced in much the same way as figures, except that the
\gls{env-table} environment is used instead.
\begin{definition}
\glsni{begin}\marg{table}\oarg{\meta{placement specifiers}}
\end{definition}
Where the optional argument \meta{placement specifiers} is as described
\xpageref{earlier}{obj:positioning}.

As mentioned at the \htmlref{start of this chapter}{ch:floats},
tables typically have the caption at the top of the
table~\cite{turabian96}. With the \koma\ classes, such as
\icls{scrartcl}, \icls{scrreprt} and \icls{scrbook}, use the class
option \scrclsopt[tableabove]{captions} to ensure that the vertical
spacing appears correctly between the caption and the table content
and put \gls{caption} at the start of the \envname{table}
environment. \faq{Tables longer than a single page}{longtab}Page
breaks are not permitted in the \glsni{env-table}
environment. (The \isty{longtable} package can be used for that
instead. See the \sty{longtable} \htmlref{documentation}{sec:texdoc} for 
further details.)

\xminisec{Example:}

In the \glsterm{preamble}:
\begin{codeS}
\glsni{documentclass}\oarg{captions=tableabove}\marg{scrbook}
\end{codeS}
Later in the document:
\begin{code}
\begin{alltt}
\glsni{begin}\marg{table}\oarg{htbp}
 \glsni{caption}\marg{A Sample Table} 
 \glsni{label}\marg{tab:sample}
 \glsni{centering}
 \glsni{begin}\marg{tabular}\marg{lr}
 Item  \glsni{ampchar} Cost\glsni{tab.dbbackslashchar}
 Video \glsni{ampchar} 8.99\glsni{tab.dbbackslashchar}
 CD    \glsni{ampchar} 9.99\glsni{tab.dbbackslashchar}
 DVD   \glsni{ampchar} 15.00
 \glsni{end}\marg{tabular}
\glsni{end}\marg{table}
\end{alltt}
\end{code}%
This produces \tableref{tab:sample}.

\begin{table}[htbp]
\caption{A Sample Table}
\label{tab:sample}
\centering
\begin{makeimage}
\begin{tabular}{lr}
Item & Cost\\
Video & 8.99\\
CD    & 9.99\\
DVD   & 15.00
\end{tabular}
\end{makeimage}
\end{table}

Again, the \gls{centering} declaration is used to centre the
\gls{env-tabular} environment.
As with figures, you can create a list of tables using the command
\begin{definition}
\gls{listoftables}
\end{definition}
This creates a file with the extension \texttt{.lot}\indexLOT\ (see
\sectionref{sec:auxiliary}).
As with the table of contents and list of figures, you will need to
\LaTeX\ your document twice to get the list of tables up-to-date, unless
you're using \iappname{latexmk} (as described in
\sectionref{sec:crossref}) in which case it will be done
automatically.

\begin{exercise}{Creating Tables}{ex:tables}
If you did \exerciseref{ex:tabular}, you should have 
a \gls{env-tabular} environment in your document.  Try
turning this into a table, and add \tableref{tab:sample}.  
You could also try adding a list of tables.
As before, you can \downloadorview{tables} the solution.
\end{exercise}

\setnode{sidebysidetab}
\subsection{Side-by-Side Tables}
\label{sec:sidebysidetab}

You can create side-by-side tables using an analogous method to 
the side-by-side figures approach described
\htmlref{above}{sec:sidebysidefigs}.

\xminisec{Example:}

This example is similar to the one in \sectionref{sec:sidebysidefigs}.
Again, take care to ensure that there is no paragraph break between the
two \gls{env-minipage} environments.
\begin{code}
\begin{alltt}
\glsni{begin}\marg{table}
 \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}
  \glsni{caption}\marg{Prices for 2011}
  \glsni{label}\marg{tab:prices2011}
  \glsni{centering}
  \glsni{begin}\marg{tabular}\marg{lr}
   Item \glsni{ampchar} Price (\pounds)\glsni{tab.dbbackslashchar}
   Widgets \glsni{ampchar} 10.99\glsni{tab.dbbackslashchar}
   Whatsits \glsni{ampchar} 5.99
  \glsni{end}\marg{tabular}
 \glsni{end}\marg{minipage}\glsni{percentchar}
\glsni{percentchar}
 \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}
  \glsni{caption}\marg{Prices for 2012}
  \glsni{label}\marg{tab:prices2012}
  \glsni{centering}
  \glsni{begin}\marg{tabular}\marg{lr}
   Item \glsni{ampchar} Price (\glsni{pounds})\glsni{tab.dbbackslashchar}
   Widgets \glsni{ampchar} 11.99\glsni{tab.dbbackslashchar}
   Whatsits \glsni{ampchar} 6.99
  \glsni{end}\marg{tabular}
 \glsni{end}\marg{minipage}\glsni{percentchar}
\glsni{end}\marg{table}
\end{alltt}
\end{code}
This produces Tables~\ref{tab:prices2011} and~\vref{tab:prices2012}.

\begin{table}[htbp]
 \begin{minipage}{0.5\linewidth}
  \caption{Prices for 2011}
  \label{tab:prices2011}
  \centering
  \begin{makeimage}
  \begin{tabular}{lr}
   Item & Price (\pounds)\\
   Widgets & 10.99\\
   Whatsits & 5.99
  \end{tabular}
  \end{makeimage}
 \end{minipage}%
%
 \begin{minipage}{0.5\linewidth}
  \caption{Prices for 2012}
  \label{tab:prices2012}
  \centering
  \begin{makeimage}
  \begin{tabular}{lr}
   Item & Price (\pounds)\\
   Widgets & 11.99\\
   Whatsits & 6.99
  \end{tabular}
  \end{makeimage}
 \end{minipage}%
\end{table}

\setnode{sidewaysfloats}
\section{Sideways Floats}
\label{sec:sidewaysfloats}

The \isty{rotating} package provides the \gls{env-sidewaysfigure}
environment:
\begin{definition}
\glsni{begin}\marg{sidewaysfigure}
\end{definition}
and the \gls{env-sidewaystable} environment:
\begin{definition}
\glsni{begin}\marg{sidewaystable}
\end{definition}
which are like \gls{env-figure} and \gls{env-table}, respectively, but rotate the
entire float (including caption) sideways. This sideways float is
always placed on a page of its own.

If you have used the \clsopt{twoside} class option (or you are
using a class like \icls{scrbook}, which defaults to that option)
then the sideways floats will be rotated clockwise or
anti-clockwise, depending on whether they fall on an even (verso) or
odd (recto) numbered page. (Requires a second \LaTeX\ run to get it
correct.) 

\xminisec{Example:}
\begin{code}
\begin{alltt}
\glsni{begin}\marg{sidewaysfigure}
 \glsni{centering}
 \glsni{includegraphics}\oarg{width=0.75\glsni{textheight}}\marg{shapes}
 \glsni{caption}\marg{A Sideways Figure}
 \glsni{label}\marg{fig:sideways}
\glsni{end}\marg{sidewaysfigure}
\end{alltt}
\end{code}
The above code produces \figureref{fig:sideways}.

\dosidewaysfigure
 {fig:sideways}
 {\includegraphics[width=0.75\textheight]{pictures/shapes}}
 {A Sideways Figure}

\begin{htmlonly}
  \begin{figure}
    \figuretop{fig:sideways}
    \centering
\makeimg{A sideways figure}{%
\colorbox{white}{%
    \rotatebox[br]{90}{%
      \begin{tabular}{c}
      \includegraphics{pictures/shapes}\\
      {\usekomafont{captionlabel}Figure~\ref*{fig:sideways}}\captionformat A Sideways Figure
      \end{tabular}
    }%
}%
}
    \caption{A Sideways Figure}
    \label{fig:sideways}
  \end{figure}
\end{htmlonly}

\setnode{subfloats}
\section{Sub-Floats}
\label{sec:subfloats}

Some floats have sub-floats within them. For example, a figure may
contain several sub-figures, each of which requires a caption.
The simplest way to do this is to use the \isty{subcaption} package
that provides the \gls{env-subfigure} and \gls{env-subtable} environments:
\begin{definition}
\glsni{begin}\marg{subfigure}\oarg{\meta{pos}}\marg{\meta{width}}
\end{definition}
\begin{definition}
\glsni{begin}\marg{subtable}\oarg{\meta{pos}}\marg{\meta{width}}
\end{definition}
Within these environments, you can use \gls{caption} to create a
sub-caption. (In addition to the main \gls{caption} for the
containing \gls{env-figure} or \gls{env-table}
environment.)

\xminisec{Note:}
The \isty{subcaption} package requires the \isty{caption} package,
but doesn't automatically load it, so you'll need to load
both:\reportpagebreak
\begin{codeS}
\glsni{usepackage}\marg{caption,subcaption}
\end{codeS}

\xminisec{Example:}

This is very similar to the side-by-side figures example from
\sectionref{sec:sidebysidefigs}.
 
\begin{code}[0.9\linewidth]
\glsni{begin}\marg{figure}\oarg{htbp}\newline
\strut~\glsni{begin}\marg{subfigure}\oarg{b}\marg{0.5\glsni{linewidth}}\newline
\strut~~\glsni{centering}\newline
\strut~~\glsni{includegraphics}\marg{rectangle}\newline
\strut~~\glsni{caption}\marg{Rectangle}\glsni{label}\marg{fig:rectangle}\newline
\strut~\glsni{end}\marg{subfigure}\glsni{percentchar}\newline
\glsni{percentchar}\newline
\strut~\glsni{begin}\marg{subfigure}\oarg{b}\marg{0.5\glsni{linewidth}}\newline
\strut~~\glsni{centering}\newline
\strut~~\glsni{includegraphics}\marg{circle}\newline
\strut~~\glsni{caption}\marg{Circle}\glsni{label}\marg{fig:circle}\newline
\strut~\glsni{end}\marg{subfigure}\glsni{percentchar}\newline
\glsni{caption}\marg{Two Shapes}\newline
\glsni{label}\marg{fig:shape}\newline
\glsni{end}\marg{figure}
\end{code}

This produces \figureref{fig:shapes2}.
Elsewhere in the document, the figure and its components can be
referenced:
\begin{code}
Figure\gls{tildechar}\gls{ref}\marg{fig:shapes2} shows some shapes.  
Figure\gls{tildechar}\gls{ref}\marg{fig:rectangle} shows a rectangle and 
Figure\gls{tildechar}\gls{ref}\marg{fig:circle} shows a circle.
\end{code}
which produces the following text:
\begin{result}[Figure 7.5 shows some shapes. Figure 7.5a shows a
rectangle and Figure 7.5b shows a circle.]
Figure~\ref*{fig:shapes2} shows some shapes.
Figure~\ref*{fig:rectangle} shows a rectangle and
Figure~\ref*{fig:circle} shows a circle.\relax
\end{result}

You can also reference just the sub-float using
\begin{definition}
\gls{subref}\marg{\meta{label}}
\end{definition}
which is analogous to \gls{ref}, but only displays the sub-float
number without the number associated with its containing float.

\xminisec{Example:}
\begin{code}
Figure\glsni{tildechar}\cmdname{ref}\marg{fig:shapes2}
shows: (\glsni{subref}\marg{fig:rectangle}) a rectangle and
(\glsni{subref}\marg{fig:circle}) a circle.
\end{code}
produces
\begin{resultS}[Figure 7.5 shows: (a) a rectangle and (b) a circle.]
Figure~\ref*{fig:shapes2} shows: (\subref*{fig:rectangle}) a rectangle and (\subref*{fig:circle}) a circle.
\end{resultS}

\begin{figure}[htbp]
\begin{makeimage}\end{makeimage}
\figuretop{fig:shapes2}
\centering
\begin{latexonly}
 \begin{subfigure}[b]{0.5\linewidth}
   \centering
   \includegraphics{pictures/rectangle}
   \caption{Rectangle}\label{fig:rectangle}
 \end{subfigure}%
 \begin{subfigure}[b]{0.5\linewidth}
   \centering
   \includegraphics{pictures/circle}
   \caption{Circle}\label{fig:circle}
 \end{subfigure}%
\end{latexonly}
\begin{htmlonly}
\begin{tabular}{cc}
\htmladdimg{exercises/rectangle.png} \hspace{0.8in}&
\htmladdimg{exercises/circle.png}\\
(a) Rectangle & (b) Circle
\end{tabular}
\end{htmlonly}
\caption{Two Shapes}
\label{fig:shapes2}
\end{figure}

\xminisec{Note:}

The subfigure labels (a, b, etc) should typically be in
italic~\cite{turabian96}. This can be achieved with the
\isty{caption} package using:
\begin{definition}
\gls{DeclareCaptionLabelFormat}\marg{\meta{format-name}}\marg{\meta{code}}
\end{definition}
where \meta{format-name} is the name for this new format and
\meta{code} is the code used to format the label
where \texttt{\glsni{hashchar}2} gets replaced by the reference number.

Once you have defined a new format, you can then use
\begin{definition}
\gls{captionsetup}\oarg{\meta{type}}\marg{\meta{options}}
\end{definition}
to switch to that new format. For subfloats, \meta{type} needs to be
set to \texttt{sub}. The second argument \meta{options} is a
\meta{key}=\meta{value} comma-separated list. The key that sets the format is
\ikeyvalopt{captionsetup}{labelformat}. (For further details about
both \glsni{DeclareCaptionLabelFormat} and \glsni{captionsetup}, see
the \isty{caption} package \htmlref{documentation}{sec:texdoc}.)

For example, to create a format called \texttt{em-noparens} that
displays the number in an emphasized font without parentheses:
\begin{codeS}
\glsni{DeclareCaptionLabelFormat}\marg{em-noparens}\marg{\glsni{emph}\marg{\glsni{hashchar}2}}
\end{codeS}
Now switch to that new format:
\begin{codeS}
\glsni{captionsetup}\oarg{sub}\marg{labelformat=em-noparens}
\end{codeS}

Note that this only changes the caption label format. It doesn't affect the font 
used by \gls{ref} or \glsni{subref}.  For \gls{ref}, you can use the 
\isty{fncylab} package, which provides the command:
\begin{definition}
\gls{labelformat}\marg{\meta{ctr}}\marg{\meta{defn}}
\end{definition}
Within \meta{defn}, use \glsni{hashchar}1 to represent the subfigure value
and use \glsi{thefigure} for the encapsulating figure number. For
example:
\begin{codeS}
\glsni{labelformat}\marg{subfigure}\marg{\glsni{thefigure}\glsni{emph}\marg{\glsni{hashchar}1}}
\end{codeS}
Now
\begin{codeS}
\glsni{ref}\marg{fig:circle}
\end{codeS}
will produce
\begin{resultS}[7.5a (the letter a is emphasized)]
\ref*{fig:shapes2}\emph{a}
\end{resultS}
Unfortunately, this doesn't work for \glsni{subref}. Instead you will have 
to do, for example, the following in the text:
\begin{codeS}
\glsni{emph}\marg{\glsni{subref}\marg{fig:circle}}
\end{codeS}

If you want to add parentheses, the above can be modified
to:
\begin{code}
\glsni{DeclareCaptionLabelFormat}\marg{em-parens}\marg{(\glsni{emph}\marg{\glsni{hashchar}2})}\newline
\glsni{captionsetup}\oarg{sub}\marg{labelformat=em-parens}\newline
\glsni{labelformat}\marg{subfigure}\marg{\glsni{thefigure}(\glsni{emph}\marg{\glsni{hashchar}1})}
\end{code}
For \glsni{subref}, you will have to do, for example, the following
in the text:
\begin{codeS}
(\glsni{emph}\marg{\glsni{subref}\marg{fig:circle}})
\end{codeS}

\begin{exercise}{Creating Sub-Figures}{ex:subfloats}

Download the image files
\htmladdnormallink{\texttt{rectangle.pdf}}{\exerciseurl/rectangle.pdf}
and \htmladdnormallink{\texttt{circle.pdf}}{\exerciseurl/circle.pdf}
\latex{from \url{\exerciseurl/}} (or create your own images) and 
add \figureref{fig:shapes2} to your document.  You can
\downloadorview{subfloats} the solution.
\end{exercise}

%%%%%%%%%%%%%%%%%%% DEFINING COMMANDS %%%%%%%%%%%%%%%%%%%

\setnode{newcom}
\chapter{Defining Commands}
\label{ch:newcom}

It's possible to define your own \glspl{command} or
redefine existing ones.  Be very careful about redefining existing
commands; don't redefine a command simply because you want to use the
name, only redefine it if you are making a modification.  For
example, if you want to change the format of the current date, you
would redefine \gls{today}, but if you want to define a command
to display a specific date, you should define a new command with a
different name.

There are several reasons why you might want to define
a new command:
\begin{enumerate}

\item Reduce typing:

Suppose you have a series of commands or text that
you find yourself frequently using, then you could define
a command to do all these other commands for you.

\xminisec{Example:}  

Suppose you want a lot of large bold slanted sans-serif
portions of text within your document.  Every time you type those
portions of text, you will have to do something like:
\begin{codeS}
\glsni{textsf}\marg{\glsni{large}\glsni{bfseries}\glsni{slshape} Some text}
\end{codeS}%
It would be much easier if you could use just one command
to do all that, called, say, \cmdname{largeboldsfsl}:
\begin{codeS}
\begin{verbatim}
\largeboldsfsl{Some text}
\end{verbatim}
\end{codeS}%
or you could call it, say, \cmdname{lbsfsl} which is shorter,
but slightly less memorable:
\begin{codeS}
\begin{verbatim}
\lbsfsl{Some text}
\end{verbatim}
\end{codeS}

\item Ensure consistency:

You may find that you want to format an object a certain
way.

\xminisec{Example:}

Recall near the end of \sectionref{sec:subfloats}, I~suggested the
following to reference a subfigure (when using \gls{subref} instead
of \gls{ref}):
\begin{codeS}
(\glsni{emph}\marg{\glsni{subref}\marg{fig:circle}})
\end{codeS}
For consistency, you might want to define a command, say,
\begin{alltt}
\cmdname{formattedsubref}\marg{\meta{label}}
\end{alltt}
that was the same as 
(\glsni{emph}\marg{\glsni{subref}\marg{\meta{label}}}).

\xminisec{Another Example}

\refstepcounter{object}\label{example:keywords}%
Suppose your document has a lot of keywords
in it, and you want to format these keywords in a different font,
say sans-serif, so that they stand out.  You could just
do:
\begin{codeS}
A \glsni{textsf}\marg{command} usually begins with a backslash.
\end{codeS}%
however, it is better to define a new command called, say,
\cmdname{keyword} that will typeset its argument in a
sans-serif font.  That way it becomes a lot easier
to change the format at some later date.  For example,
you may decide to splash out and have your keywords
typed in a particular colour.  In which case, all you
need to do is simply change the definition of the
command \cmdname{keyword}, otherwise you'll have to 
go through your entire document looking for keywords
and changing each one which could be very time consuming if
you have a large document.  You might also decide at some
later date to make an index for your document.  Indexing
all the keywords then becomes much simpler, as again all you'll
need to do is modify the \cmdname{keyword} command.

\end{enumerate}

New commands are defined using the command:
\begin{definition}
\gls{newcommand}\marg{\meta{cmd}}\oarg{\meta{n-args}}\oarg{\meta{default}}\marg{\meta{text}}
\end{definition}%
The first \gls{mandatory} \meta{cmd} is
the name of your new command, which must start with a backslash.
The \gls{optional} \meta{n-args} specifies
how many arguments your new command must take.  The next
optional argument \meta{default} will be discussed later.
The final mandatory argument \meta{text} specifies what \LaTeX\ 
should do every time it encounters this command.

\xminisec{Example (No Parameters):}

Let's begin with a trivial example.  Suppose I~wanted to write a
document about a particular course, say \dq{Programming \textemdash\  Languages
and Software Construction}, and I~had to keep writing the course
title, then I~might decide to define a command that prints the course
title rather than having to laboriously type it out every time.
Let's call our new command \cmdname{coursetitle}.  We want the
following code:
\begin{codeS}
The course \glsni{emph}\marg{\cmdname{coursetitle}} is an undergraduate course.
\end{codeS}%
to produce the following output:
\begin{result}[coursetitle.html]
The course \emph{Programming \textemdash\ Languages and Software Construction}
is an undergraduate course.
\end{result}%
Clearly this command doesn't need any arguments, so we don't need to
worry about the optional argument \meta{n-args} to
\gls{newcommand}, and the only thing our new command needs to do
is print:
\begin{alltt}
Programming \glsni{emdash} Languages and Software Construction
\end{alltt}
so we would define our new command as follows:
\begin{code}
\glsni{newcommand}\marg{\cmdname{coursetitle}}\marg{Programming \glsni{emdash} Languages and Software Construction}
\end{code}%
Commands must always be defined before they are used.  The
best place to define commands is in the 
\gls{preamble}:
\begin{code}
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{newcommand}\marg{\cmdname{coursetitle}}\marg{Programming \glsni{emdash} Languages 
and Software Construction}

\glsni{begin}\marg{document}

\glsni{section}\marg{\cmdname{coursetitle}}

The course \glsni{emph}\marg{\cmdname{coursetitle}} is an undergraduate course.

\glsni{end}\marg{document}
\end{alltt}
\end{code}

\xminisec{Example (One Mandatory Argument):}

\refstepcounter{object}\label{sec:newcomarg}%
Now let's try defining a command that takes an \gls{argument} (or
parameter).  Let's go back to our \htmlref{\cmdname{keyword}
example}{example:keywords}\latex{ \vpageref{example:keywords}}.  This
command needs to take one argument that is the keyword.  Let's
suppose we want keywords to come out in
\htmlref{sans-serif}{sec:fontstyle}, then we could do:
\begin{codeS}
\glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{hashchar}1}}
\end{codeS}%
In this case we have used the optional argument \meta{n-args} to
\gls{newcommand}.  We want our command \cmdname{keyword} to have
one argument, so we have \texttt{[1]}.  In \texttt{\glsni{textsf}\marg{\glsni{hashchar}1}} the
\gls{hashchar}\texttt{1} represents the first argument.  (If we had
more than one argument, \glsni{hashchar}\texttt{2} would represent the second
argument, \glsni{hashchar}\texttt{3} would represent the third argument etc.\ up to a
maximum of~9\faq{How to break the 9-argument limit}{moren9}.) So
\begin{verbatim}
\keyword{commands}
\end{verbatim}
will be equivalent to 
\begin{alltt}
\glsni{textsf}\marg{commands}
\end{alltt}
and
\begin{verbatim}
\keyword{environment}
\end{verbatim}
will be equivalent to
\begin{alltt}
\glsni{textsf}\marg{environment}
\end{alltt}
and so on.
Again, it's best to put the command definition in the preamble to
ensure the command won't be used before it's defined.

\begin{code}
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{hashchar}1}}

\glsni{begin}\marg{document}

A \cmdname{keyword}\marg{command} usually begins with a backslash.

\glsni{end}\marg{document}
\end{alltt}
\end{code}

Now if we want to change the way the keywords are formatted,
we can simply change the definition of \cmdname{keyword}.
Let's modify our code so that the keyword is now in a 
slanted sans-serif font:
\begin{code}
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{slshape} \glsni{hashchar}1}}

\glsni{begin}\marg{document}

A \cmdname{keyword}\marg{command} usually begins with a backslash.

\glsni{end}\marg{document}
\end{alltt}
\end{code}%
Let's go one stage further.  The \isty{color} 
\htmlref{package}{sec:packages} provides the \gls{declaration}:
\begin{definition}
\gls{color}\marg{\meta{col-name}}
\end{definition}
which switches the foreground colour to \meta{col-name}. It also
provides the text-block command:
\begin{definition}
\gls{textcolor}\marg{\meta{col-name}}\marg{\meta{text}}
\end{definition}
which sets \meta{text} in the colour given by \meta{col-name}.

So let's use the \isty{color} package to make our keywords
blue:\screenpagebreak
\begin{code}
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{usepackage}\marg{color}

\glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{slshape}\glsni{color}\marg{blue}\glsni{hashchar}1}}

\glsni{begin}\marg{document}

A \cmdname{keyword}\marg{command} usually begins with a backslash.

\glsni{end}\marg{document}
\end{alltt}
\end{code}
Or we could index the keywords.  To do this we need the
\isty{makeidx} \htmlref{package}{sec:packages} and the commands 
\gls{makeindex}, 
\begin{inlinedef}\gls{index}\marg{\meta{text}}\end{inlinedef}
and \gls{printindex}:
\begin{code}
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{usepackage}\marg{makeidx}

\glsni{makeindex}

\glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{slshape} \glsni{hashchar}1}\glsni{index}\marg{\glsni{hashchar}1}}

\glsni{begin}\marg{document}

A \cmdname{keyword}\marg{command} usually begins with a backslash.

\glsni{printindex}

\glsni{end}\marg{document}
\end{alltt}
\end{code}
For further information about how to create an index, 
see \latexguide\ or \latexcomp.
Alternatively, if you want a brief overview, try \latexthesis.

Since it is unlikely that the keyword will contain a paragraph break,
we should indicate that this is a 
\gls{short} using the \htmlref{starred form}{itm:starredcommand}:
\begin{codeS}
\glsni{newcommand}*\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{slshape} \glsni{hashchar}1}\glsni{index}\marg{\glsni{hashchar}1}}
\end{codeS}
Now if you forget to add the closing brace, for example,
\verb|\keyword{command|, then \gls{tex}['s] error checking mechanism will 
pick up the error sooner. This will give an error message that
looks like:
\begin{verbatim}
! Paragraph ended before \keyword was complete.
<to be read again>
                   \par
l.604
\end{verbatim}
This at least gives you the line number (604 in this example) of the
end of the paragraph where the error has occurred.

If you don't used the starred form of \gls{newcommand}, then
you will get the somewhat less than helpful error:
\begin{verbatim}
! File ended while scanning use of \keyword.
\end{verbatim}
If you have a very large document, it may take a while to track
down where exactly you have missed a brace.

\begin{exercise}{Defining a New Command}{ex:newcom}
Try typing up the following code:
\begin{bcode}
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{newcommand}*\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{hashchar}1}}

\glsni{begin}\marg{document}

A \cmdname{keyword}\marg{command} usually begins with a backslash.

Segments of code may be \cmdname{keyword}\marg{grouped}.

Some \cmdname{keyword}\marg{commands} take one or more \cmdname{keyword}\marg{arguments}.
\glsni{end}\marg{document}
\end{alltt}
\end{bcode}

Then modify your code so that the keywords are in a slanted
sans-serif font or modify your code so that the keywords come out in
blue (using the \isty{color} package as in the example earlier).
Again you can \downloadorview{newcom} the result.

\xminisec{For the more adventurous:}

If you want to create an index as in the previous example, you will
need to use the application \iappname{makeindex}. If you used
\iappname{latexmk} back in \sectionref{sec:crossref}, you can just
carry on using that as before. If not you need to do the following
in TeXworks:
\begin{enumerate}
  \item Create the PDF as described in \sectionref{sec:texworks}.

  \item Select \menu{MakeIndex} from the drop-down list next to the
   build (typeset) button (see \figureref{fig:texworks9}).

  \item Click on the build button. If all goes well, you won't see
    anything different. If you see something like the following:
\begin{alltt}
Couldn't find input index file exercise\theexercise\space nor exercise\theexercise.idx.
\end{alltt}
    then you probably forgot to add the command \gls{makeindex} to
    the preamble. Add it in and go back to Step~1.

  \item Select \menu{pdfLaTeX} from the drop-down list and build the
    PDF file again. Move to the last page of the PDF, and you should
    see the index.
\end{enumerate}

\begin{figure}[htbp]
\figconts
  {pictures/texworks9}
  {%
    \caption{Selecting MakeIndex in TeXWorks}
  }%
  {fig:texworks9}
\end{figure}

\end{exercise}

%%%%%%%%%%%%% Defining Commands with an Optional Argument %%%%%%%%%%%%%

\setnode{newcomopt}
\section{Defining Commands with an Optional Argument}
\label{sec:newcomopt}

As mentioned earlier, the \gls{newcommand} command has a second
optional argument \meta{default}.  This allows you to define a
command with an optional argument\faq{More than one optional
argument}{twooptarg}.  For example, suppose we want a command called,
say, \cmdname{price}.  Suppose we want the following code:
\begin{codeS}
\begin{verbatim}
\price{100}
\end{verbatim}
\end{codeS}%
to produce the following output:
\begin{resultS}[price.html]
\pounds100 excl VAT @ 17.5\%\relax
\end{resultS}%
and let's suppose we want an optional argument
so that we can change the VAT.  That is, we
would want the following code:
\begin{codeS}
\begin{verbatim}
\price[20]{30}
\end{verbatim}
\end{codeS}%
to produce the following output:
\begin{resultS}[price2.html]
\pounds30 excl VAT @ 20\%
\end{resultS}%
Therefore we want to define a command
such that if the optional argument is absent 
we will have \texttt{17.5}, and if it is present
the optional argument will be substituted instead.
This command can be defined as follows:
\begin{codeS}
\gls{newcommand}\marg{\cmdname{price}}\oarg{2}\oarg{17.5}\marg{\glsni{pounds} \gls{hashchar}2 excl VAT @ \glsni{hashchar}1\glsni{percent}}
\end{codeS}%
Here, \texttt{\glsni{hashchar}1} represents the optional argument (by default
\texttt{17.5}) and \texttt{\glsni{hashchar}2} represents the mandatory argument (the
second argument if the optional argument is present, or the only
argument if the optional argument is absent.)

As before, since the argument is unlikely to contain a paragraph
break, we should indicate that it is a \gls{short} using the \htmlref{starred form}{itm:starredcommand}:
\begin{codeS}
\gls{newcommand}*\marg{\cmdname{price}}\oarg{2}\oarg{17.5}\marg{\glsni{pounds} \glsni{hashchar}2 excl VAT @ \glsni{hashchar}1\gls{percent}}
\end{codeS}%

\begin{exercise}{Defining Commands with an Optional Argument}{ex:newcomopt}
In this exercise, you will need to define a slightly modified
version of the above example.  Try defining a command called,
say, \cmdname{cost}.  It should take one optional argument and
one mandatory argument.  Without the optional argument, it
behaves in the same way as the \cmdname{price} example above,
so that, say,
\begin{codeS}
\begin{verbatim}
\cost{50}
\end{verbatim}
\end{codeS}%
will produce
\begin{resultS}[price3.html]
\pounds50 excl VAT @ 17.5\%\null
\end{resultS}%
but with the optional argument, you can change the
\verb|excl VAT @ 17.5\%| bit.  So that, say,
\begin{codeS}
\begin{verbatim}
\cost[inc VAT]{50}
\end{verbatim}
\end{codeS}%
will produce
\begin{resultS}[price4.html]
\pounds50 inc VAT\mbox{}% LaTeX2HTML is getting confused!
\end{resultS}

You can \downloadorview{newcomopt} the solution.

\xminisec{For the more adventurous:}
If you did \exerciseref{ex:newcom} and you modified \cmdname{keyword}
so that it indexed the keyword, you may have noticed that
\begin{codeS}
\verb|\keyword{command}|
\end{codeS}
and
\begin{codeS}
\verb|\keyword{commands}|
\end{codeS}
produced separate entries in the index. It would be better to have an
optional argument to override the indexing mechanism. For example,
\begin{codeS}
\verb|\keyword{command}|
\end{codeS}
should print and index the word \dq{command},
whereas
\begin{codeS}
\verb|\keyword[command]{commands}|
\end{codeS}
should print \dq{commands}
and index \dq{command}. In other words, we need an optional
argument that defaults to the mandatory argument if it is not
present.
This is how to achieve that type of effect:\footnote{Recall from \chapterref{ch:def} the percent symbol discards the space resulting from the end
of line character.}
\begin{code}
\glsni{newcommand}*\marg{\cmdname{keyword}}\oarg{2}\oarg{\cmdname{keywordentry}}\marg{\glsni{percentchar}\newline
\strut~~\icmdname{def}\cmdname{keywordentry}\marg{\glsni{hashchar}2}\glsni{percentchar}\newline
\strut~~\glsni{textsf}\marg{\glsni{hashchar}2}\glsni{percentchar}\newline
\strut~~\gls{index}\marg{\glsni{hashchar}1}\glsni{percentchar}\newline
}
\end{code}
In this example, the default value for the optional argument
is set to the command \cmdname{keywordentry}. At the start of 
\cmdname{keyword} this is defined to be the mandatory argument 
(as specified by \verb|#2|) using \gls{tex}['s] \cmdname{def}
command:\footnote{\cmdname{def} is too complicated for an
introductory \LaTeX\ guide but, if you're interested, read \emph{The
\TeX{}book}~\cite{texbook}.}
\begin{alltt}
\cmdname{def}\cmdname{keywordentry}\marg{\glsni{hashchar}2}
\end{alltt}
Then typeset the keyword (given in the mandatory
argument \texttt{\glsni{hashchar}2}) in a sans-serif font:
\begin{alltt}
\glsni{textsf}\marg{\glsni{hashchar}2}
\end{alltt}
Now index the term using the optional argument (\texttt{\glsni{hashchar}1}):
\begin{alltt}
\glsni{index}\marg{\glsni{hashchar}1}
\end{alltt}
If an optional argument is specified, \texttt{\glsni{hashchar}1} will be the given
argument, but if the optional argument is missing, \texttt{\glsni{hashchar}1} will
be \cmdname{keywordentry}, which has earlier been set to
the mandatory argument \texttt{\glsni{hashchar}2}.
\end{exercise}

%%%%%%%%%%%%%%%%%%%%%%%%% Redefining Commands %%%%%%%%%%%%%%%%%%%%%

\setnode{renewcom}
\section{Redefining Commands}
\label{sec:renewcom}

Commands can be redefined using the command:
\begin{definition}
\gls{renewcommand}\marg{\meta{cmd}}\oarg{\meta{n-args}}\oarg{\meta{default}}\marg{\meta{text}}
\end{definition}\reportpagebreak\noindent
This has exactly the same format as \gls{newcommand} but is
used for redefining existing commands.
Again there is a \htmlref{starred version}{itm:starredcommand} to indicate that the command
is a \gls{short}.

\xminisec{Caveat:}

\warning Never redefine a command whose existing function is unknown
to you or just because you want to use a particular command name,
regardless of its previous function. By way of illustration: as a
production editor, I~have to combine articles by different authors
into a single book. Each author supplies the \LaTeX\ code for their
own article. Every so often, I~get code that redefines a command for
the convenience of the author. Later on another author tries to use
the same command, on the assumption that the command behaves
according to its original definition. This tends to involve the
accent commands as they are short and that saves the author typing.
It usually goes along these lines: author~A redefines \gls{c} (the
cedilla accent command) to display a maths bold
\dq{\boldc} to indicate a
vector. Later, author~B, uses the cedilla accent, say, in the name
Fran\c{c}ois:
\begin{alltt}
Fran\gls{c}\marg{c}ois
\end{alltt}
Author~A's hack turns this into
Fran\boldc cois.

\xminisec{Example (Redefining List Labels):}

Recall the \gls{env-itemize} environment discussed in
\sectionref{sec:itemize}.  You may have up to four nested
\gls{env-itemize} environments, the labels for the outer environment
are specified by the command \gls{labelitemi}, the labels for
the second level are specified by \gls{labelitemii}, the third
by \gls{labelitemiii} and the fourth by \gls{labelitemiv}.
By default, \glsni{labelitemi} is a bullet point (\makeimg{bullet
symbol}{\labelitemi}),
\glsni{labelitemii} is an en dash (\makeimg{en dash}{\labelitemii}), 
\glsni{labelitemiii} is an
asterisk (\makeimg{asterisk}{\labelitemiii}) and 
\glsni{labelitemiv} is a centred dot (\makeimg{centered
dot}{\labelitemiv}).  These can be changed by redefining
\glsni{labelitemi} etc.

Recall from \tableref{tab:symbols} that the command
\gls{dag} produces a dagger symbol, we can use this symbol
instead of a bullet point:
\begin{code}
\glsni{renewcommand}*\marg{\glsni{labelitemi}}\marg{\gls{dag}}\newline
\glsni{begin}\marg{itemize}\newline
\mbox{}\newline
\gls{item} Animal\newline
\mbox{}\newline
\glsni{item} Mineral\newline
\mbox{}\newline
\glsni{item} Vegetable\newline
\mbox{}\newline
\glsni{end}\marg{itemize}
\end{code}%
Output:
\begin{result}[List uses dagger symbol instead of a bullet point for
the marker]
\renewcommand*{\labelitemi}{\dag}

\begin{itemize}

\item Animal

\item Mineral

\item Vegetable

\end{itemize}
\end{result}

Here's another example, it uses the \Index{PostScript}
font ZapfDingbats via the \isty{pifont} package:
\begin{code}
\glsni{renewcommand}*\marg{\glsni{labelitemi}}\marg{\gls{ding}\marg{43}}\newline
\glsni{begin}\marg{itemize}\newline
\mbox{}\newline
\glsni{item} Animal\newline
\mbox{}\newline
\glsni{item} Mineral\newline
\mbox{}\newline
\glsni{item} Vegetable\newline
\mbox{}\newline
\glsni{end}\marg{itemize}
\end{code}\bookpagebreak\noindent
Output:
\begin{result}[List uses a pointing finger instead of a bullet point
for the marker]
\renewcommand*{\labelitemi}{\ding{43}}

\begin{itemize}

\item Animal

\item Mineral

\item Vegetable

\end{itemize}
\end{result}%
In the above example, it would actually be easier to use the
\gls{env-dinglist} environment defined in the \isty{pifont} package:
\begin{code}
\begin{alltt}
\glsni{begin}\marg{dinglist}\marg{43}

\glsni{item} Animal

\glsni{item} Mineral

\glsni{item} Vegetable\screenpagebreak

\glsni{end}\marg{dinglist}
\end{alltt}
\end{code}


\xminisec{Example (Redefining the Default Font):}

Recall from \sectionref{sec:changingfonts} that the default font
family is usually the serif (Roman) family. So what happens if you
need to write your entire document in, say, Helvetica?  The default
font family name is stored in:
\begin{definition}
\gls{familydefault}
\end{definition}
This command is usually
defined to be just \gls{rmdefault}, which in turn stores the name of the
default serif font (initially \texttt{cmr}, Computer Modern Roman). If 
you want the default font to be sans-serif, all you
need do is add the following line to the
\glsterm{preamble}:
\begin{codeS}
\glsni{renewcommand}\marg{\glsni{familydefault}}\marg{\gls{sfdefault}}
\end{codeS}
\glsni{sfdefault} stores the name of the default sans-serif font (initially \texttt{cmss},
Computer Modern Sans-Serif) and
the \isty{helvet} package redefines \glsni{sfdefault} to \texttt{phv},
which is the identifier for the Helvetica font.
So the following document will be in Helvetica:
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{usepackage}\marg{helvet}
\glsni{renewcommand}\marg{\glsni{familydefault}}\marg{\glsni{sfdefault}}

\glsni{begin}\marg{document}
This is a sample document.
\glsni{end}\marg{document}
\end{alltt}
Similarly, if you want the default font to be monospaced (typewriter) then you'd need to do:
\begin{codeS}
\glsni{renewcommand}\marg{\glsni{familydefault}}\marg{\gls{ttdefault}}
\end{codeS}

Incidentally, you may have noticed in \sectionref{sec:changingfonts}
that although I~said I'd used the \isty{anttor} and
\isty{libris} packages to set the serif and sans-serif families for
\latexhtml{this book}{the PDF version of this book}, I
didn't mention anything about the typewriter (monospaced) font. I~used
the TXTT font, but that doesn't have a corresponding package. You
just redefine \glsni{ttdefault} to \texttt{txtt}:
\begin{codeS}
\glsni{renewcommand}*\marg{\glsni{ttdefault}}\marg{txtt}
\end{codeS}

\xminisec{Example (Redefining Fixed Names):}

You may have noticed that \LaTeX\ automatically generates pieces of
text such as \dq{Chapter}, \dq{Figure}, \dq{Bibliography}.  These are
generated by the commands shown in \tableref{tab:textlab}.

\begin{table}[hbtp]
\caption[Predefined Names]{Predefined Names 
(\supdag Book and report style classes (such as \icls{scrreprt} and \icls{scrbook}), 
\supddag article-style classes (such as \icls{scrartcl}), 
remainder book, report and article-style classes)}
\label{tab:textlab}
\centering
\begin{tabular}{ll}
\toprule
\bfseries Command & \bfseries Default Text\\
\midrule
\gls{contentsname} & \contentsname\\
\gls{listfigurename} & \listfigurename\\
\gls{listtablename} & \listtablename\\
\gls{bibname}\supdag & \bibname\\
\gls{refname}\supddag & \refname\\
\gls{indexname} & \indexname\\
\gls{figurename} & \figurename\\
\gls{tablename} & \tablename\\
\gls{partname} & \partname\\
\gls{chaptername}\supdag & \chaptername\\
\gls{appendixname} & \appendixname\\
\gls{abstractname} & \abstractname
\\\bottomrule
\end{tabular}
\end{table}

You can change the defaults using \gls{renewcommand}.  For
example, suppose you want the table of contents to be labelled
\dq{Table of Contents}, instead of the default \dq{Contents}, you
would need to do:
\begin{codeS}
\glsni{renewcommand}*\marg{\glsni{contentsname}}\marg{Table of Contents}
\end{codeS}
\faq{Changing the words babel uses}{latexwords}In fact, the
\isty{babel} package (see \sectionref{sec:babel}) uses this method
to redefine the commands in \tableref{tab:textlab} whenever you
switch language using \reportlinebreak\screenlinebreak
\gls{selectlanguage} or within the contents of
the \gls{env-otherlanguage} environment. This unfortunately has the
side-effect that means if you try to redefine these commands,
\sty{babel} will automatically overwrite your definition whenever
there's a language change, which includes at the beginning of the
\gls{env-document} environment. Instead you need to use
\sty{babel}'s \glsni{addto} mechanism.
\begin{definition}
\gls{addto}\marg{\meta{command}}\marg{\meta{code}}
\end{definition}
This patches the definition of a command (specified in the first
\gls{argument}) adding \meta{code} to the end of the command
definition. Whenever \sty{babel} switches the current language, it
uses the command \cmdname{captions}\meta{language}, which performs
all the redefinitions of commands like those listed in
\tableref{tab:textlab}. For example, if you are using \sty{babel}
with the \istyopt{babel}{english} option and you want to change
\glsni{contentsname} so that it does \dq{Table of Contents} instead
of \dq{Contents}, you need to do:
\begin{code}
\begin{alltt}
\glsni{addto}\marg{\cmdname{captionsenglish}}\marg{\glsni{percentchar}
  \glsni{renewcommand}\marg{\glsni{contentsname}}\marg{Table of Contents}\glsni{percentchar}
}
\end{alltt}
\end{code}

\xminisec{Notes:}

\warning Take care if you want to patch an existing command. For
example, suppose you want to append something to the action of a
command. You might be tempted to do
\begin{alltt}
\wrong\glsni{renewcommand}*\marg{\cmdname{foo}}\marg{\cmdname{foo} Something else}
\end{alltt}
This will cause an infinite loop where \cmdname{foo} recursively
calls itself. Instead you should use one of the commands provided by
the \isty{etoolbox} package (such as \gls{appto}, which has the same
syntax as \sty{babel}'s \glsni{addto} described above). For further details,
read the \sty{etoolbox} \htmlref{documentation}{sec:texdoc}.

\begin{exercise}{Renewing Commands}{ex:renewcom}
If you did Exercises~\ref{ex:figures} and \ref{ex:tables}, go back to
that document and changed the figures and tables so that they
are labelled \dq{Fig} and \dq{Tab} instead of \dq{Figure} and \dq{Table}.
Hint: you need to redefine \glsni{tablename} and \glsni{figurename}.

You can \downloadorview{renewcom} the solution.
\end{exercise}

%%%%%%%%%%%%%%%%%%%%%%%% MATHEMATICS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{mathematics}
\chapter{Mathematics}
\label{ch:maths}

As mentioned in the \htmlref{introduction}{ch:intro}, \LaTeX\ is
particularly good at typesetting mathematics.  In order to
use any of the maths commands we need to be in one of the
mathematics \glspl{environment}.  There are two
basic types of mathematics: \keyword{in-line maths} and
\keyword{displayed maths}. In-line maths is mathematics that
occurs within a line of text, for example:
\begin{resultS}[inlinemaths.html]
The variable $x$ is transformed by the function $f(x)$.
\end{resultS}%
Displayed maths is mathematics that occurs on a line
of its own.  For example:
\begin{result}[displaymath.html]
A polynomial is a function of the form
\[
f(x) = \sum_{i=0}^na_ix^i
\]
\end{result}
The maths environments switch to \LaTeX's \dq{math mode}, which uses
specialist maths fonts and spacing rather than just using an italic
font.

If you want to typeset any mathematics, I~strongly advise using the
\istystart{amsmath} package:
\begin{alltt}
\glsni{usepackage}\marg{amsmath}
\end{alltt}
This patches some existing \LaTeX\ commands and environments and
also provides many useful additions.

This chapter is just an introduction to typesetting mathematics in
\LaTeX. If you want a comprehensive guide, I~recommend you read \emph{Math Mode}
by Herbert~Vo\ss~\cite{voss}, which can be access via
\appname{texdoc} (see \sectionref{sec:texdoc}):
\begin{verbatim}
texdoc mathmode
\end{verbatim}

%%%%%%%%%%%%%%%% In-Line Mathematics %%%%%%%%%%%%%%%%%%%

\setnode{inlinemaths}
\section{In-Line Mathematics}
\label{sec:inline}

In-line mathematics is created using the \gls{env-math}
environment. (Note U.S. spelling --- \dq{math} not \dq{maths}).

\xminisec{Example:}
\begin{code}
The variable \glsni{begin}\marg{math}x\glsni{end}\marg{math} is transformed
by the function \glsni{begin}\marg{math}f(x)\glsni{end}\marg{math}.
\end{code}
It's somewhat cumbersome having to type
\glsni{begin}\marg{math} and \glsni{end}\marg{math} and it also
makes the \gls{source} a little difficult to read so there
are shorthand notations that can be used instead:
\gls{beginmath} is equivalent to \glsni{begin}\marg{math} and
\gls{endmath} is equivalent to \glsni{end}\marg{math}.  So
the example above can be rewritten:
\begin{codeS}
The variable \glsni{beginmath}x\glsni{endmath} is transformed by the function 
\glsni{beginmath}f(x)\glsni{endmath}.
\end{codeS}%
There is an even shorter notation:
The \htmlref{special character}{sec:chars} \gls{dollarchar} is equivalent
to both \glsni{begin}\marg{math} and \glsni{end}\marg{math}:
\begin{codeS}
The variable \glsni{dollarchar}x\glsni{dollarchar} is transformed by the 
function \glsni{dollarchar}f(x)\glsni{dollarchar}.
\end{codeS}%
This is considerably easier to type and
to read, but you need to make sure that all your \glsni{dollarchar}
symbols have matching pairs.  The above code will look like:
\begin{resultS}[inlinemaths2.html]
The variable $x$ is transformed
by the function $f(x)$.
\end{resultS}%
The other advantage in using \glsni{dollarchar} over \glsni{beginmath} and
\glsni{endmath} is that \glsni{dollarchar} is a \gls{robust}, 
whereas \glsni{beginmath} and \glsni{endmath} are 
\glspl{fragile} and
will need to be protected if they occur in a \glslink{fragile}{moving
argument}.\casemedia{}{}{ (See \sectionref{sec:fragile}.)}{}

Note: you should always make sure you are in maths mode to
typeset any variables (such as $x$, $y$, $z$), as this will
ensure that the correct maths fonts are used, as well as the
appropriate spacing. Similarly, don't use \glsni{dollarchar}
as a short cut for an italic font.
\begin{codeS}[\linewidth]
Notice the \glsni{dollarchar}difference\glsni{dollarchar} between 
\glsni{dollarchar}(x', y', z')\glsni{dollarchar} and
\glsni{textit}\marg{(x', y', z')}.
\end{codeS}%
\begin{resultS}[Image of result: the brackets are upright in the
maths font but slanted in the italic font. The apostrophe becomes a
prime in the maths font. The spacing is also
different.]
Notice the $difference$ between $(x', y', z')$ and
\textit{(x', y', z')}.
\end{resultS}

%%%%%%%%%%%%%%%% Displayed Mathematics %%%%%%%%%%%%%%%%%%%%%%

\setnode{displayedmaths}
\section{Displayed Mathematics}
\label{sec:displayed}

One-line unnumbered displayed mathematics can be created using:
\begin{definition}
\gls{begindispmath}\meta{maths}\gls{enddispmath}
\end{definition}
where \meta{maths} is the mathematics to be displayed.

\xminisec{Example:}
\begin{code}
\begin{alltt}
A linear function is a function of the form
\glsni{begindispmath} y = mx + c \glsni{enddispmath}
\end{alltt}
\end{code}%
Output:
\begin{result}[displaymath2.html]
A linear function is a function of the form
\[ y = mx + c \]
\end{result}%

\warning Don't use the \envname{displaymath} environment or \verb|$$|\ldots\verb|$$|~\cite{l2tabu}.
Use \glsni{begindispmath} and \glsni{enddispmath} with
the \isty{amsmath} package.

The \glsni{env-equation}\refstepcounter{object}\label{env:equation} 
environment provides something similar to
\glsni{begindispmath} \glsni{enddispmath}, except
that the equation is numbered.  Modifying the above example:
\begin{code}
\begin{alltt}
A linear function is a function of the form
\glsni{begin}\marg{equation}
y = mx + c
\glsni{end}\marg{equation}
\end{alltt}
\end{code}%
results in the following output:
\begin{result}[As before but the equation now has a number in
brackets on the right.]
A linear function is a function of the form
\begin{equation}
y = mx + c
\end{equation}
\end{result}
Normal text can be inserted into the equation using
\begin{definition}
\gls{text}\marg{\meta{text}}
\end{definition}
which is provided by the \isty{amsmath} package.

\xminisec{Example:}
\begin{codeS}
\glsni{begindispmath} x = 2 \glsni{text}\marg{ and } y = -1 \glsni{enddispmath}
\end{codeS}%
results in the following output:
\begin{result}[x equals 2 and y equals minus 1 (the word 'and' is in normal text font)]
\[ x = 2 \text{ and } y = -1 \]
\end{result}

\faq{Re-using an equation}{reuseq}%
Recall from \sectionref{sec:crossref} that we can
\htmlref{cross-reference}{sec:crossref} most things that \LaTeX\
automatically numbers using \gls{ref} and \gls{label}.
Equations can be cross-referenced in the same way:\reportpagebreak
\begin{code}
\begin{alltt}
Equation\glsni{tildechar}\glsni{ref}\marg{eqn:linear} is a linear function.
\glsni{begin}\marg{equation}
\glsni{label}\marg{eqn:linear}
f(x) = mx + c
\glsni{end}\marg{equation}\screenpagebreak
\end{alltt}
\end{code}
\begin{result}[eqref.html]
Equation~\ref*{eqn:linear} is a linear function.
\begin{equation}
\label{eqn:linear}
f(x) = mx + c
\end{equation}
\end{result}
Equation numbers are usually given in parentheses, which can be done
using:
\begin{codeS}
Equation\glsni{tildechar}(\glsni{ref}\marg{eqn:linear})
\end{codeS}
The \isty{amsmath} package provides a convenient short cut:
\begin{definition}
\gls{eqref}\marg{\meta{label}}
\end{definition}
So the above can be written as:
\begin{codeS}
Equation\glsni{tildechar}\glsni{eqref}\marg{eqn:linear}
\end{codeS}
\begin{resultS}[Equation (9.2)]
% fake it to suppress hyperlink
Equation~(\ref*{eqn:linear})
\end{resultS}

\xminisec{Note:}

Both the \gls{env-equation} environment and
\gls{begindispmath}\ldots\gls{enddispmath} are only designed for one
line of maths. Therefore you must not have any line breaks or
paragraph breaks within them.
The following will cause an error:
\begin{alltt}
\glsni{begin}\marg{equation}
\wrong
f(x) = mx + c
\wrong
\glsni{end}\marg{equation}
\end{alltt}
Either remove the blank lines or comment them out:
\begin{alltt}
\glsni{begin}\marg{equation}
\glsni{percentchar}\correct
f(x) = mx + c
\glsni{percentchar}\correct
\glsni{end}\marg{equation}
\end{alltt}

\setnode{align}
\section{Multiple Lines of Displayed Maths}
\label{sec:align}

The \isty{amsmath} package provides the \gls{env-align}
and \gls{env-align*} environments for aligned equations.
The starred version doesn't number the equations. These environments 
provide pairs of left- and right-aligned columns.
As with the \gls{env-tabular} environment, use \gls{ampchar} to
separate columns and \gls{tab.dbbackslashchar} to separate rows.
Unlike the \gls{env-tabular} environment, there is no argument as
the column specifiers are predefined. Another difference is that no
page breaks can occur in the \gls{env-tabular} environment, but it's
possible to allow a page break in \glsni{env-align} or
\glsni{env-align*} using
\begin{definition}
\gls{displaybreak}\oarg{\meta{n}}
\end{definition}
immediately before the \gls{tab.dbbackslashchar} where it is to take
effect. The optional argument is a number from~0 to~4 indicating the
desirability to break the page (from~0 the least to~4 the most).

If you want to mix numbered and unnumbered rows, you can use
\begin{definition}
\gls{notag}
\end{definition}
to suppress the numbering for a particular row in the \glsni{env-align} environment.
This command must go before \gls{tab.dbbackslashchar} at the end of the
row. The default equation numbering can be overridden for a
particular row using:
\begin{definition}
\gls{tag}\marg{\meta{tag}}
\end{definition}
where \meta{tag} is the replacement for the equation number.

\screenpagebreak\warning Don't use the \envname{eqnarray} or \envname{eqnarray*}
environments. They're obsolete~\cite{l2tabu}.


\xminisec{Example (Unnumbered):}

\begin{code}
\glsni{begin}\marg{align*}\newline
y \glsni{ampchar}= 2x + 2\glsni{tab.dbbackslashchar}\newline
\strut~~\glsni{ampchar}= 2(x+1)\newline
\glsni{end}\marg{align*}
\end{code}
\begin{result}[align.html]
\begin{align*}
y &= 2x + 2\\
  &= 2(x+1)
\end{align*}
\end{result}
Note that the equals sign is placed at the start of the second
column, \emph{after} the ampersand \gls{ampchar}. This ensures the
correct amount of spacing on either side. If the first line of the
above equation was changed to:\bookpagebreak
\begin{alltt}
\wrong y =\gls{ampchar} 2x + 2\gls{tab.dbbackslashchar}
\end{alltt}
there wouldn't be enough space on the right of the equal sign:
\begin{htmlresult}{y equals 2x + 2}
\begin{makeimage}
\begin{align*}
y =& 2x + 2
\end{align*}
\end{makeimage}
\end{htmlresult}

\xminisec{Example (One Row Numbered):}

\begin{code}
\glsni{begin}\marg{align}\newline
y \glsni{ampchar}= 2x + 2\glsni{notag}\glsni{tab.dbbackslashchar}\newline
\strut~~\glsni{ampchar}= 2(x+1)\newline
\glsni{end}\marg{align}
\end{code}
\begin{result}[Image of result: as the earlier example but the second equation has been numbered]
\begin{align}
y &= 2x + 2\notag\\
  &= 2(x+1)
\end{align}
\end{result}\screenpagebreak

\xminisec{Example (Four Columns):}

\begin{code}
\glsni{begin}\marg{align*}\newline
y \glsni{ampchar}= 2x + 2 \glsni{ampchar} z 
 \glsni{ampchar}= 6x + 3\glsni{tab.dbbackslashchar}\newline
\strut~~\glsni{ampchar}= 2(x+1) \glsni{ampchar}~~~\glsni{ampchar}= 3(2x+1)\newline
\glsni{end}\marg{align*}
\end{code}
\begin{result}[4colalign.html]
\begin{align*}
y &= 2x + 2 & z &= 6x + 3\\
  &= 2(x+1) &  &= 3(2x+1)
\end{align*}
\end{result}

As with \gls{env-equation}, you can cross-reference individual rows
of an \glsni{env-align} environment, but you must remember to
put \gls{label} \emph{before} the end of row \gls{tab.dbbackslashchar}
separator. You can reference a row in the \glsni{env-align*}
environment if you have assigned it a tag with \gls{tag}, but don't
try labelling a row in the \glsni{env-align} environment where the
numbering has been suppressed with \gls{notag}.

\xminisec{Example (Cross-Referenced):}

This example has two numbered equations in an \gls{env-align} environment,
both of which are labelled and referenced:
\begin{code}
The function \glsni{dollarchar}f(x)\glsni{dollarchar} is given in 
Equation\glsni{tildechar}\glsni{eqref}\marg{eq:fx},
and its derivative \glsni{dollarchar}f'(x)\glsni{dollarchar} is given in 
Equation\glsni{tildechar}\glsni{eqref}\marg{eq:dfx}.
\newline
\glsni{begin}\marg{align}\newline
f(x) \glsni{ampchar}= 2x + 1
\glsni{label}\marg{eq:fx}\glsni{tab.dbbackslashchar}\newline
f'(x) \glsni{ampchar}= 2 \glsni{label}\marg{eq:dfx}\newline
\glsni{end}\marg{align}
\end{code}
\begin{result}[alignref.html]
The function $f(x)$ is given in Equation~(\ref*{eq:fx}), and its
derivative $f'(x)$ is given in Equation~(\ref*{eq:dfx}).
\begin{align}
f(x) &= 2x + 1\label{eq:fx}\\
f'(x) &= 2 \label{eq:dfx}
\end{align}
\end{result}

Recall the command \gls{text}\marg{\meta{text}} from the
\htmlref{previous section}{sec:displayed}. This can be used
within cells of the \glsni{env-align} and \glsni{env-align*}
environments, but the \isty{amsmath} package also provides
\begin{definition}
\gls{intertext}\marg{\meta{text}}
\end{definition}
which can be used for a line of interjection between the rows. This
command may only go right after \gls{tab.dbbackslashchar}.

\xminisec{Example}

\begin{code}
\glsni{begin}\marg{align*}\newline
y \glsni{ampchar}= 2x +
2\glsni{tab.dbbackslashchar}\newline
\glsni{intertext}\marg{Using the distributive law:}\newline
  \glsni{ampchar}= 2(x+1)\newline
\glsni{end}\marg{align*}
\end{code}
\begin{result}[intertext.html]
\begin{align*}
y &= 2x + 2\\
\intertext{Using the distributive law:}
  &= 2(x+1)
\end{align*}
\end{result}\bookpagebreak

There are other environments for multiple-line displayed maths, but
they are beyond the scope of this book. See
the \isty{amsmath} documentation for further details.

%%%%%%%%%%%%%%%% Mathematical Commands %%%%%%%%%%%%%%%%%%%%

\setnode{mathscom}
\section{Mathematical Commands}
\label{sec:mathscom}

Most of the \glspl{command} described in this
section may only be used in one of the mathematics environments.  If
you try to use a mathematics command outside a maths environment you
will get a \dq{\texttt{Missing \$ inserted}} error message.

%------------------ Maths Fonts ------------------

\setnode{mathsfonts}
\subsection{Maths Fonts}
\label{sec:mathsfonts}

Just as we are able to \htmlref{change text fonts}{sec:fonts} using
the commands \gls{textrm}, \gls{textbf} etc, we can also
use commands to change the maths font.  Basic maths font changing
commands are shown in \tableref{tab:mathsfonts}.

\begin{table}[tbhp]
\caption{Maths Font Changing Commands}
\label{tab:mathsfonts}
\centering
\begin{tabular}{lll}
\toprule
\bfseries Command & \bfseries Example Input & \bfseries Corresponding Output\\
 & & (Computer Modern)\\
\midrule
\begin{inlinedef}\gls{mathrm}\marg{\meta{maths}}\end{inlinedef} &
\verb|$\mathrm{xyz}$| & $\cmmathrm{xyz}$\\
\begin{inlinedef}\gls{mathsf}\marg{\meta{maths}}\end{inlinedef} &
\verb|$\mathsf{xyz}$| & $\cmmathsf{xyz}$\\
\begin{inlinedef}\gls{mathtt}\marg{\meta{maths}}\end{inlinedef} &
\verb|$\mathtt{xyz}$| & $\cmmathtt{xyz}$\\
\begin{inlinedef}\gls{mathit}\marg{\meta{maths}}\end{inlinedef} &
\verb|$\mathit{xyz}$| & $\cmmathit{xyz}$\\
\begin{inlinedef}\gls{mathbf}\marg{\meta{maths}}\end{inlinedef} &
\verb|$\mathbf{xyz}$| & $\cmmathbf{xyz}$\\
\begin{inlinedef}\gls{mathcal}\marg{\meta{maths}}\end{inlinedef} &
\verb|$\mathcal{XYZ}$| & $\cmmathcal{XYZ}$
\\\bottomrule
\end{tabular}
\end{table}

The calligraphic fonts via \glsni{mathcal} are only available for upper-case 
characters\faq{Better script fonts for maths}{scriptfonts}.
\tableref{tab:amsmathfont} lists additional font commands supplied 
with the \isty{amsmath} and \isty{amsfonts} 
\htmlref{packages}{sec:packages}.

\begin{table}[hbtp]
\caption[The amsfonts and amsmath Font Commands]{The 
\isty{amsfonts}\supddag\ and \isty{amsmath}\supdag\ Font Commands}
\label{tab:amsmathfont}
\centering
\begin{tabular}{lll}
\toprule
\bfseries Command & \bfseries Example Input & \bfseries Example Output\\
\midrule
\begin{inlinedef}\supddag\gls{mathbb}\marg{\meta{maths}}\end{inlinedef} &
\verb|$\mathbb{A+B=C}$| & $\mathbb{A+B=C}$\\
\begin{inlinedef}\supddag\gls{mathfrak}\marg{\meta{maths}}\end{inlinedef} &
\verb|$\mathfrak{A+B=C}$| & $\mathfrak{A+B=C}$\\
\begin{inlinedef}\supdag\gls{boldsymbol}\marg{\meta{maths}}\end{inlinedef} &
\verb|$\boldsymbol{A+B=C}$| & $\boldsymbol{A+B=C}$\\
\begin{inlinedef}\supdag\gls{pmb}\marg{\meta{symbol}}\end{inlinedef} &
\verb|$\pmb{+-=}$| & $\pmb{+-=}$
\\\bottomrule
\end{tabular}
\end{table}

%----------------- Greek Letters -----------------------

\setnode{greek}
\subsection{Greek Letters}
\label{sec:greek}

Greek letters that differ from the corresponding Roman letters are
obtained by placing a backslash in front of the name.\footnote{So,
for example, there is no omicron since it looks the same as a Roman
o.} Lower case and upper case Greek letters are shown in
\tableref{tab:greek} and \tableref{tab:Greek}, respectively. There are
also some variants of certain symbols, such as \glsni{vartheta} as
opposed to \glsni{theta}.

\begin{table}[htbp]
\caption{Lower Case Greek Letters}
\label{tab:greek}
\centering
\begin{tabular}{llllll}
\gls{alpha} & $\alpha$ &
\gls{beta} & $\beta$ &
\gls{gamma} & $\gamma$ \\
\gls{delta} & $\delta$  &
\gls{epsilon} & $\epsilon$ &
\gls{varepsilon} & $\varepsilon$\\
\gls{zeta} & $\zeta$ &
\gls{eta} & $\eta$ &
\gls{theta} & $\theta$ \\
\gls{vartheta} & $\vartheta$ &
\gls{iota} & $\iota$ & 
\gls{kappa} & $\kappa$ \\
\gls{lambda} & $\lambda$ &
\gls{mu} & $\mu$ &
\gls{nu} & $\nu$ \\
\gls{xi} & $\xi$ &
\gls{pi} & $\pi$ &
\gls{varpi} & $\varpi$\\
\gls{rho} & $\rho$ &
\gls{varrho} & $\varrho$ &
\gls{sigma} & $\sigma$ \\
\gls{varsigma} & $\varsigma$ &
\gls{tau} & $\tau$ &
\gls{upsilon} & $\upsilon$ \\
\gls{phi} & $\phi$ &
\gls{varphi} & $\varphi$ &
\gls{chi} & $\chi$ \\
\gls{psi} & $\psi$ &
\gls{omega} & $\omega$ 
\end{tabular}
\end{table}

\begin{table}[htbp]
\caption{Upper Case Greek Letters}
\label{tab:Greek}
\centering
\begin{tabular}{llllll}
\gls{Gamma} & $\Gamma$ &
\gls{Delta} & $\Delta$ &
\gls{Theta} & $\Theta$ \\
\gls{Lambda} & $\Lambda$ &
\gls{Xi} & $\Xi$ &
\gls{Pi} & $\Pi$ \\
\gls{Sigma} & $\Sigma$ &
\gls{Upsilon} & $\Upsilon$ &
\gls{Phi} & $\Phi$ \\
\gls{Psi} & $\Psi$ &
\gls{Omega} & $\Omega$
\end{tabular}
\end{table}

\xminisec{Example:}

The following code
\begin{codeS}
\glsni{begindispmath} x' = x + \glsni{Delta} x \glsni{enddispmath}
\end{codeS}
produces:
\begin{resultS}[x prime equals x plus capital Delta x]
\[ x' = x + \Delta x \]
\end{resultS}

%------------- Subscripts and Superscripts ------------

\setnode{subsupscripts}
\subsection{Subscripts and Superscripts}
\label{sec:scripts}

Subscripts are obtained either by the command
\begin{definition}
\gls{sb}\marg{\meta{maths}}
\end{definition}%
or by the \htmlref{special character}{sec:chars}:
\begin{definition}
\gls{underscorechar}\marg{\meta{maths}}
\end{definition}%
Superscripts are obtained either by the command
\begin{definition}
\gls{sp}\marg{\meta{maths}}
\end{definition}%
or by the special character:
\begin{definition}
\gls{circumchar}\marg{\meta{maths}}
\end{definition}%

\xminisec{Examples:}
\begin{enumerate}
\item  This example uses \glsni{sb} and \glsni{sp}:
\begin{codeS}
\glsni{begindispmath}y = x\glsni{sb}\marg{1}\glsni{sp}\marg{2} +
x\glsni{sb}\marg{2}\glsni{sp}\marg{2}\glsni{enddispmath}
\end{codeS}%

\item This example uses \glsni{underscorechar} and \glsni{circumchar}
\begin{codeS}
\glsni{begindispmath}y = x\glsni{underscorechar}\marg{1}\glsni{circumchar}\marg{2}
 + x\glsni{underscorechar}\marg{2}\glsni{circumchar}\marg{2}\glsni{enddispmath}
\end{codeS}%

\item Recall from 
\latexhtml{page~\pageref{itm:argnogrp}}{\htmlref{earlier}{itm:argnogrp}} that
\glspl{mandatory} only consisting of one
character don't need to be grouped, so the above code can also be
written as:
\begin{codeS}
\glsni{begindispmath}y = x\glsni{underscorechar}1\glsni{circumchar}2 
 + x\glsni{underscorechar}2\glsni{circumchar}2\glsni{enddispmath}
\end{codeS}%
This is simpler than the first two examples. However it's a good idea to be in the
habit of always using braces in case you forgot them when they're
needed.
\end{enumerate}
All three of the above examples produce the same output:
\begin{resultS}[subsup.html]
\[y = x_1^2 + x_2^2\]
\end{resultS}%

Notice how the subscript gets tucked under the slope of the $Y$ in:
\begin{codeS}
\glsni{begindispmath}
Y\glsni{underscorechar}\marg{1}\glsni{circumchar}\marg{2}
\glsni{enddispmath}
\end{codeS}
\begin{resultS}[ysubsup1.html]
\[ Y_{1}^{2} \]
\end{resultS}
Compare with
\begin{codeS}
\glsni{begindispmath}
Y\marg{}\glsni{underscorechar}\marg{1}\glsni{circumchar}\marg{2}
\glsni{enddispmath}
\end{codeS}
\begin{resultS}[ysubsup2.html]
\[ Y{}_{1}^{2} \]

\end{resultS}

\xminisec{Example (Nested)}

Subscripts and superscripts can also be nested (note that
it is now necessary to group the argument to the superscript command):
\begin{codeS}
\glsni{begindispmath}
 f(x) = e\glsni{circumchar}\marg{x\glsni{underscorechar}1}
\glsni{enddispmath}
\end{codeS}%
which produces
\begin{resultS}[nestedsup.html]
\[
f(x) = e^{x_1}
\]
\end{resultS}

This example isn't quite right as e isn't actually a variable
and shouldn't be typeset in italic.  The correct way to do this
is:\bookpagebreak
\begin{codeS}
\glsni{begindispmath}
 f(x) =
\gls{mathrm}\marg{e}\glsni{circumchar}\marg{x\glsni{underscorechar}1}
\glsni{enddispmath}
\end{codeS}%
which results in:
\begin{resultS}[Image: as above but the letter e is upright]
\[ f(x) = \mathrm{e}^{x_1} \]
\end{resultS}

\refstepcounter{object}\label{obj:e}If you are going to use e a lot,
it will be simpler to \htmlref{define a new command}{ch:newcom} to do
this. The definition should go in the
\glsterm{preamble}:
\begin{codeS}
\gls{newcommand}\marg{\cmdname{e}}\marg{\glsni{mathrm}\marg{e}}
\end{codeS}%
Then in the document:
\begin{codeS}
\glsni{begindispmath} f(x\glsni{underscorechar}1, x\glsni{underscorechar}2) 
 = \cmdname{e}\glsni{circumchar}\marg{x\glsni{underscorechar}1\glsni{circumchar}2} 
  +
\cmdname{e}\glsni{circumchar}\marg{x\glsni{underscorechar}2\glsni{circumchar}2}
\glsni{enddispmath}
\end{codeS}%
\begin{resultS}[nestedsup2.html]
\[
f(x_1, x_2) = \e^{x_1^2} + \e^{x_2^2}
\]
\end{resultS}

Take care when nesting subscripts or superscripts. The following
\begin{alltt}\wrong
x\glsni{underscorechar}1\glsni{underscorechar}2
\end{alltt}
will give a \texttt{!\ Double subscript} error.

%-------------- Functional Names --------------

\setnode{functionnames}
\subsection{Functional Names}
\label{sec:funcnames}

Functions such as log and tan can't simply be typed in as
\texttt{log} or \texttt{tan} otherwise they will come out looking
like the variables \mathorit{l} times
\mathorit{o} times \mathorit{g} (\makeimg{l o g}{$ l o g$})
or \mathorit{t} times \mathorit{a} times \mathorit{n} 
(\makeimg{t a n}{$ t a n$}).  Instead you should use
one of the commands listed in \tableref{tab:fnnames}.
The functions denoted with \supdag\ can have limits by using
the subscript command \gls{underscorechar} or the superscript command \gls{circumchar}\faq{Sub- and
superscript positioning for operators}{limits}.
In addition, the modulo commands listed in \tableref{tab:mod} are also available.

\begin{table}[bhtp]
\caption[Function Names]{Function Names (\supdag
indicates command may have limits, \supddag defined
by \protect\isty{amsmath}).}
\label{tab:fnnames}
\centering
\begin{tabular}{llllll}
\gls{arccos} & $\arccos$ &
\gls{arcsin} & $\arcsin$ &
\gls{arctan} & $\arctan$ \\
\gls{arg} & $\arg$ &
\gls{cos} & $\cos$ &
\gls{cosh} & $\cosh$ \\
\gls{cot} & $\cot$ &
\gls{coth} & $\coth$ &
\gls{csc} & $\csc$ \\
\gls{deg} & $\deg$ &
\gls{det}\supdag & $\det$ &
\gls{dim} & $\dim$ \\
\gls{exp} & $\exp$ &
\gls{gcd}\supdag & $\gcd$ &
\gls{hom} & $\hom$ \\
\gls{inf}\supdag & $\inf$ &
\gls{injlim}\supdagddag & $\injlim$ &
\gls{ker} & $\ker$ \\
\gls{lg} &  $\lg$ &
\gls{lim}\supdag & $\lim$ &
\gls{liminf}\supdag & $\liminf$ \\
\gls{limsup}\supdag & $\limsup$ &
\gls{ln} & $\ln$ &
\gls{log} & $\log$ \\
\gls{max}\supdag &  $\max$ &
\gls{min}\supdag & $\min$ &
\gls{Pr}\supdag & $\Pr$ \\
\gls{projlim}\supdagddag & $\projlim$ &
\gls{sec} & $\sec$ &
\gls{sin} & $\sin$ \\
\gls{sinh} & $\sinh$ &
\gls{sup}\supdag & $\sup$ &
\gls{tan} & $\tan$ \\
\gls{tanh} & $\tanh$ &
\gls{varinjlim}\supdagddag & $\varinjlim$ &
\gls{varliminf}\supdagddag & $\varliminf$ \\
\gls{varlimsup}\supdagddag & $\varlimsup$ &
\gls{varprojlim}\supdagddag &  $\varprojlim$ &
\end{tabular}
\end{table}

\begin{table}[htbp]
\caption[Modulo Commands]{Modulo Commands (\supddag
defined by \protect\isty{amsmath} package)}
\label{tab:mod}
\centering
\begin{tabular}{lll}
\toprule
\bfseries Command & \bfseries Example Input & \bfseries Example Output\\
\midrule
\gls{bmod} & \verb|$m \bmod n$| & $m \bmod n$\\
\gls{pmod}\marg{\meta{maths}} & \verb|$m \pmod{n}$| &$m \pmod{n}$\\
\gls{mod}\marg{\meta{maths}}\supddag & \verb|$m \mod{n}$| &$m \mod{n}$\\
\gls{pod}\marg{\meta{maths}}\supddag & \verb|$m \pod{n}$| &$m \pod{n}$
\\\bottomrule
\end{tabular}
\end{table}

\xminisec{Example (Trigonometric Functions):}

This example uses the cos and sin functions and also the 
\htmlref{Greek letter}{sec:greek} theta.
\begin{codeS}
\glsni{begindispmath} z = r(\glsni{cos}\glsni{theta} + i\glsni{sin}\glsni{theta})
\glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: z equals r (cos theta plus i sign theta)]
\[
z = r(\cos\theta + i\sin\theta)
\]
\end{resultS}

\xminisec{Example (Limit):}

The command \gls{infty} is the 
infinity symbol \makeimg{image of infinity symbol}{$\infty$}, and the command \gls{to} displays an 
arrow pointing to the right.  Note the use of \gls{underscorechar} since the
limit is a subscript.
\begin{codeS}
\glsni{begindispmath}
  \glsni{lim}\glsni{underscorechar}\marg{x\glsni{to}\glsni{infty}} f(x) 
\glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: limit as x tends to infinity of f of x]
\[
\lim_{x\to\infty} f(x)
\]
\end{resultS}%
The operators with limits behave differently depending on whether
they are in \htmlref{displayed}{sec:displayed} or 
\htmlref{in-line}{sec:inline} maths.
Notice the difference when the same code appears in-line:
\begin{codeS}
In a line of text 
\glsni{dollarchar}\glsni{lim}\glsni{underscorechar}\marg{x\glsni{to}\glsni{infty}}
f(x)\glsni{dollarchar}
\end{codeS}%
which now displays as:
\begin{resultS}[Image: the limit appears to the side of lim instead
of below it.]
In a line of text $\lim_{x\to\infty} f(x)$
\end{resultS}

\xminisec{Example (With Subscript):}

This is another example of a functional name using a subscript:
\begin{codeS}
\glsni{begindispmath} \glsni{min}\glsni{underscorechar}x f(x) \glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: the x appears below the word min.]
\[
\min_x f(x)
\]
\end{resultS}%
Again, notice the difference when it is used in-line:
\begin{codeS}
In a line of text \glsni{dollarchar}\glsni{min}\glsni{underscorechar}x 
f(x)\glsni{dollarchar}
\end{codeS}%
\begin{resultS}[Image: the x appears to the side of the word min.]
In a line of text $\min_x f(x)$
\end{resultS}
\bookpagebreak

\setnode{declaremathop}
\subsubsection{Defining New Functional Operators}
\label{sec:declaremathop}

It may be that you want a function that isn't specified in
\tableref{tab:fnnames}. In this case, the \isty{amsmath} provides the
\textbf{\em \gls{preamble} only} command
\begin{definition}
\gls{DeclareMathOperator}\marg{\meta{cmd}}\marg{\meta{operator
name}}
\end{definition}
or its \htmlref{starred variant}{itm:starredcommand}
\begin{definition}
\glsni{DeclareMathOperator}*\marg{\meta{cmd}}\marg{\meta{operator
name}}
\end{definition}
\faq{Defining a new log-like function in LaTeX}{newfunction}%
Both versions define a command called \meta{cmd}, which must start
with a backslash, that typesets \meta{operator name} as a function
name.  The starred version is for function names that can take
limits (like \gls{lim} and \gls{min} described above).

\xminisec{Example (Operator Without Limits):}

Suppose I want a function called card, which represents the
cardinality of a set $\mathcal{S}$. First I~need to define the new
operator command (which I'm going to call \cmdname{card}) \emph{in
the \gls{preamble}}:
\begin{codeS}
\glsni{DeclareMathOperator}\marg{\cmdname{card}}\marg{card}
\end{codeS}
This operator doesn't take any limits, so I~have used the unstarred
version.

Later in the document, I~can use this new operator command:
\begin{codeS}
\glsni{begindispmath} n = \cmdname{card}(\glsni{mathcal}\marg{S}) \glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: n equals card (S)]
\[
n = \card(\mathcal{S})
\]
\end{resultS}%
In this example \gls{mathcal} is used as sets are
typically represented in a calligraphic font.

\xminisec{Example (Operator With Limits):}

Suppose I~now want a function called mode, which represents the
mode of a set of numbers. First, I~define the operator command in the
preamble:
\begin{codeS}
\glsni{DeclareMathOperator}*\marg{\cmdname{mode}}\marg{mode}
\end{codeS}
This operator needs to be able to have a subscript, so I~have used
the starred version.

Later in the document, I~can use this new operator command:
\begin{codeS}
\glsni{begindispmath} x\glsni{underscorechar}m = 
\cmdname{mode}\glsni{underscorechar}\marg{x \glsni{in} \glsni{mathcal}\marg{S}}(x)
\glsni{enddispmath}
\end{codeS}
\begin{resultS}[Image: x subscript m equals mode of x in S of x]
\[
x_m = \mode_{x \in \mathcal{S}}(x)
\]
\end{resultS}

%----------- Fractions ------------

\bookpagebreak
\setnode{fractions}
\subsection{Fractions}
\label{sec:fractions}

Fractions are created using the command
\begin{definition}
\gls{frac}\marg{\meta{numerator}}\marg{\meta{denominator}}
\end{definition}
The \isty{amsmath} package also provides the command
\begin{definition}
\gls{cfrac}\oarg{\meta{pos}}\marg{\meta{numerator}}\marg{\meta{denominator}}
\end{definition}
which is designed for continued fractions. The optional argument
\texttt{pos} can be used for left (\texttt{l}) or right (\texttt{r})
placement of any of the numerators. (The default is centred.)

\xminisec{Example:}

A simple fraction:
\begin{codeS}
\glsni{begindispmath} 
 \glsni{frac}\marg{1}\marg{1+x} 
\glsni{enddispmath}
\end{codeS}
Produces:
\begin{resultS}[Image of fraction with 1 as the numerator and 1+x as
the denominator.]
\[ \frac{1}{1+x} \]
\end{resultS}
Compare with:
\begin{codeS}
In-line:
\glsni{dollarchar} 
 \glsni{frac}\marg{1}\marg{1+x} 
\glsni{dollarchar}
\end{codeS}
which produces:
\begin{resultS}[Image: as before but fraction is smaller.]
In-line: $\frac{1}{1+x}$
\end{resultS}

\xminisec{Example (Nested):}
\begin{codeS}
\glsni{begindispmath} 
\glsni{frac}\marg{1+\glsni{frac}\marg{1}\marg{x}}\marg{1+x+x\glsni{circumchar}2}
\glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image of fraction with (1+1/x) as the numerator and
(1 + x + x squared as the denominator.]
\[
\frac{1+\frac{1}{x}}{1+x+x^2}
\]
\end{resultS}

\xminisec{Example (Continued Fraction);}
A continued fraction (example taken from \isty{amsmath}
documentation and uses \glsni{sqrt}, described in \sectionref{sec:roots},
and \glsni{dotsb}, described in
\sectionref{sec:mathssym}):
\begin{code}
\begin{alltt}
\glsni{begindispmath}
\glsni{cfrac}\marg{1}\marg{\glsni{sqrt}\marg{2}+
\glsni{cfrac}\marg{1}\marg{\glsni{sqrt}\marg{2}+
\glsni{cfrac}\marg{1}\marg{\glsni{sqrt}\marg{2}+\glsni{dotsb}
}}}
\glsni{enddispmath}
\end{alltt}
\end{code}\screenpagebreak
\begin{result}[Image of a continued fraction (the denominator has a
fraction with a fraction in its denominator etc).]
\[
\cfrac{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+\dotsb
}}}
\]
\end{result}

\xminisec{Example (A Derivative):}
\begin{codeS}
\glsni{begindispmath} f'(x) = \glsni{frac}\marg{df}\marg{dx} \glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: f'(x) = d f by d x]
\[
f'(x) = \frac{df}{dx}
\]
\end{resultS}%
As with \dq{e}, the differential operator \dq{d} should
be in an upright font as it is not a variable:
\begin{code}
\begin{alltt}
\glsni{begindispmath}
  f'(x) = \glsni{frac}\marg{\glsni{mathrm}\marg{d}f}\marg{\glsni{mathrm}\marg{d}x}
\glsni{enddispmath}
\end{alltt}
\end{code}%
\begin{resultS}[Image: as above but the letter d is upright]
\[
f'(x) = \frac{\mathrm{d}f}{\mathrm{d}x}
\]
\end{resultS}

The above example is rather cumbersome, particularly
if you have a lot of derivatives, so it might be easier to
\htmlref{define a new command}{ch:newcom}\latex{ (see \chapterref{ch:newcom})}. In the 
\glsterm{preamble} define:
\begin{codeS}
\gls{newcommand}\marg{\cmdname{deriv}}\oarg{2}\marg{\glsni{frac}\marg{\glsni{mathrm}\marg{d}\glsni{hashchar}1}\marg{\glsni{mathrm}\marg{d}\glsni{hashchar}2}}
\end{codeS}%
Then in the document:
\begin{codeS}
\glsni{begindispmath} f'(x) = \cmdname{deriv}\marg{f}\marg{x} \glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: same as before]
\newcommand{\deriv}[2]{\frac{\mathrm{d}#1}{\mathrm{d}#2}}

\[ f'(x) = \deriv{f}{x} \]
\end{resultS}

\xminisec{Example (Partial Derivative):}
\label{itm:pderiv}%

Partial derivatives can be obtained similarly
using the command \gls{partial} to display the partial
derivative symbol. As in the previous example, first define a new
command to format a partial derivative in the
\glsterm{preamble}:
\begin{codeS}
\gls{newcommand}\marg{\cmdname{pderiv}}\oarg{2}\marg{\glsni{frac}\marg{\glsni{partial} \glsni{hashchar}1}{\glsni{partial} \glsni{hashchar}2}}
\end{codeS}%
Then in the document:
\begin{codeS}
\glsni{begindispmath} f\glsni{underscorechar}x = \cmdname{pderiv}\marg{f}\marg{x} \glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: f subscript x = partial d f by partial d x]
\[
f_x = \pderiv{f}{x}
\]
\end{resultS}

\xminisec{Example (Double Partial Derivative):}

\begin{code}
\begin{alltt}
\glsni{begindispmath}
  f\glsni{underscorechar}\marg{xy} = \glsni{frac}\marg{\glsni{partial}\glsni{circumchar}2 f}\marg{\glsni{partial} x \glsni{partial} y}
\glsni{enddispmath}
\end{alltt}
\end{code}%
\begin{resultS}[Image: f subscript xy = partial d 2 f by partial d x partial d y.]
\[
f_{xy} = \frac{\partial^2 f}{\partial x \partial y}
\]
\end{resultS}

\xminisec{Example (First principles):}
\begin{code}
\glsni{begindispmath}\newline
\mbox{}\qquad f'(x) = \gls{lim}\gls{underscorechar}\marg{\gls{Delta} x \gls{to}
0}\newline
\mbox{}\qquad \glsni{frac}\marg{f(x + \gls{Delta} x)-f(x)}\marg{\gls{Delta}
x}\newline
\glsni{enddispmath}
\end{code}
\begin{resultS}
\[
f'(x) = \lim_{\Delta x\to0}
  \frac{f(x+\Delta x) - f(x)}{\Delta x}
\]
\end{resultS}

%------------ Roots --------------

\setnode{roots}
\subsection{Roots}
\label{sec:roots}

Roots are obtained using the command
\begin{definition}
\gls{sqrt}\oarg{\meta{order}}\marg{\meta{maths}}
\end{definition}%
without the optional argument \meta{order}
it will produce a simple square root. Cubic roots etc
can be obtained using the optional argument.

\xminisec{Examples:}

\begin{enumerate}
\item A square root:
\begin{codeS}
\glsni{begindispmath} \glsni{sqrt}\marg{a+b} \glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: square root of (a + b)]
\[
\sqrt{a+b}
\]
\end{resultS}

\item A cubic root:
\begin{codeS}
\glsni{begindispmath} \glsni{sqrt}\oarg{3}\marg{a+b} \glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: cubic root of (a + b)]
\[
\sqrt[3]{a+b}
\]
\end{resultS}

\item An \ensuremath{n}th root:
\begin{codeS}
\glsni{begindispmath} \glsni{sqrt}\oarg{n}\marg{a+b} \glsni{enddispmath}
\end{codeS}%
\begin{resultS}[Image: the nth root of (a + b)]
\[
\sqrt[n]{a+b}
\]
\end{resultS}
\end{enumerate}

%-------- Mathematical Symbols -------------

\setnode{mathssym}
\subsection{Mathematical Symbols}
\label{sec:mathssym}

Relational symbols\faq{Where can I find the symbol for
\ldots}{symbols} are shown in \tableref{tab:relsym}.  If you want a
negation that is not shown, you can obtain it by preceding the
symbol with the command \gls{not}.  For example:
\glsni{not}\glsni{subset} produces the symbol 
\makeimg{image of subset symbol with slash through it}{$\not\subset$}.

\begin{table}[hbtp]
\caption{Relational Symbols}
\label{tab:relsym}
\centering
\begin{tabular}{llllll}
\gls{approx} & $\approx$ &
\gls{asymp} & $\asymp$ &
\gls{bowtie} & $\bowtie$ \\
\gls{cong} & $\cong$ &
\gls{dashv} & $\dashv$ &
\gls{doteq} & $\doteq$ \\
\gls{equiv} & $\equiv$ &
\gls{frown} & $\frown$ &
\gls{ge} or \gls{geq} & $\geq$ \\
\gls{gg} & $\gg$ &
\gls{in} & $\in$ &
\gls{le} or \gls{leq} & $\leq$ \\
\gls{ll} & $\ll$ &
\gls{mid} or \verb"|" & $\mid$ &
\gls{models} & $\models$ \\ 
\gls{neq} & $\neq$ &
\gls{ni} & $\ni$ &
\gls{notin} & $\notin$ \\
\gls{parallel} & $\parallel$ &
\gls{prec}& $\prec$ &
\gls{preceq}& $\preceq$ \\
\gls{perp} & $\perp$ &
\gls{propto} & $\propto$ &
\gls{sim} & $\sim$ \\
\gls{simeq} & $\simeq$ &
\gls{smile} & $\smile$ &
\gls{sqsubseteq} & $\sqsubseteq$ \\
\gls{sqsupseteq} & $\sqsupseteq$ &
\gls{subset} & $\subset$ &
\gls{subseteq} & $\subseteq$ \\
\gls{succ} & $\succ$ &
\gls{succeq} & $\succeq$ &
\gls{supset} & $\supset$ \\
\gls{supseteq} & $\supseteq$ &
\gls{vdash} & $\vdash$ &
\end{tabular}
\end{table}

Binary operator symbols are shown in \tableref{tab:binop}, and arrow
symbols are shown in \xtableref{tab:arrows}. There are also over and
under arrows (\xtableref{tab:overunderarrows}) that have an argument.
The over arrows put an extendible arrow over their argument, and the
under arrows put an extendible arrow under their argument. In
addition, the \isty{amsmath} package provides extensible arrows that
take a superscript and, optionally, a subscript:
\begin{definition}
\gls{xleftarrow}\oarg{\meta{subscript}}\marg{\meta{superscript}}
\end{definition}
\begin{definition}
\gls{xrightarrow}\oarg{\meta{subscript}}\marg{\meta{superscript}}
\end{definition}

\xminisec{Example:}
\begin{code}
\glsni{begindispmath}\newline
\mbox{}\qquad  A \glsni{xleftarrow}\marg{n+m-p} B  
 \glsni{xrightarrow}\oarg{X}\marg{n+p} C\newline
\glsni{enddispmath}
\end{code}
\begin{result}[Image of result: the arrow subscripts and superscript are centred over the arrow.]
\[
  A \xleftarrow{n+m-p} B \xrightarrow[X]{n+p} C
\]
\end{result}

\begin{table}[tbhp]
\caption{Binary Operator Symbols}
\label{tab:binop}
\centering
\begin{tabular}{llllll}
\gls{amalg} & $\amalg$ &
\gls{ast} & $\ast$ &
\gls{bullet} & $\bullet$ \\
\gls{bigcirc} & $\bigcirc$ &
\gls{bigtriangledown} & $\bigtriangledown$ &
\gls{bigtriangleup} & $\bigtriangleup$ \\
\gls{cap} & $\cap$ &
\gls{cdot} & $\cdot$ &
\gls{circ} & $\circ$ \\
\gls{cup} & $\cup$ &
\gls{dagger} & $\dagger$ &
\gls{ddagger} & $\ddagger$ \\
\gls{diamond} & $\diamond$ &
\gls{div} & $\div$ &
\gls{mp} & $\mp$ \\
\gls{odot} & $\odot$ &
\gls{ominus} & $\ominus$ &
\gls{oplus} & $\oplus$ \\
\gls{oslash} & $\oslash$ &
\gls{otimes} & $\otimes$ &
\gls{pm} & $\pm$ \\
\gls{setminus} & $\setminus$ &
\gls{sqcap} & $\sqcap$ &
\gls{sqcup} & $\sqcup$ \\
\gls{star} & $\star$ &
\gls{times} & $\times$ &
\gls{triangleleft} & $\triangleleft$ \\
\gls{triangleright} & $\triangleright$ &
\gls{uplus} & $\uplus$ &
\gls{vee} & $\vee$ \\
\gls{wedge} & $\wedge$ &
\gls{wr} & $\wr$
\end{tabular}
\end{table}

\begin{table}[tbhp]
\caption{Arrow Symbols}
\label{tab:arrows}
\centering
\begin{tabular}{llll}
\gls{downarrow} & $\downarrow$ &
\gls{Downarrow} & $\Downarrow$ \\
\gls{hookleftarrow} & $\hookleftarrow$ &
\gls{hookrightarrow} & $\hookrightarrow$ \\
\gls{leftarrow} or \gls{gets} & $\leftarrow$ &
\gls{Leftarrow} & $\Leftarrow$ \\
\gls{leftharpoondown} & $\leftharpoondown$ &
\gls{leftharpoonup} & $\leftharpoonup$ \\
\gls{leftrightarrow} & $\leftrightarrow$ &
\gls{Leftrightarrow} & $\Leftrightarrow$ \\
\gls{longleftarrow} & $\longleftarrow$ &
\gls{Longleftarrow} & $\Longleftarrow$ \\
\gls{longleftrightarrow} & $\longleftrightarrow$ &
\gls{Longleftrightarrow} & $\Longleftrightarrow$ \\
\gls{longmapsto} & $\longmapsto$ &
\gls{longrightarrow} & $\longrightarrow$ \\
\gls{Longrightarrow} & $\Longrightarrow$ &
\gls{mapsto} & $\mapsto$ \\
\gls{nearrow} & $\nearrow$ &
\gls{nwarrow} & $\nwarrow$ \\
\gls{rightarrow} or \gls{to} & $\to$ &
\gls{Rightarrow} & $\Rightarrow$ \\
\gls{rightharpoondown} & $\rightharpoondown$ &
\gls{rightharpoonup} & $\rightharpoonup$ \\
\gls{rightleftharpoons} & $\rightleftharpoons$ &
\gls{searrow} & $\searrow$ \\
\gls{swarrow} & $\swarrow$ &
\gls{uparrow} & $\uparrow$ \\
\gls{Uparrow} & $\Uparrow$ &
\gls{updownarrow} & $\updownarrow$ \\
\gls{Updownarrow} & $\Updownarrow$ &
\end{tabular}
\end{table}

\begin{table}[htbp]
\caption[Over and Under Arrows]{Over and Under Arrows
(\supdag defined by \protect\isty{amsmath})}
\label{tab:overunderarrows}
\centering
\begin{tabular}{@{}lll@{}}
\toprule
\bfseries Definition & \multicolumn{2}{c}{\bfseries Example}\\
\midrule
\begin{inlinedef}\gls{overleftarrow}\marg{\meta{maths}}\end{inlinedef}
  & \verb|\overleftarrow{ABC}| & $\overleftarrow{ABC}$\\
\begin{inlinedef}\gls{overrightarrow}\marg{\meta{maths}}\end{inlinedef}
  & \verb|\overrightarrow{ABC}| & $\overrightarrow{ABC}$\\
\begin{inlinedef}\gls{overleftrightarrow}\marg{\meta{maths}}\end{inlinedef}\supdag
  & \verb|\overleftrightarrow{ABC}| & $\overleftrightarrow{ABC}$\\
\begin{inlinedef}\gls{underleftarrow}\marg{\meta{maths}}\end{inlinedef}\supdag
  & \verb|\underleftarrow{ABC}| & $\underleftarrow{ABC}$\\
\begin{inlinedef}\gls{underrightarrow}\marg{\meta{maths}}\end{inlinedef}\supdag
  & \verb|\underrightarrow{ABC}| & $\underrightarrow{ABC}$\\
\begin{inlinedef}\gls{underleftrightarrow}\marg{\meta{maths}}\end{inlinedef}\supdag
  & \verb|\underleftrightarrow{ABC}| & $\underleftrightarrow{ABC}$
\\\bottomrule
\end{tabular}
\end{table}

\bookpagebreak
\begin{table}[htbp]
\caption{Symbols with Limits}
\label{tab:symlim}
\centering
\begin{tabular}{llllll}
\gls{sum} & $\sum$ &
\gls{int} & $\int$ &
\gls{oint} & $\oint$ \\[5pt]
\gls{prod} & $\prod$ &
\gls{coprod} & $\coprod$ &
\gls{bigcap} & $\bigcap$ \\[5pt]
\gls{bigcup} & $\bigcup$ &
\gls{bigsqcup} & $\bigsqcup$ &
\gls{bigvee} & $\bigvee$ \\[5pt]
\gls{bigwedge} & $\bigwedge$ &
\gls{bigodot} & $\bigodot$ &
\gls{bigotimes} & $\bigotimes$ \\[5pt]
\gls{bigoplus} & $\bigoplus$ &
\gls{biguplus} & $\biguplus$
\end{tabular}
\end{table}

Symbols that can have limits are shown in \tableref{tab:symlim}.
The size of these symbols depends on whether they are in displayed 
maths or in-line maths. 

\xminisec{Example (Displayed Summation and Product):}

The limits of summations and products are placed above and below the
symbol in displayed maths:
\begin{code}
\begin{alltt}
\glsni{begindispmath}
  f(x) = \glsni{sum}\glsni{underscorechar}\marg{i=1}\glsni{circumchar}\marg{n} x\glsni{underscorechar}i + \glsni{prod}\glsni{underscorechar}\marg{i=1}\glsni{circumchar}\marg{n} x\glsni{underscorechar}i
\glsni{enddispmath}
\end{alltt}
\end{code}
\begin{resultS}[Image: f(x) = sum from i equals 1 to n x subscript i
+ product from i equals 1 to n x subscript i.]
\[
f(x) = \sum_{i=1}^{n} x_i + \prod_{i=1}^{n} x_i
\]
\end{resultS}

\xminisec{Example (In-line Summation and Product):}

The limits of summations and products are placed to the right of the
symbol in in-line maths:
\begin{code}
\begin{alltt}
In a line of text:
\glsni{begin}\marg{math}
  f(x) = \glsni{sum}\glsni{underscorechar}\marg{i=1}\glsni{circumchar}\marg{n} x\glsni{underscorechar}i + \glsni{prod}\glsni{underscorechar}\marg{i=1}\glsni{circumchar}\marg{n} x\glsni{underscorechar}i
\glsni{end}\marg{math}
\end{alltt}
\end{code}
\begin{resultS}[Image: as before but summation and product symbols
are smaller and limits are to the side instead of above and below]
In a line of text:
\begin{math}
f(x) = \sum_{i=1}^{n} x_i + \prod_{i=1}^{n} x_i
\end{math}
\end{resultS}

\xminisec{Multiline Sub- or Superscripts}

The \isty{amsmath} package provides the command:
\begin{definition}
\gls{substack}\marg{\meta{maths}}
\end{definition}
which can be used for multiline sub- or superscripts. Within the
argument \meta{maths} use \gls{tab.dbbackslashchar} to separate
rows. For example:
\begin{code}
\glsni{begindispmath}\newline
\strut~\glsni{sum}\glsni{underscorechar}\marg{\newline
\strut~~\glsni{substack}\newline
\strut~~\marg{\newline
\strut~~~~i \glsni{in}
\glsni{mathcal}\marg{I}\glsni{tab.dbbackslashchar}\newline
\strut~~~~i \glsni{neq} 0\newline
\strut~~}\newline
\strut~}\newline
\strut~x\glsni{underscorechar}i\newline
\glsni{enddispmath}
\end{code}
\begin{result}[substack.html]
\[
 \sum_{
   \substack
   {
     i \in \mathcal{I}\\
     i \neq 0
   }
 }
 x_i
\]
\end{result}

\setnode{ellipses}
\subsection{Ellipses}
\label{sec:ellipses}

Ellipsis (omission mark)\index{ellipses (omission marks)|hyperpage} commands are 
shown in \tableref{tab:ellipsis}. The \isty{amsmath} package also
provides: \glsni{dotsc} for dots with commas, \glsni{dotsb} for dots
with binary operators/relations, \glsni{dotsm} for multiplication
dots, \glsni{dotsi} for dots with integrals and \glsni{dotso} for other
dots, which can be used as replacements for \glsni{ldots} and
\glsni{cdots}.

\begin{table}[hbtp]
\caption[Ellipses]{Ellipses (\supdag\ provided by \sty{amsmath}
package)}
\label{tab:ellipsis}
\centering
\begin{tabular}{ll@{\hspace{4\tabcolsep}}ll@{\hspace{4\tabcolsep}}llllll}
\gls{vdots} & $\vdots$ &
\gls{cdots} & $\cdots$ &
\gls{dotsb}\supdag & $\dotsb$ &
\gls{dotsi}\supdag & $\dotsi$ &
\gls{dotsm}\supdag & $\dotsm$\\
\gls{ddots} & $\ddots$ &
\gls{ldots} & $\ldots$ &
\gls{dotsc}\supdag & $\dotsc$ &
\gls{dotso}\supdag & $\dotso$ 
\end{tabular}
\end{table}

\xminisec{Example (Low Ellipsis):}

This example uses the command 
\refstepcounter{object}\label{cmd:forall}\gls{forall} to produce
the \dq{for all} symbol $\forall$, and it also uses 
\glsni{spacesym} (backslash space) to make a space before the for all symbol. The
\isty{amsmath} \dq{dots with commas} ellipsis \glsni{dotsc} is used rather
than the standard \glsni{ldots}:
\begin{code}
\begin{alltt}
\glsni{begindispmath}
a\glsni{underscorechar}ix\glsni{underscorechar}i = b\glsni{underscorechar}i\glsni{spacesym}\glsni{forall} i = 1,\glsni{dotsc}, n
\glsni{enddispmath}
\end{alltt}
\end{code}%
\begin{resultS}[forall.html]
\[
a_ix_i = b_i\ \forall i = 1,\dotsc, n
\]
\end{resultS}

\xminisec{Example (Centred ellipsis):}

This example uses the \isty{amsmath} \dq{dots with binary operators\slash relations}
\glsni{dotsb} instead of the standard \glsni{cdots}:
\begin{code}
\begin{alltt}
\glsni{begindispmath}
y = a\glsni{underscorechar}1 + a\glsni{underscorechar}2 + \glsni{dotsb} + a\glsni{underscorechar}n 
\glsni{enddispmath}
\end{alltt}
\end{code}%
\begin{resultS}[cdots.html]
\[
y = a_1 + a_2 + \dotsb + a_n 
\]
\end{resultS}

\begin{exercise}{Maths: Fractions and Symbols}{ex:mathssym}
This exercise uses a fraction, a square root, subscripts, 
superscripts and symbols.
Try to reproduce the following output:
\begin{result}[maths1ex.html]
The quadratic equation
\[
\sum_{i=0}^{2} a_i x^i = 0
\]
has solutions given by
\[
x = \frac{-a_1 \pm \sqrt{a_1^2 - 4 a_2 a_0}}{2a_2}
\]
\end{result}%
Again you can \downloadorview{mathssym} the solution.
\end{exercise}

%---------- Delimiters ------------

\setnode{delimiters}
\subsection{Delimiters}
\label{sec:delimiters}

Placing brackets around a tall object in maths mode, such as
fractions, does not look right if you use normal sized brackets.
For example:
\begin{code}
\glsni{begindispmath}\newline
\strut~~(\glsni{frac}\marg{1}\marg{1+x})\newline
\glsni{enddispmath}
\end{code}%
results in:
\begin{resultS}[Image: normal sized brackets around fraction.]
\[
(\frac{1}{1+x})
\]
\end{resultS}\bookpagebreak\noindent
Instead, you can automatically resize the delimiters using the
commands:
\begin{definition}
\gls{left}\meta{delimiter}
\end{definition}%
and
\begin{definition}
\gls{right}\meta{delimiter}
\end{definition}%
Rewriting the above example:
\begin{code}
\begin{alltt}
\glsni{begindispmath}
  \glsni{left}( \glsni{frac}\marg{1}\marg{1+x} \glsni{right})
\glsni{enddispmath}
\end{alltt}
\end{code}%
produces:
\begin{resultS}[Image: brackets now the same size as the fraction.]
\[
  \left( \frac{1}{1+x} \right)
\]
\end{resultS}%

Note that you must always have matching \cmdname{left} and
\cmdname{right} commands, although the delimiters used may be
different. \refstepcounter{object}\label{obj:invisdelim}If you want
one of the delimiters to be invisible, use a
\gls{delimiter.periodchar}\ (full stop) as the delimiter. Available
delimiters are shown in
\tableref{tab:delimiters}. (Note for a vertical bar
delimiter it's best to use \isty{amsmath}'s \glsni{lvert} command instead of
\gls{delim.barchar} and \glsni{lVert} instead of \gls{csbar}.) Sometimes using \glsni{left} and
\glsni{right} doesn't produce the optimal sized delimiters. In which
case you can use additional commands provided by the \isty{amsmath}
package shown in \tableref{tab:big}.

\begin{table}[hbtp]
\caption[Delimiters]{Delimiters (\supdag defined by
\protect\isty{amsmath})}
\label{tab:delimiters}
\centering
\begin{tabular}{llllllll}
\begin{inlinedef}\gls{openparen}\end{inlinedef} &
\makeimg{open round bracket}{$($} &
\begin{inlinedef}\gls{closeparen}\end{inlinedef} &
\makeimg{close round bracket}{$)$} &
\begin{inlinedef}\gls{delimiter.opensq}\end{inlinedef} & 
\makeimg{open square bracket}{$[$} &
\begin{inlinedef}\gls{delimiter.closesq}\end{inlinedef} & 
\makeimg{close square bracket}{$]$} \\
\begin{inlinedef}\gls{leftbrace}\end{inlinedef} & 
\makeimg{open curly brace}{$\{$} &
\begin{inlinedef}\gls{rightbrace}\end{inlinedef} & 
\makeimg{close curly brace}{$\}$} &
\begin{inlinedef}\gls{lvert}\supdag\end{inlinedef} & 
\makeimg{left vertical bar}{$\lvert$} &
\begin{inlinedef}\gls{rvert}\supdag\end{inlinedef} & 
\makeimg{right vertical bar}{$\rvert$} \\
\begin{inlinedef}\gls{lVert}\supdag\end{inlinedef} & 
\makeimg{left double vertical bar}{$\lVert$} &
\begin{inlinedef}\gls{rVert}\supdag\end{inlinedef} & 
\makeimg{right double vertical bar}{$\rVert$} &
\begin{inlinedef}\gls{langle}\end{inlinedef} & 
\makeimg{left angle bracket}{$\langle$} &
\begin{inlinedef}\gls{rangle}\end{inlinedef} & 
\makeimg{right angle bracket}{$\rangle$} \\
\begin{inlinedef}\gls{lfloor}\end{inlinedef} & 
\makeimg{left floor}{$\lfloor$} &
\begin{inlinedef}\gls{rfloor}\end{inlinedef} & 
\makeimg{right floor}{$\rfloor$} &
\begin{inlinedef}\gls{lceil}\end{inlinedef} & 
\makeimg{left ceiling}{$\lceil$} &
\begin{inlinedef}\gls{rceil}\end{inlinedef} & 
\makeimg{right ceiling}{$\rceil$}\\
\begin{inlinedef}\gls{uparrow}\end{inlinedef} & 
\makeimg{up arrow}{$\uparrow$} &
\begin{inlinedef}\gls{downarrow}\end{inlinedef} &
\makeimg{down arrow}{$\downarrow$} &
\begin{inlinedef}\gls{Uparrow}\end{inlinedef} & 
\makeimg{double lined up arrow}{$\Uparrow$} &
\begin{inlinedef}\gls{Downarrow}\end{inlinedef} & 
\makeimg{double lined down arrow}{$\Downarrow$}\\
\begin{inlinedef}\gls{updownarrow}\end{inlinedef} & 
\makeimg{up down arrow}{$\updownarrow$} &
\begin{inlinedef}\gls{Updownarrow}\end{inlinedef} & 
\makeimg{double lined up down arrow}{$\Updownarrow$} &
\begin{inlinedef}\gls{delim.slash}\end{inlinedef} & 
\makeimg{forward slash}{$/$} &
\begin{inlinedef}\gls{backslash}\end{inlinedef} & 
\makeimg{backslash}{$\backslash$} 
\end{tabular}
\end{table}

\begin{table}
\caption[Delimiter Sizing]{Additional Commands Provided by
\protect\isty{amsmath} for Delimiter Sizing}
\label{tab:big}
\centering
\renewcommand*{\arraystretch}{2.2}
\begin{tabular}{@{}ll@{\hspace{4\tabcolsep}}ll@{}}
\toprule
\multicolumn{2}{c@{\hspace{4\tabcolsep}}}{\bfseries Definitions} &
\multicolumn{2}{c}{\bfseries Example}\\
\midrule
\multicolumn{2}{c@{\hspace{4\tabcolsep}}}{\em Default Size} & \verb|$( X )$| & $(X)$\\
\begin{inlinedef}\gls{bigl}\meta{delim}\end{inlinedef} &
\begin{inlinedef}\gls{bigr}\meta{delim}\end{inlinedef} &
\verb|$\bigl( X \bigr)$| & 
\makeimg{(X)}{$\bigl(X\bigr)$} \\
\begin{inlinedef}\gls{Bigl}\meta{delim}\end{inlinedef} &
\begin{inlinedef}\gls{Bigr}\meta{delim}\end{inlinedef} &
\verb|$\Bigl( X \Bigr)$| & 
\makeimg{(X)}{$\Bigl(X\Bigr)$} \\
\begin{inlinedef}\gls{biggl}\meta{delim}\end{inlinedef} &
\begin{inlinedef}\gls{biggr}\meta{delim}\end{inlinedef} &
\verb|$\bigl( X \biggr)$| & 
\makeimg{(X)}{$\biggl(X\biggr)$} \\
\begin{inlinedef}\gls{Biggl}\meta{delim}\end{inlinedef} &
\begin{inlinedef}\gls{Biggr}\meta{delim}\end{inlinedef} &
\verb|$\Biggl( X \Biggr)$| & 
\makeimg{(X)}{$\Biggl(X\Biggr)$} \\
\bottomrule
\end{tabular}
\renewcommand*{\arraystretch}{1}% Keep LaTeX2HTML happy
\end{table}

\xminisec{Example (Vertical Bar Delimiters):}

\begin{code}
\glsni{begindispmath}\newline
\glsni{left}\glsni{lvert}\newline
\glsni{frac}\marg{1}\marg{1+x}\newline
\glsni{right}\glsni{rvert}\newline
\glsni{enddispmath}
\end{code}%
\begin{resultS}[Image: vertical bars same height as fraction.]
\[
\left\lvert\frac{1}{1+x}\right\rvert
\]
\end{resultS}

\xminisec{Example (Delimiter with Subscript):}

Delimiters can take limits:
\begin{code}
\glsni{begindispmath}\newline
\glsni{left}\glsni{lvert}\newline
\glsni{frac}\marg{1}\marg{1+x}\newline
\glsni{right}\glsni{rvert}\glsni{underscorechar}\marg{x=0}\newline
\glsni{enddispmath}
\end{code}\reportpagebreak
\begin{resultS}[Image: as before but the right vertical bar has a subscript.]
\[
\left\lvert\frac{1}{1+x}\right\rvert_{x=0}
\]
\end{resultS}

\xminisec{Example (Mismatch):}
The left and right delimiters don't have to match:
\begin{code}
\begin{alltt}
\glsni{begindispmath}
\glsni{left}\glsni{delimiter.opensq}\glsni{frac}\marg{1}\marg{1+x}\glsni{right}\glsni{rangle}
\glsni{enddispmath}
\end{alltt}
\end{code}%
\begin{resultS}[Image: large open square bracket followed by
fraction followed by large right angle bracket.]
\[
\left[\frac{1}{1+x}\right\rangle
\]
\end{resultS}

\xminisec{Example (An invisible delimiter):}

Every \gls{right} must have a matching \gls{left} (and vice versa), so 
use a \gls{delimiter.periodchar}\ (full stop) for an invisible
delimiter.
\begin{code}
\begin{alltt}
\glsni{begindispmath}
 \glsni{left}\glsni{delimiter.periodchar}
  \glsni{frac}\marg{\glsni{partial} f}\marg{\glsni{partial} x}
 \glsni{right}\glsni{rvert}\glsni{underscorechar}\marg{x=0}
\glsni{enddispmath}
\end{alltt}
\end{code}
\begin{resultS}[Image: partial fraction followed by large vertical
line with a subscript.]
\[
\left.
\frac{\partial f}{\partial x}
\right\rvert_{x=0}
\]
\end{resultS}

\refstepcounter{object}\label{introeq}
We have now covered enough to reproduce the equation shown in 
\chapterref{ch:intro}:
\begin{code}
\begin{alltt}
\glsni{newcommand}*\marg{\cmdname{pderiv}}\oarg{2}\marg{\glsni{frac}\marg{\glsni{partial} \glsni{hashchar}1}\marg{\glsni{partial} \glsni{hashchar}2}}
\glsni{newcommand}*\marg{\cmdname{e}}\marg{\glsni{mathrm}\marg{e}}

\glsni{begindispmath}
\cmdname{pderiv}\marg{\glsni{circumchar}2\glsni{mathcal}\marg{L}}\marg{\marg{z\glsni{underscorechar}i\glsni{circumchar}\glsni{rho}}\glsni{circumchar}2} =
-\cmdname{pderiv}\marg{\glsni{rho}\glsni{underscorechar}i}\marg{z\glsni{underscorechar}i\glsni{circumchar}\glsni{rho}}
\glsni{left}(
  \cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i} \glsni{frac}\marg{\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}}\marg{1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}}
  + v\glsni{underscorechar}i \glsni{frac}\marg{\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}\cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i}(1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i})
             +\cmdname{e}\glsni{circumchar}\marg{2v\glsni{underscorechar}i}\cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i}}\marg{(1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i})\glsni{circumchar}2}
\glsni{right})
\glsni{enddispmath}
\end{alltt}
\end{code}%
\begin{result}[Image showing a second order partial derivative.]
\[
\pderiv{^2\mathcal{L}}{{z_i^\rho}^2} =
-\pderiv{\rho_i}{z_i^\rho}
\left(
  \pderiv{v_i}{\rho_i} \frac{\e^{v_i}}{1-\e^{v_i}}
  + v_i \frac{\e^{v_i}\pderiv{v_i}{\rho_i}(1-\e^{v_i})+\e^{2v_i}\pderiv{v_i}{\rho_i}}{(1-\e^{v_i})^2}
\right)
\]
\end{result}

\xminisec{Note:}
The above code looks a bit complicated, and there are
so many braces that it can be easy to lose track, so here are some
ways of making it a little easier to type:
\begin{enumerate}
\item Whenever you start a new environment type in the
\gls{begin} and \gls{end} bits first, and then insert
whatever goes inside the environment.  This ensures that you always
have a matching \gls{begin} and \gls{end}. The same goes for 
\glsni{begindispmath} and \glsni{enddispmath}.

\item Whenever you type any braces, always type the opening and
closing braces first, and then insert whatever goes in between.  This
will ensure that your braces always match up.
\end{enumerate}

So keeping these notes in mind, let's try typing in the code in a
methodical manner:\screenpagebreak
\begin{enumerate}
\item Start and end the displayed maths mode:
\begin{code}
\glsni{begindispmath}\newline
\glsni{enddispmath}
\end{code}

\item We now need a partial derivative.
(The command \cmdname{pderiv} is defined as described
\htmlref{earlier}{itm:pderiv}\latex{\ifscreenorother{}{\ on 
page~\pageref{itm:pderiv}}}. Make sure you remember to define it,
preferably in the \gls{preamble}.)
\begin{code}
{\color{midgray}
\glsnl{begindispmath}}\newline
\cmdname{pderiv}\marg{}\marg{}\newline
{\color{midgray}
\glsnl{enddispmath}}
\end{code}

\item Let's do the first argument. This partial derivative is
actually a double derivative, which means we need a squared bit on
the top along with a calligraphic L:
\begin{code}
\begin{alltt}
{\color{midgray}\glsnl{begindispmath}
\cmdname{pderiv}\marg*{\textcolor{black}{\glsni{circumchar}2 \glsni{mathcal}\marg{L}}}\marg*{}
\glsnl{enddispmath}}
\end{alltt}
\end{code}

\item The second argument is the $z_i^\rho$ squared bit.  This is a 
nested superscript
\verb|{z_i^\rho}^2|:
\begin{code}
\begin{alltt}
\color{midgray}\glsnl{begindispmath}
\cmdname{pderiv}\marg*{\textasciicircum2 \cmdname{mathcal}\marg{L}}\marg*{\textcolor{black}{\marg{z\glsni{underscorechar}i\glsni{circumchar}\glsni{rho}}\glsni{circumchar}2}}
\glsnl{enddispmath}
\end{alltt}
\end{code}

\item We can do the next partial derivative in the same way.  This 
one is slightly easier to do:
\begin{code}
{\color{midgray}\glsnl{begindispmath}\newline
\cmdname{pderiv}\marg*{\glsnl{circumchar}2 \glsnl{mathcal}{L}}\marg*{\marg*{z\glsnl{underscorechar}i\glsnl{circumchar}\glsnl{rho}}\glsnl{circumchar}2}} =\newline
-\cmdname{pderiv}\marg{\glsni{rho}\glsni{underscorechar}i}\marg{z\glsni{underscorechar}i\glsni{circumchar}\glsni{rho}}\newline
{\color{midgray}\glsnl{enddispmath}}
\end{code}

\item Delimiters also need to occur in pairs, like curly braces and 
\glsni{begin} and \glsni{end}, so let's do them next:
\begin{code}
{\color{midgray}\verb|\[|\\
\verb|\pderiv{^2 \mathcal{L}}{{z_i^\rho}^2} =|\\
\verb|-\pderiv{\rho_i}{z_i^\rho}|}\\
\strut~~\glsni{left}(\\
\strut~~\glsni{right})\\
{\color{midgray}\verb|\]|}
\end{code}\screenpagebreak

\item Now we need to do the bits inside the brackets.  First of all 
we have yet another partial derivative:
\begin{code}
{\color{midgray}\verb|\[|\\
\verb|\pderiv{^2 \mathcal{L}}{{z_i^\rho}^2} =|\\
\verb|-\pderiv{\rho_i}{z_i^\rho}|\\
\strut~~\glsnl{left}\glsnl{openparen}}\\
\strut~~~~\cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i}\\
{\color{midgray}~~\glsnl{right}\glsnl{closeparen}\\
\verb|\]|}
\end{code}

\item Now we have a fraction following the partial derivative from
the previous step.
(Make sure you use braces for the exponential bit: \verb|\e^{v_i}|
($\e^{v_i}$) is not the same as \verb|\e^v_i| ($\e^v_i$). The
command \cmdname{e} is defined as described
\htmlref{earlier}{sec:scripts}\latex{ in \sectionref{sec:scripts}}.
Make sure you define it, preferably in the \gls{preamble}.)
\begin{code}
{\color{midgray}\verb|\[|\\
\verb|\pderiv{^2 \mathcal{L}}{{z_i^\rho}^2} =|\\
\verb|-\pderiv{\rho_i}{z_i^\rho}|\\
\strut~~\glsnl{left}\glsnl{openparen}\\
\strut~~~~\cmdname{pderiv}\marg*{v\glsnl{underscorechar}i}\marg*{\glsnl{rho}\glsnl{underscorechar}i}} \glsni{frac}\marg{\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}}\marg{1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}}\\
{\color{midgray}~~\glsnl{right}\glsnl{closeparen}\\
\verb|\]|}
\end{code}

\item This is followed by $v_i$ times another fraction:
\begin{code}\par\noindent
{\color{midgray}\verb|\[|\\
\verb|\pderiv{^2 \mathcal{L}}{{z_i^\rho}^2} =|\\
\verb|-\pderiv{\rho_i}{z_i^\rho}|\\
\strut~~\glsnl{left}\glsnl{openparen}\\
\strut~~~~\cmdname{pderiv}\marg*{v\glsnl{underscorechar}i}\marg*{\glsnl{rho}\glsnl{underscorechar}i} \glsnl{frac}\marg*{\cmdname{e}\glsnl{circumchar}\marg*{v\glsnl{underscorechar}i}}\marg*{1-\cmdname{e}\glsnl{circumchar}\marg*{v\glsnl{underscorechar}i}}}\\
\strut~~~~+ v\glsni{underscorechar}i \glsni{frac}\marg{}\marg{}\\
{\color{midgray}~~\glsnl{right}\glsnl{closeparen}\\
\color{midgray}\verb|\]|}
\end{code}

\item The bottom part of the
fraction (the denominator) is easier than the top, so let's do that first:
\begin{code}
\color{midgray}\glsnl{begindispmath}\newline
\cmdname{pderiv}\marg*{\textasciicircum2 \cmdname{mathcal}\marg*{L}}\marg*{\marg*{z\_i\textasciicircum\cmdname{rho}}\textasciicircum2} =\newline
-\cmdname{pderiv}\marg*{\cmdname{rho}\_i}\marg*{z\_i\textasciicircum\cmdname{rho}}\newline
\strut~~\cmdname{left}(\newline
\strut~~~~\cmdname{pderiv}\marg*{v\_i}\marg*{\cmdname{rho}\_i} \cmdname{frac}\marg*{\cmdname{e}\textasciicircum\marg*{v\_i}}\marg*{1-\cmdname{e}\textasciicircum\marg*{v\_i}}\newline
\strut~~~~+ v\_i \cmdname{frac}\marg*{}\marg*{\textcolor{black}{(1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i})\glsni{circumchar}2}}\newline
\strut~~\cmdname{right})\newline
\glsnl{enddispmath}
\color{black}
\end{code}

% Something weird is causing a shift in the 
% frame here.
% Compensating by ending and restarting enumerate
% environment
\breakenumi

\item Now for the top part of the fraction (the numerator).
To refresh your memory, it should look like:
\[
\e^{v_i}\pderiv{v_i}{\rho_i}(1-\e^{v_i})
+ \e^{2v_i}\pderiv{v_i}{\rho_i}
\]
That's a bit
complicated, so let's break it down:

\begin{enumerate}

\item The first term is:
\begin{alltt}
\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}
\end{alltt}

\item The next term is another partial derivative:
\begin{alltt}
\cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i}
\end{alltt}

\item Then we have:
\begin{alltt}
(1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i})
\end{alltt}

\item Next we have to add on:
\begin{alltt}
+\cmdname{e}\glsni{circumchar}\marg{2v\glsni{underscorechar}i}
\end{alltt}

\item And finally we have:
\begin{alltt}
\cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i}
\end{alltt}
\end{enumerate}

So the numerator is:
\begin{code}
\begin{verbatim}
\e^{v_i}\pderiv{v_i}{\rho_i}(1-\e^{v_i})
  + \e^{2v_i}\pderiv{v_i}{\rho_i}
\end{verbatim}
\end{code}

Inserting this into our code:\reportpagebreak
\begin{code}
\begin{alltt}
\color{midgray}\glsnl{begindispmath}
\cmdname{pderiv}\marg*{\textasciicircum2\cmdname{mathcal}\marg*{L}}\marg*{\marg*{z\_i\textasciicircum\cmdname{rho}}\textasciicircum2} =
-\cmdname{pderiv}\marg*{\cmdname{rho}\_i}\marg*{z\_i\textasciicircum\cmdname{rho}}
\cmdname{left}(
  \cmdname{pderiv}\marg*{v\_i}\marg*{\cmdname{rho}\_i} \cmdname{frac}\marg*{\cmdname{e}\textasciicircum\marg*{v\_i}}\marg*{1-\cmdname{e}\textasciicircum\marg*{v\_i}}
  \color{midgray}+ v\_i \cmdname{frac}\marg*{\textcolor{black}{\cmdname{e}\textasciicircum\marg{v\_i}\cmdname{pderiv}\marg{v\_i}\marg{\cmdname{rho}\_i}(1-\cmdname{e}\textasciicircum\marg{v\_i})
             +\cmdname{e}\textasciicircum\marg{2v\_i}\cmdname{pderiv}\marg{v\_i}\marg{\cmdname{rho}\_i}}}\marg*{(1-\cmdname{e}\textasciicircum\marg*{v\_i})\textasciicircum2}
\cmdname{right})
\glsnl{enddispmath}
\end{alltt}
\color{black}
\end{code}

\end{enumerate}


%----------- Arrays -------------

\setnode{arrays}
\subsection{Arrays}
\label{sec:arrays}

Mathematical structures such as matrices and vectors require elements
to be arranged in rows and columns.  Just as we can align material in
rows and columns in text mode using the
\gls{env-tabular} environment (\sectionref{sec:tabular}), we can do the
same in maths mode using the \gls{env-array} environment.  The
\glsni{env-array} environment has the same format as the
\gls{env-tabular} environment, however it must be in maths mode.
The column half-gaps are given by the \gls{length} register
\gls{arraycolsep} (analogous to \gls{tabcolsep}). 

\xminisec{Example:}

\begin{code}
\glsni{begindispmath}\newline
\glsni{begin}\marg{array}\marg{rrr}\newline
0 \gls{ampchar} 1 \gls{ampchar} 19\gls{tab.dbbackslashchar}\newline
-6 \gls{ampchar} 10 \gls{ampchar} 200\newline
\glsni{end}\marg{array}\newline
\glsni{enddispmath}
\end{code}

\begin{result}[Image shows 3 columns and 2 rows.]
\[
\begin{array}{rrr}
0 & 1 & 19\\
-6 & 10 & 200
\end{array}
\]
\end{result}

\xminisec{Example (Adding Delimiters):}

\begin{code}
\begin{alltt}
\glsni{begindispmath}
\glsni{left}\glsni{openparen}
 \glsni{begin}\marg{array}\marg{rrr}
   0 \glsni{ampchar} 1 \glsni{ampchar} 19\glsni{tab.dbbackslashchar}
  -6 \glsni{ampchar} 10 \glsni{ampchar} 200
 \glsni{end}\marg{array}
\glsni{right}\glsni{closeparen}
\glsni{enddispmath}
\end{alltt}
\end{code}%
\begin{resultS}[Image: as before but has large round brackets on either
side.]
\[
\left(
\begin{array}{rrr}
0 & 1 & 19\\
-6 & 10 & 200
\end{array}
\right)
\]
\end{resultS}

\xminisec{Adding a Vertical Rule:}

A vertical rule can be added using \gls{array.barchar} in the column
specifier. For example:
\begin{code}
\begin{alltt}
\glsni{begindispmath}
\glsni{left}\glsni{openparen}
 \glsni{begin}\marg{array}\marg{rr\glsni{array.barchar}r}
   0 \glsni{ampchar} 1 \glsni{ampchar} 19\glsni{tab.dbbackslashchar}
  -6 \glsni{ampchar} 10 \glsni{ampchar} 200
 \glsni{end}\marg{array}
\glsni{right}\glsni{closeparen}
\glsni{enddispmath}
\end{alltt}
\end{code}%
\begin{resultS}[Image: 3 columns and 2 rows with a vertical line
between the second and third column.]
\[
\left(
\begin{array}{rr|r}
0 & 1 & 19\\
-6 & 10 & 200
\end{array}
\right)
\]
\end{resultS}

\xminisec{Example (Cases):}
This example uses an 
\htmlref{invisible delimiter}{obj:invisdelim}:
\begin{code}
\begin{alltt}
\glsni{begindispmath}
f(x) = 
 \glsni{left}\glsni{leftbrace}
  \glsni{begin}\marg{array}\marg{rl}
   -1 \glsni{ampchar} x \glsni{ltchar} 0\glsni{tab.dbbackslashchar}
   0  \glsni{ampchar} x = 0\glsni{tab.dbbackslashchar}
   +1 \glsni{ampchar} x \glsni{gtchar} 0
  \glsni{end}\marg{array}
 \glsni{right}\glsni{delimiter.periodchar}
\glsni{enddispmath}
\end{alltt}
\end{code}%
\begin{resultS}[Image: array has large open brace on the left and
nothing on the right of it.]
\[
f(x) = 
\left\{
\begin{array}{rl}
-1 & x < 0\\
0 & x = 0\\
+1 & x > 0
\end{array}
\right.
\]
\end{resultS}
This can be rewritten more compactly using the \isty{amsmath}
\gls{env-cases} environment:
\begin{code}
\gls{begindispmath}\newline
f(x) = \newline
\strut~\glsni{begin}\marg{cases}\newline
\strut~~-1 \glsni{ampchar} x < 0\glsni{tab.dbbackslashchar}\newline
\strut~~0  \glsni{ampchar} x = 0\glsni{tab.dbbackslashchar}\newline
\strut~~+1 \glsni{ampchar} x > 0\newline
\strut~\glsni{end}\marg{cases}\newline
\gls{enddispmath}
\end{code}
\begin{resultS}[Image: as previous example but first column is left
aligned.]
\[
f(x) = 
\begin{cases}
-1 & x < 0\\
0 & x = 0\\
+1 & x > 0
\end{cases}
\]
\end{resultS}

The \isty{amsmath} package provides some convenient environments to
typeset matrices: \gls{env-pmatrix}, \gls{env-bmatrix},
\gls{env-Bmatrix}, \gls{env-vmatrix} and \gls{env-Vmatrix}. These
are similar to the \gls{env-array} environment except there is no
argument, and they add (respectively) $\bigl(~\bigr)$,
$\bigl[~\bigr]$, $\bigl\{~\bigr\}$, $\bigl\lvert~\bigr\rvert$ and
$\bigl\lVert~\bigr\rVert$ delimiters. There is also the
\gls{env-matrix} environment that doesn't have any delimiters.

\xminisec{Example:}
\begin{code}
\begin{alltt}
\glsni{begin}\marg{equation}
 \glsni{begin}\marg{pmatrix}
  a \glsni{ampchar} b\glsni{tab.dbbackslashchar}
  c \glsni{ampchar} d
 \glsni{end}\marg{pmatrix}
\glsni{end}\marg{equation}
\end{alltt}
\end{code}
\begin{result}[Image: 2 by 2 matrix with round delimiters and an
equation number.]
\begin{equation}
\begin{pmatrix}
a & b\\
c & d
\end{pmatrix}
\end{equation}
\end{result}

The \isty{amsmath} package also provides the environment
\gls{env-smallmatrix} designed for in-line use. You need to add any
delimiters explicitly.

\xminisec{Example:}
\begin{code}
\begin{alltt}
Here is a small matrix
\glsni{begin}\marg{math}
 \glsni{left}\glsni{openparen}
  \glsni{begin}\marg{smallmatrix}
  a \glsni{ampchar} b\glsni{tab.dbbackslashchar}
  c \glsni{ampchar} d
  \glsni{end}\marg{smallmatrix}
 \glsni{right}\glsni{closeparen}
\glsni{end}\marg{math}
in a line of text.
\end{alltt}
\end{code}
\begin{resultS}[Image: matrix is small enough to fit into the line
of text.]
Here is a small matrix
\begin{math}
\left(
\begin{smallmatrix}
a & b\\
c & d
\end{smallmatrix}
\right)
\end{math}
in a line of text.
\end{resultS}


%----------- Vectors ------------

\setnode{vectors}
\subsection{Vectors}
\label{sec:vec}

A variable representing a vector can be typeset using the command:
\begin{definition}
\gls{vec}\marg{\meta{variable}}
\end{definition}\screenpagebreak

\xminisec{Example:}
\begin{codeS}
\glsni{begindispmath}
\glsni{vec}\marg{x}
\glsni{enddispmath}
\end{codeS}
\begin{resultS}[Image: x with a small right arrow above it.]
\[ \vec{x} \]
\end{resultS}

Vectors are often typeset in bold.  This can be 
done by \htmlref{redefining}{sec:renewcom} the \glsni{vec}
command\doifbook{ (see \sectionref{sec:renewcom})}.
You could use \gls{mathbf}, for example:
\begin{code}
\begin{alltt}
\gls{renewcommand}\marg{\glsni{vec}}\oarg{1}\marg{\glsni{mathbf}\marg{\glsni{hashchar}1}}

\glsni{begindispmath}
  \glsni{vec}\marg{x}\glsni{cdot}\glsni{vec}\marg{\glsni{xi}} = z
\glsni{enddispmath}
\end{alltt}
\end{code}\bookpagebreak\noindent
\begin{resultS}[Image: upright bold x centred dot xi equals z]
\[
\mathbf{x}\cdot\mathbf{\xi} = z
\]
\end{resultS}
\refstepcounter{object}\label{cmd:vec}However, as you may have
noticed, the 
Greek letter $\xi$ has not come out in bold.  Here's an alternative 
(using \gls{boldsymbol} defined in the \isty{amsfonts} \htmlref{package}{sec:packages}):
\begin{code}
\gls{renewcommand}\marg{\glsni{vec}}\oarg{1}\marg{\glsni{boldsymbol}\marg{\glsni{hashchar}1}}\newline
\glsni{begindispmath}\newline
\strut~~\glsni{vec}\marg{x}\glsni{cdot}\glsni{vec}\marg{\glsni{xi}} = z\newline
\glsni{enddispmath}
\end{code}%
\begin{resultS}[As before but x and xi in italic bold]
\[
\boldsymbol{x}\cdot\boldsymbol{\xi} = z
\]
\end{resultS}

Located (or position) vectors, on the other hand, are usually typeset with a right
arrow, but the default definition of \glsni{vec} produces an
arrow that is too small:
\begin{codeS}
\glsni{begindispmath}
\glsni{vec}\marg{OP}
\glsni{enddispmath}
\end{codeS}
\begin{resultS}[Image: the letters O P with a small right arrow
above them.]
\[
\vec{OP}
\]
\end{resultS}
Instead, use \gls{overrightarrow} (\tableref{tab:overunderarrows}):
\begin{codeS}
\glsni{begindispmath}
\glsni{overrightarrow}\marg{OP}
\glsni{enddispmath}
\end{codeS}
\begin{resultS}[Image: as above but with a longer arrow that spans
both letters.]
\[
\overrightarrow{OP}
\]
\end{resultS}
You might prefer to define separate commands for a located vector and a vector
variable.

\xminisec{Example:}
In the \glsterm{preamble}, define \cmdname{lvec} for a
located vector and \cmdname{bvec} for a vector variable:
\begin{code}
\begin{alltt}
\gls{newcommand}*\marg{\cmdname{lvec}}\oarg{1}\marg{\glsni{overrightarrow}\marg{\glsni{hashchar}1}}
\glsni{newcommand}*\marg{\cmdname{bvec}}\oarg{1}\marg{\glsni{boldsymbol}\marg{\glsni{hashchar}1}}
\end{alltt}
\end{code}
Later in the document:
\begin{code}
Let \glsni{dollarchar}\cmdname{bvec}\marg{u}=(x, y)\glsni{dollarchar}
represent \glsni{dollarchar}\cmdname{lvec}\marg{OP}\glsni{dollarchar}, then\newline
\glsni{begindispmath}\newline
\strut~~\glsni{lVert} \cmdname{bvec}\marg{u} \glsni{rVert}
    = \glsni{sqrt}\marg{x\glsni{circumchar}2 + y\glsni{circumchar}2}\newline
\glsni{enddispmath}
\end{code}
\begin{result}[Image: the vector u appeas in italic bold and the
letters O P are as above.]
\newcommand*{\lvec}[1]{\overrightarrow{#1}}%
\newcommand*{\bvec}[1]{\boldsymbol{#1}}%
Let $\bvec{u}=(x, y)$ represent $\lvec{OP}$, then
\[
  \lVert \bvec{u} \rVert = \sqrt{x^2 + y^2}
\]
\end{result}
\bookpagebreak

\begin{exercise}{Maths: Vectors and Arrays}{ex:vectors}
Try to produce the following:
\renewcommand{\vec}[1]{\boldsymbol{#1}}
\begin{result}[maths2ex.html]
\[
\boldsymbol{A}\vec{x} =
\begin{pmatrix}
0 & 1\\
2 & 3
\end{pmatrix}
\begin{pmatrix}
1\\
2
\end{pmatrix}
=
\begin{pmatrix}
2\\
8
\end{pmatrix}
= \vec{y}
\]
\end{result}%
As before, you can \downloadorview{vectors} the solution.
\end{exercise}

%--------------- Mathematical Spacing -------------------

\setnode{mathssp}
\subsection{Mathematical Spacing}
\label{sec:mathsspacing}

\LaTeX\ deals with mathematical spacing fairly well, but sometimes
you may find you want to adjust the spacing yourself.  Available
spacing commands are listed in \tableref{tab:spacing}.

\begin{table}[hbtp]
\caption[Mathematical Spacing Commands]{Mathematical Spacing Commands
(\supdag provided by \protect\istyend{amsmath})}
\label{tab:spacing}
\centering
\begin{tabular}{lll}
\toprule
\bfseries Command & \bfseries Example Input & \bfseries Example Output\\
\midrule
 & \verb|$AB$| & $AB$ \\
\gls{thinspace} or \gls{comma} & \verb|$A\,B$| & $A\,B$\\
\gls{medspace}\supdag\ or \gls{colon} & \verb|$A\:B$| & $A\:B$\\
\gls{thickspace}\supdag\ or \gls{semicolon} & \verb|$A\;B$| & $A\;B$\\
\gls{quad} & \verb|$A\quad B$| & $A\quad B$\\
\gls{qquad} & \verb|$A\qquad B$| & $A\qquad B$\\
\gls{negthinspace} or \gls{exclam} & \verb|$A\!B$| & $A\!B$ \\
\gls{negmedspace}\supdag & \verb|$A\negmedspace B$| & $A\negmedspace B$ \\
\gls{negthickspace}\supdag & \verb|$A\negthickspace B$| & $A\negthickspace B$ \\
\bottomrule
\end{tabular}
\end{table}

\begin{exercise}{More Mathematics}{ex:moremaths}
This exercise uses the spacing command \glsni{qquad}. In addition,
it has a
\htmlref{function name}{sec:declaremathop}, diag, and it uses the
\gls{forall} and \htmlref{ellipses}{sec:ellipses} symbols. It also
\htmlref{redefines the \cmdname{vec}
command}{cmd:vec}\indexCom{vec}, as was done in the previous
section, uses the
\gls{env-bmatrix} environment (see \sectionref{sec:arrays}), and has \htmlref{subscripts and superscripts}{sec:scripts}.

Try to reproduce the following output:
\begin{result}[maths3ex.html]
\renewcommand{\vec}[1]{\boldsymbol{#1}}
The set of linear equations:
\[
a_ix_i = b_i  \qquad \forall i=1, \ldots, n
\]
can be written as a matrix equation:
\[
\diag(\vec{a})\vec{x} = \vec{b}
\]
where $\vec{x} = (x_1, \ldots, x_n)^T$, $\vec{b} = (b_1, \ldots, b_n)^T$
and
\[
\diag(\vec{a}) = 
\begin{bmatrix}
a_1 & 0 & \cdots & 0\\
0 & a_2 & \ddots & \vdots\\
\vdots & \ddots & \ddots & 0\\
0 & \cdots & 0 & a_n
\end{bmatrix}
\]
\end{result}

Again, you can \downloadorview{moremaths} the solution.
\end{exercise}

%%%%%%%%%%%%%%%%%% DEFINING ENVIRONMENTS %%%%%%%%%%%%%%%%

\setnode{newenv}
\chapter{Defining Environments}
\label{ch:newenv}

Just as you can \htmlref{define new commands}{ch:newcom}, you can 
also define new \glspl{environment}.  The command
\begin{definition}
\gls{newenvironment}\marg{\meta{env-name}}\oarg{\meta{n-args}}\oarg{\meta{default}}\marg{\meta{begin-code}}\marg{\meta{end-code}}
\end{definition}%
is used to define a new environment. As with new commands, you can
use the optional argument \meta{n-args} to define an environment with
arguments, and \meta{default} to define an environment with an
optional argument.

The first argument \meta{env-name} is the name of your new
environment.  Remember that the environment name must not have a
backslash.  The mandatory arguments \meta{begin-code} and
\meta{end-code} indicate what \LaTeX\ \reportlinebreak should do at the beginning and
end of the environment. Note that although \meta{begin-code} can
reference the arguments using \gls{hashchar}\texttt{1} etc, the
\meta{end-code} part can't.

\xminisec{Example (An Exercise Environment):}

Let's first consider an example of an
environment without any arguments.  Let's make an environment called,
say, \envname{exercise} that prints \textbf{Exercise} in bold and
typesets the contents of the environment in italic, with a gap
between the title and the contents.  In other words,
we want the following code:
\begin{code}
\glsni{begin}\marg{exercise}\newline
This is a sample.\newline
\glsni{end}\marg{exercise}
\end{code}
to produce the following output:
\begin{result}[newenv1.html]
\par\noindent
\textbf{Exercise}
\begin{itshape}
\par
\vspace{\baselineskip}%
\noindent
This is a sample.
\end{itshape}
\end{result}
(In the \htmlref{next chapter}{ch:counters} we will add numbering.)

Let's first consider what we want this environment to do: we can get
the word \dq{Exercise} in bold using \gls{textbf},
and the italic font can be
obtained by using the \gls{env-itshape} environment (recall
\sectionref{sec:fonts}).  
So, at the start of our
new environment we need
\begin{codeS}
\glsni{textbf}\marg{Exercise}\glsni{begin}\marg{itshape}
\end{codeS}
and at the end of our new
environment we need to end the \glsni{env-itshape} environment:
\begin{codeS}
\glsni{end}\marg{itshape}
\end{codeS}
Putting the above together into the new environment definition:
\begin{code}\obeyspaces
\glsni{newenvironment}\marg{exercise}\glsni{percentchar} environment name\newline
\marg{\glsni{percentchar} begin code\newline
\strut~~\glsni{textbf}\marg{Exercise}\glsni{begin}\marg{itshape}\glsni{percentchar}\newline
}\glsni{percentchar}\newline
\marg{\glsni{end}\marg{itshape}}\glsni{percentchar} end code
\end{code}
Let's try it out:
\begin{code}
\begin{verbatim}
\begin{exercise}
This is a sample.
\end{exercise}
\end{verbatim}
\end{code}%
\begin{resultS}[newenv2.html]
\textbf{Exercise}
\begin{itshape}
This is a sample.
\end{itshape}
\end{resultS}
Not quite right.  Let's put a paragraph break after
\textbf{Exercise}, and put one before it as well. The command
\gls{par} can be used to make a paragraph break and the extra bit of
vertical spacing can be produced using \glsni{vspace}. The
\gls{length} \gls{baselineskip} is the interline spacing.
Modifications are shown in bold \modification{like this}.
\begin{code}\obeyspaces
\glsnl{newenvironment}\marg*{exercise}\glsnl{percentchar} environment name\newline
\marg*{\glsnl{percentchar} begin code\newline
\strut~~\modification{\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{percentchar}}\newline
\strut~~\glsnl{textbf}\marg*{Exercise}\glsnl{begin}\marg*{itshape}\glsnl{percentchar}\newline
\strut~~\modification{\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{percentchar}}\newline
}\glsnl{percentchar}\newline
\marg*{\glsnl{end}\marg*{itshape}}\glsnl{percentchar} end code
\end{code}%
Let's have a look at the output now:
\begin{result}
\dohtmlcolorbox{%
\par\vspace{\baselineskip}%
\textbf{Exercise}\begin{itshape}%
\par\vspace{\baselineskip}
This is a sample.
\end{itshape}
}
\end{result}
\faq{There's a space added after my environment}{spaftend}%
The indent at the start of each line is caused by the normal
paragraph indentation. This can be suppressed using \gls{noindent}.
It's also a good idea to suppress
any spaces immediately following \verb|\begin{exercise}| and \verb|\end{exercise}|, which can be done
using \gls{ignorespaces} and \reportlinebreak\screenlinebreak\gls{ignorespacesafterend}.
Modifications are again shown in bold \modification{like this}.
\begin{code}\obeyspaces
\glsnl{newenvironment}\marg*{exercise}\glsnl{percentchar} environment name\newline
\marg*{\glsnl{percentchar} begin code\newline
\strut~~\glsnl{par}\glsnl{vspace}\marg*{\glsnl{baselineskip}}\modification{\glsni{noindent}}\newline
\strut~~\glsnl{textbf}\marg*{Exercise}\glsnl{begin}\marg*{itshape}\glsnl{percentchar}\newline
\strut~~\glsnl{par}\glsnl{vspace}\marg*{\glsnl{baselineskip}}\modification{\glsni{noindent}\glsni{ignorespaces}}\newline
}\glsnl{percentchar}\newline
\marg*{\glsnl{percentchar} end code\newline
\strut~~\glsnl{end}\marg{itshape}\modification{\glsni{ignorespacesafterend}}\newline 
}
\end{code}%
The \envname{exercise} environment now appears as:
\begin{result}
\par\vspace{\baselineskip}\noindent
\textbf{Exercise}\begin{itshape}%
\par\vspace{\baselineskip}\noindent
This is a sample.
\end{itshape}
\end{result}

Now let's modify our code so that the environment takes an
argument.  The argument should indicate the exercise topic.
For example, the following code:
\begin{code}
\begin{verbatim}
\begin{exercise}{An Example}
This is a sample.
\end{exercise}
\end{verbatim}
\end{code}%
should produce the following result:
\begin{result}[newenv3.html]
\par\vspace{\baselineskip}\noindent\textbf{Exercise (An Example)}
\begin{itshape}\par\vspace{\baselineskip}\noindent
This is a sample.
\end{itshape}
\end{result}%
As with \gls{newcommand}, \gls{hashchar}\texttt{1} is
used to indicate the first argument.  We can now modify the code as
follows:
\begin{code}\obeyspaces
\glsnl{newenvironment}\marg*{exercise}\modification{\oarg{1}}\glsnl{percentchar} environment name\newline
\marg*{\glsnl{percentchar} begin code\newline
\strut~~\glsnl{par}\glsnl{vspace}\marg*{\glsnl{baselineskip}}\glsnl{noindent}\newline
\strut~~\glsnl{textbf}\marg*{Exercise\modification{ (\glsni{hashchar}1)}}\glsnl{begin}\marg*{itshape}\glsnl{percentchar}\newline
\strut~~\glsnl{par}\glsnl{vspace}\marg*{\glsnl{baselineskip}}\glsnl{noindent}\glsnl{ignorespaces}\newline
}\glsnl{percentchar}\newline
\marg*{\glsnl{percentchar} end code\newline
\strut~~\glsnl{end}\marg*{itshape}\glsnl{ignorespacesafterend}\newline
}
\end{code}

\setnode{renewenv}
\section{Redefining Environments}
\label{sec:renewenv}

It is also possible to redefine an environment using:
\begin{definition}[\linewidth]
\gls{renewenvironment}\marg{\meta{env-name}}\oarg{\meta{n-args}}\oarg{\meta{default}}\marg{\meta{begin-code}}\marg{\meta{end-code}}
\end{definition}%
As with \gls{renewcommand}, only redefine an existing environment if
you want a modified version of that environment rather than because
you like the environment name.

\begin{exercise}{Defining a New Environment}{ex:newenv}
If you did any of the exercises from \exerciseref{ex:section}
to \exerciseref{ex:tables}, go back to the document you
created and define the \envname{exercise} environment as in
the example above.  Then try creating some exercises using this
environment. You could, maybe, put an exercise in the first
chapter, and then another one in the second chapter.
Again you can \downloadorview{newenv} an example.
\end{exercise}

%%%%%%%%%%%%%%%%% Counters %%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{counters}
\chapter{Counters}
\label{ch:counters}

As we have seen, \LaTeX\ automatically generates numbers for
chapters, sections, equations etc. These numbers are stored in
\keyword{counters}. The names of these counters are usually the same
as the name of the object with which it is associated but without
any backslash. For example, the \gls{chapter} command has an associated
counter called \icounter{chapter}, the \gls{footnote} command has an
associated counter called \icounter{footnote}, the
\gls{env-equation} environment has an associated counter called
\icounter{equation}, the \gls{env-figure} environment has an associated counter
called \icounter{figure} and the \gls{env-table} environment has an associated
counter called \icounter{table}. There is also a counter called
\icounter{page} that keeps track of the current page number.

The value of a counter can be displayed using the command
\begin{definition}
\icmdname{the}\meta{counter}
\end{definition}%
where \meta{counter} is the name of the associated counter.  Note
that \meta{counter} does not go in curly braces and adjoins
\cmdname{the} (for example, \gls{thepage}\faq{Page number is wrong at
start of page}{wrongpn}, \reportlinebreak\gls{thesection} or
\gls{thechapter}).   In fact, we have already encountered
\reportlinebreak\screenlinebreak\gls{thefigure} in \sectionref{sec:subfloats}.

\xminisec{Example:}
\begin{code}
\begin{alltt}
This page is Page\glsni{tildechar}\glsni{thepage}.
The current chapter is Chapter\glsni{tildechar}\glsni{thechapter}.
\end{alltt}
\end{code}\label{example:thepage}%
\begin{resultS}[This page is Page 226. The current chapter is Chapter 11.]
% LaTeX2HTML doesn't store the page number in the image file
% so use \pageref to fake \thepage instead
This page is Page~\pageref*{example:thepage}.
The current chapter is Chapter~\thechapter.
\end{resultS}%
New counters can be created using the command:
\begin{definition}
\gls{newcounter}\marg{\meta{counter-name}}\oarg{\meta{outer-counter}}
\end{definition}%
The \gls{mandatory} \meta{counter-name}
is the name of your new counter (no backslash in the name).  For
example, let's define a counter called \texttt{exercise} to keep
track of each exercise. (Recall the exercise example from
\chapterref{ch:newenv}.)
\begin{codeS}
\glsni{newcounter}\marg{exercise}
\end{codeS}%
We can now display the value of the counter using
the command \cmdname{theexercise}.  At the moment the counter
has the value zero, the value can be changed using one
of the following commands:

\begin{fwlist}{\cmdname{addtocounter}\marg{\meta{counter}}\marg{\meta{num}}}
\fwitem{\gls{stepcounter}\marg{\meta{counter}}} Increments 
\meta{counter} by 1

\fwitem{\gls{refstepcounter}\marg{\meta{counter}}} As above, but 
allows you to cross-\reportlinebreak reference the counter using \gls{label} and 
\gls{ref}

\fwitem{\gls{setcounter}\marg{\meta{counter}}\marg{\meta{num}}} 
Sets the counter to \meta{num}

\fwitem{\gls{addtocounter}\marg{\meta{counter}}\marg{\meta{num}}} 
Adds \meta{num} to \meta{counter}
\end{fwlist}

A couple of the commands above take a number \meta{num} as one of 
the arguments.  If you want to use another counter for this argument, 
you need to use
\begin{definition}
\gls{value}\marg{\meta{counter}}
\end{definition}%
For example, if you want to set our new \texttt{exercise} counter to 
the same value as the \texttt{page} counter, you would do
\begin{codeS}
\glsni{setcounter}\marg{exercise}\marg{\glsni{value}\marg{page}}
\end{codeS}%
Let's go back to the \envname{exercise} environment you
created in \exerciseref{ex:newenv}.  The exercises really ought to have
an associated number, and this number should be incremented each time 
we use the exercise environment.  So let's modify our code to do this.
Modifications are illustrated in bold \modification{like this}:
\begin{code}\obeyspaces
\modification{\cmdname{newcounter}\marg{exercise}}\newline
\strut\newline
\glsni{newenvironment}\marg{exercise}\oarg{1}\glsni{percentchar} environment name\newline
\marg{\glsni{percentchar} begin code\newline
\strut~~\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{noindent}\newline
\strut~~\modification{\glsni{refstepcounter}\marg{exercise}}\glsni{percentchar}\newline
\strut~~\glsni{textbf}\marg{Exercise \modification{\cmdname{theexercise}\glsni{spacesym}}(\glsni{hashchar}1)}\glsni{percentchar}\newline
\strut~~\glsni{begin}\marg{itshape}\glsni{percentchar}\newline
\strut~~\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{percentchar}\newline
\strut~~\glsni{noindent}\glsni{ignorespaces}\newline
}\glsni{percentchar}\newline
\marg{\glsni{percentchar} end code\newline
\strut~~\glsni{end}\marg{itshape}\glsni{percentchar}\newline
\strut~~\modification{\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{percentchar}}\newline
\strut~~\modification{\glsni{noindent}}\glsni{ignorespacesafterend}\newline
}
\end{code}%
Note that the counter needs to be incremented before it is used.  
I've also added an extra \gls{vspace} at the end of the
environment and a paragraph break.
Since we've used \glsni{refstepcounter} instead of 
\glsni{stepcounter} we can cross-reference our
\envname{exercise} environment:\reportpagebreak
\begin{code}
\begin{alltt}
Exercise\glsni{tildechar}\glsni{ref}\marg{ex:simple} is a simple exercise.

\glsni{begin}\marg{exercise}\marg{Simple Exercise}
\glsni{label}\marg{ex:simple}\glsni{percentchar}
This is a simple exercise.
\glsni{end}\marg{exercise}
\end{alltt}
\end{code}%
This produces 
the following output:
\begin{result}[newcounter.html]
Exercise~1 is a simple exercise.
\par\vspace{\baselineskip}\noindent\textbf{Exercise 1 (Simple Exercise)}%
\begin{itshape}\par\vspace{\baselineskip}\noindent
This is a simple exercise.
\end{itshape}
\end{result}

The counter representation can be changed by redefining
\cmdname{theexercise}\faq{Redefining counters'
\cmdname{the}-commands}{the-commands} using the \gls{renewcommand}
command described in \sectionref{sec:renewcom}.
The following commands can be used to display the counter:

\begin{fwlist}{\cmdname{fnsymbol}\marg{\meta{counter}}}
\fwitem{\gls{arabic}\marg{\meta{counter}}} Arabic numeral (1, 2, 3, \ldots)

\fwitem{\gls{Roman}\marg{\meta{counter}}} Upper case Roman numeral 
(I, II, III, \ldots)

\fwitem{\gls{roman}\marg{\meta{counter}}} Lower case Roman numeral 
(i, ii, iii, \ldots)

\fwitem{\gls{alph}\marg{\meta{counter}}} Lower case letter 
(a, b, c, \ldots, z)

\fwitem{\gls{Alph}\marg{\meta{counter}}} Upper case letter 
(A, B, C, \ldots, Z)

\fwitem{\gls{fnsymbol}\marg{\meta{counter}}}
A footnote symbol 
(\makeimg{asterisk dagger double dagger section mark
paragraph mark double bar double asterisk two single daggers
two double daggers}{\footnotesymbols})
\end{fwlist}

\xminisec{Example:}

To make the chapter numbers appear as upper case Roman 
numerals you would do:
\begin{codeS}
\gls{renewcommand}\marg{\gls{thechapter}}\marg{\glsni{Roman}\marg{chapter}}
\end{codeS}

You may have noticed that \gls{newcounter} has an optional
argument \meta{outer-counter}.  This is for use if you require the
new counter to be reset every time \meta{outer-counter} is
incremented\faq{Master and slave counters}{addtoreset}.  For example,
the section numbers in the \icls{scrbook} class are dependent on the
chapter numbers.  Each time a new chapter is started, the section
numbers are reset.  Suppose we want our \texttt{exercise} counter to
be dependent on the \icounter{chapter} counter, we would do
\begin{codeS}
\gls{newcounter}\marg{exercise}\oarg{chapter}
\end{codeS}

Note that if you make a counter dependent on another counter like
this, the default action of \cmdname{the}\meta{counter} remains the
same, so \cmdname{theexercise} won't print the chapter number.
To make the chapter number appear as well, we need to redefine
\cmdname{theexercise} (recall \sectionref{sec:renewcom}):
\begin{codeS}
\gls{renewcommand}\marg{\cmdname{theexercise}}\marg{\glsni{thechapter}.\glsni{arabic}\marg{exercise}}
\end{codeS}%
Notice the use of \gls{thechapter} instead of,
say, \verb|\arabic{chapter}|.  This way
we don't need to keep track of the \icounter{chapter} counter format.

\xminisec{Example (Footnote Markers):}

The \icounter{footnote} counter is reset at the start of each
chapter but by default the chapter number isn't displayed in
\gls{thefootnote}. In \latexhtml{this book}{the PDF version of
this document} \glsni{thefootnote} was redefined so that it
displays the chapter number:
\begin{codeS}
\gls{renewcommand}\marg{\glsni{thefootnote}}\marg{\glsni{thechapter}.\glsni{arabic}\marg{footnote}}
\end{codeS}

\begin{exercise}{Using Counters}{ex:counters}
Modify the document from \exerciseref{ex:newenv} so that
the \envname{exercise} environment has a counter.
Make the counter dependent on the chapter.
You can \downloadorview{counters} an example.
\end{exercise}

%%%%%%%%%%%%%%%%%%%%%% APPENDICES %%%%%%%%%%%%%%%%%%

\appendix

%%%%%%%%%%%%%%%%%%% Installing Packages %%%%%%%%%%%%%%

\setnode{installsty}
\chapter{Downloading and Installing Packages}
\label{ch:installsty}

New \LaTeX\ packages are being created all the time\faq{Installing things
on a (La)TeX system}{instpackages}, so you may find that there are some
packages that you don't have on your installation. In this case, if
you don't have the package you want, you can download
it\faq{Installation using MiKTeX package manager}{inst-miktex*} from
\gls{ctan}. Before discussing installing new packages, it is
a good idea for you to understand the \gls{tds}\faq{What is the TDS?}{tds}.

All the files that make up the \TeX\ distribution are stored in a
standard hierarchical structure. The root directory of the main
distribution is usually called \texttt{texmf} or \texttt{texmf-dist}. Its location
depends on your system. For example, if you are using
\itexdistro{TeX~Live}~2012 on UNIX/Linux, it will probably be located in
\texttt{/usr\slash local\slash texlive\slash 2012\slash texmf-dist} or if you are using \itexdistro{MiKTeX} it
may be located in \verb|c:\texmf| or \texttt{c:\backslashsym Program
Files\backslashsym texmf}. Whichever system you are using, I~shall
refer to this directory as \meta{TEXMF}. So, if you are using
\texdistro{TeX~Live}~2012, \meta{TEXMF}\texttt{\slash doc} refers to the directory
\texttt{/usr\slash local\slash texlive\slash 2012\slash texmf-dist\slash doc}, or if you are using
\texdistro{MiKTeX}, \meta{TEXMF}\verb|\doc| refers to the folder
\verb|c:\texmf\doc| or \texttt{c:\backslashsym Program
Files\backslashsym texmf\backslashsym doc}.
In general, you should not make any modifications to the
\meta{TEXMF} directory tree as it will get overridden whenever you
update your \TeX\ distribution.

You should also have a local texmf tree. Again, the location of the
local texmf tree depends on your system. If you are using
\texdistro{TeX~Live}, it may be 
\texttt{/usr\slash local\slash texlive\slash texmf-local}. 
If you are using \texdistro{MiKTeX}, it
may be \texttt{c:\backslashsym localtexmf} or
\texttt{c:\backslashsym Program Files\backslashsym localtexmf}.
Whichever system you are using, I~shall refer to this directory as
\meta{TEXMF-LOCAL}. There is also the \meta{TEXMF-HOME} directory.
On UNIX-like systems this is usually \verb|~/texmf|. On Windows it's
usually in your user folder. This is the one where you typically
install any new classes or packages.

These directories must all have the same structure. The principle
sub-directories relating to \LaTeX\ are illustrated in
\figureref{fig:tds}. It may be that your \meta{TEXMF-HOME} directory
doesn't exist or doesn't contain some of these sub-directories, if
so, you will need to create them.

You can use the \iappname{kpsewhich} application to find out the 
locations of \meta{TEXMF-LOCAL} and
\meta{TEXMF-HOME}. Since \appname{kpsewhich} is a command-line
application, you will need a \htmlref{command prompt or terminal}{sec:terminal} 
open\latex{ (see \sectionref{sec:terminal})}.
At the command prompt, type
\begin{verbatim}
kpsewhich -var-value=TEXMFHOME
\end{verbatim}
to display the location of \meta{TEXMF-HOME} or
\begin{verbatim}
kpsewhich -var-value=TEXMFLOCAL
\end{verbatim}
to display the location of \meta{TEXMF-LOCAL}.
(Remember to press the enter \enter\ key at the end of the line.)

\refstepcounter{object}\label{obj:docdir}%
The documentation for \LaTeX\ classes and packages can be found
in the \texttt{doc\slash latex} sub-directories: \meta{TEXMF}\texttt{\slash doc\slash latex},
\meta{TEXMF-LOCAL}\texttt{\slash doc\slash latex} and \meta{TEXMF-HOME}\texttt{\slash doc\slash latex}.

\begin{figure}[htbp]
\figconts
  {pictures/tds}
  {%
    \caption{The \protect\TeX\protect\space Directory Structure (TDS) Showing 
    the Main \protect\LaTeX-Related Sub-Directories.}%
  }%
  {fig:tds}
\end{figure}

Some packages are supplied in this format.\footnote{Complete list at \url{http://mirror.ctan.org/install/macros/latex/contrib/}.} For example, the package
\sty{sample-package} may be distributed in a compressed file \texttt{sample-package.tds.zip},
which contains the files
\begin{verbatim}
doc/latex/sample-package/sample-package.pdf
tex/latex/sample-package/sample-package.sty
tex/latex/sample-package/sample-foo.sty
tex/latex/sample-package/sample-bar.sty
\end{verbatim}
In this case all you need to do is decompress the contents of 
the archive into the
\meta{TEXMF-LOCAL} or \meta{TEXMF-HOME} directory.

\refstepcounter{object}\label{obj:runtexhash}%
On older \TeX-distributions, you would then need to \htmlref{refresh the
\TeX\ database}{sec:refresh}\latex{ (described in
\sectionref{sec:refresh}\ifscreenorother{}{\ on
page~\pageref{sec:refresh}})}. With new distributions, you don't
need to do this if you are installing a new package into your
\meta{TEXMF-HOME} directory.

\xminisec{Example (Unix-Like):}
To install \texttt{sample-package.tds.zip} (assuming you're in the
same directory as that file):
\begin{verbatim}
unzip -d ~/texmf sample-package.tds.zip
\end{verbatim}

\setnode{dtxins}
\section{DTX and INS Files}
\label{sec:dtx}
\faq{Documented LaTeX sources (.dtx files)}{dtx}Not all packages are
provided in the \gls{tds} format. Instead (or additionally) many are supplied
with the code and documentation all bundled together in one file.
This file usually has the extension \texttt{.dtx}, and it usually
comes with an installation script that has the extension
\texttt{.ins}. Once you have downloaded the \texttt{.dtx} and
\texttt{.ins} files, you will then have to extract the code before
you can use it. Let's go back to the previous example. The package
\sty{sample-package} is now distributed in a DTX file, so the
\texttt{sample-package.zip} archive contains the files
\begin{verbatim}
sample-package.dtx sample-package.ins
\end{verbatim}
(with hopefully a \texttt{README} or \texttt{INSTALL} file). Note
that this archive, unlike the TDS one, doesn't contain any
\texttt{.sty} files. The documentation source and the package code
(\texttt{sample-package.sty}, \texttt{sample-foo.sty} and
\texttt{sample-bar.sty}) are all contained in the file
\texttt{sample-package.dtx}. This is how to extract them:
\begin{enumerate}
\item Extract the contents of \texttt{sample-package.zip} to a
temporary directory.

\item\label{itm:ins} Run \LaTeX\ on the file \texttt{sample-package.ins}. If
you are using a \latexhtml{terminal}{\htmlref{terminal}{sec:terminal}}, you can type the
following at the command prompt:
\begin{verbatim}
latex sample-package.ins
\end{verbatim}
If you are using a front-end, such as TeXWorks, open the 
\texttt{.ins} file
(for example \texttt{sample-package.ins}), and click on the build/typeset button.

This will create the files containing the package code. In this
example it will create the main package file \texttt{sample-package.sty}
and supplementary packages \texttt{sample-foo.sty} and \texttt{sample-bar.sty}.

\item Make a sub-directory of \meta{TEXMF-LOCAL}\texttt{/tex/latex}%
\footnote{or \meta{TEXMF-LOCAL}\texttt{\backslashsym tex\backslashsym latex} on 
Windows} in which to place these files. In this example, the package is
called \dq{sample-package}, so make a sub-directory called \texttt{sample-package}.

\item Move the files created in \objectref{Step}{itm:ins} into
the new sub-directory you created in the previous step.

\item\label{itm:dtx} Run \iPDFLaTeX\ on the file \texttt{sample-package.dtx}.
(The same as in \objectref{Step}{itm:ins}, but use the file
\texttt{sample-package.dtx} instead of \texttt{sample-package.ins}.) This will 
create a file called \texttt{sample-package.pdf}. You may need to repeat
this step to ensure that the cross references are up-to-date.
Check the \texttt{README} file or \texttt{INSTALL} file to see
if there is anything else you need to do. (If you have downloaded
the package from CTAN, it's possible that the documentation has 
already been supplied, as package authors are encouraged to supply
a PDF version of the documentation for on-line viewing. If so,
you can omit this step.)

\item  Make a sub-directory of \meta{TEXMF-LOCAL}\texttt{/doc/latex}%
\footnote{or \meta{TEXMF-LOCAL}\texttt{\backslashsym doc\backslashsym latex} on 
Windows} in which to place the documentation. In this example, the package is
called \dq{sample-package}, so make a sub-directory called
\texttt{sample-package}.

\item Move the files created in \objectref{Step}{itm:dtx} into
the new sub-directory you created in the previous step.

\end{enumerate}

As mentioned \htmlref{above}{obj:runtexhash}, on older
\TeX-distributions, you would then need to \htmlref{refresh the
\TeX\ database}{sec:refresh}, but this isn't required for
\meta{TEXMF-HOME} installs on new distributions.

\setnode{texhash}
\section{Refreshing the \texorpdfstring{\protect\TeX}{TeX}\protect\space Database}
\label{sec:refresh}

On older \gls{tex} distributions you had to refresh the \TeX\
database whenever you installed new classes or packages. With newer
installations you don't need to do this if you install them in your
\meta{TEXMF-HOME} directory, except under certain circumstances (for
example, you're using using a networked drive). If it turns out that
\TeX\ can't find a new class or package you have installed in
\meta{TEXMF-HOME} you will need to update the database using the
\iappname{texhash} (or \iappname{mktexlsr}) application. This is a
command-line application, so you need a \htmlref{terminal or command
prompt}{sec:terminal}\latex{ (see \sectionref{sec:terminal})}.

For example, on UNIX/Linux, to update \meta{TEXMF-HOME} (the
directory \verb|~/texmf|) you need to type the following at the
command prompt:
\begin{verbatim}
texhash ~/texmf
\end{verbatim}

If you are using a modern \TeX\ distribution, such as
\itexdistro{MiKTeX}, \itexdistro{TeX~Live} or \itexdistro{MacTeX} there 
should be a package manager that has a package installation
and refresh facility. For example, \texdistro{TeX~Live} comes with
the TeX~Live Manager (\iappname{tlmgr} or \iappname{mactlmgr}) and
recent versions of \texdistro{MiKTeX} have an application called
\appname{MiKTeX Update Wizard} which can automatically download and
install known packages.

If you experience any problems, contact your system administrator for help
or try one of the resources listed in \appendixref{ch:help}.

\xminisec{Related \gls{ukfaq} topics:}
\begin{itemize}
\item \faqlink{Installing things on a (La)TeX system}{instpackages}
\item \faqlink{Installing files \dq{where (La)TeX can find them}}{wherefiles}
\item \faqlink{Installation using MiKTeX package manager}{inst-miktex*}
\item \faqlink{\dq{Temporary} installation of (La)TeX files}{tempinst}
\item \faqlink{\dq{Private} installations of files}{privinst}
\end{itemize}


%%%%%%%%%%%%%%%%%%%%%% ERRORS %%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{commonerrors}
\chapter{Common Errors}
\label{ch:errors}

\begin{itemize}
\item
If you're running \LaTeX\ from a \gls{terminal} and the only message that gets displayed is:
\begin{verbatim}
latex: Command not found.
\end{verbatim}
or
\begin{verbatim}
Bad command or file name
\end{verbatim}
then you have either mistyped the command name, or you
don't have \LaTeX\ installed on your computer, or your path hasn't
been set up correctly.  First check that you have typed the command
correctly, then check to see if you have \TeX\ installed.  Failing
that, contact your system administrator for help or try one of the
resources listed in \appendixref{ch:help}.

\item
If you're running \LaTeX\ from a \gls{terminal} and you get the message (or something similar):
\begin{verbatim}
This is TeX, Version 3.14159 (Web2C 7.3.1)
! I can't find file `sample'.
<*> sample
          
Please type another input file name: 
\end{verbatim}
then you have either misspelt the filename or you are in the wrong
directory.  If you have misspelt the filename, simply type in the
correct name at the prompt.  If you are in the wrong directory or you
want to quit, type \texttt{X} followed by the return character \enter.
To check you are in
the right directory, on a Unix-like system you can type:
\begin{verbatim}
ls
\end{verbatim}
This will list the contents of
the directory.  If you are certain that you have spelt the filename
correctly and that you are in the right directory, there may be
something wrong with your path, in which case contact your system
administrator.

\item
Error messages will usually look something like:
\begin{verbatim}
! Undefined control sequence.
l.1 \docmentclass
                 [12pt]{scrartcl}
? 
\end{verbatim}
The first line is the error message.  In this example I~have misspelt
the command \cmdname{documentclass}.  The next line begins with
\texttt{l.}\ followed by a number.  This is the line number in the
source code where the error occurred.  In this case the error
occurred on line~1.  Following the line number is the input line
\LaTeX\ has processed so far, and staggered on the next line is the
remainder of the input line.

Here's another example.  Suppose line~8 of my 
\gls{source}
looks like:
\begin{verbatim}
The date today is: \toady, which is nice to know.
\end{verbatim}
The error in this case is the misspelling of the command 
\cmdname{today}.  The error message will appear as follows:

\begin{latexonly}
\noindent
\begin{tabular}{l@{}l}
\multicolumn{2}{l}{%
\texttt{!\ Undefined control sequence.}\rlap{\color{blue}%
\tikz[baseline=-1ex]{\draw[latex-] (0em,0ex) -- (4em,2ex);
\pgftext[left,center,at={\pgfpoint{4em}{2ex}}]{Error Message}
}}}\\
\texttt{l.}\smash{\llap{\color{blue}%
\tikz[baseline]{\draw[latex-] (0em,0ex) -- (-3em,-4ex);
\pgftext[right,top,at={\pgfpoint{-3em}{-3ex}}]{\shortstack{Line\\Number}}}}}%
\texttt{8 The date today is }%
\smash{\llap{\color{blue}%
\tikz[baseline]{\draw[latex-] (0em,0ex) -- (-3em,-3ex);
\pgftext[right,top,at={\pgfpoint{-3em}{-3ex}}]{Error}}}}%
\cmdname{toady}%
\smash{\rlap{\color{blue}%
\tikz[baseline]{\draw[latex-] (0em,0ex) -- (0em,-6ex);
\pgftext[left,top,at={\pgfpoint{0em}{-6.5ex}}]{This is how far \LaTeX\ has got}}}}\\
 &\texttt{, which is nice to know.}\smash{\rlap{\color{blue}%
\tikz[baseline]{\draw[latex-] (0em,0.5ex) -- (3em,0.5ex);
\pgftext[left,center,at={\pgfpoint{3em}{0.5ex}}]{\shortstack{Rest of\\the line}}}}}\\
\texttt{?}\color{blue}%
\tikz[baseline]{\draw[latex-] (0em,0ex) -- (2em,-4ex);
\pgftext[left,top,at={\pgfpoint{2em}{-4ex}}]{\LaTeX\ prompt}}
\end{tabular}

\vspace{\baselineskip}
\end{latexonly}
\html{\htmladdimg[alt="annotated error message"]{pictures/errormessage.png}}

At the \LaTeX\ prompt, you can either type \texttt{h} for a help 
message, or type \texttt{x} to exit \LaTeX\ and go back to your 
source code and fix the problem.
\end{itemize}

There follows below a list of common error messages. If your
problem isn't listed there, try the \gls{ukfaq}.

%%%%%%%%%%%%%%%%%%%% * (No message) %%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{asteriskprompt}
\section{* (No message, just an asterisk prompt!)}

You've gone into \gls{tex}!  This is probably because 
you've forgotten the \texttt{\gls{end}\marg{document}}.  The asterisk is the 
\TeX\ prompt.  At this point the best thing to do is to abort the
\TeX\ run.

%%%%%%%%%%%%% Argument of \cline has an extra } %%%%%%%%%%%%%%%%

\setnode{clineextrabrace}
\section{Argument of \textbackslash cline has an extra \}}

If this error occurred on the first line in your \gls{env-tabular}
\glsterm{environment}, you may have forgotten the
\glsterm{argument} to the \gls*{env-tabular} environment.

%%%%%%%%%%%%% Argument of \multicolumn has an extra } %%%%%%%%%%%%%%%%

\setnode{multicolumnextrabrace}
\section{Argument of \textbackslash multicolumn has an extra \}}

If this error occurred on the first line in your \gls{env-tabular}
\glsterm{environment}, you may have forgotten the
\glsterm{argument} to the \gls*{env-tabular} environment.

%%%%%%%%%%%%%%%% \begin{...} ended by \end{...} %%%%%%%%%%%%%%%%%%%%

\setnode{mismatchedend}
\section{\textbackslash begin\{\texorpdfstring{\ldots}{...}\} ended by 
\textbackslash end\{\texorpdfstring{\ldots}{...}\}}

The beginning of your environment doesn't have a matching end.
\begin{itemize}
\item Check to make sure you have spelt the name of the environment 
correctly.

You will get this error message if you do, say,
\begin{alltt}\wrong
\glsni{end}\marg{docment}
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{end}\marg{document}
\end{alltt}

\item Check that for every \gls{begin} you have a corresponding 
\gls{end} with the same name.
\end{itemize}

%%%%%%%%%%%%%%%%%%% Bad math environment delimiter %%%%%%%%%%%%%%%%

\setnode{badmathdelim}
\section{Bad math environment delimiter}

Only a certain type of character may be used as a 
\htmlref{delimiter}{sec:delimiters} (for example,
\gls{openparen} \gls{closeparen} \gls{delimiter.opensq}
\gls{delimiter.closesq}), check which one you have specified.  This error may 
also occur if you have forgotten a \gls{right} or not used it in the
same \glslink{group}{scope}.
(Remember to use a \gls{delimiter.periodchar} if you want an invisible delimiter) or 
you may have forgotten to end your array environment with 
\verb|\end{array}|.

%%%%%%%%%%%%%%%%%%%% Can only be used in preamble %%%%%%%%%%%%%%%%%%

\setnode{onlypreamble}
\section{Can only be used in preamble.}

Some commands, such as \gls{usepackage} may only appear in the 
\gls{preamble}.  Check to see where you have put 
it.  For example, this error will be caused by doing:
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{begin}\marg{document}\wrong

\glsni{usepackage}\marg{graphicx}
\end{alltt}
instead of
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{usepackage}\marg{graphicx}\correct

\glsni{begin}\marg{document}
\end{alltt}

%%%%%%%%%%%%%%%%%% Command ... already defined %%%%%%%%%%%%%%%%%%%%%

\setnode{alreadydef}
\section{Command \texorpdfstring{\protect\ldots}{...}\protect\space already defined}

You have tried to define a \gls{command} which 
already exists.  Try giving it a different name.  Remember never to
redefine a command if you don't know what the command originally
does.

Alternatively, you have tried to define an
\gls{environment} which already exists.  Give the new
environment a different name.  Again, never redefine an environment
where you don't know what the original environment does.

%%%%%%%%%%%%% Display math should end with $$ %%%%%%%%%%%%%%%%%%%%%

\setnode{missingenddispmath}
\section{Display math should end with \$\$}

You may have a dollar sign (\gls{dollarchar}) in a displayed maths
environment, such as the \gls{env-equation} environment.  
Remember that \verb|$| is short hand for \verb|\begin{math}| or 
\verb|\end{math}|, so you can't end one of the other environments 
with a \verb|$|. (This error message is in fact a bit confusing,
as it seems to be suggesting that you end a displayed maths
environment with \verb|$$| which you also shouldn't do\faq{Why use
\glsnl{begindispmath}\ldots\glsnl{enddispmath} in place of \$\$\ldots\$\$}{dolldoll}.)

%%%%%%%%%%%%%% Environment ... undefined %%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{envundefined}
\section{Environment \texorpdfstring{\protect\ldots}{...}\protect\space undefined}

\LaTeX\ doesn't recognise the environment you have specified.

\begin{itemize}
\item Check you have spelt the environment name correctly.

You will get this error if you do, say,
\begin{alltt}\wrong
\glsni{begin}\marg{docment}
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{begin}\marg{document}
\end{alltt}

\item If it's your own environment, check you have defined the
environment before using it.

\item If the environment is defined in a package, check you 
have included the package using the 
\htmlref{\cmdname{usepackage}}{sec:packages} command.

\end{itemize}

%%%%%%%%%% Extra alignment tab has been changed to \cr %%%%%%%%%%%%

\setnode{tab2cr}
\section{Extra alignment tab has been changed to \textbackslash cr}

You have too many ampersands (\gls{ampchar}) in one row.  The most 
probable cause is that you have forgotten the end of row command
\gls{tab.dbbackslashchar} on the previous row.  Remember also that if you have a
\gls{multicolumn} command to span more than one column, you
should have fewer \glsni{ampchar}s in that row. This error can also occur
from a confusion over the two meanings of \gls{dbbackslashchar}: a
line break within a paragraph cell and a row break.  In which case,
you need to use \gls{tabularnewline} instead of
\gls{tab.dbbackslashchar}.

%%%%%%%%%%%%%%%%%%%%%%%%% Extra \right %%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{extraright}
\section{Extra \textbackslash right}

There are a number of possible causes.  The most probable is that you
have a \gls{right} that doesn't have a matching \gls{left}.
(Remember left comes before right.)  Another possible cause is that
you have missed out \verb|\end{array}|.  (Remember that
\glspl{environment} provide implicit
\glsing{group}, and \glsni{left} and its matching
\glsni{right} must appear within the same group level.)

%%%%%%%%%%%%%% File ended while scanning use of ... %%%%%%%%%%%%%

\setnode{fileendedwhilescanning}
\section{File ended while scanning use of \texorpdfstring{\ldots}{...}}

The most usual cause of this error is a missing closing brace.

You will get this error if you do, say,
\begin{alltt}\wrong
\glsni{end}\glsni{leftbracechar}document
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{end}\marg{document}
\end{alltt}

%%%%%%%%%%%%%%%%%%%%%% File not found %%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{filenotfound}
\section{File not found}

\LaTeX\ can't find the file you have specified.  You will be given
the opportunity to type in the correct filename at the prompt.  If
you want to quit, simply type \texttt{X} followed by the return
character \enter.

\begin{itemize}

\item Make sure that you have spelt the filename correctly.

This error will be caused by, say,
\begin{alltt}\wrong
\gls{documentclass}\marg{scrarticle}
\end{alltt}
instead of
\begin{alltt}\correct
\gls{documentclass}\marg{scrartcl}
\end{alltt}

If this is the case, simply type in the correct name at the prompt 
(followed by the return character \enter) then go back and fix the
spelling in the \gls{source}.

\item Make sure that the file is in the same directory as your
document or in the \LaTeX\ path.  If the file is in another directory
(not in the \LaTeX\ path), you will need to specify the pathname, but
remember that when using \LaTeX\ under Windows, you need to use a
forward slash (\glsi{dir.slash}) as the directory divider, as a backslash would be
interpreted as a command.  For example, if you have a file called
\texttt{shapes.pdf} in the subdirectory \texttt{pictures} then you
would get a \dq{file not found} error message if you did
\begin{alltt}\wrong
\gls{includegraphics}\marg{shapes}
\end{alltt}
instead of
\begin{alltt}\correct
\gls{includegraphics}\marg{pictures/shapes}
\end{alltt}

\item If the file is a \htmlref{package}{sec:packages} or
\htmlref{class file}{sec:cls}, it's possible that you don't have that
file installed on your computer.  If this is the case you will need
to download and install it as described in
\appendixref{ch:installsty}.  Remember that you need to
refresh the database after installing a new package or class file.

\end{itemize}

%%%%%%%%%%%%%%%%%%%% Illegal character in array arg %%%%%%%%%%%%%%%%%%

\setnode{illegalarraychar}
\section{Illegal character in array arg}

You have used a character in the \gls{argument} of a
\gls{env-tabular} or \gls{env-array} environment that is not
allowed. The standard available characters are: \texttt{r} (right
justified), \texttt{l} (left justified), \texttt{c} (centred) and
\texttt{p}, as well as \gls{atchar}\marg{\meta{inter-col text}}.
Remember that if you want to use the \gls{gtcol}\marg{\meta{decl}} or 
\gls{ltcol}\marg{\meta{decl}} specifiers, you must include the
\isty{array} package.

This error will also occur if you have forgotten the argument to the
\gls*{env-tabular} or \gls*{env-array} environment.

%%%%%%%%%%%%%%%%%%% Illegal parameter number in definition %%%%%%%%%%

\setnode{illegalparamnum}
\section{Illegal parameter number in definition}

You have referred to a \htmlref{parameter (argument)
number}{sec:newcomarg} that is greater than the number of parameters
you have specified. For example, suppose you defined the command to
have only one parameter, then you can't use \gls{hashchar}\texttt{2}
which refers to the second, non-existent, parameter. Remember that
you need to specify how many parameters you want in the
\gls{optional} to \glsni{newcommand}, otherwise it will be assumed
that the command has no arguments.

%%%%%%%%%%%%%%%%%%%%% Illegal unit of measure %%%%%%%%%%%%%%%%%%%%%%%

\setnode{illegalunit}
\section{Illegal unit of measure (pt inserted)}

You have either not specified a unit when giving a \gls{length} (even zero
lengths must have a unit) or you have specified an invalid unit or
you have misspelt the unit.  Available units are listed in
\tableref{tab:units}.

%%%%%%%%%%%%%%%%% Lonely \item %%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{lonelyitem}
\section{Lonely \textbackslash item}

The command \gls{item} may only appear in one of the list making
environments (such as \gls{env-itemize}).  Make sure you haven't
forgotten your environment.

%%%%%%%%%%%%%%% Misplaced alignment tab character & %%%%%%%%%%%%%%%%%

\setnode{misplacedtab}
\section{Misplaced alignment tab character \&}

You have used the special character \gls{ampchar} where you shouldn't
have.  Recall from \sectionref{sec:chars} that if you want an \& sign 
to appear you need to do \gls{amp} not just \glsni{ampchar}.

You would have got this error message if you had done, say,
\begin{alltt}\wrong
\glsni{ampchar} our equipment
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{amp} our equipment
\end{alltt}

%%%%%%%%%%%%%%%%%%%%% Missing } inserted %%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{missingendbrace}
\section{Missing \} inserted}

You have missed a closing curly brace, or you may have missed out an
argument.

\xminisec{Example:} 
If the following line occurs in a tabular environment:
\begin{alltt}\wrong
 \gls{ampchar} \gls{multicolumn}\marg{2}\marg{c}\gls{tab.dbbackslashchar}
\end{alltt}
this will produce the error. (The third argument to 
\gls{multicolumn} has been omitted.)

%%%%%%%%%%%%%%%%%%%%% Missing $ inserted %%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{missingdollar}
\section{Missing \$ inserted}

This message can be caused by a number of errors:
\begin{itemize}
\item You might have missed the beginning of one of the mathematics
\glspl{environment} (that is, you've used a
\gls{command} that must only appear in maths mode).

\item You may have typed \gls{dollarchar} instead of \gls{dollar} (you
actually want a dollar symbol to appear).  Recall from
\sectionref{sec:chars} that if you
want a \$ sign to appear you need to do \glsni{dollar} not just \glsni{dollarchar}.

You would have got this error message if you had done, say,
\begin{alltt}\wrong
expenditure came to \glsni{dollarchar}2000.00
\end{alltt}
instead of
\begin{alltt}\correct
expenditure came to \glsni{dollar}2000.00
\end{alltt}

\item You may have missed the end of a mathematics environment, or
you may have a paragraph break within an in-line or
displayed maths environment, where it is
not permitted.  Make sure you don't have any blank lines within the
environment. If you want a blank line in your code to make it easier
to edit, try having a percent sign at the start of an empty line to
ensure that the line is ignored by \LaTeX. For example:
\begin{alltt}
\glsni{begin}\marg{equation}
\glsni{percentchar}
E = mc\glsni{circumchar}2
\glsni{percentchar}
\glsni{end}\marg{equation}
\end{alltt}
\end{itemize}

%%%%%%%%%%%%%%% Missing \begin{document} %%%%%%%%%%%%%%%%%

\setnode{missingbegindoc}
\section{Missing \textbackslash begin\{document\}}

You have put some text outside of the document 
\glsterm{environment}.  Check the following:
\begin{itemize}
\item You have remembered \verb|\begin{document}|

This error would be caused by, say,
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}
\wrong
This is a simple document
\end{alltt}
instead of
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{begin}\marg{document}\correct
This is a simple document.
\end{alltt}

\item You haven't placed any text before \verb|\begin{document}|. 
For example:
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

This is a simple document\wrong 
\glsni{begin}\marg{document}
\end{alltt}
instead of
\begin{alltt}
\glsni{documentclass}\marg{scrartcl}

\glsni{begin}\marg{document}\correct
This is a simple document
\end{alltt}

\item You haven't missed out the backslash at the start of either 
\gls{documentclass} or \glsni{begin}\marg{document}

This error would be caused by, say,
\begin{alltt}\wrong
documentclass\marg{scrartcl}
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{documentclass}\marg{scrartcl}
\end{alltt}
\end{itemize}

%%%%%%%%%%%%%%%%%%% Missing delimiter %%%%%%%%%%%%%%%%%%%%%%%

\setnode{missingdelim}
\section{Missing delimiter}

You have forgotten to specify the type of delimiter you want (for
example, 
\gls{openparen} \gls{closeparen} \gls{delimiter.opensq} \gls{delimiter.closesq}
\gls{leftbrace} \gls{rightbrace}). (Remember to use a \gls{delimiter.periodchar} if you want 
an invisible delimiter, and remember that if you want a 
curly brace, you must have a backslash followed by the curly brace.)

\xminisec{Example:}

This error will occur if you do, say,
\begin{alltt}\wrong
f(x) = \glsni{left}\glsni{leftbracechar}
\glsni{begin}\marg{array}\marg{ll}
0 \glsni{ampchar} x \cmdname{leq} 0\gls{tab.dbbackslashchar}
1 \glsni{ampchar} x > 1
\glsni{end}\marg{array}
\glsni{right}.
\end{alltt}
instead of
\begin{alltt}\correct
f(x) = \glsni{left}\glsni{leftbrace}
\glsni{begin}\marg{array}\marg{ll}
0 \glsni{ampchar} x \cmdname{leq} 0\gls{tab.dbbackslashchar}
1 \glsni{ampchar} x > 1
\glsni{end}\marg{array}
\glsni{right}.
\end{alltt}

%%%%%%%%%%%%%%%% Missing \endcsname inserted %%%%%%%%%%%%%%%%

\setnode{missingendcsname}
\section{Missing \textbackslash endcsname inserted}

This is a \gls{tex} error rather than a \LaTeX\ error
which makes it harder to determine the cause, however it can be
caused by placing a backslash in front of the name of an
\gls{environment}.  (Remember that
\gls{environment} names do not contain a backslash.)

This error will be caused by, say,
\begin{alltt}\wrong
\glsni{begin}\marg{\glsni{sffamily}}
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{begin}\marg{sffamily}
\end{alltt}

%%%%%%%%%%%%%% Missing \endgroup inserted %%%%%%%%%%%%%%%%%%

\setnode{missingendgroup}
\section{Missing \textbackslash endgroup inserted}

A number of things could have caused this.  You may have missed out
the end of an \gls{environment}, or you may have an
environment inside of another environment it's not allowed to be in.
For example, this error can be caused by placing an
\envname{eqnarray} environment inside a \envname{displaymath}
environment, which is not allowed. (But, of course, you haven't
used either of those obsolete environments~\cite{l2tabu}, have you?) 

%%%%%%%%%%%%%%% Missing number %%%%%%%%%%%%%%%%%%

\setnode{missingnum}
\section{Missing number, treated as zero}

\LaTeX\ is expecting a number. If your command takes more than one
\gls{argument}, check to make sure the arguments are in
the correct order.  For example, if you are using a
\gls{env-minipage} environment, you might have
omitted the \gls{mandatory} which
specifies the width of the minipage, or you may have the
\glspl{optional} the wrong way round.  The placement specifier
should come first, followed by the height.

If you are using \gls{addtocounter} or \gls{setcounter} 
remember that the second argument must be a number, so if you want 
the value of a counter as the argument you must use \gls{value}.
This error can be caused by, say,
\begin{alltt}\wrong
\glsni{setcounter}\marg{exercise}\marg{chapter}
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{setcounter}\marg{exercise}\marg{\glsni{value}\marg{chapter}}
\end{alltt}

%%%%%%%%%%%%%% Paragraph ended %%%%%%%%%%

\setnode{parended}
\section{Paragraph ended before \textbackslash begin was complete}

You've probably missed a closing brace at the end of the argument to
\gls{begin}.  This error will be caused by, say,
\begin{alltt}\wrong
\glsni{begin}\glsni{leftbracechar}document
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{begin}\marg{document}
\end{alltt}

%%%%%%%%%%%%%%%%%%% Runaway argument %%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{runawayarg}
\section{Runaway argument}

There are a number of possible causes of this error:

\begin{itemize}

\item Paragraph breaks are not permitted in the
\glspl{argument} of \glspl{short}.
If there is a corresponding \gls{environment} then you
should use that instead.  For example, this error message will be
generated by doing, say,
\begin{alltt}
\glsni{textbf}\glsni{leftbracechar}This is a simple document.
Here is the first paragraph.
\wrong
Here is the second paragraph.\glsni{rightbracechar}
\end{alltt}
instead of\bookpagebreak
\begin{alltt}
\glsni{begin}\marg{bfseries}
This is a simple document.
Here is the first paragraph.
\correct
Here is the second paragraph.
\glsni{end}\marg{bfseries}
\end{alltt}

\item The closing brace of a 
\gls{mandatory} is missing:
This error will be caused by, say,
\begin{alltt}\wrong
\glsni{title}\glsni{leftbracechar}A Simple Document
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{title}\marg{A Simple Document}
\end{alltt}

\item This error can also be caused by omitting the 
\gls{mandatory} of an \gls{environment}.  For example, 
this error will occur
if you do, say,
\begin{alltt}\wrong
\glsni{begin}\marg{thebibliography}
\glsni{bibitem}\marg{kopka95} A Guide to \glsni{LaTeXe}
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{begin}\marg{thebibliography}\marg{1}
\glsni{bibitem}\marg{kopka95} A Guide to \glsni{LaTeXe}
\end{alltt}

\end{itemize}

%%%%%%%%%%%%%%% Something's wrong--perhaps a missing \item %%%%%%%%%%%%%%%%

\setnode{missingitem}
\section{Something's wrong--perhaps a missing \textbackslash item}

You may have missed an \gls{item} command.  The first object in
a list environment must either be an \gls{item} command, or another
list environment.

This error will be caused by, say,
\begin{alltt}\wrong
\glsni{begin}\marg{itemize}
Animal
\glsni{item} Vegetable
\glsni{item} Mineral
\glsni{end}\marg{itemize}
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{begin}\marg{itemize}
\glsni{item} Animal
\glsni{item} Vegetable
\glsni{item} Mineral
\glsni{end}\marg{itemize}
\end{alltt}

\bookpagebreak
This error can also be caused by a missing \gls{bibitem} in the
\htmlref{bibliography}{sec:bib}.  For example, the error will occur
if you do, say,
\begin{alltt}\wrong
\glsni{begin}\marg{thebibliography}\marg{1}
A Guide to \glsni{LaTeXe}
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{begin}\marg{thebibliography}\marg{1}
\glsni{bibitem}\marg{kopka95} A Guide to \glsni{LaTeXe}
\end{alltt}

See also \gls{ukfaq} entry: \faqlink{Perhaps a missing \cmdname{item}?}{errmissitem}.

%%%%%%%%%%%%%%%%% There's no line here to end %%%%%%%%%%%%%%%%%%%%%

\setnode{nolinetoend}
\section{There's no line here to end}

You have placed a line breaking command (such as \gls{newline.dbbackslashchar},
\gls{newline} or \gls{linebreak}) where it doesn't make
sense to have one.

%%%%%%%%%%%%%%%%% Undefined control sequence %%%%%%%%%%%%%%%%%%%%%%

\setnode{csundefined}
\section{Undefined control sequence}

\LaTeX\ doesn't understand the \gls{command} you
have used.  

\begin{itemize}
\item Check to see if you have misspelt the command name (remember
that all \LaTeX\ command names are case-sensitive.)

You will get this error if you do, say,
\begin{alltt}\wrong
This is a simple \cmdname{Latex}\glsni{spacesym}document
\end{alltt}
instead of
\begin{alltt}\correct
This is a simple \gls{LaTeX}\glsni{spacesym}document
\end{alltt}

\item Check that you have remembered the space when typing
\gls{spacesym} (backslash space).
For example, this error will occur if you do, say,
\begin{alltt}\wrong
This is a \cmdname{LaTeX}\cmdname{sample} document.
\end{alltt}
instead of
\begin{alltt}\correct
This is a \glsni{LaTeX}\glsni{spacesym}sample document
\end{alltt}

\item If you are using a command that is defined in a
\htmlref{package}{sec:packages} make sure you have included the
package using \gls{usepackage}.

\item Check that your command name hasn't run into the next piece
of text.  For example,
you can do
\begin{alltt}
man\glsni{oe}\marg{}uvre
\end{alltt}
or
\begin{alltt}
man\glsni{oe} uvre
\end{alltt}
or (not recommended)
\begin{alltt}
man\marg{\glsni{oe}}uvre
\end{alltt}
but not
\begin{alltt}\wrong
man\cmdname{oeuvre}
\end{alltt}

\item Check if you have used a backslash instead of a forward slash as a
directory divider.  (Remember that when using \LaTeX\ under Windows,
you need to use a forward slash (\glsi{dir.slash}) as the directory divider, as a
backslash would be interpreted as a command.)

For example, suppose you have a file called \texttt{shapes.pdf} in a 
subdirectory called \texttt{pictures}, then you would get an error 
if you did
\begin{alltt}\wrong
\glsni{includegraphics}\marg{pictures\cmdname{shapes}}
\end{alltt}
instead of
\begin{alltt}\correct
\glsni{includegraphics}\marg{pictures/shapes}
\end{alltt}

\end{itemize}

%%%%%%%%%% You can't use `macro parameter character #' in horizontal mode %%%%%%%%%%%%%%%

\setnode{hashinhmode}
\section{You can't use `macro parameter character \#' in horizontal mode}

You have used the special character \gls{hashchar} where you shouldn't
have.  Recall from \sectionref{sec:chars} that if you want a \# sign to appear you need
to do \gls{hash} not just \glsni{hashchar}.

This error message will be caused by doing, say,
\begin{alltt}\wrong
Item \glsni{hashchar}1
\end{alltt}
instead of
\begin{alltt}\correct
Item \glsni{hash}1
\end{alltt}

\setnode{help}
\chapter{Need More Help?}
\label{ch:help}

First, try to find your query in the \gls{ukfaq}. \Gls{tug}
also has a list of useful resources at
\url{http://tug.org/interest.html}. If you're still stuck, you can
post your question on a (La)TeX forum, newsgroup or mailing list,
such as those listed below. If you do post a question, remember
you're asking people who only have an altruistic interest in
helping. No one is paying them to help you. Most of the class files
and packages were written for free by people who had a need to solve
a particular problem and decided to make their work publicly
available. So no matter how frustrated you're feeling, stick to
being polite. If you can't work out how to use a particular class or
package, don't start by heaping offensive, unconstructive criticism on it as there's a chance
the author will read the message. There's no sense in alienating the
person most qualified to answer your question. In your message,
stick to the following guidelines:
\begin{enumerate}
\item Cut to the chase. In other words, be concise about the nature
of the problem. Don't write lots of long-winded paragraphs.

\item Provide a minimal
example\footnote{see \url{http://www.dickimaw-books.com/latex/minexample/}} that 
illustrates the problem.

\end{enumerate}

\xminisec{Example:}
\begin{verbatim}
I'm trying to use the \foo command in the "bar" package, 
but I'm getting the following error message:
! Undefined control sequence.
l.4 \foo

Here's a minimal example:
\documentclass{scrartcl}
\usepackage{bar}
\begin{document}
\foo{Blah}
\end{document}

I'm using bar version 1.0 (2012/06/30).
\end{verbatim}

\xminisec{Another example:}
\begin{verbatim}
I'm using the \foo command in the "bar" package. According
to the documentation, this command should display its argument
in a bold font, but it's coming out in italic instead. 
Anyone know why?

Here's a minimal example:
\documentclass{scrartcl}
\usepackage{bar}
\begin{document}
\foo{Blah}
\end{document}

I'm using bar version 1.1 (2012/07/30).
\end{verbatim}

There's no guarantee that you will get an answer, but if you follow
the above guidelines, you will increase your chances.

\xminisec{Resources}
\begin{itemize}

\item The \LaTeX\ Community (\url{http://www.latex-community.org/}).

\item \TeX/\LaTeX\ on StackExchange
(\url{http://tex.stackexchange.com/}).

\item \htmladdnormallink{\texttt{comp.text.tex}
newsgroup}{http://groups.google.com/group/comp.text.tex} (use a
newsreader rather than the Google interface if you want to avoid the
spam).

\item \htmladdnormallink{\texttt{texhax} archives}{http://tug.org/pipermail/texhax/}\doifbook{~\cite{texhax}}.

\end{itemize}
I~strongly recommend that you also have a look at the On-Line
Catalogue~\cite{texcat}.
It's also a good idea to look at the documentation that was
installed with your \TeX/\LaTeX\ distribution (see
\sectionref{sec:texdoc}). If you are using \itexdistro{MiKTeX} you can access the
on-line help via the Start Menu: \startmenu{MiKTeX \menuto\ Help}

(Please don't send your problems to me, unless you want to hire a
consultant. I~read both the \LaTeX\ Community Forum and
\texttt{comp.text.tex} and answer relevant questions if I~have time,
but it clogs up my inbox if people keep sending attachments that are in
the order of several megabytes in size.) Besides, you'll reach a
wide group of experts if you post to a newsgroup, forum or mailing
list, rather than a single busy individual.

%%%%%%%%%%%%%%%%%%%%%%%%%% Supplemental Material %%%%%%%%%%%%%%%%%%%

\ifpdf\else\input{supplemental}\fi

\backmatter

%%%%%%%%%%%%%%%%%%%%%%%%%%% Bibliography %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\clearpage\phantomsection
\setnode{bibliography}
\bibliographystyle{plain}
\bibliography{novices}

%%%%%%%%%%%%%%%%%%%%%%%%%%%% GLOSSARIES %%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{acronyms}
\printglossary[type=acronym,nonumberlist,style=acronyms]

\setnode{summary}
\setdoublecolumnglo
\printglossary[style=summary]

\setnode{bookindex}
\printindex

%%%%%%%%%%%%%%%%%%%%%%%%% LICENCE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{licence}
\chapter{GNU Free Documentation License}
\input{../fdl}

%%%%%%%%%%%%%%%%%%%%%%%%%% HISTORY %%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setnode{history}
\chapter{History}\markright{History}

\historyitem{25th Sept 2012 (Version 1.4)}

\begin{itemize}
\item Paperback edition~1 produced.
\item Added TeXWorks section.
\item Moved \dq{Text editor and Terminal approach}, \dq{TeXnicCenter}
and \dq{WinEdt} sections to new supplementary material.
\item Added hardcopy-related code.
\item Change to \koma\ classes (both for examples and for pdf
versions of this document).
\item Changed from using \sty{subfloat} to \sty{subcaption} package.
\item Added section on inter-sentence spacing.
\item Moved \dq{Errors} and \dq{Where to get Help?} to appendices.
\item Moved section \dq{Downloading and Installing Packages} to
new appendix chapter.
\item Moved introduction to packages to \dq{Creating a Simple
Document}.
\item Moved datetime section to \dq{Creating a Simple Document}
chapter. (Removed reference to ukdate package.)
\item Moved babel section to \dq{Structuring Your Document} chapter.
\item Moved graphicx section to its own chapter.
\item Added section on align.
\item Added \cmdname{cfrac}, \cmdname{substack} and \sty{amsmath} ellipses to maths chapter.
\item Added extensible arrows and \cmdname{bigl} etc to maths
chapter.
\item Added booktabs.
\item Moved lengths chapter to section in definitions.
\item Added summary chapter with commands hyperlinked to their
definitions in the summary.
\item Changed definitions chapter to use a glossary structure.
\item Moved bibliography into bib file.
\item Added \sty{varioref}.
\item Removed dependency on \sty{html} package (for pdf versions)
to avoid conflict between \sty{html} and \sty{varioref}
(\sty{html} package functions not defined by \sty{hyperref}
now emulated; \sty{comment} package loaded to provide
\envname{htmlonly} environment).
\item Removed image of equation written in Word (Microsoft have
improved their equation rendering) and added link to
Murray Sargent~III blog~\cite{sargentiii}.
\item Added section on what a terminal/command prompt is.
\item Added section on auxiliary files.
\item Added section on Perl.
\item Added information about latexmk
\item Mentioned grffile package.
\item Mentioned on-the-fly EPS conversion.
\item Mentioned \sty{etoolbox}'s \cmdname{appto} and \sty{babel}'s
\cmdname{addto}.
\item Changed to UTF-8 and mostly changed to using code points
instead of named entities in HTML files.
\item Moved the document's home page from
\url{http://theoval.cmp.uea.ac.uk/~nlct/latex/novices/} to
\url{http://www.dickimaw-books.com/latex/novices/}.
\end{itemize}

\historyitem{15th Jan 2008 (Version 1.3)}

The main reason behind this change was to increase accessibility and
conform to W3C guidelines. If you are experiencing problems relating
to accessibility, please let me know (clearly stating the problem).
\begin{itemize}
\item Corrected error in the university's post code on the
title page
\item Added alternative text tags to more of the images, and made
some of the images hyperlinks to a more detailed description of the
image.
\item Added information on how to break ligatures.
\item Moved information on TeX to the introduction, and removed
section on TeX that was in the "Some Definitions" chapter.
\item Document nodes now have permanent names instead of the generic
node\meta{n}.html which \LaTeX2HTML generates by default.
\item Went back to using straight double quotes in the HTML document
as the fancy typographic double quotes are nonstandard.

\end{itemize}

\historyitem{8th May 2007 (Version 1.2)}

\begin{itemize}
\item Links to \gls{ukfaq} added.
\item Overview made into a separate section, and tidied up a bit.
\item Added some extra definitions: moving arguments and fragile
commands, robust commands, short and long commands.
\item Changed \dq{Text editor and Terminal approach} to deal with
Unix-type systems rather than MS-DOS.
\item Moved section on \envname{tabular} environment.
\item Added section on boxes and mini-pages.
\item Segmented section on font changing commands.
\item Segmented section describing \sty{graphicx}.
\item Added section on the \sty{babel} package.
\item Updated and segmented section on downloading and installing
new packages.
\item Added section on side-by-side figures.
\item Updated section on sub-figures to use the new \sty{subfloat}
package instead of the obsolete \sty{subfigure} package.
\item Added \dq{Need More Help?} chapter.
\end{itemize}

\backcoverheading
(See \url{http://www.gnu.org/licenses/fdl-howto-opt.html#SEC2}.)

\backcovertext
\end{document}