How to continue `enum` throughout entire document?

How can I continue numbering throughout an entire document when using the + bullets? E.g.:

+ item 1

some comments

+ item 2

some comments

+ item 3

some comments

As it is now, numbering restarts each time the + are broken up by other lines.

Of course, I can explicitly number each item, but would love if I could use + throughout the document and it keep track of the numbers. I’m guessing there’s a way to do it with counters, but don’t know how. I’ll take a swing at it and post a solution if I can find one, but am posting here first since I imagine this would be generally helpful and want to contribute to the forum.

Edit: I should have been more clear, I understand that indentation can avoid this issue, but I would love to be able to separate some enums by headers, and be able to style enums separately from the content that follows. For example:

#show enum: (it) => text(gray, it)
= Section 1

+ This is question 1

this is my answer to question 1

+ This is question 2

this is my answer to question 2

+ This is question 3

this is my answer to question 3

= Section 2

+ This is question 4

this is my answer to question 4

Hi @miles-1. Actually to avoid enum breaking, you have to respect indentation. Normally, the following lines should work:

+ item 1
  
  some comments

+ item 2

  some comments

+ item 3

  some comments

Another possibility consists in writing :

+ item 1
  
  some comments

+ item 2

some comments

3. item 3

  some comments

+ item 4
   
  some comments 

Sorry, I should have been more clear why indentation is not the solution I’m looking for, I edited my question. Also, I am aware that numbering can be explicitly stated and it will continue from there, but that “hard coding” makes it difficult to rearrange questions without needing to manually count out enums from scratch.

Ok :slight_smile:. For this kind of things, I’ve created a counter and a function. Here is the code :

#let c = counter("question")
#let question(body) = [
  #c.step()
  #context[
    *Question #c.get().first() #h(0.5em)*
  ]
  #body
]

I prefer to avoid modifying the enum function, because I sometimes need enumeration inside a question.

1 Like

Another approach to this if your sections are not numbered could be to use headings instead:

#show heading.where(level: 2): set text(gray, 1em / 1.2, weight: "regular")
// oops, this will make question 4 to be numbered question 1 again!
// #show heading.where(level: 1): set heading(numbering: "1.")
#show heading.where(level: 2): set heading(numbering: (_, ..nums) => numbering("1.", ..nums))
= Section 1

== This is question 1

this is my answer to question 1

== This is question 2

this is my answer to question 2

== This is question 3

this is my answer to question 3

= Section 2

== This is question 4

this is my answer to question 4
1 Like

Hi @miles-1 ,

while @maucejo solution is very good and suitable for most cases, I want to point out that this is actually possible to configure with a simple show rule if you want to keep using the enum syntax and don’t care for nested enumerations.

#let item-counter = counter("item-counter")
#set enum(start: 0)

#show enum: it => {
  if it.start != 0 { return it }
  let args = it.fields()
  let items = args.remove("children")
  context enum(..args, start: item-counter.get().first() + 1, ..items)
  item-counter.update(i => i + it.children.len())
}

What this does is to create a counter that keeps track of the number of already processed items and set the start parameter of the enumeration according to that counter. The line #set enum(start: 0) is a trick to prevent the show rule being called recursively.

Now this:

  + Item
  + Item

  Some text in between
  
  + Item
  + Item
  
  Some more text in between
  
  + Item
  + Item

will produce the following output:
image

2 Likes

A nested version of this is also discussed in Resuming Nested Numbered Lists