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:
Result:
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¶
Result:
Square root: \(\sqrt{x}\) Nth root: \(\sqrt[n]{x}\) Complex: \(\sqrt{x^2 + y^2}\)
Advanced Mathematics¶
Calculus¶
Derivatives:
Integrals:
Partial Derivatives:
Linear Algebra¶
Matrices:
Determinant:
Vector notation:
Set Theory¶
Summations and Products¶
Summation:
Product:
Series:
Equation Environments¶
Aligned Equations¶
Cases¶
Matrix Operations¶
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:
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:
Troubleshooting¶
Common Issues¶
- Equations not rendering: Check MathJax is loaded
- Incorrect spacing: Use
\,
for thin space,\;
for medium - Escaping issues: Double backslashes in Markdown
- 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) ]