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