> ## Documentation Index
> Fetch the complete documentation index at: https://resources.latex-cloud-studio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LaTeX Mathematics - Getting Started

> Master mathematical typesetting in LaTeX. Learn how to write equations, use math symbols, and create beautiful mathematical documents.

LaTeX is renowned for its superior mathematical typesetting. This guide will take you from basic equations to advanced mathematical expressions.

<Info>
  **Fun fact**: LaTeX's math rendering is so good that even Microsoft Word now uses a LaTeX-like syntax for its equation editor!
</Info>

## Why LaTeX for Math?

Compare these approaches to writing the quadratic formula:

**Plain text**: x = (-b +/- sqrt(b^2 - 4ac)) / 2a

**LaTeX result**: $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$

The difference is clear – LaTeX produces publication-quality mathematics.

## Math Modes

LaTeX has two math modes:

### 1. Inline Math Mode

For math within text, use `$...$` or `\(...\)`:

```latex inline-math.tex theme={null}
The famous equation $E = mc^2$ was
discovered by Einstein. We can also
write \(a^2 + b^2 = c^2\) for the
Pythagorean theorem.
```

<Card title="Rendered Output" icon="eye">
  The famous equation $E = mc^2$ was discovered by Einstein. We can also write $a^2 + b^2 = c^2$ for the Pythagorean theorem.
</Card>

### 2. Display Math Mode

For centered equations on their own line, use `\[...\]` or `equation` environment:

```latex display-math.tex theme={null}
The quadratic formula is:
\[x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\]

For numbered equations, use:
\begin{equation}
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
\end{equation}
```

<Card title="Rendered Output" icon="eye">
  The quadratic formula is:

  $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$

  For numbered equations:

  $\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2} \tag{1}$
</Card>

<Tip>
  Use `\[...\]` for important formulas you want to highlight. Use `$...$` for variables and simple expressions within sentences.
</Tip>

## Basic Math Elements

### Superscripts and Subscripts

```latex super-subscripts.tex theme={null}
% Superscripts with ^
$x^2$, $x^{10}$, $x^{n+1}$

% Subscripts with _
$x_1$, $x_{10}$, $x_{i,j}$

% Combined
$x_1^2$, $a_n^{k+1}$

% Chemical formulas
$\text{H}_2\text{O}$, $\text{CO}_2$
```

<Card title="Rendered Output" icon="eye">
  **Superscripts:** $x^2$, $x^{10}$, $x^{n+1}$

  **Subscripts:** $x_1$, $x_{10}$, $x_{i,j}$

  **Combined:** $x_1^2$, $a_n^{k+1}$

  **Chemical formulas:** $\text{H}_2\text{O}$, $\text{CO}_2$
</Card>

### Fractions

```latex fractions.tex theme={null}
% Simple fractions
$\frac{1}{2}$, $\frac{a}{b}$

% Nested fractions
$\frac{1}{1 + \frac{1}{2}}$

% Display style in inline math
$\displaystyle\frac{a+b}{c+d}$

% Alternative notation
$a/b$ or $^a/_b$
```

<Card title="Rendered Output" icon="eye">
  **Simple fractions:** $\frac{1}{2}$, $\frac{a}{b}$

  **Nested fractions:** $\frac{1}{1 + \frac{1}{2}}$

  **Display style:** $\displaystyle\frac{a+b}{c+d}$

  **Alternative notation:** $a/b$ or $^a/_b$
</Card>

### Roots

```latex roots.tex theme={null}
% Square root
$\sqrt{2}$, $\sqrt{x^2 + y^2}$

% nth root
$\sqrt[3]{8}$, $\sqrt[n]{x}$

% Nested roots
$\sqrt{2 + \sqrt{3}}$
```

<Card title="Rendered Output" icon="eye">
  **Square root:** $\sqrt{2}$, $\sqrt{x^2 + y^2}$

  **nth root:** $\sqrt[3]{8}$, $\sqrt[n]{x}$

  **Nested roots:** $\sqrt{2 + \sqrt{3}}$
</Card>

## Common Math Symbols

### Greek Letters

```latex greek-letters.tex theme={null}
% Lowercase
$\alpha, \beta, \gamma, \delta, \epsilon$
$\theta, \lambda, \mu, \pi, \sigma, \phi$

% Uppercase
$\Gamma, \Delta, \Theta, \Lambda, \Sigma, \Phi$

% Variants
$\epsilon$ vs $\varepsilon$
$\phi$ vs $\varphi$
```

<Card title="Rendered Output" icon="eye">
  **Lowercase:** $\alpha, \beta, \gamma, \delta, \epsilon$ and $\theta, \lambda, \mu, \pi, \sigma, \phi$

  **Uppercase:** $\Gamma, \Delta, \Theta, \Lambda, \Sigma, \Phi$

  **Variants:** $\epsilon$ vs $\varepsilon$ and $\phi$ vs $\varphi$
</Card>

### Operators and Relations

```latex operators.tex theme={null}
% Basic operators
$a + b - c \times d \div e$

% Comparison
$a < b \leq c = d \geq e > f$
$a \neq b \approx c \equiv d$

% Set operations
$A \cup B \cap C \subset D$
$x \in A, y \notin B$

% Logic
$p \land q \lor r \implies s$
$\forall x \exists y$
```

<Card title="Rendered Output" icon="eye">
  **Basic operators:** $a + b - c \times d \div e$

  **Comparison:** $a < b \leq c = d \geq e > f$ and $a \neq b \approx c \equiv d$

  **Set operations:** $A \cup B \cap C \subset D$ and $x \in A, y \notin B$

  **Logic:** $p \land q \lor r \implies s$ and $\forall x \exists y$
</Card>

### Arrows

```latex arrows.tex theme={null}
% Basic arrows
$\rightarrow, \leftarrow, \leftrightarrow$
$\Rightarrow, \Leftarrow, \Leftrightarrow$

% Long arrows
$\longrightarrow, \longleftarrow$

% Special arrows
$\uparrow, \downarrow, \updownarrow$
$\nearrow, \searrow, \swarrow, \nwarrow$
```

<Card title="Rendered Output" icon="eye">
  **Basic arrows:** $\rightarrow, \leftarrow, \leftrightarrow$ and $\Rightarrow, \Leftarrow, \Leftrightarrow$

  **Long arrows:** $\longrightarrow, \longleftarrow$

  **Special arrows:** $\uparrow, \downarrow, \updownarrow$ and $\nearrow, \searrow, \swarrow, \nwarrow$
</Card>

## Functions and Operators

### Standard Functions

```latex functions.tex theme={null}
% Trigonometric
$\sin\theta, \cos\theta, \tan\theta$

% Logarithms
$\log x, \ln x, \log_2 x$

% Limits
$\lim_{x \to 0} \frac{\sin x}{x} = 1$

% Min/Max
$\min(a,b), \max(a,b)$
```

<Card title="Rendered Output" icon="eye">
  **Trigonometric:** $\sin\theta, \cos\theta, \tan\theta$

  **Logarithms:** $\log x, \ln x, \log_2 x$

  **Limits:** $\displaystyle\lim_{x \to 0} \frac{\sin x}{x} = 1$

  **Min/Max:** $\min(a,b), \max(a,b)$
</Card>

### Sums and Products

```latex sums-products.tex theme={null}
% Summation
$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$

% Product
$\prod_{i=1}^{n} i = n!$

% Multiple lines
$\sum_{\substack{i=1 \\ i \neq j}}^{n} a_i$
```

<Card title="Rendered Output" icon="eye">
  **Summation:** $\displaystyle\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$

  **Product:** $\displaystyle\prod_{i=1}^{n} i = n!$

  **Multiple lines:** $\displaystyle\sum_{\substack{i=1 \\ i \neq j}}^{n} a_i$
</Card>

## Integrals and Derivatives

```latex calculus.tex theme={null}
% Derivatives
$f'(x), f''(x), f^{(n)}(x)$
$\frac{df}{dx}, \frac{d^2f}{dx^2}$
$\frac{\partial f}{\partial x}$

% Integrals
$\int f(x)\,dx$
$\int_a^b f(x)\,dx$
$\iint_D f(x,y)\,dx\,dy$

% Special notation
$\oint_C F \cdot dr$
```

<Card title="Rendered Output" icon="eye">
  **Derivatives:** $f'(x), f''(x), f^{(n)}(x)$ and $\frac{df}{dx}, \frac{d^2f}{dx^2}$ and $\frac{\partial f}{\partial x}$

  **Integrals:** $\displaystyle\int f(x)\,dx$ and $\displaystyle\int_a^b f(x)\,dx$ and $\displaystyle\iint_D f(x,y)\,dx\,dy$

  **Special notation:** $\displaystyle\oint_C F \cdot dr$
</Card>

## Matrices and Arrays

### Basic Matrices

```latex matrices.tex theme={null}
% Using pmatrix (parentheses)
$\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}$

% Using bmatrix (brackets)
$\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix}$

% Using vmatrix (determinant)
$\begin{vmatrix}
a & b \\
c & d
\end{vmatrix} = ad - bc$
```

<Card title="Rendered Output" icon="eye">
  **pmatrix (parentheses):** $\begin{pmatrix} a & b \\ c & d \end{pmatrix}$

  **bmatrix (brackets):** $\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}$

  **vmatrix (determinant):** $\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$
</Card>

### Advanced Arrays

```latex arrays.tex theme={null}
% Custom arrays
$\left[
\begin{array}{cc|c}
1 & 2 & 3 \\
4 & 5 & 6
\end{array}
\right]$

% Cases (piecewise functions)
$f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}$
```

<Card title="Rendered Output" icon="eye">
  **Custom arrays:** $\left[ \begin{array}{cc|c} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array} \right]$

  **Cases (piecewise functions):** $f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}$
</Card>

## Spacing in Math Mode

```latex math-spacing.tex theme={null}
% Default spacing
$a b$ vs $ab$

% Manual spacing
$a\,b$     % thin space
$a\:b$     % medium space
$a\;b$     % thick space
$a\quad b$ % quad space
$a\qquad b$ % double quad

% Negative space
$a\!b$     % negative thin space
```

<Card title="Rendered Output" icon="eye">
  **Default:** $a b$ vs $ab$

  **Thin space:** $a\,b$ | **Medium space:** $a\:b$ | **Thick space:** $a\;b$

  **Quad space:** $a\quad b$ | **Double quad:** $a\qquad b$

  **Negative space:** $a\!b$
</Card>

<Tip>
  Use `\,` before differentials in integrals: `\int f(x)\,dx` looks better than `\int f(x)dx`.
</Tip>

## Advanced Features

### Theorem Environments

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex theorems.tex theme={null}
      \documentclass{article}
      \usepackage{amsthm}

      \newtheorem{theorem}{Theorem}
      \newtheorem{lemma}{Lemma}
      \newtheorem{proof}{Proof}

      \begin{document}
      \begin{theorem}[Pythagoras]
      For a right triangle with legs $a$ and $b$ 
      and hypotenuse $c$, we have $a^2 + b^2 = c^2$.
      \end{theorem}

      \begin{proof}
      Consider a square with side length $a + b$...
      \end{proof}
      \end{document}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <div className="latex-preview-shell">
      <div className="latex-preview-paper latex-preview-paper--narrow">
        <p className="latex-preview-paragraph">
          <strong>Theorem 1 (Pythagoras).</strong> For a right triangle with legs
          a and b and hypotenuse c, we have a² + b² = c².
        </p>

        <p className="latex-preview-paragraph">
          <strong>Proof.</strong> Consider a square with side length a + b...
        </p>
      </div>
    </div>
  </Tab>
</Tabs>

### Aligning Equations

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex align.tex theme={null}
      \begin{align}
      2x + 3y &= 7 \\
      x - y &= 1
      \end{align}

      % Multi-line derivation
      \begin{align}
      (x + y)^2 &= (x + y)(x + y) \\
      &= x^2 + xy + yx + y^2 \\
      &= x^2 + 2xy + y^2
      \end{align}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <div className="latex-preview-shell">
      <div className="latex-preview-paper latex-preview-paper--narrow">
        <div className="latex-preview-display-math">
          2x + 3y = 7    (1)<br />
          x - y = 1    (2)
        </div>

        <div className="latex-preview-display-math">
          (x + y)² = (x + y)(x + y)    (3)<br />
          \= x² + xy + yx + y²    (4)<br />
          \= x² + 2xy + y²    (5)
        </div>
      </div>
    </div>
  </Tab>
</Tabs>

## Common Mistakes to Avoid

<Warning>
  **1. Forgetting braces for multi-character super/subscripts**

  * Wrong: `$x^10$` → x¹0
  * Right: `$x^{10}$` → x¹⁰

  **2. Using text in math mode**

  * Wrong: `$x = speed * time$`
  * Right: `$x = \text{speed} \times \text{time}$`

  **3. Incorrect fraction syntax**

  * Wrong: `$\frac{1/2}$`
  * Right: `$\frac{1}{2}$`
</Warning>

## Math Packages

Essential packages for advanced mathematics:

```latex theme={null}
\usepackage{amsmath}   % Advanced math environments
\usepackage{amssymb}   % Additional symbols
\usepackage{mathtools} % Enhanced amsmath
\usepackage{physics}   % Physics notation
\usepackage{siunitx}   % SI units
```

## Practice Exercises

Try typesetting these formulas:

1. **Euler's Identity**: $e^{i\pi} + 1 = 0$
2. **Gaussian Integral**: $\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$
3. **Binomial Theorem**: $(x+y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k$
4. **Maxwell's Equation**: $\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}$

## Quick Reference

| Feature      | Syntax            | Example          |
| ------------ | ----------------- | ---------------- |
| Inline math  | `$...$`           | `$x^2$`          |
| Display math | `\[...\]`         | `\[x^2\]`        |
| Fraction     | `\frac{num}{den}` | `$\frac{a}{b}$`  |
| Square root  | `\sqrt{x}`        | `$\sqrt{2}$`     |
| Subscript    | `_`               | `$x_1$`          |
| Superscript  | `^`               | `$x^2$`          |
| Greek letter | `\alpha`          | `$\alpha$`       |
| Sum          | `\sum`            | `$\sum_{i=1}^n$` |
| Integral     | `\int`            | `$\int_a^b$`     |

## Next Steps

<CardGroup cols={2}>
  <Card title="Math Symbols Reference" icon="symbols" href="/learn/reference/symbols">
    Complete list of mathematical symbols
  </Card>

  <Card title="Advanced Equations" icon="calculator" href="/learn/latex/mathematics/equations">
    Multi-line equations and advanced layouts
  </Card>

  <Card title="Matrices & Arrays" icon="table-cells" href="/learn/latex/mathematics/matrices">
    Complex matrix operations and layouts
  </Card>

  <Card title="Scientific Notation" icon="atom" href="/learn/latex/mathematics/science">
    Physics, chemistry, and scientific formatting
  </Card>
</CardGroup>

***

Ready to create beautiful mathematical documents? You now have the foundation to typeset any mathematical expression in LaTeX!
