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