A statement is an object, not typography
The first version of a theorem anybody writes is usually \textbf{Theorem 3.2.} Every compact set is closed typed out by hand, and it looks identical on the page. What is missing is everything that is not ink: no counter stands behind it, so there is nothing to step when you insert a lemma; no \label can attach to it, because a label records the last counter that moved and here none did; and no destination exists for a PDF link, because destinations are built from numbers that a package actually issued. You have produced a picture of a theorem.
The environment version inverts the ownership of that information. \begin{theorem} asks a counter to advance, assembles a heading from a style you chose once, opens a hanging list item so the head sits in the margin and the body indents like a paragraph, and leaves a referenceable state behind for the \label you write inside it. Renumbering, cross-references, bookmarks and a list of results are all downstream consequences of the same single fact: the number was issued, not typed.
It is worth knowing that \newtheorem is not an amsthm invention. The LaTeX kernel has provided it since the beginning, in ltthm.dtx, and it gives you the counter and a bold heading and nothing else. What the package adds is the layer a real mathematics document needs: styles that bind a font choice to the kind of statement, the proof environment with its automatic tombstone, the ability to re-arrange the heading, and the optional note in brackets. So "my \begin{theorem} worked without loading anything" is not a mystery — you were using the kernel version, and the difference shows up the first time a definition comes out italic.
Two boundaries matter, because both are covered elsewhere on this site and neither is this package's job. Choosing and wiring counters — \newcounter, the printed form, references that differ from headings — is the machinery in the counters lesson; amsthm only names a counter and asks whether another structure should borrow it. Writing an environment from scratch, or a box that breaks across pages, belongs to the environment-authoring lesson. What stays here is the declaration vocabulary: \newtheorem, \theoremstyle, \newtheoremstyle, \newtheorem*, proof — plus the two higher-level spelling systems that sit on top of them.
\underbrace{\mathbf{Theorem\ 3.2}}_{\text{name + number}}\quad \underbrace{\textit{(Cauchy–Schwarz)}}_{\text{the note}}\quad \underbrace{\text{body text in the style font}}_{\text{body font}}
What \newtheorem takes: three slots and a star
The declaration has one optional argument whose position decides what it means, and that single detail causes most of the confusion in the wild. Written before the heading text, \newtheorem{lemma}[theorem]{Lemma} says "lemmas count in the theorem series". Written after it, \newtheorem{theorem}{Theorem}[section] says "this counter nests inside section and restarts with it". Same brackets, same command, two different relationships — and you can combine both in one preamble, which is what nearly every mathematics article does.
After \newtheorem{theorem}{Theorem} the following things exist: an environment called theorem, a counter also called theorem whose printed form is \thetheorem, and the heading word Theorem exactly as you spelled it. Note what is absent: nothing derives the lowercase word a sentence needs ("by Theorem 3.2" versus "by the theorem"), and nothing tells hyperref or cleveref what noun to print. Those want their own one-liners — \theoremautorefname on the hyperref side, \crefname on the cleveref side — and until they exist a reference prints as a bare number.
The starred form, \newtheorem*{convention}{Convention}, declares an unnumbered environment. It is exactly right for asides you never cite, and dangerous for anything else: an unnumbered environment steps no counter, so a \label inside it captures whatever the previous \refstepcounter left behind — usually the enclosing section. The reference compiles, points somewhere, and is wrong. The star also cannot take a numbering parent, since there is no number to nest.
Declare everything in the preamble, and declare each name once. The heading word is frozen into the environment's definition when you declare it, the style is looked up at the same moment, and the counter is created there too; re-running \newtheorem on a name that already exists either stops with an "already defined" error or, depending on which piece collides, quietly replaces the old definition. If a structure is only correct for one class of document, guard the declaration with a class test rather than declaring it twice.

% Preamble:
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma} % shares the counter
\newtheorem{definition}{Definition}
\theoremstyle{definition}
\newtheorem{example}{Example}
\newtheorem*{remark}{Remark} % unnumbered
% Body:
\begin{theorem}[Cauchy--Schwarz]
$|\langle u, v \rangle| \le \lVert u \rVert \lVert v \rVert$
\end{theorem}
\begin{proof}
By the discriminant of $q(t) = \lVert u + t v \rVert^2 \ge 0$.
\end{proof}
Choosing the numbering series: share, nest, or restart
The decision is about how a reader counts objects, not about aesthetics. Statements that chain into one another — theorem, lemma, proposition, corollary, claim — belong in a single series, because the reader's mental model is "the third thing we proved", and separate series make "Lemma 3.1" and "Theorem 3.1" two different objects with the same name. Things a reader looks up by kind — definitions, examples, notation, exercises in a textbook — deserve their own series, because "Definition 5.2" is a filing location and you do not want a definition to consume a theorem number.
Nesting is orthogonal to sharing. A structure nested in section prints 3.2 and restarts at every section; a structure with no parent prints a document-wide 14. The usual configuration for a paper is one nested shared series for claims plus one nested series for definitions and examples; the usual configuration for lecture notes adds a third for exercises. All three are the same two lines of syntax with different parent names.
A parent must be a counter that actually steps. section exists in every standard class, chapter only in the book-family ones, and asking for a parent that is not there is the third reading of the optional argument: an error complaining that the counter used by the environment has not been defined. Nesting one level deeper — [subsection] — does work and gives you three-digit numbers such as 1.2.3, which is almost never what a reader wants; when you genuinely need "Theorem 3.1.2" with a per-section restart, you are no longer choosing among amsthm options but rewriting a printed form, which is the counters lesson's subject.
Two failure modes are worth recognising on sight. Numbers that restart in the middle of a document usually mean a stray \setcounter{theorem}{0} somewhere in the body, or a structure declared twice with different parents. Numbers that will not restart at a chapter boundary usually mean the sectioning command was faked — a hand-set counter instead of a real \chapter — because a reset fires when the parent is stepped, not when it is set. Neither is fixable inside amsthm; the package only knows which counter to ask.
\underbrace{\text{Thm }1\to \text{Lem }2\to \text{Thm }3}_{\text{one shared series}}\qquad \underbrace{\text{Thm }1,\ \text{Lem }1,\ \text{Thm }2}_{\text{two independent series}}
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage[margin=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\usepackage[capitalise]{cleveref}
% =====================================================================
% 1. One series for claims, nested in the section: theorem 3.1, lemma 3.2, ...
% Order matters: the shared counter must already exist when you mention it.
% =====================================================================
\theoremstyle{plain} % italic body: anything you CLAIM
\newtheorem{theorem}{Theorem}[section] % trailing [section] = numbering parent
\newtheorem{lemma}[theorem]{Lemma} % leading [theorem] = share its series
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{claim}[theorem]{Claim}
% =====================================================================
% 2. A separate series for things you introduce, numbered independently
% =====================================================================
\theoremstyle{definition} % upright body: anything you SET UP
\newtheorem{definition}{Definition}[section]
\newtheorem{example}{Example} % inherits definition's style
\newtheorem{notation}{Notation}
% =====================================================================
% 3. Asides: small, upright, no own series; the starred form is unnumbered
% =====================================================================
\theoremstyle{remark}
\newtheorem{remark}{Remark}
\newtheorem*{convention}{Convention} % no number, nothing to \label
% =====================================================================
% 4. Your own style: the nine arguments, in order
% name / space above / space below / body font / head indent /
% head font / punctuation / space after head / head specification
% =====================================================================
\newtheoremstyle{question}% 1. name
{6pt}% 2. space above ({} = class default)
{6pt}% 3. space below
{\upshape}% 4. body font
{\parindent}% 5. head indent ({} = none)
{\bfseries\sffamily}% 6. head font
{}% 7. punctuation after the head
{\newline}% 8. space after head (\newline = own line)
{\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}}% 9. head spec: name, number, note
\theoremstyle{question}
\newtheorem{question}{Question}[section]
\begin{document}
\section{Compact sets}
\begin{definition}[Compactness]\label{def:compact}
A set $K$ is \emph{compact} if every open cover of $K$ has a finite subcover.
\end{definition}
\begin{theorem}[Heine--Borel]\label{thm:hb}
A subset of $\mathbb{R}^n$ is compact if and only if it is closed and bounded.
\end{theorem}
\begin{proof}
For the forward direction, cover $K$ by the balls $B(0,r)$ with $r>0$; a
finite subcover is bounded, so $K$ is. For closedness, every point outside
$K$ has a ball missing $K$, hence
\begin{equation}
K^{c}=\bigcup_{x\notin K} B\bigl(x,\operatorname{dist}(x,K)\bigr)
\qquad\text{is open.} \qedhere
\end{equation}
\end{proof}
\begin{lemma}\label{lem:closed}
Closed subsets of a compact set are compact.
\end{lemma}
\begin{corollary}\label{cor:finite}
Every finite subset of $\mathbb{R}^n$ is compact.
\end{corollary}
\begin{remark}
The statement of \cref{thm:hb} is false in an infinite-dimensional space;
note how the lemma is numbered inside the same series as the theorem.
\end{remark}
\begin{question}[Covering number]
How many $\varepsilon$-balls does $K$ meet?
\end{question}
\begin{convention}
All spaces are real and all maps are linear unless stated otherwise.
\end{convention}
\subsection*{What the reference machinery prints}
Sources: \ref{thm:hb}, \cref{thm:hb,def:compact,cor:finite},
and the note alone via \nameCref{thm:hb}. A \verb|\label| inside the unnumbered
\verb|convention| environment would silently refer to the enclosing section instead.
\end{document}
Styles: the three defaults and the nine arguments of your own
\theoremstyle takes one of three predefined names and applies to every structure declared afterwards. plain is the default: italic body, bold Roman head — right for anything you claim, because the mathematical content is the point and the label is furniture. definition is upright: right for anything you introduce, because in a definition the term is the emphasis and an italic body makes every common noun look like notation being coined. remark tightens the vertical space, keeps the body upright and sets the head in italic, which reads as "you may skip this". Assign them by intent and the document becomes self-documenting at a glance.
Because the style is captured at declaration time, the layout of your preamble is the layout of your styles: a \theoremstyle{definition} line in the middle of a block of theorem declarations silently converts everything below it. The maintainable shape is three short blocks, each starting with the style it wants, exactly as the listing above does. The reverse operation — declaring first and styling later — is the bug: the structures you already declared keep the old style.
A style of your own is one call to \newtheoremstyle with nine arguments, in this order: the name; the vertical space above; the space below; the body font; the indent of the head; the head font; the punctuation glued after the head; the space between head and body; and the head specification. Empty braces mean "use the default" for the first two and the fifth. The font slots want shape commands — \itshape, \upshape, \bfseries, \sffamily — not \textbf, because the slot installs a switch, not a grouping command.
The ninth argument is where the interesting things live. It is a template in which #1 is the heading word, #2 the number and #3 the optional note, wrapped in \thmname, \thmnumber and \thmnote so each part can be styled separately: that is how you make the note roman inside an italic head, or drop the note entirely, or move it before the number. An empty specification means "the default one", and the command \swapnumbers flips the default to the European order where the number precedes the name — one line for the whole document instead of nine per style.
\forall \varepsilon > 0 \; \exists \delta > 0 \; : \; |x - a| < \delta \Rightarrow |f(x) - L| < \varepsilon
\newline; that plus a \newtheorem{axiom}{Axiom} is most of what a French-style textbook looks like.\begin{gathered} \textbf{Proposition 1.1}\quad \text{every compact subset is closed} \\ \textbf{Definition 1.2}\quad \text{a set } K \text{ is compact if every cover} \\ \textit{Remark 1.3}\quad \text{the converse needs metrisability} \end{gathered}
Names in brackets: what the optional argument carries
\begin{theorem}[Cauchy--Schwarz] puts a name after the number, in parentheses, in the note font of the current style. It belongs to the heading, not the body: the name is not part of the sentence, it is how the sentence is addressed. This is also the place for a reference — \begin{lemma}[Variant of \cref{lem:base}] — for a hypothesis you want visible in a list of results, and for nothing else; long explanatory prose in the note pushes the head off the line and looks like a paragraph with a number stapled to it.
The note is a moving argument, which has two consequences people trip over. It is written to the .aux file and into the PDF bookmark string, so fragile commands inside it need \protect, and accents or math get stripped with a hyperref warning rather than an error — the bookmark quietly loses the character. If a name must contain something delicate, the cheap fix is a plain-text alternative for the bookmark and the reference, and the pretty version in the head.
The same mechanism is what makes name-aware references possible. When a note is present it is also stored as the label name, so a \label written inside the environment carries the string "Cauchy–Schwarz" as well as the number; cleveref can then print \nameCref{thm:cs} as the name and \cref{thm:cs} as "Theorem 3.2". That works only when the label is inside the environment — before \begin{theorem} it names the enclosing section instead, and the failure is silent.
If the shape of the name is what you dislike — bold instead of italic, before the number, with different parentheses — that is a style question and belongs in the head specification, once, near the other declarations. The per-instance version, a manual \textbf inside the note or the first words of the body, is how documents end up with four spellings of the same convention by section twelve.
\lVert u \rVert \, \lVert v \rVert \ge |\langle u, v \rangle|
The proof environment, the tombstone, and \qedhere
proof is the environment people install amsthm for and forget to declare: it exists only once the package is loaded, takes no counter, and prints the word \proofname expands to — "Proof" by default, and the first thing a non-English document redefines. Its optional argument replaces the word outright, which is why \begin{proof}[Proof of \cref{thm:main}], \begin{proof}[Sketch] and \begin{proof}[Second proof] all work with no further machinery.
Closing the environment does three jobs: it ends the paragraph, then walks back over the glue, then pushes the tombstone to the right margin of the last line. The mark itself is the macro \qedsymbol — a small square by default, which publisher classes commonly replace with a solid one — and the whole routine is \qed, which you can also call by hand in a proof you typeset without the environment. For an environment that behaves like proof but says something else, \newproof{solution}{Solution} is the two-argument shorthand; it is what exercise answers want, and it is why you should not build one out of \newtheorem*.
The one placement you cannot delegate is a proof that ends with a display: the tombstone needs room at the end of a text line, and a centred equation leaves none, so the square falls to a line of its own. The fix is \qedhere written inside the display, as the last thing on its final line — in equation, at the end of the last row of an align. When a proof closes with a list instead, the mark needs a text line too, so make the last \item end with words rather than with a display. Nothing in the log reports the wrong version; it is one of those layout facts that is only visible on the page, which is why it is worth a look at every proof ending.
One structural limit is worth knowing before you hit it: the mark is stashed in a single slot, not a stack, so a proof nested inside a proof loses one of the two tombstones. Claim inside a proof is usually better served by a claim environment sharing the main series, or by breaking the argument into a lemma with its own proof one line earlier. Boxed asides are a different matter — see the next section.
\begin{aligned} \lVert u + t v \rVert^{2} &= \langle u + t v,\, u + t v \rangle \\ &= \lVert u \rVert^{2} + 2t\langle u, v \rangle + t^{2} \lVert v \rVert^{2} \\ &\ge 0 \qquad \text{for every } t \in \mathbb{R}, \qquad \blacksquare \end{aligned}
\proofname, do it at \begin{document}: a language or class file loaded later redefines it again.\square
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage[margin=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\usepackage[capitalise]{cleveref}
\newtheorem{theorem}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{exercise}{Exercise}[section]
% ---- the word in the head is the macro \proofname. A language file redefines
% it, so your own change belongs at \begin{document}, not in the preamble:
% \AtBeginDocument{\renewcommand{\proofname}{Beweis}}
% ---- the mark is a macro as well: amsthm's default is the small open square,
% publisher classes usually swap in the solid one
\renewcommand{\qedsymbol}{\ensuremath{\blacksquare}}
% ---- \newproof: an environment that behaves like proof (no counter, the title
% in the head, the tombstone at the end) but says another word
\newproof{solution}{Solution}
\newproof{note}{Note}
\begin{document}
\section{Three ways a proof can end}
\begin{theorem}[Squeeze]\label{thm:squeeze}
If $a_n\le b_n\le c_n$ and $a_n,c_n\to L$, then $b_n\to L$.
\end{theorem}
\begin{proof}[Proof of \cref{thm:squeeze}]
Choose $N$ so that $|a_n-L|<\varepsilon$ and $|c_n-L|<\varepsilon$ for
$n\ge N$; squeezing $b_n$ between them gives
\begin{equation}
-\varepsilon < a_n \le b_n \le c_n < \varepsilon
\qquad\text{for every } n\ge N. \qedhere % <- inside the display
\end{equation}
\end{proof}
\begin{proof}
The same argument in a multi-line alignment needs the mark on the last row:
\begin{align}
|b_n-L| &\le \max\bigl(|b_n-a_n|,\ |b_n-c_n|\bigr) \notag\\
&\le \max\bigl(|c_n-a_n|,\ 0\bigr) \xrightarrow[n\to\infty]{} 0.
\qedhere % <- end of the last line
\end{align}
\end{proof}
\begin{proof}
A proof that ends with a list needs a text line for the mark to sit on, so the
last item must close with words rather than with a display:
\begin{enumerate}
\item $a_n$ is monotone and bounded.
\item Hence it converges, and the limit is $L$ by the line above.
\end{enumerate}
\end{proof}
\section{Answers that are not proofs}
\begin{exercise}
Decide whether $[-1,1]$ is compact, and give reasons.
\end{exercise}
\begin{solution}
Yes: $[-1,1]$ is closed and bounded, and Heine--Borel then applies --- or
directly, every sequence in it has a monotone subsequence, hence a convergent
one.
\end{solution}
\begin{note}
Without the \verb|\qedhere| tricks above you get a stray square on a line of
its own, which is not an error and never appears in the log.
\end{note}
\end{document}
Two ways to change the looks: thmtools and tcolorbox
Both of these are declaration layers, not drawing layers: they decide what \begin{theorem} means, and they are where you go when the nine arguments of \newtheoremstyle start feeling like arithmetic. thmtools re-expresses the whole interface as keyval options — \declaretheorem[style=plain, numberwithin=section, name=Theorem]{thm}, with sibling for a shared series and a \declaretheoremstyle whose keys have names instead of positions. The practical gain is ordering: a style written as options cannot leak into the declaration below it, and things like a per-structure qed mark, head hooks, and a list of theorems come along for free.
The second thing thmtools solves has nothing to do with appearance. A results appendix that retypes each theorem is a document guaranteed to drift, because the two copies are unrelated text. thm-restate stores the statement once and reprints it: \begin{restatable}[Name]{thm}{key} ... \end{restatable} typesets it in place and remembers the body, and the matching restatable* in the appendix reprints it unnumbered. The cost is an auxiliary file and one extra compile — write it once and the drift disappears.
tcolorbox takes the statement and puts it in furniture. \tcbuselibrary{theorems} plus \newtcbtheorem[number within=section]{thmbox}{Theorem}{⟨box options⟩}{th} defines an environment that takes the name and a label suffix as two mandatory arguments, so a boxed theorem reads \begin{thmbox}{Cauchy--Schwarz}{cs} and is referenced as th:cs. The note stops being a parenthetical in the heading and becomes a title line — which is what a textbook or a set of lecture notes usually wants — and breakable gives you a frame that survives a page break, which a minipage wrapper around an amsthm environment emphatically does not.
Two cautions keep these from biting. A box theorem owns its counter unless you tell it to reuse an existing one, so mixing thmbox and theorem in one document gives you two half-populated series; and the moment you need a box you have left amsthm's vocabulary, so the underlying environment mechanics — arguments, hooks, page-breaking — are the environment-authoring lesson, not this one. The invariant that survives both layers is the small one: one declaration per name, one package family per document, and every statement still addressable by number.
\boxed{\;\text{Theorem 3.2 (Cauchy--Schwarz).}\quad |\langle u, v \rangle| \le \lVert u \rVert\, \lVert v \rVert\;}\quad \text{a frame, not a counter}
\newtheorem and some from \declaretheorem works, and nobody who inherits it will be sure why.\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage{thmtools} % keyval declarations on top of amsthm
\usepackage{thm-restate} % the restatable environment (needs an extra run)
\usepackage[most]{tcolorbox} % tcolorbox + its "theorems" library
\tcbuselibrary{theorems,breakable}
\usepackage[margin=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\usepackage[capitalise]{cleveref}
% =====================================================================
% thmtools: the same declarations you would write with \theoremstyle,
% but as options, so ordering stops mattering.
% =====================================================================
\declaretheoremstyle[%
spaceabove = 8pt,
spacebelow = 8pt,
bodyfont = \itshape,
headfont = \bfseries\sffamily,
notefont = \upshape,
headpunct = {.},
headformat = {\NAME\ \NUMBER\ \NOTE}%
]{amshead}
\declaretheorem[style=amshead, numberwithin=section, name=Theorem,
refname={theorem,theorems}, Refname={Theorem,Theorems}]{thm}
\declaretheorem[style=amshead, sibling=thm, name=Lemma]{lem}
\declaretheorem[style=amshead, sibling=thm, name=Corollary]{cor}
\declaretheorem[style=definition, numberwithin=section, name=Definition]{defn}
% =====================================================================
% tcolorbox: a box that prints the title in a header line and borrows an
% existing counter here. The last argument is the label prefix, so each use
% gets its own key: this theorem is \cref{th:hb}.
% =====================================================================
\newtcbtheorem[number within=section, use counter from=thm]{thmbox}{Theorem}
{colback=blue!4!white, colframe=blue!40!black,
fonttitle=\bfseries\sffamily, breakable}{th}
\begin{document}
\section{Statements}
\begin{restatable}[Cauchy--Schwarz]{thm}{thmcs}
For $u,v$ in an inner product space,
$|\langle u,v\rangle|\le \lVert u\rVert\,\lVert v\rVert$.
\end{restatable}
\begin{proof}
Expand $\lVert u+tv\rVert^{2}\ge 0$ in $t$ and read off the discriminant.
\end{proof}
\begin{thmbox}{Heine--Borel}{hb}
A subset of $\mathbb{R}^n$ is compact iff it is closed and bounded.
\end{thmbox}
\appendix
\section{List of results}
\listtheorems{thm,lem,cor,defn}
% The statement above, reprinted verbatim and unnumbered: read back from the
% file written on the previous run, so the two copies can never drift apart.
\begin{restatable*}{thm}{thmcs}\end{restatable*}
\end{document}
How this breaks, and where it stops being amsthm
Three loud messages, each with one cause. ! LaTeX Error: Environment theorem undefined. means the declaration is missing — either no \newtheorem{theorem} anywhere, or the \input that carries it is not in the file you compiled. ! Undefined control sequence on a \theoremstyle or \qedhere line means amsthm itself is not loaded, which is easy to miss because the kernel \newtheorem keeps working and half the preamble looks fine. And a complaint that the counter used by an environment has not been defined is the ordering bug: the parent or sibling you named does not exist yet.
The most expensive class of failure is two theorem packages agreeing to disagree. amsthm, ntheorem and the older theorem package all redefine \newtheorem and all define their own end-of-proof marker, so loading two produces either an "already defined" error naming whichever object collides, or a proof with two tombstones and a heading built by the wrong package. The tell that you are reading documentation for the wrong one: \theorembodyfont{\itshape}, \theoremheaderfont, \theoremnumbering and \theoremsymbol are ntheorem syntax, not amsthm syntax. Delete one \usepackage line; do not write a workaround.
Then the failures that print nothing at all. A definition set in italic because \theoremstyle{definition} came after the declaration. A \cref that prints the section number because its \label sits inside an unnumbered \newtheorem* environment or before the \begin. A theorem number that restarts mid-document because a body-level \setcounter moved the parent by hand. A QED square stranded on its own line after a display. And a heading that lost its bracketed name because a custom head specification dropped the \thmnote term — that last one is invisible until someone compares two theorems.
The debugging move that resolves most of them is to ask what the objects are rather than what the page looks like: which counter does this environment step, what does its \the… print, which style was current when it was declared, and what is in its head specification. Those four questions are amsthm's whole surface area. Anything about how a number is formatted is the counters machinery; anything about how an environment is written is the environment machinery; and anything about whether a reference carries a noun belongs to hyperref and cleveref, which will happily print a bare 3.2 at you until their name tables are told about a structure you declared.
Beamer sits on the far side of that last boundary and deserves a warning of its own, because a preamble copied from an article into a deck is how people meet it. beamer brings its own theorem support: the same \newtheorem syntax works, but each structure is rendered as a coloured block through beamer's templates, with the name in the block header rather than in a parenthetical, and the tombstone routine is not the one described above. Style commands you paste in from this lesson are then either ignored or fighting a layer that owns the same names. To change how a beamer theorem looks you go through beamer's own templates and colours; to keep one preamble for both a paper and its slides, guard the appearance layer per class and let the declarations stay plain.
Lesson cheat sheet
One key line of code from each section — jump to it or copy it straight from here.
\underbrace{\mathbf{Theorem\ 3.2}}_{\text{name + number}}\quad \underbrace{\textit{(Cauchy–Schwarz)}}_{\text{the note}}\quad \underbrace{\text{body text in the style font}}_{\text{body font}}
\usepackage{amsthm}
\documentclass[11pt,a4paper]{article}
\forall \varepsilon > 0 \; \exists \delta > 0 \; : \; |x - a| < \delta \Rightarrow |f(x) - L| < \varepsilon
\lVert u \rVert \, \lVert v \rVert \ge |\langle u, v \rangle|
Common mistakes
! LaTeX Error: Environment theorem undefined.— the environment was never declared, or the file holding the declarations is not loaded. The kernel gives you\newtheorembut no styles and noproof; if\theoremstyleis next reported as an undefined control sequence,amsthmitself is missing.- Loading
ntheoremor the oldtheorempackage alongsideamsthm. All three redefine\newtheoremand define their own end-of-proof symbol, so the result is an "already defined" error, a doubled QED, or headings built by a package you did not choose. Keep one;\theorembodyfontin a snippet is the giveaway that it is notamsthm. - Numbering every structure independently when the statements interleave: the reader meets Theorem 3.1, Lemma 3.1 and Theorem 3.2 — three objects with one name. If a lemma exists only to serve a theorem, give it the shared counter:
\newtheorem{lemma}[theorem]{Lemma}, declared after the theorem. - Setting definitions and examples in
plainstyle. An italic definition makes every ordinary word look like notation being introduced, which is the opposite of what the environment is for; and because the style is captured at declaration time, the fix is to move the\theoremstyle{definition}line above the block, not to patch each instance. - Typing the tombstone by hand as
$\square$at the end of the text, and leaving a final display without\qedhere. The first double-marks when the environment also closes; the second strands the square on a line of its own, which produces no error and no log entry — you only see it on the page. - Putting
\labelinside an unnumbered environment declared with\newtheorem*, or before the\beginline. Neither environment steps a counter at the moment the label is written, so the reference resolves to the enclosing section and compiles cleanly: wrong output, zero diagnostics.
Questions about this lesson
How do I number theorems within sections in LaTeX?
\newtheorem{theorem}{Theorem}[section] produces Theorem 1.1, 1.2 … and restarts at every section; in a report or book use [chapter] instead. The counter must exist, which it does in the standard classes. Note that this optional argument is a different thing from the one written before the braces — \newtheorem{lemma}[theorem]{Lemma} shares a series rather than nesting in a unit.Can theorem, lemma and corollary share one number sequence?
\newtheorem{lemma}[theorem]{Lemma}, \newtheorem{corollary}[theorem]{Corollary}. They then count in one series — Theorem 3.1, Lemma 3.2, Corollary 3.3 — and each keeps its own word in the heading. Definitions and examples normally get their own series instead.amsthm or ntheorem: which should I load, and what breaks if I load both?
\newtheorem machinery and supply their own end-of-proof symbol, so loading two gives an "already defined" error, a doubled QED square, or headings assembled by the package you did not intend to use. Snippets using \theorembodyfont, \theoremheaderfont or \theoremnumbering belong to ntheorem, not amsthm.Why does my proof end with the QED symbol on a line of its own?
\qedhere inside the equation, as the last thing on its final line — the last row of an align, the last item if the proof ends with a list. Nothing is reported in the log, so this is checked visually at the end of every proof-heavy revision. To change the glyph itself, redefine \qedsymbol; to change the word before the proof, use the optional argument or \proofname.How do I create my own theorem style with an upright body and a bold sans-serif head?
\newtheoremstyle takes nine arguments in this order: name, space above, space below, body font, head indent, head font, punctuation after the head, space between head and body, head specification. An upright body with a sans bold head is {\upshape} in the body-font slot and {\bfseries\sffamily} in the head-font slot; empty braces keep the default. Use shape switches (\itshape, \upshape, \bfseries), not \textbf. The ninth argument lets you rearrange the heading with #1 the name, #2 the number, #3 the bracketed note, via \thmname, \thmnumber and \thmnote — and \swapnumbers is the one-line alternative if all you want is the number before the name. Declare the style before the \newtheorem lines that should inherit it.How do I restate a theorem in an appendix without retyping it, or put theorems in a coloured box?
\begin{restatable}[Name]{thm}{key} … \end{restatable} where it is proved, and put an empty \begin{restatable*}{thm}{key}\end{restatable*} in the appendix; the body is reprinted from what the first run wrote, so you need an extra compile and must keep those auxiliary files. For boxes, \tcbuselibrary{theorems} plus \newtcbtheorem[number within=section]{thmbox}{Theorem}{options}{th} gives a breakable framed theorem whose mandatory arguments are the title and the label suffix. In both cases the declarations must come from one layer: a boxed theorem and an amsthm theorem keep separate counters unless you explicitly connect them.Live playground: edit the LaTeX, see it render
The preview updates as you type — break it on purpose to see how errors look.
Keep reading
Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.