From f4fb829042e4dbbb1c8c05add1060da51b14ca66 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 16 Nov 2011 01:15:54 +0000 Subject: siunitx 2.4 (14nov11) git-svn-id: svn://tug.org/texlive/trunk@24604 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/siunitx/README | 2 - Master/texmf-dist/doc/latex/siunitx/siunitx.pdf | Bin 564682 -> 570576 bytes Master/texmf-dist/source/latex/siunitx/siunitx.dtx | 3068 ++++++++++---------- .../latex/siunitx/config/siunitx-abbreviations.cfg | 2 +- .../tex/latex/siunitx/config/siunitx-binary.cfg | 2 +- .../tex/latex/siunitx/config/siunitx-version-1.cfg | 94 +- Master/texmf-dist/tex/latex/siunitx/siunitx.sty | 2352 ++++++++------- 7 files changed, 2798 insertions(+), 2722 deletions(-) diff --git a/Master/texmf-dist/doc/latex/siunitx/README b/Master/texmf-dist/doc/latex/siunitx/README index 6d0438f160d..ff3caf89b03 100644 --- a/Master/texmf-dist/doc/latex/siunitx/README +++ b/Master/texmf-dist/doc/latex/siunitx/README @@ -61,5 +61,3 @@ need the packages: - listings - pgfplots - xcolor -The xfrac package is also loaded if available, but is not -required to typeset the documentation. diff --git a/Master/texmf-dist/doc/latex/siunitx/siunitx.pdf b/Master/texmf-dist/doc/latex/siunitx/siunitx.pdf index c26fed17cce..bd1be6f42ec 100644 Binary files a/Master/texmf-dist/doc/latex/siunitx/siunitx.pdf and b/Master/texmf-dist/doc/latex/siunitx/siunitx.pdf differ diff --git a/Master/texmf-dist/source/latex/siunitx/siunitx.dtx b/Master/texmf-dist/source/latex/siunitx/siunitx.dtx index 45af72af81d..8d4beff96f9 100644 --- a/Master/texmf-dist/source/latex/siunitx/siunitx.dtx +++ b/Master/texmf-dist/source/latex/siunitx/siunitx.dtx @@ -66,8 +66,6 @@ need the packages: - listings - pgfplots - xcolor -The xfrac package is also loaded if available, but is not -required to typeset the documentation. % %<*internal> \fi @@ -144,17 +142,7 @@ This work consists of the file siunitx.dtx \documentclass[german,french,english,UKenglish]{l3doc} \usepackage[table]{xcolor} \usepackage{amsmath,babel,booktabs,cancel,caption,colortbl,csquotes} -\usepackage{datatool,helvet,multirow,pgfplots,siunitx,xtab} -\IfFileExists{xfrac.sty} - {\usepackage{xfrac}} - {% - \PackageWarningNoLine{siunitx} - {% - xfrac unavailable: \string\sfrac\space fraction\MessageBreak - will have wrong appearance% - } - } -\ProvideDocumentCommand\sfrac{mm}{\frac{#1}{#2}} +\usepackage{datatool,helvet,multirow,pgfplots,siunitx,xfrac,xtab} \usepackage[capitalise]{cleveref} \usepackage[final]{listings} \usepackage[osf]{mathpazo} @@ -388,7 +376,7 @@ This work consists of the file siunitx.dtx %^^A It is achieved by temporarily disabling \@latex@warning@no@line %\let\latex@addmarginpar\@addmarginpar %\let\latex@warning@no@line\@latex@warning@no@line -%\def\@addmarginpar{^^A +%\def\@addmarginpar{^^A % \let\@latex@warning@no@line\@gobble % \latex@addmarginpar % \let\@latex@warning@no@line\latex@warning@no@line @@ -553,6 +541,8 @@ This work consists of the file siunitx.dtx %\changes{v2.3h}{2011/10/14}{Ensure math mode for exponent products in all % circumstances} %\changes{v2.3h}{2011/10/14}{Improvements to output when using \pkg{tex4ht}} +%\changes{v2.4}{2011/11/03}{Reduce number of math mode options, improving +% consistency of output} % %\begin{abstract} % Physical quantities have both numbers and units, and each physical @@ -633,8 +623,6 @@ This work consists of the file siunitx.dtx % \item \pkg{pgfplots} % \item \pkg{xcolor} %\end{itemize} -% The \pkg{xfrac} package is also loaded if available, but is not -% required to typeset the documentation. % %\section{\pkg{siunitx} for the impatient} % @@ -1769,6 +1757,7 @@ This work consists of the file siunitx.dtx % retain-explicit-plus & Switch & false \\ % retain-unity-mantissa & Switch & true \\ % retain-zero-exponent & Switch & false \\ +% round-half & Choice & up \\ % round-integer-to-decimal & Switch & false \\ % round-minimum & Literal & 0 \\ % round-mode & Choice & off \\ @@ -1839,6 +1828,20 @@ This work consists of the file siunitx.dtx % \num{0.0055} \\ % \num{0.0045} %\end{LaTeXdemo} +% \DescribeOption{round-half} +% \changes{v2.4}{2011/1/04}{New \opt{round-half} option} +% In cases where the rounded part of a number is exactly half, there are +% two common methods for \enquote{breaking the tie}. The choice of method +% is determined by the option \opt{round-half}, which recognises the +% choices \opt{up} and \opt{even}. +%\begin{LaTeXdemo} +% \sisetup{round-mode = places, round-half = up}% +% \num{0.055} \\ +% \num{0.045} \\ +% \sisetup{round-half = even}% +% \num{0.055} \\ +% \num{0.045} +%\end{LaTeXdemo} % %\DescribeOption{add-decimal-zero} %\DescribeOption{add-integer-zero} @@ -1951,28 +1954,28 @@ This work consists of the file siunitx.dtx % Type & % \multicolumn{1}{l}{Default} \\ % \midrule -% bracket-negative-numbers & Switch & false \\ -% bracket-numbers & Switch & true \\ ^^A ( -% close-bracket & Literal & ) \\ -% complex-root-position & Choice & after-number \\ -% copy-complex-root & Choice & false \\ -% copy-decimal-marker & Choice & false \\ -% exponent-base & Literal & 10 \\ -% exponent-product & Math & \cs{times} \\ -% group-digits & Choice & true \\ -% group-minimum-digits & integer & 5 \\ -% group-separator & Math & \cs{,} \\ -% negative-color & Literal & \meta{none} \\ +% bracket-negative-numbers & Switch & false \\ +% bracket-numbers & Switch & true \\ ^^A ( +% close-bracket & Literal & ) \\ +% complex-root-position & Choice & after-number \\ +% copy-complex-root & Choice & false \\ +% copy-decimal-marker & Choice & false \\ +% exponent-base & Literal & 10 \\ +% exponent-product & Math & \cs{times} \\ +% group-digits & Choice & true \\ +% group-minimum-digits & integer & 5 \\ +% group-separator & Literal & \cs{,} \\ +% negative-color & Literal & \meta{none} \\ % open-bracket & Literal & ( % \\ ^^A ) ( -% output-close-uncertainty & Literal & ) \\ -% output-complex-root & Math & \verb=\mathrm{i}= \\ -% output-decimal-marker & Math & . \\ -% output-exponent-marker & Literal & \meta{none} \\ -% output-open-uncertainty & Literal & ( \\ ^^A ) -% separate-uncertainty & Switch & false \\ -% tight-spacing & Switch & false \\ -% uncertainty-separator & Math & \meta{none} \\ +% output-close-uncertainty & Literal & ) \\ +% output-complex-root & Literal & \verb=\ensuremath{\mathrm{i}}= \\ +% output-decimal-marker & Literal & . \\ +% output-exponent-marker & Literal & \meta{none} \\ +% output-open-uncertainty & Literal & ( \\ ^^A ) +% separate-uncertainty & Switch & false \\ +% tight-spacing & Switch & false \\ +% uncertainty-separator & Literal & \meta{none} \\ % \bottomrule % \end{tabular} %\end{table} @@ -1996,7 +1999,7 @@ This work consists of the file siunitx.dtx % \num[group-digits = integer]{12345.67890} %\end{LaTeXdemo} % The separator used between groups of digits is stored by the -% \opt{group-separator} option. This takes literal input and is +% \opt{group-separator} option. This takes literal input and may be % used in math mode: for a text-mode full space use |\text{~}|. %\begin{LaTeXdemo} % \num{12345} \\ @@ -2027,8 +2030,8 @@ This work consists of the file siunitx.dtx % The decimal marker used in output is set using the % \opt{output-decimal-marker} option. This can differ from the input % marker, as can the root of $\sqrt{-1}$, which is stored in the -% \opt{output-complex-root} option. The later is always in math mode, -% but the standard setting uses \cs{mathrm} to give an upright +% \opt{output-complex-root} option. The standard setting uses \cs{mathrm} +% in math mode to give an upright % \enquote{i}: this can easily be altered. The complex root or decimal % marker from the input can be used in the output by setting the % \opt{copy-complex-root} and \opt{copy-decimal-marker} options, @@ -2179,7 +2182,7 @@ This work consists of the file siunitx.dtx % input-product & Literal & x \\ % input-quotient & Literal & / \\ % output-product & Math & \cs{times} \\ -% output-quotient & Math & / \\ +% output-quotient & Literal & / \\ % quotient-mode & Choice & symbol \\ % \bottomrule % \end{tabular} @@ -2222,9 +2225,7 @@ This work consists of the file siunitx.dtx % creates some type of fraction. Most alternatives to the standard % \cs{frac} function will involve loading additional packages: the % demonstrations here need \pkg{amsmath} and -% \pkg{xfrac}.\footnote{If \pkg{xfrac} is not available when typesetting -% this document, the demonstration of \cs{sfrac} will have the wrong -% appearance.} +% \pkg{xfrac}. %\begin{LaTeXdemo} % \sisetup{quotient-mode = fraction} % \num{1 / 1} @@ -2250,20 +2251,25 @@ This work consists of the file siunitx.dtx % \multicolumn{1}{l}{Default} \\ % \midrule % list-final-separator & Literal & \verb*= and = \\ +% list-pair-separator & Literal & \verb*= and = \\ % list-separator & Literal & \verb*=, = \\ % range-phrase & Literal & \verb*= to = \\ % \bottomrule % \end{tabular} %\end{table} % -%\DescribeOption{list-final-separator} -%\DescribeOption{list-separator} +% \DescribeOption{list-final-separator} +% \DescribeOption{list-pair-separator} +% \changes{v2.4}{2011/11/02}{New \opt{list-pair-separator} option} +% \DescribeOption{list-separator} % Lists of numbers are printed with a separator between each item, % which is stored using the \opt{list-separator} option. The % separator before the last item of a list may be different, and -% is therefore set using the \opt{list-final-separator} option. Any +% is therefore set using the \opt{list-final-separator} option. +% The separator used for exactly two items is set using the +% \opt{list-pair-separator} option. Any % spaces needed should be included in the option settings: none are -% added within the code. These two items are printed in text mode. +% added within the code. These items are printed in text mode. %\begin{LaTeXdemo} % \numlist{0.1;0.2;0.3} \\ % \numlist[list-separator = {; }]{0.1;0.2;0.3} \\ @@ -2271,7 +2277,9 @@ This work consists of the file siunitx.dtx % \numlist[ % list-separator = { and }, % list-final-separator = { and finally } -% ]{0.1;0.2;0.3} +% ]{0.1;0.2;0.3} \\ +% \numlist{0.1;0.2} \\ +% \numlist[list-pair-separator = {, and }]{0.1;0.2} %\end{LaTeXdemo} % %\DescribeOption{range-phrase} @@ -2284,6 +2292,22 @@ This work consists of the file siunitx.dtx % \numrange[range-phrase = --]{5}{100} %\end{LaTeXdemo} % +% \changes{v2.4}{2011/11/04}{Automatically compress exponents for lists and +% ranges when fixed exponents are active} +% For lists and ranges when a single unit is given, \pkg{siunitx} will +% automatically \enquote{compress} exponents when a fixed exponent is in +% use. +%\begin{LaTeXdemo} +% \sisetup{ +% fixed-exponent = 3 , +% list-units = brackets , +% range-units = brackets , +% scientific-notation = fixed +% }% +% \SIrange{1e3}{7e3}{\metre} \\ +% \SIlist{1e3;2e3;3e3}{\kg} +%\end{LaTeXdemo} +% %\subsection{Angles} % % Angle processing provided by the \cs{ang} function has a set of @@ -2300,12 +2324,12 @@ This work consists of the file siunitx.dtx % Type & % \multicolumn{1}{l}{Default} \\ % \midrule -% add-arc-degree-zero & Switch & false \\ -% add-arc-minute-zero & Switch & false \\ -% add-arc-second-zero & Switch & false \\ -% angle-symbol-over-decimal & Switch & false \\ -% arc-separator & Math & false \\ -% number-angle-product & Math & \meta{empty} \\ +% add-arc-degree-zero & Switch & false \\ +% add-arc-minute-zero & Switch & false \\ +% add-arc-second-zero & Switch & false \\ +% angle-symbol-over-decimal & Switch & false \\ +% arc-separator & Literal & false \\ +% number-angle-product & Math & \meta{empty} \\ % \bottomrule % \end{tabular} %\end{table} @@ -2717,17 +2741,17 @@ This work consists of the file siunitx.dtx % Type & % \multicolumn{1}{l}{Default} \\ % \midrule -% bracket-unit-denominator & Switch & true \\ -% forbid-literal-units & Switch & false \\ -% literal-superscript-as-power & Switch & true \\ -% inter-unit-product & Math & \cs{,} \\ -% parse-units & Switch & true \\ -% per-mode & Choice & reciprocal \\ -% per-symbol & Math & / \\ -% power-font & Choice & number \\ -% prefixes-as-symbols & Switch & true \\ -% qualifier-mode & Choice & subscript \\ -% sticky-per & Switch & false \\ +% bracket-unit-denominator & Switch & true \\ +% forbid-literal-units & Switch & false \\ +% literal-superscript-as-power & Switch & true \\ +% inter-unit-product & Math & \cs{,} \\ +% parse-units & Switch & true \\ +% per-mode & Choice & reciprocal \\ +% per-symbol & Literal & / \\ +% power-font & Choice & number \\ +% prefixes-as-symbols & Switch & true \\ +% qualifier-mode & Choice & subscript \\ +% sticky-per & Switch & false \\ % \bottomrule % \end{tabular} %\end{table} @@ -2782,8 +2806,6 @@ This work consists of the file siunitx.dtx % unless \opt{bracket-unit-denominator} is set to \opt{false}. % Notice that \opt{bracket-unit-denominator} only applies when % \opt{per-mode} is set to \opt{symbol} or \opt{symbol-or-fraction}. -% The output for \opt{per-symbol} is always made in math mode, and so -% \cs{text} will be needed to print textual information. %\begin{LaTeXdemo} % \sisetup{per-mode = symbol}% % \si{\joule\per\mole\per\kelvin} \\ @@ -2916,6 +2938,7 @@ This work consists of the file siunitx.dtx % \multicolumn{1}{l}{Default} \\ % \midrule ^^A ( % allow-number-unit-breaks & Switch & false \\ +% exponent-to-prefix & Switch & false \\ % list-units & Choice & repeat \\ % multi-part-units & Choice & brackets \\ % number-unit-product & Math & \cs{,} \\ @@ -3020,6 +3043,24 @@ This work consists of the file siunitx.dtx % \SIrange[range-units = single]{2}{4}{\degreeCelsius} %\end{LaTeXdemo} % +% \DescribeOption{exponent-to-prefix} +% \changes{v2.4}{2011/11/06}{New \opt{exponent-to-prefix} option} +% When the \opt{exponent-to-prefix} option is set \opt{true}, the package +% will attempt to convert any exponents in quantities into unit prefixes, +% and will attach these to the first unit given. This process is only +% possible if the exponent is one for which a prefix is available, and +% retains the number of significant figures in the input. +%\begin{LaTeXdemo} +% \SI{1700}{\g} \\ +% \SI{1.7e3}{\g} \\ +% \sisetup{exponent-to-prefix}% +% \SI{1700}{\g} \\ +% \SI{1.7e3}{\g} \\ +% \sisetup{fixed-exponent = 3, scientific-notation = fixed}% +% \SI{1700}{\g} \\ +% \SI{1.7e3}{\g} +%\end{LaTeXdemo} +% %\subsection{Tabular material} % % Processing of material in tables obeys the same settings as described @@ -4005,6 +4046,42 @@ This work consists of the file siunitx.dtx % } %\end{LaTeXdemo} % +% \subsection{A left-aligned column visually centred under a heading} +% +% When you have a column of non-related numbers, the usual advice is to +% make these left-aligned and then centre the resulting column under the +% heading. With the \pkg{dcolumn} package, that would be done with +% something like |D{x}{}{5.0}|. This is something of an abuse of the +% nature of a number, but can also be done using \pkg{siunitx} +% (\ref{tbl:xmpl:unrel}). +%\begin{LaTeXdemo}[code and float] +% \begin{table} +% \caption{Formatting unrelated numbers} +% \label{tbl:xmpl:unrel} +% \centering +% \begin{tabular} +% { +% S[ +% table-format = 5.0, +% parse-numbers = false, +% input-symbols=., +% input-decimal-markers = x +% ] +% } +% \toprule +% \multicolumn{1}{c}{Header} \\ +% \midrule +% 120 \\ +% 12.3 \\ +% 12340 \\ +% 12.02 \\ +% 123 \\ +% 1 \\ +% \bottomrule +% \end{tabular} +% \end{table} +%\end{LaTeXdemo} +% %\subsection{Symbols and \texorpdfstring{\XeTeX}{XeTeX}} % % A small number of non-Latin symbols are needed by \pkg{siunitx}, @@ -4552,6 +4629,14 @@ This work consists of the file siunitx.dtx % as this manual, where the text and math mode numerals are (deliberately) % different. To restore the previous behaviour, set % \opt{literal-superscript-as-power = false}. +% +% \subsection{Upgrading from version 2.3} +% +% The number of options which assume that the input is given in math mode +% has been significantly reduced. As most material can be typeset in either +% math or text mode, the \enquote{intrinsic} math mode options could lead to +% inconsistent output. The only options which now force math mode are those +% for products, which will almost always require the use of math mode. % %\section{Correct application of (SI) units} % @@ -4902,39 +4987,25 @@ This work consists of the file siunitx.dtx % % The usual preliminaries. % \begin{macrocode} -\ProvidesExplPackage {siunitx} {2011/10/14} {2.3h} +\ProvidesExplPackage {siunitx} {2011/11/14} {2.4} {A comprehensive (SI) units package} % \end{macrocode} % -% Various problems pop up if the support files are too old. First, -% a check on \pkg{expl3}. There is also a check on \pkg{xparse}, but -% that comes a bit later. If the version of \pkg{expl3} is \emph{really} -% old then the message system may not be in place at all: there is a -% back up for that case. +% Make sure that the version of \pkg{l3kernel} in use is sufficiently new. +% This will also trap any problems with \pkg{l3packages} (as the two are now +% tied together, version-wise). % \begin{macrocode} -\cs_if_exist:NTF \msg_new:nnnn - { - \msg_new:nnnn { siunitx } { support-outdated } - { Support~package~#1~too~old. } - { - Please~install~an~up~to~date~version~of~#1. \\ - Loading~siunitx~will~abort! - } - } +\@ifpackagelater { expl3 } { 2011/09/05 } + { } { \PackageError { siunitx } { Support~package~expl3~too~old. } { - Please~install~an~up~to~date~version~of~expl3. \\ + You~need~to~update~your~installation~of~the~bundles~'l3kernel'~and~ + 'l3packages'.\\ Loading~siunitx~will~abort! } \tex_endinput:D } -\@ifpackagelater { expl3 } { 2011/09/05 } - { } - { - \msg_error:nnx { siunitx } { support-outdated } { expl3 } - \tex_endinput:D - } % \end{macrocode} % %\begin{macro}{\siunitx_load_check:} @@ -4948,7 +5019,7 @@ This work consists of the file siunitx.dtx \msg_new:nnnn { siunitx } { incompatible-package } { Package~'#1'~incompatible. } { The~#1~package~and~siunitx~are~incompatible. } -\cs_new_protected_nopar:Npn \siunitx_load_check:n #1 { +\cs_new_protected:Npn \siunitx_load_check:n #1 { \group_begin: \@ifpackageloaded {#1} { \msg_error:nnx { siunitx } { incompatible-package } {#1} } @@ -4977,6 +5048,12 @@ This work consists of the file siunitx.dtx % \end{macrocode} %\end{macro} % +% \begin{macro}{\clist_map_function:nc} +% \begin{macrocode} +\cs_generate_variant:Nn \clist_map_function:nN { nc } +% \end{macrocode} +% \end{macro} +% %\begin{macro}{ % \l_siunitx_tmp_bool , % \l_siunitx_tmp_box , @@ -5087,34 +5164,29 @@ This work consists of the file siunitx.dtx % \end{macrocode} %\end{macro} % -%\begin{macro}{ -% \siunitx_tl_put_left_math:Nn , -% \siunitx_tl_put_left_math:NV , -% \siunitx_tl_put_left_math:cV , -% \siunitx_tl_put_right_math:Nn , -% \siunitx_tl_put_right_math:NV , -% \siunitx_tl_put_right_math:cV -%} -% To add stuff in math mode. +% \begin{macro} +% { +% \siunitx_tl_put_left_math:Nn , +% \siunitx_tl_put_left_math:NV , +% \siunitx_tl_put_right_math:Nn , +% \siunitx_tl_put_right_math:NV , +% } +% To add stuff in math mode. % \begin{macrocode} -\cs_new_protected:Npn \siunitx_tl_put_left_math:Nn #1#2 { - \tl_put_left:Nn #1 { \siunitx_ensuremath:n {#2} } -} +\cs_new_protected:Npn \siunitx_tl_put_left_math:Nn #1#2 + { \tl_put_left:Nn #1 { \ensuremath {#2} } } \cs_generate_variant:Nn \siunitx_tl_put_left_math:Nn { NV } -\cs_generate_variant:Nn \siunitx_tl_put_left_math:Nn { cV } -\cs_new_protected:Npn \siunitx_tl_put_right_math:Nn #1#2 { - \tl_put_right:Nn #1 { \siunitx_ensuremath:n {#2} } -} +\cs_new_protected:Npn \siunitx_tl_put_right_math:Nn #1#2 + { \tl_put_right:Nn #1 { \ensuremath {#2} } } \cs_generate_variant:Nn \siunitx_tl_put_right_math:Nn { NV } -\cs_generate_variant:Nn \siunitx_tl_put_right_math:Nn { cV } % \end{macrocode} -%\end{macro} +% \end{macro} % %\begin{macro}{\c_siunitx_old_options_seq} % To pick up old options, all of the names need to be known. % \begin{macrocode} \seq_new:N \c_siunitx_old_options_seq -\cs_set_protected_nopar:Npn \siunitx_tmp:w #1 { +\cs_set_protected:Npn \siunitx_tmp:w #1 { \seq_put_right:No \c_siunitx_old_options_seq { \tl_to_str:n {#1} } } \siunitx_tmp:w { addsign } @@ -5314,10 +5386,10 @@ This work consists of the file siunitx.dtx %\begin{macro}{\l_siunitx_option_deactivate_clist} % Some options need to be deactivated at the start of the document. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_option_deactivate:n #1 { +\cs_new_protected:Npn \siunitx_option_deactivate:n #1 { \clist_put_right:Nn \l_siunitx_option_deactivate_clist {#1} } -\cs_new_protected_nopar:Npn \siunitx_option_deactivate_aux:n #1 { +\cs_new_protected:Npn \siunitx_option_deactivate_aux:n #1 { \keys_define:nn { siunitx } { #1 .code:n = @@ -5369,7 +5441,7 @@ This work consists of the file siunitx.dtx } { \prg_return_false: } } - \cs_new_nopar:Npn \siunitx_cs_if_tl_aux:w #1 MACRO #2 \q_stop + \cs_new:Npn \siunitx_cs_if_tl_aux:w #1 MACRO #2 \q_stop { \tl_if_empty:nTF {#1} } \prg_new_conditional:Npnn \siunitx_cs_if_macro:N #1 { T , F , TF , p } @@ -5384,23 +5456,19 @@ This work consists of the file siunitx.dtx %\end{macro} %\end{macro} % -%\begin{macro}{\siunitx_ensuremath:n} -% A copy is made of \cs{ensuremath}: if \pkg{tex4ht} is in use, it -% is possible to deactivate this to give nicer looking conversion to -% other formats. +% If \pkg{tex4ht} is in use, make a few changes to give nicer looking +% conversion to other formats. % \begin{macrocode} -\cs_new_eq:NN \siunitx_ensuremath:n \ensuremath -\AtBeginDocument { - \@ifpackageloaded { tex4ht } - { - \cs_set_eq:NN \siunitx_ensuremath:n \use:n - \cs_set_eq:NN \siunitx_print_text_super:n \textsuperscript - \keys_set:nn { siunitx } { qualifier-mode = brackets, mode = text } - } - { } -} +\AtBeginDocument + { + \@ifpackageloaded { tex4ht } + { + \cs_set_eq:NN \siunitx_print_text_super:n \textsuperscript + \keys_set:nn { siunitx } { qualifier-mode = brackets, mode = text } + } + { } + } % \end{macrocode} -%\end{macro} % % \begin{macro}{\siunitx_textsuperscript:n} % This function is set up here so that it can be redefined @@ -5453,7 +5521,7 @@ This work consists of the file siunitx.dtx % using \cs{AtBeginDocument} as it has to come after anything that % \pkg{fontspec} does (nasty errors arise otherwise). % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_set_math_fam:n #1 { +\cs_new_protected:Npn \siunitx_set_math_fam:n #1 { \int_new:c { c_siunitx_math #1 _int } \group_begin: \hbox_set:Nn \l_siunitx_tmp_box @@ -5486,7 +5554,7 @@ This work consists of the file siunitx.dtx % new macros here arises as \cs{sfdefault} and \cs{ttdefault} are % \cs{long}, whereas \cs{f@family} is not. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_set_text_fam:n #1 { +\cs_new_protected:Npn \siunitx_set_text_fam:n #1 { \tl_new:c { c_siunitx_text #1 _tl } \tl_set:cx { c_siunitx_text #1 _tl } { \use:c { #1 default } } } @@ -5612,8 +5680,8 @@ This work consists of the file siunitx.dtx %} % These could be token lists or functions! % \begin{macrocode} -\cs_new_nopar:Npn \siunitx_font_shape: { } -\cs_new_nopar:Npn \siunitx_font_weight: { } +\cs_new:Npn \siunitx_font_shape: { } +\cs_new:Npn \siunitx_font_weight: { } % \end{macrocode} %\end{macro} % @@ -5622,7 +5690,7 @@ This work consists of the file siunitx.dtx % functions. Nesting font-control should not happen, so the first % test is to ensure this is not happening. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_detect_font: { +\cs_new_protected:Npn \siunitx_detect_font: { \bool_if:NF \l_siunitx_font_set_bool { \siunitx_detect_font_init: @@ -5642,7 +5710,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_detect_font_init:} % Set up the basic macros on the assumption nothing happens. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_detect_font_init: { +\cs_new_protected:Npn \siunitx_detect_font_init: { \bool_set_true:N \l_siunitx_font_set_bool \cs_set:Npn \siunitx_font_weight: { @@ -5661,7 +5729,7 @@ This work consists of the file siunitx.dtx % math or text, and also the type of math (if appropriate). For % inline math, there is a choice of what test to apply. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_detect_font_weight: { +\cs_new_protected:Npn \siunitx_detect_font_weight: { \mode_if_math:TF { \bool_if:NTF \l_siunitx_display_math_bool @@ -5690,7 +5758,7 @@ This work consists of the file siunitx.dtx % The tests for font weight depend on whether the module is testing % text or math content. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_detect_font_weight_math: { +\cs_new_protected:Npn \siunitx_detect_font_weight_math: { \str_if_eq:VnT \math@version { bold } { \cs_set:Npn \siunitx_font_weight: @@ -5702,7 +5770,7 @@ This work consists of the file siunitx.dtx \str_if_eq:VnT \math@version { light } { \cs_set:Npn \siunitx_font_weight: { \lseries } } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_weight_text: { +\cs_new_protected:Npn \siunitx_detect_font_weight_text: { \tl_set:Nx \l_siunitx_tmpa_tl { \tl_head:V \f@series } \str_if_eq:VnT \l_siunitx_tmpa_tl { b } { @@ -5722,7 +5790,7 @@ This work consists of the file siunitx.dtx % Family detection usually picks up the surrounding text. However, for % display math there are two options, and so a second test may be made. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_detect_font_family: { +\cs_new_protected:Npn \siunitx_detect_font_family: { \mode_if_math:TF { \bool_if:NTF \l_siunitx_display_math_bool @@ -5754,14 +5822,14 @@ This work consists of the file siunitx.dtx % default (\texttt{rm}), as the text function is always called and may % have changed things. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_detect_font_family_math: { +\cs_new_protected:Npn \siunitx_detect_font_family_math: { \tl_set:Nn \l_siunitx_font_family_tl { rm } \int_compare:nNnT { \fam } = { \c_siunitx_mathsf_int } { \tl_set:Nn \l_siunitx_font_family_tl { sf } } \int_compare:nNnT { \fam } = { \c_siunitx_mathtt_int } { \tl_set:Nn \l_siunitx_font_family_tl { tt } } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_family_text: { +\cs_new_protected:Npn \siunitx_detect_font_family_text: { \tl_if_eq:NNT \f@family \c_siunitx_textsf_tl { \tl_set:Nn \l_siunitx_font_family_tl { sf } } \tl_if_eq:NNT \f@family \c_siunitx_texttt_tl @@ -5773,11 +5841,11 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_detect_font_shape:} % The shape test uses \cs{f@shape} as a handy indicator. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_detect_font_shape: { +\cs_new_protected:Npn \siunitx_detect_font_shape: { \str_if_eq:VnT \f@shape { it } - { \cs_set_nopar:Npn \siunitx_font_shape: { \itshape } } + { \cs_set:Npn \siunitx_font_shape: { \itshape } } \str_if_eq:VnT \f@shape { sl } - { \cs_set_nopar:Npn \siunitx_font_shape: { \slshape } } + { \cs_set:Npn \siunitx_font_shape: { \slshape } } } % \end{macrocode} %\end{macro} @@ -5786,7 +5854,7 @@ This work consists of the file siunitx.dtx % The mode switch works from the fact that math mode output it the % standard. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_detect_font_mode: { +\cs_new_protected:Npn \siunitx_detect_font_mode: { \mode_if_math:F { \bool_set_false:N \l_siunitx_font_math_mode_bool @@ -5829,9 +5897,9 @@ This work consists of the file siunitx.dtx \cs_new:Npn \siunitx_number_mathrm:n #1 { } \cs_new:Npn \siunitx_number_mathsf:n #1 { } \cs_new:Npn \siunitx_number_mathtt:n #1 { } -\cs_new_nopar:Npn \siunitx_number_textrm: { } -\cs_new_nopar:Npn \siunitx_number_textsf: { } -\cs_new_nopar:Npn \siunitx_number_texttt: { } +\cs_new:Npn \siunitx_number_textrm: { } +\cs_new:Npn \siunitx_number_textsf: { } +\cs_new:Npn \siunitx_number_texttt: { } % \end{macrocode} %\end{macro} % @@ -5842,22 +5910,22 @@ This work consists of the file siunitx.dtx \keys_define:nn { siunitx } { number-color .tl_set:N = \l_siunitx_number_color_tl, number-math-rm .code:n = - { \cs_set_nopar:Npn \siunitx_number_mathrm:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_number_mathrm:n ##1 { #1 {##1} } }, number-math-sf .code:n = - { \cs_set_nopar:Npn \siunitx_number_mathsf:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_number_mathsf:n ##1 { #1 {##1} } }, number-math-tt .code:n = - { \cs_set_nopar:Npn \siunitx_number_mathtt:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_number_mathtt:n ##1 { #1 {##1} } }, number-mode .choice:, number-mode / math .code:n = { \bool_set_true:N \l_siunitx_number_math_mode_bool }, number-mode / text .code:n = { \bool_set_false:N \l_siunitx_number_math_mode_bool }, number-text-rm .code:n = - { \cs_set_nopar:Npn \siunitx_number_textrm: {#1} }, + { \cs_set:Npn \siunitx_number_textrm: {#1} }, number-text-sf .code:n = - { \cs_set_nopar:Npn \siunitx_number_textsf: {#1} }, + { \cs_set:Npn \siunitx_number_textsf: {#1} }, number-text-tt .code:n = - { \cs_set_nopar:Npn \siunitx_number_texttt: {#1} } + { \cs_set:Npn \siunitx_number_texttt: {#1} } } % \end{macrocode} %\end{macro} @@ -5872,12 +5940,12 @@ This work consists of the file siunitx.dtx %} % The same storage for unit-mode fonts. % \begin{macrocode} -\cs_new_nopar:Npn \siunitx_unit_mathrm: { } -\cs_new_nopar:Npn \siunitx_unit_mathsf: { } -\cs_new_nopar:Npn \siunitx_unit_mathtt: { } -\cs_new_nopar:Npn \siunitx_unit_textrm: { } -\cs_new_nopar:Npn \siunitx_unit_textsf: { } -\cs_new_nopar:Npn \siunitx_unit_texttt: { } +\cs_new:Npn \siunitx_unit_mathrm: { } +\cs_new:Npn \siunitx_unit_mathsf: { } +\cs_new:Npn \siunitx_unit_mathtt: { } +\cs_new:Npn \siunitx_unit_textrm: { } +\cs_new:Npn \siunitx_unit_textsf: { } +\cs_new:Npn \siunitx_unit_texttt: { } % \end{macrocode} %\end{macro} % @@ -5887,22 +5955,22 @@ This work consists of the file siunitx.dtx \keys_define:nn { siunitx } { unit-color .tl_set:N = \l_siunitx_unit_color_tl, unit-math-rm .code:n = - { \cs_set_nopar:Npn \siunitx_unit_mathrm:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_unit_mathrm:n ##1 { #1 {##1} } }, unit-math-sf .code:n = - { \cs_set_nopar:Npn \siunitx_unit_mathsf:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_unit_mathsf:n ##1 { #1 {##1} } }, unit-math-tt .code:n = - { \cs_set_nopar:Npn \siunitx_unit_mathtt:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_unit_mathtt:n ##1 { #1 {##1} } }, unit-mode .choice:, unit-mode / math .code:n = { \bool_set_true:N \l_siunitx_unit_math_mode_bool }, unit-mode / text .code:n = { \bool_set_false:N \l_siunitx_unit_math_mode_bool }, unit-text-rm .code:n = - { \cs_set_nopar:Npn \siunitx_unit_textrm: {#1} }, + { \cs_set:Npn \siunitx_unit_textrm: {#1} }, unit-text-sf .code:n = - { \cs_set_nopar:Npn \siunitx_unit_textsf: {#1} }, + { \cs_set:Npn \siunitx_unit_textsf: {#1} }, unit-text-tt .code:n = - { \cs_set_nopar:Npn \siunitx_unit_texttt: {#1} } + { \cs_set:Npn \siunitx_unit_texttt: {#1} } } % \end{macrocode} %\end{macro} @@ -6051,7 +6119,7 @@ This work consists of the file siunitx.dtx % function is called. Everything is inside \cs{text} as this allows % proper setting of the various mode settings. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_print_aux: { +\cs_new_protected:Npn \siunitx_print_aux: { \text { \siunitx_print_color: @@ -6079,7 +6147,7 @@ This work consists of the file siunitx.dtx % anything if it is. This will change when \LaTeX3 proper is available: % there will be colour out of the box! % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_print_color: { +\cs_new_protected:Npn \siunitx_print_color: { \tl_if_empty:cF { l_siunitx_ \l_siunitx_print_type_tl _color_tl } { \color @@ -6117,7 +6185,7 @@ This work consists of the file siunitx.dtx \char_set_catcode_active:N \! \tl_to_lowercase:n { \group_end: - \cs_set_protected_nopar:Npn \siunitx_print_math: + \cs_set_protected:Npn \siunitx_print_math: { \cs_set_eq:NN \PrintSubscript @ \cs_set_eq:NN \PrintSuperscript ^ @@ -6131,8 +6199,10 @@ This work consists of the file siunitx.dtx { \l_siunitx_print_arg_tl } } } - \cs_set_protected_nopar:Npn \siunitx_print_text: + \cs_set_protected:Npn \siunitx_print_text: { + \tl_replace_all:Nnn \l_siunitx_print_arg_tl { - } + { \c_siunitx_minus_tl } \cs_set_eq:NN \PrintSubscript \siunitx_print_text_sub:n \cs_set_eq:NN \PrintSuperscript \siunitx_print_text_super:n \tl_replace_all:Nnn \l_siunitx_print_arg_tl { @ } @@ -6176,13 +6246,13 @@ This work consists of the file siunitx.dtx } } \cs_set_eq:NN \l_peek_search_token \siunitx_print_text_super:n - \cs_set_nopar:Npn \peek_true:w + \cs_set:Npn \peek_true:w { \tex_afterassignment:D \peek_true_aux:w \cs_set_eq:NN \peek_tmp:w } - \cs_set_nopar:Npn \peek_true_aux:w { \siunitx_print_text_sub_super:n } - \cs_set_nopar:Npn \peek_false:w { \ensuremath { @ { \text {#1} } } } + \cs_set:Npn \peek_true_aux:w { \siunitx_print_text_sub_super:n } + \cs_set:Npn \peek_false:w { \ensuremath { @ { \text {#1} } } } \peek_after:Nw \peek_execute_branches_meaning: } } @@ -6289,7 +6359,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_number_preprocess_init:} % A little initialisation as normal. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_preprocess_init: { +\cs_new_protected:Npn \siunitx_number_preprocess_init: { \bool_set_false:N \l_siunitx_error_bool \tl_clear:N \l_siunitx_number_multi_tl } @@ -6301,7 +6371,7 @@ This work consists of the file siunitx.dtx % Rather than search through the entire argument, we use the % delimited-argument trick. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_preprocess_product: { +\cs_new_protected:Npn \siunitx_number_preprocess_product: { \tl_map_function:NN \l_siunitx_input_product_tl \siunitx_number_preprocess_product_aux:N } @@ -6331,7 +6401,7 @@ This work consists of the file siunitx.dtx % For the quotient, only one token can appear in each part. So there % is an additional error check. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_preprocess_quotient: { +\cs_new_protected:Npn \siunitx_number_preprocess_quotient: { \tl_map_function:NN \l_siunitx_input_quotient_tl \siunitx_number_preprocess_quotient_aux:N } @@ -6581,7 +6651,7 @@ This work consists of the file siunitx.dtx % carried out at the start of each part of a number, and so is called % from a few places. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_in_init: { +\cs_new_protected:Npn \siunitx_number_in_init: { \cs_set_eq:NN \siunitx_number_in_parse_loop:N \siunitx_number_in_parse_mantissa:N \cs_set_eq:NN \siunitx_number_in_check:n @@ -6595,7 +6665,7 @@ This work consists of the file siunitx.dtx \bool_set_false:N \l_siunitx_number_in_uncert_bool \siunitx_number_in_init_part:n { mantissa } } -\cs_new_protected_nopar:Npn \siunitx_number_in_init_part:n #1 { +\cs_new_protected:Npn \siunitx_number_in_init_part:n #1 { \bool_set_false:N \l_siunitx_number_in_decimal_bool \bool_set_true:N \l_siunitx_number_in_first_bool \bool_set_false:N \l_siunitx_number_in_sign_bool @@ -6617,7 +6687,7 @@ This work consists of the file siunitx.dtx % some tokens do not behave safely under \texttt{x} expansion (at the % moment). To get round this, they are redefined here. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_in_protect: { +\cs_new_protected:Npn \siunitx_number_in_protect: { \tl_map_function:NN \l_siunitx_input_protect_tl \siunitx_number_in_protect_aux:N } @@ -6631,7 +6701,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_number_in_sign_replace:N} % A short spin-out to keep the replacement of tokens clear. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_in_sign_replace:N #1 { +\cs_new_protected:Npn \siunitx_number_in_sign_replace:N #1 { \tl_replace_all:Nnn #1 { -+ } { \mp } \tl_replace_all:Nnn #1 { +- } { \pm } \tl_replace_all:Nnn #1 { << } { \ll } @@ -7008,7 +7078,7 @@ This work consists of the file siunitx.dtx { \prop_del:Nn \l_siunitx_number_in_prop { mantissa } } } } -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_aux:nn #1#2 { +\cs_new_protected:Npn \siunitx_number_in_complex_aux:nn #1#2 { \prop_get:NnNT \l_siunitx_number_in_prop {#1} \l_siunitx_tmpa_tl { \prop_del:Nn \l_siunitx_number_in_prop {#1} @@ -7200,7 +7270,7 @@ This work consists of the file siunitx.dtx % A short auxiliary function needed in various places for storing % either the integer or decimal part of a number, as appropriate. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_in_store: { +\cs_new_protected:Npn \siunitx_number_in_store: { \prop_put:NVn \l_siunitx_number_in_prop \l_siunitx_number_part_tl { true } \bool_if:NTF \l_siunitx_number_in_decimal_bool @@ -7228,8 +7298,8 @@ This work consists of the file siunitx.dtx % has any sign deleted. For complex numbers, the check is needed in % case there was no real part. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_in_check:n #1 { } -\cs_new_protected_nopar:Npn \siunitx_number_in_check_short:n #1 { +\cs_new_protected:Npn \siunitx_number_in_check:n #1 { } +\cs_new_protected:Npn \siunitx_number_in_check_short:n #1 { \prop_if_in:NVF \l_siunitx_number_in_prop \l_siunitx_number_part_integer_tl { @@ -7255,7 +7325,7 @@ This work consists of the file siunitx.dtx } } } -\cs_new_protected_nopar:Npn \siunitx_number_in_check_full:n #1 { +\cs_new_protected:Npn \siunitx_number_in_check_full:n #1 { \tl_if_eq:NNF \l_siunitx_number_part_tl \c_siunitx_number_part_complex_tl { \siunitx_number_in_check_short:n {#1} } @@ -7303,7 +7373,7 @@ This work consists of the file siunitx.dtx % wrong. The method needed depends on whether there is an integer % part. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_to_uncert:n #1 { +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert:n #1 { \prop_del:Nn \l_siunitx_number_in_prop { complex } \prop_del:Nn \l_siunitx_number_in_prop { complex-decimal-marker } \prop_del:Nn \l_siunitx_number_in_prop { complex-sign } @@ -7329,7 +7399,7 @@ This work consists of the file siunitx.dtx % conversion is easy as all of the decimal part can be copied % across. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_to_uncert_int: { +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert_int: { \prop_get:NnNF \l_siunitx_number_in_prop { complex-decimal } \l_siunitx_tmpa_tl { \tl_clear:N \l_siunitx_tmpa_tl } @@ -7343,7 +7413,7 @@ This work consists of the file siunitx.dtx % only the significant digits are needed. This means that a loop is % needed to drop non-significant ones. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_to_uncert_dec:n +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert_dec:n #1 { \tl_clear:N \l_siunitx_number_uncert_tl @@ -7362,7 +7432,7 @@ This work consists of the file siunitx.dtx { \siunitx_error:nx { misplaced-sign-token } { \exp_not:n {#1} } } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert_dec_loop:N #1 { \str_if_eq:nnTF {#1} { 0 } @@ -7384,7 +7454,7 @@ This work consists of the file siunitx.dtx % also re-obtains the decimal part from the mantissa, as the stored % value may have been trimmed to drop non-significant zeros. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_to_uncert_pad: +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert_pad: { \int_set:Nn \l_siunitx_number_uncert_length_int { \tl_length:N \l_siunitx_tmpa_tl } @@ -7447,26 +7517,33 @@ This work consists of the file siunitx.dtx % for \enquote{formatting}: this is left for the output part of the % system. % -%\begin{macro}{ -% \l_siunitx_round_int , -% \l_siunitx_round_tl , -% \l_siunitx_round_bool , -% \l_siunitx_round_decimal_in_tl , -% \l_siunitx_round_decimal_out_tl , -% \l_siunitx_round_integer_in_tl , -% \l_siunitx_round_integer_out_tl -%} -% The rounding system needs a number of variables. +% \begin{variable} +% { +% \l_siunitx_round_int , +% \l_siunitx_round_tl , +% \l_siunitx_round_bool , +% \l_siunitx_round_decimal_in_tl , +% \l_siunitx_round_decimal_out_tl , +% \l_siunitx_round_discard_tl , +% \l_siunitx_round_even_bool , +% \l_siunitx_round_integer_in_tl , +% \l_siunitx_round_integer_out_tl , +% \l_siunitx_round_half_up_bool +% } +% The rounding system needs a number of variables. % \begin{macrocode} \int_new:N \l_siunitx_round_int \tl_new:N \l_siunitx_round_tl \bool_new:N \l_siunitx_round_bool \tl_new:N \l_siunitx_round_decimal_in_tl \tl_new:N \l_siunitx_round_decimal_out_tl +\tl_new:N \l_siunitx_round_discard_tl +\tl_new:N \l_siunitx_round_even_bool \tl_new:N \l_siunitx_round_integer_in_tl \tl_new:N \l_siunitx_round_integer_out_tl +\bool_new:N \l_siunitx_round_half_up_bool % \end{macrocode} -%\end{macro} +% \end{variable} % %\begin{macro}{ % \l_siunitx_process_decimal_int , @@ -7497,114 +7574,141 @@ This work consists of the file siunitx.dtx % \end{macrocode} %\end{macro} % -%\begin{macro}{ -% \l_siunitx_process_decimal_zero_bool , -% \l_siunitx_process_integer_zero_bool , -% \l_siunitx_process_sign_tl , -% \l_siunitx_process_sign_tl , -% \l_siunitx_process_fixed_int , -% \l_siunitx_process_integer_min_int , -% \l_siunitx_process_plus_tl , -% \l_siunitx_process_unity_mantissa_tl , -% \l_siunitx_process_zero_exponent_bool , -% \l_siunitx_process_int_to_dec_bool , -% \l_siunitx_process_round_min_tl , -% \l_siunitx_process_precision_int -%} +% \begin{variable}{\l_siunitx_process_drop_exponent_bool} +% Used to drop the exponent when this is necessary. +% \begin{macrocode} +\bool_new:N \l_siunitx_process_drop_exponent_bool +% \end{macrocode} +% \end{variable} +% +% \begin{variable} +% { +% \l_siunitx_process_decimal_zero_bool , +% \l_siunitx_process_integer_zero_bool , +% \l_siunitx_process_sign_tl , +% \l_siunitx_process_sign_tl , +% \l_siunitx_process_fixed_int , +% \l_siunitx_process_integer_min_int , +% \l_siunitx_process_plus_tl , +% \l_siunitx_process_unity_mantissa_tl , +% \l_siunitx_process_zero_exponent_bool , +% \l_siunitx_process_int_to_dec_bool , +% \l_siunitx_process_round_min_tl , +% \l_siunitx_process_precision_int +% } % First, the options are set up. % \begin{macrocode} -\keys_define:nn { siunitx } { - add-decimal-zero .bool_set:N = \l_siunitx_process_decimal_zero_bool, - add-integer-zero .bool_set:N = \l_siunitx_process_integer_zero_bool, - explicit-sign .tl_set:N = \l_siunitx_process_sign_tl, - fixed-exponent .int_set:N = \l_siunitx_process_fixed_int, - minimum-integer-digits .int_set:N = - \l_siunitx_process_integer_min_int, - retain-explicit-plus .bool_set:N = \l_siunitx_process_plus_tl, - retain-unity-mantissa .bool_set:N = - \l_siunitx_process_unity_mantissa_bool, - retain-zero-exponent .bool_set:N = - \l_siunitx_process_zero_exponent_bool, - round-integer-to-decimal .bool_set:N = - \l_siunitx_process_int_to_dec_bool, - round-minimum .tl_set:N = \l_siunitx_process_round_min_tl, - round-mode .choice: , - round-mode / figures .code:n = - { \tl_set:Nn \l_siunitx_round_tl { figures } }, - round-mode / off .code:n = { \tl_clear:N \l_siunitx_round_tl }, - round-mode / places .code:n = - { \tl_set:Nn \l_siunitx_round_tl { places } }, - round-precision .int_set:N = \l_siunitx_process_precision_int, - scientific-notation .choice: , - scientific-notation - / false .code:n = - { - \bool_set_false:N \l_siunitx_process_fixed_bool - \bool_set_false:N \l_siunitx_process_engineering_bool - \bool_set_false:N \l_siunitx_process_scientific_bool - }, - scientific-notation - / engineering .code:n = - { - \bool_set_false:N \l_siunitx_process_fixed_bool - \bool_set_true:N \l_siunitx_process_engineering_bool - \bool_set_true:N \l_siunitx_process_scientific_bool - }, - scientific-notation - / fixed .code:n = - { - \bool_set_true:N \l_siunitx_process_fixed_bool - \bool_set_false:N \l_siunitx_process_engineering_bool - \bool_set_false:N \l_siunitx_process_scientific_bool - }, - scientific-notation - / true .code:n = - { - \bool_set_false:N \l_siunitx_process_fixed_bool - \bool_set_false:N \l_siunitx_process_engineering_bool - \bool_set_true:N \l_siunitx_process_scientific_bool - }, -} -\keys_set:nn { siunitx } { - add-decimal-zero = true, - add-integer-zero = true, - retain-unity-mantissa = true, - round-precision = 2, -} +\keys_define:nn { siunitx } + { + add-decimal-zero .bool_set:N = \l_siunitx_process_decimal_zero_bool, + add-integer-zero .bool_set:N = \l_siunitx_process_integer_zero_bool, + explicit-sign .tl_set:N = \l_siunitx_process_sign_tl, + fixed-exponent .int_set:N = \l_siunitx_process_fixed_int, + minimum-integer-digits .int_set:N = + \l_siunitx_process_integer_min_int, + retain-explicit-plus .bool_set:N = \l_siunitx_process_plus_tl, + retain-unity-mantissa .bool_set:N = + \l_siunitx_process_unity_mantissa_bool, + retain-zero-exponent .bool_set:N = + \l_siunitx_process_zero_exponent_bool, + round-half .choice:, + round-half / even .code:n = + { \bool_set_false:N \l_siunitx_round_half_up_bool }, + round-half / up .code:n = + { \bool_set_true:N \l_siunitx_round_half_up_bool }, + round-integer-to-decimal .bool_set:N = + \l_siunitx_process_int_to_dec_bool, + round-minimum .tl_set:N = \l_siunitx_process_round_min_tl, + round-mode .choice: , + round-mode / figures .code:n = + { \tl_set:Nn \l_siunitx_round_tl { figures } }, + round-mode / off .code:n = { \tl_clear:N \l_siunitx_round_tl }, + round-mode / places .code:n = + { \tl_set:Nn \l_siunitx_round_tl { places } }, + round-precision .int_set:N = \l_siunitx_process_precision_int, + scientific-notation .choice: , + scientific-notation + / false .code:n = + { + \bool_set_false:N \l_siunitx_process_fixed_bool + \bool_set_false:N \l_siunitx_process_engineering_bool + \bool_set_false:N \l_siunitx_process_scientific_bool + }, + scientific-notation + / engineering .code:n = + { + \bool_set_false:N \l_siunitx_process_fixed_bool + \bool_set_true:N \l_siunitx_process_engineering_bool + \bool_set_true:N \l_siunitx_process_scientific_bool + }, + scientific-notation + / fixed .code:n = + { + \bool_set_true:N \l_siunitx_process_fixed_bool + \bool_set_false:N \l_siunitx_process_engineering_bool + \bool_set_false:N \l_siunitx_process_scientific_bool + }, + scientific-notation + / true .code:n = + { + \bool_set_false:N \l_siunitx_process_fixed_bool + \bool_set_false:N \l_siunitx_process_engineering_bool + \bool_set_true:N \l_siunitx_process_scientific_bool + } + } +\keys_set:nn { siunitx } + { + add-decimal-zero = true, + add-integer-zero = true, + retain-unity-mantissa = true, + round-half = up, + round-precision = 2 + } % \end{macrocode} -%\end{macro} +% \end{variable} % -%\begin{macro}{\siunitx_number_process:} -% Post-processing is a series of small tasks. +% \begin{macro}{\siunitx_number_process:} +% Post-processing is a series of small tasks. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process: { - \siunitx_number_process_sign: - \siunitx_number_process_zero_fill: - \siunitx_number_process_mantissa: - \prop_if_in:NnF \l_siunitx_number_in_prop { symbolic } - { - \siunitx_number_process_exponent: - \bool_if:NTF \l_siunitx_process_fixed_bool - { \siunitx_number_process_fixed: } - { - \bool_if:NT \l_siunitx_process_scientific_bool - { \siunitx_number_process_scientific: } - } - \siunitx_number_process_uncertainty: - \prop_if_in:NnF \l_siunitx_number_in_prop { uncertainty } - { \siunitx_number_process_round: } - } - \siunitx_number_process_integer_digits: -} +\cs_new_protected:Npn \siunitx_number_process: + { + \siunitx_number_process_sign: + \siunitx_number_process_zero_fill: + \siunitx_number_process_mantissa: + \prop_if_in:NnF \l_siunitx_number_in_prop { symbolic } + { + \siunitx_number_process_exponent: + \bool_if:NTF \l_siunitx_process_fixed_bool + { \siunitx_number_process_fixed: } + { + \bool_if:NT \l_siunitx_process_scientific_bool + { \siunitx_number_process_scientific: } + } + \siunitx_number_process_uncertainty: + \bool_if:NT \l_siunitx_exp_to_prefix_bool + { + \tl_if_empty:NF \l_siunitx_unit_tl + { \siunitx_number_exp_to_prefix: } + } + \prop_if_in:NnF \l_siunitx_number_in_prop { uncertainty } + { \siunitx_number_process_round: } + } + \siunitx_number_process_integer_digits: + \bool_if:NT \l_siunitx_process_drop_exponent_bool + { + \prop_del:Nn \l_siunitx_number_in_prop { exponent } + \prop_del:Nn \l_siunitx_number_in_prop { exponent-integer } + } + } % \end{macrocode} -%\end{macro} +% \end{macro} % %\begin{macro}{\siunitx_number_process_exponent:} %\begin{macro}[aux]{\siunitx_number_process_exponent_aux:n} % To check for a totally zero exponent, the possibility that one or more % of the exponent storage areas is zero needs to be considered. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_exponent: { +\cs_new_protected:Npn \siunitx_number_process_exponent: { \bool_if:NF \l_siunitx_process_zero_exponent_bool { \prop_if_in:NnT \l_siunitx_number_in_prop { exponent } @@ -7624,7 +7728,7 @@ This work consists of the file siunitx.dtx } } } -\cs_new_protected_nopar:Npn \siunitx_number_process_exponent_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_process_exponent_aux:n #1 { \prop_get:NnNT \l_siunitx_number_in_prop { exponent- #1 } \l_siunitx_tmpa_tl { @@ -7636,181 +7740,184 @@ This work consists of the file siunitx.dtx %\end{macro} %\end{macro} % -%\begin{macro}{\siunitx_number_process_figures:n} -%\begin{macro}[aux]{ -% \siunitx_number_process_figures_aux:n , -% \siunitx_number_process_figures_init:n -%} -% The approach here is to find how many digits there are in each part -% of the number, working out which are significant. The next stage is -% reconstruction of the number. +% \begin{macro}{\siunitx_number_process_figures:n} +% \begin{macro}[aux] +% { +% \siunitx_number_process_figures_aux:n , +% \siunitx_number_process_figures_init:n +% } +% The approach here is to find how many digits there are in each part +% of the number, working out which are significant. The next stage is +% reconstruction of the number. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures:n #1 { - \int_compare:nNnTF { \l_siunitx_process_precision_int } > { 0 } - { - \prop_if_in:NnT \l_siunitx_number_in_prop {#1} - { \siunitx_number_process_figures_aux:n {#1} } - } - { - \prop_del:Nn \l_siunitx_number_in_prop { #1 -sign } - \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } - \bool_if:NF \l_siunitx_process_int_to_dec_bool - { - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } - } - } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_aux:n #1 { - \siunitx_number_process_figures_init:n {#1} - \siunitx_number_process_figures_count:n { integer } - \siunitx_number_process_figures_count:n { decimal } - \bool_if:NTF \l_siunitx_round_bool - { - \bool_set_false:N \l_siunitx_round_bool - \int_compare:nNnTF - { \l_siunitx_round_int } > - { \l_siunitx_process_precision_int } - { - \siunitx_number_process_figures_round: - \siunitx_number_process_round_tidy:n {#1} - } - { \siunitx_number_process_figures_pad:n {#1} } - } - { - \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } - } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_init:n #1 { - \int_zero:N \l_siunitx_round_int - \bool_set_false:N \l_siunitx_round_bool - \prop_get:NnNF \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_round_decimal_in_tl - { \tl_clear:N \l_siunitx_round_decimal_in_tl } - \prop_get:NnNF \l_siunitx_number_in_prop { #1 -integer } - \l_siunitx_round_integer_in_tl - { \tl_clear:N \l_siunitx_round_integer_in_tl } - \tl_clear:N \l_siunitx_round_decimal_out_tl - \tl_clear:N \l_siunitx_round_integer_out_tl -} +\cs_new_protected:Npn \siunitx_number_process_figures:n #1 + { + \int_compare:nNnTF \l_siunitx_process_precision_int > \c_zero + { + \prop_if_in:NnT \l_siunitx_number_in_prop {#1} + { \siunitx_number_process_figures_aux:n {#1} } + } + { + \prop_del:Nn \l_siunitx_number_in_prop { #1 -sign } + \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } + \bool_if:NF \l_siunitx_process_int_to_dec_bool + { \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } } + } + } +\cs_new_protected:Npn \siunitx_number_process_figures_aux:n #1 + { + \siunitx_number_process_figures_init:n {#1} + \siunitx_number_process_figures_count:n { integer } + \siunitx_number_process_figures_count:n { decimal } + \bool_if:NTF \l_siunitx_round_bool + { + \bool_set_false:N \l_siunitx_round_bool + \int_compare:nNnTF + \l_siunitx_round_int > \l_siunitx_process_precision_int + { + \siunitx_number_process_figures_round: + \siunitx_number_process_round_tidy:n {#1} + } + { \siunitx_number_process_figures_pad:n {#1} } + } + { + \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } + } + } +\cs_new_protected:Npn \siunitx_number_process_figures_init:n #1 + { + \int_zero:N \l_siunitx_round_int + \bool_set_false:N \l_siunitx_round_bool + \bool_set_false:N \l_siunitx_round_even_bool + \prop_get:NnNF \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_round_decimal_in_tl + { \tl_clear:N \l_siunitx_round_decimal_in_tl } + \prop_get:NnNF \l_siunitx_number_in_prop { #1 -integer } + \l_siunitx_round_integer_in_tl + { \tl_clear:N \l_siunitx_round_integer_in_tl } + \tl_clear:N \l_siunitx_round_decimal_out_tl + \tl_clear:N \l_siunitx_round_integer_out_tl + \tl_clear:N \l_siunitx_round_discard_tl + } % \end{macrocode} -%\end{macro} -%\end{macro} -%\begin{macro}{\siunitx_number_process_figures_count:n} -%\begin{macro}[aux]{\siunitx_number_process_figures_count_aux:n} -% The counting code has to check that characters are actually -% significant. +% \end{macro} +% \end{macro} +% \begin{macro}{\siunitx_number_process_figures_count:n} +% \begin{macro}[aux]{\siunitx_number_process_figures_count_aux:n} +% The counting code has to check that characters are actually +% significant. % \begin{macrocode} -\cs_new_protected_nopar:Npn - \siunitx_number_process_figures_count:n #1 { - \tl_if_empty:cF { l_siunitx_round_ #1 _in_tl } - { - \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -uncertainty } - { \siunitx_number_process_figures_count_aux:n {#1} } - } -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_figures_count_aux:n #1 { - \int_set:Nn \l_siunitx_tmp_int - { \tl_head:v { l_siunitx_round_ #1 _in_tl } } - \tl_set:cx { l_siunitx_round_ #1 _in_tl } - { \tl_tail:v { l_siunitx_round_ #1 _in_tl } } - \tl_put_left:cV { l_siunitx_round_ #1 _out_tl } \l_siunitx_tmp_int - \bool_if:NF \l_siunitx_round_bool - { - \int_compare:nNnF { \l_siunitx_tmp_int } = { 0 } - { \bool_set_true:N \l_siunitx_round_bool } - } - \bool_if:NT \l_siunitx_round_bool - { \int_incr:N \l_siunitx_round_int } - \tl_if_empty:cTF { l_siunitx_round_ #1 _in_tl } - { - \tl_set_eq:cc { l_siunitx_round_ #1 _in_tl } - { l_siunitx_round_ #1 _out_tl } - \tl_clear:c { l_siunitx_round_ #1 _out_tl } - } - { \siunitx_number_process_figures_count_aux:n {#1} } -} +\cs_new_protected:Npn \siunitx_number_process_figures_count:n #1 + { + \tl_if_empty:cF { l_siunitx_round_ #1 _in_tl } + { + \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -uncertainty } + { \siunitx_number_process_figures_count_aux:n {#1} } + } + } +\cs_new_protected:Npn \siunitx_number_process_figures_count_aux:n #1 + { + \int_set:Nn \l_siunitx_tmp_int + { \tl_head:v { l_siunitx_round_ #1 _in_tl } } + \tl_set:cx { l_siunitx_round_ #1 _in_tl } + { \tl_tail:v { l_siunitx_round_ #1 _in_tl } } + \tl_put_left:cV { l_siunitx_round_ #1 _out_tl } \l_siunitx_tmp_int + \bool_if:NF \l_siunitx_round_bool + { + \int_compare:nNnF { \l_siunitx_tmp_int } = \c_zero + { \bool_set_true:N \l_siunitx_round_bool } + } + \bool_if:NT \l_siunitx_round_bool + { \int_incr:N \l_siunitx_round_int } + \tl_if_empty:cTF { l_siunitx_round_ #1 _in_tl } + { + \tl_set_eq:cc { l_siunitx_round_ #1 _in_tl } + { l_siunitx_round_ #1 _out_tl } + \tl_clear:c { l_siunitx_round_ #1 _out_tl } + } + { \siunitx_number_process_figures_count_aux:n {#1} } + } % \end{macrocode} -%\end{macro} -%\end{macro} -%\begin{macro}{\siunitx_number_process_figures_round:} -%\begin{macro}[aux]{\siunitx_number_process_figures_round_loop:} -% The control macro for rounding to figures does the decimal part -% then the integer part as loops. There is then some tidying up if a -% digit is carried at the end. +% \end{macro} +% \end{macro} +% \begin{macro}{\siunitx_number_process_figures_round:} +% \begin{macro}[aux]{\siunitx_number_process_figures_round_loop:} +% The control macro for rounding to figures does the decimal part +% then the integer part as loops. There is then some tidying up if a +% digit is carried at the end. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_round: { - \int_set:Nn \l_siunitx_round_int - { \l_siunitx_round_int - \l_siunitx_process_precision_int } - \tl_if_empty:NF \l_siunitx_round_decimal_in_tl - { \siunitx_number_process_figures_round_loop: } - \tl_if_empty:NF \l_siunitx_round_integer_in_tl - { \siunitx_number_process_figures_integer: } - \bool_if:NT \l_siunitx_round_bool - { - \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 1 } - \tl_if_empty:NF \l_siunitx_round_decimal_out_tl - { - \tl_reverse:N \l_siunitx_round_decimal_out_tl - \tl_set:Nx \l_siunitx_round_decimal_out_tl - { \tl_tail:n \l_siunitx_round_decimal_out_tl } - \tl_reverse:N \l_siunitx_round_decimal_out_tl - } - } -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_figures_round_loop: { - \siunitx_number_process_round_decimal: - \tl_if_empty:NF \l_siunitx_round_decimal_in_tl - { \siunitx_number_process_figures_round_loop: } -} +\cs_new_protected:Npn \siunitx_number_process_figures_round: + { + \int_set:Nn \l_siunitx_round_int + { \l_siunitx_round_int - \l_siunitx_process_precision_int } + \tl_if_empty:NF \l_siunitx_round_decimal_in_tl + { \siunitx_number_process_figures_round_loop: } + \tl_if_empty:NF \l_siunitx_round_integer_in_tl + { \siunitx_number_process_figures_integer: } + \bool_if:NT \l_siunitx_round_bool + { + \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 1 } + \tl_if_empty:NF \l_siunitx_round_decimal_out_tl + { + \tl_reverse:N \l_siunitx_round_decimal_out_tl + \tl_set:Nx \l_siunitx_round_decimal_out_tl + { \tl_tail:n \l_siunitx_round_decimal_out_tl } + \tl_reverse:N \l_siunitx_round_decimal_out_tl + } + } + } +\cs_new_protected:Npn \siunitx_number_process_figures_round_loop: + { + \siunitx_number_process_round_decimal: + \tl_if_empty:NF \l_siunitx_round_decimal_in_tl + { \siunitx_number_process_figures_round_loop: } + } % \end{macrocode} -%\end{macro} -%\end{macro} -%\begin{macro}{\siunitx_number_process_figures_integer:} -% For figures, the integer part is a little complicated as zeros need -% to be included. +% \end{macro} +% \end{macro} +% \begin{macro}{\siunitx_number_process_figures_integer:} +% For figures, the integer part is a little complicated as zeros need +% to be included. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_integer: { - \int_compare:nNnT { \l_siunitx_round_int } > { 0 } - { \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 0 } } - \int_compare:nNnF { \l_siunitx_round_int } > { 1 } - { - \int_set:Nn \l_siunitx_tmp_int - { \tl_head:V \l_siunitx_round_integer_in_tl } - \bool_if:NT \l_siunitx_round_bool - { \int_incr:N \l_siunitx_tmp_int } - \bool_set_false:N \l_siunitx_round_bool - \int_compare:nNnTF { \l_siunitx_round_int } = { 1 } - { - \int_compare:nNnT { \l_siunitx_tmp_int } > { 4 } - { \bool_set_true:N \l_siunitx_round_bool } - } - { - \int_compare:nNnT { \l_siunitx_tmp_int } = { 10 } - { - \bool_set_true:N \l_siunitx_round_bool - \int_zero:N \l_siunitx_tmp_int - } - \tl_put_left:NV \l_siunitx_round_integer_out_tl - \l_siunitx_tmp_int - } - } - \int_decr:N \l_siunitx_round_int - \tl_set:Nx \l_siunitx_round_integer_in_tl - { \tl_tail:V \l_siunitx_round_integer_in_tl } - \tl_if_empty:NF \l_siunitx_round_integer_in_tl - { \siunitx_number_process_figures_integer: } -} +\cs_new_protected:Npn \siunitx_number_process_figures_integer: + { + \int_compare:nNnT \l_siunitx_round_int > \c_zero + { \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 0 } } + \int_compare:nNnF \l_siunitx_round_int > \c_one + { + \int_set:Nn \l_siunitx_tmp_int + { \tl_head:V \l_siunitx_round_integer_in_tl } + \siunitx_number_process_round_up: + \int_compare:nNnTF \l_siunitx_round_int = \c_one + { + \int_compare:nNnT \l_siunitx_tmp_int > \c_four + { \bool_set_true:N \l_siunitx_round_bool } + } + { + \int_compare:nNnT \l_siunitx_tmp_int = \c_ten + { + \bool_set_true:N \l_siunitx_round_bool + \int_zero:N \l_siunitx_tmp_int + } + \tl_put_left:NV \l_siunitx_round_integer_out_tl + \l_siunitx_tmp_int + } + } + \int_decr:N \l_siunitx_round_int + \tl_set:Nx \l_siunitx_round_integer_in_tl + { \tl_tail:V \l_siunitx_round_integer_in_tl } + \tl_if_empty:NF \l_siunitx_round_integer_in_tl + { \siunitx_number_process_figures_integer: } + } % \end{macrocode} %\end{macro} %\begin{macro}{\siunitx_number_process_figures_pad:n} % If the number is too short, then the reversal is undone and the % padding routine is called. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_pad:n #1 { +\cs_new_protected:Npn \siunitx_number_process_figures_pad:n #1 { \prop_get:NnN \l_siunitx_number_in_prop { #1 -integer } \l_siunitx_round_integer_in_tl \prop_get:NnN \l_siunitx_number_in_prop { #1 -decimal } @@ -7834,7 +7941,7 @@ This work consists of the file siunitx.dtx % When working to a fixed exponent value, the idea is to use the stack % to do the work. First, there is some set up to do. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed: { +\cs_new_protected:Npn \siunitx_number_process_fixed: { \prop_if_in:NnF \l_siunitx_number_in_prop { complex } { \prop_get:NnNF \l_siunitx_number_in_prop { mantissa-integer } @@ -7866,7 +7973,7 @@ This work consists of the file siunitx.dtx % The main loop checks to see which way to adjust the exponent then % does the work. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_fixed_aux_i:nnn #1#2#3 { \prop_put:Nnn \l_siunitx_number_in_prop { exponent } { true } @@ -7884,7 +7991,7 @@ This work consists of the file siunitx.dtx \int_compare:nNnF { #1 + 0 #2 } = { 0 } { \siunitx_number_process_fixed_aux_ii:nnn {#1} {#2} {#3} } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_fixed_aux_ii:nnn #1#2#3 { \int_compare:nNnTF {#3} > { \l_siunitx_process_fixed_int } { \siunitx_number_process_fixed_large:nnn {#1} {#2} {#3} } @@ -7921,15 +8028,15 @@ This work consists of the file siunitx.dtx % leading zeros to dispose of. There is also a check to avoid adding % an additional zero to the decimal part of the number. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed_large:nnn #1 +\cs_new_protected:Npn \siunitx_number_process_fixed_large:nnn #1 { \int_compare:nNnTF {#1} = \c_zero { \siunitx_number_process_fixed_large_aux:nnn { } } { \siunitx_number_process_fixed_large_aux:nnn {#1} } } -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed_large_aux:nnn #1#2#3 +\cs_new_protected:Npn \siunitx_number_process_fixed_large_aux:nnn #1#2#3 { - \cs_set_protected_nopar:Npn + \cs_set_protected:Npn \siunitx_number_process_fixed_large_aux:w ##1##2 \q_stop { \tl_if_empty:nTF {##2} @@ -7961,11 +8068,11 @@ This work consists of the file siunitx.dtx { \siunitx_number_process_fixed_aux_ii:nnn { #1 0 } { } { #3 - 1 } } { \siunitx_number_process_fixed_large_aux:w #2 \q_stop } } -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed_large_aux:w +\cs_new_protected:Npn \siunitx_number_process_fixed_large_aux:w { } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_fixed_small:nnn #1#2#3 { - \cs_set_protected_nopar:Npn + \cs_set_protected:Npn \siunitx_number_process_fixed_small_aux:w ##1##2 \q_stop ##3 { \tl_if_empty:nTF {##2} @@ -7987,7 +8094,7 @@ This work consists of the file siunitx.dtx } \siunitx_number_process_fixed_small_aux:w #1 \q_stop { } } -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed_small_aux:w +\cs_new_protected:Npn \siunitx_number_process_fixed_small_aux:w { } % \end{macrocode} %\end{macro} @@ -7997,7 +8104,7 @@ This work consists of the file siunitx.dtx % Producing extra digits for the integer part is a simple process % once the target is known. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_integer_digits: { +\cs_new_protected:Npn \siunitx_number_process_integer_digits: { \int_compare:nNnT { \l_siunitx_process_integer_min_int } > { \c_zero } { @@ -8030,7 +8137,7 @@ This work consists of the file siunitx.dtx % A check for the mantissa consisting only of the token \texttt{1}, when % an exponent is also available. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_mantissa: { +\cs_new_protected:Npn \siunitx_number_process_mantissa: { \bool_if:NF \l_siunitx_process_unity_mantissa_bool { \prop_if_in:NnT \l_siunitx_number_in_prop { exponent } @@ -8063,7 +8170,7 @@ This work consists of the file siunitx.dtx % For padding a number by adding zero to the end repeatedly. This can % happen if the input was zero or if the number is too short. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_pad:n #1 { +\cs_new_protected:Npn \siunitx_number_process_pad:n #1 { \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } \l_siunitx_tmpa_tl { @@ -8079,288 +8186,339 @@ This work consists of the file siunitx.dtx % \end{macrocode} %\end{macro} % -%\begin{macro}{\siunitx_number_process_places:n} -%\begin{macro}[aux]{ -% \siunitx_number_process_places_init:n , -% \siunitx_number_process_places_aux_i:n , -% \siunitx_number_process_places_aux_ii:n , -% \siunitx_number_process_places_loop:n , -% \siunitx_number_process_places_integer:n -%} -% For rounding to a fixed number of places, a check is made to see if -% the decimal part is exactly zero. If it is, just create the -% appropriate number of zeros in the padding routine. Otherwise, do the -% real work. +% \begin{macro}{\siunitx_number_process_places:n} +% \begin{macro}[aux] +% { +% \siunitx_number_process_places_init:n , +% \siunitx_number_process_places_aux_i:n , +% \siunitx_number_process_places_none: , +% \siunitx_number_process_places_aux_ii:n , +% \siunitx_number_process_places_loop:n , +% \siunitx_number_process_places_integer:n +% } +% For rounding to a fixed number of places, a check is made to see if +% the decimal part is exactly zero. If it is, just create the +% appropriate number of zeros in the padding routine. Otherwise, do the +% real work. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_places:n #1 { - \prop_if_in:NnT \l_siunitx_number_in_prop {#1} - { - \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -uncertainty } - { \siunitx_number_process_places_aux_i:n {#1} } - } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_places_aux_i:n #1 { - \int_compare:nNnTF { \l_siunitx_process_precision_int } = { 0 } - { - \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_tmpa_tl - { - \int_compare:nNnTF - { \tl_head:V \l_siunitx_tmpa_tl } > { 4 } - { - \prop_get:NnNTF \l_siunitx_number_in_prop { #1 -integer } - \l_siunitx_tmpa_tl - { - \tl_set:Nx \l_siunitx_tmpa_tl - { \int_eval:n { \l_siunitx_tmpa_tl + 1 } } - \prop_put:NnV \l_siunitx_number_in_prop - { #1 -integer } \l_siunitx_tmpa_tl - } - { - \prop_put:Nnn \l_siunitx_number_in_prop - { #1 -integer } { 1 } - } - - } - { - \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -integer } - { - \prop_put:Nnn \l_siunitx_number_in_prop - { #1 -integer } { 0 } - } - } - } - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } - \bool_if:NF \l_siunitx_process_int_to_dec_bool - { - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } - } - } - { - \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_tmpa_tl - { - \tl_if_empty:NT \l_siunitx_tmpa_tl - { \tl_set:Nn \l_siunitx_tmpa_tl { 0 } } - \int_compare:nNnTF { \l_siunitx_tmpa_tl } = { 0 } - { - \prop_put:Nnn \l_siunitx_number_in_prop { #1 -decimal } - { } - \int_set:Nn \l_siunitx_round_int - { \l_siunitx_process_precision_int } - \siunitx_number_process_pad:n {#1} - } - { - \int_set:Nn \l_siunitx_round_int - { \tl_length:N \l_siunitx_tmpa_tl } - \siunitx_number_process_places_aux_ii:n {#1} - } - } - } -} +\cs_new_protected:Npn \siunitx_number_process_places:n #1 + { + \prop_if_in:NnT \l_siunitx_number_in_prop {#1} + { + \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -uncertainty } + { \siunitx_number_process_places_aux_i:n {#1} } + } + } +\cs_new_protected:Npn \siunitx_number_process_places_aux_i:n #1 + { + \int_compare:nNnTF \l_siunitx_process_precision_int = \c_zero + { \siunitx_number_process_places_none:n {#1} } + { + \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_tmpa_tl + { + \tl_if_empty:NT \l_siunitx_tmpa_tl + { \tl_set:Nn \l_siunitx_tmpa_tl { 0 } } + \int_compare:nNnTF \l_siunitx_tmpa_tl = \c_zero + { + \prop_put:Nnn \l_siunitx_number_in_prop { #1 -decimal } { } + \int_set:Nn \l_siunitx_round_int + { \l_siunitx_process_precision_int } + \siunitx_number_process_pad:n {#1} + } + { + \int_set:Nn \l_siunitx_round_int + { \tl_length:N \l_siunitx_tmpa_tl } + \siunitx_number_process_places_aux_ii:n {#1} + } + } + } + } +% \end{macrocode} +% Rounding to no places at all requires a few checks to see if there is any +% work to do. That includes a check for rounding half to even, where if +% the decimal part is exactly half then special action is required. +% \begin{macrocode} +\cs_new_protected:Npn \siunitx_number_process_places_none:n #1 + { + \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } \l_siunitx_tmpa_tl + { + \int_compare:nNnTF { \tl_head:V \l_siunitx_tmpa_tl } > \c_four + { + \prop_get:NnNTF \l_siunitx_number_in_prop { #1 -integer } + \l_siunitx_tmpb_tl + { + \tl_set:Nx \l_siunitx_tmpb_tl + { \int_eval:n { \l_siunitx_tmpb_tl + 1 } } + \bool_if:NF \l_siunitx_round_half_up_bool + { + \int_compare:nNnT + { 0 \tl_tail:V \l_siunitx_tmpa_tl } = \c_zero + { + \int_if_odd:nT \l_siunitx_tmpb_tl + { + \tl_set:Nx \l_siunitx_tmpb_tl + { \int_eval:n { \l_siunitx_tmpb_tl - 1 } } + } + } + } + } + { \tl_set:Nn \l_siunitx_tmpb_tl { 1 } } + \prop_put:NnV \l_siunitx_number_in_prop + { #1 -integer } \l_siunitx_tmpb_tl + } + { + \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -integer } + { + \prop_put:Nnn \l_siunitx_number_in_prop + { #1 -integer } { 0 } + } + } + } + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } + \bool_if:NF \l_siunitx_process_int_to_dec_bool + { \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } } + } % \end{macrocode} % For rounding to a fixed number of places, the package finds the % difference in length between what is present and what is required. % If the number is too short, there is some simple padding to do. % \begin{macrocode} -\cs_new_protected_nopar:Npn - \siunitx_number_process_places_aux_ii:n #1 { - \int_sub:Nn \l_siunitx_round_int - { \l_siunitx_process_precision_int } - \int_compare:nNnTF { \l_siunitx_round_int } < { 0 } - { - \int_set:Nn \l_siunitx_round_int { - \l_siunitx_round_int } - \siunitx_number_process_pad:n {#1} - } - { - \siunitx_number_process_places_init:n {#1} - \siunitx_number_process_places_loop:n {#1} - \siunitx_number_process_round_tidy:n {#1} - } -} +\cs_new_protected:Npn \siunitx_number_process_places_aux_ii:n #1 + { + \int_sub:Nn \l_siunitx_round_int + { \l_siunitx_process_precision_int } + \int_compare:nNnTF \l_siunitx_round_int < \c_zero + { + \int_set:Nn \l_siunitx_round_int { - \l_siunitx_round_int } + \siunitx_number_process_pad:n {#1} + } + { + \siunitx_number_process_places_init:n {#1} + \siunitx_number_process_places_loop:n {#1} + \siunitx_number_process_round_tidy:n {#1} + } + } % \end{macrocode} -% To keep the code a little clearer. +% To keep the code a little clearer. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_places_init:n #1 { - \prop_get:NnNF \l_siunitx_number_in_prop { #1 -integer } - \l_siunitx_round_integer_in_tl - { \tl_clear:N \l_siunitx_round_integer_in_tl } - \prop_get:NnN \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_round_decimal_in_tl - \tl_reverse:N \l_siunitx_round_integer_in_tl - \tl_reverse:N \l_siunitx_round_decimal_in_tl - \tl_clear:N \l_siunitx_round_integer_out_tl - \tl_clear:N \l_siunitx_round_decimal_out_tl - \bool_set_false:N \l_siunitx_round_bool -} +\cs_new_protected:Npn \siunitx_number_process_places_init:n #1 + { + \prop_get:NnNF \l_siunitx_number_in_prop { #1 -integer } + \l_siunitx_round_integer_in_tl + { \tl_clear:N \l_siunitx_round_integer_in_tl } + \prop_get:NnN \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_round_decimal_in_tl + \tl_reverse:N \l_siunitx_round_integer_in_tl + \tl_reverse:N \l_siunitx_round_decimal_in_tl + \tl_clear:N \l_siunitx_round_integer_out_tl + \tl_clear:N \l_siunitx_round_decimal_out_tl + \tl_clear:N \l_siunitx_round_discard_tl + \bool_set_false:N \l_siunitx_round_bool + \bool_set_false:N \l_siunitx_round_even_bool + } % \end{macrocode} % If there is a decimal, do the decimal processing then come back here. % If there is an integer, do the same. Only if both are empty does the % loop stop. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_places_loop:n #1 { - \tl_if_empty:NTF \l_siunitx_round_decimal_in_tl - { - \tl_if_empty:NF \l_siunitx_round_integer_in_tl - { - \siunitx_number_process_places_integer:n {#1} - \siunitx_number_process_places_loop:n {#1} - } - \bool_if:NT \l_siunitx_round_bool - { - \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 1 } - \bool_set_false:N \l_siunitx_round_bool - } - } - { - \siunitx_number_process_round_decimal: - \siunitx_number_process_places_loop:n {#1} - } -} +\cs_new_protected:Npn \siunitx_number_process_places_loop:n #1 + { + \tl_if_empty:NTF \l_siunitx_round_decimal_in_tl + { + \tl_if_empty:NF \l_siunitx_round_integer_in_tl + { + \siunitx_number_process_places_integer:n {#1} + \siunitx_number_process_places_loop:n {#1} + } + \bool_if:NT \l_siunitx_round_bool + { + \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 1 } + \bool_set_false:N \l_siunitx_round_bool + } + } + { + \siunitx_number_process_round_decimal: + \siunitx_number_process_places_loop:n {#1} + } + } % \end{macrocode} % Rounding for integers is just a case of carrying digits. % \begin{macrocode} -\cs_new_protected_nopar:Npn - \siunitx_number_process_places_integer:n #1 { - \int_set:Nn \l_siunitx_tmp_int - { \tl_head:V \l_siunitx_round_integer_in_tl } - \tl_set:Nx \l_siunitx_round_integer_in_tl - { \tl_tail:V \l_siunitx_round_integer_in_tl } - \bool_if:NT \l_siunitx_round_bool - { \int_incr:N \l_siunitx_tmp_int } - \bool_set_false:N \l_siunitx_round_bool - \int_compare:nNnT { \l_siunitx_tmp_int } = { 10 } - { - \int_zero:N \l_siunitx_tmp_int - \bool_set_true:N \l_siunitx_round_bool - } - \tl_put_left:NV \l_siunitx_round_integer_out_tl \l_siunitx_tmp_int -} +\cs_new_protected:Npn \siunitx_number_process_places_integer:n #1 + { + \int_set:Nn \l_siunitx_tmp_int + { \tl_head:V \l_siunitx_round_integer_in_tl } + \tl_set:Nx \l_siunitx_round_integer_in_tl + { \tl_tail:V \l_siunitx_round_integer_in_tl } + \siunitx_number_process_round_up: + \bool_set_false:N \l_siunitx_round_bool + \int_compare:nNnT \l_siunitx_tmp_int = \c_ten + { + \int_zero:N \l_siunitx_tmp_int + \bool_set_true:N \l_siunitx_round_bool + } + \tl_put_left:NV \l_siunitx_round_integer_out_tl \l_siunitx_tmp_int + } % \end{macrocode} %\end{macro} %\end{macro} % -%\begin{macro}{\siunitx_number_process_round:} -% The lead-off for rounding is the same for decimal places and -% significant figures. +% \begin{macro}{\siunitx_number_process_round:} +% The lead-off for rounding is the same for decimal places and +% significant figures. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_round: { - \tl_if_empty:NF \l_siunitx_round_tl - { - \bool_if:NT \l_siunitx_process_int_to_dec_bool - { - \prop_if_in:NnF \l_siunitx_number_in_prop - { mantissa-decimal } - { - \prop_put:Nnn \l_siunitx_number_in_prop - { mantissa-decimal } { 0 } - } - \prop_if_in:NnF \l_siunitx_number_in_prop - { mantissa-decimal-marker } - { - \prop_put:Nnn \l_siunitx_number_in_prop - { mantissa-decimal-marker } { . } - } - } - \cs_set_nopar:Npx \siunitx_tmp:w - { - \exp_not:N \clist_map_function:nN - { mantissa , complex } - \exp_not:c - { siunitx_number_process_ \l_siunitx_round_tl :n } - } - \siunitx_tmp:w - } -} +\cs_new_protected:Npn \siunitx_number_process_round: + { + \tl_if_empty:NF \l_siunitx_round_tl + { + \bool_if:NT \l_siunitx_process_int_to_dec_bool + { + \prop_if_in:NnF \l_siunitx_number_in_prop { mantissa-decimal } + { + \prop_put:Nnn \l_siunitx_number_in_prop { mantissa-decimal } + { 0 } + } + \prop_if_in:NnF \l_siunitx_number_in_prop + { mantissa-decimal-marker } + { + \prop_put:Nnn \l_siunitx_number_in_prop + { mantissa-decimal-marker } { . } + } + } + \clist_map_function:nc { mantissa , complex } + { siunitx_number_process_ \l_siunitx_round_tl :n } + } + } % \end{macrocode} -%\end{macro} -%\begin{macro}{\siunitx_number_process_round_decimal:} -%\begin{macro}[aux]{\siunitx_number_process_round_decimal_aux:} -% The rounding routine for decimals is the same for figures and places, -% so there is a generalised function here. Unfortunately, it is also -% complicated! +% \end{macro} +% \begin{macro}{\siunitx_number_process_round_decimal:} +% \begin{macro}[aux]{\siunitx_number_process_round_decimal_aux:} +% The rounding routine for decimals is the same for figures and places, +% so there is a generalised function here. Unfortunately, it is also +% complicated! % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_round_decimal: { - \int_compare:nNnF { \l_siunitx_round_int } > { 1 } - { \siunitx_number_process_round_decimal_aux: } - \tl_set:Nx \l_siunitx_round_decimal_in_tl - { \tl_tail:V \l_siunitx_round_decimal_in_tl } - \int_decr:N \l_siunitx_round_int -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_round_decimal_aux: { - \int_set:Nn \l_siunitx_tmp_int - { \tl_head:V \l_siunitx_round_decimal_in_tl } - \bool_if:NT \l_siunitx_round_bool - { \int_incr:N \l_siunitx_tmp_int } - \bool_set_false:N \l_siunitx_round_bool - \int_compare:nNnTF { \l_siunitx_round_int } = { 1 } - { - \int_compare:nNnT { \l_siunitx_tmp_int } > { 4 } - { \bool_set_true:N \l_siunitx_round_bool } - } - { - \int_compare:nNnT { \l_siunitx_tmp_int } = { 10 } - { - \bool_set_true:N \l_siunitx_round_bool - \int_zero:N \l_siunitx_tmp_int - } - \tl_put_left:NV \l_siunitx_round_decimal_out_tl - \l_siunitx_tmp_int - } -} +\cs_new_protected:Npn \siunitx_number_process_round_decimal: + { + \int_compare:nNnF \l_siunitx_round_int > \c_one + { \siunitx_number_process_round_decimal_aux: } + \tl_put_right:Nx \l_siunitx_round_discard_tl + { \tl_head:V \l_siunitx_round_decimal_in_tl } + \tl_set:Nx \l_siunitx_round_decimal_in_tl + { \tl_tail:V \l_siunitx_round_decimal_in_tl } + \int_decr:N \l_siunitx_round_int + } % \end{macrocode} -%\end{macro} -%\end{macro} -%\begin{macro}{\siunitx_number_process_round_tidy:n} -%\begin{macro}[aux]{\siunitx_number_process_round_tidy_aux:w} -% To put data back again: there is a check to see if the number has been -% rounded to zero and a minimal value has been requested. +% The logic here has to deal with the (simpler) rounding up method and the +% case where there is a need to check for rounding to an even number. The +% later is only required when the discarded part is exactly equal to +% half of the least-significant digit. So there is a somewhat complex check +% for that, along with a somewhat simpler check when carrying out the +% rounding. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_round_tidy:n #1 { - \int_compare:nNnTF - { - 0 \l_siunitx_round_integer_out_tl + - 0 \l_siunitx_round_decimal_out_tl - } - = { 0 } - { - \fp_compare:nNnTF { \l_siunitx_process_round_min_tl } = { 0 } - { - \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } - \prop_put:NnV \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_round_decimal_out_tl - } - { - \exp_after:wN \siunitx_number_process_round_tidy_aux:w - \l_siunitx_process_round_min_tl . . \q_stop {#1} - } - } - { - \prop_put:NnV \l_siunitx_number_in_prop { #1 -integer } - \l_siunitx_round_integer_out_tl - \tl_if_empty:NTF \l_siunitx_round_decimal_out_tl - { - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } - } - { - \prop_put:NnV \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_round_decimal_out_tl - } - } -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_round_tidy_aux:w #1 . #2 . #3 \q_stop #4 { - \prop_put:Nnn \l_siunitx_number_in_prop { comparator } { < } - \prop_put:Nnn \l_siunitx_number_in_prop { #4 -integer } {#1} - \tl_if_empty:nTF {#2} - { \prop_del:Nn \l_siunitx_number_in_prop { #4 -decimal } } - { \prop_put:Nnn \l_siunitx_number_in_prop { #4 -decimal } {#2} } -} +\cs_new_protected:Npn \siunitx_number_process_round_decimal_aux: + { + \int_set:Nn \l_siunitx_tmp_int + { \tl_head:V \l_siunitx_round_decimal_in_tl } + \siunitx_number_process_round_up: + \int_compare:nNnTF \l_siunitx_round_int = \c_one + { + \int_compare:nNnT \l_siunitx_tmp_int > \c_four + { + \bool_set_true:N \l_siunitx_round_bool + \bool_if:NF \l_siunitx_round_half_up_bool + { + \int_compare:nNnT + { \l_siunitx_round_discard_tl \int_use:N \l_siunitx_tmp_int } + = \c_five + { \bool_set_true:N \l_siunitx_round_even_bool } + } + } + } + { + \int_compare:nNnT \l_siunitx_tmp_int = \c_ten + { + \bool_set_true:N \l_siunitx_round_bool + \int_zero:N \l_siunitx_tmp_int + } + \tl_put_left:NV \l_siunitx_round_decimal_out_tl + \l_siunitx_tmp_int + } + } % \end{macrocode} -%\end{macro} -%\end{macro} +% \end{macro} +% \end{macro} +% \begin{macro}{\siunitx_number_process_round_up:} +% This is needed a few times, to round up the current digit unless +% it is even and \enquote{half to even} is active. +% \begin{macrocode} +\cs_new_protected:Npn \siunitx_number_process_round_up: + { + \bool_if:NT \l_siunitx_round_bool + { + \bool_if:NTF \l_siunitx_round_even_bool + { + \bool_set_false:N \l_siunitx_round_even_bool + \int_if_even:nF \l_siunitx_tmp_int + { \int_incr:N \l_siunitx_tmp_int } + } + { \int_incr:N \l_siunitx_tmp_int } + } + \bool_set_false:N \l_siunitx_round_bool + } +% \end{macrocode} +% \end{macro} +% \begin{macro}{\siunitx_number_process_round_tidy:n} +% \begin{macro}[aux]{\siunitx_number_process_round_tidy_aux:w} +% To put data back again: there is a check to see if the number has been +% r ounded to zero and a minimal value has been requested. +% \begin{macrocode} +\cs_new_protected:Npn \siunitx_number_process_round_tidy:n #1 + { + \int_compare:nNnTF + { + 0 \l_siunitx_round_integer_out_tl + + 0 \l_siunitx_round_decimal_out_tl + } + = \c_zero + { + \fp_compare:nNnTF { \l_siunitx_process_round_min_tl } = { 0 } + { + \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } + \prop_put:NnV \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_round_decimal_out_tl + } + { + \exp_after:wN \siunitx_number_process_round_tidy_aux:w + \l_siunitx_process_round_min_tl . . \q_stop {#1} + } + } + { + \prop_put:NnV \l_siunitx_number_in_prop { #1 -integer } + \l_siunitx_round_integer_out_tl + \tl_if_empty:NTF \l_siunitx_round_decimal_out_tl + { + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } + } + { + \prop_put:NnV \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_round_decimal_out_tl + } + } + } +\cs_new_protected:Npn \siunitx_number_process_round_tidy_aux:w + #1 . #2 . #3 \q_stop #4 + { + \prop_put:Nnn \l_siunitx_number_in_prop { comparator } { < } + \prop_put:Nnn \l_siunitx_number_in_prop { #4 -integer } {#1} + \tl_if_empty:nTF {#2} + { \prop_del:Nn \l_siunitx_number_in_prop { #4 -decimal } } + { \prop_put:Nnn \l_siunitx_number_in_prop { #4 -decimal } {#2} } + } +% \end{macrocode} +% \end{macro} +% \end{macro} % %\begin{macro}{\siunitx_number_process_scientific:} %\begin{macro}[aux]{ @@ -8381,7 +8539,7 @@ This work consists of the file siunitx.dtx % of places involved is unchanged. The first step is to skip any % complex-number containing input and to recover the stored data. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_scientific: { +\cs_new_protected:Npn \siunitx_number_process_scientific: { \prop_if_in:NnF \l_siunitx_number_in_prop { complex } { \prop_get:NnNF \l_siunitx_number_in_prop { mantissa-integer } @@ -8407,7 +8565,7 @@ This work consists of the file siunitx.dtx \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_aux_i:nnn #1#2#3 { \int_compare:nNnF { #1 + 0 #2 } = { 0 } { \siunitx_number_process_scientific_aux_ii:nnn {#1} {#2} {#3} } @@ -8416,7 +8574,7 @@ This work consists of the file siunitx.dtx % The code here works on a loop, standardising the mantissa into the % range \( 1 \le x < 10 \). % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_aux_ii:nnn #1#2#3 { \int_compare:nNnTF {#1} > { 9 } { \siunitx_number_process_scientific_large:nnn {#1} {#2} {#3} } @@ -8439,7 +8597,7 @@ This work consists of the file siunitx.dtx % using some mathematics. This does limit the range of the input, but % in real cases this should not be an issue. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_large:nnn #1#2#3 { \int_set:Nn \l_siunitx_tmp_int { \int_div_truncate:nn {#1} { 10 } } \tl_set:Nx \l_siunitx_tmpa_tl { \int_use:N \l_siunitx_tmp_int } @@ -8455,13 +8613,13 @@ This work consists of the file siunitx.dtx % \end{macrocode} % For small numbers, the important digit is easy to find. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_small:wn #1#2 \q_stop #3 { \siunitx_number_process_scientific_aux_ii:nnn {#1} {#2} { #3 - 1 } } % \end{macrocode} % A tidy-up and store routine. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_store:nnn #1#2#3 { \prop_put:Nnn \l_siunitx_number_in_prop { mantissa-integer } {#1} @@ -8510,7 +8668,7 @@ This work consists of the file siunitx.dtx % The fastest way to do this is by expansion, as the number of tokens % is known. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_engineering:nnn #1#2#3 { \use:c @@ -8533,7 +8691,7 @@ This work consists of the file siunitx.dtx \cs_new_eq:cN { siunitx_number_process_scientific_engineering_0:nnn } \siunitx_number_process_scientific_store:nnn -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_1:nnn } #1#2#3 { \tl_if_empty:nTF {#2} @@ -8547,14 +8705,14 @@ This work consists of the file siunitx.dtx {#1} #2 \q_stop {#3} } } -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_1:nw } #1#2#3 \q_stop #4 { \siunitx_number_process_scientific_store:nnn {#1#2} {#3} { #4 - 1 } } -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_2:nnn } #1#2#3 { \tl_if_empty:nTF {#2} @@ -8568,7 +8726,7 @@ This work consists of the file siunitx.dtx {#1} #2 \q_stop {#3} } } -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_2_i:nw } #1#2#3 \q_stop #4 { @@ -8583,7 +8741,7 @@ This work consists of the file siunitx.dtx {#1#2} #3 \q_stop {#4} } } -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_2_ii:nw } #1#2#3 \q_stop #4 { @@ -8603,7 +8761,7 @@ This work consists of the file siunitx.dtx % Sorting out signs consists of two parts: retaining a plus if necessary % and adding an explicit sign. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_sign: { +\cs_new_protected:Npn \siunitx_number_process_sign: { \bool_if:NF \l_siunitx_process_plus_tl { \prop_if_in:NnTF \l_siunitx_number_in_prop { mantissa-sign } @@ -8629,7 +8787,7 @@ This work consists of the file siunitx.dtx % Adding a sign to an existing number needs a couple of to make sure % there is a number to add to, and to see if there is a sign already. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_sign_add:n #1 { +\cs_new_protected:Npn \siunitx_number_process_sign_add:n #1 { \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -sign } { \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -had-sign } @@ -8653,7 +8811,7 @@ This work consists of the file siunitx.dtx % some quick tests and an assignment. Using a pre-defined token list is % a speed-related choice: very slightly faster comparison. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_sign_plus:n #1 { +\cs_new_protected:Npn \siunitx_number_process_sign_plus:n #1 { \prop_get:NnN \l_siunitx_number_in_prop { #1 -sign } \l_siunitx_tmpa_tl \tl_if_eq:NNT \c_siunitx_plus_tl \l_siunitx_tmpa_tl @@ -8674,11 +8832,11 @@ This work consists of the file siunitx.dtx % There may be a need to expand uncertainties into a decimal and integer % part. This is done here so that the core \texttt{in} code is faster. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_uncertainty: { +\cs_new_protected:Npn \siunitx_number_process_uncertainty: { \clist_map_function:nN { mantissa , complex } \siunitx_number_process_uncertainty_aux:n } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_aux:n #1 { \prop_if_in:NnT \l_siunitx_number_in_prop { #1 -uncertainty } { @@ -8696,7 +8854,7 @@ This work consists of the file siunitx.dtx % correctly pad with zeros and also to allow for the possibility that % the error crosses the decimal--integer boundary. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_decimal:n #1 { \siunitx_number_process_uncertainty_count:nn {#1} { decimal } \siunitx_number_process_uncertainty_count:nn {#1} { uncertainty } @@ -8720,7 +8878,7 @@ This work consists of the file siunitx.dtx \prop_put:NnV \l_siunitx_number_in_prop { #1 -uncertainty-decimal-marker } \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_count:nn #1#2 { \prop_get:NnN \l_siunitx_number_in_prop { #1 - #2 } \l_siunitx_tmpa_tl @@ -8733,7 +8891,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_number_process_uncertainty_pad:} % Uncertainty is short: add zeros. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_uncertainty_pad: { +\cs_new_protected:Npn \siunitx_number_process_uncertainty_pad: { \int_while_do:nNnn { \l_siunitx_process_uncertainty_int } < { \l_siunitx_process_decimal_int } @@ -8750,7 +8908,7 @@ This work consists of the file siunitx.dtx %\begin{macro}[aux]{\siunitx_number_process_uncertainty_separate_aux:N} % Find the integer--decimal boundary and work appropriately. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_separate: { \tl_map_function:NN \l_siunitx_tmpa_tl \siunitx_number_process_uncertainty_separate_aux:N @@ -8771,7 +8929,7 @@ This work consists of the file siunitx.dtx % Relatively easy: the uncertainty is in the integer part of the number, % and so there is no need to generate zeros. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_integer:n #1 { \prop_get:NnN \l_siunitx_number_in_prop { #1 -uncertainty } \l_siunitx_tmpa_tl @@ -8789,11 +8947,11 @@ This work consists of the file siunitx.dtx % Checks for adding zeros to each component are carried out. The nesting % here makes checking the appropriate flag a little more efficient. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_process_zero_fill: { +\cs_new_protected:Npn \siunitx_number_process_zero_fill: { \siunitx_number_process_zero_fill_aux:n { integer } \siunitx_number_process_zero_fill_aux:n { decimal } } -\cs_new_nopar:Npn \siunitx_number_process_zero_fill_aux:n #1 { +\cs_new:Npn \siunitx_number_process_zero_fill_aux:n #1 { \bool_if:cT { l_siunitx_process_ #1 _zero_bool } { \siunitx_number_process_zero_fill_aux:nn { mantissa } {#1} @@ -8801,7 +8959,7 @@ This work consists of the file siunitx.dtx \siunitx_number_process_zero_fill_aux:nn { exponent } {#1} } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_zero_fill_aux:nn #1#2 { \prop_if_in:NnT \l_siunitx_number_in_prop { #1 -decimal-marker } { @@ -8813,6 +8971,49 @@ This work consists of the file siunitx.dtx %\end{macro} %\end{macro} % +% \begin{macro}{\siunitx_number_exp_to_prefix:} +% This function is a bit awkward, as it essentially cuts across the +% unit processor. The idea here is first to recover the numerical exponent, +% and sign if there is one. +% \begin{macrocode} +\cs_new_protected:Npn \siunitx_number_exp_to_prefix: + { + \prop_set_eq:NN \l_siunitx_unit_prop \l_siunitx_unit_saved_prop + \prop_get:NnNT \l_siunitx_number_in_prop { exponent-integer } + \l_siunitx_tmpa_tl + { + \prop_get:NnNT \l_siunitx_number_in_prop { exponent-sign } + \l_siunitx_tmpb_tl + { \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_tmpb_tl } + \prop_get:NnNT \l_siunitx_unit_prop { prefix-1 } \l_siunitx_tmpb_tl + { + \prop_del:Nn \l_siunitx_unit_prop { prefix-1 } + \prop_del:Nn \l_siunitx_unit_prop { prefix-symbol-1 } + \prop_get:NVN \l_siunitx_prefix_forward_prop \l_siunitx_tmpb_tl + \l_siunitx_tmpb_tl + \tl_set:Nx \l_siunitx_tmpa_tl + { \int_eval:n { \l_siunitx_tmpa_tl + \l_siunitx_tmpb_tl } } + } + \prop_get:NVNTF \l_siunitx_prefix_reverse_prop \l_siunitx_tmpa_tl + \l_siunitx_tmpb_tl + { + \prop_del:Nn \l_siunitx_number_in_prop { exponent } + \use:c + { + siunitx_ \exp_after:wN \token_to_str:N \l_siunitx_tmpb_tl + _function:w + } + \siunitx_unit_format: + } + { + \msg_error:nnx { siunitx } { non-convertible-exponent } + { \l_siunitx_tmpa_tl } + } + } + } +% \end{macrocode} +% \end{macro} +% %\subsection{Formatting numbers for output} % % Getting numbers ready for printing requires the reconstruction of the @@ -8948,22 +9149,23 @@ This work consists of the file siunitx.dtx tight-spacing .bool_set:N = \l_siunitx_tight_bool, uncertainty-separator .tl_set:N = \l_siunitx_uncert_sep_tl, } -\keys_set:nn { siunitx } { - bracket-numbers = true, % ( - close-bracket = ), - complex-root-position = after-number, - copy-decimal-marker = false, - exponent-base = 10, - exponent-product = \times, - group-digits = true, - group-minimum-digits = 5, - group-separator = \,, - open-bracket = (, % ) ( - output-close-uncertainty = ), - output-complex-root = \mathrm { i }, - output-decimal-marker = ., - output-open-uncertainty = (, % ) -} +\keys_set:nn { siunitx } + { + bracket-numbers = true , % ( + close-bracket = ) , + complex-root-position = after-number , + copy-decimal-marker = false , + exponent-base = 10 , + exponent-product = \times , + group-digits = true , + group-minimum-digits = 5 , + group-separator = \, , + open-bracket = ( , % ) ( + output-close-uncertainty = ) , + output-complex-root = \ensuremath { \mathrm { i } } , + output-decimal-marker = . , + output-open-uncertainty = ( % ) + } % \end{macrocode} %\end{macro} % @@ -8971,7 +9173,7 @@ This work consists of the file siunitx.dtx % The master control function for formatting output: the usual set up. % The number is put back together in stages. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format: { +\cs_new_protected:Npn \siunitx_number_format: { \prop_if_empty:NF \l_siunitx_number_in_prop { \prop_clear:N \l_siunitx_number_out_prop @@ -8993,7 +9195,7 @@ This work consists of the file siunitx.dtx % avoid ambiguity. The function here adds the appropriate tokens % around whatever is in the supplied named store. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_brackets:n #1 { +\cs_new_protected:Npn \siunitx_number_format_brackets:n #1 { \bool_if:NT \l_siunitx_brackets_bool { \prop_if_in:NnT \l_siunitx_number_out_prop { #1 -bracket } @@ -9003,16 +9205,14 @@ This work consists of the file siunitx.dtx } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_brackets_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_format_brackets_aux:n #1 { \prop_get:NnNF \l_siunitx_number_out_prop { #1 -result } \l_siunitx_tmpa_tl { \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl } - \siunitx_tl_put_left_math:NV \l_siunitx_tmpa_tl - \l_siunitx_bracket_open_tl - \siunitx_tl_put_right_math:NV \l_siunitx_tmpa_tl - \l_siunitx_bracket_close_tl + \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_bracket_open_tl + \tl_put_right:NV \l_siunitx_tmpa_tl \l_siunitx_bracket_close_tl \str_if_eq:nnTF {#1} { result } { \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl } { @@ -9028,14 +9228,14 @@ This work consists of the file siunitx.dtx %\begin{macro}[aux]{\siunitx_number_format_color_aux:n} % If the mantissa is negative, then any colour for output might change. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_color: { +\cs_new_protected:Npn \siunitx_number_format_color: { \tl_if_empty:NF \l_siunitx_negative_color_tl { \siunitx_number_format_color_aux:n { mantissa-sign } \siunitx_number_format_color_aux:n { sign } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_color_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_format_color_aux:n #1 { \prop_get:NnNT \l_siunitx_number_in_prop {#1} \l_siunitx_tmpa_tl { \str_if_eq:VnT \l_siunitx_tmpa_tl { - } @@ -9057,7 +9257,7 @@ This work consists of the file siunitx.dtx % The real and complex parts of each number are reassembled, with % brackets if needed. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_complex: { +\cs_new_protected:Npn \siunitx_number_format_complex: { \prop_if_in:NnT \l_siunitx_number_in_prop { complex-root } { \prop_if_in:NnTF \l_siunitx_number_out_prop { complex } @@ -9073,51 +9273,24 @@ This work consists of the file siunitx.dtx } } { - \tl_set:Nx \l_siunitx_tmpa_tl - { - \exp_not:N \siunitx_ensuremath:n - { \exp_not:V \l_siunitx_output_complex_tl } - } \prop_put:NnV \l_siunitx_number_out_prop { complex } - \l_siunitx_tmpa_tl + \l_siunitx_output_complex_tl } \siunitx_number_format_join_complex: } } -\cs_new_protected_nopar:Npn \siunitx_number_format_complex_aux:n #1 { - \siunitx_number_format_complex_aux: - \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl - \bool_if:NTF \l_siunitx_complex_after_bool - { - \siunitx_tl_put_right_math:NV \l_siunitx_tmpb_tl - \l_siunitx_tmpa_tl - } - { - \siunitx_tl_put_left_math:NV \l_siunitx_tmpb_tl - \l_siunitx_tmpa_tl - } - \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl -} -\cs_new_protected_nopar:Npn \siunitx_number_format_complex_aux: { - \tl_set:Nn \l_siunitx_tmpa_tl - { - \use:c - { - siunitx_ \l_siunitx_print_type_tl _ - math \l_siunitx_font_family_tl :n - } - } +\cs_new_protected:Npn \siunitx_number_format_complex_aux:n #1 { \bool_if:NTF \l_siunitx_output_complex_copy_bool { \prop_get:NnN \l_siunitx_number_in_prop { complex-root } - \l_siunitx_tmpb_tl - \tl_put_right:Nx \l_siunitx_tmpa_tl - { { \exp_not:V \l_siunitx_tmpb_tl } } - } - { - \tl_put_right:Nx \l_siunitx_tmpa_tl - { { \exp_not:V \l_siunitx_output_complex_tl } } + \l_siunitx_tmpa_tl } + { \tl_set_eq:NN \l_siunitx_tmpa_tl \l_siunitx_output_complex_tl } + \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl + \bool_if:NTF \l_siunitx_complex_after_bool + { \tl_put_right:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl } + { \tl_put_left:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl } + \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl } % \end{macrocode} %\end{macro} @@ -9129,11 +9302,11 @@ This work consists of the file siunitx.dtx %} % Just copy across. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_copy:n #1 { +\cs_new_protected:Npn \siunitx_number_format_copy:n #1 { \prop_get:NnN \l_siunitx_number_in_prop {#1} \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn \siunitx_number_format_copy:nn #1#2 { +\cs_new_protected:Npn \siunitx_number_format_copy:nn #1#2 { \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop {#2} \l_siunitx_tmpa_tl } @@ -9148,7 +9321,7 @@ This work consists of the file siunitx.dtx % part, which needs to be \enquote{copied} to the standard result % slot. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_final: { +\cs_new_protected:Npn \siunitx_number_format_final: { \prop_if_in:NnT \l_siunitx_number_out_prop { complex } { \prop_if_in:NnF \l_siunitx_number_out_prop { mantissa-result } @@ -9192,7 +9365,7 @@ This work consists of the file siunitx.dtx % \texttt{result-bracket-exponent} indicates that the number needs % brackets due to the exponent part, but not in other cases. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_final_combined: { +\cs_new_protected:Npn \siunitx_number_format_final_combined: { \siunitx_number_format_brackets:n { mantissa } \prop_get:NnN \l_siunitx_number_out_prop { mantissa-result } \l_siunitx_tmpa_tl @@ -9223,7 +9396,7 @@ This work consists of the file siunitx.dtx % front of the number itself. The number must be superscripted, of % course. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_final_exponent: { +\cs_new_protected:Npn \siunitx_number_format_final_exponent: { \prop_get:NnN \l_siunitx_number_out_prop { exponent } \l_siunitx_tmpa_tl \tl_if_empty:NTF \l_siunitx_output_exponent_tl @@ -9248,7 +9421,7 @@ This work consists of the file siunitx.dtx % When there is only an exponent, a check must be made for a % sign in the mantissa part. If there is one, it is copied across. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_format_final_exponent_only: { \prop_get:NnNT \l_siunitx_number_in_prop { mantissa-sign } \l_siunitx_tmpa_tl @@ -9275,7 +9448,7 @@ This work consists of the file siunitx.dtx % Grouping digits only happens if there are no symbols in the input, and % of course if grouping has been requested. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_group:n #1 { +\cs_new_protected:Npn \siunitx_number_format_group:n #1 { \siunitx_number_format_group_aux:nn {#1} { integer } \siunitx_number_format_group_aux:nn {#1} { decimal } \prop_if_in:NnTF \l_siunitx_number_out_prop { #1 -integer } @@ -9290,11 +9463,6 @@ This work consists of the file siunitx.dtx \tl_set_eq:NN \l_siunitx_tmpb_tl \l_siunitx_output_decimal_tl } - \tl_set:Nx \l_siunitx_tmpb_tl - { - \exp_not:N \siunitx_ensuremath:n - { \exp_not:V \l_siunitx_tmpb_tl } - } \tl_put_right:NV \l_siunitx_tmpa_tl \l_siunitx_tmpb_tl \prop_put:NnV \l_siunitx_number_out_prop { #1 -decimal-marker } \l_siunitx_tmpb_tl @@ -9305,7 +9473,7 @@ This work consists of the file siunitx.dtx \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_format_group_aux:nn #1#2 { +\cs_new_protected:Npn \siunitx_number_format_group_aux:nn #1#2 { \prop_if_in:NnT \l_siunitx_number_in_prop { #1 - #2 } { \bool_if:cTF { l_siunitx_group_ #2 _bool } @@ -9320,7 +9488,7 @@ This work consists of the file siunitx.dtx % The idea here is that grouping is only needed for numbers with sufficient % digits: this is done simply by counting up all of the digits. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_group:nn #1#2 +\cs_new_protected:Npn \siunitx_number_format_group:nn #1#2 { \prop_get:NnN \l_siunitx_number_in_prop { #1 - #2 } \l_siunitx_tmpa_tl \int_compare:nNnTF @@ -9340,7 +9508,7 @@ This work consists of the file siunitx.dtx % simple recursion is needed. This trick is taken more or less directly % from \pkg{numprint}. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_group_decimal: { +\cs_new_protected:Npn \siunitx_number_format_group_decimal: { \tl_if_empty:NF \l_siunitx_tmpa_tl { \exp_after:wN \siunitx_number_format_group_decimal_aux:NNNN @@ -9358,8 +9526,7 @@ This work consists of the file siunitx.dtx \tl_put_right:Nn \l_siunitx_tmpb_tl { #1 #2 #3 } \tl_if_empty:nF {#4} { - \siunitx_tl_put_right_math:NV \l_siunitx_tmpb_tl - \l_siunitx_group_sep_tl + \tl_put_right:NV \l_siunitx_tmpb_tl \l_siunitx_group_sep_tl \siunitx_number_format_group_decimal_aux:NNNN #4 } } @@ -9378,7 +9545,7 @@ This work consists of the file siunitx.dtx % By keeping everything on the stack, recursion can occur quite % efficiently here. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_group_integer: { +\cs_new_protected:Npn \siunitx_number_format_group_integer: { \tl_if_empty:NF \l_siunitx_tmpa_tl { \siunitx_number_format_group_integer_setup:V \l_siunitx_tmpa_tl @@ -9418,8 +9585,7 @@ This work consists of the file siunitx.dtx \tl_put_right:Nn \l_siunitx_tmpb_tl {#1#2#3} \quark_if_nil:nF {#4} { - \siunitx_tl_put_right_math:NV \l_siunitx_tmpb_tl - \l_siunitx_group_sep_tl + \tl_put_right:NV \l_siunitx_tmpb_tl \l_siunitx_group_sep_tl \siunitx_number_format_group_integer_aux:NNNN #4 } } @@ -9430,7 +9596,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_number_format_join_complex:} % For adding the complex part to the main part of a number. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_join_complex: { +\cs_new_protected:Npn \siunitx_number_format_join_complex: { \siunitx_number_format_sign_complex: \prop_if_in:NnT \l_siunitx_number_out_prop { mantissa } { @@ -9460,11 +9626,11 @@ This work consists of the file siunitx.dtx %\begin{macro}[aux]{\siunitx_number_format_join_uncert_pm:N} % For adding separated uncertainties to the main part of a number. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_join_uncert: { +\cs_new_protected:Npn \siunitx_number_format_join_uncert: { \siunitx_number_format_join_uncert:n { mantissa } \siunitx_number_format_join_uncert:n { complex } } -\cs_new_protected_nopar:Npn \siunitx_number_format_join_uncert:n #1 { +\cs_new_protected:Npn \siunitx_number_format_join_uncert:n #1 { \prop_get:NnNT \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl { @@ -9482,11 +9648,11 @@ This work consists of the file siunitx.dtx { \siunitx_number_format_copy:nn {#1} { #1 -result } } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_join_uncert_pm:N #1 +\cs_new_protected:Npn \siunitx_number_format_join_uncert_pm:N #1 { \bool_if:NTF \l_siunitx_tight_bool - { \tl_put_left:Nn #1 { \siunitx_ensuremath:n { { \pm } } } } - { \tl_put_left:Nn #1 { \siunitx_ensuremath:n { { } \pm { } } } } + { \tl_put_left:Nn #1 { \ensuremath { { \pm } } } } + { \tl_put_left:Nn #1 { \ensuremath { { } \pm { } } } } } % \end{macrocode} %\end{macro} @@ -9499,7 +9665,7 @@ This work consists of the file siunitx.dtx % uncertainty is separate, it is stored at this stage pending later % re-attachment. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_reassemble: { +\cs_new_protected:Npn \siunitx_number_format_reassemble: { \prop_if_in:NnT \l_siunitx_number_in_prop { mantissa } { \siunitx_number_format_group:n { mantissa } @@ -9520,7 +9686,7 @@ This work consists of the file siunitx.dtx % A simple check and copy operation for a relation: this will still need % to be added to the result, of course. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_relation: { +\cs_new_protected:Npn \siunitx_number_format_relation: { \prop_get:NnNT \l_siunitx_number_in_prop { comparator } \l_siunitx_tmpa_tl { @@ -9550,7 +9716,7 @@ This work consists of the file siunitx.dtx % the right formatting in text mode. For speed reasons, this is done in % a separate function. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_sign:n #1 { +\cs_new_protected:Npn \siunitx_number_format_sign:n #1 { \prop_if_in:NnT \l_siunitx_number_out_prop {#1} { \prop_get:NnNT \l_siunitx_number_in_prop { #1 -sign } @@ -9566,14 +9732,14 @@ This work consists of the file siunitx.dtx } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_sign_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_format_sign_aux:n #1 { \bool_if:NT \l_siunitx_tight_bool { \tl_set:Nx \l_siunitx_tmpa_tl { { \exp_not:V \l_siunitx_tmpa_tl } } } \tl_clear:N \l_siunitx_tmpb_tl - \siunitx_tl_put_left_math:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl + \tl_put_left:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop { #1 -sign } \l_siunitx_tmpb_tl \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl @@ -9587,26 +9753,24 @@ This work consists of the file siunitx.dtx \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_format_sign_negative_brackets:n #1 { \siunitx_number_format_brackets_aux:n {#1} \prop_get:NnNT \l_siunitx_number_out_prop { #1 } \l_siunitx_tmpa_tl { - \siunitx_tl_put_left_math:NV \l_siunitx_tmpa_tl - \l_siunitx_bracket_open_tl - \siunitx_tl_put_right_math:NV \l_siunitx_tmpa_tl - \l_siunitx_bracket_close_tl + \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_bracket_open_tl + \tl_put_right:NV \l_siunitx_tmpa_tl \l_siunitx_bracket_close_tl \prop_put:NnV \l_siunitx_number_out_prop { #1 } \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_format_sign_complex: { +\cs_new_protected:Npn \siunitx_number_format_sign_complex: { \siunitx_number_format_sign_complex:n { complex } \siunitx_number_format_sign_complex:n { complex-result } } -\cs_new_protected_nopar:Npn \siunitx_number_format_sign_complex:n #1 { +\cs_new_protected:Npn \siunitx_number_format_sign_complex:n #1 { \prop_if_in:NnT \l_siunitx_number_out_prop {#1} { \prop_get:NnNT \l_siunitx_number_in_prop { complex-sign } @@ -9625,8 +9789,7 @@ This work consists of the file siunitx.dtx } } \tl_clear:N \l_siunitx_tmpb_tl - \siunitx_tl_put_left_math:NV \l_siunitx_tmpb_tl - \l_siunitx_tmpa_tl + \tl_put_left:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop { complex-sign } \l_siunitx_tmpb_tl \prop_get:NnN \l_siunitx_number_out_prop {#1} @@ -9649,7 +9812,7 @@ This work consists of the file siunitx.dtx % Uncertainty output varies depending on whether there is a need to % separate the error form the number in the output. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_format_uncertainty:n #1 { +\cs_new_protected:Npn \siunitx_number_format_uncertainty:n #1 { \prop_if_in:NnTF \l_siunitx_number_in_prop { #1 -uncertainty } { \bool_if:NTF \l_siunitx_uncert_sep_bool @@ -9659,22 +9822,19 @@ This work consists of the file siunitx.dtx } { \siunitx_number_format_copy:nn {#1} { #1 -result } } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_format_uncertainty_joined:n #1 { \prop_get:NnN \l_siunitx_number_in_prop { #1 -uncertainty } \l_siunitx_tmpa_tl \prop_del:Nn \l_siunitx_number_in_prop { #1 -uncertainty } - \siunitx_tl_put_left_math:NV \l_siunitx_tmpa_tl - \l_siunitx_output_uncert_open_tl - \siunitx_tl_put_left_math:NV \l_siunitx_tmpa_tl - \l_siunitx_uncert_sep_tl - \siunitx_tl_put_right_math:NV \l_siunitx_tmpa_tl - \l_siunitx_output_uncert_close_tl + \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_output_uncert_open_tl + \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_uncert_sep_tl + \tl_put_right:NV \l_siunitx_tmpa_tl \l_siunitx_output_uncert_close_tl \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl \tl_put_right:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_format_uncertainty_sep:n #1 { \prop_if_in:NnT \l_siunitx_number_out_prop { #1 -integer } { @@ -9784,7 +9944,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_number_output_bracket:} % Compound numbers may need brackets adding. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_bracket: { +\cs_new_protected:Npn \siunitx_number_output_bracket: { \bool_if:NF \l_siunitx_error_bool { \bool_if:NT \l_siunitx_number_compound_bool @@ -9798,7 +9958,7 @@ This work consists of the file siunitx.dtx % If a colour needs to be set, it is recovered here and put into the % appropriate place. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_color: { +\cs_new_protected:Npn \siunitx_number_output_color: { \prop_if_in:NnT \l_siunitx_number_out_prop { color } { \prop_get:NnN \l_siunitx_number_out_prop { color } @@ -9836,7 +9996,7 @@ This work consists of the file siunitx.dtx % the units to come at the end of the number, and there then have to % be brackets in the output if there are any separate parts. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_parse_aux: { +\cs_new_protected:Npn \siunitx_number_output_parse_aux: { \siunitx_number_in_parse:V \l_siunitx_number_arg_tl \bool_if:NF \l_siunitx_error_bool { @@ -9867,7 +10027,7 @@ This work consists of the file siunitx.dtx % repeat. That means doing things that have already been done by the % number formatter again. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_parts: { +\cs_new_protected:Npn \siunitx_number_output_parts: { \bool_if:nTF { \tl_if_empty_p:N \l_siunitx_pre_unit_tl && @@ -9876,7 +10036,7 @@ This work consists of the file siunitx.dtx { \siunitx_number_output_single: } { \siunitx_number_output_parts_aux: } } -\cs_new_protected_nopar:Npn \siunitx_number_output_parts_aux: { +\cs_new_protected:Npn \siunitx_number_output_parts_aux: { \bool_if:NTF \l_siunitx_multi_repeat_bool { \prop_if_in:NnT \l_siunitx_number_out_prop { mantissa-result } @@ -9906,24 +10066,18 @@ This work consists of the file siunitx.dtx } { \siunitx_number_output_single: } } -\cs_new_protected_nopar:Npn \siunitx_number_output_parts_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_output_parts_aux:n #1 { \prop_if_in:NnT \l_siunitx_number_out_prop {#1} { \siunitx_number_output_parts_print:n {#1} } \prop_if_in:NnT \l_siunitx_number_out_prop { #1 -uncertainty } - { - \bool_if:NTF \l_siunitx_tight_bool - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { { \pm } } } - } - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { { } \pm { } } } - } + { + \bool_if:NTF \l_siunitx_tight_bool + { \siunitx_print:nn { number } { \ensuremath { { \pm } } } } + { \siunitx_print:nn { number } { \ensuremath { { } \pm { } } } } \siunitx_number_output_parts_print:n { #1 -uncertainty } } } -\cs_new_protected_nopar:Npn \siunitx_number_output_parts_print:n #1 { +\cs_new_protected:Npn \siunitx_number_output_parts_print:n #1 { \siunitx_unit_output_pre_print: \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl \siunitx_print:nV { number } \l_siunitx_tmpa_tl @@ -9939,7 +10093,7 @@ This work consists of the file siunitx.dtx % print everything correctly. The extra group here is necessary % otherwise looping will delete the units entirely! % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_product: { +\cs_new_protected:Npn \siunitx_number_output_product: { \bool_if:NTF \l_siunitx_product_brackets_bool { \bool_if:nTF @@ -9972,10 +10126,9 @@ This work consists of the file siunitx.dtx % When printing products that have to be bracketed, there is a need to % shuffle the units about a bit. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_product_brackets: { +\cs_new_protected:Npn \siunitx_number_output_product_brackets: { \siunitx_unit_output_pre_print: - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_open_tl } } + \siunitx_print:nV { number } \l_siunitx_bracket_open_tl \nobreak \tl_set_eq:NN \l_siunitx_unit_saved_tl \l_siunitx_unit_tl \tl_clear:N \l_siunitx_pre_unit_tl @@ -9983,8 +10136,7 @@ This work consists of the file siunitx.dtx \siunitx_number_output_product_aux: \nobreak \tl_set_eq:NN \l_siunitx_unit_tl \l_siunitx_unit_saved_tl - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_close_tl } } + \siunitx_print:nV { number } \l_siunitx_bracket_close_tl \siunitx_unit_output_print: } % \end{macrocode} @@ -9992,7 +10144,7 @@ This work consists of the file siunitx.dtx %\begin{macro}[aux]{\siunitx_number_output_product_aux:} % Printing the products needs a looping function. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_product_aux: { +\cs_new_protected:Npn \siunitx_number_output_product_aux: { \bool_set_true:N \l_siunitx_number_compound_bool \siunitx_number_preprocess:V \l_siunitx_number_arg_tl \bool_if:NF \l_siunitx_error_bool @@ -10005,17 +10157,11 @@ This work consists of the file siunitx.dtx \bool_if:NTF \l_siunitx_tight_bool { \siunitx_print:nn { number } - { - \siunitx_ensuremath:n - { \l_siunitx_output_product_tl } - } + { \ensuremath { \l_siunitx_output_product_tl } } } { \siunitx_print:nn { number } - { - \siunitx_ensuremath:n - { { } \l_siunitx_output_product_tl { } } - } + { \ensuremath { { } \l_siunitx_output_product_tl { } } } } \siunitx_number_output_parse:V \l_siunitx_number_next_tl } @@ -10027,7 +10173,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_number_output_quotient:} % For quotients, there are two options. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient: { +\cs_new_protected:Npn \siunitx_number_output_quotient: { \use:c { siunitx_number_output_quotient_ \l_siunitx_quotient_mode_tl : } } @@ -10037,7 +10183,7 @@ This work consists of the file siunitx.dtx % For fraction output, there are quite a lot of braces to construct, % unfortunately. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient_fraction: { +\cs_new_protected:Npn \siunitx_number_output_quotient_fraction: { \bool_set_false:N \l_siunitx_number_compound_bool \siunitx_number_output_quotient_aux_i: \tl_set:Nx \l_siunitx_number_out_tl @@ -10059,13 +10205,12 @@ This work consists of the file siunitx.dtx % If a symbol is used for the division, the build process is less % complex. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient_symbol: { +\cs_new_protected:Npn \siunitx_number_output_quotient_symbol: { \bool_set_true:N \l_siunitx_number_compound_bool \siunitx_number_output_quotient_aux_i: \tl_set_eq:NN \l_siunitx_number_out_tl \l_siunitx_number_numerator_tl - \siunitx_tl_put_right_math:NV \l_siunitx_number_out_tl - \l_siunitx_output_quotient_tl + \tl_put_right:NV \l_siunitx_number_out_tl \l_siunitx_output_quotient_tl \tl_put_right:NV \l_siunitx_number_out_tl \l_siunitx_number_denominator_tl \siunitx_number_output_single_aux: @@ -10078,7 +10223,7 @@ This work consists of the file siunitx.dtx %} % The two parts of the number are parsed and formatted. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient_aux_i: { +\cs_new_protected:Npn \siunitx_number_output_quotient_aux_i: { \siunitx_number_in_parse:V \l_siunitx_number_numerator_tl \siunitx_number_output_quotient_aux_ii: \siunitx_number_output_color: @@ -10105,7 +10250,7 @@ This work consists of the file siunitx.dtx \prop_get:NnN \l_siunitx_number_out_prop { result } \l_siunitx_number_denominator_tl } -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient_aux_ii: { +\cs_new_protected:Npn \siunitx_number_output_quotient_aux_ii: { \siunitx_number_process: \siunitx_number_format: } @@ -10121,7 +10266,7 @@ This work consists of the file siunitx.dtx % exponent: if there is, any other parts will already be bracketed and % mathematically there is no need for brackets at this point. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_number_output_single: { +\cs_new_protected:Npn \siunitx_number_output_single: { \bool_if:nF { \tl_if_empty_p:N \l_siunitx_pre_unit_tl && @@ -10136,7 +10281,7 @@ This work consists of the file siunitx.dtx \l_siunitx_number_out_tl \siunitx_number_output_single_aux: } -\cs_new_protected_nopar:Npn \siunitx_number_output_single_aux: { +\cs_new_protected:Npn \siunitx_number_output_single_aux: { \siunitx_unit_output_pre_print: \quark_if_no_value:NTF \l_siunitx_number_out_tl { \tl_clear:N \l_siunitx_number_unit_product_tl } @@ -10264,7 +10409,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_angle_init:} % The usual separation of initial storage resets. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_angle_init: { +\cs_new_protected:Npn \siunitx_angle_init: { \bool_set_false:N \l_siunitx_angle_degree_space_bool \bool_set_false:N \l_siunitx_angle_minute_space_bool \prop_clear:N \l_siunitx_angle_degree_prop @@ -10393,7 +10538,7 @@ This work consists of the file siunitx.dtx % Only the highest-order part of an arc can have a sign. This is checked % now so that the shuffling code is easier to write. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_angle_check_sign: { +\cs_new_protected:Npn \siunitx_angle_check_sign: { \prop_if_empty:NTF \l_siunitx_angle_degree_prop { \prop_if_empty:NF \l_siunitx_angle_minute_prop @@ -10404,7 +10549,7 @@ This work consists of the file siunitx.dtx \siunitx_angle_check_sign_aux:n { second } } } -\cs_new_protected_nopar:Npn \siunitx_angle_check_sign_aux:n #1 { +\cs_new_protected:Npn \siunitx_angle_check_sign_aux:n #1 { \prop_if_in:cnTF { l_siunitx_angle_ #1 _prop } { mantissa-sign } { \msg_error:nn { siunitx } { bad-arc-sign } } @@ -10419,7 +10564,7 @@ This work consists of the file siunitx.dtx % to worry about. There is therefore a shuffle to move them into the % correct places. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_angle_zero_fill: { +\cs_new_protected:Npn \siunitx_angle_zero_fill: { \bool_if:nT { \prop_if_empty_p:N \l_siunitx_angle_second_prop && @@ -10457,11 +10602,11 @@ This work consists of the file siunitx.dtx \siunitx_angle_sign_shuffle:nn { minute } { degree } } } -\cs_new_protected_nopar:Npn \siunitx_angle_sign_shuffle:nn #1#2 { +\cs_new_protected:Npn \siunitx_angle_sign_shuffle:nn #1#2 { \siunitx_angle_sign_shuffle_aux:nnn {#1} {#2} { } \siunitx_angle_sign_shuffle_aux:nnn {#1} {#2} { -deleted } } -\cs_new_protected_nopar:Npn \siunitx_angle_sign_shuffle_aux:nnn +\cs_new_protected:Npn \siunitx_angle_sign_shuffle_aux:nnn #1#2#3 { \prop_get:cnN { l_siunitx_angle_ #1 _prop } { mantissa-sign #3 } \l_siunitx_tmpa_tl @@ -10482,22 +10627,22 @@ This work consists of the file siunitx.dtx % and either does a standard format or calls the special astronomy-style % routine. There may also be some spaces to add. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_angle_print: { +\cs_new_protected:Npn \siunitx_angle_print: { \siunitx_angle_print_aux:nn { degree } { \SIUnitSymbolDegree } \bool_if:NT \l_siunitx_angle_degree_space_bool { \nobreak - \siunitx_ensuremath:n { \l_siunitx_angle_arc_separator_tl } + \l_siunitx_angle_arc_separator_tl } \siunitx_angle_print_aux:nn { minute } { \SIUnitSymbolArcminute } \bool_if:NT \l_siunitx_angle_minute_space_bool { \nobreak - \siunitx_ensuremath:n { \l_siunitx_angle_arc_separator_tl } + \l_siunitx_angle_arc_separator_tl } \siunitx_angle_print_aux:nn { second } { \SIUnitSymbolArcsecond } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_aux:nn #1#2 { +\cs_new_protected:Npn \siunitx_angle_print_aux:nn #1#2 { \prop_if_empty:cF { l_siunitx_angle_ #1 _prop } { \prop_set_eq:Nc \l_siunitx_number_in_prop @@ -10536,20 +10681,19 @@ This work consists of the file siunitx.dtx % added in after superscripts, which otherwise messes up the % calculation. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy: { +\cs_new_protected:Npn \siunitx_angle_print_astronomy: { \prop_if_in:NnTF \l_siunitx_number_in_prop { mantissa-decimal-marker } { \siunitx_angle_print_astronomy_aux: } { \siunitx_number_output_single: } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy_aux: { +\cs_new_protected:Npn \siunitx_angle_print_astronomy_aux: { \prop_get:NnNT \l_siunitx_number_out_prop { mantissa-integer } \l_siunitx_tmpa_tl { \siunitx_print:nV { number } \l_siunitx_tmpa_tl } \hbox_set:Nn \l_siunitx_angle_marker_box { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { { \l_siunitx_output_decimal_tl } } } + \siunitx_print:nn { number } { { \l_siunitx_output_decimal_tl } } } \hbox_set:Nn \l_siunitx_angle_unit_box { @@ -10571,7 +10715,7 @@ This work consists of the file siunitx.dtx \l_siunitx_tmpa_tl { \siunitx_print:nV { number } \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy_aux:n #1 { +\cs_new_protected:Npn \siunitx_angle_print_astronomy_aux:n #1 { \dim_set:cn { l_siunitx_angle_ #1 _dim } { \box_wd:c { l_siunitx_angle_ #1 _box } } \hbox_set_to_wd:cnn { l_siunitx_angle_ #1 _box } { \c_zero_skip } @@ -10581,7 +10725,7 @@ This work consists of the file siunitx.dtx \tex_hss:D } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy_marker: { +\cs_new_protected:Npn \siunitx_angle_print_astronomy_marker: { \hbox_set_to_wd:Nnn \l_siunitx_angle_marker_box { \l_siunitx_angle_marker_dim } { @@ -10591,7 +10735,7 @@ This work consists of the file siunitx.dtx } \box_use:N \l_siunitx_angle_marker_box } -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy_unit: { +\cs_new_protected:Npn \siunitx_angle_print_astronomy_unit: { \hbox_set_to_wd:Nnn \l_siunitx_angle_marker_box { \l_siunitx_angle_unit_dim } { @@ -10616,21 +10760,21 @@ This work consists of the file siunitx.dtx \bool_if:NT \l_siunitx_angle_degree_space_bool { \nobreak - \siunitx_ensuremath:n { \l_siunitx_angle_arc_separator_tl } + \l_siunitx_angle_arc_separator_tl } \siunitx_angle_print_direct_aux:nn {#2} { \SIUnitSymbolArcminute } \bool_if:NT \l_siunitx_angle_minute_space_bool { \nobreak - \siunitx_ensuremath:n { \l_siunitx_angle_arc_separator_tl } + \l_siunitx_angle_arc_separator_tl } \siunitx_angle_print_direct_aux:nn {#3} { \SIUnitSymbolArcsecond } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_direct_aux:nn #1#2 { +\cs_new_protected:Npn \siunitx_angle_print_direct_aux:nn #1#2 { \tl_if_empty:nF {#1} { \tl_set:Nn \l_siunitx_unit_tl {#2} - \siunitx_print:nn { number } { \siunitx_ensuremath:n {#1} } + \siunitx_print:nn { number } { \ensuremath {#1} } \siunitx_unit_output_print: } } @@ -10677,21 +10821,31 @@ This work consists of the file siunitx.dtx % \end{macrocode} %\end{macro} % -%\begin{macro}{\siunitx_declare_prefix:Nnnn} -% Prefixes need to store both the symbol and the power they represent. +% \begin{macro}{\siunitx_declare_prefix:Nnnn} +% \begin{variable} +% {\l_siunitx_prefix_forward_prop, \l_siunitx_prefix_reverse_prop} +% Prefixes need to store both the symbol and the power they represent. +% A reverse system is also set up, to allow powers to be converted to +% prefixes. % \begin{macrocode} -\cs_new_protected:Npn \siunitx_declare_prefix:Nnnn #1#2#3#4 { - \tl_put_right:Nn \l_siunitx_declare_list_tl {#1} - \cs_set:cpn { siunitx_ \token_to_str:N #1 _literal:w } {#2} - \cs_set:cpn { siunitx_ \token_to_str:N #1 _function:w } - { - \bool_if:NTF \l_siunitx_prefix_symbols_bool - { \siunitx_unit_parse_prefix:n {#2} } - { \siunitx_unit_parse_prefix:nn {#3} {#4} } - } -} +\cs_new_protected:Npn \siunitx_declare_prefix:Nnnn #1#2#3#4 + { + \tl_put_right:Nn \l_siunitx_declare_list_tl {#1} + \prop_put:Nnn \l_siunitx_prefix_forward_prop {#1} {#4} + \prop_put:Nnn \l_siunitx_prefix_reverse_prop {#4} {#1} + \cs_set:cpn { siunitx_ \token_to_str:N #1 _literal:w } {#2} + \cs_set:cpn { siunitx_ \token_to_str:N #1 _function:w } + { + \bool_if:NTF \l_siunitx_prefix_symbols_bool + { \siunitx_unit_parse_prefix:Nn #1 {#2} } + { \siunitx_unit_parse_prefix:nn {#3} {#4} } + } + } +\prop_new:N \l_siunitx_prefix_forward_prop +\prop_new:N \l_siunitx_prefix_reverse_prop % \end{macrocode} -%\end{macro} +% \end{variable} +% \end{macro} % %\begin{macro}{\siunitx_declare_qualifier:Nn} % Qualifiers just need storing. @@ -10852,13 +11006,13 @@ This work consists of the file siunitx.dtx % Without this, horrible things happen with \pkg{memoir} and % \pkg{hyperref}. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_create_empty_functions: { +\cs_new_protected:Npn \siunitx_unit_create_empty_functions: { \tl_map_function:NN \l_siunitx_declare_list_tl \siunitx_unit_create_empty_functions_aux:N } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_unit_create_empty_functions_aux:N #1 { - \cs_if_free:NT #1 { \cs_set_protected_nopar:Npn #1 { \ERROR } } + \cs_if_free:NT #1 { \cs_set_protected:Npn #1 { \ERROR } } } % \end{macrocode} %\end{macro} @@ -10867,7 +11021,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_unit_create_functions:} % Creation of macros essentially involves picking up a couple of loops. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_create_functions: { +\cs_new_protected:Npn \siunitx_unit_create_functions: { \bool_if:NT \l_siunitx_create_overwrite_bool { \tl_map_function:NN \l_siunitx_declare_list_tl \cs_undefine:N } \bool_if:NTF \l_siunitx_create_optional_bool @@ -10911,10 +11065,7 @@ This work consists of the file siunitx.dtx \bool_if:NT \l_siunitx_create_prespace_bool { \exp_not:n - { - \siunitx_ensuremath:n - { \l_siunitx_number_unit_product_tl } - } + { \ensuremath { \l_siunitx_number_unit_product_tl } } } \exp_not:n { \siunitx_unit_output:nn {#1} { } } \group_end: @@ -10949,7 +11100,7 @@ This work consists of the file siunitx.dtx { \exp_not:n { - \siunitx_ensuremath:n + \ensuremath { \l_siunitx_number_unit_product_tl } } } @@ -10979,18 +11130,18 @@ This work consists of the file siunitx.dtx \AtBeginDocument { \cs_if_eq:NNT \color \use_none:n { \cs_set_protected:Npn \color #1 { } } - \cs_set_nopar:Npn \siunitx_tmp:w #1 { } + \cs_set:Npn \siunitx_tmp:w #1 { } \cs_if_eq:NNT \color \siunitx_tmp:w { \cs_set_protected:Npn \color #1 { } } \tl_map_function:nN { \bar \color \ng \pm \array@row@rst } \siunitx_protect_symbols:N } \tl_put_right:Nn \document { \siunitx_protect_symbols:N \fg } -\cs_new_protected_nopar:Npn \siunitx_protect_symbols:N #1 { +\cs_new_protected:Npn \siunitx_protect_symbols:N #1 { \cs_if_exist:NT #1 { \siunitx_cs_if_macro:NT #1 - { \cs_set_protected_nopar:Npx #1 { \exp_not:V #1 } } + { \cs_set_protected:Npx #1 { \exp_not:V #1 } } } } % \end{macrocode} @@ -11053,6 +11204,7 @@ This work consists of the file siunitx.dtx \cs_set_eq:NN \siunitx_pm: \pm \siunitx_unit_parse:nn {#1} {#2} \siunitx_unit_format: + \prop_set_eq:NN \l_siunitx_unit_saved_prop \l_siunitx_unit_prop \cs_set_eq:NN \pm \siunitx_pm: } } @@ -11060,7 +11212,7 @@ This work consists of the file siunitx.dtx { \siunitx_unit_format_literal:n {#1} } } \cs_generate_variant:Nn \siunitx_unit_in:nn { V } -\cs_new_nopar:Npn \siunitx_pm: { } +\cs_new:Npn \siunitx_pm: { } % \end{macrocode} %\end{macro} % @@ -11098,17 +11250,20 @@ This work consists of the file siunitx.dtx % input to collect up the units, before re-combining everything into % a single block at the end of the process. % -%\begin{macro}{ -% \l_siunitx_unit_int , -% \l_siunitx_unit_prop -%} -% Parsed units are stored in a property list, to keep things compact. -% An integer is also needed to count up units. +% \begin{variable} +% { +% \l_siunitx_unit_int , +% \l_siunitx_unit_prop , +% \l_siunitx_unit_saved_prop +% } +% Parsed units are stored in a property list, to keep things compact. +% An integer is also needed to count up units. % \begin{macrocode} \int_new:N \l_siunitx_unit_int \prop_new:N \l_siunitx_unit_prop +\prop_new:N \l_siunitx_unit_saved_prop % \end{macrocode} -%\end{macro} +% \end{variable} % %\begin{macro}{\l_siunitx_per_bool} % To allow \cs{per} to be \enquote{sticky}. @@ -11117,22 +11272,24 @@ This work consists of the file siunitx.dtx % \end{macrocode} %\end{macro} % -%\begin{macro}{ -% \l_siunitx_prefix_symbols_bool , -% \l_siunitx_sticky_per_bool -%} -% Some options are directly related to how units are handled at this -% stage, so need be created before the reconstruction part of the code. +% \begin{variable} +% { +% \l_siunitx_exp_to_prefix_bool , +% \l_siunitx_prefix_symbols_bool , +% \l_siunitx_sticky_per_bool +% } +% Some options are directly related to how units are handled at this +% stage, so need be created before the reconstruction part of the code. % \begin{macrocode} -\keys_define:nn { siunitx } { - prefixes-as-symbols .bool_set:N = \l_siunitx_prefix_symbols_bool, - sticky-per .bool_set:N = \l_siunitx_sticky_per_bool, -} -\keys_set:nn { siunitx } { - prefixes-as-symbols = true -} +\keys_define:nn { siunitx } + { + exponent-to-prefix .bool_set:N = \l_siunitx_exp_to_prefix_bool , + prefixes-as-symbols .bool_set:N = \l_siunitx_prefix_symbols_bool , + sticky-per .bool_set:N = \l_siunitx_sticky_per_bool + } +\keys_set:nn { siunitx } { prefixes-as-symbols = true } % \end{macrocode} -%\end{macro} +% \end{variable} % %\begin{macro}{\siunitx_unit_parse:nn} % The unit to be parsed is received here along with any options given. @@ -11153,7 +11310,7 @@ This work consists of the file siunitx.dtx % little clearer. The definition of \cs{pm} is saved here as it % is used by units and numbers. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_parse_init: { +\cs_new_protected:Npn \siunitx_unit_parse_init: { \prop_clear:N \l_siunitx_unit_prop \int_zero:N \l_siunitx_unit_int \bool_set_false:N \l_siunitx_per_bool @@ -11208,24 +11365,29 @@ This work consists of the file siunitx.dtx %\end{macro} % %\begin{macro}{ -% \siunitx_unit_parse_prefix:n , +% \siunitx_unit_parse_prefix:Nn , % \siunitx_unit_parse_prefix:nn %} % Saving prefixes always increments the counter. For non-symbolic % mode, the base needs to be saved along with the power. % \begin{macrocode} -\cs_new_protected:Npn \siunitx_unit_parse_prefix:n #1 { - \int_incr:N \l_siunitx_unit_int - \tl_set:Nx \l_siunitx_tmpa_tl - { prefix- \int_use:N \l_siunitx_unit_int } - \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#1} -} -\cs_new_protected:Npn \siunitx_unit_parse_prefix:nn #1#2 { - \siunitx_unit_parse_prefix:n {#2} - \tl_set:Nx \l_siunitx_tmpa_tl - { prefix-base- \int_use:N \l_siunitx_unit_int } - \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#1} -} +\cs_new_protected:Npn \siunitx_unit_parse_prefix:Nn #1#2 + { + \int_incr:N \l_siunitx_unit_int + \tl_set:Nx \l_siunitx_tmpa_tl + { prefix- \int_use:N \l_siunitx_unit_int } + \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#1} + \tl_set:Nx \l_siunitx_tmpa_tl + { prefix-symbol- \int_use:N \l_siunitx_unit_int } + \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#2} + } +\cs_new_protected:Npn \siunitx_unit_parse_prefix:nn #1#2 + { + \siunitx_unit_parse_prefix:Nn \ERROR {#2} + \tl_set:Nx \l_siunitx_tmpa_tl + { prefix-base- \int_use:N \l_siunitx_unit_int } + \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#1} + } % \end{macrocode} %\end{macro} % @@ -11233,14 +11395,14 @@ This work consists of the file siunitx.dtx % The \cs{per} function always applies to the next unit seen, so % the counter has to be advanced by one. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_parse_per: { +\cs_new_protected:Npn \siunitx_unit_parse_per: { \tl_set:Nx \l_siunitx_tmpa_tl { per- \int_eval:n { \l_siunitx_unit_int + 1 } } \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl { true } \bool_if:NT \l_siunitx_sticky_per_bool { \cs_set_eq:NN \per \siunitx_unit_parse_per_error: } } -\cs_new_protected_nopar:Npn \siunitx_unit_parse_per_error: { +\cs_new_protected:Npn \siunitx_unit_parse_per_error: { \msg_error:nn { siunitx } { duplicate-sticky-per } } % \end{macrocode} @@ -11283,7 +11445,7 @@ This work consists of the file siunitx.dtx % \begin{macrocode} \cs_new_protected:Npn \siunitx_unit_parse_unit:Nn #1#2 { \tl_set:Nx \l_siunitx_tmpa_tl - { prefix- \int_use:N \l_siunitx_unit_int } + { prefix-symbol- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVTF \l_siunitx_unit_prop \l_siunitx_tmpa_tl { \tl_set:Nx \l_siunitx_tmpa_tl @@ -11300,7 +11462,7 @@ This work consists of the file siunitx.dtx \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#2} \siunitx_unit_parse_unit_per: } -\cs_new_protected_nopar:Npn \siunitx_unit_parse_unit_per: { +\cs_new_protected:Npn \siunitx_unit_parse_unit_per: { \bool_if:NT \l_siunitx_sticky_per_bool { \bool_if:NT \l_siunitx_per_bool @@ -11492,7 +11654,7 @@ This work consists of the file siunitx.dtx % symbol. In that special case, the space between a number and a unit % has to be removed. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format: { +\cs_new_protected:Npn \siunitx_unit_format: { \siunitx_unit_format_init: \int_while_do:nNnn { \l_siunitx_unit_int } > { 0 } { @@ -11519,7 +11681,7 @@ This work consists of the file siunitx.dtx % The odd code when adding a space is to pick up repeated per symbols, % which need to suppress the space. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_add: { +\cs_new_protected:Npn \siunitx_unit_format_add: { \bool_if:NTF \l_siunitx_per_two_parts_bool { \tl_set:Nx \l_siunitx_tmpb_tl @@ -11537,7 +11699,7 @@ This work consists of the file siunitx.dtx { \siunitx_unit_format_add_aux:n { } } \tl_clear:N \l_siunitx_unit_current_tl } -\cs_new_protected_nopar:Npn \siunitx_unit_format_add_aux:n #1 { +\cs_new_protected:Npn \siunitx_unit_format_add_aux:n #1 { \tl_if_empty:cF { l_siunitx_unit #1 _tl } { \str_if_eq:VnTF \l_siunitx_per_mode_tl { repeat } @@ -11587,7 +11749,7 @@ This work consists of the file siunitx.dtx % \( 1 \) in the numerator is it's blank. For symbol mode, this is % only done if there is no number. Then some construction work. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction: { +\cs_new_protected:Npn \siunitx_unit_format_fraction: { \int_compare:nNnT { \l_siunitx_unit_numerator_int } = { 0 } { \str_if_eq:VnT \l_siunitx_per_mode_tl { symbol } @@ -11604,7 +11766,7 @@ This work consists of the file siunitx.dtx } { \tl_set_eq:NN \l_siunitx_unit_tl \l_siunitx_unit_numerator_tl } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction_fraction: { +\cs_new_protected:Npn \siunitx_unit_format_fraction_fraction: { \tl_if_empty:NT \l_siunitx_unit_numerator_tl { \tl_set:Nn \l_siunitx_unit_numerator_tl { 1 } } \tl_set:Nx \l_siunitx_unit_numerator_tl @@ -11633,7 +11795,7 @@ This work consists of the file siunitx.dtx % \cs{tex_mathchoice:D}, with appropriate protection, before sending % everything through for printing. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction_auto: { +\cs_new_protected:Npn \siunitx_unit_format_fraction_auto: { \mode_if_math:TF { \group_begin: @@ -11666,26 +11828,23 @@ This work consists of the file siunitx.dtx % For a normal symbol, the two parts of the input are arranged either % side of the symbol itself in math mode. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction_symbol: { +\cs_new_protected:Npn \siunitx_unit_format_fraction_symbol: { \siunitx_unit_format_fraction_symbol_aux: \int_compare:nNnT { \l_siunitx_unit_denominator_int } > { 1 } { \bool_if:NT \l_siunitx_unit_denominator_bracket_bool { - \siunitx_tl_put_left_math:NV \l_siunitx_unit_denominator_tl - \l_siunitx_bracket_open_tl - \siunitx_tl_put_right_math:NV \l_siunitx_unit_denominator_tl - \l_siunitx_bracket_close_tl + \tl_put_left:NV \l_siunitx_unit_denominator_tl \l_siunitx_bracket_open_tl + \tl_put_right:NV \l_siunitx_unit_denominator_tl \l_siunitx_bracket_close_tl } } \tl_set_eq:NN \l_siunitx_unit_tl \l_siunitx_unit_numerator_tl - \siunitx_tl_put_right_math:NV \l_siunitx_unit_tl - \l_siunitx_per_symbol_tl + \tl_put_right:NV \l_siunitx_unit_tl \l_siunitx_per_symbol_tl \tl_put_right:NV \l_siunitx_unit_tl \l_siunitx_unit_denominator_tl } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_unit_format_fraction_symbol_aux: { } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_unit_format_fraction_symbol_aux_alt: { \tl_if_empty:NT \l_siunitx_unit_numerator_tl { \tl_set:Nn \l_siunitx_unit_numerator_tl { 1 } } @@ -11697,7 +11856,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_unit_format_init:} % The normal initialisation stuff. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_init: { +\cs_new_protected:Npn \siunitx_unit_format_init: { \bool_set_false:N \l_siunitx_omit_unit_space_bool \tl_clear:N \l_siunitx_unit_tl \tl_clear:N \l_siunitx_unit_current_tl @@ -11730,10 +11889,7 @@ This work consists of the file siunitx.dtx \siunitx_unit_print_literal_aux:N \tl_set:Nn \l_siunitx_unit_tl {#1} \tl_set:Nx \l_siunitx_tmpa_tl - { - \exp_not:N \siunitx_ensuremath:n - { \exp_not:o \l_siunitx_unit_product_tl } - } + { \exp_not:N \ensuremath { \exp_not:V \l_siunitx_unit_product_tl } } \tl_replace_all:NnV \l_siunitx_unit_tl { . } \l_siunitx_tmpa_tl \tl_replace_all:NnV \l_siunitx_unit_tl { ~ } \l_siunitx_tmpa_tl \bool_if:NT \l_siunitx_literal_power_bool @@ -11759,7 +11915,7 @@ This work consists of the file siunitx.dtx % can appear in units in UTF-8 and related encodings. The idea is to % do a search and replace, thus avoiding any active characters. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_literal_extras: { +\cs_new_protected:Npn \siunitx_unit_format_literal_extras: { \siunitx_unit_format_literal_extras_aux:nN { 176 } \SIUnitSymbolDegree \siunitx_unit_format_literal_extras_aux:nN { 181 } @@ -11767,7 +11923,7 @@ This work consists of the file siunitx.dtx \siunitx_unit_format_literal_extras_aux:nN { 197 } \SIUnitSymbolAngstrom } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_unit_format_literal_extras_aux:nN #1#2 { \char_set_lccode:nn { `\@ } {#1} \tl_to_lowercase:n @@ -11776,27 +11932,25 @@ This work consists of the file siunitx.dtx \l_siunitx_unit_tl } } -\xetex_if_engine:F { - \luatex_if_engine:F - { - \AtBeginDocument - { - \cs_if_exist:NTF \inputencodingname - { - \tl_set:Nn \l_siunitx_tmpa_tl { latin1 , latin5 , latin9 } - \clist_if_in:NVF \l_siunitx_tmpa_tl \inputencodingname - { - \cs_set_eq:NN \siunitx_unit_format_literal_extras: - \scan_stop: - } - } - { - \cs_set_eq:NN \siunitx_unit_format_literal_extras: - \scan_stop: - } - } - } -} +\pdftex_if_engine:T + { + \AtBeginDocument + { + \cs_if_exist:NTF \inputencodingname + { + \tl_set:Nn \l_siunitx_tmpa_tl { latin1 , latin5 , latin9 } + \clist_if_in:NVF \l_siunitx_tmpa_tl \inputencodingname + { + \cs_set_eq:NN \siunitx_unit_format_literal_extras: + \scan_stop: + } + } + { + \cs_set_eq:NN \siunitx_unit_format_literal_extras: + \scan_stop: + } + } + } % \end{macrocode} %\end{macro} %\end{macro} @@ -11815,7 +11969,7 @@ This work consists of the file siunitx.dtx % per symbols make life a little more complex, as they have to be % handled here as well. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_power: { +\cs_new_protected:Npn \siunitx_unit_format_power: { \tl_set:Nx \l_siunitx_tmpa_tl { power- \int_use:N \l_siunitx_unit_int } \prop_get:NVNTF \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -11837,7 +11991,7 @@ This work consists of the file siunitx.dtx % different. A search and replace function is needed for superscripts % in text mode so that negative signs get printed correctly. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_power_aux: { +\cs_new_protected:Npn \siunitx_unit_format_power_aux: { \str_if_eq:VnTF \l_siunitx_per_mode_tl { repeat } { \siunitx_unit_format_power_repeat: } { \siunitx_unit_format_power_per: } @@ -11873,15 +12027,13 @@ This work consists of the file siunitx.dtx % A check is made for a qualifier with a space, which needs brackets % if there is also a power. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_power_brackets: { +\cs_new_protected:Npn \siunitx_unit_format_power_brackets: { \tl_set:Nx \l_siunitx_tmpb_tl { bracket- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVT \l_siunitx_unit_prop \l_siunitx_tmpb_tl { - \siunitx_tl_put_left_math:NV \l_siunitx_unit_current_tl - \l_siunitx_bracket_open_tl - \siunitx_tl_put_right_math:NV \l_siunitx_unit_current_tl - \l_siunitx_bracket_close_tl + \tl_put_left:NV \l_siunitx_unit_current_tl \l_siunitx_bracket_open_tl + \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_bracket_close_tl } } % \end{macrocode} @@ -11889,7 +12041,7 @@ This work consists of the file siunitx.dtx % change does not use any numbers, as this makes life easier with % non-integer values. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_power_per: { +\cs_new_protected:Npn \siunitx_unit_format_power_per: { \tl_set:Nx \l_siunitx_tmpb_tl { per- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVT \l_siunitx_unit_prop \l_siunitx_tmpb_tl @@ -11906,13 +12058,12 @@ This work consists of the file siunitx.dtx } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_power_repeat: { +\cs_new_protected:Npn \siunitx_unit_format_power_repeat: { \tl_set:Nx \l_siunitx_tmpb_tl { per- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVT \l_siunitx_unit_prop \l_siunitx_tmpb_tl { - \siunitx_tl_put_left_math:NV \l_siunitx_unit_current_tl - \l_siunitx_per_symbol_tl + \tl_put_left:NV \l_siunitx_unit_current_tl \l_siunitx_per_symbol_tl } } % \end{macrocode} @@ -11928,9 +12079,9 @@ This work consists of the file siunitx.dtx % If there is a prefix, it is added to the output. When using numerical % output, some conversion is needed instead. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_prefix: { +\cs_new_protected:Npn \siunitx_unit_format_prefix: { \tl_set:Nx \l_siunitx_tmpa_tl - { prefix- \int_use:N \l_siunitx_unit_int } + { prefix-symbol- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVT \l_siunitx_unit_prop \l_siunitx_tmpa_tl { \prop_get:NVN \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -11940,7 +12091,7 @@ This work consists of the file siunitx.dtx { \siunitx_unit_format_prefix_number: } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_prefix_number: { +\cs_new_protected:Npn \siunitx_unit_format_prefix_number: { \tl_set:Nx \l_siunitx_tmpa_tl { prefix-base- \int_use:N \l_siunitx_unit_int } \prop_get:NVN \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -11961,7 +12112,7 @@ This work consists of the file siunitx.dtx % is the kilogram and so there is some code to convert the number % back correctly. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_prefix_number_calc: { +\cs_new_protected:Npn \siunitx_unit_format_prefix_number_calc: { \tl_set:Nx \l_siunitx_tmpa_tl { power- \int_use:N \l_siunitx_unit_int } \prop_get:NVNF \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -12002,7 +12153,7 @@ This work consists of the file siunitx.dtx } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_prefix_symbol: { +\cs_new_protected:Npn \siunitx_unit_format_prefix_symbol: { \tl_set_eq:NN \l_siunitx_unit_current_tl \l_siunitx_unit_prefix_current_tl } @@ -12021,7 +12172,7 @@ This work consists of the file siunitx.dtx % For the \texttt{space} methods, a warning is set in the property list % as if there is a power then some brackets will be needed. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier: { +\cs_new_protected:Npn \siunitx_unit_format_qualifier: { \tl_set:Nx \l_siunitx_tmpa_tl { qualifier- \int_use:N \l_siunitx_unit_int } \prop_get:NVNT \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -12034,15 +12185,13 @@ This work consists of the file siunitx.dtx } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier_brackets: { - \siunitx_tl_put_right_math:NV \l_siunitx_unit_current_tl - \l_siunitx_bracket_open_tl +\cs_new_protected:Npn \siunitx_unit_format_qualifier_brackets: { + \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_bracket_open_tl \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_tmpa_tl - \siunitx_tl_put_right_math:NV \l_siunitx_unit_current_tl - \l_siunitx_bracket_close_tl + \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_bracket_close_tl } \char_set_catcode_active:N \~ -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier_space: { +\cs_new_protected:Npn \siunitx_unit_format_qualifier_space: { \tl_put_right:Nn \l_siunitx_unit_current_tl { \text { ~ } } \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_tmpa_tl \tl_set:Nx \l_siunitx_tmpa_tl @@ -12050,11 +12199,11 @@ This work consists of the file siunitx.dtx \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl { true } } \char_set_catcode_space:N \~ -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier_subscript: { +\cs_new_protected:Npn \siunitx_unit_format_qualifier_subscript: { \tl_put_right:Nx \l_siunitx_unit_current_tl { \exp_not:N \PrintSubscript { \exp_not:V \l_siunitx_tmpa_tl } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier_text: { +\cs_new_protected:Npn \siunitx_unit_format_qualifier_text: { \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_tmpa_tl } % \end{macrocode} @@ -12066,7 +12215,7 @@ This work consists of the file siunitx.dtx % slight issue is making sure that the additional space is included % between the two units, if needed. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_sorted: { +\cs_new_protected:Npn \siunitx_unit_format_sorted: { \tl_set_eq:NN \l_siunitx_unit_tl \l_siunitx_unit_numerator_tl \tl_if_empty:NTF \l_siunitx_unit_tl { @@ -12090,7 +12239,7 @@ This work consists of the file siunitx.dtx % when the code is inside the \cs{si} function (or similar) and there % is only a prefix with nothing else present at all. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_format_symbol: { +\cs_new_protected:Npn \siunitx_unit_format_symbol: { \tl_set:Nx \l_siunitx_tmpa_tl { symbol- \int_use:N \l_siunitx_unit_int } \prop_get:NVNTF \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -12100,13 +12249,14 @@ This work consists of the file siunitx.dtx } { \siunitx_unit_format_symbol_aux: } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_symbol_aux: { +\cs_new_protected:Npn \siunitx_unit_format_symbol_aux: { \msg_error:nn { siunitx } { prefix-only } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_symbol_aux_alt: { +\cs_new_protected:Npn \siunitx_unit_format_symbol_aux_alt: { \int_compare:nNnTF { \l_siunitx_unit_int } = { 1 } { \prop_del:Nn \l_siunitx_unit_prop { prefix-1 } + \prop_del:Nn \l_siunitx_unit_prop { prefix-symbol-1 } \prop_del:Nn \l_siunitx_unit_prop { prefix-base-1 } \prop_if_empty:NF \l_siunitx_unit_prop { \msg_error:nn { siunitx } { prefix-only } } @@ -12263,7 +12413,7 @@ This work consists of the file siunitx.dtx % as in that case omission of the space between a number and unit % depends on the current math style. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_output_number_sep: { +\cs_new_protected:Npn \siunitx_unit_output_number_sep: { \bool_if:NTF \l_siunitx_number_unit_breaks_bool { \penalty \binoppenalty } { \nobreak } \bool_if:NTF \l_siunitx_per_auto_bool @@ -12283,9 +12433,9 @@ This work consists of the file siunitx.dtx } { \siunitx_unit_output_number_sep_aux: } } -\cs_new_protected_nopar:Npn \siunitx_unit_output_number_sep_aux: { +\cs_new_protected:Npn \siunitx_unit_output_number_sep_aux: { \bool_if:NF \l_siunitx_omit_unit_space_bool - { \siunitx_ensuremath:n { \l_siunitx_number_unit_product_tl } } + { \ensuremath { \l_siunitx_number_unit_product_tl } } } % \end{macrocode} %\end{macro} @@ -12296,14 +12446,14 @@ This work consists of the file siunitx.dtx % The printing functions for units do some simple tests then % actually print there output. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_unit_output_pre_print: { +\cs_new_protected:Npn \siunitx_unit_output_pre_print: { \tl_if_empty:NF \l_siunitx_pre_unit_tl { \nobreak \siunitx_print:nV { unit } \l_siunitx_pre_unit_tl } } -\cs_new_protected_nopar:Npn \siunitx_unit_output_print: { +\cs_new_protected:Npn \siunitx_unit_output_print: { \int_compare:nNnF { \l_siunitx_unit_prefix_int } = { 0 } { \tl_set:Nx \l_siunitx_tmpa_tl @@ -12396,7 +12546,7 @@ This work consists of the file siunitx.dtx } { \siunitx_unit_output_pre_print: - \siunitx_print:nn { number } { \siunitx_ensuremath:n {#1} } + \siunitx_print:nn { number } { \ensuremath {#1} } \siunitx_unit_output_print: } } @@ -12475,110 +12625,133 @@ This work consists of the file siunitx.dtx %\end{macro} %\end{macro} % -%\begin{macro}{\l_siunitx_list_separator_tl} -%\begin{macro}{\l_siunitx_list_separator_final_tl} -% Settings for lists. +% \begin{variable} +% { +% \l_siunitx_list_separator_pair_tl , +% \l_siunitx_list_separator_final_tl , +% \l_siunitx_list_separator_tl, +% } +% Settings for lists. % \begin{macrocode} -\keys_define:nn { siunitx } { - list-final-separator .tl_set:N = \l_siunitx_list_separator_final_tl, - list-separator .tl_set:N = \l_siunitx_list_separator_tl, - list-units .choice:, - list-units - / brackets .code:n = - { - \bool_set_true:N \l_siunitx_list_brackets_bool - \bool_set_false:N \l_siunitx_list_repeat_bool - }, - list-units - / repeat .code:n = - { - \bool_set_false:N \l_siunitx_list_brackets_bool - \bool_set_true:N \l_siunitx_list_repeat_bool - }, - list-units - / single .code:n = - { - \bool_set_false:N \l_siunitx_list_brackets_bool - \bool_set_false:N \l_siunitx_list_repeat_bool - }, -} -\keys_set:nn { siunitx } { - list-final-separator = { ~ and ~ }, - list-separator = { , ~ }, - list-units = repeat, +\keys_define:nn { siunitx } + { + list-final-separator .tl_set:N = \l_siunitx_list_separator_final_tl , + list-pair-separator .tl_set:N = \l_siunitx_list_separator_pair_tl , + list-separator .tl_set:N = \l_siunitx_list_separator_tl , + list-units .choice:, + list-units + / brackets .code:n = + { + \bool_set_true:N \l_siunitx_list_brackets_bool + \bool_set_false:N \l_siunitx_list_repeat_bool + }, + list-units + / repeat .code:n = + { + \bool_set_false:N \l_siunitx_list_brackets_bool + \bool_set_true:N \l_siunitx_list_repeat_bool + }, + list-units + / single .code:n = + { + \bool_set_false:N \l_siunitx_list_brackets_bool + \bool_set_false:N \l_siunitx_list_repeat_bool + } + } +\keys_set:nn { siunitx } + { + list-final-separator = { ~ and ~ } , + list-pair-separator = { ~ and ~ } , + list-separator = { , ~ } , + list-units = repeat } % \end{macrocode} -%\end{macro} -%\end{macro} +% \end{variable} % -%\begin{macro}{\siunitx_list_numbers:n} -%\begin{macro}{\siunitx_list_numbers_aux_i:n} -%\begin{macro}{\siunitx_list_numbers_aux_ii:n} -% Lists of numbers are handled in a very simple fashion. The input -% list is traversed, and the items are simply placed on a list for -% output. This uses the internal function \cs{siunitx_number_output:n} -% for speed, but does not make any other optimisation. The output list -% also adds the relevant separators. -% \begin{macrocode} -\cs_new_protected:Npn \siunitx_list_numbers:n #1 { - \tl_clear:N \l_siunitx_unit_tl - \tl_clear:N \l_siunitx_preunit_tl - \siunitx_list_numbers_aux_i:n {#1} -} -\cs_new_protected:Npn \siunitx_list_numbers_aux_i:n #1 { - \tl_clear:N \l_siunitx_list_tl - \tl_clear:N \l_siunitx_list_current_tl - \tl_map_function:nN {#1} \siunitx_list_numbers_aux_ii:n - \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_separator_final_tl - \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_current_tl - \tl_use:N \l_siunitx_list_tl -} -\cs_new_protected:Npn \siunitx_list_numbers_aux_ii:n #1 { - \tl_if_empty:NTF \l_siunitx_list_tl - { \tl_set_eq:NN \l_siunitx_list_tl \l_siunitx_list_current_tl } - { - \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_separator_tl - \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_current_tl - } - \tl_set:Nn \l_siunitx_list_current_tl - { \siunitx_combined_output:n {#1} } -} +% \begin{macro}{\siunitx_list_numbers:n} +% \begin{macro}[aux] +% {\siunitx_list_numbers_aux_i:n, \siunitx_list_numbers_aux_ii:n} +% \begin{macro}{\siunitx_list_numbers_aux:nn} +% Setting up lists is made slightly complicated by the need to handle the +% case of exactly two items and the case of the very last separator +% differently from everything else. Beyond that, there is not too much +% to any of this code. +% \begin{macrocode} +\cs_new_protected:Npn \siunitx_list_numbers:n #1 + { + \tl_clear:N \l_siunitx_unit_tl + \tl_clear:N \l_siunitx_preunit_tl + \siunitx_list_numbers_aux_i:n {#1} + } +\cs_new_protected:Npn \siunitx_list_numbers_aux_i:n #1 + { + \bool_set_true:N \l_siunitx_list_first_bool + \tl_clear:N \l_siunitx_list_current_tl + \int_compare:nNnTF { \tl_length:n {#1} } > \c_two + { + \tl_map_function:nN {#1} \siunitx_list_numbers_aux_ii:n + \l_siunitx_list_tl + \l_siunitx_list_separator_final_tl + \l_siunitx_list_current_tl + } + { + \int_compare:nNnTF { \tl_length:n {#1} } = \c_two + { \siunitx_list_numbers_aux:nn #1 } + { \siunitx_combined_output:n {#1} } + } + \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_separator_final_tl + \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_current_tl + } +\cs_new_protected:Npn \siunitx_list_numbers_aux_ii:n #1 + { + \tl_if_empty:NTF \l_siunitx_list_tl + { \tl_set_eq:NN \l_siunitx_list_tl \l_siunitx_list_current_tl } + { + \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_separator_tl + \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_current_tl + } + \tl_set:Nn \l_siunitx_list_current_tl { \siunitx_combined_output:n {#1} } + } +\cs_new_protected:Npn \siunitx_list_numbers_aux:nn #1#2 + { + \siunitx_combined_output:n {#1} + \l_siunitx_list_separator_pair_tl + \siunitx_combined_output:n {#2} + } % \end{macrocode} -%\end{macro} -%\end{macro} -%\end{macro} +% \end{macro} +% \end{macro} +% \end{macro} % -%\begin{macro}{\siunitx_list_units:nnn} -% For a list of items with units, the method is to first parse the -% unit when repeating (to save time), then to use the number loop above -% for the actual work. On the other hand, when the unit is only printed -% once life is easier as the normal unit printer can operate. +% \begin{macro}{\siunitx_list_units:nnn} +% For a list of items with units, the method is to first parse the +% unit when repeating (to save time), then to use the number loop above +% for the actual work. On the other hand, when the unit is only printed +% once life is easier as the normal unit printer can operate. % \begin{macrocode} -\cs_new_protected:Npn \siunitx_list_units:nnn #1#2#3 { - \siunitx_unit_parse_options:nn {#2} {#3} - \bool_if:NTF \l_siunitx_list_repeat_bool - { - \siunitx_unit_in:nn {#2} {#3} - \siunitx_list_numbers_aux_i:n {#1} - } - { - \bool_if:NT \l_siunitx_list_brackets_bool - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_open_tl } } - } - \siunitx_list_numbers:n {#1} - \bool_if:NT \l_siunitx_list_brackets_bool - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_close_tl } } - } - \siunitx_unit_output_number_sep: - \siunitx_unit_output:nn {#2} {#3} - } -} +\cs_new_protected:Npn \siunitx_list_units:nnn #1#2#3 + { + \siunitx_unit_parse_options:nn {#2} {#3} + \bool_if:NTF \l_siunitx_list_repeat_bool + { + \siunitx_unit_in:nn {#2} {#3} + \siunitx_list_numbers_aux_i:n {#1} + } + { + \bool_if:NT \l_siunitx_process_fixed_bool + { \bool_set_true:N \l_siunitx_process_drop_exponent_bool } + \bool_if:NT \l_siunitx_list_brackets_bool + { \siunitx_print:nV { number } \l_siunitx_bracket_open_tl } + \siunitx_list_numbers:n {#1} + \bool_if:NT \l_siunitx_list_brackets_bool + { \siunitx_print:nV { number } \l_siunitx_bracket_close_tl } + \siunitx_range_exponent: + \siunitx_unit_output_number_sep: + \siunitx_unit_output:nn {#2} {#3} + } + } % \end{macrocode} -%\end{macro} +% \end{macro} % %\subsection{Ranges} % @@ -12624,38 +12797,42 @@ This work consists of the file siunitx.dtx % \end{macrocode} %\end{macro} % -%\begin{macro}{\siunitx_range_numbers:nn} -%\begin{macro}{\siunitx_range_numbers_aux:n} -% A range of numbers. This is more restrictive than the \cs{num} -% function: nothing compound. +% \begin{macro}{\siunitx_range_numbers:nn} +% \begin{macro}[aux]{\siunitx_range_numbers_core:nn} +% \begin{macro}[aux]{\siunitx_range_numbers_aux:n} +% A range of numbers. This is more restrictive than the \cs{num} +% function: nothing compound. % \begin{macrocode} -\cs_new_protected:Npn \siunitx_range_numbers:nn #1#2 { - \siunitx_range_numbers_aux:n {#1} - \l_siunitx_range_phrase_tl - \siunitx_range_numbers_aux:n {#2} -} -\cs_new_protected:Npn \siunitx_range_numbers_aux:n #1 { - \bool_if:NTF \l_siunitx_number_parse_bool - { - \tl_clear:N \l_siunitx_number_out_tl - \tl_clear:N \l_siunitx_number_out_saved_tl - \bool_set_false:N \l_siunitx_number_compound_bool - \siunitx_number_output_parse:n {#1} - \bool_if:NT \l_siunitx_number_compound_bool - { \msg_error:nnx { siunitx } { multi-part-range } {#1} } - } - { - \siunitx_unit_output_pre_print: - \siunitx_print:nn { number } {#1} - \siunitx_unit_output_print: - } -} +\cs_new_protected:Npn \siunitx_range_numbers:nn #1#2 + { + \siunitx_range_numbers_aux:n {#1} + \l_siunitx_range_phrase_tl + \siunitx_range_numbers_aux:n {#2} + } +\cs_new_protected:Npn \siunitx_range_numbers_aux:n #1 + { + \bool_if:NTF \l_siunitx_number_parse_bool + { + \tl_clear:N \l_siunitx_number_out_tl + \tl_clear:N \l_siunitx_number_out_saved_tl + \bool_set_false:N \l_siunitx_number_compound_bool + \siunitx_number_output_parse:n {#1} + \bool_if:NT \l_siunitx_number_compound_bool + { \msg_error:nnx { siunitx } { multi-part-range } {#1} } + } + { + \siunitx_unit_output_pre_print: + \siunitx_print:nn { number } {#1} + \siunitx_unit_output_print: + } + } % \end{macrocode} -%\end{macro} -%\end{macro} +% \end{macro} +% \end{macro} +% \end{macro} % %\begin{macro}{\siunitx_range_unit:nnnn} -% Unit printing is also simple: basically a past-up job. +% Unit printing is also simple: basically a past-up job. The only compl % \begin{macrocode} \cs_new_protected:Npn \siunitx_range_unit:nnnn #1#2#3#4 { \siunitx_unit_parse_options:nn {#1} {#2} @@ -12667,17 +12844,14 @@ This work consists of the file siunitx.dtx \siunitx_range_numbers_aux:n {#4} } { + \bool_if:NT \l_siunitx_process_fixed_bool + { \bool_set_true:N \l_siunitx_process_drop_exponent_bool } \bool_if:NT \l_siunitx_range_brackets_bool - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_open_tl } } - } + { \siunitx_print:nV { number } \l_siunitx_bracket_open_tl } \siunitx_range_numbers:nn {#3} {#4} \bool_if:NT \l_siunitx_range_brackets_bool - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_close_tl } } - } + { \siunitx_print:nV { number } \l_siunitx_bracket_close_tl } + \siunitx_range_exponent: \siunitx_unit_output_number_sep: \siunitx_unit_output:nn {#1} {#2} } @@ -12685,6 +12859,30 @@ This work consists of the file siunitx.dtx % \end{macrocode} %\end{macro} % +% \begin{macro}{\siunitx_range_exponent:} +% The idea here is to construct and print an exponent if this is fixed, +% and thus removed from the range. This function is also used by the +% related list concept. +% \begin{macrocode} +\cs_new_protected:Npn \siunitx_range_exponent: + { + \bool_if:NT \l_siunitx_process_fixed_bool + { + \tl_set_eq:NN \l_siunitx_tmpa_tl \l_siunitx_exponent_product_tl + \bool_if:NT \l_siunitx_tight_bool + { \tl_set:Nx \l_siunitx_tmpa_tl { { \exp_not:o \l_siunitx_tmpa_tl } } } + \tl_set:Nx \l_siunitx_tmpa_tl + { + \exp_not:N \ensuremath { { } \exp_not:o \l_siunitx_tmpa_tl { } } + 10 \exp_not:N \PrintSuperscript + { \int_use:N \l_siunitx_process_fixed_int } + } + \siunitx_print:nV { number } \l_siunitx_tmpa_tl + } + } +% \end{macrocode} +% \end{macro} +% %\subsection{Setting up tables} % % There is a slight problem with the \pkg{cellspace} package: it also @@ -12718,9 +12916,9 @@ This work consists of the file siunitx.dtx % arguments do not work correctly. So they are added \enquote{by hand} % to the appropriate macro. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_rewrite_create:N #1 { +\cs_new_protected:Npn \siunitx_table_rewrite_create:N #1 { \newcolumntype {#1} { } - \cs_set_protected_nopar:Npn + \cs_set_protected:Npn \siunitx_table_rewrite_create_aux:w \NC@do ##1##2 \NC@do #1 { \NC@list { \NC@do ##1 \NC@do #1 ##2 } } \exp_after:wN \siunitx_table_rewrite_create_aux:w \tex_the:D \NC@list @@ -12736,7 +12934,7 @@ This work consists of the file siunitx.dtx \NC@find } } -\cs_new_protected_nopar:Npn \siunitx_table_rewrite_create_aux:w { } +\cs_new_protected:Npn \siunitx_table_rewrite_create_aux:w { } \AtBeginDocument { \siunitx_table_rewrite_create:N s } \AtBeginDocument { \siunitx_table_rewrite_create:N S } % \end{macrocode} @@ -12802,14 +13000,14 @@ This work consists of the file siunitx.dtx \keys_set:nn { siunitx } {#2} \use:c { siunitx_table_collect_begin_ #1 : } } -\cs_new_protected_nopar:Npn \siunitx_table_collect_begin_s: { +\cs_new_protected:Npn \siunitx_table_collect_begin_s: { \cs_set_eq:NN \siunitx_table_collect_token:N \siunitx_table_collect_token_s:N \cs_set_eq:NN \siunitx_table_print: \siunitx_table_print_s: \siunitx_table_collect_init_s: \siunitx_table_collect_get: } -\cs_new_protected_nopar:Npn \siunitx_table_collect_begin_S: { +\cs_new_protected:Npn \siunitx_table_collect_begin_S: { \cs_set_eq:NN \siunitx_table_collect_token:N \siunitx_table_collect_token_S:N \cs_set_eq:NN \siunitx_table_print: \siunitx_table_print_S: @@ -12859,7 +13057,7 @@ This work consists of the file siunitx.dtx { \tl_use:N \l_siunitx_table_collect_pre_tl \tl_clear:N \l_siunitx_table_collect_pre_tl - \cs_set_nopar:Npn \siunitx_table_collect_next: + \cs_set:Npn \siunitx_table_collect_next: { \exp_after:wN \siunitx_table_collect_get: #1 } } { @@ -12910,10 +13108,10 @@ This work consists of the file siunitx.dtx % broken with \pkg{expl3}'s \cs{peek_catcode_ignore_spaces:NTF}, so % everything is done by hand. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_collect_get: { +\cs_new_protected:Npn \siunitx_table_collect_get: { \cs_set_eq:NN \siunitx_table_collect_next: \siunitx_table_collect_get: - \cs_set_nopar:Npn \peek_execute_branches: + \cs_set:Npn \peek_execute_branches: { \if_catcode:w \exp_not:N \l_peek_token \c_group_begin_token \exp_after:wN \siunitx_table_collect_braced:n @@ -12930,7 +13128,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_table_collect_init:} % The usual spin-out of basics. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_collect_init: { +\cs_new_protected:Npn \siunitx_table_collect_init: { \tl_clear:N \l_siunitx_table_collect_tl \tl_clear:N \l_siunitx_table_collect_pre_tl \tl_clear:N \l_siunitx_table_collect_post_tl @@ -12945,7 +13143,7 @@ This work consists of the file siunitx.dtx % initialisation function for numbers is used to set % \cs{l_siunitx_number_valid_tl} correctly. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_collect_init_s: { +\cs_new_protected:Npn \siunitx_table_collect_init_s: { \siunitx_table_collect_init: \bool_set_false:N \l_siunitx_table_collect_pre_bool \cs_set_protected:Npn \siunitx_table_collect_braced:n ##1 @@ -12954,7 +13152,7 @@ This work consists of the file siunitx.dtx \siunitx_table_collect_next: } } -\cs_new_protected_nopar:Npn \siunitx_table_collect_init_S: { +\cs_new_protected:Npn \siunitx_table_collect_init_S: { \siunitx_number_in_init: \tl_set:Nx \l_siunitx_number_valid_tl { @@ -12988,7 +13186,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_table_collect_next:} % A holder for the next thing to do. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_collect_next: { } +\cs_new_protected:Npn \siunitx_table_collect_next: { } % \end{macrocode} %\end{macro} % @@ -12999,7 +13197,7 @@ This work consists of the file siunitx.dtx % definition of \cs{siunitx_table_print:}, as it will re-appear on its % own. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_collect_newline: { +\cs_new_protected:Npn \siunitx_table_collect_newline: { \siunitx_table_print: \cs_set_eq:NN \siunitx_table_print: \prg_do_nothing: \tabularnewline @@ -13010,7 +13208,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\siunitx_table_collect_end:} % The same concept applies to the \cs{end} macro. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_collect_end: { +\cs_new_protected:Npn \siunitx_table_collect_end: { \siunitx_table_print: \cs_set_eq:NN \siunitx_table_print: \prg_do_nothing: \end @@ -13137,13 +13335,13 @@ This work consists of the file siunitx.dtx { \@ifpackageloaded { colortbl } { - \cs_new_protected_nopar:Npn \siunitx_table_colortbl_correction: + \cs_new_protected:Npn \siunitx_table_colortbl_correction: { \skip_horizontal:n { \c_zero_skip plus -0.5 fill } \tex_kern:D \c_zero_skip } } - { \cs_new_protected_nopar:Npn \siunitx_table_colortbl_correction: { } } + { \cs_new_protected:Npn \siunitx_table_colortbl_correction: { } } } % \end{macrocode} % \end{macro} @@ -13155,13 +13353,13 @@ This work consists of the file siunitx.dtx % horizontal skip. The correction for \pkg{colortbl} is separate as the % spacing needs to be explicitly deleted. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_align_left:n #1 +\cs_new_protected:Npn \siunitx_table_align_left:n #1 { \siunitx_table_colortbl_correction: \skip_horizontal:n {#1} \tex_kern:D \c_zero_skip } -\cs_new_protected_nopar:Npn \siunitx_table_align_right:n #1 +\cs_new_protected:Npn \siunitx_table_align_right:n #1 { \skip_horizontal:n { \c_siunitx_one_fill_skip - #1 } \tex_kern:D \c_zero_skip @@ -13197,7 +13395,7 @@ This work consists of the file siunitx.dtx \siunitx_table_align_right:n } { - \cs_set_protected_nopar:Npn \siunitx_table_column_begin:n ##1 + \cs_set_protected:Npn \siunitx_table_column_begin:n ##1 { \siunitx_table_colortbl_correction: \tex_hbox:D to \dim_eval:n {#1} @@ -13205,7 +13403,7 @@ This work consists of the file siunitx.dtx \skip_horizontal:n {##1} \tex_kern:D \c_zero_skip } - \cs_set_protected_nopar:Npn \siunitx_table_column_end:n ##1 + \cs_set_protected:Npn \siunitx_table_column_end:n ##1 { \skip_horizontal:n { \c_siunitx_one_fill_skip - ##1 } \tex_kern:D \c_zero_skip @@ -13259,7 +13457,7 @@ This work consists of the file siunitx.dtx % some spacing to do at each side, with the main part of the job being % to print the material using the internal version of \cs{si}. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_s: +\cs_new_protected:Npn \siunitx_table_print_s: { \siunitx_table_column_begin:n { \l_siunitx_table_unit_align_skip } \siunitx_unit_output:Vn \l_siunitx_table_collect_tl { } @@ -13355,33 +13553,31 @@ This work consists of the file siunitx.dtx % \begin{macro} % { % \siunitx_table_print_S_direct_main: , -% \siunitx_table_print_S_main: , -% \siunitx_table_print_S_parsed: , -% \siunitx_table_print_S_pre: , -% \siunitx_table_print_S_post: , -% \siunitx_table_print_S_reserved_exponent_aux: , -% \siunitx_table_print_S_reserved_mantissa_uncert_aux: , -% \siunitx_table_print_S_reserved_round: +% \siunitx_table_print_S_parsed: % } % \begin{macro}{\siunitx_table_print_S_reserved_store_fill:n} % Various functions which are set up by the option system, and so are % reserved here first for completeness. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_main: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_main: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_parsed: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_pre: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_post: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_exponent_aux: { } -\cs_new_protected_nopar:Npn - \siunitx_table_print_S_reserved_mantissa_uncert_aux: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_round: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_store_fill:n #1 { } +\cs_new_protected:Npn \siunitx_table_print_S_direct_main: { } +\cs_new_protected:Npn \siunitx_table_print_S_parsed: { } +\cs_new_protected:Npn \siunitx_table_print_S_reserved_store_fill:n #1 { } % \end{macrocode} % \end{macro} % \end{macro} % -% \begin{variable}{\l_siunitx_table_pre_tl, \l_siunitx_table_post_tl} +% \begin{variable} +% { +% \l_siunitx_table_align_exponent_bool, +% \l_siunitx_table_align_text_pre_bool, +% \l_siunitx_table_align_text_post_bool, +% \l_siunitx_table_align_uncert_bool, +% \l_siunitx_table_auto_round_bool, +% \l_siunitx_table_omit_exponent_bool, +% \l_siunitx_table_parse_only_bool, +% \l_siunitx_table_pre_tl, +% \l_siunitx_table_post_tl +% } % \begin{macrocode} \keys_define:nn { siunitx } { @@ -13399,73 +13595,14 @@ This work consists of the file siunitx.dtx \siunitx_table_print_S_reserved_store_fill_mid:n }, table-align-comparator .default:n = true, - table-align-exponent .choice:, - table-align-exponent / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_exponent_aux: - \siunitx_table_print_S_reserved_exponent_not_aligned: - }, - table-align-exponent / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_exponent_aux: - \siunitx_table_print_S_reserved_exponent_aligned: - }, - table-align-exponent .default:n = true, - table-align-text-pre .choice:, - table-align-text-pre / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_pre: - \siunitx_table_print_S_pre_not_aligned: - }, - table-align-text-pre / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_pre: - \siunitx_table_print_S_pre_aligned: - }, - table-align-text-pre .default:n = true , - table-align-text-post .choice:, - table-align-text-post / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_post: - \siunitx_table_print_S_post_not_aligned: - }, - table-align-text-post / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_post: - \siunitx_table_print_S_post_aligned: - }, - table-align-text-post .default:n = true , - table-align-uncertainty .choice:, - table-align-uncertainty / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_mantissa_uncert_aux: - \siunitx_table_print_S_reserved_mantissa_uncert_not_aligned: - }, - table-align-uncertainty / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_mantissa_uncert_aux: - \siunitx_table_print_S_reserved_mantissa_uncert_aligned: - }, - table-align-uncertainty .default:n = true, - table-auto-round .choice:, - table-auto-round / - false .code:n = - { \cs_set_eq:NN \prg_do_nothing: }, - table-auto-round / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_round: - \siunitx_table_print_S_reserved_round_auto: - }, - table-auto-round .default:n = true, + table-align-exponent .bool_set:N = + \l_siunitx_table_align_exponent_bool, + table-align-text-pre .bool_set:N = + \l_siunitx_table_align_text_pre_bool, + table-align-text-post .bool_set:N = + \l_siunitx_table_align_text_post_bool, + table-align-uncertainty .bool_set:N = \l_siunitx_table_align_uncert_bool, + table-auto-round .bool_set:N = \l_siunitx_table_auto_round_bool, table-number-alignment .choice:, table-number-alignment / center .code:n = @@ -13506,20 +13643,8 @@ This work consists of the file siunitx.dtx \cs_set_eq:NN \siunitx_table_print_S_parsed: \siunitx_table_print_S_reserved: }, - table-omit-exponent .choice:, - table-omit-exponent / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_parse_aux: - \siunitx_number_process: - }, - table-omit-exponent / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_parse_aux: - \siunitx_table_print_S_parse_omit_exp: - }, - table-omit-exponent .default:n = true, + table-omit-exponent .bool_set:N = + \l_siunitx_table_omit_exponent_bool, table-text-alignment .choice:, table-text-alignment / center .code:n = @@ -13606,20 +13731,7 @@ This work consists of the file siunitx.dtx { \prg_replicate:nn {#1} { 8 } } } }, - table-parse-only .choice: , - table-parse-only / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_main: - \siunitx_table_print_S_alignment: - }, - table-parse-only / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_main: - \siunitx_table_print_S_no_alignment: - }, - table-parse-only .default:n = true, + table-parse-only .bool_set:N = \l_siunitx_table_parse_only_bool, table-space-text-pre .tl_set:N = \l_siunitx_table_pre_tl, table-space-text-post .tl_set:N = \l_siunitx_table_post_tl, table-sign-exponent .code:n = @@ -13690,7 +13802,7 @@ This work consists of the file siunitx.dtx % insert. Font detection for the \texttt{S} column is included here as % this is needed to do this work outside of an \cs{hbox}. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S: +\cs_new_protected:Npn \siunitx_table_print_S: { \bool_if:NTF \l_siunitx_table_collect_pre_bool { @@ -13701,10 +13813,16 @@ This work consists of the file siunitx.dtx { \siunitx_table_column_begin:n { \l_siunitx_table_number_align_skip } \siunitx_detect_font: - \siunitx_table_print_S_main: - \siunitx_table_print_S_pre: + \bool_if:NTF \l_siunitx_table_parse_only_bool + { \siunitx_table_print_S_no_alignment: } + { \siunitx_table_print_S_alignment: } + \bool_if:NTF \l_siunitx_table_align_text_pre_bool + { \siunitx_table_print_S_pre_aligned: } + { \siunitx_table_print_S_pre_not_aligned: } \box_use:N \l_siunitx_table_result_box - \siunitx_table_print_S_post: + \bool_if:NTF \l_siunitx_table_align_text_post_bool + { \siunitx_table_print_S_post_aligned: } + { \siunitx_table_print_S_post_not_aligned: } \siunitx_table_column_end:n { \l_siunitx_table_number_align_skip } } } @@ -13715,7 +13833,7 @@ This work consists of the file siunitx.dtx % With no alignment to do, the code can be pretty simple. The collected % number is simply printed between the two non-numerical parts. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_no_alignment: +\cs_new_protected:Npn \siunitx_table_print_S_no_alignment: { \l_siunitx_table_collect_pre_tl \siunitx_number_output:V \l_siunitx_table_collect_tl @@ -13728,43 +13846,41 @@ This work consists of the file siunitx.dtx % This is a pass-through, so that the appropriate alignment mode is % retained without needing to retest on each use. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_alignment: +\cs_new_protected:Npn \siunitx_table_print_S_alignment: { \siunitx_table_print_S_parsed: } % \end{macrocode} % \end{macro} % % \begin{macro}{\siunitx_table_print_S_parse:} -% \begin{macro}[aux]{\siunitx_table_print_S_parse_omit_exp:} % A modified version of the number parser for tables. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_parse: +\cs_new_protected:Npn \siunitx_table_print_S_parse: { \bool_set_false:N \l_siunitx_error_bool \siunitx_number_in_parse:V \l_siunitx_table_collect_tl \bool_if:NF \l_siunitx_error_bool { - \siunitx_table_print_S_parse_aux: + \bool_if:NTF \l_siunitx_table_omit_exponent_bool + { + \bool_set_true:N \l_siunitx_process_fixed_bool + \siunitx_number_process: + \prop_del:Nn \l_siunitx_number_in_prop { exponent } + \prop_del:Nn \l_siunitx_number_in_prop { exponent-integer } + } + { \siunitx_number_process: } \siunitx_number_format: \siunitx_number_output_color: } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_parse_omit_exp: - { - \bool_set_true:N \l_siunitx_process_fixed_bool - \siunitx_number_process: - \prop_del:Nn \l_siunitx_number_in_prop { exponent } - \prop_del:Nn \l_siunitx_number_in_prop { exponent-integer } -} % \end{macrocode} % \end{macro} -% \end{macro} % % \begin{macro}{\siunitx_table_print_S_measure:NN} % A short routine to measure up whatever has been extracted from the % storage system. Boxing up is avoided for the empty cases, as this saves % a little time(the print routine is relatively slow). % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_measure:NN #1#2 +\cs_new_protected:Npn \siunitx_table_print_S_measure:NN #1#2 { \tl_if_empty:NTF #1 { \dim_zero:N #2 } @@ -13773,7 +13889,7 @@ This work consists of the file siunitx.dtx \hbox_set:Nn \l_siunitx_tmp_box { \siunitx_print:nV { number } #1 } \exp_args:NNNo \group_end: - \dim_set:Nn #2 { \tex_the:D \box_wd:N \l_siunitx_tmp_box } + \dim_set:Nn #2 { \dim_use:N \box_wd:N \l_siunitx_tmp_box } } } % \end{macrocode} @@ -13790,22 +13906,22 @@ This work consists of the file siunitx.dtx % to maintain alignment. The order in which the two are inserted depends % on whether those parts are also aligned. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_pre_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_pre_aligned: { \box_use:N \l_siunitx_table_pre_box \hbox_to_wd:nn { \l_siunitx_table_fill_pre_dim } { \tex_hfil:D } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_pre_not_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_pre_not_aligned: { \hbox_to_wd:nn { \l_siunitx_table_fill_pre_dim } { \tex_hfil:D } \box_use:N \l_siunitx_table_pre_box } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_post_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_post_aligned: { \hbox_to_wd:nn { \l_siunitx_table_fill_post_dim } { \tex_hfil:D } \box_use:N \l_siunitx_table_post_box } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_post_not_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_post_not_aligned: { \box_use:N \l_siunitx_table_post_box \hbox_to_wd:nn { \l_siunitx_table_fill_post_dim } { \tex_hfil:D } @@ -13821,7 +13937,7 @@ This work consists of the file siunitx.dtx % out which part is bigger and calculates the fill correction accordingly. % Once all of that is done, the various boxes and fill can be inserted. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered: +\cs_new_protected:Npn \siunitx_table_print_S_centered: { \siunitx_table_print_S_centered_ends: \bool_if:NT \l_siunitx_table_math_bool { \c_math_toggle_token } @@ -13854,7 +13970,7 @@ This work consists of the file siunitx.dtx % to the colour, font or so forth. After that, the narrower of the two % boxes is made the same size as the wider: this maintains the alignment. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_ends: +\cs_new_protected:Npn \siunitx_table_print_S_centered_ends: { \hbox_set:Nn \l_siunitx_table_pre_box { @@ -13913,13 +14029,13 @@ This work consists of the file siunitx.dtx % the decimal marker and the entire number. Most of the work consists % of collecting up parts of the number. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_measure: +\cs_new_protected:Npn \siunitx_table_print_S_centered_measure: { \siunitx_table_print_S_centered_measure_int_part: \siunitx_table_print_S_centered_measure_marker: \siunitx_table_print_S_centered_measure_result: } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_measure_int_part: +\cs_new_protected:Npn \siunitx_table_print_S_centered_measure_int_part: { \prop_get:NnNF \l_siunitx_number_out_prop { comparator } \l_siunitx_tmpa_tl { \tl_clear:N \l_siunitx_tmpa_tl } @@ -13932,21 +14048,16 @@ This work consists of the file siunitx.dtx \siunitx_table_print_S_measure:NN \l_siunitx_tmpa_tl \l_siunitx_table_integer_dim } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_measure_marker: +\cs_new_protected:Npn \siunitx_table_print_S_centered_measure_marker: { - \tl_set:Nx \l_siunitx_tmpa_tl - { - \exp_not:N \siunitx_ensuremath:n - { \exp_not:o \l_siunitx_output_decimal_tl } - } - \siunitx_table_print_S_measure:NN \l_siunitx_tmpa_tl + \siunitx_table_print_S_measure:NN \l_siunitx_output_decimal_tl \l_siunitx_table_marker_dim } % \end{macrocode} % As the overall result will be needed later, the boxing up here is done % using a named box that will be retained. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_measure_result: +\cs_new_protected:Npn \siunitx_table_print_S_centered_measure_result: { \prop_get:NnN \l_siunitx_number_out_prop { result } \l_siunitx_tmpa_tl \hbox_set:Nn \l_siunitx_table_result_box @@ -13968,13 +14079,13 @@ This work consists of the file siunitx.dtx % therefore set, for fill before the number and after it. One of these % will always be zero. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_integer: +\cs_new_protected:Npn \siunitx_table_print_S_centered_integer: { \dim_set:Nn \l_siunitx_table_fill_post_dim { \l_siunitx_table_integer_dim - \l_siunitx_table_fill_pre_dim } \dim_zero:N \l_siunitx_table_fill_pre_dim } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_decimal: +\cs_new_protected:Npn \siunitx_table_print_S_centered_decimal: { \dim_sub:Nn \l_siunitx_table_fill_pre_dim { \l_siunitx_table_integer_dim } @@ -13989,11 +14100,12 @@ This work consists of the file siunitx.dtx % The procedure for inserting a number with space reserved requires a model % for each part of the number. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved: +\cs_new_protected:Npn \siunitx_table_print_S_reserved: { \siunitx_table_print_S_reserved_init: \siunitx_table_print_S_reserved_ends: - \siunitx_table_print_S_reserved_round: + \bool_if:NT \l_siunitx_table_auto_round_bool + { \siunitx_table_print_S_reserved_round_auto: } \siunitx_table_print_S_parse: \bool_if:NF \l_siunitx_error_bool { @@ -14012,7 +14124,7 @@ This work consists of the file siunitx.dtx % model is done here so that all of the other options will apply without % needing complex internal tracking. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_init: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_init: { \dim_zero:N \l_siunitx_table_fill_mid_dim \dim_zero:N \l_siunitx_table_fill_post_dim @@ -14042,7 +14154,7 @@ This work consists of the file siunitx.dtx % with people forgetting to reserve space for the pre-numeral part, it is % boxed up first at natural width so that the measurement is accurate. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_ends: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_ends: { \hbox_set:Nn \l_siunitx_table_pre_box { @@ -14088,7 +14200,7 @@ This work consists of the file siunitx.dtx % allowed for, and if there are none to simply set the rounding value to % zero. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_round_auto: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_round_auto: { \prop_get:NnNTF \l_siunitx_table_model_prop { mantissa-decimal-raw } \l_siunitx_tmpa_tl @@ -14107,7 +14219,7 @@ This work consists of the file siunitx.dtx % that for filling: this is needed so that any pre-note can be aligned % freely. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_comparator: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_comparator: { \prop_get:NnNTF \l_siunitx_table_model_prop { comparator } \l_siunitx_tmpa_tl @@ -14149,9 +14261,9 @@ This work consists of the file siunitx.dtx % To allow for the various alignment options, fill is stored in a % flexible way. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_store_fill_pre:n +\cs_new_protected:Npn \siunitx_table_print_S_reserved_store_fill_pre:n { \dim_add:Nn \l_siunitx_table_fill_pre_dim } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_store_fill_mid:n +\cs_new_protected:Npn \siunitx_table_print_S_reserved_store_fill_mid:n { \dim_add:Nn \l_siunitx_table_fill_mid_dim } % \end{macrocode} % \end{macro} @@ -14171,7 +14283,7 @@ This work consists of the file siunitx.dtx % to reserve, and see if there is anything at all to put in it. The % complexity only starts if there is a mantissa in the current cell. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_mantissa: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa: { \prop_get:NnNTF \l_siunitx_table_model_prop { mantissa } \l_siunitx_tmpa_tl @@ -14211,7 +14323,7 @@ This work consists of the file siunitx.dtx % filler needed in the integer part. That is stored in the intermediate % dimension for the present, although it may get moved. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_mantissa_parts: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_parts: { \siunitx_table_print_S_reserved_mantissa_integer: \hbox_set:Nn \l_siunitx_table_result_box @@ -14235,7 +14347,7 @@ This work consists of the file siunitx.dtx % before or after any comparator. If there is an integer part, the % size is measured and the any fill needed is stored for re-insertion. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_mantissa_integer: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_integer: { \prop_get:NnNF \l_siunitx_table_model_prop { mantissa-sign } \l_siunitx_tmpa_tl @@ -14265,7 +14377,7 @@ This work consists of the file siunitx.dtx % be a \cs{pm} part to add. Once the space calculation is done, a flexible % auxiliary does the spacing and pasting up. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_mantissa_uncert: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_uncert: { \prop_get:NnNT \l_siunitx_table_model_prop { mantissa-uncertainty } \l_siunitx_tmpa_tl @@ -14281,7 +14393,9 @@ This work consists of the file siunitx.dtx \siunitx_number_format_join_uncert_pm:N \l_siunitx_tmpa_tl \hbox_set:Nn \l_siunitx_tmp_box { \siunitx_print:nV { number } \l_siunitx_tmpa_tl } - \siunitx_table_print_S_reserved_mantissa_uncert_aux: + \bool_if:NTF \l_siunitx_table_align_uncert_bool + { \siunitx_table_print_S_reserved_mantissa_uncert_aligned: } + { \siunitx_table_print_S_reserved_mantissa_uncert_not_aligned: } } { \siunitx_table_print_S_reserved_store_fill:n @@ -14295,7 +14409,7 @@ This work consists of the file siunitx.dtx % up in the middle fill store, but in the alignment case this also removes % any previous fill. The temporary box here contains the uncertainty part. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_uncert_aligned: { \hbox_set:Nn \l_siunitx_table_result_box @@ -14307,7 +14421,7 @@ This work consists of the file siunitx.dtx \dim_set:Nn \l_siunitx_table_fill_mid_dim { \l_siunitx_table_uncert_dim - \box_wd:N \l_siunitx_tmp_box } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_uncert_not_aligned: { \hbox_set:Nn \l_siunitx_table_result_box @@ -14338,7 +14452,7 @@ This work consists of the file siunitx.dtx % exponent, then any space which needs to be added must be moved from % the mid space to the post space at this stage. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_exponent: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent: { \prop_get:NnNTF \l_siunitx_table_model_prop { exponent-result } \l_siunitx_tmpa_tl @@ -14357,7 +14471,9 @@ This work consists of the file siunitx.dtx { \siunitx_table_print_S_reserved_exponent_product_correction: } \hbox_set:Nn \l_siunitx_tmp_box { \siunitx_print:nV { number } \l_siunitx_tmpa_tl } - \siunitx_table_print_S_reserved_exponent_aux: + \bool_if:NTF \l_siunitx_table_align_exponent_bool + { \siunitx_table_print_S_reserved_exponent_aligned: } + { \siunitx_table_print_S_reserved_exponent_not_aligned: } } { \dim_set:Nn \l_siunitx_table_fill_post_dim @@ -14378,15 +14494,14 @@ This work consists of the file siunitx.dtx % A short sub-function to deal with the appearance of the exponent product % for both the real number and the model. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_exponent_product: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent_product: { \tl_set_eq:NN \l_siunitx_tmpb_tl \l_siunitx_exponent_product_tl \bool_if:NT \l_siunitx_tight_bool { \tl_set:Nx \l_siunitx_tmpb_tl { { \exp_not:o \l_siunitx_tmpb_tl } } } \tl_set:Nx \l_siunitx_tmpa_tl { - \exp_not:N \siunitx_ensuremath:n - { { } \exp_not:o \l_siunitx_tmpb_tl { } } + \exp_not:N \ensuremath { { } \exp_not:o \l_siunitx_tmpb_tl { } } \exp_not:o \l_siunitx_tmpa_tl } } @@ -14394,7 +14509,7 @@ This work consists of the file siunitx.dtx % If there is no mantissa, then some additional space is needed for the % location where the product symbol would have been. % \begin{macrocode} -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent_product_correction: { \group_begin: @@ -14415,7 +14530,7 @@ This work consists of the file siunitx.dtx % or exclude the mid fill space. Doing that here avoids one extra assignment % (to clear the mid fill in the aligned case). % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_exponent_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent_aligned: { \hbox_set:Nn \l_siunitx_table_result_box { @@ -14429,7 +14544,7 @@ This work consists of the file siunitx.dtx - \box_wd:N \l_siunitx_tmp_box } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent_not_aligned: { \hbox_set:Nn \l_siunitx_table_result_box @@ -14460,7 +14575,7 @@ This work consists of the file siunitx.dtx % then calls the main function, which will be assigned by the % key--value system. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct: +\cs_new_protected:Npn \siunitx_table_print_S_direct: { \m@th \siunitx_table_print_S_direct_main: @@ -14480,12 +14595,12 @@ This work consists of the file siunitx.dtx % it will work with non-numerical input. % \begin{macrocode} \char_set_catcode_active:N \@ -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_centered: +\cs_new_protected:Npn \siunitx_table_print_S_direct_centered: { \cs_set_eq:NN \siunitx_table_print: \siunitx_table_print_S_direct_centered_end: \hbox_set:Nn \l_siunitx_tmp_box - { \siunitx_ensuremath:n { \l_siunitx_output_decimal_tl } } + { \ensuremath { \l_siunitx_output_decimal_tl } } \hbox_set_to_wd:Nnn \l_siunitx_table_post_box { \box_wd:N \l_siunitx_tmp_box } { \tex_hfil:D } @@ -14495,11 +14610,11 @@ This work consists of the file siunitx.dtx \tl_map_function:NN \l_siunitx_input_decimal_tl \siunitx_table_print_S_direct_centered_aux:N } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_centered_aux:N #1 +\cs_new_protected:Npn \siunitx_table_print_S_direct_centered_aux:N #1 { \char_set_lccode:nn { `\@ } { `#1 } \char_set_mathcode:nn { `#1 } { 32768 } - \tl_to_lowercase:n { \cs_set_nopar:Npn @ } + \tl_to_lowercase:n { \cs_set:Npn @ } { \c_math_toggle_token \c_group_end_token @@ -14510,7 +14625,7 @@ This work consists of the file siunitx.dtx } } \char_set_catcode_letter:N \@ -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_centered_end: +\cs_new_protected:Npn \siunitx_table_print_S_direct_centered_end: { \c_math_toggle_token \c_group_end_token @@ -14552,7 +14667,7 @@ This work consists of the file siunitx.dtx % \cs{tex_hill:D} as \texttt{fil} glue will not work. % \begin{macrocode} \char_set_catcode_active:N \@ -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_reserved: +\cs_new_protected:Npn \siunitx_table_print_S_direct_reserved: { \cs_set_eq:NN \siunitx_table_print: \siunitx_table_print_S_direct_reserved_end: @@ -14561,7 +14676,7 @@ This work consists of the file siunitx.dtx { \tl_clear:N \l_siunitx_tmpa_tl } \hbox_set:Nn \l_siunitx_tmp_box { - \siunitx_ensuremath:n + \ensuremath { \prop_get:NnNT \l_siunitx_table_model_prop { mantissa-sign } \l_siunitx_tmpb_tl @@ -14576,7 +14691,7 @@ This work consists of the file siunitx.dtx { \tl_clear:N \l_siunitx_tmpa_tl } \hbox_set:Nn \l_siunitx_tmp_box { - \siunitx_ensuremath:n + \ensuremath { \l_siunitx_output_decimal_tl \l_siunitx_tmpa_tl @@ -14593,11 +14708,11 @@ This work consists of the file siunitx.dtx \siunitx_table_print_S_direct_reserved_aux:N \tex_hfill:D } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_reserved_aux:N #1 +\cs_new_protected:Npn \siunitx_table_print_S_direct_reserved_aux:N #1 { \char_set_lccode:nn { `\@ } { `#1 } \char_set_mathcode:nn { `#1 } { 32768 } - \tl_to_lowercase:n { \cs_set_nopar:Npn @ } + \tl_to_lowercase:n { \cs_set:Npn @ } { \c_math_toggle_token \c_group_end_token @@ -14609,7 +14724,7 @@ This work consists of the file siunitx.dtx } } \char_set_catcode_letter:N \@ -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_reserved_end: +\cs_new_protected:Npn \siunitx_table_print_S_direct_reserved_end: { \c_math_toggle_token \tex_hfil:D @@ -14780,7 +14895,7 @@ This work consists of the file siunitx.dtx % For creating the outer symbol macro. % \begin{macrocode} \cs_new_protected:Npn \siunitx_symbol_new:n #1 { - \cs_set_protected_nopar:cpn { SIUnitSymbol #1 } + \cs_set_protected:cpn { SIUnitSymbol #1 } { \mode_if_math:TF { \tl_to_lowercase:n { \use:c { l_siunitx_ #1 _math_tl } } } @@ -14824,7 +14939,7 @@ This work consists of the file siunitx.dtx % be more difficult to follow. % \begin{macrocode} \clist_new:N \l_siunitx_pgf_link_clist -\cs_new_protected_nopar:Npn \siunitx_pgf_link: { +\cs_new_protected:Npn \siunitx_pgf_link: { \clist_clear:N \l_siunitx_pgf_link_clist \str_if_eq:VnT \l_siunitx_round_tl { figure } { @@ -14840,10 +14955,7 @@ This work consists of the file siunitx.dtx { { \exp_not:V \l_siunitx_output_decimal_tl } } } \clist_put_right:Nx \l_siunitx_pgf_link_clist - { - set~thousands~separator = - { \exp_not:V \l_siunitx_group_sep_tl } - } + { set~thousands~separator = { \exp_not:V \l_siunitx_group_sep_tl } } \clist_put_right:Nn \l_siunitx_pgf_link_clist { min~exponent~for~1000~sep = \int_use:N \l_siunitx_group_min_int } \bool_if:nF @@ -14874,7 +14986,7 @@ This work consists of the file siunitx.dtx { showpos = false } } \group_begin: - \cs_set_nopar:Npx \siunitx_tmp:w + \cs_set:Npx \siunitx_tmp:w { \group_end: \exp_not:N \pgfqkeys @@ -14986,6 +15098,8 @@ This work consists of the file siunitx.dtx The~input~'#1'~is~a~number~which~has~more~than~one~part: \\ ranges~can~only~contain~one~number~in~each~part. } +\msg_new:nnn { siunitx } { non-convertible-exponent } + { Exponent~'#1'~cannot~be~converted~into~a~symbolic~prefix. } \msg_new:nnn { siunitx } { option-not-available } { Option~'#1'~not~available~in~strict~mode. } \msg_new:nnn { siunitx } { option-preamble-only } @@ -15094,7 +15208,7 @@ This work consists of the file siunitx.dtx %\begin{macro}{\SendSettingsToPgf} % A settings transfer function. % \begin{macrocode} -\cs_new_protected_nopar:Npn \SendSettingsToPgf { \siunitx_pgf_link: } +\cs_new_protected:Npn \SendSettingsToPgf { \siunitx_pgf_link: } % \end{macrocode} %\end{macro} % @@ -15283,8 +15397,8 @@ This work consists of the file siunitx.dtx { \token_to_str:N \@writefile {#1} {#2} } } } -\cs_new_protected_nopar:Npn \siunitx_contents_add:N #1 - { \cs_set_nopar:Npn #1 { \token_to_str:N #1 } } +\cs_new_protected:Npn \siunitx_contents_add:N #1 + { \cs_set:Npn #1 { \token_to_str:N #1 } } % \end{macrocode} % \end{macro} % @@ -15296,7 +15410,7 @@ This work consists of the file siunitx.dtx % of the input, removes any set up options (which are being ignored) % and stops \pkg{hyperref} issuing a warning. % \begin{macrocode} -\cs_new_protected_nopar:Npn \siunitx_contents_bookmarks: +\cs_new_protected:Npn \siunitx_contents_bookmarks: { \tl_map_function:NN \l_siunitx_declare_list_tl \siunitx_unit_print_literal_aux:N @@ -15308,13 +15422,13 @@ This work consists of the file siunitx.dtx \cs_set_eq:NN \SIrange \siunitx_bookmark_SIrange:w \cs_set_eq:NN \si \siunitx_bookmark_si:w \cs_set_eq:NN \siunitx_textsuperscript:n \use:n - \cs_set_nopar:Npn \SIUnitSymbolAngstrom { \AA } - \cs_set_nopar:Npn \SIUnitSymbolArcminute { ' } - \cs_set_nopar:Npn \SIUnitSymbolArcsecond { '' } - \cs_set_nopar:Npn \SIUnitSymbolCelsius { \textcelsius } - \cs_set_nopar:Npn \SIUnitSymbolDegree { \textdegree } - \cs_set_nopar:Npn \SIUnitSymbolMicro { \textmu } - \cs_set_nopar:Npn \SIUnitSymbolOhm { [ohm] } + \cs_set:Npn \SIUnitSymbolAngstrom { \AA } + \cs_set:Npn \SIUnitSymbolArcminute { ' } + \cs_set:Npn \SIUnitSymbolArcsecond { '' } + \cs_set:Npn \SIUnitSymbolCelsius { \textcelsius } + \cs_set:Npn \SIUnitSymbolDegree { \textdegree } + \cs_set:Npn \SIUnitSymbolMicro { \textmu } + \cs_set:Npn \SIUnitSymbolOhm { [ohm] } } % \end{macrocode} % \end{macro} @@ -15751,10 +15865,10 @@ This work consists of the file siunitx.dtx } } \siunitx_option_deactivate:n { strict } -\cs_new_protected_nopar:Npn \siunitx_strict_option:n #1 { +\cs_new_protected:Npn \siunitx_strict_option:n #1 { \clist_map_function:nN {#1} \siunitx_strict_option_aux:n } -\cs_new_protected_nopar:Npn \siunitx_strict_option_aux:n #1 { +\cs_new_protected:Npn \siunitx_strict_option_aux:n #1 { \keys_define:nn { siunitx } { #1 .code:n = { \msg_warning:nnx { siunitx } { option-not-available } {#1} } @@ -15861,12 +15975,12 @@ This work consists of the file siunitx.dtx false .code:n = { } , binary-units .default:n = true } -\cs_new_protected_nopar:Npn \siunitx_load_abbreviations: +\cs_new_protected:Npn \siunitx_load_abbreviations: { \@onefilewithoptions { siunitx-abbreviations } [ ] [ ] \c_siunitx_configuration_ext_tl } -\cs_new_protected_nopar:Npn \siunitx_load_binary: +\cs_new_protected:Npn \siunitx_load_binary: { \@onefilewithoptions { siunitx-binary } [ ] [ ] \c_siunitx_configuration_ext_tl @@ -15949,7 +16063,7 @@ This work consists of the file siunitx.dtx % \end{macrocode} % % \begin{macrocode} -\ProvidesExplFile {siunitx-version-1.cfg} {2011/10/14} {2.3h} +\ProvidesExplFile {siunitx-version-1.cfg} {2011/11/14} {2.4} {siunitx: Version 1 settings} % \end{macrocode} % @@ -15984,43 +16098,43 @@ This work consists of the file siunitx.dtx anglesep .choice: , anglesep / cdot .meta:n = - { arc-separator = { } \cdot { } }, + { arc-separator = \ensuremath { { } \cdot { } } }, anglesep / - comma .meta:n = { arc-separator = { {,} } }, + comma .meta:n = { arc-separator = \ensuremath { { {,} } } }, anglesep / - fullstop .meta:n = { arc-separator = { { . } } }, + fullstop .meta:n = { arc-separator = \ensuremath { { { . } } } }, anglesep / - med .meta:n = { arc-separator = \: }, + med .meta:n = { arc-separator = \ensuremath { \: } }, anglesep / - medium .meta:n = { arc-separator = \: }, + medium .meta:n = { arc-separator = \ensuremath { \: } }, anglesep / none .meta:n = { arc-separator = }, anglesep / - period .meta:n = { arc-separator = { { . } } }, + period .meta:n = { arc-separator = \ensuremath { { { . } } } }, anglesep / space .meta:n = { arc-separator = \text { ~ } }, anglesep / - stop .meta:n = { arc-separator = { { . } } }, + stop .meta:n = { arc-separator = \ensuremath { { { . } } } }, anglesep / - thick .meta:n = { arc-separator = \; }, + thick .meta:n = { arc-separator = \ensuremath { \; } }, anglesep / - thin .meta:n = { arc-separator = \, }, + thin .meta:n = { arc-separator = \ensuremath { \, } }, anglesep / tightcdot .meta:n = - { arc-separator = \bgroup \cdot \egroup }, + { arc-separator = \ensuremath { \bgroup \cdot \egroup } }, anglesep / tighttimes .meta:n = - { arc-separator = \bgroup \times \egroup }, + { arc-separator = \ensuremath { \bgroup \times \egroup } }, anglesep / - times .meta:n = { arc-separator = \times }, + times .meta:n = { arc-separator = \ensuremath { \times } }, anglesep / - unknown .meta:n = { arc-separator = #1 }, + unknown .meta:n = { arc-separator = \ensuremath {#1} }, astroang .meta:n = { angle-symbol-over-decimal = #1 }, astroang .default:n = { true }, - closeerr .meta:n = { close-bracket = #1 }, - closefrac .meta:n = { close-bracket = #1 }, - closerange .meta:n = { close-bracket = #1 }, + closeerr .meta:n = { close-bracket = \ensuremath {#1} }, + closefrac .meta:n = { close-bracket = \ensuremath {#1} }, + closerange .meta:n = { close-bracket = \ensuremath {#1} }, colour .code:n = { color = #1 }, colorall .code:n = , colourall .code:n = , @@ -16033,57 +16147,57 @@ This work consists of the file siunitx.dtx decimalsymbol .choice: , decimalsymbol / cdot .meta:n = - { output-decimal-marker = { } \cdot { } }, + { output-decimal-marker = \ensuremath { { } \cdot { } } }, decimalsymbol / - comma .meta:n = { output-decimal-marker = { { , } } }, + comma .meta:n = { output-decimal-marker = { \ensuremath { { , } } } }, decimalsymbol / - fullstop .meta:n = { output-decimal-marker = { { . } } }, + fullstop .meta:n = { output-decimal-marker = { \ensuremath { { . } } } }, decimalsymbol / - period .meta:n = { output-decimal-marker = { { . } } }, + period .meta:n = { output-decimal-marker = { \ensuremath { { . } } } }, decimalsymbol / - stop .meta:n = { output-decimal-marker = { { . } } }, + stop .meta:n = { output-decimal-marker = { \ensuremath { { . } } } }, decimalsymbol / tightcdot .code:n = - { output-decimal-marker = \bgroup \cdot \egroup }, + { output-decimal-marker = \ensuremath { \bgroup \cdot \egroup } }, decimalsymbol / - unknown .meta:n = { output-decimal-marker = #1 }, + unknown .meta:n = { output-decimal-marker = \ensuremath {#1} }, debug .code:n = , detectdisplay .meta:n = { detect-display-math = #1 }, detectdisplay .default:n = { true }, digitsep .choice: , digitsep / cdot .meta:n = - { group-separator = { } \cdot { } }, + { group-separator = \ensuremath { { } \cdot { } } }, digitsep / - comma .meta:n = { group-separator = { , } }, + comma .meta:n = { group-separator = \ensuremath { { , } } }, digitsep / - fullstop .meta:n = { group-separator = . }, + fullstop .meta:n = { group-separator = \ensuremath { . } }, digitsep / - med .meta:n = { group-separator = \: }, + med .meta:n = { group-separator = \ensuremath { \: } }, digitsep / - medium .meta:n = { group-separator = \: }, + medium .meta:n = { group-separator = \ensuremath { \: } }, digitsep / none .meta:n = { group-separator = }, digitsep / - period .meta:n = { group-separator = . }, + period .meta:n = { group-separator = \ensuremath { . } }, digitsep / space .meta:n = { group-separator = \text { ~ } }, digitsep / - stop .meta:n = { group-separator = . }, + stop .meta:n = { group-separator = \ensuremath { . } }, digitsep / - thick .meta:n = { group-separator = \; }, + thick .meta:n = { group-separator = \ensuremath { \; } }, digitsep / - thin .meta:n = { group-separator = \, }, + thin .meta:n = { group-separator = \ensuremath { \, } }, digitsep / tightcdot .meta:n = - { group-separator = \bgroup \cdot \egroup }, + { group-separator = \ensuremath { \bgroup \cdot \egroup } }, digitsep / tighttimes .meta:n = - { group-separator = \bgroup \times \egroup }, + { group-separator = \ensuremath { \bgroup \times \egroup } }, digitsep / - times .meta:n = { group-separator = \times }, + times .meta:n = { group-separator = \ensuremath { \times } }, digitsep / - unknown .meta:n = { group-separator = #1 }, + unknown .meta:n = { group-separator = \ensuremath {#1} }, dp .meta:n = { round-mode = places, @@ -16092,19 +16206,19 @@ This work consists of the file siunitx.dtx emulate .code:n = , errspace .choice: , errspace / - med .meta:n = { uncertainty-separator = \: }, + med .meta:n = { uncertainty-separator = \ensuremath { \: } }, errspace / - medium .meta:n = { uncertainty-separator = \: }, + medium .meta:n = { uncertainty-separator = \ensuremath { \: } }, errspace / none .meta:n = { uncertainty-separator = }, errspace / space .meta:n = { uncertainty-separator = \text { ~ } }, errspace / - thick .meta:n = { uncertainty-separator = \; }, + thick .meta:n = { uncertainty-separator = \ensuremath { \; } }, errspace / - thin .meta:n = { uncertainty-separator = \, }, + thin .meta:n = { uncertainty-separator = \ensuremath { \, } }, errspace / - unknown .meta:n = { uncertainty-separator = #1 }, + unknown .meta:n = { uncertainty-separator = \ensuremath {#1} }, eVcorra .code:n = , eVcorrb .code:n = , expbase .choice: , @@ -16206,9 +16320,9 @@ This work consists of the file siunitx.dtx obeyitalic .default:n = { true }, obeymode .meta:n = { detect-mode = #1 }, obeymode .default:n = { true }, - openerr .meta:n = { open-bracket = #1 }, - openfrac .meta:n = { open-bracket = #1 }, - openrange .meta:n = { open-bracket = #1 }, + openerr .meta:n = { open-bracket = \ensuremath {#1} }, + openfrac .meta:n = { open-bracket = \ensuremath {#1} }, + openrange .meta:n = { open-bracket = \ensuremath {#1} }, padangle .choice: , padangle / all .meta:n = @@ -16352,9 +16466,9 @@ This work consists of the file siunitx.dtx sign .meta:n = { explicit-sign = #1 }, slash .choice: , slash / - slash .meta:n = { per-symbol = / }, + slash .meta:n = { per-symbol = \ensuremath { / } }, slash / - unknown .meta:n = { per-symbol = #1 }, + unknown .meta:n = { per-symbol = \ensuremath {#1} }, stickyper .meta:n = { sticky-per = #1 }, stickyper .default:n = { true }, strictarc .code:n = , @@ -16894,7 +17008,7 @@ This work consists of the file siunitx.dtx % \end{macrocode} % % \begin{macrocode} -\ProvidesExplFile {siunitx-abbreviations.cfg} {2011/10/14} {2.3h} +\ProvidesExplFile {siunitx-abbreviations.cfg} {2011/11/14} {2.4} {siunitx: Abbreviated units} % \end{macrocode} % @@ -17076,7 +17190,7 @@ This work consists of the file siunitx.dtx % \end{macrocode} % % \begin{macrocode} -\ProvidesExplFile {siunitx-binary.cfg} {2011/10/14} {2.3h} +\ProvidesExplFile {siunitx-binary.cfg} {2011/11/14} {2.4} {siunitx: Binary units} % \end{macrocode} % diff --git a/Master/texmf-dist/tex/latex/siunitx/config/siunitx-abbreviations.cfg b/Master/texmf-dist/tex/latex/siunitx/config/siunitx-abbreviations.cfg index b7baf06db7a..cdd37780dd4 100644 --- a/Master/texmf-dist/tex/latex/siunitx/config/siunitx-abbreviations.cfg +++ b/Master/texmf-dist/tex/latex/siunitx/config/siunitx-abbreviations.cfg @@ -13,7 +13,7 @@ %% See http://www.latex-project.org/lppl.txt %% --------------------------------------------------------------- %% -\ProvidesExplFile {siunitx-abbreviations.cfg} {2011/10/14} {2.3h} +\ProvidesExplFile {siunitx-abbreviations.cfg} {2011/11/14} {2.4} {siunitx: Abbreviated units} \DeclareSIUnit \A { \ampere } \DeclareSIUnit \pA { \pico \ampere } diff --git a/Master/texmf-dist/tex/latex/siunitx/config/siunitx-binary.cfg b/Master/texmf-dist/tex/latex/siunitx/config/siunitx-binary.cfg index 06b5b97101d..88f31faebf4 100644 --- a/Master/texmf-dist/tex/latex/siunitx/config/siunitx-binary.cfg +++ b/Master/texmf-dist/tex/latex/siunitx/config/siunitx-binary.cfg @@ -13,7 +13,7 @@ %% See http://www.latex-project.org/lppl.txt %% --------------------------------------------------------------- %% -\ProvidesExplFile {siunitx-binary.cfg} {2011/10/14} {2.3h} +\ProvidesExplFile {siunitx-binary.cfg} {2011/11/14} {2.4} {siunitx: Binary units} \DeclareBinaryPrefix \kibi { Ki } { 10 } \DeclareBinaryPrefix \mebi { Mi } { 20 } diff --git a/Master/texmf-dist/tex/latex/siunitx/config/siunitx-version-1.cfg b/Master/texmf-dist/tex/latex/siunitx/config/siunitx-version-1.cfg index b78df64c54e..57c10d8ab57 100644 --- a/Master/texmf-dist/tex/latex/siunitx/config/siunitx-version-1.cfg +++ b/Master/texmf-dist/tex/latex/siunitx/config/siunitx-version-1.cfg @@ -13,7 +13,7 @@ %% See http://www.latex-project.org/lppl.txt %% --------------------------------------------------------------- %% -\ProvidesExplFile {siunitx-version-1.cfg} {2011/10/14} {2.3h} +\ProvidesExplFile {siunitx-version-1.cfg} {2011/11/14} {2.4} {siunitx: Version 1 settings} \keys_define:nn { siunitx } { addsign .choice: , @@ -41,43 +41,43 @@ anglesep .choice: , anglesep / cdot .meta:n = - { arc-separator = { } \cdot { } }, + { arc-separator = \ensuremath { { } \cdot { } } }, anglesep / - comma .meta:n = { arc-separator = { {,} } }, + comma .meta:n = { arc-separator = \ensuremath { { {,} } } }, anglesep / - fullstop .meta:n = { arc-separator = { { . } } }, + fullstop .meta:n = { arc-separator = \ensuremath { { { . } } } }, anglesep / - med .meta:n = { arc-separator = \: }, + med .meta:n = { arc-separator = \ensuremath { \: } }, anglesep / - medium .meta:n = { arc-separator = \: }, + medium .meta:n = { arc-separator = \ensuremath { \: } }, anglesep / none .meta:n = { arc-separator = }, anglesep / - period .meta:n = { arc-separator = { { . } } }, + period .meta:n = { arc-separator = \ensuremath { { { . } } } }, anglesep / space .meta:n = { arc-separator = \text { ~ } }, anglesep / - stop .meta:n = { arc-separator = { { . } } }, + stop .meta:n = { arc-separator = \ensuremath { { { . } } } }, anglesep / - thick .meta:n = { arc-separator = \; }, + thick .meta:n = { arc-separator = \ensuremath { \; } }, anglesep / - thin .meta:n = { arc-separator = \, }, + thin .meta:n = { arc-separator = \ensuremath { \, } }, anglesep / tightcdot .meta:n = - { arc-separator = \bgroup \cdot \egroup }, + { arc-separator = \ensuremath { \bgroup \cdot \egroup } }, anglesep / tighttimes .meta:n = - { arc-separator = \bgroup \times \egroup }, + { arc-separator = \ensuremath { \bgroup \times \egroup } }, anglesep / - times .meta:n = { arc-separator = \times }, + times .meta:n = { arc-separator = \ensuremath { \times } }, anglesep / - unknown .meta:n = { arc-separator = #1 }, + unknown .meta:n = { arc-separator = \ensuremath {#1} }, astroang .meta:n = { angle-symbol-over-decimal = #1 }, astroang .default:n = { true }, - closeerr .meta:n = { close-bracket = #1 }, - closefrac .meta:n = { close-bracket = #1 }, - closerange .meta:n = { close-bracket = #1 }, + closeerr .meta:n = { close-bracket = \ensuremath {#1} }, + closefrac .meta:n = { close-bracket = \ensuremath {#1} }, + closerange .meta:n = { close-bracket = \ensuremath {#1} }, colour .code:n = { color = #1 }, colorall .code:n = , colourall .code:n = , @@ -90,57 +90,57 @@ decimalsymbol .choice: , decimalsymbol / cdot .meta:n = - { output-decimal-marker = { } \cdot { } }, + { output-decimal-marker = \ensuremath { { } \cdot { } } }, decimalsymbol / - comma .meta:n = { output-decimal-marker = { { , } } }, + comma .meta:n = { output-decimal-marker = { \ensuremath { { , } } } }, decimalsymbol / - fullstop .meta:n = { output-decimal-marker = { { . } } }, + fullstop .meta:n = { output-decimal-marker = { \ensuremath { { . } } } }, decimalsymbol / - period .meta:n = { output-decimal-marker = { { . } } }, + period .meta:n = { output-decimal-marker = { \ensuremath { { . } } } }, decimalsymbol / - stop .meta:n = { output-decimal-marker = { { . } } }, + stop .meta:n = { output-decimal-marker = { \ensuremath { { . } } } }, decimalsymbol / tightcdot .code:n = - { output-decimal-marker = \bgroup \cdot \egroup }, + { output-decimal-marker = \ensuremath { \bgroup \cdot \egroup } }, decimalsymbol / - unknown .meta:n = { output-decimal-marker = #1 }, + unknown .meta:n = { output-decimal-marker = \ensuremath {#1} }, debug .code:n = , detectdisplay .meta:n = { detect-display-math = #1 }, detectdisplay .default:n = { true }, digitsep .choice: , digitsep / cdot .meta:n = - { group-separator = { } \cdot { } }, + { group-separator = \ensuremath { { } \cdot { } } }, digitsep / - comma .meta:n = { group-separator = { , } }, + comma .meta:n = { group-separator = \ensuremath { { , } } }, digitsep / - fullstop .meta:n = { group-separator = . }, + fullstop .meta:n = { group-separator = \ensuremath { . } }, digitsep / - med .meta:n = { group-separator = \: }, + med .meta:n = { group-separator = \ensuremath { \: } }, digitsep / - medium .meta:n = { group-separator = \: }, + medium .meta:n = { group-separator = \ensuremath { \: } }, digitsep / none .meta:n = { group-separator = }, digitsep / - period .meta:n = { group-separator = . }, + period .meta:n = { group-separator = \ensuremath { . } }, digitsep / space .meta:n = { group-separator = \text { ~ } }, digitsep / - stop .meta:n = { group-separator = . }, + stop .meta:n = { group-separator = \ensuremath { . } }, digitsep / - thick .meta:n = { group-separator = \; }, + thick .meta:n = { group-separator = \ensuremath { \; } }, digitsep / - thin .meta:n = { group-separator = \, }, + thin .meta:n = { group-separator = \ensuremath { \, } }, digitsep / tightcdot .meta:n = - { group-separator = \bgroup \cdot \egroup }, + { group-separator = \ensuremath { \bgroup \cdot \egroup } }, digitsep / tighttimes .meta:n = - { group-separator = \bgroup \times \egroup }, + { group-separator = \ensuremath { \bgroup \times \egroup } }, digitsep / - times .meta:n = { group-separator = \times }, + times .meta:n = { group-separator = \ensuremath { \times } }, digitsep / - unknown .meta:n = { group-separator = #1 }, + unknown .meta:n = { group-separator = \ensuremath {#1} }, dp .meta:n = { round-mode = places, @@ -149,19 +149,19 @@ emulate .code:n = , errspace .choice: , errspace / - med .meta:n = { uncertainty-separator = \: }, + med .meta:n = { uncertainty-separator = \ensuremath { \: } }, errspace / - medium .meta:n = { uncertainty-separator = \: }, + medium .meta:n = { uncertainty-separator = \ensuremath { \: } }, errspace / none .meta:n = { uncertainty-separator = }, errspace / space .meta:n = { uncertainty-separator = \text { ~ } }, errspace / - thick .meta:n = { uncertainty-separator = \; }, + thick .meta:n = { uncertainty-separator = \ensuremath { \; } }, errspace / - thin .meta:n = { uncertainty-separator = \, }, + thin .meta:n = { uncertainty-separator = \ensuremath { \, } }, errspace / - unknown .meta:n = { uncertainty-separator = #1 }, + unknown .meta:n = { uncertainty-separator = \ensuremath {#1} }, eVcorra .code:n = , eVcorrb .code:n = , expbase .choice: , @@ -263,9 +263,9 @@ obeyitalic .default:n = { true }, obeymode .meta:n = { detect-mode = #1 }, obeymode .default:n = { true }, - openerr .meta:n = { open-bracket = #1 }, - openfrac .meta:n = { open-bracket = #1 }, - openrange .meta:n = { open-bracket = #1 }, + openerr .meta:n = { open-bracket = \ensuremath {#1} }, + openfrac .meta:n = { open-bracket = \ensuremath {#1} }, + openrange .meta:n = { open-bracket = \ensuremath {#1} }, padangle .choice: , padangle / all .meta:n = @@ -409,9 +409,9 @@ sign .meta:n = { explicit-sign = #1 }, slash .choice: , slash / - slash .meta:n = { per-symbol = / }, + slash .meta:n = { per-symbol = \ensuremath { / } }, slash / - unknown .meta:n = { per-symbol = #1 }, + unknown .meta:n = { per-symbol = \ensuremath {#1} }, stickyper .meta:n = { sticky-per = #1 }, stickyper .default:n = { true }, strictarc .code:n = , diff --git a/Master/texmf-dist/tex/latex/siunitx/siunitx.sty b/Master/texmf-dist/tex/latex/siunitx/siunitx.sty index fac3155705f..fcf188e6609 100644 --- a/Master/texmf-dist/tex/latex/siunitx/siunitx.sty +++ b/Master/texmf-dist/tex/latex/siunitx/siunitx.sty @@ -14,35 +14,23 @@ %% --------------------------------------------------------------- %% \RequirePackage{expl3} -\ProvidesExplPackage {siunitx} {2011/10/14} {2.3h} +\ProvidesExplPackage {siunitx} {2011/11/14} {2.4} {A comprehensive (SI) units package} -\cs_if_exist:NTF \msg_new:nnnn - { - \msg_new:nnnn { siunitx } { support-outdated } - { Support~package~#1~too~old. } - { - Please~install~an~up~to~date~version~of~#1. \\ - Loading~siunitx~will~abort! - } - } +\@ifpackagelater { expl3 } { 2011/09/05 } + { } { \PackageError { siunitx } { Support~package~expl3~too~old. } { - Please~install~an~up~to~date~version~of~expl3. \\ + You~need~to~update~your~installation~of~the~bundles~'l3kernel'~and~ + 'l3packages'.\\ Loading~siunitx~will~abort! } \tex_endinput:D } -\@ifpackagelater { expl3 } { 2011/09/05 } - { } - { - \msg_error:nnx { siunitx } { support-outdated } { expl3 } - \tex_endinput:D - } \msg_new:nnnn { siunitx } { incompatible-package } { Package~'#1'~incompatible. } { The~#1~package~and~siunitx~are~incompatible. } -\cs_new_protected_nopar:Npn \siunitx_load_check:n #1 { +\cs_new_protected:Npn \siunitx_load_check:n #1 { \group_begin: \@ifpackageloaded {#1} { \msg_error:nnx { siunitx } { incompatible-package } {#1} } @@ -58,6 +46,7 @@ } \RequirePackage{ amstext , array , l3keys2e } \cs_new:Npn \siunitx_tmp:w { } +\cs_generate_variant:Nn \clist_map_function:nN { nc } \bool_new:N \l_siunitx_tmp_bool \box_new:N \l_siunitx_tmp_box \dim_new:N \l_siunitx_tmp_dim @@ -109,18 +98,14 @@ \cs_if_exist:NT \upOmega { \tl_set:Nn \c_siunitx_omega_tl { \upOmega } } } -\cs_new_protected:Npn \siunitx_tl_put_left_math:Nn #1#2 { - \tl_put_left:Nn #1 { \siunitx_ensuremath:n {#2} } -} +\cs_new_protected:Npn \siunitx_tl_put_left_math:Nn #1#2 + { \tl_put_left:Nn #1 { \ensuremath {#2} } } \cs_generate_variant:Nn \siunitx_tl_put_left_math:Nn { NV } -\cs_generate_variant:Nn \siunitx_tl_put_left_math:Nn { cV } -\cs_new_protected:Npn \siunitx_tl_put_right_math:Nn #1#2 { - \tl_put_right:Nn #1 { \siunitx_ensuremath:n {#2} } -} +\cs_new_protected:Npn \siunitx_tl_put_right_math:Nn #1#2 + { \tl_put_right:Nn #1 { \ensuremath {#2} } } \cs_generate_variant:Nn \siunitx_tl_put_right_math:Nn { NV } -\cs_generate_variant:Nn \siunitx_tl_put_right_math:Nn { cV } \seq_new:N \c_siunitx_old_options_seq -\cs_set_protected_nopar:Npn \siunitx_tmp:w #1 { +\cs_set_protected:Npn \siunitx_tmp:w #1 { \seq_put_right:No \c_siunitx_old_options_seq { \tl_to_str:n {#1} } } \siunitx_tmp:w { addsign } @@ -306,10 +291,10 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_option_deactivate:n #1 { +\cs_new_protected:Npn \siunitx_option_deactivate:n #1 { \clist_put_right:Nn \l_siunitx_option_deactivate_clist {#1} } -\cs_new_protected_nopar:Npn \siunitx_option_deactivate_aux:n #1 { +\cs_new_protected:Npn \siunitx_option_deactivate_aux:n #1 { \keys_define:nn { siunitx } { #1 .code:n = @@ -341,7 +326,7 @@ } { \prg_return_false: } } - \cs_new_nopar:Npn \siunitx_cs_if_tl_aux:w #1 MACRO #2 \q_stop + \cs_new:Npn \siunitx_cs_if_tl_aux:w #1 MACRO #2 \q_stop { \tl_if_empty:nTF {#1} } \prg_new_conditional:Npnn \siunitx_cs_if_macro:N #1 { T , F , TF , p } @@ -352,16 +337,15 @@ { \prg_return_false: } } } -\cs_new_eq:NN \siunitx_ensuremath:n \ensuremath -\AtBeginDocument { - \@ifpackageloaded { tex4ht } - { - \cs_set_eq:NN \siunitx_ensuremath:n \use:n - \cs_set_eq:NN \siunitx_print_text_super:n \textsuperscript - \keys_set:nn { siunitx } { qualifier-mode = brackets, mode = text } - } - { } -} +\AtBeginDocument + { + \@ifpackageloaded { tex4ht } + { + \cs_set_eq:NN \siunitx_print_text_super:n \textsuperscript + \keys_set:nn { siunitx } { qualifier-mode = brackets, mode = text } + } + { } + } \cs_new_eq:NN \siunitx_textsuperscript:n \textsuperscript \bool_new:N \l_siunitx_display_math_bool \tex_everydisplay:D \exp_after:wN @@ -372,7 +356,7 @@ \cs_generate_variant:Nn \prop_get:NnNT { NV } \cs_generate_variant:Nn \prop_get:NnNF { NV } \cs_generate_variant:Nn \prop_get:NnNTF { NV } -\cs_new_protected_nopar:Npn \siunitx_set_math_fam:n #1 { +\cs_new_protected:Npn \siunitx_set_math_fam:n #1 { \int_new:c { c_siunitx_math #1 _int } \group_begin: \hbox_set:Nn \l_siunitx_tmp_box @@ -391,7 +375,7 @@ \siunitx_set_math_fam:n { sf } \siunitx_set_math_fam:n { tt } } -\cs_new_protected_nopar:Npn \siunitx_set_text_fam:n #1 { +\cs_new_protected:Npn \siunitx_set_text_fam:n #1 { \tl_new:c { c_siunitx_text #1 _tl } \tl_set:cx { c_siunitx_text #1 _tl } { \use:c { #1 default } } } @@ -465,9 +449,9 @@ \bool_new:N \l_siunitx_font_set_bool \bool_new:N \l_siunitx_font_math_mode_bool \tl_new:N \l_siunitx_font_family_tl -\cs_new_nopar:Npn \siunitx_font_shape: { } -\cs_new_nopar:Npn \siunitx_font_weight: { } -\cs_new_protected_nopar:Npn \siunitx_detect_font: { +\cs_new:Npn \siunitx_font_shape: { } +\cs_new:Npn \siunitx_font_weight: { } +\cs_new_protected:Npn \siunitx_detect_font: { \bool_if:NF \l_siunitx_font_set_bool { \siunitx_detect_font_init: @@ -481,7 +465,7 @@ { \siunitx_detect_font_mode: } } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_init: { +\cs_new_protected:Npn \siunitx_detect_font_init: { \bool_set_true:N \l_siunitx_font_set_bool \cs_set:Npn \siunitx_font_weight: { @@ -492,7 +476,7 @@ \tl_set:Nn \l_siunitx_font_family_tl { rm } \bool_set_true:N \l_siunitx_font_math_mode_bool } -\cs_new_protected_nopar:Npn \siunitx_detect_font_weight: { +\cs_new_protected:Npn \siunitx_detect_font_weight: { \mode_if_math:TF { \bool_if:NTF \l_siunitx_display_math_bool @@ -512,7 +496,7 @@ } { \siunitx_detect_font_weight_text: } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_weight_math: { +\cs_new_protected:Npn \siunitx_detect_font_weight_math: { \str_if_eq:VnT \math@version { bold } { \cs_set:Npn \siunitx_font_weight: @@ -524,7 +508,7 @@ \str_if_eq:VnT \math@version { light } { \cs_set:Npn \siunitx_font_weight: { \lseries } } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_weight_text: { +\cs_new_protected:Npn \siunitx_detect_font_weight_text: { \tl_set:Nx \l_siunitx_tmpa_tl { \tl_head:V \f@series } \str_if_eq:VnT \l_siunitx_tmpa_tl { b } { @@ -537,7 +521,7 @@ \str_if_eq:VnT \l_siunitx_tmpa_tl { l } { \cs_set:Npn \siunitx_font_weight: { \lseries } } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_family: { +\cs_new_protected:Npn \siunitx_detect_font_family: { \mode_if_math:TF { \bool_if:NTF \l_siunitx_display_math_bool @@ -557,26 +541,26 @@ } { \siunitx_detect_font_family_text: } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_family_math: { +\cs_new_protected:Npn \siunitx_detect_font_family_math: { \tl_set:Nn \l_siunitx_font_family_tl { rm } \int_compare:nNnT { \fam } = { \c_siunitx_mathsf_int } { \tl_set:Nn \l_siunitx_font_family_tl { sf } } \int_compare:nNnT { \fam } = { \c_siunitx_mathtt_int } { \tl_set:Nn \l_siunitx_font_family_tl { tt } } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_family_text: { +\cs_new_protected:Npn \siunitx_detect_font_family_text: { \tl_if_eq:NNT \f@family \c_siunitx_textsf_tl { \tl_set:Nn \l_siunitx_font_family_tl { sf } } \tl_if_eq:NNT \f@family \c_siunitx_texttt_tl { \tl_set:Nn \l_siunitx_font_family_tl { tt } } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_shape: { +\cs_new_protected:Npn \siunitx_detect_font_shape: { \str_if_eq:VnT \f@shape { it } - { \cs_set_nopar:Npn \siunitx_font_shape: { \itshape } } + { \cs_set:Npn \siunitx_font_shape: { \itshape } } \str_if_eq:VnT \f@shape { sl } - { \cs_set_nopar:Npn \siunitx_font_shape: { \slshape } } + { \cs_set:Npn \siunitx_font_shape: { \slshape } } } -\cs_new_protected_nopar:Npn \siunitx_detect_font_mode: { +\cs_new_protected:Npn \siunitx_detect_font_mode: { \mode_if_math:F { \bool_set_false:N \l_siunitx_font_math_mode_bool @@ -589,54 +573,54 @@ \cs_new:Npn \siunitx_number_mathrm:n #1 { } \cs_new:Npn \siunitx_number_mathsf:n #1 { } \cs_new:Npn \siunitx_number_mathtt:n #1 { } -\cs_new_nopar:Npn \siunitx_number_textrm: { } -\cs_new_nopar:Npn \siunitx_number_textsf: { } -\cs_new_nopar:Npn \siunitx_number_texttt: { } +\cs_new:Npn \siunitx_number_textrm: { } +\cs_new:Npn \siunitx_number_textsf: { } +\cs_new:Npn \siunitx_number_texttt: { } \keys_define:nn { siunitx } { number-color .tl_set:N = \l_siunitx_number_color_tl, number-math-rm .code:n = - { \cs_set_nopar:Npn \siunitx_number_mathrm:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_number_mathrm:n ##1 { #1 {##1} } }, number-math-sf .code:n = - { \cs_set_nopar:Npn \siunitx_number_mathsf:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_number_mathsf:n ##1 { #1 {##1} } }, number-math-tt .code:n = - { \cs_set_nopar:Npn \siunitx_number_mathtt:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_number_mathtt:n ##1 { #1 {##1} } }, number-mode .choice:, number-mode / math .code:n = { \bool_set_true:N \l_siunitx_number_math_mode_bool }, number-mode / text .code:n = { \bool_set_false:N \l_siunitx_number_math_mode_bool }, number-text-rm .code:n = - { \cs_set_nopar:Npn \siunitx_number_textrm: {#1} }, + { \cs_set:Npn \siunitx_number_textrm: {#1} }, number-text-sf .code:n = - { \cs_set_nopar:Npn \siunitx_number_textsf: {#1} }, + { \cs_set:Npn \siunitx_number_textsf: {#1} }, number-text-tt .code:n = - { \cs_set_nopar:Npn \siunitx_number_texttt: {#1} } -} -\cs_new_nopar:Npn \siunitx_unit_mathrm: { } -\cs_new_nopar:Npn \siunitx_unit_mathsf: { } -\cs_new_nopar:Npn \siunitx_unit_mathtt: { } -\cs_new_nopar:Npn \siunitx_unit_textrm: { } -\cs_new_nopar:Npn \siunitx_unit_textsf: { } -\cs_new_nopar:Npn \siunitx_unit_texttt: { } + { \cs_set:Npn \siunitx_number_texttt: {#1} } +} +\cs_new:Npn \siunitx_unit_mathrm: { } +\cs_new:Npn \siunitx_unit_mathsf: { } +\cs_new:Npn \siunitx_unit_mathtt: { } +\cs_new:Npn \siunitx_unit_textrm: { } +\cs_new:Npn \siunitx_unit_textsf: { } +\cs_new:Npn \siunitx_unit_texttt: { } \keys_define:nn { siunitx } { unit-color .tl_set:N = \l_siunitx_unit_color_tl, unit-math-rm .code:n = - { \cs_set_nopar:Npn \siunitx_unit_mathrm:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_unit_mathrm:n ##1 { #1 {##1} } }, unit-math-sf .code:n = - { \cs_set_nopar:Npn \siunitx_unit_mathsf:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_unit_mathsf:n ##1 { #1 {##1} } }, unit-math-tt .code:n = - { \cs_set_nopar:Npn \siunitx_unit_mathtt:n ##1 { #1 {##1} } }, + { \cs_set:Npn \siunitx_unit_mathtt:n ##1 { #1 {##1} } }, unit-mode .choice:, unit-mode / math .code:n = { \bool_set_true:N \l_siunitx_unit_math_mode_bool }, unit-mode / text .code:n = { \bool_set_false:N \l_siunitx_unit_math_mode_bool }, unit-text-rm .code:n = - { \cs_set_nopar:Npn \siunitx_unit_textrm: {#1} }, + { \cs_set:Npn \siunitx_unit_textrm: {#1} }, unit-text-sf .code:n = - { \cs_set_nopar:Npn \siunitx_unit_textsf: {#1} }, + { \cs_set:Npn \siunitx_unit_textsf: {#1} }, unit-text-tt .code:n = - { \cs_set_nopar:Npn \siunitx_unit_texttt: {#1} } + { \cs_set:Npn \siunitx_unit_texttt: {#1} } } \keys_define:nn { siunitx } { color .meta:n = @@ -734,7 +718,7 @@ \group_end: } \cs_generate_variant:Nn \siunitx_print:nn { nV } -\cs_new_protected_nopar:Npn \siunitx_print_aux: { +\cs_new_protected:Npn \siunitx_print_aux: { \text { \siunitx_print_color: @@ -750,7 +734,7 @@ { \siunitx_print_text: } } } -\cs_new_protected_nopar:Npn \siunitx_print_color: { +\cs_new_protected:Npn \siunitx_print_color: { \tl_if_empty:cF { l_siunitx_ \l_siunitx_print_type_tl _color_tl } { \color @@ -774,7 +758,7 @@ \char_set_catcode_active:N \! \tl_to_lowercase:n { \group_end: - \cs_set_protected_nopar:Npn \siunitx_print_math: + \cs_set_protected:Npn \siunitx_print_math: { \cs_set_eq:NN \PrintSubscript @ \cs_set_eq:NN \PrintSuperscript ^ @@ -788,8 +772,10 @@ { \l_siunitx_print_arg_tl } } } - \cs_set_protected_nopar:Npn \siunitx_print_text: + \cs_set_protected:Npn \siunitx_print_text: { + \tl_replace_all:Nnn \l_siunitx_print_arg_tl { - } + { \c_siunitx_minus_tl } \cs_set_eq:NN \PrintSubscript \siunitx_print_text_sub:n \cs_set_eq:NN \PrintSuperscript \siunitx_print_text_super:n \tl_replace_all:Nnn \l_siunitx_print_arg_tl { @ } @@ -817,13 +803,13 @@ } } \cs_set_eq:NN \l_peek_search_token \siunitx_print_text_super:n - \cs_set_nopar:Npn \peek_true:w + \cs_set:Npn \peek_true:w { \tex_afterassignment:D \peek_true_aux:w \cs_set_eq:NN \peek_tmp:w } - \cs_set_nopar:Npn \peek_true_aux:w { \siunitx_print_text_sub_super:n } - \cs_set_nopar:Npn \peek_false:w { \ensuremath { @ { \text {#1} } } } + \cs_set:Npn \peek_true_aux:w { \siunitx_print_text_sub_super:n } + \cs_set:Npn \peek_false:w { \ensuremath { @ { \text {#1} } } } \peek_after:Nw \peek_execute_branches_meaning: } } @@ -862,11 +848,11 @@ { \siunitx_number_preprocess_quotient: } } \cs_generate_variant:Nn \siunitx_number_preprocess:n { V } -\cs_new_protected_nopar:Npn \siunitx_number_preprocess_init: { +\cs_new_protected:Npn \siunitx_number_preprocess_init: { \bool_set_false:N \l_siunitx_error_bool \tl_clear:N \l_siunitx_number_multi_tl } -\cs_new_protected_nopar:Npn \siunitx_number_preprocess_product: { +\cs_new_protected:Npn \siunitx_number_preprocess_product: { \tl_map_function:NN \l_siunitx_input_product_tl \siunitx_number_preprocess_product_aux:N } @@ -887,7 +873,7 @@ \tl_map_break: } } -\cs_new_protected_nopar:Npn \siunitx_number_preprocess_quotient: { +\cs_new_protected:Npn \siunitx_number_preprocess_quotient: { \tl_map_function:NN \l_siunitx_input_quotient_tl \siunitx_number_preprocess_quotient_aux:N } @@ -1013,7 +999,7 @@ } \siunitx_number_in_check:n {#1} } -\cs_new_protected_nopar:Npn \siunitx_number_in_init: { +\cs_new_protected:Npn \siunitx_number_in_init: { \cs_set_eq:NN \siunitx_number_in_parse_loop:N \siunitx_number_in_parse_mantissa:N \cs_set_eq:NN \siunitx_number_in_check:n @@ -1027,7 +1013,7 @@ \bool_set_false:N \l_siunitx_number_in_uncert_bool \siunitx_number_in_init_part:n { mantissa } } -\cs_new_protected_nopar:Npn \siunitx_number_in_init_part:n #1 { +\cs_new_protected:Npn \siunitx_number_in_init_part:n #1 { \bool_set_false:N \l_siunitx_number_in_decimal_bool \bool_set_true:N \l_siunitx_number_in_first_bool \bool_set_false:N \l_siunitx_number_in_sign_bool @@ -1040,14 +1026,14 @@ \tl_set:Nn \l_siunitx_number_part_sign_tl { #1 -sign } \tl_set:Nn \l_siunitx_number_part_uncert_tl { #1 -uncertainty } } -\cs_new_protected_nopar:Npn \siunitx_number_in_protect: { +\cs_new_protected:Npn \siunitx_number_in_protect: { \tl_map_function:NN \l_siunitx_input_protect_tl \siunitx_number_in_protect_aux:N } \cs_new_protected:Npn \siunitx_number_in_protect_aux:N #1 { \cs_set_eq:NN #1 \scan_stop: } -\cs_new_protected_nopar:Npn \siunitx_number_in_sign_replace:N #1 { +\cs_new_protected:Npn \siunitx_number_in_sign_replace:N #1 { \tl_replace_all:Nnn #1 { -+ } { \mp } \tl_replace_all:Nnn #1 { +- } { \pm } \tl_replace_all:Nnn #1 { << } { \ll } @@ -1331,7 +1317,7 @@ { \prop_del:Nn \l_siunitx_number_in_prop { mantissa } } } } -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_aux:nn #1#2 { +\cs_new_protected:Npn \siunitx_number_in_complex_aux:nn #1#2 { \prop_get:NnNT \l_siunitx_number_in_prop {#1} \l_siunitx_tmpa_tl { \prop_del:Nn \l_siunitx_number_in_prop {#1} @@ -1466,7 +1452,7 @@ \siunitx_number_in_parse_uncert_after:N } } -\cs_new_protected_nopar:Npn \siunitx_number_in_store: { +\cs_new_protected:Npn \siunitx_number_in_store: { \prop_put:NVn \l_siunitx_number_in_prop \l_siunitx_number_part_tl { true } \bool_if:NTF \l_siunitx_number_in_decimal_bool @@ -1480,8 +1466,8 @@ } \tl_clear:N \l_siunitx_number_parsed_tl } -\cs_new_protected_nopar:Npn \siunitx_number_in_check:n #1 { } -\cs_new_protected_nopar:Npn \siunitx_number_in_check_short:n #1 { +\cs_new_protected:Npn \siunitx_number_in_check:n #1 { } +\cs_new_protected:Npn \siunitx_number_in_check_short:n #1 { \prop_if_in:NVF \l_siunitx_number_in_prop \l_siunitx_number_part_integer_tl { @@ -1507,7 +1493,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_in_check_full:n #1 { +\cs_new_protected:Npn \siunitx_number_in_check_full:n #1 { \tl_if_eq:NNF \l_siunitx_number_part_tl \c_siunitx_number_part_complex_tl { \siunitx_number_in_check_short:n {#1} } @@ -1540,7 +1526,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_to_uncert:n #1 { +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert:n #1 { \prop_del:Nn \l_siunitx_number_in_prop { complex } \prop_del:Nn \l_siunitx_number_in_prop { complex-decimal-marker } \prop_del:Nn \l_siunitx_number_in_prop { complex-sign } @@ -1561,7 +1547,7 @@ \prop_del:Nn \l_siunitx_number_in_prop { complex-integer } \prop_del:Nn \l_siunitx_number_in_prop { complex-decimal } } -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_to_uncert_int: { +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert_int: { \prop_get:NnNF \l_siunitx_number_in_prop { complex-decimal } \l_siunitx_tmpa_tl { \tl_clear:N \l_siunitx_tmpa_tl } @@ -1570,7 +1556,7 @@ { \tl_clear:N \l_siunitx_tmpb_tl } \siunitx_number_in_complex_to_uncert_pad: } -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_to_uncert_dec:n +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert_dec:n #1 { \tl_clear:N \l_siunitx_number_uncert_tl @@ -1589,7 +1575,7 @@ { \siunitx_error:nx { misplaced-sign-token } { \exp_not:n {#1} } } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert_dec_loop:N #1 { \str_if_eq:nnTF {#1} { 0 } @@ -1604,7 +1590,7 @@ } { \tl_map_break: } } -\cs_new_protected_nopar:Npn \siunitx_number_in_complex_to_uncert_pad: +\cs_new_protected:Npn \siunitx_number_in_complex_to_uncert_pad: { \int_set:Nn \l_siunitx_number_uncert_length_int { \tl_length:N \l_siunitx_tmpa_tl } @@ -1660,8 +1646,11 @@ \bool_new:N \l_siunitx_round_bool \tl_new:N \l_siunitx_round_decimal_in_tl \tl_new:N \l_siunitx_round_decimal_out_tl +\tl_new:N \l_siunitx_round_discard_tl +\tl_new:N \l_siunitx_round_even_bool \tl_new:N \l_siunitx_round_integer_in_tl \tl_new:N \l_siunitx_round_integer_out_tl +\bool_new:N \l_siunitx_round_half_up_bool \int_new:N \l_siunitx_process_decimal_int \int_new:N \l_siunitx_process_uncertainty_int \tl_new:N \l_siunitx_uncertainty_decimal_tl @@ -1669,84 +1658,104 @@ \bool_new:N \l_siunitx_process_fixed_bool \bool_new:N \l_siunitx_process_engineering_bool \bool_new:N \l_siunitx_process_scientific_bool -\keys_define:nn { siunitx } { - add-decimal-zero .bool_set:N = \l_siunitx_process_decimal_zero_bool, - add-integer-zero .bool_set:N = \l_siunitx_process_integer_zero_bool, - explicit-sign .tl_set:N = \l_siunitx_process_sign_tl, - fixed-exponent .int_set:N = \l_siunitx_process_fixed_int, - minimum-integer-digits .int_set:N = - \l_siunitx_process_integer_min_int, - retain-explicit-plus .bool_set:N = \l_siunitx_process_plus_tl, - retain-unity-mantissa .bool_set:N = - \l_siunitx_process_unity_mantissa_bool, - retain-zero-exponent .bool_set:N = - \l_siunitx_process_zero_exponent_bool, - round-integer-to-decimal .bool_set:N = - \l_siunitx_process_int_to_dec_bool, - round-minimum .tl_set:N = \l_siunitx_process_round_min_tl, - round-mode .choice: , - round-mode / figures .code:n = - { \tl_set:Nn \l_siunitx_round_tl { figures } }, - round-mode / off .code:n = { \tl_clear:N \l_siunitx_round_tl }, - round-mode / places .code:n = - { \tl_set:Nn \l_siunitx_round_tl { places } }, - round-precision .int_set:N = \l_siunitx_process_precision_int, - scientific-notation .choice: , - scientific-notation - / false .code:n = - { - \bool_set_false:N \l_siunitx_process_fixed_bool - \bool_set_false:N \l_siunitx_process_engineering_bool - \bool_set_false:N \l_siunitx_process_scientific_bool - }, - scientific-notation - / engineering .code:n = - { - \bool_set_false:N \l_siunitx_process_fixed_bool - \bool_set_true:N \l_siunitx_process_engineering_bool - \bool_set_true:N \l_siunitx_process_scientific_bool - }, - scientific-notation - / fixed .code:n = - { - \bool_set_true:N \l_siunitx_process_fixed_bool - \bool_set_false:N \l_siunitx_process_engineering_bool - \bool_set_false:N \l_siunitx_process_scientific_bool - }, - scientific-notation - / true .code:n = - { - \bool_set_false:N \l_siunitx_process_fixed_bool - \bool_set_false:N \l_siunitx_process_engineering_bool - \bool_set_true:N \l_siunitx_process_scientific_bool - }, -} -\keys_set:nn { siunitx } { - add-decimal-zero = true, - add-integer-zero = true, - retain-unity-mantissa = true, - round-precision = 2, -} -\cs_new_protected_nopar:Npn \siunitx_number_process: { - \siunitx_number_process_sign: - \siunitx_number_process_zero_fill: - \siunitx_number_process_mantissa: - \prop_if_in:NnF \l_siunitx_number_in_prop { symbolic } - { - \siunitx_number_process_exponent: - \bool_if:NTF \l_siunitx_process_fixed_bool - { \siunitx_number_process_fixed: } - { - \bool_if:NT \l_siunitx_process_scientific_bool - { \siunitx_number_process_scientific: } - } - \siunitx_number_process_uncertainty: - \prop_if_in:NnF \l_siunitx_number_in_prop { uncertainty } - { \siunitx_number_process_round: } - } - \siunitx_number_process_integer_digits: -} -\cs_new_protected_nopar:Npn \siunitx_number_process_exponent: { +\bool_new:N \l_siunitx_process_drop_exponent_bool +\keys_define:nn { siunitx } + { + add-decimal-zero .bool_set:N = \l_siunitx_process_decimal_zero_bool, + add-integer-zero .bool_set:N = \l_siunitx_process_integer_zero_bool, + explicit-sign .tl_set:N = \l_siunitx_process_sign_tl, + fixed-exponent .int_set:N = \l_siunitx_process_fixed_int, + minimum-integer-digits .int_set:N = + \l_siunitx_process_integer_min_int, + retain-explicit-plus .bool_set:N = \l_siunitx_process_plus_tl, + retain-unity-mantissa .bool_set:N = + \l_siunitx_process_unity_mantissa_bool, + retain-zero-exponent .bool_set:N = + \l_siunitx_process_zero_exponent_bool, + round-half .choice:, + round-half / even .code:n = + { \bool_set_false:N \l_siunitx_round_half_up_bool }, + round-half / up .code:n = + { \bool_set_true:N \l_siunitx_round_half_up_bool }, + round-integer-to-decimal .bool_set:N = + \l_siunitx_process_int_to_dec_bool, + round-minimum .tl_set:N = \l_siunitx_process_round_min_tl, + round-mode .choice: , + round-mode / figures .code:n = + { \tl_set:Nn \l_siunitx_round_tl { figures } }, + round-mode / off .code:n = { \tl_clear:N \l_siunitx_round_tl }, + round-mode / places .code:n = + { \tl_set:Nn \l_siunitx_round_tl { places } }, + round-precision .int_set:N = \l_siunitx_process_precision_int, + scientific-notation .choice: , + scientific-notation + / false .code:n = + { + \bool_set_false:N \l_siunitx_process_fixed_bool + \bool_set_false:N \l_siunitx_process_engineering_bool + \bool_set_false:N \l_siunitx_process_scientific_bool + }, + scientific-notation + / engineering .code:n = + { + \bool_set_false:N \l_siunitx_process_fixed_bool + \bool_set_true:N \l_siunitx_process_engineering_bool + \bool_set_true:N \l_siunitx_process_scientific_bool + }, + scientific-notation + / fixed .code:n = + { + \bool_set_true:N \l_siunitx_process_fixed_bool + \bool_set_false:N \l_siunitx_process_engineering_bool + \bool_set_false:N \l_siunitx_process_scientific_bool + }, + scientific-notation + / true .code:n = + { + \bool_set_false:N \l_siunitx_process_fixed_bool + \bool_set_false:N \l_siunitx_process_engineering_bool + \bool_set_true:N \l_siunitx_process_scientific_bool + } + } +\keys_set:nn { siunitx } + { + add-decimal-zero = true, + add-integer-zero = true, + retain-unity-mantissa = true, + round-half = up, + round-precision = 2 + } +\cs_new_protected:Npn \siunitx_number_process: + { + \siunitx_number_process_sign: + \siunitx_number_process_zero_fill: + \siunitx_number_process_mantissa: + \prop_if_in:NnF \l_siunitx_number_in_prop { symbolic } + { + \siunitx_number_process_exponent: + \bool_if:NTF \l_siunitx_process_fixed_bool + { \siunitx_number_process_fixed: } + { + \bool_if:NT \l_siunitx_process_scientific_bool + { \siunitx_number_process_scientific: } + } + \siunitx_number_process_uncertainty: + \bool_if:NT \l_siunitx_exp_to_prefix_bool + { + \tl_if_empty:NF \l_siunitx_unit_tl + { \siunitx_number_exp_to_prefix: } + } + \prop_if_in:NnF \l_siunitx_number_in_prop { uncertainty } + { \siunitx_number_process_round: } + } + \siunitx_number_process_integer_digits: + \bool_if:NT \l_siunitx_process_drop_exponent_bool + { + \prop_del:Nn \l_siunitx_number_in_prop { exponent } + \prop_del:Nn \l_siunitx_number_in_prop { exponent-integer } + } + } +\cs_new_protected:Npn \siunitx_number_process_exponent: { \bool_if:NF \l_siunitx_process_zero_exponent_bool { \prop_if_in:NnT \l_siunitx_number_in_prop { exponent } @@ -1766,7 +1775,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_process_exponent_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_process_exponent_aux:n #1 { \prop_get:NnNT \l_siunitx_number_in_prop { exponent- #1 } \l_siunitx_tmpa_tl { @@ -1774,142 +1783,144 @@ { \bool_set_true:N \l_siunitx_tmp_bool } } } -\cs_new_protected_nopar:Npn \siunitx_number_process_figures:n #1 { - \int_compare:nNnTF { \l_siunitx_process_precision_int } > { 0 } - { - \prop_if_in:NnT \l_siunitx_number_in_prop {#1} - { \siunitx_number_process_figures_aux:n {#1} } - } - { - \prop_del:Nn \l_siunitx_number_in_prop { #1 -sign } - \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } - \bool_if:NF \l_siunitx_process_int_to_dec_bool - { - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } - } - } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_aux:n #1 { - \siunitx_number_process_figures_init:n {#1} - \siunitx_number_process_figures_count:n { integer } - \siunitx_number_process_figures_count:n { decimal } - \bool_if:NTF \l_siunitx_round_bool - { - \bool_set_false:N \l_siunitx_round_bool - \int_compare:nNnTF - { \l_siunitx_round_int } > - { \l_siunitx_process_precision_int } - { - \siunitx_number_process_figures_round: - \siunitx_number_process_round_tidy:n {#1} - } - { \siunitx_number_process_figures_pad:n {#1} } - } - { - \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } - } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_init:n #1 { - \int_zero:N \l_siunitx_round_int - \bool_set_false:N \l_siunitx_round_bool - \prop_get:NnNF \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_round_decimal_in_tl - { \tl_clear:N \l_siunitx_round_decimal_in_tl } - \prop_get:NnNF \l_siunitx_number_in_prop { #1 -integer } - \l_siunitx_round_integer_in_tl - { \tl_clear:N \l_siunitx_round_integer_in_tl } - \tl_clear:N \l_siunitx_round_decimal_out_tl - \tl_clear:N \l_siunitx_round_integer_out_tl -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_figures_count:n #1 { - \tl_if_empty:cF { l_siunitx_round_ #1 _in_tl } - { - \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -uncertainty } - { \siunitx_number_process_figures_count_aux:n {#1} } - } -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_figures_count_aux:n #1 { - \int_set:Nn \l_siunitx_tmp_int - { \tl_head:v { l_siunitx_round_ #1 _in_tl } } - \tl_set:cx { l_siunitx_round_ #1 _in_tl } - { \tl_tail:v { l_siunitx_round_ #1 _in_tl } } - \tl_put_left:cV { l_siunitx_round_ #1 _out_tl } \l_siunitx_tmp_int - \bool_if:NF \l_siunitx_round_bool - { - \int_compare:nNnF { \l_siunitx_tmp_int } = { 0 } - { \bool_set_true:N \l_siunitx_round_bool } - } - \bool_if:NT \l_siunitx_round_bool - { \int_incr:N \l_siunitx_round_int } - \tl_if_empty:cTF { l_siunitx_round_ #1 _in_tl } - { - \tl_set_eq:cc { l_siunitx_round_ #1 _in_tl } - { l_siunitx_round_ #1 _out_tl } - \tl_clear:c { l_siunitx_round_ #1 _out_tl } - } - { \siunitx_number_process_figures_count_aux:n {#1} } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_round: { - \int_set:Nn \l_siunitx_round_int - { \l_siunitx_round_int - \l_siunitx_process_precision_int } - \tl_if_empty:NF \l_siunitx_round_decimal_in_tl - { \siunitx_number_process_figures_round_loop: } - \tl_if_empty:NF \l_siunitx_round_integer_in_tl - { \siunitx_number_process_figures_integer: } - \bool_if:NT \l_siunitx_round_bool - { - \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 1 } - \tl_if_empty:NF \l_siunitx_round_decimal_out_tl - { - \tl_reverse:N \l_siunitx_round_decimal_out_tl - \tl_set:Nx \l_siunitx_round_decimal_out_tl - { \tl_tail:n \l_siunitx_round_decimal_out_tl } - \tl_reverse:N \l_siunitx_round_decimal_out_tl - } - } -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_figures_round_loop: { - \siunitx_number_process_round_decimal: - \tl_if_empty:NF \l_siunitx_round_decimal_in_tl - { \siunitx_number_process_figures_round_loop: } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_integer: { - \int_compare:nNnT { \l_siunitx_round_int } > { 0 } - { \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 0 } } - \int_compare:nNnF { \l_siunitx_round_int } > { 1 } - { - \int_set:Nn \l_siunitx_tmp_int - { \tl_head:V \l_siunitx_round_integer_in_tl } - \bool_if:NT \l_siunitx_round_bool - { \int_incr:N \l_siunitx_tmp_int } - \bool_set_false:N \l_siunitx_round_bool - \int_compare:nNnTF { \l_siunitx_round_int } = { 1 } - { - \int_compare:nNnT { \l_siunitx_tmp_int } > { 4 } - { \bool_set_true:N \l_siunitx_round_bool } - } - { - \int_compare:nNnT { \l_siunitx_tmp_int } = { 10 } - { - \bool_set_true:N \l_siunitx_round_bool - \int_zero:N \l_siunitx_tmp_int - } - \tl_put_left:NV \l_siunitx_round_integer_out_tl - \l_siunitx_tmp_int - } - } - \int_decr:N \l_siunitx_round_int - \tl_set:Nx \l_siunitx_round_integer_in_tl - { \tl_tail:V \l_siunitx_round_integer_in_tl } - \tl_if_empty:NF \l_siunitx_round_integer_in_tl - { \siunitx_number_process_figures_integer: } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_figures_pad:n #1 { +\cs_new_protected:Npn \siunitx_number_process_figures:n #1 + { + \int_compare:nNnTF \l_siunitx_process_precision_int > \c_zero + { + \prop_if_in:NnT \l_siunitx_number_in_prop {#1} + { \siunitx_number_process_figures_aux:n {#1} } + } + { + \prop_del:Nn \l_siunitx_number_in_prop { #1 -sign } + \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } + \bool_if:NF \l_siunitx_process_int_to_dec_bool + { \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } } + } + } +\cs_new_protected:Npn \siunitx_number_process_figures_aux:n #1 + { + \siunitx_number_process_figures_init:n {#1} + \siunitx_number_process_figures_count:n { integer } + \siunitx_number_process_figures_count:n { decimal } + \bool_if:NTF \l_siunitx_round_bool + { + \bool_set_false:N \l_siunitx_round_bool + \int_compare:nNnTF + \l_siunitx_round_int > \l_siunitx_process_precision_int + { + \siunitx_number_process_figures_round: + \siunitx_number_process_round_tidy:n {#1} + } + { \siunitx_number_process_figures_pad:n {#1} } + } + { + \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } + } + } +\cs_new_protected:Npn \siunitx_number_process_figures_init:n #1 + { + \int_zero:N \l_siunitx_round_int + \bool_set_false:N \l_siunitx_round_bool + \bool_set_false:N \l_siunitx_round_even_bool + \prop_get:NnNF \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_round_decimal_in_tl + { \tl_clear:N \l_siunitx_round_decimal_in_tl } + \prop_get:NnNF \l_siunitx_number_in_prop { #1 -integer } + \l_siunitx_round_integer_in_tl + { \tl_clear:N \l_siunitx_round_integer_in_tl } + \tl_clear:N \l_siunitx_round_decimal_out_tl + \tl_clear:N \l_siunitx_round_integer_out_tl + \tl_clear:N \l_siunitx_round_discard_tl + } +\cs_new_protected:Npn \siunitx_number_process_figures_count:n #1 + { + \tl_if_empty:cF { l_siunitx_round_ #1 _in_tl } + { + \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -uncertainty } + { \siunitx_number_process_figures_count_aux:n {#1} } + } + } +\cs_new_protected:Npn \siunitx_number_process_figures_count_aux:n #1 + { + \int_set:Nn \l_siunitx_tmp_int + { \tl_head:v { l_siunitx_round_ #1 _in_tl } } + \tl_set:cx { l_siunitx_round_ #1 _in_tl } + { \tl_tail:v { l_siunitx_round_ #1 _in_tl } } + \tl_put_left:cV { l_siunitx_round_ #1 _out_tl } \l_siunitx_tmp_int + \bool_if:NF \l_siunitx_round_bool + { + \int_compare:nNnF { \l_siunitx_tmp_int } = \c_zero + { \bool_set_true:N \l_siunitx_round_bool } + } + \bool_if:NT \l_siunitx_round_bool + { \int_incr:N \l_siunitx_round_int } + \tl_if_empty:cTF { l_siunitx_round_ #1 _in_tl } + { + \tl_set_eq:cc { l_siunitx_round_ #1 _in_tl } + { l_siunitx_round_ #1 _out_tl } + \tl_clear:c { l_siunitx_round_ #1 _out_tl } + } + { \siunitx_number_process_figures_count_aux:n {#1} } + } +\cs_new_protected:Npn \siunitx_number_process_figures_round: + { + \int_set:Nn \l_siunitx_round_int + { \l_siunitx_round_int - \l_siunitx_process_precision_int } + \tl_if_empty:NF \l_siunitx_round_decimal_in_tl + { \siunitx_number_process_figures_round_loop: } + \tl_if_empty:NF \l_siunitx_round_integer_in_tl + { \siunitx_number_process_figures_integer: } + \bool_if:NT \l_siunitx_round_bool + { + \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 1 } + \tl_if_empty:NF \l_siunitx_round_decimal_out_tl + { + \tl_reverse:N \l_siunitx_round_decimal_out_tl + \tl_set:Nx \l_siunitx_round_decimal_out_tl + { \tl_tail:n \l_siunitx_round_decimal_out_tl } + \tl_reverse:N \l_siunitx_round_decimal_out_tl + } + } + } +\cs_new_protected:Npn \siunitx_number_process_figures_round_loop: + { + \siunitx_number_process_round_decimal: + \tl_if_empty:NF \l_siunitx_round_decimal_in_tl + { \siunitx_number_process_figures_round_loop: } + } +\cs_new_protected:Npn \siunitx_number_process_figures_integer: + { + \int_compare:nNnT \l_siunitx_round_int > \c_zero + { \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 0 } } + \int_compare:nNnF \l_siunitx_round_int > \c_one + { + \int_set:Nn \l_siunitx_tmp_int + { \tl_head:V \l_siunitx_round_integer_in_tl } + \siunitx_number_process_round_up: + \int_compare:nNnTF \l_siunitx_round_int = \c_one + { + \int_compare:nNnT \l_siunitx_tmp_int > \c_four + { \bool_set_true:N \l_siunitx_round_bool } + } + { + \int_compare:nNnT \l_siunitx_tmp_int = \c_ten + { + \bool_set_true:N \l_siunitx_round_bool + \int_zero:N \l_siunitx_tmp_int + } + \tl_put_left:NV \l_siunitx_round_integer_out_tl + \l_siunitx_tmp_int + } + } + \int_decr:N \l_siunitx_round_int + \tl_set:Nx \l_siunitx_round_integer_in_tl + { \tl_tail:V \l_siunitx_round_integer_in_tl } + \tl_if_empty:NF \l_siunitx_round_integer_in_tl + { \siunitx_number_process_figures_integer: } + } +\cs_new_protected:Npn \siunitx_number_process_figures_pad:n #1 { \prop_get:NnN \l_siunitx_number_in_prop { #1 -integer } \l_siunitx_round_integer_in_tl \prop_get:NnN \l_siunitx_number_in_prop { #1 -decimal } @@ -1918,7 +1929,7 @@ { \l_siunitx_process_precision_int - \l_siunitx_round_int } \siunitx_number_process_pad:n {#1} } -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed: { +\cs_new_protected:Npn \siunitx_number_process_fixed: { \prop_if_in:NnF \l_siunitx_number_in_prop { complex } { \prop_get:NnNF \l_siunitx_number_in_prop { mantissa-integer } @@ -1946,7 +1957,7 @@ \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_fixed_aux_i:nnn #1#2#3 { \prop_put:Nnn \l_siunitx_number_in_prop { exponent } { true } @@ -1964,7 +1975,7 @@ \int_compare:nNnF { #1 + 0 #2 } = { 0 } { \siunitx_number_process_fixed_aux_ii:nnn {#1} {#2} {#3} } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_fixed_aux_ii:nnn #1#2#3 { \int_compare:nNnTF {#3} > { \l_siunitx_process_fixed_int } { \siunitx_number_process_fixed_large:nnn {#1} {#2} {#3} } @@ -1994,15 +2005,15 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed_large:nnn #1 +\cs_new_protected:Npn \siunitx_number_process_fixed_large:nnn #1 { \int_compare:nNnTF {#1} = \c_zero { \siunitx_number_process_fixed_large_aux:nnn { } } { \siunitx_number_process_fixed_large_aux:nnn {#1} } } -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed_large_aux:nnn #1#2#3 +\cs_new_protected:Npn \siunitx_number_process_fixed_large_aux:nnn #1#2#3 { - \cs_set_protected_nopar:Npn + \cs_set_protected:Npn \siunitx_number_process_fixed_large_aux:w ##1##2 \q_stop { \tl_if_empty:nTF {##2} @@ -2034,11 +2045,11 @@ { \siunitx_number_process_fixed_aux_ii:nnn { #1 0 } { } { #3 - 1 } } { \siunitx_number_process_fixed_large_aux:w #2 \q_stop } } -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed_large_aux:w +\cs_new_protected:Npn \siunitx_number_process_fixed_large_aux:w { } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_fixed_small:nnn #1#2#3 { - \cs_set_protected_nopar:Npn + \cs_set_protected:Npn \siunitx_number_process_fixed_small_aux:w ##1##2 \q_stop ##3 { \tl_if_empty:nTF {##2} @@ -2060,9 +2071,9 @@ } \siunitx_number_process_fixed_small_aux:w #1 \q_stop { } } -\cs_new_protected_nopar:Npn \siunitx_number_process_fixed_small_aux:w +\cs_new_protected:Npn \siunitx_number_process_fixed_small_aux:w { } -\cs_new_protected_nopar:Npn \siunitx_number_process_integer_digits: { +\cs_new_protected:Npn \siunitx_number_process_integer_digits: { \int_compare:nNnT { \l_siunitx_process_integer_min_int } > { \c_zero } { @@ -2087,7 +2098,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_process_mantissa: { +\cs_new_protected:Npn \siunitx_number_process_mantissa: { \bool_if:NF \l_siunitx_process_unity_mantissa_bool { \prop_if_in:NnT \l_siunitx_number_in_prop { exponent } @@ -2112,7 +2123,7 @@ } \tl_new:N \c_siunitx_unity_tl \tl_set:Nn \c_siunitx_unity_tl { 1 } -\cs_new_protected_nopar:Npn \siunitx_number_process_pad:n #1 { +\cs_new_protected:Npn \siunitx_number_process_pad:n #1 { \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } \l_siunitx_tmpa_tl { @@ -2125,233 +2136,263 @@ \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_process_places:n #1 { - \prop_if_in:NnT \l_siunitx_number_in_prop {#1} - { - \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -uncertainty } - { \siunitx_number_process_places_aux_i:n {#1} } - } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_places_aux_i:n #1 { - \int_compare:nNnTF { \l_siunitx_process_precision_int } = { 0 } - { - \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_tmpa_tl - { - \int_compare:nNnTF - { \tl_head:V \l_siunitx_tmpa_tl } > { 4 } - { - \prop_get:NnNTF \l_siunitx_number_in_prop { #1 -integer } - \l_siunitx_tmpa_tl - { - \tl_set:Nx \l_siunitx_tmpa_tl - { \int_eval:n { \l_siunitx_tmpa_tl + 1 } } - \prop_put:NnV \l_siunitx_number_in_prop - { #1 -integer } \l_siunitx_tmpa_tl - } - { - \prop_put:Nnn \l_siunitx_number_in_prop - { #1 -integer } { 1 } - } - - } - { - \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -integer } - { - \prop_put:Nnn \l_siunitx_number_in_prop - { #1 -integer } { 0 } - } - } - } - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } - \bool_if:NF \l_siunitx_process_int_to_dec_bool - { - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } - } - } - { - \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_tmpa_tl - { - \tl_if_empty:NT \l_siunitx_tmpa_tl - { \tl_set:Nn \l_siunitx_tmpa_tl { 0 } } - \int_compare:nNnTF { \l_siunitx_tmpa_tl } = { 0 } - { - \prop_put:Nnn \l_siunitx_number_in_prop { #1 -decimal } - { } - \int_set:Nn \l_siunitx_round_int - { \l_siunitx_process_precision_int } - \siunitx_number_process_pad:n {#1} - } - { - \int_set:Nn \l_siunitx_round_int - { \tl_length:N \l_siunitx_tmpa_tl } - \siunitx_number_process_places_aux_ii:n {#1} - } - } - } -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_places_aux_ii:n #1 { - \int_sub:Nn \l_siunitx_round_int - { \l_siunitx_process_precision_int } - \int_compare:nNnTF { \l_siunitx_round_int } < { 0 } - { - \int_set:Nn \l_siunitx_round_int { - \l_siunitx_round_int } - \siunitx_number_process_pad:n {#1} - } - { - \siunitx_number_process_places_init:n {#1} - \siunitx_number_process_places_loop:n {#1} - \siunitx_number_process_round_tidy:n {#1} - } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_places_init:n #1 { - \prop_get:NnNF \l_siunitx_number_in_prop { #1 -integer } - \l_siunitx_round_integer_in_tl - { \tl_clear:N \l_siunitx_round_integer_in_tl } - \prop_get:NnN \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_round_decimal_in_tl - \tl_reverse:N \l_siunitx_round_integer_in_tl - \tl_reverse:N \l_siunitx_round_decimal_in_tl - \tl_clear:N \l_siunitx_round_integer_out_tl - \tl_clear:N \l_siunitx_round_decimal_out_tl - \bool_set_false:N \l_siunitx_round_bool -} -\cs_new_protected_nopar:Npn \siunitx_number_process_places_loop:n #1 { - \tl_if_empty:NTF \l_siunitx_round_decimal_in_tl - { - \tl_if_empty:NF \l_siunitx_round_integer_in_tl - { - \siunitx_number_process_places_integer:n {#1} - \siunitx_number_process_places_loop:n {#1} - } - \bool_if:NT \l_siunitx_round_bool - { - \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 1 } - \bool_set_false:N \l_siunitx_round_bool - } - } - { - \siunitx_number_process_round_decimal: - \siunitx_number_process_places_loop:n {#1} - } -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_places_integer:n #1 { - \int_set:Nn \l_siunitx_tmp_int - { \tl_head:V \l_siunitx_round_integer_in_tl } - \tl_set:Nx \l_siunitx_round_integer_in_tl - { \tl_tail:V \l_siunitx_round_integer_in_tl } - \bool_if:NT \l_siunitx_round_bool - { \int_incr:N \l_siunitx_tmp_int } - \bool_set_false:N \l_siunitx_round_bool - \int_compare:nNnT { \l_siunitx_tmp_int } = { 10 } - { - \int_zero:N \l_siunitx_tmp_int - \bool_set_true:N \l_siunitx_round_bool - } - \tl_put_left:NV \l_siunitx_round_integer_out_tl \l_siunitx_tmp_int -} -\cs_new_protected_nopar:Npn \siunitx_number_process_round: { - \tl_if_empty:NF \l_siunitx_round_tl - { - \bool_if:NT \l_siunitx_process_int_to_dec_bool - { - \prop_if_in:NnF \l_siunitx_number_in_prop - { mantissa-decimal } - { - \prop_put:Nnn \l_siunitx_number_in_prop - { mantissa-decimal } { 0 } - } - \prop_if_in:NnF \l_siunitx_number_in_prop - { mantissa-decimal-marker } - { - \prop_put:Nnn \l_siunitx_number_in_prop - { mantissa-decimal-marker } { . } - } - } - \cs_set_nopar:Npx \siunitx_tmp:w - { - \exp_not:N \clist_map_function:nN - { mantissa , complex } - \exp_not:c - { siunitx_number_process_ \l_siunitx_round_tl :n } - } - \siunitx_tmp:w - } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_round_decimal: { - \int_compare:nNnF { \l_siunitx_round_int } > { 1 } - { \siunitx_number_process_round_decimal_aux: } - \tl_set:Nx \l_siunitx_round_decimal_in_tl - { \tl_tail:V \l_siunitx_round_decimal_in_tl } - \int_decr:N \l_siunitx_round_int -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_round_decimal_aux: { - \int_set:Nn \l_siunitx_tmp_int - { \tl_head:V \l_siunitx_round_decimal_in_tl } - \bool_if:NT \l_siunitx_round_bool - { \int_incr:N \l_siunitx_tmp_int } - \bool_set_false:N \l_siunitx_round_bool - \int_compare:nNnTF { \l_siunitx_round_int } = { 1 } - { - \int_compare:nNnT { \l_siunitx_tmp_int } > { 4 } - { \bool_set_true:N \l_siunitx_round_bool } - } - { - \int_compare:nNnT { \l_siunitx_tmp_int } = { 10 } - { - \bool_set_true:N \l_siunitx_round_bool - \int_zero:N \l_siunitx_tmp_int - } - \tl_put_left:NV \l_siunitx_round_decimal_out_tl - \l_siunitx_tmp_int - } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_round_tidy:n #1 { - \int_compare:nNnTF - { - 0 \l_siunitx_round_integer_out_tl + - 0 \l_siunitx_round_decimal_out_tl - } - = { 0 } - { - \fp_compare:nNnTF { \l_siunitx_process_round_min_tl } = { 0 } - { - \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } - \prop_put:NnV \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_round_decimal_out_tl - } - { - \exp_after:wN \siunitx_number_process_round_tidy_aux:w - \l_siunitx_process_round_min_tl . . \q_stop {#1} - } - } - { - \prop_put:NnV \l_siunitx_number_in_prop { #1 -integer } - \l_siunitx_round_integer_out_tl - \tl_if_empty:NTF \l_siunitx_round_decimal_out_tl - { - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } - \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } - } - { - \prop_put:NnV \l_siunitx_number_in_prop { #1 -decimal } - \l_siunitx_round_decimal_out_tl - } - } -} -\cs_new_protected_nopar:Npn - \siunitx_number_process_round_tidy_aux:w #1 . #2 . #3 \q_stop #4 { - \prop_put:Nnn \l_siunitx_number_in_prop { comparator } { < } - \prop_put:Nnn \l_siunitx_number_in_prop { #4 -integer } {#1} - \tl_if_empty:nTF {#2} - { \prop_del:Nn \l_siunitx_number_in_prop { #4 -decimal } } - { \prop_put:Nnn \l_siunitx_number_in_prop { #4 -decimal } {#2} } -} -\cs_new_protected_nopar:Npn \siunitx_number_process_scientific: { +\cs_new_protected:Npn \siunitx_number_process_places:n #1 + { + \prop_if_in:NnT \l_siunitx_number_in_prop {#1} + { + \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -uncertainty } + { \siunitx_number_process_places_aux_i:n {#1} } + } + } +\cs_new_protected:Npn \siunitx_number_process_places_aux_i:n #1 + { + \int_compare:nNnTF \l_siunitx_process_precision_int = \c_zero + { \siunitx_number_process_places_none:n {#1} } + { + \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_tmpa_tl + { + \tl_if_empty:NT \l_siunitx_tmpa_tl + { \tl_set:Nn \l_siunitx_tmpa_tl { 0 } } + \int_compare:nNnTF \l_siunitx_tmpa_tl = \c_zero + { + \prop_put:Nnn \l_siunitx_number_in_prop { #1 -decimal } { } + \int_set:Nn \l_siunitx_round_int + { \l_siunitx_process_precision_int } + \siunitx_number_process_pad:n {#1} + } + { + \int_set:Nn \l_siunitx_round_int + { \tl_length:N \l_siunitx_tmpa_tl } + \siunitx_number_process_places_aux_ii:n {#1} + } + } + } + } +\cs_new_protected:Npn \siunitx_number_process_places_none:n #1 + { + \prop_get:NnNT \l_siunitx_number_in_prop { #1 -decimal } \l_siunitx_tmpa_tl + { + \int_compare:nNnTF { \tl_head:V \l_siunitx_tmpa_tl } > \c_four + { + \prop_get:NnNTF \l_siunitx_number_in_prop { #1 -integer } + \l_siunitx_tmpb_tl + { + \tl_set:Nx \l_siunitx_tmpb_tl + { \int_eval:n { \l_siunitx_tmpb_tl + 1 } } + \bool_if:NF \l_siunitx_round_half_up_bool + { + \int_compare:nNnT + { 0 \tl_tail:V \l_siunitx_tmpa_tl } = \c_zero + { + \int_if_odd:nT \l_siunitx_tmpb_tl + { + \tl_set:Nx \l_siunitx_tmpb_tl + { \int_eval:n { \l_siunitx_tmpb_tl - 1 } } + } + } + } + } + { \tl_set:Nn \l_siunitx_tmpb_tl { 1 } } + \prop_put:NnV \l_siunitx_number_in_prop + { #1 -integer } \l_siunitx_tmpb_tl + } + { + \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -integer } + { + \prop_put:Nnn \l_siunitx_number_in_prop + { #1 -integer } { 0 } + } + } + } + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } + \bool_if:NF \l_siunitx_process_int_to_dec_bool + { \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } } + } +\cs_new_protected:Npn \siunitx_number_process_places_aux_ii:n #1 + { + \int_sub:Nn \l_siunitx_round_int + { \l_siunitx_process_precision_int } + \int_compare:nNnTF \l_siunitx_round_int < \c_zero + { + \int_set:Nn \l_siunitx_round_int { - \l_siunitx_round_int } + \siunitx_number_process_pad:n {#1} + } + { + \siunitx_number_process_places_init:n {#1} + \siunitx_number_process_places_loop:n {#1} + \siunitx_number_process_round_tidy:n {#1} + } + } +\cs_new_protected:Npn \siunitx_number_process_places_init:n #1 + { + \prop_get:NnNF \l_siunitx_number_in_prop { #1 -integer } + \l_siunitx_round_integer_in_tl + { \tl_clear:N \l_siunitx_round_integer_in_tl } + \prop_get:NnN \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_round_decimal_in_tl + \tl_reverse:N \l_siunitx_round_integer_in_tl + \tl_reverse:N \l_siunitx_round_decimal_in_tl + \tl_clear:N \l_siunitx_round_integer_out_tl + \tl_clear:N \l_siunitx_round_decimal_out_tl + \tl_clear:N \l_siunitx_round_discard_tl + \bool_set_false:N \l_siunitx_round_bool + \bool_set_false:N \l_siunitx_round_even_bool + } +\cs_new_protected:Npn \siunitx_number_process_places_loop:n #1 + { + \tl_if_empty:NTF \l_siunitx_round_decimal_in_tl + { + \tl_if_empty:NF \l_siunitx_round_integer_in_tl + { + \siunitx_number_process_places_integer:n {#1} + \siunitx_number_process_places_loop:n {#1} + } + \bool_if:NT \l_siunitx_round_bool + { + \tl_put_left:Nn \l_siunitx_round_integer_out_tl { 1 } + \bool_set_false:N \l_siunitx_round_bool + } + } + { + \siunitx_number_process_round_decimal: + \siunitx_number_process_places_loop:n {#1} + } + } +\cs_new_protected:Npn \siunitx_number_process_places_integer:n #1 + { + \int_set:Nn \l_siunitx_tmp_int + { \tl_head:V \l_siunitx_round_integer_in_tl } + \tl_set:Nx \l_siunitx_round_integer_in_tl + { \tl_tail:V \l_siunitx_round_integer_in_tl } + \siunitx_number_process_round_up: + \bool_set_false:N \l_siunitx_round_bool + \int_compare:nNnT \l_siunitx_tmp_int = \c_ten + { + \int_zero:N \l_siunitx_tmp_int + \bool_set_true:N \l_siunitx_round_bool + } + \tl_put_left:NV \l_siunitx_round_integer_out_tl \l_siunitx_tmp_int + } +\cs_new_protected:Npn \siunitx_number_process_round: + { + \tl_if_empty:NF \l_siunitx_round_tl + { + \bool_if:NT \l_siunitx_process_int_to_dec_bool + { + \prop_if_in:NnF \l_siunitx_number_in_prop { mantissa-decimal } + { + \prop_put:Nnn \l_siunitx_number_in_prop { mantissa-decimal } + { 0 } + } + \prop_if_in:NnF \l_siunitx_number_in_prop + { mantissa-decimal-marker } + { + \prop_put:Nnn \l_siunitx_number_in_prop + { mantissa-decimal-marker } { . } + } + } + \clist_map_function:nc { mantissa , complex } + { siunitx_number_process_ \l_siunitx_round_tl :n } + } + } +\cs_new_protected:Npn \siunitx_number_process_round_decimal: + { + \int_compare:nNnF \l_siunitx_round_int > \c_one + { \siunitx_number_process_round_decimal_aux: } + \tl_put_right:Nx \l_siunitx_round_discard_tl + { \tl_head:V \l_siunitx_round_decimal_in_tl } + \tl_set:Nx \l_siunitx_round_decimal_in_tl + { \tl_tail:V \l_siunitx_round_decimal_in_tl } + \int_decr:N \l_siunitx_round_int + } +\cs_new_protected:Npn \siunitx_number_process_round_decimal_aux: + { + \int_set:Nn \l_siunitx_tmp_int + { \tl_head:V \l_siunitx_round_decimal_in_tl } + \siunitx_number_process_round_up: + \int_compare:nNnTF \l_siunitx_round_int = \c_one + { + \int_compare:nNnT \l_siunitx_tmp_int > \c_four + { + \bool_set_true:N \l_siunitx_round_bool + \bool_if:NF \l_siunitx_round_half_up_bool + { + \int_compare:nNnT + { \l_siunitx_round_discard_tl \int_use:N \l_siunitx_tmp_int } + = \c_five + { \bool_set_true:N \l_siunitx_round_even_bool } + } + } + } + { + \int_compare:nNnT \l_siunitx_tmp_int = \c_ten + { + \bool_set_true:N \l_siunitx_round_bool + \int_zero:N \l_siunitx_tmp_int + } + \tl_put_left:NV \l_siunitx_round_decimal_out_tl + \l_siunitx_tmp_int + } + } +\cs_new_protected:Npn \siunitx_number_process_round_up: + { + \bool_if:NT \l_siunitx_round_bool + { + \bool_if:NTF \l_siunitx_round_even_bool + { + \bool_set_false:N \l_siunitx_round_even_bool + \int_if_even:nF \l_siunitx_tmp_int + { \int_incr:N \l_siunitx_tmp_int } + } + { \int_incr:N \l_siunitx_tmp_int } + } + \bool_set_false:N \l_siunitx_round_bool + } +\cs_new_protected:Npn \siunitx_number_process_round_tidy:n #1 + { + \int_compare:nNnTF + { + 0 \l_siunitx_round_integer_out_tl + + 0 \l_siunitx_round_decimal_out_tl + } + = \c_zero + { + \fp_compare:nNnTF { \l_siunitx_process_round_min_tl } = { 0 } + { + \prop_put:Nnn \l_siunitx_number_in_prop { #1 -integer } { 0 } + \prop_put:NnV \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_round_decimal_out_tl + } + { + \exp_after:wN \siunitx_number_process_round_tidy_aux:w + \l_siunitx_process_round_min_tl . . \q_stop {#1} + } + } + { + \prop_put:NnV \l_siunitx_number_in_prop { #1 -integer } + \l_siunitx_round_integer_out_tl + \tl_if_empty:NTF \l_siunitx_round_decimal_out_tl + { + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal } + \prop_del:Nn \l_siunitx_number_in_prop { #1 -decimal-marker } + } + { + \prop_put:NnV \l_siunitx_number_in_prop { #1 -decimal } + \l_siunitx_round_decimal_out_tl + } + } + } +\cs_new_protected:Npn \siunitx_number_process_round_tidy_aux:w + #1 . #2 . #3 \q_stop #4 + { + \prop_put:Nnn \l_siunitx_number_in_prop { comparator } { < } + \prop_put:Nnn \l_siunitx_number_in_prop { #4 -integer } {#1} + \tl_if_empty:nTF {#2} + { \prop_del:Nn \l_siunitx_number_in_prop { #4 -decimal } } + { \prop_put:Nnn \l_siunitx_number_in_prop { #4 -decimal } {#2} } + } +\cs_new_protected:Npn \siunitx_number_process_scientific: { \prop_if_in:NnF \l_siunitx_number_in_prop { complex } { \prop_get:NnNF \l_siunitx_number_in_prop { mantissa-integer } @@ -2377,12 +2418,12 @@ \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_aux_i:nnn #1#2#3 { \int_compare:nNnF { #1 + 0 #2 } = { 0 } { \siunitx_number_process_scientific_aux_ii:nnn {#1} {#2} {#3} } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_aux_ii:nnn #1#2#3 { \int_compare:nNnTF {#1} > { 9 } { \siunitx_number_process_scientific_large:nnn {#1} {#2} {#3} } @@ -2400,7 +2441,7 @@ } } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_large:nnn #1#2#3 { \int_set:Nn \l_siunitx_tmp_int { \int_div_truncate:nn {#1} { 10 } } \tl_set:Nx \l_siunitx_tmpa_tl { \int_use:N \l_siunitx_tmp_int } @@ -2413,10 +2454,10 @@ \exp_after:wN \siunitx_number_process_scientific_aux_ii:nnn \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_small:wn #1#2 \q_stop #3 { \siunitx_number_process_scientific_aux_ii:nnn {#1} {#2} { #3 - 1 } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_store:nnn #1#2#3 { \prop_put:Nnn \l_siunitx_number_in_prop { mantissa-integer } {#1} @@ -2460,7 +2501,7 @@ } } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_scientific_engineering:nnn #1#2#3 { \use:c @@ -2483,7 +2524,7 @@ \cs_new_eq:cN { siunitx_number_process_scientific_engineering_0:nnn } \siunitx_number_process_scientific_store:nnn -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_1:nnn } #1#2#3 { \tl_if_empty:nTF {#2} @@ -2497,14 +2538,14 @@ {#1} #2 \q_stop {#3} } } -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_1:nw } #1#2#3 \q_stop #4 { \siunitx_number_process_scientific_store:nnn {#1#2} {#3} { #4 - 1 } } -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_2:nnn } #1#2#3 { \tl_if_empty:nTF {#2} @@ -2518,7 +2559,7 @@ {#1} #2 \q_stop {#3} } } -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_2_i:nw } #1#2#3 \q_stop #4 { @@ -2533,14 +2574,14 @@ {#1#2} #3 \q_stop {#4} } } -\cs_new_protected_nopar:cpn +\cs_new_protected:cpn { siunitx_number_process_scientific_engineering_2_ii:nw } #1#2#3 \q_stop #4 { \siunitx_number_process_scientific_store:nnn { #1#2 } {#3} { #4 - 2 } } -\cs_new_protected_nopar:Npn \siunitx_number_process_sign: { +\cs_new_protected:Npn \siunitx_number_process_sign: { \bool_if:NF \l_siunitx_process_plus_tl { \prop_if_in:NnTF \l_siunitx_number_in_prop { mantissa-sign } @@ -2562,7 +2603,7 @@ { \siunitx_number_process_sign_add:n { complex } } } } -\cs_new_protected_nopar:Npn \siunitx_number_process_sign_add:n #1 { +\cs_new_protected:Npn \siunitx_number_process_sign_add:n #1 { \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -sign } { \prop_if_in:NnF \l_siunitx_number_in_prop { #1 -had-sign } @@ -2581,7 +2622,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_process_sign_plus:n #1 { +\cs_new_protected:Npn \siunitx_number_process_sign_plus:n #1 { \prop_get:NnN \l_siunitx_number_in_prop { #1 -sign } \l_siunitx_tmpa_tl \tl_if_eq:NNT \c_siunitx_plus_tl \l_siunitx_tmpa_tl @@ -2592,11 +2633,11 @@ } \tl_new:N \c_siunitx_plus_tl \tl_set:Nn \c_siunitx_plus_tl { + } -\cs_new_protected_nopar:Npn \siunitx_number_process_uncertainty: { +\cs_new_protected:Npn \siunitx_number_process_uncertainty: { \clist_map_function:nN { mantissa , complex } \siunitx_number_process_uncertainty_aux:n } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_aux:n #1 { \prop_if_in:NnT \l_siunitx_number_in_prop { #1 -uncertainty } { @@ -2605,7 +2646,7 @@ { \siunitx_number_process_uncertainty_integer:n {#1} } } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_decimal:n #1 { \siunitx_number_process_uncertainty_count:nn {#1} { decimal } \siunitx_number_process_uncertainty_count:nn {#1} { uncertainty } @@ -2629,14 +2670,14 @@ \prop_put:NnV \l_siunitx_number_in_prop { #1 -uncertainty-decimal-marker } \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_count:nn #1#2 { \prop_get:NnN \l_siunitx_number_in_prop { #1 - #2 } \l_siunitx_tmpa_tl \int_set:cn { l_siunitx_process_ #2 _int } { \tl_length:N \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_process_uncertainty_pad: { +\cs_new_protected:Npn \siunitx_number_process_uncertainty_pad: { \int_while_do:nNnn { \l_siunitx_process_uncertainty_int } < { \l_siunitx_process_decimal_int } @@ -2647,7 +2688,7 @@ \tl_put_right:NV \l_siunitx_uncertainty_decimal_tl \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_separate: { \tl_map_function:NN \l_siunitx_tmpa_tl \siunitx_number_process_uncertainty_separate_aux:N @@ -2661,18 +2702,18 @@ { \tl_put_right:Nn \l_siunitx_uncertainty_decimal_tl {#1} } \int_decr:N \l_siunitx_process_uncertainty_int } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_uncertainty_integer:n #1 { \prop_get:NnN \l_siunitx_number_in_prop { #1 -uncertainty } \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_in_prop { #1 -uncertainty-integer } \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn \siunitx_number_process_zero_fill: { +\cs_new_protected:Npn \siunitx_number_process_zero_fill: { \siunitx_number_process_zero_fill_aux:n { integer } \siunitx_number_process_zero_fill_aux:n { decimal } } -\cs_new_nopar:Npn \siunitx_number_process_zero_fill_aux:n #1 { +\cs_new:Npn \siunitx_number_process_zero_fill_aux:n #1 { \bool_if:cT { l_siunitx_process_ #1 _zero_bool } { \siunitx_number_process_zero_fill_aux:nn { mantissa } {#1} @@ -2680,7 +2721,7 @@ \siunitx_number_process_zero_fill_aux:nn { exponent } {#1} } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_process_zero_fill_aux:nn #1#2 { \prop_if_in:NnT \l_siunitx_number_in_prop { #1 -decimal-marker } { @@ -2688,6 +2729,41 @@ { \prop_put:Nnn \l_siunitx_number_in_prop { #1 - #2 } { 0 } } } } +\cs_new_protected:Npn \siunitx_number_exp_to_prefix: + { + \prop_set_eq:NN \l_siunitx_unit_prop \l_siunitx_unit_saved_prop + \prop_get:NnNT \l_siunitx_number_in_prop { exponent-integer } + \l_siunitx_tmpa_tl + { + \prop_get:NnNT \l_siunitx_number_in_prop { exponent-sign } + \l_siunitx_tmpb_tl + { \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_tmpb_tl } + \prop_get:NnNT \l_siunitx_unit_prop { prefix-1 } \l_siunitx_tmpb_tl + { + \prop_del:Nn \l_siunitx_unit_prop { prefix-1 } + \prop_del:Nn \l_siunitx_unit_prop { prefix-symbol-1 } + \prop_get:NVN \l_siunitx_prefix_forward_prop \l_siunitx_tmpb_tl + \l_siunitx_tmpb_tl + \tl_set:Nx \l_siunitx_tmpa_tl + { \int_eval:n { \l_siunitx_tmpa_tl + \l_siunitx_tmpb_tl } } + } + \prop_get:NVNTF \l_siunitx_prefix_reverse_prop \l_siunitx_tmpa_tl + \l_siunitx_tmpb_tl + { + \prop_del:Nn \l_siunitx_number_in_prop { exponent } + \use:c + { + siunitx_ \exp_after:wN \token_to_str:N \l_siunitx_tmpb_tl + _function:w + } + \siunitx_unit_format: + } + { + \msg_error:nnx { siunitx } { non-convertible-exponent } + { \l_siunitx_tmpa_tl } + } + } + } \prop_new:N \l_siunitx_number_out_prop \tl_new:N \l_siunitx_group_sep_tl \tl_new:N \l_siunitx_output_decimal_tl @@ -2764,23 +2840,24 @@ tight-spacing .bool_set:N = \l_siunitx_tight_bool, uncertainty-separator .tl_set:N = \l_siunitx_uncert_sep_tl, } -\keys_set:nn { siunitx } { - bracket-numbers = true, % ( - close-bracket = ), - complex-root-position = after-number, - copy-decimal-marker = false, - exponent-base = 10, - exponent-product = \times, - group-digits = true, - group-minimum-digits = 5, - group-separator = \,, - open-bracket = (, % ) ( - output-close-uncertainty = ), - output-complex-root = \mathrm { i }, - output-decimal-marker = ., - output-open-uncertainty = (, % ) -} -\cs_new_protected_nopar:Npn \siunitx_number_format: { +\keys_set:nn { siunitx } + { + bracket-numbers = true , % ( + close-bracket = ) , + complex-root-position = after-number , + copy-decimal-marker = false , + exponent-base = 10 , + exponent-product = \times , + group-digits = true , + group-minimum-digits = 5 , + group-separator = \, , + open-bracket = ( , % ) ( + output-close-uncertainty = ) , + output-complex-root = \ensuremath { \mathrm { i } } , + output-decimal-marker = . , + output-open-uncertainty = ( % ) + } +\cs_new_protected:Npn \siunitx_number_format: { \prop_if_empty:NF \l_siunitx_number_in_prop { \prop_clear:N \l_siunitx_number_out_prop @@ -2793,7 +2870,7 @@ \siunitx_number_format_final: } } -\cs_new_protected_nopar:Npn \siunitx_number_format_brackets:n #1 { +\cs_new_protected:Npn \siunitx_number_format_brackets:n #1 { \bool_if:NT \l_siunitx_brackets_bool { \prop_if_in:NnT \l_siunitx_number_out_prop { #1 -bracket } @@ -2803,16 +2880,14 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_brackets_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_format_brackets_aux:n #1 { \prop_get:NnNF \l_siunitx_number_out_prop { #1 -result } \l_siunitx_tmpa_tl { \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl } - \siunitx_tl_put_left_math:NV \l_siunitx_tmpa_tl - \l_siunitx_bracket_open_tl - \siunitx_tl_put_right_math:NV \l_siunitx_tmpa_tl - \l_siunitx_bracket_close_tl + \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_bracket_open_tl + \tl_put_right:NV \l_siunitx_tmpa_tl \l_siunitx_bracket_close_tl \str_if_eq:nnTF {#1} { result } { \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl } { @@ -2820,14 +2895,14 @@ \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_format_color: { +\cs_new_protected:Npn \siunitx_number_format_color: { \tl_if_empty:NF \l_siunitx_negative_color_tl { \siunitx_number_format_color_aux:n { mantissa-sign } \siunitx_number_format_color_aux:n { sign } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_color_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_format_color_aux:n #1 { \prop_get:NnNT \l_siunitx_number_in_prop {#1} \l_siunitx_tmpa_tl { \str_if_eq:VnT \l_siunitx_tmpa_tl { - } @@ -2837,7 +2912,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_complex: { +\cs_new_protected:Npn \siunitx_number_format_complex: { \prop_if_in:NnT \l_siunitx_number_in_prop { complex-root } { \prop_if_in:NnTF \l_siunitx_number_out_prop { complex } @@ -2853,61 +2928,34 @@ } } { - \tl_set:Nx \l_siunitx_tmpa_tl - { - \exp_not:N \siunitx_ensuremath:n - { \exp_not:V \l_siunitx_output_complex_tl } - } \prop_put:NnV \l_siunitx_number_out_prop { complex } - \l_siunitx_tmpa_tl + \l_siunitx_output_complex_tl } \siunitx_number_format_join_complex: } } -\cs_new_protected_nopar:Npn \siunitx_number_format_complex_aux:n #1 { - \siunitx_number_format_complex_aux: - \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl - \bool_if:NTF \l_siunitx_complex_after_bool - { - \siunitx_tl_put_right_math:NV \l_siunitx_tmpb_tl - \l_siunitx_tmpa_tl - } - { - \siunitx_tl_put_left_math:NV \l_siunitx_tmpb_tl - \l_siunitx_tmpa_tl - } - \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl -} -\cs_new_protected_nopar:Npn \siunitx_number_format_complex_aux: { - \tl_set:Nn \l_siunitx_tmpa_tl - { - \use:c - { - siunitx_ \l_siunitx_print_type_tl _ - math \l_siunitx_font_family_tl :n - } - } +\cs_new_protected:Npn \siunitx_number_format_complex_aux:n #1 { \bool_if:NTF \l_siunitx_output_complex_copy_bool { \prop_get:NnN \l_siunitx_number_in_prop { complex-root } - \l_siunitx_tmpb_tl - \tl_put_right:Nx \l_siunitx_tmpa_tl - { { \exp_not:V \l_siunitx_tmpb_tl } } - } - { - \tl_put_right:Nx \l_siunitx_tmpa_tl - { { \exp_not:V \l_siunitx_output_complex_tl } } + \l_siunitx_tmpa_tl } + { \tl_set_eq:NN \l_siunitx_tmpa_tl \l_siunitx_output_complex_tl } + \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl + \bool_if:NTF \l_siunitx_complex_after_bool + { \tl_put_right:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl } + { \tl_put_left:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl } + \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl } -\cs_new_protected_nopar:Npn \siunitx_number_format_copy:n #1 { +\cs_new_protected:Npn \siunitx_number_format_copy:n #1 { \prop_get:NnN \l_siunitx_number_in_prop {#1} \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn \siunitx_number_format_copy:nn #1#2 { +\cs_new_protected:Npn \siunitx_number_format_copy:nn #1#2 { \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop {#2} \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn \siunitx_number_format_final: { +\cs_new_protected:Npn \siunitx_number_format_final: { \prop_if_in:NnT \l_siunitx_number_out_prop { complex } { \prop_if_in:NnF \l_siunitx_number_out_prop { mantissa-result } @@ -2942,7 +2990,7 @@ \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_format_final_combined: { +\cs_new_protected:Npn \siunitx_number_format_final_combined: { \siunitx_number_format_brackets:n { mantissa } \prop_get:NnN \l_siunitx_number_out_prop { mantissa-result } \l_siunitx_tmpa_tl @@ -2966,7 +3014,7 @@ \prop_put:Nnn \l_siunitx_number_out_prop { result-bracket-exponent } { true } } -\cs_new_protected_nopar:Npn \siunitx_number_format_final_exponent: { +\cs_new_protected:Npn \siunitx_number_format_final_exponent: { \prop_get:NnN \l_siunitx_number_out_prop { exponent } \l_siunitx_tmpa_tl \tl_if_empty:NTF \l_siunitx_output_exponent_tl @@ -2985,7 +3033,7 @@ \prop_put:NnV \l_siunitx_number_out_prop { exponent-result } \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_format_final_exponent_only: { \prop_get:NnNT \l_siunitx_number_in_prop { mantissa-sign } \l_siunitx_tmpa_tl @@ -3004,7 +3052,7 @@ } \siunitx_number_format_copy:nn { exponent-result } { result } } -\cs_new_protected_nopar:Npn \siunitx_number_format_group:n #1 { +\cs_new_protected:Npn \siunitx_number_format_group:n #1 { \siunitx_number_format_group_aux:nn {#1} { integer } \siunitx_number_format_group_aux:nn {#1} { decimal } \prop_if_in:NnTF \l_siunitx_number_out_prop { #1 -integer } @@ -3019,11 +3067,6 @@ \tl_set_eq:NN \l_siunitx_tmpb_tl \l_siunitx_output_decimal_tl } - \tl_set:Nx \l_siunitx_tmpb_tl - { - \exp_not:N \siunitx_ensuremath:n - { \exp_not:V \l_siunitx_tmpb_tl } - } \tl_put_right:NV \l_siunitx_tmpa_tl \l_siunitx_tmpb_tl \prop_put:NnV \l_siunitx_number_out_prop { #1 -decimal-marker } \l_siunitx_tmpb_tl @@ -3034,7 +3077,7 @@ \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_format_group_aux:nn #1#2 { +\cs_new_protected:Npn \siunitx_number_format_group_aux:nn #1#2 { \prop_if_in:NnT \l_siunitx_number_in_prop { #1 - #2 } { \bool_if:cTF { l_siunitx_group_ #2 _bool } @@ -3042,7 +3085,7 @@ { \siunitx_number_format_copy:n { #1 - #2 } } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_group:nn #1#2 +\cs_new_protected:Npn \siunitx_number_format_group:nn #1#2 { \prop_get:NnN \l_siunitx_number_in_prop { #1 - #2 } \l_siunitx_tmpa_tl \int_compare:nNnTF @@ -3054,7 +3097,7 @@ \prop_put:NnV \l_siunitx_number_out_prop { #1 - #2 } \l_siunitx_tmpb_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_format_group_decimal: { +\cs_new_protected:Npn \siunitx_number_format_group_decimal: { \tl_if_empty:NF \l_siunitx_tmpa_tl { \exp_after:wN \siunitx_number_format_group_decimal_aux:NNNN @@ -3072,14 +3115,13 @@ \tl_put_right:Nn \l_siunitx_tmpb_tl { #1 #2 #3 } \tl_if_empty:nF {#4} { - \siunitx_tl_put_right_math:NV \l_siunitx_tmpb_tl - \l_siunitx_group_sep_tl + \tl_put_right:NV \l_siunitx_tmpb_tl \l_siunitx_group_sep_tl \siunitx_number_format_group_decimal_aux:NNNN #4 } } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_group_integer: { +\cs_new_protected:Npn \siunitx_number_format_group_integer: { \tl_if_empty:NF \l_siunitx_tmpa_tl { \siunitx_number_format_group_integer_setup:V \l_siunitx_tmpa_tl @@ -3119,12 +3161,11 @@ \tl_put_right:Nn \l_siunitx_tmpb_tl {#1#2#3} \quark_if_nil:nF {#4} { - \siunitx_tl_put_right_math:NV \l_siunitx_tmpb_tl - \l_siunitx_group_sep_tl + \tl_put_right:NV \l_siunitx_tmpb_tl \l_siunitx_group_sep_tl \siunitx_number_format_group_integer_aux:NNNN #4 } } -\cs_new_protected_nopar:Npn \siunitx_number_format_join_complex: { +\cs_new_protected:Npn \siunitx_number_format_join_complex: { \siunitx_number_format_sign_complex: \prop_if_in:NnT \l_siunitx_number_out_prop { mantissa } { @@ -3144,11 +3185,11 @@ { true } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_join_uncert: { +\cs_new_protected:Npn \siunitx_number_format_join_uncert: { \siunitx_number_format_join_uncert:n { mantissa } \siunitx_number_format_join_uncert:n { complex } } -\cs_new_protected_nopar:Npn \siunitx_number_format_join_uncert:n #1 { +\cs_new_protected:Npn \siunitx_number_format_join_uncert:n #1 { \prop_get:NnNT \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl { @@ -3166,13 +3207,13 @@ { \siunitx_number_format_copy:nn {#1} { #1 -result } } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_join_uncert_pm:N #1 +\cs_new_protected:Npn \siunitx_number_format_join_uncert_pm:N #1 { \bool_if:NTF \l_siunitx_tight_bool - { \tl_put_left:Nn #1 { \siunitx_ensuremath:n { { \pm } } } } - { \tl_put_left:Nn #1 { \siunitx_ensuremath:n { { } \pm { } } } } + { \tl_put_left:Nn #1 { \ensuremath { { \pm } } } } + { \tl_put_left:Nn #1 { \ensuremath { { } \pm { } } } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_reassemble: { +\cs_new_protected:Npn \siunitx_number_format_reassemble: { \prop_if_in:NnT \l_siunitx_number_in_prop { mantissa } { \siunitx_number_format_group:n { mantissa } @@ -3186,7 +3227,7 @@ \prop_if_in:NnT \l_siunitx_number_in_prop { exponent } { \siunitx_number_format_group:n { exponent } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_relation: { +\cs_new_protected:Npn \siunitx_number_format_relation: { \prop_get:NnNT \l_siunitx_number_in_prop { comparator } \l_siunitx_tmpa_tl { @@ -3199,7 +3240,7 @@ \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_format_sign:n #1 { +\cs_new_protected:Npn \siunitx_number_format_sign:n #1 { \prop_if_in:NnT \l_siunitx_number_out_prop {#1} { \prop_get:NnNT \l_siunitx_number_in_prop { #1 -sign } @@ -3215,14 +3256,14 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_sign_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_format_sign_aux:n #1 { \bool_if:NT \l_siunitx_tight_bool { \tl_set:Nx \l_siunitx_tmpa_tl { { \exp_not:V \l_siunitx_tmpa_tl } } } \tl_clear:N \l_siunitx_tmpb_tl - \siunitx_tl_put_left_math:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl + \tl_put_left:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop { #1 -sign } \l_siunitx_tmpb_tl \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl @@ -3236,26 +3277,24 @@ \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_format_sign_negative_brackets:n #1 { \siunitx_number_format_brackets_aux:n {#1} \prop_get:NnNT \l_siunitx_number_out_prop { #1 } \l_siunitx_tmpa_tl { - \siunitx_tl_put_left_math:NV \l_siunitx_tmpa_tl - \l_siunitx_bracket_open_tl - \siunitx_tl_put_right_math:NV \l_siunitx_tmpa_tl - \l_siunitx_bracket_close_tl + \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_bracket_open_tl + \tl_put_right:NV \l_siunitx_tmpa_tl \l_siunitx_bracket_close_tl \prop_put:NnV \l_siunitx_number_out_prop { #1 } \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_number_format_sign_complex: { +\cs_new_protected:Npn \siunitx_number_format_sign_complex: { \siunitx_number_format_sign_complex:n { complex } \siunitx_number_format_sign_complex:n { complex-result } } -\cs_new_protected_nopar:Npn \siunitx_number_format_sign_complex:n #1 { +\cs_new_protected:Npn \siunitx_number_format_sign_complex:n #1 { \prop_if_in:NnT \l_siunitx_number_out_prop {#1} { \prop_get:NnNT \l_siunitx_number_in_prop { complex-sign } @@ -3274,8 +3313,7 @@ } } \tl_clear:N \l_siunitx_tmpb_tl - \siunitx_tl_put_left_math:NV \l_siunitx_tmpb_tl - \l_siunitx_tmpa_tl + \tl_put_left:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop { complex-sign } \l_siunitx_tmpb_tl \prop_get:NnN \l_siunitx_number_out_prop {#1} @@ -3286,7 +3324,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_format_uncertainty:n #1 { +\cs_new_protected:Npn \siunitx_number_format_uncertainty:n #1 { \prop_if_in:NnTF \l_siunitx_number_in_prop { #1 -uncertainty } { \bool_if:NTF \l_siunitx_uncert_sep_bool @@ -3296,22 +3334,19 @@ } { \siunitx_number_format_copy:nn {#1} { #1 -result } } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_format_uncertainty_joined:n #1 { \prop_get:NnN \l_siunitx_number_in_prop { #1 -uncertainty } \l_siunitx_tmpa_tl \prop_del:Nn \l_siunitx_number_in_prop { #1 -uncertainty } - \siunitx_tl_put_left_math:NV \l_siunitx_tmpa_tl - \l_siunitx_output_uncert_open_tl - \siunitx_tl_put_left_math:NV \l_siunitx_tmpa_tl - \l_siunitx_uncert_sep_tl - \siunitx_tl_put_right_math:NV \l_siunitx_tmpa_tl - \l_siunitx_output_uncert_close_tl + \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_output_uncert_open_tl + \tl_put_left:NV \l_siunitx_tmpa_tl \l_siunitx_uncert_sep_tl + \tl_put_right:NV \l_siunitx_tmpa_tl \l_siunitx_output_uncert_close_tl \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl \tl_put_right:NV \l_siunitx_tmpb_tl \l_siunitx_tmpa_tl \prop_put:NnV \l_siunitx_number_out_prop {#1} \l_siunitx_tmpb_tl } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_number_format_uncertainty_sep:n #1 { \prop_if_in:NnT \l_siunitx_number_out_prop { #1 -integer } { @@ -3357,14 +3392,14 @@ \siunitx_combined_output:n {#1} } \cs_generate_variant:Nn \siunitx_number_output:n { V } -\cs_new_protected_nopar:Npn \siunitx_number_output_bracket: { +\cs_new_protected:Npn \siunitx_number_output_bracket: { \bool_if:NF \l_siunitx_error_bool { \bool_if:NT \l_siunitx_number_compound_bool { \siunitx_number_format_brackets:n { result } } } } -\cs_new_protected_nopar:Npn \siunitx_number_output_color: { +\cs_new_protected:Npn \siunitx_number_output_color: { \prop_if_in:NnT \l_siunitx_number_out_prop { color } { \prop_get:NnN \l_siunitx_number_out_prop { color } @@ -3384,7 +3419,7 @@ } } \cs_generate_variant:Nn \siunitx_number_output_parse:n { V } -\cs_new_protected_nopar:Npn \siunitx_number_output_parse_aux: { +\cs_new_protected:Npn \siunitx_number_output_parse_aux: { \siunitx_number_in_parse:V \l_siunitx_number_arg_tl \bool_if:NF \l_siunitx_error_bool { @@ -3401,7 +3436,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_output_parts: { +\cs_new_protected:Npn \siunitx_number_output_parts: { \bool_if:nTF { \tl_if_empty_p:N \l_siunitx_pre_unit_tl && @@ -3410,7 +3445,7 @@ { \siunitx_number_output_single: } { \siunitx_number_output_parts_aux: } } -\cs_new_protected_nopar:Npn \siunitx_number_output_parts_aux: { +\cs_new_protected:Npn \siunitx_number_output_parts_aux: { \bool_if:NTF \l_siunitx_multi_repeat_bool { \prop_if_in:NnT \l_siunitx_number_out_prop { mantissa-result } @@ -3440,30 +3475,24 @@ } { \siunitx_number_output_single: } } -\cs_new_protected_nopar:Npn \siunitx_number_output_parts_aux:n #1 { +\cs_new_protected:Npn \siunitx_number_output_parts_aux:n #1 { \prop_if_in:NnT \l_siunitx_number_out_prop {#1} { \siunitx_number_output_parts_print:n {#1} } \prop_if_in:NnT \l_siunitx_number_out_prop { #1 -uncertainty } { \bool_if:NTF \l_siunitx_tight_bool - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { { \pm } } } - } - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { { } \pm { } } } - } + { \siunitx_print:nn { number } { \ensuremath { { \pm } } } } + { \siunitx_print:nn { number } { \ensuremath { { } \pm { } } } } \siunitx_number_output_parts_print:n { #1 -uncertainty } } } -\cs_new_protected_nopar:Npn \siunitx_number_output_parts_print:n #1 { +\cs_new_protected:Npn \siunitx_number_output_parts_print:n #1 { \siunitx_unit_output_pre_print: \prop_get:NnN \l_siunitx_number_out_prop {#1} \l_siunitx_tmpa_tl \siunitx_print:nV { number } \l_siunitx_tmpa_tl \siunitx_unit_output_print: } -\cs_new_protected_nopar:Npn \siunitx_number_output_product: { +\cs_new_protected:Npn \siunitx_number_output_product: { \bool_if:NTF \l_siunitx_product_brackets_bool { \bool_if:nTF @@ -3490,10 +3519,9 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_number_output_product_brackets: { +\cs_new_protected:Npn \siunitx_number_output_product_brackets: { \siunitx_unit_output_pre_print: - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_open_tl } } + \siunitx_print:nV { number } \l_siunitx_bracket_open_tl \nobreak \tl_set_eq:NN \l_siunitx_unit_saved_tl \l_siunitx_unit_tl \tl_clear:N \l_siunitx_pre_unit_tl @@ -3501,11 +3529,10 @@ \siunitx_number_output_product_aux: \nobreak \tl_set_eq:NN \l_siunitx_unit_tl \l_siunitx_unit_saved_tl - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_close_tl } } + \siunitx_print:nV { number } \l_siunitx_bracket_close_tl \siunitx_unit_output_print: } -\cs_new_protected_nopar:Npn \siunitx_number_output_product_aux: { +\cs_new_protected:Npn \siunitx_number_output_product_aux: { \bool_set_true:N \l_siunitx_number_compound_bool \siunitx_number_preprocess:V \l_siunitx_number_arg_tl \bool_if:NF \l_siunitx_error_bool @@ -3518,27 +3545,21 @@ \bool_if:NTF \l_siunitx_tight_bool { \siunitx_print:nn { number } - { - \siunitx_ensuremath:n - { \l_siunitx_output_product_tl } - } + { \ensuremath { \l_siunitx_output_product_tl } } } { \siunitx_print:nn { number } - { - \siunitx_ensuremath:n - { { } \l_siunitx_output_product_tl { } } - } + { \ensuremath { { } \l_siunitx_output_product_tl { } } } } \siunitx_number_output_parse:V \l_siunitx_number_next_tl } } } -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient: { +\cs_new_protected:Npn \siunitx_number_output_quotient: { \use:c { siunitx_number_output_quotient_ \l_siunitx_quotient_mode_tl : } } -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient_fraction: { +\cs_new_protected:Npn \siunitx_number_output_quotient_fraction: { \bool_set_false:N \l_siunitx_number_compound_bool \siunitx_number_output_quotient_aux_i: \tl_set:Nx \l_siunitx_number_out_tl @@ -3554,18 +3575,17 @@ } \siunitx_number_output_single_aux: } -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient_symbol: { +\cs_new_protected:Npn \siunitx_number_output_quotient_symbol: { \bool_set_true:N \l_siunitx_number_compound_bool \siunitx_number_output_quotient_aux_i: \tl_set_eq:NN \l_siunitx_number_out_tl \l_siunitx_number_numerator_tl - \siunitx_tl_put_right_math:NV \l_siunitx_number_out_tl - \l_siunitx_output_quotient_tl + \tl_put_right:NV \l_siunitx_number_out_tl \l_siunitx_output_quotient_tl \tl_put_right:NV \l_siunitx_number_out_tl \l_siunitx_number_denominator_tl \siunitx_number_output_single_aux: } -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient_aux_i: { +\cs_new_protected:Npn \siunitx_number_output_quotient_aux_i: { \siunitx_number_in_parse:V \l_siunitx_number_numerator_tl \siunitx_number_output_quotient_aux_ii: \siunitx_number_output_color: @@ -3592,11 +3612,11 @@ \prop_get:NnN \l_siunitx_number_out_prop { result } \l_siunitx_number_denominator_tl } -\cs_new_protected_nopar:Npn \siunitx_number_output_quotient_aux_ii: { +\cs_new_protected:Npn \siunitx_number_output_quotient_aux_ii: { \siunitx_number_process: \siunitx_number_format: } -\cs_new_protected_nopar:Npn \siunitx_number_output_single: { +\cs_new_protected:Npn \siunitx_number_output_single: { \bool_if:nF { \tl_if_empty_p:N \l_siunitx_pre_unit_tl && @@ -3611,7 +3631,7 @@ \l_siunitx_number_out_tl \siunitx_number_output_single_aux: } -\cs_new_protected_nopar:Npn \siunitx_number_output_single_aux: { +\cs_new_protected:Npn \siunitx_number_output_single_aux: { \siunitx_unit_output_pre_print: \quark_if_no_value:NTF \l_siunitx_number_out_tl { \tl_clear:N \l_siunitx_number_unit_product_tl } @@ -3666,7 +3686,7 @@ { \siunitx_angle_direct:nnn {#1} {#2} {#3} } } } -\cs_new_protected_nopar:Npn \siunitx_angle_init: { +\cs_new_protected:Npn \siunitx_angle_init: { \bool_set_false:N \l_siunitx_angle_degree_space_bool \bool_set_false:N \l_siunitx_angle_minute_space_bool \prop_clear:N \l_siunitx_angle_degree_prop @@ -3755,7 +3775,7 @@ \prop_set_eq:cN { l_siunitx_angle_ #2 _prop } \l_siunitx_number_in_prop } -\cs_new_protected_nopar:Npn \siunitx_angle_check_sign: { +\cs_new_protected:Npn \siunitx_angle_check_sign: { \prop_if_empty:NTF \l_siunitx_angle_degree_prop { \prop_if_empty:NF \l_siunitx_angle_minute_prop @@ -3766,7 +3786,7 @@ \siunitx_angle_check_sign_aux:n { second } } } -\cs_new_protected_nopar:Npn \siunitx_angle_check_sign_aux:n #1 { +\cs_new_protected:Npn \siunitx_angle_check_sign_aux:n #1 { \prop_if_in:cnTF { l_siunitx_angle_ #1 _prop } { mantissa-sign } { \msg_error:nn { siunitx } { bad-arc-sign } } @@ -3776,7 +3796,7 @@ { \msg_error:nn { siunitx } { bad-arc-sign } } } } -\cs_new_protected_nopar:Npn \siunitx_angle_zero_fill: { +\cs_new_protected:Npn \siunitx_angle_zero_fill: { \bool_if:nT { \prop_if_empty_p:N \l_siunitx_angle_second_prop && @@ -3814,11 +3834,11 @@ \siunitx_angle_sign_shuffle:nn { minute } { degree } } } -\cs_new_protected_nopar:Npn \siunitx_angle_sign_shuffle:nn #1#2 { +\cs_new_protected:Npn \siunitx_angle_sign_shuffle:nn #1#2 { \siunitx_angle_sign_shuffle_aux:nnn {#1} {#2} { } \siunitx_angle_sign_shuffle_aux:nnn {#1} {#2} { -deleted } } -\cs_new_protected_nopar:Npn \siunitx_angle_sign_shuffle_aux:nnn +\cs_new_protected:Npn \siunitx_angle_sign_shuffle_aux:nnn #1#2#3 { \prop_get:cnN { l_siunitx_angle_ #1 _prop } { mantissa-sign #3 } \l_siunitx_tmpa_tl @@ -3829,22 +3849,22 @@ \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_angle_print: { +\cs_new_protected:Npn \siunitx_angle_print: { \siunitx_angle_print_aux:nn { degree } { \SIUnitSymbolDegree } \bool_if:NT \l_siunitx_angle_degree_space_bool { \nobreak - \siunitx_ensuremath:n { \l_siunitx_angle_arc_separator_tl } + \l_siunitx_angle_arc_separator_tl } \siunitx_angle_print_aux:nn { minute } { \SIUnitSymbolArcminute } \bool_if:NT \l_siunitx_angle_minute_space_bool { \nobreak - \siunitx_ensuremath:n { \l_siunitx_angle_arc_separator_tl } + \l_siunitx_angle_arc_separator_tl } \siunitx_angle_print_aux:nn { second } { \SIUnitSymbolArcsecond } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_aux:nn #1#2 { +\cs_new_protected:Npn \siunitx_angle_print_aux:nn #1#2 { \prop_if_empty:cF { l_siunitx_angle_ #1 _prop } { \prop_set_eq:Nc \l_siunitx_number_in_prop @@ -3858,20 +3878,19 @@ { \siunitx_number_output_single: } } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy: { +\cs_new_protected:Npn \siunitx_angle_print_astronomy: { \prop_if_in:NnTF \l_siunitx_number_in_prop { mantissa-decimal-marker } { \siunitx_angle_print_astronomy_aux: } { \siunitx_number_output_single: } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy_aux: { +\cs_new_protected:Npn \siunitx_angle_print_astronomy_aux: { \prop_get:NnNT \l_siunitx_number_out_prop { mantissa-integer } \l_siunitx_tmpa_tl { \siunitx_print:nV { number } \l_siunitx_tmpa_tl } \hbox_set:Nn \l_siunitx_angle_marker_box { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { { \l_siunitx_output_decimal_tl } } } + \siunitx_print:nn { number } { { \l_siunitx_output_decimal_tl } } } \hbox_set:Nn \l_siunitx_angle_unit_box { @@ -3893,7 +3912,7 @@ \l_siunitx_tmpa_tl { \siunitx_print:nV { number } \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy_aux:n #1 { +\cs_new_protected:Npn \siunitx_angle_print_astronomy_aux:n #1 { \dim_set:cn { l_siunitx_angle_ #1 _dim } { \box_wd:c { l_siunitx_angle_ #1 _box } } \hbox_set_to_wd:cnn { l_siunitx_angle_ #1 _box } { \c_zero_skip } @@ -3903,7 +3922,7 @@ \tex_hss:D } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy_marker: { +\cs_new_protected:Npn \siunitx_angle_print_astronomy_marker: { \hbox_set_to_wd:Nnn \l_siunitx_angle_marker_box { \l_siunitx_angle_marker_dim } { @@ -3913,7 +3932,7 @@ } \box_use:N \l_siunitx_angle_marker_box } -\cs_new_protected_nopar:Npn \siunitx_angle_print_astronomy_unit: { +\cs_new_protected:Npn \siunitx_angle_print_astronomy_unit: { \hbox_set_to_wd:Nnn \l_siunitx_angle_marker_box { \l_siunitx_angle_unit_dim } { @@ -3929,21 +3948,21 @@ \bool_if:NT \l_siunitx_angle_degree_space_bool { \nobreak - \siunitx_ensuremath:n { \l_siunitx_angle_arc_separator_tl } + \l_siunitx_angle_arc_separator_tl } \siunitx_angle_print_direct_aux:nn {#2} { \SIUnitSymbolArcminute } \bool_if:NT \l_siunitx_angle_minute_space_bool { \nobreak - \siunitx_ensuremath:n { \l_siunitx_angle_arc_separator_tl } + \l_siunitx_angle_arc_separator_tl } \siunitx_angle_print_direct_aux:nn {#3} { \SIUnitSymbolArcsecond } } -\cs_new_protected_nopar:Npn \siunitx_angle_print_direct_aux:nn #1#2 { +\cs_new_protected:Npn \siunitx_angle_print_direct_aux:nn #1#2 { \tl_if_empty:nF {#1} { \tl_set:Nn \l_siunitx_unit_tl {#2} - \siunitx_print:nn { number } { \siunitx_ensuremath:n {#1} } + \siunitx_print:nn { number } { \ensuremath {#1} } \siunitx_unit_output_print: } } @@ -3964,16 +3983,21 @@ \cs_set:cpn { siunitx_ \token_to_str:N #1 _function:w } { \siunitx_unit_parse_power_before:n {#2} } } -\cs_new_protected:Npn \siunitx_declare_prefix:Nnnn #1#2#3#4 { - \tl_put_right:Nn \l_siunitx_declare_list_tl {#1} - \cs_set:cpn { siunitx_ \token_to_str:N #1 _literal:w } {#2} - \cs_set:cpn { siunitx_ \token_to_str:N #1 _function:w } - { - \bool_if:NTF \l_siunitx_prefix_symbols_bool - { \siunitx_unit_parse_prefix:n {#2} } - { \siunitx_unit_parse_prefix:nn {#3} {#4} } - } -} +\cs_new_protected:Npn \siunitx_declare_prefix:Nnnn #1#2#3#4 + { + \tl_put_right:Nn \l_siunitx_declare_list_tl {#1} + \prop_put:Nnn \l_siunitx_prefix_forward_prop {#1} {#4} + \prop_put:Nnn \l_siunitx_prefix_reverse_prop {#4} {#1} + \cs_set:cpn { siunitx_ \token_to_str:N #1 _literal:w } {#2} + \cs_set:cpn { siunitx_ \token_to_str:N #1 _function:w } + { + \bool_if:NTF \l_siunitx_prefix_symbols_bool + { \siunitx_unit_parse_prefix:Nn #1 {#2} } + { \siunitx_unit_parse_prefix:nn {#3} {#4} } + } + } +\prop_new:N \l_siunitx_prefix_forward_prop +\prop_new:N \l_siunitx_prefix_reverse_prop \cs_new_protected:Npn \siunitx_declare_qualifier:Nn #1#2 { \tl_put_right:Nn \l_siunitx_declare_list_tl {#1} \cs_set:cpn { siunitx_ \token_to_str:N #1 _literal:w } @@ -4056,15 +4080,15 @@ unit-optional-argument , use-xspace , } -\cs_new_protected_nopar:Npn \siunitx_unit_create_empty_functions: { +\cs_new_protected:Npn \siunitx_unit_create_empty_functions: { \tl_map_function:NN \l_siunitx_declare_list_tl \siunitx_unit_create_empty_functions_aux:N } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_unit_create_empty_functions_aux:N #1 { - \cs_if_free:NT #1 { \cs_set_protected_nopar:Npn #1 { \ERROR } } + \cs_if_free:NT #1 { \cs_set_protected:Npn #1 { \ERROR } } } -\cs_new_protected_nopar:Npn \siunitx_unit_create_functions: { +\cs_new_protected:Npn \siunitx_unit_create_functions: { \bool_if:NT \l_siunitx_create_overwrite_bool { \tl_map_function:NN \l_siunitx_declare_list_tl \cs_undefine:N } \bool_if:NTF \l_siunitx_create_optional_bool @@ -4098,10 +4122,7 @@ \bool_if:NT \l_siunitx_create_prespace_bool { \exp_not:n - { - \siunitx_ensuremath:n - { \l_siunitx_number_unit_product_tl } - } + { \ensuremath { \l_siunitx_number_unit_product_tl } } } \exp_not:n { \siunitx_unit_output:nn {#1} { } } \group_end: @@ -4136,7 +4157,7 @@ { \exp_not:n { - \siunitx_ensuremath:n + \ensuremath { \l_siunitx_number_unit_product_tl } } } @@ -4154,18 +4175,18 @@ \AtBeginDocument { \cs_if_eq:NNT \color \use_none:n { \cs_set_protected:Npn \color #1 { } } - \cs_set_nopar:Npn \siunitx_tmp:w #1 { } + \cs_set:Npn \siunitx_tmp:w #1 { } \cs_if_eq:NNT \color \siunitx_tmp:w { \cs_set_protected:Npn \color #1 { } } \tl_map_function:nN { \bar \color \ng \pm \array@row@rst } \siunitx_protect_symbols:N } \tl_put_right:Nn \document { \siunitx_protect_symbols:N \fg } -\cs_new_protected_nopar:Npn \siunitx_protect_symbols:N #1 { +\cs_new_protected:Npn \siunitx_protect_symbols:N #1 { \cs_if_exist:NT #1 { \siunitx_cs_if_macro:NT #1 - { \cs_set_protected_nopar:Npx #1 { \exp_not:V #1 } } + { \cs_set_protected:Npx #1 { \exp_not:V #1 } } } } \keys_define:nn { siunitx } { @@ -4200,6 +4221,7 @@ \cs_set_eq:NN \siunitx_pm: \pm \siunitx_unit_parse:nn {#1} {#2} \siunitx_unit_format: + \prop_set_eq:NN \l_siunitx_unit_saved_prop \l_siunitx_unit_prop \cs_set_eq:NN \pm \siunitx_pm: } } @@ -4207,7 +4229,7 @@ { \siunitx_unit_format_literal:n {#1} } } \cs_generate_variant:Nn \siunitx_unit_in:nn { V } -\cs_new_nopar:Npn \siunitx_pm: { } +\cs_new:Npn \siunitx_pm: { } \cs_new_protected:Npn \siunitx_unit_if_literal:nTF #1#2#3 { \group_begin: \tl_map_function:NN \l_siunitx_declare_list_tl @@ -4226,20 +4248,21 @@ } \int_new:N \l_siunitx_unit_int \prop_new:N \l_siunitx_unit_prop +\prop_new:N \l_siunitx_unit_saved_prop \bool_new:N \l_siunitx_per_bool -\keys_define:nn { siunitx } { - prefixes-as-symbols .bool_set:N = \l_siunitx_prefix_symbols_bool, - sticky-per .bool_set:N = \l_siunitx_sticky_per_bool, -} -\keys_set:nn { siunitx } { - prefixes-as-symbols = true -} +\keys_define:nn { siunitx } + { + exponent-to-prefix .bool_set:N = \l_siunitx_exp_to_prefix_bool , + prefixes-as-symbols .bool_set:N = \l_siunitx_prefix_symbols_bool , + sticky-per .bool_set:N = \l_siunitx_sticky_per_bool + } +\keys_set:nn { siunitx } { prefixes-as-symbols = true } \cs_new_protected:Npn \siunitx_unit_parse:nn #1#2 { \siunitx_unit_parse_init: \siunitx_unit_parse_options:nn {#1} {#2} #1 } -\cs_new_protected_nopar:Npn \siunitx_unit_parse_init: { +\cs_new_protected:Npn \siunitx_unit_parse_init: { \prop_clear:N \l_siunitx_unit_prop \int_zero:N \l_siunitx_unit_int \bool_set_false:N \l_siunitx_per_bool @@ -4271,26 +4294,31 @@ { power- \int_use:N \l_siunitx_unit_int } \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#1} } -\cs_new_protected:Npn \siunitx_unit_parse_prefix:n #1 { - \int_incr:N \l_siunitx_unit_int - \tl_set:Nx \l_siunitx_tmpa_tl - { prefix- \int_use:N \l_siunitx_unit_int } - \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#1} -} -\cs_new_protected:Npn \siunitx_unit_parse_prefix:nn #1#2 { - \siunitx_unit_parse_prefix:n {#2} - \tl_set:Nx \l_siunitx_tmpa_tl - { prefix-base- \int_use:N \l_siunitx_unit_int } - \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#1} -} -\cs_new_protected_nopar:Npn \siunitx_unit_parse_per: { +\cs_new_protected:Npn \siunitx_unit_parse_prefix:Nn #1#2 + { + \int_incr:N \l_siunitx_unit_int + \tl_set:Nx \l_siunitx_tmpa_tl + { prefix- \int_use:N \l_siunitx_unit_int } + \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#1} + \tl_set:Nx \l_siunitx_tmpa_tl + { prefix-symbol- \int_use:N \l_siunitx_unit_int } + \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#2} + } +\cs_new_protected:Npn \siunitx_unit_parse_prefix:nn #1#2 + { + \siunitx_unit_parse_prefix:Nn \ERROR {#2} + \tl_set:Nx \l_siunitx_tmpa_tl + { prefix-base- \int_use:N \l_siunitx_unit_int } + \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#1} + } +\cs_new_protected:Npn \siunitx_unit_parse_per: { \tl_set:Nx \l_siunitx_tmpa_tl { per- \int_eval:n { \l_siunitx_unit_int + 1 } } \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl { true } \bool_if:NT \l_siunitx_sticky_per_bool { \cs_set_eq:NN \per \siunitx_unit_parse_per_error: } } -\cs_new_protected_nopar:Npn \siunitx_unit_parse_per_error: { +\cs_new_protected:Npn \siunitx_unit_parse_per_error: { \msg_error:nn { siunitx } { duplicate-sticky-per } } \cs_new_protected:Npn \siunitx_unit_parse_qualifier:n #1 { @@ -4309,7 +4337,7 @@ } \cs_new_protected:Npn \siunitx_unit_parse_unit:Nn #1#2 { \tl_set:Nx \l_siunitx_tmpa_tl - { prefix- \int_use:N \l_siunitx_unit_int } + { prefix-symbol- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVTF \l_siunitx_unit_prop \l_siunitx_tmpa_tl { \tl_set:Nx \l_siunitx_tmpa_tl @@ -4326,7 +4354,7 @@ \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl {#2} \siunitx_unit_parse_unit_per: } -\cs_new_protected_nopar:Npn \siunitx_unit_parse_unit_per: { +\cs_new_protected:Npn \siunitx_unit_parse_unit_per: { \bool_if:NT \l_siunitx_sticky_per_bool { \bool_if:NT \l_siunitx_per_bool @@ -4435,7 +4463,7 @@ power-font = number, qualifier-mode = subscript } -\cs_new_protected_nopar:Npn \siunitx_unit_format: { +\cs_new_protected:Npn \siunitx_unit_format: { \siunitx_unit_format_init: \int_while_do:nNnn { \l_siunitx_unit_int } > { 0 } { @@ -4453,7 +4481,7 @@ { \siunitx_unit_format_sorted: } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_add: { +\cs_new_protected:Npn \siunitx_unit_format_add: { \bool_if:NTF \l_siunitx_per_two_parts_bool { \tl_set:Nx \l_siunitx_tmpb_tl @@ -4471,7 +4499,7 @@ { \siunitx_unit_format_add_aux:n { } } \tl_clear:N \l_siunitx_unit_current_tl } -\cs_new_protected_nopar:Npn \siunitx_unit_format_add_aux:n #1 { +\cs_new_protected:Npn \siunitx_unit_format_add_aux:n #1 { \tl_if_empty:cF { l_siunitx_unit #1 _tl } { \str_if_eq:VnTF \l_siunitx_per_mode_tl { repeat } @@ -4505,7 +4533,7 @@ \l_siunitx_unit_current_tl } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction: { +\cs_new_protected:Npn \siunitx_unit_format_fraction: { \int_compare:nNnT { \l_siunitx_unit_numerator_int } = { 0 } { \str_if_eq:VnT \l_siunitx_per_mode_tl { symbol } @@ -4522,7 +4550,7 @@ } { \tl_set_eq:NN \l_siunitx_unit_tl \l_siunitx_unit_numerator_tl } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction_fraction: { +\cs_new_protected:Npn \siunitx_unit_format_fraction_fraction: { \tl_if_empty:NT \l_siunitx_unit_numerator_tl { \tl_set:Nn \l_siunitx_unit_numerator_tl { 1 } } \tl_set:Nx \l_siunitx_unit_numerator_tl @@ -4543,7 +4571,7 @@ \tl_set:Nx \l_siunitx_unit_tl { \exp_not:N \ensuremath { \exp_not:V \l_siunitx_unit_tl } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction_auto: { +\cs_new_protected:Npn \siunitx_unit_format_fraction_auto: { \mode_if_math:TF { \group_begin: @@ -4572,31 +4600,28 @@ } { \siunitx_unit_format_fraction_symbol: } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction_symbol: { +\cs_new_protected:Npn \siunitx_unit_format_fraction_symbol: { \siunitx_unit_format_fraction_symbol_aux: \int_compare:nNnT { \l_siunitx_unit_denominator_int } > { 1 } { \bool_if:NT \l_siunitx_unit_denominator_bracket_bool { - \siunitx_tl_put_left_math:NV \l_siunitx_unit_denominator_tl - \l_siunitx_bracket_open_tl - \siunitx_tl_put_right_math:NV \l_siunitx_unit_denominator_tl - \l_siunitx_bracket_close_tl + \tl_put_left:NV \l_siunitx_unit_denominator_tl \l_siunitx_bracket_open_tl + \tl_put_right:NV \l_siunitx_unit_denominator_tl \l_siunitx_bracket_close_tl } } \tl_set_eq:NN \l_siunitx_unit_tl \l_siunitx_unit_numerator_tl - \siunitx_tl_put_right_math:NV \l_siunitx_unit_tl - \l_siunitx_per_symbol_tl + \tl_put_right:NV \l_siunitx_unit_tl \l_siunitx_per_symbol_tl \tl_put_right:NV \l_siunitx_unit_tl \l_siunitx_unit_denominator_tl } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_unit_format_fraction_symbol_aux: { } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_unit_format_fraction_symbol_aux_alt: { \tl_if_empty:NT \l_siunitx_unit_numerator_tl { \tl_set:Nn \l_siunitx_unit_numerator_tl { 1 } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_init: { +\cs_new_protected:Npn \siunitx_unit_format_init: { \bool_set_false:N \l_siunitx_omit_unit_space_bool \tl_clear:N \l_siunitx_unit_tl \tl_clear:N \l_siunitx_unit_current_tl @@ -4618,10 +4643,7 @@ \siunitx_unit_print_literal_aux:N \tl_set:Nn \l_siunitx_unit_tl {#1} \tl_set:Nx \l_siunitx_tmpa_tl - { - \exp_not:N \siunitx_ensuremath:n - { \exp_not:o \l_siunitx_unit_product_tl } - } + { \exp_not:N \ensuremath { \exp_not:V \l_siunitx_unit_product_tl } } \tl_replace_all:NnV \l_siunitx_unit_tl { . } \l_siunitx_tmpa_tl \tl_replace_all:NnV \l_siunitx_unit_tl { ~ } \l_siunitx_tmpa_tl \bool_if:NT \l_siunitx_literal_power_bool @@ -4637,7 +4659,7 @@ \cs_new_protected:Npn \siunitx_unit_format_literal_power:n #1 { \PrintSuperscript { \siunitx_unit_format_power_aux:n {#1} } } %\end{macro} -\cs_new_protected_nopar:Npn \siunitx_unit_format_literal_extras: { +\cs_new_protected:Npn \siunitx_unit_format_literal_extras: { \siunitx_unit_format_literal_extras_aux:nN { 176 } \SIUnitSymbolDegree \siunitx_unit_format_literal_extras_aux:nN { 181 } @@ -4645,7 +4667,7 @@ \siunitx_unit_format_literal_extras_aux:nN { 197 } \SIUnitSymbolAngstrom } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_unit_format_literal_extras_aux:nN #1#2 { \char_set_lccode:nn { `\@ } {#1} \tl_to_lowercase:n @@ -4654,28 +4676,26 @@ \l_siunitx_unit_tl } } -\xetex_if_engine:F { - \luatex_if_engine:F - { - \AtBeginDocument - { - \cs_if_exist:NTF \inputencodingname - { - \tl_set:Nn \l_siunitx_tmpa_tl { latin1 , latin5 , latin9 } - \clist_if_in:NVF \l_siunitx_tmpa_tl \inputencodingname - { - \cs_set_eq:NN \siunitx_unit_format_literal_extras: - \scan_stop: - } - } - { - \cs_set_eq:NN \siunitx_unit_format_literal_extras: - \scan_stop: - } - } - } -} -\cs_new_protected_nopar:Npn \siunitx_unit_format_power: { +\pdftex_if_engine:T + { + \AtBeginDocument + { + \cs_if_exist:NTF \inputencodingname + { + \tl_set:Nn \l_siunitx_tmpa_tl { latin1 , latin5 , latin9 } + \clist_if_in:NVF \l_siunitx_tmpa_tl \inputencodingname + { + \cs_set_eq:NN \siunitx_unit_format_literal_extras: + \scan_stop: + } + } + { + \cs_set_eq:NN \siunitx_unit_format_literal_extras: + \scan_stop: + } + } + } +\cs_new_protected:Npn \siunitx_unit_format_power: { \tl_set:Nx \l_siunitx_tmpa_tl { power- \int_use:N \l_siunitx_unit_int } \prop_get:NVNTF \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -4691,7 +4711,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_power_aux: { +\cs_new_protected:Npn \siunitx_unit_format_power_aux: { \str_if_eq:VnTF \l_siunitx_per_mode_tl { repeat } { \siunitx_unit_format_power_repeat: } { \siunitx_unit_format_power_per: } @@ -4723,18 +4743,16 @@ \siunitx_print:nV {#1} \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_power_brackets: { +\cs_new_protected:Npn \siunitx_unit_format_power_brackets: { \tl_set:Nx \l_siunitx_tmpb_tl { bracket- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVT \l_siunitx_unit_prop \l_siunitx_tmpb_tl { - \siunitx_tl_put_left_math:NV \l_siunitx_unit_current_tl - \l_siunitx_bracket_open_tl - \siunitx_tl_put_right_math:NV \l_siunitx_unit_current_tl - \l_siunitx_bracket_close_tl + \tl_put_left:NV \l_siunitx_unit_current_tl \l_siunitx_bracket_open_tl + \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_bracket_close_tl } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_power_per: { +\cs_new_protected:Npn \siunitx_unit_format_power_per: { \tl_set:Nx \l_siunitx_tmpb_tl { per- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVT \l_siunitx_unit_prop \l_siunitx_tmpb_tl @@ -4751,18 +4769,17 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_power_repeat: { +\cs_new_protected:Npn \siunitx_unit_format_power_repeat: { \tl_set:Nx \l_siunitx_tmpb_tl { per- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVT \l_siunitx_unit_prop \l_siunitx_tmpb_tl { - \siunitx_tl_put_left_math:NV \l_siunitx_unit_current_tl - \l_siunitx_per_symbol_tl + \tl_put_left:NV \l_siunitx_unit_current_tl \l_siunitx_per_symbol_tl } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_prefix: { +\cs_new_protected:Npn \siunitx_unit_format_prefix: { \tl_set:Nx \l_siunitx_tmpa_tl - { prefix- \int_use:N \l_siunitx_unit_int } + { prefix-symbol- \int_use:N \l_siunitx_unit_int } \prop_if_in:NVT \l_siunitx_unit_prop \l_siunitx_tmpa_tl { \prop_get:NVN \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -4772,7 +4789,7 @@ { \siunitx_unit_format_prefix_number: } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_prefix_number: { +\cs_new_protected:Npn \siunitx_unit_format_prefix_number: { \tl_set:Nx \l_siunitx_tmpa_tl { prefix-base- \int_use:N \l_siunitx_unit_int } \prop_get:NVN \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -4787,7 +4804,7 @@ { \siunitx_unit_format_prefix_number_calc: } { \msg_error:nn { siunitx } { prefix-base-mismatch } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_prefix_number_calc: { +\cs_new_protected:Npn \siunitx_unit_format_prefix_number_calc: { \tl_set:Nx \l_siunitx_tmpa_tl { power- \int_use:N \l_siunitx_unit_int } \prop_get:NVNF \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -4828,11 +4845,11 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_prefix_symbol: { +\cs_new_protected:Npn \siunitx_unit_format_prefix_symbol: { \tl_set_eq:NN \l_siunitx_unit_current_tl \l_siunitx_unit_prefix_current_tl } -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier: { +\cs_new_protected:Npn \siunitx_unit_format_qualifier: { \tl_set:Nx \l_siunitx_tmpa_tl { qualifier- \int_use:N \l_siunitx_unit_int } \prop_get:NVNT \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -4845,15 +4862,13 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier_brackets: { - \siunitx_tl_put_right_math:NV \l_siunitx_unit_current_tl - \l_siunitx_bracket_open_tl +\cs_new_protected:Npn \siunitx_unit_format_qualifier_brackets: { + \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_bracket_open_tl \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_tmpa_tl - \siunitx_tl_put_right_math:NV \l_siunitx_unit_current_tl - \l_siunitx_bracket_close_tl + \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_bracket_close_tl } \char_set_catcode_active:N \~ -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier_space: { +\cs_new_protected:Npn \siunitx_unit_format_qualifier_space: { \tl_put_right:Nn \l_siunitx_unit_current_tl { \text { ~ } } \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_tmpa_tl \tl_set:Nx \l_siunitx_tmpa_tl @@ -4861,14 +4876,14 @@ \prop_put:NVn \l_siunitx_unit_prop \l_siunitx_tmpa_tl { true } } \char_set_catcode_space:N \~ -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier_subscript: { +\cs_new_protected:Npn \siunitx_unit_format_qualifier_subscript: { \tl_put_right:Nx \l_siunitx_unit_current_tl { \exp_not:N \PrintSubscript { \exp_not:V \l_siunitx_tmpa_tl } } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_qualifier_text: { +\cs_new_protected:Npn \siunitx_unit_format_qualifier_text: { \tl_put_right:NV \l_siunitx_unit_current_tl \l_siunitx_tmpa_tl } -\cs_new_protected_nopar:Npn \siunitx_unit_format_sorted: { +\cs_new_protected:Npn \siunitx_unit_format_sorted: { \tl_set_eq:NN \l_siunitx_unit_tl \l_siunitx_unit_numerator_tl \tl_if_empty:NTF \l_siunitx_unit_tl { @@ -4880,7 +4895,7 @@ } \tl_put_right:NV \l_siunitx_unit_tl \l_siunitx_unit_denominator_tl } -\cs_new_protected_nopar:Npn \siunitx_unit_format_symbol: { +\cs_new_protected:Npn \siunitx_unit_format_symbol: { \tl_set:Nx \l_siunitx_tmpa_tl { symbol- \int_use:N \l_siunitx_unit_int } \prop_get:NVNTF \l_siunitx_unit_prop \l_siunitx_tmpa_tl @@ -4890,13 +4905,14 @@ } { \siunitx_unit_format_symbol_aux: } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_symbol_aux: { +\cs_new_protected:Npn \siunitx_unit_format_symbol_aux: { \msg_error:nn { siunitx } { prefix-only } } -\cs_new_protected_nopar:Npn \siunitx_unit_format_symbol_aux_alt: { +\cs_new_protected:Npn \siunitx_unit_format_symbol_aux_alt: { \int_compare:nNnTF { \l_siunitx_unit_int } = { 1 } { \prop_del:Nn \l_siunitx_unit_prop { prefix-1 } + \prop_del:Nn \l_siunitx_unit_prop { prefix-symbol-1 } \prop_del:Nn \l_siunitx_unit_prop { prefix-base-1 } \prop_if_empty:NF \l_siunitx_unit_prop { \msg_error:nn { siunitx } { prefix-only } } @@ -5003,7 +5019,7 @@ \siunitx_print:nV { unit } \l_siunitx_unit_tl } \cs_generate_variant:Nn \siunitx_unit_output:nn { V } -\cs_new_protected_nopar:Npn \siunitx_unit_output_number_sep: { +\cs_new_protected:Npn \siunitx_unit_output_number_sep: { \bool_if:NTF \l_siunitx_number_unit_breaks_bool { \penalty \binoppenalty } { \nobreak } \bool_if:NTF \l_siunitx_per_auto_bool @@ -5023,18 +5039,18 @@ } { \siunitx_unit_output_number_sep_aux: } } -\cs_new_protected_nopar:Npn \siunitx_unit_output_number_sep_aux: { +\cs_new_protected:Npn \siunitx_unit_output_number_sep_aux: { \bool_if:NF \l_siunitx_omit_unit_space_bool - { \siunitx_ensuremath:n { \l_siunitx_number_unit_product_tl } } + { \ensuremath { \l_siunitx_number_unit_product_tl } } } -\cs_new_protected_nopar:Npn \siunitx_unit_output_pre_print: { +\cs_new_protected:Npn \siunitx_unit_output_pre_print: { \tl_if_empty:NF \l_siunitx_pre_unit_tl { \nobreak \siunitx_print:nV { unit } \l_siunitx_pre_unit_tl } } -\cs_new_protected_nopar:Npn \siunitx_unit_output_print: { +\cs_new_protected:Npn \siunitx_unit_output_print: { \int_compare:nNnF { \l_siunitx_unit_prefix_int } = { 0 } { \tl_set:Nx \l_siunitx_tmpa_tl @@ -5088,7 +5104,7 @@ } { \siunitx_unit_output_pre_print: - \siunitx_print:nn { number } { \siunitx_ensuremath:n {#1} } + \siunitx_print:nn { number } { \ensuremath {#1} } \siunitx_unit_output_print: } } @@ -5127,80 +5143,100 @@ \bool_new:N \l_siunitx_list_repeat_bool \tl_new:N \l_siunitx_list_current_tl \tl_new:N \l_siunitx_list_tl -\keys_define:nn { siunitx } { - list-final-separator .tl_set:N = \l_siunitx_list_separator_final_tl, - list-separator .tl_set:N = \l_siunitx_list_separator_tl, - list-units .choice:, - list-units - / brackets .code:n = - { - \bool_set_true:N \l_siunitx_list_brackets_bool - \bool_set_false:N \l_siunitx_list_repeat_bool - }, - list-units - / repeat .code:n = - { - \bool_set_false:N \l_siunitx_list_brackets_bool - \bool_set_true:N \l_siunitx_list_repeat_bool - }, - list-units - / single .code:n = - { - \bool_set_false:N \l_siunitx_list_brackets_bool - \bool_set_false:N \l_siunitx_list_repeat_bool - }, -} -\keys_set:nn { siunitx } { - list-final-separator = { ~ and ~ }, - list-separator = { , ~ }, - list-units = repeat, -} -\cs_new_protected:Npn \siunitx_list_numbers:n #1 { - \tl_clear:N \l_siunitx_unit_tl - \tl_clear:N \l_siunitx_preunit_tl - \siunitx_list_numbers_aux_i:n {#1} -} -\cs_new_protected:Npn \siunitx_list_numbers_aux_i:n #1 { - \tl_clear:N \l_siunitx_list_tl - \tl_clear:N \l_siunitx_list_current_tl - \tl_map_function:nN {#1} \siunitx_list_numbers_aux_ii:n - \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_separator_final_tl - \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_current_tl - \tl_use:N \l_siunitx_list_tl -} -\cs_new_protected:Npn \siunitx_list_numbers_aux_ii:n #1 { - \tl_if_empty:NTF \l_siunitx_list_tl - { \tl_set_eq:NN \l_siunitx_list_tl \l_siunitx_list_current_tl } - { - \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_separator_tl - \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_current_tl - } - \tl_set:Nn \l_siunitx_list_current_tl - { \siunitx_combined_output:n {#1} } -} -\cs_new_protected:Npn \siunitx_list_units:nnn #1#2#3 { - \siunitx_unit_parse_options:nn {#2} {#3} - \bool_if:NTF \l_siunitx_list_repeat_bool - { - \siunitx_unit_in:nn {#2} {#3} - \siunitx_list_numbers_aux_i:n {#1} - } - { - \bool_if:NT \l_siunitx_list_brackets_bool +\keys_define:nn { siunitx } + { + list-final-separator .tl_set:N = \l_siunitx_list_separator_final_tl , + list-pair-separator .tl_set:N = \l_siunitx_list_separator_pair_tl , + list-separator .tl_set:N = \l_siunitx_list_separator_tl , + list-units .choice:, + list-units + / brackets .code:n = + { + \bool_set_true:N \l_siunitx_list_brackets_bool + \bool_set_false:N \l_siunitx_list_repeat_bool + }, + list-units + / repeat .code:n = { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_open_tl } } - } - \siunitx_list_numbers:n {#1} - \bool_if:NT \l_siunitx_list_brackets_bool + \bool_set_false:N \l_siunitx_list_brackets_bool + \bool_set_true:N \l_siunitx_list_repeat_bool + }, + list-units + / single .code:n = { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_close_tl } } + \bool_set_false:N \l_siunitx_list_brackets_bool + \bool_set_false:N \l_siunitx_list_repeat_bool } - \siunitx_unit_output_number_sep: - \siunitx_unit_output:nn {#2} {#3} - } + } +\keys_set:nn { siunitx } + { + list-final-separator = { ~ and ~ } , + list-pair-separator = { ~ and ~ } , + list-separator = { , ~ } , + list-units = repeat } +\cs_new_protected:Npn \siunitx_list_numbers:n #1 + { + \tl_clear:N \l_siunitx_unit_tl + \tl_clear:N \l_siunitx_preunit_tl + \siunitx_list_numbers_aux_i:n {#1} + } +\cs_new_protected:Npn \siunitx_list_numbers_aux_i:n #1 + { + \bool_set_true:N \l_siunitx_list_first_bool + \tl_clear:N \l_siunitx_list_current_tl + \int_compare:nNnTF { \tl_length:n {#1} } > \c_two + { + \tl_map_function:nN {#1} \siunitx_list_numbers_aux_ii:n + \l_siunitx_list_tl + \l_siunitx_list_separator_final_tl + \l_siunitx_list_current_tl + } + { + \int_compare:nNnTF { \tl_length:n {#1} } = \c_two + { \siunitx_list_numbers_aux:nn #1 } + { \siunitx_combined_output:n {#1} } + } + \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_separator_final_tl + \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_current_tl + } +\cs_new_protected:Npn \siunitx_list_numbers_aux_ii:n #1 + { + \tl_if_empty:NTF \l_siunitx_list_tl + { \tl_set_eq:NN \l_siunitx_list_tl \l_siunitx_list_current_tl } + { + \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_separator_tl + \tl_put_right:NV \l_siunitx_list_tl \l_siunitx_list_current_tl + } + \tl_set:Nn \l_siunitx_list_current_tl { \siunitx_combined_output:n {#1} } + } +\cs_new_protected:Npn \siunitx_list_numbers_aux:nn #1#2 + { + \siunitx_combined_output:n {#1} + \l_siunitx_list_separator_pair_tl + \siunitx_combined_output:n {#2} + } +\cs_new_protected:Npn \siunitx_list_units:nnn #1#2#3 + { + \siunitx_unit_parse_options:nn {#2} {#3} + \bool_if:NTF \l_siunitx_list_repeat_bool + { + \siunitx_unit_in:nn {#2} {#3} + \siunitx_list_numbers_aux_i:n {#1} + } + { + \bool_if:NT \l_siunitx_process_fixed_bool + { \bool_set_true:N \l_siunitx_process_drop_exponent_bool } + \bool_if:NT \l_siunitx_list_brackets_bool + { \siunitx_print:nV { number } \l_siunitx_bracket_open_tl } + \siunitx_list_numbers:n {#1} + \bool_if:NT \l_siunitx_list_brackets_bool + { \siunitx_print:nV { number } \l_siunitx_bracket_close_tl } + \siunitx_range_exponent: + \siunitx_unit_output_number_sep: + \siunitx_unit_output:nn {#2} {#3} + } + } \bool_new:N \l_siunitx_range_brackets_bool \bool_new:N \l_siunitx_range_repeat_bool \keys_define:nn { siunitx } { @@ -5229,27 +5265,29 @@ range-phrase = { ~ to ~ }, range-units = repeat, } -\cs_new_protected:Npn \siunitx_range_numbers:nn #1#2 { - \siunitx_range_numbers_aux:n {#1} - \l_siunitx_range_phrase_tl - \siunitx_range_numbers_aux:n {#2} -} -\cs_new_protected:Npn \siunitx_range_numbers_aux:n #1 { - \bool_if:NTF \l_siunitx_number_parse_bool - { - \tl_clear:N \l_siunitx_number_out_tl - \tl_clear:N \l_siunitx_number_out_saved_tl - \bool_set_false:N \l_siunitx_number_compound_bool - \siunitx_number_output_parse:n {#1} - \bool_if:NT \l_siunitx_number_compound_bool - { \msg_error:nnx { siunitx } { multi-part-range } {#1} } - } - { - \siunitx_unit_output_pre_print: - \siunitx_print:nn { number } {#1} - \siunitx_unit_output_print: - } -} +\cs_new_protected:Npn \siunitx_range_numbers:nn #1#2 + { + \siunitx_range_numbers_aux:n {#1} + \l_siunitx_range_phrase_tl + \siunitx_range_numbers_aux:n {#2} + } +\cs_new_protected:Npn \siunitx_range_numbers_aux:n #1 + { + \bool_if:NTF \l_siunitx_number_parse_bool + { + \tl_clear:N \l_siunitx_number_out_tl + \tl_clear:N \l_siunitx_number_out_saved_tl + \bool_set_false:N \l_siunitx_number_compound_bool + \siunitx_number_output_parse:n {#1} + \bool_if:NT \l_siunitx_number_compound_bool + { \msg_error:nnx { siunitx } { multi-part-range } {#1} } + } + { + \siunitx_unit_output_pre_print: + \siunitx_print:nn { number } {#1} + \siunitx_unit_output_print: + } + } \cs_new_protected:Npn \siunitx_range_unit:nnnn #1#2#3#4 { \siunitx_unit_parse_options:nn {#1} {#2} \bool_if:NTF \l_siunitx_range_repeat_bool @@ -5260,21 +5298,34 @@ \siunitx_range_numbers_aux:n {#4} } { + \bool_if:NT \l_siunitx_process_fixed_bool + { \bool_set_true:N \l_siunitx_process_drop_exponent_bool } \bool_if:NT \l_siunitx_range_brackets_bool - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_open_tl } } - } + { \siunitx_print:nV { number } \l_siunitx_bracket_open_tl } \siunitx_range_numbers:nn {#3} {#4} \bool_if:NT \l_siunitx_range_brackets_bool - { - \siunitx_print:nn { number } - { \siunitx_ensuremath:n { \l_siunitx_bracket_close_tl } } - } + { \siunitx_print:nV { number } \l_siunitx_bracket_close_tl } + \siunitx_range_exponent: \siunitx_unit_output_number_sep: \siunitx_unit_output:nn {#1} {#2} } } +\cs_new_protected:Npn \siunitx_range_exponent: + { + \bool_if:NT \l_siunitx_process_fixed_bool + { + \tl_set_eq:NN \l_siunitx_tmpa_tl \l_siunitx_exponent_product_tl + \bool_if:NT \l_siunitx_tight_bool + { \tl_set:Nx \l_siunitx_tmpa_tl { { \exp_not:o \l_siunitx_tmpa_tl } } } + \tl_set:Nx \l_siunitx_tmpa_tl + { + \exp_not:N \ensuremath { { } \exp_not:o \l_siunitx_tmpa_tl { } } + 10 \exp_not:N \PrintSuperscript + { \int_use:N \l_siunitx_process_fixed_int } + } + \siunitx_print:nV { number } \l_siunitx_tmpa_tl + } + } \AtBeginDocument { \@ifpackageloaded { cellspace } { @@ -5287,9 +5338,9 @@ } { } } -\cs_new_protected_nopar:Npn \siunitx_table_rewrite_create:N #1 { +\cs_new_protected:Npn \siunitx_table_rewrite_create:N #1 { \newcolumntype {#1} { } - \cs_set_protected_nopar:Npn + \cs_set_protected:Npn \siunitx_table_rewrite_create_aux:w \NC@do ##1##2 \NC@do #1 { \NC@list { \NC@do ##1 \NC@do #1 ##2 } } \exp_after:wN \siunitx_table_rewrite_create_aux:w \tex_the:D \NC@list @@ -5305,7 +5356,7 @@ \NC@find } } -\cs_new_protected_nopar:Npn \siunitx_table_rewrite_create_aux:w { } +\cs_new_protected:Npn \siunitx_table_rewrite_create_aux:w { } \AtBeginDocument { \siunitx_table_rewrite_create:N s } \AtBeginDocument { \siunitx_table_rewrite_create:N S } \tl_new:N \l_siunitx_table_collect_tl @@ -5319,14 +5370,14 @@ \keys_set:nn { siunitx } {#2} \use:c { siunitx_table_collect_begin_ #1 : } } -\cs_new_protected_nopar:Npn \siunitx_table_collect_begin_s: { +\cs_new_protected:Npn \siunitx_table_collect_begin_s: { \cs_set_eq:NN \siunitx_table_collect_token:N \siunitx_table_collect_token_s:N \cs_set_eq:NN \siunitx_table_print: \siunitx_table_print_s: \siunitx_table_collect_init_s: \siunitx_table_collect_get: } -\cs_new_protected_nopar:Npn \siunitx_table_collect_begin_S: { +\cs_new_protected:Npn \siunitx_table_collect_begin_S: { \cs_set_eq:NN \siunitx_table_collect_token:N \siunitx_table_collect_token_S:N \cs_set_eq:NN \siunitx_table_print: \siunitx_table_print_S: @@ -5356,7 +5407,7 @@ { \tl_use:N \l_siunitx_table_collect_pre_tl \tl_clear:N \l_siunitx_table_collect_pre_tl - \cs_set_nopar:Npn \siunitx_table_collect_next: + \cs_set:Npn \siunitx_table_collect_next: { \exp_after:wN \siunitx_table_collect_get: #1 } } { @@ -5388,10 +5439,10 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_table_collect_get: { +\cs_new_protected:Npn \siunitx_table_collect_get: { \cs_set_eq:NN \siunitx_table_collect_next: \siunitx_table_collect_get: - \cs_set_nopar:Npn \peek_execute_branches: + \cs_set:Npn \peek_execute_branches: { \if_catcode:w \exp_not:N \l_peek_token \c_group_begin_token \exp_after:wN \siunitx_table_collect_braced:n @@ -5401,14 +5452,14 @@ } \peek_after:Nw \peek_ignore_spaces_execute_branches: } -\cs_new_protected_nopar:Npn \siunitx_table_collect_init: { +\cs_new_protected:Npn \siunitx_table_collect_init: { \tl_clear:N \l_siunitx_table_collect_tl \tl_clear:N \l_siunitx_table_collect_pre_tl \tl_clear:N \l_siunitx_table_collect_post_tl \bool_set_false:N \l_siunitx_table_collect_post_bool \bool_set_false:N \l_siunitx_table_math_bool } -\cs_new_protected_nopar:Npn \siunitx_table_collect_init_s: { +\cs_new_protected:Npn \siunitx_table_collect_init_s: { \siunitx_table_collect_init: \bool_set_false:N \l_siunitx_table_collect_pre_bool \cs_set_protected:Npn \siunitx_table_collect_braced:n ##1 @@ -5417,7 +5468,7 @@ \siunitx_table_collect_next: } } -\cs_new_protected_nopar:Npn \siunitx_table_collect_init_S: { +\cs_new_protected:Npn \siunitx_table_collect_init_S: { \siunitx_number_in_init: \tl_set:Nx \l_siunitx_number_valid_tl { @@ -5444,13 +5495,13 @@ \siunitx_table_collect_next: } } -\cs_new_protected_nopar:Npn \siunitx_table_collect_next: { } -\cs_new_protected_nopar:Npn \siunitx_table_collect_newline: { +\cs_new_protected:Npn \siunitx_table_collect_next: { } +\cs_new_protected:Npn \siunitx_table_collect_newline: { \siunitx_table_print: \cs_set_eq:NN \siunitx_table_print: \prg_do_nothing: \tabularnewline } -\cs_new_protected_nopar:Npn \siunitx_table_collect_end: { +\cs_new_protected:Npn \siunitx_table_collect_end: { \siunitx_table_print: \cs_set_eq:NN \siunitx_table_print: \prg_do_nothing: \end @@ -5513,21 +5564,21 @@ { \@ifpackageloaded { colortbl } { - \cs_new_protected_nopar:Npn \siunitx_table_colortbl_correction: + \cs_new_protected:Npn \siunitx_table_colortbl_correction: { \skip_horizontal:n { \c_zero_skip plus -0.5 fill } \tex_kern:D \c_zero_skip } } - { \cs_new_protected_nopar:Npn \siunitx_table_colortbl_correction: { } } + { \cs_new_protected:Npn \siunitx_table_colortbl_correction: { } } } -\cs_new_protected_nopar:Npn \siunitx_table_align_left:n #1 +\cs_new_protected:Npn \siunitx_table_align_left:n #1 { \siunitx_table_colortbl_correction: \skip_horizontal:n {#1} \tex_kern:D \c_zero_skip } -\cs_new_protected_nopar:Npn \siunitx_table_align_right:n #1 +\cs_new_protected:Npn \siunitx_table_align_right:n #1 { \skip_horizontal:n { \c_siunitx_one_fill_skip - #1 } \tex_kern:D \c_zero_skip @@ -5547,7 +5598,7 @@ \siunitx_table_align_right:n } { - \cs_set_protected_nopar:Npn \siunitx_table_column_begin:n ##1 + \cs_set_protected:Npn \siunitx_table_column_begin:n ##1 { \siunitx_table_colortbl_correction: \tex_hbox:D to \dim_eval:n {#1} @@ -5555,7 +5606,7 @@ \skip_horizontal:n {##1} \tex_kern:D \c_zero_skip } - \cs_set_protected_nopar:Npn \siunitx_table_column_end:n ##1 + \cs_set_protected:Npn \siunitx_table_column_end:n ##1 { \skip_horizontal:n { \c_siunitx_one_fill_skip - ##1 } \tex_kern:D \c_zero_skip @@ -5586,7 +5637,7 @@ } } \keys_set:nn { siunitx } { table-unit-alignment = center } -\cs_new_protected_nopar:Npn \siunitx_table_print_s: +\cs_new_protected:Npn \siunitx_table_print_s: { \siunitx_table_column_begin:n { \l_siunitx_table_unit_align_skip } \siunitx_unit_output:Vn \l_siunitx_table_collect_tl { } @@ -5608,16 +5659,9 @@ \box_new:N \l_siunitx_table_result_box \skip_new:N \l_siunitx_table_number_align_skip \skip_new:N \l_siunitx_table_text_align_skip -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_main: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_main: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_parsed: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_pre: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_post: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_exponent_aux: { } -\cs_new_protected_nopar:Npn - \siunitx_table_print_S_reserved_mantissa_uncert_aux: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_round: { } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_store_fill:n #1 { } +\cs_new_protected:Npn \siunitx_table_print_S_direct_main: { } +\cs_new_protected:Npn \siunitx_table_print_S_parsed: { } +\cs_new_protected:Npn \siunitx_table_print_S_reserved_store_fill:n #1 { } \keys_define:nn { siunitx } { table-align-comparator .choice:, @@ -5634,73 +5678,14 @@ \siunitx_table_print_S_reserved_store_fill_mid:n }, table-align-comparator .default:n = true, - table-align-exponent .choice:, - table-align-exponent / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_exponent_aux: - \siunitx_table_print_S_reserved_exponent_not_aligned: - }, - table-align-exponent / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_exponent_aux: - \siunitx_table_print_S_reserved_exponent_aligned: - }, - table-align-exponent .default:n = true, - table-align-text-pre .choice:, - table-align-text-pre / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_pre: - \siunitx_table_print_S_pre_not_aligned: - }, - table-align-text-pre / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_pre: - \siunitx_table_print_S_pre_aligned: - }, - table-align-text-pre .default:n = true , - table-align-text-post .choice:, - table-align-text-post / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_post: - \siunitx_table_print_S_post_not_aligned: - }, - table-align-text-post / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_post: - \siunitx_table_print_S_post_aligned: - }, - table-align-text-post .default:n = true , - table-align-uncertainty .choice:, - table-align-uncertainty / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_mantissa_uncert_aux: - \siunitx_table_print_S_reserved_mantissa_uncert_not_aligned: - }, - table-align-uncertainty / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_mantissa_uncert_aux: - \siunitx_table_print_S_reserved_mantissa_uncert_aligned: - }, - table-align-uncertainty .default:n = true, - table-auto-round .choice:, - table-auto-round / - false .code:n = - { \cs_set_eq:NN \prg_do_nothing: }, - table-auto-round / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_reserved_round: - \siunitx_table_print_S_reserved_round_auto: - }, - table-auto-round .default:n = true, + table-align-exponent .bool_set:N = + \l_siunitx_table_align_exponent_bool, + table-align-text-pre .bool_set:N = + \l_siunitx_table_align_text_pre_bool, + table-align-text-post .bool_set:N = + \l_siunitx_table_align_text_post_bool, + table-align-uncertainty .bool_set:N = \l_siunitx_table_align_uncert_bool, + table-auto-round .bool_set:N = \l_siunitx_table_auto_round_bool, table-number-alignment .choice:, table-number-alignment / center .code:n = @@ -5741,20 +5726,8 @@ \cs_set_eq:NN \siunitx_table_print_S_parsed: \siunitx_table_print_S_reserved: }, - table-omit-exponent .choice:, - table-omit-exponent / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_parse_aux: - \siunitx_number_process: - }, - table-omit-exponent / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_parse_aux: - \siunitx_table_print_S_parse_omit_exp: - }, - table-omit-exponent .default:n = true, + table-omit-exponent .bool_set:N = + \l_siunitx_table_omit_exponent_bool, table-text-alignment .choice:, table-text-alignment / center .code:n = @@ -5841,20 +5814,7 @@ { \prg_replicate:nn {#1} { 8 } } } }, - table-parse-only .choice: , - table-parse-only / - false .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_main: - \siunitx_table_print_S_alignment: - }, - table-parse-only / - true .code:n = - { - \cs_set_eq:NN \siunitx_table_print_S_main: - \siunitx_table_print_S_no_alignment: - }, - table-parse-only .default:n = true, + table-parse-only .bool_set:N = \l_siunitx_table_parse_only_bool, table-space-text-pre .tl_set:N = \l_siunitx_table_pre_tl, table-space-text-post .tl_set:N = \l_siunitx_table_post_tl, table-sign-exponent .code:n = @@ -5907,7 +5867,7 @@ \keys_set:nV { siunitx } \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S: +\cs_new_protected:Npn \siunitx_table_print_S: { \bool_if:NTF \l_siunitx_table_collect_pre_bool { @@ -5918,40 +5878,46 @@ { \siunitx_table_column_begin:n { \l_siunitx_table_number_align_skip } \siunitx_detect_font: - \siunitx_table_print_S_main: - \siunitx_table_print_S_pre: + \bool_if:NTF \l_siunitx_table_parse_only_bool + { \siunitx_table_print_S_no_alignment: } + { \siunitx_table_print_S_alignment: } + \bool_if:NTF \l_siunitx_table_align_text_pre_bool + { \siunitx_table_print_S_pre_aligned: } + { \siunitx_table_print_S_pre_not_aligned: } \box_use:N \l_siunitx_table_result_box - \siunitx_table_print_S_post: + \bool_if:NTF \l_siunitx_table_align_text_post_bool + { \siunitx_table_print_S_post_aligned: } + { \siunitx_table_print_S_post_not_aligned: } \siunitx_table_column_end:n { \l_siunitx_table_number_align_skip } } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_no_alignment: +\cs_new_protected:Npn \siunitx_table_print_S_no_alignment: { \l_siunitx_table_collect_pre_tl \siunitx_number_output:V \l_siunitx_table_collect_tl \l_siunitx_table_collect_post_tl } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_alignment: +\cs_new_protected:Npn \siunitx_table_print_S_alignment: { \siunitx_table_print_S_parsed: } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_parse: +\cs_new_protected:Npn \siunitx_table_print_S_parse: { \bool_set_false:N \l_siunitx_error_bool \siunitx_number_in_parse:V \l_siunitx_table_collect_tl \bool_if:NF \l_siunitx_error_bool { - \siunitx_table_print_S_parse_aux: + \bool_if:NTF \l_siunitx_table_omit_exponent_bool + { + \bool_set_true:N \l_siunitx_process_fixed_bool + \siunitx_number_process: + \prop_del:Nn \l_siunitx_number_in_prop { exponent } + \prop_del:Nn \l_siunitx_number_in_prop { exponent-integer } + } + { \siunitx_number_process: } \siunitx_number_format: \siunitx_number_output_color: } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_parse_omit_exp: - { - \bool_set_true:N \l_siunitx_process_fixed_bool - \siunitx_number_process: - \prop_del:Nn \l_siunitx_number_in_prop { exponent } - \prop_del:Nn \l_siunitx_number_in_prop { exponent-integer } -} -\cs_new_protected_nopar:Npn \siunitx_table_print_S_measure:NN #1#2 +\cs_new_protected:Npn \siunitx_table_print_S_measure:NN #1#2 { \tl_if_empty:NTF #1 { \dim_zero:N #2 } @@ -5960,30 +5926,30 @@ \hbox_set:Nn \l_siunitx_tmp_box { \siunitx_print:nV { number } #1 } \exp_args:NNNo \group_end: - \dim_set:Nn #2 { \tex_the:D \box_wd:N \l_siunitx_tmp_box } + \dim_set:Nn #2 { \dim_use:N \box_wd:N \l_siunitx_tmp_box } } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_pre_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_pre_aligned: { \box_use:N \l_siunitx_table_pre_box \hbox_to_wd:nn { \l_siunitx_table_fill_pre_dim } { \tex_hfil:D } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_pre_not_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_pre_not_aligned: { \hbox_to_wd:nn { \l_siunitx_table_fill_pre_dim } { \tex_hfil:D } \box_use:N \l_siunitx_table_pre_box } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_post_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_post_aligned: { \hbox_to_wd:nn { \l_siunitx_table_fill_post_dim } { \tex_hfil:D } \box_use:N \l_siunitx_table_post_box } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_post_not_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_post_not_aligned: { \box_use:N \l_siunitx_table_post_box \hbox_to_wd:nn { \l_siunitx_table_fill_post_dim } { \tex_hfil:D } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered: +\cs_new_protected:Npn \siunitx_table_print_S_centered: { \siunitx_table_print_S_centered_ends: \bool_if:NT \l_siunitx_table_math_bool { \c_math_toggle_token } @@ -6006,7 +5972,7 @@ { \siunitx_table_print_S_centered_decimal: } } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_ends: +\cs_new_protected:Npn \siunitx_table_print_S_centered_ends: { \hbox_set:Nn \l_siunitx_table_pre_box { @@ -6051,13 +6017,13 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_measure: +\cs_new_protected:Npn \siunitx_table_print_S_centered_measure: { \siunitx_table_print_S_centered_measure_int_part: \siunitx_table_print_S_centered_measure_marker: \siunitx_table_print_S_centered_measure_result: } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_measure_int_part: +\cs_new_protected:Npn \siunitx_table_print_S_centered_measure_int_part: { \prop_get:NnNF \l_siunitx_number_out_prop { comparator } \l_siunitx_tmpa_tl { \tl_clear:N \l_siunitx_tmpa_tl } @@ -6070,17 +6036,12 @@ \siunitx_table_print_S_measure:NN \l_siunitx_tmpa_tl \l_siunitx_table_integer_dim } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_measure_marker: +\cs_new_protected:Npn \siunitx_table_print_S_centered_measure_marker: { - \tl_set:Nx \l_siunitx_tmpa_tl - { - \exp_not:N \siunitx_ensuremath:n - { \exp_not:o \l_siunitx_output_decimal_tl } - } - \siunitx_table_print_S_measure:NN \l_siunitx_tmpa_tl + \siunitx_table_print_S_measure:NN \l_siunitx_output_decimal_tl \l_siunitx_table_marker_dim } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_measure_result: +\cs_new_protected:Npn \siunitx_table_print_S_centered_measure_result: { \prop_get:NnN \l_siunitx_number_out_prop { result } \l_siunitx_tmpa_tl \hbox_set:Nn \l_siunitx_table_result_box @@ -6088,23 +6049,24 @@ \dim_set:Nn \l_siunitx_table_result_dim { \box_wd:N \l_siunitx_table_result_box } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_integer: +\cs_new_protected:Npn \siunitx_table_print_S_centered_integer: { \dim_set:Nn \l_siunitx_table_fill_post_dim { \l_siunitx_table_integer_dim - \l_siunitx_table_fill_pre_dim } \dim_zero:N \l_siunitx_table_fill_pre_dim } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_centered_decimal: +\cs_new_protected:Npn \siunitx_table_print_S_centered_decimal: { \dim_sub:Nn \l_siunitx_table_fill_pre_dim { \l_siunitx_table_integer_dim } \dim_zero:N \l_siunitx_table_fill_post_dim } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved: +\cs_new_protected:Npn \siunitx_table_print_S_reserved: { \siunitx_table_print_S_reserved_init: \siunitx_table_print_S_reserved_ends: - \siunitx_table_print_S_reserved_round: + \bool_if:NT \l_siunitx_table_auto_round_bool + { \siunitx_table_print_S_reserved_round_auto: } \siunitx_table_print_S_parse: \bool_if:NF \l_siunitx_error_bool { @@ -6115,7 +6077,7 @@ \bool_if:NT \l_siunitx_table_math_bool { \c_math_toggle_token } } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_init: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_init: { \dim_zero:N \l_siunitx_table_fill_mid_dim \dim_zero:N \l_siunitx_table_fill_post_dim @@ -6134,7 +6096,7 @@ } \prop_set_eq:NN \l_siunitx_table_model_prop \l_siunitx_number_out_prop } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_ends: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_ends: { \hbox_set:Nn \l_siunitx_table_pre_box { @@ -6172,7 +6134,7 @@ \tex_hfil:D } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_round_auto: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_round_auto: { \prop_get:NnNTF \l_siunitx_table_model_prop { mantissa-decimal-raw } \l_siunitx_tmpa_tl @@ -6180,7 +6142,7 @@ { \int_zero:N \l_siunitx_process_precision_int } \tl_set:Nn \l_siunitx_round_tl { places } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_comparator: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_comparator: { \prop_get:NnNTF \l_siunitx_table_model_prop { comparator } \l_siunitx_tmpa_tl @@ -6211,11 +6173,11 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_store_fill_pre:n +\cs_new_protected:Npn \siunitx_table_print_S_reserved_store_fill_pre:n { \dim_add:Nn \l_siunitx_table_fill_pre_dim } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_store_fill_mid:n +\cs_new_protected:Npn \siunitx_table_print_S_reserved_store_fill_mid:n { \dim_add:Nn \l_siunitx_table_fill_mid_dim } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_mantissa: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa: { \prop_get:NnNTF \l_siunitx_table_model_prop { mantissa } \l_siunitx_tmpa_tl @@ -6244,7 +6206,7 @@ } } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_mantissa_parts: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_parts: { \siunitx_table_print_S_reserved_mantissa_integer: \hbox_set:Nn \l_siunitx_table_result_box @@ -6261,7 +6223,7 @@ } \siunitx_table_print_S_reserved_mantissa_uncert: } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_mantissa_integer: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_integer: { \prop_get:NnNF \l_siunitx_table_model_prop { mantissa-sign } \l_siunitx_tmpa_tl @@ -6286,7 +6248,7 @@ \siunitx_table_print_S_reserved_store_fill:n { \l_siunitx_table_integer_dim } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_mantissa_uncert: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_uncert: { \prop_get:NnNT \l_siunitx_table_model_prop { mantissa-uncertainty } \l_siunitx_tmpa_tl @@ -6302,7 +6264,9 @@ \siunitx_number_format_join_uncert_pm:N \l_siunitx_tmpa_tl \hbox_set:Nn \l_siunitx_tmp_box { \siunitx_print:nV { number } \l_siunitx_tmpa_tl } - \siunitx_table_print_S_reserved_mantissa_uncert_aux: + \bool_if:NTF \l_siunitx_table_align_uncert_bool + { \siunitx_table_print_S_reserved_mantissa_uncert_aligned: } + { \siunitx_table_print_S_reserved_mantissa_uncert_not_aligned: } } { \siunitx_table_print_S_reserved_store_fill:n @@ -6310,7 +6274,7 @@ } } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_uncert_aligned: { \hbox_set:Nn \l_siunitx_table_result_box @@ -6322,7 +6286,7 @@ \dim_set:Nn \l_siunitx_table_fill_mid_dim { \l_siunitx_table_uncert_dim - \box_wd:N \l_siunitx_tmp_box } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_table_print_S_reserved_mantissa_uncert_not_aligned: { \hbox_set:Nn \l_siunitx_table_result_box @@ -6336,7 +6300,7 @@ - \box_wd:N \l_siunitx_tmp_box } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_exponent: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent: { \prop_get:NnNTF \l_siunitx_table_model_prop { exponent-result } \l_siunitx_tmpa_tl @@ -6355,7 +6319,9 @@ { \siunitx_table_print_S_reserved_exponent_product_correction: } \hbox_set:Nn \l_siunitx_tmp_box { \siunitx_print:nV { number } \l_siunitx_tmpa_tl } - \siunitx_table_print_S_reserved_exponent_aux: + \bool_if:NTF \l_siunitx_table_align_exponent_bool + { \siunitx_table_print_S_reserved_exponent_aligned: } + { \siunitx_table_print_S_reserved_exponent_not_aligned: } } { \dim_set:Nn \l_siunitx_table_fill_post_dim @@ -6372,19 +6338,18 @@ \l_siunitx_table_fill_mid_dim } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_exponent_product: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent_product: { \tl_set_eq:NN \l_siunitx_tmpb_tl \l_siunitx_exponent_product_tl \bool_if:NT \l_siunitx_tight_bool { \tl_set:Nx \l_siunitx_tmpb_tl { { \exp_not:o \l_siunitx_tmpb_tl } } } \tl_set:Nx \l_siunitx_tmpa_tl { - \exp_not:N \siunitx_ensuremath:n - { { } \exp_not:o \l_siunitx_tmpb_tl { } } + \exp_not:N \ensuremath { { } \exp_not:o \l_siunitx_tmpb_tl { } } \exp_not:o \l_siunitx_tmpa_tl } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent_product_correction: { \group_begin: @@ -6398,7 +6363,7 @@ \siunitx_table_print_S_reserved_store_fill:n { \l_siunitx_tmp_dim } \dim_sub:Nn \l_siunitx_table_exponent_dim { \l_siunitx_tmp_dim } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_reserved_exponent_aligned: +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent_aligned: { \hbox_set:Nn \l_siunitx_table_result_box { @@ -6412,7 +6377,7 @@ - \box_wd:N \l_siunitx_tmp_box } } -\cs_new_protected_nopar:Npn +\cs_new_protected:Npn \siunitx_table_print_S_reserved_exponent_not_aligned: { \hbox_set:Nn \l_siunitx_table_result_box @@ -6427,18 +6392,18 @@ - \box_wd:N \l_siunitx_tmp_box } } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct: +\cs_new_protected:Npn \siunitx_table_print_S_direct: { \m@th \siunitx_table_print_S_direct_main: } \char_set_catcode_active:N \@ -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_centered: +\cs_new_protected:Npn \siunitx_table_print_S_direct_centered: { \cs_set_eq:NN \siunitx_table_print: \siunitx_table_print_S_direct_centered_end: \hbox_set:Nn \l_siunitx_tmp_box - { \siunitx_ensuremath:n { \l_siunitx_output_decimal_tl } } + { \ensuremath { \l_siunitx_output_decimal_tl } } \hbox_set_to_wd:Nnn \l_siunitx_table_post_box { \box_wd:N \l_siunitx_tmp_box } { \tex_hfil:D } @@ -6448,11 +6413,11 @@ \tl_map_function:NN \l_siunitx_input_decimal_tl \siunitx_table_print_S_direct_centered_aux:N } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_centered_aux:N #1 +\cs_new_protected:Npn \siunitx_table_print_S_direct_centered_aux:N #1 { \char_set_lccode:nn { `\@ } { `#1 } \char_set_mathcode:nn { `#1 } { 32768 } - \tl_to_lowercase:n { \cs_set_nopar:Npn @ } + \tl_to_lowercase:n { \cs_set:Npn @ } { \c_math_toggle_token \c_group_end_token @@ -6463,7 +6428,7 @@ } } \char_set_catcode_letter:N \@ -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_centered_end: +\cs_new_protected:Npn \siunitx_table_print_S_direct_centered_end: { \c_math_toggle_token \c_group_end_token @@ -6490,7 +6455,7 @@ \box_use:N \l_siunitx_table_post_box } \char_set_catcode_active:N \@ -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_reserved: +\cs_new_protected:Npn \siunitx_table_print_S_direct_reserved: { \cs_set_eq:NN \siunitx_table_print: \siunitx_table_print_S_direct_reserved_end: @@ -6499,7 +6464,7 @@ { \tl_clear:N \l_siunitx_tmpa_tl } \hbox_set:Nn \l_siunitx_tmp_box { - \siunitx_ensuremath:n + \ensuremath { \prop_get:NnNT \l_siunitx_table_model_prop { mantissa-sign } \l_siunitx_tmpb_tl @@ -6514,7 +6479,7 @@ { \tl_clear:N \l_siunitx_tmpa_tl } \hbox_set:Nn \l_siunitx_tmp_box { - \siunitx_ensuremath:n + \ensuremath { \l_siunitx_output_decimal_tl \l_siunitx_tmpa_tl @@ -6531,11 +6496,11 @@ \siunitx_table_print_S_direct_reserved_aux:N \tex_hfill:D } -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_reserved_aux:N #1 +\cs_new_protected:Npn \siunitx_table_print_S_direct_reserved_aux:N #1 { \char_set_lccode:nn { `\@ } { `#1 } \char_set_mathcode:nn { `#1 } { 32768 } - \tl_to_lowercase:n { \cs_set_nopar:Npn @ } + \tl_to_lowercase:n { \cs_set:Npn @ } { \c_math_toggle_token \c_group_end_token @@ -6547,7 +6512,7 @@ } } \char_set_catcode_letter:N \@ -\cs_new_protected_nopar:Npn \siunitx_table_print_S_direct_reserved_end: +\cs_new_protected:Npn \siunitx_table_print_S_direct_reserved_end: { \c_math_toggle_token \tex_hfil:D @@ -6647,7 +6612,7 @@ text-ohm = \ensuremath { \c_siunitx_omega_tl }, } \cs_new_protected:Npn \siunitx_symbol_new:n #1 { - \cs_set_protected_nopar:cpn { SIUnitSymbol #1 } + \cs_set_protected:cpn { SIUnitSymbol #1 } { \mode_if_math:TF { \tl_to_lowercase:n { \use:c { l_siunitx_ #1 _math_tl } } } @@ -6662,7 +6627,7 @@ \siunitx_symbol_new:n { Micro } \siunitx_symbol_new:n { Ohm } \clist_new:N \l_siunitx_pgf_link_clist -\cs_new_protected_nopar:Npn \siunitx_pgf_link: { +\cs_new_protected:Npn \siunitx_pgf_link: { \clist_clear:N \l_siunitx_pgf_link_clist \str_if_eq:VnT \l_siunitx_round_tl { figure } { @@ -6678,10 +6643,7 @@ { { \exp_not:V \l_siunitx_output_decimal_tl } } } \clist_put_right:Nx \l_siunitx_pgf_link_clist - { - set~thousands~separator = - { \exp_not:V \l_siunitx_group_sep_tl } - } + { set~thousands~separator = { \exp_not:V \l_siunitx_group_sep_tl } } \clist_put_right:Nn \l_siunitx_pgf_link_clist { min~exponent~for~1000~sep = \int_use:N \l_siunitx_group_min_int } \bool_if:nF @@ -6712,7 +6674,7 @@ { showpos = false } } \group_begin: - \cs_set_nopar:Npx \siunitx_tmp:w + \cs_set:Npx \siunitx_tmp:w { \group_end: \exp_not:N \pgfqkeys @@ -6815,6 +6777,8 @@ The~input~'#1'~is~a~number~which~has~more~than~one~part: \\ ranges~can~only~contain~one~number~in~each~part. } +\msg_new:nnn { siunitx } { non-convertible-exponent } + { Exponent~'#1'~cannot~be~converted~into~a~symbolic~prefix. } \msg_new:nnn { siunitx } { option-not-available } { Option~'#1'~not~available~in~strict~mode. } \msg_new:nnn { siunitx } { option-preamble-only } @@ -6893,7 +6857,7 @@ \@onlypreamble \DeclareSIQualifier \@onlypreamble \DeclareSIUnit \@onlypreamble \DeclareSIUnitWithOptions -\cs_new_protected_nopar:Npn \SendSettingsToPgf { \siunitx_pgf_link: } +\cs_new_protected:Npn \SendSettingsToPgf { \siunitx_pgf_link: } \NewDocumentCommand \ang { o > { \SplitArgument { 2 } { ; } } m } { \group_begin: \IfNoValueF {#1} @@ -6991,9 +6955,9 @@ { \token_to_str:N \@writefile {#1} {#2} } } } -\cs_new_protected_nopar:Npn \siunitx_contents_add:N #1 - { \cs_set_nopar:Npn #1 { \token_to_str:N #1 } } -\cs_new_protected_nopar:Npn \siunitx_contents_bookmarks: +\cs_new_protected:Npn \siunitx_contents_add:N #1 + { \cs_set:Npn #1 { \token_to_str:N #1 } } +\cs_new_protected:Npn \siunitx_contents_bookmarks: { \tl_map_function:NN \l_siunitx_declare_list_tl \siunitx_unit_print_literal_aux:N @@ -7005,13 +6969,13 @@ \cs_set_eq:NN \SIrange \siunitx_bookmark_SIrange:w \cs_set_eq:NN \si \siunitx_bookmark_si:w \cs_set_eq:NN \siunitx_textsuperscript:n \use:n - \cs_set_nopar:Npn \SIUnitSymbolAngstrom { \AA } - \cs_set_nopar:Npn \SIUnitSymbolArcminute { ' } - \cs_set_nopar:Npn \SIUnitSymbolArcsecond { '' } - \cs_set_nopar:Npn \SIUnitSymbolCelsius { \textcelsius } - \cs_set_nopar:Npn \SIUnitSymbolDegree { \textdegree } - \cs_set_nopar:Npn \SIUnitSymbolMicro { \textmu } - \cs_set_nopar:Npn \SIUnitSymbolOhm { [ohm] } + \cs_set:Npn \SIUnitSymbolAngstrom { \AA } + \cs_set:Npn \SIUnitSymbolArcminute { ' } + \cs_set:Npn \SIUnitSymbolArcsecond { '' } + \cs_set:Npn \SIUnitSymbolCelsius { \textcelsius } + \cs_set:Npn \SIUnitSymbolDegree { \textdegree } + \cs_set:Npn \SIUnitSymbolMicro { \textmu } + \cs_set:Npn \SIUnitSymbolOhm { [ohm] } } \DeclareExpandableDocumentCommand \siunitx_bookmark_num:w { o m } {#2} \DeclareExpandableDocumentCommand \siunitx_bookmark_numrange:w { o m m } @@ -7187,10 +7151,10 @@ } } \siunitx_option_deactivate:n { strict } -\cs_new_protected_nopar:Npn \siunitx_strict_option:n #1 { +\cs_new_protected:Npn \siunitx_strict_option:n #1 { \clist_map_function:nN {#1} \siunitx_strict_option_aux:n } -\cs_new_protected_nopar:Npn \siunitx_strict_option_aux:n #1 { +\cs_new_protected:Npn \siunitx_strict_option_aux:n #1 { \keys_define:nn { siunitx } { #1 .code:n = { \msg_warning:nnx { siunitx } { option-not-available } {#1} } @@ -7265,12 +7229,12 @@ false .code:n = { } , binary-units .default:n = true } -\cs_new_protected_nopar:Npn \siunitx_load_abbreviations: +\cs_new_protected:Npn \siunitx_load_abbreviations: { \@onefilewithoptions { siunitx-abbreviations } [ ] [ ] \c_siunitx_configuration_ext_tl } -\cs_new_protected_nopar:Npn \siunitx_load_binary: +\cs_new_protected:Npn \siunitx_load_binary: { \@onefilewithoptions { siunitx-binary } [ ] [ ] \c_siunitx_configuration_ext_tl -- cgit v1.2.3