How to disable undefined behavior in `outline` title ? (`heading(level: 1)`)

i have a custom style for level one headings

#show heading: it => {
  if it.level == 1 {
    pagebreak()
    v(20em)
    align(center)[
      #block(width: 70%,text(weight: 900, 2em, smallcaps(it)))
    ]
    pagebreak()
  } 
}

the outline title is adopting this behavior by default. it will pagebreak before and after the title, so the entries will be in the next page. how to disable this? and is this intended behavior ?

Hi, you can probably find a solution in How to create a pagebreak before every depth 1 heading except for the outline? (though with level instead of depth).

Some notes for your specific case:

  • When including the if it.level == 1 in the body of the show rule, any heading with a higher level will not be shown at all, as the show rule returns none for them. You should instead use a where-selector as in

    #show heading.where(level: 1): it => ...
    
  • A normal pagebreak may create an unwanted empty page when the previous page is already empty. You maybe want to set the weak parameter to prevent that.

Thanks this solution worked.

#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
}

Although I think the outline title should not adopt behavior from the level one heading. as for your suggestion of using the where selector (which I’m thankful for), I have 6 levels of headings defined and default behavior for anything above that in my template, and the normal function seems to work best for me in such a case.