# How to force LaTeX to error when an \include file is missing/misspelled?

The only file which was meant to be compiled in my Main.tex was specified by the following line:

\include{transformtaion}


It was compiled without any error using the following command:

pdflatex -synctex=1 -interaction=nonstopmode Main.tex


However, the generated PDF file was empty. After investing a large amount of time, I learned that the problem is with misspelling of the file, i.e. transformtaion instead of transformation.
The question is how to force the compilation process to give a compile-time error which indicates the misspelling problem.

• Get rid of interaction=nonstopmode. Oct 28 at 13:47
• @IanThompson that probably does not do much \include does not complain if the file is not found. \input does. Oct 28 at 13:49
• @daleif --- I didn't know that. I'd still get rid of nonstopmode, though. Oct 28 at 13:52
• @IanThompson This is not the solution. No error will be shown with or without interaction=nonstopmode. Oct 28 at 17:44
• If you are an AUCTeX/Emacs user, this error should not happend. When inputing files for input or include, you are prompted with a list of valid files. with auto-completion. Oct 31 at 22:13

It is a (maybe not so great) feature of \include to just tell you on the terminal that the file does not exist. You get a one-liner like this:

No file transformtaion.tex.


which is quite hard to spot if you're not looking for it.

Redefining the internals of \include is not advisable, so you can use the include hooks to explicitly check for the existence of the file, and error accordingly:

\documentclass{article}

\makeatletter
\def\mkfilename#1{%
\if\relax\detokenize\expandafter{#1}\relax\else#1/\fi}
{\IfFileExists{\mkfilename\CurrentFilePath\CurrentFile}{}
\makeatother

\begin{document}
\include{transformtaion}
\end{document}


then you'll see an error:

! Error: File transformtaion.tex not found!.

Type  H <return>  for immediate help.
...

l.15 \include{transformtaion}

?


In older releases (before 2020-10-01), without the built-in support for include hooks, you can use filehook and currfile:

\documentclass{article}

\usepackage{filehook}
\usepackage{currfile}
\makeatletter
\AtBeginOfIncludes
{\IfFileExists{\currfiledir\currfilebase.tex}{}

• Undefined control sequence. \AddToHood; Is it related to my document class which is report? If this is the case, what is the alternative solution? Oct 28 at 17:05
• @Alish No, report is fine. You have an older LaTeX distribution (pre 2020). I added an alternative for older releases. I'd recommend an update though Oct 28 at 17:43
• @Alish I just tested with a file named transformtaion.tex and it works. Can you show me the .log, please (you can upload it to pastebin or something like that) Oct 28 at 18:00
• @Alish Sorry, I missed the case of files in subfolders. The code should work now. Aside: you seem to have forgotten to add \makeatletter...\makeatother to the code in your document. Oct 31 at 22:03