@myriaddreamin/rehype-typst

0.5.4 • Public • Published

rehype-typst

rehype plugin to render elements with a language-math class with Typst.

Contents

What is this?

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.

When should I use this?

This project is useful as it renders math with Typst at compile time, which means that there is no client side JavaScript needed.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install @myriaddreamin/rehype-typst

Use

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.

API

This package exports no identifiers. The default export is rehypeTypst.

unified().use(rehypeTypst[, options])

Render elements with a language-math (or math-display, math-inline) class with Typst.

Returns

Transform (Transformer).

Markdown

This plugin supports the syntax extension enabled by remark-math. It also supports math generated by using fenced code:

```math
C_L
```

HTML

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @myriaddreamin/rehype-typst

Weekly Downloads

23,005

Version

0.5.4

License

MIT

Unpacked Size

11 kB

Total Files

4

Last publish

Collaborators

  • myriaddreamin