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 * Automatic and manual beams::
60 * Music expressions explained::
62 * Adding articulation marks to notes::
63 * Combining notes into chords::
64 * Basic rhythmical commands::
65 * Commenting input files::
68 * Listening to output::
70 * Single staff polyphony::
72 * Organizing larger pieces::
73 * An orchestral part::
74 * Integrating text and music::
81 We start off by showing how very simple music is entered in LilyPond.
82 A note is entered by typing its name, from @samp{a} through @samp{g},
83 and a number. So, if you enter
90 then the result looks like this:
92 @lilypond[notime,relative]
96 The number specifies the length of the note, @samp{1} for a
97 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
104 \set Score.timing = ##f
105 \set Staff.autoBeaming = ##f
106 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
109 If you do not specify a @rglos{duration}, the the first note is a
110 quarter, and for others, the last entered duration is used.
117 \set Score.timing = ##f
118 \transpose c c' { a a a2 a s16_" " }
122 Rests are entered just like notes, but with the name ``@code{r}'':
131 \set Score.timing = ##f
132 \set Staff.Clef = \turnOff
133 \set Staff.TimeSignature = \turnOff
141 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
148 \set Score.timing = ##f
149 \transpose c c' { a2. a4 a8. a16 s16_" " }
153 The @rglos{meter} (or @rglos{time signature}) can be set with the
154 @code{\time} command:
162 @c a clef here may lead to confusion
164 \override Staff.Clef #'transparent = ##t
174 The @rglos{clef} can be set using the @code{\clef} command:
176 @c what is more common name treble or violin?
177 @c in Dutch, it's violin.
178 @c in English it's definitely treble.
187 \set Score.timing = ##f
198 To recognize names like @code{c} and @code{d} as pitches, they have to
199 be entered inside a so-called @code{\notes} block. This block is
200 formed by enclosing notes and commands are enclosed in curly braces,
210 and adding the keyword @code{\notes} before the opening brace
211 @code{@{}, for example,
222 Now the piece of music is almost ready to be printed. When this
223 enclosed a @code{\score} block, i.e. braces @code{@{ @dots{} @}} with
224 keyword @code{\score} in front, like
237 then the music will be converted to printable output:
248 linewidth = 55 * \staffspace
253 In many examples in this manual, both @code{\score} and @code{\notes}
254 and accompanying braces are left out for brevity. However, they must
255 be present when feeding the file to LilyPond.
257 For more elaborate information on
260 @item Entering pitches and durations
262 @ref{Pitches} and @ref{Durations}.
267 @item Time signatures and other timing commands
268 see @ref{Time signature}.
271 @node Running LilyPond
272 @section Running LilyPond
274 In the last section we explained what kind of things you could enter
275 in a LilyPond file. In this section we will explain what commands to run
276 and how to view or print the output. If you have not used LilyPond
277 before, want to test your setup, or want to run an example file
278 yourself, read this section. The instructions that follow are for
279 Unix-like systems. Some additional instructions for Microsoft Windows
280 are given at the end of this section.
282 Begin by opening a terminal window and starting a text editor. For
283 example, you could open an xterm and execute
284 @code{joe}.@footnote{There are macro files for VIM addicts, and there
285 is a @code{LilyPond-mode} for Emacs addicts. If it has not been
286 installed already, then refer to the file @file{INSTALL.txt}}. In
287 your text editor, enter the following input and save the file as
293 \notes @{ c'4 e' g' @}
298 To process @file{test.ly}, proceed as follows:
306 You will see something resembling:
311 Now processing: `/home/fred/ly/test.ly'
313 Interpreting music...[1]
314 @emph{ ... more interesting stuff ... }
315 PDF output to `test.pdf'...
316 DVI output to `test.dvi'...
320 @cindex Viewing music
323 The result is the file @file{test.pdf}@footnote{For @TeX{}
324 afficionados: there is also a @file{test.dvi} file. It can be viewed
325 with @code{xdvi}. The DVI uses a lot of PostScript specials, which do
326 not show up in the magnifying glass. The specials also mean that the
327 DVI file cannot be processed with @code{dvilj}. Use @code{dvips} for
332 } which you can print or with the standard facilities of your
333 operating system.@footnote{If your system does not have any tools
334 installed, you can try @uref{Ghostscript,
335 http://www.cs.wisc.edu/~ghost/}, a freely available package for
336 viewing and printing PDF and PostScript files.}
338 On Windows, start up a text-editor@footnote{Any programmer-oriented
339 editor will do, for example NotePad. Do not use word processor. Its
340 formatting codes will confuse LilyPond} and enter
346 \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.}
371 \set Score.timing = ##f
372 \transpose c c' { cis1 ees fisis aeses s16_" " }
376 @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.
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 does get an accidental:
434 \set Staff.TimeSignature = \turnOff
445 Adding all alterations explicitly might require a little more effort
446 when typing, but the advantage is that transposing is easier, and
447 music can be printed according to different conventions. See
448 @ref{Accidentals} for some examples how accidentals can be printed
449 according to different rules.
452 For more information on
456 see @ref{Accidentals}
459 see @ref{Key signature}
463 @section Entering ties
466 A tie is created by adding a tilde ``@code{~}'' to the first note
469 @lilypond[fragment,verbatim,relative=2]
476 For more information on Ties, see @ref{Ties}.
480 @node Automatic and manual beams
481 @section Automatic and manual beams
483 @cindex beams, by hand
484 Beams are drawn automatically
488 @lilypond[fragment,relative=1,verbatim]
494 If you do not like where beams are put, they can be entered by
495 hand. Mark the first note to be beamed with @code{[} and the last one
500 @lilypond[fragment,relative=1,verbatim]
506 For more information on beams, see @ref{Beaming}.
509 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'}:
568 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:
580 @lilypond[raggedright,fragment,verbatim]
583 cis''8. d''16 cis''8 e''4 e''8
584 b'8. cis''16 b'8 d''4 d''8
587 This example shows that music in a high register needs lots of quotes.
588 This makes the input less readable, and it is a source of errors. The
589 solution is to use ``relative octave'' mode. In practice, this is the
590 most convenient way to copy existing music. To use relative mode, add
591 @code{\relative} before the piece of music. You must also give a note
592 from which relative starts, in this case @code{c''}. If you do not
593 use octavation quotes (i.e. do not add @code{'} or @code{,} after a
594 note), relative mode chooses the note that is closest to the previous
595 one. For example, @code{c f} goes up while @code{c g} goes down:
605 \set Score.timing = ##f
606 \set Staff.TimeSignature = \turnOff
615 Since most music has small intervals, pieces can be written almost
616 without octavation quotes in relative mode. The previous example is
619 @lilypond[raggedright,fragment,verbatim]
629 @c needed better, maybe even redundant explanation
630 @c added another example below.
631 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
632 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
633 Larger intervals are made by adding octavation quotes.
642 \set Score.timing = ##f
643 \set Staff.TimeSignature = \turnOff
651 In @code{\relative} mode, quotes or commas no longer determine the
652 absolute height of a note. Rather, the height of a note is relative to
653 the previous one, and changing the octave of a single note shifts all
654 following notes an octave up or down.
656 For more information on Relative octaves see @ref{Relative octaves}
657 and @ref{Octave check}.
660 @node Music expressions explained
661 @section Music expressions explained
664 In input files, music is represent by so-called @emph{music
665 expression}. We have already seen in the previous examples;
666 a single note is a music expression:
668 @lilypond[verbatim,relative=2]
672 Enclosing group of notes in braces creates a new music
675 @lilypond[verbatim,relative=2]
679 Putting a bunch of music expressions (notes) in braces, means that
680 they should be played in sequence. The result again is a music
681 expression, which can be grouped with other expressions sequentially.
682 Here, the expression from the previous example is combined with two
685 @lilypond[verbatim,relative=2]
689 This technique becomes useful for non-monophonic music. To enter music
690 with more voices or more staves, we also combine expressions in
691 parallel. Two voices that should play at the same time, are entered as
692 a simultaneous combination of two sequences. A ``simultaneous'' music
693 expression is formed by enclosing expressions in @code{<<} and
694 @code{>>}. In the following example, three sequences (all contaning
695 two notes) are combined simultaneously:
697 @lilypond[verbatim,relative=2]
705 This mechanism is similar to mathematical
706 formulas: a big formula is created by composing small formulas. Such
707 formulas are called expressions, and their definition is recursive, so
708 you can make arbitrarily complex and large expressions. For example,
717 ((1 + 2) * 3) / (4 * 5)
720 @cindex music expression
721 This example shows a sequence of expressions, where each expression is
722 contained in the next one. The simplest expressions are numbers and
723 operators (like +, * and /). Parentheses are used to group
726 Like mathematical expressions, music expressions can be nested
727 arbitrarily deep, e.g.
728 @lilypond[verbatim,relative=1]
730 << { e f } { c <<b d>> }
738 When spreading expressions over multiple lines, it is customary to use
739 an indent that indicates the nesting level. Formatting music like this
740 eases reading, and helps you insert the right number of closing
741 braces at the end of an expression. For example,
756 Some editors have special support for entering LilyPond, and can help
757 indenting source files. See @ref{Editor support} for more information.
764 To print more than one staff, each piece of music that makes up a
765 staff is marked by adding @code{\new Staff} before it. These
766 @code{Staff}'s are then combined parallel with @code{<<} and
767 @code{>>}, as demonstrated here:
770 @lilypond[fragment,verbatim]
772 \new Staff { \clef violin c'' }
773 \new Staff { \clef bass c }
779 The command @code{\new} introduces a ``notation context.'' A notation
780 context is an environment in which musical events (like notes or
781 @code{\clef} commands) are interpreted. For simple pieces, such
782 notation contexts are created implicitly. For more complex pieces, it
783 is best to mark contexts explicitly. This ensures that each fragment
786 There are several types of contexts: @code{Staff}, @code{Voice} and
787 @code{Score} handle normal music notation. Other staves are also
788 @code{Lyrics} (for setting lyric texts) and @code{ChordNames} (for
789 printing chord names).
792 In terms of syntax, prepending @code{\new} to a music expression
793 creates a bigger music expression. In this way it resembles the minus
794 sign in mathematics. The formula (4+5) is an expression, so -(4+5) is a bigger
797 We can now typeset a melody with two staves:
799 @c TODO: (c) status of this Paul McCartney (?) song (let's all stand together)
803 @lilypond[verbatim,raggedright]
823 For more information on context see the description in
824 @ref{Interpretation context}.
828 @node Adding articulation marks to notes
829 @section Adding articulation marks to notes
835 Common accents can be added to a note using a dash (`@code{-}') and a
838 @lilypond[verbatim,relative=1]
839 c-. c-- c-> c-^ c-+ c-_
845 Similarly, fingering indications can be added to a note using a dash
846 (`@code{-}') and the digit to be printed:
848 @lilypond[verbatim,relative=1]
853 Dynamic signs are made by adding the markings (with a backslash) to
856 @lilypond[verbatim,relative=1]
866 Crescendi and decrescendi are started with the commands @code{\<} and
867 @code{\>}. An ending dynamic, for example @code{\f}, will finish the
868 crescendo, or the command @code{\!} can be used:
870 @lilypond[verbatim,relative=1]
880 A slur is a curve drawn across many notes, and indicates legato
881 articulation. The starting note and ending note are marked with a
882 ``@code{(}'' and a ``@code{)}'' respectively:
885 @lilypond[fragment,relative=1,verbatim]
886 d4( c16)( cis d e c cis d e)( d4)
890 @cindex slurs versus ties
891 A slur looks like a tie, but it has a different meaning. A tie simply
892 makes the first note sound longer, and can only be used on pairs of
893 notes with the same pitch. Slurs indicate the articulations of notes,
894 and can be used on larger groups of notes. Slurs and ties are also
897 @lilypond[fragment,relative=1]
898 c2~( c8 fis fis4 ~ fis2 g2)
901 @cindex phrasing slurs
902 Slurs to indicate phrasing can be entered with @code{\(} and
903 @code{\)}, so you can have both legato slurs and phrasing slurs at the
907 @lilypond[fragment,relative=1,verbatim]
908 a8(\( ais b c) cis2 b'2 a4 cis, c\)
913 For more information on
916 see @ref{Fingering instructions}
918 see @ref{Articulations}
922 see @ref{Phrasing slurs}
928 @node Combining notes into chords
929 @section Combining notes into chords
932 Chords can be made by surrounding pitches with angled brackets.
933 Angled brackets are the symbols @code{<} and @code{>}.
936 @lilypond[relative,fragment,verbatim]
943 You can combine markings like beams and ties with chords. They must
944 be placed outside the angled brackets:
946 @lilypond[relative,fragment,verbatim]
947 r4 <c e g>8[ <c f a>]~ <c f a>
953 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
955 @lilypond[relative,fragment]
957 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
965 @node Basic rhythmical commands
966 @section Basic rhythmical commands
970 @cindex partial measure
971 A pickup is entered with the keyword @code{\partial}. It
972 is followed by a duration: @code{\partial 4} is a quarter note upstep
973 and @code{\partial 8} an eighth note:
974 @lilypond[relative=1,verbatim,fragment]
981 Tuplets are made with the @code{\times} keyword. It takes two
982 arguments: a fraction and a piece of music. The duration of the piece
983 of music is multiplied by the fraction. Triplets make notes occupy
984 2/3 of their notated duration, so a triplet has 2/3 as its fraction:
986 @lilypond[relative,verbatim,fragment]
987 \times 2/3 { f8 g a }
993 Grace notes are also made by prefixing a music expression with the
994 keyword @code{\appoggiatura} or @code{\acciaccatura}
998 @lilypond[relative=1,verbatim,fragment]
999 c4 \appoggiatura b16 c4
1000 c4 \acciaccatura b16 c4
1005 For more information on
1008 see @ref{Grace notes},
1012 see @ref{Partial measures}.
1017 @node Commenting input files
1018 @section Commenting input files
1021 @cindex line comment
1022 @cindex block comment
1023 Comments are pieces of the input that are ignored. There are two
1024 types of comments. The percent symbol @code{%} introduces a line
1025 comment; the rest of the line is ignored. Block comments span larger
1026 sections of input. Anything that is enclosed in @code{%@{} and
1027 @code{%@}} is ignored too. The following fragment shows possible uses
1031 % notes for twinkle twinkle follow:
1036 This line, and the notes below
1037 are ignored, since they are in a
1047 @node Printing lyrics
1048 @section Printing lyrics
1051 @c TODO: (c) status of the Queen fragment.
1055 Lyrics are entered by separating each syllable with a space, and
1056 surrounding them with @code{\lyrics @{ @dots{} @}}, for example,
1058 \lyrics @{ I want to break free @}
1061 Like notes, lyrics are also a form of music, but they must not be
1062 printed on a staff, which is the default way to print music. To print
1063 them as lyrics, they must be marked with @code{ \new Lyrics}:
1065 \new Lyrics \lyrics @{ I want to break free @}
1067 The melody for this song is as follows:
1069 @lilypond[fragment,relative=1]
1072 \times 2/3 { f4 g g } \times 2/3 { g4( a2) }
1075 The lyrics can be set to these notes, combining both with the
1076 @code{\lyricsto} keyword:
1078 \lyricsto "@var{name}" \new Lyrics @dots{}
1080 where @var{name} identifies to which melody the lyrics should be
1081 aligned. In this case, there is only one melody, so we can leave it
1085 @lilypond[verbatim,fragment]
1088 \relative c' \new Voice {
1091 \times 2/3 { f g g } \times 2/3 { g4( a2) }
1093 \lyricsto "" \new Lyrics \lyrics { I want to break free }
1099 @cindex extender line
1101 This melody ends on a @rglos{melisma}, a single syllable (``free'')
1102 sung to more than one note. This is indicated with an @emph{extender
1103 line}. It is entered as two underscores, i.e.
1105 \lyrics @{ I want to break free __ @}
1107 @lilypond[raggedright]
1110 \relative c' \new Voice {
1113 \times 2/3 { f g g } \times 2/3 { g4( a2) } }
1114 \lyricsto "" \new Lyrics \lyrics { I want to break free __ }
1119 Similarly, hyphens between words can be entered as two dashes,
1120 resulting in a centered hyphen between two syllables:
1122 Twin -- kle twin -- kle
1124 @lilypond[raggedright]
1126 << \notes \relative f' { \time 2/4
1128 \new Lyrics \lyrics { Twin -- kle twin -- kle }
1130 \paper { raggedright = ##t }
1134 More options, like putting multiple lines of lyrics below a melody are
1135 discussed in @ref{Vocal music}.
1140 @section A lead sheet
1146 In popular music, it is common to denote accompaniment as chord-names.
1147 Using them in LilyPond has two parts, just like lyrics: entering the
1148 chords (with @code{\chords}), and printing them (with @code{\new
1151 Chord names are entered by starting chords mode (with @code{\chords}).
1152 In chords mode, you can enter chords with a letter (indicating the
1153 root of the chord), and a durations following that:
1156 \chords { c2 f4. g8 }
1160 The result of @code{\chords} is a list of chords, and is equivalent
1161 to entering chords with @code{<@dots{}>}.
1163 Other chords can be created by adding modifiers after a colon. The
1164 following example shows a few common modifiers:
1167 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1170 Printing chords is done by adding @code{\new ChordNames}
1171 before the chords thus entered:
1174 \new ChordNames \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1179 When put together, chord names, lyrics and a melody form
1180 a lead sheet, for example,
1185 \new ChordNames \chords @{ @emph{chords} @}
1186 \notes @emph{the melody}
1187 \lyricsto "" \new Lyrics \lyrics @{ @emph{the text} @}
1194 \new ChordNames \chords { r8 c2:sus4 f }
1195 \notes \relative c' {
1198 \times 2/3 { f g g } \times 2/3 { g4( a2) } }
1199 \new Lyrics \lyricsto "" \lyrics { I want to break free __ }
1201 \paper{ raggedright = ##t }
1206 A complete list of modifiers and other options for layout are in the
1207 reference manual section @ref{Chords}.
1209 @node Listening to output
1210 @section Listening to output
1215 MIDI (Musical Instrument Digital Interface) is a standard for
1216 connecting and recording digital instruments. A MIDI file is like a
1217 tape recording of a MIDI instrument. The @code{\midi} block causes LilyPond
1218 to create a MIDI file, so you can listen to the music you entered.
1219 It is great for checking the music: octaves that are off or
1220 accidentals that were mistyped stand out very much when listening to
1221 the musical transcription.
1223 The @code{\midi} block is added to @code{\score}, for example,
1227 \midi @{ \tempo 4=72 @}
1231 Here, the tempo is specified using the @code{\tempo} command. In this
1232 case the tempo of quarter notes is set to 72 beats per minute. More
1233 information on auditory output is in the @ref{Sound} section in the
1236 If there is a @code{\midi} command in a @code{\score}, then only MIDI
1237 will be produced. If notation is needed too, then a @code{\paper}
1238 block must be added too:
1243 \midi @{ \tempo 4=72 @}
1253 Bibliographic information is entered in a separate block, the
1254 @code{\header} block. The name of the piece, its composer, etc. are
1255 entered as an assignment, within @code{\header @{ @dots{} @}}. For
1259 title = "Eight miniatures"
1260 composer = "Igor Stravinsky"
1261 tagline = "small is beautiful"
1264 \score @{ @dots{} @}
1267 @cindex bibliographic information
1270 @cindex Engraved by LilyPond
1272 When the file is processed by the @code{lilypond} wrapper script
1273 the title and composer specified are printed above the music. The
1274 `tagline' is a short line printed at bottom of the last page which
1275 normally says ``Engraved by LilyPond, version @dots{}''. In the
1276 example above it is replaced by the line ``small is
1277 beautiful.''@footnote{Nicely printed parts are good PR for us, so do
1278 us a favor, and leave the tagline if you can.}
1280 Normally, the @code{\header} is put at the top of the file. However,
1281 for a document that contains multiple pieces (e.g. an etude book, or
1282 an orchestral part with multiple movements), the header can be
1283 put in the @code{\score} block as follows; in this case, the name of
1284 each piece will be printed before each movement:
1287 @cindex Engraved by LilyPond
1288 @cindex signature line
1293 title = "Eight miniatures"
1294 composer = "Igor Stravinsky"
1295 tagline = "small is beautiful"
1299 \header @{ piece = "Adagio" @}
1302 \header @{ piece = "Menuetto" @}
1306 More information on titling can be found in @ref{Invoking lilypond}.
1309 @node Single staff polyphony
1310 @section Single staff polyphony
1313 @cindex multiple voices
1314 @cindex voices, more -- on a staff
1316 When different melodic lines are combined on a single staff they are
1317 printed as polyphonic voices: each voice has its own stems, slurs and
1318 beams, and the top voice has the stems up, while the bottom voice has
1321 Entering such parts is done by entering each voice as a sequence (with
1322 @code{@{ .. @}}), and combining those simultaneously, separating the
1323 voices with @code{\\}:
1326 << @{ a4 g2 f4~ f4 @} \\
1327 @{ r4 g4 f2 f4 @} >>
1329 @lilypond[relative=1]
1330 \new Staff << { a4 g2 f4~ f4 } \\
1334 For polyphonic music typesetting, spacer rests can also be convenient: these
1335 are rests that do not print. It is useful for filling up voices that
1336 temporarily do not play:
1338 << @{ a4 g2 f4~ f4 @} \\
1339 @{ s4 g4 f2 f4 @} >>
1341 @lilypond[relative=1]
1342 \new Staff << { a4 g2 f4~ f4 } \\
1346 Again, these expressions can be nested arbitrarily:
1352 << { a4 g2 f4~ f4 } \\
1355 << { \clef bass <c g>1 ~ <c g>4 } \\
1362 More features of polyphonic typesetting are in the notation manual
1366 @section Piano staves
1368 @cindex staff switch, manual
1369 @cindex cross staff voice, manual
1370 @cindex @code{\context}
1372 Piano music is always typeset in two staves connected by a brace.
1373 Printing such a staff is similar to the polyphonic example in
1376 << \new Staff @{ @dots{} @}
1377 \new Staff @{ @dots{} @}
1380 but now this entire expression must be interpreted as a
1383 \new PianoStaff << \new Staff @dots{} >>
1386 Here is a full-fledged example:
1388 @lilypond[relative,fragment]
1390 << \new Staff { \time 2/4
1393 \clef bass c,, c' e c }
1397 More information on formatting piano music is in @ref{Piano music}.
1399 @node Organizing larger pieces
1400 @section Organizing larger pieces
1402 When all of the elements discussed earlier are combined to produce
1403 larger files, the @code{\score} blocks get a lot bigger, because the
1404 music expressions are longer, and, in the case of polyphonic and/or
1405 orchestral pieces, more deeply nested. Such large expressions can
1408 By using variables, also known as identifiers, it is possible to break
1409 up complex music expressions. An identifier is assigned as follows:
1412 namedMusic = \notes @{ @dots{}
1415 The contents of the music expression @code{namedMusic}, can be used
1416 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1417 In the next example, a two note motive is repeated two times by using
1418 variable substitution:
1420 @lilypond[raggedright,verbatim]
1429 The name of an identifier should have alphabetic characters only;
1430 no numbers, underscores or dashes. The assignment should be outside of
1431 the @code{\score} block.
1433 It is possible to use variables for many other types of objects in the
1438 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1440 Depending on its contents, the identifier can be used in different
1441 places. The following example uses the above variables:
1444 \notes @{ c4^\name @}
1452 More information on the possible uses of identifiers is in the
1453 technical manual, in TODO.
1456 @node An orchestral part
1457 @section An orchestral part
1459 In orchestral music, all notes are printed twice: both in a part for
1460 the musicians, and in a full score for the conductor. Identifiers can
1461 be used to avoid double work: the music is entered once, and stored in
1462 a variable. The contents of that variable is then used to generate
1463 both the part and the score.
1465 It is convenient to define the notes in a special file, for example,
1466 suppose that the @file{horn-music.ly} contains the following part of a
1469 hornNotes = \notes \relative c @{
1475 Then, an individual part is made by putting the following in a file:
1477 \include "horn-music.lyinc"
1479 instrument = "Horn in F"
1482 \notes \transpose f c' \hornNotes
1485 The @code{\include} command substitutes the contents of the file at
1486 this position in the file, so that @code{hornNotes} is defined
1487 afterwards. The code @code{\transpose f c'} indicates that the
1488 argument, being @code{\hornNotes}, should be transposed by a fifth
1489 downwards: sounding @code{f} is denoted by notated @code{c'}, which
1490 corresponds with tuning of a normal French Horn in F. The
1491 transposition can be seen in the following output:
1493 @lilypond[raggedright]
1495 \notes \transpose f c' \notes \relative c {
1502 In ensemble pieces, one of the voices often does not play for many
1503 measures. This is denoted by a special rest, the multi-measure
1504 rest. It is entered with a capital R followed by a duration (1
1505 for a whole note, 2 for a half note, etc.) By multiplying the
1506 duration, longer rests can be constructed. For example, this rest
1507 takes 3 measures in 2/4 time:
1512 When printing the part, the following @code{skipBars} property must be
1513 set to true, to prevent the rest from being expanded to three one bar
1516 \set Score.skipBars = ##t
1518 Prepending the rest and the property setting above, leads to the
1521 @lilypond[raggedright]
1522 \score {\notes { \transpose f c' \relative c { \time 2/4
1523 \set Score.skipBars = ##t
1525 r4 f8 a cis4 f e d } }}
1528 The score is made by combining all of the music in a @code{\score}
1529 block, assuming that the other voice is in @code{bassoonNotes}, in the
1530 file @file{bassoon-music.ly}:
1532 \include "bassoon-music.lyinc"
1533 \include "horn-music.lyinc"
1537 \new Staff \hornNotes
1538 \new Staff \bassoonNotes
1542 This would lead to the simple score depicted below:
1544 @lilypond[raggedright]
1546 \notes \relative c \simultaneous {
1547 \new Staff { \time 2/4
1549 r4 f8 a cis4 f e d }
1550 \new Staff { \clef bass
1551 r4 d,8 f | gis4 c | b bes |
1552 a8 e f4 | g d | gis f }
1556 More in-depth information on preparing parts and scores is in the
1557 notation manual, in @ref{Orchestral music}.
1560 @node Integrating text and music
1561 @section Integrating text and music
1563 @cindex La@TeX{}, music in
1564 @cindex HTML, music in
1565 @cindex Texinfo, music in
1567 Sometimes you might want to use music examples in a text that you are
1568 writing (for example, a musicological treatise, a songbook, or (like us)
1569 the LilyPond manual). You can make such texts by hand, simply by
1570 importing a PostScript figure into your word processor. However,
1571 there is an automated procedure to reduce the amount of work.
1573 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1574 code. A script called @code{lilypond-book} will extract the music
1575 fragments, run LilyPond on them, and put back the resulting notation.
1576 This program is fully described in @ref{lilypond-book manual}. Here
1577 we show a small example. The example also contains explanatory text,
1578 so we will not comment on it further:
1581 \documentclass[a4paper]@{article@}
1584 In a lilypond-book document, you can freely mix music and text. For
1587 \score @{ \notes \relative c' @{
1588 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1592 If you have no \verb+\score+ block in the fragment,
1593 \texttt@{lilypond-book@} will supply one:
1599 In the example you see here two things happened: a
1600 \verb+\score+ block was added, and the line width was set to natural
1601 length. You can specify options by putting them in brackets:
1603 \begin[staffsize=26,verbatim]@{lilypond@}
1607 If you want to include large examples in the text it is more
1608 convenient to put it in a separate file:
1610 \lilypondfile@{screech-boink.ly@}
1615 Under Unix, you can view the results as follows:
1619 $ lilypond-book --output=out/ lilybook.tex
1620 lilypond-book (GNU LilyPond) 2.1.19
1621 Reading `input/tutorial/lilybook.tex'
1622 Reading `input/screech-boink.ly'
1623 @var{lots of stuff deleted}
1624 Writing `out/lilybook.latex'
1626 $ latex lilybook.latex
1627 @var{lots of stuff deleted}
1631 To convert the file into a nice PDF document, run the following
1634 $ dvips -Ppdf -u +lilypond lilybook
1635 $ ps2pdf lilybook.ps
1639 Running lilypond-book and running latex creates a lot of temporary
1640 files. You would not want those to clutter up your working
1641 directory. The @code{outdir} option to lilypond-book creates the
1642 temporary files in a separate subdirectory @file{out}.
1644 The result looks more or less like this:
1648 In a lilypond-book document, you can freely mix music and text. For
1652 \notes \relative c' {
1653 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1661 If you have no @code{\score} block in the fragment,
1662 @code{lilypond-book} will supply one:
1668 In the example you see here, two things happened: a
1669 @code{score} block was added, and the line width was set to natural
1670 length. You can specify options by putting them in brackets:
1672 @lilypond[staffsize=26,verbatim]
1676 If you want to include large examples in the text, it is more
1677 convenient to put it in a separate file:
1679 @lilypondfile{screech-boink.ly}