提出这个问题时很明显,逗号分隔列表的长度严重影响了编译速度\ReferencedID
。这是从文本中收集的标签列表。但这个列表可能包含重复项,事实上,在我的问题示例中确实如此。那么,如何从逗号分隔的列表中删除重复项?
为了具体起见,我的例子列表如下:
\gdef \ReferencedIDs{,2014.11.14,2014.11.14,2014.11.17,2014.11.14,2014.07.18.tm,2014.11.12.tm,2013.10.05.kanjur,2013.10.05.powai,2013.10.06,2013.10.28.zhm,2013.10.17,2013.10.22,2013.10.14.ks,2013.10.06,2013.10.17,2013.10.22,2013.10.24,2013.10.28,2013.10.30,2013.11.11,2014.09.05.tm,2014.07.18.tm,2014.11.12.tm,2014.11.17,2015.01.06,2015.01.06}
答案1
假设\ReferencedIDs
已经形成以逗号分隔的列表,你可以组合我在除非直接将字符串作为参数给出,否则 seqsplit 不起作用
\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{seqsplit}
\usepackage{xparse}
\ExplSyntaxOn
\cs_set_eq:NN \faheem_seqsplit:n \seqsplit
\cs_generate_variant:Nn \faheem_seqsplit:n { V }
\clist_new:N \l_faheem_referenced_ids_clist
\NewDocumentCommand{\printIDs}{s}
{
\clist_set:NV \l_faheem_referenced_ids_clist \ReferencedIDs
\IfBooleanF{#1}
{ \clist_remove_duplicates:N \l_faheem_referenced_ids_clist }
\faheem_seqsplit:V \l_faheem_referenced_ids_clist
}
\ExplSyntaxOff
\def\ReferencedIDs{,2014.11.14,2014.11.14,2014.11.17,2014.11.14,2014.07.18.tm,%
2014.11.12.tm,2013.10.05.kanjur,2013.10.05.powai,2013.10.06,2013.10.28.zhm,%
2013.10.17,2013.10.22,2013.10.14.ks,2013.10.06,2013.10.17,2013.10.22,2013.10.24,%
2013.10.28,2013.10.30,2013.11.11,2014.09.05.tm,2014.07.18.tm,2014.11.12.tm,%
2014.11.17,2015.01.06,2015.01.06}
\begin{document}
This is the original list with duplicates, \printIDs*
Here is the list with duplicates removed, \printIDs
\end{document}
答案2
感谢 Joseph Wright 向我展示了如何使用 来实现这一点expl3
。以下代码基本上是不言自明的。删除重复项的行是
\clist_remove_duplicates:N \l_ReferencedIDs
有关文档,请interface3.pdf
至少参阅在 TeX Live 上找到的文件texdoc interface3
。
\documentclass[12pt]{article}
\usepackage{seqsplit}
\usepackage{expl3}
\usepackage[T1]{fontenc}
\let\oldseqsplit\seqsplit% Copy \seqsplit
\renewcommand{\seqsplit}{% Redefine \seqsplit to...
\expandafter\oldseqsplit\expandafter}% ...expand its argument before processing it
\gdef \ReferencedIDs{,2014.11.14,2014.11.14,2014.11.17,2014.11.14,2014.07.18.tm,2014.11.12.tm,2013.10.05.kanjur,2013.10.05.powai,2013.10.06,2013.10.28.zhm,2013.10.17,2013.10.22,2013.10.14.ks,2013.10.06,2013.10.17,2013.10.22,2013.10.24,2013.10.28,2013.10.30,2013.11.11,2014.09.05.tm,2014.07.18.tm,2014.11.12.tm,2014.11.17,2015.01.06,2015.01.06}
\ExplSyntaxOn
\clist_set:NV \l_ReferencedIDs \ReferencedIDs % initialise list
\clist_remove_duplicates:N \l_ReferencedIDs % remove duplicates
\gdef \DeduplicatedReferencedIDs{\l_ReferencedIDs}
\ExplSyntaxOff
\begin{document}
This is the original list with duplicates, \seqsplit{\ReferencedIDs}.
Here is the list with duplicates removed, \seqsplit{\DeduplicatedReferencedIDs}.
\end{document}
注意:\seqsplit{\DeduplicatedReferencedIDs}
没有正确包装;我不知道为什么。