This document demonstrates how to use LaTeX equations in your Markdown files for AstroPaper. LaTeX is a powerful typesetting system often used for mathematical and scientific documents.

Photo by Vitaly Gariev
Table of contents
Instructions
In this section, you will find instructions on how to add support for LaTeX in your Markdown files for AstroPaper.
-
Install the necessary remark and rehype plugins by running:
pnpm install rehype-katex remark-math katex -
Update the Astro configuration to use these plugins:
// ...import remarkMath from "remark-math";import rehypeKatex from "rehype-katex";export default defineConfig({// ...markdown: {remarkPlugins: [remarkMath,[remarkToc, { heading: "(table of contents|შინაარსის ცხრილი)" }],[remarkCollapse, { test: "(Table of contents|შინაარსის ცხრილი)" }],],rehypePlugins: [rehypeKatex],shikiConfig: {// For more themes, visit https://shiki.style/themesthemes: { light: "min-light", dark: "night-owl" },wrap: false,},},// ...}); -
Import KaTeX CSS in your post layout file
To ensure KaTeX styles are loaded efficiently only on pages that need them, import the CSS directly into your post layout (e.g.,
src/layouts/PostDetails.astro). This enables automatic code-splitting and bundling optimization by Astro’s build tool.---import { render, type CollectionEntry } from "astro:content";import Layout from "@/layouts/Layout.astro";// ... other importsimport "katex/dist/katex.min.css";export interface Props {// ...}---This approach is superior to linking external CDN stylesheets because:
- No render-blocking: The CSS is bundled with your page JavaScript, not fetched separately
- Code-splitting: CSS is only loaded on pages that actually use math equations
- Automatic optimization: Astro minifies and optimizes the CSS automatically
- Offline support: No external CDN dependency—everything is self-hosted
-
As the last step, add a text-color for
katexintypography.css.@plugin "@tailwindcss/typography";@layer base {/* other classes *//* Katex text color */.prose .katex-display {@apply text-foreground;}/* ===== Code Blocks & Syntax Highlighting ===== *//* other classes */}
And voilà, this setup allows you to write LaTeX equations in your Markdown files, which will be rendered properly when the site is built. Once you do it, the rest of the document will appear rendered correctly.
Inline Equations
Inline equations are written between single dollar signs $...$. Here are some examples:
- The famous mass-energy equivalence formula:
- The quadratic formula:
- Euler’s identity:
Block Equations
For more complex equations or when you want the equation to be displayed on its own line, use double dollar signs $$...$$:
The Gaussian integral:
$$ \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi} $$The definition of the Riemann zeta function:
$$ \zeta(s) = \sum_{n=1}^{\infty} \frac{1}{n^s} $$Maxwell’s equations in differential form:
$$\begin{aligned}\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\left(\mathbf{J} + \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t}\right)\end{aligned}$$Using Mathematical Symbols
LaTeX provides a wide range of mathematical symbols:
- Greek letters: , , , , ,
- Operators: , , , ,
- Relations: , , , ,
- Logical symbols: , , , ,