![迭代 \author 的逗号分隔参数](https://linux22.com/image/470282/%E8%BF%AD%E4%BB%A3%20%5Cauthor%20%E7%9A%84%E9%80%97%E5%8F%B7%E5%88%86%E9%9A%94%E5%8F%82%E6%95%B0.png)
如何定义一个接受逗号分隔参数、遍历参数并在参数之间插入一些命令或文本的宏?
例如,通过检查当前参数是否不是第一个。
我希望通过\mycommand{a,b,c}
并获得a \and b \and c
。
这是我使用的\author
示例\and
\documentclass[]{article}
\usepackage{expkv-cs}
\ekvcHash\myauthor{author=,affiliation=,email=,}{%
\begin{tabular}{ c }
\ekvcValue{author}{#1}\\
\ekvcValue{affiliation}{#1}
\end{tabular}
}
% this macro should have comma separated arguments instead of three fixed arguments
\newcommand*{\myauthorslist}[3]{%
\author{
\myauthor{#1} \and \myauthor{#2} \and \myauthor{#3} % this should be done by iterating the arguments
}
}
\begin{document}
\myauthorslist
{author={Author1},affiliation={University of City1}}
{author={Author2},affiliation={University of City2}}
{author={Author3},affiliation={University of City3}}
\title{mytitle}
\maketitle
\end{document}
即传递如下参数:
\myauthorslist{
{author={Author1},affiliation={University of City1}}
,{author={Author2},affiliation={University of City2}}
,{author={Author3},affiliation={University of City3}}
% ...
}
更新:到目前为止我已经尝试过:
\documentclass[]{article}
\usepackage{expkv-cs}
\ekvcHash\myauthor{long author=,long affiliation=}{%
\begin{tabular}{ c }
\ekvcValue{author}{#1}\\
\ekvcValue{affiliation}{#1}
\end{tabular}
}
\ExplSyntaxOn
\NewDocumentCommand \myauthorslist { O{ \and } m } {
\clist_use:nn { #2 } { #1 }
}
\ExplSyntaxOff
\begin{document}
\author{
\myauthorslist{
\myauthor{author={Author1},affiliation={University of City1}},
,\myauthor{author={Author2},affiliation={University of City2}}
,\myauthor{author={Author3},affiliation={University of City3}}
}
}
\title{mytitle}
\maketitle
\end{document}
前面的方法可行。但我想不重复\myauthor
,而是像下面这样调用它:
\author{
\myauthorslist{
{author={Author1},affiliation={University of City1}},
,{author={Author2},affiliation={University of City2}}
,{author={Author3},affiliation={University of City3}}
}
}
但我不知道如何使用\myauthor
。\myauthorslist
以下不起作用:
\NewDocumentCommand \myauthorslist { O{ \and } m } {
\clist_use:nn { #2 } { \myauthor{ #1 } } % <- this is not working!
}