[latex3-commits] [git/LaTeX3-latex3-latex3] main: Implement expanded-fix for keyval (see #912 and #896) (05cc492ea)

Bruno Le Floch blflatex at gmail.com
Wed May 12 12:23:01 CEST 2021


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

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

commit 05cc492ea21ad1e039894004388e1f0b55b4fe80
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Wed May 12 12:23:01 2021 +0200

    Implement expanded-fix for keyval (see #912 and #896)


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

05cc492ea21ad1e039894004388e1f0b55b4fe80
 l3kernel/l3keys.dtx | 78 ++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 50 insertions(+), 28 deletions(-)

diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index fbd8d4b5b..fba59760b 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -1016,11 +1016,27 @@
 %   The use of \cs{s_@@_mark} here prevents loss of braces from the key
 %   argument.
 %    \begin{macrocode}
-      \cs_new:Npn \keyval_parse:nnn ##1 ##2 ##3
+      \cs_if_exist:NTF \tex_expanded:D
         {
-          \group_align_safe_begin:
-          \@@_loop_active:nnw {##1} {##2} \s_@@_mark ##3 #1 \s_@@_tail #1
-          \group_align_safe_end:
+          \cs_new:Npn \keyval_parse:nnn ##1 ##2 ##3
+            {
+              \__kernel_exp_not:w \tex_expanded:D
+                {
+                  {
+                    \@@_loop_active:nnw {##1} {##2}
+                      \s_@@_mark ##3 #1 \s_@@_tail #1
+                  }
+                }
+            }
+        }
+        {
+          \cs_new:Npn \keyval_parse:nnn ##1 ##2 ##3
+            {
+              \group_align_safe_begin:
+              \@@_loop_active:nnw {##1} {##2}
+                \s_@@_mark ##3 #1 \s_@@_tail #1
+              \group_align_safe_end:
+            }
         }
       \cs_new_eq:NN \keyval_parse:NNn \keyval_parse:nnn
 %    \end{macrocode}
@@ -1280,24 +1296,32 @@
 %   \cs{exp_not:n} with the correct arguments. Afterwards they insert the next
 %   iteration of the other loop.
 %    \begin{macrocode}
-\cs_new:Npn \@@_pair:nnnn #1 #2 #3 #4
-  {
-    \@@_if_blank:w \s_@@_mark #2 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
-      \s_@@_mark \s_@@_stop
-    \group_align_safe_end:
-    \exp_not:n { #4 { #2 } { #1 } }
-    \group_align_safe_begin:
-    \@@_loop_other:nnw {#3} {#4}
-  }
-\cs_new:Npn \@@_key:nn #1 #2
-  {
-    \@@_if_blank:w \s_@@_mark #1 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
-      \s_@@_mark \s_@@_stop
-    \group_align_safe_end:
-    \exp_not:n { #2 { #1 } }
-    \group_align_safe_begin:
-    \@@_loop_other:nnw {#2}
-  }
+\group_begin:
+  \cs_set_protected:Npn \@@_tmp:w #1#2
+    {
+      \cs_new:Npn \@@_pair:nnnn ##1 ##2 ##3 ##4
+        {
+          \@@_if_blank:w \s_@@_mark ##2 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
+            \s_@@_mark \s_@@_stop
+          #1
+          \exp_not:n { ##4 {##2} {##1} }
+          #2
+          \@@_loop_other:nnw {##3} {##4}
+        }
+      \cs_new:Npn \@@_key:nn ##1 ##2
+        {
+          \@@_if_blank:w \s_@@_mark ##1 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
+            \s_@@_mark \s_@@_stop
+          #1
+          \exp_not:n { ##2 {##1} }
+          #2
+          \@@_loop_other:nnw {##2}
+        }
+    }
+  \cs_if_exist:NTF \tex_expanded:D
+    { \@@_tmp:w { } { } }
+    { \@@_tmp:w \group_align_safe_end: \group_align_safe_begin: }
+\group_end:
 %    \end{macrocode}
 % \end{macro}
 %
@@ -1319,12 +1343,10 @@
 %    \begin{macrocode}
 \cs_new:Npn \@@_blank_true:w \s_@@_mark \s_@@_stop \@@_trim:nN #1 \@@_key:nn
   { \@@_loop_other:nnw }
-\cs_new:Npn \@@_blank_key_error:w
-  \s_@@_mark \s_@@_stop \group_align_safe_end: \exp_not:n #1 \group_align_safe_begin:
-  {
-    \__kernel_msg_expandable_error:nn
-      { keyval } { blank-key-name }
-  }
+\cs_if_exist:NTF \tex_expanded:D
+  { \cs_new:Npn \@@_blank_key_error:w #1 \exp_not:n #2 }
+  { \cs_new:Npn \@@_blank_key_error:w #1 \group_align_safe_begin: }
+      { \__kernel_msg_expandable_error:nn { keyval } { blank-key-name } }
 %    \end{macrocode}
 % \end{macro}
 %





More information about the latex3-commits mailing list.