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