Marmare314 / lemmify

A library for typesetting mathematical theorems in typst.
GNU General Public License v3.0
11 stars 7 forks source link

Show rules are messing up with outline entries #19

Open gzagatti opened 6 months ago

gzagatti commented 6 months ago

In the example below, I add a page break after H1. Normally, Typst will display the page after the break in the outline.

But when I insert thm-rules show rule after the heading show rule, the outline entry does not behave as expected anymore. The outline shows the page entry before the break.

#import "@preview/lemmify:0.1.5": *

#let (
  theorem, lemma, corollary,
  remark, proposition, example,
  proof, rules: thm-rules
) = default-theorems("thm-group", lang: "en")

#outline(target: heading.where(outlined: true))

#show heading: it => {
  if it.level == 1{
  pagebreak(weak: false)
    it
  } else if it.level == 2 {
    it
  } else {
    it
  }
}

#show: thm-rules

#[= Foo]

#[= Bar]

Hello!

If I reverse the order and call the show rule for thm-rule before heading, the problem goes away. I find this behavior very odd. My assumption is that lemmify shouldn't be messing up with headings in its show rule. Any idea of what's going on here?

Marmare314 commented 4 months ago

I finally figured out what part of the code is causing this. It is the thm-reset-counter-heading-at function, specifically

show heading.where(level: level): it => {
  thm-reset-counter(group)
  it
}

Reversing the order of thm-reset-counter(group) and it seems to fix the issue. But I'm still not sure why this is causing the outline page number to be decreased.