LaTeX Theorems and Proofs: amsthm, Numbering, and QED
For a LaTeX theorem and proof, load amsmath followed by amsthm, declare the theorem with \newtheorem{theorem}{Theorem}, and write the statement inside a theorem environment. Write its argument in the separate proof environment. amsthm adds the proof heading and an end-of-proof square automatically.
Start with a complete theorem and proof
amsthm supplies the proof environment and theorem-formatting tools, but it does not automatically create an environment named theorem. The \newtheorem declaration belongs in the preamble. Its first argument is the environment name used in the source; its second argument is the heading printed in the PDF.
The statement and proof are separate blocks. A theorem states the result, while a proof explains why the result follows from its assumptions. Do not define proof with \newtheorem: the existing proof environment has different behavior, including its automatic end mark and optional heading.
The minimal example uses a single global theorem counter. It prints Theorem 1 followed by a proof whose last line ends with a hollow square. No special symbol package is required for that default mark. Keep this version working before adding shared counters, custom styles, or decorative boxes.
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
The sum of two even integers is even.
\end{theorem}
\begin{proof}
Let $a=2r$ and $b=2s$ for integers $r$ and $s$.
Then $a+b=2(r+s)$, which is even.
\end{proof}
\end{document}Choose global, section, or shared numbering
With no optional counter argument, each declared environment receives its own counter. A theorem and a lemma can therefore both be numbered 1. That is valid, but a single shared sequence is often easier for readers because the next result always has the next number, regardless of its kind.
Put [section] at the end of the theorem declaration to number results within sections. Theorems in section 2 then become 2.1, 2.2, and so on. Put [theorem] between the environment name and printed heading when declaring a lemma to make it share the existing theorem counter.
These optional arguments have different positions and purposes. A final [section] creates a counter that resets with the section; a middle [theorem] reuses another counter. Do not declare independent section-based counters if you actually want theorems and lemmas to advance one sequence.
In report or book, a chapter-based counter may be appropriate. Standard article has no chapter counter, so [chapter] produces an error there. Also, a section-based result before the first numbered section can be numbered 0.1. Add the intended numbered heading rather than manually changing each displayed result number.
Use theorem styles for definitions and remarks
amsthm provides three standard styles. plain uses a bold heading and italic body, suitable for theorems, lemmas, and corollaries. definition uses a bold heading with upright body text, useful for definitions and worked examples. remark uses an italic heading with an upright body.
Apply \theoremstyle before the declarations it should affect. The selected style is stored when an environment is defined; switching styles immediately before using an already-defined environment does not restyle that environment. Group related declarations in the preamble so the intended formatting is easy to audit.
Use \newtheorem* for an unnumbered environment, such as an informal remark. An unnumbered result does not provide a new result number for a normal cross-reference. If readers need to cite that remark elsewhere, a numbered declaration is usually the simpler and more robust choice.
An optional argument on a theorem instance adds a name or attribution, such as [Euclid]. It is not the same as the counter options on the declaration. Keep the title short enough to fit a heading, and place lengthy historical notes or citations in the surrounding text when necessary.
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\begin{document}
\section{Integers}
\begin{definition}
An integer $n$ is even if $n=2k$ for some integer $k$.
\end{definition}
\begin{lemma}
Every multiple of four is even.
\end{lemma}
\begin{proof}
If $n=4k$, then $n=2(2k)$.
\end{proof}
\begin{theorem}[Closure under addition]
The sum of two even integers is even.
\end{theorem}
\begin{proof}
Write the integers as $2r$ and $2s$, and add them.
\end{proof}
\begin{remark}
The definition, lemma, and theorem share one counter.
\end{remark}
\end{document}Reference a theorem without hard-coding its number
Place \label just inside the theorem environment, after its opening command. At that point the result counter has advanced, so the label records the correct number. A label before the environment can capture the preceding section or another counter instead, even though the source still compiles.
Write Theorem~\ref{thm:main} to produce a named reference with a nonbreaking space. Choose descriptive label keys rather than embedding the current number in the key. Then inserting a new lemma earlier in the file updates references without renaming labels or editing prose by hand.
Compile twice after adding or moving labels. The first run writes the number to the auxiliary file, and the next run reads it. If question marks remain, check the exact label spelling, duplicate-label warnings, and whether the labeled material is actually included in the document.
hyperref makes references clickable when loaded appropriately for the template. cleveref can add names automatically, but shared-counter naming deserves a check in the resulting PDF. For a small document, explicit wording plus \ref avoids adding another package merely to save a few characters.
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[hidelinks]{hyperref}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}[Euclid]
\label{thm:primes}
There are infinitely many primes.
\end{theorem}
\begin{proof}[Proof of Theorem~\ref{thm:primes}]
Suppose the primes form a finite list $p_1,\ldots,p_n$.
The integer $p_1\cdots p_n+1$ has a prime divisor
different from every prime on the list, a contradiction.
\end{proof}
Theorem~\ref{thm:primes} rules out a largest prime.
\end{document}Place the QED symbol after a displayed equation
The proof environment places its end mark automatically when it closes. If the proof ends with ordinary text, this normally gives the expected result. If it ends with displayed mathematics, the square can land on a separate line below the display instead of next to the final mathematical step.
Use \qedhere inside the final display to place the automatic mark there. Load amsmath before amsthm so the proof package can cooperate with the math environments. The example below uses an unnumbered equation, which is a straightforward choice when the final identity does not need its own reference.
In a multi-line align environment, place \qedhere on the final relevant row, before the environment closes. Numbered or unusually nested displays can need additional care; inspect the actual output rather than assuming the same placement works for every equation structure. A proof ending in a list similarly needs its mark checked on the last item.
Do not add \qed manually inside a normal proof just to move the square. That can leave both a manually inserted mark and the automatic closing mark. Use \qedhere for placement, and avoid an empty paragraph immediately before \end{proof}, which can also create an unwanted final line.
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\begin{document}
\begin{proof}
For any real number $x$,
\begin{equation*}
(x+1)^2-x^2=2x+1. \qedhere
\end{equation*}
\end{proof}
\begin{proof}
Expanding and collecting terms gives
\begin{align*}
(x+1)^2 &= x^2+2x+1,\\
(x+1)^2-x^2 &= 2x+1. \qedhere
\end{align*}
\end{proof}
\end{document}Change the proof heading or end symbol
An optional argument changes the proof heading, for example \begin{proof}[Proof of the lemma] or [Proof sketch]. The heading is descriptive text, not a label declaration. A proof sketch should make clear which steps are omitted; the formatting cannot make an incomplete argument into a complete proof.
The default square is controlled by \qedsymbol. To use a filled square, load amssymb and redefine it to a math-mode \blacksquare. Put the redefinition in the preamble for a document-wide change. Avoid inserting the raw Unicode square into a pdfLaTeX source file when a supported command is available.
Outside a proof, amsthm's \qed command can add an end mark to an informal solution. Inside a proof, let the environment manage it. If a journal requires no end mark, an empty \qedsymbol redefinition removes it, but follow the publisher's style rather than changing it solely for decoration.
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\renewcommand{\qedsymbol}{$\blacksquare$}
\begin{document}
\begin{proof}[Proof sketch]
Apply the preceding identity and simplify.
\end{proof}
\end{document}Fix common errors and respect existing templates
Environment theorem undefined means the environment was not declared, or its source name differs from the declaration. Environment proof undefined usually means amsthm is missing and the class does not supply an equivalent. Check the template first: AMS classes already include theorem support, so avoid defining a second proof environment.
If a command is already defined, look for duplicate declarations or competing theorem packages. amsthm and ntheorem are alternative systems, not packages to stack indiscriminately. A publisher may already define theorem names and counters; reuse its definitions or follow its documented customization interface.
For boxed results, a package such as tcolorbox can provide a separate presentation layer, but its counters and labels must be configured deliberately. Establish correct statements, numbering, and references with the plain environment first. Then test the styling on a long theorem that crosses a page, not only a one-line example.
Before delivery, inspect every theorem heading, the first result after each section, all references, and every proof-ending display. A clean compile does not catch a wrong label location, an unintended independent lemma counter, or a square that sits awkwardly below the last equation.
Frequently asked questions
How do I define a theorem in LaTeX?
Load amsthm and declare \newtheorem{theorem}{Theorem} in the preamble. Put the statement inside the theorem environment. amsthm supplies proof automatically, but you declare theorem-like statement environments yourself.
How do I share numbering between theorems and lemmas?
Declare the theorem first, then use \newtheorem{lemma}[theorem]{Lemma}. The middle optional argument reuses the theorem counter. A final [section] on the theorem declaration resets that shared sequence by section.
Why is the QED square below my equation?
The automatic end mark is being placed after the display. Load amsmath before amsthm and put \qedhere inside the last display at the intended location. Inspect the PDF, especially for multi-line or numbered equations.
How do I make an upright definition environment?
Issue \theoremstyle{definition} before declaring the definition with \newtheorem. The style is selected at declaration time. Use the theorem counter in the declaration if definitions should share the result sequence.
Related guides
Test the example in your own document
Open a small project in Octree, paste a complete example, and compile it before moving the changes into your main document. Check the PDF as well as the error log.
Try Octree Free →