Fix LaTeX error: environment lemma undefined.
The error ! LaTeX Error: Environment lemma undefined means LaTeX reached a \begin{lemma} without knowing what lemma is. Standard LaTeX has no built-in theorem environments, and packages like amsthm supply proof while lemma and theorem require your own declaration.
The short answer: add \usepackage{amsthm} to your preamble, then declare each theorem-like environment with \newtheorem{lemma}{Lemma}. If the error names theorem or proposition, they need a matching \newtheorem line as well.
Why LaTeX throws environment lemma undefined
Plain LaTeX knows about basic structures like itemize, enumerate, and center, but it leaves mathematical environments entirely up to the author. Because different fields, journals, and languages use different names and numbering styles, LaTeX does not predefine lemma, theorem, proposition, or corollary.
When LaTeX reads \begin{lemma}, it checks its internal table of known environments. If nothing has defined lemma, it skips the block, ignores the contents, and eventually raises a secondary error when it hits \end{lemma}: \begin{document} ended by \end{lemma}. Fix the missing definition first, and the trailing error will disappear.
Three causes and how to fix them
Most instances of this error come down to one of three oversights in the preamble or source file.
Fixing the missing declaration
Declare the lemma environment
Add \newtheorem{lemma}{Lemma} in your preamble after loading amsthm. This tells LaTeX to create a lemma environment that prints the word Lemma in bold followed by an automatic number.
\usepackage{amsthm} \newtheorem{lemma}{Lemma} \begin{document} \begin{lemma} Every bounded sequence has a convergent subsequence. \end{lemma} \end{document}Share a counter between theorem and lemma
If you want lemmas, theorems, and corollaries to share a single numbering sequence (Theorem 1, Lemma 2, Theorem 3), pass the name of the main counter in square brackets before the display name.
\newtheorem{theorem}{Theorem} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{corollary}[theorem]{Corollary}Check for spelling mistakes and typos
Look closely at the environment name in the log and your source code. A typo like \begin{lema} or \begin{lem} will trigger the same undefined error because the spelling does not match your \newtheorem declaration.
% Wrong \begin{lem} The set is closed. \end{lem} % Right \begin{lemma} The set is closed. \end{lemma}
What about the proof environment?
If the error names proof instead of lemma, the cause is slightly different. The proof environment is supplied by the amsthm package, so you do not need a \newtheorem{proof} declaration. You only need to load the package in your preamble.
Add \usepackage{amsthm} before \begin{document}. Once loaded, \begin{proof} works immediately and prints an upright heading followed by a Q.E.D. square at the end.
Finding the error in your editor
When a build fails, Texeno and other modern editors catch the exact line number from the pdfLaTeX log. Click on the error in the build results panel to jump straight to the offending \begin{lemma} line in your source file.
If you are compiling from a local terminal, the log will show l.14 \begin{lemma}, pointing you to line 14 of your file. Fix the preamble, recompile, and your PDF will build without interruption.
Questions
Why does LaTeX say environment lemma undefined?
LaTeX does not predefine lemma, theorem, or corollary. You must load amsthm and declare the environment in your preamble using \newtheorem{lemma}{Lemma} before you can use it in your document.
Do I need \newtheorem for the proof environment?
No. The proof environment is predefined by the amsthm package. You only need to add \usepackage{amsthm} to your preamble.
How do I make lemmas share numbers with theorems?
Pass the main counter name in square brackets when you declare the dependent environment, such as \newtheorem{lemma}[theorem]{Lemma}. This keeps all theorem-style blocks in a single numbered sequence.
Try your own paper in Texeno.
Start free, upload a project as a .zip and press Recompile. Upgrade when you need longer compiles.
Start writing