[latex3-commits] [git/LaTeX3-latex3-latex3] xparse: Avoid second error for environment with too many args (e79c9c7)

Bruno Le Floch bruno at le-floch.fr
Wed Feb 27 17:52:57 CET 2019


Repository : https://github.com/latex3/latex3
On branch  : xparse
Link       : https://github.com/latex3/latex3/commit/e79c9c717665ac42ea9d527e15a404fb4ea95c39

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

commit e79c9c717665ac42ea9d527e15a404fb4ea95c39
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Wed Feb 27 17:52:57 2019 +0100

    Avoid second error for environment with too many args


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

e79c9c717665ac42ea9d527e15a404fb4ea95c39
 l3packages/xparse/testfiles/xparse005.tlg |    8 ------
 l3packages/xparse/xparse.dtx              |   38 ++++++++++++++++++-----------
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/l3packages/xparse/testfiles/xparse005.tlg b/l3packages/xparse/testfiles/xparse005.tlg
index 2dab2fe..10ef228 100644
--- a/l3packages/xparse/testfiles/xparse005.tlg
+++ b/l3packages/xparse/testfiles/xparse005.tlg
@@ -220,14 +220,6 @@ l. ...  }
 The argument specification provided has more than 9 arguments. This cannot be
 implemented.
 LaTeX will ignore this entire definition.
-! LaTeX3 Error: Function '\environment testA end aux ' cannot be defined with
-(LaTeX3)        12 arguments.
-For immediate help type H <return>.
- ...                                              
-l. ...  }
-This is a coding error.
-LaTeX has been asked to define a function '\environment testA end aux ' with
-12 arguments. TeX allows between 0 and 9 arguments for a single function.
 ! LaTeX3 Error: Two '!' apply to the same argument in argument specification
 (LaTeX3)        of command '\testA'.
 For immediate help type H <return>.
diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index 4a8447b..79fa3b3 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -1124,7 +1124,7 @@
 % \begin{macro}{\@@_declare_cmd:Nnn, \@@_declare_expandable_cmd:Nnn}
 % \begin{macro}{\@@_declare_cmd_aux:Nnn}
 % \begin{macro}
-%   {\@@_declare_cmd_internal:Nnn, \@@_declare_cmd_internal:cnx}
+%   {\@@_declare_cmd_internal:Nnnn, \@@_declare_cmd_internal:cnxn}
 %   The main functions for creating commands set the appropriate flag then
 %   use the same internal code to do the definition.
 %    \begin{macrocode}
@@ -1142,7 +1142,7 @@
 %  The first stage is to log information, both for the user in the log and
 %  for programmatic use in a property list of all declared commands.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_declare_cmd_aux:Nnn #1#2
+\cs_new_protected:Npn \@@_declare_cmd_aux:Nnn #1#2#3
   {
     \cs_if_exist:NTF #1
       {
@@ -1161,7 +1161,7 @@
           { \token_to_str:N #1 } { \tl_to_str:n {#2} }
       }
     \bool_set_false:N \l_@@_environment_bool
-    \@@_declare_cmd_internal:Nnn #1 {#2}
+    \@@_declare_cmd_internal:Nnnn #1 {#2} {#3} { }
   }
 %    \end{macrocode}
 %   At definition time, the variable \cs{l_@@_fn_tl} is only used for error messages.
@@ -1169,7 +1169,7 @@
 %   the appropriate name, then normalizing the argument specification to get rid of
 %   shorthands.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_declare_cmd_internal:Nnn #1#2#3
+\cs_new_protected:Npn \@@_declare_cmd_internal:Nnnn #1#2#3#4
   {
     \tl_set:Nx \l_@@_function_tl { \cs_to_str:N #1 }
     \tl_set:Nx \l_@@_fn_tl
@@ -1177,9 +1177,10 @@
     \@@_normalize_arg_spec:n {#2}
     \exp_args:No \@@_prepare_signature:n \l_@@_arg_spec_tl
     \@@_declare_cmd_code:Nnn #1 {#2} {#3}
+    #4
     \@@_break_point:n {#2}
   }
-\cs_generate_variant:Nn \@@_declare_cmd_internal:Nnn { cnx }
+\cs_generate_variant:Nn \@@_declare_cmd_internal:Nnnn { cnx }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
@@ -1327,7 +1328,8 @@
     \bool_set_false:N \l_@@_expandable_bool
     \bool_set_true:N \l_@@_environment_bool
     \str_set:Nx \l_@@_environment_str {#1}
-    \@@_declare_env_internal:nnnn {#1} {#2}
+    \exp_args:NV \@@_declare_env_internal:nnnn
+      \l_@@_environment_str {#2}
   }
 %    \end{macrocode}
 %   Creating a document environment requires a few more steps than creating
@@ -1337,10 +1339,16 @@
 %   redefined to contain the appropriate information. To minimize the amount
 %   of expansion at point of use, the code here is expanded now as well as
 %   when used.
+%   The last argument of \cs{@@_declare_cmd_internal:Nnnn} is only run
+%   if the definition succeeded.  In package mode this ensures that the
+%   original definition of the environment is not changed if the
+%   definition fails for any reason.  This also avoids an error when
+%   defining the \verb*|end aux | function when the user asks for more
+%   than $9$ arguments.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_declare_env_internal:nnnn #1#2#3#4
   {
-    \@@_declare_cmd_internal:cnx { environment~ #1 } {#2}
+    \@@_declare_cmd_internal:cnxn { environment~ #1 } {#2}
       {
         \cs_set_nopar:Npx \exp_not:c { environment~ #1 ~end~aux }
           {
@@ -1349,15 +1357,17 @@
           }
         \exp_not:n {#3}
       }
-    \cs_set_nopar:cpx { environment~ #1 ~end }
-      { \exp_not:c { environment~ #1 ~end~aux } }
-    \cs_generate_from_arg_count:cNnn
-      { environment~ #1 ~end~aux~ } \cs_set:Npn
-      \l_@@_current_arg_int {#4}
+      {
+        \cs_set_nopar:cpx { environment~ #1 ~end }
+          { \exp_not:c { environment~ #1 ~end~aux } }
+        \cs_generate_from_arg_count:cNnn
+          { environment~ #1 ~end~aux~ } \cs_set:Npn
+          \l_@@_current_arg_int {#4}
 %<*package>
-    \cs_set_eq:cc {#1}       { environment~ #1 }
-    \cs_set_eq:cc { end #1 } { environment~ #1 ~end }
+        \cs_set_eq:cc {#1}       { environment~ #1 }
+        \cs_set_eq:cc { end #1 } { environment~ #1 ~end }
 %</package>
+      }
   }
 %    \end{macrocode}
 % \end{macro}





More information about the latex3-commits mailing list