How to indent lists that are part of a paragraph (i.e. no paragraph break before the list) using a rule?

Hi all, I would like to slightly indent lists like this one:

some text:
- item 1
- item 2

but not like this other one:

some text

- item 1
- item 2

I know I can use #move(dx:...) or something similar, but I would like to achieve it using a rule instead.

Is that possible?

Thanks!

Hello!
The obvious solution for this would be to set the list indent right before each usage.

some text

#set list(indent: 1em)
- item 1
- item 2

#set list(indent: 0em)
some text:
- item 1
- item 2

image

A more automatic solution would be to use custom checkmarks. @OrangeX4 has implemented this, and I am shamelessly using his code :)

#show list.item: it => {
  // https://github.com/OrangeX4/typst-cheq/blob/main/lib.typ
  // The body should be a sequence
  if not (type(it.body) == content and it.body.func() == [].func()) {
    return it
  }
  let children = it.body.children
  // A checklist item has at least 5 children: `[`, markder, `]`, space, content
  if children.len() < 5 or not (children.at(0) == [#"["] and children.at(2) == [#"]"] and children.at(3) == [ ]) {
    return it
  }  
  // Process
  show list: set block(height: 0em) // Typst v0.12
  let marker = children.at(1).text
  if marker == "I" {
    list(indent: 1em, children.slice(4).sum())
  }
}

some text  
- [I] item 1
- [I] item 2

some text:
- item 1
- item 2

image

I would suggest putting the set in a scope instead of manually resetting it:

some text

#[
  #set list(indent: 1em)
  - item 1
  - item 2
]

#set list(indent: 0em)
some text:
- item 1
- item 2

However, your response still misses a crucial part: how can you automatically detect whether a list is “attached” to the preceding paragraph? So that a single rule could style both lists accordingly.

@Carlos, I have adjusted the title accordingly, because I think it could have been mistaken for asking about nested lists:

- top-level
  - not top-level

I hope this way it gets some additional attention. Just lmk or change it again if I missed your intent with that change.

Unfortunately I don’t know either…

Thanks for the scope!

how can you automatically detect whether a list is “attached” to the preceding paragraph? So that a single rule could style both lists accordingly

I don’t think it’s possible unless you use a global show rule and iterate over the whole body… You can probably precisely detect sequences of type

#{
([some text], parbreak(), item(...))
}

and then style and reconstruct the list, but you’d have to detect the end of the list…