3

I have several chapters in the folder /Chapters and I have the following LaTeX code:

\newcommand\chapnames{Chap1, Chap2, Chap3, Chap4, Chap5, Chap6}

\ForEach
{,}
{\input{./Chapters/\thislevelitem}}
{\chapnames}

Unfortunately, this piece of code does not work unless I change it to:

\ForEach
{,}
{\input{./Chapters/\thislevelitem}}
{Chap1, Chap2, Chap3, Chap4, Chap5, Chap6}

Is there a way to make it work while using \chapnames variable as shown in the \ForEach code at the top?

Qrrbrbirlbel
  • 119,821
Ivan
  • 83

1 Answers1

5

From the forarray manual, subsection 3.1.2 “The command \ForEachX”, page 4:

The command \ForEachX processes the list of items in the same way as the command \ForEach. However, it expands its third argument, a token containing the actual list, before processing it. It has the following syntax:

\ForEachX{<separator >}{<function>}{<list token>}

Therefore, your code sample has to be written as

\newcommand\chapnames{Chap1, Chap2, Chap3, Chap4, Chap5, Chap6}

\ForEachX
{,}
{\input{./Chapters/\thislevelitem}}
{\chapnames}
Qrrbrbirlbel
  • 119,821