3

I have a directory containing many separate latex documents, either directly or inside subdirectories; and I want to compile all these documents simultaneously. Some of these documents involve multiple .tex files — a master file that includes some other file(s).

The following questions ask something very similar:

However, the answers given there don’t work in my situation; they essentially tell latexmk (or pdflatex, or whatever) to attempt to compile all .tex files within the current directory. That works when each .tex file is an individual document, but fails when there are multiple-file documents, for two reasons:

  • the .tex files that are intended just as includes don’t compile individually, so latexmk chokes on these
  • even when compiling the master file of a document, latexmk may fail because it tries to locate the requested include files within the current directory, not within the directory where the master file lives.

Does anyone have a good command-line one liner to compile all documents, in this situation?

The closest I’ve come is ag -lR --null 'documentclass' . | xargs -0 latexmk This runs latexmk on all files containing documentclass, which solves the first issue above by picking out the master files (at least to a first approximation); but it doesn’t solve the second issue, of finding the correct include files.

(I am on Mac OS; but I guess answers should be similar for all system with a unix-/linux-like command-line.)

  • Try passing the -cd argument to latexmk. This will cause latexmk to change to the directory of your tex file and so should then find the included files. – David Purton Aug 16 '18 at 1:21
  • @DavidPurton: Thankyou! That, added to the attempt I mention, solves the problem. If you make it an answer, I’ll accept it. – Peter LeFanu Lumsdaine Aug 16 '18 at 9:39
2

You can pass the -cd argument to latexmk. This will cause latexmk to change to the directory of your tex file and so should then find the included files.

  • Great, that works perfectly — thanks! So just for easy reference/copy-pasting: the resulting full command is grep -lR --null 'documentclass' . | xargs -0 latexmk -cd (or with ag instead of grep, to ignore files in .gitignore, and a few other subtle differences). – Peter LeFanu Lumsdaine Aug 16 '18 at 10:23

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.