]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/input.itely
partial update of text, fixes doc build
[lilypond.git] / Documentation / user / input.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
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.  See TRANSLATION for details.
8 @end ignore
9
10 @c \version "2.11.38"
11
12 @node Input syntax
13 @chapter Input syntax
14
15 This section deals with general LilyPond input syntax issues,
16 rather than specific notation.
17
18 FIXME: don't complain about anything in this chapter.  It's still
19 under heavy development.
20
21 @menu
22 * Input structure::             
23 * Useful concepts and properties::  
24 * Titles and headers::          
25 * Working with input files::    
26 * Controlling output::          
27 * MIDI output::                 
28 @end menu
29
30
31 @node Input structure
32 @section Input structure
33
34 The main format of input for LilyPond are text files.  By convention,
35 these files end with @code{.ly}.
36
37 @menu
38 * Structure of a score::        
39 * Multiple scores in a book::   
40 * File structure::              
41 @end menu
42
43
44 @node Structure of a score
45 @subsection Structure of a score
46
47 @funindex \score
48
49 A @code{\score} block must contain a single music expression
50 delimited by curly brackets:
51
52 @example
53 \score @{
54 ...
55 @}
56 @end example
57
58 @warning{There must be @strong{only one} outer music expression in
59 a @code{\score} block, and it @strong{must} be surrounded by
60 curly brackets.}
61
62 This single music expression may be of any size, and may contain
63 other music expressions to any complexity.  All of these examples
64 are music expressions:
65
66 @example
67 @{ c'4 c' c' c' @}
68 @end example
69
70 @lilypond[verbatim,quote]
71 {
72   { c'4 c' c' c'}
73   { d'4 d' d' d'}
74 }
75 @end lilypond
76
77 @lilypond[verbatim,quote]
78 <<
79   \new Staff { c'4 c' c' c' }
80   \new Staff { d'4 d' d' d' }
81 >>
82 @end lilypond
83
84 @example
85 @{
86   \new GrandStaff <<
87     \new StaffGroup <<
88       \new Staff @{ \flute @}
89       \new Staff @{ \oboe @}
90     >>
91     \new StaffGroup <<
92       \new Staff @{ \violinI @}
93       \new Staff @{ \violinII @}
94     >>
95   >>
96 @}
97 @end example
98
99 Comments are one exception to this general rule.  (For others see
100 @ref{File structure}.)  Both single-line comments and comments
101 delimited by @code{%@{ .. %@}} may be placed anywhere within an
102 input file.  They may be placed inside or outside a @code{\score}
103 block, and inside or outside the single music expression within a
104 @code{\score} block.
105
106 @seealso
107
108 Learning Manual:
109
110 @rlearning{Working on input files},
111 @rlearning{Music expressions explained},
112 @rlearning{Score is a (single) compound musical expression}.
113
114
115 @node Multiple scores in a book
116 @subsection Multiple scores in a book
117
118 @funindex \book
119 @cindex movements, multiple
120
121 A document may contain multiple pieces of music and text.  Examples
122 of these are an etude book, or an orchestral part with multiple
123 movements.  Each movement is entered with a @code{\score} block,
124
125 @example
126 \score @{
127   @var{..music..}
128 @}
129 @end example
130
131 and texts are entered with a @code{\markup} block,
132
133 @example
134 \markup @{
135   @var{..text..}
136 @}
137 @end example
138
139 @funindex \book
140
141 All the movements and texts which appear in the same @code{.ly} file
142 will normally be typeset in the form of a single output file.
143
144 @example
145 \score @{
146   @var{..}
147 @}
148 \markup @{
149   @var{..}
150 @}
151 \score @{
152   @var{..}
153 @}
154 @end example
155
156 However, if you want multiple output files from the same @code{.ly}
157 file, then you can add multiple @code{\book} blocks, where each such
158 @code{\book} block will result in a separate output.  If you do not
159 specify any @code{\book} block in the file, LilyPond will implicitly
160 treat the full file as a single @code{\book} block, see @ref{File
161 structure}.  One important exception is within lilypond-book documents,
162 where you explicitly have to add a @code{\book} block, otherwise only
163 the first @code{\score} or @code{\markup} will appear in the output.
164
165 The header for each piece of music can be put inside the @code{\score}
166 block.  The @code{piece} name from the header will be printed before
167 each movement.  The title for the entire book can be put inside the
168 @code{\book}, but if it is not present, the @code{\header} which is at
169 the top of the file is inserted.
170
171 @example
172 \header @{
173   title = "Eight miniatures"
174   composer = "Igor Stravinsky"
175 @}
176 \score @{
177   @dots{}
178   \header @{ piece = "Romanze" @}
179 @}
180 \markup @{
181    ..text of second verse..
182 @}
183 \markup @{
184    ..text of third verse..
185 @}
186 \score @{
187   @dots{}
188   \header @{ piece = "Menuetto" @}
189 @}
190 @end example
191
192 @node File structure
193 @subsection File structure
194
195 @funindex \paper
196 @funindex \midi
197 @funindex \layout
198 @funindex \header
199 @funindex \score
200 @funindex \book
201
202 A @code{.ly} file may contain any number of toplevel expressions, where a
203 toplevel expression is one of the following:
204
205 @itemize @bullet
206 @item
207 An output definition, such as @code{\paper}, @code{\midi}, and
208 @code{\layout}.  Such a definition at the toplevel changes the default
209 book-wide settings.  If more than one such definition of
210 the same type is entered at the top level any definitions in the later
211 expressions have precedence.
212
213 @item
214 A direct scheme expression, such as
215 @code{#(set-default-paper-size "a7" 'landscape)} or
216 @code{#(ly:set-option 'point-and-click #f)}.
217
218 @item
219 A @code{\header} block.  This sets the global header block.  This
220 is the block containing the definitions for book-wide settings, like
221 composer, title, etc.
222
223 @item
224 A @code{\score} block.  This score will be collected with other
225 toplevel scores, and combined as a single @code{\book}.
226 This behavior can be changed by setting the variable
227 @code{toplevel-score-handler} at toplevel.  The default handler is
228 defined in the init file @file{scm/@/lily@/.scm}.
229
230 @item
231 A @code{\book} block logically combines multiple movements
232 (i.e., multiple @code{\score} blocks) in one document.  If there
233 are a number of @code{\score}s, one output file will be created
234 for each @code{\book} block, in which all corresponding movements
235 are concatenated.  The only reason to explicitly specify
236 @code{\book} blocks in a @code{.ly} file is if you wish to create
237 multiple output files from a single input file.  One exception is
238 within lilypond-book documents, where you explicitly have to add
239 a @code{\book} block if you want more than a single @code{\score}
240 or @code{\markup} in the same example.  This behavior can be
241 changed by setting the variable @code{toplevel-book-handler} at
242 toplevel.  The default handler is defined in the init file
243 @file{scm/@/lily@/.scm}.
244
245 @item
246 A compound music expression, such as
247 @example
248 @{ c'4 d' e'2 @}
249 @end example
250
251 This will add the piece in a @code{\score} and format it in a
252 single book together with all other toplevel @code{\score}s and music
253 expressions.  In other words, a file containing only the above
254 music expression will be translated into
255
256 @example
257 \book @{
258   \score @{
259     \new Staff @{
260       \new Voice @{
261         @{ c'4 d' e'2 @}
262       @}
263     @}
264   @}
265         \layout @{ @}
266         \header @{ @}
267 @}
268 @end example
269
270 This behavior can be changed by setting the variable
271 @code{toplevel-music-handler} at toplevel.  The default handler is
272 defined in the init file @file{scm/@/lily@/.scm}.
273
274 @item
275 A markup text, a verse for example
276 @example
277 \markup @{
278    2.  The first line verse two.
279 @}
280 @end example
281
282 Markup texts are rendered above, between or below the scores or music
283 expressions, wherever they appear.
284
285 @cindex variables
286
287 @item
288 A variable, such as
289 @example
290 foo = @{ c4 d e d @}
291 @end example
292
293 This can be used later on in the file by entering @code{\foo}.  The
294 name of an variable should have alphabetic characters only; no
295 numbers, underscores or dashes.
296
297 @end itemize
298
299 The following example shows three things that may be entered at
300 toplevel
301
302 @example
303 \layout @{
304   % Don't justify the output
305   ragged-right = ##t
306 @}
307
308 \header @{
309    title = "Do-re-mi"
310 @}
311
312 @{ c'4 d' e2 @}
313 @end example
314
315
316 At any point in a file, any of the following lexical instructions can
317 be entered:
318
319 @itemize
320 @item @code{\version}
321 @item @code{\include}
322 @item @code{\sourcefilename}
323 @item @code{\sourcefileline}
324 @item
325 A single-line comment, introduced by a leading @code{%} sign.
326
327 @item
328 A multi-line comment delimited by @code{%@{ .. %@}}.
329
330 @end itemize
331
332 @seealso
333
334 Learning Manual:
335 @rlearning{How LilyPond input files work}.
336
337 @node Useful concepts and properties
338 @section Useful concepts and properties
339
340
341 @menu
342 * Input modes::                 
343 * Direction and placement::     
344 * Distances and measurements::  
345 * Spanners::                    
346 @end menu
347
348 @node Input modes
349 @subsection Input modes
350
351 The way in which the notation contained within an input file is
352 interpreted is determined by the current input mode.
353
354 @strong{Chord mode}
355
356 This is activated with the @code{\chordmode} command, and causes
357 input to be interpreted with the syntax of chord notation, see
358 @ref{Chord notation}.  Chords are rendered as notes on a staff.
359
360 Chord mode is also activated with the @code{\chords} command.
361 This also creates a new @code{ChordNames} context and
362 causes the following input to be interpreted with the syntax of
363 chord notation and rendered as chord names in the @code{ChordNames}
364 context, see @ref{Printing chord names}.
365
366 @strong{Drum mode}
367
368 This is activated with the @code{\drummode} command, and causes
369 input to be interpreted with the syntax of drum notation, see
370 @ref{Basic percussion notation}.
371
372 Drum mode is also activated with the @code{\drums} command.
373 This also creates a new @code{DrumStaff} context and causes the
374 following input to be interpreted with the syntax of drum notation
375 and rendered as drum symbols on a drum staff, see @ref{Basic
376 percussion notation}.
377
378 @strong{Figure mode}
379
380 This is activated with the @code{\figuremode} command, and causes
381 input to be interpreted with the syntax of figured bass, see
382 @ref{Entering figured bass}.
383
384 Figure mode is also activated with the @code{\figures} command.
385 This also creates a new @code{FiguredBass} context and causes the
386 following input to be interpreted with the figured bass syntax
387 and rendered as figured bass symbols in the @code{FiguredBass}
388 context, see @ref{Introduction to figured bass}.
389
390 @strong{Fret and tab modes}
391
392 There are no special input modes for entering fret and tab symbols.
393
394 To create tab diagrams, enter notes or chords in note mode and
395 render them in a @code{TabStaff} context, see
396 @ref{Default tablatures}.
397
398 To create fret diagrams above a staff, enter them as markup
399 above the notes using the @code{\fret-diagram} command, see
400 @ref{Fret diagrams}.
401
402 @strong{Lyrics mode}
403
404 This is activated with the @code{\lyricmode} command, and causes
405 input to be interpreted as lyric syllables with optional durations
406 and associated lyric modifiers, see @ref{Vocal music}.
407
408 Lyric mode is also activated with the @code{\addlyrics} command.
409 This also creates a new @code{Lyrics} context and an implicit
410 @code{\lyricsto} command which associates the following lyrics
411 with the preceding music.
412
413 @strong{Markup mode}
414
415 This is activated with the @code{\markup} command, and causes
416 input to be interpreted with the syntax of markup, see
417 @ref{Text markup commands}.
418
419 @c silly work-around for texinfo broken-ness
420 @c (@strong{Note...} causes a spurious cross-reference in Info)
421 @b{Note mode}
422
423 This is the default mode or it may be activated with the
424 @code{\notemode} command.  Input is interpreted as pitches,
425 durations, markup, etc and typeset as musical notation on a staff.
426
427 It is not normally necessary to specify note mode explicitly, but
428 it may be useful to do so in certain situations, for example if you
429 are in lyric mode, chord mode or any other mode and want to insert
430 something that only can be done with note mode syntax.
431
432 For example, to indicate dynamic markings for the verses of a
433 choral pieces it is necessary to enter note mode to interpret
434 the markings:
435
436 @lilypond[verbatim,relative=2,quote]
437 { c4 c4 c4 c4 }
438 \addlyrics {
439   \notemode{\set stanza = \markup{ \dynamic f 1. } }
440   To be sung loudly
441 }
442 \addlyrics {
443   \notemode{\set stanza = \markup{ \dynamic p 2. } }
444   To be sung quietly
445 }
446 @end lilypond
447
448
449
450 @node Direction and placement
451 @subsection Direction and placement
452
453 In typesetting music the direction and placement of many items is
454 a matter of choice.  For example, the stems of notes can
455 be directed up or down; lyrics, dynamics, and other expressive
456 marks may be placed above or below the staff; text may be aligned
457 left, right or center; etc.  Most of these choices may be left to
458 be determined automatically by LilyPond, but in some cases it may
459 be desirable to force a particular direction or placement.
460
461 @strong{Default actions}
462
463 By default some directions are always up or always down (e.g.
464 dynamics or fermata), while other things can alternate between
465 up or down based on the stem direction (like slurs or accents).
466
467 @c TODO Add table showing these
468
469 @strong{Context layout}
470
471 Contexts are positioned in a system from top to bottom in the
472 order in which they are encountered.  Note, however, that a
473 context will be created implicitly if a command is encountered
474 when there is no suitable context available to contain it.
475
476 @c TODO Add example ?
477
478 The default order in which contexts are laid out can be changed,
479 see @ref{Aligning contexts}
480
481 @strong{Articulation direction indicators}
482
483 When adding articulations to notes the direction indicator,
484 @code{^} (meaning @qq{up}), @code{_} (meaning @qq{down}) or
485 @code{-} (meaning @qq{use default direction}), can usually be
486 omitted, in which case @code{-} is assumed.  But a direction
487 indicator is @strong{always} required before
488
489 @itemize
490 @item @code{\tweak} commands
491 @item @code{\markup} commands
492 @item @code{\tag} commands
493 @item string markups, e.g. -"string"
494 @item fingering instructions, e.g. @code{-1}
495 @item articulation shortcuts, e.g. @code{-.}, @code{->}, @code{--}
496 @end itemize
497
498 @strong{The direction property}
499
500 The position or direction of many layout objects is controlled
501 by the @code{direction} property.
502
503 The value of the @code{direction} property may be
504 set to @code{1}, meaning @qq{up} or @qq{above}, or to @code{-1},
505 meaning @qq{down} or @qq{below}.  The symbols @code{UP} and
506 @code{DOWN} may be used instead of @code{1} and @code{-1}
507 respectively.  The default direction may be specified by setting
508 @code{direction} to @code{0} or @code{CENTER}.  Alternatively,
509 in many cases predefined commands
510 exist to specify the direction.  These are all of the form
511
512 @noindent
513 @code{\xxxUp}, @code{xxxDown}, @code{xxxNeutral}
514
515 @noindent
516 where @code{xxxNeutral} means @qq{use the default direction}.
517 See @rlearning{Within-staff objects}.
518
519 In a few cases, arpeggio being the only common example, the value
520 of the @code{direction} property specifies whether the object
521 is to be placed to the right or left of the parent object.  In
522 this case @code{-1} or @code{LEFT} means @qq{to the left} and
523 @code{1} or @code{RIGHT} means @qq{to the right}.  @code{0}
524 or @code{CENTER} means @qq{use the default} direction, as before.
525
526 @ignore
527 These all have side-axis set to #X
528 AmbitusAccidental - direction has no effect
529 Arpeggio - works
530 StanzaNumber - not tried
531 TrillPitchAccidental - not tried
532 TrillPitchGroup - not tried
533 @end ignore
534
535
536
537 @node Distances and measurements
538 @subsection Distances and measurements
539
540 DISCUSS after working on other sections.
541
542 TODO: staff spaces.  Maybe move into tweaks?
543
544
545 @node Spanners
546 @subsection Spanners
547
548 Many objects of musical notation extend over several notes or even
549 several bars.  Examples are crescendi, trills, tuplet brackets, and
550 volta repeat brackets.  Such objects are called @qq{spanners}, and
551 have special properties to control their appearance and behaviour.
552 Some of these properties are common to all spanners; others are
553 restricted to a sub-set of the spanners.
554
555 @node Titles and headers
556 @section Titles and headers
557
558 Almost all printed music includes a title and the composer's name;
559 some pieces include a lot more information.
560
561 @menu
562 * Creating titles::             
563 * Custom titles::               
564 * Reference to page numbers::   
565 * Table of contents::           
566 @end menu
567
568
569 @node Creating titles
570 @subsection Creating titles
571
572 Titles are created for each @code{\score} block, as well as for the full
573 input file (or @code{\book} block).
574
575 The contents of the titles are taken from the @code{\header} blocks.
576 The header block for a book supports the following
577
578
579 @table @code
580 @funindex dedication
581 @item dedication
582 The dedicatee of the music, centered at the top of the first page.
583
584 @funindex title
585 @item title
586 The title of the music, centered just below the dedication.
587
588 @funindex subtitle
589 @item subtitle
590 Subtitle, centered below the title.
591
592 @funindex subsubtitle
593 @item subsubtitle
594 Subsubtitle, centered below the subtitle.
595
596 @funindex poet
597 @item poet
598 Name of the poet, flush-left below the subtitle.
599
600 @funindex composer
601 @item composer
602 Name of the composer, flush-right below the subtitle.
603
604 @funindex meter
605 @item meter
606 Meter string, flush-left below the poet.
607
608 @funindex opus
609 @item opus
610 Name of the opus, flush-right below the composer.
611
612 @funindex arranger
613 @item arranger
614 Name of the arranger, flush-right below the opus.
615
616 @funindex instrument
617 @item instrument
618 Name of the instrument, centered below the arranger.  Also
619 centered at the top of pages (other than the first page).
620
621 @funindex piece
622 @item piece
623 Name of the piece, flush-left below the instrument.
624
625 @cindex page breaks, forcing
626 @funindex breakbefore
627 @item breakbefore
628 This forces the title to start on a new page (set to ##t or ##f).
629
630 @funindex copyright
631 @item copyright
632 Copyright notice, centered at the bottom of the first page.  To
633 insert the copyright symbol, see @ref{Text encoding}.
634
635 @funindex tagline
636 @item tagline
637 Centered at the bottom of the last page.
638
639 @end table
640
641 Here is a demonstration of the fields available.  Note that you
642 may use any @ref{Formatting text}, commands in the header.
643
644 @lilypond[quote,verbatim,line-width=11.0\cm]
645 \paper {
646   line-width = 9.0\cm
647   paper-height = 10.0\cm
648 }
649
650 \book {
651   \header {
652     dedication = "dedicated to me"
653     title = \markup \center-align { "Title first line" "Title second line,
654 longer" }
655     subtitle = "the subtitle,"
656     subsubtitle = #(string-append "subsubtitle LilyPond version "
657 (lilypond-version))
658     poet = "Poet"
659     composer =  \markup \center-align { "composer" \small "(1847-1973)" }
660     texttranslator = "Text Translator"
661     meter = \markup { \teeny "m" \tiny "e" \normalsize "t" \large "e" \huge
662 "r" }
663     arranger = \markup { \fontsize #8.5 "a" \fontsize #2.5 "r" \fontsize
664 #-2.5 "r" \fontsize #-5.3 "a" \fontsize #7.5 "nger" }
665     instrument = \markup \bold \italic "instrument"
666     piece = "Piece"
667   }
668
669   \score {
670     { c'1 }
671     \header {
672       piece = "piece1"
673       opus = "opus1"
674     }
675   }
676   \markup {
677       and now...
678   }
679   \score {
680     { c'1 }
681     \header {
682       piece = "piece2"
683       opus = "opus2"
684     }
685   }
686 }
687 @end lilypond
688
689 As demonstrated before, you can use multiple @code{\header} blocks.
690 When same fields appear in different blocks, the latter is used.
691 Here is a short example.
692
693 @example
694 \header @{
695   composer = "Composer"
696 @}
697 \header @{
698   piece = "Piece"
699 @}
700 \score @{
701   \new Staff @{ c'4 @}
702   \header @{
703     piece = "New piece"  % overwrite previous one
704   @}
705 @}
706 @end example
707
708 If you define the @code{\header} inside the @code{\score} block, then
709 normally only the @code{piece} and @code{opus} headers will be printed.
710 Note that the music expression must come before the @code{\header}.
711
712 @lilypond[quote,verbatim,line-width=11.0\cm]
713 \score {
714   { c'4 }
715   \header {
716     title = "title"  % not printed
717     piece = "piece"
718     opus = "opus"
719   }
720 }
721 @end lilypond
722
723 @funindex printallheaders
724 @noindent
725 You may change this behavior (and print all the headers when defining
726 @code{\header} inside @code{\score}) by using
727
728 @example
729 \paper@{
730   printallheaders=##t
731 @}
732 @end example
733
734 @cindex copyright
735 @cindex tagline
736
737 The default footer is empty, except for the first page, where the
738 @code{copyright} field from @code{\header} is inserted, and the last
739 page, where @code{tagline} from @code{\header} is added.  The default
740 tagline is @qq{Music engraving by LilyPond (@var{version})}.@footnote{Nicely
741 printed parts are good PR for us, so please leave the tagline if you
742 can.}
743
744 Headers may be completely removed by setting them to false.
745
746 @example
747 \header @{
748   tagline = ##f
749   composer = ##f
750 @}
751 @end example
752
753
754 @node Custom titles
755 @subsection Custom titles
756
757 A more advanced option is to change the definitions of the following
758 variables in the @code{\paper} block.  The init file
759 @file{ly/titling-init.ly} lists the default layout.
760
761 @table @code
762 @funindex bookTitleMarkup
763 @item bookTitleMarkup
764   This is the title added at the top of the entire output document.
765 Typically, it has the composer and the title of the piece
766
767 @funindex scoreTitleMarkup
768 @item scoreTitleMarkup
769   This is the title put over a @code{\score} block.  Typically, it has
770 the name of the movement (@code{piece} field).
771
772 @funindex oddHeaderMarkup
773 @item oddHeaderMarkup
774   This is the page header for odd-numbered pages.
775
776 @funindex evenHeaderMarkup
777 @item evenHeaderMarkup
778   This is the page header for even-numbered pages.  If unspecified,
779   the odd header is used instead.
780
781   By default, headers are defined such that the page number is on the
782   outside edge, and the instrument is centered.
783
784 @funindex oddFooterMarkup
785 @item oddFooterMarkup
786   This is the page footer for odd-numbered pages.
787
788 @funindex evenFooterMarkup
789 @item evenFooterMarkup
790   This is the page footer for even-numbered pages.  If unspecified,
791   the odd header is used instead.
792
793   By default, the footer has the copyright notice on the first, and
794   the tagline on the last page.
795 @end table
796
797
798 @cindex \paper
799 @cindex header
800 @cindex footer
801 @cindex page layout
802 @cindex titles
803
804 The following definition will put the title flush left, and the
805 composer flush right on a single line.
806
807 @verbatim
808 \paper {
809   bookTitleMarkup = \markup {
810    \fill-line {
811      \fromproperty #'header:title
812      \fromproperty #'header:composer
813    }
814   }
815 }
816 @end verbatim
817
818 @node Reference to page numbers
819 @subsection Reference to page numbers
820
821 A particular place of a score can be marked using the @code{\label}
822 command, either at top-level or inside music.  This label can then be
823 referred to in a markup, to get the number of the page where the marked
824 point is placed, using the @code{\page-ref} markup command.
825
826 @lilypond[verbatim,line-width=11.0\cm]
827 \header { tagline = ##f }
828 \book {
829   \label #'firstScore
830   \score {
831     {
832       c'1
833       \pageBreak \mark A \label #'markA
834       c'
835     }
836   }
837
838   \markup { The first score begins on page \page-ref #'firstScore "0" "?" }
839   \markup { Mark A is on page \page-ref #'markA "0" "?" }
840 }
841 @end lilypond
842
843 The @code{\page-ref} markup command takes three arguments:
844 @enumerate
845 @item the label, a scheme symbol, eg. @code{#'firstScore};
846 @item a markup that will be used as a gauge to estimate the dimensions
847 of the markup;
848 @item a markup that will be used in place of the page number if the label 
849 is not known;
850 @end enumerate
851
852 The reason why a gauge is needed is that, at the time markups are
853 interpreted, the page breaking has not yet occurred, so the page numbers
854 are not yet known.  To work around this issue, the actual markup
855 interpretation is delayed to a later time; however, the dimensions of
856 the markup have to be known before, so a gauge is used to decide these
857 dimensions.  If the book has between 10 and 99 pages, it may be "00",
858 ie. a two digit number.
859
860 @predefined
861
862 @funindex \label
863 @code{\label}
864 @funindex \page-ref
865 @code{\page-ref}
866
867 @node Table of contents
868 @subsection Table of contents
869 A table of contents is included using the @code{\markuplines \table-of-contents}
870 command.  The elements which should appear in the table of contents are
871 entered with the @code{\tocItem} command, which may be used either at
872 top-level, or inside a music expression.
873
874 @verbatim
875 \markuplines \table-of-contents
876 \pageBreak
877
878 \tocItem \markup "First score"
879 \score { 
880   {
881     c'  % ...
882     \tocItem \markup "Some particular point in the first score"
883     d'  % ... 
884   }
885 }
886
887 \tocItem \markup "Second score"
888 \score {
889   {
890     e' % ...
891   }
892 }
893 @end verbatim
894
895 The markups which are used to format the table of contents are defined
896 in the @code{\paper} block.  The default ones are @code{tocTitleMarkup},
897 for formatting the title of the table, and @code{tocItemMarkup}, for
898 formatting the toc elements, composed of the element title and page
899 number.  These variables may be changed by the user:
900
901 @verbatim
902 \paper {
903   %% Translate the toc title into French:
904   tocTitleMarkup = \markup \huge \column {
905     \fill-line { \null "Table des matières" \null }
906     \hspace #1
907   }
908   %% use larger font size
909   tocItemMarkup = \markup \large \fill-line {
910     \fromproperty #'toc:text \fromproperty #'toc:page
911   }
912 }
913 @end verbatim
914
915 Note how the toc element text and page number are referred to in
916 the @code{tocItemMarkup} definition.
917
918 New commands and markups may also be defined to build more elaborated
919 table of contents:
920 @itemize
921 @item first, define a new markup variable in the @code{\paper} block
922 @item then, define a music function which aims at adding a toc element
923 using this markup paper variable.
924 @end itemize
925
926 In the following example, a new style is defined for entering act names
927 in the table of contents of an opera:
928
929 @verbatim
930 \paper {
931   tocActMarkup = \markup \large \column {
932     \hspace #1
933     \fill-line { \null \italic \fromproperty #'toc:text \null }
934     \hspace #1
935   }
936 }
937
938 tocAct = 
939 #(define-music-function (parser location text) (markup?)
940    (add-toc-item! 'tocActMarkup text))
941 @end verbatim
942
943 @lilypond[line-width=11.0\cm]
944 \header { tagline = ##f }
945 \paper {
946   tocActMarkup = \markup \large \column {
947     \hspace #1
948     \fill-line { \null \italic \fromproperty #'toc:text \null }
949     \hspace #1
950   }
951 }
952
953 tocAct = 
954 #(define-music-function (parser location text) (markup?)
955    (add-toc-item! 'tocActMarkup text))
956
957 \book {
958   \markuplines \table-of-contents
959   \tocAct \markup { Atto Primo }
960   \tocItem \markup { Coro. Viva il nostro Alcide }
961   \tocItem \markup { Cesare. Presti omai l'Egizzia terra }
962   \tocAct \markup { Atto Secondo }
963   \tocItem \markup { Sinfonia }
964   \tocItem \markup { Cleopatra. V'adoro, pupille, saette d'Amore }
965   \markup \null
966 }
967 @end lilypond
968
969 @seealso
970
971 Init files: @file{ly/@/toc@/-init@/.ly}.
972
973 @predefined
974
975 @funindex \table-of-contents
976 @code{\table-of-contents}
977 @funindex \tocItem
978 @code{\tocItem}
979
980
981 @node Working with input files
982 @section Working with input files
983
984 @menu
985 * Including LilyPond files::    
986 * Different editions from one source::  
987 * Text encoding::               
988 * Displaying LilyPond notation::  
989 @end menu
990
991
992 @node Including LilyPond files
993 @subsection Including LilyPond files
994
995 @funindex \include
996 @cindex including files
997
998 A large project may be split up into separate files.  To refer to another
999 file, use
1000
1001 @example
1002 \include "otherfile.ly"
1003 @end example
1004
1005 The line @code{\include "file.ly"} is equivalent to pasting the contents
1006 of file.ly into the current file at the place where you have the
1007 \include.  For example, for a large project you might write separate files
1008 for each instrument part and create a @q{full score} file which brings
1009 together the individual instrument files.
1010
1011 The initialization of LilyPond is done in a number of files that are
1012 included by default when you start the program, normally transparent to the
1013 user.  Run @code{lilypond --verbose} to see a list of paths and files that Lily
1014 finds.
1015
1016 Files placed in directory @file{PATH/TO/share/lilypond/VERSION/ly/} (where
1017 VERSION is in the form @q{2.6.1}) are on the path and available to
1018 @code{\include}.  Files in the
1019 current working directory are available to \include, but a file of the same
1020 name in LilyPond's installation takes precedence.  Files are
1021 available to \include from directories in the search path specified as an
1022 option when invoking @code{lilypond --include=DIR} which adds DIR to the
1023 search path.
1024
1025 The @code{\include} statement can use full path information, but with the UNIX
1026 convention @code{/} rather than the DOS/Windows @code{\}.  For example,
1027 if @file{stuff.ly} is located one directory higher than the current working
1028 directory, use
1029
1030 @example
1031 \include "../stuff.ly"
1032 @end example
1033
1034
1035 @node Different editions from one source
1036 @subsection Different editions from one source
1037
1038 @funindex \tag
1039 @cindex tag
1040
1041 The @code{\tag} command marks music expressions with a name.  These
1042 tagged expressions can be filtered out later.  With this mechanism it
1043 is possible to make different versions of the same music source.
1044
1045 In the following example, we see two versions of a piece of music, one
1046 for the full score, and one with cue notes for the instrumental part
1047
1048 @example
1049 c1
1050 <<
1051   \tag #'part <<
1052     R1 \\
1053     @{
1054       \set fontSize = #-1
1055       c4_"cue" f2 g4 @}
1056   >>
1057   \tag #'score R1
1058 >>
1059 c1
1060 @end example
1061
1062 The same can be applied to articulations, texts, etc.: they are
1063 made by prepending
1064 @example
1065 -\tag #@var{your-tag}
1066 @end example
1067 to an articulation, for example,
1068 @example
1069 c1-\tag #'part ^4
1070 @end example
1071
1072 This defines a note with a conditional fingering indication.
1073
1074 @cindex keepWithTag
1075 @cindex removeWithTag
1076 By applying the @code{\keepWithTag} and @code{\removeWithTag}
1077 commands, tagged expressions can be filtered.  For example,
1078 @example
1079 <<
1080   @var{the music}
1081   \keepWithTag #'score @var{the music}
1082   \keepWithTag #'part @var{the music}
1083 >>
1084 @end example
1085 would yield
1086
1087 @c FIXME: broken
1088 @c @lilypondfile[ragged-right,quote]{tag-filter.ly}
1089
1090 The arguments of the @code{\tag} command should be a symbol
1091 (such as @code{#'score} or @code{#'part}), followed by a
1092 music expression.  It is possible to put multiple tags on
1093 a piece of music with multiple @code{\tag} entries,
1094
1095 @example
1096   \tag #'original-part \tag #'transposed-part @dots{}
1097 @end example
1098
1099
1100 @knownissues
1101
1102 Multiple rests are not merged if you create the score with both tagged
1103 sections.
1104
1105
1106 @node Text encoding
1107 @subsection Text encoding
1108
1109 LilyPond uses the Pango library to format multi-lingual texts, and
1110 does not perform any input-encoding conversions.  This means that any
1111 text, be it title, lyric text, or musical instruction containing
1112 non-ASCII characters, must be utf-8.  The easiest way to enter such text is
1113 by using a Unicode-aware editor and saving the file with utf-8 encoding.  Most
1114 popular modern editors have utf-8 support, for example, vim, Emacs,
1115 jEdit, and GEdit do.
1116
1117 @c  Currently not working
1118 @ignore
1119 Depending on the fonts installed, the following fragment shows Hebrew
1120 and Cyrillic lyrics,
1121
1122 @cindex Cyrillic
1123 @cindex Hebrew
1124 @cindex ASCII, non
1125
1126 @li lypondfile[fontload]{utf-8.ly}
1127
1128 The @TeX{} backend does not handle encoding specially at all.  Strings
1129 in the input are put in the output as-is.  Extents of text items in the
1130 @TeX{} backend, are determined by reading a file created via the
1131 @file{texstr} backend,
1132
1133 @example
1134 lilypond -dbackend=texstr input/les-nereides.ly
1135 latex les-nereides.texstr
1136 @end example
1137
1138 The last command produces @file{les-nereides.textmetrics}, which is
1139 read when you execute
1140
1141 @example
1142 lilypond -dbackend=tex input/les-nereides.ly
1143 @end example
1144
1145 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
1146 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
1147 interpreting non-ASCII strings.
1148
1149 @end ignore
1150
1151 To use a Unicode escape sequence, use
1152
1153 @example
1154 #(ly:export (ly:wide-char->utf-8 #x2014))
1155 @end example
1156
1157
1158 @node Displaying LilyPond notation
1159 @subsection Displaying LilyPond notation
1160
1161 @funindex \displayLilyMusic
1162 Displaying a music expression in LilyPond notation can be
1163 done using the music function @code{\displayLilyMusic}.  For example,
1164
1165 @example
1166 @{
1167   \displayLilyMusic \transpose c a, @{ c e g a bes @}
1168 @}
1169 @end example
1170
1171 will display
1172
1173 @example
1174 @{ a, cis e fis g @}
1175 @end example
1176
1177 By default, LilyPond will print these messages to the console along
1178 with all the other messages.  To split up these messages and save
1179 the results of @code{\display@{STUFF@}}, redirect the output to
1180 a file.
1181
1182 @example
1183 lilypond file.ly >display.txt
1184 @end example
1185
1186
1187
1188 @node Controlling output
1189 @section Controlling output
1190
1191 @menu
1192 * Extracting fragments of music::  
1193 * Skipping corrected music::    
1194 @end menu
1195
1196 @node Extracting fragments of music
1197 @subsection Extracting fragments of music
1198
1199 It is possible to quote small fragments of a large score directly from
1200 the output.  This can be compared to clipping a piece of a paper score
1201 with scissors.
1202
1203 This is done by defining the measures that need to be cut out
1204 separately.  For example, including the following definition
1205
1206
1207 @verbatim
1208 \layout {
1209   clip-regions
1210   = #(list
1211       (cons
1212        (make-rhythmic-location 5 1 2)
1213        (make-rhythmic-location 7 3 4)))
1214 }       
1215 @end verbatim
1216
1217 @noindent
1218 will extract a fragment starting halfway the fifth measure, ending in
1219 the seventh measure.  The meaning of @code{5 1 2} is: after a 1/2 note
1220 in measure 5, and @code{7 3 4} after 3 quarter notes in measure 7.
1221
1222 More clip regions can be defined by adding more pairs of
1223 rhythmic-locations to the list. 
1224
1225 In order to use this feature, LilyPond must be invoked with
1226 @code{-dclip-systems}.  The clips are output as EPS files, and are
1227 converted to PDF and PNG if these formats are switched on as well.
1228
1229 For more information on output formats, see @rprogram{Invoking lilypond}.
1230
1231 @node Skipping corrected music
1232 @subsection Skipping corrected music
1233
1234
1235 @funindex skipTypesetting
1236 @funindex showLastLength
1237
1238 When entering or copying music, usually only the music near the end (where
1239 you
1240 are adding notes) is interesting to view and correct.  To speed up
1241 this correction process, it is possible to skip typesetting of all but
1242 the last few measures.  This is achieved by putting
1243
1244 @verbatim
1245 showLastLength = R1*5
1246 \score { ... }
1247 @end verbatim
1248
1249 @noindent
1250 in your source file.  This will render only the last 5 measures
1251 (assuming 4/4 time signature) of every @code{\score} in the input
1252 file.  For longer pieces, rendering only a small part is often an order
1253 of magnitude quicker than rendering it completely
1254
1255 Skipping parts of a score can be controlled in a more fine-grained
1256 fashion with the property @code{Score.skipTypesetting}.  When it is
1257 set, no typesetting is performed at all.
1258
1259 This property is also used to control output to the MIDI file.  Note that
1260 it skips all events, including tempo and instrument changes.  You have
1261 been warned.
1262
1263 @lilypond[quote,fragment,ragged-right,verbatim]
1264 \relative c'' {
1265   c8 d
1266   \set Score.skipTypesetting = ##t
1267   e e e e e e e e
1268   \set Score.skipTypesetting = ##f
1269   c d b bes a g c2 }
1270 @end lilypond
1271
1272 In polyphonic music, @code{Score.skipTypesetting} will affect all
1273 voices and staves, saving even more time.
1274
1275
1276
1277 @node MIDI output
1278 @section MIDI output
1279
1280 @cindex Sound
1281 @cindex MIDI
1282
1283 MIDI (Musical Instrument Digital Interface) is a standard for
1284 connecting and controlling digital instruments.  A MIDI file is a
1285 series of notes in a number of tracks.  It is not an actual
1286 sound file; you need special software to translate between the
1287 series of notes and actual sounds.
1288
1289 Pieces of music can be converted to MIDI files, so you can listen to
1290 what was entered.  This is convenient for checking the music; octaves
1291 that are off or accidentals that were mistyped stand out very much
1292 when listening to the MIDI output.
1293
1294 @knownissues
1295
1296 Many musically interesting effects, such as swing, articulation,
1297 slurring, etc., are not translated to midi.
1298
1299 The midi output allocates a channel for each staff, and one for global
1300 settings.  Therefore the midi file should not have more than 15 staves
1301 (or 14 if you do not use drums).  Other staves will remain silent.
1302
1303 Not all midi players correctly handle tempo changes in the midi
1304 output.  Players that are known to work include
1305 @uref{http://@/timidity@/.sourceforge@/.net/,timidity}.
1306
1307 @menu
1308 * Creating MIDI files::         
1309 * MIDI block::                  
1310 * MIDI instrument names::       
1311 * What goes into the MIDI?  FIXME::  
1312 * other midi::                  
1313 @end menu
1314
1315 @node Creating MIDI files
1316 @subsection Creating MIDI files
1317
1318 To create a MIDI from a music piece of music, add a @code{\midi} block
1319 to a score, for example,
1320
1321 @example
1322 \score @{
1323   @var{...music...}
1324    \midi @{
1325      \context @{
1326        \Score
1327        tempoWholesPerMinute = #(ly:make-moment 72 4)
1328        @}
1329      @}
1330 @}
1331 @end example
1332
1333 The tempo can be specified using the @code{\tempo} command within the 
1334 actual music, see @ref{Metronome marks}.  An alternative, which does not
1335 result in a metronome mark in the printed score, is shown in the example
1336 above.  In this example the tempo of quarter notes is set to 72 beats per
1337 minute. 
1338 This kind of tempo
1339 specification can not take dotted note lengths as an argument.  In this
1340 case, break the dotted notes into smaller units.  For example, a tempo
1341 of 90 dotted quarter notes per minute can be specified as 270 eighth
1342 notes per minute
1343
1344 @example
1345 tempoWholesPerMinute = #(ly:make-moment 270 8)
1346 @end example
1347
1348 If there is a @code{\midi} command in a @code{\score}, only MIDI will
1349 be produced.  When notation is needed too, a @code{\layout} block must
1350 be added
1351
1352 @example
1353 \score @{
1354   @var{...music...}
1355   \midi @{ @}
1356   \layout @{ @}
1357 @}
1358 @end example
1359 @cindex layout block
1360
1361
1362
1363 Ties, dynamics, and tempo changes are interpreted.  Dynamic marks,
1364 crescendi and decrescendi translate into MIDI volume levels.  Dynamic
1365 marks translate to a fixed fraction of the available MIDI volume
1366 range, crescendi and decrescendi make the volume vary linearly between
1367 their two extremes.  The fractions can be adjusted by
1368 @code{dynamicAbsoluteVolumeFunction} in @rinternals{Voice} context.
1369 For each type of MIDI instrument, a volume range can be defined.  This
1370 gives a basic equalizer control, which can enhance the quality of
1371 the MIDI output remarkably.  The equalizer can be controlled by
1372 setting @code{instrumentEqualizer}, or by setting
1373
1374 @example
1375 \set Staff.midiMinimumVolume = #0.2
1376 \set Staff.midiMaximumVolume = #0.8
1377 @end example
1378
1379 To remove dynamics from the MIDI output, insert the following lines
1380 in the @code{\midi@{@}} section.
1381
1382 @example
1383 \midi @{
1384   ...
1385   \context @{
1386     \Voice
1387     \remove "Dynamic_performer"
1388   @}
1389 @}
1390 @end example
1391
1392
1393 @knownissues
1394
1395 Unterminated (de)crescendos will not render properly in the midi file,
1396 resulting in silent passages of music.  The workaround is to explicitly
1397 terminate the (de)crescendo.  For example,
1398
1399 @example
1400 @{ a\< b c d\f @}
1401 @end example
1402
1403 @noindent
1404 will not work properly but
1405
1406 @example
1407 @{ a\< b c d\!\f @}
1408 @end example
1409
1410 @noindent
1411 will.
1412
1413
1414 MIDI output is only created when the @code{\midi} command is within
1415 a @code{\score} block.  If you put it within an explicitly instantiated
1416 context ( i.e. @code{\new Score} ) the file will fail.  To solve this,
1417 enclose the @code{\new Score} and the @code{\midi} in a @code{\score} block.
1418
1419 @example
1420 \score @{
1421   \new Score @{ @dots{}notes@dots{} @}
1422   \midi
1423 @}
1424 @end example
1425
1426
1427 @node MIDI block
1428 @subsection MIDI block
1429 @cindex MIDI block
1430
1431
1432 The MIDI block is analogous to the layout block, but it is somewhat
1433 simpler.  The @code{\midi} block is similar to @code{\layout}.  It can contain
1434 context definitions.
1435
1436
1437 @cindex context definition
1438
1439 Context definitions follow precisely the same syntax as within the
1440 \layout block.  Translation modules for sound are called performers.
1441 The contexts for MIDI output are defined in @file{ly/@/performer@/-init@/.ly}.
1442
1443
1444 @node MIDI instrument names
1445 @subsection MIDI instrument names
1446
1447 @cindex instrument names
1448 @funindex Staff.midiInstrument
1449
1450 The MIDI instrument name is set by the @code{Staff.midiInstrument}
1451 property.  The instrument name should be chosen from the list in
1452 @ref{MIDI instruments}.
1453
1454 @example
1455 \set Staff.midiInstrument = "glockenspiel"
1456 @var{...notes...}
1457 @end example
1458
1459 If the selected instrument does not exactly match an instrument from
1460 the list of MIDI instruments, the Grand Piano (@code{"acoustic grand"})
1461 instrument is used.
1462
1463
1464 @node What goes into the MIDI?  FIXME
1465 @subsection What goes into the MIDI?  FIXME
1466
1467 @menu
1468 * Repeats and MIDI::            
1469 @end menu
1470
1471 @node Repeats and MIDI
1472 @subsubsection Repeats and MIDI
1473
1474 @cindex expanding repeats
1475 @funindex \unfoldRepeats
1476
1477 With a little bit of tweaking, all types of repeats can be present
1478 in the MIDI output.  This is achieved by applying the
1479 @code{\unfoldRepeats} music function.  This function changes all
1480 repeats to unfold repeats.
1481
1482 @lilypond[quote,verbatim,fragment,line-width=8.0\cm]
1483 \unfoldRepeats {
1484   \repeat tremolo 8 {c'32 e' }
1485   \repeat percent 2 { c''8 d'' }
1486   \repeat volta 2 {c'4 d' e' f'}
1487   \alternative {
1488     { g' a' a' g' }
1489     {f' e' d' c' }
1490   }
1491 }
1492 \bar "|."
1493 @end lilypond
1494
1495 When creating a score file using @code{\unfoldRepeats} for MIDI,
1496 it is necessary to make two @code{\score} blocks: one for MIDI
1497 (with unfolded repeats) and one for notation (with volta, tremolo,
1498 and percent repeats).  For example,
1499
1500 @example
1501 \score @{
1502   @var{..music..}
1503   \layout @{ .. @}
1504 @}
1505 \score @{
1506   \unfoldRepeats @var{..music..}
1507   \midi @{ .. @}
1508 @}
1509 @end example
1510
1511
1512 @node other midi
1513 @subsection other midi
1514
1515 Micro tones are also exported to the MIDI file.
1516
1517 Figured bass has no effect on MIDI.
1518