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