What is the difference between "-interaction=nonstopmode" and "-halt-on-error"?
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.
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: █