It is more complex than it needs to be for most uses because it tries to be as feature-complete as possible.
Last active
April 1, 2024 15:09
-
-
Save frozolotl/1eeafa5ff4a38b2aab412743bd9c1ded to your computer and use it in GitHub Desktop.
A reimplementation of the default enum layout directly in Typst.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#show enum: en => { | |
let gutter = if en.tight { | |
par.leading | |
} else if en.spacing != auto { | |
en.spacing | |
} else { | |
1.2em | |
} | |
let number = en.start | |
grid( | |
columns: (en.indent, auto, en.body-indent, auto), | |
row-gutter: gutter, | |
..for it in en.children { | |
number = if it.has("number") { it.number } else { number } | |
let (num, body) = if en.full { | |
let parents = state("enum-parents", ()) | |
let body = { | |
parents.update(arr => { | |
arr.push(number) | |
arr | |
}) | |
it.body | |
parents.update(arr => { | |
let _ = arr.pop() | |
arr | |
}) | |
} | |
(context numbering(en.numbering, ..parents.get(), number), body) | |
} else { | |
(numbering(en.numbering, number), it.body) | |
} | |
number += 1 | |
let num = grid.cell(align: en.number-align, text(overhang: false, num)) | |
([], num, [], body) | |
}, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment