我尝试制作一个引用列表,可用于xstring
。以下是 MWE:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xstring}
\makeatletter
\NewDocumentCommand{\citelist}{m}
{%
\@for\citeitem:={#1}\do{\@nameuse{b@\citeitem}, }%
}
\makeatother
\begin{document}
`\citelist{a,b}'
\StrChar{\citelist{a,b}}{1}[\temp]
`\meaning\temp' (instead of `macro:->A')
\begin{thebibliography}{A}
\bibitem[A]{a} A
\bibitem[B]{b} B
\end{thebibliography}
\end{document}
不幸的\citelist
是 不适用于\StrChar
。我该怎么办?
答案1
\@for
使用不可扩展的赋值。递归定义应该可行。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xstring}
\makeatletter
\newcommand{\citelist}[1]{\@citelist#1,\relax,}
\newcommand*{\@citelist}{}% better safe than sorry
\def\@citelist#1,{\ifx#1\relax\else\@nameuse{b@#1}, \expandafter\@citelist\fi}%
\makeatother
\begin{document}
`\citelist{a,b}'
\StrChar{\citelist{a,b}}{1}[\temp]
`\meaning\temp' (instead of `macro:->A')
\begin{thebibliography}{A}
\bibitem[A]{a} A
\bibitem[B]{b} B
\end{thebibliography}
\end{document}