diff --git a/content/index.md b/content/index.md deleted file mode 100644 index 91370ece0..000000000 --- a/content/index.md +++ /dev/null @@ -1,26 +0,0 @@ -# quartz-typst - -- [X] Equations -$$ -f(x) = exp(x) -\ -mat(1,2;3,4) -\ -$$ -- [X] Package Imports -$$ -#import "@preview/fletcher:0.5.1": diagram, node, edge -#diagram(spacing:(16mm,16mm),$ - X - #edge("r",$f$,"->",bend:30deg) - #edge("r",$g$,"->",bend:-30deg) - & Y -$) -$$ - -$$ -#import "@preview/physica:0.9.3": * -tensor(Gamma,+lambda,-mu,-nu) -$$ -- [ ] Inline math - diff --git a/docs/plugins/Latex.md b/docs/plugins/Latex.md index 236cbeca4..9ef37ff5d 100644 --- a/docs/plugins/Latex.md +++ b/docs/plugins/Latex.md @@ -11,9 +11,13 @@ This plugin adds LaTeX support to Quartz. See [[features/Latex|Latex]] for more This plugin accepts the following configuration options: -- `renderEngine`: the engine to use to render LaTeX equations. Can be `"katex"` for [KaTeX](https://katex.org/) or `"mathjax"` for [MathJax](https://www.mathjax.org/) [SVG rendering](https://docs.mathjax.org/en/latest/output/svg.html). Defaults to KaTeX. +- `renderEngine`: the engine to use to render LaTeX equations. Can be `"katex"` for [KaTeX](https://katex.org/), `"mathjax"` for [MathJax](https://www.mathjax.org/) [SVG rendering](https://docs.mathjax.org/en/latest/output/svg.html), or `"typst"` for [Typst](https://typst.app/) (a new way to compose LaTeX equation). Defaults to KaTeX. - `customMacros`: custom macros for all LaTeX blocks. It takes the form of a key-value pair where the key is a new command name and the value is the expansion of the macro. For example: `{"\\R": "\\mathbb{R}"}` +> [!note] Typst support +> +> Currently, typst doesn't support inline-math + ## API - Category: Transformer diff --git a/quartz/plugins/transformers/latex.ts b/quartz/plugins/transformers/latex.ts index f17d55795..26913bac3 100644 --- a/quartz/plugins/transformers/latex.ts +++ b/quartz/plugins/transformers/latex.ts @@ -1,12 +1,20 @@ import remarkMath from "remark-math" import rehypeKatex from "rehype-katex" import rehypeMathjax from "rehype-mathjax/svg" +//@ts-ignore import rehypeTypst from "@myriaddreamin/rehype-typst" import { QuartzTransformerPlugin } from "../types" +import { KatexOptions } from "katex" +import { Options as MathjaxOptions } from "rehype-mathjax/svg" +//@ts-ignore +import { Options as TypstOptions } from "@myriaddreamin/rehype-typst" interface Options { renderEngine: "katex" | "mathjax" | "typst" customMacros: MacroType + katexOptions: Omit + mathJaxOptions: Omit + typstOptions: TypstOptions } interface MacroType { @@ -24,43 +32,35 @@ export const Latex: QuartzTransformerPlugin> = (opts) => { htmlPlugins() { switch (engine) { case "katex": { - return [[rehypeKatex, { output: "html", macros }]] + return [[rehypeKatex, { output: "html", macros, ...(opts?.katexOptions ?? {}) }]] } case "typst": { - return [[rehypeTypst]] + return [[rehypeTypst, opts?.typstOptions ?? {}]] } case "mathjax": { - return [[rehypeMathjax, { macros }]] + return [[rehypeMathjax, { macros, ...(opts?.mathJaxOptions ?? {}) }]] } - default: { - return [[rehypeMathjax, { macros }]] + default: { + return [[rehypeMathjax, { macros, ...(opts?.mathJaxOptions ?? {}) }]] } } }, externalResources() { switch (engine) { - case "katex": { + case "katex": return { - css: [ - // base css - "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css", - ], + css: [{ content: "https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" }], js: [ { // fix copy behaviour: https://github.com/KaTeX/KaTeX/blob/main/contrib/copy-tex/README.md - src: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/contrib/copy-tex.min.js", + src: "https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/copy-tex.min.js", loadTime: "afterDOMReady", contentType: "external", }, ], } - } - case "typst": { - return {} - } - default: { - return {} - } + default: + return { css: [], js: [] } } }, }