diff --git a/package-lock.json b/package-lock.json index e346c4afb..de4a63b7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@clack/prompts": "^0.11.0", + "@daiji256/rehype-mathml": "^1.2.1", "@floating-ui/dom": "^1.7.4", "@myriaddreamin/rehype-typst": "^0.6.0", "@napi-rs/simple-git": "0.1.22", @@ -196,6 +197,20 @@ "sisteransi": "^1.0.5" } }, + "node_modules/@daiji256/rehype-mathml": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@daiji256/rehype-mathml/-/rehype-mathml-1.2.1.tgz", + "integrity": "sha512-E1119EsVo1nORP0iO5S4/CKpXSKYNwdHSitxoowOGsqzYXuG/jgMINEyMNVidTQkWZ39tm7JrAbV+pCXIDsEZw==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "hast-util-from-html-isomorphic": "^2.0.0", + "hast-util-to-text": "^4.0.0", + "temml": "^0.11.0", + "unified": "^11.0.0", + "unist-util-visit-parents": "^6.0.0" + } + }, "node_modules/@emnapi/runtime": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.5.0.tgz", @@ -6772,6 +6787,15 @@ "node": ">=14" } }, + "node_modules/temml": { + "version": "0.11.11", + "resolved": "https://registry.npmjs.org/temml/-/temml-0.11.11.tgz", + "integrity": "sha512-Z/Ihgwad+ges0ez6+KmKWZ3o4BYbP6aZ/cU94cVtN+DwxwqxjHgcF4Z6cb9jLkKN+aU7uni165HsIxLHs5/TqA==", + "license": "MIT", + "engines": { + "node": ">=18.13.0" + } + }, "node_modules/tiny-inflate": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tiny-inflate/-/tiny-inflate-1.0.3.tgz", diff --git a/package.json b/package.json index be09dbfe5..218be32c9 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ }, "dependencies": { "@clack/prompts": "^0.11.0", + "@daiji256/rehype-mathml": "^1.2.1", "@floating-ui/dom": "^1.7.4", "@myriaddreamin/rehype-typst": "^0.6.0", "@napi-rs/simple-git": "0.1.22", diff --git a/quartz/plugins/transformers/latex.ts b/quartz/plugins/transformers/latex.ts index 40939d5e9..e8a3fadf5 100644 --- a/quartz/plugins/transformers/latex.ts +++ b/quartz/plugins/transformers/latex.ts @@ -1,6 +1,7 @@ import remarkMath from "remark-math" import rehypeKatex from "rehype-katex" import rehypeMathjax from "rehype-mathjax/svg" +import rehypeMathML from "@daiji256/rehype-mathml" //@ts-ignore import rehypeTypst from "@myriaddreamin/rehype-typst" import { QuartzTransformerPlugin } from "../types" @@ -10,17 +11,22 @@ import { Options as MathjaxOptions } from "rehype-mathjax/svg" import { Options as TypstOptions } from "@myriaddreamin/rehype-typst" interface Options { - renderEngine: "katex" | "mathjax" | "typst" + renderEngine: "katex" | "mathjax" | "typst" | "mathml" customMacros: MacroType katexOptions: Omit mathJaxOptions: Omit typstOptions: TypstOptions + mathMLOptions: MathMLOptions } interface MacroType { [key: string]: string } +interface MathMLOptions { + macros?: MacroType +} + export const Latex: QuartzTransformerPlugin> = (opts) => { const engine = opts?.renderEngine ?? "katex" const macros = opts?.customMacros ?? {} @@ -40,6 +46,9 @@ export const Latex: QuartzTransformerPlugin> = (opts) => { case "mathjax": { return [[rehypeMathjax, { macros, ...(opts?.mathJaxOptions ?? {}) }]] } + case "mathml": { + return [[rehypeMathML, { macros, ...(opts?.mathMLOptions ?? {}) }]] + } default: { return [[rehypeMathjax, { macros, ...(opts?.mathJaxOptions ?? {}) }]] }