views:

1425

answers:

3

As suggested here, latexmk is a handy way to continually compile your document whenever the source changes. But often when you're working on a document you'll end up with errors and then latex will panic and wait for user input before continuing. That can get very annoying, especially recently when I hacked up something to compile latex directly from an etherpad document, which saves continuously as you type.

Is there a setting for latex or latexmk to make it just abort with an error message if it can't compile? Or, if necessary, how would I set up some kind of Expect script to auto-dismiss LaTeX's complaints?

(I had thought pdflatex's option "-halt-on-error" would do the trick but apparently not.)

Bonus question: Skim on Mac OSX is a nice pdf viewer that autorefreshes when the pdf changes (unlike Preview), except that whenever there's a latex error it makes you reconfirm that you want autorefreshing. Texniscope doesn't have this problem, but I had to ditch Texniscope for other reasons. Is there a way to make Skim always autorefresh, or is there another viewer that gets this right?


ADDED: Mini-tutorial on latexmk based on the answer to this question:

  1. Get latexmk here: http://www.phys.psu.edu/~collins/software/latexmk-jcc/
  2. Add the following to your ~/.latexmkrc file:

    $pdflatex = 'pdflatex -interaction=nonstopmode';

  3. While editing your source file, foo.tex, run the following in a terminal:

    latexmk -pvc -pdf foo.tex

  4. Use Skim or another realtime pdf viewer to view foo.pdf.

Voila! Hitting save on foo.tex will now cause foo.pdf to refresh without touching a thing.

+10  A: 

With MikTeX, pdflatex has this command-line option:

  -interaction=MODE               Set the interaction mode; MODE must be one
                                  of: batchmode, nonstopmode, scrollmode,
                                  errorstopmode.
Bastien Léonard
This is not specific to MixTeX or even LaTeX -- it's been there from Knuth's very first version of TeX AFAIK.
ShreevatsaR
Even if it's not there, I've used echo q|pdflatex for a while to achieve this; works well enough :)
Joey
I'm having trouble figuring out what those modes actually mean. The manpage says "the meaning of these modes is the same as the corresponding \commands". What "\commands" is it talking about?
dreeves
Answer: it's talking about raw TeX commands and I think I want nonstopmode: shows all errors on the console but doesn't prompt about them. errorstopmode is what it normally does. scrollmode stops for certain errors like missing files. batchmode neither stops nor outputs errors to the console.
dreeves
+1  A: 

Another possible hack is simply to use:

yes x | latexmk source.tex

You could always create an alias for 'yes x | latexmk' if you're going to use this option lots. The main advantage of this that I can see above the other suggestions is that it is very quick for when you occasionally want latexmk to behave like this.

Mehmet

A: 

There is also a \batchmode command may do the work.

Grissiom
See comment in the accepted answer.
dreeves