J'ai le problème avec votre code, où j'ai remplacé les trois lignes height et mis un % sur le \tocAct, voir ci-dessous.
Après, c'est une question de temps: si quelqu'un trouve la solution en 5 minutes et que le code survit aux màj, autant utiliser le travail déjà fait, mais sinon, je préfère investir quelques heures en python que des semaines en scheme, d'autant que j'ai déjà programmé des indexes de cette manière et que cela fonctionne bien.
\version "2.24.1"
% Voir https://lists.gnu.org/archive/html/lilypond-user-fr/2022-08/msg00074.html
% et https://gitlab.com/lilypond/lilypond/-/issues/6355
#(let ((default-table-of-contents make-table-of-contents-markup-list))
(define-markup-list-command (table-of-contents layout props) ()
(let* ((result (interpret-markup-list layout props (default-table-of-contents)))
(alist (ly:output-def-lookup layout 'label-alist-table))
(parent (ly:output-def-parent layout)))
(when (not (null? parent))
(ly:output-def-set-variable! parent 'label-alist-table alist))
result)))
#(use-modules (ice-9 match))
#(define (group-to-fill-partial-sums lst weight threshold initial)
(let loop ((lst lst)
(i 0)
(partial-sum (initial 0))
(acc '()))
(match lst
(()
(reverse! (map reverse! acc)))
((elt . rest)
(let* ((elt-weight (weight elt))
(new-sum (+ partial-sum elt-weight)))
(cond
((null? acc)
(loop rest i new-sum (list (list elt))))
((<= new-sum threshold)
(loop rest i new-sum (cons (cons elt (car acc))
(cdr acc))))
(else
(loop rest
(1+ i)
(+ (initial (1+ i))
elt-weight)
(cons (list elt)
acc)))))))))
#(define (index-map f . lsts)
(let loop ((lsts lsts)
(i 0))
(if (any null? lsts)
'()
(cons (apply f i (map car lsts))
(loop (map cdr lsts)
(1+ i))))))
#(ly:register-stencil-expression 'new-toc-group)
#(define-markup-command (new-toc-group layout props arg) (markup?)
(let* ((stil (interpret-markup layout props arg))
(expr (ly:stencil-expr stil))
(x (ly:stencil-extent stil X))
(y (ly:stencil-extent stil Y)))
(ly:make-stencil `(new-toc-group ,expr)
x
y)))
#(define-markup-list-command (multicolumn-toc layout props columns) (index?)
#:properties ((baseline-skip)
(padding 5)
(line-width))
(let ((width (/ (- line-width (* padding (1- columns)))
columns))
(height (- (ly:output-def-lookup layout 'paper-height) 30.0)))
(let ((mkup (ly:output-def-lookup layout 'tocItemMarkup)))
(ly:output-def-set-variable! layout 'tocItemMarkup (make-override-markup
`(line-width . ,width)
mkup)))
(match-let*
(((title . ungrouped-stils)
(interpret-markup-list layout
props
(make-table-of-contents-markup-list)))
(stils
(let loop ((ungrouped-stils ungrouped-stils)
(group '())
(acc '()))
(match ungrouped-stils
(()
(reverse!
(map (lambda (group-elts)
(let ((rev-group-elts (reverse! group-elts)))
(stack-stencils Y DOWN baseline-skip rev-group-elts)))
(cons group acc))))
((stil . rest)
(match (ly:stencil-expr stil)
(('new-toc-group expr)
(let* ((x (ly:stencil-extent stil X))
(y (ly:stencil-extent stil Y))
(unwrapped (ly:make-stencil expr x y)))
(loop rest
(list unwrapped)
(cons group acc))))
(_
(loop rest
(cons stil group)
acc)))))))
(split (group-to-fill-partial-sums
stils
(lambda (stil)
(+ (interval-length (ly:stencil-extent stil Y))
baseline-skip))
height
(let ((title-height (interval-length (ly:stencil-extent title Y))))
(lambda (i)
(if (< i columns)
title-height
0)))))
(cols (group-to-fill-partial-sums
split
(const 1)
columns
(const 0))))
(cons title
(map (lambda (page-cols)
(apply ly:stencil-add
(index-map
(lambda (i col-stils)
(ly:stencil-translate-axis
(stack-stencils Y DOWN baseline-skip col-stils)
(* i (+ width padding))
X))
page-cols)))
cols)))))
\paper {
ragged-last-bottom = ##t
ragged-last = ##f
%% Attention : s'il y a plusieurs éléments à l'intérieur du tocActMarkup,
%% ne pas faire \new-toc-group { ... } mais \new-toc-group \line { ... }
tocActMarkup = \markup \new-toc-group \line {
\vspace #1
\hspace #-4
\italic \fromproperty #'toc:text
}
tocItemMarkup = \markup
\fontsize #-2
\fill-line {
\fill-with-pattern #1.5 #CENTER .
\line {
\hspace #-6.5 %% Cancelling the first level's tocIndentMarkup
\fromproperty #'toc:indent \fromproperty #'toc:text
\hspace #2
}
\fromproperty #'toc:page
}
tocTitleMarkup =
\markup {
\column {
\vspace #3
\fill-line { \fontsize #9 "My Real Book" }
\vspace #1
\fill-line { \fontsize #3 "For C Instruments" }
\vspace #2
}
}
}
tocAct =
#(define-music-function (label text) (symbol-list-or-symbol? markup?)
(add-toc-item! 'tocActMarkup text label))
\bookpart {
\paper {
left-margin = 20
right-margin = 15
}
\markuplist
% les \override sont facultatifs
\override #'(padding . 10)
\override #'(baseline-skip . 1)
\multicolumn-toc #4
}
\bookpart {
$@(map (lambda (i)
(let ((sym (gensym "act")))
#{
% \tocAct #sym #(format #f "Pièce ~a" i)
\tocItem #(list sym 'sheet) "Lead sheet"
\tocItem #(list sym 'bass) "Bass line"
c'
#}))
(iota 300 1))
}