[Tex/LaTex] \input with wildcards (regex) in the file name

input

I would like to \input all tex-files in a certain directory starting with "prefix", in alphabetical order.
Something like \input{prefix*tex} would be nice, but it doesn't work.

Is there some workaround?

Best Answer

I would use your operating system, so for exanple

 ls prefix*tex | sed -e 's/\(.*\)/\\input{\1}/' > list-prefix.tex
 pdflatex main

will make a file list-prefix.tex with one \input{..} per line, for each file matching prefix*.tex.

will input all the files if main.tex has \input{list-prefix} at some point.

If you only need to input (and never add headings etc, and want to avoid making a temporary file, you can use

\input{"|cat prefix*.tex"}

but then you have to process your main.tex with pdflatex --shell-escape or equivalent.

I've used unix shell commands here but the same works on windows if you substitute the appropriate commands (or use bash on windows, which is what I do personally)

Related Question