Skip to content

Mathematical Notation

Material for MkDocs supports mathematical notation through the Arithmatex extension, enabling LaTeX math rendering with MathJax or KaTeX.

Overview

Mathematical notation provides:

  • LaTeX syntax support - Industry-standard math typesetting
  • Inline and block math - Equations within text or standalone
  • Equation numbering - Automatic equation references
  • Math environments - Matrices, alignments, and more
  • Custom macros - Define reusable notation
  • Accessibility - Screen reader compatible output

Configuration

Basic Setup

Enable Arithmatex in mkdocs.yml:

markdown_extensions:
  - pymdownx.arithmatex:
      generic: true

extra_javascript:
  - javascripts/mathjax.js
  - https://polyfill.io/v3/polyfill.min.js?features=es6
  - https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js

MathJax Configuration

Create docs/javascripts/mathjax.js:

window.MathJax = {
  tex: {
    inlineMath: [["\\(", "\\)"]],
    displayMath: [["\\[", "\\]"]],
    processEscapes: true,
    processEnvironments: true
  },
  options: {
    ignoreHtmlClass: ".*|",
    processHtmlClass: "arithmatex"
  }
};

document$.subscribe(() => {
  MathJax.typesetPromise()
})

Basic Usage

Inline Math

Use \(...\) for inline equations:

The Pythagorean theorem states that \(a^2 + b^2 = c^2\).

Einstein's famous equation is \(E = mc^2\).

Result:

The Pythagorean theorem states that \(a^2 + b^2 = c^2\).

Einstein's famous equation is \(E = mc^2\).

Display Math

Use \[...\] for display equations:

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

Result:

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

Common Mathematical Expressions

Greek Letters

Lower Upper LaTeX
\(\alpha\) \(A\) \alpha, A
\(\beta\) \(B\) \beta, B
\(\gamma\) \(\Gamma\) \gamma, \Gamma
\(\delta\) \(\Delta\) \delta, \Delta
\(\epsilon\) \(E\) \epsilon, E
\(\theta\) \(\Theta\) \theta, \Theta
\(\lambda\) \(\Lambda\) \lambda, \Lambda
\(\pi\) \(\Pi\) \pi, \Pi
\(\sigma\) \(\Sigma\) \sigma, \Sigma
\(\omega\) \(\Omega\) \omega, \Omega

Operators and Relations

Addition: \(a + b\)
Subtraction: \(a - b\)
Multiplication: \(a \times b\) or \(a \cdot b\)
Division: \(a \div b\) or \(\frac{a}{b}\)
Equal: \(a = b\)
Not equal: \(a \neq b\)
Less than: \(a < b\)
Greater than: \(a > b\)
Less or equal: \(a \leq b\)
Greater or equal: \(a \geq b\)
Approximately: \(a \approx b\)

Superscripts and Subscripts

Superscript: \(x^2\), \(x^{n+1}\)
Subscript: \(x_i\), \(x_{i,j}\)
Combined: \(x_i^2\), \(x_{i,j}^{k+1}\)

Result:

Superscript: \(x^2\), \(x^{n+1}\) Subscript: \(x_i\), \(x_{i,j}\) Combined: \(x_i^2\), \(x_{i,j}^{k+1}\)

Fractions

Simple: \(\frac{1}{2}\)
Complex: \(\frac{x^2 + 3x + 2}{x - 1}\)
Nested: \(\frac{1}{1 + \frac{1}{x}}\)

Result:

Simple: \(\frac{1}{2}\) Complex: \(\frac{x^2 + 3x + 2}{x - 1}\) Nested: \(\frac{1}{1 + \frac{1}{x}}\)

Roots

Square root: \(\sqrt{x}\)
Nth root: \(\sqrt[n]{x}\)
Complex: \(\sqrt{x^2 + y^2}\)

Result:

Square root: \(\sqrt{x}\) Nth root: \(\sqrt[n]{x}\) Complex: \(\sqrt{x^2 + y^2}\)

Advanced Mathematics

Calculus

Derivatives:

\[ f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h} \]
\[ \frac{d}{dx}(x^n) = nx^{n-1} \]

Integrals:

\[ \int_a^b f(x)\,dx = F(b) - F(a) \]
\[ \int_0^{\pi} \sin(x)\,dx = 2 \]

Partial Derivatives:

\[ \frac{\partial f}{\partial x} = \lim_{h \to 0} \frac{f(x+h,y) - f(x,y)}{h} \]

Linear Algebra

Matrices:

\[ A = \begin{pmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{pmatrix} \]

Determinant:

\[ \det(A) = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc \]

Vector notation:

\[ \vec{v} = \begin{bmatrix} v_1 \\ v_2 \\ v_3 \end{bmatrix} \]

Set Theory

\[ A \cup B = \{x : x \in A \text{ or } x \in B\} \]
\[ A \cap B = \{x : x \in A \text{ and } x \in B\} \]
\[ A \setminus B = \{x : x \in A \text{ and } x \notin B\} \]

Summations and Products

Summation:

\[ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} \]

Product:

\[ \prod_{i=1}^{n} i = n! \]

Series:

\[ \sum_{n=0}^{\infty} \frac{x^n}{n!} = e^x \]

Equation Environments

Aligned Equations

\[ \begin{align} 2x + 3y &= 7 \\ x - y &= 1 \end{align} \]

Cases

\[ f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x^2 & \text{if } x < 0 \end{cases} \]

Matrix Operations

\[ \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} x + 2y \\ 3x + 4y \end{bmatrix} \]

Physics and Engineering

Classical Mechanics

Newton's Second Law: [ F = ma = mfrac{d2x}{dt2} ]

Kinetic Energy: [ K = frac{1}{2}mv^2 ]

Quantum Mechanics

Schrödinger Equation: [ ihbarfrac{partial}{partial t}Psi = hat{H}Psi ]

Wave Function: [ Psi(x,t) = Ae^{i(kx - omega t)} ]

Electromagnetics

Maxwell's Equations: [ begin{align} nabla cdot mathbf{E} &= frac{rho}{epsilon_0} \ nabla cdot mathbf{B} &= 0 \ nabla times mathbf{E} &= -frac{partial mathbf{B}}{partial t} \ nabla times mathbf{B} &= mu_0mathbf{J} + mu_0epsilon_0frac{partial mathbf{E}}{partial t} end{align} ]

Statistics and Probability

Distributions

Normal Distribution: [ f(x) = frac{1}{sigmasqrt{2pi}}e{-frac{1}{2}left(frac{x-mu}{sigma}right)2} ]

Binomial Distribution: [ P(X = k) = binom{n}{k}pk(1-p) ]

Statistical Measures

Mean: [ bar{x} = frac{1}{n}sum_{i=1}^{n}x_i ]

Standard Deviation: [ sigma = sqrt{frac{1}{n}sum_{i=1}^{n}(x_i - bar{x})^2} ]

Custom Macros

Define reusable macros in your MathJax configuration:

window.MathJax = {
  tex: {
    macros: {
      RR: "\\mathbb{R}",
      CC: "\\mathbb{C}",
      NN: "\\mathbb{N}",
      ZZ: "\\mathbb{Z}",
      QQ: "\\mathbb{Q}",
      norm: ["\\lVert #1 \\rVert", 1],
      abs: ["\\lvert #1 \\rvert", 1],
      inner: ["\\langle #1, #2 \\rangle", 2]
    }
  }
};

Usage: - Real numbers: \(\mathbb{R}\) - Complex numbers: \(\mathbb{C}\) - Natural numbers: \(\mathbb{N}\) - Norm: \(\lVert x \rVert\) - Inner product: \(\langle x, y \rangle\)

Best Practices

1. Clarity

Use spacing and alignment for readability:

\[
\int_0^1 \frac{x^2 - 1}{x + 1} \, dx
\]

2. Accessibility

Provide context for equations:

The quadratic formula, \(x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}\),
solves equations of the form \(ax^2 + bx + c = 0\).

3. Performance

For pages with many equations, consider lazy loading:

MathJax = {
  tex: {
    inlineMath: [['\\(', '\\)']],
    displayMath: [['\\[', '\\]']]
  },
  options: {
    lazyMargin: "200px"
  }
};

4. Mobile Responsiveness

Use scrollable containers for wide equations:

.arithmatex {
  overflow-x: auto;
  max-width: 100%;
}

Troubleshooting

Common Issues

  1. Equations not rendering: Check MathJax is loaded
  2. Incorrect spacing: Use \, for thin space, \; for medium
  3. Escaping issues: Double backslashes in Markdown
  4. Performance: Reduce equation complexity

Debug Mode

Enable MathJax debugging:

window.MathJax = {
  options: {
    menuOptions: {
      settings: {
        assistiveMml: true,
        collapsible: true,
        explorer: true
      }
    }
  }
};

Examples in Context

Algorithm Complexity

The time complexity of binary search is \(O(\log n)\), while linear search is \(O(n)\).

For a balanced binary tree with \(n\) nodes, the height is \(h = \lfloor \log_2 n \rfloor + 1\).

Machine Learning

The cost function for linear regression: [ J(theta) = frac{1}{2m}sum_{i=1}{m}(h_theta(x) - y{(i)})2 ]

Gradient descent update rule: [ theta_j := theta_j - alphafrac{partial}{partialtheta_j}J(theta) ]

Financial Mathematics

Compound interest formula: [ A = Pleft(1 + frac{r}{n}right)^{nt} ]

Black-Scholes option pricing: [ C = S_0N(d_1) - Ke^{-rt}N(d_2) ]

See Also