17

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
15

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.

  • 1
    Thanks! Your answer implies that setting both is the same as setting just -halt-on-error. Is this correct? – Jonathan Komar Aug 5 '15 at 11:32
  • 1
    No. Halt on error halts. Nonstop mode doesn't stop. – Will Robertson Aug 5 '15 at 14:19
  • 3
    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 5 '15 at 15:08
  • @Reid More detail added – Joseph Wright Aug 5 '15 at 15:15
  • 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 3 '17 at 21:56
5

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: █

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.