[latex3-commits] [latex3/latex3] gh1550: Support 'opt' cmds in \GetDocumentCommandArgSpec (6aa399b3f)

github at latex-project.org github at latex-project.org
Sat Jul 20 14:55:33 CEST 2024


Repository : https://github.com/latex3/latex3
On branch  : gh1550
Link       : https://github.com/latex3/latex3/commit/6aa399b3ffa951f3aad9268a65a2a7374414d605

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

commit 6aa399b3ffa951f3aad9268a65a2a7374414d605
Author: Joseph Wright <joseph at texdev.net>
Date:   Sat Jul 20 14:36:31 2024 +0200

    Support 'opt' cmds in \GetDocumentCommandArgSpec
    
    Fixes #1550.


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

6aa399b3ffa951f3aad9268a65a2a7374414d605
 l3packages/CHANGELOG.md                   |  2 ++
 l3packages/xparse/testfiles/xparse009.lvt |  9 +++++++++
 l3packages/xparse/testfiles/xparse009.tlg | 16 +++++++++++++---
 l3packages/xparse/xparse.dtx              | 17 ++++++++++++++++-
 4 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/l3packages/CHANGELOG.md b/l3packages/CHANGELOG.md
index b57519528..281908ead 100644
--- a/l3packages/CHANGELOG.md
+++ b/l3packages/CHANGELOG.md
@@ -8,6 +8,8 @@ this project uses date-based 'snapshot' version identifiers.
 ## [Unreleased]
 
 ### Fixed
+- Support for optimised commands using `\GetDocumentCommandArgSpec` (issue
+  [\#1550](https://github.com/latex3/latex3/issues/1550))
 - Unmatched `macrocode` environment in `xtemplate`
 
 ## [2024-05-08]
diff --git a/l3packages/xparse/testfiles/xparse009.lvt b/l3packages/xparse/testfiles/xparse009.lvt
index 9bddb077d..7950d9d2d 100644
--- a/l3packages/xparse/testfiles/xparse009.lvt
+++ b/l3packages/xparse/testfiles/xparse009.lvt
@@ -87,5 +87,14 @@
     \ShowDocumentEnvironmentArgSpec { undefined }
   }
 
+\TEST { Optimised~specs }
+  {
+    \OMIT
+    \DeclareDocumentCommand \fooa { } { }
+    \DeclareDocumentCommand \foob { mmm } { }
+    \TIMO
+    \ShowDocumentCommandArgSpec { \fooa }
+    \ShowDocumentCommandArgSpec { \foob }
+  }
 
 \END
\ No newline at end of file
diff --git a/l3packages/xparse/testfiles/xparse009.tlg b/l3packages/xparse/testfiles/xparse009.tlg
index f850aa409..1511d33b7 100644
--- a/l3packages/xparse/testfiles/xparse009.tlg
+++ b/l3packages/xparse/testfiles/xparse009.tlg
@@ -4,8 +4,8 @@ Author: Joseph Wright
 ============================================================
 TEST 1: Get and show argument spec
 ============================================================
-|\null code |
-> \ArgumentSpecification=\null code .
+||
+> \ArgumentSpecification=.
 <recently read> }
 l. ...  }
 ||
@@ -208,7 +208,7 @@ For immediate help type H <return>.
 l. ...  }
 You have used \NewExpandableDocumentCommand with a command that already has a definition.
 The existing definition of '\?' will not be altered.
-> \ArgumentSpecification=\? code .
+> \ArgumentSpecification=m.
 <recently read> }
 l. ...  }
 ============================================================
@@ -238,3 +238,13 @@ For immediate help type H <return>.
 l. ...  }
 You have asked for the argument specification for the environment 'undefined', but it is not defined.
 ============================================================
+============================================================
+TEST 4: Optimised specs
+============================================================
+> \ArgumentSpecification=.
+<recently read> }
+l. ...  }
+> \ArgumentSpecification=mmm.
+<recently read> }
+l. ...  }
+============================================================
diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index 62ac19ff2..5ffdb727e 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -1442,7 +1442,22 @@
   {
     \__kernel_cmd_if_xparse:NTF #1
       {
-        \tl_set:Ne \ArgumentSpecification { \tl_item:Nn #1 { 2 } }
+        \tl_set:Ne \ArgumentSpecification
+          {
+            \exp_args:No \tl_if_head_eq_meaning:nNTF {#1} \@@_start_optimized:
+              {
+                \prg_replicate:nn
+                  {
+                    \str_count:e
+                      {
+                        \exp_args:Nc \cs_parameter_spec:N
+                          { \cs_to_str:N #1 \c_space_tl code }
+                      } / 2
+                  }
+                  { m }
+              }
+              { \tl_item:Nn #1 { 2 } }
+          }
         #2
       }
       {#3}





More information about the latex3-commits mailing list.