How to define a macro that accepts comma separated arguments, iterates over the arguments and inserts some command or text between the arguments?
E.g. by checking if the current argument is not the first.
I would like to pass \mycommand{a,b,c} and get a \and b \and c.
Here is my example using \author and \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}
I.e. pass the arguments like the following:
\myauthorslist{
{author={Author1},affiliation={University of City1}}
,{author={Author2},affiliation={University of City2}}
,{author={Author3},affiliation={University of City3}}
% ...
}
UPDATE: What I've tried so far:
\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}
The previous is working. But I'd like to non repeat \myauthor and call it like the following:
\author{
\myauthorslist{
{author={Author1},affiliation={University of City1}},
,{author={Author2},affiliation={University of City2}}
,{author={Author3},affiliation={University of City3}}
}
}
But I don't know how to use \myauthor in \myauthorslist. The following is not working:
\NewDocumentCommand \myauthorslist { O{ \and } m } {
\clist_use:nn { #2 } { \myauthor{ #1 } } % <- this is not working!
}
\myauthorslist{{cs list},{cs list},...}? – campa Oct 25 '23 at 09:16expl3, you can useclists. Does this help? https://tex.stackexchange.com/a/576767/278534 – User23456234 Oct 25 '23 at 09:23{ O{ \and } m }. But I don't know how to pass\myauthorto\clist_use:nn { #2 } { #1 }. I've tried\clist_use:nn { #2 } { \myauthor{#1} }but it doesn't work. – wolfrevo Oct 25 '23 at 09:59\author {author={Author1},affiliation={University of City1}} \author{author={Author2},affiliation={University of City2}} \author{author={Author3},affiliation={University of City3}}– David Carlisle Oct 25 '23 at 10:01expl3, could belistofitemspackage. – Iacobus1983 Oct 25 '23 at 11:50\seq_set_from_clistto fill a sequence from a command which takes aclistas argument. Then you can process the sequence with\seq_use:Nnnnand specify the separators (nnn). First the separator between exact two items, second the separator between multiple items, third the separator only between the last two of multiple items. – lukeflo Oct 25 '23 at 16:23\clist_use:Nnnn? – cfr Oct 26 '23 at 00:28seqis that it can be indexed when mapping to a function viaseq_map_indexed_function. This is very useful if you want to test whether you are on the first item or elsewhere in the sequence. – wolfrevo Oct 26 '23 at 08:06expl3(as seems to be the case here) and the job can be done directly with aclist, the direct approach is probably the more straightforward one. Unless the OP needs to do this over and over, the speed difference is likely to be negligible. – cfr Oct 26 '23 at 14:01