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