Writing Math in LaTeX
Introduction
is the universal standard for writing mathematical expressions. Coupled with modern editors like VS Code, Obsidian, or Overleaf, it allows you to write mathematics efficiently on a PC.
Why LaTeX?
With LaTeX, you can write absolutely anything in mathematics:
- Simple or complex equations with fractions, roots, indices
- Matrices, determinants, systems of equations
- Multiple integrals, partial derivatives
- Specialized symbols (quantum physics, set theory, logic)
- Commutative diagrams, graphs
- Musical notation, chess, chemistry...
The good news: It is impossible (and useless) to know all LaTeX commands by heart. There are thousands of them, and even experts regularly look up the exact syntax.
Don't worry if you don't remember everything immediately. Mastery comes with practice. Commands you use often (fractions, sums, integrals) will naturally engrave themselves in your memory. For the rest, there are tools!
Detexify: Your Best Ally
Detexify is a magical tool that recognizes symbols drawn with the mouse:
- Draw approximately the symbol you're looking for
- The AI suggests corresponding LaTeX commands
- Copy the command and use it in your document
Recommended workflow for beginners:
- Use Detexify every time you're looking for an unknown symbol
- Note the commands you use frequently
- After a few weeks, you'll naturally know the common symbols
- Create snippets for commands you type often (see following sections)
At first, keep Detexify open in a tab. Over time, you'll barely need it for common mathematics, but it will remain essential for rare or specialized symbols.
Learning objectives:
- Master basic mathematical syntax in LaTeX
- Be autonomous in learning new commands
- Use Detexify to quickly find symbols
- Create custom snippets to speed up typing
- Use LaTeX in different environments (Markdown, Overleaf)
Example of what you'll be able to do:
What is written above is false, it's only for demonstration purposes!
Prerequisites & Installation
Several options are available for writing mathematical expressions in LaTeX.
- Markdown on VS Code
- Markdown on Obsidian
- LaTeX on Overleaf (online)
- LaTeX on VS Code
Code editor with LaTeX rendering via extensions: code.visualstudio.com
Recommended extensions:
Note-taking in Markdown with native LaTeX rendering: obsidian.md
Recommended plugins:
Online, collaborative LaTeX IDE: overleaf.com
Always load \usepackage{amsmath,amssymb,mathtools} in the preamble.
Code editor with local LaTeX compilation: code.visualstudio.com
Add the LaTeX Workshop extension for compilation, snippets, and preview.
Install a LaTeX distribution:
- TeX Live: Recommended LaTeX distribution (Windows/macOS/Linux)
- MiKTeX: Lighter alternative to TeX Live
Always load \usepackage{amsmath,amssymb,mathtools} in the preamble.
Math Modes
LaTeX offers two modes for writing mathematics. Understanding these modes is essential as they influence the rendering of symbols and spacing.
Inline vs Display Mode
| Mode | Syntax | Usage | Rendering |
|---|---|---|---|
| Inline | $ ... $ or \( ... \) | Mathematics within running text | Compact, reduced indices/exponents |
| Display | $$ ... $$ or \[ ... \] | Equations centered on their own line | Enlarged, indices/exponents placed above/below |
Example:
The Pythagorean theorem is written $a^2 + b^2 = c^2$ for a right triangle.
$$
\int_{0}^{\infty} e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$
The Pythagorean theorem is written for a right triangle.
Force display style in inline mode
Use \displaystyle to get enlarged rendering even in inline mode:
Compare $\sum_{i=1}^{n} i$ with $\displaystyle\sum_{i=1}^{n} i$ in the text.
Compare with in the text.
In inline mode, avoid \displaystyle as it disrupts line spacing. Rather prefer switching to display mode with $$ ... $$ for complex expressions.
Quick Symbol Reference
Basic Operators
| LaTeX Command | Rendering | Description |
|---|---|---|
\cdot | Multiplication | |
\frac{a}{b} | Fraction | |
a_i, x^{n+1} | Indices and exponents | |
\sqrt[n]{x} | nth root | |
\sum_{k=0}^n | Sum | |
\int_a^b | Integral | |
\prod_{i=1}^n | Product | |
\lim_{x \to 0} | Limit |
Sets and Relations
| Command | Rendering | Description |
|---|---|---|
\in | Belongs to | |
\notin | Does not belong to | |
\subset | Strict inclusion | |
\subseteq | Inclusion | |
\cup | Union | |
\cap | Intersection | |
\emptyset | Empty set | |
\mathbb{N} | Natural numbers | |
\mathbb{Z} | Integers | |
\mathbb{Q} | Rational numbers | |
\mathbb{R} | Real numbers | |
\mathbb{C} | Complex numbers |
Adaptive Delimiters
Delimiters \left and \right automatically adapt to the content size:
$\displaystyle( \frac{a}{b} )$ vs $\displaystyle\left( \frac{a}{b} \right)$
vs
| Delimiter | Static | Adaptive |
|---|---|---|
| Parentheses | ( ) | \left( \right) |
| Brackets | [ ] | \left[ \right] |
| Braces | \{ \} | \left\{ \right\} |
| Bars | | | | \left| \right| |
Advanced Math Environments
align Environment
To align multiple equations on the & symbol:
\begin{align}
f(x) &= x^2 + 2x + 1 \\
&= (x + 1)^2
\end{align}
align automatically numbers each line. To avoid numbering, use align* or add \nonumber on a specific line.
cases Environment: Piecewise Functions
Ideal for defining conditional functions:
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
Application in probability:
P(X = k) = \begin{cases}
\binom{n}{k} p^k (1-p)^{n-k} & \text{if } k \in \{0,\ldots,n\} \\
0 & \text{otherwise}
\end{cases}
Matrices: Types and Variants
LaTeX offers several matrix environments with different delimiters:
| Environment | Delimiters | Code | Rendering |
|---|---|---|---|
matrix | None | \begin{matrix} a & b \\ c & d \end{matrix} | |
pmatrix | ( ) | \begin{pmatrix} a & b \\ c & d \end{pmatrix} | |
bmatrix | [ ] | \begin{bmatrix} a & b \\ c & d \end{bmatrix} | |
Bmatrix | { } | \begin{Bmatrix} a & b \\ c & d \end{Bmatrix} | |
vmatrix | | | | \begin{vmatrix} a & b \\ c & d \end{vmatrix} | |
smallmatrix | None | \begin{smallmatrix} a & b \\ c & d \end{smallmatrix} |
smallmatrix is perfect for vectors and small matrices in inline mode, avoiding disruption of paragraph line spacing. Use it with \left( and \right) to add delimiters.
The matrix $\left(\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\right)$ is invertible if $ad - bc \neq 0$.
The matrix is invertible if .
Complete example: system of linear equations:
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix}
\begin{pmatrix}
x \\
y \\
z
\end{pmatrix}
=
\begin{pmatrix}
b_1 \\
b_2 \\
b_3
\end{pmatrix}
Speed Up Input with Snippets
Snippets transform a shortcut into predefined code. Example: fr + Tab → \frac{•}{•}
Snippets in VS Code
Initial Setup
Ctrl/Cmd + Shift + P→ Preferences: Configure User Snippets- Choose
latex.json(ormarkdown.jsonfor Markdown) - Add your snippets in JSON format
Anatomy of a VS Code Snippet
"sum": {
"prefix": "sum", // Shortcut to type
"body": "\\sum_{i=$1}^{$2} $3", // Generated code
"description": "Sum" // Description (optional)
}
Properties of a snippet:
- prefix: The shortcut to type (e.g.,
sum) - body: The generated LaTeX code (escape backslashes:
\\) - description: Description displayed in autocompletion
Smart navigation (tab stops): $1, $2, $3 define where the cursor is positioned. After insertion, your cursor is placed on $1, then Tab moves to $2, etc.
Default values: ${1:value} defines a default value for the tab stop.
Examples of Useful Snippets
Add these snippets to your latex.json or markdown.json configuration:
{
"fraction": {
"prefix": "fr",
"body": "\\frac{$1}{$2}$0",
"description": "Fraction a/b"
},
"sum": {
"prefix": "sum",
"body": "\\sum_{${1:i}=${2:0}}^{${3:n}} $0",
"description": "Sum with bounds"
},
"integral": {
"prefix": "int",
"body": "\\int_{${1:a}}^{${2:b}} ${3:f(x)} \\,\\mathrm{d}${4:x}$0",
"description": "Definite integral"
},
"limit": {
"prefix": "lim",
"body": "\\lim_{${1:x} \\to ${2:0}} $0",
"description": "Limit"
},
"matrix": {
"prefix": "mat",
"body": [
"\\begin{${1|matrix,pmatrix,bmatrix,vmatrix|}}",
"\t$2",
"\\end{${1|matrix,pmatrix,bmatrix,vmatrix|}}"
],
"description": "Matrix with choice of delimiters"
},
"cases": {
"prefix": "cas",
"body": [
"\\begin{cases}",
"\t$1 & \\text{if } $2 \\\\",
"\t$3 & \\text{if } $4",
"\\end{cases}$0"
],
"description": "Piecewise function (2 cases)"
},
"align": {
"prefix": "ali",
"body": [
"\\begin{align${1:*}}",
"\t$2 &= $3 \\\\",
"\t&= $4",
"\\end{align${1:*}}$0"
],
"description": "Equation alignment"
}
}
The ${1|option1,option2,option3|} syntax displays a dropdown menu upon insertion. Used in the mat snippet above to choose the matrix type.
Snippets in Obsidian with Latex Suite
Latex Suite is the reference extension for writing mathematics quickly in Obsidian. It transforms the writing experience by enabling input as fluid as with pen on paper.
Installation:
- Open Obsidian → Settings → Community plugins options
- Search for "Latex Suite" in the plugin browser
- Click Install, then Enable
Key features:
| Feature | Description | Example |
|---|---|---|
| Auto-expansion | Automatic expansion without pressing Tab | // → \frac{•}{•} |
| Visual mode | Transformation of selected text | Select x+y then S → \sqrt{x+y} |
| Context-aware | Snippets active only in math mode | @a works in $$...$$ only |
| Regex triggers | Advanced patterns for auto-formatting | x2 → x_{2} automatically |
| Variables | Predefined symbols to simplify regex | ${GREEK} for all Greek letters |
Anatomy of a Latex Suite Snippet
A Latex Suite snippet is a JavaScript object with 4 main properties:
{
trigger: "//", // Trigger: text that activates the snippet
replacement: "\\frac{$0}{$1}$2", // Replacement: generated LaTeX code
options: "mA", // Options: context and behavior
priority: 1, // Execution priority. In case of conflict, the snippet with the highest priority will be preferred (optional)
description: "Quick fraction", // Description (optional)
flags: "i" // Regex flags (optional)
}
Options explained:
| Option | Meaning | Description |
|---|---|---|
t | Text mode | Snippet active outside math environments |
m | Math mode | Snippet active in $$...$$ or $...$ |
M | Block math mode | Snippet active in $$...$$ |
n | Inline math mode | Snippet active in $...$ |
c | Code mode | Snippet active in ``` ``` |
A | Auto-expand | Automatic expansion without Tab |
v | Visual | Snippet active when text is selected |
w | Word boundary | Requires a space or line start before the trigger |
r | Regex | The trigger is a regular expression |
Tab stops with $0, $1, $2:
As in VS Code, tab stops define where the cursor is positioned after expansion:
{ trigger: "sum", replacement: "\\sum_{${0:k}=${1:0}}^{${2:n}} $3", options: "mA" }
${0:k}: First stop with default value "k"${1:0}: Second stop with default value "0"$3: Last stop without default value
{ trigger: "begin", replacement: "\\begin{$1}\n $2\n\\end{$1}", options: "MA" }
Here, the first stop $1 is automatically reused in \end{...}.
Advanced regex triggers:
Snippets can use regex to detect patterns:
{
trigger: "([A-Za-z])(\\d)", // Detects letter + digit
replacement: "[[0]]_{[[1]]}", // [[0]] = letter, [[1]] = digit
options: "rmA" // r = regex
}
Example: x2 → x_{2} automatically
Predefined variables:
The default_snippet_variables.js file defines constants to simplify regex:
{
"${GREEK}": "alpha|beta|gamma|delta|...",
"${SYMBOL}": "parallel|nabla|hbar|...",
"${UNITS}": "V|A|Hz|kg|m|..."
}
Usage in a snippet:
{
trigger: "\\\\(${GREEK})([A-Za-z])",
replacement: "\\[[0]] [[1]]", // Inserts a space after Greek letters
options: "rmA"
}
My Personal Configuration
I've created a complete configuration with over 250 snippets optimized for mathematics and physics. This configuration is the result of two years of daily note-taking.
- default_snippets.js (custom snippets)
- default_snippet_variables.js (variables and symbols)
The snippets cover:
- Automatic Obsidian callouts
- Advanced mathematical symbols
- Physical units (automatic detection:
10Hz→10\text{Hz}) - Shortcuts for sequences and series:
uu→ ,ff→ ,SS→ - Automatic conversion of isolated letters to math mode
I advise you to read the document even diagonally to discover them and know that they exist, so you can come back later with a ctrl+f.
Installation:
- Copy the contents of the two files above
- In Obsidian: Settings → Latex Suite → Snippets
- Paste the contents of
default_snippets.jsin the text area - Go to Snippets variables
- Paste the contents of
default_snippet_variables.js
I highly recommend using my configuration as a base, then customize it according to your needs.
Examples of snippets from my configuration
1. Quick entry to math mode
| Shortcut | Result | Description |
|---|---|---|
ml | $\displaystyle •$ | Inline math mode with displaystyle |
dm | $$\n•\n$$ | Display math mode (block) |
2. Fractions and operations
| Shortcut | Result | Description |
|---|---|---|
// | \frac{•}{•} | Quick fraction |
sr | ^{2} | Square |
cb | ^{3} | Cube |
sq | \sqrt{•} | Square root |
ee | e^{•} | Exponential |
3. Greek letters with @
The @ prefix allows quick insertion of Greek letters:
| Shortcut | Result | Shortcut | Result |
|---|---|---|---|
@a | \alpha | @G | \Gamma |
@b | \beta | @D | \Delta |
@g | \gamma | @T | \Theta |
@d | \delta | @L | \Lambda |
@e | \varepsilon | @S | \Sigma |
@t | \theta | @O | \Omega |
@l | \lambda | @P | \Pi |
@p | \varphi | ||
@o | \omega | ||
@s | \sigma |
4. Sets and symbols with double capitals
| Shortcut | Result | Description |
|---|---|---|
RR | Real numbers | |
CC | Complex numbers | |
NN | Natural numbers | |
ZZ | Integers | |
KK | Generic field | |
LL | Function space | |
MM | Matrix space |
5. Automatic indices
Snippets automatically detect common indices:
x2 → x_{2} (numeric indices)
xii → x_{i} (indices i, j, k, n, m)
xip1 → x_{i+1} (indices with +)
xim2 → x_{i-2} (indices with -)
6. Accents and modifiers
Type a letter followed by:
| Suffix | Result | Example | Preview |
|---|---|---|---|
vec | \vec{•} | xvec → \vec{x} | |
dot | \dot{•} | xdot → \dot{x} | |
ddot | \ddot{•} | xddot → \ddot{x} | |
bar | \bar{•} | xbar → \bar{x} | |
hat | \hat{•} | xhat → \hat{x} |
7. Derivatives and integrals
| Shortcut | Result | Example preview | Description |
|---|---|---|---|
par | \frac{\partial •}{\partial •} | Partial derivative | |
pa2 | \frac{\partial^{2} •}{\partial •^{2}} | Second derivative | |
ddt | \frac{d}{dt} | Time derivative | |
int | \int_{0}^{\infty} • \, d• | Integral with bounds | |
oinf | \int_{0}^{\infty} • \, d• | Integral from 0 to infinity | |
infi | \int_{-\infty}^{+\infty} • \, d• | Integral over R |
8. Quick matrices
| Shortcut | Result | Example preview | Description |
|---|---|---|---|
pmat | \begin{pmatrix}\n•\n\end{pmatrix} | Matrix with parentheses | |
bmat | \begin{bmatrix}\n•\n\end{bmatrix} | Matrix with brackets | |
vmat | \begin{vmatrix}\n•\n\end{vmatrix} | Determinant | |
cases | \begin{cases}\n•\n\end{cases} | Piecewise function |
9. Visual mode: selection transformations
Select text then press:
| Key | Transformation | Example | Preview |
|---|---|---|---|
S | \sqrt{...} | x+1 → \sqrt{x+1} | |
U | \underbrace{...}_{•} | a+b → \underbrace{a+b}_{•} | |
O | \overbrace{...}^{•} | a+b → \overbrace{a+b}^{•} | |
C | \cancel{...} | x → \cancel{x} |
Practical Exercises
| # | Task | Educational objective |
|---|---|---|
| 1 | Write a sheet containing A1 level differentiation formulas | Master align and cases environments |
| 2 | Create a VS Code snippet for the matrix environment | Automate input |
| 3 | Import the document on Overleaf and share it with a classmate | Discover revision mode |
Resources
Documentation and Online Tools
- Overleaf – Learn LaTeX in 30 Minutes - Complete introduction
- Detexify - Find LaTeX symbols by drawing - Draw a symbol to find the LaTeX command
- MathJax Documentation - TeX Syntax - Complete TeX syntax
- MathJax Macros - List of available macros - List of available macros
- LaTeX Math Cheat Sheet - Quick reference
- LaTeX Wikibook - Community documentation
Obsidian Configuration Files
- Open default_snippets.js - Latex Suite snippets configuration
- Open default_snippet_variables.js - Variables and symbols for Latex Suite
These files contain over 250 snippets optimized for quick input of mathematics, physics, and chemistry in Obsidian. See the Snippets in Obsidian section for installation instructions.