如何将文档输入流中的 LaTeX3 序列元素大写?我认为问题\seq_item:N
在于它不可扩展。
\documentclass{article}
\ExplSyntaxOn
\seq_new:N \g_syllabus_kafname_seq
\NewDocumentCommand\kafname{ m }
{
\seq_gput_right:Nn \g_syllabus_kafname_seq { #1 }
}
\NewDocumentCommand{\thekaf}{ O{1} }
{
\seq_item:Nn \g_syllabus_kafname_seq { #1 }
}
\NewDocumentCommand \firstcap { m } { \text_titlecase:n {#1} }
\ExplSyntaxOff
\begin{document}
\kafname{aass}
\kafname{bbb}
\kafname{ccc}
\firstcap{\thekaf[2]} %Need Bbb
\end{document}
答案1
您可以将格式化命令放在 \thekaf 命令中:
\documentclass{article}
\ExplSyntaxOn
\seq_new:N \g_syllabus_kafname_seq
\NewDocumentCommand\kafname{ m }
{
\seq_gput_right:Nn \g_syllabus_kafname_seq { #1 }
}
\cs_new:Npn \__syllabus_kaf_format:n {}
\NewDocumentCommand{\thekaf}{ O{1} }
{
\__syllabus_kaf_format:n
{\seq_item:Nn \g_syllabus_kafname_seq { #1 }}
}
\NewDocumentCommand \firstcap { m } {
\group_begin:
\cs_set_eq:NN \__syllabus_kaf_format:n\text_titlecase:n
#1
\group_end:
}
\ExplSyntaxOff
\begin{document}
\kafname{aass}
\kafname{bbb}
\kafname{ccc}
\thekaf[2], \firstcap{\thekaf[2]} %Need Bbb
\end{document}