0

I would like to adapt this answer of another post for one optional argument but my MWE is just a M(not)WE.

\documentclass{article}
\usepackage{xparse}

\newcommand\test[2]{#1+#2\par}

\ExplSyntaxOn \NewDocumentCommand\testcomas{O{x}m}{ \clist_map_inline:nn { #2 } { \test{#1}{##2} } } \ExplSyntaxOff

\begin{document}

\testcomas{a, b ,c d, ,e }

\testcomas[T]{a, b ,c d, ,e }

\end{document}

Bernard
  • 271,350
projetmbc
  • 13,315
  • 2
    Try \test{#1}{##1} instead of \test{#1}{##2}. TeX's parameters are always numbered consecutively. The double hash means that your argument is nested by one additional level. (The documentation says that in \clist_map_inline:Nn <comma list> {<inline function>} <inline function> should be code that receives the item as #1, since you are in a function definition with parameters already, you need two #s to refer to this item.) – moewe Jul 16 '20 at 16:16
  • Shame on me ! Each time I see xparse, my three neurons run away. Thanks for helping them. :-) – projetmbc Jul 16 '20 at 16:19
  • I have started from this post but I have just done a very stupid thing. So the answer is in the post indicateed except for the optional argument but this is not hard to work with. – projetmbc Jul 16 '20 at 18:35

0 Answers0