From a61becaf5e426945dba6956b1058f126220c4339 Mon Sep 17 00:00:00 2001 From: "zuk (Jakob Krueger)" Date: Mon, 3 Mar 2025 16:57:05 +0400 Subject: [PATCH] Support multiple alternative titles in headerToTOC function This update allows the alttitle header field to accept a list of alternative titles instead of a single value. Each title in the list is processed and added to the table of contents as an alternative title, enhancing flexibility and usability. --- toc_include.ly | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/toc_include.ly b/toc_include.ly index 7eb9a09..b3c6f39 100644 --- a/toc_include.ly +++ b/toc_include.ly @@ -286,11 +286,10 @@ headerToTOC = #(define-music-function (parser location header label) (ly:book? s )) (let* ( - (extractedheadervars (extract-and-check-vars-from-header header '(title starttext alttitle altalttitle categorytitle categories authors))) + (extractedheadervars (extract-and-check-vars-from-header header '(title starttext alttitle categorytitle categories authors))) (title (assq-ref extractedheadervars 'title)) (starttext (assq-ref extractedheadervars 'starttext)) (alttitle (assq-ref extractedheadervars 'alttitle)) - (altalttitle (assq-ref extractedheadervars 'altalttitle)) (categorytitle (assq-ref extractedheadervars 'categorytitle)) (categories (assq-ref extractedheadervars 'categories)) (authors (assq-ref extractedheadervars 'authors)) @@ -300,8 +299,12 @@ headerToTOC = #(define-music-function (parser location header label) (ly:book? s (if categories (add-category-index-item! (string-tokenize categories) 'indexItemMarkup (cons (list (cons 'rawtext (if categorytitle categorytitle title))) '()) label)) (if authors (add-author-index-item! (all-author-ids authors) 'indexItemMarkup (cons (list (cons 'rawtext (if categorytitle categorytitle title))) '()) label)) (if starttext (add-to-toc! starttext (cons (list (cons 'rawtext starttext) (cons 'alternative #t)) '()))) - (if alttitle (add-to-toc! alttitle (cons (list (cons 'rawtext alttitle) (cons 'alternative #t)) '()))) - (if altalttitle (add-to-toc! altalttitle (cons (list (cons 'rawtext altalttitle) (cons 'alternative #t)) '()))) + (if alttitle + (if (list? alttitle) + (for-each (lambda (alt) + (add-to-toc! alt (cons (list (cons 'rawtext alt) (cons 'alternative #t)) '()))) + alttitle) + (add-to-toc! alttitle (cons (list (cons 'rawtext alttitle) (cons 'alternative #t)) '())))) (if title (add-to-toc! title (cons (list (cons 'rawtext title)) '())) #{ #}) ))