28

Is there a way to compile all tex files within a specific folder, from LINUX terminal, at once?

I would like to do this using pdflatex or lualatex in a way to create a pdf file for each distinc original tex file.

This question is not about creating individual tex files to form a single pdf file using \input or \include, at all.

4

3 Answers 3

30

You could use a loop in the shell eg

cd myfolder; for i in *.tex; do pdflatex $i;done
5
  • 6
    latexmk -pdf "$i" seems more productive and sure than pdflatex $i... Commented Apr 3, 2014 at 11:03
  • @PaulGaborit yes or just make with a suitable makefile, but I wanted to avoid bringing in other commands and provide simplest answer to the question that I could think of (and it's also something I do myself quite a lot, not necessarily for tex but in general) Commented Apr 3, 2014 at 11:09
  • Ok. But "$i" seems more sure than $i... Commented Apr 3, 2014 at 15:59
  • @PaulGaborit why? I never quote the shell variable in that context (only matters if you have spaces in filenames and they are evil anyway:-) Commented Apr 3, 2014 at 16:13
  • 2
    Spaces are not the only problem characters. There is also the semicolons, and some other characters ... Commented Apr 3, 2014 at 22:09
17

By default latexmk compiles all tex files in the current directory, including doing the necessary calls to biber, bibtex, etc. To run pdflatex on the files use

latexmk -pdf

or for lualatex

latexmk -lualatex

You can set default behaviour via a configuration file.

3
  • 2
    I second. This is the way to go, because latexmk will compile a file twice, if necessary e.g. for references etc.
    – Keks Dose
    Commented Apr 3, 2014 at 15:38
  • @AndrewSwann Sorry, I forgot to comment on this answer. It looks nice and clean. But, I couldn't run latexmk -lualatex on my Linux. The reason is that I already had problems to make lualatex work, in the first place. I just don't like the idea of having to care about the settings of a fourth element (latexmk), in addition to pdflatex, bibtex and lualatex.
    – fcpenha
    Commented Dec 10, 2014 at 23:38
  • If lualatex won't run on your system, then nothing that calls lualatex, including latexmk -lualatex, stands a chance of working. If you are just interested in running pdflatex then latexmk -pdf will do that for you, and will not call lualatex. Commented Dec 11, 2014 at 7:36
5

I imagine there are quite a few ways to do this- David Carlisle mentioned one in his comment, here's another:

find -name "*.tex"|while read file; do pdflatex "$file";done
5
  • 4
    Be careful where you call that! If I did that in my home directory, that'd be about 2100 .tex files...
    – jon
    Commented Apr 2, 2014 at 18:33
  • 4
    Another variant: find -name "*.tex" -exec pdflatex '{}' \;
    – nickpapior
    Commented Apr 2, 2014 at 18:52
  • 2
    @jon Be careful where you call that... that's true for most commands :)
    – cmhughes
    Commented Apr 2, 2014 at 18:55
  • 1
    To surpass the levels, just do: find -maxdepth 1 -name "*.tex" -exec pdflatex '{}' \;
    – nickpapior
    Commented Apr 2, 2014 at 19:17
  • @zeroth -- Right. I was trying to suggest that some comment about find's recursivity should be made, not that I just accidentally tried to latex 2100 files.
    – jon
    Commented Apr 2, 2014 at 19:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .