Markdown Math Formulas
In technical documentation, academic papers, and tutorials, mathematical formulas are often needed. While standard Markdown doesn't support math formulas, many Markdown editors and platforms support math formula display through LaTeX syntax. This chapter will detail how to write math formulas in Markdown.
Math Formula Basics
Two Types of Formulas
Math formulas are divided into two types:
- Inline formulas: Formulas embedded in paragraphs
- Block formulas: Formulas displayed independently
Inline Formulas
Use single $ symbol to wrap:
Einstein's mass-energy equation is $E = mc^2$.Effect:
Einstein's mass-energy equation is
Block Formulas
Use double $ symbols to wrap:
$$
E = mc^2
$$Effect:
Supported Platforms
GitHub
- Does not support math formulas (unless using special renderers)
- Needs MathJax or KaTeX
GitLab
- Full support
- Uses KaTeX rendering
Typora
- Full support
- Supports real-time preview
Obsidian
- Full support
- Uses MathJax
Jupyter Notebook
- Full support
- Native Markdown cells
VS Code
- Needs plugin support
- Recommend Markdown Preview Enhanced
LaTeX Syntax Basics
Superscripts and Subscripts
Superscript: $x^2$, $x^n$
Subscript: $x_1$, $x_{ij}$
Combined: $x^{2n}$, $x_{i+j}$Effect:
Superscript:
Fractions
Simple fraction: $\frac{a}{b}$
Nested fraction: $\frac{\frac{a}{b}}{c}$
Complex fraction: $\frac{a + b}{c - d}$Effect:
Simple fraction:
Roots
Square root: $\sqrt{x}$
nth root: $\sqrt[n]{x}$
Complex expression: $\sqrt{a^2 + b^2}$Effect:
Square root:
Summation and Integration
Summation: $\sum_{i=1}^{n} x_i$
Integration: $\int_{a}^{b} f(x) dx$
Indefinite integral: $\int f(x) dx$Effect:
Summation:
Limits
Limit: $\lim_{x \to \infty} f(x)$
One-sided limit: $\lim_{x \to 0^+} f(x)$Effect:
Limit:
Greek Letters
Lowercase Greek Letters
$\alpha$ $\beta$ $\gamma$ $\delta$ $\epsilon$ $\zeta$
$\eta$ $\theta$ $\iota$ $\kappa$ $\lambda$ $\mu$
$\nu$ $\xi$ $\pi$ $\rho$ $\sigma$ $\tau$
$\upsilon$ $\phi$ $\chi$ $\psi$ $\omega$Effect:
Uppercase Greek Letters
$\Gamma$ $\Delta$ $\Theta$ $\Lambda$ $\Sigma$ $\Phi$ $\Psi$ $\Omega$Effect:
Math Symbols
Relation Symbols
Equals: $=$
Not equals: $\neq$
Less than: $<$
Greater than: $>$
Less than or equal: $\leq$
Greater than or equal: $\geq$
Approximately equal: $\approx$
Identically equal: $\equiv$Effect:
Equals:
Operation Symbols
Addition: $+$
Subtraction: $-$
Multiplication: $\times$
Division: $\div$
Dot product: $\cdot$
Cross product: $\times$
Plus minus: $\pm$Effect:
Addition:
Set Symbols
Element of: $\in$
Not element of: $\notin$
Subset: $\subset$
Proper subset: $\subsetneq$
Union: $\cup$
Intersection: $\cap$
Empty set: $\emptyset$
Universal quantifier: $\forall$Effect:
Element of:
Logic Symbols
Because: $\because$
Therefore: $\therefore$
And: $\land$
Or: $\lor$
Not: $\lnot$
Implies: $\implies$
If and only if: $\iff$Effect:
Because:
Arrow Symbols
Right arrow: $\rightarrow$
Left arrow: $\leftarrow$
Left-right arrow: $\leftrightarrow$
Up arrow: $\uparrow$
Down arrow: $\downarrow$
Long right arrow: $\Longrightarrow$Effect:
Right arrow:
Matrices
Basic Matrix
$$
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
$$Effect:
Bracketed Matrix
$$
\begin{bmatrix}
1 & 2 \\
3 & 4
\end{bmatrix}
$$Effect:
Braced Matrix
$$
\begin{Bmatrix}
a & b \\
c & d
\end{Bmatrix}
$$Effect:
Determinant
$$
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
$$Effect:
3x3 Matrix
$$
\begin{pmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
$$Effect:
Systems of Equations
Basic System
$$
\begin{cases}
3x + 2y = 7 \\
x - y = 1
\end{cases}
$$Effect:
Aligned Equations
$$
\begin{aligned}
f(x) &= (x + a)(x - a) \\
&= x^2 - a^2
\end{aligned}
$$Effect:
Piecewise Functions
Basic Piecewise Function
$$
f(x) =
\begin{cases}
x & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
$$Effect:
Complex Piecewise Function
$$
f(x) =
\begin{cases}
x^2 & x < 0 \\
2x & 0 \leq x < 1 \\
1 + x & x \geq 1
\end{cases}
$$Effect:
Advanced Formulas
Differential Equations
$$
\frac{dy}{dx} = 2x + 3
$$Effect:
Partial Derivatives
$$
\frac{\partial f}{\partial x} = \frac{\partial}{\partial x}(x^2 + y^2) = 2x
$$Effect:
Taylor Series
$$
f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x - a)^n
$$Effect:
Euler's Formula
$$
e^{i\pi} + 1 = 0
$$Effect:
Normal Distribution
$$
f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}
$$Effect:
Fourier Transform
$$
F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-i\omega t} dt
$$Effect:
Common Formula Examples
Pythagorean Theorem
$$
a^2 + b^2 = c^2
$$Effect:
Quadratic Formula
$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$Effect:
Logarithmic Formula
$$
\log_a(x) = \frac{\ln x}{\ln a}
$$Effect:
Probability Formula
$$
P(A|B) = \frac{P(B|A)P(A)}{P(B)}
$$Effect:
Formula Numbering
Basic Numbering
$$
E = mc^2 \tag{1}
$$Effect:
Reference Formulas
According to formula (1), we can draw conclusions.Formatting Tips
Spacing Adjustment
Wide spacing: $a \quad b$
Narrow spacing: $a \, b$
Negative spacing: $a \! b$Effect:
Wide spacing:
Text in Formulas
Text in formula: $f(x) = x^2 \text{ if } x > 0$Effect:
Text in formula:
Large Brackets
Large brackets: $\left( \frac{a}{b} \right)$
Adapts to content sizeEffect:
Large brackets:
Practical Examples
Physics Documentation
# Classical Mechanics
## Newton's Second Law
$$
F = ma
$$
## Energy Conservation
$$
E = K + U = \frac{1}{2}mv^2 + mgh
$$
## Circular Motion
$$
F_c = \frac{mv^2}{r} = m\omega^2r
$$Math Tutorial
# Calculus Basics
## Derivative Definition
$$
f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}
$$
## Integration Calculation
$$
\int x^n dx = \frac{x^{n+1}}{n+1} + C
$$
## Definite Integral
$$
\int_{0}^{\pi} \sin x dx = 2
$$Statistics Documentation
# Statistics Basics
## Expected Value
$$
E[X] = \sum_{i=1}^{n} x_i P(x_i)
$$
## Variance
$$
Var(X) = E[(X - \mu)^2] = E[X^2] - (E[X])^2
$$
## Standard Deviation
$$
\sigma = \sqrt{Var(X)}
$$Common Questions
Q: Formulas not displaying on GitHub?
A: GitHub natively doesn't support math formulas, you can:
- Use GitLab
- Use static site generators (like Jekyll + MathJax)
- Use third-party renderers
Q: How to quickly find LaTeX commands?
A:
- Use online tools: Detexify
- Check LaTeX reference manuals
- Use editor's auto-completion feature
Q: How to wrap long formulas?
A: Use \\ for line breaks:
$$
f(x) = x^2 + 2x + 1 \\
= (x + 1)^2
$$Q: How to display large brackets?
A: Use \left\{ and \right\}:
$$
f(x) = \left\{
\begin{array}{ll}
x^2 & x \geq 0 \\
-x^2 & x < 0
\end{array}
\right.
$$Summary
This chapter detailed Markdown math formula writing methods:
- Basic syntax: Inline formulas
$and block formulas$$ - Basic elements: Fractions, roots, superscripts, subscripts
- Greek letters: Common Greek letter symbols
- Math symbols: Relations, operations, sets, logic symbols
- Advanced features: Matrices, equation systems, piecewise functions
- Common formulas: Physics, mathematics, statistics formulas
- Formatting tips: Spacing, text, brackets, etc.
Mastering LaTeX syntax for math formulas allows you to precisely express mathematical concepts in technical documentation.
Next: Learn Markdown Diagram Drawing methods.