Introduction#
About blockst#
blockst renders block-based programs in Typst documents, each drawn the way its editor draws it:
- Scratch 3 —
scratch(), the Scratch look in 26 languages, including right-to-left scripts, with an execution engine for turtle graphics and helpers for importing.sb3project files. - Blockly —
blockly(), today’s flat Blockly and the pre-2019 look, with profiles for the Jugendwettbewerb Informatik (jwinf.de) and its robot and turtle blocks. - MakeCode —
makecode(), the micro:bit and Calliope mini editors’ blocks in all 36 of their languages. - NEPO (Open Roberta) —
nepo(), the Calliope mini and micro:bit blocks of Open Roberta Lab.
All four share one text notation: a block per line, (…) for a value, [… v] for a dropdown, <…> for a condition, indentation and an end marker for the body of a loop. Typst hands the text to a bundled WASM plugin, the plugin parses it and returns SVG, Typst embeds the SVG. Nothing has to be installed beyond the package.
- Fully text-based: write blocks as plain text, get rendered blocks. The same notation for every editor.
- Each editor’s own geometry, palette and vocabulary — jwinf’s classic Blockly measured on jwinf.de, MakeCode’s zelos renderer as the editors run it.
- Localized: Scratch’s official translations, Blockly’s message files, the MakeCode editors’ own strings.
- Themes for print (
print,grayscale,high-contrast) and the document’s own category colours over any palette. - Line numbers and line labels for worksheets that talk about single lines.
Quick start#
#import "@preview/blockst:0.4.0": scratch, blockly, makecode, nepo
#scratch("
when green flag clicked
move (10) steps
turn cw (15) degrees
")The same document can hold the other editors’ blocks. A jwinf task:
#blockly("
Roboter-Programm
wiederhole (4) mal:
gehe nach rechts
falls <auf Kiste>
hebe Murmel auf ::aktionen
ende
ende
", profile: "jwinf")A micro:bit program:
#makecode("
beim Start
zeige Symbol [Herz v]
ende
wenn Knopf [A v] geklickt
zeige Zahl ((1) + (2))
pausiere (ms) (100)
ende
")Which function for which editor#
| Editor | Function | Profiles | Default language | Code fences |
|---|---|---|---|---|
| Scratch 3 | scratch() | — | "en", 26 languages | scratch via raw-scratch() |
| Blockly, jwinf | blockly() | blockly (default), blockly-klassisch, jwinf, jwinf-turtle | "de", 24 languages | blockly, jwinf, jwinf-turtle via raw-blockly() |
| MakeCode | makecode() | makecode (micro:bit, default), makecode-calliope | "de", 36 languages | makecode, microbit, calliope via raw-makecode() |
| Open Roberta | nepo() | platforms calliope (default), calliopev3, microbit | "de" | nepo via raw-nepo() |
Every function takes the same rendering options — theme, scale, font, line numbers, colours — and all of them read the defaults set with set-blockst(). The chapters Scratch, Blockly and jwinf, MakeCode and NEPO describe what is particular to each editor.
Package information#
- Version: 0.4.0
- License: MIT
- Repository: github.com/Loewe1000/blockst
- Compiler requirement: Typst 0.15.0+
- Font requirement: Scratch and Blockly labels are designed for Helvetica Neue. On Linux/Windows install a compatible font (e.g. Nimbus Sans) or set another one with
set-blockst(font: …). MakeCode labels use a monospace face — Menlo, Consolas or DejaVu Sans Mono, whichever is installed.