diff options
author | Karl Berry <karl@freefriends.org> | 2023-01-03 20:48:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-01-03 20:48:54 +0000 |
commit | 1b5abf4a65fe416aecdb56564546076514fe3c7d (patch) | |
tree | b77e20ca831bb56c88b1bd9737103d66c553f242 /Master/texmf-dist/source/latex/siunitx/siunitx-number.dtx | |
parent | d1a0bd826619d5cb07de57865ef733b300e52bbe (diff) |
siunitx (3jan23)
git-svn-id: svn://tug.org/texlive/trunk@65450 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/siunitx/siunitx-number.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/siunitx/siunitx-number.dtx | 158 |
1 files changed, 146 insertions, 12 deletions
diff --git a/Master/texmf-dist/source/latex/siunitx/siunitx-number.dtx b/Master/texmf-dist/source/latex/siunitx/siunitx-number.dtx index f08a6a8c0f1..007d0b08257 100644 --- a/Master/texmf-dist/source/latex/siunitx/siunitx-number.dtx +++ b/Master/texmf-dist/source/latex/siunitx/siunitx-number.dtx @@ -286,8 +286,18 @@ % % \begin{function}{exponent-mode} % \begin{syntax} -% |exponent-mode| = |engineering|\verb"|"|fixed|\verb"|"|input|\verb"|"|scientific| +% |exponent-mode| = |engineering|\verb"|"|fixed|\verb"|"|input|\verb"|"|scientific|\verb"|"|threshold| % \end{syntax} +% Choice which determines whether numbers are converted to exponent form. The +% option |engineering| forces exponent form with an exponent which is the +% smallest power of three which gives a mantissa with an integer part. The +% option |fixed| uses a fixed exponent (set in |fixed-exponent|). The +% option |input| leaves the input unchanged (which will therefore produce an +% exponent only if the input contained one). The choice |scientific| gives +% an exponent with the mantissa~$m$ in the range $1 \le m < 10$. Finally, +% the option |threshold| will apply |scientific| if the exponent of input +% is outside of the range stored in |exponent-thresholds|. The standard +% setting is |input|. % \end{function} % % \begin{function}{exponent-product} @@ -442,10 +452,20 @@ % \end{syntax} % \end{function} % -% \begin{function}{print-implicit-plus} +% \begin{function} +% { +% print-implicit-plus , +% print-mantissa-implicit-plus , +% print-exponent-implicit-plus +% } % \begin{syntax} -% |print-implicit-plus| = |true|\verb"|"|false| +% |print-implicit-plus| = |true|\verb"|"|false| +% |print-mantissa-implicit-plus| = |true|\verb"|"|false| +% |print-exponent-implicit-plus| = |true|\verb"|"|false| % \end{syntax} +% Controls whether the plus sign implicit in a positive number is printed; +% this can be controlled at the level of the mantissa or exponent, or +% can be activated for both. % \end{function} % % \begin{function}{print-unity-mantissa} @@ -1867,8 +1887,10 @@ drop-zero-decimal .bool_set:N = \l_@@_drop_zero_decimal_bool , exponent-mode .choices:nn = - { engineering , fixed , input , scientific } + { engineering , fixed , input , scientific , threshold } { \tl_set_eq:NN \l_@@_exponent_mode_tl \l_keys_choice_tl } , + exponent-thresholds .code:n = + { \@@_set_thresholds:n {#1} } , fixed-exponent .int_set:N = \l_@@_exponent_fixed_int , minimum-decimal-digits .int_set:N = @@ -1934,6 +1956,40 @@ % \end{macro} % \end{macro} % +% \begin{variable}{\l_@@_lower_threshold_int, \l_@@_upper_threshold_int} +% For storing the range for exponents. +% \begin{macrocode} +\int_new:N \l_@@_lower_threshold_int +\int_new:N \l_@@_upper_threshold_int +% \end{macrocode} +% \end{variable} +% +% \begin{macro}{\@@_set_round_thresholds:n} +% \begin{macro}{\@@_set_round_thresholds:w} +% \begin{macro}{\@@_set_round_threshold:nn} +% Split the range, parse each part, set the data structures. +% \begin{macrocode} +\cs_new_protected:Npx \@@_set_thresholds:n #1 + { + \exp_not:N \@@_set_thresholds:w + #1 \token_to_str:N : \token_to_str:N : \exp_not:N \q_stop + } +\use:x + { + \cs_new_protected:Npn \exp_not:N \@@_set_thresholds:w + ##1 \token_to_str:N : ##2 \token_to_str:N : ##3 \exp_not:N \q_stop + } + { + \@@_set_threshold:nn { lower } {#1} + \@@_set_threshold:nn { upper } {#2} + } +\cs_new_protected:Npn \@@_set_threshold:nn #1#2 + { \int_set:cn { l__@@_ #1 _threshold_int } { 0 #2 } } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% % \begin{macro}{\siunitx_number_process:NN} % \begin{macro}{\@@_process:nnnnnnnNN} % A top-level interface for the processing tools. Rounding happens in all @@ -2010,6 +2066,9 @@ % \begin{macro}[EXP]{\@@_exponent_engineering:nnNw} % \begin{macro}[EXP]{\@@_exponent_engineering_uncert:nn} % \begin{macro}[EXP]{\@@_exponent_engineering_uncert_S:nnn} +% \begin{macro}[EXP]{\@@_exponent_threshold:nnnnnnn} +% \begin{macro}[EXP]{\@@_exponent_threshold:nn} +% \begin{macro}[EXP]{\@@_exponent_threshold:nnnnnnnn} % Manipulating an exponent is done using a single expansion function % \emph{unless} dealing with engineering-style output. The latter is easier % to handle by first converting to scientific output, then post-processing. @@ -2302,6 +2361,32 @@ } } % \end{macrocode} +% To branch here we need to work out the scientific notation form. +% \begin{macrocode} +\cs_new:Npn \@@_exponent_threshold:nnnnnnn #1#2#3#4#5#6#7 + { + \exp_args:Ne \@@_exponent_threshold:nn + { + \@@_exponent_scientific:nnnnnnn + {#1} {#2} {#3} {#4} {#5} {#6} {#7} + } + { {#1} {#2} {#3} {#4} {#5} {#6} {#7} } + } +\cs_new:Npn \@@_exponent_threshold:nn #1#2 + { \@@_exponent_threshold:nnnnnnnn #1 {#2} } +\cs_new:Npn \@@_exponent_threshold:nnnnnnnn #1#2#3#4#5#6#7#8 + { + \bool_lazy_and:nnTF + { \int_compare_p:nNn {#6#7} > \l_@@_lower_threshold_int } + { \int_compare_p:nNn {#6#7} < \l_@@_upper_threshold_int } + { \exp_not:n {#8} } + { \exp_not:n { {#1} {#2} {#3} {#4} {#5} {#6} {#7} } } + } + +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} % \end{macro} % \end{macro} % \end{macro} @@ -3095,7 +3180,8 @@ % \@@_round_uncertainty_engineering:nnn , % \@@_round_uncertainty_fixed:nnn , % \@@_round_uncertainty_input:nnn , -% \@@_round_uncertainty_scientific:nnn +% \@@_round_uncertainty_scientific:nnn , +% \@@_round_uncertainty_threshold:nnn % } % \begin{macro}[EXP] % { @@ -3225,7 +3311,9 @@ % we have a pathological case and need to filter out. They show up as they % have the either the precision greater than the length of the integer % part, or have a value of exactly $10$ when the exponent mode is -% scientific. +% scientific. The latter test has to deal with an exponent threshold too: +% there we are looking for cases where the threshold will have forced +% scientific presentation. % \begin{macrocode} \cs_new:Npn \@@_round_uncertainty_shift:nn #1#2 { \@@_round_uncertainty_shift:nnnw #1 {#2} } @@ -3237,7 +3325,25 @@ { \int_compare_p:nNn {#3} > { \tl_count:n {#1} } } { ! \bool_lazy_and_p:nn - { \str_if_eq_p:Vn \l_@@_exponent_mode_tl { scientific } } + { + \bool_lazy_or_p:nn + { \str_if_eq_p:Vn \l_@@_exponent_mode_tl { scientific } } + { + \bool_lazy_and_p:nn + { \str_if_eq_p:Vn \l_@@_exponent_mode_tl { threshold } } + { + ! \bool_lazy_or_p:nn + { + \int_compare_p:nNn {#5#6} > + \l_@@_lower_threshold_int + } + { + \int_compare_p:nNn {#5#6} < + \l_@@_upper_threshold_int + } + } + } + } { \str_if_eq_p:nn { #1.#2 } { 10. } } } { @@ -3311,6 +3417,18 @@ \@@_exponent_finalise:n { #2#3 + \tl_count:n {#1} - 1 } } % \end{macrocode} +% We need to branch here based on the order of magnitude. +% \begin{macrocode} +\cs_new:Npn \@@_round_uncertainty_threshold:nnn #1#2#3 + { + \bool_lazy_and:nnTF + { \int_compare_p:nNn {#2#3} > \l_@@_lower_threshold_int } + { \int_compare_p:nNn {#2#3} < \l_@@_upper_threshold_int } + { \@@_round_uncertainty_input:nnn } + { \@@_round_uncertainty_scientific:nnn } + {#1} {#2} {#3} + } +% \end{macrocode} % \end{macro} % \end{macro} % \end{macro} @@ -3415,7 +3533,8 @@ % \begin{variable} % { % \l_@@_bracket_negative_bool , -% \l_@@_implicit_plus_bool , +% \l_@@_implicit_plus_mant_bool , +% \l_@@_implicit_plus__exp_bool , % \l_@@_exponent_base_tl , % \l_@@_exponent_product_tl , % \l_@@_group_size_int , @@ -3495,8 +3614,16 @@ \l_@@_output_exp_marker_tl , output-open-uncertainty .tl_set:N = \l_@@_output_uncert_open_tl , - print-implicit-plus .bool_set:N = - \l_@@_implicit_plus_bool , + print-implicit-plus .meta:n = + { + print-mantissa-implicit-plus = {#1} , + print-exponent-implicit-plus = {#1} + } , + print-implicit-plus .default:n = true , + print-mantissa-implicit-plus .bool_set:N = + \l_@@_implicit_plus_mant_bool , + print-exponent-implicit-plus .bool_set:N = + \l_@@_implicit_plus_exp_bool , print-unity-mantissa .bool_set:N = \l_@@_unity_mantissa_bool , print-zero-exponent .bool_set:N = @@ -3703,7 +3830,7 @@ { \tl_if_blank:nTF {#2} { - \bool_if:NT \l_@@_implicit_plus_bool + \bool_if:NT \l_@@_implicit_plus_mant_bool { \@@_output_sign:nN {#1} + } } { @@ -4251,7 +4378,7 @@ \tl_if_blank:nTF {#2} { \bool_lazy_and:nnT - { \l_@@_implicit_plus_bool } + { \l_@@_implicit_plus_exp_bool } { ! \str_if_eq_p:nn {#3} { 0 } } { #1 + } } @@ -4460,7 +4587,9 @@ output-decimal-marker = . , output-open-uncertainty = ( , % ) parse-numbers = true , + print-exponent-implicit-plus = false , print-implicit-plus = false , + print-mantissa-implicit-plus = false , print-unity-mantissa = true , print-zero-exponent = false , print-zero-integer = true , @@ -4484,6 +4613,11 @@ zero-symbol = \mbox { --- } } % \end{macrocode} +% One awkward setting. +% \begin{macrocode} +\keys_set:nx { siunitx } + { exponent-thresholds = -3 \c_colon_str 3 } +% \end{macrocode} % % \begin{macrocode} %</package> |