This file is indexed.

/usr/share/lifelines/book-latex.ll is in lifelines-reports 3.0.61-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
/*
** @progname       book-latex.ll
** @author         Nicklaus
** @version        3.1
** @category       
** @output         LaTeX
** @description    
**
** Generates really spiffy register reports for formatting with LaTex. Reports
** read like a book. Includes source citation, footnotes, etc. Register
** reports are either descendant or ancestor/ahnentafel style.

** $Id: book-latex.ll,v 1.14 2005/11/19 05:30:30 memmerto Exp $
** 
** SourceForge Versions:
**
** $Log: book-latex.ll,v $
** Revision 1.14  2005/11/19 05:30:30  memmerto
** - Add missing </PARA> tags, as per SF Patch 551968.
** - Add "usepackage{isolatin1}" to register-tex.ll, as per SF Patch # 402021.
** - Add comments about how to change between A4/Letter paper.
** - Add -v (version) option; clean up -h/-? (usage) options, as per SF Feature Request # 1310390.
** - Add "temp" and "random" hints to more file operations.
**
** Revision 1.13  2005/10/26 04:40:45  dr_doom
** make user property usage more consistent
**
** Revision 1.12  2005/06/18 00:29:39  dr_doom
** Update formatted docs, minor cleanup in merge families
**
** Revision 1.11  2004/09/02 23:11:04  rsimms
**         Enhanced book-latex.ll to filter text to render harmless those
**         characters meaningful to the LaTeX system.  Also added an option
**         to suppress e-mail addresses of source authors when they're specified
**         as EMAI subnodes of AUTH nodes.  Also indented all of the code with
**         spaces (instead of tabs/spaces mix) to make the code easier to follow.
**
** Revision 1.10 2004/07/19 05:54:54 dr_doom
** Merge Vincent Broman Changes to reports
**
** Revision 1.9  2003/01/19 02:50:23  dr_doom
**
** Revision 1.8  2001/10/03 02:58:55  dabright
**  Restored some previous additions to this report.
**  The update from Dennis Nicklaus on 12 Aug 2001
**  had deleted them and he asked me to re-add them. So:
**  Add  CREM (cremated) tag processing;
**  modified OCCU tag processing so that it can recognize date ranges
**  (and so avoid saying "xx is a yy and a zz and a ..."); modified
**  OCCU tag processing to recognize a subordinate AGNC tag indicating
**  employer; modified onDate to recognize date ranges (FROM dd mmm
**  yyyy TO dd mmm yyyy) - this still has some rough edges.
**
** Revision 1.7  2001/08/12 20:53:59  nozell
** Update by Dennis Nicklaus to his book-latex.ll
**
** Revision 1.5  2000/11/28 21:39:45  nozell
** Add keyword tags to all reports
** Extend the report script menu to display script output format
**
** Revision 1.4  2000/11/11 07:52:06  pere
** Use ISO 8859/1 charset in LaTeX.  Add meta-information in header.
**
** Revision 1.3  2000/11/11 07:46:47  pere
** Include index even when there is no bibliography.
**
** Revision 1.2  2000/11/11 04:07:37  dabright
**
** reports/book-latex.ll: Added processing for BAPM tag, corrected
** error in referencing "spouse" rather than "s" in longvitals,
** added processing for the TYPE tag (modifier for EVENT), corrected
** setDayNumber so that it only uses text phrases (e.g., "on the same
** day") when both previous date and current date are fully
** specified, preserve line breaks represented by blank CONT/CONC
** tags, ensure "cn" variable in sourceIt is initialized before
** referenced, and miscellaneous typographical corrections.
**
**
** Revision 1.1  2000/11/10 dabright
** Initial revision - copy of Version 2.5 from Dennis Nicklaus
**
** Pre-SourceForge history:
**
## Dennis Nicklaus (dnicklaus at yahoo.com)
** Version 2.5     Feb. 2000
**
** Requires LifeLines version 2.3.3 or later
** Requires tree.tex (for formatting)   (tex macros for tree drawing).
**    (found in TUGboat, vol. 6 (1985) and online in various places,
**    including with the desc-tex lifelines report)
**
** based on work by David Olsen (dko@cs.wisc.edu) which in turn was
** based on work originally done by Tom Wetmore (ttw@cbnews1.att.com).
** also work by Kurt Baudendistel (baud@research.att.com).
** A few others, such as Ed Sternin (edik@brocku.ca) made other suggestions.
** and corrections.
**
** This report prints, in register/book format, information about all 
** descendants of a person (or persons) and all of their spouses.  
** It tries to understand as many different
** GEDCOM tags as possible.  All source information (SOUR lines) is in the
** bibliography and footnotes.
**
** An alternate usage (new in version 2) lets you print out sort of a
** combination ahnentafel and register report going through the ancestors of
** the persons chosen.
**
** The output is in LaTeX format.  Therefore, the name of the output file
** should end in ".tex".  To print (assuming the name of the output file is
** "out.tex"):
**      latex out      < ignore lots of warnings about underfull \hboxes >
**      makeindex out  < not all systems have makeindex available
**                       if yours is one, just remove the \input{file.ind} line
**                       from the LaTeX output and skip the 'makeindex'>
**      latex out      < repeat latex-ing to get cross-references resolved>
**      latex out      < needed to get the index into the TOC>
**                     < you may need to repeat more if Latex
**                       says so, e.g. if page refs change. >
**      dvips -o out   < without the -o, dvips will likely print to your
**                     < default printer instead of creating a .ps file.
**      lpr out.ps
**                     < the last three commands here may be replaced by >
**                       pdflatex out    -- if you have 'pdflatex' and a PDF is
**                       the desired final product >
**
** I admit that this is lot of post-processing, but the results are worth it.
**
** NOTE ON PAPER SIZES:
** Paper sizes (A4 or letter) can be specified within the LaTeX output,
** but this requires editing by folks who don't like the default.
**
** Since dvips (a neccessary processing step) can take a paper-size
** argument on the command line, it's much simpler to let the user
** specify the desired page size when running dvips (outlined above)
** instead of editing the report/LaTeX output.
**
** Example:
**   dvips -t letter out [ for US Letter-sized paper, 8.5x11" ]
**   dvips -t a4 out [ for ISO/European A4-sized paper, 8.3x11.7" ]
**
** A special note about indexing.  If you have names with double quotes in
** them, e.g. Forrest "Foggy" Morrison, not the nice Latex quotes style:
** Forrest ``Foggy'' Morrison, then the " marks will screw up the index.

  If you'd like to credit me & this program in your
  introduction if it's something you're really going to publish
  that'd be nice (but not required).
  Something like this could be used:
     "This document was prepared using LifeLines v." version() " genealogical database program\n"
     "by Thomas T.~Wetmore~IV, {\\tt ttw@beltway.att.com}. The script {\\tt book-latex}\n"
     "by Dennis Nicklaus {\\tt dnicklaus at yahoo.com} was used to generate the \\LaTeX\\ code.\n"

*/
/* WHAT DENNIS NICKLAUS DID:
  I expanded this program greatly, mostly based on a "book" report
  done by Kurt Baudendistel (baud@research.att.com).
  I combined what I liked best about register-tex and the book report.

  numbering:
    Register-tex had modified register numbering, where book
    had no numbering, and just always referred to people by
    page number, so I took the mod. reg. numbering.
  sources/bibliography:
    book had really nice SOUR support, so I took that
    and modified it a little bit, so that it supports
    a more std. gedcom usage of the SOUR definitions
    (according to my reading of the std).
  nothing needed in database:
    book required that you have various things like CHAP
    and PART additions to your lifelines gedcom database
    in order to find who to include in the book.
    I didn't include that
  multiple-person selection:
    On the other hand, maybe you want to include the
    descendants of more than one person. I included the
    ability (which was sort of there in book) of specifying
    multiple people.  For Instance, you might specify your
    maternal grandfather and your paternal grandfather to
    get all your first cousins on both sides into the same
    book.  This report asks you to keep selecting as many
    people as you want.  It does the complete descendancy
    for each person selected.  Each person so selected
    starts a new chapter in the book.  I make up a title
    of the book based on the surnames of indi's chosen.
    When you don't want to select any more people, just
    hit return at the "select indi" prompt.
  english sentences:
    The book report was very good at automatically making
    real sentences instead of just fragments. I used that.
    I try to make compound sentences using "and" whenever
    possible, and this makes for a lot of rules in the
    code to try to handle a lot of cases. I probably missed a 
    few where the English will still come out poorly.
  placename smarts:
    Also from book is the ability to recognize a place which
    is used multiple times. For instance, the first time
    it sees Keswick,Keokuk Co.,Iowa, it'll print the whole
    thing.  But then every subsequent time, it'll just print
    Keswick.  Makes things VERY readable, but it can leave
    some ambiguous things, like if you have two Keswick's,
    it might be hard to figure out which is meant.
    Likewise, I picked up ADDR support from book.
    if you have: 
      2 PLAC thattown
      3 ADDR thisplace
    It'll say "at thisplace in thattown".  Simply having
    2 PLAC results in "in thattown".
    One thing I did change from book was making sure 
    it always says "in thattown" after saying "at thisplace".
    Book was happy just saying "at thisplace" and assuming
    you know what it meant.
    But if you have several of
      2 PLAC Town,County,State
      3 ADDR his home
    Then just saying "at his home" doesn't do much, so I made
    sure it always says at least "at his home in Town".
    (the first time, it'd say, "at his home in Town,County, State".)
    (also useful if you have lots of different St. Mary's, e.g.)
    I also made it watch for words like "near, north,..."
    for the "town" part of the place, so that it doesn't say
    something icky like "in near Mytown".
  many events:
    register-tex supported a lot more GEDCOM fields, so 
    I tried to include all of them.
    But I personally don't use all of them, so some may look ugly.
  charts: I added a feature that makes it draw 3 gen desc. tree charts
    for any indi who heads up a chapter.  I took code
    from desc-tex to do this. (and modified it slightly
    because it didn't work for some cases).
    So you need the tree.tex macros, which this will
    try to include.
    Note:  I modified the tree.tex macro a little bit
    to scrunch things up because I have some ancestors
    with huge families, and all their 10 kids had big families,
    so I had to scrunch the spacing to fit 3 gen. onto one page.

    I dropped most of the pedigree chart capabilities in book,
    but I did add one thing to look for the something like:
      1 NOTE BOOKPEDIGREE
    on each indi. If a note like that is found for an indi,
    that indi's pedigree (8 gen, I think) will be printed
    as a latex figure in the book.  I find this useful,
    for instance, when I do a book of all the desc. of
    all the grandparents of my grandmother.  I have
    a BOOKPEDIGREE note on my grandmother so you can see
    how all these lines fit together.

    If you have
      1 NOTE BOOKDESCENDENT 
    on an individual, it'll draw a 3-gen desc. chart for that person.


  excursions: These are for when you are following one family
    down, say SMITH, and one of the SMITHs marries a JONES.
    If you want to include the JONES ancestry in this book,
    but don't really want to follow every JONES descendant,
    then if you put a note on the JONES person:
      1 NOTE BOOKEXCURSION
    That causes this report to wait until the end of the
    chapter, then make a subsection which goes to the
    farthest male JONES ancestor, and document
    the direct line between that JONES ancestor and the
    JONES who married the SMITH.  It doesn't follow
    every JONES line down, but includes info about each
    child of each direct JONES ancestor.

  intro
    I include the possibility that you might want to put
    your own introduction before most of the book.
    You can input your own intro file if you want.
    It should contain all the Latex directives you want
    also, such as \chapter{Introduction}.

  grandchild divisions
    Starting with the 4th generation down from each chapter head,
    I group together sets of grandchildren with over and
    under braces. (It doesn't make any sense to do it for
    generations 1-3 because they'd all be in the same group.)
    The idea is that if patriarch has kids A,B,C...
    Then by generation 4, you'll get a grouping of A's grandkids
    followed by B's grandkids, followed by C's grandkids.
    Lots of intermarrying might occasionally confuse the 
    code which does this.

  Chapter splits
    If you put a
      1 NOTE BOOKCHAPSPLIT
    on the person who is a chapter head, 
    then each of his children will head up their own chapters with
    the children of that head as Generation 1 in their respective chapters.
    You should be careful not to have a BOOKCHAPSPLIT on anyone who
    is not the head of a line, or it'll probably come out ugly.

    Okay, now that you know how to produce a report, here are the formatting
    conventions you must follow to get a good one. All records shown here are 
    optional, and all other records are okay -- they'll just be ignored by 
    the book report:

     1 NAME - Multiple name records allowed. First is ``true name.''
            - Later ones, with given but no surname, are ``nicknames''
              or familiars. 
            - Later ones, with surname but no given, are aliases or
              alternate spellings.
            - Later ones, with both surname and given, are aliases.
            - Post-titles, such as MD, should be included in this name.
     2 SOUR ... - Source for name.
     1 TITL ... - Pre-titles, such as Reverend. (but I don't call people
                  by their titl much. I mean after all, a person
                  isn't Captain John yet when they are born.
                  So I currently ignore this.)
     1 SEX  ...
     1 SOUR ... - Source for parentage if no BIRT or CHR is given. This 
                  produces better output than BIRT-SOUR records with no
                  DATE or PLAC given.
                  I also use this when I have a general source
                  which tells me everything about the person and
                  I don't want to mess things up by citing it
                  separately 8 times for birth, death, marr,...
     1 evnt ... - BIRT, CHR, DEAT, BURI, CREM, MARR, DIV, DIVF, or ANUL,...
     2 DATE ... - Date should be of format
                  [ABT|BEF|AFT|BET] [day] [JAN|...|DEC] [year] [-year for BET]
     2 PLAC ... - Comma separated list of localities appropriate for the
                  expression ``in ...''.
     3 ADDR ... - Location appropriate for the expression ``at ... in ...''.
     3 CEME ... - Location appropriate for the expression ``at ... in ...''.
     2 AGE  ... - Age appropriate for the expression ``at age ...''.
     2 CAUS ... - Cause of death appropriate for the expression
                  ``died of ...''.
     2 SOUR ... - Source for event.
     2 NOTE ... - Text to be inserted in book following technical details
                  of the event. (I use this instead of TEXT)
     3 SOUR ... - Source for text.
     1 OCCU ... - Description (title) of an occupation (job).
     2 AGNC ... - Employer (produces "worked [or became] a <OCCU> with <AGNC>").
     1 TEXT ... - Text to be inserted in book about the person.
                  I toyed with putting this before the death info,
                  but decided I like having all the vital stuff first,
                  then the more interesting text stuff.
     2 SOUR ... - Source for text.
     1 NCHI ... - Number of children (family records only).

     n CONT ... - Appropriate for TEXT and SOUR.

    You have the option of selecting either 1 TEXT, 1 NOTE or (not and)
    only those 1 NOTE records which start with an ! (exclamation)
    to include as the main body of text for each individual.

    From the GEDCOM std, TEXT "contains information from the source document."
    One might argue that I'm misusing it here.  But it depends on what
    kinds of things you use 1 TEXT for. It might be nicely readable and
    technically appropriate if, for example, you copy a bio. of someone from
    an old book and want it included in your printout.  Also, in sort of
    a self-referential way, you're including text from the book you
    publish with this. :-)

    I personally don't print out the "1 NOTE" records because I personally
    (and feel it is common that most people) have a lot of garbage in their
    notes, either general reminders to themselves, or PAF-style source notes
    (e.g. 1 NOTE BIRTH-DEATH: whatever source)
    However, with version 2.2, I give the option to print out either
    all 1 TEXT, all 1 NOTE, or all 1 NOTE !-tagged notes. (where if the
    1st char of the note is !, then the 1 NOTE gets included).

    Something that I consider a typical 2 NOTE usage might be:
      1 BURI
        2 DATE when
        2 PLAC somewhere
        2 NOTE (with her parents)
    But you do have to be a little aware of what this report is going
    to generate if you want to make it a grammatically correct sentence

    

  SOURCE records are complicated, but they produce great output. 

    To document a fact with a simple footnote, use

       n SOUR ...
      +1 CONT ...

    This can get more complicated (all records optional):
    (actually, I'm not sure what all is supported for footnotes
    any more, I mostly use bibliography entries.)

       n SOUR ...
      +1 CONT ...
      +1 PAGE ...
      +1 VOLU ...
      +1 NOTE ...
      +2 CONT ...
      +1 SOUR @id@

    The +1 SOUR @id@ produces a citation to an entry in the bibliography, 
    not a footnote, that is attached to the text of the footnote.  To get 
    a citation in the text itself, use

       n SOUR
      +1 SOUR @id@

    or the more simple

       n SOUR @id@

    To create a bibliographic entry that can be referenced as a citation,
    include a cross-reference definition. This can be included at the point
    where a citation is wanted. However, since you will like re-use the
    same citation many times and you'll want to be consist, define the
    cross-reference definition separately.

    A cross-reference definition takes this form (start at level 0)

      n @id@ SOUR   - no text allowed here
     +1 AUTH ...    - author of source
       +2 EMAI ...  - e-mail address of author (useful for fellow genealogists)
                      there is now an option to block e-mail addresses from
                      showing in the output (in their place is a mention that
                      one is on file)
       +2 ADDR ...  - postal address of author
     +1 TITL ...    - title of article or book
     +1 PUBL        - publishing info record
   note that all these +2 things have to be under it for a bib. entry.
   (rules are diff. for footnotes).
   This is the way I read the 5.3 GEDCOM std.
     +2 NAME ...   - name of publication,e.g. journal
     +2 PUBR ...   - publisher name
     +2 ADDR ...   - address
     +2 PHON ...   - phone number
     +2 DATE ...   - date of pub.
     +2 VOLU ...   - volume or list or range
     +2 NUM  ...   - number or list or range

     +1 FILM ...   - LDS film number
     +1 FICH ...   - LDS fiche number
     +1 PAGE ...   - page or list or range
     +1 REPO ...   - library name
     +1 NOTE ...   - free form text
     +2 CONT ...
     +1 SOUR @id@  - cite another source from bibliographic entry
     +1 TEXT ...   - free form text to print
     +2 CONT ...

    Note that the id can be most text that begins with an alphanumeric 
    character -- check your gedcom spec! Using a descriptive name of 
    the source that it represents, such as kurts-death-record or 0996198 
    (for film numbers) is a good idea.
    (but Lifelines eats the nice names when it reads them in)

SEMI-BROKEN STUFF

  A few problems you might notice:
  I'm not really happy with the desc. trees in several other cases,
  such as multiple spouses, and had to fix desctex a little bit
  to make it work better.  It still isn't perfect, I don't think.
  
  The sentence structure may come out badly in some odd cases I haven't
  encountered/tested yet.  It's been a real pain to get it as
  far as it is, and I'm still not happy with it.  (It gets complicated
  because I try to make compound sentences and use pronouns so
  it isn't so choppy.)

  The "test for common grandparents" thing was just the simplest
  way of doing it I could think of. Not perfect, but works 99%.

  I really want to put some smarts in so placename ambiguity is 
  less of a problem. For instance to distinguish the town of 
  Washington, Iowa from the state of Washington.

  My LaTex is sort of rusty, and some things aren't really properly
  done, possibly. (Like the spacing on the overbraces designed to
  fill one column.) Also, it's line-filling is pretty weird sometimes,
  such as just putting one or two words in the first line of a 
  person's description. I don't understand why it does that.

FOR VERSION 2:  
  I also now support a book which goes through an individual's
  ancestors in ascending order.  Numbering is ahnentafel style.
  A new chapter for each generation.

FOR VERSION 2.2
  (Several of these were suggested by Ed Sternin (edik@brocku.ca)

   a.  Fixed problem where in the descendant trees if a spouse's 
       last name isn't known.  It now puts in escaped underscores.
       (Also fixed printfirstname [now printablefirstname] to print
       underscores when no given name is known.)

   b.  Added the BOOKCHAPSPLIT option 
       If you put a 
       1 NOTE BOOKCHAPSPLIT on the person who is a chapter head, 
       then each of his children will head up their own chapters with
       the children of that head as Generation 1 in their respective chapters.
       I added this because I have a family where the father had 3 sons.
       I want to include the info on the father, but I also want each
       of the three sons to have their own chapter.  So I put a 
       BOOKCHAPSPLIT note on the father, and it all comes out automatically.
       You should be careful not to have a BOOKCHAPSPLIT on anyone who
       is not the head of a line, or it'll probably come out ugly.
       (It causes subsequently members of the generation of the noted 
       person to have separate chapters, as well as the children of 
       the noted person.)

   c.  I give the option to print out either all 1 TEXT, all 1 NOTE, or all
       1 NOTE !-tagged notes (where if the 1st char of the note is !, then the
       1 NOTE gets included).

   d.  Fixed mistake with running headers in ancestor format books so the
       running header is now "<name> Ancestors", not "Descendents".

   e.  Added option (query turned off by default to match old way since it is
       confusing to a beginner) to reset the placenametable at each generation.
       If this option is selected, then the effect is that any placename
       will have the fully specified (long) name printed out once in each 
       generation. I find this useful sometimes, just to remind people
       where you're talking about since it might have been a long time
       since the place was introduced.

   f.  if there is a 1 Event, 2 DATE or 2 PLAC record where there is 
       no value on the 2 DATE or 2 PLAC (but the record is present),
       it'll no fill in an underscore where the date/place would be, e.g.,
         Joe was born in ____ in ____ .
       Previously if the 2 DATE or 2 PLAC were present and empty, it 
       would have said "born in in ." which isn't so nice.

   g.  Changed from supporting 3 SITE records to 3 ADDR records because
       SITE isn't supposed to be part of std. GEDCOM anymore, ADDR is.
       I hope this is as easy of a global replace for you as
       it was for me. (of a gedcom file in a text editor).

   h.  Fixed A back-reference number (explaining that children were shown
       earlier) in ancestor mode.

   i.  Fixed problem in ancestor mode that would print out the long text for
       some individuals more than once.
  
  New For Version 2.3
  Not much is new:
    Don't do excursions in ancestor mode
    Added a couple LaTex macros that I use for pictures.

  New For Version 2.4
  Some contributions by Dave Steiner (steiner@bakerst.rutgers.edu)
    Some very minor typesetting fixups to make some spacing more
    consistent. Some  spaces added in certain parts, spaces taken
    out of other places.
    Says a couple "have no children" instead of "had no children" if
    it looks like the couple are still married and living.
    The bibliography filename will now be <outfile>-bib.tex
    instead of <database>-bib.tex.

  Supports CONC as well as CONT continuation lines in most places.

  I've made a couple other similarly minor cosmetic changes,
  one of which forces a new paragraph during excursions in an oddball case.

  Made a change in ancestor mode so that if cousins marry, it won't
  print the information about the common ancestors twice.

  Also an ancestor mode change so that ref. numbers for a person's
  parents appear in the text in the longvitals() description.

  New For Version 2.5.
  Fixed a mistake in check_print_divinfo which made it not work at all.

  New For Version 3.0
  Several miscellaneous fixes.
  Now part of lifelines sourceforge distribution. See sourceforge history.
  Uses documentclass instead of documentstyle
  Added ability to print a limited number of generations in
  descendant-style books. At the terminal generation, if a person
  is not dead, it will only print the birth year, not full date.
  Fixed the titlepage generation.
  Some fixes to support latest version of lifelines (or maybe its
  just differences for lifelines under solaris):
     Intersect() can't be used inside an if() call.
         It has to call intersect separately and use the result in a set()
     The childnum argument of children() is now only valid
         within the scope of the children() loop.
*/

/* Stuff I haven't implemented:
   adler@math.toronto.edu (Jeffrey D. Adler)
     One suggestion came from "Denis B. Roegel" <Denis.Roegel@loria.fr>
  regarding the over/under braces.
  He suggested using something like:
  \begin{minipage}{\columnwidth}
  $\overbrace{\hspace*{3in}}$
  \vspace{3ex}
  \begin{center}{\large\bf 24\ Henry REGLE}\end{center}
  \end{minipage}
  \nobreak
  Henry {\sc REGLE}\index{REGLE, Henry|bfit}, ...
  and For \underbrace, try to put a \nobreak before:
  \nobreak
  $\underbrace{\hspace*{3in}}$

  I haven't tried this out to see if I like it better.
  But I did include some of the \nobreaks before the underbrace
  and after the big center-ed person's name.
*/

global(maxgenprint)      /* number of generations to print full info for.*/
global(atmax_generation) /* used so we don't print full birthdates of living
                            individuals at the MAX-th generation */
global(ancestormode)
global(notes_text_mode)
global(eventPlaceTable)
global(atAddrValue)
global(eventNameTable)
global(in)
global(out)
global(idex)
global(stab)
global(powValue)
global(namereturn)
global(excurlist)
global(sourceList)
global(bibList)
global(bibTable)
global(figureCiteList)
global(figureNodeList)
global(gotValue)
global(gottenNode)
global(gottenValue)
global(dayNumber)
global(previousDayNumber)
global(daysToMonthList)
global(not_married_flag)
global(dumpplacetable_each_gen)
global(hadsplitnote)
global(force_desc_chart)
global(pedigreeFigureLabel)
global(global_dead)/* used at the MAX-th generation so we know if indi is dead*/
global(tex_xlat)   /* table used to escape characters meaningful to TeX */
global(opt_xlat)
global(opt_email)  /* flag indicating whether source author's
                      e-mail should be shown */

proc main() {
  list(headlist)
  table(stab)    /* Table of numbers for each individual */
  list(bibList)
  list(excurlist)
  table(bibTable)
  list(figureCiteList)
  list(figureNodeList)

  list (sourceList)

  set(opt_xlat, 1)
  table(tex_xlat)
  insert(tex_xlat, "$", "\\$")
  insert(tex_xlat, "&", "\\&")
  insert(tex_xlat, "%", "\\%")
  insert(tex_xlat, "#", "\\#")
  insert(tex_xlat, "_", "\\_")
  insert(tex_xlat, "{", "\\{")
  insert(tex_xlat, "}", "\\}")
  insert(tex_xlat, "~", "\\verb|~|")
  insert(tex_xlat, "^", "\\verb|^|")
  insert(tex_xlat, "\\", "\\verb|\\|")
  insert(tex_xlat, "<", "$<$")  /* out of math mode, < and > produce */
  insert(tex_xlat, ">", "$>$")  /*   upsidedown ! and ? marks        */

  list(daysToMonthList)
  setel(daysToMonthList, 1, 0)
  setel(daysToMonthList, 2, 31)
  setel(daysToMonthList, 3, 59)
  setel(daysToMonthList, 4, 90)
  setel(daysToMonthList, 5, 120)
  setel(daysToMonthList, 6, 151)
  setel(daysToMonthList, 7, 181)
  setel(daysToMonthList, 8, 212)
  setel(daysToMonthList, 9, 243)
  setel(daysToMonthList, 10, 273)
  setel(daysToMonthList, 11, 304)
  setel(daysToMonthList, 12, 334)
  set(force_desc_chart, 0)

  getindimsg(indi, "Enter the first person for the report")
  if(not(indi)) {
    return(0)  /* assume the user wants to quit */
  }
  set(familycount, 0)
  while(indi) {
    set(familycount, add(familycount, 1))
    enqueue(headlist, indi)
    set(indi, 0)
    getindimsg(indi, "Enter another root person or none to proceed")
  }

  if(1) {
    getintmsg(ancestormode, "Enter 0 for descendant, 1 for ancestor report")
  } else {
    set(ancestormode, 0)
  }

  set(maxgenprint, 999)
  if(eq(0, ancestormode)) {
    if(1) {
      getintmsg(maxgenprint, "Max generations for descendancy books")
    } else {
      set(maxgenprint, 999)
    }
  }

  if(1) {
    getintmsg(notes_text_mode,
      "Book Text:1='1 TEXT'; 2= all '1 NOTE'; 3= !-tag '1 NOTE's")
  } else {
    set(notes_text_mode, 1)
  }

  if(0) {  /* change this to  "if (1)" to turn this query on. */
    getintmsg(dumpplacetable_each_gen,
      "Enter 1 to reset place name table each generation, 0 to not")
  } else {
    set(dumpplacetable_each_gen, 0)
  }
  
  if(1) {
    getintmsg(opt_email,
      "Enter 1 to show source authors' e-mail addresses, 0 to not")
  } else {
    set(opt_email, 0)
  }

  /* Print preamble.  Feel free to change this to suit your tastes. */
  "\\documentclass[twocolumn,twoside,titlepage]{book}\n"  /* LaTeX 2e */
  /*"\\documentstyle[twocolumn,makeidx]{book}\n"*/
  "\\pagestyle{myheadings}\n\n"
  "% Enable ISO 8859/1 charset" nl()
  "\\usepackage{isolatin1}" nl()
  "% Shrink the margins to use more of the page.\n"
  "% This is taken from fullpage.sty, which is on some systems.\n"
  "\\topmargin 0pt\n"
  "\\advance \\topmargin by -\\headheight\n"
  "\\advance \\topmargin by -\\headsep\n"
  "\\textheight 8.9in\n"
  "\\oddsidemargin 0pt\n"
  "\\evensidemargin \\oddsidemargin\n"
  "\\textwidth 6.5in\n\n"
  "\\newcounter{childnumber}\n\n"
  "% The \\noname command is needed because TeX doesnt like underscores.\n"
  "\\newcommand{\\noname}{\\underline{\\ \\ \\ \\ \\ }}\n\n"
  "\\newcommand{\\nodate}{\\underline{\\ \\ \\ \\ }}\n\n"
  "% Environment for printing the list of children.\n"
  "\\newenvironment{childrenlist}"
    "{\\begin{small}\\begin{list}{\\sc\\roman{childnumber}.}"
    "{\\usecounter{childnumber}\\setlength{\\leftmargin}{0.5in}"
    "\\setlength{\\labelsep}{0.07in}\\setlength{\\labelwidth}{0.43in}}}"
    "{\\end{list}\\end{small}}\n\n"
  "% The following commands are used to create the index.\n"
  "\\newcommand{\\bold}[1]{{\\bf #1}}\n"
  "\\newcommand{\\bfit}[1]{{\\bf\\it #1}}\n"
  "%%\\newcommand{\\see}[2]{{\\it see #1}} %not needed with makeidx.sty\n\n" 
  "% Command to use at the beginning of each new generation.\n"
  if(ancestormode) {
    "\\newcommand{\\generation}[2]"
      "{\\newpage\\begin{center}{\\huge\\bf Generation #1}\\end{center}"
      "\\vspace{3ex}\\setcounter{footnote}{0}"
      "\\markright{#2 Ancestors" "\\hfill Generation #1\\hfill\\ }"
      "}\n\n"
  } else {
    "\\newcommand{\\generation}[2]"
      "{\\newpage\\begin{center}{\\huge\\bf Generation #1}\\end{center}"
      "\\vspace{3ex}\\setcounter{footnote}{0}"
      "\\markright{#2 Descendants" "\\hfill Generation #1\\hfill\\ }"
      "}\n\n"
  }
  "\\newcommand{\\image}[4]"
    "{\\begin{figure}\n\\centerline{\\psfig{figure=#1,height=#4}}\n"
    "\\label{#3}\n"
    "\\caption{#2}\n\\end{figure}}\n"
  "\\newcommand{\\imwide}[4]"
    "{\\begin{figure*}\n\\centerline{\\psfig{figure=#1,height=#4}}\n"
    "\\label{#3}\n"
    "\\caption{#2}\n\\end{figure*}}\n"

  "\\makeindex\n\n"
  "\n\\input{tree}\n" /* needed for making descendant trees */
  "\\begin{document}\n\n"
  
  /*******************************************/
  /* Make the title */
  /*******************************************/
  "\\title{ The " 
  forlist(headlist,head,localcount) {
    if(gt(localcount,1)) {
      if(gt(familycount,2)) {    /* don't say "a, and b." */
        ", "
      }
      if(eq(localcount,familycount)) { " and " }
    }
    strxlat(tex_xlat, surname(head))
  }
  if(eq(1,familycount)) {
    " Family}\n"
  } else {
    " Families}\n"
  }

  getstrmsg(author, "Enter the author(s) of this document:")
  "\\author{" strxlat(tex_xlat, author) "}\n"
  "\\date{\\today}\n"
  "\\maketitle\n"

  "\\clearpage\n"
  "\\onecolumn\n"
  "\\pagestyle{empty}\n"
  "\\mbox{ }\n"
  "\\vfill\n"
  "\\begin{center}\n"
  "Copyright \\copyright \\ \\today \\  " strxlat(tex_xlat, author) "\\\\" 
  getstrmsg(copyplace, "Enter the place for the copyright notice:")
  strxlat(tex_xlat, copyplace) "\n"

  "\\end{center}\n"
  "\\clearpage\n"
  "\\pagestyle{myheadings}\n"
  "\\twocolumn\n"

  "\\setcounter{page}{1}\n"
  "\\tableofcontents"

  getstrmsg(intro, "File that contains introduction (if any):")
  if(ne(strcmp(intro, ""), 0)) {
    "\\input{" intro "}\n"
  }



  table(eventNameTable)
  table(eventPlaceTable)
  table(eventNameTable)
  insert(eventNameTable, "BIRT", "was born")
  insert(eventNameTable, "ADOP", "was adopted")
  insert(eventNameTable, "BAPM", "was baptized")
  insert(eventNameTable, "CHR",  "was baptized")
  insert(eventNameTable, "DEAT", "died")
  insert(eventNameTable, "BURI", "was buried")
  insert(eventNameTable, "CREM", "was cremated")
    /* GRAD left blank since it is done as a separate case */
  insert(eventNameTable, "GRAD", "")
  insert(eventNameTable, "NATU", "was naturalized")
  insert(eventNameTable, "CHRA", "was christened (as an adult)")
  insert(eventNameTable, "CENS", "was listed in the census")
  insert(eventNameTable, "ORDN", "was ordained")
  insert(eventNameTable, "RELI", "")
  insert(eventNameTable, "RESI", "lived")
  insert(eventNameTable, "CONL", "was confirmed")
  insert(eventNameTable, "CONF", "was confirmed")
  insert(eventNameTable, "BLES", "was blessed")
  insert(eventNameTable, "BASM", "was bat mitzvah-ed")
  insert(eventNameTable, "BARM", "was bar mitzvah-ed")
  /* these two Will related things come out kind of icky because
     I just always use plain pronouns like he, she, not
     possessive ones, so I have to say "he wrote  a will"
     instead of "his will was dated"
  */
  insert(eventNameTable, "PROB", "had a will probated")
  insert(eventNameTable, "WILL", "wrote a will")
  insert(eventNameTable, "RETI", "retired")


  indiset(idex)


  set(out, 1)
  set(in, 1)

  dayformat(2)
  monthformat(6)
  dateformat(1)
  while(indi, dequeue(headlist)) {
    if(ancestormode) {
      call  ancestor_chapterproc(indi)
    } else {
      call chapterproc(indi)
    }
  }

  set(basename, 
    save(substring(outfile(), 1, sub(index(outfile(), ".", 1), 1))))

  /* Output bibliography commands */
  if(not(empty(bibList))) {
    "\n\n\\onecolumn"
    "\n\\cleardoublepage"
    "\n\\label{Bibliography}"
    "\n\\addcontentsline{toc}{chapter}{Bibliography}"
    "\n\\begin{thebibliography}{9.99}"
    "\n\\input{" basename "-bib.tex}"
    "\n\\end{thebibliography}"
  }
  "\n\n\\cleardoublepage"
  "\n\\label{Index}"
  "\n\\addcontentsline{toc}{chapter}{Index}"
  "\n\\input{" basename ".ind}"

  "\n\n\\end{document}\n"

  /* Output bibliography file */
  print("\n\nCreating support files ...")
  if( not(empty(bibList)) ) {
    newfile(concat(basename, "-bib.tex"), 0)
    print("writing to : ")
    print("\n")
    print(concat(basename, "-bib.tex"))
    print("\n")
    while(b, dequeue(bibList)) { b }
  }
}

proc chapterproc(topguy) {
  list(ilist)    /* List of individuals */
  list(glist)    /* List of generation for each individual */
  set(last_grandparents,0)
  indiset(grandparentset)
  indiset(hisset)
  indiset(last_grandparentset)
  set(chapterTitle, 
  save(concat("The ", 
    concat(fullname(topguy, 0, 1, 99), "\ Family"))))
  
  "\n\\chapter{" chapterTitle "}" "\n"

  enqueue(ilist, topguy)
  enqueue(glist, 1)
  set(curgen, 0)
  set(printed_brace,0)
  set(just_printed_brace,0) 

  /* we have to do this add1 once for the topguy of each chapter
     We used to start out with "in" initialized to 2, but that made
     the numberings bad when there were multiple chapters, so now
     we init to 1 and do this +1 here
  */
  set(in, add(in, 1))

  set(hadsplitnote,0)
  set(this_level_hadsplitnote,0)

  while(indi, dequeue(ilist)) {
    /* This is where we implement the "Chapter Split".  The idea is,
       that if you put a BOOKCHAPSPLIT note on the head of a line, then
       each of his children will head up their own chapters with
       the children of that line as Generation 1 in their respective chapters.
    */
    if(eq(1,this_level_hadsplitnote)) {
      call chapterproc(indi)
    } else {
      set(thisgen, dequeue(glist))
      if(ne(curgen, thisgen)) {
        /* If we are starting a new generation, close off brace
           from previous gen. if necessary
        */
        if(printed_brace) {
          "\n\\nobreak"
          "\n" "$\\underbrace{\\hspace*{3in}}$" "\n\n"
          set(printed_brace,0)
        }

        if(dumpplacetable_each_gen) {
          table(eventPlaceTable)
        }
        print("Generation ") print(d(thisgen)) print("\n")
        "\n\n\\generation{" d(thisgen) "}" "{"
        strxlat(tex_xlat, surname(topguy)) "}" "\n"
        "\n\\addcontentsline{toc}{section}{Generation " d(thisgen) "}\n"  
        set(curgen, thisgen)
        set(last_grandparents,0)
        indiset(last_grandparentset)
        set(printed_brace,0)
        if(eq(curgen,maxgenprint)) {
          set(atmax_generation,1)
        } else {
          set(atmax_generation,0)
        }
      }
      /* decide if we have the same grandparents or not */
      /* I try to group people  together with over/under braces
         for people descended from the same grandparent in this descendancy */
      /* rather than remember who belongs to what line, I just look
         at all their grandparents and if they overlap with the grandparents
         of the previous person, then I assume I'm on the same line.
         This isn't always true, but it is a start, at least.
      */
      if(gt(curgen,3)) {
        if(eq(0,last_grandparents)) {
           "\n" "$\\overbrace{\\hspace*{3in}}$" "\n"
           set(printed_brace,1) 
           set(just_printed_brace,1) 
           indiset(hisset)
           addtoset(hisset,indi,1)  
           set(grandparentset,parentset(parentset(hisset)))
           set(last_grandparentset,grandparentset)
           set(last_grandparents,1)
         } else {
           indiset(hisset)
           addtoset(hisset,indi,1)  
           set(grandparentset,parentset(parentset(hisset)))
           set(doit,1)
           indiset(extraSet)
           set(extraSet,intersect(grandparentset,last_grandparentset))
           forindiset(extraSet, joe, a, b) {
             set(doit,0)
           }
           if(doit) {
             if(printed_brace) {
               "\n\\nobreak"
               "\n" "$\\underbrace{\\hspace*{3in}}$" "\n\n"
             }
             "\n" "$\\overbrace{\\hspace*{3in}}$" "\n\n"
             set(printed_brace,1) 
             set(just_printed_brace,1) 
             /* also reset the place table after each set of grandchildren.
                This makes it repeat the whole location name the next time
                it sees any location. Otherwise, it can get too far from the
                introduction of the place for my liking.
             */
            if(dumpplacetable_each_gen) {
              table(eventPlaceTable)
            }
          }
          set(last_grandparentset,grandparentset)
          set(last_grandparents,1)
        }
      }

      print(d(out)) print(" ") print(name(indi)) print("\n")

      /* only do the vspace between people if there was no overbrace printed.
         Otherwise there is too much white space and it looks icky.
      */
      if(eq(0,just_printed_brace)) {
        "\n\\vspace{3ex}\\ \\\\"
      }
      set(just_printed_brace,0) 

      "\\begin{center}{\\large\\bf " d(out) "\\ "
      strxlat(tex_xlat, name(indi)) "}\\end{center}\n"
      "\\nobreak\n"
      insert(stab, save(key(indi)), out)

      call longvitals(indi, 1, 2)
      if(hadsplitnote) {
        set(this_level_hadsplitnote,1)
      }
  
      addtoset(idex, indi, 0)
      set(out, add(out, 1))
      /* check whether the children we are about to print are at the
         Max generation
      */
      set(save_atmax_generation,atmax_generation)
      if(eq(add(curgen,1),maxgenprint)) {
        set(atmax_generation,1)
      }

      families(indi, fam, spouse, nfam) {
        "\n\n"
        if(eq(0, nchildren(fam))) {
          call texname(inode(indi), 0) "\\ and "
          if(spouse) {
            call texname(inode(spouse), 0)
          } else {
            "\\noname"
          }
          call havehadchildren(indi, spouse)
        } elsif(and(spouse, lookup(stab, key(spouse)))) {
          "Children of " call texname(inode(indi), 0) "\\ and "
          call texname(inode(spouse), 0) "\\ are shown under "
          call texname(inode(spouse), 0)
          "(" d(lookup(stab, key(spouse))) ").\n"
        } else {
          "Children of " call texname(inode(indi), 0) "\\ and "
          if(spouse) {
            call texname(inode(spouse), 0)
          } else {
            "\\noname"
          }
          ":\n\\begin{childrenlist}\n"
          children(fam, child, nchl) {
            set(haschild, 0)
            families(child, cfam, cspou, ncf) {
              if(ne(0, nchildren(cfam))) {
                set(haschild, 1)
              }
            }
            if(and(haschild,lt(curgen,maxgenprint))) {
              if(not(lookup(stab, key(child)))) {
                enqueue(ilist, child)
                enqueue(glist, add(1, curgen))
                "\n\\item[{\\bf " d(in) "}\\ \\hfill"
                "\\addtocounter{childnumber}{1}"
                "{\\sc\\roman{childnumber}}.]"
                set(in, add(in, 1))
                call shortvitals(child)
              } else {
                "\n\\item[{\\bf " d(lookup(stab, key(child))) "}\\ \\hfill"
                "\\addtocounter{childnumber}{1}"
                "{\\sc\\roman{childnumber}}.]"
                call shortvitals(child)
                "  Details of " pn(child, 3) " family were shown earlier."
              }
            } else {
              if(haschild) {
                set(force_desc_chart, 1)
              }
              "\n\\item "
              call longvitals(child, 0, 1)
              set(force_desc_chart,0)
              addtoset(idex, child, 0)
            }
          }
          "\\end{childrenlist}\n"
        }
      }
      set(atmax_generation, save_atmax_generation)

      if(eq(indi,topguy)) {
        set(descFigureLabel, save(concat(key(indi), "-figure-desc")))
        "\nA brief chart of the descendants of this line is contained in "
        "Figure~\\ref{"   descFigureLabel   "}."
        "\n\\begin{figure*}\n"
        "\\centering\n"
        call desc_chart_main3(indi)
        "\n\\caption{Descendents of " fullname(indi,0,1,99) "({\\bf "
        d(lookup(stab, key(indi))) "})}" nl()
        "\\label{" descFigureLabel "}"
        "\\end{figure*}\n"
      }
    }
  }

  /* Close off the last braces if necessary */
  if(printed_brace) {
    "\n\\nobreak"
    "\n" "$\\underbrace{\\hspace*{3in}}$" "\n\n"
  }
  set(printed_brace,0)


  while(indi, dequeue(excurlist)) {
    call excursion(indi)
  }
}


/* Run this routine if you want an ahnentafel style report for the
   individuals named
*/
proc ancestor_chapterproc(topguy) {
  list(ilist)    /* List of individuals */
  list(glist)    /* List of generation for each individual */
  list(alist)
  set(chapterTitle, 
  save(concat(fullname(topguy, 0, 1, 99), "\ Ancestors")))
  "\n\\chapter{" chapterTitle "}" "\n"

  enqueue(ilist, topguy)
  enqueue(alist,1)
  enqueue(glist, 1)
  set(curgen, 0)
  insert(stab, save(key(topguy)), 1)

  while(indi, dequeue(ilist)) {
    set(ahnen, dequeue(alist))
    set(thisgen, dequeue(glist))
    if(ne(curgen, thisgen)) {
      print("Generation ") print(d(thisgen)) print("\n")
      "\n\n\\generation{" d(thisgen) "}" "{"
      strxlat(tex_xlat, surname(topguy)) "}" "\n"
      "\n\\addcontentsline{toc}{section}{Generation " d(thisgen) "}\n"  
      set(curgen, thisgen)
      /* reset the place table at each generation if asked to. */
      if(dumpplacetable_each_gen) {
        table(eventPlaceTable)
      }
    }
    print(d(ahnen)) print(" ") print(name(indi)) print("\n")

    "\n\\vspace{3ex}\\ \\\\"

    "\\begin{center}{\\large\\bf " d(ahnen) "\\ "
    strxlat(tex_xlat, name(indi)) "}\\end{center}\n"

    /****************************************************************/
    /* first, enqueue his parents onto the lists so their numbers
       will be printed out in the description of "indi" */
    /* also includes a check to see if indi's parents are already
       there such as will happen when cousins marry.
    */
    set(print_dad_note,0)
    set(print_mom_note,0)

    if(par,father(indi)) {
      if(not(lookup(stab,key(par)))) {
        enqueue(ilist, par)
        enqueue(alist, mul(2,ahnen))
        enqueue(glist, add(curgen, 1))
        insert(stab, save(key(par)), mul(2,ahnen))
      } else {
        set(print_dad_note,key(par))
      }
    }
    if(par, mother(indi)) {
      if(not(lookup(stab,key(par)))) {
        enqueue(ilist, par)
        enqueue(alist, add(1,mul(2,ahnen)))
        enqueue(glist, add(curgen, 1))
        insert(stab, save(key(par)), add(1,mul(2,ahnen)))
      } else {
       set(print_mom_note,key(par))
      }
    }

    /****************************************************************/
    /* now to print out info about this person */

    call longvitals(indi, 1, 2)
  
    addtoset(idex, indi, 0)
    families(indi, fam, spouse, nfam) {
      "\n\n"
      if(eq(0, nchildren(fam))) {
        call texname(inode(indi), 0) "\\ and "
        if(spouse) {
          call texname(inode(spouse), 0)
        } else {
          "\\noname"
        }
        call havehadchildren(indi, spouse)
      } elsif( and(female(indi), spouse, lookup(stab, key(spouse))) ) {
        /* note that the form of that if is different here than in
           descendant reports.  It is different because we explicitly
           form the queue by adding the father before the mother.
           Thus, for the parent-set, the children will be printed 
           under the father. We don't check to see if the father's
           spouse had them previously printed because that would
           only happen if a different (non-ancestor) wife also
           happened to be an ancestor from a different branch, which
           could happen, but has to be pretty rare.  (E.g. your
           dad's dad marries your mom's mom for the 2nd marriage for both
           of them, something like that. Ick.)
        */
        "Children of " call texname(inode(indi), 0) "\\ and "
        call texname(inode(spouse), 0) "\\ are shown under "
        call texname(inode(spouse), 0)
        "(" d(lookup(stab, key(spouse))) ").\n"
      } else {
        "Children of " call texname(inode(indi), 0) "\\ and "
        if(spouse) {
          call texname(inode(spouse), 0)
        } else {
          "\\noname"
        }
        ":\n\\begin{childrenlist}\n"
        children(fam, child, nchl) {
          set(haschild, 0)
          families(child, cfam, cspou, ncf) {
            if(ne(0, nchildren(cfam))) {
              set(haschild, 1)
            }
          }
          "\n\\item "
          if(not(lookup(stab, key(child)))) {
            call longvitals(child, 0, 1)
            addtoset(idex, child, 0)
          } else {
            call shortvitals(child)
            "  Details of " pn(child,3) " family were shown earlier "
            "({\\bf "
            d(lookup(stab, key(child))) "})" "."
          }
        }
        "\\end{childrenlist}\n"
      }
    }  /* END families loop */

    /* if his parents are not numbered as expected, tell 'em so. */
    if(ne(0,print_dad_note)) {
      "\n Note that " pn(indi,3) " father "
      "({\\bf "
      d(lookup(stab, print_dad_note)) "})"
      " is not found in the usual "
      "ahnentafel-style numbering place due to intermarriages.\n"
    }
    if(ne(0,print_mom_note)) {
      "Note that " pn(indi,3) " mother "
      "({\\bf "
      d(lookup(stab, print_mom_note)) "})"
      " is not found in the usual "
      "ahnentafel-style numbering place due to intermarriages.\n"
      "\n"
    }

    if(eq(indi,topguy)) {
      call pedigreeFigure(indi)
      if(strcmp(pedigreeFigureLabel, "")) {
        pn(indi, 2)
        " pedigree is illustrated in Figure \\protect\\ref{" 
        pedigreeFigureLabel "}."
      }
    }
  }
}

/* shortvitals(indi):  Displays the short form of the vital statistics (birth
   and death only) of an individual.
*/
proc shortvitals(indi) {
  call resetdayplace()
  call texname(inode(indi), 1)
  set(b, birth(indi))
  set(d, death(indi))

  set(local_dead,global_dead) /* save for restore */
  set(global_dead,d)

  if(and(b, long(b))) {
    call process_event(b) 
    if(and(d, long(d))) {
      " and " pn(indi,1)
      call process_event(d)
    }
  } else {    /* know death info, not birth*/
    if(and(d, long(d))) {
      call process_event(d)
    }
  }
  "."
  set(global_dead,local_dead) /* restore */
}


/* longvitals(i, name_parents, name_type)
   Prints out the complete vital statistics of the individual (i).  If
   name_parents is not 0, then the names of the parents of the individual will
   be printed.  The parameter name_type is passed to texname.  The GEDCOM tags
   are divided into ones that would likely occur before getting married and
   ones that would likely occur after getting married.  Within the two sets
   they are printed in the order in which they appear in the database.  I
   haven't yet figured out a convenient way of indicating the sex.
*/
proc longvitals(i, name_parents, name_type) {
  call resetdayplace()

  set(local_dead,global_dead) /* save for restore */
  set(global_dead,death(i))

  call texname(inode(i), name_type)  call print_sources(inode(i)) 
  call getValue(inode(i),"NAME")
  if(gotValue) {
    call print_sources(gottenNode) 
  }

  /* remember the value so it doesn't affect spousevitals */
  set(save_force_chart,force_desc_chart)
  set(force_desc_chart,0)

  set(dad, father(i))
  set(mom, mother(i))
  if(and(name_parents, or(dad, mom))) {
    ", "
    if(male(i))      { "the son of " }
    elsif(female(i)) { "the daughter of " }
    else             { "the child of " }
    if(dad)          {
      call texname(inode(dad), 0) 
      if(lookup(stab, key(dad))) {
        "({\\bf "
        d(lookup(stab, key(dad)))
        "})"
      }
    }
    if(and(dad, mom)) {
      "\nand "
    }
    if(mom) {
      call texname(inode(mom), 0) 
      if(lookup(stab, key(mom))) {
        "({\\bf "
        d(lookup(stab, key(mom)))
        "})"
      }
    }
    ",\n"
  }

  set(name_found, 0)
  set(needname,0)
  set(canUseAnd,1)
  set(printedOne,1) /* at the start, we have just printed his fullname*/
  set(pronoun," ")
  set(anythingprinted,0)
  set(putPeriod,0)
  /* there is a mistake in this for right now, if we don't have any
     pre-marriage info, it'll be ugly for the death.
  */
  fornodes(inode(i), n) {
    if(not(printedOne)) {
      if(needname) {
        set(pronoun, printablefirstname(i))
        set(needname,0)
        set(canUseAnd,1)
        set(printedOne,1)
        set(putPeriod,0)
        set(pronoun," ")
      } else {
        if(canUseAnd) {
          set(pronoun," and ")
          set(canUseAnd,0)
          set(printedOne,1)
          set(putPeriod,1)
        } else {    /* set up for "He" this time, "and" next time. */
                    /* put the period in for the first time */
          if(not(anythingprinted)) {
            set(putPeriod,1)
          } else {
            set(putPeriod,0)
          }
          set(pronoun,pn(i,0))
          set(canUseAnd,1)
          set(printedOne,1)
        }
      }
      set(anythingprinted,1)
    }/* end if not printedone */

    if(
      or(eq(strcmp(tag(n), "ADOP"), 0),
        eq(strcmp(tag(n), "BAPL"), 0),
        eq(strcmp(tag(n), "BAPM"), 0),
        eq(strcmp(tag(n), "BARM"), 0),
        eq(strcmp(tag(n), "BASM"), 0),
        eq(strcmp(tag(n), "BIRT"), 0),
        eq(strcmp(tag(n), "BLES"), 0),
        eq(strcmp(tag(n), "CONF"), 0),
        eq(strcmp(tag(n), "CONL"), 0),
        eq(strcmp(tag(n), "ORDN"), 0),
        eq(strcmp(tag(n), "CHR" ), 0)
      )) {
      pronoun set(printedOne,0) 
      call process_event(n)
      if(putPeriod) {". "}
    }
    if(eq(strcmp(tag(n), "GRAD"), 0)) {
      pronoun set(printedOne,0) 
      " graduated from "
      call valuec(n)
      call process_event(n)
      if(putPeriod) {". "}
    }

    if(eq(strcmp(tag(n), "CAST"), 0)) {
      pronoun set(printedOne,0) 
      " was a member of Caste: " call valuec(n) 
      call process_event(n)
      if(putPeriod) {". "}
    }
    if(eq(strcmp(tag(n), "NAME"), 0)) {
      if(eq(name_found, 0)) {
        set(name_found, 1)
      } else {
        pronoun set(printedOne,0) 
        " was also known as " call texname(n, 3)
        call print_notes(n, " ") 
        call print_sources(n) 
        if(putPeriod) {". "}
        "\n"
      }
    }
    if(eq(strcmp(tag(n), "NAMR"), 0)) {
      pronoun set(printedOne,0) 
      " had the religious name of: " call valuec(n)
      call process_event(n)
      if(putPeriod) {". "}
    }
    if(eq(strcmp(tag(n), "RELI"), 0)) {
      pronoun set(printedOne,0) 
      " was a " call valuec(n)
      call process_event(n)     
      if(putPeriod) {". "}
    }
/*
    if(eq(strcmp(tag(n), "TITL"), 0)) {
      pronoun set(printedOne,0) 
      " held the title of " value(n)
      call print_sources(n) 
      if(putPeriod) {". "} "\n"
    }
*/
  }  /*  END fornodes(inode(i), n)  */

  if(and(putPeriod,anythingprinted)) { ". " }
  set(inhibit_text_charts,0)
  if(eq(1, nfamilies(i))) {
    families(i, f, s, n) {
      if(s) {
        if(anythingprinted) { pn(i,0) }
        set(anythingprinted,1)
        call illegit_check(f)
        if(not_married_flag) {
          " had a child with"
        } else {
          " married"
        }
        /* it is OK to assume they had children if the
           Not married flag is raised. Cuz if they
           weren't married and didn't have kids, there
           isn't much point in the family existing
           (as far as this program is concerned).
        */
        call print_sources(fnode(f))
        call spousevitals(s, f)
      }
    }  /* END families(i, f, s, n) */

  } else {  /* individual 'i' had more than one family */
    families(i, f, s, n) {
      if(anythingprinted) {
        /* print "he" (or "she") for first marriage, and his
           first name for all later marriages
        */
        if(gt(n,1)) {
          printablefirstname(i)
        } else {
          pn(i,0)
        }      
      }
      set(anythingprinted, 1)
      if(s) {
        call illegit_check(f)
        if(not_married_flag) {
          " had child(ren) with "
        } else {
          " married "
        }
        ord(n) "," call print_sources(fnode(f))
        call spousevitals(s, f)
        /* make sure we don't print this (i) persons
           text and charts a second time. The theory here
           being that if the spouse is in the stab,
           then this person (i) has already had their
           notes/charts done as part of their spouse.
           We don't want to print a 2nd time
        */
        if(not(ancestormode)) {
          if(lookup(stab, key(s))) {
            set(inhibit_text_charts,1)
          }
        }
      } else {
        " " ord(n) " had a child with an unknown spouse.  "
      }
    }  /*  END families(i, f, s, n)  */
  }
  "  "
/*
  if(anythingprinted) {
    call getText(inode(i),0)
  }
*/
  /* otherwise hold off on getText until after the death info & all */
  /* I changed my mind. I like getText at the end. */
  set(needname,1)
  set(canUseAnd,0)
  set(putPeriod,0)
  if(anythingprinted) {
    set(printedOne,0) /* haven't printed a name here after the spouse info */
                      /* this works because pronoun is still a blank */
  } else {
    set(printedOne,1) /* we still have his name from way at the start */
    set(putPeriod,1) /* JUST ADDED THIS LINE 5/24/96. Don't know if works */
    /* test it on Galbraith kids where know only death.*/
  }

  fornodes(inode(i), n) {  /* process DEATH related gedcom nodes */
    if(not(printedOne)) {
      if(needname) {
        set(pronoun, printablefirstname(i))
        set(needname,0)
        set(canUseAnd,1)
        set(printedOne,1)
        set(putPeriod,0)
      } else {
        if(canUseAnd) {
          set(pronoun," and ")
          set(canUseAnd,0)
          set(printedOne,1)
          set(putPeriod,1)
        } else {
          set(pronoun,pn(i,0))
          set(canUseAnd,1)
          set(printedOne,1)
          set(putPeriod,0)
        }
      }
    }
    if(
      or(
        eq(strcmp(tag(n), "BURI"), 0),
        eq(strcmp(tag(n), "CREM"), 0),
        eq(strcmp(tag(n), "CENS"), 0),
        eq(strcmp(tag(n), "CHRA"), 0),
        eq(strcmp(tag(n), "DEAT"), 0),
        eq(strcmp(tag(n), "NATU"), 0),
        eq(strcmp(tag(n), "RETI"), 0),
        eq(strcmp(tag(n), "RESI"), 0),
        eq(strcmp(tag(n), "PROB"), 0),
        eq(strcmp(tag(n), "WILL"), 0)
      )) {
      pronoun set(printedOne,0) 
      call process_event(n)
      if(putPeriod) {". "}
    }

    /* One part of the GEDCOM standard says the tag should be DSCR,
       another part says DESR.
    */
    if(eq(strcmp(tag(n), "DESR"), 0)) {
      pronoun set(printedOne,0) 
      "Description: " call valuec(n)
      call print_sources(n) 
      if(putPeriod) {". "}
    }
    if(eq(strcmp(tag(n), "EVEN"), 0)) {
      pronoun set(printedOne,0) 
      value(n)
      call process_event(n)
      if(putPeriod) {". "}
    }
    if(eq(strcmp(tag(n), "OCCU"), 0)) {
      pronoun set(printedOne,0) 
      /* should also check for a RETIred node
         and always say WAS if it exists
      */
/* DAB - replace with do_occu; delete this when do_occu accepted
      call getValue(inode(i),"RETI")
      if(gotValue) { 
        " was"
      } else {
        call iswas(i)
      }
      " "
      call aAn(value(n)) " "
      call valuec(n)
      call process_event(n)
*/
      call do_occu(n, i)
      if(putPeriod) {". "}
    }
    if(eq(strcmp(tag(n), "PROP"), 0)) {
      pronoun set(printedOne,0) 
      "had possessions: " call valuec(n) "."
      call print_sources(n) 
      if(putPeriod) {". "}
    }
  }
  if(putPeriod) {". "}
  /* restore forcing of desc. charts */
  set(force_desc_chart,save_force_chart)
  if(not(inhibit_text_charts)) {
    call getText(inode(i),0)
    call process_book_notes(i)
  }
  set(global_dead,local_dead) /* restore */
}


/* isRange(d) - Indicate if a date node is a range
 * 
 * d - DATE node(could be NIL)
 *
 * Returns: 1 if <d> is of the form "[BET] date1-date2"; 0 otherwise
 *
 */
func isRange(d) {
  set(r, 0)
  if(d) {
    if(i, index(d, "-", 1)) { 
      set(r, 1)
    } elsif(i, index(d, "FROM", 1)) { 
      set(r, 1)
    }
  }
  return(r)
}


/* do_occu(n, i) - Process an OCCU node
 * 
 * n - OCCU node
 * i - INDI containing <n>
 *
 * An OCCU node will produce text saying "<name> is/was a <occu> with <agnc> ...."
 * It is assumed that the <name> was printed before this routine was called.
 * If the person is (likely) deceased, if the OCCU node has a subordinate RETI node,
 * or if the DATE tag subordinate to the OCCU node is a range, then "was" is used in
 * the sentence; otherwise, "is" is used. The "with <agnc>" clause is added if a
 * AGNC node is subordinate to the OCCU node; it is taken to be the name of the 
 * employer.
 *
 */

proc do_occu(n, i) {
  /* Check for date range or RETI node and use "was" if either present. */
  set(d, date(n))
  call getValue(inode(i), "RETI")
  if(or(gotValue, isRange(d))) {
    " was"
  } else {
    call iswas(i)
  }
  " "
  call aAn(value(n)) " "
  call valuec(n)
  call getValue(n, "AGNC")
  if(gotValue) {
    " with " gottenValue
  }
  call process_event(n)
  /*    
    if(putPeriod) {". "}
  */
}


/* spousevitals(spouse, fam)
   Prints out information about a marriage (fam) and about a spouse in the
   marriage (spouse).
*/

proc spousevitals(spouse, fam) {
  call texname(inode(spouse), 3)
  if(spouse) {
    call print_sources(inode(spouse))
    call getValue(inode(spouse),"NAME")
    if(gotValue) {
      call print_sources(gottenNode) 
    }
  }

  if(e, marriage(fam)) {
    call process_event(e) 
  }
  ". " 
  call check_print_divinfo(fam)

  if(spouse) {
    set(bir, birth(spouse))
    set(chr, baptism(spouse))
    set(dea, death(spouse))
    set(bur, burial(spouse))
    set(dad, father(spouse))
    set(mom, mother(spouse))

    set(local_dead,global_dead) /* save for restore */
    set(global_dead,dea)


    if(or(bir, chr, dea, bur, mom, dad)) {
      printablefirstname(spouse)
      if(or(mom, dad)) {
        ", "
        if(male(spouse)) {
          "the son of "
        } elsif(female(spouse)) {
          "the daughter of "
        } else {
          "the child of "
        }
        if(dad) { 
          call texname(inode(dad), 3) 
          if(lookup(stab, key(dad))) {
            "({\\bf "
            d(lookup(stab, key(dad)))
            "})"
          }
        }
        if(and(mom, dad)) {
          " and "
        }
        if(mom) {
          call texname(inode(mom), 3) 
          if(lookup(stab, key(mom))) {
            "({\\bf " d(lookup(stab, key(mom))) "})"
          }
          ", "
        }
      }

      if(or(or(or(bir, chr), dea), bur)) {
        if(bir) {
          call vitalEvent(bir,1)
          call print_sources(bir)
          if(chr) {
            " and"
            call vitalEvent(chr,0)
            call print_sources(chr)
            ". "
          }
          if(dea) {
            if(chr) {
              pn(spouse,0)
            } else {
              " and"
            }
            call vitalEvent(dea,1)
            call print_sources(dea)
            ". "
          } else {
            if(not(chr)) {
              ". "
            }
          } /* born, but nothing more */
        }
        if(and(chr, not(bir))) {
          call vitalEvent(chr,1)
          call print_sources(chr)
          ". "
        }
        if(and(dea,not(bir))) { /* if bir, then dea is already handled */
          if(chr) { /* then need to print pronoun, otherwise don't
                       since we still have the name standing there, 
                       not finishing a sentence
                    */
            pn(spouse,0) 
          } 
          call vitalEvent(dea,1)
          call print_sources(dea)
          ". "
        }
        if(bur) {
          if(or(or(bir,dea),chr)) {
            pn(spouse,0)
          }
          call vitalEvent(bur,0)
          call print_sources(bur)
          ".\n"
        }
      }
    }
    if(gt(nfamilies(spouse), 1)) {
      set(beforefam,1)
      families(spouse, newfam, newspouse, n) {
        if(ne(newfam, fam)) {
          printablefirstname(spouse)
          if(beforefam) {
            " had "
            if(gt(n, 1)) {
              "also "
            }
            "previously married "
          } else {
            " later remarried "
          }
          if(newspouse) {
            call texname(inode(newspouse), 3)
          }
          set(e,marriage(newfam))
          if(e) { call process_event(e) }
          if(gt(nchildren(newfam), 0)) {
            ", and had "
            d(nchildren(newfam))
            if(gt(nchildren(newfam), 1)) {
              " children "
            } else {
              " child"
            }
            " by that marriage: "
            children(newfam, stepchild, numerical) {
              if(gt(numerical,1)) {
                ", "
              }
              printablefirstname(stepchild)
            }       
          }
          ". "
        } else {  /* newfam = fam */
          set(beforefam,0) /* we see the current family */
        }
      }  /*  END families(spouse, newfam, newspouse, n)  */
    }  /*  END if(gt(nfamilies(spouse), 1))  */

    if(not(lookup(stab, key(spouse)))) { /* don't print a 2nd time */
      call getValue(inode(spouse),"OCCU")
      if(gotValue) {
        set(savenode,gottenNode)
        printablefirstname(spouse)
        /* should also check for a RETIred node and always say WAS if it exists */
/* DAB - replace with do_occu; delete this when do_occu is accepted
        call getValue(inode(spouse),"RETI")
        if(gotValue) {
          " was"
        } else {
          call iswas(spouse)
        }
        " "
        call aAn(value(savenode)) " "
        call valuec(savenode)
        call process_event(savenode)
        ". "
*/
        call do_occu(savenode, spouse) ". "
      }
      call getText(inode(spouse),0)
      call process_book_notes(spouse)
    }
    set(global_dead,local_dead) /* restore */
  } else {
    "\\noname" ".\n"
  }  /*  END if(spouse) block  */
}


/* texname(i, type)
   Prints an individual's name in LaTeX format, with the surname in small caps.
   For example, "David Kenneth /Olsen/ Jr." would be printed as
   "David Kenneth {\sc Olsen} Jr.".  The type argument determines how the name
   will appear in the index.
        type = 0: no index
        type = 1: page number appears in bold
        type = 2: page number appears in bold-italics
        type = 3: page number appears in normal text
   The parameter i can be either an INDI node (NOT an individual) or a
   NAME node.
*/
proc texname(i, type) {
  list(name_list)
  set(sname, "")
  extractnames(i, name_list, num_names, surname_no)
  forlist(name_list, nm, num) {
    if(eq(num, surname_no)) {
      if(eq(strcmp(nm, ""), 0)) {
        " \\noname"
        set(sname, "\\noname")
      } else {
        if(eq(strcmp(nm, "____"), 0)) {
          set(sname, "\\noname")
        } else {
          " {\\sc "
          strxlat(tex_xlat, save(nm))
          "}"
          set(sname, nm)
        }
      }
    } else {
      " " strxlat(tex_xlat, nm)
    }
  }
  if(gt(type, 0)) {
    "\\index{"
    strxlat(tex_xlat, sname)
    if(gt(num_names, 1)) {
      ","
    }
    forlist(name_list, nm, num) {
      if(ne(num, surname_no)) {
        " "
        strxlat(tex_xlat, nm)
      }
    }
    if(eq(type, 1)) {
      "|bold"
    } elsif(eq(type, 2)) {
      "|bfit"
    }
    "}"
  }
}


/* process_event(event_node, event_name)
   Prints information about a particular event (event_node, which is a GEDCOM
   node).  event_name is verb form of the text describing the event (such as
   "Born", "Died", etc.).
*/
proc process_event(event_node) {
  call vitalEvent(event_node,0)
  call print_sources(event_node)
  call print_notes(event_node, " ") 
}


proc inPlace(event) {
  if(place(event)) {
    if(eq(strcmp(place(event),""),0)) {
      " in \\noname"
    } else {
      call atAddr(event)
      if(not(strcmp(atAddrValue,""))) {
        set(fullSpecCompare,1)
      } else {
       set(fullSpecCompare,2)
      }  /* there was an ADDR. We want to 
            say at X in Y
         */
      list(placeList)
      list(placeTextList)
      list(placeTagList)
      extractplaces(event, placeList, nPlaces)
      requeue(placeList, atAddrValue)
      while(placeText, dequeue(placeList)) {
        enqueue(placeTextList, placeText)
        set(placeTag, placeText)
        forlist(placeList, place, placeN) {
          set(placeTag, save(concat(placeTag, concat("-", place))))
        }
        enqueue(placeTagList, placeTag)
      }

      set(there, getel(placeTagList, 1))
      if(not(strcmp(there, lookup(eventPlaceTable, "@there@")))) {
        "\nthere"
      } else {
        insert(eventPlaceTable, "@there@", there)
        set(fullySpecified, 0)
        forlist(placeTextList, place, placeN) {
          set(placeTag, dequeue(placeTagList))
          if(not(eq(fullySpecified,fullSpecCompare))) {
            if(eq(placeN, 2)) {
              /* if the name of the place doesn't start with "near", say "in" */
              if(and(
                strcmp(substring(place,1,4), "near"),
                strcmp(substring(place,1,2), "in"),
                strcmp(substring(place,1,5), "south"),
                strcmp(substring(place,1,5), "north"),
                strcmp(substring(place,1,4), "west"),
                strcmp(substring(place,1,4), "from"),
                strcmp(substring(place,1,4), "east"))) {
                /* note that case matters a lot in that comparison */
                /* a town might be named North English, but one should
                   always have written, "north of English" if
                   you just want to say it is outside of town
                */
                "\nin "
              } else {
                if(not(strcmp(substring(place,1,4), "from"))) {
                  " and was\n"
                  /* Actually, that isn't quite what I want because if
                     it has someone b. PLAC from there but no date, it'll wind
                     up outputting "He was born and was from there".
                     But oh well.
                  */
                } else {
                  "\n"    /* put nothing there if it says "near" */
                }
              }
            } elsif(gt(placeN, 2)) {
              ", "
            }
            place
            if(strlen(place)) {
              if(not(lookup(eventPlaceTable, placeTag))) {
                insert(eventPlaceTable, placeTag, 1)
                /* this next fiddling with fullSpecCompare is because
                   the FIRST time we see an "at ADDR in a,b,c"
                   since ADDR-a-b-c isn't in the table, it would
                   try to print "at ADDR in a,b". We just want it to 
                   print "at ADDR in a" if a,b,c was previously defined.
                */
                set(fullSpecCompare,1)
              } else {
                set(fullySpecified, add(fullySpecified,1))
              }
              if(gt(index(place,"Twp",1),0)) {
                /* then it is just the name
                   of a township, which I don't think is much
                   use without the county name, so I'm always
                   going to force it to print the county name
                   if it gives a township
                */
                set(fullSpecCompare,add(1,fullSpecCompare))
              }
            }
          }/* end if not fullySpecified */
        }
      }
    }/* matches the else for place being non-null */
  }
}

/* Possible customization I have chosen not to implement:
  Suggested by: "John F. Chandler"   <JCHBN@CUVMB.CC.COLUMBIA.EDU>
  if(gt(nPlaces,1)) { set(inWord,"at") }
   else { set(inWord,"in") }
   if(not(strcmp(tag(event),"IMMI"))) { set(inWord,"to") }
   if(not(strcmp(tag(event),"GRAD"))) {
     if(eq(nPlaces,1)) { set(inWord,"from") }
     else { set(inWord,"-") }
   }
   inWord " "
  instead of the original "in ".  This assumes that the institution is
  recorded in the PLAC
   I (DN) Think there is a little more to it than that because of the way
   I currently use atAddr, but I'm sure you can figure all that out.
   I currently assume that the institution name is the value of the
   1 GRAD line, e.g. 1 GRAD Univ. of Iowa and I handle it as a special case.
*/  


proc atAddr(root) {
  set(atAddrValue, "")
  if(root) {
    fornodes(root, node) {
      if(not(strcmp(tag(node), "PLAC"))) {
        fornodes(node, subnode) {
          if(and(not(strcmp(atAddrValue, "")),
              or(not(strcmp(tag(subnode), "ADDR")),
                 not(strcmp(tag(subnode), "CEME"))))) {
            if(val, value(subnode)) {
              set(atAddrValue, save(concat("\nat ", val)))
            }
          }
        }
      }
    }
  }
}


proc check_print_divinfo(fam) {
  call getValue(fnode(fam), "DIV")
  if(gotValue) {
    " They divorced"
    call process_event(gottenNode)
    ".  "
  }
}


/* print_notes(root, sep):  Prints all the notes (NOTE nodes) associated with
   the GEDCOM line root, separated by the given separator.
*/
proc print_notes(root, sep) {
  fornotes(root, note) {
    sep
    strxlat(tex_xlat, note)
    /* " "*/
  }
}


proc process_book_notes(indi) {
  set(hadpednote,0)
  set(haddescnote,0)
  set(doexcursion,0)

  fornotes(inode(indi), note) {
    set(i, index(note, "BOOKPEDIGREE", 1))
    if(gt(i, 0)) {
      set(hadpednote, 1)
    }
    set(i, index(note, "BOOKDESCENDENT", 1))
    if(gt(i, 0)) {
      set(haddescnote, 1)
    }
    set(i, index(note, "BOOKEXCURSION", 1))
    if(gt(i, 0)) {
      set(doexcursion, 1)
    }
    set(i, index(note, "BOOKCHAPSPLIT", 1))
    if(gt(i, 0)) {
      set(hadsplitnote, 1)
    }
  }
  if(eq(hadpednote,1)) {
    call pedigreeFigure(indi)
    if(strcmp(pedigreeFigureLabel, "")) {
      pn(indi, 2)
      " pedigree is illustrated in Figure \\protect\\ref{" 
      pedigreeFigureLabel "}."
    }
  }
  if(force_desc_chart) {
    set(haddescnote,1)
  }
  if(eq(haddescnote,1)) {
    set(descFigureLabel, save(concat(key(indi), "-figure-desc")))
    "\nA brief chart of the descendants of "
    call texname(inode(indi), 3)
     " is contained in "
    "Figure~\\ref{"   descFigureLabel   "}."
    "\n\\begin{figure*}\n"
    "\\centering\n"
    call desc_chart_main3(indi)
    "\n\\caption{Descendents of " strxlat(tex_xlat, fullname(indi,0,1,99)) "({\\bf "
    d(lookup(stab, key(indi))) "})}" nl()
    "\\label{" descFigureLabel "}"
    "\\end{figure*}\n"
  }
  if(eq(0, ancestormode)) {
    if(eq(doexcursion, 1)) {
      pn(indi, 2) " ancestors will be discussed in depth on page~\\pageref{"
      key(indi) "-excur-ref}" 
      " in this chapter.\n\n"
      enqueue(excurlist, indi)
    }
  }
}

proc pedigreeFigure(i) {
  indiset(iSet)
  addtoset(iSet, i, 1)
  set(max, 0)
  indiset(extraSet)
  set(extraSet,ancestorset(iSet))
  forindiset(extraSet, indi, val, num) {
    if(gt(val, max)) {
      set(max, val)
    }
  }
  if(gt(max, 1)) {
    set(pedigreeFigureLabel, save(concat(key(i), "-figure-pedigree")))
    if(gt(max, 5)) {
      set(max, 5)
    }
    call figPed(max, i)
  } else {
    set(pedigreeFigureLabel, "")
  }
}

proc figPed(n, indi) {
  "\n\\begin{figure*}"
  "\n\\centering"
  "\n\\small"
  "\n\\setlength{\\unitlength}{"
  if(eq(n, 5)) { ".8" } else { ".9" }
  "\n\\baselineskip}"

  call pow(2, n)
  "\n\\begin{picture}("
  d(add(mul(6, n), 12)) 
  ","
  d(sub(mul(powValue, 2), 1))
  ")(0,.5)"
  
  call ped6(indi, 0, powValue, powValue) 

  "\n\\end{picture}"
  "\n\\caption{Pedigree of " call scname(indi) "}"
  "\n\\label{" pedigreeFigureLabel "}"
  "\n\\end{figure*}" 
}

proc ped6(indi, x, y, z) {
  "\n\\put(" d(mul(x, 6)) "," d(y) "){\\makebox(0,0)[l]{"
  call scname(indi) 
  "}}"
  if(x) {
    "\n\\put(" d(sub(mul(x, 6), 3)) "," d(y) "){\\line(1,0){" d(3) "}}"
    "\n\\put(" d(sub(mul(x, 6), 3)) "," d(y) "){\\line(0,"
    if(female(indi)) { "1" } else { "-1" }
    "){" d(sub(z, 1)) ".4}}"
  }
  if(z2, div(z, 2)) {
    if(f, father(indi)) { call ped6(f, add(x, 1), add(y, z2), z2) }
    if(m, mother(indi)) { call ped6(m, add(x, 1), sub(y, z2), z2) }
  }
}

proc scname(indi) {
  strxlat(tex_xlat, fullname(indi, 0, 1, 99))
  if(lookup(stab, key(indi))) {
  "({\\bf "
  d( lookup(stab, key(indi)))
  "})"
  }
}

proc pow(x, i) {
  set(powValue, 1)
  call powIt(x, i)
}

proc powIt(x, i) { 
  if(i) {
    set(powValue, mul(powValue, x))
    call powIt(x, sub(i, 1))
  }
}


/* print_sources(root)
   Prints all sources (SOUR lines) associated with the given GEDCOM line.  The
   sources are formatted as LaTeX footnotes.  This routine prints each SOUR line
   as a separate footnote, which is not correct.  This should be corrected so
   that all sources are combined into a single footnote.
*/
proc print_sources(root) {
  enqueue(sourceList,root)
  call sourceIt(sourceList)
}


/* valuec(n):  Prints the value of a GEDCOM node and the values of any CONT
   lines associated with it.
*/
proc valuec(n) {
  value(n)
  fornodes(n, n1) {
    if(eq(strcmp(tag(n1), "CONT"), 0)) {
      "\n" value(n1)
    } elsif(eq(strcmp(tag(n1), "CONC"), 0)) {
      value(n1)
    }
  }
}


proc resetdayplace() {
  call setDayNumber(0)
  insert(eventPlaceTable, "@there@", "")
}

proc vitalEvent(event, reset) {
  if(reset) {
    call setDayNumber(0)
    insert(eventPlaceTable, "@there@", "")
  }
  if(event) {
    if(eventName, lookup(eventNameTable, tag(event))) {
      " " eventName
      if(
        or(
          not(strcmp(tag(event), "ADOP")), 
          not(strcmp(tag(event), "CHR")), 
          not(strcmp(tag(event), "CREM")), 
          not(strcmp(tag(event), "BURI"))
        )) {
        set(previousDayNumber, dayNumber)
      } else {
        set(previousDayNumber, 0)
      }
    }
    if(not(eventName)) {
      call getValue(event, "TYPE")
      if(gotValue) {
        " " strxlat(tex_xlat, gottenValue)
      }
    }
    if(not(strcmp(tag(event), "DEAT"))) {
      call ofCause(event) 
    }
    call onDate(event)
    call atAge(event)
    call inPlace(event)
  }
}


proc setDayNumber(event) {
  set(dayNumber, 0)
  if(date(event)) {
    extractdate(event, day, month, year)
    /* DAB - Have to check day month and year, otherwise two events for which
       only the year is known
       are said to have occurred on "the same day"
    */
    if(and(and(year, month), day)) {
      set(yearNumber,
        add(mul(year, 365), div(year, 4),
             neg(div(year, 100)), div(year, 400)))
      set(monthNumber, getel(daysToMonthList, month))
      set(leapYear, and(eq(mod(year, 4), 0),
        not(and(eq(mod(year, 100), 0), ne(mod(year, 400), 0)))))
      if(and(leapYear, le(month, 2))) {
        decr(monthNumber)
      }
      set(dayNumber, add(yearNumber, monthNumber, day))
    }
  }
}


/* This was the old way, replaced by the above by Jim Eggert */
/*
proc setDayNumber(event) {
  set(dayNumber, 0)
  if(date(event)) {
    extractdate(event, day, month, year)
    if(year) {
      set(yearNumber, sub(add(mul(year, 365), div(year, 4)), div(year, 400)))
      set(monthNumber, getel(daysToMonthList, month))
      set(leapYear, and(eq(mod(year, 4), 0), 
        not(and(eq(mod(year, 100), 0), ne(mod(year, 400), 0)))))
      if(and(leapYear, gt(month, 2))) {
        incr(monthNumber)
      }
      set(dayNumber, add(yearNumber, monthNumber, day))
    }
  }
}
*/


proc atAge(event) {
  call getValueCont(event, "AGE")
  if(gotValue) {
    if(not(strcmp(gottenValue, "young"))) {
      "\nyoung"
    } elsif(not(strcmp(gottenValue, "0"))) {
      "\nas an infant"
    } elsif(not(strcmp(gottenValue, "infancy"))) {
      "\nas an infant"
    } else {
      "\nat age "
      strxlat(tex_xlat, gottenValue)
    }
  }
}


proc ofCause(event) {
  call getValueCont(event, "CAUS")
  if(gotValue) {
    "\nof "
    strxlat(tex_xlat, gottenValue)
  }
}


proc onDate(event) {
  if(atmax_generation) {
    if(global_dead) {
      set(year_only,0)
    } else {
      set(year_only,1)
    }
  } else {
    set(year_only,0)  
  }
  call setDayNumber(event)
  if(d, date(event)) {
    if(strcmp(d, "Not married")) { 
      if(eq(strcmp(d, ""),0)) { "\nin \\nodate\\ " } 
      elsif(eq(index(d, "AFT", 1), 1)) { "\nsome time after " }
      elsif(eq(index(d, "Aft", 1), 1)) { "\nsome time after " }
      elsif(eq(index(d, "BEF", 1), 1)) { "\nsome time before " }
      elsif(eq(index(d, "Bef", 1), 1)) { "\nsome time before " }
      elsif(eq(index(d, "ABT", 1), 1)) { "\ncirca " }
      elsif(eq(index(d, "Abt", 1), 1)) { "\ncirca " }
      elsif(eq(index(d, "FROM", 1), 1)) { 
        set(t, index(d, "TO", 1))
/*
DAB - experimental (and not working) 
        set(fromDateEvent, createnode("EVEN", ""))
        set(fromDateNode, createnode("DATE", substring(d, add(1, strlen("FROM")), sub(t, 1)) ))
        addnode(fromDateNode, fromDateEvent, 0)
        set(toDateEvent, createnode("EVEN", ""))
        set(toDateNode, createnode("DATE", substring(d, add(t, strlen("TO")), strlen(d)) ))
        addnode(toDateNode, toDateEvent, 0)
DEBUG:
        "\n from date nodes: "
        traverse(fromDateEvent, xx, yy) {
          d(yy) ": " tag(xx) " " value(xx)
        }
        "\n to date nodes: "
        traverse(toDateEvent, xx, yy) {
          d(yy) ": " tag(xx) " " value(xx)
        }

        "\nfrom " stddate(fromDateEvent)
        " to " stddate(toDateEvent)
        deletenode(toDateNode)
        deletenode(toDateEvent)
        deletenode(fromDateNode)
        deletenode(fromDateEvent)
DAB - end of experimental
*/

/* DAB - This way work, but doesn't necessarily produce dates in the same
         format as stddate
*/
        "\nfrom " substring(d, add(1, strlen("FROM")), sub(t, 1)) 
        " to " substring(d, add(t, strlen("TO")), strlen(d)) 
        set(event, 0)
      } elsif(i, index(d, "-", 1)) { 
        "\nbetween " substring(d, 1, sub(i, 1)) 
        " and " substring(d, add(i, 1), strlen(d)) 
        set(event, 0)
      } elsif(and(dayNumber, eq(dayNumber, previousDayNumber))) {
        "\non the same day"
        set(event, 0)
      } elsif(and(dayNumber, eq(dayNumber, add(previousDayNumber, 1)))) {
        "\non the next day"
        set(event, 0)
      } elsif(and(dayNumber, eq(dayNumber, add(previousDayNumber, 2)))) {
        "\ntwo days later"
        set(event, 0)
      } elsif(and(dayNumber, eq(dayNumber, add(previousDayNumber, 7)))) {
       "\none week later"
        set(event, 0)
      } else {
        if(year_only) { "\nin "
        } else {
          extractdate(event, d, m, y)
          if(d) { "\non " } else { "\nin " }
        }
      }
      if(event) { 
        if(and(dayNumber, eq(dayNumber, previousDayNumber))) {
          "that day"
        } else {
          if(year_only) {
            year(event) 
          } else {
            stddate(event) 
          }
        }
      }
    }
  }
}

proc getValue(root, t) {
  set(gotValue, 0)
  if(root) {
    fornodes(root, node) {
      if(and(not(gotValue), not(strcmp(tag(node), t)))) {
        set(gotValue, 1)
        set(gottenNode, node)
        set(gottenValue, save(value(node)))
      }
    }
  }
}


proc getValueCont(root, t) {
  set(gotValue, 0)
  if(root) {
    fornodes(root, node) {
      if(and(not(gotValue), not(strcmp(tag(node), t)))) {
        set(gotValue, 1)
        set(gottenNode, node)
        set(gottenValue, save(value(node)))
        fornodes(node, subnode) {
          if(not(strcmp("CONT", tag(subnode)))) {
            /* If you want empty CONT tags to not leave a blank line, uncomment the following "if".
             * However, a blank line can be very useful (or even necessary) for some TeX formatting.
             */
            /*if(strlen(value(subnode))) {*/
              set(gottenValue, 
                save(concat(gottenValue, "\n", value(subnode))))
            /*}*/
          } elsif(not(strcmp("CONC", tag(subnode)))) {
            /* Same comment as above, this time for CONC tags */
            /*if(strlen(value(subnode))) {*/
              set(gottenValue, 
              save(concat(gottenValue, value(subnode))))
            /*}*/
          }
        }
      }
    }
  }
}


proc getValueCommaCont(root, t) {
  set(gotValue, 0)
  if(root) {
    fornodes(root, node) {
      if(and(not(gotValue), not(strcmp(tag(node), t)))) {
        set(gotValue, 1)
        set(gottenNode, node)
        set(gottenValue, save(value(node)))
        fornodes(node, subnode) {
          if(not(strcmp("CONT", tag(subnode)))) {
            if(strlen(value(subnode))) {
              set(gottenValue, 
                save(concat(gottenValue, ",\n", value(subnode))))
            }
          } elsif(not(strcmp("CONC", tag(subnode)))) {
            if(strlen(value(subnode))) {
              set(gottenValue, 
              save(concat(gottenValue, value(subnode))))
            }
          }
        }
      }
    }
  }
}


proc aAn(s) {
  set(s, save(trim(lower(s), 1)))
  if(not(strcmp(s, "a"))) { "an" }
  elsif(not(strcmp(s, "e"))) { "an" }
  elsif(not(strcmp(s, "i"))) { "an" }
  elsif(not(strcmp(s, "o"))) { "an" }
  elsif(not(strcmp(s, "u"))) { "an" }
  elsif(not(strcmp(s, "x"))) { "an" }
  else { "a" }
}


func printablefirstname(i) {
   set(firstname, givens(i))
   if(eq(strcmp(firstname, ""), 0)) {
      set(namereturn, save("\\noname"))
   } else {
      set(where, index(firstname, " ", 1))
      /* don't print out middle names */
      if(gt(where, 0)) {
         set(namereturn, save(substring(firstname, 1, sub(where, 1))))
      } else {
         set(namereturn, save(firstname))
      } /* if no middle names */
      set(namereturn, strxlat(tex_xlat, namereturn))
   }
   return(namereturn)
}

proc iswas(indi) {
  call setDayNumber(birth(indi))
  if(or(death(indi), or(not(dayNumber), lt(dayNumber, 693971)))) {
    "\nwas" 
  } else {
    "\nis"
  }
}


/* Check to see if this family might still have children at some point:
   If one spouse is dead, too old, or they are divorced; then they won't.
*/
proc havehadchildren(indi, spouse) {
  call setDayNumber(birth(indi))
  set(indiDayNumber, dayNumber)
  call setDayNumber(birth(spouse))
  set(divp, 0)
  spouses(indi, s, f, n) {
    if(eq(s, spouse)) {
      call getValue(fnode(f), "DIV")
      set(divp, gotValue)
      break()
    }
  }
  if(
    or(
      death(indi),
      or(not(indiDayNumber), lt(indiDayNumber, 693971)), death(spouse),
      or(not(dayNumber), lt(dayNumber, 693971)),
      divp
    )) {
    "\\ had no children.\n"
  } else {
    "\\ have no children.\n"
  }
}
 
/* illegit_check gives people a break.  If we have no marriage record,
   the assumption still is that the couple were married and that
   is the word we stick in the text.
   Only if it specifically says they were not married, do we
   state that they weren't
*/
proc illegit_check(fam) {
  set(not_married_flag, 0)
  if(e,marriage(fam)) { 
    if(d, date(e)) {  
      if(not(strcmp(d, "Not married"))) {
        set(not_married_flag, 1)
      }
    }
  }
}


proc sourceIt(sourceList) {
  list(cList)
  list(fList)
  set(cn, 0)
  while(root, dequeue(sourceList)) {
    fornodes(root, node) {
      if(not(strcmp( tag(node), "SOUR"))) {
        set(footnote, 1)
        set(val, value(node))
        if(val) {
          if(reference(val)) {
            call bibliographize(dereference(val))
          }
        }
        if(xref(node)) {
          call bibliographize(node)
          set(val, xref(node))
        }
        if(val) {
          set(a1, index(val, "@", 1))
          set(a2, index(val, "@", 2))
          if(and(eq(a1, 1), eq(a2, strlen(val)))) { 
            set(c, save(substring(val, 2, sub(strlen(val), 1))))
            enqueue(cList, c)
            incr(cn)
            set(footnote, 0)
          }
        } else {
          set(subnodecount, 0)
          fornodes(node, subnode) {
            if(strcmp(tag(subnode), "SOUR")) {
              incr(subnodecount)
            }
          }
          if(eq(subnodecount, 0)) {
            fornodes(node, subnode) {
              set(val, value(subnode))
              /* With loadsources, this is needed here. It is technically
                 illegal gedcom.
              */
              if(xref(subnode)) {
                call bibliographize(subnode)
                set(val, xref(subnode))
              }
              if(val) {
                set(a1, index(val, "@", 1))
                set(a2, index(val, "@", 2))
                if(and(eq(a1, 1), eq(a2, strlen(val)))) { 
                  set(c, save(substring(val, 2, sub(strlen(val), 1))))
                  enqueue(cList, c)
                  incr(cn)
                }
              } 
            }
            set(footnote, 0)
          }
        }
        if(footnote) {
          enqueue(fList, node)
        }
      }
    }
  }
  while(cn) {
    forlist(cList, c, n) {
      if(and(ne(n, cn), not(strcmp(c, getel(cList, cn))))) {
        setel(cList, cn, "")
      }
    }
    decr(cn)
  }
  if(not(empty(fList))) {
    "\n\\footnote{" 
    while(f, dequeue(fList)) { 
      set(first, 1)
      call getValueCont(f, "TITL") 
      if(gotValue) { 
        if(not(first)) { ", " } else { set(first, 0) }
        "\n"
        strxlat(tex_xlat, gottenValue)
      }
      call getValueCont(f, "DATE") 
      if(gotValue) { 
        if(not(first)) { ", " } else { set(first, 0) }
        "\n"
        strxlat(tex_xlat, gottenValue)
      }
      call getValueCont(f, "PLAC") 
      if(gotValue) { 
        if(not(first)) { ", " } else { set(first, 0) }
        "\n"
        strxlat(tex_xlat, gottenValue)
      }
      call getValueCont(f, "VOLU") 
      if(gotValue) { 
        if(not(first)) { ", " } else { set(first, 0) }
        if(
          or(index(gottenValue, "-", 1),
            index(gottenValue, ",", 1),
            index(gottenValue, "and ", 1)
          )) {
          "\nVolumes "
        } else {
          "\nVolume "
        }
        strxlat(tex_xlat, gottenValue)
      }
      call getValueCont(f, "PAGE") 
      if(gotValue) { 
        if(not(first)) { ", " } else { set(first, 0) }
        if(
          or(index(gottenValue, "-", 1),
            index(gottenValue, ",", 1),
            index(gottenValue, "and ", 1)
          )) {
          "\nPages "
        } else {
          "\nPage "
        }
        strxlat(tex_xlat, gottenValue)
      }
      call getValueCont(f, "FILM") 
      if(gotValue) { 
        if(not(first)) { ", " } else { set(first, 0) }
        "on Latter Day Saints Microfilm Number " 
        strxlat(tex_xlat, gottenValue)
      }

      call getValueCont(f, "TEXT") 
      if(gotValue) { 
        set(first, 0)
        "\n"
        strxlat(tex_xlat, gottenValue)
      }
      if(not(first)) { "\\@." }
      call getValueCont(f, "NOTE") 
      if(gotValue) { 
        set(first, 0)
        "\n"
        strxlat(tex_xlat, gottenValue)
      }
      if(and(first, not(value(f)))) { "\n" }
      call values(f)
    }
    "}"
  }
  if(not(empty(cList))) {
    "\\cite{"
    while(c, dequeue(cList)) {
      if(strlen(c)) {
        if(cn) { "," }
        c
        incr(cn)
      }
    }
    "}"
  }
}

proc bibliographize(root) {
  set(val, xref(root))
  set(c, save(substring(val, 2, sub(strlen(val), 1))))

  if(not(lookup(bibTable, c))) {
    insert(bibTable, c, 1)

/*  
    call getValueCont(root, "TEXT")
    if(figureFlag, gotValue) {
      enqueue(figureCiteList, c)
      enqueue(figureNodeList, gottenNode)
    }
*/
    set(cref, save(concat("\\protect\\ref{", c, "}")))
    set(pref, save(concat("\\protect\\pageref{", c, "}")))

    set(b, "\\bibitem")
    if(figureFlag) {
      set(b, save(concat(b, "[", cref, "]")))
    }
    set(b, save(concat(b, "{", c, "} ")))
    call getValueCont(root, "TITL") 
    if(gotValue) { 
      set(b, save(concat(b, "{\\em ", strxlat(tex_xlat, gottenValue), "}, ")))
    }
    call getValueCont(root, "AUTH") 
    if(gotValue) { 
      set(b, save(concat(b, " ", strxlat(tex_xlat, gottenValue), ", ")))
      set(authnode, gottenNode)
      call getValueCont(authnode, "EMAI")
      if(gotValue) {
        if(opt_email) {
          set(b, save(concat(b, strxlat(tex_xlat, gottenValue), ", ")))
        } else {
          set(b, save(concat(b, "e-mail address on file, ")))
        }
      }
    }
    call getValueCont(root, "PUBL") 
    if(gotValue) { 
      set(pubnode,gottenNode)
      call getValueCont(pubnode, "NAME") 
      if(gotValue) { 
        set(b, save(
          concat(b, "in {\\em ", strxlat(tex_xlat, gottenValue), "}, ")))
      }
      call getValueCommaCont(pubnode, "ADDR") 
      if(gotValue) {
        set(b, save(
          concat(b, strxlat(tex_xlat, gottenValue), ": ")))
        }
      call getValueCont(pubnode, "PUBR") 
      if(gotValue) {
        set(b, save(
          concat(b, strxlat(tex_xlat, gottenValue), ", ")))
      }
      call getValueCont(pubnode, "PHON") 
      if(gotValue) {
        set(b, save(concat(b, strxlat(tex_xlat, gottenValue), ", ")))
      }
      call getValueCont(pubnode, "DATE") 
      if(gotValue) {
        set(b, save(
          concat(b, strxlat(tex_xlat, gottenValue), ", ")))
      }
      call getValueCont(pubnode, "VOLU") 
      if(gotValue) { 
        set(word, "Volume ")
        if(
          or(index(gottenValue, "-", 1),
            index(gottenValue, ",", 1),
            index(gottenValue, "and ", 1)
          )) {
          set(word, "Volumes ")
        }
        set(b, save(concat(b, word, strxlat(tex_xlat, gottenValue), ", ")))
      }
      call getValueCont(pubnode, "NUM") 
      if(gotValue) { 
        set(word, "Number ")
        if(
          or(index(gottenValue, "-", 1),
            index(gottenValue, ",", 1),
            index(gottenValue, "and ", 1)
          )) {
          set(word, "Numbers ")
        }
        set(b, save(concat(b, word, strxlat(tex_xlat, gottenValue), ", ")))
      }
      call getValueCont(root, "LCCN") 
      if(gotValue) { 
        set(b, save(
          concat(b, "Call Number ", strxlat(tex_xlat, gottenValue), ", ")))
      }
    }
    call getValueCont(root, "PAGE") 
    if(gotValue) { 
      set(word, "page ")
      if(
        or(index(gottenValue, "-", 1),
          index(gottenValue, ",", 1),
          index(gottenValue, "and ", 1)
        )) {
        set(word, "pages ")
      }
      set(b, save(concat(b, word, strxlat(tex_xlat, gottenValue), ", ")))
    }
    call getValueCont(root, "FILM") 
    if(gotValue) { 
      set(b, save(concat(b, 
         "Filmed by the Church of Jesus Christ of Latter Day Saints, ",
         "Microfilm Number ", 
         strxlat(tex_xlat, gottenValue), ", "))) 
    }
    call getValueCont(root, "FICH") 
    if(gotValue) { 
      set(b, save(concat(b, 
         "Filmed by the Church of Jesus Christ of Latter Day Saints, ",
         "Microfiche Number ", 
         strxlat(tex_xlat, gottenValue), ", "))) 
    }
    call getValueCont(root, "REPO") 
    if(gotValue) { 
      set(b, save(concat(b, "at ", strxlat(tex_xlat, gottenValue), ", ")))
    }

    if(index(b, ", ", 1)) {
      set(b, save(concat(save(substring(b, 1, sub(strlen(b), 2))), ".")))
    }
  
    call getValueCont(root, "NOTE") 
    if(gotValue) { set(b, save(concat(b, " ", strxlat(tex_xlat, gottenValue)))) }

    call getValueCont(root, "TEXT") 
    if(gotValue) { set(b, save(concat(b, " ", strxlat(tex_xlat, gottenValue)))) }
  
    call getValueCont(root, "HIDE") 
    if(gotValue) { set(b, save(concat(b, " ", strxlat(tex_xlat, gottenValue)))) }
  
    call getValueCont(root, "SOUR") 
    if(gotValue) { 
      set(bb, "?")
      if(gottenValue) {
        set(a1, index(gottenValue, "@", 1))
        set(a2, index(gottenValue, "@", 2))
        if(and(eq(a1, 1), eq(a2, strlen(gottenValue)))) { 
          set(bb, save(substring(gottenValue, 2, sub(strlen(gottenValue), 1))))
        }
      }
      set(b, save(concat(b, "\\cite{", strxlat(tex_xlat, bb), "}")))
    }
  
    if(figureFlag) {
      set(b, save(concat(b, " See figure on page~", pref, ".")))
    }
  
    /* This while loop undoes the line breaking in a CONT/CONC.
       Since those line breaks can be
       significant, it is commented out.
    */
/*
    while(i, index(b, "\n", 1)) {
      set(b, save(
        concat(
          substring(b, 1, sub(i, 1)),
          " ", 
          substring(b, add(i, 1), strlen(b))
        ) ))
    }
*/
    enqueue(bibList, save(concat(b, "\n")))
  }
}


proc getText(root, paragraph) {
  set(pronounOkay, 1)
  if(root) {
    if(eq(1,notes_text_mode)) {   /* only 1 TEXT records */
      fornodes(root, node) {
        if(not(strcmp("TEXT", tag(node)))) {
          set(pronounOkay, 0)
          if(paragraph) {
            "\n\n" set(paragraph, 0)
          }
          call values(node)
          "\n\n"
        }
      }
    } else {
      if(eq(2,notes_text_mode)) { /* all 1 NOTE records */
        fornotes(root, note) {
          if(paragraph) {
            "\n\n" set(paragraph, 0)
          }
          strxlat(tex_xlat, note)
          "\n\n"
          set(pronounOkay, 0)
        }
      } else {   /* only !-tagged 1 NOTE records (1st char must be !) */
        fornotes(root, note) {
          set(i, index(note,"!",1))
          if(eq(1,i)) {
            set(pronounOkay, 0)
            if(paragraph) {
              "\n\n" set(paragraph, 0)
            }
            strxlat(tex_xlat, substring(note, 2, strlen(note)))
            "\n\n"
          }
        }
      }
    }
  }
  /* if we printed any notes, then reset things so we don't use
     "there" in place names right after the notes.
  */
  if(not(pronounOkay)) {
    insert(eventPlaceTable, "@there@", "")
  }
}

proc values(root) {
  if(root) {
    if(strlen(value(root))) { "\n" strxlat(tex_xlat, value(root)) }
    fornodes(root, node) {
      if(not(strcmp("CONT", tag(node)))) {
        if(strlen(value(node))) {
          "\n" strxlat(tex_xlat, value(node))
        }
      } elsif(not(strcmp("CONC", tag(node)))) {
        if(strlen(value(node))) {
          strxlat(tex_xlat, value(node))
        }
      }
    }
    if(root) {
      enqueue(sourceList, root)
    }
    call sourceIt(sourceList)
  }
}


/********************************************************************/
/* below here are routines for printing descendant charts */
/* 
 * These are adapted from desc-tex
 * By Eric Majani (eric@elroy.jpl.nasa.gov)
 */

proc desc_chart_main3(indi) {
  "\\tree\n"
  call desc_chart_out(indi,3,1)
  "\\endtree\n"
}


proc descch_indi(indi) {
  "{\\bf " call desc_chart_name(indi) "}"
  if(or(birth(indi),death(indi))) {
    " "
    if(e, birth(indi)) {
      year(e)
    }
    "-"
    if(e, death(indi)) {
      year(e)
    }  
  }
  nl()
  families(indi,fam,sp,num) {
    if(e,marriage(fam)) {
      "   m. " short(e)  nl()
    } 
  }
}


proc desc_chart_name(i) {
  set(whole, givens(i))
  set(space,index(whole, " ", 1))
  if(gt(space, 0)) {
     strxlat(tex_xlat, substring(whole, 1, space))
  } else {
    strxlat(tex_xlat, whole) " "
  }
  if(eq(strcmp(surname(i), "____"), 0)) {
    " \\noname" 
  } else {
    strxlat(tex_xlat, surname(i))
  } 
}


proc descch_indinomar(indi) {
  "{\\bf " call desc_chart_name(indi) "}"
  if(or(birth(indi),death(indi))) {
    " "
    if(e, birth(indi)) {
      year(e)
    }
    "-"
    if(e, death(indi)) {
      year(e)
    }  
  }
  nl()
}


proc descch_prcouple(indi,fam,num) {
  if(eq(num,1)) {
    "{\\bf "
    call desc_chart_name(indi)
    "}" 
    if(e, birth(indi)) {
      " " year(e)"-"
    }
    if(e, death(indi)) {
      if(not(birth(indi))) {
        " -"
      }
      year(e)  
    }
  }
  nl()

/* I can't remember why I put this IF in here. I guess I'll take it out
   and see what breaks!
*/
/*
  if(eq(num,nfamilies(indi))) {
*/ 
    if(e,marriage(fam)) {
      " m. " year(e) " "
    } else {
      "m.\\ \\ \\ \\ \\ \\ "
    } /* space over without date */
  /*}*/
}


proc descch_printfam(indi,fam,sp) {
  "\\spouse{ " call desc_chart_name(sp) "}" nl()
}


proc desc_chart_out(indi,depth,level) {
  if(or(eq(0,nfamilies(indi)),eq(depth,level))) {
    call descch_indinomar(indi)
  }
  if(lt(level,depth)) {
    families(indi,fam,sp,num) {         
      call descch_prcouple(indi,fam,num)
      call descch_printfam(indi,fam,sp)
      set(level,add(level,1))
      set(num2,0)
      if(le(level,depth)) {
        children(fam,child,num2) {
          "\\subtree " nl()
          call desc_chart_out(child,depth,level)
          "\\endsubtree " nl()
        }
      }
      set(num2,nchildren(fam))
      set(level,sub(level,1))
      set(temp1,ne(num,nfamilies(indi)))
      set(temp2,gt(num2,0))
      if(and(temp1,temp2))
/*
      if(ne(num,nfamilies(indi)))
*/
      {
        if(eq(level,1)) {
          "\\endtree " nl()
          "\\tree " nl()
        } else {
          "\\endsubtree " nl()
           "\\subtree "  nl()
        }
      }
    }
  }
}

proc excursion(indi) {
  list(anclist)
  indiset(ancset)
  
  "\n\\section{"  strxlat(tex_xlat, surname(indi)) " Ancestors" "}" "\n"
  "\\label{" key(indi) "-excur-ref}" "\n"

  /* get us to the patriarch of the line.*/
  set(thisguy,indi)
  addtoset(ancset,thisguy,0)
  while(father(thisguy)) {
    set(thisguy,father(thisguy))
    push(anclist,thisguy)
    addtoset(ancset,thisguy,0)
  }
  "The " strxlat(tex_xlat, surname(indi)) " line has been traced back to "
  call texname(inode(thisguy), 0) "."

  while(indi,pop(anclist)) {
    print("Excursion: ") print(name(indi)) print("\n")
    call longvitals(indi,1,2)
      families(indi, fam, spouse, nfam) {
        "\n\n"
        if(eq(0, nchildren(fam))) {
          call texname(inode(indi), 0) "\\ and "
          if(spouse) {
            call texname(inode(spouse), 0)
          } else {
            "\\noname"
          }
          call havehadchildren(indi, spouse)
        } elsif(and(spouse, lookup(stab, key(spouse)))) {
          "Children of " call texname(inode(indi), 0) "\\ and "
          call texname(inode(spouse), 0) "\\ are shown under "
          call texname(inode(spouse), 0)
          "(" d(lookup(stab, key(spouse))) ").\n\n"
        } else {
          "Children of " call texname(inode(indi), 0) "\\ and "
          if(spouse) {
            call texname(inode(spouse), 0)
          } else {
            "\\noname"
          }
          ":\n\\begin{childrenlist}\n"
          children(fam, child, nchl) {
          "\n\\item "
          set(personIsAnc,0)
          forindiset(ancset,them,val,num) {
            if(eq(them, child)) {
              set(personIsAnc,1)
            }
          }
          if(personIsAnc) {
            "**" call shortvitals(child)
          } else {
            call longvitals(child, 0,2)
          }
          addtoset(idex, child, 0)
        }
        "\\end{childrenlist}\n"
      }
    }
  }
  "\n\n\n"
}

/*
**  function: strxlat
**
**  This idea was copied and/or adapted from Jim Eggert's modification
**  to the ps-circ(le) program for LifeLines.
**  A typical call would look like:
**      set(str, strxlat(tex_xlat, name(person)))
**  which would translate characters in person's name according to the
**  table called tex_xlat -- which escapes the special characters being
**  displayed as text via LaTeX.  The output is assigned to str.
**  The output of strxlat() can also be sent directly to output.
**
*/

func strxlat(xlat, string) {
  if(opt_xlat) {
    set(fixstring, "")
    set(pos, 1)
    while(le(pos, strlen(string))) {
      set(char, substring(string, pos, pos))
      if(special, lookup(xlat, char)) {
        set(fixstring, concat(fixstring, special))
      } else {
        set(fixstring, concat(fixstring, char))
      }
      incr(pos)
    }
  } else {
    set(fixstring, string)
  }
  return(save(fixstring))  /* save() is used for compatibilty with older LL */
}