summaryrefslogtreecommitdiff
path: root/macros/generic/expkv-cs/expkv-cs.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/generic/expkv-cs/expkv-cs.dtx')
-rw-r--r--macros/generic/expkv-cs/expkv-cs.dtx152
1 files changed, 66 insertions, 86 deletions
diff --git a/macros/generic/expkv-cs/expkv-cs.dtx b/macros/generic/expkv-cs/expkv-cs.dtx
index ffb706b221..c975e4931c 100644
--- a/macros/generic/expkv-cs/expkv-cs.dtx
+++ b/macros/generic/expkv-cs/expkv-cs.dtx
@@ -1568,8 +1568,8 @@ and the derived files expkv-cs.pdf
% \begin{macro}{\ekvcVersion,\ekvcDate}
% We're on our first input, so lets store the version and date in a macro.
% \begin{macrocode}
-\def\ekvcVersion{1.1a}
-\def\ekvcDate{2021-09-20}
+\def\ekvcVersion{1.1b}
+\def\ekvcDate{2021-11-21}
% \end{macrocode}
% \end{macro}
%
@@ -1783,7 +1783,7 @@ and the derived files expkv-cs.pdf
% \begin{macro}[internal]
% {
% \ekvc@SetupSplitKeys, \ekvc@SetupSplitKeys@a, \ekvc@SetupSplitKeys@b,
-% \ekvc@SetupSplitKeys@c, \ekvc@SetupSplitKeys@d
+% \ekvc@SetupSplitKeys@c, \ekvc@SetupSplitKeys@d, \ekvc@SetupSplitKeys@e,
% \ekvc@SetupSplitKeys@check@unknown,\ekvc@SetupSplitKeys@unknown
% }
% These macros parse the list of keys and set up the key macros. First we need
@@ -1791,7 +1791,7 @@ and the derived files expkv-cs.pdf
% \begin{macrocode}
\protected\long\def\ekvc@SetupSplitKeys
{%
- \ekvc@keycount=0
+ \ekvc@keycount=\ekv@zero
\let\ekvc@any@long\ekv@empty
\let\ekvc@initials\ekv@empty
\ekvparse\ekvc@SetupSplitKeys@check@unknown\ekvc@SetupSplitKeys@a
@@ -1829,20 +1829,15 @@ and the derived files expkv-cs.pdf
% the value given to the key. Additionally we'll need a sorting macro for each
% key count in use so we set it up with |\ekvc@setup@splitmacro|.
% \begin{macrocode}
-\protected\long\def\ekvc@SetupSplitKeys@d#1#2%
+\protected\def\ekvc@SetupSplitKeys@d
{%
- \begingroup
- \edef\ekvc@tmp
- {%
- \endgroup
- \long\def\ekv@unexpanded{\ekvc@tmp}####1####2%
- \ekv@unexpanded\expandafter
- {\csname ekvc@splitmark@\the\ekvc@keycount\endcsname}####3%
- {%
- ####2%
- \ekv@unexpanded\expandafter
- {\csname ekvc@splitmark@\the\ekvc@keycount\endcsname}{####1}%
- }%
+ \begingroup\expandafter\endgroup
+ \expandafter\ekvc@SetupSplitKeys@e
+ \csname ekvc@splitmark@\the\ekvc@keycount\endcsname
+ }
+\protected\long\def\ekvc@SetupSplitKeys@e#1#2#3%
+ {%
+ \long\def\ekvc@tmp##1##2#1##3{##2#1{##1}}%
% \end{macrocode}
% The short variant needs a bit of special treatment. The key macro will be
% short to throw the correct error, but since there might be long macros
@@ -1850,25 +1845,16 @@ and the derived files expkv-cs.pdf
% use a two step approach, first grabbing only the short argument, then
% reordering.
% \begin{macrocode}
- \unless\ifx\ekvc@long\long
- \let\ekv@unexpanded\expandafter
- {\csname ekvc@\ekvc@set(\detokenize{#1})\endcsname\ekvc@tmp}%
- \def\ekv@unexpanded{\ekvc@tmp}####1%
- {%
- \ekv@unexpanded\expandafter
- {\csname ekvc@\ekvc@set(\detokenize{#1})\endcsname}%
- {####1}%
- }%
- \fi
- \def\ekv@unexpanded{\ekvc@initials}%
- {%
- \ekv@unexpanded\expandafter{\ekvc@initials}%
- \ekv@unexpanded\expandafter
- {\csname ekvc@splitmark@\the\ekvc@keycount\endcsname{#2}}%
- }%
- }%
- \ekvc@tmp
- \ekvlet\ekvc@set{#1}\ekvc@tmp
+ \unless\ifx\ekvc@long\long
+ \expandafter\let\csname ekvc@\ekvc@set(#2)\endcsname\ekvc@tmp
+ \edef\ekvc@tmp##1%
+ {%
+ \ekv@unexpanded\expandafter{\csname ekvc@\ekvc@set(#2)\endcsname}%
+ {##1}%
+ }%
+ \fi
+ \ekvlet\ekvc@set{#2}\ekvc@tmp
+ \edef\ekvc@initials{\ekv@unexpanded\expandafter{\ekvc@initials#1{#3}}}%
\ekvc@helpers@needed
{\expandafter\ekvc@setup@splitmacro\expandafter{\the\ekvc@keycount}}%
{}%
@@ -2128,7 +2114,7 @@ and the derived files expkv-cs.pdf
% \begin{macro}[internal]
% {
% \ekvc@SetupHashKeys,\ekvc@SetupHashKeys@a,\ekvc@SetupHashKeys@b,
-% \ekvc@SetupHashKeys@c,\ekvc@SetupHashKeys@d
+% \ekvc@SetupHashKeys@c,\ekvc@SetupHashKeys@d,\ekvc@SetupHashKeys@e,
% \ekvc@SetupHashKeys@check@unknown,\ekvc@SetupHashKeys@unknown
% }
% This should look awfully familiar as well, since it's just the same as for
@@ -2156,44 +2142,35 @@ and the derived files expkv-cs.pdf
{\ekvc@SetupHashKeys@d{#1 #2}}%
}
% \end{macrocode}
+% Again we build the marker, this time instead of a numbered one a named
+% hashmark, inside a group to not actually define the macro used as a marker.
+% \begin{macrocode}
+\protected\long\def\ekvc@SetupHashKeys@d#1%
+ {%
+ \begingroup\expandafter\endgroup
+ \expandafter\ekvc@SetupHashKeys@e\csname ekvc@hashmark@#1\endcsname{#1}%
+ }
+% \end{macrocode}
% Yes, even the defining macro looks awfully familiar. Instead of numbered we
% have named marks. Still the key macros grab everything up to their
% respective mark and reorder the arguments. The same quirk is applied for
% short keys. And instead of the |\ekvc@setup@splitmacro| we use
% |\ekvc@setup@hashmacro|.
% \begin{macrocode}
-\protected\long\def\ekvc@SetupHashKeys@d#1#2%
+\protected\long\def\ekvc@SetupHashKeys@e#1#2#3%
{%
- \begingroup
- \edef\ekvc@tmp
- {%
- \endgroup
- \long\def\ekv@unexpanded{\ekvc@tmp}####1####2%
- \ekv@unexpanded\expandafter{\csname ekvc@hashmark@#1\endcsname}%
- ####3%
- {%
- ####2%
- \ekv@unexpanded\expandafter{\csname ekvc@hashmark@#1\endcsname}%
- {####1}%
- }%
- \unless\ifx\ekvc@long\long
- \let\ekv@unexpanded\expandafter
- {\csname ekvc@\ekvc@set(#1)\endcsname\ekvc@tmp}%
- \def\ekv@unexpanded{\ekvc@tmp}####1%
- {%
- \ekv@unexpanded\expandafter{\csname ekvc@\ekvc@set(#1)\endcsname}%
- {####1}%
- }%
- \fi
- \def\ekv@unexpanded{\ekvc@initials}%
- {%
- \ekv@unexpanded\expandafter{\ekvc@initials}%
- \ekv@unexpanded\expandafter{\csname ekvc@hashmark@#1\endcsname{#2}}%
- }%
- }%
- \ekvc@tmp
- \ekvlet\ekvc@set{#1}\ekvc@tmp
- \ekvc@setup@hashmacro{#1}%
+ \long\def\ekvc@tmp##1##2#1##3{##2#1{##1}}%
+ \unless\ifx\ekvc@long\long
+ \expandafter\let\csname ekvc@\ekvc@set(#2)\endcsname\ekvc@tmp
+ \edef\ekvc@tmp##1%
+ {%
+ \ekv@unexpanded\expandafter{\csname ekvc@\ekvc@set(#2)\endcsname}%
+ {##1}%
+ }%
+ \fi
+ \ekvlet\ekvc@set{#2}\ekvc@tmp
+ \edef\ekvc@initials{\ekv@unexpanded\expandafter{\ekvc@initials#1{#3}}}%
+ \ekvc@setup@hashmacro{#2}%
}
% \end{macrocode}
% \begin{macrocode}
@@ -2479,7 +2456,10 @@ and the derived files expkv-cs.pdf
% \end{macro}
%
% \begin{macro}[internal]
-% {\ekvc@change,\ekvc@change@a,\ekvc@change@b,\ekvc@change@c}
+% {
+% \ekvc@change ,\ekvc@change@a,\ekvc@change@b,
+% \ekvc@change@c,\ekvc@change@d,\ekvc@change@e
+% }
% First we need to see whether the macro is currently |\long|. For this we get
% the meaning and will parse it. |#1| is the macro name in which we want to
% change the defaults.
@@ -2502,11 +2482,12 @@ and the derived files expkv-cs.pdf
\expandafter\ekvc@change@a\expandafter{\detokenize{macro:}}
% \end{macrocode}
% Next we expand the macro once to get its contents (including the current
-% default values with their markers). |#1| is either |\long| or empty, |#2| is
-% the macro.
+% default values with their markers) and place |\ekvc@stop| instead of an
+% argument as a marker for the last step. |#1| is either |\long| or empty,
+% |#2| is the macro.
% \begin{macrocode}
\protected\def\ekvc@change@b#1#2%
- {\expandafter\ekvc@change@c\expandafter{#2{##1}}{#1}#2}
+ {\expandafter\ekvc@change@c\expandafter{#2\ekvc@stop}{#1}#2}
% \end{macrocode}
% Here we place an unbalanced closing brace after the expansion of the macro.
% Then we just parse the \kv-list with |\ekvset|, that will exchange the
@@ -2518,25 +2499,24 @@ and the derived files expkv-cs.pdf
% \begin{macrocode}
\ekv@exparg{\protected\long\def\ekvc@change@c#1#2#3#4}%
{%
- \expandafter\iffalse\expandafter{\expandafter\fi
+ \expandafter\iffalse\expandafter{\expandafter{\expandafter\fi
\ekvset{\string#3}{#4}%
\ekvc@change@d{#2}{#3}%
#1%
- }%
+ }}%
}
% \end{macrocode}
-% The final step needs to put an unbalanced opening brace after |\def|. We do
-% that with the help of a temporary macro which stores everything necessary
-% for |\def| and expand an |\iffalse}\fi| construct to leave a single
-% opening brace. |#1| will be either empty or |\long| and |#2| is the macro.
-% Each of the macros defined with \expkvc\ takes exactly one parameter, so we
-% put that here as |####1|.
+% The final step needs to put an unbalanced opening brace after |\edef|. Also
+% we have to protect everything from further expanding with the exception of
+% the redefined macro's argument, which is why we placed the |\ekvc@stop|
+% earlier. Then we need to also protect the rest of the contents from further
+% expanding using |\unexpanded| with another unbalanced opening brace.
+% |#1| will be either empty or |\long| and |#2| is the macro.
% \begin{macrocode}
\protected\def\ekvc@change@d#1#2%
- {%
- \def\ekvc@tmp{#1\def#2####1}%
- \expandafter\ekvc@tmp\expandafter{\iffalse}\fi
- }
+ {#1\edef#2##1{\expandafter\ekvc@change@e\iffalse}\fi}
+\long\def\ekvc@change@e#1\ekvc@stop
+ {\ekv@unexpanded{#1}##1\ekv@unexpanded\expandafter{\iffalse}\fi}
% \end{macrocode}
% \end{macro}
%
@@ -3018,8 +2998,8 @@ and the derived files expkv-cs.pdf
% \end{macro}
%
% \begin{macro}{\ekvcFlagIf}
-% As already explained, truthiness is defined as a flag's height is odd, so we
-% just branch accordingly here.
+% As already explained, truthiness is defined as a flag's height being odd, so
+% we just branch accordingly here.
% \begin{macrocode}
\def\ekvcFlagIf#1%
{%