Here's a little code where the key-value allowed by the macro is an unwanted feature : for example, single[both = OK, only = KO]
doesn't give any error as I'd hoped. But on the other hand, I would also like to eat this kind of unwanted keys: see the call of \single
inside \both
. Concretely, I would like to use \single
options when calling \both
, but also allows more options from \both
.
\documentclass{article}
\ExplSyntaxOn
\tl_new:N \l_mbc_both_tl
\tl_new:N \l_mbc_only_tl
\keys_define:nn { strict-mode } {
both .tl_set:N = \l_mbc_both_tl,
both .groups:n = { single-use },
only .tl_set:N = \l_mbc_only_tl,
only .groups:n = { both-use },
}
\NewDocumentCommand{\single}{ O{} }{
\group_begin:
\keys_set_groups:nnn { strict-mode }
{ single-use }
{ #1 }
Single used...
\group_end:
}
\NewDocumentCommand{\both}{ O{} }{
\group_begin:
\keys_set:nn { strict-mode } { #1 }
Both used... ~ \single[#1]
\group_end:
}
\ExplSyntaxOff
\begin{document}
\single[both = OK]
\single[both = OK, only = KO]
\single[after = math KO]
\both[both = OK]
\both[both = OK, only = OK]
\both[after = math OK]
\end{document}
Is there a way of defining sub-keys that are only allowed for one environment?
\both
allows all the keys and\single
processes only a subset. I'm not sure what you want to do, because I thought that's what you were aiming for. (But I'm also not clear what is supposed to be done with the values or whatafter
is meant to do?){ mypkg / strict~mode / single }
and the other as{ mypkg / strict-mode / both }
. Set normally for\single
. Set defined for\both
and catch the residue, then set the residue againstsingle
. That way anything not in the first set will generate an error for\single
and anything not in either will generate an error for\both
.