2

I want to repurpose a predefined comma separated list multiple times in the document. As a minimal example, have a look at the following code which does not work as expected:

\documentclass{article}

\usepackage{xparse}

\newcommand*{\listtotestA}{
    A,
    B,
    C
}

\def\listtotestB{
    D,
    E,
    F
}

\ExplSyntaxOn
\NewDocumentCommand \teslist{m}{
    \clist_map_inline:nn{#1}{
        Output: ##1 \\
    }
}
\ExplSyntaxOff

\begin{document}

\teslist{\listtotestA}
\\
\teslist{\listtotestB}

\end{document}

Instead of

Output: A
Output: B
Output: C

Output: D
Output: E
Output: F

It produces

Output: A,B,C

Output: D,E,F

What am I missing?

3
  • You need to expand the list macro first: \clist_map_inline:on {#1}{...} or \clist_map_inline:Vn {#1}{...}
    – cgnieder
    Apr 25, 2017 at 9:43
  • (You probably need to define the corresponding variant first...) It would be cleaner not to mix l2e code with l3 code but a good recommendation would require to know a bit more about the use case you have in mind…
    – cgnieder
    Apr 25, 2017 at 9:46
  • Actually the lists consist of filenames I want to include, i.e. system paths.
    – milkpirate
    Apr 25, 2017 at 15:02

1 Answer 1

1

A listofitems approach.

\documentclass{article}

\usepackage{listofitems}

\newcommand*{\listtotestA}{
    A,
    B,
    C
}

\def\listtotestB{
    D,
    E,
    F
}

\newcommand\teslist[1]{%
    \readlist*\mylist{#1}%
    \foreachitem\x\in\mylist{Output: \x\\}%
}

\begin{document}

\noindent\teslist{\listtotestA}

\noindent\teslist{\listtotestB}

\end{document}

enter image description here

You must log in to answer this question.

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