如何在缺少输入文件时强制停止?

如何在缺少输入文件时强制停止?

我注意到,如果我错误地 \include 了一个不存在的文件(例如,错误地输入了文件名),编译将继续,不会出现错误,也不会出现警告,只会显示一条消息“没有文件 colophon2.tex”。这只发生在 \include tex 文件时,而不会发生在 \includegraphics 和 \includepdf 中。更糟糕的是,这条消息会淹没在许多其他不有趣/不重要的编译消息中。

在这种情况下,我怎样才能强制编译因出现错误而停止,或者至少以更明显的方式警告我缺少了某些内容?

我使用的是 Macbook Pro、OS X 10.6.8,并尝试使用 Sublime Text、Texshop、TexMaker、TexWorks 以及我能找到的所有其他 Tex IDE。它们都有同样的问题。

pdflatex版本如下:

pdflatex -v
pdfTeX 3.1415926-2.3-1.40.12 (TeX Live 2011)
kpathsea version 6.0.1
Copyright 2011 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.5.2; using libpng 1.5.2
Compiled with zlib 1.2.5; using zlib 1.2.5
Compiled with xpdf version 3.02pl5

提前致谢!

答案1

更改排版

No file no-file-like-this.tex.

出现错误

! LaTeX Error: File `no-file-like-this.tex' not found.

您可以修补\include以使用正常的\input而不是接受丢失的文件的修补程序:

\documentclass{article}
\usepackage{etoolbox}
\makeatletter

\patchcmd\@include\@input@\input{}{}

\makeatother
\begin{document}
\include{no-file-like-this}
\end{document}

相关内容