Mathematical Notation with KaTeX

2 min read 285 words

Demonstrating mathematical notation support using KaTeX for inline and block equations.

Table of Contents

This post demonstrates the mathematical notation capabilities powered by KaTeX.

Inline Math

You can write inline math using single dollar signs. For example, the famous equation E = mc^2 shows the relationship between energy and mass. The quadratic formula x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} solves quadratic equations.

Here are more examples:

  • The derivative notation: f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}
  • Probability: P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)} (Bayes’ theorem)
  • Greek letters: \alpha, \beta, \gamma, \delta, \epsilon, \theta, \lambda, \mu, \pi, \sigma, \omega

Block Math

Block math uses double dollar signs and is centered on its own line:

\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}

The Gaussian Distribution

The probability density function of the normal distribution:

f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^2}

Matrix Notation

Matrices are also supported:

\mathbf{A} = \begin{pmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{pmatrix}

Summations and Products

\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
\prod_{i=1}^{n} i = n!

Calculus

The fundamental theorem of calculus:

\frac{d}{dx} \int_{a}^{x} f(t) \, dt = f(x)

Taylor series expansion:

f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n

Alternative Delimiters

You can also use LaTeX-style delimiters. Inline: a^2 + b^2 = c^2

Block math with bracket delimiters:

\nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0}

Complex Equations

Maxwell’s equations in differential form:

\begin{aligned} \nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \\ \nabla \cdot \mathbf{B} &= 0 \\ \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \\ \nabla \times \mathbf{B} &= \mu_0 \mathbf{J} + \mu_0 \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t} \end{aligned}

Conclusion

KaTeX provides fast, high-quality math rendering that works great for data science, engineering, and scientific content. The math notation looks great in both light and dark modes!