In this post, I found a nice trick for dealing with lists. The code below allows to print lists with an optional separator argument.
\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newcommand{\printlist}[2][,]{%
\def\itemdelim{\def\itemdelim{#1}}% Item delimiter delayed by one cycle
\renewcommand*{\do}[1]{\itemdelim##1}% How each item is processed
\docsvlist{#2}}% Process CSV list
\begin{document}
$\printlist{1,2,3,4,5,6,7}$ \par
$\printlist[;]{a,b,c,d,e,f}$
\end{document}
However, if I use \printlist within the \author command, in combination with a newline \\, this won't work properly: The line break is set only for the first element of the list. For all other elements, the line break is ignored:
\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newcommand{\printlist}[2][;]{%
\def\itemdelim{\def\itemdelim{#1}}% Item delimiter delayed by one cycle
\renewcommand*{\do}[1]{\itemdelim##1}% How each item is processed
\docsvlist{#2}}% Process CSV list
\title{Test}
\author{\printlist[,\]{abc,def,ghi,jkl}}
\begin{document}
\maketitle
\end{document}
If I use a separator without line-break, e.g. ::, the above works as expected.
Adding additional line-breaks \\ in the \author command also leads to the expected result:
\author{\printlisti[::]{abc,def,ghi}\\123\\456\\789}
It seems that the combination of \printlist with line breaks \\ is causing a problem. How come?



\authorwill be put inside atabularwhere each cell forms its own group. The definitions of\itemdelimand\doare local and won't survive this first row. – Qrrbrbirlbel Mar 11 '23 at 02:28tabularand local\door\itemdelim. Why are they lost after the first row? – normanius Mar 11 '23 at 02:32\begin{tabular}{c}\def\itemdelim{test} \\ \itemdelim \end{tabular}. It will lead to an Undefined control sequence\itemdelim. You basically need\gdefs for every instance of\defand\renewcommand. Or prepare the list beforehand. – Qrrbrbirlbel Mar 11 '23 at 02:35\gdefhelps in your example, why doesn't work for my problem? Using\gdefin the definition of\printlistleads to the same result. – normanius Mar 11 '23 at 02:46\def\itemdelimwill be used in the first row. It's that internal\def\itemdelim{#1}that needs to be global (as well as the\dotoo). I hope my answer is somewhat clearer. – Qrrbrbirlbel Mar 11 '23 at 02:49