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