Inputting multiple files in LaTeX
My suggestion is to create one file with all the \input
lines automatically and use \input
to include this file (and hence, all desired files) into your main document. The best way to keep everything up to date would be a Makefile. On a Unix system you can use this command line to create the file with the input lines:
ls dir/*.tex | awk '{printf "\\input{%s}\n", $1}' > inputs.tex
You would only update inputs.tex
once in a while (or automatically) but always use \input{inputs.tex}
in your main document. The beauty of using ls
(or find
) is that you can combine naming some files explicitly and others using shell (glob) patterns to control what files are included in what order.
Makefile
The GNU Make Makefile rule to do this automatically would look like this:
.PHONY: all all: inputs.tex inputs.tex: $(wildcard dir/*.tex) ls dir/*.tex | awk '{printf "\\input{%s}\n", $$1}' > inputs.tex
A call to make
would trigger updating the all
target, which in turn would update inputs.tex
if any of the included TeX files has changed or a new one was added.
Shell Escapes
Reading about shell escapes in PDFLaTeX in the solution mentioned by Faheem Mitha, here is another idea: one could also execute the command line mentioned above from within the LaTeX source file and read \input{inputs.tex}
after that. However, I haven't tried this.
You could use package bashful
to do it from within LaTeX, e.g., using gniourf_gniourf suggestion, you would write
\documentclass{minimal}
\usepackage{bashful}
\begin{document}
\bash[stdoutFile=inputs.tex]
{ shopt -s nullglob; for file in dir/*.tex; do echo "\\input{$file}"; done; }
\END
\input{inputs.tex}
\end{document}