根据文档,
⟨key⟩ .inherit:n = {⟨parents⟩}
Specifies that the ⟨key⟩ path should inherit the keys listed as ⟨parents⟩.
因为许多父母都聚集在一起\l_MY_parents_clist
,我会受益于
⟨key⟩ .inherit:V = \l_MY_parents_clist,
不幸的是,.inherit:V
密钥变体不存在,我该怎么办?
下面是一个工作代码,它使用辅助函数从头开始创建一个 keyval 列表,并使用辅助变量来存储它。有没有更高效的方法?
% !TeX program = lualatex
\documentclass{article}
\begin{document}
\noindent
\ExplSyntaxOn
\clist_set:Nn \l_tmpa_clist { parent, grand_parent }
\cs_set:Npn \MY_helper:Nn #1 #2 {
\tl_put_right:Nn #1 {
child .inherit:n = { #2 },
}
}
\tl_clear:N \l_tmpa_tl
\exp_args:NNV
\MY_helper:Nn \l_tmpa_tl \l_tmpa_clist
\exp_args:NnV
\keys_define:nn { } \l_tmpa_tl
TESTING:\\
\keys_define:nn { parent } {
test .code:n = TEST: #1\\,
}
\keys_set:nn { child } {
test = blah,
}
\keys_define:nn { grand_parent } {
grand-test .code:n = GRAND-TEST: #1\\,
}
\keys_set:nn { child } {
grand-test = blah,
}
\end{document}
答案1
你可以将其构造得更像
\documentclass{article}
\begin{document}
\ExplSyntaxOn
\clist_set:Nn \l_tmpa_clist { parent, grand_parent }
\cs_set:Npn \MY_helper:nnn #1 #2 #3 {
\keys_define:nn { #1 } {#2 .inherit:n = { #3 }}
}
\cs_generate_variant:Nn \MY_helper:nnn {nnV}
\MY_helper:nnV {} {child} \l_tmpa_clist
TESTING:\\
\keys_define:nn { parent } {
test .code:n = TEST: #1\\,
}
\keys_set:nn { child } {
test = blah,
}
\keys_define:nn { grand_parent } {
grand-test .code:n = GRAND-TEST: #1\\,
}
\keys_set:nn { child } {
grand-test = blah,
}
\end{document}