aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/texpdf.org
blob: bd92b270b16502ae2e9856f6b84c6bb8d5bd6fe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
-*- mode: org -*-
#+TITLE:       sisu tex pdf
#+DESCRIPTION: documents - structuring, various output representations & search
#+FILETAGS:    :sisu:texpdf:
#+AUTHOR:      Ralph Amissah
#+EMAIL:       [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]]
#+COPYRIGHT:   Copyright (C) 2015 - 2021 Ralph Amissah
#+LANGUAGE:    en
#+STARTUP:     content hideblocks hidestars noindent entitiespretty
#+OPTIONS:     H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t
#+PROPERTY:    header-args  :exports code
#+PROPERTY:    header-args+ :noweb yes
#+PROPERTY:    header-args+ :eval no
#+PROPERTY:    header-args+ :results no
#+PROPERTY:    header-args+ :cache no
#+PROPERTY:    header-args+ :padline no
#+PROPERTY:    header-args+ :mkdirp yes

* texpdf
** texpdf.rb

#+HEADER: :tangle "../lib/sisu/texpdf.rb"
#+BEGIN_SRC ruby
#<<sisu_document_header>>
module SiSU_TeX
  begin
    require 'pstore'
  rescue LoadError
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      error('pstore NOT FOUND (LoadError)')
  end
  require_relative 'texpdf_parts'                        # texpdf_parts.rb
  require_relative 'se_hub_particulars'                 # se_hub_particulars.rb
    include SiSU_Particulars
  require_relative 'texpdf_format'                      # texpdf_format.rb
    include SiSU_TeX_Pdf
  require_relative 'shared_metadata'                    # shared_metadata.rb
  require_relative 'prog_text_translation'              # prog_text_translation.rb
  @tex_file=@@tex_footnote_array=@@tex_col_w=[]
  @@tabular="{tabular}"
  @@column_instruct=@@squigle_close=@@tex_line_mode=@@tex_word_mode=@@line_mode=''
  @@tex_debug_counter=@@table_pagebreak_counter=@@tex_footnote_call_counter=@@tex_table_flag=@@tex_counter=@@tex_column=@@tex_columns=@@tex_columns=@@counting=0
  @@tex_pattern_margin_number=/\\\\ocn\\\{[0-9]+\\\}/
  @@n=@@tableheader=@@rights=nil
  @@date ||=SiSU_Env::InfoDate.new
  class Source
    begin
      require 'pstore'
    rescue LoadError
      SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
        error('pstore NOT FOUND (LoadError)')
    end
    require_relative 'se'                               # se.rb
      include SiSU_Env
    require_relative 'ao'                               # ao.rb
      include SiSU_AO
    include SiSU_TeX
    def initialize(opt)
      @opt=opt
      @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
      @md=@particulars.md
      @env=SiSU_Env::InfoEnv.new(@md.fns) #@env=@particulars.env
    end
    def directories
      begin
        case @opt.fns
        when /\.(?:-|ssm\.)?sst$/
          SiSU_Env::FileOp.new(@md).mkdir
          Dir.mkdir(@env.processing_path.tex) unless FileTest.directory?(@env.processing_path.tex)
        end
      rescue
        SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
          __LINE__.to_s + ':' + __FILE__
        end
      ensure
      end
    end
    def read
      begin
        song
      ensure
        Dir.chdir(@opt.f_pth[:pth])
      end
    end
    def song
      begin
        @md=@particulars.md
        SiSU_Screen::Ansi.new(
          @opt.act[:color_state][:set],
          'LaTeX/PDF',
          "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}"
        ).green_title_hi unless @opt.act[:quiet][:set]==:on
        if (@opt.act[:verbose][:set]==:on \
        || @opt.act[:verbose_plus][:set]==:on \
        || @opt.act[:maintenance][:set]==:on)
          @env.url.output_tell
          if @md.opt.act[:pdf_l][:set]==:on
            SiSU_Screen::Ansi.new(
              @opt.act[:color_state][:set],
              @opt.fns,
              "#{@env.program.pdf_viewer} #{@md.file.output_path.pdf.dir}/#{@md.file.base_filename.pdf_l}#{@md.papersize_array[0]}.pdf"
            ).flow
          end
          if @md.opt.act[:pdf_p][:set]==:on
            SiSU_Screen::Ansi.new(
              @opt.act[:color_state][:set],
              @opt.fns,
              "#{@opt.fns} #{@env.program.pdf_viewer} #{@md.file.output_path.pdf.dir}/#{@md.file.base_filename.pdf_p}#{@md.papersize_array[0]}.pdf"
            ).flow
          end
        end
        @md=@particulars.md
        $flag=@md.opt.selections.str                                                          #introduced to pass 0 for no object citation numbers... to texpdf_format
        directories
                                                                               #% needed needs to be reprogrammed !!!
        ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here
        SiSU_TeX::Source::LaTeXcreate.new(@particulars).songsheet
        ao_array=''
        pwd=Dir.pwd
        SiSU_TeX::Source::LaTeXtoPdf.new(@md,@particulars.env).latexrun_selective
        Dir.chdir(pwd)
      rescue
        SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
          __LINE__.to_s + ':' + __FILE__
        end
      ensure
        unless (@opt.act[:verbose_plus][:set]==:on \
        || @opt.act[:maintenance][:set]==:on)
          texfiles=Dir["#{@env.processing_path.tex}/#{@opt.fns}*"]
          texfiles.each do |f|
            if FileTest.file?(f)
              File.unlink(f)
            end
          end
        end
        @tex_file=@@tex_footnote_array=[]
        @@column_instruct=''
        @@squigle_close=@@tex_line_mode=@@tex_word_mode=@@line_mode=''
        @@tex_debug_counter=@@table_pagebreak_counter=@@tex_footnote_call_counter=@@tex_table_flag=@@tex_counter=@@tex_column=@@tex_columns=@@tex_columns=@@counting=0
        @@tex_col_w=[]
        @@n=@@tableheader=@@rights=nil
        @@date=SiSU_Env::InfoDate.new
        @@flag={}
        $flag=1 #remove at some stage
        SiSU_Env::Clear.new(@opt.selections.str,@opt.fns).param_instantiate
      end
    end
    private
    class LaTeXtoPdf
      @@n_lpdf||=0 #change
      def initialize(md,env)
        @md,@env=md,env
        @f=SiSU_Env::FileOp.new(@md).base_filename
      end
      def latex_do(texfilename,papersize)
        @texfilename=texfilename
        @@n_lpdf=@@n_lpdf+1
        tex_fn_base=@texfilename.gsub(/\.tex$/,'')
        tell=SiSU_Screen::Ansi.new(@md.opt.selections.str)
        if @md.opt.act[:pdf_p][:set]==:on
          if (@md.opt.act[:verbose][:set]==:on \
          || @md.opt.act[:verbose_plus][:set]==:on \
          || @md.opt.act[:maintenance][:set]==:on)
            SiSU_Screen::Ansi.new(
              @md.opt.act[:color_state][:set],
              "#{papersize} portrait ->"
            ).dark_grey_title_hi
          end
          cmd=SiSU_Env::SystemCall.new("#{tex_fn_base}.tex",'',@md.opt.selections.str)
          if @md.opt.act[:verbose][:set]==:on \
          || @md.opt.act[:verbose_plus][:set]==:on \
          || @md.opt.act[:maintenance][:set]==:on
            tell.grey_open
          end
          if "#{tex_fn_base}" =~/\w+/ \
          and "#{papersize}" =~/\w+/
            2.times { |i| cmd.latex2pdf(@md,papersize) } #comment out to skip processing of latex portrait
          end
          if @md.opt.act[:verbose][:set]==:on \
          || @md.opt.act[:verbose_plus][:set]==:on \
          || @md.opt.act[:maintenance][:set]==:on
            tell.p_off
          end
        end
        if @md.opt.act[:pdf_l][:set]==:on
          if (@md.opt.act[:verbose][:set]==:on \
          || @md.opt.act[:verbose_plus][:set]==:on \
          || @md.opt.act[:maintenance][:set]==:on)
            SiSU_Screen::Ansi.new(
              @md.opt.act[:color_state][:set],
              "#{papersize} landscape ->"
            ).dark_grey_title_hi
          end
          cmd=SiSU_Env::SystemCall.new("#{tex_fn_base}.landscape.tex",'',@md.opt.selections.str)
          if (@md.opt.act[:verbose][:set]==:on \
          || @md.opt.act[:verbose_plus][:set]==:on \
          || @md.opt.act[:maintenance][:set]==:on)
            tell.grey_open
          end
          if "#{tex_fn_base}" =~/\w+/ \
          and "#{papersize}" =~/\w+/
            2.times { |i| cmd.latex2pdf(@md,papersize) } #comment out to skip processing of latex landscape
          end
          if (@md.opt.act[:verbose][:set]==:on \
          || @md.opt.act[:verbose_plus][:set]==:on \
          || @md.opt.act[:maintenance][:set]==:on)
            tell.p_off
          end
        end
        pwd=Dir.pwd
        if @md.opt.act[:pdf_p][:set]==:on
          portrait_pdf="#{pwd}/#{tex_fn_base}.pdf"
        end
        if @md.opt.act[:pdf_l][:set]==:on
          landscape_pdf="#{pwd}/#{tex_fn_base}.landscape.pdf"
        end
        case papersize
        when /a4/     then pdf_p=@f.pdf_p_a4;     pdf_l=@f.pdf_l_a4
        when /a5/     then pdf_p=@f.pdf_p_a5;     pdf_l=@f.pdf_l_a5
        when /b5/     then pdf_p=@f.pdf_p_b5;     pdf_l=@f.pdf_l_b5
        when /letter/ then pdf_p=@f.pdf_p_letter; pdf_l=@f.pdf_l_letter
        when /legal/  then pdf_p=@f.pdf_p_legal;  pdf_l=@f.pdf_l_legal
        else               pdf_p=@f.pdf_p_a4;     pdf_l=@f.pdf_l_a4
        end
        FileUtils::mkdir_p(@md.file.output_path.pdf.dir) unless FileTest.directory?(@md.file.output_path.pdf.dir)
        cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX
        if @md.opt.act[:pdf_p][:set]==:on
          if FileTest.file?(portrait_pdf)
            FileUtils::cp(portrait_pdf,"#{@md.file.output_path.pdf.dir}/#{pdf_p}")
            FileUtils::rm(portrait_pdf)
          else
            STDERR.puts "#{__FILE__}:#{__LINE__} NOT FOUND: #{portrait_pdf}" if @md.opt.act[:maintenance][:set]==:on
            errmsg="pdf file not generated #{portrait_pdf.gsub(/.+?([^\/]+?\.pdf)$/,'\1')} (check texlive dependencies)"
            if @md.opt.act[:no_stop][:set]==:on
              SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
                error("#{errmsg}, proceeding without pdf output (as requested)")
            else
              SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
                error("#{errmsg}, STOPPING")
              exit
            end
          end
        end
        if @md.opt.act[:pdf_l][:set]==:on
          if FileTest.file?(landscape_pdf)
            FileUtils::cp(landscape_pdf,"#{@md.file.output_path.pdf.dir}/#{pdf_l}")
            FileUtils::rm(landscape_pdf)
          else
            STDERR.puts "#{__FILE__}:#{__LINE__} NOT FOUND: #{landscape_pdf}" if @md.opt.act[:maintenance][:set]==:on
            errmsg="pdf file not generated #{landscape_pdf.gsub(/.+?([^\/]+?\.pdf)$/,'\1')} (check texlive dependencies)"
            if @md.opt.act[:no_stop][:set]==:on
              SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
                error("#{errmsg}, proceeding without pdf output (as requested)")
            else
              SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
                error("#{errmsg}, STOPPING")
              exit
            end
          end
        end
        if (@md.opt.act[:verbose][:set]==:on \
        || @md.opt.act[:verbose_plus][:set]==:on \
        || @md.opt.act[:maintenance][:set]==:on)
          SiSU_Screen::Ansi.new(
            @md.opt.act[:color_state][:set],
            @@n_lpdf,
            'processed (SiSU LaTeX to pdf - using pdfetex aka. pdftex or pdflatex)'
          ).generic_number
        end
      end
      def latexrun_selective
        begin
          pwd=Dir.pwd
          Dir.chdir(pwd) #watch
          @tex_f_no=0
          if FileTest.file?(@env.source_file_with_path)
            @md.papersize_array.each do |ps|
              if @md.fns =~/\.(?:-|ssm\.)?sst$/
                case @md.fns
                when /\.(?:-|ssm\.)?sst$/
                  if FileTest.directory?(@env.processing_path.tex)==true
                    Dir.chdir(@env.processing_path.tex)
                    texfile=@md.fns.gsub(/$/,".#{ps}.tex").
                      gsub(/~/,'-')
                    if @md.opt.act[:pdf_p][:set]==:on \
                    or @md.opt.act[:pdf_l][:set]==:on
                      latex_do(texfile,ps)
                      if @md.opt.act[:pdf_p][:set]==:on
                        if File.exist?(texfile) \
                        and File.size(texfile) > 0
                          #@tex_f_no+=1
                        else
                          errmsg="zero file size #{@env.processing_path.tex}/#{texfile}"
                          if @md.opt.act[:no_stop][:set]==:on
                            SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
                              error("#{errmsg}, proceeding without pdf output (as requested)")
                          else
                            SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
                              error("#{errmsg}, STOPPING")
                            exit
                          end
                        end
                      end
                    end
                  end
                end
              end
            end
            case @md.papersize_array[0] #default pdf
            when /a4/     then pdf_p=@f.pdf_p_a4;     pdf_l=@f.pdf_l_a4
            when /a5/     then pdf_p=@f.pdf_p_a5;     pdf_l=@f.pdf_l_a5
            when /b5/     then pdf_p=@f.pdf_p_b5;     pdf_l=@f.pdf_l_b5
            when /letter/ then pdf_p=@f.pdf_p_letter; pdf_l=@f.pdf_l_letter
            when /legal/  then pdf_p=@f.pdf_p_legal;  pdf_l=@f.pdf_l_legal
            else               pdf_p=@f.pdf_p_a4;     pdf_l=@f.pdf_l_a4
            end
            if @md.opt.act[:pdf_p][:set]==:on
              if FileTest.file?("#{@md.file.output_path.pdf.dir}/#{pdf_p}")
                mklnk=((@md.file.output_dir_structure.by_language_code?) \
                || (@md.file.output_dir_structure.by_filetype?)) \
                ? "#{@md.fnb}.portrait.pdf"
                : 'portrait.pdf'
                if FileTest.directory?(@md.file.output_path.pdf.dir)
                  pwd=Dir.pwd
                  Dir.chdir(@md.file.output_path.pdf.dir)
                  FileUtils::rm_f(mklnk)
                  FileUtils::ln_s(pdf_p, mklnk)
                  Dir.chdir(pwd)
                end
              end
            end
            if @md.opt.act[:pdf_l][:set]==:on
              if FileTest.file?("#{@md.file.output_path.pdf.dir}/#{pdf_l}")
                mklnk=((@md.file.output_dir_structure.by_language_code?) \
                || (@md.file.output_dir_structure.by_filetype?)) \
                ? "#{@md.fnb}.landscape.pdf"
                : 'landscape.pdf'
                pwd_set=Dir.pwd
                Dir.chdir(@md.file.output_path.pdf.dir)
                FileUtils::rm_f(mklnk)
                FileUtils::ln_s(pdf_l, mklnk)
                Dir.chdir(pwd_set)
              end
            end
          else
            SiSU_Screen::Ansi.new(
              @md.opt.act[:color_state][:set],
              "*WARN* FILE NOT FOUND: << #{@md.fns} >> - requested latex system processing skipped"
            ).warn
          end
          lst=Dir["*.{aux,log,out}"]
          lst.each {|file| File.unlink(file)} if lst
        rescue
          SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
            __LINE__.to_s + ':' + __FILE__
          end
        end
      end
    end
    class LaTeXcreate
      include SiSU_Parts_TeXpdf
      @@tex_head={
        'a4'=>    { p: nil, l: nil },
        'a5'=>    { p: nil, l: nil },
        'b5'=>    { p: nil, l: nil },
        'letter'=>{ p: nil, l: nil },
        'legal'=> { p: nil, l: nil },
        'book'=>  { p: nil, l: nil }
      }
      @@prefix_b=nil
      def initialize(particulars)
        @particulars=particulars
        @md=@particulars.md
        @env=SiSU_Env::InfoEnv.new(@md.fns) #@env=@particulars.env
        @data=@particulars.ao_array # ao file drawn here
        @st={ tex: {} }
        @tex_ml=SiSU_TeX_Pdf::UseTeX.new(@md)
        @dp=@@dp ||=SiSU_Env::InfoEnv.new.digest.pattern
        l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language
        @language=l[:n]
        @translate=SiSU_Translate::Source.new(@md,@language)
        @codeblock_box='listings' #alternative 'boites'
        @make ||=SiSU_Env::ProcessingSettings.new(@md)
      end
      def songsheet
        begin
          data=@data
          @@tex_footnote_array=[]
          @@rights=nil
          txt_gen=if @md.opt.act[:pdf_l][:set]==:on \
          and @md.opt.act[:pdf_p][:set]==:on
            'pdfTex portrait & landscape'
          elsif @md.opt.act[:pdf_l][:set]==:on
            'pdfTex landscape'
          elsif @md.opt.act[:pdf_p][:set]==:on
            'pdfTex portrait'
          else
            SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).error('error: neither landscape nor portrait')
          end
          if (@md.opt.act[:verbose][:set]==:on \
          || @md.opt.act[:verbose_plus][:set]==:on \
          || @md.opt.act[:maintenance][:set]==:on)
            SiSU_Screen::Ansi.new(
              @md.opt.act[:color_state][:set],
              txt_gen
            ).txt_grey
          end
          if defined? @md.rights.all \
          and not @md.rights.all.empty?
            sp_char=SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.rights.copyright.copyright_and_license.dup)
            copymark='Copyright {\begin{small}{\copyright\end{small}} '
           #copymark='Copyright {\begin{small}^{\copyright\end{small}} '
            copyright=sp_char.special_characters_safe.gsub(/\s*Copyright \(C\)/, copymark)
            @@rights||="\n #{Tex[:backslash]*2}[3]\\ \\linebreak #{copyright}"
          end
          if defined? @md.notes.prefix_b \
          and not @md.notes.prefix_b.empty?
            sp_char=SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.notes.prefix_b)
            prefix_b=sp_char.special_characters_safe
            @@prefix_b="\n #{Tex[:backslash]*2}[3]\\ \\linebreak \\ #{prefix_b}\n" unless @@prefix_b
          end
          data=pre(data)
          data=footnote(data)
          if @md.flag_tables #WORK ON 2009
            data=tables(data) #uncomment to start experimenting with tables
          end
          data=number_paras(data)
          data=markup(data)
          output(data)
        rescue
          SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
            __LINE__.to_s + ':' + __FILE__
          end
        ensure
        end
      end
    protected
      def pre(data)
        @tex_file=[]
        data.each do |dob|
          # DEBUG 2003w16 this is a kludge, because i could not get parameters
          # from param, Sort out ... revert to more elegant solution
          # even more of a kludge as had to insert newlines where code is used not satisfactory, think about
          dob.tmp=dob.obj #.dup
          if dob.is==:para \
          || dob.is==:heading
            dob.tmp=dob.tmp.gsub(/#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}/,'')
            dob.tmp=SiSU_TeX_Pdf::SpecialCharacters.new(@md,dob.tmp).special_characters
            if dob.tmp =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/
              dob.tmp=SiSU_TeX_Pdf::FormatTextObject.new(@md,dob.tmp).url_str_internal(dob.tmp)
            end
          elsif dob.is ==:code
            dob.tmp=if @codeblock_box=='listings'
              dob.tmp
            else
              SiSU_TeX_Pdf::SpecialCharacters.new(@md,dob.tmp).special_characters_code
            end
          elsif dob.is ==:break
            if dob.obj==Mx[:br_page]; dob.tmp='\newpage'
            elsif dob.obj==Mx[:br_page_new]; dob.tmp='\clearpage'
            elsif dob.obj==Mx[:br_page_line]; dob.tmp=' \\ \hline \\ '
            elsif dob.obj==Mx[:br_obj]; dob.tmp='\parasep'
            end
          elsif dob.is==:comment \
          || dob.is==:meta
            dob.tmp='' #dob.tmp=nil
          end
        end
        data
      end
      def footnote(data)
        data.each do |dob|
          # EMBEDDED FOOTNOTES / ENDNOTES should be straightforward but not quite a synch.
          if dob.tmp =~/#{Mx[:en_a_o]}[\d*+]+\s|#{Mx[:en_b_o]}([*+]\d+)\s/
            dob.tmp=dob.tmp.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/m,"\\footnote[\\1]{%\n \\2} ").
              gsub(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/m,"\\FootnoteA{\\1}{%\n \\2} ").
              gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/m,"\\FootnoteA{\\1}{%\n \\2} ")
          end
        end
        data
      end
      def tables_hash(md,dob)
        @block={}
        @dob=dob
        @md.papersize_array.each do |ps|
          @@tableheader={ ps => { p: 0, l: 0 } }
          dob.tmp={ tmp: dob.tmp, paper_size: ps }
          format_l=SiSU_TeX_Pdf::FormatTextObject.new(md,dob)
          dob.tmp={ tmp: dob.tmp, paper_size: ps }
          format_p=SiSU_TeX_Pdf::FormatTextObject.new(md,dob)
          @block[ps]={
            l: format_l.longtable_landscape,
            p: format_p.longtable_portrait
          }
        end
        @dob.tmp=@block
        @dob
      end
      def tables(data)
        @tex_file=[]
        data.each do |dob|
          @tex_file << if dob.is_a?(String) \
          or dob.is_a?(Hash)
            dob
          elsif dob.is==:table
            tables_hash(@md,dob) #Hash result
          else dob
          end
        end
        @tex_file
      end
      def enclose(dob)
        dob
      end
      def box_boites(dob,ocn)
        sp_char=SiSU_TeX_Pdf::SpecialCharacters.new(@md,dob.tmp,dob.is)
        dob.tmp=sp_char.special_characters_safe
        dob.tmp=dob.tmp.gsub(/(#{Mx[:nbsp]})/m,'{\color{mywhite}\1}').
        #dob.tmp.gsub(/#{Mx[:nbsp]}/m,'{~}') # dob.tmp.gsub(/#{Mx[:nbsp]}\s*/m,'{~}')
          gsub(/#{Mx[:vline]}/m,'\vline').
          gsub(/ \\( |#{Mx[:br_nl]})/,' {\textbackslash}\1').
          gsub(/#{Mx[:br_nl]}\s*\Z/m,'').
          gsub(/#{Mx[:br_nl]}{2}/,'\newline \\\\\\ ').
          gsub(/#{Mx[:br_nl]}/,' \\\\\\ ').
          gsub(/\n\n\n/m," \\newline\n\n")
        ocn=SiSU_TeX_Pdf::FormatTextObject.new(@md).ocn_display(dob)
        dob.tmp = ocn \
        + @tex_ml.paraskip_small \
        + '\begin{Codeblock}' \
        + '\begin{codeblockboitebox} \hardspace \newline ' \
        + dob.tmp \
        + '\end{codeblockboitebox}' \
        + '\end{Codeblock}' \
        + "\n" \
        + @tex_ml.paraskip_normal
        dob
      end
      def box_listings(dob,ocn)
        sp_char=SiSU_TeX_Pdf::SpecialCharacters.new(@md,dob.tmp,dob.is)
        dob.tmp=sp_char.characters_code_listings
        dob.tmp=dob.tmp.gsub(/^\s+/m,''). #bug, fix earlier, should be made unecessary
          gsub(/#{Mx[:nbsp]}/m,' ').
          gsub(/#{Mx[:vline]}/m,'|').
          gsub(/#{Mx[:br_nl]}(?:\s?\n)?/m,"\n").
          gsub(/\n\n\n/m," \n\n")
        ocn=SiSU_TeX_Pdf::FormatTextObject.new(@md).ocn_display(dob)
        dob.tmp = ocn \
        + @tex_ml.paraskip_small \
        + '\begin{Codeblock}' \
        + "\n" \
        + '\begin{lstlisting} ' \
        + "\n" \
        + dob.tmp \
        + "\n" \
        + '\end{lstlisting} ' \
        + "\n" \
        + '\end{Codeblock}' \
        + "\n" \
        + @tex_ml.paraskip_normal
        dob
      end
      def markup_common(dob)
        if dob.of==:block
          @lineone=if dob.is==:block \
          || dob.is==:group \
          || dob.is==:alt \
          || dob.is==:verse
            dob.tmp=dob.tmp.gsub(/#{Mx[:nbsp]}/m,' \hardspace ').
              gsub(/#{Mx[:gl_bullet]}/m,'\txtbullet \hardspace '). #Bullet environment not used for grouped text, no hanging indent here
              gsub(/#{Mx[:br_nl]}+/m,"\n\n") #match not ideal, but currently not inserting extra newlines anyway
            ocn=SiSU_TeX_Pdf::FormatTextObject.new(@md).ocn_display(dob)
            dob.tmp=if dob.is==:group \
            || dob.is==:block \
            || dob.is==:alt
              dob.tmp=SiSU_TeX_Pdf::SpecialCharacters.new(@md,dob.tmp).special_characters_safe
              ocn \
              + @tex_ml.paraskip_small \
              + "\n" \
              + ' \\begin{footnotesize}' \
              + "\n\n" \
              + dob.tmp \
              + '\\end{footnotesize}' \
              + "\n" \
              + @tex_ml.paraskip_normal
            elsif dob.is==:verse
              dob.tmp=dob.tmp.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/m,'\begin{bfseries}\1 \end{bfseries}').
                gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/m,'\emph{\1}').
                gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/m,'\uline{\1}')
              ocn \
              + @tex_ml.paraskip_tiny \
              + "\n" \
              + ' \\begin{footnotesize}' \
              + "\n\n" \
              + dob.tmp \
              + '\\end{footnotesize}' \
              + "\n" \
              + @tex_ml.paraskip_normal \
              + "\n\\linebreak\n"
            end
            dob
          elsif dob.is ==:code
            dob=if @codeblock_box == 'listings'
              box_listings(dob,ocn)
            elsif @codeblock_box == 'boites'
              box_boites(dob,ocn)
            else
              box_boites(dob,ocn)
            end
            dob
          else 'error' #should never occur
          end
          dob=enclose(dob) unless (dob.tmp.is_a?(String) && dob.tmp =~/^$/)
          dob
        else
          tst=SiSU_TeX_Pdf::FormatTextObject.new(@md,dob)
          case dob.is
          when :heading
            case dob.ln
            when 0
              tst.title_level_A
            when 1
              tst.section_heading_level_B
            when 2
              tst.section_heading_level_C
            when 3
              tst.section_heading_level_D
            when 4
              tst.heading_level_1
            when 5
              tst.heading_level_2
            when 6
              tst.heading_level_3
            when 7
              tst.heading_level_4
            else dob
            end
          when :heading_insert
            br="\n\\\\\n"
            if dob.name=='book_index'
              h=tst.section_heading_level_B
              heading="\\clearpage\n" + h.tmp
              idx_arr=[]
              idx=SiSU_Particulars::CombinedSingleton.instance.get_idx_raw(@md.opt).raw_idx
              idx.each do |x|
                x=if x.is_a?(String)
                  x=SiSU_TeX_Pdf::SpecialCharacters.new(@md,x).special_characters
                  x=SiSU_TeX_Pdf::FormatTextObject.new(@md,x).url_str_internal(x,true)
                else x=nil
                end
                idx_arr << x.sub(/,$/,'') if x.is_a?(String)
              end
              idx_str=idx_arr.join(br)
              l=heading + br + idx_str
              p=heading + br +
                '\begin{multicols}{2}' + br +
                idx_str + br +
                '\end{multicols}'
              dob.tmp={ l: l, p: p }
            elsif dob.ln==2 \
            and dob.obj=~/Metadata\b/
              tst.section_heading_level_B
            elsif dob.ln==4 \
            and dob.obj=~/Metadata\b/
              h=tst.heading_level_1
              metadata=SiSU_Metadata::TeX_Metadata.new(@md).metadata_tex
              dob.tmp=h.tmp + ' ' + '\begin{scriptsize}' + metadata.join(br) + '\end{scriptsize}'
            else dob.tmp='' # dob.tmp={ l: '', p: '' }
            end
          when :para
            if dob.bullet_
              dob.tmp=tst.bullet
            elsif dob.indent \
            and dob.hang \
            and dob.indent =~/[1-9]/ \
            and dob.indent == dob.hang
              dob.tmp=tst.indent
            elsif dob.hang \
            and dob.hang =~/[0-9]/ \
            and (dob.indent != dob.hang or dob.indent =~/[1-9]/)
              dob.tmp=tst.hang
            else
              dob.tmp=dob.tmp.strip
              dob=enclose(dob) unless (dob.tmp.is_a?(String) && dob.tmp =~/^$/)
            end
          else
            dob.tmp=dob.tmp.strip unless dob.is==:code
            dob=enclose(dob) unless (dob.tmp.is_a?(String) && dob.tmp =~/^$/)
          end
          if dob.is_a?(String)
            dob.tmp=dob.tmp.gsub(/\s*(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*/,' \newline ').   #% tread with care
              gsub(/(\.#{Tex[:tilde]}\S*\s*|<:\S+>|#{Mx[:fa_o]}.*?#{Mx[:fa_c]}|#{Mx[:gr_o]}.*?#{Mx[:gr_c]}|<!.*?!>|<!>)/,' ')   #% tread with care
          end
          dob
        end
        if (dob.tmp.is_a?(String) and dob.tmp =~/(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image\b)/m) \
        && dob.is !=:code
          dob=SiSU_TeX_Pdf::BareUrls.new(@md,dob).bare_urls
          tst=SiSU_TeX_Pdf::FormatTextObject.new(@md,dob)
          dob=tst.urls_txt_and_images
          dob
        elsif (dob.tmp.is_a?(String) and dob.tmp  =~/https?:\/\/\S+\b/m) \
        && dob.is ==:code \
        && @codeblock_box !='listings'
          dob=SiSU_TeX_Pdf::BareUrls.new(@md,dob).bare_urls_in_code
          dob
        end
        if dob.class !=Hash \
        && (dob.tmp.is_a?(String) and dob.tmp =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\b/) \
        && dob.is !=:code
          tst=SiSU_TeX_Pdf::FormatTextObject.new(@md,dob)
        end
        dob
      end
      def markup(data)
        @tex_file=[]
        home=the_text.txt_home.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}|#{Mx[:br_paragraph]}|\\\\/,' - ') #no line splitting in heading neither html nor latex
        title=@md.title.full.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}|#{Mx[:br_paragraph]}|\\\\/,' - ') #no line splitting in heading neither html nor latex
        @md.papersize_array.each do |ps|
          if @md.opt.act[:pdf_p][:set]==:on
            txt_obj={ txt: "#{home}: - #{title}", paper_size: ps, orientation: :portrait }
            orient_portrait=SiSU_TeX_Pdf::FormatHead.new(@md,txt_obj)
            @@tex_head[ps][:p]=orient_portrait.document_head_with_orientation(@codeblock_box)
          end
          if @md.opt.act[:pdf_l][:set]==:on
            txt_obj={ txt: "#{home}: - #{title}", paper_size: ps, orientation: :landscape }
            orient_landscape=SiSU_TeX_Pdf::FormatHead.new(@md,txt_obj)
            @@tex_head[ps][:l]=orient_landscape.document_head_with_orientation(@codeblock_box)
          end
        end
        @tex_file << <<-WOK
#{@tex_ml.header}#{@tex_ml.footer}
% (tilde hash amp affected by http)
% \\sloppy
\\begin{document}
        WOK
        @copymark='' #check and remove as now is superflous
        x={}
        txt_obj={ title: @md.title.full }
        if @md.opt.act[:pdf_l][:set]==:on
          x[:l]=SiSU_TeX_Pdf::FormatTextObject.new(@md,txt_obj).title_landscape
        end
        if @md.opt.act[:pdf_p][:set]==:on
          x[:p]=SiSU_TeX_Pdf::FormatTextObject.new(@md,txt_obj).title_portrait
        end
        @tex_file << x
        x=nil
        if defined? @md.creator.author \
        and @md.creator.author
          sp_char=SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.creator.author)
          author=sp_char.special_characters
          @tex_file << if @md.author_home
            <<-WOK

\\author{\\href{#{@md.author_home}}{#{@copymark} \\textnormal{#{author}}}}
            WOK
          else "\n\\author{#{@copymark} \\textnormal{#{author}}}"
          end
        end
        if defined? @md.make.cover_image \
        and not @md.make.cover_image.nil? \
        and @md.make.cover_image[:cover] =~/\S+/
          x={}
          dir=SiSU_Env::InfoEnv.new(@md.fns)
          x[:l] =<<-WOK
\\titlepic{\\includegraphics[width=0.3\\textwidth]{#{dir.path.image_source_include}/#{@md.make.cover_image[:cover]}}}
          WOK
          x[:p] =<<-WOK
\\titlepic{\\includegraphics[width=0.6\\textwidth]{#{dir.path.image_source_include}/#{@md.make.cover_image[:cover]}}}
          WOK
          @tex_file << x
          x=nil
        end
        @tex_file << unless @md.fnb =~/^mail\s*$/ then @tex_ml.site
        else                                           '\date'
        end
        @tex_file << <<-WOK
\\pagenumbering{roman}\\maketitle
\\pagestyle{fancy}
        WOK
        if defined? @md.rights.all \
        and @md.rights.all
          @tex_file << "\\newpage\n"
          @tex_file << @@rights
          @tex_file << @@prefix_b if defined? @md.creator.prefix_b and @md.creator.prefix_b
        end
        x={}
        if (@make.build.toc?)
          toc=<<-WOK
\\clearpage
\\pagenumbering{roman}
\\setcounter{page}{1}
\\renewcommand{\\contentsname}{#{@translate.contents}}
\\tableofcontents
\\clearpage
          WOK
          toc_pb={ l: @tex_ml.newpage(:landscape), p: @tex_ml.newpage(:portrait) }
        else
          toc=''
          toc_pb={ l: '', p: '' }
        end
        if @md.opt.act[:pdf_l][:set]==:on
          x[:l] =<<-WOK
#{@tex_ml.newpage(:landscape)}
\\pagestyle{fancy}
#{toc}#{toc_pb[:l]}
\\pagenumbering{arabic}
\\clearpage
\\setcounter{page}{2}
\\clearpage
#{@tex_ml.paraskip_normal}
#{@tex_ml.newpage(:landscape)}
          WOK
        end
        if @md.opt.act[:pdf_p][:set]==:on
          x[:p] =<<-WOK
#{@tex_ml.newpage(:portrait)}
\\pagestyle{fancy}
#{toc}#{toc_pb[:p]}
#{@tex_ml.newpage(:portrait)}
\\pagenumbering{arabic}
\\clearpage
\\setcounter{page}{2}
\\clearpage
#{@tex_ml.paraskip_normal}
#{@tex_ml.newpage(:portrait)}
          WOK
        end
        @tex_file << x
        x=nil
        data.each do |dob|                                                      #% case follows with levels 1-6 indents & graphics
          if dob.is_a?(Hash)
          elsif dob.of==:para \
          || dob.of==:block #GATEWAY FIX FIX stuff
            dob=markup_common(dob)
          elsif dob.is==:table
            if ( dob.tmp['a4'] \
            or dob.tmp['a5'] \
            or dob.tmp['b5'] \
            or dob.tmp['letter'] \
            or dob.tmp['legal'])
              @md.papersize_array.each do |ps|
                if dob.tmp[ps]
                  if (dob.tmp[ps][:p] and dob.tmp[ps][:l])
                    dob.tmp[ps]={
                      p: markup_common(dob.tmp[ps][:p]),
                      l: markup_common(dob.tmp[ps][:l])
                    }
                  else p "#{__FILE__}:#{__LINE__}" if @md.opt.act[:maintenance][:set]==:on
                  end
                end
              end
            elsif dob.tmp.is_a?(Hash) \
            and (dob.tmp[:p] and dob.tmp[:l])
              dob = {
                p: markup_common(dob.tmp[:p]),
                l: markup_common(dob.tmp[:l])
              }
            else p "#{__FILE__}:#{__LINE__}" if @md.opt.act[:maintenance][:set]==:on
            end
          end
          @tex_file << dob
        end
        @st[:tex][:stmp]||=@md.stmpd
        stamp=@st[:tex][:stmp] if @st[:tex][:stmp]
        if stamp
          use=stamp.gsub(/\n/,"#{Tex[:backslash]*2}\n")
          @tex_file << "\n\\newpage\n"
          @tex_file << "\\section*" +
            "{#{@tex_ml.owner_chapter}}\n" +
            "\\addcontentsline{toc}" +
            "{section}{#{@tex_ml.owner_chapter}}\n"
          @tex_file << "#{use}\n"
          @tex_file << @@rights if @@rights
        end
        @tex_file << "\n\\end{document}"
      end
      def number_paras_numbering(dob) # need tables and other types of object
        if dob.of ==:para
          paranum=dob.ocn ? dob.ocn : ''
          paranum = '' if paranum.to_i==0
          paranumber_display=if @make.build.ocn?
            tags=''
            #[keep] code that follows inserts "name tags" as hypertargets, currently using ocn (converting nametags to ocn) for internal linking, related code: |texpdf_format.rb|@|uses nametags directly|
            #if dob.tags.length > 0 # insert tags "hypertargets"
            #  dob.tags.each do |t|
            #    tags=tags +"\\hspace{0mm}\\hypertarget{#{t}}{\\hspace{0mm}}"
            #  end
            #end
            "\\ocn{#{dob.ocn}}" #ocn object citation numbering
          else ''
          end
          dob.tmp = paranumber_display + dob.tmp
        end
        dob
      end
      def number_paras(data)
        data.each do |dob|
          dob=if dob.is_a?(Hash)
            if ( dob['a4'] \
            or dob['a5'] \
            or dob['b5'] \
            or dob['letter'] \
            or dob['legal'])
              para_hash={}
              @md.papersize_array.each do |ps|
                if defined? dob.tmp and dob.tmp[ps]
                  if (dob.tmp[ps][:p] and dob.tmp[ps][:l])
                    para_hash[ps]={
                      p: number_paras_numbering(dob.tmp[ps][:p]),
                      l: number_paras_numbering(dob.tmp[ps][:l])
                    }
                    dob.tmp=para_hash
                  else p "#{__FILE__}:#{__LINE__}" if @md.opt.act[:maintenance][:set]==:on
                  end
                end
              end
            elsif (dob.tmp[:p] and dob.tmp[:l])
              dob.tmp = {
                p: number_paras_numbering(dob.tmp[:p]),
                l: number_paras_numbering(dob.tmp[:l])
              }
            else p "#{__FILE__}:#{__LINE__}" if @md.opt.act[:maintenance][:set]==:on
            end
          else
            dob=if dob.of !=:comment \
            || dob.of !=:meta \
            || dob.of !=:layout
              number_paras_numbering(dob)
            else dob
            end
          end
        end
        data
      end
      def output_morph_hash(o)
        ps,h,fn=o[:ps],o[:h],o[:filename]
        if h[ps] \
        and (h[ps][:p] or h[ps][:l])
          if @md.opt.act[:pdf_p][:set]==:on
            if h[ps][:p]
              h[ps][:p]=h[ps][:p].gsub(/[ ]+$/m,'').
                gsub(/\n\n\n+/m,"\n\n")
            end
            if h[ps][:p] !~/\A\s*\Z/
              fn[:portrait].puts h[ps][:p],"\n"
            end
          end
          if @md.opt.act[:pdf_l][:set]==:on
            if h[ps][:l]
              h[ps][:l]=h[ps][:l].gsub(/[ ]+$/m,'').
                gsub(/\n\n\n+/m,"\n\n")
            end
            if h[ps][:l] !~/\A\s*\Z/
              fn[:landscape].puts h[ps][:l],"\n"
            end
          end
        elsif (h[:p] or h[:l])
          if @md.opt.act[:pdf_p][:set]==:on
            if h[:p]
              h[:p]=h[:p].gsub(/[ ]+$/m,'').
                gsub(/\n\n\n+/m,"\n\n")
            end
            if h[:p] !~/\A\s*\Z/
              fn[:portrait].puts h[:p],"\n"
            end
          end
          if @md.opt.act[:pdf_l][:set]==:on
            if h[:l]
              h[:l]=h[:l].gsub(/[ ]+$/m,'').
                gsub(/\n\n\n+/m,"\n\n")
            end
            if h[:l] !~/\A\s*\Z/
              fn[:landscape].puts h[:l],"\n"
            end
          end
        else p "#{__FILE__}:#{__LINE__}" if @md.opt.act[:maintenance][:set]==:on
        end
      end
      def output(array)
        @array=array=array.flatten.compact
        fns=@md.fns.gsub(/~/,'-') #this is a sorry fix, but necessary as it appears latex programs like not ~
        @md.papersize_array.each do |ps|
          texfile_landscape=(@md.opt.act[:pdf_l][:set]==:on) \
          ? (File.new("#{@env.processing_path.tex}/#{fns}.#{ps}.landscape.tex",'w+'))
          : nil
          texfile_portrait=(@md.opt.act[:pdf_p][:set]==:on) \
          ? (File.new("#{@env.processing_path.tex}/#{fns}.#{ps}.tex",'w+'))
          : nil
          file={
            landscape: texfile_landscape,
            portrait:  texfile_portrait
          }
          if @md.opt.act[:pdf_p][:set]==:on
            file[:portrait] << @@tex_head[ps][:p]
          end
          if @md.opt.act[:pdf_l][:set]==:on
            file[:landscape] << @@tex_head[ps][:l]
          end
          array.each do |morph|
            if morph.is_a?(String)
              #morph.gsub!(/^\s+/,'')
              if morph !~/\A\s*\Z/
                if @md.opt.act[:pdf_p][:set]==:on
                  file[:portrait].puts morph,"\n"
                end
                if @md.opt.act[:pdf_l][:set]==:on
                  file[:landscape].puts morph,"\n"
                end
              end
            elsif morph.class.inspect =~ /SiSU_AO_DocumentStructure/ \
            and morph.tmp \
            and morph.tmp.is_a?(String)
              if morph.is !=:code \
              && morph.of !=:block
                morph.tmp=morph.tmp.gsub(/^\s+/,'')
              else morph.tmp
              end
              if (morph.tmp !~/\A\s*\Z/) \
              || morph.is==:code
                if @md.opt.act[:pdf_p][:set]==:on
                  file[:portrait].puts morph.tmp,"\n"
                end
                if @md.opt.act[:pdf_l][:set]==:on
                  file[:landscape].puts morph.tmp,"\n"
                end
              end
            elsif morph.is_a?(Hash)            #inserted headers and the like, only
              h={ ps: ps, h: morph, filename: file }
              output_morph_hash(h)
            elsif morph.tmp.is_a?(Hash)       #tables & images?
              h={ ps: ps, h: morph.tmp, filename: file }
              output_morph_hash(h)
            end
          end
          array=@array
          if @md.opt.act[:pdf_p][:set]==:on
            file[:portrait].close
          end
          if @md.opt.act[:pdf_l][:set]==:on
            file[:landscape].close
          end
        end
        @@tex_head={
          'a4'=>    { p: nil, l: nil },
          'a5'=>    { p: nil, l: nil },
          'b5'=>    { p: nil, l: nil },
          'letter'=>{ p: nil, l: nil },
          'legal'=> { p: nil, l: nil },
          'book'=>  { p: nil, l: nil }
        }
        array=[]
      end
    end
  end
end
__END__
#+END_SRC

** texpdf_parts.rb

#+HEADER: :tangle "../lib/sisu/texpdf_parts.rb"
#+BEGIN_SRC ruby
#<<sisu_document_header>>
module SiSU_Parts_TeXpdf
  require_relative 'generic_parts'                       # generic_parts.rb
  include SiSU_Parts_Generic
  def the_line_break
    ' \\ '
  end
  def url_decoration
    def tex_open                     #'{\UseTextSymbol{OML}{<}}'
      Dx[:url_o]
    end
    def tex_close                    #'{\UseTextSymbol{OML}{>}}'
      Dx[:url_c]
    end
    def txt_open
      '<'
    end
    def txt_close
      '>'
    end
    self
  end
  def the_font
    def set_fonts
      'verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman'
    end
    self
  end
  class TeX
    def initialize(papersize='')
      @papersize=papersize
    end
    def a4
      def portrait
        def w
          160
        end
        def h
          228
        end
        def img_px
          450
        end
        self
      end
      def landscape
        def w
          238
        end
        def h
          160
        end
        def img_px
          300
        end
        self
      end
      self
    end
    def letter
      def portrait
        def w
          166
        end
        def h
          212
        end
        def img_px
          468
        end
        self
      end
      def landscape
        def w
          226
        end
        def h
          166
        end
        def img_px
          290
        end
        self
      end
      self
    end
    def legal
      def portrait
        def w
          168
        end
        def h
          286
        end
        def img_px
          474
        end
        self
      end
      def landscape
        def w
          296
        end
        def h
          166
        end
        def img_px
          420
        end
        self
      end
      self
    end
    def b5
      def portrait
        def w
          140
        end
        def h
          204
        end
        def img_px
          356
        end
        self
      end
      def landscape
        def w
          200
        end
        def h
          130
        end
        def img_px
          260
        end
        self
      end
      self
    end
    def a5
      def portrait
        def w
          112
        end
        def h
          162
        end
        def img_px
          280
        end
        self
      end
      def landscape
        def w
          152
        end
        def h
          100
        end
        def img_px
          190
        end
        self
      end
      self
    end
    def dimensions
      case @papersize
      when /a4/     then a4
      when /letter/ then letter
      when /legal/  then legal
      when /b5/     then b5
      when /a5/     then a5
      else               a4
      end
    end
  end
end
__END__
#+END_SRC

** texpdf_format.rb

#+HEADER: :tangle "../lib/sisu/texpdf_format.rb"
#+BEGIN_SRC ruby
#<<sisu_document_header>>
module SiSU_TeX_Pdf
  require_relative 'texpdf_parts'                        # texpdf_parts.rb
  @@table_pg_break_counter=1
  class BareUrls
    include SiSU_Parts_TeXpdf
    def initialize(md,dob=nil)
      @md,@dob=md,dob
    end
    def bare_urls
      @dob.obj=@dob.obj.gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@[a-zA-Z0-9_-]+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/,
         "#{url_decoration.tex_open}\\begin{scriptsize}\\email{\\1}#{url_decoration.tex_close}")
      @dob.tmp=@dob.tmp.gsub(/(^|[^\\])_/m,'\1\_'). #watch may not work
        gsub(/(^|[^#{Mx[:lnk_c]}])#{Mx[:url_o]}_?(?:\\?_)?(\S+?)#{Mx[:url_c]}/m,
          "\\1#{url_decoration.tex_open}\\begin{scriptsize}\\url{\\2}\\end{scriptsize}#{url_decoration.tex_close}")
      @dob
    end
    def bare_urls_in_code
      @dob.tmp=@dob.tmp.gsub(/(^|[^\\])_/m,'\1\_'). #watch may not work
        gsub(/(https?:\/\/\S+?)([{]|[.,;)\]]?(?: |$))/m,
          '\begin{scriptsize}\url{\1}\end{scriptsize}\2')
      @dob
    end
  end
  class FormatTextObject
    include SiSU_Parts_TeXpdf
    attr_accessor :string,:string1,:orientation,:url,:dir,:tex
    @@sys=SiSU_Env::SystemCall.new
    @@tex_pattern_margin_number=/\\ocn\{[0-9]+\}/
    @@tableheader={
      'a4' => { p: 0, l: 0 },
      'a5' => { p: 0, l: 0 },
      'b5' => { p: 0, l: 0 },
      'letter' => { p: 0, l: 0 },
      'legal' => { p: 0, l: 0 }
    }
    @@sys=SiSU_Env::SystemCall.new
    def initialize(md,dob=nil)
      @md,@dob=md,dob
      if defined? @md.image \
      and @md.image =~/center/
        @center_begin,@center_end='\begin{center}','\end{center}'
      else @center_begin,@center_end='',''
      end
      @start_table=''
      @tx=SiSU_Env::GetInit.new.tex
      @env ||=SiSU_Env::InfoEnv.new(@md.fns)
      @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine
      @make ||=SiSU_Env::ProcessingSettings.new(@md)
    end
    def ocn_display(dob)
      show_ocn=(@make.build.ocn?) \
      ? dob.ocn
      : ''
      "\\ocn{#{dob.ocn}}" #ocn object citation numbering
    end
    def table_special_characters(r)
      r=r.gsub(/#{Mx[:tc_p]}/mu,'&').
        gsub(/#{Mx[:tc_c]}/m,'\\\\\\').
        gsub(/%/,'\%').
        gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\begin{bfseries}\1 \end{bfseries}').
        gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\emph{\1}').
        gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\uline{\1}'). # ulem
        gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,"``\\1''"). # quote #CHECK
        gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\uline{\1}'). # ulem
        gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\sout{\1}'). # ulem
        gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,"\$^{\\textrm{\\1}}\$").
        gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,"\$_{\\textrm{\\1}}\$")
    end
    def longtable_landscape
      end_table='\end{longtable}'
      row_break='\\\\\\'
      if @dob.is==:table
        tw=case @dob.tmp[:paper_size]
        when /a4/i      then @tx.a4.landscape.w     #European default, SiSU default
        when /letter/i  then @tx.letter.landscape.w #U.S. default
        when /legal/i   then @tx.legal.landscape.w  #U.S. alternative
        when /book|b5/i then @tx.b5.landscape.w     #book default - larger
        when /a5/i      then @tx.a5.landscape.w
        else             @tx.a4.landscape.w     #default currently A4
        end
        textwidth=(tw.to_i/2) - 24
        colW=[]
        colW << '{'
        @dob.widths.each  do |x|
          x=(x.to_i * textwidth)/100
          col_w=x.to_s # x.gsub(/.+/,'l\|') #unless x.nil?
          colW << "p{#{col_w}mm}" if col_w
        end
        colW << '}'
        colW=colW.join
        start_table="\n\\setlength{\\LTleft}{0pt}\n\\setlength{\\LTright}{\\fill}\n" +
          "\\begin{tiny}\n\\begin{longtable}#{colW}\n"
        rows=@dob.obj.split(/#{Mx[:br_nl]}/)
        if @dob.head_ #result imperfect, check on
          rows[0]=rows[0].gsub(/(^|.+?)(?:#{Mx[:tc_p]}|$)/u,'\bfseries \1&').
            gsub(/&\s*$/," #{row_break} \\hline\\endhead #{row_break}")
        end
        rows_new=[]
        rows.each do |r|
          r=table_special_characters(r)
          r=r.gsub(/$/," #{row_break}\n") unless r =~/#{row_break*2}$/
          if r=~/\<!f(.+?)!\>/ # not tested table footer if any
            tablefoot=$1
            r=r.gsub(/\<!f(.+?)!\>/,'')
            r="#{r} \\multicolumn{#{@dob.cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n"
          end
          rows_new << r
        end
        table=rows_new.join #@dob[:ao].obj=rows.join
        ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}"
      else ''
      end
    end
    def longtable_portrait
      end_table='\end{longtable}'
      row_break='\\\\\\'
      if @dob.is==:table
        tw=case @dob.tmp[:paper_size]
        when /a4/i      then @tx.a4.portrait.w     #European default, SiSU default
        when /letter/i  then @tx.letter.portrait.w #U.S. default
        when /legal/i   then @tx.legal.portrait.w  #U.S. alternative
        when /book|b5/i then @tx.b5.portrait.w     #book default - larger
        when /a5/i      then @tx.a5.portrait.w
        else             @tx.a4.portrait.w         #default currently A4
        end
        textwidth=tw.to_i - 20
        colW=[]
        colW << '{'
        @dob.widths.each do |x|
          x=(x.to_i * textwidth)/100 #x=(x.to_i/100.0 * 160)
          col_w=x.to_s # x.gsub(/.+/,'l\|') #unless x.nil?
          colW << "p{#{col_w}mm}" if col_w
        end
        colW << '}'
        colW=colW.join
        start_table="\n\\setlength{\\LTleft}{0pt}\n\\setlength{\\LTright}{\\fill}\n" +
          "\\begin{tiny}\n\\begin{longtable}#{colW}\n"
        rows=@dob.obj.split(/#{Mx[:br_nl]}/)
        if @dob.head_
          rows[0]=rows[0].gsub(/(^|.+?)(?:#{Mx[:tc_p]}|$)/u,'\bfseries \1&').
            gsub(/&\s*$/," #{row_break} \\hline\\endhead #{row_break}")
        end
        rows_new=[]
        rows.each do |r|
          r=table_special_characters(r)
          r=r.gsub(/$/," #{row_break}\n") unless r =~/#{row_break*2}$/
          if r=~/\<!f(.+?)!\>/ # not tested table footer if any
            tablefoot=$1
            r=r.gsub(/\<!f(.+?)!\>/,'')
            r="#{r} \\multicolumn{#{@dob.cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n"
          end
          rows_new << r
        end
        table=rows_new.join #@dob[:ao].obj=rows.join
        ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}"
      else ''
      end
    end
    def remove_footnotes(cont_ln)
      cont_ln=if cont_ln =~/\\[Ff]ootnote/m
        cont_ln.gsub(/\s*\\[Ff]ootnote\[\d+\]\{%\s+.+?\}\s*/m,' ').
          gsub(/\s*\\[Ff]ootnote[A]\{[*+]+\d*\}\{%\S+.+?\}\s*/m,' ')
      else cont_ln
      end
    end
    def title_level_A
      dob=@dob
      dob.tmp=dob.tmp.strip if dob.tmp
      dob.tmp=dob.tmp.gsub(/\\begin\{(bfseries|itshape)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(/#{Mx[:url_o]}|#{Mx[:url_c]}/,'')
      cont_ln=dob.tmp.dup
      cont_ln=cont_ln.gsub(/\\begin\{(monosp)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(@@tex_pattern_margin_number,'')
      cont_ln=remove_footnotes(cont_ln)
      cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1')
      titleset=''
      dob.tmp=dob.tmp.gsub(/^(.*)\n?$/m,
        "#{titleset}\\part*{\\1}
\\markboth{#{@md.title.full}}\n")
      dob
    end
    def section_heading_level(dob)
      dob.tmp=dob.tmp.strip if dob.tmp
      dob.tmp=dob.tmp.gsub(/\\begin\{(bfseries|itshape)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(/#{Mx[:url_o]}|#{Mx[:url_c]}/,'')
      cont_ln=dob.tmp.dup
      cont_ln=cont_ln.gsub(/\\begin\{(monosp)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(@@tex_pattern_margin_number,'')
      cont_ln=remove_footnotes(cont_ln)
      cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1')
      dob.tmp=dob.tmp.gsub(/^(.*)\n?$/m,
        "\\clearpage
\\part*{\\1}
\\addcontentsline{toc}{part}{#{cont_ln}}
\\markboth{#{@md.title.full}}\n")
      dob
    end
    def heading_dev_null(dob)
      dob.tmp,dob.obj='',''
      dob
    end
    def heading_sublevels(dob)
      if dob.lv=='1'
        sect='section'
        tocadd=%{\\addcontentsline{toc}{section}}
        pre=''
        post=''
        headadd=%{\n\\markright{#{@md.title.full}}}
      elsif dob.lv=='2'
        sect='subsection'
        tocadd=%{\\addcontentsline{toc}{subsection}}
        pre=''
        post=" \\\\\n"
        headadd=''
      elsif dob.lv=='3'
        sect='subsubsection'
        tocadd=%{\\addcontentsline{toc}{subsubsection}}
        pre='' #pre='~~~~'
        post=" \\\\\n"
        headadd=''
      end
      dob.tmp=dob.tmp.strip if dob.tmp
      dob.tmp=dob.tmp.gsub(/\\begin\{(bfseries|itshape)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(/#{Mx[:url_o]}|#{Mx[:url_c]}/,'')
      cont_ln=dob.tmp.dup
      cont_ln=cont_ln.gsub(/\\ocn\{[0-9]*\}/m,'').
        gsub(@@tex_pattern_margin_number,'').
        gsub(/#{Tex[:backslash]*2}/,"#{Tex[:backslash]*4}"). # added w42
        gsub(/\\footnote\[\d+\]\{%.+?\\end\{scriptsize\}\s*\}/m,''). #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22
        gsub(/\\Footnote[A]\{[*+]+\d*\}\{%.+?\\end\{scriptsize\}\s*\}/m,'') #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22
      if dob.name =~/endnotes/
        dob.tmp=dob.tmp.gsub(/.+/m,'')
      end
      cont_ln=remove_footnotes(cont_ln)
      cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1')
      dob.tmp=dob.tmp.gsub(/^(.*)?\n?$/m,
        "\\#{sect}*{\\1}
#{tocadd}{#{pre}#{cont_ln}#{post}}#{headadd}")
      dob
    end
    def section_heading_level_B
      section_heading_level(@dob)
    end
    def section_heading_level_C
      section_heading_level(@dob)
    end
    def section_heading_level_D
      section_heading_level(@dob)
    end
    def heading_level_1
      if not @dob.use_ == :dummy
        heading_sublevels(@dob)
      else
        heading_dev_null(@dob)
      end
    end
    def heading_level_2
      heading_sublevels(@dob)
    end
    def heading_level_3
      heading_sublevels(@dob)
    end
    def heading_level_4
      heading_sublevels(@dob)
    end
    def hang
      _idt=10
      indent = "#{_idt*(@dob.indent.to_i-1)}mm"
      hang =  "#{_idt*(@dob.hang.to_i - @dob.indent.to_i)}mm"
      "\\begin{ParagraphHang}{#{indent}}{#{hang}}#{@dob.tmp} \\end{ParagraphHang}}"
    end
    def indent
      indent=case @dob.indent
      when /1/ then '0mm'
      when /2/ then '10mm'
      when /3/ then '20mm'
      when /4/ then '30mm'
      when /5/ then '40mm'
      when /6/ then '50mm'
      when /7/ then '60mm'
      when /8/ then '70mm'
      when /9/ then '80mm'
      end
      "\\begin{ParagraphIndent}{#{indent}}#{@dob.tmp} \\end{ParagraphIndent}}"
    end
    def bullet
      blt=if @dob.indent
        indent=case @dob.indent
        when /1/ then '0em'
        when /2/ then '1.0em'
        when /3/ then '2.0em'
        when /4/ then '3.0em'
        when /5/ then '4.0em'
        when /6/ then '5.0em'
        when /7/ then '6.0em'
        when /8/ then '7.0em'
        when /9/ then '8.0em'
        else      '-1.0em'
        end
        "\\begin{Bullet}{#{indent}}#{@dob.tmp}\\end{Bullet}"
      else
        "\\begin{Bullet}{-5mm}#{@dob.tmp}\\end{Bullet}"
      end
      blt
    end
    def symbol_graphic
      dir=SiSU_Env::InfoEnv.new(@md.fns)
      image='c_' + /<:=\s*(\S+?)\s*>/m.match(@txt).captures.join + '.png' #watch
      if FileTest.file?("#{dir.path.image_source_include}/#{image}")
        @txt.gsub!(/<:=\s*(\S+?)\s*>/,
          "\\includegraphics*[width=11pt]{#{dir.path.image_source_include}/c_\\1.png}")
      else
        SiSU_Screen::Ansi.new(
          @md.opt.act[:color_state][:set],
          "ERROR - image:",
          %{"#{image}" missing},
          "search path: #{dir.path.image_source_include}"
        ).error2 unless @md.opt.act[:quiet][:set]==:on
        @txt.gsub!(/#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,'') # fragile match operator\\ fragile !
      end
    end
    def url_str_internal(str,idx=nil)
      map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags
      rgx_url_internal=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}#?\S+?#{Mx[:rel_c]}/m
      while str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/m
        link,url=$1,$2
        link,url=link.strip,url.strip
        link.gsub!(/&/,"#{Xx[:protect]}&")
        url="#{@env.url.root}/" + url
        str.sub!(/#{Mx[:lnk_o]}[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+#{Mx[:lnk_c]}#{Mx[:rel_o]}:\S+?#{Mx[:rel_c]}/m,
          "#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}")
      end
      while str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}#?(\S+?)#{Mx[:rel_c]}/m
        link,url=$1,$2
        link,url=link.strip,url.strip
        link.gsub!(/&/,"#{Xx[:protect]}&")
        url.gsub!(/\\_/,'_')
        ocn_lnk=if map_nametags[url] \
        and map_nametags[url][:ocn]
          map_nametags[url][:ocn]
        else nil
        end
        ocn_lnk=(url=~/^\d+$/ ? url : ocn_lnk)
        if ocn_lnk and not ocn_lnk.empty?
          idx \
          ? (str.sub!(rgx_url_internal,"\\hyperlink{#{ocn_lnk}}{#{link}}"))
          : (str.sub!(rgx_url_internal,"#{url_decoration.tex_open}\\hyperlink{#{ocn_lnk}}{#{link}}#{url_decoration.tex_close}"))
        else
          puts %{name tag: "#{url}" not found}
          str.sub!(rgx_url_internal,"#{link}")
        end
        #[keep] code that follows uses nametags directly, currently nametags converted to their ocn, related code: |texpdf.rb|@|hypertargets|
        #idx \
        #? (str.sub!(rgx_url_internal,"\\hyperlink{#{url}}{#{link}}")) \
        #: (str.sub!(rgx_url_internal,"#{url_decoration.tex_open}\\hyperlink{#{url}}{#{link}}#{url_decoration.tex_close}"))
      end
      str=str.gsub(/#{Xx[:protect]}/,'')
    end
    def url_str(str)
      rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
      while str =~rgx_url_generic
        if str=~rgx_url_generic
          regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
          z,url=regx_url.match(str).captures if str =~regx_url
          url=url.strip
          link=z.strip
          link.gsub!(/&/,"#{Xx[:protect]}&")
          str.sub!(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}")
          str=str.gsub(/#{Xx[:protect]}/,'')
          str
        else str
        end
        str
      end
      str
    end
    def url_with_txt(dob)
      rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
      while dob.tmp =~rgx_url_generic
        if dob.tmp=~rgx_url_generic
          if dob.tmp =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
            regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
            punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m.match(dob.tmp).captures.join
          else
            regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
            punctuate=''
          end
          z,url=regx_url.match(dob.tmp).captures if dob.tmp =~regx_url
          url=url.strip
          link=z.strip
          link.gsub!(/&/,"#{Xx[:protect]}&")
          dob.tmp.sub!(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}#{punctuate}")
          dob.tmp.gsub!(/#{Xx[:protect]}/,'')
          #dob.tmp=dob.tmp.sub(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}#{punctuate}").
          #  gsub(/#{Xx[:protect]}/,'')
          dob
        else dob
        end
        dob
      end
      dob
    end
    def urls_txt_and_images
      dob=@dob
      dir=SiSU_Env::InfoEnv.new(@md.fns)
      @dm={
        'a4'=>     @tx.a4.landscape.img_px,
        'letter'=> @tx.letter.landscape.img_px,
        'legal'=>  @tx.legal.landscape.img_px,
        'b5'=>     @tx.b5.landscape.img_px,
        'a5'=>     @tx.a5.landscape.img_px
      }
      images_hash={ }
      generic_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image\b)/m
      rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
      #url_bare_rgx=/#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
      url_image_rgx=/#{Mx[:lnk_o]}[a-zA-Z0-9_\\-]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
      image_rgx=/#{Mx[:lnk_o]}[a-zA-Z0-9_\\-]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}image/m
      @md.papersize_array.each do |ps|
        images_hash[ps] = dob.tmp
        while images_hash[ps] =~generic_rgx
          if dob.tmp =~rgx_url_generic \
          and dob.tmp !~/\.(?:png|jpg|gif)|#{Mx[:lnk_c]}image\b/m
            dob=url_with_txt(dob)
          elsif images_hash[ps]=~generic_rgx
            if dob.tmp=~rgx_url_generic
              if images_hash[ps] =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
                regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
                punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m.match(images_hash[ps]).captures.join
              else
                regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
                punctuate=''
              end
              z,url=regx_url.match(images_hash[ps]).captures if images_hash[ps] =~regx_url
              url=url.strip
            else
              if images_hash[ps] =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}image\.[^'"\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/m
                regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image\.[^'"\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/m
                punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\.[^'"\s]+?([;.,]?(?:\s|$))/m.match(images_hash[ps]).captures.join
              else
                regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/m
                punctuate=''
              end
              z=regx_url.match(images_hash[ps])[1] if images_hash[ps] =~regx_url
              url=''
            end
            if images_hash[ps] =~/#{Mx[:lnk_o]}\s*\S+\.?(?:png|jpg|gif)/m \
            and images_hash[ps]=~/\s+\d+x\d+(\s+|\s*#{Mx[:lnk_c]})/m
              image=z.scan(/\S+/)[0] #image,x,y=z.scan(/\S+/)
              image.gsub!(/\\/,'')
              w=((z =~/\s(\d+)x\d*/) ? z[/\s(\d+)x\d*/,1] : 200)
              width={}
              width['a4'] =     ((w.to_i > @dm['a4'])     ? @dm['a4'] :     w)
              width['letter'] = ((w.to_i > @dm['letter']) ? @dm['letter'] : w)
              width['legal'] =  ((w.to_i > @dm['legal'])  ? @dm['legal'] :  w)
              width['a5'] =     ((w.to_i > @dm['a5'])     ? @dm['a5'] :     w)
              width['b5'] =     ((w.to_i > @dm['b5'])     ? @dm['b5'] :     w)
              c=z[/``(.+?)''/m,1]
              hsp="\n{\\color{mywhite} .}&~\n" # ~ character for hardspace
              caption=(c ?  "{\\\\\ \n\\begin{scriptsize}#{hsp*3}#{c}\\end{scriptsize}&}" : '')
            elsif images_hash[ps] =~/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/m
              SiSU_Screen::Ansi.new(
                @md.opt.act[:color_state][:set],
                %{document built without image: "#{$1}" as image dimensions not provided (either image not found or neither imagemagick nor graphicsmagick is installed)?\n}
              ).print_grey #unless @md.opt.act[:quiet][:set]==:on
              images_hash[ps].gsub!(/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/,'[image]')
            end
            if image #most images fc etc. #% clean up !
              if FileTest.file?("#{dir.path.image_source_include}/#{image}")
                case images_hash[ps]
                when url_image_rgx
                  images_hash[ps].sub!(url_image_rgx,
                    "#{@center_begin}\\\n\\href{#{url}}\n{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include}/#{image}}}#{caption}#{@center_end}")
                when image_rgx
                  images_hash[ps].sub!(image_rgx,
                    "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include}/#{image}}#{caption}#{@center_end}")
                end
                images_hash[ps]
              elsif @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/
                pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1]
                img_src=pt + '/image'
                if FileTest.file?("#{img_src}/#{image}")
                  case images_hash[ps]
                  when url_image_rgx
                    images_hash[ps].sub!(url_image_rgx,
                      "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{img_src}/#{image}}}#{caption} #{@center_end}")
                  when image_rgx
                    images_hash[ps].sub!(image_rgx,
                      "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{img_src}/#{image}}#{caption} #{@center_end}")
                  end
                  images_hash[ps]
                end

              elsif @md.fns =~/\.(?:ssm\.)?sst$/ \
              and FileTest.file?("#{dir.path.image_source_include_local}/#{image}")
                case images_hash[ps]
                when url_image_rgx
                  images_hash[ps].sub!(url_image_rgx,
                    "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_local}/#{image}}}#{caption} #{@center_end}")
                when image_rgx
                  images_hash[ps].sub!(image_rgx,
                    "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_local}/#{image}}#{caption} #{@center_end}")
                end
                images_hash[ps]
              elsif @md.fns =~/\.-ss[tm]$/ \
              and FileTest.file?("#{dir.path.image_source_include_remote}/#{image}")
                case images_hash[ps]
                when url_image_rgx
                  images_hash[ps].sub!(url_image_rgx,
                    "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_remote}/#{image}}}#{caption}#{@center_end}")
                when image_rgx
                  images_hash[ps].sub!(image_rgx,
                    "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_remote}/#{image}}#{caption}#{@center_end}")
                end
                images_hash[ps]
              else
                SiSU_Screen::Ansi.new(
                  @md.opt.act[:color_state][:set],
                  "ERROR - image:",
                  %{"#{image}" missing},
                  "search locations: #{dir.path.image_source_include_local}, #{dir.path.image_source_include_remote} and #{dir.path.image_source_include}"
                ).error2 unless @md.opt.act[:quiet][:set]==:on
                if images_hash[ps] =~url_image_rgx \
                or images_hash[ps] =~image_rgx
                  images_hash[ps]=''
                end
                images_hash[ps]
              end
            else
              link=z.strip #[/(.+?)\\/m,1]
              images_hash[ps]="\\href{#{url}}{#{link}}#{punctuate}" if images_hash[ps] =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/
              images_hash[ps]
            end
          else images_hash[ps]
          end
          images_hash[ps] #=ocn_display(dob) + images_hash[ps]
        end #while loop
        images_hash
      end
      use_images_hash={}
      images_hash.each do |k,t|
        use_images_hash[k]={ l: t, p: t}
      end
      dob.tmp=use_images_hash
      dob
    end
    def title
      title=SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.title.full).special_characters_safe
      "\n\\title{#{title}}"
    end
    def title_landscape
      title
    end
    def title_portrait
      title
    end
  end
  class FormatHead
    require_relative 'prog_text_translation'        # prog_text_translation.rb
    def initialize(md,t_o)
      @md,@t_o=md,t_o
      @env=SiSU_Env::InfoEnv.new(@md.fns)
      if t_o.is_a?(Hash)
        @txt =t_o[:txt]            || nil
        @subtitle=t_o[:subtitle]   || nil
        @ps=t_o[:paper_size]       || nil
        @ocn=t_o[:ocn]             || nil
        @layout=t_o[:orientation]  || nil
      else
        p t_o.class
        p caller
      end
      @tx=SiSU_Env::GetInit.new.tex
      @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine
      @ps=@txt if @txt=~/(?:a4|letter|legal|book|a5|b5)/i
      @lang ||=SiSU_i18n::Languages.new #.list[@md.opt.lng][:xlp]
      @author=if defined? @md.creator.author \
      and @md.creator.author=~/\S+/
        SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.creator.author).special_characters_safe
      else ''
      end
      @subject=if defined? @md.classify.subject \
      and @md.classify.subject=~/\S+/
        SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.classify.subject).special_characters_safe
      else ''
      end
      @keywords=if defined? @md.classify.keywords \
      and @md.classify.keywords=~/\S+/
        SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.classify.keywords).special_characters_safe
      else ''
      end
    end
    def tex_head_lang #babel 18n
      lang_char_arr=@md.i18n
      mainlang_char=if @md.i18n == Array \
      and @md.i18n.length > 0
        lang_char_arr.slice(0)
      else @md.opt.lng
      end
      mainlang=@lang.list[mainlang_char][:xlp]
      otherlang=if mainlang != 'english'
        [ @lang.list['en'][:xlp] ]
      else []
      end
      if lang_char_arr.length > 0
        lang_char_arr.slice(1..9).each { |ch| otherlang << @lang.list[ch][:xlp] }
        otherlang=otherlang.uniq
      end
      otherlang=otherlang.join(',')
      { mainlang: mainlang, otherlang: otherlang }
    end
    def tex_head_encode
      texpdf_fontface=if defined? @md.make.texpdf_fontface.main \
      and not @md.make.texpdf_fontface.main.nil? \
      and @md.make.texpdf_fontface.main=~/\S{3,}/
        @md.make.texpdf_fontface.main
      else @env.font.texpdf.main
      end
      texpdf_fontface_sans=if defined? @md.make.texpdf_fontface.sans \
      and not @md.make.texpdf_fontface.sans.nil? \
      and @md.make.texpdf_fontface.sans=~/\S{3,}/                                  # not used
        @md.make.texpdf_fontface.sans
      else @env.font.texpdf.sans
      end
      texpdf_fontface_serif=if defined? @md.make.texpdf_fontface.serif \
      and not @md.make.texpdf_fontface.serif.nil? \
      and @md.make.texpdf_fontface.serif=~/\S{3,}/                                 # not used
        @md.make.texpdf_fontface.serif
      else @env.font.texpdf.serif
      end
      texpdf_fontface_mono=if defined? @md.make.texpdf_fontface.mono \
      and not @md.make.texpdf_fontface.mono.nil? \
      and @md.make.texpdf_fontface.mono=~/\S{3,}/
        @md.make.texpdf_fontface.mono
      else @env.font.texpdf.mono
      end
      texpdf_fontface_cjk=if @md.opt.lng =~/zh/ \
      and defined? @md.make.texpdf_fontface.cjk_zh \
      and not @md.make.texpdf_fontface.cjk_zh.nil? \
      and @md.make.texpdf_fontface.cjk_zh=~/\S{3,}/
        @md.make.texpdf_fontface.cjk_zh
      elsif @md.opt.lng =~/ja/ \
      and defined? @md.make.texpdf_fontface.cjk_ja \
      and not @md.make.texpdf_fontface.cjk_ja.nil? \
      and @md.make.texpdf_fontface.cjk_ja=~/\S{3,}/
        @md.make.texpdf_fontface.cjk_ja
      elsif @md.opt.lng =~/ko/ \
      and defined? @md.make.texpdf_fontface.cjk_ko \
      and not @md.make.texpdf_fontface.cjk_ko.nil? \
      and @md.make.texpdf_fontface.cjk_ko=~/\S{3,}/
        @md.make.texpdf_fontface.cjk_ko
      elsif @md.opt.lng =~/(?:zh|ja|ko)/ \
      and defined? @md.make.texpdf_fontface.cjk \
      and not @md.make.texpdf_fontface.cjk.nil? \
      and @md.make.texpdf_fontface.cjk=~/\S{3,}/
        @md.make.texpdf_fontface.cjk
      else
        case @md.opt.lng
        when /zh/ then @env.font.texpdf.cjk_zh
        when /ja/ then @env.font.texpdf.cjk_ja
        when /ko/ then @env.font.texpdf.cjk_ko
        else @env.font.texpdf.cjk
        end
      end
      # you may wish to check selected font against available fonts:
      # fc-list :outline -f "%{family}\n"
      # fc-list :lang=ja
      case @tex2pdf
      when /xe/
        if @md.opt.lng =~/(?:zh|ja|ko)/
          if @md.opt.lng =~/zh/
            <<-WOK
\\setCJKmainfont{Noto}
\\setCJKmainfont{Noto Sans CJK TC}
\\setCJKsansfont{Noto Sans CJK TC}
\\setCJKmonofont{Noto Sans Mono CJK TC}
\\setmainlanguage{#{tex_head_lang[:mainlang]}}
\\setotherlanguage{english}
% \\setmainfont{#{texpdf_fontface_cjk}}
% \\setotherfont{#{texpdf_fontface}}
\\setotherfont{Noto Sans}
% \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}}
            WOK
          elsif @md.opt.lng =~/ja/
            <<-WOK
\\setCJKmainfont{TakaoMincho}
\\setCJKsansfont{TakaoMincho Sans}
\\setCJKmonofont{TakaoMincho Sans Mono CJK JP}
%\\setCJKmainfont{Noto Serif CJK JP}
%\\setCJKsansfont{Noto Sans CJK JP}
%\\setCJKmonofont{Noto Sans Mono CJK JP}
\\setmainlanguage{#{tex_head_lang[:mainlang]}}
\\setotherlanguage{english}
% \\setmainfont{#{texpdf_fontface_cjk}}
% \\setotherfont{#{texpdf_fontface}}
\\setotherfont{Noto Sans}
% \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}}
            WOK
          elsif @md.opt.lng =~/ko/
            <<-WOK
\\setCJKmainfont{Noto}
\\setCJKmainfont{Noto Sans CJK KR}
\\setCJKsansfont{Noto Sans CJK KR}
\\setCJKmonofont{Noto Sans Mono CJK KR}
\\setmainlanguage{#{tex_head_lang[:mainlang]}}
\\setotherlanguage{english}
% \\setmainfont{#{texpdf_fontface_cjk}}
% \\setotherfont{#{texpdf_fontface}}
\\setotherfont{Noto Sans}
% \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}}
            WOK
          else puts "lang error"
          end
        elsif (tex_head_lang[:mainlang] == "english" \
        && (tex_head_lang[:otherlang] == "english" \
          || tex_head_lang[:otherlang] == "" \
          || tex_head_lang[:otherlang].length == 0))
          <<-WOK
% \\setmainlanguage{#{tex_head_lang[:mainlang]}}
% \\setmainfont{#{texpdf_fontface}}
% \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}}
          WOK
        else
          <<-WOK
% \\setmainlanguage{#{tex_head_lang[:mainlang]}}
% \\setotherlanguage{english}
% \\setmainfont{#{texpdf_fontface}}
% \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}}
          WOK
        end
      when /pdf/
        <<-WOK
\\usepackage[#{tex_head_lang[:mainlang]},#{tex_head_lang[:otherlang]}]{babel}
\\usepackage{ucs}
\\usepackage[utf8x]{inputenc} %
        WOK
      end
    end
    def tex_head_info
      generator="Generated by: #{@md.project_details.project} #{@md.project_details.version} of #{@md.project_details.date_stamp} (#{@md.project_details.date})" if @md.project_details.version
      lastdone="Last Generated on: #{Time.now}"
      rubyv="Ruby version: #{@md.ruby_version}"
      <<-WOK
%% SiSU (Linux & Ruby - \"better ways\") LaTeX output
%% #{generator}
%% #{rubyv}
%% LaTeX output
%% #{lastdone}
%% SiSU https://git.sisudoc.org/
      WOK
    end
    def tex_head_paper_characters
       if @md.opt.lng =~/(?:zh|ja|ko)/
         <<-WOK
\\renewcommand*\\familydefault{\\sfdefault}
\\usepackage[UTF8, fontset=TakaoMincho]{ctex}
%\\usepackage[UTF8, fontset=Takao明朝]{ctex}
%\\usepackage[UTF8, fontset=none]{ctex}
\\usepackage{ctexhook}
\\usepackage[T1]{fontenc}
\\usepackage{newunicodechar}
\\usepackage[utf8]{inputenc}
         WOK
       else
         <<-WOK
% \\usepackage[scaled]{dejavu}
\\renewcommand*\\familydefault{\\sfdefault}
%\\usepackage{inconsolata}
\\usepackage[T1]{fontenc}
\\usepackage{newunicodechar}
\\usepackage[utf8]{inputenc}
         WOK
       end
    end
    def tex_head_paper_shared
      <<-WOK
\\usepackage{alltt}
\\usepackage[
  unicode=true,
  pdfusetitle,
  pdfsubject={},
  pdfkeywords={},         % keywords list {} {} {},
  pdftoolbar=true,
  pdfmenubar=true,
  pdfwindowui=true,
  pdffitwindow=false,     % window fit to page when opened
  pdfstartview={FitH},    % fits the width of the page to the window
  pdfnewwindow=true,      % links in new window
  pdfborder={0 0 1},
  plainpages=false,       % was true
  bookmarks=true,
  bookmarksopen=false,
  bookmarksnumbered=false,
  backref=false,
  breaklinks=false,
  colorlinks=true,
  urlcolor=black,
  filecolor=black,
  linkcolor=black,
  citecolor=black,        % links_mono_or_color_set
]{hyperref}
\\PassOptionsToPackage{hyphens}{url}\\usepackage{hyperref}
\\usepackage[usenames]{color}
\\definecolor{myblack}{rgb}{0,0,0}
\\definecolor{myred}{rgb}{0.75,0,0}
\\definecolor{mygreen}{rgb}{0,0.5,0}
\\definecolor{myblue}{rgb}{0,0,0.5}
\\definecolor{mywhite}{rgb}{1,1,1}
\\usepackage{textcomp}
\\usepackage[parfill]{parskip}
\\usepackage[normalem]{ulem}
\\usepackage{soul}
\\usepackage{longtable}
\\usepackage{graphicx}
\\usepackage[tc]{titlepic}
\\usepackage{amssymb}
\\usepackage{amsmath}
\\usepackage[cm]{sfmath}
\\usepackage{underscore}
\\usepackage{listings}
\\setcounter{secnumdepth}{2}
\\setcounter{tocdepth}{4}
\\usepackage{bookmark}
\\usepackage{microtype}
\\makeatletter
\\usepackage[multiple,ragged]{footmisc}
\\setlength\\footnotemargin{12pt}
\\usepackage[para]{manyfoot}
\\DeclareNewFootnote{A}
\\makeatother
\\chardef\\txtbullet="2022
\\chardef\\tilde="7E
\\def\\asterisk{{\\rm \\char42} }
\\definecolor{Light}{gray}{.92}
\\definecolor{listinggray}{gray}{0.9}
\\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\\lstset{%
  backgroundcolor=\\color{lbcolor},
  tabsize=4,
  rulecolor=,
  language=,
  basicstyle={\\ttfamily\\scriptsize},
  upquote=true,
  columns=fixed,
  showstringspaces=false,
  extendedchars=true,
  breaklines=true,
  prebreak = \\raisebox{0ex}[0ex][0ex]{\\ensuremath{\\hookleftarrow}},
  frame=single,
  showtabs=false,
  showspaces=false,
  showstringspaces=false,
  identifierstyle=\\ttfamily,
  keywordstyle=\\color[rgb]{0,0,1},
  commentstyle=\\color[rgb]{0.133,0.545,0.133},
  stringstyle=\\color[rgb]{0.627,0.126,0.941},
}
\\DeclareTOCStyleEntry[numwidth+=8pt]{part}{part}
\\DeclareTOCStyleEntry[numwidth+=4pt]{section}{section}
\\DeclareTOCStyleEntry[numwidth+=3pt]{section}{paragraph}
\\DeclareTOCStyleEntry[numwidth+=3pt]{section}{subparagraph}
\\DeclareTOCStyleEntry[numwidth+=3pt]{section}{subsection}
\\DeclareTOCStyleEntries[indent+=4pt]{section}{section,subsection,subsubsection}
\\DeclareTOCStyleEntries[numwidth+=3pt]{section}{paragraph,subparagraph}
\\usepackage{ltxcmds}
      WOK
    end
    def tex_head_paper_newenv_newcmd
      <<-WOK
\\newenvironment{ParagraphIndent}[1]{%
  \\begin{list}{}{%
    \\setlength\\topsep{0pt}%
    \\addtolength{\\leftmargin}{#1}
    \\setlength\\parsep{0pt plus 1pt}%
  }
  \\item[]
} {\\end{list}}
\\newenvironment{ParagraphHang}[2]{%
  \\begin{list}{}{%
    \\setlength\\topsep{0pt}%
    \\addtolength{\\leftmargin}{#1}
    \\itemindent=#2
    \\setlength\\parsep{0pt plus 1pt}%
  }
  \\item[]
} {\\end{list}}
\\newenvironment{Bullet}[1]{%
  \\begin{list}{}{%
    \\setlength\\topsep{0pt}%
    \\addtolength{\\leftmargin}{#1}
    \\itemindent=-1em
    \\setlength\\parsep{0pt plus 1pt}%
  }
  \\item[]
  $\\txtbullet$\\hspace{\\enspace}
} {\\end{list}}
\\newcommand{\\monosp}[1]{\\normaltext\\ttfamily\\texbackslash#1}
\\newcommand{\\br}{\\hfill\\break}
\\newcommand{\\brl}[1]{%
  \\ifx&#1&%
    \\hfill\\break
  \\else
    \\vspace{#1ex}
  \\fi
}
\\newcommand{\\brln}{\\hspace*{\\fill}\\linebreak}
\\newcommand{\\objBlockOpen}{%
  \\setlength{\\parskip}{0.5ex plus0.2ex minus0.1ex}\\raggedright
  \\begin{footnotesize}
}
\\newcommand{\\objBlockClose}{%
  \\end{footnotesize}
  \\setlength{\\parskip}{1ex plus0.5ex minus0.2ex}
}
\\newcommand{\\objGroupOpen}{%
  \\setlength{\\parskip}{0.5ex plus0.2ex minus0.1ex}
  \\begin{footnotesize}
}
\\newcommand{\\objGroupClose}{%
  \\end{footnotesize}
}
\\newcommand{\\objPoemVerseOpen}{%
  \\setlength{\\parskip}{0.1ex plus0.1ex minus0.1ex}
  \\begin{footnotesize}

}
\\newcommand{\\objPoemVerseClose}{%

  \\end{footnotesize}
  \\setlength{\\parskip}{1ex plus0.5ex minus0.2ex}
  \\linebreak
}
\\newcommand{\\parasep}{%
  \\smallskip \\begin{center}*\\hspace{2em}*\\hspace{2em}*\\end{center} \\br
}
\\newcommand{\\spaces}[1]{{\\hspace*{#1ex}}}
\\newcommand{\\s}{\\hspace*{1ex}}
\\newcommand{\\hardspace}{\\hspace*{1ex}}
\\newcommand{\\-}{\\hspace*{1ex}}
\\newcommand{\\caret}{{\\^{~}}}
\\newcommand{\\pipe}{{\\textbar}}
\\newcommand{\\curlyOpen}{{}
\\newcommand{\\curlyClose}{}}
\\newcommand{\\lt}{{UseTextSymbol{OML}{<}}}
\\newcommand{\\gt}{{UseTextSymbol{OML}{>}}}
\\newcommand{\\slash}{{/}}
\\newcommand{\\underscore}{\\_}
\\newcommand{\\exclaim}{\\Verbatim{!}}
\\newcommand{\\linktext}[2]{%
  {\\href{#1}
  {\\;\\ulcorner\\,\\textup{{#2}}\\,\\lrcorner}}
}
\\newcommand{\\linkurl}[2]{%
  \\;{\\href{#1}
  {\\;\\scriptsize\\ttfamily\\ulcorner\\,\\textup{{#2}}\\,\\lrcorner}}
}
\\newcommand{\\link}[2]{%
  {\\begin{scriptsize}\\color{black}\\urlstyle{tt}\\href{#1}
  {\\;\\ulcorner\\,{#2}\\,\\lrcorner}\\end{scriptsize}}
}
\\newcommand{\\objCodeBlock}[1]{\\normaltext\\raggedright\\small\\ttfamily\\texbackslash#1}
\\newcommand{\\objCodeOpen}{%
  \\normaltext\\raggedright\\small\\ttfamily\\texbackslash
  \\begin{lstlisting}
}
\\newcommand{\\objCodeClose}{%
  \\end{lstlisting}
}
\\newcommand{\\ocn}[1]{%
  \\setlength{\\parindent}{0em}
  \\ifx&#1&% #1 is empty
    \\hspace{-0.5ex}{\\marginpar{\\begin{tiny}\\end{tiny}}}
  \\else% #1 is nonempty
    \\hspace{-0.5ex}{\\marginpar{\\begin{tiny}\\hspace{0em}\\hypertarget{#1}{#1}\\end{tiny}}}
  \\fi
}
\\newcommand{\\ocnhold}[1]{%
  \\begin{tiny}\\hspace{0mm}\\end{tiny}{\\marginpar{\\begin{tiny}\\hspace{0mm}\\hypertarget{#1}{#1}\\end{tiny}}}
}
\\newcommand{\\objCodeBlockHold}[1]{\\normaltext\\raggedright\\small\\ttfamily\\texbackslash#1}
\\newcommand{\\objTableOpen}[1]{%
  \\setlength{\\LTleft}{0pt}
  \\setlength{\\LTright}{\\fill}
  \\begin{tiny}
  \\begin{longtable}{#1}
}
\\newcommand{\\objTableClose}{%
  \\end{longtable}
  \\end{tiny}
}
      WOK
    end
    def tex_head_paper_orient(orientation)
      colorlinks = <<-WOK
  colorlinks=true,    % myblack
  urlcolor=myblue,    % \\href{...}{...}   external url
  filecolor=mygreen,  % \\href{...}        local file
  linkcolor=myred,    % \\href{...} and \\pageref{...}
      WOK
      colorlinks = (orientation == "landscape") ? colorlinks : ""
      <<-WOK
\\usepackage[#{tex_head_lang[:mainlang]},#{tex_head_lang[:otherlang]}]{babel}
\\usepackage[autostyle, english = american]{csquotes}
% \\MakeOuterQuote{"} % not required, using '' as quote delimiter
\\selectlanguage{#{tex_head_lang[:mainlang]}}
\\hypersetup{
  pdftitle={#{@md.title.short}},
  pdfauthor={#{@md.creator.author}},
  pdfsubject={},
#{colorlinks}
}
\\usepackage{fancyhdr}
\\lhead[ ]{ }
\\chead[ \\fancyplain{} \\bfseries \\footnotesize \\leftmark ]{ \\fancyplain{} \\bfseries \\footnotesize \\rightmark }
\\rhead[ ]{ }
\\lfoot[\\textrm{\\thepage}]{\\tiny \\href{https://sisudoc.org}{SiSU}}
    \\cfoot{\\href{https://git.sisudoc.org}{git}}
\\rfoot[\\tiny \\href{}{}]{\\textrm{\\thepage}}
\\begin{document}
\\thispagestyle{empty}
\\title{#{@md.title.full}}
\\author{ \\textnormal{#{@md.creator.author}}}
\\date{\\begin{tiny}2015-08-23\\end{tiny}}
\\maketitle
\\addcontentsline{toc}{part}{#{@md.title.full}}
\\newpage
\\pagestyle{fancy}
\\pagenumbering{alph}
\\setcounter{page}{1}
      WOK
    end
    def tex_head_paper_portrait(d)
      multicol=(@md.book_idx ? '\usepackage{multicol}' : '')
      <<-WOK
#{tex_head_info}
\\documentclass[11pt,a4paper,titlepage,makeidx]{scrartcl}
\\usepackage{fontspec}
% \\usepackage{lmodern} %%issue remove for now (consider later)
\\usepackage{geometry}
\\geometry{%
  #{d[:papertype]},
  portrait,
  left=#{d[:left]},
  right=#{d[:right]},
  top=#{d[:top]},
  bottom=#{d[:bottom]},
}
% \\ProvidesPackage{./sty/spineShared}
\\usepackage{multicol}
\\setlength{\\marginparsep}{#{d[:marginparsep]}}
\\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
#{tex_head_paper_characters}
#{tex_head_paper_shared}
#{tex_head_paper_newenv_newcmd}
#{tex_head_paper_orient("portrait")}
#{multicol}
      WOK
    end
    def tex_head_paper_landscape(d)
      <<-WOK
#{tex_head_info}
\\documentclass[11pt,a4paper,landscape,titlepage,twocolumn,makeidx]{scrartcl}
\\usepackage{geometry}
\\geometry{%
  #{d[:papertype]},
  landscape,
  left=#{d[:left]},
  right=#{d[:right]},
  top=#{d[:top]},
  bottom=#{d[:bottom]},
}
\\usepackage{multicol}
\\setlength{\\marginparsep}{#{d[:marginparsep]}}
\\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
#{tex_head_paper_characters}
#{tex_head_paper_shared}
#{tex_head_paper_newenv_newcmd}
#{tex_head_paper_orient("landscape")}
      WOK
    end
    def tex_head_paper_portrait_dvi(d)
      <<-WOK
#{tex_head_info}
\\documentclass[#{d[:fontsize]},#{d[:papertype]},titlepage]{scrartcl}      %with titlepage
\\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm}
\\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}}
\\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}}
\\setlength{\\headsep}{#{d[:headsep]}}
\\setlength{\\marginparsep}{#{d[:marginparsep]}}
\\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
      WOK
    end
    def tex_head_paper_dimensions
      d={}
      fontsize_set=if defined? @env.font.texpdf.size(@md.opt.act[:pdf_font_size]) \
      and not @env.font.texpdf.size(@md.opt.act[:pdf_font_size]).nil?
        @env.font.texpdf.size(@md.opt.act[:pdf_font_size])
      else :na
      end
      case @layout
      when :portrait
        fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
        d[:papertype],d[:fontsize]='a4paper',fontsize
        d[:left],d[:right]='30mm','20mm'
        d[:top],d[:bottom]='30mm','30mm'
        d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='0mm','0mm','-12pt'
        d[:headheight],d[:headsep],d[:columnsep]='12pt','35pt',''
        d[:marginparsep],d[:marginparwidth]='4mm','8mm'
        case @ps #@md.papersize
        when /a4/i           #European default, SiSU default
          fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize]='a4paper',fontsize
          d[:textheight],d[:textwidth]=@tx.a4.portrait.h,@tx.a4.portrait.w
        when /letter/i   #U.S. default
          fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize]='letterpaper',fontsize
          d[:textheight],d[:textwidth]=@tx.letter.portrait.h,@tx.letter.portrait.w
        when /legal/i     #U.S. alternative
          fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize]='legalpaper',fontsize
          d[:textheight],d[:textwidth]=@tx.legal.portrait.h,@tx.legal.portrait.w
        when /book|b5/i   #book default - larger
          fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize]='b5paper',fontsize
          d[:left],d[:right]='20mm','20mm'
          d[:top],d[:bottom]='20mm','20mm'
          d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='-4mm','-4mm','-36pt'
          d[:headheight],d[:headsep],d[:columnsep]='12pt','20pt',''
          d[:textheight],d[:textwidth]=@tx.b5.portrait.h,@tx.b5.portrait.w
        when /a5/i
          fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize]='a5paper',fontsize
          d[:left],d[:right]='20mm','20mm'
          d[:top],d[:bottom]='20mm','20mm'
          d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='-4mm','-4mm','-36pt'
          d[:headheight],d[:headsep],d[:columnsep]='11pt','12pt',''
          d[:marginparsep],d[:marginparwidth]='4mm','6mm'
          d[:textheight],d[:textwidth]=@tx.a5.portrait.h,@tx.a5.portrait.w
        else           #default currently A4
          fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize]='a4paper',fontsize
          d[:textheight],d[:textwidth]=@tx.a4.portrait.h,@tx.a4.portrait.w
        end
      when :landscape
        fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
        d[:papertype],d[:fontsize]='a4paper',fontsize
        d[:left],d[:right]='30mm','20mm'
        d[:top],d[:bottom]='30mm','30mm'
        d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='6mm','6mm','-12mm'
        d[:headheight],d[:headsep],d[:columnsep]='12pt','20pt','40pt'
        d[:marginparsep],d[:marginparwidth]='4mm','8mm'
        case @ps #@md.papersize
        when /a4/i                            #European default, SiSU default
          fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize]='a4paper',fontsize
          d[:textheight],d[:textwidth]=@tx.a4.landscape.h,@tx.a4.landscape.w
        when /letter/i                    #U.S. default
          fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize]='letterpaper',fontsize
          d[:textheight],d[:textwidth]=@tx.letter.landscape.h,@tx.letter.landscape.w
        when /legal/i #U.S. alternative
          fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize],d[:columnsep]='legalpaper',fontsize,'48pt'
          d[:textheight],d[:textwidth]=@tx.legal.landscape.h,@tx.legal.landscape.w
        when /book|b5/i       #book default - larger
          fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize],d[:columnsep]='b5paper',fontsize,'35pt'
          d[:left],d[:right]='25mm','25mm'
          d[:top],d[:bottom]='20mm','20mm'
          d[:textheight],d[:textwidth]=@tx.b5.landscape.h,@tx.b5.landscape.w
        when /a5/i
          fontsize=(fontsize_set==:na) ? '10pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize],d[:columnsep]='a5paper',fontsize,'32pt'
          d[:left],d[:right]='25mm','25mm'
          d[:top],d[:bottom]='20mm','20mm'
          d[:textheight],d[:textwidth]=@tx.a5.landscape.h,@tx.a5.landscape.w
        else                            #default currently A4
          fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
          d[:papertype],d[:fontsize]='a4paper',fontsize
          d[:textheight],d[:textwidth]=@tx.a4.landscape.h,@tx.a4.landscape.w
        end
      end
      d
    end
    def tex_head_paper
      case @layout
      when :portrait
        tex_head_paper_portrait(tex_head_paper_dimensions)
      when :landscape
        tex_head_paper_landscape(tex_head_paper_dimensions)
      end
    end
    def hyperlinks_monochrome
      <<-WOK
  colorlinks=true,
  urlcolor=myblack,
  filecolor=myblack,
  linkcolor=myblack,
      WOK
    end
    def hyperlinks_colored
      <<-WOK
  colorlinks=true,
  urlcolor=myblue,    % \\href{...}{...}   external url
  filecolor=mygreen,  % \\href{...}        local file
  linkcolor=myred,    % \\href{...} and \\pageref{...}
      WOK
    end
    def hyperlinks_color?
      case @layout
      when :portrait  then hyperlinks_monochrome
        if @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).portrait != :na
          case @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).portrait
          when :color then hyperlinks_colored
          when :mono  then hyperlinks_monochrome
          else p __LINE__.to_s + ':error'
          end
        else               hyperlinks_monochrome
        end
      when :landscape
        if @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).landscape != :na
          case @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).landscape
          when :color then hyperlinks_colored
          when :mono  then hyperlinks_monochrome
          else p __LINE__.to_s + ':error'
          end
        else               hyperlinks_colored
        end
      end
    end
    def tex_head_pdftex
      author=if defined? @md.creator.author \
      and @md.creator.author=~/\S+/
        SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.creator.author).special_characters_safe_no_urls
      else ''
      end
      <<-WOK
        WOK
    end
    def tex_head_codeblock(codeblock_box_type)
      codeblock_box=if codeblock_box_type=='listings'
        <<-WOK
% \\usepackage{listings}
% \\usepackage{color}
% \\usepackage{textcomp}
        WOK
      elsif codeblock_box_type=='boites'
        "\\usepackage{boites}"
      else
        "\\usepackage{boites}"
      end
      codeblock_box
    end
    def document_head_with_orientation(codeblock_box_type)
      endnotes=("\\usepackage{endnotes}" if @txt =~/endnotes?/) || '' #not implemented see also def endnotes
      @lang.list[@md.i18n[0]][:xlp]
      <<-WOK
#{tex_head_paper}
#{tex_head_encode}
#{tex_head_pdftex}
#{tex_head_codeblock(codeblock_box_type)}
% \\selectlanguage{#{tex_head_lang[:mainlang]}}
      WOK
    end
    def a4generic
    end
  end
  class SpecialCharacters
    include SiSU_Parts_TeXpdf
    def initialize(md,str,is=:default)
      @md,@txt,@is=md,str,is
      @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine
    end
    def xetex_code_listings(str,is=:default)                                 # ~ ^ $ & % _ { }  #LaTeX special characters - KEEP list
      word=str.scan(/\S+|\n/) #unless line =~/^(?:@\S|%+\s)/
      para_array=[]
      str=if word
        word.each do |w| # _ - / # | : ! ^ ~
          w=w.gsub(/#{Mx[:gl_o]}#lt#{Mx[:gl_c]}/,'<').gsub(/#{Mx[:gl_o]}#gt#{Mx[:gl_c]}/,'>').
            gsub(/[\\]?~/,'~').
            gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,"\n").              #watch
            gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~').                #126 usual
            gsub(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|')                   #unless is=='code' #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX
          para_array << w
        end
        str=para_array.join(' ')
        str=str.strip unless is==:code
        str
      else ''
      end
      str=str.gsub(/\s*#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}\s*/,' ').
        gsub(/.+?<-#>/,'').
        gsub(/#{Mx[:br_eof]}/,'').
        gsub(/#{Mx[:br_endnotes]}/,'').
      #problem sequence ->
        gsub(/&(?:lt|#060);/,'<').                                           # < SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'>').                     # > SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{').                            # { SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}').                            # } SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~').                    # ~ SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#').                            # SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!').                            # ! SiSU not really special sisu character but done, also LaTeX
       #gsub(/(^|\s)\*\s/,'\1\asterisk ').                                   # * should you wish to escape astrisk e.g. describing \*{bold}*
        gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*').                            # * should you wish to escape astrisk e.g. describing \*{bold}*
        gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-').                            # - SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+').                            # + SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,',').                            # + SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'&').                            #unless @txt=~/<:code>/  # / SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/').                            # / SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\').                           # \ SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_').                            # _ SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|').                            # | SiSU not really special sisu character but done, also LaTeX
        gsub(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':').                            # : SiSU not really special sisu character but done, also LaTeX
        gsub(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'^').                         # ^ SiSU not really special sisu character but done, also LaTeX
      ##watch placement, problem sequence ^
        gsub(/<sup><font face=symbol>&atild;<\/font><\/sup>/,' ').
        gsub(/\\copy(right|mark)?/,'<=copymark>')                            # ok problem with superscript
    end
    def xetex_special_characters_1(str,is=:default)                          # ~ ^ $ & % _ { }  #LaTeX special characters - KEEP list
      word=str.scan(/\S+|\n/) #unless line =~/^(?:@\S|%+\s)/
      para_array=[]
      str=if word
        word.each do |w| # _ - / # | : ! ^ ~
          if w !~/https?:/ \
          and w=~/\/\S+?\// \
          and w.length > 6
            w=w.gsub(/([_.\/])/,'\1\-')
          end
          w=w.gsub(/#{Mx[:gl_o]}#lt#{Mx[:gl_c]}/,'<').gsub(/#{Mx[:gl_o]}#gt#{Mx[:gl_c]}/,'>').
            gsub(/[\\]?~/,'<=tilde>').
            gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,' \newline ').      #watch
            gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>').         #126 usual
            gsub(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'\pipe')               #unless is=='code' #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX
          if w !~/#{Mx[:rel_o]}/ \
          and w !~/#{Mx[:gl_o]}#/
            w=w.gsub(/\#/,'<=hash>')
          end
          para_array << w
        end
        str=para_array.join(' ')
        str=str.strip unless is==:code
        str
      else ''
      end
      str=str.gsub(/\s*#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}\s*/,' ').
        gsub(/.+?<-#>/,'').
        gsub(/#{Mx[:br_eof]}/,'').
        gsub(/#{Mx[:br_endnotes]}/,'')
      #problem sequence ->
      str=str.gsub(/&(?:nbsp);|#{Mx[:nbsp]}/,'\hardspace') unless is==:code  # < SiSU special character also LaTeX
      str=str.gsub(/&(?:lt|#060);/,'\lt').                                   # < SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'\gt').                   # > SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'\curlyopen').                   # { SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'\curlyclose').                  # } SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>').             # ~ SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'\#').                           # # SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!').                            # ! SiSU not really special sisu character but done, also LaTeX
        gsub(/(^|\s)\*\s/,'\1\asterisk ').                                   # * should you wish to escape astrisk e.g. describing \*{bold}*
        gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'\*').                           # * should you wish to escape astrisk e.g. describing \*{bold}*
        gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-').                            # - SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+').                            # + SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,',').                            # + SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'<=amp>'). #unless @txt=~/<:code>/  # / SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'\slash').                       # / SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\textbackslash').               # \ SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'<=underscore>').                # _ SiSU special character also LaTeX
        gsub(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|').                            # | SiSU not really special sisu character but done, also LaTeX
        gsub(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':').                            # : SiSU not really special sisu character but done, also LaTeX
        gsub(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'\caret').                    # ^ SiSU not really special sisu character but done, also LaTeX
      ##watch placement, problem sequence ^
        gsub(/<sup><font face=symbol>&atild;<\/font><\/sup>/,' ').
        gsub(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript
    end
    def xetex_special_characters_2(str,is=:default)
      str=str.gsub(/#{Mx[:gl_o]}#156#{Mx[:gl_c]}/,'\oe ').
        gsub(/\$/,'\$').
        gsub(/\#/,'\#').
        gsub(/\%/,'\%').
        gsub(/\~/,'\~') #revist, should not be necessary to mark remaining tildes
      if str !~/^\s*#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\s/
        str=str.gsub(/_/,'\_')
      end
      str=str.gsub(/\{/,'\{').
        gsub(/\}/,'\}')
      str=if is==:code
        str.gsub(/&/,'{\\\&}').
          gsub(/\\~(\\\{)/,'{$\tilde$}\1').
          gsub(/(\\\})\\~/,'\1{$\tilde$}').
          gsub(/\\~(\[)/,'{$\tilde$}\1').
          gsub(/(\])\\~/,'\1{$\tilde$}').
          gsub(/<=tilde>/,'{$\tilde$}').
          gsub(/<=hash>/,'{\#}')
      else
        str.gsub(/&nbsp;|#{Mx[:nbsp]}/,'~'). # ~ character for hardspace
          gsub(/&/,'<=amp>')
      end
      str=str.gsub(/&\S+?;/,' ').
        gsub(/§/u,'\S'). #latex: space between next character not preserved? #str.gsub(/§ /,'\S ')
        gsub(/£/u,'\pounds').
        gsub(/<a href=".+?">/,' ').
        gsub(/<\/a>/,' ')
      unless is==:no_urls
        str=str.gsub(/((?:^|\s)#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
            '\1\begin{scriptsize}\url{\2}\end{scriptsize}\3'). #special case \{ e.g. \}http://url
          gsub(/#{Mx[:url_o]}\\_(\S+?)#{Mx[:url_c]}/,
            '\begin{scriptsize}\url{\1}\end{scriptsize}'). #special case \{ e.g. \}http://url
          gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,
            '\begin{scriptsize}\\url{\1}\end{scriptsize}') #specially escaped url no decoration
      end
      if is !=:code \
      and is !=:no_urls
        str=str.gsub(/(^|#{Mx[:gl_c]}|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"\s]+?)([;.,]?(?=\s|$))/,
          "\\1#{url_decoration.tex_open}\\begin{scriptsize}\\url{\\2}\\end{scriptsize}#{url_decoration.tex_close}\\3") #url matching with decoration <url> positive lookahead, sequence issue with { linked }http://url cannot use \b at start
      end
      str=str.gsub(/<:ee>/,'').
        gsub(/<!>/,' ').  #proposed change, insert, but may be redundant
        gsub(/<(br|p)>|<\/\s*(br|p)>|<(br|p)\s*\/>/," #{Tex[:backslash]*2} "). # Work Area
        gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\begin{bfseries}\1 \end{bfseries}').
        gsub(/<h\d+>(.+?)<\/h\d+>/,'\begin{bfseries}\1 \end{bfseries}').
        gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\emph{\1}').
        gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\uline{\1}'). # ulem
        gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,"``\\1''"). # quote #CHECK
        gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\uline{\1}'). # ulem
        gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\sout{\1}'). # ulem
        gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,"\$^{\\textrm{\\1}}\$").
        gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,"\$_{\\textrm{\\1}}\$").
        gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\begin{monosp}\1\end{monosp}')
      unless is==:code
        str=str.gsub(/"(.+?)"/,'“\1”').  # quote marks / quotations open & close " need condition exclude for code
          gsub(/\s+"/,' “').                                # open "
          gsub(/^(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*"/,'\1“'). #fix Mx[:lv_o] # open "
          gsub(/"(\s|\.|,|:|;)/,'”\1').                     # close "
          gsub(/"(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*$/,'”\1'). #fix Mx[:lv_o] # close "
          gsub(/"(\.|,)/,'”').                              # close "
          gsub(/\s+'/,' `').                                # open '
          gsub(/^(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*'/,'\1`') #fix Mx[:lv_o] # open '
      end
      str=str.gsub(/(<font.*?>|<\/font>)/,'').
        gsub(/\s*#{Mx[:fa_superscript_o]}(\S+?)#{Mx[:fa_superscript_c]}/,'^\1')
      str
    end
    def xetex_special_characters_3(str)
      str=str.gsub(/<br(\s*[^\/][^>])/,'\1'). # clean up, incredibly messy :-( footnote indents, problems if match exists in ordinary paragraphs? check! Work Area 200501 a bit tricky as must be able to match multiple times, and to clean remainder
        gsub(/([^<][^b][^r]\s+)\/>/,'\1') # clean up, incredibly messy :-( footnote indents, problems if match exists in ordinary paragraphs? check! Work Area 200501 a bit tricky as must be able to match multiple times, and to clean remainder
      while str =~/(https?:\/\/\S+?)(?:<=tilde>\S+)+/ #tilde in urls \href treated differently from text #FIX
        str=str.gsub(/(https?:\/\/\S+?)(?:<=tilde>(\S+))+/,'\1~\2')
      end
      str=str.gsub(/<=tilde>/,'{$\tilde$}').
        gsub(/(https?:\/\/\S+?)(?:(?:<=hash>)(\S+))+/,'\1#\2'). #hash in urls \href treated differently from text #FIX
        gsub(/<=hash>/,'{\#}')
      while str =~/(https?:\/\/\S+?)(?:<=amp>\S+)+/ #amp in urls \href treated differently from text #FIX
        str=str.gsub(/(https?:\/\/\S+?)(?:<=amp>(\S+))+/,'\1&\2')
      end
      str=str.gsub(/<=amp>/,'{\\\&}'). #changed ... 2005
        gsub(/<=copymark>\s*(.+)/,
          '^\copyright \textnormal{\1} \2') # watch likely to be problematic
      str
    end
    def special_characters_safe_close(str)
      str=str.gsub(/<=tilde>/,'{$\tilde$}').
        gsub(/<=hash>/,'{\#}').
        gsub(/<=amp>/,'{\\\&}'). #changed ... 2005
        gsub(/<=copymark>\s*(.+)/,
          '^\copyright \textnormal{\1} \2') # watch likely to be problematic
    end
    def special_characters_code_fix(str)
      str=str.gsub(/<=tilde>/,'{$\tilde$}')
      str
    end
    def special_characters_unsafe_1(str) #depreciated, make obsolete
      # some substitutions are sequence sensitive, rearrange with care.
      str=str.gsub(/\\textbackslash (copyright|clearpage|newpage)/,"\\\\\\1")  #kludge bad solution, find out where tail is sent through specChar !
      str
    end
    def special_characters                                                   # special characters - some substitutions are sequence sensitive, rearrange with care
      str,is=@txt,@is
      str=xetex_special_characters_1(str,is) unless str.nil?
      str=special_characters_unsafe_1(str) unless str.nil? #xetex_special_characters_unsafe_1(@txt)
      str=xetex_special_characters_2(str,is) unless str.nil? #issues with xetex
      str=xetex_special_characters_3(str) unless str.nil?
      @txt=str
    end
    def special_word_break_points
      str=@txt
      str=str.gsub(/([_,.;:\/|=])/,'\1\-').
        gsub(/(--)(\S{4,})/,'\1\-\2')
      @txt=str
    end
    def special_number_break_points
      str=@txt
      str=str.gsub(/([0-9a-f]{8})/i,'\1\-')
      @txt=str
    end
    def special_characters_safe                                              # special characters - some substitutions are sequence sensitive, rearrange with care
      str,is=@txt,@is
      str=xetex_special_characters_1(str,is) unless str.nil?
      str=xetex_special_characters_2(str,is) unless str.nil?                 # remove this to start with, causes issues
      str=special_characters_safe_close(str) unless str.nil?
      @txt=str
    end
    def special_characters_safe_no_urls
      str,is=@txt,:no_urls
      str=xetex_special_characters_1(str,is) unless str.nil?
      str=xetex_special_characters_2(str,is) unless str.nil? # remove this to start with, causes issues
      str=special_characters_safe_close(str) unless str.nil?
      @txt=str
    end
    def characters_code_listings                                             # special characters - some substitutions are sequence sensitive, rearrange with care
      str,is=@txt,@is
      str=xetex_code_listings(str,is) unless str.nil?
      @txt=str
    end
    def special_characters_code
      str=@txt
      str=str.gsub(/ \\\\([ #{Mx[:br_nl]}]+|$)/,' \textbackslash\textbackslash\hardspace\1')
      str
    end
  end
  class UseTeX
    include SiSU_Parts_TeXpdf
    attr_accessor :url,:txt,:date
    def initialize(md)
      @md=md
      @date=SiSU_Env::InfoDate.new # #{@date.year}
      @copymark='{\\begin{footnotesize}\\raisebox{1ex}{\\copyright}\\end{footnotesize}}'
    end
    def skip
      "\n\\vspace*{\\smallskipamount} \n"
    end
    def paraskip_normal
      '\setlength{\parskip}{1ex plus0.5ex minus0.2ex}'
    end
    def paraskip_small
      '\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}'
    end
    def paraskip_tiny
      '\setlength{\parskip}{0.1ex plus0.1ex minus0.1ex}'
    end
    def skip_small
      "\\smallskip{}"
    end
    def skip_small_vspace
      "\n\\vspace*{\\smallskipamount} \n"
    end
    def skip_small_footnote
    end
    def skip_medium
      "\n\\medskip{}\n\n"
    end
    def skip_dummy
      "\n"
    end
    def header
      ""
    end
    def footer
      "\\lfoot[\\textrm{\\thepage}]{\\tiny \\href{#{@md.footer_links[:left][:url]}}{#{@md.footer_links[:left][:say]}}}\n" +
      "\\cfoot{\\href{#{@md.footer_links[:center][:url]}}{#{@md.footer_links[:center][:say]}}}\n" +
      "\\rfoot[\\tiny \\href{}{}]{\\textrm{\\thepage}}\n"
    end
    def site
      if not the_url.home.empty? \
      and not the_url.home_txt.empty?
        "\n\\date{\\begin{tiny} \\end{tiny}}"
      else ''
      end
    end
    def owner_chapter
      "Contact Details for Original Promulgating Authority"
    end
    #BOOK standard dimensions - 229x156
    def newpage(orientation)
      case orientation
      when :landscape # using longtable latex package
        <<-WOK
\\clearpage
        WOK
      when :portrait
        <<-WOK
\\newpage
        WOK
      end
    end
    def sisu_rights
      v=SiSU_Env::InfoVersion.instance.get_version
      base_prog_txt=if @md.base_program
        case @md.base_program
        when /kdissert/i then "\n\\\\ This document prepared using \\href{http://freehackers.org/~tnagy/kdissert/}{Kdissert \\ http://freehackers.org/~tnagy/kdissert/ } \\\\ Kdissert is Document Mapping software by Thomas Nagy"
        else ''
        end
      else ''
      end
      <<-WOK
\\\\ ~
{\\begin{footnotesize}#{base_prog_txt}
\\\\ Generated by \\href{https://git.sisudoc.org/}{SiSU} \\begin{tiny}[ #{v.project} #{v.version} of #{v.date_stamp} ]\\end{tiny} \\href{https://git.sisudoc.org/}{git.sisudoc.org}
\\\\ Copyright #{@copymark} 1997, current #{@date.year_static} Ralph Amissah, All Rights Reserved.
\\\\ SiSU is software for document structuring, publishing and search (with object citation numbering), \\href{http://www.sisudoc.org}{www.sisudoc.org}
\\\\ SiSU is released under \\href{http://www.fsf.org/licenses/gpl.html}{GPL 3 } or later, #{url_brace.tex_open}\\href{http://www.fsf.org/licenses/gpl.html}{http://www.fsf.org/licenses/gpl.html}#{url_brace.tex_close}.
{\\end{footnotesize}
\\\\
      WOK
    end
    def doc_sc_info_footnote_full
      <<-WOK
\\footnote{%\nGenerated by \\href{https://git.sisudoc.org/}{SiSU \\ git.sisudoc.org }\\ \\newline \\scriptsize{Document version information: \\emph{sourcefile} \\uline{#{@md.fnstex}}; \\emph{version} \\uline{#{@md.sc_number}}; \\emph{date} \\uline{#{@md.sc_date}}; \\emph{time} \\uline{#{@md.sc_time}}}}
      WOK
    end
    def doc_sc_info_footnote_brief
      " \\footnote{%\nGenerated by \\href{https://git.sisudoc.org/}{SiSU} \\ \\href{https://git.sisudoc.org/}{git.sisudoc.org} \\newline \\href{https://sisudoc.org}{sisudoc.org} \\\n}"
    end
    def doc_sc_info
      v=SiSU_Env::InfoVersion.instance.get_version
      <<-WOK
\\\\
{\\begin{footnotesize}
Document version information: \\\\
\\emph{sourcefile} \\uline{#{@md.fnstex}}; \\emph{version} \\uline{#{@md.sc_number}}; \\emph{date} \\uline{#{@md.sc_date}}; \\emph{time} \\uline{#{@md.sc_time}} \\\\
Generated by \\href{https://git.sisudoc.org/}{SiSU git.sisudoc.org }\\- version information: \\\\
\\uline{ #{v.project} #{v.version} of #{v.date_stamp}}
\\end{footnotesize}}&
      WOK
    end
    def doc_no_sc_info
      v=SiSU_Env::InfoVersion.instance.get_version
      <<-WOK
\\\\
{\\begin{small}
Document information: \\\\
\\emph{sourcefile} \\uline{#{@md.fnstex}} \\\\
Generated by \\href{https://git.sisudoc.org/}{SiSU https://git.sisudoc.org/ } \\\\ version information: \\
\\uline{ #{v.project} #{v.version} of #{v.date_stamp}}

\\end{small}}&
      WOK
    end
    def endnotes #not used should be inserted before MetaData section which preceeds doc_tail, but is "part of document"
      <<-WOK
\\subsection*{Endnotes}
\\addcontentsline{toc}{section}{Endnotes}
\\
\\listofendnotes
      WOK
    end
  end
end
__END__
rg usepackage texpdf*
rg usepackage texpdf* | rg '\{.+?\}'
# texpdf_format.rb
rg usepackage texpdf* | rg --only-matching '\{.+?\}' |sort|uniq

,* sort & make unique
@tex2pdf
alltt.sty
amssymb.sty
babel.sty
boites.sty
breakurl.sty
color.sty
endnotes.sty
fancyhdr.sty
fontspec.sty
footmisc.sty
graphicx.sty
inputenc.sty
listings.sty
longtable.sty
manyfoot.sty
mathptmx.sty
multicol.sty
parskip.sty
polyglossia.sty
soul.sty
textcomp.sty
thumbpdf.sty
titlepic.sty
ucs.sty
ulem.sty
url.sty
xeCJK.sty
xltxtra.sty
xunicode.sty

,* debian related
,** found in

alltt.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/base/alltt.sty
amssymb.sty
  texlive-base: /usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty
babel.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
boites.sty
  texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/boites/boites.sty
breakurl.sty
  texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/breakurl/breakurl.sty
color.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty
endnotes.sty
  texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/endnotes/endnotes.sty
fancyhdr.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/fancyhdr/fancyhdr.sty
fontspec.sty
  texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.sty
footmisc.sty
  texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/footmisc/footmisc.sty
graphicx.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
inputenc.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty
listings.sty
  texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/listings/listings.sty
longtable.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/tools/longtable.sty
manyfoot.sty
  texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/ncctools/manyfoot.sty
mathptmx.sty
  texlive-font-utils: /usr/share/doc/texlive-doc/fonts/fontinst/examples/mathptmx/mathptmx.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/psnfss/mathptmx.sty
multicol.sty
  ptex-jtex: /usr/share/texmf/ajtex/multicol.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/tools/multicol.sty
parskip.sty
  texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/parskip/parskip.sty
polyglossia.sty
  texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/polyglossia/polyglossia.sty
soul.sty
  texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/soul/soul.sty
textcomp.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty
thumbpdf.sty
  texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/generic/thumbpdf/thumbpdf.sty
titlepic.sty
  texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/titlepic/titlepic.sty
ucs.sty
  texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/ucs/ucs.sty
ulem.sty
  texlive-plain-generic: /usr/share/texlive/texmf-dist/tex/generic/ulem/ulem.sty
url.sty
  texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/url/url.sty
xeCJK.sty
  texlive-xetex: /usr/share/texlive/texmf-dist/tex/xelatex/xecjk/xeCJK.sty
xltxtra.sty
  texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/xltxtra/xltxtra.sty
xunicode.sty
  texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/xelatex/xunicode/xunicode.sty

,** belongs to

texlive-base:
  amssymb.sty

texlive-latex-base:
  alltt.sty
  babel.sty
  color.sty
  fancyhdr.sty
  graphicx.sty
  inputenc.sty
  longtable.sty
  mathptmx.sty
  multicol.sty
  textcomp.sty
  url.sty

texlive-latex-extra:
  boites.sty
  breakurl.sty
  endnotes.sty
  footmisc.sty
  manyfoot.sty
  soul.sty
  titlepic.sty
  ucs.sty

texlive-latex-recommended:
  fontspec.sty
  listings.sty
  parskip.sty
  polyglossia.sty
  thumbpdf.sty
  xltxtra.sty
  xunicode.sty

texlive-plain-generic:
  ulem.sty

texlive-xetex:
  xeCJK.sty

,** all texlive packages used

texlive-base
texlive-latex-base
texlive-latex-extra
texlive-latex-recommended
texlive-plain-generic
texlive-xetex
#+END_SRC

* document header

#+NAME: sisu_document_header
#+BEGIN_SRC emacs-lisp
<<./sisu_version_info_and_doc_header_including_copyright_and_license.org:sisu_doc_header_including_copyright_and_license()>>
#+END_SRC