Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
LilyPond wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Alphabetically sorted index
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Sometimes you may want to get a sorted index of the pieces contained in a book. Often the <code>\table-of-content</code> command does this job quite well. However, the problem with it is that it always sorts 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. It takes the code of LilyPond's <code>ly/toc-init.ly</code> file and defines three new commands <code>\indexItem</code>, <code>\indexSection</code>, and <code>\index</code>. The first two are used to define index items, the last one will create the output. <code>\indexItem</code> and <code>\indexSection</code> 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. <pre> \markuplist \index \indexItem #"Berta" \markup "Berta" \indexItem #"Clown" \markup "Clown" \indexItem #"Adam" \markup "Adam"</pre> By setting the first argument of <code>\indexItem</code> and <code>\indexSection</code> to a different value than the second it is possible to create heavily customized sorted indices. For example, a topic-based index can be achieved by <pre> \markuplist \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"</pre> '''Limitations:''' It is not yet possible to create multiple indices, for example, an alphabetically sorted ''and'' a topic-based one. To achieve that a few additions to the snippet would be necessary, which I had not yet time to implement. <lilypond version="2.24.0" full> %% http://lsr.di.unimi.it/LSR/Item?id=763 % Usage: % - define and index item with \indexItem $sortstring $markup % - use \indexSection $sortstring $markup to divide the index into several sections % - display the alphabetical index with \markuplist \index % code ist mostly taken from ./ly/toc-init.ly and just renamed and slightly modfied %here starts the snippet: %% defined later, in a closure #(define-public (add-index-item! markup-symbol text sorttext) #f) #(define-public (index-items) #f) #(let ((index-item-list (list))) (set! add-index-item! (lambda (markup-symbol text sorttext) (let ((label (gensym "index"))) (set! index-item-list ;; We insert index items sorted from the beginning on and do ;; not sort them later - this saves pretty much computing time (insert-alphabetical-sorted! (list label markup-symbol text sorttext) index-item-list)) (make-music 'EventChord 'page-marker #t 'page-label label 'elements (list (make-music 'LabelEvent 'page-label label)))))) (set! index-items (lambda () index-item-list))) #(define (insert-alphabetical-sorted! iitem ilist) (if (null? ilist) (list iitem) (if (string-ci<? (cadddr iitem) (cadddr (car ilist))) (cons iitem ilist) (cons (car ilist) (insert-alphabetical-sorted! iitem (cdr ilist))) ) ) ) \header { tagline = ##f } \paper { indexTitleMarkup = \markup \column { \fontsize #5 \sans \bold \fill-line { \null "Alphabetical Index" \null } \hspace #1 } indexItemMarkup = \markup \large \fill-line { \fromproperty #'index:text \fromproperty #'index:page } indexSectionMarkup = \markup \column { \hspace #1 \fill-line { \sans \bold \fontsize #3 \fromproperty #'index:text } \hspace #1 } } #(define-markup-list-command (index layout props) () ( _i "Outputs an alphabetical sorted index, using the paper variable @code{indexTitleMarkup} for its title, then the list of lines built using the @code{indexItem} music function Usage: @code{\\markuplist \\index}" ) (cons (interpret-markup layout props (ly:output-def-lookup layout 'indexTitleMarkup)) (space-lines (chain-assoc-get 'baseline-skip props) (map (lambda (index-item) (let ((label (car index-item)) (index-markup (cadr index-item)) (text (caddr index-item))) (interpret-markup layout (cons (list (cons 'index:page (markup #:page-ref label "XXX" "?")) (cons 'index:text text)) props) (ly:output-def-lookup layout index-markup)))) (index-items))))) indexItem = #(define-music-function (sorttext text) (string? markup?) "Add a line to the alphabetical index, using the @code{indexItemMarkup} paper variable markup." (add-index-item! 'indexItemMarkup text sorttext)) indexSection = #(define-music-function (sorttext text) (string? markup?) "Add a section line to the alphabetical index, using @code{indexSectionMarkup} paper variable markup. This can be used to divide the alphabetical index into different sections, for example one section for each first letter." (add-index-item! 'indexSectionMarkup text sorttext)) % --------------------------------------------------------------- % Example \markuplist \index \indexSection #"B" \markup { "B" } \indexSection #"K" \markup { "K" } \indexSection #"Z" \markup { "Z" } \score { \relative c' { \repeat unfold 10 { c d e f } \indexItem #"Karola" \markup{ "Karola" } \repeat unfold 10 { c d e f } \bar "|." } \header { piece = "first piece" } } \score { << \new Staff \new Voice = "voc" { \relative c' { \indexItem #"Zora" \markup { \italic "Zora" } \repeat unfold 10 { c d e f } \indexItem #"Bettina" \markup { \larger "Bettina" } \indexItem #"Barbara" \markup { \smallCaps "Barbara" } \repeat unfold 10 { c d e f } \bar "|." } } \new Lyrics \lyricsto "voc" { \repeat unfold 10 { la la la la } \repeat unfold 10 { mi mi mi mi } } >> \header { piece = "second piece" } } </lilypond> [[Category:Text]] [[Category:Titles]] [[Category:Paper and layout]] [[Category:Editorial annotations]]
Summary:
Please note that all contributions to LilyPond wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Meta:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Alphabetically sorted index
Add topic