0

I'm trying to create the following macro:

\adddescr{<comma separated list>}{<description 1>}...{<description n>}

this macro should print element -- description \par accordingly, so that depending on the amount of items in the list, \adddescr should read that amount of the following tokens.

Here are some concrete examples:

\adddescr{foo,bar,baz}{aaa}{bbb}{ccc}

\adddescr{one,two,three}1{two}three

The output result has to be like that

foo — aaa
bar — bbb
baz — ccc

one — 1
two — two
three — t
hree

Here's what I have so far — it currently can only iterate over my list and print it without parsing the following tokens

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\def\adddescr#1{
  \seq_set_split:Nnn \l_tempa_seq {,} {#1}
  \seq_map_inline:Nn \l_tempa_seq {
    ##1 ~ -- ~ \par
  }
}

\ExplSyntaxOff


\begin{document}
\adddescr{foo,bar,baz}{aaa}{bbb}{ccc}
\\

\adddescr{one,two,three}1{two}three
\end{document}

enter image description here

1 Answer 1

3

enter image description here

\documentclass{article}

\def\adddescr#1{\adddescrx#1,\adddescrstop,\relax}
\def\adddescrx#1,#2\relax{#1\adddescrnext{#2}}
\def\adddescrnext#1#2{ -- #2\par\adddescrx#1\relax}
\def\adddescrstop#1#2{}

\begin{document}

\adddescr{foo,bar,baz}{aaa}{bbb}{ccc}

\adddescr{one,two,three}1{two}three

\end{document}

just using a simple recursion here rather than an expl3 loop.

1
  • Couldn't imagine it can be done so easily and short even without expl3, but since I'm still using it for other code I will implement the idea by using quarks. Thanks!
    – antshar
    Jul 31, 2022 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .