主页 Math Formula Render
Post
Cancel

Math Formula Render

Preface

This article is strongly personal in tone. If you find it uncomfortable to read, please close it as soon as possible. This article is only a personal learning record. You are welcome to repost or share it within the scope of the license agreement, but please respect the copyright and keep the original link. Thank you for your understanding and cooperation. If you find this site helpful, you can subscribe via RSS. Thanks for your support!

This post tests MathJax 3.2.2 rendering, following the official Chirpy theme conventions: block-level equations use $$...$$, inline math uses $...$ (never use ```math fences — kramdown GFM renders them as plain code blocks).

1. Inline Math

When $a \ne 0$, the equation $ax^2 + bx + c = 0$ has two solutions. Here is Einstein’s mass-energy equivalence $E = mc^2$, and Euler’s identity $e^{i\pi} + 1 = 0$.

2. Block Equations (Basics)

\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}\] \[\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}\] \[\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}\]

3. Numbered Equations and References (equation + label)

\[\begin{equation} \nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0} \label{eq:gauss} \end{equation}\]

Gauss’s law is given by $\eqref{eq:gauss}$, where $\rho$ is the charge density.

\[\begin{equation} \nabla \times \mathbf{B} = \mu_0 \mathbf{J} + \mu_0 \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t} \label{eq:ampere} \end{equation}\]

The Ampère–Maxwell law is shown in $\eqref{eq:ampere}$; both $\eqref{eq:gauss}$ and $\eqref{eq:ampere}$ belong to Maxwell’s equations.

4. Multi-line Alignment (align)

\[\begin{align} f(x) &= (x + 1)^2 \\ &= x^2 + 2x + 1 \\ &= x^2 + 2x + 2 - 1 \end{align}\] \[\begin{align} \frac{\partial u}{\partial t} &= \alpha \frac{\partial^2 u}{\partial x^2} \\ \frac{\partial u}{\partial t} + u \frac{\partial u}{\partial x} &= 0 \end{align}\]

5. Matrices

\[\begin{pmatrix} a & b \\ c & d \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} ax + by \\ cx + dy \end{pmatrix}\] \[A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}, \quad \det(A) = 0\]

6. Fractions, Scripts, Greek Letters

\[\frac{\partial^2 \varphi}{\partial x^2} + \frac{\partial^2 \varphi}{\partial y^2} = 0\]

The Greek alphabet: $\alpha, \beta, \gamma, \delta, \varepsilon, \zeta, \eta, \theta, \lambda, \mu, \nu, \pi, \rho, \sigma, \tau, \phi, \omega, \Gamma, \Delta, \Theta, \Lambda, \Sigma, \Omega$

7. Sums, Integrals, Limits

\[\lim_{n \to \infty} \left( 1 + \frac{1}{n} \right)^n = e\] \[\oiint_S \mathbf{F} \cdot d\mathbf{S} = \iiint_V \nabla \cdot \mathbf{F} \, dV\] \[\sum_{k=0}^{n} \binom{n}{k} x^k y^{n-k} = (x + y)^n\]

8. Special Operators

\[a \approx b, \quad a \ne b, \quad a \times b, \quad a \div b, \quad a \pm b, \quad a \le b, \quad a \ge b, \quad a \in S, \quad A \subset B, \quad A \cap B, \quad A \cup B\] \[\forall \varepsilon > 0, \exists \delta > 0: |x - x_0| < \delta \Rightarrow |f(x) - f(x_0)| < \varepsilon\]

9. Long Formula (Horizontal Scroll Test)

\[P(X=k) = \frac{\lambda^k e^{-\lambda}}{k!}, \quad k = 0, 1, 2, \ldots, \quad E(X) = \operatorname{Var}(X) = \lambda, \quad \hat{\theta}_{MLE} = \arg\max_{\theta} \prod_{i=1}^{n} f(x_i; \theta)\]

10. Dollar Signs in Code Blocks (Must Not Render)

1
2
3
4
5
<?php
$price = 100;
$total = $price * 1.2;
echo "Total: $total";
?>
1
2
const price = 5;
console.log(`Cost: ${price * 3} dollars`);

Neither $price nor ${price} inside code blocks should trigger math rendering.

11. Mixed Layout Test

The Fourier transform $F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-i\omega t} \, dt$ is a cornerstone of signal processing; its inverse is:

\[f(t) = \frac{1}{2\pi} \int_{-\infty}^{\infty} F(\omega) e^{i\omega t} \, d\omega\]

GPU alignment arithmetic (echoing the earlier post):

\[\text{offset} = \frac{\text{size} + \text{alignment} - 1}{\text{alignment}} \times \text{alignment} = \left\lceil \frac{\text{size}}{\text{alignment}} \right\rceil \times \text{alignment}\]

12.1 Piecewise Functions and Matrix Variants (cases / vmatrix)

\[f(x) = \begin{cases} x^2, & x \ge 0 \\ -x^2, & x < 0 \end{cases}\] \[\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc, \quad \begin{Vmatrix} 1 \\ 2 \end{Vmatrix} = \sqrt{5}\]

12.2 Decorative Structures (boxed / overbrace / underbrace / xrightarrow / substack / cancel)

\[\boxed{E = mc^2}\] \[\underbrace{(a + b + \cdots + z)}_{26\ \text{terms}}, \quad \overbrace{a + a + \cdots + a}^{n\ \text{terms}}\] \[A \xrightarrow{\text{rotate}} B \qquad A \xleftarrow{\text{inverse rotate}} A\] \[\sum_{\substack{0 \le i \le n \\ 0 \le j \le i}} a_{ij} = \sum_{i=0}^{n} \sum_{j=0}^{i} a_{ij}\] \[\frac{a}{\cancel{b}} \cdot \cancel{b} = a\]

12.3 Series Expansions

\[e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots\] \[f(x) = \frac{a_0}{2} + \sum_{n=1}^{\infty} \left( a_n \cos\frac{n\pi x}{L} + b_n \sin\frac{n\pi x}{L} \right)\]

12.4 Probability and Statistics

\[P(A \mid B) = \frac{P(B \mid A) \, P(A)}{P(B)}\] \[p(x) = \frac{1}{\sqrt{2\pi}\,\sigma} \exp\left( -\frac{(x-\mu)^2}{2\sigma^2} \right)\] \[\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i, \quad s^2 = \frac{1}{n-1}\sum_{i=1}^{n} (x_i - \bar{x})^2\]

12.5 Vector Calculus (Gradient / Divergence / Curl)

\[\nabla f = \frac{\partial f}{\partial x}\mathbf{i} + \frac{\partial f}{\partial y}\mathbf{j} + \frac{\partial f}{\partial z}\mathbf{k}\] \[\nabla \cdot \mathbf{F} = \frac{\partial F_x}{\partial x} + \frac{\partial F_y}{\partial y} + \frac{\partial F_z}{\partial z}\] \[\nabla \times \mathbf{F} = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \dfrac{\partial}{\partial x} & \dfrac{\partial}{\partial y} & \dfrac{\partial}{\partial z} \\ F_x & F_y & F_z \end{vmatrix}\]

12.6 Classic Physics Equations

Maxwell’s equations (differential form):

\[\begin{align} \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{align}\]

The Schrödinger equation:

\[i\hbar \frac{\partial}{\partial t}\Psi(\mathbf{r},t) = \left( -\frac{\hbar^2}{2m}\nabla^2 + V(\mathbf{r}) \right) \Psi(\mathbf{r},t)\]

The Euler–Lagrange equation:

\[\frac{\partial L}{\partial q} - \frac{d}{dt}\frac{\partial L}{\partial \dot{q}} = 0\]

12.7 Linear Algebra

\[\mathbf{A}\mathbf{v} = \lambda \mathbf{v}, \quad \mathbf{A} = \mathbf{P}\mathbf{D}\mathbf{P}^{-1}, \quad \mathbf{A} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^{\mathsf{T}}\] \[\operatorname{tr}(\mathbf{A}) = \sum_{i=1}^{n} a_{ii}, \quad \operatorname{rank}(\mathbf{A}\mathbf{B}) \le \min\{\operatorname{rank}(\mathbf{A}), \operatorname{rank}(\mathbf{B})\}\]

12.8 Machine Learning Formulas

\[\text{softmax}(z_i) = \frac{e^{z_i}}{\sum_{j=1}^{K} e^{z_j}}, \quad \mathcal{L} = -\sum_{i=1}^{C} y_i \log \hat{y}_i\] \[\text{Attention}(Q, K, V) = \text{softmax}\left( \frac{QK^{\mathsf{T}}}{\sqrt{d_k}} \right) V\] \[\nabla_{\theta} J(\theta) = \mathbb{E}_{\pi_{\theta}} \left[ \sum_{t=0}^{T} \nabla_{\theta} \log \pi_{\theta}(a_t \mid s_t) \, G_t \right]\]

12.9 CJK Text Inside Math (\text Test)

\[\text{speed} = \frac{\text{distance}}{\text{time}}, \quad p = \frac{F}{S}\]

13. Math Symbol Pronunciation Cheat Sheet

Adapted from a printable Chinese pronunciation reference; 11 categories. The third column lists the LaTeX command.

13.1 Basic Operators

SymbolLaTeXNameMeaning / Example
$+$+plusaddition, $2 + 3 = 5$
$-$-minussubtraction, $5 - 2 = 3$
$\times$\timestimes$2 \times 3 = 6$
$\cdot$\cdotdot / centered dot$a \cdot b$
$\div$\divdivided by$6 \div 2 = 3$
$\pm$\pmplus or minus$\pm 3$
$\mp$\mpminus or plusopposite of $\pm$
$=$=equals$a = b$
$\ne$\neis not equal to$a \ne b$
$\approx$\approxis approximately equal to$\pi \approx 3.14$
$\equiv$\equivis identically equal to$a \equiv a$
$\propto$\proptois proportional to$y \propto x$
$:$:ratio$3 : 5$

13.2 Comparison

SymbolLaTeXNameMeaning / Example
$>$>greater than$5 > 3$
$<$<less than$3 < 5$
$\ge$\gegreater than or equal to$a \ge b$
$\le$\leless than or equal to$a \le b$
$\gg$\ggmuch greater than$a \gg b$
$\ll$\llmuch less than$a \ll b$
$\nless$\nlessnot less thansame as $\ge$
$\ngtr$\ngtrnot greater thansame as $\le$

13.3 Exponents, Roots, Logarithms

SymbolLaTeXNameMeaning / Example
$a^2$a^2a squaredsecond power
$a^3$a^3a cubedthird power
$a^n$a^na to the nn-th power
$\sqrt{a}$\sqrt{a}square root of a$\sqrt{4} = 2$
$\sqrt[3]{a}$\sqrt[3]{a}cube root$\sqrt[3]{8} = 2$
$\sqrt[n]{a}$\sqrt[n]{a}n-th rootn-th root of a
$\log_a b$\log_a blog base a of b$\log_{10} 100 = 2$
$\ln x$\ln xnatural logbase $e$
$\lg x$\lg xcommon logbase 10
$\mathrm{e}$eEuler’s number$\mathrm{e} \approx 2.718$
$n!$n!n factorial$3! = 6$
$\vert x \vert$\vert x \vertabsolute value of x$\vert -3 \vert = 3$

13.4 Set Theory

SymbolLaTeXNameMeaning / Example
$\in$\inbelongs to$x \in A$
$\notin$\notindoes not belong tonot an element
$\subseteq$\subseteqis a subset of$A \subseteq B$
$\subset$\subsetis a proper subset of$A \subset B$
$\supseteq$\supseteqis a superset of$B \supseteq A$
$\cup$\cupunion$A \cup B$
$\cap$\capintersection$A \cap B$
$\emptyset$\emptysetthe empty setno elements
$\complement$\complementcomplementcomplement in a universe
$\forall$\forallfor allholds for all elements
$\exists$\existsthere existsat least one
$\nexists$\nexiststhere does not existno such element
$\mathbb{N}$\mathbb{N}natural numbers${0, 1, 2, \ldots}$
$\mathbb{Z}$\mathbb{Z}integers${\ldots, -1, 0, 1, \ldots}$
$\mathbb{Q}$\mathbb{Q}rational numbersall fractions $p/q$
$\mathbb{R}$\mathbb{R}real numbersall reals
$\mathbb{C}$\mathbb{C}complex numbers$a + bi$

13.5 Calculus

SymbolLaTeXNameMeaning / Example
$\sum$\sumsummation / sigma$\sum_i x_i$
$\prod$\prodproduct / capital pirepeated product
$\int$\intintegraldefinite or indefinite
$\iint$\iintdouble integral2-D integral
$\oint$\ointcontour integralalong a closed path
$\frac{df}{dx}$\frac{df}{dx}derivative of f with respect to xdifferentiation
$\partial$\partialpartial (derivative)$\partial f / \partial x$
$\nabla$\nablanabla / delgradient operator
$\Delta$\Deltadelta / incrementchange, $\Delta x$
$\lim$\limlimit$\lim_{x \to 0} f(x)$
$\to$\totends to$x \to 0$
$\infty$\inftyinfinity$x \to \infty$
$o(x)$o(x)little-ohigher-order infinitesimal

13.6 Logic

SymbolLaTeXNameMeaning / Example
$\Rightarrow$\Rightarrowimplies$p \Rightarrow q$
$\Leftrightarrow$\Leftrightarrowif and only ifnecessary and sufficient
$\to$\toderiveslogical derivation
$\land$\landlogical and$p \land q$
$\lor$\lorlogical or$p \lor q$
$\neg$\negnegation$\neg p$
$\sim$\simnotlogical negation
$\oplus$\oplusexclusive or / XORbitwise XOR
$\vdash$\vdashsyntactically entailsprovable
$\top$\toptautology / topalways true
$\bot$\botcontradiction / bottomalways false

13.7 Geometry

SymbolLaTeXNameMeaning / Example
$\angle$\angleangle$\angle ABC$
$\parallel$\parallelis parallel to$AB \parallel CD$
$\nparallel$\nparallelis not parallel tonot parallel
$\perp$\perpis perpendicular to$AB \perp CD$
$\triangle$\triangletriangle$\triangle ABC$
$\bigcirc$\bigcirccirclecircle $O$
$^\circ$^\circdegrees$90^\circ$
$^\prime$^\primeminutes of arc$30^\circ 15^\prime$
$^{\prime\prime}$^{\prime\prime}seconds of arcarc seconds
$\cong$\congis congruent to$\triangle ABC \cong \triangle DEF$
$\sim$\simis similar to$\triangle ABC \sim \triangle DEF$
$\overset{\frown}{AB}$\overset{\frown}{AB}arcarc $AB$

13.8 Probability and Statistics

SymbolLaTeXNameMeaning / Example
$P(A)$P(A)probabilityprobability of event $A$
$E(X)$E(X)expectationexpected value
$\operatorname{Var}(X)$\operatorname{Var}variancealso $D(X)$
$\sigma$\sigmastandard deviationsigma
$\sigma^2$\sigma^2variancesigma squared
$\mu$\mumeanpopulation mean
$\bar{x}$\bar{x}x barsample mean
$N(\mu, \sigma^2)$N(\mu,\sigma^2)normal distributionmean $\mu$, variance $\sigma^2$
$A \cap B$\capintersection of eventsboth occur
$A \cup B$\cupunion of eventsat least one occurs
$P(A \vert B)$P(A \vert B)conditional probability$A$ given $B$
$A \mathrel{\perp\mkern-6mu\perp} B$\mathrel{\perp\mkern-6mu\perp}independentstatistically independent (kramdown GFM eats the backslash in \!, hence the \mkern form)

13.9 Linear Algebra

SymbolLaTeXNameMeaning / Example
$\vert A \vert$\vert A \vertdeterminant of Adeterminant
$\det(A)$\det(A)determinantsame as $\vert A \vert$
$A^{\mathsf{T}}$A^{\mathsf{T}}A transposematrix transpose
$A^{-1}$A^{-1}A inversematrix inverse
$\operatorname{rank}(A)$\operatorname{rank}rankrank of the matrix
$\operatorname{tr}(A)$\operatorname{tr}tracesum of diagonal entries
$\langle x, y \rangle$\langle x,y \rangleinner productdot product of vectors
$\Vert x \Vert$\Vert x \Vertnorm of xlength of a vector
$\otimes$\otimestensor productKronecker product
$\oplus$\oplusdirect sumdirect sum of subspaces
$I$Iidentity matrixones on the diagonal
$\ker$\kerkernelnull space of a map

13.10 Miscellaneous

SymbolLaTeXNameMeaning / Example
$\equiv$\equivcongruent (modulo)$a \equiv b \pmod{n}$
$\bmod$\bmodmodulo$7 \bmod 3 = 1$
$\lfloor x \rfloor$\lfloor x \rfloorfloor of x$\lfloor 3.7 \rfloor = 3$
$\lceil x \rceil$\lceil x \rceilceiling of x$\lceil 3.2 \rceil = 4$
$\binom{n}{k}$\binom{n}{k}n choose kcombinations
$\mathrm{A}_n^k$\mathrm{A}_n^kpermutationsk-permutations of n
$\gcd$\gcdgreatest common divisor$\gcd(12, 8) = 4$
$\operatorname{lcm}$\operatorname{lcm}least common multiple$\operatorname{lcm}(4, 6) = 12$
$f(x)$f(x)f of xfunction of x
$f^{-1}$f^{-1}f inverseinverse function
$\aleph_0$\aleph_0aleph-nullcardinality of the naturals

13.11 Greek Alphabet (Common in Math)

SymbolLaTeXNameCommon Usage
$A \ \alpha$A \alphaAlphaangles, coefficients
$B \ \beta$B \betaBetaangles, Beta function
$\Gamma \ \gamma$\Gamma \gammaGammaGamma function, Euler’s constant
$\Delta \ \delta$\Delta \deltaDeltachange, discriminant
$E \ \varepsilon$\varepsilonEpsilonsmall quantities, limits
$Z \ \zeta$Z \zetaZetaRiemann zeta function
$H \ \eta$H \etaEtaefficiency, viscosity
$\Theta \ \theta$\Theta \thetaThetaangles, parameters
$I \ \iota$I \iotaIotatiny quantities
$K \ \kappa$K \kappaKappacurvature, constants
$\Lambda \ \lambda$\Lambda \lambdaLambdawavelength, eigenvalues
$M \ \mu$M \muMumean, micro- prefix
$N \ \nu$N \nuNudegrees of freedom, frequency
$\Xi \ \xi$\Xi \xiXirandom variables
$O \ o$O oOmicronbig-O notation
$\Pi \ \pi$\Pi \piPicircle constant $\approx 3.14159$
$P \ \rho$P \rhoRhodensity, correlation
$\Sigma \ \sigma$\Sigma \sigmaSigmasummation, std deviation
$T \ \tau$T \tauTautorque, time constant
$\Upsilon \ \upsilon$\Upsilon \upsilonUpsilonoccasionally in physics
$\Phi \ \varphi$\Phi \varphiPhigolden ratio, phase
$X \ \chi$X \chiChichi-squared distribution
$\Psi \ \psi$\Psi \psiPsiwave function
$\Omega \ \omega$\Omega \omegaOmegaangular velocity, ohms
该博客文章由作者通过 CC BY 4.0 进行授权。