jfdsap
1
+ Main Level
+ Sublist
+ Sublist
+ Sublist
Expected output
- Main Level
a. Sublist b.Sublist c.Sublist
I am already using:
#let henum(it) = [
#let items = if it.func() == enum {
enum.children.len()
} else if it.has("children") {
it.children.filter(x => x.func() == enum.item).len()
} else {
panic("Unknown input")
}
#show enum.item: it => [#it #colbreak()]
#columns(items)[
#it
]
]
this is still writing lots of repeating code. I want to taget level 2 list like
#show: enum.items.where(level:2): henum
1 Like
Currently, you can’t target enum
at specific levels, see Add level field to bullet list items for easier format and style minipulation · Issue #4520 · typst/typst · GitHub
The comments in the github issue discussion give a workaround, which I combined with the code example you linked:
#let henum(it) = [
#if it.has("children") and it.children.len() == 1 {
return it
}
#let items = if it.has("children") {
it.children.filter(x => x.func() == enum.item).len()
} else {
panic("Unknown input")
}
#show enum.item: it => [#it #colbreak()]
#columns(items)[
#it.children.enumerate().map(((idx, child)) => {
// ensure consistent numbering if not manually numering items
if child.number == none {
let fields = child.fields()
let num = fields.remove("number")
let body = fields.remove("body")
return enum.item(
..fields,
idx + 1,
body
)
}
child
}).join()
]
]
#let depth = state("depth", 0)
#show enum.item: i => {
depth.update(d => d + 1)
i
depth.update(d => d - 1)
}
#show enum: l => {
context if depth.get() == 2 {
henum(l)
}
else {
l
}
}
2 Likes