I've been using the following line of code to generate a header for my Typst document:
(#counter(heading).at(last-heading.location()).at(0)) #upper[#last-heading.body]
However, it seems like this code is no longer working as expected. I'm wondering if there might be a small bug in my code, or if there have been changes to the location() function.
According to the documentation, it states that location "is only available on content returned by query or provided by a show rule, for other content it will be none."
For context, here's my full code snippet:
let previous-heading = state("page-first-section", [])
set page(
header: locate(
loc => [
#let pageNumber = loc.page()
// find the last heading of level 1 on the current page
#let last-heading = query(
heading.where(level: 1), loc)
.rev()
.find(h => h.location().page() == loc.page())
#{
if calc.even(pageNumber) {
align(left, text(font: "New Computer Modern", size: 12pt, style: "italic")[#previous-heading.display()])
}
if not last-heading == none {
previous-heading.update([
(#counter(heading).at(last-heading.location()).at(0)) #upper[#last-heading.body]
])
}
}
#line(
length: 100%,
stroke: 0.4pt
)
]
)
)