summaryrefslogtreecommitdiff
path: root/macros/xetex/latex/hanzibox/hanzibox.dtx
blob: e3099aba20fc3a89dcc633207a4ccf7427b17fe1 (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
% \iffalse meta-comment
% !TEX program  = XeLaTeX
%<*internal>
\iffalse
%</internal>
%<*readme>
hanzibox
LaTeX3-based Chinese Character package
=======

`hanzibox` is a LaTeX package developed in LaTeX3, which provides `\hanzibox` and `\hanzidialog` macros. These two macros are used for typesetting Chinese character with or without a background grid such as a cross grid or star grid for Chinese character writting learning.

And you can display the Hanyu Pinyin above the Chinese character and the translation below them as needed.

The `\hanzibox` macro can automatically invoke the `\xpinyin*` macro of the `xpinyin` package to get Hanyu Pinyin according to the Chinese characters.  And the `\hanzibox` macro provides an asterisk version of `\hanzibox*`, whose function is achieved by automatically invoking the `xpinyin` package's `\pinyin` macro to get Hanyu Pinyin. The `\hanzidialog` macro is implemented by manually inserting the `\pinyin` macro of the `xpinyin` package in it's pinyin option.

`hanzibox` is a utility for learning to write and pronounce Chinese characters, and can be used for Chinese character learning plans, presentations, exercise booklets and other documentation work.

The development of this package was inspired by [Jan Vorisek's hanzibox package](https://github.com/janvorisek/chinese-latex-utilities).

However, the new package redesigned the `\hanzibox` and `\hanzidialog` macros and the background grid is redesigned with the `l3draw` package by reference to [zitie package](https://www.ctan.org/pkg/zitie).  Also, the new package provides more options and arguments in order to get better results.

The `hanzibox.sty` package currently only supports the XeTeX engine and only supports UTF-8 encoded LaTeX source files.

You can read the manual (in Chinese) for more details and examples.

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

1. Gitee repository: [hanzibox-l3](https://gitee.com/nwafu_nan/hanzibox-l3)
2. Issues and pull requests are welcome. [issue](https://gitee.com/nwafu_nan/hanzibox-l3/issues) or [pull request](https://gitee.com/nwafu_nan/hanzibox-l3/pulls).

hanzibox
基于LaTeX3的汉字练习宏包
=======

`hanzibox`是一个用LaTeX3开发的LaTeX宏包,它提供了`\hanzibox`和`\hanzidialog` 两个命令。这两个命令分别用于排版汉字学习中带有或不带田字格、米字格等背景格子的汉字,并可以根据需要在汉字正上方显示拼音,在正下方显示译文。其中,`\hanzibox`命令能够根据汉字自动调用`xpinyin`宏包的`\xpinyin*`命令实现汉字注音。并且`\hanzibox`命令提供了`\hanzibox*`星号版本,其注音功能是通过自动调用`xpinyin`宏包的`\pinyin`命令实现的。`\hanzidialog`命令的注音功能是通过在拼音选项中手动插入`xpinyin`宏包`\pinyin`命令实现的。

`hanzibox` 是一个用于学习汉字书写与发音的工具,可以用于汉字学习教案、演示文稿、习题册等文档工作。

该宏包的开发灵感源自[Jan Vorisek的hanzibox宏包](https://github.com/janvorisek/chinese-latex-utilities)。但对`\hanzibox`和`\hanzidialog`命令重新进行了设计,并参考[zitie字贴宏包](https://www.ctan.org/pkg/zitie)重新用`l3draw`宏包设计了背景格子。同时,新的宏包也提供了更多命令选项和参数,以期更好地控制排版结果。

目前,`hanzibox.sty`宏包仅支持XeTeX编译引擎,并且只支持UTF-8编码的LaTeX源文件。

可以通过阅读宏包手册(中文)以也解该宏包更多的使用细节和使用样例。

###  参与贡献
---------------------
1. 本项目由西北农林科技大学信息工程学院耿楠创建和维护
2. 如果您愿意一同参与工作(不计报酬,免费自由),请及时与作者联系
3. 项目的gitee仓库地址:[hanzibox-l3](https://gitee.com/nwafu_nan/hanzibox-l3)
4. 如果您有任何改进意见或者功能需求,欢迎提交 [issue](https://gitee.com/nwafu_nan/hanzibox-l3/issues) 或 [pull request](https://gitee.com/nwafu_nan/hanzibox-l3/pulls)。

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

    Copyright (C) 2020-2021 by Nan Geng <nangeng@nwafu.edu.cn>
    ----------------------------------------------------------------------

    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".

    The Current Maintainer of this work is Nan Geng.

    This package consists of the file  hanzibox.dtx,
                 and the derived files hanzibox.sty,
                                       hanzibox.pdf,
                                       hanzibox.ins,
                                       README.md (this file).

%</readme>
%<*internal>
\fi
\begingroup
  \def\temp{LaTeX2e}
\expandafter\endgroup\ifx\temp\fmtname\else
\csname fi\endcsname
%</internal>
%<*install>

\input ctxdocstrip %

\let\MetaPrefix\relax

\preamble

    Copyright (C) 2020-2021 by Nan Geng <nangeng@nwafu.edu.cn>
--------------------------------------------------------------------------

    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".

    The Current Maintainer of this work is Nan Geng.

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

\endpreamble

\postamble

    This package consists of the file  hanzibox.dtx,
                 and the derived files hanzibox.sty,
                                       hanzibox.pdf,
                                       hanzibox.ins,
                                       README.md.
\endpostamble

\declarepostamble\emptypostamble
\endpostamble

\def\MetaPrefix{-- }


\let\MetaPrefix\DoubleperCent

\generate
  {
%</install>
%<*internal>
    \usedir{source/xelatex/hanzibox}
    \file{hanzibox.ins} {\from{\jobname.dtx}{install}}
%</internal>
%<*install>
    \usedir{xetex/xelatex/hanzibox}
    \file{hanzibox.sty} {\from{\jobname.dtx}{package}}
    \nopreamble\nopostamble
    \usedir{doc/xelatex/hanzibox}
    \file{README.md}   {\from{\jobname.dtx}{readme}}
  }

\endbatchfile
%</install>
%<*internal>
\fi
%</internal>
%<package>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
%<package>\RequirePackage{expl3}
%<+package>\GetIdInfo$Id: hanzibox.dtx 2.1.0 2021-09-30 08:00:00 +0800 Nan Geng <nangeng@nwafu.edu.cn> $
%<package>  {Boxed Chinese characters with Pinyin above and translation below.}
%<package>\ProvidesExplPackage{\ExplFileName}
%<package>  {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
%<*driver>
\documentclass{ctxdoc}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{xcolor-material}
\usepackage{hanzibox}
\renewcommand*\marg[1]{\{\meta{#1}\}}
\renewcommand*\oarg[1]{[\meta{#1}]}
\renewcommand*\parg[1]{(\meta{#1})}
\NewDocumentCommand{\init}{+v}{\hspace{\fill}初始值~=~\textcolor{blue}{\bfseries#1}}
\DeclareDocumentCommand\opt{m}{\texttt{#1}}
\DeclareDocumentCommand\kvopt{mm}
  {\texttt{#1\breakablethinspace=\breakablethinspace#2}}
\def\breakablethinspace{\hskip 0.16667em\relax}
\begin{document}
  \DisableImplementation
  \EnableImplementation
  \DocInput{\jobname.dtx}
  \IndexLayout
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \changes{v1.0.0}{2021/09/18}{开始编写模板}
% \changes{v2.0.0}{2021/09/25}{基于l3draw重新设计}
% \changes{v2.0.0}{2021/09/28}{重新编写README.md内容}
%
% \CheckSum{1043}
% \GetFileId{hanzibox.sty}
%
% \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         \~}
%
%
% \title{\bfseries\pkg{hanzibox}:田字格-米字格汉字练习宏包}
% \author{耿楠\\ \path{nangeng@nwafu.edu.cn}}
% \date{\filedate\qquad\fileversion\thanks{\url{https://gitee.com/nwafu_nan/hanzibox-l3}.}}
% \maketitle
%
% \changes{v2.0.0}{2021/09/28}{修订说明文档}
%
% \begin{documentation}
%
% \begin{abstract}
%
% \pkg{hanzibox} 是一个用\LaTeX3开发的 \LaTeX 宏包,它提供了\tn{hanzibox}和\tn{hanzidialog}
% 两个命令。这两个命令用于输出汉字学习中带有或不带田字格、米字格等背景格子的汉字,
% 并可以根据需要在汉字正上方显示拼音,在正下方显示译文。
% 其中,\tn{hanzibox}命令能够根据汉字利用\pkg{xpinyin}宏包实现汉字注音。
% 同时,\tn{hanzibox}命令还提供了\tn{hanzibox*}星号版本,以实现手动注音功能。
% \tn{hanzidialog}命令的注音功能则是通过在其拼音选项中手动插入
% \pkg{xpinyin}宏包的\tn{pinyin}命令实现。
%
% \end{abstract}
%
% \section{简要说明}
%
% \pkg{hanzibox} 是一个用于输出汉字学习中的田字格、米字格等背景,并在汉字正上方显示拼音,
% 在正下方显示译文。当然,也可以根据需要隐藏拼音、汉字或译文,还可以选择性地隐藏拼音中的
% 声母、韵母或音调,从而有效实现汉字学习中的素材准备。
%
% 使用\pkg{hanzibox}宏包的\LaTeX 源文件需采用 \texttt{UTF-8}编码,并且需使用\XeLaTeX 进行编译。
%
% \pkg{hanzibox} 依赖 \package{l3kernel} 、\package{l3packages}、\package{l3draw}和\package{xpinyin}宏包。
%
% \section{用户接口}
%
% \begin{function}[added=2021-09-18,updated=2021-09-30]{\hanzibox,\hanzibox*}
%   \begin{syntax}
%     \tn{hanzibox}  \oarg{外观选项} \Arg{汉字} \oarg{拼音选项} \oarg{译文选项}
%     \tn{hanzibox*} \oarg{外观选项} \Arg{汉字} \oarg{拼音选项} \oarg{译文选项}
%   \end{syntax}
%   排版汉字,并根据选项内容在顶部排版拼音,在底部排版译文。\\
%   其中,\Arg{汉字}可以留空,\oarg{外观选项}用于设置盒子外观;
%   \tn{hanzibox}命令中的\oarg{拼音选项}无效,可以省略,也可以留空;
%   \oarg{译文选项}可以是任意文本,需要注意的是,当需要\oarg{译文选项}时,
%   \oarg{拼音选项}可以留空,但不能省略。
%   注音由\pkg{xpinyin}宏包自动根据汉字获得,此时,可能会存在多音字等问题,
%   其调整详情请参阅\pkg{xpinyin}宏包说明。星号命令\tn{hanzibox*}用于手动排版拼音。
%
%   排版样式可通过\tn{hanziboxset}命令或\tn{hanzibox}\oarg{外观选项}的key-value进行设置。
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.40\linewidth,gobble=5]
%     \centering
%     \hanziboxset{fillcolor=yellow!30, charcolor=red,
%       xscale=1.5,yscale=1.5,resize=real,framecolor=red}
%     \hanzibox[frametype=none]{我}
%     \hanzibox[frametype=口  ]{我}[][吾]
%     \hanzibox[frametype=十  ]{我}[wo3][俺]
%     \hanzibox[frametype=×   ]{我}[wo2][爷]
%     \hanzibox[frametype=田  ]{我}[wo1][愚]
%     \hanzibox[frametype=米  ]{我}[ni3][奴]
%     \hanzibox[frametype=咪  ]{我}[ta1][山人]
%   \end{SideBySideExample}
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.40\linewidth,gobble=5]
%     \centering
%     \hanziboxset{xscale=1.5,yscale=1.5,resize=real}
%     \hanzibox*[frametype=none]{我}[wo3][me]
%     \hanzibox*[frametype=口  ]{我}[wo3][吾]
%     \hanzibox*[frametype=十  ]{我}[wo3][俺]
%     \hanzibox*[frametype=×   ]{我}[wo3][爷]
%     \hanzibox*[frametype=田  ]{我}[wo2][愚]
%     \hanzibox*[frametype=米  ]{我}[ni3][奴]
%     \hanzibox*[frametype=咪  ]{我}[ta5][山人]
%   \end{SideBySideExample}
% \end{function}
%
% \begin{function}[added=2021-09-18,updated=2021-09-28]{\hanzidialog}
%   \begin{syntax}
%     \tn{hanzidialog} \oarg{外观选项} \Arg{汉字} \oarg{拼音选项} \oarg{译文选项}
%   \end{syntax}
%   排版汉字,并根据选项内容在顶部排版拼音,在底部排版译文。\\
%   其中,\Arg{汉字}可以留空,\oarg{拼音选项}可以是任意文本;\oarg{译文选项}可以是任意文本。
%   \oarg{拼音选项}和\oarg{译文选项}都可以留空,也可以省略,
%   但当需要\oarg{译文选项}时,\oarg{拼音选项}可以留空,不能省略。
%   如果是汉语拼音则需要手动使用\pkg{xpinyin}宏包的\tn{pinyin}命令,
%   排版样式可能通过\tn{hanziboxset}命令或\tn{hanzidialog}\oarg{外观选项}的key-value进行设置。
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.25\linewidth,gobble=5]
%     \centering
%     \hanzidialog{王老师}[Wang \pinyin{lao3shi1}][teacher wang]
%
%     \hanzidialog[frametype=田]{王老师}[Wang \pinyin{lao3shi1}]
%                 [王先生]
%
%     \hanzidialog[height=1cm,frametype=咪,framecolor=red,resize=real]
%                 {王老师}[Wang \pinyin{lao3shi1}][王先生]
%
%   \end{SideBySideExample}
% \end{function}
%
% \begin{function}[added=2021-09-20,updated=2021-09-24]{\hanziboxset}
%   \begin{syntax}
%     \tn{hanziboxset} \marg{键值列表}
%   \end{syntax}
%   \tn{hanziboxset} 的参数是一组由(英文)逗号隔开的选项列表,
%   列表中的选项通常是 \kvopt{\meta{key}}{\meta{value}} 形式。
%   部分选项的\meta{value} 可以省略。对于同一项,后续设置会覆盖以前的设置。
%   在下文的说明中,多数选项都设有默认值。
%
%   \tn{hanziboxset} 采用 \LaTeX3 风格的键值设置,支持不同类型以及多种
%   层次的选项设定。键值列表中,“|=|”左右的空格不影响设置;但需注意,
%   参数列表中\textbf{不可以出现空行}。
%
%   布尔型的参数 \kvopt{\meta{选项}}{true} 中的“|= true|”可以省略。
% \end{function}
%
% \section{选项说明}
%
%   本宏包提供了一系列选项,以实现汉字盒子外观样式设置。
%   载入\pkg{hanzibox}宏包后,以下选项均可通过统一命令\tn{hanziboxset}进行设置。
%   同时,这些选项也可以通过\tn{hanzibox}或\tn{hanzidialog}命令的\oarg{外观选项}进行设置。
%
% \begin{function}[added=2021-09-24,updated=2021-09-24]{basechar,zihao}
%   \begin{syntax}
%     basechar = \meta{CJK char} \init{好}
%     zihao    = \meta{字号}     \init{4}
%   \end{syntax}
%   \opt{basechar} 设置基字符,用于计算缩放比例,
%   基字符不同时,即使给定相同的缩放比例,其实际缩放比例也可能不同。
% 
%   \opt{zihao} 设置计算缩放比例时字号大小。
% \end{function}
%
% \begin{function}[added=2021-09-27,updated=2021-09-28]{pinyinf,charf,tranf}
%   \begin{syntax}
%     pinyinf = \meta{格式命令}   \init{\normalsize}
%     charf   = \meta{格式命令}   \init{\tiny}
%     tranf   = \meta{格式命令}   \init{\tiny}
%   \end{syntax}
%   分别用于设置拼音、汉字、译文的排版格式。
% \end{function}
%
% \begin{function}[added=2021-09-24,updated=2021-09-24]{frametype,resize}
%  \begin{syntax}
%    frametype = <none|口|十|田|米|咪> \init{none}
%    resize    = <none|real|base> \init{none}
%  \end{syntax}
%  \opt{frametype} 设置汉字盒子样式。可用值的效果与选项值文字形状类似:\verb|口|--仅方框,
%  \verb|十|--仅中间的横线和竖线,\verb|田|--常见的田字格,\verb|米|--十字格再加上斜的两条对角线,
%  \verb|咪|--常见的米字格。
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.50\linewidth,gobble=5]
%     \centering
%     \hanzibox[frametype=none]{无}
%     \hanzibox[frametype=口  ]{口}
%     \hanzibox[frametype=十  ]{十}
%     \hanzibox[frametype=田  ]{田}
%     \hanzibox[frametype=米  ]{米}
%     \hanzibox[frametype=咪  ]{咪}
%   \end{SideBySideExample}
%
%  \opt{resize} 设置缩放方式,\opt{real}--使用字符实际宽高缩放,
%  \opt{base}--使用 \opt{basechar} 设置的字符的宽高缩放,
%
%  以下为宽度设置为 1cm 时的缩放情况。
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=5]
%     \centering
%     \hanziboxset{width=1cm,frametype=咪,
%                  framecolor=black}
%     \hanzibox[resize=none  ]{无}
%     \hanzibox[resize=real  ]{实}
%     \hanzibox[resize=base  ]{基}
%   \end{SideBySideExample}
% \end{function}
%
% \begin{function}[added=2021-09-24,updated=2021-09-24]{
%   xscale,yscale,scale,
%   width,height}
%   \begin{syntax}
%     xscale = \meta{scale ratio} \init{1}
%     yscale = \meta{scale ratio} \init{1}
%     scale  = \meta{scale ratio}
%     width  = \meta{dim}
%     height = \meta{dim}
%   \end{syntax}
%   设置缩放比例和盒子宽高。
%
%   宽高具有更高的优先级,即若比例和宽高都设置了,则使用宽高来计算。
%   宽高都为0cm视为未设置,二者有一大于0cm,视为设置了宽高。
%
%   此处的宽高和最终的宽高可能略有差异,最终的宽高保存在
%   \tn{hanziboxwidth} 和 \tn{hanziboxheight} dim寄存器中。
% \end{function}
%
% \begin{function}[added=2021-09-24,updated=2021-09-24]{
%   linewidth,
%   dashpattern,
%   framearc,
%   framearc*
%   }
%   \begin{syntax}
%     linewidth   = \meta{dim} \init{0.4pt}
%     dashpattern = \meta{ dim1, dim2, ... }
%     framearc    = \meta{dim}
%     framearc*   = \{ \marg{dim1} \marg{dim2} \}
%   \end{syntax}
%   设置边框线宽、线型、转角样式。
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.28\linewidth,gobble=5]
%     \centering
%     \hanziboxset{width=1.0cm,resize=real,framecolor=red}
%     \hanzibox[linewidth=1pt,frametype=口]{好}
%     \hanzibox[dashpattern={1.5mm,1mm,2mm,1.5mm},frametype=田]{好}
%     \hanzibox[framearc=1mm,frametype=口]{好} \\
%     \hanzibox[framearc=1mm,frametype=咪]{好}
%     \hanzibox[framearc*={1mm}{2mm},frametype=口]{好}
%     \hanzibox[framearc*={2mm}{1mm},frametype=咪]{好}
%   \end{SideBySideExample}
% \end{function}
%
% \begin{function}[added=2021-09-24,updated=2021-09-24]{
%   framecolor,
%   framecolor*,
%   charcolor,
%   charcolor*,
%   fillcolor,
%   fillcolor*
%   }
%   \begin{syntax}
%     framecolor  = \meta{color expr} \init{black}
%     framecolor* = \meta{model(s)} \meta{value(s)}
%     charcolor   = \meta{color expr} \init{black}
%     charcolor*  = \meta{model(s)} \meta{value(s)}
%     fillcolor   = \meta{color expr}
%     fillcolor*  = \meta{model(s)} \meta{value(s)}
%   \end{syntax}
%   分别设置格子线条、字符和填充颜色。
%   颜色名称仅支持 \LaTeX3 定义的 black, white, red, green, blue, cyan, magenta 和 yellow。
%   颜色模型和表达式也应使用 \LaTeX3 支持的模型和表达式,详见 \pkg{interface3.pdf} 文档。
%
%   若要去掉 \opt{fillcolor},应将其置为空(\verb|fillcolor={}|),而不是将其设置为white(白色)。
% \end{function}
%
% \begin{function}[added=2021-09-24,updated=2021-09-24]{initial,vowel,tone}
%   \begin{syntax}
%     initial = <\TTF> \init{true}
%     vowel   = <\TTF> \init{true}
%     tone    = <\TTF> \init{true}
%   \end{syntax}
%   分别用于设置是否输出拼音的声母、韵母和声调,默认值为\textbf{true}。
%   该选项仅对\tn{hanzibox}命令有效。
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.33\linewidth,gobble=5]
%     \centering
%     \hanziboxset{frametype=咪,framecolor=red,
%                  fillcolor=yellow!40,resize=real}
%     \hanzibox{明月几时有}[]
%       [How long will the full moon appear?]\\[0.5ex]
%     \hanzibox[initial=false]{明月几时有}[]
%       [How long will the full moon appear?]\\[0.5ex]
%     \hanzibox[vowel=false]{明月几时有}[]
%       [How long will the full moon appear?]\\[0.5ex]
%     \hanzibox[tone=false]{明月几时有}[]
%       [How long will the full moon appear?]\\[0.5ex]
%     \hanzibox[initial=false,vowel=false]{明有几时有}
%       [][How long will the full moon appear?]
%   \end{SideBySideExample}
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.28\linewidth,gobble=5]
%     \centering
%     \hanziboxset{frametype=咪,framecolor=red,fillcolor=yellow!40,
%                  charf=\Huge,resize=real}
%     \hanzibox*[initial=false]{我}[wo3][吾]
%     \hanzibox*[initial=true,vowel=false]{我}[wo3][吾]
%     \hanzibox*[initial=true,vowel=true,tone=false]{我}[wo3][不才]
%   \end{SideBySideExample}
% \end{function}
%
% \begin{function}[added=2021-09-21,updated=2021-09-26]{pinyin,hanzi,tran}
%   \begin{syntax}
%     pinyin = <\TTF> \init{true}
%     hanzi = <\TTF>  \init{true}
%     tran = <\TTF>   \init{true}
%   \end{syntax}
%   分别用于设置是否输出拼音、汉字和译文,默认值为\textbf{true}。
%   该选项对\tn{hanzidialog}命令无效。
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.33\linewidth,gobble=5]
%     \centering
%     \hanziboxset{frametype=咪,framecolor=red,charf=\large,
%                  fillcolor=yellow!40}
%     \hanzibox[pinyin=false]{明月几时有}[]
%       [How long will the full moon appear?]\\[0.5ex]
%     \hanzibox[hanzi=false]{明月几时有}[]
%       [How long will the full moon appear?]\\[0.5ex]
%     \hanzibox[tran=false]{明月几时有}[]
%       [How long will the full moon appear?]\\[0.5ex]
%   \end{SideBySideExample}
% \end{function}
%
% \changes{v2.0.0}{2021/09/28}{在说明文档中添加应用实例}
%
% \section{应用实例}
%
% \pkg{hanzibox}宏包可以广泛用于汉字学习的练习中。
%
% \subsection{拼一拼---写一写练习}
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=5]
%     \centering
%     \hanziboxset{frametype=田,framecolor=blue}
%     \hanzibox{门}\hanzibox[hanzi=false]{口}\hfill
%     \hanzibox{生}\hanzibox[hanzi=false]{日}\hfill
%     \hanzibox{题}\hanzibox[hanzi=false]{目}\hfill
%     \hanzibox[hanzi=false]{田}\hanzibox{野}
%   \end{SideBySideExample}
%
% \subsection{标注声母练习}
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.35\linewidth,gobble=5]
%     \centering
%     \hanziboxset{frametype=咪,framecolor=red,charcolor=red,
%                  charf=\Huge,pinyinf=\small,initial=false}
%     \hanzibox{门口}\hfill
%     \hanzibox{生日}\\
%     \hanzibox{题目}\hfill
%     \hanzibox{田野}
%   \end{SideBySideExample}
%
% \subsection{标注韵母练习}
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.35\linewidth,gobble=5]
%     \centering
%     \hanziboxset{frametype=咪,framecolor=red,charcolor=red,
%                  charf=\Huge,pinyinf=\small,vowel=false}
%     \hanzibox{门口}\hfill
%     \hanzibox{生日}\\
%     \hanzibox{题目}\hfill
%     \hanzibox{田野}
%   \end{SideBySideExample}
%
% \subsection{标注声调练习}
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.35\linewidth,gobble=5]
%     \centering
%     \hanziboxset{frametype=咪,framecolor=red,charcolor=red,
%                  charf=\Huge,pinyinf=\small,tone=false}
%     \hanzibox{门口}\hfill
%     \hanzibox{生日}\\
%     \hanzibox{题目}\hfill
%     \hanzibox{田野}
%   \end{SideBySideExample}
%
% \subsection{随机生成生词练习}
%
% 假设提前准备了生词表\verb!\clist_set:Nn \l__words_clist!,则可以使用
% \LaTeX3的随机函数随机生成生词练习题(每次编译可以得到不同的结果)。
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.30\linewidth,gobble=5]
%     \ExplSyntaxOn
%     \clist_set:Nn \l__words_clist
%       {
%         {铅笔} , {橡皮} , {报纸} ,
%         {头发} , {耳朵} , {眼睛} ,
%         {大象} , {蚂蚁} , {松鼠} ,
%         {男孩} , {同学} , {兄弟} ,
%         {学生} , {医生} , {护士} ,
%         {老师} , {警察} , {羊肉} ,
%         {窗户} , {镜子} , {沙发}
%       }
%     \hanziboxset{frametype=咪,framecolor=red,charcolor=red,
%                  charf=\huge,pinyinf=\footnotesize,hanzi=false}
%     \centering
%     \int_step_inline:nn {6}
%       {
%         \hanzibox{\clist_rand_item:N \l__words_clist}\\
%       }
%     \ExplSyntaxOff
%   \end{SideBySideExample}
%
% \subsection{随机生成拼音练习}
%
% 假设提前准备了声母和韵母表,则可以使用
% \LaTeX3的随机函数随机生成拼音练习题(每次编译可以得到不同的结果)。
% 此时,若生成的拼音不正确,可让学生填写“无”。
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.25\linewidth,gobble=5]
%     \ExplSyntaxOn
%     \int_new:N \l__tone_int
%     \clist_set:Nn \l__initials_clist
%       {
%         {zh} , {ch} , {sh} , {b} , {p} , {m} , {f} ,
%         {d}  , {t}  , {n}  , {l} , {g} , {k} , {h} ,
%         {j}  , {q}  , {x}  , {r} , {z} , {c} , {s} ,
%         {y}  , {w}
%       }
%     \clist_set:Nn \l__vowel_clist
%       {
%         {iang} , {iong} , {uang} , {ueng} , {ang} , {eng} , {ing} ,
%         {ong}  , {uai}  , {uan}  , {uai}  , {uei} , {iao} , {iou} ,
%         {ian}  , {van}  , {uen}  , {ai}   , {ei}  , {ua}  , {uo}  ,
%         {ui}   , {ao}   , {ou}   , {iu}   , {ie}  , {ve}  , {er}  ,
%         {an}   , {en}   , {in}   , {un}   , {vn}  , {a}   , {e}   ,
%         {i}    , {o}    , {u}    , {v}
%       }
%     \hanziboxset{frametype=咪,framecolor=red,charcolor=red,
%                  charf=\huge,pinyinf=\footnotesize,hanzi=false}
%     \centering
%     \int_step_inline:nn {10}
%       {
%         \int_zero:N \l__tone_int
%         \int_set:Nn \l__tone_int {\int_rand:n {5}}
%         \hanzibox*{好}[
%           \clist_rand_item:N \l__initials_clist
%           \clist_rand_item:N \l__vowel_clist
%           \int_use:N \l__tone_int
%          ]\\
%       }
%     \ExplSyntaxOff
%   \end{SideBySideExample}
%
% \subsection{生成汉字书写练习格子纸}
%
% 可以通过将\tn{hanzibox}命令的\Arg{汉字}参数留空,
% 或将\tn{hanzibox}、\tn{hanzibox*}命令的\verb!hanzi!选项置为
% \verb!false!(\verb!hanzi=false!),从而生成空白背景格子,
% 再根据需要通过循环的方式生成指定行数和列数的
% 汉字书写练习用格子纸。
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.50\linewidth,gobble=5]
%     \hanziboxset{frametype=咪,framecolor=red,
%        charcolor=red,charf=\huge}
%     \centering
%     \ExplSyntaxOn
%     \int_step_inline:nn {8}
%       {
%         \int_step_inline:nn {6}
%           {
%             \hanzibox{}
%             \hspace*{-0.4pt}
%           }
%         \par\nointerlineskip\vspace*{-6.0pt}
%      }
%     \ExplSyntaxOff
%   \end{SideBySideExample}
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.50\linewidth,gobble=5]
%     \hanziboxset{frametype=咪,framecolor=red,
%        charcolor=red,charf=\huge,hanzi=false}
%     \centering
%     \ExplSyntaxOn
%     \int_step_inline:nn {8}
%       {
%         \int_step_inline:nn {6}
%           {
%             \hanzibox*{国}
%             \hspace*{-0.4pt}
%           }
%         \par\nointerlineskip\vspace*{-6.0pt}
%      }
%     \ExplSyntaxOff
%   \end{SideBySideExample}
%
% \subsection{生成诗词注音}
%
% 可以通过自动注音生成带有注音的诗词排版,
% 但当有多音字时,需要使用\pkg{xpinyin}宏包的\tn{setpinyin}命令
% 为多音字设置正确的读音。
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.50\linewidth,gobble=5]
%     \setpinyin{长}{chang2}
%     \setpinyin{尽}{jin4}
%     \hanziboxset{frametype=咪,framecolor=red,
%       charf=\huge,pinyinf=\footnotesize,
%       charcolor=green!40!black}
%     \centering
%     \hanzibox{故人西辞黄鹤楼}
%     \hanzibox{烟花三月下扬州}
%     \hanzibox{孤帆远影碧空尽}
%     \hanzibox{唯见长江天际流}
%   \end{SideBySideExample}
%
% \subsection{诗词手动注音}
%
% 也可以使用\tn{hanzibox*}命令实现诗词手动注音,
% 此时,可以通过留空拼音或文字构成注音或根据拼音写汉字练习。
% 但需要注意,目前只能在一行文本的尾部实现留空练习。
%
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.33\linewidth,gobble=5]
%     \hanziboxset{frametype=咪,framecolor=red,charf=\Large,
%       charcolor=green!40!black,}
%     \centering
%     \hanzibox*{故人西辞黄鹤楼}[gu4ren2xi1ci2huang2he2lou2]
%     \hanzibox*{烟花三月下扬州}[yan1hua1san1yue4]
%     \hanzibox*{孤帆远影      }[gu1fan1yuan3ying3bi4kong1jin4]
%     \hanzibox*{唯见长江天际流}[wei2jian4]
%   \end{SideBySideExample}
%
% \end{documentation}
%
% \StopEventually{}
%
% \begin{implementation}
%
% \section{代码实现}
%
% 本宏包使用 \LaTeX3 语法编写,依赖 \pkg{expl3} 环境,
% 并需调用 \pkg{l3packages}、\pkg{l3draw}、\pkg{xpinyin}等相关宏包。
%
% 按照 \LaTeX3 语法,代码中的空格、换行、回车与制表符会完全被忽略,
% 而下划线“|_|”和冒号“|:|”则可作为一般字母使用。
% 正常的空格可以使用“|~|”代替;至于 |~| 原来所表示的“带子”,
% 则要用 \LaTeXe{} 的原始命令 \tn{nobreakspace} 代替。
%
% 以下代码中有一些形如 \textcolor[HTML]{2E3191}{\textsf{<*package>}}
% 的标记,这是 \pkg{DocStrip} 中的“guard”,用来选择性地提取文件。
% “\textsf{*}”和“\textsf{/}”分别表示该部分的开始和结束。不含
% “\textsf{*}”和“\textsf{/}”的 guard 出现在行号右侧,它们用来确定
% 单独一行代码的归属。这些 guard 的颜色深浅不一,用以明确嵌套关系。
%
% 另有若干形如 \textcolor[HTML]{AD1457}{\textsf{<@@=hanzibox>}} 的 guard,
% 它们由 \pkg{l3docstrip} 定义,用来标识名字空间(模块)。
%
% \subsection{环境检测与准备}
%
%    \begin{macrocode}
%<*package>
%<@@=hanzibox>
%    \end{macrocode}
%
% 载入必要的宏包
%
%    \begin{macrocode}

\RequirePackage { xtemplate, l3keys2e, l3draw, xparse }

%    \end{macrocode}
%
% 检查LaTeX3宏包版本
%
%    \begin{macrocode}
% \clist_map_inline:nn { xtemplate, l3keys2e }
%   {
%     \@ifpackagelater {#1} { 2020/07/17 }
%       { } { \msg_error:nnn { hanzibox } { l3-too-old } {#1} }
%   }
% \msg_new:nnn { hanzibox } { l3-too-old }
%   {
%     Package~ "#1"~ is~ too~ old. \\\\
%     Please~ update~ an~ up-to-date~ version~ of~ the~ bundles \\
%     "l3kernel"~ and~ "l3packages"~ using~ your~ TeX~ package \\
%     manager~ or~ from~ CTAN.
%   }
%
%    \end{macrocode}
%
% 检查编译引擎
%
%    \begin{macrocode}
\sys_if_engine_xetex:F
  {
    \msg_fatal:nnx { hanzibox } { unsupported-engine }
      { \c_sys_engine_str }
  }
\msg_new:nnn { hanzibox } { unsupported-engine }
  {
    The~ hanzibox~ packages~ requires~ XeTeX. \\\\
    "#1"~ is~ not~ supported~ at~ present.~ You~ must~ change \\
    your~ typesetting~ engine~ to~ "xelatex"~ or~ "lualatex".
  }

%    \end{macrocode}
%
% 载入xpinyin宏包
%
%    \begin{macrocode}
\RequirePackage { xpinyin }

%    \end{macrocode}
%
% \subsection{用户接口}
%
% \changes{v1.1.0}{2021/09/22}{为用户命令添加组限制}
% \changes{v2.0.0}{2021/09/26}{调整星号命令为手动拼音注音}
% 背景盒子由l3draw实现,
% 其设计思路和部分源码来自\LaTeX 字帖宏包(\url{https://www.ctan.org/pkg/zitie})。
%
% \begin{macro}{\hanzibox}
% 自动拼音汉字盒子命令。
%    \begin{macrocode}
\NewDocumentCommand{\hanzibox}{ s O{} m O{} O{} }
  {
    \IfBooleanTF{#1}
      {
        \bool_set_false:N \l_@@_autopinyin_bool
      }{
        \bool_set_true:N  \l_@@_autopinyin_bool
      }
      \group_begin:
        \@@_handle:nnnn { #2 } { #3 } { #4 } { #5 }
      \group_end:
  }

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\hanzidialog}
% 手动汉字盒子命令。
%    \begin{macrocode}
\NewDocumentCommand{\hanzidialog}{O{} m O{} O{} }
  {
    \group_begin:
      \bool_set_false:N \l_@@_autopinyin_bool
      \@@_dialog:nnnn { #1 } { #2 } { #3 } { #4 }
    \group_end:
  }

%    \end{macrocode}
% \end{macro}
%
% \subsection{内部变量声明}
%
% \changes{v1.1.0}{2021/09/21}{添加缩放比例,前景/背景色,隐藏控制变量。}
% \changes{v2.0.0}{2021/09/24}{根据l3draw的需要重新设计各个变量。}
% \changes{v2.1.0}{2021/09/30}{添加记录拼音返回结果的clist变量。}
%
% \begin{variable}{\l_@@_autopinyin_bool,
%   \l_@@_withinitial_bool,
%   \l_@@_withvowel_bool,
%   \l_@@_withtone_bool,
%   \l_@@_withpinyin_bool,
%   \l_@@_withhanzi_bool,
%   \l_@@_withtran_bool,
%   \l_@@_basebox_box,
%   \l_@@_frame_type_tl,
%   \g_@@_frame_list_clist,
%   \l_@@_resize_method_tl,
%   \g_@@_resize_method_clist,
%   \l_@@_frame_size_dim,
%   \l_@@_char_width_dim,
%   \l_@@_char_height_dim,
%   \l_@@_box_width_dim,
%   \l_@@_box_height_dim,
%   \l_@@_linewidth_dim,
%   \l_@@_box_coffin,
%   \l_@@_tmpa_coffin,
%   \l_@@_tmpb_coffin,
%   \hanziboxwidth,
%   \hanziboxheight,
%   \l_@@_pinyin_tl,
%   \l_@@_tone_pinyin_clist,
%   \l_@@_character_tl,
%   \l_@@_translation_tl,
%   \l_@@_pinyin_format_tl,
%   \l_@@_character_format_tl,
%   \l_@@_translation_format_tl,
%   \l_@@_pinyin_int,
%   \l_@@_character_int,
%   \l_@@_translation_int,
%   \l_@@_tone_int,
%   \l_@@_pinyin_str,
%   \l_@@_initial_tl,
%   \l_@@_vowel_tl
%  }
% 定义变量。
%
%    \begin{macrocode}
\bool_new:N   \l_@@_autopinyin_bool
\bool_new:N   \l_@@_withinitial_bool
\bool_new:N   \l_@@_withvowel_bool
\bool_new:N   \l_@@_withtone_bool
\bool_new:N   \l_@@_withpinyin_bool
\bool_new:N   \l_@@_withhanzi_bool
\bool_new:N   \l_@@_withtran_bool

\box_new:N    \l_@@_basebox_box
\tl_new:N     \l_@@_frame_type_tl
\clist_new:N  \g_@@_frame_list_clist
\tl_new:N     \l_@@_resize_method_tl
\clist_new:N  \g_@@_resize_method_clist
\dim_new:N    \l_@@_frame_size_dim
\dim_new:N    \l_@@_char_width_dim
\dim_new:N    \l_@@_char_height_dim
\dim_new:N    \l_@@_box_width_dim
\dim_new:N    \l_@@_box_height_dim
\dim_new:N    \l_@@_linewidth_dim

\clist_new:N  \l_@@_tone_pinyin_clist

\coffin_new:N \l_@@_str_box_coffin
\coffin_new:N \l_@@_box_coffin
\coffin_new:N \l_@@_pinyin_box_coffin
\coffin_new:N \l_@@_tran_box_coffin
\coffin_new:N \l_@@_tmpa_coffin
\coffin_new:N \l_@@_tmpb_coffin

\dim_new:N    \hanziboxwidth
\dim_new:N    \hanziboxheight

\tl_new:N     \l_@@_pinyin_tl
\tl_new:N     \l_@@_character_tl
\tl_new:N     \l_@@_translation_tl
\tl_new:N     \l_@@_pinyin_format_tl
\tl_new:N     \l_@@_character_format_tl
\tl_new:N     \l_@@_translation_format_tl
\int_new:N    \l_@@_pinyin_int
\int_new:N    \l_@@_character_int
\int_new:N    \l_@@_translation_int

\int_new:N    \l_@@_tone_int
\str_new:N    \l_@@_pinyin_str
\tl_new:N     \l_@@_initial_tl
\tl_new:N     \l_@@_vowel_tl

%    \end{macrocode}
% \end{variable}
%
% \subsection{辅助函数}
%
% \subsubsection{设置填充色}
%
% \begin{macro}{\@@_aux_color_fill:}
% 设置填充色
%    \begin{macrocode}
\cs_new_nopar:Nn \@@_aux_color_fill:
  { }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{计算盒子尺寸}
%
% \begin{macro}{\@@_calc_basechar_w_h:}
% 计算基字符盒子宽和高
%    \begin{macrocode}
\cs_new:Npn \@@_calc_basechar_w_h:
  {
    \dim_set:Nn \l_@@_char_width_dim
      {
        \box_wd:N \l_@@_basebox_box
      }
    \dim_set:Nn \l_@@_char_height_dim
      {
        \box_ht_plus_dp:N \l_@@_basebox_box
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_coffin_ht_plus_dp:N}
% 获取coffin盒子总高度
%    \begin{macrocode}
\cs_new_nopar:Npn \@@_coffin_ht_plus_dp:N #1
  {
    \coffin_ht:N #1 + \coffin_dp:N #1
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0.0}{2021/09/28}{添加根据基字符格式计算外观盒子尺寸的函数}
%
% \begin{macro}{\@@_calc_frame_size:}
% 计算外框长度(正方形,由基字符按charf选项设定的格式构造的盒子确定)
%    \begin{macrocode}
\cs_new:Npn \@@_calc_frame_size:
  {
    \hbox_set:Nn \l_tmpa_box
      {
        \tl_use:N \l_@@_character_format_tl
        \tl_use:N \c_@@_basechar_tl
      }

    \dim_set:Nn \l_tmpa_dim
      {
        \box_wd:N \l_tmpa_box
      }
    \dim_set:Nn \l_tmpb_dim
      {
        \box_ht_plus_dp:N \l_tmpa_box
      }

    \dim_compare:nNnTF \l_tmpa_dim > \l_tmpb_dim
      {
        \dim_gset_eq:NN \l_@@_frame_size_dim \l_tmpa_dim
      }
      {
        \dim_gset_eq:NN \l_@@_frame_size_dim \l_tmpb_dim
      }

    \dim_gadd:Nn \l_@@_frame_size_dim { 2pt }

    \dim_gset_eq:NN \hanziboxwidth \l_@@_frame_size_dim
    \dim_gset_eq:NN \hanziboxheight \l_@@_frame_size_dim

  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{定义边框样式}
%
% \begin{macro}{\@@_frame_type:n,\@@_frame_type_c:n}
% 生成边框样式函数名称
%    \begin{macrocode}
\cs_new_nopar:Npn \@@_frame_type:n #1
  {
    @@_frame_construct_type_ #1 :nnnnnn
  }
\cs_new_nopar:Npn \@@_frame_type_c:n #1
  {
    \use:c
      {
        @@_frame_construct_type_ #1 :nnnnnn
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_new_frame_construct:nn}
% 边框样式函数的定义函数。
%    \begin{macrocode}
\cs_new:Npn \@@_new_frame_construct:nn #1
  {
    \clist_put_right:Nn \g_@@_frame_list_clist {#1}
    \cs_new:cn { \@@_frame_type:n {#1} }
  }
\@@_new_frame_construct:nn { none } { }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\@@_new_frame_construct:nn { 口 }
  {
    \color_stroke:n { hanziboxframecolor }
    \draw_path_rectangle_corners:nn { #1, #2} { #3, #4}

    \cs_if_eq:NNTF \@@_aux_color_fill: \c_empty_tl
      {
        \draw_path_use_clear:n { stroke }
      }
      {
        \draw_path_use_clear:n { stroke , fill }
      }
  }

\@@_new_frame_construct:nn { 十 }
  {
    \tl_if_empty:NF \l_@@_dash_pattern_tl
      {
        \exp_args:No \draw_dash_pattern:nn { \l_@@_dash_pattern_tl } { 0pt }
      }
    \color_stroke:n { hanziboxframecolor!30 }
    \draw_path_moveto:n { (#3)/2, #2 }
    \draw_path_lineto:n { #3/2, #4 }
    \draw_path_moveto:n { #1, (#4)/2 }
    \draw_path_lineto:n { #3, (#4)/2 }
    \draw_path_use_clear:n { stroke }
  }

\@@_new_frame_construct:nn { × }
  {
    \tl_if_empty:NF \l_@@_dash_pattern_tl
      {
        \exp_args:No \draw_dash_pattern:nn { \l_@@_dash_pattern_tl } { 0pt }
      }
    \color_stroke:n { hanziboxframecolor!30 }
    \draw_path_moveto:n { #1, #2 }
    \draw_path_lineto:n { #3, #4 }
    \draw_path_moveto:n { #1, #4 }
    \draw_path_lineto:n { #3, #2 }
    \draw_path_use_clear:n { stroke }
  }

\@@_new_frame_construct:nn { 田 }
  {
    \@@_frame_type_c:n { 口 } {#1} {#2} {#3} {#4} {#5} {#6}
    \@@_frame_type_c:n { 十 } {#1} {#2} {#3} {#4} {#5} {#6}
  }

\@@_new_frame_construct:nn { 米 }
  {
    \@@_frame_type_c:n { × } {#1} {#2} {#3} {#4} {#5} {#6}
    \@@_frame_type_c:n { 十 } {#1} {#2} {#3} {#4} {#5} {#6}
  }

\@@_new_frame_construct:nn { 咪 }
  {
    \@@_frame_type_c:n { 口 } {#1} {#2} {#3} {#4} {#5} {#6}
    \@@_frame_type_c:n { × } {#1} {#2} {#3} {#4} {#5} {#6}
    \@@_frame_type_c:n { 十 } {#1} {#2} {#3} {#4} {#5} {#6}
  }
%    \end{macrocode}
%
% \subsubsection{定义缩放方式}
%
% \begin{macro}{\@@_resize:n,\@@_resize_c:n}
% 缩放方式命名函数
%    \begin{macrocode}
\cs_new_nopar:Npn \@@_resize:n #1
  {
    @@_processor_resize_ #1 :w
  }
\cs_new_nopar:Npn \@@_resize_c:n #1
  {
    \use:c
      {
        @@_processor_resize_ #1 :w
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_dim_gezero_dispatch:NNnnn,\@@_dim_gezero_dispatch:NNnnn,
%               \@@_force_size_dispatch:nnn,\@@_force_size_dispatch:nnnn}
% 定义缩放方式函数需要的辅助函数。
%    \begin{macrocode}
\cs_new:Npn \@@_dim_gezero_dispatch:NNnnn #1#2 #3#4#5
  {
    \dim_compare:nNnTF #1 > \c_zero_dim
      { #3 }
      {
        \dim_compare:nNnTF #2 > \c_zero_dim
          { #4 } { #5 }
      }
  }
\cs_new:Npn \@@_dim_gezero_dispatch:NNnnnn #1#2 #3#4#5#6
  {
    \dim_compare:nNnTF #1 > \c_zero_dim
      {
        \dim_compare:nNnTF #2 > \c_zero_dim
          { #3 } { #4 }
      }
      {
        \dim_compare:nNnTF #2 > \c_zero_dim
          { #5 } { #6 }
      }
  }
\cs_new:Npn \@@_force_size_dispatch:nnn % height, width, none
  {
    \@@_dim_gezero_dispatch:NNnnn \l_@@_height_dim \l_@@_width_dim
  }
\cs_new:Npn \@@_force_size_dispatch:nnnn % both, height, width, none
  {
    \@@_dim_gezero_dispatch:NNnnnn \l_@@_box_height_dim \l_@@_box_width_dim
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_new_resize_method:nn}
% 缩放方式函数的定义函数。
%    \begin{macrocode}
\cs_new:Npn \@@_new_resize_method:nn #1
  {
    \clist_put_right:Nn \g_@@_resize_method_clist {#1}
    \cs_new:cpn { \@@_resize:n {#1} }
  }
%    \end{macrocode}
% \end{macro}
%
% 定义缩放方式函数。
%    \begin{macrocode}
\@@_new_resize_method:nn { none } { }

\@@_new_resize_method:nn { real }
  {
    \@@_force_size_dispatch:nnnn
      {
        \coffin_resize:Nnn \l_@@_box_coffin
                           \l_@@_box_width_dim
                           \l_@@_box_height_dim
      }
      {
        \coffin_scale:Nnn \l_@@_box_coffin
          {
            \dim_ratio:nn { \l_@@_box_height_dim }
                          { \@@_coffin_ht_plus_dp:N \l_@@_box_coffin }
          }
          {
            \dim_ratio:nn { \l_@@_box_height_dim }
                          { \@@_coffin_ht_plus_dp:N \l_@@_box_coffin }
          }
      }
      {
        \coffin_scale:Nnn \l_@@_box_coffin
          {
            \dim_ratio:nn { \l_@@_box_width_dim }
                          { \coffin_wd:N \l_@@_box_coffin }
          }
          {
            \dim_ratio:nn { \l_@@_box_width_dim }
                          { \coffin_wd:N \l_@@_box_coffin }
          }
      }
      {
        \coffin_scale:Nnn \l_@@_box_coffin
                          { \l_@@_x_scale_tl }
                          { \l_@@_y_scale_tl }
      }
  }

\@@_new_resize_method:nn { base }
  {
    \@@_force_size_dispatch:nnnn
      {
        \coffin_resize:Nnn \l_@@_box_coffin
                           \l_@@_box_width_dim
                           \l_@@_box_height_dim
      }
      {
        \coffin_resize:Nnn \l_@@_box_coffin
           {
             \l_@@_char_width_dim * \dim_ratio:nn { \l_@@_box_height_dim }
               { \@@_coffin_ht_plus_dp:N \l_@@_box_coffin }
           }
           {
             \l_@@_box_height_dim
           }
      }
      {
        \coffin_resize:Nnn \l_@@_box_coffin
           {
             \l_@@_box_width_dim
           }
           {
             \l_@@_char_height_dim * \dim_ratio:nn { \l_@@_box_width_dim }
               { \coffin_wd:N \l_@@_box_coffin }
           }
      }
      {
        \coffin_resize:Nnn \l_@@_box_coffin
           {
             \l_@@_x_scale_tl \l_@@_char_width_dim
           }
           {
             \l_@@_y_scale_tl \l_@@_char_height_dim
           }
      }
  }

\msg_new:nnn { hanzibox } { frame-type } { using~ `#1'~ frame. }
%    \end{macrocode}
%
% \changes{v2.0.0}{2021/09/28}{删除square缩放样式}
%
% \subsubsection{设置字号}
%
% \begin{macro}{\@@_zihao:n}
% 设置字号
%    \begin{macrocode}
\cs_new_nopar:Npn \@@_zihao:n #1 { \zihao {#1} }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{定义边框类型错误提示信息}
%
%    \begin{macrocode}
\msg_new:nnn { hanzibox } { frame-exists } { The~ frame~ type~ `#1~ not~ exists. }
%    \end{macrocode}
%
% \subsubsection{命名颜色}
%
% \begin{macro}{\@@_color_select:nn,\@@_color_select:nnn}
% 颜色命名函数,注意使用的是l3语法
%    \begin{macrocode}
\cs_set_nopar:Npn \@@_color_select:nn #1#2
  {
    \color_set:nn {#1} {#2}
  }
\cs_set_nopar:Npn \@@_color_select:nnn #1#2#3
  {
    \color_set:nnn {#1} {#2} {#3}
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{设置Debug状态}
%
% \begin{macro}{\@@_debug:n}
% 设置debug状态
%    \begin{macrocode}
\cs_new:Npn \@@_debug:n
  {
    \bool_if:NTF \l_@@_debug_bool
      { \use:n } { \use_none:n }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{选项处理}
%
% \changes{v2.0.0}{2021/09/25}{参考zitie宏包,重新设计选项,
%                              仅保留1.1.0版本中的拼音、汉字、译文显示控制选项。}
%
% 定义 |hanzibox| 键值类。
%    \begin{macrocode}
\keys_define:nn { hanzibox }
  {
%    \end{macrocode}
%
% \begin{macro}{basechar}
% 设置基字符。
%    \begin{macrocode}
    basechar  .code:n = { \tl_gset:Nx \c_@@_basechar_tl {#1}
                          \@@_calc_basechar_w_h:
                        },
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{zihao}
% 设置字号。
%    \begin{macrocode}
    zihao     .code:n = { \hbox_gset:Nn \l_@@_basebox_box
                            {
                              \@@_zihao:n {#1} \c_@@_basechar_tl
                            }
                          \@@_calc_basechar_w_h:
                        },
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{pinyinf}
% 拼音的格式
%    \begin{macrocode}
    pinyinf .tl_set:N = \l_@@_pinyin_format_tl ,
    pinyinf .initial:n = \tiny ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{charf}
% 汉字的格式
%    \begin{macrocode}
    charf .code:n = { \tl_gset:Nn \l_@@_character_format_tl {#1}
                      \@@_calc_frame_size:
                    },
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{tranf}
% 译文的格式
%    \begin{macrocode}
    tranf .tl_set:N = \l_@@_translation_format_tl ,
    tranf .initial:n = \tiny ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{frametype}
% 设置边框类型,其取值可以是:none-无方框,口–仅方框, 十–仅中间的横线和竖线,
% 田–常见的田字格, 米–十字格再加上斜的两条线, 咪–常见的米字格。
%    \begin{macrocode}
    frametype .code:n = { \exp_args:NNx \clist_if_in:NnTF \g_@@_frame_list_clist {#1}
                            { \tl_set:Nx \l_@@_frame_type_tl {#1} }
                            { \msg_error:nnx { hanzibox } { frame-exists } {#1} }
                        },
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{resize}
% resize 设置缩放方式,其取值可以是:
% none,不使用缩放
% real,使用字符实际宽高缩放,
% base,使用 basechar 设置的字符的宽高缩放。
%    \begin{macrocode}
    resize    .code:n = { \exp_args:NNx \clist_if_in:NnTF \g_@@_resize_method_clist {#1}
                            { \tl_set:Nx \l_@@_resize_method_tl {#1} }
                            { \msg_error:nnx { hanzibox } { resize-method } {#1} }
                        },
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{xscale}
% x方向缩放比例
%    \begin{macrocode}
    xscale .tl_set:N = \l_@@_x_scale_tl ,
    xscale .initial:n = 1 ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{yscale}
% y方向缩放比例
%    \begin{macrocode}
    yscale .tl_set:N = \l_@@_y_scale_tl ,
    yscale .initial:n = 1 ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{scale}
% x,y方向缩放比例
%    \begin{macrocode}
    scale  .meta:n = { xscale = #1 , yscale = #1 } ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{width}
% 盒子宽度
%    \begin{macrocode}
    width  .dim_set:N = \l_@@_box_width_dim ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{height}
% 盒子高度
%    \begin{macrocode}
    height .dim_set:N = \l_@@_box_height_dim ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{linewidth}
% 线条宽度
%    \begin{macrocode}
    linewidth .dim_set:N = \l_@@_linewidth_dim ,
    linewidth .initial:n = 0.4pt ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{framecolor}
% 边框颜色
%    \begin{macrocode}
    framecolor  .code:n = { \@@_color_select:nn { hanziboxframecolor } {#1} } ,
    framecolor  .initial:n = black ,
    framecolor* .code:n = { \@@_color_select:nnn { hanziboxframecolor } #1 } ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{charcolor}
% 字符颜色
%    \begin{macrocode}
    charcolor  .code:n = { \@@_color_select:nn { hanziboxcharcolor } {#1} } ,
    charcolor  .initial:n = black ,
    charcolor* .code:n = { \@@_color_select:nnn { hanziboxframecolor } {#1} } ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{color}
% 同时设置边框和字符颜色
%    \begin{macrocode}
    color  .meta:n = { framecolor = #1, charcolor = #1 } ,
    color* .meta:n = { framecolor* = #1, charcolor* = #1 } ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{fillcolor}
% 填充色
%    \begin{macrocode}
    fillcolor  .code:n = { \exp_args:Nx \tl_if_empty:nTF {#1}
                            {  \@@_color_select:nn { hanziboxfillcolor } { white }
                               \cs_set_nopar:Npn \@@_aux_color_fill: { }
                            }{ \@@_color_select:nn { hanziboxfillcolor } {#1}
                               \cs_set_nopar:Npn \@@_aux_color_fill: { \color_fill:n {#1} }
                            }
                        } ,
    fillcolor* .code:n = { \@@_color_select:nnn { hanziboxfillcolor } #1
                           \cs_set_nopar:Npn \@@_aux_color_fill: { \color_fill:nn #1 }
                         } ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{dashpattern}
% 虚线样式
%    \begin{macrocode}
    dashpattern .tl_set:N = \l_@@_dash_pattern_tl ,
    dashpattern .initial:n = { } ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{framearc}
% 转角半径
%    \begin{macrocode}
    framearc  .code:n = { \tl_set:Nn \l_@@_frame_arc_tl { {#1}{#1} } } ,
    framearc* .tl_set:N = \l_@@_frame_arc_tl ,
    framearc* .initial:n = { { 0cm }{ 0cm } } ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{debug}
% Debug状态
%    \begin{macrocode}
    debug .bool_set:N = \l_@@_debug_bool ,
    debug .initial:n = false ,
    debug .default:n = true ,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{autopinyin}
% 是否使用\tn{xpyinyin*}命令通过汉字自动获取汉语拼音,默认为true。
%    \begin{macrocode}
    autopinyin .bool_set:N = \l_@@_autopinyin_bool,
    autopinyin .default:n = true,
    autopinyin .initial:n = true,

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{initial}
% 是否输出声母,默认为true。
%    \begin{macrocode}
    initial .bool_set:N = \l_@@_withinitial_bool,
    initial .default:n = true,
    initial .initial:n = true,

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{vowel}
% 是否输出韵母,默认为true。
%    \begin{macrocode}
    vowel .bool_set:N = \l_@@_withvowel_bool,
    vowel .default:n = true,
    vowel .initial:n = true,

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{tone}
% 是否输出声调,默认为true。
%    \begin{macrocode}
    tone .bool_set:N = \l_@@_withtone_bool,
    tone .default:n = true,
    tone .initial:n = true,

%    \end{macrocode}
% \end{macro}
%
% \changes{v1.1.0}{2021/09/21}{添加隐藏拼音键。}
%
% \begin{macro}{pinyin}
% 是否显示汉语拼音,默认为true。
%    \begin{macrocode}
    pinyin .bool_set:N = \l_@@_withpinyin_bool,
    pinyin .default:n = true,
    pinyin .initial:n = true,

%    \end{macrocode}
% \end{macro}
%
% \changes{v1.1.0}{2021/09/21}{添加隐藏汉字键。}
%
% \begin{macro}{hanzi}
% 是否显示汉语拼音,默认为true。
%    \begin{macrocode}
    hanzi .bool_set:N = \l_@@_withhanzi_bool,
    hanzi .default:n = true,
    hanzi .initial:n = true,

%    \end{macrocode}
% \end{macro}
%
% \changes{v1.1.0}{2021/09/21}{添加隐藏译文键。}
%
% \begin{macro}{tran}
% 是否显示汉语拼音,默认为true。
%    \begin{macrocode}
    tran .bool_set:N = \l_@@_withtran_bool,
    tran .default:n = true,
    tran .initial:n = true,

%    \end{macrocode}
% \end{macro}
%
%
% 处理未知选项。
%    \begin{macrocode}
    unknown .code:n = { \@@_error:n { unknown-option } }
  }
\msg_new:nnn { hanzibox } { unknown-option }
  { package~ option~ "\l_keys_key_tl"~ is~ unknown. }

%    \end{macrocode}
%
% 参数默认值
%    \begin{macrocode}
\keys_set:nn { hanzibox }
  {
    basechar = 好 ,
    zihao = 4 ,
    pinyinf = \tiny ,
    charf = \normalsize ,
    tranf = \tiny ,
    frametype = none ,
    resize = none ,
  }

%    \end{macrocode}
%
% \subsection{选项用户接口}
%
% \begin{macro}{\hanziboxset}
% 选项设置用户接口。
%    \begin{macrocode}
\NewDocumentCommand \hanziboxset { m }
  { \keys_set:nn { hanzibox } {#1} }
%    \end{macrocode}
% \end{macro}
%
% \subsection{内部函数}
%
% \begin{macro}{\@@_pinyinaux:n}
% \begin{macro}{\@@_pinyinaux:x}
% \pkg{xpyinyin}宏包\tn{pinyin} 命令的\LaTeX3{}版本函数及其函数变体。
%    \begin{macrocode}
  % \xpinyinsetup{pysep={\hspace*{1em}}}
\cs_set_eq:NN \@@_pinyinaux:n \pinyin
\cs_generate_variant:Nn \@@_pinyinaux:n { x }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_dialog:nnnn}
% 手动汉字盒子排版内部命令。
%    \begin{macrocode}
\cs_new:Npn \@@_dialog:nnnn #1#2#3#4
  {
    \group_begin:
      \keys_set:nn { hanzibox } { #1 }

      \tl_set:Nx \l_@@_character_tl {#2}
      \tl_set:Nx \l_@@_pinyin_tl {#3}
      \tl_set:Nx \l_@@_translation_tl {#4}

      \hcoffin_set:Nn \l_@@_pinyin_box_coffin
        {
          \tl_use:N \l_@@_pinyin_format_tl
          \tl_use:N \l_@@_pinyin_tl
        }
      \hcoffin_set:Nn \l_@@_str_box_coffin
        {
          \tl_map_inline:Nn \l_@@_character_tl
            {
              \@@_single_handle:N ##1 \allowbreak
            }
        }
      \hcoffin_set:Nn \l_@@_tran_box_coffin
        {
          \tl_use:N \l_@@_translation_format_tl
          \tl_use:N \l_@@_translation_tl
        }
      \coffin_join:NnnNnnnn \l_@@_str_box_coffin
        { hc } { t } \l_@@_pinyin_box_coffin { hc } { H } { 0pt } { 3pt }
      \coffin_join:NnnNnnnn \l_@@_str_box_coffin
        { hc } { b } \l_@@_tran_box_coffin { hc } { t } { 0pt } { -2pt }

      \coffin_set_eq:NN \l_@@_box_coffin \l_@@_str_box_coffin

      \@@_resize_c:n { \l_@@_resize_method_tl }

      \coffin_typeset:Nnnnn \l_@@_box_coffin
        { l } { b } { 0pt } { 0pt }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0.1}{2021/09/28}{分离多字、单字、0个字的盒子构造代码}
% \changes{v2.1.0}{2021/09/30}{更新拼音获取方式,以处理\tn{setuppinyin}的结果}
%
% \begin{macro}{\@@_multi_str_coffin_construct:}
% 构造多汉字带拼音字符串盒子。
%    \begin{macrocode}
\cs_new:Npn \@@_multi_str_coffin_construct:
  {
    \bool_if:NTF \l_@@_autopinyin_bool
      {
        \hcoffin_set:Nn \l_@@_str_box_coffin
          {
            \tl_map_inline:Nn \l_@@_character_tl
              {
                \hcoffin_set:Nn \l_tmpa_coffin
                  {
                    \@@_single_handle:N ##1
                  }

                \bool_if:NT \l_@@_withpinyin_bool
                  {
                    \@@_get_hanzi_pinyin:n { ##1 }
                    \@@_single_pinyin:V \l_@@_hanzi_pinyin_tl

                    \coffin_join:NnnNnnnn \l_tmpa_coffin
                      { hc } { t } \l_@@_pinyin_box_coffin { hc } { H } { 0pt } { 3pt }
                  }
                \coffin_typeset:Nnnnn \l_tmpa_coffin
                  { l } { b } { 0pt } { 0pt }
                \allowbreak
              }
          }
      }
      {
        \@@_get_tone_pinyin:V \l_@@_pinyin_tl
        \clist_clear:N \l_@@_tone_pinyin_clist
        \clist_set:NV \l_@@_tone_pinyin_clist \l_@@_tone_pinyin_tl
        \int_set:Nn \l_tmpa_int {\clist_count:N \l_@@_tone_pinyin_clist}
        \hcoffin_set:Nn \l_@@_str_box_coffin
          {
            \int_compare:nNnTF { \l_@@_character_int } = { \l_tmpa_int }
              {
                \tl_map_inline:Nn \l_@@_character_tl
                  {
                    \hcoffin_set:Nn \l_tmpa_coffin
                      {
                        \@@_single_handle:N ##1
                      }

                    \bool_if:NT \l_@@_withpinyin_bool
                      {
                        \clist_pop:NN \l_@@_tone_pinyin_clist \l_tmpb_tl
                        \@@_single_pinyin:V \l_tmpb_tl

                        \coffin_join:NnnNnnnn \l_tmpa_coffin
                          { hc } { t } \l_@@_pinyin_box_coffin { hc } { H } { 0pt } { 3pt }
                      }
                    \coffin_typeset:Nnnnn \l_tmpa_coffin
                      { l } { b } { 0pt } { 0pt }
                    \allowbreak
                  }
              }
              {
                \int_compare:nNnTF { \l_@@_character_int } > { \l_tmpa_int }
                  {
                    \int_step_inline:nn { \l_tmpa_int }
                      {
                        \hcoffin_set:Nn \l_tmpa_coffin
                          {
                            \tl_set:Nx \l_tmpa_tl {\tl_item:Nn \l_@@_character_tl { ##1 }}
                            \@@_single_handle:N \l_tmpa_tl
                          }
                        \bool_if:NT \l_@@_withpinyin_bool
                          {
                            \clist_pop:NN \l_@@_tone_pinyin_clist \l_tmpb_tl
                            \@@_single_pinyin:V \l_tmpb_tl

                            \coffin_join:NnnNnnnn \l_tmpa_coffin
                              { hc } { t } \l_@@_pinyin_box_coffin { hc } { H } { 0pt } { 3pt }
                          }
                        \coffin_typeset:Nnnnn \l_tmpa_coffin
                          { l } { b } { 0pt } { 0pt }
                        \allowbreak
                      }
                    \int_step_inline:nnn { \l_tmpa_int + 1 } { \l_@@_character_int }
                      {
                        \hcoffin_set:Nn \l_tmpa_coffin
                          {
                            \tl_set:Nx \l_tmpa_tl {\tl_item:Nn \l_@@_character_tl { ##1 }}
                            \@@_single_handle:N \l_tmpa_tl
                          }
                        \coffin_typeset:Nnnnn \l_tmpa_coffin
                          { l } { b } { 0pt } { 0pt }
                        \allowbreak
                      }
                  }
                  {
                    \int_step_inline:nn { \l_@@_character_int }
                      {
                        \hcoffin_set:Nn \l_tmpa_coffin
                          {
                            \tl_set:Nx \l_tmpa_tl {\tl_item:Nn \l_@@_character_tl { ##1 }}
                            \@@_single_handle:N \l_tmpa_tl
                          }
                        \bool_if:NT \l_@@_withpinyin_bool
                          {
                            \clist_pop:NN \l_@@_tone_pinyin_clist \l_tmpb_tl
                            \@@_single_pinyin:V \l_tmpb_tl

                            \coffin_join:NnnNnnnn \l_tmpa_coffin
                              { hc } { t } \l_@@_pinyin_box_coffin { hc } { H } { 0pt } { 3pt }
                          }
                        \coffin_typeset:Nnnnn \l_tmpa_coffin
                          { l } { b } { 0pt } { 0pt }
                        \allowbreak
                      }

                    \bool_if:NTF \l_@@_withhanzi_bool
                      {
                        \bool_set_false:N \l_@@_withhanzi_bool
                        \int_step_inline:nnn { \l_@@_character_int + 1 } { \l_tmpa_int }
                          {
                            \hcoffin_set:Nn \l_tmpa_coffin
                              {
                                \@@_single_handle:N \c_@@_basechar_tl
                              }
                            \bool_if:NT \l_@@_withpinyin_bool
                              {
                                \clist_pop:NN \l_@@_tone_pinyin_clist \l_tmpb_tl
                                \@@_single_pinyin:V \l_tmpb_tl

                                \coffin_join:NnnNnnnn \l_tmpa_coffin
                                  { hc } { t } \l_@@_pinyin_box_coffin { hc } { H } { 0pt } { 3pt }
                              }
                            \coffin_typeset:Nnnnn \l_tmpa_coffin
                              { l } { b } { 0pt } { 0pt }
                            \allowbreak
                          }
                        \bool_set_true:N \l_@@_withhanzi_bool
                      }
                      {
                        \int_step_inline:nnn { \l_@@_character_int + 1 } { \l_tmpa_int }
                          {
                            \hcoffin_set:Nn \l_tmpa_coffin
                              {
                                \@@_single_handle:N \c_@@_basechar_tl
                              }
                            \bool_if:NT \l_@@_withpinyin_bool
                              {
                                \clist_pop:NN \l_@@_tone_pinyin_clist \l_tmpb_tl
                                \@@_single_pinyin:V \l_tmpb_tl

                                \coffin_join:NnnNnnnn \l_tmpa_coffin
                                  { hc } { t } \l_@@_pinyin_box_coffin { hc } { H } { 0pt } { 3pt }
                              }
                            \coffin_typeset:Nnnnn \l_tmpa_coffin
                              { l } { b } { 0pt } { 0pt }
                            \allowbreak
                          }
                      }
                  }
              }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_single_str_coffin_construct:}
% 构造单个汉字带拼音字符串盒子。
%    \begin{macrocode}
\cs_new:Npn \@@_single_str_coffin_construct:
  {
    \bool_if:NTF \l_@@_autopinyin_bool
      {
        \@@_multi_str_coffin_construct:
      }
      {
        \hcoffin_set:Nn \l_@@_str_box_coffin
          {
            \hcoffin_set:Nn \l_tmpa_coffin
              {
                \@@_single_handle:N \l_@@_character_tl
              }

            \bool_if:NT \l_@@_withpinyin_bool
              {
                \hcoffin_set:Nn \l_@@_pinyin_box_coffin
                  {
                    \color_select:n { hanziboxcharcolor }
                    \tl_use:N \l_@@_pinyin_format_tl
                    \@@_get_tone_pinyin:V \l_@@_pinyin_tl
                    \clist_clear:N \l_@@_tone_pinyin_clist
                    \clist_set:NV \l_@@_tone_pinyin_clist \l_@@_tone_pinyin_tl
                    \clist_use:Nn \l_@@_tone_pinyin_clist {}
                  }
                \coffin_join:NnnNnnnn \l_tmpa_coffin
                  { hc } { t } \l_@@_pinyin_box_coffin { hc } { H } { 0pt } { 3pt }
              }
            \coffin_typeset:Nnnnn \l_tmpa_coffin
              { l } { b } { 0pt } { 0pt }
            \allowbreak
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_null_str_coffin_construct:}
% 构造空白汉字(0个汉字)带拼音字符串盒子。
%    \begin{macrocode}
\cs_new:Npn \@@_null_str_coffin_construct:
  {
    \hcoffin_set:Nn \l_@@_str_box_coffin
      {
        \bool_set_false:N \l_@@_withhanzi_bool

        \hcoffin_set:Nn \l_tmpa_coffin
          {
            \@@_single_handle:N \c_@@_basechar_tl
          }

        \bool_if:NT \l_@@_withpinyin_bool
          {
            \hcoffin_set:Nn \l_@@_pinyin_box_coffin
              {
                \color_select:n { hanziboxcharcolor }
                \tl_use:N \l_@@_pinyin_format_tl
                \@@_get_tone_pinyin:V \l_@@_pinyin_tl
                \clist_clear:N \l_@@_tone_pinyin_clist
                \clist_set:NV \l_@@_tone_pinyin_clist \l_@@_tone_pinyin_tl
                \clist_use:Nn \l_@@_tone_pinyin_clist {}
                % \@@_get_tone_pinyin:V \l_@@_pinyin_tl
                % \l_@@_tone_pinyin_tl
              }
            \coffin_join:NnnNnnnn \l_tmpa_coffin
              { hc } { t } \l_@@_pinyin_box_coffin { hc } { H } { 0pt } { 3pt }
          }
        \coffin_typeset:Nnnnn \l_tmpa_coffin
          { l } { b } { 0pt } { 0pt }
        \allowbreak
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0.0}{2021/09/28}{将拼音处理调整为在handle函数中直接实现}
% \changes{v2.0.0}{2021/09/28}{区分了单个汉字和空白汉字的处理}
% \changes{v2.0.1}{2021/09/29}{将汉字盒子处理过程拆解为函数实现}
%
% \begin{macro}{\@@_handle:nnnn}
% 构造汉字盒子入口
%    \begin{macrocode}
\cs_new:Npn \@@_handle:nnnn #1#2#3#4
  {
    \group_begin:
      \keys_set:nn { hanzibox } { #1 }

      \tl_gset:Nx \l_@@_character_tl {#2}
      \tl_gset:Nx \l_@@_pinyin_tl {#3}
      \tl_gset:Nx \l_@@_translation_tl {#4}

      \int_set:Nn \l_@@_character_int
        {
          \tl_count:V \l_@@_character_tl
        }
      \int_set:Nn \l_@@_translation_int
        {
          \tl_count:V \l_@@_translation_tl
        }
      \int_set:Nn \l_@@_pinyin_int
        {
          \tl_count:V \l_@@_pinyin_tl
        }

      \int_compare:nNnTF { \l_@@_character_int } > { 1 }
        {
          \@@_multi_str_coffin_construct:
        }
        {
          \int_compare:nNnTF { \l_@@_character_int } = { 1 }
            {
              \@@_single_str_coffin_construct:
            }
            {
              \@@_null_str_coffin_construct:
            }
        }
      \bool_if:NT \l_@@_withtran_bool
        {
          \hcoffin_set:Nn \l_@@_tran_box_coffin
            {
              \color_select:n { hanziboxcharcolor }
              \tl_use:N \l_@@_translation_format_tl
              \tl_use:N \l_@@_translation_tl
            }
        }
      \coffin_join:NnnNnnnn \l_@@_str_box_coffin
        { hc } { b } \l_@@_tran_box_coffin { hc } { t } { 0pt } { -3pt }

      \coffin_set_eq:NN \l_@@_box_coffin \l_@@_str_box_coffin

      \@@_resize_c:n { \l_@@_resize_method_tl }

      \coffin_typeset:Nnnnn \l_@@_box_coffin
        { l } { b } { 0pt } { 0pt }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0.0}{2021/09/27}{对于无需分解声韵母的情况,
%     直接使用xpinyin宏包的结果排版拼音。}
%
% \begin{macro}{\@@_single_pinyin:n}
% 构造单个汉字的拼音盒子
%    \begin{macrocode}
\cs_new:Npn \@@_single_pinyin:n #1
  {
    \bool_if:NTF \l_@@_withtone_bool
      {
        \bool_if:nTF { !(\l_@@_withinitial_bool) || !(\l_@@_withvowel_bool) }
          {
            \@@_split_pinyin_withtone:n { #1 }
            \hcoffin_set:Nn \l_@@_pinyin_box_coffin
              {
                \color_select:n { hanziboxcharcolor }
                \tl_use:N \l_@@_pinyin_format_tl

                \bool_if:NTF \l_@@_withinitial_bool
                  {
                    \bool_if:NTF \l_@@_withvowel_bool
                    {
                      \tl_use:N \l_@@_initial_tl
                      \tl_use:N \l_@@_vowel_tl
                    }
                    {
                      \tl_use:N \l_@@_initial_tl
                      \phantom{ \tl_use:N \l_@@_vowel_tl }
                    }
                  }
                  {
                    \bool_if:NTF \l_@@_withvowel_bool
                    {
                      \phantom{ \tl_use:N \l_@@_initial_tl }
                      \tl_use:N \l_@@_vowel_tl
                    }
                    {
                      \phantom{ \tl_use:N \l_@@_initial_tl }
                      \phantom{ \tl_use:N \l_@@_vowel_tl }
                    }
                  }
              }
          }
          {
            \hcoffin_set:Nn \l_@@_pinyin_box_coffin
              {
                \color_select:n { hanziboxcharcolor }
                \tl_use:N \l_@@_pinyin_format_tl
                #1
              }
          }
      }
      {
        \@@_split_pinyin_withouttone:n { #1 }
        \hcoffin_set:Nn \l_@@_pinyin_box_coffin
        {
          \color_select:n { hanziboxcharcolor }
          \tl_use:N \l_@@_pinyin_format_tl

          \tl_use:N \l_@@_pinyin_tl
        }
      }
  }
\cs_generate_variant:Nn  \@@_single_pinyin:n { V }
\cs_generate_variant:Nn  \@@_single_pinyin:n { x }
\cs_set:Npn \@@_single_pinyin_o:n
  { \exp_after:wN \@@_single_pinyin:n }
\cs_set:Npn \@@_single_pinyin_f:n
  { \exp_args:Nf \@@_single_pinyin:n }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_single_handle:nN,\@@_single_handle:N}
% 构造单个汉字盒子入口
%    \begin{macrocode}
\cs_new:Npn \@@_single_handle:nN #1#2
  {
    \group_begin:
      \tl_if_empty:nF {#1} { \keys_set:nn { hanzibox } {#1} }

      \tl_set:Nf \l_@@_curr_char_tl {#2}

      \@@_single_construct_o:N \l_@@_curr_char_tl
    \group_end:
  }
\cs_new:Npn \@@_single_handle:N #1
  {
    \group_begin:
      \tl_set:Nf \l_@@_curr_char_tl {#1}
      \@@_single_construct_o:N \l_@@_curr_char_tl
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0.0}{2021/09/27}{删除单个汉字构造中添加拼音的功能}
%
% \begin{macro}{\@@_single_construct:N}
% 构造单个汉字盒子
%    \begin{macrocode}
\cs_new:Npn \@@_single_construct:N #1
  {
    \bool_if:NTF \l_@@_withhanzi_bool
      {
        \hcoffin_set:Nn \l_@@_box_coffin
          {
            \color_select:n { hanziboxcharcolor }
            \tl_use:N \l_@@_character_format_tl
            #1
          }
      }
      {
        \hcoffin_set:Nn \l_@@_box_coffin
          {
            \color_select:n { hanziboxcharcolor }
            \tl_use:N \l_@@_character_format_tl
            \phantom{#1}
          }
      }

    \@@_single_frame_construct:
  }
\cs_set:Npn \@@_single_construct_o:N
  { \exp_after:wN \@@_single_construct:N }
\cs_set:Npn \@@_single_construct_f:N
  { \exp_args:Nf \@@_single_construct:N }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0.0}{2021/09/28}{将汉字盒子与边框按中心对齐,以使汉字居中}
%
% \begin{macro}{\@@_single_frame_construct:}
% 构造单个汉字盒子边框
%    \begin{macrocode}
\cs_new:Npn \@@_single_frame_construct:
  {
    \draw_begin:
      \draw_linewidth:n { \l_@@_linewidth_dim }
      \@@_aux_color_fill:
      \color_stroke:n { hanziboxframecolor }

      \exp_after:wN \draw_path_corner_arc:nn \l_@@_frame_arc_tl

      \draw_path_scope_begin:
        \@@_frame_type_c:n { \l_@@_frame_type_tl }
          { 0 } { 0 } { \hanziboxwidth } { \hanziboxheight } { 1.0 } { 1.0 }
        \draw_transform_shift:n {\hanziboxwidth / 2.0, \hanziboxheight / 2.0 }
        \draw_coffin_use:Nnn \l_@@_box_coffin { hc } { vc }
      \draw_path_scope_end:
    \draw_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{\pkg{xpinyin}宏包拼音后处理函数}
%
% \changes{v2.1.0}{2021/09/30}{添加从xpinyin宏包中提取拼音串函数。}
% 摘录自LaTeX工作室问答:如何得到xpinyin拼音宏包得到的拼音文本?
% (\url{https://ask.latexstudio.net/ask/question/3768.html})
%
% 变量定义
%    \begin{macrocode}
\tl_new:N \l_@@_save_tl
\tl_new:N \l_@@_hanzi_pinyin_tl
\tl_new:N \l_@@_tone_pinyin_tl
%    \end{macrocode}
%
% 构造声调表
%    \begin{macrocode}
\clist_const:Nn \c_@@_tone_a_clist { ā,á,ǎ,à,a }
\clist_const:Nn \c_@@_tone_o_clist { ō,ó,ǒ,ò,o }
\clist_const:Nn \c_@@_tone_e_clist { ē,é,ě,è,e }
\clist_const:Nn \c_@@_tone_u_clist { ū,ú,ǔ,ù,u }
\clist_const:Nn \c_@@_tone_i_clist { ī,í,ǐ,ì,i }
\clist_const:Nn \c_@@_tone_v_clist { ǖ,ǘ,ǚ,ǜ,ü }
%    \end{macrocode}
%
% \begin{macro}{\@@_pinyin_aux:n}
% 拼音生成辅助函数(改自xpinyin宏包的\verb!\__xpinyin_pinyin_aux:n #1!函数)
%    \begin{macrocode}
\cs_new_protected:Npn \@@_pinyin_aux:n #1
  {
    \quark_if_recursion_tail_stop_do:nn {#1}
      {
        \bool_if:NT \l__xpinyin_first_bool
          { \tl_set:NV \l_@@_tone_pinyin_tl \l__xpinyin_item_tl }
      }
    \__xpinyin_if_number:nTF {#1}
      {
        \bool_if:NT \l__xpinyin_first_bool
          { \bool_set_false:N \l__xpinyin_first_bool }
        \tl_put_right:NV \l_@@_tone_pinyin_tl \l__xpinyin_pre_tl
        \tl_put_right:Nx \l_@@_tone_pinyin_tl
          { \clist_item:cn { c_@@_tone_ \l__xpinyin_tone_tl _clist } {#1} }
        \tl_put_right:NV \l_@@_tone_pinyin_tl \l__xpinyin_post_tl
        \bool_if:NF \l_@@_autopinyin_bool
          {
            \tl_put_right:Nn \l_@@_tone_pinyin_tl {,}
          }
        \__xpinyin_pinyin_init:
      }
      {
        \int_compare:nNnTF
          { 0 \cs_if_exist_use:c { c__xpinyin_ \tl_to_str:N \l__xpinyin_tone_tl _tl } } >
          { 0 \cs_if_exist_use:c { c__xpinyin_ \tl_to_str:n {#1} _tl } }
          { \tl_put_right:Nn \l__xpinyin_post_tl {#1} }
          {
            \tl_set:Nn \l__xpinyin_tone_tl {#1}
            \tl_set_eq:NN \l__xpinyin_pre_tl \l__xpinyin_item_tl
            \tl_clear:N \l__xpinyin_post_tl
          }
        \tl_put_right:Nx \l__xpinyin_item_tl { \__xpinyin_replace_v:n {#1} }
      }
    \@@_pinyin_aux:n
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_get_tone_pinyin:n}
% 根据手动拼音得到拼音
%    \begin{macrocode}
\cs_new:Npn \@@_get_tone_pinyin:n #1
  {
    \tl_clear:N \l_@@_tone_pinyin_tl
    \__xpinyin_pinyin_init:
    \tl_set:Nn \l_@@_save_tl {#1}
    \bool_set_true:N \l__xpinyin_first_bool
    \@@_pinyin_aux:n #1 \q_recursion_tail \q_recursion_stop
  }
\cs_generate_variant:Nn  \@@_get_tone_pinyin:n { V }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_get_hanzi_pinyin:n}
% 自动拼音
%    \begin{macrocode}
\cs_new:Npn \@@_get_hanzi_pinyin:n #1
  {
    \tl_set_eq:Nc \l_tmpa_tl { c__xpinyin_ \__xpinyin_char_to_unicode:n {#1} _tl }
    \exp_args:No \tl_if_head_eq_meaning:nNTF { \l_tmpa_tl } \__xpinyin_pinyin:n
      {
        \exp_args:Nf \@@_get_tone_pinyin:n { \exp_after:wN \use_ii:nn \l_tmpa_tl }
        \tl_set_eq:NN \l_@@_hanzi_pinyin_tl \l_@@_tone_pinyin_tl
      }
      { \tl_set_eq:NN \l_@@_hanzi_pinyin_tl \l_tmpa_tl }
  }
%    \end{macrocode}
% \end{macro}
%
% \changes{v2.0.0}{2021/09/24}{添加从xpinyin宏包中提取拼音函数。}
% 代码摘录自LaTeX工作室:基于xpinyin宏包获取汉字的声母,韵母,声调
% (\url{https://www.latexstudio.net/index/details/index/mid/1994.html})
%
% 从需要的声母、韵母、读音表。
%
% 声母表
%    \begin{macrocode}
\clist_set:Nn \l_@@_initials_clist
  {
    {zh} , {ch} , {sh} , {b} , {p} , {m} , {f} ,
    {d}  , {t}  , {l}  , {k} , {h} , {j} , {q} ,
    {x}  , {r}  , {z}  , {c} , {s} , {y} , {w} ,
    {g}  , {n}
  }
%    \end{macrocode}
%
% \changes{v2.0.0}{2021/09/27}{修订部分错误带音调韵母表}
%
% 带声音调韵母表
%    \begin{macrocode}
\clist_set:Nn \l_@@_vowel_tone_clist
  {
    {iāng} , {iáng} , {iǎng} , {iàng} , {iang} ,
    {iōng} , {ióng} , {iǒng} , {iòng} , {iong} ,
    {uāng} , {uáng} , {uǎng} , {uàng} , {uang} ,
    {uēng} , {uéng} , {uěng} , {uèng} , {ueng} ,
    {āng}  , {áng}  , {ǎng}  , {àng}  , {ang}  ,
    {ēng}  , {éng}  , {ěng}  , {èng}  , {eng}  ,
    {īng}  , {íng}  , {ǐng}  , {ìng}  , {ing}  ,
    {ōng}  , {óng}  , {ǒng}  , {òng}  , {ong}  ,
    {uāi}  , {uái}  , {uǎi}  , {uài}  , {uai}  ,
    {uān}  , {uán}  , {uǎn}  , {uàn}  , {uan}  ,
    {uēi}  , {uéi}  , {uěi}  , {uèi}  , {uei}  ,
    {uāo}  , {uáo}  , {uǎo}  , {uào}  , {uao}  ,
    {iōu}  , {ióu}  , {iǒu}  , {iòu}  , {iou}  ,
    {iān}  , {ián}  , {iǎn}  , {iàn}  , {ian}  ,
    {üān}  , {üán}  , {üǎn}  , {üàn}  , {üan}  ,
    {uēn}  , {uén}  , {uěn}  , {uèn}  , {uen}  ,
    {āi}   , {ái}   , {ǎi}   , {ài}   , {ai}   ,
    {ēi}   , {éi}   , {ěi}   , {èi}   , {ei}   ,
    {uā}   , {uá}   , {uǎ}   , {uà}   , {ua}   ,
    {uō}   , {uó}   , {uǒ}   , {uò}   , {uo}   ,
    {uī}   , {uí}   , {uǐ}   , {uì}   , {ui}   ,
    {āo}   , {áo}   , {ǎo}   , {ào}   , {ao}   ,
    {ōu}   , {óu}   , {ǒu}   , {òu}   , {ou}   ,
    {iū}   , {iú}   , {iǔ}   , {iù}   , {iu}   ,
    {iā}   , {iá}   , {iǎ}   , {ià}   , {ia}   ,
    {iē}   , {ié}   , {iě}   , {iè}   , {ie}   ,
    {uē}   , {ué}   , {uě}   , {uè}   , {ue}   ,
    {üē}   , {üé}   , {üě}   , {üè}   , {üe}   ,
    {ēr}   , {ér}   , {ěr}   , {èr}   , {er}   ,
    {ān}   , {án}   , {ǎn}   , {àn}   , {an}   ,
    {ēn}   , {én}   , {ěn}   , {èn}   , {en}   ,
    {īn}   , {ín}   , {ǐn}   , {ìn}   , {in}   ,
    {ūn}   , {ún}   , {ǔn}   , {ùn}   , {un}   ,
    {ǖn}   , {ǘn}   , {ǚn}   , {ǜn}   , {ün}   ,
    {ā}    , {á}    , {ǎ}    , {à}    , {a}    ,
    {ē}    , {é}    , {ě}    , {è}    , {e}    ,
    {ī}    , {í}    , {ǐ}    , {ì}    , {i}    ,
    {ō}    , {ó}    , {ǒ}    , {ò}    , {o}    ,
    {ū}    , {ú}    , {ǔ}    , {ù}    , {u}    ,
    {ǖ}    , {ǘ}    , {ǚ}    , {ǜ}    , {ü}
  }
%    \end{macrocode}
%
% 韵母表
%    \begin{macrocode}
\clist_set:Nn \l_@@_vowel_clist
  {
    {iang} , {iong} , {uang} , {ueng} , {ang} , {eng} , {ing} ,
    {ong}  , {uai}  , {uan}  , {uai}  , {uei} , {iao} , {iou} ,
    {ian}  , {üan}  , {uen}  , {ai}   , {ei}  , {ua}  , {uo}  ,
    {ui}   , {ao}   , {ou}   , {iu}   , {ie}  , {üe}  , {er}  ,
    {an}   , {en}   , {in}   , {un}   , {ün}  , {a}   , {e}   ,
    {i}    , {o}    , {ü}    , {u}
  }
%    \end{macrocode}
%
% 声调表
%    \begin{macrocode}
\clist_set:Nn \l_@@_tone_num_clist
  {
    {ā} {a1} , {á} {a2} , {ǎ} {a3} , {à} {a4} ,
    {ō} {o1} , {ó} {o2} , {ǒ} {o3} , {ò} {o4} ,
    {ē} {e1} , {é} {e2} , {ě} {e3} , {è} {e4} ,
    {ū} {u1} , {ú} {u2} , {ǔ} {u3} , {ù} {u4} ,
    {ḿ} {m2} ,
    {ń} {n2} , {ň} {n3} , {ǹ} {n4} ,
    {ī} {i1} , {í} {i2} , {ǐ} {i3} , {ì} {i4} ,
    {ǖ} {v1} , {ǘ} {v2} , {ǚ} {v3} , {ǜ} {v4}
  }
%    \end{macrocode}
%
% 去声调表
%    \begin{macrocode}
\clist_set:Nn \l_@@_nonetone_clist
  {
    {ā} {a} , {á} {a} , {ǎ} {a} , {à} {a} ,
    {ō} {o} , {ó} {o} , {ǒ} {o} , {ò} {o} ,
    {ē} {e} , {é} {e} , {ě} {e} , {è} {e} ,
    {ū} {u} , {ú} {u} , {ǔ} {u} , {ù} {u} ,
    {ḿ} {m} ,
    {ń} {n} , {ň} {n} , {ǹ} {n} ,
    {ī} {i} , {í} {i} , {ǐ} {i} , {ì} {i} ,
    {ǖ} {ü} , {ǘ} {ü} , {ǚ} {ü} , {ǜ} {ü}
  }
%    \end{macrocode}
%
% \begin{macro}{\@@_split_pinyin_withtone:n}
% 分离拼音中的声母和带声调的韵母。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_split_pinyin_withtone:n #1
  {
    \int_zero:N  \l_@@_tone_int
    \str_clear:N \l_@@_pinyin_str
    \tl_clear:N  \l_@@_pinyin_tl
    \tl_clear:N  \l_@@_initial_tl
    \tl_clear:N  \l_@@_vowel_tl

    \tl_set:Nn \l_@@_pinyin_tl {#1}

    \tl_map_inline:Nn \l_@@_pinyin_tl
      {
        \str_put_right:Nn \l_@@_pinyin_str {##1}
      }

    \clist_map_inline:Nn \l_@@_initials_clist
      {
        \str_if_in:NnT { \l_@@_pinyin_str } {##1}
          {
            \tl_set:Nn \l_@@_initial_tl {##1}
            \clist_map_break:
          }
      }

    \clist_map_inline:Nn \l_@@_vowel_tone_clist
      {
        \str_if_in:NnT { \l_@@_pinyin_str } { ##1 }
          {
            \tl_set:Nn \l_@@_vowel_tl {##1}
            \clist_map_break:
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_split_pinyin_withouttone:n}
% 分离拼音中的声母和不带声调的韵母。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_split_pinyin_withouttone:n #1
  {
    \int_zero:N  \l_@@_tone_int
    \str_clear:N \l_@@_pinyin_str
    \tl_clear:N  \l_@@_pinyin_tl
    \tl_clear:N  \l_@@_initial_tl
    \tl_clear:N  \l_@@_vowel_tl

    \tl_set:Nn \l_@@_pinyin_tl {#1}

    \clist_map_inline:Nn \l_@@_nonetone_clist
      {
        \tl_replace_all:Nnn \l_@@_pinyin_tl ##1
      }

    \tl_map_inline:Nn \l_@@_pinyin_tl
      {
        \str_put_right:Nn \l_@@_pinyin_str {##1}
      }

    \clist_map_inline:Nn \l_@@_initials_clist
      {
        \str_if_in:NnT {\l_@@_pinyin_str} {##1}
          {
            \tl_set:Nn \l_@@_initial_tl {##1}
            \clist_map_break:
          }
      }

    \clist_map_inline:Nn \l_@@_vowel_clist
      {
        \str_if_in:NnT { \l_@@_pinyin_str } { ##1 }
          {
            \tl_set:Nn \l_@@_vowel_tl {##1}
            \clist_map_break:
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \end{implementation}
%
% \Finale
%
\endinput