Debugging Compilation timeout errors

Sometimes when you are trying to compile a LaTeX document you get a "compilation timeout" message without further information about what's causing the problem. This article provide some advices to figure out what might be causing your project to take too long to compile.

Contents

Usually when your project times out you don't see any error messages, a simple thing that you can try is to add the command \tracingall in your .tex file right below \begin{document}. This will print some additional error messages in some cases.

Below, a list of common problems that may cause compilation to take too long is presented. These are good places to start looking for errors when something goes wrong.

Errors in tabular, longtable and array environments. If you place invalid commands, forget or add extra & or \\ characters or forget the closing environment command, this may cause LaTeX to take too long to figure out what's wrong.

Missing semicolon in a tikz environment. This is a very common error, the next snippet will cause a compilation timeout error because of the missing semicolon at the end of the first \draw command.

In absence of log messages the only way to solve your problem is to look for the faulty chunk of code.

If your document imports files to generate the final output, commenting out some lines will help to find the faulty one. Be careful, do not comment out parts that can generate more errors. It's recommended to leave uncommented the preamble and the bibliography-related commands.

Once you identify the problematic file, or if your document has only one source file, comment out parts of the text and check if your project compiles with no errors. To comment out a block of text import the comment package and use the comment environment.

\documentclass{article}\usepackage[utf8]{inputenc}\usepackage{tikz}\usepackage{comment}\begin{document}\section{Introduction}
This document contains some dummy information and figures with the
only purpose of taking up some space.
\begin{comment}\section{Second section}\begin{tikzpicture}\draw (0,0)--(1,1)
\draw (0,1)--(1,0);
\end{tikzpicture}
This text and the previous figure won't work
\end{comment}\end{document}

In this example only the title of the first section, Introduction, and the text corresponding to that section will be printed in the PDF output. Everything else is commented out.

If you have a big document with several high resolution images your project may take too long to compile, even when there are no errors in the code. The recommendation is to use lower resolution images where possible and to add the draft option to your \documentclass command. The draft option will disable rendering images and will show a placeholder instead, hence improving the compilation time. Helpful to debug the project before the final version.