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