summaryrefslogtreecommitdiff
path: root/macros/generic/collargs
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-03-18 03:01:30 +0000
committerNorbert Preining <norbert@preining.info>2024-03-18 03:01:30 +0000
commit9c8677e09c2c9b0d9593f26ed226411d68160a4e (patch)
tree1c5464d3dc4dbe0ad27d69bec29b581f4b0d1fdd /macros/generic/collargs
parent55140d5421e1ad0024c9acbfa72bd06402c2aa9f (diff)
CTAN sync 202403180301
Diffstat (limited to 'macros/generic/collargs')
-rw-r--r--macros/generic/collargs/CHANGELOG.md10
-rw-r--r--macros/generic/collargs/README.md8
-rw-r--r--macros/generic/collargs/collargs.edtx211
3 files changed, 116 insertions, 113 deletions
diff --git a/macros/generic/collargs/CHANGELOG.md b/macros/generic/collargs/CHANGELOG.md
index e3e1204b2d..d79205db9a 100644
--- a/macros/generic/collargs/CHANGELOG.md
+++ b/macros/generic/collargs/CHANGELOG.md
@@ -14,6 +14,16 @@ those cases, please see [Memoize's GitHub
repository](https://github.com/sasozivanovic/memoize) for the recent
development history.
+## 2024/03/15 v1.2.0
+* Argument processors:
+ * They now work without a formal argument, taking token register
+ `\collargsArg` as input. The processors taking a formal argument were
+ impossible (or at least too hard for me) to define.
+ * Remove `append/prepend pre/postwrap`, as they become useless with the above
+ change.
+* Implement keys `clear args` and `return`, and expose `\collargsArgs`.
+* Implement key `alias`.
+
## 2024/01/02 v1.1.0
* Implement `brace collected`.
diff --git a/macros/generic/collargs/README.md b/macros/generic/collargs/README.md
index 235225f08a..35ec0dd7be 100644
--- a/macros/generic/collargs/README.md
+++ b/macros/generic/collargs/README.md
@@ -1,6 +1,6 @@
Package CollArgs provides a command which can determine the argument scope of
-any command whose argument structure conforms to
-[xparse](https://ctan.org/pkg/xparse)'s argument specification.
+any command whose argument structure conforms to
+[LaTeX3 argument specification](https://www.latex-project.org/help/documentation/usrguide.pdf).
This package was developed as an auxiliary package of
[Memoize](https://ctan.org/pkg/memoize). This is why it is, somewhat
@@ -15,5 +15,5 @@ any later version. The latest version of this license is in
https://www.latex-project.org/lppl.txt and version 1.3c or later is part of all
distributions of LaTeX version 2008 or later.
-This work has the LPPL maintenance status `maintained'. The Current Maintainer
-of this work is Sašo Živanović (saso.zivanovic@guest.arnes.si).
+This work has the LPPL maintenance status `maintained`. The Current Maintainer
+of this work is Sašo Živanović (`saso.zivanovic@guest.arnes.si`).
diff --git a/macros/generic/collargs/collargs.edtx b/macros/generic/collargs/collargs.edtx
index 6cd39ad4ca..3df03eabfb 100644
--- a/macros/generic/collargs/collargs.edtx
+++ b/macros/generic/collargs/collargs.edtx
@@ -46,14 +46,14 @@
%
%
% \paragraph{Identification}
-%<latex>\ProvidesPackage{collargs}[2024/01/02 v1.1.0 Collect arguments of any command]
+%<latex>\ProvidesPackage{collargs}[2024/03/15 v1.2.0 Collect arguments of any command]
%<context>%D \module[
%<context>%D file=t-collargs.tex,
-%<context>%D version=1.1.0,
+%<context>%D version=1.2.0,
%<context>%D title=CollArgs,
%<context>%D subtitle=Collect arguments of any command,
%<context>%D author=Saso Zivanovic,
-%<context>%D date=2024-01-02,
+%<context>%D date=2024-03-15,
%<context>%D copyright=Saso Zivanovic,
%<context>%D license=LPPL,
%<context>%D ]
@@ -105,15 +105,14 @@
% \end{macro}
%
% \begin{macro}{\CollectArguments,\CollectArgumentsRaw}
-% These are the only public commands provided by the
-% package. |\CollectArguments| takes three arguments: the optional |#1| is
-% the option list, processed by |pgfkeys| (given the grouping structure,
-% these options will apply to all arguments); the mandatory |#2| is the
-% |xparse|-style argument specification; the mandatory |#3| is the ``next''
-% command (or a sequence of commands). The argument list is expected to
-% start immediately after the final argument; |\CollectArguments| parses it,
-% effectively figuring out its extent, and then passes the entire argument
-% list to the ``next'' command (as a single argument).
+% |\CollectArguments| takes three arguments: the optional |#1| is the option
+% list, processed by |pgfkeys| (given the grouping structure, these options
+% will apply to all arguments); the mandatory |#2| is the |xparse|-style
+% argument specification; the mandatory |#3| is the ``next'' command (or a
+% sequence of commands). The argument list is expected to start immediately
+% after the final argument; |\CollectArguments| parses it, effectively
+% figuring out its extent, and then passes the entire argument list to the
+% ``next'' command (as a single argument).
%
% |\CollectArgumentsRaw| differs only in how it takes and processes the
% options. For one, these should be given as a mandatory argument.
@@ -145,7 +144,9 @@
% Remember the code to execute after collection.
\def\collargs@next{#3}%
% Initialize the token register holding the collected arguments.
- \global\collargs@toks{}%
+ \ifcollargsClearArgs
+ \global\collargsArgs{}%
+ \fi
% Execute the central loop macro, which expects the argument specification
% |#2| to be delimited from the following argument tokens by a dot.
\collargs@#2.%
@@ -162,7 +163,6 @@
\def\collargsSet#1{\pgfqkeys{/collargs}{#1}}
% \end{macro}
%
-%
% \subsubsection{The keys}
% \label{sec:code:collargs:keys}
%
@@ -409,24 +409,10 @@
append postprocessor/.code={\collargsAppendPostprocessor{#1}},
prepend postprocessor/.code={\collargsPrependPostprocessor{#1}},
}
-\def\collargsAppendPreprocessor{%
- \collargs@addprocessor\appto\collargs@preprocess@arg}
-\def\collargsPrependPreprocessor{%
- \collargs@addprocessor\preto\collargs@preprocess@arg}
-\def\collargsAppendPostprocessor{%
- \collargs@addprocessor\appto\collargs@postprocess@arg}
-\def\collargsPrependPostprocessor{%
- \collargs@addprocessor\preto\collargs@postprocess@arg}
-% Here, |#1| will be either |\appto| or |\preto|, and |#2| will be either
-% |\collargs@preprocess@arg| or |\collargs@postprocess@arg|. |#3| is the
-% processor code.
-\def\collargs@addprocessor#1#2#3{%
- #1#2{%
- \expanded{%
- \unexpanded{#3}{\the\collargsArg}%
- }%
- }%
-}
+\def\collargsAppendPreprocessor#1{\appto\collargs@preprocess@arg{#1}}
+\def\collargsPrependPreprocessor#1{\preto\collargs@preprocess@arg{#1}}
+\def\collargsAppendPostprocessor#1{\appto\collargs@postprocess@arg{#1}}
+\def\collargsPrependPostprocessor#1{\preto\collargs@postprocess@arg{#1}}
% \end{macro}
% \end{collargskey}
% \end{macro}
@@ -451,71 +437,38 @@
% \end{collargskey}
% \end{macro}
% \end{collargskey}
-%
+%
% \begin{collargskey}[noindex]{(append/prepend) expandable (pre/post)processor}
% \begin{macro}[noindex]{\collargs(Append/Prepend)Expandable(Pre/Post)processor}
% \begin{collargskey}[noprint]{append expandable preprocessor, prepend expandable preprocessor, append expandable postprocessor, prepend expandable postprocessor}
% \begin{macro}[noprint]{\collargsAppendExpandablePreprocessor,\collargsPrependExpandablePreprocessor,\collargsAppendExpandablePostprocessor,\collargsPrependExpandablePostprocessor}
-% These keys
-% and macros simplify the definition of fully expandable processors. Note
-% that expandable processors are added to the same list as non-expandable
-% processors.
+% These keys and macros simplify the definition of expandable
+% processors. Note that expandable processors are added to the same
+% list as non-expandable processors.
\collargsSet{
- append expandable preprocessor/.code={%
- \collargsAppendExpandablePreprocessor{#1}},
- prepend expandable preprocessor/.code={%
- \collargsPrependExpandablePreprocessor{#1}},
- append expandable postprocessor/.code={%
- \collargsAppendExpandablePostprocessor{#1}},
- prepend expandable postprocessor/.code={%
- \collargsPrependExpandablePostprocessor{#1}},
-}
-\def\collargsAppendExpandablePreprocessor{%
- \collargs@addeprocessor\appto\collargs@preprocess@arg}
-\def\collargsPrependExpandablePreprocessor{%
- \collargs@addeprocessor\preto\collargs@preprocess@arg}
-\def\collargsAppendExpandablePostprocessor{%
- \collargs@addeprocessor\appto\collargs@postprocess@arg}
-\def\collargsPrependExpandablePostprocessor{%
- \collargs@addeprocessor\preto\collargs@postprocess@arg}
-\def\collargs@addeprocessor#1#2#3{%
- #1#2{%
- \expanded{%
- \edef\noexpand\collargs@temp{\unexpanded{#3}{\the\collargsArg}}%
- \unexpanded{\expandafter\collargsArg\expandafter{\collargs@temp}}%
- }%
+ append expandable preprocessor/.code={\collargsAppendExpandablePreprocessor{#1}},
+ prepend expandable preprocessor/.code={\collargsPrependExpandablePreprocessor{#1}},
+ append expandable postprocessor/.code={\collargsAppendExpandablePostprocessor{#1}},
+ prepend expandable postprocessor/.code={\collargsPrependExpandablePostprocessor{#1}},
+}
+\def\collargsAppendExpandablePreprocessor#1{%
+ \appto\collargs@preprocess@arg{%
+ \collargsArg\expandafter{\expanded{#1}}%
}%
}
-% \end{macro}
-% \end{collargskey}
-% \end{macro}
-% \end{collargskey}
-%
-% \begin{collargskey}[noindex]{(append/prepend) (pre/post)wrap}
-% \begin{macro}[noindex]{\collargs(Append/Prepend)(Pre/Post)wrap}
-% \begin{collargskey}[noprint]{append prewrap, prepend prewrap, append postwrap, prepend postwrap}
-% \begin{macro}[noprint]{\collargsAppendPrewrap,\collargsPrependPrewrap,\collargsAppendPostwrap,\collargsPrependPostwrap}
-% These keys and macros
-% simplify the definition of processors which yield the result after a
-% single expansion. Again, they are added to the same list as other
-% processors.
-\collargsSet{
- append prewrap/.code={\collargsAppendPrewrap{#1}},
- prepend prewrap/.code={\collargsPrependPrewrap{#1}},
- append postwrap/.code={\collargsAppendPostwrap{#1}},
- prepend postwrap/.code={\collargsPrependPostwrap{#1}},
-}
-\def\collargsAppendPrewrap{\collargs@addwrap\appto\collargs@preprocess@arg}
-\def\collargsPrependPrewrap{\collargs@addwrap\preto\collargs@preprocess@arg}
-\def\collargsAppendPostwrap{\collargs@addwrap\appto\collargs@postprocess@arg}
-\def\collargsPrependPostwrap{\collargs@addwrap\preto\collargs@postprocess@arg}
-\def\collargs@addwrap#1#2#3{%
- #1#2{%
- \long\def\collargs@temp##1{#3}%
- \expandafter\expandafter\expandafter\collargsArg
- \expandafter\expandafter\expandafter{%
- \expandafter\collargs@temp\expandafter{\the\collargsArg}%
- }%
+\def\collargsPrependExpandablePreprocessor#1{%
+ \preto\collargs@preprocess@arg{%
+ \collargsArg\expandafter{\expanded{#1}}%
+ }%
+}
+\def\collargsAppendExpandablePostprocessor#1{%
+ \appto\collargs@postprocess@arg{%
+ \collargsArg\expandafter{\expanded{#1}}%
+ }%
+}
+\def\collargsPrependExpandablePostprocessor#1{%
+ \preto\collargs@postprocess@arg{%
+ \collargsArg\expandafter{\expanded{#1}}%
}%
}
% \end{macro}
@@ -535,19 +488,51 @@
\newif\ifcollargsNoDelimiters
% \end{macro}
% \end{collargskey}
-
-% \begin{collargskey}{brace collected}
-% \begin{macro}{\ifcollargsBraceCollected}
-% When this conditional is set to false, the collected arguments are not
-% enclosed in braces when passed on to \meta{next-code}.
+%
+% \begin{collargskey}{clear args}
+% \begin{macro}{\ifcollargsClearArgs}
+% When this conditional is set to |false|, the global token register
+% |\collargsArgs| receiving the collected arguments is not cleared prior
+% to argument collection.
+\collargsSet{%
+ clear args/.is if=collargsClearArgs,
+}
+\newif\ifcollargsClearArgs
+\collargsClearArgstrue
+% \end{macro}
+% \end{collargskey}
+%
+% \begin{collargskey}{return}
+% \begin{macro}{\collargsReturn}
+% Exiting |\CollectArguments|, should the next-command be followed by the
+% braced collected arguments, collected arguments as they are, or nothing?
+\collargsSet{%
+ return/.is choice,
+ return/braced/.code=\collargsReturnBraced,
+ return/plain/.code=\collargsReturnPlain,
+ return/no/.code=\collargsReturnNo,
+}
+\def\collargsReturnBraced{\def\collargsReturn{0}}
+\def\collargsReturnPlain{\def\collargsReturn{1}}
+\def\collargsReturnNo{\def\collargsReturn{2}}
+\collargsReturnBraced
+% \end{macro}
+% \end{collargskey}
+%
+% \begin{collargskey}{alias}
+% \begin{macro}{\collargsAlias}
+%
\collargsSet{%
- brace collected/.is if=collargsBraceCollected,
+ alias/.code 2 args=\collargsAlias{#1}{#2}%
+}
+\def\collargsAlias#1#2{%
+ \csdef{collargs@#1}{\collargs@@@#2}%
}
-\newif\ifcollargsBraceCollected
-\collargsBraceCollectedtrue
% \end{macro}
% \end{collargskey}
%
+%
+%
% \subsubsection{The central loop}
% \label{sec:code:collargs:central-loop}
%
@@ -677,11 +662,11 @@
}
% \end{macro}
%
-% \begin{macro}{\collargs@toks}
+% \begin{macro}{\collargsArgs}
% This token register is where we store the collected argument tokens. All
% assignments to this register are global, because it needs to survive the
% groups opened for individual arguments.
-\newtoks\collargs@toks
+\newtoks\collargsArgs
% \end{macro}
%
% \begin{macro}{\collargsArg}
@@ -705,10 +690,10 @@
\endgroup
\noexpand\collargs@fix{%
\expandonce\collargs@next
- \ifcollargsBraceCollected
- {\the\collargs@toks}%
- \else
- \the\collargs@toks
+ \ifcase\collargsReturn\space
+ {\the\collargsArgs}%
+ \or
+ \the\collargsArgs
\fi
\collargs@spaces
}%
@@ -722,7 +707,7 @@
% \begin{macro}{\collargs@appendarg}
% This macro is used by the argument type
% handlers to append the collected argument to the storage
-% (|\collargs@toks|).
+% (|\collargsArgs|).
\long\def\collargs@appendarg#1{%
% Temporarily store the collected argument into a token register. The
% processors will manipulate the contents of this register.
@@ -744,7 +729,7 @@
\collargs@postprocess@arg
% Append the processed argument, preceded by any grabbed spaces (in the
% correct mode), to the storage.
- \xtoksapp\collargs@toks{\collargs@grabbed@spaces\the\collargsArg}%
+ \xtoksapp\collargsArgs{\collargs@grabbed@spaces\the\collargsArg}%
% Initialize the space-grabber.
\collargs@init@grabspaces
% Once the argument was appended to the list, we can close its group, opened
@@ -761,7 +746,15 @@
% defined by the argument type handler. Note that this macro \emph{appends}
% a wrapper, so multiple wrappers are allowed --- this is used by type |e|
% handler.
-\def\collargs@wrap{\collargs@addwrap\appto\collargs@process@arg}
+\def\collargs@wrap#1{%
+ \appto\collargs@process@arg{%
+ \long\def\collargs@temp##1{#1}%
+ \expandafter\expandafter\expandafter\collargsArg
+ \expandafter\expandafter\expandafter{%
+ \expandafter\collargs@temp\expandafter{\the\collargsArg}%
+ }%
+ }%
+}
\def\collargs@process@arg{}
% \end{macro}
%
@@ -1046,7 +1039,7 @@
% which will put everything up to the first opening brace into the first
% argument, looks funky, but that's all.
\collargs@defusecollector##1##{%
- % We append the collected argument, |##1|, to |\collargs@toks|, the token
+ % We append the collected argument, |##1|, to |\collargsArgs|, the token
% register holding the collected argument tokens.
\collargs@appendarg{##1}%
% Back to the central loop, with the rest of the argument specification
@@ -1448,7 +1441,7 @@
\collargs@readContent
}
% This macro appends the result given by the heavy machinery, waiting for us in
-% macro |\collargsArg|, to |\collargs@toks|, but not before dressing
+% macro |\collargsArg|, to |\collargsArgs|, but not before dressing
% it up (via |\collargs@wrap|) in a pair of verbatim braces.
\def\collargs@m@verb@group@i{%
\edef\collargs@temp{%