LaTeX is a powerful typesetting system that excels at creating beautiful mathematical expressions. This tutorial will guide you from basic math notation to advanced mathematical typesetting.

If you are looking for instructions on how to write math and scientific expressions using the simpler AsciiMath format, use this tutorials.

1. Getting Started with Math Mode

In LaTeX, mathematical expressions are written in special "math mode." There are two types:

Inline Math

For math within a sentence, use single dollar signs:

Code:
The formula \$E = mc^2\$ is famous.
Result: The formula $ E = mc^2 $ is famous.

Display Math

For standalone equations, use double dollar signs:

Code:
\$\$E = mc^2\$\$
Result: $$E = mc^2$$

2. Escaping the Dollar Sign ($)

Since the dollar sign ($) is used to enter and exit math mode in LaTeX, you need special techniques to display an actual dollar sign in your text.

In Regular Text

To display a dollar sign in regular text (outside of math mode), use a backslash before the dollar sign:

Code:
The price is \\\$19.99 for the book.
Result: The price is $19.99 for the book.

In Math Mode

If you need to display a dollar sign within a mathematical expression, you have several options:

Method 1: Using \text{} command

Code:
\$\$\text{Cost} = \text{\$}50 + 0.05x\$\$
Result: $$\text{Cost} = \text{\$}50 + 0.05x$$

Method 2: Using \$ within \text{}

Code:
\$\$P = \text{\$1000} \times (1 + r)^t\$\$
Result: $$P = \text{\$1000} \times (1 + r)^t$$

Mixed Text and Math

Code:
If you invest \\\$1000 at 5% interest, after \$t\$ years you will have \$A = 1000(1.05)^t\$ dollars.
Result: If you invest \$1000 at 5% interest, after $t$ years you will have $A = 1000(1.05)^t$ dollars.
Remember: The backslash (\) is the escape character in LaTeX. Always use \\\$ when you want to display an actual dollar sign rather than enter math mode.
Best Practice: In mathematical contexts involving money, consider using the \text{} command to clearly distinguish currency symbols from mathematical operations.

3. Basic Mathematical Operations

Simple Operations

Operation LaTeX Code Result
Addition \$a + b\$ \$a + b\$
Subtraction \$a - b\$ $a - b$
Multiplication \$a \times b\$ or \$a \cdot b\$ $a \times b$ or $a \cdot b$
Division \$a \div b\$ $a \div b$
Equals \$a = b\$ $a = b$

Superscripts and Subscripts

Superscripts (exponents):
\$x^2\$, \$x^{10}\$, \$x^{2y+1}\$
Result: $x^2$, $x^{10}$, $x^{2y+1}$
Subscripts:
\$a_1\$, \$a_{10}\$, \$a_{i+1}\$
Result: $a_1$, $a_{10}$, $a_{i+1}$
Use curly braces {} when your superscript or subscript contains more than one character.

4. Fractions and Roots

Fractions

Code:
\$\$\frac{a}{b}\$\$
Result: $$\frac{a}{b}$$
Complex fractions:
\$\$\frac{x^2 + 2x + 1}{x - 1}\$\$
Result: \$\$\frac{x^2 + 2x + 1}{x - 1}\$\$

Square Roots and Radicals

Code:
\$\sqrt{x}\$, \$\sqrt{x^2 + y^2}\$, \$\sqrt[3]{27}\$
Result: $\sqrt{x}$, $\sqrt{x^2 + y^2}$, $\sqrt[3]{27}$

5. Greek Letters and Special Symbols

Common Greek Letters

Letter Lowercase Uppercase
Alpha \$\\alpha\$ -- $\alpha$ \$A\$ -- $A$
Beta \$\\beta\$ -- $\beta$ \$B\$ -- $B$
Gamma \$\\gamma\$ -- $\gamma$ \$\\Gamma\$ -- $\Gamma$
Delta \$\\delta\$ -- $\delta$ \$\\Delta\$ -- $\Delta$
Pi \$\\pi\$ -- $\pi$ \$\\Pi\$ -- $\Pi$
Sigma \$\\sigma\$ -- $\sigma$ \$\\Sigma\$ -- $\Sigma$
Theta \$\\theta\$ -- $\theta$ \$\\Theta\$ -- $\Theta$
Lambda \$\\lambda\$ -- $\lambda$ \$\\Lambda\$ -- $\Lambda$

Special Symbols

Symbol LaTeX Code Result
Infinity \infty $\infty$
Plus/minus \pm $\pm$
Not equal \neq $\neq$
Less than or equal \leq $\leq$
Greater than or equal \geq $\geq$
Approximately \approx $\approx$

6. Functions and Operators

Trigonometric Functions

Code:
\$\\sin(x)\$, \$\\cos(x)\$, \$\\tan(x)\$
Result: $\sin(x)$, $\cos(x)$, $\tan(x)$

Logarithms

Code:
\$\\log(x)\$, \$\\ln(x)\$, \$\\log_2(x)\$
Result: $\log(x)$, $\ln(x)$, $\log_2(x)$

Limits

Code:
\$\$\\lim_{x \\to 0} \\frac{\\sin(x)}{x} = 1\$\$
Result: $$\lim_{x \to 0} \frac{\sin(x)}{x} = 1$$

7. Sums, Products, and Integrals

Summation

Code:
\$\$\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}\$\$
Result: $$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$$

Product

Code:
\$\$\\prod_{i=1}^{n} i = n!\$\$
Result: $$\prod_{i=1}^{n} i = n!$$

Integrals

Indefinite integral:
\$\$\\int x^2 \\, dx = \\frac{x^3}{3} + C\$\$
Result: $$\int x^2 \, dx = \frac{x^3}{3} + C$$
Definite integral:
\$\$\\int_0^1 x^2 \\, dx = \\frac{1}{3}\$\$
Result: $$\int_0^1 x^2 \, dx = \frac{1}{3}$$

8. Matrices and Arrays

Basic Matrix

Code:
\$\$\\begin{matrix} a & b \\\\ c & d \\end{matrix}\$\$
Result: $$\begin{matrix} a & b \\ c & d \end{matrix}$$

Matrix with Brackets

Code:
\$\$\\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9 \\end{bmatrix}\$\$
Result: $$\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}$$

Determinant

Code:
\$\$\\begin{vmatrix} a & b \\\\ c & d \\end{vmatrix} = ad - bc\$\$
Result: $$\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$$

9. Advanced Features

Multi-line Equations

Code:
\$\$\\begin{align} f(x) &= x^2 + 2x + 1 \\\\ &= (x + 1)^2 \\end{align}\$\$
Result: $$\begin{align} f(x) &= x^2 + 2x + 1 \\ &= (x + 1)^2 \end{align}$$

Cases (Piecewise Functions)

Code:
\$\$f(x) = \\begin{cases} x^2 & \\text{if } x \\geq 0 \\\\ -x^2 & \\text{if } x < 0 \\end{cases}\$\$
Result: $$f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x^2 & \text{if } x < 0 \end{cases}$$

Binomial Coefficients

Code:
\$\$\\binom{n}{k} = \\frac{n!}{k!(n-k)!}\$\$
Result: $$\binom{n}{k} = \frac{n!}{k!(n-k)!}$$

Derivatives

Code:
\$\$\\frac{d}{dx}f(x) = f'(x)\$\$
Result: $$\frac{d}{dx}f(x) = f'(x)$$
Partial derivatives:
\$\$\\frac{\\partial f}{\\partial x}\$\$
Result: $$\frac{\partial f}{\partial x}$$

10. Formatting Tips

Spacing

LaTeX automatically handles most spacing, but you can add manual spacing:

Command Description Example
\\, Small space \$a\\,b\$ vs \$ab\$
\\; Medium space \$a\\;b\$
\\quad Large space \$a\\quad b\$
\\qquad Very large space \$a\\qquad b\$

Text in Math Mode

Code:
\$\$P(\\text{heads}) = \\frac{1}{2}\$\$
Result: $$P(\text{heads}) = \frac{1}{2}$$

Font Styles in Math

Style Command Example
Bold \\mathbf{} \$\\mathbf{x}\$
Italic \\mathit{} \$\\mathit{text}\$
Roman \\mathrm{} \$\\mathrm{d}x\$
Calligraphic \\mathcal{} \$\\mathcal{L}\$
Blackboard bold \\mathbb{} \$\\mathbb{R}\$

11. Common Mistakes to Avoid

Mistake: Writing \$sin x\$ instead of \$\\sin x\$
Problem: This treats "sin" as three separate variables
Solution: Always use backslash before function names: \$\\sin x\$
Mistake: Writing \$x^2y\$ instead of \$x^{2y}\$
Problem: Only the "2" is superscripted: \$x^2y\$
Solution: Use braces for multi-character exponents: \$x^{2y}\$
Mistake: Not using display math for complex equations
Problem: Inline fractions like \$\\frac{a+b}{c+d}\$ look cramped
Solution: Use display math: \$\$\\frac{a+b}{c+d}\$\$

Practice Exercises

Try writing these mathematical expressions:

  1. The quadratic formula: $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$
  2. Euler's identity: $e^{i\pi} + 1 = 0$
  3. The binomial theorem: $(x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k$
  4. A 3×3 identity matrix
  5. The definition of a derivative using limits

Conclusion

This tutorial covers the fundamentals of LaTeX mathematical notation. With practice, you'll be able to create professional-looking mathematical documents. Remember to:

  • Use curly braces {} for grouping
  • Choose appropriate math mode (inline vs display)
  • Use proper function names with backslashes
  • Pay attention to spacing and alignment

For more advanced features and complete documentation, consult the LaTeX documentation and math symbol references available online.