Latex Tutorial

Filed under: , , ,

Complete LaTeX Tutorial

Learn mathematical typesetting from basic expressions to calculus, matrices, statistics, logic, and browser rendering with MathJax.

1. What LaTeX is

LaTeX is a typesetting language widely used for mathematics, engineering, science, technical documentation, and academic publishing.

\frac{x+1}{x-1}
\[\frac{x+1}{x-1}\]

Commands usually begin with a backslash, and curly braces group content.

\sqrt{x}
\[\sqrt{x}\]
x^{10}
\[x^{10}\]
a_{n+1}
\[a_{n+1}\]
\alpha+\beta
\[\alpha+\beta\]

2. Inline and display mathematics

Inline

The function is \(f(x)=x^2\).

The function is \(f(x)=x^2\).

Display

\[
f(x)=x^2
\]
\[f(x)=x^2\]

In many Markdown systems, $...$ and $$...$$ are also supported.

3. Powers and subscripts

x^2
\[x^2\]
x^{12}
\[x^{12}\]
x_1
\[x_1\]
a_{n+1}^{(k)}
\[a_{n+1}^{(k)}\]

Use braces whenever an exponent or subscript contains more than one character.

4. Fractions, roots, and brackets

\frac{a}{b}
\[\frac{a}{b}\]
\sqrt{x}
\[\sqrt{x}\]
\sqrt[3]{x}
\[\sqrt[3]{x}\]
\binom{n}{r}
\[\binom{n}{r}\]
\left(\frac{x+1}{x-1}\right)
\[\left(\frac{x+1}{x-1}\right)\]
x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
\[x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}\]

5. Common symbols

PurposeLaTeXRendered
Not equal\ne\(\ne\)
Less/greater than or equal\le \ge\(\le,\ge\)
Approximately\approx\(\approx\)
Plus or minus\pm\(\pm\)
Multiplication\times \cdot\(\times,\cdot\)
Infinity\infty\(\infty\)
Arrow\to \Rightarrow\(\to,\Rightarrow\)
Therefore\therefore\(\therefore\)

6. Greek letters

\alpha \beta \gamma \delta \theta \lambda \mu \pi \rho \sigma \phi \omega
\[ \alpha,\beta,\gamma,\delta,\theta,\lambda,\mu,\pi,\rho,\sigma,\phi,\omega \]
\Gamma \Delta \Theta \Lambda \Pi \Sigma \Phi \Omega
\[ \Gamma,\Delta,\Theta,\Lambda,\Pi,\Sigma,\Phi,\Omega \]

7. Sets and number systems

\[ \mathbb{N},\quad \mathbb{Z},\quad \mathbb{Q},\quad \mathbb{R},\quad \mathbb{C} \]
\{x\in\mathbb{R}\mid x\ge 0\}
\[\{x\in\mathbb{R}\mid x\ge 0\}\]
A\cup B
\[A\cup B\]
A\cap B
\[A\cap B\]
A\subseteq B
\[A\subseteq B\]
\emptyset
\[\emptyset\]

8. Functions, domain, range, and mappings

f:\mathbb{R}\to\mathbb{R},\qquad x\mapsto x^2
\[ f:\mathbb{R}\to\mathbb{R},\qquad x\mapsto x^2 \]
\operatorname{Dom}(f)=[0,\infty)
\[ \operatorname{Dom}(f)=[0,\infty),\qquad \operatorname{Range}(f)=[0,\infty) \]
(f\circ g)(x)=f(g(x))
\[(f\circ g)(x)=f(g(x))\]

9. Aligned equations

\[
\begin{aligned}
2x+5 &= 17 \\
2x &= 12 \\
x &= 6
\end{aligned}
\]
\[ \begin{aligned} 2x+5 &= 17 \\ 2x &= 12 \\ x &= 6 \end{aligned} \]

The & marks the alignment point, and \\ starts a new line.

10. Piecewise functions

\[
f(x)=
\begin{cases}
x^2, & x\ge 0,\\
-x, & x<0.
\end{cases}
\]
\[ f(x)= \begin{cases} x^2, & x\ge 0,\\ -x, & x<0. \end{cases} \]

11. Calculus

\lim_{x\to 0}\frac{\sin x}{x}=1
\[\lim_{x\to 0}\frac{\sin x}{x}=1\]
\frac{d}{dx}(x^2)=2x
\[\frac{d}{dx}(x^2)=2x\]
\int_0^1x^2\,dx
\[\int_0^1x^2\,dx\]
\sum_{i=1}^{n}i
\[\sum_{i=1}^{n}i\]
\frac{\partial f}{\partial x}
\qquad
\frac{d^2y}{dx^2}
\qquad
\iint_D f(x,y)\,dA
\[ \frac{\partial f}{\partial x} \qquad \frac{d^2y}{dx^2} \qquad \iint_D f(x,y)\,dA \]

12. Trigonometry and logarithms

\[ \sin x,\quad \cos x,\quad \tan x,\quad \log x,\quad \ln x,\quad e^x \]
\sin^2\theta+\cos^2\theta=1
\[\sin^2\theta+\cos^2\theta=1\]

13. Vectors and matrices

\begin{pmatrix}
a & b\\
c & d
\end{pmatrix}
\[ \begin{pmatrix} a & b\\ c & d \end{pmatrix} \]
\[ \vec{v},\qquad \mathbf{v},\qquad \begin{vmatrix} a & b\\ c & d \end{vmatrix}=ad-bc \]

14. Probability and statistics

\[ P(A\mid B)=\frac{P(A\cap B)}{P(B)} \]
\[ \mathbb{E}[X],\qquad \operatorname{Var}(X),\qquad X\sim\mathcal{N}(\mu,\sigma^2) \]
s^2=\frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar{x})^2
\[ s^2=\frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar{x})^2 \]

15. Geometry

a^2+b^2=c^2
\[a^2+b^2=c^2\]
A=\pi r^2
\[A=\pi r^2\]
90^\circ
\[90^\circ\]
AB\perp CD
\[AB\perp CD\]
d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}
\[ d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2} \]

16. Logic and relations

\[ \forall,\quad \exists,\quad \neg,\quad \land,\quad \lor,\quad \implies,\quad \iff \]
\forall x\in\mathbb{R},\quad x^2\ge 0
\[\forall x\in\mathbb{R},\quad x^2\ge 0\]

17. Text, spacing, and decoration

x=3\text{ or }x=-3
\[x=3\text{ or }x=-3\]
f(x)=\sqrt{x},\qquad x\ge 0
\[f(x)=\sqrt{x},\qquad x\ge 0\]
\[ \hat{x},\quad \bar{x},\quad \vec{x},\quad \dot{x},\quad \ddot{x},\quad \tilde{x} \]

18. LaTeX in HTML with MathJax

HTML needs a renderer. This page uses MathJax.

<script>
window.MathJax = {
  tex: {
    inlineMath: [['\\(', '\\)'], ['$', '$']],
    displayMath: [['\\[', '\\]'], ['$$', '$$']]
  }
};
</script>

<script
  async
  src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>

Dynamic content

const area = document.getElementById('math-area');

area.textContent = String.raw`\[
  \frac{-b\pm\sqrt{b^2-4ac}}{2a}
\]`;

MathJax.typesetPromise([area]);

Use String.raw in JavaScript to avoid repeatedly escaping backslashes.

19. Common mistakes

ProblemIncorrectCorrect
Multi-digit powerx^12x^{12}
Visible set braces{x}\{x\}
Trigonometric namesin x\sin x
Words in mathx=3 or x=-3x=3\text{ or }x=-3
Tall brackets(\frac ab)\left(\frac ab\right)

20. Practice exercises

  1. Write \(x^2+y^2=r^2\).
  2. Write \(\sqrt{\frac{x+1}{x-1}}\).
  3. Write \(\sum_{i=1}^{n}i^2\).
  4. Write \(\frac{d}{dx}(x^3)=3x^2\).
  5. Write the quadratic formula.
  6. Write a \(2\times2\) matrix.
  7. Write a piecewise absolute-value function.
Show answers
x^2+y^2=r^2

\sqrt{\frac{x+1}{x-1}}

\sum_{i=1}^{n}i^2

\frac{d}{dx}(x^3)=3x^2

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

\begin{pmatrix}
a & b\\
c & d
\end{pmatrix}

|x|=
\begin{cases}
x, & x\ge 0,\\
-x, & x<0.
\end{cases}

21. Quick reference

Powers:       x^2, x^{10}
Subscripts:   x_1, a_{n+1}
Fractions:    \frac{a}{b}
Roots:        \sqrt{x}, \sqrt[n]{x}
Sets:         \in, \subseteq, \cup, \cap, \mathbb{R}
Calculus:     \sum, \lim, \frac{d}{dx}, \int
Logic:        \forall, \exists, \neg, \land, \lor, \implies
Spacing:      \,, \quad, \qquad
Text:         \text{...}, \operatorname{...}
Layouts:      aligned, cases, pmatrix, bmatrix, array

The fastest way to learn is to copy a working expression, change one part at a time, and render it immediately.

Back to top ↑