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