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