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