1= Functions and scripting2
3Typst has a built-in scripting language for dynamic content.4
5== Variables6
7#let name = "sublimated"8#let version = 0.139#let features = ("math", "tables", "code", "figures")10
11The current version of Typst used by #name is #version.12
13== Conditionals14
15#let score = 8516
17Result: #if score >= 90 [18 excellent19] else if score >= 70 [20 good21] else [22 needs improvement23]24
25== Loops26
27Features supported:28#for feature in features [29 - #feature30]31
32Numbered:33#for (i, feature) in features.enumerate() [34 + #feature (#(i + 1) of #features.len())35]36
37== Functions38
39#let badge(label, color: blue) = box(40 fill: color.lighten(80%),41 stroke: color + 0.5pt,42 inset: (x: 6pt, y: 3pt),43 radius: 3pt,44)[#text(fill: color, size: 9pt, weight: "bold")[#label]]45
46Status: #badge[Active] #badge("Beta", color: orange) #badge("Deprecated", color: red)47
48== Computed content49
50#let data = (51 (name: "Alice", score: 92),52 (name: "Bob", score: 78),53 (name: "Carol", score: 95),54 (name: "Dave", score: 61),55)56
57#let average = data.map(d => d.score).sum() / data.len()58
59#table(60 columns: 3,61 [*Name*], [*Score*], [*Status*],62 ..data.map(d => (63 d.name,64 str(d.score),65 if d.score >= average [above avg] else [below avg],66 )).flatten(),67)68
69Class average: #calc.round(average, digits: 1)70
71== String operations72
73#let title = "hello world"74Uppercase: #upper(title) \75First letter: #title.first() \76Length: #title.len() characters v1
commit 86a4983
message create functions.typ via macOS
author anton
date Apr 18, 2026
size 1.4 KB