How to create a pagebreak before every depth 1 heading except for the outline?

Say I have something like

// some show rule here
stuff here
#outline()
more stuff
= My first heading

What show rule can help me add a #pagebreak(weak: true) before things like “My first heading” but not the outline?

Currently I have something like

#show heading.where(depth: 1): body => {    
  pagebreak(weak: true)
  body
}

but this also seems to put a pagebreak before the outline.

Would it be an option to just put the show rule after the outline?

stuff here
#outline()
more stuff

#show heading.where(depth: 1): ...

= My first heading

If this is not possible (maybe because you’re editing a template), you could use a state to store whether you are currently in the outline, and use that to determine whether you want to insert a page break:

#show outline: it => {
  state("in-outline").update(true)
  it
  state("in-outline").update(false)
}

#show heading.where(depth: 1): it => {
  if not state("in-outline", false).get() {
    pagebreak(weak: true)
  }
  it
}
2 Likes

Although @Eric’s answer is more targeted, maybe the following works for you:

#show heading.where(depth: 1, outlined: true): ...

Since the outline itself isn’t outlined, it will not be affected. Of course, this is only an option if a) you have no other non-outlined level 1 headings or b) this is actually closer to what you want. If it’s only a), I would probably still prefer Eric’s solution.

2 Likes

This suggests the following slightly hacky solution :slight_smile:

#show outline: set heading(supplement: [Outline])
#show heading.where(depth: 1): it => {
  if it.supplement != [Outline] {
    pagebreak(weak: true)
  }
  it
}
2 Likes

Thank you all for the help!

1 Like