]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/notation/input.itely
Doc: NR 3.2.1: clarify titles and \header blocks (2652)
[lilypond.git] / Documentation / notation / input.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @c \version "2.16.0"
12
13 @node General input and output
14 @chapter General input and output
15
16 This section deals with general LilyPond input and output issues,
17 rather than specific notation.
18
19 @menu
20 * Input structure::
21 * Titles and headers::
22 * Working with input files::
23 * Controlling output::
24 * MIDI output::
25 * Extracting musical information::
26 @end menu
27
28
29 @node Input structure
30 @section Input structure
31
32 The main format of input for LilyPond are text files.  By convention,
33 these files end with @file{.ly}.
34
35 @menu
36 * Structure of a score::
37 * Multiple scores in a book::
38 * Multiple output files from one input file::
39 * Output file names::
40 * File structure::
41 @end menu
42
43
44 @node Structure of a score
45 @subsection Structure of a score
46
47 @funindex \score
48
49 A @code{\score} block must contain a single music expression
50 delimited by curly brackets:
51
52 @example
53 \score @{
54 ...
55 @}
56 @end example
57
58 @warning{There must be @strong{only one} outer music expression in
59 a @code{\score} block, and it @strong{must} be surrounded by
60 curly brackets.}
61
62 This single music expression may be of any size, and may contain
63 other music expressions to any complexity.  All of these examples
64 are music expressions:
65
66 @example
67 @{ c'4 c' c' c' @}
68 @end example
69
70 @lilypond[verbatim,quote]
71 {
72   { c'4 c' c' c' }
73   { d'4 d' d' d' }
74 }
75 @end lilypond
76
77 @lilypond[verbatim,quote]
78 <<
79   \new Staff { c'4 c' c' c' }
80   \new Staff { d'4 d' d' d' }
81 >>
82 @end lilypond
83
84 @example
85 @{
86   \new GrandStaff <<
87     \new StaffGroup <<
88       \new Staff @{ \flute @}
89       \new Staff @{ \oboe @}
90     >>
91     \new StaffGroup <<
92       \new Staff @{ \violinI @}
93       \new Staff @{ \violinII @}
94     >>
95   >>
96 @}
97 @end example
98
99 Comments are one exception to this general rule.  (For others see
100 @ref{File structure}.)  Both single-line comments and comments
101 delimited by @code{%@{ .. %@}} may be placed anywhere within an
102 input file.  They may be placed inside or outside a @code{\score}
103 block, and inside or outside the single music expression within a
104 @code{\score} block.
105
106 Remember that even in a file containing only a @code{\score} block, it
107 is implicitly enclosed in a \book block.  A \book block in a source
108 file produces at least one output file, and by default the name of the
109 output file produced is derived from the name of the input file, so
110 @file{fandangoforelephants.ly} will produce
111 @file{fandangoforelephants.pdf}.
112
113 (For more details  about @code{\book} blocks, see
114 @ref{Multiple scores in a book},
115 @ref{Multiple output files from one input file} @ref{File structure}.)
116
117 @seealso
118 Learning Manual:
119 @rlearning{Working on input files},
120 @rlearning{Music expressions explained},
121 @rlearning{Score is a (single) compound musical expression}.
122
123
124 @node Multiple scores in a book
125 @subsection Multiple scores in a book
126
127 @funindex \book
128 @cindex movements, multiple
129
130 A document may contain multiple pieces of music and text.  Examples
131 of these are an etude book, or an orchestral part with multiple
132 movements.  Each movement is entered with a @code{\score} block,
133
134 @example
135 \score @{
136   @var{..music..}
137 @}
138 @end example
139
140 and texts are entered with a @code{\markup} block,
141
142 @example
143 \markup @{
144   @var{..text..}
145 @}
146 @end example
147
148 @funindex \book
149
150 All the movements and texts which appear in the same @file{.ly} file
151 will normally be typeset in the form of a single output file.
152
153 @example
154 \score @{
155   @var{..}
156 @}
157 \markup @{
158   @var{..}
159 @}
160 \score @{
161   @var{..}
162 @}
163 @end example
164
165 One important exception is within lilypond-book documents,
166 where you explicitly have to add a @code{\book} block, otherwise only
167 the first @code{\score} or @code{\markup} will appear in the output.
168
169 The header for each piece of music can be put inside the @code{\score}
170 block.  The @code{piece} name from the header will be printed before
171 each movement.  The title for the entire book can be put inside the
172 @code{\book}, but if it is not present, the @code{\header} which is at
173 the top of the file is inserted.
174
175 @example
176 \header @{
177   title = "Eight miniatures"
178   composer = "Igor Stravinsky"
179 @}
180 \score @{
181   @dots{}
182   \header @{ piece = "Romanze" @}
183 @}
184 \markup @{
185    ..text of second verse..
186 @}
187 \markup @{
188    ..text of third verse..
189 @}
190 \score @{
191   @dots{}
192   \header @{ piece = "Menuetto" @}
193 @}
194 @end example
195
196 @funindex \bookpart
197
198 Pieces of music may be grouped into book parts using @code{\bookpart}
199 blocks.  Book parts are separated by a page break, and can start with a
200 title, like the book itself, by specifying a @code{\header} block.
201
202 @example
203 \bookpart @{
204   \header @{
205     title = "Book title"
206     subtitle = "First part"
207   @}
208   \score @{ @dots{} @}
209   @dots{}
210 @}
211 \bookpart @{
212   \header @{
213     subtitle = "Second part"
214   @}
215   \score @{ @dots{} @}
216   @dots{}
217 @}
218 @end example
219
220 @node Multiple output files from one input file
221 @subsection Multiple output files from one input file
222
223 If you want multiple output files from the same @file{.ly} file,
224 then you can add multiple @code{\book} blocks, where each
225 such \book block will result in a separate output file.
226 If you do not specify any @code{\book} block in the
227 input file, LilyPond will implicitly treat the whole
228 file as a single \book block, see
229 @ref{File structure}.
230
231 When producing multiple files from a single source file, Lilypond
232 ensures that none of the output files from any @code{\book} block
233 overwrites the output file produced by a preceding @code{\book} from
234 the same input file.
235
236 It does this by adding a suffix to the output name for each
237 @code{\book} which uses the default output file name derived from the
238 input source file.
239
240 The default behaviour is to append a version-number suffix for each
241 name which may clash, so
242
243 @example
244 \book @{
245   \score @{ @dots{} @}
246   \layout @{ @dots{} @}
247 @}
248 \book @{
249   \score @{ @dots{} @}
250   \layout @{ @dots{} @}
251 @}
252 \book @{
253   \score @{ @dots{} @}
254   \layout @{ @dots{} @}
255 @}
256 @end example
257
258 in source file @file{eightminiatures.ly}
259 will produce
260
261 @itemize
262 @item
263 @file{eightminiatures.pdf},
264 @item
265 @file{eightminiatures-1.pdf} and
266 @item
267 @file{eightminiatures-2.pdf}.
268 @end itemize
269
270 @node Output file names
271 @subsection Output file names
272
273 @funindex \bookOutputSuffix
274 @funindex \bookOutputName
275
276 Lilypond provides facilities to allow you to control what file names
277 are used by the various back-ends when producing output files.
278
279 In the previous section, we saw how Lilypond prevents name-clashes when
280 producing several ouputs from a single source file.  You also have the
281 ability to specify your own suffixes for each @code{\book} block, so
282 for example you can produce files called
283 @file{eightminiatures-Romanze.pdf}, @file{eightminiatures-Menuetto.pdf}
284 and @file{eightminiatures-Nocturne.pdf} by adding a
285 @code{\bookOutputSuffix} declaration inside each @code{\book} block.
286
287 @example
288 \book @{
289   \bookOutputSuffix "Romanze"
290   \score @{ @dots{} @}
291   \layout @{ @dots{} @}
292 @}
293 \book @{
294   \bookOutputSuffix "Menuetto"
295   \score @{ @dots{} @}
296   \layout @{ @dots{} @}
297 @}
298 \book @{
299   \bookOutputSuffix "Nocturne"
300   \score @{ @dots{} @}
301   \layout @{ @dots{} @}
302 @}
303 @end example
304
305 You can also specify a different output filename for @code{book} block,
306 by using @code{\bookOutputName} declarations
307
308 @example
309 \book @{
310   \bookOutputName "Romanze"
311   \score @{ @dots{} @}
312   \layout @{ @dots{} @}
313 @}
314 \book @{
315   \bookOutputName "Menuetto"
316   \score @{ @dots{} @}
317   \layout @{ @dots{} @}
318 @}
319 \book @{
320   \bookOutputName "Nocturne"
321   \score @{ @dots{} @}
322   \layout @{ @dots{} @}
323 @}
324 @end example
325
326 The file above will produce these output files:
327
328 @itemize
329 @item
330 @file{Romanze.pdf},
331 @item
332 @file{Menuetto.pdf} and
333 @item
334 @file{Nocturne.pdf}.
335 @end itemize
336
337
338 @node File structure
339 @subsection File structure
340
341 @funindex \paper
342 @funindex \midi
343 @funindex \layout
344 @funindex \header
345 @funindex \score
346 @funindex \book
347 @funindex \bookpart
348
349 A @file{.ly} file may contain any number of toplevel expressions, where a
350 toplevel expression is one of the following:
351
352 @itemize
353 @item
354 An output definition, such as @code{\paper}, @code{\midi}, and
355 @code{\layout}.  Such a definition at the toplevel changes the default
356 book-wide settings.  If more than one such definition of the same type
357 is entered at the top level the definitions are combined, but in
358 conflicting situations the later definitions take precedence.  For
359 details of how this affects the @code{\layout} block see
360 @ref{The \layout block}.
361
362 @item
363 A direct scheme expression, such as
364 @code{#(set-default-paper-size "a7" 'landscape)} or
365 @code{#(ly:set-option 'point-and-click #f)}.
366
367 @item
368 A @code{\header} block.  This sets the global (i.e. the top of
369 file) header block.  This is the block containing the default
370 settings of titling fields like composer, title, etc. for all
371 books within the file (see @ref{Titles explained}).
372
373 @item
374 A @code{\score} block.  This score will be collected with other
375 toplevel scores, and combined as a single @code{\book}.
376 This behavior can be changed by setting the variable
377 @code{toplevel-score-handler} at toplevel.  The default handler is
378 defined in the init file @file{../scm/lily.scm}.
379
380 @item
381 A @code{\book} block logically combines multiple movements
382 (i.e., multiple @code{\score} blocks) in one document.  If there
383 are a number of @code{\score}s, one output file will be created
384 for each @code{\book} block, in which all corresponding movements
385 are concatenated.  The only reason to explicitly specify
386 @code{\book} blocks in a @file{.ly} file is if you wish to create
387 multiple output files from a single input file.  One exception is
388 within lilypond-book documents, where you explicitly have to add
389 a @code{\book} block if you want more than a single @code{\score}
390 or @code{\markup} in the same example.  This behavior can be
391 changed by setting the variable @code{toplevel-book-handler} at
392 toplevel.  The default handler is defined in the init file
393 @file{../scm/lily.scm}.
394
395 @item
396 A @code{\bookpart} block.  A book may be divided into several parts,
397 using @code{\bookpart} blocks, in order to ease the page breaking,
398 or to use different @code{\paper} settings in different parts.
399
400 @item
401 A compound music expression, such as
402 @example
403 @{ c'4 d' e'2 @}
404 @end example
405
406 This will add the piece in a @code{\score} and format it in a
407 single book together with all other toplevel @code{\score}s and music
408 expressions.  In other words, a file containing only the above
409 music expression will be translated into
410
411 @example
412 \book @{
413   \score @{
414     \new Staff @{
415       \new Voice @{
416         @{ c'4 d' e'2 @}
417       @}
418     @}
419     \layout @{ @}
420   @}
421   \paper @{ @}
422   \header @{ @}
423 @}
424 @end example
425
426 This behavior can be changed by setting the variable
427 @code{toplevel-music-handler} at toplevel.  The default handler is
428 defined in the init file @file{../scm/lily.scm}.
429
430 @item
431 A markup text, a verse for example
432 @example
433 \markup @{
434    2.  The first line verse two.
435 @}
436 @end example
437
438 Markup texts are rendered above, between or below the scores or music
439 expressions, wherever they appear.
440
441 @cindex variables
442
443 @item
444 A variable, such as
445 @example
446 foo = @{ c4 d e d @}
447 @end example
448
449 This can be used later on in the file by entering @code{\foo}.  The
450 name of a variable should have alphabetic characters only; no
451 numbers, underscores or dashes.
452
453 @end itemize
454
455 The following example shows three things that may be entered at
456 toplevel
457
458 @example
459 \layout @{
460   % Don't justify the output
461   ragged-right = ##t
462 @}
463
464 \header @{
465    title = "Do-re-mi"
466 @}
467
468 @{ c'4 d' e2 @}
469 @end example
470
471
472 At any point in a file, any of the following lexical instructions can
473 be entered:
474
475 @itemize
476 @item @code{\version}
477 @item @code{\include}
478 @item @code{\sourcefilename}
479 @item @code{\sourcefileline}
480 @item
481 A single-line comment, introduced by a leading @code{%} sign.
482
483 @item
484 A multi-line comment delimited by @code{%@{ .. %@}}.
485
486 @end itemize
487
488 @cindex whitespace
489
490 Whitespace between items in the input stream is generally ignored,
491 and may be freely omitted or extended to enhance readability.
492 However, whitespace should always be used in the following
493 circumstances to avoid errors:
494
495 @itemize
496 @item Around every opening and closing curly bracket.
497 @item After every command or variable, i.e. every item that
498 begins with a @code{\} sign.
499 @item After every item that is to be interpreted as a Scheme
500 expression, i.e. every item that begins with a @code{#}@tie{}sign.
501 @item To separate all elements of a Scheme expression.
502 @item In @code{lyricmode} to separate all the terms in both
503 @code{\override} and @code{\set} commands.  In particular, spaces
504 must be used around the dot and the equals sign in commands like
505 @code{\override Score . LyricText #'font-size = #5} and before and
506 after the entire command.
507
508 @end itemize
509
510 @seealso
511 Learning Manual:
512 @rlearning{How LilyPond input files work}.
513
514 Notation Reference:
515 @ref{Titles explained},
516 @ref{The \layout block}.
517
518
519 @node Titles and headers
520 @section Titles and headers
521
522 Almost all printed music includes a title and the composer's name;
523 some pieces include a lot more information.
524
525 @menu
526 * Creating titles headers and footers::
527 * Custom titles headers and footers::
528 * Creating footnotes::
529 * Reference to page numbers::
530 * Table of contents::
531 @end menu
532
533
534 @node Creating titles headers and footers
535 @subsection Creating titles headers and footers
536
537 @menu
538 * Titles explained::
539 * Default layout of bookpart and score titles::
540 * Default layout of headers and footers::
541 @end menu
542
543
544 @node Titles explained
545 @unnumberedsubsubsec Titles explained
546
547 Each @code{\book} block in a single input file produces a separate
548 output file, see @ref{File structure}.  Within each output file
549 two types of titling areas are provided: @emph{Bookpart Titles} at
550 the beginning of each bookpart and @emph{Score Titles} at the
551 beginning of each score.
552
553 Values of titling fields such as @code{title} and @code{composer}
554 are set in @code{\header} blocks.  (For the syntax of @code{\header}
555 blocks and a complete list of the fields available by default see
556 @ref{Default layout of bookpart and score titles}).  Both Bookpart
557 Titles and Score Titles can contain the same fields, although by
558 default the fields in Score Titles are limited to @code{piece} and
559 @code{opus}.
560
561 @code{\header} blocks may be placed in four different places to form
562 a descending hierarchy of @code{\header} blocks:
563
564 @itemize
565
566 @item
567 At the top of the input file, before all @code{\book},
568 @code{\bookpart}, and @code{\score} blocks.
569
570 @item
571 Within a @code{\book} block but outside all the @code{\bookpart} and
572 @code{\score} blocks within that book.
573
574 @item
575 Within a @code{\bookpart} block but outside all @code{\score} blocks
576 within that bookpart.
577
578 @item
579 After the music expression in a @code{\score} block.
580
581 @end itemize
582
583 The values of the fields filter down this hierarchy, with the values
584 set higher in the hierarchy persisting unless they are over-ridden
585 by a value set lower in the hierarchy, so:
586
587 @itemize
588
589 @item
590  A Bookpart Title is derived from fields set at the top of the input
591 file, modified by fields set in the @code{\book} block, and further
592 modified by fields set in the @code{\bookpart} block.  The resulting
593 values are used to print the Bookpart Title for that bookpart.
594
595 @item
596 A Score Title is derived from fields set at the top of the input
597 file, modified by fields set in the @code{\book} block, further
598 modified by fields set in the @code{\bookpart} block and finally
599 modified by fields set in the @code{\score} block.  The resulting
600 values are used to print the Score Title for that score.  Note,
601 though, that only @code{piece} and @code{opus} fields are printed
602 by default in Score Titles unless the @code{\paper} variable,
603 @code{print-all-headers}, is set to @code{#t}.
604
605 @end itemize
606
607 @warning{Remember when placing a @bs{}@code{header} block inside a
608 @bs{}@code{score} block, that the music expression must come before the
609 @bs{}@code{header} block.}
610
611 It is not necessary to provide @code{\header} blocks in all four
612 places: any or even all of them may be omitted.  Similarly, simple
613 input files may omit the @code{\book} and @code{\bookpart} blocks,
614 leaving them to be created implicitly.
615
616 If the book has only a single score, the @code{\header} block should
617 normally be placed at the top of the file so that just a Bookpart
618 Title is produced, making all the titling fields available for use.
619
620 If the book has multiple scores a number of different arrangements
621 of @code{\header} blocks are possible, corresponding to the various
622 types of musical publications.  For example, if the publication
623 contains several pieces by the same composer a @code{\header} block
624 placed at the top of the file specifying the book title and the
625 composer with @code{\header} blocks in each @code{\score} block
626 specifying the @code{piece} and/or @code{opus} would be most
627 suitable, as here:
628
629 @lilypond[papersize=a5,quote,verbatim,noragged-right]
630 \header {
631   title = "SUITE I."
632   composer = "J. S. Bach."
633 }
634
635 \score {
636   \new Staff \relative g, {
637     \clef bass
638     \key g \major
639     \repeat unfold 2 { g16( d' b') a b d, b' d, } |
640     \repeat unfold 2 { g,16( e' c') b c e, c' e, } |
641   }
642   \header {
643     piece = "Prélude."
644   }
645 }
646
647 \score {
648   \new Staff \relative b {
649     \clef bass
650     \key g \major
651     \partial 16 b16 |
652     <g, d' b'~>4 b'16 a( g fis) g( d e fis) g( a b c) |
653     d16( b g fis) g( e d c) b(c d e) fis( g a b) |
654   }
655   \header {
656     piece = "Allemande."
657   }
658 }
659 @end lilypond
660
661 More complicated arrangements are possible.  For example, text
662 fields from the @code{\header} block in a book can be displayed in
663 all Score Titles, with some fields over-ridden and some manually
664 suppressed:
665
666 @lilypond[papersize=a5,quote,verbatim,noragged-right]
667 \book {
668   \paper {
669     print-all-headers = ##t
670   }
671   \header {
672     title = "DAS WOHLTEMPERIRTE CLAVIER"
673     subtitle = "TEIL I"
674     % Do not display the tagline for this book
675     tagline = ##f
676   }
677   \markup { \vspace #1 }
678   \score {
679     \new PianoStaff <<
680       \new Staff { s1 }
681       \new Staff { \clef "bass" s1 }
682     >>
683     \header {
684       title = "PRAELUDIUM I"
685       opus = "BWV 846"
686       % Do not display the subtitle for this score
687       subtitle = ##f
688     }
689   }
690   \score {
691     \new PianoStaff <<
692       \new Staff { s1 }
693       \new Staff { \clef "bass" s1 }
694     >>
695     \header {
696       title = "FUGA I"
697       subsubtitle = "A 4 VOCI"
698       opus = "BWV 846"
699       % Do not display the subtitle for this score
700       subtitle = ##f
701     }
702   }
703 }
704 @end lilypond
705
706 @seealso
707 Notation Reference:
708 @ref{File structure},
709 @ref{Default layout of bookpart and score titles},
710 @ref{Custom layout for titles}.
711
712
713 @node Default layout of bookpart and score titles
714 @unnumberedsubsubsec Default layout of bookpart and score titles
715
716 This example demonstrates all @code{\header} variables:
717
718 @lilypond[papersize=a7,quote,verbatim,noragged-right]
719 \book {
720   \header {
721       % The following fields are centered
722     dedication = "Dedication"
723     title = "Title"
724     subtitle = "Subtitle"
725     subsubtitle = "Subsubtitle"
726       % The following fields are evenly spread on one line
727       % the field "instrument" also appears on following pages
728     instrument = \markup \with-color #green "Instrument"
729     poet = "Poet"
730     composer = "Composer"
731       % The following fields are placed at opposite ends of the same line
732     meter = "Meter"
733     arranger = "Arranger"
734       % The following fields are centered at the bottom
735     tagline = "tagline goes at the bottom of the last page"
736     copyright = "copyright goes at the bottom of the first page"
737   }
738   \score {
739     { s1 }
740     \header {
741         % The following fields are placed at opposite ends of the same line
742       piece = "Piece 1"
743       opus = "Opus 1"
744     }
745   }
746   \score {
747     { s1 }
748     \header {
749         % The following fields are placed at opposite ends of the same line
750       piece = "Piece 2 on the same page"
751       opus = "Opus 2"
752     }
753   }
754   \pageBreak
755   \score {
756     { s1 }
757     \header {
758         % The following fields are placed at opposite ends of the same line
759       piece = "Piece 3 on a new page"
760       opus = "Opus 3"
761     }
762   }
763 }
764 @end lilypond
765
766 Note that
767
768 @itemize
769 @item
770 The instrument name will be repeated on every page.
771
772 @item
773 Only @code{piece} and @code{opus} are printed in a @code{\score}
774 when the paper variable @code{print-all-headers} is set to
775 @code{##f} (the default).
776
777 @item
778 @c Is the bit about \null markups true? -mp
779 Text fields left unset in a @code{\header} block are replaced with
780 @code{\null} markups so that the space is not wasted.
781
782 @item
783 The default settings for @code{scoreTitleMarkup} place the @code{piece}
784 and @code{opus} text fields at opposite ends of the same line.
785
786 @end itemize
787
788 To change the default layout see @ref{Custom layout for titles}.
789
790 @cindex breakbefore
791
792 Use the @code{breakbefore} variable inside a @code{\header} block
793 that is itself in a @code{\score} block, to make the top-level
794 @code{\header} block titles appear on the first page on their own, with
795 the music (defined in the @code{\score} block) starting on the next.
796
797 @lilypond[papersize=a8landscape,verbatim,noragged-right]
798 \book {
799   \header {
800     title = "This is my Title"
801     subtitle = "This is my Subtitle"
802     copyright = "This is the bottom of the first page"
803   }
804   \score {
805     \repeat unfold 4 { e'' e'' e'' e'' }
806     \header {
807       piece = "This is the Music"
808       breakbefore = ##t
809     }
810   }
811 }
812 @end lilypond
813
814 @seealso
815 Learning Manual:
816 @rlearning{How LilyPond input files work},
817
818 Notation Reference:
819 @ref{Custom layout for titles},
820 @ref{File structure}.
821
822 Installed Files:
823 @file{ly/titling-init.ly}.
824
825
826 @node Default layout of headers and footers
827 @unnumberedsubsubsec Default layout of headers and footers
828
829 @emph{Headers} and @emph{footers} are lines of text appearing at
830 the top and bottom of pages, separate from the main text of a book.
831 They are controlled by the following @code{\paper} variables:
832
833 @itemize
834 @item @code{oddHeaderMarkup}
835 @item @code{evenHeaderMarkup}
836 @item @code{oddFooterMarkup}
837 @item @code{evenFooterMarkup}
838 @end itemize
839
840 These markup variables can only access text fields from top-level
841 @code{\header} blocks (which apply to all scores in the book) and are
842 defined in @file{ly/titling-init.ly}.  By default:
843
844 @itemize
845
846 @item
847 page numbers are automatically placed on the top far left (if even) or
848 top far right (if odd), starting from the second page.
849
850 @item
851 the @code{instrument} text field is placed in the center of every
852 page, starting from the second page.
853
854 @item
855 the @code{copyright} text is centered on the bottom of the first page.
856
857 @item
858 the @code{tagline} is centered on the bottom of the last page, and below
859 the @code{copyright} text if there is only a single page.
860
861 @end itemize
862
863 @lilypond[papersize=a8landscape]
864 \book {
865   \score {
866     \relative c' {
867       c4 d e f
868     }
869   }
870 }
871 @end lilypond
872
873 The default tagline can be changed by adding a @code{tagline} in the
874 top-level @code{\header} block.
875
876 @lilypond[papersize=a8landscape,verbatim]
877 \book {
878   \header {
879     tagline = "... music notation for Everyone"
880   }
881   \score {
882     \relative c' {
883       c4 d e f
884     }
885   }
886 }
887 @end lilypond
888
889 To remove the @code{tagline} set the value to @code{##f}.
890
891
892 @node Custom titles headers and footers
893 @subsection Custom titles headers and footers
894
895 @c TODO: somewhere put a link to header spacing info
896 @c       (you'll have to explain it more in NR 4).
897
898 @menu
899 * Custom text formatting for titles::
900 * Custom layout for titles::
901 * Custom layout for headers and footers::
902 @end menu
903
904
905 @node Custom text formatting for titles
906 @unnumberedsubsubsec Custom text formatting for titles
907
908 Standard @code{\markup} commands can be used to customize any header,
909 footer and title text within the @code{\header} block.
910
911 @lilypond[quote,verbatim,noragged-right]
912 \score {
913   { s1 }
914   \header {
915     piece = \markup { \fontsize #4 \bold "PRAELUDIUM I" }
916     subtitle = \markup { \italic "(Excerpt)" }
917   }
918 }
919 @end lilypond
920
921 @seealso
922 Notation Reference:
923 @ref{Formatting text}.
924
925
926 @node Custom layout for titles
927 @unnumberedsubsubsec Custom layout for titles
928
929 @cindex bookTitleMarkup
930 @cindex scoreTitleMarkup
931 @funindex bookTitleMarkup
932 @funindex scoreTitleMarkup
933
934 @code{\markup} commands in the @code{\header} block are useful for
935 simple text formatting, but they do not allow precise control over the
936 placement of titles.  To customize the placement of the text fields,
937 change either or both of the following @code{\paper} variables:
938
939 @itemize
940 @item @code{bookTitleMarkup}
941 @item @code{scoreTitleMarkup}
942 @end itemize
943
944 The placement of titles when using the default values of these
945 @code{\markup} variables is shown in the examples in
946 @ref{Default layout of bookpart and score titles}.
947
948 The default settings for @code{scoreTitleMarkup} as defined in
949 @file{ly/titling-init.ly} are:
950
951 @example
952 scoreTitleMarkup = \markup @{ \column @{
953   \on-the-fly #print-all-headers @{ \bookTitleMarkup \hspace #1 @}
954   \fill-line @{
955     \fromproperty #'header:piece
956     \fromproperty #'header:opus
957   @}
958 @}
959 @}
960 @end example
961
962 This places the @code{piece} and @code{opus} text fields at opposite
963 ends of the same line:
964
965 @lilypond[quote,verbatim,noragged-right]
966 \score {
967   { s1 }
968   \header {
969     piece = "PRAELUDIUM I"
970     opus = "BWV 846"
971   }
972 }
973 @end lilypond
974
975 This example redefines @code{scoreTitleMarkup} so that the @code{piece}
976 text field is centered and in a large, bold font.
977
978 @lilypond[papersize=a5,quote,verbatim,noragged-right]
979 \book {
980   \paper {
981     indent = 0\mm
982     scoreTitleMarkup = \markup {
983       \fill-line {
984         \null
985         \fontsize #4 \bold \fromproperty #'header:piece
986         \fromproperty #'header:opus
987       }
988     }
989   }
990   \header { tagline = ##f }
991   \score {
992     { s1 }
993     \header {
994       piece = "PRAELUDIUM I"
995       opus = "BWV 846"
996     }
997   }
998 }
999 @end lilypond
1000
1001 Text fields not normally effective in score @code{\header} blocks
1002 can be printed in the Score Title area if @code{print-all-headers} is
1003 placed inside the @code{\paper} block.  A disadvantage of using this
1004 method is that text fields that are intended specifically for the
1005 Bookpart Title area need to be manually suppressed in every
1006 @code{\score} block.  See @ref{Titles explained}.
1007
1008 To avoid this, add the desired text field to the @code{scoreTitleMarkup}
1009 definition.  In the following example, the @code{composer} text field
1010 (normally associated with @code{bookTitleMarkup}) is added to
1011 @code{scoreTitleMarkup}, allowing each score to list a different
1012 composer:
1013
1014 @lilypond[papersize=a5,quote,verbatim,noragged-right]
1015 \book {
1016   \paper {
1017     indent = 0\mm
1018     scoreTitleMarkup = \markup {
1019       \fill-line {
1020         \null
1021         \fontsize #4 \bold \fromproperty #'header:piece
1022         \fromproperty #'header:composer
1023       }
1024     }
1025   }
1026   \header { tagline = ##f }
1027   \score {
1028     { s1 }
1029     \header {
1030       piece = "MENUET"
1031       composer = "Christian Petzold"
1032     }
1033   }
1034   \score {
1035     { s1 }
1036     \header {
1037       piece = "RONDEAU"
1038       composer = "François Couperin"
1039     }
1040   }
1041 }
1042 @end lilypond
1043
1044 It is also possible to create your own custom text fields, and refer to
1045 them in the markup definition.
1046
1047 @lilypond[papersize=a5,quote,verbatim,noragged-right]
1048 \book {
1049   \paper {
1050     indent = 0\mm
1051     scoreTitleMarkup = \markup {
1052       \fill-line {
1053         \null
1054         \override #`(direction . ,UP) {
1055           \dir-column {
1056             \center-align \fontsize #-1 \bold
1057               \fromproperty #'header:mycustomtext %% User-defined field
1058             \center-align \fontsize #4 \bold
1059               \fromproperty #'header:piece
1060           }
1061         }
1062         \fromproperty #'header:opus
1063       }
1064     }
1065   }
1066   \header { tagline = ##f }
1067   \score {
1068     { s1 }
1069     \header {
1070       piece = "FUGA I"
1071       mycustomtext = "A 4 VOCI" %% User-defined field
1072       opus = "BWV 846"
1073     }
1074   }
1075 }
1076 @end lilypond
1077
1078 @seealso
1079 Notation Reference:
1080 @ref{Titles explained}.
1081
1082
1083 @node Custom layout for headers and footers
1084 @unnumberedsubsubsec Custom layout for headers and footers
1085
1086 @c can make-header and make-footer be removed from
1087 @c paper-defaults-init.ly? -mp
1088
1089 @code{\markup} commands in the @code{\header} block are useful for
1090 simple text formatting, but they do not allow precise control over the
1091 placement of headers and footers.  To customize the placement of
1092 the text fields, use either or both of the following @code{\paper}
1093 variables:
1094
1095 @itemize
1096 @item @code{oddHeaderMarkup}
1097 @item @code{evenHeaderMarkup}
1098 @item @code{oddFooterMarkup}
1099 @item @code{evenFooterMarkup}
1100 @end itemize
1101
1102 @cindex markup, conditional
1103 @cindex on-the-fly
1104 @funindex \on-the-fly
1105
1106 The @code{\markup} command @code{\on-the-fly} can be used to add
1107 markup conditionally to header and footer text defined within the
1108 @code{\paper} block, using the following syntax:
1109
1110 @example
1111 @code{variable} = @code{\markup} @{
1112   ...
1113   @code{\on-the-fly}  #@var{procedure}  @var{markup}
1114   ...
1115 @}
1116 @end example
1117
1118 The @var{procedure} is called each time the @code{\markup} command
1119 in which it appears is evaluated.  The @var{procedure} should test
1120 for a particular condition and interpret (i.e. print) the
1121 @var{markup} argument if and only if the condition is true.
1122
1123 A number of ready-made procedures for testing various conditions are
1124 provided:
1125
1126 @quotation
1127 @multitable {print-page-number-check-first-----} {should this page be printed-----}
1128
1129 @headitem  Procedure name           @tab  Condition tested
1130
1131 @item print-page-number-check-first @tab  should this page number be printed?
1132 @item create-page-number-stencil    @tab  'print-page-numbers true?
1133 @item print-all-headers             @tab  'print-all-headers true?
1134 @item first-page                    @tab  first page in the book?
1135 @item (on-page nmbr)                @tab  page number = nmbr?
1136 @item last-page                     @tab  last page in the book?
1137 @item not-first-page                @tab  not first page in the book?
1138 @item part-first-page               @tab  first page in the book part?
1139 @item part-last-page                @tab  last page in the book part?
1140 @item not-single-page               @tab  pages in book part > 1?
1141
1142 @end multitable
1143 @end quotation
1144
1145 The following example centers page numbers at the bottom of every
1146 page.  First, the default settings for @code{oddHeaderMarkup} and
1147 @code{evenHeaderMarkup} are removed by defining each as a @emph{null}
1148 markup.  Then, @code{oddFooterMarkup} is redefined with the page
1149 number centered.  Finally, @code{evenFooterMarkup} is given the
1150 same layout by defining it as @code{\oddFooterMarkup}:
1151
1152 @lilypond[papersize=a8,quote,verbatim,noragged-right]
1153 \book {
1154   \paper {
1155     print-page-number = ##t
1156     print-first-page-number = ##t
1157     oddHeaderMarkup = \markup \null
1158     evenHeaderMarkup = \markup \null
1159     oddFooterMarkup = \markup {
1160       \fill-line {
1161         \on-the-fly #print-page-number-check-first
1162         \fromproperty #'page:page-number-string
1163       }
1164     }
1165     evenFooterMarkup = \oddFooterMarkup
1166   }
1167   \score {
1168     \new Staff { s1 \break s1 \break s1 }
1169   }
1170 }
1171 @end lilypond
1172
1173 Several @code{\on-the-fly} conditions can be combined with an
1174 @q{and} operation, for example,
1175
1176 @example
1177   @code{\on-the-fly #first-page}
1178   @code{\on-the-fly #last-page}
1179   @code{@{ \markup ... \fromproperty #'header: ... @}}
1180 @end example
1181
1182 determines if the output is a single page.
1183
1184 @seealso
1185 Notation Reference:
1186 @ref{Titles explained},
1187 @ref{Default layout of bookpart and score titles}.
1188
1189 Installed Files:
1190 @file{../ly/titling-init.ly}.
1191
1192
1193 @node Creating footnotes
1194 @subsection Creating footnotes
1195
1196 There are two types of footnotes that can be created; automatic
1197 footnotes and manual footnotes.
1198
1199 @menu
1200 * Footnotes overview::
1201 * Automatic footnotes::
1202 * Manual footnotes::
1203 @end menu
1204
1205 @node Footnotes overview
1206 @unnumberedsubsubsec Footnotes overview
1207
1208 Automatic footnotes create incrementing numerical indicators and manual
1209 footnotes allow a custom indicator to be created instead.  Footnotes are
1210 normally applied like @code{\tweak} and consequently can be placed
1211 directly on grobs (graphical objects) created by most music elements and
1212 post-events.  In cases where this does not work (like with bar lines and
1213 meter changes, where the grobs are produced as a consequence of property
1214 changes), footnotes can also be specified as a standalone music event
1215 affecting all grobs of a given type at a particular time step.
1216
1217 The full form of a footnote command is
1218
1219 @example
1220 \footnote @var{mark} @var{offset} @var{grob-name} @var{footnote}
1221 @var{music}
1222 @end example
1223
1224 The elements are as follows:
1225
1226 @table @var
1227 @item mark
1228 is a markup or string specifying the footnote mark which is used for
1229 both marking the reference point as well as the footnote itself at the
1230 bottom of the page.  It can be omitted (or equivalently replaced with
1231 @code{\default}) in which case a number in sequence will be generated.
1232 @item offset
1233 is a number pair such as @samp{#(2 . 1)} specifying the X and Y offset
1234 from the reference point where the mark will be placed.
1235 @item grob-name
1236 specifies a type of grob to mark (like @samp{#'Flag}).  If it is given,
1237 the respective grob will be used as a reference point even in case that
1238 its @q{cause} is not the referenced @var{music} itself but a grob
1239 created from it.  It can be omitted (or replaced with @code{\default}),
1240 and then only a directly created grob will be annotated.
1241 @item footnote
1242 This markup or string specifies the footnote text to use at the bottom
1243 of the page.
1244 @item music
1245 This is the item, a music event or chord constituent or post-event, that
1246 is being annotated.  While it cannot be omitted, it @emph{can} be
1247 replaced by @code{\default} in which case the footnote is not attached
1248 to a music expression in particular, but rather to a moment of time.  It
1249 is mandatory in this case to use the @var{grob-name} argument for
1250 selecting an affected grob type, like @samp{#'TimeSignature}.
1251 @end table
1252
1253 Like with @code{\tweak}, if your @code{\footnote} is applied to a
1254 post-event or articulation, it will itself have to be preceded with
1255 @code{-} to make the parser attach the result to the preceding note or
1256 rest.
1257
1258 @node Automatic footnotes
1259 @unnumberedsubsubsec Automatic footnotes
1260
1261 Automatic footnotes take four arguments: the @samp{(x . y)} position of
1262 the indicator, the optional @var{grob-name} specifying the layout object
1263 to be annotated, the @var{footnote} markup itself that will appear at
1264 the bottom of the page, and of course the @var{music} to attach the
1265 footnote to.
1266
1267 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1268 \book {
1269   \header { tagline = ##f }
1270   \relative c' {
1271     \footnote #'(0.5 . -2)
1272       \markup { The first note }
1273     a'4 b8
1274     \footnote #'(0.5 . 1) #'Flag
1275       \markup { The third note }
1276     e\noBeam c4 d4
1277   }
1278 }
1279 @end lilypond
1280
1281 Chorded notes pose no particular difficulty:
1282
1283 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1284 \book {
1285   \header { tagline = ##f }
1286   \relative c' {
1287     <
1288     \footnote #'(1 . -1.25) "Here is a C" c
1289     \footnote #'(2 . -0.25) \markup { \italic "An E-flat" } es
1290     \footnote #'(2 . 3) \markup { \bold "This is a G" } g
1291     >1
1292   }
1293 }
1294 @end lilypond
1295
1296 @warning {When footnotes have the same vertical position, the footnotes
1297 are printed in order of descendancy; the higher the footnote, the
1298 higher up in the list.}
1299
1300 Here are some more examples of footnoted grobs, also showing the
1301 relative position of the footnotes to the tagline and copyright.
1302
1303 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1304 \book {
1305   \header { copyright = \markup { "Copyright 1970" } }
1306   \relative c' {
1307     a'4-\footnote #'(-3 . 0) \markup { \bold Forte } \f
1308     -\footnote #'(0 . 1.5) \markup { A slur } (
1309     b8)-\footnote #'(0 . -2) \markup { Beam } [ e]
1310     \footnote #'(1 . -1) #'Stem
1311       \markup  { \teeny { This is a stem } }
1312     c4
1313     \footnote #'(0 . 0.5) #'AccidentalCautionary
1314       \markup \italic { A cautionary accidental }
1315     \footnote #'(1 . 1) "The note itself"
1316     dis?4-\footnote #'(0.5 . -0.5) \markup \italic { Slow Down }
1317          _"rit."
1318   }
1319 }
1320 @end lilypond
1321
1322 For top-level @code{\markup}, the @code{\auto-footnote} command is
1323 required:
1324
1325 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1326 \book {
1327   \header { tagline = ##f }
1328   \markup { \auto-footnote "A simple tune" \italic "By me" }
1329   \relative c' {
1330     a'4 b8 e c4 d
1331   }
1332 }
1333 @end lilypond
1334
1335
1336 @node Manual footnotes
1337 @unnumberedsubsubsec Manual footnotes
1338
1339 @cindex footnotes, manual
1340
1341 Manually marked footnotes take an additional first markup argument
1342 @var{mark} for making the reference mark.  In contrast to automatically
1343 generated footnote marks, they will not appear before the @var{footnote}
1344 markup at the bottom of the page: establishing the visual connection is
1345 left to the user.  LilyPond will only make sure that the corresponding
1346 markup appears on the bottom of the same page.
1347
1348 Other than that, the use is identical to that of automatically numbered
1349 footnotes.
1350
1351 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1352 \book {
1353   \header { tagline = ##f }
1354   \relative c' {
1355     \footnote
1356           "1" #'(0.5 . -2)
1357           \markup { \italic "1. The first note" }
1358     a'4
1359     b8
1360     \footnote
1361           \markup { \bold "2" } #'(0.5 . 1)
1362           "2. The second note"
1363     e
1364     c4
1365     d-\footnote "3" #'(0.5 . -1) "3. Piano" \p
1366   }
1367 }
1368 @end lilypond
1369
1370 To annotate chorded notes with manual footnotes:
1371
1372 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1373 \book {
1374   \header { tagline = ##f }
1375   \relative c' {
1376     <
1377     \footnote "1" #'(1 . -1.25) "1. C" c
1378     \footnote
1379        \markup { \bold "b" } #'(2 . -0.25) "b. E-flat" es
1380     \footnote "3" #'(2 . 3) \markup { \italic "iii. G" } g
1381     >1
1382   }
1383 }
1384 @end lilypond
1385
1386 @warning {When footnotes have the same vertical position, the footnotes
1387 are printed in order of descendancy; the higher the footnote, the
1388 higher up in the list.}
1389
1390 Here are some examples of manually footnoted grobs, also showing
1391 the relative position of the footnotes to the tagline and copyright
1392
1393 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1394 \book {
1395   \header { tagline = ##f }
1396   \relative c' {
1397     a'4-\footnote
1398       \markup { \teeny 1 } #'(-3 . 0)
1399       \markup { 1. \bold Forte } \f
1400     -\footnote
1401       \markup { \teeny b } #'(0 . 1.5)
1402       \markup { b. A slur } (
1403     b8)-\footnote
1404       \markup { \teeny 3 } #'(0 . -2)
1405       \markup { 3. Beam } [
1406     e]
1407     \footnote
1408       \markup { 4 } #'(1 . -1) #'Stem
1409       \markup  { \bold 4. { This is a stem } }
1410     c4
1411     \footnote
1412       \markup \concat \teeny { "sharp (v)" }
1413           #'(0 . 0.5) #'AccidentalCautionary
1414       \markup \italic { v. A cautionary accidental }
1415     dis?4-\footnote
1416       \markup \concat \teeny { "a" } #'(0.5 . -0.5)
1417       \markup \italic { a. Slow Down } _"rit."
1418     \footnote
1419       \markup { \teeny \musicglyph #"rests.4" }
1420           #'(1.5 . -0.25)
1421       \markup { \null } \breathe
1422   }
1423 }
1424 @end lilypond
1425
1426 To manually footnote a top-level @code{\markup}:
1427
1428 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1429 \book {
1430   \header { tagline = ##f }
1431   \markup { "A simple tune" \footnote "*" \italic "* By me" }
1432   \relative c' {
1433     a'4 b8 e c4 d4
1434   }
1435 }
1436 @end lilypond
1437
1438 @seealso
1439 Learning Manual:
1440 @rlearning{Objects and interfaces}.
1441
1442 Notation Reference:
1443 @ref{Balloon help},
1444 @ref{Page layout},
1445 @ref{Text marks},
1446 @ref{Text scripts},
1447 @ref{Titles and headers}.
1448
1449 Internals Reference:
1450 @rinternals{FootnoteEvent},
1451 @rinternals{FootnoteItem},
1452 @rinternals{FootnoteSpanner},
1453 @rinternals{Footnote_engraver}.
1454
1455 @knownissues
1456 Multiple footnotes for the same page can only be stacked, one on top of
1457 the other, and cannot be printed on the same line.  Footnotes cannot be
1458 attached to @code{MultiMeasureRests} and may collide with @code{Staff},
1459 @code{\markup} objects and other @code{footnote} annotations.  When
1460 using any manual @code{footnote} command a @code{\paper} block
1461 containing @code{footnote-auto-number = ##f} is required.
1462
1463
1464 @node Reference to page numbers
1465 @subsection Reference to page numbers
1466
1467 A particular place of a score can be marked using the @code{\label}
1468 command, either at top-level or inside music.  This label can then be
1469 referred to in a markup, to get the number of the page where the marked
1470 point is placed, using the @code{\page-ref} markup command.
1471
1472 @lilypond[verbatim,papersize=a8landscape]
1473 \header { tagline = ##f }
1474 \book {
1475   \label #'firstScore
1476   \score {
1477     {
1478       c'1
1479       \pageBreak \mark A \label #'markA
1480       c'1
1481     }
1482   }
1483   \markup { The first score begins on page \page-ref #'firstScore "0" "?" }
1484   \markup { Mark A is on page \page-ref #'markA "0" "?" }
1485 }
1486 @end lilypond
1487
1488 The @code{\page-ref} markup command takes three arguments:
1489 @enumerate
1490 @item the label, a scheme symbol, eg. @code{#'firstScore};
1491 @item a markup that will be used as a gauge to estimate the dimensions
1492 of the markup;
1493 @item a markup that will be used in place of the page number if the label
1494 is not known;
1495 @end enumerate
1496
1497 The reason why a gauge is needed is that, at the time markups are
1498 interpreted, the page breaking has not yet occurred, so the page numbers
1499 are not yet known.  To work around this issue, the actual markup
1500 interpretation is delayed to a later time; however, the dimensions of
1501 the markup have to be known before, so a gauge is used to decide these
1502 dimensions.  If the book has between 10 and 99 pages, it may be "00",
1503 ie. a two digit number.
1504
1505
1506 @predefined
1507 @funindex \label
1508 @code{\label},
1509 @funindex \page-ref
1510 @code{\page-ref}.
1511 @endpredefined
1512
1513
1514 @node Table of contents
1515 @subsection Table of contents
1516 A table of contents is included using the @code{\markuplist \table-of-contents}
1517 command.  The elements which should appear in the table of contents are
1518 entered with the @code{\tocItem} command, which may be used either at
1519 top-level, or inside a music expression.
1520
1521 @verbatim
1522 \markuplist \table-of-contents
1523 \pageBreak
1524
1525 \tocItem \markup "First score"
1526 \score {
1527   {
1528     c'4  % ...
1529     \tocItem \markup "Some particular point in the first score"
1530     d'4  % ...
1531   }
1532 }
1533
1534 \tocItem \markup "Second score"
1535 \score {
1536   {
1537     e'4 % ...
1538   }
1539 }
1540 @end verbatim
1541
1542 The markups which are used to format the table of contents are defined
1543 in the @code{\paper} block.  The default ones are @code{tocTitleMarkup},
1544 for formatting the title of the table, and @code{tocItemMarkup}, for
1545 formatting the toc elements, composed of the element title and page
1546 number.  These variables may be changed by the user:
1547
1548 @verbatim
1549 \paper {
1550   %% Translate the toc title into French:
1551   tocTitleMarkup = \markup \huge \column {
1552     \fill-line { \null "Table des matières" \null }
1553     \hspace #1
1554   }
1555   %% use larger font size
1556   tocItemMarkup = \markup \large \fill-line {
1557     \fromproperty #'toc:text \fromproperty #'toc:page
1558   }
1559 }
1560 @end verbatim
1561
1562 Note how the toc element text and page number are referred to in
1563 the @code{tocItemMarkup} definition.
1564
1565 New commands and markups may also be defined to build more elaborated
1566 table of contents:
1567 @itemize
1568 @item first, define a new markup variable in the @code{\paper} block
1569 @item then, define a music function which aims at adding a toc element
1570 using this markup paper variable.
1571 @end itemize
1572
1573 In the following example, a new style is defined for entering act names
1574 in the table of contents of an opera:
1575
1576 @verbatim
1577 \paper {
1578   tocActMarkup = \markup \large \column {
1579     \hspace #1
1580     \fill-line { \null \italic \fromproperty #'toc:text \null }
1581     \hspace #1
1582   }
1583 }
1584
1585 tocAct =
1586 #(define-music-function (parser location text) (markup?)
1587    (add-toc-item! 'tocActMarkup text))
1588 @end verbatim
1589
1590 @lilypond[line-width=10.0\cm]
1591 \header { tagline = ##f }
1592 \paper {
1593   tocActMarkup = \markup \large \column {
1594     \hspace #1
1595     \fill-line { \null \italic \fromproperty #'toc:text \null }
1596     \hspace #1
1597   }
1598 }
1599
1600 tocAct =
1601 #(define-music-function (parser location text) (markup?)
1602    (add-toc-item! 'tocActMarkup text))
1603
1604 \book {
1605   \markuplist \table-of-contents
1606   \tocAct \markup { Atto Primo }
1607   \tocItem \markup { Coro. Viva il nostro Alcide }
1608   \tocItem \markup { Cesare. Presti omai l'Egizzia terra }
1609   \tocAct \markup { Atto Secondo }
1610   \tocItem \markup { Sinfonia }
1611   \tocItem \markup { Cleopatra. V'adoro, pupille, saette d'Amore }
1612   \markup \null
1613 }
1614 @end lilypond
1615
1616 Dots can be added to fill the line between an item and its page number:
1617
1618 @lilypond[verbatim,line-width=10.0\cm]
1619 \header { tagline = ##f }
1620 \paper {
1621   tocItemMarkup = \tocItemWithDotsMarkup
1622 }
1623
1624 \book {
1625   \markuplist \table-of-contents
1626   \tocItem \markup { Allegro }
1627   \tocItem \markup { Largo }
1628   \markup \null
1629 }
1630 @end lilypond
1631
1632 @seealso
1633 Installed Files:
1634 @file{ly/toc-init.ly}.
1635
1636 @predefined
1637 @funindex \table-of-contents
1638 @code{\table-of-contents},
1639 @funindex \tocItem
1640 @code{\tocItem}.
1641 @endpredefined
1642
1643
1644 @node Working with input files
1645 @section Working with input files
1646
1647 @menu
1648 * Including LilyPond files::
1649 * Different editions from one source::
1650 * Special characters::
1651 @end menu
1652
1653
1654 @node Including LilyPond files
1655 @subsection Including LilyPond files
1656
1657 @funindex \include
1658 @cindex including files
1659
1660 A large project may be split up into separate files.  To refer to
1661 another file, use
1662
1663 @example
1664 \include "otherfile.ly"
1665 @end example
1666
1667 The line @code{\include "otherfile.ly"} is equivalent to pasting the
1668 contents of @file{otherfile.ly} into the current file at the place
1669 where the @code{\include} appears.  For example, in a large
1670 project you might write separate files for each instrument part
1671 and create a @qq{full score} file which brings together the
1672 individual instrument files.  Normally the included file will
1673 define a number of variables which then become available
1674 for use in the full score file.  Tagged sections can be
1675 marked in included files to assist in making them usable in
1676 different places in a score, see @ref{Different editions from
1677 one source}.
1678
1679 Files in the current working directory may be referenced by
1680 specifying just the file name after the @code{\include} command.
1681 Files in other locations may be included by giving either a full
1682 path reference or a relative path reference (but use the UNIX
1683 forward slash, /, rather than the DOS/Windows back slash, \, as the
1684 directory separator.)  For example, if @file{stuff.ly} is located
1685 one directory higher than the current working directory, use
1686
1687 @example
1688 \include "../stuff.ly"
1689 @end example
1690
1691 @noindent
1692 or if the included orchestral parts files are all located in a
1693 subdirectory called @file{parts} within the current directory, use
1694
1695 @example
1696 \include "parts/VI.ly"
1697 \include "parts/VII.ly"
1698 ... etc
1699 @end example
1700
1701 Files which are to be included can also contain @code{\include}
1702 statements of their own.  By default, these second-level
1703 @code{\include} statements are not interpreted until they have
1704 been brought into the main file, so the file names they specify
1705 must all be relative to the directory containing the main file,
1706 not the directory containing the included file.  However,
1707 this behavior can be changed by passing the option
1708 @option{-drelative-includes} option at the command line
1709 (or by adding @code{#(ly:set-option 'relative-includes #t)}
1710 at the top of the main input file).  With @code{relative-includes}
1711 set, the path for each @code{\include} command will be taken
1712 relative to the file containing that command.  This behavior is
1713 recommended and it will become the default behavior in a future
1714 version of lilypond.
1715
1716 Files can also be included from a directory in a search path
1717 specified as an option when invoking LilyPond from the command
1718 line.  The included files are then specified using just their
1719 file name.  For example, to compile @file{main.ly} which includes
1720 files located in a subdirectory called @file{parts} by this method,
1721 cd to the directory containing @file{main.ly} and enter
1722
1723 @example
1724 lilypond --include=parts main.ly
1725 @end example
1726
1727 and in main.ly write
1728
1729 @example
1730 \include "VI.ly"
1731 \include "VII.ly"
1732 ... etc
1733 @end example
1734
1735 Files which are to be included in many scores may be placed in
1736 the LilyPond directory @file{../ly}.  (The location of this
1737 directory is installation-dependent - see
1738 @rlearning{Other sources of information}).  These files can then
1739 be included simply by naming them on an @code{\include} statement.
1740 This is how the language-dependent files like @file{english.ly} are
1741 included.
1742
1743 LilyPond includes a number of files by default when you start
1744 the program.  These includes are not apparent to the user, but the
1745 files may be identified by running @code{lilypond --verbose} from
1746 the command line.  This will display a list of paths and files that
1747 LilyPond uses, along with much other information.  Alternatively,
1748 the more important of these files are discussed in
1749 @rlearning{Other sources of information}.  These files may be
1750 edited, but changes to them will be lost on installing a new
1751 version of LilyPond.
1752
1753 Some simple examples of using @code{\include} are shown in
1754 @rlearning{Scores and parts}.
1755
1756 @seealso
1757 Learning Manual:
1758 @rlearning{Other sources of information},
1759 @rlearning{Scores and parts}.
1760
1761 @knownissues
1762 If an included file is given a name which is the same as one in
1763 LilyPond's installation files, LilyPond's file from the
1764 installation files takes precedence.
1765
1766
1767 @node Different editions from one source
1768 @subsection Different editions from one source
1769
1770 Several methods can be used to generate different versions of a score
1771 from the same music source.  Variables are perhaps the most useful for
1772 combining lengthy sections of music and/or annotation.  Tags are more
1773 useful for selecting one section from several alternative shorter
1774 sections of music, and can also be used for splicing pieces of music
1775 together at different points.
1776
1777 Whichever method is used, separating the notation from the structure of
1778 the score will make it easier to change the structure while leaving the
1779 notation untouched.
1780
1781 @menu
1782 * Using variables::
1783 * Using tags::
1784 * Using global settings::
1785 @end menu
1786
1787 @node Using variables
1788 @unnumberedsubsubsec Using variables
1789
1790 @cindex variables, use of
1791
1792 If sections of the music are defined in variables they can be
1793 reused in different parts of the score, see @rlearning{Organizing
1794 pieces with variables}.  For example, an @notation{a cappella}
1795 vocal score frequently includes a piano reduction of the parts
1796 for rehearsal purposes which is identical to the vocal music, so
1797 the music need be entered only once.  Music from two variables
1798 may be combined on one staff, see @ref{Automatic part combining}.
1799 Here is an example:
1800
1801 @lilypond[verbatim,quote]
1802 sopranoMusic = \relative c'' { a4 b c b8( a) }
1803 altoMusic = \relative g' { e4 e e f }
1804 tenorMusic = \relative c' { c4 b e d8( c) }
1805 bassMusic = \relative c' { a4 gis a d, }
1806 allLyrics = \lyricmode {King of glo -- ry }
1807 <<
1808   \new Staff = "Soprano" \sopranoMusic
1809   \new Lyrics \allLyrics
1810   \new Staff = "Alto" \altoMusic
1811   \new Lyrics \allLyrics
1812   \new Staff = "Tenor" {
1813     \clef "treble_8"
1814     \tenorMusic
1815   }
1816   \new Lyrics \allLyrics
1817   \new Staff = "Bass" {
1818     \clef "bass"
1819     \bassMusic
1820   }
1821   \new Lyrics \allLyrics
1822   \new PianoStaff <<
1823     \new Staff = "RH" {
1824       \set Staff.printPartCombineTexts = ##f
1825       \partcombine
1826       \sopranoMusic
1827       \altoMusic
1828     }
1829     \new Staff = "LH" {
1830       \set Staff.printPartCombineTexts = ##f
1831       \clef "bass"
1832       \partcombine
1833       \tenorMusic
1834       \bassMusic
1835     }
1836   >>
1837 >>
1838 @end lilypond
1839
1840 Separate scores showing just the vocal parts or just the piano
1841 part can be produced by changing just the structural statements,
1842 leaving the musical notation unchanged.
1843
1844 For lengthy scores, the variable definitions may be placed in
1845 separate files which are then included, see @ref{Including
1846 LilyPond files}.
1847
1848 @node Using tags
1849 @unnumberedsubsubsec Using tags
1850
1851 @funindex \tag
1852 @funindex \keepWithTag
1853 @funindex \removeWithTag
1854 @funindex \pushToTag
1855 @funindex \appendToTag
1856 @cindex tag
1857 @cindex keep tagged music
1858 @cindex remove tagged music
1859 @cindex splice into tagged music
1860
1861 The @code{\tag #'@var{partA}} command marks a music expression
1862 with the name @var{partA}.
1863 Expressions tagged in this way can be selected or filtered out by
1864 name later, using either @code{\keepWithTag #'@var{name}} or
1865 @code{\removeWithTag #'@var{name}}.  The result of applying these filters
1866 to tagged music is as follows:
1867 @multitable @columnfractions .5 .5
1868 @headitem Filter
1869   @tab Result
1870 @item
1871 Tagged music preceded by @code{\keepWithTag #'@var{name}}
1872   @tab Untagged music and music tagged with @var{name} is included;
1873        music tagged with any other tag name is excluded.
1874 @item
1875 Tagged music preceded by @code{\removeWithTag #'@var{name}}
1876 @tab Untagged music and music tagged with any tag name other than
1877      @var{name} is included; music tagged with @var{name} is
1878      excluded.
1879 @item
1880 Tagged music not preceded by either @code{\keepWithTag} or
1881 @code{\removeWithTag}
1882 @tab All tagged and untagged music is included.
1883 @end multitable
1884
1885 The arguments of the @code{\tag}, @code{\keepWithTag} and
1886 @code{\removeWithTag} commands should be a symbol
1887 (such as @code{#'score} or @code{#'part}), followed
1888 by a music expression.
1889
1890 In the following example, we see two versions of a piece of music,
1891 one showing trills with the usual notation, and one with trills
1892 explicitly expanded:
1893
1894 @lilypond[verbatim,quote]
1895 music = \relative g' {
1896   g8. c32 d
1897   \tag #'trills { d8.\trill }
1898   \tag #'expand { \repeat unfold 3 { e32 d } }
1899   c32 d
1900  }
1901
1902 \score {
1903   \keepWithTag #'trills \music
1904 }
1905 \score {
1906   \keepWithTag #'expand \music
1907 }
1908 @end lilypond
1909
1910 @noindent
1911 Alternatively, it is sometimes easier to exclude sections of music:
1912
1913 @lilypond[verbatim,quote]
1914 music = \relative g' {
1915   g8. c32 d
1916   \tag #'trills { d8.\trill }
1917   \tag #'expand {\repeat unfold 3 { e32 d } }
1918   c32 d
1919  }
1920
1921 \score {
1922   \removeWithTag #'expand
1923   \music
1924 }
1925 \score {
1926   \removeWithTag #'trills
1927   \music
1928 }
1929 @end lilypond
1930
1931 Tagged filtering can be applied to articulations, texts, etc. by
1932 prepending
1933
1934 @example
1935 -\tag #'@var{your-tag}
1936 @end example
1937
1938 to an articulation.  For example, this would define a note with a
1939 conditional fingering indication and a note with a conditional
1940 annotation:
1941
1942 @example
1943 c1-\tag #'finger ^4
1944 c1-\tag #'warn ^"Watch!"
1945 @end example
1946
1947 Multiple tags may be placed on expressions with multiple
1948 @code{\tag} entries:
1949
1950 @lilypond[quote,verbatim]
1951 music = \relative c'' {
1952   \tag #'a \tag #'both { a4 a a a }
1953   \tag #'b \tag #'both { b4 b b b }
1954 }
1955 <<
1956 \keepWithTag #'a \music
1957 \keepWithTag #'b \music
1958 \keepWithTag #'both \music
1959 >>
1960 @end lilypond
1961
1962 Multiple @code{\removeWithTag} filters may be applied to a single
1963 music expression to remove several differently named tagged sections:
1964
1965 @lilypond[verbatim,quote]
1966 music = \relative c'' {
1967 \tag #'A { a4 a a a }
1968 \tag #'B { b4 b b b }
1969 \tag #'C { c4 c c c }
1970 \tag #'D { d4 d d d }
1971 }
1972 {
1973 \removeWithTag #'B
1974 \removeWithTag #'C
1975 \music
1976 }
1977 @end lilypond
1978
1979 Two or more @code{\keepWithTag} filters applied to a single music
1980 expression will cause @emph{all} tagged sections to be removed, as
1981 the first filter will remove all tagged sections except the one
1982 named, and the second filter will remove even that tagged section.
1983
1984 Sometimes you want to splice some music at a particular place in an
1985 existing music expression.  You can use @code{\pushToTag} and
1986 @code{\appendToTag} for adding material at the front or end of the
1987 @code{elements} of an existing music construct.  Not every music
1988 construct has @code{elements}, but sequential and simultaneous music are
1989 safe bets:
1990
1991 @lilypond[verbatim,quote]
1992 test = { \tag #'here { \tag #'here <<c''>> } }
1993
1994 {
1995   \pushToTag #'here c'
1996   \pushToTag #'here e'
1997   \pushToTag #'here g' \test
1998   \appendToTag #'here c'
1999   \appendToTag #'here e'
2000   \appendToTag #'here g' \test
2001 }
2002 @end lilypond
2003
2004 Both commands get a tag, the material to splice in at every occurence of
2005 the tag, and the tagged expression.  The commands make sure to
2006 copy everything that they change so that the original @code{\test}
2007 retains its meaning.
2008
2009 @seealso
2010 Learning Manual:
2011 @rlearning{Organizing pieces with variables}.
2012
2013 Notation Reference:
2014 @ref{Automatic part combining},
2015 @ref{Including LilyPond files}.
2016
2017 @ignore
2018 @c This warning is more general than this placement implies.
2019 @c Rests are not merged whether or not they come from tagged sections.
2020 @c Should be deleted?  -td
2021
2022 @knownissues
2023 Multiple rests are not merged if you create a score with more
2024 than one tagged section at the same place.
2025
2026 @end ignore
2027
2028
2029 @node Using global settings
2030 @unnumberedsubsubsec Using global settings
2031
2032 @cindex include-settings
2033
2034 Global settings can be included from a separate file:
2035
2036 @example
2037 lilypond -dinclude-settings=MY_SETTINGS.ly MY_SCORE.ly
2038 @end example
2039
2040 Groups of settings such as page size, font or type face can be stored
2041 in separate files. This allows different editions from the same score
2042 as well as standard settings to be applied to many scores, simply by
2043 specifying the proper settings file.
2044
2045 This technique also works well with the use of style sheets, as
2046 discussed in @rlearning{Style sheets}.
2047
2048 @seealso
2049 Learning Manual:
2050 @rlearning{Organizing pieces with variables},
2051 @rlearning{Style sheets}.
2052
2053 Notation Reference:
2054 @ref{Including LilyPond files}.
2055
2056
2057 @node Special characters
2058 @subsection Special characters
2059
2060 @cindex special characters
2061 @cindex non-ASCII characters
2062
2063 @menu
2064 * Text encoding::
2065 * Unicode::
2066 * ASCII aliases::
2067 @end menu
2068
2069
2070 @node Text encoding
2071 @unnumberedsubsubsec Text encoding
2072
2073 @cindex UTF-8
2074
2075 LilyPond uses the character repertoire defined by the Unicode
2076 consortium and ISO/IEC 10646.  This defines a unique name and
2077 code point for the character sets used in virtually all modern
2078 languages and many others too.  Unicode can be implemented using
2079 several different encodings.  LilyPond uses the UTF-8 encoding
2080 (UTF stands for Unicode Transformation Format) which represents
2081 all common Latin characters in one byte, and represents other
2082 characters using a variable length format of up to four bytes.
2083
2084 The actual appearance of the characters is determined by the
2085 glyphs defined in the particular fonts available - a font defines
2086 the mapping of a subset of the Unicode code points to glyphs.
2087 LilyPond uses the Pango library to layout and render multi-lingual
2088 texts.
2089
2090 LilyPond does not perform any input-encoding conversions.  This
2091 means that any text, be it title, lyric text, or musical
2092 instruction containing non-ASCII characters, must be encoded in
2093 UTF-8.  The easiest way to enter such text is by using a
2094 Unicode-aware editor and saving the file with UTF-8 encoding.  Most
2095 popular modern editors have UTF-8 support, for example, vim, Emacs,
2096 jEdit, and GEdit do.  All MS Windows systems later than NT use
2097 Unicode as their native character encoding, so even Notepad can
2098 edit and save a file in UTF-8 format.  A more functional
2099 alternative for Windows is BabelPad.
2100
2101 If a LilyPond input file containing a non-ASCII character is not
2102 saved in UTF-8 format the error message
2103
2104 @example
2105 FT_Get_Glyph_Name () error: invalid argument
2106 @end example
2107
2108 will be generated.
2109
2110 Here is an example showing Cyrillic, Hebrew and Portuguese
2111 text:
2112
2113 @lilypond[quote]
2114 %c No verbatim here as the code does not display correctly in PDF
2115 % Cyrillic
2116 bulgarian = \lyricmode {
2117   Жълтата дюля беше щастлива, че пухът, който цъфна, замръзна като гьон.
2118 }
2119
2120 % Hebrew
2121 hebrew = \lyricmode {
2122   זה כיף סתם לשמוע איך תנצח קרפד עץ טוב בגן.
2123 }
2124
2125 % Portuguese
2126 portuguese = \lyricmode {
2127   à vo -- cê uma can -- ção legal
2128 }
2129
2130 \relative c' {
2131   c2 d e f g f e
2132 }
2133 \addlyrics { \bulgarian }
2134 \addlyrics { \hebrew }
2135 \addlyrics { \portuguese }
2136 @end lilypond
2137
2138
2139 @node Unicode
2140 @unnumberedsubsubsec Unicode
2141
2142 @cindex Unicode
2143
2144 To enter a single character for which the Unicode code point is
2145 known but which is not available in the editor being used, use
2146 either @code{\char ##xhhhh} or @code{\char #dddd} within a
2147 @code{\markup} block, where @code{hhhh} is the hexadecimal code for
2148 the character required and @code{dddd} is the corresponding decimal
2149 value.  Leading zeroes may be omitted, but it is usual to specify
2150 all four characters in the hexadecimal representation.  (Note that
2151 the UTF-8 encoding of the code point should @emph{not} be used
2152 after @code{\char}, as UTF-8 encodings contain extra bits indicating
2153 the number of octets.)  Unicode code charts and a character name
2154 index giving the code point in hexadecimal for any character can be
2155 found on the Unicode Consortium website,
2156 @uref{http://www.unicode.org/}.
2157
2158 For example, @code{\char ##x03BE} and @code{\char #958} would both
2159 enter the Unicode U+03BE character, which has the Unicode name
2160 @qq{Greek Small Letter Xi}.
2161
2162 Any Unicode code point may be entered in this way and if all special
2163 characters are entered in this format it is not necessary to save
2164 the input file in UTF-8 format.  Of course, a font containing all
2165 such encoded characters must be installed and available to LilyPond.
2166
2167 The following example shows Unicode hexadecimal values being entered
2168 in four places -- in a rehearsal mark, as articulation text, in
2169 lyrics and as stand-alone text below the score:
2170
2171 @lilypond[quote,verbatim]
2172 \score {
2173   \relative c'' {
2174     c1 \mark \markup { \char ##x03EE }
2175     c1_\markup { \tiny { \char ##x03B1 " to " \char ##x03C9 } }
2176   }
2177   \addlyrics { O \markup { \concat { Ph \char ##x0153 be! } } }
2178 }
2179 \markup { "Copyright 2008--2012" \char ##x00A9 }
2180 @end lilypond
2181
2182 @cindex copyright sign
2183
2184 To enter the copyright sign in the copyright notice use:
2185
2186 @example
2187 \header @{
2188   copyright = \markup @{ \char ##x00A9 "2008" @}
2189 @}
2190 @end example
2191
2192
2193 @node ASCII aliases
2194 @unnumberedsubsubsec ASCII aliases
2195
2196 A list of ASCII aliases for special characters can be included:
2197
2198 @lilypond[quote,verbatim]
2199 \paper {
2200   #(include-special-characters)
2201 }
2202
2203 \markup "&flqq; &ndash; &OE;uvre incomplète&hellip; &frqq;"
2204
2205 \score {
2206   \new Staff { \repeat unfold 9 a'4 }
2207   \addlyrics {
2208     This is al -- so wor -- kin'~in ly -- rics: &ndash;_&OE;&hellip;
2209   }
2210 }
2211
2212 \markup \column {
2213   "The replacement can be disabled:"
2214   "&ndash; &OE; &hellip;"
2215   \override #'(replacement-alist . ()) "&ndash; &OE; &hellip;"
2216 }
2217 @end lilypond
2218
2219 You can also make your own aliases, either globally:
2220
2221 @lilypond[quote,verbatim]
2222 \paper {
2223   #(add-text-replacements!
2224     '(("100" . "hundred")
2225       ("dpi" . "dots per inch")))
2226 }
2227 \markup "A 100 dpi."
2228 @end lilypond
2229
2230 or locally:
2231
2232 @lilypond[quote,verbatim]
2233 \markup \replace #'(("100" . "hundred")
2234                     ("dpi" . "dots per inch")) "A 100 dpi."
2235 @end lilypond
2236
2237 @seealso
2238 Notation Reference:
2239 @ref{List of special characters}.
2240
2241 Installed Files:
2242 @file{ly/text-replacements.ly}.
2243
2244
2245 @node Controlling output
2246 @section Controlling output
2247
2248 @menu
2249 * Extracting fragments of music::
2250 * Skipping corrected music::
2251 * Alternative output formats::
2252 * Replacing the notation font::
2253 @end menu
2254
2255 @node Extracting fragments of music
2256 @subsection Extracting fragments of music
2257
2258 It is possible to quote small fragments of a large score directly from
2259 the output.  This can be compared to clipping a piece of a paper score
2260 with scissors.
2261
2262 This is done by defining the measures that need to be cut out
2263 separately.  For example, including the following definition
2264
2265
2266 @verbatim
2267 \layout {
2268   clip-regions
2269   = #(list
2270       (cons
2271        (make-rhythmic-location 5 1 2)
2272        (make-rhythmic-location 7 3 4)))
2273 }
2274 @end verbatim
2275
2276 @noindent
2277 will extract a fragment starting halfway the fifth measure, ending in
2278 the seventh measure.  The meaning of @code{5 1 2} is: after a 1/2 note
2279 in measure 5, and @code{7 3 4} after 3 quarter notes in measure 7.
2280
2281 More clip regions can be defined by adding more pairs of
2282 rhythmic-locations to the list.
2283
2284 In order to use this feature, LilyPond must be invoked with
2285 @option{-dclip-systems}.  The clips are output as EPS files, and are
2286 converted to PDF and PNG if these formats are switched on as well.
2287
2288 For more information on output formats, see @rprogram{Invoking lilypond}.
2289
2290 @node Skipping corrected music
2291 @subsection Skipping corrected music
2292
2293
2294 @funindex skipTypesetting
2295 @funindex showFirstLength
2296 @funindex showLastLength
2297
2298 When entering or copying music, usually only the music near the end (where
2299 you
2300 are adding notes) is interesting to view and correct.  To speed up
2301 this correction process, it is possible to skip typesetting of all but
2302 the last few measures.  This is achieved by putting
2303
2304 @verbatim
2305 showLastLength = R1*5
2306 \score { ... }
2307 @end verbatim
2308
2309 @noindent
2310 in your source file.  This will render only the last 5 measures
2311 (assuming 4/4 time signature) of every @code{\score} in the input
2312 file.  For longer pieces, rendering only a small part is often an order
2313 of magnitude quicker than rendering it completely.  When working on the
2314 beginning of a score you have already typeset (e.g. to add a new part),
2315 the @code{showFirstLength} property may be useful as well.
2316
2317 Skipping parts of a score can be controlled in a more fine-grained
2318 fashion with the property @code{Score.skipTypesetting}.  When it is
2319 set, no typesetting is performed at all.
2320
2321 This property is also used to control output to the MIDI file.  Note that
2322 it skips all events, including tempo and instrument changes.  You have
2323 been warned.
2324
2325 @lilypond[quote,relative=2,ragged-right,verbatim]
2326 c8 d
2327 \set Score.skipTypesetting = ##t
2328 e8 e e e e e e e
2329 \set Score.skipTypesetting = ##f
2330 c8 d b bes a g c2
2331 @end lilypond
2332
2333 In polyphonic music, @code{Score.skipTypesetting} will affect all
2334 voices and staves, saving even more time.
2335
2336 @node Alternative output formats
2337 @subsection Alternative output formats
2338
2339 @cindex scalable vector graphics output
2340 @cindex SVG output
2341 @cindex encapsulated postscript output
2342 @cindex EPS output
2343
2344 The default output formats for the printed score are Portable
2345 Document Format (PDF) and PostScript (PS).  Scalable Vector
2346 Graphics (SVG), Encapsulated PostScript (EPS) and Portable
2347 Network Graphics (PNG) output formats are also available through
2348 command line options, see
2349 @rprogram{Basic command line options for LilyPond}.
2350
2351
2352 @node Replacing the notation font
2353 @subsection Replacing the notation font
2354
2355 Gonville is an alternative to the Feta font used in LilyPond and can
2356 be downloaded from:
2357 @example
2358 @uref{http://www.chiark.greenend.org.uk/~sgtatham/gonville/ ,http://www.chiark.greenend.org.uk/~sgtatham/gonville/}
2359 @end example
2360
2361 Here are a few sample bars of music set in Gonville:
2362
2363 @c NOTE: these images are a bit big, but that's important
2364 @c       for the font comparison.  -gp
2365 @sourceimage{Gonville_after,,,}
2366
2367 Here are a few sample bars of music set in LilyPond's Feta font:
2368
2369 @sourceimage{Gonville_before,,,}
2370
2371 @subsubheading Installation Instructions for MacOS
2372
2373 Download and extract the zip file.  Copy the @code{lilyfonts}
2374 directory to @file{@var{SHARE_DIR}/lilypond/current}; for more
2375 information, see @rlearning{Other sources of information}.  Rename the
2376 existing @code{fonts} directory to @code{fonts_orig} and the
2377 @code{lilyfonts} directory to @code{fonts}.  To revert back to Feta,
2378 reverse the process.
2379
2380 @seealso
2381 Learning Manual:
2382 @rlearning{Other sources of information}.
2383
2384 @knownissues
2385 Gonville cannot be used to typeset @q{Ancient Music} notation and it is
2386 likely newer glyphs in later releases of LilyPond may not exist in the
2387 Gonville font family.  Please refer to the author's website for more
2388 information on these and other specifics, including licensing of
2389 Gonville.
2390
2391
2392 @node MIDI output
2393 @section MIDI output
2394
2395 @cindex Sound
2396 @cindex MIDI
2397
2398 MIDI (Musical Instrument Digital Interface) is a standard for
2399 connecting and controlling digital instruments.  A MIDI file is a
2400 series of notes in a number of tracks.  It is not an actual
2401 sound file; you need special software to translate between the
2402 series of notes and actual sounds.
2403
2404 Pieces of music can be converted to MIDI files, so you can listen to
2405 what was entered.  This is convenient for checking the music; octaves
2406 that are off or accidentals that were mistyped stand out very much
2407 when listening to the MIDI output.
2408
2409 Standard MIDI output is somewhat crude; optionally, an enhanced and
2410 more realistic MIDI output is available by means of
2411 @ref{The Articulate script}.
2412
2413 The MIDI output allocates a channel for each staff, and reserves channel
2414 10 for drums.  There are only 16 MIDI channels per device, so if the
2415 score contains more than 15 staves, MIDI channels will be reused.
2416
2417 @menu
2418 * Creating MIDI files::
2419 * MIDI block::
2420 * What goes into the MIDI output?::
2421 * Repeats in MIDI::
2422 * Controlling MIDI dynamics::
2423 * Percussion in MIDI::
2424 * The Articulate script::
2425 @end menu
2426
2427 @node Creating MIDI files
2428 @subsection Creating MIDI files
2429
2430 To create a MIDI output file from a LilyPond input file, add a
2431 @code{\midi} block to a score, for example,
2432
2433 @example
2434 \score @{
2435   @var{...music...}
2436   \midi @{ @}
2437 @}
2438 @end example
2439
2440 If there is a @code{\midi} block in a @code{\score} with no
2441 @code{\layout} block, only MIDI output will be produced.  When
2442 notation is needed too, a @code{\layout} block must also be
2443 present.
2444
2445 @example
2446 \score @{
2447   @var{...music...}
2448   \midi @{ @}
2449   \layout @{ @}
2450 @}
2451 @end example
2452
2453 Pitches, rhythms, ties, dynamics, and tempo changes are interpreted
2454 and translated correctly to the MIDI output.  Dynamic marks,
2455 crescendi and decrescendi translate into MIDI volume levels.
2456 Dynamic marks translate to a fixed fraction of the available MIDI
2457 volume range.  Crescendi and decrescendi make the volume vary
2458 linearly between their two extremes.  The effect of dynamic markings
2459 on the MIDI output can be removed completely, see @ref{MIDI block}.
2460
2461 The initial tempo and later tempo changes can be specified
2462 with the @code{\tempo} command within the music notation.  These
2463 are reflected in tempo changes in the MIDI output.  This command
2464 will normally result in the metronome mark being printed, but this
2465 can be suppressed, see @ref{Metronome marks}.  An alternative way
2466 of specifying the initial or overall MIDI tempo is described below,
2467 see @ref{MIDI block}.
2468
2469 Due to some limitations on Windows, the default extension for
2470 MIDI files on Windows is @code{.mid}.  Other operating systems still
2471 use the extension @code{.midi}.  If a different extension is preferred,
2472 insert the following line at the top-level of the input file,
2473 before the start of any @code{\book}, @code{\bookpart} or @code{\score} blocks:
2474
2475 @example
2476 #(ly:set-option 'midi-extension "midi")
2477 @end example
2478
2479 The line above will set the default extension for MIDI files to
2480 @code{.midi}.
2481
2482 Alternatively, this option can also be supplied on the command line:
2483
2484 @example
2485 lilypond … -dmidi-extension=midi lilyFile.ly
2486 @end example
2487
2488
2489 @unnumberedsubsubsec Instrument names
2490
2491 @cindex instrument names
2492 @funindex Staff.midiInstrument
2493
2494 The MIDI instrument to be used is specified by setting the
2495 @code{Staff.midiInstrument} property to the instrument name.
2496 The name should be chosen from the list in @ref{MIDI instruments}.
2497
2498 @example
2499 \new Staff @{
2500   \set Staff.midiInstrument = #"glockenspiel"
2501   @var{...notes...}
2502 @}
2503 @end example
2504
2505 @example
2506 \new Staff \with @{midiInstrument = #"cello"@} @{
2507   @var{...notes...}
2508 @}
2509 @end example
2510
2511 If the selected instrument does not exactly match an instrument from
2512 the list of MIDI instruments, the Grand Piano (@code{"acoustic grand"})
2513 instrument is used.
2514
2515
2516 @snippets
2517
2518 @lilypondfile[verbatim,quote,ragged-right,texidoc,doctitle]
2519 {changing-midi-output-to-one-channel-per-voice.ly}
2520
2521 @knownissues
2522
2523 @c In 2.11 the following no longer seems to be a problem -td
2524 @ignore
2525 Unterminated (de)crescendos will not render properly in the midi file,
2526 resulting in silent passages of music.  The workaround is to explicitly
2527 terminate the (de)crescendo.  For example,
2528
2529 @example
2530 @{ a4\< b c d\f @}
2531 @end example
2532
2533 @noindent
2534 will not work properly but
2535
2536 @example
2537 @{ a4\< b c d\!\f @}
2538 @end example
2539
2540 @noindent
2541 will.
2542 @end ignore
2543
2544 Changes in the MIDI volume take place only on starting a note, so
2545 crescendi and decrescendi cannot affect the volume of a
2546 single note.
2547
2548 Not all midi players correctly handle tempo changes in the midi
2549 output.  Players that are known to work include MS Windows Media
2550 Player and @uref{http://@/timidity@/.sourceforge@/.net/,timidity}.
2551
2552 @node MIDI block
2553 @subsection MIDI block
2554 @cindex MIDI block
2555
2556 A @code{\midi} block must appear within a score block if MIDI output
2557 is required.  It is analogous to the layout block, but somewhat
2558 simpler.  Often, the @code{\midi} block is left empty, but it
2559 can contain context rearrangements, new context definitions or code
2560 to set the values of properties.  For example, the following will
2561 set the initial tempo exported to a MIDI file without causing a tempo
2562 indication to be printed:
2563
2564 @example
2565 \score @{
2566   @var{...music...}
2567   \midi @{
2568     \tempo 4 = 72
2569   @}
2570 @}
2571 @end example
2572
2573 In this example the tempo is set to 72 quarter note
2574 beats per minute.  @code{\tempo} is actually a music command for
2575 setting properties during the interpretation of music: in the
2576 context of output definitions like a @code{\midi} block, as a matter of
2577 courtesy those are reinterpreted as if they were context modifications.
2578
2579 @cindex MIDI context definitions
2580
2581 Context definitions follow precisely the same syntax as those
2582 within a @code{\layout} block.  Translation modules for sound are
2583 called performers.  The contexts for MIDI output are defined in
2584 @file{../ly/performer-init.ly},
2585 see @rlearning{Other sources of information}.
2586 For example, to remove the effect of dynamics
2587 from the MIDI output, insert the following lines in the
2588 @code{\midi@{ @}} block.
2589
2590 @example
2591 \midi @{
2592   ...
2593   \context @{
2594     \Voice
2595     \remove "Dynamic_performer"
2596   @}
2597 @}
2598 @end example
2599
2600 MIDI output is created only when a @code{\midi} block is included
2601 within a score block defined with a @code{\score} command.
2602
2603 @example
2604 \score @{
2605   @{ @dots{}notes@dots{} @}
2606   \midi @{ @}
2607 @}
2608 @end example
2609
2610 @node What goes into the MIDI output?
2611 @subsection What goes into the MIDI output?
2612
2613 @c TODO Check grace notes - timing is suspect?
2614
2615 @unnumberedsubsubsec Supported in MIDI
2616
2617 @cindex Pitches in MIDI
2618 @cindex MIDI, Pitches
2619 @cindex Quarter tones in MIDI
2620 @cindex MIDI, quarter tones
2621 @cindex Microtones in MIDI
2622 @cindex MIDI, microtones
2623 @cindex Chord names in MIDI
2624 @cindex MIDI, chord names
2625 @cindex Rhythms in MIDI
2626 @cindex MIDI, Rhythms
2627 @cindex Articlulate scripts
2628 @cindex MIDI, articulations
2629 @cindex articulations in MIDI
2630 @cindex trills in MIDI
2631 @cindex turns in MIDI
2632 @cindex rallentando in MIDI
2633 @cindex accelerando in MIDI
2634 @c TODO etc
2635
2636 The following items of notation are reflected in the MIDI output:
2637
2638 @itemize
2639 @item Pitches
2640 @item Microtones (See @ref{Accidentals}.  Rendering needs a
2641 player that supports pitch bend.)
2642 @item Chords entered as chord names
2643 @item Rhythms entered as note durations, including tuplets
2644 @item Tremolos entered without @q{@code{:}[@var{number}]}
2645 @item Ties
2646 @item Dynamic marks
2647 @item Crescendi, decrescendi over multiple notes
2648 @item Tempo changes entered with a tempo marking
2649 @item Lyrics
2650 @end itemize
2651
2652 Using @ref{The Articulate script}, a number of items are added to the
2653 above list:
2654
2655 @itemize
2656 @item Articulations (slurs, staccato, etc)
2657 @item Trills, turns
2658 @item Rallentando and accelerando
2659 @end itemize
2660
2661
2662 @unnumberedsubsubsec Unsupported in MIDI
2663
2664 @c TODO index as above
2665
2666 The following items of notation have no effect on the MIDI output,
2667 unless you use @ref{The Articulate script}:
2668
2669 @itemize
2670 @item Rhythms entered as annotations, e.g. swing
2671 @item Tempo changes entered as annotations with no tempo marking
2672 @item Staccato and other articulations and ornamentations
2673 @item Slurs and Phrasing slurs
2674 @item Crescendi, decrescendi over a single note
2675 @item Tremolos entered with @q{@code{:}[@var{number}]}
2676 @item Figured bass
2677 @item Microtonal chords
2678 @end itemize
2679
2680
2681 @node Repeats in MIDI
2682 @subsection Repeats in MIDI
2683
2684 @cindex repeats in MIDI
2685 @funindex \unfoldRepeats
2686
2687 With a few minor additions, all types of repeats can be represented
2688 in the MIDI output.  This is achieved by applying the
2689 @code{\unfoldRepeats} music function.  This function changes all
2690 repeats to unfold repeats.
2691
2692 @lilypond[quote,verbatim]
2693 \unfoldRepeats {
2694   \repeat tremolo 8 { c'32 e' }
2695   \repeat percent 2 { c''8 d'' }
2696   \repeat volta 2 { c'4 d' e' f' }
2697   \alternative {
2698     { g' a' a' g' }
2699     { f' e' d' c' }
2700   }
2701 }
2702 \bar "|."
2703 @end lilypond
2704
2705 In scores containing multiple voices, unfolding of repeats in MIDI
2706 output will only occur correctly if @emph{each} voice contains fully
2707 notated repeat indications.
2708
2709 When creating a score file using @code{\unfoldRepeats} for MIDI,
2710 it is necessary to make two @code{\score} blocks: one for MIDI
2711 (with unfolded repeats) and one for notation (with volta, tremolo,
2712 and percent repeats).  For example,
2713
2714 @example
2715 \score @{
2716   @var{..music..}
2717   \layout @{ .. @}
2718 @}
2719 \score @{
2720   \unfoldRepeats @var{..music..}
2721   \midi @{ .. @}
2722 @}
2723 @end example
2724
2725 @node Controlling MIDI dynamics
2726 @subsection Controlling MIDI dynamics
2727
2728 MIDI dynamics are implemented by the Dynamic_performer which lives
2729 by default in the Voice context.  It is possible to control the
2730 overall MIDI volume, the relative volume of dynamic markings and
2731 the relative volume of different instruments.
2732
2733 @unnumberedsubsubsec Dynamic marks
2734
2735 Dynamic marks are translated to a fixed fraction of the available
2736 MIDI volume range.  The default fractions range from 0.25 for
2737 @notation{ppppp} to 0.95 for @notation{fffff}.  The set of dynamic
2738 marks and the associated fractions can be seen in
2739 @file{../scm/midi.scm}, see @rlearning{Other sources of information}.
2740 This set of fractions may be changed or extended by providing a
2741 function which takes a dynamic mark as its argument and returns the
2742 required fraction, and setting
2743 @code{Score.dynamicAbsoluteVolumeFunction} to this function.
2744
2745 For example, if a @notation{rinforzando} dynamic marking,
2746 @code{\rfz}, is required, this will not by default
2747 have any effect on the MIDI volume, as this dynamic marking is not
2748 included in the default set.  Similarly, if a new dynamic marking
2749 has been defined with @code{make-dynamic-script} that too will not
2750 be included in the default set.  The following example shows how the
2751 MIDI volume for such dynamic markings might be added.  The Scheme
2752 function sets the fraction to 0.9 if a dynamic mark of rfz is
2753 found, or calls the default function otherwise.
2754
2755 @lilypond[verbatim,quote]
2756 #(define (myDynamics dynamic)
2757     (if (equal? dynamic "rfz")
2758       0.9
2759       (default-dynamic-absolute-volume dynamic)))
2760
2761 \score {
2762   \new Staff {
2763     \set Staff.midiInstrument = #"cello"
2764     \set Score.dynamicAbsoluteVolumeFunction = #myDynamics
2765     \new Voice {
2766       \relative c'' {
2767         a4\pp b c-\rfz
2768       }
2769     }
2770   }
2771   \layout {}
2772   \midi {}
2773 }
2774 @end lilypond
2775
2776 Alternatively, if the whole table of fractions needs to be
2777 redefined, it would be better to use the
2778 @notation{default-dynamic-absolute-volume} procedure in
2779 @file{../scm/midi.scm} and the associated table as a model.
2780 The final example in this section shows how this might be done.
2781
2782 @unnumberedsubsubsec Overall MIDI volume
2783
2784 The minimum and maximum overall volume of MIDI dynamic markings is
2785 controlled by setting the properties @code{midiMinimumVolume} and
2786 @code{midiMaximumVolume} at the @code{Score} level.  These
2787 properties have an effect only on dynamic marks, so if they
2788 are to apply from the start of the score a dynamic mark must be
2789 placed there.  The fraction corresponding to each dynamic mark is
2790 modified with this formula
2791
2792 @example
2793 midiMinimumVolume + (midiMaximumVolume - midiMinimumVolume) * fraction
2794 @end example
2795
2796 In the following example the dynamic range of the overall MIDI
2797 volume is limited to the range 0.2 - 0.5.
2798
2799 @lilypond[verbatim,quote]
2800 \score {
2801   <<
2802     \new Staff {
2803       \key g \major
2804       \time 2/2
2805       \set Staff.midiInstrument = #"flute"
2806       \new Voice \relative c''' {
2807         r2 g\mp g fis~
2808         fis4 g8 fis e2~
2809         e4 d8 cis d2
2810       }
2811     }
2812     \new Staff {
2813       \key g \major
2814       \set Staff.midiInstrument = #"clarinet"
2815       \new Voice \relative c'' {
2816         b1\p a2. b8 a
2817         g2. fis8 e
2818         fis2 r
2819       }
2820     }
2821   >>
2822   \layout {}
2823   \midi {
2824     \tempo 2 = 72
2825     \context {
2826       \Score
2827       midiMinimumVolume = #0.2
2828       midiMaximumVolume = #0.5
2829     }
2830   }
2831 }
2832 @end lilypond
2833
2834 @unnumberedsubsubsec Equalizing different instruments (i)
2835
2836 If the minimum and maximum MIDI volume properties are set in
2837 the @code{Staff} context the relative volumes of the MIDI
2838 instruments can be controlled.  This gives a basic instrument
2839 equalizer, which can enhance the quality of the MIDI output
2840 remarkably.
2841
2842 In this example the volume of the clarinet is reduced relative
2843 to the volume of the flute.  There must be a dynamic
2844 mark on the first note of each instrument for this to work
2845 correctly.
2846
2847 @lilypond[verbatim,quote]
2848 \score {
2849   <<
2850     \new Staff {
2851       \key g \major
2852       \time 2/2
2853       \set Staff.midiInstrument = #"flute"
2854       \set Staff.midiMinimumVolume = #0.7
2855       \set Staff.midiMaximumVolume = #0.9
2856       \new Voice \relative c''' {
2857         r2 g\mp g fis~
2858         fis4 g8 fis e2~
2859         e4 d8 cis d2
2860       }
2861     }
2862     \new Staff {
2863       \key g \major
2864       \set Staff.midiInstrument = #"clarinet"
2865       \set Staff.midiMinimumVolume = #0.3
2866       \set Staff.midiMaximumVolume = #0.6
2867       \new Voice \relative c'' {
2868         b1\p a2. b8 a
2869         g2. fis8 e
2870         fis2 r
2871       }
2872     }
2873   >>
2874   \layout {}
2875   \midi {
2876     \tempo 2 = 72
2877   }
2878 }
2879 @end lilypond
2880
2881 @unnumberedsubsubsec Equalizing different instruments (ii)
2882
2883 If the MIDI minimum and maximum volume properties are not set
2884 LilyPond will, by default, apply a small degree of equalization
2885 to a few instruments.  The instruments and the equalization
2886 applied are shown in the table @notation{instrument-equalizer-alist}
2887 in @file{../scm/midi.scm}.
2888
2889 This basic default equalizer can be replaced by setting
2890 @code{instrumentEqualizer} in the @code{Score} context to a new
2891 Scheme procedure which accepts a MIDI instrument name as its only
2892 argument and returns a pair of fractions giving the minimum and
2893 maximum volumes to be applied to that instrument.  This replacement
2894 is done in the same way as shown for resetting the
2895 @code{dynamicAbsoluteVolumeFunction} at the start of this section.
2896 The default equalizer, @notation{default-instrument-equalizer}, in
2897 @file{../scm/midi.scm} shows how such a procedure might be written.
2898
2899 The following example sets the relative flute and clarinet volumes
2900 to the same values as the previous example.
2901
2902 @lilypond[verbatim,quote]
2903 #(define my-instrument-equalizer-alist '())
2904
2905 #(set! my-instrument-equalizer-alist
2906   (append
2907     '(
2908       ("flute" . (0.7 . 0.9))
2909       ("clarinet" . (0.3 . 0.6)))
2910     my-instrument-equalizer-alist))
2911
2912 #(define (my-instrument-equalizer s)
2913   (let ((entry (assoc s my-instrument-equalizer-alist)))
2914     (if entry
2915       (cdr entry))))
2916
2917 \score {
2918   <<
2919     \new Staff {
2920       \key g \major
2921       \time 2/2
2922       \set Score.instrumentEqualizer = #my-instrument-equalizer
2923       \set Staff.midiInstrument = #"flute"
2924       \new Voice \relative c''' {
2925         r2 g\mp g fis~
2926         fis4 g8 fis e2~
2927         e4 d8 cis d2
2928       }
2929     }
2930     \new Staff {
2931       \key g \major
2932       \set Staff.midiInstrument = #"clarinet"
2933       \new Voice \relative c'' {
2934         b1\p a2. b8 a
2935         g2. fis8 e
2936         fis2 r
2937       }
2938     }
2939   >>
2940   \layout { }
2941   \midi {
2942     \tempo 2 = 72
2943   }
2944 }
2945 @end lilypond
2946
2947 @ignore
2948 @c Delete when satisfied this is adequately covered elsewhere -td
2949
2950 @n ode Microtones in MIDI
2951 @s ubsection Microtones in MIDI
2952
2953 @cindex microtones in MIDI
2954
2955 Microtones consisting of half sharps and half flats are exported
2956 to the MIDI file and render correctly in MIDI players which support
2957 pitch bending.  See @ref{Note names in other languages}.  Here is
2958 an example showing all the half sharps and half flats.  It can be
2959 copied out and compiled to test microtones in your MIDI player.
2960
2961 @lilypond[verbatim,quote]
2962 \score {
2963   \relative c' {
2964     c4 cih cis cisih
2965     d4 dih ees eeh
2966     e4 eih f fih
2967     fis4 fisih g gih
2968     gis4 gisih a aih
2969     bes4 beh b bih
2970   }
2971   \layout {}
2972   \midi {}
2973 }
2974 @end lilypond
2975 @end ignore
2976
2977
2978 @node Percussion in MIDI
2979 @subsection Percussion in MIDI
2980
2981 Percussion instruments are generally notated in a @code{DrumStaff}
2982 context and when notated in this way they are outputted correctly
2983 to MIDI channel@tie{}10, but some pitched percussion instruments,
2984 like the xylophone, marimba, vibraphone, timpani, etc., are
2985 treated like @qq{normal} instruments and music for these instruments
2986 should be entered in a normal @code{Staff} context, not a
2987 @code{DrumStaff} context, to obtain the correct MIDI output.
2988
2989 Some non-pitched percussion sounds included in the general MIDI
2990 standard, like melodic tom, taiko drum, synth drum, etc., cannot
2991 be reached via MIDI channel@tie{}10, so the notation for such
2992 instruments should also be entered in a normal @code{Staff}
2993 context, using suitable normal pitches.
2994
2995 Many percussion instruments are not included in the general MIDI
2996 standard, e.g. castanets.  The easiest, although unsatisfactory,
2997 method of producing some MIDI output when writing for such
2998 instruments is to substitute the nearest sound from the standard
2999 set.
3000
3001 @c TODO Expand with examples, and any other issues
3002
3003 @knownissues
3004
3005 Because the general MIDI standard does not contain rim shots, the
3006 sidestick is used for this purpose instead.
3007
3008 @node The Articulate script
3009 @subsection The Articulate script
3010
3011 A more realistic MIDI output is possible when using the Articulate
3012 script.  It tries to take articulations (slurs, staccato, etc) into
3013 account, by replacing notes with sequential music of suitably
3014 time-scaled note plus skip.  It also tries to unfold trills turns
3015 etc., and take rallentando and accelerando into account.
3016
3017 To use the Articulate script, you have to include it at the top of
3018 your input file,
3019
3020 @example
3021 \include "articulate.ly"
3022 @end example
3023
3024 and in the @code{\score} section do
3025
3026 @example
3027 \unfoldRepeats \articulate <<
3028         all the rest of the score...
3029 >>
3030 @end example
3031
3032 After altering your input file this way, the visual output is heavily
3033 altered, but the standard @code{\midi} block will produce a better
3034 MIDI file.
3035
3036 Although not essential for the Articulate script to work, you may want
3037 to insert the @code{\unfoldRepeats} command as it appears in the
3038 example shown above as it enables performing abbreviatures such as
3039 @notation{trills}.
3040
3041 @knownissues
3042
3043 Articulate shortens chords and some music (esp. organ music) could
3044 sound worse.
3045
3046
3047 @node Extracting musical information
3048 @section Extracting musical information
3049
3050 In addition to creating graphical output and MIDI, LilyPond can
3051 display musical information as text.
3052
3053 @menu
3054 * Displaying LilyPond notation::
3055 * Displaying scheme music expressions::
3056 * Saving music events to a file::
3057 @end menu
3058
3059 @node Displaying LilyPond notation
3060 @subsection Displaying LilyPond notation
3061
3062 @funindex \displayLilyMusic
3063 Displaying a music expression in LilyPond notation can be
3064 done with the music function @code{\displayLilyMusic}.  To see the
3065 output, you will typically want to call LilyPond using the command
3066 line.  For example,
3067
3068 @example
3069 @{
3070   \displayLilyMusic \transpose c a, @{ c4 e g a bes @}
3071 @}
3072 @end example
3073
3074 will display
3075
3076 @example
3077 @{ a,4 cis e fis g @}
3078 @end example
3079
3080 By default, LilyPond will print these messages to the console
3081 along with all the other LilyPond compilation messages.  To split
3082 up these messages and save the results of @code{\display@{STUFF@}},
3083 redirect the output to a file.
3084
3085 @example
3086 lilypond file.ly >display.txt
3087 @end example
3088
3089 @funindex \void
3090 Note that Lilypond does not just display the music expression, but
3091 also interprets it (since @code{\displayLilyMusic} returns it in
3092 addition to displaying it).  This is convenient since you can just
3093 insert @code{\displayLilyMusic} into existing music in order to get
3094 information about it.  If you don't actually want Lilypond to
3095 interpret the displayed music as well as display it, use @code{\void}
3096 in order to have it ignored:
3097
3098 @example
3099 @{
3100   \void \displayLilyMusic \transpose c a, @{ c4 e g a bes @}
3101 @}
3102 @end example
3103
3104
3105 @node Displaying scheme music expressions
3106 @subsection Displaying scheme music expressions
3107
3108 See @rextend{Displaying music expressions}.
3109
3110
3111 @node Saving music events to a file
3112 @subsection Saving music events to a file
3113
3114 Music events can be saved to a file on a per-staff basis by
3115 including a file in your main score.
3116
3117 @example
3118 \include "event-listener.ly"
3119 @end example
3120
3121 This will create file(s) called @file{FILENAME-STAFFNAME.notes} or
3122 @file{FILENAME-unnamed-staff.notes} for each staff.  Note that if
3123 you have multiple unnamed staves, the events for all staves will
3124 be mixed together in the same file.  The output looks like this:
3125
3126 @example
3127 0.000   note     57       4   p-c 2 12
3128 0.000   dynamic  f
3129 0.250   note     62       4   p-c 7 12
3130 0.500   note     66       8   p-c 9 12
3131 0.625   note     69       8   p-c 14 12
3132 0.750   rest     4
3133 0.750   breathe
3134 @end example
3135
3136 The syntax is a tab-delimited line, with two fixed fields on each
3137 line followed by optional parameters.
3138
3139 @example
3140 @var{time}  @var{type}  @var{...params...}
3141 @end example
3142
3143 This information can easily be read into other programs such as
3144 python scripts, and can be very useful for researchers wishing to
3145 perform musical analysis or playback experiments with LilyPond.
3146
3147
3148 @knownissues
3149
3150 Not all lilypond music events are supported by
3151 @file{event-listener.ly}.  It is intended to be a well-crafted
3152 @qq{proof of concept}.  If some events that you want to see are
3153 not included, copy @file{event-listener.ly} into your lilypond
3154 directory and modify the file so that it outputs the information
3155 you want.