summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex3/galley/galley2.dtx
blob: a2fd84c8e16e97905d12bc1f622bb1cf37b233ab (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
% \iffalse
%%
%% $Header: /usr3/users/latex3/design/consolidation/CURRENT/RCS/galley2.dtx,v 1.15 2000/01/27 21:45:56 latex3 Exp $
%%
%% (C) Copyright 1999-2000 Frank Mittelbach
%% All rights reserved.
%%
%% Not for general distribution. In its present form it is not allowed
%% to put this package onto CD or an archive without consulting the
%% the authors.
%% 
%<*dtx>
          \ProvidesFile{galley.dtx}
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{galley2}
%<driver>\ProvidesFile{galley.drv}
% \fi
%         \ProvidesFile{galley2.dtx}
          [2000/01/27 v0.2s galley structures]
%
% \iffalse
%<*driver>
 \documentclass{ltxdoc}
 \typeout{********}
 \typeout{* Unpack with:}
 \typeout{* \string\generate{%
  \string\file{galley2.sty}{\string\from{galley2.dtx}{package,trace}}}
 }
 \typeout{********}
% \usepackage{ldcdoc}
% \makeatletter 
%   \let\GAL@typeout\@gobble \let\GAL@show@datastructure\@gobble
% \makeatother

 \newcommand\LaTeXplus{\LaTeXe$*$}

 \CodelineIndex \EnableCrossrefs
 \renewcommand\MakePrivateLetters{\makeatletter\catcode`\:11\relax}
 \begin{document}
 \DocInput{galley2.dtx}
 \end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \newcommand\PARM[1]{parameter \textbf{#1}}
% \newcommand\subsubsubsection{\paragraph}
%
%
% \GetFileInfo{galley2.dtx}
%
% \title{The \textsf{galley} package\thanks{This file
%         has version number \fileversion, last
%         revised \filedate.}}
% \author{FMi}
% \date{\filedate}
% \maketitle
%
% \begin{abstract}
%   This module provides the data structure for galleys and contains
%   the low-level interfaces for direct manipulation of this data structure.
%   Higher-level templates for interfacing with the
%   galley mechanism are set up by the module
%   \texttt{xhj}.
%   The low-level interfaces of the current module are  geared
%   towards package writers having special needs which are not
%   fulfilled by the templates in the \texttt{xhj} module.
%   They are not intended to be used directly in class design.
% \end{abstract}
%
% \tableofcontents
% 
% \section{Introduction}
%
% In \LaTeXplus{} terminology a galley is a rectangular area which
% receives text and other material filling it from
% top.\footnote{The predominant direction depends on the writing
% system and with extensions to \TeX{} such as Omega there are
% possibilities to define galleys with a different filling direction.}
% The vertically extend of a galley is normally not restricted 
% (there are exceptions); instead certain chunks are taken off the top
% of an
% already partially filled galley to form columns or similar areas
% on a page. This process is typically asynchronous but there are ways
% to control or change its behavior.
%
% Examples for galleys are `the main galley', where the continuous
% document data gets formatted into  and from which columns and pages are
% constructed, and  `vbox galley's, such as the body of  a minipage
% environment or the body of a float (in \LaTeXe only---the new float
% mechanism for \LaTeXplus{} will employ horizontally oriented float
% bodies). The latter galleys are typically not being split after
% formatting though there can be exceptions.
%
% The data that is being formatted into a galley can be described as a
% sequence of paragraphs of text separated by vertical material such
% as vertical spaces, penalties, writes, specials, etc.
%
% There are two components that a mechanism for galleys has to provide:
% the framework for manipulating the shape and placement of paragraph
% text (this is provided with higher-level templates in the module
% \texttt{xhj}) and the framework for manipulating the inter-paragraph
% material. 
% 
% 
% 
% \subsection{Some problems with \LaTeXe{} galleys}
%
% The handling of inter-paragraph material poses the most difficult
% problems as it is typically influenced by various factors and
% information gained at different stages throughout the document
% processing. \LaTeXe{} provided a certain control over this material,
% e.g., headings would set a |@nobreak| flag to prevent paragraph
% breaking after them and other commands and environments would test
% for it; |\addvspace| and |\addpenalty| could be used several times
% in succession and still provide reasonable results, but all in all
% these have been adhoc solutions to the most pressing problem of that
% area---many others remained unsolved:
% 
% The following is a list of document extracts which one can imagine
% to appear in ordinary documents. They all have in common that in
% \LaTeXe{} they produce surprising (and undesired) results:
% \begin{enumerate}
% \item
% \begin{verbatim}
% \end{itemize} \vspace{3pt} \begin{itemize} ...
%\end{verbatim}
% \ldots not three points of extra space but 13 (with
%       the \texttt{article} class)
% 
% \item
% \begin{verbatim}
% \section{HEAD} {\sc ABC} ...
%\end{verbatim}
% \ldots page breaking restrictions apply to the
%       second paragraph after the heading not the first as they
%       should
% \item
% \begin{verbatim}
% \usepackage{hyperref}
%\end{verbatim}
% \ldots the danger of completely changed vertical spacing because
%       the |\special|s added by \texttt{hyperref} interfere with the
%       spacing and penalty mechanisms of \LaTeXe
% 
% 
% \item
% \begin{verbatim}
% {\section{HEAD}} para text \par \begin{itemize} ...
%\end{verbatim}
%   \ldots one gets an indentation after the heading; a page break might
%   happen after the first line in the paragraphs; and there will be no
%   space above the itemize environment (though there will be space
%   below) --- because of this \LaTeXe{} claims this is incorrect input
%   --- and then since \LaTeX\,2.09 uses the equivalent of
%   |\twocolumn[\chapter{HEAD}]| in certain circumstances in the report
%   and book class :-)
% \end{enumerate}
%
% All these pitfalls are due to the fact that \LaTeXe{} typesets the
% inter-paragraph material whenever it receives it and once it is
% typeset \TeX{} has only a limited power to modify the material
% already present on the galley.
%
% Thus to be able to do better one has to defer any typesetting until
% the very last moment (i.e., when the next paragraph starts) and
% instead collect such inter-paragraph material in a suitable data
% structure where it can be manipulated and examined.
% The present code in this module provides such a data structure. Of
% course, to be successful it is important that all functions that
% would normally produce inter-paragraph material (such as user
% commands like |\vspace|) obey the concepts behind the mechanism and
% refrain from directly adding to the galley.
% How this is achieved will be explained in the next sections.
%
%
% \section{The galley data structure}
%
% A galley is a \LaTeX{} object which contains (or receives)
% paragraphs and typesets them vertically below each other intermixed
% with material like vertical spaces and penalties, etc.\ which are
% placed between such paragraphs.
%
% Galleys can be nested and thus data structures associated with them
% need to be provided using a stack structure.
%
% Technical aspects of the implementation of this structure are
% discussed in section~\ref{sec:galley-concept-impl}.
%
%
% \subsection{Writes, marks, specials and inserts}
%
% Writes, marks, specials and inserts are internally represented by
% \TeX{} as invisible objects (nodes) within the horizontal or
% vertical lists of \TeX. The
% problem with this is that they interfere with other nodes, produce
% additional break points, etc.
%
% For this reason they should not appear on their own but need to be
% placed into precisely controlled places. They can either go directly
% after the last line of a paragraph (preceded and followed by
% |\nobreak|) or they can go directly in front of the next
% paragraph. Table~\ref{tab:vthing} lists the different nodes and
% their suggested handling.
% \begin{table}
% \begin{center}
% \begin{tabular}{ll}
% \hline
%   vthing & attach to \\
% \hline
%   insert & prev \\
%   write  & prev or next (flag) \\
%   mark   & prev or next (flag) \\
%   special (hyperref) & prev or next (different command) \\
%   special (others)   & next
% \end{tabular}
% \end{center}
% \small            ^^A well designed object :-)
% \begin{quote}
%   prev := just add to MVL followed by |\nobreak| \\
%   next := store tokens and put in a primitive ``in hmode at start of
%    next para''
% \end{quote}
% \caption{Invisible nodes and their handling}\label{tab:vthing}
% \end{table}
%
%
% \subsection{Individual parameters}
%
% Each parameter related to a galley exists in two incarnation:
% \begin{itemize} 
% \item it has one value which is considered to be static for a
%   sequence of paragraphs (potentially for all paragraphs typeset on
%   this level); any change to it via some mutator command will
%   persist until a further change or the end of the level --- called
%   static galley parameter value (SGPV)
% \item it has one value which is reset after each use to the
%   corresponding static value --- called dynamic galley parameter
%   value (DGPV).
% \end{itemize}
%
% The actual processing routines always use the DGPVs. Thus to produce
% a paragraph sequence with a certain uniform setting of parameters
% one would set up (or modify) the SGPVs, and to locally overwrite
% individual values for one paragraph one would modify the relevant DGPVs.
%
%
% \subsubsection{Vertical (pre-paragraph) parameters}
%
% \begin{description}
% \item[nobreak flag (b)] a flag that signals how page breaking should
%   be handled
%   between the previous and the upcoming paragraph; it takes a number
%   between 0 and 3 with the following meaning: 0 means normal
%   breaking behavior (value of \PARM{penalty} is used), 1 means
%   prevent break between paragraphs (value of \PARM{penalty} is
%   discarded and replaced by 10000), 2 is like 1 but additionally
%   prevents\footnote{as far as possible with \TeX} a page break
%   within the first lines of the upcoming paragraph (by fiddling with
%   |\clubpenalty|), 3 is like 1 but also suppresses a page break for
%   the whole upcoming paragraph (by setting
%   |\interlinepenalty|)\footnote{One can actually implement something
%   even better: with e\TeX{} more control is possible and with normal
%   \TeX{} one could prevent a break for a minimum of X lines by
%   checking on the value of \texttt{\textbackslash prevgraf} and decreasing this for the next
%   time around}
%   At the moment it also supports negative numbers ($-3$ especially)
%   which have the same meaning as the positive counterparts except
%   that they only influence the breaking within the paragraph, e.g.,
%   $-3$ do not break within the next paragraph (which is useful for
%   initials etc). However this should probably be redesigned properly!
% \item[vpenalty (p)] penalty between paragraphs unless flag above is set
% \item[vspace (v)]   skip between paragraphs as set by class or package
%   commands, if -1sp then |\parskip| is used instead.\footnote{This
%   -1sp is a speedup measure to avoid the need for an additional flag
%   for suppressing or adding \texttt{\textbackslash parskip}, this way
%   between normal paragraphs  \texttt{\textbackslash parskip} is
%   added (as the default for this parameter is -1sp) but any setting
%   will result in suppressing it. Of course this means if some
%   environment requests some space it does get 1sp less, acceptable?
%   Using 0pt instead is not a good idea as it makes it difficult to
%   state for some environment that all space should be suppressed.}
% \item[user vpenalty (up)] penalty between paragraphs set by user level
%   commands
% \item[user vspace (uv)] additional space between paragraphs set by user level
%   commands. This space is always added and never suppressed or subject
%   to functions like using the maximum, since it is provided by
%   user commands like |\vspace| where we assume that the user intends
%   to correct the default result.
% \item[prev whatsits (pw)] whatsits that are supposed to get attached to
%   the previous paragraph
% \item[parshape (ps)] structured parameter that sets up a \TeX{}
%   |\parshape| declaration or empty; it replaces the next two parameters
%   in the current implementation. However for reasons of secure
%   programming it might be necessary to have all three. (Right now
%   |\linewidth| and |\@totalleftmargin| are locally set when
%   modifying the ps parameter and thus are in danger of getting out
%   of sync if setting happens not at group boundaries.
% \item[measure (m)] nominal width of the upcoming paragraph lines
%   (|\linewidth| is  set to this value)\footnote{Not used right now
%   see comment on ps parameter.}
% \item[hoffset (h)] offset for the upcoming paragraph lines from the left
%   margin (in \LaTeXe{} this was
%   |\@totalleftmargin|).\footnote{Not used right now, see comment on
%   ps parameter.}
% \end{description}
%
%
% \subsubsection{Paragraph-start parameters}
%
% \begin{description}
% \item[indentation (i)] flag to suppress insertion of indentation
%    box. A value of 0 means insert indentation any other value suppresses
%    indentation.
% \item[next whatsits (nw)] whatsits that are supposed to get attached to
%   the next paragraph
% \item[object (o)]  typeset material at the start of the paragraph
% \item[queries (q)] information about previously seen objects/states
%   on the galley that can be queried by following code as necessary,
%   e.g., the fact that we just have processed an `item', or a
%   `heading', or \ldots
%
%   This parameter is not yet properly used and perhaps becomes
%   obsolete once there is a proper mechanism for handing such data.
% \end{description}
%
%    
% \subsubsection{Paragraph-justification parameters}
%
% The following parameter is supposed to define the inner shape of a
% paragraph, e.g., adjusted, centered lines, ragged shapes, etc. It
% is not meant to define the measure (for this see the \PARM{parshape}).
% \begin{description}
% \item[justification (j)] This is a multivalued parameter consisting of
%      \begin{itemize}
%        \item the counterpart to |\parfillskip| at the
%              beginning of a paragraph
%        \item the \TeX{} |\leftskip|
%        \item the \TeX{} |\rightskip|
%        \item the \TeX{} |\parfillskip|
%        \item the \TeX{} |\spaceskip|
%        \item the \TeX{} |\xspaceskip|
%        \item glue specification to be put in front of a forced ``newline''
%        \item the \TeX{} |\parindent|\footnote{This parameter should
%           perhaps be taken out, there is some dicussion related to
%           this elsewhere.}
%      \end{itemize}
% \end{description}
%
% \subsubsection{Line breaking parameters}
%
% Line breaking parameters are considered to be not related to
% individual paragraphs but to paragraphs sequences, i.e., they are
% not reset on each paragraph. Wrong? Instead they are initialized at
% start of galley and are otherwise only settable via templates. One
% could of course make them a multivalued parameter as well.
%
%
%
% \subsubsection{Paragraph-end parameters}
%
% None defined yet (but perhaps should)
%
%
%
% \subsection{Document level (user) commands}
%
% \subsubsection{Penalties}
%
%  To give the user a chance to actually overwrite a penalty setting
%  produced from environments or commands internally updating the
%  galley structure, user level document commands like |\nopagebreak|
%  do not modify the internal \PARM{penalty} but instead use a
%  \PARM{user penalty}. If that parameter is set (i.e., non-empty) it
%  will get used and the internal \PARM{penalty} that is normally
%  applied will be ignored. This way, even in situations where the
%  user request appears too early in the document (e.g., between
%  environments where the following environment would modify
%  \PARM{penalty} the desired outcome is ensured.
%
% \subsubsection{Vertical spaces}
%
% In contrast user commands for specifying vertical space will always
%  add to the existing space.\footnote{Always? i can image to have the
%  desire to explicitly set the space to a fixed value in which case i
%  would like to ensure that the internal value for \PARM{vspace} is
%  fully ignored. On the other hand this may not been sensible because
%   it might be difficult for the user to know how big the space should
%   be.}
%
%
% \subsection{Galley structure after lists/displays}\label{sec:endlist}
%
% After lists or a math display the continuation depends on whether
% the following text logically   is part of the previous material or
% starts a new  paragraph. This difference is coded in the source
% document by leaving or not leaving an empty line (|\par|).
%
% Depending on this the handling of the upcoming paragraph might
% differ in \PARM{penalty}, \PARM{vspace}, \PARM{indent} (and perhaps
% others)
%
% To allow for this a processing mechanism like this should be
% investigated\footnote{There is some concept code for this below but
% it is not finished!}:
% \begin{itemize}
% \item
%   The environment that intends to make use of the structure sets a flag
% \item
%   The values of parameters for the case of the paragraph continuing
%    the previous material are specified by modifying the DGPVs.
% \item
%   The values of parameters for the case that the next paragraph is
%    to be considered independent are specified in a third structure
%    (called XGPV for now) which is a plist like the SGPV (or part of
%    it if we don't allow to modify any odd rubbish in that case,
%    which is probably sensible)
% \item
%    The code for the |\par| command is augmented in a way that if it
%    is executed in vertical mode the following happens:
%    \begin{itemize}
%    \item
%      The values in the XGPV are added to the DGPV values to allow
%      for user level changes to be preserved.
%    \item
%      The flag above is reset so that following |\par| does not
%      modify the DGPV further.
%    \end{itemize}
% \end{itemize}
% The XGPV has to be stored away if a new galley level is initiated!
%
%
%
%
%
% \section{The low-level command interface}
%
% The commands described in this section are used to update the galley
% data structure. Their intended use is a) in kernel code, i.e., in
% parts that are already provided by the \LaTeXplus{} kernel such as
% the basic float mechanism and b) as building blocks for higher-level
% templates such as those defined by the module \texttt{xhj} or the
% module \texttt{xinitials}.
% They are not meant to be used directly when building classes.
%
% Their names are currently very strange and inconsistent and need to
% be normalized.
%
%
%
% \subsection{Manipulating the dynamic galley parameters values}
%
% To manipulate the dynamic parameter values of the galley structure a
% number of commands are available. As explained above changing the
% dynamic parameters effects the only next paragraph (or the next sequence
% of vertical objects between paragraphs) --- afterwards the
% parameters are reset to the values stored in their static counterparts.
%
% \noindent
% \DescribeMacro{\setDGPVthing:nn}\marg{id}\marg{value} \\
% The |\setDGPVthing:nn| command takes a parameter \meta{id} (or more
% exactly its letter or letter sequence such as `j' or `ps') and
% assigns the \meta{value} to it. No processing of the value is
% undertaken.
% 
% \noindent
% \DescribeMacro{\appendtoDGPVthing:nn}\marg{id}\marg{value} \\
% \DescribeMacro{\appendtoDGPVthing:no}
% The |\appendtoDGPVthing:nn| also leaves the \meta{value} unchanged
% but appends it to the current value of the parameter. This is, for
% example, used to build the list of whatsits nodes in the \PARM{next
% whatsits} parameter.
%
% \noindent
% \DescribeMacro{\setDGPVdimension:nn}\marg{id}\marg{value} \\
% \DescribeMacro{\addDGPVdimension:nn}
% \DescribeMacro{\maxDGPVdimension:nn}
% In contrast the family of |\...DGPVdimension:nn| commands process the
% \meta{value} by interpreting it as a calc dimension expression. The
% result is then set (|\set...|), or added to the current value
% (|\add...|), or compared with the current value (|\max...|) and the
% maximum assigned.
%
% \noindent
% \DescribeMacro{\setGALpenalty:n}\marg{value} \\
% \DescribeMacro{\addGALpenalty:n}
% What is available for dimensions is also available for integer
% valued parameters. However, since there is only one such parameter
% (the \PARM{penalty}) at the moment, we provide a family of commands
% which take only a \meta{value} argument.
%
% \noindent
% \DescribeMacro{\setGALobject:n}\marg{value} \\
% \DescribeMacro{\setGALbreak:n}
% The |\setGALobject:n| and |\setGALbreak:n| are special variants of
% the |\setDGPVthing:nn| command for the \PARM{object} and
% \PARM{nobreak flag} parameters, respectively.\footnote{should
% probably vanish}
%
% \noindent
% \DescribeMacro{\setGALleftparshape:nnn}\marg{\# of normal lines}
%   \marg{default width} \marg{delta offset list} \\
% \DescribeMacro{\setGALrightparshape:nnn}
% Defines a special parshape (that is it sets the \PARM{parshape}
% taking into account its current setting with respect to the galley
% measure) at the left or the right starting with
% a number of normal lines (first arg) followed by a number of special
% lines which are constructed assuming a hole of a certain width
% (second argument). The number of lines this hole exists vertically is
% defined by the number of delta offsets in the in comma separated
% third argument. The width of each delta is added to the nominal
% width of the hole thus allowing for special corrections on a line by
% line basis.
%
%
%
% \subsection{Manipulating the static galley parameters values}
%
% Manipulating the static galley parameters essentially means changing
% the default values to which these parameters are restored to at the
% end of each paragraph. These commands always set the corresponding
% dynamic parameter as well.
%
% \noindent
% \DescribeMacro{\setSGPVthing:nn} \marg{id} \marg{value}\\
% Like |\setDGPVthing:nn| but for long-term changes, e.g., no
% processing of \meta{value} is undertaken.
%
% \noindent
% \DescribeMacro{\setSGPVdimension:nn} \marg{id} \marg{value} \\
% Like |\setDGPVdimension:nn| but for long-term changes, e.g., the
% \meta{value} is evaluated using calc prior to assigning it to the
% parameter.
%
% There are no commands for making long-term changes to other parts of
% the interface. Mostly because they seemed to be unnecessary. If
% needed they could be added without much problem.
%
%
%
% \subsection{Manipulating the galley measure}
%
% In the current implementation the galley measure, i.e., the width of
% text lines and their indentation from the left are not represented
% by a galley parameter directly. Instead they are internally stored
% as part of the \PARM{parshape} (see discussion above). For
% this reason that parameter can't be (or rather shouldn't be)
% modified directly but only through the commands below and commands
% like |\setGALleftparshape:nnn| which know baout those dependencies
% and handle the update accordingly.
%
% \noindent
% \DescribeMacro{\setSGPVmeasure:nn} \marg{left-margin}
%                                 \marg{line-width} \\
% This command make a long-term change to the measure by setting the
% width of
% the line to \meta{line-width} and the width of the left margin to
% \meta{left-margin}. In addition it sets the registers |\linewidth|
% and |\@totalleftmargin| to these values (for inspection).
%
% \noindent
% \DescribeMacro{\addSGPVmeasure:nn}
%           \marg{left-margin-increment} \marg{line-width-increment}\\
% This command make a long-term change to the measure by incrementing the
% width of of the line with \meta{line-width-increment} and the width
% of the left margin with  \meta{left-margin-increment}. In addition
% it sets the registers |\linewidth| 
% and |\@totalleftmargin| to the resulting values (for inspection).
%
%
%
%
%
% \subsection{Saving and restoring SGPV changes}
%
% \DescribeMacro{\GALsavegalleystate:} \\
% \DescribeMacro{\GALrestoregalleystate:} This pair of commands stores
% and retrieves the current state of the SGPVs and can be used with
% environments that want to make long term changes and revert to the
% old settings afterwards, i.e. use |\GALsavegalleystate:| at the
% beginning, before doing any modification, and then
% |\GALrestoregalleystate:| at the end. They should be called at the
% same level of grouping (as the saving is done locally) and with the
% current implementation they can't be called several times on the
% same level.\footnote{Or so i think; which is something we may not be
% able to leave as that}
%
%
% \subsection{Manipulating the behavior of \texttt{\textbackslash par}}
%
% The |\par| command in \TeX{} is perhaps the most troublesome item of
% the language for the simple reason that it can't be sucessfully
% trapped by the macro programmer and hidden from (mis)use. 
% When \TeX{} sees an empty line it converts it into the token |\par|
% and this name is fixed and can't be changed. It is easy to provide
% special definitions for the action taken when this token is
% processed but there is no way to prevent somebody from overwriting
% those carefully designed interfaces by simply doing something like
% |\let\par\foo|. If this happens anything might go wrong and since
% |\par| is a name that can't be hidden from the user nor from the
% package designer the only thing one can do is to boldly state that
% \begin{center}
%  \bfseries Manual changes to |\par| are not supported!
% \end{center}
%
% Having said this we now present the interfaces that can be used to give
% |\par| a special meaning within \LaTeXplus. It should be stressed
% that |\par| always has a special meaning within the galley mechanism
% and that direct changes to it, at best lead to incorrect formatting,
% far more likely however will lead to disaster.
%
% \noindent
% \DescribeMacro{\setGALnormalpar:}\\
% This command defines |\par| to have its standard definition within
% the galley mechanism, i.e., if a paragraph is currently processed it
% will be finished (including all code necessary, e.g., execute end of
% paragraph hooks) and preparations are undertaken to initialize the
% data structure to be ready to processes inter-paragraph material
% and/or start a new paragraph.
%
% \noindent
% \DescribeMacro{\setGALignoredpar:n} \marg{error text}\\
%    The
%    |\setGALignoredpar:n| changes |\par| so that it does nothing for
%    a while, outputting the \meta{error text} after 3 successive
%    |\par|s.\footnote{That command should probably be replaced in favor
%    of the one below as it is quite dangerous if used in horizontal
%    mode (see comments in the code section, there may be no way to
%    gain control!)} 
%
% \noindent
% \DescribeMacro{\setGALendlistpar:}
%    A special definition for |\par| at the end of list like
%    structures. The code for this is currently not functional, some
%    ideas regarding this can be found in section~\ref{sec:endlist}
%    and in the code section.
%
% \noindent
% \DescribeMacro{\GALignorepars:n}\marg{error text} \\
%   A sort of |\ignorespaces| but for spaces and |\par|s. Should of
%   course only be used as the last command in expansion (and may need
%   support within |\end| handling---the latter is not done)
% 
%
% \section{Open issues}
%
% In this section unresolved issues or ideas to think about and
% perhaps implement are collected. There is no particular order to
% them.
%
% \begin{itemize}
% \item
%   It seems advisable to change the way galleys are set up: don't
%   automatically start a new galley with each vbox but instead start
%   a galley only in dedicated ``galley-boxes'' such as the internal
%   form of |\parbox| etc. The advantage is much less overhead, the
%   disadvantage is that non-conforming packages (written without this
%   mechanism in mind) will 99\% fall over while with the current setup
%   they have a good chance to survive and produce more or less proper
%   formatting.
% \item
%   |\@totalleftmargin| and |\linewidth| need to be adequately dealt
%   with, probably by integrating them properly into the data structure
%   somehow at the parshape level.
% \item
%   It is quite likely that we need more granularity on the interfaces
%   for storing and restoring the galley state. There need to be a
%   full store and restore for cases where an unrelated galley is
%   started in the middle of some other galley (such as formatting a
%   marginal paragraph in the middle of the main galley) but it is not
%   appropriate to store and restore the whole galley state when
%   formatting a list inside a galley (what is wanted there is to
%   store and restore the outer measure, the outer parshape, etc.\ but
%   not any registers which deal with penalties, vertical spaces
%   between paragraphs and so on. So |\GALsavegalleystate:| needs some
%   companion!
% \item
%   Not properly integrated into the whole scheme are math displays
%   (Michael Downes will hopefully come to rescue me here at some point).
% \end{itemize}
%
%
%
% \StopEventually{}
% 
% \section{Implementation}
%
% Set up certain defaults including to ignore white space
% within the body of this package. \LaTeXe{} release needs to be
% recent because of changing some bits of the |\parbox| handling below.
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}[1998/12/01]
\RequirePackage{ldcsetup}
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{xhj} % taken out of this file
%    \end{macrocode}
%
%    \begin{macrocode}
\IgnoreWhiteSpace
%    \end{macrocode}
%
%    The code does use `:' characters in command names (basically
%    inherited from expl3 and property list code I took from there for
%    the first proto-type implementation). Right now it is a bit of a
%    nuisance since using `:' should either be integrated into
%    |\IgnoreWhiteSpace| and friends or otherwise probably not be
%    used.
%    \begin{macrocode}
\catcode`\:=11\relax
%    \end{macrocode}
%
%
% \subsection{Tracing}
%
% \begin{macro}{\tracinggalleys}
%    A complicated mechanism like the galley interface needs some
%    tracing facilities. Here we provide some modeled after
%    \TeX's internal low-level tracing functions.
%    \begin{macrocode}
\def\tracinggalleys{\afterassignment\@tracinggalleys\count@}
%<-trace>\let\@tracinggalleys\relax
%    \end{macrocode}
%
%    If we compile this module without tracing than |\tracinggalleys|
%    will scan away an integer assignment but otherwise does
%    nothing. But if we docstrip with tracing included then depending
%    on the integer values the following things happen:
%    \begin{description}
%    \item[0] No tracing.
%    \item[1] All tracing info is written to the log file only.
%    \item[2] All tracing info is written to the terminal.
%    \item[3 and higher] All tracing info is written to the terminal
%      and before it is presented a quick check for other internal
%      \TeX{}-tracing is undertaken. If it looks as if |\tracingall|
%      is currently used then various tracings are temporarily disable
%      to avoid getting the output of the tracing being traced as
%      well. This prevents getting many many uninteresting output
%      lines which would otherwise appear.
%
%      This value can only be used if e\TeX{} in extended mode is used
%      as the formatter, as it sets |\tracingassigns|\footnote{Really
%      useful that primitive, try it one day if you got stuck while
%      macro writing, that alone is worth using e\TeX{} for.} which is
%      not a primitive of \TeX.
%    \end{description}
%
%    \begin{macrocode}
%<*trace>
\def\@tracinggalleys{
  \ifcase \count@
    \let\GAL@typeout\@gobble
%    \end{macrocode}
%
% We can't let |\Gal@typout| simply to |\wlog| if we don't want to see
% tracing on the screen since that does expand its argument and
% produces havoc in some cases, so here is a slightly slower variant.
%    \begin{macrocode}
  \or
    \def\GAL@typeout ##1{
       \begingroup
           \let\protect\@unexpandable@protect
           \wlog {##1}
       \endgroup
    }
%    \end{macrocode}
%    If |\tracinggalleys| is set to 2 we show a lot of tracing data.
%    \begin{macrocode}
  \or
    \let\GAL@typeout\typeout
%    \end{macrocode}
%    And another variant when lowlevel tracing is called for. This
%    version does assume that e\TeX{} is being used as it tries to set
%    |\tracingassigns|, so it will fail if this assumption is incorrect.
%    \begin{macrocode}
  \else
    \def\GAL@typeout ##1{
       \ifnum\tracingmacros>\z@
       \begingroup
         \tracingassigns\z@
         \tracingcommands\z@
         \tracingrestores\z@
         \tracingmacros\z@
         \typeout{##1}
       \endgroup
       \else
         \typeout{##1}
       \fi
    }
  \fi
}
%</trace>
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GAL@typeout}
%    This macro is used below to display some tracing info. By default
%    no tracing happens.
%    \begin{macrocode}
\let\GAL@typeout\@gobble
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Taking away primitives from direct use}
%
% To make this mechanism work we have to shield the primitive \TeX{}
% parameters from direct access by the user or a package writer. We do
% this by giving them internal names of the type
% |\GAL@@|\meta{param-name} and the allocating under the original
% parameter name a suitable register to trap any direct access.
%
% We have to trap |\clubpenalty| and |\interlinepenalty|; both are used
% to prohibit page breaking in paragraphs.
%    \begin{macrocode}
\let\GAL@@clubpenalty\clubpenalty
\newcount\clubpenalty
\let\GAL@@interlinepenalty\interlinepenalty
\newcount\interlinepenalty
%    \end{macrocode}
%
% See comments below why this is not needed.
%    \begin{macrocode}
%\let\GAL@@brokenpenalty\brokenpenalty   
%\newcount\brokenpenalty                 
%    \end{macrocode}
%
% And of course we have to trap |\everypar| since this token register
% is one of the central bits of the algorithm. It is used to gain
% control at the start of a new paragraph and actually put the stored
% galley data structure for inter-paragraph material onto the page.
%    \begin{macrocode}
\let\GAL@@everypar\everypar
\newtoks\everypar
%    \end{macrocode}
%
% Not sure if we really need to trap |\parindent|, anyway here it is:
%    \begin{macrocode}
\let\GAL@@parindent\parindent \GAL@@parindent\z@
\newdimen\parindent
%    \end{macrocode}
%
% The |\parskip| parameter is a real nuisance, we really do not want
% it at all as we handle our inter-paragraph spaces ourself. However,
% we can't get rid of it, best we can do is to make it always zero.
%
% Setting the then alocated |\parskip| register will not have any
% effect at all.\footnote{Perhaps it should: i.e., at least produce a
% warning or error message.}
%    \begin{macrocode}
\let\GAL@@parskip\parskip    \GAL@@parskip\z@
\newskip\parskip
%    \end{macrocode}
%
% The next block is trapping those parameters which are responsible
% for the justification, ie
%    \begin{macrocode}
\let\GAL@@leftskip\leftskip
\newskip\leftskip
\let\GAL@@rightskip\rightskip
\newskip\rightskip
\let\GAL@@parfillskip\parfillskip
\newskip\parfillskip         \parfillskip\@flushglue
%    \end{macrocode}
%
% And while we are at it, we might as well allocate two additional
% skips which are related to justification: |\GAL@@startskip| the
% counterpart to |\GAL@@parfillskip| at the beginning of the paragraph
% and |\GAL@@linefillskip| which will hold the space to be inserted
% before a forced newline (as in |\\|).
%    \begin{macrocode}
\newskip\GAL@@startskip
\newskip\GAL@@linefillskip
%    \end{macrocode}
%
% |\spaceskip| and |\xspaceskip| are needed when doing proper ragged
% settings so they are part of the interface.
%    \begin{macrocode}
\let\GAL@@spaceskip\spaceskip
\newskip\spaceskip
\let\GAL@@xspaceskip\xspaceskip
\newskip\xspaceskip
%    \end{macrocode}
%
% The next is not yet (but perhaps it should be as well).
%    \begin{macrocode}
\let\GAL@@lineskip\lineskip
\newskip\lineskip
%    \end{macrocode}
%
%
%
% \subsection{Some extra scratch registers}
%
% Those registers are needed by the mutator functions and we better
% not rely on general scratch registers (at least not for the
% moment). The box register is for the indentation box.
%    \begin{macrocode}
\newcount\GAL@cnta
%    \end{macrocode}
%
%    \begin{macrocode}
\newskip\GAL@skipa
\newskip\GAL@skipb
%    \end{macrocode}
%
%    \begin{macrocode}
\newbox\GAL@boxa
%    \end{macrocode}
%
%
%
% \subsection{Galley data structure}\label{sec:galley-concept-impl}
%
% \subsubsection{Original concepts}
%
% In earlier implementations of \texttt{galley2.dtx}, galley objects
% have been represented in the following fashion:
%
% \begin{itemize}
% \item the long range values are stored in a within one level in
%   global a plist with the name |\GAL@static@hmode@plist| which is a
%   property list keeping all individual galley values for hmode. The
%   keys in the property list are of the form
%   |\GAL@|\meta{letter(s)}|@|.
% \item a copy of this plist is saved away under the name
%   |\GAL@static@hmode@|\meta{level-num}|@plist| just before we start
%   a new level so that when returning to a level the previous state can
%   be reconstructed.\footnote{Instead of doing a global save under a
%    name associated with the level number we could probably simply
%    save the list locally and use the savestack since each new level
%    has to be always associated with a new group anyway!}
% \item the keys in the above plists are also used directly as global
%   variables holding the actual current values of the galley object
%   parameters which allows fast access.
% \item similar plists exists for vmode and perhaps we want even
%   more\footnote{but perhaps not, putting the parameters in different
%   plists is mainly a speed thing, we can use flags to reinit only
%   things that have changed; the lists are shorter which makes
%   property handling faster, etc, but it needs some careful studying
%   at a later stage whether this is really beneficial---in principle
%   there is no problem with keeping all parameters in a single plist.}
% \end{itemize}
% This means that to make a long-term change to some galley object
% parameter one has to change the property within the
% |\GAL@static@|\meta{h/v}|mode@plist|. Such a change is then
% propagated to both the saved version as well as the global key
% commands.
%
% \subsubsection{Current concepts}
%
% After some evaluation I decided to change this setup in favour of
% the following:
%
% \begin{itemize}
% \item Actual values are represented by global control sequences of
% the form |\GAL@|\meta{letter(s)}|@|.
% \item If they are supposed to be reset after each usage their
% long-term (static) value is recorded globally in
% |\GAL@|\meta{letter(s)}|@s|. 
% \item When starting a new galley level saved versions of the
% dynamic parameters are stored locally in |\GAL@|\meta{letter(s)}|@l|
% and those for the static parameters are stored in
% |\GAL@|\meta{letter(s)}|@sl|. When the level is popped those values
% are used to restore the state of the parameters. A consequence of
% this setup is that starting a new galley state should always involve
% a new group level!
% \end{itemize}
% This means that to make a long-term change to some galley object
% parameter one has to change the the |\GAL@|\meta{letter(s)}|@s|
% parameter  (if it exists) as well as the |\GAL@|\meta{letter(s)}|@|
% one.
%
% If a new parameter is added to this setup we have to modify the
% following functions below: |\GAL@init@static|,
% |\GAL@save@galleystate|, \\
% |\GAL@restore@galleystate|, and
% |\GAL@init@dynamic@fully|.
%
% \begin{macro}{\GAL@init@static}
% The |\GAL@init@static| function initialises the static and dynamic
% parameters with fixed defaults. This is, for example, used when
% starting a new level. At a later state one probably want to be able
% to globally set even those defaults for a whole document, but for
% now this is probably okay.
%
%    \begin{macrocode}
\def\GAL@init@static {
          \gdef\GAL@b@s  {\z@}
          \gdef\GAL@p@s  {\z@}
          \gdef\GAL@v@s  {-1sp}
          \gdef\GAL@uv@s {\z@}
          \gdef\GAL@up@s {}
          \gdef\GAL@pw@s {}
          \gdef\GAL@j@s  {\z@\leftskip\rightskip\parfillskip
                          \spaceskip\xspaceskip\parfillskip\parindent}
          \gdef\GAL@o@s  {}
          \gdef\GAL@ps@s {}
          \gdef\GAL@i@s  {\z@}
          \gdef\GAL@nw@s {}
          \gdef\GAL@q@s  {}
%    \end{macrocode}
%
%    The definition of |\par| is kind of static.\footnote{Do we need
%    to set the internal version of \texttt{\textbackslash everypar}
%    as well?}
%    \begin{macrocode}
   \setGALnormalpar:
%    \end{macrocode}
%
%    Having the static parameter updated we have to initialise the
%    dynamic ones as well.
%    \begin{macrocode}
   \GAL@init@dynamic@fully
%    \end{macrocode}
%    The seldom used parameters for linebreaking and
%    hyphenation are not subject to the galley concept but are set for
%    the whole galley. For this reason the code below should be moved
%    outside this macro.
%
%    We interface to a default template instance so that the default
%    can be easily overwritten on the class level.\footnote{bad idea?
%    good idea?}
%    \begin{macrocode}
   \UseInstance{hj}{default}
%% alternative
%%   \UseInstance{hyphenation}{default}
%%   \UseInstance{linebreak}{default}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\GALsavegalleystate:}
% The |\GALsavegalleystate:| function saves away a copy of the current
% static plists in a way that it can be retrieved when returning to
% the current level. In the new implementation this means locally
% saviing all the dynamic parameters to their local counterparts
% (i.e., |\GAL@|\meta{letter}|@| to  |\GAL@|\meta{letter}|@|l) and the
% same for the static parameters.
%    \begin{macrocode}
\def\GALsavegalleystate: {
          \let\GAL@b@l \GAL@b@
          \let\GAL@p@l \GAL@p@
          \let\GAL@v@l \GAL@v@
          \let\GAL@uv@l \GAL@uv@
          \let\GAL@up@l \GAL@up@
          \let\GAL@pw@l \GAL@pw@
          \let\GAL@j@l \GAL@j@
          \let\GAL@o@l \GAL@o@
          \let\GAL@ps@l \GAL@ps@
          \let\GAL@i@l \GAL@i@
          \let\GAL@nw@l \GAL@nw@
          \let\GAL@q@l \GAL@q@
%
          \let\GAL@b@sl \GAL@b@s
          \let\GAL@p@sl \GAL@p@s
          \let\GAL@v@sl \GAL@v@s
          \let\GAL@uv@sl \GAL@uv@s
          \let\GAL@up@sl \GAL@up@s
          \let\GAL@pw@sl \GAL@pw@s
          \let\GAL@j@sl \GAL@j@s
          \let\GAL@o@sl \GAL@o@s
          \let\GAL@ps@sl \GAL@ps@s
          \let\GAL@i@sl \GAL@i@s
          \let\GAL@nw@sl \GAL@nw@s
          \let\GAL@q@sl \GAL@q@s
%    \end{macrocode}
% The current definition of |\par| is handled manually (really
% manually)\footnote{Now this is pretty dangerous but i'm not sure
% this can be avoided: if \texttt{\textbackslash par} is being
% manually changed outside the control of these macros we might end up
% in deep shit. For example the old definition of tabular does this
% and the result is pretty bad, ie endless loop with
% \texttt{\textbackslash par} being a noop. any ideas?}
%    \begin{macrocode}
  \let\saved@GAL@par\par
%    \end{macrocode}
% We also have to track the state of the |\GAL@reassign@list|:
%    \begin{macrocode}
  \let\saved@GAL@reassign@list\GAL@reassign@list
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GALrestoregalleystate:}
% And here we have the reverse operation which is needed when we
% return to a previous level.
%    \begin{macrocode}
\def\GALrestoregalleystate: {
          \global\let\GAL@b@ \GAL@b@l
          \global\let\GAL@p@ \GAL@p@l
          \global\let\GAL@v@ \GAL@v@l
          \global\let\GAL@uv@ \GAL@uv@l
          \global\let\GAL@up@ \GAL@up@l
          \global\let\GAL@pw@ \GAL@pw@l
          \global\let\GAL@j@ \GAL@j@l
          \global\let\GAL@o@ \GAL@o@l
          \global\let\GAL@ps@ \GAL@ps@l
          \global\let\GAL@i@ \GAL@i@l
          \global\let\GAL@nw@ \GAL@nw@l
          \global\let\GAL@q@ \GAL@q@l
%
          \global\let\GAL@b@s \GAL@b@sl
          \global\let\GAL@p@s \GAL@p@sl
          \global\let\GAL@v@s \GAL@v@sl
          \global\let\GAL@uv@s \GAL@uv@sl
          \global\let\GAL@up@s \GAL@up@sl
          \global\let\GAL@pw@s \GAL@pw@sl
          \global\let\GAL@j@s \GAL@j@sl
          \global\let\GAL@o@s \GAL@o@sl
          \global\let\GAL@ps@s \GAL@ps@sl
          \global\let\GAL@i@s \GAL@i@sl
          \global\let\GAL@nw@s \GAL@nw@sl
          \global\let\GAL@q@s \GAL@q@sl
%    \end{macrocode}
%    \begin{macrocode}
  \global\let\par\saved@GAL@par
  \global\let\GAL@reassign@list\saved@GAL@reassign@list
%    \end{macrocode}
%    As long as we to not set up the individual paragraph shape
%    parameters each time (see comments in
%    |\GAL@set@horizontal@objects|) we have to restore them at this
%    point as well.
%    \begin{macrocode}
  \expandafter \setup@paragraph@justification \GAL@j@
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\saved@GAL@par}
% Recover from confusion: the top-level definition of |\saved@GAL@par|
% should never get assigned to |\par| but in case it is (by getting
% the grouping wrong) we better try to recover
% gracefully\footnote{Gracefully meaning I haven't bothered with
% producing anything other than an undefined csname error :-)}, so
% instead of ending up with a |\par| being an undefined command we do
% the following:
%    \begin{macrocode}
\def\saved@GAL@par{\ERROR\GAL@normal@par}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GAL@init@dynamic@as@necessary}
%    Whenever parameters got changed for one paragraph the
%    |\GAL@reassign@list| gets extended with an assignment that resets
%    the parameter back to its static value. The
%    |\GAL@init@dynamic@as@necessary| then executes this list and afterwards
%    define it to be empty.
%    \begin{macrocode}
\def\GAL@init@dynamic@as@necessary {
%<*trace>
  \GAL@typeout{Reinit~ parameters \on@line}
  \GAL@typeout{\@spaces \meaning  \GAL@reassign@list}
%</trace>
  \GAL@reassign@list
  \global\let\GAL@reassign@list\@empty
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GAL@init@dynamic@fully}
%    Sometimes we want to ensure that all parameter are set to their
%    static values. This is done by the |\GAL@init@dynamic@fully| macro..
%    \begin{macrocode}
\def\GAL@init@dynamic@fully {
%<*trace>
  \GAL@typeout{Reinit~ parameters \on@line}
%</trace>
          \global\let\GAL@b@ \GAL@b@s
          \global\let\GAL@p@ \GAL@p@s
          \global\let\GAL@v@ \GAL@v@s
          \global\let\GAL@uv@ \GAL@uv@s
          \global\let\GAL@up@ \GAL@up@s
          \global\let\GAL@pw@ \GAL@pw@s
          \global\let\GAL@j@ \GAL@j@s
          \global\let\GAL@o@ \GAL@o@s
          \global\let\GAL@ps@ \GAL@ps@s
          \global\let\GAL@i@ \GAL@i@s
          \global\let\GAL@nw@ \GAL@nw@s
          \global\let\GAL@q@ \GAL@q@s
%    \end{macrocode}
%    And since everything is as the static value there is nothing for
%    us to reassign so be make this list empty.
%    \begin{macrocode}
         \global\let\GAL@reassign@list\@empty
}
%    \end{macrocode}
%  \end{macro}
%
%
% \begin{macro}{\GAL@reassign@list}
%    The |\GAL@reassign@list| holds the parameters that need to be
%    reset at the next paragraph or more exactly it holds the
%    assignments that do the resetting. So by default this is empty.
%    \begin{macrocode}
\let\GAL@reassign@list\@empty
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\GAL@prepare@reassign:NN}
%    The |\GAL@prepare@reassign:NN| macro receives the internal names
%    of dynamic and and static placeholder for a parameter and extends
%    the |\GAL@reassign@list|.
%    \begin{macrocode}
\def\GAL@prepare@reassign:NN #1#2{
%    \end{macrocode}
%    It might pay off to make a quick check whether or not the value
%    of the dynamic parameter really differs from those of the static
%    one. If not we can avoid updating the |\GAL@reassign@list| which
%    takes some time and further more makes later updates of this list
%    slower.\footnote{This needs some empirical  testing: if most
%    of the time this test results in false then it might be better to
%    remove it though. One such test indicated that removal might be
%    better but this isn't far from being conclusive.}
%    \begin{macrocode}
  \ifx#1#2 
  \else
    \appendtoDGPV@internal:Nn\GAL@reassign@list
          {\global \let #1 #2 }
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GAL@prepare@reassign:n}
%    In contrast |\GAL@prepare@reassign:n| takes only the id for a
%    parameter, such as |v| or |up|. It also has some extra code to
%    check if the parameter is actually one that has both dynamic and
%    static incarnations.\footnote{In the current implementation this
%    is probably always the case but if we re-add \texttt{m} and
%    \texttt{h} we may not want to reset them on every paragraph but
%    handle them always as static for the whole galley.} If not we
%    don't need to reassign.\footnote{Furthermore, for speed
%    consideration it might be advisable to internally always replaces
%    the call to this command by \texttt{GAL@prepare@reassign:NN}
%    since this will always saves at least one extra csname parsing.}
%    \begin{macrocode}
\def\GAL@prepare@reassign:n #1{
  \expandafter\ifx \csname GAL@#1@s\endcsname \relax
%<*trace>
    \GAL@typeout{Not~ reassigning~ for~ #1!}
%</trace>
  \else
    \expandafter
    \GAL@prepare@reassign:NN
       \csname GAL@#1@ \expandafter \endcsname
       \csname GAL@#1@s \endcsname
 \fi
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
% \subsubsection{Starting and ending a level}
%
% The |\GAL@start@level| command first saves away the current state
% and then starts a new group. This group (|\bgroup|) will be matched
% by the closing brace of the current ``vbox'' either the explicit |}|
% or an |\egroup| equivalent of that. The |\GAL@cleanup@level| which
% then gets into control is supposed to restore the state and finally
% issue and |\egroup| which will then actually end the box.
%
% \begin{macro}{\GAL@start@level}
%    \begin{macrocode}
\def\GAL@start@level{
         \GALsavegalleystate:
         \bgroup
%<*trace>
           \advance\GAL@level@num\@ne
           \GAL@typeout{Entering~ galley~ level:~
                        \the\GAL@level@num~ \on@line}
%</trace>
           \GAL@init@static
           \@GAL@if@first@on@leveltrue     % temp solution!
                                           % see below
           \aftergroup\GAL@cleanup@level}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\GAL@level@num}
%    The counter is really only necessary if tracing is compiled in,
%    however we define it always just to ensure that the allocation
%    doesn't change if tracing is added.
%    \begin{macrocode}
\newcount\GAL@level@num
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@GAL@if@first@on@level}
%    This belongs to some hack which needs some better
%    implementation. It signals that we are at the beginning of a galley.
%    \begin{macrocode}
\newif\if@GAL@if@first@on@level
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GAL@cleanup@level}
%    \begin{macrocode}
\def\GAL@cleanup@level{
    \par
    \GAL@finish@typesetting
%<*trace>
    \GAL@typeout{Returning~ to~ galley~ level:~  \the\GAL@level@num~ \on@line}
%</trace>
    \GALrestoregalleystate:
  \egroup
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\GAL@finish@typesetting}
%  At the end of a galley (if in vmode) we have to ensure that we
%    don't have any dangling bits in the data structure (like
%    untypeset specials or writes that want to make their appearance
%    at the beginning of the next paragraph. This is what
%    |\GAL@finish@typesetting| is supposed to take care
%    of\footnote{one day}.
%    \begin{macrocode}
\def\GAL@finish@typesetting {}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\everyvbox}
%    We start a new galley with every vbox.
%    \begin{macrocode}
\everyvbox{\GAL@start@level}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\insert}
%    Interestingly enough |\everyvbox| is not triggered by |\inserts|
%    even though those are also vboxes so we have to do it manually
%    here (and that is a bit of a pain~\ldots).
%    \begin{macrocode}
\let\@@insert\insert
%    \end{macrocode}
%    There are cases where after the |\insert| we have stuff like
%    |\csname ...\endcsname| and to ensure that we don't fall over in
%    that case our redefinition has to be a bit elaborate. Of course
%    all this is only of interest if we stay with the current
%    implementation of always automatically starting a galley.
%    \begin{macrocode}
\long\def\insert #1#{\@insert{#1}}
\long\def\@insert #1#2{\@@insert#1{\GAL@start@level#2\par}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GAL@ignore@next@galley}
% \begin{macro}{\GAL@ignore@next@galley@vbox}
%    We may not need the next two commands at all if we change from
%    setting up a galley everywhere to setting up galleys only for
%    ``minipage'' like vboxes. And i think we should!
%    \begin{macrocode}
\def\GAL@ignore@next@galley{
  \everyvbox{\global\everyvbox{\GAL@start@level}}
}
\def\GAL@ignore@next@galley@vbox{
  \everyvbox{\global\everyvbox{\GAL@start@level}}\vbox
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsubsection{Using the galley data structure}
%
% \begin{macro}{\GAL@show@datastructure}
%    Some tracing to show the state of the data structure.
%    As some internal params take arbitrary content we have to be a bit careful
%    displaying them. Needs (some:-) improvement to be useful.
%    \begin{macrocode}
%<*trace>
\def \GAL@show@datastructure #1{
    \GAL@typeout{#1^^J
       \@spaces nominal~ width~ =~ \the\hsize ^^J
       \@spaces left~ indentation~ =~ \the\@totalleftmargin ^^J
       \@spaces break~ switch~ (b)~ =~ \GAL@b@ \space (\GAL@b@s) ^^J
       \@spaces v-penalty~ (p)~ =~ \GAL@p@ \space (\GAL@p@s) ^^J
       \@spaces v-space~ (v)~ =~ \GAL@v@ \space (\GAL@v@s) ^^J
       \@spaces user~ v-penalty~ (up)~ =~ \GAL@up@ ^^J
       \@spaces user~v-space~ (uv)~ =~ \GAL@uv@ ^^J
       \@spaces prev-whatits~ (pw)~ =~ \meaning \GAL@pw@ ^^J
       \@spaces next-whatits~ (nw)~ =~ \meaning \GAL@nw@ ^^J
       \@spaces parshape~spec~ (ps)~ =~ \GAL@ps@ \space (\GAL@ps@s) ^^J
       \@spaces queries~ (q)~ =~ \meaning \GAL@q@ ^^J
       \@spaces indent~ flag~ (i)~ =~ \GAL@i@  \space (\GAL@i@s) ^^J
       \@spaces para~ object~ (o)~ =~ \meaning \GAL@o@ ^^J
       \@spaces para~ justification~ (j)~ =~ \meaning \GAL@j@ }
}
%</trace>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\GAL@use@on@para}
% The next function is called when \TeX{} switches to horizontal mode,
% i.e., at the start of a paragraph.
% 
%    \begin{macrocode}
\def\GAL@use@on@para{
%<*trace>
  \GAL@show@datastructure{Para~ start~ for~ galley~ 
                          level~ \the\GAL@level@num \on@line}
%</trace>
%    \end{macrocode}
%    At the start of a new galley we do not want to have any vertical
%    space being inserted not even a zero |\parskip| since that would
%    mess up use of |\vtop| etc.  The below is a sort of crude fix for
%    the problem ie this is the old minipage switch.
%
%    What about a redesign???
%    \begin{macrocode}
  \if@GAL@if@first@on@level
    \GAL@handle@first@para
  \else
%    \end{macrocode}
%
%
%    We want to return to vmode without leaving too much trace. so we
%    remove the indentation box and call |\endgraf|. All this is done
%    in a group to keep an already setup |\parshape|, eg in a list. In
%    fact we might want to have this parshape setting as part of the
%    galley-objects but this is not done so far.\footnote{There is a
%    problem with code like this which was the result of a pr in
%    \LaTeXe. If the start of a paragraph is triggered by certain very
%    special commands (such as encoding-specific accents that involve
%    grouping) we might have the case that such a command already
%    started a group and then triggers the paragraph mechanism which
%    in turn triggers this macro. That may result in those groups to
%    overlap in a bad way---needs some clear instruction perhaps
%    \texttt{\textbackslash leavevmode} in all potential cases.}
%    \begin{macrocode}
    \begingroup
      \global\setbox\GAL@boxa\lastbox
      \endgraf
      \GAL@set@vertical@objects
%    \end{macrocode}
%    Before reentering h-mode we better clear the everypar register or
%    we end up in a loop:
%    \begin{macrocode}
      \GAL@@everypar{}
      \noindent
    \endgroup
  \fi
%    \end{macrocode}
%    Instead of setting up the measure each time one could probably
%    move this to the template setting things up (or not?)
%    \begin{macrocode}
    \GAL@set@measure
    \GAL@set@horizontal@objects
%    \end{macrocode}
%    At this point during the processing the parameters are all
%    reinitialised, i.e., anything not yet used will be
%    lost!\footnote{This is important if you think about paragraph
%    ending stuff which is not yet implemented}
%    \begin{macrocode}
    \GAL@init@dynamic@as@necessary
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\GAL@handle@first@para}
% Since this part of the code from above is not used that often it was
% placed into a separate command (for faster skipping).
%
% What needs to be done always?
%    \begin{macrocode}
\def\GAL@handle@first@para {
    \@GAL@if@first@on@levelfalse
    \GAL@pw@
%    \end{macrocode}
%    \begin{macrocode}
    \@tempskipa \GAL@uv@ \relax
    \ifdim \@tempskipa =\z@ \else 
%    \end{macrocode}
%    \begin{macrocode}
      \ifhmode
        \begingroup
          \global\setbox\GAL@boxa\lastbox
          \endgraf
          \vskip \@tempskipa
          \GAL@@everypar{}
          \noindent
        \endgroup
      \else
        \vskip \@tempskipa
      \fi
    \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\GAL@use@on@vobject}
% The other case where (part of) the galley data structure is going to
% be used is the case when we are already in vertical mode but want to
% append some vertical mode material (e.g., a rule, an inline float)
% or start some environment that likes to look like a paragraph even
% though it doesn't actually uses \TeX's low-level mechanisms (e.g.,
% longtable?, tabbing, \ldots).
%    \begin{macrocode}
\def\GAL@use@on@vobject{
%<*trace>
  \GAL@show@datastructure{V-object~ for~ galley~ 
                          level~ \the\GAL@level@num \on@line}
%</trace>
  \if@GAL@if@first@on@level
    \GAL@handle@first@para
  \else
    \GAL@set@vertical@objects
  \fi
  \GAL@init@dynamic@as@necessary
}
%    \end{macrocode}
% The use of this command should be followed by a |\nobreak| after the
% v-object or else we introduce an unwanted breakpoint due to the next
% |\parskip| being inserted.
%
% \end{macro}
%
%
% \begin{macro}{\GAL@set@vertical@objects}
%    When setting the vertical components of the galley structure the
%    following happens:
%    \begin{itemize}
%    \item First any whatsits for the previous para are
%      inserted\footnote{A nobreak is probably not necessary at this
%      point as the
%      parskip should by now already be inserted so that the next
%      thing happening is an explicit penalty anyway.}
%    \item
%      If a document user command for penalties as been used (i.e., when
%      \PARM{user penalty} is none-empty) it take precidence and the internal
%      penalty value is ignored.
%    \item
%      Otherwise the \PARM{break switch} is checked. If this greater
%      zero a nobreak penalty is issued and \PARM{penalty} is ignored.
%    \item
%      Otherwise the \PARM{penalty} value is used.
%    \end{itemize}
%
%    \begin{macrocode}
\def \GAL@set@vertical@objects {
   \GAL@pw@
   \penalty
    \ifx \GAL@up@ \@empty
      \ifnum \GAL@b@ > \z@
         \@M
      \else
         \GAL@p@ \relax
      \fi
    \else
      \GAL@up@ \relax
    \fi
%    \end{macrocode}
%    A user skip as supplied by |\vspace| etc.\ is going into a
%    separate register to ensure that it will always have the effect
%    of adding extra space independent of what surrounding
%    environments do.
%
%    The |\parskip| below is not the \TeX{} primitive (which is always
%    zero) but a user level register which is only applied at this
%    point if ever.
%    \begin{macrocode}
   \GAL@skipa \GAL@v@ \relax
   \vskip \ifdim 
%    \end{macrocode}
%    |\parskip| gets applied if we are between two paragraphs without
%    any further space requests; this is signalled by |\GAL@v@| having
%    a value of |-1sp| (its default). Of course it is in theory
%    possible that this value is the result to modification of
%    |\GAL@v@| but allowing for this saves us an extra flag or
%    register that would otherwise be needed and checked every time.
%    \begin{macrocode}
           \GAL@skipa = -1sp \parskip
%<*trace>
           \GAL@typeout{\parskip=\the\parskip\space applied}
%</trace>
         \else 
           \GAL@skipa
         \fi
  \vskip \GAL@uv@ \relax
}  
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\GAL@set@measure}
% Some comments on the next macro:
% not sure: do we better set parshape global? (can we?); of course it
% could and perhaps should be run inline, also we might instead add
% |\parshape| to the required content of |\GAL@ps@| so that we avoid
% the test and simply execute it always.
%
%    \begin{macrocode}
\def \GAL@set@measure {
  \parshape  
    \ifx\GAL@ps@\@empty
        \z@
    \else
      \GAL@ps@
    \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\GAL@set@horizontal@objects}
% Once we are back in hmode we first output any waiting whatsits, then
% run any query setups, then
% look at the saved indentation box: if it is void we know that we had
% a paragraph started with \noindent otherwise we typeset some
% indentation then the galley object and finally a horizontal skip
% (might also want a break penalty there or even more stuff).
%
%    \begin{macrocode}
\def \GAL@set@horizontal@objects {
  \GAL@nw@
  \GAL@q@
%    \end{macrocode}
%    The shape is now a multi-valued parameter so we pass it expanded
%    and let |\setup@paragraph@justification|  do the assignments if necessary.
%
%    As a speedup measure we are comparing |\GAL@j@| to the saved
%    version |\GAL@j@s|, if they are identical we assume that all
%    components of the multi-valued parameter are already properly set
%    up. This saves doing 8 assignments at every paragraph. The catch
%    is, that a change to the static parameter (via |\setSGPVthing:nn|
%    |s|) needs to be manually followed by running
%    |\setup@paragraph@justification| (see definition of
%    \texttt{justification} template).\footnote{Actually,
%     that shortcut does not work correctly! Needs thought! So commented out for the 
%     moment!}
%    \begin{macrocode}
%  \ifx \GAL@j@ \GAL@j@s % what is the right test to suppress?
%     \GAL@typeout{Not~ setting~ up~ paragraph~ shape}
%  \else
     \expandafter \setup@paragraph@justification \GAL@j@
%  \fi
  \ifnum \GAL@i@ = \z@
    \ifvoid\GAL@boxa \else \hb@xt@ \GAL@@parindent{} \fi
  \fi
  \GAL@o@ \relax
  \hskip \GAL@@startskip \relax
  \setup@page@breaking@penalties \GAL@b@
}  
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\setup@page@breaking@penalties}
% The way the following code is written (at the moment)
% |\clubpenalty|, |\interlinepenalty|, and |\brokenpenalty| are still
% available as user level registers so that setting up, say, the
% broken penalty default for the whole document is done via setting
% that particular register. 
%
% Another observation is that we most likely do not have to set
%    |\GAL@@brokenpenalty| at all (and if |\GAL@@interlinepenalty| is
%    set to `nobreak' we can also leave |\GAL@@clubpenalty| alone)
%    since if i read it right these penalties are additive so one
%    large one should be sufficient.
%
%    \begin{macrocode}
\def \setup@page@breaking@penalties #1{
  \GAL@@clubpenalty \clubpenalty
  \GAL@@interlinepenalty \interlinepenalty
%  \GAL@@brokenpenalty \brokenpenalty
  \ifcase #1
% 0
  \or
% 1
  \or
%2
    \GAL@@clubpenalty \@M
%    \GAL@@brokenpenalty \@M
  \or
%3 
    \GAL@@interlinepenalty \@M
%    \GAL@@brokenpenalty \@M
  \else
% assume negative: this loops if called with a value greater than 3! so
% probably can't stay this way.
    \setup@page@breaking@penalties {-#1}
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\setup@paragraph@justification}
%    Setting up the inner paragraph shape, e.g., the justification is
%    done by breaking up the multi-value parameter |s| into its 8
%    components.\footnote{Do one has to make those settings global? Check!}
%    \begin{macrocode}
\def \setup@paragraph@justification #1 #2 #3 #4 #5 #6 #7 #8{
  \global \GAL@@startskip   #1 \relax
  \global \GAL@@leftskip    #2 \relax
  \global \GAL@@rightskip   #3 \relax
  \global \GAL@@parfillskip #4 \relax
  \global \GAL@@spaceskip   #5 \relax
  \global \GAL@@xspaceskip  #6 \relax
  \global \GAL@@linefillskip#7 \relax
  \global \GAL@@parindent   #8 \relax
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Handling of \texttt{\textbackslash par}}
%
% Depending on the state of the machinery |\par| might a get different
% definition. 
%
% \begin{macro}{\GAL@normal@par}
%    In most cases |\par| will be |\let| to |\GAL@normal@par|.
%    \begin{macrocode}
\def \GAL@normal@par {
  \begingroup
  \ifvmode
    \endgraf
  \else                      %% For error-trapping needs
                             %%   \ifinner \ifhmode etc cases
%    \end{macrocode}
% At this point we might want to add and end par hook (not done);
% if we are not adding one then this definition can be optimised a lot
% (moving |\endgraf| up and using |\ifhmode| instead of the above.
%    \begin{macrocode}
        \endgraf
        %%%% NOTE: this puts us into vmode with the para on the galley
        %%%%       AND rignt here we have stuff that has migrated
        %%%%       (eg vadjust stuff) from the last line!!!
        \nobreak
  \fi
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@par}
%    \LaTeX's saved version of the original |\par| primitive now needs
%    actually run |\GAL@normal@par| to trick \LaTeX{} into accepting
%    this redefinition. This is needed at least as long as if we run
%    with a mixture of old and new code.
%    \begin{macrocode}
\let\@@par\GAL@normal@par
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GAL@endlist@par}
%
%    Another potential definition of |\par| comes into play when we
%    are at the end of a list environment and want to take different
%    actions depending on getting a continution of the paragraph or a
%    real end. This code is not functional!
%
%    ATTENTION: most likely either have to set those locally or have
%    to save the state of |\par| as well! And anyway it is not
%    finished code yet!!!!
%
%    \begin{macrocode}
%<*unfinished>
\def \GAL@endlist@par {
  \begingroup
  \ifvmode
    \addDGPVdimension:nn v \GAL@v@X
    \addDGPVdimension:nn i \GAL@i@X
    \addGALpenalty:n       \GAL@p@X
    \setGALnormalpar:
  \else
    \endgraf
    \nobreak
  \fi
  \endgroup
}
%</unfinished>
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\setGALnormalpar:}
%    The |\setGALnormalpar:| states that we are in normal operation.
%    \begin{macrocode}
\def\setGALnormalpar:{
  \global\let\par\GAL@normal@par
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\setGALendlistpar:}
%    The |\setGALendlistpar:| states that we want to handle the end
%    of list case.
%    \begin{macrocode}
%<*unfinished>
\def\setGALendlistpar:{
  \global\let\par\GAL@endlist@par
}
%</unfinished>
%    \end{macrocode}
% \end{macro}
%
%
% For ignoring |\par| commands we currently have two functions.
%
% \begin{macro}{\setGALignoredpar:n}
%    The |\setGALignoredpar:n| command disables |\par| altogether and
%    hopes that the beginning of another paragraph shows up soon
%    (three |\par|s are allowed). If not it issues an error message
%    (arg 1) and redefines |\par| to be |\GAL@normal@par|.
%    \begin{macrocode}
\def \setGALignoredpar:n #1 {
  \ifvmode
    \global \par@deathcycles \z@
    \global\let\par\GAL@ignored@par
    \gdef\GAL@ignored@par@error{#1}
    \appendtoDGPVthing:nn q \setGALnormalpar:
%    \end{macrocode}
%    Not sure what should be done if this gets executed in hmode: a)
%    ignore the request b) output an error message c) run it and with
%    it have the rest of the document being typeset into a single
%    paragraph :-)?  Since c) isn't really an option we have to take
%    some precaution, for the moment i have added an error but perhaps
%    this should be restricted to appear really only in hmode as an
%    error not in a |\write|, say, so maybe the test should be for
%    hmode --- or perhaps the whole commands should be removed in
%    favour of the one below.
%    \begin{macrocode}
  \else
    \ERROR \setGALnormalpar: \par
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GAL@ignored@par}
%    Helper function for |\setGALignoredpar:n|.
%    \begin{macrocode}
\def\GAL@ignored@par{
  \global \advance\par@deathcycles \@ne
  \ifnum \par@deathcycles > \thr@@
      \PackageError{galley2}\GAL@ignored@par@error\@ehd
      \setGALnormalpar:
      \par
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\GALignorepars:n}
%    An alternative is to explicitly look out for |\par| and spaces
%    (the point being that this immediately set the definition of
%    |\par| back to its normal value if anything else is encountered).
%    Again up to three |\par|s are accepted otherwise we get an error
%    message.
%    \begin{macrocode}
\def \GALignorepars:n #1 {
  \global \par@deathcycles \z@
  \global\let\par\GAL@ignore@next@pars
  \gdef\GAL@ignored@par@error{#1}
  \GAL@ignore@next@pars
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\GAL@ignore@next@pars}
%    And here is a helper for |\GALignorepars:n|.
%    \begin{macrocode}
\def\GAL@ignore@next@pars {
  \global \advance\par@deathcycles \@ne
  \ifnum \par@deathcycles > \thr@@
      \PackageError{galley2}\GAL@ignored@par@error\@ehd
      \setGALnormalpar:
      \par
  \fi
  \@ifnextchar\par{}{\setGALnormalpar:}
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%  \subsection{Support for paragraph shapes}
%
%
% \begin{macro}{\GAL@for}
% Next macro is a reimplementation of |\@for| to get rid of the |:|
%    \begin{macrocode}
\long\def\GAL@for#1#2\do#3{%
  \expandafter\def\expandafter\@fortmp\expandafter{#2}%
  \ifx\@fortmp\@empty \else
    \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}\fi}
%    \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\parshape@setup}
%    The |\parshape@setup| macro provides a low-level interface for
%    declaring special parshapes for the upcoming paragraph. It is
%    especially tuned to deal with the more common cases like
%    providing space for an initial or for an inline figure. It takes
%    six arguments with the following meaning:
%    \begin{itemize}
%    \item If a hole is to be cut on the left of the paragraph the
%    first argument should be |{\the\parshape@lineindent}| otherwise
%    |\@totalleftmargin| (hole on the right). At the moment there is
%    no provision for special shapes on both sides of the
%    paragraph.\footnote{This is low-level but still more than awkward
%    so probably should be replaced by something nicer one day.}
%    \item 
%    The second argument gives the indentation to be used for all
%    lines following the last special line. Typical value would be
%    |\@totalleftmargin|, or in case of setting up hanging paragraphs,
%    |\@totalleftmargin+<amount of hang>|. More exactly this indentation
%    is assumed to be what is needed if this would have been a normal
%    paragraph. It is therefore also added to the special lines.
%    \item 
%    The third argument gives the line width for all lines following
%    the last special line. Typical argument might be |\linewidth| or
%    in case of hanging paragraphs
%      |\linewidth+<amount of hang>|.\footnote{rewrite 
%      description of this and previous item}
%    \item
%    The forth argument gives the number of lines before the first special
%    line (in case of an initial this would be 0 typically).
%    \item
%    The fifth argument gives an initial amount to be left free on all
%    special lines.
%    \item 
%    Finally the sixth argument specifies the special lines as a comma
%    separated lists of dimensions. These dimensions are deltas to the
%    space specified in the forth argument.
%    \end{itemize}
%
%    Running this command has several effects:
%    \begin{itemize}
%    \item
%      The |\GAL@ps@| parameter is getting updated, ie it receives the
%      area parshape spec.
%    \item
%      In the command |\parshape@firstlineindent| the indent of the
%      first special line (not taking into account the standard line
%      indentation) is made available for use by an
%      application. This can be used to get to the left point on the
%      line to insert an initial character or a figure.
%    \end{itemize}
%
%    \begin{macrocode}
\def \parshape@setup #1 #2 #3 #4 #5 #6{
%    \end{macrocode}
%
%    \begin{macrocode}
  \setlength\@tempdima{#2}
  \setlength\@tempdimb{#3}
  \global\let\GAL@ps@\@gobble % remove upcoming space below
%    \end{macrocode}
%
%    \begin{macrocode}
  \parshape@linecnt \z@
  \@whilenum \parshape@linecnt < #4 \do 
     { \xdef\GAL@ps@{\GAL@ps@\space
                     \the\@tempdima\space \the\@tempdimb
                    }
       \advance \parshape@linecnt \@ne
     }
%    \end{macrocode}
%
%    \begin{macrocode}
  \GAL@for\parshape@next#6\do
     {
      \advance\parshape@linecnt\@ne
      \setlength\parshape@lineindent{\@tempdima+#5+\parshape@next}
      \setlength\parshape@linewidth 
                {\@tempdima+\@tempdimb-\parshape@lineindent}

%    \end{macrocode}
%
%    \begin{macrocode}
%      \setlength\parshape@linewidth 
%                {\@tempdimb-#5-(\parshape@next)}
%      \setlength\parshape@lineindent
%                {\@tempdima+\@tempdimb-\parshape@linewidth}
%    \end{macrocode}
%
%    If we setting up the first special line we record the indentation
%    used compared to a normal paragraph at this point. The
%    |\parshape@firstlineindent| is not part of the galley structure
%    thus we store it locally.
%    \begin{macrocode}
      \ifnum\parshape@linecnt=\@ne
        \@tempdimc \parshape@lineindent
        \advance\@tempdimc -\@tempdima
        \edef\parshape@firstlineindent{\the\@tempdimc}
      \fi
%    \end{macrocode}
%
%    \begin{macrocode}
      \xdef\GAL@ps@{\GAL@ps@\space
                    #1\space
                    \the\parshape@linewidth}
     }
%    \end{macrocode}
%
%    \begin{macrocode}
  \advance\parshape@linecnt\@ne
  \xdef\GAL@ps@{\the\parshape@linecnt\space
                    \GAL@ps@\space
                    \the\@tempdima\space \the\@tempdimb}
%<*trace>
  \GAL@typeout{\space\space set~ ps = \GAL@ps@}%
%</trace>
%    \end{macrocode}
%
%    \begin{macrocode}
  \GAL@prepare@reassign:NN \GAL@ps@ \GAL@ps@s
}
%    \end{macrocode}
% \end{macro}
%
%
%    \begin{macrocode}
\newcount\parshape@linecnt
\newlength\parshape@lineindent
\newlength\parshape@linewidth
%    \end{macrocode}
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  \subsection{Short-term mutators}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  All these functions only modify the DGPV, i.e., the one that gets
%  reset after use.
%
%
%  \subsubsection{Dimensions (skips and dimens)}
%
%
%  For setting galley parameters of type skip or dimen we provide
%  functions which take as their first argument an identifier
%  (typically a single character) that identifies the parameter to
%  change, e.g., `v' for vertical skip or `i' for indentation and as
%  second argument a dimension (for setting the parameter to this
%  value or adding this value or using the maximum of the old and the
%  new value, etc).\footnote{They currently work using skip registers
%  internally which means that it is up to the programmer to ensure
%  that a dimen parameter gets passed only dimen values without plus
%  or minus parts.}
%
%
%
% \begin{macro}{\setDGPVdimension:nn}
%    |\setDGPVdimension:nn| sets the parameter specified by the first
%    argument to the value given as the second argument.
%    \begin{macrocode}
\def\setDGPVdimension:nn #1#2{%  #1=v/h #2=value
  \calc@assign@skip\GAL@skipb{#2}
%<*trace>
  \GAL@typeout{\space\space set~ #1 = #2 = \the\GAL@skipb}%
%</trace>
  \expandafter \xdef
     \csname GAL@#1@\endcsname
     {\the\GAL@skipb}
  \GAL@prepare@reassign:n{#1}
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\addDGPVdimension:nn}
%
%    |\addDGPVdimension:nn| add to the parameter specified by the first
%    argument the value given as the second argument.
%    \begin{macrocode}
\def\addDGPVdimension:nn #1#2{%  #1=v/h/... #2=value
  \GAL@skipb\csname GAL@#1@ \endcsname\relax
%    \end{macrocode}
%    Since the value of -1sp is (at least for the v parameter) used as
%    a special flag we are a bit careful when adding so that we are
%    not off by -1sp: this is not visible but in certain situations
%    \TeX{} might be upset even by this tiny amount.\footnote{Really
%    necessary?}
%    \begin{macrocode}
  \ifdim\GAL@skipb=-1sp
    \calc@assign@skip\GAL@skipb{#2}
  \else
    \calc@assign@skip{\advance\GAL@skipb}{#2}
  \fi
%<*trace>
  \GAL@typeout{\space\space set~ #1 =+ #2 = \the\GAL@skipb}
%</trace>
  \expandafter
     \xdef
     \csname GAL@#1@\endcsname
     {\the\GAL@skipb}
  \GAL@prepare@reassign:n{#1}
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\maxDGPVdimension:nn}
%    |\maxDGPVdimension:nn| compares the current value of the
%    parameter specified by the first argument with the value given as
%    the second argument and stores the maximum of
%    them.\footnote{Current \LaTeX's \texttt{\textbackslash addvspace}
%    works quite differently and we may have to provide something else
%    here (or in addition)}
%    \begin{macrocode}
\def\maxDGPVdimension:nn #1#2{
  \GAL@skipa\csname GAL@#1@\endcsname\relax
  \calc@assign@skip\GAL@skipb{#2}
  \ifdim\GAL@skipa<\GAL@skipb
    \expandafter
       \xdef
       \csname GAL@#1@\endcsname
       {\the\GAL@skipb}
    \GAL@prepare@reassign:n{#1}
  \fi
%<*trace>
  \GAL@typeout{\space\space set~ #1 =
       max(\the\GAL@skipa,\the\GAL@skipb) ^^J\@spaces\@spaces
            = \csname GAL@#1@\endcsname}
%</trace>
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{Integers}
%
% From previous coding we still have things like |\setGALpenalty:n| ---
% i guess one could normalise this to an interface like
% |\setGALinteger| \ldots
%
% \begin{macro}{\setGALpenalty:n}
% we can either set the `penalty' object or add to it. To speed things
% up we use a mixture of calc and low-level \TeX{} conventions
%
%    \begin{macrocode}
\def\setGALpenalty:n #1{%  
  \calc@assign@count\GAL@cnta{#1}
  \xdef \GAL@p@ {\the\GAL@cnta}
%<*trace>
  \GAL@typeout{\space\space set~ p = #1 = \the\GAL@cnta}
%</trace>
  \GAL@prepare@reassign:NN \GAL@p@ \GAL@p@s
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\addGALpenalty:n}
%
%    \begin{macrocode}
\def\addGALpenalty:n #1{%  
  \GAL@cnta \GAL@p@ \relax
  \calc@assign@count{\advance\GAL@cnta}{#1}
  \xdef \GAL@p@ {\the\GAL@cnta}
%<*trace>
  \GAL@typeout{\space\space set~ p += #1 = \the\GAL@cnta}
%</trace>
  \GAL@prepare@reassign:NN \GAL@p@ \GAL@p@s
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\setGALbreak:n}
%    The |\setGALbreak:n| sets the switch that controls page breaking
%    \begin{macrocode}
\def\setGALbreak:n #1{%  values 0, 1, 2, or 3
%<*trace>
   \GAL@typeout{\space\space set~ b = #1 }
%</trace>
   \gdef \GAL@b@ {#1}
   \GAL@prepare@reassign:NN  \GAL@b@  \GAL@b@s 
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
% \subsubsection{Objects and thingies in general}
%
% \begin{macro}{\setGALobject:n}
%
% For the `o' object i've implemented only a `set' command so far
% (have to see what kind of usage this gets first)
%
%    \begin{macrocode}
\def\setGALobject:n #1{
    \gdef \GAL@o@ {#1}
    \GAL@prepare@reassign:NN \GAL@o@ \GAL@o@s
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\setDGPVthing:nn}
%    A generalised version of that is |\setDGPVthing:nn|.
%    \begin{macrocode}
\def\setDGPVthing:nn #1 #2{
    \expandafter \gdef \csname GAL@#1@\endcsname {#2}
    \GAL@prepare@reassign:n{#1}
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\appendtoDGPVthing:nn}
% \begin{macro}{\appendtoDGPVthing:no}
%    And here is another one which appends code to the right of the
%    parameter:
%    \begin{macrocode}
\def\appendtoDGPVthing:nn #1#2{
    \expandafter\appendtoDGPV@internal:Nn\csname GAL@#1@\endcsname {#2}
    \GAL@prepare@reassign:n{#1}
}
\def\appendtoDGPVthing:no #1#2{
    \expandafter\appendtoDGPV@internal:No\csname GAL@#1@\endcsname {#2}
    \GAL@prepare@reassign:n{#1}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\appendtoDGPV@internal:Nn}
% \begin{macro}{\appendtoDGPV@internal:No}
%    These are internals which look suspiciently like some macros
%    already present a million times in \LaTeX{}.
%    \begin{macrocode}
\def\appendtoDGPV@internal:Nn #1 #2{
    \expandafter \gdef \expandafter #1 \expandafter
        {#1 #2}
}
\def\appendtoDGPV@internal:No #1 #2{
   \expandafter\appendtoDGPV@internal:Nn\expandafter #1\expandafter {#2}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Paragraph shapes}
%
% \begin{macro}{\setGALleftparshape:nnn}
% \begin{macro}{\setGALrightparshape:nnn}
%    Setting a parshape on the left or the right for the next
%    paragraph, e.g., an initial. Not implemented so far is doing
%    something special on both sides.
%    \begin{macrocode}
\def \setGALleftparshape:nnn {
 \parshape@setup {\the\parshape@lineindent} \@totalleftmargin
                 \linewidth  }
\def \setGALrightparshape:nnn {
 \parshape@setup \@totalleftmargin \@totalleftmargin \linewidth
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\GALhangfrom:n}
%     And here a reimplementation of |\@hangfrom| but obeying
%    |\@totalleftmargin| indentation.
%    \begin{macrocode}
\def \GALhangfrom:n #1 {
   \setbox\@tempboxa\hbox{{#1}}
   \parshape@setup {\the\parshape@lineindent}
                   {\@totalleftmargin+\wd\@tempboxa}
                   {\linewidth-\wd\@tempboxa}
                   \z@
                   \z@
                   {-\wd\@tempboxa}
    \noindent\box\@tempboxa}
\let \@hangfrom \GALhangfrom:n
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  \subsection{Long-term mutators}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  The following functions now modify the SGPV, i.e., modify the
%  values that are used as defaults unless overwritten for an
%  individual paragraph. Right now I don't see any purpose in providing
%  computation support at this level other than something like calc
%  expansion; so need one function per parameter type. Otherwise a
%  single function would be sufficient.
%
% \subsubsection{Objects and thingies in general}
%
% \begin{macro}{\setSGPVthing:nn}
%  So here is one that simply stores away the value in the right plist
%  under the right key. In addition we also directly update the key
%  command itself to avoid having to run something like
%  |\GAL@init@hmode| afterwards.
%    \begin{macrocode}
\def\setSGPVthing:nn #1 #2 {
    \setDGPVthing:nn {#1} {#2}
    \global\expandafter
       \let\csname GAL@#1@s \expandafter\endcsname 
           \csname GAL@#1@  \endcsname
}
%    \end{macrocode}
% \end{macro}
%
%
%  \subsubsection{Dimensions (skips and dimens)}
%
% \begin{macro}{\setSGPVdimension:nn}
%    The |\setSGPVdimension:nn| first sets the dynamic part of the
%    parameter (which is done using calc expansion) followed by
%    updating the static part of the parameter.
%    \begin{macrocode}
\def\setSGPVdimension:nn #1 #2 {
    \setDGPVdimension:nn {#1} {#2}
    \global\expandafter
       \let\csname GAL@#1@s \expandafter\endcsname 
           \csname GAL@#1@  \endcsname
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Paragraph shapes}
%
% \begin{macro}{\setSGPVmeasure:nn}
% Dealing with the parshape: the long term modification is essentially
% setting the measure and to support old \LaTeX{}  code also sets
% |\linewidth| and |\@totalleftmargin| (but see comments on this somewhere!)
%
%    \begin{macrocode}
\def \setSGPVmeasure:nn #1 #2 {
  \setlength\@totalleftmargin{#1}
  \setlength\linewidth{#2}
  \xdef\GAL@ps@s{\@ne\space
                 \the\@totalleftmargin\space \the\linewidth}
  \global\let\GAL@ps@\GAL@ps@s
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\addSGPVmeasure:nn}
%    This is a variant modifies the measure (the name is
%    horrible) by adding to |\@totalleftmargin| and |\linewidth|. Note
%    that you normally need to substract from |\linewidth| if
%    |\@totalleftmargin| is enlarged!
%    \begin{macrocode}
\def \addSGPVmeasure:nn #1 #2 {
  \addtolength\@totalleftmargin{#1}
  \addtolength\linewidth{#2}
  \xdef\GAL@ps@s{\@ne\space
                 \the\@totalleftmargin\space \the\linewidth}
  \global\let\GAL@ps@\GAL@ps@s
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{Integers}
%
% No functions provided. For consistency reasons there probably should
% some in the end.
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  \subsection{Higher level commands}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% \begin{macro}{\vspace}
%    The |*| of |\vspace| is parsed but not handled in this
%    implementation yet!
%    \begin{macrocode}
\DeclareDocumentCommand \vspace {s m }
 {
  \addDGPVdimension:nn{uv}{#2}
 }
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\addvspace}
%    |\addvspace| is quite a bit different to the latex original, this
%    needs changing!
%    \begin{macrocode}
\def\addvspace#1{
  \maxDGPVdimension:nn{v}{#1}
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\addpenalty}
%    \begin{macrocode}
\def\addpenalty#1{
  \addGALpenalty:n{#1}
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  \subsection{Templates (first ideas)}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Code in this section is essentially left over from previous
% versions. Most templates have been moved to different files already.
%
% The endlist template is rubbish and just for testing the concept
% itself! and not finished either!
%
%    \begin{macrocode}
\RequirePackage{template}
\RequirePackage{xparse}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareTemplateType{endlist}{0}

\DeclareTemplate{endlist}{std}{0}{
  penalty     =+C \GAL@p@ ,
  vspace      =+L \GAL@v@ ,
  parindent   =+L \GAL@i@ ,
  par-penalty     =+C [0]   \GAL@p@X ,
  par-vspace      =+L [\z@] \GAL@v@X ,
  par-parindent   =+L [\z@] \GAL@i@X ,
 }
 {\DoParameterAssignments 
  \setGALendlistpar:}

\DeclareInstance{endlist}{list}{std}{
  penalty     = 999 ,
  vspace      = 10pt ,
  parindent   = 0pt ,
  par-penalty     = -1000 ,
  par-vspace      = 5pt ,
  par-parindent   = 10pt ,
 }
%    \end{macrocode}
%
%
%
%
% \subsection{Initialisation}
%
%    \begin{macrocode}
\GAL@init@static  % this is to be after the templates by now

\GAL@@everypar{\GAL@use@on@para\the\everypar}

%    \end{macrocode}
%
% We need to initialize again at start of document i fear to ensure
% that stuff like the hyphenation is set up properly (this needs some
% further thoughts!)
%    \begin{macrocode}
\AtBeginDocument {
  \GAL@init@static  % this is to be after the templates by now
}
%    \end{macrocode}
%
% \section{Updated code from \texttt{latex.ltx}}
%
% There are a bunch of additional code lines which are originally from
% \texttt{latex.ltx} and have been updated (in part) to use the new
% mechanism. This isn't really worth printing as most of that is not
% fully done or obsolete by redefinition of, say, code for lists,
% etc. But one might want to have a look at it at some stage. For this
% reason the code contains an |\end{document}| at this point. which
% you may or may not want to remove.
%
% \PrintIndex
%
% \end{document}
%
%    \begin{macrocode}
\def\@@line#1{\GAL@use@on@vobject\hb@xt@\hsize{#1}\nobreak}

\long\def \@savemarbox #1#2{%
  \global\setbox #1%
    \color@vbox
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore
        \@marginparreset
        #2%
        \par                       % needed nowadays!
        \@minipagefalse
        \outer@nobreak
        }%
    \color@endbox
}

\long\def\@footnotetext#1{\insert\footins{%
    \reset@font\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
       \csname p@footnote\endcsname\@thefnmark
    }%
    \color@begingroup
      \@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox\par}%  %ditto!!!
    \color@endgroup}}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% all latex.ltx commands that involved the @nobreak flag
%
% most of them have been modified to use the new structure but not all
% and not all correctly (see comments within the code

%<*trace>
\def\showGALcmd#1{\GAL@typeout{In~#1: \the\GAL@level@num~ \on@line}}
%</trace>

\def\@afterheading{
%<*trace>
  \showGALcmd{@afterheading}
%</trace>
  \if@afterindent \else
    \setDGPVthing:nn i \@ne
  \fi
  \setGALbreak:n 2
}

\def\nofiles{%
%<*trace>
  \showGALcmd{}
%</trace>
  \@fileswfalse
  \typeout{No auxiliary output files.^^J}%
  \long\def\protected@write##1##2##3%
    {\write\m@ne{}%
%
% i think that the following code can simply vanish since if we are in
% vmode and the \PARM{break flag} is set then the GAL mechansim will
% automatically add a penalty 10000 at the right point; correct?
%
%\if@nobreak\ifvmode\nobreak\fi\fi}%
  }
  \let\makeindex\relax
  \let\makeglossary\relax}

\long\def \protected@write#1#2#3{%
%<*trace>
  \showGALcmd{protected@write}
%</trace>
      \begingroup
       \let\thepage\relax
       #2%
       \let\protect\@unexpandable@protect
       \edef\reserved@a{\write#1{#3}}%
       \appendtoDGPVthing:no {nw} \reserved@a
      \endgroup
%
% see above
%
%      \if@nobreak\ifvmode\nobreak\fi\fi
}

\def\markboth#1#2{\gdef\@themark{{#1}{#2}}{%
%<*trace>
  \showGALcmd{}
%</trace>
     \let\protect\@unexpandable@protect
     \let\label\relax \let\index\relax \let\glossary\relax
     \mark{\@themark}}%
%
%\if@nobreak\ifvmode\nobreak\fi\fi
}

\def\markright#1{{\let\protect\@unexpandable@protect
%<*trace>
  \showGALcmd{}
%</trace>
     \let\label\relax \let\index\relax \let\glossary\relax
     \expandafter\@markright\@themark
     {#1}\mark{\@themark}}%
%
%\if@nobreak\ifvmode\nobreak\fi\fi
}

\def \newpage {%
%<*trace>
  \showGALcmd{newpage}
%</trace>
  \if@noskipsec
    \ifx \@nodocument\relax
      \leavevmode
      \global \@noskipsecfalse
    \fi
  \fi
  \if@inlabel
    \leavevmode
    \global \@inlabelfalse
  \fi
%
% newpage is supposed to stop any \PARM{nobreak flag}, so the right
% approach is probably something like
%
  \ifnum \GAL@b@ > \z@
     \setGALbreak:n 0
  \fi
%
%  \if@nobreak \@nobreakfalse \everypar{}\fi
%
  \par
  \vfil
  \penalty -\@M}
%
%
% the |\@arrayparboxrestore| nothing else than initialising a new
% galley level (in the old \LaTeX) so most of what is there needs
% either to vanish or to get integrated into the startup code of a new
% galley (not done yet)
%
\def\@arrayparboxrestore{%
%<*trace>
  \showGALcmd{@arrayparboxrestore}
%</trace>
%
% again nothing to do (i think): if used as part of a minipage or
% parbox we are at a new level, otherwise we are probably not supposed
% to change that value
%
%  \let\if@nobreak\iffalse
  \let\if@noskipsec\iffalse
  \let\par\@@par
  \let\-\@dischyph
  \let\'\@acci\let\`\@accii\let\=\@acciii
  \parindent\z@ \parskip\z@skip
  \everypar{}%
  \linewidth\hsize
  \@totalleftmargin\z@
  \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip
  \parfillskip\@flushglue \lineskip\normallineskip
  \baselineskip\normalbaselineskip
  \sloppy}

\def\@startsection#1#2#3#4#5#6{%
%<*trace>
  \showGALcmd{@startsection}
%</trace>
  \if@noskipsec \leavevmode \fi
  \par
  \@tempskipa #4\relax
  \@afterindenttrue
  \ifdim \@tempskipa <\z@
    \@tempskipa -\@tempskipa \@afterindentfalse
  \fi
%
% the section case is interesting since the @nobreak flag is used for
% two things: a) to suppress a penalty if heading follow each other
% and be to suppress a skip in this case. This works because in latex
% the @nobreak switch is only set in the heading context (so is
% actually something like ``heading just seen flag''
%
% not sure how to model something like this in general, for the moment
% i look at the \PARM{nobreak flag} but this is not correct!
%
%  \if@nobreak
%    \everypar{}%
%  \else
%    \addpenalty\@secpenalty\addvspace\@tempskipa
%  \fi
  \ifnum \GAL@b@ = \z@
     \addpenalty\@secpenalty\addvspace\@tempskipa
  \fi
  \@ifstar
    {\@ssect{#3}{#4}{#5}{#6}}%
    {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}

\def\@xsect#1{%
%<*trace>
  \showGALcmd{@xsect}
%</trace>
  \@tempskipa #1\relax
  \ifdim \@tempskipa>\z@
    \par \nobreak
    \vskip \@tempskipa
    \@afterheading
  \else
    \global\@noskipsectrue
%    \@nobreakfalse
%    \everypar{%
%      \if@noskipsec
%        \global\@noskipsecfalse
%       {\setbox\z@\lastbox}%
%        \clubpenalty\@M
%        \begingroup \@svsechd \endgroup
%        \unskip
%        \@tempskipa #1\relax
%        \hskip -\@tempskipa
%      \else
%        \clubpenalty \@clubpenalty
%        \everypar{}%
%      \fi}%
    \setDGPVthing:nn i \@ne
    \setGALbreak:n 2
    \setGALobject:n { \begingroup \@svsechd \endgroup
                       \unskip }
% obey stupid latex startsection interface with negative numbers ...
    \@tempskipa #1\relax
    \setDGPVdimension:nn h {-\@tempskipa}
%
% the noskipsec flag is probably needed in interaction with lists as
% long as this is only a partial conversion so i do set it (maybe not)
%
    \everypar{%
      \if@noskipsec
        \global\@noskipsecfalse
      \else
        \everypar{}%
      \fi}%
  \fi
  \ignorespaces}

\gdef\@specialoutput{%
%<*trace>
  \showGALcmd{@specialoutput}
%</trace>
   \ifnum \outputpenalty>-\@Mii
     \@doclearpage
   \else
     \GAL@ignore@next@galley
     \ifnum \outputpenalty<-\@Miii
       \ifnum \outputpenalty<-\@MM \deadcycles \z@ \fi
       \global \setbox\@holdpg \vbox {\unvbox\@cclv}%
     \else
       \global \setbox\@holdpg \vbox{%
                      \unvbox\@holdpg
                      \unvbox\@cclv
                      \setbox\@tempboxa \lastbox
                      \unskip
                                     }%
       \@pagedp \dp\@holdpg
       \@pageht \ht\@holdpg
       \unvbox \@holdpg
       \@next\@currbox\@currlist{%
         \ifnum \count\@currbox>\z@
           \advance \@pageht \@pagedp
           \ifvoid\footins \else
             \advance \@pageht \ht\footins
             \advance \@pageht \skip\footins
             \advance \@pageht \dp\footins
           \fi
           \ifvbox \@kludgeins
             \ifdim \wd\@kludgeins=\z@
               \advance \@pageht \ht\@kludgeins
             \fi
           \fi
           \@reinserts
           \@addtocurcol
         \else
           \@reinserts
           \@addmarginpar
         \fi
         }\@latexbug
%
% with the same argument as before we can always add the penalty, right?
%
       \ifnum \outputpenalty<\z@
%         \if@nobreak
%           \nobreak
%         \else
           \addpenalty \interlinepenalty
%         \fi
       \fi
     \fi
   \fi
}

\def \@addtocurcol {%
%<*trace>
  \showGALcmd{@addtocurcol}
%</trace>
   \@insertfalse
   \@setfloattypecounts
   \ifnum \@fpstype=8
   \else
     \ifnum \@fpstype=24
     \else
       \@flsettextmin
       \advance \@textmin \@textfloatsheight
       \@reqcolroom \@pageht
       \ifdim \@textmin>\@reqcolroom
         \@reqcolroom \@textmin
       \fi
       \advance \@reqcolroom \ht\@currbox
       \ifdim \@colroom>\@reqcolroom
         \@flsetnum \@colnum
         \ifnum \@colnum>\z@
           \@bitor\@currtype\@deferlist
           \if@test
           \else
             \@bitor\@currtype\@botlist
             \if@test
               \@addtobot
             \else
               \ifodd \count\@currbox
                 \advance \@reqcolroom \intextsep
                 \ifdim \@colroom>\@reqcolroom
                   \global \advance \@colnum \m@ne
                   \global \advance \@textfloatsheight \ht\@currbox
                   \global \advance \@textfloatsheight 2\intextsep
                   \@cons \@midlist \@currbox
%
% same argument as before (perhaps incorrect here?)
%
%                   \if@nobreak
%                     \nobreak
%                     \@nobreakfalse
%                     \everypar{}%
%                   \else
                     \addpenalty \interlinepenalty
%                   \fi
%
% at least it seems to me that we should not use \vskip here
%
%
% however we should then also have a way to trigger the use of the
% GAL structure without actually starting hmode (note done so all
% this is incorrect)
%
                   \vskip \intextsep
                   \box\@currbox
%
% and neither here ...
%
                   \penalty\interlinepenalty
                   \vskip\intextsep
                   \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
                   \outputpenalty \z@
                   \@inserttrue
                 \fi
               \fi
               \if@insert
               \else
                 \@addtotoporbot
               \fi
             \fi
           \fi
         \fi
       \fi
     \fi
   \fi
   \if@insert
   \else
     \@resethfps
     \@cons\@deferlist\@currbox
   \fi
}

% and the whole item stuff is too complicated for me to really think
% about it tonight ...

\def\@item[#1]{%
%<*trace>
  \showGALcmd{@item}
%</trace>
  \if@noparitem
    \@donoparitem
  \else
    \if@inlabel
      \indent \par
    \fi
    \ifhmode
      \unskip\unskip \par
    \fi
    \if@newlist
      \if@nobreak
        \@nbitem
      \else
        \addpenalty\@beginparpenalty
        \addvspace\@topsep
        \addvspace{-\parskip}%
      \fi
    \else
      \addpenalty\@itempenalty
      \addvspace\itemsep
    \fi
    \global\@inlabeltrue
  \fi
  \everypar{%
    \@minipagefalse
    \global\@newlistfalse
    \if@inlabel
      \global\@inlabelfalse
      {\setbox\z@\lastbox
       \ifvoid\z@
         \kern-\itemindent
       \fi}%
      \box\@labels
      \penalty\z@
    \fi
    \if@nobreak
      \@nobreakfalse
      \clubpenalty \@M
    \else
      \clubpenalty \@clubpenalty
      \everypar{}%
    \fi}%
  \if@noitemarg
    \@noitemargfalse
    \if@nmbrlist
      \refstepcounter\@listctr
    \fi
  \fi
  \sbox\@tempboxa{\makelabel{#1}}%
  \global\setbox\@labels\hbox{%
    \unhbox\@labels
    \hskip \itemindent
    \hskip -\labelwidth
    \hskip -\labelsep
    \ifdim \wd\@tempboxa >\labelwidth
      \box\@tempboxa
    \else
      \hbox to\labelwidth {\unhbox\@tempboxa}%
    \fi
    \hskip \labelsep}%
  \ignorespaces}


%    \end{macrocode}
%
%
%    \section{Fixing non-galley vboxes}
%
%    \begin{macrocode}
\DeclareRobustCommand{\LaTeX}{L\kern-.36em%
        {\sbox\z@ T%
         \GAL@ignore@next@galley@vbox to\ht\z@{\hbox{\check@mathfonts
                              \fontsize\sf@size\z@
                              \math@fontsfalse\selectfont
                              A}%
                        \vss}%
        }%
        \kern-.15em%
        \TeX}
\DeclareTextCommandDefault{\textunderscore}{%
  \leavevmode \kern.06em\GAL@ignore@next@galley@vbox{\hrule\@width.3em}}
\DeclareTextCommandDefault{\textvisiblespace}{%
   \mbox{\kern.06em\vrule \@height.3ex}%
   \GAL@ignore@next@galley@vbox{\hrule \@width.3em}%
   \hbox{\vrule \@height.3ex}}
\gdef\showhyphens#1{%
  \setbox0\vbox{%
    \color@begingroup
    \everypar{}%
    \parfillskip\z@skip\hsize\maxdimen
    \normalfont
    \pretolerance\m@ne\tolerance\m@ne\hbadness\z@\showboxdepth\z@\ #1%
    \color@endgroup}}
\catcode`\:=12
\long\def\@imakepicbox(#1,#2)[#3]#4{%
  \GAL@ignore@next@galley@vbox to#2\unitlength
   {\let\mb@b\vss \let\mb@l\hss\let\mb@r\hss
    \let\mb@t\vss
    \@tfor\reserved@a :=#3\do{%
      \if s\reserved@a
        \let\mb@l\relax\let\mb@r\relax
      \else
        \expandafter\let\csname mb@\reserved@a\endcsname\relax
      \fi}%
    \mb@t
    \hb@xt@ #1\unitlength{\mb@l #4\mb@r}%
    \mb@b
    \kern\z@}}
\catcode`\:=11
\long\def\frame#1{%
  \leavevmode
  \hbox{%
    \hskip-\@wholewidth
    \GAL@ignore@next@galley@vbox{%
      \vskip-\@wholewidth
      \hrule \@height\@wholewidth
      \hbox{%
        \vrule\@width\@wholewidth
        #1%
        \vrule\@width\@wholewidth}%
      \hrule\@height\@wholewidth
      \vskip-\@wholewidth}%
    \hskip-\@wholewidth}}
\def\@frameb@x#1{%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep
  \advance\@tempdima\dp\@tempboxa
  \hbox{%
    \lower\@tempdima\hbox{%
      \GAL@ignore@next@galley@vbox{%
        \hrule\@height\fboxrule
        \hbox{%
          \vrule\@width\fboxrule
          #1%
          \GAL@ignore@next@galley@vbox{%
            \vskip\fboxsep
            \box\@tempboxa
            \vskip\fboxsep}%
          #1%
          \vrule\@width\fboxrule}%
        \hrule\@height\fboxrule}%
                          }%
        }%
}
\typeout{****~ Careful:~ there~ is~ another~ rewrite~ for~ iiiparbox~ in~ coffins!}
 
\long\def\@iiiparbox#1#2[#3]#4#5{%
  \leavevmode
  \@pboxswfalse
  \setlength\@tempdima{#4}%
  \@begin@tempboxa\vbox{\hsize\@tempdima\@parboxrestore#5\@@par}%
    \ifx\relax#2\else
      \setlength\@tempdimb{#2}%
      \def\@parboxto{to\@tempdimb}%
    \fi
    \GAL@ignore@next@galley
    \if#1b\vbox
    \else\if #1t\vtop
    \else\ifmmode\vcenter
    \else\@pboxswtrue $\vcenter
    \fi\fi\fi
    \@parboxto{\let\hss\vss\let\unhbox\unvbox
       \csname bm@#3\endcsname}%
    \if@pboxsw \m@th$\fi
  \@end@tempboxa}
\def\@iiiminipage#1#2[#3]#4{%
  \leavevmode
  \@pboxswfalse
  \setlength\@tempdima{#4}%
  \def\@mpargs{{#1}{#2}[#3]{#4}}%
  \setbox\@tempboxa\vbox\bgroup
    \color@begingroup
      \hsize\@tempdima
      \textwidth\hsize \columnwidth\hsize
      \@parboxrestore
      \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
      \let\@footnotetext\@mpfootnotetext
      \let\@listdepth\@mplistdepth \@mplistdepth\z@
      \@minipagerestore
      \@setminipage}
\long\def\@mpfootnotetext#1{%
  \global\setbox\@mpfootins\vbox{%
    \unvbox\@mpfootins
    \reset@font\footnotesize
    \hsize\columnwidth
    \@parboxrestore
    \protected@edef\@currentlabel
         {\csname p@mpfootnote\endcsname\@thefnmark}%
    \color@begingroup
      \@makefntext{%
        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
    \color@endgroup}}
\def\@array[#1]#2{%
  \GAL@ignore@next@galley
  \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi
  \bgroup
  \setbox\@arstrutbox\hbox{%
    \vrule \@height\arraystretch\ht\strutbox
           \@depth\arraystretch \dp\strutbox
           \@width\z@}%
  \@mkpream{#2}%
  \edef\@preamble{%
    \ialign \noexpand\@halignto
      \bgroup \@arstrut \@preamble \tabskip\z@skip \cr}%
  \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox
  \let\tabularnewline\\%
%
% we can't allow uncontrolled changes of \par
%
%%%%    \let\par\@empty
    \let\@sharp##%
    \set@typeset@protect
    \lineskip\z@skip\baselineskip\z@skip
    \ifhmode \@preamerr\z@ \@@par\fi
    \@preamble}
\gdef\@shortstack[#1]{%
  \leavevmode
  \GAL@ignore@next@galley@vbox\bgroup
    \baselineskip-\p@\lineskip 3\p@
    \let\mb@l\hss\let\mb@r\hss
    \expandafter\let\csname mb@#1\endcsname\relax
    \let\\\@stackcr
    \@ishortstack}
\gdef\@ishortstack#1{\ialign{\mb@l {##}\unskip\mb@r\cr #1\crcr}\egroup}
\gdef\@stackcr{\@ifstar\@ixstackcr\@ixstackcr}
\gdef\@ixstackcr{\@ifnextchar[\@istackcr{\cr\ignorespaces}}
\gdef\@istackcr[#1]{\cr\noalign{\vskip #1}\ignorespaces}
\newif\if@negarg
\gdef\line(#1,#2)#3{\@xarg #1\relax \@yarg #2\relax
  \@linelen #3\unitlength
  \ifdim\@linelen<\z@\@badlinearg\else
    \ifnum\@xarg =\z@ \@vline
      \else \ifnum\@yarg =\z@ \@hline \else \@sline\fi
    \fi
  \fi}
\gdef\@sline{%
  \ifnum\@xarg<\z@ \@negargtrue \@xarg -\@xarg \@yyarg -\@yarg
  \else \@negargfalse \@yyarg \@yarg \fi
\ifnum \@yyarg >\z@ \@tempcnta\@yyarg \else \@tempcnta -\@yyarg \fi
\ifnum\@tempcnta>6 \@badlinearg\@tempcnta\z@ \fi
\ifnum\@xarg>6 \@badlinearg\@xarg \@ne \fi
\setbox\@linechar\hbox{\@linefnt\@getlinechar(\@xarg,\@yyarg)}%
\ifnum \@yarg >\z@ \let\@upordown\raise \@clnht\z@
   \else\let\@upordown\lower \@clnht \ht\@linechar\fi
\@clnwd \wd\@linechar
\if@negarg
  \hskip -\wd\@linechar \def\reserved@a{\hskip -2\wd\@linechar}%
\else
     \let\reserved@a\relax
\fi
\@whiledim \@clnwd <\@linelen \do
  {\@upordown\@clnht\copy\@linechar
   \reserved@a
   \advance\@clnht \ht\@linechar
   \advance\@clnwd \wd\@linechar}%
\advance\@clnht -\ht\@linechar
\advance\@clnwd -\wd\@linechar
\@tempdima\@linelen\advance\@tempdima -\@clnwd
\@tempdimb\@tempdima\advance\@tempdimb -\wd\@linechar
\if@negarg \hskip -\@tempdimb \else \hskip \@tempdimb \fi
\multiply\@tempdima \@m
\@tempcnta \@tempdima
\@tempdima \wd\@linechar \divide\@tempcnta \@tempdima
\@tempdima \ht\@linechar \multiply\@tempdima \@tempcnta
\divide\@tempdima \@m
\advance\@clnht \@tempdima
\ifdim \@linelen <\wd\@linechar
   \hskip \wd\@linechar
   \@picture@warn
   \else\@upordown\@clnht\copy\@linechar\fi}
\gdef\@hline{\ifnum \@xarg <\z@ \hskip -\@linelen \fi
\vrule \@height \@halfwidth \@depth \@halfwidth \@width \@linelen
\ifnum \@xarg <\z@ \hskip -\@linelen \fi}
\gdef\@getlinechar(#1,#2){\@tempcnta#1\relax\multiply\@tempcnta 8%
  \advance\@tempcnta -9\ifnum #2>\z@ \advance\@tempcnta #2\relax\else
  \advance\@tempcnta -#2\relax\advance\@tempcnta 64 \fi
  \char\@tempcnta}
\gdef\vector(#1,#2)#3{\@xarg #1\relax \@yarg #2\relax
  \@tempcnta \ifnum\@xarg<\z@ -\@xarg\else\@xarg\fi
  \ifnum\@tempcnta<5\relax
  \@linelen #3\unitlength
  \ifdim\@linelen<\z@\@badlinearg\else
    \ifnum\@xarg =\z@ \@vvector
      \else \ifnum\@yarg =\z@ \@hvector \else \@svector\fi
    \fi
  \fi
  \else\@badlinearg\fi}
\gdef\@hvector{\@hline\hb@xt@\z@{\@linefnt
 \ifnum \@xarg <\z@ \@getlarrow(1,0)\hss\else
    \hss\@getrarrow(1,0)\fi}}
\gdef\@vvector{\ifnum \@yarg <\z@ \@downvector \else \@upvector \fi}
\gdef\@svector{\@sline
  \@tempcnta\@yarg \ifnum\@tempcnta <\z@ \@tempcnta -\@tempcnta\fi
  \ifnum\@tempcnta <5%
    \hskip -\wd\@linechar
    \@upordown\@clnht \hbox{\@linefnt  \if@negarg
    \@getlarrow(\@xarg,\@yyarg)\else \@getrarrow(\@xarg,\@yyarg)\fi}%
  \else\@badlinearg\fi}
\gdef\@getlarrow(#1,#2){\ifnum #2=\z@ \@tempcnta'33 \else
  \@tempcnta #1\relax\multiply\@tempcnta \sixt@@n \advance\@tempcnta
  -9 \@tempcntb #2\relax\multiply\@tempcntb \tw@
  \ifnum \@tempcntb >\z@ \advance\@tempcnta \@tempcntb
  \else\advance\@tempcnta -\@tempcntb\advance\@tempcnta 64
  \fi\fi\char\@tempcnta}
\gdef\@getrarrow(#1,#2){\@tempcntb #2\relax
\ifnum\@tempcntb <\z@ \@tempcntb -\@tempcntb\relax\fi
\ifcase \@tempcntb\relax \@tempcnta'55 \or
\ifnum #1<\thr@@ \@tempcnta #1\relax\multiply\@tempcnta
24\advance\@tempcnta -6 \else \ifnum #1=\thr@@ \@tempcnta 49
\else\@tempcnta 58 \fi\fi\or
\ifnum #1<\thr@@ \@tempcnta=#1\relax\multiply\@tempcnta
24\advance\@tempcnta -\thr@@ \else \@tempcnta 51 \fi\or
\@tempcnta #1\relax\multiply\@tempcnta
\sixt@@n \advance\@tempcnta -\tw@ \else
\@tempcnta #1\relax\multiply\@tempcnta
\sixt@@n \advance\@tempcnta 7 \fi\ifnum #2<\z@ \advance\@tempcnta 64 \fi
\char\@tempcnta}
\gdef\@vline{\ifnum \@yarg <\z@ \@downline \else \@upline\fi}
\gdef\@upline{%
  \hb@xt@\z@{\hskip -\@halfwidth \vrule \@width \@wholewidth
   \@height \@linelen \@depth \z@\hss}}
\gdef\@downline{%
  \hb@xt@\z@{\hskip -\@halfwidth \vrule \@width \@wholewidth
   \@height \z@ \@depth \@linelen \hss}}
\gdef\@upvector{\@upline\setbox\@tempboxa\hbox{\@linefnt\char'66}\raise
     \@linelen \hb@xt@\z@{\lower \ht\@tempboxa\box\@tempboxa\hss}}
\gdef\@downvector{\@downline\lower \@linelen
      \hb@xt@\z@{\@linefnt\char'77\hss}}
\gdef\dashbox#1(#2,#3){\leavevmode\hb@xt@\z@{\baselineskip \z@skip
\lineskip \z@skip
\@dashdim #2\unitlength
\@dashcnt \@dashdim \advance\@dashcnt 200
\@dashdim #1\unitlength\divide\@dashcnt \@dashdim
\ifodd\@dashcnt\@dashdim \z@
\advance\@dashcnt \@ne \divide\@dashcnt \tw@
\else \divide\@dashdim \tw@ \divide\@dashcnt \tw@
\advance\@dashcnt \m@ne
\setbox\@dashbox \hbox{\vrule \@height \@halfwidth \@depth \@halfwidth
\@width \@dashdim}\put(0,0){\copy\@dashbox}%
\put(0,#3){\copy\@dashbox}%
\put(#2,0){\hskip-\@dashdim\copy\@dashbox}%
\put(#2,#3){\hskip-\@dashdim\box\@dashbox}%
\multiply\@dashdim \thr@@
\fi
\setbox\@dashbox \hbox{\vrule \@height \@halfwidth \@depth \@halfwidth
\@width #1\unitlength\hskip #1\unitlength}\@tempcnta\z@
\put(0,0){\hskip\@dashdim \@whilenum \@tempcnta <\@dashcnt
\do{\copy\@dashbox\advance\@tempcnta \@ne }}\@tempcnta\z@
\put(0,#3){\hskip\@dashdim \@whilenum \@tempcnta <\@dashcnt
\do{\copy\@dashbox\advance\@tempcnta \@ne }}%
\@dashdim #3\unitlength
\@dashcnt \@dashdim \advance\@dashcnt 200
\@dashdim #1\unitlength\divide\@dashcnt \@dashdim
\ifodd\@dashcnt \@dashdim \z@
\advance\@dashcnt \@ne \divide\@dashcnt \tw@
\else
\divide\@dashdim \tw@ \divide\@dashcnt \tw@
\advance\@dashcnt \m@ne
\setbox\@dashbox\hbox{\hskip -\@halfwidth
\vrule \@width \@wholewidth
\@height \@dashdim}\put(0,0){\copy\@dashbox}%
\put(#2,0){\copy\@dashbox}%
\put(0,#3){\lower\@dashdim\copy\@dashbox}%
\put(#2,#3){\lower\@dashdim\copy\@dashbox}%
\multiply\@dashdim \thr@@
\fi
\setbox\@dashbox\hbox{\vrule \@width \@wholewidth
\@height #1\unitlength}\@tempcnta\z@
\put(0,0){\hskip -\@halfwidth \GAL@ignore@next@galley@vbox{\@whilenum \@tempcnta <\@dashcnt
\do{\vskip #1\unitlength\copy\@dashbox\advance\@tempcnta \@ne }%
\vskip\@dashdim}}\@tempcnta\z@
\put(#2,0){\hskip -\@halfwidth \GAL@ignore@next@galley@vbox{\@whilenum \@tempcnta<\@dashcnt
\do{\vskip #1\unitlength\copy\@dashbox\advance\@tempcnta \@ne }%
\vskip\@dashdim}}}\@makepicbox(#2,#3)}
\gdef\@ovvert#1#2{\GAL@ignore@next@galley@vbox to\@ovyy{%
    \if@ovb \@tempcntb \@tempcnta \advance \@tempcntb #1\relax
      \kern -\@ovro \hbox{\char \@tempcntb}\nointerlineskip
    \else \kern \@ovri \kern \@ovdy \fi
    \leaders\vrule \@width \@wholewidth\vfil \nointerlineskip
    \if@ovt \@tempcntb \@tempcnta \advance \@tempcntb #2\relax
      \hbox{\char \@tempcntb}%
    \else \kern \@ovdy \kern \@ovro \fi}}
\catcode`\:=12
\def\@xfloat #1[#2]{%
  \@nodocument
  \def \@captype {#1}%
   \def \@fps {#2}%
   \@onelevel@sanitize \@fps
   \def \reserved@b {!}%
   \ifx \reserved@b \@fps
     \@fpsadddefault
   \else
     \ifx \@fps \@empty
       \@fpsadddefault
     \fi
   \fi
   \ifhmode
     \@bsphack
     \@floatpenalty -\@Mii
   \else
     \@floatpenalty-\@Miii
   \fi
  \ifinner
     \@parmoderr\@floatpenalty\z@
  \else
    \@next\@currbox\@freelist
      {%
       \@tempcnta \sixt@@n
       \expandafter \@tfor \expandafter \reserved@a
         \expandafter :\expandafter =\@fps
         \do
          {%
           \if \reserved@a h%
             \ifodd \@tempcnta
             \else
               \advance \@tempcnta \@ne
             \fi
           \fi
           \if \reserved@a t%
             \@setfpsbit \tw@
           \fi
           \if \reserved@a b%
             \@setfpsbit 4%
           \fi
           \if \reserved@a p%
             \@setfpsbit 8%
           \fi
           \if \reserved@a !%
             \ifnum \@tempcnta>15
               \advance\@tempcnta -\sixt@@n\relax
             \fi
           \fi
           }%
       \@tempcntb \csname ftype@\@captype \endcsname
       \multiply \@tempcntb \@xxxii
       \advance \@tempcnta \@tempcntb
       \global \count\@currbox \@tempcnta
       }%
    \@fltovf
  \fi
  \global \setbox\@currbox
    \color@vbox
      \normalcolor
      \vbox \bgroup
        \hsize\columnwidth
        \@parboxrestore
        \@floatboxreset
}
\catcode`\:=11
\def\end@float{%
  \@endfloatbox
  \ifnum\@floatpenalty <\z@
    \@largefloatcheck
    \@cons\@currlist\@currbox
    \ifnum\@floatpenalty <-\@Mii
      \penalty -\@Miv
      \@tempdima\prevdepth
      \GAL@ignore@next@galley@vbox{}%
      \prevdepth\@tempdima
      \penalty\@floatpenalty
    \else
      \vadjust{\penalty -\@Miv \GAL@ignore@next@galley@vbox{}\penalty\@floatpenalty}\@Esphack
    \fi
  \fi
}
\def \@xympar{%
  \ifnum\@floatpenalty <\z@\@cons\@currlist\@marbox\fi
  \setbox\@tempboxa
    \color@vbox
      \vbox \bgroup
  \end@float
  \@ignorefalse
  \@esphack
}
\def \AtBeginDvi #1{%
  \global \setbox \@begindvibox
    \vbox{\unvbox \@begindvibox #1}%
}
\def\clearpage{%
  \ifvmode
    \ifnum \@dbltopnum =\m@ne
      \ifdim \pagetotal <\topskip
        \hbox{}%
      \fi
    \fi
  \fi
  \newpage
  \write\m@ne{}%
  \GAL@ignore@next@galley@vbox{}%
  \penalty -\@Mi
}
\def \@emptycol {\GAL@ignore@next@galley@vbox{}\penalty -\@M}
\long\def \@topnewpage [#1]{%
  \@nodocument
  \@next\@currbox\@freelist{}{}%
  \global \setbox\@currbox
    \color@vbox
      \normalcolor
      \vbox {%
        \hsize\textwidth
        \@parboxrestore
        \col@number \@ne
        #1%
        \vskip -\dbltextfloatsep
             }%
    \color@endbox
  \ifdim \ht\@currbox>\textheight
    \ht\@currbox \textheight
  \fi
  \global \count\@currbox \tw@
  \@tempdima -\ht\@currbox
  \advance \@tempdima -\dbltextfloatsep
  \global \advance \@colht \@tempdima
  \ifx \@dbltoplist \@empty
  \else
    \@latexerr{Float(s) lost}\@ehb
    \let \@dbltoplist \@empty
  \fi
  \@cons \@dbltoplist \@currbox
  \global \@dbltopnum \m@ne
  \ifdim \@colht<2.5\baselineskip
    \@latex@warning@no@line {Optional argument of \noexpand\twocolumn
                too tall on page \thepage}%
    \@emptycol
    \if@firstcolumn
    \else
      \@emptycol
    \fi
  \else
    \global \vsize \@colht
    \global \@colroom \@colht
    \@floatplacement
  \fi
}
\gdef\@specialoutput{%
   \ifnum \outputpenalty>-\@Mii
     \@doclearpage
   \else
     \ifnum \outputpenalty<-\@Miii
       \ifnum \outputpenalty<-\@MM \deadcycles \z@ \fi
       \global \setbox\@holdpg \vbox {\unvbox\@cclv}%
     \else
       \global \setbox\@holdpg \vbox{%
                      \unvbox\@holdpg
                      \unvbox\@cclv
                      \setbox\@tempboxa \lastbox
                      \unskip
                                     }%
       \@pagedp \dp\@holdpg
       \@pageht \ht\@holdpg
       \unvbox \@holdpg
       \@next\@currbox\@currlist{%
         \ifnum \count\@currbox>\z@
           \advance \@pageht \@pagedp
           \ifvoid\footins \else
             \advance \@pageht \ht\footins
             \advance \@pageht \skip\footins
             \advance \@pageht \dp\footins
           \fi
           \ifvbox \@kludgeins
             \ifdim \wd\@kludgeins=\z@
               \advance \@pageht \ht\@kludgeins
             \fi
           \fi
           \@reinserts
           \@addtocurcol
         \else
           \@reinserts
           \@addmarginpar
         \fi
         }\@latexbug
       \ifnum \outputpenalty<\z@
         \if@nobreak
           \nobreak
         \else
           \addpenalty \interlinepenalty
         \fi
       \fi
     \fi
   \fi
}
\def \@doclearpage {%
     \ifvoid\footins
       \setbox\@tempboxa\vsplit\@cclv to\z@ \unvbox\@tempboxa
       \setbox\@tempboxa\box\@cclv
       \xdef\@deferlist{\@toplist\@botlist\@deferlist}%
       \global \let \@toplist \@empty
       \global \let \@botlist \@empty
       \global \@colroom \@colht
       \ifx \@currlist\@empty
       \else
          \@latexerr{Float(s) lost}\@ehb
          \global \let \@currlist \@empty
       \fi
       \@makefcolumn\@deferlist
       \@whilesw\if@fcolmade \fi{\@opcol\@makefcolumn\@deferlist}%
       \if@twocolumn
         \if@firstcolumn
           \xdef\@dbldeferlist{\@dbltoplist\@dbldeferlist}%
           \global \let \@dbltoplist \@empty
           \global \@colht \textheight
           \begingroup
              \@dblfloatplacement
              \@makefcolumn\@dbldeferlist
              \@whilesw\if@fcolmade \fi{\@outputpage
                                        \@makefcolumn\@dbldeferlist}%
           \endgroup
         \else
           \GAL@ignore@next@galley@vbox{}\clearpage
         \fi
       \fi
     \else
       \setbox\@cclv\vbox{\box\@cclv\vfil}%
       \@makecol\@opcol
       \clearpage
     \fi
}
\gdef \@makecol {%
   \ifvoid\footins
     \setbox\@outputbox \box\@cclv
   \else
     \setbox\@outputbox \vbox {%
       \boxmaxdepth \@maxdepth
       \@tempdima\dp\@cclv
       \unvbox \@cclv
       \vskip-\@tempdima
       \vskip \skip\footins
       \color@begingroup
         \normalcolor
         \footnoterule
         \unvbox \footins
       \color@endgroup
       }%
   \fi
   \xdef\@freelist{\@freelist\@midlist}%
   \global \let \@midlist \@empty
   \@combinefloats
   \ifvbox\@kludgeins
     \@makespecialcolbox
   \else
     \setbox\@outputbox \vbox to\@colht {%
       \@texttop
       \dimen@ \dp\@outputbox
       \unvbox \@outputbox
       \vskip -\dimen@
       \@textbottom
       }%
   \fi
   \global \maxdepth \@maxdepth
}
\gdef \@makespecialcolbox {%
   \setbox\@outputbox \vbox {%
     \@texttop
     \dimen@ \dp\@outputbox
     \unvbox\@outputbox
     \vskip-\dimen@
     }%
   \@tempdima \@colht
   \ifdim \wd\@kludgeins>\z@
     \advance \@tempdima -\ht\@outputbox
     \advance \@tempdima \pageshrink
     \setbox\@outputbox \vbox to \@colht {%
       \unvbox\@outputbox
       \vskip \@tempdima
       \@textbottom
       }%
   \else
     \advance \@tempdima -\ht\@kludgeins
     \setbox \@outputbox \vbox to \@colht {%
       \GAL@ignore@next@galley@vbox to \@tempdima {%
         \unvbox\@outputbox
         \@textbottom}%
       \vss}%
   \fi
   {\setbox \@tempboxa \box \@kludgeins}%
}
\def\@outputpage{%
\begingroup           % the \endgroup is put in by \aftergroup
  \@resetactivechars
  \@parboxrestore
  \let \protect \noexpand   % <- this moved after parboxrestore!!!!
  \shipout \vbox{%
    \set@typeset@protect
    \aftergroup \endgroup
    \aftergroup \set@typeset@protect
                                % correct? or just restore by ending
                                % the group?
  \if@specialpage
    \global\@specialpagefalse\@nameuse{ps@\@specialstyle}%
  \fi
  \if@twoside
    \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
         \let\@themargin\oddsidemargin
    \else \let\@thehead\@evenhead
       \let\@thefoot\@evenfoot \let\@themargin\evensidemargin
    \fi
  \fi
  \reset@font
  \normalsize
  \normalsfcodes
  \let\label\@gobble
  \let\index\@gobble
  \let\glossary\@gobble
  \baselineskip\z@skip \lineskip\z@skip \lineskiplimit\z@
    \@begindvi
    \vskip \topmargin
    \moveright\@themargin \vbox {%
      \setbox\@tempboxa \vbox to\headheight{%
        \vfil
        \color@hbox
          \normalcolor
          \hb@xt@\textwidth{\@thehead}%
        \color@endbox
        }%                        %% 22 Feb 87
      \dp\@tempboxa \z@
      \box\@tempboxa
      \vskip \headsep
      \box\@outputbox
      \baselineskip \footskip
      \color@hbox
        \normalcolor
        \hb@xt@\textwidth{\@thefoot}%
      \color@endbox
      }%
    }%
  \global \@colht \textheight
  \stepcounter{page}%
  \let\firstmark\botmark
}
\def \@cflt{%
    \let \@elt \@comflelt
    \setbox\@tempboxa \vbox{}%
    \@toplist
    \setbox\@outputbox \vbox{%
                             \boxmaxdepth \maxdepth
                             \unvbox\@tempboxa
                             \vskip -\floatsep
                             \topfigrule
                             \vskip \textfloatsep
                             \unvbox\@outputbox
                             }%
    \let\@elt\relax
    \xdef\@freelist{\@freelist\@toplist}%
    \global\let\@toplist\@empty
}
\def\@comflelt#1{\setbox\@tempboxa
      \vbox{\unvbox\@tempboxa\box #1\vskip\floatsep}}
\def \@combinedblfloats{%
  \ifx \@dbltoplist \@empty
  \else
    \setbox\@tempboxa \vbox{}%
    \let \@elt \@comdblflelt
    \@dbltoplist
    \let \@elt \relax
    \xdef \@freelist {\@freelist\@dbltoplist}%
    \global\let \@dbltoplist \@empty
    \setbox\@outputbox \vbox to\textheight
      {%\boxmaxdepth\maxdepth   %% probably not needed, CAR
       \unvbox\@tempboxa\vskip-\dblfloatsep
       \ifnum \@dbltopnum>\m@ne
         \dblfigrule
       \fi
       \vskip \dbltextfloatsep
       \box\@outputbox
       }%
  \fi
}
\def\@vtryfc #1{%
  \global\setbox\@outputbox\vbox{}%
  \let\@elt\@wtryfc
  \@flsucceed
  \global\setbox\@outputbox \vbox to\@colht{%
    \vskip \@fptop
    \vskip -\@fpsep
    \unvbox \@outputbox
    \vskip \@fpbot}%
  \let\@elt\relax
  \xdef #1{\@failedlist\@flfail}%
  \xdef\@freelist{\@freelist\@flsucceed}}
\def\@wtryfc #1{%
  \global\setbox\@outputbox\vbox{%
    \unvbox\@outputbox
    \vskip\@fpsep
    \box #1}}
\def\@addmarginpar{\@next\@marbox\@currlist{\@cons\@freelist\@marbox
    \@cons\@freelist\@currbox}\@latexbug\@tempcnta\@ne
    \if@twocolumn
        \if@firstcolumn \@tempcnta\m@ne \fi
    \else
      \if@mparswitch
         \ifodd\c@page \else\@tempcnta\m@ne \fi
      \fi
      \if@reversemargin \@tempcnta -\@tempcnta \fi
    \fi
    \ifnum\@tempcnta <\z@  \global\setbox\@marbox\box\@currbox \fi
    \@tempdima\@mparbottom
    \advance\@tempdima -\@pageht
    \advance\@tempdima\ht\@marbox
    \ifdim\@tempdima >\z@
      \@latex@warning@no@line {Marginpar on page \thepage\space moved}%
    \else
      \@tempdima\z@
    \fi
    \global\@mparbottom\@pageht
    \global\advance\@mparbottom\@tempdima
    \global\advance\@mparbottom\dp\@marbox
    \global\advance\@mparbottom\marginparpush
    \advance\@tempdima -\ht\@marbox
    \global\setbox \@marbox
                   \vbox {\vskip \@tempdima
                          \box \@marbox}%
    \global \ht\@marbox \z@
    \global \dp\@marbox \z@
    \kern -\@pagedp
    \nointerlineskip
    \hb@xt@\columnwidth
      {\ifnum \@tempcnta >\z@
          \hskip\columnwidth \hskip\marginparsep
       \else
          \hskip -\marginparsep \hskip -\marginparwidth
       \fi
       \box\@marbox \hss}%
    \nointerlineskip
    \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}}
\def\@outputdblcol{%
  \if@firstcolumn
    \global \@firstcolumnfalse
    \global \setbox\@leftcolumn \box\@outputbox
  \else
    \global \@firstcolumntrue
    \setbox\@outputbox \vbox {%
                         \hb@xt@\textwidth {%
                           \hb@xt@\columnwidth {%
                             \box\@leftcolumn \hss}%
                           \hfil
                           \vrule \@width\columnseprule
                           \hfil
                           \hb@xt@\columnwidth {%
                             \box\@outputbox \hss}%
                                             }%
                              }%
    \@combinedblfloats
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi
        {\@outputpage
         \@startdblcolumn}%
    \endgroup
  \fi
}



%    \end{macrocode}
%
%    \begin{macrocode}
\catcode`\:=12\relax
\endinput
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
%
% \Finale
%