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

`hanzibox` is a LaTeX package written to simplify the input of Chinese
with Hanyu Pinyin and translation. Hanyu Pinyin was placed above Chinese with
xpinyin package and the translation was placed below the Chinese.

`hanzibox` is a utility for creating practise sheets, dialogs, character explanations and more.
There are PDFs included which may be useful to regular users.

It was inspired by hanzibox.sty from https://github.com/janvorisek/chinese-latex-utilities.

In this new package, the commands were kept, but redesign its options and mandatories.

At present, hanzibox.sty only supports XeTeX engines and only allows UTF-8 encoding tex source file.

You can read the package manual (in Chinese) for more detailed explanations.

Gitee repository: https://gitee.com/nwafu_nan/hanzibox-l3.

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

Issues and pull requests are welcome.

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 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/latex/hanzibox}
    \file{hanzibox.ins} {\from{\jobname.dtx}{install}}
%</internal>
%<*install>
    \usedir{tex/latex/hanzibox}
    \file{hanzibox.sty} {\from{\jobname.dtx}{package}}
    \nopreamble\nopostamble
    \usedir{doc/latex/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 1.0.0 2021-09-18 20:00:00Z +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{xpinyin}
\usepackage{hanzibox}
\renewcommand*\marg[1]{\{\meta{#1}\}}
\renewcommand*\oarg[1]{[\meta{#1}]}
\renewcommand*\parg[1]{(\meta{#1})}
\DeclareDocumentCommand\opt{m}{\texttt{#1}}
\DeclareDocumentCommand\kvopt{mm}
  {\texttt{#1\breakablethinspace=\breakablethinspace#2}}
\def\breakablethinspace{\hskip 0.16667em\relax}
\begin{document}
  \DocInput{\jobname.dtx}
  \IndexLayout
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \changes{v1.0.0}{2021/09/18}{开始编写模板。}
%
% \CheckSum{0}
%
% \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{hanzibox.sty}
%
% \title{\bfseries\pkg{hanzibox}:田字格-米字格汉字练习宏包}
% \author{耿楠\\ \path{nangeng@nwafu.edu.cn}}
% \date{\filedate\qquad\fileversion\thanks{\url{https://gitee.com/nwafu_nan/hanzibox-l3}.}}
% \maketitle
%
% \begin{documentation}
%
% \begin{abstract}
%
% \pkg{hanzibox} 是一个用\LaTeX3开发的 \LaTeX 宏包,提供了汉字学习中的田字格
% 或米字格功能,并可以根据需要在汉字正上方显示拼音,在正下方显示需要的译文。
%
% \end{abstract}
%
% \section{简要说明}
%
% 建议使用\pkg{hanzibox}宏包的\LaTeX 源文件总是采用 \texttt{UTF-8}。
%
% \pkg{hanzibox} 还依赖 \package{l3kernel} 和 \package{l3packages}。
%
% \section{用户接口}
%
% \begin{function}[added=2021-09-18,updated=2021-09-19]{\hanzidialog}
%   \begin{syntax}
%     \tn{hanzidialog} \Arg{汉字} \oarg{拼音选项} \oarg{译文选项}
%   \end{syntax}
%   排版汉字,并根据选项内容在顶部排版拼音,在底部排版译文。\\
%   其中,\oarg{拼音选项}可以是任意文本,如果是汉语拼音则需要使用\pkg{xpinyin}宏包的
%   \tn{pinyin}命令进行处理;\oarg{译文选项}可以是任意文本。
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.3\linewidth,gobble=5]
%     \hanzidialog{王老师}[Wang \pinyin{lao3shi1}][teacher wang]
%     \hanzidialog{王老师}[Wang \pinyin{lao3shi1}][王先生]
%   \end{SideBySideExample}
% \end{function}
%
% \begin{function}[added=2021-09-18,updated=2021-09-20]{\hanzibox,\hanzibox*}
%   \begin{syntax}
%     \tn{hanzibox} \oarg{外观选项} \Arg{汉字} \oarg{拼音选项} \oarg{译文选项}
%     \tn{hanzibox*} \oarg{外观选项} \Arg{汉字} \oarg{拼音选项} \oarg{译文选项}
%   \end{syntax}
%   排版汉字,并根据选项内容在顶部排版拼音,在底部排版译文。\\
%   其中,\oarg{外观选项}用于设置盒子外观;\oarg{拼音选项}用于设置拼音,
%   要求其拼音格式符合\pkg{xpinyin}宏包的规定;\oarg{译文选项}可以是任意文本。
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.43\linewidth,gobble=5]
%     \hanzibox[inner=none,border=false]{我}[wo3][me]
%     \hanzibox[inner=cross,border=true]{我}[wo3][吾]
%     \hanzibox[inner=star]{我}[wo3][俺]
%     \hanzibox[borderwidth=1.5pt]{我}[wo3][爷]
%     \hanzibox[bordercolor=red]{我}[wo3][山人]
%   \end{SideBySideExample}
%   星号命令用于根据汉字自动在顶部排版拼音,在底部排版译文。\\
%   此时,\oarg{拼音选项}中的拼音无效,可以留空,但若有译文则该选项不可省略;
%   \oarg{译文选项}可以是任意文本。\\
%   注意:此时的注意由\pkg{xpinyin}宏包实现,如需要设置多音字的拼音,请参阅其宏包说明。
%   \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.43\linewidth,gobble=5]
%     \hanzibox*[inner=none,border=false]{我}[][me]
%     \hanzibox*[inner=cross,border=true]{我}[][吾]
%     \hanzibox*[inner=star]{我}[wo3][不才]
%     \hanzibox*[borderwidth=1.5pt]{我}[wo2][本人]
%     \hanzibox*[bordercolor=red]{我}[ni3][孤家]
%   \end{SideBySideExample}
% \end{function}
%
% \section{选项说明}
%
% \begin{function}[added=2021-09-20]{\hanziboxset}
%   \begin{syntax}
%     \tn{hanziboxset} \marg{键值列表}
%   \end{syntax}
%   本宏包提供了一系列选项,以实现汉字盒子外观样式设置。
%   载入\pkg{hanzibox}宏包后,以下选项均可通过统一的\tn{hanziboxset}命令进行设置。
%   同时,这些选项也可以通过\tn{hanzibox}命令的外观选项进行设置。
% \end{function}
%
% \tn{hanziboxset} 的参数是一组由(英文)逗号隔开的选项列表,
% 列表中的选项通常是 \kvopt{\meta{key}}{\meta{value}} 形式。
% 部分选项的\meta{value} 可以省略。对于同一项,后续设置会覆盖以前的设置。
% 在下文的说明中,将用\textbf{粗体}表示默认值。
%
% \tn{hanziboxset} 采用 \LaTeX3 风格的键值设置,支持不同类型以及多种
% 层次的选项设定。键值列表中,“|=|”左右的空格不影响设置;但需注意,
% 参数列表中\textbf{不可以出现空行}。
%
% 布尔型的参数 \kvopt{\meta{选项}}{true} 中的“|= true|”可以省略。
%
% 注:各选项也可以以相同的键值列表在汉字盒子命令的外观选项中进行设置。
%
% \subsection{缩放比例}
%
% \begin{function}[added=2021-09-20]{ratio}
%   \begin{syntax}
%     ratio = \Arg{number}
%   \end{syntax}
%   设置\tn{hanzibox}命令绘制汉字盒子及其拼音和译文的整体缩放比例,默认值为\textbf{1.0}。
% \end{function}
%
%
% \subsection{汉字边框}
%
% \begin{function}[added=2021-09-20]{border}
%   \begin{syntax}
%     border = <\TTF>
%   \end{syntax}
%   为\tn{hanzibox}命令选择是否绘制汉字的边框,默认值为\textbf{true}。该选项对\tn{hanzidialog}命令无效。
% \end{function}
%
% \begin{function}[added=2021-09-20]{borderwidth}
%   \begin{syntax}
%     borderwidth = \Arg{dimen}
%   \end{syntax}
%   为\tn{hanzibox}命令设置汉字的边框宽度,默认值为\textbf{0.4pt}。该选项对\tn{hanzidialog}命令无效。
% \end{function}
%
% \begin{function}[added=2021-09-20]{bordercolor}
%   \begin{syntax}
%     bordercolor = \Arg{color}
%   \end{syntax}
%   为\tn{hanzibox}命令设置汉字的边框颜色,默认值为\textbf{black}。该选项对\tn{hanzidialog}命令无效。
% \end{function}
%
% \subsection{格子样式}
%
% \begin{function}[added=2021-09-20]{inner}
%   \begin{syntax}
%     inner = <(none)|star|cross>
%   \end{syntax}
%   为\tn{hanzibox}命令设置汉字盒子内部装饰为无(none)、米字格(star)或田字格(cross),
%   默认值为\textbf{none}。该选项对\tn{hanzidialog}命令无效。
% \end{function}
%
% \end{documentation}
%
% \StopEventually{}
%
% \begin{implementation}
%
% \section{代码实现}
%
% 本宏包使用 \LaTeX3 语法编写,依赖 \pkg{expl3} 环境,
% 并需调用 \pkg{l3packages} 中的相关宏包。
%
% 按照 \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, 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
  {
    \sys_if_engine_luatex:F
      {
        \msg_fatal:nnx { hanzibox } { unsupported-engine }
          { \c_sys_engine_str }
      }
  }
\msg_new:nnn { hanzibox } { unsupported-engine }
  {
    The~ hanzibox~ packages~ requires~ either~ XeTeX~ or~ LuaTeX. \\\\
    "#1"~ is~ not~ supported~ at~ present.~ You~ must~ change \\
    your~ typesetting~ engine~ to~ "xelatex"~ or~ "lualatex".
  }

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

%    \end{macrocode}
%
% 在Expl3中使用TikZ库的补丁
%
%    \begin{macrocode}
\RequirePackage{etoolbox}
\ExplSyntaxOff
\patchcmd
  {\pgfutil@InputIfFileExists}
  {\input #1}
  {%
    \@pushfilename
    \xdef\@currname{#1}%
    \input #1 %
    \@popfilename
  }
  {}{}
\ExplSyntaxOn
\usetikzlibrary{decorations}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{positioning}

%    \end{macrocode}
%
% TikZ样式设置
%
%    \begin{macrocode}
\tikzset{%
  stretch~dash/.code~args={on~#1~off~#2}{%
    \tikz@addoption{%
      \pgfgetpath\currentpath%
      \pgfprocessround{\currentpath}{\currentpath}%
      \pgf@decorate@parsesoftpath{\currentpath}{\currentpath}%
      \pgfmathparse{max(round((\pgf@decorate@totalpathlength-#1)/(#1+#2)),0)}%
      \let\npattern=\pgfmathresult%
      \pgfmathparse{\pgf@decorate@totalpathlength/(\npattern*(#1+#2)+#1)}%
      \let\spattern=\pgfmathresult%
      \pgfsetdash{{\spattern*#1}{\spattern*#2}}{0pt}%
    }%
  }%
}

%    \end{macrocode}
%
% \subsection{用户接口}
%
% \begin{macro}{\hanzidialog}
% 手动汉字盒子命令。
%    \begin{macrocode}
\NewDocumentCommand{\hanzidialog}{ m O{} O{} }
  {
    \@@_dialog:nnnn { #1 } { #2 } { #3 }
  }

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\hanzibox}
% 自动拼音汉字盒子命令。
%    \begin{macrocode}
\NewDocumentCommand{\hanzibox}{ s O{} m O{} O{} }
  {
    \IfBooleanTF{#1}
      {
        \@@_star_draw:nnnn { #2 } { #3 } { #4 } { #5 }
      }{
        \@@_draw:nnnn { #2 } { #3 } { #4 } { #5 }
      }
  }

%    \end{macrocode}
% \end{macro}
%
% \subsection{内部变量声明}
%
% \begin{variable}{\l_@@_inner_int,
%   \l_@@_border_bool,
%   \l_@@_borderwidth_dim,
%   \l_@@_bordercolor_tl,
%   \l_@@_pinyin_tl,
%   \l_@@_character_tl,
%   \l_@@_translation_tl,
%   \l_@@_pinyin_int,
%   \l_@@_character_int,
%   \l_@@_translation_int
%  }
% 临时变量。
%    \begin{macrocode}
\fp_new:N \l_@@_ratio_fp
\int_new:N \l_@@_inner_int
\bool_new:N \l_@@_border_bool
\dim_new:N \l_@@_borderwidth_dim
\tl_new:N \l_@@_bordercolor_tl
\tl_new:N \l_@@_pinyin_tl
\tl_new:N \l_@@_character_tl
\tl_new:N \l_@@_translation_tl
\int_new:N \l_@@_pinyin_int
\int_new:N \l_@@_character_int
\int_new:N \l_@@_translation_int

%    \end{macrocode}
% \end{variable}
%
%
% \subsection{选项处理}
%
% 定义 |hanzibox| 键值类。
%    \begin{macrocode}
\keys_define:nn { hanzibox }
  {
%    \end{macrocode}
%
% \begin{macro}{ratio}
% 设置汉字及其拼音和译文的整体缩放比例。
%    \begin{macrocode}
    ratio .fp_set:N  = \l_@@_ratio_fp,
    ratio .initial:n = 1.0,

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{inner}
% 设置汉字格子内部样式,有空白、米字和十字3种样式,默认为空白样式。
%    \begin{macrocode}
    inner .choice:,
    inner .value_required:n = true,
    inner .choices:nn =
      { none,star,cross }
      { \int_set_eq:NN \l_@@_inner_int \l_keys_choice_int },
    inner .initial:n = none,

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{border}
% 是否绘制汉字盒子边框,默认为空true。
%    \begin{macrocode}
    border .bool_set:N = \l_@@_border_bool,
    border .default:n = true,
    border .initial:n = true,

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{borderwidth}
% 汉字盒子边框宽度,默认为空3 pt。
%    \begin{macrocode}
    borderwidth .dim_set:N  = \l_@@_borderwidth_dim,
    borderwidth .initial:n = 0.4 pt,

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{bordercolor}
% 汉字盒子边框颜色,默认为black。
%    \begin{macrocode}
    bordercolor .tl_set:N  = \l_@@_bordercolor_tl,
    bordercolor .initial:n = black,

%    \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}
%
% \subsection{选项用户接口}
%
% \begin{macro}{\hanziboxset}
% 选项设置用户接口。
%    \begin{macrocode}
\NewDocumentCommand \hanziboxset { m }
  { \keys_set:nn { hanzibox } {#1} }
%    \end{macrocode}
% \end{macro}
%
% \subsection{内部函数}
%
% \begin{macro}{\@@_dialog:nnnn}
% 手动汉字盒子排版内部命令,根据选项用TikZ实现绘制。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_dialog:nnnn #1#2#3
  {
    \tl_set:Nx \l_@@_character_tl {#1}
    \tl_set:Nx \l_@@_pinyin_tl {#2}
    \tl_set:Nx \l_@@_translation_tl {#3}
    \scalebox{\fp_use:N \l_@@_ratio_fp}{
      \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{%
        {\node[] at (1,1){\huge{\tl_use:N \l_@@_character_tl}}};
        {\node[label={\strut\small\textbf{\tl_use:N \l_@@_pinyin_tl}},
          text~height=1cm] (charr) at (1,1){};}%
        {\node[align=center] at (1,-0.5)
          {\strut\small\textit{\tl_use:N \l_@@_translation_tl}};}%
      }%
    }%
  }

%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_pinyinaux:n}
% \begin{macro}{\@@_pinyinaux:x}
% \pkg{xpyinyin}宏包\tn{pinyin} 命令的\LaTeX3{}版本函数及其函数变体。
%    \begin{macrocode}
\cs_set_eq:NN \@@_pinyinaux:n \pinyin
\cs_generate_variant:Nn \@@_pinyinaux:n { x }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_draw:nnnn}
% 自动汉字盒子排版内部命令,根据选项用TikZ实现绘制。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_draw:nnnn #1#2#3#4
  {
%    \end{macrocode}
%
% 设置盒子外观选项
%
%    \begin{macrocode}
    \keys_set:nn { hanzibox } { #1 }
%    \end{macrocode}
%
% 将各参数存入token list变量,注意使用x递归展开
%
%    \begin{macrocode}
    \tl_set:Nx \l_@@_character_tl {#2}
    \tl_set:Nx \l_@@_pinyin_tl {#3}
    \tl_set:Nx \l_@@_translation_tl {#4}
%    \end{macrocode}
%
% 计算token list中的内容长度(个数)
%
%    \begin{macrocode}
    \int_set:Nn \l_@@_character_int
      {
        \tl_count:V \l_@@_character_tl
      }
    \int_set:Nn \l_@@_pinyin_int
      {
        \tl_count:V \l_@@_pinyin_tl
      }
    \int_set:Nn \l_@@_translation_int
      {
        \tl_count:V \l_@@_translation_tl
      }

    \scalebox{\fp_use:N \l_@@_ratio_fp}{
    \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{%
      \int_compare:nNnT { \l_@@_character_int } < {2}
        {
          \int_case:nn {\l_@@_inner_int}
            {
              {1}{
              }
              {2}{
                \draw[stretch~dash=on~2pt~off~2pt,thin,
                      \tl_use:N \l_@@_bordercolor_tl!50](0,0)--(2,2);%
                \draw[stretch~dash=on~2pt~off~2pt,thin,
                      \tl_use:N \l_@@_bordercolor_tl!50](0,2)--(2,0);%

                \draw[stretch~dash=on~2pt~off~2pt,thin,
                      \tl_use:N \l_@@_bordercolor_tl!50](0,1)--(2,1);%
                \draw[stretch~dash=on~2pt~off~2pt,thin,
                      \tl_use:N \l_@@_bordercolor_tl!50](1,0)--(1,2);%
              }
              {3}{
                \draw[stretch~dash=on~2pt~off~2pt,thin,
                      \tl_use:N \l_@@_bordercolor_tl!50](0,1)--(2,1);%
                \draw[stretch~dash=on~2pt~off~2pt,thin,
                      \tl_use:N \l_@@_bordercolor_tl!50](1,0)--(1,2);%
              }
            }
        }
      \int_compare:nNnTF { \l_@@_character_int } = {0}
        {
          \draw[line~width=\dim_use:N \l_@@_borderwidth_dim,
                \tl_use:N \l_@@_bordercolor_tl] (0,0) rectangle(2,2);
          \node[] at (1,1){\huge{\tl_use:N \l_@@_character_tl}};
          \int_compare:nNnTF { \l_@@_pinyin_int } = {0}
            { }
            {
              \node[label={\strut\small\@@_pinyinaux:x {\l_@@_pinyin_tl}},
                text~height=1cm] (charr) at (1,1){};
            }
          \int_compare:nNnTF { \l_@@_translation_int } = {0}
            { }
            {
              \node[align=center] at (1,-0.5)
                {\strut\small\textit{\tl_use:N \l_@@_translation_tl}};
            }
        }
        {
          \bool_if:NTF \l_@@_border_bool
            {
              \draw[line~width=\dim_use:N \l_@@_borderwidth_dim,
                \tl_use:N \l_@@_bordercolor_tl] (0,0) rectangle(2*\l_@@_character_int,2);
            }{}

          \node[] at (1*\l_@@_character_int,1)
            {\huge\tl_use:N \l_@@_character_tl};

          \int_compare:nNnTF { \l_@@_pinyin_int } = {0}
            { }
            {
              \node[label={\strut\small\@@_pinyinaux:x {\l_@@_pinyin_tl}},
                text~height=1cm] (charr) at (1*\l_@@_character_int,1){};
            }

          \int_compare:nNnTF { \l_@@_translation_int } = {0}
            { }
            {
              \node[align=center] at (1*\l_@@_character_int,-0.5)
                {\strut\small\textit{\tl_use:N \l_@@_translation_tl}};
            }
        }
    }%
    }%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_star_draw:nnnn}
% 自动汉字拼音盒子排版内部命令,根据选项用TikZ实现绘制。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_star_draw:nnnn #1#2#3#4
  {
%    \end{macrocode}
%
% 设置盒子外观选项
%
%    \begin{macrocode}
    \keys_set:nn { hanzibox } { #1 }
%    \end{macrocode}
%
% 将各参数存入token list变量,注意使用x递归展开
%
%    \begin{macrocode}
    \tl_set:Nx \l_@@_character_tl {#2}
    \tl_set:Nx \l_@@_pinyin_tl {#3}
    \tl_set:Nx \l_@@_translation_tl {#4}
%    \end{macrocode}
%
% 计算token list中的内容长度(个数)
%
%    \begin{macrocode}
    \int_set:Nn \l_@@_character_int
      {
        \tl_count:V \l_@@_character_tl
      }
    \int_set:Nn \l_@@_pinyin_int
      {
        \tl_count:V \l_@@_pinyin_tl
      }
    \int_set:Nn \l_@@_translation_int
      {
        \tl_count:V \l_@@_translation_tl
      }

    \scalebox{\fp_use:N \l_@@_ratio_fp}{
    \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{%
      \int_compare:nNnT { \l_@@_character_int } < {2}
        {
          \int_case:nn {\l_@@_inner_int}
            {
              {1}{
              }
              {2}{
                \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm,
                      \tl_use:N \l_@@_bordercolor_tl!50](0,0)--(2,2);%
                \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm,
                      \tl_use:N \l_@@_bordercolor_tl!50](0,2)--(2,0);%

                \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm,
                      \tl_use:N \l_@@_bordercolor_tl!50](0,1)--(2,1);%
                \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm,
                      \tl_use:N \l_@@_bordercolor_tl!50](1,0)--(1,2);%
              }
              {3}{
                \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm,
                      \tl_use:N \l_@@_bordercolor_tl!50](0,1)--(2,1);%
                \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm,
                      \tl_use:N \l_@@_bordercolor_tl!50](1,0)--(1,2);%
              }
            }
        }
      \int_compare:nNnTF { \l_@@_character_int } = {0}
        {
          \draw[line~width=\dim_use:N \l_@@_borderwidth_dim, yshift=-0.5cm,
                \tl_use:N \l_@@_bordercolor_tl] (0,0) rectangle(2,2);
          \node[] at (1,1){\huge{\xpinyin*[vsep=0.85 cm]{\tl_use:N \l_@@_character_tl}}};
          \int_compare:nNnTF { \l_@@_translation_int } = {0}
            { }
            {
              \node[align=center] at (1,-1.0)
                {\strut\small\textit{\tl_use:N \l_@@_translation_tl}};
            }
        }
        {
          \bool_if:NTF \l_@@_border_bool
            {
              \draw[line~width=\dim_use:N \l_@@_borderwidth_dim, yshift=-0.5cm,
                \tl_use:N \l_@@_bordercolor_tl] (0,0) rectangle(2*\l_@@_character_int,2);
            }{}

          \node[] at (1*\l_@@_character_int,1)
            {\huge{\xpinyin*[vsep=0.90 cm]{\tl_use:N \l_@@_character_tl}}};

          \int_compare:nNnTF { \l_@@_translation_int } = {0}
            { }
            {
              \node[align=center] at (1*\l_@@_character_int,-1.0)
                {\strut\small\textit{\tl_use:N \l_@@_translation_tl}};
            }
        }
    }%
    }%
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \end{implementation}
%
% \Finale
%
\endinput