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?

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.