2

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:

correct arranged names

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:

names printed too often

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.

lukeflo
  • 1,555
  • 2
    you should read the definition of \seq_map_indexed:NN in the reference (interface3). It will call the function for every item in your sequence, this means \dai_map_author_info:nn is executed three times. – Ulrike Fischer Jun 13 '23 at 22:25
  • Hi @Ulrike, thanks. I read it. I understand the repetition progress now, i guess (Although, i don't fully understand what stands for...). So it would be enough to just use \NewDocumentCommand \printauthornames {} {\dai_map_author_names:nn} or not? – lukeflo Jun 14 '23 at 07:02
  • Btw. Is there any advantage in using a cs_new command as intermediate step and then creating a NewDocumentCommand over just using the latter directly? – lukeflo Jun 14 '23 at 07:06
  • OK, sitting in the train on my way to work, I understand why it is necessary to define a cs_new command 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

0 Answers0