summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3kernel/l3tl.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3tl.dtx')
-rw-r--r--Master/texmf-dist/source/latex/l3kernel/l3tl.dtx134
1 files changed, 70 insertions, 64 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3tl.dtx b/Master/texmf-dist/source/latex/l3kernel/l3tl.dtx
index 1b029fc3611..1424199ecd6 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3tl.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3tl.dtx
@@ -35,7 +35,7 @@
%
%<*driver|package>
\RequirePackage{l3names}
-\GetIdInfo$Id: l3tl.dtx 3034 2011-12-07 11:40:25Z bruno $
+\GetIdInfo$Id: l3tl.dtx 3091 2011-12-25 16:22:59Z bruno $
{L3 Experimental token lists}
%</driver|package>
%<*driver>
@@ -178,7 +178,6 @@
% \tl_put_left:cn, \tl_put_left:cV, \tl_put_left:co, \tl_put_left:cx,
% \tl_gput_left:Nn, \tl_gput_left:NV, \tl_gput_left:No, \tl_gput_left:Nx,
% \tl_gput_left:cn, \tl_gput_left:cV, \tl_gput_left:co, \tl_gput_left:cx
-
% }
% \begin{syntax}
% \cs{tl_put_left:Nn} \meta{tl~var} \Arg{tokens}
@@ -272,7 +271,7 @@
%
% \section{Reassigning token list category codes}
%
-% \begin{function}[updated = 2011-11-20]
+% \begin{function}[updated = 2011-12-18]
% {
% \tl_set_rescan:Nnn, \tl_set_rescan:Nno, \tl_set_rescan:Nnx,
% \tl_set_rescan:cnn, \tl_set_rescan:cno, \tl_set_rescan:cnx,
@@ -290,7 +289,7 @@
% \cs{tl_rescan:nn}.
% \end{function}
%
-% \begin{function}[updated = 2011-08-11]{\tl_rescan:nn}
+% \begin{function}[updated = 2011-12-18]{\tl_rescan:nn}
% \begin{syntax}
% \cs{tl_rescan:nn} \Arg{setup} \Arg{tokens}
% \end{syntax}
@@ -355,13 +354,16 @@
% (\emph{i.e.}~contains no tokens at all).
% \end{function}
%
-% \begin{function}[EXP,pTF]{\tl_if_empty:n, \tl_if_empty:V, \tl_if_empty:o}
+% \begin{function}[EXP,pTF]
+% {\tl_if_empty:n, \tl_if_empty:V, \tl_if_empty:o, \tl_if_empty:x}
% \begin{syntax}
% \cs{tl_if_empty_p:n} \Arg{token list}
% \cs{tl_if_empty:nTF} \Arg{token list} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token list} is entirely empty
% (\emph{i.e.}~contains no tokens at all).
+% All versions of these functions are fully expandable
+% (including those involving an \texttt{x}-type expansion).
% \end{function}
%
% \begin{function}[EXP,pTF]
@@ -666,7 +668,6 @@
% Removes any leading and trailing explicit space characters
% from the content of the \meta{tl~var}.
% \end{function}
-
%
% \section{The first token from a token list}
%
@@ -1003,7 +1004,7 @@
% Creating new token list variables is a case of checking for an
% existing definition and if free doing the definition.
% \begin{macrocode}
-\cs_new_protected_nopar:Npn \tl_new:N #1
+\cs_new_protected:Npn \tl_new:N #1
{
\chk_if_free_cs:N #1
\cs_gset_eq:NN #1 \c_empty_tl
@@ -1043,9 +1044,9 @@
% Clearing a token list variable means setting it to an empty value.
% Error checking will be sorted out by the parent function.
% \begin{macrocode}
-\cs_new_protected_nopar:Npn \tl_clear:N #1
+\cs_new_protected:Npn \tl_clear:N #1
{ \tl_set_eq:NN #1 \c_empty_tl }
-\cs_new_protected_nopar:Npn \tl_gclear:N #1
+\cs_new_protected:Npn \tl_gclear:N #1
{ \tl_gset_eq:NN #1 \c_empty_tl }
\cs_generate_variant:Nn \tl_clear:N { c }
\cs_generate_variant:Nn \tl_gclear:N { c }
@@ -1058,9 +1059,9 @@
% Clearing a token list variable means setting it to an empty value.
% Error checking will be sorted out by the parent function.
% \begin{macrocode}
-\cs_new_protected_nopar:Npn \tl_clear_new:N #1
+\cs_new_protected:Npn \tl_clear_new:N #1
{ \cs_if_exist:NTF #1 { \tl_clear:N #1 } { \tl_new:N #1 } }
-\cs_new_protected_nopar:Npn \tl_gclear_new:N #1
+\cs_new_protected:Npn \tl_gclear_new:N #1
{ \cs_if_exist:NTF #1 { \tl_gclear:N #1 } { \tl_new:N #1 } }
\cs_generate_variant:Nn \tl_clear_new:N { c }
\cs_generate_variant:Nn \tl_gclear_new:N { c }
@@ -1227,13 +1228,6 @@
% \end{macrocode}
% \end{variable}
%
-% \begin{variable}{\l_tl_rescan_tl}
-% A token list variable to actually store the material being processed.
-% \begin{macrocode}
-\tl_new:N \l_tl_rescan_tl
-% \end{macrocode}
-% \end{variable}
-%
% \begin{macro}
% {
% \tl_set_rescan:Nnn, \tl_set_rescan:Nno, \tl_set_rescan:Nnx,
@@ -1244,6 +1238,7 @@
% \tl_gset_rescan:Nnn, \tl_gset_rescan:Nno, \tl_gset_rescan:Nnx,
% \tl_gset_rescan:cnn, \tl_gset_rescan:cno, \tl_gset_rescan:cnx
% }
+% \begin{macro}{\tl_rescan:nn}
% \begin{macro}[aux]{\tl_set_rescan_aux:NNnn}
% \begin{macro}[aux]{\tl_rescan_aux:w}
% The idea here is to deal cleanly with the problem that
@@ -1267,23 +1262,31 @@
{ \tl_set_rescan_aux:NNnn \tl_set:Nn }
\cs_new_protected_nopar:Npn \tl_gset_rescan:Nnn
{ \tl_set_rescan_aux:NNnn \tl_gset:Nn }
+\cs_new_protected_nopar:Npn \tl_rescan:nn
+ { \tl_set_rescan_aux:NNnn \prg_do_nothing: \use:n }
\cs_new_protected:Npn \tl_set_rescan_aux:NNnn #1#2#3#4
{
\group_begin:
- \exp_args:No \etex_everyeof:D { \c_tl_rescan_marker_tl }
+ \exp_args:No \etex_everyeof:D { \c_tl_rescan_marker_tl \exp_not:N }
\tex_endlinechar:D \c_minus_one
\tex_newlinechar:D \c_minus_one
#3
- \tl_clear:N \l_tl_rescan_tl
- \exp_after:wN \tl_rescan_aux:w \etex_scantokens:D {#4}
- \exp_args:NNNo \group_end:
- #1 #2 \l_tl_rescan_tl
+ \use:x
+ {
+ \group_end:
+ #1 \exp_not:N #2
+ {
+ \exp_after:wN \tl_rescan_aux:w
+ \exp_after:wN \prg_do_nothing:
+ \etex_scantokens:D {#4}
+ }
+ }
}
\use:x
{
- \cs_new_protected:Npn \exp_not:N \tl_rescan_aux:w ##1
+ \cs_new:Npn \exp_not:N \tl_rescan_aux:w ##1
\c_tl_rescan_marker_tl
- { \tl_set:Nn \exp_not:N \l_tl_rescan_tl {##1} }
+ { \exp_not:N \exp_not:o { ##1 } }
}
\cs_generate_variant:Nn \tl_set_rescan:Nnn { Nno , Nnx }
\cs_generate_variant:Nn \tl_set_rescan:Nnn { c , cno , cnx }
@@ -1294,22 +1297,6 @@
% \end{macro}
% \end{macro}
% \end{macro}
-%
-% \begin{macro}{\tl_rescan:nn}
-% The same idea is also applied to in line token lists.
-% \begin{macrocode}
-\cs_new_protected:Npn \tl_rescan:nn #1#2
- {
- \group_begin:
- \exp_args:No \etex_everyeof:D { \c_tl_rescan_marker_tl }
- \tex_endlinechar:D \c_minus_one
- \tex_newlinechar:D \c_minus_one
- #1
- \exp_after:wN \tl_rescan_aux:w \etex_scantokens:D {#2}
- \exp_args:No \group_end:
- \l_tl_rescan_tl
- }
-% \end{macrocode}
% \end{macro}
%
% \subsection{Reassigning token list character codes}
@@ -1386,6 +1373,7 @@
{ \tl_to_str:n {#5} }
}
{
+ \group_align_safe_begin:
\cs_set:Npx \tl_tmp:w ##1##2 #4
{
##2
@@ -1394,6 +1382,7 @@
\exp_not:n { \exp_not:n {#5} }
##1
}
+ \group_align_safe_end:
#2 #3
{
\exp_after:wN #1
@@ -1441,9 +1430,9 @@
% \begin{macro}{\tl_gremove_once:Nn, \tl_gremove_once:cn}
% Removal is just a special case of replacement.
% \begin{macrocode}
-\cs_new_protected_nopar:Npn \tl_remove_once:Nn #1#2
+\cs_new_protected:Npn \tl_remove_once:Nn #1#2
{ \tl_replace_once:Nnn #1 {#2} { } }
-\cs_new_protected_nopar:Npn \tl_gremove_once:Nn #1#2
+\cs_new_protected:Npn \tl_gremove_once:Nn #1#2
{ \tl_greplace_once:Nnn #1 {#2} { } }
\cs_generate_variant:Nn \tl_remove_once:Nn { c }
\cs_generate_variant:Nn \tl_gremove_once:Nn { c }
@@ -1455,9 +1444,9 @@
% \begin{macro}{\tl_gremove_all:Nn, \tl_gremove_all:cn}
% Removal is just a special case of replacement.
% \begin{macrocode}
-\cs_new_protected_nopar:Npn \tl_remove_all:Nn #1#2
+\cs_new_protected:Npn \tl_remove_all:Nn #1#2
{ \tl_replace_all:Nnn #1 {#2} { } }
-\cs_new_protected_nopar:Npn \tl_gremove_all:Nn #1#2
+\cs_new_protected:Npn \tl_gremove_all:Nn #1#2
{ \tl_greplace_all:Nnn #1 {#2} { } }
\cs_generate_variant:Nn \tl_remove_all:Nn { c }
\cs_generate_variant:Nn \tl_gremove_all:Nn { c }
@@ -1754,7 +1743,7 @@
% These functions return the replacement text of a token list as a
% string.
% \begin{macrocode}
-\cs_new_nopar:Npn \tl_to_str:N #1 { \etex_detokenize:D \exp_after:wN {#1} }
+\cs_new:Npn \tl_to_str:N #1 { \etex_detokenize:D \exp_after:wN {#1} }
\cs_generate_variant:Nn \tl_to_str:N { c }
% \end{macrocode}
% \end{macro}
@@ -1764,7 +1753,7 @@
% error here. No such luck for ones equal to \cs{scan_stop:} so
% instead a test is made and if there is an issue an error is forced.
% \begin{macrocode}
-\cs_new_nopar:Npn \tl_use:N #1
+\cs_new:Npn \tl_use:N #1
{
\cs_if_exist:NTF #1 {#1}
{ \msg_expandable_kernel_error:nnn { kernel } { bad-var } {#1} }
@@ -1789,7 +1778,7 @@
\int_eval:n
{ 0 \tl_map_function:nN {#1} \tl_length_aux:n }
}
-\cs_new_nopar:Npn \tl_length:N #1
+\cs_new:Npn \tl_length:N #1
{
\int_eval:n
{ 0 \tl_map_function:NN #1 \tl_length_aux:n }
@@ -1935,6 +1924,7 @@
%
% \begin{macro}{\str_head:n, \str_tail:n}
% \begin{macro}[aux]{\str_head_aux:w}
+% \begin{macro}[aux]{\str_tail_aux:w}
% After \cs{tl_to_str:n}, we have a list of character tokens,
% all with category code 12, except the space, which has category
% code 10. Directly using \cs{tl_head:w} would thus lose leading spaces.
@@ -1962,7 +1952,7 @@
\tl_to_str:n {#1}
{ { } } ~ \q_stop
}
-\cs_new_nopar:Npn \str_head_aux:w #1 ~ %
+\cs_new:Npn \str_head_aux:w #1 ~ %
{ \tl_head:w #1 { ~ } }
\cs_new:Npn \str_tail:n #1
{
@@ -1970,10 +1960,11 @@
\reverse_if:N \if_charcode:w
\scan_stop: \tl_to_str:n {#1} X X \q_stop
}
-\cs_new_nopar:Npn \str_tail_aux:w #1 X #2 \q_stop { \fi: #1 }
+\cs_new:Npn \str_tail_aux:w #1 X #2 \q_stop { \fi: #1 }
% \end{macrocode}
% \end{macro}
% \end{macro}
+% \end{macro}
%
% \begin{macro}[pTF]{\tl_if_head_eq_meaning:nN}
% \begin{macro}[pTF]{\tl_if_head_eq_charcode:nN}
@@ -2096,7 +2087,11 @@
% an empty argument, whose head is not \enquote{normal}.
% \begin{macrocode}
\prg_new_conditional:Npnn \tl_if_head_N_type:n #1 { p , T , F , TF }
- { \str_if_eq_return:on { \use:n #1 { } } { #1 { } } }
+ {
+ \str_if_eq_return:xx
+ { \exp_not:o { \use:n #1 { } } }
+ { \exp_not:n { #1 { } } }
+ }
% \end{macrocode}
% \end{macro}
%
@@ -2227,17 +2222,15 @@
%
% \subsection{Experimental functions}
%
-% \begin{macro}[EXP,pTF]{\str_if_eq_return:on}
+% \begin{macro}[EXP]{\str_if_eq_return:xx}
% It turns out that we often need to compare a token list
% with the result of applying some function to it, and
% return with \cs{prg_return_true/false:}. This test is
% similar to \cs{str_if_eq:nnTF}, but hard-coded for speed.
% \begin{macrocode}
-\cs_new:Npn \str_if_eq_return:on #1 #2
+\cs_new:Npn \str_if_eq_return:xx #1 #2
{
- \if_int_compare:w
- \pdftex_strcmp:D { \exp_not:o {#1} } { \exp_not:n {#2} }
- = \c_zero
+ \if_int_compare:w \pdftex_strcmp:D {#1} {#2} = \c_zero
\prg_return_true:
\else:
\prg_return_false:
@@ -2266,7 +2259,7 @@
% trailing spaces.
% \begin{macrocode}
\prg_new_conditional:Npnn \tl_if_single:n #1 { p , T , F , TF }
- { \str_if_eq_return:on { \use_none:nn #1 ?? } {?} }
+ { \str_if_eq_return:xx { \exp_not:o { \use_none:nn #1 ?? } } {?} }
% \end{macrocode}
% \end{macro}
%
@@ -2280,8 +2273,8 @@
\prg_new_conditional:Npnn \tl_if_single_token:n #1 { p , T , F , TF }
{
\tl_if_head_N_type:nTF {#1}
- { \str_if_eq_return:on { \use_none:n #1 } { } }
- { \str_if_eq_return:on { ~ } { #1 } }
+ { \str_if_eq_return:xx { \exp_not:o { \use_none:n #1 } } { } }
+ { \str_if_eq_return:xx { \exp_not:n {#1} } { ~ } }
}
% \end{macrocode}
% \end{macro}
@@ -2311,6 +2304,7 @@
\cs_new:Npn \tl_act:NNNnn { \tex_romannumeral:D \tl_act_aux:NNNnn }
\cs_new:Npn \tl_act_aux:NNNnn #1 #2 #3 #4 #5
{
+ \group_align_safe_begin:
\tl_act_loop:w #5 \q_tl_act_mark \q_tl_act_stop
{#4} #1 #2 #3
\tl_act_result:n { }
@@ -2348,7 +2342,8 @@
\tl_act_loop:w #2 \q_tl_act_stop
{#3} #4
}
-\cs_new:Npn \tl_act_end:wn #1 \tl_act_result:n #2 { \c_zero #2 }
+\cs_new:Npn \tl_act_end:wn #1 \tl_act_result:n #2
+ { \group_align_safe_end: \c_zero #2 }
\cs_new:Npn \tl_act_group:nwnNNN #1 #2 \q_tl_act_stop #3#4#5
{
#5 {#3} {#1}
@@ -2451,9 +2446,9 @@
% This reverses the list, leaving \cs{exp_stop_f:} in front,
% which stops the \texttt{f}-expansion.
% \begin{macrocode}
-\cs_new_protected_nopar:Npn \tl_reverse:N #1
+\cs_new_protected:Npn \tl_reverse:N #1
{ \tl_set:Nf #1 { \tl_reverse:o { #1 \exp_stop_f: } } }
-\cs_new_protected_nopar:Npn \tl_greverse:N #1
+\cs_new_protected:Npn \tl_greverse:N #1
{ \tl_gset:Nf #1 { \tl_reverse:o { #1 \exp_stop_f: } } }
\cs_generate_variant:Nn \tl_reverse:N { c }
\cs_generate_variant:Nn \tl_greverse:N { c }
@@ -2573,7 +2568,7 @@
\q_recursion_tail
\prg_break_point:n { }
}
-\cs_new_nopar:Npn \tl_item_aux:nn #1#2
+\cs_new:Npn \tl_item_aux:nn #1#2
{
\quark_if_recursion_tail_break:n {#2}
\int_compare:nNnTF {#1} = \c_zero
@@ -2586,6 +2581,17 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}[pTF]{\tl_if_empty:x}
+% We can test expandably the emptyness of an expanded token list
+% thanks to the primitive \tn{pdfstrcmp} which expands its argument:
+% a token list is empty if and only if its string representation is
+% empty.
+% \begin{macrocode}
+\prg_new_conditional:Npnn \tl_if_empty:x #1 { p , T , F , TF }
+ { \str_if_eq_return:xx { } {#1} }
+% \end{macrocode}
+% \end{macro}
+%
% \subsection{Deprecated functions}
%
% \begin{macro}{\tl_new:Nn, \tl_new:cn, \tl_new:Nx}
@@ -2610,7 +2616,7 @@
%<*deprecated>
\cs_new_protected_nopar:Npn \tl_gset:Nc
{ \tex_global:D \tl_set:Nc }
-\cs_new_protected_nopar:Npn \tl_set:Nc #1#2
+\cs_new_protected:Npn \tl_set:Nc #1#2
{ \tl_set:No #1 { \cs:w #2 \cs_end: } }
%</deprecated>
% \end{macrocode}