Is there a simple way of handling the first and/or the last item in an etoolbox-based list in a special way? Here’s a simple example:
\documentclass{article}
\usepackage{etoolbox}
\begin{document}
\forcsvlist{\listadd\namelist}{Tom, Dick, Harry, Jack}
\renewcommand*{\do}[1]{; #1}
\dolistloop{\namelist}
\renewcommand*{\do}[1]{#1, }
\dolistloop{\namelist}
\end{document}
The output is
; Tom; Dick; Harry; Jack
Tom, Dick, Harry, Jack,
How would I go about changing the above code to create the output
Tom; Dick; Harry; Jack
Tom, Dick, Harry and Jack
The first output would be easy to achieve if one could define the first item’s formatting to be simply #1 while the rest are formatted as ; #1. The second output would be easy to achieve if one could define all items to be formatted as , #1 except the first one, which should be #1 and the last one, which should be and #1.
Note that I’m looking for a solution for etoolbox lists, not other list structures.
elementcountshould be copied to the second counter before the loop, and the second counter is decremented instead. – TakingItCasual Jul 07 '20 at 05:49