Table of contents section command: Difference between revisions
Rework a confusing sentence |
mNo edit summary |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
If you have several pieces in several files, you might want to build a book from that. Assume you have a master file which includes the pieces: | If you have several pieces in several files, you might want to build a book from that. Assume you have a master file which includes the pieces: | ||
\include "tune1.ly" | |||
\include | \include "tune2.ly" | ||
\include | |||
In your piece-files you might have <code>\tocItem</code> commands to build the table of contents. | In your piece-files you might have <code>\tocItem</code> commands to build the table of contents. | ||
With the following snippet, you can replace those <code>\tocItem</code> commands with <code>#(set-toc-section! | With the following snippet, you can replace those <code>\tocItem</code> commands with <code>#(set-toc-section! "''section''")</code> in the master file: | ||
#(set-toc-section! "tunes") | |||
\include "tune1.ly" | |||
\include "tune2.ly" | |||
#(set-toc-section! "parts") | |||
\include "part1.ly" | |||
\include "part2.ly" | |||
Now every section is introduced with a section line in the table of contents only if the section title was set before. If you reorder the parts (includes), the sections will still appear in the right place. This is meant for compiling a collection of pieces, which also compile themselves. For a complete opus with pieces, see [[Ready-to-use LilyPond macros: advanced layout and titles, using a special stylesheet]]. | |||
Now every section is introduced with a section line in the table of contents only if the section title was set before. If you reorder the parts (includes), the sections will still appear in the right place. This is meant for compiling a collection of pieces, which also compile themselves. For a complete opus with pieces | |||
<lilypond version="2.24" full> | <lilypond version="2.24" full> | ||
% define toc-section commands | % define toc-section commands | ||
#(begin | #(begin | ||
| Line 32: | Line 29: | ||
piece = #(define-music-function (text) (markup?) | piece = #(define-music-function (text) (markup?) | ||
(begin | (begin | ||
(if (get-toc-section) (add-toc-item! 'tocCollMarkup (get-toc-section))) | (if (get-toc-section) | ||
(add-toc-item! 'tocCollMarkup (get-toc-section))) | |||
(set-toc-section! #f) | (set-toc-section! #f) | ||
(add-toc-item! 'tocPartMarkup text))) | (add-toc-item! 'tocPartMarkup text))) | ||
\paper { | \paper { | ||
#(set-paper-size | % A small paper size for demonstration purposes. | ||
#(set-paper-size '(cons (* 100 mm) (* 50 mm))) | |||
% this will not know the page number! | % this will not know the page number! | ||
tocCollMarkup = \markup { \fill-line { \bold \fromproperty #'toc:text \vspace #1 \null } } | tocCollMarkup = \markup { \fill-line { | ||
tocPartMarkup = \markup { \fill-line { \concat { \hspace #2 \fromproperty #'toc:text } \vspace #0 \fromproperty #'toc:page } } | \bold \fromproperty #'toc:text \vspace #1 \null } } | ||
tocPartMarkup = \markup { \fill-line { | |||
\concat { \hspace #2 \fromproperty #'toc:text } | |||
\vspace #0 \fromproperty #'toc:page } } | |||
} | } | ||