[latex3-commits] [git/LaTeX3-latex3-latex3] github-629: Allow xparse processors to depend on other arguments (fixes #629) (b110cee57)

Bruno Le Floch bruno at le-floch.fr
Sun Sep 29 22:13:18 CEST 2019


Repository : https://github.com/latex3/latex3
On branch  : github-629
Link       : https://github.com/latex3/latex3/commit/b110cee570494250baa5c0355ebc605a874f6965

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

commit b110cee570494250baa5c0355ebc605a874f6965
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sun Sep 29 22:12:32 2019 +0200

    Allow xparse processors to depend on other arguments (fixes #629)


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

b110cee570494250baa5c0355ebc605a874f6965
 l3packages/CHANGELOG.md                          |  2 ++
 l3packages/xparse/testfiles/xparse004.luatex.tlg |  6 +++++
 l3packages/xparse/testfiles/xparse004.lvt        |  8 +++++++
 l3packages/xparse/testfiles/xparse004.tlg        |  6 +++++
 l3packages/xparse/xparse.dtx                     | 30 ++++++++++++++++++++----
 5 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/l3packages/CHANGELOG.md b/l3packages/CHANGELOG.md
index 03c6c6f29..ed626b19a 100644
--- a/l3packages/CHANGELOG.md
+++ b/l3packages/CHANGELOG.md
@@ -7,6 +7,8 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+- `xparse`: Allow processors to depend on other arguments (fixes #629)
+
 ## [2019-05-28]
 
 - `xparse`: Remove stray spaces in processor information
diff --git a/l3packages/xparse/testfiles/xparse004.luatex.tlg b/l3packages/xparse/testfiles/xparse004.luatex.tlg
index 426004e34..df6346e5a 100644
--- a/l3packages/xparse/testfiles/xparse004.luatex.tlg
+++ b/l3packages/xparse/testfiles/xparse004.luatex.tlg
@@ -845,3 +845,9 @@ TEST 29: Processor spaces
 |{a}{bcd}|
 > \box_wd:N \l_tmpa_box =0.0pt.
 ============================================================
+============================================================
+TEST 30: Processor depending on other argument
+============================================================
+|{a}{bcd;e}|1|
+|{a,bcd}{e}|1|
+============================================================
diff --git a/l3packages/xparse/testfiles/xparse004.lvt b/l3packages/xparse/testfiles/xparse004.lvt
index 2fd37b5a7..25751d9a7 100644
--- a/l3packages/xparse/testfiles/xparse004.lvt
+++ b/l3packages/xparse/testfiles/xparse004.lvt
@@ -472,4 +472,12 @@
     \dim_log:n { \box_wd:N \l_tmpa_box }
   }
 
+\TEST { Processor~depending~on~other~argument }
+  {
+    \DeclareDocumentCommand { \foo } { >{\SplitList{#2}} m >{\CountArg} O{,} }
+      { \TYPE { \tl_to_str:n { |#1|#2| } } }
+    \foo { a , bcd ; e }
+    \foo { a , bcd ; e } [;]
+  }
+
 \END
diff --git a/l3packages/xparse/testfiles/xparse004.tlg b/l3packages/xparse/testfiles/xparse004.tlg
index c067611e8..a6d8b5975 100644
--- a/l3packages/xparse/testfiles/xparse004.tlg
+++ b/l3packages/xparse/testfiles/xparse004.tlg
@@ -845,3 +845,9 @@ TEST 29: Processor spaces
 |{a}{bcd}|
 > \box_wd:N \l_tmpa_box =0.0pt.
 ============================================================
+============================================================
+TEST 30: Processor depending on other argument
+============================================================
+|{a}{bcd;e}|1|
+|{a,bcd}{e}|1|
+============================================================
diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index 0251ec847..51671cd34 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -340,6 +340,7 @@
 % mailing list.
 %
 % \subsection{Default values of arguments}
+% \label{sec:defaultvaluesofarguments}
 %
 % Uppercase argument types (\texttt{O}, \texttt{D}, \ldots{}) allow to
 % specify a default value to be used when the argument is missing; their
@@ -676,6 +677,23 @@
 % followed by \cs{ProcessorB} to the tokens grabbed by the \texttt{m}
 % argument.
 %
+% It might sometimes be useful to use the value of another argument as
+% one of the arguments of a processor.  For example, using the
+% \cs{SplitList} processor defined below,
+% \begin{verbatim}
+%   \NewDocumentCommand \foo { O{,} >{\SplitList{#1}} m } { \foobar{#2} }
+%   \foo{a,b;c,d}
+% \end{verbatim}
+% results in |\foobar| receiving the argument |{a}{b;c}{d}| because
+% \cs{SplitList} receives as its two arguments the optional one (whose
+% value here is the default, a comma) and the mandatory one.  To
+% summarize, first the arguments are searched for in the input, then any
+% default argument is determined as explained in
+% Section~\ref{sec:defaultvaluesofarguments}, then these default
+% arguments are passed to any processor.  When referring to arguments
+% (through |#1|, |#2| and so on) in a processor, the arguments used are
+% always those before applying any processor.
+%
 % \begin{variable}{\ProcessedArgument}
 %   \pkg{xparse} defines a very small set of processor functions. In the
 %   main, it is anticipated that code writers will want to create their
@@ -1552,7 +1570,7 @@
 % \end{macro}
 %
 % \begin{macro}{\@@_args_process:}
-% \begin{macro}{\@@_args_process_loop:nn, \@@_args_process_aux:n, \@@_args_process_aux:nn}
+% \begin{macro}{\@@_args_process_loop:nn, \@@_args_process_aux:n}
 %   Loop through arguments (stored in \cs{l_@@_args_tl}) and the
 %   corresponding processors (in \cs{l_@@_process_all_tl})
 %   simultaneously, apply all processors for each argument and store the
@@ -1575,9 +1593,13 @@
     \tl_put_right:No \l_@@_args_ii_tl
       { \exp_after:wN { \ProcessedArgument } }
   }
-\cs_new_protected:Npn \@@_args_process_aux:n
-  { \exp_args:No \@@_args_process_aux:nn { \ProcessedArgument } }
-\cs_new_protected:Npn \@@_args_process_aux:nn #1#2 { #2 {#1} }
+\cs_new_protected:Npn \@@_args_process_aux:n #1
+  {
+    \cs_generate_from_arg_count:NNnn \@@_tmp:w \cs_set:Npn
+      { \l_@@_current_arg_int } {#1}
+    \exp_args:NNNo \exp_after:wN \@@_tmp:w \l_@@_args_tl
+      { \ProcessedArgument }
+  }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}





More information about the latex3-commits mailing list