This is my first function in Typst. It prints a Pascal Triangle and was the result of an experiment initially involved a trailing spaces issue.
A function to print Pascal's Triangle
#let pascal_triangle(n) = {
set align(center)
let row = ()
for r in range(0, n) {
// step the row
for i in range(row.len() - 1, 0, step: -1) {
row.at(i) = row.at(i) + row.at(i - 1)
}
row.push(1)
// print the row
grid(
columns: row.len() * (32pt,),
align: center,
//stroke : 0.2pt,
..row.map(str)
)
}
}
#pascal_triangle(13)
The result:
Thanks to @bluss and @janekfleper