I want to display the nearest level 1 heading on the left side of the header and the nearest level 2 heading on the right side of the header. However, why can’t the level 2 heading show the chapter number 2.1? Here is my code.
header:context {
let headings = query(heading)
let head1 = headings.filter(h => h.level == 1 and h.location().page() <= here().page())
let h1=none
if head1.len() != 0{
h1 = head1.last()
}
let head2 = headings.filter(h => h.level == 2 and h.location().page() <= here().page())
let h2 = none
if head2.len() != 0 {
h2 = head2.last()
}
if h1 != none or h2 != none {
let h1number = ""
if h1 != none{
h1number = str(counter("chapter").at(h1.location()).first()-1)
h2number}
// this is error code,it doesn't get the level2 number
let h2number = ""
if h2 != none{
h2number = str(counter(heading).at(h2.location()).first()) //don't get the level 2 number
}
grid(
columns: (1fr, 1fr),
align(left, text(size: 9pt, if h1 != none { h1number + h1.body } else { none })),
align(right, text(size: 9pt, if h2 != none { h2number + h2.body } else { none }))
)
line(length: 100%, stroke: 0.5pt + rgb("#CCCCCC"))
v(1pt)
}
},