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}
Commands usually begin with a backslash, and curly braces group content.
\sqrt{x}x^{10}a_{n+1}\alpha+\beta2. Inline and display mathematics
Inline
The function is \(f(x)=x^2\).
The function is \(f(x)=x^2\).
Display
\[
f(x)=x^2
\]
In many Markdown systems, $...$ and $$...$$ are also supported.
3. Powers and subscripts
x^2x^{12}x_1a_{n+1}^{(k)}Use braces whenever an exponent or subscript contains more than one character.
4. Fractions, roots, and brackets
\frac{a}{b}\sqrt{x}\sqrt[3]{x}\binom{n}{r}\left(\frac{x+1}{x-1}\right)
x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
5. Common symbols
| Purpose | LaTeX | Rendered |
|---|---|---|
| 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
\Gamma \Delta \Theta \Lambda \Pi \Sigma \Phi \Omega
7. Sets and number systems
\{x\in\mathbb{R}\mid x\ge 0\}
A\cup BA\cap BA\subseteq B\emptyset8. Functions, domain, range, and mappings
f:\mathbb{R}\to\mathbb{R},\qquad x\mapsto x^2
\operatorname{Dom}(f)=[0,\infty)
(f\circ g)(x)=f(g(x))
9. Aligned equations
\[
\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}
\]
11. Calculus
\lim_{x\to 0}\frac{\sin x}{x}=1\frac{d}{dx}(x^2)=2x\int_0^1x^2\,dx\sum_{i=1}^{n}i\frac{\partial f}{\partial x}
\qquad
\frac{d^2y}{dx^2}
\qquad
\iint_D f(x,y)\,dA
12. Trigonometry and logarithms
\sin^2\theta+\cos^2\theta=1
13. Vectors and matrices
\begin{pmatrix}
a & b\\
c & d
\end{pmatrix}
14. Probability and statistics
s^2=\frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar{x})^2
15. Geometry
a^2+b^2=c^2A=\pi r^290^\circAB\perp CDd=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}
16. Logic and relations
\forall x\in\mathbb{R},\quad x^2\ge 0
17. Text, spacing, and decoration
x=3\text{ or }x=-3
f(x)=\sqrt{x},\qquad x\ge 0
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
| Problem | Incorrect | Correct |
|---|---|---|
| Multi-digit power | x^12 | x^{12} |
| Visible set braces | {x} | \{x\} |
| Trigonometric name | sin x | \sin x |
| Words in math | x=3 or x=-3 | x=3\text{ or }x=-3 |
| Tall brackets | (\frac ab) | \left(\frac ab\right) |
20. Practice exercises
- Write \(x^2+y^2=r^2\).
- Write \(\sqrt{\frac{x+1}{x-1}}\).
- Write \(\sum_{i=1}^{n}i^2\).
- Write \(\frac{d}{dx}(x^3)=3x^2\).
- Write the quadratic formula.
- Write a \(2\times2\) matrix.
- 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 ↑