diff options
Diffstat (limited to 'Master/texmf-dist/tex/xelatex/hanzibox')
-rw-r--r-- | Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty | 313 |
1 files changed, 198 insertions, 115 deletions
diff --git a/Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty b/Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty index b2e6ae1281b..bade0bc6be0 100644 --- a/Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty +++ b/Master/texmf-dist/tex/xelatex/hanzibox/hanzibox.sty @@ -21,13 +21,13 @@ %% %% This work has the LPPL maintenance status "maintained". %% -%% The Current Maintainer of this work is Nan Geng Nan Geng. +%% The Current Maintainer of this work is Nan Geng. %% %% -------------------------------------------------------------------------- %% \NeedsTeXFormat{LaTeX2e}[2020/10/01] \RequirePackage{expl3} -\GetIdInfo$Id: hanzibox.dtx 1.0.0 2021-09-18 20:00:00Z +0800 Nan Geng <nangeng@nwafu.edu.cn> $ +\GetIdInfo$Id: hanzibox.dtx 1.1.0 2021-09-23 08:00:00 +0800 Nan Geng <nangeng@nwafu.edu.cn> $ {Boxed Chinese characters with Pinyin above and translation below.} \ProvidesExplPackage{\ExplFileName} {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} @@ -36,15 +36,12 @@ \sys_if_engine_xetex:F { - \sys_if_engine_luatex:F - { - \msg_fatal:nnx { hanzibox } { unsupported-engine } - { \c_sys_engine_str } - } + \msg_fatal:nnx { hanzibox } { unsupported-engine } + { \c_sys_engine_str } } \msg_new:nnn { hanzibox } { unsupported-engine } { - The~ hanzibox~ packages~ requires~ either~ XeTeX~ or~ LuaTeX. \\\\ + The~ hanzibox~ packages~ requires~ either~ XeTeX. \\\\ "#1"~ is~ not~ supported~ at~ present.~ You~ must~ change \\ your~ typesetting~ engine~ to~ "xelatex"~ or~ "lualatex". } @@ -85,24 +82,35 @@ \NewDocumentCommand{\hanzidialog}{ m O{} O{} } { - \__hanzibox_dialog:nnnn { #1 } { #2 } { #3 } + \group_begin: + \__hanzibox_dialog:nnnn { #1 } { #2 } { #3 } + \group_end: } \NewDocumentCommand{\hanzibox}{ s O{} m O{} O{} } { \IfBooleanTF{#1} { - \__hanzibox_star_draw:nnnn { #2 } { #3 } { #4 } { #5 } + \group_begin: + \__hanzibox_asterisk_draw:nnnn { #2 } { #3 } { #4 } { #5 } + \group_end: }{ - \__hanzibox_draw:nnnn { #2 } { #3 } { #4 } { #5 } + \group_begin: + \__hanzibox_draw:nnnn { #2 } { #3 } { #4 } { #5 } + \group_end: } } -\fp_new:N \l__hanzibox_ratio_fp +\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 @@ -112,8 +120,8 @@ \keys_define:nn { hanzibox } { - ratio .fp_set:N = \l__hanzibox_ratio_fp, - ratio .initial:n = 1.0, + scale .fp_set:N = \l__hanzibox_scale_fp, + scale .initial:n = 1.0, inner .choice:, inner .value_required:n = true, @@ -132,6 +140,24 @@ bordercolor .tl_set:N = \l__hanzibox_bordercolor_tl, bordercolor .initial:n = black, + fgcolor .tl_set:N = \l__hanzibox_fgcolor_tl, + fgcolor .initial:n = black, + + bgcolor .tl_set:N = \l__hanzibox_bgcolor_tl, + bgcolor .initial:n = white, + + withpinyin .bool_set:N = \l__hanzibox_pinyin_bool, + withpinyin .default:n = true, + withpinyin .initial:n = true, + + withhanzi .bool_set:N = \l__hanzibox_hanzi_bool, + withhanzi .default:n = true, + withhanzi .initial:n = true, + + withtran .bool_set:N = \l__hanzibox_tran_bool, + withtran .default:n = true, + withtran .initial:n = true, + unknown .code:n = { \__hanzibox_error:n { unknown-option } } } \msg_new:nnn { hanzibox } { unknown-option } @@ -144,13 +170,13 @@ \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_ratio_fp}{ + \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{\tl_use:N \l__hanzibox_character_tl}}}; - {\node[label={\strut\small\textbf{\tl_use:N \l__hanzibox_pinyin_tl}}, + {\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{\tl_use:N \l__hanzibox_translation_tl}};}% + {\strut\small\textit{\l__hanzibox_translation_tl}};}% }% }% } @@ -176,79 +202,63 @@ \tl_count:V \l__hanzibox_translation_tl } - \scalebox{\fp_use:N \l__hanzibox_ratio_fp}{ + \scalebox{\fp_use:N \l__hanzibox_scale_fp}{ \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{% - \int_compare:nNnT { \l__hanzibox_character_int } < {2} + \__hanzibox_border_draw:n {0.0cm} + \bool_if:NT \l__hanzibox_hanzi_bool { - \int_case:nn {\l__hanzibox_inner_int} - { - {1}{ - } - {2}{ - \draw[stretch~dash=on~2pt~off~2pt,thin, - \tl_use:N \l__hanzibox_bordercolor_tl!50](0,0)--(2,2);% - \draw[stretch~dash=on~2pt~off~2pt,thin, - \tl_use:N \l__hanzibox_bordercolor_tl!50](0,2)--(2,0);% - - \draw[stretch~dash=on~2pt~off~2pt,thin, - \tl_use:N \l__hanzibox_bordercolor_tl!50](0,1)--(2,1);% - \draw[stretch~dash=on~2pt~off~2pt,thin, - \tl_use:N \l__hanzibox_bordercolor_tl!50](1,0)--(1,2);% - } - {3}{ - \draw[stretch~dash=on~2pt~off~2pt,thin, - \tl_use:N \l__hanzibox_bordercolor_tl!50](0,1)--(2,1);% - \draw[stretch~dash=on~2pt~off~2pt,thin, - \tl_use:N \l__hanzibox_bordercolor_tl!50](1,0)--(1,2);% - } - } + \__hanzibox_frame_background:n {0.0cm} } \int_compare:nNnTF { \l__hanzibox_character_int } = {0} { - \draw[line~width=\dim_use:N \l__hanzibox_borderwidth_dim, - \tl_use:N \l__hanzibox_bordercolor_tl] (0,0) rectangle(2,2); - \node[] at (1,1){\huge{\tl_use:N \l__hanzibox_character_tl}}; - \int_compare:nNnTF { \l__hanzibox_pinyin_int } = {0} - { } + \bool_if:NTF \l__hanzibox_hanzi_bool { - \node[label={\strut\small\__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl}}, - text~height=1cm] (charr) at (1,1){}; + \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}}; } - \int_compare:nNnTF { \l__hanzibox_translation_int } = {0} - { } + \bool_if:NTF \l__hanzibox_pinyin_bool { - \node[align=center] at (1,-0.5) - {\strut\small\textit{\tl_use:N \l__hanzibox_translation_tl}}; + \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} } { - \bool_if:NTF \l__hanzibox_border_bool - { - \draw[line~width=\dim_use:N \l__hanzibox_borderwidth_dim, - \tl_use:N \l__hanzibox_bordercolor_tl] (0,0) rectangle(2*\l__hanzibox_character_int,2); - }{} - - \node[] at (1*\l__hanzibox_character_int,1) - {\huge\tl_use:N \l__hanzibox_character_tl}; - - \int_compare:nNnTF { \l__hanzibox_pinyin_int } = {0} - { } + \bool_if:NTF \l__hanzibox_hanzi_bool { - \node[label={\strut\small\__hanzibox_pinyinaux:x {\l__hanzibox_pinyin_tl}}, - text~height=1cm] (charr) at (1*\l__hanzibox_character_int,1){}; + \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}; } - \int_compare:nNnTF { \l__hanzibox_translation_int } = {0} - { } + \bool_if:NTF \l__hanzibox_pinyin_bool { - \node[align=center] at (1*\l__hanzibox_character_int,-0.5) - {\strut\small\textit{\tl_use:N \l__hanzibox_translation_tl}}; + \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 + { + \__hanzibox_frame_background:n {0.0cm} } }% }% } -\cs_new_protected:Npn \__hanzibox_star_draw:nnnn #1#2#3#4 +\cs_new_protected:Npn \__hanzibox_asterisk_draw:nnnn #1#2#3#4 { \keys_set:nn { hanzibox } { #1 } \tl_set:Nx \l__hanzibox_character_tl {#2} @@ -267,65 +277,138 @@ \tl_count:V \l__hanzibox_translation_tl } - \scalebox{\fp_use:N \l__hanzibox_ratio_fp}{ + \scalebox{\fp_use:N \l__hanzibox_scale_fp}{ \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{% - \int_compare:nNnT { \l__hanzibox_character_int } < {2} + \__hanzibox_border_draw:n {-0.5cm} + \bool_if:NT \l__hanzibox_hanzi_bool { - \int_case:nn {\l__hanzibox_inner_int} - { - {1}{ - } - {2}{ - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm, - \tl_use:N \l__hanzibox_bordercolor_tl!50](0,0)--(2,2);% - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm, - \tl_use:N \l__hanzibox_bordercolor_tl!50](0,2)--(2,0);% - - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm, - \tl_use:N \l__hanzibox_bordercolor_tl!50](0,1)--(2,1);% - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm, - \tl_use:N \l__hanzibox_bordercolor_tl!50](1,0)--(1,2);% - } - {3}{ - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm, - \tl_use:N \l__hanzibox_bordercolor_tl!50](0,1)--(2,1);% - \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=-0.5cm, - \tl_use:N \l__hanzibox_bordercolor_tl!50](1,0)--(1,2);% - } - } + \__hanzibox_frame_background:n {-0.5cm} } \int_compare:nNnTF { \l__hanzibox_character_int } = {0} { - \draw[line~width=\dim_use:N \l__hanzibox_borderwidth_dim, yshift=-0.5cm, - \tl_use:N \l__hanzibox_bordercolor_tl] (0,0) rectangle(2,2); - \node[] at (1,1){\huge{\xpinyin*[vsep=0.85 cm]{\tl_use:N \l__hanzibox_character_tl}}}; - \int_compare:nNnTF { \l__hanzibox_translation_int } = {0} - { } + \bool_if:NTF \l__hanzibox_pinyin_bool { - \node[align=center] at (1,-1.0) - {\strut\small\textit{\tl_use:N \l__hanzibox_translation_tl}}; + \bool_if:NTF \l__hanzibox_hanzi_bool + { + \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}}}; + } + }{ + \bool_if:NTF \l__hanzibox_hanzi_bool + { + \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}}}; + } } + \__hanzibox_tran_draw:nn {1}{-1.0} } { - \bool_if:NTF \l__hanzibox_border_bool - { - \draw[line~width=\dim_use:N \l__hanzibox_borderwidth_dim, yshift=-0.5cm, - \tl_use:N \l__hanzibox_bordercolor_tl] (0,0) rectangle(2*\l__hanzibox_character_int,2); - }{} - - \node[] at (1*\l__hanzibox_character_int,1) - {\huge{\xpinyin*[vsep=0.90 cm]{\tl_use:N \l__hanzibox_character_tl}}}; - - \int_compare:nNnTF { \l__hanzibox_translation_int } = {0} - { } + \bool_if:NTF \l__hanzibox_pinyin_bool { - \node[align=center] at (1*\l__hanzibox_character_int,-1.0) - {\strut\small\textit{\tl_use:N \l__hanzibox_translation_tl}}; + \bool_if:NTF \l__hanzibox_hanzi_bool + { + \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}}}; + } + }{ + \bool_if:NTF \l__hanzibox_hanzi_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}}}; + } } + \__hanzibox_tran_draw:nn {\l__hanzibox_character_int}{-1.0} + } + \bool_if:NF \l__hanzibox_hanzi_bool + { + \__hanzibox_frame_background:n {-0.5cm} } }% }% } +\cs_new_protected:Npn \__hanzibox_frame_background:n #1 + { + \int_compare:nNnT { \l__hanzibox_character_int } < {2} + { + \int_case:nn {\l__hanzibox_inner_int} + { + {1}{ + } + {2}{ + \__hanzibox_star_background:n {#1} + } + {3}{ + \__hanzibox_cross_background:n {#1} + } + } + } + } +\cs_new_protected:Npn \__hanzibox_star_background:n #1 + { + \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[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);% + } +\cs_new_protected:Npn \__hanzibox_cross_background:n #1 + { + \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);% + } +\cs_new_protected:Npn \__hanzibox_border_draw:n #1 + { + \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); + }{} + } + } +\cs_new_protected:Npn \__hanzibox_tran_draw:nn #1#2 + { + \bool_if:NTF \l__hanzibox_tran_bool + { + \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}}; + } + } %% %% This package consists of the file hanzibox.dtx, %% and the derived files hanzibox.sty, |