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