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.

  • 1
    It will be easier to answer for your needs, if you'll detail how do you compile one tex file from the terminal. – Yaron Sep 11 '19 at 7:32
  • 1
    @Yaron I have added the command I usually use – mattiav27 Sep 11 '19 at 7:41
  • 1
    @Melebius the compiler generally produces .bak, .log, .aux, .out, .bib files. I would like to have only the .tex and .pdf files in my directory – mattiav27 Sep 11 '19 at 8:15

You can do it with for command

for f in *.tex; do pdflatex $f; done

I find this syntax easier to remember than find.

Regarding deleting auxiliary files consider using latexmk -c -pdf or latexmk -C -pdf instead of pdflatex. 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.

for f in *.tex; do latexmk -C -pdf $f; done

According to manual it should also work like this

latexmk -C -pdf *.tex

Another option would be to delete files manually after the processing is done. That would be accomplished like this:

for f in *.tex; do pdflatex $f; done; rm *.bak *.log *.aux *.out *.bib

I am not sure if this still qualifies for a oneliner.

|improve this answer|||||

According to man pdflatex, it only accepts one file. Such commands can be run on more files using find:

find . -maxdepth 1 -name '*.tex' -exec pdflatex {} \;
  • The . parameter tells find 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 each pdflatex call.

You can test the command by including echo between -exec and pdflatex. In this case, the resulting commands find will be just printed to the standard output.

After the process, you can simply remove the unwanted files using the rm command, for example:

rm *.bak *.log *.aux *.out *.bib
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.