%---------------------------------------- % CHAPTERS %---------------------------------------- \newcommand{\includechapters}[2]{% \foreach \i in {0, ..., #2} {% \edef\FileName{content/chapters/#1/\i}% \IfFileExists{\FileName}{% \include{\FileName}% } } } \includechapters{part1}{4} \includechapters{part2}{4} % \includechapters{part3}{1}