summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/fontspec/fontspec.dtx
blob: 12c452c0f615b4b81c1521f4af993b2370e1674e (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
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
% \iffalse
%<*internal>
\begingroup
\input docstrip.tex
\keepsilent
\usedir{tex/latex/fontspec}
\let\MetaPrefix\relax
\preamble

  _________________________________________
  The fontspec package for XeLaTeX/LuaLaTeX
  (C) 2004--2010    Will Robertson and Khaled Hosny

  License information appended.


\endpreamble
\postamble

Copyright 2004--2010 Will Robertson <wspr81@gmail.com>
Copyright 2009--2010 Khaled Hosny <khaledhosny@eglug.org>

Distributable under the LaTeX Project Public License,
version 1.3c or higher (your choice). The latest version of
this license is at: http://www.latex-project.org/lppl.txt

This work is "author-maintained" by Will Robertson.

This work consists of this file fontspec.dtx
          and the derived files fontspec.sty,
                                fontspec.lua,
                                fontspec.cfg,
                                fontspec-xetex.tex,
                                fontspec-luatex.tex,
                            and fontspec.pdf.

\endpostamble
\askforoverwritefalse

\def\MetaPrefix{-- }
\generate{\file{fontspec.lua}          {\from{fontspec.dtx}{lua}}}

\let\MetaPrefix\DoubleperCent
\generate{\file{fontspec.sty}          {\from{fontspec.dtx}{fontspec}}}
\generate{\file{fontspec-patches.sty}  {\from{fontspec.dtx}{patches}}}

\nopreamble\nopostamble
\generate{\file{fontspec.cfg}          {\from{fontspec.dtx}{cfg}}}
\generate{\file{fontspec-example.tex}  {\from{fontspec.dtx}{example}}}
\generate{\file{fontspec-testsuite.tex}{\from{fontspec.dtx}{testsuite}}}

\def\tmpa{plain}
\ifx\tmpa\fmtname\endgroup\expandafter\bye\fi

\generate{\file{fontspec-style.sty}    {\from{fontspec.dtx}{doc-style}}}
\endgroup
%</internal>
%
%<*driver>
\ProvidesFile{fontspec.dtx}
%</driver>
%<fontspec>\ProvidesPackage{fontspec}
%<patches>\ProvidesPackage{fontspec-patches}
%<*fontspec|patches>
  [2010/09/19 v2.1 Advanced font selection for XeLaTeX/LuaLaTeX]
%</fontspec|patches>
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{fontspec-style}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
%
% \fi
%
% \GetFileInfo{fontspec.dtx}
% \makeatletter                         ^^A% To document @-cmds
% \errorcontextlines=999                ^^A% Show up all my mistakes
%
% \title{The \textsf{fontspec} package}
% \author{
%    \textsc{Will Robertson} and \textsc{Khaled Hosny}\\
%    \texttt{will.robertson@latex-project.org}
% }
% \date{\filedate \qquad \fileversion}
%
% \maketitle
% \tableofcontents
%
% \section{History}
%
% This package began life as a \LaTeX\ interface to select system-installed
% \MacOSX\ fonts in \name{Jonathan Kew}'s \XeTeX, the first widely-used
% Unicode extension to \TeX. Over time, \XeTeX\ was extended to support OpenType
% fonts and then was ported into a cross-platform program to run also on Windows
% and Linux.
%
% More recently, \LuaTeX\ is fast becoming the \TeX\ engine of the day; it
% supports Unicode encodings and OpenType fonts and opens up the internals of
% \TeX\ via the Lua programming language. Hans Hagen's Con\TeX t Mk.\,IV is a
% re-write of his powerful typesetting system, taking full advantage of
% \LuaTeX's features including font support; a kernel of his work in this area
% has been extracted to be useful for other \TeX\ macro systems as well, and
% this has enabled \pkg{fontspec} to be adapted for \LaTeX\ when run with the
% \LuaTeX\ engine. Elie Roux and Khaled Hosny have been instrumental and
% invaluable with this development work.
%
% \section{Introduction}
%
% The \pkg{fontspec} package allows users of either \XeTeX\ or \LuaTeX\ to
% load OpenType fonts in a \LaTeX\ document. No font installation is necessary,
% and font features can be selected and used as desired throughout the document.
%
% Without \pkg{fontspec}, it is necessary to write cumbersome font definition
% files for \LaTeX, since \LaTeX's font selection scheme (known as the
% `\textsc{nfss}') has a lot going on behind the scenes to allow easy
% commands like \cmd\emph\ or \cmd\bfseries. With an uncountable number of
% fonts now available for use, however, it becomes less desirable to have to
% write these font definition (|.fd|) files for every font one wishes to use.
%
% Because \pkg{fontspec} is designed to work in a variety of modes, this
% user documentation is split into separate sections that are designed to be
% relatively independent. Nonetheless, the basic functionality all behaves in
% the same way, so previous users of \pkg{fontspec} under \XeTeX\ should have
% little or no difficulty switching over to \LuaTeX.
%
% This manual can get rather in-depth, as there are a lot of details
% to cover. See the example documents \path{fontspec-xetex.tex} and
% \path{fontspec-luatex.tex} for a complete minimal example with each engine.
%
% \subsection{About this manual}
%
% This document is typeset with pdf\LaTeX\ using pre-compiled examples
% that have been generated by either \XeTeX\ or \LuaTeX. You may regenerate
% the examples by removing the \verb|doc/| subdirectory and typesetting the
% manual with the following invocation:
% \begin{verbatim}
%   pdflatex -shell-escape fontspec.dtx
% \end{verbatim}
% Note that many of the examples use fonts that are not included in \TeX~Live
% or MiKTeX, and some of them are non-free fonts that must be purchased.
%
% I'd like to reduce the number of non-free fonts used in this
% manual. If you know any freely available fonts that could be used
% as alternative to any of the fonts in this document, please suggest them
% to me.
% Finally, if any aspect of the documentation is unclear or you would
% like to suggest more examples that could be made, get in touch.
% (Contributions especially welcome.)
%
% \subsection{Acknowledgements}
%
% This package couldn't be possible without the early and continued support
% the author of \XeTeX, Jonathan Kew. When I started this package, he steered
% me many times in the right direction.
%
% I've had great
% feedback over the years on feature requests, documentation queries, bug reports, font suggestions, and so on from lots of people all around the world.
% Many thanks to you all.
%
% Thanks to David Perry for numerous documentation improvements and
% contributing the text for one of the sections of this manual.
%
% Special thanks to Khaled Hosny, who had been the driving force behind the support for \LuaLaTeX, ultimately leading to version 2.0 of the package.
%
% \section{Package loading and options}
%
% For basic use, no package options are required:
% \begin{Verbatim}
%   \usepackage{fontspec}
% \end{Verbatim}
%
% \paragraph{\pkg{xunicode}}
% Ross Moore's \pkg{xunicode} package is now automatically loaded for
% users of both \XeLaTeX\ and \LuaLaTeX.
% This package provides backwards compatibility with \LaTeX's methods for accessing extra
% characters and accents (for example, |\%|, |\$|, |\textbullet|, |\"u|, and
% so on), plus many more Unicode characters.
% \textbf{Warning}: introduced in v2.1, this is a backwards incompatible change to previous
% versions of \pkg{fontspec}. This change was necessary in order to provide consistent
% support for users of \XeTeX\ and \LuaTeX. I'm not aware of any issues this
% may cause but please let me know if you run into problems.
%
% \paragraph{\XeTeX\ users only}
% The \pkg{xltxtra} package adds some minor extra features to \XeLaTeX, including, via the \pkg{metalogo} package, the
% \cmd\XeTeX\ macro to typeset the \XeTeX\ logo. While this package was
% previously recommended, it serves a much smaller r\^ole nowadays and generally
% will not be required.
%
% \paragraph{\LuaTeX\ users only}
% In order to load fonts by their name rather than by their filename (\eg,
% `Latin Modern Roman' instead of `ec-lmr10'), you may need to run the script
% \texttt{mkluatexfontdb}, which is distributed with the \pkg{luaotfload}
% package. Note that if you do not execute this script beforehand, the first
% time you attempt to typeset the process will pause for (up to) several
% minutes. (But only the first time.)
% Please see the \pkg{luaotfload} documentation for more information.
%
% \paragraph{\pkg{babel}}
% \emph{The \pkg{babel} package is not really supported!} Especially Vietnamese,
% Greek, and Hebrew at least might not work correctly, as far as I can tell.
% There's a better chance with Cyrillic and Latin-based languages,
% however---\pkg{fontspec} ensures at least that fonts should load correctly,
% but hyphenation and other matters aren't guaranteed. Under \XeTeX, the
% \pkg{polyglossia} package is recommended instead as a modern replacement for
% \pkg{babel}.
%
%
%
% \subsection{Maths fonts adjustments}
% By default, \pkg{fontspec} adjusts \LaTeX's
% default maths setup in order to maintain the correct Computer Modern symbols
% when the roman font changes. However, it will attempt to avoid doing this if
% another maths font package is loaded (such as \pkg{mathpazo} or the
% \pkg{unicode-math} package).
%
% If you find that \pkg{fontspec} is incorrectly changing the maths font when it should be
% leaving well enough alone, apply the |[no-math]| package option to manually
% suppress its maths font.
%
% \subsection{Configuration} If you wish to customise any part of the
% \pkg{fontspec} interface (see later in this manual, \vref{sec:newfeatures}
% and~\ref{sec:aliasfontfeature}), this should be done by creating your own
% \texttt{fontspec.cfg} file,
% which will be automatically loaded if it is found by \XeTeX\ or \LuaTeX. Either place it
% in the same folder as the main document for isolated cases, or in a location
% that \XeTeX\ or \LuaTeX\ searches by default; \eg\ in Mac\TeX: \path{~/Library/texmf/tex/latex/}.
% The package option |[no-config]| will suppress this behaviour under all circumstances.
%
% \subsection{Warnings}
% \label{sec:quiet-warnings}
%
% This package can give many warnings that can be harmless if you know what
% you're doing. Use the |[quiet]| package option to write these warnings to the
% transcript (\texttt{.log}) file instead.
%
% Use the |[silent]| package option to completely suppress these warnings if you
% don't even want the |.log| file cluttered up.
%
%
%
%
%
% \part{General font selection}
%
% This section concerns the variety of commands that can be used to select
% fonts.
%
% \cmdbox{%
%   \CMD{\string\fontspec} \oarg{font features} \marg{font name}\\
%   \CMD{\string\setmainfont} \oarg{font features} \marg{font name}\\
%   \CMD{\string\setsansfont} \oarg{font features} \marg{font name}\\
%   \CMD{\string\setmonofont} \oarg{font features} \marg{font name}\\
%   \CMD{\string\newfontfamily} \meta{cmd} \oarg{font features} \marg{font name}
% }
%
% These are the main font-selecting commands of this package.
% The \cs{fontspec} command selects a font for one-time use; all
% others should be used to define the standard fonts used in a document.
% They will be described later in this section.
%
% The font features argument accepts comma separated
% \meta{font feature}=\meta{option} lists; these are described in later:
% \begin{itemize}
% \item For general font features, see \vref{sec:font-ind-features}
% \item For OpenType fonts, see Part~\vref{sec:opentype-features}
% \item For \XeTeX-only general font features, see Part~\vref{sec:xetex-features}
% \item For \LuaTeX-only general font features, see Part~\vref{sec:luatex-features}
% \item For features for \AAT\ fonts in \XeTeX, see \vref{sec:aat-features}
% \end{itemize}
%
% \section{Font selection}
%
% In both \LuaTeX\ and \XeTeX, fonts can be selected either by `font name' or
% by `file name'.
%
% \subsection{By font name}
%
% Fonts known to \LuaTeX\ or \XeTeX\ may be loaded by their names.
% `Known to' in this case generally means `exists in a standard fonts location'
% such as |~/Library/Fonts| on \MacOSX, or |C:\Windows\Fonts| on Windows.
%
% The simplest example might be something like
% \begin{Verbatim}
%   \fontspec[ ... ]{Cambria}
% \end{Verbatim}
% in which the bold and italic fonts will be found automatically
% (if they exist) and are immediately accessible with the usual
% \cs{textit} and \cs{textbf} commands.
%
% TODO: add explanation for how to find out what the `font name' is.
%
%
% \subsection{By file name}
% \label{sec:by-file-name}
%
% \XeTeX\ and \LuaTeX\ also allow fonts to be loaded by file name instead of font name.
% When you have a very large collection of fonts, you will sometimes not
% wish to have them all installed in your system's font directories.
% In this case, it is more convenient to load them from a different location on your disk.
% This technique is also necessary in \XeTeX\ when loading OpenType fonts that are present within your \TeX\ distribution, such as \path{/usr/local/texlive/2010/texmf-dist/fonts/opentype/public}.
% Fonts in such locations are visible to \XeTeX\ but cannot be loaded by font name, only file name; \LuaTeX\ does not have this restriction.
%
% When selecting fonts by file name, any font that can be found in the default
% search paths may be used directly (including in the current directory)
% without having to explicitly define the location of the font file on disk.
%
% \paragraph{\XeTeX\ \& Mac users only:}
% Note that \XeTeX\ can only select fonts in this way with the |xdvipdfmx| driver, but \XeTeX\ with the |xdv2pdf| driver can only select system-installed fonts
% by font name and not file name. The |xdvipdfmx| driver is default for \XeTeX, so this is only a problem if you wish to explicitly use
% the |xdv2pdf| driver.
%
% Fonts selected by filename must include bold and italic variants explicitly.
% \begin{Verbatim}
%   \fontspec
%      [ BoldFont       = texgyrepagella-bold.otf ,
%        ItalicFont     = texgyrepagella-italic.otf ,
%        BoldItalicFont = texgyrepagella-bolditalic.otf ]
%      {texgyrepagella-regular.otf}
% \end{Verbatim}
% \pkg{fontspec} knows that the font is to be selected by file name by the
% presence of the `|.otf|' extension.
% An alternative is to specify the extension separately, as shown following:
% \begin{Verbatim}
%   \fontspec
%      [ Extension      = .otf ,
%        BoldFont       = texgyrepagella-bold ,
%        ... ]
%      {texgyrepagella-regular}
% \end{Verbatim}
% If desired, an abbreviation can be applied to the font names based on the
% mandatory `font name' argument:
% \begin{Verbatim}
%   \fontspec
%      [ Extension      = .otf ,
%        UprightFont    = *-regular ,
%        BoldFont       = *-bold ,
%        ... ]
%      {texgyrepagella}
% \end{Verbatim}
% In this case `texgyrepagella' is no longer the name of an actual font,
% but is used to construct the font names for each shape;
% the |*| is replaced by `texgyrepagella'.
% Note in this case that |UprightFont| is required for constructing the font
% name of the normal font to use.
%
% To load a font that is not in one of the default search paths, its location
% in the filesystem must be specified with the |Path| feature:
% \begin{Verbatim}
%   \fontspec
%      [ Path           = /Users/will/Fonts/ ,
%        UprightFont    = *-regular ,
%        BoldFont       = *-bold ,
%        ... ]
%      {texgyrepagella}
% \end{Verbatim}
% Note that \XeTeX\ and \LuaTeX\ are able to load the font without giving an
% extension, but \pkg{fontspec} must know to search for the file; this can can
% be indicated by declaring the font exists in an `|ExternalLocation|':
% \begin{Verbatim}
%   \fontspec
%      [ ExternalLocation ,
%        BoldFont       = texgyrepagella-bold ,
%        ... ]
%      {texgyrepagella-regular}
% \end{Verbatim}
% To be honest, |Path| and |ExternalLocation| are actually the same feature
% with different names. The former can be given without an argument and the
% latter can be given with one; the different names are just for clarity.
%
%
% \section{Default font families}
% \label{sec:setxxfont}
%
% \cmdbox{
%   \cmd{\setmainfont} \oarg{font features} \marg{font name} \\
%   \cmd{\setsansfont} \oarg{font features} \marg{font name} \\
%   \cmd{\setmonofont} \oarg{font features} \marg{font name}
% }
%
% These commands are used to select
% the default font families for the entire document. They take the
% same arguments as \cmd{\fontspec}. See \exref{fontload}.
% Here, the scales of the fonts have been chosen to equalise their
% lowercase letter heights. The \feat{Scale} font feature will be discussed
% further in \vref{sec:font-ind-features}, including methods for automatic
% scaling.
%
% \begin{Lexample}{fontload}{Loading the default, sans serif, and monospaced fonts.}
%   \setmainfont{TeX Gyre Bonum}
%   \setsansfont[Scale=MatchLowercase]{Latin Modern Sans}
%   \setmonofont[Scale=MatchLowercase]{Inconsolata}
%
%   \rmfamily Pack my box with five dozen liquor jugs\par
%   \sffamily Pack my box with five dozen liquor jugs\par
%   \ttfamily Pack my box with five dozen liquor jugs
% \end{Lexample}
%
%
%
%
% \section{New commands to select font families}
%
% \cmdbox{
%   \CMD{\string\newfontfamily} \cs{\meta{font-switch}} \oarg{font features} \marg{font name} \\
%   \CMD{\string\newfontface} \cs{\meta{font-switch}} \oarg{font features} \marg{font name}
% }
%
% \noindent For cases when a specific font with a specific
% feature set is going to be re-used many times in a document, it is inefficient
% to keep calling \cs{fontspec} for every use. While the \cs{fontspec} command does not define
% a new font instance after the first call, the feature options must still be
% parsed and processed.
%
% \DescribeMacro{\newfontfamily}
% For this reason, new commands can be created for loading a particular font
% family with the \cmd\newfontfamily\ command, demonstrated in \exref{nff}.
% This macro should be used to create commands that would be used in
% the same way as \cmd\rmfamily, for example.
% If you would like to create a command that only changes the font
% inside its argument (i.e., the same behaviour as \cs{emph}) define it using regular \LaTeX\
% commands:
% \begin{Verbatim}
%   \newcommand\textnote[1]{{\notefont #1}}
%   \textnote{This is a note.}
% \end{Verbatim}
% Note that the double braces are intentional; the inner pair are used to
% to delimit the scope of the font change.
%
% \begin{Lexample}{nff}{Defining new font families.}
%   \newfontfamily\notefont{Kurier}
%   \notefont This is a \emph{note}.
% \end{Lexample}
%
% \DescribeMacro{\newfontface}
% Sometimes only a specific font face is desired, without accompanying italic or bold variants
% being automatically selected.
% This is common when selecting a fancy italic font, say, that has swash features unavailable
% in the upright forms. \cmd\newfontface\ is used for this purpose, shown
% in \exref{nfface}, which is repeated in \vref{sec:contextuals}.
%
% \begin{Xexample}{nfface}{Defining a single font face.}
%   \newfontface\fancy
%       [Contextuals={WordInitial,WordFinal}]
%                        {Hoefler Text Italic}
%   \fancy where is all the vegemite
%   % \emph, \textbf, etc., all don't work
% \end{Xexample}
%
% Comment for advanced users:
% The commands defined by \cs{newfontface} and \cs{newfontfamily} include
% their encoding information, so even if the document is set to use a
% legacy \TeX\ encoding, such commands will still work correctly. For example,
% \begin{verbatim}
% \documentclass{article}
% \usepackage{fontspec}
% \newfontfamily\unicodefont{Lucida Grande}
% \usepackage{mathpazo}
% \usepackage[T1]{fontenc}
% \begin{document}
% A legacy \TeX\ font. {\unicodefont A unicode font.}
% \end{document}
% \end{verbatim}
%
% \subsection{More control over font shape selection}
% \label{sec:bfitfonts}
%
% \cmdbox{
%  \feat{BoldFont} = \meta{font name} \\
%  \feat{ItalicFont} = \meta{font name} \\
%  \feat{~BoldItalicFont} = \meta{font name} \\
%  \feat{SlantedFont} = \meta{font name} \\
%  \feat{BoldSlantedFont} = \meta{font name} \\
%  \feat{SmallCapsFont} = \meta{font name}
% }
%
% The automatic bold, italic, and bold italic font selections will not be
% adequate for the needs of every font: while some fonts mayn't even
% have bold or italic shapes, in which case a skilled (or lucky)
% designer may be able to chose well-matching accompanying shapes from
% a different font altogether, others can have a range of bold and
% italic fonts to chose among.  The \feat{BoldFont} and
% \feat{ItalicFont} features are provided for these situations. If only
% one of these is used, the bold italic font is requested as the
% default from the \emph{new} font. See \exref{bff}.
%
% \begin{Xexample}{bff}{Explicit selection of the bold font.}
%   \fontspec[BoldFont={Helvetica Neue}]
%                           {Helvetica Neue UltraLight}
%                 Helvetica Neue UltraLight         \\
%   {\itshape     Helvetica Neue UltraLight Italic} \\
%   {\bfseries               Helvetica Neue       } \\
%   {\bfseries\itshape       Helvetica Neue Italic} \\
% \end{Xexample}
%
% If a bold italic shape is not defined, or you want to specify
% \emph{both} custom bold and italic shapes, the \feat{BoldItalicFont}
% feature is provided.
%
% \subsubsection{Input shorthands}
%
% For those cases that the base font name is repeated, you can
% replace it with an asterisk. (This has been shown previously in \vref{sec:by-file-name}.)
% For example,
% some space can be saved instead of writing `\texttt{Baskerville SemiBold}':
% \begin{Verbatim}
%   \fontspec[BoldFont={* SemiBold}]{Baskerville}
% \end{Verbatim}
%
% As a matter of fact, this feature can also be used for the upright font too:
% \begin{Verbatim}
%   \fontspec[UprightFont={* SemiBold},
%             BoldFont={* Bold}]{Baskerville}
% \end{Verbatim}
%
% \subsubsection{Small caps and slanted font shapes}
%
% For the rare situations where a font family will have slanted \emph{and}
% italic shapes, these may be specified separately using the analogous
% features \feat{SlantedFont} and \feat{BoldSlantedFont}. Without these,
% however, the \LaTeX\ font switches for slanted (\cs{textsl}, \cs{slshape})
% will default to the italic shape.
%
% Old-fashioned font families used to distribute their small caps
% glyphs in separate fonts due to the limitations on the number
% of glyphs allowed in the PostScript Type~1 format. Such fonts may be used
% by declaring the \feat{SmallCapsFont} of the family you are specifying:
% \begin{Verbatim}
%   \fontspec[
%     SmallCapsFont={Minion MM Small Caps & Oldstyle Figures}
%            ]{Minion MM Roman}
%   Roman 123 \\ \textsc{Small caps 456}
% \end{Verbatim}
% For most modern fonts that have small caps as a font feature, this level of
% control isn't generally necessary, but you may still occasionally find font
% families in which the small caps are in a separate font.
%
% All of the bold, italic, and small caps fonts can be loaded with different
% font features from the main font. See \ref{sec:bfit-feat} for details.
% When an OpenType font is selected for |SmallCapsFont|, the small caps
% font feature is \emph{not} automatically enabled. In this case, users
% should write instead
% \begin{Verbatim}
%   \fontspec[
%     SmallCapsFont={...},
%     SmallCapsFeatures={Letters=SmallCaps},
%            ]{...}
% \end{Verbatim}
%
% \subsection{Math(s) fonts}
%
% When \cmd\setmainfont, \cmd\setsansfont\ and \cmd\setmonofont\ are used in the
% preamble, they also define the fonts to be used in maths mode inside the
% \cmd\mathrm-type commands. This only occurs in the preamble because \LaTeX\
% freezes the maths fonts after this stage of the processing. The \pkg{fontspec}
% package must also be loaded after any maths font packages (\eg, \pkg{euler})
% to be successful. (Actually, it is \emph{only} \pkg{euler} that is the
% problem.\footnote{Speaking of \pkg{euler}, if you want to use its
% \texttt{[mathbf]} option, it won't work, and you'll need to put this after
% \pkg{fontspec} is loaded instead:
% \ttfamily\cmd\AtBeginDocument\char`\{\cmd\DeclareMathAlphabet\cmd\mathbf\char`\{U\char`\}\char`\{eur\char`\}\char`\{b\char`\}\char`\{n\char`\}})
%
% Note that you may find that loading some maths packages won't be as smooth as
% you expect since \pkg{fontspec} (and \XeTeX\ in general) breaks many of the
% assumptions of \TeX\ as to where maths characters and accents can be found.
% Contact me if you have troubles, but I can't guarantee to be able to fix any
% incompatibilities. The Lucida and Euler maths fonts should be fine; for all
% others keep an eye out for problems.
%
% \cmdbox{
%   \cmd{\setmathrm} \oarg{font features} \marg{font name} \\
%   \cmd{\setmathsf} \oarg{font features} \marg{font name} \\
%   \cmd{\setmathtt} \oarg{font features} \marg{font name} \\
%   \cmd{\setboldmathrm} \oarg{font features} \marg{font name}
% }
%
% However, the default text fonts may not necessarily be the ones you
% wish to use when typesetting maths (especially with the use of fancy
% ligatures and so on). For this reason, you may optionally use the
% commands above (in the same way as our other
% \cmd\fontspec-like commands) to explicitly state which fonts to use
% inside such commands as \cmd\mathrm. Additionally, the
% \cmd\setboldmathrm\ command allows you define the font used for
% \cmd\mathrm\ when in bold maths mode (which is activated with, among
% others, \cmd\boldmath).
%
% For example, if you were using Optima with the Euler maths font, you
% might have this in your preamble:
% \begin{Verbatim}
%   \usepackage{mathpazo}
%   \usepackage{fontspec,xunicode}
%   \setmainfont{Optima}
%   \setmathrm{Optima}
%   \setboldmathrm[BoldFont={Optima ExtraBlack}]{Optima Bold}
% \end{Verbatim}
%
%
% \subsection{Miscellaneous font selecting details}
%
% \paragraph{Spaces}
% \cmd\fontspec\ and \cmd\addfontfeatures\ ignore trailing spaces as
% if it were a `naked' control sequence; \eg, `|M. \fontspec{...} N|' and
% `|M. \fontspec{...}N|' are the same.
%
% \paragraph{Italic small caps}
% Note that this package redefines the \cs{itshape} and \cs{scshape}
% commands in order to allow them to select italic small caps in
% conjunction.
%
% \paragraph{Emphasis and nested emphasis}
% You may specify the behaviour of the \cs{emph} command by setting the
% \cs{emshape} command. \Eg, for bold emphasis:\par
% \indent|\renewcommand\emshape{\bfseries}|\par\noindent
% Nested emphasis is controlled by the \cs{eminnershape} command.
% For example, for |\emph{\emph{...}}| to produce small caps:\par
% \indent|\renewcommand\eminnershape{\scshape}|\par\noindent
% \XeTeX\ users will need to load the \pkg{xltxtra} package before the
% advice above works.
%
%
%
%
%
% \section{Selecting font features}
% \label{sec:selectingfeature}
%
% The commands discussed so far such as \cmd{fontspec} each take an optional argument for
% accessing the font features of the requested font.
% Commands are provided to set default features to be applied for all fonts, and even to change the features that a font is presently loaded with.
% Different font shapes can be loaded with separate features, and different features can even be selected for different sizes that the font appears in.
% This section discusses these options.
%
% \subsection{Default settings} \label{sec:defaults}
%
% \cmdbox{\cmd\defaultfontfeatures \marg{font features}}
%
% It is desirable to define
% options that are applied to every subsequent font selection command:
% a default feature set, so to speak. This may be defined with the
% \cmd{\defaultfontfeatures} command, shown in \exref{dff}.
% New calls of \cs{defaultfontfeatures} overwrite previous ones.
%
% \begin{Xexample}{dff}{A demonstration of the \cs{defaultfontfeatures} command.}
%   \fontspec{TeX Gyre Adventor}
%   Some default text 0123456789 \\
%   \defaultfontfeatures{
%      Numbers=OldStyle, Color=888888
%   }
%   \fontspec{TeX Gyre Adventor}
%   Now grey, with old-style figures:
%   0123456789
% \end{Xexample}
%
% \subsection{Changing the currently selected features}
% \label{sec:addfontfeatures}
%
% \cmdbox{\cmd\addfontfeatures \marg{font features}}
%
% This command allows font features to
% be changed without knowing what features are currently selected or even what
% font is being used. A good example of this could be to add a hook to all
% tabular material to use monospaced numbers, as shown in \exref{aff}.
%
% \begin{Lexample}{aff}{A demonstration of the \cs{addfontfeatures} command.}
%   \fontspec[Numbers={Proportional,OldStyle}]
%            {TeX Gyre Adventor}
%   `In 1842, 999 people sailed 97 miles in
%    13 boats. In 1923, 111 people sailed 54
%    miles in 56 boats.'            \bigskip
%
%   {\addfontfeatures{Numbers={Monospaced,Lining}}
%   \begin{tabular}{@{} cccc @{}}
%             Year & People & Miles & Boats \\
%     \hline  1842 &  999   &  75   &  13   \\
%             1923 &  111   &  54   &  56
%   \end{tabular}}
% \end{Lexample}
%
% \DescribeMacro{\addfontfeature}
% This command may also be executed under the alias \cmd{\addfontfeature}.
%
% \subsection{Priority of feature selection}
% Features defined with \cs{addfontfeatures} override features
% specified by \cs{fontspec}, which in turn override features
% specified by \cs{defaultfontfeatures}.  If in doubt, whenever a
% new font is chosen for the first time, an entry is made in the
% transcript (\texttt{.log}) file displaying the font name and the
% features requested.
%
% \subsection{Different features for different font shapes}
% \label{sec:bfit-feat}
%
% \cmdbox{
%  \feat{BoldFeatures}\marg{features} \\
%  \feat{ItalicFeatures}\marg{features} \\
%  \feat{BoldItalicFeatures}\marg{features} \\
%  \feat{SlantedFeatures}\marg{features} \\
%  \feat{BoldSlantedFeatures}\marg{features} \\
%  \feat{SmallCapsFeatures}\marg{features}
% }
%
% It is entirely possible that separate fonts in a family will require
% separate options; \eg, Hoefler Text Italic contains various swash
% feature options that are completely unavailable in the upright shapes.
%
% The font features defined at the top level of the optional \cmd\fontspec\
% argument are applied to \emph{all} shapes of the family.
% Using \feat{Upright-}, \feat{SmallCaps-}, \feat{Bold-},
% \feat{Italic-}, and \feat{BoldItalicFeatures},
% separate font features may be defined to their respective shapes
% \emph{in addition} to, and with precedence over, the `global' font features.
% See \exref{itfeat}.
%
% \begin{Xexample}{itfeat}{Features for, say, just italics.}
%   \fontspec{Hoefler Text} \itshape \scshape
%   Attention All Martini Drinkers \\
%   \addfontfeature{ItalicFeatures={Alternate = 1}}
%   Attention All Martini Drinkers \\
% \end{Xexample}
%
% Combined with the options for selecting arbitrary \emph{fonts} for
% the different shapes, these separate feature options allow the
% selection of arbitrary weights in the Skia typeface, as shown in \exref{bffeat}.
%
% \begin{Xexample}{bffeat}{Multiple Master--like features in AAT fonts.}
%   \fontspec[BoldFont={Skia},
%    BoldFeatures={Weight=2}]{Skia}
%   Skia \\ \bfseries Skia `Bold'
% \end{Xexample}
%
% Note that because most fonts include their small caps glyphs
% within the main font, features specified with \feat{SmallCapsFeatures} are applied \emph{in addition} to
% any other shape-specific features as defined above, and hence \feat{SmallCapsFeatures}
% can be nested within \feat{ItalicFeatures} and friends. Every combination
% of upright, italic, bold and small caps can thus be assigned individual
% features, as shown in the somewhat ludicrous \exref{scfeat}.
%
% \begin{Xexample}{scfeat}{An example of setting the \feat{SmallCapsFeatures}
% separately for each font shape.}
%   \fontspec[
%       UprightFeatures={Color = 220022,
%            SmallCapsFeatures = {Color=115511}},
%        ItalicFeatures={Color = 2244FF,
%            SmallCapsFeatures = {Color=112299}},
%          BoldFeatures={Color = FF4422,
%            SmallCapsFeatures = {Color=992211}},
%    BoldItalicFeatures={Color = 888844,
%            SmallCapsFeatures = {Color=444422}},
%            ]{TeX Gyre Termes}
%   Upright {\scshape Small Caps}\\
%   \itshape Italic {\scshape Italic Small Caps}\\
%   \upshape\bfseries Bold {\scshape Bold Small Caps}\\
%   \itshape Bold Italic {\scshape Bold Italic Small Caps}
% \end{Xexample}
%
% \subsection{Different features for different font sizes}
% \label{sec:sizefeature}
%
% \cmdbox{
% \ttfamily SizeFeatures = \char`\{\\
% \null\quad...\\
% \null\quad\char`\{~Size =
% \rmfamily\meta{size range}\ttfamily
% ,
% \rmfamily \meta{font features}\ttfamily
% ~\char`\} , \\
% \null\quad\char`\{~Size =
% \rmfamily\meta{size range}\ttfamily
% , Font =
% \rmfamily\meta{font name}\texttt, \meta{font features}\ttfamily
% ~\char`\} , \\
% \null\quad... \\
% \char`\}}
%
% The \feat{SizeFeature} feature is a little more complicated
% than the previous features discussed. It allows different fonts
% and different font features to be selected for a given font
% family as the point size varies.
%
% It takes a comma separated list of braced, comma separated lists of features for each size range.
% Each sub-list must contain the \opt{Size} option
% to declare the size range, and optionally \opt{Font} to change the
% font based on size. Other (regular) fontspec features that are added
% are used on top of the font features that would be used anyway.
% A demonstration to hopefully clarify these details is shown in \exref{sizefeat}.
% A less trivial example is shown in the context of optical font sizes
% in \vref{sec:opticalsize}.
%
% \begin{Xexample}{sizefeat}{An example of specifying different font features for different sizes of font with \feat{SizeFeatures}.}
%   \fontspec[ SizeFeatures={
%       {Size={-8}, Font=TeX Gyre Bonum Italic, Color=AA0000},
%       {Size={8-14}, Color=00AA00},
%       {Size={14-}, Color=0000AA}} ]{TeX Gyre Chorus}
%
%   {\scriptsize Small\par} Normal size\par {\Large Large\par}
% \end{Xexample}
%
% To be precise, the \opt{Size} sub-feature accepts arguments in the form shown in \vref{tab:sizing}.
% Braces around the size range are optional. For an exact font size (|Size=X|)
% font sizes chosen near that size will `snap'. For example, for size definitions
% at exactly 11pt and 14pt, if a 12pt font is requested \emph{actually} the
% 11pt font will be selected. This is a remnant of the past when fonts were designed
% in metal (at obviously rigid sizes) and later when bitmap fonts were similarly
% designed for fixed sizes.
%
% If additional features are only required for a single size, the other sizes
% must still be specified.  As in:
% \begin{verbatim}
%   SizeFeatures={
%      {Size=-10,Numbers=Uppercase},
%      {Size=10-}}
% \end{verbatim}
% Otherwise, the font sizes greater than 10 won't be defined!
%
% \begin{table}
% \caption{Syntax for specifying the size to apply custom font features.}\label{tab:sizing}
% \centering
% \begin{tabular}{@{}ll@{}}
% \toprule
% Input & Font size, $s$ \\
% \midrule
%  |Size = X-| & $s \geq \texttt{X}$ \\
%  |Size = -Y| & $s < \texttt{Y}$ \\
%  |Size = X-Y| & $\texttt{X} \leq s < \texttt{Y}$ \\
%  |Size = X| & $s = \texttt{X}$ \\
% \bottomrule
% \end{tabular}
% \end{table}
%
%
% \section{Font independent options} \label{sec:font-ind-features}
%
% Features introduced in this section may be used with any font.
%
% \subsection{Colour}
%
% \feat{Color} (or \feat{Colour}), also shown in \vref{sec:defaults}
% and elsewhere, uses font specifications to set the colour of
% the text. The colour is defined as a triplet of two-digit Hex RGB
% values, with optionally another value for the transparency (where
% |00| is completely transparent and |FF| is opaque.)
% \begin{Xexample}{color}{Selecting colour with transparency.}
%   \fontsize{48}{48}
%   \fontspec{TeX Gyre Bonum Bold}
%   {\addfontfeature{Color=FF000099}W}\kern-1ex
%   {\addfontfeature{Color=0000FF99}S}\kern-0.8ex
%   {\addfontfeature{Color=DDBB2299}P}\kern-0.8ex
%   {\addfontfeature{Color=00BB3399}R}
% \end{Xexample}
% Transparency is supported by \LuaLaTeX and by \XeLaTeX\ with the \texttt{xdv2pdf}
% driver (\MacOSX\ only); \XeLaTeX\ with the \texttt{xdvipdfmx} driver
% does not support this feature.
%
% If you load the \pkg{xcolor} package, you may use any named colour instead
% of writing the colours in hexadecimal.
% \begin{Verbatim}
%  \usepackage{xcolor}
%  ...
%  \fontspec[Color=red]{Verdana} ...
%  \definecolor{Foo}{rgb}{0.3,0.4,0.5}
%  \fontspec[Color=Foo]{Verdana} ...
% \end{Verbatim}
% The \pkg{color} package is \emph{not} supported; use \pkg{xcolor} instead.
%
% You may specify the transparency with a named colour using the \feat{Opacity}
% feature:
% \begin{Verbatim}
%  \fontspec[Color=red,Opacity=0.7]{Verdana} ...
% \end{Verbatim}
%
% \subsection{Scale}
%
% \cmdbox{
%  \feat{Scale} = \meta{number} \\
%  \feat{Scale} = \opt{MatchLowercase} \\
%  \feat{Scale} = \opt{MatchUppercase}
% }
%
% In its explicit form, \feat{Scale} takes a single
% numeric argument for linearly scaling the font, as demonstrated
% in \vref{sec:setxxfont}.
% It is now possible to
% measure the correct dimensions of the fonts loaded and
% calculate values to scale them automatically.
%
% As well as a numerical argument, \feat{Scale} feature
% also accepts options \opt{MatchLowercase}
% and \opt{MatchUppercase}, which will scale the font being selected to match
% the current default roman font to either the height of the lowercase or
% uppercase letters, respectively; these features are shown in \exref{scale}.
%
% \begin{Xexample}{scale}{Automatically calculated scale values.}
%   \setmainfont{Georgia}
%   \newfontfamily\lc[Scale=MatchLowercase]{Verdana}
%    The perfect match {\lc is hard to find.}\\
%   \newfontfamily\uc[Scale=MatchUppercase]{Arial}
%    L O G O \uc F O N T
% \end{Xexample}
%
% The amount of scaling used in each instance is reported in the \texttt{.log} file.
% Since there is some subjectivity about the exact scaling to be used, these values
% should be used to fine-tune the results.
%
%
%
%
% \subsection{Interword space}
%
% While the space between words can be varied on an individual
% basis with the \TeX\ primitive \cmd\spaceskip\ command, it is
% more convenient to specify this information when the font is
% first defined.
%
% The space in between words in a paragraph will be chosen automatically,
% and generally will not need to be adjusted. For those
% times when the precise details are important, the \feat{WordSpace}
% feature is
% provided, which takes either a single scaling factor to scale the
% default value, or a triplet of comma-separated
% values to scale the nominal value, the stretch, and the shrink of the
% interword space by, respectively. (|WordSpace={|$x$|}| is the same as
% |WordSpace={|$x$|,|$x$|,|$x$|}|.)
%
% \begingroup
% \let\centering\relax
% \begin{Xexample}{wordspace}{Scaling the default interword space. An exaggerated value has been chosen to emphasise the effects here.}
%   \fontspec{TeX Gyre Termes}
%   Some text for our example to take
%   up some space, and to demonstrate
%   the default interword space.
%   \bigskip
%
%   \addfontfeature{ WordSpace = 0.3 }
%   Some text for our example to take
%   up some space, and to demonstrate
%   the default interword space.
% \end{Xexample}
% \endgroup
%
% \subsection{Post-punctuation space}
%
% If \cmd\frenchspacing\ is \emph{not} in effect, \TeX\ will allow extra
% space after some punctuation in its goal of justifying the lines of text.
% Generally, this is considered old-fashioned, but occasionally in small amounts the
% effect can be justified, pardon the pun.
%
% The \feat{PunctuationSpace} feature takes a scaling factor by which to
% adjust the nominal value chosen for the font; this is demonstrated in
% \exref{punctspace}.
% Note that |PunctuationSpace=0|
% is \emph{not} equivalent to \cmd\frenchspacing, although the difference
% will only be apparent when a line of text is under-full.
%
% \begin{Lexample}{punctspace}{Scaling the default post-punctuation space.}
%   \nonfrenchspacing
%   \fontspec{TeX Gyre Schola}
%    Letters, Words. Sentences.          \par
%   \fontspec[PunctuationSpace=2]{TeX Gyre Schola}
%    Letters, Words. Sentences.          \par
%   \fontspec[PunctuationSpace=0]{TeX Gyre Schola}
%    Letters, Words. Sentences.
% \end{Lexample}
%
%
%
%
% \subsection{The hyphenation character}
%
% The letter used for hyphenation may be chosen with the \feat{HyphenChar}
% feature. It takes three types of input, which are chosen according to some
% simple rules. If the input is the string \opt{None}, then hyphenation is
% suppressed for this font.
% If the input is a single character, then this
% character is used. Finally, if the input is longer than a single character
% it must be the UTF-8 slot number of the hyphen character you desire.
%
% This package
% redefines \LaTeX's \cmd\-\ macro
% such that it adjusts along with the above changes.
%
% \begin{Xexample}{hyphchar}{Explicitly choosing the hyphenation character.}
%  \def\text{\fbox{\parbox{1.55cm}{%
%    EXAMPLE HYPHENATION%
%  }}\qquad\qquad\null\par\bigskip}
%
%  \fontspec{Linux Libertine}
%  \addfontfeature{HyphenChar=None}
%  \text
%  \addfontfeature{HyphenChar={+}}
%  \text
% \end{Xexample}
%
% \subsection{Optical font sizes} \label{sec:opticalsize}
%
% Optically scaled fonts thicken out as the font size decreases
% in order to make the glyph shapes more robust (less prone to losing
% detail), which improves legibility. Conversely, at large optical
% sizes the serifs and other small details may be more delicately
% rendered.
%
% OpenType fonts with optical scaling will exist in
% several discrete sizes, and these will be selected by \XeTeX\
% \emph{automatically} determined by the current font size as in
% \exref{optsize}, in which we've scaled down some large text in order to be
% able to compare the difference for equivalent font sizes.
%
% The
% \opt{OpticalSize} option may be used to specify a different optical
% size.
% With \opt{OpticalSize} set
% to zero, no optical size font substitution is performed, as shown in
% \exref{optsize0}.
%
% \begin{Xexample}{optsize}{A demonstration of automatic optical size selection.}
%   \fontspec{Latin Modern Roman}
%    Automatic optical size                  \\
%   \scalebox{0.4}{\Huge
%    Automatic optical size}
% \end{Xexample}
%
% \begin{Xexample}{optsize0}{Optical size substitution is suppressed when set to zero.}
%   \fontspec[OpticalSize=0]{Latin Modern Roman 5 Regular}
%    Latin Modern optical sizes                \\
%   \fontspec[OpticalSize=0]{Latin Modern Roman 8 Regular}
%    Latin Modern optical sizes                \\
%   \fontspec[OpticalSize=0]{Latin Modern Roman 12 Regular}
%    Latin Modern optical sizes                \\
%   \fontspec[OpticalSize=0]{Latin Modern Roman 17 Regular}
%    Latin Modern optical sizes
% \end{Xexample}
%
% The \feat{SizeFeatures} feature (\vref*{sec:sizefeature}) can be
% used to specify exactly which optical sizes will be used for ranges
% of font size. For example, something like:
% \begin{verbatim}
%   \fontspec[
%     SizeFeatures={
%       {Size=-10,     OpticalSize=8 },
%       {Size= 10-14,  OpticalSize=10},
%       {Size= 14-18,  OpticalSize=14},
%       {Size=    18-, OpticalSize=18}}
%            ]{Latin Modern Roman}
% \end{verbatim}
%
% \part{OpenType}
% \label{sec:opentype-features}
%
% \section{Introduction}
% \label{sec:opentype-features-intro}
%
% OpenType fonts (and other `smart' font technologies such as AAT and Graphite) can change the appearance of text in many different ways.
% These changes are referred to as features.
% When the user applies a feature~--- for example, small capitals~--- to a run of text, the code inside the font makes appropriate adjustments and small capitals appear in place of lowercase letters.
% However, the use of such features does not affect the underlying text.
% In our small caps example, the lowercase letters are still stored in the document; only the appearance has been changed by the OpenType feature.
% This makes it possible to search and copy text without difficulty.
% If the user selected a different font that does not support small caps, the `plain' lowercase letters would appear instead.
%
% Some OpenType features are required to support particular scripts, and these features are often applied automatically.
% The scripts used in India, for example, often require that characters be reshaped and reordered after they are typed by the user, in order to display them in the traditional ways that readers expect.
% Other features can be applied to support a particular language.
% The Junicode font for medievalists uses by default the Old English shape of the letter thorn, while in modern Icelandic thorn has a more rounded shape.
% If a user tags some text as being in Icelandic, Junicode will automatically change to the Icelandic shape through an OpenType feature that localizes the shapes of letters.
%
% A very large group of OpenType features is designed to support high quality typography in Latin, Greek, Cyrillic and other standard scripts.
% Examples of some font features have already been shown in previous sections; the complete set of OpenType font features supported by \pkg{fontspec} is described below in \ref{sec:ot-feat}.
%
% The OpenType specification provides four-letter codes (e.g., \texttt{smcp} for small capitals) for each feature.  The four-letter codes are given below along with the \pkg{fontspec} names for various features, for the benefit of people who are already familiar with OpenType.  You can ignore the codes if they don't mean anything to you.
%
%
% \subsection{How to select font features}
%
% Font features are selected by a series of \meta{feature}=\meta{option}
% selections. Features are (usually) grouped logically; for example, all
% font features relating to ligatures are accessed by writing \verb|Ligatures={...}| with the appropriate argument(s), which could be \texttt{TeX}, \texttt{Rare}, etc., as shown below in \ref{sec:ot-feat-liga}.
%
% Multiple options may be given to
% any feature that accepts non-numerical input, although doing so will
% not always work. Some options will override others in generally
% obvious ways; \Verb|Numbers={OldStyle,Lining}| doesn't make much
% sense because the two options are mutually exclusive, and \XeTeX\
% will simply use the last option that is specified (in this case
% using \opt{Lining} over \opt{OldStyle}).
%
% If a feature or an option is requested that the font does not have,
% a warning is given in the console output. As mentioned in \vref{sec:quiet-warnings}
% these warnings can be suppressed by selecting the \texttt{[quiet]} package option.
%
% \section{Complete listing of OpenType font features}
% \label{sec:ot-feat}
%
% \subsection{Ligatures}
% \label{sec:ot-feat-liga}
%
% \feat{Ligatures} refer to the replacement of two separate characters
% with a specially drawn glyph for functional or \ae sthetic reasons.
% The list of options, of which multiple may be selected at one time,
% is shown in \ref{feat:Ligatures}.
% A demonstration with the Linux Libertine fonts\footnote{\url{http://www.linuxlibertine.org/}} is shown in \exref{lig}.
%
% Note the additional features accessed with \verb|Ligatures=TeX|. These are
% not actually real OpenType features, but additions provided by \pkg{luaotfload} (i.e., \LuaTeX\ only) to emulate \TeX's behaviour for \textsc{ascii} input of curly quotes and punctuation. In \XeTeX\ this is achieved with the \feat{Mapping} feature (see \vref{sec:mapping}) but for consistency \verb|Ligatures=TeX| will perform the same function as \verb|Mapping=tex-text|.
%
% \begin{features}{Ligatures}
% \otf*{Required}{rlig}
% \otf*{Common}{liga}
% \otf*{Contextual}{clig}
% \otf{Rare/Discretionary}{dlig}
% \otf{Historic}{hlig}
% \otf{TeX}{tlig/trep}
% \end{features}
%
% \begin{Lexample}[firstline=2]{lig}{An example of the \feat{Ligatures} feature.}
%    \Huge\centering
%    \def\test#1#2{%
%      #2 $\to$ {\addfontfeature{#1} #2}\\}
%    \fontspec{Linux Libertine}
%    \test{Ligatures=Historic}{strict}
%    \test{Ligatures=Rare}{wurtzite}
%    \test{Ligatures=NoCommon}{firefly}
% \end{Lexample}
%
% \subsection{Letters} \label{sec:letters}
% The \opt{Letters} feature specifies how the letters in the current font
% will look. OpenType fonts may contain the following options:
% \opt{Uppercase}, \opt{SmallCaps}, \opt{PetiteCaps},
% \opt{UppercaseSmallCaps}, \opt{UppercasePetiteCaps}, and
% \opt{Unicase}.
%
% \begin{features}{Letters}
% \otf{Uppercase}{case}
% \otf{SmallCaps}{smcp}
% \otf{PetiteCaps}{pcap}
% \otf{UppercaseSmallCaps}{c2sc}
% \otf{UppercasePetiteCaps}{c2pc}
% \otf{Unicase}{unic}
% \end{features}
%
% Petite caps are smaller than small caps.
% \opt{SmallCaps} and \opt{PetiteCaps}
% turn lowercase letters into the smaller caps letters,
% whereas the \opt{Uppercase...} options turn the \emph{capital} letters into
% the smaller
% caps (good, \eg, for applying to already uppercase acronyms like
% `NASA').
% This difference is shown in \exref{caps}.
% `Unicase' is a weird hybrid of upper and lower case letters.
%
% \begin{Lexample}{caps}{Small caps from lowercase or uppercase letters.}
%   \fontspec[Letters=SmallCaps]{TeX Gyre Adventor}
%    THIS SENTENCE no verb                \\
%   \fontspec[Letters=UppercaseSmallCaps]{TeX Gyre Adventor}
%    THIS SENTENCE no verb
% \end{Lexample}
%
% Note that the \opt{Uppercase} option will (probably)
% not actually map letters to uppercase.
%  \note{If you want automatic uppercase letters, look to \LaTeX's
%       \cmd\MakeUppercase\ command.}
% It is designed select various
% uppercase forms for glyphs such as accents and dashes, such as shown
% in \exref{letters-uppercase}; note the raised position of the hyphen
% to better match the surrounding letters.
%
% \begin{Lexample}{letters-uppercase}{An example of the \opt{Uppercase} option of the \feat{Letters} feature.}
%   \fontspec{Linux Libertine}
%    UPPER-CASE example \\
%   \addfontfeature{Letters=Uppercase}
%    UPPER-CASE example
% \end{Lexample}
%
% The \feat{Kerning} feature also contains an \opt{Uppercase} option,
% which adds a small amount of spacing in between letters (see \vref{sec:kerning}).
%
% \subsection{Numbers}
%
% The \feat{Numbers} feature defines how numbers will look in the
% selected font, accepting options shown in \ref{feat:Numbers}.
%
% \begin{features}{Numbers}
% \otf{Uppercase/Lining}{lnum}
% \otf{Lowercase/OldStyle}{onum}
% \otf{Proportional}{pnum}
% \otf{Monospaced}{tnum}
% \otf{SlashedZero}{zero}
% \otf{Arabic}{anum}
% \end{features}
%
% The synonyms
% \opt{Uppercase} and \opt{Lowercase} are equivalent to \opt{Lining} and
% \opt{OldStyle}, respectively.
% The differences have been shown previously
% in \vref{sec:addfontfeatures}.
% The \opt{Monospaced} option is useful for tabular material when digits need
% to be vertically aligned.
%
% The \opt{SlashedZero} option
% replaces the default zero with a slashed version to prevent
% confusion with an uppercase `O', shown in \exref{slashzero}.
%
% \begin{Lexample}{slashzero}{The effect of the \opt{SlashedZero} option.}
%   \fontspec[Numbers=Lining]{TeX Gyre Bonum}
%    0123456789
%   \fontspec[Numbers=SlashedZero]{TeX Gyre Bonum}
%    0123456789
% \end{Lexample}
%
% The \opt{Arabic} option (with tag \verb|anum|) maps regular numerals to their Arabic script or Persian equivalents
% based on the current \opt{Language} setting (see \vref{sec:ot}), shown in
% \exref{num-arab} using the Zar fonts\footnote{\url{http://wiki.irmug.org/index.php/X_Series_2}}.
% This option is based on a \LuaTeX\ feature of the \pkg{luaotfload} package,
% not an OpenType feature. (Thus, this feature is unavailable in \XeTeX.)
%
% \begin{Lexample}[firstline=2]{num-arab}{An example of number remapping to Arabic or Persian. (\LuaTeX\ only.)}
%   \huge
%   \fontspec[Script=Arabic,Numbers=Arabic]{XB Zar}
%   {\addfontfeature{Language=Arabic}
%    0123456789} \\
%   {\addfontfeature{Language=Parsi}
%    0123456789}
% \end{Lexample}
%
% \subsection{Contextuals}
% This feature refers to substitutions of glyphs that vary `contextually' by their relative position in a word or string of characters;
% features such as contextual swashes are accessed here.
%
% \begin{features}{Contextuals}
% \otf{Swash}{cswh}
% \otf{Alternate}{calt}
% \otf{WordInitial}{init}
% \otf{WordFinal}{fina}
% \otf{LineFinal}{falt}
% \otf{Inner}{medi}
% \end{features}
%
% \begin{Lexample}{swash}{An example of the \opt{Swashes} option of the \opt{Contextuals} feature.}
%   \fontspec{Warnock Pro} \itshape
%    Without Contextual Swashes             \\
%   \fontspec[Contextuals=Swash]{Warnock Pro}
%    With Contextual Swashes; cf. W C S
% \end{Lexample}
%
% Historic forms are accessed in OpenType
% fonts via the feature \feat{Style=Historic}; this is generally \emph{not}
% contextual in OpenType, which is why it is not included here.
%
% \subsection{Vertical Position}
%
% \begin{features}{VerticalPosition}
% \otf{Superior}{sups}
% \otf{Inferior}{subs}
% \otf{Numerator}{numr}
% \otf{Denominator}{dnom}
% \otf{ScientificInferior}{sinf}
% \otf{Ordinal}{ordn}
% \end{features}
%
% The \feat{VerticalPosition} feature is used to access things like
% subscript (\opt{Inferior}) and superscript (\opt{Superior}) numbers and
% letters (and a small amount of punctuation, sometimes).
% The \opt{Ordinal} option will only raise characters that are used
% in some languages directly after a number.
% The \opt{ScientificInferior} feature will move glyphs
% further below the baseline than the \opt{Inferior} feature.
% These are shown in \exref{vertpos}
%
% \opt{Numerator} and \opt{Denominator} should only be used for creating
% arbitrary fractions (see next section).
%
% \begin{Lexample}{vertpos}{The \feat{VerticalPosition} feature. Note that the \opt{Ordinal} option can be quite unreliable, as the results here demonstrate.}
%   \fontspec[VerticalPosition=Superior]{Warnock Pro}
%    Sup: abdehilmnorst (-\$12,345.67)                      \\
%   \fontspec[VerticalPosition=Numerator]{Warnock Pro}
%    Numerator: 12345                                       \\
%   \fontspec[VerticalPosition=Denominator]{Warnock Pro}
%    Denominator: 12345                                     \\
%   \fontspec[VerticalPosition=ScientificInferior]{Warnock Pro}
%    Scientific Inferior: 12345                             \\
%   \fontspec[VerticalPosition=Ordinal]{Warnock Pro}
%   `Ordinals': 1st 2nd 3rd 4th 0th
% \end{Lexample}
%
% The \pkg{realscripts} package (yet to be released)
% (or \pkg{xltxtra} for \XeTeX)
% redefines the \cmd\textsubscript\ and
% \cmd\textsuperscript\ commands to use the above font features automatically.
%
%
% \subsection{Fractions}
%
% \begin{features}{Fractions}
% \otf{On}{frac}
% \otf{Alternate}{afrc}
% \end{features}
%
% For OpenType fonts use a regular text slash to create fractions, but
% the \feat{Fraction} feature must be explicitly activated.
% Some (Asian fonts predominantly) also provide for the
% \opt{Alternate} feature. These are both shown in \exref{ot-frac}.
%
% \begin{Xexample}{ot-frac}{The \feat{Fractions} feature.}
%   \fontspec{Hiragino Maru Gothic Pro W4}
%    1/2 \quad 1/4 \quad 5/6 \quad 13579/24680 \\
%   \addfontfeature{Fractions=On}
%    1/2 \quad 1/4 \quad 5/6 \quad 13579/24680 \\
%   \addfontfeature{Fractions=Alternate}
%    1/2 \quad 1/4 \quad 5/6 \quad 13579/24680 \\
% \end{Xexample}
%
%
% \subsection{Stylistic Set variations}
%
% This feature selects a `Stylistic Set' variation,
% which usually corresponds to an alternate glyph style for a range of
% characters (usually an alphabet or subset thereof).
% This feature is specified numerically. These correspond to OpenType
% features |ss01|, |ss02|, etc.
%
% Two demonstrations from the Junicode
% font\footnote{\url{http://junicode.sf.net}}
% are shown in \exref{ss} and \exref{ss2}; thanks to Adam
% Buchbinder for the suggestion.
%
% \begin{Lexample}{ss}{Insular letterforms, as used in medieval Northern Europe, for the Junicode font accessed with the \feat{StylisticSet} feature.}
%   \fontspec{Junicode}
%    Insular forms. \\
%   \addfontfeature{StylisticSet=2}
%    Insular forms. \\
% \end{Lexample}
%
% \begin{Lexample}{ss2}{Enlarged minuscules (capital letters remain unchanged) for the Junicode font, accessed with the \feat{StylisticSet} feature.}
%   \fontspec{Junicode}
%    ENLARGED Minuscules. \\
%   \addfontfeature{StylisticSet=6}
%    ENLARGED Minuscules. \\
% \end{Lexample}
%
% (This is a synonym of the \feat{Variant} feature for \AAT\ fonts.)
% See \vref{sec:newfeatures} for a way to assign names to stylistic sets,
% which should be done on a per-font basis.
%
% \subsection{Character Variants}
%
% Similar to the `Stylistic Sets' above, `Character Variations' are selected
% numerically to adjust the output of (usually) a single character for the
% particular font. These correspond to the OpenType features |cv01| to |cv99|.
%
% I don't have a font to demonstrate this with (please suggest one if you
% know of a free font with this feature!), but the syntax is similar to that
% above:
% \begin{verbatim}
%   \fontspec[CharacterVariant={1,3,5}]{...}
% \end{verbatim}
%
% \subsection{Alternates}
%
% The \feat{Alternate} feature (for the raw OpenType feature |salt|) is used to access alternate font glyphs when variations exist in the font, such as in \exref{salt}.
% It uses a numerical selection, starting from zero, that will be different for each font.
% Note that the \texttt{Style=Alternate} option is equivalent
% to \texttt{Alternate=0} to access the default case.
%
% \begin{Xexample}[firstline=2]{salt}{The \feat{Alternate} feature.}
%   \huge
%   \fontspec{Linux Libertine}
%   \textsc{a} \& h \\
%   \addfontfeature{Alternate=0}
%   \textsc{a} \& h
% \end{Xexample}
%
% See \vref{sec:newfeatures} for a way to assign names to alternates,
% which must be done on a per-font basis.
%
% \subsection{Style}
% \label{sec:ot-feat-style}
%
% \begin{features}{Style}
% \otf{Alternate}{salt}
% \otf{Italic}{ital}
% \otf{Ruby}{ruby}
% \otf{Swash}{swsh}
% \otf{Historic}{hist}
% \otf{TitlingCaps}{titl}
% \otf{HorizontalKana}{hkna}
% \otf{VerticalKana}{vkna}
% \end{features}
%
% `Ruby' refers to a small optical size, used in
% Japanese typography for annotations.
% For fonts with multiple |salt| OpenType features,
% use the fontspec \feat{Alternate} feature instead.
%
% \Exref{style-alt} and \exref{style-hist} both contain glyph
% substitutions with similar characteristics.
% Note the occasional inconsistency with which font features are labelled; a long-tailed `Q' could turn up anywhere!
%
%  \begin{Xexample}[firstline=2]{style-alt}{Example of the \opt{Alternate} option of the \feat{Style} feature.}
%   \Large
%   \fontspec{Warnock Pro}
%    K Q R k v w y                      \\
%   \addfontfeature{Style=Alternate}
%    K Q R k v w y
% \end{Xexample}
%
% \begin{Xexample}[firstline=2]{style-hist}{Example of the \opt{Historic} option of the \feat{Style} feature.}
%   \Large
%   \fontspec{Adobe Jenson Pro}
%    M Q Z                      \\
%   \addfontfeature{Style=Historic}
%    M Q Z
% \end{Xexample}
%
% In other features, larger breadths of changes can be seen, covering
% the style of an entire alphabet. See \exref{style-titl} and \exref{style-itrub}; in the latter, the \opt{Italic} option affects the Latin text and the \opt{Ruby} option the Japanese.
%
% \begin{Xexample}[firstline=2]{style-titl}{Example of the \opt{TitlingCaps} option of the \feat{Style} feature.}
%   \Large
%   \fontspec{Adobe Garamond Pro}
%    TITLING CAPS                       \\
%   \addfontfeature{Style=TitlingCaps}
%    TITLING CAPS
% \end{Xexample}
%
% \begin{Xexample}[firstline=2]{style-itrub}{Example of the \opt{Italic} and \opt{Ruby} options of the \feat{Style} feature.}
%   \Large \def\kana{ようこそ ワカヨタレソ}
%   \fontspec{Hiragino Mincho Pro}
%    Latin \kana        \\
%   \addfontfeature{Style={Italic, Ruby}}
%    Latin \kana
% \end{Xexample}
%
% Note the difference here between the default and the horizontal style kana
% in \exref{style-hvkana}: the horizontal style is slightly wider.
%
% \begin{Xexample}[firstline=2]{style-hvkana}{Example of the \opt{HorizontalKana} and \opt{VerticalKana} options of the \feat{Style} feature.}
%   \Large \def\kana{ようこそ ワカヨタレソ}
%    \fontspec{Hiragino Mincho Pro}
%     \kana   \\
%   {\addfontfeature{Style=HorizontalKana}
%     \kana } \\
%   {\addfontfeature{Style=VerticalKana}
%     \kana }
% \end{Xexample}
%
% \subsection{Diacritics}
% Specifies how combining diacritics should be placed.
% These will usually be controlled automatically
% according to the Script setting.
%
% \begin{features}{Diacritics}
% \otf*{MarkToBase}{mark}
% \otf*{MarkToMark}{mkmk}
% \otf*{AboveBase}{abvm}
% \otf*{BelowBase}{blwm}
% \end{features}
%
% \subsection{Kerning}\label{sec:kerning}
% Specifies how inter-glyph spacing should behave.
%
% \begin{features}{Kerning}
% \otf{Uppercase}{cpsp}
% \otf*[Off]{On}{kern}
% \end{features}
%
% As briefly mentioned previously at the end of \vref{sec:letters},
% the \opt{Uppercase} option will add a small amount of tracking between uppercase letters, seen in \exref{kernup}, which uses the Romande fonts\footnote{\url{http://arkandis.tuxfamily.org/adffonts.html}} (thanks to Clea F. Rees for the suggestion).
%
% \begin{Xexample}[firstline=2]{kernup}{Adding extra kerning for uppercase letters. (The difference is usually very small.)}
%   \large
%   \fontspec{Romande ADF Std Bold}
%    UPPERCASE EXAMPLE \\
%   \addfontfeature{Kerning=Uppercase}
%    UPPERCASE EXAMPLE
% \end{Xexample}
%
%
% \subsection{Font transformations}
%
% In rare situations users may want to mechanically distort the shapes of the glyphs in the current font such as shown in \exref{fake}. Please don't overuse these features; they are \emph{not} a good alternative to having the real shapes.
%
% \begin{Xexample}{fake}{Articifial font transformations.}
%   \fontspec{Charis SIL} \emph{ABCxyz} \quad
%   \fontspec[FakeSlant=0.2]{Charis SIL} ABCxyz
%
%   \fontspec{Charis SIL}  ABCxyz \quad
%   \fontspec[FakeStretch=1.2]{Charis SIL} ABCxyz
%
%   \fontspec{Charis SIL} \textbf{ABCxyz} \quad
%   \fontspec[FakeBold=1.5]{Charis SIL} ABCxyz
% \end{Xexample}
%
% If values are omitted, their defaults are as shown above.
%
% If you want the bold shape to be faked automatically, or the italic shape
% to be slanted automatically, use the \feat{AutoFakeBold} and
% \feat{AutoFakeSlant} features. For example, the following two invocations
% are equivalent:
% \begin{verbatim}
%   \fontspec[AutoFakeBold=1.5]{Charis SIL}
%   \fontspec[BoldFeatures={FakeBold=1.5}]{Charis SIL}
% \end{verbatim}
%
% If both of the \feat{AutoFake...} features are used, then the bold italic
% font will also be faked.
%
% Currently, \feat{FakeStretch} doesn't work in \LuaTeX\ and will be ignored
% silently.
%
% \subsection{Annotation}
% Some fonts are equipped with an extensive range of
% numbers and numerals in different forms. These are accessed with the
% \feat{Annotation} feature (OpenType feature |nalt|), selected numerically as shown in
% \exref{ot-annot}.
%
% \begin{Xexample}{ot-annot}{Annotation forms for OpenType fonts.}
%   \fontspec{Hiragino Maru Gothic Pro}
%    1 2 3 4 5 6 7 8 9
%   \def\x#1{\\{\addfontfeature{Annotation=#1}
%             1 2 3 4 5 6 7 8 9 }}
%   \x0\x1\x2\x3\x4\x5\x6\x7\x7\x8\x9
% \end{Xexample}
%
% \subsection{CJK shape}
%
% \begin{features}{CJKShape}
% \otf{Traditional}{trad}
% \otf{Simplified} {smpl}
% \otf{JIS1978}    {jp78}
% \otf{JIS1983}    {jp83}
% \otf{JIS1990}    {jp90}
% \otf{Expert}     {expt}
% \otf{NLC}        {nlck}
% \end{features}
%
% There have been many standards for how CJK ideographic
% glyphs are `supposed' to look. Some fonts will contain many alternate
% glyphs available in order to be able to display these gylphs
% correctly in whichever form is appropriate. Both \AAT\ and OpenType
% fonts support the following \feat{CJKShape} options:
% \opt{Traditional}, \opt{Simplified}, \opt{JIS1978}, \opt{JIS1983},
% \opt{JIS1990}, and \opt{Expert}. OpenType also supports the \opt{NLC} option.

% \begin{Xexample}[firstline=2]{ot-cjk-shape}{Different standards for CJK ideograph presentation.}
%   \LARGE\def\text{ 唖噛躯 妍并訝}
%   \fontspec{Hiragino Mincho Pro}
%   {\addfontfeature{CJKShape=Traditional}
%   \text }                          \\
%   {\addfontfeature{CJKShape=NLC}
%   \text }                          \\
%   {\addfontfeature{CJKShape=Expert}
%   \text }
% \end{Xexample}
%
% \subsection{Character width}\label{sec:CharacterWidth}
% Many Asian fonts are equipped with variously spaced characters for
% shoe-horning into their generally monospaced text.
% These are
% accessed through the \feat{CharacterWidth} feature.
%
% \begin{features}{CharacterWidth}
% \otf{Proportional}{pwid}
% \otf{Full}        {fwid}
% \otf{Half}        {hwid}
% \otf{Third}       {twid}
% \otf{Quarter}     {qwid}
% \otf{AlternateProportional}{palt}
% \otf{AlternateHalf}{halt}
% \end{features}
%
% Japanese alphabetic glyphs (in Hiragana or Katakana) may be typeset
% proportionally, to better fit horizontal measures, or monospaced, to
% fit into the rigid grid imposed by ideographic typesetting. In this
% latter case, there are also half-width forms for squeezing more kana
% glyphs (which are less complex than the kanji they are amongst) into
% a given block of space. The same features are given to roman letters
% in Japanese fonts, for typesetting foreign words in the same style
% as the surrounding text.
%
% \begin{Xexample}[firstline=2]{charwdprop}{Proportional or fixed width forms.}
%   \def\texta{ようこそ}\def\textb{ワカヨタレソ}
%   \def\test{\makebox[2cm][l]{\texta}%
%             \makebox[2.5cm][l]{\textb}%
%             \makebox[2.5cm][l]{abcdef}}
%   \fontspec{Hiragino Mincho Pro}
%   {\addfontfeature{CharacterWidth=Proportional}\test}\\
%   {\addfontfeature{CharacterWidth=Full}\test}\\
%   {\addfontfeature{CharacterWidth=Half}\test}
% \end{Xexample}
%
% The same situation occurs with numbers, which are provided in
% increasingly illegible compressed forms seen in \exref{charwd}.
%
% \begin{Xexample}[firstline=2]{charwd}{Numbers can be compressed significantly.}
%   \centering
%   \fontspec[Renderer=AAT]{Hiragino Mincho Pro}
%   {\addfontfeature{CharacterWidth=Full}
%    ---12321---}\\
%   {\addfontfeature{CharacterWidth=Half}
%    ---1234554321---}\\
%   {\addfontfeature{CharacterWidth=Third}
%    ---123456787654321---}\\
%   {\addfontfeature{CharacterWidth=Quarter}
%    ---12345678900987654321---}
% \end{Xexample}
%
% \subsection{Vertical typesetting}
%
% TODO!
%
%
% \subsection{OpenType scripts and languages}\label{sec:ot}
%
% Fonts that include glyphs for various scripts and languages may contain different font features for the different character sets and languages they support, and different font features may behave differently depending on the script or language chosen.
% When multilingual fonts are used, it is important to select which language
% they are being used for, and more importantly what script is being used.
%
% The `script' refers to the alphabet in used; for example, both English
% and French use the Latin script. Similarly, the Arabic script can be used
% to write in both the Arabic and Persian languages.
%
% The
% \feat{Script} and \feat{Language} features are used to designate this information. The possible options are
% tabulated in \vref{tab:ot-scpt} and \vref{tab:ot-lang},
% respectively. When a script or language is requested that is not
% supported by the current font, a warning is printed in the console output.
%
% Because these font features can
% change which features are able to be selected for the font, they are automatically selected
% by \pkg{fontspec} before all others and, if \XeTeX\ is being used, will
% specifically select the \opt{ICU}
% renderer for this font, as described in \vref{sec:renderer}.
%
%
% \subsubsection{\feat{Script} and \feat{Language} examples}
%
% In the following examples, the Code2000 font\footnote{\url{http://www.code2000.net/}}
% is used to typeset the input with and without the OpenType Script
% applied. The text is only rendered correctly in the second case;
% many examples of incorrect diacritic spacing as
% well as a lack of contextual ligatures and rearrangement can be
% seen. Thanks to \name{Jonathan Kew}, \name{Yves Codet} and
% \name{Gildas Hamel} for their contributions towards these examples.
%
% \begin{Xexample}[firstline=14,lastline=23]{script-lang}{An example of various Scripts and Languages.}
% \def\testfeature#1#2{%^^A
%   \fontspec{\examplefont}#2 & \fontspec[#1]{\examplefont}#2\\[1ex]}
% \def \examplefont{Code2000}
% \def \arabictext{العربي}
% \def \devanagaritext{हिन्दी}
% \def \bengalitext{লেখ}
% \def \gujaratitext{મર્યાદા-સૂચક નિવેદન}
% \def \malayalamtext{നമ്മുടെ പാരബര്യ}
% \def \gurmukhitext{ਆਦਿ ਸਚੁ ਜੁਗਾਦਿ ਸਚੁ}
% \def \tamiltext{தமிழ் தேடி}
% \def \hebrewtext{רִדְתָּֽהּ}
% \def \vietnamesetext{cấp số mỗi}
% \begin{tabular}{r@{\quad}l}
%   \testfeature{Script=Arabic}{\arabictext}
%   \testfeature{Script=Devanagari}{\devanagaritext}
%   \testfeature{Script=Bengali}{\bengalitext}
%   \testfeature{Script=Gujarati}{\gujaratitext}
%   \testfeature{Script=Malayalam}{\malayalamtext}
%   \testfeature{Script=Gurmukhi}{\gurmukhitext}
%   \testfeature{Script=Tamil}{\tamiltext}
%   \testfeature{Script=Hebrew}{\hebrewtext}
%   \def\examplefont{Doulos SIL}
%   \testfeature{Language=Vietnamese}{\vietnamesetext}
% \end{tabular}
% \end{Xexample}
%
%
%
% \subsubsection{Defining new scripts and languages}
%
% \DescribeMacro{\newfontscript}
% \DescribeMacro{\newfontlanguage}
% While the scripts and languages listed in \ref{tab:ot-scpt} and \ref{tab:ot-lang}
% are intended to be comprehensive, there may be some missing; alternatively,
% you might wish to use different names to access scripts/languages that are
% already listed.
% Adding scripts and languages can be performed with the \cmd\newfontscript\
% and \cmd\newfontlanguage\ commands. For example,
% \begin{Verbatim}
%   \newfontscript{Arabic}{arab}
%   \newfontlanguage{Zulu}{ZUL}
% \end{Verbatim}
% The first argument is the \pkg{fontspec} name, the second the OpenType
% tag. The advantage to using these commands rather than \cmd\newfontfeature\
% (see \vref{sec:newfeatures}) is the error-checking that is performed when
% the script or language is requested.
%
% \begin{table}[!hbp]
%   \caption{Defined \opt{Script}s for OpenType fonts. Aliased names are shown in adjacent positions marked with red pilcrows ({\sffamily\textcolor{red}{\P}}).}
%   \label{tab:ot-scpt}
% \def\dup{\makebox[0pt][r]{\textcolor{red}{\P}}}
% \setlength\columnseprule{0pt}
%   \hrule
%   \begin{multicols}{4}\setlength\parindent{0pt}
%     \sffamily\scriptsize
%     Arabic \par Armenian \par Balinese \par Bengali \par Bopomofo \par Braille \par Buginese \par Buhid \par Byzantine Music \par Canadian Syllabics \par Cherokee \par \dup CJK \par \dup CJK Ideographic \par Coptic \par Cypriot Syllabary \par Cyrillic \par Default \par Deseret \par Devanagari \par Ethiopic \par Georgian \par Glagolitic \par Gothic \par Greek \par Gujarati \par Gurmukhi \par Hangul Jamo \par Hangul \par Hanunoo \par Hebrew \par \dup Hiragana and Katakana \par \dup Kana \par Javanese \par Kannada \par Kharosthi \par Khmer \par Lao \par Latin \par Limbu \par Linear B \par Malayalam \par \dup Math \par \dup Maths \par Mongolian \par Musical Symbols \par Myanmar \par N'ko \par Ogham \par Old Italic \par Old Persian Cuneiform \par Oriya \par Osmanya \par Phags-pa \par Phoenician \par Runic \par Shavian \par Sinhala \par Sumero-Akkadian Cuneiform \par Syloti Nagri \par Syriac \par Tagalog \par Tagbanwa \par Tai Le \par Tai Lu \par Tamil \par Telugu \par Thaana \par Thai \par Tibetan \par Tifinagh \par Ugaritic Cuneiform \par Yi
%   \end{multicols}
%   \hrule
% \end{table}
%
% \begin{table}[p]
%   \vspace*{-3cm}
%   \hspace{-3cm}
%   \def\dup{\makebox[0pt][r]{\textcolor{red}{\P}}}
%   \begin{minipage}{\linewidth+4cm}
%   \caption{Defined \opt{Language}s for OpenType fonts. Aliased names are shown in adjacent positions marked with red pilcrows ({\sffamily\textcolor{red}{\P}}).}
%   \label{tab:ot-lang}
%   \setlength\columnseprule{0pt}
%   \hrule
%   \begin{multicols}{6}
%     \everypar{\setlength\parindent{0pt}\setlength\hangindent{2em}}
%     \sffamily\footnotesize\raggedright
%     Abaza \par Abkhazian \par Adyghe \par Afrikaans \par Afar \par Agaw \par Altai \par Amharic \par Arabic \par Aari \par Arakanese \par Assamese \par Athapaskan \par Avar \par Awadhi \par Aymara \par Azeri \par Badaga \par Baghelkhandi \par Balkar \par Baule \par Berber \par Bench \par Bible Cree \par Belarussian \par Bemba \par Bengali \par Bulgarian \par Bhili \par Bhojpuri \par Bikol \par Bilen \par Blackfoot \par Balochi \par Balante \par Balti \par Bambara \par Bamileke \par Breton \par Brahui \par Braj Bhasha \par Burmese \par Bashkir \par Beti \par Catalan \par Cebuano \par Chechen \par Chaha Gurage \par Chattisgarhi \par Chichewa \par Chukchi \par Chipewyan \par Cherokee \par Chuvash \par Comorian \par Coptic \par Cree \par Carrier \par Crimean Tatar \par Church Slavonic \par Czech \par Danish \par Dargwa \par Woods Cree \par German \par Default \par Dogri \par Divehi \par Djerma \par Dangme \par Dinka \par Dungan \par Dzongkha \par Ebira \par Eastern Cree \par Edo \par Efik \par Greek \par English \par Erzya \par Spanish \par Estonian \par Basque \par Evenki \par Even \par Ewe \par French Antillean \par \dup Farsi \par \dup Parsi \par \dup Persian \par Finnish \par Fijian \par Flemish \par Forest Nenets \par Fon \par Faroese \par French \par Frisian \par Friulian \par Futa \par Fulani \par Ga \par Gaelic \par Gagauz \par Galician \par Garshuni \par Garhwali \par Ge'ez \par Gilyak \par Gumuz \par Gondi \par Greenlandic \par Garo \par Guarani \par Gujarati \par Haitian \par Halam \par Harauti \par Hausa \par Hawaiin \par Hammer-Banna \par Hiligaynon \par Hindi \par High Mari \par Hindko \par Ho \par Harari \par Croatian \par Hungarian \par Armenian \par Igbo \par Ijo \par Ilokano \par Indonesian \par Ingush \par Inuktitut \par Irish \par Irish Traditional \par Icelandic \par Inari Sami \par Italian \par Hebrew \par Javanese \par Yiddish \par Japanese \par Judezmo \par Jula \par Kabardian \par Kachchi \par Kalenjin \par Kannada \par Karachay \par Georgian \par Kazakh \par Kebena \par Khutsuri Georgian \par Khakass \par Khanty-Kazim \par Khmer \par Khanty-Shurishkar \par Khanty-Vakhi \par Khowar \par Kikuyu \par Kirghiz \par Kisii \par Kokni \par Kalmyk \par Kamba \par Kumaoni \par Komo \par Komso \par Kanuri \par Kodagu \par Korean Old Hangul \par Konkani \par Kikongo \par Komi-Permyak \par Korean \par Komi-Zyrian \par Kpelle \par Krio \par Karakalpak \par Karelian \par Karaim \par Karen \par Koorete \par Kashmiri \par Khasi \par Kildin Sami \par Kui \par Kulvi \par Kumyk \par Kurdish \par Kurukh \par Kuy \par Koryak \par Ladin \par Lahuli \par Lak \par Lambani \par Lao \par Latin \par Laz \par L-Cree \par Ladakhi \par Lezgi \par Lingala \par Low Mari \par Limbu \par Lomwe \par Lower Sorbian \par Lule Sami \par Lithuanian \par Luba \par Luganda \par Luhya \par Luo \par Latvian \par Majang \par Makua \par Malayalam Traditional \par Mansi \par Marathi \par Marwari \par Mbundu \par Manchu \par Moose Cree \par Mende \par Me'en \par Mizo \par Macedonian \par Male \par Malagasy \par Malinke \par Malayalam Reformed \par Malay \par Mandinka \par Mongolian \par Manipuri \par Maninka \par Manx Gaelic \par Moksha \par Moldavian \par Mon \par Moroccan \par Maori \par Maithili \par Maltese \par Mundari \par Naga-Assamese \par Nanai \par Naskapi \par N-Cree \par Ndebele \par Ndonga \par Nepali \par Newari \par Nagari \par Norway House Cree \par Nisi \par Niuean \par Nkole \par N'ko \par Dutch \par Nogai \par Norwegian \par Northern Sami \par Northern Tai \par Esperanto \par Nynorsk \par Oji-Cree \par Ojibway \par Oriya \par Oromo \par Ossetian \par Palestinian Aramaic \par Pali \par Punjabi \par Palpa \par Pashto \par Polytonic Greek \par Pilipino \par Palaung \par Polish \par Provencal \par Portuguese \par Chin \par Rajasthani \par R-Cree \par Russian Buriat \par Riang \par Rhaeto-Romanic \par Romanian \par Romany \par Rusyn \par Ruanda \par Russian \par Sadri \par Sanskrit \par Santali \par Sayisi \par Sekota \par Selkup \par Sango \par Shan \par Sibe \par Sidamo \par Silte Gurage \par Skolt Sami \par Slovak \par Slavey \par Slovenian \par Somali \par Samoan \par Sena \par Sindhi \par Sinhalese \par Soninke \par Sodo Gurage \par Sotho \par Albanian \par Serbian \par Saraiki \par Serer \par South Slavey \par Southern Sami \par Suri \par Svan \par Swedish \par Swadaya Aramaic \par Swahili \par Swazi \par Sutu \par Syriac \par Tabasaran \par Tajiki \par Tamil \par Tatar \par TH-Cree \par Telugu \par Tongan \par Tigre \par Tigrinya \par Thai \par Tahitian \par Tibetan \par Turkmen \par Temne \par Tswana \par Tundra Nenets \par Tonga \par Todo \par Turkish \par Tsonga \par Turoyo Aramaic \par Tulu \par Tuvin \par Twi \par Udmurt \par Ukrainian \par Urdu \par Upper Sorbian \par Uyghur \par Uzbek \par Venda \par Vietnamese \par Wa \par Wagdi \par West-Cree \par Welsh \par Wolof \par Tai Lue \par Xhosa \par Yakut \par Yoruba \par Y-Cree \par Yi Classic \par Yi Modern \par Chinese Hong Kong \par Chinese Phonetic \par Chinese Simplified \par Chinese Traditional \par Zande \par Zulu
%   \end{multicols}
%   \hspace{4pt}
%   \hrule
%  \end{minipage}
% \end{table}
%
%
%
% \part{\LuaTeX-only font features}
% \label{sec:luatex-features}
%
% \section{OpenType font feature files}
%
% An OpenType font feature file is a plain text file describing OpenType layout
% feature of a font in a human-readable format. The syntax of OpenType feature
% files is defined by Adobe\footnote{\url{http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html}}.
%
% Feature files can be used to add or customise OpenType features of a font on
% the fly without editing the font file itself.
%
% A feature file is loaded by passing its name or path to \feat{FeatureFile};
% OpenType features defined in the file can be then be applied as usual to the font.
%
% For example, to add OpenType mapping of f-ligatures in the Times New Roman
% font, one can define a \texttt{times-nr.fea} file with content shown in
% Figure~\ref{fig:featurefile}.
% Then the font with the new ligatures can be loaded with:
% \begin{Verbatim}
%   \setmainfont[FeatureFile=times-nr.fea]{Times New Roman}
% \end{Verbatim}
%
% \begin{figure}
% \caption{Addition of ligatures to a font via the \feat{FeatureFile} font feature.}
% \label{fig:featurefile}
% \hrule
% \begin{Verbatim}
% lookup fligatures {
%   lookupflag 0;
%     sub \f \i  by \fi;
%     sub \f \l  by \fl;
% } fligatures;
%
% feature liga {
%   script DFLT;
%      language dflt ;
%       lookup fligatures;
%
%   script latn;
%      language dflt ;
%       lookup fligatures;
% } liga;
% \end{Verbatim}
% \hrule
% \end{figure}
%
% \part{Fonts and features with \XeTeX}
% \label{sec:xetex-features}
%
%
%
%
% \section{\XeTeX-only font features}
%
% The features described here are available for any font
% selected by \pkg{fontspec}.
%
% \subsection{Mapping}
% \label{sec:mapping}
%
% \feat{Mapping} enables a \XeTeX\ text-mapping scheme, shown in \exref{mapping}.
%
% \begin{Xexample}{mapping}{\XeTeX's \feat{Mapping} feature.}
%   \fontspec[Mapping=tex-text]{Cochin}
%   ``!`A small amount of---text!''
% \end{Xexample}
%
% Using the |tex-text| mapping is also equivalent to writing |Ligatures=TeX|.
% The use of the latter syntax is recommended for better compatibility with
% \LuaTeX\ documents.
%
%
% \subsection{Letter spacing}
% Letter spacing, or tracking, is the term given to adding (or subtracting) a small amount of horizontal space in between adjacent characters. It is specified with the \feat{LetterSpace}, which takes a numeric argument,
% shown in \exref{tracking}.
%
% The letter spacing parameter is a normalised additive factor (not a scaling factor); it is defined as a percentage of the font size. That is, for a 10\,pt font, a letter spacing parameter of `|1.0|' will add 0.1\,pt between each letter.
%
% \begin{Xexample}{tracking}{The \feat{LetterSpace} feature.}
%   \fontspec{Didot}
%   \addfontfeature{LetterSpace=0.0}
%   USE TRACKING FOR DISPLAY CAPS TEXT \\
%   \addfontfeature{LetterSpace=2.0}
%   USE TRACKING FOR DISPLAY CAPS TEXT
% \end{Xexample}
%
% This functionality \emph{should not be used for lowercase text}, which is spacing correctly to begin with, but it can be very useful, in small amounts, when setting small caps or all caps titles.
% Also see the OpenType \opt{Uppercase}
% option of the \feat{Letters} feature (\vref*{sec:letters}).
%
% \subsection{Different font technologies: \AAT\ and \ICU}\label{sec:renderer}
%
% \XeTeX\ supports two rendering technologies for typesetting, selected with
% the \feat{Renderer} font feature. The first, \opt{AAT}, is
% that provided (only) by \MacOSX\ itself. The second, \opt{ICU},
% is an open source OpenType interpreter. It provides much greater support for
% OpenType features, notably contextual arrangement, over \opt{AAT}.
%
% In general, this feature will not need to be explicitly called: for OpenType
% fonts, the \opt{ICU} renderer is used automatically, and for \AAT\ fonts,
% \opt{AAT} is chosen by default. Some fonts, however, will contain font tables
% for \emph{both} rendering technologies, such as the Hiragino Japanese fonts
% distributed with \MacOSX, and in these cases the choice may be required.
%
% Among some other font features only available through a specific renderer,
% \opt{ICU} provides for the \feat{Script} and \feat{Language} features, which allow
% different font behaviour for different alphabets and languages; see \vref{sec:ot}
% for the description of these features. {\em Because these font features can
% change which features are able to be selected for the font instance, they are selected
% by \pkg{fontspec} before all others and will automatically and without warning
% select the \opt{ICU} renderer.}
%
%
% \subsection{Optical font sizes} \label{sec:aat-opticalsize}
%
% Multiple Master fonts are parameterised over
% orthogonal font axes, allowing continuous selection along such
% features as weight, width, and optical size~(see \vref{sec:mm} for
% further details). Whereas an OpenType font will have only a few separate
% optical sizes, a Multiple Master font's optical size can be
% specified over a continuous range. Unfortunately, this flexibility makes
% it harder to create an automatic interface through \LaTeX, and the
% optical size for a Multiple Master font must always be specified
% explicitly.
% \begin{Verbatim}
%   \fontspec[OpticalSize=11]{Minion MM Roman}
%    MM optical size test                    \\
%   \fontspec[OpticalSize=47]{Minion MM Roman}
%    MM optical size test                    \\
%   \fontspec[OpticalSize=71]{Minion MM Roman}
%    MM optical size test                    \\
% \end{Verbatim}
%
%
%
%
% \section{\MacOSX's \AAT\ fonts}
% \label{sec:aat-features}
%
% \MacOSX's font technology began life before the ubiquitous-OpenType era
% and revolved around the Apple-invented `\AAT' font format. This format
% had some advantages (and other disadvantages) but it never became widely
% popular in the font world.
%
% Nonetheless, this is the font format that was first supported by \XeTeX\
% (due to its pedigree on \MacOSX\ in the first place) and was the first
% font format supported by \pkg{fontspec}. A number of fonts distributed with
% \MacOSX\ are still in the \AAT\ format, such as `Skia'. Documents
% that use these fonts should be compiled with \XeLaTeX\ using the
% \texttt{xdv2pdf} driver, as opposed to the default \texttt{xdvipdfmx}. E.g.,
% \begin{verbatim}
%   xelatex -output-driver="xdv2pdf" filename.tex
% \end{verbatim}
%
% \MacOSX\ also supports Multiple Master fonts, which are discussed
% in \ref{sec:mm}.
%
% \subsection{Ligatures}
%
% \feat{Ligatures} refer to the replacement of two separate characters
% with a specially drawn glyph for functional or \ae sthetic reasons.
% For \AAT\ fonts, you may choose from any combination of \opt{Required},
% \opt{Common}, \opt{Rare} (or \opt{Discretionary}), \opt{Logos}, \opt{Rebus},
% \opt{Diphthong}, \opt{Squared}, \opt{AbbrevSquared}, and \opt{Icelandic}.
%
% Some other Apple \AAT\ fonts have those `Rare' ligatures contained in
% the \opt{Icelandic} feature. Notice also that the old \TeX\ trick of
% splitting up a ligature with an empty brace pair does not work in
% \XeTeX; you must use a 0\,pt kern or \cs{hbox} (\eg, \cs{null}) to
% split the characters up if you do not want a ligature to be performed (the usual examples for when this might be desired are words like `shelf\null full').
%
% \subsection{Letters} \label{sec:aat-letters}
% The \opt{Letters} feature specifies how the letters in the current font
% will look. For \AAT\ fonts, you may choose from \opt{Normal},
% \opt{Uppercase}, \opt{Lowercase}, \opt{SmallCaps}, and
% \opt{InitialCaps}.
%
%
% \subsection{Numbers}
% The \feat{Numbers} feature defines how numbers will look in the
% selected font. For \AAT\ fonts, they may be a
% combination of \opt{Lining} or \opt{OldStyle} and \opt{Proportional} or
% \opt{Monospaced} (the latter is good for tabular material). The synonyms
% \opt{Uppercase} and \opt{Lowercase} are equivalent to \opt{Lining} and
% \opt{OldStyle}, respectively. The differences have been shown previously
% in \vref{sec:addfontfeatures}.
%
% \subsection{Contextuals} \label{sec:contextuals}
% This feature refers to glyph substitution that vary by their position;
% things like contextual swashes are implemented here
% The options for \AAT\ fonts are
% \opt{WordInitial}, \opt{WordFinal} (\exref{wordcx}), \opt{LineInitial},
% \opt{LineFinal}, and \opt{Inner} (\exref{longsaat}, also called `non-final' sometimes). As
% non-exclusive selectors, like the ligatures, you can turn them off
% by prefixing their name with \opt{No}.
%
% \begin{Xexample}{wordcx}{Contextual glyph for the beginnings and ends of words.}
%   \newfontface\fancy
%       [Contextuals={WordInitial,WordFinal}]
%                        {Hoefler Text Italic}
%   \fancy where is all the vegemite
% \end{Xexample}
%
% \begin{Xexample}{longsaat}{A contextual feature for the `long s' can be convenient as the character does not need to be marked up explicitly.}
%   \fontspec[Contextuals=Inner]{Hoefler Text}
%   `Inner' swashes can \emph{sometimes}    \\
%    contain the archaic long~s.
% \end{Xexample}
%
%
%
% \subsection{Vertical position}
% The \feat{VerticalPosition} feature is used to access things like
% subscript (\opt{Inferior}) and superscript (\opt{Superior}) numbers and
% letters (and a small amount of punctuation, sometimes).
% The \opt{Ordinal} option is (supposed to be)
% contextually sensitive to only raise characters that appear directly
% after a number.
% These are shown in \exref{aat-supp}.
%
% \begin{Xexample}{aat-supp}{Vertical position for AAT fonts.}
%   \fontspec{Skia}
%    Normal
%   \fontspec[VerticalPosition=Superior]{Skia}
%    Superior
%   \fontspec[VerticalPosition=Inferior]{Skia}
%    Inferior                \\
%   \fontspec[VerticalPosition=Ordinal]{Skia}
%    1st 2nd 3rd 4th 0th 8abcde
% \end{Xexample}
%
% The \pkg{xltxtra} package redefines the \cmd\textsubscript\ and
% \cmd\textsuperscript\ commands to use the above font features.
%
% \subsection{Fractions}
% Many fonts come with the capability to typeset various forms of
% fractional material. This is accessed in \pkg{fontspec} with the
% \feat{Fractions} feature, which may be turned \opt{On} or \opt{Off}
% in both \AAT\ and OpenType fonts.
%
% In \AAT\ fonts, the `fraction slash' or solidus character, is
% to be used to create fractions. When \feat{Fractions} are turned
% \opt{On}, then only pre-drawn fractions will be used.
% See \exref{aat-frac}.
%
% Using the \opt{Diagonal} option (\AAT\ only), the font will attempt
% to create the fraction from superscript and subscript
% characters.
%
% \edef\caretcc{\the\catcode`\^}
% \catcode`\^=12\relax
% \begin{Xexample}{aat-frac}{Fractions in AAT fonts. The \texttt{\relax^^^^2044} glyph is the `fraction slash' that may be typed in \MacOSX\ with \textsc{opt+shift+1}; not shown literally here due to font contraints.}
%   \fontspec[Fractions=On]{Skia}
%    1{^^^^2044}2 \quad 5{^^^^2044}6 \\ % fraction slash
%    1/2 \quad 5/6    % regular  slash
%
%   \fontspec[Fractions=Diagonal]{Skia}
%          13579{^^^^2044}24680 \\ % fraction slash
%    \quad 13579/24680    % regular  slash
% \end{Xexample}
% \catcode`\^=\caretcc\relax
%
% Some (Asian fonts predominantly) also provide for the
% \opt{Alternate} feature shown in \exref{frac-alt}.
%
% \begin{Xexample}{frac-alt}{Alternate design of pre-composed fractions.}
%   \fontspec{Hiragino Maru Gothic Pro}
%    1/2 \quad 1/4 \quad 5/6 \quad 13579/24680 \\
%   \addfontfeature{Fractions=Alternate}
%    1/2 \quad 1/4 \quad 5/6 \quad 13579/24680
% \end{Xexample}
%
%
% \subsection{Variants}
% The \feat{Variant} feature takes a single numerical input for
% choosing different alphabetic shapes. Don't mind my fancy \exref{aat-var}
% \texttt{:)} I'm just looping through the nine~(\,!\,) variants of
% Zapfino.
%
% \begin{Xexample}[firstline=2,lastline=9]{aat-var}{Nine variants of Zapfino.}
%   \Huge \rule{0pt}{2cm}
%   \newcounter{var}\newcounter{trans}
%   \whiledo{\value{var}<9}{%
%     \stepcounter{trans}%
%     \edef\1{%
%     \noexpand\fontspec[Variant=\thevar,
%       Color=005599\thetrans\thetrans]{Zapfino}}\1%
%     \makebox[0.75\width]{d}%
%     \stepcounter{var}}
%   \hspace*{2cm}
% \end{Xexample}
%
% See \vref{sec:newfeatures} for a way to assign names to variants,
% which should be done on a per-font basis.
%
% \subsection{Alternates}
%
% Selection of \feat{Alternate}s \emph{again}
% must be done numerically; see \exref{aat-alt}.
% See \vref{sec:newfeatures} for a way to assign names to alternates,
% which should be done on a per-font basis.
%
% \begin{Xexample}{aat-alt}{Alternate shape selection must be numerical.}
%   \fontspec[Alternate=0]{Hoefler Text Italic}
%    Sphinx Of Black Quartz, {\scshape Judge My Vow} \\
%   \fontspec[Alternate=1]{Hoefler Text Italic}
%    Sphinx Of Black Quartz, {\scshape Judge My Vow}
% \end{Xexample}
%
%
% \subsection{Style}
%
% The options of the \feat{Style} feature
% are defined in \AAT\ as one of the following: \opt{Display},
% \opt{Engraved}, \opt{IlluminatedCaps}, \opt{Italic},
% \opt{Ruby},\footnotemark\ \opt{TallCaps}, or \opt{TitlingCaps}.
% \footnotetext{`Ruby' refers to a small optical size, used in
% Japanese typography for annotations.}
%
% Typical examples for these features are shown in \ref{sec:ot-feat-style}.
%
%
%
%
%
%
% \subsection{CJK shape}
% There have been many standards for how CJK ideographic
% glyphs are `supposed' to look. Some fonts will contain many alternate
% glyphs in order to be able to display these gylphs
% correctly in whichever form is appropriate. Both \AAT\ and OpenType
% fonts support the following \feat{CJKShape} options:
% \opt{Traditional}, \opt{Simplified}, \opt{JIS1978}, \opt{JIS1983},
% \opt{JIS1990}, and \opt{Expert}. OpenType also supports the \opt{NLC} option.
%
% \subsection{Character width}
% See \vref{sec:CharacterWidth} for relevant examples; the features are
% the same between OpenType and \AAT\ fonts.
% \AAT\ also allows \feat{CharacterWidth}|=|\opt{Default} to return to
% the original font settings.
%
%


%
%
%
% \subsection{Vertical typesetting}
%
% TODO: improve!
%
% \XeTeX\ provides for vertical typesetting simply with the ability to rotate
% the individual glyphs as a font is used for typesetting, as shown in
% \exref{vert}.
%
% \begin{Xexample}[firstline=2]{vert}{Vertical typesetting.}
%   \def\verttext{共産主義者は}
%   \fontspec{Hiragino Mincho Pro}
%   \verttext
%
%   \fontspec[Renderer=AAT,Vertical=RotatedGlyphs]{Hiragino Mincho Pro}
%   \rotatebox{-90}{\verttext}% requires the graphicx package
% \end{Xexample}
%
% No actual provision is made for typesetting top-to-bottom
% languages; for an example of how to do this, see the vertical Chinese
% example provided in the \XeTeX\ documentation.
%
%
%
%
% \subsection{Diacritics}
% Diacritics are marks, such as the acute accent or the tilde, applied to letters; they usually indicate a change in pronunciation.
% In Arabic scripts, diacritics are used to indicate vowels.
% You may either choose
% to \opt{Show}, \opt{Hide} or \opt{Decompose} them in \AAT\ fonts.
% The \opt{Hide} option is for scripts such as Arabic which may be
% displayed either with or without vowel markings. E.g.,
% \verb|\fontspec[Diacritics=Hide]{...}|
%
% Some older fonts distributed with \MacOSX\ included `|O/|' \etc\ as shorthand for writing `\O' under the label of the \feat{Diacritics} feature. If you come across such fonts, you'll
% want to turn this feature off (imagine typing |hello/goodbye| and
% getting `hell\o goodbye' instead!) by decomposing the two characters
% in the diacritic into the ones you actually
% want. I recommend using
% the proper \LaTeX\ input conventions for obtaining such characters
% instead.
%
%
%
% \subsection{Annotation}
% Various Asian fonts are equipped with a more extensive range of
% numbers and numerals in different forms. These are accessed through
% the \feat{Annotation} feature (see \exref{aat-annot}) with the following
% options: \opt{Off},
% \opt{Box}, \opt{RoundedBox}, \opt{Circle}, \opt{BlackCircle},
% \opt{Parenthesis}, \opt{Period}, \opt{RomanNumerals}, \opt{Diamond},
% \opt{BlackSquare}, \opt{BlackRoundSquare}, and \opt{DoubleCircle}.
%
% \begin{Xexample}{aat-annot}{Various annotation forms.}
%   \fontspec{Hei Regular}
%    1 2 3 4 5 6 7 8 9                         \\
%   \fontspec[Annotation=Circle]{Hei Regular}
%    1 2 3 4 5 6 7 8 9                         \\
%   \fontspec[Annotation=Parenthesis]{Hei Regular}
%    1 2 3 4 5 6 7 8 9                         \\
%   \fontspec[Annotation=Period]{Hei Regular}
%    1 2 3 4 5 6 7 8 9
% \end{Xexample}
%
% \section{\AAT\ \& Multiple Master font axes} \label{sec:mm}
%
% Multiple Master and \AAT\ font specifications both provide continuous
% variation along font parameters. For example, they don't have just
% regular and bold weights, they can have any bold weight you like between
% the two extremes.
%
% \opt{Weight}, \opt{Width}, and \opt{OpticalSize} are supported by this
% package. Skia, which is distributed with
% Mac~OS~X, has two of these variable parameters, allowing for the
% demonstration in \exref{aatmm}.
% Variations along a multiple master font's optical size axis has been
% shown previously in \vref{sec:opticalsize}.
%
% \begin{Xexample}{aatmm}{Continuously variable font parameters. These fonts
%  are unfortunately quite rare.}
%   \fontspec[Weight=0.5,Width=3]{Skia}
%    Really light and extended Skia         \\
%   \fontspec[Weight=2,Width=0.5]{Skia}
%    Really fat and condensed Skia
% \end{Xexample}
%
%
% \part{Programming interface}
%
% This is the beginning of some work to provide some hooks that use
% \pkg{fontspec} for various macro programming purposes.
%
%
% \section{Defining new features} \label{sec:newfeatures}
% This package cannot hope to contain every possible font
% feature. Three commands are provided for selecting font features
% that are not provided for out of the box. If you are using
% them a lot, chances are I've left something out, so please let me
% know.
%
% \DescribeMacro{\newAATfeature}
% New \AAT\ features may be created with this command:\par
% {\centering\cmd\newAATfeature\marg{feature}\marg{option}\marg{feature code}\marg{selector code}\par}\noindent
% Use the \XeTeX\ file \path{AAT-info.tex} to obtain the code numbers.
% See \exref{newAATfeat}.
%
% \begin{Xexample}{newAATfeat}{Assigning new \AAT\ features.}
%   \newAATfeature{Alternate}{HoeflerSwash}{17}{1}
%   \fontspec[Alternate=HoeflerSwash]{Hoefler Text Italic}
%    This is XeTeX by Jonathan Kew.
% \end{Xexample}
%
%
% \DescribeMacro{\newICUfeature}
% \DescribeMacro{\newopentypefeature}
% New OpenType features may be created with this command:\par
% {\centering\cmd\newICUfeature\marg{feature}\marg{option}\marg{feature tag}\par}
% The synonym \cs{newopentypefeature} is provided for \LuaLaTeX\ users.
%
% Here's what it would look like in practise:
% \begin{Verbatim}
% \newopentypefeature{Style}{NoLocalForms}{-locl}
% \end{Verbatim}
%
% \DescribeMacro{\newfontfeature}
% In case the above commands do not accommodate the desired font feature
% (perhaps a new \XeTeX\ feature that \pkg{fontspec} hasn't been updated
% to support), a command is provided to pass arbitrary input into the
% font selection string:\par
% {\centering\cmd{\newfontfeature}\marg{name}\marg{input string}\par}
%
% For example, Zapfino
% contains the feature `Avoid d-collisions'. To access it
% with this package, you could do some like that shown in \exref{avoidd}
%
% \begin{Xexample}{avoidd}{Assigning new arbitary features.}
%   \newfontfeature{AvoidD}{Special=Avoid d-collisions}
%   \newfontfeature{NoAvoidD}{Special=!Avoid d-collisions}
%   \fontspec[AvoidD,Variant=1]{Zapfino}
%    sockdolager rubdown               \\
%   \fontspec[NoAvoidD,Variant=1]{Zapfino}
%    sockdolager rubdown
% \end{Xexample}
%
% The advantage to using the \cmd\newAATfeature\ and \cmd\newICUfeature\
% commands instead of \cs{newfontfeature} is that they check if the selected font actually contains the desired font
% feature at load time. By contrast, \cmd\newfontfeature\ will not give a warning
% for improper input.
%
% \section{Going behind \pkg{fontspec}'s back}
% Expert users may wish not to use \pkg{fontspec}'s feature handling at all,
% while still taking advantage of its \LaTeX\ font selection conveniences. The
% \feat{RawFeature} font feature allows literal \XeTeX\ font feature selection
% when you happen to have the OpenType feature tag memorised.
%
% \begin{Xexample}{raw}{Using raw font features directly.}
%   \fontspec[RawFeature=+smcp]{TeX Gyre Pagella}
%   Pagella small caps
% \end{Xexample}
%
% Multiple features can either be included in a single declaration:\par
% {\centering|[RawFeature=+smcp;+onum]|\par}
% \noindent or with multiple declarations:\par
% {\centering|[RawFeature=+smcp, RawFeature=+onum]|\par}
%
% \section{Renaming existing features \& options}
% \label{sec:aliasfontfeature}
%
% \DescribeMacro{\aliasfontfeature}
% If you don't like the name of a particular font feature,
% it may be aliased to another with the
% \cs{aliasfontfeature}\marg{existing name}\marg{new name} command,
% such as shown in \exref{alias}.
%
% \begin{Xexample}{alias}{Renaming font features.}
%   \aliasfontfeature{ItalicFeatures}{IF}
%   \fontspec[IF = {Alternate=1}]{Hoefler Text}
%   Roman Letters \itshape And Swash
% \end{Xexample}
%
% Spaces in feature (and option names, see below) \emph{are} allowed. (You may have
% noticed this already in the lists of OpenType scripts and languages).
%
% \DescribeMacro{\aliasfontfeatureoption}
% If you wish to change the name of a font feature option,
% it can be aliased to another with the command
% \cs{aliasfontfeatureoption}\marg{font feature}\marg{existing name}\marg{new name}, such as shown in \exref{aliasopt}.
%
% \begin{Lexample}{aliasopt}{Renaming font feature options.}
%   \aliasfontfeature{VerticalPosition}{Vert Pos}
%   \aliasfontfeatureoption{VerticalPosition}{ScientificInferior}{Sci Inf}
%   \fontspec[Vert Pos=Sci Inf]{Linux Libertine}
%    Scientific Inferior: 12345
% \end{Lexample}
%
% This example demonstrates an important point: when aliasing the feature
% options, the \emph{original} feature name must be used when declaring
% to which feature the option belongs.
%
% Only feature options that exist as sets of fixed strings may be altered in
% this way. That is, \opt{Proportional} can be aliased to \opt{Prop} in the
% \feat{Letters} feature, but \opt{550099BB} cannot be substituted for \opt{Purple}
% in a \feat{Color} specification. For this type of thing, the \cmd\newfontfeature\
% command should be used to declare a new, \eg, \feat{PurpleColor} feature:
% \begin{Verbatim}
%   \newfontfeature{PurpleColor}{color=550099BB}
% \end{Verbatim}
% Except that this example was written before support for named colours was
% implemented. But you get the idea.
%
% \section{Programming details}
%
% In some cases, it is useful to know what the \LaTeX\ font family
% of a specific \pkg{fontspec} font is. After a \cmd\fontspec-like
% command, this is stored inside the \cmd\zf@family\ macro.
% Otherwise, \LaTeX's own \cmd\f@family\ macro can be useful here,
% too.
% The raw \TeX\ font that is defined is stored temporarily
% in \cmd{\zf@basefont}.
%
% The following commands in \pkg{expl3} syntax may be used
% for writing codes that interface with fontspec-loaded fonts.
% All of the following conditionals also exist with |T| and |F|
% suffices as well as |TF|.
%
% \begin{macro}{\fontspec_if_fontspec_font:TF}
% Test whether the currently selected font has been loaded by fontspec.
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_aat_feature:nnTF}
% Test whether the currently selected font contains the \AAT\
% feature (|#1|,|#2|).
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_opentype:TF}
% Test whether the currently selected font is an OpenType font.
% Always true for LuaTeX fonts.
% \end{macro}
%
% \begin{macro}{\fontspec_if_feature:nTF}
% Test whether the currently selected font contains the raw OpenType
% feature |#1|. E.g.: |\fontspec_if_feature:nTF {pnum} {True} {False}|.
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \end{macro}
%
% \begin{macro}{\fontspec_if_feature:nnnTF}
% Test whether the currently selected font with raw OpenType script tag |#1| and raw OpenType language tag |#2| contains the raw OpenType feature tag |#3|. E.g.: |\fontspec_if_feature:nTF {latn} {ROM} {pnum} {True} {False}|.
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \end{macro}
%
% \begin{macro}{\fontspec_if_script:nTF}
% Test whether the currently selected font contains the raw OpenType
% script |#1|. E.g.: |\fontspec_if_script:nTF {latn} {True} {False}|.
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \end{macro}
%
% \begin{macro}{\fontspec_if_language:nTF}
% Test whether the currently selected font contains the raw OpenType language
% tag |#1|. E.g.: |\fontspec_if_language:nTF {ROM} {True} {False}|.
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \end{macro}
%
% \begin{macro}{\fontspec_if_language:nnTF}
% Test whether the currently selected font contains the raw OpenType language
% tag |#2| in script |#1|. E.g.: |\fontspec_if_language:nnTF {cyrl} {SRB} {True} {False}|.
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_current_script:nTF}
% Test whether the currently loaded font is using the specified raw
% OpenType script tag |#1|.
% \end{macro}
%
% \begin{macro}{\fontspec_if_current_language:nTF}
% Test whether the currently loaded font is using the specified raw
% OpenType language tag |#1|.
% \end{macro}
%
% \begin{macro}{\fontspec_set_family:Nnn}
% \darg{family}
% \darg{fontspec features}
% \darg{font name}
% Defines a new font family from given \meta{features} and \meta{font},
% and stores the name in the variable \meta{family}.
% See the standard \pkg{fontspec} user commands for applications of this
% function.
% \end{macro}
%
%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \part{The patching/improvement of \LaTeXe\ and other packages}
% \label{sec:patching}
%
% Derived originally from xltxtra, this package contains patches to various
% \LaTeX\ components and third-party packages to improve the default
% behaviour.
%
% \section{Inner emphasis}
% \label{sec:emph}
%
% \pkg{fixltx2e}'s method for checking for ``inner'' emphasis is a little fragile in \XeTeX, because
% font slant information might be missing from the font. Therefore, we use \LaTeX's NFSS
% information, which is more likely to be correct.
%
% \section{Unicode footnote symbols}
% By default \LaTeX\ defines symbolic footnote characters in terms of commands
% that don't resolve well; better results can be achieved by using specific Unicode characters or proper LICRs with the \pkg{xunicode} package.
%
% This problem has been solved by loading the \pkg{fixltx2e} package.
%
% \section{Verbatim}
% \label{sec:verb}
%
% Many verbatim mechanisms assume the existence of a `visible space' character that exists in the \textsc{ascii} space slot of the typewriter font. This character is known in Unicode as \unichar{2434}{box open}, which looks like this: `\verb*| |'.
%
% When a Unicode typewriter font is used, \LaTeX\ no longer prints visible spaces for the |verbatim*| environment and |\verb*| command. This problem is fixed by using the correct Unicode glyph, and the following packages are patched to do the same:
% \pkg{listings}, \pkg{fancyvrb}, \pkg{moreverb}, and \pkg{verbatim}.
%
% In the case that the typewriter font does not contain `\verb*| |', the Latin Modern Mono font is used as a fallback.
%
% \section{Discretionary hyphenation: \cmd\-}
% \label{sec:hyphen}
%
% \LaTeX\ defines the macro \cmd\-\ to insert discretionary hyphenation points.
% However, it is hard-coded in \LaTeX\ to use the hyphen |-| character. Since \pkg{fontspec}
% makes it easy to change the hyphenation character on a per font basis, it would
% be nice if \cmd\-\ adjusted automatically --- and now it does.
%
% \StopEventually{}
%
% \clearpage
% \part{fontspec.sty}
%
% \section{Implementation}
% Herein lie the implementation details of this package. Welcome!
% It was my first.
%
% For some reason, I decided to prefix all the package internal
% command names and variables with |zf|. I don't know why I chose
% those letters, but I guess I just liked the look/feel of them
% together at the time. (Possibly inspired by Hermann \emph{Z}ap\emph{f}.)
%
% \iffalse
%<*fontspec>
% \fi
%    \begin{macrocode}
\RequirePackage{expl3,xparse}
\input binhex.tex  % before expl syntax!
\ExplSyntaxOn
%    \end{macrocode}
%
%    \begin{macrocode}
\msg_new:nnn {fontspec} {not-pdftex}
{
  Requires~ XeTeX~ or~ LuaTeX~ to~ function!
}
\xetex_if_engine:F {
  \luatex_if_engine:TF {
    \RequirePackage{luatextra}[2010/05/10]
    \luatexRequireModule{fontspec}
  }{
    \msg_error:nn {fontspec} {not-pdftex}
  }
}
%    \end{macrocode}
%
% \begin{macro}{\xetex_or_luatex:nn}
% Use |#1| if \XeTeX\ or |#2| if \LuaTeX.
%    \begin{macrocode}
\xetex_if_engine:TF
  { \cs_new_eq:NN \xetex_or_luatex:nn \use_i:nn }
  { \luatex_if_engine:T
    { \cs_new_eq:NN \xetex_or_luatex:nn \use_ii:nn }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\xetex_or_luatex:nnn}
% Use |#1| and (|{#2}| if \XeTeX) or (|{#3}| if \LuaTeX).
%    \begin{macrocode}
\xetex_if_engine:TF
  { \cs_new:Npn \xetex_or_luatex:nnn #1#2#3 {#1{#2}} }
  {
    \luatex_if_engine:T
     { \cs_new:Npn \xetex_or_luatex:nnn #1#2#3 {#1{#3}} }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Bits and pieces}
% \paragraph{Conditionals}
%    \begin{macrocode}
\newif\ifzf@firsttime
\newif\ifzf@nobf
\newif\ifzf@noit
\newif\ifzf@nosc
\newif\ifzf@tfm
\newif\ifzf@atsui
\newif\ifzf@icu
\newif\ifzf@mm
\newif\ifzf@graphite
%    \end{macrocode}
% For dealing with legacy maths
%    \begin{macrocode}
\newif\ifzf@math@euler
\newif\ifzf@math@lucida
\newif\ifzf@package@euler@loaded
%    \end{macrocode}
% For package options:
%    \begin{macrocode}
\newif\if@zf@configfile
\newif\if@zf@math
%    \end{macrocode}
% \paragraph{Counters}
%    \begin{macrocode}
\newcount\c@zf@newff
\newcount\c@zf@index
\newcount\c@zf@script
\newcount\c@zf@language
\int_new:N \l_fontspec_strnum_int
%    \end{macrocode}
% Temporary definition until expl3 has been updated to include this:
%    \begin{macrocode}
\cs_set:Npn \use:x #1 { \edef\@tempa{#1}\@tempa }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set:Npn \use_v:nnnnn #1#2#3#4#5 {#5}
\cs_set:Npn \use_iv:nnnnn #1#2#3#4#5 {#4}
%    \end{macrocode}
%
%
% \begin{macro}{\fontspec_glyph_if_exist:NnTF}
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_glyph_if_exist:Nn {p,TF,T,F} {
  \etex_iffontchar:D #1 #2 \scan_stop:
    \prg_return_true:
  \else:
    \prg_return_false:
  \fi:
}
%    \end{macrocode}
% \end{macro}
%
%
%    \begin{macrocode}
\cs_new:Npn \fontspec_setkeys:xx #1#2
 {
  \use:x { \exp_not:N \setkeys*[zf]{#1}{#2} }
 }
\cs_new:Npn \fontspec_setkeys:xxx #1#2#3
 {
  \use:x { \exp_not:N \setkeys*[zf@#1]{#2}{#3} }
 }
%    \end{macrocode}
%
% \subsection{Error/warning messages}
%
% Shorthands for messages:
%    \begin{macrocode}
\cs_new:Npn \fontspec_error:n     { \msg_error:nn     {fontspec} }
\cs_new:Npn \fontspec_error:nx    { \msg_error:nnx    {fontspec} }
\cs_new:Npn \fontspec_warning:n   { \msg_warning:nn   {fontspec} }
\cs_new:Npn \fontspec_warning:nx  { \msg_warning:nnx  {fontspec} }
\cs_new:Npn \fontspec_warning:nxx { \msg_warning:nnxx {fontspec} }
\cs_new:Npn \fontspec_info:n      { \msg_info:nn      {fontspec} }
\cs_new:Npn \fontspec_info:nx     { \msg_info:nnx     {fontspec} }
\cs_new:Npn \fontspec_info:nxx    { \msg_info:nnxx    {fontspec} }
\cs_new:Npn \fontspec_trace:n     { \msg_trace:nn     {fontspec} }
%    \end{macrocode}
%
% Errors:
%    \begin{macrocode}
\msg_new:nnn {fontspec} {no-size-info}
{
  Size~ information~ must~ be~ supplied.\\
  For~ example,~ SizeFeatures={Size={8-12},...}.
}
\msg_new:nnnn {fontspec} {rename-feature-not-exist}
{
  The~ feature~ #1~ doesn't~ appear~ to~ be~ defined.
}
{
  It~ looks~ like~ you're~ trying~ to~ rename~ a~ feature~ that~ doesn't~ exist.
}
\msg_new:nnn {fontspec} {no-glyph}
{
  '\zf@fontname'~ does~ not~ contain~ glyph~ #1.
}
\msg_new:nnnn {fontspec} {unknown-options}
{
  The~ following~ font~ options~ are~ not~ recognised:\\
  \space\space\space\space #1
}
{
  There~ is~ probably~ a~ typo~ in~ the~ font~ feature~ selection.
}
\msg_new:nnnn {fontspec} {euler-too-late}
{
  The~ euler~ package~ must~ be~ loaded~ BEFORE~ fontspec.
}
{
  fontspec~ only~ overwrites~ euler's~ attempt~ to\\
  define~ the~ maths~ text~ fonts~ if~ fontspec~ is\\
  loaded~ after~ euler.~ Type~ <return>~ to~ proceed\\
  with~ incorrect~ \string\mathit,~ \string\mathbf,~ etc.
}
\msg_new:nnnn {fontspec} {no-xcolor}
{
  Cannot~ load~ named~ colours~ without~ the~ xcolor~ package.
}
{
  Sorry,~ I~ can't~ do~ anything~ to~ help.~ Instead~ of~ loading\\
  the~ color~ package,~ use~ xcolor~ instead.~ It's~ better.
}
\msg_new:nnnn {fontspec} {unknown-color-model}
{
  Error~ loading~ colour~ `#1';~ unknown~ colour~ model.
}
{
  Sorry,~ I~ can't~ do~ anything~ to~ help.~ Please~ report~ this~ error\\
  to~ my~ developer~ with~ a~ minimal~ example~ that~ causes~ the~ problem.
}
%    \end{macrocode}
% Warnings:
%    \begin{macrocode}
\msg_new:nnn {fontspec} {addfontfeatures-ignored}
{
  \string\addfontfeature (s)~ ignored;\\
  it~ cannot~ be~ used~ with~ a~ font~ that~ wasn't~ selected~ by~ fontspec.
}
\msg_new:nnn {fontspec} {feature-option-overwrite}
{
  Option~ '#2'~ of~ font~ feature~ '#1'~ overwritten.
}
\msg_new:nnn {fontspec} {script-not-exist}
{
  Font~ '\zf@fontname'~ does~ not~ contain~ script~ '#1'.
}
\msg_new:nnn {fontspec} {aat-feature-not-exist}
{
  '\XKV@tfam=\XKV@tkey'~ feature~ not~ supported\\
  for~ AAT~ font~ '\zf@fontname'.
}
\msg_new:nnn {fontspec} {aat-feature-not-exist-in-font}
{
  AAT~ feature~ '\XKV@tfam=\XKV@tkey'~ (#1)~ not~ available\\
  in~ font~ '\zf@fontname'.
}
\msg_new:nnn {fontspec} {icu-feature-not-exist}
{
  '\XKV@tfam=\XKV@tkey'~ feature~ not~ supported\\
  for~ ICU~ font~ '\zf@fontname'
}
\msg_new:nnn {fontspec} {icu-feature-not-exist-in-font}
{
  OpenType~ feature~ '\XKV@tfam=\XKV@tkey'~ (#1)~ not~ available\\
  for~ font~ '\zf@fontname', \\
  with~ script~ '\l_fontspec_script_name_tl',~ and~ language~ '\l_fontspec_lang_name_tl'.
}
\msg_new:nnn {fontspec} {no-opticals}
{
  '\zf@fontname'~ doesn't~ appear~ to~ have~ an~ Optical~ Size~ axis.
}
\msg_new:nnn {fontspec} {language-not-exist}
{
  Language~ '#1'~ not~ available\\
  for~ font~ '\zf@fontname'\\
  with~ script~ '\l_fontspec_script_name_tl'.
}
\msg_new:nnn {fontspec} {only-xetex-feature}
{
  Ignored~ XeTeX~ only~ feature:~ '#1'.
}
\msg_new:nnn {fontspec} {only-luatex-feature}
{
  Ignored~ LuaTeX~ only~ feature:~ '#1'.
}
\msg_new:nnn {fontspec} {no-mapping}
{
  Input~ mapping~ not~ (yet?)~ supported~ in~ LuaTeX.
}
\msg_new:nnn {fontspec} {no-mapping-ligtex}
{
  Input~ mapping~ not~ (yet?)~ supported~ in~ LuaTeX.\\
  Use~ "Ligatures=TeX"~ instead~ of~ "Mapping=tex-text".
}
\msg_new:nnn {fontspec} {cm-default-obsolete}
{
  The~ "cm-default"~ package~ option~ is~ obsolete.
}
%    \end{macrocode}
% Info messages:
%    \begin{macrocode}
\msg_new:nnn {fontspec} {defining-font}
{
  Defining~ font~ family~ for~ '#2'~ with~ options~ [\zf@default@options #1].
}
\msg_new:nnn {fontspec} {no-font-shape}
{
  Could~ not~ resolve~ font~ #1~ (it~ probably~ doesn't~ exist).
}
\msg_new:nnn {fontspec} {set-scale}
{
  \zf@fontname\space scale ~=~ \l_fontspec_scale_tl.
}
\msg_new:nnn {fontspec} {setup-math}
{
  Adjusting~ the~ maths~ setup~ (use~ [no-math]~ to~ avoid~ this).
}
\msg_new:nnn {fontspec} {no-scripts}
{
  Font~ \zf@fontname\space does~ not~ contain~ any~ OpenType~ `Script'~ information.
}
\msg_new:nnn {fontspec} {opa-twice}
{
  Opacity~ set~ twice,~ in~ both~ Colour~ and~ Opacity.\\
  Using~ specification~ "Opacity=#1".
}
\msg_new:nnn {fontspec} {opa-twice-col}
{
  Opacity~ set~ twice,~ in~ both~ Opacity~ and~ Colour.\\
  Using~ an~ opacity~ specification~ in~ hex~ of~ "#1/FF".
}
\msg_new:nnn {fontspec} {bad-colour}
{
  Bad~ colour~ declaration~ "#1".~
  Colour~ must~ be~ one~ of:\\
  *~ a~ named~ xcolor~ colour\\
  *~ a~ six-digit~ hex~ colour~ RRGGBB\\
  *~ an~ eight-digit~ hex~ colour~ RRGGBBTT~ with~ opacity
}
%    \end{macrocode}
%
% \subsection{Option processing}
%
%    \begin{macrocode}
\DeclareOption{cm-default}{
  \fontspec_warning:n {cm-default-obsolete}
}
\DeclareOption{math}{\@zf@mathtrue}
\DeclareOption{no-math}{\@zf@mathfalse}
\DeclareOption{config}{\@zf@configfiletrue}
\DeclareOption{no-config}{\@zf@configfilefalse}
\DeclareOption{quiet}{
  \msg_redirect_module:nnn { fontspec } { warning } { info }
  \msg_redirect_module:nnn { fontspec } { info } { none }
}
\DeclareOption{silent}{
  \msg_redirect_module:nnn { fontspec } { warning } { none }
  \msg_redirect_module:nnn { fontspec } { info } { none }
}
\ExecuteOptions{config,math}
\ProcessOptions*
%    \end{macrocode}
%
% \subsection{Packages}
% We require the \pkg{calc} package for autoscaling and a recent version of the
% \pkg{xkeyval} package for option processing.
%    \begin{macrocode}
\RequirePackage{calc}
\RequirePackage{xkeyval}[2005/05/07]
%    \end{macrocode}
%
% New for \LuaTeX, we load a new package called `\pkg{fontspec-patches}'
% designed to incorporate the hidden but useful parts of the old \pkg{xltxtra}
% package.
%    \begin{macrocode}
\RequirePackage{fontspec-patches}
%    \end{macrocode}
%
%
% \subsection{Encodings}
% Frank Mittelbach has recommended using the `\texttt{EU}$x$' family of font encodings
% to experiment with Unicode.
% Now that \XeTeX\ can find fonts in the |texmf| tree, the Latin Modern OpenType fonts
% can be used as the defaults. See the |euenc| collection of files for how this is implemented.
%    \begin{macrocode}
\xetex_or_luatex:nnn {\tl_set:Nn \zf@enc} {EU1} {EU2}
\tl_set:Nn \rmdefault {lmr}
\tl_set:Nn \sfdefault {lmss}
\tl_set:Nn \ttdefault {lmtt}
\RequirePackage[\zf@enc]{fontenc}
\tl_set_eq:NN \UTFencname \zf@enc % for xunicode
%    \end{macrocode}
% Dealing with a couple of the problems introduced by \pkg{babel}:
%    \begin{macrocode}
\tl_set_eq:NN \cyrillicencoding \zf@enc
\tl_set_eq:NN \latinencoding    \zf@enc
\g@addto@macro \document {
  \tl_set_eq:NN \cyrillicencoding \zf@enc
  \tl_set_eq:NN \latinencoding    \zf@enc
}
%    \end{macrocode}
% That latin encoding definition is repeated to suppress font warnings.
% Something to do with \cmd\select@language\ ending up in the \texttt{.aux}
% file which is read at the beginning of the document.
%
% \paragraph{xunicode}
% Now we load \pkg{xunicode}, working around its internal \XeTeX\ check
% when under \LuaTeX.
%    \begin{macrocode}
\xetex_or_luatex:nn
{
  \RequirePackage{xunicode}
}
{
  \cs_set_eq:NN \fontspec_tmp: \XeTeXpicfile
  \cs_set:Npn \XeTeXpicfile {}
  \RequirePackage{xunicode}
  \cs_set_eq:NN \XeTeXpicfile \fontspec_tmp:
}
%    \end{macrocode}
%
%
% \subsection{User commands}\label{sec:codeuser}
% This section contains the definitions of the commands detailed in
% the user documentation.  Only the `top level' definitions of the
% commands are contained herein; they all use or define macros which
% are defined or used later on in \vref{sec:codeinternal}.
%
% \subsubsection{Font selection}
% \begin{macro}{\fontspec}
%   This is the main command of the package that
%   selects fonts with various features. It takes two arguments: the
%   \MacOSX\ font name and the optional requested features of that
%   font. It simply runs \cs{zf@fontspec}, which takes the same
%   arguments as the top level macro and puts the new-fangled font
%   family name into the global \cmd{\zf@family}. Then this new font
%   family is selected.
%    \begin{macrocode}
\DeclareDocumentCommand \fontspec { O{} m } {
  \fontencoding {\zf@enc}
  \fontspec_set_family:Nnn \f@family {#1}{#2}
  \selectfont
  \ignorespaces
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\setmainfont}
% \begin{macro}{\setsansfont}
% \begin{macro}{\setmonofont}
%     The following three macros perform equivalent operations setting
%     the default font (using \cs{let} rather than \cs{renewcommand}
%     because \cs{zf@family} will change in the future) for a
%     particular family: `roman', sans serif, or typewriter
%     (monospaced). I end them with |\normalfont| so that if they're
%     used in the document, the change registers immediately.
%    \begin{macrocode}
\DeclareDocumentCommand \setmainfont { O{} m } {
  \fontspec_set_family:Nnn \rmdefault {#1}{#2}
  \normalfont
}
\DeclareDocumentCommand \setsansfont { O{} m } {
  \fontspec_set_family:Nnn \sfdefault {#1}{#2}
  \normalfont
}
\DeclareDocumentCommand \setmonofont { O{} m } {
  \fontspec_set_family:Nnn \ttdefault {#1}{#2}
  \normalfont
}
%    \end{macrocode}
% \end{macro} \end{macro} \end{macro}
%
%
% \begin{macro}{\setromanfont}
% This is the old name for \cs{setmainfont}, retained
% for backwards compatibility.
%    \begin{macrocode}
\cs_set_eq:NN \setromanfont \setmainfont
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\setmathrm}
% \begin{macro}{\setmathsf}
% \begin{macro}{\setboldmathrm}
% \begin{macro}{\setmathtt}
% These commands are analogous to \cmd\setromanfont\ and others,
% but for selecting the font used for \cmd\mathrm, \etc. They
% can only be used in the preamble of the
% document. \cmd\setboldmathrm\ is used for specifying which
% fonts should be used in \cmd\boldmath.
%    \begin{macrocode}
\DeclareDocumentCommand \setmathrm { O{} m } {
  \fontspec_set_family:Nnn \zf@rmmaths {#1}{#2}
}
\DeclareDocumentCommand \setboldmathrm { O{} m } {
  \fontspec_set_family:Nnn \zf@rmboldmaths {#1}{#2}
}
\DeclareDocumentCommand \setmathsf { O{} m } {
  \fontspec_set_family:Nnn \zf@sfmaths {#1}{#2}
}
\DeclareDocumentCommand \setmathtt { O{} m } {
  \fontspec_set_family:Nnn \zf@ttmaths {#1}{#2}
}
\@onlypreamble\setmathrm
\@onlypreamble\setboldmathrm
\@onlypreamble\setmathsf
\@onlypreamble\setmathtt
%    \end{macrocode}
% If the commands above are not executed, then \cmd\rmdefault\ (\etc)
% will be used.
%    \begin{macrocode}
\def\zf@rmmaths{\rmdefault}
\def\zf@sfmaths{\sfdefault}
\def\zf@ttmaths{\ttdefault}
%    \end{macrocode}
% \end{macro} \end{macro} \end{macro}
% \end{macro}
%
% \begin{macro}{\newfontfamily}
% \begin{macro}{\newfontface}
%   This macro takes the arguments of \cs{fontspec} with a prepended
%   \meta{instance cmd} (code for middle optional argument generated
%   by \name{Scott Pakin}'s \textsf{newcommand.py}). This command is used
%   when a specific font instance needs to be referred to repetitively
%   (\eg, in a section heading) since continuously calling
%   \cs{zf@fontspec} is inefficient because it must parse the
%   option arguments every time.
%
%   \cs{fontspec_select:nn} defines a font family and saves its name in
%   \cs{zf@family}. This family is then used in a typical NFSS \cmd\fontfamily\
%   declaration, saved in the macro name specified.
%    \begin{macrocode}
\DeclareDocumentCommand \newfontfamily { m O{} m } {
  \fontspec_select:nn{#2}{#3}
  \use:x {
    \exp_not:N \DeclareRobustCommand \exp_not:N #1 {
      \exp_not:N \fontencoding {\zf@enc}
      \exp_not:N \fontfamily {\zf@family} \exp_not:N \selectfont
    }
  }
}
%    \end{macrocode}
% \cmd\newfontface\ uses an undocumented feature of the \feat{BoldFont}
% feature; if its argument is empty (\ie, |BoldFont={}|), then no bold
% font is searched for.
%    \begin{macrocode}
\DeclareDocumentCommand \newfontface { m O{} m } {
  \newfontfamily #1 [ BoldFont={},ItalicFont={},SmallCapsFont={},#2 ] {#3}
}
%    \end{macrocode}
% \end{macro} \end{macro}
%
% \subsubsection{Font feature selection}
%
% \begin{macro}{\defaultfontfeatures}
%   This macro takes one argument that consists of all of feature
%   options that will be applied by default to all subsequent
%   \cs{fontspec}, et al., commands. It stores its value in
%   \cs{zf@default@options} (initialised empty), which is
%   concatenated with the individual macro choices in the
%   \cs{zf@get@feature@requests} macro.
%    \begin{macrocode}
\DeclareDocumentCommand \defaultfontfeatures {m} {\def\zf@default@options{#1,}}
\let\zf@default@options\@empty
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\addfontfeatures}
%   In order to be able to extend the feature selection of
%   a given font, two things need to be known: the currently selected
%   features, and the currently selected font. Every time a font
%   family is created, this information is saved inside a control
%   sequence with the name of the font family itself.
%
%   This macro extracts this information, then appends the requested
%   font features to add to the already existing ones, and calls the
%   font again with the top level \cs{fontspec} command.
%
%   The default options are \emph{not} applied (which is why
%   \cs{zf@default@options} is emptied inside the group; this is allowed
%   as \cmd\zf@family\ is globally defined in \cmd\fontspec_select:nn), so this
%   means that the only added features to the font are strictly those
%   specified by this command.
%
%   \cs{addfontfeature} is defined as an alias, as I found that I
%   often typed this instead when adding only a single font feature.
%    \begin{macrocode}
\DeclareDocumentCommand \addfontfeatures {m} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \begingroup
      \let\zf@default@options\@empty
      \use:x {
        \exp_not:N\fontspec_select:nn
          {\csname zf@family@options\f@family\endcsname,#1}
          {\csname zf@family@fontname\f@family\endcsname}
      }
    \endgroup
    \fontfamily\zf@family\selectfont
  \else
    \fontspec_warning:n {addfontfeatures-ignored}
  \fi
  \ignorespaces
}
\let\addfontfeature\addfontfeatures
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Defining new font features}
%
% \begin{macro}{\newfontfeature}
%   \cs{newfontfeature} takes two arguments: the name of the feature
%   tag by which to reference it, and the string that is used to
%   select the font feature. It uses a counter to keep track of the
%   number of new features introduced; every time a new feature is
%   defined, a control sequence is defined made up of the
%   concatenation of |+zf-| and the new feature tag. This long-winded
%   control sequence is then called upon to update the font family
%   string when a new instance is requested.
%    \begin{macrocode}
\DeclareDocumentCommand \newfontfeature {mm} {
  \stepcounter{zf@newff}
  \cs_set:cpx{+zf-#1}{+zf-\the\c@zf@newff}
  \define@key[zf]{options}{#1}[]{
    \zf@update@family{\csname+zf-#1\endcsname}
    \zf@update@ff{#2}
  }
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\newAATfeature}
% This command assigns a new AAT feature by its code (|#2|,|#3|) to a new name (|#1|).
% Better than \cmd\newfontfeature\ because it checks if the feature exists in the
% font it's being used for.
%    \begin{macrocode}
\DeclareDocumentCommand \newAATfeature {mmmm} {
  \unless\ifcsname zf@options@#1\endcsname
    \zf@define@font@feature{#1}
  \fi
  \key@ifundefined[zf]{#1}{#2}{}{
    \fontspec_warning:nxx {feature-option-overwrite}{#1}{#2}
  }
  \zf@define@feature@option{#1}{#2}{#3}{#4}{}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newICUfeature}
% \begin{macro}{\newopentypefeature}
% This command assigns a new OpenType feature by its abbreviation (|#2|) to a new name (|#1|).
% Better than \cmd\newfontfeature\ because it checks if the feature exists in the
% font it's being used for.
%    \begin{macrocode}
\DeclareDocumentCommand \newICUfeature {mmm} {
  \unless\ifcsname zf@options@#1\endcsname
    \zf@define@font@feature{#1}
  \fi
  \key@ifundefined[zf]{#1}{#2}{}{
    \fontspec_warning:nxx {feature-option-overwrite}{#1}{#2}
  }
  \zf@define@feature@option{#1}{#2}{}{}{#3}
}
\cs_set_eq:NN \newopentypefeature \newICUfeature
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\aliasfontfeature}
% \begin{macro}{\aliasfontfeatureoption}
% User commands for renaming font features and font feature options.
% Provided I've been consistent, they should work for everything.
%    \begin{macrocode}
\DeclareDocumentCommand \aliasfontfeature {mm} {\multi@alias@key{#1}{#2}}
\DeclareDocumentCommand \aliasfontfeatureoption {mmm} {
  \keyval@alias@key[zf@feat]{#1}{#2}{#3}
}
%    \end{macrocode}
% \end{macro} \end{macro}
%
% \begin{macro}{\newfontscript}
% Mostly used internally, but also possibly useful for users, to define new OpenType
% `scripts', mapping logical names to OpenType script tags.
% Iterates though the scripts in the selected font to check that it's a valid
% feature choice, and then prepends the (\XeTeX) \cmd\font\ feature string with the appropriate
% script selection tag.
%    \begin{macrocode}
\DeclareDocumentCommand \newfontscript {mm}
{
  \fontspec_new_script:nn {#1} {#2}
  \fontspec_new_script:nn {#2} {#2}
}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new:Npn \fontspec_new_script:nn #1#2
{
  \define@key[zf@feat]{Script}{#1}[]{
    \fontspec_check_script:nTF {#2} {
      \zf@update@family{+script=#1}
      \tl_set:Nn \l_fontspec_script_tl {#2}
      \c@zf@script=\l_fontspec_strnum_int\relax
    }{
      \fontspec_warning:nx {script-not-exist} {#1}
    }
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newfontlanguage}
% Mostly used internally, but also possibly useful for users, to define new OpenType
% `languages', mapping logical names to OpenType language tags.
% Iterates though the languages in the selected font to check that it's a valid
% feature choice, and then prepends the (\XeTeX) \cmd\font\ feature string with the appropriate
% language selection tag.
%    \begin{macrocode}
\DeclareDocumentCommand \newfontlanguage {mm}
{
  \fontspec_new_lang:nn {#1} {#2}
  \fontspec_new_lang:nn {#2} {#2}
}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new:Npn \fontspec_new_lang:nn #1#2
{
  \define@key[zf@feat]{Lang}{#1}[]{
    \fontspec_check_lang:nTF {#2} {
      \zf@update@family{+lang=#1}
      \tl_set:Nn \l_fontspec_lang_tl {#2}
      \c@zf@language=\l_fontspec_strnum_int\relax
    }{
      \fontspec_warning:nx {language-not-exist} {#1}
    }
  }
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\DeclareFontsExtensions}
% \texttt{dfont} would never be uppercase, right?
%    \begin{macrocode}
\DeclareDocumentCommand \DeclareFontsExtensions {m}
{
  \tl_set:Nx \l_fontspec_extensions_clist { \zap@space #1~\@empty }
}
\DeclareFontsExtensions{.otf,.ttf,.OTF,.TTF,.ttc,.TTC,.dfont}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Programmer's interface}
%
% These functions are not used directly by fontspec when defining fonts;
% they are designed to be used by other packages who wish to do font-related
% things on top of fontspec itself.
%
% Because I haven't fully explored how these functions will behave in
% practise, I am not giving them user-level names. As it becomes more clear
% which of these should be accessible by document writers, I'll open them up
% a little more.
%
% All functions are defined assuming that the font to be queried is
% currently selected as a fontspec font. (I.e., via \verb|\fontspec| or
% from a \verb|\newfontfamily| macro or from \verb|\setmainfont| and so on.)
%
% \begin{macro}{\fontspec_if_fontspec_font:TF}
% Test whether the currently selected font has been loaded by fontspec.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_fontspec_font: {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \prg_return_true:
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_aat_feature:nnTF}
% Conditional to test if the currently selected font contains the \AAT\
% feature (|#1|,|#2|).
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_aat_feature:nn {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \font_set:Nnn \zf@basefont {\use:c{zf@family@fontdef\f@family}} {\f@size pt}
    \ifzf@atsui
      \fontspec_make_AAT_feature_string:nn{#1}{#2}
      \ifx\@tempa\@empty
        \prg_return_false:
      \else
        \prg_return_true:
      \fi
    \else
      \prg_return_false:
    \fi
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_opentype:TF}
% Test whether the currently selected font is an OpenType font.
% Always true for LuaTeX fonts.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_opentype: {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \font_set:Nnn \zf@basefont {\csname zf@family@fontdef\f@family\endcsname} {\f@size pt}
    \fontspec_set_font_type:
    \ifzf@icu
      \prg_return_true:
    \else
      \prg_return_false:
    \fi
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_feature:nTF}
% Test whether the currently selected font contains the raw OpenType
% feature |#1|. E.g.: |\fontspec_if_feature:nTF {pnum} {True} {False}|
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_feature:n {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \font_set:Nnn \zf@basefont {\csname zf@family@fontdef\f@family\endcsname} {\f@size pt}
    \fontspec_set_font_type:
    \ifzf@icu
      \int_set:Nn \c@zf@script
        {\use:c {g_fontspec_script_num_(\zf@family)_tl}}
      \int_set:Nn \c@zf@language
        {\use:c {g_fontspec_lang_num_(\zf@family)_tl}}
      \tl_set:Nv \l_fontspec_script_tl {g_fontspec_script_(\zf@family)_tl}
      \tl_set:Nv \l_fontspec_lang_tl   {g_fontspec_lang_(\zf@family)_tl}
      \fontspec_check_ot_feat:nTF {#1} \prg_return_true: \prg_return_false:
    \else
      \prg_return_false:
    \fi
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_feature:nnnTF}
% Test whether the currently selected font with raw OpenType script tag |#1| and raw OpenType language tag |#2| contains the raw OpenType feature tag |#3|. E.g.: |\fontspec_if_feature:nTF {latn} {ROM} {pnum} {True} {False}|
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_feature:nnn {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \font_set:Nnn \zf@basefont {\csname zf@family@fontdef\f@family\endcsname} {\f@size pt}
    \fontspec_set_font_type:
    \ifzf@icu
      \fontspec_iv_str_to_num:n{#1} \c@zf@script   = \l_fontspec_strnum_int \relax
      \fontspec_iv_str_to_num:n{#2} \c@zf@language = \l_fontspec_strnum_int \relax
      \fontspec_check_ot_feat:nTF {#3} \prg_return_true: \prg_return_false:
    \else
      \prg_return_false:
    \fi
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_script:nTF}
% Test whether the currently selected font contains the raw OpenType
% script |#1|. E.g.: |\fontspec_if_script:nTF {latn} {True} {False}|
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_script:n {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \font_set:Nnn \zf@basefont {\csname zf@family@fontdef\f@family\endcsname} {\f@size pt}
    \fontspec_set_font_type:
    \ifzf@icu
      \fontspec_check_script:nTF {#1} \prg_return_true: \prg_return_false:
    \else
      \prg_return_false:
    \fi
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_language:nTF}
% Test whether the currently selected font contains the raw OpenType language
% tag |#1|. E.g.: |\fontspec_if_language:nTF {ROM} {True} {False}|.
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_language:n {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \font_set:Nnn \zf@basefont {\csname zf@family@fontdef\f@family\endcsname} {\f@size pt}
    \fontspec_set_font_type:
    \ifzf@icu
      \tl_set:Nv \l_fontspec_script_tl {g_fontspec_script_(\zf@family)_tl}
      \int_set:Nn \c@zf@script
        {\use:c {g_fontspec_script_num_(\zf@family)_tl}}
      \fontspec_check_lang:nTF {#1} \prg_return_true: \prg_return_false:
    \else
      \prg_return_false:
    \fi
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_language:nnTF}
% Test whether the currently selected font contains the raw OpenType language
% tag |#2| in script |#1|. E.g.: |\fontspec_if_language:nnTF {cyrl} {SRB} {True} {False}|.
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_language:nn {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \font_set:Nnn \zf@basefont {\csname zf@family@fontdef\f@family\endcsname} {\f@size pt}
    \fontspec_set_font_type:
    \ifzf@icu
      \tl_set:Nn \l_fontspec_script_tl {#1}
      \fontspec_iv_str_to_num:n{#1} \c@zf@script   = \l_fontspec_strnum_int \relax
      \fontspec_check_lang:nTF {#2} \prg_return_true: \prg_return_false:
    \else
      \prg_return_false:
    \fi
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_current_script:nTF}
% Test whether the currently loaded font is using the specified raw
% OpenType script tag |#1|.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_current_script:n {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \font_set:Nnn \zf@basefont {\csname zf@family@fontdef\f@family\endcsname} {\f@size pt}
    \fontspec_set_font_type:
    \ifzf@icu
      \tl_if_eq:nvTF {#1} {g_fontspec_script_(\zf@family)_tl}
        {\prg_return_true:} {\prg_return_false:}
    \else
      \prg_return_false:
    \fi
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_current_language:nTF}
% Test whether the currently loaded font is using the specified raw
% OpenType language tag |#1|.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_current_language:n {TF,T,F} {
  \ifcsname zf@family@fontdef\f@family\endcsname
    \font_set:Nnn \zf@basefont {\csname zf@family@fontdef\f@family\endcsname} {\f@size pt}
    \fontspec_set_font_type:
    \ifzf@icu
      \tl_if_eq:nvTF {#1} {g_fontspec_lang_(\zf@family)_tl}
        {\prg_return_true:} {\prg_return_false:}
    \else
      \prg_return_false:
    \fi
  \else
    \prg_return_false:
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% Need this:
%    \begin{macrocode}
\cs_generate_variant:Nn \tl_if_eq:nnTF {nv}
%    \end{macrocode}
%
% \begin{macro}{\fontspec_set_family:Nnn}
% \darg{family}
% \darg{fontspec features}
% \darg{font name}
% Defines a new font family from given \meta{features} and \meta{font},
% and stores the name in the variable \meta{family}.
% See the standard \pkg{fontspec} user commands for applications of this
% function.
%
% We want to store the actual name of the font family within the \meta{family}
% variable because the actual \LaTeX\ family name is automatically generated
% by fontspec and it's easier to keep it that way.
%
% Please use |\fontspec_set_family:Nnn| instead of |\fontspec_select:nn|,
% which may change in the future.
%    \begin{macrocode}
\cs_new:Npn \fontspec_set_family:Nnn #1#2#3 {
  \fontspec_select:nn {#2}{#3}
  \tl_set_eq:NN #1 \zf@family
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{expl3 interface for font loading}
%
% Using |\font\1={xyz}| notation doesn't work at present with LuaLaTeX,
% although it should be the correct way to do things. Continue to use
% |\font\1="xyz"| for now for both engines.
%    \begin{macrocode}
\xetex_or_luatex:nnn { \cs_set:Npn \fontspec_fontwrap:n #1 } { "#1" } { {#1} }
\cs_set:Npn \fontspec_fontwrap:n #1 { "#1" }
%    \end{macrocode}
%
% Beginnings of an `l3font', I guess:
%    \begin{macrocode}
\cs_new:Npn \font_set:Nnn #1#2#3 {
  \font #1 = \fontspec_fontwrap:n {#2} ~at~#3\scan_stop:
}
\cs_new:Npn \font_gset:Nnn #1#2#3 {
  \global \font #1 = \fontspec_fontwrap:n {#2} ~at~#3\scan_stop:
}
%    \end{macrocode}
%
%
% \subsection{Internal macros}
% \label{sec:codeinternal}
%
% The macros from here in are used internally by all those defined above.
% They are not designed to remain consistent between versions.
%
%
%
%
% \begin{macro}{\fontspec_select:nn}
% This is the command that defines font families for use, the underlying
% procedure of all \cmd\fontspec-like commands. Given a
% list of font features (|#1|) for a requested font (|#2|),
% it will define an NFSS
% family for that font and put the family name (globally) into \cs{zf@family}.
% The \TeX\ `\cs{font}' command is (globally) stored in \cs{zf@basefont}.
%
% This macro does its processing inside a group to attempt to restrict the scope of its internal processing. This works to some degree to insulate the internal commands from having to be manually.
%    \begin{macrocode}
\cs_set:Npn \fontspec_select:nn #1#2 {
  \begingroup
  \fontspec_init:
%    \end{macrocode}
% \cmd{\zf@fontname} is used as the generic name of the font being defined.
% \cmd{\zf@family@long} is the unique identifier of the font with all its
% features.
% \cmd{\zf@up} is the font specifically to be used as the upright font.
%    \begin{macrocode}
  \edef\zf@fontname{#2}
  \let\zf@family@long\zf@fontname
  \let\zf@up\zf@fontname
%    \end{macrocode}
% Now convert the requested features to font definition
% strings. First the features are parsed for information about font
% loading (whether it's a named font or external font, etc.), and then
% information is extracted for the names of the other shape fonts.
%
% Then the mapping from user features to low-level features occurs.
% This is performed with \cs{fontspec_get_features:n}, in
% which \cs{setkeys} retrieves the requested font features and
% processes them. As \cs{setkeys} is run multiple times, some of its
% information storing only occurs once while we decide if the font family
% has been defined or not. When the later processing is occuring per-shape
% this no longer needs to happen; this is indicated by the `firsttime'
% conditional.
%    \begin{macrocode}
  \fontspec_preparse_features:nn {#1}{#2}
  \fontspec_set_scriptlang:
  \fontspec_get_features:n {\zf@font@feat}
  \zf@firsttimefalse
%    \end{macrocode}
% Check if the family is unique and, if so, save its information.
% (\cs{addfontfeature} and other macros use this data.)
% Then the font family and its shapes are defined in the NFSS.
%
% All NFSS specifications take their default values, so if any of them
% are redefined, the shapes will be selected to fit in with the
% current state. For example, if \cmd\bfdefault\ is redefined to |b|, all
% bold shapes defined by this package will also be assigned to |b|.
%    \begin{macrocode}
  \fontspec_save_family:nT {#2} {
    \fontspec_info:nxx {defining-font} {#1} {#2}
    \fontspec_save_fontinfo:nn {#1} {#2}
    \DeclareFontFamily{\zf@enc}{\zf@family}{}
    \fontspec_set_upright:
    \fontspec_set_bold:
    \fontspec_set_italic:
    \fontspec_set_slanted:
    \fontspec_set_bold_italic:
    \fontspec_set_bold_slanted:
  }
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zf@fontspec}
% For backwards compatibility. Do not use this from now on!
%    \begin{macrocode}
\cs_set_eq:NN \zf@fontspec \fontspec_select:nn
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_preparse_features:nn}
% Perform the (multi-step) feature parsing process.
%    \begin{macrocode}
\cs_new:Npn \fontspec_preparse_features:nn #1#2 {
%    \end{macrocode}
% Detect if external fonts are to be used, possibly automatically, and
% parse fontspec features for bold/italic fonts and their features.
%    \begin{macrocode}
  \fontspec_if_detect_external:nT {#2}
   { \setkeys[zf]{preparse-external}{ExternalLocation} }
  \fontspec_setkeys:xx {preparse-external} {\zf@default@options #1}
%    \end{macrocode}
% When \cmd{\zf@fontname} is augmented with a prefix or whatever to create
% the name of the upright font (\cmd{\zf@up}), this latter is the new `general
% font name' to use.
%    \begin{macrocode}
  \let\zf@fontname\zf@up
  \fontspec_setkeys:xx {preparse} {\XKV@rm}
  \let\zf@font@feat\XKV@rm
%    \end{macrocode}
% Finally save the `confirmed' font definition.
%    \begin{macrocode}
  \font_set:Nnn \zf@basefont {\fontspec_fullname:n {\zf@up}} {\f@size pt}
  \fontspec_set_font_type:
  \font_gset:Nnn \zf@basefont {\fontspec_fullname:n {\zf@up}} {\f@size pt}
  \zf@basefont % this is necessary for LuaLaTeX to check the scripts properly
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_detect_external:nT}
% Check if either the fontname ends with a known font extension.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_detect_external:n {T}
 {
  \clist_map_inline:Nn \l_fontspec_extensions_clist
   {
    \bool_set_false:N \l_tmpa_bool
    \tl_if_in:nnT {#1 <= end_of_string} {##1 <= end_of_string}
      { \bool_set_true:N \l_tmpa_bool \clist_map_break: }
   }
  \bool_if:NTF \l_tmpa_bool \prg_return_true: \prg_return_false:
 }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_fullname:n}
% Constructs the complete font name based on a common piece of info.
%    \begin{macrocode}
\cs_set:Npn \fontspec_fullname:n #1 {
  \fontspec_namewrap:n { #1 \l_fontspec_extension_tl }
  \l_fontspec_renderer_tl
  \l_fontspec_optical_size_tl
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\fontspec_save_family:nT}
%% Now we have a unique (in fact, too unique!) string that contains
% the family name and every option in abbreviated form. This is used
% with a counter to create a simple NFSS family name for the font we're
% selecting.
%
% The font name is fully expanded, in case it's defined in terms of macros, before having its spaces zapped.
%    \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_save_family:n {T} {
  \cs_if_exist:cF {g_fontspec_UID_\zf@family@long}
  {
    \cs_if_exist:cTF {g_fontspec_family_#1_int} {
      \int_gincr:c {g_fontspec_family_#1_int}
    }{
      \int_new:c {g_fontspec_family_#1_int}
    }
    \edef\@tempa{#1~}
    \tl_gset:cx {g_fontspec_UID_\zf@family@long} {
      \expandafter\zap@space\@tempa\@empty
          ( \int_use:c {g_fontspec_family_#1_int} )
    }
  }
  \tl_gset:Nv \zf@family {g_fontspec_UID_\zf@family@long}
  \cs_if_exist:cTF {zf@family@fontname\zf@family}
    \prg_return_false: \prg_return_true:
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_set_scriptlang:}
% Only necessary for OpenType fonts.
% First check if the font supports scripts, then apply defaults if
% none are explicitly requested. Similarly with the language settings.
%    \begin{macrocode}
\cs_new:Npn \fontspec_set_scriptlang: {
  \ifzf@icu
    \tl_if_empty:NTF \l_fontspec_script_name_tl {
      \fontspec_check_script:nTF {latn}
      {
        \tl_set:Nn \l_fontspec_script_name_tl {Latin}
        \tl_if_empty:NT \l_fontspec_lang_name_tl {
          \tl_set:Nn \l_fontspec_lang_name_tl {Default}
        }
        \fontspec_setkeys:xxx {feat} {Script} {\l_fontspec_script_name_tl}
        \fontspec_setkeys:xxx {feat} {Lang}   {\l_fontspec_lang_name_tl}
      }
      {
        \fontspec_info:n {no-scripts}
      }
    }
    {
      \tl_if_empty:NT \l_fontspec_lang_name_tl {
        \tl_set:Nn \l_fontspec_lang_name_tl {Default}
      }
      \fontspec_setkeys:xxx {feat} {Script} {\l_fontspec_script_name_tl}
      \fontspec_setkeys:xxx {feat} {Lang}   {\l_fontspec_lang_name_tl}
    }
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_save_fontinfo:nn}
% Saves the relevant font information for future processing.
%    \begin{macrocode}
\cs_new:Npn \fontspec_save_fontinfo:nn #1#2 {
    \tl_gset:cx {zf@family@fontname\zf@family} {#2}
    \tl_gset:cx {zf@family@options\zf@family} {\zf@default@options #1}
    \tl_gset:cx {zf@family@fontdef\zf@family} {
      \fontspec_fullname:n {\zf@fontname} : \l_fontspec_pre_feat_tl \l_fontspec_rawfeatures_sclist
    }
    \tl_gset:cx {g_fontspec_script_num_(\zf@family)_tl}
      { \int_use:N \c@zf@script   }
    \tl_gset:cx {g_fontspec_lang_num_(\zf@family)_tl}
      { \int_use:N \c@zf@language }
    \tl_gset_eq:cN {g_fontspec_script_(\zf@family)_tl} \l_fontspec_script_tl
    \tl_gset_eq:cN {g_fontspec_lang_(\zf@family)_tl}   \l_fontspec_lang_tl
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_set_upright:}
% Sets the upright shape.
%    \begin{macrocode}
\cs_new:Npn \fontspec_set_upright: {
  \zf@make@font@shapes{\zf@fontname}
    {\mddefault}{\updefault}{\zf@font@feat\zf@up@feat}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_set_bold:}
% The macros \cs{zf@bf}, et al., are used to store the name of the
% custom bold, et al., font, if requested as user options. If they are
% empty, the default fonts are used.
%
% The extra bold options defined with
% \feat{BoldFeatures} are appended to the generic font features.
% Then, the bold font is defined either as the ATS
% default (\cs{zf@make@font@shapes}' optional argument is to check if
% there actually is one; if not, the bold NFSS series is left
% undefined) or with the font specified with the \feat{BoldFont} feature.
%    \begin{macrocode}
\cs_new:Npn \fontspec_set_bold: {
  \unless\ifzf@nobf
    \ifx\zf@bf\@empty
      \zf@make@font@shapes[\zf@fontname]{/B}
        {\bfdefault}{\updefault}{\zf@font@feat\zf@bf@feat}
    \else
      \zf@make@font@shapes{\zf@bf}
        {\bfdefault}{\updefault}{\zf@font@feat\zf@bf@feat}
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_set_italic:}
% And italic in the same way:
%    \begin{macrocode}
\cs_new:Npn \fontspec_set_italic: {
  \unless\ifzf@noit
    \ifx\zf@it\@empty
      \zf@make@font@shapes[\zf@fontname]{/I}
        {\mddefault}{\itdefault}{\zf@font@feat\zf@it@feat}
    \else
      \zf@make@font@shapes{\zf@it}
        {\mddefault}{\itdefault}{\zf@font@feat\zf@it@feat}
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_set_slanted:}
% And slanted but only if requested:
%    \begin{macrocode}
\cs_new:Npn \fontspec_set_slanted: {
  \ifx\zf@sl\@empty\else
    \zf@make@font@shapes{\zf@sl}
      {\mddefault}{\sldefault}{\zf@font@feat\zf@sl@feat}
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_set_bold_italic:}
% % If requested, the custom fonts take precedence when choosing the
% bold italic font. When both italic and bold fonts are requested and
% the bold italic font hasn't been explicitly specified (a rare
% occurance, presumably), the new bold font is used to define the new
% bold italic font.
%    \begin{macrocode}
\cs_new:Npn \fontspec_set_bold_italic: {
  \@tempswatrue
  \ifzf@nobf\@tempswafalse\fi
  \ifzf@noit\@tempswafalse\fi
  \bool_if:NT \l_fontspec_external_bool \@tempswafalse
  \if@tempswa
    \ifx\zf@bfit\@empty
      \ifx\zf@bf\@empty
        \ifx\zf@it\@empty
          \zf@make@font@shapes[\zf@fontname]{/BI}
            {\bfdefault}{\itdefault}{\zf@font@feat\zf@bfit@feat}
        \else
          \zf@make@font@shapes[\zf@it]{/B}
            {\bfdefault}{\itdefault}{\zf@font@feat\zf@bfit@feat}
        \fi
      \else
        \zf@make@font@shapes[\zf@bf]{/I}
          {\bfdefault}{\itdefault}{\zf@font@feat\zf@bfit@feat}
      \fi
    \else
      \zf@make@font@shapes{\zf@bfit}
        {\bfdefault}{\itdefault}{\zf@font@feat\zf@bfit@feat}
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_set_bold_slanted:}
% And bold slanted, again, only if requested:
%    \begin{macrocode}
\cs_new:Npn \fontspec_set_bold_slanted: {
  \ifx\zf@bfsl\@empty
    \ifx\zf@sl\@empty\else
      \zf@make@font@shapes[\zf@sl]{/B}
        {\bfdefault}{\sldefault}{\zf@font@feat\zf@bfsl@feat}
    \fi
  \else
    \zf@make@font@shapes{\zf@bfsl}
      {\bfdefault}{\sldefault}{\zf@font@feat\zf@bfsl@feat}
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
% \subsubsection{Fonts}
%
% \begin{macro}{\fontspec_set_font_type:}
% Now check if the font is to be rendered with \ATSUI\ or \ICU. This will either
% be automatic (based on the font type), or specified by the user via a font feature.
%
% This macro sets \cs{zf@atsui} or \cs{zf@icu} or \cs{zf@mm} booleans
% accordingly depending if the font in \cmd\zf@basefont\ is an \AAT\
% font or an OpenType font or a font with feature axes (either \AAT\ or
% Multiple Master), respectively.
%    \begin{macrocode}
\xetex_or_luatex:nnn { \cs_new:Npn \fontspec_set_font_type: }
   {
    \zf@tfmfalse \zf@atsuifalse \zf@icufalse \zf@mmfalse \zf@graphitefalse
    \ifcase\XeTeXfonttype\zf@basefont
      \zf@tfmtrue
    \or
      \zf@atsuitrue
      \ifnum\XeTeXcountvariations\zf@basefont > \c_zero
        \zf@mmtrue
      \fi
    \or
      \zf@icutrue
    \fi
%    \end{macrocode}
% If automatic, the \cmd{\l_fontspec_renderer_tl} token list will still be
% empty (other suffices that could be added will be later in the feature
% processing), and if it is indeed still empty, assign it a value so that the
% other weights of the font are specifically loaded with the same renderer.
%    \begin{macrocode}
    \tl_if_empty:NT \l_fontspec_renderer_tl {
      \ifzf@atsui
        \tl_set:Nn \l_fontspec_renderer_tl {/AAT}
      \else\ifzf@icu
        \tl_set:Nn \l_fontspec_renderer_tl {/ICU}
      \fi\fi
    }
  }
  {
    \zf@icutrue
  }
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\zf@make@font@shapes}
%  \doarg{Font name prefix}
%  \darg{Font name}
%  \darg{Font series}
%  \darg{Font shape}
%  \darg{Font features}
%   This macro eventually uses \cs{DeclareFontShape} to define the font shape in
%   question.
%
%   The optional first
%   argument is used when making the font shapes for bold, italic, and
%   bold italic fonts using \XeTeX's auto-recognition with |#2| as |/B|, |/I|,
%   and |/BI| font name suffixes. If no such font is found, it falls
%   back to the original font name, in which case this macro doesn't
%   proceed and the font shape is not created for the NFSS.
%    \begin{macrocode}
\newcommand*\zf@make@font@shapes[5][]{
  \begingroup
    \edef\@tempa{#1}
    \unless\ifx\@tempa\@empty
      \font_set:Nnn \@tempfonta {\fontspec_fullname:n {#1}} {\f@size pt}
      \edef\@tempa{\fontname\@tempfonta}
    \fi
    \font_set:Nnn \@tempfontb {\fontspec_fullname:n {#1#2}} {\f@size pt}
    \edef\@tempb{\fontname\@tempfontb}
    \ifx\@tempa\@tempb
      \fontspec_info:nx {no-font-shape} {#1#2}
    \else
      \edef\zf@fontname{#1#2}
      \let\zf@basefont\@tempfontb
      \fontspec_declare_shape:nnnn {}{#3}{#4}{#5}
%    \end{macrocode}
% Next, the small caps are defined. \cs{zf@make@smallcaps} is used to
% define the appropriate string for activating small caps in the font,
% if they exist. If we are defining small caps for the upright shape,
% then the small caps shape default is used. For an \emph{italic}
% font, however, the shape parameter is overloaded and we must call
% italic small caps by their own identifier. See \vref{sec:sishape}
% for the code that enables this usage.
%    \begin{macrocode}
      \ifx\zf@sc\@empty
        \unless\ifzf@nosc
          \zf@make@smallcaps
          \unless\ifx\zf@smallcaps\@empty
            \fontspec_declare_shape:nnnn {\zf@smallcaps}{#3}
              {\ifx#4\itdefault\sidefault\else\scdefault\fi}{#5\zf@sc@feat}
          \fi
        \fi
      \else
        \edef\zf@fontname{\zf@sc}
        \fontspec_declare_shape:nnnn {}{#3}
          {\ifx#4\itdefault\sidefault\else\scdefault\fi}{#5\zf@sc@feat}
      \fi
    \fi
  \endgroup
}
%    \end{macrocode}
% Note that the test for italics to choose the \cmd\sidefault\ shape
% only works while \cmd\fontspec_select:nn\ passes single tokens to this macro\dots
% \end{macro}
%
% \begin{macro}{\fontspec_declare_shape:nnnn}
% \darg{Raw appended font feature}
% \darg{Font series}
% \darg{Font shape}
% \darg{Font features}
% Wrapper for \cmd\DeclareFontShape.
%    \begin{macrocode}
\cs_new:Npn \fontspec_declare_shape:nnnn #1#2#3#4 {
  \clist_if_empty:NTF \l_fontspec_sizefeat_clist
  {
    \fontspec_get_features:n{#4}
    \tl_set:Nx \l_fontspec_nfss_tl {
      <-> \l_fontspec_scale_tl
      \fontspec_fontwrap:n {
        \fontspec_fullname:n {\zf@fontname} :
          \l_fontspec_pre_feat_tl \l_fontspec_rawfeatures_sclist #1
      }
    }
  }
%    \end{macrocode}
% Default code, above, sets things up for no optical size fonts or features.
% On the other hand, loop through \feat{SizeFeatures} arguments, which
% are of the form
% {\par\centering |SizeFeatures={{<one>},{<two>},{<three>}}|.\par}
%    \begin{macrocode}
  {
    \tl_clear:N \l_fontspec_nfss_tl
    \clist_map_inline:Nn \l_fontspec_sizefeat_clist {
      \tl_clear:N \l_fontspec_size_tl
      \tl_set_eq:NN \l_fontspec_sizedfont_tl \zf@fontname
      \fontspec_setkeys:xx {sizing} { \expandafter \@firstofone ##1 }
      \tl_if_empty:NT \l_fontspec_size_tl { \fontspec_error:n {no-size-info} }
      \fontspec_get_features:n{#4,\XKV@rm}
      \tl_put_right:Nx \l_fontspec_nfss_tl {
        <\l_fontspec_size_tl> \l_fontspec_scale_tl
        \fontspec_fontwrap:n {
          \fontspec_fullname:n { \l_fontspec_sizedfont_tl }
          : \l_fontspec_pre_feat_tl \l_fontspec_rawfeatures_sclist #1
        }
      }
    }
  }
%    \end{macrocode}
% And finally the actual font shape declaration using \cmd\l_fontspec_nfss_tl\ defined above.
% \cmd\zf@adjust\ is defined in various places to deal with things like the hyphenation
% character and interword spacing.
%    \begin{macrocode}
  \PackageInfo{fontspec}{
    Defining~ shape~ #2/#3~ with~ raw~ font~ features:
    \MessageBreak \l_fontspec_rawfeatures_sclist
  \@gobble}
  \use:x{
    \exp_not:N\DeclareFontShape{\zf@enc}{\zf@family}{#2}{#3}
      {\l_fontspec_nfss_tl}{\zf@adjust}
  }
%    \end{macrocode}
% This extra stuff for the slanted shape substitution is a little bit awkward,
% but I'd rather have it here than break out yet another macro. Alternatively,
% one day I might just redefine \cmd\slshape. Why not, eh?
%    \begin{macrocode}
  \tl_if_eq:xxT {#3} {\itdefault}
  {
    \use:x {
      \exp_not:N \DeclareFontShape {\zf@enc}{\zf@family}{#2}{\sldefault}
        {<->ssub*\zf@family/#2/\itdefault}{\zf@adjust}
    }
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_fontspec_pre_feat_tl}
% These are the features always applied to a font selection before other
% features.
%    \begin{macrocode}
\xetex_or_luatex:nnn { \tl_set:Nn \l_fontspec_pre_feat_tl }
  {
    \ifzf@icu
      \tl_if_empty:NF \l_fontspec_script_tl
      {
        script   = \l_fontspec_script_tl ;
        language = \l_fontspec_lang_tl   ;
      }
    \fi
  }
  {
    mode     = \l_fontspec_mode_tl   ;
    \tl_if_empty:NF \l_fontspec_script_tl
    {
      script   = \l_fontspec_script_tl ;
      language = \l_fontspec_lang_tl   ;
    }
  }
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\zf@update@family}
% This macro is used to build up a complex family name based on its
% features.
%
% \cmd{\zf@firsttime} is set true in \cmd{\fontspec_select:nn} only the first
% time \cmd{zf@get@feature@requests} is called, so that the family
% name is only created once.
%    \begin{macrocode}
\newcommand*{\zf@update@family}[1]{
  \ifzf@firsttime
    \xdef\zf@family@long{\zf@family@long#1}
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Features}
%
% \begin{macro}{\fontspec_get_features:n}
%   This macro is a wrapper for |\setkeys| which expands and adds a
%   default specification to the original passed options. It begins by
%   initialising the commands used to hold font-feature specific
%   strings.
%    \begin{macrocode}
\cs_set:Npn \fontspec_get_features:n #1 {
  \let\l_fontspec_rawfeatures_sclist     \@empty
  \tl_clear:N \l_fontspec_scale_tl
  \tl_set_eq:NN \l_fontspec_opacity_tl \g_fontspec_opacity_tl
  \tl_set_eq:NN \l_fontspec_hexcol_tl \g_fontspec_hexcol_tl
  \let\zf@adjust \@empty
  \fontspec_setkeys:xx {options} {#1}
  \tl_if_empty:NF \XKV@rm {
    \fontspec_error:nx {unknown-options} { \exp_not:V \XKV@rm }
  }
%    \end{macrocode}
% Finish the colour specification:
%    \begin{macrocode}
  \zf@update@ff{color=\l_fontspec_hexcol_tl\l_fontspec_opacity_tl}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_init:}
% Initialisations that either need to occur globally:
% (all setting of these variables is done locally inside a group)
%    \begin{macrocode}
\tl_clear:N \zf@bf
\tl_clear:N \zf@it
\tl_clear:N \zf@fake@slant
\tl_clear:N \zf@fake@embolden
\tl_clear:N \zf@bfit
\tl_clear:N \zf@sl
\tl_clear:N \zf@bfsl
\tl_clear:N \zf@sc
\tl_clear:N \zf@up@feat
\tl_clear:N \zf@bf@feat
\tl_clear:N \zf@it@feat
\tl_clear:N \zf@bfit@feat
\tl_clear:N \zf@sl@feat
\tl_clear:N \zf@bfsl@feat
\tl_clear:N \zf@sc@feat
\tl_clear:N \l_fontspec_script_name_tl
\tl_clear:N \l_fontspec_script_tl
\tl_clear:N \l_fontspec_lang_name_tl
\tl_clear:N \l_fontspec_lang_tl
\clist_clear:N \l_fontspec_sizefeat_clist
\tl_new:Nn \g_fontspec_hexcol_tl {000000}
\tl_new:Nn \g_fontspec_opacity_tl {FF~}
%    \end{macrocode}
% Or once per fontspec font invocation:
% (Some of these may be redundant.
% Check whether they're assigned to globally or not.)
%    \begin{macrocode}
\newcommand*\fontspec_init:{
  \zf@icufalse
  \zf@firsttimetrue
  \xetex_or_luatex:nnn { \cs_set:Npn \fontspec_namewrap:n ##1 }
    { ##1 }
    { name:##1 }
  \tl_clear:N \l_fontspec_optical_size_tl
  \tl_clear:N \l_fontspec_renderer_tl
  \luatex_if_engine:T {
    \tl_set:Nn \l_fontspec_mode_tl {node}
    \luatexprehyphenchar   =`\-  % fixme
    \luatexposthyphenchar  = 0   % fixme
    \luatexpreexhyphenchar = 0   % fixme
    \luatexpostexhyphenchar= 0   % fixme
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zf@make@smallcaps}\label{mac:zf@make@smallcaps}
% This macro checks if the font contains small caps, and if so
% creates the string for accessing them in \cmd{\zf@smallcaps}.
%    \begin{macrocode}
\newcommand*\zf@make@smallcaps{
  \let\zf@smallcaps\@empty
  \xetex_or_luatex:nn
  {
    \ifzf@atsui
      \fontspec_make_AAT_feature_string:nn{3}{3}
      \unless\ifx\@tempa\@empty
        \edef\zf@smallcaps{\@tempa;}
      \fi
    \fi
    \ifzf@icu
      \fontspec_check_ot_feat:nT {+smcp} {\edef\zf@smallcaps{+smcp;}}
    \fi
  }
  {
    \fontspec_check_ot_feat:nT {+smcp} {\edef\zf@smallcaps{+smcp;}}
  }
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\sclist_put_right:Nn}
% I'm hardly going to write an `sclist' module but a couple of functions are
% necessary.
%    \begin{macrocode}
\cs_new:Npn \sclist_put_right:Nn #1#2 {
  \tl_if_empty:NTF #1 {
    \tl_set:Nn #1 {#2}
  }{
    \tl_put_right:Nn #1 {;#2}
  }
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\zf@update@ff}
% \cmd{\l_fontspec_rawfeatures_sclist} is the string used to define the list of specific
% font features. Each time another font feature is requested, this
% macro is used to add that feature to the list. Font features are
% separated by semicolons.
%    \begin{macrocode}
\newcommand*\zf@update@ff[1]{
  \unless\ifzf@firsttime
    \xdef\l_fontspec_rawfeatures_sclist{\l_fontspec_rawfeatures_sclist #1;}
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\fontspec_make_feature:nnn}
%   This macro is called by each feature key selected, and runs
%   according to which type of font is selected.
%    \begin{macrocode}
\cs_new:Npn \fontspec_make_feature:nnn #1#2#3 {
  \xetex_or_luatex:nn
  {
    \ifzf@atsui
      \fontspec_make_AAT_feature:nn {#1}{#2}
    \fi
    \ifzf@icu
      \fontspec_make_ICU_feature:n {#3}
    \fi
  }
  {
    \fontspec_make_ICU_feature:n {#3}
  }
}
\cs_generate_variant:Nn \fontspec_make_feature:nnn {nnx}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new:Npn \fontspec_make_AAT_feature:nn #1#2 {
  \tl_if_empty:nTF {#1}
  {
    \fontspec_warning:n {aat-feature-not-exist}
  }
  {
    \fontspec_make_AAT_feature_string:nn {#1}{#2}
    \ifx\@tempa\@empty
      \fontspec_warning:nx {aat-feature-not-exist-in-font} {#1,#2}
    \else
      \zf@update@family{+#1,#2}
      \zf@update@ff\@tempa
    \fi
  }
}
\cs_new:Npn \fontspec_make_ICU_feature:n #1 {
  \tl_if_empty:nTF {#1}
  {
    \fontspec_warning:n {icu-feature-not-exist}
  }
  {
    \fontspec_check_ot_feat:nTF {#1} {
      \zf@update@family{#1}
      \zf@update@ff{#1}
    }{
      \fontspec_warning:nx {icu-feature-not-exist-in-font} {#1}
    }
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zf@define@font@feature}
% \begin{macro}{\zf@define@feature@option}
% These macros are used in order to simplify font feature definition later on.
%    \begin{macrocode}
\newcommand*\zf@define@font@feature[1]{
  \define@key[zf]{options}{#1}{{\setkeys[zf@feat]{#1}{##1}}}
}
\newcommand*\zf@define@feature@option[5]{
  \define@key[zf@feat]{#1}{#2}[]{\fontspec_make_feature:nnn{#3}{#4}{#5}}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\keyval@alias@key}
% This macro maps one \pkg{xkeyval} key to another.
%    \begin{macrocode}
\newcommand*\keyval@alias@key[4][KV]{
  \cs_set_eq:cc{#1@#2@#4}{#1@#2@#3}
  \cs_set_eq:cc{#1@#2@#4@default}{#1@#2@#3@default}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\multi@alias@key}
% This macro iterates through families to map one key to another,
% regardless of which family it's contained within.
%    \begin{macrocode}
\newcommand*\multi@alias@key[2]{
  \key@ifundefined[zf]{options}{#1}
    {
      \key@ifundefined[zf]{preparse}{#1}
      {
        \key@ifundefined[zf]{preparse-external}{#1}
          { \fontspec_warning:nx {rename-feature-not-exist} {#1} }
          { \keyval@alias@key[zf]{preparse-external}{#1}{#2} }
      }
      { \keyval@alias@key[zf]{preparse}{#1}{#2} }
    }
    { \keyval@alias@key[zf]{options}{#1}{#2} }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_make_AAT_feature_string:nn}
%   This macro takes the numerical codes for a font feature and
%   creates a specified macro containing the string required in the
%   font definition to turn that feature on or off. Used primarily in
%   \cmd\zf@make@aat@feature, but also used to check if small caps
%   exists in the requested font (see page~\pageref{mac:zf@make@smallcaps}).
%
%    \begin{macrocode}
\cs_new:Npn \fontspec_make_AAT_feature_string:nn #1#2 {
  \edef\@tempa{\XeTeXfeaturename\zf@basefont #1}
  \unless\ifx\@tempa\@empty
%    \end{macrocode}
% For exclusive selectors, it's easy; just grab the string:
%    \begin{macrocode}
    \ifnum\XeTeXisexclusivefeature\zf@basefont #1>0
      \edef\@tempb{\XeTeXselectorname\zf@basefont #1\space #2}
%    \end{macrocode}
% For \emph{non}-exclusive selectors, it's a little more complex.
% If the selector is even, it corresponds to switching the feature on:
%    \begin{macrocode}
    \else
      \unless\ifodd #2
        \edef\@tempb{\XeTeXselectorname\zf@basefont #1\space #2}
%    \end{macrocode}
% If the selector is \emph{odd}, it corresponds to switching the feature off.
% But \XeTeX\ doesn't return a selector string for this number, since the
% feature is defined for the `switching on' value. So we need to check the
% selector of the previous number, and then prefix the feature string with |!|
% to denote the switch.
%    \begin{macrocode}
      \else
        \edef\@tempb{
          \XeTeXselectorname\zf@basefont #1\space \numexpr#2-1\relax
        }
        \unless\ifx\@tempb\@empty
          \edef\@tempb{!\@tempb}
        \fi
      \fi
    \fi
%    \end{macrocode}
% Finally, save out the complete feature string in \cmd\@tempa.
% If the selector doesn't exist, re-initialise the feature string to empty.
%    \begin{macrocode}
    \unless\ifx\@tempb\@empty
      \edef\@tempa{\@tempa=\@tempb}
    \else
      \let\@tempa\@empty
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_iv_str_to_num:n}
% \begin{macro}{\fontspec_v_str_to_num:n}
% This macro takes a four character string and converts it to the
% numerical representation required for \XeTeX\ OpenType script/language/feature
% purposes. The output is stored in \cmd\l_fontspec_strnum_int.
%
% The reason it's ugly is because the input can be of the form of any of these:
% `|abcd|', `|abc|', `|abc |', `|ab|', `|ab  |', \etc.
% (It is assumed the first two chars are \emph{always} not spaces.) So this macro
% reads in the string, delimited by a space; this input is padded with \cmd\@empty s
% and anything beyond four chars is snipped. The \cmd\@empty s then are used to reconstruct
% the spaces in the string to number calculation.
%
% The variant \cmd\fontspec_v_str_to_num:n\ is used when looking at features, which are passed around
% with prepended plus and minus signs (\eg, \texttt{+liga}, \texttt{-dlig}); it
% simply strips off the first char of the input before calling the normal \cmd\fontspec_iv_str_to_num:n.
%
% It's probable that all OpenType features \emph{are} in fact four characters long, but
% not impossible that they aren't. So I'll leave the less efficient parsing stage in there
% even though it's not strictly necessary for now.
%    \begin{macrocode}
\cs_set:Npn \fontspec_iv_str_to_num:n #1 {
  \fontspec_iv_str_to_num:w #1 \@empty \@empty \q_nil
}
\cs_set:Npn \fontspec_iv_str_to_num:w #1#2#3#4#5 \q_nil {
  \int_set:Nn \l_fontspec_strnum_int {
      `#1 * "1000000
    + `#2 * "10000
    + \ifx \@empty #3 32 \else `#3 \fi * "100
    + \ifx \@empty #4 32 \else `#4 \fi
  }
}
\cs_set:Npn \fontspec_v_str_to_num:n #1 {
  \bool_if:nTF
    {
      \tl_if_head_eq_charcode_p:nN {#1} {+} ||
      \tl_if_head_eq_charcode_p:nN {#1} {-}
    }
    {
      \exp_after:wN \fontspec_iv_str_to_num:n
      \exp_after:wN { \use_none:n #1 }
    }
    { \fontspec_iv_str_to_num:n {#1} }
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\fontspec_check_script:nTF}
% This macro takes an OpenType script tag and checks if it exists in the current
% font. The output boolean is \cmd\@tempswatrue. \cmd\l_fontspec_strnum_int\ is used to store
% the number corresponding to the script tag string.
%    \begin{macrocode}
\xetex_or_luatex:nnn {\prg_new_conditional:Nnn \fontspec_check_script:n {TF}}
  {
    \fontspec_iv_str_to_num:n{#1}
    \@tempcntb\XeTeXOTcountscripts\zf@basefont
    \c@zf@index\z@ \@tempswafalse
    \loop\ifnum\c@zf@index<\@tempcntb
      \ifnum\XeTeXOTscripttag\zf@basefont\c@zf@index=\l_fontspec_strnum_int
        \@tempswatrue
        \c@zf@index\@tempcntb
      \else
        \advance\c@zf@index\@ne
      \fi
    \repeat
    \if@tempswa \prg_return_true: \else: \prg_return_false: \fi:
  }
  {
    \directlua{fontspec.check_ot_script("zf@basefont", "#1")}
    \if@tempswa \prg_return_true: \else: \prg_return_false: \fi:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_check_lang:nTF}
% This macro takes an OpenType language tag and checks if it exists in the current
% font/script. The output boolean is \cmd\@tempswatrue. \cmd\l_fontspec_strnum_int\ is used to store
% the number corresponding to the language tag string.
% The script used is whatever's held in \cmd\c@zf@script. By default, that's the
% number corresponding to `|latn|'.
%    \begin{macrocode}
\xetex_or_luatex:nnn {\prg_new_conditional:Nnn \fontspec_check_lang:n {TF}}
  {
    \fontspec_iv_str_to_num:n{#1}
    \@tempcntb\XeTeXOTcountlanguages\zf@basefont\c@zf@script
    \c@zf@index\z@
    \@tempswafalse
    \loop\ifnum\c@zf@index<\@tempcntb
      \ifnum\XeTeXOTlanguagetag\zf@basefont\c@zf@script\c@zf@index=\l_fontspec_strnum_int
        \@tempswatrue
        \c@zf@index\@tempcntb
      \else
        \advance\c@zf@index\@ne
      \fi
    \repeat
    \if@tempswa \prg_return_true: \else: \prg_return_false: \fi:
  }
  {
    \directlua{
      fontspec.check_ot_lang( "zf@basefont", "#1", "\l_fontspec_script_tl" )
    }
    \if@tempswa \prg_return_true: \else: \prg_return_false: \fi:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_check_ot_feat:nTF}
% \begin{macro}{\fontspec_check_ot_feat:nT}
% This macro takes an OpenType feature tag and checks if it exists in the current
% font/script/language.
% The output boolean is \cmd\@tempswa. \cmd\l_fontspec_strnum_int\ is used to store
% the number corresponding to the feature tag string.
% The script used is whatever's held in \cmd\c@zf@script. By default, that's the
% number corresponding to `|latn|'. The language used is \cmd\c@zf@language,
% by default |0|, the `default language'.
%    \begin{macrocode}
\xetex_or_luatex:nnn
   { \prg_new_conditional:Nnn \fontspec_check_ot_feat:n {TF,T} }
   {
    \@tempcntb\XeTeXOTcountfeatures\zf@basefont\c@zf@script\c@zf@language
    \fontspec_v_str_to_num:n {#1}
    \c@zf@index\z@
    \@tempswafalse
    \loop\ifnum\c@zf@index<\@tempcntb
      \ifnum\XeTeXOTfeaturetag\zf@basefont\c@zf@script\c@zf@language
            \c@zf@index=\l_fontspec_strnum_int
        \@tempswatrue
        \c@zf@index\@tempcntb
      \else
        \advance\c@zf@index\@ne
      \fi
    \repeat
    \if@tempswa \prg_return_true: \else: \prg_return_false: \fi:
  }
  {
    \directlua{
      fontspec.check_ot_feat(
                              "zf@basefont", "#1",
                              "\l_fontspec_lang_tl", "\l_fontspec_script_tl"
                            )
    }
    \if@tempswa \prg_return_true: \else: \prg_return_false: \fi:
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{\pkg{keyval} definitions}
%
% This is the tedious section where we correlate all possible
% (eventually) font feature requests with their \XeTeX\ representations.
%
% \subsubsection{Pre-parsing naming information}
%
% These features are extracted from the font feature list before all others, using
% \pkg{xkeyval}'s \cmd\setkeys|*|.
%
% \paragraph{\feat{ExternalLocation}}
% For fonts that aren't installed in the system. If no argument is given, the font is located
% with |kpsewhich|; it's either in the current directory or the \TeX\ tree. Otherwise, the
% argument given defines the file path of the font.
%    \begin{macrocode}
\bool_new:N \l_fontspec_external_bool
\define@key[zf]{preparse-external}{ExternalLocation}[]{
  \zf@nobftrue
  \zf@noittrue
  \bool_set_true:N \l_fontspec_external_bool
  \xetex_or_luatex:nnn { \cs_gset:Npn \fontspec_namewrap:n ##1 }
    {     [ #1 ##1 ] }
    { file: #1 ##1   }
  \xetex_if_engine:T { \setkeys[zf]{preparse}{Renderer=ICU} }
}
\aliasfontfeature{ExternalLocation}{Path}
%    \end{macrocode}
%
% \paragraph{\feat{Extension}}
% For fonts that aren't installed in the system. Specifies the font extension
% to use.
%    \begin{macrocode}
\define@key[zf]{preparse-external}{Extension}{
  \tl_set:Nn \l_fontspec_extension_tl {#1}
  \bool_if:NF \l_fontspec_external_bool {
    \setkeys*[zf]{preparse-external}{ExternalLocation}
  }
}
\tl_clear:N \l_fontspec_extension_tl
%    \end{macrocode}
%
% \subsubsection{Pre-parsed features}
%
% After the font name(s) have been sorted out, now need to extract any
% renderer/font configuration features that need to be processed before
% all other font features.
%
% \paragraph{\feat{Renderer}}
% This feature must be processed before all others (the other font shape and features options are also pre-parsed for convenience) because the renderer determines the format of the features and even whether certain features are available.
%    \begin{macrocode}
\define@choicekey[zf]{preparse}{Renderer}[\l_tmpa_tl\l_tmpa_num]
    {AAT,ICU,Graphite,Full,Basic}{
  \zf@update@family{+rend:#1}
  \intexpr_compare:nTF {\l_tmpa_num < 3} {
    \xetex_or_luatex:nn
    {
      \tl_set:Nv \l_fontspec_renderer_tl {g_fontspec_renderer_tag_\l_tmpa_tl}
    }
    {
      \fontspec_warning:nx {only-xetex-feature} {Renderer=AAT/ICU/Graphite}
    }
  }{
    \xetex_or_luatex:nn
    { \fontspec_warning:nx {only-luatex-feature} {Renderer=Full/Basic} }
    { \tl_set:Nv \l_fontspec_mode_tl {g_fontspec_mode_tag_\l_tmpa_tl}  }
  }
}
\tl_set:cn {g_fontspec_renderer_tag_AAT} {/AAT}
\tl_set:cn {g_fontspec_renderer_tag_ICU} {/ICU}
\tl_set:cn {g_fontspec_renderer_tag_Graphite} {/GR}
\tl_set:cn {g_fontspec_mode_tag_Full}  {node}
\tl_set:cn {g_fontspec_mode_tag_Basic} {base}
%    \end{macrocode}
%
% \paragraph{OpenType script/language}
% See later for the resolutions from \pkg{fontspec} features to OpenType definitions.
%    \begin{macrocode}
\define@key[zf]{preparse}{Script}{
  \xetex_if_engine:T { \setkeys[zf]{preparse}{Renderer=ICU} }
  \tl_set:Nn \l_fontspec_script_name_tl {#1}
  \zf@update@family{+script:#1}
}
%    \end{macrocode}
% Exactly the same:
%    \begin{macrocode}
\define@key[zf]{preparse}{Language}{
  \xetex_if_engine:T { \setkeys[zf]{preparse}{Renderer=ICU} }
  \tl_set:Nn \l_fontspec_lang_name_tl {#1}
  \zf@update@family{+language:#1}
}
%    \end{macrocode}
%
% \subsubsection{Bold/italic choosing options}
%
% The \feat{Bold}, \feat{Italic}, and \feat{BoldItalic}
% features are for defining explicitly the bold and italic fonts used
% in a font family.
%
% \paragraph{Fonts}
% Upright:
%    \begin{macrocode}
\define@key[zf]{preparse-external}{UprightFont}{
  \fontspec_complete_fontname:Nn \zf@up {#1}
  \zf@update@family{up:#1}
}
%    \end{macrocode}
% Bold:
%    \begin{macrocode}
\define@key[zf]{preparse-external}{BoldFont}{
  \edef\@tempa{#1}
  \ifx\@tempa\@empty
    \zf@nobftrue
    \zf@update@family{nobf}
  \else
    \zf@nobffalse
    \fontspec_complete_fontname:Nn \zf@bf {#1}
    \zf@update@family{bf:#1}
  \fi
}
%    \end{macrocode}
% Same for italic:
%    \begin{macrocode}
\define@key[zf]{preparse-external}{ItalicFont}{
  \edef\@tempa{#1}
  \ifx\@tempa\@empty
    \zf@noittrue
    \zf@update@family{noit}
  \else
    \zf@noitfalse
    \fontspec_complete_fontname:Nn \zf@it {#1}
    \zf@update@family{it:#1}
  \fi
}
%    \end{macrocode}
% Simpler for bold+italic \& slanted:
%    \begin{macrocode}
\define@key[zf]{preparse-external}{BoldItalicFont}{
  \fontspec_complete_fontname:Nn \zf@bfit {#1}
  \zf@update@family{bfit:#1}
}
\define@key[zf]{preparse-external}{SlantedFont}{
  \fontspec_complete_fontname:Nn \zf@sl {#1}
  \zf@update@family{sl:#1}
}
\define@key[zf]{preparse-external}{BoldSlantedFont}{
  \fontspec_complete_fontname:Nn \zf@bfsl {#1}
  \zf@update@family{bfsl:#1}
}
%    \end{macrocode}
% Small caps isn't pre-parsed because it can vary with others above:
%    \begin{macrocode}
\define@key[zf]{options}{SmallCapsFont}{
  \edef\@tempa{#1}
  \ifx\@tempa\@empty
    \zf@nosctrue
    \zf@update@family{nosc}
  \else
    \zf@noscfalse
    \fontspec_complete_fontname:Nn \zf@sc {#1}
    \zf@update@family{sc:\zap@space #1~\@empty}
  \fi
}
%    \end{macrocode}
%
% \begin{macro}{\fontspec_complete_fontname:Nn}
% This macro defines |#1| as the input with any |*| tokens of its input
% replaced by the font name. This lets us define supplementary fonts in full
% (``\texttt{Baskerville Semibold}'') or in abbreviation (``\texttt{* Semibold}'').
%    \begin{macrocode}
\cs_set:Npn \fontspec_complete_fontname:Nn #1#2 {
  \tl_set:Nn #1 {#2}
  \tl_replace_all_in:Nnx #1 {*} {\zf@fontname}
}
\cs_generate_variant:Nn \tl_replace_all_in:Nnn {Nnx}
%    \end{macrocode}
% \end{macro}
%
% \paragraph{Features}
%    \begin{macrocode}
\define@key[zf]{preparse}{UprightFeatures}{
  \def\zf@up@feat{, #1}
  \zf@update@family{rmfeat:#1}
}
\define@key[zf]{preparse}{BoldFeatures}{
  \def\zf@bf@feat{, #1}
  \zf@update@family{bffeat:#1}
}
\define@key[zf]{preparse}{ItalicFeatures}{
  \def\zf@it@feat{, #1}
  \zf@update@family{itfeat:#1}
}
\define@key[zf]{preparse}{BoldItalicFeatures}{
  \def\zf@bfit@feat{, #1}
  \zf@update@family{bfitfeat:#1}
}
\define@key[zf]{preparse}{SlantedFeatures}{
  \def\zf@sl@feat{, #1}
  \zf@update@family{slfeat:#1}
}
\define@key[zf]{preparse}{BoldSlantedFeatures}{
  \def\zf@bfsl@feat{, #1}
  \zf@update@family{bfslfeat:#1}
}
%    \end{macrocode}
% Note that small caps features can vary by shape, so these in fact \emph{aren't} pre-parsed.
%    \begin{macrocode}
\define@key[zf]{options}{SmallCapsFeatures}{
  \unless\ifzf@firsttime\def\zf@sc@feat{, #1}\fi
  \zf@update@family{scfeat:\zap@space #1~\@empty}
}
%    \end{macrocode}
%
% paragraph{Features varying by size}
% TODO: sizezfeatures and italicfont (etc) don't play nice
%    \begin{macrocode}
\define@key[zf]{preparse}{SizeFeatures}{
  \tl_set:Nn \l_fontspec_sizefeat_clist {#1}
  \zf@update@family{sizefeat:\zap@space #1~\@empty}
}
%    \end{macrocode}
%
%    \begin{macrocode}
\define@key[zf]{sizing}{Size}{ \tl_set:Nn \l_fontspec_size_tl {#1} }
\define@key[zf]{sizing}{Font}{
  \fontspec_complete_fontname:Nn \l_fontspec_sizedfont_tl {#1}
}
%    \end{macrocode}
%
% \subsubsection{Font-independent features}
%
% These features can be applied to any font.
%
% \paragraph{Scale}
% If the input isn't one of the pre-defined string options, then
% it's gotta be numerical. \cs{fontspec_calc_scale:n} does all the work in
% the auto-scaling cases.
%    \begin{macrocode}
\define@key[zf]{options}{Scale}{
  \prg_case_str:nnn {#1}
  {
    {MatchLowercase} { \fontspec_calc_scale:n {5} }
    {MatchUppercase} { \fontspec_calc_scale:n {8} }
  }
  { \tl_set:Nx \l_fontspec_scale_tl {#1} }
  \zf@update@family{+scale:\l_fontspec_scale_tl}
  \tl_set:Nx \l_fontspec_scale_tl { s*[\l_fontspec_scale_tl] }
}
%    \end{macrocode}
%
% \begin{macro}{\fontspec_calc_scale:n}
% This macro calculates the amount of scaling between the default
% roman font and the (default shape of) the font being selected such
% that the font dimension that is input is equal for both. The only
% font dimensions that justify this are 5 (lowercase height)
% and 8 (uppercase height in \XeTeX).
%
% This script is executed for every extra shape, which seems wasteful,
% but allows alternate italic shapes from a separate font, say, to
% be loaded and to be auto-scaled correctly. Even if this would be ugly.
%    \begin{macrocode}
\cs_new:Npn \fontspec_calc_scale:n #1 {
  \group_begin:
    \rmfamily
    \fontspec_set_font_dimen:NnN \@tempdima {#1} \font
    \fontspec_set_font_dimen:NnN \@tempdimb {#1} \zf@basefont
    \dim_set:Nn \@tempdimc { 1pt*\@tempdima/\@tempdimb }
    \tl_gset:Nx \l_fontspec_scale_tl {\strip@pt\@tempdimc}
    \fontspec_info:n {set-scale}
  \group_end:
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_set_font_dimen:NnN}
% This function sets the dimension |#1| (for font |#3|) to `fontdimen' |#2|
% for either font dimension 5 (x-height) or 8 (cap-height). If, for some
% reason, these return an incorrect `zero' value (as \cs{fontdimen8} might
% for a \texttt{.tfm} font), then we cheat and measure the height of a glyph.
% We assume in this case that the font contains either an `X' or an `x'.
%    \begin{macrocode}
\cs_new:Npn \fontspec_set_font_dimen:NnN #1#2#3
{
  \dim_set:Nn #1 { \fontdimen #2 #3 }
  \dim_compare:nNnT #1 = {0pt} {
    \settoheight #1 {
      \tl_if_eq:nnTF {#3} {\font} \rmfamily #3
      \prg_case_int:nnn #2 {
        {5} {x} % x-height
        {8} {X} % cap-height
      } {?} % "else" clause; never reached.
    }
  }
}
%    \end{macrocode}
% \end{macro}
%
%
% \paragraph{Inter-word space}
% These options set the relevant \cmd\fontdimen s for the
% font being loaded.
%    \begin{macrocode}
\define@key[zf]{options}{WordSpace}{
  \zf@update@family{+wordspace:#1}
  \unless\ifzf@firsttime
    \zf@wordspace@parse#1,\zf@@ii,\zf@@iii,\zf@@
  \fi
}
%    \end{macrocode}
%
% \begin{macro}{\zf@wordspace@parse}
% This macro determines if the input to \feat{WordSpace} is
% of the form |{X}| or |{X,Y,Z}| and executes the font scaling.
% If the former input, it executes |{X,X,X}|.
%    \begin{macrocode}
\def\zf@wordspace@parse#1,#2,#3,#4\zf@@{
  \def\@tempa{#4}
  \ifx\@tempa\@empty
    \setlength\@tempdima{#1\fontdimen2\zf@basefont}
    \@tempdimb\@tempdima
    \@tempdimc\@tempdima
  \else
    \setlength\@tempdima{#1\fontdimen2\zf@basefont}
    \setlength\@tempdimb{#2\fontdimen3\zf@basefont}
    \setlength\@tempdimc{#3\fontdimen4\zf@basefont}
  \fi
  \edef\zf@adjust{
    \zf@adjust
    \fontdimen2\font\the\@tempdima
    \fontdimen3\font\the\@tempdimb
    \fontdimen4\font\the\@tempdimc
  }
}
%    \end{macrocode}
% \end{macro}
%
% \paragraph{Punctuation space}
% Scaling factor for the nominal \cmd\fontdimen \#7.
%    \begin{macrocode}
\define@key[zf]{options}{PunctuationSpace}{
  \zf@update@family{+punctspace:#1}
  \setlength\@tempdima{#1\fontdimen7\zf@basefont}
  \edef\zf@adjust{\zf@adjust\fontdimen7\font\the\@tempdima}
}
%    \end{macrocode}
%
% \paragraph{Letterspacing}
%    \begin{macrocode}
\define@key[zf]{options}{LetterSpace}{
  \zf@update@family{+tracking:#1}
  \zf@update@ff{letterspace=#1}
}
%    \end{macrocode}
%
% \paragraph{Hyphenation character}
% This feature takes one of three arguments: `\opt{None}',
% \meta{glyph}, or \meta{slot}. If the input isn't the first,
% and it's one character, then it's the second; otherwise, it's
% the third.
%    \begin{macrocode}
\define@key[zf]{options}{HyphenChar}{
  \zf@update@family{+hyphenchar:#1}
  \tl_if_eq:nnTF {#1} {None}
  {
    \tl_put_right:Nn \zf@adjust { \hyphenchar \font = \c_minus_one }
  }
  {
    \tl_if_single:nTF {#1}
      { \tl_set:Nn \l_fontspec_hyphenchar_tl {`#1} }
      { \tl_set:Nn \l_fontspec_hyphenchar_tl { #1} }
    \fontspec_glyph_if_exist:NnTF \zf@basefont {\l_fontspec_hyphenchar_tl}
    {
      \xetex_or_luatex:nnn { \tl_put_right:Nn \zf@adjust }
        { \hyphenchar \font = \l_fontspec_hyphenchar_tl \scan_stop: }
        {
          \hyphenchar \font = \c_zero
          \luatexprehyphenchar = \l_fontspec_hyphenchar_tl \scan_stop:
        }
    }
    { \fontspec_error:nx {no-glyph}{#1} }
  }
}
%    \end{macrocode}
%
% \paragraph{Color}
%    \begin{macrocode}
\define@key[zf]{options}{Color}{
  \zf@update@family{+col:#1}
  \cs_if_exist:cTF {\token_to_str:N\color@#1}
  {
    \convertcolorspec{named}{#1}{HTML}\l_fontspec_hexcol_tl
  }
  {
    \intexpr_compare:nTF { \tl_elt_count:n {#1} == 6 }
    { \tl_set:Nn \l_fontspec_hexcol_tl {#1} }
    {
      \intexpr_compare:nTF { \tl_elt_count:n {#1} == 8 }
      { \fontspec_parse_colour:viii #1 }
      {
        \ifzf@firsttime\else
          \fontspec_warning:nx {bad-colour} {#1}
        \fi
      }
    }
  }
}
\cs_set:Npn \fontspec_parse_colour:viii #1#2#3#4#5#6#7#8 {
  \tl_set:Nn \l_fontspec_hexcol_tl {#1#2#3#4#5#6}
  \tl_if_eq:NNF \l_fontspec_opacity_tl \g_fontspec_opacity_tl
   {
    \ifzf@firsttime\else
      \fontspec_warning:nx {opa-twice-col} {#7#8}
    \fi
   }
  \tl_set:Nn \l_fontspec_opacity_tl {#7#8}
}
\keyval@alias@key[zf]{options}{Color}{Colour}
%    \end{macrocode}
%    \begin{macrocode}
\newcounter{fontspec_tmp_int}
\define@key[zf]{options}{Opacity}{
  \zf@update@family{+opac:#1}
  \setcounter {fontspec_tmp_int} { 255*\real{#1} }
  \tl_if_eq:NNF \l_fontspec_opacity_tl \g_fontspec_opacity_tl
   {
    \ifzf@firsttime\else
      \fontspec_warning:nx {opa-twice} {#1}
    \fi
   }
  \tl_set:Nx \l_fontspec_opacity_tl
   { \nhex2 { \value{fontspec_tmp_int} } }
}
%    \end{macrocode}
%
%
% \paragraph{Mapping}
%    \begin{macrocode}
\xetex_or_luatex:nnn {
  \define@key[zf]{options}{Mapping}
}{
  \zf@update@family{+map:#1}
  \zf@update@ff{mapping=#1}
}{
  \tl_if_eq:nnTF {#1} {tex-text} {
    \fontspec_warning:n {no-mapping-ligtex}
    \msg_redirect_name:nnn {fontspec} {no-mapping-ligtex} {none}
    \setkeys[zf]{options}{ Ligatures=TeX }
  }{
    \fontspec_warning:n {no-mapping}
  }
}
%    \end{macrocode}
%
% \paragraph{FeatureFile}
%    \begin{macrocode}
\define@key[zf]{options}{FeatureFile}{
  \zf@update@family{+fea:#1}
  \zf@update@ff{featurefile=#1}
}
%    \end{macrocode}
%
%
% \subsubsection{Continuous font axes}
%
%    \begin{macrocode}
\define@key[zf]{options}{Weight}{
  \zf@update@family{+weight:#1}
  \zf@update@ff{weight=#1}
}
\define@key[zf]{options}{Width}{
  \zf@update@family{+width:#1}
  \zf@update@ff{width=#1}
}
\define@key[zf]{options}{OpticalSize}{
  \xetex_or_luatex:nn {
    \ifzf@icu
      \tl_set:Nn \l_fontspec_optical_size_tl {/ S = #1}
      \zf@update@family{+size:#1}
    \fi
    \ifzf@mm
      \zf@update@family{+size:#1}
      \zf@update@ff{optical size=#1}
    \fi
    \ifzf@icu\else
      \ifzf@mm\else
        \ifzf@firsttime
          \fontspec_warning:n {no-opticals}
        \fi
      \fi
    \fi
  }{
    \tl_set:Nn \l_fontspec_optical_size_tl {/ S = #1}
    \zf@update@family{+size:#1}
  }
}
%    \end{macrocode}
%
% \subsubsection{Font transformations}
% These are to be specified to apply directly to a font shape:
%    \begin{macrocode}
\define@key[zf]{options}{FakeSlant}[0.2]{
  \zf@update@family{+slant:#1}
  \zf@update@ff{slant=#1}
}
\define@key[zf]{options}{FakeStretch}[1.2]{
  \zf@update@family{+extend:#1}
  \zf@update@ff{extend=#1}
}
\define@key[zf]{options}{FakeBold}[1.5]{
  \zf@update@family{+embolden:#1}
  \zf@update@ff{embolden=#1}
}
%    \end{macrocode}
% These are to be given to a shape that has no real bold/italic
% to signal that \pkg{fontspec} should automatically create `fake' shapes.
%
% The behaviour is currently that only if both \opt{AutoFakeSlant} \emph{and}
% \opt{AutoFakeBold} are specified, the bold italic is also faked.
%
% These features presently \emph{override} real shapes found in the font;
% in the future I'd like these features to be ignored in this case, instead.
% (This is just a bit harder to program in the current design of
% \pkg{fontspec})
%    \begin{macrocode}
\define@key[zf]{options}{AutoFakeSlant}[0.2]{
  \ifzf@firsttime
    \tl_set:Nn \zf@fake@slant {#1}
    \tl_put_right:Nn \zf@it@feat {,FakeSlant=#1}
    \tl_set_eq:NN \zf@it \zf@fontname
    \zf@update@family{fakeit:#1}
    \tl_if_empty:NF \zf@fake@embolden {
      \tl_put_right:Nx \zf@bfit@feat
        {,FakeBold=\zf@fake@embolden,FakeSlant=#1}
      \tl_set_eq:NN \zf@bfit \zf@fontname
    }
  \fi
}
%    \end{macrocode}
% Same but reversed:
%    \begin{macrocode}
\define@key[zf]{options}{AutoFakeBold}[1.5]{
  \ifzf@firsttime
    \tl_set:Nn \zf@fake@embolden {#1}
    \tl_put_right:Nn \zf@bf@feat {,FakeBold=#1}
    \tl_set_eq:NN \zf@bf \zf@fontname
    \zf@update@family{fakebf:#1}
    \tl_if_empty:NF \zf@fake@slant {
      \tl_put_right:Nx \zf@bfit@feat
        {,FakeSlant=\zf@fake@slant,FakeBold=#1}
      \tl_set_eq:NN \zf@bfit \zf@fontname
    }
  \fi
}
%    \end{macrocode}
%
%
% \subsubsection{Ligatures}
% The call to the nested keyval family must be wrapped in braces to
% hide the parent list (this later requires the use of global
% definitions (|\xdef|) in |\zf@update@...|). Both \AAT\ and OpenType
% names are offered to chose |Rare|/|Discretionary| ligatures.
%    \begin{macrocode}
\zf@define@font@feature{Ligatures}
\zf@define@feature@option{Ligatures}{Required}       {1}{0}{+rlig}
\zf@define@feature@option{Ligatures}{NoRequired}     {1}{1}{-rlig}
\zf@define@feature@option{Ligatures}{Common}         {1}{2}{+liga}
\zf@define@feature@option{Ligatures}{NoCommon}       {1}{3}{-liga}
\zf@define@feature@option{Ligatures}{Rare}           {1}{4}{+dlig}
\zf@define@feature@option{Ligatures}{NoRare}         {1}{5}{-dlig}
\zf@define@feature@option{Ligatures}{Discretionary}  {1}{4}{+dlig}
\zf@define@feature@option{Ligatures}{NoDiscretionary}{1}{5}{-dlig}
\zf@define@feature@option{Ligatures}{Contextual}     {}{}  {+clig}
\zf@define@feature@option{Ligatures}{NoContextual}   {}{}  {-clig}
\zf@define@feature@option{Ligatures}{Historic}       {}{}  {+hlig}
\zf@define@feature@option{Ligatures}{NoHistoric}     {}{}  {-hlig}
\zf@define@feature@option{Ligatures}{Logos}          {1}{6} {}
\zf@define@feature@option{Ligatures}{NoLogos}        {1}{7} {}
\zf@define@feature@option{Ligatures}{Rebus}          {1}{8} {}
\zf@define@feature@option{Ligatures}{NoRebus}        {1}{9} {}
\zf@define@feature@option{Ligatures}{Diphthong}      {1}{10}{}
\zf@define@feature@option{Ligatures}{NoDiphthong}    {1}{11}{}
\zf@define@feature@option{Ligatures}{Squared}        {1}{12}{}
\zf@define@feature@option{Ligatures}{NoSquared}      {1}{13}{}
\zf@define@feature@option{Ligatures}{AbbrevSquared}  {1}{14}{}
\zf@define@feature@option{Ligatures}{NoAbbrevSquared}{1}{15}{}
\zf@define@feature@option{Ligatures}{Icelandic}      {1}{32}{}
\zf@define@feature@option{Ligatures}{NoIcelandic}    {1}{33}{}
%    \end{macrocode}
% Emulate CM extra ligatures.
%    \begin{macrocode}
\define@key[zf@feat]{Ligatures}{TeX}[]{
  \xetex_or_luatex:nn {
    \zf@update@family{+map:tex-text}
    \zf@update@ff{mapping=tex-text}
  }{
    \zf@update@family{+tlig+trep}
    \zf@update@ff{+tlig;+trep}
  }
}
%    \end{macrocode}
%
% \subsubsection{Letters}
%    \begin{macrocode}
\zf@define@font@feature{Letters}
\zf@define@feature@option{Letters}{Normal}             {3}{0}{}
\zf@define@feature@option{Letters}{Uppercase}          {3}{1}{+case}
\zf@define@feature@option{Letters}{Lowercase}          {3}{2}{}
\zf@define@feature@option{Letters}{SmallCaps}          {3}{3}{+smcp}
\zf@define@feature@option{Letters}{PetiteCaps}         {} {} {+pcap}
\zf@define@feature@option{Letters}{UppercaseSmallCaps} {} {} {+c2sc}
\zf@define@feature@option{Letters}{UppercasePetiteCaps}{} {} {+c2pc}
\zf@define@feature@option{Letters}{InitialCaps}        {3}{4}{}
\zf@define@feature@option{Letters}{Unicase}            {} {} {+unic}
%    \end{macrocode}
%
% \subsubsection{Numbers}
%
% These were originally separated into \feat{NumberCase} and
% \feat{NumberSpacing} following \AAT, but it makes more sense to
% combine them.
%
% Both naming conventions are offered to select the number case.
%
%    \begin{macrocode}
\zf@define@font@feature{Numbers}
\zf@define@feature@option{Numbers}{Monospaced}   {6} {0}{+tnum}
\zf@define@feature@option{Numbers}{Proportional} {6} {1}{+pnum}
\zf@define@feature@option{Numbers}{Lowercase}    {21}{0}{+onum}
\zf@define@feature@option{Numbers}{OldStyle}     {21}{0}{+onum}
\zf@define@feature@option{Numbers}{Uppercase}    {21}{1}{+lnum}
\zf@define@feature@option{Numbers}{Lining}       {21}{1}{+lnum}
\zf@define@feature@option{Numbers}{SlashedZero}  {14}{5}{+zero}
\zf@define@feature@option{Numbers}{NoSlashedZero}{14}{4}{-zero}
%    \end{macrocode}
%
% |luaotload| provides a custom |anum| feature for replacing Latin
% (AKA Arabic) numbers with Arabic (AKA Indic-Arabic). The same feature
% maps to Farsi (Persian) numbers if font language is Farsi.
%
%    \begin{macrocode}
\luatex_if_engine:T {
  \zf@define@feature@option{Numbers}{Arabic}{}{}{+anum}
}
%    \end{macrocode}
%
% \subsubsection{Contextuals}
%    \begin{macrocode}
\zf@define@font@feature  {Contextuals}
\zf@define@feature@option{Contextuals}{Swash}        {} {} {+cswh}
\zf@define@feature@option{Contextuals}{NoSwash}      {} {} {-cswh}
\zf@define@feature@option{Contextuals}{Alternate}    {} {} {+calt}
\zf@define@feature@option{Contextuals}{NoAlternate}  {} {} {-calt}
\zf@define@feature@option{Contextuals}{WordInitial}  {8}{0}{+init}
\zf@define@feature@option{Contextuals}{NoWordInitial}{8}{1}{-init}
\zf@define@feature@option{Contextuals}{WordFinal}    {8}{2}{+fina}
\zf@define@feature@option{Contextuals}{NoWordFinal}  {8}{3}{-fina}
\zf@define@feature@option{Contextuals}{LineInitial}  {8}{4}{}
\zf@define@feature@option{Contextuals}{NoLineInitial}{8}{5}{}
\zf@define@feature@option{Contextuals}{LineFinal}    {8}{6}{+falt}
\zf@define@feature@option{Contextuals}{NoLineFinal}  {8}{7}{-falt}
\zf@define@feature@option{Contextuals}{Inner}        {8}{8}{+medi}
\zf@define@feature@option{Contextuals}{NoInner}      {8}{9}{-medi}
%    \end{macrocode}
%
% \subsubsection{Diacritics}
%    \begin{macrocode}
\zf@define@font@feature{Diacritics}
\zf@define@feature@option{Diacritics}{Show}        {9}{0}{}
\zf@define@feature@option{Diacritics}{Hide}        {9}{1}{}
\zf@define@feature@option{Diacritics}{Decompose}   {9}{2}{}
\zf@define@feature@option{Diacritics}{MarkToBase}  {}{}{+mark}
\zf@define@feature@option{Diacritics}{NoMarkToBase}{}{}{-mark}
\zf@define@feature@option{Diacritics}{MarkToMark}  {}{}{+mkmk}
\zf@define@feature@option{Diacritics}{NoMarkToMark}{}{}{-mkmk}
\zf@define@feature@option{Diacritics}{AboveBase}   {}{}{+abvm}
\zf@define@feature@option{Diacritics}{NoAboveBase} {}{}{-abvm}
\zf@define@feature@option{Diacritics}{BelowBase}   {}{}{+blwm}
\zf@define@feature@option{Diacritics}{NoBelowBase} {}{}{-blwm}
%    \end{macrocode}
%
% \subsubsection{Kerning}
%    \begin{macrocode}
\zf@define@font@feature{Kerning}
\zf@define@feature@option{Kerning}{Uppercase}{}{}{+cpsp}
\zf@define@feature@option{Kerning}{On}       {}{}{+kern}
\zf@define@feature@option{Kerning}{Off}      {}{}{-kern}
%\zf@define@feature@option{Kerning}{Vertical}{}{}{+vkrn}
%\zf@define@feature@option{Kerning}
%    {VerticalAlternateProportional}{}{}{+vpal}
%\zf@define@feature@option{Kerning}{VerticalAlternateHalfWidth}{}{}{+vhal}
%    \end{macrocode}
%
% \subsubsection{Vertical position}
%    \begin{macrocode}
\zf@define@font@feature{VerticalPosition}
\zf@define@feature@option{VerticalPosition}{Normal}     {10}{0}{}
\zf@define@feature@option{VerticalPosition}{Superior}   {10}{1}{+sups}
\zf@define@feature@option{VerticalPosition}{Inferior}   {10}{2}{+subs}
\zf@define@feature@option{VerticalPosition}{Ordinal}    {10}{3}{+ordn}
\zf@define@feature@option{VerticalPosition}{Numerator}  {}  {} {+numr}
\zf@define@feature@option{VerticalPosition}{Denominator}{}  {} {+dnom}
\zf@define@feature@option{VerticalPosition}{ScientificInferior}{}{}{+sinf}
%    \end{macrocode}
%
% \subsubsection{Fractions}
%    \begin{macrocode}
\zf@define@font@feature{Fractions}
\zf@define@feature@option{Fractions}{On}       {11}{1}{+frac}
\zf@define@feature@option{Fractions}{Off}      {11}{0}{-frac}
\zf@define@feature@option{Fractions}{Diagonal} {11}{2}{}
\zf@define@feature@option{Fractions}{Alternate}{}  {} {+afrc}
%    \end{macrocode}
%
% \subsubsection{Alternates and variants}
% Selected numerically because they don't have standard names. Very
% easy to process, very annoying for the user!
%
%    \begin{macrocode}
\define@key[zf]{options}{Alternate}[0]{
  \clist_set_eq:NN \l_fontspec_tmpa_clist \XKV@rm
  \setkeys*[zf@feat]{Alternate}{#1}
  \unless\ifx\XKV@rm\@empty
    \def\XKV@tfam{Alternate}
    \fontspec_make_feature:nnx {17}{#1} { \fontspec_salt:n {#1} }
  \fi
  \clist_set_eq:NN \XKV@rm \l_fontspec_tmpa_clist
}
%    \end{macrocode}
%
%    \begin{macrocode}
\xetex_or_luatex:nnn { \cs_set:Npn \fontspec_salt:n #1 }
  {+salt=#1} { +salt= \intexpr_eval:n {#1+1} }
%    \end{macrocode}
%
%    \begin{macrocode}
\define@key[zf]{options}{Variant}{
  \clist_set_eq:NN \l_fontspec_tmpa_clist \XKV@rm
  \setkeys*[zf@feat]{Variant}{#1}
  \unless\ifx\XKV@rm\@empty
    \def\XKV@tfam{Variant}
    \fontspec_make_feature:nnx {18}{#1} { +ss \two@digits {#1} }
  \fi
  \clist_set_eq:NN \XKV@rm \l_fontspec_tmpa_clist
}
\aliasfontfeature{Variant}{StylisticSet}
%    \end{macrocode}
%
%    \begin{macrocode}
\define@key[zf]{options}{CharacterVariant}{
  \clist_set_eq:NN \l_fontspec_tmpa_clist \XKV@rm
  \setkeys*[zf@feat]{CharacterVariant}{#1}
  \unless\ifx\XKV@rm\@empty
    \def\XKV@tfam{CharacterVariant}
    \fontspec_make_feature:nnx {}{} { +cv \two@digits {#1} }
  \fi
  \clist_set_eq:NN \XKV@rm \l_fontspec_tmpa_clist
}
%    \end{macrocode}
%
% \subsubsection{Style}
%    \begin{macrocode}
\zf@define@font@feature{Style}
\zf@define@feature@option{Style}{Alternate}     {}  {} {+salt}
\zf@define@feature@option{Style}{Italic}        {32}{2}{+ital}
\zf@define@feature@option{Style}{Ruby}          {28}{2}{+ruby}
\zf@define@feature@option{Style}{Swash}         {}  {} {+swsh}
\zf@define@feature@option{Style}{Historic}      {}  {} {+hist}
\zf@define@feature@option{Style}{Display}       {19}{1}{}
\zf@define@feature@option{Style}{Engraved}      {19}{2}{}
\zf@define@feature@option{Style}{TitlingCaps}   {19}{4}{+titl}
\zf@define@feature@option{Style}{TallCaps}      {19}{5}{}
\zf@define@feature@option{Style}{HorizontalKana}{}  {} {+hkna}
\zf@define@feature@option{Style}{VerticalKana}  {}  {} {+vkna}
%    \end{macrocode}
%
% \subsubsection{CJK shape}
%    \begin{macrocode}
\zf@define@font@feature{CJKShape}
\zf@define@feature@option{CJKShape}{Traditional}{20}{0} {+trad}
\zf@define@feature@option{CJKShape}{Simplified} {20}{1} {+smpl}
\zf@define@feature@option{CJKShape}{JIS1978}    {20}{2} {+jp78}
\zf@define@feature@option{CJKShape}{JIS1983}    {20}{3} {+jp83}
\zf@define@feature@option{CJKShape}{JIS1990}    {20}{4} {+jp90}
\zf@define@feature@option{CJKShape}{Expert}     {20}{10}{+expt}
\zf@define@feature@option{CJKShape}{NLC}        {20}{13}{+nlck}
%    \end{macrocode}
%
% \subsubsection{Character width}
%    \begin{macrocode}
\zf@define@font@feature{CharacterWidth}
\zf@define@feature@option{CharacterWidth}{Proportional}{22}{0}{+pwid}
\zf@define@feature@option{CharacterWidth}{Full}{22}{1}{+fwid}
\zf@define@feature@option{CharacterWidth}{Half}{22}{2}{+hwid}
\zf@define@feature@option{CharacterWidth}{Third}{22}{3}{+twid}
\zf@define@feature@option{CharacterWidth}{Quarter}{22}{4}{+qwid}
\zf@define@feature@option{CharacterWidth}{AlternateProportional}{22}{5}{+palt}
\zf@define@feature@option{CharacterWidth}{AlternateHalf}{22}{6}{+halt}
\zf@define@feature@option{CharacterWidth}{Default}{22}{7}{}
%    \end{macrocode}
%
% \subsubsection{Annotation}
%    \begin{macrocode}
\zf@define@feature@option{Annotation}{Off}{24}{0}{}
\zf@define@feature@option{Annotation}{Box}{24}{1}{}
\zf@define@feature@option{Annotation}{RoundedBox}{24}{2}{}
\zf@define@feature@option{Annotation}{Circle}{24}{3}{}
\zf@define@feature@option{Annotation}{BlackCircle}{24}{4}{}
\zf@define@feature@option{Annotation}{Parenthesis}{24}{5}{}
\zf@define@feature@option{Annotation}{Period}{24}{6}{}
\zf@define@feature@option{Annotation}{RomanNumerals}{24}{7}{}
\zf@define@feature@option{Annotation}{Diamond}{24}{8}{}
\zf@define@feature@option{Annotation}{BlackSquare}{24}{9}{}
\zf@define@feature@option{Annotation}{BlackRoundSquare}{24}{10}{}
\zf@define@feature@option{Annotation}{DoubleCircle}{24}{11}{}
%    \end{macrocode}
%
%    \begin{macrocode}
\define@key[zf]{options}{Annotation}[0]{
  \clist_set_eq:NN \l_fontspec_tmpa_clist \XKV@rm
  \setkeys*[zf@feat]{Annotation}{#1}
  \unless\ifx\XKV@rm\@empty
    \def\XKV@tfam{Alternate}
    \fontspec_make_feature:nnx {}{} { \fontspec_nalt:n {#1} }
  \fi
  \clist_set_eq:NN \XKV@rm \l_fontspec_tmpa_clist
}
%    \end{macrocode}
%
%    \begin{macrocode}
\xetex_or_luatex:nnn { \cs_set:Npn \fontspec_nalt:n #1 }
  {+nalt=#1} { +nalt= \intexpr_eval:n {#1+1} }
%    \end{macrocode}
%
% \subsubsection{Vertical}
%    \begin{macrocode}
\zf@define@font@feature{Vertical}
\define@key[zf@feat]{Vertical}{RotatedGlyphs}[]{
  \ifzf@icu
    \fontspec_make_feature:nnn{}{}{+vrt2}
    \zf@update@family{+vert}
    \zf@update@ff{vertical}
  \else
    \zf@update@family{+vert}
    \zf@update@ff{vertical}
  \fi
}
%    \end{macrocode}
%
% \subsubsection{Script}
%    \begin{macrocode}
\newfontscript{Arabic}{arab}            \newfontscript{Armenian}{armn}
\newfontscript{Balinese}{bali}          \newfontscript{Bengali}{beng}
\newfontscript{Bopomofo}{bopo}          \newfontscript{Braille}{brai}
\newfontscript{Buginese}{bugi}          \newfontscript{Buhid}{buhd}
\newfontscript{Byzantine~Music}{byzm} \newfontscript{Canadian~Syllabics}{cans}
\newfontscript{Cherokee}{cher}
\newfontscript{CJK~Ideographic}{hani}   \newfontscript{Coptic}{copt}
\newfontscript{Cypriot~Syllabary}{cprt} \newfontscript{Cyrillic}{cyrl}
\newfontscript{Default}{DFLT}           \newfontscript{Deseret}{dsrt}
\newfontscript{Devanagari}{deva}        \newfontscript{Ethiopic}{ethi}
\newfontscript{Georgian}{geor}          \newfontscript{Glagolitic}{glag}
\newfontscript{Gothic}{goth}            \newfontscript{Greek}{grek}
\newfontscript{Gujarati}{gujr}          \newfontscript{Gurmukhi}{guru}
\newfontscript{Hangul~Jamo}{jamo}       \newfontscript{Hangul}{hang}
\newfontscript{Hanunoo}{hano}           \newfontscript{Hebrew}{hebr}
\newfontscript{Hiragana~and~Katakana}{kana}
\newfontscript{Javanese}{java}          \newfontscript{Kannada}{knda}
\newfontscript{Kharosthi}{khar}         \newfontscript{Khmer}{khmr}
\newfontscript{Lao}{lao~}               \newfontscript{Latin}{latn}
\newfontscript{Limbu}{limb}             \newfontscript{Linear~B}{linb}
\newfontscript{Malayalam}{mlym}         \newfontscript{Math}{math}
\newfontscript{Mongolian}{mong}
\newfontscript{Musical~Symbols}{musc}   \newfontscript{Myanmar}{mymr}
\newfontscript{N'ko}{nko~}              \newfontscript{Ogham}{ogam}
\newfontscript{Old~Italic}{ital}
\newfontscript{Old~Persian~Cuneiform}{xpeo}
\newfontscript{Oriya}{orya}             \newfontscript{Osmanya}{osma}
\newfontscript{Phags-pa}{phag}          \newfontscript{Phoenician}{phnx}
\newfontscript{Runic}{runr}             \newfontscript{Shavian}{shaw}
\newfontscript{Sinhala}{sinh}
\newfontscript{Sumero-Akkadian~Cuneiform}{xsux}
\newfontscript{Syloti~Nagri}{sylo}      \newfontscript{Syriac}{syrc}
\newfontscript{Tagalog}{tglg}           \newfontscript{Tagbanwa}{tagb}
\newfontscript{Tai~Le}{tale}            \newfontscript{Tai~Lu}{talu}
\newfontscript{Tamil}{taml}             \newfontscript{Telugu}{telu}
\newfontscript{Thaana}{thaa}            \newfontscript{Thai}{thai}
\newfontscript{Tibetan}{tibt}           \newfontscript{Tifinagh}{tfng}
\newfontscript{Ugaritic~Cuneiform}{ugar}\newfontscript{Yi}{yi~~}
%    \end{macrocode}
% For convenience:
%    \begin{macrocode}
\newfontscript{Kana}{kana}
\newfontscript{Maths}{math}
\newfontscript{CJK}{hani}
%    \end{macrocode}
%
% \subsubsection{Language}
%    \begin{macrocode}
\newfontlanguage{Abaza}{ABA}\newfontlanguage{Abkhazian}{ABK}
\newfontlanguage{Adyghe}{ADY}\newfontlanguage{Afrikaans}{AFK}
\newfontlanguage{Afar}{AFR}\newfontlanguage{Agaw}{AGW}
\newfontlanguage{Altai}{ALT}\newfontlanguage{Amharic}{AMH}
\newfontlanguage{Arabic}{ARA}\newfontlanguage{Aari}{ARI}
\newfontlanguage{Arakanese}{ARK}\newfontlanguage{Assamese}{ASM}
\newfontlanguage{Athapaskan}{ATH}\newfontlanguage{Avar}{AVR}
\newfontlanguage{Awadhi}{AWA}\newfontlanguage{Aymara}{AYM}
\newfontlanguage{Azeri}{AZE}\newfontlanguage{Badaga}{BAD}
\newfontlanguage{Baghelkhandi}{BAG}\newfontlanguage{Balkar}{BAL}
\newfontlanguage{Baule}{BAU}\newfontlanguage{Berber}{BBR}
\newfontlanguage{Bench}{BCH}\newfontlanguage{Bible~Cree}{BCR}
\newfontlanguage{Belarussian}{BEL}\newfontlanguage{Bemba}{BEM}
\newfontlanguage{Bengali}{BEN}\newfontlanguage{Bulgarian}{BGR}
\newfontlanguage{Bhili}{BHI}\newfontlanguage{Bhojpuri}{BHO}
\newfontlanguage{Bikol}{BIK}\newfontlanguage{Bilen}{BIL}
\newfontlanguage{Blackfoot}{BKF}\newfontlanguage{Balochi}{BLI}
\newfontlanguage{Balante}{BLN}\newfontlanguage{Balti}{BLT}
\newfontlanguage{Bambara}{BMB}\newfontlanguage{Bamileke}{BML}
\newfontlanguage{Breton}{BRE}\newfontlanguage{Brahui}{BRH}
\newfontlanguage{Braj~Bhasha}{BRI}\newfontlanguage{Burmese}{BRM}
\newfontlanguage{Bashkir}{BSH}\newfontlanguage{Beti}{BTI}
\newfontlanguage{Catalan}{CAT}\newfontlanguage{Cebuano}{CEB}
\newfontlanguage{Chechen}{CHE}\newfontlanguage{Chaha~Gurage}{CHG}
\newfontlanguage{Chattisgarhi}{CHH}\newfontlanguage{Chichewa}{CHI}
\newfontlanguage{Chukchi}{CHK}\newfontlanguage{Chipewyan}{CHP}
\newfontlanguage{Cherokee}{CHR}\newfontlanguage{Chuvash}{CHU}
\newfontlanguage{Comorian}{CMR}\newfontlanguage{Coptic}{COP}
\newfontlanguage{Cree}{CRE}\newfontlanguage{Carrier}{CRR}
\newfontlanguage{Crimean~Tatar}{CRT}\newfontlanguage{Church~Slavonic}{CSL}
\newfontlanguage{Czech}{CSY}\newfontlanguage{Danish}{DAN}
\newfontlanguage{Dargwa}{DAR}\newfontlanguage{Woods~Cree}{DCR}
\newfontlanguage{German}{DEU}
\newfontlanguage{Dogri}{DGR}\newfontlanguage{Divehi}{DIV}
\newfontlanguage{Djerma}{DJR}\newfontlanguage{Dangme}{DNG}
\newfontlanguage{Dinka}{DNK}\newfontlanguage{Dungan}{DUN}
\newfontlanguage{Dzongkha}{DZN}\newfontlanguage{Ebira}{EBI}
\newfontlanguage{Eastern~Cree}{ECR}\newfontlanguage{Edo}{EDO}
\newfontlanguage{Efik}{EFI}\newfontlanguage{Greek}{ELL}
\newfontlanguage{English}{ENG}\newfontlanguage{Erzya}{ERZ}
\newfontlanguage{Spanish}{ESP}\newfontlanguage{Estonian}{ETI}
\newfontlanguage{Basque}{EUQ}\newfontlanguage{Evenki}{EVK}
\newfontlanguage{Even}{EVN}\newfontlanguage{Ewe}{EWE}
\newfontlanguage{French~Antillean}{FAN}
\newfontlanguage{Farsi}{FAR}
\newfontlanguage{Parsi}{FAR}
\newfontlanguage{Persian}{FAR}
\newfontlanguage{Finnish}{FIN}\newfontlanguage{Fijian}{FJI}
\newfontlanguage{Flemish}{FLE}\newfontlanguage{Forest~Nenets}{FNE}
\newfontlanguage{Fon}{FON}\newfontlanguage{Faroese}{FOS}
\newfontlanguage{French}{FRA}\newfontlanguage{Frisian}{FRI}
\newfontlanguage{Friulian}{FRL}\newfontlanguage{Futa}{FTA}
\newfontlanguage{Fulani}{FUL}\newfontlanguage{Ga}{GAD}
\newfontlanguage{Gaelic}{GAE}\newfontlanguage{Gagauz}{GAG}
\newfontlanguage{Galician}{GAL}\newfontlanguage{Garshuni}{GAR}
\newfontlanguage{Garhwali}{GAW}\newfontlanguage{Ge'ez}{GEZ}
\newfontlanguage{Gilyak}{GIL}\newfontlanguage{Gumuz}{GMZ}
\newfontlanguage{Gondi}{GON}\newfontlanguage{Greenlandic}{GRN}
\newfontlanguage{Garo}{GRO}\newfontlanguage{Guarani}{GUA}
\newfontlanguage{Gujarati}{GUJ}\newfontlanguage{Haitian}{HAI}
\newfontlanguage{Halam}{HAL}\newfontlanguage{Harauti}{HAR}
\newfontlanguage{Hausa}{HAU}\newfontlanguage{Hawaiin}{HAW}
\newfontlanguage{Hammer-Banna}{HBN}\newfontlanguage{Hiligaynon}{HIL}
\newfontlanguage{Hindi}{HIN}\newfontlanguage{High~Mari}{HMA}
\newfontlanguage{Hindko}{HND}\newfontlanguage{Ho}{HO}
\newfontlanguage{Harari}{HRI}\newfontlanguage{Croatian}{HRV}
\newfontlanguage{Hungarian}{HUN}\newfontlanguage{Armenian}{HYE}
\newfontlanguage{Igbo}{IBO}\newfontlanguage{Ijo}{IJO}
\newfontlanguage{Ilokano}{ILO}\newfontlanguage{Indonesian}{IND}
\newfontlanguage{Ingush}{ING}\newfontlanguage{Inuktitut}{INU}
\newfontlanguage{Irish}{IRI}\newfontlanguage{Irish~Traditional}{IRT}
\newfontlanguage{Icelandic}{ISL}\newfontlanguage{Inari~Sami}{ISM}
\newfontlanguage{Italian}{ITA}\newfontlanguage{Hebrew}{IWR}
\newfontlanguage{Javanese}{JAV}\newfontlanguage{Yiddish}{JII}
\newfontlanguage{Japanese}{JAN}\newfontlanguage{Judezmo}{JUD}
\newfontlanguage{Jula}{JUL}\newfontlanguage{Kabardian}{KAB}
\newfontlanguage{Kachchi}{KAC}\newfontlanguage{Kalenjin}{KAL}
\newfontlanguage{Kannada}{KAN}\newfontlanguage{Karachay}{KAR}
\newfontlanguage{Georgian}{KAT}\newfontlanguage{Kazakh}{KAZ}
\newfontlanguage{Kebena}{KEB}\newfontlanguage{Khutsuri~Georgian}{KGE}
\newfontlanguage{Khakass}{KHA}\newfontlanguage{Khanty-Kazim}{KHK}
\newfontlanguage{Khmer}{KHM}\newfontlanguage{Khanty-Shurishkar}{KHS}
\newfontlanguage{Khanty-Vakhi}{KHV}\newfontlanguage{Khowar}{KHW}
\newfontlanguage{Kikuyu}{KIK}\newfontlanguage{Kirghiz}{KIR}
\newfontlanguage{Kisii}{KIS}\newfontlanguage{Kokni}{KKN}
\newfontlanguage{Kalmyk}{KLM}\newfontlanguage{Kamba}{KMB}
\newfontlanguage{Kumaoni}{KMN}\newfontlanguage{Komo}{KMO}
\newfontlanguage{Komso}{KMS}\newfontlanguage{Kanuri}{KNR}
\newfontlanguage{Kodagu}{KOD}\newfontlanguage{Korean~Old~Hangul}{KOH}
\newfontlanguage{Konkani}{KOK}\newfontlanguage{Kikongo}{KON}
\newfontlanguage{Komi-Permyak}{KOP}\newfontlanguage{Korean}{KOR}
\newfontlanguage{Komi-Zyrian}{KOZ}\newfontlanguage{Kpelle}{KPL}
\newfontlanguage{Krio}{KRI}\newfontlanguage{Karakalpak}{KRK}
\newfontlanguage{Karelian}{KRL}\newfontlanguage{Karaim}{KRM}
\newfontlanguage{Karen}{KRN}\newfontlanguage{Koorete}{KRT}
\newfontlanguage{Kashmiri}{KSH}\newfontlanguage{Khasi}{KSI}
\newfontlanguage{Kildin~Sami}{KSM}\newfontlanguage{Kui}{KUI}
\newfontlanguage{Kulvi}{KUL}\newfontlanguage{Kumyk}{KUM}
\newfontlanguage{Kurdish}{KUR}\newfontlanguage{Kurukh}{KUU}
\newfontlanguage{Kuy}{KUY}\newfontlanguage{Koryak}{KYK}
\newfontlanguage{Ladin}{LAD}\newfontlanguage{Lahuli}{LAH}
\newfontlanguage{Lak}{LAK}\newfontlanguage{Lambani}{LAM}
\newfontlanguage{Lao}{LAO}\newfontlanguage{Latin}{LAT}
\newfontlanguage{Laz}{LAZ}\newfontlanguage{L-Cree}{LCR}
\newfontlanguage{Ladakhi}{LDK}\newfontlanguage{Lezgi}{LEZ}
\newfontlanguage{Lingala}{LIN}\newfontlanguage{Low~Mari}{LMA}
\newfontlanguage{Limbu}{LMB}\newfontlanguage{Lomwe}{LMW}
\newfontlanguage{Lower~Sorbian}{LSB}\newfontlanguage{Lule~Sami}{LSM}
\newfontlanguage{Lithuanian}{LTH}\newfontlanguage{Luba}{LUB}
\newfontlanguage{Luganda}{LUG}\newfontlanguage{Luhya}{LUH}
\newfontlanguage{Luo}{LUO}\newfontlanguage{Latvian}{LVI}
\newfontlanguage{Majang}{MAJ}\newfontlanguage{Makua}{MAK}
\newfontlanguage{Malayalam~Traditional}{MAL}\newfontlanguage{Mansi}{MAN}
\newfontlanguage{Marathi}{MAR}\newfontlanguage{Marwari}{MAW}
\newfontlanguage{Mbundu}{MBN}\newfontlanguage{Manchu}{MCH}
\newfontlanguage{Moose~Cree}{MCR}\newfontlanguage{Mende}{MDE}
\newfontlanguage{Me'en}{MEN}\newfontlanguage{Mizo}{MIZ}
\newfontlanguage{Macedonian}{MKD}\newfontlanguage{Male}{MLE}
\newfontlanguage{Malagasy}{MLG}\newfontlanguage{Malinke}{MLN}
\newfontlanguage{Malayalam~Reformed}{MLR}\newfontlanguage{Malay}{MLY}
\newfontlanguage{Mandinka}{MND}\newfontlanguage{Mongolian}{MNG}
\newfontlanguage{Manipuri}{MNI}\newfontlanguage{Maninka}{MNK}
\newfontlanguage{Manx~Gaelic}{MNX}\newfontlanguage{Moksha}{MOK}
\newfontlanguage{Moldavian}{MOL}\newfontlanguage{Mon}{MON}
\newfontlanguage{Moroccan}{MOR}\newfontlanguage{Maori}{MRI}
\newfontlanguage{Maithili}{MTH}\newfontlanguage{Maltese}{MTS}
\newfontlanguage{Mundari}{MUN}\newfontlanguage{Naga-Assamese}{NAG}
\newfontlanguage{Nanai}{NAN}\newfontlanguage{Naskapi}{NAS}
\newfontlanguage{N-Cree}{NCR}\newfontlanguage{Ndebele}{NDB}
\newfontlanguage{Ndonga}{NDG}\newfontlanguage{Nepali}{NEP}
\newfontlanguage{Newari}{NEW}\newfontlanguage{Nagari}{NGR}
\newfontlanguage{Norway~House~Cree}{NHC}\newfontlanguage{Nisi}{NIS}
\newfontlanguage{Niuean}{NIU}\newfontlanguage{Nkole}{NKL}
\newfontlanguage{N'ko}{NKO}\newfontlanguage{Dutch}{NLD}
\newfontlanguage{Nogai}{NOG}\newfontlanguage{Norwegian}{NOR}
\newfontlanguage{Northern~Sami}{NSM}\newfontlanguage{Northern~Tai}{NTA}
\newfontlanguage{Esperanto}{NTO}\newfontlanguage{Nynorsk}{NYN}
\newfontlanguage{Oji-Cree}{OCR}\newfontlanguage{Ojibway}{OJB}
\newfontlanguage{Oriya}{ORI}\newfontlanguage{Oromo}{ORO}
\newfontlanguage{Ossetian}{OSS}\newfontlanguage{Palestinian~Aramaic}{PAA}
\newfontlanguage{Pali}{PAL}\newfontlanguage{Punjabi}{PAN}
\newfontlanguage{Palpa}{PAP}\newfontlanguage{Pashto}{PAS}
\newfontlanguage{Polytonic~Greek}{PGR}\newfontlanguage{Pilipino}{PIL}
\newfontlanguage{Palaung}{PLG}\newfontlanguage{Polish}{PLK}
\newfontlanguage{Provencal}{PRO}\newfontlanguage{Portuguese}{PTG}
\newfontlanguage{Chin}{QIN}\newfontlanguage{Rajasthani}{RAJ}
\newfontlanguage{R-Cree}{RCR}\newfontlanguage{Russian~Buriat}{RBU}
\newfontlanguage{Riang}{RIA}\newfontlanguage{Rhaeto-Romanic}{RMS}
\newfontlanguage{Romanian}{ROM}\newfontlanguage{Romany}{ROY}
\newfontlanguage{Rusyn}{RSY}\newfontlanguage{Ruanda}{RUA}
\newfontlanguage{Russian}{RUS}\newfontlanguage{Sadri}{SAD}
\newfontlanguage{Sanskrit}{SAN}\newfontlanguage{Santali}{SAT}
\newfontlanguage{Sayisi}{SAY}\newfontlanguage{Sekota}{SEK}
\newfontlanguage{Selkup}{SEL}\newfontlanguage{Sango}{SGO}
\newfontlanguage{Shan}{SHN}\newfontlanguage{Sibe}{SIB}
\newfontlanguage{Sidamo}{SID}\newfontlanguage{Silte~Gurage}{SIG}
\newfontlanguage{Skolt~Sami}{SKS}\newfontlanguage{Slovak}{SKY}
\newfontlanguage{Slavey}{SLA}\newfontlanguage{Slovenian}{SLV}
\newfontlanguage{Somali}{SML}\newfontlanguage{Samoan}{SMO}
\newfontlanguage{Sena}{SNA}\newfontlanguage{Sindhi}{SND}
\newfontlanguage{Sinhalese}{SNH}\newfontlanguage{Soninke}{SNK}
\newfontlanguage{Sodo~Gurage}{SOG}\newfontlanguage{Sotho}{SOT}
\newfontlanguage{Albanian}{SQI}\newfontlanguage{Serbian}{SRB}
\newfontlanguage{Saraiki}{SRK}\newfontlanguage{Serer}{SRR}
\newfontlanguage{South~Slavey}{SSL}\newfontlanguage{Southern~Sami}{SSM}
\newfontlanguage{Suri}{SUR}\newfontlanguage{Svan}{SVA}
\newfontlanguage{Swedish}{SVE}\newfontlanguage{Swadaya~Aramaic}{SWA}
\newfontlanguage{Swahili}{SWK}\newfontlanguage{Swazi}{SWZ}
\newfontlanguage{Sutu}{SXT}\newfontlanguage{Syriac}{SYR}
\newfontlanguage{Tabasaran}{TAB}\newfontlanguage{Tajiki}{TAJ}
\newfontlanguage{Tamil}{TAM}\newfontlanguage{Tatar}{TAT}
\newfontlanguage{TH-Cree}{TCR}\newfontlanguage{Telugu}{TEL}
\newfontlanguage{Tongan}{TGN}\newfontlanguage{Tigre}{TGR}
\newfontlanguage{Tigrinya}{TGY}\newfontlanguage{Thai}{THA}
\newfontlanguage{Tahitian}{THT}\newfontlanguage{Tibetan}{TIB}
\newfontlanguage{Turkmen}{TKM}\newfontlanguage{Temne}{TMN}
\newfontlanguage{Tswana}{TNA}\newfontlanguage{Tundra~Nenets}{TNE}
\newfontlanguage{Tonga}{TNG}\newfontlanguage{Todo}{TOD}
\newfontlanguage{Tsonga}{TSG}\newfontlanguage{Turoyo~Aramaic}{TUA}
\newfontlanguage{Tulu}{TUL}\newfontlanguage{Tuvin}{TUV}
\newfontlanguage{Twi}{TWI}\newfontlanguage{Udmurt}{UDM}
\newfontlanguage{Ukrainian}{UKR}\newfontlanguage{Urdu}{URD}
\newfontlanguage{Upper~Sorbian}{USB}\newfontlanguage{Uyghur}{UYG}
\newfontlanguage{Uzbek}{UZB}\newfontlanguage{Venda}{VEN}
\newfontlanguage{Vietnamese}{VIT}\newfontlanguage{Wa}{WA}
\newfontlanguage{Wagdi}{WAG}\newfontlanguage{West-Cree}{WCR}
\newfontlanguage{Welsh}{WEL}\newfontlanguage{Wolof}{WLF}
\newfontlanguage{Tai~Lue}{XBD}\newfontlanguage{Xhosa}{XHS}
\newfontlanguage{Yakut}{YAK}\newfontlanguage{Yoruba}{YBA}
\newfontlanguage{Y-Cree}{YCR}\newfontlanguage{Yi~Classic}{YIC}
\newfontlanguage{Yi~Modern}{YIM}\newfontlanguage{Chinese~Hong~Kong}{ZHH}
\newfontlanguage{Chinese~Phonetic}{ZHP}\newfontlanguage{Chinese~Simplified}{ZHS}
\newfontlanguage{Chinese~Traditional}{ZHT}\newfontlanguage{Zande}{ZND}
\newfontlanguage{Zulu}{ZUL}
%    \end{macrocode}
%
% \paragraph{Turkish} Turns out that many fonts use `TUR' as their Turkish language tag rather than the specified `TRK'. So we check for both:
%    \begin{macrocode}
\define@key[zf@feat]{Lang}{Turkish}[]{
  \fontspec_check_lang:nTF {TRK} {
    \c@zf@language\l_fontspec_strnum_int\relax
    \zf@update@family{+lang=Turkish}
    \tl_set:Nn \l_fontspec_lang_tl {TRK}
  }{
    \fontspec_check_lang:nTF {TUR} {
      \c@zf@language\l_fontspec_strnum_int\relax
      \zf@update@family{+lang=Turkish}
      \tl_set:Nn \l_fontspec_lang_tl {TUR}
    }{
      \fontspec_warning:nx {language-not-exist} {#1}
    }
  }
}
%    \end{macrocode}
%
% \paragraph{Default}
%
%    \begin{macrocode}
\define@key[zf@feat]{Lang}{Default}[]{
  \zf@update@family{+lang=dflt}
  \tl_set:Nn \l_fontspec_lang_tl {DFLT}
  \c@zf@language=0\relax
}
%    \end{macrocode}
%
% \subsubsection{Raw feature string}
% This allows savvy \XeTeX-ers to input font features manually if they have
% already memorised the OpenType abbreviations and don't mind not having error checking.
%    \begin{macrocode}
\define@key[zf]{options}{RawFeature}{
  \zf@update@family{+Raw:#1}
  \zf@update@ff{#1}
}
%    \end{macrocode}
%
%
%
% \subsection{Italic small caps} \label{sec:sishape}
% The following code for utilising italic small caps sensibly is
% inspired from Philip Lehman's \textit{The Font Installation
%   Guide}. Note that |\upshape| needs to be used \emph{twice} to get
% from italic small caps to regular upright (it always goes to small
% caps, then regular upright).
% \begin{macro}{\sishape}
% \begin{macro}{\textsi}
%     First, the commands for actually selecting italic small caps are
%     defined. I use |si| as the NFSS shape for italic small caps, but
%     I have seen |itsc| and |slsc| also used. |\sidefault| may be
%     redefined to one of these if required for compatibility.
%    \begin{macrocode}
\providecommand*{\sidefault}{si}
\DeclareRobustCommand{\sishape}{
  \not@math@alphabet\sishape\relax
  \fontshape\sidefault\selectfont
}
\DeclareTextFontCommand{\textsi}{\sishape}
%    \end{macrocode}
% \end{macro} \end{macro}
% \begin{macro}{\zf@merge@shape}
%   This is the macro which enables the overload on the |\..shape|
%   commands. It takes three such arguments. In essence, the macro
%   selects the first argument, unless the second argument is already
%   selected, in which case it selects the third.
%    \begin{macrocode}
\newcommand*{\zf@merge@shape}[3]{
  \edef\@tempa{#1}
  \edef\@tempb{#2}
  \ifx\f@shape\@tempb
    \ifcsname\f@encoding/\f@family/\f@series/#3\endcsname
      \edef\@tempa{#3}
    \fi
  \fi
  \fontshape{\@tempa}\selectfont
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\itshape} \begin{macro}{\scshape} \begin{macro}{\upshape}
%       Here the original |\..shape| commands are redefined to use the
%       merge shape macro.
%    \begin{macrocode}
\DeclareRobustCommand \itshape {
  \not@math@alphabet\itshape\mathit
  \zf@merge@shape\itdefault\scdefault\sidefault
}
\DeclareRobustCommand \slshape {
  \not@math@alphabet\slshape\relax
  \zf@merge@shape\sldefault\scdefault\sidefault
}
\DeclareRobustCommand \scshape {
  \not@math@alphabet\scshape\relax
  \zf@merge@shape\scdefault\itdefault\sidefault
}
\DeclareRobustCommand \upshape {
  \not@math@alphabet\upshape\relax
  \zf@merge@shape\updefault\sidefault\scdefault
}
%    \end{macrocode}
% \end{macro} \end{macro} \end{macro}
%
% \subsection{Selecting maths fonts}
% Here, the fonts used in math mode are redefined to correspond to the
% default roman, sans serif and typewriter fonts. Unfortunately, you
% can only define maths fonts in the preamble, otherwise I'd run this
% code whenever \cs{setmainfont} and friends was run.
%
% \begin{macro}{\zf@math}
% Everything here is performed \cs{AtBeginDocument} in order to
% overwrite \pkg{euler}'s attempt. This means \pkg{fontspec} must be
% loaded \emph{after} \pkg{euler}. We set up a conditional to return
% an error if this rule is violated.
%
% Since every maths setup is slightly different, we also take
% different paths for defining various math glyphs depending which
% maths font package has been loaded.
%
%    \begin{macrocode}
\@ifpackageloaded{euler}{\zf@package@euler@loadedtrue}
                        {\zf@package@euler@loadedfalse}
\def\zf@math{
  \let\zf@font@warning\@font@warning
  \let\@font@warning\@font@info
  \@ifpackageloaded{euler}{
    \ifzf@package@euler@loaded
      \zf@math@eulertrue
    \else
      \fontspec_error:n {euler-too-late}
    \fi
  }{}
  \@ifpackageloaded{lucbmath}{\zf@math@lucidatrue}{}
  \@ifpackageloaded{lucidabr}{\zf@math@lucidatrue}{}
  \@ifpackageloaded{lucimatx}{\zf@math@lucidatrue}{}
%    \end{macrocode}
% Knuth's CM fonts fonts are all squashed together, combining letters,
% accents, text symbols and maths symbols all in the one font,
% \texttt{cmr}, plus other things in other fonts. Because we are
% changing the roman font in the document, we need to redefine all of
% the maths glyphs in \LaTeX's \texttt{operators} maths font to still
% go back to the legacy \texttt{cmr} font for all these random glyphs,
% unless a separate maths font package has been loaded instead.
%
% In every case, the maths accents are always taken from the
% \texttt{operators} font, which is generally the main text
% font. (Actually, there is a \cmd\hat\ accent in
% \texttt{EulerFractur}, but it's \emph{ugly}. So I ignore it. Sorry
% if this causes inconvenience.)
%    \begin{macrocode}
  \DeclareSymbolFont{legacymaths}{OT1}{cmr}{m}{n}
  \SetSymbolFont{legacymaths}{bold}{OT1}{cmr}{bx}{n}
  \DeclareMathAccent{\acute}   {\mathalpha}{legacymaths}{19}
  \DeclareMathAccent{\grave}   {\mathalpha}{legacymaths}{18}
  \DeclareMathAccent{\ddot}    {\mathalpha}{legacymaths}{127}
  \DeclareMathAccent{\tilde}   {\mathalpha}{legacymaths}{126}
  \DeclareMathAccent{\bar}     {\mathalpha}{legacymaths}{22}
  \DeclareMathAccent{\breve}   {\mathalpha}{legacymaths}{21}
  \DeclareMathAccent{\check}   {\mathalpha}{legacymaths}{20}
  \DeclareMathAccent{\hat}     {\mathalpha}{legacymaths}{94} % too bad, euler
  \DeclareMathAccent{\dot}     {\mathalpha}{legacymaths}{95}
  \DeclareMathAccent{\mathring}{\mathalpha}{legacymaths}{23}
%    \end{macrocode}
% \paragraph{\cmd\colon: what's going on?} Okay, so \verb":" and \cmd\colon\ in maths mode are defined in a few places, so I need to work out what does what. Respectively, we have:
% \begin{Verbatim}
% % fontmath.ltx:
% \DeclareMathSymbol{\colon}{\mathpunct}{operators}{"3A}
% \DeclareMathSymbol{:}{\mathrel}{operators}{"3A}
%
% % amsmath.sty:
% \renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
%  \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}
%
% % euler.sty:
% \DeclareMathSymbol{:}\mathrel  {EulerFraktur}{"3A}
%
% % lucbmath.sty:
% \DeclareMathSymbol{\@tempb}{\mathpunct}{operators}{58}
% \ifx\colon\@tempb
%   \DeclareMathSymbol{\colon}{\mathpunct}{operators}{58}
% \fi
% \DeclareMathSymbol{:}{\mathrel}{operators}{58}
% \end{Verbatim}
% ($\mathrm{3A_{16}}=\mathrm{58_{10}}$) So I think, based on this summary, that it is fair to tell \pkg{fontspec} to `replace' the operators font with legacymaths for this symbol, except when \pkg{amsmath} is loaded since we want to keep its definition.
%
%
%    \begin{macrocode}
  \begingroup
    \mathchardef\@tempa="603A \relax
    \let\next\egroup
    \ifx\colon\@tempa
      \DeclareMathSymbol{\colon}{\mathpunct}{legacymaths}{58}
    \fi
  \endgroup
%    \end{macrocode}
% The following symbols are only defined specifically in \pkg{euler}, so skip them
% if that package is loaded.
%    \begin{macrocode}
  \ifzf@math@euler\else
    \DeclareMathSymbol{!}{\mathclose}{legacymaths}{33}
    \DeclareMathSymbol{:}{\mathrel}  {legacymaths}{58}
    \DeclareMathSymbol{;}{\mathpunct}{legacymaths}{59}
    \DeclareMathSymbol{?}{\mathclose}{legacymaths}{63}
%    \end{macrocode}
% And these ones are defined both in \pkg{euler} and \pkg{lucbmath},
% so we only need to run this code if no extra maths package has been
% loaded.
%    \begin{macrocode}
    \ifzf@math@lucida\else
      \DeclareMathSymbol{0}{\mathalpha}{legacymaths}{`0}
      \DeclareMathSymbol{1}{\mathalpha}{legacymaths}{`1}
      \DeclareMathSymbol{2}{\mathalpha}{legacymaths}{`2}
      \DeclareMathSymbol{3}{\mathalpha}{legacymaths}{`3}
      \DeclareMathSymbol{4}{\mathalpha}{legacymaths}{`4}
      \DeclareMathSymbol{5}{\mathalpha}{legacymaths}{`5}
      \DeclareMathSymbol{6}{\mathalpha}{legacymaths}{`6}
      \DeclareMathSymbol{7}{\mathalpha}{legacymaths}{`7}
      \DeclareMathSymbol{8}{\mathalpha}{legacymaths}{`8}
      \DeclareMathSymbol{9}{\mathalpha}{legacymaths}{`9}
      \DeclareMathSymbol{\Gamma}{\mathalpha}{legacymaths}{0}
      \DeclareMathSymbol{\Delta}{\mathalpha}{legacymaths}{1}
      \DeclareMathSymbol{\Theta}{\mathalpha}{legacymaths}{2}
      \DeclareMathSymbol{\Lambda}{\mathalpha}{legacymaths}{3}
      \DeclareMathSymbol{\Xi}{\mathalpha}{legacymaths}{4}
      \DeclareMathSymbol{\Pi}{\mathalpha}{legacymaths}{5}
      \DeclareMathSymbol{\Sigma}{\mathalpha}{legacymaths}{6}
      \DeclareMathSymbol{\Upsilon}{\mathalpha}{legacymaths}{7}
      \DeclareMathSymbol{\Phi}{\mathalpha}{legacymaths}{8}
      \DeclareMathSymbol{\Psi}{\mathalpha}{legacymaths}{9}
      \DeclareMathSymbol{\Omega}{\mathalpha}{legacymaths}{10}
      \DeclareMathSymbol{+}{\mathbin}{legacymaths}{43}
      \DeclareMathSymbol{=}{\mathrel}{legacymaths}{61}
      \DeclareMathDelimiter{(}{\mathopen} {legacymaths}{40}{largesymbols}{0}
      \DeclareMathDelimiter{)}{\mathclose}{legacymaths}{41}{largesymbols}{1}
      \DeclareMathDelimiter{[}{\mathopen} {legacymaths}{91}{largesymbols}{2}
      \DeclareMathDelimiter{]}{\mathclose}{legacymaths}{93}{largesymbols}{3}
      \DeclareMathDelimiter{/}{\mathord}{legacymaths}{47}{largesymbols}{14}
      \DeclareMathSymbol{\mathdollar}{\mathord}{legacymaths}{36}
    \fi
  \fi
%    \end{macrocode}
% Finally, we change the font definitions for \cmd\mathrm\ and so
% on. These are defined using the \cmd\zf@rmmaths\ (\dots) macros,
% which default to \cmd\rmdefault\ but may be specified with the
% \cmd\setmathrm\ (\dots) commands in the preamble.
%
% Since \LaTeX\ only generally defines one level of boldness, we omit
% \cmd\mathbf\ in the \textsf{bold} maths series. It can be specified
% as per usual with \cmd\setboldmathrm, which stores the appropriate
% family name in \cmd\zf@rmboldmaths.
%    \begin{macrocode}
  \DeclareSymbolFont{operators}\zf@enc\zf@rmmaths\mddefault\updefault
  \SetSymbolFont{operators}{normal}\zf@enc\zf@rmmaths\mddefault\updefault
  \SetMathAlphabet\mathrm{normal}\zf@enc\zf@rmmaths\mddefault\updefault
  \SetMathAlphabet\mathit{normal}\zf@enc\zf@rmmaths\mddefault\itdefault
  \SetMathAlphabet\mathbf{normal}\zf@enc\zf@rmmaths\bfdefault\updefault
  \SetMathAlphabet\mathsf{normal}\zf@enc\zf@sfmaths\mddefault\updefault
  \SetMathAlphabet\mathtt{normal}\zf@enc\zf@ttmaths\mddefault\updefault
  \SetSymbolFont{operators}{bold}\zf@enc\zf@rmmaths\bfdefault\updefault
  \ifdefined\zf@rmboldmaths
    \SetMathAlphabet\mathrm{bold}\zf@enc\zf@rmboldmaths\mddefault\updefault
    \SetMathAlphabet\mathbf{bold}\zf@enc\zf@rmboldmaths\bfdefault\updefault
    \SetMathAlphabet\mathit{bold}\zf@enc\zf@rmboldmaths\mddefault\itdefault
  \else
    \SetMathAlphabet\mathrm{bold}\zf@enc\zf@rmmaths\bfdefault\updefault
    \SetMathAlphabet\mathit{bold}\zf@enc\zf@rmmaths\bfdefault\itdefault
  \fi
  \SetMathAlphabet\mathsf{bold}\zf@enc\zf@sfmaths\bfdefault\updefault
  \SetMathAlphabet\mathtt{bold}\zf@enc\zf@ttmaths\bfdefault\updefault
  \let\font@warning\zf@font@warning}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zf@math@maybe}
% We're a little less sophisticated about not executing the \cmd\zf@maths\ macro if various other maths font packages are loaded. This list is based on the wonderful `\LaTeX Font Catalogue': \url{http://www.tug.dk/FontCatalogue/mathfonts.html}. I'm sure there are more I've missed. Do the \TeX\ Gyre fonts have maths support yet?
%
% Untested: would |\unless\ifnum\Gamma=28672\relax\@zf@mathfalse\fi| be a better test?
% This needs more cooperation with euler and lucida, I think.
%    \begin{macrocode}
\def\zf@math@maybe{
  \@ifpackageloaded{anttor}{
    \ifx\define@antt@mathversions a\@zf@mathfalse\fi}{}
  \@ifpackageloaded{arev}{\@zf@mathfalse}{}
  \@ifpackageloaded{eulervm}{\@zf@mathfalse}{}
  \@ifpackageloaded{mathdesign}{\@zf@mathfalse}{}
  \@ifpackageloaded{concmath}{\@zf@mathfalse}{}
  \@ifpackageloaded{cmbright}{\@zf@mathfalse}{}
  \@ifpackageloaded{mathesf}{\@zf@mathfalse}{}
  \@ifpackageloaded{gfsartemisia}{\@zf@mathfalse}{}
  \@ifpackageloaded{gfsneohellenic}{\@zf@mathfalse}{}
  \@ifpackageloaded{iwona}{
    \ifx\define@iwona@mathversions a\@zf@mathfalse\fi}{}
  \@ifpackageloaded{kpfonts}{\@zf@mathfalse}{}
  \@ifpackageloaded{kmath}{\@zf@mathfalse}{}
  \@ifpackageloaded{kurier}{
    \ifx\define@kurier@mathversions a\@zf@mathfalse\fi}{}
  \@ifpackageloaded{fouriernc}{\@zf@mathfalse}{}
  \@ifpackageloaded{fourier}{\@zf@mathfalse}{}
  \@ifpackageloaded{mathpazo}{\@zf@mathfalse}{}
  \@ifpackageloaded{mathptmx}{\@zf@mathfalse}{}
  \@ifpackageloaded{MinionPro}{\@zf@mathfalse}{}
  \@ifpackageloaded{unicode-math}{\@zf@mathfalse}{}
  \@ifpackageloaded{breqn}{\@zf@mathfalse}{}
  \if@zf@math
    \fontspec_info:n {setup-math}
    \zf@math
  \fi
}
\AtBeginDocument{\zf@math@maybe}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Finishing up}
% Now we just want to set up loading the \texttt{.cfg} file, if it exists.
%    \begin{macrocode}
\if@zf@configfile
  \InputIfFileExists{fontspec.cfg}
    {\typeout{fontspec.cfg~ loaded.}}
    {\typeout{No~ fontspec.cfg~ file~ found;~ no~ configuration~ loaded.}}
\fi
%    \end{macrocode}
%
% The end! Thanks for coming.
%
% \iffalse
%</fontspec>
%<*lua>
% \fi
%
% \clearpage
% \part{fontspec.lua}
%
% First we define some metadata.
%    \begin{macrocode}
fontspec          = { }

fontspec.module   = {
    name          = "fontspec",
    version       = 2.0,
    date          = "2009/12/04",
    description   = "Advanced font selection for LuaLaTeX.",
    author        = "Khaled Hosny",
    copyright     = "Khaled Hosny",
    license       = "LPPL"
}

luatexbase.provides_module(fontspec.module)

%    \end{macrocode}
% Some utility functions
%    \begin{macrocode}

utf = unicode.utf8

function fontspec.log    (...) luatexbase.module_log    (fontspec.module.name, string.format(...)) end
function fontspec.warning(...) luatexbase.module_warning(fontspec.module.name, string.format(...)) end
function fontspec.error  (...) luatexbase.module_error  (fontspec.module.name, string.format(...)) end

function fontspec.sprint (...) tex.sprint(luatexbase.catcodetables['latex-package'], ...) end

%    \end{macrocode}
% The following functions check for exsitence of certain script, language or
% feature in a given font.
%    \begin{macrocode}

local function check_script(id, script)
    local s = string.lower(script)
    if id and id > 0 then
        local otfdata = fonts.ids[id].shared.otfdata
        if otfdata then
            local features = otfdata.luatex.features
            for i,_ in pairs(features) do
                for j,_ in pairs(features[i]) do
                    if features[i][j][s] then
                        fontspec.log("script '%s' exists in font '%s'",
                                      script, fonts.ids[id].fullname)
                        return true
                    end
                end
            end
        end
    end
end

local function check_language(id, language, script)
    local s = string.lower(script)
    local l = string.lower(language)
    if id and id > 0 then
        local otfdata = fonts.ids[id].shared.otfdata
        if otfdata then
            local features = otfdata.luatex.features
            for i,_ in pairs(features) do
                for j,_ in pairs(features[i]) do
                    if features[i][j][s] and features[i][j][s][l] then
                        fontspec.log("language '%s' for script '%s' exists in font '%s'",
                                      language, script, fonts.ids[id].fullname)
                        return true
                    end
                end
            end
        end
    end
end

local function check_feature(id, feature, language, script)
    local s = string.lower(script)
    local l = string.lower(language)
    local f = string.lower(feature:gsub("^[+-]", ""))
    if id and id > 0 then
        local otfdata = fonts.ids[id].shared.otfdata
        if otfdata then
            local features = otfdata.luatex.features
            for i,_ in pairs(features) do
                if features[i][f] and features[i][f][s] then
                    if features[i][f][s][l] == true then
                        fontspec.log("feature '%s' for language '%s' and script '%s' exists in font '%s'",
                                      feature, language, script, fonts.ids[id].fullname)
                        return true
                    end
                end
            end
        end
    end
end

%    \end{macrocode}
% The following are the function that get called from \TeX\ end.
%    \begin{macrocode}

local function tempswatrue()  fontspec.sprint([[\@tempswatrue]])  end
local function tempswafalse() fontspec.sprint([[\@tempswafalse]]) end

function fontspec.check_ot_script(fnt, script)
    if check_script(font.id(fnt), script) then
        tempswatrue()
    else
        tempswafalse()
    end
end

function fontspec.check_ot_lang(fnt, lang, script)
    if check_language(font.id(fnt), lang, script) then
        tempswatrue()
    else
        tempswafalse()
    end
end

function fontspec.check_ot_feat(fnt, feat, lang, script)
    for _, f in ipairs { "+trep", "+tlig", "+anum" } do
        if feat == f then
            tempswatrue()
            return
        end
    end
    if check_feature(font.id(fnt), feat, lang, script) then
        tempswatrue()
    else
        tempswafalse()
    end
end

%    \end{macrocode}
%
% \iffalse
%</lua>
% \fi
%
% \clearpage
% \part{fontspec-patches.sty}
%
% \iffalse
%<*patches>
% \fi
%
%    \begin{macrocode}
\ExplSyntaxOn
%    \end{macrocode}
%
% \subsection{Unicode footnote symbols}
%    \begin{macrocode}
\RequirePackage{fixltx2e}[2006/03/24]
%    \end{macrocode}
% \subsection{Emph}
%
% \begin{macro}{\em}
% \begin{macro}{\emph}
% \begin{macro}{\emshape}
% \begin{macro}{\eminnershape}
% Redefinition of |{\em ...}| and |\emph{...}| to use \textsc{nfss} info to detect when the inner shape should be used.
%    \begin{macrocode}
\DeclareRobustCommand \em {
  \@nomath\em
  \tl_if_eq:xxTF \f@shape \itdefault \eminnershape
  {
    \tl_if_eq:xxTF \f@shape \sldefault \eminnershape \emshape
  }
}
\DeclareTextFontCommand{\emph}{\em}
\let\emshape\itshape
\let\eminnershape\upshape
%    \end{macrocode}
% \end{macro} \end{macro}
% \end{macro} \end{macro}
%
% \subsection{\cmd\-}
%
% \begin{macro}{\-}
% This macro is courtesy of Frank Mittelbach and the \LaTeXe\ source code.
%    \begin{macrocode}
\DeclareRobustCommand{\-}{%
  \discretionary{%
    \char\ifnum\hyphenchar\font<\z@
           \xlx@defaulthyphenchar
         \else
           \hyphenchar\font
         \fi}{}{}}
\def\xlx@defaulthyphenchar{`\-}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Verbatims}
%
% Many thanks to Apostolos Syropoulos for discovering this problem and writing the  redefinion of \LaTeX's |verbatim| environment and \cs{verb*} command.
%
% \begin{macro}{\fontspec_visible_space:}
% Print \unichar{2434}{Open box}, which is used to visibly display a space character.
%    \begin{macrocode}
\cs_new:Npn \fontspec_visible_space: {
  \fontspec_glyph_if_exist:NnTF \font {"2423}
    {\char"2423\relax}
    {\fontspec_visible_space_fallback:}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_visible_space:@fallback}
% If the current font doesn't have \unichar{2434}{Open box}, use Latin Modern Mono instead.
%    \begin{macrocode}
\cs_new:Npn \fontspec_visible_space_fallback: {
  {
    \usefont{EU1}{lmtt}{\f@series}{\f@shape}
    \textvisiblespace
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_print_visible_spaces:}
% Helper macro to turn spaces (\verb|^^20|) active and print visible space instead.
%    \begin{macrocode}
\group_begin:
\char_make_active:n{"20}%
\cs_gset:Npn\fontspec_print_visible_spaces:{%
\char_make_active:n{"20}%
\cs_set_eq:NN^^20\fontspec_visible_space:%
}%
\group_end:
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\verb}
% \begin{macro}{\verb*}
% Redefine \cmd\verb\ to use \cmd\fontspec_print_visible_spaces:.
%    \begin{macrocode}
\def\verb{
  \relax\ifmmode\hbox\else\leavevmode\null\fi
  \bgroup
    \verb@eol@error \let\do\@makeother \dospecials
    \verbatim@font\@noligs
    \@ifstar\@@sverb\@verb
}
\def\@@sverb{\fontspec_print_visible_spaces:\@sverb}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% It's better to put small things into \cmd\AtBeginDocument, so here we go:
%    \begin{macrocode}
\AtBeginDocument{
  \fontspec_patch_verbatim:
  \fontspec_patch_moreverb:
  \fontspec_patch_fancyvrb:
  \fontspec_patch_listings:
}
%    \end{macrocode}
%
% \begin{environment}{verbatim*}
% With the \pkg{verbatim} package.
%    \begin{macrocode}
\cs_set:Npn \fontspec_patch_verbatim: {
  \@ifpackageloaded{verbatim}{
    \cs_set:cpn {verbatim*} {
      \begingroup \@verbatim \fontspec_print_visible_spaces: \verbatim@start
    }
  }{
%    \end{macrocode}
% This is for vanilla \LaTeX.
%    \begin{macrocode}
    \cs_set:cpn {verbatim*} {
      \@verbatim \fontspec_print_visible_spaces: \@sxverbatim
    }
  }
}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{listingcont*}
% This is for \pkg{moreverb}.
% The main |listing*| environment inherits this definition.
%    \begin{macrocode}
\cs_set:Npn \fontspec_patch_moreverb: {
  \@ifpackageloaded{moreverb}{
    \cs_set:cpn {listingcont*} {
      \cs_set:Npn \verbatim@processline {
        \thelisting@line \global\advance\listing@line\c_one
        \the\verbatim@line\par
      }
      \@verbatim \fontspec_print_visible_spaces: \verbatim@start
    }
  }{}
}
%    \end{macrocode}
% \end{environment}
%
% \pkg{listings} and \pkg{fancvrb} make things nice and easy:
%    \begin{macrocode}
\cs_set:Npn \fontspec_patch_fancyvrb: {
  \@ifpackageloaded{fancyvrb}{
    \cs_set_eq:NN \FancyVerbSpace \fontspec_visible_space:
  }{}
}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set:Npn \fontspec_patch_listings: {
  \@ifpackageloaded{listings}{
    \cs_set_eq:NN \lst@visiblespace \fontspec_visible_space:
  }{}
}
%    \end{macrocode}
%
% \iffalse
%</patches>
% \fi
%
% \clearpage
% \part{fontspec.cfg}
%
% \iffalse
%<*cfg>
% \fi
%
%    \begin{macrocode}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% FOR BACKWARDS COMPATIBILITY WITH PREVIOUS VERSIONS %%%

% Please note that most of the entries here from fontspec v1.x are
% no longer present. Please advise of any serious problems this causes.

\aliasfontfeatureoption{Ligatures}{Historic}{Historical}
\let\newfontinstance\newfontfamily

%    \end{macrocode}
%
% \iffalse
%</cfg>
% \fi
%
% \clearpage
% \PrintChanges
%
% \clearpage
% \setcounter{IndexColumns}{2}
% \PrintIndex
%
% \Finale
%
% \iffalse
%<*example>
%
%    \begin{macrocode}
\documentclass{article}

\usepackage{fontspec}

\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\setsansfont[Ligatures=TeX,Scale=MatchLowercase]{TeX Gyre Heros}
\setmonofont[Scale=MatchLowercase]{Inconsolata}

\begin{document}
\pagestyle{empty}

\section*{The basics of the \textsf{fontspec} package}

The \textsf{fontspec} package enables automatic font selection
for \LaTeX{} documents typeset with Xe\TeX{} or \LuaTeX.
The basic command is

{\centering \verb|\fontspec[font features]{font display name}|.\par}

The default, sans serif, and typewriter fonts may be set with the
\verb|\setmainfont|, \verb|\setsansfont| and \verb|\setmonofont|
commands, respectively, as shown in the preamble. They take the
same syntax as the \verb|\fontspec| package. All expected font
shapes are available:

\begin{center}
  {\itshape Italics and \scshape small caps\dots}\\
  {\sffamily\bfseries Bold sans serif and \itshape bold italic sans serif\dots}
\end{center}

Text fonts in maths mode are also changed (e.g., notice the cosine function in
`$\cos(n\pi)=\pm 1$') but only if the roman and sans serif fonts are set in
the preamble; \verb|\setmainfont| will not affect these maths mode fonts when
called mid-document.
Maths symbols themselves are not affected.

Notice the font features used to load the default fonts in the preamble.
The first, \verb|Ligatures=TeX|, enables regular \TeX{} ligatures like
\verb|``---''| for ``---''.
The second, \verb|Scale=MatchLowercase|, automatically scales the fonts to
the same x-height.

Please see the complete \textsf{fontspec} documentation for further
information.

\end{document}
%    \end{macrocode}
%
%</example>
%<*testsuite>
%
%    \begin{macrocode}
\documentclass{article}
\usepackage{fontspec,fancyvrb,geometry,graphicx,calc,multicol}
\geometry{margin=2cm,a4paper}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\setmonofont{Consolas}

\newcommand\meta[1]{$\langle$\emph{#1}$\rangle$}

\newcommand\TEST[1]{%
  \section{Test #1}
  \begin{minipage}{0.5\textwidth}
  \VerbatimInput{testsuite/#1.ltx}
  \end{minipage}
  \hfill
  \begin{minipage}{8cm+4pt}
    \fboxsep=1pt
    \fboxrule=1pt
    \fbox{\includegraphics[width=8cm]{testsuite/#1.safe.pdf}}
  \end{minipage}
}

\newcommand\codeline[1]{\par{\centering#1\par}\par\noindent\ignorespaces}

\pagestyle{empty}
\begin{document}
\title{The \textsf{fontspec} test suite}
\author{Will Robertson}
\date{Compiled: \today}
\maketitle
\thispagestyle{empty}

\section*{Preamble}

\begin{multicols}{2}\noindent
The examples shown in the remainder of the document are generated directly from the code shown alongside.
As well as being good minimal examples, these tests are useful to ensure that changes to \textsf{fontspec} don't affect old behaviour.

When the test suite is run, the new output is compared pixel by pixel with that shown here and warnings produced if the outputs are not identical (within a small tolerance to account for rounding errors).

Tests with a name that begins with `\textit X' are processed with \texttt{xelatex} only; `\textit L' with \texttt{lualatex}; and `\textit F' with both.
In the latter case, the output from both engines is compared with each other, ensuring that the package is consistent cross-platform.

To generate tests yourself, write a new file in the \texttt{testsuite/} folder with filename
\codeline{\meta{F,L,X}\meta{num}\meta{letter}\texttt{.ltx}}
according to the naming scheme above and the following numbering scheme. If you are writing a new test entirely, increment the \meta{num}; if you are writing a variation on an old test, increment the \meta{letter}. No need to be too fussy, though.

After writing the new test, run
\codeline{\texttt{make initest}}
This will generate the reference output (\texttt{*.safe.pdf}) from which to check all future tests.
After any changes have been made to \textsf{fontspec}, the entire test suite is compiled with \codeline{\texttt{make check}}
If you want to run just a single test, use
\codeline{\texttt{make }\meta{testname}}
(but this syntax \emph{may} be fragile and need to be changed in the future).
\end{multicols}

\input{testsuite/testsuite-listing.tex}

\end{document}
%    \end{macrocode}
%</testsuite>
%
%<*doc-style>
%    \begin{macrocode}
\ProvidesPackage{fontspec-style}

\usepackage{booktabs,calc,caption,color,enumitem,fancyvrb,hologo,graphicx,ifthen,url,varioref,varwidth,microtype,tocloft}

% ToC formatting:
\setlength\cftsubsecnumwidth{1.4\cftsubsecnumwidth}
\def\@cfttocstart{\begin{multicols}{2}}
\def\@cfttocfinish{\end{multicols}}

\fvset{gobble=2}

\captionsetup[table]{position=above}
\captionsetup[figure]{position=above}

\newcommand\XeTeX{\hologo{XeTeX}}
\newcommand\XeLaTeX{\hologo{XeLaTeX}}
\newcommand\LuaTeX{\hologo{LuaTeX}}
\newcommand\LuaLaTeX{\hologo{LuaLaTeX}}
\usepackage{tgpagella,eulervm}
\usepackage{inconsolata}
\usepackage[
  bookmarks=true,
  colorlinks=true,
  linkcolor=niceblue,
  urlcolor=niceblue,
  citecolor=niceblue,
  pdftitle={The fontspec package},
  pdfsubject={Advanced font selection for XeLaTeX/LuaLaTeX},
  pdfauthor={Will Robertson},
  pdfkeywords={xetex, xelatex, luatex, lualatex, unicode, opentype, aat}
  ]{hyperref}

%% ToC
\def\@dotsep{1000}
\setcounter{tocdepth}{2}
\setlength\columnseprule{0.4pt}
\renewcommand\tableofcontents{\relax
  \begin{multicols}{2}[\section*{\contentsname}]\relax
    \@starttoc{toc}\relax
  \end{multicols}}

%% Index
\setcounter{IndexColumns}{2}
\renewenvironment{theglossary}
  {\small\list{}{}
     \item\relax
     \glossary@prologue\GlossaryParms
     \let\item\@idxitem \ignorespaces
     \def\pfill{\hspace*{\fill}}}
  {\endlist}

%% varioref definitions:
\labelformat{table}{Table~#1}
\labelformat{section}{Section~#1}
\labelformat{subsection}{Section~#1}

\definecolor{niceblue}{rgb}{0.1,0.2,0.8}

\newsavebox\X
\newsavebox\Y

\newcounter{example}

\newcommand\exref[1]{Example~\ref{ex:#1}}
\newcommand\Exref[1]{Example~\ref{ex:#1}}

\newenvironment{Xexample}[3][]
  {\VerbatimEnvironment\begin{Fexample}[#1]{#2}{#3}{X}}
  {\end{Fexample}}

\newenvironment{Lexample}[3][]
  {\VerbatimEnvironment\begin{Fexample}[#1]{#2}{#3}{L}}
  {\end{Fexample}}



\newenvironment{Fexample}[4][]
  {%
    \def\options{#1}%
    \def\filename{#2}%
    \def\captiontext{#3}%
    \def\prefix{#4}
    \refstepcounter{example}%
    \label{ex:\filename}%
    \IfFileExists{doc/\theexample-\prefix-\filename.tex}{}{%
      \immediate\write18{cd doc && rm \theexample-* ;}%
    }%
    \VerbatimEnvironment
    \begin{VerbatimOut}{doc/\theexample-\prefix-\filename.tex}}
% text in the environment
  {\end{VerbatimOut}
    \begin{figure}
      \setlength\parindent{0pt}%
      \edef\@tempa{[gobble=0,fontsize=\noexpand\small,\options]}%
      \savebox\X{%
                  \expandafter\BVerbatimInput
                  \@tempa{doc/\theexample-\prefix-\filename.tex}%
                }%
      \IfFileExists{doc/\theexample-\prefix-\filename.pdf}{}
         {%
           \edef\1{%
             cd doc; \csname prog@\prefix\endcsname
             "%
             \unexpanded{%
               \documentclass{article}%
               \usepackage{booktabs,ifthen,graphicx,xcolor,varwidth}
               \usepackage[active,tightpage]{preview}%
               \usepackage{fontspec}%
               \defaultfontfeatures{Ligatures=TeX} \begin{document}\begin{preview}\begin{varwidth}{0.7\linewidth}\input} \theexample-\prefix-\filename.tex
             \unexpanded{\end{varwidth}\end{preview}\end{document}}
             "
           }%
           \immediate\write18{
              mkdir -p doc;
              cp -a fontspec.dtx doc/;
              cd doc;
              tex fontspec.dtx > /dev/null ;
           }
           \immediate\write18{\unexpanded\expandafter{\1}}%
         }%
      \savebox\Y{%
      \IfFileExists{doc/\theexample-\prefix-\filename.pdf}
          {\includegraphics{doc/\theexample-\prefix-\filename.pdf}}
          {Graphic not generated.}%
      }
      % TYPESETTING
      \rule[0.5\baselineskip]{\columnwidth}{1pt}%
      \vspace{-1.2ex}%
      \def\@tempa{\small\textsf{Example~\theexample:~}}%
      \settowidth\@tempdima{\@tempa\captiontext}%
      \par
      \ifdim\@tempdima>\linewidth
        \settowidth\@tempdima{\@tempa}%
        \@tempa\parbox[t]{\linewidth-\@tempdima}{\small\captiontext}%
        \vspace{0.4\baselineskip}%
      \else
        \parbox{\linewidth}{\centering\@tempa~\captiontext}%
      \fi
      \par\rule[0.4\baselineskip]{\columnwidth}{0.4pt}\par
      \ifdim\dimexpr\wd\X+\wd\Y>\linewidth\relax
        \null\hfill\makebox[0pt][r]{\usebox\Y}\usebox\X
      \else
        \hfill\usebox\Y\hfill\usebox\X
      \fi
      \par\rule[0.5\baselineskip]{\columnwidth}{1pt}
    \end{figure}
}

\def\prog@X{xelatex
               -output-driver=xdv2pdf\space
               -jobname=\theexample-X-\filename\space}

\def\prog@L{lualatex
               -jobname=\theexample-L-\filename\space}

%%%%%%%%%%%%%%%%%%%%%%

\newcommand*\setexsize[1]{\let\examplesize#1}
\newcommand*\setverbwidth[1]{\def\auxwidth{#1}}

%% Various labelling commands:
\newcommand*\name[1]{{#1}}
\newcommand*\pkg[1]{\textsf{#1}}
\newcommand*\opt[1]{\texttt{#1}}
\newcommand*\feat[1]{\texttt{#1}}

\let\latin\textit
\def\eg{\latin{e.g.}}
\def\ie{\latin{i.e.}}
\def\Eg{\latin{E.g.}}
\def\Ie{\latin{I.e.}}
\def\etc{\@ifnextchar.{\latin{etc}}{\latin{etc.}\@}}

\newcommand\note[1]{\unskip\footnote{#1}}

\def\MacOSX{Mac~OS~X}
\def\AAT{\textsc{aat}}
\def\ATSUI{\textsc{atsui}}
\def\ICU{\textsc{icu}}
\def\LuaTeX{L\kern-0.08emu\kern-0.03ema\kern-0.12em\TeX}

%% (La)TeX font-related declarations:
\linespread{1.05}      % Pagella needs more space between lines
\frenchspacing         % Remove ugly extra space after punctuation

\makeatletter
\newcounter{argument}
\g@addto@macro\endmacro{\setcounter{argument}{0}}
\newcommand*\darg[1]{%
  \stepcounter{argument}%
  \noindent{\ttfamily\char`\#\theargument~:~}#1\par}
\newcommand*\doarg[1]{%
  \stepcounter{argument}%
  \noindent{\ttfamily\makebox[0pt][r]{[}\char`\#\theargument]:~}#1\par}
\makeatother

\newcommand\unichar[2]{\textsc{\MakeLowercase{u+#1: #2}}}

\newcommand\cmdbox[1]{%
  \smallskip\par\noindent
  \fbox{\begin{varwidth}{\linewidth}
    #1%
  \end{varwidth}}%
  \smallskip
}
\def\CMD#1{\texttt{\null#1\unskip}}

\usepackage{xparse}
\NewDocumentCommand \otf {somm} {%
  \IfBooleanTF #1
  {%
    \gdef\NOTE{\par\smallskip {$\ast$ \footnotesize This feature is activated by default.}}%
    \IfNoValueTF {#2} {\gdef\offname{No#3}}{\gdef\offname{#2}}%
    \featname&#3&$\ast$&\texttt{#4}\\
    \featname&\offname&&\texttt{#4}~~{\footnotesize(\textit{deactivate})}\\
  }
  {\featname&#3&&\texttt{#4}\\}%
}
\newenvironment{features}[1]{%
  \def\NOTE{}
  \def\thisfeatname{#1}%
  \def\featname{\thisfeatname~~\texttt=~~\null\gdef\featname{}}%
  \begin{table}
    \caption{Options for the OpenType font feature `\thisfeatname'.}
    \edef\@tempa{\noexpand\label{feat:\thisfeatname}}\@tempa
    \centering
    \begin{tabular}{@{}l@{}l@{\hspace{0.5\tabcolsep}}l@{\hspace{0.5\tabcolsep}}l@{}}
    \toprule
    Feature & Option && Tag \\
    \midrule
}{
    \bottomrule
    \end{tabular}
    \NOTE
  \end{table}
}

%%%%%%%%%%%

\def \MakePrivateLetters {%
  \catcode `\@ = 11
  \catcode `\_ = 11
  \catcode `\: = 11
}

%% for LaTeX3 csnames
\catcode `\_= 11

\renewcommand\partname{Part}

%    \end{macrocode}
%</doc-style>
% \fi
\endinput