I have a function to create chapters, which I call once for each chapter file.
I'm adding a label to the chapter headers in order to query for them.
#let Chapter(title) = {
set text(size: 24pt)
pagebreak(weak: true)
stack(
v(5mm),
heading(level:1)[#title #label("chapter-heading")], // Notice label
line(length: 100%, stroke: 2pt + luma(50%)),
v(5mm)
)
}
I now wanted to query the labels, in order to show the current chapter name in the header. For testing, I started returning all the chapters.
#let GetChapterName() = {
return query(selector(<chapter-heading>))
}
That GetChapterName() function gets called from set page to style the header.
// Style the header
#set page(
header: context {
let display = IsShowHeader()
if display {
block(
width: 100%,
inset: 5.5pt,
fill: luma(15%)
)[
#grid(
columns: (2fr, 1fr, 2fr),
rows: 1,
align: (left, center, right),
[ax], [#here().position()], [#GetChapterName()] // This displays the header.
)
]
}
}
)
For some reason, the list returned by GetChapterName() function has duplicate chapter names (see attached image).
Why the duplicates?