Purplelink
← All LaTeX errors

LaTeX Error: Environment x undefined

A \begin{...} names an environment LaTeX has no definition for.

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:

Related errors

Frequently asked questions

Which package defines the align environment?
amsmath. Add \usepackage{amsmath} to the preamble. The same package defines align*, gather, multline, equation* and the matrix environments such as pmatrix and bmatrix.
Why is the theorem environment undefined?
LaTeX does not predefine theorem, lemma or definition. Declare each one with a line such as \newtheorem{theorem}{Theorem} in the preamble. The proof environment comes from the amsthm package.
I loaded the package. Why is the environment still undefined?
Check the spelling inside \begin{...}, including a trailing star: equation* and equation are separate environments. Some templates also define environments only in their own class file, so the same text in another class leaves them undefined.