# Show error message when using batchmode

Consider the following MWE (in a foo.tex file):

\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]

\begin{document}
\section{Foo}
\begin{theorem*}
Undefined star theorem environment
\end{theorem*}
\end{document}


If I now run pdflatex -interaction=batchmode -file-line-error foo.tex I get the following output in the console (as seen in the image below)

foo.tex:12:
foo.tex:14:


This means that only the file name and line number of the error are printed. Is there a way to also print the error message when using batchmode? This means that I would like to get something like:

foo.tex:12: LaTeX Error: Environment theorem* undefined.
foo.tex:14: LaTeX Error: \begin{document} ended by \end{theorem*}.


foo.tex:12:
foo.tex:14:


Edit: The strange thing is that some error messages are in fact printed even when using batchmode. For instance if I write a new line containing \error after \begin{document} and then compile the document, I get the following output:

Why is it that in this case the error message is printed?

• Doesn't happen to me; probably it's specific of MiKTeX. – egreg Mar 25 '15 at 20:44
• @egreg so batchmode should always print error messages? – petobens Mar 25 '15 at 22:09
• No, I mean that I get no error message on the terminal in either case (which is the purpose of batchmode). I think that the command window has no batch mode capabilities, so something gets written anyway. On Unix systems, batchmode suppresses output (after the banner). – egreg Mar 25 '15 at 22:13
• @egreg but you do get the file name and line number of the error? Or batchmode suppresses the error altogether? – petobens Mar 25 '15 at 22:15
• @JosephWright and @egreg: I guess then there might be a problem with my setup. However I have no idea what that problem is. If one of you can, in the form an answer, explain how should batchmode theoretically/correctly work (and compare it for instance to nonstopmode, I will happily accept it. Thanks for the help. – petobens Mar 29 '15 at 16:13

If I use the command line

> pdflatex -interaction=batchmode -file-line-error test


and press Return, here's the output I get on the terminal

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode


although the file starts with \error and, indeed, the log file shows

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdflatex 2015.7.4)  4 JUL 2015 23:41
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**test
(./test.tex
LaTeX2e <2015/01/01> patch level 1
Babel <3.9l> and hyphenation patterns for 79 languages loaded.
! Undefined control sequence.
l.1 \error

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.


I'm using a standard terminal on a Unix system (Mac OS X, but it's the same on other Unix boxes I tried) with TeX Live. Joseph Wright confirms that this is the behavior also on a Windows command shell with MiKTeX.

Note that -interaction=nonstopmode is very different: it makes TeX not stop at errors, showing them on the terminal window along with the normal output, so I get something like

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2015/01/01> patch level 1
Babel <3.9l> and hyphenation patterns for 79 languages loaded.
./test.tex:1: Undefined control sequence.
l.1 \error

(/usr/local/texlive/2015/texmf-dist/tex/latex/amscls/amsart.cls
Document Class: amsart 2015/03/04 v2.20.2
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the ?' option.
[...]


which is probably what you don't want.

TeX Live has the script texfot that filters messages on the terminal; if I run

> texfot pdflatex -interaction=nonstopmode -file-line-error test


the terminal shows

/usr/texbin/texfot: invoking: pdflatex -interaction=nonstopmode -file-line-error test
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdflatex)
./test.tex:1: Undefined control sequence.
l.1 \error
Output written on test.pdf (1 page, 19010 bytes).


What about using nonstopmode instead of batchmode? As far as I know nonstopmode does the same as the normal mode, but does not hold on errors. batchmode is intended not to put a lot of output to the terminal.

• Welcome to TeX.SX! While this seems to be a good suggestion and might well be what the OP is looking fot, it is a bit meagre for an answer and in its current form is better suited as a comment. If you, however decide to add a short explanation, it might well become a very good answer (and wait for the OP's response). – moewe Mar 28 '15 at 9:42
• You are right, I intended to post a comment. Sorry for that. As far as I know nonstopmode does the same as the normal mode, but does not hold on errors. batchmode is intended not to do a lot of output to the terminal. – T_O Mar 28 '15 at 16:29
• You can edit your answer to include that explanation. – moewe Mar 28 '15 at 17:29