diff options
author | Karl Berry <karl@freefriends.org> | 2021-07-24 20:48:09 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-07-24 20:48:09 +0000 |
commit | f0de3338cfffa669b4bfa9f7b24d887637265089 (patch) | |
tree | a6123d80e5ca4106e8f62275c00013f5f155239c /Master/texmf-dist/source | |
parent | 3a2294eff9e415a4ff2a6b6275988c8cf14cd628 (diff) |
spbmark (24jul21)
git-svn-id: svn://tug.org/texlive/trunk@60044 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r-- | Master/texmf-dist/source/latex/spbmark/spbmark.dtx | 144 |
1 files changed, 94 insertions, 50 deletions
diff --git a/Master/texmf-dist/source/latex/spbmark/spbmark.dtx b/Master/texmf-dist/source/latex/spbmark/spbmark.dtx index 33498e535e5..b2666aab806 100644 --- a/Master/texmf-dist/source/latex/spbmark/spbmark.dtx +++ b/Master/texmf-dist/source/latex/spbmark/spbmark.dtx @@ -23,7 +23,7 @@ % % \title{\pkg{spbmark} -- Customize superscripts and subscripts} % \author{Qu Yi} -% \date{2021/07/22\hskip 1em\relax v1.02\thanks{\url{https://github.com/texl3/spbmark}}} +% \date{2021/07/23\hskip 1em\relax v1.04\thanks{\url{https://github.com/texl3/spbmark}}} % % \maketitle % \begin{abstract} @@ -53,7 +53,7 @@ % \tn{super} command is used to output superscripts, \tn{sub} command is used to output subscripts, \tn{supersub} command is used to output both superscripts and subscripts. % \end{function} % -% They match the corresponding pattern depending on whether they are currently in text mode or mathematical mode, or they can use an asterisk variant to force the mathematical pattern. The \meta{vshift} and \meta{hshift} represent respectively vertical and horizontal offsets of superscript or subscript, their default value is 0 pt, and the parameters of \meta{script align} are the same as the \texttt{supersubalign}. +% They match the corresponding pattern depending on whether they are currently in text mode or mathematical mode, or they can use an asterisk variant to force the mathematical pattern. The \meta{vshift} and \meta{hshift} represent respectively vertical and horizontal offsets of superscript or subscript, their default value is \texttt{0pt}, and the parameters of \meta{script align} are the same as the \texttt{supersubalign}. % % The second optional parameter generally does not need to be used. The \meta{height} and \meta{depth} are separated by commas. Only the front part indicates the height of the superscript or subscript, and only the back part indicates the depth. % @@ -66,22 +66,23 @@ % \end{function} % % \section{Global control interface} -% \begin{function}[added = 2021-06-26]{\spbset} +% \begin{function}[added = 2021-06-26,updated = 2021-07-23]{\spbset} % \begin{syntax} % \tn{spbset}\marg{key-value list} % \end{syntax} -% \pkg{spbmark} uses the \tn{spbset} command to control the global default format of superscripts and subscripts. The values set by it will be overwritten by the optional parameters of the superscript and other commands. The list of key values it has is as follows: +% \pkg{spbmark} uses the \tn{spbset} command to control the global default format of superscripts and subscripts. The values set by it will be overwritten by the optional parameters of the superscript and other commands. % \end{function} % -% \begin{function}{super-vshift,super-hshift,sub-vshift,sub-hshift,supersubsep,supersubalign} +% \begin{function}{super-vshift,super-hshift,sub-vshift,sub-hshift,super-format,sub-format} % \begin{syntax} % super-vshift = <fixed length> % super-hshift = <fixed length> % sub-vshift = <fixed length> % sub-hshift = <fixed length> -% supersubsep = <fixed length> -% supersubalign = <horizontal alignment> +% super-format = <format code> +% sub-format = <format code> % \end{syntax} +% These list of keys control the format of superscript or subscript. They are equivalent to the optional parameters of the \tn{super} or \tn{sub} commands. % \end{function} % % \noindent @@ -89,17 +90,35 @@ % \DescribeOption{super-hshift} Extra horizontal shift of the superscripts. \\ % \DescribeOption{sub-vshift} Extra vertical shift of the subscripts. \\ % \DescribeOption{sub-hshift} Extra horizontal shift of the subscripts. \\ -% \DescribeOption{supersubsep} The distance between superscript and subscript when using \tn{supersub}, its default value is 0.3 ex. \\ -% \DescribeOption{supersubalign} The alignment of superscript and subscript when using \tn{supersub}, which contains l, c, and r parameters respectively for left, center, and right alignment. \\ +% \DescribeOption{super-format} Control the format of superscripts, the last command in the code can take an argument, which is a superscript. \\ +% \DescribeOption{sub-format} Control the format of subscripts, the last command in the code can take an argument, which is a subscript. +% +% \begin{function}{supersub-hshift,supersub-format,supersubsep,supersubalign} +% \begin{syntax} +% supersub-hshift = <fixed length> +% supersub-format = \{<super code>,<sub code>\} +% supersubsep = <fixed length> +% supersubalign = <horizontal alignment> +% \end{syntax} +% These list of keys control the format of superscripts and subscripts. They are equivalent to the optional parameters of the \tn{supersub} command. +% \end{function} +% +% \noindent +% \DescribeOption{supersub-hshift} Extra vertical shift of the superscripts and the subscripts. \\ +% \DescribeOption{supersub-format} Control the format of superscripts or subscripts. The first part is in superscript format, and the latter part is in subscript format. The two are separated by commas, or only the first part exists. \\ +% \DescribeOption{supersubsep} The distance between superscripts and subscripts, its default value is \texttt{0.3ex}. \\ +% \DescribeOption{supersubalign} The alignment of superscripts and subscripts, which contains \texttt{l}, \texttt{c}, and \texttt{r} parameters respectively for left, center, and right alignment. % % \section{Examples of use} % Here is a list of the three commands, please pay attention to the delimiter and usage of optional parameters: % \begin{quotation} % \noindent -% |A\super[0.2ex](\color{red}){exam}[0.2em]B| \\ +% |\spbset{supersub-format = {\ttfamily,\color{blue}}}| \\ +% |A\super[0.2ex](\textcolor{red}){exam}[0.2em]B| \\ % |$A\sub(\mathsf){exam}B$| \\ % |A\supersub[0.3ex][c]{examsuper}{sub}B| \\ -% A\super[0.2ex](\color{red}){exam}[0.2em]B \\ +% \spbset{supersub-format = {\ttfamily,\color{blue}}} +% A\super[0.2ex](\textcolor{red}){exam}[0.2em]B \\ % $A\sub(\mathsf){exam}B$ \\ % A\supersub[0.3ex][c]{examsuper}{sub}B % \end{quotation} @@ -136,7 +155,7 @@ %<*package> \NeedsTeXFormat{LaTeX2e}[2018/12/31] \RequirePackage{xparse,l3keys2e} -\ProvidesExplPackage{spbmark}{2021/07/22}{1.02} +\ProvidesExplPackage{spbmark}{2021/07/23}{1.04} {Customize superscripts and subscripts} \cs_new_protected:Npn \spb_define:n { \keys_define:nn { spbmark } } @@ -155,28 +174,33 @@ \ProcessKeysOptions{spbmark/option} +\tl_new:N \l__spb_super_script_formatii_tl +\tl_new:N \l__spb_sub_script_formatii_tl \spb_define:n { - super-vshift .dim_set:N = \l__spb_super_script_vshift_dim, - super-vshift .initial:n = 0pt, - super-hshift .dim_set:N = \l__spb_super_script_hshift_dim, - super-hshift .initial:n = 0pt, - sub-vshift .dim_set:N = \l__spb_sub_script_vshift_dim, - sub-vshift .initial:n = 0pt, - sub-hshift .dim_set:N = \l__spb_sub_script_hshift_dim, - sub-hshift .initial:n = 0pt, - supersubsep .dim_set:N = \l__spb_supersub_script_sep_dim, - supersubsep .initial:n = 0.3ex, - supersubalign .tl_set:N = \l__spb_supersub_script_align_tl, - supersubalign .initial:n = l + super-vshift .dim_set:N = \l__spb_super_script_vshift_dim, + super-vshift .initial:n = 0pt, + super-hshift .dim_set:N = \l__spb_super_script_hshift_dim, + super-hshift .initial:n = 0pt, + sub-vshift .dim_set:N = \l__spb_sub_script_vshift_dim, + sub-vshift .initial:n = 0pt, + sub-hshift .dim_set:N = \l__spb_sub_script_hshift_dim, + sub-hshift .initial:n = 0pt, + supersub-hshift .dim_set:N = \l__spb_supersub_script_hshift_dim, + supersub-hshift .initial:n = 0pt, + super-format .tl_set:N = \l__spb_super_script_formati_tl, + sub-format .tl_set:N = \l__spb_sub_script_formati_tl, + supersub-format .code:n = \spb_both_format_assign:n {#1}, + supersubsep .dim_set:N = \l__spb_supersub_script_sep_dim, + supersubsep .initial:n = 0.3ex, + supersubalign .tl_set:N = \l__spb_supersub_script_align_tl, + supersubalign .initial:n = l } \tl_set:Nn \l__spb_boxa_wd_tl { \box_wd:N \l_tmpa_box } \tl_set:Nn \l__spb_boxb_wd_tl { \box_wd:N \l_tmpb_box } \cs_new:Npn \spb_tmp_boxa_use: { \box_use:N \l_tmpa_box } \cs_new:Npn \spb_tmp_boxb_use: { \box_use:N \l_tmpb_box } -\cs_new:Npn \spb_tmp_hboxa_set:n #1 { \hbox_set:Nn \l_tmpa_box {#1} } -\cs_new:Npn \spb_tmp_hboxb_set:n #1 { \hbox_set:Nn \l_tmpb_box {#1} } \cs_new:Npn \spb_box_max_dim_horizontal: { \skip_horizontal:n @@ -194,6 +218,26 @@ \spb_boxwd_subtract:nnnn { -0.5 } { 0.5 } {#1} {#2} \use:c { spb_tmp_#1_use: } } +\cs_new:Npn \spb_math_print_store:nnn #1#2#3 + { + \hbox_set:Nn \l_tmpa_box + { \ensuremath{#1{\spb_math:nn {#2} {#3}}} } + } +\cs_new:Npn \spb_text_print_store:nnn #1#2#3 + { + \hbox_set:Nn \l_tmpa_box + { #1{\use:c { spb@text#2script@save }{#3}} } + } +\cs_new:Npn \spb_math_print_store:nnnn #1#2#3#4 + { + \hbox_set:Nn \l_tmpa_box { \ensuremath{#1{\spb@sp@save{#2}}} } + \hbox_set:Nn \l_tmpb_box { \ensuremath{#3{\spb@sb@save{#4}}} } + } +\cs_new:Npn \spb_text_print_store:nnnn #1#2#3#4 + { + \hbox_set:Nn \l_tmpa_box { #1{\spb@textsuperscript@save{#2}} } + \hbox_set:Nn \l_tmpb_box { #3{\spb@textsubscript@save{#4}} } + } \cs_set_eq:NN \spb@textsuperscript@save \textsuperscript \cs_set_eq:NN \spb@textsubscript@save \textsubscript \cs_set_eq:NN \spb@sp@save \sp @@ -211,29 +255,34 @@ \tl_if_empty:nF {#1} { \box_set_ht:Nn \l_tmpb_box {#1} } \tl_if_novalue:nF {#2} { \box_set_dp:Nn \l_tmpb_box {#2} } } +\NewDocumentCommand{\spb_both_format_assign:n} + {>{\SplitArgument{1}{,}}m} + {\spb_supersub_script_both_format:nn #1} +\cs_new_protected:Npn \spb_supersub_script_both_format:nn #1#2 + { + \tl_set:Nn \l__spb_super_script_formatii_tl {#1} + \tl_if_novalue:nTF {#2} + { \tl_clear:N \l__spb_sub_script_formatii_tl } + { \tl_set:Nn \l__spb_sub_script_formatii_tl {#2} } + } + \clist_map_inline:nn { super,sub } { \exp_args:Nc \NewDocumentCommand {#1} { sO{\dim_use:c { l__spb_#1_script_vshift_dim }} - >{\SplitArgument{1}{,}}O{}D(){} + >{\SplitArgument{1}{,}}O{} + D(){\tl_use:c { l__spb_#1_script_formati_tl }} mO{\dim_use:c { l__spb_#1_script_hshift_dim }} } { \IfBooleanTF{##1} + {\spb_math_print_store:nnn {##4} {#1} {##5}} { - \spb_tmp_hboxa_set:n - { \ensuremath{##4{\spb_math:nn {#1} {##5}}} } - }{ \mode_if_math:TF - { - \spb_tmp_hboxa_set:n - { \ensuremath{##4{\spb_math:nn {#1} {##5}}} } - }{ - \spb_tmp_hboxa_set:n - { ##4{\use:c { spb@text#1script@save }{##5}} } - } + { \spb_math_print_store:nnn {##4} {#1} {##5} } + { \spb_text_print_store:nnn {##4} {#1} {##5} } } \hbox_set_to_wd:Nnn \l_tmpb_box { \l__spb_boxa_wd_tl + ##6 } { \hss\box_move_up:nn {##2} { \spb_tmp_boxa_use: } } @@ -244,23 +293,18 @@ \NewDocumentCommand{\supersub} { sO{\l__spb_supersub_script_sep_dim} - O{\l__spb_supersub_script_align_tl}D(){}mmO{0pt}D(){} + O{\l__spb_supersub_script_align_tl} + D(){\l__spb_super_script_formatii_tl}mm + O{\l__spb_supersub_script_hshift_dim} + D(){\l__spb_sub_script_formatii_tl} } { \IfBooleanTF{#1} + {\spb_math_print_store:nnnn {#4} {#5} {#8} {#6}} { - \spb_tmp_hboxa_set:n { \ensuremath{#4{\spb@sp@save{#5}}} } - \spb_tmp_hboxb_set:n { \ensuremath{#8{\spb@sb@save{#6}}} } - }{ \mode_if_math:TF - { - \spb_tmp_hboxa_set:n { \ensuremath{#4{\spb@sp@save{#5}}} } - \spb_tmp_hboxb_set:n { \ensuremath{#8{\spb@sb@save{#6}}} } - } - { - \spb_tmp_hboxa_set:n { #4{\spb@textsuperscript@save{#5}} } - \spb_tmp_hboxb_set:n { #8{\spb@textsubscript@save{#6}} } - } + { \spb_math_print_store:nnnn {#4} {#5} {#8} {#6} } + { \spb_text_print_store:nnnn {#4} {#5} {#8} {#6} } } \hbox_set_to_wd:Nnn \l_tmpa_box { \l__spb_boxa_wd_tl + #7 } { \hss\box_move_up:nn {#2} { \spb_tmp_boxa_use: } } @@ -282,7 +326,7 @@ \spb_box_max_dim_horizontal: } { - \dim_compare:nTF { \l__spb_boxa_wd_tl > \l__spb_boxb_wd_tl } + \dim_compare:nNnTF { \l__spb_boxa_wd_tl } > { \l__spb_boxb_wd_tl } { \spb_boxwd_script_align:nn { boxa } { boxb } } { \spb_boxwd_script_align:nn { boxb } { boxa } } } |