Hello everyone,
For a personal project where i’m trying to create a sorted outline by alphabetical order i found myself blocked due to my understanding of state that i consider has a global variable.
The current implementation of this ordered outline is :
#let alphabet-displayed = state("alphabet-displayed", ())
#let ordered-outline() = context {
let current-page = here().page()
let headings = query(selector(heading.where(level : 2)))
let sorted-headings = headings.sorted(
key: heading => {if heading.body.has("text") {heading.body.text} else {""}}
)
sorted-headings.map(entry => {
let first-letter = entry.body.text.first()
// reimplement default outline.entry
if entry.numbering != none {
numbering(entry.numbering, ..counter(heading).at(entry.location()))
}
[ ]
/* Focus Here */
if (first-letter not in alphabet-displayed.get()){
text(first-letter) + linebreak()
alphabet-displayed.update(current => current + (first-letter,))
}
h(4pt) + entry.body
box(width: 1fr, repeat[.])
[#entry.location().page()]
}).join([ \ ])
}
== Aaaa
some song
== Abaaa
some song
== B
some song
== C
some song
== D
some song
#pagebreak()
= Index
#ordered-outline()
With result :
I want the letter of each “sub section” of the outline to be shown only one. How can i achieve this result ? In the example give, “A” should only be noted once even thought multiple song begin with A
Thanks in advance for your help.
Edits
EDIT 1 : Reformat code & image for following @Andrew comment.