Is it possible to make 'set enum(indent: ...)' work non-recursively?

If using the first-line indent for body text, I prefer lists to be indented at the same degree.

That is, instead of:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.

1. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
   do eiusmod tempor incididunt ut labore et dolore magna aliqua.
2. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
   do eiusmod tempor incididunt ut labore et dolore magna aliqua.
   1. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna.
   2. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna.

…I prefer:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.

   1. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna.
   2. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna.
      1. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
         sed do eiusmod tempor incididunt ut labore et dolore.
      2. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
         sed do eiusmod tempor incididunt ut labore et dolore.

My current workaround it to wrap a list into pad:

#set par(first-line-indent: 1em, justify: true, leading: 1em)
#show par: set block(spacing: 1em)

#lorem(20)

#lorem(20)

#pad(left: 1em, [
  + #lorem(20)
  + #lorem(20)
    + #lorem(20)
    + #lorem(20)
])

Yes, this works, but I would prefer to find a more “native” way to achieve the same output. For this, I tried set enum(indent: 1em):

#set par(first-line-indent: 1em, justify: true, leading: 1em)
#show par: set block(spacing: 1em)
#set enum(indent: 1em)

#lorem(20)

#lorem(20)

+ #lorem(20)
+ #lorem(20)
  + #lorem(20)
  + #lorem(20)

…but then the nested list is indented as well:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.

   1. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna.
   2. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna.
         1. Lorem ipsum dolor sit amet, consectetur adipiscing
            elit, sed do eiusmod tempor incididunt ut labore.
         2. Lorem ipsum dolor sit amet, consectetur adipiscing
            elit, sed do eiusmod tempor incididunt ut labore.

How is it possible to use set enum(indent: 1em), but limit it to the top-level lists only?

Hey @jsx97 , can you please adapt your title to our guidelines for the Questions category? How to post in the Questions category

In particular, your title should be a question you ask to a friend about Typst.

For instance, some variation of the question at the very end of your post would be a great candidate for a title:

Thanks in advance :slight_smile:

1 Like

At the moment there’s no way to revoke rules, which would be a mechanism to make this possible, among other things. This means that the current solution is to manually wrap the top-level enum in a pad(left: 1em) or similar.

Technically another solution would be to have a show rule which inspects the content to wrap the only the top level enums in pad, but you don’t actually get enums, you get enum.items and must also respect the spacing in between them in the top level content sequence.

1 Like

Okay, done. (I simply don’t really see what is good to add “How to…” or “Is it possible to…” to each question on the forum. Isn’t it this simply adds visual noise, and a good title should be concise, not like the original version of the title of Daniel Defoe’s “Robinson Crusoe”? Sorry anyway. :slight_smile:)

Do you know, is it possible to wrap each top-level list or enum into pad automatically?

That’s what I was getting at with the show rule I alluded to. I tried this too, but like I said you don’t really get fully realized enum or list items, but instead individual items separated by spacing, making it harder.

Not sure my English is good enough to understand the first two sentences. So you mean that wrapping top-level lists and enums into pad is not possible yet?

I was referring to this:

which would go kind like this:

#let hack(body) = {
  if body.has("children") {
    // inspect and recreate body.children, wrapping lists and enums in pad
    // ...
  } else {
    body
  }
}


#show: hack

+ Foo
  + Bar

The main issues are that this representation is unstable and edge cases could easily be missed, this may also affect layout in unforeseen ways, like changing the spacing between lists and paragraphs or possibly making it impossible to use tight/non-tight lists or enums.

I haven’t really tried to make it work because I don’t think such a solution will result in better or easier typesetting, feel free to fiddle around yourself though.

1 Like

Ah, now I see, thanks a lot.

Another solution is to use the plain enum (or list) functions.

#set par(first-line-indent: 1em, justify: true, leading: 1em)
#show par: set block(spacing: 1em)

#lorem(25)

#lorem(25)

#enum(
  numbering: "1.a)", indent: 1em,
  enum.item[Lorem ipsum dolor sit amet.],
  enum.item([Lorem ipsum dolor sit amet.] + enum(
    numbering: "1.a)",
    enum.item[Lorem ipsum dolor sit amet.],
    enum.item[Lorem ipsum dolor sit amet.]
  ))
)
1 Like

A maybe not-so-hacky solution:

#set enum(indent: 1em)
#show enum: it => {
  set enum(indent: 0em)
  it
}

For top-level lists, the set enum(indent: 0em) comes too late so the 1em is in effect. For inner lists the 0em is applied repeatedly at each level but that doesn’t hurt.

3 Likes

@sijo Works great (are there any pitfalls?), thank you very much.

You’re welcome! I can’t think of any pitfall…

1 Like

Honestly, I thought this wouldn’t work for whatever reason.

This should probably be marked as the correct solution.

It’s worth clarifying that this is new behavior introduced in Typst 0.11: #show enum: set enum will affect even top-level enums, but #show enum: it => set enum(...); it will only affected nested enums. (Same applies to any other elements, not just enums.)

3 Likes

Personally, I think the title is much clearer now, and I can tell what you were asking at a glance, without opening your post. I’d say this goes to show the value of this policy. :slight_smile:

It’s fine, don’t worry! We’re all constantly adapting and learning. :slight_smile:

1 Like