diff options
Diffstat (limited to 'macros/latex/contrib/l3kernel/l3text.dtx')
-rw-r--r-- | macros/latex/contrib/l3kernel/l3text.dtx | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/macros/latex/contrib/l3kernel/l3text.dtx b/macros/latex/contrib/l3kernel/l3text.dtx index 0d1365c8d2..3cb5795a5d 100644 --- a/macros/latex/contrib/l3kernel/l3text.dtx +++ b/macros/latex/contrib/l3kernel/l3text.dtx @@ -43,7 +43,7 @@ % }^^A % } % -% \date{Released 2022-02-24} +% \date{Released 2022-04-10} % % \maketitle % @@ -562,11 +562,45 @@ % \end{variable} % % \begin{variable}{\l_text_expand_exclude_tl} -% Commands which need not to expand. +% Commands which need not to expand. We start with a somewhat historical +% list, and tidy up if possible. % \begin{macrocode} \tl_new:N \l_text_expand_exclude_tl \tl_set:Nn \l_text_expand_exclude_tl { \begin \cite \end \label \ref } +\bool_lazy_and:nnT + { \str_if_eq_p:Vn \fmtname { LaTeX2e } } + { \tl_if_exist_p:N \@expl@finalise@setup@@@@ } + { + \tl_gput_right:Nn \@expl@finalise@setup@@@@ + { + \tl_gput_right:Nn \@kernel@after@begindocument + { + \group_begin: + \cs_set_protected:Npn \@@_tmp:w #1 + { + \tl_clear:N \l_text_expand_exclude_tl + \tl_map_inline:nn {#1} + { + \bool_lazy_any:nF + { + { \token_if_protected_macro_p:N ##1 } + { \token_if_protected_long_macro_p:N ##1 } + { + \str_if_eq_p:ee + { \cs_replacement_spec:N ##1 } + { \exp_not:n { \protect ##1 } \c_space_tl } + } + } + { \tl_put_right:Nn \l_text_expand_exclude_tl {##1} } + } + } + \exp_args:NV \@@_tmp:w \l_text_expand_exclude_tl + \exp_args:NNNV \group_end: + \tl_set:Nn \l_text_expand_exclude_tl \l_text_expand_exclude_tl + } + } + } % \end{macrocode} % \end{variable} % @@ -632,13 +666,14 @@ % \begin{macro}[EXP]{\@@_expand_accent:NN} % \begin{macro}[EXP]{\@@_expand_letterlike:N} % \begin{macro}[EXP]{\@@_expand_letterlike:NN} -% \begin{macro}[EXP]{\@@_expand_cs:N, \@@_expand_encoding:N} -% \begin{macro}[EXP]{\@@_expand_encoding_escape:N} +% \begin{macro}[EXP]{\@@_expand_cs:N} +% \begin{macro}[EXP]{\@@_expand_protect:w} % \begin{macro}[EXP]{\@@_expand_protect:N} % \begin{macro}[EXP]{\@@_expand_protect:nN} % \begin{macro}[EXP]{\@@_expand_protect:Nw} % \begin{macro}[EXP]{\@@_expand_testopt:N} % \begin{macro}[EXP]{\@@_expand_testopt:NNn} +% \begin{macro}[EXP]{\@@_expand_encoding:N, \@@_expand_encoding_escape:N} % \begin{macro}[EXP]{\@@_expand_replace:N} % \begin{macro}[EXP]{\@@_expand_replace:n} % \begin{macro}[EXP]{\@@_expand_cs_expand:N} @@ -947,14 +982,15 @@ % \end{macrocode} % \LaTeXe{}'s \cs{protect} makes life interesting. Where possible, we % simply remove it and replace with the \enquote{parent} command; of course, -% the \cs{protect} might be explicit, in which case we need to leave it alone -% if it's required. There is also the case of a straight \tn{@protected@testopt} -% to cover. +% the \cs{protect} might be explicit, in which case we need to leave it alone. +% That includes the case where it's not even followed by an \texttt{N}-type +% token. There is also the case of a straight \tn{@protected@testopt} to +% cover. % \begin{macrocode} \cs_new:Npx \@@_expand_cs:N #1 { \exp_not:N \str_if_eq:nnTF {#1} { \exp_not:N \protect } - { \exp_not:N \@@_expand_protect:N } + { \exp_not:N \@@_expand_protect:w } { \bool_lazy_and:nnTF { \cs_if_exist_p:N \fmtname } @@ -963,8 +999,23 @@ { \exp_not:N \@@_expand_replace:N #1 } } } +\cs_new:Npn \@@_expand_protect:w #1 \q_@@_recursion_stop + { + \tl_if_head_is_N_type:nTF {#1} + { \@@_expand_protect:N } + { + \@@_expand_store:n { \protect } + \@@_expand_loop:w + } + #1 \q_@@_recursion_stop + } \cs_new:Npn \@@_expand_protect:N #1 { + \@@_if_recursion_tail_stop_do:Nn #1 + { + \@@_expand_store:n { \protect } + \@@_expand_end:w + } \exp_args:Ne \@@_expand_protect:nN { \cs_to_str:N #1 } #1 } @@ -1122,6 +1173,7 @@ % \end{macro} % \end{macro} % \end{macro} +% \end{macro} % % \begin{macro} % { |