# Compile all tex files within a folder at once

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.

-
`cd myfolder; for i in *.tex; do pdflatex \$i;done` ? –  David Carlisle Apr 2 '14 at 17:39
here: tex.stackexchange.com/questions/127243/… you'll find a perl script that might solve your problem, –  dcmst Apr 2 '14 at 17:39
I often use the Makefile available here: code.google.com/p/latex-makefile –  cslstr Apr 2 '14 at 17:44
@DavidCarlisle it seems that you solved my problem. My question clearly displays my lack of knowledge on Linux. –  fcpenha Apr 2 '14 at 17:49

You could use a loop in the shell eg

``````cd myfolder; for i in *.tex; do pdflatex \$i;done
``````
-
`latexmk -pdf "\$i"` seems more productive and sure than `pdflatex \$i`... –  Paul Gaborit Apr 3 '14 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) –  David Carlisle Apr 3 '14 at 11:09
Ok. But `"\$i"` seems more sure than `\$i`... –  Paul Gaborit Apr 3 '14 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:-) –  David Carlisle Apr 3 '14 at 16:13
Spaces are not the only problem characters. There is also the semicolons, and some other characters ... –  Paul Gaborit Apr 3 '14 at 22:09

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.

-
I second. This is the way to go, because latexmk will compile a file twice, if necessary e.g. for references etc. –  Keks Dose Apr 3 '14 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 Dec 10 '14 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`. –  Andrew Swann Dec 11 '14 at 7:36

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
``````
-
Be careful where you call that! If I did that in my home directory, that'd be about 2100 `.tex` files... –  jon Apr 2 '14 at 18:33
Another variant: `find -name "*.tex" -exec pdflatex '{}' \;` –  zeroth Apr 2 '14 at 18:52
@jon Be careful where you call that... that's true for most commands :) –  cmhughes Apr 2 '14 at 18:55
To surpass the levels, just do: `find -maxdepth 1 -name "*.tex" -exec pdflatex '{}' \;` –  zeroth Apr 2 '14 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 Apr 2 '14 at 19:25