LaTeX error · Fatal errors

Emergency stop

Quick answer

"Emergency stop" is not a cause in itself: TeX prints it when it cannot continue in non-interactive mode. Read the line marked *** below it. "no legal \end found" means the file ended without \end{document}; "file error in nonstop mode" means a file could not be found; "cannot \read from terminal" means LaTeX wanted to ask you something, usually a missing package. Fix the error printed just above, then compile again.

The error in the log

This is how the message appears in the .log file (and in the compile output). The line starting with l. is the line number where TeX noticed the problem; the real mistake is there or just before it.

! Emergency stop.
<*> main.tex
          
*** (job aborted, no legal \end found)

Why it happens

  • The document has no \end{document}, or it is commented out or inside an unclosed environment, so the file ends while TeX is still waiting.
  • A file named in \input, \include or \documentclass does not exist ("file error in nonstop mode").
  • A missing package: LaTeX asks for another file name, and in nonstop mode it cannot read the answer ("cannot \read from terminal").
  • A compiler set to stop at the first error (halt-on-error), so any earlier error ends in an emergency stop.

How to fix it

Scroll up to the first line beginning with ! and fix that error; the emergency stop is its consequence. If it is the only error, check the *** line.

For "no legal \end found", make sure the main file ends with \end{document} and that every environment opened before it is closed.

Broken: reproduces the error

\documentclass{article}
\begin{document}
Some text.

Try this in Octree — free LaTeX editor with AI, compiles in your browser

Fixed: compiles cleanly

\documentclass{article}
\begin{document}
Some text.
\end{document}

Related errors

Frequently Asked Questions

What does "job aborted, no legal \end found" mean?

TeX reached the end of the file without seeing \end{document}. Add it at the end of the main file, and check that it is not commented out or swallowed by an unclosed brace or verbatim environment.

Why is no PDF produced after an emergency stop?

The run is aborted before LaTeX can finish the pages, so the log ends with "Fatal error occurred, no output PDF file produced". Fix the error and compile again.

Why does an online editor show Emergency stop when my local LaTeX asks a question?

Locally, TeX may stop and prompt for a file name or a key press. Online editors and build tools run in nonstop mode, where TeX cannot ask, so the same situation ends in "Emergency stop" instead.

Paste your document into Octree — compile errors get a Fix with AI button

When a compile fails, Octree shows the error next to the line that caused it and offers a one-click fix that you can review before applying. Free, nothing to install.

Fix it in Octree →