LaTeX math with KaTeX, pre-rendered at build time
Inline and display math, matrices, integrals, sums, Maxwell's equations and more — all rendered at build time, with the KaTeX stylesheet loaded only on opt-in pages.
This site supports LaTeX-style math out of the box. Equations are
parsed by remark-math and
rendered to plain HTML + CSS at build time by
rehype-katex.
Zero client JavaScript. Every equation below is server-rendered static markup. KaTeX runs only on the build server.
Add math: true to the post (or page) frontmatter:
---title: My math-heavy postmath: true---The theme component
MathStyles.astro is rendered only
when math: true, and Astro’s per-page CSS bundling guarantees that
katex.min.css (~29 kB) and its woff2 font assets are emitted only
on pages that include them. Non-math pages never download the
stylesheet.
Wrap inline expressions with single dollar signs: $ ... $.
The Pythagorean theorem states that for any right triangle with legs , and hypotenuse . Euler’s identity, , ties together five fundamental constants. The fine-structure constant is approximately .
To escape a literal dollar sign outside math, write \$, e.g. $5.00.
Use $$ ... $$ on their own lines for centred display equations.
The fundamental theorem of calculus:
Taylor series expansion:
A matrix and its determinant:
A linear system written compactly:
The Gaussian probability density function:
Bayes’ theorem:
Maxwell’s equations in SI units:
Schrödinger’s time-dependent equation:
- A blank line is required before and after a
$$block, otherwise Markdown can swallow the delimiters. - The same syntax works in both
.mdand.mdx. - Inside MDX, do not put
{immediately after$unless you intend a JSX expression — escape with\{if needed. - Forgot
math: true? You’ll see raw$x^2$text instead of a rendered formula. Add the flag and rebuild.
Pair this with the code blocks post — the two together cover everything you need to write technical content on this theme.