[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Alphabetised table of contents?
From: |
Thomas Morley |
Subject: |
Re: Alphabetised table of contents? |
Date: |
Wed, 21 Sep 2022 10:10:04 +0200 |
Am Mi., 21. Sept. 2022 um 07:41 Uhr schrieb Jean Abou Samra
<jean@abou-samra.fr>:
>
> 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
>
>
There's also:
https://lsr.di.unimi.it/LSR/Item?id=763
Cheers,
Harm
- Alphabetised table of contents?, Brent Annable, 2022/09/20
- Re: Alphabetised table of contents?, Werner LEMBERG, 2022/09/21
- Re: Alphabetised table of contents?, Jean Abou Samra, 2022/09/21
- Re: Alphabetised table of contents?, Valentin Petzel, 2022/09/21
- Re: Alphabetised table of contents?, Jean Abou Samra, 2022/09/21
- Re: Alphabetised table of contents?, Brent Annable, 2022/09/23
- Re: Alphabetised table of contents?, Valentin Petzel, 2022/09/23