[latex3-commits] [git/LaTeX3-latex3-latex3] main: Stick to a richer approach to \protect (ec37c6cac)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Apr 8 10:59:15 CEST 2022


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/ec37c6cac3c2b384c684ce822751c40dbcdfcf1f

>---------------------------------------------------------------

commit ec37c6cac3c2b384c684ce822751c40dbcdfcf1f
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Apr 8 09:58:04 2022 +0100

    Stick to a richer approach to \protect
    
    Otherwise of course we don't actually handle robust commands!


>---------------------------------------------------------------

ec37c6cac3c2b384c684ce822751c40dbcdfcf1f
 l3kernel/l3text.dtx | 53 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 47 insertions(+), 6 deletions(-)

diff --git a/l3kernel/l3text.dtx b/l3kernel/l3text.dtx
index f08feb46f..ae01ecc17 100644
--- a/l3kernel/l3text.dtx
+++ b/l3kernel/l3text.dtx
@@ -633,6 +633,10 @@
 % \begin{macro}[EXP]{\@@_expand_letterlike:N}
 % \begin{macro}[EXP]{\@@_expand_letterlike:NN}
 % \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}
@@ -942,17 +946,17 @@
       { \@@_expand_letterlike:NN #1 }
   }
 %    \end{macrocode}
-%   \LaTeXe{}'s \cs{protect} needs to be filtered out specifically.
-%   There is also the case of a straight \tn{@protected at testopt} to
+%   \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.
+%   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 at 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_store:n { \exp_not:N \protect }
-        \exp_not:N \@@_expand_end:w
-      }
+      { \exp_not:N \@@_expand_protect:w }
       {
         \bool_lazy_and:nnTF
           { \cs_if_exist_p:N \fmtname }
@@ -961,6 +965,39 @@
           { \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
+  }
+\cs_new:Npn \@@_expand_protect:nN #1#2
+  { \@@_expand_protect:Nw #2 #1 \q_@@_nil #1 ~ \q_@@_nil \q_@@_nil \s_@@_stop }
+\cs_new:Npn \@@_expand_protect:Nw #1 #2 ~ \q_@@_nil #3 \q_@@_nil #4 \s_@@_stop
+  {
+    \@@_quark_if_nil:nTF {#4}
+      {
+        \cs_if_exist:cTF {#2}
+          { \exp_args:Ne \@@_expand_store:n { \exp_not:c {#2} } }
+          { \@@_expand_store:n { \protect #1 } }
+      }
+      { \@@_expand_store:n { \protect #1 } }
+    \@@_expand_loop:w
+  }
 \cs_new:Npn \@@_expand_testopt:N #1
   {
     \token_if_eq_meaning:NNTF #1 \@protected at testopt
@@ -1099,6 +1136,10 @@
 % \end{macro}
 % \end{macro}
 % \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
 %
 % \begin{macro}
 %   {





More information about the latex3-commits mailing list.