lilypond-user
[Top][All Lists]
Advanced

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

Re: \tocItem within \score block, using header properties


From: Jean Abou Samra
Subject: Re: \tocItem within \score block, using header properties
Date: Tue, 6 Dec 2022 19:07:04 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0



Le 06/12/2022 à 19:05, Jean Abou Samra a écrit :
Le 06/12/2022 à 18:10, Joel C. Salomon a écrit :
The requirement that `\tocItem` is either outside the `\score` block
or within a music variable is making it awkward for me to keep it near
where the score `\header` block defines the piece title.  And I have
entirely failed to figure out a way to re-use the piece title.

Minimal example below, showing different ways I've tried.

Is there a cleaner way to accomplish this?




Try

\version "2.23.82"

upperI = \relative c' {
  c4 d e f
}
lowerI = \relative c {\clef bass f e d c }

scoreI =
\score {
  \header {
    piece = "Piece Title"
  }
  <<
    \new Devnull { \tocItem \markup "Piece Title" }
    \new PianoStaff <<
      \new Staff = "upper" \upperI
      \new Staff = "lower" \lowerI
    >>
  >>
}

\book {
  \markuplist \table-of-contents
  \scoreI
}



A \tocItem needs a bottom context to be interpreted,
like a Voice, Dynamics, TabVoice or such. In this case,
you don't want anything to be printed from it, so you
can use this lesser known context type Devnull. Some
people do it with a Dynamics as well. Devnull works
with everything you might want to take out of the
individual parts: \time, \tempo, \mark, etc.

For not repeating the title between \header and \tocItem,
you could try this approach:


\version "2.23.82"

withPiece =
#(define-scheme-function (mkup score) (markup? ly:score?)
   (let* ((music (ly:score-music score))
          (n (display-scheme-music music))


Sorry, the line above was for debugging, you can remove it.


(new-music #{ { \new Devnull \tocItem #mkup #music } #})
          (new-score (ly:make-score new-music))
          (header (let ((h (ly:score-header score)))
                    (if (null? h)
                        (make-module)
                        h))))
     (for-each (lambda (odef)
                 (ly:score-add-output-def! new-score odef))
               (ly:score-output-defs score))
     (module-define! header 'piece mkup)
     (ly:score-set-header! new-score header)
     new-score))

upperI = \relative c' {
  c4 d e f
}
lowerI = \relative c {\clef bass f e d c }

scoreI =
\withPiece \markup "Piece Title" \score {
  \new PianoStaff <<
    \new Staff = "upper" \upperI
    \new Staff = "lower" \lowerI
  >>
}

\book {
  \markuplist \table-of-contents
  \scoreI
}


Best,
Jean



Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

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