chore: update katex options and cleanup types

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-11-12 06:35:58 -05:00
parent 5ede8066f1
commit ebe9c5bc5b
No known key found for this signature in database
GPG Key ID: 18974753009D2BFA
3 changed files with 23 additions and 45 deletions

View File

@ -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

View File

@ -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

View File

@ -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<KatexOptions, "macros" | "output">
mathJaxOptions: Omit<MathjaxOptions, "macros">
typstOptions: TypstOptions
}
interface MacroType {
@ -24,43 +32,35 @@ export const Latex: QuartzTransformerPlugin<Partial<Options>> = (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 }]]
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: [] }
}
},
}