Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Last active May 22, 2025 16:49
Show Gist options
  • Save peterhellberg/e5c7d863f5069c1e97b5e9a9db5d855e to your computer and use it in GitHub Desktop.
Save peterhellberg/e5c7d863f5069c1e97b5e9a9db5d855e to your computer and use it in GitHub Desktop.
Using the Typst package for cmarker to convert Markdown into PDF/SVG via `typst compile`

We can write Markdown!

Using lots of fancy features.

A second-level heading

Text that is not a quote

Text that is a quote

Some basic Git commands are:

git status
git add
git commit

A little bit of code:

package main

import "fmt"

func main() {
    fmt.Println("Hello!")
}
Column 1 Column 2
Row 1 Cell 1 Row 1 Cell 2
Row 2 Cell 1 Row 2 Cell 2
#import "@preview/cmarker:0.1.5"
#let cfg = (
file: sys.inputs.at("FILE", default: "document.md"),
rule: eval(sys.inputs.at("RULE", default: "pagebreak")),
page: eval("("+sys.inputs.at("PAGE", default: "paper: \"a4\", margin: 0.5cm")+")"),
text: eval("("+sys.inputs.at("TEXT", default: "font: \"Inter\", size: 14pt")+")"),
code: eval("("+sys.inputs.at("CODE", default: "font: \"Office Code Pro D\", weight: \"medium\", size: 1em")+")"),
line: eval("("+sys.inputs.at("LINE", default: "stroke: luma(220)")+")"),
table: eval("("+sys.inputs.at("TABLE", default: "stroke: luma(220), inset: 0.4em")+")"),
raw: (
box: eval("("+sys.inputs.at("RAW_BOX", default: "")+")"),
block: eval("("+sys.inputs.at("RAW_BLOCK", default: "inset: 1em")+")"),
),
)
#set page(..cfg.page)
#set text(..cfg.text)
#set line(..cfg.line)
#set table(..cfg.table)
#let code=text.with(..cfg.code)
#show raw.where(block: false): it => box.with(..cfg.raw.box)(code(it))
#show raw.where(block: true): it => block.with(..cfg.raw.block)(code(it))
#cmarker.render(
read(cfg.file),
scope: (
cfg: cfg,
rule: cfg.rule,
code: code,
image: (path, alt: none) => image(path, alt: alt)
)
)
@peterhellberg
Copy link
Author

peterhellberg commented May 22, 2025

typst compile document.typ document.svg

document

The markdown file document.md contains a HTML-comment like this:

<!--raw-typst
#circle(radius: 5em, fill: gradient.radial(yellow, green))
-->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment