> ## 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".

`! Emergency stop.` means TeX stopped the run, and the errors above it and any `***` line below it can help you find the cause. Look above `Emergency stop.` for the first error (see [how to find it](#any-other-emergency-stop)), then match the `***` line after `Emergency stop.` below.```log main.log theme={null}
! Emergency stop.
<*> main.tex

*** (job aborted, no legal \end found)
```| `***` 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)` | TeX tried to read terminal input (often after a missing-file error) | [Fix the missing file or terminal read](#cannot-read-from-terminal-in-nonstop-modes) |None of these? See [any other emergency stop](#any-other-emergency-stop).## Job aborted: no legal end foundTeX reached end-of-file without finding `\end{document}`. Common causes:- `\end{document}` was deleted or truncated during a copy or upload.
- The main file is empty (for example, an empty `main.tex` beside your real document).
- An unclosed environment or conditional swallowed the rest of the file — check earlier lines for errors such as `File ended while scanning use of \@xverbatim.` or `Incomplete \iffalse; all text was ignored after line 3.`, then close that block.### 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}
```**Rendered output**Compiled PDF page 1 from complete.tex**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, the Problems panel shows `The main file ended before \end{document}`. If the configured main file is empty and another `.tex` file is the sole root document, LaTeX Cloud Studio compiles that file instead ([details below](#in-latex-cloud-studio)).## Job aborted: file error in nonstop modeTeX could not open the target file, so it read no lines. Terminal output names the missing 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 transcript goes to `texput.log`:```log texput.log theme={null}
! Emergency stop.
<*> main.tex

*** (job aborted, file error in nonstop mode)
```Common causes:- The main file was renamed (for example `thesis.tex` or `report.tex`).
- The file lives in a subfolder while the compile starts in the project root.
- Letter case differs (`Main.tex` vs `main.tex` on Linux).Compile the `.tex` file containing `\documentclass` and `\begin{document}` from its folder — for example `pdflatex thesis.tex` or `latexmk -pdf thesis.tex`.### In LaTeX Cloud Studio- If the configured main file is missing or does not contain both `\documentclass` and `\begin{document}`, the compiler looks for a unique shallowest `.tex` file that contains both.
- If two root candidates tie at the shallowest depth, the compiler keeps the configured file. Move the extra file deeper or remove it from the root candidates.
- When the main file cannot be opened, the Problems panel shows `The main file could not be opened`.## Cannot read from terminal in nonstop modesTeX stops when it needs terminal input in nonstop mode, for example when a missing `\input`, `\usepackage`, or `\documentclass` file triggers a prompt or the source requests terminal input with `\typein` or `\read` on a stream with no open file. Check above `Emergency stop.` for the first error (such as a `not found` line):```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 spelling (names are case-sensitive).
- Write paths relative to the directory where TeX runs — compile from the main file's folder (LaTeX Cloud Studio runs `latexmk -cd`), then use paths like `\input{chapters/chapter1}`.
- For missing `.sty` or `.cls` files, see [missing package errors](https://resources.latex-cloud-studio.com/learn/latex/troubleshooting/missing-packages.md). With no `not found` line, remove interactive `\read`/`\typein` prompts.## Any other emergency stopIn nonstop mode, `Emergency stop.` often follows an earlier error. Fix the first error line in the log (starting with `!` or `./file.tex:LINE:` under `-file-line-error`):```bash theme={null}
grep -n -m1 -E '^!|^\./.*:[0-9]+:' main.log
```In LaTeX Cloud Studio, for unknown problems (and in repair recovery), the Problems panel shows a **Report this problem** button; when a compile record is available, the report can include up to 20,000 characters of log tail.Need a clean starting document that already compiles? [Open the Basic Article template in LaTeX Cloud Studio](https://app.latex-cloud-studio.com/start?template=article-basic\&utm_source=resources\&utm_medium=next_step\&utm_campaign=docs_open_app\&utm_content=learn_latex_troubleshooting_emergency_stop).## 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.