rehype plugin to render elements with a language-math
class with
Typst.
This package is a unified (rehype) plugin to render math.
You can add classes to HTML elements, use fenced code in markdown, or combine
with remark-math for a $C$
syntax extension.
This project is useful as it renders math with Typst at compile time, which means that there is no client side JavaScript needed.
This package is ESM only. In Node.js (version 16+), install with npm:
npm install @myriaddreamin/rehype-typst
Say our document input.html
contains:
<p>
Lift(<code class="language-math">L</code>) can be determined by Lift Coefficient
(<code class="language-math">C_L</code>) like the following equation.
</p>
<pre><code class="language-math">
L = 1/2 rho v^2 S C_L
</code></pre>
…and our module example.js
contains:
import rehypeTypst from '@myriaddreamin/rehype-typst'
import rehypeParse from 'rehype-parse'
import rehypeStringify from 'rehype-stringify'
import {read, write} from 'to-vfile'
import {unified} from 'unified'
const file = await unified()
.use(rehypeParse, {fragment: true})
.use(rehypeTypst)
.use(rehypeStringify)
.process(await read('input.html'))
file.basename = 'output.html'
await write(file)
…then running node example.js
creates an output.html
and open output.html
in a browser to see the rendered math.
This package exports no identifiers.
The default export is rehypeTypst
.
Render elements with a language-math
(or math-display
, math-inline
)
class with Typst.
Transform (Transformer
).
This plugin supports the syntax extension enabled by remark-math. It also supports math generated by using fenced code:
```math
C_L
```
The content of any element with a language-math
, math-inline
, or
math-display
class is transformed.
The elements are replaced by what Typst renders.
Either a math-display
class or using <pre><code class="language-math">
will
result in “display” math: math that is a centered block on its own line.