lilypond-user-fr
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Table des matières en colonnes


From: Jean Abou Samra
Subject: Re: Table des matières en colonnes
Date: Sun, 28 Aug 2022 19:06:11 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0



Le 27/08/2022 à 22:42, Vincent Gay a écrit :
celle çi.

Tiens, je te l'ai fais avec Libreoffice 2 colonnes et un ls de mon répertoire

Bonne nuit à tous et merci à Jean



Tu me remercieras quand tu seras satisfait du résultat :-)

Voici un brouillon qui fonctionne à peu près mais n'est pas encore très
sophistiqué. En particulier, tu voudrais probablement éviter que les différentes
entrées pour une même pièce (lead sheet, bass line, harmonic grid, ...) ne
se retrouvent sur des colonnes différentes, mais je ne l'ai pas encore implémenté.


Cordialement,
Jean


\version "2.23.12"

% Toujours le même contournement de bug
#(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))))))

#(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)
                    (ly:output-def-lookup layout 'top-margin)
                    (ly:output-def-lookup layout 'bottom-margin))))
     (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 . stils)
             (interpret-markup-list layout
                                    props
(make-table-of-contents-markup-list)))
            (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)))))


\bookpart {
  \paper {
    left-margin = 20
    right-margin = 20
  }
  \markuplist
  % les \override sont facultatifs
  \override #'(padding . 10)
  \override #'(baseline-skip . 2.5)
  \multicolumn-toc #3
}

\bookpart {
  $@(map (lambda (i)
           #{ \tocItem #(format #f "Item ~a" i) c' #})
         (iota 150))
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]