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