36

Scripting with xelatex

I know halt-on-error makes it possible to use xelatex in loops within scripts without causing scripts to hang up when a document does not compile, but why do we need nonstopmode?

xelatex -interaction=nonstopmode -halt-on-error

OR

xelatex --interaction=nonstopmode --halt-on-error

2 Answers2

32

The two settings control different behaviours. Setting -interaction=nonstopmode tells the TeX engine to run with minimal interaction with the user and as far as possible to 'go past' errors. It's therefore very useful in automation. Setting -halt-on-error tells the engine to stop processing the document at the first error, rather than trying to keep going. Thus setting both will cause the run to terminate after the first error whilst only setting -interaction=nonstopmode will cause TeX to keep going but not ask you to 'help'.

To enumerate the combinations:

  • Neither option: TeX will prompt the user for interaction in the event of an error ('error' includes \show or similar) (The user may of course alter the run mode within TeX using the related primitives.)

  • -interaction=nonstopmode: TeX will run without interaction from the user but will continue past any error messages (up to 100 errors). TeX will abort if there is a 'serious' error such as a missing file.

  • -halt-on-error: TeX will abort the run at the first error

  • -interaction=nonstopmode -halt-on-error: As -halt-on-error as once an error is reached the run is aborted

Notable, there are other possible choices for interaction mode where using the combination may be useful: -interaction=batchmode makes TeX 'quieter', so in a batch file that plus -halt-on-error can make sense for 'either make the PDF or abort early' runs.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • 1
    Thanks! Your answer implies that setting both is the same as setting just -halt-on-error. Is this correct? – Jonathan Komar Aug 05 '15 at 11:32
  • 1
    No. Halt on error halts. Nonstop mode doesn't stop. – Will Robertson Aug 05 '15 at 14:19
  • 5
    That's a tautological comment if I ever saw one. Re. the answer, I think this question would be better served by a 2×2 table explaining the effect of including and not including each option. Specifically, I don't think this answer explains well the difference in practice and why one would want both rather than just -halt-on-error. I would encourage the OP to hold off on accepting to let answers develop longer. – Reid Aug 05 '15 at 15:08
  • @Reid More detail added – Joseph Wright Aug 05 '15 at 15:15
  • @Reid Thanks Reid for clearing what I was asking. Thank you Joseph for providing a more detailed answer. Very helpful. – Jonathan Komar Aug 05 '15 at 15:54
  • @JosephWright I am sorry for asking this naïve question, but what option should I stick with by default? I couldn't really feel the advantages of one over another. – Diaa Feb 03 '17 at 21:51
  • 1
    @DiaaAbidou You don't have to set any of this: they are there if you want the behaviour I've detailed – Joseph Wright Feb 03 '17 at 21:56
  • It helps to understand the difference between stopping and halting. Colloquially they sound the same. But stopping refers to pausing compilation and returning input to the user (for instance, to correct a misspelled control sequence), whereas halting refers to ending compilation altogether. Setting both options tells the engine to plow through minor errors but bail out at the first major one. – Matthew Leingang Aug 08 '22 at 10:32
7

It seems that -halt-on-error will still pester you for input if you have -interaction set to scrollmode (default) or errorstopmode. Therefore, -halt-on-error by itself does not seem sufficient to avoid hangs in scripts.

I’ve not yet confirmed this, but I believe -interaction=nonstopmode by itself is enough to prevent hangs. The only difference -halt-on-error makes is that it will give up on the first error rather than keep trying for up to 100 errors.

Example:

$ echo '\input{nonexistentfile}' >bad.tex
$ tex -halt-on-error bad.tex
This is TeX, Version 3.14159265 (TeX Live 2016/Arch Linux) (preloaded format=tex)
(./bad.tex
! I can't find file `{nonexistentfile}'.
l.1 \input{nonexistentfile}

(Press Enter to retry, or Control-D to exit)
Please type another input file name: █