What it means
A \begin{...} names an environment that LaTeX does not know. Either the package or class that defines it is not loaded, the name is misspelled, or it is an environment you are expected to declare yourself, as with theorem and lemma. LaTeX ignores the \begin. If the build continues, the matching \end then raises a second error, \begin{document} ended by \end{theorem}.
The log line
This small file triggers the error:
\documentclass{article}
\begin{document}
\begin{theorem}
Every bounded sequence has a convergent subsequence.
\end{theorem}
\end{document}
Compiled with pdfLaTeX (TeX Live 2026), it writes this to the .log file:
! LaTeX Error: Environment theorem undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.3 \begin{theorem}
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.
The message names the environment, here theorem, and the l.3 line shows the \begin{theorem} that failed. LaTeX does not predefine theorem. It has to be declared with \newtheorem in the preamble.
To try a fix without touching your project, save the example as a .tex file and compile it online with the LaTeX to PDF tool.
Why it happens
The causes below are in order of likelihood. Each has a before and an after you can compare with your own source.
1. The package that defines it is not loaded
align, gather, multline and the matrix environments come from amsmath. algorithm comes from the algorithm package, tikzpicture from tikz, proof from amsthm.
Before
% preamble has no \usepackage{amsmath}
\begin{align}
After
\usepackage{amsmath} % in the preamble
\begin{align}
2. A theorem-like environment was never declared
theorem, lemma, definition and the rest exist only after a \newtheorem line creates them.
Before
\begin{lemma}
The set is closed.
After
\newtheorem{lemma}{Lemma} % in the preamble
\begin{lemma}
3. A misspelled environment name
The name in the error message is exactly what LaTeX read. Compare it letter by letter, and fix the matching \end as well.
Before
\begin{enumarate}
\item First step
After
\begin{enumerate}
\item First step
4. A starred form that needs amsmath
equation* is not part of basic LaTeX. Without amsmath the message reads Environment equation* undefined.
Before
\begin{equation*}
y = ax + b
After
\usepackage{amsmath} % in the preamble
\begin{equation*}
5. An environment from a different class
Classes define different sets of environments. The book class has no abstract, and frame exists only in beamer. Use a class that has the environment, or replace it.
Before
\documentclass{book}
\begin{abstract}
After
\documentclass{report}
\begin{abstract}
How to find the line
The l. line is exact: it shows the \begin{...} that failed. Fix this error first and leave the \begin{document} ended by \end{...} error that follows it alone. That one disappears as soon as the environment exists.
When you run pdflatex in a terminal without -interaction=nonstopmode, TeX stops at the error and prints a ? prompt. Press Return to carry on past the error, type x to quit, or type h for TeX's own help text, which is the paragraph you see after the l. line in the log. Editors run TeX in non-stop mode, so you get the log and never see the prompt.
What each editor shows:
- ModernTex: when a build fails, the Build button shows the error count and the last good PDF stays on screen. The Build Results panel lists each error, warning and note in plain language, Compile › Next Issue steps through them, and Raw Log shows the full LaTeX log. See ModernTex.
- Overleaf: the logs panel, opened with the button next to Recompile, lists each error and warning with its file and line, and the editor marks the line in the gutter. The unprocessed log is at the bottom of that panel.
- TeXShop: the console window shows the log as it is written and stops at the error. Goto Error moves the source window to the line. TeXShop's default pdfLaTeX command includes
--file-line-error, so the same error starts with the file and line in place of the!:./main.tex:3: LaTeX Error: Environment theorem undefined.
Related errors
- Undefined control sequence: the same problem for commands.
- File `x.sty' not found: when the package you add is not installed.
- Missing \begin{document}: another error that is about the preamble.