我想用 l3keys 定义一个选择键,它还存储赋予该键的值。这很容易:
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\tl_new:N \curmykey
\keys_define:nn { my }
{
mykey .choice:,
mykey /choice-a .code:n ={\tl_set:Nn\curmykey{#1}spezific~code~for~a},
mykey /choice-b .code:n ={\tl_set:Nn\curmykey{#1}spezific~code~for~b},
}
\ExplSyntaxOff
\begin{document}
\ExplSyntaxOn
\keys_set:nn{my}{mykey=choice-a,},~\curmykey
\ExplSyntaxOff
\end{document}
但我发现在所有代码参数中复制这个方法不太优雅\tl_set:Nn\curmykey{#1}
。有没有办法只在一个地方定义 \curmykey?(我已经尝试过了,mykey .tl_set:N
但这会破坏选择代码。)
答案1
\keys_define:nn { my }
{
mykey .code:n =
\tl_set_eq:NN \curmykey \l_keys_value_tl \keys_set:nn { my } { mykeyaux = #1 } ,
mykeyaux .choice: ,
mykeyaux / choice-a .code:n = { spezific ~ code ~ for ~ a } ,
mykeyaux / choice-b .code:n = { spezific ~ code ~ for ~ b } ,
}