Skip to content

Commit

Permalink
refactor: refactor LaTeX render support (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
moeyua authored Oct 30, 2024
1 parent d816c5c commit 5925f26
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.11.0
4 changes: 2 additions & 2 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import sitemap from '@astrojs/sitemap'
import swup from '@swup/astro'
import { defineConfig } from 'astro/config'
import robotsTxt from 'astro-robots-txt'
import rehypeKatex from 'rehype-katex'
import remarkMath from 'remark-math'
import UnoCSS from 'unocss/astro'
import { themeConfig } from './src/.config'
import remarkMath from 'remark-math'
import rehypeKatex from 'rehype-katex'

// https://astro.build/config
export default defineConfig({
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"astro-robots-txt": "^1.0.0",
"astro-seo": "^0.8.4",
"giscus": "^1.5.0",
"katex": "^0.16.11",
"rehype-katex": "^7.0.1",
"remark-math": "^6.0.0",
"typescript": "~5.5.4",
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/components/LaTeX.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const { latex } = themeConfig
const katex = latex.katex
---

{katex && (
<>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css" crossorigin="anonymous">
<script is:inline defer src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js" crossorigin="anonymous"></script>
<script is:inline defer src="https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/auto-render.min.js" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>
</>
)}

{
katex && (
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css"
crossorigin="anonymous"
/>
)
}
34 changes: 34 additions & 0 deletions src/content/posts/latex.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: "Test LaTeX"
pubDate: 2023-10-01
categories: ["test"]
description: "This is an article for testing LaTeX rendering."
---

# Test LaTeX

This is a sample article containing LaTeX mathematical formulas.

## Inline Formula

This is an inline formula: $E = mc^2$, which represents the mass-energy equivalence.

## Block Formula

Below is a block formula:

$$
\int_{a}^{b} f(x) \, dx = F(b) - F(a)
$$

This formula represents the fundamental theorem of calculus.

## Complex Formula

We can also display more complex formulas:

$$
\frac{d}{dx} \left( \int_{a}^{x} f(t) \, dt \right) = f(x)
$$

This formula represents the fundamental theorem of calculus in differential form.

0 comments on commit 5925f26

Please sign in to comment.