#Two different values for loc.page() on same page

9 messages · Page 1 of 1 (latest)

indigo cloud
#

I want my L1 headings to be on right pages only and want to insert completely blank pages before them if necessary. (1)
I also have a header and footer that should only be shown on pages that are both

  • not inserted blank pages before a L1 heading
  • pages containig L1 headings (2)

Previously I just had a pagebreak(to: odd) for (1) but this way the header and footer were shown on the inserted page. To solve that problem I'm currently trying to use the solution described here.

For (2) I'm using something like this as my header

set page(header: locate(loc => if not page-is-inserted(loc) {
    // Find next L1 heading
    let next_heading = query(
      selector(heading.where(level:1)).after(loc, inclusive: true),
      loc,
    )

    if next_heading == () {
      return []
    }

    let next_heading = next_heading.first()

    [
      Currently on page #loc.page()
      Next L1 heading is #next_heading.body at page #next_heading.location().page()
    ]
    
    // If next L1 heading is on current page, don't print header
    if next_heading.location().page() == loc.page() {
      return []
    }
    
    // actual header content...

However, the approach linked above interferes with header "logic". During debugging I've found that I get two different values for loc.page() on the same physical page (see image below)

#

The code for my headings looks like this

  show heading.where(
    level: 1
  ): it => locate(loc => [
    #[]<chapter-end-marker> // marker positioned before the pagebreak
    On page #loc.page() before pagebreak 
    #pagebreak(to: "odd", weak: true)
    Currently on page #loc.page() after pagebreak
    // actual heading content
    #[]<chapter-start-marker> // marker positioned after the 
  ])
scenic tinsel
#

not a solution in itself but you know you can insert an empty page([], header: [], footer: []) without calling set page right?

indigo cloud
#

As far as I can tell the issue with my headers is: I query all L1 headings after the current location (which is page 15 in this case), but the loc.page() of my heading is still page 13 (while actually being on page 15 because of the pagebreaks) so it does not get recognized.
Perhaps the image helps understand

indigo cloud
#

I tried using page([], header: [], footer: []) with something like this

if calc.odd(loc.page()) {
  page([], header: [], footer: [])
}

but that did not work since inserting the page changed the loc.page() value, which led to convergance issues, so the compilation never was successful

#

I could not get it to work and decided to look for other solutions - which lead me to the approach above

indigo cloud
#

I've just noticed, that the page number in the outline is also wrong

gray cedar
#

I'm facing this kind of issues with pages when I insert some pagebreak into show rule for heading 😦