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?
14 Using LilyPond comes down to encoding music in an input file. After
15 entering the music, the program is run on the file producing output
16 which can be viewed or printed. In this tutorial, we will show step
17 by step how to enter such files, and illustrate the process with
18 fragments of input and the corresponding output. At the end of every
19 section, a paragraph will list where to find further information on
22 Many people learn programs by trying and fiddling around with the
23 program. This is also possible with LilyPond. If you click on a
24 picture in the HTML version of this manual, you will see the exact
25 LilyPond input that was used to generate that image.
27 For example, consider the following input:
29 c'^\markup @{ \bold \huge @{ Click on this image! @} @}
31 @c @lily pond[relative=1,raggedright,with the following output:]
32 with the following output:
33 @lilypond[relative=1,raggedright]
34 c'^\markup { \bold \huge { Click on this image! } }
38 By cutting and pasting the full input into a test file, you have a
39 starting template for experiments. If you like learning in this way,
40 you will probably want to print out or bookmark
44 @ref{Cheat sheet}, which is a table listing all commands for quick
48 This tutorial starts with a short introduction to the LilyPond music
49 language. After this first contact, we will show you how to to
50 produce printed output. You should then be able to create and print
51 your first sheets of music.
56 * More about pitches::
58 * Combining music into compound expressions::
59 * Adding articulation marks to notes::
60 * Combining notes into chords::
61 * Basic rhythmical commands::
62 * Commenting input files::
65 * Listening to output::
67 * Single staff polyphony::
69 * Organizing larger pieces::
70 * An orchestral part::
71 * Integrating text and music::
78 We start off by showing how very simple music is entered in LilyPond:
79 you get a note simply by typing its note name, from @samp{a}
80 through @samp{g}. So if you enter
87 then the result looks like this:
89 @lilypond[notime,relative]
93 The length of a note is specified by adding a number, @samp{1} for a
94 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
101 \set Score.timing = ##f
102 \set Staff.autoBeaming = ##f
103 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
106 If you do not specify a @rglos{duration}, the previous one is used:
113 \set Score.timing = ##f
114 \transpose c c' { a a a2 a s16_" " }
118 Rests are entered just like notes, but with the name ``@code{r}'':
127 \set Score.timing = ##f
128 \set Staff.Clef = \turnOff
129 \set Staff.TimeSignature = \turnOff
137 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
144 \set Score.timing = ##f
145 \transpose c c' { a2. a4 a8. a16 s16_" " }
149 The @rglos{meter} (or @rglos{time signature}) can be set with the
150 @code{\time} command:
158 @c a clef here may lead to confusion
160 \override Staff.Clef #'transparent = ##t
170 The @rglos{clef} can be set using the @code{\clef} command:
172 @c what is more common name treble or violin?
173 @c in Dutch, it's violin.
174 @c in English it's definitely treble.
183 \set Score.timing = ##f
194 Notes and commands like @code{\clef} and @code{\time}, are enclosed
195 in @code{\notes @{@dots{}@}}. This indicates that music (as opposed
196 to @rglos{lyrics}) follows:
206 Now the piece of music is almost ready to be printed. Enclosing the
207 music in a @code{\score} processes them to printed output,
208 so the following is a complete and valid input file:
230 linewidth = 55 * \staffspace
235 In many examples in this manual, @code{\score} is left out for
236 clarity. However, it must be present when feeding the file to
239 For more elaborate information on
242 @item entering pitches and durations
244 @ref{Pitches} and @ref{Durations}.
247 @item Time signatures and other timing commands
248 see @ref{Time signature}.
251 @node Running LilyPond
252 @section Running LilyPond
254 In the last section we explained what kind of things you could enter
255 in a LilyPond file. In this section we will explain what commands to run
256 and how to view or print the output. If you have not used LilyPond
257 before, want to test your setup, or want to run an example file
258 yourself, read this section. The instructions that follow are for
259 Unix-like systems. Some additional instructions for Microsoft Windows
260 are given at the end of this section.
262 Begin by opening a terminal window and starting a text editor. For
263 example, you could open an xterm and execute
264 @code{joe}.@footnote{There are macro files for VIM addicts, and there
265 is a @code{LilyPond-mode} for Emacs addicts. If it has not been
266 installed already, then refer to the file @file{INSTALL.txt}}. In
267 your text editor, enter the following input and save the file as
273 \notes @{ c'4 e' g' @}
278 To process @file{test.ly}, proceed as follows:
286 You will see something resembling:
291 Now processing: `/home/fred/ly/test.ly'
293 Interpreting music...[1]
294 @emph{ ... more interesting stuff ... }
295 PDF output to `test.pdf'...
296 DVI output to `test.dvi'...
300 @cindex Viewing music
303 The result is the file @file{test.pdf}.@footnote{For @TeX{}
304 afficionados: there is also a @file{test.dvi} file. It can be viewed
305 with @code{xdvi}. The DVI uses a lot of PostScript specials, which do
306 not show up in the magnifying glass. The specials also mean that the
307 DVI file cannot be processed with @code{dvilj}. Use @code{dvips} for
312 } One of the following commands should put the PDF on your
328 If the music on your screen looks good, you can print it by clicking
329 File/Print inside your viewing program.
333 @cindex Printing output
338 On Windows, the same procedure should work. The terminal is started by
339 clicking on the LilyPond or Cygwin icon. Any text editor (such as
340 Notepad, Emacs or Vim) may be used to edit the LilyPond file.
342 To view the PDF file, try the following:
345 If your system has a PDF viewer installed, open
346 @file{C:\Cygwin\home\@var{your-name}} in the explorer and double-click
349 If you prefer the keyboard, you can try to enter one of the commands
350 from the list shown before in the terminal. If none work, go to
351 @uref{http://www.cs.wisc.edu/~ghost/} to install the proper software.
354 The commands for formatting and printing music on all platforms are
355 detailed in @ref{Invoking LilyPond}.
357 @node More about pitches
358 @section More about pitches
360 A @rglos{sharp} (@texisharp{}) pitch is made by adding @samp{is} to
361 the name, a @rglos{flat} (@texiflat{}) pitch by adding @samp{es}. As
362 you might expect, a @rglos{double sharp} or @rglos{double flat} is
363 made by adding @samp{isis} or @samp{eses}:@footnote{This syntax
364 derived from note naming conventions in Nordic and Germanic languages,
365 like German and Dutch.}
372 \set Score.timing = ##f
373 \transpose c c' { cis1 ees fisis aeses s16_" " }
377 @cindex key signature, setting
379 The key signature is set with the command ``@code{\key}'', followed by
380 a pitch and @code{\major} or @code{\minor}:
390 \set Staff.TimeSignature = \turnOff
399 Key signatures together with the pitches (including alterations) are
400 used together to determine when to print accidentals. This is a
401 feature that often causes confusion to newcomers, so let us explain it
405 LilyPond makes a sharp distinction between musical content and
406 layout. The alteration (flat, natural or sharp) of a note is part of
407 the pitch, and is therefore musical content. Whether an accidental (a
408 flat, natural or sharp @emph{sign}) is a printed in front of the
409 corresponding note is a question of layout. Layout is something that
410 follows rules, so accidentals are printed automatically according to
411 those rules. The pitches in your music are works of art, so they will
412 not be added automatically, and you must enter what you want to hear.
414 For example, in this example:
416 \set Staff.TimeSignature = \turnOff
422 no note gets an explicit accidental, but still you enter
429 The code @code{d} does not mean ``print a black dot just below the
430 staff.'' Rather, it means: ``a note with pitch D-natural.'' In the key
431 of A-flat, it gets an accidental:
434 \set Staff.TimeSignature = \turnOff
445 Adding all alterations explicitly might require some more effort when
446 typing, but the advantage is that transposing is easier, and music can
447 be printed according to different conventions. See @ref{Accidentals}
448 for some examples how accidentals can be printed according to
453 A tie is created by adding a tilde ``@code{~}'' to the first note
456 @lilypond[fragment,verbatim,relative=2]
462 This example shows the key signature, accidentals and ties in action:
473 fis4 fis8 fis8 eis4 a8 gis~
481 \notes { \transpose c c' {
487 fis4 fis8 fis8 eis4 a8 gis~
490 \paper { linewidth = #(* 50 staffspace) }
496 There are some interesting points to note in this example. Bar lines
497 and beams are drawn automatically. Line breaks are calculated
498 automatically; it does not matter where the line breaks are in the
499 source file. Finally, the order in which time, key and clef changes are entered is not
500 relevant: in the printout, these are ordered according to standard
501 notation conventions.
504 @cindex beams, by hand
505 Beams are drawn automatically, but if you do not like where they are
506 put, they can be entered by hand. Mark the first note to be beamed
507 with @code{[} and the last one with @code{]}:
509 @lilypond[fragment,relative=1,verbatim]
515 For more information on
524 see @ref{Accidentals}
527 see @ref{Key signature}
535 @section Octave entry
538 @c Tim wants to move this quotes example just before the: quotes-do not-work
539 @c score, but we'd need to remove quotes from the other two (key and
542 @c better to have this just before the `octaves are bad' snipped
543 @c but we'd need to remove the ', from \key and tie
544 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
545 the note name, to lower a note one octave, add a ``low quote'' @code{,}
546 (a comma). Middle C is @code{c'}:
550 c'4 c'' c''' \clef bass c c,
554 \set Score.timing = ##f
555 \set Staff.TimeSignature = \turnOff
556 c'4 c'' c''' \clef bass c c,
561 An example of the use of quotes is in the following Mozart fragment:
562 @lilypond[raggedright,fragment,verbatim]
565 cis''8. d''16 cis''8 e''4 e''8
566 b'8. cis''16 b'8 d''4 d''8
569 This example shows that music in a high register needs lots of quotes.
570 This makes the input less readable, and it is a source of errors. The
571 solution is to use ``relative octave'' mode. In practice, this is the
572 most convenient way to copy existing music. To use relative mode, add
573 @code{\relative} before the piece of music. You must also give a note
574 from which relative starts, in this case @code{c''}. If you do not
575 use octavation quotes (i.e. do not add @code{'} or @code{,} after a
576 note), relative mode chooses the note that is closest to the previous
577 one. For example, @code{c f} goes up while @code{c g} goes down:
587 \set Score.timing = ##f
588 \set Staff.TimeSignature = \turnOff
597 Since most music has small intervals, pieces can be written almost
598 without octavation quotes in relative mode. The previous example is
601 @lilypond[raggedright,fragment,verbatim]
611 @c needed better, maybe even redundant explanation
612 @c added another example below.
613 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
614 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
615 Larger intervals are made by adding octavation quotes.
624 \set Score.timing = ##f
625 \set Staff.TimeSignature = \turnOff
633 Quotes or commas do not determine the absolute height of a note; the
634 height of a note is relative to the previous one.
635 @c do not use commas or quotes in this sentence
636 For example: @code{c f,} goes down; @code{f, f} are both the same;
637 @code{c' c} are the same; and @code{c g'} goes up:
641 Here is an example of the difference between relative mode and
642 ``normal'' (non-relative) mode:
653 \set Score.timing = ##f
654 \set Staff.TimeSignature = \turnOff
670 \set Score.timing = ##f
671 \set Staff.TimeSignature = \turnOff
679 For more information on Relative octaves see @ref{Relative octaves}
680 and @ref{Octave check}.
687 @node Combining music into compound expressions
688 @section Combining music into compound expressions
690 To print more than one staff, each piece of music that makes up a
691 staff is marked by adding @code{\context Staff} before it. These
692 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and
693 @code{@}}, as is demonstrated here:
696 @lilypond[fragment,verbatim]
698 \new Staff { \clef violin c'' }
699 \new Staff { \clef bass c }
705 In this example, @code{\simultaneous } indicates that both music
706 fragments happen at the same time, and must be printed stacked
707 vertically. The notation @code{<< .. >>} can also be used as a
708 shorthand for @code{\simultaneous @{ .. @}}.
710 The command @code{\new} introduces a ``notation context''. To
711 understand this concept, imagine that you are performing a piece of
712 music. When you are playing, you combine the symbols printed at a
713 certain point with contextual information. For example, without
714 knowing the current clef, and the accidentals in the last measure, it
715 would be impossible to determine the pitch of a note. In other words,
716 this information forms a context that helps you decipher a
717 score. LilyPond produces notation from music, so in effect, it does
718 the inverse of reading scores. Therefore, it also needs to keep track
719 of contextual information. This information is maintained in
720 ``notation contexts.'' There are several types of contexts,
721 e.g. @code{Staff}, @code{Voice} and @code{Score}, but also
722 @code{Lyrics} and @code{ChordNames}. Prepending @code{\new} to a chunk
723 of music indicates what kind of context to use for interpreting it,
724 and ensures that the argument is interpreted with a fresh instance of
725 the context indicated.
730 We can now typeset a melody with two staves:
733 @lilypond[verbatim,raggedright]
753 The example shows how small chunks of music, for example, the notes
754 @code{c2}, @code{e4}, etc. of the second staff, are combined to form a
755 larger chunk by enclosing it in braces. Again, a larger chunk is
756 formed by prefix @code{\new Staff} to it, and that chunk is combined
757 with @code{<< >>}. This mechanism is similar to mathematical
758 formulas: a big formula is created by composing small formulas. Such
759 formulas are called expressions, and their definition is recursive, so
760 you can make arbitrarily complex and large expressions. For example,
769 ((1 + 2) * 3) / (4 * 5)
772 @cindex music expression
773 This example shows a sequence of expressions, where each expression is
774 contained in the next one. The simplest expressions are numbers and
775 operators (like +, * and /). Parentheses are used to group
776 expressions. In LilyPond input, a similar mechanism is used. Here,
777 the simplest expressions are notes and rests. By enclosing
778 expressions in @code{<< >>} and @code{@{ @}}, more complex music is
779 formed. The @code{\new} command also forms new expressions; prepending
780 it to a music expression yields a new expression.
782 Like mathematical expressions, music expressions can be nested
783 arbitrarily deep, e.g.
784 @lilypond[verbatim,relative=1]
786 << { e f } { c <<b d>> }
793 When spreading expressions over multiple lines, it is customary to use
794 an indent that indicates the nesting level. Formatting music like this
795 eases reading, and helps you insert the right number of closing
796 braces at the end of an expression. For example,
811 For more information on context see the Technical manual description
812 in @ref{Interpretation context}.
816 @node Adding articulation marks to notes
817 @section Adding articulation marks to notes
823 Common accents can be added to a note using a dash (`@code{-}') and a
826 @lilypond[verbatim,relative=1]
827 c-. c-- c-> c-^ c-+ c-_
833 Similarly, fingering indications can be added to a note using a dash
834 (`@code{-}') and the digit to be printed:
836 @lilypond[verbatim,relative=1]
841 Dynamic signs are made by adding the markings to the note:
843 @lilypond[verbatim,relative=1]
853 Crescendi and decrescendi are started with the commands @code{\<} and
854 @code{\>}. The command @code{\!} finishes a crescendo on the note it
857 @lilypond[verbatim,relative=1]
858 c2\< c2\!\ff\> c2 c2\!
867 A slur is drawn across many notes, and indicates bound articulation
868 (legato). The starting note and ending note are marked with a
869 ``@code{(}'' and a ``@code{)}'' respectively:
872 @lilypond[fragment,relative=1,verbatim]
873 d4( c16)( cis d e c cis d e)( d4)
877 @cindex slurs versus ties
878 A slur looks like a tie, but it has a different meaning. A tie simply
879 makes the first note sound longer, and can only be used on pairs of
880 notes with the same pitch. Slurs indicate the articulations of notes,
881 and can be used on larger groups of notes. Slurs and ties are also
884 @lilypond[fragment,relative=1]
885 c2~( c8 fis fis4 ~ fis2 g2)
888 @cindex phrasing slurs
889 If you need two slurs at the same time (one for articulation, one for
890 phrasing), you can also make a phrasing slur with @code{\(} and
894 @lilypond[fragment,relative=1,verbatim]
895 a8(\( ais b c) cis2 b'2 a4 cis, c\)
900 For more information on
903 see @ref{Fingering instructions}
905 see @ref{Articulations}
909 see @ref{Phrasing slurs}
915 @node Combining notes into chords
916 @section Combining notes into chords
919 Chords can be made by
920 surrounding pitches with @code{<} and @code{>}:
922 @lilypond[relative,fragment,verbatim]
929 You can combine beams and ties with chords. Beam and tie markings
930 must be placed outside the chord markers:
932 @lilypond[relative,fragment,verbatim]
933 r4 <c e g>8[ <c f a>]~ <c f a>
939 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
941 @lilypond[relative,fragment]
943 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
951 @node Basic rhythmical commands
952 @section Basic rhythmical commands
957 @cindex partial measure
958 A pickup (or upstep) is entered with the keyword @code{\partial}. It
959 is followed by a duration: @code{\partial 4} is a quarter note upstep
960 and @code{\partial 8} an eighth note:
961 @lilypond[relative=1,verbatim,fragment]
968 Tuplets are made with the @code{\times} keyword. It takes two
969 arguments: a fraction and a piece of music. The duration of the piece
970 of music is multiplied by the fraction. Triplets make notes occupy
971 2/3 of their notated duration, so a triplet has 2/3 as its fraction:
973 @lilypond[relative,verbatim,fragment]
974 \times 2/3 { f8 g a }
980 Grace notes are also made by prefixing a note, or a set of notes with
981 a keyword. In this case, the keywords are @code{\appoggiatura}
982 and @code{\acciaccatura}
986 @lilypond[relative=1,verbatim,fragment]
987 c4 \appoggiatura b16 c4
988 c4 \acciaccatura b16 c4
993 For more information on
996 see @ref{Grace notes},
1000 see @ref{Partial measures}.
1005 @node Commenting input files
1006 @section Commenting input files
1009 @cindex line comment
1010 @cindex block comment
1011 Comments are pieces of the input that are ignored. There are two
1012 types of comments. A line comment is introduced by @code{%}: after
1013 that, the rest of that line is ignored. Block comments span larger
1014 sections of input. Anything that is enclosed in @code{%@{} and
1015 @code{%@}} is ignored too. The following fragment shows possible uses
1019 % notes for twinkle twinkle follow:
1024 This line, and the notes below
1025 are ignored, since they are in a
1035 @node Printing lyrics
1036 @section Printing lyrics
1041 Lyrics are entered by separating each syllable with a space, and
1042 surrounding them with @code{\lyrics @{ @dots{} @}}, for example,
1044 \lyrics @{ I want to break free @}
1047 Like notes, lyrics are also a form of music, but they must not be
1048 printed on a staff, which is the default way to print music. To print
1049 them as lyrics, they must be marked with @code{ \new Lyrics}:
1051 \new Lyrics \lyrics @{ I want to break free @}
1053 The melody for this song is as follows:
1055 @lilypond[fragment,relative=1]
1058 \times 2/3 { f4 g g } \times 2/3 { g4( a2) }
1061 The lyrics can be set to these notes, combining both with the
1062 @code{\lyricsto} keyword:
1064 \lyricsto "@var{name}" \new Lyrics @dots{}
1066 where @var{name} identifies to which melody the lyrics should be
1067 aligned. In this case, there is only one melody, so we can leave it
1071 @lilypond[verbatim,fragment]
1074 \relative c' \new Voice {
1077 \times 2/3 { f g g } \times 2/3 { g4( a2) }
1079 \lyricsto "" \new Lyrics \lyrics { I want to break free }
1085 @cindex extender line
1087 This melody ends on a @rglos{melisma}, a single syllable (``free'')
1088 sung to more than one note. This is indicated with an @emph{extender
1089 line}. It is entered as two underscores, i.e.
1091 \lyrics @{ I want to break free __ @}
1093 @lilypond[raggedright]
1096 \relative c' \new Voice {
1099 \times 2/3 { f g g } \times 2/3 { g4( a2) } }
1100 \lyricsto "" \new Lyrics \lyrics { I want to break free __ }
1105 Similarly, hyphens between words can be entered as two dashes,
1106 resulting in a centered hyphen between two syllables:
1108 Twin -- kle twin -- kle
1110 @lilypond[raggedright]
1112 << \notes \relative f' { \time 2/4
1114 \new Lyrics \lyrics { Twin -- kle twin -- kle }
1116 \paper { raggedright = ##t }
1120 More options, like putting multiple lines of lyrics below a melody are
1121 discussed in @ref{Vocal music}.
1126 @section A lead sheet
1132 In popular music, it is common to denote accompaniment as chord-names.
1133 Using them in LilyPond has two parts, just like lyrics: entering the
1134 chords (with @code{\chords}), and printing them (with @code{\new
1137 Chord names are entered by starting chords mode (with @code{\chords}).
1138 In chords mode, you can enter chords with a letter (indicating the
1139 root of the chord), and a durations following that:
1142 \chords { c2 f4. g8 }
1146 The result of @code{\chords} is a list of chords, and is equivalent
1147 to entering chords with @code{<@dots{}>}.
1149 Other chords can be created by adding modifiers after a colon. The
1150 following example shows a few common modifiers:
1153 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1156 Printing chords is done by adding @code{\context ChordNames}
1157 before the chords thus entered:
1160 \context ChordNames \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1165 When put together, chord names, lyrics and a melody form
1166 a lead sheet, for example,
1171 \context ChordNames \chords @{ @emph{chords} @}
1172 \notes @emph{the melody}
1173 \lyricsto "" \new Lyrics \lyrics @{ @emph{the text} @}
1180 \context ChordNames \chords { r8 c2:sus4 f }
1181 \notes \relative c' {
1184 \times 2/3 { f g g } \times 2/3 { g4( a2) } }
1185 \new Lyrics \lyricsto "" \lyrics { I want to break free __ }
1187 \paper{ raggedright = ##t }
1192 A complete list of modifiers and other options for layout are in the
1193 reference manual section @ref{Chords}.
1195 @node Listening to output
1196 @section Listening to output
1201 MIDI (Musical Instrument Digital Interface) is a standard for
1202 connecting and recording digital instruments. A MIDI file is like a
1203 tape recording of a MIDI instrument. The @code{\midi} block causes LilyPond
1204 to create a MIDI file, so you can listen to the music you entered.
1205 It is great for checking the music: octaves that are off or
1206 accidentals that were mistyped stand out very much when listening to
1207 the musical transcription.
1209 The @code{\midi} block is added to @code{\score}, for example,
1213 \midi @{ \tempo 4=72 @}
1217 Here, the tempo is specified using the @code{\tempo} command. In this
1218 case the tempo of quarter notes is set to 72 beats per minute. More
1219 information on auditory output is in the @ref{Sound} section in the
1222 If there is a @code{\midi} command in a @code{\score}, then only MIDI
1223 will be produced. If notation is needed too, then a @code{\paper}
1224 block must be added too:
1229 \midi @{ \tempo 4=72 @}
1239 Bibliographic information is entered in a separate block, the
1240 @code{\header} block. The name of the piece, its composer, etc. are
1241 entered as an assignment, within @code{\header @{ @dots{} @}}. For
1245 title = "Eight miniatures"
1246 composer = "Igor Stravinsky"
1247 tagline = "small is beautiful"
1250 \score @{ @dots{} @}
1253 @cindex bibliographic information
1256 @cindex Engraved by LilyPond
1258 When the file is processed by the @code{lilypond} wrapper script
1259 the title and composer specified are printed above the music. The
1260 `tagline' is a short line printed at bottom of the last page which
1261 normally says ``Engraved by LilyPond, version @dots{}''. In the
1262 example above it is replaced by the line ``small is
1263 beautiful.''@footnote{Nicely printed parts are good PR for us, so do
1264 us a favor, and leave the tagline if you can.}
1266 Normally, the @code{\header} is put at the top of the file. However,
1267 for a document that contains multiple pieces (e.g. an etude book, or
1268 an orchestral part with multiple movements), the header can be
1269 put in the @code{\score} block as follows; in this case, the name of
1270 each piece will be printed before each movement:
1273 @cindex Engraved by LilyPond
1274 @cindex signature line
1279 title = "Eight miniatures"
1280 composer = "Igor Stravinsky"
1281 tagline = "small is beautiful"
1285 \header @{ piece = "Adagio" @}
1288 \header @{ piece = "Menuetto" @}
1292 More information on titling can be found in @ref{Invoking lilypond}.
1295 @node Single staff polyphony
1296 @section Single staff polyphony
1299 @cindex multiple voices
1300 @cindex voices, more -- on a staff
1302 When different melodic lines are combined on a single staff they are
1303 printed as polyphonic voices: each voice has its own stems, slurs and
1304 beams, and the top voice has the stems up, while the bottom voice has
1307 Entering such parts is done by entering each voice as a sequence (with
1308 @code{@{ .. @}}), and combining those simultaneously, separating the
1309 voices with @code{\\}:
1312 << @{ a4 g2 f4~ f4 @} \\
1313 @{ r4 g4 f2 f4 @} >>
1315 @lilypond[relative=1]
1316 \context Staff << { a4 g2 f4~ f4 } \\
1320 For polyphonic music typesetting, spacer rests can also be convenient: these
1321 are rests that do not print. It is useful for filling up voices that
1322 temporarily do not play:
1324 << @{ a4 g2 f4~ f4 @} \\
1325 @{ s4 g4 f2 f4 @} >>
1327 @lilypond[relative=1]
1328 \context Staff << { a4 g2 f4~ f4 } \\
1332 Again, these expressions can be nested arbitrarily:
1338 << { a4 g2 f4~ f4 } \\
1341 << { \clef bass <c g>1 ~ <c g>4 } \\
1348 More features of polyphonic typesetting are in the notation manual
1352 @section Piano staves
1354 @cindex staff switch, manual
1355 @cindex cross staff voice, manual
1356 @cindex @code{\translator}
1358 Piano music is always typeset in two staves connected by a brace.
1359 Printing such a staff is similar to the polyphonic example in
1360 @ref{Combining music into compound expressions}:
1362 << \new Staff @{ @dots{} @}
1363 \new Staff @{ @dots{} @}
1366 but now this entire expression must be interpreted as a
1369 \new PianoStaff << \new Staff @dots{} >>
1372 Here is a full-fledged example:
1374 @lilypond[relative,fragment]
1376 << \new Staff { \time 2/4
1379 \clef bass c,, c' e c }
1383 More information on formatting piano music is in @ref{Piano music}.
1385 @node Organizing larger pieces
1386 @section Organizing larger pieces
1388 When all of the elements discussed earlier are combined to produce
1389 larger files, the @code{\score} blocks get a lot bigger, because the
1390 music expressions are longer, and, in the case of polyphonic and/or
1391 orchestral pieces, more deeply nested. Such large expressions can
1394 By using variables, also known as identifiers, it is possible to break
1395 up complex music expressions. An identifier is assigned as follows:
1398 namedMusic = \notes @{ @dots{}
1401 The contents of the music expression @code{namedMusic}, can be used
1402 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1403 In the next example, a two note motive is repeated two times by using
1404 variable substitution:
1406 @lilypond[raggedright,verbatim]
1415 The name of an identifier should have alphabetic characters only;
1416 no numbers, underscores or dashes. The assignment should be outside of
1417 the @code{\score} block.
1419 It is possible to use variables for many other types of objects in the
1424 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1426 Depending on its contents, the identifier can be used in different
1427 places. The following example uses the above variables:
1430 \notes @{ c4^\name @}
1438 More information on the possible uses of identifiers is in the
1439 technical manual, in TODO.
1442 @node An orchestral part
1443 @section An orchestral part
1445 In orchestral music, all notes are printed twice: both in a part for
1446 the musicians, and in a full score for the conductor. Identifiers can
1447 be used to avoid double work: the music is entered once, and stored in
1448 a variable. The contents of that variable is then used to generate
1449 both the part and the score.
1451 It is convenient to define the notes in a special file, for example,
1452 suppose that the @file{horn-music.ly} contains the following part of a
1455 hornNotes = \notes \relative c @{
1461 Then, an individual part is made by putting the following in a file:
1463 \include "horn-music.lyinc"
1465 instrument = "Horn in F"
1468 \notes \transpose f c' \hornNotes
1471 The @code{\include} command substitutes the contents of the file at
1472 this position in the file, so that @code{hornNotes} is defined
1473 afterwards. The code @code{\transpose f c'} indicates that the
1474 argument, being @code{\hornNotes}, should be transposed by a fifth
1475 downwards: sounding @code{f} is denoted by notated @code{c'}, which
1476 corresponds with tuning of a normal French Horn in F. The
1477 transposition can be seen in the following output:
1479 @lilypond[raggedright]
1481 \notes \transpose f c' \notes \relative c {
1488 In ensemble pieces, one of the voices often does not play for many
1489 measures. This is denoted by a special rest, the multi-measure
1490 rest. It is entered with a capital R followed by a duration (1
1491 for a whole note, 2 for a half note, etc.) By multiplying the
1492 duration, longer rests can be constructed. For example, this rest
1493 takes 3 measures in 2/4 time:
1498 When printing the part, the following @code{skipBars} property must be
1499 set to true, to prevent the rest from being expanded to three one bar
1502 \set Score.skipBars = ##t
1504 Prepending the rest and the property setting above, leads to the
1507 @lilypond[raggedright]
1508 \score {\notes { \transpose f c' \relative c { \time 2/4
1509 \set Score.skipBars = ##t
1511 r4 f8 a cis4 f e d } }}
1514 The score is made by combining all of the music in a @code{\score}
1515 block, assuming that the other voice is in @code{bassoonNotes}, in the
1516 file @file{bassoon-music.ly}:
1518 \include "bassoon-music.lyinc"
1519 \include "horn-music.lyinc"
1523 \new Staff \hornNotes
1524 \new Staff \bassoonNotes
1528 This would lead to the simple score depicted below:
1530 @lilypond[raggedright]
1532 \notes \relative c \simultaneous {
1533 \new Staff { \time 2/4
1535 r4 f8 a cis4 f e d }
1536 \new Staff { \clef bass
1537 r4 d,8 f | gis4 c | b bes |
1538 a8 e f4 | g d | gis f }
1542 More in-depth information on preparing parts and scores is in the
1543 notation manual, in @ref{Orchestral music}.
1546 @node Integrating text and music
1547 @section Integrating text and music
1549 @cindex La@TeX{}, music in
1550 @cindex HTML, music in
1551 @cindex Texinfo, music in
1553 Sometimes you might want to use music examples in a text that you are
1554 writing (for example, a musicological treatise, a songbook, or (like us)
1555 the LilyPond manual). You can make such texts by hand, simply by
1556 importing a PostScript figure into your word processor. However,
1557 there is an automated procedure to reduce the amount of work.
1559 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1560 code. A script called @code{lilypond-book} will extract the music
1561 fragments, run LilyPond on them, and put back the resulting notation.
1562 This program is fully described in @ref{lilypond-book manual}. Here
1563 we show a small example. The example also contains explanatory text,
1564 so we will not comment on it further:
1567 \documentclass[a4paper]@{article@}
1570 In a lilypond-book document, you can freely mix music and text. For
1573 \score @{ \notes \relative c' @{
1574 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1578 If you have no \verb+\score+ block in the fragment,
1579 \texttt@{lilypond-book@} will supply one:
1585 In the example you see here two things happened: a
1586 \verb+\score+ block was added, and the line width was set to natural
1587 length. You can specify options by putting them in brackets:
1589 \begin[staffsize=26,verbatim]@{lilypond@}
1593 If you want to include large examples in the text it is more
1594 convenient to put it in a separate file:
1596 \lilypondfile@{screech-boink.ly@}
1601 Under Unix, you can view the results as follows:
1605 $ lilypond-book --output=out/ lilybook.tex
1606 lilypond-book (GNU LilyPond) 2.1.19
1607 Reading `input/tutorial/lilybook.tex'
1608 Reading `input/screech-boink.ly'
1609 @var{lots of stuff deleted}
1610 Writing `out/lilybook.latex'
1612 $ latex lilybook.latex
1613 @var{lots of stuff deleted}
1617 To convert the file into a nice PDF document, run the following
1620 $ dvips -Ppdf -u +lilypond lilybook
1621 $ ps2pdf lilybook.ps
1625 Running lilypond-book and running latex creates a lot of temporary
1626 files. You would not want those to clutter up your working
1627 directory. The @code{outdir} option to lilypond-book creates the
1628 temporary files in a separate subdirectory @file{out}.
1630 The result looks more or less like this:
1634 In a lilypond-book document, you can freely mix music and text. For
1638 \notes \relative c' {
1639 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1647 If you have no @code{\score} block in the fragment,
1648 @code{lilypond-book} will supply one:
1654 In the example you see here, two things happened: a
1655 @code{score} block was added, and the line width was set to natural
1656 length. You can specify options by putting them in brackets:
1658 @lilypond[staffsize=26,verbatim]
1662 If you want to include large examples in the text, it is more
1663 convenient to put it in a separate file:
1665 @lilypondfile{screech-boink.ly}