Pagebreaks not allowed in containers - error on some input but not others

I encounter the error pagebreaks are not allowed inside of containers in a show heading function, which runs on several other documents without problems. The function is:

show heading.where(level: 2): it => {
    marginalia.notecounter.update(0)
    pagebreak(to: "odd", weak: true)
    hide(it)
    let nums = counter(heading).get()
    let n2 = if nums.len() >= 2 {
        str(nums.at(1))
      } // else { "??" }
      v(30mm)
      align(right)[
        #text(size: numbersize2, font: titlefont, fill: gray)[ #n2 ]
        #v(0.5em)
        #text(size: titlesize2, weight: 300, font: titlefont)[#it.body ]
              // #counter(heading).at(here()).at(1)  //error here with  vorwort as 0,1 
        #v(20mm)
    ]
  }  

what can I change to make it run consistently?

I use typst --version
typst 0.15.0 (3ae52774)
on a debian 13 system.

Generally, when I have this error, you have to use colbreak instead of pagebreak.

My issue here is primarily that code which works for a while and for different inputs stops working - without a hint to what the problem is, which send the user to the well-known and hated method of trying to find the problem (very typical of using latex!).
I found the cause: the line

  - == Eigentum und Besitz von beweglichen Sachen
    Menschen konnten sich bewegliche Sachen aneignen, in Besitz nehmen. Wichtig wohl fĂĽr Steine als Waffen, gejagte Tiere.

specifically the “- == …” combination, which is non-sense and should be flagged by the compiler.

One person’s non-sense is another person’s feature… I have used headings inside of containers several times (for example for two-column layout on a slide). I don’t remember using headings as list items but this person and this one apparently found it useful. I don’t think Typst should restrict combinations of features (like list item and heading) without a good reason.

The error can probably be improved but “pagebreak in container” is already a useful hint, and the compiler also gives the line number of the offending source line.

1 Like