How to compact list items horizontally?

+ Main Level
    + Sublist 
    + Sublist
    + Sublist

Expected output

  1. 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

But there in some cases

+ Sublist with longer line

turns into

Sublist 
with 
longer 
line

how to arrange them in 2x2 grid?

how to arrange them in 2x2  grid?
a. xyz                  b. com
c. abc                  d. pqr

See How to layout nested #enum in two columns? perhaps?