Home > Archive > Tex > July 2006 > keyval {}
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Lars Madsen 2006-07-24, 8:02 am |
|
I have a macro that gets it argument from a keyval argument, called index
My maco then places #1 into a tokenlist and the recursively pops off a token a
process it. The text that 'index' will get is often in the form
index={env:align}{m:intertext}
where the processing will turn {env:align} into two index entries,
environments!align and align (environment), and similar for {m:intertext}
Everything works fine when ever I have more than one entry as above, then as
tokens in my poping I get {env:align} and {m:intertext}, but if I use
index={env:align}
keyval strips of the {}-pair and my tokens ends up as
e n v : a l i g n
is there any way of altering this 'feature' for this particular keyval value only?
Or should I use the simpler solution (which does work, but is prone to human error)
index={env:align}{}
any ideas?
--
/daleif (remove RTFSIGNATURE from email address)
LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
| |
| Will Robertson 2006-07-24, 8:02 am |
| Lars Madsen wrote:
> I have a macro that gets it argument from a keyval argument, called index
[snip]
> index={env:align}{m:intertext}
[snip]
> index={env:align}
Hi Lars,
I don't understand the different semantics between those two cases. Is
the former supposed to mean something like "the \intertext macro, when
used in the align environment"? If so, maybe there's too much
overloaded syntax. Would a different key be possible? For example,
indexone={env:align}
which turns internally into
index={env:align}{}
?
Sorry for the vague answer,
Will
| |
| Ulrike Fischer 2006-07-24, 8:02 am |
| Lars Madsen <daleif@RTFSIGNATUREimf.au.dk> schrieb:
>
> I have a macro that gets it argument from a keyval argument, called
> index
>
> My maco then places #1 into a tokenlist and the recursively pops off a
> token a process it. The text that 'index' will get is often in the
> form
>
> index={env:align}{m:intertext}
>
> where the processing will turn {env:align} into two index entries,
> environments!align and align (environment), and similar for
> {m:intertext}
>
> Everything works fine when ever I have more than one entry as above,
> then as tokens in my poping I get {env:align} and {m:intertext}, but
> if I use
>
> index={env:align}
>
> keyval strips of the {}-pair and my tokens ends up as
>
> e n v : a l i g n
>
> is there any way of altering this 'feature' for this particular keyval
> value only?
>
> Or should I use the simpler solution (which does work, but is prone to
> human error)
>
> index={env:align}{}
>
> any ideas?
Couldn't you change the input syntax to something like
index={env:align,m:intertext}
and process this list with \@for?
--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
| |
| Lars Madsen 2006-07-24, 8:02 am |
| Ulrike Fischer wrote:
> Lars Madsen <daleif@RTFSIGNATUREimf.au.dk> schrieb:
>
>
>
>
> Couldn't you change the input syntax to something like
>
> index={env:align,m:intertext}
>
> and process this list with \@for?
>
I have bad experiences with for-loops in TeX, and an interesting thing is that
the macro I use for processing can already handle this
index={env:align}{sty:amsmath}{:intertex
t}{fraction!frac@\protect\css{frac}|text
it}%
{some text, something else}
without any problems, this gets translated into (\markup is an internal macro I
already use, nomk= do not write in the margin, nowr= do not write in the text)
\markup[nomk,nowr,env]{align}
\markup[nomk,nowr,sty]{amsmath}
\markup[nomk,nowr]{intertext}
\index{fraction!frac@\protect\css{frac}|
textit}
\index{some text, something else}
so I can save a lot of {}'s
It's only the index={...} case that there was a problem
The actual macros will be released at a later point.
Anyway Morten already send me some macros that might do the trick
--
/daleif (remove RTFSIGNATURE from email address)
LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
| |
| Lars Madsen 2006-07-24, 8:02 am |
|
>
> I don't understand the different semantics between those two cases. Is
> the former supposed to mean something like "the \intertext macro, when
> used in the align environment"? If so, maybe there's too much
> overloaded syntax. Would a different key be possible? For example,
> indexone={env:align}
> which turns internally into
> index={env:align}{}
>
no, actually you're on to something there, because if I in the keyval definition
uses
\tokenlist{{#1}X}...
instead of \tokenlist{#1X}...
then the one argument index actually works (X marks the end of the recursion).
Anyhow I already got some code from somewhere else.
Thanks
--
/daleif (remove RTFSIGNATURE from email address)
LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
| |
|
|
| Ulrich Diez 2006-07-24, 7:03 pm |
| Lars Madsen wrote:
....
> keyval strips of the {}-pair and my tokens ends up as
>
> e n v : a l i g n
>
> is there any way of altering this 'feature' for this particular keyval value only?
keyval's "\setkeys"-macro iterates on comma-separated lists of
key=value-pairs and hereby removes spaces which somehow surround
these key=value-pairs.
As a side-effect, braces get removed from the keys/values also.
If I got the details right, you can loose e.g., up to 3 brace-
levels which surround the value in case that the value is not
surrounded by spaces at all.
The first brace-pair will be stripped by "\KV@split", the second
will be stripped by "\KV@@sp@b" and the third will be stripped by
"\KV@@sp@c".
You may need to define your own iterator/your own variant of
"\setkeys" where brace-stripping does not occur.
I derived something from labelcas.sty:
Actually there are two iterators.
One iterates equal-sign-separated lists and removes leading-
and trailing spaces from the items.
The other iterates comma-separated lists and removes leading-
and trailing spaces from the items.
The very first argument of each iterator denotes the macro that
is to be called on the item when space-stripping is done.
Within "\MYSTUFFsetkeys", the equal-sign-iterator is called so
that the space-stripped argument is appended to a token-register.
Then the comma-iterator is applied to that register so that the
macro "\MYSTUFF@split" is called for splitting key- and value-
part and afterwards setting the key accordingly...
It is cumbersome and I have not tested extensively.
!!!!! Therefore I give NO WARRANTIES !!!!!
Within the example you will get an error-message when
"\MYSTUFFsetkeys" comes to parsing the sequence "third=blebb".
This is because there is no key with name "third" defined.
I inserted that sequence in order to test if the correct
key-val error would be raised.
By the way:
None of the internals of the keyval-package were redefined.
I just added a few macros.
Ulrich
\documentclass{minimal}
% keyval-iterator without brace-stripping at the value.
% Derived from labelcas.sty 1.10 on July 24, 2006 by Ulrich Diez.
% LPPL 1.3 or later (at your option).
% !!!!!No warranties!!!!!
\usepackage{keyval}
\makeatletter
\newcommand\DefineMYSTUFF[3]{%
\expandafter\endgroup
\if@tempswa
\@ifdefinable\MYSTUFF@splitcall{%
\def\MYSTUFF@splitcall#2##1#1#2{%
\MYSTUFF@split##1==\relax
}%
}%
\@ifdefinable\MYsep{%
\def\MYsep{#2}%
}%
\@ifdefinable\MYsepRemove{%
\def\MYsepRemove##1#2{\@gobble##1}%
}%
\@ifdefinable\MYSTUFF@split{%
\def\MYSTUFF@split##1=##2=##3\relax{%
\KV@toks@{##1}\edef\@tempa{\the\KV@toks@
}%
\ifx\@tempa\MYsep\else
\ifx\@empty##3\@empty
\KV@toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\expandafter\MYsepRemove
\expandafter.%
\the\KV@toks@}%
\edef\@tempa{\the\KV@toks@}%
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\KV@errx
{\@tempa\space undefined}%
\else
\KV@default
\fi
\else
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\KV@errx
{\@tempa\space undefined}%
\else
\expandafter\expandafter
\expandafter \@tempc
\expandafter\expandafter
\expandafter {%
\MYsepRemove.##2}\relax
\fi
\fi
\fi}
}%
\else
\@ifdefinable\MYSTUFF@tokadd{%
\def\MYSTUFF@tokadd#2##1#1#2{%
\toks@\expandafter{\the\toks@##1}%
}%
}%
\fi
\expandafter\@ifdefinable\csname#3MYSTUF
F@remtrailspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#3MYSTUFF@remtrailspace\endcsname
##1##2#1#2##3#2#1{%
\begingroup
\toks@{##3}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#3MYSTUFF@remleadspace\endcsname
{##1}#2##2#1#2#2}%
{\csname#3MYSTUFF@remtrailspace\endcsnam
e{##1}##2#2#1#2#2#1}%
}%
}%
\expandafter\@ifdefinable\csname#3MYSTUF
F@remleadspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#3MYSTUFF@remleadspace\endcsname#
#1##2#2#1##3#2#2{%
\begingroup
\toks@{##2}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#3MYSTUFF@remleadspace\endcsname
{##1}#2##3#2#2}%
{##1##2#2#1#2}%
}%
}%
\expandafter\@ifdefinable\csname#3MYSTUF
F@iterate\endcsname{%
\expandafter\long
\expandafter\def
\csname#3MYSTUFF@iterate\endcsname##1##2
#2{%
\begingroup
\toks@{##2}%
\edef\@tempa{\the\toks@}%
\toks@{#1\@nil}%
\edef\@tempb{\the\toks@}%
\expandafter\endgroup\ifx\@tempa\@tempb
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{%
\csname#3MYSTUFF@remtrailspace\endcsname
{##1}##2#2#1#2#2#1%
\csname#3MYSTUFF@iterate\endcsname{##1}#
1%
}%
}%
}%
}%
\@ifdefinable\MYothersepRemove{%
\def\MYothersepRemove#1=\@nil{\@gobble#1
}%
}%
\begingroup\@tempswafalse
\DefineMYSTUFF{ }{=}{equal}
\begingroup\@tempswatrue
\DefineMYSTUFF{ }{,}{comma}
\newcommand*\MYSTUFFsetkeys[2]{%
\def\KV@prefix{KV@#1@}%
\let\@tempc\relax
{%
\toks@{}%
\equalMYSTUFF@iterate{\MYSTUFF@tokadd} #2=\@nil=%
\toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \space
\expandafter\MYothersepRemove
\expandafter.%
\the\toks@\@nil}%
%\showthe\toks@
\expandafter}%
\expandafter\commaMYSTUFF@iterate
\expandafter{%
\expandafter\MYSTUFF@splitcall
\expandafter}%
\the\toks@,\@nil,%
}%
\makeatother
\begin{document}
\makeatletter
\define@key{myfamily}{first}[default]{%
\@temptokena{#1}\showthe\@temptokena
}%
\define@key{myfamily}{second}[default]{%
\@temptokena{#1}\showthe\@temptokena
}%
\makeatother
\MYSTUFFsetkeys{myfamily}{
first = {test} , first = test , ,
first,second,second = test,
first={test},
third=blebb,
first = {test},
}
\end{document}
| |
| Heiko Oberdiek 2006-07-24, 7:03 pm |
| "Ulrich Diez" <eu_angelion@web.de.invalid> wrote:
> Lars Madsen wrote:
>
> ...
>
> keyval's "\setkeys"-macro iterates on comma-separated lists of
> key=value-pairs and hereby removes spaces which somehow surround
> these key=value-pairs.
> As a side-effect, braces get removed from the keys/values also.
It is a feature. That allows putting commas (or equal signs) into the
value.
> If I got the details right, you can loose e.g., up to 3 brace-
> levels which surround the value in case that the value is not
> surrounded by spaces at all.
It would be better, if brace removing is limited to one level.
Yours sincerely
Heiko <oberdiek@uni-freiburg.de>
| |
| Morten Høgholm 2006-07-24, 7:03 pm |
| On Mon, 24 Jul 2006 20:31:28 +0200, Heiko Oberdiek
<oberdiek@uni-freiburg.de> wrote:
> "Ulrich Diez" <eu_angelion@web.de.invalid> wrote:
>
>
> It would be better, if brace removing is limited to one level.
l3keyval from the expl3 code removes exactly one level of bracing.
--
Morten
| |
| Ulrich Diez 2006-07-24, 7:03 pm |
| Morten Høgholm wrote:
> l3keyval from the expl3 code removes exactly one level of bracing.
Sounds ! I wasn't aware of l3keyval when sending my other
posting. I will have a closer look at it tomorrow/at the w end
and learn...
But if I got it right, Lars Madsen requires not even one level of
bracing being removed. This is what I tried to implement.
With my stuff (which presumably is of course not as good/efficient
as l3keyval) you can still remove one bracing-level when setting
the key actually takes place. All you have to do is running the value
through some variant of \@firstofone with a delimiter within
\define@key. Preferably the delimiter shold be a comma as this can
under no circumstances occur on top-level within the value.
Something like:
\newcommand\mytypein[1]{{\def\@inputchec
k{-1}\typein{#1}}}%
\long\def\stripbraces#1,{#1}%
\define@key{myfamily}{first}[default]{%
{\@temptokena\expandafter{\stripbraces#1
,}\mytypein{first: |\the\@temptokena|}}%
}%
Or you change within the macro "\MYSTUFF@split" one instance of
\MYSTUFFSeoRemove to \MYSTUFFBraceRemove:
\documentclass{minimal}
% keyval-iterator without brace-stripping at the value.
% Derived from labelcas.sty 1.10 on July 24, 2006 by Ulrich Diez.
% LPPL 1.3 or later (at your option).
% !!!!!No warranties!!!!!
\usepackage{keyval}
\makeatletter
\newcommand\DefineMYSTUFF[4]{%
{#4\expandafter}%
\if@tempswa
\@ifdefinable\MYSTUFF@splitcall{%
\def\MYSTUFF@splitcall#2##1#1#2{%
\MYSTUFF@split##1==\relax
}%
}%
\@ifdefinable\MYSTUFFSep{%
\def\MYSTUFFSep{#2}%
}%
\@ifdefinable\MYSTUFFSepRemove{%
\def\MYSTUFFSepRemove##1#2{\@gobble##1}%
}%
\@ifdefinable\MYSTUFFBraceRemove{%
\def\MYSTUFFBraceRemove##1#2{##1}%
}%
\@ifdefinable\MYSTUFF@split{%
\def\MYSTUFF@split##1=##2=##3\relax{%
\KV@toks@{##1}\edef\@tempa{\the\KV@toks@
}%
\ifx\@tempa\MYSTUFFSep\else
\ifx\@empty##3\@empty
\KV@toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\expandafter\MYSTUFFSepRemove
\expandafter.%
\the\KV@toks@}%
\edef\@tempa{\the\KV@toks@}%
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\KV@errx
{\@tempa\space undefined}%
\else
\KV@default
\fi
\else
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\KV@errx
{\@tempa\space undefined}%
\else
\expandafter\expandafter
\expandafter \@tempc
\expandafter\expandafter
\expandafter {%
%%%%%\MYSTUFFSepRemove.##2}\relax %<-would preserve
\MYSTUFFBraceRemove##2}\relax % all braces
\fi
\fi
\fi}
}%
\else
\@ifdefinable\MYSTUFF@tokadd{%
\def\MYSTUFF@tokadd#2##1#1#2{%
\toks@\expandafter{\the\toks@##1}%
}%
}%
\@ifdefinable\MYSTUFFOtherSepRemove{%
\def\MYSTUFFOtherSepRemove##1#2\@nil{\@g
obble##1}%
}%
\fi
\expandafter\@ifdefinable\csname#3MYSTUF
F@remtrailspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#3MYSTUFF@remtrailspace\endcsname
##1##2#1#2##3#2#1{%
\begingroup
\toks@{##3}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#3MYSTUFF@remleadspace\endcsname
{##1}#2##2#1#2#2}%
{\csname#3MYSTUFF@remtrailspace\endcsnam
e{##1}##2#2#1#2#2#1}%
}%
}%
\expandafter\@ifdefinable\csname#3MYSTUF
F@remleadspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#3MYSTUFF@remleadspace\endcsname#
#1##2#2#1##3#2#2{%
\begingroup
\toks@{##2}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#3MYSTUFF@remleadspace\endcsname
{##1}#2##3#2#2}%
{##1##2#2#1#2}%
}%
}%
\expandafter\@ifdefinable\csname#3MYSTUF
F@iterate\endcsname{%
\expandafter\long
\expandafter\def
\csname#3MYSTUFF@iterate\endcsname##1##2
#2{%
\begingroup
\toks@{##2}%
\edef\@tempa{\the\toks@}%
\toks@{#1\@nil}%
\edef\@tempb{\the\toks@}%
\expandafter\endgroup\ifx\@tempa\@tempb
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{%
\csname#3MYSTUFF@remtrailspace\endcsname
{##1}##2#2#1#2#2#1%
\csname#3MYSTUFF@iterate\endcsname{##1}#
1%
}%
}%
}%
}%
\DefineMYSTUFF{ }{=}{equal}{\@tempswafalse}%
\DefineMYSTUFF{ }{,}{comma}{\@tempswatrue}%
\newcommand*\MYSTUFFsetkeys[2]{%
\def\KV@prefix{KV@#1@}%
\let\@tempc\relax
{%
\toks@{}%
\equalMYSTUFF@iterate{\MYSTUFF@tokadd} #2=\@nil=%
\toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \space
\expandafter\MYSTUFFOtherSepRemove
\expandafter.%
\the\toks@\@nil}%
%\showthe\toks@
\expandafter}%
\expandafter\commaMYSTUFF@iterate
\expandafter{%
\expandafter\MYSTUFF@splitcall
\expandafter}%
\the\toks@,\@nil,%
}%
\makeatother
\begin{document}
\makeatletter
\newcommand\mytypein[1]{{\def\@inputchec
k{-1}\typein{#1}}}%
\define@key{myfamily}{first}[default]{%
{\@temptokena{#1}\mytypein{first: |\the\@temptokena|}}%
}%
\define@key{myfamily}{second}[default]{%
{\@temptokena{#1}\mytypein{second: |\the\@temptokena|}}%
}%
\makeatother
\mytypein{^^JNow the keys in terms of \string\MYSTUFFsetkeys:}%
\MYSTUFFsetkeys{myfamily}{
first = {test} , first = test , ,
first,second,second = test,
,first={{test}},
third=blebb,
,first={test},
}
\mytypein{^^JNow the keys in terms of \string\setkeys:}%
\setkeys{myfamily}{
first = {test} , first = test , ,
first,second,second = test,
,first={{test}},
third=blebb,
,first={test},
}
\end{document}
Sincerely
Ulrich
| |
| Ulrich Diez 2006-07-24, 7:03 pm |
| Heiko Oberdiek wrote:
> It is a feature. That allows putting commas (or equal signs) into the
> value.
I know. Nonetheless there might arise other requirements...
Ulrich
| |
| Morten Høgholm 2006-07-24, 7:03 pm |
| On Mon, 24 Jul 2006 20:21:22 +0200, Ulrich Diez =
<eu_angelion@web.de.invalid> wrote:
> Lars Madsen wrote:
> ...
l =
[color=darkred]
>
> keyval's "\setkeys"-macro iterates on comma-separated lists of
> key=3Dvalue-pairs and hereby removes spaces which somehow surround
> these key=3Dvalue-pairs.
> As a side-effect, braces get removed from the keys/values also.
> If I got the details right, you can loose e.g., up to 3 brace-
> levels which surround the value in case that the value is not
> surrounded by spaces at all.
> The first brace-pair will be stripped by "\KV@split", the second
> will be stripped by "\KV@@sp@b" and the third will be stripped by
> "\KV@@sp@c".
Yes, in some cases three levels are stripped and it isn't always obvious=
=
just how they are stripped. Try this example:
\documentclass{minimal}
\usepackage{trace,keyval}
% download the expl3 code from our cvs and then try with that bit of
% code activated
\iffalse
\usepackage{l3keyval}
\CodeStart
\def_long:Npn \expsetkeys#1{% just gobble family in this example
\def:Npn \KV_key_value_elt:nn ##1##2{
\def:Npn \tmp:w{##1=3D`##2'} \show \tmp:w
}
\KV_parse_space_removal_no_sanitize:n
}
\let:NN \setkeys \expsetkeys
\CodeStop
\fi
\makeatletter
\define@key{fam}{key}{\def\val{`#1'}\sho
w\val}
\makeatother
\traceon
\setkeys{fam}{
key=3D{{{abc}}},% two stripped
key=3D {{{abc}}},% one stripped
key=3D{{{abc}}} ,% two stripped
key=3D{ {abc}},% two stripped!?
key=3D{ {abc}} ,% one stripped
key=3D { {abc}},% one stripped
key=3D{ {abc} },% two stripped
key=3D{ {{abc}} },% three stripped
key=3D{ {{abc}}},% two stripped
}
\traceoff
\stop
If you follow the trace you will see that the problem lies in the functi=
on =
\KV@split combined with how TeX reads delimited arguments. If you define=
=
\tempa as
\def\tempa !#1!{#1}
then both \tempa!abc! and \tempa!{abc}! will pass on abc as the argument=
: =
the braces are lost immediately. On the other hand \tempa! {abc}! will =
keep the braces. This is why l3keyval I pointed to earlier uses a two-st=
ep =
approach where the key is read first and only afterwards is the value =
added. Carefully, very carefully I might add... :-)
-- =
Morten
| |
| Ulrich Diez 2006-07-24, 7:03 pm |
| Hello!
I close "my efforts" on this subject by presenting the
macro "\DefineSetkeys".
You can use it for defining new "\setkeys"-variants:
\Definesetkeys{<space>}
{<item-separator>}
{<key-val-separator>}
{<Prefix>}
{<indicator for preserving all braces>}
-> defines macro "\<Prefix>setkeys".
In case that <indicator for preserving all braces> = "preserve",
no braces will be removed, in all other cases one brace-level
will be removed from the value. I hope.
The macro grew a bit "monstrous". Perhaps somebody is
interested anyway. Still no warranties as still everything is
"highly experimental".
Regards
Ulrich
\documentclass{minimal}
% keyval-iterators without brace-stripping at the value.
% Derived from labelcas.sty 1.10 on July 24, 2006 by Ulrich Diez.
% LPPL 1.3 or later (at your option).
% !!!!!Highly experimental. No warranties!!!!!
\usepackage{keyval}
\makeatletter
\newcommand\DefineSetkeys[5]{%
\expandafter\@ifdefinable\csname#4@split
call\endcsname{%
\expandafter\def\csname#4@splitcall\endc
sname#2##1#1#2{%
\csname#4@split\endcsname##1#3#3\relax
}%
}%
\expandafter\@ifdefinable\csname#4Sep\en
dcsname{%
\expandafter\def\csname#4Sep\endcsname{#
2}%
}%
\expandafter\@ifdefinable\csname#4SepRem
ove\endcsname{%
\expandafter\def\csname#4SepRemove\endcs
name##1#2{\@gobble##1}%
}%
\expandafter\@ifdefinable\csname#4BraceR
emove\endcsname{%
{\def\@tempa{#5}\def\@tempb{preserve}\ex
pandafter}%
\ifx\@tempa\@tempb
\expandafter\let
\csname#4BraceRemove\expandafter\endcsna
me
\csname#4SepRemove\endcsname
\else
\expandafter\def\csname#4BraceRemove\end
csname.##1#2{##1}%
\fi
}%
\expandafter\@ifdefinable\csname#4@tokad
d\endcsname{%
\expandafter\def\csname#4@tokadd\endcsna
me#3##1#1#3{%
\toks@\expandafter{\the\toks@##1}%
}%
}%
\expandafter\@ifdefinable\csname#4OtherS
epRemove\endcsname{%
\expandafter\def
\csname#4OtherSepRemove\endcsname##1#3\@
nil{\@gobble##1}%
}%
\expandafter\@ifdefinable\csname#4@split
\endcsname{%
\expandafter\def\csname#4@split\endcsnam
e##1#3##2#3##3\relax{%
\KV@toks@{##1}\edef\@tempa{\the\KV@toks@
}%
\expandafter\ifx\csname#4Sep\endcsname\@
tempa\else
\ifx\@empty##3\@empty
\KV@toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\csname#4SepRemove\expandafter\endcsname
\expandafter.%
\the\KV@toks@}%
\edef\@tempa{\the\KV@toks@}%
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\KV@errx
{\@tempa\space undefined}%
\else
\KV@default
\fi
\else
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\KV@errx
{\@tempa\space undefined}%
\else
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \@tempc
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\csname#4BraceRemove\endcsname.##2}\relax
\fi
\fi
\fi}
}%
\begingroup
\newcommand\iteratordefiner[3]{%
\expandafter\@ifdefinable\csname#4##3@re
mtrailspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#4##3@remtrailspace\endcsname####
1####2##1##2####3##2##1{%
\begingroup
\toks@{####3}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#4##3@remleadspace\endcsname{###
#1}##2####2##1##2##2}%
{\csname#4##3@remtrailspace\endcsname{##
##1}####2##2##1##2##2##1}%
}%
}%
\expandafter\@ifdefinable\csname#4##3@re
mleadspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#4##3@remleadspace\endcsname####1
####2##2##1####3##2##2{%
\begingroup
\toks@{####2}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#4##3@remleadspace\endcsname{###
#1}##2####3##2##2}%
{####1####2##2##1##2}%
}%
}%
\expandafter\@ifdefinable\csname#4##3@it
erate\endcsname{%
\expandafter\long
\expandafter\def
\csname#4##3@iterate\endcsname####1####2
##2{%
\begingroup
\toks@{####2}%
\edef\@tempa{\the\toks@}%
\toks@{##1\@nil}%
\edef\@tempb{\the\toks@}%
\expandafter\endgroup\ifx\@tempa\@tempb
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{%
\csname#4##3@remtrailspace\endcsname{###
#1}####2##2##1##2##2##1%
\csname#4##3@iterate\endcsname{####1}##1
%
}%
}%
}%
}%
\toks@{\iteratordefiner{#1}{#2}{comma}}\
edef\@tempa{\the\toks@}%
\toks@{\iteratordefiner{#1}{#3}{equal}}\
edef\@tempb{\the\toks@}%
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \endgroup
\expandafter\expandafter
\expandafter \@tempa
\@tempb
\expandafter\newcommand\csname#4setkeys\
endcsname[2]{%
\def\KV@prefix{KV@##1@}%
\let\@tempc\relax
{%
\toks@{}%
\csname#4equal@iterate%
\expandafter\endcsname
\expandafter{%
\csname#4@tokadd\endcsname}#1##2#3\@nil#
3%
\@temptokena{#1}%
\toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \the
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \@temptokena
\csname#4OtherSepRemove\expandafter\endc
sname
\expandafter.%
\the\toks@\@nil}%
%\showthe\toks@
\expandafter}%
\csname#4comma@iterate\expandafter\endcs
name
\expandafter{%
\csname#4@splitcall\expandafter\endcsnam
e
\expandafter}%
\the\toks@#2\@nil#2%
}%
}%
% \Definesetkeys{<space>}
% {<item-separator>}
% {<key-val-separator>}
% {<Prefix>}
% {<indicator for preserving all braces>}
% -> defines macro "\<Prefix>setkeys".
% In case that <indicator for preserving all braces> = "preserve",
% no braces will be removed, in all other cases one brace-level
% will be removed from the value.
\DefineSetkeys{ }{,}{=}{MY}{}%
\DefineSetkeys{ }{,}{:=}{DOTEQ}{preserve}%
\makeatother
\begin{document}
\makeatletter
\newcommand\mytypein[1]{{\def\@inputchec
k{-1}\typein{#1}}}%
\define@key{myfamily}{first}[default]{%
{\@temptokena{#1}\mytypein{first: |\the\@temptokena|}}%
}%
\define@key{myfamily}{second}[default]{%
{\@temptokena{#1}\mytypein{second: |\the\@temptokena|}}%
}%
\makeatother
\mytypein{^^JNow the keys in terms of \string\setkeys:}%
\setkeys{myfamily}{
first = {test} , first = test , ,
first,second,second = test,
,first={{test}},
third=blebb,
,first={test},
}
\mytypein{^^JNow the keys in terms of \string\MYsetkeys:}%
\MYsetkeys{myfamily}{
first = {test} , first = test , ,
first,second,second = test,
,first={{test}},
third=blebb,
,first={test},
}
\mytypein{^^JNow the keys in terms of \string\DOTEQsetkeys:}%
\DOTEQsetkeys{myfamily}{
first := {test} , first := test , ,
first,second,second := test,
,first:={{test}},
third:=blebb,
,first:={test},
}
\end{document}
| |
| Ulrich Diez 2006-07-25, 4:06 am |
| There is another issue with keyval:
You can define a key the name if which is surrounded by braces.
But you cannot successfully use it in all cases as from the key
bracing-levels get removed also. The amount of bracing-levels
also depends on how the whole thing is surrounded by spaces.
Sometimes you need two additional brace-levels, sometimes you
need three of them. I order to resolve this inconsistency within
my monstrous thing, I decided to try to implement brace-protection
for the key in all cases.
Also I had to resolve an error in the definition of
\<prefix>BraceRemove which would lead to an extra-expansion-step
at the value in case that one brace-level should be stripped from the
key.
\Definesetkeys{<space>}
{<item-separator>}
{<key-val-separator>}
{<Prefix>}
{<indicator for preserving all braces>}
-> defines macro "\<Prefix>setkeys".
In case that <indicator for preserving all braces> = "preserve",
no braces will be removed, in all other cases one brace-level
will be removed from the value. I hope.
Still no warranties as still everything is "highly experimental".
Coffee-break over. Back to work.
Regards
Ulrich
\documentclass{minimal}
% keyval-iterators without brace-stripping at the value.
% Derived from labelcas.sty 1.10 on July 24, 2006 by Ulrich Diez.
% LPPL 1.3 or later (at your option).
% !!!!!Highly experimental. No warranties!!!!!
\usepackage{keyval}
\makeatletter
\newcommand\DefineSetkeys[5]{%
\expandafter\@ifdefinable\csname#4@split
call\endcsname{%
\expandafter\def\csname#4@splitcall\endc
sname#2##1#1#2{%
\csname#4@split\endcsname.##1#3#3\relax
}%
}%
\expandafter\@ifdefinable\csname#4Sep\en
dcsname{%
\expandafter\def\csname#4Sep\endcsname{#
2}%
}%
\expandafter\@ifdefinable\csname#4SepRem
ove\endcsname{%
\expandafter\def\csname#4SepRemove\endcs
name##1#2{\@gobble##1}%
}%
\expandafter\@ifdefinable\csname#4BraceR
emove\endcsname{%
{\def\@tempa{#5}\def\@tempb{preserve}\ex
pandafter}%
\ifx\@tempa\@tempb
\expandafter\let
\csname#4BraceRemove\expandafter\endcsna
me
\csname#4SepRemove\endcsname
\else
\expandafter\def\csname#4BraceRemove\end
csname.##1#2{\@empty##1}%
\fi
}%
\expandafter\@ifdefinable\csname#4@tokad
d\endcsname{%
\expandafter\def\csname#4@tokadd\endcsna
me#3##1#1#3{%
\toks@\expandafter{\the\toks@##1}%
}%
}%
\expandafter\@ifdefinable\csname#4OtherS
epRemove\endcsname{%
\expandafter\def
\csname#4OtherSepRemove\endcsname##1#3\@
nil{\@gobble##1}%
}%
\expandafter\@ifdefinable\csname#4@split
\endcsname{%
\expandafter\def\csname#4@split\endcsnam
e##1#3##2#3##3\relax{%
\KV@toks@\expandafter{\@gobble##1}\edef\
@tempa{\the\KV@toks@}%
\expandafter\ifx\csname#4Sep\endcsname\@
tempa\else
\ifx\@empty##3\@empty
\KV@toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\csname#4SepRemove\expandafter\endcsname
\expandafter.%
\the\KV@toks@}%
\edef\@tempa{\the\KV@toks@}%
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\KV@errx
{\@tempa\space undefined}%
\else
\KV@default
\fi
\else
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\KV@errx
{\@tempa\space undefined}%
\else
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \@tempc
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\csname#4BraceRemove\endcsname.##2}\relax
\fi
\fi
\fi}
}%
\begingroup
\newcommand\iteratordefiner[3]{%
\expandafter\@ifdefinable\csname#4##3@re
mtrailspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#4##3@remtrailspace\endcsname####
1####2##1##2####3##2##1{%
\begingroup
\toks@{####3}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#4##3@remleadspace\endcsname{###
#1}##2####2##1##2##2}%
{\csname#4##3@remtrailspace\endcsname{##
##1}####2##2##1##2##2##1}%
}%
}%
\expandafter\@ifdefinable\csname#4##3@re
mleadspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#4##3@remleadspace\endcsname####1
####2##2##1####3##2##2{%
\begingroup
\toks@{####2}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#4##3@remleadspace\endcsname{###
#1}##2####3##2##2}%
{####1####2##2##1##2}%
}%
}%
\expandafter\@ifdefinable\csname#4##3@it
erate\endcsname{%
\expandafter\long
\expandafter\def
\csname#4##3@iterate\endcsname####1####2
##2{%
\begingroup
\toks@{####2}%
\edef\@tempa{\the\toks@}%
\toks@{##1\@nil}%
\edef\@tempb{\the\toks@}%
\expandafter\endgroup\ifx\@tempa\@tempb
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{%
\csname#4##3@remtrailspace\endcsname{###
#1}####2##2##1##2##2##1%
\csname#4##3@iterate\endcsname{####1}##1
%
}%
}%
}%
}%
\toks@{\iteratordefiner{#1}{#2}{comma}}\
edef\@tempa{\the\toks@}%
\toks@{\iteratordefiner{#1}{#3}{equal}}\
edef\@tempb{\the\toks@}%
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \endgroup
\expandafter\expandafter
\expandafter \@tempa
\@tempb
\expandafter\newcommand\csname#4setkeys\
endcsname[2]{%
\def\KV@prefix{KV@##1@}%
\let\@tempc\relax
{%
\toks@{}%
\csname#4equal@iterate%
\expandafter\endcsname
\expandafter{%
\csname#4@tokadd\endcsname}#1##2#3\@nil#
3%
\@temptokena{#1}%
\toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \the
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \@temptokena
\csname#4OtherSepRemove\expandafter\endc
sname
\expandafter.%
\the\toks@\@nil}%
%\showthe\toks@
\expandafter}%
\csname#4comma@iterate\expandafter\endcs
name
\expandafter{%
\csname#4@splitcall\expandafter\endcsnam
e
\expandafter}%
\the\toks@#2\@nil#2%
}%
}%
% \Definesetkeys{<space>}
% {<item-separator>}
% {<key-val-separator>}
% {<Prefix>}
% {<indicator for preserving all braces>}
% -> defines macro "\<Prefix>setkeys".
% In case that <indicator for preserving all braces> = "preserve",
% no braces will be removed, in all other cases one brace-level
% will be removed from the value.
\DefineSetkeys{ }{,}{=}{MY}{}%
\DefineSetkeys{ }{,}{:=}{DOTEQ}{preserve}%
\makeatother
\begin{document}
\makeatletter
\newcommand\mytypein[1]{{\def\@inputchec
k{-1}\typein{#1}}}%
\define@key{myfamily}{first}[default]{%
{\@temptokena{#1}\mytypein{first: |\the\@temptokena|}}%
}%
\define@key{myfamily}{second}[default]{%
{\@temptokena{#1}\mytypein{second: |\the\@temptokena|}}%
}%
\define@key{myfamily}{{third}}[default]{
%
{\@temptokena{#1}\mytypein{{third}: |\the\@temptokena|}}%
}%
\makeatother
\mytypein{^^JNow the keys in terms of \string\setkeys:}%
\setkeys{myfamily}{first = \TeX,
first = {test} , first = test , ,
first,second,second = test,
,first={{test}},
third=blebb,
{third}=blebb,
{third},
,first={test},
}
\mytypein{^^JNow the keys in terms of \string\MYsetkeys:}%
\MYsetkeys{myfamily}{first = \TeX,
first = {test} , first = test , ,
first,second,second = test,
,first={{test}},
third=blebb,
{third}={blebb},
{third},
,first={test},
}
\mytypein{^^JNow the keys in terms of \string\DOTEQsetkeys:}%
\DOTEQsetkeys{myfamily}{first := \TeX,
first := {test} , first := test , ,
first,second,second := test,
,first:={{test}},
third:= blebb,
{third}:={blebb},
{third},
,first:={test},
}
\end{document}
| |
| Lars Madsen 2006-07-25, 8:03 am |
| Lars Madsen wrote:
>
>
> but you are of course right that when ever we are dealing with single
> words, then using a komma separated list might be an easier syntax
>
so now it does both (pretty fast actually)
using some code from Morten (to fix the problem mentioned here) it can now handle
index={env:align,sty:amsmath,:intertext,
mem;idxbf:firmlist,cls:memoir}%
{some text}{env:center}{sty:inputenc}
since most entries are just single words the comma separated syntax is a lot
faster to use (realized that yesterday while cleaning up code code, also used
for indexing but much more horrible syntax)
--
/daleif (remove RTFSIGNATURE from email address)
LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
| |
| Ulrich Diez 2006-07-28, 7:05 pm |
| Maybe it's going to be ridiculous but there were two more
issues:
1. An undesired space somewhere in the code.
(percent-char added.)
2. You may wish to specify some "interesting values"
like "\ifx\foo\bar".
With keyval's \setkeys this is not possible.
I altered the definition of \csname#4@split\endcsname so
that defining takes place by means of \edef and
token-registers and forking takes place in terms
of \@firstoftwo/\@secondoftwo.
Ulrich
\documentclass{minimal}
% keyval-iterators without brace-stripping at the value.
% Derived from labelcas.sty 1.10 on July 25, 2006 by Ulrich Diez.
% LPPL 1.3 or later (at your option).
% !!!!!Highly experimental. No warranties!!!!!
\usepackage{keyval}
\makeatletter
\newcommand\DefineSetkeys[5]{%
\expandafter\@ifdefinable\csname#4@split
call\endcsname{%
\expandafter\long
\expandafter\def
\csname#4@splitcall\endcsname#2##1#1#2{%
\csname#4@split\endcsname.##1#3#3\relax
}%
}%
\expandafter\@ifdefinable\csname#4Sep\en
dcsname{%
\expandafter\def
\csname#4Sep\endcsname{#2}%
}%
\expandafter\@ifdefinable\csname#4SepRem
ove\endcsname{%
\expandafter\long
\expandafter\def
\csname#4SepRemove\endcsname##1#2{\@gobb
le##1}%
}%
\expandafter\@ifdefinable\csname#4BraceR
emove\endcsname{%
{\def\@tempa{#5}\def\@tempb{preserve}\ex
pandafter}%
\ifx\@tempa\@tempb
\expandafter\let
\csname#4BraceRemove\expandafter\endcsna
me
\csname#4SepRemove\endcsname
\else
\expandafter\long
\expandafter\def
\csname#4BraceRemove\endcsname.##1#2{\@empty##1}%
\fi
}%
\expandafter\@ifdefinable\csname#4@tokad
d\endcsname{%
\expandafter\long
\expandafter\def
\csname#4@tokadd\endcsname#3##1#1#3{%
\toks@\expandafter{\the\toks@##1}%
}%
}%
\expandafter\@ifdefinable\csname#4OtherS
epRemove\endcsname{%
\expandafter\long
\expandafter\def
\csname#4OtherSepRemove\endcsname##1#3\@
nil{\@gobble##1}%
}%
\expandafter\@ifdefinable\csname#4@split
\endcsname{%
\expandafter\long
\expandafter\def
\csname#4@split\endcsname##1#3##2#3##3\r
elax{%
\KV@toks@\expandafter{\@gobble##1}\edef\
@tempa{\the\KV@toks@}%
\expandafter\ifx\csname#4Sep\endcsname\@
tempa
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{%
{\toks@{##3}\edef\@tempa{\the\toks@}\exp
andafter}%
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{%
\KV@toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\csname#4SepRemove\expandafter\endcsname
\expandafter.%
\the\KV@toks@}%
\edef\@tempa{\the\KV@toks@}%
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\expandafter\@firstowtwo
\else
\expandafter\@secondoftwo
\fi
{%
\KV@errx
{\@tempa\space undefined}%
}%
{\KV@default}%
}%
{%
\expandafter\let\expandafter\@tempc
\csname\KV@prefix\@tempa\endcsname
\ifx\@tempc\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\KV@errx{\@tempa\space undefined}}%
{\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \@tempc
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\csname#4BraceRemove\endcsname.##2}\relax
}%
}%
}%
}%
}%
\begingroup
\newcommand\iteratordefiner[3]{%
\expandafter\@ifdefinable\csname#4##3@re
mtrailspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#4##3@remtrailspace\endcsname####
1####2##1##2####3##2##1{%
\begingroup
\toks@{####3}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#4##3@remleadspace\endcsname{###
#1}##2####2##1##2##2}%
{\csname#4##3@remtrailspace\endcsname{##
##1}####2##2##1##2##2##1}%
}%
}%
\expandafter\@ifdefinable\csname#4##3@re
mleadspace\endcsname{%
\expandafter\long
\expandafter\def
\csname#4##3@remleadspace\endcsname####1
####2##2##1####3##2##2{%
\begingroup
\toks@{####2}%
\edef\@tempa{\the\toks@}%
\expandafter\endgroup
\ifx\@tempa\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\csname#4##3@remleadspace\endcsname{###
#1}##2####3##2##2}%
{####1####2##2##1##2}%
}%
}%
\expandafter\@ifdefinable\csname#4##3@it
erate\endcsname{%
\expandafter\long
\expandafter\def
\csname#4##3@iterate\endcsname####1####2
##2{%
\begingroup
\toks@{####2}%
\edef\@tempa{\the\toks@}%
\toks@{##1\@nil}%
\edef\@tempb{\the\toks@}%
\expandafter\endgroup\ifx\@tempa\@tempb
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{%
\csname#4##3@remtrailspace\endcsname{###
#1}####2##2##1##2##2##1%
\csname#4##3@iterate\endcsname{####1}##1
%
}%
}%
}%
}%
\toks@{\iteratordefiner{#1}{#2}{comma}}\
edef\@tempa{\the\toks@}%
\toks@{\iteratordefiner{#1}{#3}{equal}}\
edef\@tempb{\the\toks@}%
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \endgroup
\expandafter\expandafter
\expandafter \@tempa
\@tempb
\expandafter\newcommand\csname#4setkeys\
endcsname[2]{%
\def\KV@prefix{KV@##1@}%
\let\@tempc\relax
{%
\toks@{}%
\csname#4equal@iterate%
\expandafter\endcsname
\expandafter{%
\csname#4@tokadd\endcsname}#1##2#3\@nil#
3%
\@temptokena{#1}%
\toks@\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter {%
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \the
\expandafter\expandafter
\expandafter \expandafter
\expandafter\expandafter
\expandafter \@temptokena
\csname#4OtherSepRemove\expandafter\endc
sname
\expandafter.%
\the\toks@\@nil}%
%\showthe\toks@
\expandafter}%
\csname#4comma@iterate\expandafter\endcs
name
\expandafter{%
\csname#4@splitcall\expandafter\endcsnam
e
\expandafter}%
\the\toks@#2\@nil#2%
}%
}%
% \Definesetkeys{<space>}
% {<item-separator>}
% {<key-val-separator>}
% {<Prefix>}
% {<indicator for preserving all braces>}
% -> defines macro "\<Prefix>setkeys".
% In case that <indicator for preserving all braces> = "preserve",
% no braces will be removed, in all other cases one brace-level
% will be removed from the value.
\DefineSetkeys{ }{,}{=}{MY}{}%
\DefineSetkeys{ }{,}{:=}{DOTEQ}{preserve}%
\makeatother
\begin{document}
\makeatletter
\newcommand\mytypein[1]{{\def\@inputchec
k{-1}\typein{#1}}}%
\define@key{myfamily}{first}[default]{%
{\@temptokena{#1}\mytypein{first: |\the\@temptokena|}}%
}%
\define@key{myfamily}{second}[default]{%
{\@temptokena{#1}\mytypein{second: |\the\@temptokena|}}%
}%
\define@key{myfamily}{{third}}[default]{
%
{\@temptokena{#1}\mytypein{{third}: |\the\@temptokena|}}%
}%
\makeatother
\mytypein{^^JNow the keys in terms of \string\setkeys:}%
\setkeys{myfamily}{first = \TeX{},
first = {test} , first = test , ,
first,second,second = test,
,first={{test}},
third=blebb,
{third}=blebb,
{third},
,first={test},
% ,first=\if aa \else
}
\mytypein{^^JNow the keys in terms of \string\MYsetkeys:}%
\MYsetkeys{myfamily}{first = \TeX{},
first = {test} , first = test , ,
first,second,second = test,
,first={{test}},
third=blebb,
{third}={blebb},
{third},
,first={test},
,first=\if aa \else
}
\mytypein{^^JNow the keys in terms of \string\DOTEQsetkeys:}%
\DOTEQsetkeys{myfamily}{first := \TeX{},
first := {test} , first := test , ,
first,second,second := test,
,first:={{test}},
third:= blebb,
{third}:={blebb},
{third},
,first:={test},
,first:=\if aa \else
}
\end{document}
|
|
|
|
|