summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/luatex/luatexref-t.tex
blob: b89015a0d56566cb1b16d6ee2384e16891cc8672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
% engine=luatex language=uk

% TODO: fix layout of function legend descriptions

\environment luatexref-env

\def\CFF{\kap{cff}}
\def\PATGEN{\kap{patgen}}
\def\MP{MetaPost}

\dontcomplain

\catcode`\_=12
 
\setvariables
  [document]
  [beta=0.25.3]

\starttext

\setups[titlepage]

\title{Contents}

\placecontent[criterium=text,level=subsection]

\chapter{Introduction}

\startframedtext[framecolor=red,foregroundcolor=red,width=\hsize,font=\tfa]

This book will eventually become the reference manual of \LUATEX. At
the moment, it simply reports the behavior of the executable
matching the snapshot or beta release date in the title page.

\blank

Features may come and go. The current version of \LUATEX\ is not meant
for production and users cannot depend on stability, nor on
functionality staying the same.

\blank

Nothing is considered stable just yet. This manual
therefore simply reflects the current state of the executable. {\bs
Absolutely nothing\/} on the following pages is set in stone. When the
need arises, anything can (and will) be changed without prior notice.

\blank

\bf If you are not willing to deal with this situation, you should wait 
for the stable version. Currently we expect the first release to be
available sometime in the summer of~2008.

\stopframedtext

\blank[2*line]

\LUATEX\ consists of a number of interrelated but (still) distinguishable
 parts:

\startitemize[packed]
\item \PDFTEX\ version 1.40.3 % hahe: still 1.40.3?
\item \ALEPH\ RC4 (from the \TEXLIVE\ repository)
\item \LUA\ 5.1.2 ($+$ coco 1.1.3) % hahe: still 5.1.2?
\item Dedicated \LUA\ libraries
\item Various \TEX\ extensions
\item Parts of \FONTFORGE\ 2007.06.07
\item Newly written compiled source code to glue it all together
\stopitemize

Neither \ALEPH's I/O translation processes, nor tcx files, nor
\ENCTEX\ can be used, these encoding|-|related functions are
superseded by a \LUA|-|based solution (reader callbacks).  Also, some
experimental \PDFTEX\ features are removed. These can be implemented
in Lua instead.

\chapter{Basic \TEX\ enhancements}


\section{Version information}

There are three new primitives to test the version of \LUATEX:

\starttabulate[|l|p|]
\NC \bf primitive         \NC \bf explanation \NC\NR
\NC \type{\luatexversion}   \NC A combination of major and minor number, as in pdfTeX. 
                              Current value: {\bf\the\luatexversion} \NC\NR
\NC \type{\luatexrevision}  \NC The revision, as in pdfTeX. 
                              Current value: {\bf\luatexrevision} \NC\NR
\NC \type{\luatexdatestamp} \NC A combination of the local date and hour when
                              the current executable was compiled,
                              the syntax is identical to \tex{luatexrevision}.
                              Value for the executable that generated this 
                              document: {\bf\luatexdatestamp}. \NC\NR
\stoptabulate

Note that the \type{\luatexdatestamp} depends on both the compilation
time and compilation place of the current executable, it is defined in
terms of the local time. The purpose of this primitive is solely to be
an aid in the development process, do not use it for anything besides
debugging.

\section{\UNICODE\ text support}

Text input and output is now considered to be \UNICODE\ text, so
input characters can use the full range of \UNICODE\ ($2^{20}+2^{16} =
\hbox{10FFFF} = 1114111$). % hahe: wrong +/- 1

Later chapters will talk of characters and glyphs. Although these are
not the interchangeable, they are closely related. During typesetting,
a character is always converted to a suitable graphic representation
of that character in a specific font. However, while processing a list
of to-be-typeset nodes, its contents may still be seen as a character.
Inside \LUATEX\ there is not yet a clear separation between the two
concepts. Until this is implemented, please do not be too harsh on
us if we make errors in the usage of the terms.
 
Note: for now, it only makes sense to use values above the base plane
(\type{"0xFFFF}) for \tex{mathcode} and \tex{catcode} assignments,
since the hyphenation patterns are still limited to max.\ 16-bit
values, so the other commands will not know what to do with those high
values.

A few primitives are affected by this, all in a similar fashion: each of
them has to accomodate for a larger range of acceptable numbers.  For
instance, \tex{char} now accepts values between~0 and 1114111. This
should not be a problem for well|-|behaved input files, but it could
create incompatibilities for input that would have generated an error
when processed by older \TEX|-|based engines. The maximum number of
allocations is \type {"10FFFF} or $2^{20}+2^{16}$ (21 bits). The % hahe: wrong?
maximum value that can be assigned are:

% hahe: all below wrong by 1?
\starttabulate[|l|l|l|l|]
\NC \bf primitive     \NC \bf bits \NC \bf hex     \NC \bf numeric                     \NC\NR
\NC \tex{char}        \NC 21       \NC \tt ~10FFFF \NC $2^{20}+2^{16}$                 \NC\NR
\NC \tex{chardef}     \NC 21       \NC \tt ~10FFFF \NC $2^{20}+2^{16}$                 \NC\NR
\NC \tex{lccode}      \NC 21       \NC \tt ~10FFFF \NC $2^{20}+2^{16}$                 \NC\NR
\NC \tex{uccode}      \NC 21       \NC \tt ~10FFFF \NC $2^{20}+2^{16}$                 \NC\NR
\NC \tex{sfcode}      \NC 15       \NC \tt ~~~7FFF \NC $2^{15}$                        \NC\NR
\NC \tex{catcode}     \NC ~4       \NC \tt ~~~~~~F \NC $2^{4}$                         \NC\NR
\stoptabulate

As far as the core engine is concerned, all input and output to text
files is \UTF-8 encoded. Input files can be pre|-|processed using the
\luatex{reader} callback. This will be explained in a later chapter.

Output in byte|-|sized chunks can be achieved by using characters just
outside of the valid unicode range, starting at the value 1.114.112 
(0x110000). When the times comes to print a character $c>=1.114.112$, \LUATEX\ will
actually print the single byte corresponding to $c-1.114.112$.

Output to the terminal uses \type{^^} notation for the lower control
range ($c<32$), with the exception of \type{^^I}, \type{^^J} and
\type{^^M}.  These are considered \quote{safe} and therefore printed as-is.

Normalization of the \UNICODE\ input can be handled by a macro package
during callback processing (this will be explained in \in{section}[iocallback]).

\section{Wide math characters}

Text handling is now extended up to the full \UNICODE\ range, but math mode
deals mostly with glyphs in fonts directly and fonts tend to be 16-bit
at maximum. The extension from 8-bit to 16-bit was already present in
\ALEPH\ by means of a set of extra primitives.

Therefore, the math primitives from \TEX\ and \ALEPH\ are kept mostly
as they are, except for the ones that convert from input to math
commands like \type{matcode} and \type{omathcode}. The traditional
\TEX\ primitives are unchanged, their arguments are upscaled from 8~to 
16~bits internally (as in \ALEPH).

% hahe: again wrong by 1?
\starttabulate[|l|l|l|l|]
\NC \bf primitive     \NC \bf max index/bits \NC \bf hex          \NC \bf numeric                       \NC\NR
\NC \tex{mathchardef} \NC 15             \NC \tt~~~8000           \NC $2^{3}*2^{4}*2^{8}$               \NC\NR
\NC \tex{mathcode}    \NC 8=15           \NC \tt~~~~~FF = ~~~800  \NC $2^{3}*2^{4}*2^{8}$               \NC\NR
\NC \tex{delcode}     \NC 8=24           \NC \tt~~~~~FF = ~FFFFF  \NC $2^{4}*2^{8}*2^{4}*2^{8}$         \NC\NR
\NC \tex{mathchar}    \NC 15             \NC \tt~~~7FFF           \NC $2^{3}*2^{4}*2^{8}$               \NC\NR
\NC \tex{mathaccent}  \NC 15             \NC \tt~~~7FFF           \NC $2^{3}*2^{4}*2^{8}$               \NC\NR
\NC \tex{delimiter}   \NC 27             \NC \tt7FFFFFF           \NC $2^{3}*2^{4}*2^{8}*2^{4}*2^{8}$   \NC\NR
\NC \tex{radical}     \NC 27             \NC \tt7FFFFFF           \NC $2^{3}*2^{4}*2^{8}*2^{4}*2^{8}$   \NC\NR
\NC \tex{omathchardef}\NC 27             \NC \tt8000000           \NC $2^{3}*2^{8}*2^{16}$              \NC\NR
\NC \tex{omathcode}   \NC 21=27          \NC \tt~10FFFF = 8000000 \NC $2^{3}*2^{8}*2^{16}$              \NC\NR
\NC \tex{odelcode}    \NC 21=24+24       \NC \tt~10FFFF = ~FFFFFF \NC $2^{8}*2^{16}$                    \NC\NR
\NC                   \NC                \NC \tt~~~~~~~ + ~FFFFFF \NC \quad $+ 2^{8}*2^{16}$            \NC\NR
\NC \tex{omathchar}   \NC 27             \NC \tt7FFFFFF           \NC $2^{3}*2^{8}*2^{18}$              \NC\NR
\NC \tex{omathaccent} \NC 27             \NC \tt7FFFFFF           \NC $2^{3}*2^{8}*2^{18}$              \NC\NR
\NC \tex{odelimiter}  \NC 27+24          \NC \tt7FFFFFF + ~FFFFFF \NC $2^{3}*2^{8}*2^{16}+2^{8}*2^{16}$ \NC\NR
\NC \tex{oradical}    \NC 27+24          \NC \tt7FFFFFF + ~FFFFFF \NC $2^{3}*2^{8}*2^{16}+2^{8}*2^{16}$ \NC\NR
\stoptabulate

\section{Extended tables}

All traditional \TEX\ and \ETEX\ registers can be 16 bit numbers as in \ALEPH. The affected commands
are:

\startcolumns[n=4]
\starttyping
\count
\dimen
\skip
\muskip
\marks
\toks
\countdef
\dimendef
\skipdef
\muskipdef
\toksdef
\box
\unhbox
\unvbox
\copy
\unhcopy
\unvcopy
\wd
\ht
\dp
\setbox
\vsplit
\stoptyping
\stopcolumns

The same is true for the font-related \PDFTEX\ tables like \type{\rpcode} etc.

\section{Attribute registers}

Attributes are a completely new concept in \LUATEX. Syntactically,
they behave a lot like counters: attributes obey \TEX's nesting stack
and can be used after \tex{the} etc.\ just like the normal
\tex{count} registers.

\startsyntax
\attribute <16-bit number> <optional equals> <31-bit number>!crlf
\attributedef <csname> <optional equals> <16-bit number>
\stopsyntax

Conceptually, an attribute is either \quote{set} or \quote{unset}. Set
attributes can only have values of~0 or more, otherwise they are
considered unset and automatically remapped to an special negative
value meaning \quote{unset} (currently that value is $-1$, but please
test on negativity, not on a specific value).  All attributes start
out in the \quote{unset} state (in \INITEX). 

Attributes can be used as extra counter values, but their usefulness
comes mostly from the fact that the numbers and values of all \quote{set}
attributes are attached to all nodes created in their scope. These can
then be queried from any \LUA\ code that deals with node
processing. Future versions of
\LUATEX\ will probably be using specific negative attribute ids for
internal use. Further information about how to use attributes for node
list processing from lua is given in~\in{chapter}[nodes].

\subsection{Box attributes}

Nodes typically receive the list of attributes that is in effect when
they are created. This moment can be quite asynchronous. For example: in
paragraph building, the individual line boxes are created after the
\tex{par} command has been processed, so they will receive the list of
attributes that is in effect then, not the attributes that were in
effect in, say, the first or third line of the paragraph. 

Similar situations happen in \LUATEX\ regularly. A few of the more
obvious problematic cases are dealt with: the attributes for nodes
that are created during hyphenation and ligaturing borrow their
attributes from their surrounding glyphs, and it is possible to
influence box attributes directly. 

But many other inserted nodes, like the nodes resulting from math mode
and alignments, are processed `out of order', and will have the
attributes that are in effect at the precise moment of creation (which
is often later than expected). This area needs studying, and is in
fact one of the reasons for a beta at this moment.


It is possible to fine-tune the list of attributes that are applied
to a \type{hbox}, \type{vbox} or \type{vtop} by the use of the
keyword \type{attr}. An example:

\starttyping
\attribute2=5
\setbox0=\hbox {Hello}
\setbox2=\hbox attr1=12 attr2=-1{Hello}
\stoptyping

This will set the attribute list of the box 2 to $1=12$, and the
attributes of box 0 will be $2=5$. As you can see, assigning a
negative value causes an attribute to be ignored.

The \type{attr} keyword(s) should come before a \type{to} or
\type{spread}, if that is also specified.

\section{\LUA\ related primitives}

In order to merge \LUA\ code with \TEX\ input, a few new primitives are
needed. \LUATEX\ has support for 65536 separate \LUA\ interpreter
states. States are automatically created based on the integer argument
to the primitives \tex{directlua} and \tex{latelua}.


\subsection{\tex{directlua}}

The primitive \tex{directlua} is used to execute \LUA\ code immediately.
The syntax is

\startsyntax
\directlua <16-bit number> <general text>
\stopsyntax

The \syntax{<general text>} is expanded fully, and then fed into the
\LUA\ interpreter state indicated by the \syntax{<16-bit number>}. 
If the state does not exist yet, it will be initialized
automatically. After reading and expansion has been applied to the
\syntax{<general text>}, the resulting token list is converted to a
string as if it was displayed using \type{\the\toks}. On the \LUA\
side, each \type{\directlua} block is treated as a separate chunk. 

The conversion from and to a token list means that you normally can
not use \LUA\ line comments (starting with \type{--}) within the
argument, as there typically will be only one \quote{line}, so that comment
will then run on until the end of the input. You will either need to
use \TEX-style line comments (starting with \%), or change the \TEX\
category codes locally.

\startbuffer
$\pi = \directlua0{tex.print(math.pi)}$
\stopbuffer

The \type{\directlua} command is expandable: the results of the \LUA\
code become effective immediately. As an example, the following
input:
\typebuffer
will result in
\getbuffer

Because the \syntax{<general text>} is a chunk, the normal \LUA\ error
handling is triggered if there is a problem in the included code. The
\LUA\ error messages should be clear enough, but the contextual 
information is still pretty bad. Typically, you will only see the line
number of the right brace at the end of the code. 

While on the subject of errors: some of the things you can do inside
\LUA\ code can break up \LUATEX\ pretty bad. If you are not careful
while working with the node list interface, you may even end up with
assertion errors from within the \TEX\ portion of the executable.

\subsection{\tex{latelua}}

\tex{latelua} stores \LUA\ code in a whatsit that will be processed
inside the output routine. Its intended use is very similar to
\tex{pdfliteral}. Within the \LUA\ code, you can print \PDF\ 
statements directly to the \PDF\ file.

\startsyntax
\latelua <16-bit number> <general text>
\stopsyntax

\subsection{\tex{luaescapestring}}

This primitive converts a \TEX\ token sequence so that it can be
safely used as the contents of a \LUA\ string: embedded backslashes,
double and single quotes, and newlines and carriage returns are
escaped. This is done by prepending an extra token consisting of a
backslash with category code~12, and for the line endings,
converting them to \type{n} and \type{r} respectively. The token
sequence is fully expanded.

\startsyntax
\luaescapestring <general text>
\stopsyntax

Most often, this command is not actually the best way to deal with the
differences between the \TEX\ and \LUA. In very short bits of \LUA\
code it is often not needed, and for longer stretches of \LUA\ code it
is easier to keep the code in a separate file and load it using \LUA's
\type{dofile}:
\starttyping
\directlua0 { dofile('mysetups.lua')}
\stoptyping

\subsection{\tex{closelua}}

This primitive allows you to close a \LUA\ state, freeing all of its
used memory.

\startsyntax
\closelua <16-bit number>
\stopsyntax

You cannot close the initial \LUA\ state~(0), attempts to do so
will be silently ignored.

States are never closed automatically except when a fatal out of
memory error occurs, at which point \LUATEX\ will exit anyway.

Also be aware that \LUA\ states are not closed immediately, but only
when the \tex{output} routine comes into play next (because there may be
pending \tex{latelua} calls).

\section{New \ETEX\ primitives}

\subsection{\tex{clearmarks}}

This primitive clears a marks class completely, resetting all three
connected mark texts to empty.

\startsyntax
\clearmarks <16-bit number>
\stopsyntax

\subsection{\tex{noligs} and \tex{nokerns}}

These primitives prohibit ligature and kerning insertion at the time
when the initial node list is built by \LUATEX's main control loop.
They are part of a temporary trick and will be removed in the near
future. For now, you need to enable these primitives when you want to
do node list processing of \quote{characters}, where \TEX's normal
processing would get in the way.

\startsyntax
\noligs <integer>!crlf
\nokerns <integer>
\stopsyntax


\subsection{\tex{formatname}}

\tex{formatname}'s syntax is identical to \tex{jobname}.

In \INITEX, the expansion is empty. Otherwise, the expansion is the
value that \tex{jobname} had during the \INITEX\ run that dumped the
currently loaded format.

\subsection{\tex{scantextokens}}

The syntax of \tex{scantextokens} is identical to \tex{scantokens}.

This is a slightly adapted version of \ETEX's \tex{scantokens}. The
differences are:

\startitemize
\item The last (and usually only) line does not have a
      \tex{endlinechar} appended
\item \tex{scantextokens} never raises an EOF error,
      and it does not execute \tex{everyeof} tokens.
\item The \quote{.. while end of file ..} error tests are not executed, allowing
      the expansion to end on a different grouping level or while a
      conditional is still incomplete.
\stopitemize


\subsection{Catcode tables}

Catcode tables are a new feature that allows you to switch to a
predefined catcode regime in a single statement. You can have a
practically unlimited number of different tables.

The subsystem is backward compatible: if you never use the following
commands, your document will not notice any difference in behavior
compared to traditional \TEX.

The contents of each catcode table is independent from any other
catcode tables, and their contents is stored and retrieved from the
format file.

\subsubsection{\tex{catcodetable}}

\startsyntax
\catcodetable <28-bit number>
\stopsyntax

The \tex{catcodetable} switches to a different catcode table.
Such a table has to be previously created using one of the two
primitives below, or it has to be zero (table zero is initialized by
\INITEX).

\subsubsection{\tex{initcatcodetable}}

\startsyntax
\initcatcodetable <28-bit number>
\stopsyntax

The \tex{initcatcodetable} creates a new table with catcodes
identical to those defined by \INITEX:

\starttabulate[|l|l|l|l|]
\NC~0\NC \type{_}                  \NC         \NC \tt escape        \NC\NR
\NC~5\NC \tt\letterhat\letterhat M \NC return  \NC \tt car\_ret      \NC\NR
\NC~9\NC \tt\letterhat\letterhat @ \NC null    \NC \tt ignore        \NC\NR
\NC10\NC \tt <space>               \NC space   \NC \tt spacer        \NC\NR
\NC11\NC {\tt a} -- {\tt z}        \NC         \NC \tt letter        \NC\NR
\NC11\NC {\tt A} -- {\tt Z}        \NC         \NC \tt letter        \NC\NR
\NC12\NC everything else           \NC         \NC \tt other         \NC\NR
\NC14\NC \tt\letterpercent         \NC         \NC \tt comment       \NC\NR
\NC15\NC \tt\letterhat\letterhat ? \NC delete  \NC \tt invalid\_char \NC\NR
\stoptabulate

The new catcode table is allocated globally: it will not go away after
the current group has ended. If the supplied number is identical to
the currently active table, an error is raised.

\subsubsection{\tex{savecatcodetable}}

\startsyntax
\savecatcodetable <28-bit number>
\stopsyntax

\tex{savecatcodetable} copies the current set of catcodes to a
new table with the requested number. The definitions in this new table
are all treated as if they were made in the outermost level.

The new table is allocated globally: it will not go away after the
current group has ended. If the supplied number is the currently
active table, an error is raised.

\subsection{\tex{suppressfontnotfounderror}}

\startsyntax
\suppressfontnotfounderror = 1
\stopsyntax

If this new integer parameter is non-zero, then \LUATEX\ will not
complain about font metrics that are not found. Instead it will
silently skip the font assignment, making the requested csname for the
font \type{\ifx} equal to \type{\nullfont}, so that it can be tested
against that without bothering the user.

\subsection{Font syntax}

\LUATEX\ will accept a braced argument as a font name:

\starttyping
\font\myfont = {cmr10}
\stoptyping

This allows for embedded spaces, without the need for double quotes.
Macro expansion takes place inside the argument.

\section{Debugging}

If \tex{tracingonline} is larger than 2, the node list display will
also print the node number of the nodes.

\chapter {\LUA\ general}

\section[init]{Initialization}

\subsection{\LUATEX\ as a \LUA\ interpreter}

There are some situations that make \LUATEX\ behave like it is a \LUA\
interpreter only:
\startitemize[packed]
\item If a \type{--luaonly} option is given on the commandline
\item If the executable is named \type{texlua} (or \type{luatexlua})
\item if the only non|-|option argument (file) on the commandline has the extension
	\type{lua} or \type{luc}.
\stopitemize

In this mode, it will set \LUA's \type{arg[0]} to the found script
name, pushing preceding options in negative values and the rest of the
commandline in the positive values, just like the \LUA\
interpreter.

\LUATEX\ will exit immediately after executing the specified \LUA\
script and is, in effect, a somewhat bulky standalone \LUA\
interpreter with a bunch of extra preloaded libraries.

\subsection{\LUATEX\ as a \LUA\ byte compiler}

There are two situations that make \LUATEX\ behaves like the \LUA\
byte compiler:
\startitemize[packed]
\item If a \type{--luaconly} option is given on the commandline
\item If the executable is named \type{texluac}
\stopitemize

In this mode, \LUATEX\ is exactly like \type{luac} from the standalone
\LUA\ distribution, except that it does not have the \type{-l} switch,
and that it accepts (but ignores) the \type{--luaconly} switch.

\subsection{Other commandline processing}

When the \LUATEX\ executable starts, it looks for the \type{--lua}
commandline option. If there is no \type{--lua} option, the
commandline is interpreted in a similar fashion as in traditional
\PDFTEX\ and \ALEPH. But if the option is present, \LUATEX\ will enter an
alternative mode of commandline parsing in comparison to the standard
web2c programs.

In this mode, a small series of actions is taken in order. At first,
it will only interpret a small subset of the commandline directly:

\starttabulate[|l|p|]
\NC \tt --lua=s    \NC load and execute a \LUA\ initialization script      \NC\NR
\NC \tt --safer    \NC disable easily exploitable \LUA\ commands \NC\NR
\NC \tt --help     \NC display help and exit                     \NC\NR
\NC \tt --version  \NC display version and exit                  \NC\NR
\stoptabulate

Now it searches for the requested \LUA\ initialization script. If it
can not be found using the actual name given on the commandline, a
second attempt is made by prepending the value of the environment
variable \type{LUATEXDIR}, if that variable is defined.

Then it checks the \type{--safer} switch. You can use that to disable
some \LUA\ commands that can easily be abused by a malicious document. At
the moment, this switch \type{nil}s the following functions:

\starttabulate[|l|l|]
\NC \bf library \NC \bf functions                         \NC \NR
\NC \tt os      \NC \tt execute exec setenv rename remove tmpdir \NC \NR
\NC \tt io      \NC \tt popen output tmpfile              \NC \NR
\NC \tt lfs     \NC \tt rmdir mkdir chdir lock touch      \NC \NR
\stoptabulate

And it makes \lua{io.open()} fail on files that are opened for
anything besides reading.

Next the initialization script is loaded and executed. From within the
script, the entire commandline is available in the \LUA\ table
\lua{arg}, beginning with \lua {arg[0]}, containing the name of the executable.

Commandline processing happens very early on. So early, in fact, that
none of \TEX's initializations have taken place yet. For that reason,
the \luatex{tex}, \luatex{token}, \luatex{node} and \luatex{pdf}  tables 
are off|-|limits during the execution of the startup file (they are
nilled). Special care is taken that \luatex{texio.write} and
\luatex{texio.write_nl} function properly, so that you can at least
report your actions to the log file when (and if) it eventually
becomes opened (note that \TEX\ does not even know its \tex{jobname}
yet at this point). See \in{chapter}[libraries] for more information
about the \LUATEX-specific \LUA\ extension tables. 

The \LUA\ initialization script is loaded into \LUA\ state~0, and
everything you do will remain visible during the rest of the run, with
the exception of the aforementioned \luatex{tex}, \luatex{token},
\luatex{node} and \luatex{pdf} tables: those will be initialized 
to their documented state after the execution of the script. You
should not store anything in variables or within tables with these
four global names, as they will be overwritten completely.

We recommend you use the startup file only for your own
\TEX|-|independent initializations (if you need any), to parse the
commandline, set values in the \luatex{texconfig} table, and register
the callbacks you need. \LUATEX\ will fetch some of the other
commandline options from the \luatex{texconfig} table at the end of
script execution (see the description of the \luatex{texconfig} table
later on in this document for more details on which ones exactly).

Unless the \luatex{texconfig} table tells it not to start \KPATHSEA\
at all (set \luatex{texconfig.kpse_init} to \type{false} for that),
\LUATEX\ acts on three more commandline options after the
initialization script is finished:

\starttabulate[|l|l|]
\NC \bf flag         \NC \bf meaning                           \NC \NR
\NC \tt --fmt=s      \NC set the format name                   \NC \NR
\NC \tt --progname=s \NC set the progname (only for \KPATHSEA) \NC \NR
\NC \tt --ini        \NC enable \INITEX\ mode                  \NC \NR
\stoptabulate

In order to initialize the built|-|in \KPATHSEA\ library properly,
\LUATEX\ needs to know the correct \quote{progname} to use, and for that it
needs to check \type{--progname} (and \type{--ini} and \type{--fmt}, if
\type{--progname} is missing).

\section{\LUA\ changes}

The C coroutine (COCO) patches from luajit are applied to the Lua core, the used
version is 1.1.3.  See \hyphenatedurl{http://luajit.org/coco.html} for details.

The \lua{read("*line")} function from the io library has been
adjusted so that it is line|-|ending neutral: any of \type{LF}, \type
{CR} or \type{CR+LF} are acceptable line endings.

The \lua{tostring()} printer for numbers has been changed so that it
returns~\type{0} instead of something like~\hbox{\type{2e-5}} (which confused \TEX\
enormously) when the value is so small that \TEX\ cannot distinguish
it from zero.

Dynamic loading of \type{.so} and \type{.dll} files is disabled on
all platforms.

\lua{luafilesystem} has been extended with two extra boolean functions
(\luatex{isdir(filename)} and \luatex{isfile(filename)}) and one extra
string field in its attributes table (\type{permissions}).

The \lua{string} library has an extra function:
\luatex{string.explode(s[,m])}. This function returns an array containing
the string argument \type{s} split into substrings based on the value
of the string argument \type{m}. The second argument is a string that
is either empty (this splits the string into characters), a single
character (this splits on each occurrence of that character, possibly
introducing empty strings), or a single character followed by the plus
sign \type{+} (this special version does not create empty
substrings). The default value for \type{m} is \quote{\type{ +}} (multiple
spaces).

Note: \type{m} is not hidden by surrounding braces (as it would be if
this function was written in \TEX\ macros).

The \lua{string} library also has six extra iterators that return strings
piecemeal:

\startitemize
\item \luatex{string.utfvalues(s)} (returns an integer value in the
\UNICODE\ range)
\item \luatex{string.utfcharacters(s)} (returns a string with a single
\UTF-8 token in it)
\item \luatex{string.characters(s)} (a string containing one byte)
\item \luatex{string.characterpairs(s)} (two strings each containing one byte) will
produce an empty second string in the string length was odd.
\item \luatex{string.bytes(s)} (a single byte value)
\item \luatex{string.bytepairs(s)} (two byte values) Will produce nil instead of a
number as its second return value if the string length was odd.
\stopitemize

The \luatex{string.characterpairs()} and \luatex{string.bytepairs()}
are useful especially in the conversion of UTF-16 encoded data into UTF-8.


Note: The \lua{string} library functions \luatex{find} etc. are not
Unicode-aware. In cases where this is required (i.\,e.\ because the
pattern used for searching contains characters above code point 127),
the corresponding functions from \lua{unicode.utf8} should be used.

\blank

The \lua{os} library has a few extra functions and variables:

\startitemize
\item \luatex{os.exec(commandline)} is a variation on \lua{os.execute}.

  The \type{commandline} can be either a single string or a single table. 

  If the argument is a table: \LUATEX\ first checks if there is a value at
  integer index zero. If there is, this is the command to be executed. Otherwise,
  it will use the value at integer index one. (if neither are present, nothing 
  at all happens).
  
  The set of consecutive values starting at integer 1 in the table are
  the arguments that are passed on to the command (the value at index 1 
  becomes \type{argv[0]}).  The command is searched for in the execution path, 
  so there is normally no need to pass on a fully qualified pathname.

  If the argument is a string, then it is automatically converted into 
  a table by splitting on whitespace. In this case, it is impossible
  for the command and first argument to differ from each other.

  In the string argument format, whitespace can be protected by putting (part
  of) an argument inside single or double quotes.  One layer of quotes is
  interpreted by \LUATEX, and all occurences of \type{\"}, \type{\'} or
  \type{\\} within the quoted text are un-escaped.  In the table format, there
  is no string handling taking place.

  This function normally does not return control back to the lua script: the
  command will replace the current process. However, it will return \type{nil, 'error'}
  if there was a problem while attempting to execute the command.

  On windows, the current process is actually kept in memory until after the
  execution of the command has finished. This prevents crashes in situations
  where \TEXLUA\ scripts are run inside integrated \TEX\ environments.


  (the original reason for this command is that it cleans out the current
  process before starting the new one, making it especially useful for
  use in \TEXLUA.)

\item \luatex{os.spawn(commandline)} is a returning version of \lua{os.exec},
  with otherwise identical calling conventions.
 
  If the command ran ok, then the return value is the exit status of the
  command. Otherwise, it will return \type{nil, 'error'}.

\item \luatex{os.setenv('key','value')}
  This sets a variable in the environment. Passing \lua{nil} instead of a
  value string will remove the variable.

\item \luatex{os.env}
  This is a hash table containing a dump of the variables and values
  in the process environment at the start of the run. It is writeable,
  but the actual environment is {\it not\/} updated automatically.

\item \luatex{os.gettimeofday()}
Returns the current `unix time', but as a float. This function is
not available on the SunOS platforms, so do not use this function
for portable documents.

\item \luatex{os.times()}
Returns the current process times cf. the unix C library `times'
call in seconds. This function is not available on the Windows and SunOS
platforms, so do not use this function for portable documents.

\item \luatex{os.tmpdir()} This will create a directory in the `current
directory' with the name \type{luatex.XXXXXX} where the X-es are
replaced by a unique string. The function also returns this string,
so you can \type{lfs.chdir()} into it, or \type{nil} if it failed to
create the directory.  The user is responsible for cleaning up at
the end of the run, it does not happen automatically. 

\item \luatex{os.type}
This is a string  that gives a global indication of the class of operating
system. The possible values are currently \type{windows}, \type{unix}, and
\type{msdos} (you are unlikely to find this value `in the wild'). 

\item \luatex{os.name}
This is a string that gives a more precise indication of the operating
system. These possible values are not yet fixed, and for \type{os.type} values
\type{windows} and \type{msdos}, the \type{os.name} values are simply 
\type{windows} and \type{msdos}

The list for the type \type{unix} is more precise: \type{linux}, 
\type{freebsd}, \type{openbsd}, \type{solaris}, \type{sunos} (pre-solaris), 
\type{hpux}, \type{irix}, \type{macosx}, \type{bsd} (unknown, but BSD-like), 
\type{sysv} (unknown, but SYSV-like), \type{generic} (unknown).

(\type{os.version} is planned as a future extension)

\stopitemize

In stock Lua, many things depend on the current locale. In \LUATEX, we can't do
that, because it makes documents unportable.  While \LUATEX\ is running if
forces the following locale settings:
\starttyping
	LC_CTYPE=C
	LC_COLLATE=C
	LC_NUMERIC=C
\stoptyping

\section {\LUA\ modules}

Some modules that are normally external to Lua are statically linked
in with \LUATEX, because they offer useful functionality: 

\startitemize
\item \lua{slnunicode}, from the Selene libraries, \hyphenatedurl{http://luaforge.net/projects/sln}. (version 1.1)

This library has been slightly extended so that the \type{unicode.utf8.*} 
functions also accept the first 256 values of Plane~18. This is the range \LUATEX\ 
uses for raw binary output, as explained above,

\item \lua{luazip}, from the kepler project, \hyphenatedurl{http://www.keplerproject.org/luazip/}.  
  (version 1.2.1, but patched for compilation with lua 5.1)
\item \lua{luafilesystem}, also from the kepler project, \hyphenatedurl{http://www.keplerproject.org/luafilesystem/}.  
  (version 1.2, but patched for compilation with lua 5.1)
\item \lua{lpeg}, by Roberto Ierusalimschy, \hyphenatedurl{http://www.inf.puc-rio.br/~roberto/lpeg.html}. (version 0.8.1)

Note: \lua{lpeg} is not Unicode-aware, but interprets strings on a
byte-per-byte basis. This mainly means that \luatex{lpeg.S} cannot be
used with characters above code point 127, since those characters are
encoded using two bytes, and thus \luatex{lpeg.S} will look for one
of those two bytes when matching, not the combination of the two.

The same is true for \luatex{lpeg.R}, although the latter will display
an error message if used with characters above code point 127: I.\,e.\
\luatex{lpeg.R('aä')} results in the message \type{bad argument #1 to
'R' (range must have two characters)}, since to \lua{lpeg}, \type{ä}
is two 'characters' (bytes), so \type{aä} totals three.

\item \lua{lzlib}, by Tiago Dionizio, \hyphenatedurl{http://mega.ist.utl.pt/~tngd/lua/}. (version 0.2)
\item \lua{md5}, by Roberto Ierusalimschy \hyphenatedurl{http://www.inf.puc-rio.br/~roberto/md5/md5-5/md5.html}.
\stopitemize

\chapter[libraries]{\LUATEX\ \LUA\ Libraries}

The interfacing between \TEX\ and \LUA\ is facilitated by a set of
library modules. The \LUA\ libraries in this chapter are all defined and 
initialized by the \LUATEX\ executable. Together, they allow \LUA\
scripts to query and change a number of \TEX's internal variables, run
various internal functions \TEX, and set up \LUATEX's hooks to execute
\LUA\ code.

\section{The \luatex{tex} library}

The \luatex{tex} table contains a large list of virtual internal \TEX\
parameters that are partially writable.

The designation \quote{virtual} means that these items are not properly
defined in \LUA, but are only front\-ends that are handled by a metatable
that operates on the actual \TEX\ values. As a result, most of the \LUA\
table operators (like \type{pairs} and \type{#}) do not work on such
items.

At the moment, it is possible to access almost every parameter
that has these characteristics:

\startitemize[packed]
\item You can use it after \tex{the}
\item It is a single token.
\stopitemize

This excludes parameters that need extra arguments, like
\tex{the}\tex{scriptfont}.

The subset comprising simple integer and dimension registers are
writable as well as readable (stuff like \tex{tracingcommands} and
\tex{parindent}).

\subsection{Integer parameters}

The integer parameters accept and return \LUA\ numbers.

Read-write:

\startcolumns[n=2]
\starttyping
tex.adjdemerits
tex.binoppenalty
tex.brokenpenalty
tex.catcodetable
tex.clubpenalty
tex.day
tex.defaulthyphenchar
tex.defaultskewchar
tex.delimiterfactor
tex.displaywidowpenalty
tex.doublehyphendemerits
tex.endlinechar
tex.errorcontextlines
tex.escapechar
tex.exhyphenpenalty
tex.fam
tex.finalhyphendemerits
tex.floatingpenalty
tex.globaldefs
tex.hangafter
tex.hbadness
tex.holdinginserts
tex.hyphenpenalty
tex.interlinepenalty
tex.language
tex.lastlinefit
tex.lefthyphenmin
tex.linepenalty
tex.localbrokenpenalty
tex.localinterlinepenalty
tex.looseness
tex.mag
tex.maxdeadcycles
tex.month
tex.newlinechar
tex.outputpenalty
tex.pausing
tex.pdfadjustinterwordglue
tex.pdfadjustspacing
tex.pdfappendkern
tex.pdfcompresslevel
tex.pdfdecimaldigits
tex.pdfgamma
tex.pdfgentounicode
tex.pdfimageapplygamma
tex.pdfimagegamma
tex.pdfimagehicolor
tex.pdfimageresolution
tex.pdfinclusionerrorlevel
tex.pdfminorversion
tex.pdfobjcompresslevel
tex.pdfoutput
tex.pdfpagebox
tex.pdfpkresolution
tex.pdfprependkern
tex.pdfprotrudechars
tex.pdftracingfonts
tex.pdfuniqueresname
tex.postdisplaypenalty
tex.predisplaydirection
tex.predisplaypenalty
tex.pretolerance
tex.relpenalty
tex.righthyphenmin
tex.savinghyphcodes
tex.savingvdiscards
tex.showboxbreadth
tex.showboxdepth
tex.time
tex.tolerance
tex.tracingassigns
tex.tracingcommands
tex.tracinggroups
tex.tracingifs
tex.tracinglostchars
tex.tracingmacros
tex.tracingnesting
tex.tracingonline
tex.tracingoutput
tex.tracingpages
tex.tracingparagraphs
tex.tracingrestores
tex.tracingscantokens
tex.tracingstats
tex.uchyph
tex.vbadness
tex.widowpenalty
tex.year
\stoptyping
\stopcolumns

Read|-|only:

\startcolumns[n=3]
\starttyping
tex.deadcycles
tex.insertpenalties
tex.parshape
tex.prevgraf
tex.spacefactor
\stoptyping
\stopcolumns

\subsection{Dimension parameters}

The dimension parameters accept \LUA\ numbers (signifying scaled points)
or strings (with included dimension). The result is always a string.

Read-write:

\startcolumns[n=3]
\starttyping
tex.boxmaxdepth
tex.delimitershortfall
tex.displayindent
tex.displaywidth
tex.emergencystretch
tex.hangindent
tex.hfuzz
tex.hoffset
tex.hsize
tex.lineskiplimit
tex.mathsurround
tex.maxdepth
tex.nulldelimiterspace
tex.overfullrule
tex.pagebottomoffset
tex.pageheight
tex.pagerightoffset
tex.pagewidth
tex.parindent
tex.pdfdestmargin
tex.pdfeachlinedepth
tex.pdfeachlineheight
tex.pdffirstlineheight
tex.pdfhorigin
tex.pdflastlinedepth
tex.pdflinkmargin
tex.pdfpageheight
tex.pdfpagewidth
tex.pdfpxdimen
tex.pdfthreadmargin
tex.pdfvorigin
tex.predisplaysize
tex.scriptspace
tex.splitmaxdepth
tex.vfuzz
tex.voffset
tex.vsize
\stoptyping
\stopcolumns

Read|-|only:

\startcolumns[n=3]
\starttyping
tex.pagedepth
tex.pagefilllstretch
tex.pagefillstretch
tex.pagefilstretch
tex.pagegoal
tex.pageshrink
tex.pagestretch
tex.pagetotal
tex.prevdepth
\stoptyping
\stopcolumns

\subsection{Direction parameters}

The direction parameters are read|-|only and return a \LUA\ string.

\startcolumns[n=3]
\starttyping
tex.bodydir
tex.mathdir
tex.pagedir
tex.pardir
tex.textdir
\stoptyping
\stopcolumns

\subsection{Glue parameters}

All glue parameters are read|-|only and return a \LUA\ string.

\startcolumns[n=3]
\starttyping
tex.abovedisplayshortskip
tex.abovedisplayskip
tex.baselineskip
tex.belowdisplayshortskip
tex.belowdisplayskip
tex.leftskip
tex.lineskip
tex.parfillskip
tex.parskip
tex.rightskip
tex.spaceskip
tex.splittopskip
tex.tabskip
tex.topskip
tex.xspaceskip
\stoptyping
\stopcolumns

\subsection{Muglue parameters}

All muglue parameters are read|-|only and return a \LUA\ string.

\startcolumns[n=3]
\starttyping
tex.medmuskip
tex.thickmuskip
tex.thinmuskip
\stoptyping
\stopcolumns

\subsection{Tokenlist parameters}

All tokenlist parameters are read|-|only and return a \LUA\ string.

\startcolumns[n=3]
\starttyping
tex.errhelp
tex.everycr
tex.everydisplay
tex.everyeof
tex.everyhbox
tex.everyjob
tex.everymath
tex.everypar
tex.everyvbox
tex.output
tex.pdfpageattr
tex.pdfpageresources
tex.pdfpagesattr
tex.pdfpkmode
\stoptyping
\stopcolumns

\subsection{Convert commands}

The supported commands at this moment are:

\startcolumns[n=3]
\starttyping
tex.AlephVersion
tex.Alephrevision
tex.OmegaVersion
tex.Omegarevision
tex.eTeXVersion
tex.eTeXrevision
tex.formatname
tex.jobname
tex.luatexrevision
tex.luatexdatestamp
tex.pdfnormaldeviate
tex.pdftexbanner
tex.pdftexrevision
\stoptyping
\stopcolumns

All \quote{convert} commands are read|-|only and return a \LUA\ string.

If you are wondering why this list looks haphazard; these are all the
cases of the \quote{convert} internal command that do not require an
argument.

\subsection{Attribute, count, dimension and token registers}

\TEX's attributes (\tex{attribute}), counters (\tex{count}),
dimensions (\tex{dimen}) and token (\tex{toks}) registers can be
accessed and written to using four virtual sub|-|tables of the
\luatex{tex} table:

\startcolumns[n=3]
\starttyping
tex.attribute
tex.count
tex.dimen
tex.toks
\stoptyping
\stopcolumns

It is possible to use the names of relevant \tex{attributedef}, \tex{countdef},
\tex{dimendef}, or \tex{toksdef} control sequences as indices
to these tables:

\starttyping
tex.count.scratchcounter = 0
enormous = tex.dimen['maxdimen']
\stoptyping

In this case, \LUATEX\ looks up the value for you on the fly. You have
to use a valid \tex{countdef} (or \tex{attributedef}, or
\tex{dimendef}, or \tex{toksdef}), anything else will generate an error
(the intent is to eventually also allow \type{<chardef tokens>} and even
macros that expand into a number).

The attribute and count registers accept and return \LUA\ numbers.

The dimension registers accept \LUA\ numbers (in scaled points) or
strings (with an included absolute dimension; \type {em} and \type {ex} and \type {px}
are forbidden). The result is always a number in scaled points.

The token registers accept and return \LUA\ strings. \LUA\ strings are
converted to and from token lists using \tex{the}\tex{toks} style
expansion: all category codes are either space (10) or other (12).

As an alternative to array addressing, there are also accessor
functions defined:

\startfunctioncall
tex.setdimen(number n, string s)
tex.setdimen(string s, string s)
tex.setdimen(number n, number n)
tex.setdimen(string s, number n)
number n = tex.getdimen(number n)
number n = tex.getdimen(string s)

tex.setcount(number n, number n)
tex.setcount(string s, number n)
number n = tex.getcount(number n)
number n = tex.getcount(string s)

tex.settoks (number n, string s)
tex.settoks (string s, string s)
string s = tex.gettoks (number n)
string s = tex.gettoks (string s)
\stopfunctioncall

\subsection{Box registers}

The current dimensions of \tex{box} registers can be read and
altered using three other virtual sub|-|tables :

\starttyping
tex.wd
tex.ht
tex.dp
\stoptyping

These are indexed strictly by number.

The box size registers accept \LUA\ numbers (in scaled points)
or strings (with included dimension). The result is always a number
in scaled points.

As an alternative to array addressing, there are also accessor
functions defined:

\startfunctioncall
tex.setboxwd(number n, number n)
number n = tex.getboxwd(number n)

tex.setboxht(number n, number n)
number n = tex.getboxht(number n)

tex.setboxdp(number n, number n)
number n = tex.getboxdp(number n)
\stopfunctioncall

It is also possible to set and query actual boxes, using the node
interface as defined in the \luatex{node} library:

\starttyping
tex.box
\stoptyping

for array access, or

\starttyping
tex.setbox(number n, <node> s)
<node> n = tex.getbox(number n)
\stoptyping

for function|-|based access.

Be warned that an assignment like

\starttyping
tex.box[0] = tex.box[2]
\stoptyping

does not copy the node list, it just duplicates a node pointer.  If
\tex{box2} will be cleared by \TEX\ commands later on, the contents
of \tex{box0} becomes invalid as well. To prevent this from
happening, always use \luatex{node.copy_list()} unless you are
assigning to a temporary variable:

\starttyping
tex.box[0] = node.copy_list(tex.box[2])
\stoptyping

\subsection{Print functions}

The \luatex{tex} table also contains the three print functions that
are the major interface from \LUA\ scripting to \TEX.

The arguments to these three functions are all stored in an in|-|memory
virtual file that is fed to the \TEX\ scanner as the result of the
expansion of \tex{directlua}.

The total amount of returnable text from a \tex{directlua} command
is only limited by available system \RAM. However, each separate
printed string has to fit completely in \TEX's input buffer.

\subsubsection{\luatex{tex.print}}

\startfunctioncall
tex.print(string s, ...)
tex.print(number n, string s, ...)
\stopfunctioncall

Each string argument is treated by \TEX\ as a separate input line.

The optional parameter can be used to print the strings using the
catcode regime defined by \tex{catcodetable}~\type{n}. If \type{n} is not
a valid catcode table, then it is ignored, and the currently
active catcode regime is used instead.

The very last string of the very last \luatex{tex.print()} command in a
\tex{directlua} will not have the \tex{endlinechar} appended, all
others do.

\subsubsection{\luatex{tex.sprint}}

\startfunctioncall
tex.sprint(string s, ...)
tex.sprint(number n, string s, ...)
\stopfunctioncall

Each string argument is treated by \TEX\ as a special kind of input line
that makes it suitable for use as a partial line input mechanism:

\startitemize[packed]
\item \TEX\ does not switch to the \quote{new line} state, so
   that leading spaces are not ignored.
\item No \tex{endlinechar} is inserted.
\item Trailing spaces are not removed.

(Note that this does not prevent \TEX\ itself from eating spaces as
result of interpreting the line. For example, in 
\starttyping
before\directlua0{tex.sprint("\\relax")tex.sprint(" inbetween")}after
\stoptyping
the space before \type{inbetween} will be gobbled as a result of 
the \quote{normal} scanning of \type{\relax}).
\stopitemize


\subsubsection{\luatex{tex.write}}

\startfunctioncall
tex.write(string s, ...)
\stopfunctioncall

Each string argument is treated by \TEX\ as a special kind of input
line that makes is suitable for use as a quick way to dump
information:

\startitemize
\item All catcodes on that line are either \quote{space} (for '~') or
     \quote{character} (for all others).
\item There is no \tex{endlinechar} appended.
\stopitemize

\subsection{Helper functions}

\subsubsection{\luatex{tex.round}}

\startfunctioncall
number n =  tex.round(number o)
\stopfunctioncall

Rounds lua number \type{o}, and returns a number that is in the range
of a valid \TEX\ register value. If the number starts out of range, it
generates a \quote{Number to big} error as well.

\subsubsection{\luatex{tex.scale}}

\startfunctioncall
number n =  tex.scale(number o, number delta)
table n  =  tex.scale(table o, number delta)
\stopfunctioncall

Multiplies the lua numbers \type{o} and \type{delta}, and returns a
rounded number that is in the range of a valid \TEX\ register value.
In the table version, it creates a copy of the table with all numeric
top||level values scaled in that manner. If the multiplied number(s) are
of range, it generates \quote{Number to big} error(s) as well.

\section{The \luatex{token} library}

The \luatex{token} table contains interface functions to \TEX's
handling of tokens. These functions are most useful when combined with
the \luatex{token_filter} callback, but they could be used standalone as
well.

A token is represented in \LUA\ as a small table. For the moment, this
table consists of three numeric entries:

\starttabulate[|l|l|p|]
\NC \bf no.\NC \bf meaning         \NC \bf description \NC \NR
\NC 1      \NC command code        \NC this is a value between~$0$ and~$130$ (approximately)\NC \NR
\NC 2      \NC command modifier    \NC this is a value between~$0$ and~$2^{21}$ \NC \NR
\NC 3      \NC control sequence id \NC for commands that are not the result of control
                                       sequences, like letters and characters, it is zero,
                                       otherwise, it is a number pointing into the \quote
                                       {equivalence table} \NC \NR
\stoptabulate

\subsection{\luatex{token.get_next}}

\startfunctioncall
token t = token.get_next()
\stopfunctioncall

This fetches the next input token from the current input source,
without expansion.

\subsection{\luatex{token.is_expandable}}

\startfunctioncall
boolean b = token.is_expandable(token t)
\stopfunctioncall

This tests if the token \type{t} could be expanded.

\subsection{\luatex{token.expand}}

\startfunctioncall
token.expand()
\stopfunctioncall

If a token is expandable, this will expand one level of it, so that
the first token of the expansion will now be the next token to be read
by \luatex{tex.get_next()}.

\subsection{\luatex{token.is_activechar}}

\startfunctioncall
boolean b = token.is_activechar(token t)
\stopfunctioncall

This is a special test that is sometimes handy. Discovering whether
some token is the result of an active character turned out to be very
hard otherwise.

\subsection{\luatex{token.create}}

\startfunctioncall
token t = token.create(string csname)
token t = token.create(number charcode)
token t = token.create(number charcode, number catcode)
\stopfunctioncall

This is the token factory. If you feed it a string, then it is the
name of a control sequence (without leading backslash), and it will be
looked up in the equivalence table.

If you feed it number, then this is assumed to be an input character,
and an optional second number gives its category code.  This means it
is possible to overrule a character's category code, with a few
exceptions: the category codes~0 (escape), 9~(ignored), 13~(active),
14~(comment), and 15 (invalid) cannot occur inside a token. The values~0, 9, 14
and~15 are therefore illegal as input to \luatex{token.create()}, and
active characters will be resolved immediately.

Note: unknown string sequences and never defined active characters
will result in a token representing an \quote{undefined control sequence}
with a near|-|random name. It is {\it not\/} possible to define brand
new control sequences using \luatex{token.create}!

\subsection{\luatex{token.command_name}}

\startfunctioncall
string commandname = token.command_name(token t)
\stopfunctioncall

This returns the name associated with the \quote{command} value of the token
in \LUATEX. There is not always a direct connection between these names and
primitives. For instance, all \tex{ifxxx} tests are grouped under
\type {if_fest}, and the \quote{command modifier} defines which test is to be run.

\subsection{\luatex{token.command_id}}

\startfunctioncall
number i = token.command_idtring commandname)
\stopfunctioncall

This returns a number that is the inverse operation of the previous
command, to be used as the first item in a token table.

\subsection{\luatex{token.csname_name}}

\startfunctioncall
string csname = token.csname_name(token t)
\stopfunctioncall

This returns the name associated with the \quote{equivalence table} value of
the token in \LUATEX. It returns the string value of the command used
to create the current token, or an empty string if there is no
associated control sequence.

\subsection{\luatex{token.csname_id}}

\startfunctioncall
number i = token.csname_id(string csname)
\stopfunctioncall

This returns a number that is the inverse operation of the previous
command, to be used as the third item in a token table.

\section{The \luatex{node} library}

The \luatex{node} library contains functions that facilitate dealing
with (lists of) nodes and their values. They allow you to create, alter,
copy, delete, and insert \LUATEX\ node objects, the core
objects within the typesetter.

\LUATEX\ nodes are represented in \LUA\ as userdata with
the metadata type \luatex{luatex.node}. The various parts within
a node can be accessed using named fields.

Each node has at least the three fields \type{next}, \type{id}, and
\type{subtype}:

\startitemize[intro]

\item The \type{next} field returns the userdata
object for the next node in a linked list of nodes, or
nil, if there is no next node.

\item The \type{id} indicates \TEX's \quote{node type}. The field \type{id}
has a numeric value for efficiency reasons, but some of the library
functions also accept a string value instead of \type{id}.

\item The \type{subtype} is another number. It often gives further information
about a node of a particular \type{id}, but it is most important when dealing
with \quote{whatsits}, because they are differentiated solely based on their
\type{subtype}.
\stopitemize

The other available fields depend on the \type{id} (and for \quote{whatsits}, the
\type{subtype}) of the node. Further details on the various fields and their
meanings are given in~\in{chapter}[nodes].

\TEX's math nodes are not yet supported: there is not yet an interface
to the internals of the math list and it is not possible to create
them from \LUA. Support for \type{unset} (alignment) nodes is partial:
they can be queried and modified from \LUA\ code, but not created.

Nodes can be compared to each other, but: you are actually comparing
indices into the node memory. This means that equality tests can only
be trusted under very limited conditions. It will not work correctly
in any situation where one of the two nodes has been freed and|/|or
reallocated: in that case, there will be false positives.

At the moment, memory management of nodes should still be done
explicitly by the user.  Nodes are not \quote{seen} by the \LUA\
garbage collector, so you have to call the node free-ing functions
yourself when you are no longer in need of a node (list). Nodes form
linked lists without reference counting, so you have to be careful
that when control returns back to \LUATEX\ itself, you have not
deleted nodes that are still referenced from a \type{next} pointer
elsewhere, and that you did not create nodes that are referenced more
than once.

\subsection{Node handling functions}

\subsubsection{\luatex{node.types}}

\startfunctioncall
table t = node.types()
\stopfunctioncall

This function returns an array that maps node id numbers to node type
strings, providing an overview of the possible top|-|level \type{id}
types.

\subsubsection{\luatex{node.whatsits}}

\startfunctioncall
table t = node.whatsits()
\stopfunctioncall

\TEX's \quote{whatsits} all have the same \type{id}. The various subtypes
are defined by their \type{subtype}. The function is much like
\luatex{node.types}, except that it provides an array of \type{subtype}
mappings.

\subsubsection{\luatex{node.id}}

\startfunctioncall
number id = node.id(string type)
\stopfunctioncall

This converts a single type name to its internal numeric
representation.

\subsubsection{\luatex{node.subtype}}

\startfunctioncall
number subtype = node.subtype(string type)
\stopfunctioncall

This converts a single whatsit name to its internal numeric
representation (\type{subtype}).

\subsubsection{\luatex{node.type}}

\startfunctioncall
string type = node.type(number id)
\stopfunctioncall

This converts a internal numeric representation to an external string
representation.

\subsubsection{\luatex{node.fields}}

\startfunctioncall
table t = node.fields(number id)
table t = node.fields(number id, number subtype)
\stopfunctioncall

This function returns an array of valid field names for a particular
type of node. If you want to get the valid fields for a
\quote{whatsit}, you have to supply the second argument also. In other
cases, any given second argument will be silently ignored.

This function accepts string \type{id} and \type{subtype} values as
well.

\subsubsection{\luatex{node.has_field}}

\startfunctioncall
boolean t = node.has_field(<node> n, string field)
\stopfunctioncall

This function returns a boolean that is only true if \type{n} is
actually a node, and it has the field. 


\subsubsection{\luatex{node.new}}

\startfunctioncall
<node> n = node.new(number id)
<node> n = node.new(number id, number subtype)
\stopfunctioncall

Creates a new node. All of the new node's fields are initialized to
either zero or nil except for \type{id} and \type{subtype} (if
supplied). If you want to create a new whatsit, then the second
argument is required, otherwise it need not be present. As with all
node functions, this function creates a node on the \TEX\ level.

This function accepts string \type{id} and \type{subtype} values as
well.

\subsubsection{\luatex{node.free}}

\startfunctioncall
node.free(<node> n)
\stopfunctioncall

Removes the node \type{n} from \TEX's memory. Be careful: no checks
are done on whether this node is still pointed to from a register or some
\type{next} field: it is up to you to make sure that the internal data
structures remain correct.

\subsubsection{\luatex{node.flush_list}}

\startfunctioncall
node.flush_list(<node> n)
\stopfunctioncall

Removes the node list \type{n} and the complete node list following
\type{n} from \TEX's memory. Be careful: no checks are done on whether
any of these nodes is still pointed to from a register or some
\type{next} field: it is up to you to make sure that the internal data
structures remain correct.

\subsubsection{\luatex{node.copy}}

\startfunctioncall
<node> m = node.copy(<node> n)
\stopfunctioncall

Creates a deep copy of node \type{n}, including all nested lists as in
the case of a hlist or vlist node. Only the \type{next} field is not
copied.

\subsubsection{\luatex{node.copy_list}}

\startfunctioncall
<node> m = node.copy_list(<node> n)
\stopfunctioncall

Creates a deep copy of the node list that starts at \type{n}.

\subsubsection{\luatex{node.hpack}}

\startfunctioncall
<node> h = node.hpack(<node> n)
<node> h = node.hpack(<node> n, number w, string info)
\stopfunctioncall

This function creates a new hlist by packaging the list that begins at  node
\type{n} into a horizontal box. With only a single argument, this box 
is created using the natural width of its components. In the three
argument form, \type{info} must be either \type{additional} or
\type{exactly}, and \type{w} is the additional (\type{\hbox spread})
or exact (\type{\hbox to}) width to be used.

Caveat: at this moment, there can be unexpected side|-|effects to this
function, like updating some of the \type{\marks} and \type{\inserts}.

\subsubsection{\luatex{node.slide}}

\startfunctioncall
<node> m = node.slide(<node> n)
\stopfunctioncall

Returns the last node of the node list that starts at \type{n}. As a
side|-|effect, it also creates a reverse chain of \type{prev} pointers
between nodes.

\subsubsection{\luatex{node.length}}

\startfunctioncall
number i = node.length(<node> n)
number i = node.length(<node> n, <node> m)
\stopfunctioncall

Returns the number of nodes contained in the node list that starts at
\type{n}. If \type{m} is also supplied it stops at \type{m} instead of
at the end of the list. The node \type{m} is not counted.

\subsubsection{\luatex{node.count}}

\startfunctioncall
number i = node.count(number id, <node> n)
number i = node.count(number id, <node> n, <node> m)
\stopfunctioncall

Returns the number of nodes contained in the node list that starts at
\type{n} that have an matching \type{id} field.
If \type{m} is also supplied, counting stops at \type{m} instead of at
the end of the list. The node \type{m} is not counted.

This function also accept string \type{id}'s.

\subsubsection{\luatex{node.traverse}}

\startfunctioncall
<node> t = node.traverse(<node> n)
\stopfunctioncall

This is an iterator that loops over the node list that starts at \type{n}.

\subsubsection{\luatex{node.traverse_id}}

\startfunctioncall
<node> t = node.traverse_id(number id, <node> n)
\stopfunctioncall

This is an iterator that loops over all the nodes in the list that
starts at \type{n} that have a matching \type{id} field. 

\subsubsection{\luatex{node.remove}}

\startfunctioncall
<node> head, current = node.remove(<node> head, <node> current)
\stopfunctioncall

This function removes the node \type{current} from the list following
\type{head}. It is your responsibility to make sure it is really part
of that list. The return values are the new \type{head} and
\type{current} nodes. The returned \type{current} is the 
node in the calling argument, and is only passed back as a convenience
(its \type{next} field will be cleared). The returned \type{head} is
more important, because if the function is called with \type{current}
equal to \type{head}, it will be changed.


\subsubsection{\luatex{node.insert_before}}

\startfunctioncall
<node> head, new = node.insert_before(<node> head, <node> current, <node> new)
\stopfunctioncall

This function inserts the node \type{new} before \type{current} into
the list following \type{head}. It is your responsibility to make sure
that \type{current} is really part of that list. The return values are
the (potentially mutated) \type{head} and the \type{new}, set up to
be part of the list (with correct \type{next} field). If \type{head}
is initially \type{nil}, it will become \type{new}.


\subsubsection{\luatex{node.insert_after}}

\startfunctioncall
<node> head, new = node.insert_after(<node> head, <node> current, <node> new)
\stopfunctioncall

This function inserts the node \type{new} after \type{current} into
the list following \type{head}. It is your responsibility to make sure
that \type{current} is really part of that list. The return values are
the \type{head} and the \type{new}, set up to be part of the list
(with correct \type{next} field). If \type{head} is initially
\type{nil}, it will become \type{new}.

\subsubsection{\luatex{node.first_character}}

\startfunctioncall
<node> n = node.first_character(<node> n)
<node> n = node.first_character(<node> n, <node> m)
\stopfunctioncall

Returns the first node that is a glyph node with a subtype indicating
it is a character, or \type{nil}. 

\subsubsection{\luatex{node.ligaturing}}

\startfunctioncall
<node> h, <node> t, <boolean> success = node.ligaturing(<node> n)
<node> h, <node> t, <boolean> success = node.ligaturing(<node> n, <node> m)
\stopfunctioncall

Apply \TEX-style ligaturing to the specified nodelist. The tail node
\type{m} is optional. The two returned nodes \type{h} and \type{t} are
the new head and tail (both \type{n} and \type{m} can change into 
a new ligature).

\subsubsection{\luatex{node.kerning}}

\startfunctioncall
<node> h, <node> t, <boolean> success = node.kerning(<node> n)
<node> h, <node> t, <boolean> success = node.kerning(<node> n, <node> m)
\stopfunctioncall

Apply \TEX-style kerning to the specified nodelist. The tail node
\type{m} is optional. The two returned nodes \type{h} and \type{t} are
the head and tail (either one of these can be an inserted kern node,
because special kernings with word boundaries are possible).




\subsubsection{\luatex{node.unprotect_glyphs}}

\startfunctioncall
node.unprotect_glyphs(<node> n)
\stopfunctioncall

Substracts 256 from all glyph node subtypes. This and the next
function are helpers to convert from \type{characters} to
\type{glyphs} during node processing.


\subsubsection{\luatex{node.protect_glyphs}}

\startfunctioncall
node.protect_glyphs(<node> n)
\stopfunctioncall

Adds 256 to all glyph node subtypes in the node list starting at
\type{n}, except that if the value is 1, it adds only 255. The special
handling of 1 means that \type{characters} will become \type{glyphs}
after substraction of 256.

\subsubsection{\luatex{node.last_node}}

\startfunctioncall
<node> n = node.last_node()
\stopfunctioncall

This function pops the last node from \TEX's `current list'. 
It returns that node, or \type{nil} if the current list is empty.

\subsubsection{\luatex{node.write}}

\startfunctioncall
node.write(<node> n)
\stopfunctioncall

This is an experimental function that will append a node list to 
\TEX's `current list'. There is no error checking yet!



\subsection{Attribute handling}

Attributes appear as linked list of userdata objects in the
\type{attr} field of individual nodes. They can be handled
individually, but it is much safer and more efficient to use the
dedicated functions associated with them.

\subsubsection{\luatex{node.has_attribute}}

\startfunctioncall
number v = node.has_attribute(<node> n, number id)
number v = node.has_attribute(<node> n, number id, number val)
\stopfunctioncall

Tests if a node has the attribute with number \type{id} set. If
\type{val} is also supplied, also tests if the value matches \type{val}.
It returns the value, or, if no match is found, nil.

\subsubsection{\luatex{node.set_attribute}}

\startfunctioncall
node.set_attribute(<node> n, number id, number val)
\stopfunctioncall

Sets the attribute with number \type{id} to the value
\type{val}. Duplicate assignments are ignored.

\subsubsection{\luatex{node.unset_attribute}}

\startfunctioncall
number v = node.unset_attribute(<node> n, number id, number val)
number v = node.unset_attribute(<node> n, number id)
\stopfunctioncall

Unsets the attribute with number \type{id}. If \type{val} is also supplied,
it will only perform this operation if the value matches \type{val}.
Missing attributes or attribute|-|value pairs are ignored.

If the attribute was actually deleted, returns its old
value. Otherwise, returns nil.

\section{The \luatex{texio} library}

This library takes care of the low|-|level I/O interface.

\subsection{Printing functions}

\subsubsection{\luatex{texio.write}}

\startfunctioncall
texio.write(string target, string s, ...)
texio.write(string s, ...)
\stopfunctioncall

Without the \type{target} argument, writes all given strings to the same
location(s) \TEX\ writes messages to at this moment. If
\tex{batchmode} is in effect, it writes only to the log,
otherwise  it writes to the log and the terminal.

The optional \type{target} can be one of three possibilities:
\type{term}, \type{log} or \type {term and log}.

Note: If several strings are given, and if the first of these strings
is or might be one of the targets above, the \type{target} must be
specified explicitely to prevent \LUA\ from interpreting the first
string as the target.

\subsubsection{\luatex{texio.write_nl}}

\startfunctioncall
texio.write_nl(string target, string s, ...)
texio.write_nl(string s, ...)
\stopfunctioncall

Like \luatex{texio.write}, but make sure that the given strings will
appear at the beginning of a new line. You can pass a single empty string
if you only want to move to the next line.

\section{The \luatex{pdf} library}

This table contains the current \type{h} and \type{v} values that
define the location on the output page. The values can be queried
and set using scaled points as units.

\starttyping
pdf.v
pdf.h
\stoptyping

The associated function calls are

\startfunctioncall
pdf.setv(number n)
number n = pdf.getv()
pdf.seth(number n)
number n = pdf.geth()
\stopfunctioncall


It also holds a print function to write stuff to the \PDF\ document
that can be used from within a \tex{latelua} argument. This function
is not to be used inside \tex{directlua} unless you know {\it
exactly} what you are doing.

\subsubsubject{\luatex{pdf.print}}

\startfunctioncall
pdf.print(string s)
pdf.print(string type, string s)
\stopfunctioncall

The optional parameter can be used to mimic the behavior of
\tex{pdfliteral}: the \type{type} is \type{direct} or \type{page}.

\section{The \luatex{img} library}

The \type{img} library can be used as an alternative to
\tex{pdfximage} and \tex{pdfrefximage}, and the associated `satellite'
commands like \tex{pdfximagebbox}.

\subsubsubject{\luatex{img.new}}

\startfunctioncall
<image> var = img.new()
<image> var = img.new(image_spec) 
\stopfunctioncall

This function creates a userdata object of type `image'. The 
\type{image_spec} argument is optional. If it is given, it must be
a table, and that table must contain a \type{filename} key.  A number of
other keys can also be useful, these are explained below.

You can either say
\starttyping
a=img.new()
\stoptyping 
followed by 
\starttyping
a.filename="foo.png"
\stoptyping 
or you can put the file name (and some or all of the other keys)
into a table directly, like so:
\starttyping
a=img.new{filename='foo.pdf',page=1}
\stoptyping

The generated \type{<image>} userdata object allows access to a set of
user-specified values as well as a set of values that are normally
filled in and updated automatically by \LUATEX\ itself. Some of those
are derived from the actual image file, others are updated to reflect 
the PDF output status of the object.

There is one required user-specified field: the file name
(\type{filename}).  It can optionally be augmented by the requested
image dimensions (\type{width}, \type{depth}, \type{height}),
user-specified image attributes (\type{attr}), the requested PDF page
identifier (\type{page}), the requested boundingbox (\type{pagebox})
for PDF inclusion, the requested color space object (\type{colorspace}).

The function \type{img.new} does not access the actual image file, it
just creates the \type{<image>} userdata object and initializes some
memory structures. The \type{<image>} object and its internal
structures are automatically garbage collected.

Once the image is scanned, all the values in the 
\type{<image>} become frozen, and you cannot change them any more.

\subsubsubject{\luatex{img.keys}}

\startfunctioncall
<table> keys = img.keys()
\stopfunctioncall

This function returns a list of all the possible \type{image_spec}
keys, both user-supplied and automatic ones. 

% hahe: i need to add r/w ro column...
\starttabulate[|l|l|p|] 
\NC Field name    \NC Type     \NC Description \NC \NR
\NC depth         \NC number   \NC Image depth for \LUATEX\ (in scaled points)\NC \NR
\NC height        \NC number   \NC Image height for \LUATEX\ (in scaled points)\NC \NR
\NC width         \NC number   \NC Image width for \LUATEX\  (in scaled points)\NC \NR
\NC transform     \NC number   \NC Image transform, integer number 0..7\NC \NR
\NC attr          \NC string   \NC Image attributes for \LUATEX \NC \NR
\NC filename      \NC string   \NC Image file name \NC \NR
\NC page          \NC ??       \NC Identifier for the requested image
                                   page (type is number or string,
                                   default is the number 1)\NC \NR
\NC pagebox       \NC string   \NC Requested bounding box. 
                                   One of "none", "media", "crop", "bleed", "trim", "art" \NC \NR
\NC filepath      \NC string   \NC Full (expanded) file name of the image \NC \NR
\NC colordepth    \NC number   \NC Number of bits used by the color space \NC \NR
\NC colorspace    \NC number   \NC Color space object number \NC \NR
\NC imagetype     \NC string   \NC One of "pdf", "png", "jpg", "jbig2", or \type{nil} \NC \NR
\NC objnum        \NC number   \NC PDF image object number \NC \NR
\NC index         \NC number   \NC PDF image name suffix \NC \NR
\NC pages         \NC number   \NC Total number of available pages \NC \NR
\NC xsize         \NC number   \NC Natural image width \NC \NR
\NC ysize         \NC number   \NC Natural image height \NC \NR
\NC xres          \NC number   \NC Horizontal natural image resolution (dpi) \NC \NR
\NC yres          \NC number   \NC Vertical natural image resolution (dpi) \NC \NR
\stoptabulate

A running (undefined) dimension in \type{width}, \type{height}, or \type{depth} is
represented as \type{nil} in Lua, so if you want to load an image at
its `natural' size, you do not have to specify any of those three fields.

The \type{transform} allows to mirror and rotate the image in steps of 90~deg.
The default value~0 gives an unmirrored, unrotated image.
Values 1..3 give counterclockwise rotation by 90, 180, or 270~deg.,
whereas with values 4..7 the image is first mirrored
and then rotated counterclockwise by 90, 180, or 270~deg.
The \type{transform} operation gives the same visual result
as if you would externally preprocess the image by a graphics tool
and then use it by \LUATEX.

\subsubsubject{\luatex{img.scan}}

\startfunctioncall
<image> var = img.scan(<image> var) 
<image> var = img.scan(image_spec)
\stopfunctioncall

When you say \type{img.scan(a)} for a new image, the file is scanned,
and variables such as \type{xsize}, \type{ysize}, image \type{type}, number of
\type{pages}, and the resolution are extracted. Each of the \type{width},
\type{height}, \type{depth} fields are set up according to the image dimensions,
if they were not given an explicit value already.
An image file will never be scanned more than once for a given image variable.
With all subsequent \type{img.scan(a)} calls only the dimensions are again
set up (if they have been changed by the user in the meantime).

For ease of use, you can do right-away a 
\starttyping
a=img.scan{filename="foo.png"} 
\stoptyping
without a prior \type{img.new}.

Nothing is written yet at this point, so you can do \type{a=img.scan},
retrieve the available info like image width and height, and then
throw away \type{a} again by saying \type{a=nil}.  In that case no
image object will be reserved in the PDF, and the used memory will be
cleaned up automatically.

\subsubsubject{\luatex{img.copy}}

\startfunctioncall
<image> var = img.copy(<image> var) 
<image> var = img.copy(image_spec)
\stopfunctioncall

If you say \type{a = b}, then both variables point to the same
\type{<image>} object. if you want to write out an image with
different sizes, you can do a \type{b=img.copy(a)}. 

Afterwards, \type{a} and \type{b} still reference the same actual
image dictionary, but the dimensions for \type{b} can now be changed
from their initial values that were just copies from \type{a}.

% Hartmut, I don't know if this makes sense. An example of what
% can, and what cannot be changed would be helpful.
% -- will think about it...

\subsubsubject{\luatex{img.write}}

\startfunctioncall
<image> var = img.write(<image> var)
<image> var = img.write(image_spec)
\stopfunctioncall

By \type{img.write(a)} a \PDF\ object number is allocated,
and a whatsit node of subtype \type{pdf_refximage} is generated
and put into the output list.
By this the image \type{a} is placed into the \PDF\ page stream,
and the image file is written out into an image stream object
after the shipping of the current page is finished.

Again you can do a terse call like

\starttyping
img.write{filename="foo.png"}
\stoptyping

The \type{<image>} variable is returned in case you want it for later
processing.

\subsubsubject{\luatex{img.immediatewrite}}

\startfunctioncall
<image> var = img.immediatewrite(<image> var)
<image> var = img.immediatewrite(image_spec)
\stopfunctioncall

By \type{img.immediatewrite(a)} a \PDF\ object number is allocated,
and the image file for image \type{a} is written out immediately
into the \PDF\ file as an image stream object
(like with \type{\immediate\pdfximage}).
The object number of the image stream dictionary is then available
by the \type{objnum} key.
No \type{pdf_refximage} whatsit node is generated.
You will need a \luatex{img.write(a)} or \luatex{img.node(a)} call
to let the image appear on the page,
or reference it by another trick;
else you will have a dangling image object in the \PDF\ file.

Also here you can do a terse call like

\starttyping
a = img.immediatewrite{filename="foo.png"}
\stoptyping

The \type{<image>} variable is returned; you will most likely need it.

\subsubsubject{\luatex{img.node}}

\startfunctioncall
<node> n = img.node(<image> var)
<node> n = img.node(image_spec)
\stopfunctioncall

This function allocates a \PDF\ object number
and returns a whatsit node of subtype \type{pdf_refximage},
filled with the image parameters \type{width}, \type{height},
\type{depth}, and \type{objnum}.
Also here you can do a terse call like:

\starttyping
n = img.node{filename="foo.png"}
\stoptyping

This example outputs an image:

\starttyping
node.write(img.node{filename="foo.png"})
\stoptyping

\subsubsubject{\luatex{img.types}}

\startfunctioncall
<table> types = img.types()
\stopfunctioncall

This function returns a list with the supported image file type names,
currently these are `pdf', `png', `jpg', and `jbig2'.

\subsubsubject{\luatex{img.boxes}}

\startfunctioncall
<table> boxes = img.boxes()
\stopfunctioncall

This function returns a list with the supported \PDF\ page box names,
currently these are `media', `crop', `bleed', `trim', and `art'
(all in lowercase letters).


\section{The \luatex{mplib} library}

The \MP\ library interface registers itself in the table \type{mplib}. It
is based on the MPlib beta version 0.40 (based on \MP\ 1.003).

\subsection{\luatex{mplib.new}}

To create a new metapost instance, call 

\startfunctioncall
   mp = mplib.new({...})
\stopfunctioncall

This creates the \type{mp} instance object. The argument hash can have a number of
different fields,  as follows:

\starttabulate[|l|l|p|p|]
\NC name       \NC         type   \NC description \NC default \NC\NR
\NC error_line \NC         number \NC line width for terminal and log \NC 79 \NC\NR 
\NC half_error_line \NC    number \NC ``half'' of line width \NC 50 \NC\NR 
\NC max_print_line \NC     number \NC line length in ps output\NC 100\NC\NR 
\NC main_memory \NC        number \NC total memory size \NC 5000\NC\NR 
\NC hash_size \NC          number \NC hash size\NC 9500 \NC\NR 
\NC hash_prime \NC         number \NC prime number for hashing\NC 7919\NC\NR 
\NC param_size \NC         number \NC max. simultaneous macro parameters\NC 150\NC\NR 
\NC max_in_open \NC        number \NC max. input file nestings \NC 10\NC\NR 
\NC random_seed \NC        number \NC the initial random seed \NC variable\NC\NR 
\NC interaction \NC        string \NC the interaction mode, one of
"batch", "nonstop", "scroll", "errorstop"\NC "errorstop"\NC\NR
\NC ini_version \NC        boolean \NC the --ini switch\NC false \NC\NR 
\NC troff_mode \NC         boolean \NC the -T switch \NC false \NC\NR 
\NC print_found_names \NC  boolean \NC whether long file names 
                 should be printed to the log and terminal streams\NC false \NC\NR 
\NC mem_name \NC           string \NC --mem\NC plain.mem\NC\NR 
\NC job_name \NC           string \NC --jobname\NC mpout \NC\NR 
\NC find_file \NC          function \NC a function to find files \NC only local files\NC\NR 
\stoptabulate

The \type{find_file} function should be of this form:

\starttyping
   string found = finder (string name, string mode, string type)
\stoptyping

\starttabulate[|l|l|p|]
\NC name       \NC   the requested file \NC   \NR
\NC mode       \NC   the file mode: 'r' or 'w' \NC \NR
\NC type       \NC   the kind of file, one of: 
                    "mp", "mem", "tfm", "map", "pfb", "enc" \NC \NR
\stoptabulate

Return either the full pathname of the found file, or \type{nil} if
the file cannot be found.

\subsection{\luatex{mp:statistics}}

\startfunctioncall
   table stats = mp:statistics()
\stopfunctioncall

Returns the vital statistics for an MPlib instance. There are four
fields, giving the maximum number of used items in each of the four
statically allocated object classes:

\starttabulate[|l|l|p|]
\NC main_memory \NC        number \NC memory size \NC\NR 
\NC hash_size   \NC        number \NC hash size\NC\NR 
\NC param_size  \NC        number \NC simultaneous macro parameters\NC\NR 
\NC max_in_open \NC        number \NC input file nesting levels\NC\NR 
\stoptabulate

\subsection{\luatex{mp:execute}}

You can ask the MP interpreter to run a bit of code by calling

\startfunctioncall
   local rettable = mp:execute('metapost language chunk')
\stopfunctioncall

for various bits of Metapost language input. 

Be sure to check the \type{rettable.status} (see below) because when a
fatal Metapost error occurs the MPlib instance will become unusable
thereafter.

Generally speaking, it is best to keep your chunks small, but beware
that all chunks have to obey proper syntax, like each of them is a
small file. For instance, you cannot split a single statement over
multiple chunks.

\subsection{\luatex{mp:finish}}

\startfunctioncall
   local rettable = mp:finish()
\stopfunctioncall

If for some reason you want to stop using an MPlib instance
while processing is not yet actually done, you can call
\type{mp:finish}.  Memory and files can be closed by the 
Lua garbage collector, but an explicit \type{mp:finish} is
the only way to capture the final part of the output streams.

\subsection{Result table}

The return value of \type{mp:execute} and \type{mp:finish} is a table
with a few possible keys (only `status' is always guaranteed to be present).

\starttabulate[|l|l|p|]
\NC log    \NC string \NC output to the 'log' stream \NC \NR
\NC term   \NC string \NC output to the 'term' stream \NC \NR
\NC error  \NC string \NC output to the 'error' stream (only used for
`Out Of Memory')\NC \NR
\NC status \NC number \NC the return value. 0 = good, 1 = warning, 2 = errors, 
                         3 = fatal error \NC \NR
\NC fig    \NC table \NC An array of generated figures (if any)\NC \NR
\stoptabulate

When \type{status} equals 3, you should stop using this MPlib instance
immediately, it is no longer capable of processing input. 

If it is present, each of the entries in the \type{fig} array is a
userdata representing a figure object, and each of those has a number of
object methods you can call:

\starttabulate[|l|l|p|]
\NC boundingbox  \NC function \NC returns the bounding box, as an array of 4 values\NC \NR
\NC postscript   \NC function \NC return a string that is the ps output of the \type{fig} \NC \NR
\NC objects      \NC function \NC returns the actual array of graphic objects in this \type{fig} \NC \NR
\NC copy_objects \NC function \NC returns a deep copy of the array of graphic objects in this \type{fig} \NC \NR
\NC filename     \NC function \NC the filename this \type{fig}'s PostScript output
                                  would have written to in standalone mode\NC \NR
\stoptabulate

{\bf NOTE:} you can call \type{fig:objects()} only once for any one \type{fig} object!

When the boundingbox represents a `negated rectangle' (i.w. the first set
of coordinates is larger than the second set), the picture is empty.

Graphical objects come in various types that each have a different list of
accessible values. The types are: 'fill', 'outline', 'text',
'start_clip', 'stop_clip', 'start_bounds', 'stop_bounds', 'special'.

There is helper function (\type{mplib.fields(obj)}) to get the list of
accessible values for a particular object, but you can just as easily
use the tables given below.

All graphical objects have a field \type{type} that gives the object
type as a string value, that not explicit mentioned in the tables.  In
the following, \type{number}s are PostScript points represented as
a floating point number, unless stated otherwise. Field values that
are of \type{table} are explained in the next section.

\subsubsection{fill}

\starttabulate[|l|l|p|]
\NC path       \NC table \NC the list of knots \NC \NR
\NC htap       \NC table \NC the list of knots for the reversed trajectory \NC \NR
\NC pen        \NC table \NC knots of the pen \NC \NR
\NC color      \NC table \NC the object's color \NC \NR
\NC linejoin   \NC number \NC line join style (bare number)\NC \NR
\NC miterlimit \NC number \NC miterlimit\NC \NR
\NC prescript  \NC string \NC the prescript text \NC \NR
\NC postscript \NC string \NC the postscript text \NC \NR
\stoptabulate

The entries \type{htap} and \type{pen} are optional.

\subsubsection{outline}

\starttabulate[|l|l|p|]
\NC path \NC table \NC the list of knots \NC \NR
\NC pen \NC table \NC knots of the pen \NC \NR
\NC color \NC table \NC the object's color \NC \NR
\NC linejoin \NC number \NC line join style (bare number)\NC \NR
\NC miterlimit \NC number \NC miterlimit \NC \NR
\NC linecap \NC number \NC line cap style (bare number)\NC \NR
\NC dash \NC table \NC representation of a dash list\NC \NR
\NC prescript \NC string \NC the prescript text \NC \NR
\NC postscript \NC string \NC the postscript text \NC \NR
\stoptabulate

The entry \type{dash} is optional.
 
\subsubsection{text}

\starttabulate[|l|l|p|]
\NC text \NC string \NC the text \NC \NR
\NC font \NC string \NC font tfm name \NC \NR
\NC dsize \NC number \NC font size\NC \NR
\NC color \NC table \NC the object's color \NC \NR
\NC width \NC number \NC  \NC \NR
\NC height \NC number \NC  \NC \NR
\NC depth \NC number \NC  \NC \NR
\NC transform \NC table \NC a text transformation \NC \NR
\NC prescript \NC string \NC the prescript text \NC \NR
\NC postscript \NC string \NC the postscript text \NC \NR
\stoptabulate

\subsubsection{special}

\starttabulate[|l|l|p|]
\NC prescript \NC string \NC special text \NC \NR
\stoptabulate


\subsubsection{start_bounds, start_clip}

\starttabulate[|l|l|p|]
\NC path \NC table \NC the list of knots \NC \NR
\stoptabulate

\subsubsection{stop_bounds, stop_clip}

No fields available.

\subsection{Subsidiary table formats}

\subsubsection{Paths and pens}

Paths and pens (that are really just a special type of paths as far as
MPlib is concerned) are represented by an array where each entry
is a table that represents a knot. 

\starttabulate[|l|l|p|]
\NC left_type	\NC string \NC when present: 'endpoint', but ususally absent \NC \NR
\NC right_type	\NC string \NC like \type{left_type}\NC \NR
\NC x_coord		\NC number \NC X coordinate of this knot\NC \NR
\NC y_coord		\NC number \NC Y coordinate of this knot\NC \NR
\NC left_x		\NC number \NC X coordinate of the precontrol point of this knot\NC \NR
\NC left_y		\NC number \NC Y coordinate of the precontrol point of this knot\NC \NR
\NC right_x		\NC number \NC X coordinate of the postcontrol point of this knot\NC \NR
\NC right_y		\NC number \NC Y coordinate of the postcontrol point of this knot\NC \NR
\stoptabulate

There is one special case: pens that are (possibly transformed)
ellipses have an extra string-valued key \type{type} with value
\type{elliptical} besides the array part containing the knot list.

\subsubsection{Colors}

A color is an integer array with 0, 1, 3 or 4 values:

\starttabulate[|l|l|p|]
\NC 0  \NC Marking only \NC No values. \NC\NR
\NC 1  \NC Greyscale    \NC 0ne value in the range 0 .. 1, `black' is 0 \NC\NR
\NC 3  \NC RGB          \NC 3 values in the range 0 .. 1, `black' is 0,0,0  \NC\NR
\NC 4  \NC CMYK         \NC 4 values in the range 0 .. 1, `black' is 0,0,0,1  \NC\NR
\stoptabulate

If the color model of the internal object was \type{unitialized}, then
it was initialized to the values representing `black' in the colorspace
\type{defaultcolormodel} that was in effect at the time of the \type{shipout}.

\subsubsection{Transforms}

Each transform is a six-item array.

\starttabulate[|l|l|p|]
\NC 1 \NC number \NC represents x \NC\NR
\NC 2 \NC number \NC represents y \NC\NR
\NC 3 \NC number \NC represents xx \NC\NR
\NC 4 \NC number \NC represents yx \NC\NR
\NC 5 \NC number \NC represents xy \NC\NR
\NC 6 \NC number \NC represents yy \NC\NR
\stoptabulate

Note that the translation (index 1 and 2) comes first. This differs
from the ordering in  PostScript, where the translation comes last.

\subsubsection{Dashes}

Each \type{dash} is two-item hash, using the same model as PostScript
for the representation of the dashlist. \type{dashes} is an array of
`on' and `off', values, and \type{offset} is the phase of the pattern.

\starttabulate[|l|l|p|]
\NC dashes \NC hash   \NC an array of on-off numbers \NC\NR
\NC offset \NC number \NC the starting offset value \NC\NR
\stoptabulate


\section{The \luatex{callback} library}

This library has functions that register, find and list callbacks.

The \luatex{callback} library is only available in \LUA\ state zero (0).

\startfunctioncall
id, error = callback.register(string callback_name,function callback_func)
id, error = callback.register(string callback_name,nil)
\stopfunctioncall

where the \syntax{callback_name} is a predefined callback name, see
below. The function returns the internal \type{id} of the callback
or \type{nil}, if the callback could not be registered. In the latter
case, \type{error} contains an error message, otherwise it is
\type{nil}.

\LUATEX\ internalizes the callback function in such a way that
it does not matter if you redefine a function accidentally.
% hahe: what happens then?

Callback assignments are always global. You can use the special value
\type {nil} instead of a function for clearing the callback.

Currently, callbacks are not dumped into the format file.

\startfunctioncall
table info = callback.list()
\stopfunctioncall

The keys in the table are the known callback names, the value is a
boolean where \type{true} means that the callback is currently set
(active).

\startfunctioncall
function f = callback.find(callback_name)
\stopfunctioncall

If the callback is not set, \luatex{callback.find} returns \type{nil}.

\subsection{File discovery callbacks}

\subsubsection{\luatex{find_read_file} and \luatex{find_write_file}}

Your callback function should have the following conventions:

\startfunctioncall
string actual_name = function (number id_number, string asked_name)
\stopfunctioncall

Arguments:

\startitemize

\sym{id_number} 

This number is zero for the log or \tex {input} files. For \TEX's \tex{read} or
\tex{write} the number is incremented by one, so \tex{read0} becomes~1.

\sym{asked_name} 

This is the user|-|supplied filename, as found by \tex{input}, \tex{openin}
or \tex{openout}.

\stopitemize

Return value:

\startitemize

\sym{actual_name} 

This is the filename used. For the very first file that is read in by
\TEX, you have to make sure you return an \type{actual_name} that has
an extension and that is suitable for use as \type{jobname}. If you
don't, you will have to manually fix the name of the log file and
output file after \LUATEX\ is finished, and an eventual format
filename will become mangled. That is because these file names depend
on the jobname.

You have to return \type{nil} if the file cannot be found.

\stopitemize

\subsubsection{\luatex{find_font_file}}

Your callback function should have the following conventions:

\startfunctioncall
string actual_name = function (string asked_name)
\stopfunctioncall

The \type{asked_name} is an \OTF\ or \TFM\ font metrics file.

Return \type{nil} if the file cannot be found.

\subsubsection{\luatex{find_output_file}}

Your callback function should have the following conventions:

\startfunctioncall
string actual_name = function (string asked_name)
\stopfunctioncall

The \type{asked_name} is the \PDF\ or \DVI\ file for writing.

\subsubsection{\luatex{find_format_file}}

Your callback function should have the following conventions:

\startfunctioncall
string actual_name = function (string asked_name)
\stopfunctioncall

The \type{asked_name} is a format file for reading (the format file
for writing is always opened in the current directory).

\subsubsection{\luatex{find_vf_file}}

Like \luatex{find_font_file}, but for virtual fonts. This applies to
both \ALEPH's \OVF\ files and traditional Knuthian \VF\ files.

\subsubsection{\luatex{find_ocp_file}}

Like \luatex{find_font_file}, but for ocp files.

\subsubsection{\luatex{find_map_file}}

Like \luatex{find_font_file}, but for map files.

\subsubsection{\luatex{find_enc_file}}

Like \luatex{find_font_file}, but for enc files.

\subsubsection{\luatex{find_sfd_file}}

Like \luatex{find_font_file}, but for subfont definition files.

\subsubsection{\luatex{find_pk_file}}

Like \luatex{find_font_file}, but for pk bitmap files. The argument
\type{name} is a bit special in this case. Its form is

\starttyping
<base res>dpi/<fontname>.<actual res>pk
\stoptyping

So you may be asked for \type{600dpi/manfnt.720pk}.  It is up to you
to find a \quote{reasonable} bitmap file to go with that specification.

\subsubsection{\luatex{find_data_file}}

Like \luatex{find_font_file}, but for embedded files (\tex{pdfobj file '...'}).

\subsubsection{\luatex{find_opentype_file}}

Like \luatex{find_font_file}, but for \OPENTYPE\ font files.

\subsubsection{\luatex{find_truetype_file} and \luatex{find_type1_file}}

Your callback function should have the following conventions:

\startfunctioncall
string actual_name = function (string asked_name)
\stopfunctioncall

The \type{asked_name} is a font file. This callback is called while
\LUATEX\ is building its internal list of needed font files, so the
actual timing may surprise you. Your return value is later fed back
into the matching \luatex{read_file} callback.

Strangely enough, \luatex{find_type1_file} is also used for \OPENTYPE\
(\OTF) fonts.

\subsubsection{\luatex{find_image_file}}

Your callback function should have the following conventions:

\startfunctioncall
string actual_name = function (string asked_name)
\stopfunctioncall

The \type{asked_name} is an image file. Your return value is used to
open a file from the harddisk, so make sure you return something that
is considered the name of a valid file by your operating system.

\subsection[iocallback]{File reading callbacks}

\subsubsection{\luatex{open_read_file}}

Your callback function should have the following conventions:

\startfunctioncall
table env = function (string file_name)
\stopfunctioncall

Argument:

\startitemize

\sym{file_name} 

The filename returned by a previous \luatex{find_read_file} or the return
value of \luatex{kpse.find_file()} if there was no such callback defined.

\stopitemize

Return value:

\startitemize

\sym{env} 

This is a table containing at least one required and one optional
callback function for this file. The required field is
\luatex{reader} and the associated function will be called once
for each new line to be read, the optional one is \luatex{close}
that will be called once when \LUATEX\ is done with the file.

\LUATEX\ never looks at the rest of the table, so you can use it to
store your private per|-|file data. Both the callback functions will
receive the table as their only argument.

\stopitemize

\subsubsubsection{\luatex{reader}}

\LUATEX\ will run this function whenever it needs a new input line
from the file.

\startfunctioncall
function(table env)
    return string line
end
\stopfunctioncall

Your function should return either a string or \type{nil}. The value \type{nil}
signals that the end of file has occurred, and will make \TEX\ call
the optional \luatex{close} function next.

\subsubsubsection{\luatex{close}}

\LUATEX\ will run this optional function when it decides to close the file.

\startfunctioncall
function(table env)
    return
end
\stopfunctioncall

Your function should not return any value.

\subsubsection{General file readers}

There is a set of callbacks for the loading of binary data
files. These all use the same interface:

\startfunctioncall
function(string name)
    return boolean success, string data, number data_size
end
\stopfunctioncall

The \type{name} will normally be a full path name as it is returned by
either one of the file discovery callbacks or the internal version of
\luatex{kpse.find_file()}.

\startitemize

\sym{success} 

Return false when a fatal error occured (e.\,g.\ when the file cannot be
found, after all).

\sym{data} 

The bytes comprising the file.

\sym{data_size} 

The length of the \type{data}, in bytes.

\stopitemize

Return an empty string and zero if the file was found but there was a
reading problem.

The list of functions is:
\starttabulate[|l|p|]
\NC \luatex{read_font_file} \NC This function is called when \TEX\ needs to read a \type{ofm} or
                                \type{tfm} file. \NC\NR
\NC \luatex{read_vf_file}       \NC for virtual fonts.\NC\NR
\NC \luatex{read_ocp_file}      \NC for ocp files.\NC\NR
\NC \luatex{read_map_file}      \NC for map files.\NC\NR
\NC \luatex{read_enc_file}      \NC for encoding files.\NC\NR
\NC \luatex{read_sfd_file}      \NC for subfont definition files.\NC\NR
\NC \luatex{read_pk_file}       \NC for pk bitmap files. \NC\NR
\NC \luatex{read_data_file}     \NC for embedded files (\tex{pdfobj file '...'}).\NC\NR
\NC \luatex{read_truetype_file} \NC for \TRUETYPE\ font files. \NC\NR
\NC \luatex{read_type1_file}    \NC for \TYPEONE\ font files.\NC\NR
\NC \luatex{read_opentype_file} \NC for \OPENTYPE\ font files.  \NC\NR
\stoptabulate

\subsection{Data processing callbacks}

\subsubsection{\luatex{process_input_buffer}}


This callback allows you to change the contents of the line input
buffer just before \LUATEX\ actually starts looking at it.

\startfunctioncall
function(string buffer)
    return string adjusted_buffer
end
\stopfunctioncall

If you return \type{nil}, \LUATEX\ will pretend like your callback
never happened. You can gain a small amount of processing time from
that.


\subsubsection{\luatex{token_filter}}

This callback allows you to replace the way \LUATEX\ fetches
lexical tokens.

\startfunctioncall
function()
    return table token
end
\stopfunctioncall

The calling convention for this callback is a bit more complicated than
for most other callbacks.  The function should either return a \LUA\
table representing a valid to|-|be|-|processed token or tokenlist, or
something else like nil or an empty table.

If your \LUA\ function does not return a table representing a valid
token, it will be immediately called again, until it eventually does
return a useful token or tokenlist (or until you reset the callback
value to nil). See the description of \luatex{token} for some
handy functions to be used in conjunction with this callback.

If your function returns a single usable token, then that token will
be processed by \LUATEX\ immediately. If the function returns a token
list (a table consisting of a list of consecutive token tables), then
that list will be pushed to the input stack at a completely new token
list level, with its token type set to \quote{inserted}. In either case,
the returned token(s) will not be fed back into the callback function.

\subsection{Node list processing callbacks}

The description of nodes and node lists is in~\in{chapter}[nodes].

\subsubsection{\luatex{buildpage_filter}}

This callback is called whenever \LUATEX\ is ready to move stuff to
the main vertical list. You can use this callback to do specialized
manipulation of the page building stage like imposition or column
balancing.

\startfunctioncall
function(<node> head, string extrainfo)
    return true | false | <node> newhead
end
\stopfunctioncall

As for all the callbacks that deal with nodes, the return value can be
one of three things:

\startitemize[packed]
\item \type{boolean true} signals succesful processing
\item \type{node} signals that the \quote{head} node should be
replaced by this node
\item \type{boolean false} signals that the \quote{head} node list should be
ignored and flushed from memory
\stopitemize

The string \type{extrainfo} gives some additional information about
what \TEX's state is with respect to the \quote{current page}. The possible
values are:

\starttabulate[|lT|p|]
\NC \bf value           \NC \bf explanation                        \NC\NR
\NC \tt alignment       \NC a (partial) alignment is being added   \NC\NR
\NC \tt box             \NC a typeset box is being added           \NC\NR
\NC \tt begin_of_par    \NC the beginning of a new paragraph       \NC\NR
\NC \tt vmode_par       \NC \tex{par} was found in vertical mode   \NC\NR
\NC \tt hmode_par       \NC \tex{par} was found in horizontal mode \NC\NR
\NC \tt insert          \NC an insert is added                     \NC\NR
\NC \tt penalty         \NC a penalty (in vertical mode)           \NC\NR
\NC \tt before_display  \NC immediately before a display starts    \NC\NR
\NC \tt after_display   \NC a display is finished                  \NC\NR
\stoptabulate

\subsubsection{\luatex{pre_linebreak_filter}}

This callback is called just before \LUATEX\ starts converting a list
of nodes into a stack of \tex{hbox}es. The removal of a possible final skip
and the subsequent insertion of \tex{parfillskip} has not happened
yet at that moment.

\startfunctioncall
function(<node> head, string groupcode)
    return true | false | <node> newhead
end
\stopfunctioncall

The string called \type {groupcode} identifies the nodelist's context
within \TEX's processing. The range of possibilities is given in the
table below, but not all of those can actually appear in
\luatex {pre_linebreak_filter}, some are for the
\luatex {hpack_filter} and \luatex {vpack_filter} callbacks that 
will be explained in the next two paragraphs.

\starttabulate[|lT|p|]
\NC \bf value        \NC \bf explanation                           \NC\NR
\NC \tt hbox         \NC \tex{hbox} in horizontal mode             \NC\NR
\NC \tt adjusted_hbox\NC \tex{hbox} in vertical mode               \NC\NR
\NC \tt vbox         \NC \tex{vbox}                                \NC\NR
\NC \tt vtop         \NC \tex{vtop}                                \NC\NR
\NC \tt align        \NC \tex{halign} or \tex{valign}              \NC\NR
\NC \tt disc         \NC discretionaries                           \NC\NR
\NC \tt insert       \NC packaging an insert                       \NC\NR
\NC \tt vcenter      \NC \tex{vcenter}                             \NC\NR
\NC \tt local_box    \NC \tex{localleftbox} or \tex{localrightbox} \NC\NR
\NC \tt split_off    \NC top of a \tex{vsplit}                     \NC\NR
\NC \tt split_keep   \NC remainder of a \tex{vsplit}               \NC\NR
\NC \tt align_set    \NC alignment cell                            \NC\NR
\NC \tt fin_row      \NC alignment row                             \NC\NR
\stoptabulate

\subsubsection{\luatex{post_linebreak_filter}}

This callback is called just after \LUATEX\ has converted a list
of nodes into a stack of \tex{hbox}es. 

\startfunctioncall
function(<node> head, string groupcode)
    return true | false | <node> newhead
end
\stopfunctioncall

\subsubsection{\luatex{hpack_filter}}

This callback is called when \TEX\ is ready to start boxing some
horizontal mode material. Math items are ignored at the moment.

\startfunctioncall
function(<node> head, string groupcode, number size, string packtype)
    return true | false | <node> newhead
end
\stopfunctioncall

The \type{packtype} is either \type{additional} or \type{exactly}. If
\type{additional}, then the \type{size} is a \tex{hbox spread ...}
argument. If \type{exactly}, then the \type{size} is a \tex{hbox to ...}.
In both cases, the number is in scaled points.

\subsubsection{\luatex{vpack_filter}}

This callback is called when \TEX\ is ready to start boxing some
vertical mode material. Math displays are ignored at the moment.

This function is very similar to the \luatex{hpack_filter}. Besides
the fact that it is called at different moments, there is an extra
variable that matches \TEX's \tex{maxdepth} setting.

\startfunctioncall
function(<node> head, string groupcode, number size, string packtype,  number maxdepth)
    return true | false | <node> newhead
end
\stopfunctioncall

\subsubsection{\luatex{pre_output_filter}}

This callback is called when \TEX\ is ready to start boxing the
box 255 for \tex{output}.

\startfunctioncall
function(<node> head, string groupcode, number size, string packtype, number maxdepth)
    return true | false | <node> newhead
end
\stopfunctioncall

\subsubsection{\luatex{hyphenate}}

\startfunctioncall
function(<node> head, <node> tail)
end
\stopfunctioncall

No return values. This callback has to insert discretionary nodes in
the node list it receives.


\subsubsection{\luatex{ligaturing}}

\startfunctioncall
function(<node> head, <node> tail)
end
\stopfunctioncall

No return values. This callback has to apply ligaturing to the node
list it receives.

You don't have to worry about return values because the \type{head}
node that is passed on to the callback is guaranteed not to be a
glyph_node (if need be, a temporary node will be prepended), and
therefore it cannot be affected by the mutations that take place.  
After the callback, the internal value of the `tail of the list' 
will be recalculated. 

The \type{next} of \type{head} is guaranteed to be non-nil.

The \type{next} of \type{tail} is guaranteed be nil, and therefore the
second callback argument can often be ignored. It is provided for
orthogonality, and because it can sometimes be handy when special
processing has to take place.

\subsubsection{\luatex{kerning}}

\startfunctioncall
function(<node> head, <node> tail) end
\stopfunctioncall

No return values. This callback has to apply kerning between the nodes
in the node list it receives. See \type{ligaturing} for calling
conventions.


\subsection{Information reporting callbacks}

\subsubsection{\luatex{start_run}}

\startfunctioncall
function()
\stopfunctioncall

Replaces the code that prints \LUATEX's banner.

\subsubsection{\luatex{stop_run}}

\startfunctioncall
function()
\stopfunctioncall

Replaces the code that prints \LUATEX's statistics and \quote{output written
to} messages.

\subsubsection{\luatex{start_page_number}}

\startfunctioncall
function()
\stopfunctioncall

Replaces the code that prints the \type{[} and the page number at the
begin of \tex{shipout}. This callback will also override the
printing of box information that normally takes place when
\tex{tracingoutput} is positive.

\subsubsection{\luatex{stop_page_number}}

\startfunctioncall
function()
\stopfunctioncall

Replaces the code that prints the \type{]} at the end of \tex{shipout}.

\subsubsection{\luatex{show_error_hook}}

\startfunctioncall
function()
    return
end
\stopfunctioncall

This callback is run from inside the \TEX\ error function, and the idea
is to allow you to do some extra reporting on top of what \TEX\ already
does (none of the normal actions are removed). You may find some of
the values in the \luatex{status} table useful.

\startitemize

\sym{message} 

is the formal error message \TEX\ has given to the user.
(the line after the '!').

\sym{indicator} 

is either a filename (when it is a string) or a location indicator (a
number) that can mean lots of different things like a token list id
or a \tex{read} number.

\sym{lineno} 

is the current line number.
\stopitemize

This is an investigative item for 'testing the water' only.
The final goal is the total replacement of \TEX's error handling
routines, but that needs lots of adjustments in the web source because
\TEX\ deals with errors in a somewhat haphazard fashion. This is why the
exact definition of \type{indicator} is not given here.

\subsection{Font-related callbacks}

\subsubsection{\luatex{define_font}}

\startfunctioncall
function(string name, number size, number id) return table font end
\stopfunctioncall

The string \type{name} is the filename part of the font
specification, as given by the user.

The number \type{size} is a bit special:

\startitemize[packed]
\item if it is positive, it specifies an \quote{at size} in scaled points.
\item if it is negative, its absolute value represents a \quote{scaled}
setting relative to the designsize of the font.
\stopitemize

The internal structure of the \type{font} table that is to be
returned is explained in \in{chapter}[fonts]. That table is saved
internally, so you can put extra fields in the table for your
later \LUA\ code to use.

\section{The \luatex{lua} library}

This library contains two read|-|only  items:

\subsection{Variables}

\starttyping
number n = lua.id
\stoptyping

This returns the id number of the instance.

\starttyping
string s = lua.version
\stoptyping

This returns a \LUATEX\ version identifier string. The value is
currently \directlua0{tex.print('lua.version')}, but it is soon to be
replaced by something more elaborate.

\subsection{\LUA\ bytecode registers}

\LUA\ registers can be used to communicate \LUA\ functions across \LUA\
states. The accepted values for assignments are functions and
nil. Likewise, the retrieved value is either a function or \type{nil}.

\starttyping
lua.bytecode[n] = function () .. end
lua.bytecode[n]()
\stoptyping

The contents of the \luatex{lua.bytecode} array is stored inside the format
file as actual \LUA\ bytecode, so it can also be used to preload \LUA\ code.

Note: The function must not contain any upvalues. Currently, functions
containing upvalues can be stored (and their upvalues are set to
\type{nil}), but this is an artefact of the current \LUA\
implementation and thus subject to change.

The associated function calls are

\startfunctioncall
function f = lua.getbytecode(number n)
lua.setbytecode(number n, function f)
\stopfunctioncall

Note: Since a \LUA\ file loaded using \luatex{loadfile(filename)} is
essentially an anonymous function, a complete file can be stored in a
bytecode register like this:

\startfunctioncall
lua.bytecode[n] = loadfile(filename)
\stopfunctioncall

Now all definitions (functions, variables) contained in the file can be
created by executing this bytecode register:

\startfunctioncall
lua.bytecode[n]()
\stopfunctioncall

\section{The \luatex{kpse} library}

This library provides an interface to the \KPATHSEA\ file search method.

Before the search library can be used at all, its database has to be
initialized. When \LUATEX\ is used to typeset documents, this happens
automatically (that is, unless explicitly prohibited by the user's
startup script. See~\in{section}[init] for more details). In \TEXLUA\
mode, the initialization has to be done explicitly via the
\luatex{kpse.set_program_name} function.

\subsection{\luatex{kpse.set_program_name}}

Sets the \KPATHSEA\ executable (and optionally program) name.

\startfunctioncall
kpse.set_program_name(string name)
kpse.set_program_name(string name, string progname)
\stopfunctioncall

The second argument controls the use of the \quote{dotted} values in the
\type{texmf.cnf} configuration file, and defaults to the first argument.


\subsection{\luatex{kpse.find_file}}

The most often used function in the library is find_file:

\startfunctioncall
string f = kpse.find_file(string filename)
string f = kpse.find_file(string filename, string ftype)
string f = kpse.find_file(string filename, boolean mustexist)
string f = kpse.find_file(string filename, string ftype, boolean mustexist)
string f = kpse.find_file(string filename, string ftype, number dpi)
\stopfunctioncall

Arguments:
\startitemize[intro]

\sym{filename} 

the name of the file you want to find, with or without extension.

\sym{ftype}

maps to the \type {-format} argument of \KPSEWHICH.  The supported
 \type{ftype} values are the same as the ones supported by the 
standalone \type{kpsewhich} program:

\startsimplecolumns
\starttyping
'gf'
'pk'
'bitmap font'
'tfm'
'afm'
'base'
'bib'
'bst'
'cnf'
'ls-R'
'fmt'
'map'
'mem'
'mf'
'mfpool'
'mft'
'mp'
'mppool'
'MetaPost support'
'ocp'
'ofm'
'opl'
'otp'
'ovf'
'ovp'
'graphic/figure'
'tex'
'TeX system documentation'
'texpool'
'TeX system sources'
'PostScript header'
'Troff fonts'
'type1 fonts'
'vf'
'dvips config'
'ist'
'truetype fonts'
'type42 fonts'
'web2c files'
'other text files'
'other binary files'
'misc fonts'
'web'
'cweb'
'enc files'
'cmap files'
'subfont definition files'
'opentype fonts'
'pdftex config'
'lig files'
'texmfscripts'
\stoptyping
\stopsimplecolumns

The default type is \type{tex}.

\sym{mustexist}

is similar to \KPSEWHICH's \type{-must-exist}, and the default is \type{false}.
If you specify \type{true} (or a non|-|zero integer), then the \KPSE\ library
will search the disk as well as the \type {ls-R} databases.

\sym{dpi}

This is used for the size argument of the formats \type{pk}, \type{gf}, and \type{bitmap font}.
\stopitemize

\subsection{\luatex{kpse.init_prog}}

Extra initialization for programs that need to generate bitmap fonts.

\startfunctioncall
kpse.init_prog(string prefix, number base_dpi, string mfmode)
kpse.init_prog(string prefix, number base_dpi, string mfmode, string fallback)
\stopfunctioncall


\subsection{\luatex{kpse.readable_file}}

Test if an (absolute) file name is a readable file

\startfunctioncall
string f = kpse.readable_file(string name)
\stopfunctioncall

The return value is the actual absolute filename you should use,
because the disk name is not always the same as the requested name,
due to aliases and system|-|specific handling under e.\,g.\ \MSDOS.

Returns \lua {nil} if the file does not exist or is not readable.

\subsection{\luatex{kpse.expand_path}}

Like kpsewhich's \type {-expand-path}:

\startfunctioncall
string r = kpse.expand_path(string s)
\stopfunctioncall

\subsection{\luatex{kpse.expand_var}}

Like kpsewhich's  \type{-expand-var}:

\startfunctioncall
string r = kpse.expand_var(string s)
\stopfunctioncall

\subsection{\luatex{kpse.expand_braces}}

Like kpsewhich's \type{-expand-braces}:

\startfunctioncall
string r = kpse.expand_braces(string s)
\stopfunctioncall

\subsection{\luatex{kpse.show_path}}

Like kpsewhich's \type{-show-path}:

\startfunctioncall
string r = kpse.show_path(string ftype)
\stopfunctioncall


\subsection{\luatex{kpse.var_value}}

Like kpsewhich's \type{-var-value}:

\startfunctioncall
string r = kpse.var_value(string s)
\stopfunctioncall

\section{The \luatex{status} library}

This contains a number of run|-|time configuration items that
you may find useful in message reporting, as well as an iterator
function that gets all of the names and values as a table.

\startfunctioncall
table info = status.list()
\stopfunctioncall

The keys in the table are the known items, the value is the current
value.

Almost all of the values in \type{status} are fetched through a
metatable at run|-|time whenever they are accessed, so you cannot use
\type{pairs} on \type{status}, but you {\it can\/} use \type{pairs}
on \type{info}, of course.

If you do not need the full list, you can also ask for a single item
by using its name as an index into \type{status}.

The current list is:

\starttabulate[|lT|p|]
\NC \ssbf key    \NC  \bf explanation \NC\NR
\NC pdf_gone\NC                  written \PDF\ bytes      \NC \NR
\NC pdf_ptr\NC                   not yet written \PDF\ bytes      \NC \NR
\NC dvi_gone\NC                  written \DVI\ bytes      \NC \NR
\NC dvi_ptr\NC                   not yet written \DVI\ bytes      \NC \NR
\NC total_pages\NC               number of written pages      \NC \NR
\NC output_file_name\NC          name of the \PDF\ or \DVI\ file      \NC \NR
\NC log_name\NC                  name of the log file      \NC \NR
\NC banner\NC                    terminal display banner      \NC \NR
\NC var_used\NC                  variable (one|-|word) memory in use \NC \NR
\NC dyn_used\NC                  token (multi|-|word) memory in use  \NC \NR
\NC str_ptr\NC                   number of strings      \NC \NR
\NC init_str_ptr\NC              number of \INITEX\ strings      \NC \NR
\NC max_strings\NC               maximum allowed strings      \NC \NR
\NC pool_ptr\NC                  string pool index      \NC \NR
\NC init_pool_ptr\NC             \INITEX\ string pool index      \NC \NR
\NC pool_size\NC                 current size allocated for string characters \NC \NR
\NC node_mem_usage\NC            a string giving insight into currently used nodes\NC\NR
\NC var_mem_max\NC               number of allocated words for nodes\NC \NR
\NC fix_mem_max\NC               number of allocated words for tokens\NC \NR
\NC fix_mem_end\NC               maximum number of used tokens\NC \NR
\NC cs_count\NC                  number of control sequences      \NC \NR
\NC hash_size\NC                 size of hash       \NC \NR
\NC hash_extra\NC                extra allowed hash  \NC \NR
\NC font_ptr\NC                  number of active fonts      \NC \NR
\NC max_in_stack\NC              max used input stack entries      \NC \NR
\NC max_nest_stack\NC            max used nesting stack entries     \NC \NR
\NC max_param_stack\NC           max used parameter stack entries     \NC \NR
\NC max_buf_stack\NC             max used buffer position      \NC \NR
\NC max_save_stack\NC            max used save stack entries      \NC \NR
\NC stack_size\NC                input stack size      \NC \NR
\NC nest_size\NC                 nesting stack size      \NC \NR
\NC param_size\NC                parameter stack size      \NC \NR
\NC buf_size\NC                  current allocated size of the line buffer \NC \NR
\NC save_size\NC                 save stack size      \NC \NR
\NC obj_ptr\NC                   max \PDF\ object pointer      \NC \NR
\NC obj_tab_size\NC              \PDF\ object table size      \NC \NR
\NC pdf_os_cntr\NC               max \PDF\ object stream pointer      \NC \NR
\NC pdf_os_objidx\NC             \PDF\ object stream index \NC \NR
\NC pdf_dest_names_ptr\NC        max \PDF\ destination pointer       \NC \NR
\NC dest_names_size\NC           \PDF\ destination table size      \NC \NR
\NC pdf_mem_ptr\NC               max \PDF\ memory used      \NC \NR
\NC pdf_mem_size\NC              \PDF\ memory size      \NC \NR
\NC largest_used_mark\NC         max referenced marks class        \NC \NR
\NC filename\NC                  name of the current input file    \NC \NR
\NC inputid\NC                   numeric id of the current input    \NC \NR
\NC linenumber\NC                location in the current input file\NC \NR
\NC lasterrorstring\NC           last error string\NC \NR
\NC luabytecodes\NC              number of active \LUA\ bytecode registers\NC \NR
\NC luabytecode_bytes\NC         number of bytes in \LUA\ bytecode registers\NC \NR
\NC luastates\NC                 number of active \LUA\ interpreters\NC \NR
\NC luastate_bytes\NC            number of bytes in use by \LUA\ interpreters\NC \NR
\NC output_active\NC             \type{true} if the \tex{output} routine is active\NC \NR
\stoptabulate

\section{The \luatex{texconfig} table}

This is a table that is created empty. A startup \LUA\ script could
fill this table with a number of settings that are read out by
the executable after loading and executing the startup file.

\starttabulate[|lT|l|l|p|]
\NC \ssbf key      \NC \bf type     \NC \bf default \NC \bf explanation \NC\NR
\NC string_vacancies \NC   number\NC  75000\NC cf.\ web2c docs \NC \NR
\NC pool_free \NC 	        number\NC  5000\NC cf.\ web2c docs \NC \NR
\NC max_strings \NC        number\NC  15000\NC cf.\ web2c docs \NC \NR
\NC strings_free \NC       number\NC  100\NC cf.\ web2c docs \NC \NR
\NC nest_size \NC 	        number\NC  50\NC cf.\ web2c docs \NC \NR
\NC max_in_open \NC        number\NC  15\NC cf.\ web2c docs \NC \NR
\NC param_size \NC         number\NC  60\NC cf.\ web2c docs \NC \NR
\NC save_size \NC 	        number\NC  4000\NC cf.\ web2c docs \NC \NR
\NC stack_size \NC         number\NC  300\NC cf.\ web2c docs \NC \NR
\NC dvi_buf_size \NC       number\NC  16384\NC cf.\ web2c docs \NC \NR
\NC error_line \NC         number\NC  79\NC cf.\ web2c docs \NC \NR
\NC half_error_line \NC    number\NC  50\NC cf.\ web2c docs \NC \NR
\NC max_print_line \NC     number\NC  79\NC cf.\ web2c docs \NC \NR
\NC ocp_list_size \NC      number\NC 1000\NC cf.\ web2c docs \NC \NR
\NC ocp_buf_size \NC       number\NC 1000\NC cf.\ web2c docs \NC \NR
\NC ocp_stack_size \NC     number\NC 1000\NC cf.\ web2c docs \NC \NR
\NC hash_extra \NC         number\NC  0\NC cf.\ web2c docs \NC \NR
\NC pk_dpi \NC             number\NC  72\NC cf.\ web2c docs \NC \NR
\NC kpse_init \NC boolean \NC true    \NC \type{false} totally disables \KPATHSEA\ initialisation
                                          (only ever unset this if you implement {\it all\/} file
                                          find callbacks!)\NC \NR
\NC trace_file_names \NC boolean \NC true \NC \type{false} disables \TEX's normal file open|-|close
                                              feedback (the assumption is that callbacks will take care of
	                                      that) \NC \NR
\NC src_special_auto  \NC boolean \NC false \NC source specials sub|-|item \NC \NR
\NC src_special_everypar  \NC boolean \NC false \NC source specials sub|-|item \NC \NR
\NC src_special_everyparend  \NC boolean \NC false \NC source specials sub|-|item \NC \NR
\NC src_special_everycr  \NC boolean \NC false \NC source specials sub|-|item \NC \NR
\NC src_special_everymath  \NC boolean \NC false \NC source specials sub|-|item \NC \NR
\NC src_special_everyhbox  \NC boolean \NC false \NC source specials sub|-|item \NC \NR
\NC src_special_everyvbox  \NC boolean \NC false \NC source specials sub|-|item \NC \NR
\NC src_special_everydisplay  \NC boolean \NC false \NC source specials sub|-|item \NC \NR
\NC file_line_error  \NC boolean \NC false \NC do \type{file:line} style error messages\NC \NR
\NC halt_on_error    \NC boolean \NC false \NC abort run on the first encountered error\NC \NR
\NC formatname       \NC string \NC \NC if no format name was given
                                             on the commandline, this key will be tested first
                                             instead of simply quitting\NC \NR
\NC jobname          \NC string \NC \NC if no input file name was given
                                           on the commandline, this key will be tested first
                                           instead of simply giving up\NC \NR
\stoptabulate

\section{The \luatex{font} library}

The font library provides the interface into the internals of the font
system, and also it contains helper functions to load traditional
\TEX\ font metrics formats. Other font loading functionality is
provided by the \luatex{fontforge} library that will be discussed in
the next section.

\subsection{Loading a \TFM\ file}

\startfunctioncall
table fnt = font.read_tfm(string name, number s)
\stopfunctioncall

The number is a bit special:

\startitemize
\item if it is positive, it specifies an \quote{at size} in scaled points.
\item if it is negative, its absolute value represents a \quote{scaled}
setting relative to the designsize of the font.
\stopitemize

The internal structure of the metrics font table that is returned is
explained in \in{chapter}[fonts].

\subsection{Loading a \VF\ file}

\startfunctioncall
table vf_fnt = font.read_vf(string name, number s)
\stopfunctioncall

The meaning of the number \type{s}, and the format of the returned
table is similar to the one returned by the \luatex{read_tfm()} function.

\subsection{The fonts array}

The whole table of \TEX\ fonts is accessible from lua using a virtual array.

\starttyping
font.fonts[n] = { ... }
table f = font.fonts[n]
\stoptyping

See \in{chapter}[fonts] for the structure of the tables. Because this
is a virtual array, you cannot call \type{pairs} on it, but see below
for the \type{font.each} iterator.

The two metatable functions implementing the virtual array are:

\startfunctioncall
table f = font.getfont(number n)
font.setfont(number n, table f)
\stopfunctioncall

Also note the following: assignments can only be made to fonts that
have already been defined in \TEX, but have not been accessed {\it at
all\/} since that definition. This limits the usability of the write
access to \type{font.fonts} quite a lot, a less stringent ruleset will
likely be implemented later.

\subsection{Checking a font's status}

You can test for the status of a font by calling this function:

\startfunctioncall
boolean f = font.frozen(number n)
\stopfunctioncall

The return value is one of true (unassignable), false (can be changed)
or nil (not a valid font at all).

\subsection{Defining a font directly}

You can define your own font into \luatex{font.fonts} by calling this function:

\startfunctioncall
number i = font.define(table f)
\stopfunctioncall

The return value is the internal id number of the defined font (the
index into \luatex{font.fonts}). If the font creation fails, an error is
raised. The table is a font structure, as explained in
\in{chapter}[fonts].

\subsection{Projected next font id}

\startfunctioncall
number i = font.nextid();
\stopfunctioncall

This returns the font id number that would be returned by a
\type{font.define} call if it was executed at this spot in the code
flow. This is useful for virtual fonts that need to reference
themselves.



\subsection{Currently active font}

\startfunctioncall
number i = font.current();
font.current(number i);
\stopfunctioncall

This gets or sets the currently used font number.

\subsection{Maximum font id}

\startfunctioncall
number i = font.max();
\stopfunctioncall

This is the largest used index in \type{font.fonts}.

\subsection{Iterating over all fonts}

\startfunctioncall
for i,v in font.each() do
  ...
end
\stopfunctioncall

This is an iterator over each of the defined \TEX\ fonts. The first
returned value is the index in \type{font.fonts}, the second the font
itself, as a lua table. The indices are listed incrementally, but they
do not always form an array of consecutive numbers: in some cases
there can be holes in the sequence.

\section{The \luatex{fontforge} library}

\subsection{Getting quick information on a font}

\startfunctioncall
local info = fontforge.info('filename')
\stopfunctioncall

This function returns either \type{nil}, or a \type{table}, or an
array of small tables (in the case of a TrueType collection). The
returned table(s) will contain six fairly interesting information
items from the font(s) defined by the file:

\starttabulate[|lT|l|p|]
\NC \ssbf key                      \NC \bf type \NC \bf explanation \NC\NR
\NC fontname                     \NC string   \NC the \quote{PostScript} name of the font\NC\NR
\NC fullname                     \NC string   \NC The formal name of the font\NC\NR
\NC familyname                   \NC string   \NC The family name this font belongs to\NC\NR
\NC weight                       \NC string   \NC A string indicating the color value of the font\NC\NR
\NC version                      \NC string   \NC The internal font version\NC\NR
\NC italicangle                  \NC float    \NC The slant angle\NC\NR
\stoptabulate

Getting information through this function is (sometimes much) more
efficient than loading the font properly, and is therefore handy when
you want to create a dictionary of available fonts based on a
directory contents.

\subsection{Loading an \OPENTYPE\ or \TRUETYPE\ file}

If you want to use an \OPENTYPE\ font, you have to get the metric
information from somewhere. Using the \type{fontforge} library, the
basic way to get that information is thus:


\starttyping
function load_font (filename)
  local metrics = nil
  local font = fontforge.open(filename)
  if font then 
     metrics = fontforge.to_table(font)
     fontforge.close(font)
  end
  return metrics 
end

myfont = load_font('/opt/tex/texmf/fonts/data/arial.ttf')
\stoptyping

The main function call is

\startfunctioncall
f, w = fontforge.open('filename')
\stopfunctioncall

The first return value is a table representation of the font. The
second return value is a table containing any warnings and errors
reported by fontforge while opening the font. In normal typesetting,
you would probably ignore the second argument, but it can be useful
for debugging purposes.

For \TRUETYPE\ collections (when filename ends in 'ttc'), you have to
use a second string argument to specify which font you want from the
collection.  Use one of the \type{fullname} strings that are returned
by \type{fontforge.info} for that.

\startfunctioncall
f, w = fontforge.open('filename','fullname')
\stopfunctioncall


The font file is parsed and partially interpreted by the font
loading routines from \FONTFORGE. The file format can be \OPENTYPE,
\TRUETYPE, \TRUETYPE\ Collection, \CFF, or \TYPEONE.

There are a few advantages to this approach compared to reading the
actual font file ourselves:

\startitemize

\item The font is automatically re|-|encoded, so that the \type{metrics}
   table for \TRUETYPE\ and \OPENTYPE\ fonts is using \UNICODE\ for
   the character indices.

\item Many features are pre|-|processed into a format that is easier to handle
   than just the bare tables would be.

\item \POSTSCRIPT|-|based \OPENTYPE\ fonts do not store the character height and
  depth in the font file, so the character boundingbox has to be
  calculated in some way.

\item In the future, it may be interesting to allow \LUA\ scripts access to
  the font program itself, perhaps even creating or changing the font.

\stopitemize

\subsection{Applying a \quote{feature file}}

You can apply a \quote{feature file} to a loaded font:

\startfunctioncall
fontforge.apply_featurefile(f,'filename')
\stopfunctioncall

A \quote{feature file} is a textual representation of the features in an
OpenType font.  See
\hyphenatedurl{http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html}
and 
\hyphenatedurl{http://fontforge.sourceforge.net/featurefile.html}
for a more detailed description of feature files.


\subsection{Applying an \quote{afm file}}

You can apply an \quote{afm file} to a loaded font:

\startfunctioncall
fontforge.apply_afmfile(f,'filename')
\stopfunctioncall

An \quote{afm file} is a textual representation of (some of) the metainformation
in a Type~1 font. See \hyphenatedurl{http://www.adobe.com/devnet/font/pdfs/5004.AFM_Spec.pdf}
for more information about afm files.

Note: if you \type{fontforge.open()} a PFB file named \type{font.pfb},
the library will automatically search for and apply \type{font.afm},
if it exists in the same directory as \type{font.pfb}. In that case,
there is no need for an explicit call to \type{apply_afmfile()}.


\section{Fontforge font tables}

The top|-|level keys in the returned table are (the explanations in
this part of the documentation are not yet finished):

\starttabulate[|lT|l|p|]
\NC \ssbf key                      \NC \bf type \NC \bf explanation \NC\NR
\NC table_version                \NC number   \NC indicates the metrics version\NC\NR
\NC fontname                     \NC string   \NC \POSTSCRIPT\ font name\NC\NR
\NC fullname                     \NC string   \NC official font name\NC\NR
\NC familyname                   \NC string   \NC family name\NC\NR
\NC weight                       \NC string   \NC weight indicator\NC\NR
\NC copyright                    \NC string   \NC copyright information\NC\NR
\NC filename                     \NC string   \NC the file name\NC\NR
%\NC defbasefilename              \NC string   \NC \NC\NR
\NC version                      \NC string   \NC font version\NC\NR
\NC italicangle                  \NC float    \NC slant angle\NC\NR
\NC units_per_em                 \NC number   \NC 1000 for \POSTSCRIPT-based fonts, usually 2048 for \TRUETYPE\NC\NR
\NC ascent                       \NC number   \NC height of ascender in \type{units_per_em}\NC\NR
\NC descent                      \NC number   \NC depth of descender in \type{units_per_em}\NC\NR
\NC upos                         \NC float    \NC \NC\NR
\NC uwidth                       \NC float    \NC \NC\NR
\NC vertical_origin              \NC number   \NC \NC\NR
\NC uniqueid                     \NC number   \NC \NC\NR
\NC glyphcnt                     \NC number   \NC number of included glyphs\NC\NR
\NC glyphs                       \NC array    \NC \NC\NR
\NC glyphmax                     \NC number   \NC maximum used index the glyphs array\NC\NR
%\NC changed                      \NC number   \NC \NC\NR
\NC hasvmetrics                  \NC number   \NC \NC\NR
\NC order2                       \NC number   \NC set to 1 for \TRUETYPE\ splines, 0 otherwise\NC\NR
\NC strokedfont                  \NC number   \NC \NC\NR
\NC weight_width_slope_only      \NC number   \NC \NC\NR
\NC head_optimized_for_cleartype \NC number   \NC \NC\NR
\NC uni_interp                   \NC enum     \NC \type {unset}, \type {none}, \type {adobe},
                                                    \type {greek}, \type {japanese}, \type {trad_chinese},
                                                    \type {simp_chinese}, \type {korean}, \type {ams}\NC\NR
\NC origname                     \NC string   \NC the file name, as supplied by the user\NC\NR
\NC map                          \NC table    \NC \NC\NR
\NC private                      \NC table    \NC \NC\NR
\NC xuid                         \NC string   \NC \NC\NR
\NC pfminfo                      \NC table    \NC \NC\NR
\NC names                        \NC table    \NC \NC\NR
\NC cidinfo                      \NC table    \NC \NC\NR
\NC subfonts                     \NC array    \NC \NC\NR
\NC cidmaster                    \NC array    \NC \NC\NR
\NC commments                    \NC string   \NC \NC\NR
\NC anchor_classes               \NC table    \NC \NC\NR
\NC ttf_tables                   \NC table    \NC \NC\NR
\NC kerns                        \NC table    \NC \NC\NR
\NC vkerns                       \NC table    \NC \NC\NR
\NC texdata                      \NC table    \NC \NC\NR
\NC lookups                       \NC table    \NC \NC\NR
\NC gpos                          \NC table    \NC \NC\NR
\NC gsub                          \NC table    \NC \NC\NR
\NC chosenname                   \NC string   \NC \NC\NR
\NC macstyle                     \NC number   \NC \NC\NR
\NC fondname                     \NC string   \NC \NC\NR
\NC design_size                  \NC number   \NC \NC\NR
\NC fontstyle_id                 \NC number   \NC \NC\NR
\NC fontstyle_name               \NC table    \NC \NC\NR
\NC design_range_bottom          \NC number   \NC \NC\NR
\NC design_range_top             \NC number   \NC \NC\NR
\NC strokewidth                  \NC float    \NC \NC\NR
\NC mark_classes                 \NC array    \NC \NC\NR
\NC mark_class_names             \NC array    \NC \NC\NR
\NC creationtime                 \NC number   \NC \NC\NR
\NC modificationtime             \NC number   \NC \NC\NR
\NC os2_version                  \NC number   \NC \NC\NR
\stoptabulate

\subsubsection{Glyph items}

The \type{glyphs} is an array containing the per|-|character
information (quite a few of these are only present if nonzero).

\starttabulate[|lT|l|p|]
\NC \ssbf key                      \NC \bf type \NC \bf explanation \NC\NR
\NC name                         \NC string   \NC the glyph name\NC\NR
\NC unicode                      \NC number   \NC unicode code point, or -1\NC\NR
\NC boundingbox                  \NC array    \NC array of four numbers\NC\NR
\NC width                        \NC number   \NC (only for horizontal fonts)\NC\NR
\NC vwidth                       \NC number   \NC (only for vertical fonts)\NC\NR
\NC lsidebearing                 \NC number   \NC (only if nonzero)\NC\NR
\NC glyph_class                  \NC number   \NC (only if nonzero)\NC\NR
\NC kerns                        \NC array    \NC (only for horizontal fonts, if set)\NC\NR
\NC vkerns                       \NC array    \NC (only for vertical fonts, if set)\NC\NR
\NC dependents                   \NC array    \NC linear array of glyph name strings (only if nonempty)\NC\NR
\NC lookups                      \NC table    \NC (only if nonempty)\NC\NR
\NC ligatures                    \NC table    \NC (only if nonempty)\NC\NR
\NC anchors                      \NC table   \NC (only if set)\NC\NR
%\NC color                        \NC number   \NC (only if set)\NC\NR
\NC tex_height                   \NC number   \NC (only if set)\NC\NR
\NC tex_depth                    \NC number   \NC (only if set)\NC\NR
\NC tex_sub_pos                  \NC number   \NC (only if set)\NC\NR
\NC tex_super_pos                \NC number   \NC (only if set)\NC\NR
\NC comment                      \NC string   \NC (only if set)\NC\NR
\stoptabulate

The \type{kerns} and \type{vkerns} are linear arrays of small hashes:

\starttabulate[|lT|l|p|]
\NC \ssbf key                      \NC \bf type \NC \bf explanation \NC\NR
\NC char                         \NC string   \NC \NC\NR
\NC off                          \NC number   \NC \NC\NR
\NC lookup                       \NC string   \NC \NC\NR
\stoptabulate

The \type{lookups} is a hash, based on lookup subtable names, with 
the value of each key inside that a linear array of small hashes:

% TODO: fix this description
\starttabulate[|lT|l|p|]
\NC \ssbf key                      \NC \bf type \NC \bf explanation \NC\NR
\NC type                         \NC enum     \NC \type {position}, \type {pair},  \type {substitution}, \type {alternate},
                                                  \type {multiple}, \type {ligature}, \type {lcaret},  \type {kerning}, \type {vkerning}, \type {anchors},
                                                  \type {contextpos}, \type {contextsub}, \type {chainpos}, \type {chainsub},
                                                  \type {reversesub}, \type {max}, \type {kernback}, \type {vkernback} \NC\NR
\NC specification                 \NC table   \NC extra data \NC\NR
\stoptabulate

For the first seven values of \type{type}, there can be additional
sub|-|information, stored in the sub-table \type{specification}:

\starttabulate[|lT|l|l|p|]
\NC \bf value    \NC \bf type \NC \bf explanation \NC\NR
\NC position     \NC table    \NC a table of the \type {offset_specs} type\NC\NR
\NC pair         \NC table    \NC one string: \type {paired}, and an array of one or 
                                  two \type {offset_specs} tables:  \type{offsets}\NC\NR
\NC substitution \NC table    \NC one string: \type {variant}\NC\NR
\NC alternate    \NC table    \NC one string: \type {components}\NC\NR
\NC multiple     \NC table    \NC one string: \type {components}\NC\NR
\NC ligature     \NC table    \NC two strings: \type {components}, \type {char}\NC\NR
\NC lcaret       \NC array    \NC linear array of numbers\NC\NR
\stoptabulate

Tables for \type{offset_specs} contain up to four number|-|valued
fields: \type{x} (a horizontal offset), \type{y} (a vertical offset),
\type{h} (an advance width correction) and \type{v} (an advance height
correction).

The \type{ligatures} is a linear array of small hashes:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC lig                \NC table    \NC uses the same substructure as a single \type{possub} item\NC\NR
\NC char               \NC string   \NC \NC\NR
\NC components         \NC array    \NC linear array of named components\NC\NR
\NC ccnt               \NC number   \NC \NC\NR
\stoptabulate

The \type{anchor} table is indexed by a string signifying the 
anchor type, which is one of 

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC mark              \NC table   \NC placement mark\NR
\NC basechar          \NC table   \NC mark for attaching combining items to a base char\NR
\NC baselig           \NC table   \NC mark for attaching combining items to a ligature\NR
\NC basemark          \NC table   \NC generic mark for attaching combining items to connect to\NR
\NC centry            \NC table   \NC cursive entry point\NR
\NC cexit             \NC table   \NC cursive exit point\NR
\stoptabulate

The content of these is an short array of defined anchors, with the
entry keys being the anchor names. For all except \type{baselig}, the
value is a single table with this definition:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC x                  \NC number   \NC x location\NC\NR
\NC y                  \NC number   \NC y location\NC\NR
\NC ttf_pt_index       \NC number   \NC truetype point index, only if given\NC\NR
\stoptabulate

For \type{baselig}, the value is a small array of such anchor sets
sets, one for each constituent item of the ligature.

For clarification, an anchor table could for example look like this :
\starttyping
  ['anchor']={
    ['basemark']={
     ['Anchor-7']={ ['x']=170, ['y']=1080 }
    },
    ['mark']={
     ['Anchor-1'] ={ ['x']=160, ['y']=810 },
     ['Anchor-4']= { ['x']=160, ['y']=800 }
    },
    ['baselig']={
     [1] = { ['Anchor-2'] ={ ['x']=160, ['y']=650 } }, 
     [2] = { ['Anchor-2']= { ['x']=460, ['y']=640 } }
    }
   },
\stoptyping



\subsubsection{map table}

The top|-|level map is a list of encoding mappings. Each of those is a table itself.

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC enccount           \NC number   \NC \NC\NR
\NC encmax             \NC number   \NC \NC\NR
\NC backmax            \NC number   \NC \NC\NR
\NC remap              \NC table    \NC \NC\NR
\NC map                \NC array    \NC non|-|linear array of mappings\NC\NR
\NC backmap            \NC array    \NC non|-|linear array of backward mappings\NC\NR
\NC enc                \NC table    \NC \NC\NR
\stoptabulate

The \type{remap} table is very small:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC firstenc           \NC number   \NC \NC\NR
\NC lastenc            \NC number   \NC \NC\NR
\NC infont             \NC number   \NC \NC\NR
\stoptabulate

The \type{enc} table is a bit more verbose:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC enc_name           \NC string   \NC \NC\NR
\NC char_cnt           \NC number   \NC \NC\NR
\NC char_max           \NC number   \NC \NC\NR
\NC unicode            \NC array    \NC of \UNICODE\ position numbers\NC\NR
\NC psnames            \NC array    \NC of \POSTSCRIPT\ glyph names\NC\NR
\NC builtin            \NC number   \NC \NC\NR
\NC hidden             \NC number   \NC \NC\NR
\NC only_1byte         \NC number   \NC \NC\NR
\NC has_1byte          \NC number   \NC \NC\NR
\NC has_2byte          \NC number   \NC \NC\NR
\NC is_unicodebmp      \NC number   \NC (only if nonzero)\NC\NR
\NC is_unicodefull     \NC number   \NC (only if nonzero)\NC\NR
\NC is_custom          \NC number   \NC (only if nonzero)\NC\NR
\NC is_original        \NC number   \NC (only if nonzero)\NC\NR
\NC is_compact         \NC number   \NC (only if nonzero)\NC\NR
\NC is_japanese        \NC number   \NC (only if nonzero)\NC\NR
\NC is_korean          \NC number   \NC (only if nonzero)\NC\NR
\NC is_tradchinese     \NC number   \NC (only if nonzero)\NC\NR
\NC is_simplechinese   \NC number   \NC (only if nonzero)\NC\NR
\NC low_page           \NC number   \NC \NC\NR
\NC high_page          \NC number   \NC \NC\NR
\NC iconv_name         \NC string   \NC \NC\NR
\NC iso_2022_escape    \NC string   \NC \NC\NR
\stoptabulate

\subsubsection{private table}

This is the font's private \POSTSCRIPT\ dictionary, if any. Keys and
values are both strings.

\subsubsection{cidinfo table}

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC registry                  \NC string   \NC \NC\NR
\NC ordering                  \NC string   \NC \NC\NR
\NC supplement                \NC number   \NC \NC\NR
\NC version                   \NC number   \NC \NC\NR
\stoptabulate

\subsubsection{pfminfo table}

The \type{pfminfo} table contains most of the OS/2 information:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC pfmset             \NC number  \NC \NC\NR
\NC winascent_add      \NC number  \NC \NC\NR
\NC windescent_add     \NC number  \NC \NC\NR
\NC hheadascent_add    \NC number  \NC \NC\NR
\NC hheaddescent_add   \NC number  \NC \NC\NR
\NC typoascent_add     \NC number  \NC \NC\NR
\NC typodescent_add    \NC number  \NC \NC\NR
\NC subsuper_set       \NC number  \NC \NC\NR
\NC panose_set         \NC number  \NC \NC\NR
\NC hheadset           \NC number  \NC \NC\NR
\NC vheadset           \NC number  \NC \NC\NR
\NC pfmfamily          \NC number  \NC \NC\NR
\NC weight             \NC number  \NC \NC\NR
\NC width              \NC number  \NC \NC\NR
\NC avgwidth           \NC number  \NC \NC\NR
\NC firstchar          \NC number  \NC \NC\NR
\NC lastchar           \NC number  \NC \NC\NR
\NC fstype             \NC number  \NC \NC\NR
\NC linegap            \NC number  \NC \NC\NR
\NC vlinegap           \NC number  \NC \NC\NR
\NC hhead_ascent       \NC number  \NC \NC\NR
\NC hhead_descent      \NC number  \NC \NC\NR
\NC hhead_descent      \NC number  \NC \NC\NR
\NC os2_typoascent     \NC number  \NC \NC\NR
\NC os2_typodescent    \NC number  \NC \NC\NR
\NC os2_typolinegap    \NC number  \NC \NC\NR
\NC os2_winascent      \NC number  \NC \NC\NR
\NC os2_windescent     \NC number  \NC \NC\NR
\NC os2_subxsize       \NC number  \NC \NC\NR
\NC os2_subysize       \NC number  \NC \NC\NR
\NC os2_subxoff        \NC number  \NC \NC\NR
\NC os2_subyoff        \NC number  \NC \NC\NR
\NC os2_supxsize       \NC number  \NC \NC\NR
\NC os2_supysize       \NC number  \NC \NC\NR
\NC os2_supxoff        \NC number  \NC \NC\NR
\NC os2_supyoff        \NC number  \NC \NC\NR
\NC os2_strikeysize    \NC number  \NC \NC\NR
\NC os2_strikeypos     \NC number  \NC \NC\NR
\NC os2_family_class   \NC number  \NC \NC\NR
\NC os2_xheight        \NC number  \NC \NC\NR
\NC os2_capheight      \NC number  \NC \NC\NR
\NC os2_defaultchar    \NC number  \NC \NC\NR
\NC os2_breakchar      \NC number  \NC \NC\NR
\NC os2_vendor         \NC string  \NC \NC\NR
\NC panose             \NC table  \NC \NC\NR
\stoptabulate

The \type{panose} subtable has exactly 10 string keys:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC familytype             \NC string   \NC Values as in the \OPENTYPE\ font specification:
                                        \type {Any}, \type {No Fit}, \type {Text and Display}, \type {Script},
                                        \type {Decorative}, \type {Pictorial} \NC\NR
\NC serifstyle             \NC string   \NC See the \OPENTYPE\ font specification for values\NC\NR
\NC weight                 \NC string   \NC id. \NC\NR
\NC proportion             \NC string   \NC id. \NC\NR
\NC contrast               \NC string   \NC id. \NC\NR
\NC strokevariation        \NC string   \NC id. \NC\NR
\NC armstyle               \NC string   \NC id. \NC\NR
\NC letterform             \NC string   \NC id. \NC\NR
\NC midline                \NC string   \NC id. \NC\NR
\NC xheight                \NC string   \NC id. \NC\NR
\stoptabulate

\subsubsection{names table}

Each item has two top|-|level keys:

\starttabulate[|lT|l|p|]
\NC \ssbf key         \NC \bf type \NC \bf explanation \NC\NR
\NC lang                   \NC string   \NC language for this entry \NC\NR
\NC names                  \NC table    \NC \NC\NR
\stoptabulate

The \type{names} keys are the actual \TRUETYPE\ name strings. The
possible keys are:

\starttabulate[|lT|p|]
\NC \ssbf key           \NC \bf explanation \NC\NR
\NC copyright   \NC \NC\NR
\NC family   \NC \NC\NR
\NC subfamily   \NC \NC\NR
\NC uniqueid   \NC \NC\NR
\NC fullname   \NC \NC\NR
\NC version   \NC \NC\NR
\NC postscriptname   \NC \NC\NR
\NC trademark   \NC \NC\NR
\NC manufacturer   \NC \NC\NR
\NC designer   \NC \NC\NR
\NC descriptor   \NC \NC\NR
\NC venderurl   \NC \NC\NR
\NC designerurl   \NC \NC\NR
\NC license   \NC \NC\NR
\NC licenseurl   \NC \NC\NR
\NC idontknow   \NC \NC\NR
\NC preffamilyname   \NC \NC\NR
\NC prefmodifiers   \NC \NC\NR
\NC compatfull   \NC \NC\NR
\NC sampletext   \NC \NC\NR
\NC cidfindfontname   \NC \NC\NR
\stoptabulate

\subsubsection{anchor_classes table}

The anchor_classes classes:
 
\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC name                   \NC string   \NC A descriptive id of this anchor class\NC\NR
\NC lookup                 \NC string   \NC \NC\NR
\NC type                   \NC string   \NC One of 'mark', 'mkmk', 'curs', 'mklg' \NC\NR
\stoptabulate
% type is actually a lookup subtype, not a feature name. officiallu, these strings
% should be gpos_mark2mark etc.

\subsubsection{gpos table}

Th gpos table has one array entry for each lookup.

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC type                  \NC string   \NC One of  
  'gpos_single', 'gpos_pair', 'gpos_cursive', 
  'gpos_mark2base', 'gpos_mark2ligature', 'gpos_mark2mark',  'gpos_context', 
  'gpos_contextchain' % ,  'kern_statemachine' 
\NC\NR
\NC flags                 \NC table  \NC \NC\NR
\NC name                  \NC string   \NC \NC\NR
\NC features              \NC array   \NC \NC\NR
\NC subtables             \NC array   \NC \NC\NR
\stoptabulate

The flags table has a true value for each of the lookup flags that is
actually set:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC r2l                    \NC boolean   \NC \NC\NR
\NC ignorebaseglyphs       \NC boolean    \NC \NC\NR
\NC ignoreligatures        \NC boolean    \NC \NC\NR
\NC ignorecombiningmarks   \NC boolean    \NC \NC\NR
\stoptabulate



The features table has:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC tag                    \NC string   \NC \NC\NR
\NC scripts                \NC table    \NC \NC\NR
\NC ismax                  \NC number   \NC (only if true)\NC\NR
\stoptabulate

The scripts table within features has:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC script	               \NC string          \NC \NC\NR
\NC langs                  \NC array of strings \NC \NC\NR
\stoptabulate



The subtables table has:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC name                    \NC string   \NC \NC\NR
\NC suffix                  \NC string   \NC (only if used)\NC\NR % used by gpos_single to get a default
\NC anchor_classes          \NC number   \NC (only if used)\NC\NR
\NC vertical_kerning        \NC number   \NC (only if used)\NC\NR
\NC kernclass               \NC table    \NC (only if used)\NC\NR
\stoptabulate


The kernclass with subtables table has:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
%\NC first_cnt             \NC number   \NC \NC\NR
%\NC second_cnt            \NC number   \NC \NC\NR
\NC firsts                \NC array of strings  \NC \NC\NR
\NC seconds               \NC array of strings   \NC \NC\NR
\NC lookup                \NC string \NC associated lookup \NC \NR
\NC offsets               \NC array of numbers  \NC \NC\NR
%\NC kcid                 \NC number   \NC ? \NC\NR
\stoptabulate

\subsubsection{gsub table}

This has identical layout to the \type{gpos} table, except for the
type:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC type                  \NC string   \NC One of  'gsub_single', 'gsub_multiple', 'gsub_alternate', 
  'gsub_ligature', 'gsub_context',  'gsub_contextchain', 'gsub_reversecontextchain' 
\NC\NR
\stoptabulate



\subsubsection{ttf_tables table}

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC tag                    \NC string   \NC \NC\NR
\NC len                    \NC number   \NC \NC\NR
\NC maxlen                 \NC number   \NC \NC\NR
\NC data                   \NC number   \NC \NC\NR
\stoptabulate

\subsubsection{kerns table}

Substructure is identical to the per|-|glyph subtable.

\subsubsection{vkerns table}

Substructure is identical to the per|-|glyph subtable.

\subsubsection{texdata table}


\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC type                   \NC string   \NC \type {unset}, \type {text}, \type {math}, \type {mathext}\NC\NR
\NC params                 \NC array    \NC 22 font numeric parameters\NC\NR
\stoptabulate

\subsubsection{lookups table}

Top|-|level \type{lookups} is quite different from the ones at
character level. The keys in this hash are strings, the values the
actual lookups, represented as dictionary tables.

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC type                   \NC number   \NC \NC\NR
\NC format                 \NC enum     \NC One of 'glyphs', 'class', 'coverage', 'reversecoverage' \NC\NR
\NC tag                    \NC string   \NC \NC\NR
\NC current_class          \NC array   \NC \NC\NR
\NC before_class           \NC array   \NC \NC\NR
\NC after_class            \NC array   \NC \NC\NR
\NC rules                  \NC array   \NC an array of rule items\NC\NR
\stoptabulate

Rule items have one common item and one specialized item:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC lookups                \NC array    \NC A linear array of lookup names\NC\NR
\NC glyph                  \NC array     \NC Only if the parent's format is \quote{glyph}\NC\NR
\NC class                  \NC array     \NC Only if the parent's format is \quote{glyph}\NC\NR
\NC coverage               \NC array     \NC Only if the parent's format is \quote{glyph}\NC\NR
\NC reversecoverage        \NC array     \NC Only if the parent's format is \quote{glyph}\NC\NR
\stoptabulate
 
A glyph table is:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC names                  \NC string   \NC \NC\NR
\NC back                   \NC string   \NC \NC\NR
\NC fore                   \NC string   \NC \NC\NR
\stoptabulate



A class table is:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC current              \NC array    \NC of numbers \NC\NR
\NC before               \NC array    \NC of numbers  \NC\NR
\NC after                \NC array    \NC of numbers  \NC\NR
\stoptabulate

coverage:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC current                \NC array    \NC of strings \NC\NR
\NC before                 \NC array    \NC of strings\NC\NR
\NC after                  \NC array    \NC of strings \NC\NR
\stoptabulate

reversecoverage:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC current                \NC array    \NC of strings \NC\NR
\NC before                 \NC array    \NC of strings\NC\NR
\NC after                  \NC array    \NC of strings \NC\NR
\NC replacements           \NC string   \NC \NC\NR
\stoptabulate

\section{The \luatex{lang} library}

This library provides the interface to \LUATEX's structure
representing a language, and the associated functions.

\startfunctioncall
<language> l = lang.new()
<language> l = lang.new(number id)
\stopfunctioncall

This function creates a new userdata object. An object of type
\type{<language>} is the first argument to most of the other functions
in the \luatex{lang} library. These functions can also be used as if
they were object methods, using the colon syntax.

Without an argument, the next available internal id number will be
assigned to this object. With argument, an object will be created that
links to the internal language with that id number.

\startfunctioncall
number n = lang.id(<language> l)
\stopfunctioncall

returns the internal \tex{language} id number this object refers to.

\startfunctioncall
string n = lang.hyphenation(<language> l)
lang.hyphenation(<language> l, string n)
\stopfunctioncall

Either returns the current hyphenation exceptions for this language,
or adds new ones. The syntax of the string is explained in the next
chapter,~\in{section}[patternsexceptions].

\startfunctioncall
lang.clear_hyphenation(<language> l)
\stopfunctioncall

Clears the exception dictionary for this language.

\startfunctioncall
string n = lang.clean(string o)
\stopfunctioncall

Creates a hypenation key from the supplied hyphenation value. The
syntax of the argument string is explained in the next
chapter,~\in{section}[patternsexceptions]. This function is useful if
you want to do something else based on the words in a dictionary file,
like spell-checking.

\startfunctioncall
string n = lang.patterns(<language> l)
lang.patterns(<language> l, string n)
\stopfunctioncall

Adds additional patterns for this language object, or returns the
current set. The syntax of this string is explained in the next
chapter,~\in{section}[patternsexceptions].

\startfunctioncall
lang.clear_patterns(<language> l)
\stopfunctioncall

Clears the pattern dictionary for this language.

\startfunctioncall
number n = lang.prehyphenchar(<language> l)
lang.prehyphenchar(<language> l, number n)
\stopfunctioncall

Gets or sets the \quote{pre-break} hyphen character for this font
(initially the hyphen, decimal 45).

\startfunctioncall
number n = lang.posthyphenchar(<language> l)
lang.posthyphenchar(<language> l, number n)
\stopfunctioncall

Gets or sets the \quote{post-break} hyphen character for this font
(initially null, decimal 0).


\startfunctioncall
boolean success = lang.hyphenate(<node> head)
boolean success = lang.hyphenate(<node> head, <node> tail)
\stopfunctioncall

Inserts hyphenation points (discretionary nodes) in a node list. If
\type{tail} is given as argument, processing stops on that node. 
Currently, \type{succes} is always true if \type{head} (and \type{tail}, if
specified) are proper nodes, regardless of possible other errors.

\chapter[languages]{Languages and characters, Fonts and glyphs}

\LUATEX's internal handling of the characters and glyphs that eventually 
become typeset is quite different from the way \TEX82 handles those
same objects. The easiest way to explain the difference is to focus on
unrestricted horizontal mode (i.\,e.\ paragraphs) and hyphenation first.
Later on, it will be easy to deal with the differences that occur in
horizontal and math modes.

In \TEX82, the characters you type are converted into \type{char_node}
records when they are encountered by the main control loop. \TEX\
attaches and processes the font information while creating those
records, so that the resulting \quote{horizontal list} contains the final
forms of ligatures and implicit kerning. 

When it becomes necessary to hyphenate words in a paragraph, \TEX\
converts (one word at time) the \type{char_node} records into a
string array by replacing ligatures with their components and
ignoring the kerning. Then it runs the hyphenation algorithm on this
string, and converts the hyphenated result back into a
\quote{horizontal list} that is consecutively spliced back into 
the paragraph stream.

The \type{char_node} records are somewhat misnamed, as they are glyph
positions in specific fonts, and therefore not really \quote{characters}
in the linguistic sense. There is no language information inside the
\type{char_node} records. Instead, language information is passed along 
using \type{language whatsit} records inside the horizontal list.

In \LUATEX, the situation is quite different. The characters you
type are always converted into \type{glyph_node} records with a
special subtype to identify them as being intended as linguistic
characters. \LUATEX\ stores the needed language information in those
records, but does not do any font-related processing at the time of
node creation.

When it becomes necessary to typeset a paragraph, \LUATEX\ first
inserts all hyphenation points right into the whole node list.
Next, it processes all the font information in the whole list
(creating ligatures and adjusting kerning), and finally it adjusts
all the subtype identifiers so that the records are \quote{glyph
nodes} from now on.

That was the broad overview. The rest of this chapter will deal with the
minutiae of the new process.

\section[charsandglyphs]{Characters and glyphs}

\TEX82 (including \PDFTEX) differentiated between \type{char_node}s
and \type{lig_node}s.  The former are simple items that contained
nothing but a \quote{character} and a \quote{font} field, and they
lived in the same memory as tokens did. The latter also contained a
list of components, and a subtype indicating whether this ligature was
the result of a word boundary, and it was stored in the same place as
other nodes like boxes and kerns and glues.

In \LUATEX, these two types are merged into one, somewhat larger
structure called a \type{glyph_node}. Besides having the old
character, font, and component fields, and the new special fields like
\quote{attr} (see~\in{section}[glyphnodes]), these nodes also contain:

\startitemize
\item A subtype, split into four main types: 
   \startitemize 
   \item \quote{character} -- for characters to be hyphenated
   \item \quote{glyph}  -- for specific font glyphs
   \item \quote{ligature}  -- for ligatures
   \item \quote{ghost}  -- for \quote{ghost objects}
   \stopitemize
   The latter two make further use of two extra fields:
   \startitemize 
   \item \quote{left}  -- for ligatures: created from a left word boundary. 
                    for ghosts:  created from \tex{leftghost}
   \item \quote{right} -- for ligatures: created from a right word boundary. 
                    for ghosts:  created from \tex{rightghost}
   \stopitemize
   for ligatures, both bits can be set at the same time (in case of a single-glyph word).

\item \type{glyph_node}s of type \quote{character} also contain language data, 
  split into four items that were current when the node was created:
  the \tex{setlanguage} (15 bits), \tex{lefthyphenmin} (8 bits),
  \tex{righthyphenmin} (8 bits), and \tex{uchyph} (1 bit).
\stopitemize

Incidentally, \LUATEX\ allows 32768 separate languages, and words can
be 256 characters long.

Because the \tex{uchyph} value is saved in the actual nodes, its
handling is subtly different from \TEX82: changes to \tex{uchyph}
become effective immediately, not at the end of the current partial
paragraph.

Typeset boxes now always have their language information embedded in
the nodes themselves, so there is no longer a possible dependancy on
the surrounding language settings. In \TEX82, a mid-paragraph
statement like \type{\unhbox0} would process the box using the current
paragraph language unless there was a \tex{setlanguage} issued inside
the box. In \LUATEX, all language variables are already frozen.


\section{The main control loop}

In \LUATEX's main loop, almost all input characters that are to be
typeset are converted into \type{glyph_node} records with subtype
\quote{character}, but there are a few small exceptions.

First, the \tex{accent} primitives creates nodes with subtype \quote{glyph}
instead of \quote{character}: one for the actual accent and one for the
accentee. The primary reason for this is that \tex{accent} in \TEX82
is explicitly dependent on the current font encoding, so it would not
make much sense to attach a new meaning to the primitive's name, as
that would invalidate many old documents and macro packages. A
secondary reason is that in \TEX82, \tex{accent} prohibits hyphenation
of the current word. Since in \LUATEX\ hyphenation only takes place on
\quote{character} nodes, it is possible to achieve the same effect.

This change of meaning did happen with \tex{char}, that now generates
\quote{character} nodes, consistent with its changed meaning in \XETEX.
The changed status of \tex{char} is not yet finalized, but if it stays
as it is now, a new primitive \tex{glyph} should be added to directly
insert a font glyph id.

Second, all the results of processing in math mode eventually become
nodes with \quote{glyph} subtypes.

Third, the \ALEPH-derived commands \tex{leftghost} and
\tex{rightghost} create nodes of a third subtype: \quote{ghost}. These nodes
are ignored completely by all further processing until the stage where
inter-glyph kerning is added.

Fourth, automatic discretionaries are handled differently. \TEX82
inserts an empty discretionary after sensing an input character that
matches the \tex{hyphenchar} in the current font. This test is wrong,
in our opinion: wether or not hyphenation takes place should not
depend on the current font, it is a language property.

In \LUATEX, it works like this: if \LUATEX\ senses a string of input
characters that matches the value of the new integer parameter
\tex{exhyphenchar}, it will insert an empty discretionary after that
series of nodes. Initex sets the \type{\exhyphenchar=`\-}. 
Incidentally, this is a global parameter instead of a
language-specific one because it may be useful to change the value
depending on the document structure instead of the text language. 

The exact status and meaning of \tex{hyphenchar} is still under
consideration, it will probably become used in the character to glyph
conversion stage. Currently it is simply ignored.

Fifth, \tex{setlanguage} no longer creates whatsits. The meaning of
\tex{setlanguage} is changed so that it is now an integer parameter 
like all others. That integer parameter is used in \tex{glyph_node}
creation to add language information to the glyph nodes. In
conjunction, the \tex{language} primitive is extended so that it
always also updates the value of \tex{setlanguage}.

Sixth, the \tex{noboundary} command (this command prohibits word
boundary processing where that would normally take place) now does
create whatsits. These whatsits are needed because the exact place of
the \tex{noboundary} command in the input stream has to be retained
until after the ligature and font processing stages.

Finally, there is no longer a \type{main_loop} label in the
code. Remember that \TEX82 did quite a lot of processing while adding
\type{char_nodes} to the horizontal list? For speed reasons, it handled 
that processing code outside of the \quote{main control} loop, and only the
first character of any \quote{word} was handled by that \quote{main control} loop.
In \LUATEX, there is no longer a need for that (all hard work is done
later), and the (now very small) bits of character-handling code have
been moved back inline. When \tex{tracingcommands} is on, this is
visible because the full word is reported, instead of just the initial
character.


\section[patternsexceptions]{Loading patterns and exceptions}

The hyphenation algorithm in \LUATEX\ is quite different from the one
in \TEX82, although it uses essentially the same user input.

After expansion, the argument for \tex{patterns} has to be proper
UTF-8, no \tex{char} or \tex{chardef-ed} commands are allowed. (The
current implementation is even more strict, and will reject all
non-unicode characters, but that will be changed in the future. For
now, the generated errors are a valuable tool in discovering
font-encoding specific pattern files)

Likewise, the expanded argument for \tex{hyphenation} also has to be
proper UTF-8, but here a tiny little bit of extra syntax is provided:

\startitemize[n]
\item three sets of arguments in curly braces (\type{{}{}{}})
   indicates a desired complex discretionary, with arguments 
   as in \tex{discretionary}'s command in normal document input.
\item \type{-} indicates a desired simple discretionary,  cf. \type{\-} and 
   \type{\discretionary{-}{}{}} in normal document input.
\item Internal command names are ignored. This rule is provided 
   especially for \tex{discretionary}, but it also helps to deal with
  \tex{relax} commands that may sneak in.
\item \type{=} indicates a hyphen in the document input (but that
  is only useful in documents where \tex{exhyphenchar} is not equal to
  the hyphen).
\stopitemize

The expanded argument is first converted back to a space-separated
string while dropping the internal command names. This string is then
converted into a dictionary by a routine that creates key||value pairs
by converting the other listed items. It is important to note that the
keys in an exception dictionary can always be generated from the
values. Here are a few examples:

\starttabulate[|l|l|l|]
\NC \ssbf value          \NC \ssbf implied key (input) \NC \ssbf effect\NC\NR 
\NC \type{ta-ble}        \NC table  \NC \type{ta\-ble} 
                                        ($=$ \type{ta\discretionary{-}{}{}ble})\NC\NR
\NC \type{ba{k-}{}{c}ken}\NC backen \NC \type{ba\discretionary{k-}{}{c}ken}\NC\NR
\stoptabulate

The resultant patterns and exception dictionary will be stored under
the language code that is the present value of \tex{language}. 

In the last line of the table, you see there is no \tex{discretionary}
command in the value: the command is optional in the \TEX-based input
syntax. The underlying reason for that is that it is conceivable that
a whole dictionary of words is stored as a plain text file and loaded
into \LUATEX\ using one of the functions in the Lua \luatex{lang}
library. This loading method is quite a bit faster than going through
the \TEX\ language primitives, but some (most?) of that speed gain
would be lost if it had to interpret command sequences while doing so.

The motivation behind the \ETEX\ extension \tex{savinghyphcodes} was
that hyphenation heavily depended on font encodings. This is no longer
true in \LUATEX, and the corresponding primitive is ignored pending
complete removal. The future semantics of \tex{uppercase} and
\tex{lowercase} are still under consideration, no changes have taken
place yet.


\section{Applying hyphenation}

The internal structures \LUATEX\ uses for the insertion of
discretionaries in words is very different from the ones in \TEX82,
and that means there are some noticable differences in handling as
well.

First and foremost, there is no \quote{compressed trie} involved in
hyphenation. The algorithm still reads \PATGEN-generated pattern
files, but \LUATEX\ uses a finite state hash to match the patterns
against the word to be hyphenated. This algorithm is based on the
\quote{libhnj} library used by OpenOffice. 
The memory allocation for this new implementation is completely
dynamic, so the \WEBC\ setting for \type{trie_size} is ignored.

Differences between \LUATEX\ and \TEX82 that are a direct result of that:

\startitemize
\item \LUATEX\ happily hyphenates the full Unicode character range.
\item Pattern and exception dictionary size is limited by the
  available memory only, all allocations are done dynamically.
  The trie-related settings in \type{texmf.cnf} are ignored.
\item Because there is no \quote{trie preparation} stage, language patterns 
  never become frozen. This means that the primitive \tex{patterns}
  (and its lua counterpart \luatex{lang.patterns}) can be used at any
  time, not only in initex.
\item Only the string representation of \tex{patterns} and 
  \tex{hyphenation} is stored in the format file. At format load time,
  they are simply re-evaluated. It follows that there is no real 
  reason to preload languages in the format file. In fact, it is 
  usually not a good idea to do so. It is much smarter to load 
  patterns no sooner than the first time they are actually needed.
\item \LUATEX\ uses the language-specific variables
\tex{prehyphenchar} and \tex{posthyphenchar} in the creation of 
discretionaries, instead of \TEX82's \tex{hyphenchar}.
\stopitemize

Previously, there were problems with changing the node attributes
mid-word, but that problem is now solved, as nodes in a word are not
converted to and from a string any more (this was required by the old
hyphenation code), they are edited in place. Inserted characters and
ligatures inherit their attributes from the nearest glyph node item
(usually the preceding one, but the following one for the items
inserted at the left-hand side of a word).

Word boundaries are no longer implied by font switches, but by
language switches. One word can have two separate fonts and still be
hyphenated correctly (but it can not have two different languages,
the \tex{setlanguage} command forces a word boundary).

All languages start out with \type{\prehyphenchar=`\-} and
\type{\posthyphenchar=0}. When you assign the values of
\tex{prehyphenchar} and \tex{posthyphenchar}, you are actually
changing the settings for the current \tex{language}, this behavior
is compatible with \tex{patterns} and \tex{hyphenation}.

\LUATEX\ also hyphenates the first word in a paragraph. 

Words can be up to 256 characters long (up from 64 in \TEX82).  Longer
words generate an error right now, but eventually either the
limitation will be removed or perhaps it will become possbile to
silently ignore the excess characters (this is what happens in \TEX82,
but there the behavior cannot be controlled).

If you are using the Lua function \type{lang.hyphenate}, you should be
aware that this function expects to receive a list of \quote{character}
nodes. It will not operate properly in the presence of \quote{glyph},
\quote{ligature}, or \quote{ghost} nodes, nor does it know how to deal with
kerning.  In the near future, it will be able to skip over \quote{ghost}
nodes, and we may add a less fuzzy function you can call as well.

The hyphenation exception dictionary is maintained as key-value
hash, and that is also dynamic, so the \type{hyph_size} setting is not
used either.

A technical paper detailing the new algorithm will be released as a
separate document.

\section{Applying ligatures and kerning}

After all possible hyphenation points have been inserted in the list,
\LUATEX\ will process the list to convert the \quote{character} nodes into 
\quote{glyph} and \quote{ligature} nodes. This is actually done in two stages:
first all ligatures are processed, then all kerning information is
applied to the result list. But those two stages are somewhat
dependent on each other: If the used font makes it possible to do so,
the ligaturing stage adds virtual \quote{character} nodes to the word
boundaries in the list. While doing so, it removes and interprets
\type{noboundary} nodes. The kerning stage deletes those word boundary 
items after it is done with them, and it does the same for \quote{ghost}
nodes. Finally, at the end of the kerning stage, all remaining
\quote{character} nodes are converted to \quote{glyph} nodes.

This work separation is worth mentioning because, if you overrule from
Lua only one of the two callbacks related to font handling, then you
have to make sure you perform the tasks normally done by \LUATEX\
itself in order to make sure that the other, non-overrruled, routine
continues to function properly.

Work in this area is not yet complete, but most of the possible cases
are handled by our rewritten ligaturing engine. We are working hard to
make sure all of the possible inputs will become supported soon.

For example, take the word \type{office}, hyphenated \type{of-fice},
using a \quote{normal} font with all the \type{f}-\type{i} ligatures:
\starttabulate[|l|l|]
\NC Initial:               \NC \type{{o}{f}{f}{i}{c}{e}}           \NC\NR
\NC After hyphenation:     \NC \type{{o}{f}{{-},{},{}}{f}{i}{c}{e}}\NC\NR
\NC First ligature stage:  \NC \type{{o}{{f}{-},{f},{ff}}{i}{c}{e}}\NC\NR
\NC Final result:          \NC \type{{o}{{f}{-},{fi},{ffi}}{c}{e}} \NC\NR
\stoptabulate

That's bad enough, but if there was a hyphenation point between the
\type{f} and the \type{i}: \type{of-f-ice}, the final result should be: 
\starttyping
   {o}{{f}{-},
       {{f}{-},
        {i},
        {fi}},
       {{ff}{-},
        {i},
        {ffi}}}{c}{e}
\stoptyping
with discretionaries in the post-break text as well as in the
replacement text of the top-level discretionary that resulted from the
first hyphenation point.  And this is only a simple case.

\section{Breaking paragraphs into lines}

This code is still almost unchanged, but because of the
above-mentioned changes with respect to discretionaries and ligatures,
line breaking will potentially be different from traditional \TEX.
The actual line breaking code is still based on the \TEX82 algorithms,
and it does not expect there to be discretionaries inside of
discretionaries. 

But that situation is now fairly common in \LUATEX, due to the changes
to the ligaturing mechanism. And also, the \LUATEX\ discretionary
nodes are implemented slightly different from the \TEX82 nodes: the
\type{no_break} text is now embedded inside the disc node, where 
previously these nodes kept their place in the horizontal list (the
discretionary node contained a counter indicating how many nodes to
skip).

The combined effect of these two differences is that \LUATEX\ does not
always use all of the potential breakpoints in a paragraph, especially
when fonts with many ligatures are used.

% TODO: 
%   Check \sfcode handling
%   Implement \glyph
%
%   Remove \savinghyphcodes
%   Allow non-UCS characters in \patterns

\chapter[fonts]{Font structure}

All \TEX\ fonts are represented to \LUA\ code as tables, and
internally as C~structures. All keys in the table below are saved in
the internal font structure if they are present in the table returned
by the
\luatex{define_font} callback, or if they result from the normal \TFM|/|\VF\
reading routines if there is no \luatex{define_font} callback defined.

The column \quote{from \VF} means that this key will be created by the
\luatex{font.read_vf()} routine, \quote{from \TFM} means that the key will be created
by the \luatex{font.read_tfm()} routine, and \quote{used} means whether or not the
\LUATEX\ engine itself will do something with the key.

The top|-|level keys in the table are as follows:

\starttabulate[|l|l|l|l|l|p|]
\NC \ssbf key            \NC \bf from vf \NC \bf from tfm \NC \bf used\NC \bf value type \NC \bf description \NC\NR
\NC name               \NC yes      \NC yes      \NC yes \NC string \NC metric (file) name\NC\NR
\NC area               \NC no       \NC yes      \NC yes \NC string \NC (directory) location, typically empty\NC\NR
\NC used               \NC no       \NC yes      \NC yes \NC boolean\NC used already? (initial: false)\NC \NR
\NC characters         \NC yes      \NC yes      \NC yes \NC table  \NC the defined glyphs of this font \NC \NR
\NC checksum           \NC yes      \NC yes      \NC no  \NC number \NC default: 0 \NC \NR
\NC designsize         \NC no       \NC yes      \NC yes \NC number \NC expected size (default: 655360 == 10pt) \NC \NR
\NC direction          \NC no       \NC yes      \NC yes \NC number \NC default: 0 (LTR) \NR
\NC encodingbytes      \NC no       \NC no       \NC yes \NC number \NC default: depends on \type {format}\NC\NR
\NC encodingname       \NC no       \NC no       \NC yes \NC string \NC encoding name\NC\NR
\NC fonts              \NC yes      \NC no       \NC yes \NC table  \NC locally used fonts\NC \NR
\NC fullname           \NC no       \NC no       \NC yes \NC string \NC actual (\POSTSCRIPT) name\NC\NR
\NC header             \NC yes      \NC no       \NC no  \NC string \NC header comments, if any\NC \NR
\NC hyphenchar         \NC no       \NC no       \NC yes \NC number \NC default: TeX's \tex{hyphenchar} \NC \NR
\NC parameters         \NC no       \NC yes      \NC yes \NC hash   \NC default: 7 parameters, all zero \NC \NR
\NC size               \NC no       \NC yes      \NC yes \NC number \NC loaded (at) size. (default: same as designsize) \NC \NR
\NC skewchar           \NC no       \NC no       \NC yes \NC number \NC default: TeX's \tex{skewchar}  \NC \NR
\NC type               \NC yes      \NC no       \NC yes \NC string \NC basic type of this font\NC \NR
\NC format             \NC no       \NC no       \NC yes \NC string \NC disk format type\NC \NR
\NC embedding          \NC no       \NC no       \NC yes \NC string \NC \PDF\ inclusion\NC \NR
\NC filename           \NC no       \NC no       \NC yes \NC string \NC disk file name\NC\NR
\NC tounicode          \NC no       \NC yes      \NC yes \NC number \NC if 1, \LUATEX\ assumes per-glyph tounicode entries are
present in the font\NC\NR
\NC stretch            \NC no       \NC no       \NC yes \NC number \NC the `stretch' value from \type{\pdffontexpand}\NC\NR
\NC shrink             \NC no       \NC no       \NC yes \NC number \NC the `shrink' value from \type{\pdffontexpand}\NC\NR
\NC step               \NC no       \NC no       \NC yes \NC number \NC the `step' value from \type{\pdffontexpand}\NC\NR
\NC auto_expand        \NC no       \NC no       \NC yes \NC boolean\NC the `autoexpand keyword from \type{\pdffontexpand}\NC\NR
\NC expansion_factor   \NC no       \NC no       \NC no  \NC number \NC the actual expansion factor of an expanded font\NC\NR
\NC attributes         \NC no       \NC no       \NC yes \NC string \NC the \type{\pdffontattr}\NC\NR
\stoptabulate

The key \type{name} is always required.

The keys \type{stretch}, \type{shrink}, \type{step} and optionally \type{auto_expand} 
only have meaning when used together: they can be used to replace a post-loading
\type{\pdffontexpand} command. 

The \type{expansion_factor} is value that can be present inside a font in \type{font.fonts}.
It is the actual expansion factor (a value between \type{-shrink} and \type{stretch}, with
step \type{step}) of a font that was automatically generated by the font expansion algorithm.

The key \type{attributes} can be used to replace \type{\pdffontattr}.

The key \type{used} is set by the engine when a font is actively in
use, this makes sure that the font's definition is written to the
output file (\DVI\ or \PDF). The \TFM\ reader sets it to false.

The \type{direction} is a number signalling the \quote{normal} direction for
this font. There are sixteen possibilities:

\starttabulate[|c|c|c|c|]
\NC \bf number \NC \bf meaning \NC \bf number \NC \bf meaning \NC\NR
\NC 0          \NC LT          \NC 8          \NC TT          \NC\NR
\NC 1          \NC LL          \NC 9          \NC TL          \NC\NR
\NC 2          \NC LB          \NC 10         \NC TB          \NC\NR
\NC 3          \NC LR          \NC 11         \NC TR          \NC\NR
\NC 4          \NC RT          \NC 12         \NC BT          \NC\NR
\NC 5          \NC RL          \NC 13         \NC BL          \NC\NR
\NC 6          \NC RB          \NC 14         \NC BB          \NC\NR
\NC 7          \NC RR          \NC 15         \NC BR          \NC\NR
\stoptabulate

These are \OMEGA|-|style direction abbreviations: the first character
indicates the \quote{first} edge of the character glyphs (the edge that is
seen first in the writing direction), the second the \quote{top} side.

The \type{parameters} is a hash with mixed key types. There are seven
possible string keys, as well as a number of integer indices (these
start from 8 up). The seven strings are actually used instead of the
bottom seven indices, because that gives a nicer user interface.

The names and their internal remapping:

\starttabulate[|l|c|]
\NC \bf name      \NC \bf internal remapped number \NC\NR
\NC slant         \NC 1  \NC\NR
\NC space         \NC 2  \NC\NR
\NC space_stretch \NC 3  \NC\NR
\NC space_shrink  \NC 4  \NC\NR
\NC x_height      \NC 5  \NC\NR
\NC quad          \NC 6  \NC\NR
\NC extra_space   \NC 7  \NC\LR
\stoptabulate

The keys \type{type}, \type{format}, \type{embedding}, \type{fullname} and
\type{filename} are used to embed \OPENTYPE\ fonts in the result \PDF.

The \type{characters} table is a list of character hashes indexed by
an integer number. The number is the \quote{internal code} \TEX\ knows this
character by.

Two very special string indexes can be used also: \type{left_boundary} is a
virtual character whose ligatures and kerns are used to handle word
boundary processing. \type{right_boundary} is similar but not actually
used for anything (yet!).

Other index keys are ignored.

Each character hash itself is a hash. For example, here is the
character \quote{f} (decimal 102) in the font cmr10 at 10 points:

% hahe: why this complicated notation, why not e. g. width=200250?
\starttyping
[102] = {
  ['width'] = 200250,
  ['height'] = 455111,
  ['depth'] = 0,
  ['italic'] = 50973,
  ['kerns'] = {
     [63] = 50973,
     [93] = 50973,
     [39] = 50973,
     [33] = 50973,
     [41] = 50973
  },
  ['ligatures'] = {
    [102] = {
       ['char'] = 11,
       ['type'] = 0
    },
    [108] = {
       ['char'] = 13,
       ['type'] = 0
    },
    [105] = {
       ['char'] = 12,
       ['type'] = 0
    }
  }
}
\stoptyping

The following top|-|level keys can be present inside a character hash:

\starttabulate[|l|c|c|c|l|p|]
\NC \ssbf key    \NC \bf from vf \NC \bf from tfm \NC \bf used \NC \bf value type \NC \bf description \NC\NR
\NC width      \NC yes         \NC yes          \NC yes      \NC number         \NC character's width, in sp (default 0) \NC\NR
\NC height     \NC no          \NC yes          \NC yes      \NC number         \NC character's height, in sp (default 0) \NC\NR
\NC depth      \NC no          \NC yes          \NC yes      \NC number         \NC character's depth, in sp (default 0) \NC\NR
\NC italic     \NC no          \NC yes          \NC yes      \NC number         \NC character's italic correction, in sp (default zero) \NC\NR
\NC left_protruding  \NC no    \NC no           \NC maybe    \NC number         \NC character's \type{\lpcode}\NC\NR
\NC right_protruding \NC no    \NC no           \NC maybe    \NC number         \NC character's \type{\rpcode}\NC\NR
\NC expansion_factor \NC no    \NC no           \NC maybe    \NC number         \NC character's \type{\efcode}\NC\NR
\NC tounicode  \NC no          \NC no           \NC maybe    \NC string         \NC character's Unicode equivalent(s), in
UTF-16BE hexadecimal format\NC\NR
\NC next       \NC no          \NC yes          \NC yes      \NC number         \NC the \quote{next larger} character index \NC\NR
\NC extensible \NC no          \NC yes          \NC yes      \NC table          \NC the constituent parts of an extensible recipe \NC\NR
\NC kerns      \NC no          \NC yes          \NC yes      \NC table          \NC kerning information \NC\NR
\NC ligatures  \NC no          \NC yes          \NC yes      \NC table          \NC ligaturing information \NC\NR
\NC commands   \NC yes         \NC no           \NC yes      \NC array          \NC virtual font commands \NC\NR
\NC name       \NC no          \NC no           \NC no       \NC string         \NC the character (\POSTSCRIPT) name \NC\NR
\NC index      \NC no          \NC no           \NC yes      \NC number         \NC the (\OPENTYPE\ or \TRUETYPE) font glyph index \NC\NR
\NC used       \NC no          \NC yes          \NC yes      \NC boolean        \NC typeset already (default: false)? \NC\NR
\stoptabulate

The values of \type{left_protruding} and \type{right_protruding} are used only when
\type{\pdfprotrudechars} is non-zero.

Whether or not \type{expansion_factor} is used depends on the font's global expansion
settings, as well as on the value of \type{\pdfadjustspacing}.

The usage of \type{tounicode} is this: if this font specifies a \type{tounicode=1} at
the top level, then \LUATEX\ will construct a \type{/ToUnicode} entry for the PDF
font (or font subset) based on the character-level \type{tounicode} strings, where
they are available. If a character does not have a sensible Unicode equivalent,
do not provide a string either (no empty strings).

If the font-level \type{tounicode} is not set, then \LUATEX\ will build up
\type{/ToUnicode} based on the \TEX\ code points you used, and any character-level
\type{tounicodes} will be ignored. {\it At the moment, the string format is exactly the
format that is expected by Adobe CMAP files (UTF-16BE in hexadecimal encoding), minus
the enclosing angle brackets. This may change in the future.} Small example: the
\type{tounicode} for a \type{fi} ligature would be \type{00660069}.

The presence of \type{extensible} will overrule \type{next}, if that is also present.

The \type{extensible} table is very simple:

\starttabulate[|l|l|p|]
\NC \ssbf key \NC \bf type \NC \bf description                    \NC\NR
\NC top     \NC number   \NC \quote{top} character index        \NC\NR
\NC mid     \NC number   \NC \quote{middle} character index     \NC\NR
\NC bot     \NC number   \NC \quote{bottom} character index     \NC\NR
\NC rep     \NC number   \NC \quote{repeatable} character index \NC\NR
\stoptabulate

The \type{kerns} table is a hash indexed by character index (and
\quote{character index} is defined as either a non|-|negative integer or the
string value \type {right_boundary}), with the values the kerning to be
applied, in scaled points.

The \type{ligatures} table is a hash indexed by character index (and
\quote{character index} is defined as either a non|-|negative integer or the
string value \type {right_boundary}), with the values being yet another small
hash, with two fields:

\starttabulate[|l|l|p|]
\NC \ssbf key \NC \bf type \NC \bf description \NC\NR
\NC type    \NC number   \NC the type of this ligature command, default 0 \NC\NR
\NC char    \NC number   \NC the character index of the resultant ligature \NC\NR
\stoptabulate

The \type{char} field in a ligature is required.

The \type{type} field inside a ligature is the numerical or string value of one of the eight
possible ligature types supported by \TEX.  When \TEX\ inserts a new ligature, it puts the new
glyph in the middle of the left and right glyphs. The original left and right glyphs can
optionally be retained, and when at least one of them is kept, it is also possible to move the
new \quote{insertion point} forward one or two places. The glyph that ends up to the right of the
insertion point will become the next \quote{left}.

\starttabulate[|l|c|l|l|]
\NC \bf textual (Knuth) \NC \bf number \NC \bf string    \NC result \NC\NR
\NC l + r =: n          \NC 0          \NC \type{=:}     \NC \|n    \NC\NR
\NC l + r =:\| n        \NC 1          \NC \type{=:|}    \NC \|nr   \NC\NR
\NC l + r \|=: n        \NC 2          \NC \type{|=:}    \NC \|ln   \NC\NR
\NC l + r \|=:\| n      \NC 3          \NC \type{|=:|}   \NC \|lnr  \NC\NR
\NC l + r  =:\|\> n     \NC 5          \NC \type{=:|>}   \NC n\|r   \NC\NR
\NC l + r \|=:\> n      \NC 6          \NC \type{|=:>}   \NC l\|n   \NC\NR
\NC l + r \|=:\|\> n    \NC 7          \NC \type{|=:|>}  \NC l\|nr  \NC\NR
\NC l + r \|=:\|\>\> n  \NC 11         \NC \type{|=:|>>} \NC ln\|r  \NC\NR
\stoptabulate

The default value is~0, and can be left out. That signifies a \quote{normal}
ligature where the ligature replaces both original glyphs. In this table
the~\| indicates the final insertion point.

The \type{commands} array is explained below.

\section {Real fonts}

Whether or not a \TEX\ font is a \quote{real} font that should be written to
the \PDF\ document is decided by the \type{type} value in the top|-|level
font structure. If the value is \type{real}, then this is a proper
font, and the inclusion mechanism will attempt to add the needed
font object definitions to the \PDF.

Values for \type{type}:

\starttabulate[|l|p|]
\NC \bf value     \NC \bf description        \NC\NR
\NC real          \NC this is a base font    \NC\NR
\NC virtual       \NC this is a virtual font \NC\NR
\stoptabulate

The actions to be taken depend on a number of different variables:

\startitemize[packed]
\item Whether the used font fits in an 8-bit encoding scheme or not
\item The type of the disk font file
\item The level of embedding requested
\stopitemize

A font that uses anything other than an 8-bit encoding vector has to
be written to the \PDF\ in a different way.

The rule is: if the font table has \type {encodingbytes} set to~2,
then this is a wide font, in all other cases it isn't. The value~2 is
the default for \OPENTYPE\ and \TRUETYPE\ fonts loaded via \LUA. For
\TYPEONE\ fonts, you have to set \type {encodingbytes} to~2
explicitly. For \PK\ bitmap fonts, wide font encoding is not
supported at all.

If no special care is needed, \LUATEX\ currently falls back to the
mapfile|-|based solution used by \PDFTEX\ and \DVIPS. This behavior
will be removed in the future, when the existing code becomes
integrated in the new subsystem.

But if this is a \quote{wide} font, then the new subsystem kicks in, and
some extra fields have to be present in the font structure. In this
case, \LUATEX\ does not use a map file at all.

The extra fields are: \type{format}, \type{embedding}, \type{fullname},
\type{cidinfo} (as explained above), \type{filename}, and the
\type{index} key in the separate characters.

Values for \type{format} are:

\starttabulate[|l|p|]
\NC \bf value \NC \bf description                                           \NC\NR
\NC type1     \NC this is a \POSTSCRIPT\ \TYPEONE\ font                     \NC\NR
\NC type3     \NC this is a bitmapped (\PK) font                            \NC\NR
\NC truetype  \NC this is a \TRUETYPE\ or \TRUETYPE|-|based \OPENTYPE\ font \NC\NR
\NC opentype  \NC this is a \POSTSCRIPT|-|based \OPENTYPE\ font             \NC\NR
\stoptabulate

(\type{type3} fonts are provided for backward compatibility only, and do not
support the new wide encoding options.)

Values for \type{embedding} are:

\starttabulate[|l|p|]
\NC \bf value \NC \bf description \NC\NR
\NC no        \NC don't embed the font at all \NC\NR
\NC subset    \NC include and atttempt to subset the font \NC\NR
\NC full      \NC include this font in its entirety \NC\NR
\stoptabulate

It is not possible to artificially modify the transformation matrix
for the font at the moment.

The other fields are used as follows: The \type{fullname} will be the
\POSTSCRIPT|/|\PDF\ font name. The \type{cidinfo} will be used as the
character set (the CID \type{/Ordering} and \type{/Registry} keys). The
\type{filename} points to the actual font file. If you include the
full path in the \type{filename} or if the file is in the local
directory, \LUATEX\ will run a little bit more efficient because it
will not have to re|-|run the \type{find_xxx_file} callback in that
case.

Be careful: when mixing old and new fonts in one document, it is possible to
create \POSTSCRIPT\ name clashes that can result in printing
errors. When this happens, you have to change the \type{fullname}
of the font.

Typeset strings are written out in a wide format using 2~bytes per
glyph, using the \type{index} key in the character information as
value. The overall effect is like having an encoding based on numbers
instead of traditional (\POSTSCRIPT) name|-|based reencoding. The way
to get the correct \type{index} numbers for \TYPEONE\ fonts is by
loading the font via \type{fontforge.open}; use the table indices as
\type{index} fields.

This type of reencoding means that there is no longer a clear
connection between the text in your input file and the strings in the
output \PDF\ file. Dealing with this is high on the agenda.

\section {Virtual fonts}

You have to take the following steps if you want \LUATEX\ to treat the
returned table from \luatex{define_font} as a virtual font:

\startitemize[packed]
\item Set the top|-|level key \type {type} to \type {virtual}.
\item Make sure there is at least one valid entry in \luatex{fonts} (see below)
\item Give a \type {commands} array to every character (see below)
\stopitemize

The presence of the toplevel \type {type} key with the specific value
\type {virtual} will trigger handling of the rest of the special virtual
font fields in the table, but the mere existance of 'type' is enough
to prevent \LUATEX\ from looking for a virtual font on its own.

Therefore, this also works \quote{in reverse}: if you are absolutely certain
that a font is not a virtual font, assigning the value \type{base} or
\type{real} to \type{type} will inhibit \LUATEX\ from looking for a virtual font
file, thereby saving you a disk search.

The \luatex{fonts} is another \LUA\ array. The values are one- or two|-|key
hashes themselves, each entry indicating one of the base fonts in a
virtual font. An example makes this easy to understand

\starttyping
fonts = { { name = 'ptmr8a', size = 655360},
          { name = 'psyr', size = 600000},
          { id = 38 } }
\stoptyping

says that the first referenced font (index 1) in this virtual font is
\type{ptrmr8a} loaded at 10pt, and the second is \type{psyr}  loaded
at a little over 9pt. The third one is previously defined font that
is known to \LUATEX\ as fontid \quote{38}.

The array index numbers are used by the character command definitions
that are part of each character.

The \luatex{commands} array is a hash where each item is another small array, with the first
entry representing a command and the extra items being the parameters to that command. The
allowed commands and their arguments are:

\starttabulate[|l|l|l|p|]
\NC \bf command name  \NC \bf arguments \NC \bf arg type \NC \bf description \NC\NR
\NC font              \NC 1         \NC number    \NC select a new font from the local \luatex{fonts} table\NC\NR
\NC char              \NC 1         \NC number    \NC typeset this character number from the current font, 
                                                      and move right by the character's width\NC\NR
\NC node              \NC 1         \NC node      \NC output this node (list), and move right 
                                                      by the width of this list\NC\NR
\NC slot              \NC 2         \NC number    \NC a shortcut for the combination of a font and char command\NC\NR
\NC push              \NC 0         \NC           \NC save current position\NC\NR
\NC nop               \NC 0         \NC           \NC do nothing \NC\NR
\NC pop               \NC 0         \NC           \NC pop position \NC\NR
\NC rule              \NC 2         \NC 2 numbers \NC output a rule $w*h$, and move right.\NC\NR
\NC down              \NC 1         \NC number    \NC move down on the page\NC\NR
\NC right             \NC 1         \NC number    \NC move right on the page\NC\NR
\NC special           \NC 1         \NC string    \NC output a \tex{special} command\NC\NR
\NC comment           \NC any       \NC any       \NC the arguments of this command are ignored\NC\NR
\stoptabulate

Here is a rather elaborate glyph commands example:
\starttyping
...
commands = {
  {'push'},                     -- remember where we are
  {'right', 5000},              -- move right about 0.08pt
  {'font', 3},                  -- select the fonts[3] entry
  {'char', 97},                 -- place character 97 (ASCII 'a')
  {'pop'},                      -- go all the way back
  {'down', -200000},            -- move upwards by about 3pt
  {'special', 'pdf: 1 0 0 rg'}  -- switch to red color
  {'rule', 500000, 20000}       -- draw a bar
  {'special','pdf: 0 g'}        -- back to black
}
...
\stoptyping

The default value for \type {font} is always~1 at the start of the \type{commands} array. 
Therefore, if the virtual font is essentially only a re|-|encoding, then you do usually not 
have create an explicit \quote{font} command in the array.

Rules inside of \type{commands} arrays are built up using only two dimensions: 
they do not have depth. For correct vertical placement, an extra \type{down} command 
may be needed.

Regardless of the amount of movement you create within the \type {commands},
the output pointer will always move by exactly the width that was given in
the \type {width} key of the character hash. Any movements that take place 
inside the \type{commands} array are ignored on the upper level.

\subsection{Artificial fonts}

Even in a \quote{real} font, there can be virtual characters. When \LUATEX\ encounters a \type {commands}
field inside a character when it becomes time to typeset the character, it will interpret the commands, just
like for a true virtual character. In this case, if you have created no \quote{fonts} array, then the default
(and only) \quote{base} font is taken to be the current font itself. In practice, this means that you can
create virtual duplicates of existing characters which is useful if you want to create composite characters.

Note: this feature does {\it not\/} work the other way around. There can not be \quote{real} characters in a
virtual font! You cannot use this technique for font re-encoding either; you need a truly virtual 
font for that (because characters that are already present cannot be altered).

\subsection{Example virtual font}

Finally, here is a plain \TEX\ input file with a virtual font demonstration:

\startbuffer
\directlua0 {
  callback.register('define_font',
    function (name,size)
      if name == 'cmr10-red' then
        f = font.read_tfm('cmr10',size)
        f.name = 'cmr10-red'
        f.type = 'virtual'
        f.fonts = {{ name = 'cmr10', size = size }}
        for i,v in pairs(f.characters) do
          if (string.char(i)):find('[tacohanshartmut]') then
             v.commands = {
               {'special','pdf: 1 0 0 rg'},
               {'char',i},
               {'special','pdf: 0 g'},
              }
          else
             v.commands = {{'char',i}}
          end
        end
      else
        f = font.read_tfm(name,size)
      end
      return f
    end
  )
}

\font\myfont = cmr10-red at 10pt \myfont  This is a line of text \par
\font\myfontx= cmr10 at 10pt \myfontx Here is another line of text \par
\stopbuffer

\typebuffer

%\getbuffer

\chapter[nodes]{Nodes}

\section{\LUA\ node representation}

\TEX's nodes are represented in \LUA\ as userdata object with a variable
set of fields. In the following syntax tables, such the type of such a
userdata object is represented as \syntax{<node>}.

 
The current return value of \luatex{node.types()} is: 
\ctxlua {
  local d = node.types()
  tex.print('\\type{' .. d[0] .. '} (' .. 0 .. '), ') 
  for _,v in pairs(d) do 
    if _ > 0 then
      tex.print('\\type{' .. v .. '} (' .. _ .. '), ') 
    end
  end 
} but as already mentioned, the math and alignment nodes
in this list are not supported at the moment. The useful list
is described in the next sections.

\subsection{Auxiliary items}

A few node|-|typed userdata objects do not occur in the \quote{normal}
list of nodes, but can be pointed to from within that list. They are
not quite the same as regular nodes, but it is easier for the library
routines to treat them as if they were.

\subsubsection{glue_spec items}

Skips are about the only type of data objects in traditional \TEX\
that are not a simple value. The structure that represents the glue
components of a skip is called a \type {glue_spec}, and it has the following
accessible fields:

\starttabulate[|lT|l|p|]
\NC \ssbf key            \NC \bf type \NC \bf explanation \NC\NR
\NC width          \NC number  \NC \NC\NR
\NC stretch        \NC number  \NC \NC\NR
\NC stretch_order  \NC number  \NC \NC\NR
\NC shrink         \NC number  \NC \NC\NR
\NC shrink_order   \NC number  \NC \NC\NR
\stoptabulate

These objects are reference counted, so there is actually an extra
field named \type {ref_count} as well. This item type will likely
disappear in the future, and the glue fields themselves will
become part of the nodes referencing glue items.

\subsubsection{attribute\_list and attribute items}

The newly introduced attribute registers are non|-|trivial, because
the value that is attached to a node is essentially a sparse array of
key|-|value pairs.

It is generally easiest to deal with attribute lists and attributes
by using the dedicated functions in the \luatex{node} library, but
for completeness, here is the low|-|level interface. 

An \type{attribute_list} item is used as a head pointer for a list
of attribute items. It has only one user-visible field:

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC next          \NC \syntax{<node>}  \NC pointer to the first attribute\NC\NR
\stoptabulate

A normal node's attribute field will point to an item of type
\type{attribute_list}, and the \type{next} field in that item will point 
to the first defined \quote{attribute} item, whose \type {next} will
point to the second \quote{attribute} item, etc.

Valid fields in \type{attribute} items:

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC next           \NC \syntax{<node>}  \NC pointer to the next attribute\NC\NR
\NC number         \NC number  \NC the attribute type id\NC\NR
\NC value          \NC number  \NC the attribute value\NC\NR
\stoptabulate

\subsubsection{action item}

Valid fields: \showfields{action}

These are a special kind of item that only appears inside
pdf start link objects. 

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC action_type   \NC  number   \NC  \NC\NR
\NC action_id     \NC  number or string   \NC  \NC\NR
\NC named_id      \NC  number   \NC  \NC\NR
\NC file          \NC  string   \NC  \NC\NR
\NC new_window    \NC  number   \NC  \NC\NR
\NC data          \NC  string   \NC  \NC\NR
\NC ref_count     \NC  number   \NC  \NC\NR
\stoptabulate

\subsection{Main text nodes}

These are the nodes that comprise actual typesetting commands. 

A few fields are present in all nodes regardless of their type, these are:

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC next    \NC \syntax{<node>}  \NC  The next node in a list, or nil\NC\NR
\NC id      \NC number  \NC  The node's type (\type{id}) number \NC\NR
\NC subtype \NC number  \NC  The node \type{subtype} identifier\NC\NR
\stoptabulate

The \type{subtype} is sometimes just a stub entry. Not all nodes
actually use the \type{subtype}, but this way you can be sure that all
nodes accept it as a valid field name, and that is often handy in node
list traversal. In the following tables \type{next} and \type{id} are
not explicitly mentioned.

Besides these three fields, almost all nodes also have an \type {attr}
field, and there is a also a field called \type{prev}. That last field
is always present, but only initialized on explicit request: when the
function \type{node.slide()} is called, it will set up the \type{prev}
fields to be a backwards pointer in the argument node list.


\subsubsection{hlist nodes}

Valid fields: \showfields{hlist}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  unused\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  The head of the associated attribute list \NC\NR
\NC width      \NC number  \NC  \NC\NR
\NC height     \NC number  \NC  \NC\NR
\NC depth      \NC number  \NC  \NC\NR
\NC shift      \NC number  \NC  a displacement perpendicular to the
                                character progression direction \NC\NR
\NC glue_order \NC number  \NC  a number in the range 0--4, indicating
                                the glue order\NC\NR
\NC glue_set   \NC number  \NC  the calculated glue ratio\NC\NR
\NC glue_sign  \NC number  \NC  \NC\NR
\NC list       \NC \syntax{<node>}    \NC  the body of this list\NC\NR
\NC dir        \NC number  \NC  the direction of this box\NC\NR
\stoptabulate

\subsubsection{vlist nodes}

Valid fields: As for hlist, except that \quote{shift} is a displacement
perpendicular to the line progression direction.

\subsubsection{rule nodes}

Valid fields: \showfields{rule}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  unused\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC width      \NC number  \NC  rule size. The special value $-1073741824$
                                is used for \quote{running} glue dimensions\NC\NR
\NC height     \NC number  \NC  ' '\NC\NR
\NC depth      \NC number  \NC  ' '\NC\NR
\NC dir        \NC number  \NC  the direction of this rule\NC\NR
\stoptabulate

\subsubsection{ins nodes}

Valid fields: \showfields{ins}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  the insertion class\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC cost       \NC number  \NC  the penalty associated with this insert\NC\NR
\NC height     \NC number  \NC  \NC\NR
\NC depth      \NC number  \NC  \NC\NR
\NC list       \NC \syntax{<node>}    \NC  the body of this insert\NC\NR
\NC spec       \NC \syntax{<node>}    \NC a pointer to the \tex{splittopskip} glue spec\NC\NR
\stoptabulate

\subsubsection{mark nodes}

Valid fields: \showfields{mark}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  unused\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC class      \NC number  \NC  the mark class\NC\NR
\NC mark       \NC table   \NC  a table representing a token list\NC\NR
\stoptabulate

\subsubsection{adjust nodes}

Valid fields: \showfields{adjust}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  0 = normal, 1 = \quote{pre}\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC list       \NC \syntax{<node>}    \NC  adjusted material\NC\NR
\stoptabulate

\subsubsection{disc nodes}

Valid fields: \showfields{disc}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  indicates the source of a discretionary. 
                                0 = the \tex{discretionary} command, 
                                1 = the \tex{-} command, 
                                2 = added automatically following a \type{-},
                                3 = added by the hyphenation algorithm\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC pre        \NC \syntax{<node>}    \NC  pointer to the pre|-|break text\NC\NR
\NC post       \NC \syntax{<node>}    \NC  pointer to the post|-|break text\NC\NR
\NC replace    \NC \syntax{<node>}    \NC  pointer to the no|-|break text\NC\NR
\stoptabulate

\subsubsection{math nodes}

Valid fields: \showfields{math}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  0 = \quote{on}, 1 = \quote{off}\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC surround   \NC number  \NC  width of the \tex{mathsurround} kern\NC\NR
\stoptabulate

\subsubsection{glue nodes}

Valid fields: \showfields{glue}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  0 = \tex{skip},
                                1--18 = internal glue parameters,
                                100 = \tex{leaders},
                                101 = \tex{cleaders},
                                102 = \tex{xleaders}  \NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC spec       \NC \syntax{<node>}    \NC  pointer to a glue\_spec item \NC\NR
\NC leader     \NC \syntax{<node>}    \NC  pointer to a box or rule for leaders\NC\NR
\stoptabulate

\subsubsection{kern nodes}

Valid fields: \showfields{kern}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  0 = from font,
                                1 = from \tex{kern} or \tex{/},
                                2 = from \tex{accent}\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC kern      \NC number  \NC  \NC\NR
\stoptabulate


\subsubsection{penalty nodes}

Valid fields: \showfields{penalty}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  not used\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC penalty    \NC number  \NC  \NC\NR
\stoptabulate

\subsubsection[glyphnodes]{glyph nodes}

Valid fields: \showfields{glyph}

\newbox\mybox
\setbox\mybox=\hbox{\vbox {\hsize=3cm
\starttabulate[|l|l|]
\NC bit 0 \NC character \NC\NR
\NC bit 1 \NC glyph     \NC\NR
\NC bit 2 \NC ligature  \NC\NR
\NC bit 3 \NC ghost     \NC\NR
\NC bit 4 \NC left      \NC\NR
\NC bit 5 \NC right     \NC\NR
\stoptabulate 
}}

\starttabulate[|lT|l|p|]
\NC \ssbf field\NC \ssbf type         \NC \ssbf explanation \NC\NR
\NC subtype    \NC number             \NC bitfield, with bits:\crlf
                                          \copy\mybox\NC\NR
\NC attr       \NC \syntax{<node>}    \NC \NC\NR
\NC char       \NC number             \NC \NC\NR
\NC font       \NC number             \NC \NC\NR
\NC lang       \NC number             \NC \NC\NR
\NC left       \NC number             \NC \NC\NR
\NC right      \NC number             \NC \NC\NR
\NC uchyph     \NC boolean            \NC \NC\NR
\NC components \NC \syntax{<node>}    \NC pointer to ligature components\NC\NR
\NC xoffset    \NC number             \NC \NC\NR
\NC yoffset    \NC number             \NC \NC\NR
\stoptabulate

See \in{section}[charsandglyphs] for a detailed description of the
\type{subtype} field.

\subsubsection{margin\_kern nodes}

Valid fields: \showfields{margin_kern}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC subtype    \NC number  \NC  0 = left side,
                                1 = right side\NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC width      \NC number  \NC  \NC\NR
\NC glyph      \NC \syntax{<node>}    \NC  \NC\NR
\stoptabulate

\subsection{whatsit nodes}

Whatsit nodes come in many subtypes that you can ask for by running
\luatex{node.whatsits()}: 
\ctxlua {for _,v in pairs(node.whatsits()) do
tex.print('\\type{' .. v .. '} (' .. _ .. '), ') end }

\subsubsection{open nodes}

Valid fields: \showfields{whatsit,open}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC stream    \NC number  \NC \TEX's stream id number\NC\NR
\NC name      \NC string  \NC file name \NC\NR
\NC ext       \NC string  \NC file extension \NC\NR
\NC area      \NC string  \NC file area \NC\NR
\stoptabulate

\subsubsection{write nodes}

Valid fields: \showfields{whatsit,write}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC stream    \NC number  \NC \TEX's stream id number\NC\NR
\NC data      \NC table   \NC a table representing the token list to be written\NC\NR
\stoptabulate

\subsubsection{close nodes}

Valid fields: \showfields{whatsit,close}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC stream    \NC number  \NC \TEX's stream id number\NC\NR
\stoptabulate

\subsubsection{special nodes}

Valid fields: \showfields{whatsit,special}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC data      \NC string  \NC the \tex{special} information\NC\NR
\stoptabulate

\subsubsection{language nodes}


\LUATEX\ does not have language whatsits any more. All language 
information is already present inside the glyph nodes themselves.
This whatsit subtype will be removed in the next release.


\subsubsection{local_par nodes}

Valid fields: \showfields{whatsit,local_par}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC pen_inter \NC number  \NC interline penalty\NC\NR
\NC pen_broken\NC number  \NC broken penalty\NC\NR
\NC dir       \NC number  \NC the direction of this par\NC\NR
\NC box_left  \NC \syntax{<node>}      \NC the \tex{localleftbox}\NC\NR
\NC box_left_width\NC number\NC width of the \tex{localleftbox}\NC\NR
\NC box_right  \NC \syntax{<node>}      \NC the \tex{localrightbox}\NC\NR
\NC box_right_width\NC number\NC width of the \tex{localrightbox}\NC\NR
\stoptabulate

\subsubsection{dir nodes}

Valid fields: \showfields{whatsit,dir}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC dir       \NC number  \NC the direction\NC\NR
\NC level     \NC number  \NC nesting level of this direction whatsit\NC\NR
\NC dvi_ptr   \NC number  \NC a saved dvi buffer byte offset\NC\NR
\NC dir_h     \NC number  \NC a saved dvi position\NC\NR
\stoptabulate

\subsubsection{pdf_literal nodes}

Valid fields: \showfields{whatsit,pdf_literal}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC mode      \NC number  \NC  the \quote{mode} setting of this literal\NC\NR
\NC data      \NC string  \NC the \tex{pdfliteral} information\NC\NR
\stoptabulate

\subsubsection{pdf_refobj nodes}

Valid fields: \showfields{whatsit,pdf_refobj}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC objnum    \NC number  \NC the referenced \PDF\ object number\NC\NR
\stoptabulate

\subsubsection{pdf_refxform nodes}

Valid fields: \showfields{whatsit,pdf_refxform}. 

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC width     \NC number  \NC \NC \NR
\NC height    \NC number  \NC \NC \NR
\NC depth     \NC number  \NC \NC \NR
\NC objnum    \NC number  \NC the referenced \PDF\ object number\NC\NR
\stoptabulate

Be aware that \type{pdf_refxform} nodes have dimensions that are used by \LUATEX.

\subsubsection{pdf_refximage nodes}

Valid fields: \showfields{whatsit,pdf_refximage}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC width     \NC number  \NC \NC \NR
\NC height    \NC number  \NC \NC \NR
\NC depth     \NC number  \NC \NC \NR
\NC objnum    \NC number  \NC the referenced \PDF\ object number\NC\NR
\stoptabulate

Be aware that \type{pdf_refximage} nodes have dimensions that are used by \LUATEX.

\subsubsection{pdf_annot nodes}

Valid fields: \showfields{whatsit,pdf_annot}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC width     \NC number  \NC \NC \NR
\NC height    \NC number  \NC \NC \NR
\NC depth     \NC number  \NC \NC \NR
\NC objnum    \NC number  \NC the referenced \PDF\ object number\NC\NR
\NC data      \NC string  \NC the annotation data\NC\NR
\stoptabulate


\subsubsection{pdf_start_link nodes}

Valid fields: \showfields{whatsit,pdf_start_link}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC width     \NC number  \NC \NC \NR
\NC height    \NC number  \NC \NC \NR
\NC depth     \NC number  \NC \NC \NR
\NC objnum    \NC number  \NC the referenced \PDF\ object number\NC\NR
\NC link_attr \NC table   \NC the link attribute token list\NC\NR
\NC action    \NC \syntax{<node>}    \NC the action to perform\NC\NR
\stoptabulate

\subsubsection{pdf_end_link nodes}

Valid fields: \showfields{whatsit,pdf_end_link}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\stoptabulate

\subsubsection{pdf_dest nodes}

Valid fields: \showfields{whatsit,pdf_dest}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC width     \NC number  \NC \NC \NR
\NC height    \NC number  \NC \NC \NR
\NC depth     \NC number  \NC \NC \NR
\NC named_id  \NC number  \NC is the dest_id a string value?\NC\NR
\NC dest_id   \NC number or string \NC the destination id\NC\NR
\NC dest_type \NC number\NC type of destination\NC\NR
\NC xyz_zoom  \NC number\NC \NC\NR
\NC objnum    \NC number  \NC the \PDF\ object number\NC\NR
\stoptabulate

\subsubsection{pdf_thread nodes}

Valid fields: \showfields{whatsit,pdf_thread}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC width      \NC number  \NC \NC \NR
\NC height     \NC number  \NC \NC \NR
\NC depth      \NC number  \NC \NC \NR
\NC named_id   \NC number  \NC is the tread_id a string value?\NC\NR
\NC tread_id   \NC number or string \NC the thread id\NC\NR
\NC thread_attr\NC number           \NC extra thread information\NC\NR
\stoptabulate

\subsubsection{pdf_start_thread nodes}

Valid fields: \showfields{whatsit,pdf_start_thread}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr       \NC \syntax{<node>}    \NC  \NC\NR
\NC width      \NC number  \NC \NC \NR
\NC height     \NC number  \NC \NC \NR
\NC depth      \NC number  \NC \NC \NR
\NC named_id   \NC number  \NC is the tread_id a string value?\NC\NR
\NC tread_id   \NC number or string \NC the thread id\NC\NR
\NC thread_attr\NC number           \NC extra thread information\NC\NR
\stoptabulate

\subsubsection{pdf_end_thread nodes}

Valid fields: \showfields{whatsit,pdf_end_thread}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\stoptabulate

\subsubsection{pdf_save_pos nodes}

Valid fields: \showfields{whatsit,pdf_save_pos}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\stoptabulate

\subsubsection{late_lua nodes}

Valid fields: \showfields{whatsit,late_lua}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC reg       \NC number  \NC \LUA\ state id number \NC\NR
\NC data      \NC string  \NC data to execute\NC\NR
\stoptabulate

\subsubsection{close_lua nodes}

Valid fields: \showfields{whatsit,close_lua}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC reg    \NC number  \NC \LUA\ state id number\NC\NR
\stoptabulate

\subsubsection{pdf_colorstack  nodes}

Valid fields: \showfields{whatsit,pdf_colorstack}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC stack    \NC number  \NC colorstack id number\NC\NR
\NC cmd      \NC number  \NC command to execute\NC\NR
\NC data     \NC string  \NC data\NC\NR
\stoptabulate

\subsubsection{pdf_setmatrix nodes}

Valid fields: \showfields{whatsit,pdf_setmatrix}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC data     \NC string  \NC data\NC\NR
\stoptabulate

\subsubsection{pdf_save nodes}

Valid fields: \showfields{whatsit,pdf_save}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\stoptabulate

\subsubsection{pdf_restore nodes}

Valid fields: \showfields{whatsit,pdf_restore}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\stoptabulate

\subsubsection{user_defined nodes}

User-defined whatsit nodes can only be created and handled from Lua
code. In effect, they are an extension to the extension
mechanism. The \LUATEX\ engine will simply step over such whatsits
without ever looking at the contents.

Valid fields: \showfields{whatsit,user_defined}

\starttabulate[|lT|l|p|]
\NC \ssbf field     \NC \bf type \NC  \bf explanation \NC\NR
\NC attr      \NC \syntax{<node>}    \NC  \NC\NR
\NC user_id  \NC number  \NC id number\NC\NR
\NC type     \NC number  \NC type of the value\NC\NR
\NC value    \NC number  \NC \NC\NR
\NC          \NC string  \NC \NC\NR
\NC          \NC \syntax{<node>}   \NC \NC\NR
\NC          \NC table \NC \NC\NR
\stoptabulate

The \type{type} can have one of five distinct values:

\starttabulate[|lT|l|p|]
\NC \ssbf value   \NC  \bf explanation \NC\NR
\NC  97           \NC  the value is an attribute node list \NC\NR
\NC  100          \NC  the value is a number \NC\NR
\NC  110          \NC  the value is a node list \NC\NR
\NC  115          \NC  the value is a token list in string form\NC\NR
\NC  116          \NC  the value is a token list in lua table form\NC\NR
\stoptabulate


\chapter{Modifications}

Besides the expected changes caused by new functionality, there are a
number of not|-|so|-|expected changes. These are sometimes a side|-|effect
of a new (conflicting) feature, or, more often than not, a change
necessary to clean up the internal interfaces.

\section{Changes from \TEX\ 3.141592}

\startitemize

\item See~\in{chapter}[languages] for many small changes related to paragraph 
  building, language handling, and hyphenation.

\item There is no pool file, all strings are embedded during compilation.

\item \type {plus 1 fillll} does not generate an error. The extra \quote{l} is
simply typeset.

\item The \tex{endlinechar} can be either added (values 0 or more), or not
(negative values). If it is added, the character is always decimal 13 a/k/a
\type{^^M} a/k/a carriage return (This change may be temporary).

\item The banner line and the statistics messages are different, as
well as many warnings and error texts.

\stopitemize

\section{Changes from \ETEX\ 2.2}

\startitemize

\item The \ETEX\ functionality is always present and enabled
   (but see below about \TEXXET), so the prepended asterisk or
   \type{-etex} switch for \INITEX\ is not needed.

\item \TEXXET\ is not present, so the primitives

\starttyping
\TeXXeTstate
\beginR
\beginL
\endR
\endL
\stoptyping

are missing.

\item Some of the tracing information that is output by \ETEX's \tex{tracingassigns} and 
  \tex{tracingrestores} is not there.

\item Register management in \LUATEX\ uses the \ALEPH\ model, so the maximum value is 65535
  and the implementation uses a flat array instead of the mixed
 flat|\&|sparse model from \ETEX.

\item \type{savinghyphcodes} is a no-op and may possibly be removed. 
 See~\in{chapter}[languages] for details.

\stopitemize

\section{Changes from \PDFTEX\ 1.40}

\startitemize

\item The (experimental) support for snap nodes has been removed, because 
it is much more natural to build this functionality on top of node
processing and attributes. The associated primitives that are now gone
are: \tex{pdfsnaprefpoint}, \tex{pdfsnapy}, and \tex{pdfsnapycomp}.

\item The (experimental) support for specialized spacing around nodes 
has also been removed. The associated primitives that are now gone are:
\tex{pdfadjustinterwordglue}, \tex{pdfprependkern}, and \tex{pdfappendkern}, 
as well as the five supporting primitives \tex{knbscode}, \tex{stbscode}, 
\tex{shbscode}, \tex{knbccode}, and \tex{knaccode}.



\item A number of \quote{utility functions} is removed:

\startcolumns[n=3]
\starttyping
\pdfelapsedtime
\pdfescapehex
\pdfescapename
\pdfescapestring
\pdffiledump
\pdffilemoddate
\pdffilesize
\pdflastmatch
\pdfmatch
\pdfmdfivesum
\pdfresettimer
\pdfshellescape
\pdfstrcmp
\pdfunescapehex
\stoptyping
\stopcolumns

\item A few other experimental primitives are also provided without the
      extra  \luatex {pdf} prefix, so they can also be called like this:

\startcolumns[n=3]
\starttyping
\primitive
\ifprimitive
\ifabsnum
\ifabsdim
\stoptyping
\stopcolumns

\item The definitions for new didot and new cicero are patched.

\item The \tex{pdfprimitive} is bugfixed.

\item The \tex{pdftexversion} is set to 200.

\stopitemize

\section{Changes from \ALEPH\ RC4}

\startitemize

\item The input translations from \ALEPH\ are not implemented, the
   related primitives are not available:

\startcolumns[n=2]
\starttyping
\DefaultInputMode
\noDefaultInputMode
\noInputMode
\InputMode
\DefaultOutputMode
\noDefaultOutputMode
\noOutputMode
\OutputMode
\DefaultInputTranslation
\noDefaultInputTranslation
\noInputTranslation
\InputTranslation
\DefaultOutputTranslation
\noDefaultOutputTranslation
\noOutputTranslation
\OutputTranslation
\stoptyping
\stopcolumns

\item A small series of bounds checking fixes to \tex{ocp} and
   \tex{ocplist} has been added to prevent the system from crashing
   due to array indexes running out of bounds.

\item The \tex{hoffset} bug when \tex{pagedir TRT}  is fixed,
removing the need for an explicit fix to \tex{hoffset}

\item A bug causing \tex{fam} to fail for family numbers above
    15 is fixed.

\item Some bits of \ALEPH\ assumed \type{0} and \type{null} were identical.
This resulted for instance in a bug that sometimes caused an eternal
loop when trying to \tex{show} a box.

\item A fair amount of other minor bugs are fixed as well, most of these
related to \tex{tracingcommands} output.

\item The number of possible fonts, ocps and ocplists is
smaller than their maximum \ALEPH\ value (around 5000 fonts and
30000 ocps / ocplists).

\item The internal function \type{scan_dir()} has been renamed to
\type{scan_direction()} to prevent a naming clash.

\item The \type{^^} notation can come in five and six item repetitions also, to
insert characters that do not fit in the BMP.

\item Glues {\it immediately after} direction change commands are not 
legal breakpoints.

\item The \tex{ocp} and \tex{ocplist} statistics at the end of a run
are only printed if OCP's are actually used.

\stopitemize

\section{Changes from standard \WEBC}

\startitemize

\item There is no mltex

\item There is no enctex

\item The following commandline switches are silently ignored, even
in non|-|\LUA\ mode:

\starttyping
-8bit
-translate-file=TCXNAME
-mltex
-enc
-etex
\stoptyping

\item \tex{openout} whatsits are not written to the log file.

\item Some of the so|-|called web2c extensions are hard to set up
  in non|-|\KPSE\ mode because texmf.cnf is not read: \type{shell-escape}
  is off (but that is not a problem because of \LUA's
  \lua{os.execute}), and the paranoia checks on \type{openin} and
  \type{openout} do not happen (however, it is easy for a \LUA\ script
  to do this itself by overloading \lua{io.open}).


\stopitemize

\chapter{Implementation notes}

\section{Primitives overlap}

The primitives

\starttabulate[|l|l|]
\NC \tex{pdfpagewidth} \NC \tex{pagewidth}  \NC \NR
\NC \tex{pdfpageheight}\NC \tex{pageheight} \NC \NR
\NC \tex{fontcharwd}   \NC \tex{charwd}     \NC \NR
\NC \tex{fontcharht}   \NC \tex{charht}     \NC \NR
\NC \tex{fontchardp}   \NC \tex{chardp}     \NC \NR
\NC \tex{fontcharic}   \NC \tex{charic}     \NC \NR
\stoptabulate

are all aliases of each other.

\section{Memory allocation}

The single internal memory heap that traditional \TEX\ used for tokens
and nodes is split into two separate arrays. Each of these will grow
dynamically when needed.

The \type{texmf.cnf} settings related to main memory are no longer
used (these are: \type{main_memory}, \type{mem_bot},
\type{extra_mem_top} and \type{extra_mem_bot}). \quote{Out of main
memory} errors can still occur, but the limiting factor is now the
amount of RAM in your system, not a predefined limit.

Also, the memory (de)allocation routines for nodes are completely
rewritten. The relevant code now lives in the C file \type{luanode.c},
and basically uses a dozen or so avail lists instead of a
doubly|-|linked model. An extra function layer is added so that the 
code can ask for nodes by type instead of directly requisitioning
a certain amount of memory words.

Because of the split into two arrays and the resulting differences in
the data structures, some of the Pascal \WEB\ macros have been
duplicated.  For instance, there are now \type{vlink} and \type{vinfo}
as well as \type{link} and \type{info}. All access to the variable
memory array is now hidden behind a macro called \type{vmem}.

The implementation of the growth of two arrays (via reallocation)
introduces a potential pitfall: the memory arrays should never be used
as the left hand side of a statement that can modify the array in
question.

The input line buffer and pool size are now also reallocated when
needed, and the \type{texmf.cnf} settings \type{buf_size} and
\type{pool_size} are silently ignored.

\section{Sparse arrays}

The \tex{mathcode}, \tex{delcode}, \tex{catcode},
\tex{sfcode}, \tex{lccode} and \tex{uccode} tables are now
sparse arrays that are implemented in~C. They are no longer part of
the \TEX\ \quote{equivalence table} and because each had 1.1 million
entries with a few memory words each, this makes a major difference
in memory usage.

These assignments do not yet show up when using the etex tracing
routines \tex{tracingassigns} and \tex{tracingrestores} (code
simply not written yet).

A side|-|effect of the current implementation is that \tex{global} is
now more expensive in terms of processing than non|-|global assignments.

See \type{mathcodes.c} and \type{textcodes.c} if you are interested in
the details.

Also, the glyph ids within a font are now managed by means
of a sparse array and glyph ids can go up to index $2^{21}-1$.

\section{Simple single-character csnames}

Single|-|character commands are no longer treated specially in the
internals, they are stored in the hash just like the multiletter
csnames.

The code that displays control sequences explicitly checks if
the length is one when it has to decide whether or not to add a
trailing space.

\section{Compressed format}

The format is passed through zlib, allowing it to shrink to roughly
half of the size it would have had in uncompressed form. This takes a
bit more CPU cycles but much less disk I/O, so it should still be
faster.

\section{Binary file reading}

All of the internal code is changed in such a way that if one of the
\type{read_xxx_file} callbacks is not set, then the file is read by
a C function using basically the same convention as the callback: a
single read into a buffer big enough to hold the entire file
contents. While this uses more memory than the previous code (that
mostly used \type{getc} calls), it can be quite a bit faster
(depending on your I/O subsystem).

\chapter{Known bugs and limitations}

The bugs below are going to be fixed eventually.

The top ones will be fixed soon, but in the later items either the
actual problem is hard to find, or the code that causes the bug is
going to be replaced by a new subsystem soon anyway, or it may not
be worth the hassle and the limitations will eventually be documented.

\startitemize

\item The current linebreaking implementation does not yet take all 
possible breakpoints into account where ligatures are involved in
the process.  This means that line breaks may change in future
versions.

\item Sometimes font loading via fontforge generates a message like this
\starttyping
Bad call to gww_iconv_open, neither arg is UCS4 (EUC-CN->UTF-8)
\stoptyping
during font loading. This is a limitation of the internal iconv
implementation.

\item Font expansion does not work quite as it should. On the mailing
list (sep 21), Jonathan Sauer posted a very nice test file along with
an explanation. 

\item \luatex{tex.print()} and \luatex{tex.sprint()} do not work if
\tex{directlua} is used in an \OTP\ file (in the output of an
\type{expression} rule).

\item Handling of attributes in math mode is not complete. The data
structures in math mode are quite different from those in text mode,
so this will take some extra effort to implement correctly.

\item When used inside  \type{\directlua}, \type{pdf.print()} should create a
literal node instead of flushing immediately.

\item At the moment, only characters in plane~0 and plane~1 can be
assigned catcode~13 (i.\,e.\ turned into active characters). This is a
temporary measure to reduce the memory requirements of \LUATEX.  In
general, \LUATEX's memory footprint is a bit larger that we would
like (with \type{plain.fmt} preloaded it needs about 55MB).

\item Not all of \ALEPH's direction commands are handled properly in
\PDF\ mode, and especially the vertical scripts support is missing
almost completely (only TRT and TLT are routinely tested).

\item Letter spacing (\tex{letterspacefont}) is currently non|-|functional
due to massive changes in the virtual font handling. This
functionality may actually be removed completely in the future,
because it is straightforward to set up letterspacing using the \LUA\
\quote{define_font} interface.

\item Node pointers are not always checked for validity, so if you make a 
mistake in the node list processing, \LUATEX\ may terminate itself with an
assertion error or \quote{Emergency stop}.

\item In \DVI\ generation mode, using a \type{\textdir} switch inside the
preamble of a \type{\halign} results in overprinted text in the \DVI\ file,
because the column width is not taken into account during the final
placement phase (this is a bug inherited from \ALEPH). Also, \ALEPH\
apparently dislikes having more than one non-grouped \type{\textdir}
command in a single lined paragraph.

\item Certain constructs in math mode leak memory nodes. 

\stopitemize


\chapter{TODO}

On top of the \quote{normal} extensions that are planned, there are
some more specific small feature requests. Whether these will all be
included is not certain yet, (and new requests are welcome).

\startitemize

\item Implement the \TEX\ primitive \tex{dimension}, cf.\ \tex{number}.

\item Change the \LUA\ table \type{tex.dimen} to accept and return float
values instead of strings.

\item Do something about \tex{withoutpt} and/or a new register type \tex{real}?

\item Create callback for the automatic creation of missing
characters in fonts.

\item Implement the \TEX\ primitive \tex{htdp}?

\item Do boxes with dual baselines.

\item A way to (re?)calculate the width of a  \tex{vbox}, taking only
the natural width of the included items into account.

\item Make the number of the output box configurable.

\item Complete the attributes in math and switch all the nodes to a double|-|linked list.

\item Finish the interface from Lua to \TeX's internals, specially the hash and 
equivalence table (a small subpart is implementing \type{\csname}
lookups for \type{tex.box} access).

\item Use of Type1C for embedded PostScript font subsets in
traditional 8-bit encodings.

\item Support font reencoding of 8-bit fonts via char index instead of
via map files.

\item Attempt to parse OFM level~0 fonts that are masquerading as level~1.

\item Add line numbers and input context information to the lua errors.
\stopitemize

\stoptext