
\documentclass{minimal}
\usepackage{chngcntr}
\usepackage{pgffor}
\newcounter{question}
\newcounter{answer}
\setcounter{question}{0}
\setcounter{answer}{0}
\newcommand\Que[1]{
\stepcounter{question}}
\newcommand\Ans[2][]{
\stepcounter{answer}}
\newcommand\MAX{10}
\begin{document}
\foreach \i in {1,...,\MAX} {%
\edef\File{ques\i}% The % here are necessary to eliminate any
\edef\FileName{ans\i}% The % here are necessary to eliminate any
\IfFileExists{\FileName}{% spurious spaces that may get inserted
\input{\File}% at these points
\input{\FileName}% at these points
}
}
\end{document}
これは私のメインの LaTeX ファイルのコードです。他に Question と Answer という 2 つのディレクトリがあります。Question.tex
ディレクトリにはques1
、、ques2
...という 6 つの質問ファイルがあり、 .tex
Answer ディレクトリにはans1
、、、ans2
... という同じ数のファイルがあります。上記の for ループでディレクトリを指定して、上記のフォルダーからファイルを自動的に取得し、それらを 1 つのフォルダーに保存しなくても済むようにしたいと思います。また、i の値を指定せずに、.tex
フォルダー内のすべてのファイルを読み取ることができる他の条件を指定できる方法はありますか。