- Using LaTeX Math Formulas in Jekyll Posts
Using LaTeX Math Formulas in Jekyll Posts
MathJax support has been successfully added to your Jekyll site!
How to Use LaTeX Formulas
MathJax is enabled by default for all posts and projects. You can use LaTeX syntax for mathematical equations.
Inline Math
Use $...$ or \\(...\\) for inline math:
Example:
The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ where $a \neq 0$.
Einstein's famous equation is \\(E = mc^2\\).
Renders as: The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ where $a \neq 0$.
Einstein’s famous equation is \(E = mc^2\).
Display Math (Block Equations)
Use $$...$$ or \\[...\\] for display math (centered on separate line):
Example:
$$
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} = \frac{4\pi}{c}\vec{\mathbf{j}}
$$
Maxwell's equations:
\\[
\begin{aligned}
\nabla \cdot \vec{\mathbf{E}} &= 4 \pi \rho \\\\
\nabla \cdot \vec{\mathbf{B}} &= 0 \\\\
\nabla \times \vec{\mathbf{E}} &= -\frac{1}{c} \frac{\partial \vec{\mathbf{B}}}{\partial t} \\\\
\nabla \times \vec{\mathbf{B}} &= \frac{1}{c}\left(4\pi\vec{\mathbf{j}} + \frac{\partial\vec{\mathbf{E}}}{\partial t}\right)
\end{aligned}
\\]
Renders as:
\[\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} = \frac{4\pi}{c}\vec{\mathbf{j}}\]Maxwell’s equations:
\[
\begin{aligned}
\nabla \cdot \vec{\mathbf{E}} &= 4 \pi \rho \
\nabla \cdot \vec{\mathbf{B}} &= 0 \
\nabla \times \vec{\mathbf{E}} &= -\frac{1}{c} \frac{\partial \vec{\mathbf{B}}}{\partial t} \
\nabla \times \vec{\mathbf{B}} &= \frac{1}{c}\left(4\pi\vec{\mathbf{j}} + \frac{\partial\vec{\mathbf{E}}}{\partial t}\right)
\end{aligned}
\]
Common Examples
1. Fractions and Roots
$$\frac{a}{b}, \quad \sqrt{x}, \quad \sqrt[n]{x}$$
Renders as: \(\frac{a}{b}, \quad \sqrt{x}, \quad \sqrt[n]{x}\)
2. Greek Letters
$$\alpha, \beta, \gamma, \delta, \epsilon, \theta, \lambda, \mu, \pi, \sigma, \omega$$
$$\Gamma, \Delta, \Theta, \Lambda, \Sigma, \Phi, \Psi, \Omega$$
Renders as: \(\alpha, \beta, \gamma, \delta, \epsilon, \theta, \lambda, \mu, \pi, \sigma, \omega\) \(\Gamma, \Delta, \Theta, \Lambda, \Sigma, \Phi, \Psi, \Omega\)
3. Subscripts and Superscripts
$$x^2, \quad x_i, \quad x^{2y}, \quad x_{i,j}$$
Renders as: \(x^2, \quad x_i, \quad x^{2y}, \quad x_{i,j}\)
4. Summation and Integrals
$$\sum_{i=1}^{n} x_i, \quad \int_{a}^{b} f(x)dx, \quad \prod_{i=1}^{n} x_i$$
Renders as: \(\sum_{i=1}^{n} x_i, \quad \int_{a}^{b} f(x)dx, \quad \prod_{i=1}^{n} x_i\)
5. Matrices
$$
\begin{bmatrix}
a & b \\\\
c & d
\end{bmatrix}
$$
$$
\begin{pmatrix}
1 & 0 & 0 \\\\
0 & 1 & 0 \\\\
0 & 0 & 1
\end{pmatrix}
$$
Renders as:
\[\begin{bmatrix} a & b \\\\ c & d \end{bmatrix}\] \[\begin{pmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \end{pmatrix}\]6. Aligned Equations
$$
\begin{aligned}
f(x) &= (x+1)^2 \\\\
&= x^2 + 2x + 1
\end{aligned}
$$
Renders as:
\[\begin{aligned} f(x) &= (x+1)^2 \\\\ &= x^2 + 2x + 1 \end{aligned}\]7. Cases (Piecewise Functions)
$$
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\\\
-x^2 & \text{if } x < 0
\end{cases}
$$
Renders as:
\[f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\\\ -x^2 & \text{if } x < 0 \end{cases}\]8. Calculus
$$\frac{dy}{dx}, \quad \frac{\partial f}{\partial x}, \quad \nabla f, \quad \lim_{x \to \infty} f(x)$$
Renders as: \(\frac{dy}{dx}, \quad \frac{\partial f}{\partial x}, \quad \nabla f, \quad \lim_{x \to \infty} f(x)\)
9. Vectors and Norms
$$\vec{v}, \quad \|\vec{v}\|, \quad \langle u, v \rangle, \quad \vec{a} \cdot \vec{b}$$
Renders as: \(\vec{v}, \quad \|\vec{v}\|, \quad \langle u, v \rangle, \quad \vec{a} \cdot \vec{b}\)
10. Machine Learning / Statistics
$$
\hat{y} = \mathbf{w}^T\mathbf{x} + b
$$
$$
\mathcal{L}(\theta) = -\frac{1}{N}\sum_{i=1}^{N}\left[y_i\log(\hat{y}_i) + (1-y_i)\log(1-\hat{y}_i)\right]
$$
$$
\mu = \mathbb{E}[X], \quad \sigma^2 = \text{Var}(X)
$$
Renders as: \(\hat{y} = \mathbf{w}^T\mathbf{x} + b\)
\[\mathcal{L}(\theta) = -\frac{1}{N}\sum_{i=1}^{N}\left[y_i\log(\hat{y}_i) + (1-y_i)\log(1-\hat{y}_i)\right]\] \[\mu = \mathbb{E}[X], \quad \sigma^2 = \text{Var}(X)\]Disabling MathJax for Specific Posts
If you want to disable MathJax for a specific post (to improve load time), add to the front matter:
---
title: "My Post"
mathjax: false
---
Tips
- Escaping: Use double backslashes
\\\\for line breaks in multi-line equations - Spacing: Use
\quador\qquadfor spacing between elements - Text: Use
\text{...}for regular text inside equations - Testing: You can test your LaTeX at https://www.mathjax.org/#demo