From 76b81a99688031a25bec9a92717d12d68e77d38a Mon Sep 17 00:00:00 2001 From: Christoph Wagner Date: Mon, 24 Nov 2025 09:51:33 +0100 Subject: [PATCH] no breaks in toc after section title --- private_includes/book/toc_include.ily | 45 ++++++++++++++++----------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/private_includes/book/toc_include.ily b/private_includes/book/toc_include.ily index b872527..ce8d882 100644 --- a/private_includes/book/toc_include.ily +++ b/private_includes/book/toc_include.ily @@ -90,7 +90,7 @@ (for-each (lambda (category) (let* ((catsym (string->symbol category)) (catlist (hashq-ref category-index-hash catsym - (list (list label 'indexCategoryMarkup `(((rawtext . ,category)))))))) + (list (list label 'indexCategoryMarkup `(((combine-with-next . #t) (rawtext . ,category)))))))) (if (assq catsym category-names) (hashq-set! category-index-hash catsym (cons (list label markup-symbol textoptions) catlist)) @@ -114,7 +114,7 @@ (for-each (lambda (authorID) (let* ((authorsym (string->symbol authorID)) (authorlist (hashq-ref author-index-hash authorsym - (list (list label 'indexAuthorMarkup `(((rawtext . ,authorID)))))))) + (list (list label 'indexAuthorMarkup `(((combine-with-next . #t) (rawtext . ,authorID)))))))) (hashq-set! author-index-hash authorsym (cons (list label markup-symbol textoptions) authorlist)) )) @@ -218,20 +218,29 @@ } #(define (prepare-item-markup items layout) - (map (lambda (index-item) - (let* ((label (car index-item)) - (index-markup (cadr index-item)) - (textoptions (caddr index-item)) - (text (chain-assoc-get 'rawtext textoptions)) - (alternative (chain-assoc-get 'alternative textoptions)) - (songnumber (chain-assoc-get 'songnumber textoptions))) - (markup #:override (cons 'index:label label) - #:override (cons 'index:page (markup #:custom-page-number label -1)) - #:override (cons 'index:text text) - #:override (cons 'index:alternative alternative) - #:override (cons 'index:songnumber songnumber) - (ly:output-def-lookup layout index-markup)))) - (items))) + (define (single-item-markup index-item) + (let* ((label (car index-item)) + (index-markup (cadr index-item)) + (textoptions (caddr index-item)) + (text (chain-assoc-get 'rawtext textoptions)) + (alternative (chain-assoc-get 'alternative textoptions)) + (songnumber (chain-assoc-get 'songnumber textoptions))) + (markup #:override (cons 'index:label label) + #:override (cons 'index:page (markup #:custom-page-number label -1)) + #:override (cons 'index:text text) + #:override (cons 'index:alternative alternative) + #:override (cons 'index:songnumber songnumber) + (ly:output-def-lookup layout index-markup)))) + (if (null? items) + items + (let* ((index-item (car items)) + (combine-with-next (chain-assoc-get 'combine-with-next (caddr index-item) #f)) + (restitems (cdr items)) + (item-markup (single-item-markup index-item))) + (if (and combine-with-next (not (null? restitems))) + (cons (make-column-markup (list item-markup (single-item-markup (car restitems)))) (prepare-item-markup (cdr restitems) layout)) + (cons item-markup (prepare-item-markup restitems layout)))) + )) #(define-markup-list-command (index-in-columns-with-title layout props index-type title-markup) (symbol? markup?) ( _i "Outputs index alphabetical sorted or in categories" ) @@ -245,7 +254,7 @@ (make-columnlayout-markup-list songTocColumns 2 (let ((h (- (ly:output-def-lookup layout 'paper-height) 12))) (cons (- h (interval-length (ly:stencil-extent title Y))) h)) - (prepare-item-markup items layout)))))) + (prepare-item-markup (items) layout)))))) indexItem = #(define-music-function (parser location sorttext text) (string? markup?) @@ -255,7 +264,7 @@ indexItem = indexSection = #(define-music-function (parser location 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 (prepend-alist-chain 'rawtext text '()) sorttext)) + (add-index-item! 'indexSectionMarkup (prepend-alist-chain 'combine-with-next #t (prepend-alist-chain 'rawtext text '())) sorttext)) #(define (extract-and-check-vars-from-header bookheader varlist) (let* ((headervars (hash-map->list cons (struct-ref (ly:book-header bookheader) 0)))