equation_numbering.tex

Download
latex 454 lines 13.9 KB
  1% ============================================================================
  2% equation_numbering.tex - Equation Numbering and Cross-Referencing
  3% ============================================================================
  4% This document demonstrates how to number equations and create cross-
  5% references in LaTeX using various math environments.
  6%
  7% Compilation:
  8%   pdflatex equation_numbering.tex (run twice for references)
  9% ============================================================================
 10
 11\documentclass[11pt]{article}
 12
 13\usepackage{amsmath}    % Essential for advanced math environments
 14\usepackage{amssymb}
 15\usepackage{amsthm}
 16
 17\usepackage[margin=1in]{geometry}
 18\usepackage[T1]{fontenc}
 19\usepackage{lmodern}
 20
 21% Hyperlinks with cross-references
 22\usepackage{hyperref}
 23\hypersetup{
 24    colorlinks=true,
 25    linkcolor=blue,
 26    citecolor=green,
 27    urlcolor=cyan
 28}
 29
 30% For colored boxes
 31\usepackage{xcolor}
 32\usepackage{tcolorbox}
 33
 34\title{Equation Numbering and Cross-Referencing in \LaTeX}
 35\author{Mathematics Department}
 36\date{\today}
 37
 38\begin{document}
 39
 40\maketitle
 41
 42\tableofcontents
 43
 44\section{Introduction}
 45
 46This document demonstrates how to number mathematical equations and create
 47cross-references to them. Proper equation numbering and referencing is
 48essential for academic writing, allowing readers to easily locate and
 49reference specific formulas.
 50
 51% ============================================================================
 52\section{The \texttt{equation} Environment}
 53% ============================================================================
 54
 55The \texttt{equation} environment creates a single numbered equation centered
 56on its own line.
 57
 58\subsection{Basic Usage}
 59
 60The most fundamental quadratic equation is:
 61
 62\begin{equation}
 63\label{eq:quadratic}
 64x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
 65\end{equation}
 66
 67We can reference Equation~\ref{eq:quadratic} using \verb|\ref{eq:quadratic}|.
 68With hyperref, clicking the reference number jumps to the equation.
 69
 70\subsection{The \texttt{\textbackslash label} and \texttt{\textbackslash ref} Commands}
 71
 72Every numbered equation can have a label defined with \verb|\label{...}|:
 73
 74\begin{equation}
 75\label{eq:euler}
 76e^{i\pi} + 1 = 0
 77\end{equation}
 78
 79Euler's identity (Equation~\ref{eq:euler}) is often called the most beautiful
 80equation in mathematics.
 81
 82\begin{tcolorbox}[colback=yellow!10, colframe=orange!80, title=Best Practice]
 83\textbf{Label naming convention:} Use descriptive labels with prefixes like
 84\texttt{eq:}, \texttt{fig:}, \texttt{tab:}, \texttt{sec:} to identify the
 85type of element being referenced.
 86\end{tcolorbox}
 87
 88\subsection{The \texttt{\textbackslash eqref} Command}
 89
 90The \verb|\eqref| command automatically adds parentheses around equation numbers:
 91
 92\begin{equation}
 93\label{eq:pythagoras}
 94a^2 + b^2 = c^2
 95\end{equation}
 96
 97Compare \verb|\ref{eq:pythagoras}| which gives \ref{eq:pythagoras} versus
 98\verb|\eqref{eq:pythagoras}| which gives \eqref{eq:pythagoras}. The latter
 99is preferred for equation references.
100
101% ============================================================================
102\section{Unnumbered Equations}
103% ============================================================================
104
105Sometimes you want display mathematics without a number.
106
107\subsection{Using \textbackslash[\ldots\textbackslash]}
108
109The simplest way is to use \verb|\[...\]| or \verb|$$...$$| (though the former
110is preferred in LaTeX):
111
112\[
113\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
114\]
115
116\subsection{Using \texttt{equation*}}
117
118Alternatively, use the \texttt{equation*} environment (requires \texttt{amsmath}):
119
120\begin{equation*}
121\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}
122\end{equation*}
123
124This is useful when you want to maintain consistency in style, changing only
125the environment name to toggle numbering.
126
127% ============================================================================
128\section{The \texttt{align} Environment}
129% ============================================================================
130
131The \texttt{align} environment is used for multi-line equations that should
132be aligned, typically at an equals sign or relation symbol.
133
134\subsection{Basic Alignment}
135
136Use \verb|&| to specify alignment points and \verb|\\| for line breaks:
137
138\begin{align}
139\label{eq:align1}
140f(x) &= x^2 + 2x + 1 \\
141\label{eq:align2}
142     &= (x + 1)^2 \\
143\label{eq:align3}
144     &= (x + 1)(x + 1)
145\end{align}
146
147Each line gets its own number. We can reference individual lines:
148Equation~\eqref{eq:align1} shows the expanded form,
149Equation~\eqref{eq:align2} shows the factored form.
150
151\subsection{Suppressing Numbering on Specific Lines}
152
153Use \verb|\notag| to suppress numbering on individual lines:
154
155\begin{align}
156x^2 + y^2 &= r^2 \label{eq:circle} \\
157\frac{x^2}{a^2} + \frac{y^2}{b^2} &= 1 \notag \\
158y &= mx + b \label{eq:line}
159\end{align}
160
161Only Equations~\eqref{eq:circle} and \eqref{eq:line} are numbered.
162
163\subsection{Multiple Alignments}
164
165You can have multiple alignment points by using additional \verb|&| symbols:
166
167\begin{align}
168x &= y & X &= Y & a &= b+c \\
169x' &= y' & X' &= Y' & a' &= b
170\end{align}
171
172Pairs of \verb|&| symbols: first for alignment, second to separate equations.
173
174\subsection{Unnumbered Version: \texttt{align*}}
175
176The \texttt{align*} environment produces no equation numbers:
177
178\begin{align*}
179\sin^2 x + \cos^2 x &= 1 \\
1801 + \tan^2 x &= \sec^2 x \\
1811 + \cot^2 x &= \csc^2 x
182\end{align*}
183
184% ============================================================================
185\section{The \texttt{gather} Environment}
186% ============================================================================
187
188The \texttt{gather} environment is for multiple equations that should be
189centered but not aligned:
190
191\begin{gather}
192\label{eq:gather1}
193a = b + c \\
194\label{eq:gather2}
195x^2 + y^2 = z^2 \\
196\label{eq:gather3}
197E = mc^2
198\end{gather}
199
200Each equation is centered independently and numbered. Reference example:
201Equation~\eqref{eq:gather2} is the Pythagorean theorem.
202
203Unnumbered version (\texttt{gather*}):
204
205\begin{gather*}
206\nabla \cdot \mathbf{E} = \frac{\rho}{\epsilon_0} \\
207\nabla \cdot \mathbf{B} = 0 \\
208\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t} \\
209\nabla \times \mathbf{B} = \mu_0 \mathbf{J} + \mu_0 \epsilon_0
210\frac{\partial \mathbf{E}}{\partial t}
211\end{gather*}
212
213% ============================================================================
214\section{The \texttt{multline} Environment}
215% ============================================================================
216
217The \texttt{multline} environment is for single equations that are too long
218for one line:
219
220\begin{multline}
221\label{eq:multline}
222p(x) = 3x^6 + 14x^5y + 590x^4y^2 + 19x^3y^3 \\
223- 12x^2y^4 - 12xy^5 + 2y^6 - a^3b^3
224\end{multline}
225
226The first line is left-aligned, the last line is right-aligned, and any
227intermediate lines are centered. The entire equation gets one number.
228
229Reference: The polynomial in Equation~\eqref{eq:multline} has six terms.
230
231Unnumbered version (\texttt{multline*}):
232
233\begin{multline*}
234\int_0^1 \int_0^1 \int_0^1 (x^2 + y^2 + z^2)^{10} \, dx \, dy \, dz \\
235= \text{(some very complicated expression)}
236\end{multline*}
237
238% ============================================================================
239\section{The \texttt{split} Environment}
240% ============================================================================
241
242The \texttt{split} environment is used within another math environment (like
243\texttt{equation}) to split a single equation across multiple lines with
244alignment:
245
246\begin{equation}
247\label{eq:split}
248\begin{split}
249(x + y)^3 &= (x + y)(x + y)^2 \\
250          &= (x + y)(x^2 + 2xy + y^2) \\
251          &= x^3 + 3x^2y + 3xy^2 + y^3
252\end{split}
253\end{equation}
254
255The entire \texttt{split} environment gets one equation number. This is
256useful when you want one number for a multi-line derivation.
257
258Reference: The binomial expansion in Equation~\eqref{eq:split} shows the
259cube of a sum.
260
261% ============================================================================
262\section{Subequations}
263% ============================================================================
264
265The \texttt{subequations} environment numbers equations with sub-labels
266(a, b, c, etc.):
267
268\begin{subequations}
269\label{eq:maxwell}
270Maxwell's equations in differential form:
271\begin{align}
272\nabla \cdot \mathbf{E} &= \frac{\rho}{\epsilon_0} \label{eq:maxwell_gauss} \\
273\nabla \cdot \mathbf{B} &= 0 \label{eq:maxwell_nomonopole} \\
274\nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t}
275\label{eq:maxwell_faraday} \\
276\nabla \times \mathbf{B} &= \mu_0 \mathbf{J} +
277\mu_0\epsilon_0\frac{\partial \mathbf{E}}{\partial t}
278\label{eq:maxwell_ampere}
279\end{align}
280\end{subequations}
281
282We can reference the entire group as Equations~\eqref{eq:maxwell}, or
283individual equations: Gauss's law is \eqref{eq:maxwell_gauss}, Faraday's
284law is \eqref{eq:maxwell_faraday}.
285
286% ============================================================================
287\section{The \texttt{cases} Environment}
288% ============================================================================
289
290The \texttt{cases} environment is for piecewise functions:
291
292\begin{equation}
293\label{eq:absolute}
294|x| = \begin{cases}
295x & \text{if } x \geq 0 \\
296-x & \text{if } x < 0
297\end{cases}
298\end{equation}
299
300The absolute value function is defined in Equation~\eqref{eq:absolute}.
301
302Another example:
303
304\begin{equation}
305\label{eq:piecewise}
306f(x) = \begin{cases}
3070 & \text{if } x < 0 \\
308x^2 & \text{if } 0 \leq x < 1 \\
3092 - x & \text{if } 1 \leq x < 2 \\
3100 & \text{if } x \geq 2
311\end{cases}
312\end{equation}
313
314% ============================================================================
315\section{Custom Numbering and Tags}
316% ============================================================================
317
318\subsection{Manual Tags}
319
320You can override automatic numbering with \verb|\tag|:
321
322\begin{equation}
323E = mc^2 \tag{Einstein}
324\end{equation}
325
326\begin{equation}
327a^2 + b^2 = c^2 \tag{Pythagoras}
328\end{equation}
329
330For starred tags without parentheses:
331
332\begin{equation}
333\int_a^b f(x) \, dx \tag*{Fundamental Theorem}
334\end{equation}
335
336\subsection{Equation Numbering by Section}
337
338To number equations by section (e.g., 2.1, 2.2, etc.), add this to the preamble:
339
340\begin{verbatim}
341\numberwithin{equation}{section}
342\end{verbatim}
343
344% Example (commented out to not affect this document):
345% \numberwithin{equation}{section}
346
347% ============================================================================
348\section{Cross-Referencing Best Practices}
349% ============================================================================
350
351\subsection{Label Placement}
352
353Place \verb|\label| immediately after the item you want to reference:
354
355\begin{itemize}
356    \item For equations: right after \verb|\begin{equation}| or on the line
357    \item For sections: right after \verb|\section{...}|
358    \item For figures/tables: inside the caption
359\end{itemize}
360
361\subsection{Descriptive Labels}
362
363Use meaningful labels:
364
365\begin{itemize}
366    \item \textcolor{green}{\checkmark} \verb|eq:mass_energy_equivalence|
367    \item \textcolor{red}{$\times$} \verb|eq:eq1|
368\end{itemize}
369
370\subsection{The \texttt{cleveref} Package}
371
372For even more sophisticated referencing, consider the \texttt{cleveref} package
373(not loaded in this document):
374
375\begin{verbatim}
376\usepackage{cleveref}
377% Then you can use:
378\cref{eq:quadratic}     % produces "equation (1)"
379\Cref{eq:quadratic}     % produces "Equation (1)"
380\end{verbatim}
381
382% ============================================================================
383\section{Summary Example}
384% ============================================================================
385
386Let's combine several concepts. Consider the Taylor series expansion:
387
388\begin{subequations}
389\label{eq:taylor_series}
390\begin{align}
391f(x) &= \sum_{n=0}^\infty \frac{f^{(n)}(a)}{n!}(x-a)^n \label{eq:taylor_general} \\
392e^x &= \sum_{n=0}^\infty \frac{x^n}{n!} = 1 + x + \frac{x^2}{2!} +
393\frac{x^3}{3!} + \cdots \label{eq:taylor_exp} \\
394\sin x &= \sum_{n=0}^\infty \frac{(-1)^n}{(2n+1)!}x^{2n+1} = x - \frac{x^3}{3!}
395+ \frac{x^5}{5!} - \cdots \label{eq:taylor_sin} \\
396\cos x &= \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!}x^{2n} = 1 - \frac{x^2}{2!} +
397\frac{x^4}{4!} - \cdots \label{eq:taylor_cos}
398\end{align}
399\end{subequations}
400
401The Taylor series (Equations~\ref{eq:taylor_series}) provide polynomial
402approximations to functions. The general form is given by
403\eqref{eq:taylor_general}, with specific examples for the exponential function
404\eqref{eq:taylor_exp}, sine \eqref{eq:taylor_sin}, and cosine
405\eqref{eq:taylor_cos}.
406
407From these, we can derive Euler's formula:
408
409\begin{equation}
410\label{eq:euler_formula}
411e^{ix} = \cos x + i \sin x
412\end{equation}
413
414Substituting $x = \pi$ into Equation~\eqref{eq:euler_formula} yields Euler's
415identity (Equation~\ref{eq:euler} from Section~2.2).
416
417% ============================================================================
418\section{Conclusion}
419% ============================================================================
420
421This document has demonstrated the major methods for numbering and
422referencing equations in \LaTeX:
423
424\begin{itemize}
425    \item \texttt{equation}: single numbered equation
426    \item \texttt{align}: aligned multi-line equations
427    \item \texttt{gather}: centered multi-line equations
428    \item \texttt{multline}: single equation split across lines
429    \item \texttt{split}: aligned equation with single number
430    \item \texttt{subequations}: grouped equations with sub-numbering
431    \item \texttt{cases}: piecewise functions
432\end{itemize}
433
434Remember:
435\begin{enumerate}
436    \item Use \verb|\label| to mark equations
437    \item Use \verb|\ref| or \verb|\eqref| to reference them
438    \item Compile twice for references to resolve
439    \item Use descriptive label names with prefixes
440\end{enumerate}
441
442\end{document}
443
444% ============================================================================
445% COMPILATION TIP
446% ============================================================================
447% You MUST compile TWICE for cross-references to work:
448%   pdflatex equation_numbering.tex
449%   pdflatex equation_numbering.tex
450%
451% On the first pass, LaTeX collects label information.
452% On the second pass, it resolves the references.
453% ============================================================================