\version "2.22.0" % % dual-index.ily % % lilypond include file for dual index creation % unsorted and sorted index functions % (from snippet, modified to add exercise number and unsorted index) % (also added automatic insertion of alpha index section headers) #(define-public (add-index-item! markup-symbol text sorttext exno) #f) #(define-public (alphasorted) #f) #(define-public (unsorted) #f) #(let ((index-item-list (list)) (ex-item-list (list))) (set! add-index-item! (lambda (markup-symbol text sorttext exno) (let ((label (gensym "index")) (alttext (alt-name sorttext))) ; add item to unsorted list (set! ex-item-list (cons (list label markup-symbol text sorttext exno) ex-item-list)) ; add item to sorted list based on sorttext (Attribution: Title) (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 (if (string-null? sorttext) index-item-list (insert-alphabetical-sorted! (list label markup-symbol text sorttext exno) index-item-list) )) ; add modified item to sorted list based on alttext (Title #Attribution) (set! index-item-list (if (string-null? alttext) index-item-list (insert-alphabetical-sorted! (list label markup-symbol alttext alttext exno) index-item-list) )) (make-music 'EventChord 'page-marker #t 'page-label label 'elements (list (make-music 'LabelEvent 'page-label label)))))) (set! unsorted (lambda () (reverse ex-item-list))) (set! alphasorted (lambda () (insert-alpha-hdrs! "\n" index-item-list)))) #(define (insert-alphabetical-sorted! iitem ilist) (if (null? ilist) (list iitem) (if (string-cilist str) 0) )) (if (> nth -1) (let ((att (substring str 0 nth)) (ttl (substring str (+ 2 nth) (string-length str) ))) (string-append ttl " #" att) ) "" ) ) ) % index command % modified to work on either sorted and unsorted indices (via arg "items") #(define-markup-list-command (index layout props items) (procedure?) (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)) (exnum (car (cdr (cdr (cdr (cdr index-item))))))) (interpret-markup layout (cons (list (cons 'index:page (if (ly:stencil? label) (markup #:stencil label) (markup #:page-ref label "XXX" "?"))) (cons 'index:text text) (cons 'index:exnum (number->string exnum))) props) (ly:output-def-lookup layout index-markup)))) (items)))) % save-page-refs command #(define-markup-command (save-page-refs layout props items tag) (procedure? string?) (for-each (lambda (index-item) (let ((lbl (car index-item))) (if (not (ly:stencil? lbl)) (set-car! index-item (interpret-markup layout props (markup #:abs-fontsize 12 #:page-ref lbl "XXX" tag))) ))) (items))) indexTitle = #(define-scheme-function (str) (string?) #{\markup \column { \fontsize #4 \bold \fill-line { \null #str \null } \hspace #1 } #}) indexItem = #(define-music-function (sorttext text exnum) (string? markup? number?) "Add a line to the alphabetical index, using the @code{indexItemMarkup} paper variable markup." (add-index-item! 'indexItemMarkup text sorttext exnum)) indexSection = #(define-music-function (text) (markup?) "Add a section line to the unsorted index, using @code{indexSectionMarkup} paper variable markup." (add-index-item! 'indexSectionMarkup text "" 0)) %{ convert-ly (GNU LilyPond) 2.22.1 convert-ly: Processing `'... Applying conversion: 2.19.2, 2.19.7, 2.19.11, 2.19.16, 2.19.22, 2.19.24, 2.19.28, 2.19.29, 2.19.32, 2.19.39, 2.19.40, 2.19.46, 2.19.49, 2.20.0, 2.21.0, 2.21.2, 2.22.0 %}