Why does `pagebreak(weak: true)` result in a empty page when wrapped in a `#page[]`?

I’m a bit confused about the behaviour of pagebreak(weak: true). The docs say, that weak: true only inserts a page break if the current page is not empty.
But if I put a pagebreak(weak: true) into a new #page[] the page break is actually inserted, even though the page is completely empty.

#page[
  #pagebreak(weak: true)
  Page page
]

So either I don’t really understand what weak: true or #page[] do, or it’s a bug.
Does someone know why this is happening?

Also as a side note on why I came across this issue:

I am trying to make a template which has specific pages at the beginning (title page, copyright page, declaration, …) and I started wrapping them in a #page[] each to make sure they are each on a separate page, but because some of them contain level 1 headings, which should also always start on their own page (have show heading.where(level: 1): it => { pagebreak(weak: true) it } set) they created empty pages.

1 Like

I can explain the phenomenon. According to the source code, the page function is roughly equivalent to this:

#let page(body) = {
  pagebreak(weak: true)
  place.flush()
  body
  pagebreak(weak: true)
}

As a result, #page[#pagebreak(weak: true); Page page] becomes:

#pagebreak(weak: true)
#place.flush()
#pagebreak(weak: true)
Page page
#pagebreak(weak: true)

So there’re two pages.

See also Why does pagebreak(weak: true) result in a empty page when wrapped in a #page{}? … - Search | DeepWiki

This might be a bug, but I’m not sure…

2 Likes

#6129 seems to be the relevant issue

3 Likes

Yep, thanks. Seems like I’ll just have to not use #page for now.

Hi @Gaweringo, don’t forget to tick :ballot_box_with_check: one of the responses if you got a satisfying answer. The answer you choose should usually be the response that you found most correct/helpful/comprehensive for the question you asked. Thanks!