1% ============================================================================
2% advanced_math.tex - Advanced Mathematical Typesetting
3% ============================================================================
4% This document demonstrates advanced mathematical features including matrices,
5% cases, theorem environments, custom operators, and complex multi-line
6% equation alignments.
7%
8% Compilation:
9% pdflatex advanced_math.tex (run twice for cross-references)
10% ============================================================================
11
12\documentclass[11pt]{article}
13
14\usepackage{amsmath}
15\usepackage{amssymb}
16\usepackage{amsthm}
17\usepackage{mathtools} % Extension to amsmath
18
19\usepackage[margin=1in]{geometry}
20\usepackage[T1]{fontenc}
21\usepackage{lmodern}
22
23% For colored boxes and highlighting
24\usepackage{xcolor}
25\usepackage{tcolorbox}
26
27% Graphics for diagrams
28\usepackage{tikz}
29\usetikzlibrary{matrix, arrows}
30
31\usepackage{hyperref}
32\hypersetup{colorlinks=true, linkcolor=blue}
33
34% ============================================================================
35% THEOREM ENVIRONMENTS
36% ============================================================================
37
38\theoremstyle{plain}
39\newtheorem{theorem}{Theorem}[section]
40\newtheorem{lemma}[theorem]{Lemma}
41\newtheorem{proposition}[theorem]{Proposition}
42\newtheorem{corollary}[theorem]{Corollary}
43
44\theoremstyle{definition}
45\newtheorem{definition}[theorem]{Definition}
46\newtheorem{example}[theorem]{Example}
47
48\theoremstyle{remark}
49\newtheorem{remark}[theorem]{Remark}
50\newtheorem{note}[theorem]{Note}
51
52% Proof environment is already defined by amsthm
53
54% ============================================================================
55% CUSTOM OPERATORS AND COMMANDS
56% ============================================================================
57
58% Custom operators (formatted correctly with spacing)
59\DeclareMathOperator{\Tr}{Tr} % Trace
60\DeclareMathOperator{\rank}{rank} % Matrix rank
61\DeclareMathOperator{\diag}{diag} % Diagonal matrix
62\DeclareMathOperator{\sgn}{sgn} % Sign function
63\DeclareMathOperator{\Span}{span} % Linear span
64\DeclareMathOperator{\im}{im} % Image
65\DeclareMathOperator*{\argmax}{arg\,max} % Argmax (with limits)
66\DeclareMathOperator*{\argmin}{arg\,min} % Argmin (with limits)
67
68% Custom commands
69\newcommand{\R}{\mathbb{R}}
70\newcommand{\C}{\mathbb{C}}
71\newcommand{\N}{\mathbb{N}}
72\newcommand{\Z}{\mathbb{Z}}
73\newcommand{\Q}{\mathbb{Q}}
74
75\newcommand{\norm}[1]{\left\| #1 \right\|}
76\newcommand{\abs}[1]{\left| #1 \right|}
77\newcommand{\ip}[2]{\left\langle #1, #2 \right\rangle}
78
79\title{Advanced Mathematical Typesetting in \LaTeX}
80\author{Mathematics Department}
81\date{\today}
82
83\begin{document}
84
85\maketitle
86
87\tableofcontents
88
89\section{Introduction}
90
91This document demonstrates advanced mathematical typesetting techniques in
92\LaTeX, building upon basic mathematics to show matrices, theorem environments,
93custom operators, and sophisticated alignment strategies.
94
95% ============================================================================
96\section{Matrices and Determinants}
97% ============================================================================
98
99\subsection{Basic Matrix Environments}
100
101\LaTeX{} provides several matrix environments with different delimiters:
102
103\begin{align*}
104\begin{matrix}
105a & b \\
106c & d
107\end{matrix} \quad
108\begin{pmatrix}
109a & b \\
110c & d
111\end{pmatrix} \quad
112\begin{bmatrix}
113a & b \\
114c & d
115\end{bmatrix} \quad
116\begin{vmatrix}
117a & b \\
118c & d
119\end{vmatrix} \quad
120\begin{Vmatrix}
121a & b \\
122c & d
123\end{Vmatrix}
124\end{align*}
125
126From left to right: \texttt{matrix}, \texttt{pmatrix}, \texttt{bmatrix},
127\texttt{vmatrix} (determinant), \texttt{Vmatrix} (norm).
128
129\subsection{Larger Matrices}
130
131\begin{equation}
132A = \begin{bmatrix}
133a_{11} & a_{12} & a_{13} & \cdots & a_{1n} \\
134a_{21} & a_{22} & a_{23} & \cdots & a_{2n} \\
135\vdots & \vdots & \vdots & \ddots & \vdots \\
136a_{m1} & a_{m2} & a_{m3} & \cdots & a_{mn}
137\end{bmatrix}
138\end{equation}
139
140Identity matrix:
141\begin{equation}
142I_3 = \begin{pmatrix}
1431 & 0 & 0 \\
1440 & 1 & 0 \\
1450 & 0 & 1
146\end{pmatrix}
147\end{equation}
148
149\subsection{Special Matrix Types}
150
151Diagonal matrix using custom operator:
152\begin{equation}
153D = \diag(d_1, d_2, \ldots, d_n) = \begin{pmatrix}
154d_1 & 0 & \cdots & 0 \\
1550 & d_2 & \cdots & 0 \\
156\vdots & \vdots & \ddots & \vdots \\
1570 & 0 & \cdots & d_n
158\end{pmatrix}
159\end{equation}
160
161Block matrix:
162\begin{equation}
163M = \left[\begin{array}{c|c}
164A & B \\
165\hline
166C & D
167\end{array}\right]
168\end{equation}
169
170Augmented matrix for linear systems:
171\begin{equation}
172\left[\begin{array}{ccc|c}
1731 & 2 & 3 & 4 \\
1740 & 1 & 5 & 6 \\
1750 & 0 & 1 & 7
176\end{array}\right]
177\end{equation}
178
179\subsection{Matrix Operations}
180
181\begin{theorem}[Matrix Multiplication]
182\label{thm:matmul}
183For matrices $A \in \R^{m \times n}$ and $B \in \R^{n \times p}$, the
184product $C = AB \in \R^{m \times p}$ has entries:
185\begin{equation}
186c_{ij} = \sum_{k=1}^n a_{ik} b_{kj}
187\end{equation}
188\end{theorem}
189
190\begin{example}
191\begin{equation}
192\begin{pmatrix}
1931 & 2 \\
1943 & 4
195\end{pmatrix}
196\begin{pmatrix}
1975 & 6 \\
1987 & 8
199\end{pmatrix}
200=
201\begin{pmatrix}
20219 & 22 \\
20343 & 50
204\end{pmatrix}
205\end{equation}
206\end{example}
207
208% ============================================================================
209\section{The \texttt{cases} Environment}
210% ============================================================================
211
212\subsection{Piecewise Functions}
213
214The \texttt{cases} environment is ideal for piecewise definitions:
215
216\begin{equation}
217f(x) = \begin{cases}
218x^2 & \text{if } x \geq 0 \\
219-x^2 & \text{if } x < 0
220\end{cases}
221\end{equation}
222
223\begin{example}[Heaviside Step Function]
224\begin{equation}
225H(x) = \begin{cases}
2260 & \text{if } x < 0 \\
227\frac{1}{2} & \text{if } x = 0 \\
2281 & \text{if } x > 0
229\end{cases}
230\end{equation}
231\end{example}
232
233\subsection{Recursive Definitions}
234
235The Fibonacci sequence:
236
237\begin{equation}
238F(n) = \begin{cases}
2390 & \text{if } n = 0 \\
2401 & \text{if } n = 1 \\
241F(n-1) + F(n-2) & \text{if } n \geq 2
242\end{cases}
243\end{equation}
244
245\subsection{Multiple Cases}
246
247\begin{equation}
248\text{grade}(x) = \begin{cases}
249\text{A} & \text{if } 90 \leq x \leq 100 \\
250\text{B} & \text{if } 80 \leq x < 90 \\
251\text{C} & \text{if } 70 \leq x < 80 \\
252\text{D} & \text{if } 60 \leq x < 70 \\
253\text{F} & \text{if } 0 \leq x < 60
254\end{cases}
255\end{equation}
256
257% ============================================================================
258\section{Theorem Environments}
259% ============================================================================
260
261\subsection{Theorems, Lemmas, and Propositions}
262
263\begin{definition}[Inner Product Space]
264\label{def:inner_product}
265An inner product space is a vector space $V$ over $\R$ or $\C$ equipped with
266an inner product $\ip{\cdot}{\cdot}: V \times V \to \R$ (or $\C$) satisfying:
267\begin{enumerate}
268 \item Linearity: $\ip{ax + by}{z} = a\ip{x}{z} + b\ip{y}{z}$
269 \item Symmetry: $\ip{x}{y} = \overline{\ip{y}{x}}$
270 \item Positive definiteness: $\ip{x}{x} \geq 0$ with equality iff $x = 0$
271\end{enumerate}
272\end{definition}
273
274\begin{lemma}[Cauchy-Schwarz Inequality]
275\label{lem:cauchy_schwarz}
276For any vectors $x, y$ in an inner product space:
277\begin{equation}
278\abs{\ip{x}{y}} \leq \norm{x} \norm{y}
279\end{equation}
280with equality if and only if $x$ and $y$ are linearly dependent.
281\end{lemma}
282
283\begin{theorem}[Spectral Theorem for Symmetric Matrices]
284\label{thm:spectral}
285Let $A \in \R^{n \times n}$ be a symmetric matrix. Then:
286\begin{enumerate}
287 \item All eigenvalues of $A$ are real
288 \item Eigenvectors corresponding to distinct eigenvalues are orthogonal
289 \item $A$ can be diagonalized as $A = Q\Lambda Q^T$ where $Q$ is orthogonal
290 and $\Lambda$ is diagonal
291\end{enumerate}
292\end{theorem}
293
294\begin{proof}
295Let $\lambda$ be an eigenvalue with eigenvector $v$. Then $Av = \lambda v$.
296Taking the conjugate transpose:
297\begin{align}
298v^* A^* &= \lambda^* v^* \\
299v^* A &= \lambda^* v^* \quad \text{(since $A$ is symmetric)}
300\end{align}
301Multiplying the first equation on the left by $v^*$:
302\begin{equation}
303v^* A v = \lambda v^* v
304\end{equation}
305Multiplying the second on the right by $v$:
306\begin{equation}
307v^* A v = \lambda^* v^* v
308\end{equation}
309Therefore $\lambda = \lambda^*$, so $\lambda \in \R$.
310\end{proof}
311
312\begin{corollary}
313\label{cor:eigenvalues_real}
314Real symmetric matrices have real eigenvalues.
315\end{corollary}
316
317\begin{remark}
318Theorem~\ref{thm:spectral} is fundamental in many applications including
319principal component analysis (PCA) and quadratic form optimization.
320\end{remark}
321
322% ============================================================================
323\section{Custom Operators}
324% ============================================================================
325
326\subsection{Declaring Math Operators}
327
328Custom operators are declared in the preamble using
329\verb|\DeclareMathOperator|:
330
331\begin{verbatim}
332\DeclareMathOperator{\Tr}{Tr}
333\DeclareMathOperator{\rank}{rank}
334\DeclareMathOperator*{\argmax}{arg\,max}
335\end{verbatim}
336
337The starred version \verb|\DeclareMathOperator*| allows limits above and below.
338
339\subsection{Usage Examples}
340
341Trace of a matrix:
342\begin{equation}
343\Tr(A) = \sum_{i=1}^n a_{ii}
344\end{equation}
345
346Matrix rank:
347\begin{equation}
348\rank(A) \leq \min(m, n) \quad \text{for } A \in \R^{m \times n}
349\end{equation}
350
351Argmax with limits:
352\begin{equation}
353\theta^* = \argmax_{\theta \in \Theta} \mathcal{L}(\theta; \mathcal{D})
354\end{equation}
355
356Sign function:
357\begin{equation}
358\sgn(x) = \begin{cases}
359-1 & \text{if } x < 0 \\
3600 & \text{if } x = 0 \\
3611 & \text{if } x > 0
362\end{cases}
363\end{equation}
364
365% ============================================================================
366\section{Multi-Line Equations with Complex Alignment}
367% ============================================================================
368
369\subsection{The \texttt{align} Environment}
370
371\begin{align}
372(a + b)^3 &= (a + b)(a + b)^2 \\
373 &= (a + b)(a^2 + 2ab + b^2) \\
374 &= a^3 + 2a^2b + ab^2 + a^2b + 2ab^2 + b^3 \\
375 &= a^3 + 3a^2b + 3ab^2 + b^3
376\end{align}
377
378\subsection{The \texttt{gather} Environment}
379
380For equations that don't need alignment:
381
382\begin{gather}
383\nabla \cdot \mathbf{E} = \frac{\rho}{\epsilon_0} \\
384\nabla \cdot \mathbf{B} = 0 \\
385\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t} \\
386\nabla \times \mathbf{B} = \mu_0\mathbf{J} +
387\mu_0\epsilon_0\frac{\partial \mathbf{E}}{\partial t}
388\end{gather}
389
390\subsection{The \texttt{multline} Environment}
391
392For a single long equation:
393
394\begin{multline}
395f(x_1, x_2, \ldots, x_n) = x_1^2 + x_2^2 + \cdots + x_n^2 \\
396+ 2x_1x_2 + 2x_1x_3 + \cdots + 2x_1x_n \\
397+ 2x_2x_3 + 2x_2x_4 + \cdots + 2x_2x_n \\
398+ \cdots + 2x_{n-1}x_n
399\end{multline}
400
401\subsection{Aligned Equations with Conditions}
402
403\begin{equation}
404\begin{aligned}
405\text{minimize} \quad & \frac{1}{2}\norm{x}^2 \\
406\text{subject to} \quad & Ax = b \\
407 & x \geq 0
408\end{aligned}
409\end{equation}
410
411Or using \texttt{array} for more control:
412
413\begin{equation}
414\begin{array}{ll}
415\text{maximize} & c^T x \\
416\text{subject to} & Ax \leq b \\
417 & x \geq 0
418\end{array}
419\end{equation}
420
421% ============================================================================
422\section{Advanced Equation Formatting}
423% ============================================================================
424
425\subsection{Underbrace and Overbrace}
426
427\begin{equation}
428\overbrace{a + b + c}^{\text{sum}} = \underbrace{d + e + f}_{\text{also sum}}
429\end{equation}
430
431\begin{equation}
432z = \overbrace{
433 \underbrace{x}_{\text{real}} + i\underbrace{y}_{\text{imaginary}}
434}^{\text{complex number}}
435\end{equation}
436
437\subsection{Stacked Relations}
438
439\begin{equation}
440A \xleftarrow[\text{row operations}]{\text{elementary}} B
441\xrightarrow[\text{column operations}]{\text{elementary}} C
442\end{equation}
443
444Using \texttt{mathtools} package:
445
446\begin{equation}
447f(n) \xlongequal{\text{def}} \sum_{i=0}^n i^2
448\end{equation}
449
450\subsection{Text in Math Mode}
451
452\begin{equation}
453P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)}
454\quad \text{where } P(B) \neq 0
455\end{equation}
456
457\subsection{Multi-Line Subscripts and Superscripts}
458
459\begin{equation}
460\sum_{\substack{0 \leq i \leq n \\ 0 \leq j \leq m}} a_{ij}
461\end{equation}
462
463\begin{equation}
464\prod_{\substack{p \text{ prime} \\ p < 100}} p
465\end{equation}
466
467% ============================================================================
468\section{Commutative Diagrams (Optional)}
469% ============================================================================
470
471Using TikZ for commutative diagrams:
472
473\begin{equation}
474\begin{tikzcd}
475A \arrow[r, "f"] \arrow[d, "g"'] & B \arrow[d, "h"] \\
476C \arrow[r, "k"'] & D
477\end{tikzcd}
478\end{equation}
479
480% ============================================================================
481\section{Complex Example: Lagrange Multipliers}
482% ============================================================================
483
484\begin{theorem}[Method of Lagrange Multipliers]
485\label{thm:lagrange}
486Let $f: \R^n \to \R$ and $g: \R^n \to \R$ be continuously differentiable.
487To find extrema of $f$ subject to the constraint $g(x) = 0$, solve:
488\begin{equation}
489\nabla f(x^*) = \lambda \nabla g(x^*)
490\end{equation}
491where $\lambda$ is the Lagrange multiplier.
492\end{theorem}
493
494\begin{example}
495Find the maximum and minimum of $f(x,y) = xy$ subject to $x^2 + y^2 = 1$.
496
497\begin{align}
498\text{Lagrangian: } \mathcal{L}(x, y, \lambda) &= xy - \lambda(x^2 + y^2 - 1)
499\end{align}
500
501Setting partial derivatives to zero:
502\begin{align}
503\frac{\partial \mathcal{L}}{\partial x} &= y - 2\lambda x = 0 \\
504\frac{\partial \mathcal{L}}{\partial y} &= x - 2\lambda y = 0 \\
505\frac{\partial \mathcal{L}}{\partial \lambda} &= -(x^2 + y^2 - 1) = 0
506\end{align}
507
508From the first two equations: $y = 2\lambda x$ and $x = 2\lambda y$, so:
509\begin{equation}
510x = 2\lambda(2\lambda x) = 4\lambda^2 x
511\end{equation}
512
513If $x \neq 0$: $1 = 4\lambda^2$, so $\lambda = \pm \frac{1}{2}$.
514
515Critical points occur at $\left(\pm\frac{1}{\sqrt{2}}, \pm\frac{1}{\sqrt{2}}\right)$
516with values:
517\begin{equation}
518f\left(\frac{1}{\sqrt{2}}, \frac{1}{\sqrt{2}}\right) = \frac{1}{2} \quad
519\text{(maximum)}
520\end{equation}
521\begin{equation}
522f\left(\frac{1}{\sqrt{2}}, -\frac{1}{\sqrt{2}}\right) = -\frac{1}{2} \quad
523\text{(minimum)}
524\end{equation}
525\end{example}
526
527% ============================================================================
528\section{Conclusion}
529% ============================================================================
530
531This document has demonstrated advanced mathematical typesetting including:
532
533\begin{itemize}
534 \item Matrix environments with various delimiters
535 \item Piecewise functions using \texttt{cases}
536 \item Theorem-like environments (theorem, lemma, proof, etc.)
537 \item Custom mathematical operators
538 \item Multi-line equation alignment with \texttt{align}, \texttt{gather},
539 \texttt{multline}
540 \item Advanced formatting techniques (underbrace, overbrace, stacked
541 relations)
542\end{itemize}
543
544With these tools, you can typeset virtually any mathematical content with
545professional quality.
546
547\end{document}
548
549% ============================================================================
550% PACKAGE REQUIREMENTS
551% ============================================================================
552% This document requires:
553% - amsmath, amssymb, amsthm (standard math packages)
554% - mathtools (extension to amsmath)
555% - tikz-cd (for commutative diagrams, optional)
556%
557% Compile with: pdflatex advanced_math.tex (twice for cross-references)
558% ============================================================================