LaTeX/MathJax Examples¶
This page demonstrates the comprehensive MathJax configuration for rendering mathematical notation in MkDocs with Jupyter integration.
Basic Inline Math¶
Simple inline equations using different delimiters:
- Using
\(
and\)
: The quadratic formula is \(x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}\) - Using
$
delimiters: The area of a circle is \(A = \pi r^2\) - Einstein's famous equation: \(E = mc^2\)
Display Equations¶
Using \[
and \]
delimiters:¶
Using $$
delimiters:¶
Mathematical Sets and Notation¶
Using our custom macros:
- Real numbers: \(\R\)
- Complex numbers: \(\C\)
- Natural numbers: \(\N\)
- Integers: \(\Z\)
- Rational numbers: \(\Q\)
Vectors and Matrices¶
Vector notation using custom macros: \(\(\vec{v} = \begin{pmatrix} x \\ y \\ z \end{pmatrix}\)\)
Matrix operations: \(\(\mat{A} = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix}\)\)
Matrix multiplication: \(\(\mat{C} = \mat{A} \mat{B} = \sum_{k=1}^{n} a_{ik} b_{kj}\)\)
Functions and Operators¶
Common mathematical functions using custom macros:
- Minimum: \(\argmin_{x} f(x)\)
- Maximum: \(\argmax_{x} f(x)\)
- Trace: \(\trace(\mat{A})\)
- Diagonal: \(\diag(\mat{A})\)
- Rank: \(\rank(\mat{A})\)
Probability and Statistics¶
Statistical notation with custom macros:
- Probability: \(\Pr(X = x)\)
- Expected value: \(\E[X]\)
- Variance: \(\Var(X)\)
- Covariance: \(\Cov(X, Y)\)
Example probability density function: \(\(f(x|\mu,\sigma^2) = \frac{1}{\sqrt{2\pi\sigma^2}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}\)\)
Machine Learning Notation¶
Custom macros for ML:
- Loss function: \(\loss(\params)\)
- Dataset: \(\data = \{(x_i, y_i)\}_{i=1}^n\)
- Model: \(\model_\params\)
- Parameters: \(\params = (\theta_1, \theta_2, \ldots, \theta_d)\)
Gradient descent update: \(\(\params_{t+1} = \params_t - \alpha \nabla_\params \loss(\params_t)\)\)
Calculus and Derivatives¶
Using derivative macros:
- Differential element: \(\dd x\)
- Ordinary derivative: \(\frac{\dd y}{\dd x}\)
- Partial derivative: \(\pdv{f}{x}\)
Example: Chain rule \(\(\frac{\dd}{\dd x} f(g(x)) = f'(g(x)) \cdot g'(x)\)\)
Multi-variable calculus: \(\(\pdv{f}{x} = \lim_{h \to 0} \frac{f(x+h,y) - f(x,y)}{h}\)\)
Advanced Mathematical Structures¶
Numbered Equations¶
Equation with automatic numbering: begin{equation} nabla times vec{E} = -frac{partial vec{B}}{partial t} end{equation}
Another numbered equation: begin{equation} nabla cdot vec{D} = rho_f end{equation}
Chemical Equations¶
Using mhchem package: \(\(\ce{H2O + NaCl -> Na+ + Cl- + H2O}\)\)
Cancellation¶
Using cancel package: \(\(\frac{x^2 - 1}{x - 1} = \frac{(x-1)(x+1)}{x-1} = \frac{\cancel{(x-1)}(x+1)}{\cancel{x-1}} = x + 1\)\)
Color Support¶
Using color extensions: \(\(\color{red}{x^2} + \color{blue}{y^2} = \color{green}{r^2}\)\)
Complex Expressions¶
Fourier Transform: \(\(\mathcal{F}\{f(t)\} = F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-i\omega t} \dd t\)\)
Schrödinger equation: \(\(i\hbar \frac{\partial}{\partial t} \Psi(\vec{r},t) = \hat{H} \Psi(\vec{r},t)\)\)
Matrix Equations¶
Eigenvalue problem: \(\(\mat{A}\vec{v} = \lambda\vec{v}\)\)
System of linear equations: \(\(\begin{bmatrix} 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{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix} = \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_m \end{bmatrix}\)\)
Long Equations with Line Breaking¶
For very long equations, MathJax will automatically break lines:
Testing Jupyter Integration¶
This page will also be used to test how these equations render when this content is included in Jupyter notebooks or when Jupyter notebooks with similar content are rendered in MkDocs.
Edge Cases¶
Mixed Delimiters¶
Testing mixed inline and display math:
When we consider the function \(f(x) = x^2\), we can analyze its derivative:
And its integral:
Unicode Support¶
Mathematical symbols: ∫∑∏√∞≠≤≥±×÷∂∇∆
Greek letters: αβγδεζηθικλμνξοπρστυφχψω
Special Characters¶
Testing escaping and special characters: - Dollar sign in text: $100 - Backslash: \ - Percent: %