Sometimes you may want to get an sorted index of the pieces contained in a book. Often the
\table-of-content command does this job quite well.
However, the problem with it is, that it sorts always by page numbers. For books containing many songs it is common to have an index sorted by letters or topics.
Both is possible with this snippet. Its code takes the code of ./ly/toc-init.ly and defines three new commands
\index. The first two are used to define index items, the last one will create the output.
\indexSection both take two arguments (string, markup). The first is used to calculate the order of the items in the output, the second one contains the markup that is actually printed.
\markuplines \index \indexItem #"Berta" \markup "Berta" \indexItem #"Clown" \markup "Clown" \indexItem #"Adam" \markup "Adam"
By setting the first argument of
\indexSection to a different value than the second it is possible to create heavily customized sorted indices. A topic based index can be achieved by:
\markuplines \index \indexSection #"spring" \markup \smallCaps "Songs of Spring" \indexItem #"spring - I Like the Flowers" \markup "I Like the Flowers" \indexItem #"spring - Der Winter ist vergangen" \markup "Der Winter ist vergangen" \indexSection #"rock" \markup \smallCaps "Rock Songs" \indexItem #"rock - Stairway to Heaven" \markup "Stairway to heaven" \indexItem #"rock - Nothing Else Matters" \markup "Nothing Else Matters"
It is not yet possible to create multiple indices, for example an alphabetical sorted and a topic based one.
To achieve that a few additions to the snippet are nessecary which I had not yet time to implement by now.