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