Math support in markdown
aka LaTeX, KaTeX, MathJAX
Installation
-
Install dependencies
Terminal window pnpm add katex rehype-katex remark-math -
Configure Astro
astro.config.mjs import remarkMath from "remark-math";import rehypeKatex from "rehype-katex";export default defineConfig({integrations: [starlight({customCss: ["./src/styles/custom.css"],}),],markdown: {remarkPlugins: [remarkMath],rehypePlugins: [rehypeKatex],},vite: {ssr: {noExternal: ["katex"],},},}); -
Add CSS
src/styles/custom.css @import url(katex/dist/katex.min.css);
Example
When $a \ne 0$, there are two solutions to $(ax^2 + bx + c = 0)$ and they are$$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $$When , there are two solutions to and they are