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