![使用批处理模式时显示错误消息](https://linux22.com/image/308138/%E4%BD%BF%E7%94%A8%E6%89%B9%E5%A4%84%E7%90%86%E6%A8%A1%E5%BC%8F%E6%97%B6%E6%98%BE%E7%A4%BA%E9%94%99%E8%AF%AF%E6%B6%88%E6%81%AF.png)
考虑以下 MWE(在文件中foo.tex
):
\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\begin{document}
\section{Foo}
\begin{theorem*}
Undefined star theorem environment
\end{theorem*}
\end{document}
如果我现在运行,pdflatex -interaction=batchmode -file-line-error foo.tex
我会在控制台中得到以下输出(如下图所示)
foo.tex:12:
foo.tex:14:
这意味着只打印错误的文件名和行号。有没有办法在使用批处理模式时也打印错误消息?这意味着我希望得到类似这样的信息:
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:
编辑:奇怪的是,即使使用 ,实际上也会打印一些错误消息batchmode
。例如,如果我写一个包含\error
after的新行\begin{document}
,然后编译文档,我会得到以下输出:
为什么在这种情况下会打印错误信息?
答案1
如果我使用命令行
> pdflatex -interaction=batchmode -file-line-error test
然后按回车键,这是我在终端上得到的输出
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
尽管文件以 开头\error
,但日志文件确实显示
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.
我在 Unix 系统(Mac OS X,但在我尝试过的其他 Unix 机器上也一样)上使用标准终端运行 TeX Live。Joseph Wright 证实,在 Windows 命令 shell 上使用 MiKTeX 时也会出现这种情况。
请-interaction=nonstopmode
注意非常不同:它使 TeX 不会因错误而停止,而是将其显示在终端窗口上以及正常输出,所以我得到了类似
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.
[...]
这可能是你不想。
texfot
TeX Live 有在终端上过滤消息的脚本;如果我运行
> texfot pdflatex -interaction=nonstopmode -file-line-error test
终端显示
/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).
答案2
那么使用nonstopmode
而不是怎么样batchmode
?据我所知,nonstopmode
它的作用与正常模式相同,但不会保留错误。batchmode
目的在于不向终端输出大量输出。