I have a few tens of .tex files in a directory.
How can I compile them all with a single command from the terminal?
Moreover: is it possible to avoid all the files that are generated by the compiler (.bak, .log, .aux, .out, .bib files)?
I usually compile with pdflatex file.tex
.
You can do it with
for
commandI find this syntax easier to remember than find.
Regarding deleting auxiliary files consider using
latexmk -c -pdf
orlatexmk -C -pdf
instead ofpdflatex
.latexmk
is latex make, which builds only the files that need to be built. I am not sure, which auxiliary files get deleted exactly, but I think most of them will be deleted with-c
or-C
switch.According to manual it should also work like this
Another option would be to delete files manually after the processing is done. That would be accomplished like this:
I am not sure if this still qualifies for a oneliner.
According to
man pdflatex
, it only accepts one file. Such commands can be run on more files usingfind
:.
parameter tellsfind
to search in the current folder.-maxdepth 1
disables recursion to subfolders – remove this if not needed.-name '*.tex'
allows processing just the*.tex
files.-exec
runs the given command (pdflatex
) with each found file and replaces{}
with the actual filename.\;
ends the-exec
option and marks that only one found file should be passed to eachpdflatex
call.You can test the command by including
echo
between-exec
andpdflatex
. In this case, the resulting commandsfind
will be just printed to the standard output.After the process, you can simply remove the unwanted files using the
rm
command, for example: