5

I noticed that if I mistakenly \include a file that does not exist, such as when mistyping the name of the file, the compilation continues with no error, no warning, and just a message 'No file colophon2.tex.' This only happens when \include-ing tex files, not with \includegraphics and \includepdf. What's worse, this message is lost among the many many other compilation messages that are not interesting/not important.

How can I force the compilation to stop with an error in such cases, or to at least warn me in a more visible way that something is missing?

I'm using a Macbook Pro, OS X 10.6.8, and tried this with Sublime Text, Texshop, TexMaker, TexWorks, and every other Tex IDE I could find. all of them have the same problem.

The pdflatex version is as follows:

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

Thanks in advance!

6
  • 1
    Welcome to TeX.SX! \InputFileIfExists{foo}{true branch}{false branch} might help, where foo is the name of your file you want to include
    – user31729
    Dec 22, 2014 at 13:55
  • Thanks @Christian! I already tried this and it works. However, isn't there a way to do this without changing all the \include-s? I've used Kile (in Linux) for a long time and this problem never happened there, Kile always warned me. Now that I'm on the Mac, I'm afraid that my hands are too used to writing \include and I'll end up submitting my PhD with a missing chapter :)
    – Erion
    Dec 22, 2014 at 14:14
  • Well, one could redefine \include (not advisable, actually) to behave like \InputFileIfExists... I don't use MacOS, so I have no idea on the issues there
    – user31729
    Dec 22, 2014 at 14:18
  • 1
    @ChristianHupfer -- the command is really \InputIfFileExists. but what concerns me more is that \include does some other things that an ordinary input doesn't, like controlling the .aux file. so even if every included file starts with \chapter (and thus a new page), some other important action might be lost. is this a reason to ask for an \IncludeIfFileExists? Dec 22, 2014 at 14:20
  • @barbarabeeton: Yes of course, sorry about the 'typo'
    – user31729
    Dec 22, 2014 at 14:22

1 Answer 1

2

To change the typeout

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

to an error

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

You can patch \include to use a normal \input rather than one than accepts missing files:

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

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

\makeatother
\begin{document}
\include{no-file-like-this}
\end{document}
1
  • Tried this, works exactly as I intend! Thanks everyone!
    – Erion
    Dec 22, 2014 at 15:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .