Don't make me manually abort a LaTeX compile when there's an error
Asked Answered
T

4

72

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';
    

    (For OS X with Skim)

    $pdf_previewer = "open -a /Applications/Skim.app";
    
  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. For Skim, just look at the “Sync” tab in Skim’s preferences and set it up for your editor.

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

Therein answered 10/4, 2009 at 20:20 Comment(5)
Skim is still thwarting an otherwise perfect solution. Now even with no errors it will often freeze and say "Unable to load file" until I say "OK". I just want a pdf viewer that never bugs me!Therein
Do you have any tutorial on how you managed to make this work with Etherpad?Isfahan
I use -halt-on-error and it works for me. Or I don't really get what fails for you. About Skim, same here, and no better alternative... best is to talk to the developers to push for that feature, I guess.Mcmaster
Could you move your mini-tutorial to an answer? It is not part of the question.Idelia
While using latexmk, you can also use the '-interaction=nonstopmode' option directly to avoid stopping on errors. This is essential for TexMaker, which will hang with latexmk on any errors. You should add that option to the latexmk command, in 'Options > Configure TexMaker > Commands'Gamboge
H
44

With MikTeX, pdflatex has this command-line option:

  -interaction=MODE               Set the interaction mode; MODE must be one
                                  of: batchmode, nonstopmode, scrollmode,
                                  errorstopmode.

Edit suggested by @9999years:

Those values are equivalent to a set of LaTeX \commands that provide the same functionality.

From TeX usage tips:

The modes make TeX behave in the following way:

  • errorstopmode stops on all errors, whether they are about errors in the source code or non-existent files.

  • scrollmode doesn't stop on errors in the source but requests input when a more serious error like like a missing file occurs.

  • In the somewhat misnamed nonstopmode, TeX does not request input after serious errors but stops altogether.

  • batchmode prevents all output in addition to that (intended for use in automated scripts). In all cases, all errors are written to the log file (yourtexfile.log).

Hieroglyphic answered 10/4, 2009 at 20:28 Comment(4)
This is not specific to MixTeX or even LaTeX -- it's been there from Knuth's very first version of TeX AFAIK.Kauslick
Even if it's not there, I've used echo q|pdflatex for a while to achieve this; works well enough :)Aeroneurosis
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?Therein
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.Therein
F
7

You can also put \nonstopmode or \batchmode at the very beginning of your tex file; then it'll work with any TeX version, not just pdflatex. For more info on these and related commands see the very good reference on (raw) TeX commands by David Bausum. Especially the command from the debugging family could be of interest here.

Fond answered 20/10, 2011 at 13:14 Comment(1)
This was very helpful!Illuse
R
3

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

Remington answered 21/7, 2010 at 11:30 Comment(0)
B
0

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

Beyond answered 21/7, 2010 at 11:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.