Skip to content

knot-literate-programming/knot

Repository files navigation

Knot

knot is not knitr — Literate programming for Typst, powered by Rust.

CI Latest Release Documentation License

Knot lets you write R and Python code directly inside Typst documents. The code executes, and the results — text, plots, tables — flow into your document automatically. Think RMarkdown or Quarto, but with Typst instead of LaTeX and a Rust engine underneath.


Features

  • Multi-language — R and Python in the same document, running in parallel
  • Smart caching — SHA-256 chained hashes; only changed chunks re-execute
  • Live preview — chunk-by-chunk streaming preview in VS Code as code runs
  • Rich output — plots (SVG/PNG), DataFrames as Typst tables, inline expressions
  • Bidirectional sync — click in the PDF to jump to the source, and vice versa
  • Full IDE support — completion, hover docs, diagnostics, formatting (Air + Ruff + Tinymist)

Installation

curl -sSf https://raw.githubusercontent.com/knot-literate-programming/knot/master/install.sh | bash

The script downloads the prebuilt binaries for your platform, installs the VS Code extension, and checks that all prerequisites (Typst, Tinymist, R, Python, Air, Ruff) are in place.

Prerequisites:

Tool Purpose Required?
Typst Compiles .typ → PDF Yes
Tinymist Powers the VS Code preview Yes
R Executes R chunks If using R
Python Executes Python chunks If using Python
Air R code formatter in VS Code Recommended
Ruff Python code formatter in VS Code Recommended
Build from source
git clone https://github.com/knot-literate-programming/knot.git
cd knot
cargo install --path crates/knot-cli
cargo install --path crates/knot-lsp

Then install the VS Code extension:

cd editors/vscode && npm install && npm run package
code --install-extension knot-*.vsix

Quick Start

knot init my-project
cd my-project
code .           # open in VS Code, then click "Start Preview"

A .knot file is a Typst document with executable code blocks:

#import "lib/knot.typ": *

= My Analysis

```{r}
#| label: summary
x <- c(2, 4, 6, 8, 10)
summary(x)
```

The mean is `{r} mean(x)` and the standard deviation is `{r} round(sd(x), 2)`.

```{python}
import matplotlib.pyplot as plt
plt.plot([1, 4, 9, 16])
plt.title("Growth")
typst(current_plot())
```

Compile to PDF:

knot build       # one-shot PDF
knot watch       # rebuild on save

How It Works

Knot compiles .knot files through a three-pass pipeline:

  1. Plan — parse, compute SHA-256 hashes, classify each chunk as Skip / CacheHit / MustExecute
  2. Execute — run R and Python chains in parallel; cache results
  3. Assemble — interleave outputs with source text to produce a .typ file for Typst

The VS Code extension shows a streaming preview: cache hits appear instantly, and each chunk updates the preview as it finishes executing.


Documentation

knot-literate-programming.github.io/knot

  • User guide — installation, chunk options, VS Code, CLI reference
  • Developer guide — architecture, adding a language executor, LSP internals

Contributing

We welcome bug reports, feature requests, and pull requests. See CONTRIBUTING.md for setup instructions and guidelines.


Citing Knot

@software{Klutchnikoff_Knot_2026,
  author  = {Klutchnikoff, Nicolas},
  title   = {{Knot: Literate programming for Typst}},
  url     = {https://github.com/knot-literate-programming/knot},
  version = {0.3.0},
  year    = {2026}
}

See CITATION.cff for full metadata.


License

Apache License 2.0 — see LICENSE. Inspired by knitr, Quarto, and Typst.

About

Knot: Blazing-fast, multi-language literate programming for Typst. Seamlessly weave reproducible R & Python code into your documents.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors