diff options
author | Karl Berry <karl@freefriends.org> | 2021-09-23 20:15:15 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-09-23 20:15:15 +0000 |
commit | 3d2a6781baece071615cb84c9d4954f37796789c (patch) | |
tree | 39ed8a1243ac0cd4b57b5b97a7223b1e936f6d92 /Master/texmf-dist/source/xelatex | |
parent | 951f0adfbf70bead76e686bdd9b6c189170442fb (diff) |
hanzibox (23sep21)
git-svn-id: svn://tug.org/texlive/trunk@60594 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/xelatex')
-rw-r--r-- | Master/texmf-dist/source/xelatex/hanzibox/hanzibox.dtx | 590 |
1 files changed, 455 insertions, 135 deletions
diff --git a/Master/texmf-dist/source/xelatex/hanzibox/hanzibox.dtx b/Master/texmf-dist/source/xelatex/hanzibox/hanzibox.dtx index f42af799ffb..ae34ed29bb7 100644 --- a/Master/texmf-dist/source/xelatex/hanzibox/hanzibox.dtx +++ b/Master/texmf-dist/source/xelatex/hanzibox/hanzibox.dtx @@ -5,7 +5,7 @@ %</internal> %<*readme> hanzibox -LaTeX3 Chinese Character package, v1.01 +LaTeX3 Chinese Character package, v1.1.0 ======= `hanzibox` is a LaTeX package written to simplify the input of Chinese @@ -23,11 +23,11 @@ At present, hanzibox.sty only supports XeTeX engines and only allows UTF-8 encod You can read the package manual (in Chinese) for more detailed explanations. -Gitee repository: https://gitee.com/nwafu_nan/hanzibox-l3. - Contributing ------------ +Gitee repository: https://gitee.com/nwafu_nan/hanzibox-l3. + Issues and pull requests are welcome. Copyright and Licence @@ -87,7 +87,7 @@ Copyright and Licence 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. -------------------------------------------------------------------------- @@ -114,14 +114,14 @@ Copyright and Licence { %</install> %<*internal> - \usedir{source/latex/hanzibox} + \usedir{source/xelatex/hanzibox} \file{hanzibox.ins} {\from{\jobname.dtx}{install}} %</internal> %<*install> - \usedir{tex/latex/hanzibox} + \usedir{xetex/xelatex/hanzibox} \file{hanzibox.sty} {\from{\jobname.dtx}{package}} \nopreamble\nopostamble - \usedir{doc/latex/hanzibox} + \usedir{doc/xelatex/hanzibox} \file{README.md} {\from{\jobname.dtx}{readme}} } @@ -132,7 +132,7 @@ Copyright and Licence %</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>\GetIdInfo$Id: hanzibox.dtx 1.1.0 2021-09-23 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} @@ -141,7 +141,6 @@ Copyright and Licence \usepackage{listings} \usepackage{xcolor} \usepackage{xcolor-material} -\usepackage{xpinyin} \usepackage{hanzibox} \renewcommand*\marg[1]{\{\meta{#1}\}} \renewcommand*\oarg[1]{[\meta{#1}]} @@ -161,7 +160,8 @@ Copyright and Licence % % \changes{v1.0.0}{2021/09/18}{开始编写模板。} % -% \CheckSum{0} +% \CheckSum{420} +% \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 @@ -179,7 +179,6 @@ Copyright and Licence % Grave accent \` Left brace \{ Vertical bar \| % Right brace \} Tilde \~} % -% \GetFileId{hanzibox.sty} % % \title{\bfseries\pkg{hanzibox}:田字格-米字格汉字练习宏包} % \author{耿楠\\ \path{nangeng@nwafu.edu.cn}} @@ -190,16 +189,23 @@ Copyright and Licence % % \begin{abstract} % -% \pkg{hanzibox} 是一个用\LaTeX3开发的 \LaTeX 宏包,提供了汉字学习中的田字格 -% 或米字格功能,并可以根据需要在汉字正上方显示拼音,在正下方显示需要的译文。 +% \pkg{hanzibox} 是一个用\LaTeX3开发的 \LaTeX 宏包,它提供了\tn{hanzidialog}和\tn{hanzibox} +% 两个命令。这两个命令用于输出汉字学习中的田字格或米字格,并可以根据需要在汉字正上方显示拼音, +% 在正下方显示需要的译文。其中,\tn{hanzidialog}命令的注音功能通过手动插入\pkg{xpinyin}宏包的 +% \tn{pinyin}命令实现。\tn{hanzibox}命令的注音功能自动调用\pkg{xpinyin}宏包的\tn{pinyin}命令实现, +% 并且\tn{hanzibox}命令提供了\tn{hanzibox*}星号版本,该星号版本能够根据汉字自动调用 +% \pkg{xpinyin}宏包的\tn{xpinyin*}命令实现汉字注音。 % % \end{abstract} % % \section{简要说明} % -% 建议使用\pkg{hanzibox}宏包的\LaTeX 源文件总是采用 \texttt{UTF-8}。 +% \pkg{hanzibox} 是一个用于输出汉字学习中的田字格或米字格,并在汉字正上方显示拼音, +% 在正下方显示需要的译文。同时,也可以根据需要隐藏拼音、汉字或译文。 +% +% 使用\pkg{hanzibox}宏包的\LaTeX 源文件需采用 \texttt{UTF-8}编码,并且需使用\XeLaTeX 进行编译。 % -% \pkg{hanzibox} 还依赖 \package{l3kernel} 和 \package{l3packages}。 +% \pkg{hanzibox} 依赖 \package{l3kernel} 和 \package{l3packages}。 % % \section{用户接口} % @@ -234,7 +240,7 @@ Copyright and Licence % 星号命令用于根据汉字自动在顶部排版拼音,在底部排版译文。\\ % 此时,\oarg{拼音选项}中的拼音无效,可以留空,但若有译文则该选项不可省略; % \oarg{译文选项}可以是任意文本。\\ -% 注意:此时的注意由\pkg{xpinyin}宏包实现,如需要设置多音字的拼音,请参阅其宏包说明。 +% 注意:此时的注音由\pkg{xpinyin}宏包实现,如需要设置多音字的拼音,请参阅其宏包说明。 % \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.43\linewidth,gobble=5] % \hanzibox*[inner=none,border=false]{我}[][me] % \hanzibox*[inner=cross,border=true]{我}[][吾] @@ -266,18 +272,36 @@ Copyright and Licence % % 布尔型的参数 \kvopt{\meta{选项}}{true} 中的“|= true|”可以省略。 % +% \changes{v1.1.0}{2021/09/22}{添加外观选项设置命令示例代码。} +% +% \begin{frameverb} +% \hanziboxset{ +% scale = 0.8, % 整体缩放比例 +% inner = star, % 盒子内部图案 +% border = true, % 是否有边框 +% borderwidth = 1.5 pt, % 边框宽度 +% bordercolor = red, % 边框颜色 +% fgcolor = red, % 盒子前景色(文字颜色) +% bgcolor = yellow!50, % 盒子背景色 +% withpinyin = false, % 是否显示拼音 +% withhanzi = true, % 是否显示汉字 +% withtran = true % 是否显示译文 +% } +% \end{frameverb} +% % 注:各选项也可以以相同的键值列表在汉字盒子命令的外观选项中进行设置。 % % \subsection{缩放比例} % -% \begin{function}[added=2021-09-20]{ratio} +% \changes{v1.1.0}{2021/09/22}{将缩放比例键ratio改为scale。} +% +% \begin{function}[added=2021-09-20,updated=2021-09-22]{scale} % \begin{syntax} -% ratio = \Arg{number} +% scale = \Arg{number} % \end{syntax} % 设置\tn{hanzibox}命令绘制汉字盒子及其拼音和译文的整体缩放比例,默认值为\textbf{1.0}。 % \end{function} % -% % \subsection{汉字边框} % % \begin{function}[added=2021-09-20]{border} @@ -301,6 +325,26 @@ Copyright and Licence % 为\tn{hanzibox}命令设置汉字的边框颜色,默认值为\textbf{black}。该选项对\tn{hanzidialog}命令无效。 % \end{function} % +% \changes{v1.1.0}{2021/09/21}{添加前景颜色设置选项。} +% +% \begin{function}[added=2021-09-21]{fgcolor} +% \begin{syntax} +% fgcolor = \Arg{color} +% \end{syntax} +% 为\tn{hanzibox}命令设置汉字盒子前景颜色(文字颜色), +% 默认值为\textbf{black}。该选项对\tn{hanzidialog}命令无效。 +% \end{function} +% +% \changes{v1.1.0}{2021/09/21}{添加背景颜色设置选项。} +% +% \begin{function}[added=2021-09-21]{bgcolor} +% \begin{syntax} +% bgcolor = \Arg{color} +% \end{syntax} +% 为\tn{hanzibox}命令设置汉字盒子背景颜色(填充颜色), +% 默认值为\textbf{white}。该选项对\tn{hanzidialog}命令无效。 +% \end{function} +% % \subsection{格子样式} % % \begin{function}[added=2021-09-20]{inner} @@ -311,6 +355,65 @@ Copyright and Licence % 默认值为\textbf{none}。该选项对\tn{hanzidialog}命令无效。 % \end{function} % +% \changes{v1.1.0}{2021/09/21}{添加隐藏拼音选项。} +% +% \subsection{内容隐藏} +% +% \begin{function}[added=2021-09-21]{withpinyin} +% \begin{syntax} +% withpinyin = <\TTF> +% \end{syntax} +% 为\tn{hanzibox}命令选择是否输出拼音,默认值为\textbf{true}。该选项对\tn{hanzidialog}命令无效。 +% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.35\linewidth,gobble=5] +% \hanzibox[inner=cross]{我}[wo3][吾] +% \hanzibox[withpinyin=false,inner=star]{我}[wo3][不才] +% \hanzibox[bordercolor=red]{我们}[wo3men5][吾辈] +% \end{SideBySideExample} +% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.35\linewidth,gobble=5] +% \hanzibox*[inner=cross]{我}[][吾] +% \hanzibox*[withpinyin=false,inner=star]{我}[wo3][不才] +% \hanzibox*[bordercolor=red]{我们}[wo3][吾辈] +% \end{SideBySideExample} +% \end{function} +% +% \changes{v1.1.0}{2021/09/21}{添加隐藏汉字选项。} +% +% \begin{function}[added=2021-09-21]{withhanzi} +% \begin{syntax} +% withhanzi = <\TTF> +% \end{syntax} +% 为\tn{hanzibox}命令选择是否输出汉字,默认值为\textbf{true}。该选项对\tn{hanzidialog}命令无效。 +% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.35\linewidth,gobble=5] +% \hanzibox[inner=cross]{我}[wo3][吾] +% \hanzibox[withhanzi=false,inner=star]{我}[wo3][不才] +% \hanzibox[bordercolor=red]{我们}[wo3men5][吾辈] +% \end{SideBySideExample} +% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.35\linewidth,gobble=5] +% \hanzibox*[inner=cross]{我}[][吾] +% \hanzibox*[withhanzi=false,inner=star]{我}[wo3][不才] +% \hanzibox*[bordercolor=red]{我们}[wo3][吾辈] +% \end{SideBySideExample} +% \end{function} +% +% \changes{v1.1.0}{2021/09/21}{添加隐藏译文选项。} +% +% \begin{function}[added=2021-09-21]{withtran} +% \begin{syntax} +% withtran = <\TTF> +% \end{syntax} +% 为\tn{hanzibox}命令选择是否输出译文,默认值为\textbf{true}。该选项对\tn{hanzidialog}命令无效。 +% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.35\linewidth,gobble=5] +% \hanzibox[inner=cross]{我}[wo3][吾] +% \hanzibox[withtran=false,inner=star]{我}[wo3][不才] +% \hanzibox[bordercolor=red]{我们}[wo3men5][吾辈] +% \end{SideBySideExample} +% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.35\linewidth,gobble=5] +% \hanzibox*[inner=cross]{我}[][吾] +% \hanzibox*[withtran=false,inner=star]{我}[wo3][不才] +% \hanzibox*[bordercolor=red]{我们}[wo3][吾辈] +% \end{SideBySideExample} +% \end{function} +% % \end{documentation} % % \StopEventually{} @@ -374,15 +477,12 @@ Copyright and Licence % \begin{macrocode} \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". } @@ -440,12 +540,16 @@ Copyright and Licence % % \subsection{用户接口} % +% \changes{v1.1.0}{2021/09/22}{为用户命令添加组限制。} +% % \begin{macro}{\hanzidialog} % 手动汉字盒子命令。 % \begin{macrocode} \NewDocumentCommand{\hanzidialog}{ m O{} O{} } { - \@@_dialog:nnnn { #1 } { #2 } { #3 } + \group_begin: + \@@_dialog:nnnn { #1 } { #2 } { #3 } + \group_end: } % \end{macrocode} @@ -458,9 +562,13 @@ Copyright and Licence { \IfBooleanTF{#1} { - \@@_star_draw:nnnn { #2 } { #3 } { #4 } { #5 } + \group_begin: + \@@_asterisk_draw:nnnn { #2 } { #3 } { #4 } { #5 } + \group_end: }{ - \@@_draw:nnnn { #2 } { #3 } { #4 } { #5 } + \group_begin: + \@@_draw:nnnn { #2 } { #3 } { #4 } { #5 } + \group_end: } } @@ -469,10 +577,18 @@ Copyright and Licence % % \subsection{内部变量声明} % -% \begin{variable}{\l_@@_inner_int, +% \changes{v1.1.0}{2021/09/21}{添加缩放比例,前景/背景色,隐藏控制变量。} +% +% \begin{variable}{\fp_new:N \l_@@_scale_fp, +% \l_@@_inner_int, % \l_@@_border_bool, % \l_@@_borderwidth_dim, % \l_@@_bordercolor_tl, +% \l_@@_fgcolor_tl, +% \l_@@_bgcolor_tl, +% \l_@@_pinyin_bool, +% \l_@@_hanzi_bool, +% \l_@@_tran_bool, % \l_@@_pinyin_tl, % \l_@@_character_tl, % \l_@@_translation_tl, @@ -481,12 +597,18 @@ Copyright and Licence % \l_@@_translation_int % } % 临时变量。 +% % \begin{macrocode} -\fp_new:N \l_@@_ratio_fp +\fp_new:N \l_@@_scale_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_@@_fgcolor_tl +\tl_new:N \l_@@_bgcolor_tl +\bool_new:N \l_@@_pinyin_bool +\bool_new:N \l_@@_hanzi_bool +\bool_new:N \l_@@_tran_bool \tl_new:N \l_@@_pinyin_tl \tl_new:N \l_@@_character_tl \tl_new:N \l_@@_translation_tl @@ -506,11 +628,13 @@ Copyright and Licence { % \end{macrocode} % -% \begin{macro}{ratio} +% \changes{v1.1.0}{2021/09/21}{添加缩放比例键。} +% +% \begin{macro}{scale} % 设置汉字及其拼音和译文的整体缩放比例。 % \begin{macrocode} - ratio .fp_set:N = \l_@@_ratio_fp, - ratio .initial:n = 1.0, + scale .fp_set:N = \l_@@_scale_fp, + scale .initial:n = 1.0, % \end{macrocode} % \end{macro} @@ -556,6 +680,65 @@ Copyright and Licence % \end{macrocode} % \end{macro} % +% \changes{v1.1.0}{2021/09/21}{添加前景颜色键。} +% +% \begin{macro}{fgcolor} +% 汉字盒子前景颜色(文字颜色),默认为black。 +% \begin{macrocode} + fgcolor .tl_set:N = \l_@@_fgcolor_tl, + fgcolor .initial:n = black, + +% \end{macrocode} +% \end{macro} +% +% \changes{v1.1.0}{2021/09/21}{添加背景颜色键。} +% +% \begin{macro}{bgcolor} +% 汉字盒子背景颜色,默认为black。 +% \begin{macrocode} + bgcolor .tl_set:N = \l_@@_bgcolor_tl, + bgcolor .initial:n = white, + +% \end{macrocode} +% \end{macro} +% +% \changes{v1.1.0}{2021/09/21}{添加隐藏拼音键。} +% +% \begin{macro}{withpinyin} +% 是否显示汉语拼音,默认为true。 +% \begin{macrocode} + withpinyin .bool_set:N = \l_@@_pinyin_bool, + withpinyin .default:n = true, + withpinyin .initial:n = true, + +% \end{macrocode} +% \end{macro} +% +% \changes{v1.1.0}{2021/09/21}{添加隐藏汉字键。} +% +% \begin{macro}{withhanzi} +% 是否显示汉语拼音,默认为true。 +% \begin{macrocode} + withhanzi .bool_set:N = \l_@@_hanzi_bool, + withhanzi .default:n = true, + withhanzi .initial:n = true, + +% \end{macrocode} +% \end{macro} +% +% \changes{v1.1.0}{2021/09/21}{添加隐藏译文键。} +% +% \begin{macro}{withtran} +% 是否显示汉语拼音,默认为true。 +% \begin{macrocode} + withtran .bool_set:N = \l_@@_tran_bool, + withtran .default:n = true, + withtran .initial:n = true, + +% \end{macrocode} +% \end{macro} +% +% % 处理未知选项。 % \begin{macrocode} unknown .code:n = { \@@_error:n { unknown-option } } @@ -585,13 +768,13 @@ Copyright and Licence \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}{ + \scalebox{\fp_use:N \l_@@_scale_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}}, + {\node[] at (1,1){\huge{\l_@@_character_tl}}}; + {\node[label={\strut\small\textbf{\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}};}% + {\strut\small\textit{\l_@@_translation_tl}};}% }% }% } @@ -610,6 +793,11 @@ Copyright and Licence % \end{macro} % \end{macro} % +% \changes{v1.1.0}{2021/09/21}{添加整体缩放代码。} +% \changes{v1.1.0}{2021/09/21}{添加按需要隐藏拼音、汉字或译文代码。} +% \changes{v1.1.0}{2021/09/21}{将隐藏功能修正为用前景/背景色实现。} +% \changes{v1.1.0}{2021/09/22}{将各部分绘制分解为函数实现。} +% % \begin{macro}{\@@_draw:nnnn} % 自动汉字盒子排版内部命令,根据选项用TikZ实现绘制。 % \begin{macrocode} @@ -647,74 +835,73 @@ Copyright and Licence \tl_count:V \l_@@_translation_tl } - \scalebox{\fp_use:N \l_@@_ratio_fp}{ + \scalebox{\fp_use:N \l_@@_scale_fp}{ \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{% - \int_compare:nNnT { \l_@@_character_int } < {2} +% \end{macrocode} +% +% 根据汉字长度绘制汉字盒子背景,必须提前绘制 +% +% \begin{macrocode} + \@@_border_draw:n {0.0cm} +% \end{macrocode} +% +% 如果显示汉字,则内部格线应该提前绘制 +% +% \begin{macrocode} + \bool_if:NT \l_@@_hanzi_bool { - \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);% - } - } + \@@_frame_background:n {0.0cm} } \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} - { } + \bool_if:NTF \l_@@_hanzi_bool { - \node[label={\strut\small\@@_pinyinaux:x {\l_@@_pinyin_tl}}, - text~height=1cm] (charr) at (1,1){}; + \node[\l_@@_fgcolor_tl] at (1,1){\huge{\l_@@_character_tl}}; + }{ + \node[\l_@@_bgcolor_tl] at (1,1){\huge{\l_@@_character_tl}}; } - \int_compare:nNnTF { \l_@@_translation_int } = {0} - { } + \bool_if:NTF \l_@@_pinyin_bool { - \node[align=center] at (1,-0.5) - {\strut\small\textit{\tl_use:N \l_@@_translation_tl}}; + \node[label={[font=\small,text=\l_@@_fgcolor_tl] + \strut\@@_pinyinaux:x {\l_@@_pinyin_tl}}, + text~height=1cm] (charr) at (1,1){}; + }{ + \node[label={[font=\small,text=\l_@@_bgcolor_tl] + \strut\@@_pinyinaux:x {\l_@@_pinyin_tl}}, + text~height=1cm] (charr) at (1,1){}; } + \@@_tran_draw:nn {1}{-0.5} } { - \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} - { } + \bool_if:NTF \l_@@_hanzi_bool { - \node[label={\strut\small\@@_pinyinaux:x {\l_@@_pinyin_tl}}, - text~height=1cm] (charr) at (1*\l_@@_character_int,1){}; + \node[\l_@@_fgcolor_tl] at (1*\l_@@_character_int,1) + {\huge\tl_use:N \l_@@_character_tl}; + }{ + \node[\l_@@_bgcolor_tl] at (1*\l_@@_character_int,1) + {\huge\tl_use:N \l_@@_character_tl}; } - \int_compare:nNnTF { \l_@@_translation_int } = {0} - { } + \bool_if:NTF \l_@@_pinyin_bool { - \node[align=center] at (1*\l_@@_character_int,-0.5) - {\strut\small\textit{\tl_use:N \l_@@_translation_tl}}; + \node[label={[font=\small,text=\l_@@_fgcolor_tl] + \strut\@@_pinyinaux:x {\l_@@_pinyin_tl}}, + text~height=1cm] (charr) at (1*\l_@@_character_int,1){}; + }{ + \node[label={[font=\small,text=\l_@@_bgcolor_tl] + \strut\@@_pinyinaux:x {\l_@@_pinyin_tl}}, + text~height=1cm] (charr) at (1*\l_@@_character_int,1){}; } + \@@_tran_draw:nn {\l_@@_character_int}{-0.5} + } +% \end{macrocode} +% +% 如果不显示汉字,则内部格线应该最后绘制 +% +% \begin{macrocode} + \bool_if:NF \l_@@_hanzi_bool + { + \@@_frame_background:n {0.0cm} } }% }% @@ -722,10 +909,15 @@ Copyright and Licence % \end{macrocode} % \end{macro} % -% \begin{macro}{\@@_star_draw:nnnn} +% \changes{v1.1.0}{2021/09/21}{添加\tn{hanzibox*}星号命令的内部实现代码。} +% \changes{v1.1.0}{2021/09/21}{添加按需要隐藏拼音、汉字或译文代码。} +% \changes{v1.1.0}{2021/09/21}{将隐藏功能修正为用前景/背景色实现。} +% \changes{v1.1.0}{2021/09/22}{将各部分绘制分解为函数实现。} +% +% \begin{macro}{\@@_asterisk_draw:nnnn} % 自动汉字拼音盒子排版内部命令,根据选项用TikZ实现绘制。 % \begin{macrocode} -\cs_new_protected:Npn \@@_star_draw:nnnn #1#2#3#4 +\cs_new_protected:Npn \@@_asterisk_draw:nnnn #1#2#3#4 { % \end{macrocode} % @@ -759,61 +951,86 @@ Copyright and Licence \tl_count:V \l_@@_translation_tl } - \scalebox{\fp_use:N \l_@@_ratio_fp}{ + \scalebox{\fp_use:N \l_@@_scale_fp}{ \tikz[scale=0.5, every~node/.style={inner~sep=0,outer~sep=0}]{% - \int_compare:nNnT { \l_@@_character_int } < {2} +% \end{macrocode} +% +% 根据汉字长度绘制汉字盒子背景,必须提前绘制 +% +% \begin{macrocode} + \@@_border_draw:n {-0.5cm} +% \end{macrocode} +% +% 如果显示汉字,则内部格线应该提前绘制 +% +% \begin{macrocode} + \bool_if:NT \l_@@_hanzi_bool { - \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);% - } - } + \@@_frame_background:n {-0.5cm} } \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} - { } + \bool_if:NTF \l_@@_pinyin_bool { - \node[align=center] at (1,-1.0) - {\strut\small\textit{\tl_use:N \l_@@_translation_tl}}; + \bool_if:NTF \l_@@_hanzi_bool + { + \node[\l_@@_fgcolor_tl] at (1,1) + {\huge{\xpinyin*[format={\small\color{\l_@@_fgcolor_tl}}, + vsep=0.90 cm]{\l_@@_character_tl}}}; + }{ + \node[\l_@@_bgcolor_tl] at (1,1) + {\huge{\xpinyin*[format={\small\color{\l_@@_fgcolor_tl}}, + vsep=0.90 cm]{\l_@@_character_tl}}}; + } + }{ + \bool_if:NTF \l_@@_hanzi_bool + { + \node[\l_@@_fgcolor_tl] at (1,1) + {\huge{\xpinyin*[format={\small\color{\l_@@_bgcolor_tl}}, + vsep=0.90 cm]{\l_@@_character_tl}}}; + }{ + \node[\l_@@_fgcolor_tl] at (1,1) + {\huge{\xpinyin*[format={\small\color{\l_@@_bgcolor_tl}}, + vsep=0.90 cm]{\l_@@_character_tl}}}; + } } + \@@_tran_draw:nn {1}{-1.0} } { - \bool_if:NTF \l_@@_border_bool + \bool_if:NTF \l_@@_pinyin_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}}; + \bool_if:NTF \l_@@_hanzi_bool + { + \node[\l_@@_fgcolor_tl] at (1*\l_@@_character_int,1) + {\huge{\xpinyin*[format={\small\color{\l_@@_fgcolor_tl}}, + vsep=0.90 cm]{\l_@@_character_tl}}}; + }{ + \node[\l_@@_bgcolor_tl] at (1*\l_@@_character_int,1) + {\huge{\xpinyin*[format={\small\color{\l_@@_fgcolor_tl}}, + vsep=0.90 cm]{\l_@@_character_tl}}}; + } + }{ + \bool_if:NTF \l_@@_hanzi_bool + { + \node[\l_@@_fgcolor_tl] at (1*\l_@@_character_int,1) + {\huge{\xpinyin*[format={\small\color{\l_@@_bgcolor_tl}}, + vsep=0.90 cm]{\l_@@_character_tl}}}; + }{ + \node[\l_@@_fgcolor_tl] at (1*\l_@@_character_int,1) + {\huge{\xpinyin*[format={\small\color{\l_@@_bgcolor_tl}}, + vsep=0.90 cm]{\l_@@_character_tl}}}; + } } + \@@_tran_draw:nn {\l_@@_character_int}{-1.0} + } +% \end{macrocode} +% +% 如果不显示汉字,则内部格线应该最后绘制 +% +% \begin{macrocode} + \bool_if:NF \l_@@_hanzi_bool + { + \@@_frame_background:n {-0.5cm} } }% }% @@ -821,6 +1038,109 @@ Copyright and Licence % \end{macrocode} % \end{macro} % +% \changes{v1.1.0}{2021/09/22}{添加方格背景绘制内部函数。} +% +% \begin{macro}{\@@_frame_background:n} +% TikZ米字格绘制代码。 +% \begin{macrocode} +\cs_new_protected:Npn \@@_frame_background:n #1 + { + \int_compare:nNnT { \l_@@_character_int } < {2} + { + \int_case:nn {\l_@@_inner_int} + { + {1}{ + } + {2}{ + \@@_star_background:n {#1} + } + {3}{ + \@@_cross_background:n {#1} + } + } + } + } +% \end{macrocode} +% \end{macro} +% +% \changes{v1.1.0}{2021/09/22}{添加米字格内部函数。} +% +% \begin{macro}{\@@_star_background:n} +% TikZ米字格绘制代码。 +% \begin{macrocode} +\cs_new_protected:Npn \@@_star_background:n #1 + { + \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, + \l_@@_bordercolor_tl!50](0,0)--(2,2);% + \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, + \l_@@_bordercolor_tl!50](0,2)--(2,0);% + + \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, + \l_@@_bordercolor_tl!50](0,1)--(2,1);% + \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, + \l_@@_bordercolor_tl!50](1,0)--(1,2);% + } +% \end{macrocode} +% \end{macro} +% +% \changes{v1.1.0}{2021/09/22}{添加田字格背景内部函数。} +% +% \begin{macro}{\@@_cross_background:n} +% TikZ田字格绘制代码。 +% \begin{macrocode} +\cs_new_protected:Npn \@@_cross_background:n #1 + { + \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, + \l_@@_bordercolor_tl!50](0,1)--(2,1);% + \draw[stretch~dash=on~2pt~off~2pt,thin, yshift=#1, + \l_@@_bordercolor_tl!50](1,0)--(1,2);% + } +% \end{macrocode} +% \end{macro} +% +% \changes{v1.1.0}{2021/09/22}{添加背景方格内部函数。} +% +% \begin{macro}{\@@_border_draw:n} +% 绘制边框代码。 +% \begin{macrocode} +\cs_new_protected:Npn \@@_border_draw:n #1 + { + \int_compare:nNnTF { \l_@@_character_int } = {0} + { + \draw[fill=\l_@@_bgcolor_tl,line~width=\l_@@_borderwidth_dim, + yshift=#1, draw=\l_@@_bordercolor_tl] (0,0) rectangle(2,2); + } + { + \bool_if:NTF \l_@@_border_bool + { + \draw[fill=\l_@@_bgcolor_tl,line~width=\l_@@_borderwidth_dim, + yshift=#1, draw=\l_@@_bordercolor_tl] (0,0) + rectangle(2*\l_@@_character_int,2); + }{} + } + } +% \end{macrocode} +% \end{macro} +% +% \changes{v1.1.0}{2021/09/22}{添加译文文本绘制内部函数。} +% +% \begin{macro}{\@@_tran_draw:nn} +% 绘制译文文本。 +% \begin{macrocode} +\cs_new_protected:Npn \@@_tran_draw:nn #1#2 + { + \bool_if:NTF \l_@@_tran_bool + { + \node[align=center,\l_@@_fgcolor_tl] at (1*#1,#2) + {\strut\small\textit{\l_@@_translation_tl}}; + }{ + \node[align=center,\l_@@_bgcolor_tl] at (1*#1,#2) + {\strut\small\textit{\l_@@_translation_tl}}; + } + } +% \end{macrocode} +% \end{macro} +% % \begin{macrocode} %</package> % \end{macrocode} |