]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/refman.itely
f882840e7e156773922c4a002156b0fe11474d03
[lilypond.git] / Documentation / user / refman.itely
1
2 @c Note:
3 @c
4 @c A menu is needed before every deeper *section nesting of @nodes
5 @c Run M-x texinfo-all-menus-update
6 @c to automagically fill in these menus
7 @c before saving changes
8
9
10 @ignore
11  TODO:
12
13    fix all FIXMEs
14
15    Rhythm staff (clef, x-notehead)
16
17 @end ignore
18
19
20 @c .{Reference Manual}
21
22 @node Reference Manual
23 @chapter Reference Manual
24
25 This document describes GNU LilyPond and its input format. This document
26 has been revised for LilyPond 1.3.131
27
28
29
30 @menu
31 * Overview::                    
32 * Note entry::                  
33 * Music notation::              
34 * Polyphony::                   
35 * Spanners::                    
36 * Repeats::                     
37 * Piano music::                 
38 * Lyrics::                      
39 * Chords::                      
40 * Writing parts::               
41 * Custodes::                    
42 * Tuning output::               
43 * Page layout::                 
44 * Sound::                       
45 * Music entry::                 
46 * Engravers::                   
47 * Syntactic details::           
48 @end menu
49
50 @c . {Overview}
51 @node Overview
52 @section Overview
53
54
55 The purpose of LilyPond is explained informally by the term `music
56 typesetter'.  This is not a fully correct name: not only does the
57 program print musical symbols, it also makes esthetic decisions.  All
58 symbols and their placement is @emph{generated} from a high-level
59 musical description.  In other words, LilyPond would be best described
60 by `music compiler' or `music to notation compiler'.
61
62 Internally, LilyPond is written in a mixture of Scheme and C++. Most of
63 the algorithms and low-level routines are written in C++, but these low
64 level components are glued together using Scheme data
65 structures. LilyPond is linked to GUILE, GNU's Scheme library for
66 extension.
67
68 When lilypond is run to typeset sheet music, the following happens:
69
70 @itemize @bullet
71 @item GUILE Initialization: various scheme files are read
72 @item parsing: first standard .ly initialization  files are read, and
73 then the user @file{.ly} file is read.
74 @item interpretation: the music in the file is processed "in playing
75 order", i.e. in the same order as your eyes scan sheet music, and in the
76 same order that you hear the notes play.
77
78 @item typesetting:
79 in this step, the results of the interpretation, a typesetting
80 specification, is solved.
81
82 @item the visible results ("virtual ink") is written to the output file.
83 @end itemize
84
85 These stages, involve data of a specific type: during parsing,
86 @strong{Music} objects are created.  During the interpretation,
87 @strong{context} is constructed, and with this context af network of
88 @strong{graphical objects} (``grobs'') is created. The grobs contain
89 unknown variables, and the network forms a set of equations. After
90 solving the equations and filling in these variables, the printed output
91 (in the form of @strong{molecules}) is written to an output file.
92
93 These threemanship of tasks (parsing, translating, typesetting) and
94 data-structures (music, context, graphical objects) permeates the entire
95 design of the program.  This manual is ordered in terms of user
96 tasks. With each concept will be explained to which of the three parts
97 it belongs.
98
99 LilyPond input can be classified into three types:
100 @itemize @bullet
101   @item musical expressions: a musical expression is some combination of
102 rest, notes, lyrics
103   @item output definitions: recipes for translating those musical
104 expressions into performances (MIDI) or graphics (eg. PostScript).
105
106   @item declarations: by declaring and naming musical expressions, you
107 can enter and edit them in manageable chunks.
108 @end itemize
109
110
111
112
113 @c . {Note entry}
114 @node Note entry
115 @section Note entry
116 @cindex Note entry
117
118 @menu
119 * Notes mode::                  
120 * Pitches::                     
121 * Defining pitch names::        
122 * Durations::                   
123 * Notes::                       
124 * Rests::                       
125 * Skip::                        
126 @end menu
127
128 @c .  {Notes mode}
129 @node Notes mode
130 @subsection Notes mode
131
132 @cindex note mode
133
134 @cindex @code{\notes}
135 Note mode is introduced by the keyword
136 @code{\notes}.  In Note mode, words can only
137 contain alphabetic characters.  If @code{word} is encountered,
138 LilyPond first checks for a notename of @code{word}.  If no
139 notename is found, then @code{word} is treated as a string.
140
141 Since combinations of numbers and dots are used for indicating
142 durations, it is not possible to enter real numbers in this mode.
143
144 @cindex Notes mode
145
146 @c .  {Pitches}
147 @node Pitches
148 @subsection Pitches
149
150 @cindex Pitch names
151 @cindex Note specification
152 @cindex pitches
153 @cindex entering notes
154
155 The verbose syntax for pitch specification is
156
157 @cindex @code{\pitch}
158 @example
159   \pitch @var{scmpitch}
160 @end example
161
162 @var{scmpitch} is a pitch scheme object, see @ref{Pitch data type}.
163
164 In Note and Chord mode, pitches may be designated by names.  The default
165 names are the Dutch note names.  The notes are specified by the letters
166 @code{c} through @code{b}, where @code{c} is an octave below middle C
167 and the letters span the octave above that C.  In Dutch,
168 @cindex note names, Dutch
169 a sharp is formed by adding @code{-is} to the end of a pitch name.  A
170 flat is formed by adding @code{-es}. Double sharps and double flats are
171 obtained by adding @code{-isis} or @code{-eses}.  @code{aes} and
172 @code{ees} are contracted to @code{as} and @code{es} in Dutch, but both
173 forms will be accepted.
174
175 LilyPond has predefined sets of notenames for various other languages.
176 To use them, simply include the language specific init file.  For
177 example: @code{\include "english.ly"}.  The available language files and
178 the names they define are:
179
180 @example 
181                         Note Names               sharp       flat
182 nederlands.ly  c   d   e   f   g   a   bes b   -is         -es
183 english.ly     c   d   e   f   g   a   bf  b   -s/-sharp   -f/-flat
184 deutsch.ly     c   d   e   f   g   a   b   h   -is         -es
185 norsk.ly       c   d   e   f   g   a   b   h   -iss/-is    -ess/-es
186 svenska.ly     c   d   e   f   g   a   b   h   -iss        -ess
187 italiano.ly    do  re  mi  fa  sol la  sib si  -d          -b
188 catalan.ly     do  re  mi  fa  sol la  sib si  -d/-s       -b 
189 @end example 
190
191 @cindex @code{'}
192 @cindex @code{,}
193
194
195
196
197 The optional octave specification takes the form of a series of
198 single quote (`@code{'}') characters or a series of comma
199 (`@code{,}') characters.  Each @code{'} raises the pitch by one
200 octave; each @code{,} lowers the pitch by an octave.
201
202 @lilypond[fragment,verbatim,center]
203   c' d' e' f' g' a' b' c''
204 @end lilypond
205
206 @lilypond[fragment,verbatim,center]
207   cis' dis' eis' fis' gis' ais' bis'
208 @end lilypond
209
210 @lilypond[fragment,verbatim,center]
211   ces' des' es' fes' ges' as' bes'
212 @end lilypond
213
214 @lilypond[fragment,verbatim,center]
215   cisis' eisis' gisis' aisis' beses'
216 @end lilypond
217
218 @lilypond[fragment,verbatim,center]
219   ceses' eses' geses' ases' beses'
220 @end lilypond
221
222
223 @c .  {Defining pitch names}
224 @node Defining pitch names
225 @subsection Defining pitch names
226
227 @cindex defining pitch names
228 @cindex pitch names, defining 
229
230 Note names and chord modifiers can be customised for nationalities.  The
231 syntax is as follows.
232
233 @cindex @code{\pitchnames}
234 @cindex @code{\chordmodifiers}
235 @example
236    \pitchnames @var{scheme-alist}
237    \chordmodifiers @var{scheme-alist}
238 @end example
239
240 See @file{ly/nederlands.ly} and @file{ly/chord-modifiers.ly} for
241 specific examples how to do this.  Some national note names have been
242 provided, among others: Norwegian, Swedish, German, Italian, Catalan,
243 French, Dutch and English.
244
245
246 @c .  {Durations}
247 @node Durations
248 @subsection Durations
249
250
251 @cindex duration
252 @cindex @code{\duration}
253
254 The syntax for an verbose duration specification is
255 @example
256  \duration @var{scmduration}
257 @end example
258
259 In Note, Chord, and Lyrics mode, durations may be designated by numbers
260 and dots: durations are entered as their reciprocal values.  For notes
261 longer than a whole note, use identifiers.
262
263 @quotation
264
265 @example 
266 c'\longa c'\breve  
267 c'1 c'2 c'4 c'8 c'16 c'32 c'64 c'64 
268 r\longa r\breve  
269 r1 r2 r4 r8 r16 r32 r64 r64 
270 @end example 
271
272
273 @lilypond[]
274 \score {
275   \notes \relative c'' {
276     a\longa a\breve  \autoBeamOff
277     a1 a2 a4 a8 a16 a32 a64 a64 
278     r\longa r\breve  
279     r1 r2 r4 r8 r16 r32 r64 r64 
280   }
281   \paper {
282     \translator {
283       \StaffContext
284         \remove "Clef_engraver";
285         \remove "Staff_symbol_engraver";
286         \remove "Time_signature_engraver";
287         \consists "Pitch_squash_engraver";
288     }
289   }
290 }
291 @end lilypond
292 @end quotation
293
294 As you can see, the longa is not printed. To get a longa note head, you
295 have to use a mensural note heads. This is done accomplished by setting
296 the @code{style} property of the NoteHead grob to @code{mensural}.
297
298 If the duration is omitted then it is set equal to the previous duration
299 entered.  At the start of parsing there is no previous duration, so then
300 a quarter note is assumed.  The duration can be followed by a dot
301 (`@code{.}')  to obtain dotted note lengths.
302 @cindex @code{.}
303
304 @lilypond[fragment,verbatim,center]
305   a'4. b'4.
306 @end lilypond
307 @cindex @code{r}
308 @cindex @code{s}
309
310 You can alter the length of duration by writing `@code{*}@var{fraction}'
311 after it.  This will not affect the appearance of note heads or rests.
312
313 @c . {Notes}
314 @node Notes
315 @subsection Notes
316
317 A note specification has the form
318
319 @example
320   @var{pitch}[@var{octavespec}][!][?][@var{duration}]
321 @end example
322
323
324 LilyPond will determine what accidentals to typeset depending on the key
325 and context, so alteration refer to what note is heard, not to whether
326 accidentals are printed.  A reminder accidental
327 @cindex reminder accidental
328 @cindex @code{?}
329 can be forced by adding an exclamation mark @code{!} after the pitch.
330 A cautionary accidental,
331 @cindex cautionary accidental
332
333 i.e., an accidental within parentheses can be obtained by adding the
334 question mark `@code{?}' after the pitch.
335
336 @lilypond[fragment,verbatim,center]
337   cis' d' e' cis'  c'? d' e' c'!
338 @end lilypond
339
340
341 @c .  {Rests}
342 @node  Rests
343 @subsection Rests
344 @cindex Rests
345
346 Rests are entered like notes, with note name `@code{r}'.
347 There is also a note name
348 `@code{s}', which produces a space of the specified
349 duration.
350
351
352 @c .  {Skip}
353 @node Skip
354 @subsection Skip
355 @cindex Skip
356
357
358 @example
359   \skip @var{duration} @code{;}
360 @end example
361 @cindex @code{\skip}
362
363 Skips the amount of time specified by @var{duration}.  If no other
364 music is played, a gap will be left for the skipped time with no
365 notes printed.  It works in Note Mode or Lyrics Mode.  In Note mode,
366 this has the same effect as the spacer rest.
367
368
369
370 @c . {Music notation}
371 @node Music notation
372 @section Music notation
373 @cindex Music notation
374 @menu
375 * Key::                         
376 * Breath marks::                
377 * Time signature::              
378 @end menu
379
380 @c .  {Key}
381 @node Key
382 @subsection Key
383 @cindex Key
384
385 @cindex @code{\key}
386
387 @example
388   @code{\key} @var{pitch} @var{type} @code{;}
389 @end example
390 @cindex @code{\minor}
391 @cindex @code{\major}
392 @cindex @code{\minor}
393 @cindex @code{\ionian}
394 @cindex @code{\locrian}
395 @cindex @code{\aeolian}
396 @cindex @code{\mixolydian}
397 @cindex @code{\lydian}
398 @cindex @code{\phrygian}
399 @cindex @code{\dorian}
400
401 Change the key signature.  @var{type} should be @code{\major} or
402 @code{\minor} to get @var{pitch}-major or @var{pitch}-minor,
403 respectively.  The second argument is optional; the default is major
404 keys.  The @var{\context} argument can also be given as an integer,
405 which tells the number of semitones that should be added to the pitch
406 given in the subsequent @code{\key} commands to get the corresponding
407 major key, e.g., @code{\minor} is defined as 3.  The standard mode names
408 @code{\ionian}, @code{\locrian}, @code{\aeolian}, @code{\mixolydian},
409 @code{\lydian}, @code{\phrygian}, and @code{\dorian} are also defined.
410
411 This command sets @code{Staff.keySignature}.
412
413
414
415 @cindex @code{keySignature}
416
417 @c .   {Clef changes}
418 @subsubsection Clef changes
419 @cindex @code{\clef}
420 @example
421   \clef @var{clefname} @code{;}
422 @end example
423
424 Short-cut for
425
426 @example
427   \property Staff.clefGlyph = @var{symbol associated with clefname} 
428   \property Staff.clefPosition = @var{clef Y-position for clefname}
429   \property Staff.clefOctavation = @var{extra pitch of clefname}
430 @end example
431
432 Supported clef-names include 
433
434 @itemize @bullet
435 @item treble, violin, G, G2: G clef on 2nd line
436 @item french: G clef on 1st line
437 @item soprano: C clef on 1st line
438 @item mezzosoprano: C clef on 2nd line
439 @item alto: C clef on 3rd line
440 @item tenor: C clef on 4th line
441 @item baritone: C clef on 5th line
442 @item varbaritone: F clef on 3rd line
443 @item bass, F: F clef on 4th line
444 @item subbass: F clef on 5th line
445 @item percussion: percussion clef
446 @end itemize
447
448 Supported associated symbols (for Staff.clefGlyph) are:
449
450 @itemize @bullet
451 @item clefs-C: modern style C clef
452 @item clefs-F: modern style F clef
453 @item clefs-G: modern style G clef
454 @item clefs-vaticana_do: Editio Vaticana style do clef
455 @item clefs-vaticana_fa: Editio Vaticana style fa clef
456 @item clefs-medicaea_do: Editio Medicaea style do clef
457 @item clefs-medicaea_fa: Editio Medicaea style fa clef
458 @item clefs-mensural1_c: modern style mensural C clef
459 @item clefs-mensural2_c: historic style small mensural C clef
460 @item clefs-mensural3_c: historic style big mensural C clef
461 @item clefs-mensural1_f: historic style traditional mensural F clef
462 @item clefs-mensural2_f: historic style new mensural F clef
463 @item clefs-mensural_g: historic style mensural G clef
464 @item clefs-hufnagel_do: historic style hufnagel do clef
465 @item clefs-hufnagel_fa: historic style hufnagel fa clef
466 @item clefs-hufnagel_do_fa: historic style hufnagel combined do/fa clef
467 @item clefs-percussion: modern style percussion clef
468 @end itemize
469
470 @emph{Modern style} means "as is typeset in current editions".
471 @emph{Historic style} means "as was typeset or written in contemporary
472 historic editions".  @emph{Editio XXX style} means "as is/was printed in
473 Editio XXX".
474
475 @node Breath marks
476 @subsection Breath marks
477
478 Breath marks are entered using @code{\breathe}:
479
480 @lilypond[fragment,relative]
481 c'4 \breathe d4
482 @end lilypond
483
484
485
486 @c .  {Time signature}
487 @node Time signature
488 @subsection Time signature
489 @cindex Time signature
490 @cindex meter
491 @cindex @code{\time}
492
493 @example
494   \time @var{numerator}@code{/}@var{denominator} @code{;}
495 @end example
496
497 A short-cut for doing
498 @example
499      \property Score.timeSignatureFraction = #'(@var{numerator} . @var{denominator})
500 @end example
501
502 See the documentation of @code{timeSignatureFraction}
503
504
505 @c .   {Partial}
506 @subsubsection Partial
507 @cindex Partial
508 @cindex anacrusis
509 @cindex upstep
510 @cindex partial measure
511 @cindex measure, partial
512 @cindex shorten measures
513 @cindex @code{\partial}
514 @example
515   \partial @var{duration} @code{;}
516 @end example
517
518 Short cut for 
519
520 @example
521   \property Score.measurePosition = @var{length of duration}
522 @end example
523 @cindex @code{|}
524
525 See the documentation of @code{measurePosition}.
526
527
528
529
530
531 @c .   {Polyphony}
532 @node Polyphony
533 @section Polyphony
534 @cindex Polyphony
535
536 [todo : collisiosn, rest-collisinos, voiceX identifiers, how to
537 which  contexts to instantiate.]
538
539
540 @table @code
541 @cindex @code{\shiftOff}  
542   @item @code{\shiftOff}
543     Disable horizontal shifting of note heads that collide. 
544
545 @cindex @code{\shiftOn}  
546   @item @code{\shiftOn}
547     Enable note heads that collide with other note heads to be
548     shifted horiztonally. Also @code{\shiftOnn} and @code{\shiftOnnn}
549 set different shift values.
550
551 @cindex @code{\stemBoth}  
552   @item @code{\stemBoth}
553     Allow stems, beams, and slurs to point either upwards or
554     downwards, decided automatically by LilyPond.
555
556 @cindex @code{\stemDown}  
557   @item @code{\stemDown}
558     Force stems, beams, and slurs to point down.
559
560 @cindex @code{\stemUp}  
561   @item @code{\stemUp}
562     Force stems, beams and slurs to point up.
563 @end table
564
565 @c .  {Spanners}
566 @node Spanners
567 @section Spanners
568 @cindex Spanners
569
570 @menu
571 * Beam::                        
572 * Slur ::                       
573 * Phrasing slur::               
574 * Ornaments::                   
575 * Grace notes::                 
576 * Bar check::                   
577 @end menu
578
579
580
581 @c .   {Beam}
582 @node Beam
583 @subsection Beams
584
585 @cindex beams
586
587 @c .    {Automatic beams}
588 @subsubsection Automatic beams
589
590
591 @cindex automatic beam generation
592 @cindex autobeam
593 @cindex @code{Voice.noAutoBeaming}
594
595 LilyPond will group flagged notes and generate beams autmatically, where
596 appropriate.
597
598 This feature can be disabled by setting the @code{Voice.noAutoBeaming}
599 property to true, which you may find necessary for the melody that goes
600 with lyrics, eg.  Automatic beaming can easily be overridden for
601 specific cases by specifying explicit beams. This is discussed in the
602 next subsubsection.
603
604
605
606 @cindex @code{Voice.autoBeamSettings}
607 @cindex @code{(end * * * *)}
608 @cindex @code{(begin * * * *)}
609
610 A large number of Voice properties are used to decide how to generate
611 beams.  Their default values appear in @file{scm/auto-beam.scm}.  In
612 general, beams can begin anywhere, but their ending location is
613 significant.  Beams can end on a beat, or at durations specified by the
614 properties in @code{Voice.autoBeamSettings}.  To end beams every quarter
615 note, for example, you could set the property @code{(end * * * *)} to
616 @code{(make-moment 1 4)}.  To end beams at every three eighth notes you
617 would set it to @code{(make-moment 1 8)}.  The same syntax can be used
618 to specify beam starting points using @code{(begin * * * *)}, eg:
619 @quotation
620 @example
621 \property Voice.autoBeamSettings \override
622     #'(end * * * *) = #(make-moment 1 4)
623 \property Voice.autoBeamSettings \override
624     #'(begin * * * *) = #(make-moment 1 8)
625 @end example
626 @end quotation
627
628 To allow different settings for different time signatures, instead of
629 the first two asterisks @code{* *} you can specify a time signature; use
630 @code{(end N M * *)} to restrict the definition to
631 `@var{N}@code{/}@var{M}' time.  For example, to specify beams ending
632 only for 6/8 time you would use the property @code{(end 6 8 * *)}.
633
634 To allow different endings for notes of different durations, instead of
635 th last two asterisks you can specify a duration; use @code{(end * * N
636 M)} to restrict the definition to beams that contain notes of
637 `@var{N}@code{/}@var{M}' duration.
638
639 For example, to specify beam endings for beams that contain 32nd notes,
640 you would use @code{(end * * 1 32)}.
641
642
643
644 @c .    {Manual beams}
645 @cindex Automatic beams
646 @subsubsection Manual beams
647 @cindex beams, manual
648 @cindex @code{]}
649 @cindex @code{[}
650
651 In some cases it may be necessary to override LilyPond's automatic
652 beaming algorithm.  For example, the auto beamer will not beam over
653 rests or bar lines, so if you want that, specify the begin and end point
654 manually using @code{[} and @code{]}:
655
656 @quotation
657 @lilypond[fragment,relative,verbatim]
658   \context Staff {
659     r4 [r8 g'' a r8] r8 [g | a] r8
660   }
661 @end lilypond
662
663
664 @cindex @code{stemLeftBeamCount}
665
666 If you have specific wishes for the number of beams, you can fully
667 control the number of beams through the properties
668 y@code{Voice.stemLeftBeamCount} and @code{Voice.stemRightBeamCount}.
669
670 @lilypond[fragment,relative,verbatim]
671   \context Staff {
672     [f'8 r16 f g a]
673     [f8 r16 \property Voice.stemLeftBeamCount = #1 f g a]
674   }
675 @end lilypond
676 @end quotation
677 @cindex @code{stemRightBeamCount}
678
679
680 @c .    {Adjusting beams}
681 @unnumberedsubsubsec Adjusting beams
682 @cindex Adjusting beams
683
684 FIXME
685
686
687         
688
689 @c .   {Slur}
690 @node Slur 
691 @subsection Slur
692 @cindex slur
693
694 @menu
695 * Slur attachments::            
696 @end menu
697
698 A slur connects chords and is used to indicate legato.  Slurs avoid
699 crossing stems.  A slur is started with @code{(} and stopped with
700 @code{)}.  The starting @code{(} appears to the right of the first note
701 in the slur.  The terminal @code{)} appears to the left of the last note
702 in the slur.  This makes it possible to put a note in slurs from both
703 sides:
704
705 @lilypond[fragment,verbatim,center]
706   f'()g'()a' [a'8 b'(] a'4 g'2 )f'4
707 @end lilypond
708
709 @c .    {Adjusting slurs}
710 @unnumberedsubsubsec Adjusting slurs
711
712
713 @node Slur attachments
714 @subsubsection Slur attachments
715
716 The ending of a slur should whenever possible be attached to a note
717 head.  Only in some instances where beams are involved, LilyPond may
718 attach a slur to a stem end.  In some cases, you may want to override
719 LilyPond's decision, e.g., to attach the slur to the stem end.  This can
720 be done through @code{Voice.Slur}'s grob-property @code{attachment}:
721
722
723 @quotation
724 @lilypond[fragment,relative,verbatim]
725   \property Voice.Slur \set #'direction = #1
726   \property Voice.Stem \set #'length = #5.5
727   g''8(g)g4
728   \property Voice.Slur \set #'attachment = #'(stem . stem)
729   g8(g)g4
730 @end lilypond
731 @end quotation
732
733 Similarly, slurs can be attached to note heads even when beams are
734 involved:
735
736 @quotation
737 @lilypond[fragment,relative,verbatim]
738   \property Voice.Slur \set #'direction = #1
739   \property Voice.Slur \set #'attachment = #'(head . head)
740   g''16()g()g()g()d'()d()d()d
741 @end lilypond
742 @end quotation
743
744 If a slur would strike through a stem or beam, LilyPond will move the
745 slur away vertically (upward or downward).  In some cases, this may
746 cause ugly slurs that you may want to correct:
747
748 @quotation
749 @lilypond[fragment,relative,verbatim]
750   \property Voice.Stem \set #'direction = #1
751   \property Voice.Slur \set #'direction = #1
752   d'32( d'4 )d8..
753   \property Voice.Slur \set #'attachment = #'(stem . stem)
754   d,32( d'4 )d8..
755 @end lilypond
756 @end quotation
757
758 LilyPond will increase the curvature of a slur trying to stay free of
759 note heads and stems.  However, if the curvature would increase too much,
760 the slur will be reverted to its default shape.  This decision is based
761 on @code{Voice.Slur}'s grob-property @code{beautiful} value.  In some
762 cases, you may find ugly slurs beautiful, and tell LilyPond so by
763 increasing the @code{beautiful} value:
764
765 [hoe  gedefd?? wat betekent beautiful = X?]
766
767 @quotation
768 @lilypond[verbatim]
769 \score {
770   \notes \context PianoStaff <
771     \time 6/4;
772     \context Staff=up { s1 * 6/4 }
773     \context Staff=down <
774       \clef bass;
775       \autochange Staff \context Voice
776         \notes \relative c {
777           d,8( a' d f a d f d a f d )a
778         }
779     >
780   >
781   \paper {
782     linewidth = -1.;
783     \translator {
784       \VoiceContext
785       Slur \override #'beautiful = #5.0
786       Slur \override #'direction = #1
787       Stem \override #'direction = #-1
788       autoBeamSettings \override #'(end * * * *)
789         = #(make-moment 1 2)
790     }
791     \translator {
792       \PianoStaffContext
793       VerticalAlignment \override #'threshold = #'(5 . 5)
794     }
795   }
796 }
797 @end lilypond
798 @end quotation
799
800 @cindex Adusting slurs
801
802
803
804 @c .   {Phrasing slur}
805 @node Phrasing slur
806 @subsection Phrasing slur
807 @cindex phrasing slur
808 @cindex phrasing mark
809
810 A phrasing slur (or phrasing mark) connects chords and is used to
811 indicate a musical sentence.  Phrasing slurs avoid crossing stems.  A
812 phrasing slur is started with @code{\(} and stopped with @code{\)}.  The
813 starting @code{\(} appears to the right of the first note in the
814 phrasing slur.  The terminal @code{\)} appears to the left of the last
815 note in the phrasing slur.
816
817 @lilypond[fragment,verbatim,center,relative]
818   \time 6/4; c''\((d)e f(e)\)d
819 @end lilypond
820
821 [TODO: put together with breath mark.]
822
823
824 @c .   {Tie}
825 @menu
826 * Tie::                         
827 * Tuplets::                     
828 * Text spanner::                
829 * Ottava::                      
830 * Span requests::               
831 @end menu
832
833 @node Tie
834 @subsubsection Tie
835
836 @cindex Tie
837 @cindex ties
838 @cindex @code{~}
839
840 A tie connects two adjacent note heads of the same pitch.  When used
841 with chords, it connects all of the note heads whose pitches match.
842 Ties are indicated using the tilde symbol `@code{~}'.
843 If you try to tie together chords which have no common pitches, a
844 warning message will appear and no ties will be created.
845
846 @lilypond[fragment,verbatim,center]
847   e' ~ e' <c' e' g'> ~ <c' e' g'>
848 @end lilypond
849
850 [sparseTies]
851
852
853 @c .   {Tuplets}
854 @node Tuplets
855 @subsubsection Tuplets
856 @cindex Tuplets
857 @cindex Times 
858
859 Tuplets are made out of a music expression by multiplying their duration
860 with a fraction.
861
862 @cindex @code{\times}
863 @example
864   \times @var{fraction} @var{musicexpr}
865 @end example
866
867 The duration of @var{musicexpr} will be multiplied by the fraction. 
868 In print, the fraction's denominator will be printed over the notes,
869 optionally with a bracket.  The most common tuplet is the triplet in
870 which 3 notes have the length of 2, so the notes are 2/3 of
871 their written length:
872
873 @lilypond[fragment,verbatim,center]
874   g'4 \times 2/3 {c'4 c' c'} d'4 d'4
875 @end lilypond
876
877 [todo: document tupletSpannerDuration]
878
879
880
881 @c .   {Text spanner}
882 @node Text spanner
883 @subsubsection Text spanner
884 @cindex Text spanner
885
886 @c .   {Ottava}
887 @node Ottava
888 @subsubsection Ottava
889 @cindex Ottava
890 @unnumberedsubsubsec Ottava
891
892 [move to trick. Not a supported feature.]
893
894 @lilypond[fragment,relative,verbatim]
895   a'''' b c a
896   \property Voice.TextSpanner \set #'type = #'dotted-line
897   \property Voice.TextSpanner \set #'edge-height = #'(0 . 1.5)
898   \property Voice.TextSpanner \set #'edge-text = #'("8va " . "")
899   \property Staff.centralCPosition = #-13
900   a\spanrequest \start "text" b c a \spanrequest \stop "text"
901 @end lilypond
902
903
904
905 @c .   {Span requests}
906 @node Span requests
907 @subsubsection Span requests
908 @cindex Span requests
909
910 @cindex @code{\spanrequest}
911
912 @example
913   \spanrequest @var{startstop} @var{type}
914 @end example
915 @cindex @code{\start}
916 @cindex @code{\stop}
917
918 Define a spanning request. The @var{startstop} parameter is either -1
919 (@code{\start}) or 1 (@code{\stop}) and @var{type} is a string that
920 describes what should be started.  Among the supported types are
921 @code{crescendo}, @code{decrescendo}, @code{beam}, @code{slur}.This is
922 an internal command.  Users should use the shorthands which are defined
923 in the initialization file @file{spanners.ly}.
924
925 You can attach a (general) span request to a note using the following
926 syntax.
927
928 @lilypond[fragment,verbatim,center]
929   c'4-\spanrequest \start "slur"
930   c'4-\spanrequest \stop "slur"
931 @end lilypond
932
933 The slur syntax with parentheses is a shorthand for this.
934
935 @c .  {Ornaments}
936 @node Ornaments
937 @subsection Ornaments
938 @cindex Ornaments
939 @menu
940 * Articulation::                
941 * Text scripts::                
942 @end menu
943
944 @c .   {Articulation}
945 @node Articulation
946 @subsubsection Articulation
947 @cindex Articulation
948
949 @cindex articulations
950 @cindex scripts
951 @cindex ornaments
952
953 A variety of symbols can appear above and below notes to indicate
954 different characteristics of the performance.  These symbols can be
955 added to a note with `@var{note}@code{-\}@var{name}'.  Numerous symbols
956 are defined in @file{script.ly} and @file{script.scm}.  Symbols can be
957 forced to appear above or below the note by writing
958 `@var{note}@code{^\}@var{name}' and `@var{note}@code{_\}@var{name}'
959 respectively.  Here is a chart showing symbols above notes, with the
960 name of the corresponding symbol appearing underneath.
961
962 @lilypond[]
963
964   \score {
965     < \notes {
966         \property Score.LyricSyllable \override #'font-family =
967 #'typewriter
968         \property Score.LyricSyllable \override #'font-shape = #'upright
969         c''-\accent      c''-\marcato      c''-\staccatissimo c''-\fermata 
970         c''-\stopped     c''-\staccato     c''-\tenuto        c''-\upbow
971         c''-\downbow     c''^\lheel        c''-\rheel         c''^\ltoe
972         c''-\rtoe        c''-\turn         c''-\open          c''-\flageolet
973         c''-\reverseturn c''-\trill        c''-\prall         c''-\mordent
974         c''-\prallprall  c''-\prallmordent c''-\upprall       c''-\downprall
975         c''-\thumb       c''-\segno        c''-\coda
976       }
977       \context Lyrics \lyrics {
978         accent__      marcato__      staccatissimo__ fermata
979         stopped__     staccato__     tenuto__        upbow
980         downbow__     lheel__        rheel__         ltoe
981         rtoe__        turn__         open__          flageolet
982         reverseturn__ trill__        prall__         mordent
983         prallprall__  prallmordent__ uprall__        downprall
984         thumb__       segno__        coda
985       }
986     >
987     \paper {
988       linewidth = 5.875\in;          
989       indent    = 0.0;
990     }
991   }
992
993 @end lilypond
994
995 @c .   {Text scripts}
996 @node Text scripts
997 @subsubsection Text scripts
998 @cindex Text scripts
999
1000 In addition, it is possible to place arbitrary strings of text or markup
1001 text (see @ref{Text markup}) above or below notes by using a string
1002 instead of an identifier: @code{c^"text"}.  It is possible to use @TeX{}
1003 commands, but this should be avoided because this makes it impossible
1004 for LilyPond to compute the exact length of the string, which may lead
1005 to collisions.  Also, @TeX{} commands won't work with direct postscript
1006 output.  Fingerings can be placed by simply using digits.  All of these
1007 note ornaments appear in the printed output but have no effect on the
1008 MIDI rendering of the music.
1009
1010 @c .    {Fingerings}
1011 @unnumberedsubsubsec Fingerings
1012 @cindex Fingerings
1013
1014 To save typing, fingering instructions (digits 0 to 9 are
1015 supported) and single characters shorthands exist for a few
1016 common symbols
1017
1018 @lilypond[]
1019   \score {
1020     \notes \context Voice {
1021       \property Voice.TextScript \set #'font-family = #'typewriter
1022       \property Voice.TextScript \set #'font-shape = #'upright
1023       c''4-._"c-."      s4
1024       c''4--_"c-{}-"    s4
1025       c''4-+_"c-+"      s4
1026       c''4-|_"c-|"      s4
1027       c''4->_"c->"      s4
1028       c''4-^_"c-\\^{ }" s4
1029       c''4-1_"c-1"      s4
1030       c''4-2_"c-2"      s4
1031       c''4-3_"c-3"      s4
1032       c''4-4_"c-4"      s4
1033     }
1034     \paper {
1035       linewidth = 5.875 \in;
1036       indent    = 0.0;
1037     }
1038   }
1039
1040 @end lilypond
1041
1042
1043 @cindex @code{\textscript}
1044
1045 @example
1046
1047   \textscript @var{text} @var{style}
1048 @end example
1049
1050 Defines a text to be printed over or under a note.  @var{style} is a
1051 string that may be one of @code{roman}, @code{italic}, @code{typewriter}, 
1052 @code{bold}, @code{Large}, @code{large}, @code{dynamic} or @code{finger}.
1053
1054 You can attach a general textscript request using this syntax:
1055
1056 @quotation
1057
1058 @example 
1059 c4-\textscript "6" "finger"
1060 c4-\textscript "foo" "normal" 
1061 @end example 
1062
1063 @end quotation
1064
1065 This is equivalent to @code{c4-6 c4-"foo"}.  
1066
1067 @cindex @code{\script}
1068 @cindex scripts
1069 @cindex superscript
1070 @cindex subscript
1071
1072 @example
1073   \script @var{alias}
1074 @end example
1075
1076 Prints a symbol above or below a note.  The argument is a string which
1077 points into the script-alias table defined in @file{scm/script.scm}.
1078 Usually the @code{\script} keyword is not used directly.  Various
1079 helpful identifier definitions appear in @file{script.ly}.
1080
1081 For information on how to add scripts, consult @file{scm/script.scm}.
1082
1083
1084
1085
1086 @c .   {Grace notes}
1087 @node Grace notes
1088 @subsection Grace notes
1089
1090
1091
1092
1093
1094
1095
1096 @cindex Grace music
1097 @cindex @code{\grace}
1098 @cindex ornaments
1099 @cindex grace notes
1100 @cindex @code{graceAlignPosition}
1101
1102 @example
1103   \grace @var{musicexpr}
1104 @end example
1105
1106 A grace note expression has duration 0; the next real note is
1107 assumed to be the main note.
1108
1109 You cannot have the grace note after the main note, in terms of
1110 duration, and main notes, but you can typeset the grace notes to the
1111 right of the main note using the property
1112 @code{graceAlignPosition}.
1113 @cindex @code{flagStyle}
1114
1115 When grace music is interpreted, a score-within-a-score is set up:
1116 @var{musicexpr} has its own time bookkeeping, and you could (for
1117 example) have a separate time signature within grace notes.  While in
1118 this score-within-a-score, you can create notes, beams, slurs, etc.
1119 Unbeamed eighth notes and shorter by default have a slash through the
1120 stem.  This behavior can be controlled with the
1121 @code{flagStyle} property.
1122
1123 @quotation
1124 @lilypond[fragment,verbatim]
1125 \relative c'' {
1126   \grace c8 c4 \grace { [c16 c16] } c4
1127   \grace { \property Grace.flagStyle = "" c16 } c4
1128 }
1129
1130 @end lilypond
1131 @end quotation
1132
1133
1134 At present, nesting @code{\grace} notes is not supported. The following
1135 may cause run-time errors:
1136 @example
1137   @code{\grace @{ \grace c32 c16 @} c4}
1138 @end example
1139 Since the meaning of such a construct is unclear, we don't consider
1140 this a loss.  Similarly, juxtaposing two @code{\grace} sections is
1141 syntactically valid, but makes no sense and may cause runtime errors.
1142
1143 Ending a staff or score with grace notes may also generate a run-time
1144 error, since there will be no main note to attach the grace notes to.
1145
1146 The present implementation is not robust and generally kludgy. We expect
1147 it to change after LilyPond 1.4. Syntax changes might also be
1148 implemented.
1149
1150
1151
1152
1153
1154
1155
1156
1157 @menu
1158 * Glissando ::                  
1159 * Dynamics::                    
1160 * Crescendo and Decrescendo::   
1161 * Bar lines::                   
1162 @end menu
1163
1164
1165
1166 @c .   {Glissando}
1167 @node Glissando 
1168 @subsubsection Glissando
1169 @cindex Glissando 
1170
1171 @cindex @code{\glissando}
1172
1173 A glissando line can be requested by attaching a @code{\glissando} to a
1174 note:
1175
1176 @quotation
1177 @lilypond[fragment,relative,verbatim]
1178   c'' \glissando c'
1179 @end lilypond
1180 @end quotation
1181
1182 Printing of an additional text (such as @emph{gliss.}) must be done
1183 manually.
1184
1185
1186
1187 @c .   {Dynamics}
1188 @node Dynamics
1189 @subsubsection Dynamics
1190 @cindex Dynamics
1191
1192
1193
1194 @cindex @code{\ppp}
1195 @cindex @code{\pp}
1196 @cindex @code{\p}
1197 @cindex @code{\mp}
1198 @cindex @code{\mf}
1199 @cindex @code{\f}
1200 @cindex @code{\ff}
1201 @cindex @code{\fff}
1202 @cindex @code{\ffff}
1203 @cindex @code{\fp}
1204 @cindex @code{\sf}
1205 @cindex @code{\sff}
1206 @cindex @code{\sp}
1207 @cindex @code{\spp}
1208 @cindex @code{\sfz}
1209 @cindex @code{\rfz}
1210
1211
1212
1213
1214
1215
1216 Dynamic marks are specified by using an identifier after a note:
1217 @code{c4-\ff}.  The available dynamic marks are:
1218 @code{\ppp}, @code{\pp}, @code{\p}, @code{\mp}, @code{\mf}, @code{\f},
1219 @code{\ff}, @code{\fff}, @code{\fff}, @code{\fp}, @code{\sf},
1220 @code{\sff}, @code{\sp}, @code{\spp}, @code{\sfz}, and @code{\rfz}.
1221
1222 @c .   {Crescendo and Decrescendo}
1223 @node Crescendo and Decrescendo
1224 @subsubsection Crescendo and Decrescendo
1225
1226 @cindex Crescendo and Decrescendo
1227 @cindex crescendo
1228 @cindex @code{\cr}
1229 @cindex @code{\rc}
1230 @cindex @code{\decr}
1231 @cindex @code{\rced}
1232 @cindex @code{\<}
1233 @cindex @code{\>}
1234 @cindex @code{\"!}
1235
1236
1237
1238 A crescendo mark is started with @code{\cr} and terminated with
1239 @code{\rc}, the textual reverse of @code{cr}.  A decrescendo mark is
1240 started with @code{\decr} and terminated with @code{\rced}.  There are
1241 also shorthands for these marks.  A crescendo can be started with
1242 @code{\<} and a decrescendo can be started with @code{\>}.  Either one
1243 can be terminated with @code{\!}.  Note that @code{\!}  must go before
1244 the last note of the dynamic mark whereas @code{\rc} and @code{\rced} go
1245 after the last note.  Because these marks are bound to notes, if you
1246 want to get several marks during one note, you must use spacer notes.
1247
1248 @lilypond[fragment,verbatim,center]
1249   c'' \< \! c''   d'' \decr e'' \rced 
1250   < f''1 { s4 \< \! s2 \> \! s4 } >
1251 @end lilypond
1252
1253 You can also use a text saying @emph{cresc.} instead of hairpins. Here
1254 is an example how to do it:
1255
1256 @lilypond[fragment,relative,verbatim]
1257   \context Voice {
1258     \property Voice.crescendoText = "cresc."
1259     \property Voice.crescendoSpanner = #'dashed-line
1260     a''2\mf\< a a \!a 
1261   }
1262 @end lilypond
1263
1264
1265
1266 @c .   {Bar lines}
1267 @node Bar lines
1268 @subsubsection Bar lines
1269 @cindex Bar lines
1270
1271 @cindex @code{\bar}
1272 @cindex measure lines
1273 @cindex repeat bars
1274
1275 @example
1276   \bar @var{bartype};
1277 @end example
1278
1279 This is a short-cut for doing
1280 @example
1281   \property Score.whichBar = @var{bartype} 
1282 @end example
1283
1284 You are encouraged to use @code{\repeat} for repetitions.  See
1285 @ref{Repeats}, and the documentation of @code{whichBar} in
1286 @ref{(lilypond-internals)LilyPond context properties}.
1287
1288
1289 [FIXME]
1290
1291
1292 @c .  {Bar check}
1293 @node Bar check
1294 @subsection Bar check
1295 @cindex Bar check
1296
1297 @cindex bar check
1298 @cindex @code{barCheckNoSynchronize}
1299 @cindex @code{|}
1300
1301
1302 Whenever a bar check is encountered during interpretation, a warning
1303 message is issued if it doesn't fall at a measure boundary.  This can
1304 help you find errors in the input.  Depending on the value of
1305 @code{barCheckNoSynchronize}, the beginning of the measure will be
1306 relocated, so this can also be used to shorten measures.
1307
1308 A bar check is entered using the bar symbol, @code{|}
1309
1310
1311
1312
1313
1314 @c .  {Repeats}
1315 @node Repeats
1316 @section Repeats
1317
1318
1319 @cindex repeats
1320 @cindex @code{\repeat}
1321
1322 In order to specify repeats, use the @code{\repeat}
1323 keyword.  Since repeats look and sound differently when played or
1324 printed, there are a few different variants of repeats.
1325
1326 @table @asis
1327 @item unfolded  
1328 Repeated music is fully written (played) out.  Useful for MIDI
1329 output.
1330
1331 @item volta  
1332 This is the normal notation: Repeats are not written out, but
1333 alternative endings (voltas) are printed, left to right.
1334
1335 @item folded  
1336 Alternative endings are written stacked.  Which is unfortunately not
1337 practical for anything right now.
1338
1339 @item tremolo
1340 Make tremolo beams.
1341 @end table  
1342
1343 @menu
1344 * Repeat syntax::               
1345 * Manual repeat commands::      
1346 * Tremolo repeats::             
1347 * Tremolo subdivision::         
1348 @end menu
1349
1350 @node Repeat syntax
1351 @subsection Repeat syntax
1352
1353 The syntax for repeats is
1354
1355 @example
1356   \repeat @var{variant} @var{repeatcount} @var{repeatbody}
1357 @end example
1358
1359 If you have alternative endings, you may add
1360
1361 @cindex @code{\alternative}
1362 @example
1363  \alternative @code{@{} @var{alternative1}
1364             @var{alternative2}
1365             @var{alternative3} @dots{} @code{@}}
1366 @end example
1367
1368 where each @var{alternative} is a Music expression.
1369
1370 Normal notation repeats are used like this:
1371
1372 @quotation
1373
1374 @lilypond[fragment,verbatim]
1375   c'1
1376   \repeat volta 2 { c'4 d' e' f' }
1377   \repeat volta 2 { f' e' d' c' }
1378 @end lilypond
1379 @end quotation
1380
1381 With alternative endings:
1382
1383 @quotation
1384
1385 @lilypond[fragment,verbatim]
1386   c'1
1387   \repeat volta 2 {c'4 d' e' f'} 
1388   \alternative { {d'2 d'} {f' f} }
1389 @end lilypond
1390 @end quotation
1391
1392 Folded repeats look like this:@footnote{Folded repeats offer little
1393 more over simultaneous music.  However, it is to be expected that
1394 more functionality -- especially for the MIDI backend -- will be
1395 implemented at some point in the future.}
1396
1397 @quotation
1398
1399 @lilypond[fragment,verbatim]
1400   c'1
1401   \repeat fold 2 {c'4 d' e' f'} 
1402   \alternative { {d'2 d'} {f' f} }
1403
1404 @end lilypond
1405 @end quotation
1406
1407
1408 If you don't give enough alternatives for all of the repeats, then
1409 the first alternative is assumed to be repeated often enough to equal
1410 the specified number of repeats.
1411
1412 @quotation
1413 @lilypond[fragment,verbatim]
1414 \context Staff {
1415   \relative c' {
1416     \partial 4;
1417     \repeat volta 3 { e | c2 d2 | e2 f2 | }
1418     \alternative { { g4 g g } { a | a a a a | b2. } }
1419   }
1420 }
1421
1422 @end lilypond
1423 @end quotation
1424
1425
1426 As you can see, LilyPond doesn't remember the timing information, nor
1427 are slurs or ties repeated, so you have to reset timing information
1428 after a repeat, eg using bar-checks, @code{Score.measurePosition} or
1429 @code{\partial}. We hope to fix this after 1.4.
1430
1431 It is possible to nest @code{\repeat}, although it probably is only
1432 meaningful for unfolded repeats.
1433
1434 @node Manual repeat commands
1435 @subsection Manual repeat commands
1436
1437 @cindex @code{repeatCommands}
1438
1439 The property @code{repeatCommands} can be used to control the layout of
1440 repeats. Its value is a Scheme list of repeat commands, where each repeat
1441 command can be
1442
1443 @table @code
1444 @item 'start-repeat
1445  Print a |: bar line
1446 @item 'stop-repeat
1447  Print a :| bar line
1448 @item (volta . @var{text})
1449   Print a volta bracket saying @var{text}.
1450 @item (volta . #f)
1451   Stop a running volta bracket
1452 @end table
1453
1454 @lilypond[verbatim, fragment]
1455  c''4
1456     \property Score.repeatCommands = #'((volta "93") end-repeat)
1457  c4 c4
1458     \property Score.repeatCommands = #'((volta #f))
1459  c4 c4
1460 @end lilypond
1461
1462
1463 @node Tremolo repeats
1464 @subsection Tremolo repeats
1465 @cindex tremolo beams
1466
1467 To place tremolo marks between notes, use @code{\repeat} with tremolo
1468 style.  
1469 @lilypond[verbatim,center]
1470 \score { 
1471   \context Voice \notes\relative c' {
1472     \repeat "tremolo" 8 { c16 d16 }
1473     \repeat "tremolo" 4 { c16 d16 }    
1474     \repeat "tremolo" 2 { c16 d16 }
1475     \repeat "tremolo" 4 c16
1476   }
1477   \paper {
1478     linewidth = 40*\staffspace;
1479   }  
1480 }
1481 @end lilypond
1482
1483 @node Tremolo subdivision
1484 @subsection Tremolo subdivision
1485 @cindex tremolo marks
1486 @cindex @code{tremoloFlags}
1487
1488 Tremolo marks can be printed on a single note by adding
1489 `@code{:}[@var{length}]' after the note.  The length must be at least 8.
1490 A @var{length} value of 8 gives one line across the note stem.  If the
1491 length is omitted, then the last value is used, or the value of the
1492 @code{tremoloFlags} property if there was no last value.
1493
1494 @lilypond[verbatim,fragment,center]
1495   c'2:8 c':32
1496 @end lilypond
1497
1498 Tremolos in this style do not carry over into the MIDI output.
1499
1500 Using this mechanism pays off when you entering many tremolos, since the
1501 default argument saves a lot of typing.
1502
1503
1504
1505
1506
1507 @c . {Piano music}
1508 @node Piano music
1509 @section Piano music
1510 @menu
1511 * Automatic staff changes::     
1512 * Manual staff switches::       
1513 * Pedals::                      
1514 * Arpeggio::                    
1515 * Follow Thread::               
1516 @end menu 
1517
1518
1519 @c .   {Automatic staff changes}
1520 @node Automatic staff changes
1521 @subsection Automatic staff changes
1522 @cindex Automatic staff changes
1523
1524 Voices can be switched from top to bottom staff automatically. The
1525 syntax for this is
1526 @example
1527         \autochange @var{contexttype} @var{musicexp}
1528 @end example
1529 This will switch notation context of @var{musicexp} between a
1530 @var{contexttype} named @code{up} and @code{down}. Typically, you use
1531 @code{Staff} for @var{contexttype}.  The autochanger switches on basis
1532 of pitch (central C is the turning point), and it looks ahead skipping
1533 over rests to switch rests in advance.
1534         
1535 @lilypond[verbatim,singleline]
1536 \score { \notes \context PianoStaff <
1537         \context Staff = "up" {
1538                 \autochange Staff \context Voice = VA < \relative c' { g4 a  b c d r4 a g } >
1539         }
1540         \context Staff = "down" {
1541                 \clef bass; 
1542                 s1*2
1543         } > }
1544 @end lilypond
1545
1546
1547
1548
1549 @node Manual staff switches
1550 @subsection Manual staff switches
1551
1552 @cindex manual staff switches
1553 @cindex staff switch, manual
1554
1555 @cindex @code{\translator}
1556 @example
1557   \translator @var{contexttype} = @var{name}
1558 @end example
1559
1560 A music expression indicating that the context which is a direct
1561 child of the a context of type @var{contexttype} should be shifted to
1562 a context of type @var{contexttype} and the specified name.
1563
1564 Usually this is used to switch staffs in Piano music, e.g.
1565
1566 @example
1567   \translator Staff = top @var{Music}
1568 @end example
1569
1570
1571 @c .   {Pedals}
1572 @node Pedals
1573 @subsection Pedals
1574 @cindex Pedals
1575
1576 Piano pedals can be entered using the following span requests of the
1577 types @code{Sustain}, @code{UnaChorda} and @code{Sostenuto}:
1578 @lilypond[fragment,verbatim]
1579 c''4 \spanrequest \start "Sustain"  c4 c4  \spanrequest \stop "Sustain"
1580 @end lilypond
1581
1582 For these verbose expressions, standard shorthands have been defined:
1583 @table @code
1584 @item sustainDown
1585 @item sustainUp
1586 @item unaChorda
1587 @item treChorde
1588 @item sostenutoDown
1589 @item sostenutoUp
1590 @end table
1591
1592 The symbols that are printed can be modified by setting pedalXStrings,
1593 where one of the pedal types. Refer to the generaetd documentation for
1594 more information.
1595
1596 Currently, brackets are not supported, only text markings (ie. Ped*
1597 style).
1598
1599
1600 @c .   {Arpeggio}
1601 @node Arpeggio
1602 @subsection Arpeggio
1603 @cindex Arpeggio
1604
1605 @cindex broken arpeggio
1606 @cindex @code{\arpeggio}
1607
1608 You can specify an arpeggio sign on a chord by attaching an
1609 @code{\arpeggio} to a note of the chord.
1610
1611
1612 @quotation
1613 @lilypond[fragment,relative,verbatim]
1614   \context Voice <c'\arpeggio e g c>
1615 @end lilypond
1616 @end quotation
1617
1618 When an arpeggio crosses staffs in piano music, you attach an arpeggio
1619 to the chords in both staffs, and set
1620 @code{PianoStaff.connectArpeggios}. LilyPond will connect the arpeggios
1621 in both staffs.
1622
1623 @quotation
1624 @lilypond[fragment,relative,verbatim]
1625   \context PianoStaff <
1626     \property PianoStaff.connectArpeggios = ##t
1627     \context Voice = one  { <c''\arpeggio e g c> }
1628     \context Voice = other { \clef bass;  <c,,\arpeggio e g>}
1629   >  
1630 @end lilypond
1631 @end quotation
1632
1633
1634
1635 @c .    {Follow Thread}
1636 @node Follow Thread
1637 @subsection Follow Thread
1638 @cindex follow thread
1639 @cindex staff switching
1640 @cindex cross staff
1641
1642 [todo: different name, eg. voice line ? ]
1643
1644 @cindex @code{followThread}
1645
1646 Whenever a voice switches to another staff a line connecting the notes
1647 can be printed automatically. This is enabled if the property
1648 @code{PianoStaff.followThread} is set to true:
1649
1650 @quotation
1651 @lilypond[fragment,relative,verbatim]
1652   \context PianoStaff <
1653     \property PianoStaff.followThread = ##t
1654     \context Staff \context Voice {
1655       c'1
1656       \translator Staff=two
1657       b2 a
1658     }
1659     \context Staff=two {\clef bass; \skip 1*2;}
1660   >  
1661 @end lilypond
1662 @end quotation
1663
1664
1665 @c . {Lyrics}
1666 @node Lyrics
1667 @section Lyrics
1668
1669
1670 @menu
1671 * Lyrics mode::                 
1672 * Printing lyrics::             
1673 * Automatic syllable durations::  
1674 * More stanzas::                
1675 @end menu
1676
1677 @c .  {Lyrics mode}
1678 @node Lyrics mode
1679 @subsection Lyrics mode
1680 @cindex Lyrics mode
1681
1682 @cindex lyric mode
1683 @cindex @code{\lyrics}
1684
1685 Lyrics mode is introduced by the keyword @code{\lyrics}.  This mode has
1686 rules that make it easy to include punctuation and diacritical marks in
1687 words: The purpose of Lyrics mode is that you can enter lyrics in @TeX{}
1688 format or a standard encoding without needing quotes.  The precise
1689 definition of this mode is ludicrous, and this will remain so until the
1690 authors of LilyPond acquire a deeper understanding of character
1691 encoding, or someone else steps up to fix this.
1692
1693 A word in Lyrics mode begins with: an alphabetic character, @code{_},
1694 @code{?}, @code{!}, @code{:}, @code{'}, the control characters @code{^A}
1695 through @code{^F}, @code{^Q} through @code{^W}, @code{^Y}, @code{^^},
1696 any 8-bit character with ASCII code over 127, or a two-character
1697 combination of a backslash followed by one of @code{`}, @code{'},
1698 @code{"}, or @code{^}.
1699
1700 Subsequent characters of a word can be any character that is not a digit
1701 and not white space.  One important consequence of this is that a word
1702 can end with `@code{@}}', which may be confusing. However, LilyPond will
1703 issue a warning.  Any @code{_} character which appears in an unquoted
1704 word is converted to a space.  This provides a mechanism for introducing
1705 spaces into words without using quotes.  Quoted words can also be used
1706 in Lyrics mode to specify words that cannot be written with the above
1707 rules.  Here are some examples.  Not all of these words are printable by
1708 @TeX{}.
1709
1710 @example 
1711 Ah!             % a word
1712 2B_||_!2B       % not a word because it starts with a digit
1713 ``Hello''       % not a word because it starts with `
1714 _ _ _ _         % 4 words, each one a space 
1715 @end example 
1716
1717 Since combinations of numbers and dots are used for indicating
1718 durations, you can not enter real numbers in this mode.
1719
1720 @cindex lyrics expressions
1721
1722 Syllables are entered like notes, with pitches replaced by text.  For
1723 example, @code{Twin-4 kle4 twin-4 kle4} enters four syllables, each
1724 with quarter note duration.  Note that the hyphen has no special
1725 meaning for lyrics, and does not introduce special symbols.  See
1726 section @ref{Lexical modes} for a description of what is interpreted as
1727 lyrics.
1728
1729 Spaces can be introduced into a lyric either by using quotes
1730 (@code{"}) or by using an underscore without quotes: @code{He_could4
1731 not4}.  All unquoted underscores are converted to spaces.  Printing
1732 lyrics is discussed in the next section.
1733
1734
1735 @c .  {Printing lyrics}
1736 @node Printing lyrics
1737 @subsection Printing lyrics
1738 @cindex lyrics
1739
1740
1741 Lyric syllables must be interpreted within a @code{Lyrics} context for
1742 printing them. Here is a full example:
1743
1744 @quotation
1745 @lilypond[verbatim]
1746 \score {
1747   <
1748     \notes \transpose c'' {
1749       c d e c | c d e c |
1750       e f g2 | e4 f g2 \bar "|.";
1751     }
1752     \context Lyrics \lyrics { 
1753       Va-4 der Ja- cob Va- der Ja- cob
1754       Slaapt gij nog?2 Slaapt4 gij nog?2
1755     }
1756   >
1757 }
1758
1759 @end lilypond
1760 @end quotation
1761
1762
1763
1764
1765 @cindex extender
1766 @cindex lyric extender
1767
1768 You may want a continuous line after the syllables to show melismata. 
1769 To achieve this effect, add a @code{__} lyric as a separate word
1770 after the lyric to be extended.  This will create an extender, a line
1771 that extends over the entire duration of the lyric.  This line will
1772 run all the way to the start of the next lyric, so you may want to
1773 shorten it by using a blank lyric (using @code{_}).
1774
1775 @quotation
1776
1777 @lilypond[verbatim]
1778 \score {
1779   <
1780     \notes \relative c'' {
1781       a4 () b () c () d | c () d () b () a | c () d () b () a
1782     }
1783     \context Lyrics \lyrics {
1784       foo1 __ | bar2. __ _4 | baz1 __
1785     }
1786   >
1787 }
1788
1789 @end lilypond
1790 @end quotation
1791
1792 @cindex Lyric hyphen
1793
1794 If you want to have hyphens centered between syllables (rather than
1795 attached to the end of the first syllable) you can use the special
1796 `@code{-}@code{-}' lyric as a separate word between syllables.  This
1797 will result in a hyphen which length varies depending on the space
1798 between syllables, and which will be centered between the syllables. 
1799 For example:
1800
1801 @quotation
1802
1803 @lilypond[verbatim]
1804 \score {
1805   <
1806     \notes \transpose c'' {
1807       c d e c | c d e c |
1808       e f g2 | e4 f g2 \bar "|.";
1809     }
1810     \context Lyrics \lyrics {
1811       Va4 -- der Ja -- cob | Va -- der Ja -- cob |
1812       Slaapt gij nog?2 | Slaapt4 gij nog?2
1813     }
1814   >
1815 }
1816
1817 @end lilypond
1818 @end quotation
1819
1820
1821 @c .  {Automatic syllable durations}
1822 @node Automatic syllable durations
1823 @subsection Automatic syllable durations
1824 @cindex Automatic syllable durations
1825
1826
1827 @cindex automatic lyric durations
1828 @cindex @code{\addlyrics}
1829
1830 If you have lyrics that are set to a melody, you can import the rhythm
1831 of that melody into the lyrics using @code{\addlyrics}.  The syntax for
1832 this is
1833 @example
1834   \addlyrics @var{musicexpr1 musicexpr2}
1835 @end example
1836
1837 This means that both @var{musicexpr1} and @var{musicexpr2} are
1838 interpreted, but that every non-command atomic music expression
1839 (``every syllable'') in @var{musicexpr2} is interpreted using timing
1840 of @var{musicexpr1}.
1841 @cindex @code{automaticMelismata}
1842
1843 If the property @code{automaticMelismata} is set in the
1844 context of @var{musicexpr1}, no lyrics will be put on slurred or tied
1845 notes.
1846
1847 @quotation
1848 @lilypond[verbatim,fragment]
1849 \addlyrics
1850 \transpose c'' {
1851   \property Voice.automaticMelismata = ##t
1852   c8 () cis d8. e16 f2
1853 }
1854 \context Lyrics \lyrics {
1855  do4 re mi fa }
1856 @end lilypond
1857 @end quotation
1858
1859 You should use a single rhythm melody, and single rhythm lyrics (a
1860 constant duration is the obvious choice).  If you do not, you will get
1861 undesired effects when using multiple stanzas:
1862
1863 @quotation
1864 @lilypond[verbatim,fragment]
1865 \addlyrics
1866 \transpose c'' {
1867   c8 () cis d8. e16 f2
1868 }
1869 \context Lyrics \lyrics
1870 < { do4 re mi fa }
1871   { do8 re mi fa } >
1872
1873 @end lilypond
1874 @end quotation
1875
1876 It is valid (but probably not very useful) to use notes instead of
1877 lyrics for @var{musicexpr2}.
1878
1879 @node More stanzas
1880 @subsection More stanzas
1881
1882 @cindex phrasing
1883
1884 If you have multiple stanzas printed underneath each other, the separate
1885 syllables should be aligned around punctuation. LilyPond can do this if
1886 you explain it which lyric lines belong to which melody.
1887
1888 To this end, give the Voice context an identity, and set the LyricsVoice
1889 to name starting with that identity. In the following example, the Voice
1890 identity is @code{duet}, and the identities of the LyricsVoices are
1891 @code{duet-1} and @code{duet-2}.
1892
1893
1894 @lilypond[singleline,verbatim]
1895 \score {
1896 \addlyrics
1897   \notes \relative c'' \context Voice = duet { \time 3/4; g2 e4 a2 f4 g2.  }
1898   \lyrics \context Lyrics <
1899   \context LyricsVoice = "duet-1" {
1900     \property LyricsVoice . stanza = "Bert"
1901     Hi, my name is bert.    }
1902   \context LyricsVoice = "duet-2" {
1903     \property LyricsVoice . stanza = "Ernie" 
1904     Ooooo, ch\'e -- ri, je t'aime. }
1905   >
1906 }
1907 @end lilypond
1908
1909 You can add stanza numbers by setting @code{LyricsVoice.Stanza} (for the
1910 first system) and @code{LyricsVoice.stz} for the following systems.
1911
1912 @cindex stanza numbering
1913
1914
1915 @c . {Chords}
1916 @node Chords
1917 @section Chords
1918 @cindex Chords
1919
1920 [chords vs. simultaneous music]
1921
1922 @menu
1923 * Chords mode::                 
1924 * Entering named chords::       
1925 * Printing named chords::       
1926 @end menu
1927
1928 @c .  {Chords mode}
1929 @node Chords mode
1930 @subsection Chords mode
1931 @cindex Chords mode
1932
1933 Chord mode is introduced by the keyword
1934 @code{\chords}.  It is similar to Note mode, but
1935 words are also looked up in a chord modifier table (containing
1936 @code{maj}, @code{dim}, etc).
1937
1938 Since combinations of numbers and dots are used for indicating
1939 durations, you can not enter real numbers in this mode.  Dashes
1940 and carets are used to indicate chord additions and subtractions,
1941 so scripts can not be entered in Chord mode.
1942
1943 @c .  {Entering named chords}
1944 @node Entering named chords
1945 @subsection Entering named chords
1946 @cindex Chords names
1947
1948 Chord names are a way to generate simultaneous music expressions that
1949 correspond with traditional chord names.  It can only be used in
1950 Chord mode (see section @ref{Lexical modes}).
1951
1952 @example
1953
1954   @var{tonic}[@var{duration}][@code{-}@var{modifiers}][@code{^}@var{subtractions}][@code{/}@var{inversion}][@code{/+}@var{bass}].
1955 @end example
1956
1957 @var{tonic} should be the tonic note of the chord, and @var{duration}
1958 is the chord duration in the usual notation.  There are two kinds of
1959 modifiers.  One type is @emph{chord additions}, which are obtained by
1960 listing intervals separated by dots.  An interval is written by its
1961 number with an optional @code{+} or @code{-} to indicate raising or
1962 lowering by half a step.  Chord additions has two effects: It adds
1963 the specified interval and all lower odd numbered intervals to the
1964 chord, and it may lower or raise the specified interval.  Intervals
1965 must be separated by a dot (@code{.}).
1966
1967
1968 Throughout these examples, chords have been shifted around the staff
1969 using @code{\transpose}.
1970
1971
1972 @quotation
1973
1974 @lilypond[fragment,verbatim]
1975 \transpose c'' {
1976   \chords {
1977     c1  c:3-       c:7     c:8
1978     c:9 c:9-.5+.7+ c:3-.5- c:4.6.8
1979   }
1980 }
1981
1982 @end lilypond
1983 @end quotation
1984
1985 @cindex @code{aug}
1986 @cindex @code{dim}
1987 @cindex @code{maj}
1988 @cindex @code{sus}
1989
1990 The second type of modifier that may appear after the @code{:} is a
1991 named modifier.  Named modifiers are listed in the file
1992 @file{chord-modifiers.ly}.  The available modifiers are @code{m} and
1993 @code{min} which lower the 3rd half a step, `@code{aug}' which
1994 raises the 5th, `@code{dim}' which lowers the 5th,
1995 `@code{maj}' which adds a raised 7th, and `@code{sus}'
1996 which replaces the 5th with a 4th.
1997
1998 @quotation
1999
2000 @lilypond[fragment,verbatim]
2001 \transpose c'' {
2002   \chords {
2003     c1:m c:min7 c:maj c:aug c:dim c:sus
2004   }
2005 }
2006
2007 @end lilypond
2008 @end quotation
2009  
2010
2011 Chord subtractions are used to eliminate notes from a chord.  The
2012 notes to be subtracted are listed after a @code{^} character,
2013 separated by dots.
2014
2015 @lilypond[fragment,verbatim,center]
2016   \transpose c'' {
2017     \chords {
2018       c1^3 c:7^5.3 c:8^7
2019     }
2020   }
2021 @end lilypond 
2022 @cindex @code{/}
2023
2024 Chord inversions can be specified by appending `@code{/}' and
2025 the name of a single note to a chord.  This has the effect of
2026 lowering the specified note by an octave so it becomes the lowest
2027 note in the chord.  If the specified note is not in the chord, a
2028 warning will be printed.
2029
2030 @lilypond[fragment,verbatim,center]
2031   \transpose c''' {
2032     \chords {
2033       c1 c/e c/g c:7/e
2034     }
2035   }
2036
2037 @end lilypond 
2038 @cindex @code{/+}
2039
2040 Bass notes can be added by `@code{/+}' and
2041 the name of a single note to a chord.  This has the effect of
2042 adding the specified note to the chord, lowered by an octave,
2043 so it becomes the lowest note in the chord.
2044
2045 @lilypond[fragment,verbatim,center]
2046   \transpose c''' {
2047     \chords {
2048       c1 c/+c c/+g c:7/+b
2049     }
2050   }
2051
2052 @end lilypond 
2053
2054 The most interesting application is printing  chord names, which is
2055 explained in the next subsection.
2056
2057 You should not combine @code{\relative} with named chords. [FIXME]
2058
2059 @c .  {Printing named chords}
2060 @node Printing named chords
2061 @subsection Printing named chords
2062
2063
2064
2065
2066
2067 @cindex printing chord names
2068 @cindex chord names
2069 @cindex chords
2070 @cindex @code{ChordNames}
2071 @cindex @code{ChordNameVoice}
2072
2073 For displaying printed chord names, use the @code{ChordNames} and
2074 @code{ChordNameVoice} contexts.  The chords may be entered either using
2075 the notation described above, or directly using simultaneous music.
2076
2077 @quotation
2078 @lilypond[verbatim,singleline]
2079 scheme = \notes {
2080   \chords {a1 b c} <d f g>  <e g b>
2081 }
2082 \score {
2083   \notes<
2084     \context ChordNamesVoice \scheme
2085     \context Staff \transpose c'' \scheme
2086   >
2087 }
2088 @end lilypond
2089 @end quotation
2090
2091 You can make the chord changes stand out more by setting property
2092 @code{ChordNames.chordChanges} to true.  This will only display chord
2093 names when there's a change in the chords scheme, but always display the
2094 chord name after a line break:
2095
2096 @c bug
2097 @quotation
2098 @lilypond[verbatim]
2099 scheme = \chords {
2100   c1:m \break c:m c:m c:m d
2101 }
2102
2103 \score {
2104   \notes <
2105     \context ChordNames \scheme
2106     \context Staff \transpose c'' \scheme
2107   >
2108   \paper{
2109     linewidth = 40 * \staffspace;
2110     \translator {
2111       \ChordNamesContext
2112       chordChanges = ##t
2113     }
2114   }
2115 }
2116 @end lilypond
2117 @end quotation
2118
2119
2120
2121 LilyPond examines chords specified as lists of notes to determine a
2122 name to give the chord. LilyPond will not try to
2123 identify chord inversions or added base, which may result in strange
2124 chord names when chords are entered as a list of pitches:
2125
2126 @quotation
2127 @lilypond[verbatim,center,singleline]
2128 scheme = \notes {
2129   <c'1 e' g'>
2130   <e' g' c''>
2131   <e e' g' c''>
2132 }
2133
2134 \score {
2135   <
2136     \context ChordNamesVoice \scheme
2137     \context Staff \scheme
2138   >
2139 }
2140 @end lilypond
2141 @end quotation
2142
2143 To specify chord inversions, append @code{/<notename>}.  To specify an
2144 added bass note, append @code{/+<notename}:
2145
2146 @quotation
2147 @lilypond[verbatim,center,singleline]
2148 scheme = \chords {
2149   d1 d/a d/+gis
2150 }
2151
2152 \score {
2153   \notes <
2154     \context ChordNames \scheme
2155     \context Staff \transpose c'' \scheme
2156   >
2157 }
2158 @end lilypond
2159 @end quotation
2160
2161 The chord names that LilyPond should print are fully customizable.  The
2162 code to print chord names is written in Scheme. It can be found in
2163 @file{scm/chord-name.scm}.  Chord names are based on Banter style
2164 naming, which is unambiguous and has a logical structure.  Typical
2165 American style chord names are implemented as a variation on Banter
2166 names, they can be selected by setting property @code{ChordName.style}
2167 to @code{american}:
2168
2169 @quotation
2170 @lilypond[verbatim]
2171 \include "english.ly"
2172
2173 scheme = \chords {
2174   c         % Major triad
2175   cs:m      % Minor triad
2176   df:m5-    % Diminished triad
2177   c:5^3     % Root-fifth chord
2178   c:4^3     % Suspended fourth triad
2179   c:5+      % Augmented triad
2180   c:2^3     % "2" chord
2181   c:m5-.7-  % Diminished seventh
2182   c:7+      % Major seventh
2183   c:7.4^3   % Dominant seventh suspended fourth
2184   c:5+.7    % Augmented dominant seventh
2185   c:m5-.7   % "Half" diminished seventh
2186   c:5-.7    % Dominant seventh flat fifth
2187   c:5-.7+   % Major seventh flat fifth
2188   c:m7+     % Minor-major seventh
2189   c:m7      % Minor seventh
2190   c:7       % Dominant seventh
2191   c:6       % Major sixth
2192   c:m6      % Minor sixth
2193   c:9^7     % Major triad w/added ninth
2194   c:6.9^7   % Six/Nine chord
2195   c:9       % Dominant ninth 
2196   c:7+.9    % Major ninth
2197   c:m7.9    % Minor ninth
2198 }
2199
2200 \score {
2201   \notes <
2202     \context ChordNames \scheme
2203     \context Staff \transpose c'' \scheme
2204   >
2205   \paper {
2206     \translator { 
2207       \ChordNamesContext
2208       ChordName \override #'word-space = #1 
2209       ChordName \override #'style = #'american
2210     }
2211   }
2212 }
2213 @end lilypond
2214 @end quotation
2215
2216 Similarly, Jazz style chord names are implemented as a variation on
2217 American style names:
2218 @quotation
2219 @lilypond[verbatim]
2220 scheme = \chords {
2221   % major chords
2222   c
2223   c:6           % 6 = major triad with added sixth
2224   c:maj         % triangle = maj
2225   c:6.9^7       % 6/9 
2226   c:9^7         % add9
2227
2228   % minor chords
2229   c:m           % m = minor triad
2230   c:m.6         % m6 = minor triad with added sixth
2231   c:m.7+        % m triangle = minor major seventh chord
2232   c:3-.6.9^7    % m6/9 
2233   c:m.7         % m7
2234   c:3-.9        % m9
2235   c:3-.9^7      % madd9
2236
2237   % dominant chords
2238   c:7           % 7 = dominant
2239   c:7.5+        % +7 = augmented dominant
2240   c:7.5-        % 7b5 = hard diminished dominant
2241   c:9           % 7(9)
2242   c:9-          % 7(b9)
2243   c:9+          % 7(#9)
2244   c:13^9.11     % 7(13)
2245   c:13-^9.11    % 7(b13)
2246   c:13^11       % 7(9,13)
2247   c:13.9-^11    % 7(b9,13)
2248   c:13.9+^11    % 7(#9,13)
2249   c:13-^11      % 7(9,b13)
2250   c:13-.9-^11   % 7(b9,b13)
2251   c:13-.9+^11   % 7(#9,b13)
2252
2253   % half diminished chords
2254   c:m5-.7               % slashed o = m7b5
2255   c:9.3-.5-     % o/7(pure 9)
2256
2257   % diminished chords
2258   c:m5-.7-      % o = diminished seventh chord
2259 }
2260
2261 \score {
2262   \notes <
2263     \context ChordNames \scheme
2264     \context Staff \transpose c'' \scheme
2265   >
2266   \paper {
2267     \translator { 
2268       \ChordNamesContext
2269       ChordName \override #'word-space = #1 
2270       ChordName \override #'style = #'jazz
2271     }
2272   }
2273 }
2274 @end lilypond
2275 @end quotation
2276
2277 @node Writing parts
2278 @section Writing parts
2279
2280 @c .  {Transpose}
2281 @menu
2282 * Rehearsal marks::             
2283 * Instrument names::            
2284 * Transpose::                   
2285 * Sound output for transposing instruments::  
2286 * Multi measure rests::         
2287 * Automatic part combining::    
2288 @end menu
2289
2290 @c .   {Rehearsal marks}
2291 @node Rehearsal marks
2292 @subsection Rehearsal marks
2293 @cindex Rehearsal marks
2294 @cindex mark
2295 @cindex @code{\mark}
2296 @cindex @code{Mark_engraver}
2297
2298 @example
2299   \mark @var{unsigned};
2300   \mark @var{string};
2301   \mark ; 
2302 @end example
2303
2304 With this command, you can print a rehearsal mark above the system. You
2305 can provide a number, a string or a markup text as argument. If there is
2306 no argument, the property @code{rehearsalMark} is used and automatically
2307 incremented.
2308
2309 @lilypond[fragment,verbatim]
2310 \relative c'' {
2311   c1 \mark "A2";
2312   c1 \mark ; 
2313   c1 \mark ; 
2314   c1 \mark "12";
2315   c1 \mark #'(music "scripts-segno") ;
2316   c1
2317 }
2318 @end lilypond
2319
2320 @node Instrument names
2321 @subsection Instrument names
2322
2323 You can specify an instrument name for a staff by setting
2324 @code{Staff.instrument} and @code{Staff.instr}. This will print a string
2325 before the start of the staff. For the first start, @code{instrument} is
2326 used, for the next ones @code{instr} is used.
2327
2328 @lilypond[verbatim,singleline]
2329 \score { \notes {
2330   \property Staff.instrument = "instr " { c''4 } }
2331   \paper { 
2332     \translator { \StaffContext
2333     \consists "Instrument_name_engraver"; } } }
2334 @end lilypond
2335
2336 This requires  that you add the @code{Instrument_name_engraver} to the
2337 staff context.
2338
2339
2340 @node Transpose
2341 @subsection Transpose
2342 @cindex Transpose
2343 @cindex transposition of pitches
2344 @cindex @code{\transpose}
2345
2346 A music expression can be transposed with @code{\transpose}.  The syntax
2347 is
2348 @example
2349   \transpose @var{pitch} @var{musicexpr}
2350 @end example
2351
2352 This means that middle C in @var{musicexpr} is transposed to
2353 @var{pitch}.
2354
2355 @code{\transpose} distinguishes between enharmonic pitches: both
2356 @code{\transpose cis'} or @code{\transpose des'} will transpose up half
2357 a tone.  The first version will print sharps and the second version
2358 will print flats.
2359
2360 @quotation
2361 @lilypond[fragment,verbatim]
2362 \context Staff {
2363   \clef "F";
2364   { \key e \major; c d e f }
2365   \clef "G";
2366   \transpose des'' { \key e \major; c d e f }
2367   \transpose cis'' { \key e \major; c d e f }
2368 }
2369
2370 @end lilypond
2371 @end quotation
2372
2373 If you want to use both @code{\transpose} and @code{\relative}, then
2374 you must use @code{\transpose} first.  @code{\relative} will have no
2375 effect music that appears inside a @code{\transpose}.
2376
2377 @node Sound output for transposing instruments
2378 @subsection Sound output transposing instruments
2379
2380 When you want to play a score containing transposed and untransposed
2381 instruments, you have to instruct LilyPond the pitch offset (in
2382 semitones) for the transposed instruments. This is done using
2383 @code{transposing}.
2384
2385 @cindex @code{transposing}
2386
2387 @example
2388         \property Staff.instrument = #"Cl. in B-flat"
2389         \property Staff.transposing = #-2
2390 @end example
2391
2392
2393 @c .  {Multi measure rests}
2394 @node  Multi measure rests
2395 @subsection Multi measure rests
2396 @cindex Multi measure rests
2397
2398 @cindex @code{R}
2399
2400 Multi measure rests are entered using `@code{R}'. It is specifically
2401 meant for entering parts: the rest can expand to fill a score with
2402 rests, or it can be printed as a single multimeasure rest This expansion
2403 is controlled by the property @code{Score.skipBars}. If this is set to true,
2404 Lily will not expand empty measures, and the appropriate number is added
2405 automatically.
2406
2407 @lilypond[fragment,verbatim]
2408  \time 3/4; R2.*2 \property Score.skipBars = ##t R2.*17  R2.*4
2409 @end lilypond
2410
2411 Currently, there is  no way to condense multiple rests into a single
2412 multimeasure rest.
2413
2414 @cindex condensing rests
2415
2416 @node Automatic part combining
2417 @subsection Automatic part combining
2418
2419 [TODO]
2420
2421
2422 @c . {Custodes}
2423 @node Custodes
2424 @section Custodes
2425 @cindex Custos
2426 @cindex Custodes
2427
2428 A @emph{custos} (plural: @emph{custodes}; latin word for "guard") is a
2429 staff context symbol that appears at the end of a staff line.  It
2430 anticipates the pitch of the first note(s) of the following line and
2431 thus helps the player or singer to manage line breaks during
2432 performance, thus enhancing readability of a score.
2433
2434 @quotation
2435 @lilypond[verbatim]
2436 \score {
2437   \notes { c'1 d' e' d' \break c' d' e' d' }
2438   \paper {
2439     \translator {
2440       \StaffContext
2441       \consists Custos_engraver;
2442       Custos \override #'style = #'mensural;
2443     }
2444   }
2445 }
2446 @end lilypond
2447 @end quotation
2448
2449 Custodes were frequently used in music notation until the 16th century.
2450 There were different appearences for different notation styles.
2451 Nowadays, they have survived only in special forms of musical notation
2452 such as via the editio vaticana dating back to the beginning of the 20th
2453 century.
2454
2455 For typesetting custodes, just put a @code{Custos_engraver} into the
2456 @code{StaffContext} when declaring the @code{\paper} block.  In this
2457 block, you can also globally control the appearance of the custos symbol
2458 by setting the custos @code{style} property.  Currently supported styles
2459 are @code{vaticana}, @code{medicaea}, @code{hufnagel} and
2460 @code{mensural}.
2461
2462 @quotation
2463 \paper @{
2464   \translator @{
2465       \StaffContext
2466       \consists Custos_engraver;
2467       Custos \override #'style = #'mensural;
2468   @}
2469 @}
2470 @end quotation
2471
2472 The property can also be set locally, for example in a @code{\notes}
2473 block:
2474
2475 @quotation
2476 \notes @{
2477   \property Staff.Custos \override #'style = #'vaticana
2478   c'1 d' e' d' \break c' d' e' d'
2479 @}
2480 @end quotation
2481
2482 @c . {Tuning output}
2483 @node Tuning output
2484 @section Tuning output
2485
2486 LilyPond tries to take as much formatting as possible out of your
2487 hands. Nevertheless, there are situations where it needs some help, or
2488 where you want to override its decisions.
2489
2490 Here we discuss how you can do that.
2491
2492 Notational output is specified in so called grobs (graphic
2493 objects). Each grob carries with it a set of properties (grob
2494 properties) specific to that grob.  For example, a stem grob has grob
2495 properties that specify its direction, length and thickness.
2496
2497 The most common way of tuning the output is to alter the values of these
2498 properties. There are two ways of doing that: first, you can
2499 specifically select a set of grobs at one point, and set properties as
2500 you wish, or secondly, you can (temporarily) modify the definition of a
2501 grob, thereby affecting an entire group of grobs.
2502
2503 @menu
2504 * Tuning groups of grobs ::     
2505 * Tuning per grob ::            
2506 * What to tune?::               
2507 * Text markup::                 
2508 @end menu
2509
2510 @node Tuning groups of grobs 
2511 @subsection Tuning groups of grobs 
2512
2513 @cindex grob description
2514
2515 A grob definition is an association list, that is stored in a context
2516 property.  By assigning to that property (using plain @code{\property}),
2517 you can change the resulting grobs.  
2518 @lilypond[verbatim, fragment]
2519 c'4 \property Voice.Stem = #'((meta .  ((interfaces . ())))) c'4
2520 @end lilypond
2521 The @code{\property} statement effectively empties the definition of the
2522 Stem object. One of the effects is that property specifying how it
2523 should be printed is erased, with the effect of rendering it invisible.
2524
2525 @cindex \override
2526 @cindex \revert
2527 @cindex \set
2528
2529
2530 This mechanism is fairly crude, since you can only set, but not modify,
2531 the definition of a grob. For this reason, there is a more advanced
2532 mechanism: you can add a property on top of an existing definition, or
2533 remove a property: @code{\override} adds a settings, @code{\revert}
2534 removes that setting.
2535 @lilypond[verbatim]
2536 c'4 \property Voice.Stem \override #'thickness = #4.0
2537 c'4 \property Voice.Stem \revert #'thickness
2538 c'4
2539 @end lilypond
2540
2541 For the digirati, the grob description is an Scheme association
2542 list. Since it is singly linked, we can treat it as a stack, and
2543 @code{\override} and @code{\revert} are just push and pop
2544 operations. This pushing and popping is also used in the
2545 @code{autoBeamSettings} property.
2546
2547 If you revert a setting which was not set in the first place, then it
2548 has no effect. However, if the setting was set as a system default, it
2549 may remove the default value, and this may give surprising results,
2550 including crashes.  In other words, if you use @code{\override} and
2551 @code{\revert}, be sure to balance the overrides and reverts.
2552
2553 If balancing them is too much work, use the following shorthand:
2554 @code{\set} performs a revert followed by an override:
2555 @example
2556 \property Voice.Stem \set #'thickness = #2.0
2557 @end example
2558
2559 Formally the syntax for these constructions is
2560 @example
2561 \property @var{context}.@var{grobname} \override @var{symbol} = @var{value}
2562 \property @var{context}.@var{grobname} \set @var{symbol} = @var{value}
2563 \property @var{context}.@var{grobname} \revert @var{symbol}
2564 @end example
2565 Here @var{symbol} is a Scheme expression of symbol type, @var{context}
2566 and @var{grobname} are strings and @var{value} is a Scheme expression.
2567
2568 LilyPond will hang or crash if @var{value} contains cyclic references.
2569
2570
2571
2572 @node Tuning per grob 
2573 @subsection Tuning per grob 
2574
2575 @cindex \outputproperty
2576
2577 A second way of tuning grobs is the more arcane @code{\outputproperty}
2578 feature.
2579 Syntax is as follows
2580 @example
2581 \outputproperty @var{predicate} @var{symbol} = @var{value}
2582 @end example
2583 Here @code{predicate} is a Scheme functoin taking a grob a argument
2584 argument, and returning a boolean.  This statement is processed by the
2585 @code{Output_property_engraver}.  It instructs the engraver to feed all
2586 grobs that it sees to @var{predicate}. Whenever the predicate returns
2587 true, the grob property @var{symbol} will be set to @var{value}.
2588
2589 You will need to combine this statement with @code{\context} to select
2590 the appropriate context to apply this to.
2591
2592 If possible, avoid this feature: the semantics are not very clean, and
2593 the syntax and semantics are up for rewrite.
2594
2595 Here are some random examples:
2596
2597 @lilypond[fragment,verbatim,singleline]
2598 \relative c'' { c4
2599   \context Staff \outputproperty
2600   #(make-type-checker 'note-head-interface)
2601   #'extra-offset = #'(0.5 . 0.75)
2602   <c8 e g> }
2603 @end lilypond
2604
2605 @cindex @code{extra-offset}
2606
2607 This selects all note heads occurring at current staff level, and sets
2608 the @code{extra-offset} of those heads to @code{(0.5,0.75)}, shifting
2609 them up and right.
2610
2611 Move the text "m.d.", but not the fingering instruction "2".
2612 @lilypond[verbatim,singleline]
2613 #(define (make-text-checker text)
2614    (lambda (grob) (equal? text (ly-get-elt-property grob 'text))))
2615
2616 \score {    
2617   \notes\relative c''' {
2618     \property Voice.Stem \set #'direction = #1
2619     \outputproperty #(make-text-checker "m.d.")
2620       #'extra-offset = #'(-3.5 . -4.5)
2621     a^2^"m.d."    
2622   }
2623 }
2624 @end lilypond
2625
2626
2627
2628
2629 @node What to tune?
2630 @subsection What to tune?
2631
2632 This all tells you how to tune grobs, but what variables are there? The
2633 question is not  answered in this manual (although you may encounter
2634 some examples.).
2635
2636 Grob properties are tied directly to the implementation of LilyPond, and
2637 they are thus a moving target. Refer to the automatically generated
2638 documentation of the internals (available from the website).
2639
2640 You need the following information
2641
2642 @itemize @bullet
2643 @item
2644 which grob to modify
2645 @item
2646 which property to modify
2647 @item
2648 which context the grob comes from.
2649 @end itemize
2650
2651 Included with the automatically generated documentation is a master list
2652 of grobs. Each one can be clicked, taking you to a overview of the
2653 available properties.
2654
2655 There is also a master list of contexts. Clicking each takes you to an
2656 overview of the context, listing which grob types are created there.
2657
2658
2659
2660 @node Text markup
2661 @subsection Text markup
2662 @cindex text markup
2663 @cindex markup text
2664
2665 LilyPond has an internal mechanism to typeset texts. You can
2666 form text markup expressions by composing scheme expressions
2667 in the following way.
2668
2669 @lilypond[verbatim]
2670 \score { \notes \relative c' {
2671   b-#"text"
2672   c-#'(bold "text")
2673   d-#'(lines "one" (bold "text"))
2674   e-#'(music (named "noteheads-2" "flags-u3"))
2675 }
2676 \paper { linewidth = 10.\cm; } }
2677 @end lilypond
2678
2679 Normally, the Scheme markup text is stored in the @code{text} property
2680 of a grob.  Formally, it is defined as follows:
2681
2682 @example
2683 text: string | (head? text+)
2684 head: markup | (markup+)
2685 markup-item: property | abbrev | @var{fontstyle}
2686 property: (@var{key} . @var{value})
2687 abbrev: @code{rows lines roman music bold italic named super sub text}
2688 @end example
2689
2690 The markup is broken down and converted into a list of grob properties,
2691 which are prepended to the grop's property list.  The
2692 @var{key}-@var{value} pair is a grob property.
2693
2694 The following abbreviations are currently
2695 defined:
2696
2697 @table @code
2698 @item rows
2699 horizontal mode: set all text on one line (default)
2700 @item lines
2701  vertical mode: set every text on new line
2702 @item roman
2703  select roman font
2704 @item music
2705  select feta font
2706 @item bold
2707  select bold series
2708 @item italic
2709  select italic shape
2710 @item named
2711  lookup by character name
2712 @item text
2713  plain text lookup (by character value)
2714 @item super
2715  superscript
2716 @item sub
2717  subscript
2718 @end table
2719
2720 @var{fontstyle} may be any of @code{finger volta timesig mmrest mark
2721 script large Large dynamic}
2722
2723
2724 @c . {Page layout}
2725 @node Page layout
2726 @section Page layout
2727 @cindex Page layout
2728
2729 @menu
2730 * Paper block::                 
2731 * Paper variables::             
2732 * Font Size::                   
2733 * Paper size::                  
2734 * Line break::                  
2735 * Page break::                  
2736 @end menu
2737
2738 @c .  {Paper block}
2739 @node Paper block
2740 @subsection Paper block
2741 @cindex Paper block
2742
2743 The most important output definition is the @code{\paper} block, for
2744 music notation.  The syntax is
2745
2746 @example
2747   @code{\paper @{} [@var{paperidentifier}] @var{items} @code{@}}
2748 @end example
2749
2750 where each of the items is one of
2751
2752 @itemize @bullet
2753   @item  An assignment.  The assignment must be terminated by a
2754        semicolon.  
2755
2756   @item  A context definition.  See Section @ref{Notation contexts} for
2757        more information on context definitions.
2758
2759   @item  \stylesheet  declaration.  Its syntax is
2760        @example
2761                 \stylesheet @var{alist}
2762        @end example
2763
2764         See @file{font.scm} for details of @var{alist}.
2765 @end itemize
2766
2767 @c .  {Paper variables}
2768 @node Paper variables
2769 @subsection Paper variables 
2770 @cindex Paper variables
2771
2772 The paper block has some variables you may want to use or change:
2773
2774 @table @code
2775 @cindex @code{indent}
2776   @item @code{indent}  
2777     The indentation of the first line of music.
2778 @cindex @code{staffspace}
2779
2780   @item @code{staffspace}
2781     The distance between two staff lines, calculated from the center
2782     of the lines.  You should use either this or @code{stafflinethickness}
2783     as a unit for distances you modify.
2784   
2785 @cindex @code{linewidth}
2786   @item @code{linewidth}  
2787     Sets the width of the lines.
2788
2789 If set to a negative value, a single
2790     unjustified line is produced.
2791
2792 @cindex @code{textheight}
2793
2794   @item @code{textheight}  
2795     Sets the total height of the music on each page. Only used by
2796     ly2dvi.
2797 @cindex @code{interscoreline}
2798
2799   @item @code{interscoreline}  
2800     Sets the spacing between the score lines. Defaults to 16 pt.
2801 @cindex @code{interscorelinefill}
2802
2803   @item @code{interscorelinefill}  
2804     If set to a positive number, the distance between the score 
2805     lines will stretch in order to fill the full page. In that
2806     case @code{interscoreline} specifies the minimum spacing.
2807     Defaults to 0.
2808 @cindex @code{stafflinethickness}
2809
2810   @item @code{stafflinethickness}  
2811     Determines the thickness of staff lines, and also acts as a scaling
2812     parameter for other line thicknesses.
2813 @end table
2814
2815
2816
2817 @c .  {Font size}
2818 @node Font Size
2819 @subsection Font size
2820 @cindex font size
2821
2822 The Feta font provides musical symbols at six different sizes.  These
2823 fonts are 11 point, 13 point, 16 point, 20 point,
2824 23 point, and 26 point.  The point size of a font is the
2825 height of the five lines in a staff when displayed in the font.
2826
2827 Definitions for these sizes are the files @file{paperSZ.ly}, where
2828 @code{SZ} is one of 11, 13, 16, 20, 23 and 26.  If you include any of
2829 these files, the identifiers @code{paperEleven}, @code{paperThirteen},
2830 @code{paperSixteen}, @code{paperTwenty}, @code{paperTwentythree}, and
2831 @code{paperTwentysix} are defined respectively.  The default
2832 @code{\paper} block is also set.
2833
2834 The font definitions are generated using a Scheme function. For more
2835 details, see the file @file{font.scm}.
2836
2837
2838
2839 @c .  {Paper size}
2840 @node Paper size
2841 @subsection Paper size
2842 @cindex Paper size
2843
2844 @cindex paper size
2845 @cindex page size
2846 @cindex @code{papersize}
2847
2848 To change the paper size, you must first set the
2849 @code{papersize} variable at top level.  Set it to
2850 the strings @code{a4}, @code{letter}, or @code{legal}.  After this
2851 specification, you must set the font as described above.  If you want
2852 the default font, then use the 20 point font.  The new paper size will
2853 not take effect if the font is not loaded and selected afterwards.
2854
2855 @example
2856         papersize = "a4"
2857         \include "paper16.ly"
2858
2859         \score @{
2860                 ...
2861                 \paper @{ \paperSixteen @}
2862         @}
2863 @end example
2864
2865 The file "paper16.ly" will now include a file named @file{a4.ly}, which
2866 will set the paper variables @code{hsize} and @code{vsize} (used by
2867 @code{ly2dvi})
2868
2869
2870
2871
2872
2873
2874
2875 @c .  {Line break}
2876 @node Line break
2877 @subsection Line break
2878
2879 @cindex line breaks
2880 @cindex breaking lines
2881
2882 Line breaks are normally computed automatically. They are chosen such
2883 that the resulting spacing has low variation, and looks neither cramped
2884 nor loose.
2885
2886 Occasionally you might want to override the automatic breaks; you can do
2887 this by specifying @code{\break}. This will force a line break at this
2888 point. Do remember that line breaks can only occur at places where there
2889 are barlines.  If you want to have a line break where there is no
2890 barline, you can force a barline by entering @code{\bar "";}.
2891
2892 Similarly, @code{\noBreak} forbids a  line break at a certain point.
2893
2894 @cindex @code{\penalty}
2895
2896 The @code{\break} and @code{\noBreak} commands are defined in terms of
2897 the penalty command:
2898 @example
2899   \penalty @var{int} @code{;}
2900 @end example
2901
2902 This imposes   encourages or discourages LilyPond to make a line break
2903 at this point.
2904
2905 @strong{Warning} do not use @code{\penalty} directly. It is rather
2906 kludgy, and slated for rewriting.
2907
2908 @c .  {Page break}
2909 @node Page break
2910 @subsection Page break
2911
2912 @cindex page breaks
2913 @cindex breaking pages
2914
2915
2916 Page breaks are normally computed by @TeX{}, so they are not under direct
2917 control.  However, you can insert a commands into the @file{.tex} output to
2918 instruct @TeX{} where to break pages. For more details, see  the
2919 example file @file{input/test/between-systems.ly}
2920
2921 [or -> Tricks? ]
2922
2923
2924
2925
2926
2927
2928 @c . {Sound}
2929 @node Sound
2930 @section Sound
2931 @cindex Sound
2932
2933 LilyPond allows MIDI output, with the purpose of proof-hearing the music
2934 you enter. The performance lacks lots of interesting effects, such as
2935 swing, articulation, slurring, tieing, etc.
2936
2937 Also note that it is not possible to use the percussion channel
2938 (generally channel 10 of a MIDI file).
2939
2940 @menu
2941 * MIDI block::                  
2942 * MIDI instrument names::       
2943 * Tempo::                       
2944 @end menu
2945
2946 @c .  {MIDI block}
2947 @node MIDI block
2948 @subsection MIDI block
2949 @cindex MIDI block
2950
2951
2952 The MIDI block is analogous to the paper block, but it is somewhat
2953 simpler.  The @code{\midi} block can contain:
2954 @cindex MIDI block
2955
2956 @itemize @bullet
2957   @item  a @code{\tempo} definition
2958   @item  context definitions
2959 @end itemize
2960
2961 Assignments in the @code{\midi} block are not allowed.
2962
2963
2964
2965 @cindex context definition
2966
2967 Context definitions follow precisely the same syntax as within the
2968 \paper block.  Translation modules for sound are called performers.
2969 The contexts for MIDI output are defined in @file{ly/performer.ly}.
2970
2971
2972 @c .  {MIDI instrument names}
2973 @node MIDI instrument names
2974 @subsection MIDI instrument names
2975 @cindex instrument names
2976 @cindex @code{Staff.midiInstrument}
2977 @cindex @code{Staff.instrument}
2978
2979 The MIDI instrument name is set by the @code{Staff.midiInstrument}
2980 property or, if that property is not set, the @code{Staff.instrument}
2981 property.  The instrument name should be chosen from the following list.
2982 If the selected string does not exactly match, then LilyPond uses the
2983 default piano.
2984
2985 [FIXME: to appendix ]
2986
2987
2988 @example 
2989 "acoustic grand"            "contrabass"           "lead 7 (fifths)"
2990 "bright acoustic"           "tremolo strings"      "lead 8 (bass+lead)"
2991 "electric grand"            "pizzicato strings"    "pad 1 (new age)"
2992 "honky-tonk"                "orchestral strings"   "pad 2 (warm)"
2993 "electric piano 1"          "timpani"              "pad 3 (polysynth)"
2994 "electric piano 2"          "string ensemble 1"    "pad 4 (choir)"
2995 "harpsichord"               "string ensemble 2"    "pad 5 (bowed)"
2996 "clav"                      "synthstrings 1"       "pad 6 (metallic)"
2997 "celesta"                   "synthstrings 2"       "pad 7 (halo)"
2998 "glockenspiel"              "choir aahs"           "pad 8 (sweep)"
2999 "music box"                 "voice oohs"           "fx 1 (rain)"
3000 "vibraphone"                "synth voice"          "fx 2 (soundtrack)"
3001 "marimba"                   "orchestra hit"        "fx 3 (crystal)"
3002 "xylophone"                 "trumpet"              "fx 4 (atmosphere)"
3003 "tubular bells"             "trombone"             "fx 5 (brightness)"
3004 "dulcimer"                  "tuba"                 "fx 6 (goblins)"
3005 "drawbar organ"             "muted trumpet"        "fx 7 (echoes)"
3006 "percussive organ"          "french horn"          "fx 8 (sci-fi)"
3007 "rock organ"                "brass section"        "sitar"
3008 "church organ"              "synthbrass 1"         "banjo"
3009 "reed organ"                "synthbrass 2"         "shamisen"
3010 "accordion"                 "soprano sax"          "koto"
3011 "harmonica"                 "alto sax"             "kalimba"
3012 "concertina"                "tenor sax"            "bagpipe"
3013 "acoustic guitar (nylon)"   "baritone sax"         "fiddle"
3014 "acoustic guitar (steel)"   "oboe"                 "shanai"
3015 "electric guitar (jazz)"    "english horn"         "tinkle bell"
3016 "electric guitar (clean)"   "bassoon"              "agogo"
3017 "electric guitar (muted)"   "clarinet"             "steel drums"
3018 "overdriven guitar"         "piccolo"              "woodblock"
3019 "distorted guitar"          "flute"                "taiko drum"
3020 "guitar harmonics"          "recorder"             "melodic tom"
3021 "acoustic bass"             "pan flute"            "synth drum"
3022 "electric bass (finger)"    "blown bottle"         "reverse cymbal"
3023 "electric bass (pick)"      "skakuhachi"           "guitar fret noise"
3024 "fretless bass"             "whistle"              "breath noise"
3025 "slap bass 1"               "ocarina"              "seashore"
3026 "slap bass 2"               "lead 1 (square)"      "bird tweet"
3027 "synth bass 1"              "lead 2 (sawtooth)"    "telephone ring"
3028 "synth bass 2"              "lead 3 (calliope)"    "helicopter"
3029 "violin"                    "lead 4 (chiff)"       "applause"
3030 "viola"                     "lead 5 (charang)"     "gunshot"
3031 "cello"                     "lead 6 (voice)" 
3032 @end example 
3033
3034
3035
3036
3037
3038 @c .  {Tempo}
3039 @node Tempo
3040 @subsection Tempo
3041 @cindex Tempo
3042 @cindex beats per minute
3043 @cindex metronome marking
3044
3045 @cindex @code{\tempo}
3046 @example
3047   \tempo @var{duration} = @var{perminute} @code{;}
3048 @end example
3049
3050 Used to specify the tempo.  For example, @code{\tempo 4 = 76;} requests
3051 output with 76 quarter notes per minute.
3052
3053
3054
3055
3056
3057 @c . {Music entry}
3058 @node Music entry
3059 @section Music entry
3060 @cindex Music entry
3061 @menu
3062 * Relative::                    
3063 * Point and click::             
3064 @end menu
3065
3066
3067
3068 @c .  {Relative}
3069 @node Relative
3070 @subsection Relative
3071 @cindex Relative
3072 @cindex relative octave specification
3073
3074 Octaves are specified by adding @code{'} and @code{,} to pitch names.
3075 When you copy existing music, it is easy to accidentally put a pitch in
3076 the wrong octave and hard to find such an error.  To prevent these
3077 errors, LilyPond features octave entry.
3078
3079 @cindex @code{\relative}
3080 @example
3081   \relative @var{startpitch} @var{musicexpr}
3082 @end example
3083
3084 The octave of notes that appear in @var{musicexpr} are calculated as
3085 follows: If no octave changing marks are used, the basic interval
3086 between this and the last note is always taken to be a fourth or less.
3087   The octave changing marks @code{'} and @code{,} can then
3088 be added to raise or lower the pitch by an extra octave.  Upon entering
3089 relative mode, an absolute starting pitch must be specified that will
3090 act as the predecessor of the first note of @var{musicexpr}.
3091
3092 This distance is determined without regarding accidentals: a
3093 @code{fisis} following a @code{ceses} will be put above the
3094 @code{ceses}.
3095
3096 Entering scales is straightforward in relative mode.
3097
3098 @lilypond[fragment,verbatim,center]
3099   \relative c'' {
3100     g a b c d e f g g, g
3101   }
3102 @end lilypond
3103
3104 And octave changing marks are used for intervals greater than a fourth.
3105
3106 @lilypond[fragment,verbatim,center]
3107   \relative c'' {
3108     c g c f, c' a, e'' }
3109 @end lilypond
3110
3111 If the preceding item is a chord, the first note of the chord is used
3112 to determine the first note of the next chord.  But other notes
3113 within the second chord are determined by looking at the immediately
3114 preceding note.
3115
3116 @lilypond[fragment,verbatim,center]
3117   \relative c' {
3118     c <c e g> 
3119     <c' e g>
3120     <c, e' g>
3121   }
3122 @end lilypond 
3123 @cindex @code{\notes}
3124
3125 The pitch after the @code{\relative} contains a notename.  To parse
3126 the pitch as a notename, you have to be in note mode, so there must
3127 be a surrounding @code{\notes} keyword (which is not
3128 shown here).
3129
3130 The relative conversion will not affect @code{\transpose} or
3131 @code{\relative} sections in its argument.  If you want to use
3132 relative within transposed music, you must place an additional
3133 @code{\relative} inside the @code{\transpose}.
3134
3135
3136 @c .  {Point and click}
3137 @node Point and click
3138 @subsection Point and click
3139
3140 [todo]
3141
3142 @c . {Engravers}
3143 @node Engravers
3144 @section Engravers
3145 @cindex engravers
3146 @menu
3147 * Notation Contexts::           
3148 * Creating contexts::           
3149 * Default contexts::            
3150 * Context properties::          
3151 * Changing context definitions::  
3152 * Defining new contexts::       
3153 @end menu
3154
3155 @c .  {Music expressions}
3156
3157
3158
3159 @c .  {Notation Contexts}
3160 @node Notation Contexts
3161 @subsection Notation Contexts
3162
3163 @cindex notation contexts
3164
3165 Notation contexts are objects that only exist during a run of LilyPond.
3166 During the interpretation phase of LilyPond (when lily prints
3167 "interpreting music"), music a @code{\score} block is interpreted in
3168 time order, i.e. in much the same order that humans read, play, and
3169 write music.
3170
3171 During this reading, the notation context is holds the state
3172 for the current point within the music. It contains information like
3173
3174 @itemize @bullet
3175   @item What notes are playing at this point?
3176   @item What symbols will be printed at this point?
3177   @item What is the current key signature, time signature, point within
3178        the measure, etc.?
3179 @end itemize
3180
3181 Contexts are grouped hierarchically: A @code{Voice} context is
3182 contained in a @code{Staff} context (because a staff can contain
3183 multiple voices at any point), a @code{Staff} context is contained in
3184 a @code{Score}, @code{StaffGroup}, or @code{ChoirStaff} context (because
3185 these can all contain multiple staffs).
3186
3187
3188 Contexts associated with sheet music output are called @emph{notation
3189 contexts}, those for sound output are called performance contexts.
3190
3191
3192 @node Creating contexts
3193 @subsection Creating contexts
3194
3195 @cindex @code{\context}
3196 @cindex context selection
3197
3198 Contexts for a music expression can be selected manually, using the
3199 following music expression.
3200
3201 @example
3202   \context @var{contexttype} [= @var{contextname}] @var{musicexpr}
3203 @end example
3204
3205 This instructs lilypond to interpret @var{musicexpr} within the context
3206  of type @var{contexttype} and with name @var{contextname}.  If this
3207 context does not exist, it will be created.  
3208
3209 @quotation
3210
3211 @lilypond[verbatim,singleline]
3212 \score {
3213   \notes \relative c'' {
3214     c4 <d4 \context Staff = "another" e4> f
3215   }
3216 }
3217
3218 @end lilypond
3219 @end quotation
3220
3221 In this example, the @code{c} and @code{d} are printed on the
3222 default staff.  For the @code{e}, a context Staff called
3223 @code{another} is specified; since that does not exist, a new
3224 context is created.  Within @code{another}, a (default) Voice context
3225 is created for the @code{e4}.  When all music referring to a
3226 context is finished, the context is ended as well.  So after the
3227 third quarter, @code{another} is removed.
3228
3229
3230
3231 @node Default contexts
3232 @subsection Default contexts
3233
3234 Most music expressions don't need @code{\context}: they inherit the
3235 notation context from their parent. Each note is a music expression, and
3236 as you can see in the following example, only the sequential music
3237 enclosing the three notes has an explicit context. 
3238
3239 @lilypond[verbatim,singleline]
3240 \score { \notes \context Voice = goUp { c'4 d' e' } } 
3241 @end lilypond
3242
3243 There are some quirks that you must keep in mind when dealing with
3244 defaults:
3245
3246 Every top-level music is interpreted by the Score context, in other
3247 words, you may think of @code{\score} working like
3248 @example
3249         \score @{
3250                 \context Score @var{music}
3251         @}
3252 @end example
3253
3254 Sequential music follows the contexts of its "children".  Take this example
3255 @lilypond[verbatim, singleline]
3256 \score { \context Score \notes { c'4 (  d' )e' } }
3257 @end lilypond
3258
3259 The sequential music is interpreted by the Score context initially
3260 (notice that the @code{\context} specification is redundant), but when a
3261 note is encountered, contexts are setup to accept that note. In this
3262 case, a Thread, Voice and Staff are created. The rest of the sequential
3263 music is also interpreted with the same Thread, Voice and Staff context,
3264 putting the notes on the same staff, in the same voice.
3265
3266 This is a convenient mechanism, but do not expect opening chords to work
3267 without @code{\context}. For every note, a separate staff is
3268 instantiated.
3269
3270 @lilypond[verbatim, singleline]
3271 \score { \notes <c'4 es'> } 
3272 @end lilypond
3273
3274 Of course, if the chord is preceded by a normal note in sequential
3275 music, the chord will be interpreted by the Thread of the preceding
3276 note:
3277 @lilypond[verbatim,singleline]
3278 \score { \notes { c'4 <c'4 es'> }  }
3279 @end lilypond
3280
3281
3282
3283 @node Context properties
3284 @subsection Context properties
3285
3286 Notation contexts can be modified from within the @file{.ly} file. The
3287 following music expression does that job:
3288
3289 @cindex @code{\property}
3290 @example
3291   \property @var{contextname}.@var{propname} =  @var{value}
3292 @end example
3293
3294 Sets the @var{propname} property of the context @var{contextname} to the
3295 specified Scheme expression @var{value}.  All @var{propname} and
3296 @var{contextname} are strings, which are typically unquoted.
3297
3298 Properties that are set in one context are inherited by all of the
3299 contained contexts.  This means that a property valid for the
3300 @code{Voice} context can be set in the @code{Score} context (for
3301 example) and thus take effect in all @code{Voice} contexts.
3302
3303
3304
3305
3306 @c .  {Context definitions}
3307 @node Changing context definitions
3308 @subsection Changing context definitions
3309
3310 @cindex context definition
3311 @cindex translator definition
3312
3313 The most common way to define a context is by extending an existing
3314 context.  You can change an existing context from the paper block, by
3315 first initializing a translator with an existing context identifier:
3316 @example
3317 \paper @{
3318   \translator @{
3319     @var{context-identifier}
3320   @} @}
3321 @end example
3322 Then you can add engravers, remove engravers and set context
3323 properties. The syntax for these operations are respectively
3324 @example
3325  \remove @var{engravername}
3326  \consists @var{engravername}
3327  @var{propname} = @var{value} 
3328 @end example
3329
3330 Here @var{engravername} is a string, the name of an engraver in the
3331 system. @var{propname} is a string and @var{value} is a Scheme
3332 expression.
3333
3334 @lilypond[verbatim,singleline]
3335 \score {  \notes {
3336         c'4 c'4 }
3337   \paper {
3338     \translator  { \StaffContext
3339         \consists Instrument_name_engraver;
3340         instrument = #"foo"
3341         \remove Clef_engraver;
3342        } } }
3343 @end lilypond
3344
3345 @cindex engraver
3346
3347 These type of property assignments happen before interpretation starts,
3348 so a @code{\property} expression will override any predefined settings.
3349
3350 Engravers are the actual C++ modules that do the work in the
3351 interpretation phase.
3352
3353
3354 There are some pre-defined identifiers to simplify editing translators,
3355 they are defined in @file{ly/engraver.ly}.  These pre-defined
3356 identifiers are:
3357
3358 @table @code
3359 @cindex @code{StaffContext}
3360   @item @code{StaffContext}  
3361     Default Staff context. 
3362 @cindex @code{RhythmicStaffContext}
3363
3364   @item @code{RhythmicStaffContext}  
3365     Default RhythmicStaff context. 
3366 @cindex @code{VoiceContext}
3367
3368   @item @code{VoiceContext}  
3369     Default Voice context.  
3370 @cindex @code{ScoreContext}
3371
3372   @item @code{ScoreContext}  
3373     Default Score context. 
3374
3375 @cindex @code{HaraKiriStaffContext}
3376
3377   @item @code{HaraKiriStaffContext}  
3378     Staff context that does not print if it only contains rests. 
3379     Useful for orchestral scores.@footnote{Harakiri, also called
3380     Seppuku, is the ritual suicide of the Japanese Samourai warriors.}
3381 @end table
3382
3383 @node Defining new contexts
3384 @subsection Defining new contexts
3385
3386 If you want to build a context from scratch, you must also supply the
3387 following extra information:
3388 @itemize @bullet
3389   @item  A name, specified by @code{\name @var{contextname};}.
3390
3391   @item A cooperation engraver. This is specified by   @code{\type
3392 @var{typename};}.
3393 @end itemize
3394
3395
3396 A context definition has this syntax:
3397
3398 @example
3399
3400   \translator @code{@{}
3401                       @var{translatorinit} @var{translatormodifierlist}
3402                     @code{@}}
3403 @end example
3404
3405 @var{translatorinit} can be an identifier or 
3406 @example
3407
3408 @end example
3409 where @var{typename} is one of
3410
3411 The cooperation engraver groups other engravers, and specifies how they
3412 should cooperate. Choices are:
3413
3414 @table @code
3415 @cindex @code{Engraver_group_engraver}
3416   @item @code{Engraver_group_engraver}  
3417     The standard cooperation engraver.
3418
3419 @cindex @code{Score_engraver}
3420
3421   @item @code{Score_engraver}  
3422     This is cooperation module that should be in the top level context,
3423 and only the toplevel context.
3424
3425 @cindex @code{Grace_engraver_group}
3426
3427   @item @code{Grace_engraver_group}  
3428     This is a special cooperation module (resembling
3429     @code{Score_engraver}) that is used to created an embedded
3430     `miniscore'.
3431 @end table 
3432
3433 @var{translatormodifierlist} is a list of items where each item is
3434 one of
3435
3436 @itemize @bullet
3437   @item  @code{\consists} @var{engravername} @code{;}  
3438     Add @var{engravername} to the list of modules in this context. 
3439   The order of engravers added with @code{\consists} is
3440     significant.
3441   
3442   @item  @code{\consistsend} @var{engravername} @code{;}  
3443     Analogous to @code{\consists}, but makes sure that
3444     @var{engravername} is always added to the end of the list of
3445     engravers.
3446
3447     Some engraver types need to be at the end of the list; this
3448     insures they are put there, and stay there, if a user adds or
3449     removes engravers.  This command is usually not needed for
3450     end-users.
3451     
3452   @item  @code{\accepts} @var{contextname} @code{;}  
3453     Add @var{contextname} to the list of  context this context can
3454     contain.  The first listed context is the context to create by
3455     default.
3456
3457   @item @code{\denies}. The opposite of @code{\accepts}. Added for
3458 completeness, but is never used in practice.
3459  
3460   
3461   @item  @code{\remove} @var{engravername} @code{;}  
3462     Remove a previously added (with @code{\consists}) engraver.
3463   
3464   @item  @code{\name} @var{contextname} @code{;}  
3465     This sets name of the context, e.g. @code{Staff}, @code{Voice}.  If
3466     the name is not specified, the translator won't do anything.
3467
3468   @item  @var{propname} @code{=} @var{value} @code{;}  
3469     A property assignment.
3470 @end itemize
3471
3472 In the @code{\paper} block, it is also possible to define translator
3473 identifiers.  Like other block identifiers, the identifier can only
3474 be used as the very first item of a translator.  In order to define
3475 such an identifier outside of @code{\score}, you must do
3476
3477 @quotation
3478
3479 @example 
3480 \paper @{
3481   foo = \translator @{ @dots{} @}
3482 @}
3483 \score @{
3484   \notes @{
3485     @dots{}
3486   @}
3487   \paper @{
3488     \translator @{ \foo @dots{} @}
3489   @}
3490 @} 
3491 @end example 
3492
3493 @end quotation
3494
3495
3496 @cindex paper types, engravers, and pre-defined translators
3497
3498       
3499
3500
3501         Properties can be preset within the @code{\translator} block
3502 corresponding to the appropriate context.  In this case, the syntax
3503 is
3504
3505 @example
3506   @var{propname} @code{=} @var{value}
3507 @end example
3508
3509 The property settings are used during the interpretation phase.  They
3510 are read by the LilyPond modules where interpretation contexts are
3511 built of.  These modules are called @emph{translators}.  Translators for
3512 notation are called @emph{engravers}, and translators for sound are
3513 called @emph{performers}.
3514
3515
3516
3517
3518 @c . {Syntactic details}
3519 @node Syntactic details
3520 @section Syntactic details
3521 @cindex Syntactic details
3522 @menu
3523 * Top level::                   
3524 * Identifiers::                 
3525 * Music expressions::           
3526 * Manipulating music expressions::  
3527 * Assignments::                 
3528 * Lexical details::             
3529 * Lexical modes::               
3530 * Ambiguities::                 
3531 @end menu
3532
3533 @c .  {Top level}
3534 @node Top level
3535 @subsection Top level
3536 @cindex Top level
3537
3538 This section describes what you may enter at top level.
3539
3540
3541 @c .   {Score}
3542 @subsubsection Score
3543 @cindex Score
3544
3545 @cindex score definition
3546
3547 The output is generated combining a music expression with an output
3548 definition.  A score block has the following syntax:
3549
3550 @example
3551   \score @{ @var{musicexpr} @var{outputdefs} @}
3552 @end example
3553
3554 @var{outputdefs} are zero or more output definitions.  If no output
3555 definition is supplied, the default @code{\paper} block will be added.
3556
3557
3558
3559 @c .   {Default output}
3560 @subsubsection Default output
3561
3562 Default values for the @code{\paper} and @code{\midi} block are set by
3563 entering such a block at top-level.
3564
3565 @c .   {Header}
3566 @subsubsection Header
3567 @cindex Header
3568 @cindex @code{\header}
3569
3570 The syntax is
3571
3572 @example
3573   \header @{ @var{key1} = @var{val1};
3574 @cindex @code{ly2dvi}
3575              @var{key2} = @var{val2}; @dots{} @}
3576 @end example
3577
3578
3579 A header describes the file's contents.  It can also appear in a
3580 @code{\score} block.  Tools like @code{ly2dvi} can use this
3581 information for generating titles.  Key values that are used by
3582 @code{ly2dvi} are: title, subtitle, composer, opus, poet, instrument,
3583 metre, arranger, piece and tagline.
3584
3585 It is customary to put the @code{\header} at the top of the file.
3586
3587 @subsubsection Default output
3588
3589 A @code{\midi} or @code{\paper} block at top-level sets the default
3590
3591 paper block for all scores that lack an explicit paper block.
3592
3593 @c .  {Identifiers}
3594 @node Identifiers
3595 @subsection Identifiers
3596 @cindex  Identifiers
3597
3598 All of the information in a LilyPond input file, is represented as a
3599 Scheme value. In addition to normal Scheme data types (such as pair,
3600 number, boolean, etc.), LilyPond has a number of specialized data types,
3601
3602 @itemize @bullet
3603 @item Input
3604 @item c++-function
3605 @item Music
3606 @item Identifier
3607 @item Translator_def
3608 @item Duration
3609 @item Pitch
3610 @item Score
3611 @item Music_output_def
3612 @item Moment (rational number)
3613 @end itemize
3614
3615 LilyPond also includes some transient object types. Objects of these
3616 types are built during a LilyPond run, and do not `exist' per se within
3617 your input file. These objects are created as a result of your input
3618 file, so you can include commands in the input to manipulate them,
3619 during a lilypond run.
3620
3621 @itemize @bullet
3622 @item Grob: short for Graphical object. See @ref{Grobs}. 
3623 @item Molecule: device-independent page output object,
3624 including dimensions.  Produced by some Grob functions
3625 See @ref{Molecules}
3626 @item Translator: object that produces audio objects or Grobs. This is
3627 not yet user accessible.
3628 @item Font_metric: object representing a font. (See @ref{Font metrics})
3629
3630 @end itemize
3631
3632
3633 @node Music expressions
3634 @subsection Music expressions
3635
3636 @cindex music expressions
3637
3638 Music in LilyPond is entered as a music expression.  Notes, rests, lyric
3639 syllables are music expressions, and you can combine music expressions
3640 to form new ones, for example by enclosing a list of expressions in
3641 @code{\sequential @{ @}} or @code{< >}.  In this example, a compound
3642 expression is formed out of the quarter note @code{c} and a quarter note
3643 @code{d}:
3644
3645 @example 
3646 \sequential @{ c4 d4 @} 
3647 @end example 
3648
3649 @cindex Sequential music
3650 @cindex @code{\sequential}
3651 @cindex sequential music
3652 @cindex @code{<}
3653 @cindex @code{>}
3654 @cindex Simultaneous music
3655 @cindex @code{\simultaneous}
3656
3657 The two basic compound  music expressions are simultaneous  and
3658 sequential music.
3659
3660 @example
3661   \sequential @code{@{} @var{musicexprlist} @code{@}}
3662   \simultaneous @code{@{} @var{musicexprlist} @code{@}}
3663 @end example
3664 For both, there is a shorthand:
3665 @example
3666   @code{@{} @var{musicexprlist} @code{@}}
3667 @end example
3668 for sequential and
3669 @example
3670   @code{<} @var{musicexprlist} @code{>}
3671 @end example
3672 for simultaneous music.
3673 Other compound music expressions include
3674 @example
3675  \repeat @var{expr}
3676  \transpose @var{pitch} @var{expr}
3677  \apply @var{func} @var{expr}
3678  \context @var{type} = @var{id} @var{expr}
3679  \times @var{fraction} @var{expr}
3680 @end example
3681
3682 In principle, the way in which you nest sequential and simultaneous to
3683 produce music is not relevant.  In the following example, three chords
3684 are expressed in two different ways:
3685
3686 @lilypond[fragment,verbatim,center]
3687   \notes \context Voice {
3688     <a c'> <b  d' > <c' e'>
3689     < { a b  c' } { c' d' e' } >
3690   }
3691 @end lilypond
3692
3693 However, in some cases, LilyPond will also try to choose contexts, and
3694 use the structure of the music expression  to do so. This can have
3695 undesired effects: for example, LilyPond will create a separate staff
3696 for each note if you start a @code{\score} with a  chord:
3697 @lilypond[verbatim,center,singleline]
3698   \score {
3699     \notes <c''4 e''>
3700   }
3701 @end lilypond
3702   The solution is to explicitly instantiate the context you desire.
3703 In this case this is typically a Voice context
3704 @lilypond[verbatim,center,singleline]
3705   \score {
3706     \notes\context Voice <c''4 e''>
3707   }
3708 @end lilypond
3709 If you use @code{\context Staff} you will get separate stems for each
3710 note head, leading to collisions, so don't use that.
3711
3712
3713
3714 @c . {Manipulating music expressions}
3715 @node Manipulating music expressions
3716 @subsection  Manipulating music expressions
3717
3718 The @code{\apply} mechanism gives you access to the internal
3719 representation of music. You can write Scheme-functions that operate
3720 directly on it. The syntax is 
3721 @example
3722         \apply #@var{func} @var{music}
3723 @end example
3724 This means that @var{func} is applied to @var{music}.  The function
3725 @var{func} should return a music expression.
3726
3727 This example replaces the text string of a script. It also shows a dump
3728 of the music it processes, which is useful if you want to know more
3729 about how music is stored.
3730 @lilypond[verbatim]
3731 #(define (testfunc x)
3732         (if (equal? (ly-get-mus-property x 'text) "foo")
3733                 (ly-set-mus-property x 'text "bar"))
3734         ;; recurse
3735         (ly-set-mus-property x 'elements
3736           (map testfunc (ly-get-mus-property x 'elements)))
3737         (display x)
3738         x        
3739 )
3740 \score { \notes
3741   \apply #testfunc { c4_"foo" }
3742
3743 @end lilypond
3744
3745 For more information on what is possible, see the @ref{Tricks} and the
3746 automatically generated documentation.
3747
3748 As always: directly accessing internal representations is dangerous: the
3749 implementation is subject to changes, so you should not use this if
3750 possible.
3751
3752
3753 @c .   {Assignments}
3754 @node Assignments
3755 @subsection Assignments
3756 @cindex Assignments
3757
3758 Identifiers allow objects to be assigned to names during the parse
3759 stage.  To assign an identifier, you use @var{name}@code{=}@var{value}
3760 and to refer to an identifier, you preceed its name with a backslash:
3761 `@code{\}@var{name}'.  @var{value} is any valid Scheme value or any of
3762 the input-types listed above.  Identifier assignments can appear at top
3763 level in the LilyPond file, but also in @code{\paper} blocks.
3764
3765 Semicolons are forbidden after top level assignments, but mandatory in
3766 other places. The rules about semicolons and assignments are very
3767 confusing, but when LilyPond input evolves more towards Scheme, we hope
3768 that this problem will grow smaller.
3769
3770 An identifier can be created with any string for its name, but you will
3771 only be able to refer to identifiers whose names begin with a letter,
3772 being entirely alphabetical.  It is impossible to refer to an identifier
3773 whose name is the same as the name of a keyword.
3774
3775 The right hand side of an identifier assignment is parsed completely
3776 before the assignment is done, so it is allowed to redefine an
3777 identifier in terms of its old value, e.g.
3778
3779 @example
3780 foo = \foo * 2.0
3781 @end example
3782
3783 When an identifier is referenced, the information it points to is
3784 copied.  For this reason, an identifier reference must always be the
3785 first item in a block.
3786 @example
3787 \paper  @{
3788         foo = 1.0
3789         \paperIdent % wrong and invalid
3790 @}
3791
3792 \paper @{
3793         \paperIdent % correct
3794         foo = 1.0 @}
3795 @end example
3796
3797 @c .  {Lexical details}
3798 @node Lexical details
3799 @subsection Lexical details
3800 @cindex Lexical details
3801 @menu
3802 @end menu
3803
3804 @c .   {Comments}
3805 @subsubsection Comments
3806 @cindex Comments
3807
3808 @cindex @code{%}
3809
3810
3811 A one line comment is introduced by a @code{%} character. 
3812 Block comments are started by @code{%@{} and ended by @code{%@}}. 
3813 They cannot be nested.
3814
3815 @c .  {Direct Scheme}
3816 @subsubsection Direct Scheme
3817 @cindex Scheme
3818 @cindex GUILE
3819 @cindex Scheme, in-line code
3820
3821
3822 LilyPond contains a Scheme interpreter (the GUILE library) for
3823 internal use. In some places Scheme expressions also form valid syntax:
3824 whereever it is allowed,
3825 @example
3826   #@var{scheme}
3827 @end example
3828 evaluates the specified Scheme code. If this is used at toplevel, then
3829 the result is discarded. Example:
3830 @example
3831   \property Staff.TestObject \override #'foobar =  #(+ 1 2)
3832 @end example
3833
3834 @code{\override} expects two Scheme expressions, so there are two Scheme
3835 expressions. The first one is a symbol (@code{foobar}), the second one
3836 an integer (namely, 3).
3837
3838 Scheme is a full-blown programming language, and a full discussion is
3839 outside the scope of this document. Interested readers are referred to
3840 the website @uref{http://www.schemers.org/} for more information on
3841 Scheme.
3842
3843
3844 @c .   {Keywords}
3845 @subsubsection Keywords
3846 @cindex Keywords
3847
3848
3849 Keywords start with a backslash, followed by a number of lower case
3850 alphabetic characters.  These are all the keywords.
3851
3852 @example
3853 apply arpeggio autochange spanrequest commandspanrequest
3854 simultaneous sequential accepts alternative bar breathe
3855 char chordmodifiers chords clef cm consists consistsend
3856 context denies duration dynamicscript elementdescriptions
3857 font grace header in lyrics key mark pitch
3858 time times midi mm name pitchnames notes outputproperty
3859 override set revert partial paper penalty property pt
3860 relative remove repeat addlyrics partcombine score
3861 script stylesheet skip textscript tempo translator
3862 transpose type
3863 @end example
3864
3865 @c .   {Integers}
3866 @subsubsection Integers
3867
3868 @cindex integers
3869 @cindex @code{+}
3870 @cindex @code{-}
3871 @cindex @code{*}
3872 @cindex @code{/}
3873
3874 Formed from an optional minus sign followed by digits.  Arithmetic
3875 operations cannot be done with integers, and integers cannot be mixed
3876 with reals.
3877
3878 @c .   {Reals}
3879 @subsubsection Reals
3880 @cindex real numbers
3881
3882
3883
3884
3885
3886 Formed from an optional minus sign and a sequence of digits followed
3887 by a @emph{required} decimal point and an optional exponent such as
3888 @code{-1.2e3}.  Reals can be built up using the usual operations:
3889 `@code{+}', `@code{-}', `@code{*}', and
3890 `@code{/}', with parentheses for grouping.
3891
3892 @cindex @code{\mm},
3893 @cindex @code{\in}
3894 @cindex @code{\cm}
3895 @cindex @code{\pt}
3896 @cindex dimensions
3897
3898 A real constant can be followed by one of the dimension keywords:
3899 @code{\mm} @code{\pt}, @code{\in}, or @code{\cm}, for millimeters,
3900 points, inches and centimeters, respectively.  This converts the number
3901 to a real that is the internal representation of dimensions.
3902
3903
3904 @c .   {Strings}
3905 @subsubsection Strings
3906 @cindex string
3907 @cindex concatenate
3908
3909 Begins and ends with the @code{"} character.  To include a @code{"}
3910 character in a string write @code{\"}.  Various other backslash
3911 sequences have special interpretations as in the C language.  A string
3912 that contains no spaces can be written without the quotes.  See
3913 @ref{Lexical modes} for details on unquoted strings; their
3914 interpretation varies depending on the situation.  Strings can be
3915 concatenated with the @code{+} operator.
3916
3917 The tokenizer accepts the following commands. They have no grammatical
3918 function, hence they can appear anywhere in the input.
3919
3920
3921 @c .   {Main input}
3922 @subsubsection Main input
3923 @cindex Main input
3924
3925 @cindex @code{\maininput}
3926
3927 The @code{\maininput} command is used in init files to signal that the
3928 user file must be read. This command cannot be used in a user file.
3929
3930 @c .   {File inclusion}
3931 @subsubsection Main input
3932 @cindex Main input
3933
3934 @subsubsection File inclusion
3935 @cindex @code{\include}
3936 @example
3937   \include @var{filename}
3938 @end example
3939
3940 Include @var{filename}.  The argument @var{filename} may be a quoted string (an
3941 unquoted string will not work here!) or a string identifier.  The full
3942 filename including the @file{.ly} extension must be given,
3943
3944 @subsubsection Version information 
3945 @cindex @code{\version}
3946 @example
3947   \version @var{string} ;
3948 @end example
3949
3950 Specify the version of LilyPond that a file was written for.  The
3951 argument is a version string in quotes, for example @code{"1.2.0"}. 
3952 This is used to detect invalid input, and to aid
3953 @code{convert-ly}  a tool that automatically upgrades input files. See
3954 See @ref{convert-ly} for more information on @code{convert-ly}.
3955
3956 @cindex convert-ly
3957
3958
3959 @c .   {Pitch names}
3960 @subsubsection Defining pitch names
3961 @cindex Lexical modes
3962 @cindex definining pitch names
3963 @cindex pitch names, definining
3964 @cindex note names
3965 @cindex chord modifier names
3966
3967 A @code{\paper} block at top level sets the default paper block.  A
3968 @code{\midi} block at top level works similarly.
3969
3970 @c .   {Assignments}
3971 @subsubsection Assignments
3972 @cindex assignments
3973 @cindex @code{#}
3974
3975 Identifier assignments may appear at top level.  @ref{Assignments}
3976
3977
3978
3979 @c .    {Direct scheme}
3980 @subsubsection Direct scheme
3981 @cindex Direct scheme
3982
3983 Scheme statements maybe issued to produce interesting side-effects. 
3984
3985
3986 @c .  {Lexical modes}
3987 @node Lexical modes
3988 @subsection Lexical modes
3989 @cindex Lexical modes
3990 @cindex input mode
3991 @cindex mode, input 
3992 @cindex @code{\notes}
3993 @cindex @code{\chords}
3994 @cindex @code{\lyrics}
3995
3996 To simplify entering notes, lyrics, and chords, LilyPond has three
3997 special input modes on top of the default mode: note, lyrics and chords
3998 mode.  These input modes change the way that normal, unquoted words are
3999 interpreted: for example, the word @code{cis} may be interpreted as a
4000 C-sharp, as a lyric syllable `cis' or as a C-sharp major triad
4001 respectively.
4002
4003 A mode switch is entered as a compound music expressions
4004 @example
4005 @code{\notes} @var{musicexpr}
4006 @code{\chords} @var{musicexpr}
4007 @code{\lyrics}  @var{musicexpr}.
4008 @end example
4009
4010 In each of these cases, these expressions do not add anything to the
4011 meaning of their arguments.  They are just a way to indicate that the
4012 arguments should be parsed in indicated mode.  The modes are treated in
4013 more detail in the sections @ref{Note entry}, @ref{Lyrics} and
4014 @ref{Chords}.
4015
4016 You may nest different input modes.
4017
4018 @c .  {Ambiguities}
4019 @node Ambiguities
4020 @subsection Ambiguities
4021 @cindex ambiguities
4022 @cindex grammar
4023
4024
4025 The grammar contains a number of ambiguities. We hope to resolve them at
4026 some time.
4027
4028 @itemize @bullet
4029   @item  The assignment
4030
4031          @example 
4032 foo = bar 
4033 @end example 
4034
4035        can be interpreted as making a string identifier @code{\foo}
4036        containing @code{"bar"}, or a music identifier @code{\foo}
4037        containing the syllable `bar'.
4038
4039   @item  The assignment
4040
4041          @example 
4042 foo = -6 
4043 @end example 
4044
4045        can be interpreted as making an integer identifier
4046        containing -6, or a Request identifier containing the
4047        fingering `6' (with neutral direction).
4048
4049   @item  If you do a nested repeat like
4050
4051        @quotation
4052
4053 @example 
4054 \repeat @dots{}
4055 \repeat @dots{}
4056 \alternative 
4057 @end example 
4058
4059        @end quotation
4060
4061        then it is ambiguous to which @code{\repeat} the
4062        @code{\alternative} belongs.  This is the classic if-then-else
4063        dilemma.  It may be solved by using braces.
4064
4065   @item  (an as yet unidentified ambiguity :-)
4066 @end itemize
4067
4068
4069
4070
4071
4072 @c .{Local emacs vars}
4073 @c Local variables:
4074 @c mode: texinfo
4075 @c minor-mode: font-lock
4076 @c minor-mode: outline
4077 @c outline-layout: (-1 : 0)
4078 @c outline-use-mode-specific-leader: "@c \."
4079 @c outline-primary-bullet: "{"
4080 @c outline-stylish-prefixes: nil
4081 @c outline-override-protect: t
4082 @c End:
4083