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