Skip to content

Problems with header when no 2nd level heading has been introduced #41

@faultdiagnosistoolbox

Description

@faultdiagnosistoolbox

Hi,

I'm designing a template and I use hydra for the headers. The principles I wanted are
odd pages: Level 1 heading title + page number except for the page where the heading is defined
even pages: Level 2 heading title + page number if one is defined, otherwise only page number.

Unfortunately, I can't make it work and I am wondering if I'm using hydra incorrectly. A minimum working example is shown below. Initially, it produces what I want, however if you move the subsection to the indicated place, you see the problem on page 2.

I have commented out my first attempted solution, if you uncomment that you'll see a double header on page 4.

Any help resolving this would be appreciated.
Erik

#import "@preview/hydra:0.6.1": hydra
#set heading(numbering: "1.")
#set page(numbering: "1")

#set page(header: context [
  #if calc.odd(counter(page).get().first()) {
    hydra(1, skip-starting: true, display: (_, it) => {
      if it.numbering != none {
        block({
          [#numbering(it.numbering, ..counter(heading).at(it.location()))]
          h(0.6em)
          text(size: 9pt, it.body)
          h(1fr)
          text(size: 9pt, counter(page).display())
          v(-3mm)
          line(length: 100%, stroke: 0.3pt)
        })
      }
    })
  } else {
    hydra(2, skip-starting: false, display: (_, it) => {
      block({
        text(size: 9pt, counter(page).display())
        h(1fr)
        text(size: 9pt, [#numbering(it.numbering, ..counter(heading).at(it.location()))])
        h(0.6em)
        text(size: 9pt, it.body)
        v(-3mm)
        line(length: 100%, stroke: 0.3pt)
      })
    })
    // if counter(heading).get().len() < 2 {
    //   // No second level subsection just yet
    //   block({
    //     text(size: 9pt, counter(page).display())
    //     v(-3mm)
    //     line(length: 100%, stroke: 0.3pt)
    //   })
    // }
  }
])

= Section
#lorem(250)

#lorem(250)

// Subsection here is OK
== Subsection

#lorem(250)

#lorem(250)

#lorem(250)

#lorem(250)

#lorem(250)

#lorem(250)

// Move subsection here to illustrate the problem

#lorem(250)

#lorem(250)

#lorem(250)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions