diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3tl.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3tl.dtx | 69 |
1 files changed, 57 insertions, 12 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3tl.dtx b/Master/texmf-dist/source/latex/l3kernel/l3tl.dtx index 1c8867340c2..ec82eca63f0 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3tl.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3tl.dtx @@ -43,7 +43,7 @@ % }^^A % } % -% \date{Released 2019-02-15} +% \date{Released 2019-03-05} % % \maketitle % @@ -700,6 +700,16 @@ % giving an \meta{integer denotation}. % \end{function} % +% \begin{function}[EXP, added = 2019-02-25]{\tl_count_tokens:n} +% \begin{syntax} +% \cs{tl_count_tokens:n} \Arg{tokens} +% \end{syntax} +% Counts the number of \TeX{} tokens in the \meta{tokens} and leaves +% this information in the input stream. Every token, including spaces and +% braces, contributes one to the total; thus for instance, the token count of +% |a~{bc}| is $6$. +% \end{function} +% % \begin{function}[updated = 2012-01-08, EXP] % {\tl_reverse:n, \tl_reverse:V, \tl_reverse:o} % \begin{syntax} @@ -822,7 +832,7 @@ % \begin{texnote} % The result is returned within \cs{exp_not:n}, which means that the % token list does not expand further when appearing in an -% \texttt{x}-type argument expansion. +% \texttt{x}-type or \texttt{e}-type argument expansion. % \end{texnote} % \end{function} % @@ -1149,7 +1159,7 @@ % % \begin{variable}[added = 2017-11-14]{\c_novalue_tl} % A marker for the absence of an argument. This constant |tl| can safely -% be typeset (\emph{cf.}~|\q_nil|), with the result being |-NoValue-|. +% be typeset (\emph{cf.}~\cs{q_nil}), with the result being |-NoValue-|. % It is important to note that \cs{c_novalue_tl} is constructed such that it % will \emph{not} match the simple text input |-NoValue-|, \emph{i.e.} % that @@ -1571,6 +1581,10 @@ % % The two \cs{if_false:} \ldots{} \cs{fi:} are there to prevent % alignment tabs to cause a change of tabular cell while rescanning. +% We put the \enquote{opening} one after \cs{group_begin:} so that if +% one accidentally \texttt{f}-expands \cs{tl_set_rescan:Nnn} braces +% remain balanced. This is essential in \texttt{e}-type arguments +% when \tn{expanded} is not available. % \begin{macrocode} \cs_new_protected:Npn \tl_set_rescan:Nnn { \@@_set_rescan:NNnn \tl_set:No } @@ -1584,8 +1598,8 @@ } \cs_new_protected:Npn \@@_set_rescan:NNnn #1#2#3#4 { - \if_false: { \fi: \group_begin: + \if_false: { \fi: \int_set_eq:NN \tex_tracingnesting:D \c_zero_int \exp_args:No \tex_everyeof:D { \c_@@_rescan_marker_tl } \int_compare:nNnT \tex_endlinechar:D = { 32 } @@ -1804,7 +1818,7 @@ % \meta{pattern}~|#6| then we can use it as the \meta{delimiter} % through \cs{@@_replace_auxii:nNNNnn} |{#1}|. Otherwise, we end up % calling \cs{@@_replace:NnNNNnn} repeatedly with the first two -% arguments |\q_mark| |{?}|, |\?| |{??}|, |\??| |{???}|, and so on, +% arguments \cs{q_mark} |{?}|, |\?| |{??}|, |\??| |{???}|, and so on, % until |#6|~does not contain the control sequence~|#1|, which we take % as our~\meta{A}. The argument~|#2| only serves to collect~|?| % characters for~|#1|. Note that the order of the tests means that @@ -2126,9 +2140,12 @@ % groups makes the test work also for empty arguments. % The \cs{if_false:} constructions are a faster way to do % \cs{group_align_safe_begin:} and \cs{group_align_safe_end:}. +% The \cs{scan_stop:} ensures that \texttt{f}-expanding +% \cs{tl_if_in:nn} does not lead to unbalanced braces. % \begin{macrocode} \prg_new_protected_conditional:Npnn \tl_if_in:nn #1#2 { T , F , TF } { + \scan_stop: \if_false: { \fi: \cs_set:Npn \@@_tmp:w ##1 #2 { } \tl_if_empty:oTF { \@@_tmp:w #1 {} {} #2 } @@ -2427,6 +2444,36 @@ % \end{macro} % \end{macro} % +% +% \begin{macro}[EXP]{\tl_count_tokens:n} +% \begin{macro}[EXP]{\@@_act_count_normal:nN, +% \@@_act_count_group:nn, \@@_act_count_space:n} +% The token count is computed through an \cs{int_eval:n} construction. +% Each \texttt{1+} is output to the \emph{left}, into the integer +% expression, and the sum is ended by the \cs{exp_end:} inserted by +% \cs{@@_act_end:wn} (which is technically implemented as \cs{c_zero_int}). +% Somewhat a hack! +% \begin{macrocode} +\cs_new:Npn \tl_count_tokens:n #1 + { + \int_eval:n + { + \@@_act:NNNnn + \@@_act_count_normal:nN + \@@_act_count_group:nn + \@@_act_count_space:n + { } + {#1} + } + } +\cs_new:Npn \@@_act_count_normal:nN #1 #2 { 1 + } +\cs_new:Npn \@@_act_count_space:n #1 { 1 + } +\cs_new:Npn \@@_act_count_group:nn #1 #2 + { 2 + \tl_count_tokens:n {#2} + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% % \begin{macro}{\tl_reverse_items:n} % \begin{macro}{\@@_reverse_items:nwNwn} % \begin{macro}{\@@_reverse_items:wn} @@ -2945,13 +2992,11 @@ % \end{macro} % % \begin{macro}[EXP,pTF]{\tl_if_head_is_group:n} -% Pass the first token of |#1| through \cs{token_to_str:N}, -% then check for the brace balance. The extra \texttt{?} -% caters for an empty argument.\footnote{Bruno: this could -% be made faster, but we don't: if we hope to ever have -% an e-type argument, we need all brace \enquote{tricks} -% to happen in one step of expansion, keeping the token -% list brace balanced at all times.} +% Pass the first token of |#1| through \cs{token_to_str:N}, then check +% for the brace balance. The extra \texttt{?} caters for an empty +% argument. This could be made faster, but we need all brace tricks +% to happen in one step of expansion, keeping the token list brace +% balanced at all times. % \begin{macrocode} \prg_new_conditional:Npnn \tl_if_head_is_group:n #1 { p , T , F , TF } { |