How to merge two hydra's scripts? Truncate headers

Recently, I ask for achieve a custom header and number footer configuration for my document. Here the post. Answers suggest I use hydra package. But now, I want truncate the title that appears in the header, searching in this forum I found a solution with hydra, that solution is simple but I can’t merge it with the past script so I need to merge these scripts for achieve my objectives.

  1. First script (thanks @flokl):
#import "@preview/hydra:0.6.2": *

#set page(
  header: context {
    let page-num = counter(page).get().first()
    if page-num != 1 {
      if calc.even(page-num) {
        set align(left)
        counter(page).display("1")
        h(1cm)
        [Author Name]
      } else {
        set align(right)
        hydra(1) // heading lvl 1
        h(1cm)
        counter(page).display("1")
      }
    }
  },
  footer: context {
    let page-num = counter(page).get().first()
    if page-num == 1 {
      set align(center)
      counter(page).display("[1]")
    }
  }
)
  1. Second script (Again, thanks @flokl ):

#import "@preview/hydra:0.5.1": hydra, selectors
#import selectors: custom

#let chapter(long, short) = {
  [#metadata(short)<short>]
  heading(long)
}

#set page(
  header: context hydra(
    skip-starting: false,
    custom(<short>),
    display: (_, elem) => {
      elem.value
    }
  )
)

#chapter[Long title 1][Short 1]
#lorem(2000)

#chapter[Long title 2][Short 2]
#lorem(2000)

#chapter[Long title 3][Short 3]
#lorem(2000)

Well, now I have to answer :). If you replace hydra(1) in the set page call of the first script with the custom hydra call from the second it should work.

#import "@preview/hydra:0.6.2": hydra, selectors
#import selectors: custom


#let chapter(long, short) = {
  [#metadata(short)<short>]
  heading(long)
}

#set page(
  header: context {
    let page-num = counter(page).get().first()
    if page-num != 1 {
      if calc.even(page-num) {
        set align(left)
        counter(page).display("1")
        h(1cm)
        [Author Name]
      } else {
        set align(right)
        // new
        hydra(
          skip-starting: false,
          custom(<short>),
          display: (_, elem) => {
            elem.value
          }
        )
        //hydra(1) // heading lvl 1
        h(1cm)
        counter(page).display("1")
      }
    }
  },
  footer: context {
    let page-num = counter(page).get().first()
    if page-num == 1 {
      set align(center)
      counter(page).display("[1]")
    }
  }
)

#chapter[Long title 1][Short 1]
#lorem(2000)

#lorem(2000)

#chapter[Long title 2][Short 2]
#lorem(2000)

#chapter[Long title 3][Short 3]
#lorem(2000)
1 Like

@flokl, You rock! Thank you very much… and this forum is an island of wisdom.