PDF

blockstblockst0.4.0

Render Scratch, Blockly, MakeCode and Open Roberta blocks for educational documents.

Options for every editor#

scratch(), blockly(), makecode() and nepo() accept the same rendering options. Given on the call, they apply to that block group; set with set-blockst(), they become the document’s defaults; wrapped in blockst[…], they apply to everything inside.

set-blockst() — Global Defaults#

#set-blockst(
  theme: none,            // "normal", "high-contrast", "print", "grayscale"
  profile: none,          // default profile for blockly() and makecode()
  colors: none,           // (category: colour, …) over any palette
  scale: none,            // 80%, 0.8 — overall size
  inset-scale: none,      // 60% thin, 125% thick blocks; text size unchanged
  stroke-width: none,
  font: none,             // "Nimbus Sans"
  language: none,         // default language for every editor
  line-numbers: none,
  line-number-start: none,
  line-number-first-block: none,
  line-number-gutter: none,
)

All parameters are optional. Only provided values override the current defaults; a later set-blockst() changes only what it names.

blockst() — Group Override Container#

#blockst(theme: "high-contrast", scale: 80%)[
  #scratch("when green flag clicked\nmove (10) steps")
  #blockly("wiederhole (4) mal:\n  gehe nach rechts\nende", profile: "jwinf")
]

All parameters match set-blockst() but apply only within the body; spacing (default 1.5em) sets the gap between the blocks inside.

Themes#

ThemeDescription
"normal"Default — the editor’s full colours.
"high-contrast"Lighter, high-contrast variant for accessibility.
"print"Every block white with a black outline. The lightest on ink, but all categories look alike.
"grayscale"One distinct grey per category, so a control block still reads differently from an operator on a monochrome page.

The derived themes are computed from the palette in use, so grayscale on a jwinf profile is jwinf’s categories in grey, and a colour set with colors carries its own bevel, stroke, high-contrast and grey shades.

#let script = "when green flag clicked
go to (random position v)
turn cw (30) degrees"

#blockst(inset-scale: 50%)[#scratch(script)]
#blockst(theme: "high-contrast")[#scratch(script)]
#blockst(theme: "print")[#scratch(script)]

Colours#

colors lays the document’s own category colours over any palette — for the document with set-blockst(), for a single block or group on the rendering function or on blockst(). A hex string or a Typst colour per category; the category names are the ones the editor uses (motion, looks, … for Scratch, aktionen, schleifen, logik, … for jwinf, basic, input, loops, … for MakeCode).

#set-blockst(colors: (logik: "#73cc47"))
#blockly(programm, profile: "jwinf", colors: (aktionen: "#cc7347", schleifen: rgb("#5ba55b")))

jwinf colours its categories per task family; colors is the way to match a task that deviates from both jwinf profiles.

Fonts#

#set-blockst(font: "Nimbus Sans")

Scratch and Blockly labels default to Helvetica Neue, MakeCode labels to Menlo, Consolas or DejaVu Sans Mono. Set the font here rather than with set text(font: …): the renderer measures each label and writes the font into the SVG, so a document-level set text changes what is drawn but not what was measured, and the labels overlap.

Scale and inset scale#

scale multiplies the whole drawing (80%, 0.8). inset-scale changes the thickness of the blocks without touching the text: 60% gives compact, 125% generous blocks.

#set-blockst(scale: 80%)
#set-blockst(inset-scale: 60%)   // compact blocks

Line numbers#

#set-blockst(line-numbers: true, line-number-start: 1, line-number-gutter: 24)

line-number-start is the first number, line-number-gutter the width of the gutter in points. Numbering continues from one block group to the next; line-number-first-block says with which group it starts. The three can also be given as one dictionary, line-numbering: (enabled: true, start: 1, first-block: 1).