我想检索 expl3 变量的内容,例如属性列表的值。变量名可以包含特殊字符,因此它应该适用于 c 类型。我可以这样做:
\documentclass[]{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\tl_new:c {l_uf_some!special!name_tl }
\tl_set:cn{l_uf_some!special!name_tl }{special \blub abc }
\tl_new:N \l_uf_some_tl
\tl_set:Nn\l_uf_some_tl {xxx\blub abc }
\prop_new:N \l_uf_some_prop
\prop_put:Nnx\l_uf_some_prop {some} { some~text~\exp_args:No \exp_not:n { \l_uf_some_tl } }
\prop_put:Nnx\l_uf_some_prop {somespecial} { some~text~\exp_args:Nc \exp_not:o { l_uf_some!special!name_tl } }
\prop_show:N \l_uf_some_prop
\ExplSyntaxOff
\end{document}
终端上输出的正是我想要的内容:
The property list \l_uf_some_prop contains the pairs (without outer braces):
> {some} => {some text xxx\blub abc}
> {somespecial} => {some text special\blub abc}.
\exp_args:No \exp_not:n
但我对/不太满意\exp_args:Nc \exp_not:o
。在我写之前,\uf_get_tl:N/c
有没有更好的内置功能是我至今都未注意到的?
答案1
要访问(tl-)的内容五可变的,而不是 经验与其配合,您可以使用。与 -types\exp_not:V
等同的是-type 参数:c
V
v
\documentclass[]{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\tl_new:c {l_uf_some!special!name_tl }
\tl_set:cn{l_uf_some!special!name_tl }{special \blub abc }
\tl_new:N \l_uf_some_tl
\tl_set:Nn\l_uf_some_tl {xxx\blub abc }
\prop_new:N \l_uf_some_prop
\prop_put:Nnx\l_uf_some_prop {some} { some~text~\exp_not:V\l_uf_some_tl }
\prop_put:Nnx\l_uf_some_prop {somespecial} { some~text~\exp_not:v{ l_uf_some!special!name_tl } }
\prop_show:N \l_uf_some_prop
\ExplSyntaxOff
\end{document}
输出:
The property list \l_uf_some_prop contains the pairs (without outer braces):
> {some} => {some text xxx\blub abc}
> {somespecial} => {some text special\blub abc}.