Loop in LaTeX is not working
Your code worked for me with some minimal files, but \input
ting files in the middle of a loop might go wrong, as Phelype pointed out in his comment.
I'd use a somewhat safer approach by defining a macro in the loop which collects the various \input
and calling this macro when the loop is done. I've changed your definition such that \MakeLecture{1}{4}
inserts the files from 1 to 4 (and not 3 as in your case) because it sounds more reasonable to me but you can just delete the line \advance\count@\m@ne
if you don't want that.
\documentclass{article}
\makeatletter
\newcommand{\MakeLecture}[2]{%
\count@=#1
\advance\count@\m@ne
\def\@inputmyfiles{}%
\loop\ifnum\count@<#2
\advance\count@\@ne
\edef\@inputmyfiles{\unexpanded\expandafter{\@inputmyfiles}\noexpand\input{Chapter0\the\count@}}%
\repeat
\show\@inputmyfiles % ---> just for testing, delete this in real use
\@inputmyfiles
}
\makeatother
\begin{document}
\MakeLecture{2}{5}
\end{document}
The \show
command returns
> \@inputmyfiles=macro:
->\input {Chapter02}\input {Chapter03}\input {Chapter04}\input {Chapter05}.
A one-liner with expl3
(can be nested):
\RequirePackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand \MakeLecture { O{1} m }
{ \int_step_inline:nnn {#1} {#2} { \input {Chapter0##1} } }
% { \int_step_inline:nnn {#1} {#2} { \input {\code/Lecture~Slides/Chapter0##1} } }
\ExplSyntaxOff
\MakeLecture{4} % same as \MakeLecture[1]{4}