[latex3-commits] [git/LaTeX3-latex3-latex2e] keyval-detect: Ensure braces are preserved after an N-type arg (0496538a)

Joseph Wright joseph.wright at morningstar2.co.uk
Thu Sep 1 21:55:25 CEST 2022


Repository : https://github.com/latex3/latex2e
On branch  : keyval-detect
Link       : https://github.com/latex3/latex2e/commit/0496538ada012ef4de5837fb69d512f4c41c4a81

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

commit 0496538ada012ef4de5837fb69d512f4c41c4a81
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Thu Sep 1 21:55:25 2022 +0200

    Ensure braces are preserved after an N-type arg
    
    Thanks to Jonathan Spratte (skillmon) for the approach.


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

0496538ada012ef4de5837fb69d512f4c41c4a81
 base/ltcmd.dtx                    | 51 ++++++++++++++++++++++++---------------
 base/testfiles-ltcmd/ltcmd008.lvt |  1 +
 base/testfiles-ltcmd/ltcmd008.tlg |  1 +
 3 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/base/ltcmd.dtx b/base/ltcmd.dtx
index 133f075d..14d6756f 100644
--- a/base/ltcmd.dtx
+++ b/base/ltcmd.dtx
@@ -3984,9 +3984,9 @@
 % \changes{v1.1a}{2022/08/10}{New internal arg-to-keyval processor}
 % \begin{macro}{\@@_arg_to_keyvalue_braces:nnn}
 % \begin{macro}{\@@_arg_to_keyvalue_auxi:nnn}
-% \begin{macro}{\@@_arg_to_keyvalue_auxii:nnNw}
+% \begin{macro}{\@@_arg_to_keyvalue_auxii:Nnnn}
 % \begin{macro}{\@@_arg_to_keyvalue_auxiii:nnn}
-% \begin{macro}{\@@_arg_to_keyvalue_auxiv:nnNw}
+% \begin{macro}{\@@_arg_to_keyvalue_auxiv:Nnnn}
 % \begin{macro}{\@@_arg_to_keyvalue_auxv:nn}
 % \begin{macro}{\@@_arg_to_keyvalue_loop:w}
 % \begin{macro}{\@@_arg_to_keyvalue_loop_group:n}
@@ -3998,6 +3998,8 @@
 % \begin{macro}{\@@_arg_to_keyvalue_math_space:w}
 % \begin{macro}{\@@_arg_to_keyvalue_set_default:nn}
 % \begin{macro}{\@@_arg_to_keyvalue_set_keyvalue:nn}
+% \begin{macro}[EXP]{\@@_split_N_head_apply:Nn}
+% \begin{macro}[EXP]{\@@_split_N_head_apply_aux:NNw}
 %   If the entire argument is braced, we treat as free text and return as
 %   the value for the text key. Alternatively, if the start of the input is
 %   |=,| then it is forced to be key--value. To avoid needing to worry about
@@ -4021,32 +4023,29 @@
       }
     \@@_arg_to_keyvalue_auxi:nnn {#1} {#2} {#3}
   }
-\cs_new_protected:Npn \@@_arg_to_keyvalue_auxi:nnn #1#2#3
+\cs_new:Npn \@@_arg_to_keyvalue_auxi:nnn #1
   {
     \tl_if_head_is_N_type:nTF {#1}
-      { \@@_arg_to_keyvalue_auxii:nnNw {#2} {#3} #1 \q_@@_stop }
-      { \@@_arg_to_keyvalue_auxv:nn {#2} {#3} }
+      { \@@_split_N_head_apply:Nn \@@_arg_to_keyvalue_auxii:Nnnn {#1} }
+      { \@@_arg_to_keyvalue_auxv:nn }
   }
-\cs_new_protected:Npn \@@_arg_to_keyvalue_auxii:nnNw #1#2#3#4 \q_@@_stop
+\cs_new:Npn \@@_arg_to_keyvalue_auxii:Nnnn #1#2
   {
-    \str_if_eq:nnTF {#3} { = }
-      {
-        \tl_trim_spaces_apply:nN {#4} \@@_arg_to_keyvalue_auxiii:nnn
-          {#1} {#2}
-      }
-      { \@@_arg_to_keyvalue_auxv:nn {#1} {#2} }
+    \str_if_eq:eeTF { \exp_not:n {#1} } { = }
+      { \tl_trim_spaces_apply:nN {#2} \@@_arg_to_keyvalue_auxiii:nnn }
+      { \@@_arg_to_keyvalue_auxv:nn }
   }
-\cs_new_protected:Npn \@@_arg_to_keyvalue_auxiii:nnn #1#2#3
+\cs_new:Npn \@@_arg_to_keyvalue_auxiii:nnn #1
   {
     \tl_if_head_is_N_type:nTF {#1}
-      { \@@_arg_to_keyvalue_auxiv:nnNw {#2} {#3} #1 \q_@@_stop }
-      { \@@_arg_to_keyvalue_auxv:nn {#2} {#3} }
+      { \@@_split_N_head_apply:Nn \@@_arg_to_keyvalue_auxiv:Nnnn {#1} }
+      { \@@_arg_to_keyvalue_auxv:nn }
   }
-\cs_new_protected:Npn \@@_arg_to_keyvalue_auxiv:nnNw #1#2#3#4 \q_@@_stop
+\cs_new:Npn \@@_arg_to_keyvalue_auxiv:Nnnn #1#2
   {
-    \str_if_eq:nnTF {#3} { , }
-      { \tl_set:Nn \ProcessedArgument {#4} }
-      { \@@_arg_to_keyvalue_auxv:nn {#1} {#2} }
+    \str_if_eq:eeTF { \exp_not:n {#1} } { , }
+      { \tl_set:Nn \ProcessedArgument {#2} \use_none:nn }
+      { \@@_arg_to_keyvalue_auxv:nn }
   }
 %    \end{macrocode}
 %   The two clear-cut cases have been eliminated, and we therefore have to deal
@@ -4127,6 +4126,20 @@
 \cs_new_protected:Npn \@@_arg_to_keyvalue_set_keyvalue:nn #1#2
   { \tl_set:Nn \ProcessedArgument {#2} }
 %    \end{macrocode}
+%   A utility to allow us to grab the first \texttt{N}-type token without
+%   risking brace stripping the rest of the input.
+%    \begin{macrocode}
+\cs_new:Npn \@@_split_N_head_apply:Nn #1#2
+  { \exp:w \if_false: { \fi: \@@_split_N_head_apply_aux:NNw #1#2 } }
+\cs_new:Npn \@@_split_N_head_apply_aux:NNw #1#2
+  {
+    \exp_after:wN \exp_end:
+    \exp_after:wN #1 \exp_after:wN #2 \exp_after:wN { \if_false: } \fi:
+  }
+
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
 % \end{macro}
 % \end{macro}
 % \end{macro}
diff --git a/base/testfiles-ltcmd/ltcmd008.lvt b/base/testfiles-ltcmd/ltcmd008.lvt
index 01b3cb4d..786e5af6 100644
--- a/base/testfiles-ltcmd/ltcmd008.lvt
+++ b/base/testfiles-ltcmd/ltcmd008.lvt
@@ -28,6 +28,7 @@
     \foo [ $y = mx + c$  ] { baz }
     \foo [ \( y = mx + c \)  ] { baz }
     \foo [ math = $y \mathbin{=} mx + c$  ] { baz }
+    \foo [ \bong { bar } ] { baz }
   }
 
 \TEST { Mixed~argument~types~using~={...} }
diff --git a/base/testfiles-ltcmd/ltcmd008.tlg b/base/testfiles-ltcmd/ltcmd008.tlg
index 0f237f1a..25c4ba52 100644
--- a/base/testfiles-ltcmd/ltcmd008.tlg
+++ b/base/testfiles-ltcmd/ltcmd008.tlg
@@ -17,6 +17,7 @@ TEST 2: Collecting keyvals
 (TOC-entry={$y=mx+c$})(baz)
 (TOC-entry={\(y=mx+c\)})(baz)
 (math=$y\mathbin {=}mx+c$)(baz)
+(TOC-entry={\bong {bar}})(baz)
 ============================================================
 ============================================================
 TEST 3: Mixed argument types using ={...}





More information about the latex3-commits mailing list.