How can I automate level 1 headings always occur on a new recto page?

I have the following code for heading 1:

#show heading.where(
  level: 1
): it => block(sticky: true, width: 100%)[
  #set align(center)
  #set text(24pt, weight: "regular")
  #smallcaps(it.body)
]

I want these to begin a recto page (think Chapter start), so at the moment, I include the line:

#pagebreak(weak: true, to: "odd")

before each = Heading text within the text itself.

Is it possible, and if so how, to modify the #show rule to incorporate the new page command immediately before the heading, so as to obviate the need of repeating it throughout the document?

Many thanks.

:slight_smile:
Mark

Don’t use show rules unless you have to, especially if you put set rules inside. You will face Which show rule takes precedence? or Set rule inside show rule (closure) for the same element gets applied for table/grid · Issue #6219 · typst/typst · GitHub.

Prioritize show-set rules and keep show rules minimal/non-hacky:

#show heading.where(level: 1): set align(center)
#show heading.where(level: 1): set text(24pt, weight: "regular")
#show heading.where(level: 1): smallcaps
#show heading.where(level: 1): it => pagebreak(weak: true, to: "odd") + it

= Chapter A
#lorem(50)

= Chapter B
#lorem(50)

This is the most idiomatic way, but since show rules are used, you won’t be able to un-smallcaps or un-pagebreak level 1 heading, unless this is set inside a non-root scope. But at least all other heading features/behavior will work.

Thank you. That does just what I want.

As for my code, that was based on the example given in the ‘Advanced Styling’ section of the Tutorial—with input from @PgBiel in answer to a related question! I guess one of the problems with Typst being still very much in development is that the Tutorial doesn’t get updated to match so quickly.

:slight_smile:
Mark

1 Like

Thank you for context, I’ll look into it.

Hi @Mark_Hilton, glad you got a satisfying answer! Please don’t forget to mark it as the solution, so that others can more easily find it later.