Latex中使用For循環輸入不同目錄下的多個文件

Latex中使用For循環輸入不同目錄下的多個文件
\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}

這是我的主乳膠檔案的程式碼,我還有另外兩個名為「問題」和「答案」的目錄。.tex問題目錄中大約有六個名為ques1, ... 的問題文件,而答案目錄中名為, ,...ques2的文件數量相同,我想在上面的for 循環中指定目錄,以便它自動從上述文件夾中獲取文件這樣我就不必將它們保存在一個資料夾中。還有一種方法可以讓我省略提供 i 的值,而是提供一些可以讀取資料夾中所有檔案的其他條件。.texans1ans2.tex

相關內容