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