![解析已知键,存储未知的 key=val 对以供以后使用](https://linux22.com/image/416296/%E8%A7%A3%E6%9E%90%E5%B7%B2%E7%9F%A5%E9%94%AE%EF%BC%8C%E5%AD%98%E5%82%A8%E6%9C%AA%E7%9F%A5%E7%9A%84%20key%3Dval%20%E5%AF%B9%E4%BB%A5%E4%BE%9B%E4%BB%A5%E5%90%8E%E4%BD%BF%E7%94%A8.png)
我对 expl3 语法还不熟悉,无法让它正常工作。我想将已知键的值放入变量中,但保留未知对以供以后使用,例如在将几个不同的包函数合并为一个的文档命令中使用,我该怎么做?
最小(非)工作示例
\documentclass{article}
\usepackage{expl3,xparse}
\ExplSyntaxOn
% Declare
\tl_new:N \l__mymod_keyi_tl
\seq_new:N \l_mymod_keyvalue_seq
% Define
\keys_define:nn { mymod } {
keyi .tl_set:N = \l__mymod_keyi_tl,
otherKeys .code:n = \mymod_store:Vn \l_keys_key_tl {#1},
}
\cs_new_protected:Nn \mymod_store:nn {
\seq_put_right:Nn \l_mymod_keyvalue_seq {#1~=~{#2},}
}
\cs_generate_variant:Nn \mymod_store:nn { V }
% Setter
\NewDocumentCommand{\setkeys}{m} {
\keys_set:nn { mymod } { #1 }
}
% Getter i
\NewExpandableDocumentCommand\printkeyi{} {
\text_expand:n{
\l__mymod_keyi_tl
}
}
% Usage here
% \NewDocumentCommand{\fun}{m} {
% \fun1{ keyName = \text_expand:n {\l__mymod_keyi_tl} }
% \fun2{ \otherKeys or \printkeys or whatever} % keyi should NOT be among them
% }
% Getter rest
\NewExpandableDocumentCommand\printkeys{} {
\seq_use:Nn \l_mymod_keyvalue_seq {,~}
}
\ExplSyntaxOff
\begin{document}
A few words
\setkeys{keyi = 3, keyii = 4, keyiii = 5}
another few
\printkeys
\end{document}
这里
答案1
unknown 是一个关键字。