从终端输出中找到产生编译错误的文件

从终端输出中找到产生编译错误的文件

考虑以下文件:

test1.tex

\documentclass{article}
\input{test2}
\begin{document}
Hello
\end{document}     

test2.tex

\usepackage{badpak}

在 MikTeX 中:

pdflatex -interaction=nonstopmode test

我得到:

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9 64-bit)
entering extended mode
(test1.tex
LaTeX2e <2015/01/01> patch level 2
Babel <3.9m> and hyphenation patterns for 69 languages loaded.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\size10.clo")) (test2.tex)

! LaTeX Error: File `badpak.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name:
! Emergency stop.
<read *>

l.3 \begin
          {document}
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on test.log.

如果我将错误移至test1.tex

test1.tex

\documentclass{article}
\input{test2}
\usepackage{badpak}
\begin{document}
Hello
\end{document}

test2.tex

\relax

我得到:

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9 64-bit)
entering extended mode
(test1.tex
LaTeX2e <2015/01/01> patch level 2
Babel <3.9m> and hyphenation patterns for 69 languages loaded.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\size10.clo")) (test2.tex)

! LaTeX Error: File `badpak.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name:
! Emergency stop.
<read *>

l.4 \begin
          {document}
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on test.log.

两个输出几乎相同: 我如何知道错误来自哪个文件?

我也尝试了选项-file-line-error-c-style-errors,但没有更好的结果。
此外,写的成绩单也test.log没有帮助。

答案1

当 TeX 打开一个文件进行输入时,它会将其添加(到日志中,当它关闭时,它会添加,)因此您可以通过查看哪个文件路径是最接近的不匹配来判断在检测到错误时打开了哪个文件(

在这两种情况下,错误都是检测到在顶层输入文件中。

如果你使用

测试1.tex

\documentclass{article}
\input{test2}
\begin{document}
Hello
\end{document}     

测试2.tex

\usepackage{badpak}\relax

你得到

(./test1.tex
LaTeX2e <2016/03/31> patch level 2
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/home/davidc/texmf/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/home/davidc/texmf/tex/latex/base/size10.clo
File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
) (./test2.tex

! LaTeX Error: File `badpak.sty' not found.

(之前不匹配的./test2.tex表示该文件已打开。

在您的案例中,您遇到了一个不幸但非常不寻常的情况,即输入文件以命令 ( \usepackage) 结尾,该命令的尾随可选参数不存在。因此,该命令会提前查看是否存在尾随的[起始[2016/01/01]参数,这样做会到达文件末尾并触发文件关闭,因此文件被关闭latex 执行主体\usepackage并发现文件丢失,所以你看到

(test2.tex)

! LaTeX Error: File `badpak.sty' not found.

立即报告错误表示)已经test2.tex关闭。

答案2

您可以尝试使用以下命令使编译更加详细\message

\newcommand{\myinput}[1]{\message{[START input of #1}\input{#1}\message{END input of #1]}}
\myinput{test2}

相关内容