diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx | 574 |
1 files changed, 174 insertions, 400 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx b/Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx index 9b68994b370..526762d2529 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx @@ -1,6 +1,6 @@ % \iffalse meta-comment % -%% File: l3candidates.dtx Copyright (C) 2012-2016 The LaTeX3 Project +%% File: l3candidates.dtx Copyright (C) 2012-2017 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 @@ -24,7 +24,7 @@ \documentclass[full]{l3doc} %</driver> %<*driver|package> -\GetIdInfo$Id: l3candidates.dtx 6835 2017-01-30 21:25:17Z bruno $ +\GetIdInfo$Id: l3candidates.dtx 6967 2017-02-20 14:51:30Z bruno $ {L3 Experimental additions to l3kernel} %</driver|package> %<*driver> @@ -90,26 +90,6 @@ % into the kernel. However, real use sometimes leads to better ideas, so functions from this module are % \textbf{not necessarily stable} and we may have to adjust them! % -% \section{Additions to \pkg{l3basics}} -% -% \begin{function}[added = 2014-08-22, updated = 2015-08-03]{\cs_log:N, \cs_log:c} -% \begin{syntax} -% \cs{cs_log:N} \meta{control sequence} -% \end{syntax} -% Writes the definition of the \meta{control sequence} in the log -% file. See also \cs{cs_show:N} which displays the result in the -% terminal. -% \end{function} -% -% \begin{function}[updated = 2015-08-03] -% {\__kernel_register_log:N, \__kernel_register_log:c} -% \begin{syntax} -% \cs{__kernel_register_log:N} \meta{register} -% \end{syntax} -% Used to write the contents of a \TeX{} register to the log file in a -% form similar to \cs{__kernel_register_show:N}. -% \end{function} -% % \section{Additions to \pkg{l3box}} % % \subsection{Affine transformations} @@ -287,22 +267,6 @@ % % \section{Additions to \pkg{l3clist}} % -% \begin{function}[added = 2014-08-22]{\clist_log:N, \clist_log:c} -% \begin{syntax} -% \cs{clist_log:N} \meta{comma list} -% \end{syntax} -% Writes the entries in the \meta{comma list} in the log file. See -% also \cs{clist_show:N} which displays the result in the terminal. -% \end{function} -% -% \begin{function}[added = 2014-08-22]{\clist_log:n} -% \begin{syntax} -% \cs{clist_log:n} \Arg{tokens} -% \end{syntax} -% Writes the entries in the comma list in the log file. See also -% \cs{clist_show:n} which displays the result in the terminal. -% \end{function} -% % \begin{function}[EXP, added = 2016-12-06] % {\clist_rand_item:N, \clist_rand_item:n, \clist_rand_item:c} % \begin{syntax} @@ -349,18 +313,6 @@ % respectively. The two scale factors should be given as real numbers. % \end{function} % -% \begin{function}[added = 2014-08-22] -% {\coffin_log_structure:N, \coffin_log_structure:c} -% \begin{syntax} -% \cs{coffin_log_structure:N} \meta{coffin} -% \end{syntax} -% This function writes the structural information about the -% \meta{coffin} in the log file. The width, height and depth of the -% typeset material are given, along with the location of all of the -% poles of the coffin. See also \cs{coffin_show_structure:N} which -% displays the result in the terminal. -% \end{function} -% % \section{Additions to \pkg{l3file}} % % \begin{function}[TF, added = 2014-07-02]{\file_if_exist_input:n} @@ -469,35 +421,8 @@ % open stream: intended for tracking down problems. % \end{function} % -% \section{Additions to \pkg{l3fp}} -% -% \begin{function}[added = 2014-08-22, updated = 2015-08-07] -% {\fp_log:N, \fp_log:c, \fp_log:n} -% \begin{syntax} -% \cs{fp_log:N} \meta{fp~var} -% \cs{fp_log:n} \Arg{floating point expression} -% \end{syntax} -% Evaluates the \meta{floating point expression} and writes the -% result in the log file. -% \end{function} -% % \section{Additions to \pkg{l3int}} % -% \begin{function}[added = 2014-08-22, updated = 2015-08-03]{\int_log:N, \int_log:c} -% \begin{syntax} -% \cs{int_log:N} \meta{integer} -% \end{syntax} -% Writes the value of the \meta{integer} in the log file. -% \end{function} -% -% \begin{function}[added = 2014-08-22, updated = 2015-08-07]{\int_log:n} -% \begin{syntax} -% \cs{int_log:n} \Arg{integer expression} -% \end{syntax} -% Writes the result of evaluating the \meta{integer expression} -% in the log file. -% \end{function} -% % \begin{function}[EXP, added = 2016-12-06]{\int_rand:nn} % \begin{syntax} % \cs{int_rand:nn} \Arg{intexpr_1} \Arg{intexpr_2} @@ -507,16 +432,6 @@ % is only available in \pdfTeX{} and \LuaTeX{}. % \end{function} % -% \section{Additions to \pkg{l3keys}} -% -% \begin{function}[added = 2014-08-22]{\keys_log:nn} -% \begin{syntax} -% \cs{keys_log:nn} \Arg{module} \Arg{key} -% \end{syntax} -% Writes in the log file the function which is used to actually -% implement a \meta{key} for a \meta{module}. -% \end{function} -% % \section{Additions to \pkg{l3msg}} % % In very rare cases it may be necessary to produce errors in an @@ -635,21 +550,6 @@ % than two \meta{boolean expressions}. % \end{function} % -% \begin{function}[added = 2014-08-22, updated = 2015-08-03]{\bool_log:N, \bool_log:c} -% \begin{syntax} -% \cs{bool_log:N} \meta{boolean} -% \end{syntax} -% Writes the logical truth of the \meta{boolean} in the log file. -% \end{function} -% -% \begin{function}[added = 2014-08-22, updated = 2015-08-07]{\bool_log:n} -% \begin{syntax} -% \cs{bool_log:n} \Arg{boolean expression} -% \end{syntax} -% Writes the logical truth of the \meta{boolean expression} in the log -% file. -% \end{function} -% % \section{Additions to \pkg{l3prop}} % % \begin{function}[EXP]{\prop_count:N, \prop_count:c} @@ -678,13 +578,6 @@ % arguments. For that specific task, \cs{prop_item:Nn} is faster. % \end{function} % -% \begin{function}[added = 2014-08-12]{\prop_log:N, \prop_log:c} -% \begin{syntax} -% \cs{prop_log:N} \meta{property list} -% \end{syntax} -% Writes the entries in the \meta{property list} in the log file. -% \end{function} -% % \begin{function}[EXP, added = 2016-12-06] % {\prop_rand_key_value:N, \prop_rand_key_value:c} % \begin{syntax} @@ -755,13 +648,6 @@ % \end{texnote} % \end{function} % -% \begin{function}[added = 2014-08-12]{\seq_log:N, \seq_log:c} -% \begin{syntax} -% \cs{seq_log:N} \meta{sequence} -% \end{syntax} -% Writes the entries in the \meta{sequence} in the log file. -% \end{function} -% % \begin{function}[EXP, added = 2016-12-06]{\seq_rand_item:N, \seq_rand_item:c} % \begin{syntax} % \cs{seq_rand_item:N} \meta{seq~var} @@ -793,51 +679,6 @@ % warning message of some sort. % \end{function} % -% \begin{function}[added = 2014-08-22, updated = 2015-08-03]{\dim_log:N, \dim_log:c} -% \begin{syntax} -% \cs{dim_log:N} \meta{dimension} -% \end{syntax} -% Writes the value of the \meta{dimension} in the log file. -% \end{function} -% -% \begin{function}[added = 2014-08-22, updated = 2015-08-07]{\dim_log:n} -% \begin{syntax} -% \cs{dim_log:n} \Arg{dimension expression} -% \end{syntax} -% Writes the result of evaluating the \meta{dimension expression} -% in the log file. -% \end{function} -% -% \begin{function}[added = 2014-08-22, updated = 2015-08-03]{\skip_log:N, \skip_log:c} -% \begin{syntax} -% \cs{skip_log:N} \meta{skip} -% \end{syntax} -% Writes the value of the \meta{skip} in the log file. -% \end{function} -% -% \begin{function}[added = 2014-08-22, updated = 2015-08-07]{\skip_log:n} -% \begin{syntax} -% \cs{skip_log:n} \Arg{skip expression} -% \end{syntax} -% Writes the result of evaluating the \meta{skip expression} -% in the log file. -% \end{function} -% -% \begin{function}[added = 2014-08-22, updated = 2015-08-03]{\muskip_log:N, \muskip_log:c} -% \begin{syntax} -% \cs{muskip_log:N} \meta{muskip} -% \end{syntax} -% Writes the value of the \meta{muskip} in the log file. -% \end{function} -% -% \begin{function}[added = 2014-08-22, updated = 2015-08-07]{\muskip_log:n} -% \begin{syntax} -% \cs{muskip_log:n} \Arg{muskip expression} -% \end{syntax} -% Writes the result of evaluating the \meta{muskip expression} -% in the log file. -% \end{function} -% % \section{Additions to \pkg{l3tl}} % % \begin{function}[EXP,pTF]{\tl_if_single_token:n} @@ -1103,22 +944,6 @@ % argument. % \end{function} % -% \begin{function}[added = 2014-08-22, updated = 2015-08-01]{\tl_log:N, \tl_log:c} -% \begin{syntax} -% \cs{tl_log:N} \meta{tl~var} -% \end{syntax} -% Writes the content of the \meta{tl~var} in the log file. See also -% \cs{tl_show:N} which displays the result in the terminal. -% \end{function} -% -% \begin{function}[added = 2014-08-22]{\tl_log:n} -% \begin{syntax} -% \cs{tl_log:n} \Arg{token list} -% \end{syntax} -% Writes the \meta{token list} in the log file. See also -% \cs{tl_show:n} which displays the result in the terminal. -% \end{function} -% % \begin{function}[EXP, added = 2016-12-06] % {\tl_rand_item:N, \tl_rand_item:c, \tl_rand_item:n} % \begin{syntax} @@ -1136,6 +961,41 @@ % \end{texnote} % \end{function} % +% \begin{function}[EXP, added = 2017-02-17] +% {\tl_range:Nnn, \tl_range:cnn, \tl_range:nnn} +% \begin{syntax} +% \cs{tl_range:Nnn} \meta{tl~var} \Arg{start index} \Arg{end index} +% \cs{tl_range:nnn} \Arg{token list} \Arg{start index} \Arg{end index} +% \end{syntax} +% Leaves in the input stream the items from the \meta{start index} to the +% \meta{end index} inclusive. Positive \meta{indices} are counted +% from the start of the \meta{token list}, $1$~being the first item, and +% negative \meta{indices} are counted from the end of the token list, +% $-1$~being the last item. If either of \meta{start index} or +% \meta{end index} is~$0$, the result is empty. For instance, +% \begin{verbatim} +% \iow_term:x { \tl_range:nnn { abcdef } { 2 } { 5 } } +% \iow_term:x { \tl_range:nnn { abcdef } { -4 } { -1 } } +% \iow_term:x { \tl_range:nnn { abcdef } { -2 } { -1 } } +% \iow_term:x { \tl_range:nnn { abcdef } { 0 } { -1 } } +% \end{verbatim} +% will print \texttt{{b}{c}{d}{e}}, \texttt{{c}{d}{e}{f}}, \texttt{{e}{f}}, and an empty +% line to the terminal. The \meta{start index} must always be smaller than +% or equal to the \meta{end index}: if this is not the case then no output +% is generated. Thus +% \begin{verbatim} +% \iow_term:x { \tl_range:nnn { abcdef } { 5 } { 2 } } +% \iow_term:x { \tl_range:nnn { abcdef } { -1 } { -4 } } +% \end{verbatim} +% both yield empty token lists. +% \begin{texnote} +% The result is returned within the \tn{unexpanded} +% primitive (\cs{exp_not:n}), which means that the \meta{item} +% will not expand further when appearing in an \texttt{x}-type +% argument expansion. +% \end{texnote} +% \end{function} +% % \section{Additions to \pkg{l3tokens}} % % \begin{function}[TF, updated = 2012-12-20]{\peek_N_type:} @@ -1168,35 +1028,6 @@ %<*initex|package> % \end{macrocode} % -% \subsection{Additions to \pkg{l3basics}} -% -% \begin{macrocode} -%<@@=cs> -% \end{macrocode} -% -% \begin{macro}{\cs_log:N, \cs_log:c} -% Use \cs{cs_show:N} or \cs{cs_show:c} after calling -% \cs{__msg_log_next:} to redirect their output to the log file only. -% Note that \cs{cs_log:c} is not just a variant of \cs{cs_log:N} as -% the csname should be turned to a control sequence within a group -% (see \cs{cs_show:c}). -% \begin{macrocode} -\cs_new_protected:Npn \cs_log:N - { \__msg_log_next: \cs_show:N } -\cs_new_protected:Npn \cs_log:c - { \__msg_log_next: \cs_show:c } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}[int]{\__kernel_register_log:N, \__kernel_register_log:c} -% Redirect the output of \cs{__kernel_register_show:N} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \__kernel_register_log:N - { \__msg_log_next: \__kernel_register_show:N } -\cs_generate_variant:Nn \__kernel_register_log:N { c } -% \end{macrocode} -% \end{macro} -% % \subsection{Additions to \pkg{l3box}} % % \begin{macrocode} @@ -1849,17 +1680,6 @@ %<@@=clist> % \end{macrocode} % -% \begin{macro}{\clist_log:N, \clist_log:c, \clist_log:n} -% Redirect output of \cs{clist_show:N} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \clist_log:N - { \__msg_log_next: \clist_show:N } -\cs_new_protected:Npn \clist_log:n - { \__msg_log_next: \clist_show:n } -\cs_generate_variant:Nn \clist_log:N { c } -% \end{macrocode} -% \end{macro} -% % \begin{macro}{\clist_rand_item:n, \clist_rand_item:N, \clist_rand_item:c} % \begin{macro}[aux]{\@@_rand_item:nn} % The |N|-type function is not implemented through the |n|-type @@ -1874,7 +1694,7 @@ { \exp_args:Nf \@@_rand_item:nn { \clist_count:n {#1} } {#1} } \cs_new:Npn \@@_rand_item:nn #1#2 { - \int_compare:nNnF {#1} = \c_zero + \int_compare:nNnF {#1} = 0 { \clist_item:nn {#2} { \int_rand:nn { 1 } {#1} } } } \cs_new:Npn \clist_rand_item:N #1 @@ -2347,17 +2167,6 @@ % \end{macro} % \end{macro} % -% \subsection{Coffin diagnostics} -% -% \begin{macro}{\coffin_log_structure:N, \coffin_log_structure:c} -% Redirect output of \cs{coffin_show_structure:N} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \coffin_log_structure:N - { \__msg_log_next: \coffin_show_structure:N } -\cs_generate_variant:Nn \coffin_log_structure:N { c } -% \end{macrocode} -% \end{macro} -% % \subsection{Additions to \pkg{l3file}} % % \begin{macrocode} @@ -2477,49 +2286,12 @@ % \end{macrocode} % \end{macro} % -% \subsection{Additions to \pkg{l3fp-assign}} -% -% \begin{macrocode} -%<@@=fp> -% \end{macrocode} -% -% \begin{macro}{\fp_log:N, \fp_log:c, \fp_log:n} -% Redirect output of \cs{fp_show:N} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \fp_log:N - { \__msg_log_next: \fp_show:N } -\cs_new_protected:Npn \fp_log:n - { \__msg_log_next: \fp_show:n } -\cs_generate_variant:Nn \fp_log:N { c } -% \end{macrocode} -% \end{macro} -% % \subsection{Additions to \pkg{l3int}} % % \begin{macrocode} %<@@=int> % \end{macrocode} % -% \begin{macro}{\int_log:N, \int_log:c} -% Redirect output of \cs{int_show:N} to the log. This is not just a -% copy of \cs{__kernel_register_log:N} because of subtleties -% involving \tn{currentgrouplevel} and \tn{currentgrouptype}. See -% \cs{int_show:N} for details. -% \begin{macrocode} -\cs_new_protected:Npn \int_log:N - { \__msg_log_next: \int_show:N } -\cs_generate_variant:Nn \int_log:N { c } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\int_log:n} -% Redirect output of \cs{int_show:n} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \int_log:n - { \__msg_log_next: \int_show:n } -% \end{macrocode} -% \end{macro} -% % \begin{macro}[EXP]{\int_rand:nn} % \begin{macro}[aux, EXP] % { @@ -2556,12 +2328,12 @@ \@@_rand:ww #2; #1; } { - \int_compare:nNnTF {#1} > \c_zero + \int_compare:nNnTF {#1} > 0 { \int_compare:nNnTF { #2 - #1 } < \c__fp_rand_size_int } { \int_compare:nNnTF {#2} < { #1 + \c__fp_rand_size_int } } { \exp_args:Nf \@@_rand_narrow:nn - { \int_eval:n { #2 - #1 + \c_one } } {#1} + { \int_eval:n { #2 - #1 + 1 } } {#1} } { \fp_to_int:n { randint(#1,#2) } } } @@ -2603,20 +2375,6 @@ } % \end{macrocode} % -% \subsection{Additions to \pkg{l3keys}} -% -% \begin{macrocode} -%<@@=keys> -% \end{macrocode} -% -% \begin{macro}{\keys_log:nn} -% Redirect output of \cs{keys_show:nn} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \keys_log:nn - { \__msg_log_next: \keys_show:nn } -% \end{macrocode} -% \end{macro} -% % \subsection{Additions to \pkg{l3msg}} % % \begin{macrocode} @@ -2737,17 +2495,6 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}{\bool_log:N, \bool_log:c, \bool_log:n} -% Redirect output of \cs{bool_show:N} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \bool_log:N - { \__msg_log_next: \bool_show:N } -\cs_new_protected:Npn \bool_log:n - { \__msg_log_next: \bool_show:n } -\cs_generate_variant:Nn \bool_log:N { c } -% \end{macrocode} -% \end{macro} -% % \subsection{Additions to \pkg{l3prop}} % % \begin{macrocode} @@ -2765,11 +2512,11 @@ { \int_eval:n { - \c_zero + 0 \prop_map_function:NN #1 \@@_count:nn } } -\cs_new:Npn \@@_count:nn #1#2 { + \c_one } +\cs_new:Npn \@@_count:nn #1#2 { + 1 } \cs_generate_variant:Nn \prop_count:N { c } % \end{macrocode} % \end{macro} @@ -2804,15 +2551,6 @@ % \end{macro} % \end{macro} % -% \begin{macro}{\prop_log:N, \prop_log:c} -% Redirect output of \cs{prop_show:N} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \prop_log:N - { \__msg_log_next: \prop_show:N } -\cs_generate_variant:Nn \prop_log:N { c } -% \end{macrocode} -% \end{macro} -% % \begin{macro}[EXP] % {\prop_rand_key_value:N, \prop_rand_key_value:c} % \begin{macro}[aux, EXP]{\@@_rand:NN, \@@_rand_item:Nw} @@ -2836,10 +2574,10 @@ } \cs_new:Npn \@@_rand_item:Nw #1#2 \s_@@ \@@_pair:wn #3 \s_@@ #4 { - \int_compare:nNnF {#2} > \c_one + \int_compare:nNnF {#2} > 1 { \use_i_delimit_by_q_stop:nw { #1 {#3} \exp_not:n {#4} } } \exp_after:wN \@@_rand_item:Nw \exp_after:wN #1 - \__int_value:w \int_eval:n { #2 - \c_one } \s_@@ + \__int_value:w \int_eval:n { #2 - 1 } \s_@@ } \cs_generate_variant:Nn \prop_rand_key_value:N { c } % \end{macrocode} @@ -2944,15 +2682,6 @@ % \end{macro} % \end{macro} % -% \begin{macro}{\seq_log:N, \seq_log:c} -% Redirect output of \cs{seq_show:N} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \seq_log:N - { \__msg_log_next: \seq_show:N } -\cs_generate_variant:Nn \seq_log:N { c } -% \end{macrocode} -% \end{macro} -% % \begin{macro}{\seq_rand_item:N, \seq_rand_item:c} % Importantly, \cs{seq_item:Nn} only evaluates its argument once. % \begin{macrocode} @@ -2995,36 +2724,6 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}{\dim_log:N, \dim_log:c, \dim_log:n} -% Diagnostics. Redirect output of \cs{dim_show:n} to the log. -% \begin{macrocode} -\cs_new_eq:NN \dim_log:N \__kernel_register_log:N -\cs_new_eq:NN \dim_log:c \__kernel_register_log:c -\cs_new_protected:Npn \dim_log:n - { \__msg_log_next: \dim_show:n } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\skip_log:N, \skip_log:c, \skip_log:n} -% Diagnostics. Redirect output of \cs{skip_show:n} to the log. -% \begin{macrocode} -\cs_new_eq:NN \skip_log:N \__kernel_register_log:N -\cs_new_eq:NN \skip_log:c \__kernel_register_log:c -\cs_new_protected:Npn \skip_log:n - { \__msg_log_next: \skip_show:n } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\muskip_log:N, \muskip_log:c, \muskip_log:n} -% Diagnostics. Redirect output of \cs{muskip_show:n} to the log. -% \begin{macrocode} -\cs_new_eq:NN \muskip_log:N \__kernel_register_log:N -\cs_new_eq:NN \muskip_log:c \__kernel_register_log:c -\cs_new_protected:Npn \muskip_log:n - { \__msg_log_next: \muskip_show:n } -% \end{macrocode} -% \end{macro} -% % \subsection{Additions to \pkg{l3tl}} % % \begin{macrocode} @@ -3640,11 +3339,11 @@ { \token_if_expandable:NTF #1 { - \bool_if:nTF + \bool_lazy_any:nTF { - \token_if_protected_macro_p:N #1 - || \token_if_protected_long_macro_p:N #1 - || \token_if_eq_meaning_p:NN \q_recursion_tail #1 + { \token_if_eq_meaning_p:NN \q_recursion_tail #1 } + { \token_if_protected_macro_p:N #1 } + { \token_if_protected_long_macro_p:N #1 } } { \use_ii:nn } { \use_i:nn } @@ -3786,11 +3485,9 @@ #2 \q_recursion_stop } { - \bool_if:nTF - { - \token_if_cs_p:N #1 - || ! ( \int_compare_p:nNn { `#1 } = { "0307 } ) - } + \bool_lazy_or:nnTF + { \token_if_cs_p:N #1 } + { ! \int_compare_p:nNn { `#1 } = { "0307 } } { \@@_change_case_output:Vwn \c__unicode_dotless_i_tl } { \@@_change_case_output:nwn { i } @@ -3923,15 +3620,15 @@ #3 \q_recursion_stop } { - \bool_if:nT + \bool_lazy_and:nnT + { ! \token_if_cs_p:N #2 } { - ! \token_if_cs_p:N #2 - && - ( - \int_compare_p:nNn { `#2 } = { "0300 } - || \int_compare_p:nNn { `#2 } = { "0301 } - || \int_compare_p:nNn { `#2 } = { "0303 } - ) + \bool_lazy_any_p:n + { + { \int_compare_p:nNn { `#2 } = { "0300 } } + { \int_compare_p:nNn { `#2 } = { "0301 } } + { \int_compare_p:nNn { `#2 } = { "0303 } } + } } { \@@_change_case_output:Vwn \c__unicode_dot_above_tl } #1 #2#3 \q_recursion_stop @@ -3978,11 +3675,9 @@ #3 \q_recursion_stop } { - \bool_if:nTF - { - ! \token_if_cs_p:N #2 - && \int_compare_p:nNn { `#2 } = { "0307 } - } + \bool_lazy_and:nnTF + { ! \token_if_cs_p:N #2 } + { \int_compare_p:nNn { `#2 } = { "0307 } } { #1 } { #1 #2 } #3 \q_recursion_stop @@ -4559,11 +4254,9 @@ % \begin{macrocode} \cs_new:Npn \@@_change_case_mixed_nl:Nnw #1 { - \bool_if:nTF - { - \int_compare_p:nNn { `#1 } = { `i } - || \int_compare_p:nNn { `#1 } = { `I } - } + \bool_lazy_or:nnTF + { \int_compare_p:nNn { `#1 } = { `i } } + { \int_compare_p:nNn { `#1 } = { `I } } { \@@_change_case_output:nwn { I } \@@_change_case_mixed_nl:Nw @@ -4583,14 +4276,12 @@ #3 \q_recursion_stop } { - \bool_if:nTF + \bool_lazy_and:nnTF + { ! ( \token_if_cs_p:N #2 ) } { - ! ( \token_if_cs_p:N #2 ) - && - ( - \int_compare_p:nNn { `#2 } = { `j } - || \int_compare_p:nNn { `#2 } = { `J } - ) + \bool_lazy_or_p:nn + { \int_compare_p:nNn { `#2 } = { `j } } + { \int_compare_p:nNn { `#2 } = { `J } } } { \@@_change_case_output:nwn { J } @@ -4644,23 +4335,7 @@ % \end{macrocode} % \end{variable} % -% -% \begin{macro}{\tl_log:N, \tl_log:c} -% Redirect output of \cs{tl_show:N} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \tl_log:N - { \__msg_log_next: \tl_show:N } -\cs_generate_variant:Nn \tl_log:N { c } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\tl_log:n} -% Redirect output of \cs{tl_show:n} to the log. -% \begin{macrocode} -\cs_new_protected:Npn \tl_log:n - { \__msg_log_next: \tl_show:n } -% \end{macrocode} -% \end{macro} +% \subsubsection{Other additions to \pkg{l3tl}} % % \begin{macro}{\tl_rand_item:n, \tl_rand_item:N, \tl_rand_item:c} % Importantly \cs{tl_item:nn} only evaluates its argument once. @@ -4675,6 +4350,105 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\tl_range:Nnn, \tl_range:cnn, \tl_range:nnn} +% \begin{macro}[aux] +% {\@@_range:nnnw, \@@_range:nnw, \@@_range_normalize:nn, \@@_range_collect:w, \@@_range_skip:w} +% To avoid checking for the end of the token list at every step, start +% by counting the number $l$ of items and \enquote{normalizing} the +% bounds, namely clamping them to the interval $[0,l]$ and dealing +% with negative indices. More precisely, \cs{@@_range:nnw} receives +% the number of items to skip at the beginning of the token list, and +% the index of the last item to keep. If nothing should be kept, +% leave |{}|: this stops the \texttt{f}-expansion of \cs{tl_head:f} +% and that function produces an empty result. Otherwise, repeatedly +% call \cs{@@_range_skip:w} to delete |#1| items from the input stream +% (the extra brace group avoids an off-by-one mistake), then +% repeatedly call \cs{@@_range_collect:w} to store in its second +% argument the items to be kept. Eventually, the result is a brace +% group followed by the rest of the token list, and \cs{tl_head:f} +% cleans up and gives the result in \cs{exp_not:n}. +% \begin{macrocode} +\cs_new:Npn \tl_range:Nnn { \exp_args:No \tl_range:nnn } +\cs_generate_variant:Nn \tl_range:Nnn { c } +\cs_new:Npn \tl_range:nnn #1#2#3 + { + \tl_head:f + { + \exp_args:Nf \@@_range:nnnw { \tl_count:n {#1} } {#2} {#3} + #1 + } + } +\cs_new:Npn \@@_range:nnnw #1#2#3 + { + \exp_args:Nff \@@_range:nnw + { + \exp_args:Nf \@@_range_normalize:nn + { \int_eval:n { #2 - 1 } } {#1} + } + { + \exp_args:Nf \@@_range_normalize:nn + { \int_eval:n {#3} } {#1} + } + } +\cs_new:Npn \@@_range:nnw #1#2 + { + \if_int_compare:w #2 > #1 \exp_stop_f: \else: + \exp_after:wN { \exp_after:wN } + \fi: + \exp_after:wN \@@_range_collect:w + \__int_value:w \__int_eval:w #2 - #1 \exp_after:wN ; + \exp_after:wN { \exp_after:wN } + \exp:w \@@_range_skip:w #1 ; { } + } +\cs_new:Npn \@@_range_skip:w #1 ; #2 + { + \if_int_compare:w #1 > 0 \exp_stop_f: + \exp_after:wN \@@_range_skip:w + \__int_value:w \__int_eval:w #1 - 1 \exp_after:wN ; + \else: + \exp_after:wN \exp_end: + \fi: + } +\cs_new:Npn \@@_range_collect:w #1 ; #2#3 + { + \if_int_compare:w #1 > 1 \exp_stop_f: + \exp_after:wN \@@_range_collect:w + \__int_value:w \__int_eval:w #1 - 1 \exp_after:wN ; + \fi: + { #2 {#3} } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \begin{macro}[EXP, aux]{\@@_range_normalize:nn} +% This function converts an \meta{index} argument into an explicit +% position in the token list (a result of $0$ denoting \enquote{out of +% bounds}). Expects two explicit integer arguments: the \meta{index} +% |#1| and the string count~|#2|. If |#1| is negative, replace it by +% $|#1| + |#2| + 1$, then limit to the range $[0, |#2|]$. +% \begin{macrocode} +\cs_new:Npn \@@_range_normalize:nn #1#2 + { + \int_eval:n + { + \if_int_compare:w #1 < 0 \exp_stop_f: + \if_int_compare:w #1 < -#2 \exp_stop_f: + 0 + \else: + #1 + #2 + 1 + \fi: + \else: + \if_int_compare:w #1 < #2 \exp_stop_f: + #1 + \else: + #2 + \fi: + \fi: + } + } +% \end{macrocode} +% \end{macro} +% % \subsection{Additions to \pkg{l3tokens}} % % \begin{macrocode} @@ -4713,10 +4487,10 @@ \cs_new_protected:Npn \@@_execute_branches_N_type: { \if_int_odd:w - \if_catcode:w \exp_not:N \l_peek_token { \c_two \fi: - \if_catcode:w \exp_not:N \l_peek_token } \c_two \fi: - \if_meaning:w \l_peek_token \c_space_token \c_two \fi: - \c_one + \if_catcode:w \exp_not:N \l_peek_token { 0 \exp_stop_f: \fi: + \if_catcode:w \exp_not:N \l_peek_token } 0 \exp_stop_f: \fi: + \if_meaning:w \l_peek_token \c_space_token 0 \exp_stop_f: \fi: + 1 \exp_stop_f: \exp_after:wN \@@_N_type:w \token_to_meaning:N \l_peek_token \q_mark \@@_N_type_aux:nnw |