On Mon, 2025-10-13 at 19:12 +0200, Andreas Schneider wrote:
> Thank you very much, this creates basically what I need. Only a
> slight 
> inconvenience is that I need to re-run the script every time I change
> a 
> title.
I recall that having an attribute "dynamic" that was supposed to
trigger recalculations, but I'm not sure that went anywhere. There are
a number of such things - Upbeat for example...
> That markup is inserted into titles upon edit is annoying.
So here is a fix for the toc:

%8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><

(use-modules (ice-9 string-fun))
(d-PushPosition)
(while (d-PreviousMovement))

(let ((tag "SimpleToc"))
        (d-DirectivePut-paper-postfix tag "tocItemMarkup = 
\\tocItemWithDotsMarkup")
        (d-DirectivePut-score-prefix tag "\\markuplist \\table-of-contents\n")
        (let loop ()
                (define title (d-DirectiveGet-header-data "MTitles"))
                (if title
                        (begin
                                (set! title (assq-ref (eval-string title) 
'title))
                                (if title
                                        (begin
                                                (set! title 
(string-replace-substring title "\\column{" ""))
                                                (set! title 
(string-replace-substring title "\\line{" ""))
                                                (set! title 
(string-replace-substring title "}" ""))
                                                
(d-DirectivePut-movementcontrol-prefix tag (string-append "\\tocItem \\markup 
\"" title "\"\n")))
                                        (d-WarningDialog (_ "No title for this 
movement"))))
                        (d-WarningDialog (_ "No (simple) titles for this 
movement")))
                (if (d-NextMovement)
                        (loop))))
(d-PopPosition)         


%8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><


>  Actually, it 
> is added over and over so that it is present multiple times after 
> several edits if not deleted manually. What is the reason for this 
> strange behaviour?
> 
> Andreas
> 
> 
> Am 13.10.25 um 18:33 schrieb Richard Shann:
> > On Mon, 2025-10-13 at 10:50 +0100, Richard Shann wrote:
> > > On Mon, 2025-10-13 at 10:25 +0100, Richard Shann wrote:
> > > > On Sun, 2025-10-12 at 17:50 +0200, Andreas Schneider wrote:
> > > > > I would like to create a table of contents from the (simple)
> > > > > titles
> > > > > of
> > > > > all movements in a score. That is, I would like Denemo to
> > > > > generate
> > > > > Lilypond output similar to the one in attached file. How can
> > > > > I
> > > > > accomplish that?
> > > > 
> > > > Does this do what you want?
> > > 
> > > That version only did single word titles :( it needs quotes:
> > > 
> > > %8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><
> > > (d-PushPosition)
> > > (while (d-PreviousMovement))
> > > (let ((tag "SimpleToc"))
> > >          (let loop ()
> > >                  (define title (d-DirectiveGet-header-data
> > > "MTitles"))
> > >                  (if title
> > >                          (begin
> > >                                  (set! title (assq-ref (eval-
> > > string
> > > title) 'title))
> > >                                  (if title
> > >                                          (begin
> > >                                                  (d-DirectivePut-
> > > score-prefix tag "\\markuplist \\table-of-contents\n")
> > >                                                  (d-DirectivePut-
> > > movementcontrol-prefix tag (string-append "\\tocItem \\markup \""
> > > title "\"\n")))
> > >                                          (d-WarningDialog (_ "No
> > > title
> > > for this movement"))))
> > >                          (d-WarningDialog (_ "No (simple) titles
> > > for
> > > this movement")))
> > >                  (if (d-NextMovement)
> > >                          (loop))))
> > > (d-PopPosition)
> > > %8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><
> > 
> > Unfortunately, although this works for movement titles that have
> > never
> > been edited, it falls down if they are edited because the editing
> > introduces markup into the titles - at the moment there is no way
> > around that (you have to delete the Movement Titles directive and
> > start
> > again).
> > 
> > Richard
> > 
> > 
> > > 
> > > Richard
> > > 
> > > > 
> > > > %8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8>
> > > > <
> > > > (d-PushPosition)
> > > > (while (d-PreviousMovement))
> > > > (let ((tag "SimpleToc"))
> > > >          (let loop ()
> > > >                  (define title (d-DirectiveGet-header-data
> > > > "MTitles"))
> > > >                  (if title
> > > >                          (begin
> > > >                                  (set! title (assq-ref (eval-
> > > > string
> > > > title) 'title))
> > > >                                  (if title
> > > >                                          (begin
> > > >                                                  (d-
> > > > DirectivePut-
> > > > score-prefix tag "\\markuplist \\table-of-contents\n")
> > > >                                                  (d-
> > > > DirectivePut-
> > > > movementcontrol-prefix tag (string-append "\\tocItem \\markup "
> > > > title
> > > > "\n")))
> > > >                                          (d-WarningDialog (_
> > > > "No
> > > > title
> > > > for this movement"))))
> > > >                          (d-WarningDialog (_ "No (simple)
> > > > titles for
> > > > this movement")))
> > > >                  (if (d-NextMovement)
> > > >                          (loop))))
> > > > (d-PopPosition)
> > > > 
> > > > %8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8>
> > > > <
> > > > 
> > > > Richard
> > > > 
> > > > 
> > > > > 
> > > > > Andreas
> > > > 
> > > > 
> > > 
> > 
> 

Reply via email to