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