I'm just getting started with expl3. I had a previous question which initiated about automating the process of printing authors of a specific paper and their further informations.
The solution by Alan Munn works great. To use only the authors defined inside the commands I tried to create my own command to get the particular informations from the sequence and print them seperated by dashes (therefore, i kept the other variables out of the MWE and both commands, mentioned below, only print the authors. \printauthormeta would normally print additional informations).
If I use a simple new defined command \NewDocumentCommand{\printauthornames}{}{\seq_use:Nn \l_dai_authors_seq {~--~}} it works fine when i recall \printauthornames:
But if i try to copy the workflow from the solution: first defining an new expl3 command \cs_new_protected:Nn \dai_map_author_names:nn and afterwards use it in a \NewDocumentCommand (like the original author did for \dai_map_author_info:nn, see the MWE), the authors are printed multiple times:
Here is the full MWE with the working simple command commented out:
\documentclass[%
]{article}
\usepackage[T1]{fontenc}
\ExplSyntaxOn
% First define three sequences for storing the data
\seq_new:N \l_dai_authors_seq
% User command to enter authors (comma separated)
\NewDocumentCommand{\authors}{m}{
\seq_set_from_clist:Nn \l_dai_authors_seq {#1}
}
% command to print only authors seperated by dash's: not working
\cs_new_protected:Nn \dai_map_author_names:nn {
{\seq_use:Nn \l_dai_authors_seq {~--~}}
}
% internal command to print an author/affiliations/email block
\cs_new_protected:Nn \dai_map_author_info:nn {
{\parindent=0pt
{\seq_item:Nn \l_dai_authors_seq {#1}\par}
\vspace{\baselineskip}
}
}
% User command to print all the author blocks which would include additional information in the full document
\NewDocumentCommand \printauthormeta {} {
\seq_map_indexed_function:NN \l_dai_authors_seq \dai_map_author_info:nn
}
%\NewDocumentCommand{\printauthornames}{}{\seq_use:Nn \l_dai_authors_seq {~--~}}
\NewDocumentCommand \printauthornames {} {
\seq_map_indexed_function:NN \l_dai_authors_seq \dai_map_author_names:nn
}
\ExplSyntaxOff
\authors{Margaret Atwood, Zadie Smith, Madeleine Thien}
\begin{document}
\section{Autoren}
\printauthormeta
\printauthornames
\end{document}
Since the simple solution with only NewDocumentComman works perfectly fine, I just want to understand what went wrong with my second mentioned try to first define an internal expl3 command which then can be used in a "regular" Latex command. I guess it could have something to do with the arguments :nn. When they are nested inside multiple commands/definitions I still have problems recognizing how to use them.


\dai_map_author_info:nnis executed three times. – Ulrike Fischer Jun 13 '23 at 22:25\NewDocumentCommand \printauthornames {} {\dai_map_author_names:nn}or not?cs_newcommand as intermediate step and then creating aNewDocumentCommandover just using the latter directly? – lukeflo Jun 14 '23 at 07:06cs_newcommand as intermediate step for the more complex code of the question mentioned at the top of the post. My bad :) – lukeflo Jun 14 '23 at 08:02