]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/notation/input.itely
Doc: Complete the list of on-the-fly procedures
[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.19.22"
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 * Creating 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   @dots{}
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{%@{ @dots{} %@}} 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{@dots{}music@dots{}}
137 @}
138 @end example
139
140 and texts are entered with a @code{\markup} block,
141
142 @example
143 \markup @{
144   @var{@dots{}text@dots{}}
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{@dots{}}
156 @}
157 \markup @{
158   @var{@dots{}}
159 @}
160 \score @{
161   @var{@dots{}}
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    @dots{}text of second verse@dots{}
186 @}
187 \markup @{
188    @dots{}text of third verse@dots{}
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   \paper @{ @dots{} @}
247 @}
248 \book @{
249   \score @{ @dots{} @}
250   \paper @{ @dots{} @}
251 @}
252 \book @{
253   \score @{ @dots{} @}
254   \paper @{ @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 outputs 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   \paper @{ @dots{} @}
292 @}
293 \book @{
294   \bookOutputSuffix "Menuetto"
295   \score @{ @dots{} @}
296   \paper @{ @dots{} @}
297 @}
298 \book @{
299   \bookOutputSuffix "Nocturne"
300   \score @{ @dots{} @}
301   \paper @{ @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   \paper @{ @dots{} @}
313 @}
314 \book @{
315   \bookOutputName "Menuetto"
316   \score @{ @dots{} @}
317   \paper @{ @dots{} @}
318 @}
319 \book @{
320   \bookOutputName "Nocturne"
321   \score @{ @dots{} @}
322   \paper @{ @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,,The @code{@bs{}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{%@{ @dots{} %@}}.
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
497 @item Around every opening and closing curly bracket.
498
499 @item After every command or variable, i.e., every item that
500 begins with a @code{\} sign.
501
502 @item After every item that is to be interpreted as a Scheme
503 expression, i.e., every item that begins with a @code{#}@tie{}sign.
504
505 @item To separate all elements of a Scheme expression.
506
507 @item In @code{lyricmode} before and after @code{\set} and
508 @code{\override} commands.
509
510 @end itemize
511
512 @seealso
513 Learning Manual:
514 @rlearning{How LilyPond input files work}.
515
516 Notation Reference:
517 @ref{Titles explained},
518 @ref{The layout block,,The @code{@bs{}layout} block}.
519
520
521 @node Titles and headers
522 @section Titles and headers
523
524 @cindex titles
525 @cindex headers
526 @cindex footers
527
528 Almost all printed music includes a title and the composer's name;
529 some pieces include a lot more information.
530
531 @menu
532 * Creating titles headers and footers::
533 * Custom titles headers and footers::
534 * Creating output file metadata::
535 * Creating footnotes::
536 * Reference to page numbers::
537 * Table of contents::
538 @end menu
539
540
541 @node Creating titles headers and footers
542 @subsection Creating titles headers and footers
543
544 @menu
545 * Titles explained::
546 * Default layout of bookpart and score titles::
547 * Default layout of headers and footers::
548 @end menu
549
550
551 @node Titles explained
552 @unnumberedsubsubsec Titles explained
553
554 Each @code{\book} block in a single input file produces a separate
555 output file, see @ref{File structure}.  Within each output file
556 three types of titling areas are provided: @emph{Book Titles} at the
557 beginning of each book, @emph{Bookpart Titles} at the beginning of
558 each bookpart and @emph{Score Titles} at the beginning of each score.
559
560 Values of titling fields such as @code{title} and @code{composer}
561 are set in @code{\header} blocks.  (For the syntax of @code{\header}
562 blocks and a complete list of the fields available by default see
563 @ref{Default layout of bookpart and score titles}).  Book Titles,
564 Bookpart Titles and Score Titles can all contain the same fields,
565 although by default the fields in Score Titles are limited to
566 @code{piece} and @code{opus}.
567
568 @code{\header} blocks may be placed in four different places to form
569 a descending hierarchy of @code{\header} blocks:
570
571 @itemize
572
573 @item
574 At the top of the input file, before all @code{\book},
575 @code{\bookpart}, and @code{\score} blocks.
576
577 @item
578 Within a @code{\book} block but outside all the @code{\bookpart} and
579 @code{\score} blocks within that book.
580
581 @item
582 Within a @code{\bookpart} block but outside all @code{\score} blocks
583 within that bookpart.
584
585 @item
586 After the music expression in a @code{\score} block.
587
588 @end itemize
589
590 The values of the fields filter down this hierarchy, with the values
591 set higher in the hierarchy persisting unless they are over-ridden
592 by a value set lower in the hierarchy, so:
593
594 @itemize
595
596 @item
597 A Book Title is derived from fields set at the top of the input file,
598 modified by fields set in the @code{\book} block.  The resulting
599 fields are used to print the Book Title for that book, providing that
600 there is other material which generates a page at the start of the
601 book, before the first bookpart.  A single @code{\pageBreak} will
602 suffice.
603
604 @item
605 A Bookpart Title is derived from fields set at the top of the input
606 file, modified by fields set in the @code{\book} block, and further
607 modified by fields set in the @code{\bookpart} block.  The resulting
608 values are used to print the Bookpart Title for that bookpart.
609
610 @item
611 A Score Title is derived from fields set at the top of the input
612 file, modified by fields set in the @code{\book} block, further
613 modified by fields set in the @code{\bookpart} block and finally
614 modified by fields set in the @code{\score} block.  The resulting
615 values are used to print the Score Title for that score.  Note,
616 though, that only @code{piece} and @code{opus} fields are printed
617 by default in Score Titles unless the @code{\paper} variable,
618 @code{print-all-headers}, is set to @code{#t}.
619
620 @end itemize
621
622 @warning{Remember when placing a @bs{}@code{header} block inside a
623 @bs{}@code{score} block, that the music expression must come before the
624 @bs{}@code{header} block.}
625
626 It is not necessary to provide @code{\header} blocks in all four
627 places: any or even all of them may be omitted.  Similarly, simple
628 input files may omit the @code{\book} and @code{\bookpart} blocks,
629 leaving them to be created implicitly.
630
631 If the book has only a single score, the @code{\header} block should
632 normally be placed at the top of the file so that just a Bookpart
633 Title is produced, making all the titling fields available for use.
634
635 If the book has multiple scores a number of different arrangements
636 of @code{\header} blocks are possible, corresponding to the various
637 types of musical publications.  For example, if the publication
638 contains several pieces by the same composer a @code{\header} block
639 placed at the top of the file specifying the book title and the
640 composer with @code{\header} blocks in each @code{\score} block
641 specifying the @code{piece} and/or @code{opus} would be most
642 suitable, as here:
643
644 @lilypond[papersize=a5,quote,verbatim,noragged-right]
645 \header {
646   title = "SUITE I."
647   composer = "J. S. Bach."
648 }
649
650 \score {
651   \new Staff \relative {
652     \clef bass
653     \key g \major
654     \repeat unfold 2 { g,16( d' b') a b d, b' d, } |
655     \repeat unfold 2 { g,16( e' c') b c e, c' e, } |
656   }
657   \header {
658     piece = "Prélude."
659   }
660 }
661
662 \score {
663   \new Staff \relative {
664     \clef bass
665     \key g \major
666     \partial 16 b16 |
667     <g, d' b'~>4 b'16 a( g fis) g( d e fis) g( a b c) |
668     d16( b g fis) g( e d c) b(c d e) fis( g a b) |
669   }
670   \header {
671     piece = "Allemande."
672   }
673 }
674 @end lilypond
675
676 More complicated arrangements are possible.  For example, text
677 fields from the @code{\header} block in a book can be displayed in
678 all Score Titles, with some fields over-ridden and some manually
679 suppressed:
680
681 @lilypond[papersize=a5,quote,verbatim,noragged-right]
682 \book {
683   \paper {
684     print-all-headers = ##t
685   }
686   \header {
687     title = "DAS WOHLTEMPERIRTE CLAVIER"
688     subtitle = "TEIL I"
689     % Do not display the default LilyPond footer for this book
690     tagline = ##f
691   }
692   \markup { \vspace #1 }
693   \score {
694     \new PianoStaff <<
695       \new Staff { s1 }
696       \new Staff { \clef "bass" s1 }
697     >>
698     \header {
699       title = "PRAELUDIUM I"
700       opus = "BWV 846"
701       % Do not display the subtitle for this score
702       subtitle = ##f
703     }
704   }
705   \score {
706     \new PianoStaff <<
707       \new Staff { s1 }
708       \new Staff { \clef "bass" s1 }
709     >>
710     \header {
711       title = "FUGA I"
712       subsubtitle = "A 4 VOCI"
713       opus = "BWV 846"
714       % Do not display the subtitle for this score
715       subtitle = ##f
716     }
717   }
718 }
719 @end lilypond
720
721 @seealso
722 Notation Reference:
723 @ref{File structure},
724 @ref{Default layout of bookpart and score titles},
725 @ref{Custom layout for titles}.
726
727
728 @node Default layout of bookpart and score titles
729 @unnumberedsubsubsec Default layout of bookpart and score titles
730
731 This example demonstrates all printed @code{\header} variables:
732
733 @lilypond[papersize=a6landscape,quote,verbatim,noragged-right]
734 \book {
735   \header {
736       % The following fields are centered
737     dedication = "Dedication"
738     title = "Title"
739     subtitle = "Subtitle"
740     subsubtitle = "Subsubtitle"
741       % The following fields are evenly spread on one line
742       % the field "instrument" also appears on following pages
743     instrument = \markup \with-color #green "Instrument"
744     poet = "Poet"
745     composer = "Composer"
746       % The following fields are placed at opposite ends of the same line
747     meter = "Meter"
748     arranger = "Arranger"
749       % The following fields are centered at the bottom
750     tagline = "The tagline goes at the bottom of the last page"
751     copyright = "The copyright goes at the bottom of the first page"
752   }
753   \score {
754     { s1 }
755     \header {
756         % The following fields are placed at opposite ends of the same line
757       piece = "Piece 1"
758       opus = "Opus 1"
759     }
760   }
761   \score {
762     { s1 }
763     \header {
764         % The following fields are placed at opposite ends of the same line
765       piece = "Piece 2 on the same page"
766       opus = "Opus 2"
767     }
768   }
769   \pageBreak
770   \score {
771     { s1 }
772     \header {
773         % The following fields are placed at opposite ends of the same line
774       piece = "Piece 3 on a new page"
775       opus = "Opus 3"
776     }
777   }
778 }
779 @end lilypond
780
781 Note that
782
783 @itemize
784 @item
785 The instrument name will be repeated on every page.
786
787 @item
788 Only @code{piece} and @code{opus} are printed in a @code{\score}
789 when the paper variable @code{print-all-headers} is set to
790 @code{##f} (the default).
791
792 @item
793 @c Is the bit about \null markups true? -mp
794 Text fields left unset in a @code{\header} block are replaced with
795 @code{\null} markups so that the space is not wasted.
796
797 @item
798 The default settings for @code{scoreTitleMarkup} place the @code{piece}
799 and @code{opus} text fields at opposite ends of the same line.
800
801 @end itemize
802
803 To change the default layout see @ref{Custom layout for titles}.
804
805 @cindex breakbefore
806
807 If a @code{\book} block starts immediately with a @code{\bookpart}
808 block, no Book Title will be printed, as there is no page on which
809 to print it.  If a Book Title is required, begin the @code{\book}
810 block with some markup material or a @code{\pageBreak} command.
811
812 Use the @code{breakbefore} variable inside a @code{\header} block
813 that is itself in a @code{\score} block, to make the higher-level
814 @code{\header} block titles appear on the first page on their own, with
815 the music (defined in the @code{\score} block) starting on the next.
816
817 @lilypond[papersize=c7landscape,verbatim,noragged-right]
818 \book {
819   \header {
820     title = "This is my Title"
821     subtitle = "This is my Subtitle"
822     copyright = "This is the bottom of the first page"
823   }
824   \score {
825     \repeat unfold 4 { e'' e'' e'' e'' }
826     \header {
827       piece = "This is the Music"
828       breakbefore = ##t
829     }
830   }
831 }
832 @end lilypond
833
834 @seealso
835 Learning Manual:
836 @rlearning{How LilyPond input files work},
837
838 Notation Reference:
839 @ref{Custom layout for titles},
840 @ref{File structure}.
841
842 Installed Files:
843 @file{ly/titling-init.ly}.
844
845
846 @node Default layout of headers and footers
847 @unnumberedsubsubsec Default layout of headers and footers
848
849 @emph{Headers} and @emph{footers} are lines of text appearing at
850 the top and bottom of pages, separate from the main text of a book.
851 They are controlled by the following @code{\paper} variables:
852
853 @itemize
854 @item @code{oddHeaderMarkup}
855 @item @code{evenHeaderMarkup}
856 @item @code{oddFooterMarkup}
857 @item @code{evenFooterMarkup}
858 @end itemize
859
860 These markup variables can only access text fields from top-level
861 @code{\header} blocks (which apply to all scores in the book) and are
862 defined in @file{ly/titling-init.ly}.  By default:
863
864 @itemize
865
866 @item
867 page numbers are automatically placed on the top far left (if even) or
868 top far right (if odd), starting from the second page.
869
870 @item
871 the @code{instrument} text field is placed in the center of every
872 page, starting from the second page.
873
874 @item
875 the @code{copyright} text is centered on the bottom of the first page.
876
877 @item
878 the @code{tagline} is centered on the bottom of the last page, and below
879 the @code{copyright} text if there is only a single page.
880
881 @end itemize
882
883 The default LilyPond footer text can be changed by adding a
884 @code{tagline} in the top-level @code{\header} block.
885
886 @lilypond[papersize=a8landscape,verbatim]
887 \book {
888   \header {
889     tagline = "... music notation for Everyone"
890   }
891   \score {
892     \relative {
893       c'4 d e f
894     }
895   }
896 }
897 @end lilypond
898
899 To remove the default LilyPond footer text, the @code{tagline} can be
900 set to @code{##f}.
901
902
903 @node Custom titles headers and footers
904 @subsection Custom titles headers and footers
905
906 @c TODO: somewhere put a link to header spacing info
907 @c       (you'll have to explain it more in NR 4).
908
909 @menu
910 * Custom text formatting for titles::
911 * Custom layout for titles::
912 * Custom layout for headers and footers::
913 @end menu
914
915
916 @node Custom text formatting for titles
917 @unnumberedsubsubsec Custom text formatting for titles
918
919 Standard @code{\markup} commands can be used to customize any header,
920 footer and title text within the @code{\header} block.
921
922 @lilypond[quote,verbatim,noragged-right]
923 \score {
924   { s1 }
925   \header {
926     piece = \markup { \fontsize #4 \bold "PRAELUDIUM I" }
927     opus = \markup { \italic "BWV 846" }
928   }
929 }
930 @end lilypond
931
932 @seealso
933 Notation Reference:
934 @ref{Formatting text}.
935
936
937 @node Custom layout for titles
938 @unnumberedsubsubsec Custom layout for titles
939
940 @cindex bookTitleMarkup
941 @cindex scoreTitleMarkup
942 @funindex bookTitleMarkup
943 @funindex scoreTitleMarkup
944
945 @code{\markup} commands in the @code{\header} block are useful for
946 simple text formatting, but they do not allow precise control over the
947 placement of titles.  To customize the placement of the text fields,
948 change either or both of the following @code{\paper} variables:
949
950 @itemize
951 @item @code{bookTitleMarkup}
952 @item @code{scoreTitleMarkup}
953 @end itemize
954
955 The placement of titles when using the default values of these
956 @code{\markup} variables is shown in the examples in
957 @ref{Default layout of bookpart and score titles}.
958
959 The default settings for @code{scoreTitleMarkup} as defined in
960 @file{ly/titling-init.ly} are:
961
962 @example
963 scoreTitleMarkup = \markup @{ \column @{
964   \on-the-fly \print-all-headers @{ \bookTitleMarkup \hspace #1 @}
965   \fill-line @{
966     \fromproperty #'header:piece
967     \fromproperty #'header:opus
968   @}
969 @}
970 @}
971 @end example
972
973 This places the @code{piece} and @code{opus} text fields at opposite
974 ends of the same line:
975
976 @lilypond[quote,verbatim,noragged-right]
977 \score {
978   { s1 }
979   \header {
980     piece = "PRAELUDIUM I"
981     opus = "BWV 846"
982   }
983 }
984 @end lilypond
985
986 This example redefines @code{scoreTitleMarkup} so that the @code{piece}
987 text field is centered and in a large, bold font.
988
989 @lilypond[papersize=a5,quote,verbatim,noragged-right]
990 \book {
991   \paper {
992     indent = 0\mm
993     scoreTitleMarkup = \markup {
994       \fill-line {
995         \null
996         \fontsize #4 \bold \fromproperty #'header:piece
997         \fromproperty #'header:opus
998       }
999     }
1000   }
1001   \header { tagline = ##f }
1002   \score {
1003     { s1 }
1004     \header {
1005       piece = "PRAELUDIUM I"
1006       opus = "BWV 846"
1007     }
1008   }
1009 }
1010 @end lilypond
1011
1012 Text fields not normally effective in score @code{\header} blocks
1013 can be printed in the Score Title area if @code{print-all-headers} is
1014 placed inside the @code{\paper} block.  A disadvantage of using this
1015 method is that text fields that are intended specifically for the
1016 Bookpart Title area need to be manually suppressed in every
1017 @code{\score} block.  See @ref{Titles explained}.
1018
1019 To avoid this, add the desired text field to the @code{scoreTitleMarkup}
1020 definition.  In the following example, the @code{composer} text field
1021 (normally associated with @code{bookTitleMarkup}) is added to
1022 @code{scoreTitleMarkup}, allowing each score to list a different
1023 composer:
1024
1025 @lilypond[papersize=a5,quote,verbatim,noragged-right]
1026 \book {
1027   \paper {
1028     indent = 0\mm
1029     scoreTitleMarkup = \markup {
1030       \fill-line {
1031         \null
1032         \fontsize #4 \bold \fromproperty #'header:piece
1033         \fromproperty #'header:composer
1034       }
1035     }
1036   }
1037   \header { tagline = ##f }
1038   \score {
1039     { s1 }
1040     \header {
1041       piece = "MENUET"
1042       composer = "Christian Petzold"
1043     }
1044   }
1045   \score {
1046     { s1 }
1047     \header {
1048       piece = "RONDEAU"
1049       composer = "François Couperin"
1050     }
1051   }
1052 }
1053 @end lilypond
1054
1055 It is also possible to create your own custom text fields, and refer to
1056 them in the markup definition.
1057
1058 @lilypond[papersize=a5,quote,verbatim,noragged-right]
1059 \book {
1060   \paper {
1061     indent = 0\mm
1062     scoreTitleMarkup = \markup {
1063       \fill-line {
1064         \null
1065         \override #`(direction . ,UP) {
1066           \dir-column {
1067             \center-align \fontsize #-1 \bold
1068               \fromproperty #'header:mycustomtext %% User-defined field
1069             \center-align \fontsize #4 \bold
1070               \fromproperty #'header:piece
1071           }
1072         }
1073         \fromproperty #'header:opus
1074       }
1075     }
1076   }
1077   \header { tagline = ##f }
1078   \score {
1079     { s1 }
1080     \header {
1081       piece = "FUGA I"
1082       mycustomtext = "A 4 VOCI" %% User-defined field
1083       opus = "BWV 846"
1084     }
1085   }
1086 }
1087 @end lilypond
1088
1089 @seealso
1090 Notation Reference:
1091 @ref{Titles explained}.
1092
1093
1094 @node Custom layout for headers and footers
1095 @unnumberedsubsubsec Custom layout for headers and footers
1096
1097 @c can make-header and make-footer be removed from
1098 @c paper-defaults-init.ly? -mp
1099
1100 @code{\markup} commands in the @code{\header} block are useful for
1101 simple text formatting, but they do not allow precise control over the
1102 placement of headers and footers.  To customize the placement of
1103 the text fields, use either or both of the following @code{\paper}
1104 variables:
1105
1106 @itemize
1107 @item @code{oddHeaderMarkup}
1108 @item @code{evenHeaderMarkup}
1109 @item @code{oddFooterMarkup}
1110 @item @code{evenFooterMarkup}
1111 @end itemize
1112
1113 @cindex markup, conditional
1114 @cindex on-the-fly
1115 @funindex \on-the-fly
1116
1117 The @code{\markup} command @code{\on-the-fly} can be used to add
1118 markup conditionally to header and footer text defined within the
1119 @code{\paper} block, using the following syntax:
1120
1121 @example
1122 variable = \markup @{
1123   @dots{}
1124   \on-the-fly  \@var{procedure}  @var{markup}
1125   @dots{}
1126 @}
1127 @end example
1128
1129 The @var{procedure} is called each time the @code{\markup} command
1130 in which it appears is evaluated.  The @var{procedure} should test
1131 for a particular condition and interpret (i.e., print) the
1132 @var{markup} argument if and only if the condition is true.
1133
1134 A number of ready-made procedures for testing various conditions are
1135 provided:
1136
1137 @quotation
1138 @multitable {print-page-number-check-first-----} {should this page be printed-----}
1139
1140 @headitem  Procedure name           @tab  Condition tested
1141
1142 @item print-page-number-check-first @tab  should this page number be printed?
1143 @item create-page-number-stencil    @tab  print-page-numbers true?
1144 @item print-all-headers             @tab  print-all-headers true?
1145 @item first-page                    @tab  first page in the book?
1146 @item not-first-page                @tab  not first page in the book?
1147 @item (on-page nmbr)                @tab  page number = nmbr?
1148 @item last-page                     @tab  last page in the book?
1149 @item part-first-page               @tab  first page in the book part?
1150 @item not-part-first-page           @tab  not first page in the book part?
1151 @item part-last-page                @tab  last page in the book part?
1152 @item not-single-page               @tab  pages in book part > 1?
1153
1154 @end multitable
1155 @end quotation
1156
1157 The following example centers page numbers at the bottom of every
1158 page.  First, the default settings for @code{oddHeaderMarkup} and
1159 @code{evenHeaderMarkup} are removed by defining each as a @emph{null}
1160 markup.  Then, @code{oddFooterMarkup} is redefined with the page
1161 number centered.  Finally, @code{evenFooterMarkup} is given the
1162 same layout by defining it as @code{\oddFooterMarkup}:
1163
1164 @lilypond[papersize=a8,quote,verbatim,noragged-right]
1165 \book {
1166   \paper {
1167     print-page-number = ##t
1168     print-first-page-number = ##t
1169     oddHeaderMarkup = \markup \null
1170     evenHeaderMarkup = \markup \null
1171     oddFooterMarkup = \markup {
1172       \fill-line {
1173         \on-the-fly \print-page-number-check-first
1174         \fromproperty #'page:page-number-string
1175       }
1176     }
1177     evenFooterMarkup = \oddFooterMarkup
1178   }
1179   \score {
1180     \new Staff { s1 \break s1 \break s1 }
1181   }
1182 }
1183 @end lilypond
1184
1185 Several @code{\on-the-fly} conditions can be combined with an
1186 @q{and} operation, for example,
1187
1188 @example
1189   \on-the-fly \first-page
1190   \on-the-fly \last-page
1191   @code{@{ \markup @dots{} \fromproperty #'header: @dots{} @}}
1192 @end example
1193
1194 determines if the output is a single page.
1195
1196 @seealso
1197 Notation Reference:
1198 @ref{Titles explained},
1199 @ref{Default layout of bookpart and score titles}.
1200
1201 Installed Files:
1202 @file{../ly/titling-init.ly}.
1203
1204 @node Creating output file metadata
1205 @subsection Creating output file metadata
1206
1207 @cindex PDF metadata
1208 @cindex MIDI metadata
1209
1210 In addition to being shown in the printed output, @code{\header} variables
1211 are also used to set metadata for output files.  For example, with PDF
1212 files, this metadata could be displayed by PDF readers as the
1213 @code{properties} of the PDF file.  For each type of output file, only the
1214 @code{\header} definitions of blocks that define separate files of that
1215 type, and blocks higher in the block hierarchy, will be consulted.
1216 Therefore, for PDF files, only the @code{\book} level and the top level
1217 @code{\header} definitions affect the document-wide PDF metadata, whereas
1218 for MIDI files, all headers above or at the @code{\score} level are used.
1219
1220 For example, setting the @code{title} property of the @code{header} block
1221 to @q{Symphony I} will also give this title to the PDF document, and use
1222 it as the sequence name of the MIDI file.
1223
1224 @example
1225 \header@{
1226   title = "Symphony I"
1227 @}
1228 @end example
1229
1230 If you want to set the title of the printed output to one value, but have the
1231 title property of the PDF to have a different value, you can use
1232 @code{pdftitle}, as below.
1233
1234 @example
1235 \header@{
1236   title = "Symphony I"
1237   pdftitle = "Symphony I by Beethoven"
1238 @}
1239 @end example
1240
1241 The variables @code{title}, @code{subject}, @code{keywords},
1242 @code{subtitle}, @code{composer}, @code{arranger}, @code{poet}, @code{author}
1243 and @code{copyright} all set PDF properties and can all be prefixed with
1244 @q{pdf} to set a PDF property to a value different from the printed output.
1245
1246 The PDF property @code{Creator} is automatically set to @q{LilyPond} plus
1247 the current LilyPond version, and @code{CreationDate} and @code{ModDate} are
1248 both set to the current date and time.  @code{ModDate} can be overridden by
1249 setting the header variable @code{moddate} (or @code{pdfmoddate}) to a
1250 valid PDF date string.
1251
1252 The @code{title} variable sets also the sequence name for MIDI.  The
1253 @code{midititle} variable can be used to set the sequence name
1254 independently of the value used for typeset output.
1255
1256 @node Creating footnotes
1257 @subsection Creating footnotes
1258
1259 @cindex footnotes
1260
1261 Footnotes may be used in many different situations.  In all cases,
1262 a @q{footnote mark} is placed as a reference in text or music, and
1263 the corresponding @q{footnote text} appears at the bottom of the
1264 same page.
1265
1266 Footnotes within music expressions and footnotes in stand-alone text
1267 outside music expressions are created in different ways.
1268
1269 @menu
1270 * Footnotes in music expressions::
1271 * Footnotes in stand-alone text::
1272 @end menu
1273
1274 @node Footnotes in music expressions
1275 @unnumberedsubsubsec Footnotes in music expressions
1276
1277 @cindex footnotes in music expressions
1278 @funindex \footnote
1279
1280 @subsubsubheading Music footnotes overview
1281
1282 Footnotes in music expressions fall into two categories:
1283
1284 @table @emph
1285 @item Event-based footnotes
1286 are attached to a particular event.  Examples for such events are
1287 single notes, articulations (like fingering indications, accents,
1288 dynamics), and post-events (like slurs and manual beams).  The
1289 general form for event-based footnotes is as follows:
1290
1291 @example
1292 [@var{direction}] \footnote [@var{mark}] @var{offset} @var{footnote} @var{music}
1293 @end example
1294
1295 @item Time-based footnotes
1296 are bound to a particular point of time in a musical context.  Some
1297 commands like @code{\time} and @code{\clef} don't actually use events
1298 for creating objects like time signatures and clefs.  Neither does a
1299 chord create an event of its own: its stem or flag is created at the
1300 end of a time step (nominally through one of the note events inside).
1301 Exactly which of a chord's multiple note events will be deemed the
1302 root cause of a stem or flag is undefined.  So for annotating those,
1303 time-based footnotes are preferable as well.
1304
1305 A time-based footnote allows such layout objects to be annotated
1306 without referring to an event.  The general form for Time-based
1307 footnotes is:
1308
1309 @example
1310 \footnote [@var{mark}] @var{offset} @var{footnote} [@var{Context}].@var{GrobName}
1311 @end example
1312
1313 @end table
1314
1315 The elements for both forms are:
1316
1317 @table @var
1318
1319 @item direction
1320 If (and only if) the @code{\footnote} is being applied to a
1321 post-event or articulation, it must be preceded with a direction
1322 indicator (@code{-, _, ^}) in order to attach @var{music} (with
1323 a footnote mark) to the preceding note or rest.
1324
1325 @item mark
1326 is a markup or string specifying the footnote mark which is used for
1327 marking both the reference point and the footnote itself at the
1328 bottom of the page.  It may be omitted (or equivalently replaced with
1329 @code{\default}) in which case a number in sequence will be generated
1330 automatically.  Such numerical sequences restart on each page
1331 containing a footnote.
1332
1333 @item offset
1334 is a number pair such as @samp{#(2 . 1)} specifying the X and
1335 Y@tie{}offsets in units of staff-spaces from the boundary of the
1336 object where the mark should be placed.  Positive values of the
1337 offsets are taken from the right/top edge, negative values from the
1338 left/bottom edge and zero implies the mark is centered on the edge.
1339
1340 @item Context
1341 is the context in which the grob being footnoted is created.  It
1342 may be omitted if the grob is in a bottom context, e.g., a
1343 @code{Voice} context.
1344
1345 @item GrobName
1346 specifies a type of grob to mark (like @samp{Flag}).  If it is
1347 specified, the footnote is not attached to a music expression in
1348 particular, but rather to all grobs of the type specified which
1349 occur at that moment of musical time.
1350
1351 @item footnote
1352 is the markup or string specifying the footnote text to use at the
1353 bottom of the page.
1354
1355 @item music
1356 is the music event or post-event or articulation
1357 that is being annotated.
1358
1359 @end table
1360
1361 @subsubsubheading Event-based footnotes
1362
1363 @cindex footnotes, event-based
1364
1365 A footnote may be attached to a layout object directly caused
1366 by the event corresponding to @var{music} with the syntax:
1367
1368 @example
1369 \footnote [@var{mark}] @var{offset} @var{footnote} @var{music}
1370 @end example
1371
1372 @lilypond[quote,verbatim,papersize=a8landscape]
1373 \book {
1374   \header { tagline = ##f }
1375   \relative c'' {
1376     \footnote #'(-1 . 3) "A note" a4
1377     a4
1378     \footnote #'(2 . 2) "A rest" r4
1379     a4
1380   }
1381 }
1382 @end lilypond
1383
1384 Marking a @emph{whole} chord with an event-based footnote is not
1385 possible: a chord, even one containing just a single note, does
1386 not produce an actual event of its own.  However, individual
1387 notes @emph{inside} of the chord can be marked:
1388
1389 @lilypond[quote,verbatim,papersize=a8landscape]
1390 \book {
1391   \header { tagline = ##f }
1392   \relative c'' {
1393     \footnote #'(2 . 3) "Does not work" <a-3>2
1394     <\footnote #'(-2 . -3) "Does work" a-3>4
1395     <a-3 \footnote #'(3 . 1/2) "Also works" c-5>4
1396   }
1397 }
1398 @end lilypond
1399
1400 If the footnote is to be attached to a post-event or articulation
1401 the @code{\footnote} command @emph{must} be preceded by a direction
1402 indicator, @code{-, _, ^}, and followed by the post-event or
1403 articulation to be annotated as the @var{music} argument.  In this
1404 form the @code{\footnote} can be considered to be simply a copy of
1405 its last argument with a footnote mark attached to it.  The syntax
1406 is:
1407
1408 @example
1409 @var{direction} \footnote [@var{mark}] @var{offset} @var{footnote} @var{music}
1410 @end example
1411
1412 @lilypond[quote,verbatim,papersize=a8landscape]
1413 \book {
1414   \header { tagline = ##f }
1415   \relative {
1416     a'4_\footnote #'(0 . -1) "A slur forced down" (
1417     b8^\footnote #'(1 . 0.5) "A manual beam forced up" [
1418     b8 ]
1419     c4 )
1420     c-\footnote #'(1 . 1) "Tenuto" --
1421   }
1422 }
1423 @end lilypond
1424
1425 @subsubsubheading Time-based footnotes
1426
1427 @cindex footnotes, time-based
1428
1429 If the layout object being footmarked is @emph{indirectly} caused by
1430 an event (like an @code{Accidental} or @code{Stem} caused by a
1431 @code{NoteHead} event), the @var{GrobName} of the layout object
1432 is required after the footnote text instead of @var{music}:
1433
1434 @lilypond[quote,verbatim,papersize=a8landscape]
1435 \book {
1436   \header { tagline = ##f }
1437   \relative c'' {
1438     \footnote #'(-1 . -3) "A flat" Accidental
1439     aes4 c
1440     \footnote #'(-1 . 0.5) "Another flat" Accidental
1441     ees
1442     \footnote #'(1 . -2) "A stem" Stem
1443     aes
1444   }
1445 }
1446 @end lilypond
1447
1448 Note, however, that when a GrobName is specified, a footnote
1449 will be attached to all grobs of that type at the current time step:
1450
1451 @lilypond[quote,verbatim,papersize=a8landscape]
1452 \book {
1453   \header { tagline = ##f }
1454   \relative c' {
1455     \footnote #'(-1 . 3) "A flat" Accidental
1456     <ees ges bes>4
1457     \footnote #'(2 . 0.5) "Articulation" Script
1458     c'->-.
1459   }
1460 }
1461 @end lilypond
1462
1463 A note inside of a chord can be given an individual (event-based)
1464 footnote.  A @samp{NoteHead} is the only grob directly caused
1465 from a chord note, so an event-based footnote command is
1466 @emph{only} suitable for adding a footnote to the @samp{NoteHead}
1467 within a chord.  All other chord note grobs are indirectly caused.
1468 The @code{\footnote} command itself offers no syntax for
1469 specifying @emph{both} a particular grob type @emph{as well as} a
1470 particular event to attach to.  However, one can use a time-based
1471 @code{\footnote} command for specifying the grob type, and then
1472 prefix this command with @code{\single} in order to have it
1473 applied to just the following event:
1474
1475 @lilypond[quote,verbatim,papersize=a8landscape]
1476 \book {
1477   \header { tagline = ##f }
1478   \relative c'' {
1479     < \footnote #'(1 . -2) "An A" a
1480       \single \footnote #'(-1 . -1) "A sharp" Accidental
1481       cis
1482       \single \footnote #'(0.5 . 0.5) "A flat" Accidental
1483       ees fis
1484     >2
1485   }
1486 }
1487 @end lilypond
1488
1489 @warning {When footnotes are attached to several musical elements at
1490 the same musical moment, as they are in the example above, the
1491 footnotes are numbered from the higher to the lower elements as they
1492 appear in the printed output, not in the order in which they are
1493 written in the input stream.}
1494
1495 Layout objects like clefs and key-change signatures are mostly caused
1496 as a consequence of changed properties rather than actual events.
1497 Others, like bar lines and bar numbers, are a direct consequence of
1498 timing.  For this reason, footnotes on such objects have to be based
1499 on their musical timing.  Time-based footnotes are also preferable
1500 when marking features like stems and beams on @emph{chords}: while
1501 such per-chord features are nominally assigned to @emph{one} event
1502 inside the chord, relying on a particular choice would be imprudent.
1503
1504 The layout object in question must always be explicitly specified
1505 for time-based footnotes, and the appropriate context must be
1506 specified if the grob is created in a context other than the bottom
1507 context.
1508
1509 @lilypond[quote,verbatim,papersize=a8landscape]
1510 \book {
1511   \header { tagline = ##f }
1512   \relative c'' {
1513     r1 |
1514     \footnote #'(-0.5 . -1) "Meter change" Staff.TimeSignature
1515     \time 3/4
1516     \footnote #'(1 . -1) "Chord stem" Stem
1517     <c e g>4 q q
1518     \footnote #'(-0.5 . 1) "Bar line" Staff.BarLine
1519     q q
1520     \footnote #'(0.5 . -1) "Key change" Staff.KeySignature
1521     \key c \minor
1522     q
1523   }
1524 }
1525 @end lilypond
1526
1527 Custom marks can be used as alternatives to numerical marks, and the
1528 annotation line joining the marked object to the mark can be
1529 suppressed:
1530
1531 @lilypond[quote,verbatim,papersize=a8landscape]
1532 \book {
1533   \header { tagline = ##f }
1534   \relative c' {
1535     \footnote "*" #'(0.5 . -2) \markup { \italic "* The first note" } a'4
1536     b8
1537     \footnote \markup { \super "$" } #'(0.5 . 1)
1538       \markup { \super "$" \italic " The second note" } e
1539     c4
1540     \once \override Score.FootnoteItem.annotation-line = ##f
1541     b-\footnote \markup \tiny "+" #'(0.1 . 0.1)
1542       \markup { \super "+" \italic " Editorial" } \p
1543   }
1544 }
1545 @end lilypond
1546
1547 More examples of custom marks are shown in
1548 @ref{Footnotes in stand-alone text}.
1549
1550
1551 @node Footnotes in stand-alone text
1552 @unnumberedsubsubsec Footnotes in stand-alone text
1553
1554 @cindex footnotes in stand-alone text
1555
1556 These are for use in markup outside of music expressions.  They do
1557 not have a line drawn to their point of reference: their marks simply
1558 follow the referenced markup.  Marks can be inserted automatically,
1559 in which case they are numerical.  Alternatively, custom marks can be
1560 provided manually.
1561
1562 Footnotes to stand-alone text with automatic and custom marks are
1563 created in different ways.
1564
1565 @subsubsubheading Footnotes in stand-alone text with automatic marks
1566
1567 The syntax of a footnote in stand-alone text with automatic marks is
1568
1569 @example
1570 \markup @{ @dots{} \auto-footnote @var{text} @var{footnote} @dots{} @}
1571 @end example
1572
1573 The elements are:
1574
1575 @table @var
1576
1577 @item text
1578 is the markup or string to be marked.
1579
1580 @item footnote
1581 is the markup or string specifying the footnote text to use at the bottom
1582 of the page.
1583
1584 @end table
1585
1586 For example:
1587
1588 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1589 \book {
1590   \header { tagline = ##f }
1591   \markup {
1592     "A simple"
1593     \auto-footnote "tune" \italic " By me"
1594     "is shown below.  It is a"
1595     \auto-footnote "recent" \italic " Aug 2012"
1596     "composition."
1597   }
1598   \relative {
1599     a'4 b8 e c4 d
1600   }
1601 }
1602 @end lilypond
1603
1604 @subsubsubheading Footnotes in stand-alone text with custom marks
1605
1606 The syntax of a footnote in stand-alone text with custom marks is
1607
1608 @example
1609 \markup @{ @dots{} \footnote @var{mark} @var{footnote} @dots{} @}
1610 @end example
1611
1612 The elements are:
1613
1614 @table @var
1615
1616 @item mark
1617 is a markup or string specifying the footnote mark which is used for
1618 marking the reference point.  Note that this mark is @emph{not}
1619 inserted automatically before the footnote itself.
1620
1621 @item footnote
1622 is the markup or string specifying the footnote text to use at the
1623 bottom of the page, preceded by the @var{mark}.
1624
1625 @end table
1626
1627 Any easy-to-type character such as * or + may be used as a mark, as
1628 shown in @ref{Footnotes in music expressions}.  Alteratively, ASCII
1629 aliases may be used (see @ref{ASCII aliases}):
1630
1631 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1632 \book {
1633   \paper { #(include-special-characters) }
1634   \header { tagline = ##f }
1635   \markup {
1636     "A simple tune"
1637     \footnote "*" \italic "* By me"
1638     "is shown below.  It is a recent"
1639     \footnote \super &dagger; \concat {
1640       \super &dagger; \italic " Aug 2012"
1641     }
1642     "composition."
1643   }
1644   \relative {
1645     a'4 b8 e c4 d
1646   }
1647 }
1648 @end lilypond
1649
1650 Unicode character codes may also be used to specify marks
1651 (see @ref{Unicode}):
1652
1653 @lilypond[verbatim,quote,ragged-right,papersize=a8]
1654 \book {
1655   \header { tagline = ##f }
1656   \markup {
1657     "A simple tune"
1658     \footnote \super \char##x00a7 \concat {
1659       \super \char##x00a7 \italic " By me"
1660     }
1661     "is shown below.  It is a recent"
1662     \footnote \super \char##x00b6 \concat {
1663       \super \char##x00b6 \italic " Aug 2012"
1664     }
1665     "composition."
1666   }
1667   \relative {
1668     a'4 b8 e c4 d
1669   }
1670 }
1671 @end lilypond
1672
1673 @seealso
1674 Learning Manual:
1675 @rlearning{Objects and interfaces}.
1676
1677 Notation Reference:
1678 @ref{ASCII aliases},
1679 @ref{Balloon help},
1680 @ref{List of special characters},
1681 @ref{Text marks},
1682 @ref{Text scripts},
1683 @ref{Unicode}.
1684
1685 Internals Reference:
1686 @rinternals{FootnoteEvent},
1687 @rinternals{FootnoteItem},
1688 @rinternals{FootnoteSpanner},
1689 @rinternals{Footnote_engraver}.
1690
1691 @knownissues
1692 Multiple footnotes for the same page can only be stacked, one above
1693 the other; they cannot be printed on the same line.
1694
1695 Footnotes cannot be attached to @code{MultiMeasureRests} or
1696 automatic beams or lyrics.
1697
1698 Footnote marks may collide with staves, @code{\markup} objects, other
1699 footnote marks and annotation lines.
1700
1701
1702 @node Reference to page numbers
1703 @subsection Reference to page numbers
1704
1705 A particular place of a score can be marked using the @code{\label}
1706 command, either at top-level or inside music.  This label can then be
1707 referred to in a markup, to get the number of the page where the marked
1708 point is placed, using the @code{\page-ref} markup command.
1709
1710 @lilypond[verbatim,papersize=a8landscape]
1711 \header { tagline = ##f }
1712 \book {
1713   \label #'firstScore
1714   \score {
1715     {
1716       c'1
1717       \pageBreak \mark A \label #'markA
1718       c'1
1719     }
1720   }
1721   \markup { The first score begins on page \page-ref #'firstScore "0" "?" }
1722   \markup { Mark A is on page \page-ref #'markA "0" "?" }
1723 }
1724 @end lilypond
1725
1726 The @code{\page-ref} markup command takes three arguments:
1727 @enumerate
1728 @item the label, a scheme symbol, eg. @code{#'firstScore};
1729 @item a markup that will be used as a gauge to estimate the dimensions
1730 of the markup;
1731 @item a markup that will be used in place of the page number if the label
1732 is not known;
1733 @end enumerate
1734
1735 The reason why a gauge is needed is that, at the time markups are
1736 interpreted, the page breaking has not yet occurred, so the page numbers
1737 are not yet known.  To work around this issue, the actual markup
1738 interpretation is delayed to a later time; however, the dimensions of
1739 the markup have to be known before, so a gauge is used to decide these
1740 dimensions.  If the book has between 10 and 99 pages, it may be "00",
1741 ie. a two digit number.
1742
1743
1744 @predefined
1745 @funindex \label
1746 @code{\label},
1747 @funindex \page-ref
1748 @code{\page-ref}.
1749 @endpredefined
1750
1751
1752 @node Table of contents
1753 @subsection Table of contents
1754 A table of contents is included using the
1755 @code{\markuplist \table-of-contents} command.  The elements which
1756 should appear in the table of contents are entered with the
1757 @code{\tocItem} command, which may be used either at top-level, or
1758 inside a music expression.
1759
1760 @verbatim
1761 \markuplist \table-of-contents
1762 \pageBreak
1763
1764 \tocItem \markup "First score"
1765 \score {
1766   {
1767     c'4  % ...
1768     \tocItem \markup "Some particular point in the first score"
1769     d'4  % ...
1770   }
1771 }
1772
1773 \tocItem \markup "Second score"
1774 \score {
1775   {
1776     e'4 % ...
1777   }
1778 }
1779 @end verbatim
1780
1781 Markups used for formatting the table of contents are defined in the
1782 @code{\paper} block.  There are two @q{pre-defined} markups already
1783 available;
1784
1785 @itemize
1786
1787 @item
1788 @code{tocTitleMarkup}
1789
1790 @noindent
1791 Used for formatting the title of the table of contents.
1792
1793 @verbatim
1794 tocTitleMarkup = \markup \huge \column {
1795   \fill-line { \null "Table of Contents" \null }
1796   \null
1797 }
1798 @end verbatim
1799
1800 @item
1801 @code{tocItemMarkup}
1802
1803 @noindent
1804 Used for formatting the elements within the table of contents.
1805
1806 @verbatim
1807 tocItemMarkup = \markup \fill-line {
1808   \fromproperty #'toc:text \fromproperty #'toc:page
1809 }
1810 @end verbatim
1811
1812 @end itemize
1813
1814 @noindent
1815 Both of these variables can be changed.
1816
1817 Here is an example changing the table of contents' title into French;
1818
1819 @verbatim
1820 \paper {
1821   tocTitleMarkup = \markup \huge \column {
1822     \fill-line { \null "Table des matières" \null }
1823     \hspace #1
1824   }
1825 @end verbatim
1826
1827 Here is an example changing the font-size of the elements in the table
1828 of contents;
1829
1830 @verbatim
1831 tocItemMarkup = \markup \large \fill-line {
1832   \fromproperty #'toc:text \fromproperty #'toc:page
1833 }
1834 @end verbatim
1835
1836 Note how the element text and page numbers are referred to in the
1837 @code{tocItemMarkup} definition.
1838
1839 The @code{\tocItemWithDotsMarkup} command can be included within the
1840 @code{tocItemMarkup} to fill the line, between a table of contents item
1841 and its corresponding page number, with dots;
1842
1843 @lilypond[verbatim,line-width=10.0\cm]
1844 \header { tagline = ##f }
1845 \paper {
1846   tocItemMarkup = \tocItemWithDotsMarkup
1847 }
1848
1849 \book {
1850   \markuplist \table-of-contents
1851   \tocItem \markup { Allegro }
1852   \tocItem \markup { Largo }
1853   \markup \null
1854 }
1855 @end lilypond
1856
1857 Custom commands with their own markups can also be defined to build a
1858 more complex table of contents.  In the following example, a new style
1859 is defined for entering act names in a table of contents of an opera;
1860
1861 @noindent
1862 A new markup variable (called @code{tocActMarkup}) is defined in the
1863 @code{\paper} block;
1864
1865 @verbatim
1866 \paper {
1867   tocActMarkup = \markup \large \column {
1868     \hspace #1
1869     \fill-line { \null \italic \fromproperty #'toc:text \null }
1870     \hspace #1
1871   }
1872 }
1873 @end verbatim
1874
1875 @noindent
1876 A custom music function (@code{tocAct}) is then created -- which uses
1877 the new @code{tocActMarkup} markup definition.
1878
1879 @verbatim
1880 tocAct =
1881   #(define-music-function (text) (markup?)
1882      (add-toc-item! 'tocActMarkup text))
1883 @end verbatim
1884
1885 @noindent
1886 A LilyPond input file, using these customer definitions, could look
1887 something like this;
1888
1889 @lilypond[line-width=10.0\cm]
1890 \header { tagline = ##f }
1891 \paper {
1892   tocActMarkup = \markup \large \column {
1893     \hspace #1
1894     \fill-line { \null \italic \fromproperty #'toc:text \null }
1895     \hspace #1
1896   }
1897 }
1898
1899 tocAct =
1900 #(define-music-function (text) (markup?)
1901    (add-toc-item! 'tocActMarkup text))
1902
1903 \book {
1904   \markuplist \table-of-contents
1905   \tocAct \markup { Atto Primo }
1906   \tocItem \markup { Coro. Viva il nostro Alcide }
1907   \tocItem \markup { Cesare. Presti omai l'Egizia terra }
1908   \tocAct \markup { Atto Secondo }
1909   \tocItem \markup { Sinfonia }
1910   \tocItem \markup { Cleopatra. V'adoro, pupille, saette d'Amore }
1911   \markup \null
1912 }
1913 @end lilypond
1914
1915
1916 Here is an example of the @code{\fill-with-pattern} command used within
1917 the context of a table of contents;
1918
1919 @verbatim
1920 \paper {
1921   tocItemMarkup = \markup { \fill-line {
1922     \override #'(line-width . 70)
1923     \fill-with-pattern #1.5 #CENTER . \fromproperty #'toc:text \fromproperty #'toc:page
1924     }
1925   }
1926 }
1927 @end verbatim
1928
1929 @seealso
1930 Installed Files:
1931 @file{ly/toc-init.ly}.
1932
1933 @predefined
1934 @funindex \table-of-contents
1935 @code{\table-of-contents},
1936 @funindex \tocItem
1937 @code{\tocItem}.
1938 @endpredefined
1939
1940
1941 @node Working with input files
1942 @section Working with input files
1943
1944 @menu
1945 * Including LilyPond files::
1946 * Different editions from one source::
1947 * Special characters::
1948 @end menu
1949
1950
1951 @node Including LilyPond files
1952 @subsection Including LilyPond files
1953
1954 @funindex \include
1955 @cindex including files
1956
1957 A large project may be split up into separate files.  To refer to
1958 another file, use
1959
1960 @example
1961 \include "otherfile.ly"
1962 @end example
1963
1964 The line @code{\include "otherfile.ly"} is equivalent to pasting the
1965 contents of @file{otherfile.ly} into the current file at the place
1966 where the @code{\include} appears.  For example, in a large
1967 project you might write separate files for each instrument part
1968 and create a @qq{full score} file which brings together the
1969 individual instrument files.  Normally the included file will
1970 define a number of variables which then become available
1971 for use in the full score file.  Tagged sections can be
1972 marked in included files to assist in making them usable in
1973 different places in a score, see @ref{Different editions from
1974 one source}.
1975
1976 Files in the current working directory may be referenced by
1977 specifying just the file name after the @code{\include} command.
1978 Files in other locations may be included by giving either a full
1979 path reference or a relative path reference (but use the UNIX
1980 forward slash, /, rather than the DOS/Windows back slash, \, as the
1981 directory separator.)  For example, if @file{stuff.ly} is located
1982 one directory higher than the current working directory, use
1983
1984 @example
1985 \include "../stuff.ly"
1986 @end example
1987
1988 @noindent
1989 or if the included orchestral parts files are all located in a
1990 subdirectory called @file{parts} within the current directory, use
1991
1992 @example
1993 \include "parts/VI.ly"
1994 \include "parts/VII.ly"
1995 @dots{} etc
1996 @end example
1997
1998 Files which are to be included can also contain @code{\include}
1999 statements of their own.  By default, these second-level
2000 @code{\include} statements are not interpreted until they have
2001 been brought into the main file, so the file names they specify
2002 must all be relative to the directory containing the main file,
2003 not the directory containing the included file.  However,
2004 this behavior can be changed globally by passing the option
2005 @option{-drelative-includes} option at the command line
2006 (or by adding @code{#(ly:set-option 'relative-includes #t)}
2007 at the top of the main input file).
2008
2009 When @code{relative-includes} is set to @code{#t}, the path for each
2010 @code{\include} command will be taken relative to the file containing
2011 that command.  This behavior is recommended and it will become the
2012 default behavior in a future version of lilypond.
2013
2014 Files relative to the main directory and files relative to some other
2015 directory may both be @code{\include}d by setting
2016 @code{relative-includes} to @code{#t} or @code{#f} at appropriate
2017 places in the files.  For example, if a general library, libA, has
2018 been created which itself uses sub-files which are @code{\include}d
2019 by the entry file of that library, those @code{\include} statements
2020 will need to be preceded by
2021 @code{#(ly:set-option #relative-includes #t)} so they are interpreted
2022 correctly when brought into the main @code{.ly} file, like this:
2023
2024 @example
2025 libA/
2026   libA.ly
2027   A1.ly
2028   A2.ly
2029   @dots{}
2030 @end example
2031
2032 @noindent
2033 then the entry file, @code{libA.ly}, will contain
2034
2035 @example
2036 #(ly:set-option 'relative-includes #t)
2037 \include "A1.ly"
2038 \include "A2.ly"
2039 @dots{}
2040 % return to default setting
2041 #(ly:set-option 'relative-includes #f)
2042 @end example
2043
2044 Any @file{.ly} file can then include the entire library simply with
2045
2046 @example
2047 \include "~/libA/libA.ly"
2048 @end example
2049
2050 More complex file structures may be devised by switching at
2051 appropriate places.
2052
2053 Files can also be included from a directory in a search path
2054 specified as an option when invoking LilyPond from the command
2055 line.  The included files are then specified using just their
2056 file name.  For example, to compile @file{main.ly} which includes
2057 files located in a subdirectory called @file{parts} by this method,
2058 cd to the directory containing @file{main.ly} and enter
2059
2060 @example
2061 lilypond --include=parts main.ly
2062 @end example
2063
2064 and in main.ly write
2065
2066 @example
2067 \include "VI.ly"
2068 \include "VII.ly"
2069 @dots{} etc
2070 @end example
2071
2072 Files which are to be included in many scores may be placed in
2073 the LilyPond directory @file{../ly}.  (The location of this
2074 directory is installation-dependent - see
2075 @rlearning{Other sources of information}).  These files can then
2076 be included simply by naming them on an @code{\include} statement.
2077 This is how the language-dependent files like @file{english.ly} are
2078 included.
2079
2080 LilyPond includes a number of files by default when you start
2081 the program.  These includes are not apparent to the user, but the
2082 files may be identified by running @code{lilypond --verbose} from
2083 the command line.  This will display a list of paths and files that
2084 LilyPond uses, along with much other information.  Alternatively,
2085 the more important of these files are discussed in
2086 @rlearning{Other sources of information}.  These files may be
2087 edited, but changes to them will be lost on installing a new
2088 version of LilyPond.
2089
2090 Some simple examples of using @code{\include} are shown in
2091 @rlearning{Scores and parts}.
2092
2093 @seealso
2094 Learning Manual:
2095 @rlearning{Other sources of information},
2096 @rlearning{Scores and parts}.
2097
2098 @knownissues
2099 If an included file is given a name which is the same as one in
2100 LilyPond's installation files, LilyPond's file from the
2101 installation files takes precedence.
2102
2103
2104 @node Different editions from one source
2105 @subsection Different editions from one source
2106
2107 Several methods can be used to generate different versions of a score
2108 from the same music source.  Variables are perhaps the most useful for
2109 combining lengthy sections of music and/or annotation.  Tags are more
2110 useful for selecting one section from several alternative shorter
2111 sections of music, and can also be used for splicing pieces of music
2112 together at different points.
2113
2114 Whichever method is used, separating the notation from the structure of
2115 the score will make it easier to change the structure while leaving the
2116 notation untouched.
2117
2118 @menu
2119 * Using variables::
2120 * Using tags::
2121 * Using global settings::
2122 @end menu
2123
2124 @node Using variables
2125 @unnumberedsubsubsec Using variables
2126
2127 @cindex variables, use of
2128
2129 If sections of the music are defined in variables they can be
2130 reused in different parts of the score, see @rlearning{Organizing
2131 pieces with variables}.  For example, an @notation{a cappella}
2132 vocal score frequently includes a piano reduction of the parts
2133 for rehearsal purposes which is identical to the vocal music, so
2134 the music need be entered only once.  Music from two variables
2135 may be combined on one staff, see @ref{Automatic part combining}.
2136 Here is an example:
2137
2138 @lilypond[verbatim,quote]
2139 sopranoMusic = \relative { a'4 b c b8( a) }
2140 altoMusic = \relative { e'4 e e f }
2141 tenorMusic = \relative { c'4 b e d8( c) }
2142 bassMusic = \relative { a4 gis a d, }
2143 allLyrics = \lyricmode { King of glo -- ry }
2144 <<
2145   \new Staff = "Soprano" \sopranoMusic
2146   \new Lyrics \allLyrics
2147   \new Staff = "Alto" \altoMusic
2148   \new Lyrics \allLyrics
2149   \new Staff = "Tenor" {
2150     \clef "treble_8"
2151     \tenorMusic
2152   }
2153   \new Lyrics \allLyrics
2154   \new Staff = "Bass" {
2155     \clef "bass"
2156     \bassMusic
2157   }
2158   \new Lyrics \allLyrics
2159   \new PianoStaff <<
2160     \new Staff = "RH" {
2161       \partcombine \sopranoMusic \altoMusic
2162     }
2163     \new Staff = "LH" {
2164       \clef "bass"
2165       \partcombine \tenorMusic \bassMusic
2166     }
2167   >>
2168 >>
2169 @end lilypond
2170
2171 Separate scores showing just the vocal parts or just the piano
2172 part can be produced by changing just the structural statements,
2173 leaving the musical notation unchanged.
2174
2175 For lengthy scores, the variable definitions may be placed in
2176 separate files which are then included, see @ref{Including
2177 LilyPond files}.
2178
2179 @node Using tags
2180 @unnumberedsubsubsec Using tags
2181
2182 @funindex \tag
2183 @funindex \keepWithTag
2184 @funindex \removeWithTag
2185 @cindex tag
2186 @cindex keep tagged music
2187 @cindex remove tagged music
2188
2189 The @code{\tag #'@var{partA}} command marks a music expression
2190 with the name @var{partA}.
2191 Expressions tagged in this way can be selected or filtered out by
2192 name later, using either @code{\keepWithTag #'@var{name}} or
2193 @code{\removeWithTag #'@var{name}}.  The result of applying these filters
2194 to tagged music is as follows:
2195 @multitable @columnfractions .5 .5
2196 @headitem Filter
2197   @tab Result
2198 @item
2199 Tagged music preceded by @code{\keepWithTag #'@var{name}} or
2200        @code{\keepWithTag #'(@var{name1} @var{name2}@dots{})}
2201 @tab Untagged music and music tagged with any of the given tag
2202      names is included;
2203      music tagged with any other tag name is excluded.
2204 @item
2205 Tagged music preceded by @code{\removeWithTag #'@var{name}} or
2206        @code{\removeWithTag #'(@var{name1} @var{name2}@dots{})}
2207 @tab Untagged music and music not tagged with any of the given tag names
2208      is included; music tagged with any of the given tag names is
2209      excluded.
2210 @item
2211 Tagged music not preceded by either @code{\keepWithTag} or
2212 @code{\removeWithTag}
2213 @tab All tagged and untagged music is included.
2214 @end multitable
2215
2216 The arguments of the @code{\tag}, @code{\keepWithTag} and
2217 @code{\removeWithTag} commands should be a symbol or list of
2218 symbols (such as @code{#'score} or @code{#'(violinI violinII}),
2219 followed by a music expression.  If @emph{and only if} the symbols
2220 are valid LilyPond identifiers (alphabetic characters only, no
2221 numbers, underscores, or dashes) which cannot be confused with notes,
2222 the @code{#'} may be omitted and, as a shorthand, a list of symbols
2223 can use the dot separator: i.e., @code{\tag #'(violinI violinII)} can
2224 be written @code{\tag violinI.violinII}.  The same applies to
2225 @code{\keepWithTag} and @code{\removeWithTag}.
2226
2227 In the following example, we see two versions of a piece of music,
2228 one showing trills with the usual notation, and one with trills
2229 explicitly expanded:
2230
2231 @lilypond[verbatim,quote]
2232 music = \relative {
2233   g'8. c32 d
2234   \tag #'trills { d8.\trill }
2235   \tag #'expand { \repeat unfold 3 { e32 d } }
2236   c32 d
2237  }
2238
2239 \score {
2240   \keepWithTag #'trills \music
2241 }
2242 \score {
2243   \keepWithTag #'expand \music
2244 }
2245 @end lilypond
2246
2247 @noindent
2248 Alternatively, it is sometimes easier to exclude sections of music:
2249
2250 @lilypond[verbatim,quote]
2251 music = \relative {
2252   g'8. c32 d
2253   \tag #'trills { d8.\trill }
2254   \tag #'expand {\repeat unfold 3 { e32 d } }
2255   c32 d
2256  }
2257
2258 \score {
2259   \removeWithTag #'expand
2260   \music
2261 }
2262 \score {
2263   \removeWithTag #'trills
2264   \music
2265 }
2266 @end lilypond
2267
2268 Tagged filtering can be applied to articulations, texts, etc., by
2269 prepending
2270
2271 @example
2272 -\tag #'@var{your-tag}
2273 @end example
2274
2275 to an articulation.  For example, this would define a note with a
2276 conditional fingering indication and a note with a conditional
2277 annotation:
2278
2279 @example
2280 c1-\tag #'finger ^4
2281 c1-\tag #'warn ^"Watch!"
2282 @end example
2283
2284 Multiple tags may be placed on expressions with multiple
2285 @code{\tag} entries, or by combining multiple tags into one symbol
2286 list:
2287
2288 @lilypond[quote,verbatim]
2289 music = \relative c'' {
2290   \tag #'a \tag #'both { a4 a a a }
2291   \tag #'(b both) { b4 b b b }
2292 }
2293 <<
2294 \keepWithTag #'a \music
2295 \keepWithTag #'b \music
2296 \keepWithTag #'both \music
2297 >>
2298 @end lilypond
2299
2300 Multiple @code{\removeWithTag} filters may be applied to a single
2301 music expression to remove several differently named tagged
2302 sections.  Alternatively, you can use a single @code{\removeWithTag}
2303 with a list of tags.
2304
2305 @lilypond[verbatim,quote]
2306 music = \relative c'' {
2307   \tag #'A { a4 a a a }
2308   \tag #'B { b4 b b b }
2309   \tag #'C { c4 c c c }
2310   \tag #'D { d4 d d d }
2311 }
2312 \new Voice {
2313   \removeWithTag #'B
2314   \removeWithTag #'C
2315   \music
2316   \removeWithTag #'(B C)
2317   \music
2318 }
2319 @end lilypond
2320
2321 Using two or more @code{\keepWithTag} filters on a single music
2322 expression will cause @emph{all} of the tagged sections to be removed.
2323 The first filter will remove all except the one named and any subsequent
2324 filters will remove the rest.  Using one @code{\keepWithTag} command
2325 with a list of multiple tags will only remove tagged sections that are
2326 not specified in that list.
2327
2328 @lilypond[verbatim,quote]
2329 music = \relative c'' {
2330   \tag #'violinI { a4 a a a }
2331   \tag #'violinII { b4 b b b }
2332   \tag #'viola { c4 c c c }
2333   \tag #'cello { d4 d d d }
2334 }
2335
2336 \new Staff {
2337   \keepWithTag #'(violinI violinII)
2338   \music
2339 }
2340 @end lilypond
2341
2342 @noindent
2343 will print @code{\tag}s @var{violinI} and @var{violinII} but not
2344 @var{viola} or @var{cello}.
2345
2346 @cindex tag groups
2347 @funindex \tagGroup
2348
2349 While @code{\keepWithTag} is convenient when dealing with @emph{one} set
2350 of alternatives, the removal of music tagged with @emph{unrelated} tags
2351 is problematic when using them for more than one purpose.  In that case
2352 @q{groups} of tags can be declared:
2353
2354 @example
2355 \tagGroup #'(violinI violinII viola cello)
2356 @end example
2357
2358 @noindent
2359 Now all the different tags belong to a single @q{tag group}.  Note that
2360 individual tags cannot be members of more than one @emph{tag group}.
2361
2362 @example
2363 \keepWithTag #'violinI @dots{}
2364 @end example
2365
2366 @noindent
2367 will now only show music tagged from @code{violinI}'s tag group and any
2368 music tagged with one of the @emph{other} tags will removed.
2369
2370 @lilypond[verbatim,quote]
2371 music = \relative {
2372   \tagGroup #'(violinI violinII viola cello)
2373   \tag #'violinI { c''4^"violinI" c c c }
2374   \tag #'violinII { a2 a }
2375   \tag #'viola { e8 e e2. }
2376   \tag #'cello { d'2 d4 d }
2377   R1^"untagged"
2378 }
2379
2380 \new Voice {
2381   \keepWithTag #'violinI
2382   \music
2383 }
2384 @end lilypond
2385
2386 When using the @code{\keepWithTag} command, only tags from the tag
2387 groups of the tags given in the command are visible.
2388
2389 @funindex \pushToTag
2390 @funindex \appendToTag
2391 @cindex splice into tagged music
2392
2393 Sometimes you want to splice some music at a particular place in an
2394 existing music expression.  You can use @code{\pushToTag} and
2395 @code{\appendToTag} for adding material at the front or end of the
2396 @code{elements} of an existing music construct.  Not every music
2397 construct has @code{elements}, but sequential and simultaneous music are
2398 safe bets:
2399
2400 @lilypond[verbatim,quote]
2401 music = { \tag #'here { \tag #'here <<c''>> } }
2402
2403 {
2404   \pushToTag #'here c'
2405   \pushToTag #'here e'
2406   \pushToTag #'here g' \music
2407   \appendToTag #'here c'
2408   \appendToTag #'here e'
2409   \appendToTag #'here g' \music
2410 }
2411 @end lilypond
2412
2413 Both commands get a tag, the material to splice in at every occurence of
2414 the tag, and the tagged expression.
2415
2416 @seealso
2417 Learning Manual:
2418 @rlearning{Organizing pieces with variables}.
2419
2420 Notation Reference:
2421 @ref{Automatic part combining},
2422 @ref{Including LilyPond files}.
2423
2424 @knownissues
2425 Calling @code{\relative} on a music expression obtained by filtering
2426 music through @code{\keepWithTag} or @code{\removeWithTag} might cause
2427 the octave relations to change, as only the pitches actually
2428 remaining in the filtered expression will be considered.  Applying
2429 @code{\relative} first, before @code{\keepWithTag} or
2430 @code{\removeWithTag}, avoids this danger as @code{\relative} then
2431 acts on all the pitches as-input.
2432
2433
2434 @node Using global settings
2435 @unnumberedsubsubsec Using global settings
2436
2437 @cindex include-settings
2438
2439 Global settings can be included from a separate file:
2440
2441 @example
2442 lilypond -dinclude-settings=MY_SETTINGS.ly MY_SCORE.ly
2443 @end example
2444
2445 Groups of settings such as page size, font or type face can be stored
2446 in separate files. This allows different editions from the same score
2447 as well as standard settings to be applied to many scores, simply by
2448 specifying the proper settings file.
2449
2450 This technique also works well with the use of style sheets, as
2451 discussed in @rlearning{Style sheets}.
2452
2453 @seealso
2454 Learning Manual:
2455 @rlearning{Organizing pieces with variables},
2456 @rlearning{Style sheets}.
2457
2458 Notation Reference:
2459 @ref{Including LilyPond files}.
2460
2461
2462 @node Special characters
2463 @subsection Special characters
2464
2465 @cindex special characters
2466 @cindex non-ASCII characters
2467
2468 @menu
2469 * Text encoding::
2470 * Unicode::
2471 * ASCII aliases::
2472 @end menu
2473
2474
2475 @node Text encoding
2476 @unnumberedsubsubsec Text encoding
2477
2478 @cindex UTF-8
2479
2480 LilyPond uses the character repertoire defined by the Unicode
2481 consortium and ISO/IEC 10646.  This defines a unique name and
2482 code point for the character sets used in virtually all modern
2483 languages and many others too.  Unicode can be implemented using
2484 several different encodings.  LilyPond uses the UTF-8 encoding
2485 (UTF stands for Unicode Transformation Format) which represents
2486 all common Latin characters in one byte, and represents other
2487 characters using a variable length format of up to four bytes.
2488
2489 The actual appearance of the characters is determined by the
2490 glyphs defined in the particular fonts available - a font defines
2491 the mapping of a subset of the Unicode code points to glyphs.
2492 LilyPond uses the Pango library to layout and render multi-lingual
2493 texts.
2494
2495 LilyPond does not perform any input-encoding conversions.  This
2496 means that any text, be it title, lyric text, or musical
2497 instruction containing non-ASCII characters, must be encoded in
2498 UTF-8.  The easiest way to enter such text is by using a
2499 Unicode-aware editor and saving the file with UTF-8 encoding.  Most
2500 popular modern editors have UTF-8 support, for example, vim, Emacs,
2501 jEdit, and Gedit do.  All MS Windows systems later than NT use
2502 Unicode as their native character encoding, so even Notepad can
2503 edit and save a file in UTF-8 format.  A more functional
2504 alternative for Windows is BabelPad.
2505
2506 If a LilyPond input file containing a non-ASCII character is not
2507 saved in UTF-8 format the error message
2508
2509 @example
2510 FT_Get_Glyph_Name () error: invalid argument
2511 @end example
2512
2513 will be generated.
2514
2515 Here is an example showing Cyrillic, Hebrew and Portuguese
2516 text:
2517
2518 @c NOTE: No verbatim in the following example as the code does not
2519 @c display correctly in PDF Font settings for Cyrillic and Hebrew
2520
2521 @lilypond[quote]
2522 % Linux Libertine fonts contain Cyrillic and Hebrew glyphs.
2523 \paper {
2524   #(define fonts
2525     (set-global-fonts
2526      #:roman "Linux Libertine O,serif"
2527      #:sans "Linux Biolinum O,sans-serif"
2528      #:typewriter "Linux Libertine Mono O,monospace"
2529    ))
2530 }
2531
2532 % Cyrillic
2533 bulgarian = \lyricmode {
2534   Жълтата дюля беше щастлива, че пухът, който цъфна, замръзна като гьон.
2535 }
2536
2537 % Hebrew
2538 hebrew = \lyricmode {
2539   זה כיף סתם לשמוע איך תנצח קרפד עץ טוב בגן.
2540 }
2541
2542 % Portuguese
2543 portuguese = \lyricmode {
2544   à vo -- cê uma can -- ção legal
2545 }
2546
2547 \relative {
2548   c'2 d e f g f e
2549 }
2550 \addlyrics { \bulgarian }
2551 \addlyrics { \hebrew }
2552 \addlyrics { \portuguese }
2553 @end lilypond
2554
2555
2556 @node Unicode
2557 @unnumberedsubsubsec Unicode
2558
2559 @cindex Unicode
2560
2561 To enter a single character for which the Unicode code point is
2562 known but which is not available in the editor being used, use
2563 either @code{\char ##xhhhh} or @code{\char #dddd} within a
2564 @code{\markup} block, where @code{hhhh} is the hexadecimal code for
2565 the character required and @code{dddd} is the corresponding decimal
2566 value.  Leading zeroes may be omitted, but it is usual to specify
2567 all four characters in the hexadecimal representation.  (Note that
2568 the UTF-8 encoding of the code point should @emph{not} be used
2569 after @code{\char}, as UTF-8 encodings contain extra bits indicating
2570 the number of octets.)  Unicode code charts and a character name
2571 index giving the code point in hexadecimal for any character can be
2572 found on the Unicode Consortium website,
2573 @uref{http://www.unicode.org/}.
2574
2575 For example, @code{\char ##x03BE} and @code{\char #958} would both
2576 enter the Unicode U+03BE character, which has the Unicode name
2577 @qq{Greek Small Letter Xi}.
2578
2579 Any Unicode code point may be entered in this way and if all special
2580 characters are entered in this format it is not necessary to save
2581 the input file in UTF-8 format.  Of course, a font containing all
2582 such encoded characters must be installed and available to LilyPond.
2583
2584 The following example shows Unicode hexadecimal values being entered
2585 in four places -- in a rehearsal mark, as articulation text, in
2586 lyrics and as stand-alone text below the score:
2587
2588 @lilypond[quote,verbatim]
2589 \score {
2590   \relative {
2591     c''1 \mark \markup { \char ##x03EE }
2592     c1_\markup { \tiny { \char ##x03B1 " to " \char ##x03C9 } }
2593   }
2594   \addlyrics { O \markup { \concat { Ph \char ##x0153 be! } } }
2595 }
2596 \markup { "Copyright 2008--2015" \char ##x00A9 }
2597 @end lilypond
2598
2599 @cindex copyright sign
2600
2601 To enter the copyright sign in the copyright notice use:
2602
2603 @example
2604 \header @{
2605   copyright = \markup @{ \char ##x00A9 "2008" @}
2606 @}
2607 @end example
2608
2609
2610 @node ASCII aliases
2611 @unnumberedsubsubsec ASCII aliases
2612
2613 A list of ASCII aliases for special characters can be included:
2614
2615 @lilypond[quote,verbatim]
2616 \paper {
2617   #(include-special-characters)
2618 }
2619
2620 \markup "&flqq; &ndash; &OE;uvre incomplète&hellip; &frqq;"
2621
2622 \score {
2623   \new Staff { \repeat unfold 9 a'4 }
2624   \addlyrics {
2625     This is al -- so wor -- kin'~in ly -- rics: &ndash;_&OE;&hellip;
2626   }
2627 }
2628
2629 \markup \column {
2630   "The replacement can be disabled:"
2631   "&ndash; &OE; &hellip;"
2632   \override #'(replacement-alist . ()) "&ndash; &OE; &hellip;"
2633 }
2634 @end lilypond
2635
2636 You can also make your own aliases, either globally:
2637
2638 @lilypond[quote,verbatim]
2639 \paper {
2640   #(add-text-replacements!
2641     '(("100" . "hundred")
2642       ("dpi" . "dots per inch")))
2643 }
2644 \markup "A 100 dpi."
2645 @end lilypond
2646
2647 or locally:
2648
2649 @lilypond[quote,verbatim]
2650 \markup \replace #'(("100" . "hundred")
2651                     ("dpi" . "dots per inch")) "A 100 dpi."
2652 @end lilypond
2653
2654 @seealso
2655 Notation Reference:
2656 @ref{List of special characters}.
2657
2658 Installed Files:
2659 @file{ly/text-replacements.ly}.
2660
2661
2662 @node Controlling output
2663 @section Controlling output
2664
2665 @menu
2666 * Extracting fragments of music::
2667 * Skipping corrected music::
2668 * Alternative output formats::
2669 * Replacing the notation font::
2670 @end menu
2671
2672 @funindex clip-regions
2673 @cindex Fragments, music
2674 @cindex Music fragments
2675
2676 @node Extracting fragments of music
2677 @subsection Extracting fragments of music
2678
2679 It is possible to output one or more fragments of a score by defining
2680 the explicit location of the music to be extracted within the
2681 @code{\layout} block of the input file using the @code{clip-regions}
2682 function, and then running LilyPond with the @option{-dclip-systems}
2683 option;
2684
2685 @example
2686 \layout @{
2687   clip-regions
2688   = #(list
2689       (cons
2690        (make-rhythmic-location 5 1 2)
2691        (make-rhythmic-location 7 3 4)))
2692 @}
2693 @end example
2694
2695 @noindent
2696 This example will extract a single fragment of the input file
2697 @emph{starting} after a half-note duration in fifth measure
2698 (@code{5 1 2}) and @emph{ending} after the third quarter-note in the
2699 seventh measure (@code{7 3 4}).
2700
2701 Additional fragments can be extracted by adding more pairs of
2702 @code{make-rhythmic-location} entries to the @code{clip-regions} list in
2703 the @code{\layout} block.
2704
2705 By default, each music fragment will be output as a separate @code{EPS}
2706 file, but other formats such as @code{PDF} or @code{PNG} can also be
2707 created if required.  The extracted music is output as if had been
2708 literally @q{cut} from the original printed score so if a fragment runs
2709 over one or more lines, a separate output file for each line will be
2710 generated.
2711
2712 @seealso
2713 Notation Reference:
2714 @ref{The layout block}.
2715
2716 Application Usage:
2717 @rprogram{Command-line usage}.
2718
2719
2720
2721 @node Skipping corrected music
2722 @subsection Skipping corrected music
2723
2724
2725 @funindex skipTypesetting
2726 @funindex showFirstLength
2727 @funindex showLastLength
2728
2729 When entering or copying music, usually only the music near the end (where
2730 you
2731 are adding notes) is interesting to view and correct.  To speed up
2732 this correction process, it is possible to skip typesetting of all but
2733 the last few measures.  This is achieved by putting
2734
2735 @example
2736 showLastLength = R1*5
2737 \score @{ @dots{} @}
2738 @end example
2739
2740 @noindent
2741 in your source file.  This will render only the last 5 measures
2742 (assuming 4/4 time signature) of every @code{\score} in the input
2743 file.  For longer pieces, rendering only a small part is often an order
2744 of magnitude quicker than rendering it completely.  When working on the
2745 beginning of a score you have already typeset (e.g., to add a new part),
2746 the @code{showFirstLength} property may be useful as well.
2747
2748 Skipping parts of a score can be controlled in a more fine-grained
2749 fashion with the property @code{Score.skipTypesetting}.  When it is
2750 set, no typesetting is performed at all.
2751
2752 This property is also used to control output to the MIDI file.  Note that
2753 it skips all events, including tempo and instrument changes.  You have
2754 been warned.
2755
2756 @lilypond[quote,ragged-right,verbatim]
2757 \relative c' {
2758   c1
2759   \set Score.skipTypesetting = ##t
2760   \tempo 4 = 80
2761   c4 c c c
2762   \set Score.skipTypesetting = ##f
2763   d4 d d d
2764 }
2765 @end lilypond
2766
2767 In polyphonic music, @code{Score.skipTypesetting} will affect all
2768 voices and staves, saving even more time.
2769
2770 @node Alternative output formats
2771 @subsection Alternative output formats
2772
2773 @cindex scalable vector graphics output
2774 @cindex SVG output
2775 @cindex encapsulated postscript output
2776 @cindex EPS output
2777
2778 The default output formats for the printed score are Portable
2779 Document Format (PDF) and PostScript (PS).  Portable
2780 Network Graphics (PNG), Scalable Vector Graphics (SVG) and Encapsulated
2781 PostScript (EPS) output is available through the command line option,
2782 see @rprogram{Basic command line options for LilyPond}.
2783
2784
2785 @node Replacing the notation font
2786 @subsection Replacing the notation font
2787
2788 Gonville is an alternative to the Feta font used in LilyPond and can
2789 be downloaded from:
2790 @example
2791 @uref{http://www.chiark.greenend.org.uk/~sgtatham/gonville/ ,http://www.chiark.greenend.org.uk/~sgtatham/gonville/}
2792 @end example
2793
2794 Here are a few sample bars of music set in Gonville:
2795
2796 @c NOTE: these images are a bit big, but that's important
2797 @c       for the font comparison.  -gp
2798 @sourceimage{Gonville_after,15cm,,}
2799
2800 Here are a few sample bars of music set in LilyPond's Feta font:
2801
2802 @sourceimage{Gonville_before,15cm,,}
2803
2804 @subsubheading Installation Instructions for MacOS
2805
2806 Download and extract the zip file.  Copy the @code{lilyfonts}
2807 directory to @file{@var{SHARE_DIR}/lilypond/current}; for more
2808 information, see @rlearning{Other sources of information}.  Rename the
2809 existing @code{fonts} directory to @code{fonts_orig} and the
2810 @code{lilyfonts} directory to @code{fonts}.  To revert back to Feta,
2811 reverse the process.
2812
2813 @seealso
2814 Learning Manual:
2815 @rlearning{Other sources of information}.
2816
2817 @knownissues
2818 Gonville cannot be used to typeset @q{Ancient Music} notation and it is
2819 likely newer glyphs in later releases of LilyPond may not exist in the
2820 Gonville font family.  Please refer to the author's website for more
2821 information on these and other specifics, including licensing of
2822 Gonville.
2823
2824
2825 @node Creating MIDI output
2826 @section Creating MIDI output
2827
2828 @cindex Sound
2829 @cindex MIDI
2830
2831 LilyPond can produce files that conform to the MIDI (Musical Instrument
2832 Digital Interface) standard and so allow for the checking of the music
2833 output aurally (with the help of an application or device that
2834 understands MIDI).  Listening to MIDI output may also help in spotting
2835 errors such as notes that have been entered incorrectly or are missing
2836 accidentals and so on.
2837
2838 MIDI files do not contain sound (like AAC, MP3 or Vorbis files) but
2839 require additional software to produce sound from them.
2840
2841 @menu
2842 * Supported notation for MIDI::
2843 * Unsupported notation for MIDI::
2844 * The MIDI block::
2845 * Controlling MIDI dynamics::
2846 * Using MIDI instruments::
2847 * Using repeats with MIDI::
2848 * MIDI channel mapping::
2849 * Context properties for MIDI effects::
2850 * Enhancing MIDI output::
2851 @end menu
2852
2853 @cindex MIDI, Supported notation
2854
2855 @node Supported notation for MIDI
2856 @subsection Supported notation for MIDI
2857
2858 The following musical notation can be used with LilyPond's default
2859 capabilities to produce MIDI output;
2860
2861 @itemize
2862 @item Breath marks
2863 @item Chords entered as chord names
2864 @item Crescendi, decrescendi over multiple notes.  The volume is altered
2865 linearly between the two extremes
2866 @item Dynamic markings from @code{ppppp} to @code{fffff}, including
2867 @code{mp}, @code{mf} and @code{sf}
2868 @item Microtones but @emph{not} microtonal chords.  A MIDI player that
2869 supports pitch bending will also be required.
2870 @item Lyrics
2871 @item Pitches
2872 @item Rhythms entered as note durations, including tuplets
2873 @item @q{Simple} articulations; staccato, staccatissimo, accent, marcato
2874 and portato
2875 @item Tempo changes using the @code{\tempo} function
2876 @item Ties
2877 @item Tremolos that are @emph{not} entered with a
2878 @q{@code{:}[@var{number}]} value
2879 @end itemize
2880
2881 Panning, balance, expression, reverb and chorus effects can also be
2882 controlled by setting context properties,
2883 see @ref{Context properties for MIDI effects}.
2884
2885 When combined with the @file{articulate} script the following,
2886 additional musical notation can be output to MIDI;
2887
2888 @itemize
2889 @item Appoggiaturas.  These are made to take half the value of the note
2890 following (without taking dots into account).  For example;
2891
2892 @example
2893 \appoggiatura c8 d2.
2894 @end example
2895
2896 @noindent
2897 The c will take the value of a crotchet.
2898
2899 @item Ornaments (i.e., mordents, trills and turns et al.)
2900 @item Rallentando, accelerando, ritardando and a tempo
2901 @item Slurs, including phrasing slurs
2902 @item Tenuto
2903 @end itemize
2904
2905 @noindent
2906 See @ref{Enhancing MIDI output}.
2907
2908 @cindex MIDI, Unsupported notation
2909
2910 @node Unsupported notation for MIDI
2911 @subsection Unsupported notation for MIDI
2912
2913 The following items of musical notation cannot be output to MIDI;
2914
2915 @itemize
2916 @item Articulations other than staccato, staccatissimo, accent, marcato
2917 and portato
2918 @item Crescendi and decrescendi over a @emph{single} note
2919 @item Fermata
2920 @item Figured bass
2921 @item Glissandi
2922 @item Falls and doits
2923 @item Microtonal chords
2924 @item Rhythms entered as annotations, e.g., swing
2925 @item Tempo changes without @code{\tempo} (e.g., entered as annotations)
2926 @item Tremolos that @emph{are} entered with a @q{@code{:}[@var{number}]}
2927 value
2928 @end itemize
2929
2930
2931 @node The MIDI block
2932 @subsection The MIDI block
2933
2934 @cindex MIDI block
2935
2936 To create a MIDI output file from a LilyPond input file, insert a
2937 @code{\midi} block, which can be empty, within the @code{\score} block;
2938
2939 @example
2940 \score @{
2941   @var{@dots{} music @dots{}}
2942   \layout @{ @}
2943   \midi @{ @}
2944 @}
2945 @end example
2946
2947 @warning{A @code{@bs{}score} block that, as well as the music, contains
2948 only a @code{@bs{}midi} block (i.e., @emph{without} the @code{@bs{}layout}
2949 block), will only produce MIDI output files.  No notation will be
2950 printed.}
2951
2952 The default output file extension (@code{.midi}) can be changed by using
2953 the @code{-dmidi-extension} option with the @code{lilypond} command:
2954
2955 @example
2956 lilypond -dmidi-extension=mid MyFile.ly
2957 @end example
2958
2959 Alternatively, add the following Scheme expression before the start of
2960 either the @code{\book}, @code{\bookpart} or @code{\score} blocks.  See
2961 @ref{File structure}.
2962
2963 @example
2964 #(ly:set-option 'midi-extension "mid")
2965 @end example
2966
2967 @seealso
2968 Notation Reference:
2969 @ref{File structure},
2970 @ref{Creating output file metadata}.
2971
2972 Installed Files:
2973 @file{scm/midi.scm}.
2974
2975 @knownissues
2976 There are fifteen MIDI channels available and one additional channel
2977 (#10) for drums.  Staves are assigned to channels in sequence, so a
2978 score that contains more than fifteen staves will result in the extra
2979 staves sharing (but not overwriting) the same MIDI channel.  This may be
2980 a problem if the sharing staves have conflicting, channel-based, MIDI
2981 properties -- such as different MIDI instruments -- set.
2982
2983
2984 @node Controlling MIDI dynamics
2985 @subsection Controlling MIDI dynamics
2986
2987 It is possible to control the overall MIDI volume, the relative volume
2988 of dynamic markings and the relative volume of different instruments.
2989
2990 Dynamic marks translate automatically into volume levels in the
2991 available MIDI volume range whereas crescendi and decrescendi vary the
2992 volume linearly between their two extremes.  It is possible to control
2993 the relative volume of dynamic markings, and the overall volume levels
2994 of different instruments.
2995
2996 @menu
2997 * Dynamic marks in MIDI::
2998 * Setting MIDI volume::
2999 * Setting MIDI block properties::
3000 @end menu
3001
3002 @cindex MIDI volume
3003 @cindex MIDI equalization
3004 @cindex MIDI dynamics
3005 @cindex Dynamics in MIDI
3006
3007
3008 @node Dynamic marks in MIDI
3009 @unnumberedsubsubsec Dynamic marks in MIDI
3010
3011 Only the dynamic markings from @code{ppppp} to @code{fffff}, including
3012 @code{mp}, @code{mf} and @code{sf} have values assigned to them.  This
3013 value is then applied to the value of the overall MIDI volume range to
3014 obtain the final volume included in the MIDI output for that particular
3015 dynamic marking.  The default fractions range from 0.25 for
3016 @notation{ppppp} to 0.95 for @notation{fffff}. The complete set of
3017 dynamic marks and their associated fractions can be found in
3018 @file{scm/midi.scm}.
3019
3020
3021 @snippets
3022 @lilypondfile[verbatim,quote,ragged-right,texidoc,doctitle]
3023 {creating-custom-dynamics-in-midi-output.ly}
3024
3025 Installed Files:
3026 @file{ly/script-init.ly}
3027 @file{scm/midi.scm}.
3028
3029 Snippets:
3030 @rlsr{MIDI}.
3031
3032 Internals Reference:
3033 @rinternals{Dynamic_performer}.
3034
3035
3036 @node Setting MIDI volume
3037 @unnumberedsubsubsec Setting MIDI volume
3038
3039 The minimum and maximum overall volume of MIDI dynamic markings is
3040 controlled by setting the properties @code{midiMinimumVolume} and
3041 @code{midiMaximumVolume} at the @code{Score} level.  These properties
3042 have an effect only at the start of a voice and on dynamic marks.  The
3043 fraction corresponding to each dynamic mark is modified with this
3044 formula
3045
3046 @example
3047 midiMinimumVolume + (midiMaximumVolume - midiMinimumVolume) * fraction
3048 @end example
3049
3050 In the following example the dynamic range of the overall MIDI
3051 volume is limited to the range @code{0.2} - @code{0.5}.
3052
3053 @example
3054 \score @{
3055   <<
3056     \new Staff @{
3057       \set Staff.midiInstrument = #"flute"
3058       @var{@dots{} music @dots{}}
3059     @}
3060     \new Staff @{
3061       \set Staff.midiInstrument = #"clarinet"
3062       @var{@dots{} music @dots{}}
3063     @}
3064   >>
3065   \midi @{
3066     \context @{
3067       \Score
3068       midiMinimumVolume = #0.2
3069       midiMaximumVolume = #0.5
3070     @}
3071   @}
3072 @}
3073 @end example
3074
3075 Simple MIDI instrument equalization can be achieved by setting
3076 @code{midiMinimumVolume} and @code{midiMaximumVolume} properties within
3077 the @code{Staff} context.
3078
3079 @example
3080 \score @{
3081   \new Staff @{
3082     \set Staff.midiInstrument = #"flute"
3083     \set Staff.midiMinimumVolume = #0.7
3084     \set Staff.midiMaximumVolume = #0.9
3085     @var{@dots{} music @dots{}}
3086   @}
3087   \midi @{ @}
3088 @}
3089 @end example
3090
3091 For scores with multiple staves and multiple MIDI instruments, the
3092 relative volumes of each instrument can be set individually;
3093
3094 @example
3095 \score @{
3096   <<
3097     \new Staff @{
3098       \set Staff.midiInstrument = #"flute"
3099       \set Staff.midiMinimumVolume = #0.7
3100       \set Staff.midiMaximumVolume = #0.9
3101       @var{@dots{} music @dots{}}
3102     @}
3103     \new Staff @{
3104       \set Staff.midiInstrument = #"clarinet"
3105       \set Staff.midiMinimumVolume = #0.3
3106       \set Staff.midiMaximumVolume = #0.6
3107       @var{@dots{} music @dots{}}
3108     @}
3109   >>
3110   \midi @{ @}
3111 @}
3112 @end example
3113
3114 In this example the volume of the clarinet is reduced relative to the
3115 volume of the flute.
3116
3117 If these volumes properties are not set then LilyPond still applies a
3118 @q{small degree} of equalization to certain instruments.  See
3119 @file{scm/midi.scm}.
3120
3121 Installed Files:
3122 @file{scm/midi.scm}.
3123
3124 @seealso
3125 Notation Reference:
3126 @ref{Score layout}.
3127
3128 Internals Reference:
3129 @rinternals{Dynamic_performer}.
3130
3131 @snippets
3132 @lilypondfile[verbatim,quote,ragged-right,texidoc,doctitle]
3133 {replacing-default-midi-instrument-equalization.ly}
3134
3135 @knownissues
3136 Changes in the MIDI volume take place only on starting a note, so
3137 crescendi and decrescendi cannot affect the volume of a single note.
3138
3139
3140 @node Setting MIDI block properties
3141 @unnumberedsubsubsec Setting MIDI block properties
3142
3143 The @code{\midi} block can contain context rearrangements, new context
3144 definitions or code that sets the values of certain properties.
3145
3146 @example
3147 \score @{
3148   @var{@dots{} music @dots{}}
3149   \midi @{
3150     \tempo 4 = 72
3151   @}
3152 @}
3153 @end example
3154
3155 Here the tempo is set to 72 quarter-note beats per minute.  The tempo
3156 mark in the @code{\midi} block will not appear in the printed score.
3157 Although any other @code{\tempo} indications specified within the
3158 @code{\score} block will also be reflected in the MIDI output.
3159
3160 In a @code{\midi} block the @code{\tempo} command is setting properties
3161 during the interpretation of the music and in the context of output
3162 definitions; so it is interpreted @emph{as if} it were a context
3163 modification.
3164
3165 @cindex MIDI context definitions
3166 @cindex context definitions with MIDI
3167
3168 Context definitions follow the same syntax as those in a @code{\layout}
3169 block;
3170
3171 @example
3172 \score @{
3173   @var{@dots{} music @dots{}}
3174   \midi @{
3175     \context @{
3176       \Voice
3177       \remove "Dynamic_performer"
3178     @}
3179   @}
3180 @}
3181 @end example
3182
3183 This example removes the effect of dynamics from the MIDI output.  Note:
3184 LilyPond's translation modules used for sound are called @q{performers}.
3185
3186 @seealso
3187 Learning Manual:
3188 @rlearning{Other sources of information}.
3189
3190 Notation Reference:
3191 @ref{Expressive marks},
3192 @ref{Score layout}.
3193
3194 Installed Files:
3195 @file{ly/performer-init.ly}.
3196
3197 Snippets:
3198 @rlsr{MIDI}.
3199
3200 Internals Reference:
3201 @rinternals{Dynamic_performer}.
3202
3203 @knownissues
3204 Some MIDI players do not always correctly handle tempo changes in the
3205 midi output.
3206
3207 Changes to the @code{midiInstrument}, as well as some MIDI options, at
3208 the @emph{beginning} of a staff may appear twice in the MIDI output.
3209
3210
3211
3212 @node Using MIDI instruments
3213 @subsection Using MIDI instruments
3214
3215 MIDI instruments are set using the @code{midiInstrument} property within
3216 a @code{Staff} context.
3217
3218 @example
3219 \score @{
3220   \new Staff @{
3221     \set Staff.midiInstrument = #"glockenspiel"
3222     @var{@dots{} music @dots{}}
3223   @}
3224   \midi @{ @}
3225 @}
3226 @end example
3227
3228 or
3229
3230 @example
3231 \score @{
3232   \new Staff \with @{midiInstrument = #"cello"@} @{
3233     @var{@dots{} music @dots{}}
3234   @}
3235   \midi @{ @}
3236 @}
3237 @end example
3238
3239 If the instrument name does not match any of the instruments listed in
3240 the @q{MIDI instruments} section, the @code{acoustic grand} instrument
3241 will be used instead. See @ref{MIDI instruments}.
3242
3243 @seealso
3244 Learning Manual:
3245 @rlearning{Other sources of information}.
3246
3247 Notation Reference:
3248 @ref{MIDI instruments},
3249 @ref{Score layout}.
3250
3251 Installed Files:
3252 @file{scm/midi.scm}.
3253
3254 @knownissues
3255 Percussion instruments that are notated in a @code{DrumStaff}
3256 context will be output, correctly, to MIDI channel@tie{}10 but some
3257 pitched, percussion instruments like the xylophone, marimba, vibraphone
3258 or timpani, are treated as @qq{normal} instruments so the music for
3259 these should be entered in a @code{Staff} (not @code{DrumStaff}) context
3260 to obtain correct MIDI output.  A full list of
3261 @code{channel 10 drum-kits} entries can be found in @file{scm/midi.scm}.
3262 See @rlearning{Other sources of information}.
3263
3264
3265 @node Using repeats with MIDI
3266 @subsection Using repeats with MIDI
3267
3268 @cindex repeats in MIDI
3269 @cindex MIDI using repeats
3270 @funindex \unfoldRepeats
3271
3272 Repeats can be represented in the MIDI output by applying the
3273 @code{\unfoldRepeats} command.
3274
3275 @example
3276 \score @{
3277   \unfoldRepeats @{
3278     \repeat tremolo 8 @{ c'32 e' @}
3279     \repeat percent 2 @{ c''8 d'' @}
3280     \repeat volta 2 @{ c'4 d' e' f' @}
3281     \alternative @{
3282       @{ g' a' a' g' @}
3283       @{ f' e' d' c' @}
3284     @}
3285   @}
3286   \midi @{ @}
3287 @}
3288 @end example
3289
3290 In order to restrict the effect of @code{\unfoldRepeats} to the MIDI
3291 output only, while also generating printable scores, it is necessary to
3292 make @emph{two} @code{\score} blocks; one for MIDI (with unfolded
3293 repeats) and one for the notation (with volta, tremolo, and percent
3294 repeats);
3295
3296 @example
3297 \score @{
3298   @var{@dots{} music @dots{}}
3299   \layout @{ @}
3300 @}
3301 \score @{
3302   \unfoldRepeats @{
3303     @var{@dots{} music @dots{}}
3304   @}
3305   \midi @{ @}
3306 @}
3307 @end example
3308
3309 When using multiple voices, each of the voices must contain completely
3310 unfolded repeats for correct MIDI output.
3311
3312 @seealso
3313 Notation Reference:
3314 @ref{Repeats}.
3315
3316
3317 @node MIDI channel mapping
3318 @subsection MIDI channel mapping
3319
3320 @cindex MIDI Channels
3321 @cindex MIDI Tracks
3322 @funindex midiChannelMapping
3323
3324 When generating a MIDI file from a score, LilyPond will automatically
3325 assign every note in the score to a MIDI channel, the one on which it
3326 should be played when it is sent to a MIDI device.  A MIDI channel has
3327 a number of controls available to select, for example, the instrument
3328 to be used to play the notes on that channel, or to request the MIDI
3329 device to apply various effects to the sound produced on the channel.
3330 At all times, every control on a MIDI channel can have only a single
3331 value assigned to it (which can be modified, however, for example,
3332 to switch to another instrument in the middle of a score).
3333
3334 The MIDI standard supports only 16 channels per MIDI device.  This
3335 limit on the number of channels also limits the number of different
3336 instruments which can be played at the same time.
3337
3338 LilyPond creates separate MIDI tracks for each staff, (or discrete
3339 instrument or voice, depending on the value of
3340 @code{Score.midiChannelMapping}), and also for each lyrics context.
3341 There is no limit to the number of tracks.
3342
3343 To work around the limited number of MIDI channels, LilyPond supports
3344 a number of different modes for MIDI channel allocation, selected using
3345 the @code{Score.midiChannelMapping} context property.  In each case,
3346 if more MIDI channels than the limit are required, the allocated
3347 channel numbers wrap around back to 0, possibly causing the incorrect
3348 assignment of instruments to some notes.  This context property can be
3349 set to one of the following values:
3350
3351 @table @var
3352
3353 @item @code{'staff}
3354
3355 Allocate a separate MIDI channel to each staff in the score (this is
3356 the default).  All notes in all voices contained within each staff will
3357 share the MIDI channel of their enclosing staff, and all are encoded
3358 in the same MIDI track.
3359
3360 The limit of 16 channels is applied to the total number of staff and
3361 lyrics contexts, even though MIDI lyrics do not take up a MIDI channel.
3362
3363 @item @code{'instrument}
3364
3365 Allocate a separate MIDI channel to each distinct MIDI instrument
3366 specified in the score.  This means that all the notes played with the
3367 same MIDI instrument will share the same MIDI channel (and track), even
3368 if the notes come from different voices or staves.
3369
3370 In this case the lyrics contexts do not count towards the MIDI channel
3371 limit of 16 (as they will not be assigned to a MIDI instrument), so
3372 this setting may allow a better allocation of MIDI channels when the
3373 number of staves and lyrics contexts in a score exceeds 16.
3374
3375 @item @code{'voice}
3376
3377 Allocate a separate MIDI channel to each voice in the score that has a
3378 unique name among the voices in its enclosing staff.  Voices in
3379 different staves are always assigned separate MIDI channels, but any two
3380 voices contained within the same staff will share the same MIDI channel
3381 if they have the same name.  Because @code{midiInstrument} and the
3382 several MIDI controls for effects are properties of the staff context,
3383 they cannot be set separately for each voice.  The first voice will be
3384 played with the instrument and effects specified for the staff, and
3385 voices with a different name from the first will be assigned the default
3386 instrument and effects.
3387
3388 Note: different instruments and/or effects can be assigned to several
3389 voices on the same staff by moving the @code{Staff_performer} from the
3390 @code{Staff} to the @code{Voice} context, and leaving
3391 @code{midiChannelMapping} to default to @code{'staff} or set to
3392 @code{'instrument}; see the snippet below.
3393
3394 @end table
3395
3396 For example, the default MIDI channel mapping of a score can be changed
3397 to the @code{'instrument} setting as shown:
3398
3399 @example
3400 \score @{
3401   ...music...
3402   \midi @{
3403     \context @{
3404       \Score
3405       midiChannelMapping = #'instrument
3406     @}
3407   @}
3408 @}
3409 @end example
3410
3411 @snippets
3412 @lilypondfile[verbatim,quote,ragged-right,texidoc,doctitle]
3413 {changing-midi-output-to-one-channel-per-voice.ly}
3414
3415
3416 @node Context properties for MIDI effects
3417 @subsection Context properties for MIDI effects
3418
3419 @cindex Effects in MIDI
3420 @cindex Pan position in MIDI
3421 @cindex Stereo balance in MIDI
3422 @cindex Balance in MIDI
3423 @cindex Expression in MIDI
3424 @cindex Reverb in MIDI
3425 @cindex Chorus level in MIDI
3426 @funindex midiPanPosition
3427 @funindex midiBalance
3428 @funindex midiExpression
3429 @funindex midiReverbLevel
3430 @funindex midiChorusLevel
3431
3432 The following context properties can be used to apply various MIDI
3433 effects to notes played on the MIDI channel associated with the
3434 current staff, MIDI instrument or voice (depending on the value of the
3435 @code{Score.midiChannelMapping} context property and the context in
3436 which the @code{Staff_performer} is located; see
3437 @ref{MIDI channel mapping}).
3438
3439 Changing these context properties will affect all notes played on the
3440 channel after the change, however some of the effects may even apply
3441 also to notes which are already playing (depending on the
3442 implementation of the MIDI output device).
3443
3444 The following context properties are supported:
3445
3446 @table @var
3447
3448 @item @code{Staff.midiPanPosition}
3449
3450 The pan position controls how the sound on a MIDI channel is
3451 distributed between left and right stereo outputs.  The context
3452 property accepts a number between -1.0 (@code{#LEFT}) and 1.0
3453 (@code{#RIGHT}); the value -1.0 will put all sound power to the left
3454 stereo output (keeping the right output silent), the value 0.0
3455 (@code{#CENTER}) will distribute the sound evenly between the left and
3456 right stereo outputs, and the value 1.0 will move all sound to the
3457 right stereo output.  Values between -1.0 and 1.0 can be used to obtain
3458 mixed distributions between left and right stereo outputs.
3459
3460 @item @code{Staff.midiBalance}
3461
3462 The stereo balance of a MIDI channel.  Similarly to the pan position,
3463 this context property accepts a number between -1.0 (@code{#LEFT}) and
3464 1.0 (@code{#RIGHT}).  It varies the relative volume sent to the two
3465 stereo speakers without affecting the distribution of the stereo
3466 signals.
3467
3468 @item @code{Staff.midiExpression}
3469
3470 Expression level (as a fraction of the maximum available level) to
3471 apply to a MIDI channel.  A MIDI device combines the MIDI channel's
3472 expression level with a voice's current dynamic level (controlled using
3473 constructs such as @code{\p} or @code{\ff}) to obtain the total volume
3474 of each note within the voice.  The expression control could be used, for
3475 example, to implement crescendo or decrescendo effects over single
3476 sustained notes (not supported automatically by LilyPond).
3477
3478 @c Issue 4059 contains an attached snippet which shows how this might
3479 @c be done, but this is too large and complex for the NR, even as a
3480 @c referenced snippet.  It could be added to the LSR.
3481
3482 The expression level ranges from 0.0 (no expression, meaning zero
3483 volume) to 1.0 (full expression).
3484
3485 @item @code{Staff.midiReverbLevel}
3486
3487 Reverb level (as a fraction of the maximum available level) to apply
3488 to a MIDI channel.  This property accepts numbers between 0.0 (no
3489 reverb) and 1.0 (full effect).
3490
3491 @item @code{Staff.midiChorusLevel}
3492
3493 Chorus level (as a fraction of the maximum available level) to apply to
3494 a MIDI channel.  This property accepts numbers between 0.0 (no chorus
3495 effect) and 1.0 (full effect).
3496
3497 @end table
3498
3499
3500 @knownissues
3501
3502 As MIDI files do not contain any actual audio data, changes in these
3503 context properties translate only to requests for changing MIDI channel
3504 controls in the outputted MIDI files.  Whether a particular MIDI device
3505 (such as a software MIDI player) can actually handle any of these
3506 requests in a MIDI file is entirely up to the implementation of the
3507 device: a device may choose to ignore some or all of these requests.
3508 Also, how a MIDI device will interpret different values for these
3509 controls (generally, the MIDI standard fixes the behavior only at the
3510 endpoints of the value range available for each control), and whether a
3511 change in the value of a control will affect notes already playing on
3512 that MIDI channel or not, is also specific to the MIDI device
3513 implementation.
3514
3515 When generating MIDI files, LilyPond will simply transform the
3516 fractional values within each range linearly into values in a
3517 corresponding (7-bit, or 14-bit for MIDI channel controls which support
3518 fine resolution) integer range (0-127 or 0-32767, respectively),
3519 rounding fractional values towards the nearest integer away from zero.
3520 The converted integer values are stored as-is in the generated MIDI
3521 file.  Please consult the documentation of your MIDI device for
3522 information about how the device interprets these values.
3523
3524
3525 @node Enhancing MIDI output
3526 @subsection Enhancing MIDI output
3527
3528 @menu
3529 * The articulate script::
3530 @end menu
3531
3532 The default MIDI output is basic but can be improved by setting MIDI
3533 instruments, @code{\midi} block properties and/or using the
3534 @file{articulate} script.
3535
3536 @cindex instrument names
3537 @cindex MIDI, instruments
3538 @cindex articulate script
3539 @cindex articulate.ly
3540 @funindex Staff.midiInstrument
3541
3542
3543 @node The articulate script
3544 @unnumberedsubsubsec The @file{articulate} script
3545
3546 To use the @file{articulate} script add the appropriate @code{\include}
3547 command at the top of the input file;
3548
3549 @example
3550 \include "articulate.ly"
3551 @end example
3552
3553 The script creates MIDI output into appropriately @q{time-scaled} notes
3554 to match many articulation and tempo indications.  Engraved output
3555 however, will also be altered to literally match the MIDI output.
3556
3557 @example
3558 \score @{
3559   \articulate <<
3560     @var{@dots{} music @dots{}}
3561   >>
3562   \midi @{ @}
3563 @}
3564 @end example
3565
3566 The @code{\articulate} command enables abbreviatures (such as trills and
3567 turns) to be processed.  A full list of supported items can be found in
3568 the script itself.  See @file{ly/articulate.ly}.
3569
3570 @seealso
3571 Learning Manual:
3572 @rlearning{Other sources of information}.
3573
3574 Notation Reference:
3575 @ref{Score layout}.
3576
3577 Installed Files:
3578 @file{ly/articulate.ly}.
3579
3580 @warning{The @file{articulate} script may shorten chords, which might
3581 not be appropriate for some types of instrument, such as organ music.
3582 Notes that do not have any articulations attached to them may also be
3583 shortened; so to allow for this, restrict the use of the
3584 @code{\articulate} function to shorter segments of music, or modify the
3585 values of the variables defined in the @file{articulate} script to
3586 compensate for the note-shortening behavior.}
3587
3588
3589
3590 @node Extracting musical information
3591 @section Extracting musical information
3592
3593 In addition to creating graphical output and MIDI, LilyPond can
3594 display musical information as text.
3595
3596 @menu
3597 * Displaying LilyPond notation::
3598 * Displaying scheme music expressions::
3599 * Saving music events to a file::
3600 @end menu
3601
3602 @node Displaying LilyPond notation
3603 @subsection Displaying LilyPond notation
3604
3605 @funindex \displayLilyMusic
3606 Displaying a music expression in LilyPond notation can be
3607 done with the music function @code{\displayLilyMusic}.  To see the
3608 output, you will typically want to call LilyPond using the command
3609 line.  For example,
3610
3611 @example
3612 @{
3613   \displayLilyMusic \transpose c a, @{ c4 e g a bes @}
3614 @}
3615 @end example
3616
3617 will display
3618
3619 @example
3620 @{ a,4 cis4 e4 fis4 g4 @}
3621 @end example
3622
3623 By default, LilyPond will print these messages to the console
3624 along with all the other LilyPond compilation messages.  To split
3625 up these messages and save the results of @code{\displayLilyMusic},
3626 redirect the output to a file.
3627
3628 @example
3629 lilypond file.ly >display.txt
3630 @end example
3631
3632 @funindex \void
3633 Note that LilyPond does not just display the music expression, but
3634 also interprets it (since @code{\displayLilyMusic} returns it in
3635 addition to displaying it).  Just insert @code{\displayLilyMusic} into
3636 the existing music in order to get information about it.
3637
3638 To interpret and display a music section in the console but, at the same
3639 time, remove it from the output file use the @code{\void} command.
3640
3641 @example
3642 @{
3643   \void \displayLilyMusic \transpose c a, @{ c4 e g a bes @}
3644   c1
3645 @}
3646 @end example
3647
3648
3649 @node Displaying scheme music expressions
3650 @subsection Displaying scheme music expressions
3651
3652 See @rextend{Displaying music expressions}.
3653
3654
3655 @node Saving music events to a file
3656 @subsection Saving music events to a file
3657
3658 Music events can be saved to a file on a per-staff basis by
3659 including a file in your main score.
3660
3661 @example
3662 \include "event-listener.ly"
3663 @end example
3664
3665 This will create file(s) called @file{FILENAME-STAFFNAME.notes} or
3666 @file{FILENAME-unnamed-staff.notes} for each staff.  Note that if
3667 you have multiple unnamed staves, the events for all staves will
3668 be mixed together in the same file.  The output looks like this:
3669
3670 @example
3671 0.000   note     57       4   p-c 2 12
3672 0.000   dynamic  f
3673 0.250   note     62       4   p-c 7 12
3674 0.500   note     66       8   p-c 9 12
3675 0.625   note     69       8   p-c 14 12
3676 0.750   rest     4
3677 0.750   breathe
3678 @end example
3679
3680 The syntax is a tab-delimited line, with two fixed fields on each
3681 line followed by optional parameters.
3682
3683 @example
3684 @var{time}  @var{type}  @var{@dots{}params@dots{}}
3685 @end example
3686
3687 This information can easily be read into other programs such as
3688 python scripts, and can be very useful for researchers wishing to
3689 perform musical analysis or playback experiments with LilyPond.
3690
3691
3692 @knownissues
3693
3694 Not all lilypond music events are supported by
3695 @file{event-listener.ly}.  It is intended to be a well-crafted
3696 @qq{proof of concept}.  If some events that you want to see are
3697 not included, copy @file{event-listener.ly} into your lilypond
3698 directory and modify the file so that it outputs the information
3699 you want.