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