summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/ctex/ctex.dtx
blob: e01c5519d5113dd0fe53f2251c2c03ff14c74a35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
% \iffalse meta-comment
% !TeX program  = XeLaTeX
% !TeX encoding = UTF-8
%
% Copyright (C) 2003--2022
% CTEX.ORG and any individual authors listed elsewhere in this file.
% --------------------------------------------------------------------------
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any later
% version. This version of this license is in
%    http://www.latex-project.org/lppl/lppl-1-3c.txt
% and 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".
%
% --------------------------------------------------------------------------
%
%<*internal>
\iffalse
%</internal>
%<*readme>
ctex
====

`ctex` is a collection of macro packages and document classes
for LaTeX Chinese typesetting.

Authors and Contributors
------------------------

* Wu Lingyun <aloft@ctex.org>
* Jiang Jiang <gzjjgod@gmail.com>
* Wang Yue <yuleopen@gmail.com>
* Liu Haiyang <leoliu.pku@gmail.com>
* Li Yanrui <liyanrui.m2@gmail.com>
* Chen Zhichu <zhichu.chen@gmail.com>
* Li Qing <sobenlee@gmail.com>
* Liam Huang <liamhuang0205@gmail.com>
* Zeng Xiangdong <xdzeng96@gmail.com>
* Li Zeping <zepinglee@gmail.com>
* Zhou Yukai <muzimuzhi@gmail.com>
* Zhang Ruixi <ruixizhang42@gmail.com>

Contributing
------------

This package is a part of the [ctex-kit](https://github.com/CTeX-org/ctex-kit) project.

Issues and pull requests are welcome.

Copyright and Licence
---------------------

    Copyright (C) 2003--2022
    CTEX.ORG and any individual authors listed elsewhere in this file.
    ----------------------------------------------------------------------

    This work may be distributed and/or modified under the
    conditions of the LaTeX Project Public License, either
    version 1.3c of this license or (at your option) any later
    version. This version of this license is in
       http://www.latex-project.org/lppl/lppl-1-3c.txt
    and 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".

    This package consists of the files ctex.dtx,
                                       ctxdoc.cls,
                                       ctxdocstrip.tex,
                                       ctex-zhconv.lua,
                                       ctex-zhconv-make.lua,
                 and the derived files ctex.pdf,
                                       ctex.ins,
                                       ctex.sty,
                                       ctexsize.sty,
                                       ctexheading.sty,
                                       ctexart.cls,
                                       ctexbook.cls,
                                       ctexrep.cls,
                                       ctexbeamer.cls,
                                       ctexcap.sty,
                                       ctexhook.sty,
                                       ctexpatch.sty,
                                       ctex-c5size.clo,
                                       ctex-cs4size.clo,
                                       ctex-heading-article.def,
                                       ctex-heading-book.def,
                                       ctex-heading-report.def,
                                       ctex-heading-beamer.def,
                                       ctex-scheme-plain.def,
                                       ctex-scheme-plain-article.def,
                                       ctex-scheme-plain-book.def,
                                       ctex-scheme-plain-report.def,
                                       ctex-scheme-plain-beamer.def,
                                       ctex-scheme-chinese.def,
                                       ctex-scheme-chinese-article.def,
                                       ctex-scheme-chinese-book.def,
                                       ctex-scheme-chinese-report.def,
                                       ctex-scheme-chinese-beamer.def,
                                       ctex-name-gbk.cfg,
                                       ctex-name-utf8.cfg,
                                       ctex.cfg,
                                       ctexopts.cfg,
                                       ctexbackend.cfg,
                                       ctex-engine-pdftex.def,
                                       ctex-engine-xetex.def,
                                       ctex-engine-luatex.def,
                                       ctex-engine-aptex.def,
                                       ctex-engine-uptex.def,
                                       c19rm.fd,
                                       c19sf.fd,
                                       c19tt.fd,
                                       c70rm.fd,
                                       c70sf.fd,
                                       c70tt.fd,
                                       jy2zhrm.fd,
                                       jy2zhsf.fd,
                                       jy2zhtt.fd,
                                       jt2zhrm.fd,
                                       jt2zhsf.fd,
                                       jt2zhtt.fd,
                                       ctex-fontset-adobe.def,
                                       ctex-fontset-fandol.def,
                                       ctex-fontset-founder.def,
                                       ctex-fontset-mac.def,
                                       ctex-fontset-macnew.def,
                                       ctex-fontset-macold.def,
                                       ctex-fontset-ubuntu.def,
                                       ctex-fontset-windows.def,
                                       ctexspa.def,
                                       ctexpunct.spa,
                                       ctex-spa-make.tex,
                                       ctex-spa-macro.tex,
                                       ctex-zhmap-adobe.tex,
                                       ctex-zhmap-fandol.tex,
                                       ctex-zhmap-founder.tex,
                                       ctex-zhmap-mac.tex,
                                       ctex-zhmap-ubuntu.tex,
                                       ctex-zhmap-windows.tex,
                                       ctex-zhconv-index.lua,
                                       translator-theorem-dictionary-ChineseGBK.dict,
                                       translator-theorem-dictionary-ChineseUTF8.dict, and
                                       README.md (this file).
%</readme>
%<*internal>
\fi
\begingroup
  \def\temp{LaTeX2e}
\expandafter\endgroup\ifx\temp\fmtname\else
\csname fi\endcsname
%</internal>
%<*install>

\input ctxdocstrip %

\preamble

    Copyright (C) 2003--2022
    CTEX.ORG and any individual authors listed in the documentation.
---------------------------------------------------------------------

    This work may be distributed and/or modified under the
    conditions of the LaTeX Project Public License, either
    version 1.3c of this license or (at your option) any later
    version. This version of this license is in
       http://www.latex-project.org/lppl/lppl-1-3c.txt
    and 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".

---------------------------------------------------------------------

\endpreamble
\postamble

    This package consists of the files ctex.dtx,
                                       ctxdoc.cls,
                                       ctxdocstrip.tex,
                                       ctex-zhconv.lua,
                                       ctex-zhconv-make.lua,
                 and the derived files ctex.pdf,
                                       ctex.ins,
                                       ctex.sty,
                                       ctexsize.sty,
                                       ctexheading.sty,
                                       ctexart.cls,
                                       ctexbook.cls,
                                       ctexrep.cls,
                                       ctexbeamer.cls,
                                       ctexcap.sty,
                                       ctexhook.sty,
                                       ctexpatch.sty,
                                       ctex-c5size.clo,
                                       ctex-cs4size.clo,
                                       ctex-heading-article.def,
                                       ctex-heading-book.def,
                                       ctex-heading-report.def,
                                       ctex-heading-beamer.def,
                                       ctex-scheme-plain.def,
                                       ctex-scheme-plain-article.def,
                                       ctex-scheme-plain-book.def,
                                       ctex-scheme-plain-report.def,
                                       ctex-scheme-plain-beamer.def,
                                       ctex-scheme-chinese.def,
                                       ctex-scheme-chinese-article.def,
                                       ctex-scheme-chinese-book.def,
                                       ctex-scheme-chinese-report.def,
                                       ctex-scheme-chinese-beamer.def,
                                       ctex-name-gbk.cfg,
                                       ctex-name-utf8.cfg,
                                       ctex.cfg,
                                       ctexopts.cfg,
                                       ctexbackend.cfg,
                                       ctex-engine-pdftex.def,
                                       ctex-engine-xetex.def,
                                       ctex-engine-luatex.def,
                                       ctex-engine-aptex.def,
                                       ctex-engine-uptex.def,
                                       c19rm.fd,
                                       c19sf.fd,
                                       c19tt.fd,
                                       c70rm.fd,
                                       c70sf.fd,
                                       c70tt.fd,
                                       jy2zhrm.fd,
                                       jy2zhsf.fd,
                                       jy2zhtt.fd,
                                       jt2zhrm.fd,
                                       jt2zhsf.fd,
                                       jt2zhtt.fd,
                                       ctex-fontset-adobe.def,
                                       ctex-fontset-fandol.def,
                                       ctex-fontset-founder.def,
                                       ctex-fontset-mac.def,
                                       ctex-fontset-macnew.def,
                                       ctex-fontset-macold.def,
                                       ctex-fontset-ubuntu.def,
                                       ctex-fontset-windows.def,
                                       ctexspa.def,
                                       ctexpunct.spa,
                                       ctex-spa-make.tex,
                                       ctex-spa-macro.tex,
                                       ctex-zhmap-adobe.tex,
                                       ctex-zhmap-fandol.tex,
                                       ctex-zhmap-founder.tex,
                                       ctex-zhmap-mac.tex,
                                       ctex-zhmap-ubuntu.tex,
                                       ctex-zhmap-windows.tex,
                                       ctex-zhconv-index.lua,
                                       translator-theorem-dictionary-ChineseGBK.dict,
                                       translator-theorem-dictionary-ChineseUTF8.dict, and
                                       README.md.
\endpostamble

\generate
  {
    \usedir{tex/latex/ctex}
    \file{ctex.sty}                        {\from{\jobname.dtx}{style,ctex}}
    \file{ctexsize.sty}                    {\from{\jobname.dtx}{style,ctexsize}}
    \file{ctexheading.sty}                 {\from{\jobname.dtx}{style,ctexheading}}
    \file{ctexart.cls}                     {\from{\jobname.dtx}{class,article}}
    \file{ctexbook.cls}                    {\from{\jobname.dtx}{class,book}}
    \file{ctexrep.cls}                     {\from{\jobname.dtx}{class,report}}
    \file{ctexbeamer.cls}                  {\from{\jobname.dtx}{class,beamer}}
    \usepostamble\emptypostamble
    \file{ctexcap.sty}                     {\from{\jobname.dtx}{ctexcap}}
    \file{ctexhook.sty}                    {\from{\jobname.dtx}{ctexhook}}
    \file{ctexpatch.sty}                   {\from{\jobname.dtx}{ctexpatch}}
    \file{ctex-c5size.clo}                 {\from{\jobname.dtx}{c5size}}
    \file{ctex-cs4size.clo}                {\from{\jobname.dtx}{cs4size}}
    \file{ctex-heading-article.def}        {\from{\jobname.dtx}{heading,article}}
    \file{ctex-heading-book.def}           {\from{\jobname.dtx}{heading,book}}
    \file{ctex-heading-report.def}         {\from{\jobname.dtx}{heading,report}}
    \file{ctex-heading-beamer.def}         {\from{\jobname.dtx}{heading,beamer}}
    \file{ctex-scheme-plain.def}           {\from{\jobname.dtx}{scheme,generic,plain}}
    \file{ctex-scheme-plain-article.def}   {\from{\jobname.dtx}{scheme,article,plain}}
    \file{ctex-scheme-plain-book.def}      {\from{\jobname.dtx}{scheme,book,plain}}
    \file{ctex-scheme-plain-report.def}    {\from{\jobname.dtx}{scheme,report,plain}}
    \file{ctex-scheme-plain-beamer.def}    {\from{\jobname.dtx}{scheme,beamer,plain}}
    \file{ctex-scheme-chinese.def}         {\from{\jobname.dtx}{scheme,generic,chinese}}
    \file{ctex-scheme-chinese-article.def} {\from{\jobname.dtx}{scheme,article,chinese}}
    \file{ctex-scheme-chinese-book.def}    {\from{\jobname.dtx}{scheme,book,chinese}}
    \file{ctex-scheme-chinese-report.def}  {\from{\jobname.dtx}{scheme,report,chinese}}
    \file{ctex-scheme-chinese-beamer.def}  {\from{\jobname.dtx}{scheme,beamer,chinese}}
 \ctxfile{GBK}{ctex-name-gbk.cfg}          {\from{\jobname.dtx}{name,GBK}}
    \file{ctex-name-utf8.cfg}              {\from{\jobname.dtx}{name,UTF8}}
    \file{ctex.cfg}                        {\from{\jobname.dtx}{config}}
    \file{ctexopts.cfg}                    {\from{\jobname.dtx}{ctexopts}}
    \file{ctexbackend.cfg}                 {\from{\jobname.dtx}{backend}}
    \file{ctex-engine-pdftex.def}          {\from{\jobname.dtx}{pdftex}}
    \file{ctex-engine-xetex.def}           {\from{\jobname.dtx}{xetex}}
    \file{ctex-engine-luatex.def}          {\from{\jobname.dtx}{luatex}}
    \file{ctex-engine-aptex.def}           {\from{\jobname.dtx}{aptex}}
    \file{ctex-engine-uptex.def}           {\from{\jobname.dtx}{uptex}}
    \file{c19rm.fd}                        {\from{\jobname.dtx}{fd,rm,c19}}
    \file{c19sf.fd}                        {\from{\jobname.dtx}{fd,sf,c19}}
    \file{c19tt.fd}                        {\from{\jobname.dtx}{fd,tt,c19}}
    \file{c70rm.fd}                        {\from{\jobname.dtx}{fd,rm,c70}}
    \file{c70sf.fd}                        {\from{\jobname.dtx}{fd,sf,c70}}
    \file{c70tt.fd}                        {\from{\jobname.dtx}{fd,tt,c70}}
    \file{jy2zhrm.fd}                      {\from{\jobname.dtx}{fd,rm,jy2}}
    \file{jy2zhsf.fd}                      {\from{\jobname.dtx}{fd,sf,jy2}}
    \file{jy2zhtt.fd}                      {\from{\jobname.dtx}{fd,tt,jy2}}
    \file{jt2zhrm.fd}                      {\from{\jobname.dtx}{fd,rm,jt2}}
    \file{jt2zhsf.fd}                      {\from{\jobname.dtx}{fd,sf,jt2}}
    \file{jt2zhtt.fd}                      {\from{\jobname.dtx}{fd,tt,jt2}}
    \file{ctex-fontset-adobe.def}          {\from{\jobname.dtx}{fontset,adobe}}
    \file{ctex-fontset-fandol.def}         {\from{\jobname.dtx}{fontset,fandol}}
    \file{ctex-fontset-founder.def}        {\from{\jobname.dtx}{fontset,founder}}
    \file{ctex-fontset-mac.def}            {\from{\jobname.dtx}{fontset,mac}}
    \file{ctex-fontset-macnew.def}         {\from{\jobname.dtx}{fontset,macnew}}
    \file{ctex-fontset-macold.def}         {\from{\jobname.dtx}{fontset,macold}}
    \file{ctex-fontset-ubuntu.def}         {\from{\jobname.dtx}{fontset,ubuntu}}
    \file{ctex-fontset-windows.def}        {\from{\jobname.dtx}{fontset,windows}}
 \ctxfile{GBK}{translator-theorem-dictionary-ChineseGBK.dict}
                                           {\from{\jobname.dtx}{dict,theorem,GBK}}
    \file{translator-theorem-dictionary-ChineseUTF8.dict}
                                           {\from{\jobname.dtx}{dict,theorem,UTF8}}
    \file{ctexspa.def}                     {\from{\jobname.dtx}{ctexspa}
                                            \from{ctexpunct.spa}{}}
    \usedir{tex/generic/ctex}
    \file{ctex-spa-make.tex}               {\from{\jobname.dtx}{spa,make}}
    \file{ctex-spa-macro.tex}              {\from{\jobname.dtx}{spa,macro}}
    \file{ctex-zhmap-adobe.tex}            {\from{\jobname.dtx}{zhmap,adobe}}
    \file{ctex-zhmap-fandol.tex}           {\from{\jobname.dtx}{zhmap,fandol}}
    \file{ctex-zhmap-founder.tex}          {\from{\jobname.dtx}{zhmap,founder}}
    \file{ctex-zhmap-mac.tex}              {\from{\jobname.dtx}{zhmap,mac}}
    \file{ctex-zhmap-ubuntu.tex}           {\from{\jobname.dtx}{zhmap,ubuntu}}
    \file{ctex-zhmap-windows.tex}          {\from{\jobname.dtx}{zhmap,windows}}
%</install>
%<*internal>
    \usedir{source/latex/ctex}
    \file{\jobname.ins}                    {\from{\jobname.dtx}{install}}
%</internal>
%<*install>
    \nopreamble\nopostamble
    \usedir{doc/latex/ctex}
    \file{README.md}                       {\from{\jobname.dtx}{readme}}
  }

\catcode32=12\space

\Msg{*************************************************************}
\Msg{*                                                           *}
\Msg{* To finish the installation you have to move the following *}
\Msg{* file into proper directories searched by TeX:             *}
\Msg{*                                                           *}
\Msg{* The recommended directory is TDS:tex/latex/ctex           *}
\Msg{*                                                           *}
\Msg{*     ctex.sty                                              *}
\Msg{*     ctexsize.sty                                          *}
\Msg{*     ctexheading.sty                                       *}
\Msg{*     ctexart.cls                                           *}
\Msg{*     ctexbook.cls                                          *}
\Msg{*     ctexrep.cls                                           *}
\Msg{*     ctexbeamer.cls                                        *}
\Msg{*     ctexcap.sty                                           *}
\Msg{*     ctexhook.sty                                          *}
\Msg{*     ctexpatch.sty                                         *}
\Msg{*     ctex-c5size.clo                                       *}
\Msg{*     ctex-cs4size.clo                                      *}
\Msg{*     ctex-heading-article.def                              *}
\Msg{*     ctex-heading-book.def                                 *}
\Msg{*     ctex-heading-report.def                               *}
\Msg{*     ctex-heading-beamer.def                               *}
\Msg{*     ctex-scheme-plain.def                                 *}
\Msg{*     ctex-scheme-plain-article.def                         *}
\Msg{*     ctex-scheme-plain-book.def                            *}
\Msg{*     ctex-scheme-plain-report.def                          *}
\Msg{*     ctex-scheme-plain-beamer.def                          *}
\Msg{*     ctex-scheme-chinese.def                               *}
\Msg{*     ctex-scheme-chinese-article.def                       *}
\Msg{*     ctex-scheme-chinese-book.def                          *}
\Msg{*     ctex-scheme-chinese-report.def                        *}
\Msg{*     ctex-scheme-chinese-beamer.def                        *}
\Msg{*     ctex-name-gbk.cfg                                     *}
\Msg{*     ctex-name-utf8.cfg                                    *}
\Msg{*     ctex.cfg                                              *}
\Msg{*     ctexopts.cfg                                          *}
\Msg{*     ctexbackend.cfg                                       *}
\Msg{*     ctex-engine-pdftex.def                                *}
\Msg{*     ctex-engine-xetex.def                                 *}
\Msg{*     ctex-engine-luatex.def                                *}
\Msg{*     ctex-engine-aptex.def                                 *}
\Msg{*     ctex-engine-uptex.def                                 *}
\Msg{*     c19rm.fd                                              *}
\Msg{*     c19sf.fd                                              *}
\Msg{*     c19tt.fd                                              *}
\Msg{*     c70rm.fd                                              *}
\Msg{*     c70sf.fd                                              *}
\Msg{*     c70tt.fd                                              *}
\Msg{*     jy2zhrm.fd                                            *}
\Msg{*     jy2zhsf.fd                                            *}
\Msg{*     jy2zhtt.fd                                            *}
\Msg{*     jt2zhrm.fd                                            *}
\Msg{*     jt2zhsf.fd                                            *}
\Msg{*     jt2zhtt.fd                                            *}
\Msg{*     ctex-fontset-adobe.def                                *}
\Msg{*     ctex-fontset-fandol.def                               *}
\Msg{*     ctex-fontset-founder.def                              *}
\Msg{*     ctex-fontset-mac.def                                  *}
\Msg{*     ctex-fontset-macnew.def                               *}
\Msg{*     ctex-fontset-macold.def                               *}
\Msg{*     ctex-fontset-ubuntu.def                               *}
\Msg{*     ctex-fontset-windows.def                              *}
\Msg{*     ctexspa.def                                           *}
\Msg{*     ctex-spa-make.tex                                     *}
\Msg{*     ctex-spa-macro.tex                                    *}
\Msg{*     ctex-zhmap-adobe.tex                                  *}
\Msg{*     ctex-zhmap-fandol.tex                                 *}
\Msg{*     ctex-zhmap-founder.tex                                *}
\Msg{*     ctex-zhmap-mac.tex                                    *}
\Msg{*     ctex-zhmap-ubuntu.tex                                 *}
\Msg{*     ctex-zhmap-windows.tex                                *}
\Msg{*     translator-theorem-dictionary-ChineseGBK.dict         *}
\Msg{*     translator-theorem-dictionary-ChineseUTF8.dict        *}
\Msg{*                                                           *}
\Msg{* To produce the documentation run the file ctex.dtx        *}
\Msg{* through XeLaTeX.                                          *}
\Msg{*                                                           *}
\Msg{* Happy TeXing!                                             *}
\Msg{*                                                           *}
\Msg{*************************************************************}

\endbatchfile
%</install>
%<*internal>
\fi
%</internal>
%<*!(driver|readme|install|zhmap|spa|docstrip)>
%<*!(fd|ctexspa|dict|backend)>
%<class|style|ctexcap|ctexhook|ctexpatch>\NeedsTeXFormat{LaTeX2e}
%<class>\input{ctexbackend.cfg}
%<class|style|ctexcap|ctexhook|ctexpatch>\RequirePackage{expl3}
%<+!driver>\GetIdInfo$Id: ctex.dtx c6b2e9c 2022-06-04 19:41:06 +0800 Qing Lee <sobenlee@gmail.com> $
%<ctex>  {Chinese adapter in LaTeX (CTEX)}
%<ctex>\ProvidesExplPackage{\ExplFileName}
%<ctexsize>  {Chinese font size definition (CTEX)}
%<ctexsize>\ProvidesExplPackage{ctexsize}
%<ctexheading>  {Heading style modification (CTEX)}
%<ctexheading>\ProvidesExplPackage{ctexheading}
%<class&article>  {Chinese adapter for class article (CTEX)}
%<class&article>\ProvidesExplClass{ctexart}
%<class&book>  {Chinese adapter for class book (CTEX)}
%<class&book>\ProvidesExplClass{ctexbook}
%<class&report>  {Chinese adapter for class report (CTEX)}
%<class&report>\ProvidesExplClass{ctexrep}
%<class&beamer>  {Chinese adapter for class beamer (CTEX)}
%<class&beamer>\ProvidesExplClass{ctexbeamer}
%<ctexcap>  {Chinese adapter in LaTeX (CTEX)}
%<ctexcap>\ProvidesExplPackage{ctexcap}
%<ctexhook>  {Document and package hooks (CTEX)}
%<ctexhook>\ProvidesExplPackage{ctexhook}
%<ctexpatch>  {Patching commands (CTEX)}
%<ctexpatch>\ProvidesExplPackage{ctexpatch}
%<c5size>  {c5size option (CTEX)}
%<c5size>\ProvidesExplFile{ctex-c5size.clo}
%<cs4size>  {cs4size option (CTEX)}
%<cs4size>\ProvidesExplFile{ctex-cs4size.clo}
%<heading&article>  {Heading modification for article (CTEX)}
%<heading&article>\ProvidesExplFile{ctex-article.def}
%<heading&book>  {Heading modification for book (CTEX)}
%<heading&book>\ProvidesExplFile{ctex-book.def}
%<heading&report>  {Heading modification for report (CTEX)}
%<heading&report>\ProvidesExplFile{ctex-report.def}
%<heading&beamer>  {Heading modification for beamer (CTEX)}
%<heading&beamer>\ProvidesExplFile{ctex-beamer.def}
%<scheme&plain&generic>  {Plain scheme for generic (CTEX)}
%<scheme&plain&generic>\ProvidesExplFile{ctex-scheme-plain.def}
%<scheme&plain&article>  {Plain scheme for article (CTEX)}
%<scheme&plain&article>\ProvidesExplFile{ctex-scheme-plain-article.def}
%<scheme&plain&book>  {Plain scheme for book (CTEX)}
%<scheme&plain&book>\ProvidesExplFile{ctex-scheme-plain-book.def}
%<scheme&plain&report>  {Plain scheme for report (CTEX)}
%<scheme&plain&report>\ProvidesExplFile{ctex-scheme-plain-report.def}
%<scheme&plain&beamer>  {Plain scheme for beamer (CTEX)}
%<scheme&plain&beamer>\ProvidesExplFile{ctex-scheme-plain-beamer.def}
%<scheme&chinese&generic>  {Chinese scheme for generic (CTEX)}
%<scheme&chinese&generic>\ProvidesExplFile{ctex-scheme-chinese.def}
%<scheme&chinese&article>  {Chinese scheme for article (CTEX)}
%<scheme&chinese&article>\ProvidesExplFile{ctex-scheme-chinese-article.def}
%<scheme&chinese&book>  {Chinese scheme for book (CTEX)}
%<scheme&chinese&book>\ProvidesExplFile{ctex-scheme-chinese-book.def}
%<scheme&chinese&report>  {Chinese scheme for report (CTEX)}
%<scheme&chinese&report>\ProvidesExplFile{ctex-scheme-chinese-report.def}
%<scheme&chinese&beamer>  {Chinese scheme for beamer (CTEX)}
%<scheme&chinese&beamer>\ProvidesExplFile{ctex-scheme-chinese-beamer.def}
%<name&GBK>  {Caption with encoding GBK (CTEX)}
%<name&GBK>\ProvidesExplFile{ctex-name-gbk.cfg}
%<name&UTF8>  {Caption with encoding UTF-8 (CTEX)}
%<name&UTF8>\ProvidesExplFile{ctex-name-utf8.cfg}
%<config>  {Configuration file (CTEX)}
%<config>\ProvidesExplFile{\ExplFileName.cfg}
%<ctexopts>  {Option configuration file (CTEX)}
%<ctexopts>\ProvidesExplFile{ctexopts.cfg}
%<pdftex>  {(pdf)LaTeX adapter (CTEX)}
%<pdftex>\ProvidesExplFile{ctex-engine-pdftex.def}
%<xetex>  {XeLaTeX adapter (CTEX)}
%<xetex>\ProvidesExplFile{ctex-engine-xetex.def}
%<luatex>  {LuaLaTeX adapter (CTEX)}
%<luatex>\ProvidesExplFile{ctex-engine-luatex.def}
%<aptex>  {Asian pTeX adapter (CTEX)}
%<aptex>\ProvidesExplFile{ctex-engine-aptex.def}
%<uptex>  {upTeX adapter (CTEX)}
%<uptex>\ProvidesExplFile{ctex-engine-uptex.def}
%<windows>  {Windows fonts definition (CTEX)}
%<windows>\ProvidesExplFile{ctex-fontset-windows.def}
%<adobe>  {Adobe fonts definition (CTEX)}
%<adobe>\ProvidesExplFile{ctex-fontset-adobe.def}
%<fandol>  {Fandol fonts definition (CTEX)}
%<fandol>\ProvidesExplFile{ctex-fontset-fandol.def}
%<mac>  {macOS fonts definition (CTEX)}
%<mac>\ProvidesExplFile{ctex-fontset-mac.def}
%<macnew>  {macOS fonts definition for El Capitan or later version (CTEX)}
%<macnew>\ProvidesExplFile{ctex-fontset-macnew.def}
%<macold>  {macOS fonts definition for Yosemite or earlier version (CTEX)}
%<macold>\ProvidesExplFile{ctex-fontset-macold.def}
%<founder>  {Founder fonts definition (CTEX)}
%<founder>\ProvidesExplFile{ctex-fontset-founder.def}
%<ubuntu>  {Ubuntu fonts definition (CTEX)}
%<ubuntu>\ProvidesExplFile{ctex-fontset-ubuntu.def}
%<!driver>  {\ExplFileDate}{2.5.9}{\ExplFileDescription}
%</!(fd|ctexspa|dict|backend)>
%<c19&rm>\ProvidesFile{c19rm.fd}%
%<c19&sf>\ProvidesFile{c19sf.fd}%
%<c19&tt>\ProvidesFile{c19tt.fd}%
%<c70&rm>\ProvidesFile{c70rm.fd}%
%<c70&sf>\ProvidesFile{c70sf.fd}%
%<c70&tt>\ProvidesFile{c70tt.fd}%
%<jy2&rm>\ProvidesFile{jy2zhrm.fd}%
%<jy2&sf>\ProvidesFile{jy2zhsf.fd}%
%<jy2&tt>\ProvidesFile{jy2zhtt.fd}%
%<jt2&rm>\ProvidesFile{jt2zhrm.fd}%
%<jt2&sf>\ProvidesFile{jt2zhsf.fd}%
%<jt2&tt>\ProvidesFile{jt2zhtt.fd}%
%<ctexspa>\ProvidesFile{ctexspa.def}%
%<backend>\ProvidesFile{ctexbackend.cfg}%
%<dict&theorem&GBK>\ProvidesDictionary{translator-theorem-dictionary}{ChineseGBK}%
%<dict&theorem&UTF8>\ProvidesDictionary{translator-theorem-dictionary}{ChineseUTF8}%
%<fd>  [2022/06/04 v2.5.9 Chinese font definition (CTEX)]
%<ctexspa>  [2022/06/04 v2.5.9 Space info for CJKpunct (CTEX)]
%<backend>  [2022/06/04 v2.5.9 Backend configuration file (CTEX)]
%<dict&theorem>  [2022/06/04 v2.5.9 Chinese translation for theorem name (CTEX)]
%</!(driver|readme|install|zhmap|spa|docstrip)>
%<*driver>
\documentclass{ctxdoc}
\begin{document}
  \DocInput{\jobname.dtx}
  \IndexLayout
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
%
% \fi
%
% \changes{v2.0}{2014/03/06}{应用 \LaTeXiii{} 重新整理代码。}
% \changes{v2.0}{2014/03/12}{删除 \file{c19gbsn.fd} 和 \file{c19gkai.fd}。}
% \changes{v2.1}{2015/05/18}{将章节标题设置功能提取到可以独立使用的宏包
%   \pkg{ctexheading} 中。}
% \changes{v2.2}{2015/06/24}{不再依赖 \pkg{etoolbox} 宏包。}
% \changes{v2.4}{2015/02/19}{加强 \pkg{beamer} 宏包支持。}
% \changes{v2.4.12}{2018/01/13}{同步 \LaTeXiii{} 2017/12/16。}
% \changes{v2.4.15}{2019/03/23}{同步 \LaTeXiii{} 2019/03/05。}
% \changes{v2.5.1}{2020/05/02}{\pkg{zhconv} 更名为 \pkg{ctex-zhconv}。}
%
% \CheckSum{6444}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \GetFileId{ctex.sty}
%
% \title{\bfseries \CTeX{} 宏集手册}
% \author{\href{http://www.ctex.org}{CTEX.ORG}}
% \date{\filedate\qquad\fileversion\thanks{\ctexkitrev{\ExplFileVersion}.}}
% \maketitle
%
% \begin{abstract}
% \CTeX{} 宏集是面向中文排版的通用 \LaTeX{} 排版框架,为中文 \LaTeX{} 文档
% 提供了汉字输出支持、标点压缩、字体字号命令、标题文字汉化、中文版式调整、数字
% 日期转换等支持功能,可适应论文、报告、书籍、幻灯片等不同类型的中文文档。
%
% \CTeX{} 宏集支持 \LaTeX、\pdfLaTeX、\XeLaTeX、\LuaLaTeX、\upLaTeX{} 等多种不同
% 的编译方式,并为它们提供了统一的界面。主要功能由宏包 \pkg{ctex} 以及中文文档类
% \cls{ctexart}、\cls{ctexrep}、\cls{ctexbook} 和 \cls{ctexbeamer} 实现。
% \end{abstract}
%
% \tableofcontents
%
% \bigskip
% \setlength{\parskip}{0.8ex}
%
% \begin{documentation}
%
% \section{介绍}
%
% \subsection*{历史}
%
% \CTeX{} 宏集的源头有两个:一是王磊编写的 \cls{cjkbook} 文档类,二是吴凌云编写的
% \file{GB.cap}。
% 这些工作没有经过认真系统的设计,也没有用户文档,不利于维护和改进。
%
% 2003 年,吴凌云使用 \pkg{doc} 和 \pkg{DocStrip} 重构了整个工程,并增加了许多新的功能,
% 称为 \pkg{ctex} 宏包。2007 年,oseen 和王越在 \pkg{ctex} 宏包的基础上,
% 增加了对 UTF-8 编码的支持,开发出了 \pkg{ctexutf8} 宏包。
%
% 2009 年 5 月,我们在 Google Code 建立了 ctex-kit 项目^^A
% \footnote{\nolinkurl{http://code.google.com/p/ctex-kit/},该链接现已失效。},
% 对 \pkg{ctex} 宏包及相关脚本进行了整合,并加入了对 \XeTeX{} 引擎的支持。
% 在开发新版本时,考虑到合作开发和调试的方便,我们放弃了 \pkg{doc} 和 \pkg{DocStrip},
% 采取了直接编写宏包代码的方式。
%
% 2014 年 3 月,为了适应 \LaTeX{} 的最新发展,特别是 \LaTeXiii{} 的逐渐成熟,李清用
% \LaTeXiii{} 重构了整个宏包的代码,并重新使用 \pkg{doc} 和 \pkg{DocStrip} 工具进行代码
% 的管理,升级版本号为 2.0,并改称 \CTeX{} 宏集。
%
% 2015 年 3 月,由于 Google Code 即将停止服务,ctex-kit 项目迁移至
% \href{https://github.com/CTeX-org/ctex-kit}{GitHub}^^A
% \footnote{\url{https://github.com/CTeX-org/ctex-kit}}。
%
% 最初,Knuth 在设计开发 \TeX{} 的时候没有考虑到多国文字支持,特别是对多字节的中日韩
% 表意文字的支持。这使得 \TeX{} 以至后来的 \LaTeX{} 对中文的支持一直不是很好。即使在
% \pkg{CJK} 宏包解决了中文字符处理的问题以后,中文用户使用 \LaTeX{} 仍然要面对许
% 多困难。
% 这些困难里,以章节标题的中文化为最。由于中文和西文书写习惯的差异,用户很难使用标准
% 文档类中的代码结构来表达中文标题。于是,用户不得不对标准文档类做较大的修改。
% 除此之外,日期格式、首行缩进、中文字号和字距等细节问题,也需要精细的调校。
% 我们设计 \CTeX{} 宏集的目的之一就是解决这些 \LaTeX{} 文档的汉化难题。
%
% 另一方面,随着 \TeX{} 引擎和 \LaTeX{} 宏包的不断发展,\LaTeX{} 的中文支持方式从早期的
% 专用系统(如 \pkg{CCT})发展为适用于不同引擎的多种方式^^A
% \footnote{比如:\pdfTeX{} 引擎下的 \pkg{CJK}、\pkg{zhmCJK}宏包,
% \XeTeX{} 引擎下的 \pkg{xeCJK} 宏包和 \LuaTeX{} 引擎下的 \pkg{LuaTeX-ja} 宏包。}。
% 这些方式的适用情况和使用方式有不少细节上的差异,同时操作系统的不同、语言环境的不同等
% 客观情况又进一步带来了更多的细节差异。我们设计 \CTeX{} 宏集的另一个主要目的就是
% 尽可能消除这些差异带来的影响,使用户能够以一个统一的接口来使用不同的中文支持方式,
% 使得同一份文档能够在不同环境下交换使用。
%
% \CTeX{} 宏集的许多实现细节离不开热心朋友们在 \nolinkurl{bbs.ctex.org} 论坛^^A
% \footnote{2018 年,\CTeX{} 论坛因故无限期关闭,此链接现已失效。}^^A
% 上的讨论,在此对参与讨论的朋友们表示感谢。
%
% \subsection*{关于宏集名字的说明}
%
% \CTeX{} 之名是英文单词 China(中国)或 Chinese(中文)的首字母“C”与 “\TeX{}”
% 结合而成的。在纯文本环境下,该名字应写作“CTeX”。
%
% \CTeX{} 宏集是由 \href{https://github.com/CTeX-org}{\CTeX{} 社区}发起并维护的
% \LaTeX{} \emph{宏包和文档类的集合}。
% 社区另有发布名为 \href{http://www.ctex.org/CTeX}{\CTeX{} 套装}^^A
% 的 \TeX{} 发行版,与本文档所述的 \CTeX{} 宏集并非是同一事物。
%
% \pkg{ctex} 则是本宏集中的 \pkg{ctex.sty} 的名字。这一完全小写的名称,在过去
% 也被用来指代整个 \CTeX{} 宏集,不过现在则特指 \pkg{ctex.sty} 这一宏包。
% 在不引起歧义的情况下,它也可以沿用过去的习惯,代指整个宏集。
%
% \section{简明教程}
%
% \subsection{\CTeX{} 宏集的组成}
%
% 为了适应用户不同的需求,我们将 \CTeX{} 宏集的主要功能设计安排在四个中文文档类和
% 三个宏包当中,具体的组成见表~\ref{tab:ctex}。
%
% \begin{table}[htbp]
% \centering
% \caption{\CTeX{} 宏集的组成}\label{tab:ctex}
% \begin{tabularx}{\linewidth}{llX}
% \toprule
%   类别   & 文件 & 说明 \\
% \midrule
%   文档类 & \file{ctexart.cls}    & 标准文档类 \cls{article} 的汉化版本,
%                                    一般适用于短篇幅的文章 \\
%          & \file{ctexrep.cls}    & 标准文档类 \cls{report} 的汉化版本,
%                                    一般适用于中篇幅的报告 \\
%          & \file{ctexbook.cls}   & 标准文档类 \cls{book} 的汉化版本,
%                                    一般适用于长篇幅的书籍 \\
%          & \file{ctexbeamer.cls} & 文档类 \cls{beamer} 的汉化版本,
%                                    适用于幻灯片演示 \\
% \midrule
%   宏包   & \file{ctex.sty}        & 提供全部功能,但\emph{默认不开启章节标题设置功能},
%                                     需要使用 \opt{heading} 选项来开启 \\
%          & \file{ctexsize.sty}    & 定义和调整中文字号,可以在 \pkg{ctex} 宏包
%                                     或 \CTeX{} 中文文档类之外单独调用 \\
%          & \file{ctexheading.sty} & 提供章节标题设置功能(见 \ref{sec:secstyle}
%                                     节),可以在 \pkg{ctex} 宏包或 \CTeX{} 中文
%                                     文档类之外单独调用 \\
% \bottomrule
% \end{tabularx}
% \end{table}
%
% \subsection{\CTeX{} 宏集的安装和更新}
% \label{subsec:easy-ins}
% 最常见的 \TeX{} 发行版(\TeXLive{} 和 \MiKTeX{})已收录 \CTeX{} 宏集及其依赖的宏包和宏集。
% \footnote{\pkg{zhmCJK} 宏包是个例外。当用户显式指定选项 \opt{zhmap = zhmCJK} 时,^^A
% \CTeX{} 宏集依赖它。由于,它没有被 \TeXLive{} 和 \MiKTeX{} 收录,用户可能需要遵照其说明文档
% 自行安装。}如果本地安装 \TeXLive{} 或 \MiKTeX{} 不是完整版本,则可能需要通过这
% 两个发行版提供的\emph{包管理器}来安装宏包。
%
% \TeXLive{} 的包管理器是 tlmgr(\TeXLive{} Manager)。用户可以在系统命令行中^^A
% \footnote{Windows 系统的命令行是 CMD 命令提示符,你可以使用 Win + R 组合键
% 打开“运行”对话框,然后输入 cmd 确认打开命令提示符窗口。}执行
% \begin{frameverb}
%   tlmgr gui
% \end{frameverb}
% 启动管理器的图形界面(Windows 用户也可以通过开始菜单的 TeX Live 20XX(年份)
% \ding{212} TeX Live Manager 打开)。连接上远程仓库之后,搜索 |ctex| 即可安装。
% tlmgr 的图形界面使用 Perl 编写,在实践中发现容易造成系统假死。遇到这种问题的用户,
% 也可以直接在系统命令行执行
% \begin{frameverb}
%   tlmgr install ctex
% \end{frameverb}
% 来安装 \CTeX{} 宏集^^A
% \footnote{*nix 用户可能需要超级用户权限(sudo)才能正确安装宏集。}。
%
% \MiKTeX{} 通常会在缺失宏包时自动完成安装。如需手动安装,可以使用其管理维护
% 工具 \MiKTeX{} Console。用户可以打开管理器,连接上远程仓库之后,在“Package”
% 选项卡中搜索“ctex”并安装即可。
% 也可以使用 mpm(\MiKTeX{} Package Manager),在命令行执行
% \begin{frameverb}
%   mpm --admin --install=ctex
% \end{frameverb}
% 来安装 \CTeX{} 宏集。
%
% 若希望了解 \CTeX{} 宏集具体的依赖情况或手工安装宏集的方法,
% 请参阅第 \ref{sec:dep-ins}~节。
%
% 当我们将宏集的新版本发布于 CTAN,且为发行版的远程仓库更新后,用户就可以在本地
% 通过包管理器获取新版本。
%
% 对于 \TeXLive{},可以在 tlmgr 的图形界面点击“更新全部已安装的”按钮或者在
% 命令行执行
% \begin{frameverb}
%   tlmgr update --all
% \end{frameverb}
% 来完整更新已安装的宏包。
%
% 对于 \MiKTeX{},在 \MiKTeX{} Console 中找到“Updates”选项卡,检查更新后即可
% 选择升级宏包。也可以使用 mpm,在命令行执行
% \begin{frameverb}
%   mpm --admin --update
% \end{frameverb}
% 来进行更新。
%
% \subsection{使用 \CTeX{} 文档类}
%
% \emph{如果用户需要在三个标准文档类或 \cls{beamer} 的基础上添加中文及版式的支持,
% 我们建议用户使用 \CTeX{} 宏集提供的四个中文文档类。}
%
% \CTeX{} 宏集提供了四个中文文档类:\cls{ctexart}、\cls{ctexrep}、\cls{ctexbook} 和
% \cls{ctexbeamer},分别对应 \LaTeX{} 的标准文档类 \cls{article}、\cls{report}、
% \cls{book} 和 \cls{beamer}。使用它们的时候,需要将涉及到的所有源文件使用 UTF-8
% 编码保存\footnote{使用 (pdf)\LaTeX{} 时也能够使用 GBK 编码,但不推荐。(见
% \ref{subs:encoding}~节)}。
%
% \begin{ctexexam}
%   \documentclass{ctexart}
%   \begin{document}
%   中文文档类测试。你需要将所有源文件保存为 UTF-8 编码。
%
%   你可以使用 XeLaTeX、LuaLaTeX 或 upLaTeX 编译,也可以使用 (pdf)LaTeX 编译。
%   推荐使用 XeLaTeX 或 LuaLaTeX 编译。对高级用户,我们也推荐使用 upLaTeX 编译。
%   \end{document}
% \end{ctexexam}
%
% 以下是使用 \cls{ctexbeamer} 文档类编写中文演示文稿的一个示例。
% \begin{ctexexam}
%   \documentclass{ctexbeamer}
%   \begin{document}
%   \begin{frame}{中文演示文档}
%   \begin{itemize}
%     \item 你需要将所有源文件保存为 UTF-8 编码
%     \item 你可以使用 XeLaTeX、LuaLaTeX 或 upLaTeX 编译
%     \item 也可以使用 (pdf)LaTeX 编译
%     \item 推荐使用 XeLaTeX 或 LuaLaTeX 编译
%     \item 对高级用户,我们也推荐使用 upLaTeX 编译
%   \end{itemize}
%   \end{frame}
%   \end{document}
% \end{ctexexam}
%
% \subsection{使用 \pkg{ctex} 宏包}
%
% \emph{用户在使用非标准文档类及 \cls{beamer} 时,如果需要添加中文及版式的支持,
% 则可以使用 \pkg{ctex} 宏包。}
%
% 对于建立在 \LaTeX{} 标准文档类之上开发的文档类,在使用 \pkg{ctex} 宏包时
% 加上 \opt{heading} 选项,可以将章节标题设置为中文风格。
% \begin{ctexexam}
%   \documentclass{ltxdoc}
%   \usepackage[heading = true]{ctex}
%   \begin{document}
%   \section{简介}
%   章节标题中文化的 \LaTeX{} 手册。
%   \end{document}
% \end{ctexexam}
%
% \section{宏包选项与 \tn{ctexset} 命令}
% \label{sec:options}
%
% \CTeX{} 宏集已经尽可能就中文的行文和版式习惯做了调整和配置,通常而言,这些配置
% 已经够用。因此,除非必要,我们不建议普通用户修改这些默认配置。如果你认为 \CTeX{} 宏集
% 的默认配置还可以完善,可以在项目主页上^^A
% \href{https://github.com/CTeX-org/ctex-kit/issues}{提交 issue},
% 向我们反映,我们会酌情在后续版本中予以改进。
%
% 不过,\CTeX{} 宏集也提供了一系列选项。用户可以使用这些选项来控制 \CTeX{} 宏集的行为。
% 按形式分类,这些选项有的以传统的方式提供,有的以 \meta{key}|=|\meta{value} 的形式提供。
% 按指定位置分类,这些选项又可以分为以下三类:
% \begin{itemize}
% \item 名字后带有 \rexptarget\rexpstar{} 号的选项,只能作为宏包/文档类选项,需要
%   在引入宏包/文档类的时候指定;
% \item 名字后带有 \exptarget\expstar{} 号的选项,只能通过 \CTeX{} 宏集提供的
%   用户接口 \tn{ctexset} 来设定;
% \item 名字后不带有特殊符号的选项,既可以作为宏包/文档类选项,也可以通过
%   \tn{ctexset} 来设定。
% \end{itemize}
% 后续文档将在使用说明中对某些特殊的选项加以说明。
%
% \begin{function}[added=2014-03-18]{\ctexset}
%   \begin{syntax}
%     \tn{ctexset} \Arg{键值列表}
%   \end{syntax}
% 是 \CTeX{} 宏集的通用控制命令,用来在宏包载入后控制宏包的各项功能。
% \tn{ctexset} 的参数是一个键值列表,以通用的接口完成各项设置。
% \end{function}
%
% \tn{ctexset} 的参数是一组由逗号分隔的选项列表,列表中的选项通常是一个
% \meta{key}|=|\meta{value} 格式的定义。例如设置摘要与参考文献标题名称
% (\ref{subs:capname}~节)就可以使用:
% \begin{ctexexam}[labelref=exam:capname]
%   \ctexset{
%     abstractname = {本文概要},
%     bibname      = {文\quad 献}
%   }
% \end{ctexexam}
%
% \tn{ctexset} 采用 \LaTeXiii{} 风格的键值设置,支持不同类型的选项与层次化的选
% 项设置,相关示例见 \ref{sec:secstyle}~节。
%
% \section{编译方式、编码与中文字库}
% \label{sec:chinese}
%
% \subsection{编译方式}
% \label{subs:compile}
%
% \CTeX{} 宏集会根据用户使用的编译方式\footnote{\LaTeX、\pdfLaTeX、\XeLaTeX、
% \LuaLaTeX{} 及 \upLaTeX。},在底层选择不同的中文支持方式(见
% 表~\ref{tab:chinese-support})。
%
% \begin{table}[htbp]
% \centering
% \begin{threeparttable}
% \caption{\CTeX{} 宏集的中文支持方式}
% \label{tab:chinese-support}
% \begin{tabular}{*6c}
%   \toprule
%   编译方式 & (pdf)\LaTeX & \XeLaTeX & \LuaLaTeX & \upLaTeX\tnote{*} \\
%   \midrule
%   支持宏包 & \pkg{CJK} & \pkg{xeCJK} & \pkg{LuaTeX-ja} & 原生 \\
%   \bottomrule
% \end{tabular}
% \begin{tablenotes}
% \item[*] p\LaTeX-ng(或称 \ApLaTeX)与 \upLaTeX{} 兼容。使用 p\LaTeX-ng 编译
% 时,\pkg{ctex} 采用与 \upLaTeX{} 相同的设置。
% \end{tablenotes}
% \end{threeparttable}
% \end{table}
%
% 不同的编译方式和中文支持方式会在一定程度上影响 \CTeX{} 宏集的行为,比如宏包对
% 文档编码、字体选择、空格、标点等的处理。具体细节将在本文档后续内容中进行阐述。
%
% \subsection{中文编码}
% \label{subs:encoding}
%
% \begin{function}[rEXP,updated=2019-11-10]{GBK, UTF8}
%   指明编写文档时使用的编码。\CTeX{} 宏集无法检测文档源文件的实际编码格式,因此需要
%   用户通过选项声明。如果没有显式指定,则默认采用 UTF-8 编码。
%
%   使用 \XeLaTeX{}、\LuaLaTeX{} 或 \upLaTeX{} 编译时,\CTeX{} 宏集强制使用
%   UTF-8 编码,此时 \opt{GBK} 选项无效;使用 (pdf)\LaTeX{} 编译时,
%   \CTeX{} 宏集默认使用 UTF-8 编码,但用户也可以显式声明 \opt{GBK} 选项,
%   使 \CTeX{} 宏集按 GBK 编码处理文档。
%
%   用户需要\emph{保证编译方式、源文件编码、宏包编码选项三者一致}。
%
%   \emph{我们建议编写新文档时始终使用 UTF-8 编码,而仅把 GBK 编码留给
%   历史遗留文档。}
% \end{function}
%
% \subsection{中文字库}
% \label{subs:options-CJK-font}
%
% 以往,为 \LaTeX{} 文档配置中文支持是一件相当繁琐的事情。默认情况下,
% \CTeX{} 宏集能自动检测用户使用的编译方式(参见 \ref{subs:compile}~节)和
% 操作系统\footnote{\CTeX{} 宏集现在能够识别 macOS 及 Windows 系统,
% 并将其他系统统一归为 Linux。},选择合适的底层支持和字库,从而简化配置过程。
% 自动配置的情况参见表~\ref{tab:default-font-select}。
%
% \begin{table}[htbp]
% \centering
% \begin{threeparttable}
% \caption{\CTeX{} 宏集自动配置字体策略}
% \label{tab:default-font-select}
% \begin{tabular}{*{5}{c}}
%   \toprule
%              & macOS Old\tnote{1}
%              & macOS New\tnote{2}
%              & Windows\tnote{3}
%              & 其他 \\
%   \midrule
%   \XeLaTeX   & \makecell{\pkg{xeCJK}\\华文字库}
%              & \makecell{\pkg{xeCJK}\\华文字库 + 苹方}
%              & \makecell{\pkg{xeCJK}\\中易字库 + 微软雅黑}
%              & \makecell{\pkg{xeCJK}\\Fandol 字库\tnote{4}} \\
%   \cmidrule(lr){1-5}
%   \LuaLaTeX\tnote{5}
%              & \makecell{\pkg{LuaTeX-ja}\\华文字库}
%              & \makecell{\pkg{LuaTeX-ja}\\华文字库 + 苹方}
%              & \makecell{\pkg{LuaTeX-ja}\\中易字库 + 微软雅黑}
%              & \makecell{\pkg{LuaTeX-ja}\\Fandol 字库} \\
%   \cmidrule(lr){1-5}
%   \pdfLaTeX
%              & 不可用
%              & 不可用
%              & \makecell{\pkg{CJK} + \pkg{zhmetrics}\\中易字库 + 微软雅黑\tnote{6}}
%              & 不可用 \\
%   \cmidrule(lr){1-5}
%   \makecell{\LaTeX{} + \\\dvipdfmx}
%              & 不可用
%              & \makecell{\pkg{CJK} + \pkg{zhmetrics}\\华文字库 + 苹方}
%              & \makecell{\pkg{CJK} + \pkg{zhmetrics}\\中易字库 + 微软雅黑\tnote{6}}
%              & \makecell{\pkg{CJK} + \pkg{zhmetrics}\\Fandol 字库} \\
%   \cmidrule(lr){1-5}
%   \makecell{\upLaTeX{} + \\\dvipdfmx}
%              & 不可用
%              & \makecell{\pkg{zhmetrics-uptex}\\华文字库 + 苹方}
%              & \makecell{\pkg{zhmetrics-uptex}\\中易字库 + 微软雅黑}
%              & \makecell{\pkg{zhmetrics-uptex}\\Fandol 字库} \\
%   \bottomrule
% \end{tabular}
% \begin{tablenotes}
%   \item [1] Yosemite (10.10) 及以前的 macOS 系统。
%   \item [2] El Capitan (10.11) 及以后的 macOS 系统。
%   \item [3] 仅支持 Windows Vista 及以后的 Windows 操作系统。
%   \item [4] 由马起园、苏杰、黄晨成等人开发的开源中文字体,
%     参见:\url{https://www.ctan.org/pkg/fandol}。
%   \item [5] \LuaLaTeX{} 编译时使用 \pkg{LuaTeX-ja} 宏包。对此,
%     第 \ref{sec:lualatex-chinese}~节有特别说明。
%   \item [6] 微软雅黑字体并不总是有效,这和选项 \opt{zhmap} 的取值有关。
% \end{tablenotes}
% \end{threeparttable}
% \end{table}
%
% 通常,由 \CTeX{} 宏集进行的自动配置已经足够使用,无需用户手工干预;但
% 是 \CTeX{} 仍然提供了一系列选项,供在 \CTeX{} 的自动选择机制因为
% 意外情况失效,或者在用户有特殊需求的情况下使用。\emph{除非必要,用户不
% 应使用这些选项。}
%
% \begin{function}[rEXP,updated=2014-03-08]{zhmap}
%   \begin{syntax}
%     zhmap = <\TTF|zhmCJK>
%   \end{syntax}
%   指定字体映射机制。本选项只在使用 (pdf)\LaTeX{} 编译时有意义。
% \end{function}
% \begin{optdesc}
%   \item[true] 这是该选项的默认值。^^A
%   \footnote{对于以键值对形式提供的选项,文档以\textbf{粗体}来表示其默认值。^^A
%   下同,不再额外解释。}使用 \pkg{zhmetrics} 宏包,将 CJK 字库通过 \tn{special}
%   命令映射到 \file{.ttf} 文件。
%
%   \item[false] 使用传统的 CJK 字库(Type 1)^^A
%   \footnote{使用 (pdf)\LaTeX{} 编译时,如果需要使用自定义的字体映射文件(比如需要
%     使用 \LaTeX{} + Dvips 编译),或者希望使用 Type1 字库,请禁用本选项。为此,你
%     可能需要安装 CJK 字体。参考 \pkg{zhmetrics} 宏包提供的脚本
%     \href{https://github.com/CTeX-org/ctex-kit/blob/master/zhmetrics/CTeXFonts.lua}
%     {\file{CTeXFonts.lua}}。}。
%
%   \item[zhmCJK] 载入 \pkg{zhmCJK} 宏包^^A
%   \footnote{\pkg{zhmCJK} 宏包基于 \pkg{zhmetrics} 和 \pkg{CJK} 宏包,提供与
%   \pkg{xeCJK} 宏包类似的用户接口。}^^A
%   ,由 \pkg{zhmCJK} 宏包提供从 CJK 字库到 \file{.ttf} 的映射。
% \end{optdesc}
%
% \begin{function}[added=2014-03-08]{fontset}
%   \begin{syntax}
%     fontset = <adobe|fandol|founder|mac|macnew|macold|ubuntu|windows|none|...>
%   \end{syntax}
%   指定 \CTeX{} 宏集加载的字库。
%
%   如果没有指定 \opt{fontset} 的值,\CTeX{} 宏集将自动检测用户使用的操作系统,配置
%   相应的字体(参见表~\ref{tab:default-font-select})。
% \end{function}
%
% \CTeX{} 预定义了以下六种中文字库。
%
% \begin{optdesc}
%   \item[adobe] 使用 Adobe 公司的四款中文字体,\emph{不支持 \pdfLaTeX}。
%   \item[fandol] 使用 Fandol 中文字体,\emph{不支持 \pdfLaTeX}。
%   \item[founder] 使用方正公司的中文字体。
%   \item[mac] 使用 macOS 系统下的字体,\emph{不支持 \pdfLaTeX},根据版本分为
%     |macnew| 和 |macold| 两种。
%   \item[macnew] 使用 El Capitan 或之后的多字重华文字体和苹方字体。
%   \item[macold] 使用 Yosemite 或之前的华文字体。
%   \item[ubuntu] 使用 Ubuntu 系统下的思源宋体、思源黑体和 \TeX{} 发行版自带的
%     文鼎楷体,\emph{不支持 \pdfLaTeX}。
%   \item[windows] 使用 Windows 系统下的中易字体和微软雅黑字体。
%     当使用 (pdf)\LaTeX{} 编译时,微软雅黑仅在以下两种情形有效:
%     安装有 \pkg{zhmCJK} 宏包且选项 \opt{zhmap=zhmCJK} 时,或者
%     安装有微软雅黑的 Type1 字体且选项 \opt{zhmap=false} 时。
% \end{optdesc}
%
% 如果不想使用 \CTeX{} 预定义的中文字库,可以设置 \opt{fontset} 为下述值之一。
%
% \begin{optdesc}
%   \item[none] 不配置中文字体,需要用户自己配置。
%   \item[\meta{name}] 这里 \meta{name} 为自定义的名字。
%   \CTeX{} 宏集将载入名为 |ctex-fontset-|\meta{name}|.def| 的文件作为字体配置
%   文件。因此,请先保证文件的存在。可以在当前工作目录或者本地 \texttt{TDS} 目录
%   树下合适位置建立一个名为 |ctex-fontset-|\meta{name}|.def| 的文件,在这个文件
%   里面自定义中文字体。然后通过使用 |fontset=|\meta{name} 选项来调用它。字体配置
%   文件的具体写法可以参考 \CTeX{} 宏集 \texttt{fontset} 目录下的字体配置文件。
% \end{optdesc}
%
% 注意:\emph{如果希望使用 \tn{ctexset} 在导言区指定字库,则需要先在宏包/文档类选项中指定
% \opt{fontset = none}}(这会禁用 \CTeX{} 宏集的操作系统检测功能和自动设定字库功能)。例如:
% \begin{ctexexam}
%   \documentclass[fontset = none]{ctexart}
%   \ctexset{fontset = founder}
%   \begin{document}
%   在文档类选项中声明 \verb|fontset = none|,随后在导言区用 \verb|\ctexset|
%   指定字体。
%   \end{document}
% \end{ctexexam}
%
% \CTeX{} 宏集预定义的中文字库还定义了一些字体命令。除了在 \opt{ubuntu} 字库中没有
% \tn{fangsong} 的定义外,所有字库都有以下四个字体命令:
% \begin{optdesc}
%   \item[\tn{songti}] 宋体,CJK 等价命令 |\CJKfamily{zhsong}|。
%   \item[\tn{heiti}] 黑体,CJK 等价命令 |\CJKfamily{zhhei}|。
%   \item[\tn{fangsong}] 仿宋,CJK 等价命令 |\CJKfamily{zhfs}|。
%   \item[\tn{kaishu}] 楷书,CJK 等价命令 |\CJKfamily{zhkai}|。
% \end{optdesc}
% 在 \opt{windows}、\opt{founder} 和 \opt{macnew} 字库中,额外定义了 \tn{lishu}
% 和 \tn{youyuan}:
% \begin{optdesc}
%   \item[\tn{lishu}] 隶书,CJK 等价命令 |\CJKfamily{zhli}|。
%   \item[\tn{youyuan}] 圆体,CJK 等价命令 |\CJKfamily{zhyou}|。
% \end{optdesc}
% 在 \opt{windows} 字库中还定义了 \tn{yahei}。出于兼容性的考虑,\tn{yahei} 命令
% 在 \opt{macnew} 字库中也有定义,但实际调用苹方黑体:
% \begin{optdesc}
%   \item[\tn{yahei}] 微软雅黑,CJK 等价命令 |\CJKfamily{zhyahei}|。
% \end{optdesc}
% 在 \opt{macnew} 字库中,还定义了 \tn{pingfang}:
% \begin{optdesc}
%   \item[\tn{pingfang}] 苹方黑体,CJK 等价命令 |\CJKfamily{zhpf}|。
% \end{optdesc}
%
% \section{排版格式设定}
% \label{sec:format-settings}
% \subsection{文档默认字号}
% \label{subs:options-class}
%
% \begin{function}[rEXP,added=2015-05-06]{zihao}
%   \begin{syntax}
%     zihao = <-4|5|false>
%   \end{syntax}
%   将文章默认字号(\tn{normalsize})设置为小四号字或五号字,
%   具体情况见表 \ref{tab:fontsize}。\opt{false} 禁用本功能。
%   本选项可以用于四个 \CTeX{} 文档类和 \pkg{ctex} 宏包,
%   也可以用于 \pkg{ctexsize} 宏包。
%
%   该选项的默认值与 \opt{scheme} 的取值有关。
%   当 \opt{scheme = chinese} 时,对标准文档类默认值为 |5|,即设置
%   \tn{normalsize} 为五号字;对 \cls{beamer} 则为 |false|,使用文档类原有的设置。
%   当 \opt{scheme = plain} 时,该选项不设默认值,沿用标准文档类或 \cls{beamer} 的原有设置。
% \end{function}
%
% \begin{table}[htbp]
% \centering
% \setlength\tabcolsep{1em}
% \caption{标准字体命令与字号的对应}\label{tab:fontsize}
% \begin{tabular}{l*2{c>{\ttfamily}r}*3{>{\ttfamily}c}}
% \toprule
% & \multicolumn2c{|zihao = 5|} & \multicolumn2c{|zihao = -4|} &
% \multicolumn1c{|10pt|} & \multicolumn1c{|11pt|} & \multicolumn1c{|12pt|} \\
% \cmidrule(lr){2-3} \cmidrule(lr){4-5}
% \cmidrule(lr){6-6} \cmidrule(lr){7-7} \cmidrule(lr){8-8}
% 字体命令        & 字号 & \si{bp} & 字号 & \si{bp}
%                        & \si{pt} & \si{pt} & \si{pt} \\
% \midrule
% |\tiny|         & 七号 & 5.5  & 小六 & 6.5  & ~5 & ~6 & ~6 \\
% |\scriptsize|   & 小六 & 6.5  & 六号 & 7.5  & ~7 & ~8 & ~8 \\
% |\footnotesize| & 六号 & 7.5  & 小五 & 9~~  & ~8 & ~9 & 10 \\
% |\small|        & 小五 & 9~~  & 五号 & 10.5 & ~9 & 10 & 11 \\
% |\normalsize|   & 五号 & 10.5 & 小四 & 12~~ & 10 & 11 & 12 \\
% |\large|        & 小四 & 12~~ & 小三 & 15~~ & 12 & 12 & 14 \\
% |\Large|        & 小三 & 15~~ & 小二 & 18~~ & 14 & 14 & 17 \\
% |\LARGE|        & 小二 & 18~~ & 二号 & 22~~ & 17 & 17 & 20 \\
% |\huge|         & 二号 & 22~~ & 小一 & 24~~ & 20 & 20 & 25 \\
% |\Huge|         & 一号 & 26~~ & 一号 & 26~~ & 25 & 25 & 25 \\
% \bottomrule
% \end{tabular}
%\end{table}
%
% \begin{function}[rEXP]{10pt, 11pt, 12pt}
%   \CTeX{} 文档类是在 \LaTeX{} 标准文档类之上开发的。因此,除了可以使用 \CTeX{}
%   宏包定义的字号选项之外,还可以使用标准文档类的同类选项(\opt{10pt}、\opt{11pt}
%   和 \opt{12pt})。在使用这些来自标准文档类的选项的时候,\CTeX{} 文档类的字号
%   选项会被抑制。亦即,在 \opt{zihao} 选项之后设置 \opt{10pt} 选项,
%   \opt{zihao} 选项将不再起作用。
% \end{function}
%
% 标准文档类的其他选项在 \CTeX{} 文档类中依旧有效。例如,设置纸张大小和方向的
% \opt{a4paper} 和 \opt{landscape},设置单双面的 \opt{oneside} 和
% \opt{twoside} 等。\CTeX{} 会将这些选项传给标准文档类^^A
% \footnote{事实上,\LaTeX{} 在文档类中的选项是全局设定的,除了对使用的文档类有
% 影响外,也可能会影响到随后使用的宏包。如果这些宏包中有某些选项出现在文档类的
% 选项列表中,那么该选项将会被自动激活。}。
%
% \subsection{章节标题风格}
% \label{subs:options-heading}
%
% \begin{function}[rEXP,added=2014-03-08]{heading}
%   \begin{syntax}
%     heading = <\TFF>
%   \end{syntax}
%   本选项只能在调用 \pkg{ctex.sty} 时作为宏包选项使用。
%
%   \CTeX{} 宏集提供了一套用于修改文档章节标题格式的接口。该选项用于选择是否
%   启用该功能。详细的设置方法请参见第 \ref{subs:pagestyle}~节和第 \ref{sec:secstyle}~节。
% \end{function}
%
% \CTeX{} 宏集提供的四个文档类总是启用该功能。如果在 \pkg{ctex.sty} 下启用该选项,
% 将会检查当前是否使用 \LaTeX{} 标准文档类。
% 若然,则该选项将会使得 \pkg{ctex.sty} 宏包的行为和 \CTeX{} 宏集提供的
% 四个中文文档类\emph{完全}一致;若不然,则会根据 \tn{chapter}
% 是否有定义来使用 \cls{ctexbook} 或者 \cls{ctexart} 的标题设置。
%
% \begin{function}[rEXP]{sub3section, sub4section}
%   修改 \tn{paragraph} 和 \tn{subparagraph} 的格式。
%
%   默认情况下,\tn{paragraph} 和 \tn{subparagraph} 会将标题与随后的正文
%   排版在同一个段落。启用 \opt{sub3section} 会将 \tn{paragraph} 的格式修改为
%   类似 \tn{section} 的格式,并将 \tn{subparagraph} 的格式修改为原本 \tn{paragraph}
%   的格式。启用 \opt{sub4section} 会将 \tn{paragraph} 和 \tn{subparagraph} 的格式
%   都修改为类似 \tn{section} 的格式。
%
%   启用该选项通常还需要将计数器 |secnumdepth| 的值为设置为 |4| 或 |5|。
%
%   具体格式可参考 \ref{subsec:sec-spacing}~小节中的 \opt{runin} 和 \opt{afterskip} 选项。
%
%   注意,上述两个选项只有在非 \cls{beamer} 文档类下 \opt{heading} 选项启用的时候
%   才有意义。亦即,只有在使用除了 \cls{ctexbeamer} 的三个 \CTeX{} 文档类或启用了
%   \opt{heading} 的 \pkg{ctex.sty} 的时候才有意义。
% \end{function}
%
% \subsection{排版方案选项}
% \label{subs:options-type-style}
%
% \begin{function}[rEXP,added=2015-04-15]{scheme}
%   \begin{syntax}
%     scheme = <(chinese)|plain>
%   \end{syntax}
%   选择文章的排版方案,预设有 \opt{chinese} 和 \opt{plain} 两种方案。
% \end{function}
%   \begin{optdesc}[itemsep=\medskipamount]
%     \item[chinese] 对 \cls{beamer} 以外的文档类,调整默认字号为五号字,并调
%       整行距为 |1.3|;汉化文档中的标题名字(如“图”、“表”、“目录”和“参
%       考文献”等,见 \ref{subs:capname}~节);
%       在 \opt{heading = true} 的情况下^^A
%       \footnote{使用 \CTeX{} 文档类,或者使用 \pkg{ctex} 宏包且开启该选项时。}^^A
%       (\ref{subs:options-heading}~节),还会将章节标题的风格修改为
%       中文样式(见 \ref{sec:secstyle}~节)。
%
%       当关闭 \opt{heading} 选项的 \pkg{ctex} 宏包与标准文档类或其衍生文档类
%       联用时,会载入 \pkg{indentfirst} 宏包,以实现章节标题后的段首缩进。
%     \item[plain] 不调整默认字号和行距,不会汉化文档中的标题名字,也不会将章节
%       标题风格修改为中文样式,同时不会调整 \tn{pagestyle},并禁用 \opt{autoindent}
%       选项。事实上,此时的 \CTeX{} 宏集只提供了中文支持功能,而不对文章版式进行任何修改。
%   \end{optdesc}
%
% \begin{function}[updated=2014-04-11]{punct}
%   \begin{syntax}
%     punct = <(quanjiao)|banjiao|kaiming|CCT|plain>
%   \end{syntax}
%   设置标点处理格式。预定义好的格式有:
% \end{function}
%   \begin{optdesc}
%     \item[quanjiao] 全角式:所有标点占一个汉字宽度,相邻两个标点占 1.5 汉字宽度;
%     \item[banjiao]  半角式:所有标点占半个汉字宽度;
%     \item[kaiming]  开明式:句末点号^^A
%       \footnote{标点符号分为标号与点号。点号分为两类,一共七种:句末点号有^^A
%       句号、问号和叹号;句内点号有逗号、顿号、冒号和分号。}用占一个汉字宽度,标^^A
%       号和句内点号占半个汉字宽度;
%     \item[CCT]   CCT 式:所有标点符号的宽度略小于一个汉字宽度;
%     \item[plain] 原样(不调整标点间距)。
%   \end{optdesc}
%
% \begin{function}[updated=2014-03-08]{space}
%   \begin{syntax}
%     space = <\TF|(auto)>
%   \end{syntax}
%   是否在生成的 PDF 中保留汉字后面的空格。该选项仅在使用 \XeLaTeX{}/(pdf)\LaTeX{} 编译时有效。
% \end{function}
%
% \begin{optdesc}
%   \item[true] 总是保留汉字后的空格。此时,用户需要自行在行尾加上~|%|~处理换行产生
%     的空格\footnote{\LaTeX{} 将单个换行视作一个空格。}。
%   \item[false] 使用 (pdf)\LaTeX{} 编译时:总是忽略掉汉字后面的空格,不论汉字后是什么;
%     使用 \XeLaTeX{} 编译时,等同于 \opt{auto} 的效果。不建议使用该选项。
%   \item[auto] 根据空格后面的情况决定是否保留:如果空格后面是汉字,则忽略该
%   空格,否则保留。
% \end{optdesc}
%
%   例如,使用
%   \begin{ctexexam}
%   \ctexset{space=true}
%   汉字 分词
%   技术 English
%   \end{ctexexam}
%   将得到“{\ctexset{space=true}汉字 分词 技术 English}”;使用
%   \begin{ctexexam}
%   \ctexset{space=auto}
%   汉字 分词
%   技术 English
%   \end{ctexexam}
%   则会得到“{\ctexset{space=auto}汉字 分词 技术 English}”。
%
% \emph{使用 \textup{\LuaLaTeX{} 及 \upLaTeX} 编译的时候,该选项无效:汉字间的
% 空格以及汉字与西文字符之间的空格总是有效,不会被忽略,但可以自动忽略掉由换行
% 产生的空格。}
%
% \begin{function}[rEXP,added=2014-04-23]{linespread}
%   \begin{syntax}
%     linespread = <数值>
%   \end{syntax}
%   接受一个浮点数值,设置行距倍数。本选项的初始值与 \opt{scheme} 有关。
% \end{function}
% \begin{optdesc}
%   \item[scheme = chinese] 对标准文档类初始值为 $1.3$,即 $1.3$ 倍行距。此
%   时,相邻两行的基线(\tn{baselineskip})距离为 $1.3\times 1.2=1.56$ 倍字体
%   高度。对 \cls{beamer} 不改变行距,即使用默认的单倍行距。
%
%   \item[scheme = plain] \CTeX{} 宏集默认不调整行距倍数,文档中的行距由所选文档类和
%   其他宏包或用户设置决定。
% \end{optdesc}
%
% \begin{function}[added=2014-03-13]{autoindent}
%   \begin{syntax}
%     autoindent = <\TTF|数值|带单位的数值>
%   \end{syntax}
%   在字体大小发生变化时,是否自动调整段首缩进(\tn{parindent})的大小。
% \end{function}
% \begin{optdesc}
%   \item[\meta{数值或带单位的数值}] 用于设置段首缩进的长度。如果不带单位,则默认
%   单位是单个汉字字宽 \tn{ccwd};如果带单位,则使用该单位。
%   若要显式使用 \tn{ccwd} 为单位,则必须在导言区进行设置。
%
%   \item[true] 等价于设置 \opt{autoindent = 2} 或
%   在导言区设置 \opt{autoindent = 2\tn{ccwd}}。
%
%   \item[false] 禁用自动调整功能,可以设置固定长度的段首缩进。如设置每段缩进 40 点:
%   \begin{ctexexam}
%   \ctexset{autoindent=false}
%   \setlength\parindent{40pt}
%   \end{ctexexam}
% \end{optdesc}
%
% \begin{function}[EXP,added=2014-03-26]{linestretch}
%   \begin{syntax}
%     linestretch = <数值或长度>
%   \end{syntax}
%   \opt{linestretch} 是一个比较特殊的选项,它用来设置汉字之间弹性间距的弹性程
%   度。如果有单位,则可以在选项中直接写;如果是数字,单位则是汉字宽度
%   \tn{ccwd} 的倍数。
% \end{function}
%
%   如果行宽不是汉字宽度的整数倍,为了让段落左右两端对齐,自然就要求伸展汉字之
%   间的间距,而 \opt{linestretch} 选项就是设置每行总的允许伸行量。初始值是允
%   许每行伸行一个汉字的宽度 \tn{ccwd},并且此宽度能根据字号变化动态调整。
%
%   过小的 \opt{linestretch} 可能导致段落文字右侧可能参差不齐;较大的
%   \opt{linestretch} 选项则可以帮助拥有较长不可断行内容的复杂段落方便地断行,
%   而不会产生大量编译警告;但很大的 \opt{linestretch} 则会掩盖段落不良断行产
%   生的坏盒子警告。
%
%   如果将 \opt{linestretch} 选项的值设置为 \tn{maxdimen},则可以禁止按字号自
%   动修改每行的允许伸长量。此时汉字间的弹性间距则固定为 \tn{baselineskip} 的
%   $0.08$ 倍。
%
% \section{文档汉化}
% \label{sec:chinese-localization}
% \subsection{日期汉化}
%
% \CTeX 宏包对显示当前日期的 \tn{today} 命令进行了汉化,使之以中文的方式显示今
% 天的日期。如本文档编译时的日期是“\today”。
%
% \begin{function}[EXP]{today}
%   \begin{syntax}
%     today = <(small)|big|old>
%   \end{syntax}
% 该选项用来控制 \tn{today} 命令的输出格式:
% \begin{optdesc}
%   \item[small] \ctexset{today=small}
%     效果为“\today”。使用阿拉伯数字和汉字的日期格式。
%   \item[big] \ctexset{today=big}
%     效果为“\today”。使用全汉字的日期格式。
%   \item[old] \ctexset{today=old}
%     效果为“\today”。使用文档原来的(英文)日期格式。
%     \ctexset{today=small}  ^^A NOTE(Liam): 复原设定是好习惯。
% \end{optdesc}
% \end{function}
%
% 设置日期格式使用 \tn{ctexset} 命令完成,例如设置全汉字的日期格式:
% \begin{ctexexam}
%   \ctexset{today=big}
% \end{ctexexam}
%
% \CTeX 宏包的中文日期功能实际上是调用 \pkg{zhnumber} 宏包完成的。如果需要更
% 多有关日期、时间的命令和更复杂的设置,可以查阅 \pkg{zhnumber} 宏包的文档。
%
% \subsection{文档标题汉化}
% \label{subs:capname}
%
% 这里主要介绍由 \opt{scheme} 选项(\ref{subs:options-type-style}~节)控制
% 的文档标题汉化功能。
%
% 设置文档标题名的示例可见例~\ref{exam:capname}。下面的选项(如
% \opt{contentsname})主要用来重新定义与选项同名的宏(如 \tn{contentsname})的
% 定义。
%
% \begin{defaultcapconfig}
%
% \begin{function}[EXP]{contentsname}
%   \begin{syntax}
%     contentsname = <名字>
%   \end{syntax}
% 设置目录标题名 \tn{contentsname}。中文默认为“\contentsname”。
% \end{function}
%
% \begin{function}[EXP]{listfigurename}
%   \begin{syntax}
%     listfigurename = <名字>
%   \end{syntax}
% 设置插图目录标题名 \tn{listfigurename}。中文默认为“\listfigurename”。
% \end{function}
%
% \begin{function}[EXP]{listtablename}
%   \begin{syntax}
%     listtablename = <名字>
%   \end{syntax}
% 设置表格目录标题名 \tn{listtablename}。中文默认为“\listtablename”。
% \end{function}
%
% \begin{function}[EXP]{figurename}
%   \begin{syntax}
%     figurename = <名字>
%   \end{syntax}
% 设置图片环境标题名 \tn{figurename}。中文默认为“\figurename”。
% \end{function}
%
% \begin{function}[EXP]{tablename}
%   \begin{syntax}
%     tablename = <名字>
%   \end{syntax}
% 设置表格环境标题名 \tn{tablename}。中文默认为“\tablename”。
% \end{function}
%
% \begin{function}[EXP]{abstractname}
%   \begin{syntax}
%     abstractname = <名字>
%   \end{syntax}
% 设置摘要 \env{abstract} 环境标题名 \tn{abstractname}。中文默认
% 为“\abstractname”。注意 \cls{book} 类没有摘要,该选项无效。
% \end{function}
%
% \begin{function}[EXP]{indexname}
%   \begin{syntax}
%     indexname = <名字>
%   \end{syntax}
% 设置索引标题名 \tn{indexname}。中文默认为“\indexname”。
% \end{function}
%
% \begin{function}[EXP]{appendixname}
%   \begin{syntax}
%     appendixname = <名字>
%   \end{syntax}
% 设置附录标题名 \tn{appendixname}。中文默认为“\appendixname”。
% \end{function}
%
% \begin{function}[EXP]{bibname}
%   \begin{syntax}
%     bibname = <名字>
%   \end{syntax}
% 设置参考文献标题名。中文默认为“\refname”。
%
% 在标准文档类中 \cls{article} 的参考文献名使用宏 \tn{refname},而
% \cls{book} 和 \cls{report} 使用宏 \tn{bibname}。本选项会根据标准文档类的不同,自动
% 设定 \tn{refname} 或是 \tn{bibname}。因此,对于标准文档类及对应的 \CTeX{} 文档类
% 可以统一地使用 \opt{bibname} 选项来控制参考文献标题名。
%
% 对于 \cls{beamer} 及对应的 \cls{ctexbeamer} 来说,它们同时具有宏 \tn{bibname} 和
% 宏 \tn{refname}。本选项仅控制其中的 \tn{bibname};
% \tn{refname} 则交由 \opt{refname} 选项控制。
% \end{function}
%
% \begin{function}[EXP]{proofname}
%   \begin{syntax}
%     proofname = <名字>
%   \end{syntax}
% 设置证明环境的名称 \tn{proofname}。中文默认为“\proofname”。
% \end{function}
%
% 如果使用 \cls{ctexbeamer} 文档类或者在 \cls{beamer} 文档类下使用 \pkg{ctex} 包,
% 还会汉化常用定理类环境的诸如“定义”、“定理”和“引理”等名称。此时,还有下列
% 三个选项。
%
% \begin{function}[EXP]{refname}
%   \begin{syntax}
%     refname = <名字>
%   \end{syntax}
% 设置参考文献标题名 \tn{refname}。中文默认为“\refname”。
%
% 注意,三个标准文档类(及相应的 \CTeX{} 文档类)的参考文献标题名由 \opt{bibname} 选项
% 统一设置,本选项仅适用于 \cls{beamer} 及其对应的 \cls{ctexbeamer}。
% 在三个标准文档类(及相应的 \CTeX{} 文档类)中使用 \opt{refname} 选项会报错。
% \end{function}
%
% \begin{function}[EXP]{algorithmname}
%   \begin{syntax}
%     algorithmname = <名字>
%   \end{syntax}
% 设置算法环境标题名 \tn{algorithmname}。中文默认为“算法”。
% \end{function}
%
% \begin{function}[EXP]{continuation}
%   \begin{syntax}
%     continuation = <名字>
%   \end{syntax}
% 设置 \cls{beamer} 可断页的帧在续页标题中的延续标识 \tn{insertcontinuationtext}。
% 中文默认为“(续)”。
% \end{function}
%
% \end{defaultcapconfig}
%
% \subsection{页面格式设置与汉化}
% \label{subs:pagestyle}
%
% 页面格式设置与汉化的功能(及章节标题样式设置功能,见第 \ref{sec:secstyle} 节)^^A
% 由 \pkg{ctexheading} 宏包完成。加载该宏包时,或者使用 \CTeX{} 文档类时,^^A
% 或者是使用 \pkg{ctex} 宏包并设定选项 \opt{heading = true} 时,相关功能被激活。
% 此时,整个文档的页面格式(page style)被设定为 |headings|,即相当于设置了
% \begin{frameverb}
%   \pagestyle{headings}
% \end{frameverb}
% 在页眉中显示当前章节的编号与标题。
%
% 同时,\CTeX 宏包也会对默认的 |headings| 页面格式进行修改,使之调用
% \tn{CTEXthechapter}、\tn{CTEXthesection} 等宏来正确显示中文的章节编号。
%
% \CTeX 宏包的默认页面格式设置是经过汉化的 |headings|,其基本效果如本文档所
% 示,只在页眉一侧显示章节编号和标题,另一侧显示页码。
%
% 更复杂的页面格式可以通过调用 \pkg{fancyhdr}、\pkg{titleps} 等宏包来设
% 置。\CTeX 宏包同时也为这些自定义页面格式
% 的包提供了以下宏供使用:
% \begin{itemize}
% \item \tn{CTEXthechapter}、\tn{CTEXthesection} 等章节编号(见
% \ref{subsec:sec-commands}~小节)。它们用来代替英文文档类中的
% \tn{thechapter}、\tn{thesection} 等宏。
%
% \item \tn{leftmark}、\tn{rightmark},它们是在使用章节标题命令后,自动设置的
% 宏。它们实际是在与章节标题命令对应的标记命令
% \tn{chaptermark}、\tn{sectionmark} 中调用 \tn{markright} 或 \tn{markboth} 生
% 成的。
% \end{itemize}
% 有关 \LaTeX 页面标记的含义与使用细节,已经超出了本文档讨论的范围。可以参考
% \cite[Chapter~23]{knuthtex1986}、\cite[\S4.3, \S4.4]{mittelbach2004} 等书籍。
%
% 这里举一个例子,说明通过重定义 \tn{sectionmark},在 \cls{ctexart} 文档类中的
% 标准 |headings| 页面格式下控制页眉的方式:
% \begin{ctexexam}
%   \documentclass{ctexart}
%   \pagestyle{headings}
%   \ctexset{section={
%       name={第,节},
%       number=\arabic{section},
%     }
%   }
%   \renewcommand\sectionmark[1]{%
%     \markright{\CTEXifname{\CTEXthesection——}{}#1}}
%
%   \begin{document}
%
%   \section{天地玄黄}
%   \newpage
%
%   \section{宇宙洪荒}
%
%   \end{document}
% \end{ctexexam}
% 在上例中,我们设置了页眉的形式是用破折号分开的节编号与节标题,即“第 1 节
% ——天地玄黄”、“第 2 节——宇宙洪荒”。
%
% \CTeX 宏包已经对 \pkg{fancyhdr} 宏包进行了补丁,载入 \pkg{fancyhdr} 后,其
% |fancy| 页面格式将使用 \tn{CTEXthechapter} 等宏显示中文章节编号。
%
% 关于 \pkg{fancyhdr} 的具体用法可以参见其宏包手册。通常也只要像在标准的英文文
% 档类中使用 \pkg{fancyhdr} 一样定义页眉页脚格式即可,并不需要额外的定义。
%
% 下面我则给出一个与前例类似而稍复杂的例子,展示如何在文档中设置页眉内容与页眉
% 的格式。
% \begin{ctexexam}
%   \documentclass{ctexart}
%   \ctexset{section={
%       name={第,节},
%       number=\arabic{section},
%     }
%   }
%   \usepackage{fancyhdr}
%   \fancyhf{}
%   \lhead{\textnormal{\kaishu\rightmark}}
%   \rhead{--\ \thepage\ --}
%   \pagestyle{fancy}
%   % \sectionmark 的重定义需要在 \pagestyle 之后生效
%   \renewcommand\sectionmark[1]{%
%     \markright{\CTEXifname{\CTEXthesection——}{}#1}}
%
%   \begin{document}
%
%   \section{天地玄黄}
%   \newpage
%
%   \section{宇宙洪荒}
%
%   \end{document}
% \end{ctexexam}
% 本例的页眉效果大致如下(有页眉线):
% \begin{trivlist}\item
% \textnormal{\kaishu 第 1 节——天地玄黄}\hfill -- 1 --\par
% \smallskip\hrule
% \end{trivlist}
%
% \section{章节标题样式设置}
% \label{sec:secstyle}
%
% \CTeX{} 宏集对 \LaTeX{} 的标准文档类(\cls{article}、\cls{report}、
% \cls{book})和 \cls{beamer} 进行了章节标题样式设置功能的扩充。
% 章节标题样式设置功能(及页面格式设置与汉化功能,见第 \ref{subs:pagestyle} 节)^^A
% 由 \pkg{ctexheading} 宏包完成。加载该宏包时,或者使用 \CTeX{} 文档类时,^^A
% 或者是使用 \pkg{ctex} 宏包并设定选项 \opt{heading = true} 时,相关功能被激活。
% 其中,独立使用 \pkg{ctexheading} 宏包时,本节介绍各选项的默认值与指定
% \opt{scheme = plain} 时相同。
%
% 本节涉及的所有选项均需使用 \tn{ctexset} 命令设置。
%
% \changes{v2.0}{2015/03/21}{\tn{CTEXsetup}, \tn{CTEXoptions} 是过时命令。}
%
% 章节标题的样式选项是分层设置的。顶层的选项是章节标题名称(例如 |section|),
% 次一层的选项是章节标题的样式(例如 \opt{nameformat})。章节标题名称包括
% |part|, |chapter|, |section|, |subsection|, |subsubsection|, |paragraph|,
% |subparagraph|。可用的样式选项包括:
% \begin{itemize}
%   \item 编号相关(\ref{subsec:sec-number}~小节):
%     \opt{numbering}, \opt{name}, \opt{number}
%   \item 格式相关(\ref{subsec:sec-format}~小节):
%     \opt{format}, \opt{nameformat}, \opt{numberformat}, \opt{titleformat},
%     \opt{aftername}, \opt{aftertitle}, \opt{pagestyle}
%   \item 间距、缩进相关(\ref{subsec:sec-spacing}~小节):
%     \opt{runin}, \opt{hang}, \opt{indent}, \opt{beforeskip}, \opt{afterskip},
%     \opt{fixskip}, \opt{break}, \opt{afterindent}
%   \item 目录、附录相关(\ref{subsec:sec-toc-appendix}~小节):
%     \opt{tocline}, \opt{lofskip}, \opt{lotskip}, \opt{appendix/numbering},
%     \opt{appendix/name}, \opt{appendix/number}
% \end{itemize}
%
% 注意,对 \cls{article} 及其衍生的 \cls{ctexart} 等文档类,没有 |chapter|
% 级别的标题;而对于 \cls{beamer} 文档类,这些选项控制的是由 \tn{partpage},
% \tn{sectionpage} 和 \tn{subsectionpage} 产生的标题样式,此时只有 |part|,
% |section| 和 |subsection| 这三层级别,并且 \opt{runin}, \opt{afterindent},
% \opt{fixskip}, \opt{hang}, \opt{break} 和 \opt{tocline} 这六个选项无效。
%
% 多层选项之间用斜线分开,例如,\opt{part/name} 选项设置 \tn{part} 标题的在数
% 字前后的名称,而 \opt{section/number} 选项设置 \tn{section} 标题的数字类型。
% 注意,斜线 |/| 的前后不能有空格或者换行。
%
% 使用 \tn{ctexset} 设置多级选项时,还可以在同一个上级选项下设置多个下级选项。
% 例如,同时设置 |part| 一级标题的 \opt{pagestyle} 选项,|chapter| 一级标题的
% \opt{format} 与 \opt{pagestyle} 选项和 |section| 一级标题的 \opt{name} 与
% \opt{number} 选项:
% \begin{ctexexam}
%   \ctexset {
%     part/pagestyle = empty,
%     chapter = {
%       format    = \raggedright,
%       pagestyle = empty,
%     },
%     section = {
%       name   = {第,节},
%       number = \chinese{section},
%     }
%   }
% \end{ctexexam}
%
% \subsection{编号相关}
% \label{subsec:sec-number}
%
% \begin{function}[EXP,added=2015-06-21]{part/numbering, chapter/numbering,
%   section/numbering, subsection/numbering, subsubsection/numbering,
%   paragraph/numbering, subparagraph/numbering}
%   \begin{syntax}
%     numbering = \TTF
%   \end{syntax}
%   控制是否对\emph{不带星号}的章节标题进行编号。
%   各级标题的默认值均为 \opt{true}。
%
%   \LaTeX{} 标准的章节标题命令(如 \tn{section})大体上完成四项工作:
%   输出标题内容、对标题编号(计数器增加 1)、将标题列入目录(若调用了
%   \pkg{hyperref} 宏包还会添加 PDF 书签)、更新页眉页脚标记。带星号的
%   章节标题命令(如 \tn{section*})只简单地输出章节标题内容,但不对标题编号,
%   不将标题列入目录或 PDF 书签,也不写入页眉页脚标记。与之不同的是,
%   本选项仅仅是否对\emph{不带星号}的章节标题进行编号。因此,当设置本选项为
%   \opt{false} 时,除了不对标题编号以外,其余功能与正常标题一致:可以
%   编入目录,并生成正确的 \pkg{hyperref} 目录超链接位置和页眉页脚标记。例如:
%   \begin{ctexexam}
%   \documentclass{ctexbook}
%   \begin{document}
%   \tableofcontents
%   \chapter{A}
%   \chapter*{B}
%   \ctexset{chapter/numbering=false}
%   \chapter{C}
%   \end{document}
%   \end{ctexexam}
%   三章的标题分别为“第一章\quad A”、“B”和“C”,但在目录中则只出现
%   “第一章\quad A”和“C”。
%
%   注意,章节标题是否编号还要受到 \LaTeX{} 计数器 |secnumdepth| 的控制^^A
%   (可通过以下介绍的 \opt{secnumdepth} 选项设置)。
%   例如,对于 |section| 而言,其深度为 1。因此,|section| 会被编号,当且仅当
%   |secnumdepth| 不小于 1,并且 \opt{section/numbering} 为 \opt{true},
%   并且使用不带星号的章节标题命令(即 \tn{section})。
% \end{function}
%
% \begin{function}[EXP,added=2020-05-06]{secnumdepth}
%   \begin{syntax}
%     secnumdepth = <整数或章节名称>
%   \end{syntax}
%   设置对章节标题进行编号的层次数。\opt{secnumdepth} 的值可以是一个整数,也可以是
%   |part|, |chapter| 等名称。
%   层次数与名称的对应关系见表~\ref{tab:heading-level}。
%   章节层次的默认设置见表~\ref{tab:heading-level-default}。
%
%   本选项对 \cls{beamer}/\cls{ctexbeamer} 文档类无效。
% \end{function}
%
% \begin{table}[htbp]
% \begin{minipage}[t]{.43\linewidth}
%   \small\centering
%   \caption{章节层次}
%   \label{tab:heading-level}
%   \begin{tabular}{rll}
%   \toprule
%   层次 & 名称 & 注 \\
%   \midrule
%   |-1| & part    & \cls{book}/\cls{report} 类 \\
%    |0| & chapter & \cls{book}/\cls{report} 类 \\
%    |0| & part    & \cls{article} 类   \\
%    |1| & section \\
%    |2| & subsection \\
%    |3| & subsubsection \\
%    |4| & paragraph \\
%    |5| & subparagraph \\
%   \bottomrule
%   \end{tabular}
% \end{minipage}^^A
% \begin{minipage}[t]{.57\linewidth}
%   \small\centering
%   \caption{章节层次的默认设置}
%   \label{tab:heading-level-default}
%   \begin{tabular}{lll}
%   \toprule
%   文档类 & \opt{secnumdepth} & \opt{tocdepth} \\
%   \midrule
%   \cls{article}           & |3| (subsubsection) & |3| (subsubsection) \\
%   \cls{book}/\cls{report} & |2| (subsection)    & |2| (subsection) \\
%   \cls{beamer}            & 无效 & |3| (subsubsection) \\
%   \bottomrule
%   \end{tabular}
% \end{minipage}
% \end{table}
%
%   如果没有特别说明,以下将用 “|...|” 代表各级章节标题名。
%
% \begin{function}[EXP,updated=2014-03-08]{.../name}
%   \begin{syntax}
%     name = \{<前名字>,<后名字>\}
%     name = \Arg{前名字}
%   \end{syntax}
%   设置章节的名字。所谓“章节的名字”,可以分为前后两部分,即章节编号前后的
%   词语,两个词之间用一个半角逗号分开;也可以只有一部分,表示只有章节编号之前
%   的名字。例如:
%   \begin{ctexexam}
%   \ctexset{
%     chapter/name = {第,章},
%     section/name = {\S},
%   }
%   \end{ctexexam}
%   会使得 \tn{chapter} 标题使用形如“第一章”的名字,而 \tn{section} 标题则使
%   用形如“\S1”的名字。该选项的默认设置见表~\ref{tab:name-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \setlength\leftskip{0pt plus 1 fil minus \marginparwidth}
%   \caption{\opt{name} 选项的默认设置}
%   \label{tab:name-default}
%   \begin{tabular}{llll}
%   \toprule
%   标题名 & \opt{scheme = chinese} & \opt{scheme = plain} & 注 \\
%   \midrule
%   part & |{第,部分}| & |{\partname\space}| & 原 \tn{partname} 为 Part \\
%   chapter & |{第,章}| & |{\chaptername\space}|
%     & 原 \tn{chaptername} 为 Chapter \\
%   section (beamer) & |{}| & |{\sectionname\space}|
%     & \BSTACK 原 \tn{sectionname} 为\\ |\translate{Section}| \ESTACK \\
%   section & 同右 & |{}| & \\
%   subsection (beamer) & |{}| & |{\subsectionname\space}|
%     & \BSTACK 原 \tn{subsectionname} 为\\ |\translate{Subsection}| \ESTACK \\
%   subsection & 同右 & |{}| & \\
%   subsubsection & 同右 & |{}| & \\
%   paragraph & 同右 & |{}| & \\
%   subparagraph & 同右 & |{}| & \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \begin{function}[EXP]{.../number}
%   \begin{syntax}
%     number = \Arg{数字输出命令}
%   \end{syntax}
%   设置章节编号的数字输出格式。\meta{数字输出命令} 通常是对应章节编号计数器的
%   输出命令,如 \tn{thesection} 或 |\chinese{chapter}| 之类。例如:
%   \begin{ctexexam}
%   \ctexset{
%     section/number = \Roman{section}
%   }
%   \end{ctexexam}
%   将会使 \tn{section} 的编号变为大写罗马数字(如 I、II 等)。
%
%   \opt{number} 选项定义的同时将控制对章节计数器的交叉引用。在引用计数器时,
%   记录在 \LaTeX{} 辅助文件中的是 \opt{number} 选项的定义。
%
%   但是,\opt{number} 选项不会影响计数器本身的输出。即设置 |section/number|
%   不会影响 \tn{thesection} 的定义(但该选项会影响 \tn{CTEXthesection} 的定
%   义,见后)。该选项的默认设置见表~\ref{tab:number-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{number} 选项的默认设置}
%   \label{tab:number-default}
%   \setlength\leftskip{0pt plus 1 fil minus \marginparwidth}
%   \begin{tabular}{llll}
%   \toprule
%   标题名 & \opt{scheme = chinese} & \opt{scheme = plain}
%     & 原 |\the|\meta{标题} 等价定义 \\
%   \midrule
%   part (beamer) & |\chinese{part}| & |\insertromanpartnumber| & 意义为 |\Roman{part}| \\
%   part & |\chinese{part}| & |\thepart| & |\Roman{part}| \\
%   chapter & |\chinese{chapter}| & |\thechapter| & |\arabic{chapter}| \\
%   section (beamer) & 同右 & |\insertsectionnumber| & 意义为 |\arabic{section}| \\
%   section & 同右 & |\thesection| & |\arabic{section}| \\
%   subsection (beamer)
%     & \BSTACK |\arabic{section}.|\\ |\arabic{subsection}| \ESTACK
%     & |\insertsubsectionnumber| & 意义为 |\arabic{subsection}| \\
%   subsection & 同右 & |\thesubsection| & |\thesection.\arabic{subsection}| \\
%   subsubsection & 同右 & |\thesubsubsection|
%     & |\thesubsection.\arabic{subsubsection}| \\
%   paragraph & 同右 & |\theparagraph|
%     & |\thesubsubsection.\arabic{paragraph}| \\
%   subparagraph & 同右 & |\thesubparagraph|
%     & |\theparagraph.\arabic{subparagraph}| \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \subsection{格式相关}
% \label{subsec:sec-format}
%
% \CTeX{} 宏集提供了 \opt{numberformat}, \opt{nameformat}, \opt{titleformat},
% \opt{format} 这几个选项用来控制章节标题的格式。
% 它们的作用范围如图~\ref{fig:heading-format} 所示。具体用法见下文。
%
% \begin{figure}[htbp]
%   \centering
%   \[
%     \underbrace{
%       \overbrace{
%         \text{\huge\bfseries 第}
%         \mspace{-25mu}
%         \underbrace{\text{\huge\bfseries 1}}_{\text{\small\opt{numberformat}}}
%         \mspace{-25mu}
%         \text{\huge\bfseries 章}
%       }^{\text{\small\opt{nameformat}}} \quad
%       \overbrace{\text{\huge\bfseries 熟悉 \LaTeX}}^{\text{\small\opt{titleformat}}}
%     }_{\text{\small\opt{format}}}
%   \]
%   \caption{\opt{numberformat}, \opt{nameformat}, \opt{titleformat},
%     \opt{format} 几个选项的作用范围示意}
%   \label{fig:heading-format}
% \end{figure}
%
% \begin{function}[EXP,updated=2020-04-22]{.../format, .../format+}
%   \begin{syntax}
%     format = \Arg{格式命令}
%     format+= \Arg{格式命令}
%   \end{syntax}
%   \opt{format} 选项用于控制章节标题的全局格式,作用域为章节名字和随后的标题
%   内容。可以用于控制章节标题的对齐方式、整体字体字号等格式。
%   带加号的 \opt{format+} 选项用于在已有的格式命令后附加内容。
%
%   \opt{format} 选项的最后一个格式命令可以带有一个参数。
%   这一参数用于接受章节名字、编号和标题内容(以及由 \opt{nameformat}, \opt{numberformat},
%   \opt{aftername}, \opt{titleformat}, \opt{aftertitle}, \opt{indent}
%   及 \opt{hang} 选项设定的,应用于这些内容之上的格式),以实现特殊效果。
%
%   例如,设置章标题为无衬线字体左对齐、为节标题增加无衬线字体设置、
%   为小节标题加框(\tn{fbox} 命令本身需带一个参数):
%   \begin{ctexexam}
%   \ctexset{
%     chapter/format     = \sffamily\raggedright,
%     section/format    += \sffamily,
%     subsection/format += \fbox,
%   }
%   \end{ctexexam}
%
%   \opt{format} 选项的默认设置见表~\ref{tab:format-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \begin{threeparttable}
%     \caption{\opt{format} 选项的默认设置}
%     \label{tab:format-default}
%     \begin{tabular}{lll}
%     \toprule
%     标题名 & \opt{scheme = chinese} & \opt{scheme = plain} \\
%     \midrule
%     part (article) & |\Large\bfseries\centering| & |\raggedright|\tnote{*} \\
%     part (beamer) & 同右 & |\centering| \\
%     part & |\huge\bfseries\centering| & |\centering| \\
%     chapter & |\huge\bfseries\centering| & |\raggedright| \\
%     section (beamer) & 同右 & |\centering| \\
%     section & |\Large\bfseries\centering| & |\Large\bfseries| \\
%     subsection (beamer) & 同右 & |\centering| \\
%     subsection & 同右 & |\large\bfseries| \\
%     subsubsection & 同右 & |\normalsize\bfseries| \\
%     paragraph & 同右 & |\normalsize\bfseries| \\
%     subparagraph & 同右 & |\normalsize\bfseries| \\
%     \bottomrule
%     \end{tabular}
%     \begin{tablenotes}
%       \item[*] 为了与 \LaTeXe{} 的默认效果保持一致,在 \opt{scheme = plain}
%           时,part 和 chapter 的 \opt{nameformat} 和 \opt{titleformat}
%           并不一样,因此没有使用 \opt{format} 选项统一设置名字和标题的格式。
%     \end{tablenotes}
%   \end{threeparttable}
% \end{table}
%
% \begin{function}[EXP,updated=2015-06-30]{.../nameformat, .../nameformat+}
%   \begin{syntax}
%     nameformat = \Arg{格式命令}
%     nameformat+= \Arg{格式命令}
%   \end{syntax}
%   \opt{nameformat} 用于控制章节名字的格式,作用域为章节名字,包括编号。它一
%   般用于章节名(包括编号)与章节标题的字体、字号等设置不一致的情形。参见
%   下面的 \opt{titleformat} 选项。\opt{nameformat+} 用于在已有的章节名字
%   格式命令后附加内容。
%
%   \opt{nameformat} 选项的最后一个格式命令可以带有一个参数。
%   这一参数用于接受章节名字和编号,以实现特殊效果(见例~\ref{exam:miscopt})。
%
%   \opt{nameformat} 选项的默认设置见表~\ref{tab:nameformat-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{nameformat} 选项的默认设置}
%   \label{tab:nameformat-default}
%   \begin{tabular}{lll}
%   \toprule
%   标题名 & \opt{scheme = chinese} & \opt{scheme = plain} \\
%   \midrule
%   part (article) & |{}| & |\Large\bfseries| \\
%   part (beamer) & 同右
%     & \BSTACK |\usebeamerfont{part name}| \\
%               |\usebeamercolor[fg]{part name}| \ESTACK \\
%   part & |{}| & |\huge\bfseries| \\
%   chapter & |{}| & |\huge\bfseries| \\
%   section (beamer) & 同右
%     & \BSTACK |\usebeamerfont{section name}| \\
%               |\usebeamercolor[fg]{section name}| \ESTACK \\
%   section & 同右 & |{}| \\
%   subsection (beamer) & 同右
%     & \BSTACK |\usebeamerfont{subsection name}| \\
%               |\usebeamercolor[fg]{subsection name}| \ESTACK \\
%   subsection & 同右 & |{}| \\
%   subsubsection & 同右 & |{}| \\
%   paragraph & 同右 & |{}| \\
%   subparagraph & 同右 & |{}| \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \begin{function}[EXP,updated=2015-06-19]{.../numberformat, .../numberformat+}
%   \begin{syntax}
%     numberformat = \Arg{格式命令}
%     numberformat+= \Arg{格式命令}
%   \end{syntax}
%   \opt{numberformat} 选项用于控制章节编号的格式,作用域仅为编号数字本身。对
%   各级标题默认均为空,当需要编号的格式和前后的章节名字不一样时可以使用。
%   \opt{numberformat+} 用于在已有的编号格式命令后附加内容。
%
%   \opt{numberformat} 选项的最后一个格式命令可以带有一个参数。这一参数用于接受
%   编号数字。例如,我们可以使用 \opt{numberformat} 特别强调章标题中的数字:
%   \begin{ctexexam}
%   \ctexset{
%     chapter/number = \arabic{chapter},
%     chapter/numberformat = \color{blue}\zihao{0}\emph,
%   }
%   \end{ctexexam}
%   上面的代码在 \opt{scheme = chinese} 时可以做出类似这样的章标题效果:
%   \begin{center}
%     \huge\bfseries 第 \emph{\color{blue}\zihao{0}4} 章
%   \end{center}
%
%   \opt{numberformat} 选项默认均设置为空,故章节编号默认与章节名字使用
%   相同的格式。
% \end{function}
%
% \begin{function}[EXP,updated=2015-06-30]{.../titleformat, .../titleformat+}
%   \begin{syntax}
%     titleformat = \Arg{格式命令}
%     titleformat+= \Arg{格式命令}
%   \end{syntax}
%   \opt{titleformat} 选项用于控制标题内容的格式,作用域为章节标题内容。
%   \opt{titleformat+} 选项用于在已有的标题格式命令后附加内容。
%
%   \opt{titleformat} 选项的最后一个格式命令可以带有一个参数。这一参数用于接受
%   标题内容。例如,实现多行标题的居中悬挂对齐:
%   \begin{ctexexam}
%   \usepackage{varwidth} %% 提供 varwidth 环境
%   \ctexset{
%     chapter/name = {第,回},
%     chapter/titleformat = \chaptertitleformat
%   }
%   \newcommand\chaptertitleformat[1]{%% 以标题内容为参数
%     \begin{varwidth}[t]{.7\linewidth}#1\end{varwidth}}
%   ......
%   \chapter{情中情因情感妹妹\\错里错以错劝哥哥}
%   \end{ctexexam}
%   上面的代码可以做出类似这样的章标题效果:
%   \begin{center}\Large\bfseries
%   第三十四回\quad
%   \begin{tabular}[t]{l}
%     情中情因情感妹妹\\
%     错里错以错劝哥哥
%   \end{tabular}
%   \end{center}
%
%   \opt{titleformat} 选项的默认设置见表~\ref{tab:titleformat-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{titleformat} 选项的默认设置}
%   \label{tab:titleformat-default}
%   \begin{tabular}{lll}
%   \toprule
%   标题名 & \opt{scheme = chinese} & \opt{scheme = plain} \\
%   \midrule
%   part (article) & |{}| & |\huge\bfseries| \\
%   part (beamer) & 同右 & |\usebeamerfont{part title}| \\
%   part & |{}| & |\Huge\bfseries| \\
%   chapter & |{}| & |\Huge\bfseries| \\
%   section (beamer) & 同右 & |\usebeamerfont{section title}| \\
%   section & 同右 & |{}| \\
%   subsection (beamer) & 同右 & |\usebeamerfont{subsection title}| \\
%   subsection & 同右 & |{}| \\
%   subsubsection & 同右 & |{}| \\
%   paragraph & 同右 & |{}| \\
%   subparagraph & 同右 & |{}| \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \begin{function}[EXP,updated=2014-03-08]{.../aftername, .../aftername+}
%   \begin{syntax}
%   aftername = \Arg{代码}
%   aftername+= \Arg{代码}
%   \end{syntax}
%   \opt{aftername} 选项的参数 \meta{代码} 将被插入到章节编号与其后的标题内容之
%   间,用于控制格式变换。常用于控制章节编号与标题内容之间的距离,或者控制标题
%   是否另起一行。\opt{aftername+} 用于在已有的代码后附加内容。该选项的默认设置
%   见表~\ref{tab:aftername-default}。
% \end{function}
%
% \begin{function}[EXP,added=2015-06-19]{.../aftertitle, .../aftertitle+}
%   \begin{syntax}
%   aftertitle = \Arg{代码}
%   aftertitle+= \Arg{代码}
%   \end{syntax}
%   \opt{aftertitle} 选项的参数 \meta{代码} 将被插入到章节标题内容之后。
%   \opt{aftertitle+} 用于在已有的代码后附加内容。该选项的默认设置
%   见表~\ref{tab:aftertitle-default}。需注意,\opt{sub3section} 或
%   \opt{sub4section} 宏包选项(见 \ref{subs:options-heading}~节)会影响
%   \opt{aftertitle} 选项的默认值。
% \end{function}
%
% \begin{table}[htbp]
%   \setlength\leftskip{0pt plus 1 fil minus \marginparwidth}
%   \begin{minipage}[t]{.75\linewidth}
%     \small\centering
%     \caption{\opt{aftername} 选项的默认设置}
%     \label{tab:aftername-default}
%     \begin{tabular}{lll}
%     \toprule
%     标题名 & \opt{scheme = chinese} & \opt{scheme = plain} \\
%     \midrule
%     part (article) & |\quad| & |\par\nobreak| \\
%     part (beamer) & 同右 & |\vskip 1em \par| \\
%     part & 同右 & |\par\vskip 20pt| \\
%     chapter & |\quad| & |\par\nobreak\vskip 20pt| \\
%     section (beamer) & 同右 & |\vskip 1em \par| \\
%     section & 同右 & |\quad| \\
%     subsection (beamer) & 同右 & |\vskip 1em \par| \\
%     subsection & 同右 & |\quad| \\
%     subsubsection & 同右 & |\quad| \\
%     paragraph & 同右 & |\quad| \\
%     subparagraph & 同右 & |\quad| \\
%     \bottomrule
%     \end{tabular}
%   \end{minipage}\nobreak\quad
%   \begin{minipage}[t]{.42\linewidth}
%     \small\centering
%     \caption{\opt{aftertitle} 选项的默认设置}
%     \label{tab:aftertitle-default}
%     \begin{tabular}{p{\dimexpr .58\linewidth - 2\tabcolsep\relax}p{\dimexpr .4\linewidth - 2\tabcolsep\relax}}
%     \toprule
%     标题名 & 默认值 \\
%     \midrule
%     part & |\par| \\
%     chapter & |\par| \\
%     section & |\@@par| \\
%     subsection & |\@@par| \\
%     subsubsection & |\@@par| \\
%     paragraph & |{}| \\
%     \qquad(sub3section) & |\@@par| \\
%     \qquad(sub4section) & 同上 \\
%     subparagraph & |{}| \\
%     \qquad(sub4section) & |\@@par| \\
%     \bottomrule
%     \end{tabular}
%   \end{minipage}
% \end{table}
%
% \begin{function}[EXP,added=2014-03-21]{part/pagestyle, chapter/pagestyle}
%   \begin{syntax}
%     pagestyle = \Arg{页面格式}
%   \end{syntax}
%   设置 \cls{book}/\cls{ctexbook} 或 \cls{report}/\cls{ctexrep} 文档类
%   中,\tn{part} 与 \tn{chapter} 标题所在页的页面格式(page style)。
%   该选项的默认设置见表~\ref{tab:pagestyle-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{pagestyle} 选项的默认设置}
%   \label{tab:pagestyle-default}
%   \begin{tabular}{ll}
%   \toprule
%   标题名 & 默认值 \\
%   \midrule
%   part (article) & 无效 \\
%   part & |plain| \\
%   chapter & |plain| \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \subsection{间距、缩进相关}
% \label{subsec:sec-spacing}
%
% \begin{function}[EXP,added=2015-06-27]{section/runin, subsection/runin,
%   subsubsection/runin, paragraph/runin, subparagraph/runin}
%   \begin{syntax}
%   runin = \TF
%   \end{syntax}
%   \opt{runin} 选项只对 \tn{section} 级以下标题有意义,用于确定标题与随后的
%   正文是否排在同一段之上。该选项的默认设置见表~\ref{tab:runin-default}。
%
%   默认情况下,\tn{paragraph}、\tn{subparagraph} 两级标题是与后面正文排在同一
%   段的,\opt{runin} 选项为 \opt{true};但使用 \opt{sub3section} 或
%   \opt{sub4section} 宏包选项(见 \ref{subs:options-heading}~节)后,将对
%   这两级标题设 \opt{runin} 选项为 \opt{false},这两级标题会改为排在不同段。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{runin} 选项的默认设置}
%   \label{tab:runin-default}
%   \begin{tabular}{ll}
%   \toprule
%   标题名 & 默认值 \\
%   \midrule
%   part & 无效 \\
%   chapter & 无效 \\
%   section & |false| \\
%   subsection & |false| \\
%   subsubsection & |false| \\
%   paragraph & |true| \\
%   \qquad(sub3section) & |false| \\
%   \qquad(sub4section) & 同上 \\
%   subparagraph & |true| \\
%   \qquad(sub4section) & |false| \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \begin{function}[EXP,updated=2020-04-23]{.../hang}
%   \begin{syntax}
%   hang = \TF
%   \end{syntax}
%   \opt{hang} 选项用于设置是否对章节标题实施悬挂缩进(缩进的宽度为名字宽度
%   和 \opt{indent} 选项设置的宽度之和)。
%
%   注意,当 \opt{hang = true} 时,不恰当地设置选项 \opt{aftername} 的值,可能会引发
%   错误。这是因为当 \opt{hang = true} 时,\LaTeX{} 内部会构造一个 \tn{hbox} 而
%   进入受限水平模式(restricted horizontal mode)。若在 \opt{aftername} 中加入
%   包含 \tn{vskip} 等会导致从受限水平模式切出的垂直命令(vertical command)时,就会报错。
%   特别地,\opt{aftername} 的默认值也可能导致这种情形(见表~\ref{tab:aftername-default})。
%   因此,当设置 \opt{hang = true} 时,用户必须恰当地设置选项 \opt{aftername} 的值。
%
%   本选项对 \cls{beamer}/\cls{ctexbeamer} 文档类无效。
%   对于 \tn{section} 级以下标题,若设置了 \opt{runin} 选项为 \opt{true},
%   即标题与随后正文排在同一段,\opt{hang} 选项没有意义。
%   该选项的默认设置见表~\ref{tab:hang-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \begin{minipage}[t]{.5\linewidth}
%     \small\centering
%     \caption{\opt{hang} 选项的默认设置}
%     \label{tab:hang-default}
%     \begin{tabular}{ll}
%     \toprule
%     标题名 & 默认值 \\
%     \midrule
%     part & |false| \\
%     chapter & |false| \\
%     section & |true| \\
%     subsection & |true| \\
%     subsubsection & |true| \\
%     paragraph & 无意义 \\
%     \qquad(sub3section) & |true| \\
%     \qquad(sub4section) & |true| \\
%     subparagraph & 无意义 \\
%     \qquad(sub4section) & |true| \\
%     \bottomrule
%     \end{tabular}
%   \end{minipage}^^A
%   \begin{minipage}[t]{.5\linewidth}
%     \small\centering
%     \caption{\opt{indent} 选项的默认设置}
%     \label{tab:indent-default}
%     \begin{tabular}{ll}
%     \toprule
%     标题名 & 默认值 \\
%     \midrule
%     part & |0pt| \\
%     chapter & |0pt| \\
%     section & |0pt| \\
%     subsection & |0pt| \\
%     subsubsection & |0pt| \\
%     paragraph & |0pt| \\
%     subparagraph & |\parindent| \\
%     \qquad(sub3section) & |0pt| \\
%     \qquad(sub4section) & 同上 \\
%     \bottomrule
%     \end{tabular}
%   \end{minipage}
% \end{table}
%
% \begin{function}[EXP,updated=2020-04-23]{.../indent}
%   \begin{syntax}
%   indent = \Arg{缩进间距}
%   \end{syntax}
%   \opt{indent} 选项用于设置章节标题本身的首行缩进。
%   该选项的默认设置见表~\ref{tab:indent-default}。
%
%   如果 \opt{indent} 的值是以 \texttt{em}、\texttt{ex} 或 \cs{ccwd} 为单位,
%   那么缩进间距的大小是相对于 \opt{format} 中指定的字号大小。
%   例如,设置 \tn{part} 标题缩进三个字、\tn{section} 标题缩进 \SI{20}{pt}:
%   \begin{ctexexam}
%   \ctexset{
%     part = {
%       format += \raggedright,
%       indent  = 3\ccwd,
%     },
%     section = {
%       format  = \Large\bfseries,
%       indent  = 20pt,
%     }
%   }
%   \part{首行缩进的标题}
%   \noindent 无缩进的正文。
%   \section{首行缩进的标题}
%   \noindent 无缩进的正文。
%   \end{ctexexam}
% \end{function}
%
% \begin{function}[EXP,updated=2016-05-10]{.../beforeskip}
%   \begin{syntax}
%   beforeskip = \Arg{弹性间距}
%   \end{syntax}
%   \opt{beforeskip} 选项用于设置章节标题前的垂直间距。
%   该选项的默认设置见表~\ref{tab:beforeskip-default}。
% \end{function}
%
% \begin{function}[EXP,updated=2015-06-27]{.../afterskip}
%   \begin{syntax}
%   afterskip = \Arg{弹性间距}
%   \end{syntax}
%   \opt{afterskip} 选项控制章节标题与后面下方之间的距离。
%
%   对于 \tn{section} 级以下标题,\opt{runin} 选项会影响 \opt{afterskip} 选项的意义:
%   若 \opt{runin} 为 \opt{true},标题与随后正文排在同一段,\meta{弹性间距} 给出水平间距。
%   否则,正文另起一段,\meta{弹性间距} 给出的是垂直间距。
%
%   该选项的默认设置见表~\ref{tab:afterskip-default}。
%   注意 \opt{sub3section} 或 \opt{sub4section} 宏包选项(见
%   \ref{subs:options-heading}~节)会影响 \opt{aftertitle} 选项的默认值。
% \end{function}
%
% \begin{table}[htbp]
%   \setlength\leftskip{0pt plus 1 fil minus \marginparwidth}
%   \begin{minipage}[t]{.6\linewidth}
%     \small\centering
%     \caption{\opt{beforeskip} 选项的默认设置}
%     \label{tab:beforeskip-default}
%     \begin{tabular}{ll}
%     \toprule
%     标题名 & 默认值 \\
%     \midrule
%     part (article) & |4ex| \\
%     part (beamer) & |0pt| \\
%     part & |0pt plus 1fil| \\
%     chapter & |50pt| \\
%     section (beamer) & |0pt| \\
%     section & |3.5ex plus 1ex minus .2ex| \\
%     subsection (beamer) & |0pt| \\
%     subsection & |3.25ex plus 1ex minus .2ex| \\
%     subsubsection & |3.25ex plus 1ex minus .2ex| \\
%     paragraph & |3.25ex plus 1ex minus .2ex| \\
%     subparagraph & |3.25ex plus 1ex minus .2ex| \\
%     \bottomrule
%     \end{tabular}
%   \end{minipage}\nobreak\quad
%   \begin{minipage}[t]{.5\linewidth}
%     \small\centering
%     \caption{\opt{afterskip} 选项的默认设置}
%     \label{tab:afterskip-default}
%     \begin{tabular}{ll}
%     \toprule
%     标题名 & 默认值 \\
%     \midrule
%     part (article) & |3ex| \\
%     part (beamer) & |0pt| \\
%     part & |0pt plus 1fil| \\
%     chapter & |40pt| \\
%     section (beamer) & |0pt| \\
%     section & |2.3ex plus .2ex| \\
%     subsection (beamer) & |0pt| \\
%     subsection & |1.5ex plus .2ex| \\
%     subsubsection & |1.5ex plus .2ex| \\
%     paragraph & |1em| \\
%     \qquad(sub3section) & |1ex plus .2ex| \\
%     \qquad(sub4section) & 同上 \\
%     subparagraph & |1em| \\
%     \qquad(sub4section) & |1ex plus .2ex| \\
%     \bottomrule
%     \end{tabular}
%   \end{minipage}
% \end{table}
%
% \begin{function}[EXP,added=2016-06-03]{.../fixskip}
%   \begin{syntax}
%   fixskip = \TFF
%   \end{syntax}
%   默认情况下,\cls{article}、\cls{book} 和 \cls{report} 类的标题与正文的距离
%   除了由 \opt{beforeskip} 和 \opt{afterskip} 选项设置的垂直间距外,还会有
%   一些多余的间距。\opt{fixskip} 选项用于抑制这些多余间距。该选项默认不开启。
% \end{function}
%
% \begin{function}[EXP,added=2016-09-19]{.../break, .../break+}
%   \begin{syntax}
%     break = \Arg{格式命令}
%     break+= \Arg{格式命令}
%   \end{syntax}
%   \opt{break} 选项用于控制章节标题与\emph{之前}正文的分隔关系。
%   一般用于设置是否在标题之前分页或者设置行间罚点。
%   \opt{break+} 用于在已有的格式命令后附加内容。
%
%   例如,若当前页剩余高度小于正文高度的一半时,则另起一页输出
%   \tn{section} 标题:
%   \begin{ctexexam}
%   \usepackage{needspace}
%   \ctexset{section/break = \Needspace{.5\textheight}}
%   \end{ctexexam}
%
%   该选项的默认设置见表~\ref{tab:break-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{break} 选项的默认设置}
%   \label{tab:break-default}
%   \begin{tabular}{ll}
%   \toprule
%   标题名 & 默认值 \\
%   \midrule
%   part (article) & |{}| \\
%   part & |\if@openright\cleardoublepage\else\clearpage\fi| \\
%   chapter & 同上 \\
%   section & |\addpenalty{\@secpenalty}| \\
%   subsection & 同上 \\
%   subsubsection & 同上 \\
%   paragraph & 同上 \\
%   subparagraph & 同上 \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \begin{function}[EXP,added=2015-06-27]{.../afterindent}
%   \begin{syntax}
%   afterindent = \TF
%   \end{syntax}
%   \opt{afterindent} 选项用于设置章节标题后首段的缩进。
%
%   \cls{book} 和 \cls{report} 类的 \tn{part} 标题被单独排在一页之上,
%   \opt{afterindent} 选项没有意义。
%   对于 \tn{section} 级以下标题,若设置了 \opt{runin} 选项为 \opt{true},
%   即标题与随后正文排在同一段,\opt{afterindent} 选项也就没有了意义。
%
%   该选项的默认设置见表~\ref{tab:afterindent-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{afterindent} 选项的默认设置}
%   \label{tab:afterindent-default}
%   \begin{tabular}{lll}
%   \toprule
%   标题名 & \opt{scheme = chinese} & \opt{scheme = plain} \\
%   \midrule
%   part (article) & |true| & |false| \\
%   part & 无效 & 无效 \\
%   chapter & |true| & |false| \\
%   section & |true| & |false| \\
%   subsection & |true| & |false| \\
%   subsubsection & |true| & |false| \\
%   paragraph & |true| & |false| \\
%   subparagraph & |true| & |false| \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \subsection{目录、附录相关}
% \label{subsec:sec-toc-appendix}
%
% \begin{function}[EXP,added=2020-05-06]{tocdepth}
%   \begin{syntax}
%     tocdepth = <整数或章节名称>
%   \end{syntax}
%   设置对章节标题编入目录的层次数。\opt{tocdepth} 的值可以是一个整数,也可以是
%   |part|, |chapter| 等名称。
%   层次数与名称的对应关系见表~\ref{tab:heading-level}。
%   章节层次的默认设置见表~\ref{tab:heading-level-default}。
% \end{function}
%
% \begin{function}[EXP,added=2016-10-25]{.../tocline}
%   \begin{syntax}
%     tocline = \Arg{格式定义}
%   \end{syntax}
%   \opt{tocline} 选项用于定义章节标题在目录文件(\file{.toc})中的格式。
%   \meta{格式定义}有两个参数:参数 |#1| 是 |part|、|chapter| 等名字,
%   参数 |#2| 是标题内容。该选项的默认设置见表~\ref{tab:tocline-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{tocline} 选项的默认设置}
%   \label{tab:tocline-default}
%   \begin{tabular}{ll}
%   \toprule
%   标题名 & 默认值 \\
%   \midrule
%   part & |\CTEXifname{\CTEXthepart\hspace{1em}}{}#2| \\
%   chapter (\opt{chinese})
%     & |\CTEXifname{\protect\numberline{\CTEXthechapter\hspace{.3em}}}{}#2| \\
%   chapter (\opt{plain})
%     & |\CTEXnumberline{#1}#2| \\
%   section & |\CTEXnumberline{#1}#2| \\
%   subsection & 同上 \\
%   subsubsection & 同上 \\
%   paragraph & 同上 \\
%   subparagraph & 同上 \\
%   \bottomrule
%   \end{tabular}
%
%   \medskip
%   \raggedright
%   这里 \tn{CTEXnumberline} 的意义是,若标题 |#1| 没有名字,则不输出
%   |\numberline{\CTEXthe#1}| 等编号:
%   \begin{verbatim}
%     \CTEXifname{\protect\numberline{\csname CTEXthe#1\endcsname}}{}
%   \end{verbatim}
%   其中,\tn{CTEXifname} 的定义见 \ref{subsec:sec-commands}~小节。
% \end{table}
%
% \begin{function}[EXP,added=2016-10-01]{chapter/lofskip, chapter/lotskip}
%   \begin{syntax}
%   lofskip = \Arg{弹性间距}
%   lotskip = \Arg{弹性间距}
%   \end{syntax}
%   \opt{lofskip} 选项控制插图目录(\file{.lof})中,章之间的插图标题的距离。
%   同样,\opt{lotskip} 选项控制表格目录(\file{.lot})中,章之间的表格标题
%   的距离。
%
%   目前,这两个选项只在 \opt{chapter} 标题下有定义。
%   它们的默认值,在 \opt{scheme} 选项的不同取值下都为 \SI{10}{pt}。
% \end{function}
%
% \begin{function}[EXP,added=2015-06-21]{appendix/numbering}
%   \begin{syntax}
%     numbering = \TTF
%   \end{syntax}
%   控制是否对附录章(对应 \cls{book} 与 \cls{report})或附录节
%   (对应 \cls{article})进行编号,用法与普通章节对应的 \opt{numbering}
%   选项相同。该选项默认值为 \opt{true}。
% \end{function}
%
% \begin{function}[EXP,updated=2014-03-08]{appendix/name}
%   \begin{syntax}
%     name = \{<前名字>,<后名字>\}
%     name = \Arg{前名字}
%   \end{syntax}
%   设置附录章(对应 \cls{book} 与 \cls{report})或附录节(对应 \cls{article})
%   的名字,用法与普通章节对应的 \opt{name} 选项相同。
%
%   注意该选项与 \opt{appendixname} 选项(\ref{subs:capname}~节)在意义上有
%   些重叠,但不完全相同。\opt{appendixname} 选项只用来重定义
%   \tn{appendixname},而不管 \tn{appendixname} 如何使用;该选项则决定在章节
%   标题中输出的名字,可以调用 \tn{appendixname} 设置。
%
%   该选项的默认设置见表~\ref{tab:appendix-name-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{appendix/name} 选项的默认设置}
%   \label{tab:appendix-name-default}
%   \begin{tabular}{llllll}
%   \toprule
%   文档类 & 影响命令 & \opt{scheme = chinese} & 实际定义
%     & \opt{scheme = plain} & 实际定义 \\
%   \midrule
%   \cls{article} & \tn{section} & |{}| & & |{}| & \\
%   \cls{book}, \cls{report}
%       & \tn{chapter} & |\appendixname\space| & \verb*|附录 |
%       & |\appendixname\space| & \verb*|Appendix | \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \begin{function}[EXP]{appendix/number}
%   \begin{syntax}
%     number = \Arg{数字输出命令}
%   \end{syntax}
%   设置附录章(对 \cls{book} 与 \cls{report})或附录节(对 \cls{article})
%   编号的数字输出格式,用法与普通章节对应的 \opt{number} 选项相同。
%
%   \opt{appendix/number} 选项同时也会控制附录章节计数器的交叉引用。
%   与普通章节的 \opt{number} 选项类似,同样需要注意,该选项不会影响计数器本身
%   的输出,即不影响 \tn{thesection} 或 \tn{thechapter} 的定义。
%
%   该选项的默认设置见表~\ref{tab:appendix-number-default}。
% \end{function}
%
% \begin{table}[htbp]
%   \small\centering
%   \caption{\opt{appendix/number} 选项的默认设置}
%   \label{tab:appendix-number-default}
%   \begin{tabular}{llllll}
%   \toprule
%   文档类 & 影响命令 & 默认值 \\
%   \midrule
%   \cls{article} & \tn{section} & |\Alph{section}| \\
%   \cls{book}, \cls{report} & \tn{chapter} & |\Alph{chapter}| \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \subsection{辅助命令}
% \label{subsec:sec-commands}
%
% \CTeX{} 宏集还提供了一些辅助命令(宏),用于存储章节标题格式,或进行一些条件判断。
%
% \begin{function}{\CTEXthepart, \CTEXthechapter, \CTEXthesection,
%   \CTEXthesubsection, \CTEXthesubsubsection, \CTEXtheparagraph,
%   \CTEXthesubparagraph}
%   以 |\CTEXthe| 开头的这组宏给出结合了 \opt{name} 与 \opt{number} 选项的章节
%   编号输出格式。例如在 \opt{scheme = chinese} 时,默认章编号输出格式就是
%   \tn{CTEXthechapter},形如“第一章”。
%
%   这组宏在 \CTeX 文档类中将代替 \tn{thechapter} 等宏的作用,在章节中引用本章
%   节的完整编号。例如用于帮助定义自定义的目录格式、页眉格式等。
% \end{function}
%
% \begin{function}[added=2016-09-18]{\CTEXifname}
%   \begin{syntax}
%     \tn{CTEXifname} \Arg{有名字时的内容} \Arg{无名字时的内容}
%   \end{syntax}
%   \tn{CTEXifname} 会根据当前章节有无名字展开得到不同内容(通常是格式命令)。
%   由于章节名字总是与编号一起出现,章节有无名字通常也表达为“章节是否编号”。
%   在 \LaTeX{} 中,后者取决于以下几个方面:章节深度是否不大于计数器
%   |secnumdepth| 的值,章节标题是否使用不带星号的命令。在 \CTeX{} 宏集中,
%   后者还取决于 \opt{.../numbering} 是否为 \opt{true}。
%
%   \tn{CTEXifname} 可用于 \opt{format}, \opt{titleformat}, \opt{aftertitle},
%   \opt{afterskip}, \opt{indent} 这五个选项和 \tn{chapter} 标题
%   \opt{beforeskip} 选项的格式设置之中。也可用于帮助定义自定义的目录格式、
%   页眉格式等。
%
%   例如,设置章的标题有名字时左对齐,无名字时居中对齐,并且在标题后画一条横线。
%   \begin{ctexexam}
%   \ctexset{
%     chapter/format     = \CTEXifname{\raggedright}{\centering},
%     chapter/aftertitle = \par\CTEXifname{}{\hrule},
%   }
%   \end{ctexexam}
% \end{function}
%
% \subsection{示例}
%
% 我们最后举一个稍微复杂的例子,来看看上述选项的综合应用。
%
% \begin{ctexexam}[labelref=exam:miscopt]
%   \ctexset {
%     chapter = {
%       beforeskip = 0pt,
%       fixskip    = true,
%       format     = \Huge\bfseries,
%       nameformat = \rule{\linewidth}{1bp}\par\bigskip\hfill\chapternamebox,
%       number     = \arabic{chapter},
%       aftername  = \par\medskip,
%       aftertitle = \par\bigskip\nointerlineskip\rule{\linewidth}{2bp}\par
%     }
%   }
%   \newcommand\chapternamebox[1]{%
%     \parbox{\ccwd}{\linespread{1}\selectfont\centering #1}}
%   ......
%   \chapter{熟悉 \LaTeX}
% \end{ctexexam}
% 本例的设置效果大致如下:
% \begin{center}
% \begin{minipage}{.75\linewidth}\Large\bfseries
% \hrule height .5bp \relax
% \medskip
% \hfill\parbox{\ccwd}{\linespread{1}\selectfont\centering 第 1 章}
% \par\smallskip
% \noindent 熟悉 \LaTeX
% \medskip\hrule height 1bp \relax
% \end{minipage}
% \end{center}
%
% \section{实用命令}
% \label{sec:useful-commands}
% \subsection{字号与间距}
%
% \begin{function}[updated = 2014-03-08, label = ]{\zihao}
%   \begin{syntax}
%     \tn{zihao} \Arg{字号}
%   \end{syntax}
%   用于调整字号大小。其中 \meta{字号} 的有效值共有 16 个,如表 \ref{tab:zihao}
%   所示。使用 \tn{zihao} 命令调整字体大小时,西文字号大小会始终和中文字号保持一致。
% \end{function}
%
% \begin{table}[!htbp]
% \centering
% \def\ZH#1{\zihaopt{#1} & \zihao{#1}}
% \tabcolsep=1em
% \caption{中文字号}\label{tab:zihao}
% \begin{tabular}{>{\ttfamily}S[mode=text,detect-family,table-format=-1]
%                             S[table-format=2.1]S[table-format=2.5]l}
% \toprule
% {\meta{字号}} & {大小(bp)} & {大小(pt)} & 意义 \\
% \midrule
%  0   & 42   & \ZH{0}    初号    \\
% {−0} & 36   & \ZH{-0}   小初号  \\
%  1   & 26   & \ZH{1}    一号    \\
% -1   & 24   & \ZH{-1}   小一号  \\
%  2   & 22   & \ZH{2}    二号    \\
% -2   & 18   & \ZH{-2}   小二号  \\
%  3   & 16   & \ZH{3}    三号    \\
% -3   & 15   & \ZH{-3}   小三号  \\
%  4   & 14   & \ZH{4}    四号    \\
% -4   & 12   & \ZH{-4}   小四号  \\
%  5   & 10.5 & \ZH{5}    五号    \\
% -5   &  9   & \ZH{-5}   小五号  \\
%  6   &  7.5 & \ZH{6}    六号    \\
% -6   &  6.5 & \ZH{-6}   小六号  \\
%  7   &  5.5 & \ZH{7}    七号    \\
%  8   &  5   & \ZH{8}    八号    \\
% \bottomrule
% \end{tabular}
% \end{table}
%
% \begin{function}[updated=2014-03-28]{\ziju}
%   \begin{syntax}
%     \tn{ziju} \Arg{中文字符宽度的倍数}
%   \end{syntax}
%   用于调整相邻汉字之间的间距,即(在正常中文行文中)前一个汉字的右边缘与后一个汉字
%   的左边缘之间的距离。其中参数可以是任意浮点数值;而中文字符宽度指的是实际汉字的
%   宽度,不包含当前字距。
%
%   这个命令会影响 \tn{ccwd} 的值,但不会影响英文字距。
% \end{function}
%
% \begin{function}[updated=2014-03-27]{\ccwd}
%   当前汉字的字宽保存在长度寄存器 \tn{ccwd} 之中。汉字字宽是相邻两个汉字中心
%   之间的距离,包含字距在内。因此修改字距会间接修改字宽。
% \end{function}
%
% \subsection{中文数字转换}
%
% \CTeX{} 宏集的中文数字转换功能实际上是调用 \pkg{zhnumber} 宏包来完成。下面只
% 介绍一些基本的用法,更高级的用法可以查阅 \pkg{zhnumber} 宏包的文档。
%
% \begin{function}[updated=2016-05-01]{\chinese}
%   \begin{syntax}
%     \tn{chinese} \Arg{counter}
%     \tn{pagenumbering} \{chinese\}
%   \end{syntax}
%   \tn{chinese} 命令与 \tn{roman} 等命令的用法类似,作用在一个 \LaTeX{}
%   计数器上,将计数器的值以中文数字的形式输出。
% \end{function}
%
% \begin{function}[added=2014-03-08]{\zhnumber}
%   \begin{syntax}
%     \tn{zhnumber} \Arg{number}
%   \end{syntax}
%   以中文格式输出数字。这里的数字可以是整数、小数和分数。
% \end{function}
%
% \begin{function}[added=2014-03-08]{\zhdigits}
%   \begin{syntax}
%     \tn{zhdigits} \Arg{number}
%   \end{syntax}
%   将阿拉伯数字转换为中文数字串。
% \end{function}
%
% \begin{function}{\CTEXnumber}
%   \begin{syntax}
%     \tn{CTEXnumber} "\"<macro> \Arg{number}
%   \end{syntax}
%   |\|<macro> 必须是一个 \TeX{} 宏,不需预先定义。\tn{CTEXnumber} 通过
%   \tn{zhnumber} 将 \meta{number} 转为中文数字,最后将结果存储在 |\|<macro>
%   里。对 |\|<macro> 的定义是局部的,将它展开一次就可以得到转换结果。
% \end{function}
%
% 一般来说,并不需要使用 \tn{CTEXnumber},直接使用 \tn{zhnumber} 即可。但是,如果
% 在文档中需要多次使用同一个数字 \meta{number} 的中文形式,就可以先用
% \tn{CTEXnumber} 将结果保存起来备用,而不是每次使用时都用 \tn{zhnumber} 现场
% 转换一次。
%
% \begin{function}{\CTEXdigits}
%   \begin{syntax}
%     \tn{CTEXdigits} "\"<macro> \Arg{number}
%   \end{syntax}
%   \tn{CTEXdigits} 与 \tn{CTEXnumber} 类似,但其转换的结果是中文数字串,而不是
%   中文数字。
% \end{function}
%
% \subsection{杂项}
%
% \begin{function}{\CTeX}
% 用于显示 \CTeX 标志。
% \end{function}
%
% \section{\LuaLaTeX{} 下的中文支持方式}
% \label{sec:lualatex-chinese}
%
% 在 \LuaLaTeX{} 下,\CTeX{} 宏集依赖 \pkg{LuaTeX-ja} 宏包来完成中文支持。
% 该宏包是日本 \TeX{} 社区的北川弘典、前田一贵、八登崇之等人开发的,设计目的主要
% 是在 \LuaTeX{} 引擎下实现日本 p\TeX{} 引擎的(大部分)功能。它为了兼容 p\LaTeX
% 的使用习惯,对 \LaTeXe 的 \pkg{NFSS} 作了不少修改和扩充。这对于简体中文用户来说
% 不是必要的,因而 \CTeX{} 禁用了它在 \LaTeX{} 格式下的大部分设置,只保留了必要的
% 部分。同时修改了它的字体设置方式,使得相关命令与 \pkg{xeCJK} 宏包大致相同。
%
% 20150420 版以后的 \pkg{LuaTeX-ja} 宏包开始支持竖排,但 \CTeX{} 暂不支持竖排。
%
% \subsection{\LuaLaTeX{} 下替代字体的设置}
%
% \begin{function}[updated=2020-04-30]{AlternateFont}
%   \begin{syntax}
%     \tn{setCJKfamilyfont} \Arg{family} \Arg{base font name}
%     \  [
%     \    <base font features> ,
%     \    AlternateFont =
%     \      \{
%     \        \Arg{character range_1} \Arg{alternate font name_1} ,
%     \        \Arg{character range_2} \Arg{alternate font name_2} \Arg{alternate font features_2} ,
%     \        ......
%     \      \}
%     \  ]
%   \end{syntax}
%   在设置字体族 \meta{family} 的时候,同时设置该字体族在字符范围
%   \meta{character range_n} 内,对应字形的替代字体。
% \end{function}
%
% \begin{function}[added=2014-04-14]{CharRange}
%   \begin{syntax}
%     \tn{setCJKfamilyfont} \Arg{family} \Arg{alternate font name}
%     \  [
%     \    CharRange = \Arg{character range} ,
%     \    <alternate font features>
%     \  ]
%   \end{syntax}
%   只设置字体族 \meta{family} 在字符范围 \meta{character range} 内,对应字形的
%   替代字体。
% \end{function}
%
% 一个 \tn{setCJKfamilyfont} 里只能使用一次 \opt{CharRange} 或者
% \opt{AlternateFont},但可以将它们分开重叠使用。例如下面的方式是有效的。
%
% \begin{ctexexam}
%   \setCJKmainfont[AlternateFont={...}{...}, ...]{...}
%   \setCJKmainfont[CharRange={"4E00->"67FF,-2}, ...]{...}
%   \setCJKmainfont[CharRange={"6800->"9FFF}, ...]{...}
% \end{ctexexam}
%
% \begin{function}[EXP,added=2020-04-30]{declarecharrange}
%   \begin{syntax}
%     \tn{ctexset}
%     \  \{
%     \    declarecharrange =
%     \      \{
%     \        \Arg{name_1} \Arg{character range_1} ,
%     \        \Arg{name_2} \Arg{character range_2} ,
%     \        ...
%     \      \}
%     \  \}
%   \end{syntax}
%   预先声明字符范围。声明字符范围 \meta{name} 之后,它的名字 \meta{name} 可以
%   用在 \opt{AlternateFont} 和 \opt{CharRange} 选项的 \meta{character range}
%   之中,表示对应的字符范围。
% \end{function}
%
% 在声明字符范围 \meta{name} 的同时,还为 \tn{setCJKmainfont} 等字体设置命令定义
% 了选项 \meta{name},用于设置对应字符的替代字体:
% \begin{syntax}
%   \meta{name} = \Arg{alternate font name}
%   \meta{name} = \Arg{alternate font name} \Arg{alternate font features}
% \end{syntax}
% \meta{name} 选项可以与 \opt{AlternateFont} 共同使用,但不能与 \opt{CharRange}
% 一起使用。如果没有给 \meta{name} 设置值,则等价于设置 \opt{CharRange=\meta{name}},
% 即只设置 \meta{name} 对应的字符范围的替代字体。
%
% \begin{function}[EXP,added=2014-04-15]{clearalternatefont,resetalternatefont}
%   \begin{syntax}
%     \tn{ctexset}
%     \  \{
%     \    clearalternatefont = \Arg{family_1, family_2, ...} ,
%     \    resetalternatefont = \Arg{family_1, family_2, ...} ,
%     \    clearalternatefont ,
%     \    resetalternatefont
%     \  \}
%   \end{syntax}
%   清除与重置 CJK 字体族 \meta{family} 的替换字体设置。如果没有给定值,则作用于
%   当前 CJK 字体族。清除与重置操作总是全局的。
% \end{function}
%
% \section{\CTeX{} 宏集的配置文件}
%
% \CTeX{} 宏集提供了不同的配置文件,可以通过修改配置文件来改变 \CTeX{} 宏集的
% 默认行为。
%
% 在多数情况下,并不需要修改配置文件,\CTeX{} 宏集的默认设置已经能满足大多数用
% 户的需要。不恰当地修改 \CTeX{} 宏集的默认行为也可能导致同一文件在别处无法正
% 常编译或排版效果完全不同,因此修改应该慎重。
%
% 但在一些情况下,直接修改配置文件仍是必要的,例如:
% \begin{itemize}
% \item 系统没有安装默认设置的字体文件,无法编译。
% \item 需要经常编译来自其他系统的中文 \TeX{} 文件,但对方的操作系统或默认设置
% 与本机不同。
% \end{itemize}
%
% 与 \CTeX{} 宏集的源代码一样,配置文件采用 \LaTeXiii{} 的语法编写。
%
% \CTeX{} 宏集的配置文件随宏包其他文件一起安装在 \TeX{} 系统 TDS 目录树中,文
% 件后缀是 \file{.cfg}。为了避免本地配置文件内容因 \CTeX{} 宏集的更新而丢失,
% 不要直接修改系统 TDS 目录树中的配置文件,而应该将系统自带的配置文件复制到本
% 地的或用户私有的 TDS 目录树中修改,并运行 \bashcmd{texhash} 命令刷新文件名数据库。
%
% 例如对于 \TeX{} Live,系统自带的配置文件就在 \TeX{} Live 安装目录下的
% \path{texmf-dist/tex/latex/ctex/config/} 子目录下,可以修改它的副本,保存在
% 本地 TDS 树的 \path{texmf-local/tex/latex/ctex/} 目录下,或者用户 TDS 树的
% \path{~/texmf/tex/latex/ctex/} 目录下,作为本地/用户专有的
% 配置文件。复制配置文件后需要运行 |texhash| 命令使本地配置文件生效。
%
% \MiKTeX{} 的配置文件也保存在类似的目录结构中,\MiKTeX{} 管理的
% 几个 TDS 根目录可以在 \MiKTeX{} Options 设置项中查看到,这里不再赘述。
%
% 除了修改本地 \TeX{} 系统中的配置文件,对于特定文档,也可以将修改过的配置文件
% 保存在文档的工作目录下。此时配置文件就只对工作目录下的所有文档生效。
%
% \subsection{修改宏包默认选项}
%
% 配置文件 \file{ctexopts.cfg} 可以用来修改宏包的默认选项。随系统安装的配置文
% 件除了文件信息声明外没有实际的内容,但在注释中给出了一个简单的示例,只要取消
% 注释就可以生效。
%
% \begin{ctexexam}
%   % 系统自带 ctexopts.cfg 注释中的示例语句,固定默认字体集为 windows。
%   % 该设置可以用在安装了 Windows 字体的非 Windows 系统中。
%   \ctex_set:nn { option } { fontset = windows }
% \end{ctexexam}
% 如上例所示,宏包选项通常使用 \LaTeXiii{} 的 \cs{ctex_set:nn} 命令完成键值设置,
% 第一个参数是固定的子模块 |option|,第二个参数中是用户定义的新的默认宏包选项。
%
% \file{ctexopts.cfg} 中的设置将在 \CTeX{} 宏集的开始处,定义过宏包选项之后,
% \tn{ProcessKeysOptions} 命令之前生效。最好只使用此配置文件修改宏包默认选项。
%
% \subsection{宏包载入后的配置}
%
% 配置文件 \file{ctex.cfg} 将在宏包的末尾被载入生效。可以用它完成任意的设置,
% 或是覆盖已有的定义。随系统安装的配置文件除版本信息外没有实际内容,注意配置文
% 件中也使用 \LaTeXiii{} 语法。
%
% \begin{ctexexam}
%   % 简单的 ctex.cfg 内容示例。
%   % 修改默认的页面格式设置。
%   \pagestyle{plain}
% \end{ctexexam}
%
% \begin{ctexexam}
%   % 略复杂的 ctex.cfg 内容示例:禁止段末孤字成行。
%   % 在使用 XeTeX 编译时,打开 xeCJK 的 CheckSingle 选项。
%   \sys_if_engine_xetex:T
%     {
%       \xeCJKsetup { CheckSingle }
%     }
%   % 在使用 LuaTeX 编译时,设置 LuaTeX-ja 的 jcharwidowpenalty 参数。
%   \sys_if_engine_luatex:T
%     {
%       \ltjsetparameter { jcharwidowpenalty = 10000 }
%     }
% \end{ctexexam}
%
% \subsection{配置标题中文翻译}
%
% 由于 \CTeX{} 宏集需要同时支持 GBK 和 UTF-8 两种编码,因此对标题的中文翻译写
% 在两个配置文件当中:\file{ctex-name-gbk.cfg} 和 \file{ctex-name-utf8.cfg}。
% 两个文件的设置相同,只是编码不同。
%
% 为了同一文档在不同电脑上编译效果的一致性,通常不建议修改默认的中文翻译。
%
% \subsection{自定义字体集}
%
% \ref{subs:options-CJK-font}~节介绍的用于 |fontset| 选项的自定义字库文件,
% 类似于 \CTeX{} 宏集的配置文件,也应该与其他本地配置文件一起保存在本地
% \texttt{TDS} 目录树下,并可以配合 \file{ctexopts.cfg} 等配置文件使用。
%
% \section{对旧版本的兼容性}
%
% \subsection{\CTeX\ 0.8a 及以前的版本}
%
% 在 ctex-kit 项目成立之前,\CTeX 宏包的最后一个版本是 \CTeX\
% 0.8a(2007/05/06)。
%
% 第 2 版未考虑对这些很早版本的兼容性。
%
% \subsection{\CTeX\ 0.9--\CTeX\ 1.0d}
%
% 在 2009 年在 ctex-kit 项目成立后,新增了 \XeTeX{} 引擎的支持,并增加了不少控
% 制字体的命令和选项。
%
% 这里主要介绍新版本 \CTeX 宏包相对 1.02d 版本(2014/06/09)的兼容性。
%
% 第 2 版的 \CTeX 宏包已尽力保证对 1.0x 版本的兼容性,原有为 1.0x 编写的代码,
% 在第 2 版的 \CTeX 宏包下保证仍能编译,并且在大多数情况下保持编译效果不变。
%
% \CTeX 宏包在 0.8a 以前的版本支持以 \pkg{CCT} 作为底层中文支持方式,从 0.9 版
% 之后即不再推荐使用,只保留向后兼容。在 \CTeX 宏包第 2 版中则完全不再支持
% \pkg{CCT}。
%
% 下面这些是在旧版本 \CTeX 宏包中存在,而在新版本中已不建议使用的选项和命令,
% 在未来版本中可能会删去它们的支持。
%
% 在多数情况下它们的功能仍将保留,但也有部分选项命令功能已失效。
%
% \begin{function}{cs4size, c5size}
%   分别相当于 |zihao=-4| 和 |zihao=5|,过时选项。
% \end{function}
%
% \begin{function}{CCT, CCTfont}
% 相关选项已删除。
% \end{function}
%
% \begin{function}{indent, noindent}
% \opt{indent} 和 \opt{noindent} 什么也不做,过时选项。
%
% 在中文版式下,\pkg{ctex} 宏包的相关功能在与标准文档类及其衍生文档类联用时
% 默认打开。\CTeX{} 文档类的相关功能由章节标题的 \opt{afterindent} 选项的值
% 来确定。
% \end{function}
%
% \begin{function}[label = ]{zhmap, nozhmap}
% \opt{zhmap} 宏包选项增加了参数,扩充了功能,除了支持真假值参数外,还支持选择
% \pkg{zhmCJK} 作为底层中文处理宏包。(\ref{subs:options-CJK-font}~节)
%
% \opt{nozhmap} 选项相当于 |zhmap=false|。过时选项。
% \end{function}
%
% \begin{function}{winfonts, adobefonts, nofonts}
% 宏包选项 \opt{winfonts} 相当于 |fontset=windows|,\opt{adobefonts} 相当于
% |fontset=adobe|,\opt{nofonts} 相当于 |fontset=none|。这几个选项是过时选项,
% 对于新文档,应使用 \opt{fontset} 选项设置不同字体集。
%
% 另外,第 2 版 \CTeX 宏包的默认字体不再是 Windows 系统字体,而是根据检测到的
% 操作系统选择使用 Windows、Mac 的系统字体还是 Fandol 字体
% (\ref{subs:options-CJK-font}~节)。
% \end{function}
%
% \begin{function}[label = ]{punct, nopunct}
% 旧版本中宏包 \opt{punct} 选项没有参数,现在可以用参数设定标点风格
% (\ref{subs:options-type-style}~节)。原有无参形式的 \opt{punct} 选项相当
% 于 |punct=quanjiao|。
%
% 旧版宏包中 \opt{nopunct} 选项的效果大致相当于 |punct=plain|。过时选项,不推荐使用。
% \end{function}
%
% \begin{function}{cap, nocap}
% 原有的 \opt{cap} 和 \opt{nocap} 选项由新的 \opt{scheme} 选项代替。
% (\ref{subs:options-type-style}~节)
%
% \opt{cap} 选项相当于 |scheme = chinese|,\opt{nocap} 选项相当
% 于 |scheme = plain|。它们均已过时,仅因兼容性而保留。
% \end{function}
%
% \begin{function}[label = ]{space, nospace}
% 新版本宏包 \opt{space} 选项增加真假值参数。
% (\ref{subs:options-type-style}~节)
%
% \opt{nospace} 选项相当于 |space=false|,成为过时选项。
% \end{function}
%
% \begin{function}{fancyhdr}
% 新版本宏包中总是自动处理对 \pkg{fancyhdr} 宏包的兼容性,而由用户自己使用
% \tn{usepackage} 载入 \pkg{fancyhdr} 宏包。
%
% \opt{fancyhdr} 选项过时,因兼容性保留,功能是载入 \pkg{fancyhdr} 宏包。
% \end{function}
%
% \begin{function}{hyperref}
% 新版本宏包中总是自动处理对 \pkg{hyperref} 宏包的兼容性,而由用户自己使用
% \tn{usepackage} 载入 \pkg{hyperref} 宏包。
%
% \opt{hyperref} 选项过时,因兼容性保留,功能是在导言区末尾载入 \pkg{hyperref}
% 宏包。
% \end{function}
%
% \begin{function}{fntef}
% 旧版本的 \opt{fntef} 选项用于统一 \pkg{CCTfntef} 与 \pkg{CJKfntef} 的界面,
% 新版本 \CTeX{} 宏集不再支持 \pkg{CCT},也不再自动载入 \pkg{CJKfntef} 或
% \pkg{xeCJKfntef} 宏包,而仅在其末尾做适当格式调整。
%
% \opt{fntef} 选项过时,因兼容性保留,功能是根据引擎载入 \pkg{CJKfntef}
% (\pdfTeX{}) 或 \pkg{xeCJKfntef} (\XeTeX{}) 宏包。
% \end{function}
%
% \begin{function}{\CTEXunderdot, \CTEXunderline, \CTEXunderdblline,
%   \CTEXunderwave, \CTEXsout, \CTEXxout, CTEXfilltwosides}
% 在调用 \opt{fntef} 宏包选项的同时,旧版本 \CTeX{} 宏包由于需要支持 \pkg{CCT}
% 系统,会将以 |\CJK| 开头的 \tn{CJKunderline} 等宏换名为以 |\CTEX| 开头的
% \tn{CTEXunderline} 等宏。此功能在新版本的 \CTeX{} 宏集中已失去意义。此外,
% 在 \pdfTeX{} 引擎下,用于设置格式的 \tn{CJKunderdotbasesep} 等宏也被更名为
% \tn{CTEXunderdotbasesep} 等宏。
%
% 在新版本中,上述由 \opt{fntef} 衍生的相关命令和环境均被移除。
% \end{function}
%
% \begin{function}{\CTEXsetfont}
% 更新当前的中文字体信息,包括当前字距(\tn{ccwd})和段首缩进(\tn{parindent})。
% 一般来说,用户无需使用这个命令。
% \end{function}
%
% \begin{function}{\CTEXindent}
% 更新 \tn{ccwd} 宽度后设置 |\parindent=2\ccwd|。过时命令。
% \end{function}
%
% \begin{function}{\CTEXnoindent}
% 设置 |\parindent=0pt|。过时命令。
% \end{function}
%
% \begin{function}{\CTEXsetup}
% \begin{syntax}
%   \tn{CTEXsetup}\oarg{选项}\Arg{标题}
% \end{syntax}
% 相当于设置了
% \texttt{\tn{ctexset}\{ \meta{标题} = \Arg{选项} \}}。
% 过时命令。
% \end{function}
%
% \begin{function}{\CTEXoptions}
% \begin{syntax}
%   \tn{CTEXoptions}\oarg{选项}
% \end{syntax}
% 相当于设置了
% \texttt{\tn{ctexset}\Arg{选项}}。
% 过时命令。
% \end{function}
%
% \begin{function}{\Chinese}
% \begin{syntax}
%   \tn{Chinese}\Arg{counter}
% \end{syntax}
% 新版宏集中 \tn{chinese} 统一了旧版本中 \tn{chinese} 和 \tn{Chinese} 的功能。因此,
% 该命令已过时。
% \end{function}
%
% \begin{function}{captiondelimiter}
% 原为 \tn{CTEXoptions} 命令的选项,用于控制 \tn{caption} 编号后面的标点。此选
% 项已过时,并在新版本的 \CTeX 宏包中失效。
%
% 可以使用 \pkg{caption} 宏包的 \opt{labelsep} 选项来完成同样的功能。
% \begin{ctexexam}
%   % 代替 \CTEXoptions[captiondelimiter={:}]
%   \usepackage{caption}
%   \captionsetup{labelsep=colon}
% \end{ctexexam}
% \end{function}
%
% \subsection{\CTeX\ 1.02c 以后的 SVN 开发版}
%
% \CTeX 宏包在 1.02c 版本(2011/03/11)之后在 Google code 上的 SVN 开发版本,
% 内部版本号一直升到 1.11 版,但从未正式发布。SVN 开发版在 1.02c 版本的基础上
% 新增的功能在第 2 版中大多继承了过来,但新增的命令与选项都不再保持兼容。
%
% \CTeX 宏包第 2 版不保证对未发布的 SVN 开发版兼容。
%
% \subsection{\CTeX\ 2.2 之前的版本}
%
% \begin{function}{part/beforeskip, chapter/beforeskip, section/beforeskip,
%   subsection/beforeskip, subsubsection/beforeskip, paragraph/beforeskip,
%   subparagraph/beforeskip}
%   在 \CTeX\ 2.2 之前的版本中,\opt{beforeskip} 选项的符号还用于确定章节标题后
%   首段的缩进。当 \opt{beforeskip} 是负值时,章节标题后的第一段按英文文档的排版
%   习惯,没有首行缩进,否则保留首行缩进。
%
%   这一特性在 2.2 版和后续版本中不再保留,相应的功能通过新的 \opt{afterindent}
%   选项来设置。如果原先设置 \opt{beforeskip} 为负值,在新版本中需要改为正值,
%   并设置相应的 \opt{afterindent} 选项为 \opt{false}。
% \end{function}
%
% \begin{function}{section/afterskip, subsection/afterskip,
%   subsubsection/afterskip, paragraph/afterskip, subparagraph/afterskip}
%   在 \CTeX\ 2.2 之前的版本中,对于 \tn{section} 级以下标题,\opt{afterskip}
%   选项的符号用于确定标题与随后正文是否排在同一段。
%   如果是正值,则正文另起一段,否则标题与随后正文排在同一段,
%   \opt{afterskip} 的绝对值给出水平间距。
%
%   这一特性在 2.2 版和后续版本中不再保留,相应的功能通过新的 \opt{runin}
%   选项来设置。如果原先设置 \opt{afterskip} 为负值,在新版本中需要改为正值,
%   并设置相应的 \opt{runin} 选项为 \opt{true}。
% \end{function}
%
% \subsection{\CTeX\ 2.4.1 和 2.4.2}
%
% \begin{function}{part/fixbeforeskip, chapter/fixbeforeskip}
%   这两个选项已经被删除,相应功能由新的选项 \opt{fixskip} 提供。
% \end{function}
%
% \subsection{\CTeX\ 2.5 之前的版本}
%
% \CTeX\ 2.5 有一些比较大的变动。
%
% \begin{function}[label =]{UTF8, GBK}
%   (pdf)\LaTeX{} 格式下,文档编码初始值统一设置成 UTF-8。因此,仍旧使用 GBK
%   编码的文档,需要在文档类或宏包选项中显式指定 \opt{GBK}。
% \end{function}
%
% \begin{function}[label =]{\CTEXunderdot, \CTEXunderline, \CTEXunderdblline,
%   \CTEXunderwave, \CTEXsout, \CTEXxout, CTEXfilltwosides}
%   不再默认载入 \pkg{CJKfntef} 或 \pkg{xeCJKfntef} 宏包,同步移除有关命令
%   和环境。若需使用相关宏包,建议用户使用 \tn{usepackage} 命令主动载入。
% \end{function}
%
% \begin{function}[label =]{fntef}
%   作为兼容性保留,会视编译引擎载入相应宏包。
% \end{function}
%
% \begin{function}{windows}
%   不再支持 Windows XP 系统,默认要求 Windows 系统有微软雅黑字体。
%   建议 Windows XP 系统的用户及时更新操作系统。若一定要在 Windows XP 中使用,
%   请使用 2.5 以前的版本。
% \end{function}
%
% \begin{function}{windowsold, windowsnew}
%   过时字库选项,作为兼容性保留,功能是载入 \opt{windows} 字库。
% \end{function}
%
% \begin{function}{ubuntu}
%   改用思源(Noto CJK)和文鼎字库。该字库不再支持 \pdfLaTeX 编译。
% \end{function}
%
% \begin{function}[label =]{AlternateFont}
%   不再支持将替代字体的可选项放在字体名之前的方括号中,
%   新的语法是将可选项放在字体名之后的花括号之内。
% \end{function}
%
% 除了以上列出的选项以外,当用户使用 \CTeX{} 系列文档类,且使用 \LaTeX 或
% \upLaTeX 编译时,若用户没有在文档类选项中显式指定 |dvips|/|dvipdfmx|/|dvisvgm|
% 等驱动选项,则文档类指定默认驱动为 \dvipdfmx。
%
% \section{宏集依赖情况与手工安装方法}
% \label{sec:dep-ins}
%
% 本节介绍 \CTeX{} 宏集的依赖情况,并介绍手工编译安装的具体方法。
% 通常用户只需参照第 \ref{subsec:easy-ins}~节介绍的方法,使用发行版自带的包管理器安装
% 本宏集。
%
% \CTeX{} 宏集有两个源文件:\file{ctex.dtx}、\file{ctexpunct.spa}。
% 使用不同的编译方式时,\CTeX{} 依赖的宏包略有不同。在手工安装 \CTeX{} 宏集之前,请确保
% 你的 \TeX{} 发行版中已经正确安装了这些宏包。\CTeX{} 依赖宏包的详情叙述如下:
%
% \begin{itemize}
%   \item \pkg{expl3}、\pkg{xparse} 和 \pkg{l3keys2e} 宏包。它们属于 \pkg{l3kernel}
%   和 \pkg{l3packages} 宏集。
%   \item \pkg{indentfirst} 宏包,属于 \pkg{tools} 宏集。
%   \item \pkg{zhnumber} 宏包。
%   \item[\ding{229}] 以上是各种编译方式都必需的依赖项。
%   \item \pkg{CJK} 宏集。
%   \item \pkg{CJKpunct} 宏包。
%   \item \pkg{xCJK2uni} 宏包。
%   \item \pkg{zhmetrics} 宏包。
%   \item \pkg{zhmCJK} 宏包,它还依赖
%   \begin{itemize}
%     \item \pkg{iftex} 宏包。
%     \item \pkg{ltxcmds} 宏包。
%     \item \pkg{kvoptions} 宏包。
%     \item \pkg{kvsetkeys} 宏包。
%     \item \pkg{keyval} 宏包,\pkg{graphics} 宏集。
%   \end{itemize}
%   \item[\ding{229}] 以上是使用 \pdfLaTeX{} 或 \LaTeX{} + \dvipdfmx{} 的编译方式所需要
%   的依赖项,其中 \pkg{zhmCJK} 是可选的。
%   \item \pkg{xeCJK} 宏集,它还依赖
%   \begin{itemize}
%     \item \pkg{xtemplate} 宏包,它属于 \pkg{l3packages} 宏集。
%     \item \pkg{fontspec} 宏包。
%   \end{itemize}
%   \item[\ding{229}] 以上是使用 \XeLaTeX{} 编译时的依赖项。
%   \item \pkg{luatexja} 宏包,它还依赖
%   \begin{itemize}
%     \item \pkg{adobemapping} 宏包。
%     \item \pkg{luaotfload} 宏包,它还依赖 \pkg{lualibs} 宏包。
%     \item \pkg{luatexbase} 宏包,它还依赖 \pkg{ctablestack} 宏包。
%     \item \pkg{atbegshi} 宏包。
%     \item \pkg{etoolbox} 宏包。
%     \item \pkg{iftex} 宏包。
%     \item \pkg{infwarerr} 宏包。
%     \item \pkg{ltxcmds} 宏包。
%     \item \pkg{pdftexcmds} 宏包。
%     \item \pkg{xkeyval} 宏包。
%     \item \pkg{chinese-jfm} 宏包。
%   \end{itemize}
%   \item \pkg{fontspec} 宏包。
%   \item[\ding{229}] 以上是使用 \LuaLaTeX{} 编译时的依赖项。
%   \item \pkg{zhmetrics-uptex} 宏包。
%   \item[\ding{229}] 以上是使用 \upLaTeX{} 编译时的依赖项。
% \end{itemize}
%
% 出于一些原因,\pkg{zhmCJK} 尚未被收入 \TeXLive{} 和 \MiKTeX。因此,若
% 你希望使用 \pkg{zhmCJK} 作为 \CTeX{} 宏集的底层中文支持方式,那么你需要自行安装该宏包。
% \pkg{zhmCJK} 的安装较为复杂。我们建议你
% \begin{enumerate}
%   \item 从 CTAN 下载 \pkg{zhmCJK} 宏包的
%   \href{http://mirrors.ctan.org/install/language/chinese/zhmcjk.tds.zip}
%   {TDS 安装包},
%   \item 按目录结构将文件复制到 \TeX{} 发行版的本地 TDS 根目录,
%   \item 最后执行 \bashcmd{texhash} 刷新 \TeX{} 发行版的 ls-R 数据库以完成安装。
% \end{enumerate}
% 其他细节,可参照其
% \href{http://mirrors.ctan.org/language/chinese/zhmcjk/zhmCJK.pdf}{宏包手册}
% 中第 3 节的指导。
%
% \emph{\CTeX{} 宏集已被 \TeXLive{} 和 \MiKTeX{} 收录,若无特别理由,
% 我们强烈建议用户使用包管理器安装本宏集。}
%
% 若要手工安装,请遵循如下步骤:
% \begin{enumerate}
%   \item 从 CTAN 下载 \CTeX{} 宏集的
%   \href{http://mirrors.ctan.org/install/language/chinese/ctex.tds.zip}
%   {TDS 安装包},
%   \item 按目录结构将文件复制到 \TeX{} 发行版的本地 TDS 根目录,
%   \item 最后执行 \bashcmd{texhash} 刷新 \TeX{} 发行版的 ls-R 数据库以完成安装。
% \end{enumerate}
%
% \section{开发人员}
%
% \begin{itemize}
% \item 吴凌云 (\email{aloft@ctex.org})
% \item 江疆 (\email{gzjjgod@gmail.com})
% \item 王越 (\email{yuleopen@gmail.com})
% \item 刘海洋 (\email{LeoLiu.PKU@gmail.com})
% \item 李延瑞 (\email{LiYanrui.m2@gmail.com})
% \item 陈之初 (\email{zhichu.chen@gmail.com})
% \item 李清 (\email{sobenlee@gmail.com})
% \item 黄晨成 (\email{liamhuang0205@gmail.com})
% \item 曾祥东 (\email{xdzeng96@gmail.com})
% \item 李泽平 (\email{zepinglee@gmail.com})
% \item 周宇恺 (\email{muzimuzhi@gmail.com})
% \item 张瑞熹 (\email{ruixizhang42@gmail.com})
% \end{itemize}
%
%
%
% \begin{thebibliography}{9}
% \bibitem{knuthtex1986}
% \textsc{Donald~Ervin Knuth}.
% \newblock \textit{The {{\TeX{}book}}}, \textit{Computers \& Typesetting},
%   volume~A.
% \newblock Addison-Wesley, 1986
%
% \bibitem{mittelbach2004}
% \textsc{Frank Mittelbach} and \textsc{Michel Goossens}.
% \newblock \textit{The {{\LaTeX}} Companion}.
% \newblock Tools and Techniques for Computer Typesetting. Boston:
%   Addison-Wesley, second edition, 2004
%
% \end{thebibliography}
%
% \end{documentation}
%
%
% \StopEventually{}
%
%
%\begin{implementation}
% \clearpage
% \section{代码实现}
%
%    \begin{macrocode}
%<@@=ctex>
%    \end{macrocode}
%
% \changes{v2.5.9}{2022/05/27}{设置消息模块的名字和类型。}
%
%    \begin{macrocode}
%<*class|style>
\RequirePackage { xparse , l3keys2e }
%<class>\prop_gput:Nnn \g_msg_module_type_prop { ctex } { Class }
%<article>\prop_gput:Nnn \g_msg_module_name_prop { ctex } { ctexart }
%<book>\prop_gput:Nnn \g_msg_module_name_prop { ctex } { ctexbook }
%<report>\prop_gput:Nnn \g_msg_module_name_prop { ctex } { ctexrep }
%<beamer>\prop_gput:Nnn \g_msg_module_name_prop { ctex } { ctexbeamer }
%<ctexsize>\prop_gput:Nnn \g_msg_module_name_prop { ctex } { ctexsize }
%<ctexheading>\prop_gput:Nnn \g_msg_module_name_prop { ctex } { ctexheading }
%</class|style>
%    \end{macrocode}
%
%    \begin{macrocode}
%<*class|ctex>
%    \end{macrocode}
%
% \changes{v2.3}{2015/12/20}{与 \LaTeXiii{} (2015/12/20) 同步。}
% \changes{v2.4.10}{2017/07/19}{常数 \cs{c_minus_one} 已过时。}
% \changes{v2.4.10}{2017/07/22}{使用 \texttt{lazy} 函数对 Boolean 表达式
% 进行最小化运算(\LaTeXiii{} 2017/07/19)。}
%
% 检查 \pkg{expl3} 和 \pkg{l3keys2e} 的版本。
%    \begin{macrocode}
\msg_new:nnnn { ctex } { l3-too-old }
  { Support~package~`#1'~too~old. }
  {
    Please~update~an~up-to-date~version~of~the~bundles\\\\
    `l3kernel'~and~`l3packages'\\\\
    using~your~TeX~package~manager~or~from~CTAN.
  }
\@ifpackagelater { expl3 } { 2020/07/17 } { }
  { \msg_error:nnn { ctex } { l3-too-old } { expl3 } }
%<*class>
\@ifpackagelater { l3keys2e } { 2015/12/20 } { }
  { \msg_error:nnn { ctex } { l3-too-old } { l3keys2e } }
%</class>
%    \end{macrocode}
%
% \begin{variable}{\c_@@_engine_str,\c_@@_engine_file_str}
% 引擎检查。目前 \LaTeXiii{} 将 \ApTeX{} 识别为 \upTeX。
%    \begin{macrocode}
\str_const:Nx \c_@@_engine_str
  { \cs_if_exist:NTF \ngostype { aptex } { \c_sys_engine_str } }
\msg_new:nnnn { ctex } { engine-not-supported }
  { Engine~`#1'~is~not~yet~supported,~ctex~will~abort! }
  { You~can~switch~to~xelatex,~lualatex,~pdflatex,~uplatex,~or~aplatex. }
\file_if_exist:nTF { ctex-engine- \c_@@_engine_str .def }
  {
    \str_const:Nx \c_@@_engine_file_str
      { ctex-engine- \c_@@_engine_str .def }
  }
  { \msg_critical:nnx { ctex } { engine-not-supported } { \c_@@_engine_str } }
%    \end{macrocode}
% \end{variable}
%
%    \begin{macrocode}
%</class|ctex>
%    \end{macrocode}
%
% \changes{v2.5}{2020/04/19}
%   {处理 \cs{ctex_file_input:n} 在 \pkg{ctexsize} 中未定义的错误。}
% \changes{v2.5}{2020/04/21}{在 \pkg{ctexsize} 也载入 \pkg{fix-cm}。}
%
%    \begin{macrocode}
%<*class|ctex|ctexheading|ctexsize>
%    \end{macrocode}
%
% \pkg{ctexsize} 也要载入 \pkg{fix-cm} 包解决传统 cm 字体字号缺失的问题。
%    \begin{macrocode}
%<!ctexsize>\RequirePackage { ctexhook , ctexpatch }
%<!ctexheading>\RequirePackage { fix-cm }
%    \end{macrocode}
%
% 宏包载入检查。
%    \begin{macrocode}
%<*class|ctex>
%<*class>
\ctex_disable_package:n { ctex }
\ctex_disable_package:n { ctexcap }
%</class>
\ctex_disable_package:n { ctexsize }
\ctex_disable_package:n { ctexheading }
%</class|ctex>
%    \end{macrocode}
%
% \changes{v2.5.7}{2021/06/04}{兼容 \LaTeX \ 2021/06/01 的字体钩子。}
%
% \begin{variable}{\c_@@_everysel_loaded_bool}
% \LaTeX \ 2021-06-01 以后的版本内建了 \pkg{everysel} 包的功能。
%    \begin{macrocode}
%<*!ctexsize>
%<*!ctexheading>
\ctex_if_format_at_least:nTF { 2021/06/01 }
  { \bool_const:Nn \c_@@_everysel_loaded_bool { \c_false_bool } }
  {
    \RequirePackage { everysel }
    \bool_const:Nn \c_@@_everysel_loaded_bool { \c_true_bool }
  }
%</!ctexheading>
%    \end{macrocode}
% \end{variable}
%
% \subsection{内部函数与变量}
%
% \begin{variable}{\l_@@_tmp_tl,\l_@@_tmp_int,\l_@@_tmp_box,\l_@@_tmp_dim}
% 临时变量。
%    \begin{macrocode}
\tl_clear_new:N \l_@@_tmp_tl
\int_new:N \l_@@_tmp_int
\box_new:N \l_@@_tmp_box
%<!ctexheading>\dim_new:N \l_@@_tmp_dim
%    \end{macrocode}
% \end{variable}
%
% \begin{macro}[int]{\ctex_define_option:n,
% \ctex_define:n,\ctex_set:n,\ctex_set:nn}
% 在宏包内部使用的键值选项定义、设置命令。
%    \begin{macrocode}
%</!ctexsize>
\cs_new_protected:Npn \ctex_define_option:n
  { \keys_define:nn { ctex / option } }
%<*!ctexsize>
\cs_new_protected:Npn \ctex_define:n
  { \keys_define:nn { ctex } }
\cs_new_protected:Npn \ctex_set:n
  { \keys_set:nn { ctex } }
\cs_new_protected:Npn \ctex_set:nn #1
  { \keys_set:nn { ctex / #1 } }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5.3}{2020/06/06}{正确关闭和恢复 \LaTeXiii 语法环境。}
% \changes{v2.5.4}{2020/08/02}{应用 \pkg{l3cctab}。}
% \changes{v2.5.5}{2020/10/17}{放弃应用 \pkg{l3cctab}。}
%
% \begin{macro}[int]{\ctex_scheme_input:n}
% 输入 \opt{scheme} 文件。先查找当前文档类下的 \meta{scheme},找不到再查找一般的文件。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_scheme_input:n #1
  {
    \ctex_push_file:
      \tl_if_exist:NTF \c_@@_class_tl
        {
          \file_if_exist_input:nF { ctex-scheme- #1 - \c_@@_class_tl .def }
            { \file_input:n  { ctex-scheme- #1 .def } }
        }
        { \file_input:n  { ctex-scheme- #1 .def } }
    \ctex_pop_file:
  }
\cs_generate_variant:Nn \ctex_scheme_input:n { o }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}{\g_@@_section_depth_int}
% 若大于 |3|,则 \tn{paragraph} 和 \tn{subparagraph} 标题单独占一行;若为 |3|,则
% \tn{paragraph} 单独占一行。
%    \begin{macrocode}
%<*!beamer>
\int_new:N \g_@@_section_depth_int
\int_gset:Nn \g_@@_section_depth_int { 2 }
%</!beamer>
%    \end{macrocode}
% \end{variable}
%
%    \begin{macrocode}
%</!ctexsize>
%</class|ctex|ctexheading|ctexsize>
%<*class|ctex>
%    \end{macrocode}
%
% 对旧版本的宏包给出错误信息。
%    \begin{macrocode}
\msg_new:nnnn { ctex } { package-too-old }
  { Support~package~`#1'~too~old. }
  {
    Please~update~an~up-to-date~version~of~the~package~`#1'\\
    using~your~TeX~package~manager~or~from~CTAN.
  }
%    \end{macrocode}
%
% \changes{v2.1}{2015/05/25}{不依赖 \pkg{ifpdf} 宏包。}
%
% \begin{macro}[int]{\ifctexpdf}
% 在 \pkg{zhmetrics} 映射文件中使用。
%    \begin{macrocode}
\sys_if_output_pdf:TF
  { \cs_new_eq:NN \ifctexpdf \if_true: }
  { \cs_new_eq:NN \ifctexpdf \if_false: }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_if_preamble:TF}
% 测试是否在 \LaTeXe{} 的导言区。在宏包内部初始为真,文档最开始位置再设置为假。
% 注意,钩子 \cs{ctex_after_end_preamble:n} 在 \tn{AtBeginDocument} 之后执行,
% 可以与 \tn{@onlypreamble} 的行为一致。
%    \begin{macrocode}
\cs_new_eq:NN \ctex_if_preamble:TF \use_i:nn
\ctex_after_end_preamble:n { \cs_set_eq:NN \ctex_if_preamble:TF \use_ii:nn }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.3}{2015/09/17}{代码实现避免使用 \tn{lowercase} 技巧(Joseph Wright)。}
%
% \changes{v2.4.16}{2019/05/11}{允许设置 \texttt{autoindent} 为 $0$。}
%
% \begin{macro}[int]{\ctex_set_default_ccwd:Nn}
% 若参数 |#2| 带长度单位,则设置它为 |tl| 变量 |#1| 的值,否则以 \tn{ccwd} 为单位。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_set_default_ccwd:Nn #1#2
  { \tl_set:Nx #1 { \@@_default_ccwd_aux:n {#2} } }
\cs_new:Npn \@@_default_ccwd_aux:n #1
  {
    \exp_not:n {#1}
    \exp_after:wN \@@_default_ccwd_aux:w
      \dim_use:N \tex_dimexpr:D #1 pt \scan_stop: \q_stop
  }
\exp_last_unbraced:NNNNo
  \cs_new:Npn \@@_default_ccwd_aux:w #1 { \tl_to_str:n { pt } } #2 \q_stop
    { \tl_if_empty:nT {#2} { \ccwd } }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}{\g_@@_encoding_tl}
% 所有引擎下默认编码均设为 UTF-8,初始值为空,\tn{ProcessKeysOptions} 再判断。
%    \begin{macrocode}
\tl_new:N \g_@@_encoding_tl
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\g_@@_zhmCJK_bool}
% 是否使用 \pkg{zhmCJK} 宏包。
%    \begin{macrocode}
\bool_new:N \g_@@_zhmCJK_bool
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_autoindent_tl}
% 保存 \opt{autoindent} 选项的值,空值表示不自动调整首行缩进。
%    \begin{macrocode}
\tl_new:N \l_@@_autoindent_tl
%    \end{macrocode}
% \end{variable}
%
% \begin{macro}[int]{\ctex_if_autoindent_touched:F}
% 检查 \opt{autoindent} 选项是否被用户设置。
%    \begin{macrocode}
\cs_new_eq:NN \ctex_if_autoindent_touched:F \use:n
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_zhmap_case:nnn}
% 参数 |#1| 是 \pkg{zhmCJK} 的内容,|#2| 是 \pkg{zhmetrics}。
%    \begin{macrocode}
\cs_new_eq:NN \ctex_zhmap_case:nnn \use_ii:nnn
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_at_end:n}
% 区分 \tn{AtEndOfClass} 和 \tn{AtEndOfPackage},虽然它们的意思都是一样的。
%    \begin{macrocode}
%<class>\cs_new_protected:Npn \ctex_at_end:n { \AtEndOfClass }
%<ctex>\cs_new_protected:Npn \ctex_at_end:n { \AtEndOfPackage }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}{\g_@@_std_options_clist}
% 保存传递给标准文档类的选项。
%    \begin{macrocode}
%<*class>
\clist_new:N \g_@@_std_options_clist
%</class>
%    \end{macrocode}
% \end{variable}
%
% 对无效选项给出警告。
%    \begin{macrocode}
\msg_new:nnn { ctex } { invalid-option }
  { Option~`\l_keys_key_tl'~is~invalid~in~current~mode. }
\msg_new:nnn { ctex } { invalid-value }
  { Value~`#1'~is~invalid~for~the~key~`\l_keys_key_tl'. }
%    \end{macrocode}
%
% \begin{macro}[int]{\ctex_deprecated_option:nn,
% \ctex_set_deprecated_option:n,\ctex_deprecated_command:Nn}
% 对过时选项或命令给出警告。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_deprecated_option:n
  { \msg_warning:nnn { ctex } { deprecated-option } }
\cs_new_protected:Npn \ctex_set_deprecated_option:n #1
  {
    \ctex_deprecated_option:n { Option~`#1'~is~set. }
    \ctex_set:nn { option } {#1}
  }
\cs_new_protected:Npn \ctex_deprecated_command:Nn #1#2
  {
    \msg_warning:nnxx { ctex } { deprecated-command }
      { \token_to_str:N #1 } { \exp_not:n {#2} }
  }
\msg_new:nnn { ctex } { deprecated-option }
  { Option~`\l_keys_key_tl'~is~deprecated.\\ #1 }
\msg_new:nnn { ctex } { deprecated-command }
  { Command~`#1'~is~deprecated.\\ #2 }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</class|ctex>
%    \end{macrocode}
%
% \begin{variable}{\g_@@_font_size_int}
% |0| 表示修改默认字体大小为五号,|1| 为小四号,大于 1 则不作修改。初始值 |-1|
% 表示 \opt{zihao} 选项未初始化,会在将来根据文档类决定初值。
%    \begin{macrocode}
%<*class|ctex|ctexsize>
\int_new:N \g_@@_font_size_int
\int_gset:Nn \g_@@_font_size_int { -1 }
%</class|ctex|ctexsize>
%    \end{macrocode}
% \end{variable}
%
% \subsection{宏包选项}
%
% \changes{v2.3}{2015/09/25}
%   {\texttt{.value_required:} 和 \texttt{.value_forbidden:} 已过时。}
%
%   \begin{macrocode}
%<*class|style>
\ctex_define_option:n
  {
%</class|style>
%    \end{macrocode}
%
% \changes{v2.0}{2015/05/06}{新增 \opt{zihao} 选项。}
% \changes{v2.0}{2015/05/06}{\opt{c5size}, \opt{cs4size} 是过时选项。}
%
% \begin{macro}{zihao}
% \changes{v2.4.1}{2016/05/13}{不允许无参 \opt{zihao} 选项。}
%    \begin{macrocode}
%<*class|ctex|ctexsize>
    zihao .choice: ,
    zihao .value_required:n = true ,
    zihao /     5  .code:n = { \int_gset:Nn \g_@@_font_size_int { 0 } } ,
    zihao /    -4  .code:n = { \int_gset:Nn \g_@@_font_size_int { 1 } } ,
    zihao / false  .code:n = { \int_gset:Nn \g_@@_font_size_int { 2 } } ,
%<ctexsize>  }
%</class|ctex|ctexsize>
%<*class|ctex>
    c5size  .code:n = { \ctex_set_deprecated_option:n { zihao =  5 } } ,
    cs4size .code:n = { \ctex_set_deprecated_option:n { zihao = -4 } } ,
    c5size  .value_forbidden:n = true ,
    cs4size .value_forbidden:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2014/04/23}{新增 \opt{linespread} 选项。}
%
% \begin{macro}{linespread}
% 行距初始值为标志 \texttt{nan},用于检查用户是否设置了 \opt{linespread} 选项。
%    \begin{macrocode}
    linespread  .fp_set:N = \l_@@_line_spread_fp ,
    linespread .initial:n = { \c_nan_fp } ,
    linespread .value_required:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2014/03/13}{新增 \opt{autoindent} 选项。}
%
% \begin{macro}{autoindent}
% 自动调整段落的首行缩进功能。
%    \begin{macrocode}
    autoindent .choice: ,
    autoindent .default:n = { true } ,
    autoindent / true    .code:n =
      {
        \tl_set:Nn \l_@@_autoindent_tl { 2 \ccwd }
        \cs_set_eq:NN \ctex_if_autoindent_touched:F \use_none:n
      } ,
    autoindent / false   .code:n =
      {
        \tl_clear:N \l_@@_autoindent_tl
        \cs_set_eq:NN \ctex_if_autoindent_touched:F \use_none:n
      } ,
    autoindent / unknown .code:n =
      {
        \ctex_set_default_ccwd:Nn \l_@@_autoindent_tl {#1}
        \cs_set_eq:NN \ctex_if_autoindent_touched:F \use_none:n
      } ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2015/03/21}{\opt{indent}, \opt{noindent} 是过时选项。}
% \begin{macro}{indent}
% 仅为兼容性保留,已过时。
%    \begin{macrocode}
    indent .code:n =
      {
        \ctex_deprecated_option:n
          {
            The~functionality~has~been~removed.\\
            It's~better~to~set~the~heading~styles~via~`afterindent'~option.
          }
      } ,
    indent .value_forbidden:n = true ,
    noindent .code:n =
      {
        \ctex_deprecated_option:n
          {
            The~functionality~has~been~removed.\\
            It's~better~to~set~the~heading~styles~via~`afterindent'~option.
          }
      } ,
    noindent .value_forbidden:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5}{2019/11/10}{所有引擎下默认编码均设为 UTF-8。}
%
% \begin{macro}{GBK,UTF8}
% 文档编码,默认为 UTF-8。
%   \begin{macrocode}
    GBK  .code:n =
      {
        \sys_if_engine_pdftex:TF
          { \tl_gset:Nn \g_@@_encoding_tl { GBK } }
          {
            \msg_warning:nn { ctex } { invalid-option }
            \tl_gset:Nn \g_@@_encoding_tl { UTF8 }
          }
      } ,
    UTF8 .code:n = { \tl_gset:Nn \g_@@_encoding_tl { UTF8 } } ,
    GBK  .value_forbidden:n = true ,
    UTF8 .value_forbidden:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2014/03/08}{新增 \opt{fontset} 选项。}
% \changes{v2.0}{2015/03/21}{\opt{nofonts}, \opt{adobefonts}, \opt{winfonts}
% 是过时选项。}
%
% \begin{macro}{fontset}
% 初始值为空。若用户未指定,则根据操作系统载入对应字体配置,可以区分 Windows、
% macOS 和其他。
%   \begin{macrocode}
    fontset    .tl_gset:N = \g_@@_fontset_tl ,
    nofonts    .code:n = { \ctex_set_deprecated_option:n { fontset = none } } ,
    adobefonts .code:n = { \ctex_set_deprecated_option:n { fontset = adobe } } ,
    winfonts   .code:n = { \ctex_set_deprecated_option:n { fontset = windows } } ,
    nofonts    .value_forbidden:n = true ,
    winfonts   .value_forbidden:n = true ,
    adobefonts .value_forbidden:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2014/03/08}{新增 \opt{zhmCJK} 支持选项。}
% \changes{v2.0}{2015/03/22}{\opt{nozhmap} 是过时选项。}
%
% \begin{macro}{zhmap}
%   \begin{macrocode}
    zhmap .choice: ,
    zhmap .default:n = { true } ,
    zhmap / zhmCJK .code:n =
      {
        \bool_gset_true:N \g_@@_zhmCJK_bool
        \cs_gset_eq:NN \ctex_zhmap_case:nnn \use_i:nnn
      } ,
    zhmap / true   .code:n =
      {
        \bool_gset_false:N \g_@@_zhmCJK_bool
        \cs_gset_eq:NN \ctex_zhmap_case:nnn \use_ii:nnn
      } ,
    zhmap / false  .code:n =
      {
        \bool_gset_false:N \g_@@_zhmCJK_bool
        \cs_gset_eq:NN \ctex_zhmap_case:nnn \use_iii:nnn
      } ,
    nozhmap   .code:n =
      { \ctex_set_deprecated_option:n { zhmap = false } } ,
    nozhmap   .value_forbidden:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2014/04/11}{\opt{punct} 选项可以设置标点格式。}
% \changes{v2.0}{2015/03/21}{\opt{nopunct} 是过时选项。}
%
% \begin{macro}{punct}
% 设置标点符号输出格式。
%   \begin{macrocode}
    punct   .tl_set:N = \l_@@_punct_tl ,
    punct  .default:n = { quanjiao } ,
    punct  .initial:n = { quanjiao } ,
    nopunct   .code:n = \ctex_set_deprecated_option:n { punct = plain } ,
    nopunct   .value_forbidden:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2015/03/22}{\opt{nospace} 是过时选项。}
% \begin{macro}{space}
%   \begin{macrocode}
    space .choices:nn =
      { true , auto , false }
      {
        \exp_args:Nx \ctex_at_end:n
          { \ctex_set:n { space = \l_keys_choice_tl } }
      } ,
    space  .default:n = { true } ,
    nospace   .code:n = { \ctex_deprecated_option:nn { space = false } } ,
    nospace   .value_forbidden:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2014/03/08}{\pkg{ctex} 宏包新增 \opt{heading} 选项。}
%
% \begin{macro}{heading}
%   \begin{macrocode}
    heading .bool_set:N = \l_@@_heading_bool ,
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</class|ctex>
%<*class|ctex|ctexheading>
%    \end{macrocode}
%
% \begin{macro}{sub3section,sub4section}
% \begin{macrocode}
%<*!beamer>
    sub3section .code:n =
      { \int_gset:Nn \g_@@_section_depth_int { 3 } } ,
    sub4section .code:n =
      { \int_gset:Nn \g_@@_section_depth_int { 4 } } ,
    sub3section .value_forbidden:n = true ,
    sub4section .value_forbidden:n = true ,
%</!beamer>
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2015/04/15}{新增 \opt{scheme} 选项,并将 \opt{cap} 和 \opt{nocap}
% 列为过时选项。}
%
% \begin{macro}{scheme}
%    \begin{macrocode}
    scheme .tl_set:N  = \l_@@_scheme_tl ,
%<*ctexheading>
    scheme .default:n = { plain } ,
    scheme .initial:n = { plain }
  }
%</ctexheading>
%<*!ctexheading>
    scheme .default:n = { chinese } ,
    scheme .initial:n = { chinese } ,
%</!ctexheading>
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</class|ctex|ctexheading>
%<*class|ctex>
%    \end{macrocode}
%
% \begin{macro}{cap,nocap}
% \opt{cap} 和 \opt{nocap} 是过时选项。
% \begin{macrocode}
    cap    .code:n = { \ctex_set_deprecated_option:n { scheme = chinese } } ,
    nocap  .code:n = { \ctex_set_deprecated_option:n { scheme = plain } } ,
    cap    .value_forbidden:n = true ,
    nocap  .value_forbidden:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2015/04/20}{\opt{hyperref} 成为过时选项,原选项功能总是打开。}
% \changes{v2.0}{2015/04/20}{\opt{fancyhdr} 成为过时选项,原选项功能总是打开。}
% \changes{v2.0}{2015/04/20}{\opt{fntef} 成为过时选项,原选项功能总是打开。}
%
% 以下三项都是过时的兼容选项,它们会载入有关宏包。
%
% \begin{macro}{fntef}
% \changes{v2.5}{2019/11/10}{仅在该选项启用时会载入 \pkg{CJKfntef} 或
% \pkg{xeCJKfntef} 宏包。}
%   \begin{macrocode}
    fntef .code:n =
      {
        \sys_if_engine_xetex:TF
          {
            \ctex_deprecated_option:n { `xeCJKfntef'~package~is~loaded. }
            \ctex_at_end:n { \RequirePackage { xeCJKfntef } }
          }
          {
            \sys_if_engine_pdftex:TF
              {
                \ctex_deprecated_option:n { `CJKfntef'~package~is~loaded. }
                \ctex_at_end:n { \RequirePackage { CJKfntef } }
              }
              {
                \ctex_deprecated_option:n
                  { Furthermore,~option~`fntef'~is~invalid~in~current~mode. }
              }
          }
      } ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{fancyhdr}
%   \begin{macrocode}
    fancyhdr .code:n =
      {
        \ctex_deprecated_option:n { `fancyhdr'~package~is~loaded. }
        \ctex_at_end:n { \RequirePackage { fancyhdr } }
      } ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{hyperref}
% \changes{v2.1}{2015/06/03}{补充定义 \tn{hypersetup}。}
%   \begin{macrocode}
    hyperref .code:n =
      {
        \ctex_deprecated_option:n { `hyperref'~package~will~be~loaded. }
        \ctex_at_end:n
          {
            \cs_if_exist:NF \hypersetup
              { \cs_new_eq:NN \hypersetup \ctex_hypersetup:n }
          }
        \ctex_at_end_preamble:n { \RequirePackage { hyperref } }
      } ,
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</class|ctex>
%<*class|ctex|ctexsize>
%    \end{macrocode}
%
% \changes{v2.0}{2015/05/06}{兼容 \pkg{extsizes} 宏包、\cls{beamer}、\pkg{memoir}
% 等提供的更多字号选项。}
% \changes{v2.0.1}{2015/05/15}{修复 \opt{10pt}、\opt{11pt} 等选项无效的问题。}
% \begin{macro}{10pt,11pt,12pt}
% 使 \pkg{ctex} 和 \pkg{ctexsize} 可以接受文档类的全局选项,不修改默认字体大小。
% 在文档类下还将参数传给标准文档类。
%    \begin{macrocode}
\tl_clear_new:N \l_@@_tmp_tl
\clist_map_inline:nn
  {
    10pt , 11pt , 12pt ,
     8pt ,  9pt , 14pt , 17pt , 20pt , 25pt , 30pt , 36pt , 48pt , 60pt
  }
  {
    \tl_put_right:Nn \l_@@_tmp_tl
      {
        #1 .code:n =
%<*!class>
          { \int_gset:Nn \g_@@_font_size_int { 2 } } ,
%</!class>
%<*class>
          {
            \int_gset:Nn \g_@@_font_size_int { 2 }
            \clist_gput_right:Nn \g_@@_std_options_clist {#1}
          } ,
%</class>
        #1 .value_forbidden:n = true ,
      }
  }
\exp_args:No \ctex_define_option:n { \l_@@_tmp_tl }
\tl_clear:N \l_@@_tmp_tl
%    \end{macrocode}
% \end{macro}
%
% 将未知选项传给标准文档类。
%    \begin{macrocode}
%<*class>
\ctex_define_option:n
  {
    unknown .code:n =
      { \clist_gput_right:No \g_@@_std_options_clist { \CurrentOption } }
  }
%</class>
%    \end{macrocode}
%
% 载入选项配置文件。
%    \begin{macrocode}
%<!ctexsize>\ctex_file_input:n { ctexopts.cfg }
%</class|ctex|ctexsize>
%    \end{macrocode}
%
% 处理宏包选项。
%    \begin{macrocode}
%<*class|style>
\ProcessKeysOptions { ctex / option }
%</class|style>
%    \end{macrocode}
%
% \pdfLaTeX{} 下,如果没有显式指定编码为 |UTF8|,则给出警告信息。
%    \begin{macrocode}
%<*class|ctex>
\msg_new:nnn { ctex } { pdftex-utf8 }
  { UTF8~will~be~used~as~the~default~encoding. }
\tl_if_empty:NT \g_@@_encoding_tl
  {
    \sys_if_engine_pdftex:T
      { \msg_warning:nn { ctex } { pdftex-utf8 } }
    \tl_gset:Nn \g_@@_encoding_tl { UTF8 }
  }
%</class|ctex>
%    \end{macrocode}
%
%    \begin{macrocode}
%<*class>
%    \end{macrocode}
%
% 五号字使用标准文档类的 |10pt| 字体大小设置,小四号字则使用 |12pt|。
%    \begin{macrocode}
\int_case:nn { \g_@@_font_size_int }
  {
    { 0 } { \clist_gput_right:Nn \g_@@_std_options_clist { 10pt } }
    { 1 } { \clist_gput_right:Nn \g_@@_std_options_clist { 12pt } }
  }
%    \end{macrocode}
%
% 使用 \tn{PassOptionsToClass} 是为了预防可能存在的选项冲突。
%    \begin{macrocode}
%<*article>
\tl_const:Nn \c_@@_class_tl { article }
\PassOptionsToClass { \g_@@_std_options_clist } { article }
\LoadClass { article }
%</article>
%<*book>
\tl_const:Nn \c_@@_class_tl { book }
\PassOptionsToClass { \g_@@_std_options_clist } { book }
\LoadClass { book }
%</book>
%<*report>
\tl_const:Nn \c_@@_class_tl { report }
\PassOptionsToClass { \g_@@_std_options_clist } { report }
\LoadClass { report }
%</report>
%<*beamer>
\tl_const:Nn \c_@@_class_tl { beamer }
\PassOptionsToClass { \g_@@_std_options_clist } { beamer }
\LoadClass { beamer }
%</beamer>
%    \end{macrocode}
%
%    \begin{macrocode}
%</class>
%    \end{macrocode}
%
% \subsection{特定引擎支持与设置}
%
% \changes{v2.5}{2020/04/22}{给 \LaTeX 和 \upLaTeX 下的文档类指定驱动为 \dvipdfmx。}
%
% \subsubsection{\pkg{ctexbackend.cfg}}
%
% 对于 \XeLaTeX{}/\pdfLaTeX{}/\LuaLaTeX{} 等默认直接输出 PDF 的编译方式,用户
% 无需为涉及驱动的宏包指定驱动选项。对于 \LaTeX 和 \upLaTeX{} 等默认不直接输出 PDF 的编译方式,
% 用户则需要指定驱动选项。
%
% 由于历史遗留问题,在使用 \LaTeX{} 或 \upLaTeX{} 等编译时,
% 大多数涉及驱动的宏包选定的默认输出驱动都是 Dvips。
% 考虑当前实际使用频率,以及考虑到 \CTeX{} 宏集对中文支持的默认方式,
% 我们在用户使用 \CTeX{} 系列文档类时,将默认的输出驱动改为 \dvipdfmx。
%
% 具体来说,如果 |dvips|,|dvipdfmx|,|dvisvgm| 等驱动没有在文档类的全局选项中被明确指定,
% 我们就在 \tn{@classoptionslist} 开头加入 |dvipdfmx|。
%
% 本段代码只在 \cls{ctexart} 等文档类开头载入,不在 \pkg{ctex} 中使用。
% 并且需要放在 \pkg{expl3} 之前载入,保证它载入正确的 backend 文件。
%    \begin{macrocode}
%<*backend>
\begingroup
\expandafter\ifx\csname Umathchardef\endcsname\relax
\else\expandafter\endgroup\expandafter\endinput\fi
  \ifodd
    \expandafter\ifx\csname      pdfoutput\endcsname\relax
    \expandafter\ifx\csname enablecjktoken\endcsname\relax 0\else 1\fi
                                   \else\ifnum\pdfoutput>0 0\else 1\fi\fi\space
    \def\x#1{%
      \if\relax\detokenize{#1}\relax
        \gdef\@classoptionslist{dvipdfmx}%
      \else
        \let\CTEX@add\@ne
        \@tfor\x:={dvips}{dvipdfmx}{dvisvgm}\do{%
          \expandafter\in@\expandafter{\expandafter,\x,}{,#1,}%
          \ifin@ \let\CTEX@add\tw@ \@break@tfor \fi}%
        \ifodd\CTEX@add \gdef\@classoptionslist{dvipdfmx,#1}\fi
      \fi}
    \expandafter\x\expandafter{\@classoptionslist}
  \fi
\endgroup
%</backend>
%    \end{macrocode}
%
% \subsubsection{\pkg{ctex-engine-pdftex.def}}
%
% \begin{macro}[int]{\ctex_set_zhmap:n}
% 设置 \upTeX{} 字体映射,同时作用于 \tn{AtBeginDvi} 与
% \tn{AtBeginShipoutFirst}。该宏对 \pdfTeX{} 和 \upTeX{} 均有用。
% \tn{AtBeginDvi} 直接将 \tn{special} 保存到盒子中,
% \tn{AtBeginShipoutFirst} 是保存到到宏中,并且不展开参数。
%
% 可以使用 \LaTeX\ 2020/10/01 的钩子机制来统一设置。
%     \begin{macrocode}
%<*pdftex|uptex|aptex>
\cs_new_protected:Npn \ctex_set_zhmap:n
  { \tl_gput_right:Nx \g_@@_zhmap_tl }
\cs_new_protected:Npn \ctex_use_zhmap:
  { \tl_use:N \g_@@_zhmap_tl }
\cs_if_exist:NTF \ctex_gadd_ltxhook:nn
  {
    \cs_new_protected:Npn \ctex_at_shipout_first:n
      { \ctex_gadd_ltxhook:nn { shipout/firstpage } }
    \ctex_at_shipout_first:n { \ctex_use_zhmap: }
  }
  {
    \cs_new_protected:Npn \ctex_add_dvi_zhmap:
      { \AtBeginDvi { \ctex_use_zhmap: } }
    \ctex_after_end_preamble:n { \ctex_add_dvi_zhmap: }
    \ctex_at_end_package:nn { atbegshi }
      {
        \cs_new_protected:Npn \ctex_at_shipout_first:n
          { \AtBeginShipoutFirst }
        \ctex_at_shipout_first:n { \ctex_use_zhmap: }
        \cs_gset_eq:NN \ctex_add_dvi_zhmap: \prg_do_nothing:
      }
  }
\tl_new:N \g_@@_zhmap_tl
\@onlypreamble \ctex_set_zhmap:n
%</pdftex|uptex|aptex>
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%<*pdftex>
%    \end{macrocode}
%
% \changes{v2.1}{2015/05/18}{给 \pdfLaTeX{} 下的非 UTF-8 编码 CJK 字体族加上 CMap。}
%
% \begin{variable}{\c_@@_cmap_encoding_seq}
% 需要加上 CMap 的 CJK 字体编码。
%    \begin{macrocode}
\seq_const_from_clist:Nn \c_@@_cmap_encoding_seq
  { C19 , C10 , C00 , C09 , C40 , C60 }
%    \end{macrocode}
% \end{variable}
%
% \begin{macro}[int]{\ctex_family_cmap:nn}
% 在 \tn{DeclareFontFamily} 的 \meta{loading-settings} 中给 CJK 字体族加上 CMap。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_family_cmap:nn #1#2
  {
    \cs_if_free:cF { #1 + #2 }
      {
        \seq_if_in:NnT \c_@@_cmap_encoding_seq {#1}
          { \tl_gput_right:cn { #1 + #2 } { \ctex_add_cmap:n {#1} } }
      }
  }
\cs_generate_variant:Nn \ctex_family_cmap:nn { x }
\cs_new_eq:NN \CTEX@Family@CMap \ctex_family_cmap:xn
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5.7}{2021/06/06}{更好地兼容 \pkg{cmap} 包。}
%
% \begin{macro}[int]{\ctex_add_cmap:n}
% \changes{v2.5.7}{2021/06/06}{确保 cmap 文件存在。}
% 给 |#1| 编码的 CJK 字体加上 CMap。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_add_cmap:n #1
  {
    \cs_if_free:NF \CJK@plane
      { \exp_args:Ne \@@_add_cmap_auxi:n { #1 \CJK@plane } }
  }
\cs_new_protected:Npn \@@_add_cmap_auxi:n #1
  { \exp_args:Nc \@@_add_cmap_auxii:Nn { @@_add_cmap_ #1 : } {#1} }
\cs_new_protected:Npn \@@_add_cmap_auxii:Nn #1#2
  {
    \cs_if_exist:NF #1 { \@@_save_cmap:Nn #1 {#2} }
    #1
  }
\cs_new_protected:Npn \@@_save_cmap:Nn #1#2
  {
    \exp_args:Ne \file_get_full_name:nNTF
      { \str_lowercase:n {#2} .cmap } \l_@@_cmap_file_tl
      {
        \tex_immediate:D \tex_pdfobj:D stream ~ file { \l_@@_cmap_file_tl }
        \cs_new_protected:Npx #1
          {
            \pdfnobuiltintounicode \tex_font:D
            \tex_pdffontattr:D \tex_font:D
              { /ToUnicode ~ \int_value:w \tex_pdflastobj:D \c_space_tl 0 ~ R }
          }
      }
      { \cs_new_eq:NN #1 \prg_do_nothing: }
  }
\tl_new:N \l_@@_cmap_file_tl
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\DeclareFontFamily}
% 只在 \pdfLaTeX{} 下加 CMap。如 \pkg{cmap} 宏包被引入,则不重复设置。
%    \begin{macrocode}
\group_begin:
\char_set_catcode_other:N \#
\sys_if_output_pdf:TF
  {
    \group_end:
    \ctex_appto_cmd:NnnTF \DeclareFontFamily { \ExplSyntaxOff }
      { \CTEX@Family@CMap {#1} {#2} }
      {
        \ctex_at_end_package:nn { cmap }
          {
            \cs_gset_eq:NN \ctex_add_cmap:n \use_none:n
            \cs_gset_eq:NN \CTEX@Family@CMap \use_none:nn
          }
      }
      { \ctex_patch_failure:N \DeclareFontFamily }
  }
  { \group_end: }
%    \end{macrocode}
% \end{macro}
%
% 首先检查选项,决定是否载入 \pkg{zhmCJK} 宏包。
%    \begin{macrocode}
\if_bool:N \g_@@_zhmCJK_bool
  \PassOptionsToPackage { encoding = \g_@@_encoding_tl } { zhmCJK }
  \RequirePackage { zhmCJK }
%    \end{macrocode}
% 不载入 \pkg{zhmCJK} 宏包时直接调用 \pkg{CJK} 及相关宏包。
%    \begin{macrocode}
\else:
  \str_if_eq:onTF { \g_@@_encoding_tl } { GBK }
    { \RequirePackage { CJK } }
    { \RequirePackage { CJKutf8 } }
  \RequirePackage { CJKpunct , CJKspace }
%    \end{macrocode}
%
% \changes{v2.4.4}{2016/09/09}{解决 \opt{zhmap} 文件的 \tn{catcode} 问题。}
%
% \begin{macro}[int]{\ctex_load_zhmap:nnnn}
% 载入 \pkg{zhmetrics} 的字体映射文件,同时设置 \tn{CJKrmdefault} 等。
%    \begin{macrocode}
  \cs_new_protected:Npn \ctex_load_zhmap:nnnn #1#2#3#4
    {
      \tl_set:Nn \CJKrmdefault {#1}
      \tl_set:Nn \CJKsfdefault {#2}
      \tl_set:Nn \CJKttdefault {#3}
      \ctex_set_zhmap:n { \ctex_file_input:n { ctex-zhmap- #4 .tex } }
    }
  \@onlypreamble \ctex_load_zhmap:nnnn
%    \end{macrocode}
% \end{macro}
%
% \pkg{zhmCJK} 判断结束。
%    \begin{macrocode}
\fi:
%    \end{macrocode}
%
% \begin{macro}[int]{\ctex_CJK_input:n,\CJK@input}
% 载入 \pkg{CJK} 包的 \file{.enc} 和 \file{.bdg} 等文件时,需要设置 \tn{endlinechar} 为 $-1$。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_CJK_input:n #1
  {
    \ctex_push_file:
      \int_set:Nn \tex_endlinechar:D { -1 }
      \file_input:n {#1}
    \ctex_pop_file:
  }
\cs_set_eq:NN \CJK@input \ctex_CJK_input:n
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_plane_to_utfxvibe:Nn,\CJK@surr}
% \changes{v2.0}{2014/04/08}{解决与 \tn{nouppercase} 的冲突。}
% \pkg{fancyhdr} 宏包的 \tn{nouppercase} 会将 \tn{uppercase} 定义为 \tn{relax},而
% \tn{CJK@surr} 需要用它将 \tn{CJK@plane} 转化成大写字母,这就造成了冲突^^A
% \footnote{\url{https://github.com/CTeX-org/ctex-kit/issues/146}}。
% 我们在这里给出 \tn{CJK@surr} 的一个不依赖 \tn{uppercase} 的实现。
%    \begin{macrocode}
\cs_if_free:NF \CJK@surr
  {
    \cs_new_protected:Npn \ctex_plane_to_utfxvibe:Nn #1#2
      {
        \int_set:Nn \l_@@_tmp_int
          { \exp_args:Ne \int_from_hex:n {#2} }
        \int_compare:nNnTF \l_@@_tmp_int < { 256 }
          { \tl_gset:Nx #1 { \int_to_Hex:n { \l_@@_tmp_int } } }
          {
            \int_sub:Nn \l_@@_tmp_int { 256 }
            \tl_gset:Nx #1
              {
                \int_to_Hex:n
                  { \int_div_truncate:nn { \l_@@_tmp_int } { 4 } + "D800 }
                \int_to_Hex:n
                  { \int_mod:nn { \l_@@_tmp_int } { 4 } + "DC }
              }
          }
      }
    \cs_set_eq:NN \CJK@surr \ctex_plane_to_utfxvibe:Nn
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CJK@addcmap}
% \changes{v2.5.7}{2021/06/06}{应用 \tn{pdfnobuiltintounicode}。}
% \LaTeX \ 2021-06-01 默认载入 \file{glyphtounicode.tex},我们对 CJK 字体禁用这一内建设置。
%    \begin{macrocode}
\cs_if_free:NF \CJK@addcmap
  {
    \ctex_patch_cmd:Nnn \CJK@addcmap
      { \pdffontattr \font@name }
      {
        \pdfnobuiltintounicode \font@name
        \pdffontattr \font@name
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \pkg{CJKpunct} 宏包会在 \tn{AtBeginDocument} 的里设置标点格式为 \opt{quanjiao}。
%    \begin{macrocode}
\AtBeginDocument
  {
    \str_if_eq:eeF { \l_@@_punct_tl } { quanjiao }
      { \punctstyle { \l_@@_punct_tl } }
  }
%    \end{macrocode}
%
% 在导言区末尾更新 \tn{CJKfamilydefault},注意要在 \tn{CJK@envStart} 之前使用。
%    \begin{macrocode}
\ctex_at_end_preamble:n { \ctex_update_default_family: }
%    \end{macrocode}
%
% 启用中文字符功能。\opt{GBK} 编码时,将汉字的首字节设置为活动字符,并对这些
% 字符初始化;\opt{UTF8} 编码时,上游宏包已经处理好。
% \tn{CJK@makeActive} 应该先于 \file{ctex-name-gbk.cfg} 等文件的载入。
% 注意 \tn{CJK@loadBinding} 需要调用补丁后的 \tn{CJK@input}。使用
% \pkg{zhmCJK} 时,此功能已经被启用。
%    \begin{macrocode}
\reverse_if:N \if_bool:N \g_@@_zhmCJK_bool
  \str_if_eq:onF { \g_@@_encoding_tl } { UTF8 }
    {
      \CJK@makeActive
      \CJK@loadBinding { standard }
    }
%    \end{macrocode}
%
% 在导言区结束时调用 \tn{CJK@envStart} 启用完整的中文功能。
%
% \tn{CJK@envStart} 的定义是
% \begin{verbatim}
%   \def\CJK@envStart#1#2#3{
%     \CJK@upperReset
%     \ifCJK@lowercase@
%       \CJK@lowerReset
%     \fi%
%     \CJK@makeActive%
%     \CJK@global\let\CJK@selectFamily \CJK@selFam
%     \CJK@global\let\CJK@selectEnc \CJK@selEnc%
%     \def\CJK@@@enc{#2}
%     \ifx\CJK@@@enc \@empty
%       \PackageInfo{CJK}{
%         no encoding parameter given,\MessageBreak
%         waiting for \protect\CJKenc\space commands}
%     \else
%       \CJKenc{#2}
%     \fi
%     \CJKfontenc{#2}{#1}
%     \CJKfamily{#3}
%     \def\CJK@series{\f@series}
%     \def\CJK@shape{\f@shape}%
%     \csname CJKhook\endcsname}
% \end{verbatim}
% \tn{CJK@upperReset} 可能会有一定风险,因此我们直到导言区末尾才使用
% \tn{CJK@envStart}。这样可以避免将 \env{CJK} 环境内置入 \env{document} 环境的
% 最里层,最后也就不需要 \tn{clearpage}。\pkg{zhmCJK} 已经提供类似功能。
% 注意先使用 \cs{ctex_update_default_family:} 更新 \tn{CJKfamilydefault}。
%    \begin{macrocode}
  \exp_args:Nx \ctex_at_end_preamble:n
    {
      \exp_not:N \CJK@envStart
        { } { \g_@@_encoding_tl } { \exp_not:N \CJKfamilydefault }
      \exp_not:N \CJKtilde
    }
%    \end{macrocode}
%
% \pkg{zhmCJK} 判断结束。
%    \begin{macrocode}
\fi:
%    \end{macrocode}
%
% \begin{macro}[int]{\ctex_auto_ignorespaces:}
% 保存 \tn{CJK@@ignorespaces} 的定义,方便使用。
%    \begin{macrocode}
\cs_new_eq:NN \ctex_auto_ignorespaces: \CJK@@@@ignorespaces
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ignorespaces_case:N,\ctex_set_ignorespaces:}
% 设置忽略空格的的方式。根据 \opt{space} 选项的值重定义 \tn{CJK@ignorespaces},
% 并保存起来供 \tn{CJKhook} 备用。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ignorespaces_case:N #1
  {
    \cs_set_protected:Npn \ctex_set_ignorespaces:
      { \cs_set_eq:NN \CJK@ignorespaces #1 }
    \ctex_set_ignorespaces:
  }
\cs_new_protected:Npn \ctex_set_ignorespaces:
  { \cs_set_eq:NN \CJK@ignorespaces \ctex_auto_ignorespaces: }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CJKhook}
% \changes{v2.5.5}{2020/10/06}{不再通过旧的钩子命令来定义。}
% \env{CJK} 和 \env{CJK*} 环境都会重新定义 \tn{CJK@ignorespaces}。我们在 \pkg{CJK}
% 宏包提供的 \tn{CJKhook} 里重新设置它,让这两个环境忽略空格的方式都受 \opt{space}
% 选项的控制。这对 \pkg{zhmCJK} 是必要的。
%    \begin{macrocode}
\tl_if_exist:NF \CJKhook { \tl_new:N \CJKhook }
\tl_gput_right:Nn \CJKhook { \ctex_set_ignorespaces: }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_punct_set:n}
% 设置 CJK 族对应到实际的字体。|#1| 是 \opt{fontset} 的名字。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_punct_set:n #1
  {
    \clist_map_inline:Nn \c_@@_punct_family_clist
      {
        \cs_if_free:cF { c_@@_ #1 ##1 _punct_spaces_tl }
          {
            \cs_set_eq:cc
              { CJKpunct@ ##1 @spaces }
              { c_@@_ #1 ##1 _punct_spaces_tl }
          }
      }
  }
\clist_const:Nn \c_@@_punct_family_clist
  {
    zhsong , zhhei , zhfs , zhkai , zhli , zhyou ,
    zhsongb , zhheil , zhheib , zhyoub ,
    zhyahei , zhyaheib , zhpf , zhpfb
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_punct_map_family:nn}
% CJK 族 |#1| 使用族 |#2| 的边界信息。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_punct_map_family:nn #1#2
  {
    \cs_if_free:cF { CJKpunct@ #2 @spaces }
      { \cs_set_eq:cc { CJKpunct@ #1 @spaces } { CJKpunct@ #2 @spaces } }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_punct_map_bfseries:nn}
% CJK 族 |#1| 的 \tn{bfseries} 使用族 |#2| 的边界信息。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_punct_map_bfseries:nn #1#2
  {
    \clist_map_inline:nn {#1}
      {
        \ctex_punct_map_series:nnn { ##1 } { b } {#2}
        \ctex_punct_map_series:nnn { ##1 } { bx } {#2}
      }
  }
\cs_new_protected:Npn \ctex_punct_map_series:nnn #1#2#3
  {
    \CJKpunctmapfamily { C19 } {#1} {#2} { m }  {#3}
    \CJKpunctmapfamily { C19 } {#1} {#2} { it } {#3}
    \CJKpunctmapfamily { C19 } {#1} {#2} { sl } {#3}
    \CJKpunctmapfamily { C70 } {#1} {#2} { m }  {#3}
    \CJKpunctmapfamily { C70 } {#1} {#2} { it } {#3}
    \CJKpunctmapfamily { C70 } {#1} {#2} { sl } {#3}
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_punct_map_itshape:nn}
% CJK 族 |#1| 的 \tn{itshape} 使用族 |#2| 的边界信息。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_punct_map_itshape:nn #1#2
  {
    \CJKpunctmapfamily { C19 } {#1} { m }  { it } {#2}
    \CJKpunctmapfamily { C19 } {#1} { b }  { it } {#2}
    \CJKpunctmapfamily { C19 } {#1} { bx } { it } {#2}
    \CJKpunctmapfamily { C70 } {#1} { m }  { it } {#2}
    \CJKpunctmapfamily { C70 } {#1} { b }  { it } {#2}
    \CJKpunctmapfamily { C70 } {#1} { bx } { it } {#2}
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_punct_space:nn,\ctexspadef}
% 定义标点的边界信息。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_punct_space:nn #1#2
  { \tl_const:cn { c_@@_ #1 _punct_spaces_tl } {#2} }
\cs_new_eq:NN \ctexspadef \ctex_punct_space:nn
%    \end{macrocode}
% \end{macro}
%
% 载入边界信息文件。
%     \begin{macrocode}
\ctex_file_input:n { ctexspa.def }
%    \end{macrocode}
%
%    \begin{macrocode}
%</pdftex>
%    \end{macrocode}
%
% \subsubsection{\pkg{ctex-engine-xetex.def}}
%
%    \begin{macrocode}
%<*xetex>
%    \end{macrocode}
%
% \changes{v2.4.4}{2016/09/12}{不再默认设置 \pkg{xeCJK} 的伪粗体。}
%    \begin{macrocode}
\RequirePackage { xeCJK }
\exp_args:Nx \xeCJKsetup
  {
    LoadFandol   = false ,
    PunctStyle   = \l_@@_punct_tl
  }
%    \end{macrocode}
%
% 最新版本的 \pkg{fontspec} 默认对 \tn{rmfamily} 和 \tn{sffamily} 设置
% |Ligatures=TeX|,对 \tn{ttfamily} 设置 |WordSpace={1,0,0}| 和
% |PunctuationSpace=WordSpace|。
%    \begin{macrocode}
\@ifpackagelater { fontspec } { 2014/05/25 } { }
  { \msg_error:nnn { ctex } { package-too-old } { fontspec } }
%    \end{macrocode}
%
%    \begin{macrocode}
%</xetex>
%    \end{macrocode}
%
% \subsubsection{\pkg{ctex-engine-luatex.def}}
%
%    \begin{macrocode}
%<*luatex>
%    \end{macrocode}
%
% \changes{v2.0}{2014/03/08}{通过 \pkg{LuaTeX-ja} 宏包支持 \LuaLaTeX。}
% \changes{v2.3}{2015/09/25}{更新 \pkg{LuaTeX-ja} 支持(20150922.0)。}
% \changes{v2.5}{2020/04/18}{更新 \pkg{LuaTeX-ja} 支持(20200412.0)。}
% \changes{v2.5.4}{2020/08/16}{更新 \pkg{LuaTeX-ja} 支持(20200808.0)。}
%
% \pkg{LuaTeX-ja} 为了兼容 p\LaTeX 的使用习惯,对 \LaTeXe 的 \pkg{NFSS} 作了不少
% 修改和扩充,这对于简体中文用户来说不是必要的。我们在这里禁用它。
%    \begin{macrocode}
\msg_new:nnn { ctex } { luatexja-loaded }
  {
    Package~`luatexja'~can~not~be~loaded~before~`ctex'.\\
    Loading~file~`#1'~will~abort!
  }
\@ifpackageloaded { luatexja }
  { \msg_critical:nnx { ctex } { luatexja-loaded } { \g_file_curr_name_str } }
  {
    \ctex_at_begin_package:nn { luatexja }
      { \msg_redirect_name:nnn { ctexhook } { disable-package } { info } }
    \ctex_at_end_package:nn { luatexja }
      { \msg_redirect_name:nnn { ctexhook } { disable-package } { } }
    \ctex_disable_package:n { ltj-latex }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage { luatexja }
\@ifpackagelater { luatexja } { 2020/04/12 } { }
  { \msg_error:nnn { ctex } { package-too-old } { luatexja } }
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage { fontspec }
\@ifpackagelater { fontspec } { 2020/02/21 } { }
  { \msg_error:nnn { ctex } { package-too-old } { fontspec } }
%    \end{macrocode}
%
% 引擎文件是通过 \cs{ctex_file_input:n} 载入的,其中的 \tn{catcodetable} 机制会完整恢复
% 文件载入之前的 \tn{catcode} 状态,在引擎文件中的 \tn{catcode} 设置都无效。
% 因此,对 \tn{ltjlineendcomment} 的设置要放到文件之外进行。
%    \begin{macrocode}
\ctex_at_end:n { \char_set_catcode_comment:n { \ltjlineendcomment } }
%    \end{macrocode}
%
% \paragraph{\pkg{LuaTeX-ja} 的默认设置}
%
%    \begin{macrocode}
\ExplSyntaxOff
%    \end{macrocode}
%
% 以下设置抄录自 \file{lltjdefs.sty},略有改动。
%
% \changes{v2.4.11}{2017/08/17}{不把 Enclosed Alphanumerics 设置为 JAchar。}
% U+2460--U+24FF (Enclosed Alphanumerics) 原属于字符范围 6,是 JAchar,
% 我们把它们归入字符范围 3,改成  ALchar。
%    \begin{macrocode}
\ltjdefcharrange{1}{"80-"36F, "1E00-"1EFF}
\ltjdefcharrange{2}{"370-"4FF, "1F00-"1FFF}
\ltjdefcharrange{3}{%
  "2000-"243F, "2460-"24FF, "2500-"27BF, "2900-"29FF, "2B00-"2BFF}
\ltjdefcharrange{4}{%
   "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF,
  "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A95F, "A980-"ABFF, "E000-"F8FF,
  "FB00-"FE0F, "FE20-"FE2F, "FE70-"FEFF, "10000-"1AFFF, "1B170-"1F0FF,
  "1F300-"1FFFF, "2000-"206F}
\ltjdefcharrange{5}{"D800-"DFFF, "E0000-"E00FF, "E01F0-"10FFFF}
\ltjdefcharrange{6}{%
  "2E80-"2EFF, "3000-"30FF, "3190-"319F, "31F0-"4DBF,
  "4E00-"9FFF, "F900-"FAFF, "FE10-"FE1F, "FE30-"FE6F, "FF00-"FFEF,
  "1B000-"1B16F, "1F100-"1F2FF, "20000-"3FFFF, "E0100-"E01EF}
\ltjdefcharrange{7}{%
  "1100-"11FF, "2F00-"2FFF, "3100-"318F, "31A0-"31EF, "A000-"A4CF,
  "A960-"A97F, "AC00-"D7FF}
\ltjdefcharrange{8}{"A7, "A8, "B0, "B1, "B4, "B6, "D7, "F7}
%    \end{macrocode}
% 将间隔号、引号、破折号等中西文公用的标点符号归入字符范围 9,将他们设置为 JAchar。
%    \begin{macrocode}
\ltjdefcharrange{9}{%
  "00B7, "2018, "2019, "201C, "201D, "2013, "2014, "2025, "2026, "2027, "2E3A}
%    \end{macrocode}
% \changes{v2.4.11}{2017/08/17}{不把希腊和西里尔字母设置为 JAchar。}
% \pkg{LuaTeX-ja} 默认把字符范围 2 和 3 设置为 JAchar,我们这里把它们都改成 ALchar。
%    \begin{macrocode}
\ltjsetparameter{jacharrange={-1, -2, -3, -4, -5, +6, +7, -8, +9}}
\directlua{for x=128,255 do luatexja.math.is_math_letters[x] = true end}
%    \end{macrocode}
%
% 以下设置抄录自 2020/08/08 之前的 \file{ltj-latex.sty}。
% 自 2020/08/08 开始,\pkg{LuaTeX-ja} 引入新的缓存机制,此段设置被整合进 \file{luatexja.lua}。
%    \begin{macrocode}
\@ifpackagelater{luatexja}{2020/08/08}
  { \ltjsetparameter { autospacing, autoxspacing, differentjfm = paverage } }
  {
    \directlua{
      local s = kpse.find_file('ltj-kinsoku.lua', 'tex')
      luatexja.stack.charprop_stack_table[0] = s and dofile(s) or {}
    }
    \ltjsetparameter{kanjiskip=\z@ plus .4pt minus .5pt,
      xkanjiskip=.25\zw plus 1pt minus 1pt,
      autospacing, autoxspacing, jacharrange={-1},
      yalbaselineshift=\z@, yjabaselineshift=\z@,
      jcharwidowpenalty=500, differentjfm=paverage
    }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\ExplSyntaxOn
%    \end{macrocode}
%
% \paragraph{\pkg{LuaTeX-ja} 的补丁}
%
%    \begin{macrocode}
%<@@=ctex_ltj>
%    \end{macrocode}
%
% \changes{v2.5.3}{2020/05/31}{不再依赖 \pkg{xunicode},单独补丁 \file{tuenc.def}。}
%
% \begin{macro}{\CTEX@alchar, \CTEX@beginallalchar, \CTEX@endallalchar}
% 分组中的字符都是 ALchar 类。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@alchar #1
  { \CTEX@beginallalchar #1 \CTEX@endallalchar }
\cs_new_protected:Npn \CTEX@beginallalchar
  {
    \group_begin:
      \ctex_ltj_zero_globaldefs:
      \ltj@allalchar
  }
\cs_new_protected:Npn \CTEX@endallalchar
  { \group_end: }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\CTEX@chardef@text@cmd}
% 补丁 \tn{chardef@text@cmd},应用于 \tn{DeclareTextSymbol},使其定义的符号都是 ALchar。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@chardef@text@cmd #1
  {
    \cs_set_eq:NN \@ifdefinable \@@@@ifdefinable
    \tl_set:Nn \l_@@_cmd_tl {#1}
    \tex_afterassignment:D \@@_chardef_text_cmd:
    \tex_chardef:D #1
  }
\tl_new:N \l_@@_cmd_tl
\cs_new_protected:Npn \@@_chardef_text_cmd:
  { \exp_after:wN \@@_chardef_text_cmd_aux:N \l_@@_cmd_tl }
\cs_new_protected:Npn \@@_chardef_text_cmd_aux:N #1
  {
    \int_compare:nNnF {#1} < { "80 }
      { \cs_set_protected:Npx #1 { \CTEX@alchar { \tex_Uchar:D #1 } } }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\CTEX@text@composite@x}
% \tn{@text@composite@x} 的重定义,应用于 \tn{DeclareUnicodeComposite} 等。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@text@composite@x #1#2
  {
    \CTEX@beginallalchar
      \cs_if_exist_use:NF #1 {#2}
    \CTEX@endallalchar
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\CTEX@add@unicode@accent}
% \tn{add@unicode@accent} 的重定义,应用于 \tn{DeclareUnicodeAccent}。
%    \begin{macrocode}
\cs_new_protected:Npx \CTEX@add@unicode@accent #1#2
  {
    \CTEX@beginallalchar
      \exp_not:N \tl_if_blank:nTF {#2} { \tex_Uchar:D "A0 ~ } {#2}
      \exp_not:N \tex_Uchar:D \tex_numexpr:D #1 \scan_stop:
    \CTEX@endallalchar
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\CTEX@patch@text@cmd}
% 单独补丁由 \tn{DeclareTextCommand} 定义的命令。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@patch@text@cmd #1
  {
    \exp_args:NNc \@@_patch_text_cmd:NN #1
      { \UnicodeEncodingName \token_to_str:N #1 }
  }
\cs_new_protected:Npn \@@_patch_text_cmd:NN #1#2
  {
    \cs_set_eq:NN \CTEX@textcmd #2
    \ctex_preto_cmd:NnnTF \CTEX@textcmd
      { \ExplSyntaxOff \makeatletter }
      { \CTEX@beginallalchar }
      {
        \ctex_appto_cmd:NnnTF \CTEX@textcmd
          { \ExplSyntaxOff \makeatletter }
          { \CTEX@endallalchar }
          { \cs_set_eq:NN #2 \CTEX@textcmd }
          { \ctex_patch_failure:N #1 }
      }
      { \ctex_patch_failure:N #1 }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\CTEX@patch@tunec}
% 重新载入 \tn{tunec.def},使补丁生效。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@patch@tunec
  {
    \cs_set_eq:NN \chardef@text@cmd   \CTEX@chardef@text@cmd
    \ctex_file_input:n { tuenc.def }
    \cs_set_eq:NN \@text@composite@x  \CTEX@text@composite@x
    \cs_set_eq:NN \add@unicode@accent \CTEX@add@unicode@accent
    \CTEX@patch@text@cmd \textasteriskcentered
  }
\@ifpackageloaded { xunicode }
  { }
  { \CTEX@patch@tunec }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.3}{2015/09/26}{更新 \pkg{unicode-math} 宏包补丁。}
%
% 在 \LaTeX{} 下,\pkg{LuaTeX-ja} 对 \pkg{fontspec}、\pkg{xunicode}、\pkg{unicode-math}
% 和 \pkg{listings} 打了补丁。其中前三个是把 \tn{char} 换成 \tn{ltjalchar},确保
% 字符是 ALchar 类。我们这里用 \pkg{xunicode-addon} 来处理 \pkg{xunicode}。
%    \begin{macrocode}
\ctex_at_end_package:nn { xunicode }
  {
    \RequirePackage { xunicode-addon }
    \AtBeginUTFCommand { \CTEX@beginallalchar }
    \AtEndUTFCommand   { \CTEX@endallalchar }
  }
%    \end{macrocode}
%
% \changes{v2.4.2}{2016/05/15}{恢复 \pkg{luatexja} 对 \tn{emshape} 和
% \tn{eminnershape} 的重定义。}
% \changes{v2.4.3}{2016/08/26}{简化 \pkg{fontspec} 补丁。}
% \changes{v2.5}{2020/04/18}{删除 \pkg{fontspec} 补丁。}
%
% 对 \pkg{listings} 的补丁是让代码环境支持 JAchar 类。
%    \begin{macrocode}
\ctex_at_end_package:nn { listings }
  { \RequirePackage { lltjp-listings } }
%    \end{macrocode}
%
% \paragraph{\pkg{Lua} 函数}
%
% \changes{v2.5.8}{2021/11/29}{简化部分 \pkg{Lua} 函数。}
%
% 直接用 |token.set_lua| 定义,不是传统意义上的 \TeX \ 宏。
%    \begin{macrocode}
\group_begin:
\char_set_catcode_space:n { 32 }
\lua_now:e
  {
%    \end{macrocode}
% \begin{macro}{ctex.newluacmd}
% 定义新的 \pkg{Lua} 函数。
%    \begin{macrocode}
    ctex = ctex or { }
    local ctex = ctex
    local functions = lua.get_functions_table()
    local new_luafunction = luatexbase.new_luafunction
    local create, set_lua = token.create, token.set_lua
    local lua_cmds = {
      lua_call            = true ,
      lua_expandable_call = true ,
    }
    local newluacmd = function (name, func, ...)
      local tok = create(name)
      local id = lua_cmds[tok.cmdname] and tok.index
      local id = id or new_luafunction(name)
      set_lua(name, id, ...)
      functions[id] = func
    end
    ctex.newluacmd = newluacmd
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
    local ltjfont = luatexja.jfont
    local getattribute = tex.getattribute
    local tex_set, sprint = tex.set, tex.sprint
    local scan_int, scan_arg = token.scan_int, token.scan_argument
%    \end{macrocode}
% \begin{macro}{\ctex_ltj_add_kyenc:n}
% 保存 jfont 的编码,用于判断。
%    \begin{macrocode}
    newluacmd("ctex_ltj_add_kyenc:n", ltjfont.add_kyenc_list, "global", "protected")
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ctex_ltj_is_kenc:n}
% 判断编码是否属于 jfont。
%    \begin{macrocode}
    newluacmd("ctex_ltj_is_kenc:n", ltjfont.is_kenc, "global")
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ctex_ltj_patch_external_font:n}
% 若对字体的定义完全相同,则它们有相同的 \texttt{font.id}。因此如果字形是由
% \textsf{NFSS} 的替换机制定义的,它们就有相同的 \texttt{font.id}。
% |print_aftl_address| 函数的定义是
% \begin{verbatim}
%   function luatexja.jfont.print_aftl_address()
%     return ';ltjaltfont' .. tostring(aftl_base):sub(8)
%   end
% \end{verbatim}
% 主要目的是,如果当前字形有替代字体,则往字形的定义中加入一些标志,确保
% \texttt{font.id} 唯一。
%    \begin{macrocode}
    newluacmd("ctex_ltj_patch_external_font:n", function ()
      local s = scan_arg()
      local is_braced, is_quoted
      if s:sub(1,1) == '{' and s:sub(-1)=='}' then
        is_braced = true; s = s:sub(2,-2)
      end
      if s:sub(1,1) == '"' and s:sub(-1) == '"' then
        is_quoted = true; s = s:sub(2,-2)
      end
      s = s .. ltjfont.print_aftl_address()
      if     is_braced then s = '{'..s..'}'
      elseif is_quoted then s = '"'..s..'"'
      end
      sprint(-2, s)
    end, "global")
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ctex_ltj_set_alt_font:nnnn}
% |#1| 和 |#2| 分别是字符区间的首末,|#3| 是基础字体,|#4| 是替代字体。
%    \begin{macrocode}
    newluacmd("ctex_ltj_set_alt_font:nnnn", function ()
      local b = tonumber(scan_arg())
      local e = tonumber(scan_arg())
      local alt  = scan_arg()
      local base = scan_arg()
      ltjfont.set_alt_font_latex(b, e, alt, base)
    end, "global", "protected")
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ctex_ltj_clear_alt_font:n}
% 清除 |#1| 的替代字体。
%    \begin{macrocode}
    newluacmd("ctex_ltj_clear_alt_font:n", function ()
      local base = scan_arg()
      ltjfont.clear_alt_font_latex(base)
    end, "global", "protected")
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ctex_ltj_pickup_alt_font:nn}
% 定义 |#1| 的替代字体,|#2| 是字体大小。\\
% 会在内部执行 \tn{ltj@pickup@altfont@auxy} 和 \tn{ltj@pickup@altfont@copy}。
%    \begin{macrocode}
    newluacmd("ctex_ltj_pickup_alt_font:nn", function ()
      local base = scan_arg()
      local size = scan_arg()
      ltjfont.output_alt_font_cmd("y", base)
      ltjfont.pickup_alt_font_a(size)
    end, "global", "protected")
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@@_pickup_alt_font:Nn}
% |#1| 是 \texttt{font.id},|#2| 是字体名称。
% 在 \tn{ltj@pickup@altfont@copy} 之中使用。
%    \begin{macrocode}
    newluacmd("@@_pickup_alt_font:Nn", function ()
      local num  = scan_int()
      local base = scan_arg()
      ltjfont.pickup_alt_font_b(num, base)
    end, "global", "protected")
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@@_if_alt_set:nT}
% 判断是否存在替代字体。会设置变量 |aftl_base| 和返回 \tn{@firstofone} 或 \tn{@gobble}。
%    \begin{macrocode}
    newluacmd("@@_if_alt_set:nT", ltjfont.does_alt_set, "global")
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ctex_ltj_zero_globaldefs:}
% 设置 \tn{globaldefs} 为 $0$,避免全局设置,应当在分组中使用。
% 这里通过 Lua 设置,可以不受外部 \TeX\ 环境中的 \tn{globaldefs} 的影响。
%    \begin{macrocode}
    newluacmd("ctex_ltj_zero_globaldefs:", function ()
      tex_set("globaldefs", 0)
    end, "global", "protected")
  }
\group_end:
%    \end{macrocode}
% \end{macro}
%
% \paragraph{字体切换方式}
%
% \begin{macro}[int]{\ctex_ltj_select_font:,\CJK@family}
% \tn{CJK@family} 保存的是当前 CJK 实际的字体族名,如果为空表示没有设置过字体。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_select_font:
  {
    \group_begin: \exp_args:NNc \group_end:
    \cs_if_exist_use:NF { \l_@@_current_font_tl }
      { \tl_if_empty:NF \CJK@family { \@@_select_font_aux: } }
  }
\tl_new:N \CJK@family
\tl_new:N \l_@@_current_font_tl
\tl_set:Nn \l_@@_current_font_tl
  { \CJK@encoding / \CJK@family / \f@series / \f@shape / \f@size }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5.8}{2021/11/18}{兼容 \pkg{microtype}。}
%
% \begin{macro}{\@@_select_font_aux:}
% 使用 \tn{pickup@font} 取得字体名称前,总需要先设置 \tn{font@name}。在这里将
% \tn{f@family} 换成 CJK 字体族,并确保编码正确。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_select_font_aux:
  {
    \group_begin:
      \tl_set_eq:NN \f@encoding \CJK@encoding
      \tl_set_eq:NN \f@family \CJK@family
      \cs_set_eq:NN \pickup@font \ctex_ltj_pickup_font:
      \@@_push_fontname:n { \curr@fontshape / \f@size }
      \ctex_ltj_pickup_font:
    \group_end:
    \font@name
    \@@_pop_fontname:
%    \end{macrocode}
% 当字形未定义的时候,\textsf{NFSS} 就会启动替换机制(\tn{wrong@fontshape})。
% 第一次启动后,\cs{l_@@_current_font_tl} 还是没有定义。为此,我们再次选择字体,
% 确保它有定义和指向正确的 \texttt{font.id}。这对 \opt{AlternateFont} 的设置
% 特别重要。
%    \begin{macrocode}
    \cs_if_exist:cF { \l_@@_current_font_tl }
      { \@@_select_font_aux: }
  }
\cs_new_protected:Npn \@@_push_fontname:n #1
  {
    \seq_gpush:No \g_@@_fontname_seq { \font@name }
    \tl_gset:Nx \font@name { \exp_not:c {#1} }
  }
\cs_new_protected:Npn \@@_pop_fontname:
  {
    \seq_gpop:NNT \g_@@_fontname_seq \l_@@_tmp_tl
      { \tl_gset_eq:NN \font@name \l_@@_tmp_tl }
  }
\seq_new:N \g_@@_fontname_seq
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_pickup_font:}
% 替换 \tn{define@newfont} 内部调用的 \tn{extract@font} 和 \tn{do@subst@correction}。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_pickup_font:
  {
    \exp_after:wN \cs_if_exist:NF \font@name
      {
        \group_begin:
          \cs_set_eq:NN \extract@font \ctex_ltj_extract_font:
          \cs_set_eq:NN \do@subst@correction \ctex_ltj_subst_font:
          \define@newfont
        \group_end:
      }
  }
\cs_new_eq:NN \pickup@jfont \ctex_ltj_pickup_font:
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_extract_font:}
% \pkg{LuaTeX-ja} 的 \tn{globaljfont} 在 \pkg{luatexja-core} 中定义:
% \begin{verbatim}
%   %%%%%%%% \jfont\CS={...:...;jfm=metric;...}, \globaljfont
%   \protected\def\jfont#1{%
%     \afterassignment\ltj@@jfont
%     \directlua{luatexja.jfont.jfontdefX
%       (false, 'yoko','\luatexluaescapestring{\noexpand#1}')}}
%   \protected\def\globaljfont#1{%
%     \afterassignment\ltj@@jfont
%     \directlua{luatexja.jfont.jfontdefX
%       (true,  'yoko','\luatexluaescapestring{\noexpand#1}')}}
%   \newluafunction\ltj@@jfont@inner
%   \directlua{
%     local t = lua.get_functions_table()
%     t[\the\ltj@@jfont@inner] = luatexja.jfont.jfontdefY
%   }
%   \def\ltj@@jfont{\luafunction\ltj@@jfont@inner}
% \end{verbatim}
% \texttt{jfontdefX} 函数的作用是把 \tn{CS} 定义为其后的字体,\texttt{jfontdefY}
% 的作用是更新 \texttt{JFM} 和记录相关字体信息。最后的工作是:
% \begin{verbatim}
%   tex.sprint(cat_lp, global_flag, '\\protected\\expandafter\\def\\csname ',
%     (cstemp==' ') and '\\space' or cstemp, '\\endcsname{\\ltj@cur'..
%     (jfm_dir == 'yoko' and 'j' or 't') .. 'fnt', fn, '\\relax}')
% \end{verbatim}
% \tn{CS} 的作用就是把 \tn{ltj@curjfnt} 设置为刚才定义的字体的 \texttt{font.id}。
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \ctex_ltj_extract_font:
  {
    \get@external@font
    \ctex_ltj_if_alternate_shape_exist:nT { \curr@fontshape }
      {
        \tl_set:Nx \external@font
          { \exp_after:wN \@@_patch_external_font:w \external@font }
      }
    \exp_after:wN \globaljfont \font@name \external@font \scan_stop:
%    \end{macrocode}
% 这里 \tn{font@name} 不会直接改变当前字体,而 \tn{DeclareFontFamily} 和
% \tn{DeclareFontShape} 的最后一个参数通常要使用 \tn{font} 来引用当前字体。
% 为此,我们在分组内启用之前定义的字体,以便能得到正确的 \tn{font}。对字体参数的
% 赋值总是全局的,不会受到分组的影响。
%    \begin{macrocode}
    \font@name
    \ctex_ltj_use_jfont:
    \use:c { \f@encoding + \f@family }
    \use:c { \curr@fontshape }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ctex_ltj_use_jfont:}
% 使用 jfont,确保当前的 \tn{font} 是 jfont。
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \ctex_ltj_use_jfont:
  { \tex_setfontid:D \ltj@curjfnt }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_subst_font:}
% \tn{do@subst@correction} 在设置通过 \texttt{sub} 或者 \texttt{ssub} 函数定义的
% 字体时会用到。如果没有设置 \opt{SlantedFont},\pkg{fontspec} 会设置
% \tn{itdefault} 作为 \tn{sldefault} 的替代字形,因而会用到这个函数。它的本来定义是:
% \begin{verbatim}
%   \def\do@subst@correction{%
%       \xdef\subst@correction{%
%          \font@name
%          \global\expandafter\font
%            \csname \curr@fontshape/\f@size\endcsname
%            \noexpand\fontname\font
%           \relax}%
%       \aftergroup\subst@correction
%   }
% \end{verbatim}
% 我们在这里不需要定义新字体,而是设置对应字体的命令。
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \ctex_ltj_subst_font:
  {
    \ctex_ltj_if_alternate_shape_exist:nF { \curr@fontshape }
      {
        \group_begin:
        \tl_set_eq:NN \CJK@family \f@family
        \cs_if_exist:cF { \l_@@_current_font_tl  }
          {
            \cs_gset_protected_nopar:Npx \subst@correction
              {
                \cs_new_eq:NN
                  \exp_not:c { \l_@@_current_font_tl }
                  \font@name
              }
            \group_insert_after:N \group_insert_after:N
            \group_insert_after:N \subst@correction
          }
        \group_end:
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int,TF]{\ctex_ltj_if_alternate_shape_exist:n}
% 即 \pkg{LuaTeX-ja} 中的 \tn{ltj@@does@alt@set},判断是否存在替代字体。
%    \begin{macrocode}
\prg_new_conditional:Npnn \ctex_ltj_if_alternate_shape_exist:n #1 { T , F , TF }
  {
    \@@_if_alt_set:nT {#1} { \prg_return_true: \use_none:n }
    \prg_return_false:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_patch_external_font:w}
%    \begin{macrocode}
\cs_new:Npn \@@_patch_external_font:w #1 ~ at
  { \ctex_ltj_patch_external_font:n {#1} ~ at }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_select_alternate_font:}
% 在 \tn{selectfont} 中更新替代字体。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_select_alternate_font:
  {
    \ctex_ltj_if_alternate_shape_exist:nT { \l_@@_current_shape_tl }
      {
        \ctex_ltj_pickup_alt_font:nn
          { \l_@@_current_shape_tl } { \f@size }
      }
  }
\tl_new:N \l_@@_current_shape_tl
\tl_set:Nn \l_@@_current_shape_tl
  { \CJK@encoding / \CJK@family / \f@series / \f@shape }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ltj@pickup@altfont@auxy}
% 被用在函数 |output_alt_font_cmd| 中,作用是定义替代字体。
%    \begin{macrocode}
\cs_new_protected:Npn \ltj@pickup@altfont@auxy #1
  {
    \cs_if_exist:cF { #1/\f@size }
      {
        \group_begin:
          \use:e { \exp_not:N \split@name #1 / \f@size } \@nil
          \@@_push_fontname:n { \curr@fontshape / \f@size }
          \ctex_ltj_pickup_font:
        \group_end:
        \@@_pop_fontname:
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ltj@pickup@altfont@copy}
% 被用在函数 |pickup_alt_font_a| 中。\tn{ltj@@getjfontnumber} 的作用是将字体命令
% |#1| 对应的 \texttt{font.id} 保存到 \tn{ltj@tempcntc} 中。
%    \begin{macrocode}
\cs_new_protected:Npn \ltj@pickup@altfont@copy #1#2
  {
    \ltj@@@@getjfontnumber #1
    \@@_pickup_alt_font:Nn \ltj@tempcntc {#2}
  }
%    \end{macrocode}
% \end{macro}
%
% \paragraph{数学字体族}
%
% 以下内容来自 \file{lltjfont.sty},目的是让汉字可以在数学环境中直接使用。
%
% \begin{macro}[int]{\ctex_ltj_if_jfont:nTF}
% 参数 |#1| 是一个 \LaTeXe{} 编码名称或者字体命令。\LaTeXe{} 字体命令的一般形式是:
% \begin{quote}\ttfamily\small
%   \textbackslash\meta{encoding}/\meta{family}/\meta{series}/\meta{shape}
% \end{quote}
% 通过截取名字中的 \meta{encoding} 来判断是否是 jfont。
% 最后会设置 \tn{ifin@} 为对应的 \tn{iftrue} 或者 \tn{iffalse}。
%    \begin{macrocode}
\cs_new:Npn \ctex_ltj_if_jfont:nTF #1
  {
    \ctex_ltj_is_kenc:n { \@@_ltj_if_jfont:w #1 / \q_stop }
    \ifin@ \exp_after:wN \use_i:nn \else: \exp_after:wN \use_ii:nn \fi:
  }
\cs_new:Npn \@@_ltj_if_jfont:w #1 / #2 \q_stop
  {#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_if_jfont_math:NTF}
% |#1| 是一个形式为 |\M@|\meta{encoding} 的命令,它由 \tn{DeclareFontEncoding} 的
% 第三个参数来定义。
%    \begin{macrocode}
\cs_new:Npn \ctex_ltj_if_jfont_math:NTF #1
  { \exp_after:wN \@@_if_jfont_math:w \token_to_str:N #1 \q_stop }
\group_begin:
  \char_set_catcode_other:N M
  \cs_new:Npn \@@_if_jfont_math:w #1 M #2#3 \q_stop
    { \ctex_ltj_if_jfont:nTF {#3} }
\group_end:
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\getanddefine@fonts,\ctex_ltj_get_and_define_fonts:nN}
% 在使用的场合,\tn{escapechar} 已经被设置成 $-1$,使用 \cs{token_to_str:N} 就
% 可以得到名字,不必使用 \cs{cs_to_str:N}。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_get_and_define_fonts:nN #1#2
  {
    \exp_args:No \ctex_ltj_if_jfont:nTF { \token_to_str:N #2 }
      { \ctex_ltj_get_and_define_fonts_ja:nN }
      { \ctex_ltj_get_and_define_fonts_al:nN }
      {#1} #2
  }
\cs_new_eq:NN \ctex_ltj_get_and_define_fonts_al:nN \getanddefine@fonts
\cs_set_eq:NN \getanddefine@fonts \ctex_ltj_get_and_define_fonts:nN
\cs_new_protected:Npn \ctex_ltj_get_and_define_fonts_ja:nN #1#2
  {
    \tl_gset:Nx \font@name { \use:c { \token_to_str:N #2 / \tf@size } }
    \ctex_ltj_pickup_font: \tl_set_eq:NN \textfont@name \font@name
    \tl_gset:Nx \font@name { \use:c { \token_to_str:N #2 / \sf@size } }
    \ctex_ltj_pickup_font: \tl_set_eq:NN \scriptfont@name \font@name
    \tl_gset:Nx \font@name { \use:c { \token_to_str:N #2 / \ssf@size } }
    \ctex_ltj_pickup_font:
    \tl_put_right:Nx \math@fonts
      {
        \ltj@setpar@global
        \ltj@@@@set@stackfont #1 , \textfont@name   \c_colon_str { MJT }
        \ltj@@@@set@stackfont #1 , \scriptfont@name \c_colon_str { MJS }
        \ltj@@@@set@stackfont #1 , \font@name       \c_colon_str { MJSS }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\use@mathgroup,\ctex_ltj_use_math_group:Nn}
% 在使用 \pkg{unicode-math} 宏包时,\cs{ctex_ltj_math_group_hook:} 将被重定义。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_use_math_group:Nn #1#2
  {
    \mode_if_math:T
      {
        \math@bgroup
          \cs_if_eq:cNF { M@ \f@encoding } #1 {#1}
          \ctex_ltj_math_group_hook:
          \ctex_ltj_if_jfont_math:NTF #1
            { \jfam } { \mathgroup } #2 \scan_stop:
        \math@egroup
      }
  }
\cs_new_eq:NN \ctex_ltj_math_group_hook: \prg_do_nothing:
\cs_set_eq:NN \use@mathgroup \ctex_ltj_use_math_group:Nn
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.4.3}{2016/08/25}{更新 \pkg{unicode-math} 补丁。}
% \changes{v2.4.9}{2017/02/27}{调整 \pkg{unicode-math} 补丁的代码顺序。}
% 对 \pkg{unicode-math} 的补丁主要是将 \file{unicode-math-table.tex} 中的数学符号设置为
% \pkg{luatexja} 中的数学字母。
% 本段代码应放在 \cs{ctex_ltj_math_group_hook:} 的定义之后,避免因宏包载入顺序而造成的编译错误。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_set_math_letter:NN #1#2
  {
    \group_begin:
      \cs_set_protected:Npn #1 ##1##2##3
        { \ltjsetmathletter { ##1 } }
      #2
    \group_end:
  }
\ctex_at_end_package:nn { unicode-math }
  {
    \cs_if_exist:NTF \um_input_math_symbol_table:
      {
        \ctex_ltj_set_math_letter:NN
          \um_sym:nnn
          \um_input_math_symbol_table:
      }
      {
        \cs_set_eq:NN \use@mathgroup \ctex_ltj_use_math_group:Nn
        \cs_set_protected:Npn \ctex_ltj_math_group_hook:
          { \__um_switchto_literal: }
        \ctex_ltj_set_math_letter:NN
          \__um_sym:nnn
          \__um_input_math_symbol_table:
      }
  }
%    \end{macrocode}
%
% \paragraph{字体族的定义与使用}
%
% \changes{v2.5.9}{2022/05/26}{依赖 \pkg{chinese-jfm} 宏包。}
%
% \begin{macro}[int]{\ctex_set_jfm:n}
% \begin{variable}{\l_@@_jfm_tl, \l_@@_redirect_jfm_prop}
% 设置 \texttt{JFM},需要进行一些重定向操作。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_set_jfm:n #1
  {
    \prop_get:NnNF \l_@@_redirect_jfm_prop {#1} \l_@@_jfm_tl
      { \tl_set:Nn \l_@@_jfm_tl {#1} }
  }
\cs_generate_variant:Nn \ctex_set_jfm:n { o }
\prop_new:N \l_@@_redirect_jfm_prop
\prop_set_from_keyval:Nn \l_@@_redirect_jfm_prop
  {
    plain    = mono ,
    quanjiao = zh_CN / quanjiao ,
    banjiao  = zh_CN / banjiao ,
    kaiming  = zh_CN / kaiming
  }
\keys_define:nn { ctex_ltj / fontspec }
  {
    JFM           .code:n = \ctex_set_jfm:n {#1} ,
    JFM .value_required:n = true
  }
\tl_new:N \l_@@_jfm_tl
\ctex_set_jfm:o { \l__ctex_punct_tl }
%    \end{macrocode}
% \end{variable}
% \end{macro}
%
% \begin{macro}[int]{\CJK@encoding}
% 在 \LaTeX 下,\pkg{LuaTeX-ja} 依赖字体编码来实现特殊设置。例如上述的
% \cs{ctex_ltj_if_jfont:nTF} 就是通过判断编码来实现的,它在设置数学字体时会用到。所以
% 不应该与西文共用 \texttt{EU2}。定义字体族 song 为 \tn{CJK@encoding} 的默认替换
% 字体。下划线 |_| 不在 \tn{nfss@catcodes} 里,可以放心使用。
%    \begin{macrocode}
\tl_const:Nn \CJK@encoding { LTJY3 }
\DeclareFontEncoding { \CJK@encoding } { } { }
\use:e
  {
    \exp_not:N \DeclareFontSubstitution
      { \CJK@encoding } { song } { \mddefault } { \shapedefault }
  }
\ctex_ltj_add_kyenc:n { \CJK@encoding }
\DeclareFontFamily { \CJK@encoding } { song } { }
\DeclareFontShape { \CJK@encoding } { song } { \mddefault } { \shapedefault }
  { <-> psft:SimSun:cid=Adobe-GB1-5;jfm=\l_@@_jfm_tl } { }
\DeclareFontShape { \CJK@encoding } { song } { \bfdefault } { \shapedefault }
  { <-> psft:SimHei:cid=Adobe-GB1-5;jfm=\l_@@_jfm_tl } { }
\tl_const:Nn \c_@@_math_tl { CJKmath }
\DeclareSymbolFont { \c_@@_math_tl }
  { \CJK@encoding } { song } { \mddefault } { \shapedefault }
\SetSymbolFont { \c_@@_math_tl } { bold }
  { \CJK@encoding } { song } { \bfdefault } { \shapedefault }
\int_const:Nn \c_@@_math_fam_int { \use:c { sym \c_@@_math_tl } }
\jfam \c_@@_math_fam_int
%    \end{macrocode}
% \end{macro}
%
% 这是 \pkg{luatexja-fontspec} 中新增的一些字体选项。
%    \begin{macrocode}
\newfontfeature { CID }     {    cid = #1 }
\newfontfeature { JFM }     {    jfm = #1 }
\newfontfeature { JFM-var } { jfmvar = #1 }
%    \end{macrocode}
%
% 在新版本的 \pkg{fontspec} 中,\cs{__fontspec_fontname_wrap:n} 变成了私有函数。
%    \begin{macrocode}
\keys_define:nn { fontspec-preparse-external }
  {
    NoEmbed .code:n =
      { \cs_set_eq:NN \__fontspec_fontname_wrap:n \@@_noembed_wrap:n }
  }
\cs_new:Npn \@@_noembed_wrap:n #1 { psft: #1 }
%    \end{macrocode}
%
% \begin{macro}[int]{\ctex_ltj_set_family:nnn}
% 将自定义的字体族名与 \pkg{fontspec} 实际设置的名字对应起来。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_set_family:nnn #1#2#3
  {
    \group_begin:
    \clist_clear:N \l_@@_char_range_clist
    \prop_clear:N \l_@@_alternate_prop
    \tl_set:Nn \l_@@_base_CJKfamily_tl {#1}
    \keys_set_known:nnN { ctex_ltj / fontspec } {#2} \l_@@_tmp_tl
    \clist_set:No \l_@@_font_options_clist { \l_@@_tmp_tl }
    \ctex_ltj_set_alternate_family:nnF {#1} {#3}
      {
        \prop_gput:Nnn \g_@@_family_font_name_prop {#1} {#3}
        \prop_gput:Nno \g_@@_family_font_options_prop
          {#1} { \l_@@_font_options_clist }
        \@@_update_family_uid:N \l_@@_font_options_clist
        \@@_use_global_options:N \l_@@_font_options_clist
        \@@_gset_family_cs:nn {#1} {#3}
      }
    \group_end:
  }
\tl_new:N \l_@@_base_CJKfamily_tl
\clist_new:N \l_@@_font_options_clist
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_use_global_options:N}
% 应用默认字体选项,并总是设置 \opt{JFM} 和 \opt{NFSSEncoding} 。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_use_global_options:N #1
  {
    \clist_concat:NNN #1 \g_@@_default_features_clist #1
    \clist_put_left:Nx #1
      { NFSSEncoding = \CJK@encoding , JFM = \l_@@_jfm_tl }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}
%  {\g_@@_family_name_prop,\g_@@_family_font_name_prop,\g_@@_family_font_options_prop}
% 分别保存 \pkg{fontspec} 设置的字体族名、字体名称和字体选项。
%    \begin{macrocode}
\prop_new:N \g_@@_family_name_prop
\prop_new:N \g_@@_family_font_name_prop
\prop_new:N \g_@@_family_font_options_prop
%    \end{macrocode}
% \end{variable}
%
% \begin{macro}{\@@_check_family:n}
% 删除重复的定义,清除替代字体的先前设置。
%   \begin{macrocode}
\cs_new_protected:Npn \@@_check_family:n #1
  {
    \prop_gpop:NnNT \g_@@_family_font_name_prop {#1} \l_@@_tmp_tl
      {
        \cs_undefine:c { \@@_family_csname:n {#1} }
        \cs_undefine:c { \@@_alternate_cs:n {#1} }
        \prop_gpop:NnNT \g_@@_family_name_prop {#1} \l_@@_base_family_tl
          {
            \use:c { \@@_alternate_cs:n { clear / #1 } }
            \cs_undefine:c { \@@_alternate_cs:n { clear / #1 } }
            \cs_undefine:c { \@@_alternate_cs:n { reset / #1 } }
            \prop_gremove:Nn \g_@@_reset_alternate_prop {#1}
          }
        \msg_warning:nnxx { ctex } { redefine-family } {#1} { \l_@@_tmp_tl }
      }
  }
\tl_new:N \l_@@_tmp_tl
\msg_new:nnn { ctex } { redefine-family }
  { Redefining~CJKfamily~`\@@_msg_family_map:n {#1}'~(#2). }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_gset_family_cs:nn}
% 在设置字体时,实际上并不是马上就定义。而是只保存相关参数,在通过 \tn{CJKfamily}
% 第一次使用时才定义。需要注意将编码改为 \tn{CJK@encoding}。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_gset_family_cs:nn #1#2
  {
    \cs_gset_protected:cpx { \@@_family_csname:n {#1} }
      {
        \group_begin:
        \exp_not:n { \cs_set_eq:NN \CJKfamily \use_none:n }
        \exp_not:n { \fontspec_gset_family:Nnn \g_@@_fontspec_family_tl }
          { \exp_not:o { \l_@@_font_options_clist } } {#2}
        \prop_gput:Nno \exp_not:N \g_@@_family_name_prop {#1}
          { \exp_not:N \g_@@_fontspec_family_tl }
        \@@_set_alternate_family:n {#1}
        \group_end:
      }
  }
\tl_new:N \l_@@_base_family_tl
\tl_new:N \g_@@_fontspec_family_tl
\cs_new:Npn \@@_family_csname:n #1 { ctex_ltj/family/#1 }
\cs_new_protected:Npn \@@_set_alternate_family:n #1
  {
    \tl_set:Nn \l_@@_base_CJKfamily_tl {#1}
    \tl_set_eq:NN \l_@@_base_family_tl \g_@@_fontspec_family_tl
    \cs_if_exist_use:c { \@@_alternate_cs:n { reset / #1 } }
    \cs_if_exist_use:c { \@@_alternate_cs:n {#1} }
  }
\cs_new:Npn \@@_alternate_cs:n #1 { ctex_ltj/alternate_family/#1 }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CJKfamily}
% 切换字体。
%    \begin{macrocode}
\NewDocumentCommand \CJKfamily { m }
  { \ctex_ltj_switch_family:x {#1} \tex_ignorespaces:D }
\cs_new_protected:Npn \ctex_ltj_switch_family:n #1
  {
    \ctex_ltj_family_if_exist:nNTF {#1} \CJK@family
      {
        \tl_set:Nn \l_ctex_ltj_family_tl {#1}
        \selectfont
      }
      { \@@_family_unknown_warning:n {#1} }
  }
\tl_new:N \l_ctex_ltj_family_tl
\cs_generate_variant:Nn \ctex_ltj_switch_family:n { x }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int,TF]{\ctex_ltj_family_if_exist:nN}
% 判断 CJK 字体族 |#1| 是否存在,若存在则把实际族名保存到 |#2| 中。
%    \begin{macrocode}
\prg_new_protected_conditional:Npnn \ctex_ltj_family_if_exist:nN #1#2 { T , F , TF }
  {
    \prop_get:NnNTF \g_@@_family_name_prop {#1} #2
      { \prg_return_true: }
      {
        \cs_if_exist_use:cTF { \@@_family_csname:n {#1} }
          {
            \tl_set_eq:NN #2 \g_@@_fontspec_family_tl
            \prg_return_true:
          }
          { \prg_return_false: }
      }
  }
\prg_generate_conditional_variant:Nnn \ctex_ltj_family_if_exist:nN { x } { T , F , TF }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_family_unknown_warning:n}
%    \begin{macrocode}
\cs_new_protected:Npn \@@_family_unknown_warning:n #1
  {
    \prop_if_empty:NF \g_@@_family_font_name_prop
      {
        \seq_if_in:NnF \g_@@_unknown_family_seq {#1}
          {
            \seq_gput_right:Nn \g_@@_unknown_family_seq {#1}
            \msg_warning:nnn { ctex } { family-unknown } {#1}
          }
      }
  }
\seq_new:N \g_@@_unknown_family_seq
\msg_new:nnn { ctex } { family-unknown }
  {
    Unknown~CJK~family~`\@@_msg_family_map:n {#1}'~is~being~ignored.\\
    Try~to~use~`\@@_msg_def_family_map:n {#1}'~to~define~it.
  }
\cs_new:Npn \@@_msg_def_family_map:n #1
  {
    \str_case_e:nnF {#1}
      {
        \CJKrmdefault { \token_to_str:N \setCJKmainfont }
        \CJKsfdefault { \token_to_str:N \setCJKsansfont }
        \CJKttdefault { \token_to_str:N \setCJKmonofont }
      }
      { \token_to_str:N \setCJKfamilyfont \{ #1 \} }
    [...]\{...\}
  }
\cs_new:Npn \@@_msg_family_map:n #1
  {
    \str_case_e:nnF {#1}
      {
        \CJKrmdefault { \token_to_str:N \CJKrmdefault }
        \CJKsfdefault { \token_to_str:N \CJKsfdefault }
        \CJKttdefault { \token_to_str:N \CJKttdefault }
      }
      {#1}
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_fontspec:nn}
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_fontspec:nn #1#2
  {
    \prop_get:NnNTF \g_@@_fontspec_prop
      { CJKfontspec/#1/#2/id } \l_ctex_ltj_family_tl
      { \ctex_ltj_switch_family:x { \l_ctex_ltj_family_tl } }
      {
        \int_gincr:N \g_@@_family_int
        \@@_fontspec:enn
          { CJKfontspec ( \int_use:N \g_@@_family_int ) }
          {#1} {#2}
      }
  }
\cs_new_protected:Npn \ctex_ltj_fontspec:ee #1#2
  { \use:e { \ctex_ltj_fontspec:nn {#1} {#2} } }
\cs_new_protected:Npn \@@_fontspec:nnn #1#2#3
  {
    \bool_if:NT \l_@@_add_alternate_bool
      {
        \cs_if_free:cF
          { \@@_alternate_cs:n { reset / \l_ctex_ltj_family_tl } }
          {
            \cs_gset_eq:cc
              { \@@_alternate_cs:n { reset / #1 } }
              { \@@_alternate_cs:n { reset / \l_ctex_ltj_family_tl } }
            \cs_gset_eq:cc
              { \@@_alternate_cs:n { clear / #1 } }
              { \@@_alternate_cs:n { clear / \l_ctex_ltj_family_tl } }
          }
        \bool_set_false:N \l_@@_add_alternate_bool
      }
    \prop_gput:Nnn \g_@@_fontspec_prop { CJKfontspec/#2/#3/id } {#1}
    \ctex_ltj_set_family:nnn {#1} {#2} {#3}
    \ctex_ltj_switch_family:n {#1}
  }
\cs_generate_variant:Nn \@@_fontspec:nnn { e }
\prop_new:N \g_@@_fontspec_prop
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]
% {\ctex_ltj_add_font_features:n,\ctex_ltj_add_font_features:nn}
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_add_font_features:n #1
  { \ctex_ltj_add_font_features:xn { \l_ctex_ltj_family_tl } {#1} }
\cs_new_protected:Npn \ctex_ltj_add_font_features:nn #1#2
  {
    \prop_get:NnNTF \g_@@_family_font_name_prop
      {#1} \l_@@_tmp_tl
      {
        \prop_get:NnN \g_@@_family_font_options_prop
          {#1} \l_@@_font_options_clist
        \clist_put_right:Nn \l_@@_font_options_clist {#2}
        \bool_set_true:N \l_@@_add_alternate_bool
        \ctex_ltj_fontspec:ee
          { \exp_not:o { \l_@@_font_options_clist } }
          { \exp_not:o { \l_@@_tmp_tl } }
      }
      { \msg_warning:nn { ctex } { addCJKfontfeature-ignored } }
  }
\bool_new:N \l_@@_add_alternate_bool
\cs_generate_variant:Nn \ctex_ltj_add_font_features:n  { x }
\cs_generate_variant:Nn \ctex_ltj_add_font_features:nn { x }
\msg_new:nnn { ctex } { addCJKfontfeature-ignored }
  {
    \token_to_str:N \addCJKfontfeature (s)~ignored.\\
    It~cannot~be~used~with~a~font~that~wasn't~selected~by~ctex.
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_pass_args:nnnn}
% 为了支持字体属性可选项在前在后两种语法,给出两个辅助工具,自带展开功能。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_pass_args:nnnn #1#2#3#4
  {
    \tl_if_novalue:nTF {#2}
      { \@@_post_arg:w {#1} {#3} {#4} }
      {
        \use:e { #1 {#2} {#3} }
        #4
      }
  }
\NewDocumentCommand \@@_post_arg:w { m m m O { } }
  {
    \use:e { #1 {#4} {#2} }
    #3
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.4.6}{2016/11/20}{支持字体属性可选项在后的新语法。}
%
% \begin{macro}[int]
% {\setCJKfamilyfont,\newCJKfontfamily,\CJKfontspec,\addCJKfontfeatures}
%    \begin{macrocode}
\NewDocumentCommand \setCJKfamilyfont { m o m }
  {
    \@@_pass_args:nnnn
      { \ctex_ltj_set_family:nnn {#1} } {#2} {#3}
      { }
  }
\NewDocumentCommand \newCJKfontfamily { o m o m }
  {
    \tl_set:Nx \l_@@_tmp_tl
      { \tl_if_novalue:nTF {#1} { \cs_to_str:N #2 } {#1} }
    \cs_new_protected:Npx #2
      { \ctex_ltj_switch_family:n { \l_@@_tmp_tl } }
    \@@_pass_args:nnnn
      { \ctex_ltj_set_family:nnn { \l_@@_tmp_tl } } {#3} {#4}
      { }
  }
\NewDocumentCommand \CJKfontspec { o m }
  {
    \@@_pass_args:nnnn
      { \ctex_ltj_fontspec:nn } {#1} {#2}
      { \tex_ignorespaces:D }
  }
\NewDocumentCommand \addCJKfontfeatures { m }
  {
    \ctex_ltj_add_font_features:x {#1}
    \tex_ignorespaces:D
  }
\cs_new_eq:NN \addCJKfontfeature \addCJKfontfeatures
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]
% {\setCJKmainfont,\setCJKsansfont,\setCJKmonofont,
%  \setCJKmathfont,\defaultCJKfontfeatures}
%    \begin{macrocode}
\NewDocumentCommand \setCJKmainfont { o m }
  {
    \@@_pass_args:nnnn
      { \ctex_ltj_set_family:nnn { \CJKrmdefault } } {#1} {#2}
      { \normalfont }
  }
\cs_new_eq:NN \setCJKromanfont \setCJKmainfont
\NewDocumentCommand \setCJKsansfont { o m }
  {
    \@@_pass_args:nnnn
      { \ctex_ltj_set_family:nnn { \CJKsfdefault } } {#1} {#2}
      { \normalfont }
  }
\NewDocumentCommand \setCJKmonofont { o m }
  {
    \@@_pass_args:nnnn
      { \ctex_ltj_set_family:nnn { \CJKttdefault } } {#1} {#2}
      { \normalfont }
  }
\NewDocumentCommand \setCJKmathfont { o m }
  {
    \@@_pass_args:nnnn
      { \ctex_ltj_set_family:nnn { \c_@@_math_tl } } {#1} {#2}
      { }
  }
\NewDocumentCommand \defaultCJKfontfeatures { m }
  { \clist_gset:Nn \g_@@_default_features_clist {#1} }
\clist_new:N \g_@@_default_features_clist
\@onlypreamble \setCJKmainfont
\@onlypreamble \setCJKsansfont
\@onlypreamble \setCJKmonofont
\@onlypreamble \setCJKmathfont
\@onlypreamble \setCJKromanfont
\@onlypreamble \defaultCJKfontfeatures
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.4.8}{2017/02/23}
%   {解决与 \pkg{fontspec} 2017/01/24 v2.5d 的字体族匹配兼容问题。}
%
% \begin{macro}[int]{\ctex_ltj_ensure_default_family:}
% 在导言区结束确认 \tn{CJKfamilydefault} 确实存在。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_ensure_default_family:
  {
    \prop_if_empty:NF \g_@@_family_font_name_prop
      {
        \ctex_ltj_family_if_exist:xNF { \CJKfamilydefault } \l_@@_tmp_tl
          {
            \str_if_eq:eeTF { \CJKfamilydefault } { \CJKrmdefault }
              { \use:n }
              {
                \ctex_ltj_family_if_exist:xNTF { \CJKrmdefault } \l_@@_tmp_tl
                  { \tl_gset:Nn \CJKfamilydefault { \CJKrmdefault } \use_none:n }
                  { \use:n }
              }
              {
                \prop_map_inline:Nn \g_@@_family_font_name_prop
                  {
                    \prop_map_break:n
                      { \tl_gset_rescan:Nnn \CJKfamilydefault { } { ##1 } }
                  }
              }
          }
        \normalfont
        \ctex_ltj_update_mathfont:
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_update_mathfont:}
% 更新数学字体为实际的字体。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_update_mathfont:
  {
    \ctex_ltj_family_if_exist:xNTF { \c_@@_math_tl } \l_@@_tmp_tl
      { \ctex_ltj_update_mathfont:n { \l_@@_tmp_tl } }
      {
        \ctex_ltj_family_if_exist:xNT { \CJKfamilydefault } \l_@@_tmp_tl
          { \ctex_ltj_update_mathfont:n { \l_@@_tmp_tl } }
      }
  }
\cs_new_protected:Npn \ctex_ltj_update_mathfont:n #1
  {
    \tl_const:Nx \c_@@_math_family_tl {#1}
    \DeclareSymbolFont { \c_@@_math_tl } { \CJK@encoding }
      { \c_@@_math_family_tl } { \mddefault } { \shapedefault }
    \cs_if_free:cTF
      { \CJK@encoding/\c_@@_math_family_tl/\bfdefault/\shapedefault }
      {
        \SetSymbolFont { \c_@@_math_tl } { bold } { \CJK@encoding }
          { \c_@@_math_family_tl } { \mddefault } { \shapedefault }
      }
      {
        \SetSymbolFont { \c_@@_math_tl } { bold } { \CJK@encoding }
          { \c_@@_math_family_tl } { \bfdefault } { \shapedefault }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \paragraph{替代字体的设置}
%
% \changes{v2.5}{2020/04/30}{重构字体选项 \opt{AlternateFont}。}
%
% \begin{macro}{AlternateFont,CharRange}
% 设置替代字体的选项。
%    \begin{macrocode}
\keys_define:nn { ctex_ltj / fontspec }
  {
    AlternateFont  .code:n = \ctex_ltj_set_alternate_prop:n {#1} ,
    AlternateFont  .value_required:n = true ,
    CharRange .clist_set:N = \l_@@_char_range_clist ,
    CharRange .value_required:n = true
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_set_alternate_prop:n}
% 保存替代字体序列。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_set_alternate_prop:n #1
  { \clist_map_function:nN {#1} \@@_push_alternate_prop:n }
\cs_new_protected:Npn \@@_push_alternate_prop:n #1
  {
    \clist_set:Nx \l_@@_tmp_clist { \tl_head:n {#1} }
    \tl_remove_all:Nn \l_@@_tmp_clist { ~ }
    \exp_args:No \@@_push_alternate_prop:nn
      { \l_@@_tmp_clist } {#1}
  }
\cs_new_protected:Npn \@@_push_alternate_prop:nn #1
  {
    \prop_remove:Nn \l_@@_alternate_prop {#1}
    \prop_put:Nnn \l_@@_alternate_prop {#1}
  }
\clist_new:N \l_@@_tmp_clist
\prop_new:N \l_@@_alternate_prop
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_set_alternate_family:nnF}
% 如果在字体的选项中设置了 \opt{CharRange},则只设置替代字体。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_set_alternate_family:nnF
  {
    \clist_if_empty:NTF \l_@@_char_range_clist
      { \@@_set_family_aux:nnn }
      { \@@_set_alternate_family_aux:nnn }
  }
\cs_new_protected:Npn \@@_set_family_aux:nnn #1#2#3
  {
    \@@_check_family:n {#1}
    \prop_if_empty:NF \l_@@_alternate_prop
      { \ctex_ltj_save_alternate_seq:cn { \@@_alternate_cs:n {#1} } {#2} }
    #3
  }
\cs_new_protected:Npn \@@_set_alternate_family_aux:nnn #1#2#3
  { \ctex_ltj_set_alternate_family:nn {#1} {#2} }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_save_alternate_seq:Nn}
% 保存由 \opt{AlternateFont} 设置的替代字体序列。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_save_alternate_seq:Nn #1#2
  {
    \prop_map_inline:Nn \l_@@_alternate_prop
      { \@@_save_alternate_auxi:w ##2 { } \q_mark #1 {#2} }
  }
\cs_new_protected:Npn \@@_save_alternate_auxi:w #1#2#
  {
    \tl_if_blank:nTF {#2}
      { \@@_save_alternate_auxii:w {#1} }
      { \@@_save_alternate_auxii:w {#1} {#2} }
  }
\cs_new_protected:Npn \@@_save_alternate_auxii:w #1#2#3 #4 \q_mark #5#6
  {
    \clist_set:Nn \l_@@_char_range_clist {#1}
    \clist_set:Nn \l_@@_alternate_options_clist {#3}
    \@@_use_global_options:N \l_@@_alternate_options_clist
    \tl_if_blank:nTF {#2}
      { \tl_set:Nn \l_@@_tmp_tl {#6} }
      {
        \tl_set:Nx \l_@@_tmp_tl { \tl_trim_spaces:n {#2} }
        \tl_replace_all:Nnn \l_@@_tmp_tl { * } {#6}
      }
    \use:e
      {
        \ctex_ltj_save_alternate_family:Nnnn \exp_not:N #5
          { \exp_not:o { \l_@@_char_range_clist } }
          { \exp_not:o { \l_@@_alternate_options_clist } }
          { \exp_not:o { \l_@@_tmp_tl } }
      }
  }
\clist_new:N \l_@@_alternate_options_clist
\cs_generate_variant:Nn \ctex_ltj_save_alternate_seq:Nn { c }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_set_alternate_family:nn}
% 设置选项 \opt{CharRange} 范围内的替代字体。如果已经定义了主字体,我们也马上
% 定义替代字体,否则只保存起来备用。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_set_alternate_family:nn #1#2
  {
    \@@_update_family_uid:N \l_@@_font_options_clist
    \@@_use_global_options:N \l_@@_font_options_clist
    \ctex_ltj_set_alternate_family:coonn
      { \@@_alternate_cs:n {#1} }
      { \l_@@_char_range_clist }
      { \l_@@_font_options_clist } {#2} {#1}
  }
\cs_new_protected:Npn \ctex_ltj_set_alternate_family:Nnnnn #1#2#3#4#5
  {
    \prop_get:NnNT \g_@@_family_name_prop {#5} \l_@@_base_family_tl
      { \ctex_ltj_set_alternate_family:nnn {#2} {#3} {#4} }
    \ctex_ltj_save_alternate_family:Nnnn #1 {#2} {#3} {#4}
  }
\cs_generate_variant:Nn \ctex_ltj_set_alternate_family:Nnnnn { coo }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_save_alternate_family:Nnnn}
% 保存替代字体序列的定义,以备定义主字体时使用。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_save_alternate_family:Nnnn #1#2#3#4
  {
    \cs_if_exist:NF #1 { \cs_set_eq:NN #1 \prg_do_nothing: }
    \cs_gset_protected:Npx #1
      { \exp_not:o { #1 \ctex_ltj_set_alternate_family:nnn {#2} {#3} {#4} } }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_set_alternate_family:nnn}
% 实际定义替代字体族。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_set_alternate_family:nnn #1#2#3
  {
    \group_begin:
    \cs_set_eq:NN \CJKfamily \use_none:n
    \ctex_ltj_swap_cs:NN
      \DeclareFontShape@ \ctex_ltj_declare_alternate_shape:nnnnnn
    \tl_set:Nn \l_@@_char_range_clist {#1}
    \fontspec_set_family:Nnn \l_@@_alternate_family_tl {#2} {#3}
    \group_end:
  }
\tl_new:N \l_@@_alternate_family_tl
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_swap_cs:NN}
% 交换两个控制序列的意义。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_swap_cs:NN #1#2
  {
    \cs_set_eq:NN \@@_tmp:w #1
    \cs_set_eq:NN #1 #2
    \cs_set_eq:NN #2 \@@_tmp:w
    \cs_undefine:N \@@_tmp:w
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{LTJFONTUID}
% \begin{macro}{\@@_update_family_uid:N}
% \pkg{fontspec} 在一个字体族的选项和字体名称相同的时候,就不定义新字体。为了
% 避免混淆替代字体的设置,我们新定义一个虚拟的选项 \opt{LTJFONTUID},确保
% \pkg{fontspec} 对 CJK 字体族总是定义新字体。
%    \begin{macrocode}
\keys_define:nn { fontspec } { LTJFONTUID .code:n = }
\cs_new_protected:Npn \@@_update_family_uid:N #1
  {
    \int_gincr:N \g_@@_family_int
    \clist_put_right:Nx #1 { LTJFONTUID = \int_use:N \g_@@_family_int }
  }
\int_new:N \g_@@_family_int
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_declare_alternate_shape:nnnnnn}
% 在定义替代字体的字形时,通过字符范围与主字体的对应字形关联起来。
% \tn{DeclareFontShape@} 一个有六个参数,我们只需要使用它的第三个参数 \meta{series}
% 和第四个参数 \meta{shape}。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_declare_alternate_shape:nnnnnn #1#2#3#4#5#6
  {
    \ctex_ltj_declare_alternate_shape:nnnnnn {#1} {#2} {#3} {#4} {#5} {#6}
    \ctex_ltj_set_alternate_shape:Nnnnnnn \l_@@_char_range_clist
      { \l_@@_base_family_tl } {#3} {#4} {#2} {#3} {#4}
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_set_alternate_shape:Nnnnnnn}
% 与 \pkg{LuaTeX-ja} 的 \tn{DeclareAlternateKanjiFont} 的功能类似,区别是固定编码
% 为 \tn{CJK@encoding}。这个设置总是全局的。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_set_alternate_shape:Nnnnnnn #1#2#3#4#5#6#7
  {
    \clist_map_inline:Nn #1
      {
        \prop_get:NnNTF \g_@@_char_range_prop { ##1 } \l_@@_char_range_tl
          {
            \ctex_ltj_set_alternate_shape:nnN { #2/#3/#4 } { #5/#6/#7 }
              \l_@@_char_range_tl
          }
          { \ctex_ltj_set_alternate_shape:nnn { #2/#3/#4 } { #5/#6/#7 } { ##1 } }
      }
    \@@_save_alternate_shape:cn
      { \@@_alternate_cs:n { clear / \l_@@_base_CJKfamily_tl } }
      { \ctex_ltj_clear_alt_font:n { \CJK@encoding/#2/#3/#4 } }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_set_alternate_shape:nnn}
% 我们使用 \texttt{->} 而不是像 \pkg{LuaTeX-ja} 一样使用 \texttt{-} 作为区间的
% 分隔符。\pkg{LuaTeX-ja} 支持使用负数来引用由 \texttt{JFM} 设置的字符类。如果
% 使用 \texttt{-} 作为分隔符,那么负数单独使用时,就需要把它放在两层花括号之内
% (例如 |{{-1}}|),或者使用类似 |{-1}-{-1}| 的形式才不会解释错误。
%    \begin{macrocode}
\NewDocumentCommand \ctex_ltj_set_alternate_shape:nnn
  { m m > { \SplitArgument { 1 } { -> } } m }
  { \ctex_ltj_set_alternate_shape:nnnn {#1} {#2} #3 }
\cs_new_protected:Npn \ctex_ltj_set_alternate_shape:nnnn #1#2#3#4
  {
    \ctex_ltj_set_alternate_shape:e
      {
        \@@_range_normalization:nn {#3} {#4}
        { \CJK@encoding / \exp_not:n {#2} }
        { \CJK@encoding / \exp_not:n {#1} }
      }
  }
\cs_new_protected:Npn \ctex_ltj_set_alternate_shape:n #1
  {
    \ctex_ltj_set_alt_font:nnnn #1
    \@@_save_alternate_shape:cn
      { \@@_alternate_cs:n { reset / \l_@@_base_CJKfamily_tl } }
      { \ctex_ltj_set_alt_font:nnnn #1 }
  }
\cs_generate_variant:Nn \ctex_ltj_set_alternate_shape:n { e }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_set_alternate_shape:nnN}
% 若字符范围预先由 \texttt{declarecharrange} 声明,则可以直接使用。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_set_alternate_shape:nnN #1#2#3
  {
    \tl_map_inline:Nn #3
      {
        \ctex_ltj_set_alternate_shape:n
          {
            ##1
            { \CJK@encoding/#2 }
            { \CJK@encoding/#1 }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_save_alternate_shape:Nn}
% 将实际设置的替换字形保存起来用于清除或恢复。
% 暂时令 \cs{l_@@_base_family_tl} 为 \cs{scan_stop:} 是让它不被展开,使得替换
% 字体的设置可以在 \tn{addCJKfontfeature} 中直接使用。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_save_alternate_shape:Nn #1#2
  {
    \group_begin:
      \cs_if_exist:NF #1 { \cs_set_eq:NN #1 \prg_do_nothing: }
      \cs_set_eq:NN \l_@@_base_family_tl \scan_stop:
      \cs_gset_protected:Npx #1 { \exp_not:o {#1} #2 }
    \group_end:
  }
\cs_generate_variant:Nn \@@_save_alternate_shape:Nn { c }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{clearalternatefont,resetalternatefont}
% 清除和重置操作总是全局的。
%    \begin{macrocode}
\ctex_define:n
  {
    clearalternatefont    .code:n =
      { \clist_map_function:eN {#1} \ctex_ltj_clear_alternate_font:n } ,
    resetalternatefont    .code:n =
      { \clist_map_function:eN {#1} \ctex_ltj_reset_alternate_font:n } ,
    clearalternatefont .default:n = \l_ctex_ltj_family_tl ,
    resetalternatefont .default:n = \l_ctex_ltj_family_tl
  }
\cs_new_protected:Npn \ctex_ltj_clear_alternate_font:n #1
  {
    \group_begin:
      \ctex_ltj_family_if_exist:xNTF {#1} \l_@@_base_family_tl
        {
          \cs_if_exist_use:cT
            { \@@_alternate_cs:n { clear / #1 } }
            {
              \prop_gput:Nno \g_@@_reset_alternate_prop
                {#1} { \l_@@_base_family_tl }
              \tl_set_eq:NN \CJK@family \l_@@_base_family_tl
              \selectfont
            }
        }
        { \@@_family_unknown_warning:n {#1} }
    \group_end:
  }
\cs_new_protected:Npn \ctex_ltj_reset_alternate_font:n #1
  {
    \group_begin:
      \prop_gpop:NnNT \g_@@_reset_alternate_prop {#1} \CJK@family
        {
          \tl_set_eq:NN \l_@@_base_family_tl \CJK@family
          \use:c { \@@_alternate_cs:n { reset / #1 } }
          \selectfont
        }
    \group_end:
  }
\prop_new:N \g_@@_reset_alternate_prop
\cs_generate_variant:Nn \clist_map_function:nN { e }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{declarecharrange}
% 预先声明字符范围。
%    \begin{macrocode}
\ctex_define:n
  {
    declarecharrange .code:n = \ctex_ltj_declare_char_range:e {#1} ,
    declarecharrange .value_required:n = true
  }
\cs_new_protected:Npn \ctex_ltj_declare_char_range:n #1
  { \clist_map_inline:nn {#1} { \@@_declare_char_range:nn ##1 } }
\cs_generate_variant:Nn \ctex_ltj_declare_char_range:n { e }
\cs_new_protected:Npn \@@_declare_char_range:nn #1
  { \tl_trim_spaces_apply:nN {#1} \ctex_ltj_declare_char_range:nn }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_declare_char_range:nn}
% \begin{variable}{\g_@@_char_range_prop}
% |#1| 是名字,|#2| 是范围。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_declare_char_range:nn #1#2
  {
    \tl_clear:N \l_@@_char_range_tl
    \clist_map_function:nN {#2} \ctex_ltj_save_char_range:n
    \prop_gput:Nno \g_@@_char_range_prop {#1} { \l_@@_char_range_tl }
    \ctex_ltj_def_char_range_key:n {#1}
    \tl_clear:N \l_@@_char_range_tl
  }
\tl_new:N \l_@@_char_range_tl
\prop_new:N \g_@@_char_range_prop
%    \end{macrocode}
% \end{variable}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_save_char_range:n}
% 预先解释字符区间的意义。
%    \begin{macrocode}
\NewDocumentCommand \ctex_ltj_save_char_range:n
  { > { \SplitArgument { 1 } { -> } } m }
  { \ctex_ltj_save_char_range:nn #1 }
\cs_new_protected:Npn \ctex_ltj_save_char_range:nn #1#2
  {
    \tl_put_right:Nx \l_@@_char_range_tl
      { { \@@_range_normalization:nn {#1} {#2} } }
  }
\cs_new:Npn \@@_range_normalization:nn #1#2
  {
    \tl_if_novalue:nTF {#2}
      {
        { \int_eval:n {#1} }
        { \int_eval:n {#1} }
      }
      {
        { \int_eval:n { \tl_if_blank:nTF {#1} { \c_@@_range_min_int } {#1} } }
        { \int_eval:n { \tl_if_blank:nTF {#2} { \c_@@_range_max_int } {#2} } }
      }
  }
\int_const:Nn \c_@@_range_min_int { "80 }
\int_const:Nn \c_@@_range_max_int { \c_max_char_int }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_def_char_range_key:n}
% 在字体设置选项中定义字符范围键。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_def_char_range_key:n #1
  {
    \keys_if_exist:nnF { ctex_ltj / fontspec } {#1}
      {
        \keys_define:nn { ctex_ltj / fontspec }
          { #1 .code:n = \ctex_ltj_char_range_key:nn {#1} { ##1 } }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_ltj_char_range_key:nn}
% 如果字符范围键没有值,则只设置的这个字符范围内的替代字体。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_char_range_key:nn #1#2
  {
    \tl_if_blank:nTF {#2}
      { \clist_set:Nn \l_@@_char_range_clist {#1} }
      { \@@_push_alternate_prop:nn {#1} { {#1} #2 } }
  }
%    \end{macrocode}
% \end{macro}
%
% \paragraph{其他设置}
%
% 在抄录环境中禁用 \opt{autospacing} 和 \opt{autoxspacing}。然而,\pkg{LuaTeX-ja}
% 还是会使 JAchar 自动折行。没有看到有简单的禁用折行的办法,可能需要设置所有的
% JAchar 的 \opt{prebreakpenalty} 或 \opt{postbreakpenalty} 为 \texttt{10000}:
% \begin{verbatim}
%   \directlua
%     {
%       luatexja.isglobal = tex.globaldefs > 0 and "global" or ""
%       for i = 0x80, 0x10FFFF do
%         if luatexja.charrange.jcr_table_main[i] > 0 and
%            luatexja.charrange.jcr_table_main[i] < 218 and
%            luatexja.charrange.is_japanese_char_curlist(i) then
%           luatexja.stack.set_stack_table(luatexja.stack_table_index.PRE + i, 10000)
%         end
%       end
%     }
% \end{verbatim}
%    \begin{macrocode}
\AtBeginDocument
  {
    \ctex_appto_cmd:NnnTF \verbatim@font
      { \char_set_catcode_letter:n { 64 } }
      { \CTEX@verbatim@font@hook }
      { }
      { \ctex_patch_failure:N \verbatim@font }
  }
\cs_new_protected:Npn \CTEX@verbatim@font@hook
  { \ltjsetparameter { autospacing = false , autoxspacing = false } }
%    \end{macrocode}
%
% \begin{macro}{\@@@@italiccorr}
% \LaTeX{} 的倾斜校正也要重新定义。
%    \begin{macrocode}
\cs_set_eq:NN \@@@@italiccorr \/
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.4.12}{2018/01/27}{正确使用 \tn{ltjsetkanjiskip} 和 \tn{ltjsetxkanjiskip}。}
%
% \begin{macro}[int]{\ctex_ltj_set_kanjiskip:N,\ctex_ltj_set_xkanjiskip:N}
% \tn{ltjsetkanjiskip} 和 \tn{ltjsetxkanjiskip} 是相应的 \tn{ltjsetparameter}
% 的快捷方式,在使用他们时,要注意先使用 \tn{ltj@setpar@global}。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_ltj_set_kanjiskip:N
  { \ltj@setpar@global \ltjsetkanjiskip }
\cs_new_protected:Npn \ctex_ltj_set_xkanjiskip:N
  { \ltj@setpar@global \ltjsetxkanjiskip }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%<@@=ctex>
%</luatex>
%    \end{macrocode}
%
% \subsubsection{\pkg{ctex-engine-uptex.def}}
%
%    \begin{macrocode}
%<*uptex|aptex>
%    \end{macrocode}
%
% \changes{v2.4}{2016/02/28}{初步支持 \upLaTeX。}
% \changes{v2.4.15}{2019/04/05}{显式补丁 \upLaTeX 的 \tn{rmfamily} 等字体命令。}
%
% 按 \pkg{CJK} 的命名习惯模拟 \tn{CJKfamily}。
%    \begin{macrocode}
\NewDocumentCommand \CJKfamily { m }
  { \kanjifamily {#1} \selectfont }
%    \end{macrocode}
%
% \changes{v2.4.15}{2019/04/05}{将 \upLaTeX 的默认字体由 \texttt{mc} 改为
%   \texttt{zhrm},并启用 \tn{jfam}。}
%
% 将 \upLaTeX 的默认字体由 |mc| 改为 |zhrm|,并启用 \tn{jfam}。
%    \begin{macrocode}
\DeclareErrorKanjiFont    {JY2}{zhrm}{m}{n}{10}
\DeclareKanjiSubstitution {JY2}{zhrm}{m}{n}
\DeclareKanjiSubstitution {JT2}{zhrm}{m}{n}
\DeclareSymbolFont{mincho}{JY2}{zhrm}{m}{n}
\SetSymbolFont{mincho}{bold}{JY2}{zhrm}{bx}{n}
\jfam \symmincho
%    \end{macrocode}
%
% \begin{macro}[int]{\em}
% \changes{v2.4.2}{2016/05/15}{兼容 \upLaTeX{} 2016/05/07u00 的定义。}
% 取消 \upLaTeX{} 对 \tn{em} 使用 |\mcfamily|、|\gtfamily| 命令的重定义,恢复
% \LaTeXe{} 对 \tn{em} 的原始定义。如果用户已经重定义了 \tn{em},则新定义保持
% 不变。\upLaTeX{} 2016/05/07u00 的定义有所变化,这一行为可以由用户通过 \pkg{platexrelease}
% 包改变,需要分支处理。
%    \begin{macrocode}
\ctex_patch_cmd_once:NnnnTF \em
  { \ExplSyntaxOff }
  { \eminnershape \else \gtfamily \itshape }
  { \eminnershape \else \itshape }
  { }
  {
    \ctex_patch_cmd:Nnn \em
      { \mcfamily \upshape \else \gtfamily \itshape }
      { \eminnershape \else \itshape }
  }
\cs_set_nopar:Npn \eminnershape { \upshape }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.4}{2016/04/24}{正确设置 \upTeX{} 下字体命令。}
% \begin{macro}[int]{\ctex_set_upfamily:nnn}
% 将 NFSS 字体族 |#1| 设置为 JFM 字体名 |#2|,粗体形式字体名 |#3|。其中字体名
% 形如 |upzhserif|,不包括表示方向的后缀 |-h| 与 |-v|。粗体字体名为空时不设置该
% 字形。本命令不设置字体映射,需要复用已有的字体映射或另行设置。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_set_upfamily:nnn #1#2#3
  {
    \DeclareKanjiFamily{JY2}{#1}{}
    \DeclareKanjiFamily{JT2}{#1}{}
    \DeclareFontShape{JY2}{#1}{m}{n}{<->~ #2-h}{}
    \DeclareFontShape{JT2}{#1}{m}{n}{<->~ #2-v}{}
    \tl_if_empty:nF {#3}
      {
        \DeclareFontShape{JY2}{#1}{b}{n}{<->~ #3-h}{}
        \DeclareFontShape{JT2}{#1}{b}{n}{<->~ #3-v}{}
        \DeclareFontShape{JY2}{#1}{bx}{n}{<->~ #3-h}{}
        \DeclareFontShape{JT2}{#1}{bx}{n}{<->~ #3-v}{}
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_set_upmap:nnn}
% 设置 \upTeX{} 字体映射。|#1| 是形如 |upserif| 的 PS TFM 字体名,不带表示粗体
% 的后缀 |b| 与表示排版方向的后缀 |-h| 与 |-v|。|#2| 与 |#3| 是普通与粗体的实际
% 字体名。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_set_upmap:nnn #1#2#3
  {
    \ctex_set_zhmap:n
      {
        \special { pdf:mapline~#1-h~UniGB-UTF16-H~#2 }
        \special { pdf:mapline~#1-v~UniGB-UTF16-V~#2 }
        \tl_if_empty:nF {#3}
          {
            \special { pdf:mapline~#1b-h~UniGB-UTF16-H~#3 }
            \special { pdf:mapline~#1b-v~UniGB-UTF16-V~#3 }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_set_upmap_unicode:nnn}
% 设置 \upTeX{} 字体映射,使用 |unicode| CMap。参数同上。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_set_upmap_unicode:nnn #1#2#3
  {
    \ctex_set_zhmap:n
      {
        \special { pdf:mapline~#1-h~unicode~#2 }
        \special { pdf:mapline~#1-v~unicode~#2 }
        \tl_if_empty:nF {#3}
          {
            \special { pdf:mapline~#1b-h~unicode~#3 }
            \special { pdf:mapline~#1b-v~unicode~#3 }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_set_upfonts:nnnnnn}
% 设置 \upTeX{} 基本字体映射,按 \pkg{zhmetrics-uptex} 的定义,依次设置衬线体
% 正、粗、意大利,无衬线体正、粗,等宽体正——共 6 种字体,并分横排及直排。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_set_upfonts:nnnnnn #1#2#3#4#5#6
  {
    \ctex_set_upmap:nnn { upserif   } {#1} {#2}
    \ctex_set_upmap:nnn { upserifit } {#3} {}
    \ctex_set_upmap:nnn { upsans    } {#4} {#5}
    \ctex_set_upmap:nnn { upmono    } {#6} {}
  }
%    \end{macrocode}
% \end{macro}
%
% 以下命令只能在导言区使用。
%    \begin{macrocode}
\@onlypreamble \ctex_set_upfamily:nnn
\@onlypreamble \ctex_set_upmap:nnn
\@onlypreamble \ctex_set_upmap_unicode:nnn
\@onlypreamble \ctex_set_upfonts:nnnnnn
%    \end{macrocode}
%
% \changes{v2.4.7}{2016/12/27}{依赖 \pkg{pxeverysel} 宏包。}
%
% \pkg{everysel} 宏包(2011/10/28)未考虑 \upLaTeX{} 对 \tn{selectfont} 的修
% 改,需要引入 \pkg{pxeverysel} 宏包。
%    \begin{macrocode}
\bool_if:NT \c_@@_everysel_loaded_bool
  { \RequirePackage { pxeverysel } }
%    \end{macrocode}
%
%    \begin{macrocode}
%</uptex|aptex>
%    \end{macrocode}
%
% \subsubsection{修改主要字体命令}
%
% \changes{v2.5.2}{2020/05/06}{兼容 \LaTeX\ 2020-02-02 之前的版本。}
% \changes{v2.5.4}{2020/06/07}{修正主要字体命令补丁。}
%
% 修改 \tn{rmfamily} 等主要字体命令,使得中文字体能随西文主要字体更新。
% \LaTeX\ 2020-02-02 以后的版本可以直接使用 \tn{@rmfamilyhook} 等钩子。
% 我们暂时需要处理旧内核的情况,以保持兼容性。
%
% \pkg{xeCJK} 和 \pkg{zhmCJK} 已经有相同的工作,本段代码不需要对他们使用。
%    \begin{macrocode}
%<*pdftex|luatex|uptex|aptex>
%<pdftex>\reverse_if:N \if_bool:N \g_@@_zhmCJK_bool
%    \end{macrocode}
%
% \changes{v2.5.5}{2020/10/17}{进一步应用 \LaTeX\ 2020/10/01 的新钩子。}
%
% \begin{macro}[int]{\ctex_provide_font_hook:NNN,\CTEX@rmfamilyhook}
% 给 \tn{rmfamily} 等字体命令加钩子,钩子名字统一为 \tn{CTEX@rmfamilyhook} 等。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_provide_font_hook:NNN #1#2
  {
    \exp_args:Nc \@@_provide_font_hook_aux:NNNN
      { CTEX \cs_to_str:N #2 } #1#2
  }
\cs_if_exist:NTF \ctex_gadd_ltxhook:nn
  {
    \cs_new_protected:Npn \@@_provide_font_hook_aux:NNNN #1#2#3#4
      {
        \tl_new:N #1
        \exp_args:Nx \ctex_gadd_ltxhook:nn { \cs_to_str:N #2 } {#1}
      }
  }
  {
    \cs_new_protected:Npn \@@_provide_font_hook_aux:NNNN #1#2#3#4
      {
        \tl_new:N #1
        \cs_if_exist:NTF #3
          { \tl_gput_right:Nn #3 {#1} }
%    \end{macrocode}
% 注意此处不能用 \cs{ctex_patch_cmd:Nnn} 来打补丁,因其会关闭 \LaTeXiii 语法,
% 但 \pkg{fontspec} 会在 \tn{rmfamily} 的命令中相应加入
% \cs{l__fontspec_rmfamily_encoding_tl} 等,导致补丁失败。
%    \begin{macrocode}
          { \ctex_parse_name:NN \tl_replace_once:Nnn #2 {#4} { #1#4 } }
      }
  }
\ctex_provide_font_hook:NNN \rmfamily \@rmfamilyhook \selectfont
\ctex_provide_font_hook:NNN \sffamily \@sffamilyhook \selectfont
\ctex_provide_font_hook:NNN \ttfamily \@ttfamilyhook \selectfont
%<pdftex|luatex>\ctex_provide_font_hook:NNN \normalfont \@defaultfamilyhook \usefont
%    \end{macrocode}
% \end{macro}
%
% 按 \pkg{CJK} 的命名习惯模拟部分命令,并设置默认字体。
%    \begin{macrocode}
\tl_if_exist:NF \CJKfamilydefault
  { \tl_const:Nn \CJKfamilydefault { \CJKrmdefault } }
%<*pdftex|luatex>
\tl_if_exist:NF \CJKrmdefault { \tl_const:Nn \CJKrmdefault { rm } }
\tl_if_exist:NF \CJKsfdefault { \tl_const:Nn \CJKsfdefault { sf } }
\tl_if_exist:NF \CJKttdefault { \tl_const:Nn \CJKttdefault { tt } }
\tl_gput_right:Nn \CTEX@rmfamilyhook { \CJKfamily { \CJKrmdefault } }
\tl_gput_right:Nn \CTEX@sffamilyhook { \CJKfamily { \CJKsfdefault } }
\tl_gput_right:Nn \CTEX@ttfamilyhook { \CJKfamily { \CJKttdefault } }
\tl_gput_right:Nn \CTEX@defaultfamilyhook { \CJKfamily { \CJKfamilydefault } }
%</pdftex|luatex>
%    \end{macrocode}
% \upLaTeX 不需要补丁 \tn{normalfont},只需要修改 \tn{kanjifamilydefault}。
%    \begin{macrocode}
%<*uptex|aptex>
\tl_if_exist:NF \CJKrmdefault { \tl_const:Nn \CJKrmdefault { zhrm } }
\tl_if_exist:NF \CJKsfdefault { \tl_const:Nn \CJKsfdefault { zhsf } }
\tl_if_exist:NF \CJKttdefault { \tl_const:Nn \CJKttdefault { zhtt } }
\tl_gput_right:Nn \CTEX@rmfamilyhook { \kanjifamily { \CJKrmdefault } }
\tl_gput_right:Nn \CTEX@sffamilyhook { \kanjifamily { \CJKsfdefault } }
\tl_gput_right:Nn \CTEX@ttfamilyhook { \kanjifamily { \CJKttdefault } }
\tl_gset:Nn \kanjifamilydefault { \CJKfamilydefault }
%</uptex|aptex>
%    \end{macrocode}
%
% \pkg{zhmCJK} 判断结束。
%    \begin{macrocode}
%<pdftex>\fi:
%    \end{macrocode}
%
% 使修改立刻生效,保证导言区字体族正确。
%    \begin{macrocode}
\normalfont
%    \end{macrocode}
%
% 在导言区末尾更新 \tn{CJKfamilydefault},\pdfTeX 已经在之前使用过此处代码。
%    \begin{macrocode}
%<!pdftex>\ctex_at_end_preamble:n { \ctex_update_default_family: }
%    \end{macrocode}
%
% \changes{v2.4}{2016/02/15}{正确更新 \pkg{CJK} 包的 \tn{CJKfamilydefault}。}
% \changes{v2.4.1}{2016/04/26}{正确更新 \upLaTeX{} 的 \tn{CJKfamilydefault}。}
%
% \begin{macro}[int]{\ctex_update_default_family:}
% 在导言区结束,如果 \tn{CJKfamilydefault} 没有被更改,则在此时根据西文字体的情况
% 更新 \tn{CJKfamilydefault}。\pkg{xeCJK} 已经有这个功能,不需要再调整。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_update_default_family:
  {
    \tl_if_eq:NNT \CJKfamilydefault \l_@@_family_default_init_tl
      {
        \group_begin:
          \cs_set_eq:NN \@@_family_default_wrap:n \exp_not:n
          \tl_gset:Nx \CJKfamilydefault
            {
              \str_case:onF { \familydefault }
                {
                  { \rmdefault } { \exp_not:N \CJKrmdefault }
                  { \sfdefault } { \exp_not:N \CJKsfdefault }
                  { \ttdefault } { \exp_not:N \CJKttdefault }
                }
                { \CJKfamilydefault }
            }
        \group_end:
      }
%    \end{macrocode}
% 使用 \LuaLaTeX{} 时,自动调整得到的 \tn{CJKfamilydefault} 可能没有定义,需要
% 确认它的存在性。使用 \pkg{CJK} 宏包或 \upLaTeX{}
% 时,\texttt{C19rm}、\texttt{JY2rm} 等总是有定义的,不需要确认。
%    \begin{macrocode}
%<luatex>    \ctex_ltj_ensure_default_family:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}{\l_@@_family_default_init_tl}
% 往 \tn{CJKfamilydefault} 中加入标志,用于判断它是否被更改。
%    \begin{macrocode}
\tl_new:N \l_@@_family_default_init_tl
\cs_new_eq:NN \@@_family_default_wrap:n \use:n
\tl_set:Nx \l_@@_family_default_init_tl
  {
    \exp_not:N \@@_family_default_wrap:n
      { \exp_not:o { \CJKfamilydefault } }
  }
\tl_gset_eq:NN \CJKfamilydefault \l_@@_family_default_init_tl
%    \end{macrocode}
% \end{variable}
%
%    \begin{macrocode}
%</pdftex|luatex|uptex|aptex>
%    \end{macrocode}
%
% \changes{v2.0}{2014/04/16}{自动检测操作系统,载入对应的字体配置。}
% \changes{v2.5}{2019/10/25}{操作系统检测移动至载入中文字库处,且不再需要
%   依赖特定引擎。}
%
% \subsubsection{\pkg{hyperref} 兼容性处理}
%
% \changes{v2.1}{2015/06/16}{不再设置 \pkg{hyperref} 宏包的 \opt{colorlinks} 选项。}
%
% 现在处理各个引擎下的 PDF 中文书签问题。根据编译引擎与文件编码的不
% 同,\pkg{ctex} 向 \pkg{hyperref} 传递适当的参数,完成中文书签的正确设置。用
% 户仍需要自己载入 \pkg{hyperref} 宏包。
%
% \begin{macro}[int]{\ctex_hypersetup:n}
% 如果已经载入 \pkg{hyperref} 宏包,则直接使用其定义设置选项;否则
% \cs{ctex_hypersetup:n} 的效果与 \tn{PassOptionsToPackage} 一致,只传递宏包参
% 数。如果用户不载入 \pkg{hyperref} 宏包,相关参数即被丢弃。
%    \begin{macrocode}
%<*class|ctex>
\@ifpackageloaded { hyperref }
  {
    \cs_new_protected:Npn \ctex_hypersetup:n #1
      { \hypersetup {#1} }
  }
  {
    \cs_new_protected:Npn \ctex_hypersetup:n #1
      { \PassOptionsToPackage {#1} { hyperref } }
  }
%</class|ctex>
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5.7}{2021/06/06}{禁用 \dvipdfmx\ 驱动的 \opt{unicode} 书签设置。}
%
% 在 \pdfTeX{} 下使用 \texttt{GBK} 编码,\dvipdfmx{} 驱动可以直接用它的
% \tn{special} 命令,其他模式用 \pkg{xCJK2uni} 宏包处理。使用 \texttt{UTF-8} 编
% 码时,\pkg{CJKutf8} 已经处理了书签问题,但仍需要设置 \opt{pdfencoding} 为
% \opt{unicode},目的是在书签的开头写入 BOM (|\376\377|),提示这是
% \texttt{UTF-16BE} 字节流。
% \pkg{hyperref} 2021-02-04 版开始默认设置 \opt{unicode} 为 \opt{true},
% 对于 \dvipdfmx\ 驱动,我们需要禁用这个设置,为此设置 \opt{pdfencoding} 为 \opt{pdfdoc}。
%    \begin{macrocode}
%<*pdftex>
\ctex_hypersetup:n { driverfallback = dvipdfmx }
\str_if_eq:onTF { \g_@@_encoding_tl } { GBK }
  {
    \ctex_hypersetup:n { CJKbookmarks = true }
    \sys_if_output_pdf:TF
      { \ctex_at_end_package:nn { hyperref } { \RequirePackage { xCJK2uni } } }
      {
        \ctex_hypersetup:n { pdfencoding = pdfdoc }
        \ctex_at_end_package:nn { hyperref }
          {
            \str_if_eq:onTF { \Hy@driver } { hdvipdfm }
              {
                \ctex_at_shipout_first:n
                  { \special { pdf:tounicode~GBK-EUC-UCS2 } }
              }
              { \RequirePackage { xCJK2uni } }
          }
      }
  }
  { \ctex_hypersetup:n { pdfencoding = unicode } }
%</pdftex>
%    \end{macrocode}
% \XeTeX 和 \LuaTeX 统一设置 \opt{pdfencoding} 为 \opt{unicode}。
%    \begin{macrocode}
%<*xetex|luatex>
\ctex_hypersetup:n { pdfencoding = unicode }
%</xetex|luatex>
%    \end{macrocode}
%
% 我们假定 \upTeX{} 使用 \dvipdfmx{} 驱动输出,于是使用与 \pdfTeX{} 类似的设
% 置。注意 \upTeX{} 需要使用 UTF8-UTF16 的编码转换。
%    \begin{macrocode}
%<*uptex|aptex>
\ctex_hypersetup:n
  {
    driverfallback = dvipdfmx ,
    pdfencoding    = pdfdoc
  }
\ctex_at_end_package:nn { hyperref }
  {
    \ctex_at_shipout_first:n
      { \special { pdf:tounicode~UTF8-UTF16 } }
  }
%</uptex|aptex>
%    \end{macrocode}
%
%    \begin{macrocode}
%<*pdftex|xetex|luatex|uptex|aptex>
%    \end{macrocode}
%
% \subsubsection{\pkg{CJKfntef}、\pkg{xeCJKfntef} 相关设置}
%
% \changes{v2.0}{2015/03/25}{默认关闭 \pkg{CJKfntef} 或 \pkg{xeCJKfntef} 的彩
% 色设置。}
% \changes{v2.0}{2015/03/25}{\tn{CTEXunderdot}、\tn{CTEXunderline}、
% \tn{CTEXunderdblline}、\tn{CTEXunderwave}、\tn{CTEXsout}、\tn{CTEXxout} 是过
% 时命令;\env{CTEXfilltwosides} 是过时环境。}
% \changes{v2.5}{2019/11/10}{不再自动载入 \pkg{CJKfntef} 或 \pkg{xeCJKfntef} 宏包。}
% \changes{v2.5}{2019/11/10}{移除 \tn{CTEXunderdot}、\tn{CTEXunderline}、
% \tn{CTEXunderdblline}、\tn{CTEXunderwave}、\tn{CTEXsout}、\tn{CTEXxout}、
% \env{CTEXfilltwosides} 等命令和环境。}
%
% 对 \pdfTeX{} 与 \XeTeX{} 引擎,分别在 \pkg{CJKfntef}、\pkg{xeCJKfntef} 宏包
% 的末尾关闭彩色显式等多余格式。
%
%    \begin{macrocode}
%<*pdftex>
\ctex_at_end_package:nn { CJKfntef }
  {
    \normalem
    \cs_new_protected:Npn \@@_clear_fntef_color:n #1
      { \tl_clear:c { CJK#1color } }
%</pdftex>
%<*xetex>
\ctex_at_end_package:nn { xeCJKfntef }
  {
    \@ifpackagelater { xeCJKfntef } { 2014/11/04 }
      {
        \cs_new_protected:Npn \@@_clear_fntef_color:n #1
          { \xeCJKsetup { #1 / format = { } } }
      }
      {
        \cs_new_protected:Npn \@@_clear_fntef_color:n #1
          { \tl_clear:c { CJK#1color } }
      }
%</xetex>
%<*pdftex|xetex>
    \clist_map_inline:nn
      { underdot , underline , underdblline , underwave , sout , xout }
      { \@@_clear_fntef_color:n {#1} }
  }
%</pdftex|xetex>
%    \end{macrocode}
%
% \subsubsection{\tn{ccwd} 的更新}
%
% \begin{macro}[int]{\ctex_update_ccwd:,\ccwd}
% \changes{v2.4.1}{2016/04/29}{正确设置 \upTeX{} 下的 \tn{ccwd}。}
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_update_ccwd:
%<*pdftex|xetex>
  {
    \hbox_set:Nn \l_@@_tmp_box { \CJKglue }
    \dim_set:Nn \ccwd { \box_wd:N \l_@@_tmp_box + \f@size \p@ }
  }
%</pdftex|xetex>
%<*luatex>
  { \skip_set:Nn \ccwd { \ltjgetparameter { kanjiskip } + \zw } }
%</luatex>
%<*uptex|aptex>
  { \skip_set:Nn \ccwd { 1zw + \tex_kanjiskip:D } }
%</uptex|aptex>
\dim_new:N \ccwd
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_update_ccglue:}
% 更新字间距。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_update_ccglue:
%<*pdftex|xetex>
  {
    \cs_set_protected:Npn \CJKglue
      { \skip_horizontal:N \l_@@_ccglue_skip }
  }
%</pdftex|xetex>
%<*luatex>
  { \ctex_ltj_set_kanjiskip:N \l_@@_ccglue_skip }
%</luatex>
%<*uptex|aptex>
  { \skip_set_eq:NN \tex_kanjiskip:D \l_@@_ccglue_skip }
%</uptex|aptex>
\skip_new:N \l_@@_ccglue_skip
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int,pTF]{\ctex_if_ccglue_touched:}
% 检查用户是否修改过汉字间距。
%    \begin{macrocode}
\prg_new_conditional:Npnn \ctex_if_ccglue_touched: { TF }
  {
%<*pdftex|xetex>
    \if_meaning:w \CJKglue \@@_ccglue:
      \prg_return_false: \else: \prg_return_true: \fi:
%</pdftex|xetex>
%<*luatex>
    \skip_if_eq:nnTF { \l_@@_ccglue_skip } { \ltjgetparameter { kanjiskip } }
      { \prg_return_false: } { \prg_return_true: }
%</luatex>
%<*uptex|aptex>
    \skip_if_eq:nnTF { \l_@@_ccglue_skip } { \tex_kanjiskip:D }
      { \prg_return_false: } { \prg_return_true: }
%</uptex|aptex>
  }
%<pdftex|xetex>\ctex_at_end:n { \cs_new_eq:NN \@@_ccglue: \CJKglue }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_update_em_unit:}
% 将当前汉字的宽度保存到 \tn{ccwd} 中备用。不采用 \texttt{1em},因为这时的
% \texttt{1em} 实际上来自西文字体的信息,未必等于汉字的宽度,这似乎在传统的
% \file{.tfm} 字体上表现更明显。在 \pdfTeX{} 和 \XeTeX{} 下,直接使用 |\f@size\p@|
% 作为汉字的宽度,这应该对大多数汉字字体都成立,但不适用于诸如“方正兰亭黑长”之类
% 的特殊字体。在 \XeTeX{} 可以用 \tn{fontcharwd} 来改进。而在 \pdfTeX{} 下,若使用
% \pkg{zhmetrics} 技术,所有的汉字共享同一个 \file{.tfm},\tn{fontcharwd} 也就没有
% 意义。在 \LuaTeX{} 下,\pkg{LuaTeX-ja} 总是按照 JFM 中的设置输出汉字的宽度,可以
% 直接用 \tn{zw} 作为汉字宽度。\upTeX{} 可以直接使用原生的长度单位 |zw|。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_update_em_unit:
%<pdftex|xetex>  { \dim_set:Nn \ccwd { \f@size \p@ } }
%<luatex>  { \dim_set:Nn \ccwd { \zw } }
%<uptex|aptex>  { \dim_set:Nn \ccwd { 1zw } }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{其他}
%
% \begin{macro}[int]{\ctex_add_to_selectfont:n,\CTEX@selectfont@hook}
% \changes{v2.4.13}{2018/03/23}{修正导言区 \tn{selectfont} 钩子位置。}
% \changes{v2.5}{2020/04/19}{兼容 \pkg{KOMA-Script} 的 \tn{selectfont} 补丁。}
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_add_to_selectfont:n #1
  {
    \cs_set_protected:Npx \CTEX@selectfont@hook
      { \exp_not:o { \CTEX@selectfont@hook #1 } }
  }
\cs_new_eq:NN \CTEX@selectfont@hook \prg_do_nothing:
%    \end{macrocode}
% 使用 \pkg{everysel} 包的情况。
% \tn{EverySelectfont} 直到文档开始时才有效。为了 \tn{ccwd} 和 \pkg{LuaTeX-ja} 的
% 字体设置在导言区也可用,我们还需要在这里手工修改 \tn{selectfont}。\pkg{everysel}
% 宏包会用 \tn{CheckCommand} 来检查 \tn{selectfont} 是否为标准定义。我们修改了
% \tn{selectfont},所以会给出一个警告。为了消除这个警告,在它检查之前,还原本来
% 定义。\pkg{pxeverysel} 宏包取消了检查,但也需要恢复定义,避免重复使用钩子。
% \pkg{KOMA-Script} 宏包也会进行检查,我们需要小心处理。
%    \begin{macrocode}
\if_bool:N \c_@@_everysel_loaded_bool
  \if_cs_exist:N \@EverySelectfont@Init
    \group_begin:
      \cs_set:Npn \@@_tmp:N #1
        {
          \tl_set:Nn \l_@@_tmp_tl {#1}
          \cs_new_eq:NN \CTEX@selectfont@save #1
          \cs_new_protected:Npn \@@_restore_selectfont:
            {
              \cs_if_free:NF \scr@new@selectfont
                {
%    \end{macrocode}
% \pkg{CJK} 直接修改 \tn{selectfont} 和 \pkg{pxeverysel} 的补丁,
% 会使 \pkg{KOMA-Script} 的 \tn{par@update} 失效。
%    \begin{macrocode}
%<*pdftex|uptex|aptex>
                  \cs_if_free:NF \par@update
%<*uptex|aptex>
                    {
                      \tl_put_right:Nn \@EverySelectfont@Init
                        { \tl_put_right:Nn #1 { \par@update } }
                    }
%</uptex|aptex>
%<*pdftex>
                    { \tl_put_right:Nn #1 { \par@update } }
                  \cs_set_eq:NN \scr@selectfont \CTEX@selectfont@save
%</pdftex>
%</pdftex|uptex|aptex>
                  \cs_set_eq:NN \scr@new@selectfont #1
%<!pdftex>                  \cs_set_eq:NN \CTEX@selectfont@save \scr@selectfont
                }
              \tl_put_left:Nn \@EverySelectfont@Init
                { \cs_set_eq:NN #1 \CTEX@selectfont@save }
              \cs_undefine:N \@@_restore_selectfont:
            }
        }
      \ctex_parse_name:NN \@@_tmp:N \selectfont
    \exp_last_unbraced:NNo \group_end:
    \ctex_patch_cmd_once:NnnnTF { \l_@@_tmp_tl }
      { \ExplSyntaxOff }
      { \size@update }
      { \CTEX@selectfont@hook \size@update }
      { \@@_restore_selectfont: }
      { \ctex_patch_failure:N \selectfont }
  \fi:
  \cs_new_protected:Npn \ctex_gadd_selectfont_hook:n
    { \EverySelectfont }
%    \end{macrocode}
% 使用 \LaTeX \ 2021-06-01 的新钩子,不使用 \pkg{everysel} 包的情况。
%    \begin{macrocode}
\else:
  \cs_new_protected:Npn \ctex_gadd_selectfont_hook:n
    { \ctex_gadd_ltxhook:nn { selectfont } }
\fi:
%    \end{macrocode}
% \end{macro}
%
% \tn{CJK@plane} 有定义,说明处于 \pkg{CJK} 宏包的 \tn{CJKsymbol} 之内,不必使用钩子。
%    \begin{macrocode}
%<*pdftex>
\ctex_gadd_selectfont_hook:n
  { \cs_if_exist:NF \CJK@plane { \CTEX@selectfont@hook } }
%</pdftex>
%<*xetex|luatex|uptex|aptex>
\ctex_gadd_selectfont_hook:n { \CTEX@selectfont@hook }
%</xetex|luatex|uptex|aptex>
%    \end{macrocode}
%
% Attribute 寄存器 \tn{ltj@curjfnt} 的初始值是 $-1$,必须把它设置为一个有效的
% \texttt{font.id},否则编译时会直接退出。
%    \begin{macrocode}
%<*luatex>
\ctex_add_to_selectfont:n
  {
    \ctex_ltj_select_font:
    \ctex_ltj_select_alternate_font:
  }
\tl_set:Nn \CJK@family { song } \selectfont
\tl_clear:N \CJK@family
%</luatex>
%    \end{macrocode}
%
% \changes{v2.4.1}{2016/05/01}{随字体更新 \upTeX{} 的 \tn{xkanjiskip}。}
%
% \begin{macro}[int]{\ctex_update_xkanjiskip:}
% \begin{variable}{\l_@@_xkanjiskip_skip}
% \upTeX{} 和 \pkg{LuaTeX-ja} 对 \tn{xkanjiskip} 都是即时赋值。单位 \opt{zw} 与字体相关,因此
% 需要每次 \tn{selectfont} 的时候更新一次 \tn{xkanjiskip}。如果用户设置过
% \tn{xkanjiskip},就不更新。注意,同 \TeX{} 的 \tn{baselineskip} 一样,如果在
% 一个段落内多次设置了 \tn{kanjiskip} 或 \tn{xkanjiskip},只有最后的设置会影响
% 全段。
%    \begin{macrocode}
%<*luatex|uptex|aptex>
\cs_new_protected:Npn \ctex_update_xkanjiskip:
  {
    \skip_if_eq:nnT
%<luatex>      { \ltjgetparameter { xkanjiskip } } { \l_@@_xkanjiskip_skip }
%<uptex|aptex>      { \tex_xkanjiskip:D } { \l_@@_xkanjiskip_skip }
      {
        \skip_set:Nn \l_@@_xkanjiskip_skip { \l_@@_xkanjiskip_tl }
%<luatex>        \ctex_ltj_set_xkanjiskip:N \l_@@_xkanjiskip_skip
%<uptex|aptex>        \skip_set_eq:NN \tex_xkanjiskip:D \l_@@_xkanjiskip_skip
      }
  }
\tl_new:N \l_@@_xkanjiskip_tl
\tl_set:Nn \l_@@_xkanjiskip_tl
%<luatex>  { .25\zw plus 1pt minus 1pt }
%<uptex|aptex>  { .25zw plus 1pt minus 1pt }
\skip_new:N \l_@@_xkanjiskip_skip
\skip_set:Nn \l_@@_xkanjiskip_skip
%<luatex>  { \ltjgetparameter { xkanjiskip } }
%<uptex|aptex>  { \tex_xkanjiskip:D }
%    \end{macrocode}
% \end{variable}
% \end{macro}
%
%    \begin{macrocode}
\ctex_add_to_selectfont:n { \ctex_update_xkanjiskip: }
%</luatex|uptex|aptex>
%    \end{macrocode}
%
% \changes{v2.4.10}{2017/07/23}{定义 \tn{cht},\tn{cdp} 和 \tn{cwd}。}
%
% \begin{macro}[int]{\cht,\cdp,\cwd,\ctex_update_kanjisize:}
% 分别从 \file{.jfm} 中读取字符高度、深度和宽度,目前仅考虑横排的情况。
%    \begin{macrocode}
%<*luatex>
\dim_new:N \cht
\dim_new:N \cdp
\dim_new:N \cwd
\group_begin:
\char_set_catcode_space:n { 32 }
\lua_now:e
  {
    local nulltable = { }
    local fmt = luatexja.jfont.font_metric_table
    local getattribute = tex.getattribute
    local setdimen = tex.setdimen
    ctex.newluacmd("ctex_update_kanjisize:", function ()
      local ft = fmt[getattribute("ltj@curjfnt")] or nulltable
      local ft = ft and ft.char_type or nulltable
      local fk = ft and ft[0] or nulltable
      setdimen("cht", fk.height or 0)
      setdimen("cdp", fk.depth or 0)
      setdimen("cwd", fk.width or ft.zw or 0)
    end, "global", "protected")
  }
\group_end:
\ctex_add_to_selectfont:n { \ctex_update_kanjisize: }
%</luatex>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{space}
% 在导言区或正文中设置忽略空格方式。
% \pdfTeX{} 和 \XeTeX{} 下初始设置为 \opt{auto},\LuaTeX{}、\upTeX{} 下是无效
% 选项。
%    \begin{macrocode}
\ctex_define:n
  {
%<*pdftex|xetex>
    space .choice: ,
    space / true  .code:n =
%<pdftex>      { \ctex_ignorespaces_case:N \prg_do_nothing: } ,
%<xetex>      { \xeCJKsetup { CJKspace = true } } ,
    space / auto  .code:n =
%<pdftex>      { \ctex_ignorespaces_case:N \ctex_auto_ignorespaces: } ,
%<xetex>      { \xeCJKsetup { CJKspace = false } } ,
    space / false .code:n =
%<pdftex>      { \ctex_ignorespaces_case:N \tex_ignorespaces:D } ,
%<xetex>      { \xeCJKsetup { CJKspace = false } } ,
    space .default:n = { true } ,
    space .initial:n = { auto }
%</pdftex|xetex>
%<*luatex|uptex|aptex>
    space .code:n =
      { \msg_warning:nn { ctex } { invalid-option } }
%</luatex|uptex|aptex>
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{punct}
% 在导言区或正文中设置标点符号输出格式。\pkg{LuaTeX-ja} 设置的是字体的默认 \texttt{JFM},
% 只会影响到之后设置的字体。\upTeX{} 暂时无效。
%    \begin{macrocode}
\ctex_define:n
  {
    punct .code:n =
      {
        \tl_set:Nx \l_@@_punct_tl {#1}
%<pdftex>        \punctstyle { \l_@@_punct_tl }
%<xetex>        \xeCJKsetup { PunctStyle = \l_@@_punct_tl }
%<luatex>        \ctex_set_jfm:o { \l_@@_punct_tl }
%<uptex|aptex>        \msg_warning:nn { ctex } { invalid-option }
      } ,
    punct .default:n = { quanjiao } ,
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</pdftex|xetex|luatex|uptex|aptex>
%    \end{macrocode}
%
% \subsubsection{载入引擎定义文件}
%
% 最后载入各个编译引擎的定义文件。
%    \begin{macrocode}
%<class|ctex>\ctex_file_input:n { \c_@@_engine_file_str }
%    \end{macrocode}
%
% \subsection{用户设置接口}
%
% \changes{v2.0}{2014/03/18}{新增统一设置接口 \tn{ctexset}。}
% \changes{v2.4.12}{2018/01/14}
%   {修正 \tn{ctexset} 在 \pkg{ctexheading} 包中无定义的错误(曾祥东)。 }
%
% \begin{macro}{\ctexset}
%    \begin{macrocode}
%<*class|ctex|ctexheading>
\NewDocumentCommand \ctexset { } { \ctex_set:n }
%</class|ctex|ctexheading>
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2015/03/21}{\tn{CTEXsetup}, \tn{CTEXoptions} 是过时命令。}
% \begin{macro}{\CTEXsetup,\CTEXoptions}
% 过时命令。
%    \begin{macrocode}
%<*class|ctex>
\NewDocumentCommand \CTEXsetup { +O { } > { \TrimSpaces } m }
  {
    \tl_if_blank:nTF {#1}
      { \ctex_deprecated_command:Nn \CTEXsetup { } }
      {
        \ctex_deprecated_command:Nn \CTEXsetup
          { \ctexset {~#2~=~{~#1~}~}~is~set. }
        \ctex_set:nn {#2} {#1}
      }
  }
\NewDocumentCommand \CTEXoptions { +O { } }
  {
    \tl_if_blank:nTF {#1}
      { \ctex_deprecated_command:Nn \CTEXoptions { } }
      {
        \ctex_deprecated_command:Nn \CTEXoptions
          { \ctexset {~#1~}~is~set. }
        \ctex_set:n {#1}
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{字距与缩进}
%
% \begin{macro}{autoindent}
% \opt{autoindent} 也是可以用在正文中的选项,意义与宏包选项 |option/autoindent| 相同。
%    \begin{macrocode}
\ctex_define:n
  {
    autoindent .choice: ,
    autoindent .default:n = { true } ,
    autoindent / true    .code:n =
      {
        \tl_set:Nn \l_@@_autoindent_tl { 2 \ccwd }
        \ctex_select_size:
      } ,
    autoindent / false   .code:n =
      { \tl_clear:N \l_@@_autoindent_tl } ,
    autoindent / unknown .code:n =
      {
        \ctex_set_default_ccwd:Nn \l_@@_autoindent_tl {#1}
        \ctex_select_size:
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\CTEXsetfont}
% 无论字体大小是否变化都更新相关信息。
%    \begin{macrocode}
\NewDocumentCommand \CTEXsetfont { } { \ctex_select_size: }
\cs_new_protected:Npn \ctex_select_size:
  { \cs_if_free:NTF \size@update { \ctex_update_size: } { \selectfont } }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_update_size:}
% 在字号变化时更新 \tn{ccwd}、\tn{parindent} 和汉字间距。字距为零则恢复正常设置。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_update_size:
  {
    \tl_if_eq:NNTF \l_@@_ziju_tl \c_@@_zero_tl
      {
        \ctex_update_stretch:
        \ctex_update_parindent:
      }
      { \ctex_update_ziju: }
  }
\tl_const:Nx \c_@@_zero_tl { \fp_use:N \c_zero_fp }
\tl_new:N \l_@@_ziju_tl
\tl_set_eq:NN \l_@@_ziju_tl \c_@@_zero_tl
%    \end{macrocode}
% 在 \tn{selectfont} 中,若 \tn{size@update} 为 \tn{relax},说明字体大小没有变化,
% 我们也就不用更新相关参数。
%    \begin{macrocode}
\ctex_add_to_selectfont:n
  { \cs_if_free:NF \size@update { \ctex_update_size: } }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2014/03/26}{新增 \opt{linestretch} 选项。}
%
% \begin{macro}{linestretch}
% 若行宽不是汉字宽度的整数倍,自然要求伸展它们之间的差。这里设置的是在此基础上的
% 额外伸展量。初始化为一个汉字的宽度。若设置为 \tn{maxdimen},则禁用此功能。
% 参数的默认单位是汉字的宽度 \tn{ccwd}。
%    \begin{macrocode}
\ctex_define:n
  {
    linestretch .code:n =
      {
        \ctex_set_default_ccwd:Nn \l_@@_line_stretch_tl {#1}
        \ctex_select_size:
      } ,
    linestretch .value_required:n = true
  }
\tl_new:N \l_@@_line_stretch_tl
\tl_set:Nn \l_@@_line_stretch_tl { \ccwd }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_update_stretch:}
% 首先计算一行上汉字的字数,\tn{CJKglue} 相当于将 \tn{linewidth} 与汉字总宽度之差
% 均匀地填充到汉字之间。\hologo{eTeX} 的除法是四舍五入,而我们这里应该用截断。由于
% 没有可展性的要求,直接用原语 \cs{tex_divide:D} 要比 \cs{int_div_truncate:nn}
% 快一些。下面的算法还兼顾到了 \tn{linewidth} 不为汉字字宽的整数倍的情况。
% 若用户禁用 \opt{linestretch} 并且修改过 \tn{CJKglue},则只更新
% \tn{ccwd},否则设置伸展量为 $0.08$ 倍 \tn{baselineskip}。注意 \pkg{everysel} 的
% 钩子位于 \tn{size@update} 之前,\tn{baselineskip} 还未更新,不能直接使用它。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_update_stretch:
  {
    \ctex_update_em_unit:
    \dim_set:Nn \l_@@_tmp_dim { \l_@@_line_stretch_tl }
    \dim_compare:nNnTF \l_@@_tmp_dim = \c_max_dim
      { \@@_update_stretch_auxi: }
      { \@@_update_stretch_auxii: }
  }
\cs_new_protected:Npn \@@_update_stretch_auxi:
  {
    \ctex_if_ccglue_touched:TF
      { \ctex_update_ccwd: }
      {
        \dim_set:Nn \l_@@_tmp_dim
          { \baselinestretch \tex_glueexpr:D \f@baselineskip \scan_stop: }
        \skip_set:Nn \l_@@_ccglue_skip
          { \c_zero_dim plus .08 \l_@@_tmp_dim }
        \ctex_update_ccglue:
      }
  }
\cs_new_protected:Npn \@@_update_stretch_auxii:
  {
    \int_set:Nn \l_@@_tmp_int
      { \tex_dimexpr:D \linewidth - \ccwd - \l_@@_tmp_dim \scan_stop: }
    \tex_divide:D \l_@@_tmp_int \ccwd
    \int_compare:nNnTF \l_@@_tmp_int > \c_zero_int
      {
        \skip_set:Nn \l_@@_ccglue_skip
          {
            \c_zero_dim plus \dim_eval:n
              {
                ( \linewidth - \ccwd - \l_@@_tmp_int \ccwd ) /
                \l_@@_tmp_int
              }
          }
      }
      { \skip_zero:N \l_@@_ccglue_skip }
    \ctex_update_ccglue:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_update_parindent:}
% 更新段落首行缩进。此函数在字号变化时调用。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_update_parindent:
  {
    \tl_if_empty:NF \l_@@_autoindent_tl
      {
        \dim_compare:nNnF \parindent = \c_zero_dim
          { \dim_set:Nn \parindent { \l_@@_autoindent_tl } }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ziju}
% 若参数为 $0$,则恢复正常间距。
%    \begin{macrocode}
\NewDocumentCommand \ziju { m }
  { \exp_args:Nx \ctex_ziju:n {#1} \tex_ignorespaces:D }
\cs_new_protected:Npn \ctex_ziju:n #1
  {
    \tl_set:Nx \l_@@_ziju_tl { \fp_eval:n {#1} }
    \ctex_select_size:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_update_ziju:}
% 更新字距。若字距不大于 $-1$,即 \tn{ccwd} 为非正值,则不计算伸缩值。
% 否则,首先假定汉字的宽度为正常宽度加上字距,看一行上能正常放下多少个汉字。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_update_ziju:
  {
    \ctex_update_em_unit:
    \dim_set:Nn \l_@@_ziju_dim { \l_@@_ziju_tl \ccwd }
    \dim_add:Nn \ccwd { \l_@@_ziju_dim }
    \dim_compare:nNnTF \ccwd > \c_zero_dim
%    \end{macrocode}
% 伸展量保证行内的剩余空白能够被均匀地填充到汉字之间,收缩的最大限度是让当前行
% 还能够再挤下一个汉字并且不会出现负间距。由 \TeX{} 决定伸展还是收缩。
%    \begin{macrocode}
      {
        \dim_set:Nn \l_@@_tmp_dim
          { \linewidth - \ccwd + \l_@@_ziju_dim }
        \int_set:Nn \l_@@_tmp_int { \l_@@_tmp_dim }
        \tex_divide:D \l_@@_tmp_int \ccwd
        \dim_sub:Nn \l_@@_tmp_dim { \l_@@_tmp_int \ccwd }
%    \end{macrocode}
% 由于 \tn{parindent} 是一个固定值,并不参与伸缩,容易导致第一行出现坏盒子。
% 我们在这里将字数减去 $2$,以此放大伸缩值。
%    \begin{macrocode}
        \dim_compare:nNnF \parindent = \c_zero_dim
          {
            \int_compare:nNnF \l_@@_tmp_int < 3
              { \int_sub:Nn \l_@@_tmp_int { 2 } }
          }
        \skip_set:Nn \l_@@_ccglue_skip
          {
            \l_@@_ziju_dim
            plus  \dim_eval:n { \l_@@_tmp_dim / \l_@@_tmp_int }
            minus \dim_min:nn { \dim_abs:n { \l_@@_ziju_dim } }
              { ( \ccwd - \l_@@_tmp_dim ) / ( \l_@@_tmp_int + 1 ) }
          }
      }
      { \skip_set:Nn \l_@@_ccglue_skip { \l_@@_ziju_dim } }
    \ctex_update_ccglue:
%    \end{macrocode}
% 字距设置得比较大时,为了尽量保证段首缩进能够与下一行对齐,应该需要相应地加上
% 或者减去伸缩值。但是这里并不清楚 \TeX{} 是伸展还是收缩,之前以“当前行是否还
% 放得下一个汉字”为标准加上或减去伸缩值的做法也未必与实际结果一致,所以只好还
% 是设置为 |2\ccwd|。
%    \begin{macrocode}
    \ctex_update_parindent:
  }
\dim_new:N \l_@@_ziju_dim
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2015/03/21}{\tn{CTEXindent}, \tn{CTEXnoindent} 是过时命令。}
% \begin{macro}{\CTEXindent,\CTEXnoindent}
% 过时命令。
%    \begin{macrocode}
\NewDocumentCommand \CTEXindent { }
  {
    \ctex_deprecated_command:Nn \CTEXindent
      { \parindent is~set~to~2\ccwd. }
    \ctex_update_ccwd:
    \dim_set:Nn \parindent { 2 \ccwd }
  }
\NewDocumentCommand \CTEXnoindent { }
  {
    \ctex_deprecated_command:Nn \CTEXnoindent
      { \parindent is~set~to~0pt. }
    \dim_zero:N \parindent
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{中文数字与日期}
%
%    \begin{macrocode}
\PassOptionsToPackage { encoding = \g_@@_encoding_tl } { zhnumber }
\RequirePackage { zhnumber }
%    \end{macrocode}
%
% \begin{macro}{\chinese}
% \changes{v2.4.1}{2016/05/01}{支持 \tn{pagenumbering}。}
%    \begin{macrocode}
\cs_new:Npn \chinese { \zhnum_counter:n }
\cs_new_eq:NN \@chinese \@zhnum
\cs_new_eq:NN \Chinese \chinese
\cs_new_eq:NN \CTEXcounter \use_none:n
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.2}{2015/06/29}{给 \pkg{enumitem} 宏包注册 \tn{chinese} 和
%   \tn{zhnum}。}
%
% 给 \pkg{enumitem} 宏包注册 \tn{chinese}、\tn{zhnum} 和 \tn{zhdig}。
%    \begin{macrocode}
\ctex_at_end_package:nn { enumitem }
  {
    \cs_if_free:NF \AddEnumerateCounter
      {
        \AddEnumerateCounter * { \zhnum }   { \@zhnum } { 1 }
        \AddEnumerateCounter * { \zhdig }   { \@zhdig } { 1 }
        \AddEnumerateCounter * { \chinese } { \@chinese } { 1 }
      }
  }
%    \end{macrocode}
%
% \begin{macro}{\CTEXnumber,\CTEXdigits}
%    \begin{macrocode}
\NewDocumentCommand \CTEXnumber { m m }
  { \protected@edef #1 { \zhnumber {#2} } }
\NewDocumentCommand \CTEXdigits { m m }
  { \protected@edef #1 { \zhdigits {#2} } }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{today}
%    \begin{macrocode}
\cs_set_eq:NN \CTEX@todayold \today
\ctex_define:n
  {
    today .choice: ,
    today / old     .code:n =
      { \cs_set_eq:NN \today \CTEX@todayold } ,
    today / small   .code:n =
      {
        \cs_set_eq:NN \today \zhtoday
        \zhnumsetup { time = Arabic }
      } ,
    today / big     .code:n =
      {
        \cs_set_eq:NN \today \zhtoday
        \zhnumsetup { time = Chinese }
      } ,
    today / unknown .code:n =
      { \msg_error:nnx { ctex } { today-undef } {#1} }
  }
\msg_new:nnnn { ctex } { today-undef }
  { Today~format~`#1'~is~undefined. }
  { Available~today~formats~are~`old',~`small',~and~`big'. }
%    \end{macrocode}
% \end{macro}
%
% \subsection{其他中文标题定义}
%
% \changes{v2.0}{2014/03/08}{将标题汉化功能加入 \pkg{ctex.sty}。}
% \changes{v2.4.3}{2016/08/18}{确保 \tn{proofname} 非空。}
%
% \begin{macro}[int]{\proofname}
% \tn{proofname} 未在标准文档类中定义,需要确保它非空。
%    \begin{macrocode}
\tl_if_exist:NF \proofname
  {
    \tl_new:N \proofname
    \tl_set:Nn \proofname { Proof }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\ctex_define:n
  {
    contentsname   .tl_set:N = \contentsname ,
    listfigurename .tl_set:N = \listfigurename ,
    listtablename  .tl_set:N = \listtablename ,
    figurename     .tl_set:N = \figurename ,
    tablename      .tl_set:N = \tablename ,
    abstractname   .tl_set:N = \abstractname ,
    indexname      .tl_set:N = \indexname ,
    appendixname   .tl_set:N = \appendixname ,
    proofname      .tl_set:N = \proofname ,
%<article>    bibname        .tl_set:N = \refname
%<book|report>    bibname        .tl_set:N = \bibname
%<*beamer>
    algorithmname  .tl_set:N = \algorithmname ,
    bibname        .tl_set:N = \bibname ,
    refname        .tl_set:N = \refname ,
    continuation   .tl_set:N = \insertcontinuationtext
%</beamer>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
%<*ctex>
\msg_new:nnn { ctex } { ctexbibname }
  {
    Neither~`\token_to_str:N \bibname'~nor~`\token_to_str:N \refname'~can~be~found.\\
    The~key~`bibname'~will~set~`\token_to_str:N \ctexbibname'~to~the~given~value.
  }
\tl_if_exist:NTF \insertcontinuationtext
  {
    \ctex_define:n
      {
        algorithmname .tl_set:N = \algorithmname ,
        bibname       .tl_set:N = \bibname ,
        refname       .tl_set:N = \refname ,
        continuation  .tl_set:N = \insertcontinuationtext
      }
  }
  {
    \tl_if_exist:NTF \bibname
      { \ctex_define:n { bibname .tl_set:N = \bibname } }
      {
        \tl_if_exist:NTF \refname
          { \ctex_define:n { bibname .tl_set:N = \refname } }
          {
            \msg_warning:nn { ctex } { ctexbibname }
            \ctex_define:n { bibname .tl_set:N = \ctexbibname }
          }
      }
  }
%</ctex>
%    \end{macrocode}
%
%    \begin{macrocode}
%</class|ctex>
%    \end{macrocode}
%
% \subsection{中文化的标题结构}
%
% 本节内容在 \CTeX{} 文档类或打开 \opt{heading} 选项下生效。
%    \begin{macrocode}
%<*class|heading>
%    \end{macrocode}
%
% \subsubsection{定义标题格式选项}
%
% \begin{variable}{\c_@@_section_headings_seq}
% 保存 \tn{section} 级以下标题名字。
%    \begin{macrocode}
%<*article|book|report>
\seq_const_from_clist:Nn \c_@@_section_headings_seq
  { section , subsection , subsubsection , paragraph , subparagraph }
%</article|book|report>
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\c_@@_headings_seq}
%    \begin{macrocode}
%<*article|book|report>
\seq_new:N \c_@@_headings_seq
\seq_gset_eq:NN \c_@@_headings_seq \c_@@_section_headings_seq
%<book|report>\seq_gput_left:Nn \c_@@_headings_seq { chapter }
\seq_gput_left:Nn \c_@@_headings_seq { part }
%</article|book|report>
%<*beamer>
\seq_const_from_clist:Nn \c_@@_headings_seq
  { part , section , subsection }
%</beamer>
%    \end{macrocode}
% \end{variable}
%
% \changes{v2.1}{2015/06/19}{\opt{nameformat} 可以接受章节名字为参数。}
% \changes{v2.3}{2016/01/05}{修复 \opt{nameformat} 作用域问题。}
%
% \begin{macro}{\@@_initial_heading:n}
%    \begin{macrocode}
\cs_new_protected:Npn \@@_initial_heading:n #1
  {
    \tl_new:c { CTEX@pre#1 }
    \tl_new:c { CTEX@post#1 }
    \tl_const:cx { CTEXthe#1 }
      {
        \exp_not:c { CTEX@pre#1 }
        \exp_not:c { CTEX@the#1 }
        \exp_not:c { CTEX@post#1 }
      }
    \tl_const:cx { CTEX@#1name }
      {
        \group_begin:
          \exp_not:c { CTEX@#1@nameformat }
            {
              \exp_not:c { CTEX@pre#1 }
              \exp_not:N \tl_if_empty:NTF
              \exp_not:c { CTEX@#1@numberformat }
                { \exp_not:c { CTEX@the#1 } }
                {
                  \group_begin:
                    \exp_not:c { CTEX@#1@numberformat }
                    \exp_not:c { CTEX@the#1 }
                  \group_end:
                }
              \exp_not:c { CTEX@post#1 }
            }
        \group_end:
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.1}{2015/05/22}{\opt{format+}, \opt{nameformat+} 等带加号的选项,
%   加号与前面的文字之间可以有可选的空格。}
% \changes{v2.1}{2015/06/19}{新的标题格式选项 \opt{aftertitle}。}
% \changes{v2.2}{2015/06/21}{新的标题格式选项 \opt{numbering}。}
% \changes{v2.2}{2015/06/27}{\opt{beforeskip} 和 \opt{afterskip} 选项的符号
%   不再有特殊意义。}
% \changes{v2.2}{2015/06/27}{新的标题格式选项 \opt{afterindent}。}
% \changes{v2.2}{2015/06/27}{新的标题格式选项 \opt{runin}。}
% \changes{v2.4.3}{2016/06/03}{新的标题格式选项 \opt{fixskip}。}
% \changes{v2.4.4}{2016/09/19}{新的标题格式选项 \opt{break}。}
% \changes{v2.4.5}{2016/10/22}{新的标题格式选项 \opt{hang}。}
% \changes{v2.4.5}{2016/10/25}{新的标题格式选项 \opt{tocline}。}
% \changes{v2.4.11}{2017/11/21}{因上游 \pkg{l3keys} 变化,重新定义
%   \opt{format\textvisiblespace+} 等带空格加号的选项。}
%
% \begin{macro}{\@@_def_heading_keys:n}
%    \begin{macrocode}
\cs_new_protected:Npn \@@_def_heading_keys:n #1
  {
    \tl_put_right:Nx \l_@@_tmp_tl
      {
        #1                  .meta:nn = { ctex / #1 } { ####1 } ,
        #1 / name            .code:n =
          { \ctex_assign_heading_name:nn {#1} { ####1 } } ,
        #1 / number        .tl_set:N = \exp_not:c { CTEX@the#1 } ,
        #1 / beforeskip    .tl_set:N = \exp_not:c { CTEX@#1@beforeskip } ,
        #1 / afterskip     .tl_set:N = \exp_not:c { CTEX@#1@afterskip} ,
        #1 / indent        .tl_set:N = \exp_not:c { CTEX@#1@indent } ,
        #1 / numbering   .bool_set:N = \exp_not:c { CTEX@#1@numbering } ,
        #1 / numbering    .initial:n = true ,
        #1 / beforeskip   .initial:n = \c_zero_skip ,
        #1 / afterskip    .initial:n = \c_zero_skip ,
        #1 / indent       .initial:n = \c_zero_dim ,
        #1 / beforeskip   .value_required:n = true ,
        #1 / afterskip    .value_required:n = true ,
        #1 / indent       .value_required:n = true ,
%<*article|book|report>
        #1 / afterindent .bool_set:N = \exp_not:c { CTEX@#1@afterindent } ,
        #1 / fixskip     .bool_set:N = \exp_not:c { CTEX@#1@fixskip } ,
        #1 / hang        .bool_set:N = \exp_not:c { CTEX@#1@hang } ,
        #1 / hang         .initial:n = true ,
        #1 / runin       .bool_set:N = \exp_not:c { CTEX@#1@runin } ,
        #1 / tocline      .cs_set:Np = \exp_not:c { CTEX@#1@tocline}
                                       \exp_not:n { ##1##2 } ,
        \@@_plus_key_aux:nn {#1} { break } ,
%</article|book|report>
        \@@_plus_key_aux:nn {#1} { format } ,
        \@@_plus_key_aux:nn {#1} { nameformat } ,
        \@@_plus_key_aux:nn {#1} { numberformat } ,
        \@@_plus_key_aux:nn {#1} { titleformat } ,
        \@@_plus_key_aux:nn {#1} { aftername } ,
        \@@_plus_key_aux:nn {#1} { aftertitle } ,
      }
  }
\cs_new:Npn \@@_plus_key_aux:nn #1#2
  {
    #1 / #2   .tl_set:N = \exp_not:c { CTEX@#1@#2 } ,
    #1 / #2 +   .code:n =
      { \tl_put_right:Nn \exp_not:c { CTEX@#1@#2 } { ####1 } } ,
    #1 / #2 ~ + .code:n =
      { \tl_put_right:Nn \exp_not:c { CTEX@#1@#2 } { ####1 } }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_assign_heading_name:nn}
% \begin{macro}{\@@_assign_heading_name:nnn}
% \opt{name} 的值是一个至多两个元素的逗号分隔列表。由于 \LaTeXiii{} 的
% \texttt{clist} 总是会自动忽略空元素,所以设置 |name={,章}| 后,第一个元素将会
% 是“章”,必须用空的分组保护空元素:|name={{},章}|,这在使用中有些许不便。我们
% 可以改用 \texttt{seq} 或者手写函数解析参数来加以改进。为实现的简单起见,这里用
% 了 \pkg{xparse} 的 \tn{SplitArgument},它带有参数的长度检查。
%    \begin{macrocode}
\NewDocumentCommand \ctex_assign_heading_name:nn
  { m > { \SplitArgument { 1 } { , } } +m }
  { \@@_assign_heading_name:nnn {#1} #2 }
\cs_new_protected:Npn \@@_assign_heading_name:nnn #1#2#3
  {
    \tl_set:cn { CTEX@pre#1 } {#2}
    \tl_if_novalue:nTF {#3}
      { \tl_clear:c { CTEX@post#1 } }
      { \tl_set:cn { CTEX@post#1 } {#3} }
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \changes{v2.0}{2014/03/21}{标题设置新增 \opt{pagestyle} 选项。}
% \changes{v2.4.1}{2016/05/10}{新的标题格式选项 \opt{part/fixbeforeskip} 和
%   \opt{chapter/fixbeforeskip}。}
% \changes{v2.4.3}{2016/06/03}{删除选项 \opt{part/fixbeforeskip} 和
%   \opt{chapter/fixbeforeskip}。}
% \changes{v2.4.5}{2016/10/01}{新的标题格式选项 \opt{chapter/lofskip} 和
%   \opt{chapter/lotskip}。}
%
% \begin{macro}{part/pagestyle,chapter/pagestyle,chapter/lofskip,chapter/lotskip}
% 只在 \cls{ctexbook} 和 \cls{ctexrep} 下有定义。
%    \begin{macrocode}
\group_begin:
%<*book|report>
\tl_set:Nn \l_@@_tmp_tl
  {
    part    / pagestyle .tl_set:N = \CTEX@part@pagestyle ,
    chapter / pagestyle .tl_set:N = \CTEX@chapter@pagestyle ,
    chapter / lofskip   .tl_set:N = \CTEX@chapter@lofskip ,
    chapter / lotskip   .tl_set:N = \CTEX@chapter@lotskip ,
    chapter / lofskip  .initial:n = \c_zero_skip ,
    chapter / lotskip  .initial:n = \c_zero_skip ,
    chapter / lofskip  .value_required:n = true ,
    chapter / lotskip  .value_required:n = true ,
  }
%</book|report>
%<*article|beamer>
\tl_clear:N \l_@@_tmp_tl
%</article|beamer>
%    \end{macrocode}
% \end{macro}
%
% 定义标题键值选项。
%    \begin{macrocode}
\seq_map_inline:Nn \c_@@_headings_seq
  {
    \@@_initial_heading:n {#1}
    \@@_def_heading_keys:n {#1}
  }
\exp_args:NNo \group_end: \ctex_define:n { \l_@@_tmp_tl }
%    \end{macrocode}
%
% \changes{v2.5}{2020/04/23}{重构标题选项 \opt{indent} 和 \opt{hang}。}
%
% \begin{macro}[int]{\CTEX@heading@format@initial}
% 标题格式的一些初始设置,包括恢复默认字体,并禁用自动调整首行缩进,禁止在标题中分页。
% 同时用 \tn{noindent} 抑制首行缩进并进入水平模式。
% 统一在各级标题的 \opt{format} 选项之前使用。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@heading@format@initial
  {
    \normalfont
    \tl_clear:N \l_@@_autoindent_tl
    \int_set:Nn \tex_interlinepenalty:D { 10 000 }
    \tex_noindent:D
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_indent_box:n}
% 设置 \tn{parindent},并插入用于产生缩进的盒子,如果缩进为 |0|,就不插入。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_indent_box:n #1
  {
    \dim_set:Nn \tex_parindent:D {#1}
    \@@_insert_indent:
  }
\cs_new_protected:Npn \@@_insert_indent:
  {
    \dim_compare:nNnF \tex_parindent:D = \c_zero_dim
      { \tex_indent:D }
  }
\cs_new_eq:NN \CTEX@indentbox \ctex_indent_box:n
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{标准标题命令的修改}
%
%    \begin{macrocode}
%<*article|book|report>
%    \end{macrocode}
%
% \begin{macro}[int]{\CTEX@fixtopskip}
% 修正 \cls{book} 和 \cls{report} 类的 \tn{part} 和 \tn{chapter} 标题之前的多余空行。
%    \begin{macrocode}
%<*book|report>
\cs_new_protected:Npn \CTEX@fixtopskip
  {
    \CTEX@fixheadingskip
    \dim_compare:nNnF \tex_pagegoal:D < \c_max_dim
      { \skip_sub:Nn \l_@@_heading_skip { \tex_topskip:D } }
  }
%</book|report>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CTEX@fixheadingskip}
% 抑制行间粘连,修正标题前后的多余间距。事实上,减掉 \tn{parskip},有一定的风险。
% 如果接下来的内容不会进入水平模式(例如在 \opt{format} 选项中使用 \tn{hrule} 或者 \tn{hbox}),
% \TeX{} 就不会加上 \tn{parskip}。这时候就需要用户把 \tn{parskip} 加到 \opt{beforeskip}
% 或者 \opt{afterskip} 作为修正。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@fixheadingskip
  {
    \par
    \dim_set:Nn \tex_prevdepth:D { -1000pt }
    \skip_sub:Nn \l_@@_heading_skip { \tex_parskip:D }
  }
\skip_new:N \l_@@_heading_skip
\cs_new_protected:Npn \CTEX@setheadingskip
  { \skip_set:Nn \l_@@_heading_skip }
\cs_new_eq:NN \CTEX@headingskip \l_@@_heading_skip
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.4.4}{2016/09/18}{提供 \tn{partmark}。}
% \begin{macro}[int]{\partmark}
% 提供 \tn{partmark}。
%    \begin{macrocode}
\ProvideDocumentCommand \partmark { m }
  { \markboth { } { } }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.4.4}{2016/09/19}{提供 \tn{CTEXifname}。}
% \changes{v2.4.6}{2016/10/31}{\tn{CTEXifname} 初始为假。}
% \begin{macro}{\CTEXifname}
% \begin{macro}[int]{\CTEX@ifnametrue,\CTEX@ifnamefalse}
% 用于判断当前标题是否有编号。
%    \begin{macrocode}
\cs_new_eq:NN \CTEXifname \use_ii:nn
\cs_new_protected:Npn \CTEX@ifnametrue
  { \cs_set_eq:NN \CTEXifname \use_i:nn }
\cs_new_protected:Npn \CTEX@ifnamefalse
  { \cs_set_eq:NN \CTEXifname \use_ii:nn }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}[int]{\CTEX@addloflotskip}
% 往插图和表格目录中加入额外间距。如果间距为零,则不加入。
%    \begin{macrocode}
%<*book|report>
\cs_new_protected:Npn \CTEX@addloflotskip #1
  {
    \skip_set:Nn \l_@@_heading_skip { \use:c { CTEX@#1@lofskip } }
    \skip_if_eq:nnF { \l_@@_heading_skip } { \c_zero_skip }
      {
        \addtocontents { lof }
          { \protect \addvspace { \skip_use:N \l_@@_heading_skip } }
      }
    \skip_set:Nn \l_@@_heading_skip { \use:c { CTEX@#1@lotskip } }
    \skip_if_eq:nnF { \l_@@_heading_skip } { \c_zero_skip }
      {
        \addtocontents { lot }
          { \protect \addvspace { \skip_use:N \l_@@_heading_skip } }
      }
  }
%</book|report>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CTEX@addtocline}
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@addtocline #1#2
  { \addcontentsline { toc } {#1} { \use:c { CTEX@#1@tocline } {#1} {#2} } }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.2}{2015/06/27}{\opt{beforeskip}、\opt{afterskip} 和 \opt{indent}
%   选项支持表达式。}
% \changes{v2.4.15}{2019/03/31}{修正 \opt{part/indent} 和 \opt{chapter/indent} 的实现方法。}
% \changes{v2.4.15}{2019/03/31}{定义 \opt{part/hang} 和 \opt{chapter/hang}。}
% \changes{v2.4.16}{2019/05/11}{修正 \opt{part/indent} 和 \opt{chapter/indent}
%   的实现方法,在其标题内部禁用 \opt{autoindent}。}
%
% \changes{v2.5}{2020/04/22}{标题选项 \opt{format} 也可以接受参数。}
%
% \paragraph{part 的标题}
%
% \changes{v2.2}{2015/06/27}{非 \cls{ctexart} 类的 \opt{part/beforeskip} 和
%   \opt{part/afterskip} 选项有意义。}
%
% \begin{macro}[int]{\part}
%    \begin{macrocode}
%<*article>
\renewcommand\part{%
  \if@noskipsec \leavevmode \fi
  \par
  \CTEX@part@break
% \addvspace{4ex}%
  \CTEX@setheadingskip \CTEX@part@beforeskip
  \ifodd \CTEX@part@fixskip \CTEX@fixheadingskip \fi
  \addvspace \CTEX@headingskip
  \ifodd \CTEX@part@afterindent
   \@afterindenttrue
  \else
   \@afterindentfalse
  \fi
  \secdef\@part\@spart}
%</article>
%<*book|report>
\renewcommand\part{%
% \if@openright
%   \cleardoublepage
% \else
%   \clearpage
% \fi
  \CTEX@part@break
% \thispagestyle{plain}%
  \thispagestyle{\CTEX@part@pagestyle}%
  \if@twocolumn
    \onecolumn
    \@tempswatrue
  \else
    \@tempswafalse
  \fi
% \null\vfil
  \CTEX@setheadingskip \CTEX@part@beforeskip
  \ifodd \CTEX@part@fixskip \CTEX@fixtopskip \fi
  \vspace*{\CTEX@headingskip}%
  \secdef\@part\@spart}
%</book|report>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@part}
%    \begin{macrocode}
%<*article>
\def\@part[#1]#2{%
  \ifnum \c@secnumdepth >\m@ne
    \ifodd \CTEX@part@numbering
      \CTEX@ifnametrue
      \refstepcounter{part}%
%     \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \CTEX@ifnamefalse
      \CTEX@makeanchor{part*}%
%     \addcontentsline{toc}{part}{#1}%
    \fi
  \else
    \CTEX@ifnamefalse
    \CTEX@makeanchor{part*}%
%   \addcontentsline{toc}{part}{#1}%
  \fi
  \CTEX@gettitle{#1}%
  \CTEX@addtocline{part}{#1}%
  \partmark{#1}%
  \begingroup
%   \parindent \z@ \raggedright \interlinepenalty \@M \normalfont
    \CTEX@heading@format@initial
    \CTEX@part@format{%
%   \ifnum \c@secnumdepth >\m@ne
%     \Large\bfseries\partname\nobreakspace\thepart\par\nobreak
%   \fi
      \CTEX@headinghang{part}%
        {\CTEXifname{\CTEX@partname\CTEX@part@aftername}{}}%
%   \huge\bfseries #2%
        \CTEX@part@titleformat{#2}%
%   \markboth{}{}\par
        \CTEX@part@aftertitle}\par
  \endgroup
  \nobreak
% \vskip 3ex
  \CTEX@setheadingskip \CTEX@part@afterskip
  \ifodd \CTEX@part@fixskip \CTEX@fixheadingskip \fi
  \vskip \CTEX@headingskip
  \@afterheading}
%</article>
%<*book|report>
\def\@part[#1]#2{%
  \ifnum \c@secnumdepth >-2\relax
    \ifodd \CTEX@part@numbering
      \CTEX@ifnametrue
      \refstepcounter{part}%
%     \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \CTEX@ifnamefalse
      \CTEX@makeanchor{part*}%
%     \addcontentsline{toc}{part}{#1}%
    \fi
  \else
    \CTEX@ifnamefalse
    \CTEX@makeanchor{part*}%
%   \addcontentsline{toc}{part}{#1}%
  \fi
  \CTEX@gettitle{#1}%
  \CTEX@addtocline{part}{#1}%
%  \markboth{}{}%
  \partmark{#1}%
  \begingroup
%   \centering \interlinepenalty \@M \normalfont
    \CTEX@heading@format@initial
    \CTEX@part@format{%
%   \ifnum \c@secnumdepth >-2\relax
%     \huge\bfseries\partname\nobreakspace\thepart\par\vskip 20\p@
%   \fi
      \CTEX@headinghang{part}%
        {\CTEXifname{\CTEX@partname\CTEX@part@aftername}{}}%
%   \Huge\bfseries #2\par
      \CTEX@part@titleformat{#2}%
      \CTEX@part@aftertitle}\par
  \endgroup
  \@endpart}
%</book|report>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@spart}
%    \begin{macrocode}
%<*article>
\def\@spart#1{%
  \CTEX@ifnamefalse
  \CTEX@makeanchor@spart{part*}%
  \CTEX@gettitle{#1}%
  \begingroup
%   \parindent \z@ \raggedright \interlinepenalty \@M \normalfont
    \CTEX@heading@format@initial
    \CTEX@part@format{%
      \CTEX@headinghang{part}{}%
%   \huge \bfseries #1\par
      \CTEX@part@titleformat{#1}%
      \CTEX@part@aftertitle}\par
  \endgroup
  \nobreak
% \vskip 3ex
  \CTEX@setheadingskip \CTEX@part@afterskip
  \ifodd \CTEX@part@fixskip \CTEX@fixheadingskip \fi
  \vskip \CTEX@headingskip
  \@afterheading}
%</article>
%<*book|report>
\def\@spart#1{%
  \CTEX@ifnamefalse
  \CTEX@makeanchor@spart{part*}%
  \CTEX@gettitle{#1}%
  \begingroup
%   \centering \interlinepenalty \@M \normalfont
    \CTEX@heading@format@initial
    \CTEX@part@format{%
      \CTEX@headinghang{part}{}%
%    \Huge \bfseries #1\par%
      \CTEX@part@titleformat{#1}%
      \CTEX@part@aftertitle}\par
  \endgroup
  \@endpart}
%</book|report>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@endpart}
%    \begin{macrocode}
%<*book|report>
\def\@endpart{%
% \vfil
  \CTEX@setheadingskip \CTEX@part@afterskip
  \ifodd \CTEX@part@fixskip \CTEX@fixheadingskip \fi
  \vskip \CTEX@headingskip
  \newpage
  \if@twoside
    \if@openright
      \null
      \thispagestyle{empty}%
      \newpage
    \fi
  \fi
  \if@tempswa
    \twocolumn
  \fi}
%</book|report>
%    \end{macrocode}
% \end{macro}
%
% \paragraph{chapter 的标题}
%
%    \begin{macrocode}
%<*book|report>
%    \end{macrocode}
%
% \begin{macro}[int]{\chapter}
%    \begin{macrocode}
\renewcommand\chapter{%
% \if@openright\cleardoublepage\else\clearpage\fi
% \thispagestyle{plain}%
  \CTEX@chapter@break
  \thispagestyle{\CTEX@chapter@pagestyle}%
  \global\@topnum\z@
% \@afterindentfalse
  \ifodd \CTEX@chapter@afterindent
    \@afterindenttrue
  \else
    \@afterindentfalse
  \fi
  \secdef\@chapter\@schapter}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@chapter}
%    \begin{macrocode}
\def\@chapter[#1]#2{%
  \ifnum \c@secnumdepth >\m@ne
%<*book>
    \if@mainmatter
%</book>
      \ifodd \CTEX@chapter@numbering
        \CTEX@ifnametrue
        \refstepcounter{chapter}%
%       \typeout{\@chapapp\space\thechapter.}%
        \typeout{\CTEXthechapter}%
%       \addcontentsline{toc}{chapter}
%         {\protect\numberline{\thechapter}#1}%
      \else
        \CTEX@ifnamefalse
        \CTEX@makeanchor{\Hy@chapapp*}%
%       \addcontentsline{toc}{chapter}{#1}%
      \fi
%<*book>
    \else
      \CTEX@ifnamefalse
      \CTEX@makeanchor@chapter{\Hy@chapapp*}%
%     \addcontentsline{toc}{chapter}{#1}%
    \fi
%</book>
  \else
    \CTEX@ifnamefalse
    \CTEX@makeanchor@chapter{\Hy@chapapp*}%
%   \addcontentsline{toc}{chapter}{#1}%
  \fi
  \CTEX@gettitle{#1}%
  \CTEX@addtocline{chapter}{#1}%
  \chaptermark{#1}%
% \addtocontents{lof}{\protect\addvspace{10\p@}}%
% \addtocontents{lot}{\protect\addvspace{10\p@}}%
  \CTEX@addloflotskip{chapter}%
  \if@twocolumn
    \@topnewpage[\@makechapterhead{#2}]%
  \else
    \@makechapterhead{#2}%
  \@afterheading
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@schapter}
%    \begin{macrocode}
\def\@schapter#1{%
  \CTEX@ifnamefalse
  \CTEX@makeanchor@schapter{\Hy@chapapp*}%
  \CTEX@gettitle{#1}%
  \if@twocolumn
    \@topnewpage[\@makeschapterhead{#1}]%
  \else
    \@makeschapterhead{#1}%
    \@afterheading
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@makechapterhead}
%    \begin{macrocode}
\def\@makechapterhead#1{%
% \vspace*{50\p@}%
  \CTEX@setheadingskip \CTEX@chapter@beforeskip
  \ifodd \CTEX@chapter@fixskip \CTEX@fixtopskip \fi
  \vspace*{\CTEX@headingskip}%
  \begingroup
%   \parindent \z@ \raggedright \normalfont
    \CTEX@heading@format@initial
    \CTEX@chapter@format{%
%   \ifnum \c@secnumdepth >\m@ne
%     \if@mainmatter
%       \huge\bfseries\@chapapp\space\thechapter\par\nobreak\vskip 20\p@
%     \fi
%   \fi
      \CTEX@headinghang{chapter}%
        {\CTEXifname{\CTEX@chaptername\CTEX@chapter@aftername}{}}%
%   \Huge \bfseries #1\par\nobreak
      \CTEX@chapter@titleformat{#1}%
      \CTEX@chapter@aftertitle}\par
  \endgroup
  \nobreak
%  \vskip 40\p@
  \CTEX@setheadingskip \CTEX@chapter@afterskip
  \ifodd \CTEX@chapter@fixskip \CTEX@fixheadingskip \fi
  \vskip \CTEX@headingskip}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@makeschapterhead}
%    \begin{macrocode}
\def\@makeschapterhead#1{%
% \vspace*{50\p@}%
  \CTEX@setheadingskip \CTEX@chapter@beforeskip
  \ifodd \CTEX@chapter@fixskip \CTEX@fixtopskip \fi
  \vspace*{\CTEX@headingskip}%
  \begingroup
% \parindent \z@ \raggedright \normalfont \interlinepenalty\@M
    \CTEX@heading@format@initial
    \CTEX@chapter@format{%
      \CTEX@headinghang{chapter}{}%
%     \Huge \bfseries  #1\par\nobreak
      \CTEX@chapter@titleformat{#1}%
      \CTEX@chapter@aftertitle}\par
  \endgroup
  \nobreak
% \vskip 40\p@
  \CTEX@setheadingskip \CTEX@chapter@afterskip
  \ifodd \CTEX@chapter@fixskip \CTEX@fixheadingskip \fi
  \vskip \CTEX@headingskip}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</book|report>
%    \end{macrocode}
%
% \paragraph{section 类的标题}
%
% \begin{macro}[int]{\@startsection}
% \LaTeX 的标准参数是:
% \begin{quote}\small
%   \Arg{name}\Arg{level}\Arg{indent}\Arg{beforeskip}\Arg{afterskip}^^A
%   \Arg{style}|*|\oarg{altheading}\Arg{heading}
% \end{quote}
%    \begin{macrocode}
\def\@startsection#1#2#3#4#5#6{%
  \if@noskipsec \leavevmode \fi
  \par
% \@tempskipa #4\relax
% \@afterindenttrue
% \ifdim \@tempskipa <\z@
%   \@tempskipa -\@tempskipa \@afterindentfalse
% \fi
  \CTEX@update@sectionformat@n{#1}%
  \ifodd \CTEX@afterindent
    \@afterindenttrue
  \else
    \@afterindentfalse
  \fi
  \if@nobreak
    \everypar{}%
  \else
%   \addpenalty\@secpenalty\addvspace\@tempskipa
    \csname CTEX@#1@break\endcsname
    \CTEX@setheadingskip{#4}%
    \ifodd \CTEX@fixskip \CTEX@fixheadingskip \fi
    \addvspace \CTEX@headingskip
  \fi
  \@ifstar
    {\CTEX@makeanchor@ssect{#1*}\@ssect{#3}{#4}{#5}{#6}}%
    {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@seccntformat}
%    \begin{macrocode}
\def\@seccntformat#1{%
% \csname the#1\endcsname\quad}%
  \csname CTEX@#1name\endcsname
  \csname CTEX@#1@aftername\endcsname}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@sect}
%    \begin{macrocode}
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \CTEX@ifnamefalse
    \CTEX@makeanchor@sect{#1*}%
    \let\@svsec\@empty
  \else
    \ifodd \csname CTEX@#1@numbering\endcsname
      \CTEX@ifnametrue
      \refstepcounter{#1}%
      \protected@edef\@svsec{\@seccntformat{#1}\relax}%
    \else
      \CTEX@ifnamefalse
      \CTEX@makeanchor{#1*}%
      \let\@svsec\@empty
    \fi
  \fi
  \CTEX@gettitle{#7}%
% \@tempskipa #5\relax
% \ifdim \@tempskipa>\z@
  \unless \ifodd \CTEX@runin
    \begingroup
      \CTEX@heading@format@initial
      #6{%
%       \@hangfrom{\hskip #3\relax\@svsec}%
%       \interlinepenalty \@M #8\@@@@par
        \CTEX@sectionhang{#3}{\@svsec}%
        \csname CTEX@#1@titleformat\endcsname{#8}%
        \csname CTEX@#1@aftertitle\endcsname}\par
    \endgroup
    \csname #1mark\endcsname{#7}%
%   \addcontentsline{toc}{#1}{%
%     \ifnum #2>\c@secnumdepth \else
%       \protect\numberline{\csname the#1\endcsname}%
%     \fi
%     #7}%
    \CTEX@addtocline{#1}{#7}%
  \else
    \def\@svsechd{%
      #6{%
%       \hskip #3\relax \@svsec #8
        {\CTEX@indentbox{#3}}\@svsec
        \csname CTEX@#1@titleformat\endcsname{#8}%
        \csname CTEX@#1@aftertitle\endcsname}%
      \csname #1mark\endcsname{#7}%
%     \addcontentsline{toc}{#1}{%
%       \ifnum #2>\c@secnumdepth \else
%         \protect\numberline{\csname the#1\endcsname}%
%       \fi
%       #7}%
      \CTEX@addtocline{#1}{#7}}%
  \fi
  \@xsect{#5}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@ssect}
%    \begin{macrocode}
\def\@ssect#1#2#3#4#5{%
  \CTEX@ifnamefalse
  \CTEX@gettitle{#5}%
% \@tempskipa #3\relax
% \ifdim \@tempskipa>\z@
  \unless \ifodd \CTEX@runin
    \begingroup
      \CTEX@heading@format@initial
      #4{%
%       \@hangfrom{\hskip #1}%
%       \interlinepenalty \@M #5\@@par
        \CTEX@sectionhang{#1}{}%
          \CTEX@titleformat@n{#5}%
          \CTEX@aftertitle}\par
    \endgroup
  \else
%   \def\@svsechd{#4{\hskip #1\relax #5}}%
    \def\@svsechd{#4{{\CTEX@indentbox{#1}}%
      \CTEX@titleformat@n{#5}\CTEX@aftertitle}}%
  \fi
  \@xsect{#3}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@xsect}
%    \begin{macrocode}
\def\@xsect#1{%
% \@tempskipa #1\relax
% \ifdim \@tempskipa>\z@
  \unless \ifodd \CTEX@runin
    \par \nobreak
%   \vskip \@tempskipa
    \CTEX@setheadingskip{#1}%
    \ifodd \CTEX@fixskip \CTEX@fixheadingskip \fi
    \vskip \CTEX@headingskip
    \@afterheading
  \else
    \@nobreakfalse
    \global\@noskipsectrue
    \everypar{%
      \if@noskipsec
        \global\@noskipsecfalse
       {\setbox\z@\lastbox}%
        \clubpenalty\@M
        \begingroup \@svsechd \endgroup
        \unskip
%       \@tempskipa #1\relax
%       \hskip -\@tempskipa
        \CTEX@heading@glue{#1}%
      \else
        \clubpenalty \@clubpenalty
        \everypar{}%
      \fi}%
  \fi
  \ignorespaces}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CTEX@headinghang,\CTEX@sectionhang}
% 分别用于用于实现 \tn{part}/\tn{chapter} 和 \tn{section} 类标题的
% \opt{indent} 和 \opt{hang} 选项。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@headinghang #1
  {
    \ctex_heading_hang:cnn
      { CTEX@#1@hang }
      { \use:c { CTEX@#1@indent } }
  }
\cs_new_protected:Npn \CTEX@sectionhang
  { \ctex_heading_hang:Nnn \CTEX@hang }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_heading_hang:Nnn,\ctex_hang_from:n}
% \opt{hang} 选项控制是否采用悬挂缩进,同时设置 \tn{parindent}。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_heading_hang:Nnn #1#2#3
  {
    \dim_set:Nn \tex_parindent:D {#2}
    \bool_if:NTF #1
      { \ctex_hang_from:n }
      { \use:n }
      { \@@_insert_indent: #3 }
  }
\cs_new_protected:Npn \ctex_hang_from:n #1
  {
    \tex_noindent:D
    \hbox_set:Nn \l_@@_tmp_box {#1}
    \tex_hangindent:D = \box_wd:N \l_@@_tmp_box
    \box_use_drop:N \l_@@_tmp_box
  }
\cs_generate_variant:Nn \ctex_heading_hang:Nnn { c }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_heading_glue:n,\CTEX@heading@glue}
% 如果缩进 |#1| 长度为零,就不插入水平间距。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_heading_glue:n #1
  {
    \group_begin:
      \skip_set:Nn \l_@@_heading_skip {#1}
      \dim_compare:nNnF \l_@@_heading_skip = \c_zero_dim
        { \skip_horizontal:N \l_@@_heading_skip }
    \group_end:
  }
\cs_new_eq:NN \CTEX@heading@glue \ctex_heading_glue:n
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CTEX@update@sectionformat@n}
% 在 \tn{@startsection} 中设置 \tn{CTEX@titleformat@n} 等为相应函数。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@update@sectionformat@n #1
  {
    \cs_set_eq:Nc \CTEX@titleformat@n { CTEX@#1@titleformat }
    \cs_set_eq:Nc \CTEX@aftertitle    { CTEX@#1@aftertitle }
    \cs_set_eq:Nc \CTEX@afterindent   { CTEX@#1@afterindent }
    \cs_set_eq:Nc \CTEX@fixskip       { CTEX@#1@fixskip }
    \cs_set_eq:Nc \CTEX@hang          { CTEX@#1@hang }
    \cs_set_eq:Nc \CTEX@runin         { CTEX@#1@runin }
  }
\cs_new_eq:NN \CTEX@titleformat@n \use:n
\cs_new_eq:NN \CTEX@aftertitle \prg_do_nothing:
\cs_new_eq:NN \CTEX@afterindent \c_true_bool
\cs_new_eq:NN \CTEX@fixskip \c_false_bool
\cs_new_eq:NN \CTEX@hang \c_true_bool
\cs_new_eq:NN \CTEX@runin \c_false_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CTEX@part@tocline, \CTEX@chapter@tocline}
%    \begin{macrocode}
\cs_new:Npn \CTEX@part@tocline #1#2
  {
    \CTEXifname
      { \CTEXthepart \hspace { 1em } }
      { }
    #2
  }
%<*book|report>
\cs_new:Npn \CTEX@chapter@tocline #1#2
  {
    \CTEXifname
      { \protect \numberline { \CTEXthechapter \hspace { .3em } } }
      { }
    #2
  }
%</book|report>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CTEXnumberline}
%    \begin{macrocode}
\cs_new:Npn \CTEXnumberline #1
  {
    \CTEXifname
      { \protect \numberline { \use:c { CTEXthe #1 } } }
      { }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\int_zero:N \l_@@_tmp_int
\seq_map_inline:Nn \c_@@_section_headings_seq
  {
    \int_incr:N \l_@@_tmp_int
    \cs_gset_protected:cpx  {#1}
      {
        \exp_not:N \@startsection {#1}
          { \int_use:N \l_@@_tmp_int }
          { \exp_not:c { CTEX@#1@indent } }
          { \exp_not:c { CTEX@#1@beforeskip } }
          { \exp_not:c { CTEX@#1@afterskip } }
          { \exp_not:N \normalfont \exp_not:c { CTEX@#1@format } }
      }
    \cs_new:cpn { CTEX@#1@tocline } ##1##2
      { \CTEXnumberline { ##1 } ##2 }
  }
%    \end{macrocode}
%
% \paragraph{附录标题}
%
% \begin{macro}[int]{appendix/name,appendix/number,appendix/numbering}
%    \begin{macrocode}
\ctex_define:n
  {
    appendix                .meta:nn = { ctex / appendix } {#1} ,
    appendix / name          .code:n =
      { \ctex_assign_heading_name:nn { appendix } {#1} } ,
    appendix / number      .tl_set:N = \CTEX@appendix@number ,
    appendix / numbering .bool_set:N = \CTEX@appendix@numbering ,
    appendix / numbering  .initial:n = true
  }
\tl_new:N \CTEX@preappendix
\tl_new:N \CTEX@postappendix
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\appendix}
%    \begin{macrocode}
\cs_new_eq:NN \CTEX@save@appendix \appendix
\cs_gset_protected:Npn \appendix
  {
    \CTEX@save@appendix
%<*article>
    \gdef \CTEX@presection { \CTEX@preappendix }
    \gdef \CTEX@thesection { \CTEX@appendix@number }
    \gdef \CTEX@postsection { \CTEX@postappendix }
    \gdef \CTEX@section@numbering { \CTEX@appendix@numbering }
%</article>
%<*book|report>
    \gdef \CTEX@prechapter { \CTEX@preappendix }
    \gdef \CTEX@thechapter { \CTEX@appendix@number }
    \gdef \CTEX@postchapter { \CTEX@postappendix }
    \gdef \CTEX@chapter@numbering { \CTEX@appendix@numbering }
%</book|report>
  }
%    \end{macrocode}
% \end{macro}
%
% \paragraph{设置 \pkg{hyperref} 宏包的标题锚点}
%
% \changes{v2.4.4}{2016/09/12}{改进 \pkg{hyperref} 宏包的标题锚点设置。}
%
% \begin{macro}[int]{\CTEX@makeanchor}
% 设置超链接跳转锚点,在 \pkg{hyperref} 载入后才有意义。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@makeanchor #1
  { }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}{\c_@@_headings_cs_seq}
% 保存内部标题命令的 \CTeX{} 定义,用于随后比较。
%    \begin{macrocode}
\seq_const_from_clist:Nn \c_@@_headings_cs_seq
%<article>  { part , spart , sect , ssect }
%<book|report>  { part , spart , chapter , schapter , sect , ssect }
\seq_map_inline:Nn \c_@@_headings_cs_seq
  {
    \cs_new_eq:cc { CTEX@ #1 } { @ #1 }
    \cs_new_eq:cN { CTEX@makeanchor@ #1 } \CTEX@makeanchor
  }
%    \end{macrocode}
% \end{variable}
%
% \begin{macro}[int]{\CTEX@hyperheadinghook}
% \pkg{hyperref} 会重定义内部标题命令,目的在于为没有编号的标题设置锚点(这一功能受他的
% \opt{implicit} 选项的控制)。我们在上面对标题命令的修改已经包含这一功能,如果这些标题命令在
% \pkg{hyperref} 载入之前没有被修改过,则恢复 \CTeX{} 的定义。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@hyperheadinghook
  {
    \group_begin:
      \ifHy@implicit
        \cs_set_eq:NN \H@old@chapter \Hy@org@chapter
        \seq_map_inline:Nn \c_@@_headings_cs_seq
          {
            \cs_if_eq:ccT { H@old@ ##1 } { CTEX@ ##1 }
              {
                \cs_gset_eq:cc { @ ##1 } { CTEX@ ##1 }
                \cs_gset_eq:cN { CTEX@makeanchor@ ##1 } \CTEX@makeanchor
              }
          }
      \else:
        \seq_map_inline:Nn \c_@@_headings_cs_seq
          { \cs_gset_eq:cN { CTEX@makeanchor@ ##1 } \CTEX@makeanchor }
      \fi:
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\ctex_at_end_package:nn { hyperref }
  {
    \cs_gset_protected:Npn \CTEX@makeanchor #1
      {
        \Hy@MakeCurrentHrefAuto {#1}
        \Hy@raisedlink
          {
            \hyper@anchorstart { \@currentHref }
            \hyper@anchorend
          }
      }
    \CTEX@hyperheadinghook
  }
%    \end{macrocode}
%
% \paragraph{兼容 \pkg{nameref} 宏包}
%
% \changes{v2.4.16}{2019/05/29}{更好地兼容 \pkg{nameref} 宏包。}
%
% \begin{macro}[int]{\CTEX@gettitle}
% 在 \pkg{nameref} 载入后才有意义,与上述 \pkg{hyperref} 的处理类似。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@gettitle #1
  { }
\ctex_at_end_package:nn { nameref }
  {
    \cs_gset_protected:Npn \CTEX@gettitle { \NR@gettitle }
    \seq_map_inline:Nn \c_@@_headings_cs_seq
      {
        \cs_if_eq:ccT { NR@ #1 } { CTEX@ #1 }
          { \cs_gset_eq:cc { @ #1 } { CTEX@ #1 } }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \paragraph{兼容 \pkg{titlesec} 宏包}
%
% 我们修改了 \tn{@startsection} 的定义,它的第四个(\meta{beforeskip})和
% 第五个(\meta{afterskip})参数的符号不再有特殊意义,改由相应的选项
% \opt{afterindent} 和 \opt{runin} 来控制。
%
% 引入 \pkg{titlesec} 宏包,并且未设置它的 \opt{loadonly} 选项时,\pkg{titlesec}
% 会展开 section 类标题获取它们的参数,进行初始设置。我们需要进行一些调整。
%
% \begin{macro}[int]{\ctex_titlesec_hook:}
% \tn{titleformat} 的设置保存在名为 |\ttlf@|\meta{section} 的宏中备用,它的内容是
% \begin{quote}\small
%   |\ttlh@|\meta{shape}\Arg{format}\Arg{label}\Arg{sep}\Arg{before}\Arg{after}
% \end{quote}
% 我们这里的 \meta{shape} 为 |hang| 或者 |runin|。\tn{titlespacing} 的设置保存在
% |\ttls@|\meta{section} 之中,它的内容是
% \begin{quote}\small
%   \Arg{left}\Arg{right}\Arg{before}\Arg{after}\Arg{afterindent}
% \end{quote}
% 其中 \meta{afterindent} 为 |1| 或 |0|,分别对应是否保留段首缩进。
% 我们需要根据 \CTeX{} 的 \opt{runin} 和 \opt{afterindent} 选项调整
% |\ttlh@|\meta{shape} 和 \meta{afterindent}。注意,由 \tn{ttl@extract} 得的
% \meta{before} 和 \meta{after} 的值总是非负的,而 \CTeX{} 的 \opt{beforeskip}
% 和 \opt{afterskip} 是可以取负值的,但我们不打算调整它们了。
% 如果使用了 \pkg{titlesec} 的 \opt{indentafter} 等选项,也不需要调整
% |\ttls@|\meta{section}。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_titlesec_hook:
  {
    \@ifpackagewith { titlesec } { explicit }
      {
        \cs_set_eq:NN \@@_titlesec_format:Nn
                      \@@_titlesec_format_explicit:Nn
      }
      { }
    \clist_map_inline:nn
      { indentafter , noindentafter , indentfirst , nonindentfirst }
      {
        \@ifpackagewith { titlesec } { ##1 }
          {
            \clist_map_break:n
              { \cs_set_eq:NN \@@_titlesec_hook:n \@@_titlesec_format:n }
          }
          { }
      }
    \seq_map_function:NN \c_@@_section_headings_seq \@@_titlesec_hook:n
  }
\cs_new_protected:Npn \@@_titlesec_hook:n #1
  {
    \@@_titlesec_format:n {#1}
    \exp_args:Nc \@@_titlesec_spacing:Nn { ttls@#1 } {#1}
  }
\cs_new_protected:Npn \@@_titlesec_format:n #1
  {
    \cs_if_free:cF { ttlf@#1 }
      { \exp_args:Nc \@@_titlesec_format:Nn { ttlf@#1 } {#1} }
  }
\cs_new_protected:Npn \@@_titlesec_format:Nn #1#2
  {
    \tl_set:Nx #1
      {
        \bool_if:cTF { CTEX@#2@runin }
          { \exp_not:N \ttlh@runin }
          { \exp_not:N \ttlh@hang }
        \tl_tail:N #1
      }
  }
\cs_new_protected:Npn \@@_titlesec_format_explicit:Nn #1#2
  {
    \cs_set_nopar:Npx #1 ##1
      {
        \bool_if:cTF { CTEX@#2@runin }
          { \exp_not:N \ttlh@runin }
          { \exp_not:N \ttlh@hang }
        \exp_args:No \tl_tail:n { #1 { } }
      }
  }
\cs_new_protected:Npn \@@_titlesec_spacing:Nn #1#2
  { \tl_set:Nx #1 { \exp_after:wN \@@_titlesec_spacing:nnnnnn #1 {#2} } }
\cs_new:Npn \@@_titlesec_spacing:nnnnnn #1#2#3#4#5#6
  {
    \exp_not:n { {#1} {#2} {#3} {#4} }
    { \bool_if:cTF { CTEX@#6@afterindent } { \@ne } { \z@ } }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\@ifpackageloaded { titlesec }
  { }
  {
    \ctex_at_end_package:nn { titlesec }
      {
        \@ifpackagewith { titlesec } { loadonly }
          { }
          { \ctex_titlesec_hook: }
      }
  }
%    \end{macrocode}
%
% \changes{v2.4.4}{2016/09/13}{使用 \pkg{titlesec} 时,章节目录也使用 \CTeX{} 的编号。}
% 让编译时终端显示  \tn{CTEXthechapter},目录使用 |\CTEXtheXXX| 编号。
%    \begin{macrocode}
\ctex_at_end_package:nn { titlesec }
  {
%<*book|report>
    \tl_set:Nn \ttl@chapterout { \typeout { \CTEXthechapter } }
%</book|report>
    \cs_if_free:NF \ttl@tocpart
      {
        \cs_set_protected:Npn \ttl@tocpart
          { \tl_set:Nn \ttl@a { \CTEXthepart \hspace { 1em } } }
      }
    \seq_map_inline:Nn \c_@@_headings_seq
      {
        \cs_if_exist:cF { ttl@toc #1 }
          {
            \cs_new_protected:cpx { ttl@toc #1 }
              {
                \tl_set:Nn \exp_not:N \ttl@a
                  {
                    \exp_not:N \protect
                    \exp_not:N \numberline { \exp_not:c { CTEXthe #1 } }
                  }
              }
          }
      }
  }
%    \end{macrocode}
%
% \changes{v2.5.8}{2021/12/04}{兼容 \pkg{titlesec} 包和 \tn{CTEXifname}。}
% 在 \pkg{titlesec} 包定义的标题中更新 \tn{CTEXifname}。
%    \begin{macrocode}
\ctex_at_end_package:nn { titlesec }
  {
    \ctex_patch_cmd:Nnn \ttl@labelling
      { \let \ifttl@toclabel \ifttl@label }
      {
        \let \ifttl@toclabel \ifttl@label
        \CTEX@updatettlifname
      }
    \cs_new_protected:Npn \CTEX@updatettlifname
      { \ifttl@label \CTEX@ifnametrue \else: \CTEX@ifnamefalse \fi: }
  }
%    \end{macrocode}
%
% \paragraph{兼容 \pkg{titleps} 宏包}
%
% \changes{v2.3}{2015/12/25}{兼容 \pkg{titleps} 宏包。}
%
% 按照 \pkg{titleps} 宏包的实现机制,|\CTEXtheXXX| 等宏直到页眉排版时才会被展开,
% 这可能会造成问题\footnote{\url{https://github.com/CTeX-org/ctex-kit/issues/217}}。
%
% \begin{macro}[int]{\ctex_titleps_hook:}
% 我们修改 \pkg{titleps} 包的内部命令 \tn{ttl@settopmark} 和 \tn{ttl@setsubmark},
% 将 |\CTEXtheXXX| 等加入更新队列中。
%    \begin{macrocode}
\group_begin:
\char_set_catcode_other:N \#
\cs_new_protected:Npn \ctex_titleps_hook:
  {
    \ctex_patch_cmd:Nnn \ttl@settopmark
      { \protect \@namedef { the#1 } { \@nameuse { the#1 } } }
      {
        \protect \@namedef { the#1 } { \@nameuse { the#1 } }
        \CTEX@titlepslabel@set {#1}
      }
    \ctex_patch_cmd:Nnn \ttl@setsubmark
      { \protect \@namedef { the#1 } { } }
      {
        \protect \@namedef { the#1 } { }
        \CTEX@titlepslabel@clear {#1}
      }
    \ctex_patch_cmd:Nnn \ttl@setsubmark
      { \protect \@namedef { the#2 } { \@nameuse { the#2 } } }
      {
        \protect \@namedef { the#2 } { \@nameuse { the#2 } }
        \CTEX@titlepslabel@set {#2}
      }
  }
\group_end:
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\CTEX@titlepslabel@set,\CTEX@titlepslabel@clear}
% 这两个函数要在随后被 \tn{xdef} 展开来获得 |\CTEXtheXXX| 的内容,不应该用
% \tn{protected} 来定义。
%    \begin{macrocode}
\cs_new:Npn \CTEX@titlepslabel@set #1
  {
    \cs_if_free:cF { CTEXthe#1 }
      { \protect \@namedef { CTEXthe#1 } { \@nameuse { CTEXthe#1 } } }
  }
\cs_new:Npn \CTEX@titlepslabel@clear #1
  {
    \cs_if_free:cF { CTEXthe#1 }
      { \protect \@namedef { CTEXthe#1 } { } }
  }
%    \end{macrocode}
% \end{macro}
%
% \pkg{titleps} 宏包的功能可以由 \pkg{titlesec} 的选项 \opt{pagestyles} 引入。
%    \begin{macrocode}
\ctex_at_end_package:nn { titlesec }
  { \cs_if_free:NF \ttl@settopmark { \ctex_titleps_hook: } }
\ctex_at_end_package:nn { titleps } { \ctex_titleps_hook: }
%    \end{macrocode}
%
% 除此之外,也可以使用 \pkg{titleps} 提供的命令 \tn{newtitlemark} 来完成:
% \begin{verbatim}
%   \newtitlemark { \CTEXthechapter }
%   \newtitlemark { \CTEXthesection }
% \end{verbatim}
% 但 \tn{newtitlemark} 不包含章节间的层次信息,功能上不及修改内部命令完整。
%
% \changes{v2.4.6}{2016/10/31}{重新初始化 \tn{ifthechapter} 等。}
% \begin{macro}[int]{\ttl@setifthe}
% 使 |\iftheXXX| 等命令在页眉设置中可用。
%    \begin{macrocode}
\ctex_at_end_package:nn { titleps }
  {
    \cs_set_protected:Npn \ttl@setifthe #1
      {
        \exp_args:Nco \cs_set:Npn { ifthe #1 }
          {
            \CTEXifname
              { \protect \@firstoftwo }
              { \protect \@secondoftwo }
          }
      }
    \seq_map_function:NN \c_@@_headings_seq \ttl@setifthe
  }
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{目录标签的宽度}
%
% \begin{macro}{\CTEX@toc@width@n}
%   \begin{macrocode}
\cs_new_protected:Npn \CTEX@toc@width@n #1
  {
    \hbox_set:Nn \l_@@_tmp_box {#1}
    \dim_set:Nn \@tempdima
      {
        \dim_max:nn { \@tempdima }
          { \box_wd:N \l_@@_tmp_box + \f@size \p@ / 2 }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5}{2020/01/11}{兼容 \pkg{titletoc} 宏包。}
%
% \begin{macro}{\numberline,\@@_patch_toc_width:n}
% 为 \tn{numberline} 命令打补丁,并兼容 \pkg{tocloft} 和 \pkg{titletoc} 宏包。
%
% 这里需要替换 |#| 本身,因此需要先切换为 other 类。表示参数的 |#| 用
% \cs{c_parameter_token} 代替。
%   \begin{macrocode}
\group_begin:
\char_set_catcode_other:N \#
\use:n
  {
    \group_end:
    \ctex_preto_cmd:NnnTF \numberline { \ExplSyntaxOff }
      { \CTEX@toc@width@n {#1} }
      { }
      { \ctex_patch_failure:N \numberline }
    \cs_new_protected:Npn \@@_patch_toc_width:n \c_parameter_token 1
      {
        \@ifpackageloaded { \c_parameter_token 1 }
          { }
          {
            \ctex_at_end_package:nn { \c_parameter_token 1 }
              {
                \ctex_preto_cmd:NnnTF \numberline
                  { \char_set_catcode_letter:n { 64 } }
                  { \CTEX@toc@width@n {#1} }
                  { }
                  { \ctex_patch_failure:N \numberline }
              }
          }
      }
  }
\@@_patch_toc_width:n { tocloft  }
\@@_patch_toc_width:n { titletoc }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{页眉信息的修改}
%
% \begin{macro}[int]{\ps@headings}
% \changes{v2.4.5}{2016/10/01}{修复补丁失败。}
% \changes{v2.4.7}{2016/12/23}{修复 \cls{ctexrep} 类的 \tn{chaptermark} 汉化错误。}
% \changes{v2.4.11}{2017/09/13}{补充页眉空格。}
%    \begin{macrocode}
%<*article>
\if@twoside
  \ctex_patch_cmd:Nnn \ps@headings
    { \ifnum \c@secnumdepth > \z@ \thesection \quad \fi }
    { \CTEXifname { \CTEXthesection \quad } { } }
  \ctex_patch_cmd:Nnn \ps@headings
    { \ifnum \c@secnumdepth > \@ne \thesubsection \quad \fi }
    { \CTEXifname { \CTEXthesubsection \quad } { } }
\else:
%    \end{macrocode}
% 不知为何,标准文档类此处对 \texttt{secnumdepth} 的判断为 $0$,与 \tn{section} 的层次 $1$ 不符。
%    \begin{macrocode}
  \ctex_patch_cmd:Nnn \ps@headings
    { \ifnum \c@secnumdepth > \m@ne \thesection \quad \fi }
    { \CTEXifname { \CTEXthesection \quad } { } }
\fi:
%</article>
%<*book|report>
\ctex_patch_cmd:Nnn \ps@headings
  {
%<book>    \ifnum \c@secnumdepth > \m@ne \if@mainmatter
%<report>    \ifnum \c@secnumdepth > \m@ne
      \@chapapp \ \thechapter . ~ \ %
%<report>    \fi
%<book>    \fi \fi
  }
  { \CTEXifname { \CTEXthechapter \quad } { } }
\if@twoside
  \ctex_patch_cmd:Nnn \ps@headings
    { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
    { \CTEXifname { \CTEXthesection \quad } { } }
\fi:
%</book|report>
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}[int]{\f@nch@initialise}
% 这里对 \pkg{fancyhdr} 宏包打补丁。原来 \pkg{fancyhdr} 宏包中使用
% \tn{thesection} 等宏表示页眉中的章节编号,这里改用 \pkg{ctex} 包所用的
% \tn{CTEXthesection} 系列宏。
% \changes{v2.5.6}{2021/01/11}{更新 \pkg{fancyhdr} 宏包的补丁。}
%    \begin{macrocode}
\ctex_at_end_package:nn { fancyhdr }
  {
    \ctex_patch_cmd:Nnn \f@nch@initialise
      { \ifnum \c@secnumdepth > \z@ \thesection \hskip 1em \relax \fi }
      { \CTEXifname { \CTEXthesection \quad } { } }
    \ctex_patch_cmd:Nnn \f@nch@initialise
      { \ifnum \c@secnumdepth > \@ne \thesubsection \hskip 1em \relax \fi }
      { \CTEXifname { \CTEXthesubsection \quad } { } }
    \ctex_patch_cmd:Nnn \f@nch@initialise
      { \ifnum \c@secnumdepth > \m@ne \@chapapp\ \thechapter . ~ \ \fi }
      { \CTEXifname { \CTEXthechapter \quad } { } }
    \ctex_patch_cmd:Nnn \f@nch@initialise
      { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
      { \CTEXifname { \CTEXthesection \quad } { } }
    \f@nch@initialise
%    \end{macrocode}
% \pkg{fancyhdr} 的 \opt{headings} 选项会重定义 \cs{ps@headings},
% 这里也要打补丁。
%    \begin{macrocode}
    \@ifpackagewith { fancyhdr } { headings }
      {
%<*article>
        \if@twoside
          \ctex_patch_cmd:Nnn \ps@headings
            { \ifnum \c@secnumdepth > \z@ \thesection \quad \fi }
            { \CTEXifname { \CTEXthesection \quad } { } }
          \ctex_patch_cmd:Nnn \ps@headings
            { \ifnum \c@secnumdepth > \@ne \thesubsection \quad \fi }
            { \CTEXifname { \CTEXthesubsection \quad } { } }
        \else:
          \ctex_patch_cmd:Nnn \ps@headings
            { \ifnum \c@secnumdepth > \z@ \thesection \quad \fi }
            { \CTEXifname { \CTEXthesection \quad } { } }
        \fi:
%</article>
%<*book|report>
        \ctex_patch_cmd:Nnn \ps@headings
          {
%<book>            \ifnum \c@secnumdepth > \m@ne \if@mainmatter
%<report>            \ifnum \c@secnumdepth > \m@ne
              \@chapapp \ \thechapter . ~ \ %
%<report>            \fi
%<book>            \fi \fi
          }
          { \CTEXifname { \CTEXthechapter \quad } { } }
        \if@twoside
          \ctex_patch_cmd:Nnn \ps@headings
            { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
            { \CTEXifname { \CTEXthesection \quad } { } }
        \fi:
%</book|report>
      }
      { }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</article|book|report>
%    \end{macrocode}
%
% \subsubsection{\cls{beamer} 标题页模板的修改}
%
%    \begin{macrocode}
%<*beamer>
%    \end{macrocode}
%
%    \begin{macrocode}
\ExplSyntaxOff
%    \end{macrocode}
%
% \changes{v2.4.15}{2019/01/29}{局部指定 \opt{autoindent} 为 \opt{false},并交换
%   \tn{CTEX@XXX@indent} 与 \tn{CTEX@XXX@format} 的顺序。}
%
% 对应 \tn{partpage}。
%    \begin{macrocode}
\defbeamertemplate*{part page}{CTEX}[1][]{%
  \begingroup
%    \centering
%    {\usebeamerfont{part name}%
%     \usebeamercolor[fg]{part name}\partname~\insertromanpartnumber}
%    \vskip1em\par
    \par \addvspace{\glueexpr\CTEX@part@beforeskip\relax}%
    \CTEX@heading@format@initial
    \CTEX@part@format{%
      \CTEX@indentbox{\CTEX@part@indent}%
      \ifodd \CTEX@part@numbering
        \CTEX@partname \CTEX@part@aftername
      \fi
      \begin{beamercolorbox}[sep=16pt,center,#1]{part title}
%       \usebeamerfont{part title}\insertpart\par
        \CTEX@part@titleformat \insertpart \CTEX@part@aftertitle
      \end{beamercolorbox}}%
    \par \addvspace{\glueexpr\CTEX@part@afterskip\relax}%
  \endgroup}
%    \end{macrocode}
%
% 对应 \tn{sectionpage}。
%    \begin{macrocode}
\defbeamertemplate*{section page}{CTEX}[1][]{%
  \begingroup
%    \centering
%    {\usebeamerfont{section name}%
%     \usebeamercolor[fg]{section name}\sectionname~\insertsectionnumber}
%    \vskip1em\par
    \par \addvspace{\glueexpr\CTEX@section@beforeskip\relax}%
    \CTEX@heading@format@initial
    \CTEX@section@format{%
      \CTEX@indentbox{\CTEX@section@indent}%
      \ifodd \CTEX@section@numbering
        \CTEX@sectionname \CTEX@section@aftername
      \fi
      \begin{beamercolorbox}[sep=12pt,center,#1]{part title}
%       \usebeamerfont{section title}\insertsection\par
        \CTEX@section@titleformat \insertsection \CTEX@section@aftertitle
      \end{beamercolorbox}}%
    \par \addvspace{\glueexpr\CTEX@section@afterskip\relax}%
  \endgroup}
%    \end{macrocode}
%
% 对应 \tn{subsectionpage}。
%    \begin{macrocode}
\defbeamertemplate*{subsection page}{CTEX}[1][]{%
  \begingroup
%    \centering
%    {\usebeamerfont{subsection name}%
%     \usebeamercolor[fg]{subsection name}\subsectionname~\insertsubsectionnumber}
%    \vskip1em\par
    \par \addvspace{\glueexpr\CTEX@subsection@beforeskip\relax}%
    \CTEX@heading@format@initial
    \CTEX@subsection@format{%
      \CTEX@indentbox{\CTEX@subsection@indent}%
      \ifodd \CTEX@subsection@numbering
        \CTEX@subsectionname \CTEX@subsection@aftername
      \fi
      \begin{beamercolorbox}[sep=8pt,center,#1]{part title}
%       \usebeamerfont{subsection title}\insertsubsection\par
        \CTEX@subsection@titleformat \insertsubsection \CTEX@subsection@aftertitle
      \end{beamercolorbox}}%
    \par \addvspace{\glueexpr\CTEX@subsection@afterskip\relax}%
  \endgroup}
%    \end{macrocode}
%
% 将 \cls{beamer} 的默认模板重定向为 \texttt{CTEX} 模板。
%    \begin{macrocode}
\defbeamertemplatealias{part page}{default}{CTEX}
\defbeamertemplatealias{section page}{default}{CTEX}
\defbeamertemplatealias{subsection page}{default}{CTEX}
%    \end{macrocode}
%
%    \begin{macrocode}
\ExplSyntaxOn
%    \end{macrocode}
%
%    \begin{macrocode}
%</beamer>
%    \end{macrocode}
%
% \subsubsection{标题编号和目录的层次设置}
%
% \changes{v2.5.2}{2020/05/06}{新增标题选项 \opt{secnumdepth} 和 \opt{tocdepth}。}
%
% \begin{macro}{secnumdepth, tocdepth}
% \opt{secnumdepth} 在 \cls{beamer} 下无意义。
%    \begin{macrocode}
\ctex_define:n
  {
%<*!beamer>
    secnumdepth           .code:n = \ctex_heading_depth:ne { secnumdepth } {#1} ,
    secnumdepth .value_required:n = true ,
%</!beamer>
    tocdepth              .code:n = \ctex_heading_depth:ne { tocdepth } {#1} ,
    tocdepth    .value_required:n = true
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_heading_depth:nn}
% 注意此处 \tn{setcounter} 的赋值是全局的。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_heading_depth:nn #1#2
  {
    \prop_get:NnNTF \c_@@_heading_level_prop {#2} \l_@@_tmp_tl
      { \setcounter {#1} { \l_@@_tmp_tl } }
      { \setcounter {#1} { \int_eval:n {#2} } }
  }
\cs_generate_variant:Nn \ctex_heading_depth:nn { ne }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}[int]{\c_@@_heading_level_prop}
% 章节层次与名称的对应表。
%    \begin{macrocode}
\prop_const_from_keyval:Nn \c_@@_heading_level_prop
  {
%<*article|beamer>
    part          =  0 ,
%</article|beamer>
%<*book|report>
    part          = -1 ,
    chapter       =  0 ,
%</book|report>
    section       =  1 ,
    subsection    =  2 ,
    subsubsection =  3 ,
    paragraph     =  4 ,
    subparagraph  =  5
  }
%    \end{macrocode}
% \end{variable}
%
% \subsubsection{标签引用数字的汉化}
%
% \begin{macro}[int]{\refstepcounter}
% 对标题进行引用时,设置标签为通过 \opt{number} 选项设置的形式。
%    \begin{macrocode}
\cs_new_protected:Npn \CTEX@setcurrentlabel@n #1
  {
    \protected@edef \@currentlabel
      {
        \cs_if_exist:cTF { CTEX@the#1 }
          { \exp_args:cc { p@#1 } { CTEX@the#1 } }
          { \exp_not:o { \@currentlabel } }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_varioref_hook:}
% 关于标签引用的宏包可能会修改 \tn{refstepcounter}。其中 \pkg{cleveref} 和
% \pkg{hyperref} 宏包都会保存之前的定义,并且它们都要求尽可能晚的被载入,所以
% 对我们上述的修改影响不大。需要注意的是 \pkg{varioref} 宏包,如果它在
% \CTeX{} 之后被载入,我们之前的修改将会被覆盖。
% 较新版 \LaTeX \ 内核已经包含 \tn{labelformat},可以直接使用。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_varioref_hook:
  {
    \seq_map_inline:Nn \c_@@_headings_seq
      { \ctex_fix_varioref_label:n { ##1 } }
    \ctex_at_end_package:nn { cleveref } { \ctex_cleveref_hook: }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ctex_fix_varioref_label:n}
% \pkg{varioref} 宏包的 \tn{labelformat} 实际上是定义一个以 |\the<#1>| 为参数的宏
% |\p@<#1>|。\LaTeX{} 在定义计数器 |<#1>| 时,都会将 |\p@<#1>| 初始化为 \tn{@empty}。
% 如果这个宏非空,说明用户自定义了标签格式,我们就不再修改。这里不能使用
% \cs{exp_args:Nnc},因为 \texttt{c} 这种展开格式不会将参数放在花括号内。而
% \tn{labelformat} 的定义是
% \begin{verbatim}
%   \def\labelformat#1{\expandafter\def\csname p@#1\endcsname##1}
% \end{verbatim}
% 它的第二个参数必须放在花括号内,否则将会被作为宏的定界符号。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_fix_varioref_label:n #1
  {
    \tl_if_empty:cT { p@#1 }
      { \exp_args:Nnx \labelformat {#1} { \exp_not:c { CTEX@the#1 } } }
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5.3}{2020/06/04}{兼容 \pkg{cleveref}。}
% \changes{v2.5.4}{2020/06/17}{同时兼容 \pkg{cleveref} 和 \pkg{hyperref}。}
% \changes{v2.5.7}{2021/06/04}{同时兼容 \pkg{cleveref} 和 \cls{beamer}。}
% \begin{macro}{\ctex_cleveref_hook:,\@@_cleveref_hook_aux:N}
% 需要将\pkg{cleveref} 包对应命令中 |\p@|\meta{counter} 的参数及时展开,以兼容 \tn{labelformat}。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_cleveref_hook:
  {
    \@ifpackageloaded { hyperref }
      {
        \@ifpackagewith { hyperref } { implicit = false }
          { }
          { \@@_cleveref_hook_aux:N \H@refstepcounter }
      }
      {
        \@@_cleveref_hook_aux:N \refstepcounter@noarg
        \@@_cleveref_hook_aux:N \refstepcounter@optarg
      }
    \@@_cleveref_hook_aux:N \appendix
  }
\cs_new_protected:Npn \@@_cleveref_hook_aux:N #1
  {
    \ctex_patch_cmd_all:NnnnTF #1
      {
        \ExplSyntaxOff
        \char_set_catcode_letter:n { 64 }
      }
      { \endcsname \csname the }
      { \expandafter \endcsname \csname the }
      { }
      { \ctex_patch_failure:N #1 }
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5}{2020/04/19}{应用新内核中的 \tn{labelformat}。}
%
% 如果 \pkg{varioref} 已经被载入,则使用它来设置。
%    \begin{macrocode}
\cs_if_exist:NTF \labelformat
  { \ctex_varioref_hook: }
  {
    \cs_new_eq:NN \CTEX@save@refstepcounter \refstepcounter
    \RenewDocumentCommand \refstepcounter { m }
      {
        \CTEX@save@refstepcounter {#1}
        \CTEX@setcurrentlabel@n {#1}
      }
    \ctex_at_end_package:nn { varioref } { \ctex_varioref_hook: }
  }
%    \end{macrocode}
%
% \subsubsection{载入 \meta{scheme} 文件}
%
%    \begin{macrocode}
\ctex_scheme_input:o { \l_@@_scheme_tl }
%    \end{macrocode}
%
%    \begin{macrocode}
%</class|heading>
%    \end{macrocode}
%
% \subsubsection{标题格式的 \opt{scheme} 定义}
%
% 下面使用 \CTeX 文档类的设置方式,\opt{plain} 模拟标准文档类直接定义或以
% \tn{@startsection} 设定的章节标题格式,\opt{chinese} 汉化的标题格式。
%
%    \begin{macrocode}
%<*scheme&(article|book|report|beamer)>
%    \end{macrocode}
%
% \changes{v2.1}{2015/05/30}{修复 \cls{ctexbook} 和 \cls{ctexrep} 类的中文
% \opt{part/number} 选项初值为空的错误。}
% \changes{v2.2}{2015/06/30}{将中文版式下的 \texttt{part} 和 \texttt{chapter}
% 标题的 \opt{nameformat} 和 \opt{titleformat} 选项的初值合并到 \opt{format} 中。}
%
%    \begin{macrocode}
\ctex_set:nn { part }
  {
    aftertitle  = \par ,
%<*article|book|report>
    hang        = false ,
%</article|book|report>
%<*plain>
    name        = \partname \space ,
%<*article|book|report>
    number      = \thepart ,
%</article|book|report>
%<*beamer>
    number      = \insertromanpartnumber ,
%</beamer>
%</plain>
%<*chinese>
    number      = \chinese { part } ,
%</chinese>
%<*article>
    beforeskip  = 4ex ,
    afterskip   = 3ex ,
%<*plain>
    format      = \raggedright ,
    nameformat  = \Large \bfseries ,
    aftername   = \par \nobreak ,
    titleformat = \huge \bfseries ,
    afterindent = false
%</plain>
%<*chinese>
    format      = \Large \bfseries \centering ,
    aftername   = \quad ,
    afterindent = true
%</chinese>
%</article>
%<*book|report>
    aftername   = \par \vskip 20 \p@ ,
    beforeskip  = 0pt \@plus 1fil ,
    afterskip   = 0pt \@plus 1fil ,
    pagestyle   = plain ,
    break       = \if@openright \cleardoublepage \else \clearpage \fi ,
%<*plain>
    format      = \centering ,
    nameformat  = \huge \bfseries ,
    titleformat = \Huge \bfseries
%</plain>
%<*chinese>
    format      = \huge \bfseries \centering
%</chinese>
%</book|report>
%<*beamer>
    format      = \centering ,
    nameformat  = \usebeamerfont { part ~ name }
                  \usebeamercolor [fg] { part ~ name } ,
    aftername   = \vskip 1em \par ,
    titleformat = \usebeamerfont { part ~ title }
%</beamer>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
%<*book|report>
\ctex_set:nn { chapter }
  {
    pagestyle   = plain ,
    aftertitle  = \par ,
    hang        = false ,
    beforeskip  = 50 \p@ ,
    afterskip   = 40 \p@ ,
    lofskip     = 10 \p@ ,
    lotskip     = 10 \p@ ,
    break       = \if@openright \cleardoublepage \else \clearpage \fi ,
%<*plain>
    name        = \chaptername \space ,
    number      = \thechapter ,
    format      = \raggedright ,
    nameformat  = \huge \bfseries ,
    aftername   = \par \nobreak \vskip 20 \p@ ,
    titleformat = \Huge \bfseries ,
    afterindent = false ,
    tocline     = \CTEXnumberline {#1} #2
%</plain>
%<*chinese>
    number      = \chinese { chapter } ,
    format      = \huge \bfseries \centering ,
    aftername   = \quad ,
    afterindent = true
%</chinese>
  }
%</book|report>
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { section }
  {
%<*article|book|report>
    number      = \thesection ,
    aftername   = \quad ,
    aftertitle  = \@@@@par ,
    beforeskip  = 3.5ex \@plus 1ex \@minus .2ex ,
    afterskip   = 2.3ex \@plus .2ex ,
    runin       = false ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    format      = \Large \bfseries ,
    afterindent = false
%</plain>
%<*chinese>
    format      = \Large \bfseries \centering ,
    afterindent = true
%</chinese>
%</article|book|report>
%<*beamer>
%<*plain>
    name        = \sectionname \space ,
%</plain>
    format      = \centering ,
    number      = \insertsectionnumber ,
    nameformat  = \usebeamerfont { section ~ name }
                  \usebeamercolor [fg] { section ~ name } ,
    aftername   = \vskip 1em \par ,
    titleformat = \usebeamerfont { section ~ title } ,
    aftertitle  = \par
%</beamer>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { subsection }
  {
%<*article|book|report>
    number      = \thesubsection ,
    format      = \large \bfseries ,
    aftername   = \quad ,
    aftertitle  = \@@@@par ,
    beforeskip  = 3.25ex \@plus 1ex \@minus .2ex ,
    afterskip   = 1.5ex  \@plus .2ex ,
    runin       = false ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    afterindent = false
%</plain>
%<*chinese>
    afterindent = true
%</chinese>
%</article|book|report>
%<*beamer>
%<*plain>
    name        = \subsectionname \space ,
    number      = \insertsubsectionnumber ,
%</plain>
%<*chinese>
    number      = \arabic { section } . \arabic { subsection } ,
%</chinese>
    format      = \centering ,
    nameformat  = \usebeamerfont { subsection ~ name }
                  \usebeamercolor [fg] { subsection ~ name } ,
    aftername   = \vskip 1em \par ,
    titleformat = \usebeamerfont { subsection ~ title } ,
    aftertitle  = \par
%</beamer>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
%<*article|book|report>
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { subsubsection }
  {
    number      = \thesubsubsection ,
    format      = \normalsize \bfseries ,
    aftername   = \quad ,
    aftertitle  = \@@@@par ,
    beforeskip  = 3.25ex \@plus 1ex \@minus .2ex ,
    afterskip   = 1.5ex \@plus .2ex ,
    runin       = false ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    afterindent = false
%</plain>
%<*chinese>
    afterindent = true
%</chinese>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { paragraph }
  {
    number      = \theparagraph ,
    format      = \normalsize \bfseries ,
    aftername   = \quad ,
    beforeskip  = 3.25ex \@plus 1ex \@minus .2ex ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    afterindent = false
%</plain>
%<*chinese>
    afterindent = true
%</chinese>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { subparagraph }
  {
    number      = \thesubparagraph ,
    format      = \normalsize \bfseries ,
    aftername   = \quad ,
    beforeskip  = 3.25ex \@plus 1ex \@minus .2ex ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    afterindent = false
%</plain>
%<*chinese>
    afterindent = true
%</chinese>
  }
%    \end{macrocode}
%
% 处理 \opt{sub3section} 与 \opt{sub4section} 的格式。
%    \begin{macrocode}
\int_compare:nNnTF \g_@@_section_depth_int > 2
  {
    \ctex_set:nn { paragraph }
      {
        aftertitle  = \@@@@par ,
        afterskip   = 1ex \@plus .2ex ,
        runin       = false
      }
  }
  {
    \ctex_set:nn { paragraph }
      {
        afterskip   = 1em ,
        runin       = true
      }
  }
\int_compare:nNnTF \g_@@_section_depth_int > 3
  {
    \ctex_set:nn { subparagraph }
      {
        aftertitle  = \@@@@par ,
        afterskip   = 1ex \@plus .2ex ,
        runin       = false
      }
  }
  {
    \ctex_set:nn { subparagraph }
      {
        afterskip   = 1em ,
        runin       = true
      }
  }
\int_compare:nNnTF \g_@@_section_depth_int > 2
  { \ctex_set:nn { subparagraph } { indent = \c_zero_dim } }
  { \ctex_set:nn { subparagraph } { indent = \parindent } }
%    \end{macrocode}
%
% 处理附录的格式。
%    \begin{macrocode}
\ctex_set:nn { appendix }
%<*article>
  { number      = \@Alph \c@section }
%</article>
%<*book|report>
  {
    name        = \appendixname \space ,
    number      = \@Alph \c@chapter
  }
%</book|report>
%    \end{macrocode}
%
%    \begin{macrocode}
%</article|book|report>
%    \end{macrocode}
%
%    \begin{macrocode}
%</scheme&(article|book|report|beamer)>
%    \end{macrocode}
%
% \subsubsection{\pkg{ctex.sty} 的 \opt{heading} 选项}
%
%    \begin{macrocode}
%<*ctex|ctexheading>
%    \end{macrocode}
%
% \begin{variable}{\c_@@_std_class_tl}
% 用于记录被引入的标准文档类。
%    \begin{macrocode}
\clist_map_inline:nn { article , book , report , beamer }
  {
    \@ifclassloaded {#1}
      { \clist_map_break:n { \tl_const:Nn \c_@@_std_class_tl {#1} } }
      { }
  }
%    \end{macrocode}
% \end{variable}
%
% 若标准文档类被引入,则载入对应的标题定义文件。否则视 \tn{chapter} 是否有定义来
% 引入 \cls{book} 或者 \cls{article}。
%    \begin{macrocode}
\msg_new:nnn { ctex } { not-standard-class }
  {
    None~of~the~standard~document~classes~was~loaded.\\
    Heading~`#1'~is~selected.\\
    ctex~may~not~work~as~expected.
  }
%<ctex>\bool_if:NTF \l_@@_heading_bool
%<ctexheading>\use:n
  {
    \tl_if_exist:NTF \c_@@_std_class_tl
      { \cs_new_eq:NN \c_@@_class_tl \c_@@_std_class_tl }
      {
        \cs_if_exist:NTF \chapter
          {
            \cs_if_exist:NF \if@mainmatter
              { \cs_new_eq:NN \if@mainmatter \tex_iftrue:D }
            \tl_const:Nn \c_@@_class_tl { book }
          }
          { \tl_const:Nn \c_@@_class_tl { article } }
        \msg_warning:nnx { ctex } { not-standard-class } { \c_@@_class_tl }
      }
    \ctex_file_input:n { ctex-heading- \c_@@_class_tl .def }
  }
%<ctex>  { \ctex_scheme_input:o { \l_@@_scheme_tl } }
%    \end{macrocode}
%
%    \begin{macrocode}
%</ctex|ctexheading>
%    \end{macrocode}
%
% \subsubsection{标题配置文件}
%
%    \begin{macrocode}
%<*name>
%    \end{macrocode}
%
%    \begin{macrocode}
\keys_set_known:nn { ctex }
  {
    contentsname   = 目录 ,
    listfigurename = 插图 ,
    listtablename  = 表格 ,
    figurename     = 图 ,
    tablename      = 表 ,
    abstractname   = 摘要 ,
    indexname      = 索引 ,
    bibname        = 参考文献 ,
    appendixname   = 附录 ,
    proofname      = 证明 ,
    algorithmname  = 算法 ,
    refname        = 参考文献 ,
    continuation   = (续) ,
    part    / name = { 第 , 部分 } ,
    chapter / name = { 第 , 章 }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
%</name>
%    \end{macrocode}
%
% \subsection{\opt{chinese} 方案的其他设置}
%
%    \begin{macrocode}
%<*scheme&chinese>
%    \end{macrocode}
%
% \opt{chinese} 在标准文档类下的页面格式总采用 \texttt{headings}。
%    \begin{macrocode}
%<article|book|report>\pagestyle { headings }
%    \end{macrocode}
%
% 日期格式。
%    \begin{macrocode}
\ctex_set:n { today = small }
%    \end{macrocode}
%
% 若用户未设置宏包选项 \opt{autoindent},则自动调整首行缩进。
%    \begin{macrocode}
\ctex_if_autoindent_touched:F
  { \ctex_set:n { autoindent = true } }
%    \end{macrocode}
%
% 使用标题定义时的设置。首先是命题名字汉化。\cls{beamer} 需要汉化定理名称。
%    \begin{macrocode}
%<*!generic>
\str_if_eq:onTF { \g_@@_encoding_tl } { GBK }
%<*beamer>
  {
    \uselanguage { ChineseGBK }
    \languagealias { chinese } { ChineseGBK }
    \ctex_file_input:n { ctex-name-gbk.cfg }
  }
  {
    \uselanguage { ChineseUTF8 }
    \languagealias { chinese } { ChineseUTF8 }
    \ctex_file_input:n { ctex-name-utf8.cfg }
  }
%    \end{macrocode}
% 让 \pkg{translator} 包优先查找中文翻译。
%    \begin{macrocode}
\clist_put_left:Nn \trans@languagepath { chinese }
%</beamer>
%<*!beamer>
  { \ctex_file_input:n { ctex-name-gbk.cfg } }
  { \ctex_file_input:n { ctex-name-utf8.cfg } }
%    \end{macrocode}
%
% \changes{v2.4.1}{2016/05/09}{\cls{beamer} 不调整默认字体大小。}
% 对 \cls{beamer} 以外的文档类,若用户未设置宏包选项 \opt{zihao},则设置 \tn{normalsize}
% 为五号字。\cls{beamer} 不调整默认字体大小。
%    \begin{macrocode}
\int_compare:nNnF \g_@@_font_size_int > { -1 }
  { \int_gset:Nn \g_@@_font_size_int { 0 } }
%    \end{macrocode}
%
% \changes{v2.4.1}{2016/05/09}{\cls{beamer} 不调整默认行距。}
% 对 \cls{beamer} 以外的文档类,若用户未设置宏包选项 \opt{linespread},则设置行
% 距初始值为 $1.3\times 1.2=1.56$ 倍字体大小。\cls{beamer} 不调整行距。
%    \begin{macrocode}
\fp_if_nan:nT { \l_@@_line_spread_fp }
  { \fp_set:Nn \l_@@_line_spread_fp { 1.3 } }
%</!beamer>
%</!generic>
%    \end{macrocode}
%
% 不使用标题定义时的通用设置,注意此处 \cs{c_@@_std_class_tl} 可能没有定义。
%    \begin{macrocode}
%<*generic>
\tl_set:Nn \l_@@_tmp_tl { beamer }
\tl_if_eq:NNTF \c_@@_std_class_tl \l_@@_tmp_tl
  {
    \str_if_eq:onTF { \g_@@_encoding_tl } { GBK }
      {
        \uselanguage { ChineseGBK }
        \languagealias { chinese } { ChineseGBK }
        \ctex_file_input:n { ctex-name-gbk.cfg }
      }
      {
        \uselanguage { ChineseUTF8 }
        \languagealias { chinese } { ChineseUTF8 }
        \ctex_file_input:n { ctex-name-utf8.cfg }
      }
    \clist_put_left:Nn \trans@languagepath { chinese }
  }
  {
    \str_if_eq:onTF { \g_@@_encoding_tl } { GBK }
      { \ctex_file_input:n { ctex-name-gbk.cfg } }
      { \ctex_file_input:n { ctex-name-utf8.cfg } }
    \int_compare:nNnF \g_@@_font_size_int > { -1 }
      { \int_gset:Nn \g_@@_font_size_int { 0 } }
    \fp_if_nan:nT { \l_@@_line_spread_fp }
      { \fp_set:Nn \l_@@_line_spread_fp { 1.3 } }
%    \end{macrocode}
% \changes{v2.0.2}{2015/05/16}{修复加载 \pkg{ctex} 宏包后章节标题后第一段
% 无段首缩进的问题。}
% 若 \pkg{ctex} 宏包与标准文档类及其衍生文档类联用,则将载入 \pkg{indentfirst} 宏包,
% 实现章节标题后首个段落的段首缩进。
%    \begin{macrocode}
    \tl_if_exist:NT \c_@@_std_class_tl
      { \RequirePackage { indentfirst } }
  }
%</generic>
%    \end{macrocode}
%
%    \begin{macrocode}
%</scheme&chinese>
%    \end{macrocode}
%
% \subsection{中文字号}
%
%    \begin{macrocode}
%<*class|ctex|ctexsize>
%    \end{macrocode}
%
% \changes{v2.0}{2014/03/08}{将中文字号功能提取到可以独立使用的 \pkg{ctexsize}。}
%
% \begin{macro}{\zihao}
%    \begin{macrocode}
\NewDocumentCommand \zihao { m }
  { \exp_args:Nx \ctex_zihao:n {#1} \tex_ignorespaces:D }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_zihao:n}
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_zihao:n #1
  {
    \prop_get:NnNTF \c_@@_font_size_prop {#1} \l_@@_font_size_tl
      { \exp_after:wN \fontsize \l_@@_font_size_tl \selectfont }
      { \msg_error:nnn { ctex } { fontsize } {#1} }
  }
\msg_new:nnnn { ctex } { fontsize }
  { Undefined~Chinese~font~size~`#1'~in~command~\token_to_str:N \zihao.}
  {
    The~old~font~size~is~used~if~you~continue.\\
    The~available~font~sizes~are~listed~as~follow.\\
    \seq_use:Nnnn \c_@@_font_size_seq { ~and~ } { ,~ } { ,~and~ }.
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{定义中文字号}
%
% \changes{v2.0}{2014/03/08}{中文字号不再采用近似值。}
%
% \begin{variable}{\c_@@_font_size_prop}
% \begin{macro}{\@@_save_font_size:nn}
% 基础行距是字号的 $1.2$ 倍,采用 \hologo{eTeX} 的 scaling 运算得到的结果
% 要比简单的 |1.2\dimexpr| 精确^^A
% \footnote{\url{http://thread.gmane.org/gmane.comp.tex.latex.latex3/3190}}。
%    \begin{macrocode}
\prop_new:N \c_@@_font_size_prop
\seq_new:N \c_@@_font_size_seq
\cs_new_protected:Npn \@@_save_font_size:nn #1#2
  {
    \use:x
      {
        \prop_gput:Nnn \exp_not:N \c_@@_font_size_prop {#1}
          {
            { \dim_to_decimal:n {#2} }
            { \dim_to_decimal:n { (#2) * 6 / 5 } }
          }
      }
    \seq_gput_right:Nn \c_@@_font_size_seq {#1}
  }
\clist_map_inline:nn
  {
    {  8 } { 5    bp } ,
    {  7 } { 5.5  bp } ,
    { -6 } { 6.5  bp } ,
    {  6 } { 7.5  bp } ,
    { -5 } { 9    bp } ,
    {  5 } { 10.5 bp } ,
    { -4 } { 12   bp } ,
    {  4 } { 14   bp } ,
    { -3 } { 15   bp } ,
    {  3 } { 16   bp } ,
    { -2 } { 18   bp } ,
    {  2 } { 22   bp } ,
    { -1 } { 24   bp } ,
    {  1 } { 26   bp } ,
    { -0 } { 36   bp } ,
    {  0 } { 42   bp }
  }
  { \@@_save_font_size:nn #1 }
%    \end{macrocode}
% \end{macro}
% \end{variable}
%
% \begin{macro}[int]{\ctex_declare_math_sizes:nnnn}
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_declare_math_sizes:nnnn #1#2#3#4
  {
    \@@_get_font_sizes:Nn \l_@@_font_size_tl { {#1} {#2} {#3} {#4} }
    \exp_after:wN \DeclareMathSizes \l_@@_font_size_tl
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_get_font_sizes:Nn}
%    \begin{macrocode}
\cs_new_protected:Npn \@@_get_font_sizes:Nn #1#2
  {
    \tl_clear:N #1
    \tl_map_inline:nn {#2}
      {
        \prop_get:NnNTF \c_@@_font_size_prop {##1} \l_@@_tmp_tl
          { \tl_put_right:Nx #1 { { \tl_head:N \l_@@_tmp_tl } } }
          { \tl_put_right:Nx #1 { { \dim_to_decimal:n { ##1 } } } }
      }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\clist_map_inline:nn
  {
    {  8 }{  8 }{ 5pt }{ 5pt } ,
    {  7 }{  7 }{ 5pt }{ 5pt } ,
    { -6 }{ -6 }{ 5pt }{ 5pt } ,
    {  6 }{  6 }{ 5pt }{ 5pt } ,
    { -5 }{ -5 }{ 6pt }{ 5pt } ,
    {  5 }{  5 }{ 7pt }{ 5pt } ,
    { -4 }{ -4 }{ 8pt }{ 6pt } ,
    {  4 }{  4 }{  5 }{  6 } ,
    { -3 }{ -3 }{ -4 }{ -5 } ,
    {  3 }{  3 }{  4 }{  5 } ,
    { -2 }{ -2 }{ -3 }{ -4 } ,
    {  2 }{  2 }{  3 }{  4 } ,
    { -1 }{ -1 }{ -2 }{ -3 } ,
    {  1 }{  1 }{  2 }{  3 } ,
    { -0 }{ -0 }{ -1 }{ -2 } ,
    {  0 }{  0 }{  1 }{  2 }
  }
  { \ctex_declare_math_sizes:nnnn #1 }
%    \end{macrocode}
%
% \subsubsection{修改默认字号大小}
%
% \begin{macro}[int]{\ctex_set_font_size:Nnn}
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_set_font_size:Nnn #1#2#3
  {
    \prop_get:NnNTF \c_@@_font_size_prop {#2} \l_@@_font_size_tl
      { \exp_after:wN \@@_set_font_size:nnNn \l_@@_font_size_tl #1 {#3} }
      { \msg_error:nnn { ctex } { fontsize } {#2} }
  }
\cs_new_protected:Npn \@@_set_font_size:nnNn #1#2#3#4
  { \cs_set_protected:Npn #3 { \@setfontsize #3 {#1} {#2} #4 } }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\int_case:nn { \g_@@_font_size_int }
  {
    { 0 } { \file_input:n { ctex-c5size.clo } }
    { 1 } { \file_input:n { ctex-cs4size.clo } }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
%</class|ctex|ctexsize>
%    \end{macrocode}
%
%    \begin{macrocode}
%<*c5size>
\ctex_set_font_size:Nnn \normalsize { 5 }
  {
    \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
    \abovedisplayshortskip \z@ \@plus3\p@
    \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
    \belowdisplayskip \abovedisplayskip
    \let\@listi\@listI
  }
\ctex_set_font_size:Nnn \small { -5 }
  {
    \abovedisplayskip 8.5\p@ \@plus3\p@ \@minus4\p@
    \abovedisplayshortskip \z@ \@plus2\p@
    \belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
    \def\@listi{\leftmargin\leftmargini
                \topsep 4\p@ \@plus2\p@ \@minus2\p@
                \parsep 2\p@ \@plus\p@ \@minus\p@
                \itemsep \parsep}
    \belowdisplayskip \abovedisplayskip
  }
\ctex_set_font_size:Nnn \footnotesize { 6 }
  {
    \abovedisplayskip 6\p@ \@plus2\p@ \@minus4\p@
    \abovedisplayshortskip \z@ \@plus\p@
    \belowdisplayshortskip 3\p@ \@plus\p@ \@minus2\p@
    \def\@listi{\leftmargin\leftmargini
                \topsep 3\p@ \@plus\p@ \@minus\p@
                \parsep 2\p@ \@plus\p@ \@minus\p@
                \itemsep \parsep}
    \belowdisplayskip \abovedisplayskip
  }
\ctex_set_font_size:Nnn \scriptsize { -6 } { }
\ctex_set_font_size:Nnn \tiny  {  7 } { }
\ctex_set_font_size:Nnn \large { -4 } { }
\ctex_set_font_size:Nnn \Large { -3 } { }
\ctex_set_font_size:Nnn \LARGE { -2 } { }
\ctex_set_font_size:Nnn \huge  {  2 } { }
\ctex_set_font_size:Nnn \Huge  {  1 } { }
%</c5size>
%<*cs4size>
\ctex_set_font_size:Nnn \normalsize { -4 }
  {
    \abovedisplayskip 12\p@ \@plus3\p@ \@minus7\p@
    \abovedisplayshortskip \z@ \@plus3\p@
    \belowdisplayshortskip 6.5\p@ \@plus3.5\p@ \@minus3\p@
    \belowdisplayskip \abovedisplayskip
    \let\@listi\@listI
  }
\ctex_set_font_size:Nnn \small { 5 }
  {
    \abovedisplayskip 11\p@ \@plus3\p@ \@minus6\p@
    \abovedisplayshortskip \z@ \@plus3\p@
    \belowdisplayshortskip 6.5\p@ \@plus3.5\p@ \@minus3\p@
    \def\@listi{\leftmargin\leftmargini
                \topsep 9\p@ \@plus3\p@ \@minus5\p@
                \parsep 4.5\p@ \@plus2\p@ \@minus\p@
                \itemsep \parsep}
    \belowdisplayskip \abovedisplayskip
  }
\ctex_set_font_size:Nnn \footnotesize { -5 }
  {
    \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
    \abovedisplayshortskip \z@ \@plus3\p@
    \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
    \def\@listi{\leftmargin\leftmargini
                \topsep 6\p@ \@plus2\p@ \@minus2\p@
                \parsep 3\p@ \@plus2\p@ \@minus\p@
                \itemsep \parsep}
    \belowdisplayskip \abovedisplayskip
  }
\ctex_set_font_size:Nnn \scriptsize { 6 } { }
\ctex_set_font_size:Nnn \tiny  { -6 } { }
\ctex_set_font_size:Nnn \large { -3 } { }
\ctex_set_font_size:Nnn \Large { -2 } { }
\ctex_set_font_size:Nnn \LARGE {  2 } { }
\ctex_set_font_size:Nnn \huge  { -1 } { }
\ctex_set_font_size:Nnn \Huge  {  1 } { }
%</cs4size>
%    \end{macrocode}
%
%    \begin{macrocode}
%<ctexsize>\normalsize
%    \end{macrocode}
%
%    \begin{macrocode}
%<*class|ctex>
%    \end{macrocode}
%
% \subsection{更新行距}
%
% \cs{l_@@_line_spread_fp} 被设置了才有必要更新行距和 \tn{footnotesep}。
%    \begin{macrocode}
\fp_if_nan:nF { \l_@@_line_spread_fp }
  {
    \exp_args:Nx \linespread { \fp_use:N \l_@@_line_spread_fp }
%    \end{macrocode}
%
% \changes{v2.0}{2014/04/23}{调整 \tn{footnotesep} 的大小,以适合行距的变化。}
%
% \begin{variable}[int]{\footnotesep}
% 我们调整了行距,可能导致脚注的间距与行距不协调,需要调整 \tn{footnotesep}。标准
% 文档类对 \tn{footnotesep} 的设置是,字体大小为 \tn{footnotesize} 时 \tn{strutbox}
% 的高度(默认值是 |.7\baselineskip|)。我们沿用这个设置方法,只需要更新具体的大小。
%    \begin{macrocode}
    \group_begin: \footnotesize \exp_args:NNNo \group_end:
    \dim_set:Nn \footnotesep { \dim_use:N \box_ht:N \strutbox }
  }
%    \end{macrocode}
% \end{variable}
%
% 激活默认字体大小,更新行距、\tn{parindent} 和 \tn{CJKglue}。
%    \begin{macrocode}
\normalsize
%    \end{macrocode}
%
% \subsection{其他功能}
%
% \begin{macro}{\CTeX}
% \changes{v2.4.12}{2017/12/05}{不依赖 \tn{ifincsname}。}
% \file{ctex-faq.sty} 中的定义是
% \begin{verbatim}
%   \DeclareRobustCommand\CTeX{$\mathbb{C}$\kern-.05em\TeX}
% \end{verbatim}
% 然而 \tn{mathbb} 未必有定义,这里就不采用它了,只定义最简单的形式。
% \CTeX{} 可以直接用在 PDF 书签中。
%    \begin{macrocode}
\NewDocumentCommand \CTeX { }
  { C \TeX }
\ctex_at_end_package:nn { hyperref }
  { \pdfstringdefDisableCommands { \tl_set:Nn \CTeX { CTeX } } }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0}{2014/03/28}{\opt{captiondelimiter} 是过时选项。}
% \begin{macro}{captiondelimiter}
% 过时选项。
%    \begin{macrocode}
\ctex_define:n
  {
    captiondelimiter .code:n =
      {
        \ctex_deprecated_option:n
          { You~can~load~the~package~`caption'~to~get~its~functionality. }
      }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</class|ctex>
%    \end{macrocode}
%
% \subsubsection{列表环境的缩进}
%
% \begin{macro}[int]{\verse,\quotation}
% 只在使用文档类的时候修改诗歌和引用环境的缩进。
%    \begin{macrocode}
%<*scheme&chinese&(article|book|report)>
\ctex_patch_cmd:Nnn \verse { -1.5em } { -2 \ccwd }
\ctex_patch_cmd:Nnn \verse {  1.5em } {  2 \ccwd }
\ctex_patch_cmd:Nnn \quotation { 1.5em } { 2 \ccwd }
%</scheme&chinese&(article|book|report)>
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%<*class|ctex>
%    \end{macrocode}
%
% \changes{v2.0}{2014/03/09}
% {解决 \pkg{etoolbox} 与 \pkg{breqn} 关于 \tn{end} 的冲突。}
% \changes{v2.2}{2015/06/23}{删去 \pkg{etoolbox} 与 \pkg{breqn} 的兼容补丁。}
%
% \subsection{载入中文字库}
%
% \begin{macro}[int]{\ctex_fontset_error:n}
% 字库不可用时给出紧急错误信息,停止读取定义文件。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_fontset_error:n #1
  { \msg_critical:nnn { ctex } { fontset-unavailable } {#1} }
\msg_new:nnn { ctex } { fontset-unavailable }
  { CTeX~fontset~`#1'~is~unavailable~in~current~mode. }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_fontset_case:nnn}
% $3$ 个参数依次为 \pdfTeX、\upTeX\ 和 \XeTeX/\LuaTeX。
%    \begin{macrocode}
\cs_new:Npx \ctex_fontset_case:nnn #1#2#3
  {
    \sys_if_engine_pdftex:TF
      {#1}
      { \sys_if_engine_uptex:TF {#2} {#3} }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_fontset_case:nnnn}
% $4$ 个参数依次为 \pdfTeX(生成 PDF)、\pdfTeX(生成 DVI)、\upTeX 和
% \XeTeX/\LuaTeX。
%    \begin{macrocode}
\cs_new:Npx \ctex_fontset_case:nnnn #1#2#3#4
  {
    \sys_if_engine_pdftex:TF
      { \sys_if_output_pdf:TF   {#1} {#2} }
      { \sys_if_engine_uptex:TF {#3} {#4} }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_detect_platform:}
% 根据操作系统判断默认字体配置。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_detect_platform:
  {
    \sys_if_platform_windows:TF
      { \tl_gset:Nn \g_@@_fontset_tl { windows } }
      {
        \ctex_if_platform_macos:TF
          { \tl_gset:Nn \g_@@_fontset_tl { mac    } }
          { \tl_gset:Nn \g_@@_fontset_tl { fandol } }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_if_platform_macos:TF}
% \changes{v2.1}{2015/06/17}{改用 \file{/Library/Fonts/Songti.ttc} 为特征文件。}
% \changes{v2.5}{2019/10/25}{改用 \file{/System/Library/Fonts/Menlo.ttc}
%   为特征文件。}
% 以特定字体判断 macOS 系统。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_if_platform_macos:TF
  { \file_if_exist:nTF { /System/Library/Fonts/Menlo.ttc } }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_load_fontset:}
% 如果用户没有指定字体,则探测操作系统,载入相应的字体配置。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_load_fontset:
  {
    \tl_if_empty:NTF \g_@@_fontset_tl
      { \ctex_detect_platform: }
      {
        \bool_lazy_or:nnTF
          { \str_if_eq_p:on { \g_@@_fontset_tl } { windowsnew } }
          { \str_if_eq_p:on { \g_@@_fontset_tl } { windowsold } }
          {
            \msg_warning:nnxx { ctex } { deprecated-fontset }
              { \g_@@_fontset_tl } { windows }
            \tl_gset:Nn \g_@@_fontset_tl { windows }
          }
          {
            \file_if_exist:nF { ctex-fontset- \g_@@_fontset_tl .def }
              {
                \use:x
                  {
                    \ctex_detect_platform:
                    \msg_error:nnxx { ctex } { fontset-not-found }
                      { \g_@@_fontset_tl } { \exp_not:N \g_@@_fontset_tl }
                  }
              }
          }
      }
    \ctex_file_input:n { ctex-fontset- \g_@@_fontset_tl .def }
  }
\msg_new:nnn { ctex } { deprecated-fontset }
  { CTeX~fontset~`#1'~is~deprecated.\\ Fontset~`#2'~will~be~used~instead. }
\msg_new:nnnn { ctex } { fontset-not-found }
  { CTeX~fontset~`#1'~could~not~be~found.\\ Fontset~`#2'~will~be~used~instead. }
  { You~may~run~`mktexlsr'~firstly. }
\@onlypreamble \ctex_load_fontset:
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{fontset}
% 在导言区通过 \tn{ctexset} 载入中文字库的选项。
%    \begin{macrocode}
\ctex_define:n
  {
    fontset .code:n =
      {
        \ctex_if_preamble:TF
          {
            \str_if_eq:eeTF {#1} { none }
              { \msg_warning:nnn { ctex } { invalid-value } {#1} }
              {
                \str_if_eq:onTF { \g_@@_fontset_tl } { none }
                  {
                    \tl_gset:Nx \g_@@_fontset_tl {#1}
                    \ctex_load_fontset:
                  }
                  {
                    \msg_error:nnxx { ctex } { fontset-loaded }
                      { \g_@@_fontset_tl } {#1}
                  }
              }
          }
          { \msg_error:nn { ctex } { fontset-only-preamble } }
      }
  }
\msg_new:nnnn { ctex } { fontset-loaded }
  {
    CTeX~fontset~`#1'~has~been~loaded.
    \str_if_eq:nnF {#1} {#2} { \\ Fontset~`#2'~will~be~ignored. }
  }
  { Only~one~fontset~can~be~loaded~in~the~preamble. }
\msg_new:nnn { ctex } { fontset-only-preamble }
  { The~`fontset'~option~can~be~used~only~in~preamble. }
%    \end{macrocode}
% \end{macro}
%
% 载入中文字库。
%    \begin{macrocode}
\str_if_eq:onF { \g_@@_fontset_tl } { none }
  { \ctex_load_fontset: }
%    \end{macrocode}
%
% \subsection{宏包配置文件}
%
% \subsubsection{\pkg{ctex.cfg}}
%
%    \begin{macrocode}
\ctex_at_end:n { \ctex_file_input:n { ctex.cfg } }
%    \end{macrocode}
%
%    \begin{macrocode}
%</class|ctex>
%    \end{macrocode}
%
%    \begin{macrocode}
%<*config>
%%
%</config>
%    \end{macrocode}
%
% \subsubsection{\pkg{ctexopts.cfg}}
%
% 这里仅为配置文件示例:使用 Windows 下的字体设置。
%    \begin{macrocode}
%<*ctexopts>
%%
%% \ctex_set:nn { option } { fontset = windows }
%</ctexopts>
%    \end{macrocode}
%
% \subsection{字体定义文件}
%
% \subsubsection{传统定义方式}
%
% \changes{v2.4.15}{2019/04/05}{将 \texttt{JY2} 和 \texttt{JT2} 编码的字体定义提取到单独的文件中。}
%
%    \begin{macrocode}
%<*c19|c70>
%%
%% Chinese characters
%%
%<c19>%% character set: GBK (extension of GB 2312)
%<c70>%% character set: Unicode
%% font encoding: Unicode
%%
%</c19|c70>
%    \end{macrocode}
%
% \pkg{CJK} 宏包使用的字体族。
%    \begin{macrocode}
%<rm&c19>\DeclareFontFamily{C19}{rm}{\hyphenchar\font\m@ne}
%<rm&c70>\DeclareFontFamily{C70}{rm}{\hyphenchar\font\m@ne}
%<sf&c19>\DeclareFontFamily{C19}{sf}{\hyphenchar\font\m@ne}
%<sf&c70>\DeclareFontFamily{C70}{sf}{\hyphenchar\font\m@ne}
%<tt&c19>\DeclareFontFamily{C19}{tt}{\hyphenchar\font\m@ne}
%<tt&c70>\DeclareFontFamily{C70}{tt}{\hyphenchar\font\m@ne}
%    \end{macrocode}
%
% \changes{v2.4}{2016/04/25}{提供 \upLaTeX{} 的 NFSS 字体定义。}
% \upLaTeX{} 使用的字体族。\upLaTeX 在 NFSS 下使用字体编码 |JY2| 和 |JT2| 来分别
% 表示横排与直排的日文。
%    \begin{macrocode}
%<rm&jy2>\DeclareKanjiFamily{JY2}{zhrm}{}
%<rm&jt2>\DeclareKanjiFamily{JT2}{zhrm}{}
%<sf&jy2>\DeclareKanjiFamily{JY2}{zhsf}{}
%<sf&jt2>\DeclareKanjiFamily{JT2}{zhsf}{}
%<tt&jy2>\DeclareKanjiFamily{JY2}{zhtt}{}
%<tt&jt2>\DeclareKanjiFamily{JT2}{zhtt}{}
%    \end{macrocode}
%
%
%    \begin{macrocode}
%<*rm>
%<*c19>
\DeclareFontShape{C19}{rm}{m}{n}{<-> CJK * gbksong}{\CJKnormal}
\DeclareFontShape{C19}{rm}{b}{n}{<-> CJK * gbkhei}{\CJKnormal}
\DeclareFontShape{C19}{rm}{bx}{n}{<-> CJK * gbkhei}{\CJKnormal}
\DeclareFontShape{C19}{rm}{m}{sl}{<-> CJK * gbksongsl}{\CJKnormal}
\DeclareFontShape{C19}{rm}{b}{sl}{<-> CJK * gbkheisl}{\CJKnormal}
\DeclareFontShape{C19}{rm}{bx}{sl}{<-> CJK * gbkheisl}{\CJKnormal}
\DeclareFontShape{C19}{rm}{m}{it}{<-> CJK * gbkkai}{\CJKnormal}
\DeclareFontShape{C19}{rm}{b}{it}{<-> CJKb * gbkkai}{\CJKbold}
\DeclareFontShape{C19}{rm}{bx}{it}{<-> CJKb * gbkkai}{\CJKbold}
%</c19>
%<*c70>
\DeclareFontShape{C70}{rm}{m}{n}{<-> CJK * unisong}{\CJKnormal}
\DeclareFontShape{C70}{rm}{b}{n}{<-> CJK * unihei}{\CJKnormal}
\DeclareFontShape{C70}{rm}{bx}{n}{<-> CJK * unihei}{\CJKnormal}
\DeclareFontShape{C70}{rm}{m}{sl}{<-> CJK * unisongsl}{\CJKnormal}
\DeclareFontShape{C70}{rm}{b}{sl}{<-> CJK * uniheisl}{\CJKnormal}
\DeclareFontShape{C70}{rm}{bx}{sl}{<-> CJK * uniheisl}{\CJKnormal}
\DeclareFontShape{C70}{rm}{m}{it}{<-> CJK * unikai}{\CJKnormal}
\DeclareFontShape{C70}{rm}{b}{it}{<-> CJKb * unikai}{\CJKbold}
\DeclareFontShape{C70}{rm}{bx}{it}{<-> CJKb * unikai}{\CJKbold}
%</c70>
%<*jy2>
\DeclareFontShape{JY2}{zhrm}{m}{n}{<-> upzhserif-h}{}
\DeclareFontShape{JY2}{zhrm}{m}{it}{<-> upzhserifit-h}{}
\DeclareFontShape{JY2}{zhrm}{b}{n}{<-> upzhserifb-h}{}
\DeclareFontShape{JY2}{zhrm}{bx}{n}{<-> upzhserifb-h}{}
%</jy2>
%<*jt2>
\DeclareFontShape{JT2}{zhrm}{m}{n}{<-> upzhserif-v}{}
\DeclareFontShape{JT2}{zhrm}{m}{it}{<-> upzhserifit-v}{}
\DeclareFontShape{JT2}{zhrm}{b}{n}{<-> upzhserifb-v}{}
\DeclareFontShape{JT2}{zhrm}{bx}{n}{<-> upzhserifb-v}{}
%</jt2>
%</rm>
%    \end{macrocode}
%
%    \begin{macrocode}
%<*sf>
%<*c19>
\DeclareFontShape{C19}{sf}{m}{n}{<-> CJK * gbkyou}{\CJKnormal}
\DeclareFontShape{C19}{sf}{b}{n}{<-> CJKb * gbkyou}{\CJKbold}
\DeclareFontShape{C19}{sf}{bx}{n}{<-> CJKb * gbkyou}{\CJKbold}
\DeclareFontShape{C19}{sf}{m}{sl}{<-> CJK * gbkyousl}{\CJKnormal}
\DeclareFontShape{C19}{sf}{b}{sl}{<-> CJKb * gbkyousl}{\CJKbold}
\DeclareFontShape{C19}{sf}{bx}{sl}{<-> CJKb * gbkyousl}{\CJKbold}
\DeclareFontShape{C19}{sf}{m}{it}{<-> CJK * gbkyou}{\CJKnormal}
\DeclareFontShape{C19}{sf}{b}{it}{<-> CJKb * gbkyou}{\CJKbold}
\DeclareFontShape{C19}{sf}{bx}{it}{<-> CJKb * gbkyou}{\CJKbold}
%</c19>
%<*c70>
\DeclareFontShape{C70}{sf}{m}{n}{<-> CJK * uniyou}{\CJKnormal}
\DeclareFontShape{C70}{sf}{b}{n}{<-> CJKb * uniyou}{\CJKbold}
\DeclareFontShape{C70}{sf}{bx}{n}{<-> CJKb * uniyou}{\CJKbold}
\DeclareFontShape{C70}{sf}{m}{sl}{<-> CJK * uniyousl}{\CJKnormal}
\DeclareFontShape{C70}{sf}{b}{sl}{<-> CJKb * uniyousl}{\CJKbold}
\DeclareFontShape{C70}{sf}{bx}{sl}{<-> CJKb * uniyousl}{\CJKbold}
\DeclareFontShape{C70}{sf}{m}{it}{<-> CJK * uniyou}{\CJKnormal}
\DeclareFontShape{C70}{sf}{b}{it}{<-> CJKb * uniyou}{\CJKbold}
\DeclareFontShape{C70}{sf}{bx}{it}{<-> CJKb * uniyou}{\CJKbold}
%</c70>
%<*jy2>
\DeclareFontShape{JY2}{zhsf}{m}{n}{<-> upzhsans-h}{}
\DeclareFontShape{JY2}{zhsf}{b}{n}{<-> upzhsansb-h}{}
\DeclareFontShape{JY2}{zhsf}{bx}{n}{<-> upzhsansb-h}{}
%</jy2>
%<*jt2>
\DeclareFontShape{JT2}{zhsf}{m}{n}{<-> upzhsans-v}{}
\DeclareFontShape{JT2}{zhsf}{b}{n}{<-> upzhsansb-v}{}
\DeclareFontShape{JT2}{zhsf}{bx}{n}{<-> upzhsansb-v}{}
%</jt2>
%</sf>
%    \end{macrocode}
%
%    \begin{macrocode}
%<*tt>
%<*c19>
\DeclareFontShape{C19}{tt}{m}{n}{<-> CJK * gbkfs}{\CJKnormal}
\DeclareFontShape{C19}{tt}{b}{n}{<-> CJKb * gbkfs}{\CJKbold}
\DeclareFontShape{C19}{tt}{bx}{n}{<-> CJKb * gbkfs}{\CJKbold}
\DeclareFontShape{C19}{tt}{m}{sl}{<-> CJK * gbkfssl}{\CJKnormal}
\DeclareFontShape{C19}{tt}{b}{sl}{<-> CJKb * gbkfssl}{\CJKbold}
\DeclareFontShape{C19}{tt}{bx}{sl}{<-> CJKb * gbkfssl}{\CJKbold}
\DeclareFontShape{C19}{tt}{m}{it}{<-> CJK * gbkfs}{\CJKnormal}
\DeclareFontShape{C19}{tt}{b}{it}{<-> CJKb * gbkfs}{\CJKbold}
\DeclareFontShape{C19}{tt}{bx}{it}{<-> CJKb * gbkfs}{\CJKbold}
%</c19>
%<*c70>
\DeclareFontShape{C70}{tt}{m}{n}{<-> CJK * unifs}{\CJKnormal}
\DeclareFontShape{C70}{tt}{b}{n}{<-> CJKb * unifs}{\CJKbold}
\DeclareFontShape{C70}{tt}{bx}{n}{<-> CJKb * unifs}{\CJKbold}
\DeclareFontShape{C70}{tt}{m}{sl}{<-> CJK * unifssl}{\CJKnormal}
\DeclareFontShape{C70}{tt}{b}{sl}{<-> CJKb * unifssl}{\CJKbold}
\DeclareFontShape{C70}{tt}{bx}{sl}{<-> CJKb * unifssl}{\CJKbold}
\DeclareFontShape{C70}{tt}{m}{it}{<-> CJK * unifs}{\CJKnormal}
\DeclareFontShape{C70}{tt}{b}{it}{<-> CJKb * unifs}{\CJKbold}
\DeclareFontShape{C70}{tt}{bx}{it}{<-> CJKb * unifs}{\CJKbold}
%</c70>
%<*jy2>
\DeclareFontShape{JY2}{zhtt}{m}{n}{<-> upzhmono-h}{}
%</jy2>
%<*jt2>
\DeclareFontShape{JT2}{zhtt}{m}{n}{<-> upzhmono-v}{}
%</jt2>
%</tt>
%    \end{macrocode}
%
% \subsubsection{预定义字库}
%
%    \begin{macrocode}
%<*fontset>
%    \end{macrocode}
%
% \paragraph{\opt{adobe}}
%
% \tn{pdfmapline} 不支持 OpenType 字体,因而 \opt{adobe} 字体集在 pdf 模式下
% 就没有定义。\opt{fandol} 的情况类似。
%    \begin{macrocode}
%<*adobe>
\ctex_fontset_case:nnnn
  { \ctex_fontset_error:n { adobe } }
  {
    \ctex_zhmap_case:nnn
      {
        \setCJKmainfont  { AdobeSongStd-Light.otf }
          [
            cmap       = UniGB-UTF16-H,
            BoldFont   = AdobeHeitiStd-Regular.otf,
            ItalicFont = AdobeKaitiStd-Regular.otf
          ]
        \setCJKsansfont { AdobeHeitiStd-Regular.otf }
          [ cmap = UniGB-UTF16-H ]
        \setCJKmonofont { AdobeFangsongStd-Regular.otf }
          [ cmap = UniGB-UTF16-H ]
        \setCJKfamilyfont { zhsong } { AdobeSongStd-Light.otf       }
          [ cmap = UniGB-UTF16-H ]
        \setCJKfamilyfont { zhhei  } { AdobeHeitiStd-Regular.otf    }
          [ cmap = UniGB-UTF16-H ]
        \setCJKfamilyfont { zhkai  } { AdobeKaitiStd-Regular.otf    }
          [ cmap = UniGB-UTF16-H ]
        \setCJKfamilyfont { zhfs   } { AdobeFangsongStd-Regular.otf }
          [ cmap = UniGB-UTF16-H ]
        \ctex_punct_set:n { adobe }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_family:nn   { \CJKsfdefault } { zhhei  }
        \ctex_punct_map_family:nn   { \CJKttdefault } { zhfs   }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
      {
        \ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { adobe }
        \ctex_punct_set:n { adobe }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
      { \ctex_fontset_error:n { adobe } }
  }
  {
    \ctex_set_upfonts:nnnnnn
      { AdobeSongStd-Light.otf       }
      { AdobeHeitiStd-Regular.otf    }
      { AdobeKaitiStd-Regular.otf    }
      { AdobeHeitiStd-Regular.otf    }
      { AdobeHeitiStd-Regular.otf    }
      { AdobeFangsongStd-Regular.otf }
    \ctex_set_upfamily:nnn { zhsong } { upzhserif   } {}
    \ctex_set_upfamily:nnn { zhhei  } { upzhsans    } {}
    \ctex_set_upfamily:nnn { zhfs   } { upzhmono    } {}
    \ctex_set_upfamily:nnn { zhkai  } { upzhserifit } {}
  }
  {
    \setCJKmainfont { AdobeSongStd-Light       }
      [ BoldFont = AdobeHeitiStd-Regular, ItalicFont = AdobeKaitiStd-Regular ]
    \setCJKsansfont { AdobeHeitiStd-Regular    }
    \setCJKmonofont { AdobeFangsongStd-Regular }
    \setCJKfamilyfont { zhsong } { AdobeSongStd-Light       }
    \setCJKfamilyfont { zhhei  } { AdobeHeitiStd-Regular    }
    \setCJKfamilyfont { zhfs   } { AdobeFangsongStd-Regular }
    \setCJKfamilyfont { zhkai  } { AdobeKaitiStd-Regular    }
  }
%</adobe>
%    \end{macrocode}
%
% \paragraph{\opt{fandol}}
%
%    \begin{macrocode}
%<*fandol>
\ctex_fontset_case:nnnn
  { \ctex_fontset_error:n { fandol } }
  {
    \ctex_zhmap_case:nnn
      {
        \setCJKmainfont { FandolSong-Regular.otf }
          [
            cmap       = UniGB-UTF16-H,
            BoldFont   = FandolSong-Bold.otf,
            ItalicFont = FandolKai-Regular.otf
          ]
        \setCJKsansfont { FandolHei-Regular.otf }
          [ cmap = UniGB-UTF16-H, BoldFont = FandolHei-Bold.otf ]
        \setCJKmonofont { FandolFang-Regular.otf }
          [ cmap = UniGB-UTF16-H ]
        \setCJKfamilyfont { zhsong } { FandolSong-Regular.otf }
          [ cmap = UniGB-UTF16-H, BoldFont = FandolSong-Bold.otf ]
        \setCJKfamilyfont { zhhei  } { FandolHei-Regular.otf  }
          [ cmap = UniGB-UTF16-H, BoldFont = FandolHei-Bold.otf  ]
        \setCJKfamilyfont { zhfs   } { FandolFang-Regular.otf }
          [ cmap = UniGB-UTF16-H ]
        \setCJKfamilyfont { zhkai  } { FandolKai-Regular.otf  }
          [ cmap = UniGB-UTF16-H ]
        \ctex_punct_set:n { fandol }
        \ctex_punct_map_family:nn   { \CJKrmdefault         } { zhsong  }
        \ctex_punct_map_family:nn   { \CJKsfdefault         } { zhhei   }
        \ctex_punct_map_family:nn   { \CJKttdefault         } { zhfs    }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault, zhsong } { zhsongb }
        \ctex_punct_map_bfseries:nn { \CJKsfdefault, zhhei  } { zhheib  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault         } { zhkai   }
      }
      {
        \ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { fandol }
        \ctex_punct_set:n { fandol }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
      { \ctex_fontset_error:n { fandol } }
  }
  {
    \ctex_set_upfonts:nnnnnn
      { FandolSong-Regular.otf }
      { FandolSong-Bold.otf    }
      { FandolKai-Regular.otf  }
      { FandolHei-Regular.otf  }
      { FandolHei-Bold.otf     }
      { FandolFang-Regular.otf }
    \ctex_set_upfamily:nnn { zhsong } { upzhserif   } { upzhserifb }
    \ctex_set_upfamily:nnn { zhhei  } { upzhsans    } { upzhsansb  }
    \ctex_set_upfamily:nnn { zhfs   } { upzhmono    } {}
    \ctex_set_upfamily:nnn { zhkai  } { upzhserifit } {}
  }
  {
    \setCJKmainfont { FandolSong-Regular }
      [
        Extension  = .otf,
        BoldFont   = FandolSong-Bold,
        ItalicFont = FandolKai-Regular
      ]
    \setCJKsansfont { FandolHei-Regular  }
      [ Extension = .otf, BoldFont = FandolHei-Bold ]
    \setCJKmonofont { FandolFang-Regular }
      [ Extension = .otf ]
    \setCJKfamilyfont { zhsong } { FandolSong-Regular }
      [ Extension = .otf, BoldFont = FandolSong-Bold ]
    \setCJKfamilyfont { zhhei  } { FandolHei-Regular  }
      [ Extension = .otf, BoldFont = FandolHei-Bold  ]
    \setCJKfamilyfont { zhfs   } { FandolFang-Regular }
      [ Extension = .otf ]
    \setCJKfamilyfont { zhkai  } { FandolKai-Regular  }
      [ Extension = .otf ]
  }
%</fandol>
%    \end{macrocode}
%
% \paragraph{\opt{founder}}
%
% \changes{v2.4.15}{2019/03/28}{统一“方正细黑一\_GBK”的名称为 \texttt{FZXiHeiI-Z08}。}
%
%    \begin{macrocode}
%<*founder>
\ctex_fontset_case:nnn
  {
    \ctex_zhmap_case:nnn
      {
        \setCJKmainfont { FZSSK.TTF }
          [ BoldFont = FZXBSK.TTF, ItalicFont = FZKTK.TTF ]
        \setCJKsansfont { FZXH1K.TTF } [ BoldFont = FZHTK.TTF ]
        \setCJKmonofont { FZFSK.TTF }
        \setCJKfamilyfont { zhsong } { FZSSK.TTF } [ BoldFont = FZXBSK.TTF ]
        \setCJKfamilyfont { zhhei  } { FZHTK.TTF }
        \setCJKfamilyfont { zhkai  } { FZKTK.TTF }
        \setCJKfamilyfont { zhfs   } { FZFSK.TTF }
        \setCJKfamilyfont { zhli   } { FZLSK.TTF }
        \setCJKfamilyfont { zhyou  } { FZY1K.TTF } [ BoldFont = FZY3K.TTF ]
        \ctex_punct_set:n { founder }
        \ctex_punct_map_family:nn   { \CJKrmdefault         } { zhsong  }
        \ctex_punct_map_family:nn   { \CJKsfdefault         } { zhheil  }
        \ctex_punct_map_family:nn   { \CJKttdefault         } { zhfs    }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault         } { zhkai   }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault, zhsong } { zhsongb }
        \ctex_punct_map_bfseries:nn { \CJKsfdefault         } { zhhei   }
        \ctex_punct_map_bfseries:nn { zhyou                 } { zhyoub  }
      }
      {
        \ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { founder }
        \ctex_punct_set:n { founder }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
      { \ctex_fontset_error:n { founder } }
  }
  {
    \ctex_set_upfonts:nnnnnn
      { FZSSK.TTF  }
      { FZXBSK.TTF }
      { FZKTK.TTF  }
      { FZXH1K.TTF }
      { FZHTK.TTF  }
      { FZFSK.TTF  }
    \ctex_set_upfamily:nnn { zhsong } { upzhserif   } { upzhserifb }
    \ctex_set_upfamily:nnn { zhhei  } { upzhsans    } { upzhsansb  }
    \ctex_set_upfamily:nnn { zhfs   } { upzhmono    } {}
    \ctex_set_upfamily:nnn { zhkai  } { upzhserifit } {}
    \ctex_set_upfamily:nnn { zhli   } { upschrm     } {}
    \ctex_set_upfamily:nnn { zhyou  } { upschgt     } {}
    \ctex_set_upmap:nnn    { upstsl } { FZLSK.TTF } {}
    \ctex_set_upmap:nnn    { upstht } { FZY1K.TTF } {}
  }
  {
    \setCJKmainfont { FZShuSong-Z01 }
      [ BoldFont = FZXiaoBiaoSong-B05, ItalicFont = FZKai-Z03 ]
    \setCJKsansfont { FZXiHeiI-Z08 } [ BoldFont = FZHei-B01 ]
    \setCJKmonofont { FZFangSong-Z02 }
    \setCJKfamilyfont { zhsong } { FZShuSong-Z01  }
      [ BoldFont = FZXiaoBiaoSong-B05 ]
    \setCJKfamilyfont { zhhei  } { FZHei-B01      }
    \setCJKfamilyfont { zhkai  } { FZKai-Z03      }
    \setCJKfamilyfont { zhfs   } { FZFangSong-Z02 }
    \setCJKfamilyfont { zhli   } { FZLiShu-S01    }
    \setCJKfamilyfont { zhyou  } { FZXiYuan-M01   }
      [ BoldFont = FZZhunYuan-M02 ]
  }
%</founder>
%    \end{macrocode}
%
% \changes{v2.5.2}{2020/05/06}
%   {修正 \opt{macnew} 和 \opt{ubuntu} 字库的 \pkg{CJKpunct} 标点信息。}
%
% \paragraph{\opt{mac} 相关}
%
% \changes{v2.4.14}{2018/05/01}{区分 \opt{macold} 及 \opt{macnew}。}
%
% 按 \href{https://github.com/CTeX-org/ctex-kit/issues/351}{Issue 351}
% 的讨论,以 El Capitan 为分界,分别设置 |macold|(El Capitan 之前)
% 和 |macnew|(El Capitan 及之后)。检测方式则以 El Capitan 及之后
% 的苹方字体为准。
%
%    \begin{macrocode}
%<*mac>
\file_if_exist:nTF { /System/Library/Fonts/PingFang.ttc }
  { \ctex_file_input:n { ctex-fontset-macnew.def } }
  { \ctex_file_input:n { ctex-fontset-macold.def } }
%</mac>
%    \end{macrocode}
%
% \changes{v2.4.14}{2018/05/01}{配置 \opt{macnew} 的默认字体设置。}
% \changes{v2.5}{2019/11/05}{为 \opt{macnew} 增加粗楷体、隶书和圆体的定义。}
% \changes{v2.5}{2019/11/07}{允许 \opt{macnew} 在 \LaTeX{} 和 \upLaTeX{} 下使用。}
%
% |macold| 的设置参考了
% \href{https://github.com/CTeX-org/ctex-kit/wiki/OS-X-Mavericks-(10.9)-预装的主要简体中文字体}^^A
% {OS X Mavericks (10.9) 预装的主要简体中文字体列表}。
%
% |macnew| 在默认字体设置方面,引入了多字重的宋体作为罗马字族,
% 以及引入了苹方黑体作为无衬线字族。
% 由于 Songti SC Light 的字重与 STSong 及 Windows 上的 SimSun 更接近,故默认字重
% 使用 Songti SC Light,而不带后缀的正常字重事实上没有使用。黑体、圆体等设置
% 也有类似的情况。
%
%    \begin{macrocode}
%<*macold|macnew>
\ctex_fontset_case:nnnn
  { \ctex_fontset_error:n { mac } }
%<*macold>
  { \ctex_fontset_error:n { macold } }
  { \ctex_fontset_error:n { macold } }
%</macold>
%<*macnew>
  {
    \ctex_zhmap_case:nnn
      {
        \setCJKmainfont { :3:Songti.ttc }
          [
            BoldFont       = :1:Songti.ttc,
            ItalicFont     = :0:Kaiti.ttc,
            BoldItalicFont = :3:Kaiti.ttc,
          ]
        \setCJKsansfont { :2:PingFang.ttc } [ BoldFont = :8:PingFang.ttc ]
        \setCJKmonofont { STFANGSO.ttf    }
        \setCJKfamilyfont { zhsong } { :3:Songti.ttc   } [ BoldFont = :1:Songti.ttc   ]
        \setCJKfamilyfont { zhhei  } { :2:PingFang.ttc } [ BoldFont = :8:PingFang.ttc ]
        \setCJKfamilyfont { zhkai  } { :0:Kaiti.ttc    } [ BoldFont = :3:Kaiti.ttc    ]
        \setCJKfamilyfont { zhfs   } { STFANGSO.ttf    }
        \setCJKfamilyfont { zhli   } { :0:Baoli.ttc    }
        \setCJKfamilyfont { zhyou  } { :4:Yuanti.ttc   } [ BoldFont = :0:Yuanti.ttc   ]
        \ctex_punct_set:n { mac }
        \ctex_punct_map_family:nn   { \CJKrmdefault         } { zhsong  }
        \ctex_punct_map_family:nn   { \CJKsfdefault         } { zhpf    }
        \ctex_punct_map_family:nn   { \CJKttdefault         } { zhfs    }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault         } { zhkai   }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault, zhsong } { zhsongb }
        \ctex_punct_map_bfseries:nn { \CJKsfdefault, zhhei  } { zhpfb   }
        \ctex_punct_map_bfseries:nn { zhyou                 } { zhyoub  }
      }
      {
        \ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { mac }
        \ctex_punct_set:n { mac }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_family:nn   { \CJKsfdefault } { zhpf   }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhpf   }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
      { \ctex_fontset_error:n { macnew } }
  }
  {
    \ctex_set_upmap:nnn { upserif   } { :3:Songti.ttc } { :1:Songti.ttc }
    \ctex_set_upmap:nnn { upserifit } { :0:Kaiti.ttc  } { }
    \ctex_set_upmap:nnn { upstsl    } { :0:Baoli.ttc  } { }
    \ctex_set_upmap:nnn { upstht    } { :4:Yuanti.ttc } { }
    \ctex_set_upmap_unicode:nnn { upsans } { :2:PingFang.ttc } { :8:PingFang.ttc }
    \ctex_set_upmap_unicode:nnn { upmono } { STFANGSO.ttf    } { }
    \ctex_set_upfamily:nnn { zhsong } { upzhserif   } { upzhserifb }
    \ctex_set_upfamily:nnn { zhhei  } { upzhsans    } { upzhsansb  }
    \ctex_set_upfamily:nnn { zhfs   } { upzhmono    } { }
    \ctex_set_upfamily:nnn { zhkai  } { upzhserifit } { }
    \ctex_set_upfamily:nnn { zhli   } { upschrm     } { }
    \ctex_set_upfamily:nnn { zhyou  } { upschgt     } { }
  }
%</macnew>
  {
%<*macold>
    \setCJKmainfont { STSong     }
      [ BoldFont = STHeiti, ItalicFont = STKaiti ]
    \setCJKsansfont { STXihei    } [ BoldFont = STHeiti ]
    \setCJKmonofont { STFangsong }
    \setCJKfamilyfont { zhsong } { STSong     }
    \setCJKfamilyfont { zhhei  } { STHeiti    }
    \setCJKfamilyfont { zhfs   } { STFangsong }
    \setCJKfamilyfont { zhkai  } { STKaiti    }
%</macold>
%<*macnew>
    \setCJKmainfont { Songti~SC~Light }
      [
        BoldFont       = Songti~SC~Bold,
        ItalicFont     = Kaiti~SC,
        BoldItalicFont = Kaiti~SC~Bold
      ]
    \setCJKsansfont { PingFang~SC }
    \setCJKmonofont { STFangsong  }
    \setCJKfamilyfont { zhsong } { Songti~SC~Light } [ BoldFont = Songti~SC~Bold ]
    \setCJKfamilyfont { zhhei  } { Heiti~SC~Light  } [ BoldFont = Heiti~SC~Medium ]
    \setCJKfamilyfont { zhpf   } { PingFang~SC     }
    \setCJKfamilyfont { zhfs   } { STFangsong      }
    \setCJKfamilyfont { zhkai  } { Kaiti~SC        } [ BoldFont = Kaiti~SC~Bold ]
    \setCJKfamilyfont { zhli   } { Baoli~SC        }
    \setCJKfamilyfont { zhyou  } { Yuanti~SC~Light } [ BoldFont = Yuanti~SC~Regular ]
%</macnew>
  }
%</macold|macnew>
%    \end{macrocode}
%
% \paragraph{\opt{ubuntu}}
%
% \changes{v2.5}{2019/11/07}{\opt{ubuntu} 改用思源(Noto CJK)和文鼎字库,不再
% 支持使用 \pdfLaTeX{} 编译。}
%
%    \begin{macrocode}
%<*ubuntu>
\ctex_fontset_case:nnnn
  { \ctex_fontset_error:n { ubuntu } }
  {
    \ctex_zhmap_case:nnn
      {
        \setCJKmainfont { :2:NotoSerifCJK-Regular.ttc }
          [ BoldFont = :2:NotoSerifCJK-Bold.ttc, ItalicFont = gkai00mp.ttf ]
        \setCJKsansfont { :2:NotoSansCJK-Regular.ttc  }
          [ BoldFont = :2:NotoSansCJK-Bold.ttc  ]
        \setCJKmonofont { :2:NotoSerifCJK-Regular.ttc }
          [ BoldFont = :2:NotoSerifCJK-Bold.ttc ]
        \setCJKfamilyfont { zhsong } { :2:NotoSerifCJK-Regular.ttc }
          [ BoldFont = :2:NotoSerifCJK-Bold.ttc ]
        \setCJKfamilyfont { zhhei  } { :2:NotoSansCJK-Regular.ttc  }
          [ BoldFont = :2:NotoSansCJK-Bold.ttc  ]
        \setCJKfamilyfont { zhkai  } { gkai00mp.ttf  }
        \ctex_punct_set:n { ubuntu }
        \ctex_punct_map_family:nn   { \CJKrmdefault        } { zhsong  }
        \ctex_punct_map_family:nn   { \CJKsfdefault        } { zhhei   }
        \ctex_punct_map_family:nn   { \CJKttdefault        } { zhsong  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault        } { zhkai   }
        \ctex_punct_map_bfseries:nn { \CJKsfdefault, zhhei } { zhheib  }
        \ctex_punct_map_bfseries:nn
          { \CJKrmdefault, \CJKttdefault, zhsong }
          { zhsongb }
      }
      {
        \ctex_load_zhmap:nnnn { rm } { zhhei } { zhsong } { ubuntu }
        \ctex_punct_set:n { ubuntu }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
      { \ctex_fontset_error:n { ubuntu } }
  }
  {
    \ctex_set_upmap_unicode:nnn { upserif }
      { :2:NotoSerifCJK-Regular.ttc } { :2:NotoSerifCJK-Bold.ttc }
    \ctex_set_upmap_unicode:nnn { upsans  }
      { :2:NotoSansCJK-Regular.ttc  } { :2:NotoSansCJK-Bold.ttc  }
    \ctex_set_upmap_unicode:nnn { upmono  }
      { :2:NotoSerifCJK-Regular.ttc } { }
    \ctex_set_upmap:nnn { upserifit } { gkai00mp.ttf  } { }
    \ctex_set_upfamily:nnn { zhsong } { upzhserif   } { upzhserifb }
    \ctex_set_upfamily:nnn { zhhei  } { upzhsans    } { upzhsansb  }
    \ctex_set_upfamily:nnn { zhkai  } { upzhserifit } { }
  }
  {
    \setCJKmainfont { Noto~Serif~CJK~SC } [ ItalicFont = AR~PL~KaitiM~GB ]
    \setCJKsansfont { Noto~Sans~CJK~SC  }
    \setCJKmonofont { Noto~Serif~CJK~SC }
    \setCJKfamilyfont { zhsong } { Noto~Serif~CJK~SC }
    \setCJKfamilyfont { zhhei  } { Noto~Sans~CJK~SC  }
    \setCJKfamilyfont { zhkai  } { AR~PL~KaitiM~GB   }
  }
%</ubuntu>
%    \end{macrocode}
%
% \paragraph{\opt{windows}}
%
% \changes{v2.4.1}{2016/05/14}{使用 \file{bootfont.bin} 判断 Windows XP 以避免
%   权限问题。}
% \changes{v2.5}{2019/11/04}{使用环境变量代替绝对路径查找字体。}
% \changes{v2.5}{2019/11/05}{不再支持 Windows XP 系统,\opt{windowsold} 和
%   \opt{windowsnew} 成为过时字库选项。}
%
% \begin{variable}{ \c_@@_msyh_suffix_tl}
% Windows 8 以后,微软雅黑由原来的 \file{.ttf} 后缀改为 \file{.ttc} 后缀,需要
% 加以区分。
%    \begin{macrocode}
%<*windows>
\file_if_exist:nTF { \c_dollar_str WINDIR/Fonts/msyh.ttc }
  { \tl_const:Nn \c_@@_msyh_suffix_tl { ttc } }
  {
    \file_if_exist:nTF { msyh.ttc }
      { \tl_const:Nn \c_@@_msyh_suffix_tl { ttc } }
      { \tl_const:Nn \c_@@_msyh_suffix_tl { ttf } }
  }
%    \end{macrocode}
% \end{variable}
%
%    \begin{macrocode}
\ctex_fontset_case:nnn
  {
    \ctex_zhmap_case:nnn
      {
        \ctex_punct_set:n { windows }
        \setCJKmainfont { simsun.ttc }
          [ BoldFont = simhei.ttf, ItalicFont = simkai.ttf ]
        \setCJKsansfont { msyh.\c_@@_msyh_suffix_tl }
          [ BoldFont = msyhbd.\c_@@_msyh_suffix_tl ]
        \setCJKmonofont { simfang.ttf }
        \setCJKfamilyfont { zhsong  } { simsun.ttc  }
        \setCJKfamilyfont { zhhei   } { simhei.ttf  }
        \setCJKfamilyfont { zhfs    } { simfang.ttf }
        \setCJKfamilyfont { zhkai   } { simkai.ttf  }
        \setCJKfamilyfont { zhyahei } { msyh.\c_@@_msyh_suffix_tl }
          [ BoldFont = msyhbd.\c_@@_msyh_suffix_tl ]
        \setCJKfamilyfont { zhli    } { simli.ttf   }
        \setCJKfamilyfont { zhyou   } { simyou.ttf  }
        \ctex_punct_map_family:nn   { \CJKrmdefault          } { zhsong   }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault          } { zhhei    }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault          } { zhkai    }
        \ctex_punct_map_family:nn   { \CJKsfdefault          } { zhyahei  }
        \ctex_punct_map_bfseries:nn { \CJKsfdefault, zhyahei } { zhyaheib }
        \ctex_punct_map_family:nn   { \CJKttdefault          } { zhfs     }
      }
      {
        \ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { windows }
        \ctex_punct_set:n { windows }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
      { }
  }
  {
    \ctex_set_upfonts:nnnnnn
      { simsun.ttc                   }
      { simhei.ttf                   }
      { simkai.ttf                   }
      { msyh.\c_@@_msyh_suffix_tl    }
      { msyhbd.\c_@@_msyh_suffix_tl  }
      { simfang.ttf                  }
    \ctex_set_upfamily:nnn { zhsong  } { upzhserif   } {}
    \ctex_set_upfamily:nnn { zhhei   } { upzhserifb  } {}
    \ctex_set_upfamily:nnn { zhfs    } { upzhmono    } {}
    \ctex_set_upfamily:nnn { zhkai   } { upzhserifit } {}
    \ctex_set_upfamily:nnn { zhyahei } { upzhsans    } { upzhsansb }
    \ctex_set_upfamily:nnn { zhli    } { upschrm     } {}
    \ctex_set_upfamily:nnn { zhyou   } { upschgt     } {}
    \ctex_set_upmap:nnn { upstsl } { simli.ttf  } {}
    \ctex_set_upmap:nnn { upstht } { simyou.ttf } {}
  }
  {
    \setCJKmainfont   { SimSun } [ BoldFont = SimHei , ItalicFont = KaiTi ]
    \setCJKsansfont   { Microsoft~YaHei } [ BoldFont = *~Bold ]
    \setCJKmonofont   { FangSong }
    \setCJKfamilyfont { zhsong  } { SimSun          }
    \setCJKfamilyfont { zhhei   } { SimHei          }
    \setCJKfamilyfont { zhfs    } { FangSong        }
    \setCJKfamilyfont { zhkai   } { KaiTi           }
    \setCJKfamilyfont { zhyahei } { Microsoft~YaHei } [ BoldFont = *~Bold ]
    \setCJKfamilyfont { zhli    } { LiSu            }
    \setCJKfamilyfont { zhyou   } { YouYuan         }
  }
%</windows>
%    \end{macrocode}
%
% \subsubsection{中文字体命令}
% \changes{v2.4.14}{2018/05/01}{为 \opt{macnew} 配置字体命令。}
%
% \begin{macro}{\songti,\heiti,\fangsong,\kaishu,\lishu,\youyuan,\yahei,\pingfang}
% 使用 \upLaTeX{} 编译时,\opt{macnew} 字库中由于传统黑体(黑体-简)无法使用,
% 我们用苹方来代替。同时 \tn{yahei}、\tn{pingfang} 命令被设置为与 \tn{heiti} 相同。
%    \begin{macrocode}
%<*!mac>
\NewDocumentCommand \songti   { } { \CJKfamily { zhsong  } }
\NewDocumentCommand \heiti    { } { \CJKfamily { zhhei   } }
%<!ubuntu>\NewDocumentCommand \fangsong { } { \CJKfamily { zhfs    } }
\NewDocumentCommand \kaishu   { } { \CJKfamily { zhkai   } }
%<*windows|founder|macnew>
\NewDocumentCommand \lishu    { } { \CJKfamily { zhli    } }
\NewDocumentCommand \youyuan  { } { \CJKfamily { zhyou   } }
%</windows|founder|macnew>
%<windows>\NewDocumentCommand \yahei    { } { \CJKfamily { zhyahei } }
%<*macnew>
\bool_lazy_or:nnTF
  { \sys_if_engine_pdftex_p: }
  { \sys_if_engine_uptex_p:  }
  {
    \cs_new_eq:NN \yahei    \heiti
    \cs_new_eq:NN \pingfang \heiti
  }
  {
    \NewDocumentCommand \yahei    { } { \CJKfamily { zhpf } }
    \NewDocumentCommand \pingfang { } { \CJKfamily { zhpf } }
  }
%</macnew>
%</!mac>
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</fontset>
%    \end{macrocode}
%
% \subsubsection{\pkg{zhmetrics} 的字体映射}
%
% \changes{v2.5.2}{2020/05/05}{\file{zhadobefonts.tex} 等字体映射文件更名为
%   \file{ctex-zhmap-*.tex}。}
%
% 确认 \tn{catcode},没有重复载入检查。
%    \begin{macrocode}
%<*zhmap>
\begingroup\catcode61\catcode48\catcode32=10\relax%
  \catcode 35=6  % #
  \catcode 45=12 % -
  \catcode123=1  % {
  \catcode125=2  % }
  \toks0{\endlinechar=\the\endlinechar\relax}%
  \toks2{\endlinechar=-1 }%
  \def\x#1 #2 {%
    \toks0\expandafter{\the\toks0 \catcode#1=\the\catcode#1\relax}%
    \toks2\expandafter{\the\toks2 \catcode#1=#2 }}%
  \x  13  5 % carriage return
  \x  32 10 % space
  \x  35  6 % #
  \x  40 12 % (
  \x  41 12 % )
  \x  45 12 % -
  \x  46 12 % .
  \x  47 12 % /
  \x  58 12 % :
  \x  60 12 % <
  \x  61 12 % =
  \x  64 11 % @
  \x  91 12 % [
  \x  93 12 % ]
  \x 123  1 % {
  \x 125  2 % }
  \edef\x#1{\endgroup%
    \edef\noexpand#1{%
      \the\toks0 %
      \let\noexpand\noexpand\noexpand#1%
          \noexpand\noexpand\noexpand\undefined%
      \noexpand\noexpand\noexpand\endinput}%
    \the\toks2}%
\expandafter\x\csname ctex@zhmap@endinput\endcsname
%    \end{macrocode}
%
% \begin{macro}[int]{\ifzhmappdf}
%    \begin{macrocode}
\begingroup\expandafter\endgroup
\expandafter\let\csname ifzhmappdf\expandafter\endcsname\csname
  \expandafter\ifx\csname ifctexpdf\endcsname\relax
    \expandafter\ifx\csname pdfoutput\endcsname\relax
      iffalse\else\ifnum\pdfoutput < 1 iffalse\else iftrue\fi\fi
  \else ifctexpdf\fi
\endcsname
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ProvidesFile}
% 提供非 \LaTeX{} 格式下的 \tn{ProvidesFile}。
%    \begin{macrocode}
\begingroup
\expandafter\ifx\csname ProvidesFile\endcsname\relax
  \long\def\x#1\ProvidesFile#2[#3]{%
    #1%
    \immediate\write-1{File: #2 #3}%
    \expandafter\xdef\csname ver@#2\endcsname{#3}}
  \expandafter\x%
\fi
\endgroup
%    \end{macrocode}
% \end{macro}
%
% 文件标识信息。
%    \begin{macrocode}
%<adobe>\ProvidesFile{ctex-zhmap-adobe.tex}%
%<adobe>  [2022/06/04 v2.5.9 Adobe font map loader for DVIPDFMx (CTEX)]
%<fandol>\ProvidesFile{ctex-zhmap-fandol.tex}%
%<fandol>  [2022/06/04 v2.5.9 Fandol font map loader for DVIPDFMx (CTEX)]
%<founder>\ProvidesFile{ctex-zhmap-founder.tex}%
%<founder>  [2022/06/04 v2.5.9 Founder font map loader for pdfTeX and DVIPDFMx (CTEX)]
%<mac>\ProvidesFile{ctex-zhmap-mac.tex}%
%<mac>  [2022/06/04 v2.5.9 Mac font map loader for DVIPDFMx (CTEX)]
%<ubuntu>\ProvidesFile{ctex-zhmap-ubuntu.tex}%
%<ubuntu>  [2022/06/04 v2.5.9 Ubuntu font map loader for DVIPDFMx (CTEX)]
%<windows>\ProvidesFile{ctex-zhmap-windows.tex}%
%<windows>  [2022/06/04 v2.5.9 Windows font map loader for pdfTeX and DVIPDFMx (CTEX)]
%    \end{macrocode}
%
% \paragraph{\pkg{ctex-zhmap-adobe.tex}}
%
%    \begin{macrocode}
%<*adobe>
\ifzhmappdf
%% pdfTeX does not support OTF fonts
\else
  \special{pdf:mapline gbk@UGBK@          UniGB-UTF16-H AdobeSongStd-Light.otf}
  \special{pdf:mapline gbksong@UGBK@      UniGB-UTF16-H AdobeSongStd-Light.otf}
  \special{pdf:mapline gbkkai@UGBK@       UniGB-UTF16-H AdobeKaitiStd-Regular.otf}
  \special{pdf:mapline gbkhei@UGBK@       UniGB-UTF16-H AdobeHeitiStd-Regular.otf}
  \special{pdf:mapline gbkfs@UGBK@        UniGB-UTF16-H AdobeFangsongStd-Regular.otf}
  \special{pdf:mapline cyberb@Unicode@    UniGB-UTF16-H AdobeSongStd-Light.otf}
  \special{pdf:mapline unisong@Unicode@   UniGB-UTF16-H AdobeSongStd-Light.otf}
  \special{pdf:mapline unikai@Unicode@    UniGB-UTF16-H AdobeKaitiStd-Regular.otf}
  \special{pdf:mapline unihei@Unicode@    UniGB-UTF16-H AdobeHeitiStd-Regular.otf}
  \special{pdf:mapline unifs@Unicode@     UniGB-UTF16-H AdobeFangsongStd-Regular.otf}
  \special{pdf:mapline gbksongsl@UGBK@    UniGB-UTF16-H AdobeSongStd-Light.otf       -s .167}
  \special{pdf:mapline gbkkaisl@UGBK@     UniGB-UTF16-H AdobeKaitiStd-Regular.otf    -s .167}
  \special{pdf:mapline gbkheisl@UGBK@     UniGB-UTF16-H AdobeHeitiStd-Regular.otf    -s .167}
  \special{pdf:mapline gbkfssl@UGBK@      UniGB-UTF16-H AdobeFangsongStd-Regular.otf -s .167}
  \special{pdf:mapline unisongsl@Unicode@ UniGB-UTF16-H AdobeSongStd-Light.otf       -s .167}
  \special{pdf:mapline unikaisl@Unicode@  UniGB-UTF16-H AdobeKaitiStd-Regular.otf    -s .167}
  \special{pdf:mapline uniheisl@Unicode@  UniGB-UTF16-H AdobeHeitiStd-Regular.otf    -s .167}
  \special{pdf:mapline unifssl@Unicode@   UniGB-UTF16-H AdobeFangsongStd-Regular.otf -s .167}
\fi
%</adobe>
%    \end{macrocode}
%
% \paragraph{\pkg{ctex-zhmap-fandol.tex}}
%
%    \begin{macrocode}
%<*fandol>
\ifzhmappdf
%% pdfTeX does not support OTF fonts
\else
  \special{pdf:mapline gbk@UGBK@          UniGB-UTF16-H FandolSong-Regular.otf}
  \special{pdf:mapline gbksong@UGBK@      UniGB-UTF16-H FandolSong-Regular.otf}
  \special{pdf:mapline gbkkai@UGBK@       UniGB-UTF16-H FandolKai-Regular.otf}
  \special{pdf:mapline gbkhei@UGBK@       UniGB-UTF16-H FandolHei-Regular.otf}
  \special{pdf:mapline gbkfs@UGBK@        UniGB-UTF16-H FandolFang-Regular.otf}
  \special{pdf:mapline cyberb@Unicode@    UniGB-UTF16-H FandolSong-Regular.otf}
  \special{pdf:mapline unisong@Unicode@   UniGB-UTF16-H FandolSong-Regular.otf}
  \special{pdf:mapline unikai@Unicode@    UniGB-UTF16-H FandolKai-Regular.otf}
  \special{pdf:mapline unihei@Unicode@    UniGB-UTF16-H FandolHei-Regular.otf}
  \special{pdf:mapline unifs@Unicode@     UniGB-UTF16-H FandolFang-Regular.otf}
  \special{pdf:mapline gbksongsl@UGBK@    UniGB-UTF16-H FandolSong-Regular.otf -s .167}
  \special{pdf:mapline gbkkaisl@UGBK@     UniGB-UTF16-H FandolKai-Regular.otf  -s .167}
  \special{pdf:mapline gbkheisl@UGBK@     UniGB-UTF16-H FandolHei-Regular.otf  -s .167}
  \special{pdf:mapline gbkfssl@UGBK@      UniGB-UTF16-H FandolFang-Regular.otf -s .167}
  \special{pdf:mapline unisongsl@Unicode@ UniGB-UTF16-H FandolSong-Regular.otf -s .167}
  \special{pdf:mapline unikaisl@Unicode@  UniGB-UTF16-H FandolKai-Regular.otf  -s .167}
  \special{pdf:mapline uniheisl@Unicode@  UniGB-UTF16-H FandolHei-Regular.otf  -s .167}
  \special{pdf:mapline unifssl@Unicode@   UniGB-UTF16-H FandolFang-Regular.otf -s .167}
\fi
%</fandol>
%    \end{macrocode}
%
% \paragraph{\pkg{ctex-zhmap-founder.tex}}
%
%    \begin{macrocode}
%<*founder>
\ifzhmappdf
  \pdfmapline{=gbk@UGBK@          <FZSSK.TTF}
  \pdfmapline{=gbksong@UGBK@      <FZSSK.TTF}
  \pdfmapline{=gbkkai@UGBK@       <FZKTK.TTF}
  \pdfmapline{=gbkhei@UGBK@       <FZHTK.TTF}
  \pdfmapline{=gbkfs@UGBK@        <FZFSK.TTF}
  \pdfmapline{=gbkli@UGBK@        <FZLSK.TTF}
  \pdfmapline{=gbkyou@UGBK@       <FZY1K.TTF}
  \pdfmapline{=cyberb@Unicode@    <FZSSK.TTF}
  \pdfmapline{=unisong@Unicode@   <FZSSK.TTF}
  \pdfmapline{=unikai@Unicode@    <FZKTK.TTF}
  \pdfmapline{=unihei@Unicode@    <FZHTK.TTF}
  \pdfmapline{=unifs@Unicode@     <FZFSK.TTF}
  \pdfmapline{=unili@Unicode@     <FZLSK.TTF}
  \pdfmapline{=uniyou@Unicode@    <FZY1K.TTF}
  \pdfmapline{=gbksongsl@UGBK@    <FZSSK.TTF}
  \pdfmapline{=gbkkaisl@UGBK@     <FZKTK.TTF}
  \pdfmapline{=gbkheisl@UGBK@     <FZHTK.TTF}
  \pdfmapline{=gbkfssl@UGBK@      <FZFSK.TTF}
  \pdfmapline{=gbklisl@UGBK@      <FZLSK.TTF}
  \pdfmapline{=gbkyousl@UGBK@     <FZY1K.TTF}
  \pdfmapline{=unisongsl@Unicode@ <FZSSK.TTF}
  \pdfmapline{=unikaisl@Unicode@  <FZKTK.TTF}
  \pdfmapline{=uniheisl@Unicode@  <FZHTK.TTF}
  \pdfmapline{=unifssl@Unicode@   <FZFSK.TTF}
  \pdfmapline{=unilisl@Unicode@   <FZLSK.TTF}
  \pdfmapline{=uniyousl@Unicode@  <FZY1K.TTF}
\else
  \special{pdf:mapline gbk@UGBK@          unicode FZSSK.TTF}
  \special{pdf:mapline gbksong@UGBK@      unicode FZSSK.TTF}
  \special{pdf:mapline gbkkai@UGBK@       unicode FZKTK.TTF}
  \special{pdf:mapline gbkhei@UGBK@       unicode FZHTK.TTF}
  \special{pdf:mapline gbkfs@UGBK@        unicode FZFSK.TTF}
  \special{pdf:mapline gbkli@UGBK@        unicode FZLSK.TTF}
  \special{pdf:mapline gbkyou@UGBK@       unicode FZY1K.TTF}
  \special{pdf:mapline cyberb@Unicode@    unicode FZSSK.TTF}
  \special{pdf:mapline unisong@Unicode@   unicode FZSSK.TTF}
  \special{pdf:mapline unikai@Unicode@    unicode FZKTK.TTF}
  \special{pdf:mapline unihei@Unicode@    unicode FZHTK.TTF}
  \special{pdf:mapline unifs@Unicode@     unicode FZFSK.TTF}
  \special{pdf:mapline unili@Unicode@     unicode FZLSK.TTF}
  \special{pdf:mapline uniyou@Unicode@    unicode FZY1K.TTF}
  \special{pdf:mapline gbksongsl@UGBK@    unicode FZSSK.TTF -s .167}
  \special{pdf:mapline gbkkaisl@UGBK@     unicode FZKTK.TTF -s .167}
  \special{pdf:mapline gbkheisl@UGBK@     unicode FZHTK.TTF -s .167}
  \special{pdf:mapline gbkfssl@UGBK@      unicode FZFSK.TTF -s .167}
  \special{pdf:mapline gbklisl@UGBK@      unicode FZLSK.TTF -s .167}
  \special{pdf:mapline gbkyousl@UGBK@     unicode FZY1K.TTF -s .167}
  \special{pdf:mapline unisongsl@Unicode@ unicode FZSSK.TTF -s .167}
  \special{pdf:mapline unikaisl@Unicode@  unicode FZKTK.TTF -s .167}
  \special{pdf:mapline uniheisl@Unicode@  unicode FZHTK.TTF -s .167}
  \special{pdf:mapline unifssl@Unicode@   unicode FZFSK.TTF -s .167}
  \special{pdf:mapline unilisl@Unicode@   unicode FZLSK.TTF -s .167}
  \special{pdf:mapline uniyousl@Unicode@  unicode FZY1K.TTF -s .167}
\fi
%</founder>
%    \end{macrocode}
%
% \paragraph{\pkg{ctex-zhmap-mac.tex}}
%
% \changes{v2.5}{2020/01/15}{增加字体映射文件 \file{zhmacfonts.tex}。}
%
%    \begin{macrocode}
%<*mac>
\ifzhmappdf
%% pdfTeX does not support OTF fonts
\else
  \special{pdf:mapline gbk@UGBK@          UniGB-UTF16-H :3:Songti.ttc}
  \special{pdf:mapline gbksong@UGBK@      UniGB-UTF16-H :3:Songti.ttc}
  \special{pdf:mapline gbkkai@UGBK@       UniGB-UTF16-H :0:Kaiti.ttc}
  \special{pdf:mapline gbkhei@UGBK@       unicode       :2:PingFang.ttc}
  \special{pdf:mapline gbkfs@UGBK@        unicode       STFANGSO.ttf}
  \special{pdf:mapline gbkli@UGBK@        UniGB-UTF16-H :0:Baoli.ttc}
  \special{pdf:mapline gbkyou@UGBK@       UniGB-UTF16-H :4:Yuanti.ttc}
  \special{pdf:mapline cyberb@Unicode@    UniGB-UTF16-H :3:Songti.ttc}
  \special{pdf:mapline unisong@Unicode@   UniGB-UTF16-H :3:Songti.ttc}
  \special{pdf:mapline unikai@Unicode@    UniGB-UTF16-H :0:Kaiti.ttc}
  \special{pdf:mapline unihei@Unicode@    unicode       :2:PingFang.ttc}
  \special{pdf:mapline unifs@Unicode@     unicode       STFANGSO.ttf}
  \special{pdf:mapline unili@Unicode@     UniGB-UTF16-H :0:Baoli.ttc}
  \special{pdf:mapline uniyou@Unicode@    UniGB-UTF16-H :4:Yuanti.ttc}
  \special{pdf:mapline gbksongsl@UGBK@    UniGB-UTF16-H :3:Songti.ttc   -s .167}
  \special{pdf:mapline gbkkaisl@UGBK@     UniGB-UTF16-H :0:Kaiti.ttc    -s .167}
  \special{pdf:mapline gbkheisl@UGBK@     unicode       :2:PingFang.ttc -s .167}
  \special{pdf:mapline gbkfssl@UGBK@      unicode       STFANGSO.ttf    -s .167}
  \special{pdf:mapline gbklisl@UGBK@      UniGB-UTF16-H :0:Baoli.ttc    -s .167}
  \special{pdf:mapline gbkyousl@UGBK@     UniGB-UTF16-H :4:Yuanti.ttc   -s .167}
  \special{pdf:mapline unisongsl@Unicode@ UniGB-UTF16-H :3:Songti.ttc   -s .167}
  \special{pdf:mapline unikaisl@Unicode@  UniGB-UTF16-H :0:Kaiti.ttc    -s .167}
  \special{pdf:mapline uniheisl@Unicode@  unicode       :2:PingFang.ttc -s .167}
  \special{pdf:mapline unifssl@Unicode@   unicode       STFANGSO.ttf    -s .167}
  \special{pdf:mapline unilisl@Unicode@   UniGB-UTF16-H :0:Baoli.ttc    -s .167}
  \special{pdf:mapline uniyousl@Unicode@  UniGB-UTF16-H :4:Yuanti.ttc   -s .167}
\fi
%</mac>
%    \end{macrocode}
%
% \paragraph{\pkg{ctex-zhmap-ubuntu.tex}}
%
%    \begin{macrocode}
%<*ubuntu>
\ifzhmappdf
%% pdfTeX does not support OTF fonts
\else
  \special{pdf:mapline gbk@UGBK@          unicode :2:NotoSerifCJK-Regular.ttc}
  \special{pdf:mapline gbksong@UGBK@      unicode :2:NotoSerifCJK-Regular.ttc}
  \special{pdf:mapline gbkkai@UGBK@       unicode gkai00mp.ttf}
  \special{pdf:mapline gbkhei@UGBK@       unicode :2:NotoSansCJK-Regular.ttc}
  \special{pdf:mapline gbkfs@UGBK@        unicode :2:NotoSerifCJK-Regular.ttc}
  \special{pdf:mapline cyberb@Unicode@    unicode :2:NotoSerifCJK-Regular.ttc}
  \special{pdf:mapline unisong@Unicode@   unicode :2:NotoSerifCJK-Regular.ttc}
  \special{pdf:mapline unikai@Unicode@    unicode gkai00mp.ttf}
  \special{pdf:mapline unihei@Unicode@    unicode :2:NotoSansCJK-Regular.ttc}
  \special{pdf:mapline unifs@Unicode@     unicode :2:NotoSerifCJK-Regular.ttc}
  \special{pdf:mapline gbksongsl@UGBK@    unicode :2:NotoSerifCJK-Regular.ttc -s .167}
  \special{pdf:mapline gbkkaisl@UGBK@     unicode gkai00mp.ttf                -s .167}
  \special{pdf:mapline gbkheisl@UGBK@     unicode :2:NotoSansCJK-Regular.ttc  -s .167}
  \special{pdf:mapline gbkfssl@UGBK@      unicode :2:NotoSerifCJK-Regular.ttc -s .167}
  \special{pdf:mapline unisongsl@Unicode@ unicode :2:NotoSerifCJK-Regular.ttc -s .167}
  \special{pdf:mapline unikaisl@Unicode@  unicode gkai00mp.ttf                -s .167}
  \special{pdf:mapline uniheisl@Unicode@  unicode :2:NotoSansCJK-Regular.ttc  -s .167}
  \special{pdf:mapline unifssl@Unicode@   unicode :2:NotoSerifCJK-Regular.ttc -s .167}
\fi
%</ubuntu>
%    \end{macrocode}
%
% \paragraph{\pkg{ctex-zhmap-windows.tex}}
%
%    \begin{macrocode}
%<*windows>
\ifzhmappdf
  \pdfmapline{=gbk@UGBK@          <simsun.ttc}
  \pdfmapline{=gbksong@UGBK@      <simsun.ttc}
  \pdfmapline{=gbkkai@UGBK@       <simkai.ttf}
  \pdfmapline{=gbkhei@UGBK@       <simhei.ttf}
  \pdfmapline{=gbkfs@UGBK@        <simfang.ttf}
  \pdfmapline{=gbkli@UGBK@        <simli.ttf}
  \pdfmapline{=gbkyou@UGBK@       <simyou.ttf}
  \pdfmapline{=cyberb@Unicode@    <simsun.ttc}
  \pdfmapline{=unisong@Unicode@   <simsun.ttc}
  \pdfmapline{=unikai@Unicode@    <simkai.ttf}
  \pdfmapline{=unihei@Unicode@    <simhei.ttf}
  \pdfmapline{=unifs@Unicode@     <simfang.ttf}
  \pdfmapline{=unili@Unicode@     <simli.ttf}
  \pdfmapline{=uniyou@Unicode@    <simyou.ttf}
  \pdfmapline{=gbksongsl@UGBK@    <simsun.ttc}
  \pdfmapline{=gbkkaisl@UGBK@     <simkai.ttf}
  \pdfmapline{=gbkheisl@UGBK@     <simhei.ttf}
  \pdfmapline{=gbkfssl@UGBK@      <simfang.ttf}
  \pdfmapline{=gbklisl@UGBK@      <simli.ttf}
  \pdfmapline{=gbkyousl@UGBK@     <simyou.ttf}
  \pdfmapline{=unisongsl@Unicode@ <simsun.ttc}
  \pdfmapline{=unikaisl@Unicode@  <simkai.ttf}
  \pdfmapline{=uniheisl@Unicode@  <simhei.ttf}
  \pdfmapline{=unifssl@Unicode@   <simfang.ttf}
  \pdfmapline{=unilisl@Unicode@   <simli.ttf}
  \pdfmapline{=uniyousl@Unicode@  <simyou.ttf}
\else
  \special{pdf:mapline gbk@UGBK@          unicode :0:simsun.ttc -v 50}
  \special{pdf:mapline gbksong@UGBK@      unicode :0:simsun.ttc -v 50}
  \special{pdf:mapline gbkkai@UGBK@       unicode simkai.ttf    -v 70}
  \special{pdf:mapline gbkhei@UGBK@       unicode simhei.ttf    -v 150}
  \special{pdf:mapline gbkfs@UGBK@        unicode simfang.ttf   -v 50}
  \special{pdf:mapline gbkli@UGBK@        unicode simli.ttf     -v 150}
  \special{pdf:mapline gbkyou@UGBK@       unicode simyou.ttf    -v 60}
  \special{pdf:mapline cyberb@Unicode@    unicode :0:simsun.ttc -v 50}
  \special{pdf:mapline unisong@Unicode@   unicode :0:simsun.ttc -v 50}
  \special{pdf:mapline unikai@Unicode@    unicode simkai.ttf    -v 70}
  \special{pdf:mapline unihei@Unicode@    unicode simhei.ttf    -v 150}
  \special{pdf:mapline unifs@Unicode@     unicode simfang.ttf   -v 50}
  \special{pdf:mapline unili@Unicode@     unicode simli.ttf     -v 150}
  \special{pdf:mapline uniyou@Unicode@    unicode simyou.ttf    -v 60}
  \special{pdf:mapline gbksongsl@UGBK@    unicode :0:simsun.ttc -v 50  -s .167}
  \special{pdf:mapline gbkkaisl@UGBK@     unicode simkai.ttf    -v 70  -s .167}
  \special{pdf:mapline gbkheisl@UGBK@     unicode simhei.ttf    -v 150 -s .167}
  \special{pdf:mapline gbkfssl@UGBK@      unicode simfang.ttf   -v 50  -s .167}
  \special{pdf:mapline gbklisl@UGBK@      unicode simli.ttf     -v 150 -s .167}
  \special{pdf:mapline gbkyousl@UGBK@     unicode simyou.ttf    -v 60  -s .167}
  \special{pdf:mapline unisongsl@Unicode@ unicode :0:simsun.ttc -v 50  -s .167}
  \special{pdf:mapline unikaisl@Unicode@  unicode simkai.ttf    -v 70  -s .167}
  \special{pdf:mapline uniheisl@Unicode@  unicode simhei.ttf    -v 150 -s .167}
  \special{pdf:mapline unifssl@Unicode@   unicode simfang.ttf   -v 50  -s .167}
  \special{pdf:mapline unilisl@Unicode@   unicode simli.ttf     -v 150 -s .167}
  \special{pdf:mapline uniyousl@Unicode@  unicode simyou.ttf    -v 60  -s .167}
\fi
%</windows>
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex@zhmap@endinput
%</zhmap>
%    \end{macrocode}
%
% \subsubsection{制作 \texttt{spa} 文件}
%
% \changes{v2.5.2}{2020/05/05}{\file{ctexmakespa.tex} 更名为 \file{ctex-spa-make.tex}。}
% \changes{v2.5.2}{2020/05/05}{\file{ctexspamacro.tex} 更名为 \file{ctex-spa-macro.tex}。}
%
% 我们通过 \XeTeX{} 的 \tn{XeTeXglyphbounds} 取得字体中标点符号的边界信息,为
% \pkg{CJKpunct} 宏包制作 \file{spa}。
%
%    \begin{macrocode}
%<*spa>
%<*macro>
\input expl3-generic %
\ExplSyntaxOn
\sys_if_engine_xetex:F
  {
    \msg_new:nnn { ctex } { xetex }
      { XeTeX~is~required~to~compile~this~document! }
    \msg_fatal:nn { ctex } { xetex }
  }
%    \end{macrocode}
%
% \pkg{CJKpunct} 定义的标点符号是:
% \begin{verbatim}
%   ‘“「『〔([{〈《〖【
%   —…、。,.:;!?%〕)]}〉》〗】’”」』
% \end{verbatim}
% 注意顺序不能改变。
%    \begin{macrocode}
\seq_const_from_clist:Nn \c_@@_punct_seq
  {
    "2018 , "201C , "300C , "300E , "3014 , "FF08 , "FF3B , "FF5B ,
    "3008 , "300A , "3016 , "3010 ,
    "2014 , "2026 , "3001 , "3002 , "FF0C , "FF0E , "FF1A , "FF1B ,
    "FF01 , "FF1F , "FF05 , "3015 , "FF09 , "FF3D , "FF5D , "3009 ,
    "300B , "3017 , "3011 , "2019 , "201D , "300D , "300F
  }
%    \end{macrocode}
%
% \begin{macro}[int]{\ctex_make_spa:nn}
% |#1| 是 \file{spa} 文件名,|#2| 是由 CJK 族名与字体构成的逗号列表。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_make_spa:nn #1#2
  {
    \iow_open:Nn \g_@@_spa_iow {#1}
    \clist_map_inline:nn {#2}
      { \@@_write_family:nn ##1 }
    \iow_close:N \g_@@_spa_iow
  }
\iow_new:N \g_@@_spa_iow
\cs_new_eq:NN \MAKESPA \ctex_make_spa:nn
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_write_family:nn #1#2
  {
    \group_begin:
      \tex_font:D \l_@@_punct_font = "#2" ~ at ~ 100 pt \scan_stop:
      \l_@@_punct_font
      \clist_clear:N \l_@@_punct_bounds_clist
      \seq_map_inline:Nn \c_@@_punct_seq
        { \exp_args:No \@@_save_bounds:n { \int_use:N \tex_XeTeXcharglyph:D ##1 } }
      \iow_now:Nx \g_@@_spa_iow
        {
          \token_to_str:N \ctexspadef {#1}
%    \end{macrocode}
% 最后这三个逗号对 \pkg{CJKpunct} 来说是必要的。
%    \begin{macrocode}
            { \l_@@_punct_bounds_clist , , , }
        }
    \group_end:
  }
\cs_new_protected:Npn \@@_save_bounds:n #1
  {
    \clist_put_right:Nx \l_@@_punct_bounds_clist
      {
        \@@_calc_bounds:nn { 1 } {#1} ,
        \@@_calc_bounds:nn { 3 } {#1}
      }
  }
\clist_new:N \l_@@_punct_bounds_clist
%    \end{macrocode}
%
% \pkg{CJKpunct} 要求的格式是边界空白宽度与 1\,em 的比值的一百倍。
%    \begin{macrocode}
\cs_new:Npn \@@_calc_bounds:nn #1#2
  {
    \fp_eval:n
      {
        round
          (
            \dim_to_decimal_in_unit:nn
              { 100 \tex_XeTeXglyphbounds:D #1 ~ #2 }
              { 1 em }
          )
      }
  }
\ExplSyntaxOff
%</macro>
%    \end{macrocode}
%
% 下面是 \CTeX{} 定义的一些字体。
%    \begin{macrocode}
%<*make>
\input ctex-spa-macro %
\MAKESPA {ctexpunct.spa}
  {
    {adobezhsong}     {AdobeSongStd-Light} ,
    {adobezhhei}      {AdobeHeitiStd-Regular} ,
    {adobezhkai}      {AdobeKaitiStd-Regular} ,
    {adobezhfs}       {AdobeFangsongStd-Regular} ,
%
    {fandolzhsong}    {FandolSong} ,
    {fandolzhsongb}   {FandolSong-Bold} ,
    {fandolzhhei}     {FandolHei} ,
    {fandolzhheib}    {FandolHei-Bold} ,
    {fandolzhkai}     {FandolKai} ,
    {fandolzhfs}      {FandolFang} ,
%
    {founderzhsong}   {FZShuSong-Z01} ,
    {founderzhsongb}  {FZXiaoBiaoSong-B05} ,
    {founderzhhei}    {FZHei-B01} ,
    {founderzhheil}   {FZXiHeiI-Z08} ,
    {founderzhkai}    {FZKai-Z03} ,
    {founderzhfs}     {FZFangSong-Z02} ,
    {founderzhli}     {FZLiShu-S01} ,
    {founderzhyou}    {FZXiYuan-M01} ,
    {founderzhyoub}   {FZZhunYuan-M02} ,
%
    {maczhsong}       {Songti SC Light} ,
    {maczhsongb}      {Songti SC Bold} ,
    {maczhhei}        {Heiti SC Medium} ,
    {maczhheil}       {Heiti SC Light} ,
    {maczhkai}        {Kaiti SC} ,
    {maczhkaib}       {Kaiti SC Bold} ,
    {maczhfs}         {STFangsong} ,
    {maczhli}         {Baoli SC} ,
    {maczhyou}        {Yuanti SC Light} ,
    {maczhyoub}       {Yuanti SC Regular} ,
    {maczhpf}         {PingFang SC} ,
    {maczhpfb}        {PingFang SC Semibold} ,
%
    {ubuntuzhsong}    {Noto Serif CJK SC} ,
    {ubuntuzhsongb}   {Noto Serif CJK SC Bold} ,
    {ubuntuzhhei}     {Noto Sans CJK SC} ,
    {ubuntuzhheib}    {Noto Sans CJK SC Bold} ,
    {ubuntuzhkai}     {AR PL KaitiM GB} ,
%
    {windowszhsong}   {SimSun} ,
    {windowszhhei}    {SimHei} ,
    {windowszhkai}    {KaiTi} ,
    {windowszhfs}     {FangSong} ,
    {windowszhli}     {LiSu} ,
    {windowszhyou}    {YouYuan} ,
    {windowszhyahei}  {Microsoft YaHei} ,
    {windowszhyaheib} {Microsoft YaHei Bold}
  }
\primitive\end
%</make>
%</spa>
%    \end{macrocode}
%
% \subsection{\pkg{translator} 宏包的中文字典}
%
%    \begin{macrocode}
%<*dict>
%    \end{macrocode}
%
% \changes{v2.4}{2016/02/19}{提供 \pkg{translator} 宏包的中文定理名称翻译。}
%
% 包括 \pkg{ChineseGBK} 和 \pkg{ChineseUTF8} 两种形式,目前只翻译 \pkg{beamer}
% 宏包需要的定理环境名称。
%
%    \begin{macrocode}
%<*theorem>
\providetranslation{Comments}{评论}
\providetranslation{comments}{评论}
\providetranslation{Comment}{评论}
\providetranslation{comment}{评论}
\providetranslation{Corollaries}{推论}
\providetranslation{corollaries}{推论}
\providetranslation{Corollary}{推论}
\providetranslation{corollary}{推论}
\providetranslation{Definitions}{定义}
\providetranslation{definitions}{定义}
\providetranslation{Definition}{定义}
\providetranslation{definition}{定义}
\providetranslation{Examples}{例}
\providetranslation{examples}{例}
\providetranslation{Example}{例}
\providetranslation{example}{例}
\providetranslation{Exercises}{练习}
\providetranslation{exercises}{练习}
\providetranslation{Exercise}{练习}
\providetranslation{exercise}{练习}
\providetranslation{Facts}{事实}
\providetranslation{facts}{事实}
\providetranslation{Fact}{事实}
\providetranslation{fact}{事实}
\providetranslation{Key Lemmas}{关键引理}
\providetranslation{key lemmas}{关键引理}
\providetranslation{Key Lemma}{关键引理}
\providetranslation{key lemma}{关键引理}
\providetranslation{Key Observations}{关键观察}
\providetranslation{key observations}{关键观察}
\providetranslation{Key Observation}{关键观察}
\providetranslation{key observation}{关键观察}
\providetranslation{Lemmas}{引理}
\providetranslation{lemmas}{引理}
\providetranslation{Lemma}{引理}
\providetranslation{lemma}{引理}
\providetranslation{Main Theorems}{主要定理}
\providetranslation{main theorems}{主要定理}
\providetranslation{Main Theorem}{主要定理}
\providetranslation{main theorem}{主要定理}
\providetranslation{Observations}{观察}
\providetranslation{observations}{观察}
\providetranslation{Observation}{观察}
\providetranslation{observation}{观察}
\providetranslation{Problems}{问题}
\providetranslation{problems}{问题}
\providetranslation{Problem}{问题}
\providetranslation{problem}{问题}
\providetranslation{Proofs}{证明}
\providetranslation{proofs}{证明}
\providetranslation{Proof}{证明}
\providetranslation{proof}{证明}
\providetranslation{Proof Sketch}{证明提要}
\providetranslation{Proof sketch}{证明提要}
\providetranslation{proof sketch}{证明提要}
\providetranslation{Proof Sketches}{证明提要}
\providetranslation{Proof sketches}{证明提要}
\providetranslation{proof sketches}{证明提要}
\providetranslation{Sketch of Proof}{证明提要}
\providetranslation{Sketch of Proofs}{证明提要}
\providetranslation{Sketch of proof}{证明提要}
\providetranslation{Sketch of proofs}{证明提要}
\providetranslation{sketch of proof}{证明提要}
\providetranslation{sketch of proofs}{证明提要}
\providetranslation{Propositions}{命题}
\providetranslation{propositions}{命题}
\providetranslation{Proposition}{命题}
\providetranslation{proposition}{命题}
\providetranslation{Remarks}{注}
\providetranslation{remarks}{注}
\providetranslation{Remark}{注}
\providetranslation{remark}{注}
\providetranslation{Solutions}{解}
\providetranslation{solutions}{解}
\providetranslation{Solution}{解}
\providetranslation{solution}{解}
\providetranslation{Theorems}{定理}
\providetranslation{theorems}{定理}
\providetranslation{Theorem}{定理}
\providetranslation{theorem}{定理}
%</theorem>
%    \end{macrocode}
%
%    \begin{macrocode}
%</dict>
%    \end{macrocode}
%
% \subsection{\pkg{ctexcap} 宏包}
%
%    \begin{macrocode}
%<*ctexcap>
%    \end{macrocode}
%
% \pkg{ctexcap} 是过时宏包。
%    \begin{macrocode}
\clist_new:N \l_@@_ctexcap_options_clist
\clist_set:Nx \l_@@_ctexcap_options_clist
  { \exp_not:v { opt@ \@currname . \@currext } , heading }
\msg_new:nnn { ctexcap } { deprecated }
  {
    Package~`ctexcap'~is~deprecated.\\
    Please~use~package~`ctex'~with~option~`#1'~instead: \\\\
    \iow_indent:n { \token_to_str:N \usepackage [#1] \{ ctex \} } \\
  }
\msg_warning:nnx { ctexcap } { deprecated }
  { \clist_use:Nn \l_@@_ctexcap_options_clist { , ~ } }
%    \end{macrocode}
%
% \pkg{ctexcap} 是默认打开 \opt{heading} 选项的 \pkg{ctex}。
%    \begin{macrocode}
\PassOptionsToPackage { heading = true } { ctexcap }
\RequirePackageWithOptions { ctex }
%    \end{macrocode}
%
%    \begin{macrocode}
%</ctexcap>
%    \end{macrocode}
%
%
% \subsection{\pkg{ctexhook} 宏包}
%
% \changes{v2.2}{2015/06/26}{将文档开头和宏包末尾钩子提取到 \pkg{ctexhook} 宏包中。}
% \changes{v2.5}{2020/04/21}{增加宏包开头钩子。}
% \changes{v2.5.4}{2020/08/02}{兼容 \LaTeX \ 2020/10/01 的钩子机制。}
%
%    \begin{macrocode}
%<*ctexhook>
%    \end{macrocode}
%
% \begin{macro}[int]{\ctex_if_format_at_least:nTF}
%  与 \tn{IfFormatAtLeastTF} 同义。
%    \begin{macrocode}
\cs_new:Npn \ctex_if_format_at_least:nTF
  { \@ifl@t@r \fmtversion }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5.7}{2021/06/12}{重新应用 \pkg{l3cctab}。}
%
% \begin{macro}[int]{\ctex_file_input:n,\ctex_push_file:,\ctex_pop_file:}
% 输入文件,关闭 \LaTeXiii 语法环境,并设置 |@| 为字母类,利用 \pkg{l3cctab} 实现。
% 我们使用 \cs{file_input:n} 而不是 \LaTeXe \ 的 \tn{input} 或者 \tn{InputIfFileExists}
% 载入文件,因此 \LaTeXe \ 的文件钩子都\emph{无效}。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_file_input:n #1
  {
    \ctex_push_file:
      \file_input:n {#1}
    \ctex_pop_file:
  }
\bool_if_exist:NTF \l__kernel_expl_bool
  {
    \cs_new_protected:Npn \ctex_push_file:
      {
        \seq_gpush:Nx \g_@@_expl_status_seq
          { \bool_if:NTF \l__kernel_expl_bool { 1 } { 0 } }
        \bool_set_false:N \l__kernel_expl_bool
        \cctab_begin:N \c_@@_package_cctab
      }
    \cs_new_protected:Npn \ctex_pop_file:
      {
        \cctab_end:
        \seq_gpop:NN \g_@@_expl_status_seq \l_@@_expl_status_tl
        \int_if_odd:nTF { \l_@@_expl_status_tl }
          { \bool_set_true:N  \l__kernel_expl_bool }
          { \bool_set_false:N \l__kernel_expl_bool }
      }
    \tl_new:N \l_@@_expl_status_tl
    \seq_new:N \g_@@_expl_status_seq
  }
  {
    \cs_new_protected:Npn \ctex_push_file:
      { \cctab_begin:N \c_@@_package_cctab }
    \cs_new_protected:Npn \ctex_pop_file:
      { \cctab_end: }
  }
\cctab_const:Nn \c_@@_package_cctab
  {
    \cctab_select:N \c_document_cctab
    \char_set_catcode_letter:n { 64 }
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5.7}{2021/06/09}{使用 \tn{disable@package@load} 禁止宏包载入。}
%
% \begin{macro}[int]{\ctex_disable_package:n}
% 禁止宏包载入。采用 \LaTeX \ 2020-10-01 提供的 \tn{disable@package@load} 实现,
% 否则采用传统方式:预定义 |\ver@|\meta{package}|.sty| 标识符。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_disable_package:n #1
  {
    \@ifpackageloaded {#1}
      { \msg_error:nnxx }
      { \@@_disable_package_aux:nnnn }
      { ctexhook } { disable-package } {#1} { \@currname }
  }
\cs_new_protected:Npx \@@_disable_package_aux:nnnn #1#2#3#4
  {
    \cs_if_exist:NTF \disable@package@load
      {
        \exp_args:Nnx \exp_not:N \disable@package@load {#3}
          { \msg_warning:nnnn {#1} {#2} {#3} {#4} }
      }
      { \tl_const:cn { ver@ #3 . \exp_not:N \@pkgextension } { 9999/99/99 } }
  }
\msg_new:nnn { ctexhook } { disable-package }
  { Package~`#1'~can~not~be~loaded~with~`#2'. }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_replace_package:nn}
% 替换宏包。采用 \LaTeX \ 2020-10-01 提供的 \tn{declare@file@substitution} 实现,
% 否则给出无效警告。
%    \begin{macrocode}
\ctex_if_format_at_least:nTF { 2020/10/01 }
  {
    \cs_new_protected:Npn \ctex_replace_package:nn #1#2
      {
        \declare@file@substitution
          { #1 . \@pkgextension }
          { #2 . \@pkgextension }
      }
  }
  {
    \cs_new_protected:Npn \ctex_replace_package:nn
      { \msg_warning:nnnn { ctexhook } { replace-package-invalid } }
    \msg_new:nnn { ctexhook } { replace-package-invalid }
      {
        \token_to_str:N \ctex_replace_package:nn \{#1\}\{#2\}~is~invalid~
        before~LaTeX~2020-10-01.
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_at_begin_package:nn}
% 如果宏包已经被载入,则钩子无效,给出警告。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_at_begin_package:nn #1
  {
    \@ifpackageloaded {#1}
      { \@@_package_loaded_warning:nn {#1} }
      { \ctex_gadd_package_hook:nnn { before } {#1} }
  }
\cs_new_protected:Npn \@@_package_loaded_warning:nn #1#2
  { \msg_warning:nnx { ctexhook } { invalid-hook } {#1} }
\msg_new:nnn { ctexhook } { invalid-hook }
  {
    Package~`#1'~is~loaded. \\
    \token_to_str:N \ctex_at_begin_package:nn \{#1\}\{...\}~is~invalid.
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_at_end_package:nn}
% 与 \pkg{filehook} 的 \tn{AtEndOfPackageFile*} 类似,如果原来没有在载入宏包则
% 在宏包末尾执行语句,否则立即执行。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_at_end_package:nn #1
  {
    \@ifpackageloaded {#1}
      { \use:n }
      { \ctex_gadd_package_hook:nnn { after } {#1} }
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.5.6}{2021/02/16}{使用正确的导言区末尾钩子。}
% \changes{v2.5.8}{2021/11/18}{兼容 \LaTeX \ 2021/11/15。}
%
% \LaTeX \ 2020/10/01 开始提供常用钩子管理机制。在新机制下,我们只需要做简单的包装。
%    \begin{macrocode}
\ctex_if_format_at_least:nTF { 2020/10/01 }
  {
    \cs_new_protected:Npx \ctex_gadd_ltxhook:nn #1
      { \hook_gput_code:nnn {#1} { \c_novalue_tl } }
    \cs_new_protected:Npn \ctex_at_end_preamble:n
      { \ctex_gadd_ltxhook:nn { begindocument/before } }
    \cs_new_protected:Npn \ctex_after_end_preamble:n
      { \ctex_gadd_ltxhook:nn { begindocument/end } }
    \cs_new_protected:Npx \ctex_gadd_package_hook:nnn #1#2
      {
        \ctex_if_format_at_least:nTF { 2021/11/15 }
          { \ctex_gadd_ltxhook:nn { package/#2/#1 } }
          { \ctex_gadd_ltxhook:nn { package/#1/#2 } }
      }
    \file_input_stop:
  }
  { }
%    \end{macrocode}
%
% 对于 \LaTeX \ 2020/10/01 之前的版本,需要自行补丁。
%
% \begin{macro}[int]{\ctex_at_end_preamble:n,\ctex_after_end_preamble:n}
% 实现 \pkg{etoolbox} 宏包的 \tn{AtEndPreamble} 和 \tn{AfterEndPreamble}。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_at_end_preamble:n
  { \tl_gput_right:Nn \g_@@_end_preamble_hook_tl }
\cs_new_protected:Npn \ctex_after_end_preamble:n
  { \tl_gput_right:Nn \g_@@_after_end_preamble_hook_tl }
\cs_new_protected:Npn \CTEX@document@left@hook
  { \group_end: \g_@@_end_preamble_hook_tl \group_begin: }
\cs_new_protected:Npn \CTEX@document@right@hook
  { \scan_stop: \g_@@_after_end_preamble_hook_tl \tex_ignorespaces:D }
\cs_set_nopar:Npx \document
  {
    \CTEX@document@left@hook
    \exp_not:o { \document }
    \CTEX@document@right@hook
  }
\tl_new:N \g_@@_end_preamble_hook_tl
\tl_new:N \g_@@_after_end_preamble_hook_tl
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_gadd_package_hook:nnn,
% \ctex_gadd_hook:Nn, \ctex_gadd_hook:cn}
% 给钩子附加内容。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_gadd_package_hook:nnn #1#2
  { \ctex_gadd_hook:cn { g_@@_at_ #1 _ #2 _hook_tl } }
\cs_new_protected:Npn \ctex_gadd_hook:Nn #1
  {
    \tl_if_exist:NF #1 { \tl_new:N #1 }
    \tl_gput_right:Nn #1
  }
\cs_generate_variant:Nn \ctex_gadd_hook:Nn { c }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_use_package_hook:nn}
% 宏包钩子,只执行一次,用后清除。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_use_package_hook:nn #1#2
  {
    \group_begin: \exp_args:NNc \group_end:
    \@@_use_package_hook_aux:N { g_@@_at_ #1 _ #2 _hook_tl }
  }
\cs_new_protected:Npn \@@_use_package_hook_aux:N #1
  { \cs_if_exist_use:NT #1 { \cs_undefine:N #1 } }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@reset@ptions,\CTEX@reset@ptions@hook}
% \tn{@pushfilename} 内部的 \tn{@currname} 和 \tn{@currext} 保存的是
% 前一个宏包的状态,不能使用。需要对其后的 \tn{@reset@ptions} 做补丁来实现
% \cs{ctex_at_begin_package:nn} 的功能。
%    \begin{macrocode}
\tl_put_right:Nn \@reset@ptions { \CTEX@reset@ptions@hook }
\cs_new_protected:Npn \CTEX@reset@ptions@hook
  {
    \cs_if_eq:NNT \@currext \@pkgextension
      { \ctex_use_package_hook:nn { before } { \@currname } }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\@popfilename,\CTEX@popfilename@hook}
% 对 \tn{@popfilename} 做补丁来实现 \cs{ctex_at_end_package:nn} 的功能。
%    \begin{macrocode}
\tl_put_left:Nn \@popfilename { \CTEX@popfilename@hook }
\cs_new_protected:Npn \CTEX@popfilename@hook
  {
    \cs_if_eq:NNT \@currext \@pkgextension
      { \ctex_use_package_hook:nn { after } { \@currname } }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</ctexhook>
%    \end{macrocode}
%
%
% \subsection{\pkg{ctexpatch} 宏包}
%
% \changes{v2.2}{2015/06/23}{新增子宏包 \pkg{ctexpatch} 实现给宏打补丁功能。}
%
%    \begin{macrocode}
%<*ctexpatch>
%    \end{macrocode}
%
% \begin{macro}[int]{\ctex_patch_cmd_once:NnnnTF}
% 只进行第一次匹配进行替换。参数 |#2| 是宏重建时的 \tn{catcode} 设置。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_patch_cmd_once:NnnnTF #1#2
  {
    \ctex_patch_boot:NNnnTF \@@_patch_cmd:Nnnnnw #1
      { once } {#2} { \use_i:nn } { \use_ii:nn }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_patch_cmd_all:NnnnTF}
% 替换所有匹配到的文本。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_patch_cmd_all:NnnnTF #1#2
  {
    \ctex_patch_boot:NNnnTF \@@_patch_cmd:Nnnnnw #1
      { all } {#2} { \use_i:nn } { \use_ii:nn }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_patch_cmd:Nnn}
% 快捷方式,在补丁的时候关闭 \LaTeXiii{} 语法和设置 |@| 为字母类,补丁失败时给出警告。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_patch_cmd:Nnn #1
  {
    \ctex_patch_boot:NNnnTF \@@_patch_cmd:Nnnnnw #1
      { once }
      {
        \ExplSyntaxOff
        \char_set_catcode_letter:n { 64 }
      }
      { }
      { \ctex_patch_failure:N #1 }
  }
\cs_new_protected:Npn \ctex_patch_failure:N #1
  { \msg_warning:nnx { ctexpatch } { patch-failure } { \token_to_str:N #1 } }
\msg_new:nnn { ctexpatch } { patch-failure }
  { Oops!~Command~`#1'~is~NOT~patchable.\\ }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_preto_cmd:NnnTF}
% 在宏的原本定义前面增加钩子。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_preto_cmd:NnnTF #1#2
  {
    \ctex_patch_boot:NNnnTF \@@_hookto_cmd:Nnnnw #1
      { left } {#2} { \use_i:nn } { \use_ii:nn }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_appto_cmd:NnnTF}
% 在宏的原本定义后面追加钩子。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_appto_cmd:NnnTF #1#2
  {
    \ctex_patch_boot:NNnnTF \@@_hookto_cmd:Nnnnw #1
      { right } {#2} { \use_i:nn } { \use_ii:nn }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_patch_boot:NNnnTF}
% 参数记号 |#| 作为宏的参数被读入时,总是会双写,会影响随后的字符串替换。需要先
% 将它转换为普通符号。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_patch_boot:NNnnTF #1#2#3#4#5#6
  {
    \cs_set_protected:Npx \@@_patch_true:w  { \exp_not:n {#5} }
    \cs_set_protected:Npx \@@_patch_false:w { \exp_not:n {#6} }
    \group_begin:
      \char_set_catcode_other:n { 35 }
      \ctex_parse_name:NN #1 #2 {#3} {#4}
  }
\cs_new_eq:NN \@@_patch_true:w  \use_i:nn
\cs_new_eq:NN \@@_patch_false:w \use_ii:nn
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\ctex_parse_name:NN}
% \changes{v2.4}{2016/04/11}{修复宏名解析错误。}
% 用 \tn{DeclareRobustCommand} 定义的宏或者由 \tn{newcommand} 或 \tn{newrobustcmd}
% 定义的带一个可选参数的宏第一次展开的结果都不是其实际定义,实际定义被保存在另外的
% 宏中。由这些命令定义的宏的第一次展开结果可以有下面的形式(细节可查阅 \pkg{xpatch}
% 的文档):
% \begin{verbatim}[numbers=left,gobble=4]
%   \protect␣\xaa␣␣                    % \DeclareRobustCommand\xaa[1]{...}
%   \protect␣\xab␣␣                    % \DeclareRobustCommand\xab[1][]{...}
%   \@protected@testopt␣\xac␣\\xac␣{}  % \newcommand\xac[1][]{...}
%   \@testopt␣\\xad␣{}                 % \newrobustcmd\xad[1][]{...}
%   \x@protect␣\1\protect␣\1␣␣         % \DeclareRobustCommand\1[1]{...}
%   \x@protect␣\2\protect␣\2␣␣         % \DeclareRobustCommand\2[1][]{...}
%   \@protected@testopt␣\3\\3␣{}       % \newcommand\3[1][]{...}
%   \@testopt␣\\4␣{}                   % \newrobustcmd\4[1][]{...}
% \end{verbatim}
% \pkg{ctexpatch} 的主要原理是先对宏的 \tn{meaning} 作字符串替换,然后再用
% \tn{scantokens} 来重建它。我们希望对宏的实际定义打补丁,为此需要先得到
% 对应的名字。\pkg{letltxmacro}、\pkg{show2e} 和 \pkg{xpatch} 宏包中都有
% 类似的工作。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_parse_name:NN #1#2
  { \ctex_parse_name:NNx #1#2 { \cs_to_str:N #2 } }
\group_begin:
\cs_set_protected:Npn \@@_tmp:w #1#2#3
  {
    \cs_new_protected:Npn \ctex_parse_name:NNn ##1##2##3
      {
        \bool_lazy_or:nnTF
          { \cs_if_exist_p:c { ##3 ~ } }
          { \cs_if_exist_p:c { #1##3 } }
          {
            \group_begin:
            \use:x
              {
                \group_end:
                \@@_parse_name:nNNNnN
                  { \cs_replacement_spec:N ##2 }
                  \exp_not:N ##2
                  \exp_not:c { ##3 ~ }
                  \exp_not:c { #1##3 }
              } { ##3 } ##1
          }
          { ##1##2 }
      }
    \cs_new_protected:Npn \@@_parse_name:nNNNnN ##1##2##3##4##5##6
      {
        \exp_args:Nc ##6
          {
            \str_case:nnTF {##1}
              {
                { \protect ##3 } { }
                { \x@protect ##2 \protect ##3 } { }
              }
              {
                \str_if_eq:eeTF
                  { \exp_not:n { #1@protected@ ##3 #1##3 } }
                  {
                    \exp_last_unbraced:Ne \@@_parse_name:w
                      { \cs_replacement_spec:N ##3 } #3 ~ #2 \q_stop
                  }
                  { #1##5 ~ } { ##5 ~ }
              }
              {
                \str_case:onTF { \@@_parse_name:w ##1 #3 ~ #2 \q_stop }
                  {
                    { #1@protected@ ##2 ##4 } { }
                    { #1@ ##4 } { }
                  }
                  { #1##5 } {##5}
              }
          }
      }
    \cs_new:Npn \@@_parse_name:w ##1 #3 ~ ##2 #2 ##3 \q_stop { ##1##2 }
  }
\use:x
  {
    \@@_tmp:w
      { \c_backslash_str }
      { \c_left_brace_str }
      { \tl_to_str:n { testopt } }
  }
\group_end:
\cs_generate_variant:Nn \ctex_parse_name:NNn { NNx }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}{\l_@@_prefix_str,\l_@@_parameter_str,\l_@@_replacement_str}
% 分别保存宏的 \tn{meaning} 中的前缀、参数文本和替换文本。
%    \begin{macrocode}
\str_new:N \l_@@_prefix_str
\str_new:N \l_@@_parameter_str
\str_new:N \l_@@_replacement_str
%    \end{macrocode}
% \end{variable}
%
% \begin{macro}[int]{\ctex_get_macro_meaning:NTF}
% \begin{macro}{\@@_get_macro_meaning:w}
% 解构待补丁宏的 \tn{meaning}。若命令不是宏,则走向 |false| 分支。
%    \begin{macrocode}
\group_begin:
  \cs_set_protected:Npn \@@_tmp:w #1
    {
      \prg_new_protected_conditional:Npnn
        \ctex_get_macro_meaning:N ##1 { TF }
        {
          \exp_after:wN \@@_get_macro_meaning:w
            \token_to_meaning:N ##1 \q_mark #1 -> \q_mark \q_stop
        }
      \cs_new_protected:Npn \@@_get_macro_meaning:w
          ##1 #1 ##2 -> ##3 \q_mark ##4 \q_stop
        {
          \tl_if_empty:nTF { ##4 }
            { \prg_return_false: }
            {
              \str_set:Nn \l_@@_prefix_str      { ##1 }
              \str_set:Nn \l_@@_parameter_str   { ##2 }
              \str_set:Nn \l_@@_replacement_str { ##3 }
              \prg_return_true:
            }
        }
    }
  \exp_args:No \@@_tmp:w { \tl_to_str:n { macro: } }
\group_end:
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}[int]{\ctex_if_rescanable:NnTF}
% 检查宏是否可以重建。
%    \begin{macrocode}
\cs_new_protected:Npn \ctex_if_rescanable:NnTF #1#2#3#4
  {
    \ctex_get_macro_meaning:NTF #1
      {
        \@@_patch_rebuild:Nn \@@_rebuild_cmd:w {#2}
        \cs_if_eq:NNTF #1 \@@_rebuild_cmd:w {#3} {#4}
      }
      {#4}
  }
\cs_new_eq:NN \@@_rebuild_cmd:w \prg_do_nothing:
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_patch_rebuild:Nn}
% 使用 \cs{tl_rescan:nn} 来重新记号化 \tn{meaning} 字符串。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_patch_rebuild:Nn #1#2
  {
    \@@_patch_rescan:NNn \l_@@_prefix_tl      \l_@@_prefix_str      {#2}
    \@@_patch_rescan:NNn \l_@@_parameter_tl   \l_@@_parameter_str   {#2}
    \@@_patch_rescan:NNn \l_@@_replacement_tl \l_@@_replacement_str {#2}
    \use:x
      {
        \exp_not:o { \l_@@_prefix_tl } \tex_def:D \exp_not:N #1
          \exp_not:o { \l_@@_parameter_tl }
            { \exp_not:o { \l_@@_replacement_tl } }
      }
  }
\cs_new_protected:Npn \@@_patch_rescan:NNn #1#2#3
  {
    \str_if_empty:NTF #2
      { \tl_clear:N #1 }
      { \tl_set_rescan:Nno #1 {#3} {#2} }
  }
\tl_new:N \l_@@_prefix_tl
\tl_new:N \l_@@_parameter_tl
\tl_new:N \l_@@_replacement_tl
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_patch_cmd:Nnnnnw}
% 对宏的替换文本进行字符串替换,然后重建。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_patch_cmd:Nnnnnw #1#2#3#4#5
  {
    \group_end:
    \ctex_if_rescanable:NnTF #1 {#3}
      {
        \use:x
          {
            \@@_patch_replace:nnnTF {#2}
              { \tl_to_str:n {#4} }
              { \tl_to_str:n {#5} }
          }
          {
            \@@_patch_rebuild:Nn #1 {#3}
            \@@_patch_true:w
          }
          { \@@_patch_false:w }
      }
      { \@@_patch_false:w }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_patch_replace:nnnTF}
% 替换前先检查原文本是否存在。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_patch_replace:nnnTF #1#2#3#4
  {
    \tl_if_in:NnTF \l_@@_replacement_str {#2}
      { \use:c { tl_replace_ #1 :Nnn } \l_@@_replacement_str {#2} {#3} #4 }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_hookto_cmd:Nnnnw}
% 在宏的前/后附加钩子。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_hookto_cmd:Nnnnw #1#2#3#4
  {
    \group_end:
    \ctex_get_macro_meaning:NTF #1
      {
        \str_if_empty:NTF \l_@@_parameter_str
          { \@@_hookto_cmd_parameterless:Nnnnw }
          { \@@_hookto_cmd_parameter:Nnnnw }
          #1 {#2} {#3} {#4}
      }
      { \@@_patch_false:w }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_hookto_cmd_parameterless:Nnnnw}
% 如果宏没有参数,可以直接进行附加操作。注意保持宏的前缀。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_hookto_cmd_parameterless:Nnnnw #1#2#3#4
  {
    \str_if_empty:NF \l_@@_prefix_str
      { \tl_rescan:no {#3} { \l_@@_prefix_str } }
    \tex_edef:D #1
      {
        \use:c { @@_ #2 _hook_aux:nn }
          { \exp_not:o {#1} }
          { \exp_not:n {#4} }
      }
    \@@_patch_true:w
  }
\cs_generate_variant:Nn \tl_rescan:nn { no }
\cs_new:Npn \@@_left_hook_aux:nn #1#2 { #2#1 }
\cs_new_eq:NN \@@_right_hook_aux:nn \use:nn
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_hookto_cmd_parameter:Nnnnw}
% 如果宏有参数,需要在字符串中进行附加,然后再重建。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_hookto_cmd_parameter:Nnnnw #1#2#3#4
  {
    \@@_patch_rebuild:Nn \@@_rebuild_cmd:w {#3}
    \cs_if_eq:NNTF #1 \@@_rebuild_cmd:w
      {
        \use:c { str_put_ #2 :Nn } \l_@@_replacement_str {#4}
        \@@_patch_rebuild:Nn #1 {#3}
        \@@_patch_true:w
      }
      { \@@_patch_false:w }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</ctexpatch>
%    \end{macrocode}
%
% \end{implementation}
%
% \Finale
%
\endinput