Hello Jean, at least for me this code fails to change the order of the toc. The reason for this is that toc-markup does not in fact contain the markup, but the symbol under which the formatting markup is saved in layout.
So I suppose you rather want to use the text property: (sorted-toc-alist (sort toc-alist ;; Could use comparator-from-key in 2.23 (lambda (item1 item2) (let ((mkup1 (assoc-get 'text (cdr item1))) (mkup2 (assoc-get 'text (cdr item2)))) (string<? (markup->string mkup1) (markup->string mkup2)))))) Cheers, Valentin Am Mittwoch, 21. September 2022, 07:40:48 CEST schrieb Jean Abou Samra: > Le 21/09/2022 à 07:09, Werner LEMBERG a écrit : > > [*] Except Jean has time and interest to produce a solution like pulling > > > > a rabbit out of a hat :-) > > I do have a rabbit to pull out, because I actually already posted a > snippet like this on the lilypond-user-fr list. See > > https://lists.gnu.org/archive/html/lilypond-user-fr/2021-01/msg00041.html > > This user had needs that went beyond just sorting the TOC (replacing > page number with piece numbers), here is a simpler solution if sorting > is all you need: > > \version "2.22.2" > > %% Copied from LilyPond's definition and modified > #(define-markup-list-command (ordered-table-of-contents layout props) () > #:properties ((baseline-skip)) > (let* ((titleMarkup (ly:output-def-lookup layout 'tocTitleMarkup)) > (indentMarkup (ly:output-def-lookup layout 'tocIndentMarkup)) > (toplevelFormatter (ly:output-def-lookup layout 'tocFormatMarkup)) > (toc-alist (toc-items)) > (sorted-toc-alist > (sort toc-alist > ;; Could use comparator-from-key in 2.23 > (lambda (item1 item2) > (let ((mkup1 (assoc-get 'toc-markup (cdr item1))) > (mkup2 (assoc-get 'toc-markup (cdr item2)))) > (string<? > (markup->string mkup1) > (markup->string mkup2))))))) > (ly:output-def-set-variable! layout 'label-alist-table > (append (ly:output-def-lookup layout > 'label-alist-table) > toc-alist)) > (cons (interpret-markup layout props titleMarkup) > (space-lines baseline-skip > (map (lambda (toc-item) > (let* ((label (car toc-item)) > (alist (cdr toc-item)) > (toc-markup (assoc-get 'toc-markup > alist)) > (text (assoc-get 'text alist)) > (level (assoc-get 'level alist))) > (interpret-markup > layout > (cons (list > (cons 'toc:page > (markup #:with-link label > #:page-ref label > "XXX" "?")) > (cons 'toc:text (markup > #:with-link label text)) > (cons 'toc:label label) > (cons 'toc:level level) > (cons 'toc:toplevel-formatter > toplevelFormatter) > (cons 'toc:indent > (make-line-markup > (make-list level > indentMarkup)))) > props) > (ly:output-def-lookup layout > toc-markup)))) > sorted-toc-alist))))) > > \markuplist \ordered-table-of-contents > > \tocItem \markup "A" > { c' } > \tocItem \markup "C" > { c' } > \tocItem \markup "E" > { c' } > \tocItem \markup "F" > { c' } > \tocItem \markup "H" > { c' } > \tocItem \markup "G" > { c' } > \tocItem \markup "B" > { c' } > \tocItem \markup "D" > { c' } > > > > > Best, > Jean
signature.asc
Description: This is a digitally signed message part.