diff options
Diffstat (limited to 'Master/texmf-dist/tex/xelatex')
-rw-r--r-- | Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty | 1150 |
1 files changed, 863 insertions, 287 deletions
diff --git a/Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty b/Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty index bade0bc6be0..c45171e06c4 100644 --- a/Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty +++ b/Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty @@ -27,12 +27,12 @@ %% \NeedsTeXFormat{LaTeX2e}[2020/10/01] \RequirePackage{expl3} -\GetIdInfo$Id: hanzibox.dtx 1.1.0 2021-09-23 08:00:00 +0800 Nan Geng <nangeng@nwafu.edu.cn> $ +\GetIdInfo$Id: hanzibox.dtx 2.0.0 2021-09-28 08:00:00 +0800 Nan Geng <nangeng@nwafu.edu.cn> $ {Boxed Chinese characters with Pinyin above and translation below.} \ProvidesExplPackage{\ExplFileName} {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} -\RequirePackage { xtemplate, l3keys2e, xparse } +\RequirePackage { xtemplate, l3keys2e, l3draw, xparse } \sys_if_engine_xetex:F { @@ -41,374 +41,950 @@ } \msg_new:nnn { hanzibox } { unsupported-engine } { - The~ hanzibox~ packages~ requires~ either~ XeTeX. \\\\ + The~ hanzibox~ packages~ requires~ XeTeX. \\\\ "#1"~ is~ not~ supported~ at~ present.~ You~ must~ change \\ your~ typesetting~ engine~ to~ "xelatex"~ or~ "lualatex". } -\RequirePackage { tikz, xpinyin } - -\RequirePackage{etoolbox} -\ExplSyntaxOff -\patchcmd - {\pgfutil@InputIfFileExists} - {\input #1} - {% - \@pushfilename - \xdef\@currname{#1}% - \input #1 % - \@popfilename - } - {}{} -\ExplSyntaxOn -\usetikzlibrary{decorations} -\usetikzlibrary{shapes.geometric} -\usetikzlibrary{positioning} - -\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}% - }% - }% -} - -\NewDocumentCommand{\hanzidialog}{ m O{} O{} } - { - \group_begin: - \__hanzibox_dialog:nnnn { #1 } { #2 } { #3 } - \group_end: - } +\RequirePackage { xpinyin } \NewDocumentCommand{\hanzibox}{ s O{} m O{} O{} } { \IfBooleanTF{#1} { - \group_begin: - \__hanzibox_asterisk_draw:nnnn { #2 } { #3 } { #4 } { #5 } - \group_end: + \bool_set_false:N \l__hanzibox_autopinyin_bool }{ - \group_begin: - \__hanzibox_draw:nnnn { #2 } { #3 } { #4 } { #5 } - \group_end: - } - } - -\fp_new:N \l__hanzibox_scale_fp -\int_new:N \l__hanzibox_inner_int -\bool_new:N \l__hanzibox_border_bool -\dim_new:N \l__hanzibox_borderwidth_dim -\tl_new:N \l__hanzibox_bordercolor_tl -\tl_new:N \l__hanzibox_fgcolor_tl -\tl_new:N \l__hanzibox_bgcolor_tl -\bool_new:N \l__hanzibox_pinyin_bool -\bool_new:N \l__hanzibox_hanzi_bool -\bool_new:N \l__hanzibox_tran_bool -\tl_new:N \l__hanzibox_pinyin_tl -\tl_new:N \l__hanzibox_character_tl -\tl_new:N \l__hanzibox_translation_tl -\int_new:N \l__hanzibox_pinyin_int -\int_new:N \l__hanzibox_character_int -\int_new:N \l__hanzibox_translation_int + \bool_set_true:N \l__hanzibox_autopinyin_bool + } + \group_begin: + \__hanzibox_handle:nnnn { #2 } { #3 } { #4 } { #5 } + \group_end: + } -\keys_define:nn { hanzibox } +\NewDocumentCommand{\hanzidialog}{O{} m O{} O{} } { - scale .fp_set:N = \l__hanzibox_scale_fp, - scale .initial:n = 1.0, + \group_begin: + \bool_set_false:N \l__hanzibox_autopinyin_bool + \__hanzibox_dialog:nnnn { #1 } { #2 } { #3 } { #4 } + \group_end: + } + +\bool_new:N \l__hanzibox_autopinyin_bool +\bool_new:N \l__hanzibox_withinitials_bool +\bool_new:N \l__hanzibox_withvowel_bool +\bool_new:N \l__hanzibox_withtone_bool +\bool_new:N \l__hanzibox_withpinyin_bool +\bool_new:N \l__hanzibox_withhanzi_bool +\bool_new:N \l__hanzibox_withtran_bool - inner .choice:, - inner .value_required:n = true, - inner .choices:nn = - { none,star,cross } - { \int_set_eq:NN \l__hanzibox_inner_int \l_keys_choice_int }, - inner .initial:n = none, +\box_new:N \l__hanzibox_basebox_box +\tl_new:N \l__hanzibox_frame_type_tl +\clist_new:N \g__hanzibox_frame_list_clist +\tl_new:N \l__hanzibox_resize_method_tl +\clist_new:N \g__hanzibox_resize_method_clist +\dim_new:N \l__hanzibox_frame_size_dim +\dim_new:N \l__hanzibox_char_width_dim +\dim_new:N \l__hanzibox_char_height_dim +\dim_new:N \l__hanzibox_box_width_dim +\dim_new:N \l__hanzibox_box_height_dim +\dim_new:N \l__hanzibox_linewidth_dim - border .bool_set:N = \l__hanzibox_border_bool, - border .default:n = true, - border .initial:n = true, +\coffin_new:N \l__hanzibox_str_box_coffin +\coffin_new:N \l__hanzibox_box_coffin +\coffin_new:N \l__hanzibox_pinyin_box_coffin +\coffin_new:N \l__hanzibox_tran_box_coffin +\coffin_new:N \l__hanzibox_tmpa_coffin +\coffin_new:N \l__hanzibox_tmpb_coffin - borderwidth .dim_set:N = \l__hanzibox_borderwidth_dim, - borderwidth .initial:n = 0.4 pt, +\dim_new:N \hanziboxwidth +\dim_new:N \hanziboxheight +\dim_new:N \hanziboxboxwd +\dim_new:N \hanziboxboxht +\dim_new:N \hanziboxboxdp +\tl_new:N \hanziboxxscaleratio +\tl_new:N \hanziboxyscaleratio - bordercolor .tl_set:N = \l__hanzibox_bordercolor_tl, - bordercolor .initial:n = black, +\tl_new:N \l__hanzibox_pinyin_tl +\tl_new:N \l__hanzibox_character_tl +\tl_new:N \l__hanzibox_translation_tl +\tl_new:N \l__hanzibox_pinyin_format_tl +\tl_new:N \l__hanzibox_character_format_tl +\tl_new:N \l__hanzibox_translation_format_tl +\int_new:N \l__hanzibox_pinyin_int +\int_new:N \l__hanzibox_character_int +\int_new:N \l__hanzibox_translation_int - fgcolor .tl_set:N = \l__hanzibox_fgcolor_tl, - fgcolor .initial:n = black, +\int_new:N \l__hanzibox_tone_int +\str_new:N \l__hanzibox_pinyin_str +\tl_new:N \l__hanzibox_initial_tl +\tl_new:N \l__hanzibox_vowel_tl + +\cs_new_nopar:Nn \__hanzibox_aux_color_fill: + { } +\cs_new:Npn \__hanzibox_calc_basechar_w_h: + { + \dim_set:Nn \l__hanzibox_char_width_dim + { + \box_wd:N \l__hanzibox_basebox_box + } + \dim_set:Nn \l__hanzibox_char_height_dim + { + \box_ht_plus_dp:N \l__hanzibox_basebox_box + } + } +\cs_new_nopar:Npn \__hanzibox_coffin_ht_plus_dp:N #1 + { + \coffin_ht:N #1 + \coffin_dp:N #1 + } +\cs_new:Npn \__hanzibox_calc_frame_size: + { + \hbox_set:Nn \l_tmpa_box + { + \tl_use:N \l__hanzibox_character_format_tl + \tl_use:N \c__hanzibox_basechar_tl + } - bgcolor .tl_set:N = \l__hanzibox_bgcolor_tl, - bgcolor .initial:n = white, + \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 + } - withpinyin .bool_set:N = \l__hanzibox_pinyin_bool, - withpinyin .default:n = true, - withpinyin .initial:n = true, + \dim_compare:nNnTF \l_tmpa_dim > \l_tmpb_dim + { + \dim_gset_eq:NN \l__hanzibox_frame_size_dim \l_tmpa_dim + } + { + \dim_gset_eq:NN \l__hanzibox_frame_size_dim \l_tmpb_dim + } - withhanzi .bool_set:N = \l__hanzibox_hanzi_bool, - withhanzi .default:n = true, - withhanzi .initial:n = true, + \dim_gadd:Nn \l__hanzibox_frame_size_dim { 2pt } - withtran .bool_set:N = \l__hanzibox_tran_bool, - withtran .default:n = true, - withtran .initial:n = true, + \dim_gset_eq:NN \hanziboxwidth \l__hanzibox_frame_size_dim + \dim_gset_eq:NN \hanziboxheight \l__hanzibox_frame_size_dim - unknown .code:n = { \__hanzibox_error:n { unknown-option } } } -\msg_new:nnn { hanzibox } { unknown-option } - { package~ option~ "\l_keys_key_tl"~ is~ unknown. } +\cs_new_nopar:Npn \__hanzibox_frame_type:n #1 + { + __hanzibox_frame_construct_type_ #1 :nnnnnn + } +\cs_new_nopar:Npn \__hanzibox_frame_type_c:n #1 + { + \use:c + { + __hanzibox_frame_construct_type_ #1 :nnnnnn + } + } +\cs_new:Npn \__hanzibox_new_frame_construct:nn #1 + { + \clist_put_right:Nn \g__hanzibox_frame_list_clist {#1} + \cs_new:cn { \__hanzibox_frame_type:n {#1} } + } +\__hanzibox_new_frame_construct:nn { none } { } +\__hanzibox_new_frame_construct:nn { 口 } + { + \color_stroke:n { hanziboxframecolor } + \draw_path_rectangle_corners:nn { #1, #2} { #3, #4} -\NewDocumentCommand \hanziboxset { m } - { \keys_set:nn { hanzibox } {#1} } -\cs_new_protected:Npn \__hanzibox_dialog:nnnn #1#2#3 - { - \tl_set:Nx \l__hanzibox_character_tl {#1} - \tl_set:Nx \l__hanzibox_pinyin_tl {#2} - \tl_set:Nx \l__hanzibox_translation_tl {#3} - \scalebox{\fp_use:N \l__hanzibox_scale_fp}{ - \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{% - {\node[] at (1,1){\huge{\l__hanzibox_character_tl}}}; - {\node[label={\strut\small\textbf{\l__hanzibox_pinyin_tl}}, - text~height=1cm] (charr) at (1,1){};}% - {\node[align=center] at (1,-0.5) - {\strut\small\textit{\l__hanzibox_translation_tl}};}% - }% - }% + \cs_if_eq:NNTF \__hanzibox_aux_color_fill: \c_empty_tl + { + \draw_path_use_clear:n { stroke } + } + { + \draw_path_use_clear:n { stroke , fill } + } } -\cs_set_eq:NN \__hanzibox_pinyinaux:n \pinyin -\cs_generate_variant:Nn \__hanzibox_pinyinaux:n { x } -\cs_new_protected:Npn \__hanzibox_draw:nnnn #1#2#3#4 +\__hanzibox_new_frame_construct:nn { 十 } + { + \tl_if_empty:NF \l__hanzibox_dash_pattern_tl + { + \exp_args:No \draw_dash_pattern:nn { \l__hanzibox_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 } + } + +\__hanzibox_new_frame_construct:nn { × } + { + \tl_if_empty:NF \l__hanzibox_dash_pattern_tl + { + \exp_args:No \draw_dash_pattern:nn { \l__hanzibox_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 } + } + +\__hanzibox_new_frame_construct:nn { 田 } + { + \__hanzibox_frame_type_c:n { 口 } {#1} {#2} {#3} {#4} {#5} {#6} + \__hanzibox_frame_type_c:n { 十 } {#1} {#2} {#3} {#4} {#5} {#6} + } + +\__hanzibox_new_frame_construct:nn { 米 } + { + \__hanzibox_frame_type_c:n { × } {#1} {#2} {#3} {#4} {#5} {#6} + \__hanzibox_frame_type_c:n { 十 } {#1} {#2} {#3} {#4} {#5} {#6} + } + +\__hanzibox_new_frame_construct:nn { 咪 } { - \keys_set:nn { hanzibox } { #1 } - \tl_set:Nx \l__hanzibox_character_tl {#2} - \tl_set:Nx \l__hanzibox_pinyin_tl {#3} - \tl_set:Nx \l__hanzibox_translation_tl {#4} - \int_set:Nn \l__hanzibox_character_int + \__hanzibox_frame_type_c:n { 口 } {#1} {#2} {#3} {#4} {#5} {#6} + \__hanzibox_frame_type_c:n { × } {#1} {#2} {#3} {#4} {#5} {#6} + \__hanzibox_frame_type_c:n { 十 } {#1} {#2} {#3} {#4} {#5} {#6} + } +\cs_new_nopar:Npn \__hanzibox_resize:n #1 + { + __hanzibox_processor_resize_ #1 :w + } +\cs_new_nopar:Npn \__hanzibox_resize_c:n #1 + { + \use:c { - \tl_count:V \l__hanzibox_character_tl + __hanzibox_processor_resize_ #1 :w } - \int_set:Nn \l__hanzibox_pinyin_int + } +\cs_new:Npn \__hanzibox_dim_gezero_dispatch:NNnnn #1#2 #3#4#5 + { + \dim_compare:nNnTF #1 > \c_zero_dim + { #3 } { - \tl_count:V \l__hanzibox_pinyin_tl + \dim_compare:nNnTF #2 > \c_zero_dim + { #4 } { #5 } } - \int_set:Nn \l__hanzibox_translation_int + } +\cs_new:Npn \__hanzibox_dim_gezero_dispatch:NNnnnn #1#2 #3#4#5#6 + { + \dim_compare:nNnTF #1 > \c_zero_dim { - \tl_count:V \l__hanzibox_translation_tl + \dim_compare:nNnTF #2 > \c_zero_dim + { #3 } { #4 } } + { + \dim_compare:nNnTF #2 > \c_zero_dim + { #5 } { #6 } + } + } +\cs_new:Npn \__hanzibox_force_size_dispatch:nnn % height, width, none + { + \__hanzibox_dim_gezero_dispatch:NNnnn \l__hanzibox_height_dim \l__hanzibox_width_dim + } +\cs_new:Npn \__hanzibox_force_size_dispatch:nnnn % both, height, width, none + { + \__hanzibox_dim_gezero_dispatch:NNnnnn \l__hanzibox_box_height_dim \l__hanzibox_box_width_dim + } +\cs_new:Npn \__hanzibox_new_resize_method:nn #1 + { + \clist_put_right:Nn \g__hanzibox_resize_method_clist {#1} + \cs_new:cpn { \__hanzibox_resize:n {#1} } + } +\__hanzibox_new_resize_method:nn { none } { } - \scalebox{\fp_use:N \l__hanzibox_scale_fp}{ - \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{% - \__hanzibox_border_draw:n {0.0cm} - \bool_if:NT \l__hanzibox_hanzi_bool - { - \__hanzibox_frame_background:n {0.0cm} - } - \int_compare:nNnTF { \l__hanzibox_character_int } = {0} +\__hanzibox_new_resize_method:nn { real } + { + \__hanzibox_force_size_dispatch:nnnn + { + \coffin_resize:Nnn \l__hanzibox_box_coffin + \l__hanzibox_box_width_dim + \l__hanzibox_box_height_dim + } + { + \coffin_scale:Nnn \l__hanzibox_box_coffin + { + \dim_ratio:nn { \l__hanzibox_box_height_dim } + { \__hanzibox_coffin_ht_plus_dp:N \l__hanzibox_box_coffin } + } + { + \dim_ratio:nn { \l__hanzibox_box_height_dim } + { \__hanzibox_coffin_ht_plus_dp:N \l__hanzibox_box_coffin } + } + } + { + \coffin_scale:Nnn \l__hanzibox_box_coffin + { + \dim_ratio:nn { \l__hanzibox_box_width_dim } + { \coffin_wd:N \l__hanzibox_box_coffin } + } + { + \dim_ratio:nn { \l__hanzibox_box_width_dim } + { \coffin_wd:N \l__hanzibox_box_coffin } + } + } + { + \coffin_scale:Nnn \l__hanzibox_box_coffin + { \l__hanzibox_x_scale_tl } + { \l__hanzibox_y_scale_tl } + } + } + +\__hanzibox_new_resize_method:nn { base } + { + \__hanzibox_force_size_dispatch:nnnn + { + \coffin_resize:Nnn \l__hanzibox_box_coffin + \l__hanzibox_box_width_dim + \l__hanzibox_box_height_dim + } + { + \coffin_resize:Nnn \l__hanzibox_box_coffin + { + \l__hanzibox_char_width_dim * \dim_ratio:nn { \l__hanzibox_box_height_dim } + { \__hanzibox_coffin_ht_plus_dp:N \l__hanzibox_box_coffin } + } + { + \l__hanzibox_box_height_dim + } + } + { + \coffin_resize:Nnn \l__hanzibox_box_coffin + { + \l__hanzibox_box_width_dim + } + { + \l__hanzibox_char_height_dim * \dim_ratio:nn { \l__hanzibox_box_width_dim } + { \coffin_wd:N \l__hanzibox_box_coffin } + } + } + { + \coffin_resize:Nnn \l__hanzibox_box_coffin + { + \l__hanzibox_x_scale_tl \l__hanzibox_char_width_dim + } + { + \l__hanzibox_y_scale_tl \l__hanzibox_char_height_dim + } + } + } + +\msg_new:nnn { hanzibox } { frame-type } { using~ `#1'~ frame. } +\cs_new_nopar:Npn \__hanzibox_zihao:n #1 { \zihao {#1} } +\msg_new:nnn { hanzibox } { frame-exists } { The~ frame~ type~ `#1~ not~ exists. } +\cs_set_nopar:Npn \__hanzibox_color_select:nn #1#2 + { + \color_set:nn {#1} {#2} + } +\cs_set_nopar:Npn \__hanzibox_color_select:nnn #1#2#3 + { + \color_set:nnn {#1} {#2} {#3} + } +\cs_new:Npn \__hanzibox_debug:n + { + \bool_if:NTF \l__hanzibox_debug_bool + { \use:n } { \use_none:n } + } +\keys_define:nn { hanzibox } + { + basechar .code:n = { \tl_gset:Nx \c__hanzibox_basechar_tl {#1} + \__hanzibox_calc_basechar_w_h: + }, + zihao .code:n = { \hbox_gset:Nn \l__hanzibox_basebox_box + { + \__hanzibox_zihao:n {#1} \c__hanzibox_basechar_tl + } + \__hanzibox_calc_basechar_w_h: + }, + pinyinf .tl_set:N = \l__hanzibox_pinyin_format_tl , + pinyinf .initial:n = \tiny , + charf .code:n = { \tl_gset:Nn \l__hanzibox_character_format_tl {#1} + \__hanzibox_calc_frame_size: + }, + tranf .tl_set:N = \l__hanzibox_translation_format_tl , + tranf .initial:n = \tiny , + frametype .code:n = { \exp_args:NNx \clist_if_in:NnTF \g__hanzibox_frame_list_clist {#1} + { \tl_set:Nx \l__hanzibox_frame_type_tl {#1} } + { \msg_error:nnx { hanzibox } { frame-exists } {#1} } + }, + resize .code:n = { \exp_args:NNx \clist_if_in:NnTF \g__hanzibox_resize_method_clist {#1} + { \tl_set:Nx \l__hanzibox_resize_method_tl {#1} } + { \msg_error:nnx { hanzibox } { resize-method } {#1} } + }, + xscale .tl_set:N = \l__hanzibox_x_scale_tl , + xscale .initial:n = 1 , + yscale .tl_set:N = \l__hanzibox_y_scale_tl , + yscale .initial:n = 1 , + scale .meta:n = { xscale = #1 , yscale = #1 } , + width .dim_set:N = \l__hanzibox_box_width_dim , + height .dim_set:N = \l__hanzibox_box_height_dim , + linewidth .dim_set:N = \l__hanzibox_linewidth_dim , + linewidth .initial:n = 0.4pt , + framecolor .code:n = { \__hanzibox_color_select:nn { hanziboxframecolor } {#1} } , + framecolor .initial:n = black , + framecolor* .code:n = { \__hanzibox_color_select:nnn { hanziboxframecolor } #1 } , + charcolor .code:n = { \__hanzibox_color_select:nn { hanziboxcharcolor } {#1} } , + charcolor .initial:n = black , + charcolor* .code:n = { \__hanzibox_color_select:nnn { hanziboxframecolor } {#1} } , + color .meta:n = { framecolor = #1, charcolor = #1 } , + color* .meta:n = { framecolor* = #1, charcolor* = #1 } , + fillcolor .code:n = { \exp_args:Nx \tl_if_empty:nTF {#1} + { \__hanzibox_color_select:nn { hanziboxfillcolor } { white } + \cs_set_nopar:Npn \__hanzibox_aux_color_fill: { } + }{ \__hanzibox_color_select:nn { hanziboxfillcolor } {#1} + \cs_set_nopar:Npn \__hanzibox_aux_color_fill: { \color_fill:n {#1} } + } + } , + fillcolor* .code:n = { \__hanzibox_color_select:nnn { hanziboxfillcolor } #1 + \cs_set_nopar:Npn \__hanzibox_aux_color_fill: { \color_fill:nn #1 } + } , + dashpattern .tl_set:N = \l__hanzibox_dash_pattern_tl , + dashpattern .initial:n = { } , + framearc .code:n = { \tl_set:Nn \l__hanzibox_frame_arc_tl { {#1}{#1} } } , + framearc* .tl_set:N = \l__hanzibox_frame_arc_tl , + framearc* .initial:n = { { 0cm }{ 0cm } } , + debug .bool_set:N = \l__hanzibox_debug_bool , + debug .initial:n = false , + debug .default:n = true , + autopinyin .bool_set:N = \l__hanzibox_autopinyin_bool, + autopinyin .default:n = true, + autopinyin .initial:n = true, + + initial .bool_set:N = \l__hanzibox_withinitials_bool, + initial .default:n = true, + initial .initial:n = true, + + vowel .bool_set:N = \l__hanzibox_withvowel_bool, + vowel .default:n = true, + vowel .initial:n = true, + + tone .bool_set:N = \l__hanzibox_withtone_bool, + tone .default:n = true, + tone .initial:n = true, + + pinyin .bool_set:N = \l__hanzibox_withpinyin_bool, + pinyin .default:n = true, + pinyin .initial:n = true, + + hanzi .bool_set:N = \l__hanzibox_withhanzi_bool, + hanzi .default:n = true, + hanzi .initial:n = true, + + tran .bool_set:N = \l__hanzibox_withtran_bool, + tran .default:n = true, + tran .initial:n = true, + + unknown .code:n = { \__hanzibox_error:n { unknown-option } } + } +\msg_new:nnn { hanzibox } { unknown-option } + { package~ option~ "\l_keys_key_tl"~ is~ unknown. } + +\keys_set:nn { hanzibox } + { + basechar = 好 , + zihao = 4 , + pinyinf = \tiny , + charf = \normalsize , + tranf = \tiny , + frametype = none , + resize = none , + } + +\NewDocumentCommand \hanziboxset { m } + { \keys_set:nn { hanzibox } {#1} } + % \xpinyinsetup{pysep={\hspace*{1em}}} +\cs_set_eq:NN \__hanzibox_pinyinaux:n \pinyin +\cs_generate_variant:Nn \__hanzibox_pinyinaux:n { x } +\cs_new:Npn \__hanzibox_dialog:nnnn #1#2#3#4 + { + \group_begin: + \keys_set:nn { hanzibox } { #1 } + + \tl_set:Nx \l__hanzibox_character_tl {#2} + \tl_set:Nx \l__hanzibox_pinyin_tl {#3} + \tl_set:Nx \l__hanzibox_translation_tl {#4} + + \hcoffin_set:Nn \l__hanzibox_pinyin_box_coffin { - \bool_if:NTF \l__hanzibox_hanzi_bool - { - \node[\l__hanzibox_fgcolor_tl] at (1,1){\huge{\l__hanzibox_character_tl}}; - }{ - \node[\l__hanzibox_bgcolor_tl] at (1,1){\huge{\l__hanzibox_character_tl}}; - } - \bool_if:NTF \l__hanzibox_pinyin_bool - { - \node[label={[font=\small,text=\l__hanzibox_fgcolor_tl] - \strut\__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl}}, - text~height=1cm] (charr) at (1,1){}; - }{ - \node[label={[font=\small,text=\l__hanzibox_bgcolor_tl] - \strut\__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl}}, - text~height=1cm] (charr) at (1,1){}; - } - \__hanzibox_tran_draw:nn {1}{-0.5} + \tl_use:N \l__hanzibox_pinyin_format_tl + \tl_use:N \l__hanzibox_pinyin_tl } + \hcoffin_set:Nn \l__hanzibox_str_box_coffin { - \bool_if:NTF \l__hanzibox_hanzi_bool + \tl_map_inline:Nn \l__hanzibox_character_tl { - \node[\l__hanzibox_fgcolor_tl] at (1*\l__hanzibox_character_int,1) - {\huge\tl_use:N \l__hanzibox_character_tl}; - }{ - \node[\l__hanzibox_bgcolor_tl] at (1*\l__hanzibox_character_int,1) - {\huge\tl_use:N \l__hanzibox_character_tl}; + \__hanzibox_single_handle:N ##1 \allowbreak } - - \bool_if:NTF \l__hanzibox_pinyin_bool - { - \node[label={[font=\small,text=\l__hanzibox_fgcolor_tl] - \strut\__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl}}, - text~height=1cm] (charr) at (1*\l__hanzibox_character_int,1){}; - }{ - \node[label={[font=\small,text=\l__hanzibox_bgcolor_tl] - \strut\__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl}}, - text~height=1cm] (charr) at (1*\l__hanzibox_character_int,1){}; - } - \__hanzibox_tran_draw:nn {\l__hanzibox_character_int}{-0.5} } - \bool_if:NF \l__hanzibox_hanzi_bool + \hcoffin_set:Nn \l__hanzibox_tran_box_coffin { - \__hanzibox_frame_background:n {0.0cm} + \tl_use:N \l__hanzibox_translation_format_tl + \tl_use:N \l__hanzibox_translation_tl } - }% - }% + \coffin_join:NnnNnnnn \l__hanzibox_str_box_coffin + { hc } { t } \l__hanzibox_pinyin_box_coffin { hc } { H } { 0pt } { 3pt } + \coffin_join:NnnNnnnn \l__hanzibox_str_box_coffin + { hc } { b } \l__hanzibox_tran_box_coffin { hc } { t } { 0pt } { -2pt } + + \coffin_set_eq:NN \l__hanzibox_box_coffin \l__hanzibox_str_box_coffin + + \__hanzibox_resize_c:n { \l__hanzibox_resize_method_tl } + + \coffin_typeset:Nnnnn \l__hanzibox_box_coffin + { l } { b } { 0pt } { 0pt } + \group_end: } -\cs_new_protected:Npn \__hanzibox_asterisk_draw:nnnn #1#2#3#4 +\cs_new:Npn \__hanzibox_handle:nnnn #1#2#3#4 { - \keys_set:nn { hanzibox } { #1 } - \tl_set:Nx \l__hanzibox_character_tl {#2} - \tl_set:Nx \l__hanzibox_pinyin_tl {#3} - \tl_set:Nx \l__hanzibox_translation_tl {#4} - \int_set:Nn \l__hanzibox_character_int - { - \tl_count:V \l__hanzibox_character_tl - } - \int_set:Nn \l__hanzibox_pinyin_int - { - \tl_count:V \l__hanzibox_pinyin_tl - } - \int_set:Nn \l__hanzibox_translation_int - { - \tl_count:V \l__hanzibox_translation_tl - } + \group_begin: + \keys_set:nn { hanzibox } { #1 } + + \tl_set:Nx \l__hanzibox_character_tl {#2} + \tl_set:Nx \l__hanzibox_pinyin_tl {#3} + \tl_set:Nx \l__hanzibox_translation_tl {#4} - \scalebox{\fp_use:N \l__hanzibox_scale_fp}{ - \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{% - \__hanzibox_border_draw:n {-0.5cm} - \bool_if:NT \l__hanzibox_hanzi_bool + \int_set:Nn \l__hanzibox_character_int + { + \tl_count:V \l__hanzibox_character_tl + } + \int_set:Nn \l__hanzibox_translation_int { - \__hanzibox_frame_background:n {-0.5cm} + \tl_count:V \l__hanzibox_translation_tl } - \int_compare:nNnTF { \l__hanzibox_character_int } = {0} + \int_set:Nn \l__hanzibox_pinyin_int { - \bool_if:NTF \l__hanzibox_pinyin_bool + \tl_count:V \l__hanzibox_pinyin_tl + } + + \bool_if:NTF \l__hanzibox_autopinyin_bool + { + \int_compare:nNnTF { \l__hanzibox_character_int } > { 0 } { - \bool_if:NTF \l__hanzibox_hanzi_bool + \hcoffin_set:Nn \l__hanzibox_str_box_coffin { - \node[\l__hanzibox_fgcolor_tl] at (1,1) - {\huge{\xpinyin*[format={\small\color{\l__hanzibox_fgcolor_tl}}, - vsep=0.90 cm]{\l__hanzibox_character_tl}}}; - }{ - \node[\l__hanzibox_bgcolor_tl] at (1,1) - {\huge{\xpinyin*[format={\small\color{\l__hanzibox_fgcolor_tl}}, - vsep=0.90 cm]{\l__hanzibox_character_tl}}}; + \tl_map_inline:Nn \l__hanzibox_character_tl + { + \hcoffin_set:Nn \l_tmpa_coffin + { + \__hanzibox_single_handle:N ##1 + } + + \bool_if:NT \l__hanzibox_withpinyin_bool + { + \tl_gset_eq:Nc \l__hanzibox_pinyin_tl + { + c__xpinyin_ \int_to_arabic:n { `##1 } _tl + } + \__hanzibox_single_pinyin:V \l__hanzibox_pinyin_tl + + \coffin_join:NnnNnnnn \l_tmpa_coffin + { hc } { t } \l__hanzibox_pinyin_box_coffin { hc } { H } { 0pt } { 3pt } + } + \coffin_typeset:Nnnnn \l_tmpa_coffin + { l } { b } { 0pt } { 0pt } + \allowbreak + } } - }{ - \bool_if:NTF \l__hanzibox_hanzi_bool + } + { + \hcoffin_set:Nn \l__hanzibox_str_box_coffin { - \node[\l__hanzibox_fgcolor_tl] at (1,1) - {\huge{\xpinyin*[format={\small\color{\l__hanzibox_bgcolor_tl}}, - vsep=0.90 cm]{\l__hanzibox_character_tl}}}; - }{ - \node[\l__hanzibox_fgcolor_tl] at (1,1) - {\huge{\xpinyin*[format={\small\color{\l__hanzibox_bgcolor_tl}}, - vsep=0.90 cm]{\l__hanzibox_character_tl}}}; + \bool_set_false:N \l__hanzibox_withhanzi_bool + \tl_set:Nn \l__hanzibox_character_tl {好} + + \hcoffin_set:Nn \l_tmpa_coffin + { + \__hanzibox_single_handle:N \l__hanzibox_character_tl + } + + \bool_if:NT \l__hanzibox_withpinyin_bool + { + \hcoffin_set:Nn \l__hanzibox_pinyin_box_coffin + { + \color_select:n { hanziboxcharcolor } + \tl_use:N \l__hanzibox_pinyin_format_tl + \__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl} + } + \coffin_join:NnnNnnnn \l_tmpa_coffin + { hc } { t } \l__hanzibox_pinyin_box_coffin { hc } { H } { 0pt } { 3pt } + } + \coffin_typeset:Nnnnn \l_tmpa_coffin + { l } { b } { 0pt } { 0pt } + \allowbreak } } - \__hanzibox_tran_draw:nn {1}{-1.0} } { - \bool_if:NTF \l__hanzibox_pinyin_bool + \int_compare:nNnTF { \l__hanzibox_character_int } > { 1 } { - \bool_if:NTF \l__hanzibox_hanzi_bool + \hcoffin_set:Nn \l__hanzibox_str_box_coffin { - \node[\l__hanzibox_fgcolor_tl] at (1*\l__hanzibox_character_int,1) - {\huge{\xpinyin*[format={\small\color{\l__hanzibox_fgcolor_tl}}, - vsep=0.90 cm]{\l__hanzibox_character_tl}}}; - }{ - \node[\l__hanzibox_bgcolor_tl] at (1*\l__hanzibox_character_int,1) - {\huge{\xpinyin*[format={\small\color{\l__hanzibox_fgcolor_tl}}, - vsep=0.90 cm]{\l__hanzibox_character_tl}}}; + \tl_map_inline:Nn \l__hanzibox_character_tl + { + \__hanzibox_single_handle:N ##1 \allowbreak + } } - }{ - \bool_if:NTF \l__hanzibox_hanzi_bool + \bool_if:NT \l__hanzibox_withpinyin_bool { - \node[\l__hanzibox_fgcolor_tl] at (1*\l__hanzibox_character_int,1) - {\huge{\xpinyin*[format={\small\color{\l__hanzibox_bgcolor_tl}}, - vsep=0.90 cm]{\l__hanzibox_character_tl}}}; - }{ - \node[\l__hanzibox_fgcolor_tl] at (1*\l__hanzibox_character_int,1) - {\huge{\xpinyin*[format={\small\color{\l__hanzibox_bgcolor_tl}}, - vsep=0.90 cm]{\l__hanzibox_character_tl}}}; + \hcoffin_set:Nn \l__hanzibox_pinyin_box_coffin + { + \color_select:n { hanziboxcharcolor } + \__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl} + } + } + \coffin_join:NnnNnnnn \l__hanzibox_str_box_coffin + { hc } { t } \l__hanzibox_pinyin_box_coffin { hc } { H } { 0pt } { 7pt } + } + { + \int_compare:nNnTF { \l__hanzibox_character_int } = { 1 } + { + \hcoffin_set:Nn \l__hanzibox_str_box_coffin + { + \hcoffin_set:Nn \l_tmpa_coffin + { + \__hanzibox_single_handle:N \l__hanzibox_character_tl + } + + \bool_if:NT \l__hanzibox_withpinyin_bool + { + \hcoffin_set:Nn \l__hanzibox_pinyin_box_coffin + { + \color_select:n { hanziboxcharcolor } + \tl_use:N \l__hanzibox_pinyin_format_tl + \__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl} + } + \coffin_join:NnnNnnnn \l_tmpa_coffin + { hc } { t } \l__hanzibox_pinyin_box_coffin { hc } { H } { 0pt } { 3pt } + } + \coffin_typeset:Nnnnn \l_tmpa_coffin + { l } { b } { 0pt } { 0pt } + \allowbreak + } + } + { + \hcoffin_set:Nn \l__hanzibox_str_box_coffin + { + \bool_set_false:N \l__hanzibox_withhanzi_bool + \tl_set:Nn \l__hanzibox_character_tl {好} + + \hcoffin_set:Nn \l_tmpa_coffin + { + \__hanzibox_single_handle:N \l__hanzibox_character_tl + } + + \bool_if:NT \l__hanzibox_withpinyin_bool + { + \hcoffin_set:Nn \l__hanzibox_pinyin_box_coffin + { + \color_select:n { hanziboxcharcolor } + \tl_use:N \l__hanzibox_pinyin_format_tl + \__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl} + } + \coffin_join:NnnNnnnn \l_tmpa_coffin + { hc } { t } \l__hanzibox_pinyin_box_coffin { hc } { H } { 0pt } { 3pt } + } + \coffin_typeset:Nnnnn \l_tmpa_coffin + { l } { b } { 0pt } { 0pt } + \allowbreak + } } } - \__hanzibox_tran_draw:nn {\l__hanzibox_character_int}{-1.0} } - \bool_if:NF \l__hanzibox_hanzi_bool + \bool_if:NT \l__hanzibox_withtran_bool { - \__hanzibox_frame_background:n {-0.5cm} + \hcoffin_set:Nn \l__hanzibox_tran_box_coffin + { + \color_select:n { hanziboxcharcolor } + \tl_use:N \l__hanzibox_translation_format_tl + \tl_use:N \l__hanzibox_translation_tl + } } - }% - }% + \coffin_join:NnnNnnnn \l__hanzibox_str_box_coffin + { hc } { b } \l__hanzibox_tran_box_coffin { hc } { t } { 0pt } { -3pt } + + \coffin_set_eq:NN \l__hanzibox_box_coffin \l__hanzibox_str_box_coffin + + \__hanzibox_resize_c:n { \l__hanzibox_resize_method_tl } + + \coffin_typeset:Nnnnn \l__hanzibox_box_coffin + { l } { b } { 0pt } { 0pt } + \group_end: } -\cs_new_protected:Npn \__hanzibox_frame_background:n #1 +\cs_new:Npn \__hanzibox_single_pinyin:n #1 { - \int_compare:nNnT { \l__hanzibox_character_int } < {2} + \bool_if:NTF \l__hanzibox_withtone_bool { - \int_case:nn {\l__hanzibox_inner_int} + \bool_if:nTF { !(\l__hanzibox_withinitials_bool) || !(\l__hanzibox_withvowel_bool) } { - {1}{ - } - {2}{ - \__hanzibox_star_background:n {#1} - } - {3}{ - \__hanzibox_cross_background:n {#1} - } + \__hanzibox_split_pinyin_withtone:n { #1 } + \hcoffin_set:Nn \l__hanzibox_pinyin_box_coffin + { + \color_select:n { hanziboxcharcolor } + \tl_use:N \l__hanzibox_pinyin_format_tl + + \bool_if:NTF \l__hanzibox_withinitials_bool + { + \bool_if:NTF \l__hanzibox_withvowel_bool + { + \tl_use:N \l__hanzibox_initial_tl + \tl_use:N \l__hanzibox_vowel_tl + } + { + \tl_use:N \l__hanzibox_initial_tl + \phantom{ \tl_use:N \l__hanzibox_vowel_tl } + } + } + { + \bool_if:NTF \l__hanzibox_withvowel_bool + { + \phantom{ \tl_use:N \l__hanzibox_initial_tl } + \tl_use:N \l__hanzibox_vowel_tl + } + { + \phantom{ \tl_use:N \l__hanzibox_initial_tl } + \phantom{ \tl_use:N \l__hanzibox_vowel_tl } + } + } + } + } + { + \hcoffin_set:Nn \l__hanzibox_pinyin_box_coffin + { + \color_select:n { hanziboxcharcolor } + \tl_use:N \l__hanzibox_pinyin_format_tl + #1 + } + } + } + { + \__hanzibox_split_pinyin_withouttone:n { #1 } + \hcoffin_set:Nn \l__hanzibox_pinyin_box_coffin + { + \color_select:n { hanziboxcharcolor } + \tl_use:N \l__hanzibox_pinyin_format_tl + + \tl_use:N \l__hanzibox_pinyin_tl + } + } + } +\cs_generate_variant:Nn \__hanzibox_single_pinyin:n { V } +\cs_generate_variant:Nn \__hanzibox_single_pinyin:n { x } +\cs_set:Npn \__hanzibox_single_pinyin_o:n + { \exp_after:wN \__hanzibox_single_pinyin:n } +\cs_set:Npn \__hanzibox_single_pinyin_f:n + { \exp_args:Nf \__hanzibox_single_pinyin:n } +\cs_new:Npn \__hanzibox_single_handle:nN #1#2 + { + \group_begin: + \tl_if_empty:nF {#1} { \keys_set:nn { hanzibox } {#1} } + + \tl_set:Nf \l__hanzibox_curr_char_tl {#2} + + \__hanzibox_single_construct_o:N \l__hanzibox_curr_char_tl + \group_end: + } +\cs_new:Npn \__hanzibox_single_handle:N #1 + { + \group_begin: + \tl_set:Nf \l__hanzibox_curr_char_tl {#1} + \__hanzibox_single_construct_o:N \l__hanzibox_curr_char_tl + \group_end: + } +\cs_new:Npn \__hanzibox_single_construct:N #1 + { + \bool_if:NTF \l__hanzibox_withhanzi_bool + { + \hcoffin_set:Nn \l__hanzibox_box_coffin + { + \color_select:n { hanziboxcharcolor } + \tl_use:N \l__hanzibox_character_format_tl + #1 + } + } + { + \hcoffin_set:Nn \l__hanzibox_box_coffin + { + \color_select:n { hanziboxcharcolor } + \tl_use:N \l__hanzibox_character_format_tl + \phantom{#1} } } + + \__hanzibox_single_frame_construct: } -\cs_new_protected:Npn \__hanzibox_star_background:n #1 +\cs_set:Npn \__hanzibox_single_construct_o:N + { \exp_after:wN \__hanzibox_single_construct:N } +\cs_set:Npn \__hanzibox_single_construct_f:N + { \exp_args:Nf \__hanzibox_single_construct:N } +\cs_new:Npn \__hanzibox_single_frame_construct: { - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, - \l__hanzibox_bordercolor_tl!50](0,0)--(2,2);% - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, - \l__hanzibox_bordercolor_tl!50](0,2)--(2,0);% + \draw_begin: + \draw_linewidth:n { \l__hanzibox_linewidth_dim } + \__hanzibox_aux_color_fill: + \color_stroke:n { hanziboxframecolor } + + \exp_after:wN \draw_path_corner_arc:nn \l__hanzibox_frame_arc_tl - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, - \l__hanzibox_bordercolor_tl!50](0,1)--(2,1);% - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, - \l__hanzibox_bordercolor_tl!50](1,0)--(1,2);% + \draw_path_scope_begin: + \draw_transform_shift:n { -1.00pt, -1.50pt } + \__hanzibox_frame_type_c:n { \l__hanzibox_frame_type_tl } + { 0 } { 0 } { \hanziboxwidth } { \hanziboxheight } { 1.0 } { 1.0 } + \draw_path_scope_end: + \draw_coffin_use:Nnn \l__hanzibox_box_coffin { l } { b } + \draw_end: } -\cs_new_protected:Npn \__hanzibox_cross_background:n #1 +\clist_set:Nn \l__hanzibox_initials_clist { - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, - \l__hanzibox_bordercolor_tl!50](0,1)--(2,1);% - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, - \l__hanzibox_bordercolor_tl!50](1,0)--(1,2);% + {zh} , {ch} , {sh} , {b} , {p} , {m} , {f} , + {d} , {t} , {l} , {k} , {h} , {j} , {q} , + {x} , {r} , {z} , {c} , {s} , {y} , {w} , + {g} , {n} } -\cs_new_protected:Npn \__hanzibox_border_draw:n #1 +\clist_set:Nn \l__hanzibox_vowel_tone_clist { - \int_compare:nNnTF { \l__hanzibox_character_int } = {0} - { - \draw[fill=\l__hanzibox_bgcolor_tl,line~width=\l__hanzibox_borderwidth_dim, - yshift=#1, draw=\l__hanzibox_bordercolor_tl] (0,0) rectangle(2,2); - } - { - \bool_if:NTF \l__hanzibox_border_bool - { - \draw[fill=\l__hanzibox_bgcolor_tl,line~width=\l__hanzibox_borderwidth_dim, - yshift=#1, draw=\l__hanzibox_bordercolor_tl] (0,0) - rectangle(2*\l__hanzibox_character_int,2); - }{} - } + {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} , + {ǖ} , {ǘ} , {ǚ} , {ǜ} , {ü} + } +\clist_set:Nn \l__hanzibox_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} + } +\clist_set:Nn \l__hanzibox_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} } -\cs_new_protected:Npn \__hanzibox_tran_draw:nn #1#2 +\clist_set:Nn \l__hanzibox_nonetone_clist { - \bool_if:NTF \l__hanzibox_tran_bool + {ā} {a} , {á} {a} , {ǎ} {a} , {à} {a} , + {ō} {o} , {ó} {o} , {ǒ} {o} , {ò} {o} , + {ē} {e} , {é} {e} , {ě} {e} , {è} {e} , + {ū} {u} , {ú} {u} , {ǔ} {u} , {ù} {u} , + {ḿ} {m} , + {ń} {n} , {ň} {n} , {ǹ} {n} , + {ī} {i} , {í} {i} , {ǐ} {i} , {ì} {i} , + {ǖ} {ü} , {ǘ} {ü} , {ǚ} {ü} , {ǜ} {ü} + } +\cs_new_protected:Npn \__hanzibox_split_pinyin_withtone:n #1 + { + \int_zero:N \l__hanzibox_tone_int + \str_clear:N \l__hanzibox_pinyin_str + \tl_clear:N \l__hanzibox_pinyin_tl + \tl_clear:N \l__hanzibox_initial_tl + \tl_clear:N \l__hanzibox_vowel_tl + + \tl_set:Nn \l__hanzibox_pinyin_tl {#1} + + \tl_map_inline:Nn \l__hanzibox_pinyin_tl { - \node[align=center,\l__hanzibox_fgcolor_tl] at (1*#1,#2) - {\strut\small\textit{\l__hanzibox_translation_tl}}; - }{ - \node[align=center,\l__hanzibox_bgcolor_tl] at (1*#1,#2) - {\strut\small\textit{\l__hanzibox_translation_tl}}; + \str_put_right:Nn \l__hanzibox_pinyin_str {##1} + } + + \clist_map_inline:Nn \l__hanzibox_initials_clist + { + \str_if_in:NnT { \l__hanzibox_pinyin_str } {##1} + { + \tl_set:Nn \l__hanzibox_initial_tl {##1} + \clist_map_break: + } + } + + \clist_map_inline:Nn \l__hanzibox_vowel_tone_clist + { + \str_if_in:NnT { \l__hanzibox_pinyin_str } { ##1 } + { + \tl_set:Nn \l__hanzibox_vowel_tl {##1} + \clist_map_break: + } + } + } +\cs_generate_variant:Nn \__hanzibox_split_pinyin:n { V } +\cs_new_protected:Npn \__hanzibox_split_pinyin_withouttone:n #1 + { + \int_zero:N \l__hanzibox_tone_int + \str_clear:N \l__hanzibox_pinyin_str + \tl_clear:N \l__hanzibox_pinyin_tl + \tl_clear:N \l__hanzibox_initial_tl + \tl_clear:N \l__hanzibox_vowel_tl + + \tl_set:Nn \l__hanzibox_pinyin_tl {#1} + + \clist_map_inline:Nn \l__hanzibox_nonetone_clist + { + \tl_replace_all:Nnn \l__hanzibox_pinyin_tl ##1 + } + + \tl_map_inline:Nn \l__hanzibox_pinyin_tl + { + \str_put_right:Nn \l__hanzibox_pinyin_str {##1} + } + + \clist_map_inline:Nn \l__hanzibox_initials_clist + { + \str_if_in:NnT {\l__hanzibox_pinyin_str} {##1} + { + \tl_set:Nn \l__hanzibox_initial_tl {##1} + \clist_map_break: + } + } + + \clist_map_inline:Nn \l__hanzibox_vowel_clist + { + \str_if_in:NnT { \l__hanzibox_pinyin_str } { ##1 } + { + \tl_set:Nn \l__hanzibox_vowel_tl {##1} + \clist_map_break: + } } } +\cs_generate_variant:Nn \__hanzibox_split_pinyin:n { V } %% %% This package consists of the file hanzibox.dtx, %% and the derived files hanzibox.sty, |