#Check if page contains heading level 1

13 messages · Page 1 of 1 (latest)

grand smelt
#

Hi, I have these header components that show which heading the reader is currently inside of. However on a page like this where a chapter starts, I don't want them as it clashes with the design. Is it possible to check if the page contains a heading level 1? The second pic shows an instance where I do want it.

I am using @short solar's package hydra for the header elements https://github.com/tingerrr/hydra/tree/main

GitHub

A typst package for displaying the active section in the page header or footer. - tingerrr/hydra

#

I figure that the skip-starting argument is for this purpose, however that doesn't help me from displaying other elements such as the line

#
#set page(
  header: context {
    let cm = (accent, theme.text.lighten(50%))
    align(
      if calc.odd(here().page()) {
        // set align(right)
        cm = cm.rev()
        right
      } else {
        // set align(left)
        left
      },
      {
        let h = {
          set text(accent)
          set text(gradient.linear(..cm))
          hydra(1, skip-starting: false)
          h(0.5em)
          // sym.bar.v
          sym.bar.h
          // sym.dash.en
          h(0.5em)
          hydra(2, skip-starting: false)
        }

        h
        hline-with-gradient(cmap: cm, height: 1pt)
      }
    )

  }
)
short solar
#

skip-starting is true by default and should work in your case, can i see your heading show rule?

grand smelt
#

Here are my heading show rules

#show heading.where(numbering: "1.1") : it => [
  #v(1em)
  #block({
    box(width: 18mm, text(counter(heading).display(), weight: 600))
    text(it.body, weight: 600)
  })
  #v(1em)
]

#show heading.where(level: 1) : it => text(
  accent,
  size: 18pt,
)[
  #pagebreak(weak: true)
  #let subdued = theme.text.lighten(50%)
  #set text(font: "JetBrainsMono NF")

  #grid(
    columns: (1fr, 1fr),
    align: (left + bottom, right + top),
    text(it.body, size: 24pt, weight: "bold"),
    if it.numbering != none {
      text(subdued, weight: 200, size: 100pt)[#counter(heading).get().at(0)]
      v(1.5em)
    },
  )
  #v(-0.5em)
  // #hr
  #hline-with-gradient(cmap: (accent, subdued), height: 2pt)
  #v(1.5em)
]

#show heading.where(level: 4) : it => text(
  black,
  size: 14pt,
)[
  #v(0.25em)
  #block({
    box(width: 18mm, text(counter(heading).display(), weight: 600))
    text(it.body, weight: 600)
  })
  #v(0.15em)
]
#

skip-starting does correctly work with hydra of course, however, I need to also now show my other visual elements

#

That pic is with skip-starting=true

short solar
#

you can fix this by putting some empty content like #metadata(()) before your spacing

#

however not before the pagebreak, otherwise your outline numbers will be wrong

eager hare
#

?r theme=light

#import "@preview/hydra:0.4.0": hydra

#set page(
  margin: (top: 10mm, right: 10mm, bottom: 10mm, left: 10mm),
  header: context {
    if hydra(1) == none {
      [Level 1 heading on this page]
    } else {
      [#counter(page).get().first()]
    }
  },
);
#set heading(numbering: "1.1");

= #lorem(3)
#lorem(3);
#pagebreak();
#lorem(3);
#pagebreak();
#lorem(3)