Introduction to Mathematical Structures
In academic writing—particularly in mathematics, physics, and computer science—clearly defining theorems, lemmas, and proofs is essential. While you could manually bold text and indent paragraphs, LaTeX provides a much more powerful and automated way to handle these structures.
By using dedicated theorem environments, LaTeX automatically handles:
- Sequential Numbering: Ensuring "Theorem 1" is followed by "Theorem 2."
- Consistent Formatting: Applying the same font styles and spacing throughout the document.
- Cross-Referencing: Allowing you to link to "Theorem 3.4" even if its number changes later.
- Logical Organization: Separating the content of your claims from the proofs that support them.
The most common way to handle these structures is through the amsthm package, which is part of the American Mathematical Society (AMS) suite.
Setting Up Theorems with amsthm
To get started, you need to include the amsthm package in your document preamble (the area before \begin{document}).
The basic command to define a new theorem-like environment is:
\newtheorem{envname}{PrintLabel}
envname: The short name you will use in your code (e.g.,thm).PrintLabel: The word that will actually appear in the PDF (e.g.,Theorem).
Example 1: Basic Theorem Definition
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amsthm}
% Define the 'thm' environment
\newtheorem{thm}{Theorem}
\begin{document}
\begin{thm}
The sum of the internal angles of a triangle is $180^\circ$.
\end{thm}
\begin{thm}
In a right-angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.
\end{thm}
\end{document}Note: In the example above, LaTeX will automatically label these as Theorem 1 and Theorem 2.
Organizing Numbering and Hierarchies
In longer documents like theses or books, you often want theorems to be numbered according to the section they are in (e.g., Theorem 1.1, Theorem 1.2). You might also want different types of statements (Lemmas, Corollaries) to share the same numbering sequence.
Numbering by Section
To restart the counter at every new section, add the section name in square brackets at the end:
\newtheorem{thm}{Theorem}[section]
Sharing a Counter
If you want your Lemmas and Theorems to share the same numbering (so you don't have a "Theorem 1" and a "Lemma 1" on the same page), you define the second environment using the first one’s name in square brackets in the middle:
Example 2: Shared and Section-Based Numbering
\documentclass{article}
\usepackage{amsmath, amsthm}
% Theorem numbered by section (e.g., 1.1)
\newtheorem{thm}{Theorem}[section]
% Lemma shares the same numbering counter as 'thm'
\newtheorem{lem}[thm]{Lemma}
\begin{document}
\section{Introduction to Geometry}
\begin{thm}
This will be Theorem 1.1.
\end{thm}
\begin{lem}
This will be Lemma 1.2, because it shares the counter with 'thm'.
\end{lem}
\end{document}Using Different Theorem Styles
Not all mathematical statements should look the same. A "Theorem" is a major result, while a "Definition" is a clarification of terms, and a "Remark" is an informal note. The amsthm package provides three predefined styles:
plain: Bold title, italicized body (Standard for theorems, lemmas, corollaries).definition: Bold title, upright body (Standard for definitions, examples, exercises).remark: Italicized title, upright body (Standard for notes and remarks).
Example 3: Applying Styles
\documentclass{article}
\usepackage{amsmath, amsthm}
% Plain style (default)
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
% Definition style
\theoremstyle{definition}
\newtheorem{defn}{Definition}[section]
% Remark style
\theoremstyle{remark}
\newtheorem*{rem}{Remark} % The * means it won't be numbered
\begin{document}
\section{Number Theory}
\begin{defn}
An \textbf{even number} is an integer that is divisible by two.
\end{defn}
\begin{thm}
The sum of two even numbers is always even.
\end{thm}
\begin{rem}
This theorem is one of the simplest proofs in parity logic.
\end{rem}
\end{document}The Proof Environment
The proof environment is specifically designed to follow a theorem. By default, it starts with the word "Proof" in italics and ends with a QED symbol (an open square, also known as a Halmos symbol) flush-right.
Unlike theorems, you don't need to define the proof environment in the preamble; it is ready to use once you load amsthm.
Example 4: A Complete Theorem and Proof
\documentclass{article}
\usepackage{amsmath, amsthm}
\newtheorem{thm}{Theorem}
\begin{document}
\begin{thm}[Euclid]
There are infinitely many prime numbers.
\end{thm}
\begin{proof}
Suppose that $p_1, p_2, \dots, p_n$ are all the primes. Let $P = p_1 p_2 \dots p_n + 1$.
For any prime $p_i$, $P$ is not divisible by $p_i$. Therefore, any prime factor
of $P$ must be a prime not in our list. This contradicts the assumption that
we had all the primes.
\end{proof}
\end{document}Tip: If your proof ends with a displayed equation (like
\[ ... \]), the QED symbol might drop to a new line. To fix this, use the\qedherecommand inside the equation:\[ a^2 + b^2 = c^2 \qedhere \].
Best Practices and Tips
To make your LaTeX document professional and easy to maintain, follow these best practices:
1. Use Labels for Cross-Referencing
Never type "As seen in Theorem 5." If you add a theorem earlier in the document, "Theorem 5" might become "Theorem 6." Instead, use \label and \ref.
\begin{thm} \label{thm:pythagoras}
$a^2 + b^2 = c^2$
\end{thm}
As demonstrated in Theorem \ref{thm:pythagoras}...2. Name Your Theorems
If a theorem has a famous name (like "Fundamental Theorem of Calculus"), provide it in square brackets after \begin{thm}. This makes the document much more readable.
3. Keep Preamble Definitions Centralized
Define all your theorem environments in one place in your preamble. This makes it easy to change the numbering style or formatting for the entire document at once.
4. Customizing the QED Symbol
If you prefer a filled square or a different symbol for the end of a proof, you can redefine it in the preamble:
\renewcommand{\qedsymbol}{$\blacksquare$}
Common Pitfalls to Avoid
- Forgetting the Package: Beginners often try to use
\begin{proof}without loadingamsthm. This will result in an "Environment proof undefined" error. - Manual Numbering: Avoid writing
\textbf{Theorem 1:}manually. It defeats the purpose of LaTeX and leads to numbering errors when you reorder your content. - Nesting Proofs: While possible, nesting proofs (a proof within a proof) can be confusing for readers. If a proof is that complex, consider breaking it up with a Lemma.
- Over-Italicizing: Remember that the
plainstyle italicizes the entire body of the theorem. If you have non-mathematical text that should not be italicized, ensure it is placed in adefinitionorremarkenvironment instead.
