惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

AstroPaper

AstroPaper 6.0 | AstroPaper AstroPaper 5.0 | AstroPaper How to integrate Giscus comments into AstroPaper | AstroPaper AstroPaper 4.0 | AstroPaper How to use Git Hooks to set Created and Modified Dates | AstroPaper AstroPaper 3.0 | AstroPaper How to update dependencies of AstroPaper | AstroPaper AstroPaper 2.0 | AstroPaper Dynamic OG image generation in AstroPaper blog posts | AstroPaper Predefined color schemes | AstroPaper Customizing AstroPaper theme color schemes | AstroPaper Adding new posts in AstroPaper theme | AstroPaper How to configure AstroPaper theme | AstroPaper Tailwind Typography Plugin | AstroPaper How Do I Develop My Terminal Portfolio Website with React | AstroPaper How Do I Develop My Portfolio Website & Blog | AstroPaper
How to add LaTeX Equations in Astro blog posts | AstroPaper
Sat Naing · 2024-09-09 · via AstroPaper

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.

Free Close-up of complex equations on a chalkboard, showcasing chemistry and math symbols. Stock Photo
Photo by Vitaly Gariev

Table of contents

Open Table of contents
  • Instructions
  • Inline Equations
  • Block Equations
  • Using Mathematical Symbols

Instructions

In this section, you will find instructions on how to add support for LaTeX in your Markdown files for AstroPaper.

  1. Install the necessary remark and rehype plugins by running:

    pnpm install rehype-katex remark-math katex
  2. Update the Astro configuration to use the these plugins:

    // ...
    import remarkMath from "remark-math";
    import rehypeKatex from "rehype-katex";
    
    export default defineConfig({
      // ...
      markdown: {
        remarkPlugins: [
          remarkMath,
          remarkToc,
          [remarkCollapse, { test: "Table of contents" }],
        ],
        rehypePlugins: [rehypeKatex],
        shikiConfig: {
          // For more themes, visit https://shiki.style/themes
          themes: { light: "min-light", dark: "night-owl" },
          wrap: false,
        },
      },
      // ...
    });astro.config.ts
  3. Import KaTeX CSS in the main layout file

    ---
    import { SITE } from "@config";
    
    // astro code
    ---
    
    <!doctype html>
    <!-- Other elements  -->
    <meta property="og:image" content={socialImageURL} />
    
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.css"
    />
    
    <body>
      <slot />
    </body>src/layouts/Layout.astro
  4. As the last step, add a text-color for katex in typography.css.

    @plugin "@tailwindcss/typography";
    
    @layer base {
      /* other classes */
    
      /* Katex text color */
      .prose .katex-display {
        @apply text-foreground;
      }
    
      /* ===== Code Blocks & Syntax Highlighting ===== */
      /* other classes */
    }src/styles/typography.css

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:

  1. The famous mass-energy equivalence formula: $E = mc^2$
  2. The quadratic formula: $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$
  3. Euler’s identity: $e^{i\pi} + 1 = 0$

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: $\alpha$, $\beta$, $\gamma$, $\delta$, $\epsilon$, $\pi$
  • Operators: $\sum$, $\prod$, $\int$, $\partial$, $\nabla$
  • Relations: $\leq$, $\geq$, $\approx$, $\sim$, $\propto$
  • Logical symbols: $\forall$, $\exists$, $\neg$, $\wedge$, $\vee$