You can customize the behavior of how hydra displays the section or heading it found by passing a function to its display parameter. It works similar to a show rule, but also receives the internal context object, we’ll ignore this as its not relevant for the question.
Assuming you’re chapters are headings as they usually are you can do it like this:
The first discarded parameter _ is said context object, the second parameter it is the heading that hydra believes to be relevant at the current position.
I’d also like to know if Hydra allows me to determine whether a page is empty. I need this information to hide the header on empty pages.
Not at the moment, but there are other ways to completely ignore the page header, see here and here for some workaround to skip the header there.
Oh that’s on me! I actually made a mistake here, the reason the counter is one page behind is that I forgot to pass the correct location to the counter display. It should be numbering(it.numbering, ..counter(heading).at(it.location())). Indeed this is the counter the default display uses too, I forgot about that . Keep in mind that this assumes all headings are numbered, you may need additional checks if you change the numbering or include other heading ranges.