summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/typeface/typeface.sty
blob: 3a4ae254d7311ffcf1e0f5acfbed6e6c2c71407a (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
% $Id: typeface.sty 904 2012-06-16 13:32:38Z Geoffrey $
%
% typeface.sty Copyright (C) 2012 Geoffrey Jones
%
% This package (typeface.sty and optional configuration file, typeface.cfg)
% simplifies setting up rmdefault, sfdefault, ttdefault, symbols and math type1
% format (postscript) fonts. It is designed to allow users the widest latitude
% in mixing and matching whatever combination they might desire from these.
%
% Recommendations:
%  1. Compile with pdflatex or variants like lualatex for best results
%     (although since fontspec is a mainstay in lua, you might prefer to
%     stick with that package -- see lualatex-doc in your installation or
%     from internet download). Some type1 fonts do not render properly in
%     pdfxelatex compiled documents. Compiling to dvi rather
%     than directly to pdf can prove an `interesting' idea.
%
% Requires:
%  1. Requires e-TeX.
%  2. Ensure that microtype is already loaded if (and only if) text figures
%     substitute font letter spacing is desired (advanced usage). However,
%     note that microtype generally doesn't partner well with bitmap fonts,
%     especially if any scaling is involved. Should you select bitmap fonts
%     (concrete, cmbright, etc.), microtype will very likely throw "auto
%     expansion is only possible with scalable fonts" errors. Bottom line:
%     either avoid bitmap fonts (for example, install hfbright to configure
%     a type1 variant of cmbright), or avoid microtype.
%
% Restrictions:
%  1. This package is most suited to pdfLaTeX, and not particularly to
%     other TeX formats where, in any event, it would be swimming against
%     their particular tides. However, it has been demonstrated to work
%     (depending on your definition of `work') in LuaTeX and in more
%     restricted circumstances under XeTeX. If using XeTeX, the
%     fontspec package would make far and away the better choice.
%
% Programming conventions:
%  1. All commands in this package begin with `\tf@', `\TF@', usw. As far
%     as I know, of all the usual packages, classes, etc., only LaTeX's
%     math text size macro (\tf@size) and table files (`\tf@EXT' where EXT
%     is toc, lof, lot, etc) co-claim this namespace.
%  2. \TF@XXX is a constant (of sorts, since users can redefine many of these).
%  3. \TF@Xxx overrides standard mixed-case commands, e.g., \TF@PackageInfo
%     wrappers \PackageInfo.
%  4. Many internal commands can be overridden by pre-defining them in the
%     package configuration file (\TF@CONFIGFILE, usually `typeface.cfg').
%  5. \tf@@xxx commands are, if not strictly local to a command, volatile
%     across the scope of this package.
%
% This work may be distributed and/or modified under the conditions of the
% LaTeX Project Public License, either version 1.3 of this license or (at
% your option) any later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt and version 1.3 or later is part of
% all distributions of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Original Author of this work is Geoffrey Jones.
% The Current Maintainer of this work is Geoffrey Jones.
% =============================================================================
\NeedsTeXFormat{LaTeX2e}[2009/09/24]

\newcommand*\TF@PACKAGENAME{typeface}
\newcommand*\TF@CONFIGFILE{\TF@PACKAGENAME.cfg}
\xdef\TF@CONFIGFILE{\TF@CONFIGFILE}

\ProvidesPackage{\TF@PACKAGENAME}
  [2012/06/11 (prerelease) Type1 font load management pkg (GJ)]

\RequirePackage{ifetex}
\NeedsETeX

\RequirePackage{etexcmds}  % renames e-tex \unexpanded to \etex@unexpanded
\RequirePackage{etoolbox}  % used extensively throughout this package
\RequirePackage{ifthenx}   % ifthen package plus extensions

\RequirePackage{iftex}                                                         % TODO: have we properly incorporated this?
\RequirePackage{ifpdf}

% Package-wide constants
%-----------------------
% User-reconfigurable constants
\providecommand*\TF@AUXFILENAME{\jobname.tf}

% Defaults used whenever the user either 1) does not explicitly define a
% typeface option or 2) explicitly specifies `default' (or whatever
% \TF@DEFAULT happens to be). Users can specify site specific defaults
% by including statements like:
%   \renewcommand*\TF@DEFAULTRMFONT{kpfonts:veryoldstyle:light}, or
%   \renewcommand*\TF@DEFAULTFONTENCODING{T5}
% in their configuration file \TF@CONFIGFILE. See the bundled configuration
% file for further examples.
\newcommand*\TF@DEFAULT{default}          % this pair should almost
\newcommand*\TF@DEFAULTPRINTNAME{Default} % certainly never be redefined!

\newcommand*\TF@DONTLOAD{dontload}        % generally synonyms
\newcommand*\TF@IGNORE{ignore}

\newcommand*\TF@DEFAULTRMFONT{\TF@DEFAULT}
\newcommand*\TF@DEFAULTSFFONT{\TF@DEFAULT}
\newcommand*\TF@DEFAULTTTFONT{\TF@DEFAULT}
\newcommand*\TF@DEFAULTMATHFONT{\TF@DEFAULT}
\newcommand*\TF@DEFAULTSYMBOLSFONT{\TF@DEFAULT}
\newcommand*\TF@DEFAULTTEXTFIGURESFONT{\TF@DEFAULT}

\newcommand*\TF@DEFAULTFONTENCODING{T1}
\newcommand*\TF@DEFAULTINPUTENCODING{utf8}
\newcommand*\TF@DEFAULTTEXTCOMP{full}
\newcommand*\TF@DEFAULTCMAP{resetfonts}

\newcommand*\TF@DEBUG@COLOUR@TS{purple}
\newcommand*\TF@DEBUG@COLOUR@SC{magenta}
\newcommand*\TF@DEBUG@COLOUR@JF{green}
\newcommand*\TF@DEBUG@COLOUR@XF{red}
\newcommand*\TF@DEBUG@COLOUR@LININGNUMS{olive}
\newcommand*\TF@DEBUG@COLOUR@RM{Indigo}
\newcommand*\TF@DEBUG@COLOUR@SF{Maroon}
\newcommand*\TF@DEBUG@COLOUR@TT{Green}
\newcommand*\TF@DEBUG@COLOUR@MATH{ProcessBlue}
\newcommand*\TF@DEBUG@COLOUR@XFNAME{\TF@DEBUG@COLOUR@XF}

% Non-reconfigurable constants -- see after aux file load,
% below, for especially constant constants.

% Package-wide variables and pre-initialised commands
%----------------------------------------------------
% Global macros -- stubs created here, code populated further below
\newcommand*\tf@fontencodingchoices{}    % package option choice lists are
\newcommand*\tf@inputencodingchoices{}   % initially empty; they are configured
\newcommand*\tf@textcompchoices{}        % below, or via configuration file
\newcommand*\tf@cmapchoices{}            % \TF@CONFIGFILE
\newcommand*\tf@rmtypefacechoices{}
\newcommand*\tf@sftypefacechoices{}
\newcommand*\tf@tttypefacechoices{}
\newcommand*\tf@mathtypefacechoices{}
\newcommand*\tf@symbolstypefacechoices{}
\newcommand*\tf@textfigurestypefacechoices{}

\newcommand*\tf@loadrmtypeface{}         % created here, populated by
\newcommand*\tf@loadsftypeface{}         % expansions of \newtypeface font
\newcommand*\tf@loadtttypeface{}         % definitions below and in user
\newcommand*\tf@loadmathtypeface{}       % customisation file \TF@CONFIGFILE
\newcommand*\tf@loadsymbolstypeface{}
\newcommand*\tf@loadtextfigurestypeface{}

\newcommand*\tf@rmdefault{\rmdefault}
\newcommand*\tf@sfdefault{\sfdefault}
\newcommand*\tf@ttdefault{\ttdefault}

\newcommand*\tf@rationalisefontnames{}   % typeface aliases management command
\newcommand*\tf@empty@sfcnt@hook{}       % empty font size function hook

% Volatiles
\newcommand*\tf@@listseparator{}         % for lists constructed on the fly

% Helper commands (heaps of them)
% ===============================

% Info messaging commands
%------------------------
\newcommand*\TF@PackageInfo[2][\TF@PACKAGENAME]{%
  \PackageInfo{#1}{#2}%
}

\newcommand*\TF@PackageInfoNoLine[2][\TF@PACKAGENAME]{%
  \PackageInfo{#1}{#2\@gobble}%
}

\newcommand*\TF@PackageDebugInfo[2][\TF@PACKAGENAME]{%
  \ifbool{tf@debug}{\TF@PackageInfo[#1]{#2}}{}%
}

\newcommand*\TF@PackageDebugInfoNoLine[2][\TF@PACKAGENAME]{%
  \ifbool{tf@debug}{\TF@PackageInfoNoLine[#1]{#2}}{}%
}

\newcommand*\TF@PackageWarning[2][\TF@PACKAGENAME]{%
  \PackageWarning{#1}{#2}%
}

\newcommand*\TF@PackageWarningNoLine[2][\TF@PACKAGENAME]{%
  \PackageWarningNoLine{#1}{#2}%
}

\newcommand*\TF@PackageError[3][\TF@PACKAGENAME]{%
  \PackageError{#1}{#2}{#3}%
}

\newcommand*\TF@ChoiceOptionError[2]{%
  \PackageError{\TF@PACKAGENAME}{Unexpected option `#1=#2' ignored}{}%
}

% etoolbox command wrappers
%--------------------------
\newcommand\tf@patchcmd[3]{
  \patchcmd{#1}{#2}{#3}
    {\TF@PackageInfo{Patched \string #1}}
    {\TF@PackageError{Failed to patch \string #1}{}}
}

\newcommand*\tf@newbool[2]{\newbool{#1}\setbool{#1}{#2}}

% globally undefine each command in a list of commands
\newcommand*\tf@undefinecommands[1]{\forcsvlist{\tf@undefinecommand}{#1}}
\newcommand*\tf@undefinecommand[1]{\global\undef{#1}}

% \usepackage wrapper command for (and only for) loading font packages
% in \newtypeface commands (below and in extension file \TF@CONFIGFILE)
%----------------------------------------------------------------------
\newcommand*\tf@usefontpackage[2][]{%
  \@ifpackageloaded{#2}{
    % Note that we often pre-pass options to packages using
    % \PassOptionsToPackage. Thus, we can't just test for
    % empty options ([#1]==[]) and proceed if so. Given that,
    % we stop in all cases of the target package already being
    % loaded.
    \TF@PackageWarningNoLine{%
      Package `#2' is already loaded. You should\MessageBreak
      probably sort this out before  proceeding. Did\MessageBreak
      you load `#2' before this package? Do you\MessageBreak
      need to revise your `fontloadorder' suboptions?\MessageBreak
      What would you like to do?}
  }{
    \TF@PackageDebugInfo{\string\usepackage[#1]{#2}}
    \usepackage[#1]{#2}
  }
}

% A few little throwaway helpers
%-------------------------------
% Discard all but the six leftmost characters of a string
\def\tf@strleftvi#1{%
  \expandafter\tf@@strleftvi#1\@empty\@empty\@empty\@empty\@empty\@empty\@nil%
}
\def\tf@@strleftvi#1#2#3#4#5#6#7\@nil{#1#2#3#4#5#6}

% Round up the provided floating point number and truncate to, at most,
% six characters (including minus sign and/or decimal point)
\def\tf@roundvi#1{%
  \edef\tf@@temp{\strip@pt\dimexpr#1pt+0.00005pt\relax}%
  \expandafter\tf@strleftvi\expandafter{\tf@@temp000000}%
}

\def\tf@roundvi@pt#1{%
  \edef\tf@@temp{\strip@pt\dimexpr#1+0.00005pt\relax}%
  \expandafter\tf@strleftvi\expandafter{\tf@@temp000000}pt%
}

% Colon-separated value list commands
%------------------------------------
% Helper test: \tf@ifsuboption tests whether item #1 is a member of
% colon-separated list #2. #2 will generally be \tf@XXfontoptions, where
% XX is one of rm, sf, tt, math, symbols or textfigures. Example usage:
%   \tf@ifsuboption{light}{\tf@sffontoptions}{<true part>}{<false part>}
% The list item immediately following #1 is saved in \tf@nextsuboption.
\tf@newbool{tf@suboptionfound}{false}
\newcommand*\tf@nextsuboption{}
\DeclareListParser{\tf@doColonSeparatedList}{:}  % refer etoolbox package

\newcommand*\tf@ifsuboption[2]{%
  % #1 item name, #2 item list
  % side effects: 1) sets boolean tf@suboptionfound,
  %               2) sets \tf@nextsuboption to next suboption in #2
  \edef\tf@suboption{#1}%
  \xdef\tf@nextsuboption{}%
  \boolfalse{tf@suboptionfound}%
  \renewcommand*\do[1]{%
    \ifbool{tf@suboptionfound}%
      {\xdef\tf@nextsuboption{##1}\listbreak}{}%
    \ifthenelse{\equal{\tf@suboption}{##1}}%
      {\booltrue{tf@suboptionfound}}{}%
  }%
  \expandafter\tf@doColonSeparatedList\expandafter{#2}%
  \ifbool{tf@suboptionfound}%
    {\expandafter\@firstoftwo}%
    {\expandafter\@secondoftwo}%
}

% Replace first #1 (to-be-replaced item) with #2 (new item) in #3 (item list)
% (Note, no parm safety checking or messaging on failure.)
\newcommand*\tf@replacesuboption[3]{%
  \edef\tf@originallist{#3}
  \patchcmd{#3}{#1}{#2}{%
    \TF@PackageDebugInfo{Replaced item `\string#1' with item `\string#2'
                         in list [\tf@originallist]}%
  }{}%
}

% Count the number of times item appears in the colon-separated item list
\newcounter{tf@suboptioncount}
\newcommand*\tf@suboptioncount[2]{%
  % #1 item name
  % #2 item list
  % side effect: sets counter tf@suboptioncount
  \setcounter{tf@suboptioncount}{0}%
  \renewcommand*\do[1]{%
    \ifthenelse{\equal{#1}{##1}}{\stepcounter{tf@suboptioncount}}{}%
  }%
  \expandafter\tf@doColonSeparatedList\expandafter{#2}%
}

% Count the number of non-empty items in the colon-separated item list
\newcommand*\tf@suboptionitemscount[1]{%
  % #1 item list
  % side effect: sets counter tf@suboptioncount
  \setcounter{tf@suboptioncount}{0}%
  \renewcommand*\do[1]{\stepcounter{tf@suboptioncount}}%
  \expandafter\tf@doColonSeparatedList\expandafter{#1}%
}

% Auxiliary file management
% =========================
\newcommand*\tf@initialise@auxfile{%
  \@ifundefined{tf@@auxfilehandle}{%
    \newwrite\tf@@auxfilehandle%
    \tf@newbool{tf@auxfileopen}{false}%
    \ifbool{@filesw}{%
      \TF@PackageDebugInfoNoLine{Opening auxiliary file \TF@AUXFILENAME..}%
      \immediate\openout\tf@@auxfilehandle=\TF@AUXFILENAME%
      \booltrue{tf@auxfileopen}%
    }{%
      \TF@PackageWarningNoLine{Auxiliary file output disabled,\MessageBreak
                               `\TF@AUXFILENAME' not written}%
    }%
  }{}%
}

\newcommand*\tf@writeauxfile[1]{
  \AtBeginDocument{%
    \ifbool{@filesw}{%
      \tf@initialise@auxfile%
      \TF@PackageDebugInfoNoLine{%
        Writing `#1' to auxiliary file \TF@AUXFILENAME..}%
      \@bsphack%
      {\let\protect\string\immediate\write\tf@@auxfilehandle{#1}}%
      \@esphack%
    }{}%
  }
}

\tf@newbool{tf@auxfilechanged}{false}
\tf@newbool{tf@sffontdirty}{false}     % set these two if we need second run
\tf@newbool{tf@ttfontdirty}{false}     % to ensure they are accurately scaled
\newcommand*\tf@notifyauxfiledirty[1]{
  \ifthenelse{\equal{#1}{sf}}{\global\booltrue{tf@sffontdirty}}{}
  \ifthenelse{\equal{#1}{tt}}{\global\booltrue{tf@ttfontdirty}}{}
  \notbool{tf@auxfilechanged}{
    \global\booltrue{tf@auxfilechanged}
    \ifbool{@filesw}{
      \TF@PackageWarningNoLine{%
        Auxiliary file `\TF@AUXFILENAME' has changed.\MessageBreak
        You need to recompile `\jobname.tex' again}
    }{}
  }{}
}

\AtEndOfPackage{
  \AtBeginDocument{%
    \ifbool{tf@auxfileopen}{%
      \TF@PackageDebugInfoNoLine{Closing auxiliary file \TF@AUXFILENAME..}%
      \immediate\closeout\tf@@auxfilehandle%
      \boolfalse{tf@auxfileopen}%
    }{}%
  }
}

% \newtypeface typeface definition command. This is this package's central
% customisation command. Users can use this command to a) extend the range of
% typeface package managed fonts or b) override the font definitions set out
% below. User font (re)definitions should be placed in customisation file
% \TF@CONFIGFILE (see example customisation file provided with this package).
% ===========================================================================
\newcommand\newtypeface[5][]{%
  % #1: [<optional comma-separated list of aliases for typeface name>]
  % #2: {<typeface name>}
  % #3: {<typeface human-readable print name>}
  %     NB, #3 can be empty, in which case the user must explicitly define
  %     the font's print name macro (e.g., \tf@rmprintname) in the code in #5
  % #4: {<typeface family: rm, sf, tt, math, symbols or textfigures>}
  % #5: {<typeface initialisation code>}, e.g.,
  %       {\renewcommand*\rmdefault{ppl}} or {\tf@usefontpackage{helv}...}
  % Note that, for better integration and debugging, users should load
  % font packages using \tf@usefontpackage rather than \usepackage (however,
  % continuing to use \usepackage for loading non-font packages outside
  % \newtypeface definitions).
  %
  \ifthenelse{\equal{#4}{rm}
           \OR\equal{#4}{sf}
           \OR\equal{#4}{tt}
           \OR\equal{#4}{math}
           \OR\equal{#4}{symbols}
           \OR\equal{#4}{textfigures}}{

    \def\do{}  % pre-initialised stub
    \ifcsundef{tf@#4font@#2}{

      % Add any (optional #1) fontname aliases to the list of valid typeface
      % package choices. Also, build helper macro \tf@rationalisefontnames
      % (invoked once, further below).
      \renewcommand*\do[1]{
        \expandafter\g@addto@macro\csname tf@#4typefacechoices\endcsname{##1,}
        \g@addto@macro\tf@rationalisefontnames{%
          % fyi, \tf@#4font is created by \tf@parsefontname, defined way below
          % e.g., \tf@rmfont is created by \tf@parsefontname{rm}
          \ifthenelse{\equal{\csname tf@#4font\endcsname}{##1}}{
            \expandafter\def\csname tf@#4font\endcsname{#2}
          }{}
        }
      }
      \docsvlist{#1}  % iterate \do over each typeface alias in #1

      % Add #2 to the \tf@#4typefacechoices comma separated list
      \expandafter\g@addto@macro\csname tf@#4typefacechoices\endcsname{#2,}

      % Add #2 to the \tf@load#4typeface command
      \expandafter\g@addto@macro\csname tf@load#4typeface\endcsname{
        \ifthenelse{\equal{\csname tf@#4font\endcsname}{#2}}
          {\csname tf@#4font@#2\endcsname}
          {}
      }

      % Construct \tf@#4font@#2, the font initialisation command
      % invoked by \tf@load#4typeface, just defined above
      \expandafter\providecommand\csname tf@#4font@#2\endcsname{#5}

      % Prepend some debug code to the macro
      \expandafter\pretocmd\expandafter{\csname tf@#4font@#2\endcsname}
        {\TF@PackageDebugInfo{Loading #4 typeface `#2'...}}{}{}

      % Prepend the font print name to the macro (so long as #3 the print
      % name isn't empty, otherwise whatever code invokes \newtypeface
      % will explicitly need to take care of this itself)
      \ifthenelse{\NOT\equal{#3}{}}{
        \expandafter\pretocmd\expandafter{\csname tf@#4font@#2\endcsname}
          {\expandafter\def\csname tf@#4printname\endcsname{#3}}{}{}
      }{}

      % Restore \DeclareSizeFunction if we redefined it in
      % \tf@initialisetextfiguresfont (defined below)
      \ifthenelse{\equal{#4}{textfigures}}{
        \expandafter\apptocmd\expandafter{\csname tf@#4font@#2\endcsname}{
          \ifthenelse{\NOT\isundefined{\oldDeclareSizeFunction}}
            {\let\DeclareSizeFunction\oldDeclareSizeFunction}{}
        }{}{}
      }{}

      % Record our package-managed \rmdefault, \sfdefault, \ttdefault
      \expandafter\apptocmd\expandafter{\csname tf@#4font@#2\endcsname}{
        \xdef\tf@rmdefault{\rmdefault}
        \xdef\tf@sfdefault{\sfdefault}
        \xdef\tf@ttdefault{\ttdefault}
      }{}{}

      % Have the macro register itself as and whenever it happens to be invoked
      \expandafter\g@addto@macro\csname tf@#4font@#2\endcsname{%
        \expandafter\def\csname tf@#4fontloadcommand\endcsname{tf@#4font@#2}%
      }

      % Finally, ensure our macro is restricted to the document preamble
      \expandafter\@onlypreamble\csname tf@#4font@#2\endcsname
    }{
      % User has included their own definition for standard typeface #2
      % in the #4 family (or they included multiple definitions for one
      % of their own typefaces) in their config file.
        \TF@PackageDebugInfo{%
          Encountered multiple definitions for `#2' in\MessageBreak
          the `#4' family. This is OK, however note that the\MessageBreak
          first definition takes precedence while subsequent\MessageBreak
          definitions are ignored}
    }
  }{
    \TF@PackageError{user configuration error: second\MessageBreak
      mandatory argument to \string\newtypeface\ should\MessageBreak
      be one of [rm,sf,tt,math,symbols,textfigures]}{}
  }
}

% User typeface scale command -- useful in the body of the initialisation
% code passed to the \newtypeface command (see examples below)
\newcommand*\scaletypeface[2]{
  % #1: sf, tt or textfigures
  % #2: any scaling code recognised by the font definition (.fd) file
  \ifthenelse{\equal{\csname tf@#1scalemethod\endcsname}{\TF@FX@SCALE}}{
    #2
    \booltrue{tf@#1scaledatloadtime}
  }{}
}

% Load package configuration file \TF@CONFIGFILE. This file may contain
%   1) user-defined fonts specifications (\newtypeface commands), and
%   2) overrides of constants in the code block immediately above.
%----------------------------------------------------------------------
\IfFileExists{\TF@CONFIGFILE}{
  \TF@PackageInfoNoLine{Loading configuration file `\TF@CONFIGFILE'...}
  \input{\TF@CONFIGFILE}
  \TF@PackageInfoNoLine{...completed loading configuration file
                        `\TF@CONFIGFILE'}
}{
  \TF@PackageInfoNoLine{%
    User typeface definition file `\TF@CONFIGFILE'\MessageBreak
    cannot be found (`\TF@CONFIGFILE' not loaded)}
}

% Non-reconfigurable enums -- (re)defined after config file load
%---------------------------------------------------------------
\newcommand*\TF@IMPLICITDEFAULT {0} % pkg option kv unspecified
\newcommand*\TF@EXPLICITDEFAULT {1} % pkg option kv explicitly = \TF@DEFAULT
\newcommand*\TF@EXPLICITOTHER   {2} % pkg option kv explicitly = something else

\newcommand*\TF@OSF@LF{0}   % lining figures
\newcommand*\TF@OSF@NF{1}   % native font -- do nothing
\newcommand*\TF@OSF@JF{2}   % native OSF 'j' (or equiv) font family
\newcommand*\TF@OSF@XF{3}   % substitute font
\newcommand*\TF@OSF@TS{4}   % TS1 encoding
\newcommand*\TF@OSF@SC{5}   % small caps

\newcommand*\TF@UNSCALED{1} % unitary scaling factor -- must be 1, not 1.0 etc.

\newcommand*\TF@ER@SCALE{0} % user error
\newcommand*\TF@NO@SCALE{1} % don't scale font; equiv, scale to \TF@UNSCALED
\newcommand*\TF@FX@SCALE{2} % scale font to fixed positive real number
\newcommand*\TF@EX@SCALE{3} % scale font to rm font ex height
\newcommand*\TF@LC@SCALE{4} % scale font to rm font lowercase letters height
\newcommand*\TF@UC@SCALE{5} % scale font to rm font uppercase letters height
\newcommand*\TF@FG@SCALE{6} % scale font to rm font figures height

\newcommand*\TF@DEFAULTFONTLOADORDER{textfigures:symbols:math:rm:sf:tt}

% Package options processing
% ==========================
\RequirePackage{xkeyval}

% Roman (default body text) typeface selection.
% Save <string> in \tf@rmfontname, given user options:
%   `typeface=<string>' or `rm=<string>'
%-----------------------------------------------------
\newcommand*\tf@rmfontname{\TF@DEFAULT}
\newcommand*\tf@rmfontdefaultstatus{\TF@IMPLICITDEFAULT}

\newcommand*\tf@define@key@typeface{
  \define@key{TF}{typeface}[]{
    \renewcommand*\tf@rmfontname{##1}
    \renewcommand*\tf@rmfontdefaultstatus{\TF@EXPLICITOTHER}
    % only partially initialised here -- complete initialisation below
  }
}
\tf@define@key@typeface

% As above but using synonym `rm=' instead
\tf@patchcmd{\tf@define@key@typeface}{typeface}{rm}
\tf@define@key@typeface

% Sans serif typeface selection
% Save <string> in \tf@sffontname, given user options:
%   `sanstypeface=<string>' or `sf=<string>'
%-----------------------------------------------------
\newcommand*\tf@sffontname{\TF@DEFAULT}
\newcommand*\tf@sffontdefaultstatus{\TF@IMPLICITDEFAULT}

\newcommand*\tf@define@key@sftypeface{
  \define@key{TF}{sanstypeface}[]{
    \renewcommand*\tf@sffontname{##1}
    \renewcommand*\tf@sffontdefaultstatus{\TF@EXPLICITOTHER}
    % only partially initialised here -- complete initialisation below
  }
}
\tf@define@key@sftypeface

% As above but using synonym `sf=' instead
\tf@patchcmd{\tf@define@key@sftypeface}{sanstypeface}{sf}
\tf@define@key@sftypeface

% Monospaced (typewriter) typeface selection
% Save <string> in \tf@ttfontname, given user options:
%   `monotypeface=<string>' or `tt=<string>'
%-----------------------------------------------------
\newcommand*\tf@ttfontname{\TF@DEFAULT}
\newcommand*\tf@ttfontdefaultstatus{\TF@IMPLICITDEFAULT}

\newcommand*\tf@define@key@tttypeface{
  \define@key{TF}{monotypeface}[]{
    \renewcommand*\tf@ttfontname{##1}
    \renewcommand*\tf@ttfontdefaultstatus{\TF@EXPLICITOTHER}
    % only partially initialised here -- complete initialisation below
  }
}
\tf@define@key@tttypeface

% As above but using synonym `tt=' instead
\tf@patchcmd{\tf@define@key@tttypeface}{monotypeface}{tt}
\tf@define@key@tttypeface

% Math typeface selection
% Save <string> in \tf@mathfontname, given user options:
%   `mathtypeface=<string>' or `math=<string>'
%-------------------------------------------------------
\newcommand*\tf@mathfontname{\TF@DEFAULT}
\newcommand*\tf@mathfontdefaultstatus{\TF@IMPLICITDEFAULT}

\newcommand*\tf@define@key@mathtypeface{
  \define@key{TF}{mathtypeface}[]{
    \renewcommand*\tf@mathfontname{##1}
    \renewcommand*\tf@mathfontdefaultstatus{\TF@EXPLICITOTHER}
    % only partially initialised here -- complete initialisation below
  }
}
\tf@define@key@mathtypeface

% As above but using synonym `math=' instead
\tf@patchcmd{\tf@define@key@mathtypeface}{mathtypeface}{math}
\tf@define@key@mathtypeface

% Symbols typeface selection
% Save <string> in \tf@symbolsfontname, given user options:
%   `symbolstypeface=<string>' or `sym=<string>'
%---------------------------------------------------------
\newcommand*\tf@symbolsfontname{\TF@DEFAULT}
\newcommand*\tf@symbolsfontdefaultstatus{\TF@IMPLICITDEFAULT}

\newcommand*\tf@define@key@symbolstypeface{
  \define@key{TF}{symbolstypeface}[]{
    \renewcommand*\tf@symbolsfontname{##1}
    \renewcommand*\tf@symbolsfontdefaultstatus{\TF@EXPLICITOTHER}
    % only partially initialised here -- complete initialisation below
  }
}
\tf@define@key@symbolstypeface

% As above but using synonym `sym=' instead
\tf@patchcmd{\tf@define@key@symbolstypeface}{symbolstypeface}{sym}
\tf@define@key@symbolstypeface

% Text figures (aka old style figures, aka lowercase roman numerals).
% Depending on your body text typeface, you can choose to source text
% figures from its old style font or from one of a limited number of
% entirely different substitute typefaces.
%--------------------------------------------------------------------
\newcommand*\tf@textfiguresfontname{\TF@DEFAULT}
\newcommand*\tf@textfiguresfontdefaultstatus{\TF@IMPLICITDEFAULT}

\newcommand*\tf@define@key@textfigurestypeface{
  \define@key{TF}{textfigures}[]{
    \renewcommand*\tf@textfiguresfontname{##1}
    \renewcommand*\tf@textfiguresfontdefaultstatus{\TF@EXPLICITOTHER}
    % only partially initialised here -- complete initialisation below
  }
}
\tf@define@key@textfigurestypeface

% Font encodings. Note that fontenc is one of only a rare number of
% packages that can be loaded multiple times.
%
% Typeface package option `fontencoding=<encs>' where <encs> is:
%   1) <empty>, in which case typeface will load the fontenc package
%      with option \TF@DEFAULTFONTENCODING (as defined above or redefined in
%      \TF@CONFIGFILE). This value is implied if the user does not explicitly
%      set the this package's `fontencoding' option.
%   2) `ignore' or `dontload' (or whatever the values of `\TF@IGNORE' or
%      `\TF@DONTLOAD' happen to be). In which case typeface does not load
%      fontenc.
%   3) a colon-separated list of items drawn from comma-separated list
%      \tf@fontencodingchoices (reader, are you listening up? <encs> is, like
%      all all other multi-valued package options that can be passed to this
%      package, colon-separated; \tf@fontencodingchoices is an internally
%      coded list, thus comma-separated). The allowable set of <encs> choices,
%      \tf@fontencodingchoices, is initialised below with possible additions
%      in defined in \TF@CONFIGFILE. Font encoding choice items are passed to
%      fontenc in the order that they appear in <encs>.
%      Special value `default' (or whatever the value of \TF@DEFAULT happens
%      to be), gets translated in the process to \TF@DEFAULTFONTENCODING
%      (defined above or in \TF@CONFIGFILE).
%      Note that the ***last*** (or most recently processed) item passed to
%      fontenc becomes the current default font encoding. So, e.g., T1 is
%      assigned to \encodingdefault when typeface is passed option
%      `fontencoding=LGR:T1'.
%
% NB, the cause of LaTeX compiler error:
%      LaTeX Error: Unknown option `YYY' for package `typeface'
% is forgetting that multi-valued package options (suboptions) are
% colon, NOT comma, separated. Instead of writing package option
%      ...,fontencoding=XXX,YYY,...
% the user should instead have written
%      ...,fontencoding=XXX:YYY,...
%----------------------------------------------------------------------------
\newcommand*\tf@fontencodingstring{}
\newcommand*\tf@fontencodingdefaultstatus{}

\define@key{TF}{fontencoding}[]{
  \renewcommand*\tf@fontencodingstring{#1}
  % only partially initialised here -- complete initialisation below
}

% List of common font encodings drawn from around the place, e.g.,
% from `encguide.pdf'.  You can add your own options to this list
% by including:
%     \renewcommand\tf@fontencodingchoices{<choice,...>}
% in configuration file \TF@CONFIGFILE. It won't hurt if you repeat
% any choices here.
\g@addto@macro\tf@fontencodingchoices{,%
  \TF@DEFAULT,%
  EU1,EU2,L7X,LAE,LFE,LGR,LHE,LM1,LV1,LY1,%
  OML,OMS,OMX,OT1,OT2,OT4,OT6,%
  T1,T2A,T2B,T2C,T3,T4,T5,T6,T7,%
  TS1,TS2,TS3,U,X1,X2,%
}

% Inputenc package options -- see comments with fontencoding
%-----------------------------------------------------------
\newcommand*\tf@inputencodingstring{}
\newcommand*\tf@inputencodingdefaultstatus{}

\define@key{TF}{inputencoding}[]{
  \renewcommand*\tf@inputencodingstring{#1}
  % only partially initialised here -- complete initialisation below
}

\g@addto@macro\tf@inputencodingchoices{,%
    \TF@DEFAULT,%
    ascii,latin1,latin2,latin3,latin4,latin5,latin9,latin10,%
    decmulti,applemac,macce,next,cp850,cp852,cp858,cp437,%
    cp437de,cp865,cp1250,cp1252,cp1257,ansinew,utf8,utf8x,%
}

% Textcomp package options -- see comments with fontencoding
%-----------------------------------------------------------
\newcommand*\tf@textcompstring{}
\newcommand*\tf@textcompdefaultstatus{}

\define@key{TF}{textcomp}[]{
  \renewcommand*\tf@textcompstring{#1}
  % only partially initialised here -- complete initialisation below
}

\g@addto@macro\tf@textcompchoices{,%
  \TF@DEFAULT,safe,euro,full,almostfull,warn,force,%
}

% Cmap package options -- see comments with fontencoding
%-------------------------------------------------------
\newcommand*\tf@cmapstring{}
\newcommand*\tf@cmapdefaultstatus{}

\define@key{TF}{cmap}[]{
  \renewcommand*\tf@cmapstring{#1}
  % only partially initialised here -- complete initialisation below
}

\g@addto@macro\tf@cmapchoices{,%
  \TF@DEFAULT,resetfonts,noresetfonts,%
}

% Font load order. Default font load order is:
%    textfigures -> symbols -> math -> rm -> sf -> tt
% (or as specified in \TF@DEFAULTFONTLOADORDER, above)
%
% 1. package option loadorder allows users to indicate (albeit strongly
%    indicate) their preferred font load order. We do our best to honour
%    the user's preference, but may occasionally choose to disregard it.
% 2. users should do their best to avoid using this option lest doing so
%    lead to brittle code (seemingly innocuous changes to document code
%    leading to unexpected problems). However, this option might prove
%    useful, especially in cases where math/symbols load ordering can
%    strongly affect results.
%-----------------------------------------------------------------------
\newcommand*\tf@fontloadorder{\TF@DEFAULTFONTLOADORDER}
\tf@newbool{tf@fontloadorderimplicit}{true}

\define@key{TF}{fontloadorder}[\TF@DEFAULTFONTLOADORDER]{
  \renewcommand*\tf@fontloadorder{#1}
  \boolfalse{tf@fontloadorderimplicit}
}

% Output extra info in log files and coloured text when debugging
%----------------------------------------------------------------
\tf@newbool{tf@debug}{false}
\tf@newbool{tf@debugimplicit}{true}

\define@choicekey+{TF}{debug}[]{true,false}[true]
  {\setbool{tf@debug}{#1}\boolfalse{tf@debugimplicit}}
  {\TF@ChoiceOptionError{debug}{#1}}

% Enabling print info commands will pull in packages we generally don't use
%--------------------------------------------------------------------------
\tf@newbool{tf@printinfo}{false}
\tf@newbool{tf@printinfoimplicit}{true}

\define@choicekey+{TF}{printinfo}[]{true,false}[true]
  {\setbool{tf@printinfo}{#1}\boolfalse{tf@printinfoimplicit}}
  {\TF@ChoiceOptionError{printinfo}{#1}}

% Finished declaring package options -- process them
%---------------------------------------------------
\TF@PackageDebugInfo{Processing package options...}
\ProcessOptionsX<TF>\relax

% Set default options; reset or complain about those that don't make sense
% ========================================================================
\TF@PackageDebugInfo{Reconfiguring and error-checking user options...}

% Package options validation -- typeface/rm, sanstypeface/sf, monotypeface/tt,
% mathtypeface/math, symbolstypeface/sym, textfigures
\newcommand*\tf@reconfigurefontoption[1]{
  % Set font defaults if a) user did not explicitly specify a desired font
  % or b) explicitly specified `default' (or whatever \TF@DEFAULT is defined
  % to be) instead.
  % #1 is rm, sf, tt, math, symbols or textfigures
  \ifthenelse{\equal{\csname tf@#1fontname\endcsname}{}}{
    \expandafter\xdef\csname tf@#1fontname\endcsname{\TF@DEFAULT}
    \expandafter\xdef\csname tf@#1fontdefaultstatus\endcsname
      {\TF@IMPLICITDEFAULT}
  }{}

  \ifthenelse{\equal{\csname tf@#1fontname\endcsname}{\TF@DEFAULT}
    \AND\equal{\csname tf@#1fontdefaultstatus\endcsname}{\TF@EXPLICITOTHER}}{
    \expandafter\xdef\csname tf@#1fontdefaultstatus\endcsname
      {\TF@EXPLICITDEFAULT}
  }{}

  \ifthenelse{\equal{\csname tf@#1fontname\endcsname}{\TF@DEFAULT}}{
    \MakeUppercase{\xdef\noexpand\tf@@tmp{TF@DEFAULT#1FONT}}
    \expandafter\xdef\csname tf@#1fontname\endcsname
      {\csname\tf@@tmp\endcsname}
  }{}
}
\forcsvlist{\tf@reconfigurefontoption}{rm,sf,tt,math,symbols,textfigures}

% Shared fontencoding, inputencoding, textcomp, cmap options validation
% routine. Apologies for the jabberwocky code -- it was this or repeat
% the entire block several times.
\newcommand*\tf@@pkgoptionsvalidation[1]{
  % #1: fontencoding, inputencoding, textcomp or cmap
  \expandafter\def\csname tf@#1\endcsname{}
  \edef\tf@@optionstring{\csname tf@#1string\endcsname}
  \MakeUppercase{\xdef\noexpand\tf@@tmp{TF@DEFAULT#1}}
  \xdef\TF@@DEFAULTOPTION{\csname\tf@@tmp\endcsname}

  % Set (preliminary) defaultstatus depending on what the user specified
  \ifthenelse{\equal{\tf@@optionstring}{}}{
    \expandafter\def\csname tf@#1defaultstatus\endcsname{\TF@IMPLICITDEFAULT}
  }{
    \ifthenelse{\equal{\tf@@optionstring}{\TF@DEFAULT}}
     {\expandafter\def\csname tf@#1defaultstatus\endcsname{\TF@EXPLICITDEFAULT}}
     {\expandafter\def\csname tf@#1defaultstatus\endcsname{\TF@EXPLICITOTHER}}
  }

  % Ensure each suboption in option string matches an item
  % in the relevant options choices list
  \tf@newbool{tf@#1match}{false}
  \tf@newbool{tf@#1dontload}{false}
  \newcounter{tf@#1suboptionscount}
  \setcounter{tf@#1suboptionscount}{0}
  \renewcommand*\tf@@listseparator{}

  \def\tf@@innerdo##1{
    \boolfalse{tf@#1match}
    \ifthenelse{\equal{##1}{\tf@@option}}
      {\booltrue{tf@#1match}\listbreak}{}
  }

  \def\do##1{
    \ifthenelse{\equal{##1}{\TF@DONTLOAD}\OR\equal{##1}{\TF@IGNORE}}{
      \booltrue{tf@#1dontload}
      \expandafter\def\csname tf@#1\endcsname{\TF@DONTLOAD}
    }{
      \xdef\tf@@option{##1}
      \xdef\tf@@options{\csname tf@#1choices\endcsname}
      \expandafter\forcsvlist\expandafter\tf@@innerdo\expandafter{\tf@@options}
      \ifbool{tf@#1match}{
        \ifthenelse{\equal{##1}{\TF@DEFAULT}}{
          % translate user suboption \TF@DEFAULT (usually `default')
          % to appropriate value, setting default status accordingly
          \expandafter\xdef\csname tf@#1\endcsname{%
            \csname tf@#1\endcsname\tf@@listseparator\TF@@DEFAULTOPTION}
          \expandafter\xdef\csname tf@#1primary\endcsname
            {\TF@@DEFAULTOPTION}% fontenc only
          \expandafter\xdef\csname tf@#1defaultstatus\endcsname
            {\TF@EXPLICITDEFAULT}
        }{
          \expandafter\xdef\csname tf@#1\endcsname{%
            \csname tf@#1\endcsname\tf@@listseparator##1}
          \expandafter\xdef\csname tf@#1primary\endcsname{##1}% fontenc only
          \expandafter\xdef\csname tf@#1defaultstatus\endcsname
            {\TF@EXPLICITOTHER}
        }
        \renewcommand*\tf@@listseparator{,}
      }{
        \TF@PackageError{%
          Suboption `##1' in `#1=\tf@@optionstring'\MessageBreak
          is not valid. Setting `#1=\TF@@DEFAULTOPTION'}{}
        \expandafter\xdef\csname tf@#1string\endcsname{}
        \listbreak
      }
    }
    \stepcounter{tf@#1suboptionscount}
  }
  \expandafter\tf@doColonSeparatedList\expandafter{\tf@@optionstring}

  \ifthenelse{\value{tf@#1suboptionscount} > 1}{
    \expandafter\xdef\csname tf@#1defaultstatus\endcsname{\TF@EXPLICITOTHER}
  }{}

  % Option-specific error handling
  \ifthenelse{\equal{#1}{fontencoding}}{
    \ifthenelse{\boolean{tf@fontencodingdontload}
            \AND\value{tf@fontencodingsuboptionscount} > 1}{
      \TF@PackageError{%
        #1 suboptions `\TF@DONTLOAD' and `\TF@IGNORE'\MessageBreak
        do not mix with other suboptions. Package option\MessageBreak
        `#1=\tf@@optionstring' is not valid.\MessageBreak
        Setting `#1=\TF@@DEFAULTOPTION'}{}
      \expandafter\xdef\csname tf@#1string\endcsname{}
    }{}
  }{% inputencoding, textcomp and cmap options
    \ifthenelse{\value{tf@#1suboptionscount} > 1}{
      \TF@PackageError{%
        Package option `#1=\tf@@optionstring' is\MessageBreak
        not valid. `#1' does not accept multiple\MessageBreak
        suboptions. Setting `#1=\TF@@DEFAULTOPTION'}{}
      \expandafter\xdef\csname tf@#1string\endcsname{}
    }{}
  }

  \edef\tf@@optionstring{\csname tf@#1string\endcsname}
  \ifthenelse{\equal{\tf@@optionstring}{}}{
    \expandafter\xdef\csname tf@#1\endcsname{\TF@@DEFAULTOPTION}
    \expandafter\xdef\csname tf@#1primary\endcsname{\TF@@DEFAULTOPTION}
  }{}
}
\forcsvlist{\tf@@pkgoptionsvalidation}{fontencoding,inputencoding,textcomp,cmap}

% Package options validation -- fontloadorder
\xdef\tf@fontloadorder{\tf@fontloadorder:} % <-- insert guard
  \tf@ifsuboption{textfigures}{\tf@fontloadorder}{\relax}
    {\tf@replacesuboption{textfigure}{textfigures}{\tf@fontloadorder}}
  \tf@ifsuboption{symbols}{\tf@fontloadorder}{\relax}
    {\tf@replacesuboption{symbol}{symbols}{\tf@fontloadorder}}
  \tf@replacesuboption{maths}{math}{\tf@fontloadorder}
  \tf@replacesuboption{roman}{rm}{\tf@fontloadorder}
  \tf@replacesuboption{sans}{sf}{\tf@fontloadorder}
  \tf@replacesuboption{mono}{tt}{\tf@fontloadorder}
  \tf@replacesuboption{teletype}{tt}{\tf@fontloadorder}
\def\tf@stripguard#1:\@empty#2\relax{#1}    % <-- strip guard
\xdef\tf@fontloadorder{\expandafter%
  \tf@stripguard\tf@fontloadorder\@empty\relax}

\ifthenelse{\equal{\tf@fontloadorder}{\TF@DEFAULT}}
  {\xdef\tf@fontloadorder{\TF@DEFAULTFONTLOADORDER}}{} % NB, not \newcommand

% Check whether the font load order list is under or over complete
\newcommand*\tf@fontloadordercomplete[1]{
  \tf@ifsuboption{#1}{\tf@fontloadorder}{
    \tf@suboptioncount{#1}{\tf@fontloadorder}
    \ifthenelse{\thetf@suboptioncount > 1}{
      \TF@PackageError{Suboption `#1' appears more than once in\MessageBreak
                       `fontloadorder=\tf@fontloadorder'.\MessageBreak
                       Setting `fontloadorder=\TF@DEFAULT'}{}
      \xdef\tf@fontloadorder{\TF@DEFAULTFONTLOADORDER} % NB, not \newcommand!
    }{}
  }{
    \TF@PackageError{Suboption `#1' missing in package option\MessageBreak
                     `fontloadorder=\tf@fontloadorder'.\MessageBreak
                     Setting `fontloadorder=\TF@DEFAULT'}{}
    \xdef\tf@fontloadorder{\TF@DEFAULTFONTLOADORDER} % NB, not \newcommand!
  }
}
\forcsvlist{\tf@fontloadordercomplete}{rm,sf,tt,math,symbols,textfigures}

% check for typos, weird entries in the font order list
\renewcommand*\do[1]{  % see etoolbox package docs
  \ifthenelse{\NOT\equal{#1}{textfigures}
          \AND\NOT\equal{#1}{symbols}
          \AND\NOT\equal{#1}{math}
          \AND\NOT\equal{#1}{rm}
          \AND\NOT\equal{#1}{sf}
          \AND\NOT\equal{#1}{tt}}{
    \TF@PackageError{Unexpected suboption `#1' in package option\MessageBreak
                   `fontloadorder=\tf@fontloadorder'.\MessageBreak
                   Setting `fontloadorder=\TF@DEFAULT'}{}
  }{}
}
\expandafter\tf@doColonSeparatedList\expandafter{\tf@fontloadorder}

% Package options validation -- cmap
% -- cmap accepts a faux option which, after validation, we can now remove
\tf@replacesuboption{noresetfonts}{}{\tf@cmap}

% Load and process auxiliary file
% ===============================

% Ensure our auxiliary parameters have not been pre-defined...
\tf@undefinecommands{
  \tf@aux@fontencoding,
  \tf@aux@inputencoding,
  \tf@aux@textcomp,
  \tf@aux@cmap,
  \tf@aux@rmfontname,
  \tf@aux@sffontname,
  \tf@aux@ttfontname,
  \tf@aux@mathfontname,
  \tf@aux@symbolsfontname,
  \tf@aux@textfiguresfontname,
  \tf@aux@sfscalefactor,
  \tf@aux@ttscalefactor,
  \tf@aux@mathscalefactor,
  \tf@aux@textfiguresscalefactor,
  \tf@aux@textfiguresspacing,
}

% ... read them from our aux file if defined there ...
\InputIfFileExists{\TF@AUXFILENAME}
  {\TF@PackageDebugInfo{Loading auxiliary file `\TF@AUXFILENAME'...}}
  {\TF@PackageDebugInfo{Could not locate auxiliary file `\TF@AUXFILENAME'}}

% ... or define them safely if they are not
\providecommand*\tf@aux@fontencoding{}
\providecommand*\tf@aux@inputencoding{}
\providecommand*\tf@aux@textcomp{}
\providecommand*\tf@aux@cmap{}

\providecommand*\tf@aux@rmfontname{}
\providecommand*\tf@aux@sffontname{}
\providecommand*\tf@aux@ttfontname{}
\providecommand*\tf@aux@mathfontname{}
\providecommand*\tf@aux@symbolsfontname{}
\providecommand*\tf@aux@textfiguresfontname{}

\providecommand*\tf@aux@sfscalefactor{}
\providecommand*\tf@aux@ttscalefactor{}
\providecommand*\tf@aux@mathscalefactor{}
\providecommand*\tf@aux@textfiguresscalefactor{}
\providecommand*\tf@aux@textfiguresspacing{}

%--- Begin rebuilding the aux file anew ---------------------------------------
\tf@writeauxfile{\string\relax} % reset aux file contents
\tf@writeauxfile{\string\ProvidesFile{\TF@AUXFILENAME}[<\TF@PACKAGENAME package auxiliary file>]}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@fontencoding{\tf@fontencoding}}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@inputencoding{\tf@inputencoding}}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@textcomp{\tf@textcomp}}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@cmap{\tf@cmap}}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@rmfontname{\tf@rmfontname}}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@sffontname{\tf@sffontname}}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@ttfontname{\tf@ttfontname}}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@mathfontname{\tf@mathfontname}}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@symbolsfontname{\tf@symbolsfontname}}
\tf@writeauxfile{\string\newcommand*\string\tf@aux@textfiguresfontname{\tf@textfiguresfontname}}
%------------------------------------------------------------------------------

% Shared typeface loading commands
% ================================
\TF@PackageDebugInfo{Configuring shared typeface load commands...}

% Some fonts may be called on by multiple typeface loading commands. In
% these cases, common code is factored out to assist font load management
% and to reduce code duplication.

%------------------------------------------------------------------------------
% NB, because they contain shared/refactored code, many (if not most) of
% these commands ignore user-specified changes in fontloadorder.
%------------------------------------------------------------------------------

% Adobe Minion Pro -- shared code
%--------------------------------
\newcommand*\tf@mp@printname{Adobe Minion Pro}
\tf@newbool{tf@mp@implicitmathnums}{true}

% Minion Pro load helper command
\newcommand*\tf@mp@processoptions[1]{
  % #1 is either \tf@rmfontoptions or \tf@mathfontoptions
  \tf@ifsuboption{smallfamily}{#1}
    {\PassOptionsToPackage{smallfamily}{MinionPro}}{}
  \tf@ifsuboption{medfamily}{#1}
    {\PassOptionsToPackage{medfamily}{MinionPro}}{}
  \tf@ifsuboption{fullfamily}{#1}
    {\PassOptionsToPackage{fullfamily}{MinionPro}}{}
  \tf@ifsuboption{noopticals}{#1}
    {\PassOptionsToPackage{noopticals}{MinionPro}}{}
  \tf@ifsuboption{opticals}{#1}
    {\PassOptionsToPackage{opticals}{MinionPro}}{}
  \tf@ifsuboption{slides}{#1}
    {\PassOptionsToPackage{slides}{MinionPro}}{}
  \tf@ifsuboption{normalsize}{#1}
    {\PassOptionsToPackage{normalsize}{MinionPro}}{}
  \tf@ifsuboption{nonormalsize}{#1}
    {\PassOptionsToPackage{nonormalsize}{MinionPro}}{}

  \ifthenelse{\equal{\tf@mathfont}{adobeminionpro}}{
    \def\tf@@configurempoptions##1{
      \tf@ifsuboption{##1}{\tf@mathfontoptions}{
        \PassOptionsToPackage{mathlf}{MinionPro}
        \boolfalse{tf@mp@implicitmathnums}
      }{}
    }
    \forcsvlist{\tf@@configurempoptions}
      {lf,lsf,lining,liningstyle,liningstylefigures,mathlf}

    \def\tf@@configurempoptions##1{
      \tf@ifsuboption{##1}{\tf@mathfontoptions}{
        \PassOptionsToPackage{mathosf}{MinionPro}
        \boolfalse{tf@mp@implicitmathnums}
      }{}
    }
    \forcsvlist{\tf@@configurempoptions}
      {osf,oldstyle,oldfigures,oldstylefigures,mathosf}
  }{}
  % unlike math where we allow many lf/osf aliases for configuring
  % math figures, we only allow `mathlf' or `mathosf' in rm
  % options to configure math figures
  \ifthenelse{\equal{\tf@rmfont}{adobeminionpro}}{
    \tf@ifsuboption{mathlf}{\tf@rmfontoptions}{
      \PassOptionsToPackage{mathlf}{MinionPro}
      \boolfalse{tf@mp@implicitmathnums}}{}
    \tf@ifsuboption{mathosf}{\tf@rmfontoptions}{
      \PassOptionsToPackage{mathosf}{MinionPro}
      \boolfalse{tf@mp@implicitmathnums}}{}
  }{}
  \ifbool{tf@mp@implicitmathnums}{
    \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@LF}}
      {\PassOptionsToPackage{mathlf}{MinionPro}}
      {\PassOptionsToPackage{mathosf}{MinionPro}}
  }{}

  \tf@ifsuboption{mathtabular}{#1}
    {\PassOptionsToPackage{mathtabular}{MinionPro}}{}
  \tf@ifsuboption{mnsy}{#1}
    {\PassOptionsToPackage{mnsy}{MinionPro}}{}
  \tf@ifsuboption{cmsy}{#1}
    {\PassOptionsToPackage{cmsy}{MinionPro}}{}
  \tf@ifsuboption{swash}{#1}
    {\PassOptionsToPackage{swash}{MinionPro}}{}
  \tf@ifsuboption{abx}{#1}
    {\PassOptionsToPackage{abx}{MinionPro}}{}
  \tf@ifsuboption{amsbb}{#1}
    {\PassOptionsToPackage{amsbb}{MinionPro}}{}
  \tf@ifsuboption{fourierbb}{#1}
    {\PassOptionsToPackage{fourierbb}{MinionPro}}{}
  \tf@ifsuboption{lucidabb}{#1}
    {\PassOptionsToPackage{lucidabb}{MinionPro}}{}
  \tf@ifsuboption{mixedgreek}{#1}
    {\PassOptionsToPackage{mixedgreek}{MinionPro}}{}
  \tf@ifsuboption{italicgreek}{#1}
    {\PassOptionsToPackage{italicgreek}{MinionPro}}{}
  \tf@ifsuboption{frenchmath}{#1}
    {\PassOptionsToPackage{frenchmath}{MinionPro}}{}
  \tf@ifsuboption{minionint}{#1}
    {\PassOptionsToPackage{minionint}{MinionPro}}{}
  \tf@ifsuboption{openg}{#1}
    {\PassOptionsToPackage{openg}{MinionPro}}{}
  \tf@ifsuboption{loosequotes}{#1}
    {\PassOptionsToPackage{loosequotes}{MinionPro}}{}
  \tf@ifsuboption{footnotefigures}{#1}
    {\PassOptionsToPackage{footnotefigures}{MinionPro}}{}
}

\newcommand*\tf@loadadobeminionpro{
  \providebool{tf@adobeminionproloaded}
  \ifbool{tf@adobeminionproloaded}{\relax}{
    \booltrue{tf@adobeminionproloaded}
    \ifthenelse{\equal{\tf@rmfont}{adobeminionpro}}{
      \tf@mp@processoptions{\tf@rmfontoptions}
      \ifthenelse{\equal{\tf@mathfont}{adobeminionpro}
               \OR\equal{\tf@mathfont}{\TF@DEFAULT}}{
        \renewcommand*\tf@mathprintname{\tf@mp@printname}
      }{
        \PassOptionsToPackage{onlytext}{MinionPro}
      }
      \renewcommand*\tf@rmprintname{\tf@mp@printname}
    }{}

    \ifthenelse{\equal{\tf@mathfont}{adobeminionpro}}{
      \tf@mp@processoptions{\tf@mathfontoptions}
      \ifthenelse{\equal{\tf@rmfont}{adobeminionpro}
               \OR\equal{\tf@rmfont}{\TF@DEFAULT}}{
        \renewcommand*\tf@rmprintname{\tf@mp@printname}
      }{
        \PassOptionsToPackage{onlymath}{MinionPro}
      }
      \renewcommand*\tf@mathprintname{\tf@mp@printname}
      \renewcommand*\tf@symbolsprintname{MnSymbol}
    }{}

    \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@LF}}{
      \PassOptionsToPackage{textlf}{MinionPro}
    }{
      \PassOptionsToPackage{textosf}{MinionPro}
      \renewenvironment{liningnums}{%
        \ifbool{tf@debug}{%
          \color{\TF@DEBUG@COLOUR@LININGNUMS}%
        }{}%
        \booltrue{tf@liningnums}%
        \figureversion{lining}%  % Adobe Minion Pro specific command
      }{%
        \boolfalse{tf@liningnums}% these lines are unnecessary,
        \figureversion{text}%    % but let's be explicit anyway
      }
    }

    \let\oldoldstylenums\oldstylenums  % before MinionPro hijacks this
    \tf@usefontpackage{MinionPro}
    \ifthenelse{\NOT\equal{\tf@rmprintname}{\tf@mp@printname}}{
      % restore the hijacking if rm font is neither adobeminionpro nor default
      \let\oldstylenums\oldoldstylenums
    }{}
    % Sidestep a pesky message from fontaxes, a package loaded by MinionPro.
    % This message is generated whenever fontaxes tries to manage fonts that
    % don't provide all the features that it requires -- in general, almost
    % any font. In these cases, fontaxes will complain (a lot) that "I don't
    % know how to decode family `X' on input line...", where (in our case) X
    % is either \rmdefault (resp. \sfdefault, \ttdefault) or \tf@substosffont,
    % our text figures substitute font.  Note that the name of the fontaxes
    % warning command depends on whether fontaxes has been installed via
    % MinionPro package installation (\fa@warn@undecodable) or via a more
    % recent fontaxes package update (\fontaxes@warn@undecodable).
    \@ifpackageloaded{fontaxes}{
      \ifdef{\fa@warn@undecodable}{
        \renewcommand*\fa@warn@undecodable[1]{}
        \TF@PackageInfoNoLine{Silenced fontaxes command %
                              \string\fa@warn@undecodable}
      }{}
      \ifdef{\fontaxes@warn@undecodable}{
        \renewcommand*\fontaxes@warn@undecodable[1]{}
        \TF@PackageInfoNoLine{Silenced fontaxes command %
                              \string\fontaxes@warn@undecodable}
      }{}
    }{}
  }
}

% Antykwa Torunska -- shared code
%--------------------------------
\newcommand*\tf@at@processoptions[1]{
  % #1 is either \tf@rmfontoptions or \tf@mathfontoptions
  \tf@ifsuboption{mathnoalias}{#1}{
    \PassOptionsToPackage{mathnoalias}{anttor}}{}
  \tf@ifsuboption{light}{#1}{
    \PassOptionsToPackage{light}{anttor}
    \booltrue{tf@at@light}}{}
  \tf@ifsuboption{condensed}{#1}{
    \PassOptionsToPackage{condensed}{anttor}
    \booltrue{tf@at@condensed}}{}
}

\newcommand*\tf@loadantykwatorunska{
  \providebool{tf@antykwatorunskaloaded}
  \ifbool{tf@antykwatorunskaloaded}{\relax}{
    \booltrue{tf@antykwatorunskaloaded}
    \newcommand*\tf@at@printname{Antykwa Toru\'nska}
    \tf@newbool{tf@at@light}{false}
    \tf@newbool{tf@at@condensed}{false}

    \ifthenelse{\equal{\tf@rmfont}{antykwatorunska}
             \OR\equal{\tf@rmfont}{\TF@DEFAULT}}{
      \tf@at@processoptions{\tf@rmfontoptions}
      \renewcommand*\tf@rmprintname{\tf@at@printname}
      \renewcommand\oldstylenums[1]{{\scshape ##1}}
      \tf@SCencodedosf
    }{}
    \ifthenelse{\equal{\tf@mathfont}{antykwatorunska}
             \OR\equal{\tf@mathfont}{\TF@DEFAULT}}{
      \tf@at@processoptions{\tf@mathfontoptions}
      \PassOptionsToPackage{math}{anttor}
      \renewcommand*\tf@mathprintname{\tf@at@printname}
    }{}

    \tf@usefontpackage{anttor}

    \newcommand*\tf@at@subprintname{}
    \ifbool{tf@at@light}
      {\edef\tf@at@subprintname{\tf@at@subprintname\space Light}}{}
    \ifbool{tf@at@condensed}
      {\edef\tf@at@subprintname{\tf@at@subprintname\space Condensed}}{}
    \ifthenelse{\equal{\tf@rmprintname}{\tf@at@printname}}
      {\xdef\tf@rmprintname{\tf@rmprintname\tf@at@subprintname}}{}
    \ifthenelse{\equal{\tf@mathprintname}{\tf@at@printname}}
      {\xdef\tf@mathprintname{\tf@mathprintname\tf@at@subprintname}}{}
  }
}

% CM Bright -- shared code
%-------------------------
% CM Bright is a raster rather than an outline (scalable) font unless the
% hfbright remappings of cmbright have been installed at the user's site.
\newcommand*\tf@loadcmbright{
  % Load math/rm/sf/tt CM Bright as applicable, additionally loading
  % rm/sf/tt (but not math) if any of these happen to be default
  \providebool{tf@cmbrightloaded}
  \ifbool{tf@cmbrightloaded}{\relax}{
    \booltrue{tf@cmbrightloaded}
    \ifthenelse{\equal{\tf@mathfont}{cmbright}}{
      \tf@ifsuboption{slantedGreek}{\tf@mathfontoptions}{
        \PassOptionsToPackage{slantedGreek}{cmbright}}{}
      \tf@ifsuboption{standard-baselineskips}{\tf@mathfontoptions}{
        \PassOptionsToPackage{standard-baselineskips}{cmbright}}{}
      \tf@usefontpackage{cmbright}
      \tf@mathfont@cmbright  % housekeeping, e.g., sets math print name
    }{}
    \ifthenelse{\equal{\tf@rmfont}{cmbright}\OR\equal{\tf@rmfont}{\TF@DEFAULT}}{
      \renewcommand*\rmdefault{cmbr}
      \tf@TSencodedosf
      \tf@rmfont@cmbright    % housekeeping, e.g., sets rm print name
    }{}
    \ifthenelse{\equal{\tf@sffont}{cmbright}\OR\equal{\tf@sffont}{\TF@DEFAULT}}{
      \renewcommand*\sfdefault{cmbr}
      \tf@sffont@cmbright    % housekeeping, e.g., sets sf print name
    }{}
    \ifthenelse{\equal{\tf@ttfont}{cmbright}\OR\equal{\tf@ttfont}{\TF@DEFAULT}}{
      \renewcommand*\ttdefault{cmtl}
      \tf@ttfont@cmbright    % housekeeping, e.g., sets tt print name
    }{}
  }
}

% Concrete -- shared code
%------------------------
% Math - Concrete.  NB, concrete math is a bitmap font. Likewise
% concrete roman with OT1 fontencoding; T1 fontencoding loads
% cm-super outline fonts instead.
\newcommand*\tf@loadconcrete{
  % Load math/rm concrete as applicable, additionally loading
  % rm if user option typeface (rm) is set to \TF@DEFAULT
  \providebool{tf@concreteloaded}
  \ifbool{tf@concreteloaded}{\relax}{
    \booltrue{tf@concreteloaded}
    \ifthenelse{\equal{\tf@mathfont}{concrete}}{
      \tf@ifsuboption{exscale}{\tf@mathfontoptions}
        {\PassOptionsToPackage{exscale}{concmath}}{}
      \tf@ifsuboption{amsfonts}{\tf@mathfontoptions}
        {\PassOptionsToPackage{amsfonts}{concmath}}{}
      \tf@ifsuboption{amssymb}{\tf@mathfontoptions}
        {\PassOptionsToPackage{amssymb}{concmath}}{}
      % The documentation discusses `sansbold' option; the style file only
      % accepts `boldsans'. Might as well make things easy for end users.
      \tf@ifsuboption{sansbold}{\tf@mathfontoptions}
        {\PassOptionsToPackage{boldsans}{concmath}}{}
      \tf@ifsuboption{boldsans}{\tf@mathfontoptions}
        {\PassOptionsToPackage{boldsans}{concmath}}{}
      \tf@usefontpackage{concmath}  % preferable to ccfonts
      \tf@mathfont@concrete  % housekeeping, e.g., sets math print name
    }{}
    \ifthenelse{\equal{\tf@rmfont}{concrete}\OR\equal{\tf@rmfont}{\TF@DEFAULT}}{
      \renewcommand*\rmdefault{ccr}
      \tf@TSencodedosf
      \tf@rmfont@concrete    % housekeeping, e.g., sets rm print name
    }{}
  }
}

% Kepler Project fonts -- shared code
%------------------------------------
\newcommand*\tf@loadkpfonts{
  \providebool{tf@kpfontsloaded}
  \ifbool{tf@kpfontsloaded}{\relax}{
    \booltrue{tf@kpfontsloaded}
    \edef\tf@@lfn{jkp}  % lining figures fontname: jkp[l,x][k][f]

    \tf@newbool{tf@@kprm}{false}
    \tf@newbool{tf@@kpmath}{false}
    \ifthenelse{\equal{\tf@rmfont}{kpfonts}}{\booltrue{tf@@kprm}}{}
    \ifthenelse{\equal{\tf@mathfont}{kpfonts}}{\booltrue{tf@@kpmath}}{}
    \ifthenelse{\boolean{tf@@kprm}\AND\equal{\tf@mathfont}{\TF@DEFAULT}}
      {\booltrue{tf@@kpmath}}{}
    \ifthenelse{\boolean{tf@@kpmath}\AND\equal{\tf@rmfont}{\TF@DEFAULT}}
      {\booltrue{tf@@kprm}}{}

    \ifthenelse{\boolean{tf@@kprm}}
      {\renewcommand*\tf@rmprintname{KP Fonts}}{}
    \ifthenelse{\boolean{tf@@kpmath}}
      {\renewcommand*\tf@mathprintname{KP Fonts}}{}

    \ifthenelse{\boolean{tf@@kprm}\AND\NOT\boolean{tf@@kpmath}}
      {\PassOptionsToPackage{nomath}{kpfonts}}{}
    \ifthenelse{\boolean{tf@@kpmath}\AND\NOT\boolean{tf@@kprm}}
      {\PassOptionsToPackage{notext}{kpfonts}}{}

    \ifbool{tf@@kprm}{
      \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}}{
        \PassOptionsToPackage{oldstylenums}{kpfonts}
        \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{
          \PassOptionsToPackage{oldstylenumsmath}{kpfonts}
        }{}
      }{}
      \tf@ifsuboption{oldstyle}{\tf@rmfontoptions}{
        \PassOptionsToPackage{oldstyle}{kpfonts}
      }{
        \tf@ifsuboption{veryoldstyle}{\tf@rmfontoptions}{
          \PassOptionsToPackage{veryoldstyle}{kpfonts}
        }{}
      }
      % NB, rmx trumps light in the kpfonts package. Also note
      % that rmx might not be available under all installs.
      \tf@ifsuboption{rmx}{\tf@rmfontoptions}{
        \PassOptionsToPackage{rmx}{kpfonts}
        \edef\tf@@lfn{\tf@@lfn x}
      }{}
      \tf@ifsuboption{light}{\tf@rmfontoptions}{
        \PassOptionsToPackage{lighttext}{kpfonts}
        \edef\tf@@lfn{\tf@@lfn l}
        \xdef\tf@rmprintname{\tf@rmprintname\ Light}
      }{
        \ifthenelse{\equal{\tf@rmfont}{\TF@DEFAULT}}{
          \tf@ifsuboption{light}{\tf@mathfontoptions}{
            \PassOptionsToPackage{lighttext}{kpfonts}
            \edef\tf@@lfn{\tf@@lfn l}
            \xdef\tf@rmprintname{\tf@rmprintname\ Light}
          }{}
        }{}
      }
      \tf@ifsuboption{largesmallcaps}{\tf@rmfontoptions}{
        \PassOptionsToPackage{largesmallcaps}{kpfonts}
        \edef\tf@@lfn{\tf@@lfn k}
      }{}
      \tf@ifsuboption{nofligatures}{\tf@rmfontoptions}{
        \PassOptionsToPackage{nofligatures}{kpfonts}
        \edef\tf@@lfn{\tf@@lfn f}
      }{}
      \tf@ifsuboption{easyscsl}{\tf@rmfontoptions}{
        \PassOptionsToPackage{easyscsl}{kpfonts}
      }{}
    }{}

    \ifbool{tf@@kpmath}{
      \tf@ifsuboption{light}{\tf@mathfontoptions}{
        \PassOptionsToPackage{lightmath}{kpfonts}
        \xdef\tf@mathprintname{\tf@mathprintname\ Light}
      }{
        \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{
          \tf@ifsuboption{light}{\tf@rmfontoptions}{
            \PassOptionsToPackage{lightmath}{kpfonts}
            \xdef\tf@mathprintname{\tf@mathprintname\ Light}
          }{}
        }{}
      }
      \def\tf@@configurekpoptions##1{
        \tf@ifsuboption{##1}{\tf@mathfontoptions}{
          \PassOptionsToPackage{oldstylenumsmath}{kpfonts}
        }{}
      }
      \forcsvlist{\tf@@configurekpoptions}
        {osf,oldstyle,oldfigures,oldstylefigures,oldstylenums,oldstylenumsmath}
      \@ifpackageloaded{amsmath}{
        \PassOptionsToPackage{noamsmath}{kpfonts}}{}
      \tf@ifsuboption{noamsmath}{\tf@mathfontoptions}{
        \PassOptionsToPackage{noamsmath}{kpfonts}}{}
      \tf@ifsuboption{sfmath}{\tf@mathfontoptions}{
        \PassOptionsToPackage{sfmath}{kpfonts}}{}
      \tf@ifsuboption{sfmathbb}{\tf@mathfontoptions}{
        \PassOptionsToPackage{sfmathbb}{kpfonts}}{}
      \tf@ifsuboption{rmmathbb}{\tf@mathfontoptions}{
        \PassOptionsToPackage{rmmathbb}{kpfonts}}{}
      \tf@ifsuboption{nomathscript}{\tf@mathfontoptions}{
        \PassOptionsToPackage{nomathscript}{kpfonts}}{}
      \tf@ifsuboption{mathcalasscript}{\tf@mathfontoptions}{
        \PassOptionsToPackage{mathcalasscript}{kpfonts}}{}
      \tf@ifsuboption{classicReIm}{\tf@mathfontoptions}{
        \PassOptionsToPackage{classicReIm}{kpfonts}}{}
      \tf@ifsuboption{uprightRoman}{\tf@mathfontoptions}{
        \PassOptionsToPackage{uprightRoman}{kpfonts}}{}
      \tf@ifsuboption{frenchstyle}{\tf@mathfontoptions}{
        \PassOptionsToPackage{frenchstyle}{kpfonts}}{}
      \tf@ifsuboption{upright}{\tf@mathfontoptions}{
        \PassOptionsToPackage{upright}{kpfonts}}{}
      \tf@ifsuboption{oldstylenumsmath}{\tf@mathfontoptions}{
        \PassOptionsToPackage{oldstylenumsmath}{kpfonts}}{}
      \tf@ifsuboption{oldstylemath}{\tf@mathfontoptions}{
        \PassOptionsToPackage{oldstylemath}{kpfonts}}{}
      \tf@ifsuboption{veryoldstylemath}{\tf@mathfontoptions}{
        \PassOptionsToPackage{veryoldstylemath}{kpfonts}}{}
      \tf@ifsuboption{narrowiints}{\tf@mathfontoptions}{
        \PassOptionsToPackage{narrowiints}{kpfonts}}{}
      \tf@ifsuboption{partialup}{\tf@mathfontoptions}{
        \PassOptionsToPackage{partialup}{kpfonts}}{}
      \tf@ifsuboption{widermath}{\tf@mathfontoptions}{
        \PassOptionsToPackage{widermath}{kpfonts}}{}
      \tf@ifsuboption{noDcommand}{\tf@mathfontoptions}{
        \PassOptionsToPackage{noDcommand}{kpfonts}}{}
      \tf@ifsuboption{intlimits}{\tf@mathfontoptions}{
        \PassOptionsToPackage{intlimits}{kpfonts}}{}
      \tf@ifsuboption{nointlimits}{\tf@mathfontoptions}{
        \PassOptionsToPackage{nointlimits}{kpfonts}}{}
      \tf@ifsuboption{fullintlimits}{\tf@mathfontoptions}{
        \PassOptionsToPackage{fullintlimits}{kpfonts}}{}
      \tf@ifsuboption{sumlimits}{\tf@mathfontoptions}{
        \PassOptionsToPackage{sumlimits}{kpfonts}}{}
      \tf@ifsuboption{nosumlimits}{\tf@mathfontoptions}{
        \PassOptionsToPackage{nosumlimits}{kpfonts}}{}
      \tf@ifsuboption{fullsumlimits}{\tf@mathfontoptions}{
        \PassOptionsToPackage{fullsumlimits}{kpfonts}}{}
      \tf@ifsuboption{uprightgreeks}{\tf@mathfontoptions}{
        \PassOptionsToPackage{uprightgreeks}{kpfonts}}{}
      \tf@ifsuboption{slantedGreeks}{\tf@mathfontoptions}{
        \PassOptionsToPackage{slantedGreeks}{kpfonts}}{}
    }{}

    \ifthenelse{\boolean{tf@@kprm}\AND\equal{\tf@sffont}{\TF@DEFAULT}}
      {\renewcommand*\tf@sfprintname{KP Fonts}}
      {\PassOptionsToPackage{nosf}{kpfonts}}

    \ifthenelse{\boolean{tf@@kprm}\AND\equal{\tf@ttfont}{\TF@DEFAULT}}
      {\renewcommand*\tf@ttprintname{KP Fonts}}
      {\PassOptionsToPackage{nott}{kpfonts}}

    \tf@usefontpackage[notextcomp]{kpfonts}
    \tf@define@liningfigures{\tf@@lfn}
  }
}

% Lucida Bright fonts -- shared code
% (TODO: switch for lucimatx package if some kind soul could give me a copy)   % <-- TODO
%---------------------------------------------------------------------------
\tf@newbool{tf@@lbrm}{false}
\tf@newbool{tf@@lbmath}{false}
\tf@newbool{tf@@lbseriftt}{false}

\newcommand*\tf@@loadlucidabrtextwithoutmath{
  % Note: no attempt is made to check for incompatible user options here
  \renewcommand*\rmdefault{hlh}
  \tf@ifsuboption{casual}{\tf@rmfontoptions}{\renewcommand*\rmdefault{hlcn}}{}
  \tf@ifsuboption{fax}{\tf@rmfontoptions}{\renewcommand*\rmdefault{hlx}}{}
  \tf@ifsuboption{seriftt}{\tf@rmfontoptions}{\booltrue{tf@@lbseriftt}}{}

  \def\tf@@lbscale{lucidascale}
  \tf@ifsuboption{nolucidascale}{\tf@rmfontoptions}
    {\def\tf@@lbscale{nolucidascale}}{}
  \tf@ifsuboption{lucidasmallscale}{\tf@rmfontoptions}
    {\def\tf@@lbscale{lucidasmallscale}}{}

  \ifthenelse{\equal{\tf@@lbscale}{nolucidascale}}{% strictly redundant
    \def\DeclareLucidaFontShape##1##2##3##4##5##6{%
      \DeclareFontShape{##1}{##2}{##3}{##4}{<->##5}{##6}%
    }
  }{}

  \ifthenelse{\equal{\tf@@lbscale}{lucidascale}}{
    \def\DeclareLucidaFontShape##1##2##3##4##5##6{%
      \DeclareFontShape{##1}{##2}{##3}{##4}{%
        <-5.5>s*[1.04]##5%
        <5.5-6.5>s*[1.02]##5%
        <6.5-7.5>s*[.99]##5%
        <7.5-8.5>s*[.97]##5%
        <8.5-9.5>s*[.96]##5%
        <9.5-10.5>s*[.95]##5%
        <10.5-11.5>s*[.94]##5%
        <11.5-13>s*[.93]##5%
        <13-15.5>s*[.92]##5%
        <15.5-18.5>s*[.91]##5%
        <18.5-22.5>s*[.9]##5%
        <22.5->s*[.89]##5%
      }{##6}%
    }
  }{}

  \ifthenelse{\equal{\tf@@lbscale}{lucidasmallscale}}{
    \def\DeclareLucidaFontShape##1##2##3##4##5##6{%
      \DeclareFontShape{##1}{##2}{##3}{##4}{%
        <-5.5>s*[.98]##5%
        <5.5-6.5>s*[.96]##5%
        <6.5-7.5>s*[.94]##5%
        <7.5-8.5>s*[.92]##5%
        <8.5-9.5>s*[.91]##5%
        <9.5-10.5>s*[.9]##5%
        <10.5-11.5>s*[.89]##5%
        <11.5-13>s*[.88]##5%
        <13-15.5>s*[.87]##5%
        <15.5-18.5>s*[.86]##5%
        <18.5-22.5>s*[.85]##5%
        <22.5->s*[.84]##5%
      }{##6}%
    }
  }{}

  \normalfont
  \tf@ifsuboption{calligraphic}{\tf@rmfontoptions}{
    \DeclareFontShape\encodingdefault\rmdefault{m}{it}%
      {<->ssub*hlce/m/it}{}
  }{}

  \tf@ifsuboption{handwriting}{\tf@rmfontoptions}{
    \DeclareFontShape\encodingdefault\rmdefault{m}{it}%
      {<->ssub*hlcw/m/it}{}%
    \DeclareFontShape\encodingdefault\rmdefault{b}{it}%
      {<->ssub*hlcw/m/it}{}
  }{}

  \tf@ifsuboption{altbullet}{\tf@rmfontoptions}{
    \DeclareTextCommand\textbullet\encodingdefault%
      {\UseTextSymbol{OMS}\textbullet}
  }{}
}

\newcommand*\tf@@loadlucidabrtextwithmath{
  \@ifpackageloaded{\tf@@lbpkg}{\relax}{
    % Process options. Note that we don't care whether the user requests these
    % through rm or math suboptions -- it's all the same to us. E.g., the user
    % can request mathitalic1 in rm suboptions. Equally, no attempt is made to
    % check for incompatible user options, e.g., whether the user has
    % simultaneously specified expert and noexpert. It's up to users to do the
    % right thing (otherwise lucidabr.sty would already be coded against this
    % sort of problem).
    \def\tf@@lbprocessopt##1{
      \tf@ifsuboption{##1}{\tf@rmfontoptions}{
        \PassOptionsToPackage{##1}{\tf@@lbpkg}
      }{
        \tf@ifsuboption{##1}{\tf@mathfontoptions}{
          \PassOptionsToPackage{##1}{\tf@@lbpkg}
        }{}
      }
    }
    \ifthenelse{\boolean{tf@@lbrm}}{
      \forcsvlist{\tf@@lbprocessopt}
        {expert,noexpert,lucidascale,nolucidascale,lucidasmallscale,%
         mathitalic1,mathitalic2,mathitalic3,slantedgreek,%
         uprightgreek,vargreek,% these might, or might not, cause trouble
         noamssymbols,OT1,T1,LY1,seriftt,%
         fax,casual,calligraphic,handwriting,altbullet,%
         errorshow,warningshow,nofontinfo}
    }{
      \forcsvlist{\tf@@lbprocessopt}
        {expert,noexpert,nolucidascale,lucidascale,lucidasmallscale,%
         mathitalic1,mathitalic2,mathitalic3,slantedgreek,%
         uprightgreek,vargreek,% these might, or might not, cause trouble
         noamssymbols,OT1,T1,LY1,errorshow,warningshow,nofontinfo}
    }

    \tf@ifsuboption{seriftt}{\tf@rmfontoptions}{\booltrue{tf@@lbseriftt}}{}
    \tf@ifsuboption{seriftt}{\tf@mathfontoptions}{\booltrue{tf@@lbseriftt}}{}

    % Allow preloading amsmath (new -- not one of lucida's native package
    % options). For examples, see lucida-amsmath.pdf in lucidabr package.
    \tf@ifsuboption{amsmath}{\tf@mathfontoptions}
      {\tf@usefontpackage{amsmath}}{}

    \tf@usefontpackage{\tf@@lbpkg}
  }
}

\newcommand*\tf@loadlucidabr{
  \ifthenelse{\equal{\tf@rmfont}{lucidabright}}{\booltrue{tf@@lbrm}}{}
  \ifthenelse{\equal{\tf@mathfont}{lucidabright}}{\booltrue{tf@@lbmath}}{}
  \ifthenelse{\boolean{tf@@lbrm}\AND\equal{\tf@mathfont}{\TF@DEFAULT}}
    {\booltrue{tf@@lbmath}}{}
  \ifthenelse{\boolean{tf@@lbmath}\AND\equal{\tf@rmfont}{\TF@DEFAULT}}
    {\booltrue{tf@@lbrm}}{}

  \ifbool{tf@@lbrm}{\renewcommand*\tf@rmprintname{Lucida Bright}}{}
  \ifbool{tf@@lbmath}{\renewcommand*\tf@mathprintname{Lucida Bright}}{}

  \ifbool{tf@@lbmath}{
    \ifbool{tf@@lbrm}
      {\def\tf@@lbpkg{lucidabr}}
      {\def\tf@@lbpkg{lucbmath}}
    \tf@@loadlucidabrtextwithmath
  }{
    \tf@@loadlucidabrtextwithoutmath
  }

  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@lucidabright}{}
  \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{\tf@ttfont@lucidabright}{}

  \ifbool{tf@@lbrm}{\tf@TSencodedosf}{}
}

% Mathpazo (aka palatino with pazo math fonts) -- shared code
%------------------------------------------------------------
\newcommand*\tf@loadmathpazo{
  \providebool{tf@mathpazoloaded}
  \ifbool{tf@mathpazoloaded}{\relax}{
    \booltrue{tf@mathpazoloaded}

    % ward off possible clash of glyphs
    \tf@undefinecommands{\mathdollar}

    \tf@ifsuboption{slantedGreek}{\tf@mathfontoptions}
      {\PassOptionsToPackage{slantedGreek}{mathpazo}}{}
    \tf@ifsuboption{noBBpl}{\tf@mathfontoptions}
      {\PassOptionsToPackage{noBBpl}{mathpazo}}{}
    \let\oldoldstylenums\oldstylenums  % before mathpazo hijacks this
    \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@LF}}{
      \tf@usefontpackage[sc]{mathpazo}
    }{
      \tf@usefontpackage[sc,osf]{mathpazo}
      \tf@define@liningfigures{pplx}
    }
    \ifthenelse{\NOT\equal{\tf@rmfont}{palatino}
            \AND\NOT\equal{\tf@rmfont}{\TF@DEFAULT}}{
      \let\oldstylenums\oldoldstylenums
    }{}
    \tf@ifsuboption{osf}{\tf@mathfontoptions}{
      % Experimental mathpazo old style figures. Covers
      % normal and italic but not bold or bold italic.
      % Probably best to avoid.
      \DeclareSymbolFont{operators}     {OT1}{pplj}{m}{n}
      \SetSymbolFont{operators}{bold}   {OT1}{pplj}{b}{n}
      \DeclareMathAlphabet{\mathit}     {OT1}{pplj}{m}{it}
      \SetMathAlphabet{\mathit}{bold}   {OT1}{pplj}{b}{it}
    }{}
  }
}

% TX Fonts (including New TX) -- shared code
%-------------------------------------------
\newcommand*\tf@loadtxfonts{
  % Precondition: at least one of \tf@mathfont and \tf@rmfont equals `txfonts'
  \providebool{tf@txfontsloaded}
  \ifbool{tf@txfontsloaded}{\relax}{
    \booltrue{tf@txfontsloaded}

    % determine whether we should  load (standard) tx or new tx fonts
    \tf@newbool{newtxmath}{false}
    \tf@newbool{newtxtext}{false}
    \ifthenelse{\equal{\tf@mathfont}{txfonts}}{
      \tf@ifsuboption{new}{\tf@mathfontoptions}{\booltrue{newtxmath}}{}
    }{
      \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{
        \tf@ifsuboption{new}{\tf@rmfontoptions}{\booltrue{newtxmath}}{}
      }{}
    }
    \ifthenelse{\equal{\tf@rmfont}{txfonts}}{
      \tf@ifsuboption{new}{\tf@rmfontoptions}{\booltrue{newtxtext}}{}
    }{
      \ifthenelse{\equal{\tf@rmfont}{\TF@DEFAULT}}{
        \tf@ifsuboption{new}{\tf@mathfontoptions}{\booltrue{newtxtext}}{}
      }{}
    }

    \ifthenelse{\equal{\tf@mathfont}{txfonts}\OR\equal{\tf@mathfont}{\TF@DEFAULT}}{
      \ifbool{newtxmath}{
        \def\tf@@configuretxoptions##1{
          \tf@ifsuboption{##1}{\tf@mathfontoptions}{
            \PassOptionsToPackage{##1}{newtxmath}
          }{}
        }
        \forcsvlist{\tf@@configuretxoptions}{varg,libertine,cmintegrals,%
          uprightGreek,cmbraces,varbb,nosymbolsc,amssymbols,noamssymbols}
        \tf@usefontpackage{newtxmath}
      }{
        \tf@usefontpackage{txfonts}
      }
      \tf@ifsuboption{ptmxitalics}{\tf@mathfontoptions}{
        % Use ptmx font's quite differently kerned italic/slant math letters.
        % See van Bevern's discussion at:
        % http://rvb.mytanet.de/times-with-normal-mathcal-and-summation-sign.shtml
        \DeclareSymbolFont{letters}{OML}{ztmcm}{m}{it}
      }{}
    }{}

    \ifthenelse{\equal{\tf@rmfont}{txfonts}\OR\equal{\tf@rmfont}{\TF@DEFAULT}}{
      \ifbool{newtxtext}{
        \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}}{
          \tf@usefontpackage[osf]{newtxtext}
          \tf@define@liningfigures{ntxr}
        }{\tf@usefontpackage{newtxtext}}
      }{
        \renewcommand*\rmdefault{txr}
        \tf@TSencodedosf
      }
    }{}

    \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@txfonts}{}
    \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{\tf@ttfont@txfonts}{}
  }{}
}

% Text figures typeface -- unlike other typeface families, text
% figures configuration is not sensitive to font load ordering
% =============================================================
\TF@PackageDebugInfo{Configuring text figures load commands...}

% Configure textfigures method and associated values
%---------------------------------------------------
% `\tf@osf@method' resolves to one of the following values:
%   TF@OSF@LF: normal typesetting, \textstylenums command and textnums
%              environment => lining figures
%   TF@OSF@JF: normal typesetting, \textstylenums and textnums => old style
%              figures sourced from `j' family
%   TF@OSF@XF: normal typesetting => lining figures
%              \textstylenums and textnums => old style figures sourced from
%              substitute font (\tf@textfiguresfont contains the name of the
%              substitute font)
%   TF@OSF@TS: normal typesetting => lining figures
%              \textstylenums and textnums => old style figures sourced from
%              TS1 font mappings
%   TF@OSF@SC: normal typesetting => lining figures
%              \textstylenums and textnums => old style figures sourced from
%              SmallCap family
%   TF@OSF@NF: use native font -- do nothing

\newcommand*\tf@osf@method{TF@OSF@NF}

% Default -- no-op
\newtypeface{\TF@DEFAULT}{\TF@DEFAULTPRINTNAME}{textfigures}{
  \renewcommand*\tf@osf@method{\TF@OSF@NF}
}

% Lining style text figures
\newtypeface[lf,lsf,lining,liningstyle,liningstylefigures,false]
            {liningfigures}
            {Lining Style Figures}
            {textfigures}{
  \renewcommand*\tf@osf@method{\TF@OSF@LF}
}

% Old style text figures
\newtypeface[osf,oldstyle,oldfigures,oldstylefigures,true]
            {textfigures}
            {Old Style Figures}
            {textfigures}{
  \renewcommand*\tf@osf@method{\TF@OSF@JF} % \tf@osf@method is often set to
                                           % \TF@OSF@TS or \TF@OSF@SC later on
}

% Substitute OSF font name (literal) used in text figures font declarations
\newcommand*\tf@substosffont{tf@substosffont}

% \newtypeface textfigures preamble (see examples, below)
\newcommand*\tf@initialisetextfiguresfont[1]{
  % #1 is the substitute osf font encoding to use (T1 in all likelihood)
  \renewcommand*\tf@osf@method{\TF@OSF@XF}
  \newcommand*\tf@substosffontencoding{#1}
  \let\oldencodingdefault\encodingdefault
  \usepackage[\tf@substosffontencoding]{fontenc}
  \let\encodingdefault\oldencodingdefault
  \newcommand*\tf@s{}
  \scaletypeface{textfigures}{\edef\tf@s{[\tf@textfiguresscalefactor]}}
  \DeclareFontFamily{\tf@substosffontencoding}{\tf@substosffont}{}
  % Redefine \DeclareSizeFunction (restored in \newtypeface, defined
  % above). And, no, we can't apply  `s*' in \tf@s in this case.
  \let\oldDeclareSizeFunction\DeclareSizeFunction
  \DeclareSizeFunction{}{\empty@sfcnt\@font@info}
}

% Substitute OSF \DeclareFontShape helper
\newcommand*\tf@DeclareOsfFontShape[3]{
  \DeclareFontShape{\tf@substosffontencoding}{\tf@substosffont}
    {#1}{#2}{ <-> \tf@s #3}{}
}

% Adobe Minion Pro text figures
\newtypeface{adobeminionpro}{Adobe Minion Pro}{textfigures}{
  \tf@initialisetextfiguresfont{T1}

  % proportional vs tabular OSF (don't do tabular -- it would be bad!)
  \edef\tf@@mpsuffix{osf-\tf@substosffontencoding}
  \tf@ifsuboption{tabular}{\tf@textfiguresfontoptions}{
    \edef\tf@@mpsuffix{tosf-\tf@substosffontencoding}
  }{
    \tf@ifsuboption{tab}{\tf@textfiguresfontoptions}{
      \edef\tf@@mpsuffix{tosf-\tf@substosffontencoding}
    }{}
  }
  \tf@DeclareOsfFontShape{m} {n} {MinionPro-Regular-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{m} {it}{MinionPro-It-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{m} {sl}{MinionPro-It-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{m} {sc}{MinionPro-Regular-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{mb}{n} {MinionPro-Medium-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{mb}{it}{MinionPro-MediumI-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{mb}{sl}{MinionPro-MediumIt-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{b} {n} {MinionPro-Bold-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{b} {it}{MinionPro-BoldIt-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{b} {sl}{MinionPro-BoldIt-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{bx}{n} {MinionPro-Bold-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{bx}{it}{MinionPro-BoldIt-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{bx}{sl}{MinionPro-BoldIt-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{sb}{n} {MinionPro-Semibold-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{sb}{it}{MinionPro-SemiboldIt-\tf@@mpsuffix}
  \tf@DeclareOsfFontShape{sb}{sl}{MinionPro-SemiboldIt-\tf@@mpsuffix}
}

% Day Roman text figures -- here for completeness only
\newtypeface[dayrom]{dayroman}{Day Roman}{textfigures}{
  \tf@initialisetextfiguresfont{T1}
  \tf@DeclareOsfFontShape{m}{n}{dayromr8t}
}

% KP Fonts text figures
\newtypeface[kp,kepler]{kpfonts}{KP Fonts}{textfigures}{                       % TODO: condensed
  \tf@initialisetextfiguresfont{T1}
  \tf@ifsuboption{light}{\tf@textfiguresfontoptions}{
    \tf@DeclareOsfFontShape{m} {n}    {jkplosnmn8t}
    \tf@DeclareOsfFontShape{m} {it}   {jkplosnmit8t}
    \tf@DeclareOsfFontShape{m} {sl}   {jkplosnmsl8t}
    \tf@DeclareOsfFontShape{m} {sc}   {jkplosnmsc8t}
    \tf@DeclareOsfFontShape{m} {scsl} {jkplosnmscsl8t}
    \tf@DeclareOsfFontShape{b} {n}    {jkplosnbn8t}
    \tf@DeclareOsfFontShape{b} {it}   {jkplosnbit8t}
    \tf@DeclareOsfFontShape{b} {sl}   {jkplosnbsl8t}
    \tf@DeclareOsfFontShape{b} {sc}   {jkplosnbsc8t}
    \tf@DeclareOsfFontShape{b} {scsl} {jkplosnbscsl8t}
    \tf@DeclareOsfFontShape{bx}{n}    {jkplosnbxn8t}
    \tf@DeclareOsfFontShape{bx}{it}   {jkplosnbxit8t}
    \tf@DeclareOsfFontShape{bx}{sl}   {jkplosnbxsl8t}
    \tf@DeclareOsfFontShape{bx}{sc}   {jkplosnbxsc8t}
    \tf@DeclareOsfFontShape{bx}{scsl} {jkplosnbxscsl8t}
  }{
    \tf@DeclareOsfFontShape{m} {n}    {jkposnmn8t}
    \tf@DeclareOsfFontShape{m} {it}   {jkposnmit8t}
    \tf@DeclareOsfFontShape{m} {sl}   {jkposnmsl8t}
    \tf@DeclareOsfFontShape{m} {sc}   {jkposnmsc8t}
    \tf@DeclareOsfFontShape{m} {scsl} {jkposnmscsl8t}
    \tf@DeclareOsfFontShape{b} {n}    {jkposnbn8t}
    \tf@DeclareOsfFontShape{b} {it}   {jkposnbit8t}
    \tf@DeclareOsfFontShape{b} {sl}   {jkposnbsl8t}
    \tf@DeclareOsfFontShape{b} {sc}   {jkposnbsc8t}
    \tf@DeclareOsfFontShape{b} {scsl} {jkposnbscsl8t}
    \tf@DeclareOsfFontShape{bx}{n}    {jkposnbxn8t}
    \tf@DeclareOsfFontShape{bx}{it}   {jkposnbxit8t}
    \tf@DeclareOsfFontShape{bx}{sl}   {jkposnbxsl8t}
    \tf@DeclareOsfFontShape{bx}{sc}   {jkposnbxsc8t}
    \tf@DeclareOsfFontShape{bx}{scsl} {jkposnbxscsl8t}
    \tf@DeclareOsfFontShape{l} {n}    {jkplosnmn8t}
    \tf@DeclareOsfFontShape{l} {it}   {jkplosnmit8t}
    \tf@DeclareOsfFontShape{l} {sl}   {jkplosnmsl8t}
    \tf@DeclareOsfFontShape{l} {sc}   {jkplosnmsc8t}
    \tf@DeclareOsfFontShape{l} {scsl} {jkplosnmscsl8t}
    \tf@DeclareOsfFontShape{sb}{n}    {jkplosnbn8t}
    \tf@DeclareOsfFontShape{sb}{it}   {jkplosnbit8t}
    \tf@DeclareOsfFontShape{sb}{sl}   {jkplosnbsl8t}
    \tf@DeclareOsfFontShape{sb}{sc}   {jkplosnbsc8t}
    \tf@DeclareOsfFontShape{sb}{scsl} {jkplosnbscsl8t}
    \tf@DeclareOsfFontShape{sbx}{n}   {jkplosnbxn8t}
    \tf@DeclareOsfFontShape{sbx}{it}  {jkplosnbxit8t}
    \tf@DeclareOsfFontShape{sbx}{sl}  {jkplosnbxsl8t}
    \tf@DeclareOsfFontShape{sbx}{sc}  {jkplosnbxsc8t}
    \tf@DeclareOsfFontShape{sbx}{scsl}{jkplosnbxscsl8t}
  }
}

% Latin Modern text figures
\newtypeface[lm,lmodern]{latinmodern}{Latin Modern}{textfigures}{
  % This is a bit dodgy since we're referring to TS1 tables regardless of
  % our font encoding. Nevertheless, for numerals (and only numerals)
  % substitution it should work out well enough.
  \tf@initialisetextfiguresfont{T1}
  \DeclareFontShape{\tf@substosffontencoding}{\tf@substosffont}{m}{n}{
    <-5.5>    \tf@s ts1-lmr5   <5.5-6.5> \tf@s ts1-lmr6
    <6.5-7.5> \tf@s ts1-lmr7   <7.5-8.5> \tf@s ts1-lmr8
    <8.5-9.5> \tf@s ts1-lmr9   <9.5-11>  \tf@s ts1-lmr10
    <11-15>   \tf@s ts1-lmr12  <15->     \tf@s ts1-lmr17 }{}
  \DeclareFontShape{\tf@substosffontencoding}{\tf@substosffont}{m}{it}{
    <-7.5>    \tf@s ts1-lmri7  <7.5-8.5> \tf@s ts1-lmri8
    <8.5-9.5> \tf@s ts1-lmri9  <9.5-11>  \tf@s ts1-lmri10
    <11->     \tf@s ts1-lmri12 }{}
  \DeclareFontShape{\tf@substosffontencoding}{\tf@substosffont}{m}{sl}{
    <-8.5>    \tf@s ts1-lmro8  <8.5-9.5> \tf@s ts1-lmro9
    <9.5-11>  \tf@s ts1-lmro10 <11-15>   \tf@s ts1-lmro12
    <15->     \tf@s ts1-lmro17 }{}
  \tf@DeclareOsfFontShape{m}{sc}  {ts1-lmcsc10}
  \tf@DeclareOsfFontShape{m}{ui}  {ts1-lmu10}
  \tf@DeclareOsfFontShape{m}{scsl}{ts1-lmcsco10}
  \tf@DeclareOsfFontShape{b}{n}   {ts1-lmb10}
  \tf@DeclareOsfFontShape{b}{it}  {ts1-lmbo10}
  \tf@DeclareOsfFontShape{b}{sl}  {ts1-lmbo10}
  \DeclareFontShape{\tf@substosffontencoding}{\tf@substosffont}{bx}{n}{
    <-5.5>    \tf@s ts1-lmbx5  <5.5-6.5> \tf@s ts1-lmbx6
    <6.5-7.5> \tf@s ts1-lmbx7  <7.5-8.5> \tf@s ts1-lmbx8
    <8.5-9.5> \tf@s ts1-lmbx9  <9.5-11>  \tf@s ts1-lmbx10
    <11->     \tf@s ts1-lmbx12}{}
  \tf@DeclareOsfFontShape{bx}{it} {ts1-lmbxi10}
  \tf@DeclareOsfFontShape{bx}{sl} {ts1-lmbxo10}
}

% Libertine text figures -- NB, see comments with libertine (legacy) rm
\newtypeface{libertine}{Libertine}{textfigures}{
  \tf@initialisetextfiguresfont{T1}
  %---------------------------------------------------------------------
  % NOTE! read the comments next to libertine in the Roman fonts section
  %---------------------------------------------------------------------
  % ***proportional*** (not tabular) old style figures
  \tf@DeclareOsfFontShape{m}{ic}  {fxlric-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{m}{it}  {fxlri-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{m}{n}   {fxlr-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{m}{sc}  {fxlrc-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{m}{sl}  {fxlro-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{b}{ic}  {fxlbic-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{b}{it}  {fxlbi-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{b}{n}   {fxlz-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{b}{sc}  {fxlbc-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{b}{sl}  {fxlbo-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{bx}{ic} {fxlbic-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{bx}{it} {fxlbi-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{bx}{n}  {fxlz-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{bx}{sc} {fxlbc-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{bx}{sl} {fxlbo-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{d}{it}  {fxldro-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{d}{n}   {fxldr-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{d}{sc}  {fxldrc-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{d}{sl}  {fxldro-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{z}{ic}  {fxlzic-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{z}{it}  {fxlzi-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{z}{n}   {fxlz-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{z}{sc}  {fxlzc-\tf@substosffontencoding os}
  \tf@DeclareOsfFontShape{z}{sl}  {fxlzo-\tf@substosffontencoding os}
}

% Lucida Bright text figures
\newtypeface[lucidabr,lucida]{lucidabright}{Lucida Bright}{textfigures}{
  \tf@initialisetextfiguresfont{T1}
  \tf@DeclareOsfFontShape{m}{n}   {hlhr8c}
  \tf@DeclareOsfFontShape{m}{it}  {hlhri8c}
  \tf@DeclareOsfFontShape{m}{sl}  {hlhro8c}
  \tf@DeclareOsfFontShape{m}{sc}  {hlhr8c}
  \tf@DeclareOsfFontShape{b}{n}   {hlhb8c}
  \tf@DeclareOsfFontShape{b}{it}  {hlhbi8c}
  \tf@DeclareOsfFontShape{b}{sl}  {hlhbi8c}
  \tf@DeclareOsfFontShape{b}{sc}  {hlhb8c}
  \tf@DeclareOsfFontShape{bx}{n}  {hlhb8c}
  \tf@DeclareOsfFontShape{bx}{it} {hlhbi8c}
  \tf@DeclareOsfFontShape{bx}{sl} {hlhbi8c}
  \tf@DeclareOsfFontShape{bx}{sc} {hlhb8c}
}

% Palatino text figures
\newtypeface{palatino}{Palatino}{textfigures}{
  \tf@initialisetextfiguresfont{T1}
  \tf@DeclareOsfFontShape{m} {it} {pplri9d}
  \tf@DeclareOsfFontShape{m} {n}  {pplr9d}
  \tf@DeclareOsfFontShape{m} {sc} {pplrc9d}
  \tf@DeclareOsfFontShape{m} {sl} {pplri9d}
  \tf@DeclareOsfFontShape{b} {it} {pplbi9d}
  \tf@DeclareOsfFontShape{b} {n}  {pplb9d}
  \tf@DeclareOsfFontShape{b} {sl} {pplbi9d}
  \tf@DeclareOsfFontShape{bx}{it} {pplbi9d}
  \tf@DeclareOsfFontShape{bx}{n}  {pplb9d}
  \tf@DeclareOsfFontShape{bx}{sl} {pplbi9d}
}

% Times Roman text figures (txfonts)
\newtypeface{times}{Times Roman}{textfigures}{
  \tf@initialisetextfiguresfont{T1}
  \tf@DeclareOsfFontShape{m}{n}   {tcxr}
  \tf@DeclareOsfFontShape{m}{sc}  {tcxr}
  \tf@DeclareOsfFontShape{m}{sl}  {tcxsl}
  \tf@DeclareOsfFontShape{m}{it}  {tcxi}
  \tf@DeclareOsfFontShape{m}{ui}  {tcxi}
  \tf@DeclareOsfFontShape{b}{n}   {tcxb}
  \tf@DeclareOsfFontShape{b}{sc}  {tcxb}
  \tf@DeclareOsfFontShape{b}{sl}  {tcxbsl}
  \tf@DeclareOsfFontShape{b}{it}  {tcxbi}
  \tf@DeclareOsfFontShape{b}{ui}  {tcxbi}
  \tf@DeclareOsfFontShape{bx}{n}  {tcxb}
  \tf@DeclareOsfFontShape{bx}{sc} {tcxb}
  \tf@DeclareOsfFontShape{bx}{sl} {tcxbsl}
  \tf@DeclareOsfFontShape{bx}{it} {tcxbi}
  \tf@DeclareOsfFontShape{bx}{ui} {tcxbi}
}

% Symbols typeface -- highly sensitive to font load ordering, particularly
% to math -> symbols / symbols -> math font load order
% =======================================================================
\TF@PackageDebugInfo{Configuring symbols load commands...}

% Default -- no-op
\newtypeface{\TF@DEFAULT}{}{symbols}{
  \ifthenelse{\equal{\tf@symbolsprintname}{undefined}}{
    \renewcommand*\tf@symbolsprintname{\TF@DEFAULTPRINTNAME}
  }{}
}

% AMS symbols
\newtypeface[ams]{amssymb}{}{symbols}{
  \ifthenelse{\equal{\tf@rmfont}{adobeminionpro}
          \AND\equal{\tf@mathfont}{\TF@DEFAULT}}{
    \TF@PackageWarningNoLine{%
       Package option `symbolstypeface=\tf@symbolsfontname' conflicts
       \MessageBreak with option combination:\MessageBreak
       \space\space`typeface=\tf@rmfontname', and\MessageBreak
       \space\space`mathtypeface=\tf@mathfontname'.\MessageBreak
       Option `symbolstypeface=\tf@symbolsfontname' ignored}
      \renewcommand*\tf@symbolsprintname{\TF@DEFAULTPRINTNAME}
  }{
    \ifthenelse{\equal{\tf@mathfont}{adobeminionpro}
             \OR\equal{\tf@mathfont}{mathdesign}}{
      \TF@PackageWarningNoLine{%
         Package option `mathtypeface=\tf@mathfontname'\MessageBreak
         conflicts with `symbolstypeface=\tf@symbolsfontname'.\MessageBreak
         Option `symbolstypeface=\tf@symbolsfontname' ignored}
      \renewcommand*\tf@symbolsprintname{\TF@DEFAULTPRINTNAME}
    }{
      \tf@usefontpackage{amssymb}
      \renewcommand*\tf@symbolsprintname{AMS Symbols}
      \tf@ifsuboption{nofixmath}{\tf@symbolsfontoptions}{
      }{
        \usepackage{fixmath}  % Italic uppercase Greek. May be overridden by
                              % some maths packages later in the load stream
      }
    }
  }
}

% FD Symbol
\newtypeface[fd]{fdsymbol}{FD Symbol}{symbols}{
  % bypass a few commonly troublesome namespace collisions
  \tf@undefinecommands{\mid,\surd}

  \newcommand*\tf@fdopt@normalweight{Book}
  \newcommand*\tf@fdopt@boldweight{Medium}
  \newcommand*\tf@fdopt@largedelims{false}

  \tf@ifsuboption{normalweightRegular}{\tf@symbolsfontoptions}{
    \renewcommand*\tf@fdopt@normalweight{Regular}
  }{
    \tf@ifsuboption{normalweightAuto}{\tf@symbolsfontoptions}{
      \renewcommand*\tf@fdopt@normalweight{auto}
    }{}
  }

  \tf@ifsuboption{boldweightMedium}{\tf@symbolsfontoptions}{
    \renewcommand*\tf@fdopt@boldweight{Regular}
  }{
    \tf@ifsuboption{boldweightAuto}{\tf@symbolsfontoptions}{
      \renewcommand*\tf@fdopt@boldweight{auto}
    }{}
  }

  \tf@ifsuboption{largedelims}{\tf@symbolsfontoptions}{
    \renewcommand*\tf@fdopt@largedelims{true}
  }{}

  % FD Symbol loads AMS Math. Preload amsmath here to ensure
  % we can load it without package options clashes. This
  % reverses the usual symbols/math loading order.
  \ifthenelse{\equal{\tf@mathfont}{amsfonts}}{
    \tf@mathfont@amsfonts
  }{}

  \tf@usefontpackage[normalweight=\tf@fdopt@normalweight,
                     boldweight=\tf@fdopt@boldweight,
                     scale=1,
                     largedelims=\tf@fdopt@largedelims]{fdsymbol}
}

% Mathabx. Standard mathabx (ported from mf) is a bitmap/raster font, and
% therefore is not scalable out-of-the-box. Accordingly, you might see
% several font size rescaling warnings. Additionally, mathabx does not
% always play peacefully with other packages, potentially leading to
% symbol already defined issues. Still, it offers a good number of math
% symbols not easily found elsewhere.
\newtypeface[abx]{mathabx}{Math abx}{symbols}{
  \tf@usefontpackage{mathabx}
}

% Adobe Minion Pro compatible symbols
\newtypeface[mn]{mnsymbol}{MnSymbol}{symbols}{
  \tf@undefinecommands{\mathcal}

  % MnSymbol loads AMS Math and textcomp. Preload amsmath here
  % to ensure we load it without options clashes. This reverses the
  % usual symbols/math loading order.
  \ifthenelse{\equal{\tf@mathfont}{amsfonts}}{
    \tf@mathfont@amsfonts
  }{}
  % We don't provide MnSymbol cmsy and abx package calligraphic font
  % options here since they tend to be too fine grained, too unlikely
  % to produce noticeable typographic differences and too problematic
  % for ordinary users. Advanced users will almost certainly not want
  % to select these options for those same reasons.
  \tf@usefontpackage{MnSymbol}
}

% Adobe Myriad Pro compatible symbols
\newtypeface[md]{mdsymbol}{MdSymbol}{symbols}{
  \tf@ifsuboption{Regular}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{normalweight=Regular}{mdsymbol}}{}
  \tf@ifsuboption{regular}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{normalweight=Regular}{mdsymbol}}{}
  \tf@ifsuboption{Light}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{normalweight=Light}{mdsymbol}}{}
  \tf@ifsuboption{light}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{normalweight=Light}{mdsymbol}}{}
  \tf@ifsuboption{autolight}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{normalweight=autolight}{mdsymbol}}{}
  \tf@ifsuboption{autoregular}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{normalweight=autoregular}{mdsymbol}}{}

  \tf@ifsuboption{Semibold}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{boldweight=Semibold}{mdsymbol}}{}
  \tf@ifsuboption{semibold}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{boldweight=Semibold}{mdsymbol}}{}
  \tf@ifsuboption{Bold}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{boldweight=Bold}{mdsymbol}}{}
  \tf@ifsuboption{bold}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{boldweight=Bold}{mdsymbol}}{}
  \tf@ifsuboption{autosemibold}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{boldweight=autosemibold}{mdsymbol}}{}

  \tf@ifsuboption{onlysansmath}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{onlysansmath=true}{mdsymbol}}{}
  \tf@ifsuboption{retainmissing}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{retainmissing=true}{mdsymbol}}{}
  \tf@ifsuboption{largedelims}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{largedelims=true}{mdsymbol}}{}

  \tf@ifsuboption{scale}{\tf@symbolsfontoptions}
    {\PassOptionsToPackage{scale=\tf@nextsuboption}{mdsymbol}}{}

  % MdSymbol loads AMS Math. Preload amsmath here to ensure
  % we can load it without package options clashes. This
  % reverses the usual symbols/math loading order.
  \ifthenelse{\equal{\tf@mathfont}{amsfonts}}{
    \tf@mathfont@amsfonts
  }{}

  \tf@usefontpackage{mdsymbol}
}

% Math typeface -- highly sensitive to font load ordering, particularly
% to math -> symbols / symbols -> math font load order
% =====================================================================
\TF@PackageDebugInfo{Configuring math load commands...}

% Default -- no-op
\newtypeface{\TF@DEFAULT}{}{math}{
  \ifthenelse{\equal{\tf@mathprintname}{undefined}}{
    \renewcommand*\tf@mathprintname{\TF@DEFAULTPRINTNAME}
  }{}
}

% Math -- AMS Math
\newtypeface[ams,amsmath]{amsfonts}{AMS Math}{math}{
  \@ifpackageloaded{amsmath}{\relax}{
    % avoid a bunch of possible symbols namespace collisions
    \tf@undefinecommands{
      \iint,\iiint,\dddot,\ddddot,
      \overleftrightarrow,\underleftrightarrow,
      \underrightarrow,\underleftarrow,
    }
    \tf@ifsuboption{tbtags}{\tf@mathfontoptions}
      {\PassOptionsToPackage{tbtags}{amsmath}}{}
    \tf@ifsuboption{nosumlimits}{\tf@mathfontoptions}
      {\PassOptionsToPackage{nosumlimits}{amsmath}}{}
    \tf@ifsuboption{intlimits}{\tf@mathfontoptions}
      {\PassOptionsToPackage{intlimits}{amsmath}}{}
    \tf@ifsuboption{nonamelimits}{\tf@mathfontoptions}
      {\PassOptionsToPackage{nonamelimits}{amsmath}}{}
    \tf@usefontpackage{amsmath}
    }
  \tf@ifsuboption{donotfixamsmathbugs}{\tf@mathfontoptions}
    {}{\usepackage{mathtools}}
}

% Math -- Antykwa Torunska
\newtypeface[anttor,torunska]{antykwatorunska}{}{math}{
  \tf@loadantykwatorunska
}

% Math -- Arev Sans (Bitsream Vera Sans tuned for maths)
\newtypeface[arev]{arevmath}{Arev Math}{math}{
  \tf@ifsuboption{origletters}{\tf@mathfontoptions}
    {\PassOptionsToPackage{origletters}{arevmath}}{}
  \tf@ifsuboption{vara}{\tf@mathfontoptions}
    {\PassOptionsToPackage{vara}{arevmath}}{}
  \tf@ifsuboption{vari}{\tf@mathfontoptions}
    {\PassOptionsToPackage{vari}{arevmath}}{}
  \tf@ifsuboption{varI}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varI}{arevmath}}{}
  \tf@ifsuboption{varf}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varf}{arevmath}}{}
  \tf@ifsuboption{oldf}{\tf@mathfontoptions}
    {\PassOptionsToPackage{oldf}{arevmath}}{}
  \tf@ifsuboption{varl}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varl}{arevmath}}{}
  \tf@ifsuboption{varu}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varu}{arevmath}}{}
  \tf@ifsuboption{varv}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varv}{arevmath}}{}
  \tf@ifsuboption{varw}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varw}{arevmath}}{}
  \tf@ifsuboption{varGamma}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varGamma}{arevmath}}{}
  \tf@ifsuboption{varXi}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varXi}{arevmath}}{}
  \tf@ifsuboption{varPi}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varPi}{arevmath}}{}
  \tf@ifsuboption{varSigma}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varSigma}{arevmath}}{}
  \tf@ifsuboption{varPhi}{\tf@mathfontoptions}
    {\PassOptionsToPackage{varPhi}{arevmath}}{}
  \tf@usefontpackage{arevmath}
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@arevsans}{}
}

% Math -- CM Bright
\newtypeface{cmbright}{CM Bright}{math}{
  \tf@loadcmbright
}

% Math -- Concrete
\newtypeface{concrete}{Concrete Math}{math}{
  \tf@loadconcrete
}

% Math -- Euler
\newtypeface{euler}{Euler}{math}{
  \tf@ifsuboption{small}{\tf@mathfontoptions}
    {\PassOptionsToPackage{small}{eulervm}}{}
  \tf@ifsuboption{euler-digits}{\tf@mathfontoptions}
    {\PassOptionsToPackage{euler-digits}{eulervm}}{}
  \tf@ifsuboption{euler-hat-accent}{\tf@mathfontoptions}
    {\PassOptionsToPackage{euler-hat-accent}{eulervm}}{}
  \tf@ifsuboption{T1}{\tf@mathfontoptions}
    {\PassOptionsToPackage{T1}{eulervm}}{}
  \tf@ifsuboption{OT1}{\tf@mathfontoptions}
    {\PassOptionsToPackage{OT1}{eulervm}}{}
  \tf@ifsuboption{LY1}{\tf@mathfontoptions}
    {\PassOptionsToPackage{LY1}{eulervm}}{}
  \tf@ifsuboption{icomma}{\tf@mathfontoptions}
    {\PassOptionsToPackage{icomma}{eulervm}}{}
  \tf@usefontpackage{eulervm}
}

% Math -- European Modern
%------------------------
% To obtain: svn checkout files from:
%   `http://yytex.googlecode.com/svn/trunk/fonts/em'
% From there, you're on your own!  Hint: compile the .ins file.
% FYI, European Modern is a CM clone/extension. Blurb from the readme.txt:
%     "The European Modern (EM) font set consists of 57 text fonts that are
%     vastly extended versions of Computer Modern (CM) text fonts.  Each EM
%     text font contains 310 glyphs compared to the 128 in CM text fonts (of
%     which eleven are upright Greek letters).  Each EM text font has over 90
%     accented characters, including the 58 `standard' ones found in most
%     fonts in Type 1 format."
% For what it's worth, European Modern tt was used for typesetting keywords
% in The Latex Companion 2nd ed. Look there for that.
\newtypeface[em]{europeanmodern}{European Modern}{math}{
  \tf@ifsuboption{T1}{\tf@mathfontoptions}{
    \PassOptionsToPackage{T1}{em}}{}
  \tf@ifsuboption{LY1}{\tf@mathfontoptions}{
    \PassOptionsToPackage{LY1}{em}}{}
  \tf@ifsuboption{LM1}{\tf@mathfontoptions}{
    \PassOptionsToPackage{LM1}{em}}{}
  \tf@usefontpackage{em}
  \ifthenelse{\equal{\tf@rmfont}{\TF@DEFAULT}}{
    \renewcommand*\rmdefault{cmr} % remapped by em.sty
    \tf@rmfont@europeanmodern     % housekeeping, e.g., sets rm print name
  }{}
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{
    \renewcommand*\sfdefault{cmss}% remapped by em.sty
    \tf@sffont@europeanmodern     % housekeeping, e.g., sets sf print name
  }{}
  \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{
    \renewcommand*\ttdefault{cmtt}% remapped by em.sty
    \tf@ttfont@europeanmodern     % housekeeping, e.g., sets tt print name
  }{}
}

% Math -- Fourier
\newcommand*\tf@fouriermathfont{}
\newtypeface{fourier}{Fourier}{math}{
  % undefine a few problem symbols that might have
  % sneaked in via a previously loaded symbols font
  \tf@undefinecommands{\hslash,\complement,\hbar}

  \def\tf@fouriermathfont{adobeutopia}
  \ifthenelse{\equal{\tf@rmfont}{newcenturyschoolbook}}
    {\def\tf@fouriermathfont{newcenturyschoolbook}}{}
  \def\tf@@configurefourieroptions##1{
    \tf@ifsuboption{##1}{\tf@mathfontoptions}
      {\def\tf@fouriermathfont{newcenturyschoolbook}}{}
  }
  \forcsvlist{\tf@@configurefourieroptions}{nc,newcentury,newcenturyschoolbook}

  \def\tf@@configurefourieroptions##1{
    \tf@ifsuboption{##1}{\tf@mathfontoptions}
      {\def\tf@fouriermathfont{adobeutopia}}{}% not redundant if \rmdefault==nc
  }
  \forcsvlist{\tf@@configurefourieroptions}{utopia,adobeutopia}

  \def\tf@@configurefourieroptions##1{
    \tf@ifsuboption{##1}{\tf@mathfontoptions}{
      \ifthenelse{\equal{\tf@fouriermathfont}{adobeutopia}}{
        % NB, user must ensure utopia expert fonts are properly installed.
        % Otherwise LaTeX will compile but fail to construct the output file,
        % e.g., complaining about missing `put..x.pfb' font file.
        \PassOptionsToPackage{##1}{fourier}
      }{
        \TF@PackageWarningNoLine{%
          Suboption `##1' in package option\MessageBreak
          `mathtypeface=\tf@mathfontname'\MessageBreak
          will be ignored while `newcenturyschoolbook'\MessageBreak
          is in effect}
      }
    }{}
  }
  \forcsvlist{\tf@@configurefourieroptions}
    {upright,widespace,expert,oldstyle,fulloldstyle}

  \ifthenelse{\equal{\tf@fouriermathfont}{newcenturyschoolbook}}{
    \tf@usefontpackage{fouriernc}
  }{
    \tf@usefontpackage{fourier}  % loads [T1]{fontenc} and textcomp
    \renewcommand*\rmdefault{fut\textfamilyextension}
    \ifthenelse{\NOT\equal{\textfamilyextension}{s}}{
      \tf@define@liningfigures{futs} % see comment about expert fonts, above
    }{}
  }
}

% Math -- GFS Artemisia
\tf@newbool{tf@@gfsmatheuler}{false}
\newtypeface[artemisia]{gfsartemisia}{GFS Artemisia}{math}{
  % Unlike GFS Didot, GFS Artemisia does not set up math to any
  % worthwhile extent. It's only included here for completeness's sake.
  \ifthenelse{\equal{\tf@rmfont}{gfsartemisia}}{
    \tf@ifsuboption{euler}{\tf@rmfontoptions}{\booltrue{tf@@gfsmatheuler}}{}
  }{}
  \tf@ifsuboption{euler}{\tf@mathfontoptions}{\booltrue{tf@@gfsmatheuler}}{}
  \ifbool{tf@@gfsmatheuler}{
    \tf@usefontpackage{gfsartemisia-euler}
    \xdef\tf@rmprintname{\tf@mathprintname\  (Euler)}
  }{
    \tf@usefontpackage{gfsartemisia}  % math symbols from txfonts
  }
  \ifthenelse{\equal{\tf@rmfont}{\TF@DEFAULT}}{\tf@rmfont@gfsartemisia}{}
}

% Math -- GFS Bodoni
%............................................................................
% NB, if you run into problems when using T1 font encoding, replace the line:
%     \DeclareFontFamily{T1}{bodoni}     % <-- missing {}
% with:
%    \DeclareFontFamily{T1}{bodoni}{}    % <-- reinstated {}
% in file t1bodoni.fd
%............................................................................
\newtypeface[bodoni]{gfsbodoni}{GFS Bodoni}{math}{
  % Unlike GFS Didot, GFS Bodoni does not set up math to any
  % worthwhile extent. It's only included here for completeness's sake.
  \tf@usefontpackage{gfsbodoni}
  \ifthenelse{\equal{\tf@rmfont}{\TF@DEFAULT}}{\tf@rmfont@gfsbodoni}{}
}

% Math -- GFS Didot
\newtypeface[didot]{gfsdidot}{GFS Didot}{math}{
  \tf@usefontpackage{gfsdidot}
  \ifthenelse{\equal{\tf@rmfont}{\TF@DEFAULT}}{\tf@rmfont@gfsdidot}{}
}

% Math -- GFS Neohellenic
\newtypeface[neohellenic]{gfsneohellenic}{GFS Neohellenic}{math}{
  % Unlike GFS Didot, except for its oddly shaped digits, GFS
  % Neohellenic does not set up math to any worthwhile extent. It's
  % only included here for completeness's sake.
  \tf@usefontpackage{gfsneohellenic}
  \ifthenelse{\equal{\tf@rmfont}{\TF@DEFAULT}}{\tf@rmfont@gfsneohellenic}{}
}

% Math -- Iwona. NB, the Iwona package sets \rmdefault to Iwona. Specify
% another font in your typeface option if this behaviour is not desired.
\newtypeface{iwona}{Iwona}{math}{
  \newcommand*\tf@iwopt@light{}
  \newcommand*\tf@iwopt@condensed{}
  \tf@ifsuboption{light}{\tf@mathfontoptions}{
    \renewcommand*\tf@iwopt@light{light}
    \xdef\tf@mathprintname{\tf@mathprintname\ Light}
  }{}
  \tf@ifsuboption{condensed}{\tf@mathfontoptions}{
    \renewcommand*\tf@iwopt@condensed{condensed}
    \xdef\tf@mathprintname{\tf@mathprintname\ Condensed}
  }{}
  \tf@usefontpackage[math,\tf@iwopt@light,\tf@iwopt@condensed]{iwona}
}

% Math -- Kerkis
\newtypeface{kerkis}{Kerkis}{math}{
  \tf@usefontpackage{kmath}  % kmath on its own loads txfonts
  \tf@usefontpackage{kerkis} % loads kerkis serif and sans, plus courier mono
  \ifthenelse{\equal{\tf@rmfont}{\TF@DEFAULT}}{\tf@rmfont@kerkis}{}
}

% Math -- Kurier. NB, the Kurier package sets \rmdefault to Kurier. Specify
% another font in your typeface option if this behaviour is not desired.
\newtypeface{kurier}{Kurier}{math}{
  \newcommand*\tf@kropt@light{}
  \newcommand*\tf@kropt@condensed{}
  \tf@ifsuboption{light}{\tf@mathfontoptions}{
    \renewcommand*\tf@kropt@light{light}
    \xdef\tf@mathprintname{\tf@mathprintname\ Light}
  }{}
  \tf@ifsuboption{condensed}{\tf@mathfontoptions}{
    \renewcommand*\tf@kropt@condensed{condensed}
    \xdef\tf@mathprintname{\tf@mathprintname\ Condensed}
  }{}
  \tf@usefontpackage[math,\tf@kropt@light,\tf@kropt@condensed]{kurier}
}

% Math -- Kp-Fonts
\newtypeface[kp,kepler]{kpfonts}{}{math}{
  \tf@loadkpfonts
}

% Math -- Latin Modern
\newtypeface[lm,lmodern]{latinmodern}{Latin Modern}{math}{
  \tf@usefontpackage{lmodern}
}

% Bigelow and Holmes Lucida Bright (purchase from CTAN)
\newtypeface[lucidabr,lucida]{lucidabright}{Lucida Bright}{math}{
  \tf@loadlucidabr
}

% Math -- LX Fonts. Extension of Computer Modern Sans Serif Quotation mainly
% as a math enhancement for overhead slides, e.g., with beamer package.
\newtypeface[lx]{lxfonts}{LX Fonts}{math}{
  \tf@usefontpackage{lxfonts}
  \ifthenelse{\equal{\tf@symbolsfont}{\TF@DEFAULT}}{ % LX Fonts overrides some
    \renewcommand*\tf@symbolsprintname{LX Fonts}     % but not all symbols
  }{}
  \renewcommand*\tf@sfprintname{\tf@rmprintname}
  \renewcommand*\tf@ttprintname{\tf@rmprintname}% depends on font encoding T1/OT1
}

% Math Design
\newcommand*\tf@mdrmfont{}
\newtypeface{mathdesign}{Math Design}{math}{
  \tf@ifsuboption{expert}{\tf@mathfontoptions}
    {\PassOptionsToPackage{expert}{mathdesign}}{}
  \tf@ifsuboption{uppercase}{\tf@mathfontoptions}{
    \ifthenelse{\equal{\tf@nextsuboption}{upright}}
      {\PassOptionsToPackage{uppercase=upright}{mathdesign}}{}
    \ifthenelse{\equal{\tf@nextsuboption}{italicized}}
      {\PassOptionsToPackage{uppercase=italicized}{mathdesign}}{}
  }{}
  \tf@ifsuboption{greekuppercase}{\tf@mathfontoptions}{
    \ifthenelse{\equal{\tf@nextsuboption}{upright}}
      {\PassOptionsToPackage{greekuppercase=upright}{mathdesign}}{}
    \ifthenelse{\equal{\tf@nextsuboption}{italicized}}
      {\PassOptionsToPackage{greekuppercase=italicized}{mathdesign}}{}
  }{}
  \tf@ifsuboption{greeklowercase}{\tf@mathfontoptions}{
    \ifthenelse{\equal{\tf@nextsuboption}{upright}}
      {\PassOptionsToPackage{greeklowercase=upright}{mathdesign}}{}
    \ifthenelse{\equal{\tf@nextsuboption}{italicized}}
      {\PassOptionsToPackage{greeklowercase=italicized}{mathdesign}}{}
  }{}

  \def\tf@mdrmfont{charter}% default; available on all PSNFSS-compliant systems
  \ifthenelse{\equal{\tf@rmfont}{urwgaramond}}{\def\tf@mdrmfont{garamond}}{}
  \ifthenelse{\equal{\tf@rmfont}{adobeutopia}}{\def\tf@mdrmfont{utopia}}{}
  \ifthenelse{\equal{\tf@rmfont}{bitstreamcharter}}{\def\tf@mdrmfont{charter}}{}
  \tf@ifsuboption{urwgaramond}{\tf@mathfontoptions}{\def\tf@mdrmfont{garamond}}{}
  \tf@ifsuboption{garamond}{\tf@mathfontoptions}{\def\tf@mdrmfont{garamond}}{}
  \tf@ifsuboption{adobeutopia}{\tf@mathfontoptions}{\def\tf@mdrmfont{utopia}}{}
  \tf@ifsuboption{utopia}{\tf@mathfontoptions}{\def\tf@mdrmfont{utopia}}{}
  \tf@ifsuboption{bitstreamcharter}{\tf@mathfontoptions}{\def\tf@mdrmfont{charter}}{}
  \tf@ifsuboption{charter}{\tf@mathfontoptions}{\def\tf@mdrmfont{charter}}{}

  \let\oldscdefault\scdefault
  \tf@usefontpackage[\tf@mdrmfont,sfscaled=false,ttscaled=false]{mathdesign}

  % Of the three rm fonts accepted by mathdesign (charter, garamond and
  % utopia), utopia alone provides old style figures, and this only through
  % utopia's smallcaps collection (see below). However, mathdesign hijacks
  % smallcaps for its own ends. Rather than 'unhijacking' smallcaps back
  % from mathdesign, potentially upsetting anyone who relies on mathdesign's
  % smallcaps behaviour, as a design decision, we turn textnums off instead.
  %
  % NOTE: mathdesign redefines \scdefault in order to provide faked smallcaps
  %       whenever expert is not in force. This creates problems should the
  %       user load a non-mathdesign rm font. In which case, we try to
  %       recover smallcaps as best we can, noting that users should access
  %       mathdesign (maths mode) smallcaps through its \fscshape command.
  %
  % Also please note: Native URW Garamond does not provide smallcaps.
  \ifthenelse{
    \(\equal{\tf@rmfont}{urwgaramond}\AND\equal{\tf@mdrmfont}{garamond}\)\OR
    \(\equal{\tf@rmfont}{adobeutopia}\AND\equal{\tf@mdrmfont}{utopia}\)\OR
    \(\equal{\tf@rmfont}{bitstreamcharter}\AND\equal{\tf@mdrmfont}{charter}\)}
    {\TF@NativeOSFMathError}
    {\let\scdefault\oldscdefault}
}

% Math -- Mathpazo (aka palatino with pazo math fonts)
\newtypeface[pazo]{mathpazo}{Pazo}{math}{
  \tf@loadmathpazo
}

% Math -- Math Time Pro 2
% Michael Spivak's MathTime Pro2 fonts are essential should you plan on using
% Times (or Gyre Termes) body text fonts. Do not for one instant dream of
% using AMS fonts (although you may still need a symbols font, depending on
% your work, for which amssymb or mnsymbol might do). A free (Lite) subset of
% MathTime Pro2 can be downloaded from www.pctex.com (useful for those with
% limited or occasional math requirements for their work). The cost for the
% full set is not especially great compared to the benefits received.
% Trust me.
\newcommand\tf@premtpro{
  % prevent the clash of glyphs (hmm, nice name for a band)
  \tf@undefinecommands{
      \barwedge,\centerdot,\circledS,\coloneq,\complement,
      \dagger,\ddagger,\divideontimes,\dotplus,\doublebarwedge,
      \hbar,\hslash,\mathparagraph,\mathsection,\mathsterling,
      \ulcorner,\urcorner,\llcorner,\lrcorner,
      \thickapprox,\thicksim,\veebar,
  }
}

\newtypeface[mtpro]{mathtimepro}{MathTime 2 Professional}{math}{
  \tf@ifsuboption{amssymbols}{\tf@mathfontoptions}
    {\PassOptionsToPackage{amssymbols}{mtpro2}}{}
  \tf@ifsuboption{noamssymbols}{\tf@mathfontoptions}
    {\PassOptionsToPackage{noamssymbols}{mtpro2}}{}
  \tf@ifsuboption{slantedGreek}{\tf@mathfontoptions}
    {\PassOptionsToPackage{slantedGreek}{mtpro2}}{}
  \tf@ifsuboption{uprightGreek}{\tf@mathfontoptions}
    {\PassOptionsToPackage{uprightGreek}{mtpro2}}{}
  \tf@ifsuboption{slantedoperators}{\tf@mathfontoptions}
    {\PassOptionsToPackage{slantedoperators}{mtpro2}}{}
  \tf@ifsuboption{uprightoperators}{\tf@mathfontoptions}
    {\PassOptionsToPackage{uprightoperators}{mtpro2}}{}
  % Option subscriptcorrection makes the underscore character '_' active
  % which can break other packages. E.g., url typesets \url{a-b} as 'a-_b'.
  \tf@ifsuboption{subscriptcorrection}{\tf@mathfontoptions}
    {\PassOptionsToPackage{subscriptcorrection}{mtpro2}}{}
  \tf@ifsuboption{nosubscriptcorrection}{\tf@mathfontoptions}
    {\PassOptionsToPackage{nosubscriptcorrection}{mtpro2}}{}
  \tf@ifsuboption{zswash}{\tf@mathfontoptions}
    {\PassOptionsToPackage{zswash}{mtpro2}}{}
  \tf@ifsuboption{nozswash}{\tf@mathfontoptions}
    {\PassOptionsToPackage{nozswash}{mtpro2}}{}
  \tf@ifsuboption{curlybraces}{\tf@mathfontoptions}
    {\PassOptionsToPackage{curlybraces}{mtpro2}}{}
  \tf@ifsuboption{straightbraces}{\tf@mathfontoptions}
    {\PassOptionsToPackage{straightbraces}{mtpro2}}{}
  \tf@ifsuboption{morphedbraces}{\tf@mathfontoptions}
    {\PassOptionsToPackage{morphedbraces}{mtpro2}}{}
  \tf@ifsuboption{cmcal}{\tf@mathfontoptions}
    {\PassOptionsToPackage{cmcal}{mtpro2}}{}
  \tf@ifsuboption{lucidacal}{\tf@mathfontoptions}
    {\PassOptionsToPackage{lucidacal}{mtpro2}}{}
  \tf@ifsuboption{eucal}{\tf@mathfontoptions}
    {\PassOptionsToPackage{eucal}{mtpro2}}{}
  \tf@ifsuboption{mtpluscal}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtpluscal}{mtpro2}}{}
  \tf@ifsuboption{mtpcal}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtpcal}{mtpro2}}{}
  \tf@ifsuboption{mtpccal}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtpccal}{mtpro2}}{}
  \tf@ifsuboption{lucidascr}{\tf@mathfontoptions}
    {\PassOptionsToPackage{lucidascr}{mtpro2}}{}
  \tf@ifsuboption{mtplusscr}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtplusscr}{mtpro2}}{}
  \tf@ifsuboption{mtpscr}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtpscr}{mtpro2}}{}
  \tf@ifsuboption{eufrak}{\tf@mathfontoptions}
    {\PassOptionsToPackage{eufrak}{mtpro2}}{}
  \tf@ifsuboption{mtpfrak}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtpfrak}{mtpro2}}{}
  \tf@ifsuboption{compatiblegreek}{\tf@mathfontoptions}
    {\PassOptionsToPackage{compatiblegreek}{mtpro2}}{}
  \tf@ifsuboption{amsbb}{\tf@mathfontoptions}
    {\PassOptionsToPackage{amsbb}{mtpro2}}{}
  \tf@ifsuboption{mtpbb}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtpbb}{mtpro2}}{}
  \tf@ifsuboption{mtpbbd}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtpbbd}{mtpro2}}{}
  \tf@ifsuboption{mtphrb}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtphrb}{mtpro2}}{}
  \tf@ifsuboption{mtphrd}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtphrd}{mtpro2}}{}
  \tf@ifsuboption{mtpbbi}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtpbbi}{mtpro2}}{}
  \tf@ifsuboption{mtphbi}{\tf@mathfontoptions}
    {\PassOptionsToPackage{mtphbi}{mtpro2}}{}
  \tf@ifsuboption{errorshow}{\tf@mathfontoptions}
    {\PassOptionsToPackage{errorshow}{mtpro2}}{}
  \tf@ifsuboption{warningshow}{\tf@mathfontoptions}
    {\PassOptionsToPackage{warningshow}{mtpro2}}{}
  \tf@ifsuboption{nofontinfo}{\tf@mathfontoptions}
    {\PassOptionsToPackage{nofontinfo}{mtpro2}}{}
  \tf@ifsuboption{lite}{\tf@mathfontoptions}{  % NB, 'lite', not 'light'
    \tf@premtpro
    \tf@usefontpackage[lite]{mtpro2}
    \xdef\tf@rmprintname{\tf@mathprintname\  Lite}
  }{
    \tf@undefinecommands{\Bbbk} % prevent the clash of glyphs
    \tf@premtpro
    \tf@usefontpackage[complete]{mtpro2}
  }
}

% Math -- Adobe Minion Pro
\newtypeface{adobeminionpro}{Adobe Minion Pro}{math}{
  \tf@loadadobeminionpro
}

% Math -- MathPTMX
\newtypeface[ptmx]{mathptmx}{Math PTMX}{math}{
  \tf@usefontpackage{mathptmx}
  \ifthenelse{\equal{\tf@rmfont}{\TF@DEFAULT}}{
    \tf@rmfont@times
  }{}
}

% Math -- PXFonts
\newtypeface[px]{pxfonts}{PX Fonts}{math}{
  \tf@usefontpackage{pxfonts}
}

% Math -- TXFonts
\newtypeface[tx]{txfonts}{TX Fonts}{math}{
  \tf@loadtxfonts
}

% Roman family typeface -- somewhat sensitive to font load
% ordering, particularly if loaded via font packages rather
% than by directly setting \rmdefault
% =========================================================
\TF@PackageDebugInfo{Configuring rm load commands...}

% Default -- no-op
\newtypeface{\TF@DEFAULT}{}{rm}{
  \ifthenelse{\equal{\tf@rmprintname}{undefined}}{
    \renewcommand*\tf@rmprintname{\TF@DEFAULTPRINTNAME}
    \TF@NativeOSFError
  }{}
}

% ADF Baskervald
\newtypeface[baskervald]{adfbaskervald}{ADF Baskervald}{rm}{
  \tf@ifsuboption{lig}{\tf@rmfontoptions}
    {\renewcommand*\rmdefault{ybvw}}
    {\renewcommand*\rmdefault{ybv}}
  \DeclareTextSymbol{\zeroslash}{TS1}{225}
  \DeclareTextSymbolDefault{\zeroslash}{TS1}
  \TF@NativeOSFError
  \tf@pdfglyphcorrection{Baskervald}
}

% ADF Berenis -- sets font encoding to LY1 -- might have
%                consequences for sf/tt/math typeface choices
\newtypeface[berenis]{adfberenis}{ADF Berenis}{rm}{
  \tf@ifsuboption{tab}{\tf@rmfontoptions}    % default is proportional figures
    {\PassOptionsToPackage{tab}{berenis}}{}  % otherwise, use tabular numbers
  \tf@ifsuboption{lig}{\tf@rmfontoptions}
    {\PassOptionsToPackage{lig}{berenis}}{}  % oldstyle extra ligatures
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}}{
    \PassOptionsToPackage{osf}{berenis}
    \tf@ifsuboption{tab}{\tf@rmfontoptions}
      {\tf@define@liningfigures{ybd}}
      {\tf@define@liningfigures{ybd2}}
  }{
    \PassOptionsToPackage{lf}{berenis}
  }
  \tf@usefontpackage[lm]{berenis}
  % ADF Berenis (without lm above) loads latin modern
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@latinmodern}{}
  \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{\tf@ttfont@latinmodern}{}
}

% ADF Electrum
\newtypeface[electrum]{adfelectrum}{ADF Electrum}{rm}{
  \tf@ifsuboption{lig}{\tf@rmfontoptions}
    {\PassOptionsToPackage{lig}{electrum}}{} % oldstyle extra ligatures
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}}{
    \PassOptionsToPackage{osf}{electrum}
    \tf@define@liningfigures{yes}
  }{
    \PassOptionsToPackage{lf}{electrum}
  }
  \tf@usefontpackage{electrum}
}

% ADF Romande
\newtypeface[romande]{adfromande}{ADF Romande}{rm}{
  \tf@ifsuboption{alt}{\tf@rmfontoptions}
    {\PassOptionsToPackage{alt}{romande}}{}
  \tf@usefontpackage{romande}
  \TF@NativeOSFError   % Romande's figures are a sort of hybrid LF/OSF
}

% ADF Venturis -- including ADF Venturis 2 and ADF Venturis Old
\newtypeface[venturis]{adfventuris}{ADF Venturis}{rm}{
  \tf@newbool{tf@rm@venturisii}{false}
  \tf@newbool{tf@rm@venturisold}{false}

  \tf@ifsuboption{2}{\tf@rmfontoptions}{\booltrue{tf@rm@venturisii}}{}
  \tf@ifsuboption{old}{\tf@rmfontoptions}{\booltrue{tf@rm@venturisold}}{}

  \ifthenelse{\boolean{tf@rm@venturisii}\AND\boolean{tf@rm@venturisold}}{
    \TF@PackageError{Incompatible typeface suboptions:\MessageBreak
                     \space\space`typeface=\tf@rmfontname'\MessageBreak
                     Removed `old' suboption}{}
    \renewcommand*\tf@rmfontname{\tf@rmfont:2}
    \renewcommand*\tf@rmfontoptions{2}
    \boolfalse{tf@rm@venturisold}
  }{}
  \ifthenelse{\boolean{tf@rm@venturisii}}{
    \tf@usefontpackage{venturis2}
    \renewcommand*\tf@rmprintname{ADF Venturis 2}
    \TF@NativeOSFError
    % ADF Venturis loads venturis sans
    \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@adfventuris}{}
  }{
    \ifthenelse{\boolean{tf@rm@venturisold}}{
      \tf@usefontpackage{venturisold}
      \renewcommand*\tf@rmprintname{ADF Venturis Old}
      \TF@NativeOSFError
    }{
      \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}}{
        \tf@usefontpackage[osf]{venturis}
        \tf@define@liningfigures{yvt}
      }{
        \tf@usefontpackage[lf]{venturis}
      }
      % ADF Venturis loads venturis sans
      \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@adfventuris}{}
    }
  }
}

% Adobe Minion Pro
\newtypeface[minionpro]{adobeminionpro}{Adobe Minion Pro}{rm}{
  \tf@loadadobeminionpro
}

% Adobe Utopia
\newtypeface[utopia]{adobeutopia}{Adobe Utopia}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{mathdesign}
          \AND\equal{\tf@mdrmfont}{utopia}}{
    % \rmdefault was configured in \tf@mathfont@mathdesign
    \renewcommand*\tf@rmprintname{Math Design Utopia}
  }{
    \ifthenelse{\equal{\tf@mathfont}{fourier}
            \AND\equal{\tf@fouriermathfont}{adobeutopia}}{
      % \rmdefault was configured in \tf@mathfont@fourier
    }{
      \renewcommand*\rmdefault{put}
      \tf@SCencodedosf
    }
  }
}

% AE -- "Almost European" Computer Modern
\newtypeface{ae}{AE}{rm}{
  \tf@ifsuboption{slides}{\tf@rmfontoptions}{
    \renewcommand*\rmdefault{laess} % ``sans roman'' with slides
    \renewcommand*\tf@rmprintname{AE Sans}
  }{
    \renewcommand*\rmdefault{aer}
  }
  \tf@TSencodedosf
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@ae}{}
  \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{\tf@ttfont@ae}{}
}

% Antykwa Poltawskiego
\newtypeface[antpol,poltawski]{antykwapoltawski}{Antykwa P\'o\l tawskiego}{rm}{
  \tf@ifsuboption{light}{\tf@rmfontoptions}{
    \renewcommand*\rmdefault{antpl}
    \xdef\tf@rmprintname{\tf@rmprintname\ Light}
  }{
    \renewcommand*\rmdefault{antp}
  }
  \tf@SCencodedosf
}

% Antykwa Torunska
\newtypeface[anttor,torunska]{antykwatorunska}{}{rm}{
  \tf@loadantykwatorunska
}

% Augie
\newtypeface{augie}{Augie}{rm}{
  \renewcommand*\rmdefault{augie}
  \TF@NativeOSFError
}

% Auriocus Kalligraphicus -- decorative script
% Provides the fonts: Auriocus Kalligraphicus, Lukas Svatba (plus
% Amici variant) and Jana Skrivana, accessed via the \Fontauri,
% \Fontlukas, \Fontskrivan and \Fontamici commands
\newtypeface[auriocus,kalligraphicus]{auriocuskalligraphicus}
                                     {Auriocus Kalligraphicus}{rm}{
  \tf@ifsuboption{backslant}{\tf@rmfontoptions}
    {\tf@usefontpackage[backslant]{aurical}}
    {\tf@usefontpackage{aurical}}
  \TF@NativeLFError   % rare!
  \renewcommand*\rmdefault{AuriocusKalligraphicus}
}

% Bera Serif
\newtypeface[bera]{beraserif}{Bera Serif}{rm}{
  \tf@usefontpackage{beraserif}
  \TF@NativeOSFError
}

% Bitstream Charter
\newtypeface[charter]{bitstreamcharter}{Bitstream Charter}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{mathdesign}
          \AND\equal{\tf@mdrmfont}{charter}}{
    % \rmdefault was configured in \tf@mathfont@mathdesign
    \renewcommand*\tf@rmprintname{Math Design Charter}
  }{
    \renewcommand*\rmdefault{bch}
  }
  \TF@NativeOSFError
}

% Computer Modern (the `fix-cm' proxies -- font encoding dependent)
\newtypeface[cm,cmr]{computermodern}{Computer Modern}{rm}{
  \@ifpackageloaded{fix-cm}{\relax}{
  %-- NB, from `fixltx2e' documentation (which we ignore) -----------------
  % The package should be loaded before \documentclass, using the command
  % \RequirePackage{fix-cm}, rather than the normal \usepackage. Rationale:
  % If the package is loaded in the preamble, a preceding package or even
  % the code of the document class may have used any of the CM fonts
  % already. However, the definitions of those fonts, that are already in
  % use, cannot be changed any more.
  %
  % Rationale for our not observing this guideline: we don't have
  % programmatic control over the user's code writing. The best we can
  % do is load `fix-cm' here then issue some advice about the matter.
  %------------------------------------------------------------------------
    \usepackage{fix-cm}
    \TF@PackageWarningNoLine{%
      If you must set typeface to Computer Modern, please\MessageBreak
      include \string\RequirePackage{fix-cm}\space before the\MessageBreak
      \string\documentclass\space line in your code. See `fixltx2e'\MessageBreak
      package documentation for an explanation. Doing so\MessageBreak
      will make this warning go away. (Note that it is\MessageBreak
      \string\RequirePackage{fix-cm}, not \string\usepackage{fix-cm}.)%
    }
  }
  \renewcommand*\rmdefault{cmr}
  \tf@TSencodedosf
}

% CM Bright (sans serif as a Roman font)
\newtypeface{cmbright}{CM Bright}{rm}{
  \tf@loadcmbright
}

% CM Dunhill
\newtypeface{cmdunhill}{CM Dunhill}{rm}{
  \renewcommand*\rmdefault{cmdh}
  \tf@TSencodedosf
}

% CM Fibonacci
\newtypeface{cmfibonacci}{CM Fibonacci}{rm}{
  \renewcommand*\rmdefault{cmfib}
  \tf@TSencodedosf
}

% Concrete
\newtypeface{concrete}{Concrete}{rm}{
  \tf@loadconcrete
}

% Day Roman
\newtypeface[dayroman]{dayrom}{Day Roman}{rm}{
  \tf@ifsuboption{s}{\tf@rmfontoptions}{
    % with `long s' and additional c-t ligature
    \renewcommand*\rmdefault{dayroms}
    \xdef\tf@rmprintname{\tf@rmprintname\ S}
  }{
    \renewcommand*\rmdefault{dayrom}
  }
  \TF@NativeLFError   % rare!
}

% DejaVu
\newtypeface{dejavu}{DejaVu}{rm}{
  % NB, scaling DejaVu does not affect baselineskip
  \tf@newbool{tf@dejavu@scaled}{false}
  \tf@ifsuboption{scaled}{\tf@rmfontoptions}
    {\booltrue{tf@dejavu@scaled}}
    {\tf@ifsuboption{scale}{\tf@rmfontoptions}{\booltrue{tf@dejavu@scaled}}{}}
  \ifbool{tf@dejavu@scaled}{
    \ifthenelse{\ispositiverealnumber{\tf@nextsuboption}}
      {\xdef\tf@rmscale{\tf@nextsuboption}}
      {\renewcommand*\tf@rmscale{0.95}}  % DejaVu package default
  }{}

  \newcommand*\tf@dejavu@package{DejaVuSerif}
  \tf@ifsuboption{condensed}{\tf@rmfontoptions}{
    \renewcommand*\tf@dejavu@package{DejaVuSerifCondensed}
    \xdef\tf@rmprintname{\tf@rmprintname\ Condensed}
  }{}
  \ifbool{tf@dejavu@scaled}
    {\PassOptionsToPackage{scaled=\tf@rmscale}{\tf@dejavu@package}}{}
  \tf@usefontpackage{\tf@dejavu@package}
  \TF@NativeOSFError
}

% Droid
\newtypeface{droid}{Droid}{rm}{
  \renewcommand*\rmdefault{fdr}
  \TF@NativeOSFError
}

% % Epigrafica -- not yet ready for prime time
% \newtypeface{epigrafica}{Epigrafica}{rm}{
%   \tf@usefontpackage{epigrafica}
%   \tf@TSencodedosf
% }

% European Modern
% European Modern presents a problem by encapsulating its font declarations
% alongside math declarations within the style file rather than in separate
% fd files. Given our default math -> rm -> sf -> tt font loading order, we'd
% be in trouble if the user wanted, say, sf European Modern together with some
% arbitrary non European Modern math. To sidestep this, we extract and
% execute only the font declarations from the European Modern package.
\newtypeface[em]{europeanmodern}{European Modern}{rm}{
  % TODO: errmsg non-T1 encoding
  \ifthenelse{\equal{\tf@mathfont}{europeanmodern}}{
    % our europeanmodern math font handler has already done the required work
  }{
    \expandafter\let\csname T1/cmr/m/n/10\endcsname\@undefined
    \global\defaulthyphenchar=127
    \DeclareFontFamily{T1}{cmr}{}
    \DeclareFontShape{T1}{cmr}{m}{n}{
      <-6>   emr5   <6-7>   emr6     <7-8>   emr7     <8-9> emr8
      <9-10> emr9   <10-12> emr10    <12-17> emr12    <17-> emr17    }{}
    \DeclareFontShape{T1}{cmr}{m}{sl}{
      <-9>   emsl8  <9-10>  emsl9    <10-12> emsl10   <12-> emsl12 }{}
    \DeclareFontShape{T1}{cmr}{m}{it}{
      <-8>   emti7  <8-9>   emti8    <9-10>  emti9  <10-12> emti10 <12-> emti12}{}
    \DeclareFontShape{T1}{cmr}{m}{sc}{
      <-9>   emcsc8 <9-10>  emcsc9   <10->   emcsc10}{}
    \DeclareFontShape{T1}{cmr}{m}{ui}{<->    emu10}{}
    \DeclareFontShape{T1}{cmr}{b}{n} {<->    emb10}{}
    \DeclareFontShape{T1}{cmr}{bx}{n}{
      <-6>   embx5  <6-7>   embx6    <7-8>   embx7    <8-9> embx8
      <9-10> embx9  <10-12> embx10   <12->   embx12}{}
    \DeclareFontShape{T1}{cmr}{bx}{sl}{<->   embxsl10}{}
    \DeclareFontShape{T1}{cmr}{bx}{it}{<->   embxti10}{}
    \DeclareFontShape{T1}{cmr}{bx}{ui}{<->   emu10}{}
    \renewcommand*\rmdefault{cmr}
  }
  \tf@TSencodedosf
}


% GFS Artemisia
\newtypeface[artemisia]{gfsartemisia}{GFS Artemisia}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{\tf@mathfont@gfsartemisia}{}
  \ifthenelse{\equal{\tf@mathfont}{gfsartemisia}}{
    \tf@ifsuboption{euler}{\tf@mathfontoptions}{\booltrue{tf@@gfsmatheuler}}{}
  }{}
  \tf@ifsuboption{euler}{\tf@rmfontoptions}{\booltrue{tf@@gfsmatheuler}}{}
  \ifbool{tf@@gfsmatheuler}{
    \renewcommand*\rmdefault{artemisiaeuler}
    \xdef\tf@rmprintname{\tf@rmprintname\  (Euler)}
  }{
    \renewcommand*\rmdefault{artemisia}
  }
  \tf@SCencodedosf
  % GFS Artemisia loads txfonts, which sets \sfdefault and \ttdefault
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@txfonts}{}
  \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{\tf@ttfont@txfonts}{}
}

% GFS Bodoni
% ----------------------------------------------------
% See the comment with math gfsbodoni, if you run into
% problems when using T1 font encoding
% ----------------------------------------------------
\newtypeface[bodoni]{gfsbodoni}{GFS Bodoni}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{\tf@mathfont@gfsbodoni}{}
  \renewcommand*\rmdefault{bodoni}
  \tf@SCencodedosf
}

% GFS Didot
\newtypeface[didot]{gfsdidot}{GFS Didot}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{\tf@mathfont@gfsdidot}{}
  \renewcommand*\rmdefault{udidot}
  \tf@SCencodedosf
  % GFS Didot loads pxfonts, which sets \sfdefault and \ttdefault
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@pxfonts}{}
  \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{\tf@ttfont@pxfonts}{}
}

% GFS Neohellenic
\newtypeface[neohellenic]{gfsneohellenic}{GFS Neohellenic}{rm}{
  \renewcommand*\rmdefault{neohellenic}
  \tf@ifsuboption{symbols}{\tf@rmfontoptions}{
    \DeclareSymbolFont{letters}{OML}{neohellenic}{m}{it}
    \ifthenelse{\equal{\tf@symbolsfont}{\TF@DEFAULT}}{
      \renewcommand*\tf@symbolsprintname{GFS Neohellenic}
    }{}
  }{}
  \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{\tf@mathfont@gfsneohellenic}{}
  \tf@SCencodedosf
  % GFS Neohellenic loads sets \sfdefault
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@gfsneohellenic}{}
}

% Gyre Bonum
\newtypeface[bonum,tgbonum]{gyrebonum}{Gyre Bonum}{rm}{
  \tf@usefontpackage{tgbonum}
  \tf@TSencodedosf
}

% Gyre Pagella
\newtypeface[pagella,tgpagella]{gyrepagella}{Gyre Pagella}{rm}{
  \tf@usefontpackage{tgpagella}
  \tf@TSencodedosf
}

% Gyre Schola
\newtypeface[schola,tgschola]{gyreschola}{Gyre Schola}{rm}{
  \tf@usefontpackage{tgschola}
  \tf@TSencodedosf
}

% Gyre Termes
\newtypeface[termes,tgtermes]{gyretermes}{Gyre Termes}{rm}{
  \tf@usefontpackage{tgtermes}
  \tf@TSencodedosf
}

% Iwona
\newtypeface{iwona}{Iwona}{rm}{
  \renewcommand*\rmdefault{iwona}
  \tf@ifsuboption{light}{\tf@rmfontoptions}{
    \xdef\rmdefault{\rmdefault l}
    \xdef\tf@rmprintname{\tf@rmprintname\ Light}
  }{}
  \tf@ifsuboption{condensed}{\tf@rmfontoptions}{
    \xdef\rmdefault{\rmdefault c}
    \xdef\tf@rmprintname{\tf@rmprintname\ Condensed}
  }{}
  \tf@TSencodedosf
}

% Journal d'Analyse Mathematique expanded Times Roman font.
% NB, while JAM Times generates a more spacious and consequently rather
% attractive rendition of Times Roman, it cooperates poorly with (non-Belleek)
% maths and symbols fonts, leading to many compile time warnings, especially
% the innocuous but annoying 'LaTeX Font Warning: Font shape `xxx' will be
% scaled' (even when compiling jamtimes' own mathsample.tex file).
\newtypeface[jam]{jamtimes}{JAM Times}{rm}{
  \tf@usefontpackage[scaled=1,sfscaled=1,amsfontsscaled=1]{jamtimes}
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@helvetica}{}
  \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{\tf@ttfont@courier}{}
  \TF@NativeOSFError
}

% Kurier
\newtypeface{kurier}{Kurier}{rm}{
  \renewcommand*\rmdefault{kurier}
  \tf@ifsuboption{light}{\tf@rmfontoptions}{
    \xdef\rmdefault{\rmdefault l}
    \xdef\tf@rmprintname{\tf@rmprintname\ Light}
  }{}
  \tf@ifsuboption{condensed}{\tf@rmfontoptions}{
    \xdef\rmdefault{\rmdefault c}
    \xdef\tf@rmprintname{\tf@rmprintname\ Condensed}
  }{}
  \tf@TSencodedosf
}

% Kerkis (the latin parts are essentially URW Bookman,
% of which, also consider Gyre Bonum)
\newtypeface{kerkis}{Kerkis}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{\tf@mathfont@kerkis}{}
  \renewcommand*\rmdefault{mak}
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@kerkis}{}
  \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{\tf@ttfont@courier}{}
  \tf@TSencodedosf
}

% Kp-Fonts
\newtypeface[kp,kepler]{kpfonts}{}{rm}{
  \tf@loadkpfonts
}

% Latin Modern
\newtypeface[lm,lmodern]{latinmodern}{Latin Modern}{rm}{
  \renewcommand*\rmdefault{lmr}
  % lm doesn't supply bold smallcaps, provide an
  % option to source them from cm instead
  \tf@ifsuboption{boldsc}{\tf@rmfontoptions}{
    \normalfont
    \DeclareFontShape{T1}{lmr}{bx}{sc}  % NB, T1 only                          % TODO: other lm encodings
        {<->ssub*cmr/bx/sc}{}           % Note, no scaling (should be v. close)
  }{}
  \tf@TSencodedosf
}

% Libertine
%------------------------------------------------------------------------------
% NOTE! Around December 2011, the package author deprecated type1 libertine
% fonts in favour of otf format. To use type1 libertine (this might be wrong
% -- be sure to read the the latest libertine documentation if in any doubt):
%  i.  if you also want to access libertine otf,
%        a. install the latest version of the libertine package,
%        b. rename (or delete) the new libertine.sty (dummy) file,
%        c. then re-texhash your system.
%  ii. uninstall the libertine package, install the libertine-legacy package
%      (containing the type1 font files as well as the version of the
%      libertine.sty file that we want to use).
%------------------------------------------------------------------------------
% NB, loads in biolinum (sf) font with matching OsF configuration. This will
% only be noticeable if (a) the `sanstypeface' option is implicitly or
% explicitly set to default, or (b), in the rare event of configuring option
% `fontloadorder=...sf...rm...'
% If case (a), you can override the matching OsF behaviour by explicitly
% setting option `sanstypeface=biolinum' --> lining figures, or
% setting option `sanstypeface=biolinum:osf' --> OsF.  The joy.
\newtypeface{libertine}{Libertine}{rm}{
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}}{
    \PassOptionsToPackage{osf}{libertine}
    \tf@define@liningfigures{fxl}
  }{}
  \tf@usefontpackage{libertine}
  \tf@pdfglyphcorrection{Libertine}
  \renewcommand*\tf@sfprintname{Biolinum} % included in libertine package
}

% Bigelow and Holmes Lucida Bright (purchase from CTAN)
\newtypeface[lucidabr,lucida]{lucidabright}{Lucida Bright}{rm}{
  \tf@loadlucidabr
}

% New Century Schoolbook
\newtypeface[nc,newcentury]{newcenturyschoolbook}{New Century Schoolbook}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{fourier}
          \AND\equal{\tf@fouriermathfont}{newcenturyschoolbook}}{
    % \rmdefault was configured in \tf@mathfont@fourier
  }{
    \tf@usefontpackage{newcent}  % loads pnc, pag, pcr
  }
  \TF@NativeOSFError
}

% Palatino
\newtypeface{palatino}{Palatino}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{
    \tf@loadmathpazo
  }{
    \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}}{
      \renewcommand*\rmdefault{pplj}
      \tf@define@liningfigures{pplx}
     }{
       \renewcommand*\rmdefault{pplx}
     }
    \tf@define@oldstylenums@cmd{pplj}
  }
}

% Paratype PT Serif
\newtypeface[pt,paratype]{ptserif}{PT Serif}{rm}{
  \tf@usefontpackage{PTSerif}
  \TF@NativeOSFError
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@ptsans}{}
  % don't take this approach if tt is not specified since PTMono
  % is unlikely to be installed. If it is and that's what's
  % wanted for tt, then users can explicitly say so by including
  % monotypeface=ptmono among their package options.
}

% PXFonts
\newtypeface[px]{pxfonts}{PX Fonts}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}
    {\tf@usefontpackage{pxfonts}}
    {\renewcommand*\rmdefault{pxr}}
  \tf@TSencodedosf
  % PX Fonts sets \sfdefault and \ttdefault
  \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{\tf@sffont@pxfonts}{}
  \ifthenelse{\equal{\tf@ttfont}{\TF@DEFAULT}}{\tf@ttfont@pxfonts}{}
}

% Times Roman (faked smallcaps & oldstyle figures only if txfonts gets loaded)
\newtypeface{times}{Times Roman}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}
           \OR\equal{\tf@mathfont}{amsfonts}}{
    \tf@usefontpackage[varg]{txfonts}
    \tf@TSencodedosf
  }{
    \renewcommand*\rmdefault{ptm}
    \TF@NativeOSFMathError
  }
}

% TXFonts
\newtypeface[tx]{txfonts}{TX Fonts}{rm}{
  \tf@loadtxfonts
}

% Uncial -- for 6th to the 10th century manuscripts
% NB, requires B1 font encoding (i.e., you also need to have
% installed: b1enc.def, b1cmr.fd, and maybe TeXB1.enc)
\newtypeface{uncial}{Artificial Uncial}{rm}{
  \tf@usefontpackage{allauncl}
  \TF@NativeOSFError
}

% URW Antiqua
\newtypeface[antiqua]{urwantiqua}{URW Antiqua}{rm}{
  \renewcommand*\rmdefault{uaq}
  \TF@NativeOSFError
}

% URW Bookman
\newtypeface[bookman]{urwbookman}{URW Bookman}{rm}{
  \tf@usefontpackage{bookman}
  \TF@NativeOSFError
}

% URW Garamond -- NB, does not natively provide smallcaps
\newtypeface[garamond]{urwgaramond}{URW Garamond}{rm}{
  \ifthenelse{\equal{\tf@mathfont}{mathdesign}
          \AND\equal{\tf@mdrmfont}{garamond}}{
    % \rmdefault was configured in \tf@mathfont@mathdesign
    \renewcommand*\tf@rmprintname{Math Design Garamond}
  }{
    \renewcommand*\rmdefault{ugm}
  }
  \TF@NativeOSFError
}

% URW Nimbus
\newtypeface[nimbus]{urwnimbus}{URW Nimbus}{rm}{
  \renewcommand*\rmdefault{unm}
  \tf@TSencodedosf
}

% Zapf Chancery
\newtypeface[chancery,zapf]{zapfchancery}{Zapf Chancery}{rm}{
  \renewcommand*\rmdefault{pzc}
  \TF@NativeOSFError
}

% Sans serif fonts -- somewhat sensitive to font load ordering,
% particularly if loaded via a font package in the code below
% =============================================================
\TF@PackageDebugInfo{Configuring sf load commands...}

% Default -- no-op
\newtypeface{\TF@DEFAULT}{}{sf}{
  \ifthenelse{\equal{\tf@sfprintname}{undefined}}{
    \renewcommand*\tf@sfprintname{\TF@DEFAULTPRINTNAME}
  }{}
}

\newtypeface[libris]{adflibris}{ADF Libris}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \RequirePackage{nfssext-cfr}% see libris doc for \swashstyle & \textswash
  \renewcommand*\sfdefault{yly}
  \renewcommand*\tf@sfprintname{ADF Libris}
}

\newtypeface[venturis]{adfventuris}{ADF Venturis Sans}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \tf@newbool{tf@@venturisii}{false}
  \ifthenelse{\equal{\tf@rmfont}{adfventuris}}{
    \tf@ifsuboption{2}{\tf@rmfontoptions}{\booltrue{tf@@venturisii}}{}
  }{}
  \tf@ifsuboption{2}{\tf@sffontoptions}{\booltrue{tf@@venturisii}}{}
  \ifbool{tf@@venturisii}{
    \renewcommand*\sfdefault{yv3}
    \renewcommand*\tf@sfprintname{ADF Venturis 2 Sans}
  }{
    \renewcommand*\sfdefault{yv1}
  }
}

\newtypeface{ae}{AE Sans}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{aess}
  \ifthenelse{\equal{\tf@rmfont}{ae}}{
    \tf@ifsuboption{slides}{\tf@rmfontoptions}
      {\renewcommand*\sfdefault{laess}}{}
  }{}
  \ifthenelse{\equal{\tf@ttfont}{ae}}{
    \tf@ifsuboption{slides}{\tf@ttfontoptions}
      {\renewcommand*\sfdefault{laess}}{}
  }{}
  \tf@ifsuboption{slides}{\tf@sffontoptions}
    {\renewcommand*\sfdefault{laess}}{}
}

\newtypeface[arev]{arevsans}{Arev Sans}{sf}{
  \ifthenelse{\equal{\tf@mathfont}{\TF@DEFAULT}}{\tf@mathfont@arevmath}{}
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{fav}
}

\newtypeface{augie}{Augie}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{augie}
}

\newtypeface{avantgarde}{Avant Garde}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \tf@usefontpackage{avant}
}

\newtypeface[bera]{berasans}{Bitstream Vera Sans}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scaled=\tf@sfscalefactor}{berasans}}
  \tf@usefontpackage{berasans}
}

\newtypeface{cantarell}{Cantarell}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scale=\tf@sfscalefactor}{cantarell}}
  \tf@usefontpackage[defaultsans]{cantarell}
}

% Biolinum aka Libertine sans
%------------------------------------------------------------------------------
% NOTE: read the comments with libertine in the roman fonts section
%------------------------------------------------------------------------------
% NB1, the biolinum ex font metrics in all tested versions of libertine (as of
% writing, from v5.1.2 2011/06/06) is faulty. The bug report, again, as of
% writing is still open (see http://sourceforge.net/tracker/?func=detail&
% aid=3397220&group_id=89513&atid=590374). Consequently, ex based scaling
% produces incorrect results. The easiest way out is to avoid setting typeface
% option sanstypeface=ex. Try sanstypeface=xxx, where xxx is uppercase,
% lowercase, figures or a floating point number instead. Alternatively, until
% the bug is fixed, advanced users can hack their biolinum font description
% (*fxb*.fd) files.  Add this code:
%    \fontdimen5\font=\fontcharht\font`\x
% to the last parameter in each \DeclareFontShape command in all *fxb*.fd
% files.  E.g.,
%    \DeclareFontShape{T1}{fxb}{m}{n}{ <-> \fxl@@scale fxbr-t1}
%      {\fontdimen5\font=\fontcharht\font`\x}
%
% NB2, biolinum and libertine SHARE the same loadtime scaling command (the
% horror!). Consequently, there's a good risk that scaling one will
% inadvertently scale the other, the risk depending on the order in which (i.e.,
% when) LaTeX reads the respective rm/libertine and sf/biolinum .fd files.
\newtypeface[libertine]{biolinum}{Biolinum}{sf}{
  \tf@ifsuboption{osf}{\tf@sffontoptions}{
    % Oddly enough for sans, biolinum has an OSF variant (and its quite nice!)
    \renewcommand*\sfdefault{fxbj}
    \xdef\tf@sfprintname{\tf@sfprintname\ OSF}
  }{
    \renewcommand*\sfdefault{fxb}
  }
  \scaletypeface{sf}{\xdef\fxl@scale{\tf@sfscalefactor}}
  % TODO: pdfglyphcorrection is probably unnecessary here
  \tf@pdfglyphcorrection{Biolinum}
}

\newtypeface{cmbright}{CM Bright Sans}{sf}{
  \tf@loadcmbright
}

\newtypeface{comfortaa}{Comfortaa}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scale=\tf@sfscalefactor}{comfortaa}}
  \tf@usefontpackage{comfortaa}
  \renewcommand*\sfdefault{fco}
}

\newtypeface[cm,cms]{computermodern}{Computer Modern Sans}{sf}{
  % Warning: CM Sans Quotation is a rather dubious font. Bold, italic, slant
  % fontsizes do not match normal fontsize. No smallcaps. Best avoid.
  %
  % requires reworked .fd file to accommodate load time scaling
  \tf@ifsuboption{quotation}{\tf@sffontoptions}{
    \renewcommand*\sfdefault{lcmss}
  }{
    \renewcommand*\sfdefault{cmss}
  }
}

\newtypeface{cyklop}{Cyklop}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{cyklop}
}

\newtypeface{dejavu}{DejaVu Sans}{sf}{
  \tf@ifsuboption{condensed}{\tf@sffontoptions}{
    \scaletypeface{sf}
      {\PassOptionsToPackage{scaled=\tf@sfscalefactor}{DejaVuSansCondensed}}
    \tf@usefontpackage{DejaVuSansCondensed}
    \xdef\tf@sfprintname{\tf@sfprintname\ Condensed}
  }{
    \scaletypeface{sf}
      {\PassOptionsToPackage{scaled=\tf@sfscalefactor}{DejaVuSans}}
    \tf@usefontpackage{DejaVuSans}
  }
}

\newtypeface{droid}{Droid Sans}{sf}{
  \scaletypeface{sf}{\def\droid@fds@scale{s*[\tf@sfscalefactor]}}
  \renewcommand*\sfdefault{fds}
}

\newtypeface[em]{europeanmodern}{European Modern Sans}{sf}{
  % TODO: errmsg non-T1 encoding
  % TODO: we can source sf osf from TS1
  % See comments with rm \newtypeface declaration
  \ifthenelse{\equal{\tf@mathfont}{europeanmodern}}{
    % our europeanmodern math font handler has already done the needed work
  }{
    \DeclareFontFamily{T1}{emss}{}
    \DeclareFontShape{T1}{emss}{m}{n}  {
      <-9> emss8  <9-10> emss9  <10-12> emss10  <12-17> emss12  <17-> emss17}{}
    \DeclareFontShape{T1}{emss}{m}{sl} {
      <-9> emssi8 <9-10> emssi9 <10-12> emssi10 <12-17> emssi12 <17-> emssi17}{}
    \DeclareFontShape{T1}{emss}{sbc}{n}{<-> emssdc10}{}
    \DeclareFontShape{T1}{emss}{bx}{n} {<-> emssbx10}{}
    \DeclareFontShape{T1}{emss}{m}{it} {
      <-9> emssi8 <9-10> emssi9 <10-12> emssi10 <12-17> emssi12 <17-> emssi17}{}
    \DeclareFontShape{T1}{emss}{m}{sc} {
      <-9> emcsc8 <9-10> emcsc9 <10-> emcsc10}{}
    \DeclareFontShape{T1}{emss}{m}{ui} {<-> emu10}{}
    \DeclareFontShape{T1}{emss}{bx}{ui}{<-> emu10}{}
    \renewcommand*\sfdefault{emss}
  }
}

\newtypeface[neohellenic]{gfsneohellenic}{GFS Neohellenic}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  % NB, .fd file contains scaling paraphernalia, however fixes scale to 1.225!
  \renewcommand*\sfdefault{neohellenic}
  \tf@ifsuboption{symbols}{\tf@sffontoptions}{
    \DeclareSymbolFont{letters}{OML}{neohellenic}{m}{it}
    \ifthenelse{\equal{\tf@symbolsfont}{\TF@DEFAULT}}{
      \renewcommand*\tf@symbolsprintname{GFS Neohellenic}
    }{}
  }{}
}

\newtypeface[adventor,tgadventor]{gyreadventor}{Gyre Adventor}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scale=\tf@sfscalefactor}{tgadventor}}
  \tf@usefontpackage{tgadventor}
}

\newtypeface[heros,tgheros]{gyreheros}{Gyre Heros}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scale=\tf@sfscalefactor}{tgheros}}
  \tf@usefontpackage{tgheros}
}

\newtypeface[helv,helvet]{helvetica}{Helvetica}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scaled=\tf@sfscalefactor}{helvet}}
  \tf@usefontpackage{helvet}
}

\newtypeface{iwona}{Iwona}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{iwona}

  \tf@ifsuboption{light}{\tf@sffontoptions}{
    \xdef\sfdefault{\sfdefault l}
    \xdef\tf@sfprintname{\tf@sfprintname\ Light}
  }{}
  \tf@ifsuboption{condensed}{\tf@sffontoptions}{
    \xdef\sfdefault{\sfdefault c}
    \xdef\tf@sfprintname{\tf@sfprintname\ Condensed}
  }{}
}

\newtypeface[kp,kepler]{kpfonts}{KP Fonts Sans}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \tf@ifsuboption{osf}{\tf@sffontoptions}{
    % Oddly enough for a sans font, KP has an OSF variant
    \renewcommand*\sfdefault{jkpssosn}
    \xdef\tf@sfprintname{\tf@sfprintname\ OSF}
  }{
    \renewcommand*\sfdefault{jkpss}
  }
}

\newtypeface{kerkis}{Kerkis Sans}{sf}{
  \renewcommand*\sfdefault{maksf}
  % <enc>maksf.fd hard codes its scale factor. This code rolls that back.
  \providecommand*\tf@kerkismagicnumber{0.90} % change if <enc>maksf.fd changes
  \g@addto@macro\tf@empty@sfcnt@hook{%
    % Rewind 0.90 fixed scale factor in .fd file
    \ifthenelse{\boolean{tf@@sffamily}
        \AND\NOT\equal{\tf@sfscalemethod}{\TF@NO@SCALE}}{%
      \@tempdima=\tf@sfscalefactor\p@%
      \@tempdima=\tf@kerkismagicnumber\@tempdima%
      \edef\optional@arg{\strip@pt\@tempdima}%
      \global\booltrue{tf@sfscaledatloadtime}%
    }{}%
  }
}

\newtypeface{kurier}{Kurier Sans}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{kurier}
  \tf@ifsuboption{light}{\tf@sffontoptions}{
    \xdef\sfdefault{\sfdefault l}
    \xdef\tf@sfprintname{\tf@sfprintname\ Light}
  }{}
  \tf@ifsuboption{condensed}{\tf@sffontoptions}{
    \xdef\sfdefault{\sfdefault c}
    \xdef\tf@sfprintname{\tf@sfprintname\ Condensed}
  }{}
}

\newtypeface[lm,lmodern]{latinmodern}{Latin Modern Sans}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \tf@ifsuboption{extended}{\tf@sffontoptions}{
    \renewcommand*\sfdefault{lmssq}
    \xdef\tf@sfprintname{\tf@sfprintname\ Extended}
  }{
    \renewcommand*\sfdefault{lmss}
  }
}

\newtypeface{lato}{Lato}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scale=\tf@sfscalefactor}{lato}}
  \tf@usefontpackage[defaultsans]{lato}
}

\newtypeface[lucidabr,lucida]{lucidabright}{Lucida Bright Sans}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  % (unfortunately, redefining \DeclareLucidaFontShape won't work
  % effortlessly since it is shared between rm, sf and tt fonts)
  \renewcommand*\sfdefault{hls}
}

\newtypeface{opensans}{Open Sans}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scale=\tf@sfscalefactor}{opensans}}
  \tf@ifsuboption{osf}{\tf@sffontoptions}{
    \PassOptionsToPackage{osfigures}{opensans}
  }{}
  \tf@usefontpackage[defaultsans]{opensans}[2011/11/11]
}

\newtypeface[pt,paratype]{ptsans}{PT Sans}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scaled=\tf@sfscalefactor}{PTSans}}
  \tf@usefontpackage{PTSans}
}

\newtypeface[px]{pxfonts}{PX Fonts Sans}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{pxss}
}

\newtypeface[tx]{txfonts}{TX Fonts Sans}{sf}{
%% NOTE: for users that want to use newtx's sf fonts definitions,
%% copy this macro to typeface.cfg, uncommenting the commented text
%% below. However, please check that it functions as intended before
%% relying it in earnest. Particularly check italic and bold shape
%% scaling to roman-relative size (sf scale options ex, uppercase,
%% lowercase, figures and implicit/default).
%
%   \tf@newbool{newtx}{false}
%   \ifthenelse{\equal{\tf@sffont}{\TF@DEFAULT}}{
%     \ifthenelse{\equal{\tf@rmfont}{txfonts}}{
%       \tf@ifsuboption{new}{\tf@rmfontoptions}{\booltrue{newtx}}{}
%     }{}
%     \ifthenelse{\equal{\tf@mathfont}{txfonts}}{
%       \tf@ifsuboption{new}{\tf@mathfontoptions}{\booltrue{newtx}}{}
%     }{}
%   }{
%     \tf@ifsuboption{new}{\tf@sffontoptions}{\booltrue{newtx}}{}
%   }
%
%   \ifbool{newtx}{
%     % Michael Sharpe's newtx
%     \scaletypeface{sf}{\xdef\ntx@helvscaled{s*[\tf@sfscalefactor]}}
%     \renewcommand*\sfdefault{ntxss}
%   }{
    \renewcommand*\sfdefault{txss}
    % <enc>txss.fd hard codes its scale factor. This code rolls that back.
    \providecommand*\tf@txfontsmagicnumber{0.95}% change if <enc>txss.fd changes
    \g@addto@macro\tf@empty@sfcnt@hook{%
      % Rewind 0.95 fixed scale factor in .fd file
      \ifthenelse{\boolean{tf@@sffamily}
          \AND\NOT\equal{\tf@sfscalemethod}{\TF@NO@SCALE}}{%
        \@tempdima=\tf@sfscalefactor\p@%
        \@tempdima=\tf@txfontsmagicnumber\@tempdima%
        \edef\optional@arg{\strip@pt\@tempdima}%
        \global\booltrue{tf@sfscaledatloadtime}%
      }{}%
    }
%   }
}

\newtypeface[arial]{urwarial}{URW Arial}{sf}{
  \scaletypeface{sf}{\PassOptionsToPackage{scaled=\tf@sfscalefactor}{uarial}}
  \tf@usefontpackage{uarial}
}

\newtypeface[classico,optima]{urwclassico}{URW Classico}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{uop}
}

\newtypeface[grotesq]{urwgrotesq}{URW Grotesq}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{ugq}
}

\newtypeface[nimbus]{urwnimbus}{URW Nimbus Sans}{sf}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\sfdefault{unms}
}

% Typewriter fonts -- somewhat sensitive to font load ordering,
% particularly if loaded via a font package in the code below
% ============================================================
\TF@PackageDebugInfo{Configuring tt load commands...}

% Default -- no-op
\newtypeface{\TF@DEFAULT}{}{tt}{
  \ifthenelse{\equal{\tf@ttprintname}{undefined}}{
    \renewcommand*\tf@ttprintname{\TF@DEFAULTPRINTNAME}
  }{}
}

\newtypeface{ae}{AE Mono}{tt}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\ttdefault{aett}
  \ifthenelse{\equal{\tf@rmfont}{ae}}{
    \tf@ifsuboption{slides}{\tf@rmfontoptions}
      {\renewcommand*\ttdefault{laett}}{}
  }{}
  \ifthenelse{\equal{\tf@sffont}{ae}}{
    \tf@ifsuboption{slides}{\tf@sffontoptions}
      {\renewcommand*\ttdefault{laett}}{}
  }{}
  \tf@ifsuboption{slides}{\tf@ttfontoptions}
    {\renewcommand*\ttdefault{laett}}{}
}

\newtypeface[bera]{beramono}{Bitstream Vera Mono}{tt}{
  \scaletypeface{tt}{\PassOptionsToPackage{scaled=\tf@ttscalefactor}{beramono}}
  \tf@usefontpackage{beramono} % contains no font load order side effects
}

\newtypeface{cmbright}{Computer Modern Mono Light}{tt}{
  \tf@loadcmbright % contains math/symbols font load order side effects
}

\newtypeface[cm,cmt]{computermodern}{}{tt}{
  % requires reworked .fd files to accommodate load time scaling
  \tf@ifsuboption{light}{\tf@ttfontoptions}{
    \renewcommand*\ttdefault{cmtl}
    \renewcommand*\tf@ttprintname{Computer Modern Mono Light}
  }{
    \tf@ifsuboption{proportional}{\tf@ttfontoptions}{
      \renewcommand*\ttdefault{cmvtt}
      \renewcommand*\tf@ttprintname{Computer Modern Mono Proportional}
    }{
      \tf@ifsuboption{L}{\tf@ttfontoptions}{
        \ifthenelse{\equal{\tf@fontencoding}{T1}}{
          \DeclareFontFamily{T1}{lcmtt}{\hyphenchar\font\m@ne}
          \DeclareFontShape{T1}{lcmtt}{m}{n}{<->ecltt8}{}
          \DeclareFontShape{T1}{lcmtt}{m}{In}{<->iecltt8}{}
          \DeclareFontShape{T1}{lcmtt}{m}{it}{<->ecit1000}{}
        }{
          \ifthenelse{\equal{\tf@fontencoding}{OT1}}{
            \DeclareFontFamily{OT1}{lcmtt}{\hyphenchar\font\m@ne}
            \DeclareFontShape{OT1}{lcmtt}{m}{n}{<-> cmtt8}{}
            \DeclareFontShape{OT1}{lcmtt}{m}{In}{<->icmtt8}{}
            \DeclareFontShape{OT1}{lcmtt}{m}{it}{<->cmitt10}{}
          }
        }{
          %\TF@PackageWarningNoLine{...}
        }
        \renewcommand*\ttdefault{lcmtt}
        \renewcommand*\tf@ttprintname{Computer Modern Mono L}
      }{
        \renewcommand*\ttdefault{cmtt}
        \renewcommand*\tf@ttprintname{Computer Modern Mono}
      }
    }
  }
}

\newtypeface{courier}{Courier}{tt}{
  \scaletypeface{tt}{\PassOptionsToPackage{scaled=\tf@ttscalefactor}{couriers}}
  \tf@usefontpackage{couriers}
}

\newtypeface{dejavu}{DejaVu Mono}{tt}{
  \scaletypeface{tt}
    {\PassOptionsToPackage{scaled=\tf@ttscalefactor}{DejaVuSansMono}}
  \tf@usefontpackage{DejaVuSansMono}
}

\newtypeface{droid}{Droid Mono}{tt}{
  \scaletypeface{tt}{\def\droid@fdm@scale{s*[\tf@ttscalefactor]}}
  \renewcommand*\ttdefault{fdm}
}

\newtypeface[cursor,tgcursor]{gyrecursor}{Gyre Cursor}{tt}{
  \scaletypeface{tt}{\PassOptionsToPackage{scale=\tf@ttscalefactor}{tgcursor}}
  \tf@usefontpackage{tgcursor}
}

\newtypeface[em]{europeanmodern}{European Modern Mono}{tt}{
  % TODO: errmsg non-T1 encoding
  % TODO: we can source tt osf from TS1
  % See comments with rm \newtypeface declaration
  \ifthenelse{\equal{\tf@mathfont}{europeanmodern}}{
    % our europeanmodern math font handler has already done the required work
  }{
    \DeclareFontFamily{T1}{cmtt}{\hyphenchar \font\m@ne}
    \DeclareFontShape{T1}{cmtt}{m}{n}{
      <-9> emtt8  <9-10> emtt9  <10-12> emtt10 <12-> emtt12}{}
    \DeclareFontShape{T1}{cmtt}{m}{it} {<-> emitt10}{}
    \DeclareFontShape{T1}{cmtt}{m}{sl} {<-> emsltt10}{}
    \DeclareFontShape{T1}{cmtt}{m}{ui} {<-> emitt10}{}
    \DeclareFontShape{T1}{cmtt}{bx}{n} {
      <-9> emtt8  <9-10> emtt9  <10-12> emtt10 <12-> emtt12}{}
    \DeclareFontShape{T1}{cmtt}{bx}{it}{<-> emitt10}{}
    \DeclareFontShape{T1}{cmtt}{bx}{ui}{<-> emitt10}{}
    \renewcommand*\ttdefault{cmtt}
  }
}

\newtypeface{inconsolata}{Inconsolata}{tt}{
  \scaletypeface{tt}{\def\fifour@scaled{s*[\tf@ttscalefactor]}}
  \renewcommand*\ttdefault{fi4}
}

\newtypeface[kp,kepler]{kpfonts}{KP Fonts Mono}{tt}{
  % requires reworked .fd file to accommodate load time scaling
  \tf@ifsuboption{osf}{\tf@ttfontoptions}
    {\renewcommand*\ttdefault{jkpttosn}} % KP mono has an OSF variant
    {\renewcommand*\ttdefault{jkptt}}
}

\newtypeface[lm,lmodern]{latinmodern}{Latin Modern Mono}{tt}{
  % requires reworked .fd file to accommodate load time scaling
  \tf@ifsuboption{proportional}{\tf@ttfontoptions}{
    \renewcommand*\ttdefault{lmvtt}
    \xdef\tf@ttprintname{\tf@ttprintname\  Proportional}
    \renewcommand*\tf@ttprintname{Latin Modern Mono Proportional}
  }{
    \renewcommand*\ttdefault{lmtt}
  }
}

\newtypeface[lucidabr,lucida]{lucidabright}{Lucida Bright Mono}{tt}{
  % We follow lucidabr (see \tf@loadlucidabr, above) by defaulting
  % to sans tt unless serif tt is specified. This breaks with the
  % sans vs serif tt pattern established with other tt fonts throughout
  % this package (which default to serif tt unless `sans' option is provided).
  % Note also that we require reworked .fd file to accommodate load time
  % scaling (unfortunately, redefining \DeclareLucidaFontShape won't work
  % without knottiness since it is common to rm, sf and tt fonts).
  \tf@ifsuboption{serif}{\tf@ttfontoptions}{\booltrue{tf@@lbseriftt}}{}
  \tf@ifsuboption{seriftt}{\tf@ttfontoptions}{\booltrue{tf@@lbseriftt}}{}
  \tf@ifsuboption{sans}{\tf@ttfontoptions}{
    \ifbool{tf@@lbseriftt}{
      \TF@PackageWarningNoLine{%
        Incompatible suboptions `sans' and `seriftt' (or\MessageBreak
        `serif'). Check for conflicts in your `typeface',\MessageBreak
        `mathtypeface' and `monotypeface' package options}
    }{}
  }{}
  \ifbool{tf@@lbseriftt}{
    \renewcommand*\ttdefault{hlct}
  }{
    \renewcommand*\ttdefault{hlst}
    \renewcommand*\tf@ttprintname{Lucida Bright Sans Mono}
  }
}

\newtypeface[luxi]{luximono}{Luxi Mono}{tt}{
  \scaletypeface{tt}{\PassOptionsToPackage{scaled=\tf@ttscalefactor}{luximono}}
  % While the luximono package is available via MiKTeX package manager, it is
  % not through TeXLive package manager where instead you'll need to download
  % and install by hand
  \tf@usefontpackage{luximono}
}

\newtypeface[pt,paratype]{ptmono}{PT Mono}{tt}{
  % PT Mono is not installed with the paratype package and must
  % consequently be manually installed using the truetype variant
  % (instructions in paratype's docs)
  \scaletypeface{tt}{\PassOptionsToPackage{scaled=\tf@ttscalefactor}{PTSans}}
  \tf@usefontpackage{PTMono}
}

\newtypeface[px]{pxfonts}{PX Fonts Mono}{tt}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\ttdefault{pxtt}
}

\newtypeface[tx]{txfonts}{TX Fonts Mono}{tt}{
  % requires reworked .fd file to accommodate load time scaling
  \renewcommand*\ttdefault{txtt}
}

%== End \newtypeface font definitions =========================================

% Unpack and validate typeface font options
%------------------------------------------
% Typeface name options (typeface/rm, sanstypeface/sf, monotypeface/tt,
% mathtypeface/math, symbolstypeface/sym and textfigures) can include
% colon-separated lists of suboptions, e.g.,
%    typeface=iwona:light,
%    sanstypeface=kepler:light:osf,
%    monotypeface=latinmodern:proportional
%    textfigures=kepler:light:scale:ex:spacing:-20:lkern:-20:rkern:-10
% At this stage, each user supplied <fontname[:option]*> string has already
% been set up in \tf@XXfontname, where XX is rm, sf, tt, math, symbols or
% textfigures. We store the <fontname> part in \tf@XXfont and the <[:option]*>
% part in \tf@XXfontoptions (discarding the first colon), then validate
% that \tf@XXfont is a legitimate font name, complaining otherwise.
%......................................................................
\tf@newbool{tf@valid@fontname}{false}

\newcommand*\tf@unpackfontname[2]{%
  % split & save the string in #1 into \tf@#2font and \tf@#2fontoptions, where
  %   #1 is the <fontname(:option)*> user-supplied option string, and
  %   #2 is one of textfigures, symbols, math, rm, sf, or tt
  \expandafter\tf@@unpackfontname\expandafter{#1}{#2}%
}

\newcommand*\tf@@unpackfontname[2]{%
  \tf@split@fontname #2:#1\@empty:\@empty\relax%
}

\def\tf@split@fontname#1:#2:#3\@empty#4\relax{%         % split and save to:
  \expandafter\def\csname tf@#1font\endcsname{#2}%      % eg, \tf@rmfont
  \expandafter\def\csname tf@#1fontoptions\endcsname{#3}% eg, \tf@rmfontoptions
}

\newcommand*\tf@parsefontname[1]{
  % #1 is one of textfigures, symbols, math, rm, sf, or tt
  \edef\tf@@fontname{\csname tf@#1fontname\endcsname}
  \tf@unpackfontname{\tf@@fontname}{#1}

  % check that the fontname part we saved in \tf@#1font matches one
  % of the entries in the \tf@#1typefacechoices comma separated list
  \boolfalse{tf@valid@fontname}
  \edef\tf@@font{\csname tf@#1font\endcsname}
  \renewcommand*\do[1]{      % refer etoolbox package
    \ifthenelse{\equal{\tf@@font}{##1}}
      {\booltrue{tf@valid@fontname}\listbreak}
      {}
  }
  \edef\tf@@typefacechoices{\csname tf@#1typefacechoices\endcsname}
  \expandafter\docsvlist\expandafter{\tf@@typefacechoices}

  \ifthenelse{\NOT\boolean{tf@valid@fontname}}{
    \ifthenelse{\equal{rm}{#1}}{
      \edef\tf@@XXtypeface{typeface}
      \edef\tf@@XXdefaultfont{\TF@DEFAULTRMFONT}}{}
    \ifthenelse{\equal{sf}{#1}}{
      \edef\tf@@XXtypeface{sanstypeface}
      \edef\tf@@XXdefaultfont{\TF@DEFAULTSFFONT}}{}
    \ifthenelse{\equal{tt}{#1}}{
      \edef\tf@@XXtypeface{monotypeface}
      \edef\tf@@XXdefaultfont{\TF@DEFAULTTTFONT}}{}
    \ifthenelse{\equal{math}{#1}}{
      \edef\tf@@XXtypeface{mathtypeface}
      \edef\tf@@XXdefaultfont{\TF@DEFAULTMATHFONT}}{}
    \ifthenelse{\equal{symbols}{#1}}{
      \edef\tf@@XXtypeface{symbolstypeface}
      \edef\tf@@XXdefaultfont{\TF@DEFAULTSYMBOLSFONT}}{}
    \ifthenelse{\equal{textfigures}{#1}}{
      \edef\tf@@XXtypeface{textfigures}
      \edef\tf@@XXdefaultfont{\TF@DEFAULTTEXTFIGURESFONT}}{}
    % NB, no allowance is made in the following error message that the user
    % might have used one of the options aliases, e.g., instead of
    % typeface=..., s/he wrote rm=...  Hopefully if the user is smart enough
    % to use options aliases, s/he's smart enough to interpret the error.
    \TF@PackageError{%
      Package option `\tf@@XXtypeface=\tf@@fontname' is\MessageBreak
      invalid. Setting `\tf@@XXtypeface=\tf@@XXdefaultfont'}{}
    \expandafter\xdef\csname tf@#1fontname\endcsname{\tf@@XXdefaultfont}
    \expandafter\xdef\csname tf@#1font\endcsname{\tf@@XXdefaultfont}
    \expandafter\xdef\csname tf@rmfontdefaultstatus\endcsname{\TF@IMPLICITDEFAULT}
  }{}
}
\forcsvlist{\tf@parsefontname}{rm,sf,tt,math,symbols,textfigures}

% Configure sf, tt, math and textfigures font scaling
% ===================================================
% Options include: ex, lowercase, uppercase, figures, true (synonym for ex),
% false, or a literal constant (e.g., 0.82), allowing authors to match the
% ex-height, the baseline ascender height of lowercase letters, the ascender
% height of uppercase letters, or the ascender height of figures for the
% target fonts with respect to the \rmdefault (reference) font size. Special
% values 0, false, 1, 1.0, etc. all produce unity, that is, no scaling.
%---------------------------------------------------------------------------

% Typeface family scale command names, e.g., ex, 0.98, false, uppercase,...
\newcommand*\tf@rmscale{\TF@UNSCALED}
\newcommand*\tf@sfscale{\TF@UNSCALED}
\newcommand*\tf@ttscale{\TF@UNSCALED}
\newcommand*\tf@mathscale{\TF@UNSCALED}
\newcommand*\tf@textfiguresscale{\TF@UNSCALED}

% Typeface family scale factors (+ve real numbers only)
\newcommand*\tf@sfscalefactor{\TF@UNSCALED}
\newcommand*\tf@ttscalefactor{\TF@UNSCALED}
\newcommand*\tf@mathscalefactor{\TF@UNSCALED}
\newcommand*\tf@textfiguresscalefactor{\TF@UNSCALED}

% Track whether user explicitly defines scale or whether we implicitly set it
\tf@newbool{tf@sfscaleimplicit}{true}
\tf@newbool{tf@ttscaleimplicit}{true}
\tf@newbool{tf@mathscaleimplicit}{true}
\tf@newbool{tf@textfiguresscaleimplicit}{true}

% Determine target font scaling methods
%--------------------------------------
\newcommand*\tf@sfscalemethod{\TF@ER@SCALE}
\newcommand*\tf@ttscalemethod{\TF@ER@SCALE}
\newcommand*\tf@mathscalemethod{\TF@ER@SCALE}
\newcommand*\tf@textfiguresscalemethod{\TF@ER@SCALE}

\tf@newbool{tf@sfscaledatloadtime}{false}
\tf@newbool{tf@ttscaledatloadtime}{false}
\tf@newbool{tf@mathscaledatloadtime}{false}
\tf@newbool{tf@textfiguresscaledatloadtime}{false}

% Validate and set the math font family (0..15) for use with rm-relative
% font scaling (used in \tf@initialise@fontscaling and in printinfo)
\newcommand*\tf@mathfontfamily{0} % default

\tf@ifsuboption{fam}{\tf@mathfontoptions}{
  \xdef\tf@mathfontfamily{\tf@nextsuboption}
  \def\tf@@temp{fam}
}{}

\tf@ifsuboption{family}{\tf@mathfontoptions}{
  \xdef\tf@mathfontfamily{\tf@nextsuboption}
  \def\tf@@temp{family}
}{}

\ifthenelse{\NOT\ispositiveinteger{\tf@mathfontfamily}
            \OR\(\tf@mathfontfamily > 15\)}{
  \ifthenelse{\equal{\tf@mathfontfamily}{}}{\def\tf@mathfontfamily{<nil>}}{}
  \TF@PackageError{%
      Invalid `\tf@@temp:nn' suboption argument in package\MessageBreak
      option `mathtypeface=\tf@mathfontname'.\MessageBreak
      Integer `nn' must be between 0 and 15\MessageBreak
      (not `\tf@mathfontfamily'). Setting math font family = 0%
  }{}
  \renewcommand*\tf@mathfontfamily{0}
}{}

% Determine sf, tt, math and textfigures font scaling methods
\newcommand*\tf@configure@fontscalingmethod[1]{
  \ifthenelse{\NOT\equal{#1}{sf}
          \AND\NOT\equal{#1}{tt}
          \AND\NOT\equal{#1}{math}
          \AND\NOT\equal{#1}{textfigures}}{
    \TF@PackageError{Internal error in \TF@PACKAGENAME.sty\MessageBreak
      Illegal parameter [#1]\MessageBreak
      in \string\tf@configure@fontscalingmethod}{}
  }{
    \begingroup
      \edef\tf@@scalemethod{\TF@ER@SCALE}
      \edef\tf@@scalefactor{\TF@UNSCALED}
      \edef\tf@@fontoptions{\csname tf@#1fontoptions\endcsname}

      \tf@ifsuboption{scale}{\tf@@fontoptions}{
        \ifthenelse{\equal{\tf@nextsuboption}{false}}
          {\edef\tf@@scalemethod{\TF@NO@SCALE}}{}
        \ifthenelse{\equal{\tf@nextsuboption}{true}}
          {\edef\tf@@scalemethod{\TF@EX@SCALE}}{}
        \ifthenelse{\equal{\tf@nextsuboption}{ex}}
          {\edef\tf@@scalemethod{\TF@EX@SCALE}}{}
        \ifthenelse{\equal{\tf@nextsuboption}{lowercase}}
          {\edef\tf@@scalemethod{\TF@LC@SCALE}}{}
        \ifthenelse{\equal{\tf@nextsuboption}{lc}}
          {\edef\tf@@scalemethod{\TF@LC@SCALE}}{}
        \ifthenelse{\equal{\tf@nextsuboption}{uppercase}}
          {\edef\tf@@scalemethod{\TF@UC@SCALE}}{}
        \ifthenelse{\equal{\tf@nextsuboption}{uc}}
          {\edef\tf@@scalemethod{\TF@UC@SCALE}}{}
        \ifthenelse{\equal{\tf@nextsuboption}{figures}}
          {\edef\tf@@scalemethod{\TF@FG@SCALE}}{}
        \ifthenelse{\equal{\tf@nextsuboption}{fig}}
          {\edef\tf@@scalemethod{\TF@FG@SCALE}}{}
        \ifthenelse{\ispositiverealnumber{\tf@nextsuboption}}{
          % Test "normalised" numbers, i.e., test 0 instead of 0.00,
          % 1 instead of 001, ...
          \edef\tf@@scalefactor{\strip@pt\dimexpr\tf@nextsuboption pt\relax}
          \ifthenelse{\equal{\tf@@scalefactor}{0}
                   \OR\equal{\tf@@scalefactor}{1}}{
            \edef\tf@@scalemethod{\TF@NO@SCALE}
          }{
            \edef\tf@@scalemethod{\TF@FX@SCALE}
            \expandafter\xdef\csname tf@#1scalefactor\endcsname{\tf@@scalefactor}
          }
        }{}
      }{
        \edef\tf@@scalemethod{\TF@EX@SCALE}  % default: scale to rm ex height
      }

      % Error handling
      \ifthenelse{\equal{\tf@@scalemethod}{\TF@ER@SCALE}}{
        \TF@PackageError{%
          Invalid `scale:nnn' suboption argument in\MessageBreak
          #1 parameters `\csname tf@#1fontname\endcsname'}{}
      }{
        \ifthenelse{\equal{#1}{textfigures}}{
          \ifthenelse{\equal{\tf@nextsuboption}{lowercase}}
            {\edef\tf@@scalemethod{\TF@ER@SCALE}}{}
          \ifthenelse{\equal{\tf@nextsuboption}{lc}}
            {\edef\tf@@scalemethod{\TF@ER@SCALE}}{}
          \ifthenelse{\equal{\tf@nextsuboption}{uppercase}}
            {\edef\tf@@scalemethod{\TF@ER@SCALE}}{}
          \ifthenelse{\equal{\tf@nextsuboption}{uc}}
            {\edef\tf@@scalemethod{\TF@ER@SCALE}}{}
          \ifthenelse{\equal{\tf@nextsuboption}{figures}}
            {\edef\tf@@scalemethod{\TF@ER@SCALE}}{}
          \ifthenelse{\equal{\tf@nextsuboption}{fig}}
            {\edef\tf@@scalemethod{\TF@ER@SCALE}}{}
          \ifthenelse{\equal{\tf@@scalemethod}{\TF@ER@SCALE}}{
            \TF@PackageError{%
              Invalid `scale:\tf@nextsuboption' suboption argument in\MessageBreak
              option `textfigures=\tf@textfiguresfontname'}{}
          }{}
        }{}
      }

      % Initialise \tf@#1scalefactor if we can at this stage (generally not yet
      % possible if \tf@@scalemethod == \TF@EX@SCALE, \TF@LC@SCALE, etc.)
      \ifthenelse{\equal{\tf@@scalemethod}{\TF@NO@SCALE}}{
        \expandafter\xdef\csname tf@#1scalefactor\endcsname{\TF@UNSCALED}
      }{
        \ifthenelse{\equal{\tf@@scalemethod}{\TF@FX@SCALE}}{
          \expandafter\xdef\csname tf@#1scalefactor\endcsname
            {\strip@pt\dimexpr\tf@nextsuboption pt\relax}
        }{}
      }

      % We can apply fixed (constant literal) value scaling with rm-relative
      % scaling if we managed to save the computed scale factor in the aux file
      % during the previous run and user options haven't changed significantly
      % since then.
      \ifthenelse{\equal{\tf@fontencoding}{\tf@aux@fontencoding}
              \AND\equal{\tf@rmfontname}{\tf@aux@rmfontname}
              \AND\equal{\csname tf@#1fontname\endcsname}
                        {\csname tf@aux@#1fontname\endcsname}
          \AND\NOT\equal{\csname tf@aux@#1scalefactor\endcsname}{}}{
        \expandafter\xdef\csname tf@#1scalefactor\endcsname
          {\csname tf@aux@#1scalefactor\endcsname}
        \edef\tf@@scalefactor{\csname tf@#1scalefactor\endcsname}
        \edef\tf@@scalefactor{\strip@pt\dimexpr\tf@@scalefactor pt\relax}
        \ifthenelse{\equal{\tf@@scalefactor}{1}}
          {\edef\tf@@scalemethod{\TF@NO@SCALE}}
          {\edef\tf@@scalemethod{\TF@FX@SCALE}}
      }{}
      \expandafter\xdef\csname tf@#1scalemethod\endcsname{\tf@@scalemethod}
      \TF@PackageInfo{#1 scale method = \csname tf@#1scalemethod\endcsname}
    \endgroup
  }
}
\forcsvlist{\tf@configure@fontscalingmethod}{sf,tt,math,textfigures}

% Initialise sf, tt, math and textfigures font scale factors
%-----------------------------------------------------------
\newcommand*\tf@initialise@fontscaling[1]{
  % This macro assumes that \tf@configure@fontscalingmethod{#1} has already
  % been executed, i.e., that \tf@#1scalemethod is properly configured
  \ifthenelse{\NOT\equal{#1}{sf}
          \AND\NOT\equal{#1}{tt}
          \AND\NOT\equal{#1}{math}
          \AND\NOT\equal{#1}{textfigures}}{
    \TF@PackageError{Internal error in \TF@PACKAGENAME.sty\MessageBreak
      Illegal parameter [#1]\MessageBreak
      in \string\tf@initialise@fontscaling}{}
  }{
    \edef\tf@@scalemethod{\csname tf@#1scalemethod\endcsname}

    \ifthenelse{\equal{\tf@@scalemethod}{\TF@ER@SCALE}}{
      % User error. Error message was raised when detected. Do nothing here.
    }{
    \ifthenelse{\equal{\tf@@scalemethod}{\TF@NO@SCALE}}{
      % By this stage, \tf@#1scalefactor has already been set to \TF@UNSCALED
      %--- Aux file -----------------------------------------------------------
      \tf@writeauxfile{\string\newcommand*%
                       \string\tf@aux@#1scalefactor{\TF@UNSCALED}}
      %------------------------------------------------------------------------
    }{
    \ifthenelse{\equal{\tf@@scalemethod}{\TF@FX@SCALE}}{
      % By this stage, \tf@#1scalefactor has already been set to
      % the correct fixed value
      %--- Aux file -----------------------------------------------------------
      \tf@writeauxfile{\string\newcommand*\string\tf@aux@#1scalefactor{%
                       \csname tf@#1scalefactor\endcsname}}
      %------------------------------------------------------------------------
    }{
      \begingroup
      \expandafter\xdef\csname tf@#1scalefactor\endcsname{\TF@UNSCALED}

      \edef\tf@@lc{bdfhklt}
      \edef\tf@@uc{WXY}
      \edef\tf@@fig{08}

      % For reference font (rm) relative scaling purposes, select (and
      % therefore load) an exceedingly unlikely user fontsize close to
      % \normalsize font size
      \normalsize
      \edef\tf@@temp{\strip@pt\dimexpr\f@size pt + 0.027182pt\relax}%
      \fontsize{\tf@@temp}{\f@baselineskip}

      \usefont{\encodingdefault}{\rmdefault}{m}{n}
      \ifthenelse{\equal{\tf@@scalemethod}{\TF@EX@SCALE}}
        {\@tempdima=\fontdimen5\font}{}
       % note that with many fonts, lc, uc & fig scaling methods
       % are not particularly reliable
      \ifthenelse{\equal{\tf@@scalemethod}{\TF@LC@SCALE}}
        {\setbox0=\hbox{\tf@@lc}\@tempdima=\ht0}{}
      \ifthenelse{\equal{\tf@@scalemethod}{\TF@UC@SCALE}}
        {\setbox0=\hbox{\tf@@uc}\@tempdima=\ht0}{}
      % note that we scale to rm font figures size, even if a
      % substitute osf is in force
      \ifthenelse{\equal{\tf@@scalemethod}{\TF@FG@SCALE}}
        {\setbox0=\hbox{\tf@@fig}\@tempdima=\ht0}{}

      \ifthenelse{\equal{#1}{textfigures}}{
        \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@XF}}
          {\usefont{\tf@substosffontencoding}{\tf@substosffont}{m}{n}}
          {\usefont{\encodingdefault}{\rmdefault}{m}{n}}  % redundant
      }{
        \ifthenelse{\equal{#1}{math}}{
          % handled below
        }{
          % sf and tt
          \usefont{\encodingdefault}{\csname #1default\endcsname}{m}{n}
        }
      }

      \ifthenelse{\equal{#1}{math}}{
        \ifthenelse{\equal{\tf@@scalemethod}{\TF@EX@SCALE}}{
          \setbox0=\hbox{$x$} % to ensure font is selected
          \@tempdimb=\fontdimen5\textfont\tf@mathfontfamily
          \tf@ifsuboption{ex}{\tf@mathfontoptions}{
            \ifthenelse{\equal{\tf@nextsuboption}{alt}}{
              \@tempdimb=\ht0
            }{}
          }{}
        }{}
         % lc, uc and fig math scaling are ridiculously unreliable
        \ifthenelse{\equal{\tf@@scalemethod}{\TF@LC@SCALE}}
          {\setbox0=\hbox{$\tf@@lc$}\@tempdimb=\ht0}{}
        \ifthenelse{\equal{\tf@@scalemethod}{\TF@UC@SCALE}}
          {\setbox0=\hbox{$\tf@@uc$}\@tempdimb=\ht0}{}
        \ifthenelse{\equal{\tf@@scalemethod}{\TF@FG@SCALE}}
          {\setbox0=\hbox{$\tf@@fig$}\@tempdimb=\ht0}{}
      }{
        \ifthenelse{\equal{\tf@@scalemethod}{\TF@EX@SCALE}}
          {\@tempdimb=\fontdimen5\font}{}
        \ifthenelse{\equal{\tf@@scalemethod}{\TF@LC@SCALE}}
          {\setbox0=\hbox{\tf@@lc}\@tempdimb=\ht0}{}
        \ifthenelse{\equal{\tf@@scalemethod}{\TF@UC@SCALE}}
          {\setbox0=\hbox{\tf@@uc}\@tempdimb=\ht0}{}
        \ifthenelse{\equal{\tf@@scalemethod}{\TF@FG@SCALE}}
          {\setbox0=\hbox{\tf@@fig}\@tempdimb=\ht0}{}
      }

      \edef\tf@@scalefactor
        {\strip@pt\dimexpr \p@ * \@tempdima / \@tempdimb\relax}

      \ifbool{tf@#1scaledatloadtime}{
        \TF@PackageError{%
          INTERNAL PACKAGE ERROR: flag `tf@#1scaledatloadtime'\MessageBreak
          tested true in command `\tf@initialise@fontscaling',\MessageBreak
          Please report this error to the package maintainer}{}
      }{
        % Font wasn't scaled at load time, most likely because we haven't
        % configured the font for load time scaling and/or we haven't
        % saved the scale factor and reloaded it from the aux file yet.
        \expandafter\xdef\csname tf@#1scalefactor\endcsname{\tf@@scalefactor}
        %--- Aux file ---------------------------------------------------------
        \tf@writeauxfile{\string\newcommand*\string\tf@aux@#1scalefactor{%
          \csname tf@#1scalefactor\endcsname}}
        %----------------------------------------------------------------------
        \ifthenelse{\NOT\equal{\csname tf@#1scalemethod\endcsname}{\TF@FX@SCALE}}{
          \ifthenelse{\equal{#1}{sf}\OR\equal{#1}{tt}}{
            % math and (generally) text figures do not require
            % two pass font scaling
            \tf@notifyauxfiledirty{#1}
          }{}
        }{}
      }
      \endgroup
    }}}
  }
  \TF@PackageInfo{#1 scale factor = \csname tf@#1scalefactor\endcsname}
}

% Initialise math size declarations
%----------------------------------
\newcommand*\tf@initialise@mathsizes{
  \newcommand*\tf@@scalemathfont[1]{
    \begingroup
      \csname ##1\endcsname
      \let\oldf@size\f@size
      \dimen@\f@size\p@
      \@tempdima\tf@mathscalefactor\dimen@
      \edef\f@size{\strip@pt\@tempdima}
      \calculate@math@sizes
      \csname S@\f@size\endcsname
      \let\f@size\oldf@size

      \expandafter\xdef\csname S@@tf\f@size\endcsname{\tf@size}
      \expandafter\xdef\csname S@@sf\f@size\endcsname{\sf@size}
      \expandafter\xdef\csname S@@ssf\f@size\endcsname{\ssf@size}

      \expandafter\gdef\csname S@\f@size\endcsname{%
        \xdef\tf@size{\csname S@@tf\f@size\endcsname}%
        \xdef\sf@size{\csname S@@sf\f@size\endcsname}%
        \xdef\ssf@size{\csname S@@ssf\f@size\endcsname}%
        \TF@PackageDebugInfoNoLine{Math size \string\S@\f@size: %
            [\f@size][\tf@size][\sf@size][\ssf@size]}%
      }
    \endgroup
  }
  \forcsvlist{\tf@@scalemathfont}
    {tiny,scriptsize,footnotesize,small,normalsize,large,Large,LARGE,huge,Huge}
  \ifthenelse{\classloaded{memoir}}{
    \forcsvlist{\tf@@scalemathfont}{miniscule,HUGE}
  }{}
  \booltrue{tf@mathscaledatloadtime}
}

% Text figures spacing (tracking). User configurable by setting `spacing:nnn'
% suboption in `textfigures' package option.  E.g.,
%   textfigures=kpfonts:light:spacing:-20
% nnn may be any integer from -1000 to 1000. Given value n, the substitute
% text figures font will be kerned nnn/1000em. Requires the microtype package
% -- complains if not already loaded.
%----------------------------------------------------------------------------
\newcommand*\tf@textfiguresspacing{0}
\tf@newbool{tf@textfiguresspacingimplicit}{true}

\newcommand*\tf@initialise@textfiguresfontspacing{
  \tf@ifsuboption{spacing}{\tf@textfiguresfontoptions}{
    \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@XF}}{
      \ifthenelse{\isinteger{\tf@nextsuboption}
            \AND\(\tf@nextsuboption > -1001\)
            \AND\(\tf@nextsuboption <  1001\)}{
          \xdef\tf@textfiguresspacing{\tf@nextsuboption}
          \boolfalse{tf@textfiguresspacingimplicit}
      }{
        \TF@PackageError{%
          Invalid `spacing:nnn' suboption argument in your\MessageBreak
          package option `textfigures=\tf@textfiguresfontname'.\MessageBreak
          Integer `nnn' must be between -1000 and 1000}{}
      }
    }{
      \TF@PackageError{%
        Ignoring package suboption `spacing:nnn' in\MessageBreak
        `textfigures=\tf@textfiguresfontname'}{}
    }
  }{}

  % set textfigures=...:spacing:1... suboption to take the <true> branch
  % (microtype won't apply outer kerning if spacing == 0, we just follow
  % along with that)
  \ifthenelse{\NOT\equal{\tf@textfiguresspacing}{0}}{
    \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@XF}}{
      \@ifpackageloaded{microtype}{
        \tf@ifsuboption{lkern}{\tf@textfiguresfontoptions}{
          \ifthenelse{\isinteger{\tf@nextsuboption}}{
            \edef\tf@MTtrackingL{\tf@nextsuboption}
          }{
            \TF@PackageError{%
              Invalid `lkern:\tf@nextsuboption' suboption value\MessageBreak
              (`\tf@nextsuboption' should be an integer)}{}
          }
        }{
          \numdef\tf@MTtrackingL{\tf@textfiguresspacing}
        }
        \tf@ifsuboption{rkern}{\tf@textfiguresfontoptions}{
          \ifthenelse{\isinteger{\tf@nextsuboption}}{
            \edef\tf@MTtrackingR{\tf@nextsuboption}
          }{
            \TF@PackageError{%
              Invalid `rkern:\tf@nextsuboption' suboption value\MessageBreak
              (`\tf@nextsuboption' should be an integer)}{}
          }
        }{
          \numdef\tf@MTtrackingR{\tf@textfiguresspacing}
        }
        \SetTracking[outer kerning={\tf@MTtrackingL,\tf@MTtrackingR}]
          {encoding=*, family=\tf@substosffont}
          {\tf@textfiguresspacing}
      }{
        \TF@PackageError{%
          The microtype package must be loaded before\MessageBreak
          loading the typeface package if suboption\MessageBreak
          `spacing:nnn' in `textfigures=\tf@textfiguresfontname'\MessageBreak
          is to have any effect. Ignoring suboption `spacing'}{}
        \renewcommand*\tf@textfiguresspacing{0}
      }
    }{}
  }{}
  %--- Aux file ---------------------------------------------------------------
  \tf@writeauxfile{\string\newcommand*\string\tf@aux@textfiguresspacing{%
    \tf@textfiguresspacing}}
  %----------------------------------------------------------------------------
}

% Load remaining Required Packages
% ================================
\TF@PackageDebugInfo{Loading remaining required packages...}

\RequirePackage{scalefnt}
\usepackage{anyfontsize}

\ifbool{tf@debug}{
  \@ifpackageloaded{xcolor}{\relax}  % colour font substitutions when debugging
    {\RequirePackage[dvipsnames,svgnames,x11names]{xcolor}}
}

% More housekeeping: additional configuration if debugging
%---------------------------------------------------------
\ifbool{tf@debug}{
  \TF@PackageDebugInfo{Configuring extra debug routines...}
  \listfiles % list the names of files read during this job run
}{}

% Encodings management
%---------------------
\TF@PackageDebugInfo{Configuring encodings...}

\newcommand*\tf@@loadencpackage[2]{
  % #1 package name (e.g., inputenc)
  % #2 typeface option name (e.g., \tf@inputencoding)
  \edef\tf@@packagename{#1}
  \edef\tf@@optionname{\csname tf@#2\endcsname}
  \edef\tf@@optionstring{\csname tf@#2string\endcsname}
  \ifthenelse{\equal{\tf@@optionname}{\TF@DONTLOAD}
           \OR\equal{\tf@@optionname}{\TF@IGNORE}}{
    \relax
  }{
    \ifthenelse{\NOT\packageloaded{\tf@@packagename}}{
      \TF@PackageDebugInfo{Loading `#1' with parameters [\tf@@optionname]}
      \usepackage[\tf@@optionname]{\tf@@packagename}
    }{
      \TF@PackageWarningNoLine{%
        The `#1' package is already loaded. Please\MessageBreak
        check that its load-time options correspond with\MessageBreak
        your needs. Package option `#2=\tf@@optionstring'\MessageBreak
        ignored. (Set `#2=\TF@DONTLOAD' to make\MessageBreak
        this warning go away)}
    }
  }
}
\tf@@loadencpackage{inputenc}{inputencoding}
\tf@@loadencpackage{textcomp}{textcomp}
\ifbool{pdf}{
  \tf@@loadencpackage{cmap}{cmap}
}{}

% Even with cmap loaded, some pdf readers (notably including Adobe Acrobat)
% are unable to search for or copy ligatures and oldstyle nums from
% certain fonts. This macro provides a fix that often works. It depends
% on the availability of `glyphtounicode.tex' in your TEXMF tree.
% It is not guaranteed to work always since other factors might intervene,
% e.g., an odd fontencoding (try T1 instead), the actual pdf reader being
% used to view the document, which way the wind is blowing, etc.
\newcommand*\tf@pdfglyphcorrection[1]{
  \ifbool{pdf}{
    \IfFileExists{glyphtounicode}{
      \TF@PackageInfoNoLine{%
        Correction applied to fix #1 font\MessageBreak
        ligatures and old style figures search\MessageBreak
        and copy problems. It might or might\MessageBreak
        not work, depending on your pdf reader}
      \input{glyphtounicode}
      \pdfglyphtounicode{f_f}{FB00}
      \pdfglyphtounicode{f_i}{FB01}
      \pdfglyphtounicode{f_l}{FB02}
      \pdfglyphtounicode{f_f_i}{FB03}
      \pdfglyphtounicode{f_f_l}{FB04}
      \pdfgentounicode=1
    }{
      \TF@PackageInfoNoLine{%
        `glyphtounicode.tex' not found. Correction to\MessageBreak
        #1 font ligatures and old style figures search\MessageBreak
        and copy problem has not been applied}
    }
  }{}
}

\ifthenelse{\equal{\tf@fontencoding}{\TF@DONTLOAD}
         \OR\equal{\tf@fontencoding}{\TF@IGNORE}}{
  % Sneaky fontenc disappears itself from LaTeX's loaded packages
  % record. Check for the existence of \@ifl@ter@@ rather than trying
  % \@ifpackageloaded{fontenc}
  \ifthenelse{\isundefined{\@ifl@ter@@}}{
    \TF@PackageInfoNoLine{%
      The `fontenc' package does not appear to be loaded,\MessageBreak
      yet you have elected not to load it at this time.\MessageBreak
      Are you certain that this is a good idea?}
  }{}
}{
  \TF@PackageDebugInfo{Loading `fontenc' with parameters [\tf@fontencoding]}
  \usepackage[\tf@fontencoding]{fontenc}
  \TF@PackageDebugInfo{\string\encodingdefault=\encodingdefault}
}

% Namespace initialisation
% ========================
\TF@PackageDebugInfo{Initialising namespaces...}

% Rationalise typeface options namespace (typeface aliases)
\tf@rationalisefontnames   % constructed by \newtypeface commands

% Zero out the font name strings
\newcommand*\tf@rmprintname{undefined}
\newcommand*\tf@sfprintname{undefined}
\newcommand*\tf@ttprintname{undefined}
\newcommand*\tf@mathprintname{undefined}
\newcommand*\tf@symbolsprintname{undefined}
\newcommand*\tf@textfiguresprintname{undefined}

% Zero out the self-registered macro names saved whenever a font is loaded
% (see the \newtypeface command, above, to see how these are constructed)
\newcommand*\tf@rmfontloadcommand{undefined}
\newcommand*\tf@sffontloadcommand{undefined}
\newcommand*\tf@ttfontloadcommand{undefined}
\newcommand*\tf@mathfontloadcommand{undefined}
\newcommand*\tf@symbolsfontloadcommand{undefined}
\newcommand*\tf@textfiguresfontloadcommand{undefined}

% Discard any previously defined math symbols fonts, more or less
\let\glb@currsize\relax

% Text figures management
% =======================
% Lowercase (text) numerals -- you almost certainly won't use these unless
% your font natively provides old style figures. If it does, then all you need
% do is to include `textfigures' in your package options. If your selected
% font includes old style figures, to turn them on throughout your document
% (except if set in the `liningnums' environment). If your font does not
% natively provide old style figures, specifying `textfigures=xxx' (where xxx
% is `palatino`, `adobeminionpro' or any other font configured for this) will
% attempt to use the old style figures from the xxx font instead. The catch is
% that to use the (non-native) substitute text figures font, you have to place
% your numbers in a `textstylenums` environment, e.g.,
%   \begin{textstylenums}1234\end{textstylenums}
% or pass them to the `\textstylenums' command. Unlike LaTeX's standard
% `\oldstylenums' command, you can include some punctuation characters
% alongside figures, e.g., you can include `$', hyphen, en dash, em dash,
% full stop, comma, etc., depending on the font. However, since the success of
% this is font-dependant, you probably should avoid this writing style.
%
% WARNING: DO NOT ATTEMPT TO USE \begin{textstylenums}....\end{textstylenums}
% OR \textstylenums IN MATHS ENVIRONMENTS! IT WILL END IN TEARS!
%
% Note that if a substitute font is specified, `textnums' substitutes one font
% family for another, whereas `oldstylenums' does not (it uses the old style
% figures from the currently selected font if they are available, or typesets
% little black rectangles otherwise). Converting your document to use the
% `textnums' environment or `\textstylenums' command needn't require much
% effort if you write a wildcard based search and replace routine in your
% document editor to automate this for you (making sure to avoid numbers in
% TeX command parameters, etc).
%------------------------------------------------------------------------------
\TF@PackageDebugInfo{Initialising textfigures commands...}

% Useful author-level boolean expressions that can be used in
% \ifthenelse tests. E.g., \ifthenelse{\NOT\isliningnums}{...}{...}
\def\isliningnums{\equal{\tf@osf@method}{\TF@OSF@LF}}

% Provide the default (stub) version of liningnums environment that (when
% fleshed out on a per font basis in the font commands below) switches to
% lining (uppercase) figures whenever the environment is in effect.
\tf@newbool{tf@liningnums}{false}                                              % TODO: should we make this nestable?
\newenvironment{liningnums}
  {\booltrue{tf@liningnums}}
  {\boolfalse{tf@liningnums}}
\newcommand*\tf@resetliningnumsenvironment{
  \renewenvironment{liningnums}
    {\booltrue{tf@liningnums}}
    {\boolfalse{tf@liningnums}}
}

% Helper routine to redefine liningnums environment when using native osf
\newcommand*\tf@define@liningfigures[1]{
  % #1 is the font family name for lining figures, e.g., pplx (vs pplj)
  \renewenvironment{liningnums}{%
    \notbool{tf@suppressfiguressubstitution}{%
      \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@LININGNUMS}}{}%
      \fontfamily{#1}\selectfont%
    }{}%
  }{%
    \boolfalse{tf@liningnums}%
  }
}

% Helper routine to define the \oldstylenums command for selected font families
\newcommand*\tf@define@oldstylenums@cmd[1]{
  % #1 is the font family name for old style figures, e.g., pplj (vs pplx)
  \renewcommand\oldstylenums[1]{{\fontfamily{#1}\selectfont ##1}}
}

% Access old style figures via TS1 font encoding
\newcommand*\tf@TSencodedosf{
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}
           \OR\equal{\tf@osf@method}{\TF@OSF@SC}}{
    \renewcommand*\tf@osf@method{\TF@OSF@TS}
    \tf@resetliningnumsenvironment
  }{}
}

% Access old style figures by switching to small caps
\newcommand*\tf@SCencodedosf{
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}
           \OR\equal{\tf@osf@method}{\TF@OSF@TS}}{
    \renewcommand*\tf@osf@method{\TF@OSF@SC}
    \tf@resetliningnumsenvironment
  }{}
}

% Advise users that their selected font does not support old style figures
\newcommand\TF@NativeOSFError{
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}}{
    \TF@PackageError{Option `typeface=\tf@rmfontname' does not\MessageBreak
       support `textfigures=\tf@textfiguresfontname'.\MessageBreak
       Setting `textfigures=false'}{}
    \renewcommand*\tf@osf@method{\TF@OSF@LF}
    \tf@resetliningnumsenvironment
    \renewcommand*\tf@textfiguresfontname{false}
  }{}
}

% Advise users that the selected font ONLY supports old style figures (rare!)
\newcommand\TF@NativeLFError{
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@LF}}{
    \TF@PackageError{Option `typeface=\tf@rmfont' does not\MessageBreak
       support `textfigures=\tf@textfiguresfontname' (default).\MessageBreak
       Setting `textfigures=oldstylefigures'}{}
    \renewcommand*\tf@osf@method{\TF@OSF@JF}
    \tf@resetliningnumsenvironment
    \renewcommand*\tf@textfiguresfontname{oldstylefigures}
  }{}
}

% Advise users that their selected math font kills support for old style figures
\newcommand\TF@NativeOSFMathError{
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@JF}}{
    \TF@PackageError{Option `typeface=\tf@rmfontname' does not\MessageBreak
       support combining `mathtypeface=\tf@mathfontname'\MessageBreak
       and `textfigures=\tf@textfiguresfontname'.\MessageBreak
       Setting `textfigures=false'}{}
    \renewcommand*\tf@osf@method{\TF@OSF@LF}
    \tf@resetliningnumsenvironment
    \renewcommand*\tf@textfiguresfontname{false}
  }{}
}

% Set up our INTERNAL \tf@textstylenums declaration and the
% AUTHOR textnums environment and \textstylenums command
%----------------------------------------------------------
\newcommand*\tf@initialise@textfiguresfontcommands{
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@TS}}{
  % Access old style figures via TS1 font encoding
    \newcommand*\tf@textstylenums{%
      \ifthenelse{\NOT\boolean{tf@liningnums}
              \AND\NOT\boolean{tf@suppressfiguressubstitution}}{%
        \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@TS}}{}%
        \fontencoding{TS1}\selectfont%
      }{}%
    }
  }{
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@SC}}{
    % Access old style figures via small caps
    \newcommand*\tf@textstylenums{%
      \ifthenelse{\NOT\boolean{tf@liningnums}
              \AND\NOT\boolean{tf@suppressfiguressubstitution}}{%
        \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@SC}}{}%
        \scshape%
      }{}%
    }
  }{
  \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@XF}}{
    % Access old style figures via substitute font
    \providecommand*\lsstyle{}  % create no-op if microtype isn't loaded
    \newcommand*\tf@textstylenums{%
      \ifthenelse{\NOT\boolean{tf@liningnums}
              \AND\NOT\boolean{tf@suppressfiguressubstitution}}{%
        \ifthenelse{\NOT\equal{\tf@textfiguresspacing}{0}
                    \AND\value{tf@enable@textnumspacing} = 0}%
          {\lsstyle}{}%  % microtype-based text figures spacing
        \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@XF}}{}%
        \notbool{tf@textfiguresscaledatloadtime}
          {\scalefont{\tf@textfiguresscalefactor}}{}%
        \fontencoding{\tf@substosffontencoding}%
        \fontfamily{\tf@substosffont}%
        \selectfont%
      }{}%
    }
  }{
    % Otherwise, access old style figures natively (i.e., deliver
    % whatever the loaded font provides, which is either text
    % figures or not)
    \newcommand*\tf@textstylenums{%
      \ifthenelse{\NOT\boolean{tf@liningnums}
              \AND\NOT\boolean{tf@suppressfiguressubstitution}}{%
        \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@JF}}{}%
      }{}%
    }
  }}}
  \robustify{\tf@textstylenums}

  % Define AUTHOR-LEVEL textnums environment
  %-----------------------------------------
  \newenvironment{textnums}{%
    \tf@textstylenums%
  }{}

  % ... and AUTHOR-LEVEL \textstylenums (syn: \tsf) command
  %--------------------------------------------------------
  \newcommand\textstylenums[1]{%
    \begingroup%
    \begin{textnums}##1\end{textnums}%
    \endgroup%
  }

  \newcommand\tsf[1]{%
    \begingroup%
    \begin{textnums}##1\end{textnums}%
    \endgroup%
  }

  % ... and AUTHOR-LEVEL \liningstylenums (syn: \lsf) command
  %----------------------------------------------------------
  \newcommand\liningstylenums[1]{%
    \begingroup%
    \begin{liningnums}##1\end{liningnums}%
    \endgroup%
  }

  \newcommand\lsf[1]{%
    \begingroup%
    \begin{liningnums}##1\end{liningnums}%
    \endgroup%
  }

  % AUTHOR-LEVEL commands to enable/disable textnums letterspacing
  % (uses a counter for reentrancy)
  \newcounter{tf@enable@textnumspacing}
  \newcommand*\enabletextnumspacing{\addtocounter{tf@enable@textnumspacing}{1}}
  \newcommand*\disabletextnumspacing{\addtocounter{tf@enable@textnumspacing}{-1}}
  \newcommand*\reenabletextnumspacing{\setcounter{tf@enable@textnumspacing}{0}}
  \reenabletextnumspacing
}

% Typeface selection
% ==================
\TF@PackageDebugInfo{Loading typefaces in load order [\tf@fontloadorder] ...}

% Font loading commands are (generally) processed in this order:
%   textfigures, symbols, math, roman, sans serif, teletype
%
% Where possible, fonts are loaded using std packages (\tf@usefontpackage{...}),
% otherwise they are loaded via direct commands (\renewcommand\rmdefault{...}).
% Many packages load "matching" fonts, e.g., one might load courier tt
% alongside the rm font that it specifies. The typeface package attempts to
% reverse this when it can in order to ensure that when users specify
% particular fonts, that is in fact what they get, rather than, for example,
% getting the "matching" font decided by a font package author some long time ago.
%
% Note that when loading multiple font packages one after the other, glyph
% definitions can potentially collide. When this happens, later loaded
% glyphs can (often silently) override earlier definitions or in other case
% simply trigger errors. You should (must) always thoroughly check your output
% pdf document to ensure that the body text, math, symbols and (potential) text
% figures substitution fonts work together to produce desired results. Not all
% combinations will produce satisfactory output.
%
% The "textfigures, symbols, math, roman, sans serif, teletype" font
% load order should not be wholly relied upon. To obviate the "clash of
% glyphs" problem as best we can, this package will, for example, load the
% roman font family before loading math where a particular math package
% requires the standard load ordering to change. We might even, in extreme
% cases, load the roman font, then math, then to counteract a certain side
% effect, reload roman to re-establish its original configuration. Specific
% behavioural rules for individual situations are set out in the code above.
% Bottom line, however: we try to achieve the combination of typefaces as the
% end-user most likely intended.
%------------------------------------------------------------------------------
% Construct and execute font load commands macro in specified font load order
\newcommand*\tf@loadfonts{}
\renewcommand*\do[1]{
  \ifcsdef{beforeloading#1}
    {\g@addto@macro{\tf@loadfonts}{\csname beforeloading#1\endcsname}}{}
  \g@addto@macro{\tf@loadfonts}{\csname tf@load#1typeface\endcsname}
  \ifcsdef{afterloading#1}
    {\g@addto@macro{\tf@loadfonts}{\csname afterloading#1\endcsname}}{}
}
\expandafter\tf@doColonSeparatedList\expandafter{\tf@fontloadorder}
\tf@loadfonts

% After loading fonts, set up font scaling ...
\forcsvlist{\tf@initialise@fontscaling}{sf,tt,math,textfigures}

% ... and math size declarations ...
\tf@initialise@mathsizes

% ... and textfigures font spacing ...
\tf@initialise@textfiguresfontspacing

% ... and text figures author-level commands
\tf@initialise@textfiguresfontcommands

% Finally, hook our work into LaTeX's font selection machinery
% ============================================================

\TF@PackageDebugInfo{Hooking font scaling into LaTeX commands ...}

% Guard against the (presumably exceedingly unlikely) event where sf and
% tt are 1) the same font, yet 2) are being scaled by different amounts
\tf@newbool{tf@@sfttscaleconflict}{false}
\ifthenelse{\equal{\tf@sfdefault}{\tf@ttdefault}}{
  \@tempdima=\tf@sfscalefactor\p@
  \@tempdimb=\tf@ttscalefactor\p@
  \ifthenelse{\NOT\lengthtest{\@tempdima = \@tempdimb}}{
    \booltrue{tf@@sfttscaleconflict}
    \TF@PackageError{%
      Requested sans serif and teletypewriter fonts are\MessageBreak
      identical except for differing scale factors\MessageBreak
      [sf=\tf@sfscalefactor, tt=\tf@ttscalefactor].\MessageBreak
      **** This isn't going to work. Please help\MessageBreak
      **** me out. I don't know what to do}{}
    \global\boolfalse{tf@sfscaledatloadtime}
    \global\boolfalse{tf@ttscaledatloadtime}
  }{}
}{}

\def\empty@sfcnt#1{%
  % Subclass LaTeX's default font size function, inserting sf/tt               % TODO: confirm this works with lua, xetex
  % scale factors into \optional@arg if it is empty at the time
  \def\tf@@sizeinfofunction{#1}%
  \tf@newbool{tf@@sffamily}{false}%
  \tf@newbool{tf@@ttfamily}{false}%
  \ifdefstrequal{\tf@sfdefault}{\f@family}{\booltrue{tf@@sffamily}}{}%
  \ifdefstrequal{\tf@ttdefault}{\f@family}{\booltrue{tf@@ttfamily}}{}%
  %
  % Last chance for font load functions to affect load-time scaling
  \tf@empty@sfcnt@hook%
  %
  % So long as it's empty, set \optional@arg to appropriate scale factor
  \ifthenelse{\equal{\optional@arg}{}\AND\NOT\boolean{tf@@sfttscaleconflict}}{%
    \ifthenelse{\boolean{tf@@sffamily}
        \AND\NOT\equal{\tf@sfscalemethod}{\TF@NO@SCALE}}{%
      \edef\optional@arg{\tf@sfscalefactor}%
      \def\tf@@sizeinfofunction{\@font@info}%
      \xdef\tf@sfscalemethod{\TF@FX@SCALE}%
      \global\booltrue{tf@sfscaledatloadtime}%
      \TF@PackageInfo{%
        Scaling sf font `\curr@fontshape' (\tf@sfscalefactor*\f@size pt)}%
    }{}%
    \ifthenelse{\boolean{tf@@ttfamily}
        \AND\NOT\equal{\tf@ttscalemethod}{\TF@NO@SCALE}}{%
      \edef\optional@arg{\tf@ttscalefactor}%
      \def\tf@@sizeinfofunction{\@font@info}%
      \xdef\tf@ttscalemethod{\TF@FX@SCALE}%
      \global\booltrue{tf@ttscaledatloadtime}%
      \TF@PackageInfo{%
        Scaling tt font `\curr@fontshape' (\tf@ttscalefactor*\f@size pt)}%
    }{}%
  }{}%
  %
  \@tempdimb \f@size\p@%
  \ifx\optional@arg\@empty%
  \else%
    \@tempdimb \optional@arg\@tempdimb%
    \tf@@sizeinfofunction{Font\space shape\space `\curr@fontshape'\space
    will\space be\MessageBreak
    scaled\space to\space size\space \the\@tempdimb}%
  \fi%
  \edef\external@font{\mandatory@arg\space at\the\@tempdimb}%
}

\tf@newbool{tf@suppressfiguressubstitution}{false}
\newcommand*\enablefiguressubstitution{%
  \boolfalse{tf@suppressfiguressubstitution}%
}
\newcommand*\disablefiguressubstitution{%
  \booltrue{tf@suppressfiguressubstitution}%
}

\let\tf@oldrmfamily\rmfamily
\renewrobustcmd\rmfamily{%
  \enablefiguressubstitution%      % we enable text figures substitution
  \tf@oldrmfamily%                 % even if user has changed \rmdefault
  \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@RM}}{}%
}

\let\tf@oldsffamily\sffamily
\renewrobustcmd\sffamily{%
  \disablefiguressubstitution%
  \tf@oldsffamily%
  \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@SF}}{}%
}

\let\tf@oldttfamily\ttfamily
\renewrobustcmd\ttfamily{%
  \disablefiguressubstitution%
  \tf@oldttfamily%
  \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@TT}}{}%
}

% Provide AUTHOR level read-only access to several internal values
%-----------------------------------------------------------------
\xdef\rmprintname{\tf@rmprintname}
\xdef\sfprintname{\tf@sfprintname}
\xdef\ttprintname{\tf@ttprintname}
\xdef\mathprintname{\tf@mathprintname}
\xdef\symbolsprintname{\tf@symbolsprintname}
\xdef\textfiguresprintname{\tf@textfiguresprintname}

% Package info and typeface testing commands
% ==========================================

\ifbool{tf@printinfo}{
  \TF@PackageDebugInfo{Configuring print info commands...}

  \@ifpackageloaded{array}{\relax}{\usepackage{array}}
  \everymath=\expandafter{%
    \the\everymath%
    \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@MATH}}{}%
  }

  \providecommand*\tfabc{abcdefghijklmnopqrstuvwxyz}
  \providecommand*\tfABC{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
  \providecommand*\tfdigits{0123456789}
  \providecommand*\tftext{abcdefghijklmnopqrstuvwxyz %
    ct st th ff fi fj fl ffi ffl ft ij \ae\ \oe\ \"o\ \~e\ wavaw %
    {\large large} {\footnotesize footnotesize}}
  \providecommand*\tfTEXT{ABCDEFGHIJKLMNOPQRSTUVWXYZ %
    Ct St Th Ff Fi Fj Fl Ffi Ffl IJ \AE\ \OE\ \"O\ \~E\ WAVAW}
  \providecommand*\tfpunctuation{\$ \% . , : ; ? \& ! \# = ( \_ ) + - -- ---}

  \newcommand\tfprintinfopage{%
    \pagestyle{empty}%
    \raggedbottom%
    \tfprintpackageoptions%
    \tfprintinfo%
    \tfprinttext{rm}%
    \tfprinttext{sf}%
    \tfprinttext{tt}%
    \tfprintfigures{rm}%
    \tfprinttextalphabets%
  }

  \newcommand*\tf@@printfontname[1]{%            % helper command
    \ifthenelse{
      \equal{\csname tf@#1fontdefaultstatus\endcsname}{\TF@IMPLICITDEFAULT}}{%
        <\TF@DEFAULT> \tf@@printfontname@@helper{#1}%
    }{%
    \ifthenelse{
      \equal{\csname tf@#1fontdefaultstatus\endcsname}{\TF@EXPLICITDEFAULT}}{%
        \TF@DEFAULT\space\tf@@printfontname@@helper{#1}%
    }{%
    \ifthenelse{
      \equal{\csname tf@#1fontdefaultstatus\endcsname}{\TF@EXPLICITOTHER}}{%
        \csname tf@#1fontname\endcsname%
    }{}}}
  }

  \newcommand*\tf@@printfontname@@helper[1]{%    % helper of helper command
      \ifthenelse{\NOT\equal{\csname tf@#1fontname\endcsname}{\TF@DEFAULT}}
        {(\csname tf@#1fontname\endcsname\space-- see `\TF@CONFIGFILE')}
        {}%
  }

  \newcommand\tfprintpackageoptions{{%
    \rmfamily\selectfont\noindent%
    \texttt{typeface}\ package options:\par\noindent%
    \begin{tabular}{@{}
                    >{\ttfamily}l
                    >{\ttfamily}l@{\hspace{2.5em}}
                    >{\ttfamily}l
                    >{\ttfamily}l@{}}
%------------------------------------------------------------------------------
      typeface          & \tf@@printfontname{rm}                              &
      fontencoding      &
      \ifthenelse{\equal{\tf@fontencodingdefaultstatus}{\TF@IMPLICITDEFAULT}}{%
        <\TF@DEFAULT> (\TF@DEFAULTFONTENCODING)%
      }{%
        \tf@fontencodingstring\space%
        \ifthenelse{\equal{\tf@fontencodingdefaultstatus}{\TF@EXPLICITDEFAULT}
                 \OR\value{tf@fontencodingsuboptionscount} > 1}{%
          (\tf@fontencodingprimary)%
        }{}%
      }                                                                      \\
%------------------------------------------------------------------------------
      textfigures       & \tf@@printfontname{textfigures}%
                          \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@TS}}
                            {(TS1)}
                            {\ifthenelse{\equal{\tf@osf@method}{\TF@OSF@SC}}
                              {(smallcaps)}
                              {}%
                            }                                                 &
      inputencoding      &
      \ifthenelse{\equal{\tf@inputencodingdefaultstatus}{\TF@IMPLICITDEFAULT}}{%
        <\TF@DEFAULT> (\TF@DEFAULTINPUTENCODING)%
      }{%
        \tf@inputencodingstring\space%
        \ifthenelse{\equal{\tf@inputencodingdefaultstatus}{\TF@EXPLICITDEFAULT}}{%
          (\tf@inputencoding)%
        }{}%
      }                                                                      \\
%------------------------------------------------------------------------------
      sanstypeface      & \tf@@printfontname{sf}                              &
      textcomp      &
      \ifthenelse{\equal{\tf@textcompdefaultstatus}{\TF@IMPLICITDEFAULT}}{%
        <\TF@DEFAULT> (\TF@DEFAULTTEXTCOMP)%
      }{%
        \tf@textcompstring\space%
        \ifthenelse{\equal{\tf@textcompdefaultstatus}{\TF@EXPLICITDEFAULT}}{%
          (\tf@textcomp)%
        }{}%
      }                                                                      \\
%------------------------------------------------------------------------------
      monotypeface      & \tf@@printfontname{tt}                              &
      fontloadorder     & \ifbool{tf@fontloadorderimplicit}{<}{}%
                          \ifthenelse{\equal{\tf@fontloadorder}{\TF@DEFAULTFONTLOADORDER}}
                            {\TF@DEFAULT}
                            {\tf@fontloadorder}%
                          \ifbool{tf@fontloadorderimplicit}{>}{}             \\
%------------------------------------------------------------------------------
      mathtypeface      & \tf@@printfontname{math}                            &
      printinfo         & \ifbool{tf@printinfoimplicit}{<}{}%
                          \ifbool{tf@printinfo}{true}{false}%
                          \ifbool{tf@printinfoimplicit}{>}{}                 \\
%------------------------------------------------------------------------------
      symbolstypeface   & \tf@@printfontname{symbols}                         &
      debug             & \ifbool{tf@debugimplicit}{<}{}%
                          \ifbool{tf@debug}{true}{false}%
                          \ifbool{tf@debugimplicit}{>}{}                     \\
%------------------------------------------------------------------------------
    \end{tabular}%
    \par\medskip%
  }}

  \newcommand\tfprintinfo{{%
    \noindent%
    \begin{tabular}{@{}lllrrrl@{}}
      \ttfamily Family   & \ttfamily Typeface & \ttfamily \TeX\ Name &
                           \ttfamily em size  & \ttfamily ex size    &
                           \ttfamily scale    & \ttfamily scale time \\
      \rmfamily Roman &
      \rmfamily \tf@rmprintname &
      \rmfamily \fontname\the\font &
      \rmfamily \tf@roundvi@pt{\the\fontdimen6\font} &
      \rmfamily \tf@roundvi@pt{\the\fontdimen5\font} &
      \rmfamily \tf@roundvi{1}%
                  \ifthenelse{\NOT\equal{\tf@rmscale}{\TF@UNSCALED}}
                    { [$\times$\tf@roundvi{\tf@rmscale}]}{} &
      \rmfamily not scaled
      \\
      \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@XF}}{%
        \rmfamily Text figures &
        \rmfamily \tf@textfiguresprintname &
        % NB, the following group will print gobbledegook if the
        % \tf@substosffont typeface doesn't properly map non-numeral chars to
        % standard print glyphs (e.g., see using textfigures=latinmodern)
        \begingroup%
          \ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@XFNAME}}{}%
          \notbool{tf@textfiguresscaledatloadtime}{%
            \scalefont{\tf@textfiguresscalefactor}%
          }{}%
          \fontencoding{\tf@substosffontencoding}%
          \fontfamily{\tf@substosffont}\selectfont\fontname\the\font%
        \endgroup &
        \rmfamily \begin{textnums}\tf@roundvi{\strip@pt\fontdimen6\font}\end{textnums}pt &
        \rmfamily \begin{textnums}\tf@roundvi{\strip@pt\fontdimen5\font}\end{textnums}pt &
        \rmfamily \begin{textnums}\tf@roundvi{\tf@textfiguresscalefactor}\end{textnums}&
        \rmfamily \ifthenelse{\equal{\tf@textfiguresscalemethod}{\TF@NO@SCALE}
                           \OR\equal{\tf@textfiguresscalefactor}{\TF@UNSCALED}}
                  {not scaled}
                  {\ifbool{tf@textfiguresscaledatloadtime}{load time}{run time}}
        \\
      }{}%
      \sffamily Sans Serif &
      \sffamily \tf@sfprintname &
      \sffamily \fontname\the\font &
      \sffamily \tf@roundvi@pt{\the\fontdimen6\font} &
      \sffamily \tf@roundvi@pt{\the\fontdimen5\font} &
      \sffamily \tf@roundvi{\tf@sfscalefactor} &
      \sffamily \ifthenelse{\equal{\tf@sfscalemethod}{\TF@NO@SCALE}
                         \OR\equal{\tf@sfscalefactor}{\TF@UNSCALED}}
                  {not scaled}
                  {\ifbool{tf@sffontdirty}{run time}{load time}}
      \\
      \ttfamily Typewriter &
      \ttfamily \tf@ttprintname &
      \ttfamily \fontname\the\font &
      \ttfamily \tf@roundvi@pt{\the\fontdimen6\font} &
      \ttfamily \tf@roundvi@pt{\the\fontdimen5\font} &
      \ttfamily \tf@roundvi{\tf@ttscalefactor} &
      \ttfamily \ifthenelse{\equal{\tf@ttscalemethod}{\TF@NO@SCALE}
                         \OR\equal{\tf@ttscalefactor}{\TF@UNSCALED}}
                  {not scaled}
                  {\ifbool{tf@ttfontdirty}{run time}{load time}}
      \\
      \rmfamily Math &
      \rmfamily $\tf@mathprintname$ &
      \rmfamily $\fontname\textfont\tf@mathfontfamily$ &
      \rmfamily $\tf@roundvi@pt{\the\fontdimen6\textfont\tf@mathfontfamily}$ &
      \rmfamily $\tf@roundvi@pt{\the\fontdimen5\textfont\tf@mathfontfamily}$ &
      \rmfamily $\tf@roundvi{\tf@mathscalefactor}$ &
      \rmfamily \ifthenelse{\equal{\tf@mathscalemethod}{\TF@NO@SCALE}
                         \OR\equal{\tf@mathscalefactor}{\TF@UNSCALED}}
                  {not scaled}
                  {\ifbool{tf@mathscaledatloadtime}{load time}{run time}}
      \\
      \rmfamily Symbols &
      \multicolumn{4}{l}{\rmfamily $\tf@symbolsprintname$} & &
      \rmfamily \ifthenelse{\equal{\tf@mathscalemethod}{\TF@NO@SCALE}
                         \OR\equal{\tf@mathscalefactor}{\TF@UNSCALED}}
                  {not scaled}
                  {\ifbool{tf@mathscaledatloadtime}{load time}{run time}}
      \\
    \end{tabular}%
    \par\medskip%
  }}

  \newcommand\tfprinttext[1]{{%
    \ifthenelse{\equal{#1}{rm}}{
      \newcommand\tf@nums{\begin{textnums}0123456789\end{textnums}}
      \newcommand\tf@NUMS{\begin{liningnums}0123456789\end{liningnums}}
    }{
      \newcommand\tf@nums{0123456789}
      \newcommand\tf@NUMS{}
    }%
    \csname #1family\endcsname\selectfont\noindent%
    \begin{tabular}{@{}>{\csname #1family\endcsname\selectfont}l
                       >{\csname #1family\endcsname\selectfont}l@{}}%
    `#1' family: & \ifthenelse{\equal{#1}{rm}}{\tf@rmprintname}{}%
                   \ifthenelse{\equal{#1}{sf}}{\tf@sfprintname}{}%
                   \ifthenelse{\equal{#1}{tt}}{\tf@ttprintname}{}\\
      Normal:             &         \tftext\ \tf@nums \\
                          &         \tfTEXT\ \tf@NUMS \\
      \textbf{Bold:}      & \textbf{\tftext\ \tf@nums}\\
                          & \textbf{\tfTEXT\ \tf@NUMS}\\
      \textit{Italic:}    & \textit{\tftext\ \tf@nums}\\
                          & \textit{\tfTEXT\ \tf@NUMS}\\
      \textsl{Slant:}     & \textsl{\tftext\ \tf@nums}\\
                          & \textsl{\tfTEXT\ \tf@NUMS}\\
      \textsc{Smallcaps:} & \textsc{\tftext\ \tf@nums}\\
                          & \textsc{\tfTEXT\ \tf@NUMS}\\
      Variants:           & {\fontseries{l}\selectfont Light}
                            {\fontseries{c}\selectfont Condensed}
                            {\fontseries{m}\selectfont Medium}
                            {\fontseries{sb}\selectfont Semi-bold}
                            {\fontseries{b}\selectfont Bold}
                            {\fontseries{bx}\selectfont Bold-extended}
                            {\scshape\bfseries Bold-Smallcaps}
                            {\fontseries{eb}\selectfont Extra-bold}\\
    \end{tabular}%
    \par\medskip%
  }}

  \newcommand\tfprintfigures[1]{{%
    \csname #1family\endcsname\selectfont\noindent%
    \begin{tabular}{@{}>{\rmfamily}l>{\rmfamily}l>{\rmfamily}l
                       >{\rmfamily}l>{\rmfamily}l>{\rmfamily}l
                       >{\rmfamily}l>{\rmfamily}l@{}}
      & Normal & Italics & Bold & Bold Italics & Punctuation           \\
      Plain numerals:                                                  &
        0123456789                                                     &
        \textit{0123456789}                                            &
        \textbf{0123456789}                                            &
        \textbf{\textit{0123456789}}                                   &
        \tfpunctuation                                                 \\
      $Math$:                                                          &
        $0123456789$                                                   &
        $\mathit{0123456789}$                                          &
        $\mathbf{0123456789}$                                          &
        $\mathbf{\mathit{0123456789}}$                                 &
        $\tfpunctuation$                                               \\
      \texttt{\textbraceleft liningnums\textbraceright}:               &
        \begin{liningnums}0123456789\end{liningnums}                   &
        \textit{\begin{liningnums}0123456789\end{liningnums}}          &
        \textbf{\begin{liningnums}0123456789\end{liningnums}}          &
        \textbf{\textit{\begin{liningnums}0123456789\end{liningnums}}} &
        \begin{liningnums}\tfpunctuation\end{liningnums}               \\
      \texttt{\textbraceleft textnums\textbraceright}%
        \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@TS}\AND\equal{#1}{rm}}
          { (TS1)}
          {\ifthenelse{\equal{\tf@osf@method}{\TF@OSF@SC}\AND\equal{#1}{rm}}
            { (smallcaps)}{}}:                                         &
        \begin{textnums}0123456789\end{textnums}                       &
        \textit{\begin{textnums}0123456789\end{textnums}}              &
        \textbf{\begin{textnums}0123456789\end{textnums}}              &
        \textbf{\textit{\begin{textnums}0123456789\end{textnums}}}     &
        \begin{textnums}\tfpunctuation\end{textnums}                   \\
      \texttt{\textbackslash textstylenums}%
        \ifthenelse{\equal{\tf@osf@method}{\TF@OSF@TS}\AND\equal{#1}{rm}}
          { (TS1)}
          {\ifthenelse{\equal{\tf@osf@method}{\TF@OSF@SC}\AND\equal{#1}{rm}}
            { (smallcaps)}{}}:                                         &
        \textstylenums{0123456789}                                     &
        \textit{\textstylenums{0123456789}}                            &
        \textbf{\textstylenums{0123456789}}                            &
        \textbf{\textit{\textstylenums{0123456789}}}                   &
        \textstylenums{\tfpunctuation}                                 \\
      \texttt{\textbackslash oldstylenums}:                            &
        \oldstylenums{0123456789}                                      &
        \textit{\oldstylenums{0123456789}}                             &
        \textbf{\oldstylenums{0123456789}}                             &
        \textbf{\textit{\oldstylenums{0123456789}}}                    &
        \oldstylenums{\tfpunctuation}                                  \\
      \texttt{\textbackslash oldstylenums} (TS1):                      &
        {\fontencoding{TS1}\selectfont0123456789}                      &
        {\fontencoding{TS1}\selectfont\textit{0123456789}}             &
        {\fontencoding{TS1}\selectfont\textbf{0123456789}}             &
        {\fontencoding{TS1}\selectfont\textbf{\textit{0123456789}}}    &
        {\fontencoding{TS1}\selectfont\tfpunctuation}                  \\
    \end{tabular}%
    \par\medskip%
  }}

  \newcommand\tfprinttextalphabets{{%
    \setlength{\parindent}{0pt}
    $acegmnopqrsuvwxyz$%
    \textrm{acegmnopqrsuvwxyz}%
    \textsf{acegmnopqrsuvwxyz}%
    \texttt{acegmnopqrsuvwxyz}\ %
    $bdfhijklt$%
    \textrm{bdfhijklt}%
    \textsf{bdfhijklt}%
    \texttt{bdfhijklt}\\%
    $\tfABC$\textrm{\tfABC}\textsf{\tfABC}\texttt{\tfABC}\\%
    $\tfdigits$\textrm{\tfdigits}\textsf{\tfdigits}\texttt{\tfdigits}%
    }\par\medskip%
  }

  \newcommand\tfprinttextsample[1]{{%
    \csname #1family\endcsname\selectfont\noindent%
    Rank-dependent utility theories, introduced for objective probabilities
    by Quiggin (\begin{textnums}1981\end{textnums};
    \begin{textnums}1982\end{textnums}) and for subjective distributions by
    Schmeidler (\begin{textnums}1989\end{textnums}), reconfigure $p$ to
    accommodate findings that actual choice behaviours often differ
    systematically from that predicted by classical expected utility
    theories (for example, see Allais, \begin{textnums}1953\end{textnums};
    Ellsberg, \begin{textnums}1961\end{textnums}; Lichtenstein \& Slovic,
    \begin{textnums}1971\end{textnums}; H\"{u}fflefjord,
    \begin{textnums}2004\end{textnums}). These theories accomplish their
    task in two interrelated ways:\ first by discarding the ``linearity of
    the probabilities'' restriction imposed by the standard rationality
    assumptions, second by employing more of the information available to
    individuals at decision-making time.\par\medskip%
  }}

  \newcommand\tfprintmathalphabets[1]{{%
    \csname #1family\endcsname\selectfont\noindent%
    \edef\longestword{calligraphic:\ \ }%
    \ifundef{\mathbb}{}
      {\rlap{blackboard:}\phantom{\longestword}$\mathbb\tfABC$\\}%
    \ifundef{\mathcal}{}
      {\rlap{calligraphic:}\phantom{\longestword}$\mathcal\tfABC$\\}%
    \ifundef{\mathfrak}{}
      {\rlap{fraktur:}\phantom{\longestword}$\mathfrak\tfABC%
       \quad\mathfrak\tfabc$\\}%
    \rlap{greek:}\phantom{\longestword}$%
     \Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega%
     \quad%
     \alpha\beta\gamma%
     \ifundef{\digamma}{.}{\digamma}%
     \delta\epsilon%
     \ifundef{\varepsilon}{.}{\varepsilon}%
     \zeta\eta\theta%
     \ifundef{\vartheta}{.}{\vartheta}%
     \iota\kappa%
     \ifundef{\varkappa}{.}{\varkappa}%
     \lambda\mu\nu\xi\pi%
     \ifundef{\varpi}{.}{\varpi}%
     \rho%
     \ifundef{\varrho}{.}{\varrho}%
     \sigma%
     \ifundef{\varsigma}{.}{\varsigma}%
     \tau%
     \ifundef{\varphi}{.}{\varphi}%
     \upsilon\phi\chi\psi\omega%
     $\\%
     \ifthenelse{\NOT\isundefined{\alphaup}}{%
       \phantom{\longestword$%
       \Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega%
       \quad$}$%
       \ifundef{\alphaup}{.}{\alphaup}%
       \ifundef{\betaup}{.}{\betaup}%
       \ifundef{\gammaup}{.}{\gammaup}%
       \ifundef{\digammaup}{.}{\digammaup}%
       \ifundef{\deltaup}{.}{\deltaup}%
       \ifundef{\epsilonup}{.}{\epsilonup}%
       \ifundef{\varepsilonup}{.}{\varepsilonup}%
       \ifundef{\zetaup}{.}{\zetaup}%
       \ifundef{\etaup}{.}{\etaup}%
       \ifundef{\thetaup}{.}{\thetaup}%
       \ifundef{\varthetaup}{.}{\varthetaup}%
       \ifundef{\iotaup}{.}{\iotaup}%
       \ifundef{\kappaup}{.}{\kappaup}%
       \ifundef{\varkappaup}{.}{\varkappaup}%
       \ifundef{\lambdaup}{.}{\lambdaup}%
       \ifundef{\muup}{.}{\muup}%
       \ifundef{\nuup}{.}{\nuup}%
       \ifundef{\xiup}{.}{\xiup}%
       \ifundef{\piup}{.}{\piup}%
       \ifundef{\varpiup}{.}{\varpiup}%
       \ifundef{\rhoup}{.}{\rhoup}%
       \ifundef{\varrhoup}{.}{\varrhoup}%
       \ifundef{\sigmaup}{.}{\sigmaup}%
       \ifundef{\varsigmaup}{.}{\varsigmaup}%
       \ifundef{\tauup}{.}{\tauup}%
       \ifundef{\varphiup}{.}{\varphiup}%
       \ifundef{\upsilonup}{.}{\upsilonup}%
       \ifundef{\phiup}{.}{\phiup}%
       \ifundef{\chiup}{.}{\chiup}%
       \ifundef{\psiup}{.}{\psiup}%
       \ifundef{\omegaup}{.}{\omegaup}%
       $\\%
     }{}%
    \par\vspace{-0.5\baselineskip}%
  }}

  \newcommand\tfprintmathfonts{{%
    \noindent%
    \parbox{\linewidth}{\ttfamily\selectfont%
      \count255=0
      \textbf{Math fonts:}
      \loop\ifnum\count255<15
        \the\count255.~\fontname\textfont\count255;
        \advance\count255 by 1
     \repeat
     \the\count255.~\fontname\textfont\count255.
   }\par%
  }}

  \newcommand\tfprintmathsample[1]{{%
    \ifundef{\Res}{%
      \edef\Res{\mathop{\operator@font Res}\nolimits}%
    }{}%
    \csname #1family\endcsname\selectfont\noindent%
    \textbf{Theorem 1 (Residue Theorem)} % Credit: Hartke
    Let $f$ be analytic in the region $G$ except for the isolated
    singularities $a_1,a_2,\ldots,a_m$. If $\gamma$ is a closed rectifiable
    curve in $G$ which does not pass through any of the points $a_k$ and if
    $\gamma\approx 0$ in $G$ then
    \begin{equation}\ifbool{tf@debug}{\color{\TF@DEBUG@COLOUR@MATH}}{}%
    \frac{1}{2\pi i}\int_\gamma f = \sum_{k=1}^m n(\gamma;a_k)
    \Res(f;a_k)\qquad\pi=3.1415926\dots
    \end{equation}%
  }}
}{
  % Stub print info definitions for whenever package option printinfo=false
  %------------------------------------------------------------------------
  \newcommand\tfprintinfopage{}
  \newcommand\tfprintpackageoptions{}
  \newcommand\tfprintinfo{}
  \newcommand\tfprinttext[1]{}
  \newcommand\tfprintfigures[1]{}
  \newcommand\tfprinttextalphabets{}
  \newcommand\tfprinttextsample[1]{}
  \newcommand\tfprintmathalphabets[1]{}
  \newcommand\tfprintmathsample[1]{}
}

\renewcommand*\familydefault{\rmdefault} % override any package-induced change
\rmfamily

\TF@PackageDebugInfo{... package loaded}
%
%============================== end typeface.sty ==============================