3.2.6 Table of contents

A table of contents is included using the \markuplist \table-of-contents command. The elements which should appear in the table of contents are entered with the \tocItem command, which may be used either at top-level, or inside a music expression.

\markuplist \table-of-contents
\pageBreak

\tocItem \markup "First score"
\score {
  {
    c'4  % ...
    \tocItem \markup "Some particular point in the first score"
    d'4  % ...
  }
}

\tocItem \markup "Second score"
\score {
  {
    e'4 % ...
  }
}

Markups used for formatting the table of contents are defined in the \paper block. There are two ‘pre-defined’ markups already available;

Both of these variables can be changed.

Here is an example changing the table of contents’ title into French;

\paper {
  tocTitleMarkup = \markup \huge \column {
    \fill-line { \null "Table des matières" \null }
    \hspace #1
  }

Here is an example changing the font-size of the elements in the table of contents;

tocItemMarkup = \markup \large \fill-line {
  \fromproperty #'toc:text \fromproperty #'toc:page
}

Note how the element text and page numbers are referred to in the tocItemMarkup definition.

The \tocItemWithDotsMarkup command can be included within the tocItemMarkup to fill the line, between a table of contents item and its corresponding page number, with dots;

\header { tagline = ##f }
\paper {
  tocItemMarkup = \tocItemWithDotsMarkup
}

\book {
  \markuplist \table-of-contents
  \tocItem \markup { Allegro }
  \tocItem \markup { Largo }
  \markup \null
}

[image of music]

Custom commands with their own markups can also be defined to build a more complex table of contents. In the following example, a new style is defined for entering act names in a table of contents of an opera;

A new markup variable (called tocActMarkup) is defined in the \paper block;

\paper {
  tocActMarkup = \markup \large \column {
    \hspace #1
    \fill-line { \null \italic \fromproperty #'toc:text \null }
    \hspace #1
  }
}

A custom music function (tocAct) is then created – which uses the new tocActMarkup markup definition.

tocAct =
  #(define-music-function (text) (markup?)
     (add-toc-item! 'tocActMarkup text))

A LilyPond input file, using these customer definitions, could look something like this;

[image of music]

Here is an example of the \fill-with-pattern command used within the context of a table of contents;

\paper {
  tocItemMarkup = \markup { \fill-line {
    \override #'(line-width . 70)
    \fill-with-pattern #1.5 #CENTER . \fromproperty #'toc:text \fromproperty #'toc:page
    }
  }
}

See also

Installed Files: ‘ly/toc-init.ly’.

Predefined commands

\table-of-contents, \tocItem.


Más nyelvek: català, deutsch, español, français, italiano, 日本語.
About automatic language selection.

LilyPond — Notation Reference v2.21.0 (development-branch).