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