diff options
author | Karl Berry <karl@freefriends.org> | 2013-03-12 22:38:22 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-03-12 22:38:22 +0000 |
commit | 574c4946ce553944c797750da25ba8844775996f (patch) | |
tree | 9ea4729ca09c49a4564d99d9134a5417eb7b2af3 /Master/texmf-dist/source/latex/l3experimental/l3str/l3str-format.dtx | |
parent | 5c30ca128a813719715e012a0d72c1ccaba2d811 (diff) |
latex3 (12mar13)
git-svn-id: svn://tug.org/texlive/trunk@29361 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/l3experimental/l3str/l3str-format.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3experimental/l3str/l3str-format.dtx | 389 |
1 files changed, 207 insertions, 182 deletions
diff --git a/Master/texmf-dist/source/latex/l3experimental/l3str/l3str-format.dtx b/Master/texmf-dist/source/latex/l3experimental/l3str/l3str-format.dtx index ea6c38e6564..7d42697daab 100644 --- a/Master/texmf-dist/source/latex/l3experimental/l3str/l3str-format.dtx +++ b/Master/texmf-dist/source/latex/l3experimental/l3str/l3str-format.dtx @@ -1,6 +1,6 @@ % \iffalse meta-comment % -%% File: l3str-format.dtx Copyright (C) 2012 The LaTeX3 Project +%% File: l3str-format.dtx Copyright (C) 2012-2013 The LaTeX3 Project %% %% It may be distributed and/or modified under the conditions of the %% LaTeX Project Public License (LPPL), either version 1.3c of this @@ -100,7 +100,9 @@ % data should be formatted. The list of allowed \meta{styles} % depends on the type. % \end{itemize} -% The choice of \meta{alignment} |=| is not implemented yet. +% The choice of \meta{alignment} |=| is only valid for numeric types: in +% this case the padding is inserted between the sign and the rest of the +% number. % % \section{Formatting various data-types} % @@ -173,7 +175,7 @@ % \end{macrocode} % % \begin{macrocode} -%<@@=str> +%<@@=str_format> % \end{macrocode} % % \begin{macrocode} @@ -201,11 +203,11 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_if_digit:NTF} +% \begin{macro}[aux, EXP]{\@@_if_digit:NTF} % Here we expect |#1| to be a character with category other, or % \cs{s__stop}. % \begin{macrocode} -\prg_new_conditional:Npnn \@@_format_if_digit:N #1 { TF } +\prg_new_conditional:Npnn \@@_if_digit:N #1 { TF } { \if_int_compare:w \c_nine < 1 #1 \exp_stop_f: \prg_return_true: \else: \prg_return_false: \fi: @@ -214,27 +216,50 @@ % \end{macro} % % \begin{macro}[aux, EXP] -% {\@@_format_put:nw, \@@_format_put:ow, \@@_format_put:fw} +% {\@@_put:nw, \@@_put:ow, \@@_put:fw} % Put |#1| after an \cs{s__stop} delimiter. % \begin{macrocode} -\cs_new:Npn \@@_format_put:nw #1 #2 \s__stop { #2 \s__stop #1 } -\cs_generate_variant:Nn \@@_format_put:nw { o , f } +\cs_new:Npn \@@_put:nw #1 #2 \s__stop { #2 \s__stop #1 } +\cs_generate_variant:Nn \@@_put:nw { o , f } % \end{macrocode} % \end{macro} % +% \begin{macro}[aux, EXP, TF]{\@@_if_in:nN} +% \begin{macro}[aux, EXP]{\@@_if_in_aux:NN} +% A copy of \cs{__str_if_contains_char:nNTF} to avoid relying on +% this weird internal string function. +% \begin{macrocode} +\prg_new_conditional:Npnn \@@_if_in:nN #1#2 { TF } + { + \@@_if_in_aux:NN #2 #1 + { #2 \prg_return_false: \exp_after:wN \__prg_break: \else: } + \__prg_break_point: + } +\cs_new:Npn \@@_if_in_aux:NN #1#2 + { + \if_charcode:w #1 #2 + \prg_return_true: + \exp_after:wN \__prg_break: + \fi: + \@@_if_in_aux:NN #1 + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% % \subsection{Parsing a format specification} % -% \begin{macro}[aux, EXP]{\@@_format_parse:n} +% \begin{macro}[aux, EXP]{\@@_parse:n} % \begin{macro}[aux, EXP] % { -% \@@_format_parse_auxi:NN, -% \@@_format_parse_auxii:nN, -% \@@_format_parse_auxiii:nN, -% \@@_format_parse_auxiv:nwN, -% \@@_format_parse_auxv:nN, -% \@@_format_parse_auxvi:nwN, -% \@@_format_parse_auxvii:nN, -% \@@_format_parse_end:nwn, +% \@@_parse_auxi:NN, +% \@@_parse_auxii:nN, +% \@@_parse_auxiii:nN, +% \@@_parse_auxiv:nwN, +% \@@_parse_auxv:nN, +% \@@_parse_auxvi:nwN, +% \@@_parse_auxvii:nN, +% \@@_parse_end:nwn, % } % The goal is to parse % \begin{equation*} @@ -242,59 +267,59 @@ % [\meta{sign}] [\meta{width}] [.\meta{precision}] [\meta{style}] % \end{equation*} % \begin{macrocode} -\cs_new:Npn \@@_format_parse:n #1 +\cs_new:Npn \@@_parse:n #1 { - \exp_last_unbraced:Nf \@@_format_parse_auxi:NN - \@@_to_other:n {#1} \s__stop \s__stop {#1} + \exp_last_unbraced:Nf \@@_parse_auxi:NN + \__str_to_other:n {#1} \s__stop \s__stop {#1} } -\cs_new:Npx \@@_format_parse_auxi:NN #1#2 +\cs_new:Npx \@@_parse_auxi:NN #1#2 { - \exp_not:N \@@_if_contains_char:nNTF { < > = ^ } #2 - { \exp_not:N \@@_format_parse_auxiii:nN { #1 #2 } } + \exp_not:N \@@_if_in:nNTF { < > = ^ } #2 + { \exp_not:N \@@_parse_auxiii:nN { #1 #2 } } { - \exp_not:N \@@_format_parse_auxii:nN + \exp_not:N \@@_parse_auxii:nN { \c_catcode_other_space_tl } #1 #2 } } -\cs_new:Npn \@@_format_parse_auxii:nN #1#2 +\cs_new:Npn \@@_parse_auxii:nN #1#2 { - \@@_if_contains_char:nNTF { < > = ^ } #2 - { \@@_format_parse_auxiii:nN { #1 #2 } } - { \@@_format_parse_auxiii:nN { #1 ? } #2 } + \@@_if_in:nNTF { < > = ^ } #2 + { \@@_parse_auxiii:nN { #1 #2 } } + { \@@_parse_auxiii:nN { #1 ? } #2 } } -\cs_new:Npx \@@_format_parse_auxiii:nN #1#2 +\cs_new:Npx \@@_parse_auxiii:nN #1#2 { - \exp_not:N \@@_if_contains_char:nNTF + \exp_not:N \@@_if_in:nNTF { + - \c_catcode_other_space_tl } #2 - { \exp_not:N \@@_format_parse_auxiv:nwN { #1 #2 } ; } - { \exp_not:N \@@_format_parse_auxiv:nwN { #1 ? } ; #2 } + { \exp_not:N \@@_parse_auxiv:nwN { #1 #2 } ; } + { \exp_not:N \@@_parse_auxiv:nwN { #1 ? } ; #2 } } -\cs_new:Npn \@@_format_parse_auxiv:nwN #1#2; #3 +\cs_new:Npn \@@_parse_auxiv:nwN #1#2; #3 { - \@@_format_if_digit:NTF #3 - { \@@_format_parse_auxiv:nwN {#1} #2 #3 ; } - { \@@_format_parse_auxv:nN { #1 {#2} } #3 } + \@@_if_digit:NTF #3 + { \@@_parse_auxiv:nwN {#1} #2 #3 ; } + { \@@_parse_auxv:nN { #1 {#2} } #3 } } -\cs_new:Npn \@@_format_parse_auxv:nN #1#2 +\cs_new:Npn \@@_parse_auxv:nN #1#2 { \token_if_eq_charcode:NNTF . #2 - { \@@_format_parse_auxvi:nwN {#1} 0 ; } - { \@@_format_parse_auxvii:nN { #1 { } } #2 } + { \@@_parse_auxvi:nwN {#1} 0 ; } + { \@@_parse_auxvii:nN { #1 { } } #2 } } -\cs_new:Npn \@@_format_parse_auxvi:nwN #1#2; #3 +\cs_new:Npn \@@_parse_auxvi:nwN #1#2; #3 { - \@@_format_if_digit:NTF #3 - { \@@_format_parse_auxvi:nwN {#1} #2 #3 ; } - { \@@_format_parse_auxvii:nN { #1 {#2} } #3 } + \@@_if_digit:NTF #3 + { \@@_parse_auxvi:nwN {#1} #2 #3 ; } + { \@@_parse_auxvii:nN { #1 {#2} } #3 } } -\cs_new:Npn \@@_format_parse_auxvii:nN #1#2 +\cs_new:Npn \@@_parse_auxvii:nN #1#2 { \token_if_eq_meaning:NNTF \s__stop #2 - { \@@_format_parse_end:nwn { #1 ? } #2 } - { \@@_format_parse_end:nwn { #1 #2 } } + { \@@_parse_end:nwn { #1 ? } #2 } + { \@@_parse_end:nwn { #1 #2 } } } -\cs_new:Npn \@@_format_parse_end:nwn #1 #2 \s__stop \s__stop #3 +\cs_new:Npn \@@_parse_end:nwn #1 #2 \s__stop \s__stop #3 { \tl_if_empty:nF {#2} { \__msg_kernel_expandable_error:nnn { str } { invalid-format } {#3} } @@ -316,40 +341,40 @@ % padding between the \meta{sign} and the \meta{body}, hence the need to % keep those separate. % -% \begin{macro}[aux, EXP]{\@@_format_align_<:nnnN} +% \begin{macro}[aux, EXP]{\@@_align_<:nnnN} % \begin{quote} -% \cs{@@_format_align_<:nnnN} \Arg{body} \Arg{sign} \Arg{width} +% \cs{@@_align_<:nnnN} \Arg{body} \Arg{sign} \Arg{width} % \meta{fill} % \end{quote} % Aligning \enquote{\meta{sign} \meta{body}} to the left % entails appending |#4| the correct number of times. Then convert % the result to a string. % \begin{macrocode} -\cs_new:cpn { @@_format_align_<:nnnN } #1#2#3#4 +\cs_new:cpn { @@_align_<:nnnN } #1#2#3#4 { \use:nf { #2 #1 } { \prg_replicate:nn - { \int_max:nn { #3 - \@@_count_unsafe:n { #2 #1 } } { 0 } } + { \int_max:nn { #3 - \__str_count_unsafe:n { #2 #1 } } { 0 } } {#4} } } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_align_>:nnnN} +% \begin{macro}[aux, EXP]{\@@_align_>:nnnN} % \begin{quote} -% \cs{@@_format_align_>:nnnN} \Arg{body} \Arg{sign} \Arg{width} +% \cs{@@_align_>:nnnN} \Arg{body} \Arg{sign} \Arg{width} % \meta{fill} % \end{quote} % Aligning an \enquote{\meta{sign} \meta{body}} to the right % entails prepending |#4| the correct number of times. Then convert % the result to a string. % \begin{macrocode} -\cs_new:cpn { @@_format_align_>:nnnN } #1#2#3#4 +\cs_new:cpn { @@_align_>:nnnN } #1#2#3#4 { \prg_replicate:nn - { \int_max:nn { #3 - \@@_count_unsafe:n { #2 #1 } } { 0 } } + { \int_max:nn { #3 - \__str_count_unsafe:n { #2 #1 } } { 0 } } {#4} #2 #1 } @@ -357,9 +382,9 @@ % \end{macro} % % \begingroup\catcode`\^=12 -% \begin{macro}[aux, EXP]{\@@_format_align_^:nnnN} +% \begin{macro}[aux, EXP]{\@@_align_^:nnnN} % \begin{quote} -% \cs{@@_format_align_^:nnnN} \Arg{body} \Arg{sign} \Arg{width} +% \cs{@@_align_^:nnnN} \Arg{body} \Arg{sign} \Arg{width} % \meta{fill} % \end{quote} % Centering \enquote{\meta{sign} \meta{body}} entails @@ -367,14 +392,14 @@ % number of |#4| to be added is odd, we add one more after than % before. % \begin{macrocode} -\cs_new:cpn { @@_format_align_^:nnnN } #1#2#3#4 +\cs_new:cpn { @@_align_^:nnnN } #1#2#3#4 { \use:fnf { \prg_replicate:nn { \int_max:nn \c_zero - { #3 - \@@_count_unsafe:n { #2 #1 } - \c_one } + { #3 - \__str_count_unsafe:n { #2 #1 } - \c_one } / \c_two } {#4} @@ -384,7 +409,7 @@ \prg_replicate:nn { \int_max:nn \c_zero - { #3 - \@@_count_unsafe:n { #2 #1 } } + { #3 - \__str_count_unsafe:n { #2 #1 } } / \c_two } {#4} @@ -394,21 +419,21 @@ % \end{macro} % \endgroup % -% \begin{macro}[aux, EXP]{\@@_format_align_=:nnnN} +% \begin{macro}[aux, EXP]{\@@_align_=:nnnN} % \begin{quote} -% \cs{@@_format_align_=:nnnN} \Arg{body} \Arg{sign} \Arg{width} +% \cs{@@_align_=:nnnN} \Arg{body} \Arg{sign} \Arg{width} % \meta{fill} % \end{quote} % The special numeric alignment |=| means that we insert the % appropriate number of copies of |#4| between the \meta{sign} and the % \meta{body}. Then convert the result to a string. % \begin{macrocode} -\cs_new:cpn { @@_format_align_=:nnnN } #1#2#3#4 +\cs_new:cpn { @@_align_=:nnnN } #1#2#3#4 { \use:nf {#2} { \prg_replicate:nn - { \int_max:nn { #3 - \@@_count_unsafe:n { #2 #1 } } { 0 } } + { \int_max:nn { #3 - \__str_count_unsafe:n { #2 #1 } } { 0 } } {#4} } #1 @@ -420,7 +445,7 @@ % \subsection{Formatting token lists} % % \begin{macro}[EXP]{\tl_format:Nn, \tl_format:cn, \tl_format:nn} -% Call \cs{@@_format_tl:NNNnnNn} to read the parsed \meta{format +% Call \cs{@@_tl:NNNnnNn} to read the parsed \meta{format % specification}. Then convert the result to a string. % \begin{macrocode} \cs_new_nopar:Npn \tl_format:Nn { \exp_args:No \tl_format:nn } @@ -429,52 +454,52 @@ { \tl_to_str:f { - \exp_last_unbraced:Nf \@@_format_tl:NNNnnNn - { \@@_format_parse:n {#2} } + \exp_last_unbraced:Nf \@@_tl:NNNnnNn + { \@@_parse:n {#2} } {#1} } } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_tl:NNNnnNn} +% \begin{macro}[aux, EXP]{\@@_tl:NNNnnNn} % \begin{quote} -% \cs{@@_format_tl:NNNnnNn} \meta{fill} \meta{alignment} \meta{sign} +% \cs{@@_tl:NNNnnNn} \meta{fill} \meta{alignment} \meta{sign} % \Arg{width} \Arg{precision} \meta{style} \Arg{token list} % \end{quote} % First check that the \meta{alignment} is not |=|, and set the % default alignment |?| to |<|. Place the modified information after % a trailing \cs{s__stop} for later retrieval. Then check that there % was no \meta{sign}. The width will be useful later, store it after -% \cs{s__stop}. Afterwards, check the \meta{precision}: if it is -% empty, we will eventually use the whole string, otherwise we will -% only use a substring, starting at the index $1$, and ending at |#5|. +% \cs{s__stop}. Afterwards, store the precision, and the function +% \cs{__str_range_unsafe:nnn} that will be used to extract the first +% |#5| characters of the string. % There is a need to use the \enquote{unsafe} function, as otherwise % leading spaces would get stripped by |f|-expansion. Finally, check % that the \meta{style} is |?| or |s|. % \begin{macrocode} -\cs_new:Npn \@@_format_tl:NNNnnNn #1#2#3#4#5#6 +\cs_new:Npn \@@_tl:NNNnnNn #1#2#3#4#5#6 { \token_if_eq_charcode:NNTF #2 = { \__msg_kernel_expandable_error:nnnn { str } { invalid-align-format } {#2} {tl} - \@@_format_put:nw { #1 < } + \@@_put:nw { #1 < } } { \token_if_eq_charcode:NNTF #2 ? - { \@@_format_put:nw { #1 < } } - { \@@_format_put:nw { #1 #2 } } + { \@@_put:nw { #1 < } } + { \@@_put:nw { #1 #2 } } } \token_if_eq_charcode:NNF #3 ? { \__msg_kernel_expandable_error:nnnn { str } { invalid-sign-format } {#3} {tl} } - \@@_format_put:nw { {#4} } + \@@_put:nw { {#4} } \tl_if_empty:nTF {#5} - { \@@_format_put:nw { \use:n { } } } - { \@@_format_put:nw { \@@_substr_unsafe:nnn { {1} {#5} } } } + { \@@_put:nw { \__str_range_unsafe:nnn { {1} {-1} } } } + { \@@_put:nw { \__str_range_unsafe:nnn { {1} {#5} } } } \token_if_eq_charcode:NNF #6 s { \token_if_eq_charcode:NNF #6 ? @@ -483,15 +508,15 @@ { str } { invalid-style-format } {#6} {tl} } } - \@@_format_tl_s:NNnnNNn + \@@_tl_s:NNnnNNn \s__stop } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_tl_s:NNnnNNn} +% \begin{macro}[aux, EXP]{\@@_tl_s:NNnnNNn} % \begin{quote} -% \cs{@@_format_tl_s:NNnnNNn} \cs{s__stop} \meta{function} +% \cs{@@_tl_s:NNnnNNn} \cs{s__stop} \meta{function} % \Arg{arguments} \Arg{width} \meta{fill} \meta{alignment} % \Arg{token list} % \end{quote} @@ -499,13 +524,13 @@ % that |f|-expanding \meta{function} \Arg{other string} % \meta{arguments} yields the piece of the \meta{other string} that we % want to output. The \meta{other string} is built from the -% \meta{token list} by |f|-expanding \cs{@@_to_other:n}. +% \meta{token list} by |f|-expanding \cs{__str_to_other:n}. % \begin{macrocode} -\cs_new:Npn \@@_format_tl_s:NNnnNNn #1#2#3#4#5#6#7 +\cs_new:Npn \@@_tl_s:NNnnNNn #1#2#3#4#5#6#7 { \exp_args:Nc \exp_args:Nf - { @@_format_align_#6:nnnN } - { \exp_args:Nf #2 { \@@_to_other:n {#7} } #3 } + { @@_align_#6:nnnN } + { \exp_args:Nf #2 { \__str_to_other:n {#7} } #3 } { } {#4} #5 } @@ -522,29 +547,29 @@ \cs_new:Npn \seq_format:Nn #1#2 { \tl_to_str:f - { \@@_format_seq:of {#1} { \@@_format_parse:n {#2} } } + { \@@_seq:of {#1} { \@@_parse:n {#2} } } } \cs_generate_variant:Nn \seq_format:Nn { c } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_seq:nn, \@@_format_seq:of} +% \begin{macro}[aux, EXP]{\@@_seq:nn, \@@_seq:of} % The first argument is the contents of a \texttt{seq} variable. The % second is a parsed \meta{format specification}. Set up the loop. % \begin{macrocode} -\cs_new:Npn \@@_format_seq:nn #1#2 +\cs_new:Npn \@@_seq:nn #1#2 { - \@@_format_seq_loop:nnNn { } {#2} + \@@_seq_loop:nnNn { } {#2} #1 - { ? \@@_format_seq_end:w } { } + { ? \@@_seq_end:w } { } } -\cs_generate_variant:Nn \@@_format_seq:nn { of } +\cs_generate_variant:Nn \@@_seq:nn { of } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_seq_loop:nnNn} +% \begin{macro}[aux, EXP]{\@@_seq_loop:nnNn} % \begin{quote} -% \cs{@@_format_seq_loop:nnNn} \Arg{done} \Arg{parsed format} +% \cs{@@_seq_loop:nnNn} \Arg{done} \Arg{parsed format} % \cs{__seq_item:n} \Arg{item} % \end{quote} % The first argument is the result of formatting the items read so @@ -552,52 +577,52 @@ % until we reach the end of the sequence, where |\use_none:n #3| ends % the loop. % \begin{macrocode} -\cs_new:Npn \@@_format_seq_loop:nnNn #1#2#3#4 +\cs_new:Npn \@@_seq_loop:nnNn #1#2#3#4 { \use_none:n #3 - \exp_args:Nf \@@_format_seq_loop:nnNn - { \use:nf {#1} { \@@_format_tl:NNNnnNn #2 {#4} } } + \exp_args:Nf \@@_seq_loop:nnNn + { \use:nf {#1} { \@@_tl:NNNnnNn #2 {#4} } } {#2} } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_seq_end:w} +% \begin{macro}[aux, EXP]{\@@_seq_end:w} % Pick the right piece in the loop above. % \begin{macrocode} -\cs_new:Npn \@@_format_seq_end:w #1#2#3#4 { \use_ii:nnn #3 } +\cs_new:Npn \@@_seq_end:w #1#2#3#4 { \use_ii:nnn #3 } % \end{macrocode} % \end{macro} % % \subsection{Formatting integers} % % \begin{macro}[EXP]{\int_format:nn} -% Evalute the first argument and feed it to \cs{@@_format_int:nn}. +% Evalute the first argument and feed it to \cs{@@_int:nn}. % \begin{macrocode} \cs_new:Npn \int_format:nn #1 - { \exp_args:Nf \@@_format_int:nn { \int_eval:n {#1} } } + { \exp_args:Nf \@@_int:nn { \int_eval:n {#1} } } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_int:nn} +% \begin{macro}[aux, EXP]{\@@_int:nn} % Parse the \meta{format specification} and feed it to -% \cs{@@_format_int:NNNnnNn}. Then convert the result to a string +% \cs{@@_int:NNNnnNn}. Then convert the result to a string % \begin{macrocode} -\cs_new:Npn \@@_format_int:nn #1#2 +\cs_new:Npn \@@_int:nn #1#2 { \tl_to_str:f { - \exp_last_unbraced:Nf \@@_format_int:NNNnnNn - { \@@_format_parse:n {#2} } + \exp_last_unbraced:Nf \@@_int:NNNnnNn + { \@@_parse:n {#2} } {#1} } } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_int:NNNnnNn} +% \begin{macro}[aux, EXP]{\@@_int:NNNnnNn} % \begin{quote} -% \cs{@@_format_int:NNNnnNn} \meta{fill} \meta{alignment} +% \cs{@@_int:NNNnnNn} \meta{fill} \meta{alignment} % \meta{sign} \Arg{width} \Arg{precision} \meta{style} \Arg{integer} % \end{quote} % First set the @@ -611,22 +636,22 @@ % the \meta{precision} was absent. Finally, dispatch depending on the % \meta{style}. % \begin{macrocode} -\cs_new:Npn \@@_format_int:NNNnnNn #1#2#3#4#5#6#7 +\cs_new:Npn \@@_int:NNNnnNn #1#2#3#4#5#6#7 { \token_if_eq_charcode:NNTF #2 ? - { \@@_format_put:nw { #1 > } } - { \@@_format_put:nw { #1 #2 } } + { \@@_put:nw { #1 > } } + { \@@_put:nw { #1 #2 } } \int_compare:nNnTF {#7} < \c_zero - { \@@_format_put:nw { - } } + { \@@_put:nw { - } } { \str_case:nnn {#3} { - { ~ } { \@@_format_put:ow { \c_catcode_other_space_tl } } - { + } { \@@_format_put:nw { + } } + { ~ } { \@@_put:ow { \c_catcode_other_space_tl } } + { + } { \@@_put:nw { + } } } - { \@@_format_put:nw { { } } } + { \@@_put:nw { { } } } } - \@@_format_put:nw { {#4} } + \@@_put:nw { {#4} } \tl_if_empty:nF {#5} { \__msg_kernel_expandable_error:nnnn @@ -634,25 +659,25 @@ } \str_case:nnn {#6} { - { ? } { \@@_format_int:NwnnNNn \use:n } - { d } { \@@_format_int:NwnnNNn \use:n } - { b } { \@@_format_int:NwnnNNn \int_to_binary:n } - { o } { \@@_format_int:NwnnNNn \int_to_octal:n } - { X } { \@@_format_int:NwnnNNn \int_to_hexadecimal:n } + { ? } { \@@_int:NwnnNNn \use:n } + { d } { \@@_int:NwnnNNn \use:n } + { b } { \@@_int:NwnnNNn \int_to_binary:n } + { o } { \@@_int:NwnnNNn \int_to_octal:n } + { X } { \@@_int:NwnnNNn \int_to_hexadecimal:n } } { \__msg_kernel_expandable_error:nnnn { str } { invalid-style-format } {#6} { int } - \@@_format_int:NwnnNNn \use:n + \@@_int:NwnnNNn \use:n } \s__stop {#7} } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_int:NwnnNNn} +% \begin{macro}[aux, EXP]{\@@_int:NwnnNNn} % \begin{quote} -% \cs{@@_format_int:NwnnNNn} \meta{function} \cs{s__stop} +% \cs{@@_int:NwnnNNn} \meta{function} \cs{s__stop} % \Arg{width} \Arg{sign} \meta{fill} \meta{alignment} \Arg{integer} % \end{quote} % Use the |format_align| function corresponding to the @@ -665,48 +690,48 @@ % \item the \meta{fill} character. % \end{itemize} % \begin{macrocode} -\cs_new:Npn \@@_format_int:NwnnNNn #1#2 \s__stop #3#4#5#6#7 +\cs_new:Npn \@@_int:NwnnNNn #1#2 \s__stop #3#4#5#6#7 { \exp_args:Nc \exp_args:Nf - { @@_format_align_#6:nnnN } + { @@_align_#6:nnnN } { #1 { \int_abs:n {#7} } } {#4} {#3} #5 } % \end{macrocode} -% ^^A todo: note similarity with \@@_format_tl_s:NNnnNNn +% ^^A todo: note similarity with \@@_tl_s:NNnnNNn % \end{macro} % % \subsection{Formatting floating points} % % \begin{macro}[EXP]{\fp_format:nn} % Evalute the first argument to an internal floating point number, and -% feed it to \cs{@@_format_fp:nn}. +% feed it to \cs{@@_fp:nn}. % \begin{macrocode} \cs_new:Npn \fp_format:nn #1 - { \exp_args:Nf \@@_format_fp:nn { \__fp_parse:n {#1} } } + { \exp_args:Nf \@@_fp:nn { \__fp_parse:n {#1} } } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_fp:nn} +% \begin{macro}[aux, EXP]{\@@_fp:nn} % Parse the \meta{format specification} and feed it to -% \cs{@@_format_fp:NNNnnNn}. Then convert the result to a string +% \cs{@@_fp:NNNnnNn}. Then convert the result to a string % \begin{macrocode} -\cs_new:Npn \@@_format_fp:nn #1#2 +\cs_new:Npn \@@_fp:nn #1#2 { \tl_to_str:f { - \exp_last_unbraced:Nf \@@_format_fp:NNNnnNw - { \@@_format_parse:n {#2} } + \exp_last_unbraced:Nf \@@_fp:NNNnnNw + { \@@_parse:n {#2} } #1 } } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_fp:NNNnnNw} +% \begin{macro}[aux, EXP]{\@@_fp:NNNnnNw} % \begin{quote} -% \cs{@@_format_fp:NNNnnNw} \meta{fill} \meta{alignment} +% \cs{@@_fp:NNNnnNw} \meta{fill} \meta{alignment} % \meta{format sign} \Arg{width} \Arg{precision} \meta{style} % \cs{s__fp} \cs{__fp_chk:w} \meta{fp type} \meta{fp sign} \meta{fp % body} |;| @@ -723,37 +748,37 @@ % (default precision). Finally, dispatch depending on the % \meta{style}. % \begin{macrocode} -\cs_new:Npn \@@_format_fp:NNNnnNw +\cs_new:Npn \@@_fp:NNNnnNw #1#2#3#4#5#6 \s__fp \__fp_chk:w #7 #8 { \token_if_eq_charcode:NNTF #2 ? - { \@@_format_put:nw { #1 > } } - { \@@_format_put:nw { #1 #2 } } + { \@@_put:nw { #1 > } } + { \@@_put:nw { #1 #2 } } \token_if_eq_meaning:NNTF 2 #8 - { \@@_format_put:nw { - } } + { \@@_put:nw { - } } { \str_case:nnn {#3} { - { ~ } { \@@_format_put:ow { \c_catcode_other_space_tl } } - { + } { \@@_format_put:nw { + } } + { ~ } { \@@_put:ow { \c_catcode_other_space_tl } } + { + } { \@@_put:nw { + } } } - { \@@_format_put:nw { { } } } + { \@@_put:nw { { } } } } - \@@_format_put:nw { {#4} } + \@@_put:nw { {#4} } \tl_if_empty:nTF {#5} - { \@@_format_put:nw { { 6} } } - { \@@_format_put:nw { {#5} } } + { \@@_put:nw { { 6} } } + { \@@_put:nw { {#5} } } \str_case:nnn {#6} { - { e } { \@@_format_fp:wnnnNNw \@@_format_fp_e:wn } - { f } { \@@_format_fp:wnnnNNw \@@_format_fp_f:wn } - { g } { \@@_format_fp:wnnnNNw \@@_format_fp_g:wn } - { ? } { \@@_format_fp:wnnnNNw \@@_format_fp_g:wn } + { e } { \@@_fp:wnnnNNw \@@_fp_e:wn } + { f } { \@@_fp:wnnnNNw \@@_fp_f:wn } + { g } { \@@_fp:wnnnNNw \@@_fp_g:wn } + { ? } { \@@_fp:wnnnNNw \@@_fp_g:wn } } { \__msg_kernel_expandable_error:nnnn { str } { invalid-style-format } {#6} { fp } - \@@_format_fp:wnnnNNw \@@_format_fp_g:wn + \@@_fp:wnnnNNw \@@_fp_g:wn } \s__stop \s__fp \__fp_chk:w #7 #8 @@ -761,19 +786,19 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_fp:wnnnNNw} +% \begin{macro}[aux, EXP]{\@@_fp:wnnnNNw} % \begin{quote} -% \cs{@@_format_fp:wnnnNNw} \meta{formatting function} \cs{s__stop} +% \cs{@@_fp:wnnnNNw} \meta{formatting function} \cs{s__stop} % \Arg{precision} \Arg{width} \Arg{sign} \meta{fill} % \meta{alignment} \cs{s__fp} \cs{__fp_chk:w} \meta{fp type} % \meta{fp sign} \meta{fp body} |;| % \end{quote} % \begin{macrocode} -\cs_new:Npn \@@_format_fp:wnnnNNw +\cs_new:Npn \@@_fp:wnnnNNw #1 \s__stop #2 #3 #4 #5#6 #7 ; { \exp_args:Nc \exp_args:Nf - { @@_format_align_#6:nnnN } + { @@_align_#6:nnnN } { #1 #7 ; {#2} } {#4} {#3} #5 @@ -781,17 +806,17 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_fp_round:wn} +% \begin{macro}[aux, EXP]{\@@_fp_round:wn} % Round the given floating point (not its absolute value, to play % nicely with unusual rounding modes). % \begin{macrocode} -\cs_new:Npn \@@_format_fp_round:wn #1 ; #2 +\cs_new:Npn \@@_fp_round:wn #1 ; #2 { \__fp_parse:n { round ( #1; , #2 - \__fp_exponent:w #1; ) } } % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_fp_e:wn} -% \begin{macro}[aux, EXP]{\@@_format_fp_e_aux:wn} +% \begin{macro}[aux, EXP]{\@@_fp_e:wn} +% \begin{macro}[aux, EXP]{\@@_fp_e_aux:wn} % With the |e| type, first filter out special cases. In the normal % case, round to |#4+1| significant figures (one before the decimal % separator, |#4| after). @@ -801,7 +826,7 @@ \tl_to_lowercase:n { \group_end: - \cs_new:Npn \@@_format_fp_e:wn \s__fp \__fp_chk:w #1#2#3 ; #4 + \cs_new:Npn \@@_fp_e:wn \s__fp \__fp_chk:w #1#2#3 ; #4 { \int_case:nnn {#1} { @@ -810,26 +835,26 @@ {3} { nan } } { - \exp_last_unbraced:Nf \@@_format_fp_e_aux:wn - \@@_format_fp_round:wn \s__fp \__fp_chk:w #1#2#3 ; { #4 + 1 } + \exp_last_unbraced:Nf \@@_fp_e_aux:wn + \@@_fp_round:wn \s__fp \__fp_chk:w #1#2#3 ; { #4 + 1 } {#4} } } - \cs_new:Npn \@@_format_fp_e_aux:wn + \cs_new:Npn \@@_fp_e_aux:wn \s__fp \__fp_chk:w #1#2 #3 #4#5#6#7 ; #8 { - \@@_format_put:fw { \int_eval:n { #3 - 1 } } - \@@_format_put:nw { e } + \@@_put:fw { \int_eval:n { #3 - 1 } } + \@@_put:nw { e } \int_compare:nNnTF {#8} > \c_sixteen { - \@@_format_put:fw { \prg_replicate:nn { #8 - \c_fifteen } {0} } - \@@_format_put:fw { \use_none:n #4#5#6#7 } + \@@_put:fw { \prg_replicate:nn { #8 - \c_fifteen } {0} } + \@@_put:fw { \use_none:n #4#5#6#7 } } { - \@@_format_put:fw - { \str_substr:nnn { #4#5#6#7 0 } { 2 } { #8 + 1 } } + \@@_put:fw + { \str_range:nnn { #4#5#6#7 0 } { 2 } { #8 + 1 } } } - \@@_format_put:fw { \use_i:nnnn #4 . } + \@@_put:fw { \use_i:nnnn #4 . } \use_none:n \s__stop } } @@ -837,12 +862,12 @@ % \end{macro} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_fp_f:wn} -% \begin{macro}[aux, EXP]{\@@_format_fp_f_aux:wwwn} +% \begin{macro}[aux, EXP]{\@@_fp_f:wn} +% \begin{macro}[aux, EXP]{\@@_fp_f_aux:wwwn} % With the |f| type, first filter out special cases. In the normal % case, round to |#4| (absolute) decimal places. % \begin{macrocode} -\cs_new:Npn \@@_format_fp_f:wn \s__fp \__fp_chk:w #1#2#3 ; #4 +\cs_new:Npn \@@_fp_f:wn \s__fp \__fp_chk:w #1#2#3 ; #4 { \int_case:nnn {#1} { @@ -851,25 +876,25 @@ {3} { nan } } { - \exp_last_unbraced:Nf \@@_format_fp_f_aux:wwwn + \exp_last_unbraced:Nf \@@_fp_f_aux:wwwn \fp_to_decimal:n { abs ( round ( \s__fp \__fp_chk:w #1#2#3 ; , #4 ) ) } . . ; {#4} } } -\cs_new:Npn \@@_format_fp_f_aux:wwwn #1 . #2 . #3 ; #4 +\cs_new:Npn \@@_fp_f_aux:wwwn #1 . #2 . #3 ; #4 { \use:nf { #1 . #2 } - { \prg_replicate:nn { #4 - \@@_count_unsafe:n {#2} } {0} } + { \prg_replicate:nn { #4 - \__str_count_unsafe:n {#2} } {0} } } % \end{macrocode} % \end{macro} % \end{macro} % -% \begin{macro}[aux, EXP]{\@@_format_fp_g:wn} -% \begin{macro}[aux, EXP]{\@@_format_fp_g_aux:wn} +% \begin{macro}[aux, EXP]{\@@_fp_g:wn} +% \begin{macro}[aux, EXP]{\@@_fp_g_aux:wn} % With the |g| type, first filter out special cases. In the normal % case, round to |#4| significant figures, then test the exponent: if % $-4\leq \meta{exponent} < \meta{precision}$, use the presentation @@ -880,7 +905,7 @@ % \cs{fp_to_decimal:n} and \cs{fp_to_scientific:n}, acting on the % (absolute value of the) rounded value. % \begin{macrocode} -\cs_new:Npn \@@_format_fp_g:wn \s__fp \__fp_chk:w #1#2 ; #3 +\cs_new:Npn \@@_fp_g:wn \s__fp \__fp_chk:w #1#2 ; #3 { \int_case:nnn {#1} { @@ -889,13 +914,13 @@ {3} { nan } } { - \exp_last_unbraced:Nf \@@_format_fp_g_aux:wn - \@@_format_fp_round:wn \s__fp \__fp_chk:w #1#2 ; + \exp_last_unbraced:Nf \@@_fp_g_aux:wn + \@@_fp_round:wn \s__fp \__fp_chk:w #1#2 ; { \int_max:nn {1} {#3} } { \int_max:nn {1} {#3} } } } -\cs_new:Npn \@@_format_fp_g_aux:wn #1; #2 +\cs_new:Npn \@@_fp_g_aux:wn #1; #2 { \int_compare:nNnTF { \__fp_exponent:w #1; } < { -3 } { \fp_to_scientific:n } |