Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

It'd be really nice to do a git commit -m "some stupid broken commit" and get back a refusal from git, because the latest version of the document hasn't been successfully compiled yet (ie. changes haven't been tested). The git side of this is pretty simple, just a shell script that returns a non-zero exit code. But in order to do that, I need to be able to check whether the pdf is up to date. Apparently it can be done, since if I run latexmk after a successful compile, I get:

$ latexmk -pdf -f thesis
Latexmk: This is Latexmk, John Collins, 30 March 2012, version: 4.31.
**** Report bugs etc to John Collins <collins at phys.psu.edu>. ****
Latexmk: All targets (thesis.pdf) are up-to-date

This is nice, and I could just use this in the script (assuming it spits out a usable exit code). But it'd be really nice to be able to do it without latexmk compiling the document if it ISN'T up to date.

So, how does latexmk work out that the output file is up to date? Or, is it possible to tell latexmk to not compile, and just check the compilation status?

share|improve this question
    
I think you just want to test if there is a .tex source newer than the final pdf. In linux, test file.pdf -nt file.tex will return 0 if file.pdf is newer than file.tex. Of course you will want to loop through all your source files performing this check. –  guillem Jul 27 '12 at 7:15
    
@guillem: Yeah, that's what I was thinking, but I kind of wanted a portable solution that didn't require me to manually list all the included files. If there is a way to find all the included files (including .tex and .pdf and images), without compiling, then that would be an acceptable answer. –  naught101 Jul 28 '12 at 1:30
    
I would loop through all included files using git ls-files. Using bash scripting, this can be accomplished with for file in [backtick]git ls-files | grep "\.tex"[backtick] do echo $file; done. Same for pdf files. The echo $file command is only for demo purposes. Sorry if this is already known, maybe someone can make use of it! –  guillem Jul 30 '12 at 5:53

2 Answers 2

up vote 7 down vote accepted

A slightly better solution is to create a special initialization file, which I'll call latexmkrc-diagnose-change, with the following contents

$pdflatex = $latex = 'internal die_pdflatex %S';
sub die_notepdflatex {
    # Stop now, otherwise latexmk will update its knowledge of the
    # source files and not realize files are out-of-date on the next run.
    die "I won't do anything, but just note that '$_[0]' is out of date\n";
}

Then invoke latexmk with the command line latexmk -r latexmkrc-diagnose-change -pdf thesis. If the file(s) are out-of-date, you'll get a suitable error message, and latexmk will exit with a non-zero exit code.

share|improve this answer
    
Nice. Can you explain what is going on in the first line? For others, there's a description of latexmk RC files in the latexmk man page –  naught101 Jul 31 '12 at 1:51

Latexmk saves hashes of the involved files (by default) in jobname.fdb_latexmk In continuous mode it then loops over the those files and checks from time to time (every 2 seconds if I recall correctly).

About your hook:

It seems that latexmk updates the hashes before compiling. So the second run of latexmk always returns "up to date".

The first time you could use something like latexmk -norc -latex=idonotexist jobname. Running this won't work and so latexmk will return a negative value. The -norc will protect you from your settings file, so you dont have to use -pdflatex or whatever.

But only one time. Then you have to change some files again. This doesn't protect against "it didn't compile" but "I didn't even try to compile"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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