我创建了一个全局列表,并将4, 300
两个元素分配给它。\clist_count:N
显示其 2 个元素。如果我将此列表复制到本地列表,新列表的内容相同,但\clist_count:N
仅显示 1 个元素。这是为什么?
\documentclass{scrlttr2}
\ExplSyntaxOn
\clist_clear_new:N \g__timelist_median_clist
\clist_new:N \l__timelist_median_clist
\NewDocumentCommand{\setlist}{m}
{
\clist_gset:Nn \g__timelist_median_clist { #1 }
}
\NewDocumentCommand{\showlist}{}
{
% set a comma separated list
\clist_set:Nn \l__timelist_median_clist { \g__timelist_median_clist }
g__timelist_median_clist:\ \clist_use:Nn \g__timelist_median_clist {,}\\
count:\ \clist_count:N \g__timelist_median_clist\\
l__timelist_median_clist:\ \clist_use:Nn \l__timelist_median_clist {,}\\
count:\ \clist_count:N \l__timelist_median_clist\\
}
\ExplSyntaxOff
\begin{document}
\setlist{4,300}
\showlist
\end{document}
答案1
添加调试消息:
\documentclass{scrlttr2}
\ExplSyntaxOn
\clist_clear_new:N \g__timelist_median_clist
\clist_new:N \l__timelist_median_clist
\NewDocumentCommand{\setlist}{m}
{
\clist_gset:Nn \g__timelist_median_clist { #1 }
}
\NewDocumentCommand{\showlist}{}
{
% set a comma separated list
\clist_set:Nn \l__timelist_median_clist { \g__timelist_median_clist }
g__timelist_median_clist:\ \clist_use:Nn \g__timelist_median_clist {,}\\
count:\ \clist_count:N \g__timelist_median_clist\\
l__timelist_median_clist:\ \clist_use:Nn \l__timelist_median_clist {,}\\
count:\ \clist_count:N \l__timelist_median_clist\\
\clist_show:N\l__timelist_median_clist
\clist_show:N\g__timelist_median_clist
}
\ExplSyntaxOff
\begin{document}
\setlist{4,300}
\showlist
\end{document}
然后你就会看到
The comma list \l__timelist_median_clist contains the items (without outer
braces):
> {\g__timelist_median_clist }.
和
The comma list \g__timelist_median_clist contains the items (without outer
braces):
> {4}
> {300}.
因为\clist_set:Nn \l__timelist_median_clist { \g__timelist_median_clist }
不会复制 2 个元素的列表,所以它会为全局列表创建一个由 csname 标记组成的新的 1 项列表。
你要\clist_set_eq:NN