duskmoon314 / mdbook-typst

mdbook typst preprocessor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mdbook-typst

mdbook preprocessor to add typst support

Installation

cargo install --git https://github.com/duskmoon314/mdbook-typst
# OR
git clone https://github.com/duskmoon314/mdbook-typst.git
cargo build --release

Usage

Setup preprocessor

Add the following to your book.toml:

[preprocessor.typst]
# If installed via cargo build
command = "/path/to/mdbook-typst"

Control the style

Add css to control the style of the typst block:

/* css/typst.css as an example */
.typst-wrapper {
    display: flex;
    justify-content: center;
}

.typst-doc {
    transform: scale(1.75);
}

Add the following to your book.toml:

[output.html]
additional-css = ["css/typst.css"]

What this preprocessor does

This preprocessor will convert all code blocks with the language typst to a <div> with the class typst-wrapper and a <svg> with the class typst-doc inside.

Say you have the following code block in your markdown:

    hello
    ```typst
    y = f(x)
    ```
    world

This preprocessor will first change it to:

    hello
    ```typst
+   #set page(width:auto, height:auto, margin:0.5em)
    y = f(x)
    ```
    world

Then preprocessor will convert it to:

hello
<div class="typst-wrapper">
    <svg class="typst-doc" ...></svg>
</div>
world

TODO

  • Integrate typst in code instead of using std::process::Commend
  • Allow user to configure the preambles through book.toml

About

mdbook typst preprocessor

License:MIT License


Languages

Language:Rust 98.5%Language:CSS 1.5%