diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/siunitx/siunitx-unit.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/siunitx/siunitx-unit.dtx | 122 |
1 files changed, 69 insertions, 53 deletions
diff --git a/Master/texmf-dist/source/latex/siunitx/siunitx-unit.dtx b/Master/texmf-dist/source/latex/siunitx/siunitx-unit.dtx index f066530439a..604883dfa6e 100644 --- a/Master/texmf-dist/source/latex/siunitx/siunitx-unit.dtx +++ b/Master/texmf-dist/source/latex/siunitx/siunitx-unit.dtx @@ -1179,8 +1179,12 @@ % \begin{macro}{\@@_format_literal_auxi:w} % \begin{macro}{\@@_format_literal_auxii:w} % \begin{macro}{\@@_format_literal_auxiii:w} -% \begin{macro}{\@@_format_literal_auxiv:w} -% \begin{macro}{\@@_format_literal_auxv:w} +% \begin{macro}{\@@_format_literal_auxiv:n} +% \begin{macro}{\@@_format_literal_auxv:nw} +% \begin{macro}{\@@_format_literal_auxvi:nN} +% \begin{macro}{\@@_format_literal_super:nn, \@@_format_literal_sub:nn} +% \begin{macro}{\@@_format_literal_add:n} +% \begin{macro}{\@@_format_literal_auxvii:nn} % \begin{variable}{\l_@@_separator_tl} % To format literal units, there are two tasks to do. The input is % \texttt{x}-type expanded to force any symbolic units to be converted into @@ -1254,71 +1258,79 @@ \cs_new_protected:Npn \@@_format_literal_auxiii:w #1 / { \quark_if_recursion_tail_stop:n {#1} - \@@_format_literal_auxiv:w #1 ^ ^ \q_stop + \@@_format_literal_auxiv:n {#1} \tl_set:Nn \l_@@_separator_tl { / } \@@_format_literal_auxiii:w } +\cs_new_protected:Npn \@@_format_literal_auxiv:n #1 + { + \@@_format_literal_auxv:nw { } + #1 \q_recursion_tail \q_recursion_stop + } % \end{macrocode} -% Within each unit any sub- and superscript parts need to be separated out: -% wrapping everything in the font command is incorrect. The superscript part -% is relatively easy as there is no catcode issue or font command to add, -% while the subscript part needs a bit more work. As the user might have the -% two parts in either order, picking up the subscript needs to look in two -% places. We assume that only one is given: odd input here is simply accepted. +% To deal properly with literal formatting, we have to worry about super- +% and subscript markers. That can be complicated as they could come anywhere +% in the input: we handle that by iterating through the input and picking +% them out. This avoids any issue with loosing braces for mid-input scripts. +% We also have to deal with fractions, hence needing a series of nested +% loops and a change of separator. % \begin{macrocode} -\use:x +\cs_new_protected:Npn \@@_format_literal_auxv:nw + #1#2 \q_recursion_stop + { + \tl_if_head_is_N_type:nTF {#2} + { \@@_format_literal_auxvi:nN } + { \@@_format_literal_auxvii:nn } + {#1} #2 \q_recursion_stop + } +\cs_new_protected:Npx \@@_format_literal_auxvi:nN #1#2 { - \cs_new_protected:Npn \exp_not:N \@@_format_literal_auxiv:w - ##1 ^ ##2 ^ ##3 \exp_not:N \q_stop + \exp_not:N \quark_if_recursion_tail_stop_do:Nn #2 + { \exp_not:N \@@_format_literal_add:n {#1} } + \exp_not:N \token_if_eq_meaning:NNTF #2 ^ + { \exp_not:N \@@_format_literal_super:nn {#1} } { - \exp_not:N \@@_format_literal_auxv:w - ##1 - \c_@@_math_subscript_tl - \c_@@_math_subscript_tl - \exp_not:N \q_mark - ##2 - \c_@@_math_subscript_tl - \c_@@_math_subscript_tl - \exp_not:N \q_stop + \exp_not:N \token_if_eq_meaning:NNTF + #2 \c_@@_math_subscript_tl + { \exp_not:N \@@_format_literal_sub:nn {#1} } + { \exp_not:N \@@_format_literal_auxvi:nN {#1#2} } } - \cs_new_protected:Npn \exp_not:N \@@_format_literal_auxv:w - ##1 \c_@@_math_subscript_tl - ##2 \c_@@_math_subscript_tl ##3 - \exp_not:N \q_mark - ##4 \c_@@_math_subscript_tl - ##5 \c_@@_math_subscript_tl ##6 - \exp_not:N \q_stop + } +\cs_new_protected:Npn \@@_format_literal_super:nn #1#2 + { + \quark_if_recursion_tail_stop:n {#2} + \@@_format_literal_add:n {#1} + \tl_put_right:Nn \l_@@_formatted_tl { ^ {#2} } + \@@_format_literal_auxvi:nN { } + } +\cs_new_protected:Npx \@@_format_literal_sub:nn #1#2 + { + \exp_not:N \quark_if_recursion_tail_stop:n {#2} + \exp_not:N \@@_format_literal_add:n {#1} + \tl_put_right:Nx \exp_not:N \l_@@_formatted_tl { - \tl_set:Nx \exp_not:N \l_@@_formatted_tl + \c_@@_math_subscript_tl { \exp_not:N \exp_not:V - \exp_not:N \l_@@_formatted_tl - \exp_not:N \tl_if_empty:NF - \exp_not:N \l_@@_formatted_tl - { - \exp_not:N \exp_not:V - \exp_not:N \l_@@_separator_tl - } - \exp_not:N \tl_if_blank:nF {##1} - { - \exp_not:N \exp_not:V - \exp_not:N \l_siunitx_unit_font_tl - { \exp_not:N \exp_not:n {##1} } - } - \exp_not:N \tl_if_blank:nF {##4} - { ^ { \exp_not:N \exp_not:n {##4} } } - \exp_not:N \tl_if_blank:nF {##2##5} - { - \c_@@_math_subscript_tl - { - \exp_not:N \exp_not:V - \exp_not:N \l_siunitx_unit_font_tl - { \exp_not:N \exp_not:n {##2##5} } - } - } + \exp_not:N \l_siunitx_unit_font_tl + { \exp_not:N \exp_not:n {#2} } } } + \exp_not:N \@@_format_literal_auxvi:nN { } } +\cs_new_protected:Npn \@@_format_literal_add:n #1 + { + \tl_put_right:Nx \l_@@_formatted_tl + { + \tl_if_empty:NF \l_@@_formatted_tl + { \exp_not:V \l_@@_separator_tl } + \tl_if_empty:nF {#1} + { \exp_not:V \l_siunitx_unit_font_tl { \exp_not:n {#1} } } + } + \tl_clear:N \l_@@_separator_tl + } +\cs_new_protected:Npn \@@_format_literal_auxvii:nn #1#2 + { \@@_format_literal_auxvi:nN { #1 {#2} } } \tl_new:N \l_@@_separator_tl % \end{macrocode} % \end{variable} @@ -1329,6 +1341,10 @@ % \end{macro} % \end{macro} % \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} % % \subsection{(PDF) String creation} % |