我有以下 MWE:
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{expl3}
\usepackage{xparse}
\ExplSyntaxOn
\begin{document}
\keys_define:nn { examplea } {
foo .tl_set:N = \l_examplea_foo_tl,
baz .tl_set:N = \l_examplea_baz_tl
}
\NewDocumentCommand\examplea{m}{
% \group_begin:
\keys_set:nn { examplea } { #1 }
\typeout{\l_examplea_foo_tl}
\typeout{\l_examplea_baz_tl}
\prop_put:Nnn \my:ns {foo} { \exp_after:wN \l_examplea_foo_tl }
\prop_put:Nnn \my:ns {baz} { \l_examplea_baz_tl }
% \group_end:
}
\prop_new:N \my:ns
\examplea{foo=bar,baz=asdf}
\prop_show:N {\my:ns}
\end{document}
它输出了一些有用的东西,所以我们知道它至少得到了值。然而它也有错误:
bar
asdf
The property list \my:ns contains the pairs (without outer braces):
> {foo} => {\exp_after:wN \l_examplea_foo_tl }
> {baz} => {\l_examplea_baz_tl }.
<recently read> }
l.32 \prop_show:N {\my:ns}
?
(./index.aux) )
No pages of output.
Transcript written on index.log.
Error 1
实际上,我认为错误可能只是由 引起的\prop_show:N {\my:ns}
。无论如何
问题是,如何扩展变量\l_examplea_foo_tl
,\l_examplea_baz_tl
以便记录以下内容:
The property list \my:ns contains the pairs (without outer braces):
> {foo} => {bar}
> {baz} => {asdf}.
或者如果它应该像这样工作,并且扩展应该在通过键获取值时完成,那么这将有助于理解如何做。
答案1
您想存储价值标记列表变量:
\documentclass[a4paper]{article}
\usepackage{expl3}
\usepackage{xparse}
\ExplSyntaxOn
\begin{document}
\keys_define:nn { examplea }
{
foo .tl_set:N = \l_examplea_foo_tl,
baz .tl_set:N = \l_examplea_baz_tl
}
\NewDocumentCommand\examplea{m}
{
\keys_set:nn { examplea } { #1 }
\typeout{\l_examplea_foo_tl}
\typeout{\l_examplea_baz_tl}
\prop_put:NnV \l_examplea_main_prop {foo} \l_examplea_foo_tl
\prop_put:NnV \l_examplea_main_prop {baz} \l_examplea_baz_tl
}
\prop_new:N \l_examplea_main_prop
\examplea{foo=bar,baz=asdf}
\prop_show:N \l_examplea_main_prop
\end{document}
请注意变量的正确命名。这是控制台输出:
bar
asdf
The property list \l_examplea_main_prop contains the pairs (without outer braces):
> {foo} => {bar}
> {baz} => {asdf}.