> ## Documentation Index
> Fetch the complete documentation index at: https://resources.latex-cloud-studio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fix "! Emergency stop" and "job aborted" in LaTeX

> What "! Emergency stop" means in LaTeX, and how to fix "no legal \end found", "file error in nonstop mode", and "cannot \read from terminal".

```log main.log theme={null}
! Emergency stop.
<*> main.tex

*** (job aborted, no legal \end found)
````! Emergency stop` means TeX had to stop before it reached `\end{document}`, and it could not ask
you what to do because the compile runs without a terminal. The line that starts with `***`
names the cause. Find it in your log, then use the matching section below.| Line after `Emergency stop` | What it means | Fix |
| - | - | - |
| `*** (job aborted, no legal \end found)` | The main file ended without `\end{document}` | [Close the document](#job-aborted-no-legal-end-found) |
| `*** (job aborted, file error in nonstop mode)` | The main file could not be opened | [Compile the right file](#job-aborted-file-error-in-nonstop-mode) |
| `*** (cannot \read from terminal in nonstop modes)` | A file that the document loads is missing | [Fix the missing file](#cannot-read-from-terminal-in-nonstop-modes) |If your log shows none of these, see [any other emergency stop](#any-other-emergency-stop).## Job aborted: no legal end foundThe log ends with `*** (job aborted, no legal \end found)`: TeX read the whole main file and never
found `\end{document}`. Common causes:- `\end{document}` was deleted, or the file was cut off while it was copied or uploaded.
- The main file is empty. This happens when an empty `main.tex` sits next to the real document.
- An environment or conditional was never closed and swallowed the rest of the file. In that case
  the log shows a different error first, such as `File ended while scanning use of \@xverbatim`
  for an unclosed `verbatim` environment, or `Incomplete \iffalse; all text was ignored after
  line 3` for an `\iffalse` without `\fi`. Close that environment or conditional.### Minimal failing example```latex truncated.tex theme={null}
\documentclass{article}
\begin{document}
\section{Results}
The file stops here, before the document is closed.
```<details><summary>Compiler result</summary>
      \> \\[!WARNING]
\>
\> This example is intentionally invalid. The automated example test verifies that compilation fails with: `job aborted, no legal \end found`.</details>### Fixed versionAdd `\end{document}` as the last line of the main file:```latex complete.tex theme={null}
\documentclass{article}
\begin{document}
\section{Results}
The file stops here, before the document is closed.
\end{document}
```<details>
  <summary>Rendered output</summary>
  Open zoomable preview: Compiled PDF page 1 from complete.tex

  Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment.

  [Open SVG](https://resources.latex-cloud-studio.com/images/rendered/learn-latex-troubleshooting-emergency-stop-02/page-1.svg)
</details>**Ready to use this syntax?** Continue in the browser editor when you want to adapt the example in a real project.[Open LaTeX Cloud Studio](https://app.latex-cloud-studio.com/start?utm_source=resources\&utm_medium=rendered_output\&utm_campaign=docs_open_app\&utm_content=learn_latex_troubleshooting_emergency_stop)In LaTeX Cloud Studio, this failure appears in the Problems panel as
`The main file ended before \end{document}`. If the configured main file is empty and another
`.tex` file in the project is the real document, LaTeX Cloud Studio compiles that file instead, as
described [below](#in-latex-cloud-studio).## Job aborted: file error in nonstop modeTeX could not open the file it was asked to compile, so it never read a line of your document.
The terminal output names the file:```log terminal theme={null}
! I can't find file `main.tex'.
<*> main.tex

(Press Enter to retry, or Control-D to exit)
Please type another input file name
! Emergency stop.
<*> main.tex

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.
```The log file is named `texput.log` instead of `main.log`, because TeX never opened your file:```log texput.log theme={null}
! Emergency stop.
<*> main.tex

*** (job aborted, file error in nonstop mode)
```Common causes:- The main file was renamed, or the document has a different name, such as `thesis.tex` or
  `report.tex`.
- The document is in a subfolder, but the compile starts in the project root.
- The name differs only in case. On Linux, `Main.tex` and `main.tex` are different files.To fix it, compile the file that contains `\documentclass` and `\begin{document}`, from the folder
that contains it. On the command line, that is `pdflatex thesis.tex` or `latexmk -pdf thesis.tex`
in the document's folder.### In LaTeX Cloud Studio- If the configured main file, usually `main.tex`, is missing or does not contain both
  `\documentclass` and `\begin{document}`, the compiler uses the `.tex` file that does. It looks
  at the shallowest folder level first, so an imported project whose document is called
  `thesis.tex` compiles without a settings change.
- If two files at the same level both qualify, the compiler keeps the configured main file. Rename
  or remove the copy you do not compile, so that one root document remains.
- When the main file cannot be opened, the Problems panel shows
  `The main file could not be opened`.## Cannot read from terminal in nonstop modesA file that the document loads with `\input`, `\include`, `\usepackage`, or `\documentclass` is
missing. TeX asks for a new file name, gets no answer in nonstop mode, and stops. The real error
is the `not found` line above the emergency stop:```log report.log theme={null}
! LaTeX Error: File `chapter1.tex' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: tex)

Enter file name: 
./report.tex:4: Emergency stop.
<read *> 
         
l.4 \input{chapter1}
                    ^^M
*** (cannot \read from terminal in nonstop modes)
``````latex report.tex theme={null}
\documentclass{article}
\begin{document}
% chapter1.tex is not in the project, or has a different name
\input{chapter1}
\end{document}
```<details><summary>Compiler result</summary>
      \> \\[!WARNING]
\>
\> This example is intentionally invalid. The automated example test verifies that compilation fails with: `cannot \read from terminal in nonstop modes`.</details>To fix it:- Upload the missing file, or correct its name. Names are case-sensitive.
- Write the path relative to the main file's folder. If the chapter is in `chapters/`, use
  `\input{chapters/chapter1}`.
- If the missing file ends in `.sty` or `.cls`, it is a package or class. See
  [missing package errors](https://resources.latex-cloud-studio.com/learn/latex/troubleshooting/missing-packages.md).## Any other emergency stopIn nonstop mode, an emergency stop is often the last line of a longer failure. Read the log from
the top and fix the first error. Errors start with `!`, or with `./file.tex:LINE:` when the
compile uses `-file-line-error`. On the command line, this prints the first one:```bash theme={null}
grep -n -m1 -E '^!|^\./.*:[0-9]+:' main.log
```In LaTeX Cloud Studio, if the Problems panel cannot classify an error, it shows a
**Report this problem** button. The report includes the end of the compile log, so you do not need
to copy it.## Related pages- [Common LaTeX errors](https://resources.latex-cloud-studio.com/learn/latex/basics/errors.md): `Missing $ inserted`, `Undefined control sequence`, and others
- [Fix "Font unisong not found" in Chinese LaTeX](https://resources.latex-cloud-studio.com/learn/latex/troubleshooting/ctex-font-unisong-not-found.md)
- [Missing package errors](https://resources.latex-cloud-studio.com/learn/latex/troubleshooting/missing-packages.md)
- [Large documents](https://resources.latex-cloud-studio.com/learn/latex/how-to/large-documents.md): split a project with `\input` and `\include`
- [Troubleshooting center](https://resources.latex-cloud-studio.com/learn/latex/troubleshooting.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.