Skip to content

Instantly share code, notes, and snippets.

@frozolotl
Last active June 1, 2024 18:05
Show Gist options
  • Save frozolotl/e4fcead68b458401946cfd97a17ed395 to your computer and use it in GitHub Desktop.
Save frozolotl/e4fcead68b458401946cfd97a17ed395 to your computer and use it in GitHub Desktop.
Indented non-grid lists and enums for Typst
#set list(indent: 2em)
#show list: li => block({
for it in li.children {
let nesting = state("list-nesting", 0)
let indent = context h((nesting.get() + 1) * li.indent)
let marker = context {
let n = nesting.get()
li.marker.at(calc.rem(n, li.marker.len()))
}
let body = {
nesting.update(x => x + 1)
it.body
nesting.update(x => x - 1)
}
indent
marker
h(li.body-indent)
body
if li.tight {
linebreak()
} else {
parbreak()
}
}
})
#set enum(indent: 2em)
#show enum: en => block({
let number = en.start
for it in en.children {
number = if it.has("number") { it.number } else { number }
let parents = state("enum-parents", ())
let indent = context h((parents.get().len() + 1) * en.indent)
let num = if en.full {
context numbering(en.numbering, ..parents.get(), number)
} else {
numbering(en.numbering, number)
}
let body = {
parents.update(arr => {
arr.push(number)
arr
})
it.body
parents.update(arr => {
let _ = arr.pop()
arr
})
}
number += 1
indent
num
h(en.body-indent)
body
if en.tight {
linebreak()
} else {
parbreak()
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment