2 @c This file is part of lilypond.tely
5 @c * more details about running lilypond; error messages,
6 @c compiling/viewing (emacs?)
7 @c * where to go from First steps+More basics?
9 @c Your first LilyPond score in 10 minutes?
14 This tutorial starts with a short introduction to the LilyPond music
15 language. After this first contact we will show you how to to produce
16 printed output. Then you will be able to create and print your own
20 Many people learn programs by trying and fiddling around with the
21 program. This is also possible with LilyPond. If you click on a
22 picture in the HTML version of this manual, you will see the exact
23 LilyPond input that was used to generate that image.
26 @lilypond[raggedright,relative=2]
27 c-\markup { \bold \huge { Click here. } }
32 By cutting and pasting the full input into a test file, you have a
33 starting template for experiments. If you like learning in this way,
34 you will probably want to print out or bookmark
38 @ref{Cheat sheet}, which is a table listing all commands for quick
42 In this tutorial, we will show step by step how to enter such files,
43 and illustrate the process with fragments of input and the
44 corresponding output. At the end of every section, a paragraph will
45 list where to find further information on the topics discussed.
51 * More about pitches::
53 * Automatic and manual beams::
55 * Music expressions explained::
57 * Adding articulation marks to notes::
58 * Combining notes into chords::
59 * Basic rhythmical commands::
60 * Commenting input files::
63 * Listening to output::
65 * Single staff polyphony::
67 * Organizing larger pieces::
68 * An orchestral part::
69 * Integrating text and music::
76 The first example demonstrates how to enter the most elementary piece
77 of music, a scale. A note can be entered by typing its name, from
78 @samp{a} through @samp{g}. So, if you enter
85 the result looks like this
88 @lilypond[notime,relative=1]
93 The duration of a note is specified by a number after the note name.
94 @samp{1} for a @rglos{whole note}, @samp{2} for a @rglos{half note},
95 @samp{4} for a @rglos{quarter note} and so on
103 \set Score.timing = ##f
104 \set Staff.autoBeaming = ##f
105 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
109 If you do not specify a @rglos{duration}, the duration last entered is
110 used; the first note's duration defaults to a quarter
111 @c FIXME: let's omit the first note rule?
112 @c The first note will be a quarter
120 \set Score.timing = ##f
121 \transpose c c' { a a8 a a2 a s16_" " }
126 Rests are entered just like notes, but with the name ``@code{r}''
135 \set Score.timing = ##f
136 \set Staff.Clef = \turnOff
137 \set Staff.TimeSignature = \turnOff
144 Add a dot @samp{.} after the duration to get a @rglos{dotted note}
152 \set Score.timing = ##f
153 \transpose c c' { a2. a4 a8. a16 s16_" " }
157 The @rglos{meter} (or @rglos{time signature}) can be set with the
166 @c A clef here may lead to confusion, remove it.
169 \override Staff.Clef #'transparent = ##t
179 The @rglos{clef} can be set using the @code{\clef} command
181 @c what is more common name treble or violin?
182 @c in Dutch, it is violin.
183 @c in English it is definitely treble.
193 \set Score.timing = ##f
205 To recognize names like @code{c} and @code{d} as pitches, they have to
206 be entered inside a so-called @code{\notes} block. This block is
207 formed by enclosing notes and commands are enclosed in curly braces
208 @code{@{ @dots{} @}} and adding the keyword @code{\notes} before the
220 Now the piece of music is almost ready to be printed. Enclose
221 the @code{\notes} block in a @code{\score} block
234 and the music will be converted to printable output.
246 linewidth = 55 * \staffspace
252 In many examples in this manual, both @code{\score} and @code{\notes}
253 and accompanying braces are left out for brevity. However, they must
254 be present when feeding the file to LilyPond.
256 For more elaborate information on
259 @item Entering pitches and durations
261 @ref{Pitches} and @ref{Durations}.
266 @item Time signatures and other timing commands
267 see @ref{Time signature}.
271 @node Running LilyPond
272 @section Running LilyPond
274 @c FIXME: let's not be so casual about Emacs and VIM, but rather
275 @c instruct (how) to use them; let advanced user figure-out what
278 In the last section we explained what kind of things you could enter
279 in a LilyPond file. In this section we will explain what commands to
280 run and how to view or print the output. If you have not used
281 LilyPond before, want to test your setup, or want to run an example
282 file yourself, read this section. The instructions that follow are
283 for Unix-like systems. Some additional instructions for Microsoft
284 Windows are given at the end of this section.
286 @c FIXME: remove footnotes/integrate in text
287 Begin by opening a terminal window and starting a text editor. For
288 example, you could open an xterm and execute
289 @code{joe}@footnote{There are macro files for VIM addicts, and there
290 is a @code{LilyPond-mode} for Emacs addicts. If it has not been
291 installed already, refer to the file @file{INSTALL.txt}}. In your
292 text editor, enter the following input and save the file as
297 \notes @{ c'4 e' g' @}
302 To process @file{test.ly}, proceed as follows
310 You will see something resembling
314 Now processing: `/home/fred/ly/test.ly'
316 Interpreting music...[1]
317 @emph{ ... more interesting stuff ... }
318 PDF output to `test.pdf'...
319 DVI output to `test.dvi'...
322 @cindex Viewing music
326 The result is the file @file{test.pdf}@footnote{For @TeX{}
327 aficionados: there is also a @file{test.dvi} file. It can be viewed
328 with @code{xdvi}. The DVI uses a lot of PostScript specials, which do
329 not show up in the magnifying glass. The specials also mean that the
330 DVI file cannot be processed with @code{dvilj}. Use @code{dvips} for
335 } which you can print or with the standard facilities of your
336 operating system.@footnote{If your system does not have any tools
337 installed, you can try @uref{Ghostscript,
338 http://www.cs.wisc.edu/~ghost/}, a freely available package for
339 viewing and printing PDF and PostScript files.}
341 On Windows, start up a text-editor@footnote{Any simple or
342 programmer-oriented editor will do, for example Notepad. Do not use a
343 word processor, its formatting codes will confuse LilyPond} and enter
347 \notes @{ c'4 e' g' @}
351 Save it on the desktop as @file{test.ly} and make sure that it is not
352 called @file{test.ly.TXT}. Double clicking @file{test.ly} will process
353 the file and show the resulting PDF file.
356 @node More about pitches
357 @section More about pitches
359 A @rglos{sharp} (@texisharp{}) pitch is made by adding @samp{is} to
360 the name, a @rglos{flat} (@texiflat{}) pitch by adding @samp{es}. As
361 you might expect, a @rglos{double sharp} or @rglos{double flat} is
362 made by adding @samp{isis} or @samp{eses}:@footnote{This syntax
363 derived from note naming conventions in Nordic and Germanic languages,
364 like German and Dutch.}
372 \set Score.timing = ##f
373 \transpose c c' { cis1 ees fisis aeses s16_" " }
377 @cindex key signature, setting
378 The key signature is set with the command ``@code{\key}'', followed by
379 a pitch and @code{\major} or @code{\minor}
389 \set Staff.TimeSignature = \turnOff
398 Key signatures together with the pitches (including alterations) are
399 used together to determine when to print accidentals. This is a
400 feature that often causes confusion to newcomers, so let us explain it
404 LilyPond makes a sharp distinction between musical content and
405 layout. The alteration (flat, natural or sharp) of a note is part of
406 the pitch, and is therefore musical content. Whether an accidental (a
407 flat, natural or sharp @emph{sign}) is a printed in front of the
408 corresponding note is a question of layout. Layout is something that
409 follows rules, so accidentals are printed automatically according to
410 those rules. The pitches in your music are works of art, so they will
411 not be added automatically, and you must enter what you want to hear.
417 \set Staff.TimeSignature = \turnOff
424 no note gets an explicit accidental, but still you enter
431 The code @code{d} does not mean ``print a black dot just below the
432 staff.'' Rather, it means: ``a note with pitch D-natural.'' In the key
433 of A-flat, it does get an accidental
437 \set Staff.TimeSignature = \turnOff
448 Adding all alterations explicitly might require a little more effort
449 when typing, but the advantage is that transposing is easier, and
450 music can be printed according to different conventions. See
451 @ref{Accidentals} for some examples how accidentals can be printed
452 according to different rules.
455 For more information on
459 see @ref{Accidentals}
462 see @ref{Key signature}
466 @section Entering ties
469 A tie is created by adding a tilde ``@code{~}'' to the first note
472 @lilypond[fragment,verbatim,relative=3]
479 For more information on Ties, see @ref{Ties}.
483 @node Automatic and manual beams
484 @section Automatic and manual beams
486 @cindex beams, by hand
487 Beams are drawn automatically
490 @lilypond[fragment,relative=2,verbatim]
496 If you do not like where beams are put, they can be entered by
497 hand. Mark the first note to be beamed with @code{[} and the last one
501 @lilypond[fragment,relative=2,verbatim]
507 For more information on beams, see @ref{Beaming}.
510 Here are key signatures, accidentals and ties in action
520 fis4 fis8 fis8 eis4 a8 gis~
528 \notes \transpose c c' {
534 fis4 fis8 fis8 eis4 a8 gis~
537 \paper { linewidth = #(* 50 staffspace) }
543 There are some interesting points to note in this example. Bar lines
544 and beams are drawn automatically. Line breaks are calculated
545 automatically; it does not matter where the line breaks are in the
546 source file. Finally, the order in which time, key and clef changes
547 are entered is not relevant: in the printout, these are ordered
548 according to standard notation conventions.
553 @section Octave entry
556 @c Tim wants to move this quotes example just before the: quotes-do not-work
557 @c score, but we'd need to remove quotes from the other two (key and
560 @c better to have this just before the `octaves are bad' snipped
561 @c but we'd need to remove the ', from \key and tie
562 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
563 the note name, to lower a note one octave, add a ``low quote'' @code{,}
564 (a comma). Middle C is @code{c'}
567 c'4 c'' c''' \clef bass c c,
572 \set Score.timing = ##f
573 \set Staff.TimeSignature = \turnOff
574 c'4 c'' c''' \clef bass c c,
579 An example of the use of quotes is in the following Mozart fragment
581 @lilypond[raggedright,fragment,verbatim]
584 cis''8. d''16 cis''8 e''4 e''8
585 b'8. cis''16 b'8 d''4 d''8
589 This example shows that music in a high register needs lots of quotes.
590 This makes the input less readable, and it is a source of errors. The
591 solution is to use ``relative octave'' mode. In practice, this is the
592 most convenient way to copy existing music. To use relative mode, add
593 @code{\relative} before the piece of music. You must also give a note
594 from which relative starts, in this case @code{c''}. If you do not
595 use octavation quotes (i.e. do not add @code{'} or @code{,} after a
596 note), relative mode chooses the note that is closest to the previous
597 one. For example, @code{c f} goes up while @code{c g} goes down
607 \set Score.timing = ##f
608 \set Staff.TimeSignature = \turnOff
617 Since most music has small intervals, pieces can be written almost
618 without octavation quotes in relative mode. The previous example is
622 @lilypond[raggedright,fragment,verbatim]
632 @c needed better, maybe even redundant explanation
633 @c added another example below.
634 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
635 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
636 Larger intervals are made by adding octavation quotes.
645 \set Score.timing = ##f
646 \set Staff.TimeSignature = \turnOff
654 In @code{\relative} mode, quotes or commas no longer determine the
655 absolute height of a note. Rather, the height of a note is relative to
656 the previous one, and changing the octave of a single note shifts all
657 following notes an octave up or down.
659 For more information on Relative octaves see @ref{Relative octaves}
660 and @ref{Octave check}.
663 @node Music expressions explained
664 @section Music expressions explained
667 In input files, music is represent by so-called @emph{music
668 expression}. We have already seen in the previous examples;
669 a single note is a music expression
672 @lilypond[verbatim,relative=3]
677 Enclosing group of notes in braces creates a new music
681 @lilypond[verbatim,relative=3]
686 Putting a bunch of music expressions (notes) in braces, means that
687 they should be played in sequence. The result again is a music
688 expression, which can be grouped with other expressions sequentially.
689 Here, the expression from the previous example is combined with two
693 @lilypond[verbatim,relative=3]
698 This technique becomes useful for non-monophonic music. To enter music
699 with more voices or more staves, we also combine expressions in
700 parallel. Two voices that should play at the same time, are entered as
701 a simultaneous combination of two sequences. A ``simultaneous'' music
702 expression is formed by enclosing expressions in @code{<<} and
703 @code{>>}. In the following example, three sequences (all containing
704 two notes) are combined simultaneously
707 @lilypond[verbatim,relative=3]
716 This mechanism is similar to mathematical
717 formulas: a big formula is created by composing small formulas. Such
718 formulas are called expressions, and their definition is recursive, so
719 you can make arbitrarily complex and large expressions. For example,
728 ((1 + 2) * 3) / (4 * 5)
731 @cindex music expression
732 This example shows a sequence of expressions, where each expression is
733 contained in the next one. The simplest expressions are numbers and
734 operators (like +, * and /). Parentheses are used to group
737 Like mathematical expressions, music expressions can be nested
738 arbitrarily deep, e.g.
740 @lilypond[verbatim,relative=2]
743 << { e f } { c <<b d>> } >>
750 When spreading expressions over multiple lines, it is customary to use
751 an indent that indicates the nesting level. Formatting music like this
752 eases reading, and helps you insert the right number of closing
753 braces at the end of an expression. For example,
768 Some editors have special support for entering LilyPond, and can help
769 indenting source files. See @ref{Editor support} for more information.
776 To print more than one staff, each piece of music that makes up a
777 staff is marked by adding @code{\new Staff} before it. These
778 @code{Staff}'s are then combined parallel with @code{<<} and
779 @code{>>}, as demonstrated here
782 @lilypond[fragment,verbatim]
784 \new Staff { \clef violin c'' }
785 \new Staff { \clef bass c }
791 The command @code{\new} introduces a ``notation context.'' A notation
792 context is an environment in which musical events (like notes or
793 @code{\clef} commands) are interpreted. For simple pieces, such
794 notation contexts are created implicitly. For more complex pieces, it
795 is best to mark contexts explicitly. This ensures that each fragment
798 There are several types of contexts: @code{Staff}, @code{Voice} and
799 @code{Score} handle normal music notation. Other staves are also
800 @code{Lyrics} (for setting lyric texts) and @code{ChordNames} (for
801 printing chord names).
804 In terms of syntax, prepending @code{\new} to a music expression
805 creates a bigger music expression. In this way it resembles the minus
806 sign in mathematics. The formula (4+5) is an expression, so -(4+5) is a bigger
809 We can now typeset a melody with two staves
811 @c TODO: (c) status of this Paul McCartney (?) song (let's all stand together)
814 @lilypond[verbatim,raggedright]
834 For more information on context see the description in
835 @ref{Interpretation contexts}.
839 @node Adding articulation marks to notes
840 @section Adding articulation marks to notes
846 Common accents can be added to a note using a dash (`@code{-}') and a
849 @lilypond[verbatim,relative=2]
850 c-. c-- c-> c-^ c-+ c-_
856 Similarly, fingering indications can be added to a note using a dash
857 (`@code{-}') and the digit to be printed
860 @lilypond[verbatim,relative=2]
866 Dynamic signs are made by adding the markings (with a backslash) to
869 @lilypond[verbatim,relative=2]
879 Crescendi and decrescendi are started with the commands @code{\<} and
880 @code{\>}. An ending dynamic, for example @code{\f}, will finish the
881 crescendo, or the command @code{\!} can be used
883 @lilypond[verbatim,relative=2]
893 A slur is a curve drawn across many notes, and indicates legato
894 articulation. The starting note and ending note are marked with a
895 ``@code{(}'' and a ``@code{)}'' respectively
898 @lilypond[fragment,relative=2,verbatim]
899 d4( c16)( cis d e c cis d e)( d4)
903 @cindex slurs versus ties
904 A slur looks like a tie, but it has a different meaning. A tie simply
905 makes the first note sound longer, and can only be used on pairs of
906 notes with the same pitch. Slurs indicate the articulations of notes,
907 and can be used on larger groups of notes. Slurs and ties are also
911 @lilypond[fragment,relative=2]
912 c2~( c8 fis fis4 ~ fis2 g2)
915 @cindex phrasing slurs
916 Slurs to indicate phrasing can be entered with @code{\(} and
917 @code{\)}, so you can have both legato slurs and phrasing slurs at the
921 @lilypond[fragment,relative=2,verbatim]
922 a8(\( ais b c) cis2 b'2 a4 cis, c\)
927 For more information on
930 see @ref{Fingering instructions}
932 see @ref{Articulations}
936 see @ref{Phrasing slurs}
942 @node Combining notes into chords
943 @section Combining notes into chords
946 Chords can be made by surrounding pitches with angled brackets.
947 Angled brackets are the symbols @code{<} and @code{>}.
950 @lilypond[relative=1,fragment,verbatim]
957 You can combine markings like beams and ties with chords. They must
958 be placed outside the angled brackets
960 @lilypond[relative=1,fragment,verbatim]
961 r4 <c e g>8[ <c f a>]~ <c f a>
966 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
969 @lilypond[relative=1,fragment]
971 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
979 @node Basic rhythmical commands
980 @section Basic rhythmical commands
984 @cindex partial measure
985 A pickup is entered with the keyword @code{\partial}. It
986 is followed by a duration: @code{\partial 4} is a quarter note upstep
987 and @code{\partial 8} an eighth note
989 @lilypond[relative=2,verbatim,fragment]
996 Tuplets are made with the @code{\times} keyword. It takes two
997 arguments: a fraction and a piece of music. The duration of the piece
998 of music is multiplied by the fraction. Triplets make notes occupy
999 2/3 of their notated duration, so a triplet has 2/3 as its fraction
1002 @lilypond[relative=1,verbatim,fragment]
1003 \times 2/3 { f8 g a }
1004 \times 2/3 { c r c }
1008 @cindex accacciatura
1009 Grace notes are also made by prefixing a music expression with the
1010 keyword @code{\appoggiatura} or @code{\acciaccatura}
1011 @cindex appoggiatura
1012 @cindex acciaccatura
1015 @lilypond[relative=2,verbatim,fragment]
1016 c4 \appoggiatura b16 c4
1017 c4 \acciaccatura b16 c4
1023 For more information on
1026 see @ref{Grace notes},
1030 see @ref{Partial measures}.
1035 @node Commenting input files
1036 @section Commenting input files
1039 @cindex line comment
1040 @cindex block comment
1041 A comment is a remark for the human reader of the music input, it is
1042 ignored and has no effect on the printed output. There are two types
1043 of comments. The percent symbol @code{%} introduces a line comment;
1044 the rest of the line is ignored. A block comments marks a whole
1045 section of music input, anything that is enclosed in @code{%@{} and
1046 @code{%@}} is ignored. The following fragment shows possible uses for
1050 % notes for twinkle twinkle follow
1054 This line, and the notes below
1055 are ignored, since they are in a
1065 @node Printing lyrics
1066 @section Printing lyrics
1069 @c TODO: (c) status of the Queen fragment.
1073 Lyrics are entered by separating each syllable with a space,
1076 I want to break free
1079 To prevent certain words (for example ``as'') as being read as a
1080 pitch, the input-mode must be switched. This is done with
1081 @code{\lyrics}. In @code{\lyrics} mode, all words are read as lyric
1084 \lyrics @{ I want to break free @}
1088 Again, the braces @code{@{@}} signify that the syllables are sung in
1091 By default, music expressions are interpreted in @code{Staff} context. For
1092 lyrics, this is obviously not desirable, so it is necessary
1093 to explicitly specify a @code{Lyrics} context,
1096 \new Lyrics \lyrics @{ I want to break free @}
1099 The melody for this song is as follows
1102 @lilypond[fragment,relative=2]
1104 \times 2/3 { f4 g g } \times 2/3 { g4( a2) }
1108 The lyrics can be set to these notes, combining both with the
1109 @code{\lyricsto} keyword
1111 \lyricsto "@var{name}" \new Lyrics @dots{}
1113 where @var{name} identifies to which melody the lyrics should be
1114 aligned. In this case, there is only one melody, so we can leave it
1119 @lilypond[verbatim,fragment,raggedright]
1125 \times 2/3 { f g g } \times 2/3 { g4( a2) }
1127 \lyricsto "" \new Lyrics \lyrics { I want to break free }
1134 @cindex extender line
1136 This melody ends on a @rglos{melisma}, a single syllable (``free'')
1137 sung to more than one note. This is indicated with an @emph{extender
1138 line}. It is entered as two underscores, i.e.
1140 \lyrics @{ I want to break free __ @}
1143 @lilypond[raggedright]
1146 \notes \relative c' \new Voice {
1149 \times 2/3 { f g g } \times 2/3 { g4( a2) }
1151 \lyricsto "" \new Lyrics \lyrics { I want to break free __ }
1157 Similarly, hyphens between words can be entered as two dashes,
1158 resulting in a centered hyphen between two syllables
1160 Twin -- kle twin -- kle
1163 @lilypond[raggedright]
1166 \notes \relative f' \context Voice = bla {
1170 \new Lyrics \lyrics \lyricsto "bla" { Twin -- kle twin -- kle }
1176 More options, like putting multiple lines of lyrics below a melody are
1177 discussed in @ref{Vocal music}.
1182 @section A lead sheet
1188 In popular music, it is common to denote accompaniment as chord-names.
1189 Such chords can be entered like notes,
1196 but now, each pitch is read as the root of a chord instead of a note.
1197 This mode is switched on with @code{\chords}
1200 @lilypond[verbatim,raggedright]
1202 \chords { c2 f4. g8 }
1207 Other chords can be created by adding modifiers after a colon. The
1208 following example shows a few common modifiers
1212 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1216 For lead sheets, chords are not printed on staves, but as names on a
1217 line of themselves. Hence, we have to override the context with
1218 @code{\new}, rendering the music expression in a @code{ChordNames}
1223 \new ChordNames \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1229 When put together, chord names, lyrics and a melody form
1230 a lead sheet, for example,
1235 \new ChordNames \chords @{ @emph{chords} @}
1236 \notes @emph{the melody}
1237 \lyricsto "" \new Lyrics \lyrics @{ @emph{the text} @}
1242 @lilypond[raggedright]
1246 \new ChordNames \chords { r8 c2:sus4 f }
1247 \notes \relative c' {
1249 \times 2/3 { f g g } \times 2/3 { g4( a2) }
1251 \new Lyrics \lyricsto "" \lyrics { I want to break free __ }
1258 A complete list of modifiers and other options for layout can be found
1261 @node Listening to output
1262 @section Listening to output
1267 MIDI (Musical Instrument Digital Interface) is a standard for
1268 connecting and controlling digital instruments. A MIDI file is like a
1269 tape recording of a MIDI instrument.
1271 To create a MIDI from a music piece of music, add a
1272 @code{\midi} block causes LilyPond to create a MIDI file, so you
1273 can listen to the music you entered. It is great for checking the
1274 music: octaves that are off or accidentals that were mistyped stand
1275 out very much when listening to the musical transcription.
1277 The @code{\midi} block is added to @code{\score}, for example,
1281 \midi @{ \tempo 4=72 @}
1285 Here, the tempo is specified using the @code{\tempo} command. In this
1286 case the tempo of quarter notes is set to 72 beats per minute. More
1287 information on auditory output in the notation manual, @ref{Sound}.
1289 If there is a @code{\midi} command in a @code{\score}, only MIDI will
1290 be produced. If notation is needed too, a @code{\paper} block must be
1296 \midi @{ \tempo 4=72 @}
1306 Bibliographic information is entered in a separate block, the
1307 @code{\header} block. The name of the piece, its composer, etc. are
1308 entered as an assignment, within @code{\header @{ @dots{} @}}. For
1312 title = "Eight miniatures"
1313 composer = "Igor Stravinsky"
1314 tagline = "small is beautiful"
1317 \score @{ @dots{} @}
1320 @cindex bibliographic information
1323 @cindex Engraved by LilyPond
1325 When the file is processed the title and composer are printed above
1326 the music. The `tagline' is a short line printed at bottom of the last
1327 page which normally says ``Engraved by LilyPond, version @dots{}''. In
1328 the example above it is replaced by the line ``small is
1329 beautiful.''@footnote{Nicely printed parts are good PR for us, so
1330 please leave the tagline if you can.}
1332 Normally, the @code{\header} is put at the top of the file. However,
1333 for a document that contains multiple pieces (e.g. an etude book, or
1334 an orchestral part with multiple movements), the header can be
1335 put in the @code{\score} block as follows; in this case, the name of
1336 each piece will be printed before each movement
1339 @cindex Engraved by LilyPond
1340 @cindex signature line
1345 title = "Eight miniatures"
1346 composer = "Igor Stravinsky"
1347 tagline = "small is beautiful"
1351 \header @{ piece = "Adagio" @}
1354 \header @{ piece = "Menuetto" @}
1358 More information on titling can be found in @ref{Invoking lilypond}.
1361 @node Single staff polyphony
1362 @section Single staff polyphony
1365 @cindex multiple voices
1366 @cindex voices, more -- on a staff
1368 When different melodic lines are combined on a single staff they are
1369 printed as polyphonic voices: each voice has its own stems, slurs and
1370 beams, and the top voice has the stems up, while the bottom voice has
1373 Entering such parts is done by entering each voice as a sequence (with
1374 @code{@{ .. @}}), and combining those simultaneously, separating the
1375 voices with @code{\\}
1378 @lilypond[verbatim,relative=3]
1379 << { a4 g2 f4~ f4 } \\
1384 For polyphonic music typesetting, spacer rests can also be convenient: these
1385 are rests that do not print. It is useful for filling up voices that
1386 temporarily do not play. Here is the same example with a spacer rest
1387 instead of a normal rest
1389 @lilypond[relative=3]
1390 << { a4 g2 f4~ f4 } \\
1395 Again, these expressions can be nested arbitrarily
1398 @lilypond[fragment,relative=3]
1406 { <c, g>1 ~ <c g>4 } \\
1413 More features of polyphonic typesetting in the notation manual
1417 @section Piano staves
1419 @cindex staff switch, manual
1420 @cindex cross staff voice, manual
1421 @cindex @code{\context}
1423 Piano music is typeset in two staves connected by a brace. Printing
1424 such a staff is similar to the polyphonic example in @ref{More staves}
1426 << \new Staff @{ @dots{} @}
1427 \new Staff @{ @dots{} @} >>
1429 but now this entire expression must be interpreted as a
1432 \new PianoStaff << \new Staff @dots{} >>
1435 Here is a full-fledged example
1438 @lilypond[relative=1,fragment]
1440 \new Staff { \time 2/4 c4 c g' g }
1441 \new Staff { \clef bass c,, c' e c }
1446 More information on formatting piano music is in @ref{Piano music}.
1448 @node Organizing larger pieces
1449 @section Organizing larger pieces
1451 When all of the elements discussed earlier are combined to produce
1452 larger files, the @code{\score} blocks get a lot bigger, because the
1453 music expressions are longer, and, in the case of polyphonic pieces,
1454 more deeply nested. Such large expressions can become unwieldy.
1456 By using variables, also known as identifiers, it is possible to break
1457 up complex music expressions. An identifier is assigned as follows
1460 namedMusic = \notes @{ @dots{}
1463 The contents of the music expression @code{namedMusic}, can be used
1464 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1465 In the next example, a two note motive is repeated two times by using
1466 variable substitution
1469 @lilypond[raggedright,verbatim]
1474 \new Staff { \seufzer \seufzer }
1479 The name of an identifier should have alphabetic characters only;
1480 no numbers, underscores or dashes. The assignment should be outside of
1481 the @code{\score} block.
1483 It is possible to use variables for many other types of objects in the
1488 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1490 Depending on its contents, the identifier can be used in different
1491 places. The following example uses the above variables
1494 \notes @{ c4^\name @}
1502 More information on the possible uses of identifiers is in the
1503 technical manual, in TODO.
1506 @node An orchestral part
1507 @section An orchestral part
1509 In orchestral music, all notes are printed twice: both in a part for
1510 the musicians, and in a full score for the conductor. Identifiers can
1511 be used to avoid double work: the music is entered once, and stored in
1512 a variable. The contents of that variable is then used to generate
1513 both the part and the score.
1515 It is convenient to define the notes in a special file, for example,
1516 suppose that the @file{horn-music.ly} contains the following part of a
1519 hornNotes = \notes \relative c @{
1525 Then, an individual part is made by putting the following in a file
1528 \include "horn-music.ly"
1530 instrument = "Horn in F"
1533 \notes \transpose f c' \hornNotes
1540 \include "horn-music.ly"
1544 substitutes the contents of @file{horn-music.ly} at this position in
1545 the file, so @code{hornNotes} is defined afterwards. The command
1546 @code{\transpose f c'} indicates that the argument, being
1547 @code{\hornNotes}, should be transposed by a fifth downwards: sounding
1548 @code{f} is denoted by notated @code{c'}, which corresponds with
1549 tuning of a normal French Horn in F. The transposition can be seen in
1550 the following output
1553 @lilypond[raggedright]
1555 \notes \transpose f c' \notes \relative c {
1563 In ensemble pieces, one of the voices often does not play for many
1564 measures. This is denoted by a special rest, the multi-measure
1565 rest. It is entered with a capital @code{R} followed by a duration (1
1566 for a whole note, 2 for a half note, etc.) By multiplying the
1567 duration, longer rests can be constructed. For example, this rest
1568 takes 3 measures in 2/4 time
1573 When printing the part, multi-rests
1574 must be condensed. This is done by setting a run-time variable
1576 \set Score.skipBars = ##t
1580 This commands sets the property @code{skipBars} property in the
1581 @code{Score} context to true (@code{##t}). Prepending the rest and
1582 this option to the music above, leads to the following result
1585 @lilypond[raggedright]
1587 \notes \transpose f c' \relative c {
1589 \set Score.skipBars = ##t
1598 The score is made by combining all of the music in a @code{\score}
1599 block. Assuming that the other voice is in @code{bassoonNotes} in the
1600 file @file{bassoon-music.ly}, a score is made with
1603 \include "bassoon-music.ly"
1604 \include "horn-music.ly"
1608 \new Staff \hornNotes
1609 \new Staff \bassoonNotes
1617 @lilypond[raggedright]
1619 \notes \relative c \simultaneous {
1626 r4 d,8 f | gis4 c | b bes |
1627 a8 e f4 | g d | gis f
1634 More in-depth information on preparing parts and scores in the
1635 notation manual, in @ref{Orchestral music}.
1637 Setting run-time variables (``properties'') is discussed in ref-TODO.
1639 @node Integrating text and music
1640 @section Integrating text and music
1642 @cindex La@TeX{}, music in
1643 @cindex HTML, music in
1644 @cindex Texinfo, music in
1646 Some texts include music examples. Examples are musicological
1647 treatises, songbooks or manuals like this. Such texts can be made by
1648 hand, simply by importing a PostScript figure into the word processor.
1649 However, there is an automated procedure to reduce the amount of work
1650 involved HTML, La@TeX{}, and Texinfo documents.
1652 A script called @code{lilypond-book} will extract the music fragments,
1653 run format them, and put back the resulting notation. This program is
1654 fully described in @ref{lilypond-book manual}. Here we show a small
1655 example. The example also contains explanatory text, so we will not
1656 comment on it further
1659 \documentclass[a4paper]@{article@}
1662 Documents for lilypond-book may freely mix music and text. For
1666 \score @{ \notes \relative c' @{
1667 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1671 If there is no \verb+\score+ block in the fragment,
1672 \texttt@{lilypond-book@} will supply one
1678 In this example two things happened: a
1679 \verb+\score+ block was added, and the line width was set to natural
1682 Options are put in brackets.
1684 \begin[staffsize=26,verbatim]@{lilypond@}
1689 Larger examples can be put in a separate file, and introduced with
1690 \verb+\lilypondfile+.
1692 \lilypondfile@{screech-boink.ly@}
1697 Under Unix, you can view the results as follows
1701 $ lilypond-book --output=out/ lilybook.tex
1702 lilypond-book (GNU LilyPond) 2.1.19
1703 Reading `input/tutorial/lilybook.tex'
1704 Reading `input/screech-boink.ly'
1705 @var{lots of stuff deleted}
1706 Writing `out/lilybook.tex'
1709 @var{lots of stuff deleted}
1713 To convert the file into a nice PDF document, run the following
1716 $ dvips -Ppdf -u +lilypond lilybook
1717 $ ps2pdf lilybook.ps
1721 Running lilypond-book and running latex creates a lot of temporary
1722 files, which would clutter up the working directory. To remedy this,
1723 use the @code{output} option. It will create the files in a separate
1724 subdirectory @file{out}.
1726 The result looks more or less like
1730 Documents for lilypond-book may freely mix music and text. For
1734 @lilypond[raggedright]
1736 \notes \relative c' {
1737 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1743 If you have no @code{\score} block in the fragment,
1744 @code{lilypond-book} will supply one
1752 In this example two things happened: a
1753 @code{score} block was added, and the line width was set to natural
1756 Options are put in brackets.
1759 @lilypond[staffsize=26,verbatim]
1764 Larger examples can be put in a separate file, and introduced with
1765 @code{\lilypondfile}.
1768 @lilypondfile{screech-boink.ly}