File: tthgold.lex

package info (click to toggle)
tth 4.12%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,672 kB
  • sloc: xml: 291; makefile: 175; ansic: 131; sh: 64
file content (8795 lines) | stat: -rw-r--r-- 309,561 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
 /* TtH flex file to convert plain TeX and LaTeX to HTML.
 	 (c) Ian Hutchinson, 1997-2011.

 Released under the terms of the GPL2. See license.txt

 This file needs to be turned into a C program using flex
 And then compiled into the tth executable using a C compiler.
   */
%{
#define TTH_VERSION "4.10"
  /*#define TTH_GOLD "gold" no longer a distinction*/  /*sf*/
#define TTH_HEAD "HEAD"  /*sf*/
char tth_DOC[]="\n\
                Version XXXX (c)1997-2017 Ian Hutchinson\n\
            TtH (TeX-to-HTML) translates TeX into HTML.\n\n\
The program is a filter by default: it reads from stdin and writes to stdout.\n\
But a non-switch argument specifies the file[.tex] to translate to file.html.\n\
Diagnostics concerning unknown or untranslated constructs are sent to stderr.\n\n\
  Obtain USAGE & switch information by:   tth -?\n\
  Obtain QUALIFICATIONS by:               tth -?q\n\n\
TtH may be used and distributed under the terms of the GPL version 2.\n";
char tth_DOCQ[]="\n\
TeX including mathematics; Plain TeX; LaTeX (2e). \n\
Limitations and special usages:\n\
 \\input searches TTHINPUTS not TEXINPUTS. Counter operations are global.\n\
 \\catcode changes, tabbing environment, \\usepackage: not supported.\n\
 \\epsfbox{file.eps} links or inlines the figure file, depending on -e switch.\n\
 \\special{html:stuff} inserts HTML stuff. \\iftth is always true.\n\
 \\href{URL}{anchor text} inserts a hypertext anchor pointing to URL.\n\
 %%tth: ... passes the rest of the comment to TtH (not TeX) for parsing\n\
\n\
";
char tth_USAGE[]="\n\
USAGE: tth [-a -c ...] [<]file.tex [>file.html] [2>err]\n\
 A non-switch argument specifies the input file and the implied output file.\n\
   -h print help. -? print this usage.\n\
   -a enable automatic calls of LaTeX: if no aux file exists, attempt to call.\n\
               picture environment conversion using latex2gif. Default omit.\n\
   -c prefix header \"Content-type: text/HTML\" (for direct web serving).\n\
   -d disable definitions with delimited arguments. Default enable.\n\
   -e? epsfbox handling: -e1 convert to png/gif using user-supplied ps2png/gif.\n\
       -e2 convert and include inline. -e0 (default) no conversion, just ref. \n\
   -f? limit built-up fraction nesting in display eqns to ?(0-9). Default 5.\n\
   -g remove, don\'t guess intent of, \\font commands. Default guess font/size.\n\
   -i use italic font for equations (like TeX). Default roman.\n\
   -j? use index page length ?. Default 20 lines. -j single column.\n\
   -Lfile tell tth the base file (no extension) for LaTeX auxiliary input,\n\
      enables LaTeX commands (e.g. \\frac) without a \\documentclass line.\n\
   -n? HTML title format control. 0 raw. 1 expand macros. 2 expand eqns. \n\
   -ppath specify additional directories (path) to search for input files.\n\
   -r raw HTML output (omit header and tail) for inclusion in other files.\n\
   -t display built-up items in textstyle equations. Default in-line.\n\
   -u unicode character encoding. (Default iso-8859-1).\n\
   -w? HTML writing style. Default no head/body tags. -w -w0 no title.\n\
     -w1 single title only, head/body tags. -w2 XHTML.\n\
   -y? equation style: bit 1 compress vertically; bit 2 inline overaccents.\n\
   -xmakeindxcmd  specify command for making index. Default \"makeindex\"\n\
   -v give verbose commentary. -V even more verbose (for debugging).\n";
char *tth_debughelp="\n\
Debugging mask: usage tth -vn with n the sum of:\n\
Bit 1.   1 Standard verbose messages.\n\
Bit 2.   2 Equation code.\n\
Bit 3.   4 Definitions, counters, countersetting.\n\
Bit 4.   8 Macro expansions. Delimited argument matching.\n\
Bit 5.   16 Stack levels, brace counts etc.\n\
Bit 6.   32 Tabular, Figures and Pictures.\n\
Bit 7.   64 Comments.\n\
Bit 8.   128 Auxiliary Files.\n\
Bit 9.   256 Cross-references.\n\
Bit 10.  512 Built-ins, codes.\n\
Bit 11.  1024 Conditionals, dimensions.\n\
Bit 12.  2048 Fonts\n\
Bit 13.  4096 Termination.\n\
Bit 14.  8192 Line-end diagnosis.\n\
Bit 16. 32768 Silence unknown command warnings.\n\
 -V= 2048+256+4+2+1\n";


#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h> /* For toupper */
#include <time.h>
#define GET_DIMEN {yy_push_state(lookforunit);yy_push_state(lookfornum);\
                   *argchar=0;}
#define TTH_MAXDEPTH 30
#define TTH_CHARLEN 500
#define TTH_DLEN 20000
#define TTH_34DLEN 72000
#define TTH_FONTLEN 200
#ifdef __vms
#define  SUCCESS 1
#define RMCMD "del"
#define RMTERM ";"
#define PATH_SEP ","
#define DIR_SEP ""
#else
#define  SUCCESS 0
#ifdef MSDOS
#define RMCMD "del"
#define RMTERM ""
#define PATH_SEP ";"
#define DIR_SEP "\\"
#else 
#define RMCMD "rm"
#define RMTERM ""
#define PATH_SEP ":"
#define DIR_SEP "/"
#endif
#endif

 /*#define TTH_EXIT(level) exit(level)*/
#define TTH_EXIT(level) return level;
#define TTH_FATAL(level) yy_push_state(error);tth_ercnt=-abs(level);tth_erlev=level;

 /* Silence warnings */
#define YY_NO_TOP_STATE

    /* lex Globals */
void tth_push(),tth_pop();
char* tth_symbol_point();
int tth_root_len[TTH_MAXDEPTH] ={0};
char tth_root_index[TTH_MAXDEPTH][TTH_CHARLEN]={{0}};
int tth_root_depth=0;
int tth_num_lines = 1;
int tth_push_depth=0;
char tth_closures[TTH_MAXDEPTH][TTH_CHARLEN];
char tth_texclose[TTH_MAXDEPTH][TTH_CHARLEN]={{0}};
char tth_font_open[TTH_MAXDEPTH][TTH_CHARLEN]={{0}};
char tth_font_close[TTH_MAXDEPTH][TTH_CHARLEN]={{0}};
char tth_fonto_def[TTH_CHARLEN]={0};
char tth_fontc_def[TTH_CHARLEN]={0};
int tth_key[TTH_MAXDEPTH];
int tth_debug = 0;
int tth_verb = 0;
int tth_delimdef=1;
int tth_mathitalic=1;
int tth_flev0=5;
int tth_flev=5;
int tth_multinum=1;
int tth_autopic=0;
int tth_istyle=3;
int tth_htmlstyle=0;
int tth_unicode=2;
int tth_indexpage=20;
int tth_allowinput=1;
int tth_titlestate=4;
int tth_tagpurge=0;

#ifdef MSDOS
 /* Define the size of djgpp stack*/
unsigned _stklen = 1048576;  /* need a larger stack (1Mb) */
#endif

 /*Global string pointer and length*/
#define MAX_INCLUDE_DEPTH 100
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
YY_BUFFER_STATE halbuff;
FILE *tth_inputfile=0;
FILE *tth_indexfile=0;
FILE *tth_indexstyle=0;
FILE *tth_picfile=0;
FILE *tth_fdout=0;
int tth_stack_ptr = 0;
int tth_ercnt=0;
int tth_erlev=0;
int tth_epsftype=0;
int tth_fontguess=1;
int tth_splitfile=0; /*sf*/
int tth_inlinefrac=0;
char tth_latex_file[TTH_CHARLEN]={0}; /* base name of latex files. */
char tth_index_cmd[TTH_CHARLEN]={0}; /* Makeindex command line. */
char tth_texinput_path[TTH_CHARLEN]={0};
int tth_LaTeX=0;
char *tth_latex_builtins = "\\def\\frac#1#2{{{#1}\\over{#2}}}\
\\def\\label#1{\\tthlabel}\
\\def\\newlabel#1#2{\\tthnewlabel}\
\\def\\ref#1{\\tthref}\
\\def\\pageref#1{\\tthpageref}\
\\def\\index{\\tthgpindex}\
\\def\\see#1#2{{\\it\\seename} #1}\
\\tthcountinit\
\\newcount\\footnote\
\\newcounter{chapter}\
\\newcounter{section}[chapter]\
\\newcounter{subsection}[section]\
\\renewcommand{\\thesubsection}{\\thesection.\\arabic{subsection}}\
\\newcounter{subsubsection}[subsection]\
\\renewcommand{\\thesubsubsection}{\\thesubsection.\\arabic{subsubsection}}\
\\newcounter{equation}[chapter]\
\\newcounter{figure}[chapter]\
\\newcounter{table}[chapter]\
\\newcounter{part}\
\\newcounter{secnumdepth}\
\\setcounter{secnumdepth}{3}\
\\def\\newtheorem#1#2{\\newenvironment{#1}{\\par\\stepcounter{#1}\
  \\textbf{#2 \\arabic{#1}}\\bgroup \\em}{\\par\\egroup}\\newcounter{#1}}\
\\def\\tthenclose#1#2#3{#1{#3}#2}\
\\def\\prefacename{Preface}\
\\def\\refname{References}\
\\def\\abstractname{Abstract}\
\\def\\bibname{Bibliography}\
\\def\\chaptername{Chapter}\
\\def\\appendixname{Appendix}\
\\def\\contentsname{Contents}\
\\def\\listfigurename{List of Figures}\
\\def\\listtablename{List of Tables}\
\\def\\indexname{Index}\
\\def\\figurename{Figure}\
\\def\\tablename{Table}\
\\def\\partname{Part}\
\\def\\enclname{encl}\
\\def\\ccname{cc}\
\\def\\headtoname{To}\
\\def\\pagename{Page}\
\\def\\seename{see}\
\\def\\alsoname{see also}\
\\def\\proofname{Proof}\
\\def\\newfont#1#2{\\font#1 #2 }\
\\def\\thanks#1{\\footnote{#1}}\
\\def\\bibcite{\\gdef}\n";
char *tth_latex_builtins2=
"\\newcommand{\\part}[1][]{\\tthpart}\
\\newcommand{\\chapter}[1][]{\\tthchapter}\
\\newcommand{\\section}[1][]{\\tthsection}\
\\newcommand{\\subsection}[1][]{\\tthsubsection}\
\\newcommand{\\subsubsection}[1][]{\\tthsubsubsection}\
\\newcounter{paragraph}[subsubsection]\
\\renewcommand{\\theparagraph}{\\thesubsubsection.\\arabic{paragraph}}\
\\newcommand{\\paragraph}[1][]{\\tthparagraph}\
\\newcounter{subparagraph}[paragraph]\
\\renewcommand{\\thesubparagraph}{\\theparagraph.\\arabic{subparagraph}}\
\\newcommand{\\subparagraph}[1][]{\\tthsubparagraph}\
\\newcommand{\\author}[2][]{\\centerheader{3}{#2}{align=\"center\"}}\
\\newcommand{\\date}[2][]{\\centerheader{3}{#2}{align=\"center\"}}\
\\newcommand{\\address}[2][]{\\centerheader{3}{#2}{align=\"center\"}}\
\\newcommand{\\parbox}[2][]{\\hbox to #2}\
\\def\\symbol#1{\\char#1}\
\\def\\text{\\textrm}\
\\def\\definecolor#1#2#3{\\def{#1}{{#3}}}\
\\def\\setlength#1#2{#1=#2}\
\\def\\columnwidth{\\hsize}\
\\newcommand\\caption[1][]{\\tthcaption}\
\\newenvironment{longtable}\
{\\begin{table}\\begin{center}\
 \\def\\noalcen##1{\\noalign{\\centering ##1}\\stepcounter{table}}\
 \\renewcommand\\caption[2][]{\\ifx ##2* \\noalcen\
 \\else\\noalign{\\tthcaption{##2}}\\fi}\
 \\def\\endhead{\\\\}\\def\\endfirsthead{\\\\}\
 \\def\\endfoot{\\\\}\\def\\endlastfoot{\\\\}\
 \\def\\kill{\\\\}\
 \\begin{tabular}}\
 {\\end{tabular}\\end{center}\\end{table}}\
\\def\\tthciteform{}\\def\\tthbibform{[}\\def\\tthbibcb{]}\
\\def\\tthciteob{[}\\def\\tthcitepb{,}\\def\\tthcitefi{,}\\def\\tthcitecb{]}\
\\newcommand\\citet[2][]{{\\def\\tthciteform##1##2##3##4{##3 [##2]}\
\\def\\tthciteob{}\\def\\tthcitecb{}\\def\\tthcitib{}\\cite[#1]{#2}}}\
\\newcommand\\citep[2][]{{\\def\\tthciteform##1##2##3##4{##3, ##2}\
\\def\\tthciteob{[}\\cite[#1]{#2}}}\
\\newcommand\\marginpar[2][]{\\special{html:<table align=\"right\" border=\
\"border\"><tr><td align=\"right\">}#2\\special{html:</td></tr></table>}}\
\\def\\newsavebox{\\newbox}\n";
char *tth_latex_builtins3=
"\\def\\tthsplittail{\
\\special{html:\n<hr /><table width=\"100\\%\"><tr><td>\n\
 <a href=\"index.html\">HEAD</a></td><td align=\"right\">\n\
<a href=\"}\\tthfilenext\\special{html:\">}NEXT\n\
\\special{html:</a></td></tr></table>\n</div></body></html>}}\n\
\\def\\tthsplittop{\
\\special{html:<table width=\"100\\%\"><tr><td>\n\
 <a href=\"index.html\">HEAD</a></td><td align=\"right\">\n\
 <a href=\"}\\tthfilechar\\special{html:\">}PREVIOUS\n\
\\special{html:</a></td></tr></table>}}\n\
\\def\\glossary\\index\n\
\\newenvironment{floatingfigure}{\\special{html:\
<br clear=\"all\" />\n\
<table border=\"0\" align=\"left\" width=\"20\\%\"><tr><td>}\
\\begin{figure}\\wd}{\\special{html:</td></tr></table>}\\end{figure}}\n\
\\def\\tabularnewline{\\\\}\n\
\\def\\AtEndDocument#1{}";
char *tth_builtins = "\\def\\bye{\\vfill\\eject\\end }\
\\def\\cal{\\sffamily\\it }\
\\def\\phantom#1{\\tthphantom}\
\\let\\hphantom=\\phantom\
\\def\\root#1\\of#2{\\sqrt[#1]{#2}}\
\\def\\H#1{\\\"#1}\\def\\b#1{\\underline{#1}}\
\\def\\v{\\noexpand\\v}\\def\\u{\\noexpand\\u}\
\\def\\t{\\noexpand\\t}\\def\\d{\\noexpand\\d}\
\\def\\c#1{\\noexpand\\c #1}\
\\def\\url{\\tthurl}\
\\def\\hyperlink#1#2{\\href{\\##1}{#2}}\
\\def\\hypertarget#1#2{\\special{html:<a id=\"#1\">}#2\\special{html:</a>}}\
\\def\\proclaim #1.#2\\par{\\medskip{\\bf#1.\\ }{\\sl#2\\par}}\
\\def\\newdimen#1{\\def#1{\\tthdimen#1 0\\tth_hsize}}\
\\def\\hsize{\\tthdimen\\hsize 1\\tth_hsize}\
\\def\\ensuremath#1{$#1$}\
\\def\\TeX{\\ensuremath{\\rm T_EX}}\
\\def\\LaTeX{\\ensuremath{\\rm L^AT_EX}}\
\\def\\buildrel#1\\over#2{\\mathop{#2}^{#1}}\
\\newcount\\tthdummy\
\\def\\uppercase#1{{\\tth_uppercase #1}}\
\\def\\newbox#1{\\def#1{}}\n\
\\def\\today{\\tth_today}\n\
\\def\\tthfootnotes{Footnotes}\n\
\\def\\string#1{\\verb!#1!}\n\
\\def\\displaylines#1{\\eqalign{#1}}\n\
\\def\\leqalignno#1{\\eqalignno{#1}}\n\
\\def\\leqno#1{\\eqno{#1}}\
\\def\\bm#1{{\\tth_bm #1}}\
\\newenvironment{abstract}{\\begin{tthabstract}}{\\end{tthabstract}}\
\\newcommand\\tthoutopt[1][]{#1}\n\
\\newcommand\\tthnooutopt[1][]{}\n";

 /* static functions */
static int indexkey();
static void mkkey(),rmkey(),rmdef(),mkdef();
static void delimit();
static int b_align();
static int roman();
static int scaledpoints();
static void tagpurge();
static int adddimen();

%}


 /* Start condition stacks, not POSIX */
%option stack	
 /* Permits to compile without -lfl */
%option noyywrap	
%option noreject
 /* Remove isatty calls for VMS */
%option always-interactive 

 /* Not as accurate, probably because of rescanning. %option yylineno */

	/* Start conditions */
 /* Paragraph grouping for beginsection, item etc: */
%s pargroup
 /* Cause par to scan texclose.*/
%s parclose 
 /* Look for first token following and put argchar at end:*/
%x tokenarg
 /* Expand following command and output expchar after first token,
    if non-null, else prefix exptex and rescan (in equations)*/
%x exptokarg
 /* Put swapchar after following open brace and rescan. */
%x swaparg
 /* Enclose a bare token in braces. Caller must initialize dupstore: */
%x embracetok
 /* Output the current brace group as raw text. Terminate with closing: */
%x rawgroup
 /* Output verbatim till we encounter \end{verbatim} */
%x verbatim
 /* Output verbatim till we encounter a character matching chr1[0] */
%x verb
 /* Output without HTML tags so that we are compatible with title*/
%x notags
 /* Get from here to end of brace group. Then treat according to storetype:
    0 Make argchar the closing of first, attach second copy, rescan.
    1 Save in supstore. 2 Save in substore. For sup/bscripting. 
    3 Rescan with argchar between first and second copies.
    4 Rescan one copy only with argchar prepended.
    5 Rescan one copy with argchar postpended.
 */
%x dupgroup
 /* Same thing but delimited by square brackets */
%x dupsquare
 /* Throw away a following group closed by \fi or \end{picture} */
%x discardgroup
 /* Throw away the following text closed by \else or \fi */
%x falsetext
 /* Inner if state inside falsetext. As falsetext except no else sensitivity*/
%x innerfalse 
 /* Throw away the following text closed by \or */
%x ortext
 /* Break out of dumping of ortext states */
%x orbreak
 /* Get the unexpanded tokens to compare for ifx */
%x getifx
 /* Get the tokens to compare for if */
%x getiftok
 /* Get the numbers to compare for ifnum */
%x getifnum
 /* Look for first number following. Put into argchar, and Pop. */
%x lookfornum 
 /* Look for first number following. Output num, argchar, and Pop. */
%x insertnum
 /* Look for unit.  Catenate to argchar. Construct dimension in anumber */
%x lookforunit 
 /* Get the first file-like argument. */
%x lookforfile 
 /* Get nothing but the corresponding closebrace. */
%x matchbrace
 /* Get a box definition for setbox. Mostly getting optional dimension */
%x getbox 
 /* Get an immediate sub or sup, else pop*/
%x getsubp
 /* Get the command we are defining only: */
%x getdef
 /* Get a brace group as the definition's name */ 
%x getdefbr 
 /* Get the definition's argument description. Leave number in narg. */
%x getnumargs
 /* Compress whitespace in delimited definition argument template and store*/
%x ddcomp
 /* Get the end part of a newenvironment */
%x getend
 /* Define a let command. Explicitly using predefined macro. */
%x letdef
 /* Throw away contiguous brace groups */
%x unknown
 /* Advancing dimensions */
%x dimadv

 /* Get complete definition of a new count: */
%x getcount
 /* Perform a counter advance: */
%x advance
 /* Output the value of a counter: */
%x number
 /* Set the value of a previously defined counter: */
%x counterset 

 /* Extract the halign template.  */
%x htemplate
 /* Inside tables, interpret & and \cr */
%s halign
 /* Handle ends of lines in halign state, e.g. \hline \end{tabular} \multi */
%x hendline
 /* State for exiting expand-after of an ampersand. */
%x hamper
 /* State for exiting expand-after of an ampersand in equations. */
%x mamper

%x vtemplate
%s valign

 /* Equation mode. */
%s equation
 /* Display table mode */
%s disptab
 /* Textbox in equations mode */
%s textbox

 /* latex listing environments */
%s Litemize
%s Lenumerate
%s Ldescription
%s Lindex

 /* Uppercase mode */
%s uppercase
 /* Small caps text mode, no braces allowed. */
%s textsc
 /* Define the token to be the next lot of text: */
%x define
 /* Obtain the bracegroup as a macro argument: */
%x macarg
 /* Obtain the bracket group as a macro argument: */
%x optag
 /* Detect the presence of [ and switch to optag if found */
%x optdetect
 /* Input a file. */
%x inputfile
 /* Parameter substitution in macros. */
%x psub
 /* Expanding an edef*/
%x xpnd
 /* Interpreting delimited definition argument */
%x delimint
 /* Removing spaces e.g. after commands */
%x removespace
 /* Warn if output takes place before title. */
%s titlecheck
 /* titlecheck state for strict HTML/XHTML. */
%s stricttitle
 /* Scan builtins at start. */
%x builtins
 /* Scan LaTeX builtins at start. */
%x latexbuiltins
 /* Glue flex clause removal */
%x glue
 /* rule dimension removal */
%x ruledim
 /* big delimiter get type */
%x bigdel
 /* Picture environment */
%x picture
 /* csname getting state */
%x csname
 /*tabular alignment string interpretation*/
%x talign
 /* Copying halign material to precell*/
%x tempamp
 /* Inserting space in horizontal lines and vertical.*/
%x hskip
%x vskip
 /* Dealing with hboxes */
%x hbox
 /* Dealing with vboxes */
%x vbox
 /* Setting Dimensions */
%x setdimen
 /* PreScanning tabular argument */
%x tabpre
 /* Error exiting state */
%x error
 /* Paragraph checking state after a newline when par is possible*/
%x parcheck
 /* Expand following token till we reach something no more expandable 
    but don't embrace it. Prefix exptex if not zero. */
%x tokexp
 /* Copying of a group but escaping special characters as we go. Hence
   making it suitable for subsequent verbatim or url handling. Ending
   as dugroup. */
%x escgroup
 /* Dupgroup that treats % as a normal character */
%x uncommentgroup
 /* Deal with the string that has been stored using uncommentgroup*/
%x urlgroup
%x indexgroup
 /* Checking if the start of a $$ indicates display table */
%x halsearch
	/* Defines */
 /* NOA	[^a-zA-Z0-9] Removed 1.04 */
NUM	[+-]?[0-9.]+
SP      [ ]
TSP     [ \t]
 /* Old versions. WSP     [ \t\n] WSC     [^ \t\n] NL      \n */
WSP     [ \t\r\n]
WSC     [^ \t\r\n]
NL      \n|\r|\r\n
NLC     [^\r\n]
CMNT    %[^\r\n]*{NL}?
ANY     .|\n
  /* Costs 120k C! BRCG   \{[^\}]*(\{[^\}]*(\{[^\}]*\})?[^\}]*\})?[^\}]*\} */
BRCG    \{[^\}]*\} 

%%

  /* Local storage */
%{
#define NCOUNT 256
#define NFNMAX 1600
#define NARMAX 20
#define TTH_PUSH_BUFF(rmv) if ( tth_stack_ptr >= MAX_INCLUDE_DEPTH )\
    {fprintf(stderr,buffdeep,tth_num_lines);TTH_EXIT( 1 );}\
    eofrmv[tth_stack_ptr]=rmv;\
    include_stack[tth_stack_ptr++] = YY_CURRENT_BUFFER;
char *buffdeep="**** Error: FATAL. Scan buffers nested too deeply. Infinite loop? Line %d.\n";
#define TTH_SCAN_STRING TTH_PUSH_BUFF(0);yy_scan_string
extern void tth_epsf(),tth_symext(),tth_encode(),tth_undefine();
 /*Not static except for tthfunc*/
#define STATIC
STATIC char closing[TTH_CHARLEN]={0};
STATIC char preclose[TTH_CHARLEN]={0};
STATIC char argchar[TTH_CHARLEN]={0};
STATIC char defchar[TTH_CHARLEN]={0};
STATIC char eqchar[4*TTH_CHARLEN]={0};
STATIC char eqchar2[4*TTH_CHARLEN]={0};
STATIC char scratchstring[TTH_CHARLEN]={0};
STATIC char scrstring[TTH_CHARLEN]={0};
STATIC char swapchar[TTH_CHARLEN]={0};
STATIC char expchar[TTH_CHARLEN]={0};
STATIC char exptex[TTH_CHARLEN]={0};
STATIC char strif[TTH_CHARLEN]={0};
STATIC char newcstr[TTH_CHARLEN]={0};
STATIC char boxalign[TTH_CHARLEN]={0};
STATIC char boxvalign[TTH_CHARLEN]={0};
STATIC char dupstore[TTH_DLEN];
STATIC char dupstore2[2*TTH_DLEN];
STATIC char supstore[TTH_DLEN]={0};
STATIC char substore[TTH_DLEN]={0};
STATIC char defstore[TTH_DLEN]={0};
STATIC char psubstore[TTH_DLEN]={0};
STATIC char chr1[2]={0};
STATIC int storetype=0;
STATIC int bracecount=0;
STATIC int horizmode=0; /* 1 in horizontal mode. -1 after a \n. 0 after a \par*/
STATIC int horiztemp=0;
STATIC int whitespace=0;
STATIC int edeftype=0;
 /* Stacking of halign and tabular operational data. */
STATIC int colnum=0;
STATIC char halstring[TTH_CHARLEN]={0};
STATIC char *halstrings[NARMAX];
STATIC YY_BUFFER_STATE halbuffs[NARMAX];
STATIC int halignenter=0;
STATIC int halenter[NARMAX]={99};
STATIC int halncols[NARMAX]={0};
STATIC int halind=0;
#define TTH_HAL_PUSH  if(tth_debug&32)fprintf(stderr,"HAL PUSH %d,",halind);\
   if(tth_debug&32)fprintf(stderr,"%s\n",halstring);\
  if(halind < NARMAX) {\
  halenter[halind]=halignenter;halncols[halind]=ncols;\
  halbuffs[halind]=halbuff;colnum=0;mkkey(halstring,halstrings,&halind);\
  }else{ fprintf(stderr,"**** Error: Fatal. Tables nested too deeply. Line %d\n",tth_num_lines);\
  TTH_EXIT(1);}
#define TTH_HAL_POP  if(tth_debug&32)fprintf(stderr,"HAL POP %d,",halind-1);\
   if(halind > 0){\
   strcpy(halstring,halstrings[halind-1]);\
   rmkey(halstrings,&halind);halbuff=halbuffs[halind];\
   halignenter=halenter[halind];ncols=halncols[halind];\
   if(tth_debug&32)fprintf(stderr,"%s\n",halstring);\
   }else{ fprintf(stderr,"**** Error: Fatal. Underflow of Table index. Line %d\n",tth_num_lines);\
    TTH_EXIT(1);}
STATIC int eqalignlog=0; /* 1 eqalign, >1 no-numbering, >100 reset at line end.*/
STATIC int colspan=1; /* colspan of table cell; was 0 default. Now 1.*/
STATIC int eqaligncell=0;
STATIC int eqalignrow=0;
STATIC int eqalog[NARMAX]; /* Storage for pushing eqalign flags */
STATIC int eqacell[NARMAX];
STATIC int eqarow[NARMAX];
STATIC int eqaind=0;
#define TTH_EQA_PUSH if(eqaind < NARMAX) {\
   eqalog[eqaind]=eqalignlog;eqacell[eqaind]=eqaligncell;\
   eqarow[eqaind]=eqalignrow;eqaind++;\
   }else{ fprintf(stderr,"**** Error: Fatal. Matrices nested too deeply. Line %d\n",tth_num_lines);\
   TTH_EXIT(1);}
#define TTH_EQA_POP if(eqaind > 0){ eqaind--;\
   eqalignlog=eqalog[eqaind];eqaligncell=eqacell[eqaind];\
   eqalignrow=eqarow[eqaind];\
   }else{ fprintf(stderr,"**** Error: Fatal. Underflow of Matrix index:%d Line %d\n",eqaind,tth_num_lines);\
    TTH_EXIT(1);}
STATIC int i,ind=0,jarg=0,jargmax=0,jscratch,js2,jshal,jstal=0, hgt=0;
STATIC int iac=0,jac=0;
STATIC int ncounters=0;
STATIC int counters[NCOUNT]={0};
STATIC char *countkeys[NCOUNT]={0};
STATIC char *countwithins[NCOUNT]={0};
STATIC int nkeys=0;
STATIC char *keys[NFNMAX]={0};
STATIC char *defs[NFNMAX]={0};
STATIC char *optargs[NFNMAX]={0};
STATIC int nargs[NFNMAX]={0};
STATIC int lkeys[NFNMAX]={0};
STATIC int ckeys[NFNMAX]={0};
STATIC int localdef=0;
STATIC int narg;
STATIC int margmax=0;
STATIC char *margkeys[NARMAX]={0};
STATIC char *margs[NARMAX]={0};
STATIC int margn[NARMAX]={0};
/* Fractions and math */
extern void tth_enclose(),tth_prefix();
STATIC int eqdepth=0;
STATIC char *eqstrs[NFNMAX];
STATIC char eqstr[4*TTH_DLEN]={0};
STATIC char eqstore[4*TTH_DLEN];
STATIC char eqlimited[TTH_DLEN]={0};
/*  STATIC int eqsubsup=0; */
STATIC int eqclose=0;
STATIC int eqhgt=0;
STATIC int mtrx[NFNMAX]={0};
STATIC int active[NFNMAX]={0};
STATIC int levhgt[NFNMAX]={0};
STATIC int tophgt[NFNMAX]={0};
STATIC char levdelim[NFNMAX][20]={{0}};
STATIC int tabwidth=150;
STATIC int qrtlen=0,qrtlen2=0;
STATIC time_t thetime;
struct tm timestruct;
STATIC char *chscratch=0;
STATIC char *chs2=0;
STATIC char *chs3=0;
STATIC char *chdef=0;
STATIC char *chopt=0;
STATIC int lopt=0;
/* Latex Sections etc*/
STATIC int chaplog=0;
STATIC int countstart=0;
#define ftntno counters[0+countstart]
#define chapno counters[1+countstart]
#define sectno counters[2+countstart]
#define subsectno counters[3+countstart]
#define subsubsectno counters[4+countstart]
#define equatno counters[5+countstart]
#define figureno counters[6+countstart]
#define tableno counters[7+countstart]
#define partno counters[8+countstart]
#define secnumdepth counters[9+countstart]
STATIC int appendix=0;
STATIC char environment[20]={0};   /* Name of environment */
STATIC char labelchar[20]={0}; /* Running label in current section. */
STATIC char envirchar[20]={0}; /* Running label in numbered environment. */
STATIC char refchar[20]={0};   /* Type of internal reference. */
STATIC char colorchar[20]={0};
STATIC char filechar[20]={0};
STATIC char filenext[20]={0}; /*sf*/
STATIC char auxflch[20]={0};
STATIC char schar[3]={0}; /*sf*/
#define TNO 400
STATIC char *tchar[TNO]={0}; /*sf*/
STATIC char *fchar[TNO]={0}; /*sf*/
STATIC int tbno=0;          /*sf*/
STATIC int fgno=0;          /*sf*/
STATIC char ftntcode[4];
STATIC int ftntwrap=0;
STATIC int displaystyle=0;
STATIC int nbuiltins=0;
 /*  STATIC int compression=0; */
STATIC int enumerate=0;
STATIC char enumtype[5]={'1','a','i','A','I'};
STATIC int eofrmv[MAX_INCLUDE_DEPTH];
STATIC int lbook=0;
STATIC int lefteq=0;
STATIC char unitlength[TTH_CHARLEN]={0};
STATIC int picno=0;
STATIC int ncols=0;
STATIC char tdalign[TTH_CHARLEN]={0};
STATIC char precell[TTH_CHARLEN]={0};
STATIC float anumber=0.,bnumber=1.,cnumber=0.;
STATIC float cyanc=0.,magentac=0.,yellowc=0.,blackc=0.;
STATIC float redc=0.,greenc=0.,bluec=0.;
STATIC int thesize=0;
STATIC int tthglue=0;
STATIC int tth_eqwidth=100;
STATIC int dimadvstate=0;
#define TTH_INDPC 5
extern int tth_group();
 /* Number of scaledpoints per screen pixel. 100 pixels per inch. */
#define SCALEDPERPIXEL (65536*72/100)
 /* Guess of the screen width in pixels larger than real is usually the best
    error to have. */
#define DEFAULTHSIZEPIX 1000
/* extern int tth_halcode(); */
STATIC int boxborder=0;
extern int tth_cmykcolor();
STATIC char xpndstring[2]={0};
STATIC int bibliogs=0;
STATIC int verbinput=0;
/* Open for reading, and test that we really can read it. */
STATIC char openscrt[2];
#define TTH_FILE_OPEN(scratchstring) \
 ( (tth_inputfile=fopen(scratchstring,"r")) ?\
  ( ( (fread(openscrt,1,1,tth_inputfile)==0) && ferror(tth_inputfile) \
       && (!fclose(tth_inputfile) || 1 ) ) ? \
       NULL : (freopen(scratchstring,"r",tth_inputfile)) )\
 : NULL )
STATIC int tth_index_face=0;
STATIC int tth_index_line=0;
STATIC int tthindexrefno=0;
STATIC int oa_removes=0;
STATIC char page_compositor[]="-";
STATIC char input_filename[TTH_CHARLEN]={0};
STATIC int minus=1;
#define TTH_UNKS_LEN 4000
STATIC char unknownstring[TTH_UNKS_LEN]={0};
STATIC char valignstring[TTH_CHARLEN]={0};
STATIC int valsec=0;
STATIC char tth_verbenviron[TTH_MAXDEPTH]={0};
 /* */

 /* Define the storable stacked integers  */
#define INTDEPTHMAX 30 /* Stack depth*/ 
#define INTMAX 10      /* Maximum integers */
#define INTERROR 99999 /* Value indicating overflow */
int PUSHEDINTS[INTMAX][INTDEPTHMAX]={{0}};
int PUSHEDINTDEPTHS[INTMAX]={0};
#define TTH_INT_SETPUSH(name,value) \
   if(PUSHEDINTDEPTHS[name]<INTDEPTHMAX) {\
     PUSHEDINTS[name][++PUSHEDINTDEPTHS[name] ]=value;\
   }else{fprintf(stderr,"INT overflow, %s\n","name");++PUSHEDINTDEPTHS[name];}
#define TTH_INT_VALUE(name) \
   (PUSHEDINTDEPTHS[name]<=INTDEPTHMAX) ? \
   PUSHEDINTS[name][PUSHEDINTDEPTHS[name] ] :\
   INTERROR
#define TTH_INT_POP(name) \
   if(PUSHEDINTDEPTHS[name]>0){\
     PUSHEDINTS[name][PUSHEDINTDEPTHS[name]--]=0;\
   }else{fprintf(stderr,"INT underflow, %s\n","name");}
 /* Here we define as macros the names of our pushed integers. */
#define EQSUBSUP 0
 /* Calls are then of the form, e.g. TTH_INT_VALUE(EQSUBSUP,10)*/


/*mathstringshl*/

 /*Macros in scanner etc. */
#ifdef TTH_GOLD
#define TTH_NAME "Hgold"
#else
#define TTH_NAME "H"
#endif

#define TTH_SYMBOLN  (tth_unicode ? "" : "<span style=\"font-family:symbol\">\n")
#define TTH_SYMBOL   (tth_unicode ? "" : "<span style=\"font-family:symbol\">")
#define TTH_SYMEND   (tth_unicode ? "" : "</span>")
#define TTH_SYMENDN  (tth_unicode ? "" : "</span\n>")
#define TTH_SYMPT(chr) (tth_unicode ? tth_symbol_point(chr) : chr)

#define TTH_DISP1 ((tth_debug < 2) ? "\n<br clear=\"all\" /><table border=\"0\" width=\"%d%%\"><tr><td>\n<table align=\"center\" cellspacing=\"0\"  cellpadding=\"2\"><tr><td nowrap=\"nowrap\" align=\"center\">\n" : "\n<br clear=\"all\" /><table border=\"1\" width=\"%d%%\"><tr><td>\n<table border=\"1\" align=\"center\"><tr><td nowrap=\"nowrap\" align=\"center\">\n" ) 
/* DISPE for equalign etc. Old version.*/
#define TTH_DISPE ((tth_debug < 2) ? "\n<br clear=\"all\" /><table border=\"0\" width=\"%d%%\"><tr><td>\n" : "\n<br clear=\"all\" /><table border=\"1\" width=\"%d%%\"><tr><td>\n" ) 
 /* New broken version 
   #define TTH_DISPE ((tth_debug < 2) ? "\n<br clear=\"all\" /><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"%d%%\">\n" : "\n<br clear=\"all\" /><table border=\"1\" width=\"%d%%\">\n" ) */

#define TTH_DISP2 "</td></tr></table>\n</td></tr></table>\n"
#define TTH_DISP3 "</td></tr></table>\n</td><td width=\"1%\">"
#define TTH_DISP4 "</td></tr></table>\n"
#define TTH_DISP5 "\n</td><td width=\"1%\">"
#define TTH_DISP6 "</td></tr></table>\n" /* Instead of DISP4*/
#define TTH_TSTY1 ((tth_debug <2) ? "<br clear=\"all\" /><table border=\"0\" align=\"left\" cellspacing=\"0\" cellpadding=\"0\"><tr><td nowrap=\"nowrap\">" : "<br clear=\"all\" /><table border=\"1\" align=\"left\"><tr><td>" )
#define TTH_TSTY2 "\n</td></tr></table><br />"
#define TTH_EQ1 ((tth_debug<2) ? "<table border=\"0\" align=\"left\" cellspacing=\"0\" cellpadding=\"0\"><tr><td nowrap=\"nowrap\" align=\"center\">\n" : "<table border=\"1\" align=\"left\"><tr><td nowrap=\"nowrap\" align=\"center\">\n")
#define TTH_EQ3 ((tth_debug<2) ? "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" :  "<table border=\"1\">" )
#define TTH_EQ2 "</table>\n"
#define TTH_EQ4 "</td></tr></table>\n"
#define TTH_EQ5 ((tth_debug<2) ? "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td nowrap=\"nowrap\" align=\"center\">\n" : "<table border=\"1\"><tr><td nowrap=\"nowrap\" align=\"center\">\n")
#define TTH_EQ6 ((tth_debug<2) ? "<tr><td width=\"50%\"></td><td nowrap=\"nowrap\" align=\"right\">\n" :  "<tr><td width=\"50%\"></td><td nowrap=\"nowrap\" align=\"right\">\n" )
#define TTH_EQ7 "\n <tr><td width=\"50%%\"></td><td nowrap=\"nowrap\" align=\"%s\" colspan=\"%d\">"
#define TTH_EQ8 "</td><td width=\"50%\"></td><td width=\"1\" align=\"right\">"
#define TTH_EQ9 "</td><td width=\"50%\">"
#define TTH_EQ10 "\n <tr><td nowrap=\"nowrap\" align=\"%s\" colspan=\"%d\">"
#define TTH_EQ11 ((tth_debug<2)?"<table><tr><td nowrap=\"nowrap\" align=\"%s\" colspan=\"%d\">":"<table border=\"1\"><tr><td nowrap=\"nowrap\" align=\"%s\" colspan=\"%d\">")
#define TTH_CELL1 ((eqclose > tth_flev) ? ((levdelim[eqclose][0]||levdelim[eqclose+1][0]) ? "" : "["): ((levdelim[eqclose][0]) ? "" :  "</td><td nowrap=\"nowrap\" align=\"center\">\n") )
#define TTH_CELL2 ((eqclose > tth_flev) ? ((levdelim[eqclose+1][0]||levdelim[eqclose][0]) ? "" : "]"): ((levdelim[eqclose+1][0]) ? "" : "</td><td nowrap=\"nowrap\" align=\"center\">\n") )
  /* CELL2 and CELL3 need to be identical apart from the test. */
#define TTH_CELL3 "</td><td nowrap=\"nowrap\" align=\"center\">\n"
#define TTH_CELL4 "</td><td align=\"right\">"
 /*#define TTH_CELL_L "</td><td align=\"left\">"*/
#define TTH_CELL_TAB (eqdepth ?"</td></tr></table></td>":"</td>")
#define TTH_CELL_L "</td><td align=\"left\" class=\"cl\">"
#define TTH_CELL_R "</td><td align=\"right\" class=\"cr\">"
#define TTH_CELL5 "</td><td nowrap=\"nowrap\">"
#define TTH_CELL_START "</td><td"
#define TTH_LEV1 ((eqclose > tth_flev) ? "(": ((tth_debug<2) ? "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td nowrap=\"nowrap\" align=\"center\">\n": "<table border=\"1\"><tr><td nowrap=\"nowrap\" align=\"center\">\n") )
#define TTH_LEV2 ((eqclose > tth_flev) ? ")": "</td></tr></table>")

#define TTH_EQA1 ((tth_debug<2) ? ((eqalignlog) ? "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><tr><td nowrap=\"nowrap\" align=\"left\">\n":"<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><tr><td nowrap=\"nowrap\" align=\"center\">\n") : ((eqalignlog) ? "<table border=\"1\"><tr><td nowrap=\"nowrap\" align=\"left\">\n":"<table border=\"1\"><tr><td nowrap=\"nowrap\" align=\"center\">\n"))
#define TTH_EQA2  "</td></tr></table>"
#define TTH_EQA3 ((eqalignlog) ? "</td><td nowrap=\"nowrap\" align=\"left\">\n" : "</td><td nowrap=\"nowrap\" align=\"center\">\n")
#define TTH_EQA4  ((eqalignlog) ? "</td><td nowrap=\"nowrap\" align=\"left\" colspan=" : "</td><td nowrap=\"nowrap\" align=\"center\" colspan=")
   /* The leading \n is vital in tth_istyle. */
#define TTH_DIV  ((eqclose > tth_flev) ? "/":(tth_istyle&1 ? "\n<div class=\"hrcomp\"><hr noshade=\"noshade\" size=\"1\"/></div>":"<hr noshade=\"noshade\" size=\"1\" />") )

#define TTH_ATOP  ((eqclose > tth_flev) ? " || ":"<br />\n" )
#define TTH_NULL_BOTTOM ((eqclose > tth_flev) ? "":"&nbsp;<br />" )
#define TTH_NOALIGN "<tr><td nowrap=\"nowrap\" colspan=6>"
#define TTH_BR "<br />"
#define TTH_BRN "<br />\n"
#define TTH_SUP1 "<sup>"
#define TTH_SUP2 "</sup>"
#define TTH_SUB1 "<sub>"
#define TTH_SUB2 "</sub>"
#define TTH_OINT     strcat(eqstr,"</td><td align=\"center\">");\
    strcat(eqstr,TTH_SYMBOL);chr1[0]=243;strcat(eqstr,TTH_SYMPT(chr1));\
    strcat(eqstr,"<br />(");chr1[0]=231;strcat(eqstr,TTH_SYMPT(chr1));\
    strcat(eqstr,")<br />");chr1[0]=245;strcat(eqstr,TTH_SYMPT(chr1));\
    strcat(eqstr,TTH_SYMEND);strcat(eqstr,"<br />");strcat(eqstr,"</td><td>");\
    if(levhgt[eqclose] == 1)levhgt[eqclose]=2;hgt=3;
 /* These ought to be a good way of closing up over/under braces etc
   but layout is too broken to give good vertical centering then
#define TTH_OBR (tth_istyle&1 ? "\n<div class=\"hrcomp\"><hr /></div>" : "<hr />")
#define TTH_OBRB (tth_istyle&1 ? "\n<div class=\"hrcomp\"><br /></div>" : "<br />")
 */
#define TTH_OBR "<hr />"
#define TTH_OBRB "<br />"
#define TTH_EM1 "<em>"
#define TTH_EM2 "</em>"
#define TTH_SMALLCAPS_FONT1 "<span style=\"font-size:x-small\">"
#define TTH_SMALLCAPS_FONT2 "</span>"
#define TTH_BOLDO "<b>"
#define TTH_BOLD1 "<b>"
#define TTH_BOLDC "</b>"
#define TTH_BOLD2 "</b>"
#define TTH_BLDITO "<b><i>"
#define TTH_BLDIT1 "<b><i>"
#define TTH_BLDITC "</i></b>"
#define TTH_BLDIT2 "</i></b>"
#define TTH_ITAL1 "<i>"
#define TTH_ITAL2 "</i>"
#define TTH_ITALO "<i>"
#define TTH_ITALC "</i>"
#define TTH_TT1 "<tt>"
#define TTH_TT2 "</tt>"
#define TTH_TTO "<tt>"
#define TTH_TTC "</tt>"
#define TTH_UNDL1 "<u>"
#define TTH_UNDL2 "</u>"
#define TTH_NORM1 (tth_istyle&1 ? "<span class=\"roman\">" : "")
#define TTH_NORM2 (tth_istyle&1 ? "</span>" : "")
#define TTH_HELV1 "<span style=\"font-family:helvetica\">"
#define TTH_HELV2 "</span>"
/* #define TTH_FONTCANCEL "</i></b></tt>" Trying a less drastic approach */
#define TTH_FONTCANCEL "</b>"
#define TTH_DAG "&#8224;"
#define TTH_DDAG "&#8225;"

#define TTH_OA1 (tth_istyle&1 ? "<div class=\"comp\">" : "")
#define TTH_OA2 (tth_istyle&1 ? "<br /></div>\n<div class=\"norm\">" : "<br />")
/* The comb bottom style is messed up by differences between NS and gecko.
   The margin bottom does not seem to matter. Even uncompressed accents
   are misaligned in Gecko. This is a font scaling problem.*/
#define TTH_OA3 (tth_istyle&1 ? "</div>\n<div class=\"comb\">&nbsp;</div>\n" : "&nbsp;<br />")
#define TTH_OA4 (tth_istyle&1 ? "\n<div class=\"comb\">&nbsp;</div>\n" :"&nbsp;<br />")
#define TTH_OA5 (tth_istyle&1 ? "\n<div class=\"norm\">" : "")
#define TTH_STYLE ((tth_debug&2) ? " <style type=\"text/css\"><!--\n\
 td div.comp { margin-top: -0.6ex; margin-bottom: -1ex; background: yellow;}\n\
 td div.comb { margin-top: -0.7ex; margin-bottom: -.6ex; background: yellow;}\n\
 td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex; background: yellow;}\n\
 td div.norm {line-height:normal; background: cyan;} \n\
 span.roman {font-family: serif; font-style: normal; font-weight: normal;} \n\
 span.overacc2 {position: relative;  left: .8em; top: -1.2ex;}\n\
 span.overacc1 {position: relative;  left: .6em; top: -1.2ex;}  --></style>\n"\
 : " <style type=\"text/css\"><!--\n\
 td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}\n\
 td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}\n\
 td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}\n\
 td div.norm {line-height:normal;}\n\
 span.roman {font-family: serif; font-style: normal; font-weight: normal;} \n\
 span.overacc2 {position: relative;  left: .8em; top: -1.2ex;}\n\
 span.overacc1 {position: relative;  left: .6em; top: -1.2ex;} --></style>\n")

#define TTH_SIZESTYLE " <style type=\"text/css\"><!--\n\
 .tiny {font-size:30%;}\n\
 .scriptsize {font-size:xx-small;}\n\
 .footnotesize {font-size:x-small;}\n\
 .smaller {font-size:smaller;}\n\
 .small {font-size:small;}\n\
 .normalsize {font-size:medium;}\n\
 .large {font-size:large;}\n\
 .larger {font-size:x-large;}\n\
 .largerstill {font-size:xx-large;}\n\
 .huge {font-size:300%;}\n\
 --></style>\n"


#define TTH_MATHS(chr) strcat(eqstr,TTH_SYMBOL);\
 strcat(eqstr,TTH_SYMPT(chr));   strcat(eqstr,TTH_SYMENDN); 
#define TTH_MATHI(icr) chr1[0]=icr;TTH_MATHS(chr1);
#define TTH_MATHC(chr) strcat(eqstr,chr);
#define TTH_COMPLEX ( (strcspn(eqstr,"&+-/") < strlen(eqstr)) || (strstr(eqstr,"\\pm") != NULL) || (strstr(eqstr,"\\mp") != NULL))
 /*
#define TTH_P_STYLE " <style type=\"text/css\"><!-- div.p { margin-top: 7pt;}--></style>\n"
 */
#define TTH_P_STYLE " <style type=\"text/css\"> div.p { margin-top: 7pt;}</style>\n"
/*  #define TTH_PAR_ACTION if(tth_htmlstyle&2){\ */
/*   TTH_OUTPUT("\n<div class=\"p\"></div>\n");}\ */
/*   else{TTH_OUTPUT("\n<p>\n");}horizmode=0; */
/* The comment is to fool tidy into thinking it's not empty*/
#define TTH_PAR_ACTION TTH_OUTPUT("\n<div class=\"p\"><!----></div>\n");horizmode=0;

#define TTH_CLEAR "<br clear=\"all\" />"
#define TTH_LIMITOP(icr) chr1[0]=icr;if(eqclose >tth_flev-1){TTH_MATHI(icr);}else{\
   oa_removes=0;\
   strcat(eqstr,TTH_CELL3);\
   strcpy(eqlimited,chr1);\
   if(levhgt[eqclose] == 1)levhgt[eqclose]=2;\
   if(bracecount){\
    fprintf(stderr,"****Internal Error! Bracecount nonzero in limitop.\n");\
    bracecount=0;}\
   yy_push_state(getsubp);}
#define TTH_OUTPUT(chr) if(eqdepth){strcat(eqstr,chr);}else{fprintf(tth_fdout,"%s",chr);}
#define TTH_OUTPUTH(chr) if(eqdepth){strcat(eqstr,chr);}else{fprintf(tth_fdout,"%s",chr);}horizmode=1;
#define TTH_CLOSEGROUP TTH_OUTPUT(closing)
#define TTH_HGT 12
#define TTH_BOXCODE "<span style=\"font-size:x-small\"><sup>[<u>&#175;</u>]</sup></span>"
#define TTH_HBAR "&#295;"
#define TTH_TEXTBOX1 ""
#define TTH_TEXTBOX2 ""
 /* Tabular variable markup */
#define TTH_TRO "\n<tr>"
#define TTH_TRC "</tr>"
#define TTH_TABC "</table>\n"
#define TTH_TABB "<table border=\"1\" class=\"tabular\">"
#define TTH_TABO "<table class=\"tabular\">"
#define TTH_TRTD "<tr><td></td></tr>"
#define TTH_MULSTART "<td colspan=\"%d\"%s>"
#define TTH_TABNOAL "\n<tr><td colspan=\"%d\">"
#define TTH_TABNOAL2 "\n</tr></td>"
#define TTH_MULSPAN "<td align=\"center\" colspan=\"%d\">"
#define TTH_TDVAR "<td%s>"
#define TTH_TABRT " align=\"right\""
#define TTH_TABLT " align=\"left\""
#define TTH_TABCT " align=\"center\""

 /* This was the old doctype. Reports are that on Windows gecko recognizes
    symbol fonts for a doctype of 40 but not 401. So keep to 40*/
#define TTH_DOCTYPE4 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n           \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html>" 
#define TTH_DOCTYPE41 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n        \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>"
#define TTH_DOCXML "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n           \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">"
#define TTH_DOCTYPE (tth_htmlstyle&2 ? TTH_DOCXML : TTH_DOCTYPE4 )
#define TTH_GENERATOR (!(tth_htmlstyle&3) ? "\n<meta name=\"GENERATOR\" content=\"Tt%s %s\">\n" : ( tth_htmlstyle&2 ? "\n<head>\n<meta name=\"GENERATOR\" content=\"Tt%s %s\" />\n" : "\n<head>\n<meta name=\"GENERATOR\" content=\"Tt%s %s\">\n") )
#define TTH_ENCODING (!tth_unicode ? (tth_htmlstyle&2 ?"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n":"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n") : "")



#define TTH_MIME_HEAD "MIME-Version: 1.0\nContent-Type: MULTIPART/MIXED; BOUNDARY=\"1293058819-1213484446-873576042\"\n\n--1293058819-1213484446-873576042\nContent-Type: TEXT/HTML; charset=iso-8859-1; name=\"index.html\"\n\n" /*sf*/
#define TTH_MIME_DIVIDE "\n--1293058819-1213484446-873576042\nContent-Type: TEXT/HTML; charset=iso-8859-1; name=\"%s\"\n\n" /*sf*/


#define TTH_DO_MACRO *(yytext+strcspn(yytext," "))=0;\
  ind=indexkey(yytext,keys,&nkeys); \
  if(horizmode) horizmode=1;\
  if(ind != -1) {\
    jargmax=nargs[ind];\
    chdef=defs[ind];\
    chopt=optargs[ind];\
    if(optargs[ind]) lopt=1; else lopt=0;\
    *dupstore=0;\
    if( jargmax == 0){\
      jarg=1;\
      if(tth_debug&8)fprintf(stderr,"Using definition %s %d= %s\n",yytext,ind,chdef);\
      TTH_PUSH_BUFF(1);\
      yy_scan_string(chdef);\
      yy_push_state(psub);\
    }else if(jargmax >0){\
      jarg=1;\
      if(tth_debug&8) fprintf(stderr,"Getting arguments of %s\n",yytext);\
      bracecount=-1;\
      if(lopt) yy_push_state(optdetect);\
      else{yy_push_state(macarg);yy_push_state(embracetok);}\
    }else{\
      if(tth_debug&8)fprintf(stderr,"Using Delimited Definition:%s\n",yytext);\
      chscratch=defs[ind-1];\
      chs2=chscratch;\
      *dupstore2=0;\
      jarg=0;\
      yy_push_state(delimint);whitespace=0;\
      horizmode=1;\
    }\
  }

#define TTH_CHECK_LENGTH  js2=0;\
 if(strlen(dupstore) > 9*TTH_DLEN/10 ){chs2=dupstore;js2=1;}\
   else if(strlen(defstore) > 9*TTH_DLEN/10 ){chs2=defstore;js2=1;}\
   else if(strlen(psubstore) > 9*TTH_DLEN/10 ){chs2=psubstore;js2=1;}\
   else if(strlen(dupstore2) > 18*TTH_DLEN/10 ){chs2=dupstore2;js2=1;}\
 if(js2){ *(chs2+200)=0;fprintf(stderr,\
        "\n**** Error: FATAL. Exceeding allowed string length. Line %d. Runaway argument?\n String starts:%s ...\n",tth_num_lines,chs2);\
     fprintf(stderr,"   Possible cause: Use of macro %d, %s\n",ind,keys[ind]);\
     TTH_EXIT(1);}

#define TTH_CCAT(chr1,chr2) if(strlen(chr1)+strlen(chr2) >= TTH_CHARLEN)\
 {fprintf(stderr,\
"**** Character overflow; catenation of %s prevented, line %d\n%s",\
chr2,tth_num_lines,\
"     Check for alternating font changes. Use grouping instead.\n\
     If necessary, increase the value of TTH_CHARLEN and recompile TtH.\n");}\
else strcat(chr1,chr2);

#define TTH_CCPY(chr1,chr2) if(strlen(chr2) >= TTH_CHARLEN)\
 {fprintf(stderr,\
"**** Character overflow; strcpy of %s prevented, line %d\n",chr2,tth_num_lines);}\
else strcpy(chr1,chr2); 

#define TTH_PRECLOSE(chr1) strcpy(preclose,closing);TTH_CCPY(closing,chr1);\
 TTH_CCAT(closing,preclose); 

 /*
#define TTH_PRETEXCLOSE(chr1) strcpy(preclose,tth_texclose[tth_push_depth]);\
 TTH_CCPY(tth_texclose[tth_push_depth],chr1);\
 TTH_CCAT(tth_texclose[tth_push_depth],preclose); 
 */
#define TTH_PRETEXCLOSE(chr1) strcpy(scratchstring,tth_texclose[tth_push_depth]);\
 TTH_CCPY(tth_texclose[tth_push_depth],chr1);\
 TTH_CCAT(tth_texclose[tth_push_depth],scratchstring);*scratchstring=0; 

#define TTH_SWAP(chr1) strcpy(swapchar,chr1);yy_push_state(swaparg);\
  yy_push_state(embracetok);
  /* Do an explicitly defined tex function of argno arguments (>0) */
#define TTH_TEX_FN(chr1,argno)  chdef=chr1;jargmax=argno;\
  jarg=1;bracecount=-1;lopt=0;\
  yy_push_state(macarg);yy_push_state(embracetok);
  /* Do an explicitly defined tex function of argno arguments (>1)
     including an optional argument. */
#define TTH_TEX_FN_OPT(chr1,argno,defaultopt)  chdef=chr1;jargmax=argno;\
  jarg=1;bracecount=-1;lopt=1;chopt=defaultopt;\
  yy_push_state(optdetect);

#define TTH_PUSH_CLOSING tth_key[tth_push_depth]=nkeys;tth_push(closing)
#define TTH_POP_CLOSING if(tth_debug&16)fprintf(stderr,"nkeys:%d,tth_key:%d\n",nkeys,tth_key[tth_push_depth-1]);\
  if(nkeys-tth_key[tth_push_depth-1])\
  tth_undefine(keys,&nkeys,tth_key[tth_push_depth-1],lkeys);tth_pop(closing);

#define TTH_HALCODE(chr1) ((*chr1=='c') ? TTH_TABCT :\
( (*chr1=='r')? TTH_TABRT :\
(  (*chr1=='p')? (\
  (strcpy(scrstring," width=\"")!=NULL &&\
  strncat(scrstring,chr1+2,strlen(chr1+2)-1)!=NULL &&\
  strcat(scrstring,"\"")!=NULL) ? scrstring: "")\
 : TTH_TABLT)))


 /*    fprintf(stderr,"%s-%s[%d%d]",precell,yytext,jshal,jstal);\
    if(jshal==1){TTH_CCAT(precell,"{");}\
 */
#define TTH_HALACT if(tth_debug&32)\
    fprintf(stderr,"+%s[%d%d]",yytext,jshal,jstal);\
  if(jshal>1){jshal--;}else{\
    if(jshal==0){sprintf(scratchstring,TTH_TDVAR,TTH_HALCODE(yytext));\
         TTH_OUTPUT(tdalign);*tdalign=0;\
	 TTH_OUTPUT(scratchstring);\
         if(eqdepth){TTH_OUTPUT(TTH_EQ5);}\
    }\
    yy_switch_to_buffer(include_stack[--tth_stack_ptr] );\
    yy_pop_state();jshal=0;\
    if(tth_debug&32){fprintf(stderr,"%s",precell);}\
    TTH_SCAN_STRING(precell);*precell=0;} 
#define TTH_HALSWITCH  {TTH_PUSH_BUFF(0);yy_switch_to_buffer(halbuff);yy_push_state(talign);}

#define TTH_TEXCLOSE if(*tth_texclose[tth_push_depth-1]){\
    if(tth_debug&8)fprintf(stderr,\
	       "Active TEXCLOSE: %s at push_depth %d, eqclose=%d\n",	\
		tth_texclose[tth_push_depth-1],tth_push_depth,eqclose); \
	yyless(0);TTH_SCAN_STRING(tth_texclose[tth_push_depth-1]);\
	*tth_texclose[tth_push_depth-1]=0;}

#define TTH_INC_LINE if(!(tth_stack_ptr||ftntwrap)){\
 if(tth_debug&32)fprintf(stderr," Line increment: numlines=%d yytext=%s",\
 tth_num_lines,yytext);tth_num_lines++;};
#define TTH_INC_MULTI chs3=yytext;while((chs3=(strstr(chs3,"\n"))?(strstr(chs3,"\n")):(strstr(chs3,"\r")))){chs3++;TTH_INC_LINE};
#define TTH_EXTRACT_COMMENT \
 if((chscratch=strstr(yytext,"%%tth:"))||(chscratch=strstr(yytext,"%%ttm:"))){\
    TTH_CCPY(scratchstring,chscratch+6);\
    chs2=yytext;\
    while((chs2=strstr(chs2,"\n"))!=NULL&&chs2<=chscratch){\
      TTH_INC_LINE;chs2++;\
    }\
    TTH_SCAN_STRING(scratchstring);\
  }else


#define TTH_TINY (((horizmode!=0) || (tth_htmlstyle&4)) ? "<span class=\"tiny\">" : "<div class=\"tiny\">")
#define TTH_SCRIPTSIZE (((horizmode!=0) || (tth_htmlstyle&4)) ? "<span class=\"scriptsize\">": "<div class=\"scriptsize\">")
#define TTH_FOOTNOTESIZE (((horizmode!=0) || (tth_htmlstyle&4)) ? "<span class=\"footnotesize\">": "<div class=\"footnotesize\">")
#define TTH_SMALL (((horizmode!=0) || (tth_htmlstyle&4)) ? "<span class=\"small\">": "<div class=\"small\">")
#define TTH_NORMALSIZE (((horizmode!=0) || (tth_htmlstyle&4)) ? "<span class=\"normalsize\">": "<div class=\"normalsize\">")
#define TTH_large (((horizmode!=0) || (tth_htmlstyle&4)) ? "<span class=\"large\">": "<div class=\"large\">")
#define TTH_Large (((horizmode!=0) || (tth_htmlstyle&4)) ? "<span class=\"larger\">": "<div class=\"larger\">")
#define TTH_LARGE (((horizmode!=0) || (tth_htmlstyle&4)) ? "<span class=\"largerstill\">": "<div class=\"largerstill\">")
#define TTH_HUGE  (((horizmode!=0) || (tth_htmlstyle&4)) ? "<span class=\"huge\">": "<div class=\"huge\">")
#define TTH_SIZEEND (((horizmode!=0) || (tth_htmlstyle&4)) ? "</span>" :"</div>")

#define TTH_SIZEGEN1 "<span style=\"font-size:"
#define TTH_SIZEGEN2 "%\">"
#define TTH_COLOR "\\special{html:<span style=\"color:#%s\">}"
#define TTH_COLOREND "</span>"
 /*start executable statements*/

tth_flev=tth_flev0;

%}
 /******************************* RULES *****************************/

\\tthlatexbuiltins  nbuiltins=nkeys;tth_debug=tth_LaTeX-1;fprintf(tth_fdout,"\n");
\\tthbuiltins nbuiltins=nkeys; bibliogs=0;

 /* Strip out formating commands. */
<notags>\\bf
<notags>\\it
<notags>\\sl
<notags>\\rm
<notags>\\textbf
<notags>\\textit
<notags>\\textsl
<notags>\\textsf
<notags>\\texttt
<notags>\\textsc
<notags>\\textnormal
<notags>\\textrm
<notags>\\emph
<notags>\\thanks\{  |
<notags>\\special\{   yy_push_state(matchbrace);
 /* external macro expansion in notags.*/
<notags>\\[a-zA-Z@]+ {
  if(tth_titlestate&1){
    TTH_DO_MACRO else{TTH_OUTPUT(yytext);}
  }else{
    TTH_OUTPUT(yytext);
  }
}
<notags>\\(\#|\%|\\|[ ])   TTH_OUTPUT(yytext+1);
<notags>\$    {
  if(tth_titlestate&2){
    tth_tagpurge=1;
    TTH_SCAN_STRING("\\tth_notageq");  
  }
}

\\begin\{notags\}  {
  if(tth_titlestate){
    yy_push_state(notags);
  }else{
    yy_push_state(verbatim);
  }
  TTH_PUSH_CLOSING;
}
\\verbatiminput { /* Defined as a latex command with optional arg */
  verbinput=1;
  TTH_TEX_FN_OPT("\\tth_verbinput #2 \\tth_endverbinput#tthdrop2",2,"");
}
\\tth_verbinput    {
  fprintf(tth_fdout,"\n<pre>"); yy_push_state(verbatim); /*begin verbatim*/
  TTH_PUSH_CLOSING;  TTH_CCPY(closing,"</pre>");
  yy_push_state(inputfile);
  yy_push_state(removespace);
}

<exptokarg,tokexp,halign>\\expandafter |
\\expandafter   TTH_TEX_FN("\\tthexpandafter#tthdrop1",1);
<psub>\\tthexpandafter#tthdrop1  {
  if(horizmode) horizmode=1;
  js2=indexkey("#1",margkeys,&margmax);
  yy_pop_state();
  strcpy(exptex,margs[js2]);
  rmdef(margkeys,margs,&margmax); 
  if(tth_debug&8)fprintf(stderr,"Expanding after %s\n",exptex);
  *expchar=0;
  yy_push_state(tokexp); /* expandafter not using embracing  */
 }
<exptokarg,tokexp>\\csname |
\\csname  yy_push_state(csname);strcpy(scratchstring," ");
<csname>.     strcat(scratchstring,yytext);
<csname>{NL} {
  fprintf(stderr,"**** Error: line end in csname. Syntax error? Line %d\n",tth_num_lines);
  TTH_SCAN_STRING("\\endcsname");
}
<csname>\\endcsname {
  yy_pop_state();
  chscratch=scratchstring+strspn(scratchstring," \t")-1;
  *chscratch='\\';
  if(tth_debug&8)fprintf(stderr,"Rescanning \\csname:%s\n",chscratch);
  TTH_SCAN_STRING(chscratch);
}
 
 /**** **********  Non-standard functions. ******************/
 /* Put any personal rules here unless there is some special reason. */
\\[bB][iI][gG]bf {
  TTH_OUTPUT(TTH_Large);TTH_PRECLOSE(TTH_SIZEEND);
  TTH_OUTPUT(TTH_BOLD1);TTH_PRECLOSE(TTH_BOLD2);
}
\\includegraphics\*?(\[[^\]]*\]){0,2} {
  TTH_INC_MULTI;
  TTH_SCAN_STRING("\\epsfbox");
}
\\e?psfig |
\\epsffile |
 /* \\epsfbox TTH_TEX_FN("\\tthpsfile#tthdrop1",1);
 This code needs to be changed to behave like \leavevmode\hbox
 in that it stacks boxes horizontally. 
 A problem is that to prevent h/vbox from breaking lines unnecessarily in HTML
 we start a new table only if we are NOT in horizmode. This is the opposite
 of TeX's behaviour. However, a \vbox ought to do it.*/
\\epsfbox {
    {
      if(tth_debug&32)fprintf(stderr,"Calling tthpsfile %s\n",yytext);
    TTH_TEX_FN("\\tthpsfile#tthdrop1",1);
  }
}
\\tthepsfbox     TTH_TEX_FN("\\tthpsfile#tthdrop1",1);
<psub>\\tthpsfile#tthdrop1  {
  /*if(horizmode)*/ horizmode=1;
  js2=indexkey("#1",margkeys,&margmax);
  TTH_CCPY(scratchstring,margs[js2]);
  yy_pop_state();
  rmdef(margkeys,margs,&margmax); 
  if(tth_debug&32)fprintf(stderr,"Figure inclusion %s\n",scratchstring);
  if((chscratch=strstr(scratchstring,"file=")) != NULL){
    chscratch=chscratch+5;
  }else  if((chscratch=strstr(scratchstring,"figure=")) != NULL){
    chscratch=chscratch+7;
  }else{
    chscratch=scratchstring;
  }
  chscratch=chscratch+strspn(chscratch,"{ ");
  *(chscratch+strcspn(chscratch,"},"))=0;        /* Terminate at } or ,*/
  tth_epsf(chscratch,tth_epsftype);
 }
 

 /* Starting State for Constructing head/body and title.*/

<titlecheck,stricttitle>\\begin\{(raw)?(html|HTML)\}    {
  fprintf(stderr,"Initial HTML output assumed to be the title.\n");
  if(tth_htmlstyle&3)strcat(tth_texclose[tth_push_depth],
		   "</head>\n<body><div>\n");
  yy_pop_state();
  yyless(0);
  }
<titlecheck,stricttitle>\\special\{{SP}*html\:[^<\}]*(<title|<TITLE) {
  fprintf(stderr,"Initial HTML output including title.\n");
  if(tth_htmlstyle&3)strcat(tth_texclose[tth_push_depth],
		   "</head>\n<body><div>\n");
  yy_pop_state();
  yyless(0);
}
<titlecheck,stricttitle>\\special\{{SP}*html\: {
  fprintf(stderr,"Initial HTML output apparently NOT the title terminates head.\n");
  if(tth_htmlstyle&3) {TTH_OUTPUT("</head>\n<body><div>\n")};
  yy_pop_state();
  yyless(0);
}

<titlecheck,stricttitle>\\title   TTH_TEX_FN_OPT("{\\headline{#2} \\centerheader{1}{{#2}}{align=\"center\"}}#tthdrop2",2,"");

\\title   {
  if(!tth_htmlstyle&1){
    TTH_TEX_FN_OPT("{\\headline{#2}    \\centerheader{1}{{#2}}{align=\"center\"}}#tthdrop2",2,"");
  }else{
    TTH_TEX_FN_OPT("{\\centerheader{1}{{#2}}{align=\"center\"}}#tthdrop2",2,"");
  }
}

<titlecheck,stricttitle>\\headline=?  { 
  yy_pop_state();
  if(tth_htmlstyle&3){
    TTH_TEX_FN("{\\special{html:\n<title>} \\begin{notags}#1\\end{verbatim} \\special{html:</title>\n</head>\n<body><div>\n}}#tthdrop1",1);
  }else{
    TTH_TEX_FN("{\\special{html:\n<title>} \\begin{notags}#1\\end{verbatim}\\special{html:</title>\n}}#tthdrop1",1);
  }  
}

\\headline=?   if(!tth_htmlstyle&1){
  TTH_TEX_FN("{\\special{html:\n<title>}\\begin{notags}#1\\end{verbatim}\\special{html:</title>\n}}#tthdrop1",1);
}else{  
  TTH_TEX_FN("#tthdrop1",1);
}

<titlecheck,stricttitle>\\par
<titlecheck,stricttitle>{NL}  TTH_INC_LINE;      /* Don't put spurious \par s at top.*/
 /* Trap some common causes of improper output in titlecheck state. */
<titlecheck,stricttitle>\\beginsection |
<titlecheck,stricttitle>\\centerline    {TTH_SCAN_STRING("\\title");}

<titlecheck,stricttitle>\\underbar{SP}* |
<titlecheck,stricttitle>\\textsc    |
<titlecheck,stricttitle>\\uppercase |
<titlecheck,stricttitle>\\chapter\*?   |
<titlecheck,stricttitle>\\part      |
<titlecheck,stricttitle>\\subsection\*?      |
<titlecheck,stricttitle>\\subsubsection\*?      |
<titlecheck,stricttitle>\\section\*? {
  sprintf(newcstr,"\\headline{#1}%s{#1}#tthdrop1",yytext);
  TTH_TEX_FN(newcstr,1);}

<titlecheck,stricttitle>\\halign({SP}*to{SP}*\\hsize)?{WSP}*\{  |
<titlecheck,stricttitle>\{[ ]*\\(bf|sl|it)  |
<titlecheck,stricttitle>\\begin\{[^d][^\}]*\}   |
<titlecheck,stricttitle>\\centerheader      |
<titlecheck,stricttitle>\\item              |
<titlecheck,stricttitle>\\end               |
<titlecheck,stricttitle>\\hbox{SP}*([ ]to)?    |
<titlecheck,stricttitle>\\[^a-zA-Z][a-zA-Z]*         |
<titlecheck,stricttitle>\$\$        	|
<titlecheck,stricttitle>\$[^$]+\$ {
  fprintf(stderr,
	"**** File starts with \"%s\". It can\'t be the HTML title.\n",
	  yytext);
  fprintf(tth_fdout,"\n<title>No Title</title>\n");
  if(tth_htmlstyle&3)fprintf(tth_fdout,"</head>\n<body><div>\n");
  yy_pop_state();
  yyless(0);
  TTH_SCAN_STRING("\\par");
}
 /* Things that can't go in the HTML head in strict mode.*/
<stricttitle>\\rm(family)?{SP}* |
<stricttitle>\\obeylines{SP}* |
<stricttitle>\\it{SP}* |
<stricttitle>\\bf{SP}* |
<stricttitle>\\small{SP}* |
<stricttitle>\\(H|h)uge{SP}* |
<stricttitle>\\large{SP}* |
<stricttitle>\\LARGE{SP}* |
<stricttitle>\\Large{SP}* {
  fprintf(stderr,
	  "**** File starts with \"%s\". It can\'t be in strict HTML heads.\n",
	  yytext);
  fprintf(tth_fdout,"\n<title>No Title</title>\n");
  if(tth_htmlstyle&3)fprintf(tth_fdout,"</head>\n<body><div>\n");
  yy_pop_state();
  yyless(0);
  TTH_SCAN_STRING("\\par");
}
 /* Make the title the first one to five plain words. */
<titlecheck,stricttitle>[^ \\\{\}\t\r\n\$%]+({SP}+[^ \\\{\}\t\r\n\$%]+){0,5}  {
  fprintf(stderr,"HTML Title constructed as:%s\n",yytext);
  fprintf(tth_fdout,"\n<title>%s</title>\n",yytext);
  if(tth_htmlstyle&3)fprintf(tth_fdout,"</head>\n<body><div>\n");
  yy_pop_state();
  yyless(0);
  TTH_SCAN_STRING("\\par");
} 
<titlecheck,stricttitle>\\pagecolor {
  fprintf(stderr,"Pagecolor in titlecheck.\n");
  if(tth_htmlstyle&3)fprintf(tth_fdout,"<title>No title</title></head>\n");
  yy_pop_state();/* titlecheck terminated */
  TTH_TEX_FN_OPT("{\\edef\\tthexpcol{\\tthpageColor{#2}}\\tthexpcol}#tthdrop2",2,"");
}

\\htmlheader {  /*tth_num_lines--;*/
  TTH_TEX_FN("{\\special{html:\n<h#1>}#2\\special{html:</h#1>}}#tthdrop2",2); }
\\centerheader   TTH_TEX_FN("{\\special{html:\n<h#1 #3>}#2 \\special{html:</h#1>}}#tthdrop3",3);/* tth_num_lines--;*/

\\special\{{SP}*html\:	 |
\\begin\{(raw)?(html|HTML)\}    {
  TTH_PUSH_CLOSING;yy_push_state(rawgroup);
 }

\\href TTH_SCAN_STRING("\\expandafter\\tthhref\\tthescape");
\\tthhref {
  TTH_TEX_FN("{\\special{html:<a href=\"#1\">}#2\\special{html:</a>}}#tthdrop2",2); 
}
  /* Get the following brace group and escape special chars, rescan */
<tokexp>\\tthescape |
\\tthescape {
  *dupstore=0;
  *argchar=0;
  storetype=5; /* Rescan one copy argchar postfixed. */
  yy_push_state(escgroup);
  bracecount=-1;
  yy_push_state(embracetok); /* Make sure we have a braced argument */
}
<tokexp>\\tthurl  |
\\tthurl {
  *dupstore=0;
  *argchar=0;
  yy_push_state(urlgroup);
  storetype=99; /* Just leave in dupgroup to be dealt with by prior state*/
  yy_push_state(uncommentgroup);
  bracecount=-1;
  yy_push_state(embracetok); /* Make sure we have a braced argument */
}

<urlgroup>.|\n {
  yyless(0);
  yy_pop_state();
  /*remove the closing brace*/
  *(dupstore+strlen(dupstore)-1)=0;
  if(strcspn(dupstore,"\\&")!=0){
  /* Even the href can't contain an ampersand literally so we need to
   translate it.*/
    strcpy(dupstore2,dupstore);
    *dupstore=0;
    i=0;
    while(*(dupstore2+i)!=0){
      if(*(dupstore2+i)=='&'){
	if(*(dupstore+strlen(dupstore)-1)=='\\')
	  *(dupstore+strlen(dupstore)-1)=0;/*Remove prior  */
	strncat(dupstore,"&amp;",5);
      }else{
	strncat(dupstore,(dupstore2+i),1);
      }
      i++;
    }
  }
  sprintf(dupstore2,
	  "\\special{html:<a href=\"%s\">}\\verb%c%s%c\\special{html:</a>}"
	  ,dupstore+1,6,dupstore+1,6);
  TTH_SCAN_STRING(dupstore2);
  *dupstore=0;
  *dupstore2=0;
 }

   /* Colordvi commands, won't work in equations. Convert to \color */
\\Magenta |
\\Cyan    |
\\Yellow  |
\\Green   |
\\Blue    |
\\Red     |
\\Black   |
\\White   {
  strcpy(scratchstring,yytext+1);
  /**scratchstring=tolower(*scratchstring);*/
  sprintf(scrstring,"\\color{%s}",scratchstring);
  TTH_SWAP(scrstring);
}
{WSP}*\\and       TTH_INC_MULTI;fprintf(tth_fdout,",");

  /************************ Comment removal ******************/
  /* Many needed so that e.g.  inside a comment does not break stuff */
<define,tokenarg,embracetok,dupgroup,dupsquare,falsetext>{CMNT} |
<innerfalse,ortext,hamper,mamper,hendline,htemplate,tempamp>{CMNT} |
<matchbrace,getdef,getnumargs,macarg,optag,exptokarg,tokexp>{CMNT}   {
  TTH_INC_LINE;
  if(strstr(yytext,"%%tth:")==yytext){TTH_SCAN_STRING(yytext+6);}
  else if(strstr(yytext,"%%ttm:")==yytext){TTH_SCAN_STRING(yytext+6);}
  else{ 
    if(tth_debug&64) fprintf(stderr,"Comment:%s",yytext);
  }
 }

{CMNT}  {
  TTH_INC_LINE;
  if(strstr(yytext,"%%tth:")==yytext){TTH_SCAN_STRING(yytext+6);}
  else if(strstr(yytext,"%%ttm:")==yytext){TTH_SCAN_STRING(yytext+6);}
  else{ 
    if(tth_debug&64) fprintf(stderr,"Comment:%s",yytext);
    if(horizmode) horizmode=-1;
    yy_push_state(parcheck);
  }
 }

 /* escgroup explicitly ignores comment removal and other special chars.*/
<escgroup>(%|#)  strcat(dupstore,"\\");strcat(dupstore,yytext); 
 /* Don't escape things already escaped*/
<escgroup>(\\%|\\#)  strcat(dupstore,yytext); 
 /*********************************************************************/
 /* Date information needs to be before conditionals. */
\\tth_today {
  time(&thetime);
  strcpy(scratchstring,ctime(&thetime));
  strcpy(scratchstring+10,", ");
  TTH_OUTPUT(scratchstring+4);
  TTH_OUTPUTH(scratchstring+20);
 }

 /* Act as if these are counters */
<getifnum>(\\month|\\year|\\day) {
  yyless(0);
  TTH_SCAN_STRING("\\number");
}

<number>\\year {
  time(&thetime);
  timestruct=*localtime(&thetime);
  timestruct.tm_year= timestruct.tm_year+1900;
  sprintf(scrstring,"%d",timestruct.tm_year);
  /* Remove space afterwards*/ 
  TTH_PUSH_BUFF(1);yy_scan_string(scrstring);
  yy_pop_state();
}
<number>\\month {
  time(&thetime);
  timestruct=*localtime(&thetime);
  sprintf(scrstring,"%d",timestruct.tm_mon+1);
  TTH_PUSH_BUFF(1);yy_scan_string(scrstring);
  yy_pop_state();
}
<number>\\day {
  time(&thetime);
  timestruct=*localtime(&thetime);
  sprintf(scrstring,"%d",timestruct.tm_mday);
  TTH_PUSH_BUFF(1);yy_scan_string(scrstring);
  yy_pop_state();
}

 /***********************************************************************/
  /* Conditionals*/
\\newif{SP}*\\if[a-zA-Z@]+ {
  strcpy(scratchstring,strstr(yytext,"\\if")+3);
  sprintf(scrstring,"\\def\\if%s{\\iffalse}\\def\\%sfalse{\\%dfalse}\\def\\%strue{\\%dtrue}",scratchstring,scratchstring,nkeys,scratchstring,nkeys);
  TTH_SCAN_STRING(scrstring);
}
\\[0-9]*false {
  sscanf(yytext+1,"%d",&js2);
  strncpy(defs[js2]+3,"false",5);
}
\\[0-9]*true {
  sscanf(yytext+1,"%d",&js2);
  strncpy(defs[js2]+3,"true ",5);
}

<hamper,mamper,hendline,xpnd,getsubp>\\iftt[hm]{TSP}* |
\\iftt[hm]{TSP}* |
<hamper,mamper,hendline,xpnd,getsubp>\\iftrue{TSP}* |
\\iftrue{TSP}*   if(tth_debug&1024)fprintf(stderr,"Starting %s.\n",yytext);

<falsetext,ortext,innerfalse>\\%
<equation>\\if[hv]mode*{TSP}  |
<falsetext,innerfalse>\\if[a-z@]* {
  yy_push_state(innerfalse);
  if(tth_debug&1024)fprintf(stderr,"Starting inner \\if in falsetext.\n");
}
\\ifmmode{TSP}*        |
<hamper,mamper,hendline,xpnd,getsubp>\\iffalse{TSP}*
\\iffalse{TSP}* {
  yy_push_state(falsetext);
  if(tth_debug&1024)fprintf(stderr,"Starting \\iffalse.\n");
}
\\ifvmode{TSP}*   if(horizmode) yy_push_state(falsetext);
\\ifhmode{TSP}*   if(!horizmode) yy_push_state(falsetext);

<hamper,mamper,hendline,xpnd,getsubp>\\fi{TSP}* |
\\fi{TSP}*   {
  if(tth_debug&1024)fprintf(stderr,"Ending true clause \\if\\fi.\n");
  if(horizmode)horizmode=1;
}
<hamper,mamper,hendline,xpnd,getsubp,embracetok,optdetect,macarg,optag>\\else{TSP}* |
\\else{TSP}* {
  if(tth_debug&1024)fprintf(stderr,"Ending true clause \\if\\else\n");
  yy_push_state(falsetext);
  if(horizmode)horizmode=1;
}
<falsetext>\\else  {
  yy_pop_state();
  if(tth_debug&1024)fprintf(stderr,"Ending false clause \\if\\else.\n");
  if(horizmode)horizmode=1;
  yy_push_state(removespace);
}
<falsetext,innerfalse>\\fi[a-zA-Z@]+   /* Don't misinterpret other commands. */
<falsetext,innerfalse>\\fi{TSP}* {
  yy_pop_state(); 
  if(tth_debug&1024)fprintf(stderr,"Ending false clause \\if\\fi.\n");
  if(horizmode)horizmode=1;
}
<falsetext,innerfalse>. 

\\or    yy_push_state(innerfalse);
<ortext>\\or   yy_pop_state(); if(tth_debug&1024)fprintf(stderr,"\\or ");
<ortext>\\if[a-z]*    yy_push_state(innerfalse); /* Ignore nested ifs */
<ortext>#tthorbreak  {
 yy_pop_state(); if(tth_debug&1024)fprintf(stderr,"#tthorbreak\n");
 TTH_SCAN_STRING(yytext);
 }
<ortext>\\else  |
<ortext>\\fi   {
  if(tth_debug&1024)fprintf(stderr,"%s ortext\n",yytext);
  TTH_SCAN_STRING("#tthorbreak");}
<ortext>.   /*fprintf(stderr,"ortext ");*/

<orbreak>#tthorbreak   {
  yy_pop_state(); if(tth_debug&1024)fprintf(stderr,"#orbreak end\n");}
<orbreak>.  {
  yyless(0); 
  yy_pop_state(); if(tth_debug&1024)fprintf(stderr,"Orbreak exit\n");}

<hamper,mamper,hendline,xpnd,getsubp>\\ifnum  |
\\ifnum                                |
<hamper,mamper,hendline,xpnd,getsubp>\\ifodd  |
\\ifodd                                |
<hamper,mamper,hendline,xpnd,getsubp>\\ifcase |
\\ifcase   {
  yy_push_state(getifnum);strcpy(strif,yytext);yy_push_state(removespace);}
<getifnum>\\the{SP}* |       /* Kludge for now.*/
<getifnum>\\number{SP}*     yy_push_state(number);jscratch=0;
<getifnum>[0-9]* TTH_CCAT(strif,yytext);
<getifnum>\\[a-zA-Z@]+              { 
  TTH_DO_MACRO
  else if( (ind=indexkey(yytext,countkeys,&ncounters)) != -1) { 
    if(tth_debug&1024)fprintf(stderr,"If Counter %d, %s\n",ind,countkeys[ind]);
    sprintf(scratchstring,"%d ",counters[ind]);
    TTH_PUSH_BUFF(1);yy_scan_string(scratchstring); /* remove spaces */
  } else {
    yyless(0);
    TTH_SCAN_STRING("#"); /*Termination Sign*/
  }
 }
<getifnum>(<|>|=)  TTH_CCAT(strif,yytext);yy_push_state(removespace);
<getifnum>{WSP}  /*Oct 2001.*/
<getifnum>. {
  yy_pop_state();
  if(*yytext != '#') {yyless(0);}
  if(tth_debug&1024)fprintf(stderr,"strif text:%s\n",strif);
  chs2=strif+strcspn(strif,"0123456789");
  if(strstr(strif,"\\ifnum")){
    chscratch=chs2+strcspn(chs2,"<>=");
    sscanf(chs2,"%d",&jscratch);
    sscanf(chscratch+1,"%d",&js2);
    switch(*chscratch){
    case '<': if(!(jscratch<js2)) yy_push_state(falsetext);break;
    case '=': if(!(jscratch==js2)) yy_push_state(falsetext);break;
    case '>': if(!(jscratch>js2)) yy_push_state(falsetext);break;
    }
  }else if(strstr(strif,"\\ifodd")){
    sscanf(chs2,"%d",&jscratch);
    if(!(jscratch & 1)) yy_push_state(falsetext);break; /* even */
  }else if(strstr(strif,"\\ifcase")){
   sscanf(chs2,"%d",&jscratch);
   yy_push_state(orbreak);
   for(js2=1;js2<=jscratch;js2++) yy_push_state(ortext);
  }
}

<hamper,mamper,hendline,xpnd,getsubp>\\if |
\\if   yy_push_state(getiftok);*strif=0;  yy_push_state(removespace);
<getiftok>\\[a-zA-Z@]+              { 
  TTH_DO_MACRO
  else{
    if(tth_debug&1024) fprintf(stderr,
      "**** Unknown or unexpandable command %s as \\if test token. Line %d\n",yytext,tth_num_lines); 
    if(strlen(strif) > 1){
      yy_pop_state();
      if(!(strlen(strif)==strlen(yytext) && strstr(strif,yytext)))
	yy_push_state(falsetext);
    }else strcat(strif,yytext);
  }
}
<getiftok>{ANY} {
  if(strcspn(yytext,"\n")==0) TTH_INC_LINE;
  if(strlen(strif)){
    yy_pop_state();
    if(!(strlen(strif)==strlen(yytext) && strstr(strif,yytext)))
      yy_push_state(falsetext);
  }else strcat(strif,yytext);
}

<hamper,mamper,hendline,xpnd,getsubp>\\ifx |
\\ifx  yy_push_state(getifx);*strif=0;  yy_push_state(removespace);
<getifx>{ANY}         |
<getifx>\\[a-zA-Z@]+              {
  if(strcspn(yytext,"\n")==0) TTH_INC_LINE;
  if(tth_debug&1024) fprintf(stderr,"\\ifx comparison argument:%s\n",yytext);
  if(strlen(strif)){ /* Terminate */
    yy_pop_state();
    js2=0;
    if(strlen(strif)>1) {
      if(strlen(yytext)>1){ /* Both apparently command strings */
	if(strlen(strif)==strlen(yytext) && strstr(strif,yytext))js2=1;
	if(((ind=indexkey(yytext,keys,&nkeys))!=-1) ==
	   ((i=indexkey(strif,keys,&nkeys))!=-1)){
	  if((tth_debug&1024)&&(i>=0))
	    fprintf(stderr,"Comparing:%d:%d:%s:%s:\n",i,ind,defs[i],defs[ind]);
	  if(i==ind)js2=1; else if(strstr(defs[i],defs[ind])==defs[i]) js2=1;
	}else if((ind=indexkey(yytext,countkeys,&ncounters))!=-1)/*counters*/
	  if(ind == indexkey(strif,countkeys,&ncounters))js2=1;
      }
    }else if(strlen(yytext)==1){ /* Both single characters */
      if(*strif==*yytext) js2=1;
    }
    if(!js2){ 
      if(tth_debug&1024) fprintf(stderr,"ifx FALSE\n");
      yy_push_state(falsetext);
    }else if(tth_debug&1024) fprintf(stderr,"ifx TRUE\n");
  }
  if(strlen(yytext) > 1)yy_push_state(removespace);
  strcpy(strif,yytext);
}
 /********************************************************************/
 /* Equation Code */
 /*equationhl*/
<equation>\\lefteqn { 
  if(!eqalignrow) mkkey(eqstr,eqstrs,&eqdepth);       /* Start new row */ 
  if(tth_istyle&1)eqalignrow=eqalignrow+6*(levhgt[eqclose]-1)+TTH_HGT;else
    eqalignrow=eqalignrow+levhgt[eqclose];
  levhgt[eqclose]=1; /* new */ 
  TTH_TEX_FN("{#1}\\tth_lefteq#tthdrop1",1);
}

<equation>\\stackrel   {
  TTH_TEX_FN("{\\buildrel{#1}\\over{#2}}#tthdrop2",2);
}

<equation>{NL}  TTH_CHECK_LENGTH;  TTH_INC_LINE;
 
<equation>\\cr(cr)?{WSP}*\}  {
  TTH_INC_MULTI;
  if(*halstring){ /* halign and tabular */
    TTH_SCAN_STRING("\\tth_halcr}");
  }else{
    unput('}');
  }
} /* see also at \begin{array} = \matrix */

 /* Version that uses tabular code: */
<equation>\\end\{array\}  TTH_SCAN_STRING("\\end{tabular}");

<equation>\\end\{eqnarray\*?\} {
  if(tth_debug&2)fprintf(stderr,"end eqnarray, eqdepth=%d, eqclose=%d, tth_multinum=%d, eqalignlog=%d.\n",eqdepth,eqclose,tth_multinum,eqalignlog);
  TTH_SCAN_STRING("}}\\tth_endeqnarray"); 
}
<equation>\\nonumber  if(eqalignlog <= 100) eqalignlog=eqalignlog+100;
 /* Font faces and styles etc.*/
<equation,tokexp,exptokarg>\\mathrm  TTH_SWAP("\\rm ");
<equation,exptokarg>\\boldsymbol |
<equation,tokexp,exptokarg>\\mathbf  TTH_SWAP("\\bf ");
<equation,tokexp,exptokarg>\\mathit   TTH_SWAP("\\it ");
<equation,tokexp,exptokarg>\\mathcal  TTH_SWAP("\\it ");
<equation,tokexp,exptokarg>\\mathtt   TTH_SWAP("\\tt ");
<equation,tokexp,exptokarg>\\mathsf   TTH_SWAP("\\sffamily ");
<equation>\\mit{SP}*
<equation>\\ifmmode{WSP}* TTH_INC_MULTI; 
<equation>\\iff TTH_MATHI(219);


<equation>&   {
 /* halign */
  /*if(*halstring) {TTH_SCAN_STRING("}\\tth_mhamper{");*/
  if(*halstring) {TTH_SCAN_STRING("\\tth_mhamper");
  }else{ yy_push_state(mamper);
  }
 }
<equation>\\tth_mhamper   yy_push_state(hamper);

 /* hamper for halign */
<mamper>{WSP}  TTH_INC_MULTI;  
<mamper>{ANY}  {  
  yyless(0);yy_pop_state();
  tth_enclose(TTH_EQA1,eqstr,TTH_EQA2,eqstore);
  if(eqaligncell && !tth_LaTeX && eqalignlog){ 
    /* This ends the second cell of eqaligno. */
    strcat(eqstr,TTH_CELL_R);
  } else strcat(eqstr,TTH_EQA3);
  if(eqaligncell) {
    tth_prefix(eqstrs[eqdepth-1],eqstr,eqstore);
    rmkey(eqstrs,&eqdepth);
  }
  mkkey(eqstr,eqstrs,&eqdepth);
  *eqstr=0;
  eqaligncell++;
}

<equation,mamper>\\multispan   TTH_TEX_FN("\\tthemultispan{#1}#tthdrop1",1);
<equation,mamper>\\multicolumn   TTH_TEX_FN("\\tthemultispan{#1}#tthdrop2",2);
  /*  interior in array */
<mamper>\\tthemultispan\{[0-9]+\} {
  yy_pop_state();  
  chscratch=strstr(yytext,"multi");
  TTH_CCPY(argchar,chscratch+strcspn(chscratch,"{")+1);
  *(argchar+strcspn(argchar,"}"))=0;
  tth_enclose(TTH_EQA1,eqstr,TTH_EQA2,eqstore);
  sprintf(eqstr+strlen(eqstr),"%s\"%s\"%s\n",TTH_EQA4,argchar,">");
  if(eqaligncell) {
    tth_prefix(eqstrs[eqdepth-1],eqstr,eqstore);
    rmkey(eqstrs,&eqdepth);
  }
  mkkey(eqstr,eqstrs,&eqdepth);
  *eqstr=0;
  eqaligncell++;
 }
<equation>\\tthemultispan\{[0-9]+\} { /* line start in array */
  chscratch=strstr(yytext,"multi");
  TTH_CCPY(argchar,chscratch+strcspn(chscratch,"{")+1);
  *(argchar+strcspn(argchar,"}"))=0;
  sscanf(argchar,"%d",&colspan);
 }
<mamper>\\[a-zA-Z@]+   { /* expand first */
  TTH_DO_MACRO
  else{
    yyless(0);yy_pop_state();
    tth_enclose(TTH_EQA1,eqstr,TTH_EQA2,eqstore);
    if(eqaligncell && !tth_LaTeX && eqalignlog){ 
      /* This ends the second cell of eqaligno. */
      strcat(eqstr,TTH_CELL_R);
    } else strcat(eqstr,TTH_EQA3);
    if(eqaligncell) {
      tth_prefix(eqstrs[eqdepth-1],eqstr,eqstore);
      rmkey(eqstrs,&eqdepth);
    }
    mkkey(eqstr,eqstrs,&eqdepth);
    *eqstr=0;
    eqaligncell++;
  }
}

<equation>\\noalign  { 
  if(tth_debug&33) fprintf(stderr,"noalign in equation:\n");
  if(!eqalignrow) mkkey(eqstr,eqstrs,&eqdepth);
  if(tth_istyle&1)eqalignrow=eqalignrow+6*(levhgt[eqclose]-1)+TTH_HGT;else
    eqalignrow=eqalignrow+levhgt[eqclose];
  levhgt[eqclose]=1;
  strcpy(eqstr,TTH_NOALIGN);
  TTH_TEX_FN("{#1}\\special{html:</td></tr>}\\tth_eqfin#tthdrop1",1);
  }
<equation>\\\\\*?{SP}*(\[[^\]]*\])? | /* Was later. */
<equation>\\tth_cr |
<equation>\\cr(cr)? {  
  if(eqclose && (active[eqclose-1] || mtrx[eqclose-1])){ 
    /* If this is really an array-type environment. */
    if(tth_debug&16)fprintf(stderr,
	"Active tth_cr. yytext=%s eqclose=%d, active=%d\n",
			    yytext,eqclose,active[eqclose-1]);
    if(strstr(yytext,"tth_")){ /* Prefix special opening */
      sprintf(scrstring,TTH_EQ11,
	      (lefteq ? "left":(eqalignlog ?"right":"center")),colspan);
	      /*(colspan? colspan : 1)); Avoid colspan=0; not now necc.*/
      tth_enclose(scrstring,eqstr,TTH_EQA2,eqstore);
    }else{
      /* Next line ensures \cr is equivalent to \nonumber\\ */
      if(strstr(yytext,"\\cr"))if(eqalignlog <= 100) eqalignlog=eqalignlog+100;
      tth_enclose(TTH_EQA1,eqstr,TTH_EQA2,eqstore);  
    }
    if(tth_debug&16)fprintf(stderr,
   "TTH_CR, eqalignlog=%d, colspan=%d, envirchar=%s, tth_multinum=%d, tth_LaTeX=%d.\n",
	   eqalignlog,colspan,envirchar,tth_multinum,tth_LaTeX);
    if(eqaligncell){ /* If there is a preceding & (cell) prefix it. */
      tth_prefix(eqstrs[eqdepth-1],eqstr,eqstore);
      rmkey(eqstrs,&eqdepth);
    }
    /* If this row is an eqalign or is not the first.*/
    if((eqalignlog&&(eqalignlog-100))||eqalignrow){
      sprintf(eqchar,((eqalignlog&&(eqalignlog-100))?TTH_EQ7:TTH_EQ10),
	      (lefteq ? "left":((eqalignlog&&(eqalignlog-100)) ?
				"right":"center")),colspan);
      tth_prefix(eqchar,eqstr,eqstore); /* Prefix its opening */
      *eqchar=0;
    }
    if(eqalignrow){                     /* If this row is not the first.*/
      tth_prefix(eqstrs[eqdepth-1],eqstr,eqstore); /* Prefix previous row */
      rmkey(eqstrs,&eqdepth);
    }
    if(tth_LaTeX && tth_multinum && strlen(envirchar) && (eqalignlog==1) ){
      strcat(eqstr,TTH_EQ8);
      strcpy(scratchstring,"(\\theequation)");
    }else{
      if((eqalignlog>1)&&(eqalignlog-100)) strcat(eqstr,TTH_EQ9);
      *scratchstring=0;
    }
    strcat(scratchstring,"\\tth_closerow");
    TTH_SCAN_STRING(scratchstring);
    /*mtrx[eqclose-1]=0; A mistake. Should be done only at end.*/
  }else if(*halstring){ /* halign and tabular */
    TTH_SCAN_STRING("\\tth_halcr");
  }else{
    fprintf(stderr,"**** Improper \\\\ or \\cr outside array environment ignored, Line %d.\n",tth_num_lines);
  }
}

<equation>\\tth_closerow {
  if(tth_LaTeX && tth_multinum && strlen(envirchar) && (eqalignlog==1) ){
    equatno++;sprintf(envirchar,"%d",equatno);tth_multinum++;
  }
  strcat(eqstr,"</td></tr>"); /* Close the row */
  *eqchar=0;
  mkkey(eqstr,eqstrs,&eqdepth);     /* Start new row */
  *eqstr=0;
  /* eqalignrow++; old */
  if(tth_istyle&1)eqalignrow=eqalignrow+6*(levhgt[eqclose]-1)+TTH_HGT;else
    eqalignrow=eqalignrow+levhgt[eqclose];
  levhgt[eqclose]=1; /* new */
  eqaligncell=0;
  lefteq=0;
  colspan=1;
  if(eqalignlog >= 100) eqalignlog=eqalignlog-100;
}

<equation,textbox>\{ {
  if(tth_debug&16) {
    fprintf(stderr,"Start Group {, eqdepth=%d, eqclose=%d, tth_flev=%d, levdelim=%s\n",eqdepth,eqclose,tth_flev,levdelim[eqclose]);
  }
  if(tth_flev < 0) tth_flev=tth_flev-99;
   mkkey(eqstr,eqstrs,&eqdepth);
   *eqstr=0;
   eqclose++;
   tophgt[eqclose]=0;
   levhgt[eqclose]=1;
   TTH_PUSH_CLOSING;
 }

<getsubp>\} {
  if(mtrx[eqclose-1] || active[eqclose-1] || tophgt[eqclose]){
    /* Terminate getsubp state */
    yyless(0);
    TTH_SCAN_STRING("#");
  }else{
  /* Just enter the brace termination code. */
    TTH_SCAN_STRING("\\tth_closebrace");
  }
}
<getsubp>\\tth_closebrace |
<equation,textbox>\} { 
  TTH_TEXCLOSE else{
  do{
  if(tth_debug&16) {
    if(active[eqclose]) {
    fprintf(stderr,
         "Active Group }, eqdepth=%d, eqclose=%d, tth_flev=%d, levdelim=%s, active=%d\n"
	    ,eqdepth,eqclose,tth_flev,levdelim[eqclose],active[eqclose]);}
    else {fprintf(stderr,
	      "Close Group }, eqdepth=%d, eqclose=%d, tth_flev=%d, levdelim=%s\n"
	       ,eqdepth,eqclose,tth_flev,levdelim[eqclose]);}
  }
  if(tophgt[eqclose] != 0){ /* If fraction */
    if(tth_debug&16)fprintf(stderr,"Fraction closing.\n");
    if(levhgt[eqclose] > 1 || (eqclose > tth_flev && TTH_COMPLEX)){ 
      /* If bottom contains a fraction or we are topped out. */
      /* Try bottom compression*/
      oa_removes=b_align(eqstr,tth_debug);
      tth_enclose(TTH_LEV1,eqstr,TTH_LEV2,eqstore);
    }else{ /* Put br at end if we are still closing a real cell */
      if((eqclose <= tth_flev) && (active[eqclose-1]!=30)) strcat(eqstr,TTH_BR);
    }
    tth_prefix(eqstrs[eqdepth-1],eqstr,eqstore);
    rmkey(eqstrs,&eqdepth);
    TTH_CLOSEGROUP;TTH_POP_CLOSING; /* put closing before cell end */
    if(active[eqclose-1]!=30){ 
      /* CELL1/2 test for non-zero levdelim 0,+1 */
      tth_enclose(TTH_CELL1,eqstr,TTH_CELL2,eqstore); 
      if(eqclose <= tth_flev) yy_push_state(getsubp); 
      if(tth_debug&16) fprintf(stderr,"Whole fraction:%s\n",eqstr);
    }
  }else {
    TTH_CLOSEGROUP;TTH_POP_CLOSING;
  }
  if(eqclose > tth_flev) hgt=1; else hgt=tophgt[eqclose]+levhgt[eqclose];
  if(tth_debug&16) fprintf(stderr,"eqclose=%d,tth_flev=%d,hgt=%d,%d,%d\n",
	  eqclose,tth_flev,hgt,tophgt[eqclose],levhgt[eqclose]);
  if(levhgt[eqclose-1] < hgt) levhgt[eqclose-1]=hgt;
  if(tth_debug&2 && (levdelim[eqclose][0]||levdelim[eqclose+1][0]))
    fprintf(stderr,"Delimiting:%s%d%s\n",
	    levdelim[eqclose],hgt,levdelim[eqclose+1]);
  if(levdelim[eqclose][0]){
    delimit(levdelim[eqclose],hgt,eqchar);
  }
  if(levdelim[eqclose+1][0]){
    delimit(levdelim[eqclose+1],hgt,eqchar2);
  }
  /* Cut spurious cells off end of eqchar and eqstr if necessary*/
  chscratch=eqchar+strlen(eqchar)-strlen(TTH_CELL3);
  if( (strstr(chscratch,TTH_CELL3)==chscratch) &&
      (strstr(eqstr,TTH_CELL_START)==eqstr+strspn(eqstr," \n"))){ 
    *chscratch=0;
  }
  chscratch=eqstr+strlen(eqstr)-strlen(TTH_CELL3);
  if( (strstr(eqchar2,TTH_CELL_START)==eqchar2+strspn(eqchar2," \n")) &&
      (strstr(chscratch,TTH_CELL3)==chscratch) ){
    *chscratch=0;
  } /* Section could be combined with delimit immediately above. */
  /* rely on no delimiters on active closures. False for matrix. */
  if(levdelim[eqclose+1][0] && (hgt > 1)) yy_push_state(getsubp);
  *levdelim[eqclose]=0;
  *levdelim[eqclose+1]=0;

  tth_enclose(eqchar,eqstr,eqchar2,eqstore);
  *eqchar=0;
  *eqchar2=0;
  if(active[eqclose-1]==30){ /* eqlimited section for mathop, overbrace */
    if(tth_debug&2)fprintf(stderr,"Mathop eqlimited:%s\n",eqstr);
    if(strlen(eqlimited)+strlen(eqstr)< TTH_DLEN) {
      strcat(eqlimited,eqstr);
      if(tth_debug&2)fprintf(stderr,"EQlimited=||%s||\n",eqlimited);
    }else{
      fprintf(stderr,
          "Error: Fatal! Exceeded eqlimited storage. Over/underbrace too long.\n");
      TTH_EXIT(5);
    }
    strcpy(eqstr,eqstrs[eqdepth-1]);
    yy_push_state(getsubp);
    if(levhgt[eqclose] == 1)levhgt[eqclose]=2; /* Force fraction closure */
    active[eqclose-1]=0;
  }else{
    tth_prefix(eqstrs[eqdepth-1],eqstr,eqstore);
  }
  rmkey(eqstrs,&eqdepth);
  if(tth_flev <  0) tth_flev=tth_flev+99;
  active[eqclose]=0;
  mtrx[eqclose]=0;
  eqclose--;
  if(eqclose < 0) {
    fprintf(stderr,"**** Error! Fatal! Negative closure count, line:%d\n",tth_num_lines);
    TTH_EXIT(4);
  }
  } while (active[eqclose]);
  if(tth_debug&16) fprintf(stderr,
   "Completing Close Group, eqdepth=%d, eqclose=%d, tth_flev=%d, levdelim=%s\n"
	    ,eqdepth,eqclose,tth_flev,levdelim[eqclose]);
  }
}

<equation>\$\$ {  /* Cope with ambiguous style at equation end */
  if(displaystyle){
    if(tth_debug&2)fprintf(stderr,"$$ in displaystyle\n");
    TTH_SCAN_STRING("}\\tth_endequation");
  }else{
    yyless(1);
    TTH_SCAN_STRING("}\\tth_endinline");
  }
 }

<equation>\\tth_endinline {
  TTH_TEXCLOSE else{
    if(tth_debug&2) fprintf(stderr,"Leaving inline eq, eqclose=%d, eqdepth=%d, tth_flev=%d, levhgt=%d, tophgt=%d\n",  
	      eqclose,eqdepth,tth_flev,levhgt[eqclose],tophgt[eqclose]);
    TTH_CLOSEGROUP;TTH_POP_CLOSING;
    if(tth_inlinefrac && (levhgt[eqclose]+tophgt[eqclose]>1))
      tth_enclose(TTH_TSTY1,eqstr,TTH_TSTY2,eqstore);
    if(eqdepth==1){
      rmkey(eqstrs,&eqdepth); /*eqdepth--;*/
      tth_flev=tth_flev0;
      horizmode=1;
      if(tth_tagpurge){
	tagpurge(eqstr);
	tth_tagpurge=0;
      }
      fprintf(tth_fdout,"%s",eqstr);*eqstr=0;
    }else{
      if(displaystyle)displaystyle--;
      eqdepth--;
      if(tth_debug&2)fprintf(stderr,
			     "Equation in a textbox inside an equation.\n");
      TTH_OUTPUT(TTH_TEXTBOX1);
    }
    yy_pop_state();
  }
}
 /* Force all equations to end enclosed. */
<equation>\\end\{equation\*?\} { 
  if(strstr(yytext,"*")==NULL){    /* end{equation} */
    if(tth_multinum < 2) { 
      TTH_SCAN_STRING("}\\tth_numbereq");
    }else {
      /* end of equation which needs to unincrement*/
      equatno--;
      TTH_SCAN_STRING("}\\tth_endequation");
    }
  }else {TTH_SCAN_STRING("}\\tth_endequation");} /* embracing essential */
}
<equation>\\end\{displaymath\} |
<equation>\\\]     TTH_SCAN_STRING("}\\tth_endequation");

<equation>\\tth_numbereq {
      strcat(eqstr,TTH_DISP3);
      TTH_SCAN_STRING("(\\theequation)\\tth_endnumbered");
}
<equation>\\tth_endeqnarray  equatno--;TTH_SCAN_STRING("\\tth_endequation");
<equation>\\tth_endequation |     
<equation>\\tth_endnumbered {
  TTH_TEXCLOSE else{
  eqaligncell=0;
  if(tth_debug&2) fprintf(stderr,
	 "End equation %d, %s. eqalignlog=%d, tth_eqwidth=%d\n",
		equatno,yytext,eqalignlog,tth_eqwidth);
  if(tth_multinum)tth_multinum=1;
  {
    if(eqalignlog){
      sprintf(scrstring,TTH_DISPE,tth_eqwidth);
      tth_enclose(scrstring,eqstr,TTH_DISP6,eqstore);
/*        tth_enclose(scrstring,eqstr,TTH_DISP4,eqstore); */
    }else{
      sprintf(scrstring,TTH_DISP1,tth_eqwidth);
      if(strstr(yytext,"numb")){
	tth_enclose(scrstring,eqstr,TTH_DISP4,eqstore);
      }else{
	tth_enclose(scrstring,eqstr,TTH_DISP2,eqstore);
      }
    }
    if(tth_debug&2) fprintf(stderr,
       "Leaving display eq, eqclose=%d, eqdepth=%d, tth_flev=%d\n",  
         eqclose,eqdepth,tth_flev);
    if(eqdepth==1){
      rmkey(eqstrs,&eqdepth);/*eqdepth--;*/
    }else{
      fprintf(stderr,
   "**** Error: Fatal Abnormal eqdepth %d on display equation exit, line %d\n",
	      eqdepth,tth_num_lines);TTH_EXIT(2);
    }
    if(eqclose > 0) { 
      fprintf(stderr,
    "**** Error: Fatal Abnormal eqclose %d on Display Equation End, line %d\n",
	      eqclose,tth_num_lines);TTH_EXIT(3);
    }
    yy_pop_state();
    tth_flev=tth_flev0; /* Necessary if textstyle has been used. */
    horizmode=1; /* Make sure we now recognize \n\n */
    displaystyle=0;
    *environment=0;
    eqalignlog=0;
    TTH_CLOSEGROUP;TTH_POP_CLOSING;
    fprintf(tth_fdout,"%s\n",eqstr);*eqstr=0;
  }
  }
}
 /* Single character fractions .*/
<equation>[\$\{]{WSP}*[0-9a-zA-Z]{WSP}*\\over{WSP}*[0-9a-zA-Z]{WSP}*[\$\}] {
  if(active[eqclose]){ /* reembrace to protect active closure */
    TTH_INC_MULTI; 
    sprintf(scratchstring,"{%s}",yytext);
    TTH_SCAN_STRING(scratchstring);
  }else  if((eqclose > tth_flev || !displaystyle)){
    TTH_INC_MULTI; 
    chscratch=yytext+strspn(yytext,"${ \t\n");
    chs2=strstr(chscratch,"\\over")+5;
    sprintf(scratchstring,"<sup>%c</sup>/<sub>%c</sub>",
	    *(chscratch),*(chs2+strspn(chs2," \t\r\n")));
    TTH_OUTPUT(scratchstring);
  }else{ /* split to prevent treatment */
    strcpy(scratchstring,yytext);
    jscratch=strspn(yytext,"${ \t");
    yyless(jscratch);
    *(scratchstring+jscratch)=0;
    TTH_SCAN_STRING(scratchstring);
  }
 }

<equation>{WSP}+\\(over|above|atop|choose) {
  TTH_INC_MULTI; 
  yyless(strspn(yytext," \t\r\n"));
}
<equation>\\(over|above|atop|choose){WSP}* {
  TTH_INC_MULTI; 
  if(tth_debug&16)fprintf(stderr,
	  "Over Close Group, depth=%d, eqclose=%d, levhgt=%d\n",
	  eqdepth,eqclose,levhgt[eqclose]);
  if(levhgt[eqclose] > 1 || (eqclose > tth_flev && TTH_COMPLEX)) {
    /* Remove unnecessary cell and bottoms from single cells*/
    oa_removes=b_align(eqstr,tth_debug);
    tth_enclose(TTH_LEV1,eqstr,TTH_LEV2,eqstore);
  }else { /* Fix a strange alignment problem. Removed 15 Oct 2003
    if((tth_istyle&1) && !strstr(yytext,"atop") && !strstr(yytext,"choose"))
      tth_prefix("&nbsp;",eqstr,eqstore); */
  }
  if(strstr(yytext,"atop") || strstr(yytext,"choose"))
     strcat(eqstr,TTH_ATOP);
  else strcat(eqstr,TTH_DIV);
  mkkey(eqstr,eqstrs,&eqdepth);
  *eqstr=0;
  tophgt[eqclose]=levhgt[eqclose]+1;
  levhgt[eqclose]=1; 
  if(strstr(yytext,"choose")){
    strcat(levdelim[eqclose],"(");
    tth_push_depth--;
    TTH_PRETEXCLOSE("\\tth_chooseclose");
    tth_push_depth++;
  }
 } 
<equation,getsubp>\\tth_chooseclose  strcpy(levdelim[eqclose+1],")");
     /*TTH_SCAN_STRING("\\right)"); doesn't work. Imbalances closures.*/

 /* End of Fraction*/

 /* Sub/p scripts. */
 /* Dont make prime a superscript, it becomes too small.
   This case will not be used if we are doing a full cell (getsubsup). */
<equation>\^\\prime{SP}*	TTH_MATHI(162); 
<equation>\^		{
  strcat(eqstr,TTH_SUP1);yy_push_state(exptokarg);
  TTH_CCPY(expchar,TTH_SUP2);
  }
<equation>\_		{
  strcat(eqstr,TTH_SUB1);yy_push_state(exptokarg);
  TTH_CCPY(expchar,TTH_SUB2);
  }
 /* Version that uses tabular:*/
<equation>\\begin{WSP}*\{array\}(\[.\])? {
  TTH_INC_MULTI; 
  TTH_SCAN_STRING("\\begin{tabular}");
}
<equation>\\eqalign(no)*{WSP}*\{	|
<equation>\\(border)?matrix{WSP}*\{ { /*border not really supported*/
  TTH_INC_MULTI; 
  TTH_HAL_PUSH;*halstring=0;
  if(strstr(yytext,"eq") != NULL) eqalignlog++;/*make both levels 1*/
  TTH_EQA_PUSH;
  /*This instead of the previous makes level 1 only. Intended for lone
   \eqno, but breaks the standard layout. So don't do it.*/
  /*  if(strstr(yytext,"eq") != NULL) eqalignlog++;*/
  TTH_PUSH_CLOSING;
  if(strstr(yytext,"eq") == NULL) eqalignlog=0;
  /*if(strstr(yytext,"eq") != NULL) eqalignlog++; else eqalignlog=0;*/
  if(tth_debug&2) {
    fprintf(stderr,
     "Matrix {, eqdepth=%d, eqclose=%d, eqalignlog=%d, tth_flev=%d, levdelim=%s.\n"
	    ,eqdepth,eqclose,eqalignlog,tth_flev,levdelim[eqclose]);
  }
  mkkey(eqstr,eqstrs,&eqdepth);
  eqclose++;
  *eqstr=0;
  levhgt[eqclose]=1;
  tophgt[eqclose]=0;
  eqaligncell=0;
  eqalignrow=0;
  tth_push_depth--;
  TTH_PRETEXCLOSE("\\tth_cr\\tth_matrixclose");
  tth_push_depth++;
  mtrx[eqclose-1]=1;
  if(tth_debug&16)fprintf(stderr,"Set Matrix: eqclose=%d,eqdepth=%d\n",eqclose,eqdepth);/**/
 }
<equation>\\tth_matrixclose {
  if(tth_debug&16) fprintf(stderr,"Matrix close %d, levhgt=%d, rows=%d\n",
			   eqclose,levhgt[eqclose],eqalignrow);
  if(tth_istyle&1) levhgt[eqclose]=(eqalignrow+6*(levhgt[eqclose]-1)+TTH_HGT)/6; else       levhgt[eqclose]=levhgt[eqclose]+eqalignrow;
  tth_prefix(eqstrs[eqdepth-1],eqstr,eqstore);
  rmkey(eqstrs,&eqdepth);
  if(eqalignlog){
    /* For 50% but just first line */
    tth_enclose(TTH_EQ3,eqstr,TTH_EQ2,eqstore);
  }else{
    tth_enclose(TTH_EQ1,eqstr,TTH_EQ2,eqstore);
  }
  TTH_EQA_POP;
  TTH_HAL_POP;
  /* Enclose unless this is the end of an eqalign type construct. */
  if(eqaind || !eqalignlog)tth_enclose(TTH_CELL5,eqstr,TTH_CELL5,eqstore);
  active[eqclose-1]=0;
}

<equation>\\cases  {
  TTH_TEX_FN("\\mbox{\\left\\lbrace\\matrix{#1}\\right.}#tthdrop1",1);
}
<equation>\\pmatrix {
  TTH_TEX_FN("\\left(\\matrix{#1}\\right)#tthdrop1",1);
}

 /*  textboxes. Because of problems as subscript, removed this to builtins. 
     <equation,exptokarg>\\textrm    |
     but this does not generally seem to be a good plan.
     But the approach below breaks with unenclosed subscript texts.
 */
<equation,exptokarg>\\raisebox\{[^\}]*\}({SP}?\[[^\]]*\]){0,2}{SP}* |
<equation,exptokarg>\\[hvmf]box{WSP}* |
<equation,exptokarg>\\textrm    |
<equation,exptokarg>\\textmd    |
<equation,exptokarg>\\textnormal {
  TTH_INC_MULTI;
  strcpy(scratchstring,"\\tth_tbone");strcat(scratchstring,"\\rm ");  TTH_SCAN_STRING("\\tth_tbox");
}
<equation,exptokarg>\\textbf  {
  strcpy(scratchstring,"\\tth_tbone");strcat(scratchstring,"\\bf ");  TTH_SCAN_STRING("\\tth_tbox");
}
<equation,exptokarg>\\textsl |
<equation,exptokarg>\\textit {
  strcpy(scratchstring,"\\tth_tbone");strcat(scratchstring,"\\it ");  TTH_SCAN_STRING("\\tth_tbox");
}
<equation,exptokarg>\\texttt {
  strcpy(scratchstring,"\\tth_tbone");strcat(scratchstring,"\\tt ");  TTH_SCAN_STRING("\\tth_tbox");
}
<equation,exptokarg>\\textsf {
  strcpy(scratchstring,"\\tth_tbone");strcat(scratchstring,"\\sffamily ");  TTH_SCAN_STRING("\\tth_tbox");
}
<equation,exptokarg>\\textsc {
  strcpy(scratchstring,"\\tth_tbone");strcat(scratchstring,"\\scshape ");  TTH_SCAN_STRING("\\tth_tbox");
}
<equation>\\tth_tbox {
  if(tth_debug&2)fprintf(stderr,
    "Start textbox. eqclose %d. push_depth %d. Line %d\n"
			 ,eqclose,tth_push_depth,tth_num_lines);
  if(!displaystyle) yy_push_state(textbox);  
  TTH_SWAP(scratchstring);
  /* This had to be moved into tth_tbone */
  /*TTH_PRETEXCLOSE("\\tth_boxclose");*/
}
<exptokarg>\\tth_tbox {
  if(tth_debug&2)fprintf(stderr,
      "Start textbox exptokarg. Displaystyle %d. eqclose %d, push_depth %d, Line %d\n"
			 ,displaystyle,eqclose,tth_push_depth,tth_num_lines);
  yy_pop_state(); 
  if(!displaystyle)yy_push_state(textbox);
  yy_push_state(exptokarg); 
  TTH_SWAP(scratchstring);
}
<equation,textbox>\\tth_boxclose  { /* box closure*/
    if(tth_debug&2) fprintf(stderr,"Box closure, eqclose=%d\n",eqclose);
    if(!displaystyle) yy_pop_state(); /* textbox state end */
  }
<equation,textbox>\\tth_tbone  {
  if(tth_debug&8)fprintf(stderr,"tbone at push_depth %d\n",tth_push_depth);
  TTH_OUTPUT(TTH_TEXTBOX1);
  tth_push_depth--;TTH_PRETEXCLOSE("\\tth_boxclose");tth_push_depth++;
}
<equation,tokexp,exptokarg,textbox>\\hbox{SP}+to {GET_DIMEN;} /* Override new handling */

<equation>\$            |
<equation>(\\end|\\begin)\{math\} |
<equation>\\(\)|\()          {
  /* Deal with single $ or inline in display equations or boxes.*/
  if(displaystyle==1){ /* Open inline in box enclose it.*/
    if(tth_debug&2)fprintf(stderr,"Inline inside displaystyle.\n");
    TTH_SCAN_STRING("{$");
    displaystyle++;
  }else if(displaystyle==2){
    if(!strstr(tth_font_open[tth_push_depth],TTH_ITAL1)){
      strcat(tth_font_open[tth_push_depth],tth_font_open[0]);
      strcat(tth_font_close[tth_push_depth],tth_font_close[0]);   
    }
    displaystyle++;
  }else if(displaystyle==3){ /* End enclosure inserted. */
    if(tth_debug&2)fprintf(stderr,"End Inline inside displaystyle.\n");
    TTH_SCAN_STRING("}");
    displaystyle=1;
  }else if(strstr(tth_texclose[tth_push_depth],"tth_boxclose")) {
    if(tth_debug&2) fprintf(stderr,"Inline inside box.\n");
    if(!strstr(tth_font_open[tth_push_depth],TTH_ITAL1)){
      strcat(tth_font_open[tth_push_depth],tth_font_open[0]);
      strcat(tth_font_close[tth_push_depth],tth_font_close[0]); 
    }
  }else{
    TTH_SCAN_STRING("}\\tth_endinline");
  }
 }
		/* Math greek and symbols */
<equation>\\alpha{SP}*	TTH_MATHS("a");
<equation>\\beta{SP}*	TTH_MATHS("b");
<equation>\\gamma{SP}*	TTH_MATHS("g");
<equation>\\delta{SP}*	TTH_MATHS("d");
<equation>\\epsilon{SP}*	TTH_MATHS("e");
 /* <equation>\\varepsilon{SP}*	TTH_MATHS("e"); */ 
<equation>\\varepsilon{SP}* {
  if(tth_unicode){
    TTH_MATHI(129); /*Kludge for coding translation */
  }else{
    TTH_MATHS("e");
  }
}			  
<equation>\\zeta{SP}*	TTH_MATHS("z");
<equation>\\eta{SP}*   	TTH_MATHS("h")
<equation>\\theta{SP}*	TTH_MATHS("q");
<equation>\\vartheta{SP}*   TTH_MATHS("J");
<equation>\\iota{SP}*	TTH_MATHS("i");
<equation>\\kappa{SP}*	TTH_MATHS("k");
<equation>\\lambda{SP}*	TTH_MATHS("l");
<equation>\\lambdar{SP}*	TTH_MATHS("l");
<equation>\\mu{SP}*     	TTH_MATHS("m");
<equation>\\nu{SP}*     	TTH_MATHS("n");
<equation>\\xi{SP}*     	TTH_MATHS("x");
<equation>\\pi{SP}*      TTH_MATHS("p");
<equation>\\varpi{SP}*	TTH_MATHS("v");
<equation>\\rho{SP}*    	TTH_MATHS("r");
<equation>\\varrho{SP}*	TTH_MATHS("r");
<equation>\\sigma{SP}*	TTH_MATHS("s");
<equation>\\varsigma	TTH_MATHS("V");
<equation>\\tau{SP}*    	TTH_MATHS("t");
<equation>\\upsilon{SP}*	TTH_MATHS("u");
<equation>\\phi{SP}*    	TTH_MATHS("f");
<equation>\\varphi{SP}*	TTH_MATHS("j");
<equation>\\chi{SP}*    	TTH_MATHS("c");
<equation>\\psi{SP}*    	TTH_MATHS("y");
<equation>\\omega{SP}*	TTH_MATHS("w");
<equation>\\Gamma{SP}*	TTH_MATHS("G");
<equation>\\Delta{SP}*	TTH_MATHS("D");
<equation>\\Theta{SP}*	TTH_MATHS("Q");
<equation>\\Lambda	TTH_MATHS("L");
<equation>\\Xi{SP}*	TTH_MATHS("X");
<equation>\\Pi{SP}*     	TTH_MATHS("P");
<equation>\\Sigma{SP}*	TTH_MATHS("S");
<equation>\\Upsilon{SP}*	TTH_MATHS("U");
<equation>\\Phi{SP}*    	TTH_MATHS("F");
<equation>\\Psi{SP}*    	TTH_MATHS("Y");
<equation>\\Omega{SP}*	TTH_MATHS("W");

<equation>\\ell{SP}*     TTH_MATHC("<i>l</i>");
<equation>\\aleph{SP}*	TTH_MATHI(192);
<equation>\\imath{SP}*	TTH_MATHS("i"); 
<equation>\\jmath{SP}*	TTH_MATHC("j"); 
<equation>\\wp{SP}*  	TTH_MATHI(195);
<equation>\\cal{SP}*(R|\{R\}) |
<equation>\\Re{SP}*  	TTH_MATHI(194);
<equation>\\cal{SP}*(I|\{I\}) |
<equation>\\Im{SP}*  	TTH_MATHI(193);
<equation>\\partial{SP}*     TTH_MATHI(182);
<equation>\\infty{SP}*  	TTH_MATHI(165);
<equation>\\angle{SP}*  	TTH_MATHI(208);
<equation>\'{SP}*	TTH_MATHI(162);
<equation>\\prime{SP}*	TTH_MATHI(162);
<equation>\\emptyset{SP}*	TTH_MATHI(198);
<equation>\\nabla{SP}*	TTH_MATHI(209);
<equation>\\surd{SP}*	TTH_MATHI(214);
<equation>\|            |
<equation>\\vert{SP}* 	TTH_MATHS("|");
<equation>\\parallel{SP}* |
<equation>\\\|           |
<equation>\\Vert{SP}* 	TTH_MATHS("||");
<equation>\\lbrack{SP}*  TTH_MATHC("[");
<equation>\\rbrack{SP}*  TTH_MATHC("]");
<equation>\\lbrace{SP}*  TTH_MATHC("{");
<equation>\\rbrace{SP}*  TTH_MATHC("}");
<equation>\\rceil{SP}*   TTH_MATHI(249);
<equation>\\rfloor{SP}*  TTH_MATHI(251);
<equation>\\lceil{SP}*   TTH_MATHI(233);
<equation>\\lfloor{SP}*  TTH_MATHI(235);
<equation>\\langle{SP}*		TTH_MATHI(225);
<equation>\\rangle{SP}*		TTH_MATHI(241);
\\textbackslash{SP}*            |
<equation>\\backslash{SP}* 	|
<equation>\\setminus{SP}* 	TTH_MATHC("\\"); 
<equation>\\forall{SP}*	TTH_MATHS("\"");
<equation>\\exists{SP}*	TTH_MATHS("$");
<equation>\\neg{SP}*  	TTH_MATHI(216);
<equation>\\clubsuit{SP}*	TTH_MATHI(167);
<equation>\\diamondsuit{SP}*	TTH_MATHI(168);
<equation>\\heartsuit{SP}*	TTH_MATHI(169);
<equation>\\spadesuit{SP}*	TTH_MATHI(170);

<equation>-      TTH_MATHS("-");
  /*Risky. <equation>\+      TTH_MATHS("+"); */
<equation>\\top{SP}*         TTH_MATHC("T"); 
<equation>\\bot{SP}* 	|
<equation>\\perp{SP}*	TTH_MATHS("^");
<equation>\\circ{SP}*	TTH_MATHI(176);
<equation>\\\~{SP}*     	TTH_MATHC("&#126;"); 
<equation>\\sim{SP}*		TTH_MATHS(" ~ ");
<equation>\\pmod |     /* Incorrect for now; needs parens.*/
<equation>\\bmod{SP}*	TTH_MATHC(" mod ");
<equation>\<		TTH_MATHC(" &lt; ");
<equation>\>		TTH_MATHC(" &gt; ");
<equation>\<\<		|
<equation>\\ll{SP}*		TTH_MATHC(" &lt;&lt; ");
<equation>\>\>		|
<equation>\\gg{SP}*		TTH_MATHC(" &gt;&gt; ");
<equation>\\ast{SP}*		TTH_MATHS("*");
<equation>\\star{SP}*	TTH_MATHS("*");
<equation>\\diamond{SP}*	TTH_MATHI(224);
<equation>\\bullet{SP}*     	TTH_MATHI(183);
<equation>\\cdot{SP}*		TTH_MATHC("&#183;"); 
 /*<equation>\\cdot	TTH_MATHI(215);*/
<equation>\\cup{SP}* 	TTH_MATHI(200);
<equation>\\cap{SP}* 	TTH_MATHI(199);
<equation>\\pm{SP}*		TTH_MATHI(177);
<equation>\\mp{SP}*		TTH_MATHS("-&#177;");
<equation>\\lor{SP}* 	|
<equation>\\vee{SP}*		TTH_MATHI(218);
<equation>\\land{SP}*        |
<equation>\\wedge{SP}*	TTH_MATHI(217);
<equation>\\oplus{SP}*	TTH_MATHI(197);
<equation>\\otimes{SP}*	TTH_MATHI(196);
<equation>\\oslash{SP}*	TTH_MATHI(198);

<getsubp>\\tthtensor{WSP}*    TTH_INC_MULTI;/* Don't mess up if it is in wrong place*/
<equation>\\tthtensor{SP}* {
  if(eqclose <= tth_flev-1 && displaystyle){
    /*If we end with a CELL3, cut it off. */
    if( ((jscratch=strlen(eqstr)) >= (js2=strlen(TTH_CELL3))) && 
	strcmp(eqstr+jscratch-js2,TTH_CELL3) == 0){
      *(eqstr+jscratch-js2)=0;
    }
    strcat(eqstr,TTH_CELL_L);
    if(levhgt[eqclose] == 1)levhgt[eqclose]=2;
    if(hgt < 2) hgt=2;
    yy_push_state(getsubp);
  }
}

<equation>\\int{SP}* 	{
 if(eqclose > tth_flev-1 || !displaystyle ){
   TTH_MATHI(242); /* TTH_OUTPUT(" "); perhaps not */
 }else{
   delimit("&#242;",2,eqchar);
   strcat(eqstr,eqchar);
   *eqchar=0;
   if(levhgt[eqclose] == 1)levhgt[eqclose]=2;
   hgt=3;
   yy_push_state(getsubp);
 }
 }
<equation>\\oint{SP}*\\limits{SP}* 	|
<equation>\\oint{SP}* {
  if(eqclose > tth_flev-1){
    TTH_MATHC("(");TTH_MATHI(242);TTH_MATHC(")");
  }else{
    TTH_OINT;
    yy_push_state(getsubp);
  }
 }

<equation>\\bigcap{SP}*  TTH_LIMITOP(199);
<equation>\\bigcup{SP}*  TTH_LIMITOP(200);
<equation>\\bigvee{SP}*  TTH_LIMITOP(218);
<equation>\\bigwedge{SP}*  TTH_LIMITOP(217);
<equation>\\bigotimes{SP}*  TTH_LIMITOP(196);
<equation>\\bigoplus{SP}*  TTH_LIMITOP(197);
<equation>\\sum{SP}*  TTH_LIMITOP(229);
<equation>\\prod{SP}* TTH_LIMITOP(213);
<equation>\\int{SP}*\\limits{SP}* 	TTH_LIMITOP(242);
<equation>\\limits{SP}*  /* Drop a limits command if not combined */

<equation>\\bigcap{SP}*\\nolimits{SP}*  TTH_MATHI(199);
<equation>\\bigcup{SP}*\\nolimits{SP}*  TTH_MATHI(200);
<equation>\\bigvee{SP}*\\nolimits{SP}*  TTH_MATHI(218);
<equation>\\bigwedge{SP}*\\nolimits{SP}*  TTH_MATHI(217);
<equation>\\bigotimes{SP}*\\nolimits{SP}*  TTH_MATHI(196);
<equation>\\bigoplus{SP}*\\nolimits{SP}*  TTH_MATHI(197);
<equation>\\sum{SP}*\\nolimits{SP}*  TTH_MATHI(229);
<equation>\\prod{SP}*\\nolimits{SP}* TTH_MATHI(213);

<equation>\\div{SP}*  	TTH_MATHI(184);
<equation>\\times{SP}*		TTH_MATHC("&times;"); 
 /*<equation>\\times	TTH_MATHI(180);*/
<equation>\\le(ss)?sim{SP}*		TTH_MATHC(" &lt;~"); 
<equation>\\g(e|tr)sim{SP}*		TTH_MATHC(" &gt;~"); 

<equation>\\mid{SP}*    TTH_MATHC(" ");TTH_MATHC("|");TTH_MATHC(" ");
<equation>\\leq{SP}*	TTH_MATHC(" ");TTH_MATHI(163);TTH_MATHC(" ");
<equation>\\le{SP}*	TTH_MATHC(" ");TTH_MATHI(163);TTH_MATHC(" ");
<equation>\\ge{SP}*     TTH_MATHC(" ");TTH_MATHI(179);TTH_MATHC(" ");
<equation>\\geq{SP}*    TTH_MATHC(" ");TTH_MATHI(179);TTH_MATHC(" ");
<equation>\\equiv{SP}*	TTH_MATHC(" ");TTH_MATHI(186);TTH_MATHC(" ");
<equation>\\approx{SP}*	TTH_MATHC(" ");TTH_MATHI(187);TTH_MATHC(" ");
<equation>\\not{SP}*={SP}*        |
<equation>\\neq{SP}*	TTH_MATHC(" ");TTH_MATHI(185);TTH_MATHC(" ");
<equation>\\ne{SP}*	TTH_MATHC(" ");TTH_MATHI(185);TTH_MATHC(" ");
<equation>\\not\\subset{SP}*	TTH_MATHC(" ");TTH_MATHI(203);TTH_MATHC(" ");
<equation>\\subset{SP}*	TTH_MATHC(" ");TTH_MATHI(204);TTH_MATHC(" ");
<equation>\\subseteq{SP}*  TTH_MATHC(" ");TTH_MATHI(205);TTH_MATHC(" ");
<equation>\\supset{SP}*	TTH_MATHC(" ");TTH_MATHI(201);TTH_MATHC(" ");
<equation>\\supseteq{SP}*  TTH_MATHC(" ");TTH_MATHI(202);TTH_MATHC(" ");
<equation>\\in{SP}*	TTH_MATHC(" ");TTH_MATHI(206);TTH_MATHC(" ");
<equation>\\not\\in{SP}* |
<equation>\\notin{SP}*	TTH_MATHC(" ");TTH_MATHI(207);TTH_MATHC(" ");
<equation>\\ni{SP}*  |
<equation>\\owns{SP}*    TTH_MATHC(" ");TTH_MATHI(39);TTH_MATHC(" ");
<equation>\\simeq{SP}*  |
<equation>\\cong{SP}*    TTH_MATHC(" ");TTH_MATHI(64);TTH_MATHC(" ");
<equation>\\propto{SP}*	TTH_MATHC(" ");TTH_MATHI(181);TTH_MATHC(" ");
<equation>\\gets          |
<equation>\\leftarrow	    TTH_MATHI(172);
<equation>\\longleftarrow   TTH_MATHI(172);
   /* A slight kludge */
<equation>\\longmapsto |
<equation>\\mapsto |
<equation>\\to  |
<equation>\\rightarrow	    TTH_MATHI(174);
<equation>\\longrightarrow  TTH_MATHI(174);
<equation>\\uparrow	    TTH_MATHI(173);
<equation>\\downarrow	    TTH_MATHI(175);
<equation>\\updownarrow	    TTH_MATHC(yytext);
<equation>\\Updownarrow	    TTH_MATHC(yytext);
<equation>\\longleftrightarrow |
<equation>\\leftrightarrow  TTH_MATHI(171);
<equation>\\Leftarrow	    TTH_MATHI(220);
<equation>\\Longleftarrow   TTH_MATHI(220);
<equation>\\Rightarrow	    TTH_MATHI(222);
<equation>\\Longrightarrow  TTH_MATHI(222);
<equation>\\RA		    TTH_MATHC(yytext);
<equation>\\Longleftrightarrow |
 /* moved before if code <equation>\\iff TTH_MATHI(219); */
<equation>\\Leftrightarrow  TTH_MATHI(219);
<equation>\\Uparrow	    TTH_MATHI(221);
<equation>\\Downarrow	    TTH_MATHI(223);
 /* <equation>\\dots{SP}*	TTH_MATHI(188); Not in math mode */
<equation>\\dotsb{SP}*	TTH_MATHI(188);
<equation>\\dotsc{SP}*	TTH_MATHI(188);
<equation>\\dotsi{SP}*	TTH_MATHI(188);
<equation>\\ldots{SP}*	TTH_MATHI(188);
<equation>\\cdots{SP}*	TTH_MATHI(188);
<equation>\\ddots{SP}*   TTH_OUTPUT("<sup><big>&#183;</big></sup>&#183;<sub><big>&#183;</big></sub>");
<equation>\\vdots{SP}*   TTH_OUTPUT(":");
<equation>\\atsign{SP}*		TTH_MATHC("@");
\\dag |
<equation>\\dagger       TTH_OUTPUT(TTH_DAG);
\\ddag |
<equation>\\ddagger       TTH_OUTPUT(TTH_DDAG);

<equation>\\arccos{SP}*		TTH_MATHC("arccos");  
<equation>\\arcsin{SP}*		TTH_MATHC("arcsin");  
<equation>\\arctan{SP}*		TTH_MATHC("arctan");  
<equation>\\arg{SP}*		TTH_MATHC("arg");  
<equation>\\cos{SP}*		TTH_MATHC("cos");  
<equation>\\cosh{SP}*		TTH_MATHC("cosh");  
<equation>\\cot{SP}*		TTH_MATHC("cot");  
<equation>\\coth{SP}*		TTH_MATHC("coth");  
<equation>\\csc{SP}*		TTH_MATHC("csc");  
 /* <equation>\\deg{SP}*        TTH_MATHC("&deg;");  Incorrect TeX */
<equation>\\deg{SP}*		TTH_MATHC("deg");
<equation>\\dim{SP}*		TTH_MATHC("dim");  
<equation>\\exp{SP}*		TTH_MATHC("exp");  
<equation>\\hom{SP}*		TTH_MATHC("hom");  
<equation>\\ker{SP}*		TTH_MATHC("ker");  
<equation>\\lg{SP}*		TTH_MATHC("lg");  
<equation>\\ln{SP}*		TTH_MATHC("ln");  
<equation>\\log{SP}*		TTH_MATHC("log");  
<equation>\\sec{SP}*		TTH_MATHC("sec");  
<equation>\\sin{SP}*		TTH_MATHC("sin");  
<equation>\\sinh{SP}*		TTH_MATHC("sinh");  
<equation>\\tan{SP}*		TTH_MATHC("tan");   
<equation>\\tanh{SP}*		TTH_MATHC("tanh");  

<equation>\\Pr{SP}*(\\(no)?limits{SP}*)?	|
<equation>\\inf{SP}*(\\(no)?limits{SP}*)?     |
<equation>\\gcd{SP}*(\\(no)?limits{SP}*)?	|
<equation>\\det{SP}*(\\(no)?limits{SP}*)?	|
<equation>\\max{SP}*(\\(no)?limits{SP}*)?     |
<equation>\\min{SP}*(\\(no)?limits{SP}*)?     |
<equation>\\sup{SP}*(\\(no)?limits{SP}*)?     |
<equation>\\liminf{SP}*(\\(no)?limits{SP}*)?	|
<equation>\\limsup{SP}*(\\(no)?limits{SP}*)?	|
<equation>\\lim{SP}*(\\(no)?limits{SP}*)?	{
  if(strstr(yytext,"nolimit")){js2=0;}else{js2=1;}
  *(yytext+1+strcspn(yytext+1," \\"))=0;
  if(eqclose >tth_flev-1 || js2==0){          TTH_MATHC(yytext+1);
  }else{
    strcat(eqstr,TTH_CELL3);
    strcat(eqlimited,yytext+1);
    oa_removes=0;
    yy_push_state(getsubp);
    if(levhgt[eqclose] == 1) levhgt[eqclose]=2; /* Force fraction closure */
  }
 }
<equation>\\mathop{WSP}*\{ |
<equation>\\(over|under)brace{WSP}*\{ {
 if(eqclose > tth_flev-1 || !displaystyle ){
   unput('{');
 }else{
  TTH_INC_MULTI; 
  strcat(eqstr,TTH_CELL3);
  mkkey(eqstr,eqstrs,&eqdepth);
  eqclose++;
  if(tth_flev<0)tth_flev=tth_flev-99;
  TTH_PUSH_CLOSING;
  active[eqclose-1]=30;
    /*TTH_PRETEXCLOSE("\\tth_eqlimited");*/
  oa_removes=0;
  if(*(yytext+1) == 'o'){
    TTH_CCPY(closing,TTH_OBRB);
    strcpy(eqstr,TTH_OBR);
  }else if(*(yytext+1) == 'u'){
    TTH_CCPY(closing,TTH_OBR);
    strcpy(eqstr,TTH_OBRB); 
  }else {
    strcpy(eqstr,"");
    unput(' ');
  }
  mkkey(eqstr,eqstrs,&eqdepth);
  *eqstr=0;
  tophgt[eqclose]=1;
  levhgt[eqclose]=1;
  active[eqclose]=1;
  unput('{');
 }
}
<equation>\\tth_eqlimited  { /* not done eqlimited section for mathop, overbrace */
    if(tth_debug&2)fprintf(stderr,"Mathop eqlimited:%s\n",eqstr);
    if(strlen(eqlimited)+strlen(eqstr)< TTH_DLEN) {
      strcat(eqlimited,eqstr);
      if(tth_debug&2)fprintf(stderr,"EQLIMITED=||%s||\n",eqlimited);
    }else{
      fprintf(stderr,
          "Error: Fatal! Exceeded eqlimited storage. Over/underbrace too long.\n");
      TTH_EXIT(5);
    }
    *eqstr=0;
    /*strcpy(eqstr,eqstrs[eqdepth-1]);*/
    yy_push_state(getsubp);  /*Does not work here */
    if(levhgt[eqclose] == 1)levhgt[eqclose]=2; /* Force fraction closure */
    /*active[eqclose-1]=0;*/
}
 /* end of symbols */

<equation>\\ensuremath    /* Nothing needs doing */
<equation>\\overrightarrow	TTH_SWAP("\\buildrel\\rightarrow\\over ");
<equation>\\overleftarrow	TTH_SWAP("\\buildrel\\leftarrow\\over ");

 /* Above accents expressed with braces. Removed {WSP} 11 Apr */
<equation>\\bar\{.\} { /* single character bar; convert to \sar */
  *(yytext+1)='s';
  TTH_SCAN_STRING(yytext);
 }
<equation>\\qrt\{       |
<equation>\\(wide)?hat\{   |
<equation>\\vec\{   |
<equation>\\(wide)?tilde\{ |
<equation>\\dd?ot\{   |
<equation>\\sar\{   |    /* single character bar tth special; see above */
<equation>\\bar\{	|    /* using a rule for multiple characters barred.*/ 
<equation>\\overline\{ {
  if(tth_debug&2) {
    fprintf(stderr,"Start Overaccent {, eqdepth=%d, eqclose=%d, tth_flev=%d, levdelim=%s.\n",eqdepth,eqclose,tth_flev,levdelim[eqclose]);
  }
  if(*(yytext+2)=='d') *(yytext+1)='2';
  if(strstr(yytext,"wide")==yytext+1) yytext=yytext+4; /* skip wide */
  if(eqclose > tth_flev && *(yytext+1)=='q'){TTH_OUTPUT(scratchstring);}
  if(eqclose > tth_flev && tth_istyle&2 && *(yytext+1)!='q'){
    /* Testing of stylesheet aproach for inline use: -w2 not Netscape. */
    switch(*(yytext+1)){
    case 'h':      TTH_OUTPUT("<span class=\"overacc1\">");TTH_MATHI(217);
      TTH_OUTPUT("</span>");break;
    case 't':TTH_OUTPUT("<span class=\"overacc1\">~</span>");break;
    case 'o': case 'b': case 's': 
      TTH_OUTPUT("<span class=\"overacc2\">");TTH_MATHI(190);
      TTH_OUTPUT("</span>");break;
    case 'd':TTH_OUTPUT("<span class=\"overacc1\">&#183; </span>");break;
    case '2':TTH_OUTPUT("<span class=\"overacc1\">&#183;&#183; </span>");break;
    case 'v':
      TTH_OUTPUT("<span class=\"overacc2\">");TTH_MATHI(174);
      TTH_OUTPUT("</span>");break;
    }
  }else{ /*Display or non-style in-line*/
    mkkey(eqstr,eqstrs,&eqdepth);
    eqclose++;
    *eqstr=0;
    if(tth_flev<0)tth_flev=tth_flev-99;
    TTH_PUSH_CLOSING;
    if(eqclose > tth_flev){ /* Inline levels will be enclosed in [()]. */
      TTH_CCPY(closing,"");
      switch(*(yytext+1)){
      case 'o': case 'b': case 's': TTH_MATHS("`");break;
      case 'd': TTH_CCPY(closing,"\\dot");break;
      case '2': TTH_CCPY(closing,"\\ddot");break;
      case 't': TTH_CCPY(closing,"\\tilde");break;
      case 'h': TTH_MATHC("^");break;
      case 'v': TTH_CCPY(closing,"\\vec");break;
      case 'q': /* output moved above to fix inline */ break;
      default : fprintf(stderr,"Overaccent error:%s,%d\n",yytext,*(yytext+1));
      }
    }else{ /* Display case*/ 
      TTH_CCPY(closing,TTH_OA3);
      switch(*(yytext+1)){
      case 'o': strcpy(eqstr,TTH_DIV);
	strcat(eqstr,TTH_OA5);TTH_CCPY(closing,TTH_OA3);
	break;
      case 'b': case 's': TTH_OUTPUT(TTH_OA1);
	TTH_OUTPUT((tth_istyle&1 ? "-":"_"));TTH_OUTPUT(TTH_OA2);break;
      case 'd': TTH_OUTPUT(TTH_OA1); 
	if(tth_istyle&1) {TTH_MATHI(215);} else {TTH_OUTPUT(".");}
	TTH_OUTPUT(TTH_OA2);break;
      case '2': TTH_OUTPUT(TTH_OA1);
	if(tth_istyle&1) {TTH_MATHI(215);TTH_MATHI(215);} else 
	  {TTH_OUTPUT("..");} TTH_OUTPUT(TTH_OA2);break;
	  /* case '2': strcpy(eqstr,"..<br />");break; */
      case 't':TTH_OUTPUT(TTH_OA1);TTH_OUTPUT("~");strcat(eqstr,TTH_OA2);break;
      case 'h':TTH_OUTPUT(TTH_OA1);TTH_OUTPUT("^");strcat(eqstr,TTH_OA2);break;
      case 'v':TTH_OUTPUT(TTH_OA1);TTH_MATHI(174);TTH_OUTPUT(TTH_OA2);break;
	/* case 'v': TTH_MATHI(174);strcat(eqstr,"<br />");break; */
      case 'q': {
      if(tth_debug&2)fprintf(stderr,"qrtlen=%d\n",qrtlen);
      sprintf(eqstr,"</td><td nowrap=\"nowrap\" align=\"left\">%s&nbsp;&nbsp;",TTH_OA1);
      for(i=0;i<qrtlen2;i++) strcat(eqstr,"&nbsp;");
      if(tth_istyle&1){
	TTH_OUTPUT(TTH_SYMBOL);
	chr1[0]=190;
	for(i=0;i<0.6*qrtlen-.22;i++) strcat(eqstr,TTH_SYMPT(chr1));
	TTH_OUTPUT(TTH_SYMEND);
      }else       for(i=0;i<qrtlen;i++) strcat(eqstr,"_");
      TTH_OUTPUT(TTH_OA2);
      strcat(eqstr,TTH_large);
      TTH_OUTPUT(scratchstring);
      strcat(eqstr,TTH_SIZEEND);
      break;
      }
      default : fprintf(stderr,"Overaccent error:%s,%d\n",yytext,*(yytext+1));
      }
    }
    mkkey(eqstr,eqstrs,&eqdepth);
    *eqstr=0;
    tophgt[eqclose]=1; /* Was 2 since it is symmetrical */
    levhgt[eqclose]=1;
    active[eqclose]=1;
  }
  unput('{');
}

  /* Implementing sqrt as a command with optional argument.*/
<equation>\\sqrt TTH_SCAN_STRING("\\expandafter\\tthsqrtexp");
<equation>\\tthsqrtexp  TTH_TEX_FN_OPT("\\tth_sqrt#tthdrop2",2,"");
<psub>\\tth_sqrt#tthdrop2 {
  if((jscratch=indexkey("#1",margkeys,&margmax))!=-1)
    strcpy(scrstring,margs[jscratch]);
  else fprintf(stderr,"Error getting sqrt 1st argument");
  qrtlen2=strlen(scrstring);
  if((jscratch=indexkey("#2",margkeys,&margmax))!=-1){
    chr1[0]=214;
    if((js2=strlen(margs[jscratch]))==1 && !qrtlen2){ /* Single character */
      if(qrtlen2){ /* optional argument root of */
	sprintf(scratchstring,"<sup>%s%s%s</sup>",
		TTH_FOOTNOTESIZE,scrstring,TTH_SIZEEND);
	TTH_OUTPUT(scratchstring);
      }
      sprintf(dupstore,"{\\surd %s}",margs[jscratch]);
      TTH_SCAN_STRING(dupstore);
      *dupstore=0;
    }else if(strcspn(margs[jscratch],"{}\\")==js2
	     && !(tth_istyle&1)     /* Only for non-compressed */
	     && !qrtlen2    /* And non index */
	     ){/* multiple char qrt case.*/
      sprintf(scratchstring,"%s%s%s",TTH_SYMBOL,TTH_SYMPT(chr1),TTH_SYMEND);
      sprintf(dupstore,"\\qrt{%s}",margs[jscratch]);
      qrtlen=strlen(dupstore)-6;
      js2=0;
      chscratch=dupstore+5;
      while((jscratch=strcspn(chscratch," )(^_")) != strlen(chscratch)){
	js2++;
	chscratch=chscratch+jscratch+1;
	if(!strcspn((chscratch-1),"^_"))js2++;
      }
      qrtlen=qrtlen-(0.5*js2);
      TTH_SCAN_STRING(dupstore);*dupstore=0;
    }else{ /* Default case, embedded groups or commands.  Or index*/
      if(qrtlen2){
	sprintf(scratchstring,
	   "<sup>%s%s%s</sup>%s%s%s",TTH_FOOTNOTESIZE,scrstring,TTH_SIZEEND,
		TTH_SYMBOL,TTH_SYMPT(chr1),TTH_SYMEND);
      }else{
	sprintf(scratchstring,"%s%s%s",TTH_SYMBOL,TTH_SYMPT(chr1),TTH_SYMEND);
      }
      if(eqclose > tth_flev-1 ) { /* put in braces if topped out */
	TTH_OUTPUT(scratchstring);
	TTH_MATHC("{");
	TTH_PUSH_CLOSING;
	/* TTH_CCPY(closing,"}"); Came in wrong order after fraction. 
	 so fixed in the dupstore call.*/
	if(tth_debug&2) {
	  fprintf(stderr,
	      "Start Sqrt {, eqdepth=%d, eqclose=%d, tth_flev=%d, levdelim=%s.\n"
		  ,eqdepth,eqclose,tth_flev,levdelim[eqclose]);
	}
	mkkey(eqstr,eqstrs,&eqdepth);
	*eqstr=0;
	if(tth_flev < 0) tth_flev=tth_flev-99;
	eqclose++;
	tophgt[eqclose]=0;
	levhgt[eqclose]=1;
	sprintf(dupstore,"%s}\\}",margs[jscratch]);	
      }else{ /* use overline */
	sprintf(dupstore,"{\\overline{%s}\\tth_makeroot}",margs[jscratch]);
	tth_root_depth++;
	/* pass to delimit code via global stack. */
	TTH_SCAN_STRING(dupstore); /* defer the contents scan. Do index */
	tth_flev=tth_flev-99;  /* No built-up in index */
	/* use double braces to ensure inline enclosure works correctly. */
	sprintf(dupstore,"{{%s}\\tth_rootindex}",scrstring);
      }
      TTH_SCAN_STRING(dupstore);
      *dupstore=0;
    }
    yy_pop_state();
    rmdef(margkeys,margs,&margmax);    /* Dump two arguments */
    rmdef(margkeys,margs,&margmax);
  }else{fprintf(stderr,"Error finding sqrt argument");}
} /* end of tth_sqrt*/
<equation>\\tth_rootindex  {
    TTH_CCPY(tth_root_index[tth_root_depth],eqstr);
    tth_root_len[tth_root_depth]=strlen(eqstr);
    *eqstr=0;
    tth_flev=tth_flev+99;
}
<equation>\\tth_makeroot   strcpy(levdelim[eqclose],"&#214;");


 /* Above accents etc without braces: embrace following token (and rescan). */
<equation>\\sqrt{WSP}*   |
<equation>\\(wide)?hat{WSP}*   |
<equation>\\vec{WSP}*   |
<equation>\\(wide)?tilde{WSP}* |
<equation>\\dd?ot{WSP}*   |
<equation>\\bar{WSP}*	|
<equation>\\overline{WSP}*   {  /* overline needs leading WSP */
  TTH_INC_MULTI; 
  strcpy(dupstore,yytext);
  *(dupstore+strcspn(dupstore," \t\r\n"))=0;
  /* yy_push_state(embracetok); OLD */
  *expchar=0;TTH_CCPY(exptex,dupstore);*dupstore=0;
  yy_push_state(exptokarg); /* overaccent */
 }
<equation>\\eqno[^\$]*\$\$ { /*This is default.*/
  TTH_INC_MULTI;
  if((tth_flev > 0 )){
    strcpy(scrstring,yytext+5);
    *(scrstring+strlen(scrstring)-2)=0;
    sprintf(scratchstring,"}\\special{html:%s}%s\\tth_endnumbered",
	    (eqalignlog ? TTH_DISP5 : TTH_DISP3),scrstring);
    /*fprintf(stderr,"Ending eqno: %s\n",scratchstring); */
    TTH_SCAN_STRING(scratchstring);
  }else{
    yyless(5);  TTH_MATHC("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  }
 }
<equation>\\eqno     { /* Fallback only */
  if((tth_flev > 0 ) && (eqaligncell)) {
    tth_enclose(TTH_EQ1,eqstr,TTH_EQ4,eqstore);
    strcat(eqstr,TTH_CELL4);
  }
  TTH_MATHC("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
 }
<equation>\\[Bb]ig[lmr]?{WSP}* {
  TTH_INC_MULTI; 
  TTH_SCAN_STRING("\\left.\\tth_size2\\right");
 }
<equation>\\[Bb]igg[lmr]?{WSP}* {
  TTH_INC_MULTI; 
  TTH_SCAN_STRING("\\left.\\tth_size3\\right");
 }
<equation>\\tth_size2  levhgt[eqclose]=2;
<equation>\\tth_size3  levhgt[eqclose]=3;
<equation>\\left{WSP}*     {
  TTH_INC_MULTI;yy_push_state(bigdel);strcpy(scratchstring,"{");}
<equation>\\right{WSP}*    {
  TTH_INC_MULTI;yy_push_state(bigdel);strcpy(scratchstring,"}");}

<equation>\\global         ;
<equation>\\bmath          ;
<equation>\\textstyle      ;
 /* Textstyle html is so limited that it makes no sense to use it.
   Also it can trip problem with implied grouping of an eq insufficient.
   to end dupgroup. Partly avoided by the eqdept>2 test but not entirely.*/
 /*
<equation>\\textstyle {
  if(eqdepth>2){
    tth_flev=tth_flev-99;
    TTH_CCPY(argchar,"\\tth_endtextstyle");
    storetype=5;
    yy_push_state(dupgroup);
  }
}
<equation>\\tth_endtextstyle  tth_flev=tth_flev+99;
 */
<equation>\\displaystyle
<equation>\\scriptstyle
<equation>\\smash

  /* Default equation actions. */
  /* Was single character. IE gave problems. */
<equation>[a-zA-Z]+  {
    strcat(eqstr,tth_font_open[tth_push_depth]);
    strcat(eqstr,yytext);
    strcat(eqstr,tth_font_close[tth_push_depth]);
 }

<equation>{SP}*      TTH_MATHC(" ");
<equation>[ ]=[ ]           |
<equation>\\(%|$|&|#|\\|_)  |
<equation>[()\[\]]          |
<equation>[+\-\*=/\.,:;\?!] |
<equation>[0-9]*  { 
  if(*(yytext) == '\\'){ chscratch=yytext+1;} else {chscratch=yytext;}
  if(*chscratch=='&')chscratch="&amp;";
  /* If the font has been changed, use it for non-letters too */
  if(!tth_mathitalic || strcmp(tth_font_open[tth_push_depth],TTH_ITAL1)!=0 ){
    strcat(eqstr,tth_font_open[tth_push_depth]);
    strcat(eqstr,chscratch);
    strcat(eqstr,tth_font_close[tth_push_depth]);
  }else{
    strcat(eqstr,chscratch);
  }
}
<equation>{WSP}*={WSP}*     TTH_INC_MULTI; TTH_SCAN_STRING(" = ");



  /**** tth pseudo-TeX ******/
<equation>#tthbigsup {
  if(tth_debug&8) fprintf(stderr,"#tthbigsup, eqhgt=%d\n",eqhgt);
  strcat(eqstr,TTH_BR);
  *expchar=0;
  if(strlen(eqlimited)){
    tth_symext(eqlimited,eqstr+strlen(eqstr));
    *eqlimited=0;
    for(i=0;i<oa_removes;i++){TTH_CCAT(expchar,TTH_OA4);}
    oa_removes=0;
  }else{
    for(i=1;i<=eqhgt-2;i++){
      strcat(eqstr,TTH_BRN);
    }
  }
  if(!strlen(expchar)){TTH_CCAT(expchar,TTH_NULL_BOTTOM);}  /* IE fix */
  TTH_CCAT(expchar,TTH_CELL3); /* make compatible with cell trim code. */
  yy_push_state(exptokarg); /* tthbigsup code */
 }
<equation>\\tth_eqfin { /* Finish an eq group and attach to previous key */
  tth_prefix(eqstrs[eqdepth-1],eqstr,eqstore); /* prefix previous row.*/
  rmkey(eqstrs,&eqdepth);
  mkkey(eqstr,eqstrs,&eqdepth);     /* Start new row */
  *eqstr=0;
 }
<equation>\\tth_lefteq {
  lefteq=1;
  colspan=3;
 }

 /* End of Equation code. */

<getsubp>{WSP}*   {
 TTH_INC_MULTI;
} 
<getsubp>\\limits
<getsubp>(\^|\_) { /* unenclosed subp. Embrace or expand it */
  *expchar=0;strcpy(exptex,yytext);yy_push_state(exptokarg);
  if(tth_debug&8)fprintf(stderr,"Expanding big subpscript\n");
 }
<getsubp>\^\{ {
  storetype=1;
  yy_push_state(dupgroup);
  *dupstore=0;
 }
<getsubp>\_\{ {
  storetype=2;
  yy_push_state(dupgroup);
  *dupstore=0;
 }
<getsubp>\\[a-zA-Z@]+              {
  TTH_DO_MACRO
    else{
      yyless(0);TTH_SCAN_STRING("#");
    }
 }
\\tthscriptsize {
  if(tth_htmlstyle&4){
    TTH_OUTPUT("<span class=\"smaller\">");TTH_PRECLOSE("</span>");
  }else{
    TTH_OUTPUT("<small>");TTH_PRECLOSE("</small>");
  }
}
<getsubp>. { /* No more subp's */
  if(*yytext != '#') yyless(0);
  storetype=0;
  yy_pop_state();
  if(strlen(supstore) || strlen(substore)){ /* Need to deal with subp */
    strcpy(dupstore,"{\\tthscriptsize{");
    strcat(dupstore,supstore);
    strcat(dupstore,"}}#tthbigsup{\\tthscriptsize{");
    strcat(dupstore,substore);
    strcat(dupstore,"}}");
    if(tth_istyle&1) eqhgt=0.8*hgt+0.7; else eqhgt=hgt;
    if(tth_debug&8)fprintf(stderr,"Scanning subpscripts:%s\n",dupstore);
    TTH_SCAN_STRING(dupstore);
    *dupstore=0;
    *argchar=0;
    *supstore=0;
    *substore=0;
    strcpy(expchar,"<!--sup\n-->"); /* make non-null */
    yy_push_state(exptokarg); /* scanning subpscripts */
  }else if(strlen(eqlimited)){ /* No delimiters but a limited symbol */
    tth_symext(eqlimited,eqstr+strlen(eqstr));
    for(i=0;i<oa_removes;i++){strcat(eqstr,TTH_OA4);}
    oa_removes=0;
    strcat(eqstr,"</td><td nowrap=\"nowrap\">");
    *eqlimited=0;
  }  
 }

 /* New big, left, right, delimiters section */

<bigdel>(\\\{|\\lbrace)   { 
  yy_pop_state();strcpy(levdelim[eqclose+1],"{");unput(*scratchstring);}
<bigdel>(\\\}|\\rbrace)   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"}");unput(*scratchstring);}
<bigdel>\(   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"(");unput(*scratchstring);}
<bigdel>\)   {
  yy_pop_state();strcpy(levdelim[eqclose+1],")");unput(*scratchstring);}
<bigdel>(\[|\\lbrack)   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"[");unput(*scratchstring);}
<bigdel>(\]|\\rbrack)   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"]");unput(*scratchstring);}
<bigdel>\\lceil   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"&#233;");unput(*scratchstring);}
<bigdel>\\rceil   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"&#249;");unput(*scratchstring);}
<bigdel>\\lfloor   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"&#235;");unput(*scratchstring);}
<bigdel>\\rfloor   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"&#251;");unput(*scratchstring);}
<bigdel>\\langle   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"&#225;");unput(*scratchstring);}
<bigdel>\\rangle   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"&#241;");unput(*scratchstring);}
<bigdel>(\||\\vert)   {
  yy_pop_state();strcpy(levdelim[eqclose+1],"|");unput(*scratchstring);}
<bigdel>(\/|\\backslash)   {
  yy_pop_state();*levdelim[eqclose+1]=*yytext;unput(*scratchstring);}
<bigdel>\.   yy_pop_state();*levdelim[eqclose+1]=0;unput(*scratchstring);
<bigdel>. { /* unknown bigdelimiter; make blank and then rescan. */
  yy_pop_state();yyless(0);
  TTH_SCAN_STRING(scratchstring);
}



 /* *************   LaTeX Math constructs.     ***********************/

\\begin\{equation\*?\}  |
\\begin\{displaymath\}  |
\\\[ {    /* Latex display equations */
  if(tth_debug&3)fprintf(stderr,"Latex display eqn %d\n",equatno);
  displaystyle=1;
  /* Not needed now that empty div is used.
  if(tth_htmlstyle&2){
    TTH_OUTPUT(closing); strcpy(closing,"</div>");
    TTH_OUTPUT("\n<div class=\"p\">\n");
    }*/
  horizmode=0;
  strcpy(eqstr,"");
  eqclose=0;
  mkkey(eqstr,eqstrs,&eqdepth);
  TTH_PUSH_CLOSING;
  if(!strstr(tth_font_open[tth_push_depth],TTH_ITALO)){
    TTH_CCAT(tth_font_open[tth_push_depth],tth_font_open[0]);
    TTH_CCAT(tth_font_close[tth_push_depth],tth_font_close[0]);
  }
  yy_push_state(equation);
  if( (strlen(yytext)>2) && *(yytext+7)=='e'){
    if(*(yytext+strlen(yytext)-2)!='*') {
      equatno++;  
      strcpy(environment,"equation");
      sprintf(envirchar,"%d",equatno);
    }else if(tth_multinum) *envirchar=0;
  }
  if(tth_debug&2) fprintf(stderr,"envirchar=%s, tth_multinum=%d, equatno=%d\n",
	  envirchar,tth_multinum,equatno);
  TTH_SCAN_STRING("{"); /*OCT*/
 }
 /* begin (inline) math moved after the close math */
\\begin\{eqnarray\*?\} { /* Assume this is NOT inside \math */
  if(strstr(yytext,"*") != NULL){
    eqalignlog=1; tth_multinum++; /* No row numbering. No end numbering */
  } else eqalignlog=0;
  if(tth_debug&2)fprintf(stderr,
			 "eqnarray: eqalignlog=%d, tth_multinum=%d yytext=%s\n",
			 eqalignlog,tth_multinum,yytext); 
  TTH_SCAN_STRING("\\begin{equation}\\eqalign{");
 }


 /* **********************   LateX Non Math  ********************************/
\\begin\{document\} { /* Check for aux file. If present input. */
  tth_LaTeX=1;
  if(tth_splitfile)strcpy(filechar,"index.html"); /*sf*/
  if(strlen(tth_latex_file)){
    TTH_CCPY(argchar,tth_latex_file);strcat(argchar,".aux");
    if( (tth_inputfile=fopen(argchar,"r")) != NULL){
      tth_prefix("\\input ",argchar,eqstore);
      TTH_SCAN_STRING(argchar);
      fclose(tth_inputfile);tth_inputfile=NULL;
    } else{
      fprintf(stderr,"No auxiliary LaTeX file found: %s\n",argchar);
      /* New automatic auxfile section.*/
      if(tth_autopic){
	fprintf(stderr,
    "...trying to run latex, logfile=%s.tlg. This may take a moment ...\n",
		tth_latex_file);
	sprintf(scratchstring,
		"latex -interaction=batchmode %s >%s.tlg",
		tth_latex_file,tth_latex_file);
	if((js2=system(scratchstring))!=SUCCESS)
        fprintf(stderr,"...latex returned: %d indicating error(s) in the tex file.\n",js2);
	if( (tth_inputfile=fopen(argchar,"r")) != NULL){
	  tth_prefix("\\input ",argchar,eqstore);
	  TTH_SCAN_STRING(argchar);
	  fclose(tth_inputfile);tth_inputfile=NULL;
	  fprintf(stderr,"...latex seems to have created the aux file.\n");
	}else{
	  fprintf(stderr,"**** System call:%s failed to create aux file.\n**** You probably don't have latex installed.\n",
		  scratchstring);
	  fprintf(stderr,"**** Continuing, but any forward references etc. will be incorrect.\n");
	}
	/* End of auto aux section.*/
      }
    }    
    argchar[0]=0;
  }else{
    fprintf(stderr,
      "Latex base filename blank. Auxiliary files will not be found.\n");
  }
    TTH_PUSH_CLOSING;TTH_CCPY(closing,"");
  /* {TTH_PAR_ACTION} Not here because of titles etc. */
  horizmode=0;
 }
\\makeindex {/* Open index tid file for writing and start to do so. */
  if(strlen(tth_latex_file)){
    strcpy(scratchstring,tth_latex_file);strcat(scratchstring,".tid");
    if( (tth_indexfile=fopen(scratchstring,"w")) ){
      fprintf(stderr,"Opened index file: %s\n",scratchstring);
      /* Open the makeindex style file. Or use default compositor.*/
      strcpy(scratchstring,tth_latex_file);strcat(scratchstring,".tms");
      if( (tth_indexstyle=fopen(scratchstring,"w")) ){
	strcpy(page_compositor,".");
	fprintf(tth_indexstyle,"page_compositor \"%s\"\n",page_compositor);
	fclose(tth_indexstyle);
      }
    } else {
      fprintf(stderr,"**** Failed to open index file: %s Line %d\n",scratchstring,tth_num_lines);
    }
  }
 }

\\tthgpindex { /* Version to grab whole thing even special chars*/
  *dupstore=0;
  *argchar=0;
  yy_push_state(indexgroup);
  storetype=99; /* Just leave in dupgroup to be dealt with by prior state*/
  yy_push_state(uncommentgroup);
  bracecount=-1;
}
<indexgroup>.|\n { /* \index action on group stored in dupstore. */
  yyless(0);
  yy_pop_state();
  if(horizmode) horizmode=1;
  chscratch=dupstore+1; /* Remove braces.*/
  *(chscratch+strlen(chscratch)-1)=0;
  tthindexrefno++;
  if(tth_indexfile != NULL){
    strcpy(scratchstring,chscratch);
    *(scratchstring+strcspn(scratchstring,"|@"))= 0  ;
  /*Here we should remove spaces and special characters in a version
    of scratchstring to be used as the name. Because (quoting) ID and
    NAME tokens must begin with a letter ([A-Za-z]) and may be
    followed by any number of letters, digits ([0-9]), hyphens ("-"),
    underscores ("_"), colons (":"), and periodsx(".").  This means
    the unallowed characters are: "\n\t_!\"#$%&'()*+,/;<=>?[\\]^`{|}~" */
    /* This version replaced only ! 
    while(strlen(scratchstring)-strcspn(scratchstring,"!"))
    *(scratchstring+strcspn(scratchstring,"!")) = '+';   */
    while(strlen(scratchstring)
	  -strcspn(scratchstring,"\n\t !\"#$%&'()*+,/;<=>?[\\]^`{|}~"))
      *(scratchstring
	+strcspn(scratchstring,"\n\t !\"#$%&'()*+,/;<=>?[\\]^`{|}~")) = '_';
    strcpy(scrstring,chscratch);
    *(scrstring+strcspn(scrstring,"|"))= 0 ; /* remove all number formatting */
    if(lbook){
      if(appendix)sprintf(argchar,"%c",chapno+64);
      else sprintf(argchar,"%d",chapno);
      if(strstr(chscratch,"|see")==NULL){
	if(tth_splitfile)	fprintf(tth_indexfile, /*sf*/
		"\\indexentry{%s|href{%s#%s%s%d%d}}{%s%s%d}\n", /*sf*/
		   scrstring,filechar,scratchstring,/*sf*/
			 argchar,sectno,tthindexrefno,/*sf*/
			 argchar,page_compositor,sectno); else /*sf*/
	fprintf(tth_indexfile,
		     "\\indexentry{%s|href{#%s%s%d%d}}{%s%s%d}\n",
		scrstring,scratchstring,
		argchar,sectno,tthindexrefno,
		argchar,page_compositor,sectno);
	fprintf(tth_fdout,"<a \nid=\"%s%s%d%d\"></a>",
		scratchstring,argchar,sectno,tthindexrefno);
      }else{ /* A |see case */
	fprintf(tth_indexfile,
		"\\indexentry{%s}{%s%s%d}\n",chscratch,
		argchar,page_compositor,sectno);      }
    }else {
      if(appendix)sprintf(argchar,"%c",sectno+64);
      else sprintf(argchar,"%d",sectno);
      if(strstr(chscratch,"|see")==NULL){
	if(tth_splitfile) fprintf(tth_indexfile, /*sf*/
	      "\\indexentry{%s|href{%s#%s%s%d%d}}{%s%s%d}\n", /*sf*/
	       scrstring,filechar,scratchstring, /*sf*/
				  argchar,subsectno,tthindexrefno, /*sf*/
			 argchar,page_compositor,subsectno); else /*sf*/
	   fprintf(tth_indexfile,
		  "\\indexentry{%s|href{#%s%s%d%d}}{%s%s%d}\n",
		  scrstring,scratchstring,
		   argchar,subsectno,tthindexrefno,
		   argchar,page_compositor,subsectno);
	fprintf(tth_fdout,"<a \nid=\"%s%s%d\"></a>"
		,scratchstring,argchar,subsectno);
      }else{ /* A |see case */
	fprintf(tth_indexfile,
		"\\indexentry{%s}{%s%s%d}\n",chscratch,
		argchar,page_compositor,subsectno);
      }
    }
    *argchar=0;
  }
  *dupstore=0;
}

\\printindex { /* Check for file. If present put title and open */
  if(tth_indexfile !=NULL){
    fprintf(stderr,"Closing index file and processing ...\n");
    fclose(tth_indexfile);
    tth_indexfile=NULL;/* Omitting this caused segfaults during
			  footnote wrap if there are index entries in
			  footnotes. I guess because one tries to
			  write to fclosed file. In any case those
			  entries aren't entered into index. Fixme.*/
    if(*tth_index_cmd){
      if(strstr(tth_index_cmd," ")){/* Command with spaces is complete format*/
	sprintf(scratchstring,
		tth_index_cmd,tth_latex_file,tth_latex_file,tth_latex_file);
      }else{/* No spaces: just the makeindex command */
	sprintf(scratchstring,"%s -o %s.tin %s.tid",
		tth_index_cmd,tth_latex_file,tth_latex_file);
      }
    }else sprintf(scratchstring,"makeindex -o %s.tin -s %s.tms %s.tid",
		 tth_latex_file,tth_latex_file,tth_latex_file);
    jscratch=system(scratchstring);
    if(jscratch != SUCCESS){
      fprintf(stderr,"**** System call failed: %s**** Index not made.\n"
	      ,scratchstring);
    }
    strcpy(scratchstring,"(showing section)");
  } else *scratchstring=0;
  /* Get the index anyway */
  sprintf(argchar,"\n\\special{html:<a id=\"tth_sEcindex\"></a>\n}\\beginsection{\\indexname{ %s}}\\par\\input %s.tin",
	  scratchstring,tth_latex_file);
  TTH_SCAN_STRING(argchar);
  argchar[0]=0;
  if(tth_splitfile){ /*sf*/
    strcpy(filenext,"docindex.html");/*sf*/
    TTH_SCAN_STRING("\\tthsplittail\\tthsplitinv\\tthsplittop\\tthfileupd"); /*sf*/
  }/*sf*/
 }
\\tableofcontents { /* Check for file. If present put title and open */
  TTH_CCPY(argchar,tth_latex_file);TTH_CCAT(argchar,".toc");
  if( (tth_inputfile=fopen(argchar,"r")) != NULL){
    fclose(tth_inputfile);tth_inputfile=NULL;
    sprintf(scratchstring,"\\htmlheader{1}{\\contentsname{ }}\\input %s ",
	    argchar);
    if(tth_indexfile) {TTH_PUSH_BUFF(11);} else /*get extra code*/ 
    {TTH_PUSH_BUFF(0);} /*braces required*/
    yy_scan_string(scratchstring);
  }
  argchar[0]=0;
 }
\\listoftables { /* Check for file. If present put title and open */
  TTH_CCPY(argchar,tth_latex_file);strcat(argchar,".lot");
  if( (tth_inputfile=fopen(argchar,"r")) != NULL){
    tth_prefix("\\htmlheader{1}{\\listtablename{ }}\\input ",argchar,eqstore);
    TTH_SCAN_STRING(argchar);
    fclose(tth_inputfile);tth_inputfile=NULL;
  }
  tbno=0;/*sf*/
  argchar[0]=0;
 }
\\listoffigures { /* Check for file. If present put title and open */
  TTH_CCPY(argchar,tth_latex_file);strcat(argchar,".lof");
  if( (tth_inputfile=fopen(argchar,"r")) != NULL){
    tth_prefix("\\htmlheader{1}{\\listfigurename{ }}\\input ",argchar,eqstore);
    TTH_SCAN_STRING(argchar);
    fclose(tth_inputfile);tth_inputfile=NULL;
  }
  fgno=0;/*sf*/
  argchar[0]=0;
 }
\\@writefile{NLC}*{NL}  { /*Processing aux file*/
  TTH_INC_LINE
  if(strstr(yytext,"toc}{\\contentsline")==yytext+12){  /*sf*/
    /* Updating section label*/ /*sf*/
    if( (chscratch=strstr(yytext,"numberline {"))!=NULL){  /*sf*/
      strncpy(schar,(chscratch+12),2); /*max: 2 digit number*/ /*sf*/
      *(schar+strcspn(schar,"}."))=0; /*sf*/
    } /*sf*/
  }else if(strstr(yytext,"lof}{\\contentsline")){ /*sf*/
    if(fgno < TNO) mkkey(schar,fchar,&fgno); /*sf*/ 
    else fprintf(stderr,"Too many figures"); /*sf*/
  }else if(strstr(yytext,"lot}{\\contentsline")){ /*sf*/
    if(tbno < TNO) mkkey(schar,tchar,&tbno); /*sf*/
    else fprintf(stderr,"Too many tables"); /*sf*/
  } /*sf*/
}
\\contentsline{SP}*\{[a-z]*\}\{(\\numberline{SP}{BRCG})?   {
  horizmode=1;
  *scrstring=0;
  if(tth_debug&128) fprintf(stderr,"Contentsline %s\n",yytext);
  strcpy(refchar,"tth_sEc");
  if(strstr(yytext,"{chapter}")!=NULL){ 
    chaplog=4;strcpy(refchar,"tth_chAp");
  }else if(strstr(yytext,"{table}")!=NULL){
    strcpy(refchar,"tth_tAb");
    for(i=0;i<4;i++) strcat(scrstring,"&nbsp;");    
  }else if(strstr(yytext,"{figure}")!=NULL){
    strcpy(refchar,"tth_fIg");
    for(i=0;i<4;i++) strcat(scrstring,"&nbsp;");    
  }else if(strstr(yytext,"{section}")!=NULL){
    for(i=0;i<chaplog;i++) strcat(scrstring,"&nbsp;");
  }else if(strstr(yytext,"{subsection}")!=NULL){
    for(i=-4;i<chaplog;i++) strcat(scrstring,"&nbsp;");
  }else{ /* if(strstr(yytext,"{subsubsection}")!=NULL) all lower levels*/
    for(i=-8;i<chaplog;i++) strcat(scrstring,"&nbsp;");
  }
  if((chscratch=strstr(yytext,"\\numberline"))!=NULL){
    *(chscratch+strlen(chscratch)-1)=0;
    chscratch=chscratch+strcspn(chscratch,"{")+1;
    if(tth_splitfile){ /*sf*/
      if(strstr(yytext,"{section}")!=NULL){ /*sf*/
	if(tth_splitfile==2 || *auxflch==0){ /*sf*/
	  tth_splitfile=2;                    /*sf*/
	  sprintf(auxflch,"sec%s",chscratch); /*sf*/
	  *(auxflch+strcspn(auxflch,"."))=0;  /*sf*/
	  strcat(auxflch,".html"); /*sf*/
	} /*sf*/
      }else if(strstr(yytext,"{chapter}")!=NULL){ /*sf*/
	sprintf(auxflch,"chap%s.html",chscratch);  /*sf*/
      }else if(strstr(yytext,"{table}")!=NULL){  /*sf*/
       if(*(auxflch)=='c')sprintf(auxflch,"chap%s.html",tchar[tbno++]);/*sf*/
       else sprintf(auxflch,"sec%s.html",tchar[tbno++]);/*sf*/
      }else if(strstr(yytext,"{figure}")!=NULL){  /*sf*/
       if(*(auxflch)=='c')sprintf(auxflch,"chap%s.html",fchar[fgno++]);/*sf*/
       else sprintf(auxflch,"sec%s.html",fchar[fgno++]);/*sf*/
      } /*sf*/
    } /*sf*/
    fprintf(tth_fdout,"%s<a href=\"%s#%s%s\"\n>%s&nbsp; ",
	   scrstring,auxflch,refchar,chscratch,chscratch);
    TTH_TEX_FN("{#1}\\special{html:</a><br />}\\tthunknown#tthdrop2",2);
  }else{
    if(strstr(yytext,"{part}")){/*Only enter unnumbered line if part*/ 
      TTH_TEX_FN("{#1}\\special{html:<br />}\\tthunknown#tthdrop2",2);
    }else{TTH_TEX_FN("\\tthunknown#tthdrop2",2);}
  }
  unput('{');          /* Already in first group. */
}
\\cite{WSP}*(\[[^\{\]]*\])?{BRCG} {
  TTH_INC_MULTI;
  js2=strcspn(yytext,"{");
  strcpy(dupstore,yytext+js2+1);
  if(tth_debug&256) fprintf(stderr,"Citations:%s\n",dupstore);
  i=0;ind=-1;
  strcpy(dupstore2,"\\tthciteob");
  for(jargmax=0;jargmax<30;jargmax++){
/*      ind=ind+i+1; */
    ind=ind+i+1+strspn(dupstore+ind+i+1,", \t\n");/*Advance to start of next*/
    js2=strcspn(dupstore+ind,"},\t\n"); /*Termination of key*/ 
    i=js2+strspn(dupstore+ind+js2," \t\n"); /* Next divider*/
    *(dupstore+ind+js2)=0;
    jarg=indexkey(dupstore+ind,keys,&nkeys);
    if(jarg == -1) {
      fprintf(stderr,"No bibcite for %s\n",dupstore+ind);
    }else{
      if(ckeys[jarg]==0){
	if(tth_splitfile)sprintf(dupstore2+strlen(dupstore2),/*sf*/
	   "\\special{html:<a href=\"refs.html#%s\" id=\"CITE%s\" class=\"tth_citation\">}",/*sf*/
		     dupstore+ind,dupstore+ind);else  /*sf*/
	  sprintf(dupstore2+strlen(dupstore2),
		    "\\special{html:<a href=\"#%s\" id=\"CITE%s\" class=\"tth_citation\">}",
		   dupstore+ind,dupstore+ind);
	ckeys[jarg]++;
      }else{
	if(tth_splitfile)sprintf(dupstore2+strlen(dupstore2),/*sf*/
	   "\\special{html:<a href=\"refs.html#%s\" class=\"tth_citeref\">}",/*sf*/
		     dupstore+ind);else  /*sf*/
	  sprintf(dupstore2+strlen(dupstore2),
		    "\\special{html:<a href=\"#%s\" class=\"tth_citeref\">}",
		   dupstore+ind);
      }
      strcpy(scratchstring,defs[jarg]);
      if((chscratch=strstr(scratchstring,"#tthdrop0"))) *chscratch=0;
      /* New operator on the bibcite */
      strcat(dupstore2,"\\tthciteform ");
      strcat(dupstore2,scratchstring);
    if(*(dupstore+ind+i+1))strcat(dupstore2,"\\tthciteib{}");
      strcat(dupstore2,"\\special{html:</a>}");
      if(!nargs[jarg]){ 
	if(lbook)jscratch=chapno; else jscratch=sectno;
	if(appendix) nargs[jarg]=jscratch+64;
	else nargs[jarg]=jscratch;
	js2=jarg;
	mkkey(filechar,optargs,&js2);
      }
    }
    if(*(dupstore+ind+i+1)){
      strcat(dupstore2,"\\tthcitepb");
    } else { /* Exhausted citations */
      js2=strcspn(yytext,"{");
      if((jscratch=strcspn(yytext,"[")) < js2-2){
	strcat(dupstore2,"\\tthcitefi{}");
	strncat(dupstore2,yytext+jscratch+1,js2-jscratch-2);
      }
      strcat(dupstore2,"\\tthcitecb{}");
      jargmax=30;
    }
  }
  if(tth_debug&256)fprintf(stderr,"Rescanning citations:\n%s\n",dupstore2);
  TTH_SCAN_STRING(dupstore2);
  i=0;ind=0;jarg=0;jargmax=0; *dupstore=0; *dupstore2=0;
}

\\begin\{thebibliography\} TTH_TEX_FN("\\tth_thebibliography#tthdrop1",1);
\\tth_thebibliography {
  if(lbook)  {TTH_SCAN_STRING("\\special{html:<h2>}\\bibname\\special{html:</h2>\n}\\begin{description}");}
  else {TTH_SCAN_STRING("\\special{html:<h2>}\\refname\\special{html:</h2>\n}\\begin{description}");}
  if(tth_splitfile){ /*sf*/
    if(!bibliogs) strcpy(filenext,"refs.html"); /*sf*/
    else sprintf(filenext,"refs%d.html",bibliogs); /*sf*/
    bibliogs++; /*sf*/
    TTH_SCAN_STRING("\\tthsplittail\\tthsplitinv\\tthsplittop\\tthfileupd"); /*sf*/
  }/*sf*/
  TTH_SCAN_STRING("\\par");
 }

<Ldescription>\\bibitem TTH_TEX_FN_OPT("\\tthbibitem{#2}#tthdrop2",2,"");
<Ldescription>\\tthbibitem{BRCG} {
  TTH_INC_MULTI;
  TTH_OUTPUT(closing);strcpy(closing,"</dd>\n"); /*27 Apr 2001 */
  fprintf(tth_fdout," <dt>");
  strcpy(dupstore,yytext);
  *(dupstore+strlen(dupstore)-1)=0;
  if((chs2=strstr(dupstore,"]"))==NULL) chs2=dupstore;
  chs2=chs2+strcspn(chs2,"{")+1; 
  jarg=indexkey(chs2,keys,&nkeys);
  if(jarg== -1){
    fprintf(stderr,"Unknown bibitem %s\n",chs2);
    fprintf(tth_fdout,"[]</dt><dd>");
  }else{
    *(scratchstring)=0;
    if(tth_splitfile){  /*sf*/
      if(!optargs[jarg])  /*sf*/
	{fprintf(stderr,"**** Error: Null bibitem optarg (file)\n");}else/*sf*/
      strcpy(scratchstring,optargs[jarg]); /*sf*/
    } /*sf*/
      /* New operator on the bibcite */
    strcpy(scrstring,"\\tthbibform ");
    strcat(scrstring,defs[jarg]);
    if((chscratch=strstr(scrstring,"#tthdrop"))) *chscratch=0;/* huh?*/
    strcat(scrstring,"\\tthbibcb");
    strcat(scrstring,"}");
    TTH_PUSH_CLOSING;  strcpy(closing,"</a></dt><dd>");
    fprintf(tth_fdout,"<a href=\"%s#CITE%s\" id=\"%s\">",scratchstring,chs2,chs2);
    TTH_SCAN_STRING(scrstring);
  }
  jarg=0;*dupstore=0;
 }
\\bibliography{BRCG} { /* Input the bbl file. */
  TTH_CCPY(argchar,tth_latex_file);strcat(argchar,".bbl");
  if( (tth_inputfile=fopen(argchar,"r")) != NULL){
    tth_prefix("\\input ",argchar,eqstore);
    TTH_SCAN_STRING(argchar);
    fclose(tth_inputfile);tth_inputfile=NULL;
  }else{
      if(tth_autopic){
	fprintf(stderr,
	   "**** No bibliography file %s found. Trying to create.\n",argchar);
      /* New automatic bbl file section.*/
	fprintf(stderr,
    "...trying to run latex, logfile=%s.tlg. This may take a moment ...\n",
		tth_latex_file);
	sprintf(scratchstring,"latex -interaction=batchmode %s >%s.tlg",
		tth_latex_file,tth_latex_file);
	if((js2=system(scratchstring))!=SUCCESS)
        fprintf(stderr,"...latex returned: %d indicating error(s) in the tex file.\n",js2);
	fprintf(stderr,"...trying to run bibtex ...\n");
	sprintf(scrstring,"bibtex %s",tth_latex_file);
	if(system(scrstring)!=SUCCESS)fprintf(stderr,"Bibtex failed\n");
	if(system(scratchstring)!=SUCCESS){};
	if( (tth_inputfile=fopen(argchar,"r")) != NULL){
	  tth_prefix("\\input ",argchar,eqstore);
	  TTH_SCAN_STRING(argchar);
	  fclose(tth_inputfile);tth_inputfile=NULL;
	  fprintf(stderr,"...latex/bibtex have created file. ");
	  fprintf(stderr,"If Unknown bibitem now occurs, rerun tth.\n");
	}else{
	  fprintf(stderr,"**** System calls failed. You probably don't have latex or bibtex installed.\n**** No bbl file created. Bibliography will be incomplete.\n");
	}
      }else{
	/* End of auto bbl section.*/
	fprintf(stderr,
	"**** No bibliography file %s found. Create using latex and bibtex.\n",
		argchar);
      }
  }
  argchar[0]=0;
 }

\\appendix    {
  chapno=0;sectno=0;appendix=1;
  if(lbook) strcpy(scratchstring,
		   "\\renewcommand{\\thechapter}{\\Alph{chapter}}");
  else strcpy(scratchstring,
		   "\\renewcommand{\\thesection}{\\Alph{section}}");
  TTH_SCAN_STRING(scratchstring);
}
\\part\*  {  
  fprintf(tth_fdout,"\n<h1>"); yy_push_state(tokenarg); TTH_CCPY(argchar,"</h1>");
}
\\tthpart  {
  sprintf(scratchstring,"%s\\tthenclose{\\special{html:<br /><h1>}%s{ %s}   \\special{html:<br />}}{\\special{html:</h1><br />}} ",
	  "\\stepcounter{part}",
	  "\\partname","\\thepart");
  TTH_SCAN_STRING(scratchstring);
}
\\chapter\*  {
  fprintf(tth_fdout,"\n<h1>"); yy_push_state(tokenarg); TTH_CCPY(argchar,"</h1>");}
\\tthchapter {
  figureno=0;tableno=0;
  sprintf(labelchar,"%d",chapno+1);
  if(appendix) sprintf(labelchar,"%c",chapno+1+64);
  TTH_SCAN_STRING("\\tthchapcomplete");
  if(tth_splitfile){ /*sf*/
    sprintf(filenext,"chap%s.html",labelchar);/*sf*/
    TTH_SCAN_STRING("\\tthsplittail\\tthsplitinv\\tthsplittop\\tthfileupd"); /*sf*/
  }/*sf*/
}
\\tthfileupd   if(tth_splitfile)  strcpy(filechar,filenext); /*sf*/
\\tthsplitinv {/*sf*/
  fprintf(tth_fdout,TTH_MIME_DIVIDE,filenext);/*sf*/
  fprintf(tth_fdout,TTH_DOCTYPE); /*sf*/
  fprintf(tth_fdout,TTH_GENERATOR,TTH_NAME,TTH_VERSION); /*sf*/
  fprintf(tth_fdout,TTH_ENCODING); /*sf*/
  fprintf(tth_fdout,"%s",TTH_P_STYLE); /*sf*/
  if(tth_istyle)fprintf(tth_fdout,"%s",TTH_STYLE); /*sf*/
  if(!(tth_htmlstyle&4))fprintf(tth_fdout,"%s",TTH_SIZESTYLE); /*sf*/
  fprintf(tth_fdout,"<title>%s</title>\n",filenext);/*sf*/
  if(tth_htmlstyle&3)fprintf(tth_fdout,"</head>\n<body><div>\n");/*sf*/
}/*sf*/
\\tthfilenext fprintf(tth_fdout,"%s",filenext); /*sf*/
\\tthfilechar fprintf(tth_fdout,"%s",filechar); /*sf*/
\\tthchapcomplete {
  if(appendix) {TTH_CCPY(argchar,"\\appendixname");}
  else TTH_CCPY(argchar,"\\chaptername");
  sprintf(scratchstring,"\n\\stepcounter{chapter}\\tthenclose{\
 \\special{html:<a id=\"tth_chAp%s\"></a><h1>}\n%s{ \\thechapter}\
 \\special{html:<br />}}{\\special{html:</h1>}} ",
	  labelchar,argchar);
  TTH_SCAN_STRING(scratchstring);*argchar=0;
}
\\section\*  {   
  fprintf(tth_fdout,"\n<h2>"); yy_push_state(tokenarg); TTH_CCPY(argchar,"</h2>");}
\\tthsection {
  TTH_SCAN_STRING("\\tthsectcomplete");
  if(lbook) {
    sprintf(labelchar,"%d.%d",chapno,sectno+1);
    if(appendix)sprintf(labelchar,"%c.%d",chapno+64,sectno+1);
  }else{
    sprintf(labelchar,"%d",sectno+1);
    if(appendix)sprintf(labelchar,"%c",sectno+1+64);
    if(tth_splitfile){ /*sf*/
      sprintf(filenext,"sec%s.html",labelchar);/*sf*/
      TTH_SCAN_STRING("\\tthsplittail\\tthsplitinv\\tthsplittop\\tthfileupd"); /*sf*/
    }/*sf*/
  }
}
\\tthsectcomplete {
  if(secnumdepth > 0){
    /* the following needs the space at the end for tex compatibility */
    sprintf(scratchstring,"\n\\stepcounter{section}\\tthenclose{\
 \\special{html:<a id=\"tth_sEc%s\"></a><h2>}\n\\thesection\
 \\special{html:&nbsp;&nbsp;}}{\\special{html:</h2>}} ",labelchar);
    TTH_SCAN_STRING(scratchstring);    
  }else{
    fprintf(tth_fdout,"\n<h2>"); 
    yy_push_state(tokenarg); 
    TTH_CCPY(argchar,"</h2>");
  }
}
\\subsection\*  {   
  fprintf(tth_fdout,"\n<h3>"); yy_push_state(tokenarg); TTH_CCPY(argchar,"</h3>");}
\\tthsubsection {
  { 
    if(lbook) {
      if(appendix) sprintf(labelchar,"%c.%d.%d",chapno+64,sectno,subsectno+1);
      else sprintf(labelchar,"%d.%d.%d",chapno,sectno,subsectno+1);
    }else {
      if(appendix) sprintf(labelchar,"%c.%d",sectno+64,subsectno+1);
      else sprintf(labelchar,"%d.%d",sectno,subsectno+1);
    }
    if(secnumdepth > 1){
      sprintf(scratchstring,"\n\\stepcounter{subsection}\\tthenclose{\
     \\special{html:<a id=\"tth_sEc%s\"></a><h3>}\n\\thesubsection\
     \\special{html:&nbsp;&nbsp;}}{\\special{html:</h3>}} ",labelchar);
      TTH_SCAN_STRING(scratchstring);
    }else{
        fprintf(tth_fdout,"\n<h3>"); yy_push_state(tokenarg); TTH_CCPY(argchar,"</h3>");
    }
  }
}
\\subsubsection\*  {   
  fprintf(tth_fdout,"\n<h4>"); yy_push_state(tokenarg); TTH_CCPY(argchar,"</h4>");}
\\tthsubsubsection { 
  {
    if(lbook) {
      if(appendix) sprintf(labelchar,"%c.%d.%d.%d",
			   chapno+64,sectno,subsectno,subsubsectno+1);
      else sprintf(labelchar,"%d.%d.%d.%d",
		   chapno,sectno,subsectno,subsubsectno+1);
    }else {
      if(appendix) sprintf(labelchar,"%c.%d.%d",
			   sectno+64,subsectno,subsubsectno+1);
      else sprintf(labelchar,"%d.%d.%d",sectno,subsectno,subsubsectno+1);
    }
    if(secnumdepth > 2){
      sprintf(scratchstring,"\n\\stepcounter{subsubsection}\\tthenclose{\
      \\special{html:<a id=\"tth_sEc%s\"></a><h4>}\n\\thesubsubsection\
      \\special{html:&nbsp;&nbsp;}}{\\special{html:</h4>}} ",labelchar);
      TTH_SCAN_STRING(scratchstring);
    }else{
      fprintf(tth_fdout,"\n<h4>"); yy_push_state(tokenarg); TTH_CCPY(argchar,"</h4>");
    }
  }
}
\\tthparagraph {
  if(secnumdepth > 3){
    TTH_TEX_FN("\\par\\stepcounter{paragraph}{\\bf\\theparagraph\
 \\special{html:<a id=\"tth_sEc}\\theparagraph\\special{html:\">\n}\
    \\special{html:&nbsp;&nbsp;}#1\\special{html:</a>\n}\\ }#tthdrop1",1);
  }else{
    TTH_TEX_FN("\\par{\\bf#1\\ \\ }#tthdrop1",1);
  }
}
\\tthsubparagraph {
  if(secnumdepth > 4){
    TTH_TEX_FN("\\stepcounter{subparagraph}{\\special{html:<br />}\
    \\quad\\bf\
    \\special{html:<a id=\"tth_sEc}\\thesubparagraph\\special{html:\">\n}\
    \\thesubparagraph\
    \\special{html:&nbsp;&nbsp;}#1\\special{html:</a>\n}\\ }#tthdrop1",1);
  }else{
    TTH_TEX_FN("\\special{html:<br />}{\\quad\\bf#1\\ \\ }#tthdrop1",1);
  }
}

\\tthcaption {
  if(tth_debug&256)fprintf(stderr,"Caption in environment:%s\n",environment);
  if(!strcmp(environment,"figure")){
    figureno++;
    if(lbook) sprintf(envirchar,"%d.%d",chapno,figureno);
    else sprintf(envirchar,"%d",figureno);
    sprintf(scratchstring,"\n\\tthenclose{\\special{html:<div style=\"text-align:center\">}\\figurename{ \\thefigure:} }{\\special{html:</div>}} ");
  }else if(!strcmp(environment,"table")){
    tableno++;
    if(lbook) sprintf(envirchar,"%d.%d",chapno,tableno);
    else sprintf(envirchar,"%d",tableno);
    sprintf(scratchstring,"\n\\tthenclose{\\special{html:<div style=\"text-align:center\">}\\tablename{ \\thetable:} }{\\special{html:</div>}} ");
  }
  TTH_SCAN_STRING(scratchstring);
}
<psub>\\tthnewlabel {
  if(horizmode) horizmode=1;
  jscratch=indexkey("#1",margkeys,&margmax);
  if(tth_debug&256)fprintf(stderr,
    "tthnewlabel jscratch=%d, margs[jscratch]=%s\n",jscratch,margs[jscratch]);
  strcpy(dupstore,margs[jscratch]);
  if(tth_group(scrstring,margs[jscratch+1],TTH_CHARLEN-1)){
    fprintf(stderr,"Label end broken in newlabel:%s\n",margs[jscratch+1]); }
  if(tth_splitfile){ /*sf*/
    if(lbook)strcpy(scratchstring,"chap");  /*sf*/
    else strcpy(scratchstring,"sec"); /*sf*/
    if(strlen(schar)){ /* File defined; use it.*/  /*sf*/
      strcat(scratchstring,schar); /*sf*/
      strcat(scratchstring,".html"); /*sf*/
    }else if(*(scrstring+1)=='}') strcpy(scratchstring,"index.html"); /*sf*/
    else{ /* Should not now come here. */ /*sf*/
      strcat(scratchstring,scrstring+1); /*sf*/
      *(scratchstring+strcspn(scratchstring,".}"))=0; /*sf*/
      strcat(scratchstring,".html"); /*sf*/
      fprintf(stderr, /*sf*/
	     "**** Abnormal newlabel file reference:%s\n",scratchstring);/*sf*/
    } /*sf*/
  }else  /*sf*/
    *scratchstring=0;
  js2=nkeys; /* Just for copying the file name to optargs. */
  narg=*(scrstring+1);
  if(*(scrstring+1)=='}')narg=0;
  else if(narg > 64) narg=-(narg-64); /* Test for appendix */
  else sscanf(scrstring+1,"%d",&narg);
  if(nkeys < NFNMAX) {
    mkkey(scratchstring,optargs,&js2);
    lkeys[nkeys]=0;
    mkdef(dupstore,keys,scrstring,defs,&narg,nargs,&nkeys);
    if(tth_debug&256){
      i=indexkey(dupstore,keys,&nkeys);
      fprintf(stderr,"Defined Label %s, index %d, nargs %d, optarg %s, Def %s\n",
	      dupstore,i,nargs[i],optargs[i],defs[i]);
    }
  }
  else fprintf(stderr,"Too many functions to define %s\n",dupstore);
  *dupstore=0;
 }
<psub>\\tthlabel  { /* Called only by \label latex builtin. */
  if(horizmode) horizmode=1;
  jscratch=indexkey("#1",margkeys,&margmax);
  if(tth_debug&256)fprintf(stderr,"tthlabel jscratch=%d, margs[jscratch]=%s  ",
			  jscratch,margs[jscratch]);
  strcpy(dupstore,margs[jscratch]);
  narg=chapno;
  if(indexkey(dupstore,keys,&nkeys) == -1) {
    if(nkeys < NFNMAX) {
      js2=nkeys;
      mkkey(filechar,optargs,&js2);
      lkeys[nkeys]=0;
      if(strlen(environment))
	mkdef(dupstore,keys,envirchar,defs,&narg,nargs,&nkeys);
      else
	if(strlen(labelchar)) 
	   mkdef(dupstore,keys,labelchar,defs,&narg,nargs,&nkeys);
	else mkdef(dupstore,keys,"*",defs,&narg,nargs,&nkeys);
      if(tth_debug&256){
	i=indexkey(dupstore,keys,&nkeys);
	fprintf(stderr,"\nDefined Label %s index %d nargs %d Def %s\n",
		dupstore,i,nargs[i],defs[i]);
      }
    }
    else fprintf(stderr,"Too many functions to define %s",dupstore);
  }else{
    if(tth_debug&256)fprintf(stderr,"Predefined.\n");
  }
  fprintf(tth_fdout,"<a id=\"%s\">\n</a>",dupstore);
  *dupstore=0;
 }
<psub>\\tthpageref#tthdrop1 |
<psub>\\tthref#tthdrop1 {
  if(horizmode) horizmode=1;
  jscratch=indexkey("#1",margkeys,&margmax);
  if(tth_debug&256) fprintf(stderr,"tthref jscratch=%d, margs[jscratch]=%s\n",
			  jscratch,margs[jscratch]);
  strcpy(dupstore,margs[jscratch]);
  ind=indexkey(dupstore,keys,&nkeys);
  if(ind != -1){
    strcpy(scratchstring, "#tthdrop1\\special{html:<a href=\"");
    if(tth_splitfile){   /*sf*/
      if(!optargs[ind])   /*sf*/
	{fprintf(stderr,"**** Error: Null ref optarg (file)\n");} else/*sf*/
      strcat(scratchstring,optargs[ind]); /*sf*/
    }              /*sf*/
    if(*(yytext+4)=='p'){
      strcpy(scrstring,"pageref");
    }else{ 
      strcpy(scrstring,defs[ind]);
      if(strspn(scrstring," {}")==strlen(scrstring)) strcpy(scrstring,"*");
    }
    sprintf(scratchstring+strlen(scratchstring),
	    "#%s\">}%s\\special{html:</a>}",dupstore,scrstring);
    TTH_SCAN_STRING(scratchstring);
  }else{
    fprintf(stderr,"Unknown Latex \\ref:%s\n",dupstore);
    TTH_SCAN_STRING("#tthdrop1");
  }
  *dupstore=0;*argchar=0;
 }

<builtins,latexbuiltins>\n   TTH_INC_LINE;
<builtins>.  {
  /* These are purely to silence warnings. They are non-functional*/
  PUSHEDINTS[0][0]=0;
  PUSHEDINTDEPTHS[0]=0;
  /* end of warning silencing */
  yy_pop_state();
  yyless(0);
  strcpy(dupstore2,tth_builtins);
  strcat(dupstore2,"\\tthbuiltins");
  TTH_SCAN_STRING(dupstore2);
  *dupstore2=0;
 }
<latexbuiltins>.  {
  yy_pop_state();
  yyless(0);
  strcpy(dupstore2,tth_latex_builtins);
  strcat(dupstore2,tth_latex_builtins2);
  strcat(dupstore2,tth_latex_builtins3);
  strcat(dupstore2,"\\tthlatexbuiltins");
  TTH_SCAN_STRING(dupstore2);
  *dupstore2=0;
  tth_LaTeX=tth_debug+1; /* LaTeX initialization state. */
  if(tth_debug==1) tth_debug--; /* Don't debug builtins */
 }

\\tthcountinit    {
  countstart=ncounters;
  if(tth_debug&512) fprintf(stderr,"Countstart= %d\n",countstart);
}

\\document((class)|(style))(\[[^\]]*\])?{BRCG} {
  TTH_INC_MULTI;
  if(indexkey("\\label",keys,&nkeys) == -1){ /* Only if not already done */
    strcpy(dupstore2,tth_latex_builtins);
    strcat(dupstore2,tth_latex_builtins2);
    strcat(dupstore2,tth_latex_builtins3);
    tth_LaTeX=tth_debug+1; /* LaTeX initialization state. Make non-zero. */
    if(tth_debug==1) tth_debug--; /* Don't debug builtins */
    if(tth_debug&512) fprintf(stderr,"Defining built-in Latex commands\n");
  }
  if(strstr(yytext,"book")||strstr(yytext,"report")) {
    lbook=1;
    strcat(dupstore2,
	   "\\renewcommand{\\thesection}{\\thechapter.\\arabic{section}}");
    strcat(dupstore2,
	   "\\renewcommand{\\thefigure}{\\thechapter.\\arabic{figure}}");
    strcat(dupstore2,
	   "\\renewcommand{\\thetable}{\\thechapter.\\arabic{table}}");
    strcat(dupstore2,"\\setcounter{secnumdepth}{2}");    
    strcat(dupstore2,
	   "\\renewcommand{\\theequation}{\\thechapter.\\arabic{equation}}");
  } else {
    lbook=0;
  }
  strcat(dupstore2,"\\tthlatexbuiltins"); /* signals end of builtins */
  TTH_SCAN_STRING(dupstore2);
  *dupstore2=0;
}

\\usepackage{SP}*(\[[^\{\]]*\])?\{natbib\} {
  TTH_INC_MULTI;
  if(strstr(yytext,"numbers")){TTH_SCAN_STRING("\\NAT@numberstrue ");}
  TTH_SCAN_STRING("\\newif\\ifNAT@numbers\
\\def\\tthbibform#1#2#3#4{\\ifNAT@numbers[#1\\else[#3 #2\\fi}\
\\def\\tthciteform#1#2#3#4{\\ifNAT@numbers#1\\else\\ #3, [#2\\fi}\
\\def\\tthciteob{\\ifNAT@numbers[\\else\\fi}\
\\def\\tthciteib{\\ifNAT@numbers\\else]\\fi}\\def\\tthcitecb{]}\
\\input tthntbib.sty");
}
\\usepackage{SP}*\{  yy_push_state(matchbrace);

 /* Font faces and styles etc.*/
\\textmd               |
\\textnormal   TTH_SWAP("\\rm ");
\\textbf      TTH_SWAP("\\bf ");
\\textrm      TTH_SWAP("\\rm ");
\\textsl    TTH_SWAP("\\it ");
\\textit  TTH_SWAP("\\it ");
\\texttt  TTH_SWAP("\\tt ");
\\textsf  TTH_SWAP("\\sffamily ");
\\textsc  TTH_SWAP("\\scshape ");
 /*   Now using the halign brace closure */
<textsc>[a-z]*     {
  TTH_OUTPUT(TTH_SMALLCAPS_FONT1);
  for(jscratch=0;jscratch<strlen(yytext);jscratch++) {
    *(yytext+jscratch)=toupper(*(yytext+jscratch));}
  TTH_OUTPUTH(yytext);
  TTH_OUTPUT(TTH_SMALLCAPS_FONT2);horizmode=1;
 }
<textsc>[A-Z] TTH_OUTPUT(yytext);horizmode=1; /* Trying to fix in equations */


\\em{SP}*         TTH_OUTPUT(TTH_EM1);TTH_PRECLOSE(TTH_EM2);
<exptokarg,tokexp>\\emph |
\\emph            TTH_SWAP("\\em ");
\\begin\{em\}      TTH_SCAN_STRING("{\\em ");
\\begin\{verbatim\*?\}      {
  if(horizmode) horizmode=1;
  fprintf(tth_fdout,"\n<pre>"); yy_push_state(verbatim);
  TTH_PUSH_CLOSING;  TTH_CCPY(closing,"\n</pre>");}
\\begin\{center\}  {
  fprintf(tth_fdout,"\n<div style=\"text-align:center\">");  TTH_PUSH_CLOSING;  TTH_CCPY(closing,"</div>");}
\\begin\{flushright\}  {
  if(horizmode) horizmode=1;
  fprintf(tth_fdout,"\n<div align=\"right\">");TTH_PUSH_CLOSING;
  TTH_CCPY(closing,"</div>");}
\\begin\{verse\}  |
\\begin\{quotation\}  |
\\begin\{quote\}  {
  if(horizmode) horizmode=1;
  fprintf(tth_fdout,"\n<blockquote><div>");
  TTH_PUSH_CLOSING;TTH_CCPY(closing,"</div></blockquote>");}
\\begin\{tthabstract\} {
  if(horizmode) horizmode=1;
  TTH_SCAN_STRING("\\beginsection{\\abstractname}\\par");
  TTH_PUSH_CLOSING; /*TTH_CCPY(closing,TTH_PAR);*/
}
\\end\{tthabstract\}   TTH_SCAN_STRING("\\egroup\\par");

\\begin\{itemize\}     {
  horizmode=0;
  fprintf(tth_fdout,"\n<ul>");yy_push_state(Litemize);
  tth_eqwidth=tth_eqwidth-TTH_INDPC;
  TTH_PUSH_CLOSING;
}
{WSP}*\\end\{itemize\}    {
  TTH_INC_MULTI;
  yy_pop_state();
  TTH_OUTPUT(closing);
  fprintf(tth_fdout,"</ul>");
  tth_eqwidth=tth_eqwidth+TTH_INDPC;
  TTH_POP_CLOSING;
  horizmode=1;
}

\\begin\{enumerate\}  {
  horizmode=0;
  fprintf(tth_fdout,"\n<ol type=\"%c\">",
	 enumtype[(enumerate > 4 ? 0 : enumerate)]);
  yy_push_state(Lenumerate);
  enumerate++;
  tth_eqwidth=tth_eqwidth-TTH_INDPC;
  TTH_PUSH_CLOSING;
 }
{WSP}*\\end\{enumerate\}    {
  TTH_INC_MULTI;
  yy_pop_state();
  TTH_OUTPUT(closing);
  fprintf(tth_fdout,"</ol>");
  enumerate--;
  tth_eqwidth=tth_eqwidth+TTH_INDPC;
  TTH_POP_CLOSING;
  horizmode=1;
}
\\begin\{list\}   {    /* list like description */
  horizmode=0;
  fprintf(tth_fdout,"\n<dl>\n");yy_push_state(Ldescription);
  yy_push_state(unknown); /* dump adjacent brace groups */
  tth_eqwidth=tth_eqwidth-TTH_INDPC;
  TTH_PUSH_CLOSING;
  horizmode=1;
  yy_push_state(removespace);
}
 /* Multiple column index. */
\\begin\{theindex\} {
  if(tth_debug&3)fprintf(stderr,"Starting the index ");
  horizmode=0;
  yy_push_state(Ldescription);
  TTH_OUTPUT("\n<table width=\"100%\"><col span=\"2\" width=\"48%\" /><tr><td valign=\"top\"><hr />\n<dl>\n");
  tth_eqwidth=tth_eqwidth-TTH_INDPC;
  TTH_PUSH_CLOSING;
  tth_index_face=0;
  tth_index_line=0;
}

 /* Multiple two-column segments broken only at indexspace.*/
<Ldescription>{WSP}*\\indexspace {
  /* fprintf(stderr,"indexspace\n"); */
  TTH_INC_MULTI;
  if(tth_index_line > tth_indexpage){
    TTH_OUTPUT(closing);    *closing=0;
    tth_index_line=0;
    if((++tth_index_face)&1){
      TTH_OUTPUT("</dl></td><td valign=\"top\"><hr />\n<dl>\n");
    }else{
      TTH_OUTPUT("</dl></td></tr><tr><td valign=\"top\"><hr />\n<dl>\n");
    }
  }else{
    TTH_OUTPUT("<br /><br />");
    ++tth_index_line;
  }
}

<Ldescription>{WSP}*\\end\{theindex\} {
  TTH_INC_MULTI;
  yy_pop_state();
  TTH_OUTPUT(closing);
  TTH_OUTPUT("</dl></td></tr></table>");
  tth_eqwidth=tth_eqwidth+TTH_INDPC;
  TTH_POP_CLOSING;
}

\\begin\{(description|theindex)\} {
  /*  if(horizmode) horizmode=1; */
  horizmode=0;
  fprintf(tth_fdout,"\n<dl>\n");yy_push_state(Ldescription);
  tth_eqwidth=tth_eqwidth-TTH_INDPC;
  TTH_PUSH_CLOSING;
 }
{WSP}*\\end\{list\}   |
{WSP}*\\end\{(description|theindex|thebibliography)\}  {
  TTH_INC_MULTI;
  yy_pop_state();
  TTH_OUTPUT(closing);
  fprintf(tth_fdout,"</dl>");
  tth_eqwidth=tth_eqwidth+TTH_INDPC;
  TTH_POP_CLOSING;
}
\\begin\{figure\*?\}(\[[^\]]*\])? {
  TTH_INC_MULTI;
  if(horizmode) horizmode=1;
  strcpy(environment,"figure");
  TTH_PUSH_CLOSING;*closing=0;
  if(lbook) sprintf(envirchar,"%d.%d",chapno,figureno+1);
  else sprintf(envirchar,"%d",figureno+1);
  {TTH_PAR_ACTION};
  fprintf(tth_fdout,"<a id=\"tth_fIg%s\">\n</a> ",envirchar);
 }
\\begin\{table\*?\}(\[[^\]]*\])? {
  TTH_INC_MULTI;
  if(horizmode) horizmode=1;
  strcpy(environment,"table");
  TTH_PUSH_CLOSING;*closing=0;
  if(lbook) sprintf(envirchar,"%d.%d",chapno,tableno+1);
  else sprintf(envirchar,"%d",tableno+1);
  {TTH_PAR_ACTION};
  fprintf(tth_fdout,"<a id=\"tth_tAb%s\">\n</a> ",envirchar);
 }
\\end\{figure\*?\} |
\\end\{table\*?\}  {   /* Special case. Remove environment label. */
  TTH_TEXCLOSE else{
  TTH_CLOSEGROUP;TTH_POP_CLOSING;
  {TTH_PAR_ACTION};
  *environment=0;}}

\\setlength\{\\unitlength\}{BRCG} strcpy(unitlength,yytext);
\\begin\{picture\}   {
  if(tth_autopic){
    picno++;
    if(tth_debug&32)fprintf(stderr,"Starting picture number %d\n",picno);
    fprintf(tth_fdout,"<br /><img src=\"pic%d.gif\" alt=\"Picture %d\" />",picno,picno);
    {TTH_PAR_ACTION};
    sprintf(scratchstring,"pic%d.gif",picno);
    if((tth_picfile=fopen(scratchstring,"r"))){
      fclose(tth_picfile);tth_picfile=NULL;
      fprintf(stderr,"Including existing picture %s\n",scratchstring);
      yy_push_state(discardgroup);
    }else{
      sprintf(scratchstring,"pic%d.tex",picno);
      if ( (tth_picfile=fopen(scratchstring,"w")) != NULL){
	fprintf(tth_picfile,
		"\\batchmode\\documentclass{article}\n\\usepackage{graphicx}\\usepackage{epsfig}\n\\pagestyle{empty}\n\\begin{document}%s\n%s",
		unitlength,yytext);
	yy_push_state(picture);
	jscratch=0;
      }else{
	fprintf(stderr,"Unable to open picture file for writing.\n");
	yy_push_state(discardgroup);
	fprintf(tth_fdout,"<br />Picture Not Created.<br />\n");
      }
    }
  }else{
    yy_push_state(discardgroup);
    fprintf(tth_fdout,"<br />Picture Omitted<br />");
  }
}
<picture>\\begin\{picture\} jscratch++;fprintf(tth_picfile,"%s",yytext);    
<picture>\\end\{picture\} {
  if(jscratch) {jscratch--; fprintf(tth_picfile,"%s",yytext);}    
  else{
    fprintf(tth_picfile,"%s",yytext);
    fprintf(tth_picfile,"\\end{document}\n");
    fclose(tth_picfile);tth_picfile=NULL;
    sprintf(scratchstring,"latex2gif pic%d",picno);
    jscratch=system(scratchstring);
    if(jscratch==SUCCESS){ fprintf(stderr,"Created pic%d.gif\n",picno);}
    else{
      fprintf(stderr,"**** Failed to create pic%d.gif\n",picno);
      fprintf(tth_fdout,"<br />Picture Not Created.<br />");
    }
    yy_pop_state();
  }
}
<picture>%%tt[hm]: 
<picture>{ANY}       {
  if(strcspn(yytext,"\n")==0) TTH_INC_LINE;
  fprintf(tth_picfile,"%s",yytext);
}
<discardgroup>\\begin\{picture\} {
  yy_push_state(discardgroup);
  if(tth_debug&32)fprintf(stderr,"Discarding unsupported construct:%s\n",yytext);
 }
<discardgroup>\\end\{picture\} {
  yy_pop_state();
  if(tth_debug&32)fprintf(stderr,"Ending discarding construct:%s\n",yytext);
 }
<discardgroup>.

 /***********************************************************************/
 /* Latex tabular and haligns */
\\begin\{tabular(\*|x)\}  TTH_TEX_FN("\\begin{tabular}#tthdrop1",1);
\\begin\{tabular\}  {
  TTH_TEX_FN_OPT("\\tth_tabular#tthdrop2",2,"");
}
<psub>\\tth_tabular#tthdrop2   {
  TTH_HAL_PUSH;
  *halstring=0;
  if((jscratch=indexkey("#2",margkeys,&margmax))!=-1){
    if(tth_debug&33) fprintf(stderr,"Tabular argument:%s> ",margs[jscratch]);
    yy_pop_state();
    TTH_SCAN_STRING("\\tth_endtabpre");
    TTH_SCAN_STRING(margs[jscratch]);
    rmdef(margkeys,margs,&margmax);       rmdef(margkeys,margs,&margmax); 
  }else fprintf(stderr,"**** Error: No tabular argument found.\n");
  if(tth_debug&33) fprintf(stderr,"Beginning tabular\n");
  if(!eqdepth)yy_push_state(disptab);  /* Prevent $$ from being display math.*/
  yy_push_state(tabpre);   /* Prescan the tabular argument.*/
  ncols=0;
}
<tabpre>{NL}   TTH_INC_LINE;
<tabpre>{TSP}   /*remove spaces*/
<tabpre>\|      TTH_CCAT(halstring,yytext);
<tabpre>c|l|r   TTH_CCAT(halstring,yytext);ncols++;
 /*
<tabpre>c|l|r   {
  TTH_CCAT(halstring,"&{&");
  TTH_CCAT(halstring,yytext);ncols++;
  TTH_CCAT(halstring,"&}&");
}*/
<tabpre>@   {  TTH_TEX_FN("\\tth_preat#tthdrop1",1); }
<psub>\\tth_preat#tthdrop1 {
  yy_pop_state();
  if((jscratch=indexkey("#1",margkeys,&margmax))!=-1){
    TTH_CCAT(halstring,"@{");
    TTH_CCAT(halstring,margs[jscratch]);
    TTH_CCAT(halstring,"}");
    if(tth_debug&32) fprintf(stderr,"@string copied =%s\n",margs[jscratch]);
    rmdef(margkeys,margs,&margmax);
  }
}
<tabpre>p    { TTH_TEX_FN("\\tth_presp#tthdrop1",1);ncols++; }
<psub>\\tth_presp#tthdrop1  {
  yy_pop_state();
  if((jscratch=indexkey("#1",margkeys,&margmax))!=-1){
    if(tth_debug&32) fprintf(stderr,"p-string =%s ",margs[jscratch]);
    TTH_CCPY(scratchstring,margs[jscratch]);
    TTH_CCAT(scratchstring,"\\tth_pfinish");
    TTH_SCAN_STRING(scratchstring);
    GET_DIMEN;
    rmdef(margkeys,margs,&margmax);
  }
}
<tabpre>\\tth_pfinish {
  /*  sprintf(scratchstring,"&{&p{%d}&}&",thesize/SCALEDPERPIXEL);*/
  sprintf(scratchstring,"p{%d}",thesize/SCALEDPERPIXEL);
  TTH_CCAT(halstring,scratchstring);
  if(tth_debug&1056) fprintf(stderr,"p-string copied=%s pixels for %d sp\n",
			   scratchstring,thesize);
}
<tabpre>\*    { TTH_TEX_FN("\\tth_tabstar#tthdrop2",2); }
<psub>\\tth_tabstar#tthdrop2 {
  yy_pop_state();
  if((jscratch=indexkey("#1",margkeys,&margmax))!=-1){
    if(tth_debug&32) fprintf(stderr,"*{%s} construct. ",margs[jscratch]);
    sscanf(margs[jscratch],"%d",&js2);
    if((jscratch=indexkey("#2",margkeys,&margmax))!=-1 ||
       js2>=1 || js2<255){
      if(tth_debug&32) fprintf(stderr,"Codes: %s\n",margs[jscratch]);
      for(js2++;js2>1;js2--){TTH_CCAT(halstring,margs[jscratch]);ncols++;}
      rmdef(margkeys,margs,&margmax);
    }else fprintf(stderr,"**** Error in tabular argument * number:%d\n",js2);
    rmdef(margkeys,margs,&margmax);
  }
}
<tabpre>{ANY}   if(strcspn(yytext,"\n")==0) TTH_INC_LINE;/* Do nothing if we don't recognize */ 
<tabpre>\\tth_endtabpre {
  yy_pop_state();
  TTH_PUSH_CLOSING;
  TTH_CCPY(closing,TTH_TABC);
  if(eqdepth) {/* equation case */
    TTH_EQA_PUSH;
    eqclose++;
    tophgt[eqclose]=0;
    levhgt[eqclose]=1;
    eqalignrow=0;
  }
  if(eqdepth && displaystyle) { /* only display equations.*/
    TTH_OUTPUT(TTH_CELL3);TTH_CCAT(closing,TTH_CELL3);
  }else {TTH_OUTPUT("\n");}
  if(*(halstring) == '|') {
    TTH_OUTPUT(TTH_TABB);
  }else{
    TTH_OUTPUT(TTH_TABO);
  }  /* Guess that if template starts '|' we want a boxed table, else not */
  *tdalign=0;*precell=0; /* Safety only; ought not to be needed */
  if(eqdepth)eqalignrow++;
  yy_push_state(hendline); /* check for multicol at start */
  TTH_PUSH_BUFF(0);halbuff=yy_scan_string(halstring); /* Setup halbuff */
  yy_switch_to_buffer(include_stack[--tth_stack_ptr]); 
  /* But keep current*/
  if(tth_debug&32)fprintf(stderr,"Endtabpre:%s>\n",halstring);
  if(!*halstring){
    fprintf(stderr,"**** Error Fatal. Null or improper alignment argument, line %d.\n",tth_num_lines);
    TTH_EXIT(3);
  }
 }

<talign>\|  { /* cell boundary. Scan @strings if any */
  if(tth_debug&32)fprintf(stderr,"|");
  jstal=-1;
  if(*precell && !jshal && *tdalign){ 
    strcat(precell,"&");
    *tdalign=0;
    yy_switch_to_buffer(include_stack[--tth_stack_ptr] );
    yy_pop_state();
    if(tth_debug&32){fprintf(stderr,"%s",precell);}
    TTH_SCAN_STRING(precell);*precell=0;
  } else if(jshal==1 || jshal==-1 ){
    TTH_HALACT;
  }
}
<talign>@  {
  /*  if(tth_debug&32) fprintf(stderr,"tth_@, %d\n",margmax);*/
  TTH_TEX_FN("\\tth_atstring#tthdrop1",1);
}
<psub>\\tth_atstring#tthdrop1 {
  yy_pop_state();
  if((jscratch=indexkey("#1",margkeys,&margmax))!=-1){
    if(jshal<1){
      TTH_CCAT(precell,"{");
      TTH_CCAT(precell,margs[jscratch]);
      TTH_CCAT(precell,"}");
      /*     if(tth_debug&32) fprintf(stderr,"@string=%s ",precell);*/
    }
    rmdef(margkeys,margs,&margmax);
  } /* Have to explicitly excape from macro
       because <<EOF>> not handled in talign */
  yy_delete_buffer( YY_CURRENT_BUFFER );
  yy_switch_to_buffer(include_stack[--tth_stack_ptr] );
}

<talign>c|r|l|p{BRCG}  {
  if(jshal==1||jshal==-1){yyless(0);} 
  if(jstal==-1)jstal=0;
  TTH_HALACT; 
}
<talign><<EOF>> {  /* Reset halbuff to start. Gives matrix underflows.
    yy_delete_buffer(YY_CURRENT_BUFFER);
    if(tth_debug&32)fprintf(stderr,"\nTemplate end rescan:%s> \n",halstring);
    halbuff=yy_scan_string(halstring);
    yy_switch_to_buffer(halbuff);  */
    TTH_HALACT; /*Old approach */
}
<talign>&   yy_push_state(tempamp);
<tempamp>&  {
  yy_pop_state();
  /*  if(tth_debug&32)fprintf(stderr,"%dprecell=%s\n",jshal,precell);*/
  /* if(jshal>0)*precell=0; don't now throw away */
}
<tempamp>\{|\}   {TTH_CCAT(precell,yytext);}
<tempamp>\\&|\\%  |   /* ensure ampersand does not escape */
<tempamp>{ANY} {
  if(strcspn(yytext,"\n")==0) TTH_INC_LINE;
  if(jshal<1){TTH_CCAT(precell,yytext);}
}
<talign>. fprintf(stderr,"Unknown tabular format: %s\n",yytext);TTH_HALACT;

<valign>&  TTH_SCAN_STRING("\\par");
<valign>\\cr(cr)? {
  fprintf(tth_fdout,"\n</td><td%s>",valignstring);
}
<valign>\\tthexitvalign  {
  yy_pop_state();
}

&   {
  if(*halstring) {yy_push_state(hamper); 
  }else{fprintf(tth_fdout,"</td><td width=\"%d\">\n",tabwidth);}/* settabs */
}
\\crcr      |
\\tth_halcr |   /* used for <equation> state. */ 
\\cr |
\\\\\*?{SP}*(\[[^\]]*\])?  {
  TTH_INC_MULTI;
  if(*halstring){ /* halign and tabular */
    if(jstal==0){
      jstal=1;
      jshal=-1;
      yyless(0);
      TTH_HALSWITCH;
    }else{
      jstal=0;
      TTH_OUTPUT(TTH_CELL_TAB);
      TTH_OUTPUT(TTH_TRC);
      if(eqdepth){
	if(tth_istyle&1)eqalignrow=eqalignrow+6*(levhgt[eqclose]-1)+TTH_HGT;else
	  eqalignrow=eqalignrow+levhgt[eqclose];
	if(tth_debug&2)fprintf(stderr,
	   "Halcr. eqalignrow=%d, eqaind=%d, levhgt=%d\n",
			       eqalignrow,eqaind,levhgt[eqclose]);
	levhgt[eqclose]=1;
      }
      yy_push_state(hendline);
      yy_delete_buffer(halbuff);  /* Reset halbuff to start */
      if(tth_debug&32)fprintf(stderr,"\nEOL rescan:%s> \n",halstring);
      TTH_PUSH_BUFF(0);halbuff=yy_scan_string(halstring);
      yy_switch_to_buffer(include_stack[--tth_stack_ptr]);
    }
  }else{
    if(*(yytext+1)=='c'){
      TTH_OUTPUT("</td></tr></table>\n"); /* settabs */
    }else{
      TTH_OUTPUT("<br />"); /* LaTeX Plain text line break */
    }
  }
}
<hamper>{NL}  TTH_INC_LINE;
<hamper>{TSP}*
<hamper>\\multicolumn   {
  if(tth_debug&32) fprintf(stderr,"\nInner Multicolumn(%d%d)",jshal,jstal);
  if(jstal==0){
    jstal=1;
    jshal=-1;
    yyless(0);
    yy_pop_state();TTH_SCAN_STRING("&");
    TTH_HALSWITCH;
  }else /**/{
    jstal=0;
    TTH_OUTPUT(TTH_CELL_TAB);
    TTH_TEX_FN("\\tth_multistart#tthdrop2",2); 
  }
} /* See psub below. */
<hamper>\\omit  TTH_SCAN_STRING("\\multispan1");
<hamper>\\multispan {
  if(tth_debug&32) fprintf(stderr,"Inner Multispan(%d%d)",jshal,jstal);
  if(jstal==0){
    jstal=1;
    jshal=-1;
    yyless(0);
    yy_pop_state();TTH_SCAN_STRING("&");
    TTH_HALSWITCH;
  }else{
      jstal=0;
      yy_pop_state();
      TTH_OUTPUT(TTH_CELL_TAB);
      TTH_TEX_FN("\\tth_multispan#tthdrop1",1); 
  }
} /* See psub below */
<hamper>\\[a-zA-Z@]+   { /* expand first */
  TTH_DO_MACRO
  else{ 
    yyless(0);
    strcpy(tdalign,TTH_CELL_TAB);  /* Save the cell closing.*/
    yy_pop_state();jshal=0;
    TTH_HALSWITCH;
  }
}
<hamper>. {
  yyless(0);
  strcpy(tdalign,TTH_CELL_TAB);  /* Save the cell closing.*/
  yy_pop_state();
  jshal=0;
  TTH_HALSWITCH;
}
<hendline>\\hline
<hendline>\\hline{WSP}*\\hline    TTH_INC_MULTI;TTH_OUTPUT(TTH_TRTD);
<hendline>\\cline{SP}*\{  yy_push_state(matchbrace);
<hendline>{TSP}
<hendline>{NL}  TTH_INC_LINE;

<hendline>\\multicolumn  {
  if(tth_debug&32) fprintf(stderr,"Multicolumn at start:");
  TTH_OUTPUT(TTH_TRO);
  TTH_TEX_FN("\\tth_multiinner#tthdrop2",2); 
}
 /* Add an open brace for a starting multicol */
<psub>\\tth_multiinner#tthdrop2  {
  /*TTH_SCAN_STRING("{");
    if(tth_debug&32){fprintf(stderr,"{");}*/
  TTH_SCAN_STRING("\\tth_multistart#tthdrop2");
}
<psub>\\tth_multistart#tthdrop2 {
  if((jscratch=indexkey("#1",margkeys,&margmax))!=-1){
    sscanf(margs[jscratch],"%d",&jshal);
  }else{fprintf(stderr,"No argument #1 in multicol\n");}
  if((jscratch=indexkey("#2",margkeys,&margmax))!=-1){
    strcpy(scrstring,margs[jscratch]);
    chscratch=scrstring+strcspn(scrstring,"lrcp"); /* No @strings allowed */
    strcpy(scratchstring,TTH_HALCODE(chscratch));
  }else{*scratchstring=0;fprintf(stderr,"No argument #2 in multicol\n");}
  if(tth_debug&32) fprintf(stderr,"%d,%s\n",jshal,scratchstring);
  sprintf(scrstring,TTH_MULSTART,jshal,scratchstring);
  TTH_OUTPUT(scrstring);
  if(eqdepth){TTH_OUTPUT(TTH_EQ5);}
  yy_pop_state();    yy_pop_state(); /* get out of hendline/hamper too */  
  rmdef(margkeys,margs,&margmax);rmdef(margkeys,margs,&margmax); 
  jshal++;/* fix */
  TTH_HALSWITCH;
 }
<hendline>\\end\{(tabular|array)(\*|x)?\} {
  TTH_TEXCLOSE else{
  if(tth_debug&32) fprintf(stderr,"Ending tabular\n");
  yy_delete_buffer(halbuff);
  yy_pop_state();
  TTH_HAL_POP;
  if(eqdepth){
    eqclose--;
    if(tth_istyle&1)jscratch=(eqalignrow+6*(levhgt[eqclose+1]-1)+TTH_HGT)/6; 
    else    jscratch=levhgt[eqclose+1]+eqalignrow;
    if(jscratch>levhgt[eqclose])levhgt[eqclose]=jscratch;
    /* This was an alternative attempt when \\ was forced. Height was broken.
      if(eqalignrow>levhgt[eqclose])levhgt[eqclose]=eqalignrow;*/
    if(tth_debug&2)fprintf(stderr,
	      "Equation Tabular Close: eqclose=%d, eqalignrow=%d, levhgt=%d\n",
			   eqclose,eqalignrow,levhgt[eqclose]);
    TTH_EQA_POP;
  }
  TTH_CLOSEGROUP;TTH_POP_CLOSING;
  if(!eqdepth)yy_pop_state(); /* the disptab we added */
} 
}
<hendline>\} {
  yy_pop_state(); /* out of hendline */
  TTH_TEXCLOSE else{
  if(!eqdepth){
    if(tth_push_depth==halignenter){
      TTH_HAL_POP;
    }
    TTH_CLOSEGROUP;TTH_POP_CLOSING;
  }else{ /* This for equation state should not happen */
    eqclose--;
    TTH_EQA_POP;
    yy_pop_state();yyless(0);
  }
}} /* end of halign. */
<hendline>.  {
  yyless(0); TTH_OUTPUT(TTH_TRO);
  yy_pop_state();
  jshal=0;
  TTH_HALSWITCH;
}

<hendline>\\noalign {/*attempt to fix*/
  if(tth_debug&33) fprintf(stderr,
	"Noalign in hendline. eqdepth=%d, ncols=%d.\n",eqdepth,ncols);
  sprintf(scrstring,"\\multicolumn{%d}{l}{#1}\\cr#tthdrop1",ncols);
  TTH_TEX_FN(scrstring,1);
}

<hendline>\\omit  TTH_SCAN_STRING("\\multispan1");
<hendline>\\multispan  {
  yy_pop_state();
  if(tth_debug&32) fprintf(stderr,"Line Start Multispan\n");
  TTH_TEX_FN("\\tth_multispan#tthdrop1",1); 
  TTH_OUTPUT(TTH_TRO);
}
<psub>\\tth_multispan#tthdrop1  {
  if((jscratch=indexkey("#1",margkeys,&margmax))!=-1)
    sscanf(margs[jscratch],"%d",&jshal);
  if(tth_debug&32) fprintf(stderr," %d",jshal);
  sprintf(scrstring,TTH_MULSPAN,jshal);
  TTH_OUTPUT(scrstring);
  yy_pop_state();
  rmdef(margkeys,margs,&margmax);
  jshal++;/* fix */
  TTH_HALSWITCH;
}
<hendline>\\[a-zA-Z@]+   { /* expand first */
  TTH_DO_MACRO
  else{
    yyless(0);TTH_OUTPUT(TTH_TRO);
    yy_pop_state();
    jshal=0;
    TTH_HALSWITCH;
  }
}
\\end\{tabular(\*|x)?\} yyless(0);TTH_SCAN_STRING("\\\\"); 

\\cline{SP}*\{  yy_push_state(matchbrace);
\\hline
\\hline{WSP}*\\hline    TTH_INC_MULTI;TTH_OUTPUT("</tr><tr><td>");
   /* End of tabular and halign code.*/
 /********************************************************************/

\\tiny{SP}*  	TTH_OUTPUT(TTH_TINY);TTH_PRECLOSE(TTH_SIZEEND);
\\scriptsize{SP}*     TTH_OUTPUT(TTH_SCRIPTSIZE);TTH_PRECLOSE(TTH_SIZEEND);
\\footnotesize{SP}*   TTH_OUTPUT(TTH_FOOTNOTESIZE);TTH_PRECLOSE(TTH_SIZEEND);
\\small{SP}*  	TTH_OUTPUT(TTH_SMALL);TTH_PRECLOSE(TTH_SIZEEND);
\\normalsize{SP}*   TTH_OUTPUT(TTH_NORMALSIZE);TTH_PRECLOSE(TTH_SIZEEND);
\\large{SP}*  	TTH_OUTPUT(TTH_large);TTH_PRECLOSE(TTH_SIZEEND);
\\Large{SP}*  	TTH_OUTPUT(TTH_Large);TTH_PRECLOSE(TTH_SIZEEND);
\\LARGE{SP}*  	TTH_OUTPUT(TTH_LARGE);TTH_PRECLOSE(TTH_SIZEEND);
\\(H|h)uge{SP}*   TTH_OUTPUT(TTH_HUGE);TTH_PRECLOSE(TTH_SIZEEND);

\\centering   fprintf(tth_fdout,"<div style=\"text-align:center\">");TTH_PRECLOSE("</div>");
\\raggedleft  fprintf(tth_fdout,"<div align=\"right\">");TTH_PRECLOSE("</div>");

 /* Insert an implied hbox around the minipage(s) that terminates at the
    next \par. Inside the minipages the state is not pargroup. Thus any
    \par inside the minipage does not terminate the hbox group.
 */
<pargroup>\\begin\{minipage\}  {
  yy_push_state(INITIAL);
  TTH_TEX_FN_OPT("\\vbox\\bgroup\\hsize=#2#tthdrop2",2,"");
}
\\begin\{minipage\}  {
  TTH_PUSH_CLOSING; /* This will be cancelled at the end of the pargroup*/
  yy_push_state(pargroup);
  yy_push_state(INITIAL);
  TTH_TEX_FN_OPT("\\tth_hbox\\vbox\\bgroup\\hsize=#2#tthdrop2",2,"");
}
\\end\{minipage\} {
  TTH_SCAN_STRING("\\egroup");
  yy_pop_state();
}

  /*Default Begin and End Are at end of flex code. */

 /* colordvi-compatible commands. Expand the argument first.*/
\\Color   TTH_TEX_FN("{\\textColor{#1}#2}#tthdrop2",2);
 /* textColor in colordvi is global. But that's a terrible thing to do 
    so in TtH it is local. */
\\textColor TTH_TEX_FN("\\edef\\tthexpcol{\\tthtextColor{#1}}\\tthexpcol#tthdrop1",1);
\\tthpageColor{BRCG}    |
\\tthbgColor{BRCG}      |
\\tthspecialcolor{BRCG} |
\\tthtextColor{BRCG} { /* Color defined in one of four ways*/
  chscratch=yytext+strcspn(yytext,"{")+1;
  *(chscratch+strcspn(chscratch,"}"))=0;
  if((jscratch=sscanf(chscratch,"%f %f %f %f",
		      &cyanc,&magentac,&yellowc,&blackc))<=2){
    if((jscratch=sscanf(chscratch,"%f , %f , %f , %f", /*Latex comma delimits*/
			&cyanc,&magentac,&yellowc,&blackc))<=2){
      if(jscratch == 1) { /* grey */
	redc=cyanc;
	greenc=cyanc;
	bluec=cyanc;
      }else if(jscratch==0 || jscratch==EOF){ /* Try a named color*/
	if((jscratch=indexkey(chscratch,keys,&nkeys))!=-1){
	  /* Custom color.*/    /*Substitute and scan again*/
	  TTH_CCPY(scratchstring,yytext);
	  *(scratchstring+strcspn(scratchstring,"{"))=0;
	  TTH_CCAT(scratchstring,defs[jscratch]); 
	  *(scratchstring+strcspn(scratchstring,"#"))=0; /* Fix end*/
	  TTH_SCAN_STRING(scratchstring);
	  jscratch=5;
	}else{ 
	  jscratch=tth_cmykcolor(chscratch,&cyanc,&magentac,&yellowc,&blackc);
	}
      }else{
	jscratch=0;
      }
    }
  }
  if(jscratch!=5){ /* For non custom colors*/
    if(jscratch==0){
      fprintf(stderr,"**** Unknown color specification %s\n",chscratch);
    }else if(jscratch==4){ /* Convert to RGB from CMYK*/
      if((redc=1.-cyanc-blackc)<0.) redc=0.;
      if((greenc=1.-magentac-blackc)<0.) greenc=0.;
      if((bluec=1.-yellowc-blackc)<0.) bluec=0.;
    }else if(jscratch==3){ /* It is RGB already */
      redc=cyanc;
      greenc=magentac;
      bluec=yellowc;
    }
    if(jscratch){
      sprintf(colorchar,"%2.2X%2.2X%2.2X",
	      (int)(redc*255),(int)(greenc*255),(int)(bluec*255));
      if(tth_debug&32)fprintf(stderr,"RGB=%f,%f,%f\ncolorchar=%s\n",
			      redc,greenc,bluec,colorchar);
      if(strstr(yytext,"tthbgC")){/*Box Background color case CSS*/
	sprintf(scratchstring,
		"\\special{html:\n<span style=\"background: #%s;\">}"
		,colorchar); 
	TTH_PRECLOSE("</span>");
      }else if(strstr(yytext,"tthpageC")){ /* Page color HTML violation*/
	sprintf(scratchstring,
		"\\special{html:<body bgcolor=\"#%s\">}",colorchar);       
      }else{
	sprintf(scratchstring,TTH_COLOR,colorchar); 
	/* if(!strstr(yytext,"tthspecial"))
	 Not  closing locally for the colordvi special case breaks stuff. */
	{TTH_PRECLOSE(TTH_COLOREND);}
      }
	TTH_SCAN_STRING(scratchstring);
    }
  }
}
 /* The specials that colordvi constructs for dvips for unknown colors. */
\\special{WSP}*\{color[ ]pop\}     TTH_INC_MULTI;
 /* TTH_OUTPUT(TTH_COLOREND); Remove because nesting gets broken */
\\special{WSP}*\{color([ ]push)?[ ][^\}]*\} {
  TTH_INC_MULTI;
  TTH_CCPY(scratchstring,"\\tthspecialcolor{");
  /* if(strstr(yytext,"push")){
    TTH_CCPY(scratchstring,"\\tthtextColor{");
    } */
  TTH_CCAT(scratchstring,(strrchr(yytext,' ')+1));
  TTH_SCAN_STRING(scratchstring);
}
 
 /* Latex graphics colors (see grfguide.ps). The syntax is confusingly the 
    exact opposite of colordvi, in that textcolor colorizes its argument
    but color is the switch. Use the preceding function anyway.*/
\\textcolor   TTH_TEX_FN_OPT("{\\textColor{#2}#3}#tthdrop3",3,"");
\\color TTH_TEX_FN_OPT("\\edef\\tthexpcol{\\tthtextColor{#2}}\\tthexpcol#tthdrop2",2,"");
\\colorbox TTH_TEX_FN_OPT("{\\edef\\tthexpcol{\\tthbgColor{#2}}\\tthexpcol #3}#tthdrop3",3,"");
\\fcolorbox TTH_TEX_FN_OPT("\\fbox{\\colorbox[#1]{#2}{#3}}#tthdrop3",3,"");
\\pagecolor TTH_TEX_FN_OPT("{\\edef\\tthexpcol{\\tthpageColor{#2}}\\tthexpcol}#tthdrop2",2,"");

\\renewcommand[*] |
\\newcommand[*]   |
\\providecommand[*] |
\\renewcommand |
\\newcommand   |
\\providecommand	{
  localdef=1;
  horizmode=0; /* This protection against \par should not be needed but ...*/
  yy_push_state(define);  
  yy_push_state(getnumargs);
  yy_push_state(getdef);
}
\\renewenviroment{BRCG} {
  fprintf(stderr,"**** %s: works only for non-standard environments\n",yytext);
  strcpy(scratchstring,"\\newenvironment");
  strcat(scratchstring,yytext+strcspn(yytext,"{"));
  TTH_SCAN_STRING(scratchstring);
}
\\newenvironment{BRCG} {
  localdef=0;
  horizmode=0;
  yy_push_state(getend);  /* will define the end environment, see following */
  yy_push_state(define);  /* defines the begin environment */
  yy_push_state(getnumargs);
  TTH_CCPY(defchar,"\\begin");
  strcat(defchar,strstr(yytext,"{"));
  *dupstore=0; /*does getdef*/
  TTH_PUSH_CLOSING;TTH_CCPY(closing,strstr(yytext,"{")); /* save for getend */
}
\\newtheorem{BRCG}\[[^\]]*\]{WSP}*{BRCG}  { 
  TTH_INC_MULTI;
  /* Newtheorem with numberedlike option. Overrides macro definition.*/
  if(tth_debug&4)fprintf(stderr,"New numbered-like theorem:%s\n",yytext);
  strcpy(scratchstring,strstr(yytext,"{")+1);
  strcpy(dupstore,strstr(scratchstring,"{"));
  *strstr(scratchstring,"}")=0;
  strcpy(scrstring,strstr(yytext,"[")+1);
  *strstr(scrstring,"]")=0;
  sprintf(dupstore2,"\\newenvironment{%s}{\\par\\stepcounter{%s}   \\textbf{%s \\arabic{%s}}\\bgroup \\em}{\\par\\egroup}",
	  scratchstring,scrstring,dupstore,scrstring);
  TTH_SCAN_STRING(dupstore2);
  *dupstore=0;
  *dupstore2=0;
}
<getend>. {
  yyless(0);yy_pop_state();
  yy_push_state(define);
  yy_push_state(getnumargs);
  TTH_CCPY(defchar,"\\end");strcat(defchar,closing);
  *dupstore=0; /*does getdef*/
  TTH_POP_CLOSING;
} /* end and beginning now defined. */

\| {
  if(indexkey("\\amslatex",keys,&nkeys)!=-1){
    TTH_SCAN_STRING("\\verb|");
  }else{
    TTH_OUTPUT(" - ");
  }
} 
 /* url that does not use braces */
\\url[^ \t\n\{]    |
  /*\\verb\*?[^ \t\na] { prior to 12 Jan 2002*/
\\verb\*?[^\t\na] {  /* Prevent erroneous \verbatim detection */
  if(tth_debug&8)fprintf(stderr,"Entering Verb state:%s\n",yytext);
  chr1[0]=*(yytext+strlen(yytext)-1);
  TTH_OUTPUT(TTH_TT1); yy_push_state(verb);
  TTH_PUSH_CLOSING;  TTH_CCPY(closing,TTH_TT2);
 }
 /* Deal with cases that are not in line.*/
\\verb TTH_TEX_FN("\\verb#1#tthdrop1",1);

 /* ************* Enclosing multiple groups in stuff. ******** removed **/

  /* **************Paragraphing closures.***************/
<parcheck>[ \t]*{NL}   {
  TTH_INC_LINE;yy_pop_state();TTH_SCAN_STRING("\\par\n");horizmode=1;}
<parcheck>.          {yyless(0);yy_pop_state();horizmode=1;}

<pargroup>{NL} {
  TTH_INC_LINE;
  if(horizmode==1){
    horizmode=-1;
    yy_push_state(parcheck);
    fprintf(tth_fdout,"%s",yytext);
  }else if(horizmode==-1) {
    fprintf(stderr,"**** Abnormal NL in -1 horizmode, pargroup\n");
    /* TTH_SCAN_STRING("\\par"); */
  }
}
<pargroup>\\par	  {
  TTH_TEXCLOSE else{
    TTH_CLOSEGROUP;TTH_POP_CLOSING;
    yy_pop_state();
    if(tth_eqwidth<100) tth_eqwidth=tth_eqwidth+TTH_INDPC;
    horizmode=0;/*{TTH_PAR_ACTION} not in pargroup?*/
  }
}
<pargroup>{SP}*\\item	 {
  TTH_TEXCLOSE else{ 
    if(!strcmp(closing,"</dd></dl>")) {
      /* Do not close the list or pop closing.*/
      fprintf(tth_fdout,"%s","</dd>\n <dt>\n");
    }else{ /* Have to close a different item */
      TTH_CLOSEGROUP; /* This a special case no POP_CLOSING */
      fprintf(tth_fdout,"<dl><dt>");
      TTH_CCPY(closing,"</dd></dl>");
      horizmode=0;/*{TTH_PAR_ACTION}*/
    }
    TTH_CCPY(argchar,"</dt>\n<dd>");yy_push_state(tokenarg);
  }
}
<pargroup>{SP}*\\itemitem    {
  TTH_TEXCLOSE else{
    if(!strcmp(closing,"</dd></dl></dl>")) {
      /* Do not close the list or pop closing.*/
      fprintf(tth_fdout,"%s","</dd><dt>\n");
    }else{ /* Have to close a different item */
      TTH_CLOSEGROUP; /* This a special case no POP_CLOSING */
      fprintf(tth_fdout,"<dl><dd><dl><dt>");
      TTH_CCPY(closing,"</dd></dl></dd></dl>");
      horizmode=0;
    }
    TTH_CCPY(argchar,"</dt><dd>\n");yy_push_state(tokenarg);
  }
}

<pargroup>\\hrule |    /* Implied \par commands */
<pargroup>\\(big|med|small)(skip|break) |
<pargroup>\\end  {
  sprintf(scratchstring,"\\par%s",yytext); TTH_SCAN_STRING(scratchstring);
}
  /* Fix for \hang and friends end of a vbox implies a par */
<pargroup>\}          |
<pargroup>\\endgroup  |
<pargroup>\\egroup    {
  if(strstr(closing,"--vbox")){
    TTH_SCAN_STRING("\\par}");
  }else{
    TTH_SCAN_STRING("\\tthparendgroup");
  }
}


<parclose>\\par {
  if(strstr(tth_texclose[tth_push_depth-1],"\\tthhbclose")){
    if(tth_debug&1024){
      fprintf(stderr,"Par in hhbc:%s\n",tth_texclose[tth_push_depth-1]);}
    yyless(0);TTH_SCAN_STRING(tth_texclose[tth_push_depth-1]);
    *tth_texclose[tth_push_depth-1]=0;
  }else{
    if(horizmode) {TTH_PAR_ACTION}
    else {fprintf(tth_fdout,"\n");}
  }
}  
<parclose>{NL} {
  TTH_CHECK_LENGTH;
  if(bracecount) fprintf(stderr,
			 "**** Error. Bracecount=%d nonzero, line %d\n",
			 bracecount,tth_num_lines);
  TTH_INC_LINE;
  if(horizmode==1){
    horizmode=-1;
    yy_push_state(parcheck);
    TTH_OUTPUT(yytext);
  }else if(horizmode==-1) {
    fprintf(stderr,"**** Abnormal NL in -1 horizmode, parclose\n");
  }
}

\\par     {
  if(horizmode) {
    {TTH_PAR_ACTION}
  } else {fprintf(tth_fdout,"\n");}
 }

{NL} {
  TTH_CHECK_LENGTH;
  if(bracecount) fprintf(stderr,"**** Error. Bracecount=%d nonzero, line %d\n",
			 bracecount,tth_num_lines);
  TTH_INC_LINE;
  if(horizmode==1){
    horizmode=-1;
    yy_push_state(parcheck);
    TTH_OUTPUT(yytext);
  }else if(horizmode==-1) {
    fprintf(stderr,"**** Abnormal NL in -1 horizmode.\n");
/*      {TTH_PAR_ACTION} */
  }
 }

 /*************************** General Rules. *****************/
\\beginsection	{
  TTH_PUSH_CLOSING; fprintf(tth_fdout,"\n<h2> ");
  TTH_CCPY(closing,"</h2>\n");
  yy_push_state(pargroup);tth_eqwidth=tth_eqwidth-TTH_INDPC;}
\\centerline	{
  TTH_OUTPUT("\n<table align=\"center\" border=\"0\"><tr><td>\n");
  TTH_CCPY(argchar,"</td></tr></table><!--hboxt-->");
  yy_push_state(tokenarg);
}
\\leftline	{
  fprintf(tth_fdout,"\n<br />");yy_push_state(tokenarg);
  TTH_CCPY(argchar,"<br />");}


<exptokarg,tokexp>\\underbar |
\\underbar   |
<exptokarg,tokexp>\\underline |
\\underline	TTH_SWAP("\\tth_underline ");
\\hrule(fill)?   yy_push_state(ruledim);TTH_OUTPUT("<hr />\n");
\\vrule          yy_push_state(ruledim);
\\bigbreak |
\\bigskip	{
  /*  if(horizmode) {fprintf(tth_fdout,TTH_PAR);horizmode=0;} replaced by*/
  if(horizmode) {{TTH_PAR_ACTION}}
  fprintf(tth_fdout,"<br /><br />");
}
\\medbreak |
\\medskip   	{
  if(horizmode) {{TTH_PAR_ACTION}}
  fprintf(tth_fdout,"<br />");
}
\\smallbreak |
\\goodbreak  |
\\smallskip 	{
  if(horizmode) {{TTH_PAR_ACTION}}
}

 /* Suck up prior whitespace to prevent paragraphs in lists*/
({WSP}*(%.*{NL}))*{WSP}*\\indexspace   {
  TTH_EXTRACT_COMMENT{TTH_INC_MULTI;TTH_OUTPUT("<br />");}
}
 /* Because of sucking up, this must be explicit. */
<Litemize,Lenumerate>({WSP}*(%.*{NL}))*{WSP}*\\itemsep {
  TTH_EXTRACT_COMMENT{GET_DIMEN;}
}
  /* Try a better job at sucking up whitespace before items. */
<Litemize,Lenumerate>({WSP}*(%.*{NL}))*{WSP}*\\item  {
  TTH_EXTRACT_COMMENT{    /* Fix tth-comment before item bug. */
    TTH_INC_MULTI;
    TTH_OUTPUT(closing);
    *closing=0;
    strcat(closing,"\n<div class=\"p\"><!----></div>\n");
    strcat(closing,"</li>\n");
    fprintf(tth_fdout,"\n<li>");
  }
}
 /* New approach to optional item argument. Don't try to grab the whole.*/
<Litemize,Lenumerate>({WSP}*(%.*{NL}))*{WSP}*\\item{WSP}*\[  {
  TTH_EXTRACT_COMMENT{    /* Fix tth-comment before item bug. */
    TTH_INC_MULTI;
    if(tth_htmlstyle&2){/* Strict xhtml doesn't allow text outside <li>*/
      TTH_OUTPUT(closing);
      *closing=0;
      strcat(closing,"\n<div class=\"p\"><!----></div>\n");
      strcat(closing,"</li>\n");
      fprintf(tth_fdout,"\n<li>");
      TTH_SCAN_STRING("\\tthnooutopt[");
    }else{
      fprintf(tth_fdout,"\n<br />");
      TTH_SCAN_STRING("\\tthoutopt[");
    }
  }
}
<Litemize,Lenumerate>\\subitem  fprintf(tth_fdout,"<br />&nbsp;&nbsp;&nbsp;&nbsp;");
<Litemize,Lenumerate>\\subsubitem  fprintf(tth_fdout,"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
<Ldescription>{WSP}*\\item[^ [] { /* Space might not mean no opt. */ 
  /* If we can immediately detect absence of opt arg. Don't put dt section*/
  TTH_INC_MULTI;
  jscratch=strlen(yytext)-1; /*circumlocution necessary*/
  yyless(jscratch); 
  TTH_OUTPUT(closing); strcpy(closing,"</dd>\n");
  fprintf(tth_fdout,"\n\t<dd>");
  tth_index_line++;
}
<Ldescription>({WSP}*(%.*{NL}))*{WSP}*\\item{SP}* { /* If opt arg absent just gives null dt*/
  TTH_EXTRACT_COMMENT{    /* Fix tth-comment before item bug. */
  TTH_INC_MULTI;
  TTH_OUTPUT(closing); strcpy(closing,"</dd>\n");
  TTH_TEX_FN_OPT("\\special{html: <dt><b>}#1\\special{html:</b></dt>\n\t<dd>}#tthdrop1",1,"");
  tth_index_line++;
  }
}
<Ldescription>({WSP}*(%.*{NL}))*{WSP}*\\subitem  {
  TTH_EXTRACT_COMMENT{    /* Fix tth-comment before item bug. */
  TTH_INC_MULTI;
  TTH_OUTPUT(closing); strcpy(closing,"</dd>\n");
  fprintf(tth_fdout,"<dd>&nbsp;&nbsp;&nbsp;&nbsp;");
  tth_index_line++;
  }
}
<Ldescription>({WSP}*(%.*{NL}))*{WSP}*\\subsubitem  {
  TTH_EXTRACT_COMMENT{    /* Fix tth-comment before item bug. */
  TTH_INC_MULTI;
  TTH_OUTPUT(closing); strcpy(closing,"</dd>\n");
  fprintf(tth_fdout,"<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  tth_index_line++;
  }
}
\\item		{
  fprintf(tth_fdout,"%s","\n<dl>\n <dt>\n");TTH_PUSH_CLOSING;
  TTH_CCPY(closing,"</dd></dl>");
  TTH_CCPY(argchar,"</dt>\n<dd>\n");
  yy_push_state(pargroup);tth_eqwidth=tth_eqwidth-TTH_INDPC;
  yy_push_state(tokenarg); /* item code */
 }
\\itemitem	{
  fprintf(tth_fdout,"\n<dl><dd><dl><dt>");TTH_PUSH_CLOSING;
  TTH_CCPY(closing,"</dd></dl></dd></dl>");
  TTH_CCPY(argchar,"</dt><dd>");
  yy_push_state(pargroup);tth_eqwidth=tth_eqwidth-TTH_INDPC;
  yy_push_state(tokenarg); /* itemitem code */
}
\\((mid)|(top)|(page))insert	{TTH_PUSH_CLOSING;fprintf(tth_fdout,"\n<br />");}
\\endinsert  {
  TTH_TEXCLOSE else{
    TTH_CLOSEGROUP;TTH_POP_CLOSING;fprintf(tth_fdout,"\n<br />");}
}

\\footnote{SP}*(\[[0-9]*\])?     {  /* Now using embracetok Sep 98*/
  ftntno++;
  tth_encode(ftntcode,ftntno);
  if(tth_LaTeX){ /* convert to plain TeX form */
    if((chscratch=strstr(yytext,"["))){ /* optional argument case */
      strcpy(scratchstring,chscratch+1);
      *(scratchstring+strcspn(scratchstring,"]"))=0;
      sprintf(dupstore,"{$^{%s}$}",scratchstring);
      ftntno--;
      sscanf(scratchstring,"%d",&js2);
      tth_encode(ftntcode,js2);
    }else{
      sprintf(dupstore,"{$^{%d}$}",ftntno);
    }
  }
  if(tth_splitfile)sprintf(scratchstring,"<a href=\"footnote.html#tthFtNt%s\" id=\"tthFref%s\">",ftntcode,ftntcode);else /*sf*/
  sprintf(scratchstring,
	  "<a href=\"#tthFtNt%s\" id=\"tthFref%s\">",ftntcode,ftntcode);
  TTH_OUTPUT(scratchstring);
  bracecount--;
  TTH_CCPY(argchar,"\\tth_footnote");
  storetype=3;             /* Make argchar to be rescanned */
  yy_push_state(dupgroup); /* Puts in anchors */
  yy_push_state(embracetok);
}

\\tth_footnote { /* xdef footnote with reference.*/
  if(tth_debug&4) fprintf(stderr,"tthfootnote, dupstore=%s\n",dupstore);
  TTH_OUTPUT("</a>");  /* end the anchors */
  sprintf(newcstr,
	  "\\xdef\\tthFtNt%s{\\tthhref{%s#tthFref%s}{#1}{#2}\\end}#tthdrop2",
	  ftntcode,filechar,ftntcode);
  TTH_TEX_FN(newcstr,2);
  }

\\tth_uppercase {
  yy_push_state(uppercase);
  tth_push_depth--;
  TTH_PRETEXCLOSE("\\tth_endupper");
  tth_push_depth++;
}
<uppercase>[a-z]*     {
  for(jscratch=0;jscratch<strlen(yytext);jscratch++) {
    *(yytext+jscratch)=toupper(*(yytext+jscratch));}
  TTH_OUTPUTH(yytext);horizmode=1;
 }
<uppercase>\"[a-z]   |
<uppercase>\\(\'|\`|\"|\^|\~)[a-z] {
  *(yytext+strlen(yytext)-1)=toupper(*(yytext+strlen(yytext)-1));
  TTH_SCAN_STRING(yytext);
}

\\halign{SP}*to{SP}*\\hsize{WSP}*\{  |
\\halign{WSP}*\{	{
  TTH_INC_MULTI;
  yy_push_state(htemplate);
  *scratchstring=0;
  /*  strcpy(scrstring,"&{"); */
  strcpy(scrstring,"&");
  ncols=0;
  TTH_PUSH_CLOSING;
  TTH_CCPY(closing,"</table>\n");
  TTH_HAL_PUSH;
  *halstring=0;
  halignenter=tth_push_depth; 
 }
<htemplate>\\vrule  {
 strcpy(scratchstring," border=\"1\"");
 TTH_CCAT(scrstring,yytext);
}
 /* Add template interpretation into && strings and alignment.*/
<htemplate>& {
  TTH_CCAT(halstring,tdalign);
  /*  TTH_CCAT(scrstring,"}&|");  */
  TTH_CCAT(scrstring,"&|");  
  TTH_CCAT(halstring,scrstring);
  /*  strcpy(scrstring,"&{");*/
  strcpy(scrstring,"&");
  /*TTH_CCAT(scrstring,"&|");  
  if(strlen(scrstring)>3){
    TTH_CCAT(halstring,scrstring);
  }else {TTH_CCAT(halstring,"|");}
  strcpy(scrstring,"&"); Old version */
  *tdalign=0;
  js2=ncols; /* signifies that we are in the first part of the cell */
} 
<htemplate>\\(hfill?|hss) {
  if(*tdalign==0) {
    strcpy(tdalign,"r"); 
  } else if(ncols!=js2){
    if(*tdalign=='r') strcpy(tdalign,"c"); else strcpy(tdalign,"l");
    yy_push_state(removespace);
  }
}
<htemplate>#       {
  ncols++;
  TTH_CCAT(scrstring,"&");
  if(strlen(scrstring)>2){TTH_CCAT(halstring,scrstring);}
  strcpy(scrstring,"&");
  if(!*tdalign) strcpy(tdalign,"l");
}
<htemplate>\\#|\\&|\\% |
<htemplate>\n TTH_INC_LINE;TTH_CCAT(scrstring,yytext);
<htemplate>.  TTH_CCAT(scrstring,yytext);
<htemplate>\\cr  { /* New version uses the scanning of template. */
  /*
  TTH_CCAT(scrstring,"&");  
  TTH_CCAT(halstring,tdalign);
  if(strlen(scrstring)>2)  {TTH_CCAT(halstring,scrstring);}
  */
  /*  TTH_CCAT(scrstring,"}&");  */
  TTH_CCAT(scrstring,"&");  
  TTH_CCAT(halstring,tdalign);
  TTH_CCAT(halstring,scrstring);
  if(tth_debug&32)fprintf(stderr,"halign format string:%s> ",halstring);
  *tdalign=0;*dupstore=0;
  yy_pop_state();
  yy_push_state(hendline); /* check for multicol at start */
  TTH_PUSH_BUFF(0);halbuff=yy_scan_string(halstring); /* Setup halbuff */
  yy_switch_to_buffer(include_stack[--tth_stack_ptr]); 
  fprintf(tth_fdout,"\n<table%s>",scratchstring);
}

 /*  end of halign and htemplate */

 /*  Hack of valign allowing only one row . */
\\valign{WSP}*\{	{
  TTH_INC_MULTI;
  yy_push_state(valign);
  yy_push_state(vtemplate);
  *valignstring=0;
  valsec=0;
  TTH_PRETEXCLOSE("\\tthexitvalign");
  TTH_PUSH_CLOSING;
  TTH_CCPY(closing,"</td></tr></table>\n");
 }

<vtemplate>#       valsec++;
<vtemplate>\\(vfill?|vss) {
  if(valsec){
    if(*valignstring){
      TTH_CCPY(valignstring," valign=\"middle\"");    
    }else{
      TTH_CCPY(valignstring," valign=\"top\"");
    }
  }else{
    TTH_CCPY(valignstring," valign=\"bottom\"");
  }
}
<vtemplate>\\cr {
  fprintf(tth_fdout,"\n<table class=\"tabular\"><tr><td%s>",valignstring);
  yy_pop_state();
}    


<textsc>\\tth_endsmallcaps              |
<uppercase>\\tth_endupper		{
  yy_pop_state();
}
   /* altered approach to input*/
\\@input   |
\\include  |
\\input	      yy_push_state(inputfile);yy_push_state(removespace); 
<inputfile><<EOF>>  TTH_SCAN_STRING(" \\tth_eof");
<inputfile>{CMNT} |
<inputfile>{NL} TTH_INC_LINE;TTH_SCAN_STRING(" ");
<inputfile>\}   |
<inputfile>{TSP}*   {
    if ( tth_stack_ptr >= MAX_INCLUDE_DEPTH )
      {
      fprintf(stderr, "**** Error: Fatal. Includes nested too deeply. Line %d\n",tth_num_lines);
      TTH_EXIT( 1 );
    }
  if(tth_allowinput){
    strcpy(scratchstring,input_filename);
    if( (tth_inputfile=TTH_FILE_OPEN(scratchstring)) == NULL){
      strcat(scratchstring,".tex");
      if ( (tth_inputfile=fopen(scratchstring,"r")) == NULL){
	if(strlen(tth_texinput_path) > 0){
	  chscratch=tth_texinput_path;
	  while(strlen(chscratch)){
	    if((js2=strcspn(chscratch,PATH_SEP))){
	      strcpy(scratchstring,chscratch);
	      strcpy(scratchstring+js2,DIR_SEP);
	      strcat(scratchstring,input_filename);
	      if(tth_debug&128)
		fprintf(stderr,"Input try file:%s\n",scratchstring);
	      chscratch=chscratch+js2;
	      chscratch=chscratch+strspn(chscratch,PATH_SEP);
	      if ( (tth_inputfile=fopen(scratchstring,"r")) == NULL){
		strcat(scratchstring,".tex");
		tth_inputfile=fopen(scratchstring,"r");
	      }
	    }else{++chscratch;}
	    if(tth_inputfile)break;
	  }
	}
      }
    }
    if(tth_inputfile){
      if(tth_debug&1) fprintf(stderr,"Input file: %s\n",scratchstring);
      sprintf(scrstring,"\\tth_fileclose%p ",tth_inputfile);
      TTH_SCAN_STRING(scrstring);
      include_stack[tth_stack_ptr++] = YY_CURRENT_BUFFER;
      yy_switch_to_buffer(yy_create_buffer( tth_inputfile, YY_BUF_SIZE));
    }else{
      fprintf(stderr,"Input file %s not found\n",input_filename);
    }
  }else{
    fprintf(stderr,"Input of file %s not allowed.\n",input_filename);
  }
  *input_filename=0;
  yy_pop_state();
 }
<inputfile>\{  
<inputfile>.  TTH_CCAT(input_filename,yytext);
  /* Specific internal commands to expand in inputfile */
<inputfile>\\jobname   TTH_SCAN_STRING(tth_latex_file);
<inputfile>\\[a-zA-Z@]+ {
  TTH_DO_MACRO
    else{
      TTH_CCAT(input_filename,yytext);
    }
}

<verbatim,notags>\\tth_fileclose[^ ]*[ ] |
\\tth_fileclose[^ ]*[ ] {
#ifdef MSDOS
    /* pointer reading is broken in DJGPP */
  sscanf(yytext,"\\tth_fileclose%x ",&tth_inputfile);
#else
  sscanf(yytext,"\\tth_fileclose%p ",&tth_inputfile);
#endif
  if(!fclose(tth_inputfile)) {
    if(tth_debug&1){
      fprintf(stderr,"Closing %s.\n",yytext);
    }
  }else{ 
    fprintf(stderr,"**** Error closing %s. ",yytext);
    fprintf(stderr," Apparent file pointer:%p.\n",tth_inputfile);
  }
  
  tth_inputfile=NULL;
} 

\\font{SP}*\\[^ \t\r\n=]*[ \t\r\n=]*[^ \t\r\n%]*{WSP}*(((at{WSP}*{NUM}{WSP}*(true{SP}*)?pt)|(scaled[ \t\r\n\\]*[^ \t\r\n\\%]*)){NL}?)? {
  TTH_INC_MULTI;
 if(tth_fontguess){/* Try to guess what size etc is being called for. */
  strcpy(scratchstring,yytext);
  jscratch=0;
  js2=0;
  if(tth_debug&2048)fprintf(stderr,"Font definition start:%s\n",scratchstring);
  if((chscratch=strstr(scratchstring," at ")) != NULL){ /* at NNpt */
    chscratch=chscratch+4+strspn(chscratch+4," ");
    if(strspn(chscratch,"0123456789")){
      *(chscratch+strspn(chscratch,"0123456789"))=0;
      sscanf(chscratch,"%d",&js2);
      jscratch=(js2-10)/2;
    }
  }
  if(!js2){  /* No "at", Guess scaled */
    if((chscratch=strstr(scratchstring,"\\magstep")) != NULL){
      if(strspn(chscratch+8,"1234567890")){
	*(chscratch+8+strspn(chscratch+8,"1234567890"))=0;
	sscanf(chscratch+8,"%d",&jscratch);
	*chscratch=0;
      }
    }
    if(strcspn(scratchstring,"123456789") != strlen(scratchstring)){
      sscanf(scratchstring+strcspn(scratchstring,"123456789"),"%d",&js2);
      jscratch=jscratch + (js2-10)/2; /* Approx */
      *(scratchstring+strcspn(scratchstring,"123456789"))=0;
    }
  }
  chscratch=strstr(scratchstring+1,"\\");
  chscratch=chscratch+strcspn(chscratch," =");
  if(strstr(chscratch,"mb") != NULL) strcpy(defstore,"\\rmfamily\\bf");
  else if(strstr(chscratch,"mr") != NULL) strcpy(defstore,"\\rmfamily");
  else if(strstr(chscratch,"mssb") != NULL) strcpy(defstore,"\\sffamily\\bf");
  else if(strstr(chscratch,"mssi") != NULL) strcpy(defstore,"\\sffamily\\it");
  else if(strstr(chscratch,"mss") != NULL) strcpy(defstore,"\\sffamily ");
  else if(strstr(chscratch,"msl") != NULL) strcpy(defstore,"\\rmfamily\\it");
  else if(strstr(chscratch,"mi") != NULL) strcpy(defstore,"\\rmfamily\\it");
  else if(strstr(chscratch,"mtti") != NULL) strcpy(defstore,"\\ttfamily\\it");
  else if(strstr(chscratch,"mttb") != NULL) strcpy(defstore,"\\ttfamily\\bf");
  else if(strstr(chscratch,"mtt") != NULL) strcpy(defstore,"\\upshape\\ttfamily");
  else *defstore=0;
  switch(jscratch){
  case 1: strcat(defstore,"\\large ");break;
  case 2: strcat(defstore,"\\Large ");break;
  case 3: strcat(defstore,"\\LARGE ");break;
  case 4: case 5: case 6: case 7: case 8: strcat(defstore,"\\huge ");break;
  case -1: strcat(defstore,"\\small ");break;
  case -2: strcat(defstore,"\\footnotesize ");break;
  case -3: strcat(defstore,"\\scriptsize ");break;
  case -4: case -5: case -6:  strcat(defstore,"\\tiny ");break;
  default : strcat(defstore,"\\normalsize ");break;
  }  
  chscratch=strstr(scratchstring+1,"\\");
  *(chscratch+strcspn(chscratch," ="))=0;
  sprintf(dupstore,"\\def%s{%s}",chscratch,defstore);
  if(tth_debug&2048)fprintf(stderr,"Font definition:%s\n",dupstore);
  *defstore=0;
  TTH_SCAN_STRING(dupstore);
  *dupstore=0;
 }else 	fprintf(tth_fdout," ");
}
 /* Latex counters etc.*/
\\newcounter{WSP}*\{[a-zA-Z@]*\}  {
  TTH_INC_MULTI;
  sprintf(newcstr,"\\tth_newcounter%s",strstr(yytext,"{"));
  TTH_TEX_FN_OPT(newcstr,1,""); 
  /* This does not work using scratchstring. Need a permanent String*/
}
<psub>\\tth_newcounter\{[a-zA-Z@]*\} {
  if(tth_debug&4)fprintf(stderr,"Newcounter: %s\n",yytext);
  strcpy(dupstore2,"\\");strcat(dupstore2,yytext+strcspn(yytext,"{")+1);
  *(strstr(dupstore2,"}"))=0;
  mkkey(dupstore2,countkeys,&ncounters);
  if(tth_debug&4) fprintf(stderr,"Created new counter %s\n",dupstore2);
  sprintf(scratchstring,"\\gdef\\the%s{\\arabic{%s}}",dupstore2+1,dupstore2+1);
  strcpy(scrstring,yytext);
  TTH_SCAN_STRING(scratchstring);
  /* New using opt arg.*/
  if((jscratch=indexkey("#1",margkeys,&margmax))!=-1){
    sprintf(scratchstring,"\\%s",margs[jscratch]);
    yy_pop_state();
    rmdef(margkeys,margs,&margmax);
  }
  if(strlen(scratchstring)>1){
    if((ind=indexkey(scratchstring,countkeys,&ncounters)) != -1){
      *scrstring=0;
      i=ind;
      if(countwithins[ind]){
	strcpy(scrstring,countwithins[i]);
	i++;
	rmkey(countwithins,&i);
      }
      strcat(scrstring,dupstore2+1);
      strcat(scrstring,",");
      mkkey(scrstring,countwithins,&i);
      if(tth_debug&4)fprintf(stderr,"Added %s to withins of %s:%s\n",
			     dupstore2+1,scratchstring,scrstring);
    }else{
     fprintf(stderr,"**** Error: No such counter for \"within\" option: %s. Line %d\n",
	     scratchstring,tth_num_lines);
    }
  }
  *dupstore2=0;
  if(horizmode)horizmode=1;
 }
\\setcounter{WSP}*\{[a-zA-Z]*\}{WSP}*\{({NUM}|{SP}*\\value\{[a-zA-Z]*\}{SP}*)\}  {
  TTH_INC_MULTI;
  if(tth_debug&4)fprintf(stderr,"Setcounter: %s\n",yytext);
  yytext=yytext+strcspn(yytext,"{");
  TTH_CCPY(argchar,yytext);*(argchar+strcspn(argchar,"}"))=0;
  *(argchar)='\\';
  if((ind=indexkey(argchar,countkeys,&ncounters)) != -1){
    yy_push_state(counterset);
    if((chscratch=strstr(yytext,"\\value")) != NULL){
      strcpy(dupstore2,(chscratch+6));
      *dupstore2='\\';
    }else{
      strcpy(dupstore2,yytext+1+strcspn(yytext+1,"{")+1);
    }
    *(dupstore2+strcspn(dupstore2,"}"))=0;
    TTH_SCAN_STRING(dupstore2);
    *dupstore2=0;
  }else fprintf(stderr,"**** No counter: %s to set. Line %d\n",argchar,tth_num_lines);
  *argchar=0;
 }
\\addtocounter  iac=-1;yy_push_state(advance);  yy_push_state(removespace);
\\(arabic|alph|Alph|roman|Roman)\{[a-zA-Z]+\} {
  if(strstr(yytext,"alph")) jscratch=1;
  else if(strstr(yytext,"Alph")) jscratch=2;
  else if(strstr(yytext,"roman")) jscratch=3;
  else if(strstr(yytext,"Roman")) jscratch=4;
  else jscratch=0;
  if((chscratch=strstr(yytext,"{"))!=NULL) yytext=chscratch;
  else yytext=yytext+3;
  if((chscratch=strstr(yytext,"}"))!=NULL) *chscratch=0;
  *yytext='\\';
  TTH_SCAN_STRING(yytext);
  yy_push_state(number);if(horizmode)horizmode=1;
 }
\\stepcounter{WSP}*\{[a-zA-Z]*\} {
  TTH_INC_MULTI;
  strcpy(scratchstring,yytext+strcspn(yytext,"{"));
  *scratchstring='\\';
  *(scratchstring+strlen(scratchstring)-1)=0;
  if((ind=indexkey(scratchstring,countkeys,&ncounters)) != -1){
    strcpy(dupstore2,"\\addtocounter");
    strcat(dupstore2,yytext+strcspn(yytext,"{"));
    strcat(dupstore2,"{1}");
    if(countwithins[ind]){
      strcpy(scrstring,countwithins[ind]);
      chscratch=scrstring;
      while((chs2=strstr(chscratch,",")) != NULL){
	*chs2=0;
	sprintf(dupstore2+strlen(dupstore2),"\\setcounter{%s}{0}",chscratch);
	chscratch=chs2+1;
      }
    }
    if(tth_debug&4) fprintf(stderr,"Stepping counter:%s\n",dupstore2);
    TTH_SCAN_STRING(dupstore2);
  }else{
    fprintf(stderr,"**** No counter:%s to step. Line %d\n",scratchstring,tth_num_lines);
  }
  *dupstore2=0;if(horizmode)horizmode=1;
 }
\\@addtoreset({WSP}*\{[a-zA-Z]*\}){2} {
  TTH_INC_MULTI;
  chscratch=yytext+strcspn(yytext,"{")+1;
  chs2=chscratch+strcspn(chscratch,"{")+1;
  *(chscratch+strcspn(chscratch,"}"))=0;
  *(chs2+strcspn(chs2,"}"))=0;
  strcpy(scratchstring,"\\");
  strcat(scratchstring,chs2);
  if((ind=indexkey(scratchstring,countkeys,&ncounters)) != -1){
    *scrstring=0;
    i=ind;
    if(countwithins[ind]){
      strcpy(scrstring,countwithins[i]);
      rmkey(countwithins,&i);
      i++;
    }
    strcat(scrstring,chscratch);
    strcat(scrstring,",");
    mkkey(scrstring,countwithins,&i);
    if(tth_debug&4)fprintf(stderr,"Added %s to withins of %s:%s\n",
			 chscratch,scratchstring,scrstring);
  }else{
    fprintf(stderr,"**** Error: No such counter for \"within\" option: %s. Line %d\n",
	    scratchstring,tth_num_lines);
  }
}
 
 /* TeX counters */
\\newcount   {
  if(horizmode)horizmode=1;yy_push_state(getcount);yy_push_state(removespace);}
<getcount>\\[a-zA-Z]+ {
  mkkey(yytext,countkeys,&ncounters);yy_pop_state();
 }
<getcount>.  fprintf(stderr,"Ill-formed newcount");yy_pop_state();


\\advance     {iac=-1;yy_push_state(advance);if(horizmode)horizmode=1;}

<advance>{WSP}*    TTH_INC_MULTI;

 /*
<advance>\\[a-zA-Z]+((margin)|(width)|(height)|(size)|(offset)|(indent)){SP}*(by)?    { 
  TTH_INC_MULTI;
  if(tth_debug&4) fprintf(stderr,"Removing dimension advance: %s\n",yytext);
  yy_pop_state();
  GET_DIMEN;
 } Override the real command */

<advance>\{[a-zA-Z]*\}{WSP}*\{(({NUM})|({SP}*\\value\{[a-zA-Z]*\}{SP}*))\} {
  /* Latex addtocounter. Convert into plain form. */
  TTH_INC_MULTI;
  *yytext='\\';
  *(yytext+strcspn(yytext,"}"))=' ';
  *(yytext+strcspn(yytext,"{"))=' ';
  *(yytext+strlen(yytext)-1)=0;
  if((chscratch=strstr(yytext,"\\value")) != NULL){
    strcpy(chscratch,"      ");
    *(chscratch+6)='\\';
    *(chscratch+strcspn(chscratch,"}"))=0;
  }
  if(tth_debug&4)fprintf(stderr,"Latex advance string:%s\n",yytext);
  TTH_SCAN_STRING(yytext);
}

<advance,dimadv>by
<advance>\\tthdimen[ ]?\\[a-zA-Z]+ {/* Dimension advancing: get counter name.*/
  chscratch=yytext+strlen("\\tthdimen");
  strcpy(newcstr,chscratch+strspn(chscratch," "));
  yy_pop_state();
  yy_push_state(dimadv); /* Prepare to get second and advance. */
  dimadvstate=0;
  GET_DIMEN;
  if(tth_debug&1024)fprintf(stderr,"Advancing %s\n",newcstr);
}

<dimadv>.|\n {
  yyless(0);
  if(!dimadvstate){ /* Return of first time we have the first num,unit. */
    cnumber=anumber;
    strcpy(scrstring,scratchstring);
    GET_DIMEN;
    dimadvstate=1;
  }else{
    if(tth_debug&1024)fprintf(stderr,"Adding: %f %s, %f %s\n",
			      cnumber,scrstring,anumber,scratchstring);
    adddimen(&cnumber,scrstring,&anumber,scratchstring);
    if(*scrstring=='%')strcpy(scrstring,"\\tth_hsize");
    yy_pop_state();
    sprintf(scratchstring,"%s %f%s",newcstr,cnumber,scrstring);
    if(tth_debug&1024)fprintf(stderr,"Dimension advance string:%s\n",scratchstring);
    TTH_SCAN_STRING(scratchstring);
    dimadvstate=0;
  }
}


<advance>[+-]+ {
  if(strcspn(yytext,"-") < strlen(yytext)) minus=-1;
}             
<advance>{NUM}             |
<advance>\\[a-zA-Z]+  {
  if(iac==-1){ /* First time we are getting the one to set */ 
    iac=indexkey(yytext,countkeys,&ncounters);
    if(tth_debug&4) fprintf(stderr,"First advance:%s: %d, currently: %d.\n",
	    yytext,iac,counters[iac]);
    if(iac == -1) {
      TTH_DO_MACRO else{
	if(!(tth_debug&32768))
	  fprintf(stderr,"**** Unknown counter to advance: %s\n",argchar);
	yy_pop_state();
	GET_DIMEN;
      }
    } else {
      strcpy(argchar,yytext);
    }
  }else{
    if(tth_debug&4) fprintf(stderr,"Advancing counter %d, %s by %s. "
			    ,iac,argchar,yytext);
    if(strcspn(yytext,"0123456789") < strlen(yytext)){
      sscanf(yytext+strcspn(yytext,"+-0123456789"),"%d",&jac);
      counters[iac]=counters[iac]+jac*minus;
      jac=0;
    } else {
      TTH_CCPY(newcstr,yytext+strcspn(yytext,"\\"));
      jac=indexkey(newcstr,countkeys,&ncounters);
      if(jac == -1) {
	TTH_DO_MACRO else{
	  if(!(tth_debug&32768))
	    fprintf(stderr,"**** Unknown counter: %s\n",newcstr);
	  jac=-2; /* Quit. Expansion is exhausted. */
	}
      } else {
	if(strcspn(yytext,"-") == strlen(yytext)) {
	  counters[iac]=counters[iac]+minus*counters[jac];
	}else{
	  counters[iac]=counters[iac]-minus*counters[jac];
	}
      }
    }
    if(jac!=-1){
      minus=1;
      yy_pop_state();
      if(tth_debug&4) fprintf(stderr,"New counter value=%d\n",counters[iac]);
      *argchar=0;
    }
  }
}
<advance>.   {
  fprintf(stderr,"**** Error. Ill-formed \\advance statement\n");
  yy_pop_state();
}

<getifnum>\\value{WSP}*\{[a-zA-Z]*\} |
\\value{WSP}*\{[a-zA-Z]*\} {
  chscratch=strstr(yytext,"{");
  strcpy(scratchstring,chscratch);
  *(scratchstring+strcspn(scratchstring,"}"))=0;
  *(scratchstring)='\\';
  TTH_SCAN_STRING(scratchstring);    
  }

<exptokarg>\\number{SP}* | /* Needed for unembraced ^\the\counter*/   
<exptokarg>\\the{SP}* |
\\the{SP}* |        /*Pretend the is number. It is the same for counters.*/
\\number{SP}*     yy_push_state(number);jscratch=0;
<number>\\[a-zA-Z]+   {
  i=indexkey(yytext,countkeys,&ncounters);
  if(i == -1) {
    TTH_DO_MACRO else {
      if(!(tth_debug&32768))
	fprintf(stderr,"**** Unknown counter for number, %s\n",yytext);
      yy_pop_state();
    }
  } else {
    switch(jscratch){ 
    case 0: sprintf(dupstore2,"%d",counters[i]);break;
    case 1: sprintf(dupstore2,"%c",counters[i]+96);break;
    case 2: sprintf(dupstore2,"%c",counters[i]+64);break;
    case 3: roman(counters[i],dupstore2);break;
    case 4: roman(counters[i],dupstore2);
      for(js2=0;js2<strlen(dupstore2);js2++)
	*(dupstore2+js2)=toupper(*(dupstore2+js2));
      break;
    }
/*      if(tth_debug&4) fprintf(stderr,"Found counter %s=%s\n",yytext,dupstore2); */
    TTH_PUSH_BUFF(1);yy_scan_string(dupstore2);
    *dupstore2=0;
    yy_pop_state();
  }
}
<number>.   fprintf(stderr,"No number at character:%s",yytext);yy_pop_state();
<counterset>{SP}*=*{SP}*     /* Remove optional = and space */
<counterset>\{    TTH_PUSH_CLOSING;
<counterset>{NUM} {
  sscanf(yytext+strcspn(yytext,"+-0123456789"),"%d",&counters[ind]);
  if(tth_debug&4) fprintf(stderr,"Counter %d set to %d\n",ind,counters[ind]);
  yy_pop_state();
  }
<counterset>[+-]*\\[a-zA-Z]+ {
  js2=ind; /* Save ind because it is used by TTH_DO_MACRO */
  i=indexkey(yytext+strcspn(yytext,"\\"),countkeys,&ncounters);
  if(i == -1){
    TTH_DO_MACRO
    else{
      if(!(tth_debug&32768))
	fprintf(stderr,"**** Unknown counter for counterset, %s\n",
	    yytext+strcspn(yytext,"\\"));
      yy_pop_state();
    }
    ind=js2;
  }else{
    counters[ind]=counters[i];
    if(strcspn(yytext,"-") != strlen(yytext)) counters[ind]=-counters[ind];
    yy_pop_state();
    if(tth_debug&4)fprintf(stderr,"Counter %d set to %d\n",ind,counters[ind]);
  }
 }
<counterset>.|\n {
  fprintf(stderr,"**** Error: Failed to find value to set counter %s.\n",countkeys[ind]);
  yy_pop_state();
}


 /* Definitions */
\\let 	{	
  localdef=1;
  if(tth_debug&4) fprintf(stderr,"%s(localdef=%d)",yytext,localdef);
  /* yy_push_state(define); */
  yy_push_state(letdef);
  yy_push_state(getnumargs);
  yy_push_state(embracetok); /* Prevent let looking for arguments */
  yy_push_state(getdef);
  }
<letdef>\} {  /* others are the same as <define> */
  if(!bracecount){
    if(tth_debug&4) fprintf(stderr,"Close brace ending let,count=%d\n",
			     bracecount);
    yy_pop_state();
    strcpy(scratchstring,defstore+strspn(defstore," {"));
    *(scratchstring+strcspn(scratchstring,"}"))=0;
    if((i=indexkey(scratchstring,keys,&nkeys))==-1){
      if(tth_debug&4) fprintf(stderr,"Macro %s not found for \\let. Presuming native.\n",scratchstring);
      strcat(defstore,"#tthdrop");
      sprintf((defstore+strlen(defstore)),"%d",abs(narg));
      if(nkeys < NFNMAX) {
	lkeys[nkeys]=localdef;
	mkdef(defchar,keys,defstore,defs,&narg,nargs,&nkeys);
	if(tth_debug&4){
	  i=indexkey(defchar,keys,&nkeys);
	  fprintf(stderr,"  Just Defined Key %s index %d nargs %d Def %s\n",
		  defchar,i,nargs[i],defs[i]);
	}
      }
      else fprintf(stderr,"Too many functions to define %s",defchar);
    }else{
      if(nkeys < NFNMAX) {
	lkeys[nkeys]=localdef;
	mkdef(defchar,keys,defs[i],defs,nargs+i,nargs,&nkeys);
	if(tth_debug&4){
	  i=indexkey(defchar,keys,&nkeys);
	  fprintf(stderr,"Defined Let Key %s index %d nargs %d Def %s\n",
		  defchar,i,nargs[i],defs[i]);
	}
      }else fprintf(stderr,"Too many functions to define %s",defchar);
    }
    *defchar=0;
    *defstore=0;
  } else {
    if(tth_debug&4) fprintf(stderr,"Close brace in [e]def, count=%d\n",
			     bracecount);
    strcat(defstore,yytext);bracecount--;
  }
}

(\\def|\\gdef|\\global\\def)	{
  if(*(yytext+1)!='d')localdef=0; else localdef=1;
  if(tth_debug&4) fprintf(stderr,"%s(localdef=%d)",yytext,localdef);
  yy_push_state(define);  
  yy_push_state(getnumargs);
  yy_push_state(getdef);
  }
(\\edef|\\xdef|\\global\\edef) {
  if(*(yytext+1)!='e')localdef=0; else localdef=1;
  if(tth_debug&4) fprintf(stderr,"%s(localdef=%d)",yytext,localdef);
  edeftype=1;
  yy_push_state(define);  
  yy_push_state(getnumargs); /* determine no of args */
  yy_push_state(getdef);  /* determine the key of definition */
  }
<getdef>{NL} TTH_INC_LINE;
<getdef>{TSP}*
<getdef>\{  yy_push_state(getdefbr);strcpy(dupstore,"{");
<getdefbr>\} {  /* Really ought to match braces. */
  /*fprintf(stderr,"getdefbr strings:%s:%s:",yytext,dupstore);*/
  yy_pop_state();
  TTH_CCPY(defchar,dupstore+strspn(dupstore,"{ \t\n"));
  yy_pop_state();*dupstore=0;
  /* If this is a true definition, terminate at space etc.*/
  if(*defchar=='\\')
    *(defchar+strcspn(defchar," =}"))=0;
  if(tth_debug&4) fprintf(stderr,":%s,",defchar);
}
<getdefbr>.  strcat(dupstore,yytext);
<getdef>\\[a-zA-Z@]+({SP}*=)? 	{
  /*fprintf(stderr,"getdef string:%s:",yytext);*/
  TTH_CCPY(defchar,yytext+strspn(yytext,"{ \t\n"));
  yy_pop_state();*dupstore=0;
  *(defchar+strcspn(defchar," =}"))=0;
  if(tth_debug&4) fprintf(stderr,":%s,",yytext);
  }
<getdef>. {
  fprintf(stderr,
	  "\n**** Error: incompatible syntax in macro name:%s: Line %d\n",
	  yytext,tth_num_lines);
  yy_pop_state();
}

 /* Latex form accommodates arg number perhaps WSP is wrong. */
<getnumargs>{WSP}*\[[1-9]\]{WSP}*\{    |  
<getnumargs>([ \t]*{NL})?[ \t]*(#[0-9])+\{	{ /* New pattern */
  /*  sscanf((yytext+strcspn(yytext,"] \t\n{")-1),"%d",&narg); */
  TTH_INC_MULTI;
  sscanf((yytext+strcspn(yytext,"]{")-1),"%d",&narg);
  yy_pop_state();
  if(tth_debug&4) fprintf(stderr," %d arguments.\n",narg);
  }
<getnumargs>\{	{
  narg=0;
  yy_pop_state();
  if(tth_debug&4) fprintf(stderr," no arguments.\n");
  }
<getnumargs>(([^\{#]*#[0-9])+[^\{#]*)+\{   {
  if(tth_delimdef){
    yy_pop_state();
    if(tth_debug&4) fprintf(stderr,"yytext=%s",yytext);
    chs2=yytext-1;
    while(chs2 != NULL){
      chscratch=chs2;
      chs2=strstr(chscratch+1,"#");
    }
    sscanf(chscratch+1,"%d",&narg);
    narg=-narg;
    if(tth_debug&4) fprintf(stderr,
		 "Delimited definition:%s\n No of args: %d\n ",defchar,narg);
    if(nkeys < NFNMAX) {
      whitespace=1;
      horizmode=1;
      yyless(0);
      *dupstore=0; /* ought not to be needed */
      yy_push_state(ddcomp);
    }
    else fprintf(stderr,"Too many functions to define %s",defchar);
  }else{
    TTH_INC_MULTI;
    yy_pop_state();yy_pop_state();yy_push_state(matchbrace);
    fprintf(stderr,"Discarding delimited definition:%s\n",defchar);
  }
}
<ddcomp>{NL} {
  if(!whitespace)strcat(dupstore," ");
  TTH_INC_LINE;
  whitespace=1;
  if(horizmode==1){
    horizmode=-1;
    yy_push_state(parcheck);  
  }else{
    if(horizmode==-1){
      fprintf(stderr,"**** Abnormal NL in -1 ddcomp.\n");
/*        horizmode=0;strcat(dupstore,"\\par"); */
    }
  }
}
<ddcomp>[ \t]         {if(!whitespace){strcat(dupstore," ");} whitespace=1; }
<ddcomp>\\[a-zA-Z@]*  {whitespace=1;strcat(dupstore,yytext);}
<ddcomp>\{ {
  whitespace=0;strcat(dupstore,yytext);horizmode=1;
    lkeys[nkeys]=0;
  mkdef("",keys,dupstore,defs,&narg,nargs,&nkeys);
  if(tth_debug&4){
    fprintf(stderr,"Defined Argument-Template: index %d nargs %d Def:%s\n",
	    nkeys-1,nargs[nkeys-1],defs[nkeys-1]);
  }
  *dupstore=0;
  yy_pop_state();
}
<ddcomp>\\(\\|%|\$|&|\#)  {whitespace=0;strcat(dupstore,yytext+1);horizmode=1;}
<ddcomp>. {whitespace=0;strcat(dupstore,yytext);horizmode=1;}

<getnumargs>\[[1-9]\]{WSP}*\[[^\]]*\]{WSP}*\{   { 
  TTH_INC_MULTI;
  strcpy(scratchstring,yytext);
  chscratch=strstr(scratchstring+1,"[")+1;
  *(chscratch+strcspn(chscratch,"]"))=0;
  js2=nkeys;
  mkkey(chscratch,optargs,&js2);
  if(tth_debug&4){
    js2--;
    fprintf(stderr,"Defined Default argument %s index %d nargs %d Def %s\n",
	    chscratch,js2,nargs[js2],optargs[js2]);
  }
  strcpy(scratchstring+3,"{");
  TTH_SCAN_STRING(scratchstring);
}

\{               |
\\begingroup	 |
\\bgroup		TTH_PUSH_CLOSING;
\\tthparendgroup     |
\}               |
\\endgroup	 |
\\egroup	 {
  TTH_TEXCLOSE else{
/*    if(horizmode==-1)horizmode=1;  */
  TTH_CLOSEGROUP;TTH_POP_CLOSING;}
}
<matchbrace>\{	bracecount++;
<matchbrace>\}	{if(!bracecount){yy_pop_state();} else {bracecount--;}}
<matchbrace>\\\{ 
<matchbrace>\\\}
<matchbrace>. 

\\\+  if(!tth_LaTeX) fprintf(tth_fdout,"<table class=\"tabbing\"><tr><td width=\"%d\">\n",tabwidth);

\\settabs{SP}*{NUM}{SP}*\\columns {
  sscanf(yytext+8,"%d",&jscratch);
  tabwidth=1000/jscratch;
 }
\\eject           {TTH_PAR_ACTION};

  /* Standard TeX formatting switches work properly inside groups.*/
\\obeylines	fprintf(tth_fdout,"<pre>");TTH_PRECLOSE("\n</pre>");
\\tth_underline{SP}* { /* underline switch. */
  if(eqdepth && strcspn(TTH_NAME,"M")>0 ){ /* In equations not Mathml */
    TTH_CCAT(tth_font_open[tth_push_depth],TTH_UNDL1);
    TTH_CCAT(tth_font_close[tth_push_depth],TTH_UNDL2);
  }else{
    TTH_OUTPUT(TTH_UNDL1);TTH_PRECLOSE(TTH_UNDL2);
  }
 }
\\bfseries{SP}* {
  if(eqdepth){
    TTH_CCAT(tth_font_open[tth_push_depth],TTH_BOLDO);
    TTH_CCAT(tth_font_close[tth_push_depth],TTH_BOLDC);
    if(strstr(tth_texclose[tth_push_depth-1],"tth_boxclose")) {  
      TTH_OUTPUT(TTH_BOLD1);TTH_PRECLOSE(TTH_BOLD2);
      }  
  }else{
    TTH_OUTPUT(TTH_BOLD1);TTH_PRECLOSE(TTH_BOLD2);
  }
 }
\\bf{SP}*	{
  if(eqdepth){
    TTH_CCPY(tth_font_open[tth_push_depth],TTH_BOLDO);
    TTH_CCPY(tth_font_close[tth_push_depth],TTH_BOLDC);
    if(strstr(tth_texclose[tth_push_depth-1],"tth_boxclose")) {  
      TTH_OUTPUT(TTH_BOLD1);TTH_PRECLOSE(TTH_BOLD2);
    } 
  }else{
    TTH_OUTPUT(TTH_BOLD1);TTH_PRECLOSE(TTH_BOLD2);
  }
 }
  /* Implementation of \bm from math package. Bold italic.*/
\\tth_bm{SP}*	{
  if(eqdepth){
    TTH_CCPY(tth_font_open[tth_push_depth],TTH_BLDITO);
    TTH_CCPY(tth_font_close[tth_push_depth],TTH_BLDITC);
    if(strstr(tth_texclose[tth_push_depth-1],"tth_boxclose")) {  
      TTH_OUTPUT(TTH_BLDIT1);TTH_PRECLOSE(TTH_BLDIT2);
    } 
  }else{
    TTH_OUTPUT(TTH_BLDIT1);TTH_PRECLOSE(TTH_BLDIT2);
  }
 }
\\itshape{SP}* |
\\slshape{SP}* {
  if(eqdepth){
    TTH_CCAT(tth_font_open[tth_push_depth],TTH_ITALO);
    TTH_CCAT(tth_font_close[tth_push_depth],TTH_ITALC);
    if(strstr(tth_texclose[tth_push_depth-1],"tth_boxclose")) {  
      TTH_OUTPUT(TTH_ITAL1);TTH_PRECLOSE(TTH_ITAL2);
    }
  }else{
    TTH_OUTPUT(TTH_ITAL1);TTH_PRECLOSE(TTH_ITAL2);
  }
 }
\\it{SP}*  |
\\sl{SP}*	{
  if(eqdepth){
    TTH_CCPY(tth_font_open[tth_push_depth],TTH_ITALO);
    TTH_CCPY(tth_font_close[tth_push_depth],TTH_ITALC);
    if(strstr(tth_texclose[tth_push_depth-1],"tth_boxclose")) {  
      TTH_OUTPUT(TTH_ITAL1);TTH_PRECLOSE(TTH_ITAL2);
    }
  }else{
    TTH_OUTPUT(TTH_ITAL1);TTH_PRECLOSE(TTH_ITAL2);
  }
 }
\\ttfamily{SP}* |
\\tt{SP}*	{
  if(eqdepth){
    TTH_CCPY(tth_font_open[tth_push_depth],TTH_TTO);
    TTH_CCPY(tth_font_close[tth_push_depth],TTH_TTC);
    if(strstr(tth_texclose[tth_push_depth-1],"tth_boxclose")) {  
      TTH_OUTPUT(TTH_TT1);TTH_PRECLOSE(TTH_TT2);
    }
  }else{
    TTH_OUTPUT(TTH_TT1);TTH_PRECLOSE(TTH_TT2);
  }
 }
\\rmfamily{SP}* |
\\mdseries{SP}* |
\\upshape{SP}* |
\\normalfont{SP}* |
\\rm{SP}*	{
  if(eqdepth){
    TTH_CCPY(tth_font_open[tth_push_depth],TTH_NORM1);
    TTH_CCPY(tth_font_close[tth_push_depth],TTH_NORM2);
  }else{
    if(!eqdepth && !(tth_istyle&1)){ 
      TTH_OUTPUT(TTH_FONTCANCEL); /* not in equations: avoid bug */
    }else{
      TTH_OUTPUT(TTH_NORM1);TTH_PRECLOSE(TTH_NORM2);
    }
  }
}
\\scshape   { /* new approach */
  if(tth_push_depth){
    yy_push_state(textsc);
    tth_push_depth--;
    TTH_PRETEXCLOSE("\\tth_endsmallcaps");
    tth_push_depth++;}
}
\\sffamily{SP}*   {
  TTH_OUTPUT(TTH_HELV1); TTH_PRECLOSE(TTH_HELV2);}
\\boldmath{SP}* {
    TTH_CCAT(tth_font_open[tth_push_depth],TTH_BOLDO);
    TTH_CCAT(tth_font_close[tth_push_depth],TTH_BOLDC);
}  
\\unboldmath{SP}* {
    TTH_CCPY(tth_font_open[tth_push_depth],tth_fonto_def);
    TTH_CCPY(tth_font_close[tth_push_depth],tth_fontc_def);
}  

\\narrower	fprintf(tth_fdout,"<dl><dd>");TTH_PRECLOSE("</dd></dl>");

\\hang		        {
  fprintf(tth_fdout,"<dl><dd>");
  if(strstr(closing,"--vbox")){
    TTH_CCPY(scratchstring,"<!--vbox_par-->");
  }else{*scratchstring=0;}
  TTH_PUSH_CLOSING;
  TTH_CCPY(closing,scratchstring);
  TTH_CCAT(closing,"</dd></dl>\n");
  yy_push_state(pargroup);tth_eqwidth=tth_eqwidth-TTH_INDPC;}
\\hangindent	{
  TTH_PUSH_CLOSING; fprintf(tth_fdout,"<dl><dd>");
  TTH_CCPY(closing,"</dd></dl>\n");
  yy_push_state(pargroup);tth_eqwidth=tth_eqwidth-TTH_INDPC;
  GET_DIMEN }
\\hangafter   {
  fprintf(stderr,"Hangafter ignored\n");yy_push_state(lookfornum);*argchar=0;
}


 /* Getting values and units, do nothing. Only treat the explicit case. 
 A tokenized DIMEN will treat command and dimen as unknown commands.
 Removed /{NUM} also in hangindent, 1.01 (also saved 10k size)*/

\\parindent	GET_DIMEN
\\overfullrule	GET_DIMEN
 /* Setting sizes: */
\\[hv]offset	GET_DIMEN
\\[hv]fuzz	GET_DIMEN
\\(top|oddside|evenside)margin    GET_DIMEN
\\(head|text|foot)height          GET_DIMEN
\\(textwidth|headsep)             GET_DIMEN

 /*<argclear>.|\n  yyless(0);yy_pop_state(); *argchar=0; */

\\tthdimen{WSP}*\\[a-zA-Z@]+ {   /* Set a dimension that was defined. */
  strcpy(newcstr,yytext+1+strcspn(yytext+1,"\\"));
  *scratchstring=0;
  if(tth_push_depth-tth_LaTeX>0 || strcmp(newcstr,"\\hsize"))
     yy_push_state(setdimen);
  GET_DIMEN;/* Get the new dimension */
 /*    yy_push_state(argclear); */
  GET_DIMEN;/* Get the current dimension*/
  if(tth_debug&1024){fprintf(stderr,"Dimension to set: %s  Now follow the current and the new values:\n",newcstr);}
}
   /* Preexisting dimensions, skips etc. Now not preexisting.
\\hsize {
  strcpy(newcstr,yytext);*scratchstring=0;
  if(tth_push_depth-tth_LaTeX>0)yy_push_state(setdimen);
  GET_DIMEN;
} */
<setdimen>{ANY} {
  yy_pop_state();yyless(0);
  if(tth_debug&1024)fprintf(stderr,"Setdimen. scratchstring=%s, closing=%s, newcstr=%s, thesize=%d\n",scratchstring,closing,newcstr,thesize);
  if(thesize){
    if(*scratchstring=='%') {
      sprintf(scrstring,"\\def%s{\\tthdimen%s %f%s}",
	      newcstr,newcstr,anumber,"\\tth_hsize");
      if(strstr(closing,"<!--vbox-->")!=NULL
	 && strstr(newcstr,"\\hsize")!=NULL){
	sprintf(scratchstring,"</td><td width=\"%d\"%s>\n",
		(thesize*DEFAULTHSIZEPIX)/100,boxalign); /*Guess at width */
	TTH_OUTPUT(scratchstring);
      }
    }else if(strlen(scratchstring)){
      sprintf(scrstring,"\\def%s{\\tthdimen%s %f%s}",
	      newcstr,newcstr,anumber,scratchstring);
      if(strstr(closing,"<!--vbox-->")!=NULL
	 && strstr(newcstr,"\\hsize")!=NULL){
	sprintf(scratchstring,"</td><td width=\"%d\"%s>\n",
		thesize/SCALEDPERPIXEL,boxalign);
	TTH_OUTPUT(scratchstring);
      }
    }
    TTH_SCAN_STRING(scrstring);
  }
}
\\[a-zA-Z]*size	{
  TTH_DO_MACRO
    else{GET_DIMEN;}
}
\\hspace\*?  TTH_TEX_FN("\\hskip #1{}#tthdrop1",1);
\\vspace\*?  TTH_TEX_FN("\\vskip #1{}#tthdrop1",1);
\\hskip {
  yy_push_state(hskip);
  yy_push_state(glue);GET_DIMEN;
}
<hskip>{ANY} {
  if(*scratchstring=='%'){ /* Size is in % of hsize. Guess 100 nbsp per line!*/
    for(js2=0;js2<thesize;js2++){TTH_OUTPUT("&nbsp;");}
  }else{ /* Absolute size. Guess that a &nbsp; is 5 pixels wide */
    for(js2=0;js2<(thesize/(SCALEDPERPIXEL*5));js2++){TTH_OUTPUT("&nbsp;");}
  }
  yy_pop_state(); yyless(0);
}
\\vskip {
  yy_push_state(vskip);
  yy_push_state(glue);GET_DIMEN;
}
<vskip>{ANY} {  /*Guess that <br /> is 14 pixels */
  for(js2=0;js2<(thesize/(SCALEDPERPIXEL*14));js2++){TTH_OUTPUT("<br />");}
  yy_pop_state(); yyless(0);
}
\\hglue         |
\\[a-zA-Z]*(skip|sep)  {
  TTH_DO_MACRO
  else{
    if(horizmode) horizmode=1;
    if(tth_debug&1) fprintf(stderr,"Removing glue command:%s\n",yytext); 
    yy_push_state(glue);GET_DIMEN;
  }
 }
\\(vtop|vbox)({SP}+to|spread)* {
  if(!horizmode || horizmode==3 ||  strstr(closing,"<!--hbox") || 
     strstr(tth_texclose[tth_push_depth-1],"tthhbclose")){
    if(strstr(yytext,"vtop")){    
      TTH_CCPY(boxvalign,"</td><td valign=\"top\">");
    }else{
      TTH_CCPY(boxvalign,"</td><td>");
    }
    if(tth_debug&1024)fprintf(stderr,"Entering vbox state\n");
    yy_push_state(vbox);
    if(strstr(yytext+4,"to")||strstr(yytext+4,"spread")){GET_DIMEN;}
  }else{
    yyless(0);
    TTH_OUTPUT("<table border=\"0\"><tr><td>");
    TTH_PRETEXCLOSE("\\tthhbclose");
    if(tth_debug&1024)fprintf(stderr,"Entering vbox parclose state\n");
    yy_push_state(parclose);
    TTH_PUSH_CLOSING;
    TTH_CCAT(closing,"</td></tr></table><!--hboxt-->");
  }
}

\\tthhbclose {
  if(tth_debug&1024)fprintf(stderr,"tthhbclose Stack_ptr=%d. Closing=%s\n",tth_stack_ptr,closing);
  yy_pop_state();
  if(tth_debug&1024)fprintf(stderr,"tthhbclose pop completed\n");
  TTH_CLOSEGROUP;TTH_POP_CLOSING;
}


<vbox>(\\bgroup|\{){WSP}*(\\advance)?(\\hsize)? {
  if(tth_debug&1024)fprintf(stderr,"Starting vbox\n");
  yy_pop_state();
  /*If box does not start with explicit hsize manipulation, make it do so. */
  chscratch=strstr(yytext,"\\hsize");
  js2=1+strcspn(yytext+1,"\\");
  yyless(js2);
  if(chscratch){
/*      fprintf(stderr,"vbox:%s\n",yytext); */
  }else{
    if((ind=indexkey("\\hsize",keys,&nkeys))!=-1){/*hsize is defined*/
      if(indexkey("\\hsize",keys,&ind)!=-1){/*hsize is currently redefined*/
	/* Must be done after the yyless */
	TTH_SCAN_STRING("\\hsize=\\hsize ");/*Set size at the start of vbox*/ 
	if(tth_debug&1024)fprintf(stderr,"Vbox auto hsize reset\n"); 
      }
    }
  }
  *scratchstring=0;
  if(strstr(closing,"<!--hbox--")){
    if(!strstr(closing,"<br clear")){
      TTH_CCAT(closing,"<br clear=\"all\" />");
      if(horizmode){TTH_OUTPUT("<br />");} /* To avoid table bugs */
    }
    TTH_OUTPUT("<table border=\"0\" align=\"left\"><tr><td>");
  }else{
    if(strstr(closing,"<!--hboxt--")){
      TTH_OUTPUT(boxvalign);
      *boxvalign=0;
      TTH_CCPY(scratchstring,"\n</td><td>");
    }
    TTH_OUTPUT("<table border=\"0\"><tr><td>");
  }
  TTH_PUSH_CLOSING; 
  TTH_CCPY(closing,"\n</td></tr></table><!--vbox-->");
  TTH_CCAT(closing,scratchstring);
  if(!horizmode || horizmode==3){ /* Pass on vert mode to next box if any*/
    TTH_CCAT(tth_texclose[tth_push_depth-1],"\\tthvertbox");
  }
  horizmode=1;
}
\\hbox {TTH_SWAP("\\tth_hbox");}
\\tth_hbox   {
  if(horizmode){
    TTH_CCAT(closing,"<!--hbox-->");
  }else{
    TTH_OUTPUT("<table border=\"0\"><tr><td>");
    TTH_CCAT(closing,"</td></tr></table><!--hboxt-->");
  }
}
\\hbox{SP}+to {
  yy_push_state(hbox);
  GET_DIMEN;
}
\\line  TTH_SCAN_STRING("\\par\\hbox to\\hsize ");

<hbox>(\{|\\bgroup){WSP}*(\\hss|\\hfill)? {
  if(strstr(yytext,"\\h")){
    strcpy(boxalign," align=\"right\"");
  }
  TTH_PUSH_CLOSING; 
  TTH_CCPY(closing,"</td></tr></table><!--hbox-->\n");
  if(!horizmode){
    TTH_CCAT(closing,"<br clear=\"all\" />");
  }
  /*Special post-table state does not trigger broken table code */ 
  TTH_CCAT(tth_texclose[tth_push_depth-1],"\\tthhorizbox");
  if(horizmode&&(horizmode!=2)){TTH_OUTPUT("<br />");} 
  /* avoid broken table alignment*/ 
  if(*scratchstring == '%'){
    sprintf(scratchstring,
	    "<table align =\"left\" border=\"%d\" width=\"%d%s\"><tr><td%s>\n",
	    boxborder,thesize,"%",boxalign);
    TTH_OUTPUT(scratchstring);
  }else{
    sprintf(scratchstring,
	    "<table align=\"left\" border=\"%d\"><tr><td width=\"%d\"%s>\n",
	    boxborder,thesize/SCALEDPERPIXEL,boxalign);
    TTH_OUTPUT(scratchstring);
  }
  horizmode=1; 
  *boxalign=0;boxborder=0;
  yy_pop_state();
}
\\tthhorizbox  horizmode=2; /* fprintf(stderr,"Set Horizmode=2.\n"); */
\\tthvertbox   horizmode=3;

<hbox,vbox>{WSC} {
  fprintf(stderr,
	  "**** Error: Apparently unembraced h/vbox:%s, near line %d\n",
	  yytext,tth_num_lines);
  yyless(0);
  *boxalign=0;
  yy_pop_state();
}
<hbox,vbox>\\[a-zA-Z@]+   { /* expand a possible macro */
  TTH_DO_MACRO else{
  yyless(0);
  *boxalign=0;
  yy_pop_state();
  horizmode=1;
  }
}
\\hss |
\\hfill? {
  if(strstr(closing,"</td></tr></table>")){ 
    TTH_OUTPUT("</td><td align=\"right\">"); /* align=right a compromise. */
  }
  else{if(tth_debug&1024)fprintf(stderr,
	       "Apparent hfill/hss outside hbox. Closing=%s\n",closing);}
}
\\fbox |
((\\sbox|\\savebox)\{[^\}]*\}|\\framebox|\\makebox)(\[[^\]]*\]){0,2} {
  TTH_INC_MULTI;
  if(*(yytext+1)=='f')boxborder=1;
  if(strcspn(yytext,"[") == strlen(yytext)){
    *scrstring=0;*scratchstring=0;
  }else{
    TTH_CCPY(scratchstring,yytext+strcspn(yytext,"[")+1);
    if((chscratch=strstr(scratchstring,"["))!=NULL){
      strcpy(scrstring,chscratch+1);}else{*scrstring=0;}
    *(scratchstring+strcspn(scratchstring,"]"))=0;
  } /* Now we have the width and optional alignment. */
  switch(*scrstring){
  case 'l': strcpy(boxalign," align=\"left\"");break;
  case 'r': strcpy(boxalign," align=\"right\"");break;
  default : strcpy(boxalign," align=\"center\"");
  }
  chscratch=scrstring;
  if(*(yytext+1) =='s'){ /* Setbox case, prefix definitions.*/
    TTH_CCPY(scrstring,"\\setbox");
    TTH_CCAT(scrstring,yytext+strcspn(yytext,"{"));
    chscratch=(scrstring+strcspn(scrstring,"}")+1);
  }
  if(*scratchstring)sprintf(chscratch,"\\hbox to %s",scratchstring);
  else if(boxborder)strcpy(chscratch,"\\hbox to 0pt");/*really undefined*/
  else strcpy(chscratch,"\\hbox");

  TTH_SCAN_STRING(scrstring);
}

\\setbox[0-9]+ {
  sscanf(yytext+7,"%d",&js2);
  js2++;
  roman(js2,scratchstring);
  sprintf(scrstring,"\\setbox\\tthbox%s",scratchstring);
  TTH_SCAN_STRING(scrstring);
}

\\setbox      {
  yy_push_state(getbox); /* Get the box definition, then define */
  yy_push_state(getdef); /* Get the next cs and leave in defchar.*/
  *argchar=0; /* ensure null if no box found */
}


<getbox>(\\(h|v)?box|\\vtop)({SP}+(to|spread))? {
  TTH_CCPY(argchar,yytext);
  TTH_CCAT(argchar," ");
  if(strstr(yytext," ")){
    yy_push_state(lookforunit);yy_push_state(lookfornum);
    /* GET_DIMEN, but without resetting argchar.*/
  }
  if(tth_debug&4)fprintf(stderr,"Setting box as:%s\n",yytext);
}
<getbox>{NL} TTH_INC_LINE;
<getbox>{TSP}
<getbox>{ANY} {
  yyless(0);
  yy_pop_state();
  sprintf(dupstore,"{%s}{%s}",defchar,argchar);
  *defchar=0;*argchar=0;
  TTH_SCAN_STRING(dupstore);
  *dupstore=0;
  TTH_TEX_FN("\\edef#1{#2{#3}}#tthdrop3",3);
}

\\openup		|
 /*\\vbox{SP}+to	|*/
\\kern		        |
\\lower		        |
\\raise		        GET_DIMEN
\\rule   TTH_TEX_FN_OPT("#tthdrop3",3,"");

  /* Looking constructs */
<tokenarg>\{		{TTH_PUSH_CLOSING;TTH_CCPY(closing,argchar);
			argchar[0]=0;yy_pop_state();}
<tokenarg>{WSC}	|
<tokenarg,getnumargs>\\[a-zA-Z]+ {
      strcpy(dupstore,"{");strcat(dupstore,yytext);strcat(dupstore,"}");
      TTH_SCAN_STRING(dupstore);
      *dupstore=0;
      }
<dupsquare>\[            |
<escgroup,uncommentgroup>\{             |
<dupgroup>[^%\}\{]*\{    { 
  /* Count braces, save text in dupstore */
  TTH_INC_MULTI;
  TTH_CHECK_LENGTH;
   if(tth_debug&16) 
     fprintf(stderr,"Open brace appending - %s - to - %s -\n",yytext,dupstore);
   bracecount++;strcat(dupstore,yytext);
    }
<xpnd>\\number{SP}*     yy_push_state(number);jscratch=0;
<xpnd,hendline>\\tt[hm]dump{SP}*\{  yy_push_state(matchbrace);
 /* Prevent an expanding state from expanding:
    \hsize, natbib cites in footnotes*/
<xpnd>\\cite(t|p|author)  |
<xpnd>\\hsize {
  if(tth_debug&4)fprintf(stderr,"We don't expand:%s \n",yytext);
  strcat(defstore,yytext);strcpy(xpndstring," ");
}
<xpnd>\\[a-zA-Z@]+   {
  if(tth_debug&4)fprintf(stderr,"Attempt to expand:%s ",yytext);
  TTH_DO_MACRO
  else {
    if(tth_debug&4)fprintf(stderr,"failed");
    strcat(defstore,yytext);
    strcpy(xpndstring," ");
  }
  if(tth_debug&4)fprintf(stderr,"\n");
}
<xpnd>\\tth_[a-zA-Z@]+ { /* tth pseudo commands are unexpandable. */
    strcat(defstore,yytext);
    /* strcpy(xpndstring," "); And no termination is needed. */
}
<xpnd>\\noexpand\\[a-zA-Z]+ {
  strcat(defstore,yytext+9);    strcpy(xpndstring," "); 
}
<xpnd,getbox,macarg,lookfornum,notags>\\tthdimen[ ]?\\[a-zA-Z]+ 
 
<xpnd>#tthdrop[0-9] {
  strcat(defstore,yytext);
  yy_pop_state();
  if(nkeys < NFNMAX) {
    lkeys[nkeys]=localdef;
    mkdef(defchar,keys,defstore,defs,&narg,nargs,&nkeys);
    if(tth_debug&12){
      i=indexkey(defchar,keys,&nkeys);
      fprintf(stderr,"Defined Key %s index %d nargs %d Def %s\n",
	      defchar,i,nargs[i],defs[i]);
    }
  }
  else fprintf(stderr,"Too many functions to define %s",defchar);
  *defstore=0;*defchar=0; /* Clean up */
}
  /* If the next thing is a brace don't put the xpndstring (possible space)
     If it is not, then output the space denoting the end of previous macro*/
<xpnd>\{     strcat(defstore,yytext);*xpndstring=0;
<xpnd>{ANY}  {
    if(strcspn(yytext,"\n")==0) TTH_INC_LINE;
  strcat(defstore,xpndstring);strcat(defstore,yytext);*xpndstring=0;
}
<define,letdef>\\\\  strcat(defstore,yytext); /* Ensure \\ doesn't escape. */
<define,letdef>\\\{  strcat(defstore,yytext); /* Don't count escaped { */
<define,letdef>\{    {
   if(tth_debug&16) fprintf(stderr,"Open brace in [e]def, count=%d\n",
			    bracecount);
   bracecount++;strcat(defstore,yytext);
    }
<define,letdef>\\\}  strcat(defstore,yytext);
<define>\} {
  if(!bracecount){
    if(tth_debug&16) fprintf(stderr,"Close brace ending [e]def,count=%d\n",
			     bracecount);
    yy_pop_state();
    strcat(defstore,"#tthdrop");
    sprintf((defstore+strlen(defstore)),"%d",abs(narg));
    if(edeftype){
      if(tth_debug&4) fprintf(stderr,"Expanding definition:%s\n",defstore);
      edeftype=0;
      yy_push_state(xpnd);
      TTH_SCAN_STRING(defstore);
    }else{
      if(nkeys < NFNMAX) {
	lkeys[nkeys]=localdef;
	mkdef(defchar,keys,defstore,defs,&narg,nargs,&nkeys);
	if(tth_debug&4){
	  i=indexkey(defchar,keys,&nkeys);
	  fprintf(stderr,"Defined Key %s index %d nargs %d Def %s\n",
		  defchar,i,nargs[i],defs[i]);
	}
      }
      else fprintf(stderr,"Too many functions to define %s",defchar);
      *defchar=0;
    }
    *defstore=0;
  } else {
    if(tth_debug&16) fprintf(stderr,"Close brace in [e]def, count=%d\n",
			     bracecount);
    strcat(defstore,yytext);bracecount--;
  }
 }
<define,letdef>{NL}      TTH_INC_LINE;TTH_CHECK_LENGTH;strcat(defstore,yytext);
<define,letdef>[^\{\}]       strcat(defstore,yytext);

<optdetect>{WSP}   TTH_INC_MULTI;  /*Necessary for roots to work etc.*/
<optdetect>\[    {
  yyless(0);yy_pop_state();
  yy_push_state(macarg);yy_push_state(embracetok);yy_push_state(optag);
}
<optdetect>{ANY}  {
  yyless(0);yy_pop_state();
  sprintf(scratchstring,"#%d",jarg);
  if(margmax < NARMAX) {
    jscratch=0;
    {
      strcpy(scrstring,chopt); /* changed Aug 15 */
      mkdef(scratchstring,margkeys,scrstring,margs,&jscratch,margn,&margmax);
      if(tth_debug&8){
	i=indexkey(scratchstring,margkeys,&margmax);
	fprintf(stderr,"Used Default argument %s index %d Def:%s\n",
		scratchstring,i,margs[i]);
      }
    }/* optargs should always be defined. */
  } else fprintf(stderr,"**** Error: Too many Macro Args to define %s Line %d\n",argchar,tth_num_lines);
  if( jargmax < 0){ /* Don't understand why */
    jarg++;
  }else if(jarg == jargmax) {
    jarg=1;
    TTH_SCAN_STRING(chdef);
    yy_push_state(psub);
    if(tth_debug&8) fprintf(stderr,
		   "Using definition %s in optdetect\n",chdef);
    bracecount=0;
  } else {
    bracecount=-1;
    yy_push_state(macarg);yy_push_state(embracetok);
    jarg++;
  }
}
<macarg>\\verb\} { /* Don't add space after verb */
  strcat(dupstore,yytext);
  *(dupstore+strlen(dupstore)-1)=0;
  unput('}');
}
<optag>\\[a-zA-Z]+(\]|%) |
<macarg>\\[a-zA-Z]+(\}|%) { 
  strcat(dupstore,yytext);
  strcpy(dupstore+strlen(dupstore)-1," ");
  if(tth_debug&8) fprintf(stderr,"Macarg added space in:%s\n",yytext);
  unput(*(yytext+strlen(yytext)-1));
 }
<optag>\[ |
<macarg>\{    bracecount++;strcat(dupstore,yytext);
<optag>\] |
<macarg>\}   {
	if(bracecount == 0){
	  sprintf(argchar,"#%d",jarg);
	  if(margmax < NARMAX) {
	    jscratch=0;
	    mkdef(argchar,margkeys,dupstore+1,margs,&jscratch,margn,&margmax);
	    if(tth_debug&8){
	      i=indexkey(argchar,margkeys,&margmax);
	      fprintf(stderr,"Argument %s index %d Def:%s:\n",
		      argchar,i,margs[i]);
	    }
	  } else fprintf(stderr,"**** Error: Too many Macro Args to define %s Line %d\n",argchar,tth_num_lines);
	  *argchar=0;*dupstore=0;
	  if(jarg==1 && lopt){
	    if(tth_debug&8)fprintf(stderr,"Ended optional argument\n");
	    yy_pop_state();yy_pop_state();
	  }
	  if( jargmax < 0){
	    yy_pop_state();
	    jarg++;
	  }else if(jarg == jargmax) {
	    jarg=1;
	    yy_pop_state();
	    TTH_SCAN_STRING(chdef);
	    yy_push_state(psub);
	    if(tth_debug&8) fprintf(stderr,
		    "Using definition %s in macarg\n",chdef);
	  } else {
	    bracecount=-1;
	    yy_push_state(embracetok);
	    jarg++;
	  }
	} else {
	  strcat(dupstore,yytext);bracecount--;
	}
        }
<dupsquare>\]           |
<escgroup,uncommentgroup>\}            |
<dupgroup>[^%\}\{]*\}	{
  /* Count down braces. Save, or complete.
    storetype=
    0 Duplicate and rescan with argchar = closing of first.
    1 copy to superscript. 2 copy to subscript.
    3 Duplicate but with argchar inserted in middle and hence scanned.
    4 Rescan just one copy prefixed by argchar.
    5 Rescan one copy with argchar postfixed.
    6 Rescan two copies with argchar prefixed to first.
    Else just leave in dupstore. (Caller must clean up).
  */
  TTH_INC_MULTI;
  if(!bracecount){
    strcat(dupstore,yytext);
    if(tth_debug&16)fprintf(stderr,
	  "Ending dupgroup, dupstore= %s, storetype=%d\n",dupstore,storetype);
    if(storetype == 0){
      strcpy(dupstore2,dupstore);strcat(dupstore2,dupstore);
      TTH_PUSH_CLOSING;TTH_CCPY(closing,argchar);
      TTH_SCAN_STRING(dupstore2);
      *dupstore2=0;
      *dupstore=0;
    } else if (storetype == 1) {     /* Take the } off the end.*/	
      *(dupstore+strlen(dupstore)-1)=0;
      strcpy(supstore,dupstore);
      *dupstore=0;
    } else if (storetype == 2) {
      *(dupstore+strlen(dupstore)-1)=0;
      strcpy(substore,dupstore);
      *dupstore=0;
    } else if (storetype == 3) {
      strcpy(dupstore2,dupstore);strcat(dupstore2,argchar);
      strcat(dupstore2,dupstore);
      *argchar=0;
      if(tth_debug&16)fprintf(stderr,"Rescanning: %s\n",dupstore2);
      TTH_SCAN_STRING(dupstore2);*dupstore2=0;
      *dupstore=0;
    } else if (storetype == 4) {
      strcpy(dupstore2,argchar); *argchar=0;
      strcat(dupstore2,dupstore); *dupstore=0;
      if(tth_debug&16)fprintf(stderr,"Rescanning: %s\n",dupstore2);
      TTH_SCAN_STRING(dupstore2);*dupstore2=0;
    } else if (storetype == 5) {
      strcat(dupstore,argchar); *argchar=0;
      if(tth_debug&16)fprintf(stderr,"Rescanning: %s\n",dupstore);
      TTH_SCAN_STRING(dupstore);*dupstore=0;
    } else if (storetype == 6) {
      strcpy(dupstore2,argchar); *argchar=0;
      strcat(dupstore2,dupstore);strcat(dupstore2,dupstore); *dupstore=0;
      if(tth_debug&16)fprintf(stderr,"Rescanning: %s\n",dupstore2);
      TTH_SCAN_STRING(dupstore2);*dupstore2=0;
    }
    storetype=0;
    yy_pop_state();
  } else {
    if(tth_debug&16)
      fprintf(stderr,"appending - %s - to - %s -\n",yytext,dupstore);
    strcat(dupstore,yytext);bracecount--;}
}
<verbatim,notags>\\end\{verbatim\} {
  if(verbinput){ TTH_OUTPUT(yytext);} 
  else{
    if(tth_titlestate) tth_titlestate=99;
    TTH_TEXCLOSE else{TTH_CLOSEGROUP;TTH_POP_CLOSING;yy_pop_state();}
  }
}

\\tthverbatim TTH_TEX_FN("\\tth_grabverbname#tthdrop1",1);
<psub>\\tth_grabverbname#tthdrop1  { /* Set the name of verb environment */
  if((jscratch=indexkey("#1",margkeys,&margmax))!=-1){
    strcpy(tth_verbenviron,margs[jscratch]);
    rmdef(margkeys,margs,&margmax); 
    yy_pop_state();
    if(tth_debug)fprintf(stderr,"Verbenviron=%s\n",tth_verbenviron);
    /* Now the rest of entering verbatim environment. */
    if(horizmode) horizmode=1;
    fprintf(tth_fdout,"<pre>"); yy_push_state(verbatim);
    TTH_PUSH_CLOSING;  TTH_CCPY(closing,"</pre>");
  }else{
    fprintf(stderr,"Failed to grab verbatim name");
  }
}
<verbatim>\\end\{[A-Za-z]*\}  {/* Redefinable verbatim end command */
  if(verbinput){ TTH_OUTPUT(yytext);
  }else{
    TTH_CCPY(scratchstring,yytext+5);
    *(scratchstring+strlen(scratchstring)-1)=0;
    if(tth_debug)fprintf(stderr,"End of: %s\n",scratchstring);
    if(strstr(tth_verbenviron,scratchstring)==tth_verbenviron){
      if(tth_titlestate) tth_titlestate=99;
      TTH_TEXCLOSE else{TTH_CLOSEGROUP;TTH_POP_CLOSING;yy_pop_state();
	if(tth_debug)fprintf(stderr,"Popped state\n");}
      /* Scan \end{....} a second time for end of environment */
      if(tth_debug)fprintf(stderr,"environment:%s\nscratchstring:%s\n"
	      ,environment,scratchstring);
      if(!strcmp(environment,scratchstring)){TTH_SCAN_STRING(yytext);}
      *scratchstring=0;
      *tth_verbenviron=0;
    }else{
      TTH_OUTPUT(yytext);     
    }
  }
}

<verbatim,notags>\\tth_endverbinput {
  verbinput=0;
  TTH_TEXCLOSE else{TTH_CLOSEGROUP;TTH_POP_CLOSING;yy_pop_state();}
}
<rawgroup>\\end\{(raw)?html\}  |
<rawgroup>\}  {  
  TTH_TEXCLOSE else{TTH_CLOSEGROUP;TTH_POP_CLOSING;yy_pop_state();}
}
<rawgroup>\{ {
  TTH_OUTPUT(yytext);TTH_PUSH_CLOSING;
  TTH_CCPY(closing,"}");
  yy_push_state(rawgroup);}

 /* Dimensions and Numbers etc. */

<lookforunit>(true)?{WSP}*(cm|in|pc|pt|mm|bp|dd|cc|sp|em|ex|fil) {
  TTH_INC_MULTI;
  yy_pop_state();
  TTH_CCAT(argchar,yytext);
  strcpy(scratchstring,yytext+strlen(yytext)-2); /*unit is last 2 letters */
  if(!tthglue) {
    thesize = scaledpoints(anumber,scratchstring);
  }
  if(tth_debug&1024) fprintf(stderr,"Dimension %d sp, from specified %f %s\n",
			     thesize,anumber,scratchstring);
  *argchar=0; /* Don't think this is used. */
}
<lookforunit>\\tth_hsize { /* The dimension is in \hsizes */
  thesize=100*anumber;
  strcpy(scratchstring,"%");
  yy_pop_state();
  if(tth_debug&1024) fprintf(stderr,"Dimension tth_hsize: %d\n",thesize);
  *argchar=0; /* this is used. */
}
\\tth_hsize       GET_DIMEN; /* Do nothing outside for now */
<lookforunit>\\[a-zA-Z@]+   { /* expand a possible macro */
  TTH_DO_MACRO else { /* pop state if uninterpretable */
    if(tth_debug&1024) fprintf(stderr,"Unknown dimension %s\n",yytext);
    thesize=0;
    yyless(0);
    yy_pop_state();}
}
<lookforunit>\\tthdimen[ ]?\\[a-zA-Z]+  /* Rip this out of the way */
<lookforunit>{NUM} {/* We find a number. Scale instead. Shouldn't be in TeX*/
  if(! sscanf(yytext,"%f",&bnumber) ){
    fprintf(stderr,"**** Uninterpreted scaled dimension value:%s\n",yytext);
    bnumber=1.;
  }
  anumber=anumber*bnumber;
}

<lookfornum,lookforunit>{NL} TTH_INC_LINE;
<lookfornum,lookforunit>{TSP}*     /* Ignore spaces */
<lookfornum>=          /* and equal signs */
<lookfornum>{NUM}  { /* If we find a number store it.*/
  TTH_CCAT(argchar,yytext);
  if(! sscanf(argchar,"%f",&anumber) ){
    if(tth_debug&4)fprintf(stderr,"Uninterpreted dimension value:%s\n",argchar);
    anumber = 0;
  }
/*    if(tth_debug&1024)fprintf(stderr,"Got number: %f\n",anumber); */
  yy_pop_state();
}
<lookfornum>[-+]*        strcat(argchar,yytext);
     /* If this is an unknown token, pop extra lookforunit state too.*/
<lookfornum>\\[a-zA-Z]+ {
  TTH_DO_MACRO
  else{ 
    /* was TTH_CCAT(argchar,yytext); then became yyless(0) now
     presume if argchar !=0 that we need to collect it e.g. in setbox.*/
    if(strlen(argchar)){TTH_CCAT(argchar,yytext);}else  yyless(0);
    if(tth_debug&1024)fprintf(stderr,"Failed lookfornum:%s\n",yytext);
    yy_pop_state();yy_pop_state();
  }
}
<insertnum>({NUM}|\\[a-zA-Z]+)	{
  fprintf(tth_fdout,"%s%s",yytext,argchar);yy_pop_state();}
<lookforfile>{NL} TTH_INC_LINE;
<lookforfile>{TSP}*
<lookforfile>{WSC}+	{TTH_CCPY(argchar,yytext);yy_pop_state();
			if(tth_verb) fprintf(stderr,"File:%s",yytext);}
<glue>{WSP}*(plus|minus)   TTH_INC_MULTI;tthglue=1;GET_DIMEN  
 /* nested glue not allowed */
<glue>{ANY}     tthglue=0;yyless(0);yy_pop_state();

<embracetok>\\begingroup |
<embracetok>\\bgroup |
<embracetok>\{   { /* already embraced */
  strcat(dupstore,"{");
  TTH_SCAN_STRING(dupstore);
  *dupstore=0;
  yy_pop_state();
}

<embracetok>{NL} TTH_INC_LINE;
<embracetok>{TSP}
<embracetok>\\.   |
<embracetok>{WSC} |
<embracetok>\\[a-zA-Z@]+ { /* Enclose a bare token for using as argument.*/
      strcat(dupstore,"{");strcat(dupstore,yytext);strcat(dupstore,"}");
      TTH_SCAN_STRING(dupstore);
      *dupstore=0;
      yy_pop_state();
      }
<swaparg>\\bgroup |
<swaparg>\{  {
  sprintf(scratchstring,"{%s",swapchar);
  TTH_SCAN_STRING(scratchstring);*swapchar=0;yy_pop_state();
}
<swaparg>.  {
  fprintf(stderr,"**** Error: swaparg fault:%s:%s:\n",swapchar,yytext);
  yy_pop_state();}

  /************* count lines ****************/
<discardgroup,falsetext,innerfalse,ortext,matchbrace,getsubp>{NL} TTH_INC_LINE;
<verb,verbatim,notags,rawgroup>{NL}  {
  TTH_INC_LINE;
  fprintf(tth_fdout,"%s",yytext);
  strcpy(scratchstring,"\n");
  if(tth_debug&8192)fprintf(stderr,"Verbatim \\n:%d, \\n code:%d Length:%d\n",(int) *yytext,(int) *scratchstring, (int) strlen(scratchstring));
}
<exptokarg>{WSP}*\{(.\})?  { /* Final route for all cases once expanded. */
  TTH_INC_MULTI;
  if(strlen(expchar)){
    yyless(strcspn(yytext,"{"));
    TTH_PUSH_CLOSING;TTH_CCPY(closing,expchar);
    *expchar=0;yy_pop_state();
    if(tth_debug&8) {
      fprintf(stderr,"Exptok Group {, eqdepth=%d, eqclose=%d, tth_flev=%d, levdelim=%s\n",eqdepth,eqclose,tth_flev,levdelim[eqclose]);
    }
    mkkey(eqstr,eqstrs,&eqdepth);
    tth_flev=tth_flev-99;
    eqclose++;
    tophgt[eqclose]=0;
    levhgt[eqclose]=1;
    *eqstr=0;
    active[eqclose]=1;
  }else{ 
    strcat(exptex,yytext+strcspn(yytext,"{"));
    TTH_SCAN_STRING(exptex);
    if(tth_debug&8){
      fprintf(stderr,"Expansion completed. Rescanning %s\n",exptex);
    }
    *exptex=0;
    yy_pop_state();
  }
}

<exptokarg>({WSC}|\\%)	{
  if(tth_debug&8) fprintf(stderr,
		 "Nothing to expand in exptok[arg]. Rescan:{%s}\n",yytext);
  sprintf(scratchstring,"{%s}",yytext+strlen(yytext)-1);
  TTH_SCAN_STRING(scratchstring);
}
<exptokarg>\\.[a-zA-Z@]* { /* fix for _\| etc */
  if(tth_debug&8)fprintf(stderr,"Exptokarg, expanding:%s\n",yytext);
  TTH_DO_MACRO
  else {
    strcpy(dupstore,"{");strcat(dupstore,yytext);strcat(dupstore,"}");
    TTH_SCAN_STRING(dupstore);
    *dupstore=0;
  }
}

<tokexp>({WSC}|\\%) {
  yyless(0);yy_pop_state();
  if(strlen(exptex)){TTH_SCAN_STRING(exptex); *exptex=0;}
}
<tokexp>\\.[a-zA-Z@]* { /* fix for _\| etc OUT for tokexp. */
  if(tth_debug&8)fprintf(stderr,"Tokexp, expanding:%s\n",yytext);
  TTH_DO_MACRO
  else {
    yy_pop_state();
    yyless(0);
    *dupstore=0;
    if(strlen(exptex)){TTH_SCAN_STRING(exptex); *exptex=0;}
  }
}

<disptab>\$\$	{
  if(*halstring){ /* In a display table has to be a null inline*/
  }else{
    TTH_TEXCLOSE else{
    yy_pop_state();
    /* moved into closing. fprintf(tth_fdout,"</dl>");*/
    TTH_CLOSEGROUP;TTH_POP_CLOSING;
    if(tth_debug&33)fprintf(stderr,"Display Table end.\n");
    }
  }
}

<textbox>\$                  |
<textbox>\begin\{math\}      |
<textbox>\\\(                {
  if(tth_debug&2) 
    fprintf(stderr,"Starting textbox equation, line %d\n",tth_num_lines);
  /*  TTH_OUTPUT(TTH_TEXTBOX2);*/
  if(displaystyle)displaystyle++; 
  mkkey(eqstr,eqstrs,&eqdepth);
  TTH_PUSH_CLOSING;
  yy_push_state(equation);
  TTH_SCAN_STRING("{");
} 
 /* $ Will be superceded by equation grab for non-null eqs */
<notags>\\tth_notageq  |
\$                | 
\\begin\{math\}   |
\\\(     { 
  if(displaystyle) fprintf(stderr,"Starting displaystyle incorrect.\n");
  displaystyle=0;
  tophgt[eqclose]=0;levhgt[eqclose]=1;
  *eqstr=0;
  eqclose=0;
  mkkey(eqstr,eqstrs,&eqdepth);
  if((!tth_inlinefrac)^(strstr(TTH_NAME,"M")!=NULL)) tth_flev=tth_flev-89;
  TTH_PUSH_CLOSING;
  if(!strstr(tth_font_open[tth_push_depth],TTH_ITALO)){
    TTH_CCAT(tth_font_open[tth_push_depth],tth_font_open[0]);
    TTH_CCAT(tth_font_close[tth_push_depth],tth_font_close[0]);
  }
  yy_push_state(equation);
  TTH_SCAN_STRING("{");
 }

\\bmath           

<INITIAL,halign,textsc,uppercase,pargroup,Litemize,Lenumerate,Ldescription>\$[^$]+\$  {
  if(strcspn(yytext,"_^")==1){
    if(tth_debug&3) fprintf(stderr,"Special In line Eq:%s\n",yytext);
    /*
      yyless(1);
        unput(' '); This broke with pushback errors
      Handle subdefer appropriately for specials.
      Hence we use the following more cumbersome but safer approach.
      Really I ought to find a better way to make sure that we can
      accommodate constructs like $^1_2$ using msupsub in mathml.
      The problem seems to be the implied { which never has subscripts.
    */
    *scrstring=0;
    if(strstr(TTH_NAME,"M")){ /* MathML */    strcat(scrstring," ");}
    strcat(scrstring,yytext+1);
    TTH_SCAN_STRING(scrstring);
    *scrstring=0;
  }else{
    if(tth_debug&3) fprintf(stderr,"In line Eq:%s\n",yytext);
    yyless(1);
  }
  TTH_SCAN_STRING("$"); /* Force into other channel above.*/  
 }

<INITIAL,pargroup>\$\$[^$]*\\halign	| 
<INITIAL,pargroup>\$\$[^$]*\\halign([^$]+\$)+\$	{ 
  if(tth_debug&33)fprintf(stderr,"Display Table:\n%s\n",yytext);
  fprintf(tth_fdout,"<dl><dd>");
  yyless(2);
  yy_push_state(disptab);
  TTH_PUSH_CLOSING;  
  TTH_CCPY(closing,"</dd></dl>");
}
 /* Allowing the first half of a display to be recognized as equation is
    problematic. Instead go to halsearch state. 
    Does not permit non-output commands before the halign. TeX does.*/
<INITIAL,Litemize,Lenumerate,Ldescription,pargroup>\$\$ {
  yy_push_state(halsearch);
}

<halsearch>{WSP}  TTH_INC_MULTI;
<halsearch>.*\\halign {
  if(tth_debug&33)fprintf(stderr,"Display Table:\n%s\n",yytext);
  yyless(0);
  yy_pop_state();
  yy_push_state(disptab);
  fprintf(tth_fdout,"<dl><dd>");
  TTH_PUSH_CLOSING;  
  TTH_CCPY(closing,"</dd></dl>");
}
<halsearch>[^ ]  {
  yyless(0);
  yy_pop_state();
  TTH_SCAN_STRING("\\tth_start_equation");
}

 /* Don't recognize display equations except in certain allowed states. */
\\tth_start_equation  |
<INITIAL,Litemize,Lenumerate,Ldescription,pargroup>\$\$([^$]+\$)+\$	{
  {
    if(tth_debug&3) fprintf(stderr,"Display Eq:\n%s\n",yytext);
    if(strstr(yytext,"\\tth_start_equation")==NULL) yyless(2);
    if(strcspn(yytext,"_^")==2){
      if(strstr(TTH_NAME,"M")){ /* MathML */      unput(' ');}
    }
    TTH_SCAN_STRING("{");
    /*
    if(tth_htmlstyle&2){
      TTH_OUTPUT(closing); strcpy(closing,"</div>");
      TTH_OUTPUT("\n<div class=\"p\">\n");}*/
    horizmode=0;
    displaystyle=1;
    *eqstr=0;
    eqclose=0;
    tophgt[eqclose]=0;
    mkkey(eqstr,eqstrs,&eqdepth);
    TTH_PUSH_CLOSING;
    if(!strstr(tth_font_open[tth_push_depth],TTH_ITALO)){
      TTH_CCAT(tth_font_open[tth_push_depth],tth_font_open[0]);
      TTH_CCAT(tth_font_close[tth_push_depth],tth_font_close[0]);
    }
    yy_push_state(equation);
  }
 }

  /* Translate single characters. */
\\char\`(\\)?.  TTH_OUTPUTH(yytext+strlen(yytext)-1);

\\char{WSP}*[0-9]{2,3}   {
  TTH_INC_MULTI;
  sscanf(yytext+5,"%d",&jscratch);
  sprintf(scratchstring,"%c",jscratch);
  TTH_OUTPUTH(scratchstring);
  yy_push_state(removespace);
}
  /* Latin Characters and other non-math but output correctly in math.*/
	   
\\[\'\"^\`~]{SP}+[A-z] { /* Circumvent spaces after accents.*/
  strcpy(scratchstring,yytext);
  unput(*(scratchstring+strlen(scratchstring)-1));
  unput(*(scratchstring+1));unput(*scratchstring);
}

\~       | 
\\nobreakspace{SP}* | 
\\[ ,:>]{SP}*			TTH_OUTPUTH("&nbsp;");
\\\n			TTH_OUTPUTH("&nbsp;");TTH_INC_LINE;
\\;{SP}*			TTH_OUTPUTH("&nbsp;&nbsp;");
\\quad          TTH_OUTPUTH("&nbsp;&nbsp;&nbsp;");
\\qquad          TTH_OUTPUTH("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
\\AE		TTH_OUTPUTH("&#198;");
\\\'A		TTH_OUTPUTH("&#193;");
\\\^A		TTH_OUTPUTH("&#194;");
\\\`A		TTH_OUTPUTH("&#192;");
\\r\{A\} |
\\AA		TTH_OUTPUTH("&#197;");
\\\~A           TTH_OUTPUTH("&#195;");
\"A |		
\\\"A	        TTH_OUTPUTH("&#196;");
 /*  \\c{SP}?C    | */
\\noexpand\\c{SP}?C       	TTH_OUTPUTH("&#199;");
\\\'E		TTH_OUTPUTH("&#201;");
\\\^E		TTH_OUTPUTH("&#202;");
\\\`E		TTH_OUTPUTH("&#200;");
\"E |
\\\"E		TTH_OUTPUTH("&#203;");
\\\`I		TTH_OUTPUTH("&#204;");
\\\'I		TTH_OUTPUTH("&#205;");
\\\^I		TTH_OUTPUTH("&#206;");
\"I |
\\\"I		TTH_OUTPUTH("&#207;");
\\\~N		TTH_OUTPUTH("&#209;");
\\\`O		TTH_OUTPUTH("&#210;");
\\\'O		TTH_OUTPUTH("&#211;");
\\\^O		TTH_OUTPUTH("&#212;");
\\\O		TTH_OUTPUTH("&#216;");
\\\~O		TTH_OUTPUTH("&#213;");
\"O |
\\\"O		TTH_OUTPUTH("&#214;");
\\P		TTH_OUTPUTH("&#182;");
\\S		TTH_OUTPUTH("&#167;");
\\\'U		TTH_OUTPUTH("&#218;");
\\\^U		TTH_OUTPUTH("&#219;");
\\\`U		TTH_OUTPUTH("&#217;");
\"U |
\\\"U		TTH_OUTPUTH("&#220;");
\\\'Y		TTH_OUTPUTH("&#221;");
<verbatim,notags>&  TTH_OUTPUTH("&amp;");
\\\& 		TTH_OUTPUTH("&amp;");
\\ae		TTH_OUTPUTH("&#230;");
\\\`a		TTH_OUTPUTH("&#224;");
\\\'a		TTH_OUTPUTH("&#225;");
\\\^a		TTH_OUTPUTH("&#226;");
\\\~a		TTH_OUTPUTH("&#227;");
\"a |
\\\"a		TTH_OUTPUTH("&#228;");
\\r\{a\} |
\\aa{SP}*            TTH_OUTPUTH("&#229;");
 /*  \\c{SP}?c              | */
\\noexpand\\c{SP}?c    TTH_OUTPUTH("&#231;");
\\\^		TTH_OUTPUTH("^");
\\copyright	TTH_OUTPUTH("&#169;");
\\\'e		TTH_OUTPUTH("&#233;");
\\\^e		TTH_OUTPUTH("&#234;");
\\\`e		TTH_OUTPUTH("&#232;");
\\v{SP}?o		TTH_OUTPUTH("&#240;");
\"e |
\\\"e		TTH_OUTPUTH("&#235;");
<verbatim,notags>\> |
\>	TTH_OUTPUTH("&#62;");
<verbatim,notags>\< |
\<	TTH_OUTPUTH("&lt;");
<verbatim>[ ]   TTH_OUTPUTH("&nbsp;")
\\\`i	|
\\\`\\i{SP}*		TTH_OUTPUTH("&#236;");
\\acute{SP}*\\i   |
\\\'i	|
\\\'\\i{SP}*		TTH_OUTPUTH("&#237;");
\\\^i	|
\\\^\\i{SP}*		TTH_OUTPUTH("&#238;");
\"i |
\\\"i	|
\\\"{SP}*\\i{SP}*		TTH_OUTPUTH("&#239;");
\\\~n		TTH_OUTPUTH("&#241;");
\\\`o		TTH_OUTPUTH("&#242;");
\\\'o		TTH_OUTPUTH("&#243;");
\\\^o		TTH_OUTPUTH("&#244;");
\\\o{SP}* 		TTH_OUTPUTH("&#248;");
\\\~o		TTH_OUTPUTH("&#245;");
\"o |
\\\"o      TTH_OUTPUTH("&#246;");
\\\=		TTH_OUTPUTH("&#175;");
\\pounds{SP}*	TTH_OUTPUTH("&#163;");
\\\~		TTH_OUTPUTH("&#126;");
\\\'u		TTH_OUTPUTH("&#250;");
\\\^u		TTH_OUTPUTH("&#251;");
\\\`u		TTH_OUTPUTH("&#249;");
\"u |
\\\"u	TTH_OUTPUTH("&#252;");
\\\'y		TTH_OUTPUTH("&#253;");
\"y |
\\\"y	TTH_OUTPUTH("&#255;");
\"s             TTH_OUTPUTH("&#223;");
\\3{SP}* |
\\ss{SP}*            TTH_DO_MACRO else{ TTH_OUTPUTH("&#223;");}
  /* Polish character macros:*/
\\k\{A\}          TTH_OUTPUTH("&#260;");
\\\'[{]?C[}]?         TTH_OUTPUTH("&#262;");
\\k\{E\}          TTH_OUTPUTH("&#280;");
\\L\{\}           TTH_OUTPUTH("&#321;");
\\\'[{]?N[}]?         TTH_OUTPUTH("&#323;");
\\\'[{]?S[}]?         TTH_OUTPUTH("&#346;");
\\\'[{]?Z[}]?         TTH_OUTPUTH("&#377;");
\\\.[{]?Z[}]?         TTH_OUTPUTH("&#379;");
\\k\{a\}          TTH_OUTPUTH("&#261;");
\\\'[{]?c[}]?         TTH_OUTPUTH("&#263;");
\\k\{e\}          TTH_OUTPUTH("&#281;");
\\l\{\}           TTH_OUTPUTH("&#322;");
\\\'[{]?n[}]?         TTH_OUTPUTH("&#324;");
\\\'[{]?s[}]?         TTH_OUTPUTH("&#347;");
\\\'[{]?z[}]?         TTH_OUTPUTH("&#378;");
\\\.[{]?z[}]?         TTH_OUTPUTH("&#380;");

\"\`            TTH_OUTPUTH(",,");
\"\'            TTH_OUTPUTH("''");
\"<             TTH_OUTPUTH("&#171;");
\">             TTH_OUTPUTH("&#187;");
\"\|
 /* Convert TeX double quotes to single-character */
\'\'            |
\`\`             TTH_OUTPUTH("\"");
(\\grave|\\acute)\{.\}    {
  if(*(yytext+1)=='g') strcpy(scratchstring,"\\`");
  else  strcpy(scratchstring,"\\'");
  strcat(scratchstring,yytext+strlen(yytext)-3);
  TTH_SCAN_STRING(scratchstring);
}
  /* Remove unwanted braces from around accented characters. */
\\[\'\^\`\"\~]{SP}*\{((\\i{SP}*)|[a-zA-Z])\} |
 /*  \\c{SP}*\{[cC]\}   | */
\\noexpand\\c{SP}*\{[cC]\}   {
  if(tth_debug&8) fprintf(stderr,"Fixing accent:%s\n",yytext);
  *dupstore2=0;
  strncat(dupstore2,yytext,2);
  strncat(dupstore2,yytext+strcspn(yytext,"{")+1,
	 strcspn(yytext,"}")-strcspn(yytext,"{")-1);
  TTH_SCAN_STRING(dupstore2);
  *dupstore2=0;
  }
  /* Unknown diacriticals must terminate safely. 
\\noexpand\\H
\\noexpand\\b 
 Above are safely defined. Below need protection.*/
\\noexpand\\v
\\noexpand\\u
\\noexpand\\d
\\noexpand\\c

\\Box  TTH_OUTPUTH(TTH_BOXCODE);
\\hbar TTH_OUTPUTH(TTH_HBAR);

 /* Various things not being used.
 \\\c		TTH_OUTPUTH("&#184;");
 \?		TTH_OUTPUTH("&#191;");
 \!   		TTH_OUTPUTH("&#161;");
 */
\\jobname {
  TTH_SCAN_STRING(tth_latex_file);
}
 /* This needs to match all the cases of comments otherwise they will
    not allow escaping of the % in that state. Not all are TTH_OUTPUT */
<tokenarg>\\% |
<getdef,getnumargs>\\% |
\\%	  TTH_OUTPUTH("%");
<matchbrace>\\%
<macarg,optag,dupgroup,dupsquare,escgroup>\\(%|\}|\{|\\)   |
<macarg,optag,dupgroup,dupsquare,escgroup,uncommentgroup>{ANY}  {
  if(strcspn(yytext,"\n")==0) {TTH_INC_LINE;TTH_CHECK_LENGTH;}
  strcat(dupstore,yytext);
}
<define>\\%      strcat(defstore,yytext); 
<escgroup,uncommentgroup>%{NL} {
  TTH_INC_LINE;
}
\\break    |
\\newline  |
 /* \\\\\*?({SP}*\[[^\]]*\])?         | */
\\crlf		TTH_SCAN_STRING("\\par");
<psub>\\tthphantom#tthdrop1  {
  if(horizmode) horizmode=1;
  jscratch=indexkey("#1",margkeys,&margmax);
  yy_pop_state();
  if(jscratch!=-1){
    strcpy(dupstore,margs[jscratch]);
    rmdef(margkeys,margs,&margmax); 
    for(js2=0;js2<2*(strlen(dupstore));js2++)TTH_OUTPUT("&nbsp;");
  }else{
    fprintf(stderr,"***** Error. No argument in \\phantom. Line %d\n",tth_num_lines);
  }
  *dupstore=0;
 }

\\\$			TTH_OUTPUTH("$");
\\\#                    TTH_OUTPUTH("#");
\\\{                    TTH_OUTPUTH("{");
\\\}                    TTH_OUTPUTH("}");
 /* In nbsp choice above \\{SP}			TTH_OUTPUTH(" "); */
\\_                     TTH_OUTPUTH("_");
\\!
\\\/			TTH_OUTPUTH(" ");
(--)|(---)              TTH_OUTPUTH("-");
\\l?dots                 TTH_OUTPUTH("..."); /* non-math dots */
 /* Commands to ignore in equations as well as text*/
\\(v|h)center
\\(no)?indent   
\\null

 /* Some problems in equations being confused with this, unless specific. */
\\[a-zA-Z]*(penalty|badness|tolerance|demerits){SP}*=? {
  fprintf(stderr,"**** Removing inappropriate parameter command %s Line %d\n",yytext,tth_num_lines);
  yy_push_state(lookfornum);*argchar=0;
 }
\\global   /* Overridden where necessary for defs.. */

 /* TeX Commands in equations*/
<equation>\\[a-zA-Z@]+   {
  TTH_DO_MACRO
  else if( (ind=indexkey(yytext,countkeys,&ncounters)) != -1) { 
    if(tth_debug&4) fprintf(stderr,"Setting counter %d, %s. ",ind,countkeys[ind]);
    yy_push_state(counterset);
  } else {
    if(!(tth_debug&32768))
      fprintf(stderr,"**** Unknown command %s in equation, Line %d\n"
	      ,yytext,tth_num_lines);
    strcat(eqstr,yytext);
  }
 }
 /* Default equation action may no longer be needed, but not sure. 21 Mar*/
<equation>{WSC}  {
  strcat(eqstr,yytext);
 }

\\end\{document\} yy_scan_string("}\\end");
 /* Latex default (unknown) environment */
\\begin\{[a-zA-Z]*\*?\} {
  TTH_CCPY(environment,strstr(yytext,"{")+1);
  environment[strlen(environment)-1]=0;
  TTH_DO_MACRO
  else{
    environment[0]=0;
    fprintf(stderr,"**** Unknown or ignored environment: %s Line %d\n"
	    ,yytext,tth_num_lines);
  }
  TTH_PUSH_CLOSING;
     /*This is balanced by the \egroup just below.*/
 }
\\end\{[a-zA-Z]*\*?\}	 {
  ind=indexkey(yytext,keys,&nkeys);
  TTH_SCAN_STRING("\\egroup");
  if(ind != -1) { /* This was defined by newenvironment */
    TTH_SCAN_STRING(defs[ind]);
    environment[0]=0;
    yy_push_state(psub);
    if(tth_debug&8) fprintf(stderr,"Using definition %d= %s in end\n"
			 ,ind,defs[ind]);
  }
 }
\\begin{WSP}+ {
  TTH_INC_MULTI;
  if(strstr(yytext,"\n")){TTH_INC_LINE;}
  fprintf(stderr,
   "**** Warning! Bad LaTeX Style. Space after \\begin. Line %d\n",tth_num_lines);
  unput('n');unput('i');unput('g');unput('e');unput('b');unput('\\');
}
\\end{WSP}+\{ {
  TTH_INC_MULTI;
  if(strstr(yytext,"\n")){TTH_INC_LINE;}
  fprintf(stderr,
   "**** Warning! Bad LaTeX Style. Space after \\end Line %d\n",tth_num_lines);
  unput('{');unput('d');unput('n');unput('e');unput('\\');
}

<verb>.   {
  if(*yytext == *chr1){
    TTH_TEXCLOSE else{
      TTH_CLOSEGROUP;TTH_POP_CLOSING;
      yy_pop_state();
    }
  }else{
    if(*yytext == '&') {TTH_OUTPUTH("&amp;");}
    else if(*yytext == '<') {TTH_OUTPUTH("&lt;");}
    else if(*yytext == '>') {TTH_OUTPUTH("&gt;");}
    else if(*yytext == ' ') {TTH_OUTPUTH("&nbsp;");}
    else {TTH_OUTPUTH(yytext);}
  }
 }

  /* Special escape sequences in rawgroup */
<rawgroup>\\(\#|\%|\\)   TTH_OUTPUT(yytext+1);
  /* Don't set horizmode for whitespace.*/
<textbox,uppercase,textsc>[ \t]*       TTH_OUTPUT(yytext);
 /* Default action */
<textbox,uppercase,textsc,rawgroup,verbatim,notags>.   horizmode=1;TTH_OUTPUT(yytext);
  /* Normal action. Set to horizontal mode if not space*/
[ \t]*       fprintf(tth_fdout,"%s",yytext);
 /* Default action */
  .	    horizmode=1;fprintf(tth_fdout,"%s",yytext);

  /* Delete in certain states. */
<lookforunit,lookfornum>.  yyless(0);yy_pop_state();      
<htemplate,tokenarg>.

<error>.|\n {
  if(tth_ercnt==0){
    fprintf(stderr,"%s",yytext);
    tth_ercnt=0;
    fprintf(stderr,"\n");TTH_EXIT(1);
  }else if(tth_ercnt>0){  fprintf(stderr,"%s",yytext);tth_ercnt--;
  }else{tth_ercnt=0;TTH_EXIT(tth_erlev);} ;
}

\\leavevmode    horizmode=1;
\\leavehmode    {TTH_PAR_ACTION}
\\tt[hm]unknown       yy_push_state(unknown);
\\addvspace{SP}*    yy_push_state(unknown);
\\catcode fprintf(stderr,"**** DANGER: Catcode changes not honored. Expect abnormal behavior. Line %d\n",tth_num_lines);

 /* Ignore quietly */
\\spacefactor{SP}*{NUM}
\\linebreak{SP}*(\[{NUM}\])?
\\nolinebreak{SP}*(\[{NUM}\])?
\\-
\\magnification[ =]*{NUM}?
\\magstep[0-5]
\\magstephalf
 /*\\line   | */
\\ht[0-9]+
\\wd[0-9]+
\\dp[0-9]+
\\ht                |
\\wd                |
\\dp { /* Dump the argument. Might be used instead of matchbrace. */
  TTH_TEX_FN("#tthdrop1",1);
}
\\box[0-9]+               |
\\copy[0-9]+              |
\\un(h|v)(box|copy)[0-9]+ {
  sscanf(yytext+strcspn(yytext,"0123456789"),"%d", &js2);
  js2++;
  roman(js2,scratchstring);
  sprintf(scrstring,"\\tthbox%s",scratchstring);
  TTH_SCAN_STRING(scrstring);
}

\\bibdata\{   {
  fprintf(stderr,"%s","\nUnusual bibdata command; if natbib not explicit,\n\
maybe insert the following in the preamble:\n\
%%tth: \\usepackage{natbib} % Tells tth/m to use natbib.\n\
%%tth: \\NAT@numberstrue % If you want number-style citations\n\n");
  TTH_INC_MULTI;yy_push_state(matchbrace);
}
  
\\nobreak           |
\\usebox            |
\\box               |
\\copy              |
\\un(h|v)(box|copy) |
\\protect |
\\vfill |
\\nopagenumbers   |
\\resizebox({SP}*\{[^\}]\}){2}   |
\\raisebox{BRCG}({SP}?\[[^\]]*\]){0,2}   |
\\[vm]box   |
\\relax   |
\\newblock   |
\\maketitle   |
\\ignorespaces   |
\\smash   if(horizmode)horizmode=1;
\\vphantom\{ |
\\citation\{ |
\\bibstyle\{ |
\\bibliographystyle\{ |
\\select@language{SP}*\{ |
\\tt[hm]dump{SP}*\{  |
\\hyphenation\{    TTH_INC_MULTI;yy_push_state(matchbrace);

\\tth_eof  |
\\endinput |
\\end	|
<<EOF>>		{
  if(!strcmp(yytext,"\\end")) {
    tth_stack_ptr=0; 
    if(!ftntno){
      TTH_INC_LINE;
      if(tth_debug&1024 && !(tth_stack_ptr||ftntwrap)) fprintf(stderr,"\n");
       /*Terminate the diagnostic*/
    }/*  Count the last line if it is \end */
  }
  /*Function returns here*/
  if ( --tth_stack_ptr < 0){
    TTH_CLOSEGROUP;*closing=0;
    if(ftntno){
      TTH_SCAN_STRING("\\special{html:<hr /><h3>}\\tthfootnotes:\\special{html:</h3>\n}");
      ftntno=0;
      if(tth_splitfile){ /*sf*/
	strcpy(filenext,"footnote.html");/*sf*/
	TTH_SCAN_STRING("\\tthsplittail\\tthsplitinv\\tthsplittop\\tthfileupd"); /*sf*/
      }/*sf*/
      }else{
	if(tth_debug&4096)fprintf(stderr,"ftntwrap:%d,",ftntwrap);
	if(ftntwrap < nkeys){      /* Footnote wrap-up. Search keys. */
	  if(tth_debug&4096)fprintf(stderr," %s\n",keys[ftntwrap]);
	  yy_delete_buffer( YY_CURRENT_BUFFER );/*leakfix*/
	  if(strstr(keys[ftntwrap],"tthFtNt")){
	    {TTH_PAR_ACTION};
	    fprintf(tth_fdout,"<a id=\"%s\"></a>",keys[ftntwrap]+1);
	    if(tth_debug&256)fprintf(stderr,"Footnote key %d, scanning: %s\n",
				     ftntwrap,defs[ftntwrap]);
	    yy_scan_string(defs[ftntwrap]);yy_push_state(psub);
	  } else yy_scan_string("\\end");
  	  tth_stack_ptr++;
	  /*	  tth_stack_ptr=1;*/
	  ftntwrap++;
	}else{	
	  if(tth_indexfile){
	    /* We no longer remove it because we use different name.
	    sprintf(scratchstring,"%s %s.ind%s",RMCMD,tth_latex_file,RMTERM);
	    system(scratchstring);
	    */
	    tth_indexfile=NULL;
	  }
	  if(tth_splitfile)fprintf(tth_fdout,"<hr /><a href=\"index.html\">%s</a>",TTH_HEAD);/*sf*/
	  if(tth_debug&4096)fprintf(stderr,"Terminating.\n");
	  fflush(stdout);
	  yyterminate();
	}
      }
  }else{
    if(eofrmv[tth_stack_ptr] == 11){ /*Index ref in toc*/
      if(tth_splitfile)/*sf*/
	{fprintf(tth_fdout,"<a href=\"docindex.html#tth_sEcindex\">Index</a><br />");}else/*sf*/
	  {fprintf(tth_fdout,"<a href=\"#tth_sEcindex\">Index</a><br />");}
      eofrmv[tth_stack_ptr] = 0; /* Do it only once. */
    }else{
      /*horizmode=0;  for removespace caused uppercase problem*/
      if(eofrmv[tth_stack_ptr]) yy_push_state(removespace);
    }
    if(tth_debug&16) fprintf(stderr,
			     "EOF encountered: level=%d rmv=%d\n",
			     tth_stack_ptr, eofrmv[tth_stack_ptr]);
    yy_delete_buffer( YY_CURRENT_BUFFER );
    yy_switch_to_buffer(include_stack[tth_stack_ptr] );
  }
}
<equation>\\[a-zA-Z0-9]*{SP}*= { /* Don't suppose glue command in equations */
  TTH_CCPY(argchar,yytext);
  strcpy(argchar+strlen(argchar)-1,"\n=");
  TTH_SCAN_STRING(argchar);
  *argchar=0;
}

\\footline{SP}*=?   yy_push_state(unknown);

  /* Format looks like counter or dimension setting */
\\[a-zA-Z0-9]*{SP}*= {
  TTH_CCPY(argchar,yytext);
  argchar[strcspn(yytext," =")]=0;
  if( (ind=indexkey(argchar,countkeys,&ncounters)) != -1 ){
    if(tth_debug&4) fprintf(stderr,"Setting counter %d, %s\n",ind,countkeys[ind]);
    yy_push_state(counterset);
  } else if((ind=indexkey(argchar,keys,&nkeys)) != -1 ){ /*defined command*/
    yyless(strcspn(yytext," ="));
    TTH_SCAN_STRING(argchar);
    *argchar=0;
  } else {
    if((!strstr(unknownstring,yytext)||tth_debug)&&!(tth_debug&32768)){
      fprintf(stderr,"**** Unknown parameter/dimension/glue command %s Line %d\n",yytext,tth_num_lines);
      if(!strstr(unknownstring,yytext) &&
	 strlen(unknownstring)+strlen(yytext) < TTH_UNKS_LEN)
	strcat(unknownstring,yytext);
    }
   yy_push_state(glue); /* In case glue */
   GET_DIMEN
  }
 }    

<INITIAL,titlecheck,stricttitle>\\[a-zA-Z]+font[0-9]+   |
\\[a-zA-Z@]+              { /* Not a tth native command */
  TTH_DO_MACRO
  else if( (ind=indexkey(yytext,countkeys,&ncounters)) != -1) { 
    if(tth_debug&4) fprintf(stderr,"Setting counter %d, %s\n",ind,countkeys[ind]);
    yy_push_state(counterset);
  } else {
    if((!strstr(unknownstring,yytext)||tth_debug)&&!(tth_debug&32768)){
      fprintf(stderr,"**** Unknown command %s, (%d user-defined) Line %d\n",
	    yytext,nkeys-nbuiltins,tth_num_lines); 
      if(!strstr(unknownstring,yytext)&&
	 strlen(unknownstring)+strlen(yytext) < TTH_UNKS_LEN)
	strcat(unknownstring,yytext);
    }
    yy_push_state(unknown);
  }
 }


<unknown>\{    yy_push_state(matchbrace);
<unknown>\[[^\]]*\]   TTH_INC_MULTI;
<unknown>{ANY}       yy_pop_state();yyless(0);

<psub>(\\\\|\\\#)  strcat(psubstore,yytext);
<psub>.     strcat(psubstore,yytext);
<psub>{NL}    TTH_INC_LINE;strcat(psubstore,yytext);
<psub>##    {
  strcat(psubstore,"#");
  if(tth_debug&8) fprintf(stderr,"Double # added to %s\n",psubstore);
 }
			   /* Changed * to + here 4 Nov 07 */
<psub>(\\[a-zA-Z]+)?#[1-9] { /* Add space after a command string, in case */
  if( (js2 = strcspn(yytext,"#")) ){
    strcpy(scratchstring,yytext);
    if(!strstr(yytext,"\\verb")){/*Don't add space after \verb*/
      strcpy(scratchstring+js2," ");
    }else {*(scratchstring+js2)=0;}
    strcat(psubstore,scratchstring);
  }
  jscratch=margmax-jarg+1;
  i=indexkey(yytext+js2,margkeys,&jscratch);
  if(tth_debug&8)fprintf(stderr,"%s argument search starting at %d finds %d\n",
			 yytext,jscratch,i);
  if(i != -1) {
    strcat(psubstore,margs[i]);
  } else {
    fprintf(stderr,"Could not find argument %s on macro arg stack\n",yytext);
  }
  }
<psub>#tthdrop[0-9] {
  sscanf((yytext+strlen(yytext)-1),"%d",&i);
  if(tth_debug&8) fprintf(stderr,"dropping %d args\n",i);
  for (jscratch=0;jscratch<i;jscratch++) rmdef(margkeys,margs,&margmax);
  yy_pop_state();
  TTH_SCAN_STRING(psubstore);
  if(tth_debug&8) fprintf(stderr,"Scanning substituted text:%s\n",psubstore);
  *psubstore=0;
  }
<tokenarg,lookfornum,macarg,optag>#tthdrop[0-9] |
#tthdrop[0-9] fprintf(stderr,"**** Internal Error: encountered %s\n",yytext);

<delimint>{CMNT} {TTH_INC_MULTI;}
<delimint>\\(\\|%|\$|&|\#)    |
<delimint>{ANY}  {
  /* duplicated below  if(strcspn(yytext,"\n")==0) TTH_INC_LINE; */
  if(tth_debug&8){
    fprintf(stderr,"Horizmode=%d Whitespace=%d ",horizmode,whitespace);
    fprintf(stderr,
	    "yytext:%s, Template Remaining:%s\n",yytext,chscratch);
  }
  horiztemp=1; /* Default */
  strcpy(scratchstring,yytext);
  if(strstr(yytext,"\n") != NULL) {
    TTH_CHECK_LENGTH;
    TTH_INC_LINE;
    if(!whitespace){
      strcpy(scratchstring," ");
    } else {
      *scratchstring=0;
      if(whitespace==1)strcat(dupstore," "); /* save spaces if compressed*/ 
    }
    whitespace=2;
    if(horizmode==1){horiztemp=-1;}
    else if(horizmode==-1){
      horiztemp=0;
      strcpy(scratchstring,"\\");
      TTH_SCAN_STRING("par");
      if(tth_debug&8)fprintf(stderr,"Got implied \\par in parameter\n");
      if(*scratchstring!=*chscratch){
	fprintf(stderr,
	 "**** The \\par doesn't match the template character:%s\n",chscratch);
	fprintf(stderr,
         "**** Error. Probable runaway delimited parameter. Line %d.\n"
		,tth_num_lines);
	TTH_EXIT(3);
      }
    }
    else horiztemp=0;
  }else if(*yytext == '\t' || *yytext == ' ') {
    if(!whitespace){
      strcpy(scratchstring," "); 
    }else{
      *scratchstring=0;
      if(whitespace==1)strcat(dupstore," ");
    }
    whitespace=2;
    horiztemp=horizmode;
  }else if(strstr(yytext,"\\") && strlen(yytext)==2 ) { 
    strcpy(scratchstring,yytext+1);
    strcat(dupstore,"\\");
    if(whitespace==1)whitespace=2; else whitespace=0;
  }else if(*yytext == '\\') {
    whitespace=1;
  }else if( (*yytext>63 && *yytext<91) || (*yytext>96 && *yytext<123)){
    if(whitespace==1)whitespace=1; else whitespace=0;
  }else{
    if(whitespace==1)whitespace=2; else whitespace=0;
  }
  strcat(dupstore,scratchstring);
  if(*chscratch == '#' ) { /* Nondelimited argument. */
    if(tth_debug&8) fprintf(stderr,"Non-delimited argument; jarg=%d\n",jarg);
    chs2=chscratch+2;
    chscratch=chs2;
    if(strstr(yytext,"\n")){tth_num_lines--;}/*don't count twice*/
    yyless(0);
    horiztemp=horizmode;
    *dupstore=0;
    if(jarg){ /* Not for zeroth argument */
      bracecount=-1;
      yy_push_state(macarg);
      yy_push_state(embracetok);
    } else jarg++;
  }else if(*chscratch == '{'){ /* Last argument is nondelimited */
    jargmax=jarg;  /* use standard form of macarg */
    yyless(0);
    horiztemp=horizmode;
    *dupstore=0;
    bracecount=-1;
    yy_pop_state();
    yy_push_state(macarg);
    yy_push_state(embracetok);
  } else if(*chscratch == *scratchstring){   /* Normal delimited case. */
    chscratch++;
    if((*chscratch == '#')||(*chscratch == '{')){ /* Matched pattern seg */
      sprintf(argchar,"#%d",jarg);
      if(tth_debug&8)fprintf(stderr,"Matched Pattern:%s: jarg=%d, argchar=%s\n"
			   ,dupstore,jarg,argchar);
      jscratch=0;
      /* dupstore[strlen(dupstore)-(chscratch-chs2-compression)]=0;*/
      dupstore[strlen(dupstore)-(chscratch-chs2)]=0;
      if(jarg){
	mkdef(argchar,margkeys,dupstore,margs,
	      &jscratch,margn,&margmax);
	if(tth_debug&8){
	  i=indexkey(argchar,margkeys,&margmax);
	  fprintf(stderr,"Delimited Argument:%s: index %d Def %s\n",
		  argchar,i,margs[i]);
	}
      }
      if(*chscratch == '{') { /* Completed Template */
	jarg=1;
	yy_pop_state();
	TTH_SCAN_STRING(defs[ind]);
	if(tth_debug&8)fprintf(stderr,"Using definition %s (%d) = %s.\n",
			  keys[ind],ind,defs[ind]);
	yy_push_state(psub);
      }else{ /* Look for next argument */
	jarg++;
	chs2=chscratch+2;
	chscratch=chs2;
      }
      *dupstore=0;
      /* compression=0;*/
    }
  }else{ /* Mismatch. Start over. */
    chscratch=chs2;
    if(*scratchstring == '{') { /* Nested braces protect against matching. */
      bracecount=0; storetype=10; /* Was 4 till new definitions */
      yy_push_state(dupgroup);
    }
  }
  horizmode=horiztemp;
}
<removespace>{NL} {
  TTH_CHECK_LENGTH;
  TTH_INC_LINE;
  if(horizmode==1){
    horizmode=-1;
    yy_push_state(parcheck);
    TTH_OUTPUT(yytext);
  }else if(horizmode==-1) {
    fprintf(stderr,"**** Abnormal NL, removespace. Line %d\n",tth_num_lines);
  }
}
<removespace>[ \t]
<removespace>[^ ]  {
  if(tth_debug&16)fprintf(stderr,"End of removespace:%s\n",yytext);
  yy_pop_state();yyless(0);
 }
<ruledim>{WSP}*(width|height|depth)      TTH_INC_MULTI;GET_DIMEN;
<ruledim>{ANY}   yyless(0);yy_pop_state();   

%%
 /********************************** CODE ******************************/

int main(argc,argv)
int argc;
char *argv[];
{
int raw=0,httpcont=0;
int i,ilatex=0,ititle=1;
char *spoint=0;
char ttver[]=TTH_VERSION;
char ttname[20];
time_t secs_elapsed;
time_t make_time=939087164;
char timestr[]="On 00 Jan 2000, 00:00.";
FILE *fdin=0;
int horizmode=1; /* In signoff use font tags not divs */
char main_input[TTH_CHARLEN];
char main_output[TTH_CHARLEN];
  tth_fdout=stdout; 
  if((spoint=strstr(tth_DOC,"XXXX"))){ /* Make version strings */
    strcpy(ttname,"Tt");
    strcat(ttname,TTH_NAME);
    strncpy(spoint-10-strlen(ttname),ttname,strlen(ttname));
    strncpy(spoint,ttver,strlen(ttver));
    if(strstr(TTH_NAME,"M")){ /* MathML */
      tth_mathitalic=0; /* Don't use for mml */
      tth_htmlstyle=2; /* Use default XHTML style for MathML*/
#ifdef TTM_LAPSED
      time(&secs_elapsed);
      /*fprintf(stderr,"Maketime=%ld, elapsed=%ld",(long)make_time,
	(long)secs_elapsed); */
      if(make_time!=939087164){
	if(secs_elapsed>make_time+30*24*60*60){
	  fprintf(stderr,TTM_LAPSED);
	  TTH_EXIT(1);
	}
      }
#else
      secs_elapsed=make_time;
#endif
      while((spoint=strstr(tth_DOC,"tth")))strncpy(spoint,"ttm",3);
      while((spoint=strstr(tth_DOC,"TtH")))strncpy(spoint,"TtM",3);
      while((spoint=strstr(tth_USAGE,"tth")))strncpy(spoint,"ttm",3);
      while((spoint=strstr(tth_USAGE,"TtH")))strncpy(spoint,"TtM",3);
      while((spoint=strstr(tth_DOC,"(TeX-to-HTML")))
	strncpy(spoint,"  Tex to MathML/HTML translator.       ",
		strlen("  Tex to MathML/HTML translator.       "));
    }
  }
  for (i=1;i<argc;i++){
    if(strspn(argv[i],"-") != 1){ /*Non-switch*/
      if(strlen(tth_latex_file)){
	fprintf(stderr,
       "**** Invalid switch, %s, or input file already specified.\n",argv[i]); 
	return 1;
      }
      strcpy(tth_latex_file,argv[i]);


      if(!(spoint=strstr(tth_latex_file,".tex")))
	spoint=strstr(tth_latex_file,".TEX");
      if(tth_latex_file+strlen(tth_latex_file)-spoint==4)*spoint=0;
      strcpy(main_input,tth_latex_file);
      strcat(main_input,".tex");
      strcpy(main_output,tth_latex_file);
      strcat(main_output,".html");
      fdin=fopen(main_input,"r");
      if(fdin) tth_fdout=fopen(main_output,"w");
      if(fdin && tth_fdout){
	yyin=fdin;
	fprintf(stderr,"Translating %s to %s\n",main_input,main_output);
      }else{
	fprintf(stderr,"**** Invalid switch or file: %s\n",argv[i]); 
	return 1;
      }
    }else{
      switch(*(argv[i]+1)){
      case 'a': tth_autopic=1;break;
      case 'c': httpcont=1;break;
      case 'd': tth_delimdef=0;break;
      case 'e': sscanf(argv[i]+2,"%d",&tth_epsftype);break;
      case 'f': sscanf(argv[i]+2,"%d",&tth_flev0); 
	fprintf(stderr,"Fraction level %d\n",tth_flev0);break;
      case 'g': tth_fontguess=0;break;
      case '?': {if(*(argv[i]+2)=='q'){ printf("%s",tth_DOCQ); }
                 else {printf("%s",tth_USAGE);}; return 0;};
      case 'H': case 'h': fprintf(stderr,"%s",tth_DOC); return 0;
      case 'I': case 'i': if(tth_mathitalic==1){
	  strcpy(tth_font_open[0],"<i>");
	  strcpy(tth_font_close[0],"</i>");
	  TTH_CCPY(tth_fonto_def,tth_font_open[0]);
	  TTH_CCPY(tth_fontc_def,tth_font_close[0]);
        }else{
	  /* Make all (even multi-letter) identifiers italic*/
	  strcpy(tth_font_open[0],TTH_ITALO);
	}
	break;
      case 'j': tth_indexpage=9999;
	if(*(argv[i]+2)) sscanf(argv[i]+2,"%d",&tth_indexpage); 
	fprintf(stderr,"HTML index page length %d\n",tth_indexpage);break;
      case 'k': strcpy(tth_latex_file,argv[i]+2);break;
      case 'L': case 'l':{
	if(strlen(tth_latex_file)){
	  fprintf(stderr,
	      "Do not use both -L switch and file command-line argument %s\n",
		  main_input);
	  return 1;
	}
	strcpy(tth_latex_file,argv[i]+2);
	fprintf(stderr,"Including LaTeX commands\n");
	ilatex=1;
	break;
      }
      case 'n': 
	tth_titlestate=4;
	if(*(argv[i]+2)) sscanf(argv[i]+2,"%d",&tth_titlestate);
	break;
      /*case 'n': tth_multinum=0;break; disable 3.0*/
      case 'P': case 'p':
	if(!strcmp(argv[i]+2,"NULL")){tth_allowinput=0;}
	TTH_CCPY(tth_texinput_path,argv[i]+2);break;
      case 'r': raw=1;if(*(argv[i]+2)) sscanf(argv[i]+2,"%d",&raw);break;
      case 's': tth_splitfile=1;break; /*sf*/
      case 't': tth_inlinefrac=1;break;
      case 'u': tth_unicode=1;
	if(*(argv[i]+2)) sscanf(argv[i]+2,"%d",&tth_unicode); 
	fprintf(stderr,"HTML unicode style %d\n",tth_unicode);break;
      case 'v': tth_verb=1; tth_debug=1;
	if(*(argv[i]+2)=='?'){fprintf(stderr,"%s",tth_debughelp);return 1;}
	else if(*(argv[i]+2)) sscanf(argv[i]+2,"%d",&tth_debug);
        break;
      case 'V': tth_verb=1; tth_debug=2048+256+7;break;
      case 'w': sscanf(argv[i]+2,"%d",&tth_htmlstyle); 
	fprintf(stderr,"HTML writing style %d\n",tth_htmlstyle);
	if(!tth_htmlstyle&1) ititle=0;break;
      case 'x':strcpy(tth_index_cmd,argv[i]+2);break;
      case 'y':  sscanf(argv[i]+2,"%d",&tth_istyle); 
	fprintf(stderr,"Equation layout style %d\n",tth_istyle);
	break;
    }
      if(tth_verb)fprintf(stderr,"Debug level %d\n",tth_debug);
    }
  }
  if((spoint=getenv("TTHINPUTS"))){
    TTH_CCAT(tth_texinput_path,PATH_SEP);TTH_CCAT(tth_texinput_path,spoint);}
  if(httpcont) fprintf(tth_fdout,"Content-type: text/HTML\n\n");
  if(tth_splitfile) fprintf(tth_fdout,TTH_MIME_HEAD); /*sf*/
  if(raw!=1){
    fprintf(tth_fdout,TTH_DOCTYPE);
    fprintf(tth_fdout,TTH_GENERATOR,TTH_NAME,TTH_VERSION);
    fprintf(tth_fdout,TTH_ENCODING);
    /*if(tth_htmlstyle&2) */
    fprintf(tth_fdout,"%s",TTH_P_STYLE);
    if(tth_istyle)fprintf(tth_fdout,"%s",TTH_STYLE);
    if(!(tth_htmlstyle&4))fprintf(tth_fdout,"%s",TTH_SIZESTYLE);
  }
  if(tth_flev0) tth_flev0=tth_flev0+2; /* Increment to compensate for dummy levels. */
  if(ititle && raw!=1){
    if(tth_htmlstyle&3){
      yy_push_state(stricttitle); 
    }else{
      yy_push_state(titlecheck);
    }
  }
  yy_push_state(builtins);
  if(ilatex)yy_push_state(latexbuiltins);
  /* if(tth_debug)
    fprintf(stderr,"Starting yylex\n"); */
  yylex();
  fprintf(stderr, "Number of lines processed approximately %d\n", 
	  tth_num_lines-1);
  /* Time stamp */
  time(&secs_elapsed);
  spoint=ctime(&secs_elapsed);
  strncpy(timestr+3,spoint+8,2);
  strncpy(timestr+6,spoint+4,3);
  strncpy(timestr+10,spoint+20,4);
  strncpy(timestr+16,spoint+11,5);
  if(raw==2)*timestr=0; /* Not if -r2 */
  if(raw!=1 && raw != 4){
    fprintf(tth_fdout,"\n<br /><br /><hr /><small>File translated from\n\
T<sub>%sE%s</sub>X\nby <a href=\"http://hutchinson.belmont.ma.us/tth/\">\n\
T<sub>%sT%s</sub>%s</a>,\n\
version %s.<br />%s</small>\n",TTH_SMALL,TTH_SIZEEND,TTH_SMALL,TTH_SIZEEND
		    ,TTH_NAME,TTH_VERSION,timestr);
  }
  if(raw!=1){
    if(tth_htmlstyle&3)fprintf(tth_fdout,"</div></body>");
    fprintf(tth_fdout,"</html>\n");
  }
  if(tth_debug&16) fprintf(stderr, "Exit pushdepth= %d\n",tth_push_depth);
  /* silence gcc warnings:*/ if(1==0){yy_top_state();input();}
  return 0;
} /* end main */

void tth_push(arg)
char arg[];
{
	if(tth_debug&16) fprintf(stderr,"tth_push:%s depth:%d\n",\
			arg,tth_push_depth);	
	if(tth_push_depth == TTH_MAXDEPTH) {
	  fprintf(stderr,
		  "**** Error Fatal: Attempt to exceed max nesting:%d\n",
		  tth_push_depth);
	  TTH_FATAL(6);
	}else{
	  strcpy(tth_closures[tth_push_depth],arg);
	  strcpy(tth_font_open[tth_push_depth+1],
		 tth_font_open[tth_push_depth]);
	  strcpy(tth_font_close[tth_push_depth+1],
		 tth_font_close[tth_push_depth]);
	  tth_push_depth++;
	}
	arg[0]=0;
}

void tth_pop(arg)
char arg[];
{
  if(tth_push_depth < 1){ 
    fprintf(stderr,"**** Error: Fatal. Apparently too many }s.\nCheck for TeX errors or incompatibilities before line %d,\nnext material      ",tth_num_lines);
    /*TTH_FATAL(1);*/
    yy_push_state(error);
    tth_ercnt=40;
  }else{
    tth_push_depth--;
    strcpy(arg,tth_closures[tth_push_depth]);
    if(tth_debug&16) fprintf(stderr,"tth_pop:%s depth:%d\n",\
			    arg,tth_push_depth);	
  }
}

/* ********************************************************************
   Process epsbox. If epsftype=0 put link. Arg is the file name.
   epsftype=1 Convert the ps or eps file to a gif reference. 
   epsftype=2 Ditto but inline it. epsftype=3 inline an iconized version.*/
void tth_epsf(arg,epsftype)
char *arg;
int epsftype;
{
#define NCONV 2
#define NGTYPES 3
 char *gtype[NGTYPES]={"png","gif","jpg"};
 char commandstr[150]={0};
 char filestr[150]={0};
 char filestr1[150]={0};
 char filestr2[150]={0};
 FILE *giffile;
 int sys=SUCCESS;
 int c,i,psfound;
 char *ext;
 char eqstr[1]; /*dummy here for tthfunc*/
 *eqstr=0;        /*silence warnings */ 
 ext=arg;         /*silence warnings */
if(epsftype==0){
  fprintf(tth_fdout,"<a href=\"%s\">Figure</a>",arg);
}else{
  c=0;
  for(i=1;i<=(strlen(arg)<4 ? strlen(arg) : 4);i++){
    ext=arg+strlen(arg)-i;
    if(*ext=='.'){
      c=i;
      break;
    }
    ext=ext+i;
  }
  if(c){
    if(strcmp(ext,".eps") && strcmp(ext,".EPS")
       && strcmp(ext,".ps") && strcmp(ext,".PS")
       && strcmp(ext,".pdf") && strcmp(ext,".PDF"))
      {
      fprintf(stderr,"Not a [e]ps file: %s, no conversion\n",arg);
      if(epsftype==1) fprintf(tth_fdout,"<a href=\"%s\">Figure</a>",arg);
      if(epsftype==2) fprintf(tth_fdout,"<img src=\"%s\" alt=\"%s\" />",arg,arg);
      return;
    }
  }
  /* c=length of extension.*/
  strcpy(filestr,arg);
  giffile=fopen(filestr,"r");
  psfound=0;
  if(giffile == NULL){ /* Try possible file names */
    if(tth_debug&32)fprintf(stderr,"Graphic Input File %s not found.\n",filestr);
    if(c==0){
      strcat(filestr,".eps");
      giffile=fopen(filestr,"r");
      if(giffile == NULL){
	if(tth_debug&32)fprintf(stderr,"Graphic Input File %s not found.\n",filestr);
	strcpy(filestr,arg); strcat(filestr,".ps");
	giffile=fopen(filestr,"r");
	if(giffile == NULL){
	  if(tth_debug&32)fprintf(stderr,"Graphic Input File %s not found.\n",filestr);
	  strcpy(filestr,arg); strcat(filestr,".pdf");
	  giffile=fopen(filestr,"r");
	  if(giffile == NULL){
	    if(tth_debug&32)fprintf(stderr,"Graphic Input File %s not found.\n",filestr);
	    psfound=0;
	    strcpy(filestr,arg); /*Restore original name*/
	  }else{
	    fprintf(stderr,"Found %s. ",filestr);
	    psfound=1;
	    c=4;
	  }
	}else{
	  fprintf(stderr,"Found %s. ",filestr);
	  psfound=1;
	  c=3;
	}
      }else{
	fprintf(stderr,"Found %s. ",filestr);
	psfound=1;
	c=4;
      }
    }
  }else{psfound=1;}
  strcat(filestr1,filestr); /* The file we found for input if any.*/
  filestr[strlen(filestr)-c]=0;
  sys=SUCCESS+1;
  for(c=0;c<NGTYPES;c++){ /* Check for already translated files */
    sprintf(filestr2,"%s.%s",filestr,gtype[c]);
    if(tth_debug&32)fprintf(stderr,"Trying %s\n",filestr2);
    if ((giffile=fopen(filestr2,"r")) != NULL){
      fprintf(stderr,"Graphic %s exists. No conversion.\n",filestr2);
      strcpy(filestr,filestr2);
      sys=SUCCESS;
      fclose(giffile);
      break;
    }
  }
  if(psfound){
    if(sys!=SUCCESS){ /* No existing graphic. Translate. */
      for(c=0;c<NCONV;c++){
	sprintf(filestr2,"%s.%s",filestr,gtype[c]);
	sprintf(commandstr,"ps2%s %s %s",gtype[c],filestr1,filestr2);
	if(epsftype==3){ /* Icon version of ps2pnm/gif with 3 arguments */
	  sprintf(commandstr+strlen(commandstr)," %s_icon.%s",filestr,gtype[c]);
	}
	fprintf(stderr,"Converting file %s ",filestr1);
	if(tth_debug&32)fprintf(stderr,"Command: %s",commandstr);
	sys=system(commandstr);
	if(sys==SUCCESS){
	  if((giffile=fopen(filestr2,"r"))!=NULL){
	    fclose(giffile);
	    sprintf(filestr1,"%s_icon.%s",filestr,gtype[c]);
	    strcpy(filestr,filestr2);
	    break;
	  }else{sys=SUCCESS+1;}
	}
      }
    }
  }
  if(sys == SUCCESS){
    if(epsftype==1) fprintf(tth_fdout,"<a href=\"%s\">Figure</a>",filestr);
    if(epsftype==2) fprintf(tth_fdout,"<img src=\"%s\" alt=\"%s\" />",filestr,filestr);
    if(epsftype==3) fprintf(tth_fdout,"<a href=\"%s\"><img src=\"%s\" alt=\"%s\" /></a>"
			    ,filestr,filestr1,filestr1);
  }else if(psfound){ /* This can only happen if the system call occurs. */
    fprintf(stderr,"**** System call:%s failed.\n",commandstr);
    fprintf(stderr,
	    "**** This failure is NOT in TtH; it is in an auxiliary program.\n");
    fprintf(tth_fdout,"<a href=\"%s\">Figure</a>",arg);
  }else {
    fprintf(stderr,"**** No suitable source file for %s\n",arg);
  }
}
}
/**************************************************************************/
/* handling code for defs */

static int indexkey(key,keys,nkeys)
char *key;
char *keys[];
int *nkeys;
{
  int i, j;
  j=-1;
  for(i = *nkeys-1; i>=0; i--) {
    if(!strcmp(key,keys[i])) {
      j=i;
      break;
    }
  }
  return j;
}

static void mkkey(key,keys,nkeys)
char *key;
char *keys[];
int *nkeys;
{
  size_t size;
  size=strlen(key)+1;
  keys[*nkeys]=malloc(size);
  strcpy(keys[*nkeys],key);
  (*nkeys)++;
}

static void mkdef(key,keys,def,defs,narg,nargs,nkeys)
char *key;
char *keys[];
char *def;
char *defs[];
int *narg;
int nargs[];
int *nkeys;
{
  size_t size;
  size=strlen(key)+1;
  keys[*nkeys]=malloc(size);
  strcpy(keys[*nkeys],key);
  size=strlen(def)+1;
  defs[*nkeys]=malloc(size);
  strcpy(defs[*nkeys],def);
  nargs[*nkeys]=*narg;
  (*nkeys)++;
}

static void rmkey(keys,nkeys)
char *keys[];
int *nkeys;
{
  if((*nkeys) > 0){
    (*nkeys)--;
    free(keys[*nkeys]); 
    keys[*nkeys]=0;
  } else {
    fprintf(stderr,"**** Error: No keys left to remove\n");
  }
}

static void rmdef(keys,defs,nkeys)
char *keys[];
char *defs[];
int *nkeys;
{
  if((*nkeys) > 0){
    (*nkeys)--;
    free(keys[*nkeys]); 
    keys[*nkeys]=0;
    free(defs[*nkeys]);
    defs[*nkeys]=0;
  } else {
    fprintf(stderr,"**** Error: No defs left to remove\n");
  }
}

void tth_undefine(keys,nkeys,udkey,lkeys)
char *keys[];
int *nkeys;
int udkey;
int lkeys[];
     /* Undefine all local keys (lkeys(n)=1) from udkey to nkeys-1 */
{
  /*static void rmkey();*/
  int i,ig;
  ig=0;
  for(i=(*nkeys)-1;i>=udkey;i--) {
    if(lkeys[i]){
      if(tth_debug&4)fprintf(stderr,
			     "Undefining:Key %d, %s, %s\n",i,keys[i],
			     (ig ? "Trapped." : "Freed."));
      if(ig){
	*keys[i]=0;
	lkeys[i]=0;
      }else{
	rmkey(keys,nkeys);
      }
    }else{ig=1;}
  }
}

void tth_enclose(str0,str1,str2,store) /* Enclose str1 with str0, str2 */
char *str0, *str2, *str1, *store;
{ /* Exit if string gets more than 3.5 of the 4*max */
  int lost;
  strcpy(store,str1);
  if((lost=strlen(str2)+strlen(store)- TTH_34DLEN) < 0){
    strcat(store,str2);
  }else{
   fprintf(stderr,"**** Error: Fatal. String overflow: Lengths %d,%d\n",
	   (int)strlen(store),(int)strlen(str2));
    fprintf(stderr,"Line %d\n",tth_num_lines);
    TTH_FATAL(2);
  }
  strcpy(str1,str0);
  if((lost=strlen(str1)+strlen(store)- TTH_34DLEN) < 0){
    strcat(str1,store);
  }else{
   fprintf(stderr,"**** Error: Fatal. String overflow: Lengths %d,%d\n",
	   (int)strlen(store),(int)strlen(str1));
    fprintf(stderr,"Line %d\n",tth_num_lines);
    TTH_FATAL(2);
  }
}

void tth_prefix(str0,str1,store)  /* Prefix str1 by str0, in str1 */
char *str0, *str1, *store;
{
  int lost;
  strcpy(store,str1);
  strcpy(str1,str0);
  if((lost=strlen(str1)+strlen(store)- TTH_34DLEN) < 0){
    strcat(str1,store);
  }else{
    fprintf(stderr,
      "**** Error: Fatal. Prefix string overflow: String %d, Prefix %d\n"
	    ,(int)strlen(store),(int)strlen(str1));
    fprintf(stderr,"Line %d. Check for excessive length equation.\n%s\n"
	    ,tth_num_lines," If necessary use switch -y0.");
    TTH_FATAL(2);
  }
}
/************************************************************************/
/* start delimit */
static void delimit(char *type, int heightin, char *codes)
     /* Return codes corresponding to a delimiter of given type and height*/
{
#define notypes 14
  static int top[notypes]={230,246,233,249,236,252,234,243,233,249,234,250,32,32};
  static int flat[notypes]={231,247,234,250,239,239,234,244,234,250,234,250,32,32};
  static int mid[notypes]={231,247,234,250,237,253,234,244,234,250,234,250,225,241};
  static int bot[notypes]={232,248,235,251,238,254,234,245,234,250,235,251,32,32};
  int i,j;
  char chr1[2]={0};
  char buff[20];
  int height;
  int horizmode=1; /* In equations use font tags not divs */

  /*tth_istyle case*/ 
  if(tth_istyle&1) height=0.65*heightin + 0.71;  /* 2 has to yield 2*/
  else height=0.95*heightin+heightin*heightin/16 +.11;
  /* Experimental size. Evenness fixed. If very large assume matrix. */
  if(tth_debug&32)fprintf(stderr,"Delimiter %s, heightin=%d, height=%d\n",
			  type,heightin,height);

  if     (!strcmp(type,"(")) i=0 ;
  else if(!strcmp(type,")")) i=1 ;
  else if(!strcmp(type,"[")) i=2 ;
  else if(!strcmp(type,"]")) i=3 ;
  else if(!strcmp(type,"{")) {i=4 ; height=2*(height/2)+1;}
  else if(!strcmp(type,"}")) {i=5 ; height=2*(height/2)+1;}
  else if(!strcmp(type,"|")) i=6 ;
  else if(!strcmp(type,"&#242;")) i=7 ; /* int */
  else if(!strcmp(type,"&#233;")) i=8 ; /* lceil */
  else if(!strcmp(type,"&#249;")) i=9 ; /* rceil */
  else if(!strcmp(type,"&#235;")) i=10 ; /* lfloor */
  else if(!strcmp(type,"&#251;")) i=11 ; /* rfloor */
  else if(!strcmp(type,"&#225;")) i=12 ; /* langle */
  else if(!strcmp(type,"&#241;")) i=13 ; /* rangle */
  else if(!strcmp(type,"/") || !strcmp(type,"\\")) {
    /* Old version with font size=+... and bug   sprintf(codes,
	    "</td><td align=left>%s%d%s%s%s</td><td align=center>\n",
	   TTH_SIZEGEN1,2*(height-1),TTH_SIZEGEN2,TTH_SIZEEND,type);
    */
    sprintf(codes,
	    "</td><td align=left>%s%d%s%s%s</td><td align=center>\n",
	    TTH_SIZEGEN1,100*(height),TTH_SIZEGEN2,type,TTH_SIZEEND);
    return;
  }
  else if(!strcmp(type,"&#214;")) { /* Sqrt code */
    if(tth_root_len[tth_root_depth]){ /* An index exists */
      if(heightin<=2 ){
	if(tth_istyle&1){
	  sprintf(codes,"%s%s%s%s %s%s%s%s",TTH_CELL_R,TTH_OA1,
		  TTH_FOOTNOTESIZE,tth_root_index[tth_root_depth],
		  TTH_SIZEEND,TTH_OA2,TTH_SYMBOL,TTH_large);
	  chr1[0]=214;
	  sprintf(codes+strlen(codes),
		  "%s%s%s%s%s",TTH_SYMPT(chr1),TTH_SIZEEND,TTH_SYMEND,TTH_OA3,TTH_CELL3);
	}else{ 
	  chr1[0]=230;
	  sprintf(codes,"%s\n%s%s %s%s%s%s<br />",
		  TTH_CELL_R,TTH_SCRIPTSIZE,tth_root_index[tth_root_depth],
		  TTH_SIZEEND,TTH_SYMBOL,TTH_NORMALSIZE,TTH_SYMPT(chr1));
	  chr1[0]=214;
	  sprintf(codes+strlen(codes),"%s <br />%s%s%s",
		  TTH_SYMPT(chr1),TTH_SIZEEND,TTH_SYMEND,TTH_CELL3);
	}
      }else{
	chr1[0]=230;
	sprintf(codes,"%s%s%s%s %s%s%s%s<br />",TTH_CELL_R,TTH_OA5,TTH_SMALL,
		tth_root_index[tth_root_depth],TTH_SIZEEND,
		TTH_SYMBOL,TTH_Large,TTH_SYMPT(chr1));
	chr1[0]=231;
	for(j=1;j<(height*.78-2.3);j++){ /* extra sqrt height */
	  sprintf(codes+strlen(codes),"%s<br />",TTH_SYMPT(chr1));
	}
	chr1[0]=214;
	if(tth_istyle&1) sprintf(codes+strlen(codes),
	      "%s%s\n&nbsp;%s%s%s",TTH_SYMPT(chr1),TTH_SIZEEND,TTH_SYMEND,
				 TTH_OA3,TTH_CELL3);
	else sprintf(codes+strlen(codes),"%s%s\n&nbsp;%s<br />\n%s",
		     TTH_SYMPT(chr1),TTH_SIZEEND,TTH_SYMEND,
		     TTH_CELL3);
      }
    }else{  /* Vanilla */
      if(heightin > 2){
	chr1[0]=230;
	sprintf(codes,
		"%s\n%s&nbsp;&nbsp;%s%s<br />"
		,TTH_CELL_L,TTH_Large,TTH_SYMBOL,TTH_SYMPT(chr1));
	chr1[0]=250;
	for(j=1;j < (0.78*height-2.3);j++){
	  sprintf(codes+strlen(codes),"%s&nbsp;%s%s<br />\n",
		  TTH_SYMEND,TTH_SYMBOL,TTH_SYMPT(chr1));
	}/* Accommodate Konqueror nbsp symbol bug */
	chr1[0]=214;
	sprintf(codes+strlen(codes),"%s<br />%s%s%s",
		TTH_SYMPT(chr1),TTH_SIZEEND,TTH_SYMEND,TTH_CELL3);
      }else{
	chr1[0]=214;
	sprintf(codes,
		"%s<br />%s%s%s%s<br />%s%s%s",TTH_CELL_L,TTH_SYMBOL,
		TTH_Large,TTH_SYMPT(chr1),TTH_SIZEEND,TTH_SYMEND,TTH_OA4,TTH_CELL3);
      }
    }
    *tth_root_index[tth_root_depth]=0;
    tth_root_len[tth_root_depth]=0;
    tth_root_depth--;
    return;
  }
  else if(!strcmp(type,".")) { *codes=0; return; }
  else {
    fprintf(stderr, "Incorrect delimiter::%s::\n",type); 
    i=-1;
    *codes=0;
    return;
  }

  /* Now using 8 bit codes. */
  if(height>1){
    strcpy(codes,TTH_CELL_L);
    strcat(codes,TTH_SYMBOLN);
    for (j=1 ; j <= height ; j++){
      if(j == 1) {chr1[0]=top[i]; sprintf(buff,"%s<br />",TTH_SYMPT(chr1));}
      else if(j == height) {chr1[0]=bot[i]; sprintf(buff,"%s\n",TTH_SYMPT(chr1));}
      else if(j == (height+1)/2) {
	chr1[0]=mid[i];sprintf(buff,"%s<br />\n",TTH_SYMPT(chr1));}
      else {chr1[0]=flat[i]; sprintf(buff,"%s<br />",TTH_SYMPT(chr1));}
      strcat(codes,buff);
    } 
    strcat(codes,TTH_SYMEND);
    strcat(codes,TTH_CELL3);
    if(tth_debug&512) fprintf(stderr,"codes=%s",codes);
  }else{
    if(i > 6){
      strcpy(codes,TTH_SYMBOLN);
      strcat(codes,TTH_SYMPT(type));
      strcat(codes,TTH_SYMEND);
    }else strcpy(codes,type);
  }
}
  /* end delimit */
  /*start symext*/
/**************** Construct large, possibly extended, character. */
void tth_symext(charin,charout)
char *charin,*charout;
{
  int horizmode=1; /* In equations use font tags not divs */
  char chr1[2]={0};
  chr1[0]=242;
  if(strlen(charin) == 1){
    if(charin[0]==chr1[0]) {
      strcpy(charout,TTH_SYMBOL);
      chr1[0]=243;strcat(charout,TTH_SYMPT(chr1));
      strcat(charout,"<br />");
      chr1[0]=245;strcat(charout,TTH_SYMPT(chr1));
      strcat(charout,"<br />");
      strcat(charout,TTH_SYMEND);
    }else {
      strcpy(charout,TTH_LARGE);
      strcat(charout,TTH_SYMBOL);      
      strcat(charout,TTH_SYMPT(charin));
      strcat(charout,"<br />\n") ;
      strcat(charout,TTH_SYMEND);
      strcat(charout,TTH_SIZEEND);
    }
  }else{ /* Longer than one: remove a leading space, quote and terminate. */
    if(*charin==' ')strcpy(charout,charin+1); else strcpy(charout,charin);
    if(strstr(charout,TTH_OBR)+strlen(TTH_OBR)!=charout+strlen(charout)
       && strstr(charout, /*This mess is really TTH_DIV without eqclose ref*/
		 (tth_istyle&1 ? 
		  "\n<div class=\"hrcomp\"><hr noshade=\"noshade\" size=\"1\"/></div>"
		  :"<hr noshade=\"noshade\" size=\"1\" />")
       )+strlen(
		 (tth_istyle&1 ? 
		  "\n<div class=\"hrcomp\"><hr noshade=\"noshade\" size=\"1\"/></div>"
		  :"<hr noshade=\"noshade\" size=\"1\" />")
	  )!=charout+strlen(charout)
       && strstr(charout+strlen(charout)-9,"ble>")==NULL)
      strcat(charout,"<br />\n");
  } /* Don't add an extra br to a hr or table end. */
}
  /*end symext*/
/***************** Encode 3-digit integers *************************/
void tth_encode(code,num)
char *code;
int num;
{
int i;
sprintf(code,"%03d",num);
for (i=0;i<3;i++) *(code+i)=*(code+i) + 17;
}

/*******************************************************************/
/* Find the first brace group in the string "text" and copy it to the
   string group, whose maximum length is len, value returned 0 if successful.*/
int tth_group(group,text,len)
char *text,*group;
int len;
{
  int i,j;
  int brace;
  i=strspn(text," \t\n");
  /* if(*(text+i)=='{') i++;  remove leading brace */
  j=0;
  brace=0;                /* 1 if removing braces */
  while(i+j < strlen(text)){
    if(*(text+i+j)=='{')brace++;
    else if(*(text+i+j)=='}')brace--;
    if(brace <= 0) break;
    j++;
  }
  strncpy(group,text+i,len);
  if(i+j<len) *(group+i+j+1)=0;
  return brace;
}

/*******************************************************************/
/* Convert an integer into roman numerals. */
static int roman(int num, char *rm)
{
#define CODENUM 8
  int i,j,k,m,n,p;
  int multiples[CODENUM]={1000,500,100,50,10,5,1,0};
  char codes[CODENUM]={'m','d','c','l','x','v','i',' '};
  if(abs(num) >= 4*multiples[0]){
    strcpy(rm,"A LARGE NUMBER");
    return 1;
  }
  m=0;
  i=num;
  if(i < 0){
    i=-i;
    *(rm+(m++))='-';
  }
  for(j=0;j<CODENUM-1;j++){
    k=multiples[j];
    while(i-k>=0){
      i=i-k;
      *(rm+(m++))=codes[j];
    }
    if(j<CODENUM-2){
      n=(j/2)*2+2;
      p=multiples[n];
      if(i+p>=k){
	i=i-(k-p);
	*(rm+(m++))=codes[n];
	*(rm+(m++))=codes[j];
      }
    }
  }
  *(rm+(m++))=0;
  return 0;
}
/* start b_align */    
/*************************************************************************
 Take off the Cell start and the extra bottom from single over construct.
 This is used only at the completion of the top or bottom of a fraction.
 If cell starts or ends with CELL3, cut off since they are redundant.
 If it then ends with OA4 it is a candidate for bottom removal.
 If every CELL3 appears as part of the sequence OA4 CELL3, then change
 each occurrence to just CELL3.
 */
#define BMAXLEN 1000
#define NSTS 20
static int b_align(thestring,tth_debug)
     char *thestring;
     int tth_debug;
{
  char buff1[BMAXLEN];
  char *chr,*chr1,*chr2;
  char *oastarts[NSTS];
  char *oa4null="                                             ";
  int ists=0,i;

  if(tth_debug&8192)fprintf(stderr,"b_align string:%s",thestring);
  if(strlen(thestring) > BMAXLEN) return 0; /*Too long*/
  strcpy(buff1,thestring);
  if(strstr(thestring,TTH_CELL3) == thestring) { /*Starts with CELL3 */
    strcpy(buff1,thestring+strlen(TTH_CELL3));
    if(tth_debug&2)fprintf(stderr,"String Head cut, ");
  }	
  if(strstr(buff1+strlen(buff1)-strlen(TTH_CELL3),TTH_CELL3)){/*end*/
    *(buff1+strlen(buff1)-strlen(TTH_CELL3))=0;
    if(tth_debug&2)fprintf(stderr,"String Tail cut. ");	
  }
  if((oastarts[0]=strstr(buff1+strlen(buff1)-strlen(TTH_OA4),TTH_OA4))){
    chr=buff1;
    for (ists=0; ists<NSTS; ists++) {
      if((chr1=strstr(chr,TTH_CELL3))){
	chr2=chr1-strlen(TTH_OA4);
	if(chr2-chr<0){ists=-1; break;} 
	if(strstr(chr2,TTH_OA4)!=chr2){ists=-2; break;}
	oastarts[ists+1]=chr2;
	chr=chr1+strlen(TTH_CELL3);
      }else{
	 break;
      }
    } /* We exit with ists=number of OA-CELLs or - if non-treatable. */
    for (i=0;i<=ists;i++) {
      strncpy(oastarts[i],oa4null,strlen(TTH_OA4));
    }
    if(tth_debug&2)fprintf(stderr,"String OA4 removed %d times:\n%s\n",
			   ists+1,buff1);	
  }
  strcpy(thestring,buff1);
  return (ists+1);
} /* end b_align */
/****************************************************************************
Convert a dimension into scaled points. 1pt = 2^16 = 65536 sp.
1pc =12pt = 786432 sp
1in =72.27pt =4736287 sp
1bp =72.27/72pt =1.0038 pt= 65785 sp 
1cm =1in/2.54 = 1864680 sp 
1mm = 18648 sp
1dd =1238/1157 pt = 70124 sp
1cc = 12 dd = 841489 sp
1em = width of a quad (capital M, actually the height of it)
1ex = height of 'x'.

This needs 4 byte integers.
*/
#define EMPOINTS 12
#define ENPOINTS 6
#define EXPOINTS 10
static int scaledpoints(thenumber,thedimension)
     float thenumber;
     char *thedimension;
{
int dimval;
if(strstr(thedimension,"pt")==thedimension)dimval=65536;
else if(strstr(thedimension,"pc")==thedimension)dimval=786432;
else if(strstr(thedimension,"in")==thedimension)dimval=4736287;
else if(strstr(thedimension,"bp")==thedimension)dimval=65785;
else if(strstr(thedimension,"cm")==thedimension)dimval=1864680;
else if(strstr(thedimension,"mm")==thedimension)dimval=186468;
else if(strstr(thedimension,"dd")==thedimension)dimval=70124;
else if(strstr(thedimension,"cc")==thedimension)dimval=841489;
else if(strstr(thedimension,"ex")==thedimension)dimval=EXPOINTS*65536;
else if(strstr(thedimension,"em")==thedimension)dimval=EMPOINTS*65536;
else if(strstr(thedimension,"en")==thedimension)dimval=ENPOINTS*65536;
else if(strstr(thedimension,"sp")==thedimension)dimval=1;
else dimval=1;
return ((int) (dimval*thenumber));
}

/* Add dimension 2 into dimension 1*/
static int adddimen(number1,unit1,number2,unit2)
     float *number1,*number2;
     char *unit1,*unit2;
{
  if(*unit1=='%'){/* hsize supercedes others */
    if(*unit2=='%') {
      *number1=*number1+*number2; 
    }else{
      *number1=*number1+
	(((double)scaledpoints(*number2,unit2))/SCALEDPERPIXEL)/DEFAULTHSIZEPIX;
      strcpy(unit1,"%");
    }
  }else{      
    if(*unit2=='%'){
      *number1=*number2+
	(((double)scaledpoints(*number1,unit1))/SCALEDPERPIXEL)/DEFAULTHSIZEPIX;
      strcpy(unit1,"%");
    }else{ /* Both absolute. Return absolute scaled points.*/
      *number1=scaledpoints(*number1,unit1)+scaledpoints(*number2,unit2);
      strcpy(unit1,"sp");
      return 1; /* Absolute units */
    }
  }
  return 0; /* Percentage */
}


/***********************Color table following  color.pro of dvips ********/
#define N_COLORS 76
struct tth_ct { 
  char name[20];
  float cyan;
  float magenta;
  float yellow;
  float black;
} ;
struct tth_ct tth_colortable[N_COLORS] ={
 {"black",0,0,0,1},
 {"white",0,0,0,0},
 {"red",0,1.,1.,0},
 {"green",1.,0.,1.,0},
 {"blue",1.,1.,0.,0},
 {"cyan",1.,0,0,0},
 {"magenta",0,1,0,0},
 {"yellow",0,0,1.,0},
 {"GreenYellow",0.15,0,0.69,0},
 {"Yellow",0,0,1,0},
 {"Goldenrod",0,0.10,0.84,0},
 {"Dandelion",0,0.29,0.84,0},
 {"Apricot",0,0.32,0.52,0},
 {"Peach",0,0.50,0.70,0},
 {"Melon",0,0.46,0.50,0},
 {"YellowOrange",0,0.42,1,0},
 {"Orange",0,0.61,0.87,0},
 {"BurntOrange",0,0.51,1,0},
 {"Bittersweet",0,0.75,1,0.24},
 {"RedOrange",0,0.77,0.87,0},
 {"Mahogany",0,0.85,0.87,0.35},
 {"Maroon",0,0.87,0.68,0.32},
 {"BrickRed",0,0.89,0.94,0.28},
 {"Red",0,1,1,0},
 {"OrangeRed",0,1,0.50,0},
 {"RubineRed",0,1,0.13,0},
 {"WildStrawberry",0,0.96,0.39,0},
 {"Salmon",0,0.53,0.38,0},
 {"CarnationPink",0,0.63,0,0},
 {"Magenta",0,1,0,0},
 {"VioletRed",0,0.81,0,0},
 {"Rhodamine",0,0.82,0,0},
 {"Mulberry",0.34,0.90,0,0.02},
 {"RedViolet",0.07,0.90,0,0.34},
 {"Fuchsia",0.47,0.91,0,0.08},
 {"Lavender",0,0.48,0,0},
 {"Thistle",0.12,0.59,0,0},
 {"Orchid",0.32,0.64,0,0},
 {"DarkOrchid",0.40,0.80,0.20,0},
 {"Purple",0.45,0.86,0,0},
 {"Plum",0.50,1,0,0},
 {"Violet",0.79,0.88,0,0},
 {"RoyalPurple",0.75,0.90,0,0},
 {"BlueViolet",0.86,0.91,0,0.04},
 {"Periwinkle",0.57,0.55,0,0},
 {"CadetBlue",0.62,0.57,0.23,0},
 {"CornflowerBlue",0.65,0.13,0,0},
 {"MidnightBlue",0.98,0.13,0,0.43},
 {"NavyBlue",0.94,0.54,0,0},
 {"RoyalBlue",1,0.50,0,0},
 {"Blue",1,1,0,0},
 {"Cerulean",0.94,0.11,0,0},
 {"Cyan",1,0,0,0},
 {"ProcessBlue",0.96,0,0,0},
 {"SkyBlue",0.62,0,0.12,0},
 {"Turquoise",0.85,0,0.20,0},
 {"TealBlue",0.86,0,0.34,0.02},
 {"Aquamarine",0.82,0,0.30,0},
 {"BlueGreen",0.85,0,0.33,0},
 {"Emerald",1,0,0.50,0},
 {"JungleGreen",0.99,0,0.52,0},
 {"SeaGreen",0.69,0,0.50,0},
 {"Green",1,0,1,0},
 {"ForestGreen",0.91,0,0.88,0.12},
 {"PineGreen",0.92,0,0.59,0.25},
 {"LimeGreen",0.50,0,1,0},
 {"YellowGreen",0.44,0,0.74,0},
 {"SpringGreen",0.26,0,0.76,0},
 {"OliveGreen",0.64,0,0.95,0.40},
 {"RawSienna",0,0.72,1,0.45},
 {"Sepia",0,0.83,1,0.70},
 {"Brown",0,0.81,1,0.60},
 {"Tan",0.14,0.42,0.56,0},
 {"Gray",0,0,0,0.50},
 {"Black",0,0,0,1},
 {"White",0,0,0,0}
};

/********************************  Return a named color if it exists.*/
int tth_cmykcolor(ch,c,m,y,k)
char *ch;
float *c,*m,*y,*k;
{
extern struct tth_ct tth_colortable[N_COLORS];
int i;
  i=0;
  for(i=0;i<N_COLORS;i++){
    if(!strcmp(tth_colortable[i].name,ch)){
      *c=tth_colortable[i].cyan;
      *m=tth_colortable[i].magenta;
      *y=tth_colortable[i].yellow;
      *k=tth_colortable[i].black;
      return 4;
    }
  }
  return 0;
}


/************************************* 
Convert a symbol character 8859 reference into unicode point 
If the input string chsym is of length 1, just use its 8 bit code.
If not, try to read the first positive integer from it. 
If that fails, translate every character separately.
The returned value is a pointer to the global string chuni 
containing the unicode HTML numeric ref(s) on return.
*/

char tth_chuni[TTH_CHARLEN];

char* tth_symbol_point(chsym)
     char *chsym;
{
  /* this table is based on the test/symbols.html file of MathML*/
  /* It is used if the global tth_unicode == 1 */
char *tth_sympoint[256]={
/*0*/ "&nbsp;",/*1*/ "&nbsp;",/*2*/ "&nbsp;",/*3*/ "&nbsp;",
/*4*/ "&nbsp;",/*5*/ "&nbsp;",/*6*/ "&nbsp;",/*7*/ "&nbsp;",
/*8*/ "&nbsp;",/*9*/ "&nbsp;",/*10*/ "&nbsp;",/*11*/ "&nbsp;",
/*12*/ "&nbsp;",/*13*/ "&nbsp;",/*14*/ "&nbsp;",/*15*/ "&nbsp;",
/*16*/ "&nbsp;",/*17*/ "&nbsp;",/*18*/ "&nbsp;",/*19*/ "&nbsp;",
/*20*/ "&nbsp;",/*21*/ "&nbsp;",/*22*/ "&nbsp;",/*23*/ "&nbsp;",
/*24*/ "&nbsp;",/*25*/ "&nbsp;",/*26*/ "&nbsp;",/*27*/ "&nbsp;",
/*28*/ "&nbsp;",/*29*/ "&nbsp;",/*30*/ "&nbsp;",/*31*/ "&nbsp;",
/*32*/ "&#160;",/*33*/ "&#33;",/*34*/ "&#8704;",/*35*/ "&#35;",
/*36*/ "&#8707;",/*37*/ "&#37;",/*38*/ "&#38;",/*39*/ "&#8715;",
/*40*/ "&#40;",/*41*/ "&#41;",/*42*/ "&#8727;",/*43*/ "&#43;",
/*44*/ "&#44;",/*45*/ "&#8722;",/*46*/ "&#46;",/*47*/ "&#47;",
/*48*/ "&#48;",/*49*/ "&#49;",/*50*/ "&#50;",/*51*/ "&#51;",
/*52*/ "&#52;",/*53*/ "&#53;",/*54*/ "&#54;",/*55*/ "&#55;",
/*56*/ "&#56;",/*57*/ "&#57;",/*58*/ "&#58;",/*59*/ "&#59;",
/*60*/ "&#60;",/*61*/ "&#61;",/*62*/ "&#62;",/*63*/ "&#63;",
/*64*/ "&#8773;",/*65*/ "&#913;",/*66*/ "&#914;",/*67*/ "&#935;",
/*68*/ "&#8710;",/*69*/ "&#917;",/*70*/ "&#934;",/*71*/ "&#915;",
/*72*/ "&#919;",/*73*/ "&#921;",/*74*/ "&#977;",/*75*/ "&#922;",
/*76*/ "&#923;",/*77*/ "&#924;",/*78*/ "&#925;",/*79*/ "&#927;",
/*80*/ "&#928;",/*81*/ "&#920;",/*82*/ "&#929;",/*83*/ "&#931;",
/*84*/ "&#932;",/*85*/ "&#933;",/*86*/ "&#962;",/*87*/ "&#8486;",
/*88*/ "&#926;",/*89*/ "&#936;",/*90*/ "&#918;",/*91*/ "&#91;",
/*92*/ "&#8756;",/*93*/ "&#93;",/*94*/ "&#8869;",/*95*/ "&#95;",
/*96*/ "&#63717;",/*97*/ "&#945;",/*98*/ "&#946;",/*99*/ "&#967;",
/*100*/ "&#948;",/*101*/ "&#1013;",/*102*/ "&#981;",/*103*/ "&#947;",
/*104*/ "&#951;",/*105*/ "&#953;",/*106*/ "&#966;",/*107*/ "&#954;",
/*108*/ "&#955;",/*109*/ "&#956;",/*110*/ "&#957;",/*111*/ "&#959;",
/*112*/ "&#960;",/*113*/ "&#952;",/*114*/ "&#961;",/*115*/ "&#963;",
/*116*/ "&#964;",/*117*/ "&#965;",/*118*/ "&#982;",/*119*/ "&#969;",
/*120*/ "&#958;",/*121*/ "&#968;",/*122*/ "&#950;",/*123*/ "&#123;",
/*124*/ "&#124;",/*125*/ "&#125;",/*126*/ "&#8764;",/*127*/ "&nbsp;",
/*128*/ "&nbsp;",/*129*/ "&#949;",/*130*/ "&nbsp;",/*131*/ "&nbsp;",
/*132*/ "&nbsp;",/*133*/ "&nbsp;",/*134*/ "&nbsp;",/*135*/ "&nbsp;",
/*136*/ "&nbsp;",/*137*/ "&nbsp;",/*138*/ "&nbsp;",/*139*/ "&nbsp;",
/*140*/ "&nbsp;",/*141*/ "&nbsp;",/*142*/ "&nbsp;",/*143*/ "&nbsp;",
/*144*/ "&nbsp;",/*145*/ "&nbsp;",/*146*/ "&nbsp;",/*147*/ "&nbsp;",
/*148*/ "&nbsp;",/*149*/ "&nbsp;",/*150*/ "&nbsp;",/*151*/ "&nbsp;",
/*152*/ "&nbsp;",/*153*/ "&nbsp;",/*154*/ "&nbsp;",/*155*/ "&nbsp;",
/*156*/ "&nbsp;",/*157*/ "&nbsp;",/*158*/ "&nbsp;",/*159*/ "&nbsp;",
/*160*/ "&#8364;",/*161*/ "&#978;",/*162*/ "&#8242;",/*163*/ "&#8804;",
/*164*/ "&#8725;",/*165*/ "&#8734;",/*166*/ "&#402;",/*167*/ "&#9827;",
/*168*/ "&#9830;",/*169*/ "&#9829;",/*170*/ "&#9824;",/*171*/ "&#8596;",
/*172*/ "&#8592;",/*173*/ "&#8593;",/*174*/ "&#8594;",/*175*/ "&#8595;",
/*176*/ "&#176;",/*177*/ "&#177;",/*178*/ "&#8243;",/*179*/ "&#8805;",
/*180*/ "&#215;",/*181*/ "&#8733;",/*182*/ "&#8706;",/*183*/ "&#8226;",
/*184*/ "&#247;",/*185*/ "&#8800;",/*186*/ "&#8801;",/*187*/ "&#8776;",
/*188*/ "&#8230;",/*189*/ "&#63718;",/*190*/ "&#63719;",/*191*/ "&#8629;",
/*192*/ "&#8501;",/*193*/ "&#8465;",/*194*/ "&#8476;",/*195*/ "&#8472;",
/*196*/ "&#8855;",/*197*/ "&#8853;",/*198*/ "&#8709;",/*199*/ "&#8745;",
/*200*/ "&#8746;",/*201*/ "&#8835;",/*202*/ "&#8839;",/*203*/ "&#8836;",
/*204*/ "&#8834;",/*205*/ "&#8838;",/*206*/ "&#8712;",/*207*/ "&#8713;",
/*208*/ "&#8736;",/*209*/ "&#8711;",/*210*/ "&#63194;",/*211*/ "&#63193;",
/*212*/ "&#63195;",/*213*/ "&#8719;",/*214*/ "&#8730;",/*215*/ "&#8901;",
/*216*/ "&#172;",/*217*/ "&#8743;",/*218*/ "&#8744;",/*219*/ "&#8660;",
/*220*/ "&#8656;",/*221*/ "&#8657;",/*222*/ "&#8658;",/*223*/ "&#8659;",
/*224*/ "&#9674;",/*225*/ "&#9001;",/*226*/ "&#63720;",/*227*/ "&#63721;",
/*228*/ "&#63722;",/*229*/ "&#8721;",/*230*/ "&#63723;",/*231*/ "&#63724;",
/*232*/ "&#63725;",/*233*/ "&#63726;",/*234*/ "&#63727;",/*235*/ "&#63728;",
/*236*/ "&#63729;",/*237*/ "&#63730;",/*238*/ "&#63731;",/*239*/ "&#63732;",
/*240*/ "&nbsp;",/*241*/ "&#9002;",/*242*/ "&#8747;",/*243*/ "&#8992;",
/*244*/ "&#63733;",/*245*/ "&#8993;",/*246*/ "&#63734;",/*247*/ "&#63735;",
/*248*/ "&#63736;",/*249*/ "&#63737;",/*250*/ "&#63738;",/*251*/ "&#63739;",
/*252*/ "&#63740;",/*253*/ "&#63741;",/*254*/ "&#63742;",/*255*/ "&nbsp;"
};
  /* this table is based on Unicode 3.2*/
char *tth_sympoint2[256]={
/*0*/ "&nbsp;",/*1*/ "&nbsp;",/*2*/ "&nbsp;",/*3*/ "&nbsp;"
,/*4*/ "&nbsp;",/*5*/ "&nbsp;",/*6*/ "&nbsp;",/*7*/ "&nbsp;"
,/*8*/ "&nbsp;",/*9*/ "&nbsp;",/*10*/ "&nbsp;",/*11*/ "&nbsp;",
/*12*/ "&nbsp;",/*13*/ "&nbsp;",/*14*/ "&nbsp;",/*15*/ "&nbsp;",
/*16*/ "&nbsp;",/*17*/ "&nbsp;",/*18*/ "&nbsp;",/*19*/ "&nbsp;",
/*20*/ "&nbsp;",/*21*/ "&nbsp;",/*22*/ "&nbsp;",/*23*/ "&nbsp;",
/*24*/ "&nbsp;",/*25*/ "&nbsp;",/*26*/ "&nbsp;",/*27*/ "&nbsp;",
/*28*/ "&nbsp;",/*29*/ "&nbsp;",/*30*/ "&nbsp;",/*31*/ "&nbsp;",
/*32*/ "&#160;",/*33*/ "&#33;",/*34*/ "&#8704;",/*35*/ "&#35;",
/*36*/ "&#8707;",/*37*/ "&#37;",/*38*/ "&#38;",/*39*/ "&#8715;",
/*40*/ "&#40;",/*41*/ "&#41;",/*42*/ "&#8727;",/*43*/ "&#43;",
/*44*/ "&#44;",/*45*/ "&#8722;",/*46*/ "&#46;",/*47*/ "&#47;",
/*48*/ "&#48;",/*49*/ "&#49;",/*50*/ "&#50;",/*51*/ "&#51;",
/*52*/ "&#52;",/*53*/ "&#53;",/*54*/ "&#54;",/*55*/ "&#55;",
/*56*/ "&#56;",/*57*/ "&#57;",/*58*/ "&#58;",/*59*/ "&#59;",
/*60*/ "&#60;",/*61*/ "&#61;",/*62*/ "&#62;",/*63*/ "&#63;",
/*64*/ "&#8773;",/*65*/ "&#913;",/*66*/ "&#914;",/*67*/ "&#935;",
/*68*/ "&#8710;",/*69*/ "&#917;",/*70*/ "&#934;",/*71*/ "&#915;",
/*72*/ "&#919;",/*73*/ "&#921;",/*74*/ "&#977;",/*75*/ "&#922;",
/*76*/ "&#923;",/*77*/ "&#924;",/*78*/ "&#925;",/*79*/ "&#927;",
/*80*/ "&#928;",/*81*/ "&#920;",/*82*/ "&#929;",/*83*/ "&#931;",
/*84*/ "&#932;",/*85*/ "&#933;",/*86*/ "&#962;",/*87*/ "&#8486;",
/*88*/ "&#926;",/*89*/ "&#936;",/*90*/ "&#918;",/*91*/ "&#91;",
/*92*/ "&#8756;",/*93*/ "&#93;",/*94*/ "&#8869;",/*95*/ "&#95;",
/*96*/ "&#x02C9;",/*97*/ "&#945;",/*98*/ "&#946;",/*99*/ "&#967;",
/*100*/ "&#948;",/*101*/ "&#1013;",/*102*/ "&#981;",/*103*/ "&#947;",
/*104*/ "&#951;",/*105*/ "&#953;",/*106*/ "&#966;",/*107*/ "&#954;",
/*108*/ "&#955;",/*109*/ "&#956;",/*110*/ "&#957;",/*111*/ "&#959;",
/*112*/ "&#960;",/*113*/ "&#952;",/*114*/ "&#961;",/*115*/ "&#963;",
/*116*/ "&#964;",/*117*/ "&#965;",/*118*/ "&#982;",/*119*/ "&#969;",
/*120*/ "&#958;",/*121*/ "&#968;",/*122*/ "&#950;",/*123*/ "&#123;",
/*124*/ "&#124;",/*125*/ "&#125;",/*126*/ "&#8764;",/*127*/ "&nbsp;",
/*128*/ "&nbsp;",/*129*/ "&#949;",/*130*/ "&nbsp;",/*131*/ "&nbsp;",
/*132*/ "&nbsp;",/*133*/ "&nbsp;",/*134*/ "&nbsp;",/*135*/ "&nbsp;",
/*136*/ "&nbsp;",/*137*/ "&nbsp;",/*138*/ "&nbsp;",/*139*/ "&nbsp;",
/*140*/ "&nbsp;",/*141*/ "&nbsp;",/*142*/ "&nbsp;",/*143*/ "&nbsp;",
/*144*/ "&nbsp;",/*145*/ "&nbsp;",/*146*/ "&nbsp;",/*147*/ "&nbsp;",
/*148*/ "&nbsp;",/*149*/ "&nbsp;",/*150*/ "&nbsp;",/*151*/ "&nbsp;",
/*152*/ "&nbsp;",/*153*/ "&nbsp;",/*154*/ "&nbsp;",/*155*/ "&nbsp;",
/*156*/ "&nbsp;",/*157*/ "&nbsp;",/*158*/ "&nbsp;",/*159*/ "&nbsp;",
/*160*/ "&#8364;",/*161*/ "&#978;",/*162*/ "&#8242;",/*163*/ "&#8804;",
/*164*/ "&#8725;",/*165*/ "&#8734;",/*166*/ "&#402;",/*167*/ "&#9827;",
/*168*/ "&#9830;",/*169*/ "&#9829;",/*170*/ "&#9824;",/*171*/ "&#8596;",
/*172*/ "&#8592;",/*173*/ "&#8593;",/*174*/ "&#8594;",/*175*/ "&#8595;",
/*176*/ "&#176;",/*177*/ "&#177;",/*178*/ "&#8243;",/*179*/ "&#8805;",
/*180*/ "&#215;",/*181*/ "&#8733;",/*182*/ "&#8706;",/*183*/ "&#8226;",
/*184*/ "&#247;",/*185*/ "&#8800;",/*186*/ "&#8801;",/*187*/ "&#8776;",
/*188*/ "&#8230;",/*189*/ "&#x2502;",/*190*/ "&#x2015;",/*191*/ "&#8629;",
/*192*/ "&#8501;",/*193*/ "&#8465;",/*194*/ "&#8476;",/*195*/ "&#8472;",
/*196*/ "&#8855;",/*197*/ "&#8853;",/*198*/ "&#8709;",/*199*/ "&#8745;",
/*200*/ "&#8746;",/*201*/ "&#8835;",/*202*/ "&#8839;",/*203*/ "&#8836;",
/*204*/ "&#8834;",/*205*/ "&#8838;",/*206*/ "&#8712;",/*207*/ "&#8713;",
/*208*/ "&#8736;",/*209*/ "&#8711;",/*210*/ "&#x00Ae;",/*211*/ "&#x00A9;",
/*212*/ "&#x2122;",/*213*/ "&#8719;",/*214*/ "&#8730;",/*215*/ "&#8901;",
/*216*/ "&#172;",/*217*/ "&#8743;",/*218*/ "&#8744;",/*219*/ "&#8660;",
/*220*/ "&#8656;",/*221*/ "&#8657;",/*222*/ "&#8658;",/*223*/ "&#8659;",
/*224*/ "&#9674;",/*225*/ "&#9001;",/*226*/ "&#x00Ae;",/*227*/ "&#x00A9;",
/*228*/ "&#x2122;",/*229*/ "&#8721;",/*230*/ "&#x239B;",/*231*/ "&#x239C;",
/*232*/ "&#x239D;",/*233*/ "&#x23A1;",/*234*/ "&#x23A2;",/*235*/ "&#x23A3;",
/*236*/ "&#x23A7;",/*237*/ "&#x23A8;",/*238*/ "&#x23A9;",/*239*/ "&#x23AA;",
/*240*/ "&nbsp;",/*241*/ "&#9002;",/*242*/ "&#8747;",/*243*/ "&#8992;",
/*244*/ "&#x23AE;",/*245*/ "&#8993;",/*246*/ "&#x239E;",/*247*/ "&#x239F;",
/*248*/ "&#x23A0;",/*249*/ "&#x23A4;",/*250*/ "&#x23A5;",/*251*/ "&#x23A6;",
/*252*/ "&#x23AB;",/*253*/ "&#x23AC;",/*254*/ "&#x23AD;",/*255*/ "&nbsp;"
};
 int i=-1,j=0;
 if(strlen(chsym)==1){
   i=(int)*(chsym);
   if(i<0)i=i+256;
   strcpy(tth_chuni,(tth_unicode==1 ? tth_sympoint[i] : tth_sympoint2[i]));
 }else{
   if(sscanf(chsym+strcspn(chsym,"0123456789"),"%d",&i)){
     if(i>=0 && i<256) {
       strcpy(tth_chuni,(tth_unicode==1 ? tth_sympoint[i] : tth_sympoint2[i]));
     }else {i=-1;}
   }
   if(i==-1){
     j=0;
     *tth_chuni=0;
     while(strlen(chsym+j)){
       i=(int)*(chsym+j++);
       if(i<0)i=i+256;
       strcat(tth_chuni,(tth_unicode==1 ? tth_sympoint[i] : tth_sympoint2[i]));
     }
   }
 }
 return tth_chuni;
}
/*************************************/
void tagpurge(eqstr)
     char *eqstr;
{
  char *position;
  char eqpurge[4*TTH_DLEN];
  int len;
/*    fprintf(stderr,"Title Purging %s\n",eqstr); */
  position=eqstr;
  *eqpurge=0;
  while(position<eqstr+strlen(eqstr)){
    len=strcspn(position,"<");
    strncat(eqpurge,position,len);
    position=position+len;
    position=position+strcspn(position,">")+1;
  }
  strcpy(eqstr,eqpurge);
/*    fprintf(stderr,"Purged %s\n",eqstr); */
}

/**End of TtH**/