]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/refman.itely
patch::: 1.3.124.jcn1
[lilypond.git] / Documentation / user / refman.itely
1 @c -*-texinfo-*-
2 @c TODO: 
3 @c - Reinsert subsection commands that were lost in the
4 @c   ancient conversion from YODL!  /MB
5 @c - Restructure! Separate internal commands from user level commands. /MB
6 @c - Add some words about Guile.  /MB
7 @c - Fix indexing (keyindex) so it doesn't add line breaks  /MB
8 @c
9 @c FIXME: Index has two alphabetically sorted lists @code vs plain?
10 @c 
11 @c If we'd include the auto-generated documentation, we 'd get a lot of
12 @c very useful index entries.
13 @c 
14
15
16 @node Reference Manual
17 @chapter Reference Manual
18
19 @menu
20 * Overview::                       Overview
21 * Top level::                      Top level
22 * Pitch names::                    Pitch names
23 * Lexical conventions::            Lexical conventions
24 * Other languages::                Note names in various languages
25 * Lexical modes::                          modes
26 * Types::                          Types
27 * Music expressions::              Music expressions
28 * Atomic music expressions::       Atomic music expressions
29 * Note specification::             notedesc
30 * barlines::                       barlines
31 * Manual beams::                   Manual beam
32 * stem tremolo::                   tremolo
33 * Compound music expressions::     Compound music expressions
34 * relative::                       relative
35 * Repeats::                        Repeats      
36 * transpose::                      transpose
37 * Ambiguities::                    Ambiguities
38 * Notation conversion specifics::  Notation conversion specifics
39 * Automatic Beaming::              Automatic Beaming
40 * Chord Names::                    Chord Names
41 * lyricprint::                     lyricprint
42 * Notation Contexts::              Notation Contexts
43 * Properties::                     Changing formatting
44 * Page layout::                    Layout
45 * contextdefs::                    contextdefs
46 * Sound output::                   Sound output
47 * midilist::                       midilist
48 * Pre-defined Identifiers::        Pre-defined Identifiers
49 * Interpretation contexts:(lilypond-internals)LilyPond interpretation contexts.
50 * Engravers:(lilypond-internals)LilyPond engravers.
51 * Backend:(lilypond-internals)LilyPond backend.
52 @end menu
53
54
55
56 @node Overview
57 @section Overview
58
59
60 This document@footnote{This document has been revised for LilyPond 1.2.}
61 describes the the GNU LilyPond input format This format represents a
62 piece of music in an elegant way, but contains enough information for
63 both automatic typesetting and automatic performances.
64
65
66 LilyPond input can be classified  into three types:
67 @itemize @bullet
68   @item musical expressions: a musical expression is some combination of
69 rest, notes, lyrics
70   @item output definitions: recipes for translating those musical
71 expressions into performances (MIDI) or graphics (eg. PostScript).
72
73   @item declarations: by declaring and naming musical expressions, you
74 can enter and edit them in manageable chunks.
75 @end itemize
76
77 @node Top level
78 @section Top level
79
80 This section describes what you may enter at top level.
81
82
83
84 @cindex score definition
85
86 The output is generated combining a music expression with an output
87 definition.  A score block has the following syntax:
88
89 @example
90   \score @{ @var{musicexpr} @var{outputdefs} @}
91 @end example
92
93 @var{outputdefs} are zero or more output definitions.  If no output
94 definition is supplied, the default @code{\paper} block will be added.
95
96 @cindex header
97
98 @keyindex{header}
99
100 The syntax is
101
102 @example
103   \header @{ @var{key1} = @var{val1};
104              @var{key2} = @var{val2}; @dots{} @}
105 @end example
106
107 A header describes the file's contents.  It can also appear in a
108 @code{\score} block.  Tools like @code{ly2dvi}@indexcode{ly2dvi} can use this
109 information for generating titles.  Key values that are used by
110 @code{ly2dvi} are: title, subtitle, composer, opus, poet, instrument,
111 metre, arranger, piece and tagline.
112
113 It is customary to put the @code{\header} at the top of the file.
114
115 @node Pitch names
116 @section Pitch names
117
118
119 @cindex pitch names
120 @cindex note names
121 @cindex chord modifier names
122
123 Note names and chord modifiers can be customised for nationalities.
124 languages and conventions.  The syntax is as follows.
125 @example
126    \pitchnames@keyindex{pitchnames} @var{scheme-alist}
127    \chordmodifiers@keyindex{chordmodifiers} @var{scheme-alist}
128 @end example
129
130 See @file{ly/nederlands.ly} and @file{ly/chord-modifiers.ly} for
131 specific examples how to do this.  tables can be tailored specified
132 using. Some national note names have been provided, see
133 section @ref{Other languages}.
134 A @code{\paper} block at top level sets the default paper block.  A
135 @code{\midi} block at top level works similarly.
136
137 Identifier assignments may appear at top level.  Semicolons are
138 forbidden after top level assignments.
139
140 @cindex assignments
141
142 @node Lexical conventions
143 @section Lexical conventions
144
145 @cindex lexical conventions
146
147
148 @unnumberedsubsec Comments
149
150 @cindex comment
151
152 @indexcode{%}
153
154 A one line comment is introduced by a `@code{%}' character. 
155 Block comments are started by `@code{%@{}' and ended by `@code{%@}}'. 
156 They cannot be nested.
157
158 @unnumberedsubsec Scheme
159
160 @indexcode{#}
161
162 LilyPond contains a Scheme interpreter (the GUILE library) for
163 internal use. The interpreter is accessed by the pound sign:
164
165 @cindex Scheme
166 @cindex GUILE
167 @cindex Scheme, in-line code
168
169 Whereever the syntax allows Scheme expressions, you may enter one as
170
171 @example
172   #@var{scheme}
173 @end example
174
175 Evaluates the specified Scheme code. If this is used at toplevel, then
176 the result is discarded. Example:
177 @example
178   \property Staff.TestObject \override #'symbol =  #(+ 1 2)
179 @end example
180
181 (in this case, @code{\override} expects two Scheme expressions. 
182
183 [refer appendix/ online intro on Scheme] 
184
185 @unnumberedsubsec Keywords
186
187 @cindex keyword
188
189 Keywords start with a backslash, followed by a number of lower case
190 alphabetic characters.  These are all the keywords.
191
192 @example
193 apply arpeggio autochange spanrequest commandspanrequest
194 simultaneous sequential accepts alternative bar breathe
195 char chordmodifiers chords clef cm consists consistsend
196 context denies duration dynamicscript elementdescriptions
197 font grace header in lyrics key mark musicalpitch
198 time times midi mm name pitchnames notes outputproperty
199 override set revert partial paper penalty property pt
200 relative remove repeat addlyrics partcombine score
201 script stylesheet skip textscript tempo translator
202 transpose type
203 @end example
204
205 @unnumberedsubsec Integers
206
207 @cindex integer
208
209 Formed from an optional minus sign followed by digits.  Arithmetic
210 operations cannot be done with integers, and integers cannot be mixed
211 with reals.
212
213 @unnumberedsubsec Reals
214
215 @cindex real
216  
217
218 Formed from an optional minus sign and a sequence of digits followed
219 by a @emph{required} decimal point and an optional exponent such as
220 @code{-1.2e3}.  Reals can be built up using the usual operations:
221 `@code{+}@indexcode{+}', `@code{-}@indexcode{-}', `@code{*}@indexcode{*}', and
222 `@code{/}@indexcode{/}', with parentheses for grouping.
223
224 A real constant can be followed by one of the dimension
225 keywords:
226 @cindex dimensions
227  @code{\mm}@keyindex{mm},
228 @code{\pt}@keyindex{pt}, @code{\in}@keyindex{in}, or
229 @code{\cm}@keyindex{cm}, for millimeters, points, inches and
230 centimeters, respectively.  This converts the number to a real that
231 is the internal representation of dimensions.
232
233
234 @unnumberedsubsec
235 @cindex string
236  
237 Begins and ends with the `@code{"}' character.  To include a `@code{"}'
238 character in a string write `@code{\"}'.  Various other backslash
239 sequences have special interpretations as in the C language.  A string
240 that contains no spaces can be written without the quotes.  See
241 @ref{Lexical modes} for details on unquoted strings; their interpretation varies
242 depending on the situation.  Strings can be concatenated with the
243 `@code{+}' operator.
244
245 The tokenizer accepts the following commands. They have no grammatical
246 function, hence they can appear anywhere in the input.
247
248 @example
249   \maininput@keyindex{maininput}
250 @end example
251
252 This command is used in init files to signal that the user file must
253 be read. This command cannot be used in a user file.
254
255 @unnumberedsubsec file inclusion
256
257 @example
258   \include@keyindex{include} @var{file}
259 @end example
260
261 Include @var{file}.  The argument @var{file} may be a quoted string (an
262 unquoted string will not work here!) or a string identifier.  The full
263 filename including the @file{.ly} extension must be given,
264
265 @unnumberedsubsec Version information 
266
267 @example
268   \version@keyindex{version} @var{string} ;
269 @end example
270
271 Specify the version of LilyPond that a file was written for.  The
272 argument is a version string in quotes, for example @code{"1.2.0"}. 
273 This is used to detect invalid input, and to aid
274 @code{convert-ly}, a tool that automatically upgrades input files.
275 @cindex convert-ly
276
277 @node Other languages
278 @section Other languages
279 @cindex Note names, international
280
281 Note name definitions have been provided in various languages. 
282 Simply include the language specific init file.  For example:
283 `@code{\include "english.ly"}'.  The available language files and the
284 names they define are:
285
286 @example 
287                         Note Names               sharp       flat
288 nederlands.ly  c   d   e   f   g   a   bes b   -is         -es
289 english.ly     c   d   e   f   g   a   bf  b   -s/-sharp   -f/-flat
290 deutsch.ly     c   d   e   f   g   a   b   h   -is         -es
291 norsk.ly       c   d   e   f   g   a   b   h   -iss/-is    -ess/-es
292 svenska.ly     c   d   e   f   g   a   b   h   -iss        -ess
293 italiano.ly    do  re  mi  fa  sol la  sib si  -d          -b
294 catalan.ly     do  re  mi  fa  sol la  sib si  -d/-s       -b 
295 @end example 
296
297 Pitch names can be redefined using the @code{\pitchnames} command, see
298 @ref{Pitch names}.
299
300 @node Lexical modes
301 @section Lexical modes
302 @cindex Lexical modes
303 @cindex modes
304
305
306 To simplify entering notes, lyrics, and chords, @emph{Lilypond} has three
307 special input modes on top of the default mode.  In each mode, words
308 are identified on the input.  If @code{"word"} is encountered, it is
309 treated as a string.  If @code{\word} is encountered, it is treated as
310 a keyword or as an identifier.  The behavior of the modes differs in
311 two ways: Different modes treat unquoted words differently, and
312 different modes have different rules for deciding what is a word.
313
314 @table @samp
315   @item Normal mode.
316 @cindex mode!normal
317  
318     At the start of parsing, @emph{Lilypond} is in Normal mode.  In Normal
319     mode, a word is an alphabetic character followed by alphanumeric
320     characters.  If @code{word} is encountered on the input it is
321     treated as a string.
322
323   @item Note mode.
324 @cindex mode!note
325
326     Note mode is introduced by the keyword
327     @code{\notes}@keyindex{notes}.  In Note mode, words can only
328     contain alphabetic characters.  If @code{word} is encountered,
329     LilyPond first checks for a notename of @code{word}.  If no
330     notename is found, then @code{word} is treated as a string.
331
332     Since combinations of numbers and dots are used for indicating
333     durations, it is not possible to enter real numbers in this mode.
334
335   @item Chord mode.
336 @cindex mode!chord
337
338     Chord mode is introduced by the keyword
339     @code{\chords}@keyindex{chords}.  It is similar to Note mode, but
340     words are also looked up in a chord modifier table (containing
341     @code{maj}, @code{dim}, etc).
342
343     Since combinations of numbers and dots are used for indicating
344     durations, you can not enter real numbers in this mode.  Dashes
345     and carets are used to indicate chord additions and subtractions,
346     so scripts can not be entered in Chord mode.
347
348   @item Lyrics mode. 
349 @cindex mode!lyric
350
351     Lyrics mode is introduced by the keyword
352     @code{\lyrics}@keyindex{lyrics}.  This mode has rules that make it
353     easy to include punctuation and diacritical marks in words.  A
354     word in Lyrics mode begins with: an alphabetic character,
355     `@code{_}', `@code{?}', `@code{!}', `@code{:}', `@code{'}', the
356     control characters @code{^A} through @code{^F}, @code{^Q} through
357     @code{^W}, @code{^Y}, @code{^^}, any 8-bit character with ASCII code
358     over 127, or a two-character combination of a backslash followed
359     by one of `@code{`}', `@code{'}', `@code{"}', or
360     `@code{^}'.@footnote{The purpose of Lyrics mode is that you can
361     enter lyrics in @TeX{} format or a standard encoding without
362     needing quotes.  The precise definition of this mode indeed is
363     ludicrous.  This will remain so until the authors of LilyPond
364     acquire a deeper understanding of character encoding, or someone
365     else steps up to fix this.}
366
367     Subsequent characters of a word can be any character that is not
368     a digit and not white space.  One important consequence of this
369     is that a word can end with `@code{@}}', which may be confusing if
370     you thought the closing brace was going to terminate Lyrics
371     mode.@footnote{LilyPond will issue a warning, though.}  Any
372     `@code{_}' character which appears in an unquoted word is
373     converted to a space.  This provides a mechanism for introducing
374     spaces into words without using quotes.  Quoted words can also be
375     used in Lyrics mode to specify words that cannot be written with
376     the above rules.  Here are some examples.  Not all of these words
377     are printable by @TeX{}.
378
379 @example 
380 Ah!             % a word
381 2B_||_!2B       % not a word because it starts with a digit
382 ``Hello''       % not a word because it starts with `
383 _ _ _ _         % 4 words, each one a space 
384 @end example 
385
386     Since combinations of numbers and dots are used for indicating
387     durations, you can not enter real numbers in this mode.
388 @end table
389
390 [todo: include short table showign differences] 
391
392 @node Types
393 @section Types
394
395 @cindex  Identifiers
396
397 [say something about types]
398
399 All of the information in a LilyPond input file, is represented as a
400 Scheme value. In addition to normal Scheme data types (such as pair,
401 number, boolean, etc.), LilyPond has a number of specialized data types,
402
403 @itemize @bullet
404   @item Input
405   @item c++-function
406   @item Music: see @ref{Music expressions}
407   @item Identifier
408   @item Translator_def:
409 See section @ref{contextdefs} for more information
410
411   @item Duration
412   @item Pitch
413   @item Score
414   @item Music_output_def (TODO: this is not really a Scheme object
415 yet. Nevertheless, you can use identifiers to make references to them )
416   @item Moment (rational number)
417 @end itemize
418
419 LilyPond also includes some transient object types. Objects of these
420 types are built during a LilyPond run, and do not `exist' per se within
421 your input file. These objects are created as a result of your input
422 file, so you can include commands in the input to manipulate them,
423 during a lilypond run.
424
425 @itemize @bullet
426   @item Grob: short for Graphical object. See @ref{Grobs}. 
427   @item Molecule: device-independent page output object,
428     including dimensions.  Produced by some Grob functions
429     See @ref{Molecules}
430   @item Translator: object that produces audio objects or Grobs. This is
431 not yet user accessible.
432   @item Font_metric: object representing a font. (See @ref{Font metrics})
433 @c  @item Audio_element: (todo,  smobme)
434 @end itemize
435
436 Identifiers allow objects to be assigned to names during the parse
437 stage.  To assign an identifier, you use `@var{name}=@var{value}' and to
438 refer to an identifier, you preceed its name with a backslash:
439 `@code{\}@var{name}'.  Identifier assignments must appear at top level
440 in the @emph{Lilypond} file.  Semicolons are forbidden after assignments
441 appearing at top level but they are obligatory after assignments
442 appearing in the @code{\paper} block, see Section @ref{Page layout}.
443
444 @var{value} is any valid Scheme value or any of the input-types listed
445 above.
446
447 An identifier can be created with any string for its name, but you will
448 only be able to refer to identifiers whose names begin with a letter,
449 being entirely alphanumeric.  It is impossible to refer to an identifier
450 whose name is the same as the name of a keyword.
451
452 The right hand side of an identifier assignment is parsed completely
453 before the assignment is done, so it is allowed to redefine an
454 identifier in terms of its old value, e.g.
455
456 @example
457   foo = \foo * 2.0
458 @end example
459
460 When an identifier is referenced, the information it points to is
461 copied.  For this reason, an identifier reference must always be the
462  first item in a block.
463 @example
464 \paper  @{
465    foo = 1.0
466    \paperIdent % wrong and invalid
467 @}
468
469 \paper @{
470    \paperIdent % correct
471    foo = 1.0
472 @}
473 @end example
474
475
476 @node Music expressions
477 @section Music expressions
478
479 @cindex music expressions
480
481 Music in @emph{Lilypond} is entered as a music expression.  Notes, rests,
482 lyric syllables are music expressions (the atomic
483 expressions),
484 @cindex atomic music expressions
485 and you can combine music expressions to form new ones.  This example
486 forms a compound expressions out of the quarter @code{c} note and a
487 @code{d} note:
488
489 @example 
490 \sequential @{ c4 d4 @} 
491 @end example 
492
493 The meaning of this compound expression is to play the `@code{c}'
494 first, and then the `@code{d}' (as opposed to playing them
495 simultaneously, for instance).
496
497 Atomic music expression are discussed in
498 subsection @ref{Atomic music expressions}.  Compound music expressions are
499 discussed in subsection @ref{Compound music expressions}.
500
501
502
503 @node Atomic music expressions
504 @section Atomic music expressions
505
506
507
508
509 @cindex pitch
510
511 @cindex duration
512  
513
514 The syntax for pitch specification is
515
516
517 @example
518   \musicalpitch@keyindex{musicalpitch} @{ @var{octave} @var{note} @var{shift} @}
519 @end example
520
521 @var{octave} is specified by an integer, zero for the octave
522 containing middle C.  @var{note} is a number from 0 to 7, with 0
523 corresponding to C and 7 corresponding to B.  The shift is zero for a
524 natural, negative to add flats, or positive to add sharps.
525
526 In Note and Chord mode, pitches may be designated by names.  See
527 section @ref{Other languages} for pitch names in different languages.
528
529 The syntax for duration specification is
530
531 @example
532  \duration@keyindex{duration}
533    @{ @var{length} @var{dotcount} @}
534 @end example
535
536 @var{length} is the negative logarithm (base 2) of the duration:
537 1 is a half note, 2 is a quarter note, 3 is an eighth
538 note, etc.  The number of dots after the note is given by
539 @var{dotcount}.
540
541 In Note, Chord, and Lyrics mode, durations may be designated by
542 numbers and dots.  
543
544
545 @node Note specification
546 @section Note specification
547 @cindex Note specification
548
549 @cindex pitches
550
551 @cindex entering notes
552
553 A note specification has the form
554
555 @example
556   @var{pitch}[@var{octavespec}][!][?][@var{duration}]
557 @end example
558
559 The pitch of the note is specified by the note's name.
560
561
562 The default names are the Dutch note names.  The notes are specified
563 by the letters `@code{c}' through `@code{b}', where `@code{c}' is an
564 octave below middle C and the letters span the octave above that C. 
565 In Dutch,
566 @cindex notenames!Dutch
567 a sharp is formed by adding `@code{-is}' to the end of a pitch name.  A
568 flat is formed by adding `@code{-es}'. Double sharps and double flats
569 are obtained by adding `@code{-isis}' or `@code{-eses}'.  `@code{aes}'
570 and `@code{ees}' are contracted to `@code{as}' and `@code{es}' in Dutch,
571 but both forms will be accepted.
572
573 LilyPond has predefined sets of notenames for various languages.  See
574 section @ref{Other languages}.
575
576 The optional octave specification takes the form of a series of
577 single quote (`@code{'}@indexcode{'}') characters or a series of comma
578 (`@code{,}@indexcode{,}') characters.  Each @code{'} raises the pitch by one
579 octave; each @code{,} lowers the pitch by an octave.
580
581 @lilypond[fragment,verbatim,center]
582   c' d' e' f' g' a' b' c''
583 @end lilypond
584
585 @lilypond[fragment,verbatim,center]
586   cis' dis' eis' fis' gis' ais' bis'
587 @end lilypond
588
589 @lilypond[fragment,verbatim,center]
590   ces' des' es' fes' ges' as' bes'
591 @end lilypond
592
593 @lilypond[fragment,verbatim,center]
594   cisis' eisis' gisis' aisis' beses'
595 @end lilypond
596
597 @lilypond[fragment,verbatim,center]
598   ceses' eses' geses' ases' beses'
599 @end lilypond
600
601 Whenever a C-sharp is desired, you must specify a C-sharp.  LilyPond
602 will determine what accidentals to typeset depending on the key and
603 context.  A reminder accidental
604 @cindex reminder accidental
605 can be forced by adding an exclamation mark `@code{!}' after the pitch.
606 A cautionary accidental,
607 @cindex cautionary accidental
608 i.e., an accidental within parentheses can be obtained by adding the
609 question mark `@code{?}@indexcode{?}' after the pitch.
610
611 @lilypond[fragment,verbatim,center]
612   cis' d' e' cis'  c'? d' e' c'!
613 @end lilypond
614
615
616 @cindex duration
617
618 Durations are entered as their reciprocal values.  For notes longer
619 than a whole note, use identifiers.
620
621 @quotation
622
623 @example 
624 c'\longa c'\breve  
625 c'1 c'2 c'4 c'8 c'16 c'32 c'64 c'64 
626 @end example 
627
628 @end quotation
629
630 @quotation
631
632 @lilypond[]
633 \score {
634   \notes \relative c'' {
635     a\longa a\breve  
636     a1 a2 a4 a8 a16 a32 a64 a64 
637   }
638   \paper {
639 %{    \translator {
640       \StaffContext
641         \remove "Clef_engraver";
642         \remove "Staff_symbol_engraver";
643     } %}
644   }
645 }
646 @end lilypond
647 @end quotation
648
649 @quotation
650
651 @example 
652 r\longa r\breve  
653 r1 r2 r4 r8 r16 r32 r64 r64 
654 @end example 
655
656 @end quotation
657
658 @quotation
659
660 @lilypond[]
661 \score {
662   \notes \relative c'' {
663     r\longa r\breve  
664     r1 r2 r4 r8 r16 r32 r64 r64 
665   }
666   \paper {
667     loose_column_distance = 2.5 * \staffspace;
668     linewidth = -1.0;
669     \translator {
670         \StaffContext
671         \remove "Clef_engraver";
672         \remove "Staff_symbol_engraver";
673         \remove "Bar_engraver";
674     }
675   }
676 }
677 @end lilypond
678 @end quotation
679
680 If the duration is omitted then it is set equal to the previous
681 duration.  If there is no previous duration, a quarter note is
682 assumed.  The duration can be followed by a dot (`@code{.}@indexcode{.}')
683 to obtain dotted note lengths.
684
685 @lilypond[fragment,verbatim,center]
686   a'4. b'4.
687 @end lilypond
688
689 You can alter the length of duration by writing
690 `@code{*}@var{fraction}' after it.  This will not affect the
691 appearance of note heads or rests.
692
693
694 Rests are entered like notes, with note name `@code{r}@indexcode{r}', or
695 `@code{R}@indexcode{R}'.  There is also a note name
696 `@code{s}@indexcode{s}', which produces a space of the specified
697 duration.  `@code{R}' is specifically meant for entering parts: the
698 @code{R} rest can expand to fill a score with rests, or it can be
699 printed as a single multimeasure rest.
700
701 You can control the expansion by setting the property
702 @code{Score.skipBars}. If this is set to true, Lily will not expand
703 empty measures, and the multimeasure rests automatically adds the
704 appropriate number.
705
706 Note that there is currently no way to condense multiple rests into a
707 single multimeasure rest.
708
709
710
711 @cindex lyrics expressions
712
713 Syllables are entered like notes, with pitches replaced by text.  For
714 example, `@code{Twin-4 kle4 twin-4 kle4}' enters four syllables, each
715 with quarter note duration.  Note that the hyphen has no special
716 meaning for lyrics, and does not introduce special symbols.  See
717 section @ref{Lexical modes} for a description of what is interpreted as
718 lyrics.
719
720 Spaces can be introduced into a lyric either by using quotes
721 (`@code{"}') or by using an underscore without quotes: `@code{He_could4
722 not4}'.  All unquoted underscores are converted to spaces.  Printing
723 lyrics is discussed in section @ref{lyricprint}.
724
725
726
727 @cindex properties
728
729 @example
730   \property@keyindex{property}
731     @var{contextname}.@var{propname} =  @var{value}
732 @end example
733
734 Sets the @var{propname} property of the context @var{contextname} to
735 the specified @var{value}.  All three arguments are strings. 
736 Depending on the context, it may be necessary to quote the strings or
737 to leave space on both sides of the dot.
738
739
740
741 @cindex translator switches
742
743 @example
744   \translator@keyindex{translator}
745     @var{contexttype} = @var{name}
746 @end example
747
748 A music expression indicating that the context which is a direct
749 child of the a context of type @var{contexttype} should be shifted to
750 a context of type @var{contexttype} and the specified name.
751
752 Usually this is used to switch staffs in Piano music, e.g.
753
754 @example
755   \translator Staff = top @var{Music}
756 @end example
757
758
759 @cindex output properties
760
761
762 These allow you to tweak what is happening in the back-end
763 directly. If you want to control every detail of the output
764 formatting, this is the feature to use. The downside to this is that
765 you need to know exactly how the backend works. Example:
766
767
768 @lilypond[fragment,verbatim]
769 \relative c'' { c4
770         \context Staff \outputproperty
771                 #(make-type-checker 'Note_head)
772                 #'extra-offset = #'(5.0 . 7.5)
773 <c8 e g> }
774 @end lilypond
775
776 This selects all note heads occurring at current staff level, and sets
777 the extra-offset of those heads to (5,7.5), shifting them up and
778 right.
779
780 Use of this feature is entirely on your own risk: if you use this, the
781 result will depend very heavily on the implementation of the backend,
782 which we change regularly and unscrupulously.
783
784
785 @cindex commands
786
787 Commands are music expressions that have no duration.   
788
789
790 @example
791   @code{\key}@keyindex{key} @var{pitch} @var{type} @code{;}
792 @end example
793
794 Change the key signature.  @var{type} should be
795 @code{\major}@keyindex{major} or @code{\minor}@keyindex{minor} to get
796 @var{pitch}-major or @var{pitch}-minor, respectively.  The second
797 argument is optional; the default is major keys.  The @var{\context}
798 argument can also be given as an integer, which tells the number of
799 semitones that should be added to the pitch given in the subsequent
800 @code{\key}@keyindex{key} commands to get the corresponding major key,
801 e.g., @code{\minor}@keyindex{minor} is defined as 3.  The standard
802 mode names @code{\ionian}@keyindex{ionian},
803 @code{\locrian}@keyindex{locrian}, @code{\aeolian}@keyindex{aeolian},
804 @code{\mixolydian}@keyindex{mixolydian}, @code{\lydian}@keyindex{lydian},
805 @code{\phrygian}@keyindex{phrygian}, and @code{\dorian}@keyindex{dorian}
806 are also defined.
807
808         
809 @example
810   \mark@keyindex{mark} @var{unsigned};
811   \mark @var{string};
812 @end example
813
814 Prints a mark over or under the staff.  You must add
815 @code{Mark_engraver}@indexcode{Mark_engraver} to the Score context for
816 this to work.
817
818 @node barlines
819 @section barlines
820
821 @example
822   \bar@keyindex{bar} @var{bartype};
823 @end example
824
825 This is a short-cut for doing
826 @example
827   \property Score.whichBar = @var{bartype} 
828 @end example
829
830 You are encouraged to use @code{\repeat} for repetitions.  See
831 @ref{Repeats}, and the documentation of @code{whichBar} in
832 @ref{(lilypond-internals)LilyPond context properties}.
833
834
835 @example
836   \time@keyindex{time} @var{numerator}@code{/}@var{denominator} @code{;}
837 @end example
838
839 A short-cut for doing
840 @example
841      \property Score.timeSignatureFraction = #'(@var{numerator} . @var{denominator})
842 @end example
843
844 See the documentation of @code{timeSignatureFraction}
845
846 @example
847
848   \tempo@keyindex{tempo} @var{duration} = @var{perminute} @code{;}
849 @end example
850
851 Used to specify the tempo.  For example, `@code{\tempo 4 = 76;}'
852 requests output with 76 quarter notes per minute.
853
854 @example
855   \partial@keyindex{partial} @var{duration} @code{;}
856 @end example
857
858 Short cut for 
859
860 @example
861   \property Score.measurePosition = @var{length of duration}
862 @end example
863
864 See the documentation of @code{measurePosition}.
865
866 @cindex anacrusis
867
868 @cindex upstep
869
870 @example
871
872   @code{|}@indexcode{|}
873 @cindex bar check
874
875 @end example
876
877 @cindex shorten measures
878
879 @cindex upstep
880
881 `@code{|}' is a bar check.  Whenever a bar check is encountered during
882 interpretation, a warning message is issued if it doesn't fall at a
883 measure boundary.  This can help you finding errors in the input.
884 Depending on the value of @code{barCheckNoSynchronize}
885 @indexcode{barCheckNoSynchronize} The beginning of the measure will be
886 relocated, so this can also be used to shorten measures.
887
888
889 @example
890   \penalty@keyindex{penalty} @var{int} @code{;}
891 @end example
892
893 Discourage or encourage line breaks.  See identifiers
894 @code{\break}@keyindex{break} and @code{\nobreak}@keyindex{nobreak} in
895 section [on identifiers] [FIXME].
896
897 @example
898   \clef@keyindex{clef} @var{clefname} @code{;}
899 @end example
900
901 Short-cut for
902
903 @example
904   \property Clef.clefGlyph = @var{symbol associated with clefname} 
905   \property Clef.clefPosition = @var{clef Y-position for clefname}
906   \property Clef.clefOctavation = @var{extra pitch of clefname}
907 @end example
908
909 Supported clef-names include 
910
911 [todo]
912
913 @example
914
915   \skip@keyindex{skip} @var{duration} @code{;}
916 @end example
917
918 Skips the amount of time specified by @var{duration}.  If no other
919 music is played, a gap will be left for the skipped time with no
920 notes printed.  It works in Note Mode or Lyrics Mode.  In Note mode,
921 this has the same effect as the space rest `@code{s}'.
922
923
924 @node Manual beams
925 @section Manual beams
926 @cindex beams
927
928 A beam is specified by surrounding the beamed notes with brackets
929 `@code{[}@indexcode{[}' and `@code{]}@indexcode{]}'.  
930
931 @lilypond[fragment,verbatim,center]
932   [a'8 a'] [a'16 a' a' a']
933 @end lilypond
934
935 Some more elaborate constructions:
936
937 @lilypond[fragment,verbatim,center]
938   [a'16 <a' c''> c'' <a' c''>]
939   \times 2/3 { [e'8 f' g'] }
940 @end lilypond
941
942 Beaming can be generated automatically; see section @ref{Automatic Beaming}.
943
944
945 To place tremolo marks between notes, use @code{\repeat} with tremolo
946 style.
947 @cindex tremolo beams
948 To create tremolo beams on a single note, simply attach
949 `@code{:}@var{length}' to the note itself.
950
951 @lilypond[fragment,verbatim,center]
952   \repeat "tremolo" 8 { c16 d16 }
953   \repeat "tremolo" 4 { c16 d16 }    
954 @end lilypond
955
956 @lilypond[fragment,verbatim,center]
957   c'4:32
958 @end lilypond
959
960
961 @cindex --@@@code{-}@code{-}
962
963 @indexcode{__}
964
965 @cindex extender
966
967 @cindex hyphen
968
969 The syntax for an extender mark is `@code{__}'.  This syntax can only
970 be used within lyrics mode.  The syntax for a spanning hyphen (i.e.,
971 a hyphen that will be printed between two lyric syllables) is
972 `@code{-}@code{-}'.
973
974
975 @cindex ties
976
977 A tie connects two adjacent note heads of the same pitch.  When used
978 with chords, it connects all of the note heads whose pitches match.
979 Ties are indicated using the tilde symbol `@code{~}@indexcode{~}'.
980 If you try to tie together chords which have no common pitches, a
981 warning message will appear and no ties will be created.
982
983 @lilypond[fragment,verbatim,center]
984   e' ~ e' <c' e' g'> ~ <c' e' g'>
985 @end lilypond
986
987 @cindex articulations
988
989 @cindex scripts
990
991 @cindex ornaments
992
993 A variety of symbols can appear above and below notes to indicate
994 different characteristics of the performance.  These symbols can be
995 added to a note with `@var{note}@code{-\}@var{name}'.  Numerous symbols
996 are defined in @file{script.ly} and @file{script.scm}.  Symbols can be
997 forced to appear above or below the note by writing
998 `@var{note}@code{^\}@var{name}' and `@var{note}@code{_\}@var{name}'
999 respectively.  Here is a chart showing symbols above notes, with the
1000 name of the corresponding symbol appearing underneath.
1001
1002 @lilypond[]
1003
1004   \score {
1005     < \notes {
1006         c''-\accent      c''-\marcato      c''-\staccatissimo c''-\fermata 
1007         c''-\stopped     c''-\staccato     c''-\tenuto        c''-\upbow
1008         c''-\downbow     c''^\lheel        c''-\rheel         c''^\ltoe
1009         c''-\rtoe        c''-\turn         c''-\open          c''-\flageolet
1010         c''-\reverseturn c''-\trill        c''-\prall         c''-\mordent
1011         c''-\prallprall  c''-\prallmordent c''-\upprall       c''-\downprall
1012         c''-\thumb       c''-\segno        c''-\coda
1013       }
1014       \context Lyrics \lyrics {  
1015         accent__      marcato__      staccatissimo__ fermata
1016         stopped__     staccato__     tenuto__        upbow
1017         downbow__     lheel__        rheel__         ltoe
1018         rtoe__        turn__         open__          flageolet
1019         reverseturn__ trill__        prall__         mordent
1020         prallprall__  prallmordent__ uprall__        downprall
1021         thumb__       segno__        coda
1022       }
1023     >
1024     \paper {
1025       linewidth = 5.875\in;          
1026       indent    = 0.0;
1027     }
1028   }
1029
1030 @end lilypond
1031
1032 In addition, it is possible to place arbitrary strings of text or
1033 @TeX{} above or below notes by using a string instead of an
1034 identifier: `@code{c^"text"}'.  Fingerings 
1035 @cindex fingering
1036 can be placed by simply using digits.  All of these note ornaments
1037 appear in the printed output but have no effect on the MIDI rendering of
1038 the music.
1039
1040 To save typing, fingering instructions (digits 0 to 9 are
1041 supported) and single characters shorthands exist for a few
1042 common symbols
1043
1044 @lilypond[]
1045
1046   \score {
1047     \notes {
1048       \property Voice.TextScript \set #'font-style = #'typewriter
1049       c''4-._"c-."      s4
1050       c''4--_"c-{}-"    s4
1051       c''4-+_"c-+"      s4
1052       c''4-|_"c-|"      s4
1053       c''4->_"c->"      s4
1054       c''4-^_"c-\\^{ }" s4
1055       c''4-1_"c-1"      s4
1056       c''4-2_"c-2"      s4
1057       c''4-3_"c-3"      s4
1058       c''4-4_"c-4"      s4
1059     }
1060     \paper {
1061       linewidth = 5.875 \in;
1062       indent    = 0.0;
1063     }
1064   }
1065
1066 @end lilypond
1067
1068 Dynamic marks are specified by using an identifier after a note:
1069 `@code{c4-\ff}' (the dash is optional for dynamics: `@code{c4 \ff})'.  
1070 The available dynamic marks are:
1071 @code{\ppp}@keyindex{ppp},
1072 @code{\pp}@keyindex{pp}, @code{\p}@keyindex{p}, @code{\mp}@keyindex{mp},
1073 @code{\mf}@keyindex{mf}, @code{\f}@keyindex{f}, @code{\ff}@keyindex{ff},
1074 @code{\fff}@keyindex{fff}, @code{\fff}@keyindex{ffff},
1075 @code{\fp}@keyindex{fp}, @code{\sf}@keyindex{sf},
1076 @code{\sff}@keyindex{sff}, @code{\sp}@keyindex{sp},
1077 @code{\spp}@keyindex{spp}, @code{\sfz}@keyindex{sfz}, and
1078 @code{\rfz}@keyindex{rfz}.
1079
1080
1081 @example
1082
1083   \textscript@keyindex{textscript} @var{text} @var{style}
1084 @end example
1085
1086 Defines a text to be printed over or under a note.  @var{style} is a
1087 string that may be one of @code{roman}, @code{italic}, @code{typewriter}, 
1088 @code{bold}, @code{Large}, @code{large}, @code{dynamic} or @code{finger}.
1089
1090 You can attach a general textscript request using this syntax:
1091
1092 @quotation
1093
1094 @example 
1095 c4-\textscript "6" "finger"
1096 c4-\textscript "foo" "normal" 
1097 @end example 
1098
1099 @end quotation
1100
1101 This is equivalent to `@code{c4-6 c4-"foo"}'.  
1102
1103 @cindex scripts
1104
1105 @example
1106
1107   \script@keyindex{script} @var{alias}
1108 @end example
1109
1110 Prints a symbol above or below a note.  The argument is a string
1111 which points into the script-alias table defined in @file{script.scm}.
1112 The scheme definitions specify whether the symbol follows notes into
1113 the staff, dependence of symbol placement on staff direction, and a
1114 priority for placing several symbols over one note.  Usually the
1115 @code{\script}@keyindex{script} keyword is not used directly.  Various
1116 helpful identifier definitions appear in @file{script.ly}.
1117
1118
1119 @cindex slur
1120
1121 Slurs connects chords and try to avoid crossing stems.  A slur is
1122 started with `@code{(}' and stopped with `@code{)}'.  The
1123 starting `@code{(}' appears to the right of the first note in
1124 the slur.  The terminal `@code{)}' appears to the left of the
1125 first note in the slur.  This makes it possible to put a note in
1126 slurs from both sides:
1127
1128 @lilypond[fragment,verbatim,center]
1129   f'()g'()a' [a'8 b'(] a'4 g'2 )f'4
1130 @end lilypond
1131
1132
1133 @cindex crescendo
1134
1135 A crescendo mark is started with @code{\cr}@keyindex{cr} and terminated
1136 with @code{\rc}@keyindex{rc}.  A decrescendo mark is started with
1137 @code{\decr}@keyindex{decr} and terminated with
1138 @code{\rced}@keyindex{rced}.  There are also shorthands for these
1139 marks.  A crescendo can be started with @code{\<}@keyindex{<} and a
1140 decrescendo can be started with @code{\>}@keyindex{>}.  Either one can
1141 be terminated with @code{\!}@keyindex{"!}.  Note that @code{\!}
1142 must go before the last note of the dynamic mark whereas @code{\rc}
1143 and @code{\rced} go after the last note.  Because these marks are
1144 bound to notes, if you want to get several marks during one note, you
1145 must use spacer notes.
1146
1147 @lilypond[fragment,verbatim,center]
1148   c'' \< \! c''   d'' \decr e'' \rced 
1149   < f''1 { s4 \< \! s2 \> \! s4 } >
1150 @end lilypond
1151
1152
1153 @example
1154
1155   \spanrequest@keyindex{spanrequest} @var{startstop} @var{type}
1156 @end example
1157
1158 Define a spanning request. The @var{startstop} parameter is either -1
1159 (@code{\start}@keyindex{start}) or 1 (@code{\stop}@keyindex{stop}) and
1160 @var{type} is a string that describes what should be started.
1161 Supported types are @code{crescendo}, @code{decrescendo},
1162 @code{beam}, @code{slur}.  This is an internal command.  Users should
1163 use the shorthands which are defined in the initialization file
1164 @file{spanners.ly}.
1165
1166 You can attach a (general) span request to a note using
1167
1168 @lilypond[fragment,verbatim,center]
1169   c'4-\spanrequest \start "slur"
1170   c'4-\spanrequest \stop "slur"
1171 @end lilypond
1172
1173 The slur syntax with parentheses is a shorthand for this.
1174
1175
1176 @node stem tremolo
1177 @section stem tremolo
1178 @cindex tremolo marks
1179
1180 Tremolo marks can be printed on a single note by adding
1181 `@code{:}[@var{length}]' after the note.  The length must be at
1182 least 8.  A @var{length} value of 8 gives one line across
1183 the note stem.  If the length is omitted, then the last value is
1184 used, or the value of the @code{tremoloFlags}@indexcode{tremoloFlags} property if there was
1185 no last value.
1186
1187 @lilypond[verbatim,fragment,center]
1188   c'2:8 c':32
1189 @end lilypond
1190
1191
1192
1193 @node Compound music expressions
1194 @section Compound music expressions
1195
1196 @cindex compound music expressions
1197
1198 Music expressions are compound data structures.  You can nest music
1199 expressions any way you like.  This simple example shows how three
1200 chords can be expressed in two different ways:
1201
1202 @lilypond[fragment,verbatim,center]
1203   \notes \context Staff {
1204     \cadenzaOn
1205     <a c'> <b  d' > <c' e'>
1206     < { a b  c' } { c' d' e' } >
1207   }
1208 @end lilypond
1209
1210 @cindex context selection
1211 @c @keyindex{context}
1212
1213 @example
1214   \context @var{contexttype} [= @var{contextname}] @var{musicexpr}
1215 @end example
1216
1217 Interpret @var{musicexpr} within a context of type @var{contexttype}. 
1218 If the context does not exist, it will be created.  The new context
1219 can optionally be given a name.  
1220
1221 @cindex input modes
1222
1223 @cindex mode switch
1224
1225 Mode switching keywords form compound music expressions: @code{\notes}
1226 @keyindex{notes} @var{musicexpr}, @code{\chords} @keyindex{chords}
1227 @var{musicexpr}, and @code{\lyrics} @keyindex{lyrics} @var{musicexpr}. 
1228 These expressions do not add anything to the meaning of their
1229 arguments.  They are just a way to indicate that the arguments should
1230 be parsed in indicated mode.  See @ref{Lexical modes} for more
1231 information on modes.
1232
1233 @cindex sequential music
1234
1235
1236
1237 @example
1238
1239   \sequential@keyindex{sequential}
1240     @code{@{} @var{musicexprlist} @code{@}}
1241 @end example
1242
1243 This means that list should be played or written in sequence, i.e.,
1244 the second after the first, the third after the second.  The duration
1245 of sequential music is the the sum of the durations of the elements. 
1246 There is a shorthand, which leaves out the keyword:
1247
1248 @example
1249
1250   @code{@{} @var{musicexprlist} @code{@}}
1251 @end example
1252
1253
1254
1255 @cindex simultaneous music
1256
1257 @indexcode{<}
1258 @indexcode{>}
1259
1260 @example
1261
1262   \simultaneous@keyindex{simultaneous}
1263     @code{@{} @var{musicexprlist} @code{@}}
1264 @end example
1265
1266 It constructs a music expression where all of its arguments start at
1267 the same moment.  The duration is the maximum of the durations of the
1268 elements.  The following shorthand is a common idiom:
1269
1270 @example
1271
1272   @code{<} @var{musicexprlist} @code{>}
1273 @end example
1274
1275 If you try to use a chord as the first thing in your score, you might
1276 get multiple staffs instead of a chord.
1277
1278 @lilypond[verbatim,center]
1279   \score {
1280     \notes <c''4 e''>
1281     \paper {
1282       linewidth = -1.;
1283     }
1284   }
1285 @end lilypond
1286
1287 This happens because the chord is interpreted by a score context.
1288 Each time a note is encountered a default Voice context (along with a
1289 Staff context) is created.  The solution is to explicitly instantiate
1290 a Voice context:
1291
1292 @lilypond[verbatim,center]
1293   \score {
1294     \notes\context Voice <c''4 e''>
1295     \paper {
1296       linewidth = -1.;
1297     }
1298   }
1299 @end lilypond
1300
1301
1302
1303
1304 @node relative
1305 @section relative
1306 @cindex relative pitch specification
1307
1308 It is easy to get confused by octave changing marks and accidentally
1309 putting a pitch in the wrong octave.  A much better way of entering a
1310 note's octave is `the relative octave' mode.
1311
1312 @example
1313
1314   \relative@keyindex{relative} @var{startpitch} @var{musicexpr}
1315 @end example
1316
1317 The octave of notes that appear in @var{musicexpr} are calculated as
1318 follows: If no octave changing marks are used, the basic interval
1319 between this and the last note is always taken to be a fourth or
1320 less.@footnote{The interval is determined without regarding
1321 accidentals.  A @code{fisis} following a @code{ceses} will be put above
1322 the @code{ceses}.}  The octave changing marks `@code{'}' and `@code{,}'
1323 can then be added to raise or lower the pitch by an extra octave. 
1324 Upon entering relative mode, an absolute starting pitch must be
1325 specified that will act as the predecessor of the first note of
1326 @var{musicexpr}.
1327
1328 Entering scales is straightforward in relative mode.
1329
1330 @lilypond[fragment,verbatim,center]
1331   \relative c' {
1332     c d e f g a b c c,
1333   }
1334 @end lilypond
1335
1336 And octave changing marks are used for intervals greater than a fourth.
1337
1338 @lilypond[fragment,verbatim,center]
1339   \relative c'' {
1340     c g c f, c' a, e'' }
1341 @end lilypond
1342
1343 If the preceding item is a chord, the first note of the chord is used
1344 to determine the first note of the next chord.  But other notes
1345 within the second chord are determined by looking at the immediately
1346 preceding note.
1347
1348 @lilypond[fragment,verbatim,center]
1349   \relative c' {
1350     c <c e g> 
1351     <c' e g>
1352     <c, e' g>
1353   }
1354 @end lilypond 
1355
1356 The pitch after the @code{\relative} contains a notename.  To parse
1357 the pitch as a notename, you have to be in note mode, so there must
1358 be a surrounding @code{\notes}@keyindex{notes} keyword (which is not
1359 shown here).
1360
1361 The relative conversion will not affect @code{\transpose} or
1362 @code{\relative} sections in its argument.  If you want to use
1363 relative within transposed music, you must place an additional
1364 @code{\relative} inside the @code{\transpose}.
1365
1366 It is strongly recommended to use relative pitch mode: less work,
1367 less error-prone, and more readable.
1368
1369
1370
1371 Chord names are a way to generate simultaneous music expressions that
1372 correspond with traditional chord names.  It can only be used in
1373 Chord mode (see section @ref{Lexical modes}).
1374
1375 @example
1376
1377   @var{tonic}[@var{duration}][@code{-}@var{modifiers}][@code{^}@var{subtractions}][@code{/}@var{inversion}][@code{/+}@var{bass}].
1378 @end example
1379
1380 @var{tonic} should be the tonic note of the chord, and @var{duration}
1381 is the chord duration in the usual notation.  There are two kinds of
1382 modifiers.  One type is @emph{chord additions}, which are obtained by
1383 listing intervals separated by dots.  An interval is written by its
1384 number with an optional `@code{+}' or `@code{-}' to indicate raising or
1385 lowering by half a step.  Chord additions has two effects: It adds
1386 the specified interval and all lower odd numbered intervals to the
1387 chord, and it may lower or raise the specified interval.  Intervals
1388 must be separated by a dot (`@code{.}').
1389
1390 @quotation
1391
1392 @lilypond[fragment,verbatim]
1393 \transpose c'' {
1394   \chords {
1395     c1  c:3-       c:7     c:8
1396     c:9 c:9-.5+.7+ c:3-.5- c:4.6.8
1397   }
1398 }
1399
1400 @end lilypond
1401 @end quotation
1402
1403 The second type of modifier that may appear after the `@code{:}' is a
1404 named modifier.  Named modifiers are listed in the file
1405 @file{chord-modifiers.ly}.  The available modifiers are `@code{m}' and
1406 `@code{min}' which lower the 3rd half a step, `@code{aug}@indexcode{aug}' which
1407 raises the 5th, `@code{dim}@indexcode{dim}' which lowers the 5th,
1408 `@code{maj}@indexcode{maj}' which adds a raised 7th, and `@code{sus}@indexcode{sus}'
1409 which replaces the 5th with a 4th.
1410
1411 @quotation
1412
1413 @lilypond[fragment,verbatim]
1414 \transpose c'' {
1415   \chords {
1416     c1:m c:min7 c:maj c:aug c:dim c:sus
1417   }
1418 }
1419
1420 @end lilypond
1421 @end quotation
1422  
1423
1424 Chord subtractions are used to eliminate notes from a chord.  The
1425 notes to be subtracted are listed after a `@code{^}' character,
1426 separated by dots.
1427
1428 @lilypond[fragment,verbatim,center]
1429   \transpose c'' {
1430     \chords {
1431       c1^3 c:7^5.3 c:8^7
1432     }
1433   }
1434 @end lilypond 
1435
1436 Chord inversions can be specified by appending `@code{/}@indexcode{/}' and
1437 the name of a single note to a chord.  This has the effect of
1438 lowering the specified note by an octave so it becomes the lowest
1439 note in the chord.  If the specified note is not in the chord, a
1440 warning will be printed.
1441
1442 @lilypond[fragment,verbatim,center]
1443   \transpose c''' {
1444     \chords {
1445       c1 c/e c/g c:7/e
1446     }
1447   }
1448
1449 @end lilypond 
1450
1451 Bass notes can be added by `@code{/+}@indexcode{/+}' and
1452 the name of a single note to a chord.  This has the effect of
1453 adding the specified note to the chord, lowered by an octave,
1454 so it becomes the lowest note in the chord.
1455
1456 @lilypond[fragment,verbatim,center]
1457   \transpose c''' {
1458     \chords {
1459       c1 c/+c c/+g c:7/+b
1460     }
1461   }
1462
1463 @end lilypond 
1464
1465 Throughout these examples, chords have been shifted around the staff
1466 using @code{\transpose}.
1467
1468 You should not combine @code{\relative} with named chords. 
1469
1470
1471
1472 @cindex tuplets
1473
1474 Tuplets are made out of a music expression by multiplying their
1475 duration with a fraction.
1476
1477 @example
1478
1479   \times@keyindex{times} @var{fraction} @var{musicexpr}
1480 @end example
1481
1482 The duration of @var{musicexpr} will be multiplied by the fraction. 
1483 In print, the fraction's denominator will be printed over the notes,
1484 optionally with a bracket.  The most common tuplet is the triplet in
1485 which 3 notes have the length of 2, so the notes are 2/3 of
1486 their written length:
1487
1488 @lilypond[fragment,verbatim,center]
1489   g'4 \times 2/3 {c'4 c' c'} d'4 d'4
1490 @end lilypond
1491
1492
1493
1494 @cindex grace notes
1495
1496 @example
1497
1498   \grace@keyindex{grace} @var{musicexpr}
1499 @end example
1500
1501 A grace note expression has duration 0; the next real note is
1502 assumed to be the main note.
1503
1504
1505 You cannot have the grace note after the main note, in terms of
1506 duration, and main notes, but you can typeset the grace notes to the
1507 right of the main note using the property
1508 @code{graceAlignPosition}@indexcode{graceAlignPosition}.
1509
1510 When grace music is interpreted, a score-within-a-score is set up:
1511 @var{musicexpr} has its own time bookkeeping, and you could (for
1512 example) have a separate time signature within grace notes.  While in
1513 this score-within-a-score, you can create notes, beams, slurs, etc.
1514 Unbeamed eighth notes and shorter by default have a slash through the
1515 stem.  This behavior can be controlled with the
1516 @code{flagStyle}@indexcode{flagStyle} property.
1517
1518 @quotation
1519
1520 @lilypond[fragment,verbatim]
1521 \relative c'' {
1522   \grace c8 c4 \grace { [c16 c16] } c4
1523   \grace { \property Grace.flagStyle = "" c16 } c4
1524 }
1525
1526 @end lilypond
1527 @end quotation
1528
1529 At present, nesting @code{\grace}@keyindex{grace} notes, e.g.
1530
1531 @example
1532
1533   @code{\grace @{ \grace c32 c16 @} c4}
1534 @end example
1535
1536 may result in run-time errors of LilyPond.  Since the meaning of such
1537 a construct is unclear, we don't consider this a loss.  Similarly,
1538 juxtaposing two @code{\grace} sections is syntactically valid, but
1539 makes no sense and may cause runtime errors.
1540
1541 Ending a staff or score with grace notes may also generate a run-time
1542 error, since there will be no main note to attach the grace notes to.
1543
1544
1545
1546 @node Repeats
1547 @section Repeats
1548 @cindex repeats
1549
1550
1551 In order to specify repeats, use the @code{\repeat}@keyindex{repeat}
1552 keyword.  Since repeats look and sound differently when played or
1553 printed, there are a few different variants of repeats.
1554
1555 @table @samp
1556   @item unfolded  
1557     Repeated music is fully written (played) out.  Useful for MIDI
1558     output.
1559
1560   @item volta  
1561     This is the normal notation: Repeats are not written out, but
1562     alternative endings (voltas) are printed, left to right.
1563
1564   @item folded  
1565     Alternative endings are written stacked, which is useful for
1566     lyrics.
1567 @end table  
1568
1569 The syntax for repeats is
1570
1571 @example
1572
1573   \repeat @var{variant} @var{repeatcount} @var{repeatbody}
1574 @end example
1575
1576 If you have alternative endings, you may add
1577
1578 @example
1579
1580   \alternative@keyindex{alternative}
1581     @code{@{} @var{alternative1}
1582             @var{alternative2}
1583             @var{alternative3} @dots{} @code{@}}
1584 @end example
1585
1586 where each @var{alternative} is a Music expression.
1587
1588 Normal notation repeats are used like this:
1589
1590 @quotation
1591
1592 @lilypond[fragment,verbatim]
1593   c'1
1594   \repeat volta 2 { c'4 d' e' f' }
1595   \repeat volta 2 { f' e' d' c' }
1596
1597 @end lilypond
1598 @end quotation
1599
1600 With alternative endings:
1601
1602 @quotation
1603
1604 @lilypond[fragment,verbatim]
1605   c'1
1606   \repeat volta 2 {c'4 d' e' f'} 
1607   \alternative { {d'2 d'} {f' f} }
1608
1609 @end lilypond
1610 @end quotation
1611
1612 Folded repeats look like this:@footnote{Folded repeats offer little
1613 more over simultaneous music.  However, it is to be expected that
1614 more functionality -- especially for the MIDI backend -- will be
1615 implemented.}
1616
1617 @quotation
1618
1619 @lilypond[fragment,verbatim]
1620   c'1
1621   \repeat fold 2 {c'4 d' e' f'} 
1622   \alternative { {d'2 d'} {f' f} }
1623
1624 @end lilypond
1625 @end quotation
1626
1627 @quotation
1628
1629 @lilypond[fragment,verbatim]
1630 \context Staff {
1631   \relative c' {
1632     \partial 4;
1633     \repeat volta 2 { e | c2 d2 | e2 f2 | }
1634     \alternative { { g4 g g } { a | a a a a | b1 } }
1635   }
1636 }
1637
1638 @end lilypond
1639 @end quotation
1640
1641 If you don't give enough alternatives for all of the repeats, then
1642 the first alternative is assumed to be repeated often enough to equal
1643 the specified number of repeats.
1644
1645 @quotation
1646
1647 @lilypond[fragment,verbatim]
1648 \context Staff {
1649   \relative c' {
1650     \repeat volta 3 { \partial 4; e | c2 d2 | e2 f2 | }
1651     \alternative { { g4 g g }
1652                    {\partial 1; e4 e e } 
1653                    {\partial 1; a a a a | b1 } }
1654   }
1655 }
1656
1657 @end lilypond
1658 @end quotation
1659
1660 It is possible to nest @code{\repeat}.  This is not entirely
1661 supported: the notes will come be in the right places, but the repeat
1662 bars will not.
1663
1664
1665
1666
1667 @node transpose
1668 @section transpose
1669 @cindex transposition of pitches
1670
1671 A music expression can be transposed with
1672 @code{\transpose}@keyindex{transpose}.  The syntax is
1673
1674 @example
1675
1676   \transpose @var{pitch} @var{musicexpr}
1677 @end example
1678
1679 This means that middle C in @var{musicexpr} is transposed to
1680 @var{pitch}.
1681
1682 @code{\transpose} distinguishes between enharmonic pitches: both
1683 @code{\transpose cis'} or @code{\transpose des'} will transpose up half
1684 a tone.  The first version will print sharps and the second version
1685 will print flats.
1686
1687 @quotation
1688
1689 @lilypond[fragment,verbatim]
1690 \context Staff {
1691   \clef "F";
1692   { \key e \major; c d e f }
1693   \clef "G";
1694   \transpose des'' { \key e \major; c d e f }
1695   \transpose cis'' { \key e \major; c d e f }
1696 }
1697
1698 @end lilypond
1699 @end quotation
1700
1701 If you want to use both @code{\transpose} and @code{\relative}, then
1702 you must use @code{\transpose} first.  @code{\relative} will have no
1703 effect music that appears inside a @code{\transpose}.
1704
1705
1706
1707 @cindex automatic lyric durations
1708
1709 If you have lyrics that are set to a melody, you can import the
1710 rhythm of that melody into the lyrics using @code{\addlyrics}.
1711 @keyindex{addlyrics} The syntax for this is
1712
1713 @example
1714
1715   \addlyrics @var{musicexpr1 musicexpr2}
1716 @end example
1717
1718 This means that both @var{musicexpr1} and @var{musicexpr2} are
1719 interpreted, but that every non-command atomic music expression
1720 (``every syllable'') in @var{musicexpr2} is interpreted using timing
1721 of @var{musicexpr1}.
1722
1723 If the property @code{automaticMelismata}@indexcode{automaticMelismata} is set in the
1724 context of @var{musicexpr1}, no lyrics will be put on slurred or tied
1725 notes.
1726
1727 @quotation
1728
1729 @lilypond[verbatim,fragment]
1730 \addlyrics
1731 \transpose c'' {
1732   \property Voice.automaticMelismata = ##t
1733   c8 () cis d8. e16 f2
1734 }
1735 \context Lyrics \lyrics {
1736  do4 re mi fa }
1737
1738 @end lilypond
1739 @end quotation
1740
1741 You should use a single rhythm melody, and single rhythm lyrics (a
1742 constant duration is the obvious choice).  If you do not, you will get
1743 undesired effects when using multiple stanzas:
1744
1745 @quotation
1746
1747 @lilypond[verbatim,fragment]
1748 \addlyrics
1749 \transpose c'' {
1750   c8 () cis d8. e16 f2
1751 }
1752 \context Lyrics \lyrics
1753 < { do4 re mi fa }
1754   { do8 re mi fa } >
1755
1756 @end lilypond
1757 @end quotation
1758
1759 It is valid (but probably not very useful) to use notes instead of
1760 lyrics for @var{musicexpr2}.
1761
1762
1763
1764
1765 @node Ambiguities
1766 @section Ambiguities
1767
1768 @cindex ambiguities
1769
1770 The grammar contains a number of ambiguities.@footnote{The authors
1771 hope to resolve them at a later time.}
1772
1773 @itemize @bullet
1774   @item  The assignment
1775
1776          @example 
1777 foo = bar 
1778 @end example 
1779
1780        can be interpreted as making a string identifier @code{\foo}
1781        containing @code{"bar"}, or a music identifier @code{\foo}
1782        containing the syllable `bar'.
1783
1784   @item  The assignment
1785
1786          @example 
1787 foo = -6 
1788 @end example 
1789
1790        can be interpreted as making an integer identifier
1791        containing -6, or a Request identifier containing the
1792        fingering `6' (with neutral direction).
1793
1794   @item  If you do a nested repeat like
1795
1796        @quotation
1797
1798 @example 
1799 \repeat @dots{}
1800 \repeat @dots{}
1801 \alternative 
1802 @end example 
1803
1804        @end quotation
1805
1806        then it is ambiguous to which @code{\repeat} the
1807        @code{\alternative} belongs.  This is the classic if-then-else
1808        dilemma.  It may be solved by using braces.
1809
1810   @item  (an as yet unidentified ambiguity :-)
1811 @end itemize
1812
1813
1814
1815 @node Notation conversion specifics
1816 @section Notation conversion specifics
1817
1818
1819 @node Automatic Beaming
1820 @section Automatic Beaming
1821 @cindex automatic beam generation
1822 @cindex autobeam
1823
1824 @c beamAuto vs autoBeam ?
1825
1826 By default, LilyPond will generate beams automatically.  This feature
1827 can be disabled by setting the
1828 @code{Voice.beamAuto}@indexcode{Voice.beamAuto} property to false.
1829 It can be overridden for specific cases by specifying explicit beams.
1830
1831
1832 A large number of Voice properties are used to decide how to generate
1833 beams.  Their default values appear in @file{scm/auto-beam.scm}.  In
1834 general, beams can begin anywhere, but their ending location is
1835 significant.  Beams can end on a beat, or at durations specified by the
1836 properties in
1837 @code{Voice.autoBeamSettings}@indexcode{Voice.autoBeamSettings}.
1838 To end beams every quarter note, for example, you could set the property
1839 @code{(end * * * *)} @indexcode{(end * * * *)} to `@code{(make-moment 1
1840 4)}'.  To end beams at every three eighth notes you would set
1841 it to `@code{(make-moment 1 8)}'.
1842 The same syntax can be used to specify beam
1843 starting points using
1844 @code{(begin * * * *)}@indexcode{(begin * * * *)}, eg:
1845 @quotation
1846 @example
1847 \property Voice.autoBeamSettings \override
1848     #'(end * * * *) = #(make-moment 1 4)
1849 \property Voice.autoBeamSettings \override
1850     #'(begin * * * *) = #(make-moment 1 8)
1851 @end example
1852 @end quotation
1853
1854 To allow different settings for different time signatures, instead of
1855 the first two asterisks @code{* *} you can specify a time signature; use
1856 @code{(end N M * *)} to restrict the definition to
1857 `@var{N}@code{/}@var{M}' time.  For example, to specify beams ending
1858 only for 6/8 time you would use the property @code{(end 6 8 * *)}.
1859
1860 To allow different endings for notes of different durations, instead of
1861 th last two asterisks you can specify a duration; use @code{(end * * N
1862 M)} to restrict the definition to beams that contain notes of
1863 `@var{N}@code{/}@var{M}' duration.
1864
1865 For example, to specify beam endings for beams that contain 32nd notes,
1866 you would use @code{(end * * 1 32)}.
1867
1868
1869 @node Chord Names
1870 @section Chord Names
1871 @cindex chord names
1872 @cindex chords
1873
1874 @cindex printing!chord names
1875
1876 For displaying printed chord names, use the
1877 @code{ChordNames}@indexcode{ChordNames} and
1878 @code{ChordNameVoice}@indexcode{ChordNameVoice} contexts.  The chords
1879 may be entered either using the notation described above, or directly
1880 using simultaneous music.
1881
1882 @quotation
1883 @lilypond[verbatim]
1884 scheme = \notes {
1885   \chords {a1 b c} <d f g>  <e g b>
1886 }
1887 \score {
1888   \notes<
1889     \context ChordNamesVoice \scheme
1890     \context Staff \transpose c'' \scheme
1891   >
1892   \paper { linewidth = -1.; }
1893 }
1894 @end lilypond
1895 @end quotation
1896
1897
1898 You can make the chord changes stand out more by setting property
1899 @code{ChordNames.chordChanges} to true.  This will only display
1900 chord names when there's a change in the chords scheme, but always
1901 display the chord name after a line break:
1902
1903 @c bug
1904 @quotation
1905 @lilypond[verbatim]
1906 scheme = \chords {
1907   c1:m \break c:m c:m c:m d
1908 }
1909
1910 \score {
1911   \notes <
1912     \context ChordNames \scheme
1913     \context Staff \transpose c'' \scheme
1914   >
1915   \paper{
1916     linewidth = 40 * \staffspace;
1917     \translator {
1918       \ChordNamesContext
1919       chordChanges = ##t
1920     }
1921   }
1922 }
1923 @end lilypond
1924 @end quotation
1925
1926
1927
1928 LilyPond examines chords specified as lists of notes to determine a
1929 name to give the chord. LilyPond will not try to
1930 identify chord inversions or added base, which may result in strange
1931 chord names when chords are entered as a list of pitches:
1932
1933 @quotation
1934 @lilypond[verbatim,center]
1935 scheme = \notes {
1936   <c'1 e' g'>
1937   <e' g' c''>
1938   <e e' g' c''>
1939 }
1940
1941 \score {
1942   <
1943     \context ChordNamesVoice \scheme
1944     \context Staff \scheme
1945   >
1946   \paper { linewidth = -1.; }
1947 }
1948 @end lilypond
1949 @end quotation
1950
1951 To specify chord inversions, append @code{/<notename>}.  To specify an
1952 added bass note, append @code{/+<notename}:
1953
1954 @quotation
1955 @lilypond[verbatim,center]
1956 scheme = \chords {
1957   d1 d/a d/+gis
1958 }
1959
1960 \score {
1961   \notes <
1962     \context ChordNames \scheme
1963     \context Staff \transpose c'' \scheme
1964   >
1965   \paper { linewidth = -1.; }
1966 }
1967 @end lilypond
1968 @end quotation
1969
1970 The chord names that LilyPond should print are fully customisable.  The
1971 default code can be found in @file{scm/chord-name.scm}.  Chord names are
1972 based on Banter style naming, which is unambiguous and has a logical
1973 structure.  Typical American style chord names are implemented as a
1974 variation on Banter names, they can be selected by setting poperty
1975 @code{ChordName.style} to @code{american}:
1976
1977 @quotation
1978 @lilypond[verbatim]
1979 \include "english.ly"
1980
1981 scheme = \chords {
1982   c         % Major triad
1983   cs:m      % Minor triad
1984   df:m5-    % Diminished triad
1985   c:5^3     % Root-fifth chord
1986   c:4^3     % Suspended fourth triad
1987   c:5+      % Augmented triad
1988   c:2^3     % "2" chord
1989   c:m5-.7-  % Diminished seventh
1990   c:7+      % Major seventh
1991   c:7.4^3   % Dominant seventh suspended fourth
1992   c:5+.7    % Augmented dominant seventh
1993   c:m5-.7   % "Half" diminished seventh
1994   c:5-.7    % Dominant seventh flat fifth
1995   c:5-.7+   % Major seventh flat fifth
1996   c:m7+     % Minor-major seventh
1997   c:m7      % Minor seventh
1998   c:7       % Dominant seventh
1999   c:6       % Major sixth
2000   c:m6      % Minor sixth
2001   c:9^7     % Major triad w/added ninth
2002   c:6.9^7   % Six/Nine chord
2003   c:9       % Dominant ninth 
2004   c:7+.9    % Major ninth
2005   c:m7.9    % Minor ninth
2006 }
2007
2008 \score {
2009   \notes <
2010     \context ChordNames \scheme
2011     \context Staff \transpose c'' \scheme
2012   >
2013   \paper {
2014     \translator { 
2015       \ChordNamesContext
2016       ChordName \override #'word-space = #1 
2017       ChordName \override #'style = #'american
2018     }
2019   }
2020 }
2021 @end lilypond
2022 @end quotation
2023
2024 Similarly, Jazz style chord names are implemented as a variation on
2025 American style names:
2026 @quotation
2027 @lilypond[verbatim]
2028 scheme = \chords {
2029   % major chords
2030   c
2031   c:6           % 6 = major triad with added sixth
2032   c:maj         % triangle = maj
2033   c:6.9^7       % 6/9 
2034   c:9^7         % add9
2035
2036   % minor chords
2037   c:m           % m = minor triad
2038   c:m.6         % m6 = minor triad with added sixth
2039   c:m.7+        % m triangle = minor major seventh chord
2040   c:3-.6.9^7    % m6/9 
2041   c:m.7         % m7
2042   c:3-.9        % m9
2043   c:3-.9^7      % madd9
2044
2045   % dominant chords
2046   c:7           % 7 = dominant
2047   c:7.5+        % +7 = augmented dominant
2048   c:7.5-        % 7b5 = hard diminished dominant
2049   c:9           % 7(9)
2050   c:9-          % 7(b9)
2051   c:9+          % 7(#9)
2052   c:13^9.11     % 7(13)
2053   c:13-^9.11    % 7(b13)
2054   c:13^11       % 7(9,13)
2055   c:13.9-^11    % 7(b9,13)
2056   c:13.9+^11    % 7(#9,13)
2057   c:13-^11      % 7(9,b13)
2058   c:13-.9-^11   % 7(b9,b13)
2059   c:13-.9+^11   % 7(#9,b13)
2060
2061   % half diminished chords
2062   c:m5-.7               % slashed o = m7b5
2063   c:9.3-.5-     % o/7(pure 9)
2064
2065   % diminished chords
2066   c:m5-.7-      % o = diminished seventh chord
2067 }
2068
2069 \score {
2070   \notes <
2071     \context ChordNames \scheme
2072     \context Staff \transpose c'' \scheme
2073   >
2074   \paper {
2075     \translator { 
2076       \ChordNamesContext
2077       ChordName \override #'word-space = #1 
2078       ChordName \override #'style = #'jazz
2079     }
2080   }
2081 }
2082 @end lilypond
2083 @end quotation
2084
2085
2086 @node lyricprint
2087 @section lyricprint
2088 @cindex lyrics
2089
2090 @cindex printing!lyrics
2091
2092
2093 Lyric syllables must be interpreted within a @code{Lyrics} context
2094
2095 @cindex context!Lyrics
2096  for printing them.
2097
2098 Here is a full example: 
2099
2100 @quotation
2101 @lilypond[verbatim]
2102 \score {
2103   <
2104     \notes \transpose c'' {
2105       c d e c | c d e c |
2106       e f g2 | e4 f g2 \bar "|.";
2107     }
2108     \context Lyrics \lyrics { 
2109       Va-4 der Ja- cob Va- der Ja- cob
2110       Slaapt gij nog?2 Slaapt4 gij nog?2
2111     }
2112   >
2113 }
2114
2115 @end lilypond
2116 @end quotation
2117
2118 You may want a continuous line after the syllables to show melismata. 
2119 To achieve this effect, add a `@code{__}' lyric as a separate word
2120 after the lyric to be extended.  This will create an extender, a line
2121 that extends over the entire duration of the lyric.  This line will
2122 run all the way to the start of the next lyric, so you may want to
2123 shorten it by using a blank lyric (using `@code{_}').
2124
2125 @quotation
2126
2127 @lilypond[verbatim]
2128 \score {
2129   <
2130     \notes \relative c'' {
2131       a4 () b () c () d | c () d () b () a | c () d () b () a
2132     }
2133     \context Lyrics \lyrics {
2134       foo1 __ | bar2. __ _4 | baz1 __
2135     }
2136   >
2137 }
2138
2139 @end lilypond
2140 @end quotation
2141
2142      
2143 If you want to have hyphens centered between syllables (rather than
2144 attached to the end of the first syllable) you can use the special
2145 `@code{-}@code{-}' lyric as a separate word between syllables.  This
2146 will result in a hyphen which length varies depending on the space
2147 between syllables, and which will be centered between the syllables. 
2148 For example:
2149
2150 @quotation
2151
2152 @lilypond[verbatim]
2153 \score {
2154   <
2155     \notes \transpose c'' {
2156       c d e c | c d e c |
2157       e f g2 | e4 f g2 \bar "|.";
2158     }
2159     \context Lyrics \lyrics {
2160       Va4 -- der Ja -- cob | Va -- der Ja -- cob |
2161       Slaapt gij nog?2 | Slaapt4 gij nog?2
2162     }
2163   >
2164 }
2165
2166 @end lilypond
2167 @end quotation
2168
2169
2170
2171 @node Notation Contexts
2172 @section Notation Contexts
2173
2174 @cindex notation contexts
2175
2176 Notation contexts are objects that only exist during a run of
2177 LilyPond.  During the interpretation phase of LilyPond, the Music
2178 expression contained in a @code{\score} block is interpreted in time
2179 order.  This is the order in which humans read, play, and write
2180 music.
2181
2182 A context is an object that holds the reading state of the
2183 expression; it contains information like
2184
2185 @itemize @bullet
2186   @item What notes are playing at this point?
2187   @item What symbols will be printed at this point?
2188   @item In what style will they printed?
2189   @item What is the current key signature, time signature, point within
2190        the measure, etc.?
2191 @end itemize
2192
2193 Contexts are grouped hierarchically: A @code{Voice} context is
2194 contained in a @code{Staff} context (because a staff can contain
2195 multiple voices at any point), a @code{Staff} context is contained in
2196 a @code{Score}, @code{StaffGroup}, or @code{ChoirStaff} context (because
2197 these can all contain multiple staffs).
2198
2199 Contexts associated with sheet music output are called @emph{notation
2200 contexts}, those for sound output are called playing contexts.
2201
2202 Contexts are created either manually or automatically.  Initially,
2203 the top level music expression is interpreted by the top level
2204 context (the @code{Score} context).  When a atomic music expression
2205 (i.e. a note, a rest, @code{\bar}, or @code{\time} commands), a nested
2206 set of contexts is created that can process these atomic expressions,
2207 as in this example:
2208
2209 @example
2210
2211   @example 
2212 \score @{ \notes < c4 > @} 
2213 @end example 
2214
2215 @end example
2216
2217 The sequential music, `@code{@{ c4 @}}' is interpreted by @code{Score}
2218 context. When the note `@code{c4}' itself is interpreted, a set of
2219 contexts is needed that will accept notes.  The default for this is a
2220 @code{Voice} context, contained in a @code{Staff} context.  Creation of
2221 these contexts results in the staff being printed.
2222
2223
2224 @cindex context
2225
2226 You can also create contexts manually, and you probably have to do so
2227 if you want to typeset complicated multiple part material.  If a
2228 `@code{\context} @var{name} @var{musicexpr}' expression is encountered
2229 during the interpretation phase, the @var{musicexpr} argument will be
2230 interpreted with a context of type @var{name}.  If you specify a name,
2231 the specific context with that name is searched.
2232
2233 If a context of the specified type and name can not be found, a new
2234 one is created.  For example,
2235
2236 @quotation
2237
2238 @lilypond[verbatim]
2239 \score {
2240   \notes \relative c'' {
2241     c4 <d4 \context Staff = "another" e4> f
2242   }
2243 }
2244
2245 @end lilypond
2246 @end quotation
2247
2248 In this example, the @code{c} and @code{d} are printed on the
2249 default staff.  For the @code{e}, a context Staff called
2250 `@code{another}' is specified; since that does not exist, a new
2251 context is created.  Within @code{another}, a (default) Voice context
2252 is created for the @code{e4}.  When all music referring to a
2253 context is finished, the context is ended as well.  So after the
2254 third quarter, @code{another} is removed.
2255
2256 Almost all music expressions inherit their interpretation context
2257 from their parent.  In other words, suppose that the syntax for a
2258 music expression is
2259
2260 @example
2261
2262   \keyword @var{musicexpr1} @var{musicexpr2} @dots{}
2263 @end example
2264
2265 When the interpretation of this music expression starts, the context
2266 for @var{musicexpr1}, @var{musicexpr2}, etc. is that of the total
2267 expression.
2268
2269 Lastly, you may wonder, why this:
2270
2271 @quotation
2272
2273 @example 
2274 \score @{
2275   \notes \relative c'' @{
2276     c4 d4 e4
2277   @}
2278 @} 
2279 @end example 
2280
2281 @end quotation
2282
2283 doesn't result in this:
2284
2285 @lilypond[]
2286
2287   \score {
2288     \notes \relative c'' {
2289       <c4> <d4> <e4>
2290     }
2291   }
2292
2293 @end lilypond
2294
2295 For the @code{c4}, a default @code{Staff} (with a contained
2296 @code{Voice}) context is created.  After the @code{c4} ends, no
2297 music refers to this default staff, so it would be ended, with the
2298 result shown.  To prevent this inconvenient behavior, the context to
2299 which the sequential music refers is adjusted during the
2300 interpretation.  So after the @code{c4} ends, the context of the
2301 sequential music is also the default @code{Voice} context. 
2302 The @code{d4} gets interpreted in the same context
2303 as @code{c4}.
2304
2305 Properties that are set in one context are inherited by all of the
2306 contained contexts.  This means that a property valid for the
2307 @code{Voice} context can be set in the @code{Score} context (for
2308 example) and thus take effect in all @code{Voice} contexts.
2309
2310 Properties can be preset within the @code{\translator} block
2311 corresponding to the appropriate context.  In this case, the syntax
2312 is
2313
2314 @example
2315   @var{propname} @code{=} @var{value}
2316 @end example
2317
2318 This assignment happens before interpretation starts, so a
2319 @code{\property} expression will override any predefined settings.
2320
2321 The property settings are used during the interpretation phase.  They
2322 are read by the LilyPond modules where interpretation contexts are
2323 built of.  These modules are called @emph{translators}.  Translators for
2324 notation are called @emph{engravers}, and translators for sound are
2325 called @emph{performers}.
2326
2327
2328 @mbinclude properties.itely
2329
2330 @node Page layout
2331 @section Page layout
2332
2333 @subsection Paper block
2334
2335 The most important output definition is the @code{\paper} block, for
2336 music notation.  The syntax is
2337
2338 @example
2339   @code{\paper @{} [@var{paperidentifier}] @var{items} @code{@}}
2340 @end example
2341
2342 where each of the items is one of
2343
2344 @itemize @bullet
2345   @item  An assignment.  The assignment must be terminated by a
2346        semicolon.  
2347
2348   @item  A context definition.  See section @ref{contextdefs} for
2349        more information on context definitions.
2350
2351 @ignore
2352
2353                 FIXME
2354
2355
2356   @item
2357         
2358         A margin shape declaration.  The syntax is
2359
2360        @example
2361
2362          \shape @var{indent1}@code{,} @var{width1}@code{,}
2363                       @var{indent2}@code{,} @var{width2} @dots{} @code{;}
2364        @end example
2365
2366        @keyindex{shape}
2367
2368        Each pair of @var{indent} and @var{width} values is a dimension
2369        specifying how far to indent and how wide to make the line. 
2370        The indentation and width of successive lines are specified by
2371        the successive pairs of dimensions.  The last pair of
2372        dimensions will define the characeristics of all lines beyond
2373        those explicitly specified.
2374 @end ignore
2375
2376   @item  \stylesheet  declaration.  Its syntax is
2377        @example
2378                 \stylesheet @var{alist}
2379        @end example
2380
2381         See @file{font.scm} for details of @var{alist}.
2382 @end itemize
2383
2384
2385 @subsection Paper variables 
2386
2387 The paper block has some variables you may want to use or change:
2388
2389 @table @samp
2390   @item @code{indent}@indexcode{indent}  
2391     The indentation of the first line of music.
2392
2393   @item @code{staffspace}@indexcode{staffspace}
2394     The distance between two staff lines, calculated from the center
2395     of the lines.  You should use either this or @code{rulethickness}
2396     as a unit for distances you modify.
2397   
2398   @item @code{linewidth}@indexcode{linewidth}  
2399     Sets the width of the lines.  If set to -1.0, a single
2400     unjustified line is produced.  If you use this variable, you
2401     probably want to define it in staff spaces, ie
2402     @example
2403         linewidth = 30 * \staffspace;
2404     @end example
2405
2406   @item @code{textheight}@indexcode{textheight}  
2407     Sets the total height of the music on each page. Only used by
2408     ly2dvi.
2409
2410   @item @code{interscoreline}@indexcode{interscoreline}  
2411     Sets the spacing between the score lines. Defaults to 16 pt.
2412
2413   @item @code{interscorelinefill}@indexcode{interscorelinefill}  
2414     If set to a positive number, the distance between the score 
2415     lines will stretch in order to fill the full page. In that
2416     case @code{interscoreline} specifies the minimum spacing.
2417     Defaults to 0.
2418
2419   @item @code{stafflinethickness}@indexcode{stafflinethickness}  
2420     Determines the thickness of staff lines, and also acts as a scaling
2421     parameter for other line thicknesses.
2422 @end table
2423
2424
2425 @subsection Line breaks
2426
2427 @cindex line breaks
2428 @cindex breaking lines
2429
2430 Line breaks are normally computed automatically. They are chosen such
2431 that the resulting spacing has low variation, and looks neither cramped
2432 nor loose.
2433
2434 Occasionally you might want to override the automatic breaks; you can do
2435 this by specifying @code{\break} (see also @ref{Pre-defined
2436 Identifiers}). This will force a line break at this point. Do remember
2437 that line breaks can only occur at places where there are barlines.  If
2438 you want to have a line break where there is no barline, you can force a
2439 barline by entering @code{\bar "";}.
2440
2441 @subsection Page breaks
2442
2443 Page breaks are normally computed by @TeX{}, so they are not under direct
2444 control.  However, you can insert a commands into the .tex output to
2445 instruct @TeX{} where to break pages. For more details, see  the
2446 example file @file{input/test/between-systems.ly}
2447
2448
2449 @cindex page breaks
2450 @cindex breaking pages
2451
2452
2453 @subsection Font size
2454
2455 @cindex font size
2456 @cindex paper size
2457
2458 The Feta font provides musical symbols at six different sizes.  These
2459 fonts are 11 point, 13 point, 16 point, 20 point,
2460 23 point, and 26 point.  The point size of a font is the
2461 height of the five lines in a staff when displayed in the font.
2462
2463 Definitions for these sizes are the files @file{paperSZ.ly}, where
2464 @code{SZ} is one of 11, 13, 16, 20, 23 and 26.  If you include any of
2465 these files, the identifiers @code{paperEleven}, @code{paperThirteen},
2466 @code{paperSixteen}, @code{paperTwenty}, @code{paperTwentythree}, and
2467 @code{paperTwentysix} are defined respectively.  The default
2468 @code{\paper} block is also set.
2469
2470 The font definitions are generated using a Scheme function. For more
2471 details, see the file @file{font.scm}.
2472
2473 @subsection paper size
2474
2475 @cindex paper size
2476 @cindex page size
2477
2478 To change the paper size, you must first set the
2479 @code{papersize}@indexcode{papersize} variable at top level.  Set it to
2480 the strings @code{a4}, @code{letter}, or @code{legal}.  After this
2481 specification, you must set the font as described above.  If you want
2482 the default font, then use the 20 point font.  The new paper size will
2483 not take effect if the font is not loaded and selected afterwards.
2484
2485 @example
2486         papersize = "a4"
2487         \include "paper16.ly"
2488
2489         \score @{
2490                 ...
2491                 \paper @{ \paperSixteen @}
2492         @}
2493 @end example
2494
2495 The file "paper16.ly" will now include a file named @file{a4.ly}, which
2496 will set the paper variables @code{hsize} and @code{vsize} (used by
2497 @code{ly2dvi})
2498
2499 @node contextdefs
2500 @section contextdefs
2501
2502 @cindex context definition
2503 @cindex translator definition
2504 @cindex engraver hacking
2505
2506
2507 A notation contexts is defined by the following information
2508
2509 @enumerate i
2510   @item  A name.
2511
2512   @item  The LilyPond modules that do the actual conversion of music to
2513        notation.  Each module is a so-called
2514        @emph{engraver}
2515 @cindex engraver
2516 .
2517
2518   @item  How these modules should cooperate, i.e. which ``cooperation
2519        module'' should be used.  This cooperation module is a special
2520        type of engraver.
2521
2522   @item  What other contexts the context can contain,
2523
2524   @item  What properties are defined.
2525 @end enumerate
2526
2527 A context definition has this syntax:
2528
2529 @example
2530
2531   \translator @code{@{}
2532                       @var{translatorinit} @var{translatormodifierlist}
2533                     @code{@}}
2534 @end example
2535
2536 @var{translatorinit} can be an identifier or of the form
2537
2538 @example
2539
2540   \type @var{typename} @code{;}
2541 @end example
2542
2543 @var{typename} is one of
2544
2545 @table @samp
2546   @item @code{Engraver_group_engraver}@indexcode{Engraver_group_engraver}  
2547     The standard cooperation engraver.
2548
2549   @item @code{Score_engraver}@indexcode{Score_engraver}  
2550     This is cooperation module that should be in the top level context.
2551
2552   @item @code{Grace_engraver_group}@indexcode{Grace_engraver_group}  
2553     This is a special cooperation module (resembling
2554     @code{Score_engraver}) that is used to created an embedded
2555     `miniscore'.
2556 @end table 
2557
2558 @var{translatormodifierlist} is a list of items where each item is
2559 one of
2560
2561 @itemize @bullet
2562   @item  @code{\consists} @var{engravername} @code{;}  
2563     Add @var{engravername} to the list of modules in this context. 
2564   The order of engravers added with @code{\consists} is
2565     significant.
2566   
2567   @item  @code{\consistsend} @var{engravername} @code{;}  
2568     Analogous to @code{\consists}, but makes sure that
2569     @var{engravername} is always added to the end of the list of
2570     engravers.
2571
2572     Some engraver types need to be at the end of the list; this
2573     insures they are put there, and stay there, if a user adds or
2574     removes engravers.  This command is usually not needed for
2575     end-users.
2576     
2577   @item  @code{\accepts} @var{contextname} @code{;}  
2578     Add @var{contextname} to the list of  context this context can
2579     contain.  The first listed context is the context to create by
2580     default.
2581
2582   @item @code{\denies}. The opposite of @code{\accepts}. Added for
2583 completeness, but is never used in practice.
2584  
2585   
2586   @item  @code{\remove} @var{engravername} @code{;}  
2587     Remove a previously added (with @code{\consists}) engraver.
2588   
2589   @item  @code{\name} @var{contextname} @code{;}  
2590     This sets name of the context, e.g. @code{Staff}, @code{Voice}.  If
2591     the name is not specified, the translator won't do anything.
2592
2593   @item  @var{propname} @code{=} @var{value} @code{;}  
2594     A property assignment.  It is allowed to use reals for
2595     @var{value}.
2596 @end itemize
2597
2598 In the @code{\paper} block, it is also possible to define translator
2599 identifiers.  Like other block identifiers, the identifier can only
2600 be used as the very first item of a translator.  In order to define
2601 such an identifier outside of @code{\score}, you must do
2602
2603 @quotation
2604
2605 @example 
2606 \paper @{
2607   foo = \translator @{ @dots{} @}
2608 @}
2609 \score @{
2610   \notes @{
2611     @dots{}
2612   @}
2613   \paper @{
2614     \translator @{ \foo @dots{} @}
2615   @}
2616 @} 
2617 @end example 
2618
2619 @end quotation
2620
2621
2622 @cindex paper types, engravers, and pre-defined translators
2623
2624 Some pre-defined identifiers can simplify modification of
2625 translators.  The pre-defined identifiers are:
2626
2627 @table @samp
2628   @item @code{StaffContext}@indexcode{StaffContext}  
2629     Default Staff context. 
2630
2631   @item @code{RhythmicStaffContext}@indexcode{RhythmicStaffContext}  
2632     Default RhythmicStaff context. 
2633
2634   @item @code{VoiceContext}@indexcode{VoiceContext}  
2635     Default Voice context.  
2636
2637   @item @code{ScoreContext}@indexcode{ScoreContext}  
2638     Default Score context. 
2639
2640   @item @code{ScoreWithNumbers}@indexcode{ScoreWithNumbers}  
2641     Score context with numbering at the Score level.
2642
2643   @item @code{BarNumberingStaffContext}@indexcode{BarNumberingStaffContext}  
2644     Staff context with numbering at the Staff level.
2645
2646   @item @code{HaraKiriStaffContext}@indexcode{HaraKiriStaffContext}  
2647     Staff context that does not print if it only contains rests. 
2648     Useful for orchestral scores.@footnote{Harakiri, also called
2649     Seppuku, is the ritual suicide of the Samourai.}
2650
2651   @item @code{OrchestralPartStaffContext}@indexcode{OrchestralPartStaffContext}
2652
2653   @item @code{OrchestralScoreContext}@indexcode{OrchestralScoreContext}
2654 @end table
2655
2656 Using these pre-defined values, you can remove or add items to the
2657 translator:
2658
2659 @quotation
2660
2661 @example 
2662 \paper @{
2663   \translator @{
2664     \StaffContext
2665     \remove Some_engraver;
2666     \consists Different_engraver;
2667   @}
2668 @} 
2669 @end example 
2670
2671 @end quotation
2672
2673       
2674 @node Sound output
2675 @section Sound output
2676
2677 The MIDI block is analogous to the paper block, but it is somewhat
2678 simpler.  The @code{\midi} block can contain:
2679 @cindex MIDI block
2680
2681 @itemize @bullet
2682   @item  a @code{\tempo} definition
2683   @item  context definitions
2684 @end itemize
2685
2686 Assignments in the @code{\midi} block are not allowed.
2687
2688
2689
2690 @cindex context definition
2691
2692 Context definitions follow precisely the same syntax as within the
2693 \paper block.  Translation modules for sound are called performers.
2694 The contexts for MIDI output are defined in @file{ly/performer.ly}.
2695
2696
2697
2698 @cindex MIDI instrument names
2699
2700 @node midilist
2701 @section midilist
2702
2703 The MIDI instrument name is set by the
2704 @code{Staff.midiInstrument}@indexcode{Staff.midiInstrument} property or,
2705 if that property is not set, the
2706 @code{Staff.instrument}@indexcode{Staff.instrument} property.  The
2707 instrument name should be chosen from the following list.  If the
2708 selected string does not exactly match, then LilyPond uses the default
2709 piano.
2710
2711 @c @quotation
2712
2713 @example 
2714 "acoustic grand"            "contrabass"           "lead 7 (fifths)"
2715 "bright acoustic"           "tremolo strings"      "lead 8 (bass+lead)"
2716 "electric grand"            "pizzicato strings"    "pad 1 (new age)"
2717 "honky-tonk"                "orchestral strings"   "pad 2 (warm)"
2718 "electric piano 1"          "timpani"              "pad 3 (polysynth)"
2719 "electric piano 2"          "string ensemble 1"    "pad 4 (choir)"
2720 "harpsichord"               "string ensemble 2"    "pad 5 (bowed)"
2721 "clav"                      "synthstrings 1"       "pad 6 (metallic)"
2722 "celesta"                   "synthstrings 2"       "pad 7 (halo)"
2723 "glockenspiel"              "choir aahs"           "pad 8 (sweep)"
2724 "music box"                 "voice oohs"           "fx 1 (rain)"
2725 "vibraphone"                "synth voice"          "fx 2 (soundtrack)"
2726 "marimba"                   "orchestra hit"        "fx 3 (crystal)"
2727 "xylophone"                 "trumpet"              "fx 4 (atmosphere)"
2728 "tubular bells"             "trombone"             "fx 5 (brightness)"
2729 "dulcimer"                  "tuba"                 "fx 6 (goblins)"
2730 "drawbar organ"             "muted trumpet"        "fx 7 (echoes)"
2731 "percussive organ"          "french horn"          "fx 8 (sci-fi)"
2732 "rock organ"                "brass section"        "sitar"
2733 "church organ"              "synthbrass 1"         "banjo"
2734 "reed organ"                "synthbrass 2"         "shamisen"
2735 "accordion"                 "soprano sax"          "koto"
2736 "harmonica"                 "alto sax"             "kalimba"
2737 "concertina"                "tenor sax"            "bagpipe"
2738 "acoustic guitar (nylon)"   "baritone sax"         "fiddle"
2739 "acoustic guitar (steel)"   "oboe"                 "shanai"
2740 "electric guitar (jazz)"    "english horn"         "tinkle bell"
2741 "electric guitar (clean)"   "bassoon"              "agogo"
2742 "electric guitar (muted)"   "clarinet"             "steel drums"
2743 "overdriven guitar"         "piccolo"              "woodblock"
2744 "distorted guitar"          "flute"                "taiko drum"
2745 "guitar harmonics"          "recorder"             "melodic tom"
2746 "acoustic bass"             "pan flute"            "synth drum"
2747 "electric bass (finger)"    "blown bottle"         "reverse cymbal"
2748 "electric bass (pick)"      "skakuhachi"           "guitar fret noise"
2749 "fretless bass"             "whistle"              "breath noise"
2750 "slap bass 1"               "ocarina"              "seashore"
2751 "slap bass 2"               "lead 1 (square)"      "bird tweet"
2752 "synth bass 1"              "lead 2 (sawtooth)"    "telephone ring"
2753 "synth bass 2"              "lead 3 (calliope)"    "helicopter"
2754 "violin"                    "lead 4 (chiff)"       "applause"
2755 "viola"                     "lead 5 (charang)"     "gunshot"
2756 "cello"                     "lead 6 (voice)" 
2757 @end example 
2758
2759 @c @end quotation
2760
2761
2762 @node Pre-defined Identifiers
2763
2764 @section Pre-defined Identifiers
2765
2766 @cindex pre-defined identifiers
2767
2768
2769 Various identifiers are defined in the initialization files to
2770 provide shorthands for some settings.  Most of them are in
2771 @file{ly/declarations.ly} and @file{ly/property.ly}.
2772
2773 @table @samp
2774   @item @code{\break}@keyindex{break}  
2775     Force a line break in music by using a large argument for the
2776     keyword @code{\penalty}.
2777
2778   @item @code{\nobreak}@keyindex{nobreak}  
2779     Prevent a line break in music by using a large negative argument
2780     for the keyword @code{\penalty}.
2781
2782   @item @code{\shiftOff}@keyindex{shiftOff}  
2783     Disable horizontal shifting of note heads that collide. 
2784
2785   @item @code{\shiftOn}@keyindex{shiftOn}  
2786     Enable note heads that collide with other note heads to be
2787     shifted horiztonally. Also @code{\shiftOnn} and @code{\shiftOnnn}
2788 set different shift values.
2789
2790   @item @code{\stemBoth}@keyindex{stemBoth}  
2791     Allow stems, beams, and slurs to point either upwards or
2792     downwards, decided automatically by LilyPond.
2793
2794   @item @code{\stemDown}@keyindex{stemDown}  
2795     Force stems, beams, and slurs to point down.
2796
2797   @item @code{\stemUp}@keyindex{stemUp}  
2798     Force stems, beams and slurs to point up.
2799
2800 @end table
2801
2802