Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
What package are you using for \ForEach? –  egreg Jan 6 '13 at 19:22
    
This might be of interest: How to iterate through the name of files in a folder –  Werner Jan 6 '13 at 19:24
    
I'm using forarray package. –  Ivan Jan 6 '13 at 19:25
    
@Qrrbrbirlbel Thanks! That worked nicely :) –  Ivan Jan 6 '13 at 19:38
add comment

1 Answer 1

up vote 5 down vote accepted

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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