4 @c * more details about running lilypond; error messages,
5 @c compiling/viewing (emacs?)
6 @c * where to go from First steps+More basics?
13 Using LilyPond comes down to encoding music in an input file. After
14 entering the music, the program is run on the file producing output
15 which can be viewed or printed. In this tutorial, we will show step
16 by step how to enter such files, and illustrate the process with
17 fragments of input and the corresponding output. At the end of every
18 section, a paragraph will list where to find further information on
21 Many people learn programs by trying and fiddling around with the
22 program. This is also possible with LilyPond. If you click on a
23 picture in the HTML version of this manual, you will see the exact
24 LilyPond input that was used to generate that image.
26 For example, consider the following input:
28 c'^\markup @{ \bold \huge @{ Click on this image! @} @}
30 @c @lily pond[relative=1,raggedright,with the following output:]
31 with the following output:
32 @lilypond[relative=1,raggedright]
33 c'^\markup { \bold \huge { Click on this image! } }
37 By cutting and pasting the full input into a test file, you have a
38 starting template for experiments. If you like learning in this way,
39 you will probably want to print out or bookmark
43 @ref{Cheat sheet}, which is a table listing all commands for quick
47 This tutorial starts with a short introduction to the LilyPond music
48 language. After this first contact, we will show you how to to
49 produce printed output. You should then be able to create and print
50 your first sheets of music.
55 * More about pitches::
57 * Combining music into compound expressions::
58 * Adding articulation marks to notes::
59 * Combining notes into chords::
60 * Basic rhythmical commands::
61 * Commenting input files::
64 * Listening to output::
66 * Single staff polyphony::
69 * Fine tuning layout::
70 * Organizing larger pieces::
71 * An orchestral part::
72 * Integrating text and music::
79 We start off by showing how very simple music is entered in LilyPond:
80 you get a note simply by typing its note name, from @samp{a}
81 through @samp{g}. So if you enter
88 then the result looks like this:
90 @lilypond[notime,relative]
94 The length of a note is specified by adding a number, @samp{1} for a
95 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
102 \property Score.timing = ##f
103 \property Staff.autoBeaming = ##f
104 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
107 If you do not specify a @rglos{duration}, the previous one is used:
114 \property Score.timing = ##f
115 \transpose c c' { a a a2 a s16_" " }
119 Rests are entered just like notes, but with the name ``@code{r}'':
128 \property Score.timing = ##f
129 \property Staff.Clef = \turnOff
130 \property Staff.TimeSignature = \turnOff
138 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
145 \property Score.timing = ##f
146 \transpose c c' { a2. a4 a8. a16 s16_" " }
150 The @rglos{meter} (or @rglos{time signature}) can be set with the
151 @code{\time} command:
159 @c a clef here may lead to confusion
161 \property Staff.Clef \set #'transparent = ##t
171 The @rglos{clef} can be set using the @code{\clef} command:
173 @c what is more common name treble or violin?
174 @c in Dutch, its violin.
175 @c in English its definitely treble.
184 \property Score.timing = ##f
195 Notes and commands like @code{\clef} and @code{\time}, are enclosed
196 in @code{\notes @{@dots{}@}}. This indicates that music (as opposed
197 to @rglos{lyrics}) follows:
207 Now the piece of music is almost ready to be printed. The final step is to
208 combine the music with a printing command.
210 The printing command is the so-called @code{\paper} block:
216 The @code{\paper} block is used to customize printing specifics. The
217 customization commands go between @code{@{} and @code{@}}, but for
218 now, we accept the defaults. The music and the @code{\paper} block
219 are combined by enclosing them in @code{\score @{ ... @}}, so the
220 following is a complete and valid input file:
243 linewidth = 55 * \staffspace
248 In the rest of the tutorial we will often leave out @code{\score}
249 and @code{\paper} for clarity. However, both must be present when
250 feeding the file to LilyPond.
252 For more elaborate information on
255 @item entering pitches and durations
257 @ref{Pitches} and @ref{Durations}.
260 @item Time signatures and other timing commands
261 see @ref{Time signature}.
264 @node Running LilyPond
265 @section Running LilyPond
267 In the last section we explained what kind of things you could enter
268 in a LilyPond file. In this section we explain what commands to run
269 and how to view or print the output. If you have not used LilyPond
270 before, want to test your setup, or want to run an example file
271 yourself, read this section. The instructions that follow are for
272 Unix-like systems. Some additional instructions for Microsoft Windows
273 are given at the end of this section.
275 Begin by opening a terminal window and starting a text editor. For
276 example, you could open an xterm and execute
277 @code{joe}.@footnote{There are macro files for VIM addicts, and there
278 is a @code{LilyPond-mode} for Emacs addicts. If it has not been
279 installed already, then refer to the file @file{INSTALL.txt}}. In
280 your text editor, enter the following input and save the file as
286 \notes @{ c'4 e' g' @}
291 To process @file{test.ly}, proceed as follows:
299 You will see something resembling:
304 Now processing: `/home/fred/ly/test.ly'
306 Interpreting music...[1]
307 @emph{ ... more interesting stuff ... }
308 PDF output to `test.pdf'...
309 DVI output to `test.dvi'...
313 @cindex Viewing music
316 The result is the file @file{test.pdf}.@footnote{For @TeX{}
317 afficionados: there is also a @file{test.dvi} file. It can be viewed
318 with @code{xdvi}. The DVI uses a lot of PostScript specials, which do
319 not show up in the magnifying glass. The specials also mean that the
320 DVI file cannot be processed with @code{dvilj}. Use @code{dvips} for
325 } One of the following commands should put the PDF on your
341 If the music on your screen looks good, you can print it by clicking
342 File/Print inside your viewing program.
346 @cindex Printing output
351 On Windows, the same procedure should work, the terminal is started by
352 clicking on the LilyPond or Cygwin icon. Any text editor (such as
353 NotePad, Emacs or Vim) may be used to edit the LilyPond file.
355 To view the PDF file, try the following:
358 If your system has a PDF viewer installed, open
359 @file{C:\Cygwin\home\@var{your-name}} in the explorer and double-click
362 If you prefer the keyboard, you can try to enter one of the commands
363 from the list shown before in the terminal. If none work, go to
364 @uref{http://www.cs.wisc.edu/~ghost/} to install the proper software.
367 The commands for formatting and printing music on all platforms are
368 detailed in @ref{Invoking LilyPond}.
370 @node More about pitches
371 @section More about pitches
373 A @rglos{sharp} (@texisharp{}) pitch is made by adding @samp{is} to
374 the name, a @rglos{flat} (@texiflat{}) pitch by adding @samp{es}. As
375 you might expect, a @rglos{double sharp} or @rglos{double flat} is
376 made by adding @samp{isis} or @samp{eses}:@footnote{This syntax
377 derived from note naming conventions in Nordic and Germanic languages,
378 like German and Dutch.}
385 \property Score.timing = ##f
386 \transpose c c' { cis1 ees fisis aeses s16_" " }
390 @cindex key signature, setting
392 The key signature is set with the command ``@code{\key}'', followed by
393 a pitch and @code{\major} or @code{\minor}:
403 \property Staff.TimeSignature = \turnOff
412 Key signatures together with the pitch (including alterations) are
413 used together to determine when to print accidentals. This is a
414 feature that often causes confusion to newcomers, so let us explain it
418 LilyPond has a sharp distinction between musical content and
419 layout. The alteration (flat, natural or sharp) of a note is part of
420 the pitch, and is therefore musical content. Whether an accidental (a
421 flat, natural or sharp @emph{sign}) is a printed in front of the
422 corresponding note is a question of layout. Layout is something that
423 follows rules, so accidentals are printed automatically according to
424 those rules. The pitches in your music are works of art, so they will
425 not be added automatically, and you must enter what you want to hear.
427 For example, in this example:
429 \property Staff.TimeSignature = #'()
435 no note gets an explicit accidental, but still you enter
442 The code @code{d} does not mean ``print a black dot just below the
443 staff.'' Rather, it means: ``a note with pitch D-natural.'' In the key
444 of A-flat, it gets an accidental:
447 \property Staff.TimeSignature = #'()
458 Adding all alterations explicitly might require some more effort when
459 typing, but the advantage is that transposing is easier, and music can
460 be printed according to different conventions. See @ref{Accidentals}
461 for some examples how accidentals can be printed according to
466 A tie is created by adding a tilde ``@code{~}'' to the first note
469 @lilypond[fragment,verbatim,relative=2]
475 This example shows the key signature, accidentals and ties in action:
486 fis4 fis8 fis8 eis4 a8 gis~
495 \notes { \transpose c c' {
501 fis4 fis8 fis8 eis4 a8 gis~
504 \paper { linewidth = #(* 50 staffspace) }
510 There are some interesting points to note in this example. Bar lines
511 and beams are drawn automatically. Line breaks are calculated
512 automatically; it does not matter where the lines breaks are in the
513 source file. Finally, the order of time, key and clef changes is not
514 relevant: in the printout, these are ordered according to standard
515 notation conventions.
518 @cindex beams, by hand
519 Beams are drawn automatically, but if you do not like where they are
520 put, they can be entered by hand. Mark the first note to be beamed
521 with @code{[} and the last one with @code{]}:
523 @lilypond[fragment,relative=1,verbatim]
529 For more information on
538 see @ref{Accidentals}
541 see @ref{Key signature}
549 @section Octave entry
552 @c Tim wants to move this quotes example just before the: quotes-do not-work
553 @c score, but we'd need to remove quotes from the other two (key and
556 @c better to have this just before the `octaves are bad' snipped
557 @c but we'd need to remove the ', from \key and tie
558 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
559 the note name, to lower a note one octave, add a ``low quote'' @code{,}
560 (a comma). Middle C is @code{c'}:
564 c'4 c'' c''' \clef bass c c,
568 \property Score.timing = ##f
569 \property Staff.TimeSignature = \turnOff
570 c'4 c'' c''' \clef bass c c,
575 An example of the use of quotes is in the following Mozart fragment:
576 @lilypond[raggedright,fragment,verbatim]
579 cis''8. d''16 cis''8 e''4 e''8
580 b'8. cis''16 b'8 d''4 d''8
583 This example shows that music in a high register needs lots of quotes.
584 This makes the input less readable, and it is a source of errors. The
585 solution is to use ``relative octave'' mode. In practice, this is the
586 most convenient way to copy existing music. To use relative mode, add
587 @code{\relative} before the piece of music. You must also give a note
588 from which relative starts, in this case @code{c''}. If you do not
589 use octavation quotes (i.e. do not add @code{'} or @code{,} after a
590 note), relative mode chooses the note that is closest to the previous
591 one. For example, @code{c f} goes up while @code{c g} goes down:
601 \property Score.timing = ##f
602 \property Staff.TimeSignature = \turnOff
611 Since most music has small intervals, pieces can be written almost
612 without octavation quotes in relative mode. The previous example is
615 @lilypond[raggedright,fragment,verbatim]
625 @c needed better, maybe even redundant explanation
626 @c added another example below.
627 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
628 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
629 Larger intervals are made by adding octavation quotes.
638 \property Score.timing = ##f
639 \property Staff.TimeSignature = \turnOff
647 Quotes or commas do not determine the absolute height of a note; the
648 height of a note is relative to the previous one.
649 @c do not use commas or quotes in this sentence
650 For example: @code{c f,} goes down; @code{f, f} are both the same;
651 @code{c' c} are the same; and @code{c g'} goes up:
655 Here is an example of the difference between relative mode and
656 ``normal'' (non-relative) mode:
667 \property Score.timing = ##f
668 \property Staff.TimeSignature = \turnOff
684 \property Score.timing = ##f
685 \property Staff.TimeSignature = \turnOff
693 For more information on Relative octaves see @ref{Relative octaves}
694 and @ref{Octave check}.
701 @node Combining music into compound expressions
702 @section Combining music into compound expressions
704 To print more than one staff, each piece of music that makes up a
705 staff is marked by adding @code{\context Staff} before it. These
706 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and
707 @code{@}}, as is demonstrated here:
710 @lilypond[fragment,verbatim]
712 \new Staff { \clef violin c'' }
713 \new Staff { \clef bass c }
719 In this example, @code{\simultaneous } indicates that both music
720 fragments happen at the same time, and must be printed stacked
721 vertically. The notation @code{<< .. >>} can also be used as a
722 shorthand for @code{\simultaneous @{ .. @}}.
724 The command @code{\new} introduces a ``notation context''. To
725 understand this concept, imagine that you are performing a piece of
726 music. When you are playing, you combine the symbols printed at a
727 certain point with contextual information. For example, without
728 knowing the current clef, and the accidentals in the last measure, it
729 would be impossible to determine the pitch of a note. In other words,
730 this information forms context that helps you decipher a
731 score. LilyPond produces notation from music, so in effect, it does
732 the inverse of reading scores. Therefore, it also needs to keep track
733 of contextual information. This information is maintained in
734 ``notation contexts.'' There are several types of contexts,
735 e.g. @code{Staff}, @code{Voice} and @code{Score}, but also
736 @code{Lyrics} and @code{ChordNames}. Prepending @code{\new} to a chunk
737 of music indicates what kind of context to use for interpreting it,
738 and ensures that the argument is interpreted with a fresh instance of
739 the context indicated.
744 We can now typeset a melody with two staves:
747 @lilypond[verbatim,raggedright]
768 The example shows how small chunks of music, for example, the notes
769 @code{c2}, @code{e4}, etc. of the second staff, are combined to form a
770 larger chunk by enclosing it in braces. Again, a larger chunk is
771 formed by prefix @code{\new Staff} to it, and that chunk is combined
772 with @code{<< >>}. This mechanism is similar with mathematical
773 formulas: a big formula is created by composing small formulas. Such
774 formulas are called expressions, and their definition is recursive, so
775 you can make arbitrarily complex and large expressions. For example,
784 ((1 + 2) * 3) / (4 * 5)
787 @cindex music expression
788 This example shows a sequence of expressions, where each expression is
789 contained in the next one. The simplest expressions are numbers and
790 operators (like +, * and /). Parentheses are used to group
791 expressions. In LilyPond input, a similar mechanism is used. Here,
792 the simplest expressions are notes and rests. By enclosing
793 expressions in @code{<< >>} and @code{@{ @}}, more complex music is
794 formed. The @code{\new} command also forms new expressions; prepending
795 it to a music expression yields a new expression.
797 Like mathematical expressions, music expressions can be nested
798 arbitrarily deep, e.g.
799 @lilypond[verbatim,relative=1]
801 << { e f } { c <<b d>> }
808 When spreading expressions over multiple lines, it is customary to use
809 an indent that indicates the nesting level. Formatting music like this
810 eases reading, and helps you insert the right amount of closing
811 braces at the end of an expression. For example,
826 For more information on context see the Technical manual description
827 in @ref{Interpretation context}.
831 @node Adding articulation marks to notes
832 @section Adding articulation marks to notes
838 Common accents can be added to a note using a dash (`@code{-}') and a
841 @lilypond[verbatim,relative=1]
842 c-. c-- c-> c-^ c-+ c-_
848 Similarly, fingering indications can be added to a note using a dash
849 (`@code{-}') and the digit to be printed:
851 @lilypond[verbatim,relative=1]
856 Dynamic signs are made by adding the markings to the note:
858 @lilypond[verbatim,relative=1]
868 Crescendi and decrescendi are started with the commands @code{\<} and
869 @code{\>}. The command @code{\!} finishes a crescendo on the note it
872 @lilypond[verbatim,relative=1]
873 c2\< c2\!\ff\> c2 c2\!
882 A slur is drawn across many notes, and indicates bound articulation
883 (legato). The starting note and ending note are marked with a
884 ``@code{(}'' and a ``@code{)}'' respectively:
887 @lilypond[fragment,relative=1,verbatim]
888 d4( c16)( cis d e c cis d e)( d4)
892 @cindex slurs versus ties
893 A slur looks like a tie, but it has a different meaning. A tie simply
894 makes the first note sound longer, and can only be used on pairs of
895 notes with the same pitch. Slurs indicate the articulations of notes,
896 and can be used on larger groups of notes. Slurs and ties are also
899 @lilypond[fragment,relative=1]
900 c2~( c8 fis fis4 ~ fis2 g2)
903 @cindex phrasing slurs
904 If you need two slurs at the same time (one for articulation, one for
905 phrasing), you can also make a phrasing slur with @code{\(} and
909 @lilypond[fragment,relative=1,verbatim]
910 a8(\( ais b c) cis2 b'2 a4 cis, c\)
915 For more information on
918 see @ref{Fingering instructions}
920 see @ref{Articulations}
924 see @ref{Phrasing slurs}
930 @node Combining notes into chords
931 @section Combining notes into chords
934 Chords can be made by
935 surrounding pitches with @code{<} and @code{>}:
937 @lilypond[relative,fragment,verbatim]
944 You can combine beams and ties with chords. Beam and tie markings
945 must be placed outside the chord markers:
947 @lilypond[relative,fragment,verbatim]
948 r4 <c e g>8[ <c f a>]~ <c f a>
954 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
956 @lilypond[relative,fragment]
958 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
966 @node Basic rhythmical commands
967 @section Basic rhythmical commands
972 @cindex partial measure
973 A pickup (or upstep) is entered with the keyword @code{\partial}. It
974 is followed by a duration: @code{\partial 4} is a quarter note upstep
975 and @code{\partial 8} an eighth note:
976 @lilypond[relative=1,verbatim,fragment]
983 Tuplets are made with the @code{\times} keyword. It takes two
984 arguments: a fraction and a piece of music. The duration of the piece
985 of music is multiplied by the fraction. Triplets make notes occupy
986 2/3 of their notated duration, so a triplet has 2/3 as its fraction:
988 @lilypond[relative,verbatim,fragment]
989 \times 2/3 { f8 g a }
995 Grace notes are also made by prefixing a note, or a set of notes with
996 a keyword. In this case, the keywords are @code{\appoggiatura}
997 and @code{\acciaccatura}
1001 @lilypond[relative=1,verbatim,fragment]
1002 c4 \appoggiatura b16 c4
1003 c4 \acciaccatura b16 c4
1008 For more information on
1011 see @ref{Grace notes},
1015 see @ref{Partial measures}.
1020 @node Commenting input files
1021 @section Commenting input files
1024 @cindex line comment
1025 @cindex block comment
1026 Comments are pieces of the input that are ignored. There are two
1027 types of comments. A line comments is introduced by @code{%}: after
1028 that, the rest of that line is ignored. Block comments span larger
1029 sections of input. Anything that is enclosed in @code{%@{} and
1030 @code{%@}} is ignored too. The following fragment shows possible uses
1034 % notes for twinkle twinkle follow:
1039 This line, and the notes below
1040 are ignored, since they are in a
1050 @node Printing lyrics
1051 @section Printing lyrics
1056 Lyrics are entered by separating each syllable with a space, and
1057 surrounding them with @code{\lyrics @{ @dots{} @}}, for example,
1059 \lyrics @{ I want to break free @}
1062 Like notes, lyrics are also a form of music, but they must not be
1063 printed on a staff, which is the default way to print music. To print
1064 them as lyrics, they must be marked with @code{ \new LyricsVoice}:
1066 \new LyricsVoice \lyrics @{ I want to break free @}
1068 The melody for this song is as follows:
1070 @lilypond[fragment,relative=1]
1073 \times 2/3 { f4 g g } \times 2/3 { g4( a2) }
1076 The lyrics can be set to these notes, combining both with the
1077 @code{\lyricsto} keyword:
1079 \lyricsto "@var{name}" \new LyricsVoice @dots{}
1081 where @var{name} identifies to which melody the lyrics should be
1082 aligned. In this case, there is only one melody, so we can leave it
1086 @lilypond[verbatim,linewidth=6.0\cm]
1089 \relative c' \new Voice {
1092 \times 2/3 { f g g } \times 2/3 { g4( a2) }
1094 \lyricsto "" \new LyricsVoice \lyrics { I want to break free }
1101 @cindex extender line
1103 This melody ends on a @rglos{melisma}, a single syllable (``free'')
1104 sung to more than one note. This is indicated with an @emph{extender
1105 line}. It is entered as two underscores, i.e.
1107 \lyrics @{ I want to break free __ @}
1112 \relative c' \new Voice {
1115 \times 2/3 { f g g } \times 2/3 { g4( a2) } }
1116 \lyricsto "" \new LyricsVoice \lyrics { I want to break free __ }
1122 Similarly, hyphens between words can be entered as two dashes,
1123 resulting in a centered hyphen between two syllables:
1125 Twin -- kle twin -- kle
1127 @lilypond[raggedright]
1129 << \notes \relative f' { \time 2/4
1131 \new Lyrics \lyrics { Twin -- kle twin -- kle }
1133 \paper { raggedright = ##t }
1137 More options, like putting multiple lines of lyrics below a melody are
1138 discussed in @ref{Vocal music}.
1143 @section A lead sheet
1149 In popular music, it is common to denote accompaniment as chord-names.
1150 Using them in LilyPond has two parts, just like lyrics: entering the
1151 chords (with @code{\chords}), and printing them (with @code{\new
1154 Chord names are entered by starting chords mode (with @code{\chords}).
1155 In chords mode, you can enter chords with a letter (indicating the
1156 root of the chord), and a durations following that:
1159 \chords { c2 f4. g8 }
1163 The result of @code{\chords} is a list of chords, and is equivalent
1164 to entering chords with @code{<@dots{}>}.
1166 Other chords can be created by adding modifiers, after a colon. The
1167 following example shows a few common modifiers:
1170 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1173 Printing chords is done by adding @code{\context ChordNames}
1174 before the chords thus entered:
1177 \context ChordNames \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1182 When put together, chord names, lyrics and a melody form
1183 a lead sheet, for example,
1188 \context ChordNames \chords @{ @emph{chords} @}
1189 \notes @emph{the melody}
1190 \lyricsto "" \new LyricsVoice \lyrics @{ @emph{the text} @}
1198 \context ChordNames \chords { r8 c2:sus4 f }
1199 \notes \relative c' {
1202 \times 2/3 { f g g } \times 2/3 { g4( a2) } }
1203 \new LyricsVoice \lyricsto "" \lyrics { I want to break free __ }
1205 \paper{ raggedright = ##t }
1210 A complete list of modifiers, and other options for layout are in the
1211 reference manual section @ref{Chords}.
1213 @node Listening to output
1214 @section Listening to output
1219 MIDI (Musical Instrument Digital Interface) is a standard for
1220 connecting and recording digital instruments. A MIDI file is like a
1221 tape recording of a MIDI instrument. The @code{\midi} block makes the
1222 music go to a MIDI file, so you can listen to the music you entered.
1223 It is great for checking the music: octaves that are off, or
1224 accidentals that were mistyped, stand out very much when listening to
1225 the musical transcription.
1227 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
1232 \midi @{ \tempo 4=72 @}
1237 Here, the tempo is specified using the @code{\tempo} command. In this
1238 case the tempo of quarter notes is set to 72 beats per minute. More
1239 information on auditory output is in the @ref{Sound} section in the
1247 Bibliographic information is entered in a separate block, the
1248 @code{\header} block. The name of the piece, its composer, etc. are
1249 entered as an assignment, within @code{\header @{ @dots{} @}}. For
1253 title = "Eight miniatures"
1254 composer = "Igor Stravinsky"
1255 tagline = "small is beautiful"
1258 \score @{ @dots{} @}
1261 @cindex bibliographic information
1264 @cindex Engraved by LilyPond
1266 When the file is processed by the @code{lilypond} wrapper script, then
1267 the title and composer specified are printed above the music. The
1268 `tagline' is a short line printed at bottom of the last page, which
1269 normally says ``Engraved by LilyPond, version @dots{}''. In the
1270 example above, it is replaced by the line ``small is
1271 beautiful.''@footnote{Nicely printed parts are good PR for us, so do
1272 us a favor, and leave the tagline if you can.}
1274 Normally, the @code{\header} is put at the top of the file. However,
1275 for a document that contains multiple pieces (e.g. an etude book, or
1276 an orchestral part with multiple movements), then the header can be
1277 put into the @code{\score} block as follows; in this case, the name of
1278 each piece will be printed before each movement:
1281 @cindex Engraved by LilyPond
1282 @cindex signature line
1287 title = "Eight miniatures"
1288 composer = "Igor Stravinsky"
1289 tagline = "small is beautiful"
1293 \header @{ piece = "Adagio" @}
1296 \header @{ piece = "Menuetto" @}
1300 More information on titling can be found in @ref{Invoking lilypond}.
1303 @node Single staff polyphony
1304 @section Single staff polyphony
1307 @cindex multiple voices
1308 @cindex voices, more -- on a staff
1310 When different melodic lines are combined on a single staff, these are
1311 printed as polyphonic voices: each voice has its own stems, slurs and
1312 beams, and the top voice has the stems up, while the bottom voice has
1315 Entering such parts is done by entering each voice as a sequence (with
1316 @code{@{ .. @}}), and combining those simultaneously, separating the
1317 voices with @code{\\}:
1320 << @{ a4 g2 f4~ f4 @} \\
1321 @{ r4 g4 f2 f4 @} >>
1323 @lilypond[relative=1]
1324 \context Staff << { a4 g2 f4~ f4 } \\
1328 For polyphonic music typesetting, spacer rests can also be convenient: these
1329 are rests that do not print. It is useful for filling up voices that
1330 temporarily do not play:
1332 << @{ a4 g2 f4~ f4 @} \\
1333 @{ s4 g4 f2 f4 @} >>
1335 @lilypond[relative=1]
1336 \context Staff << { a4 g2 f4~ f4 } \\
1340 Again, these expressions can be nested arbitrarily:
1346 << { a4 g2 f4~ f4 } \\
1349 << { \clef bass <c g>1 ~ <c g>4 } \\
1356 More features of polyphonic typesetting are in the notation manual
1360 @section Piano staves
1362 @cindex staff switch, manual
1363 @cindex cross staff voice, manual
1364 @cindex @code{\translator}
1366 Piano music is always typeset in two staves connected by a brace.
1367 Printing such a staff is done similar to the polyphonic example in
1368 @ref{Combining music into compound expressions}:
1370 << \new Staff @{ @dots{} @}
1371 \new Staff @{ @dots{} @}
1374 but now this entire expression must be interpreted as a
1377 \new PianoStaff << \new Staff @dots{} >>
1380 Here is a full-fledged example:
1382 @lilypond[relative,fragment]
1384 << \new Staff { \time 2/4
1387 \clef bass c,, c' e c }
1391 More information on formatting piano music is in @ref{Piano music}.
1393 @node Setting variables
1394 @section Setting variables
1396 When the music is converted from notes to print, it is interpreted
1397 from left-to-right order, similar to what happens when we read
1398 music. During this step, context-sensitive information, such as the
1399 accidentals to print, and where barlines must be placed, are stored in
1400 variables. These variables are called @emph{context properties}.
1401 The properties can also be manipulated from input files. Consider this input:
1403 \property Staff.autoBeaming = ##f
1407 It sets the property named @code{autoBeaming} in the current staff at
1408 this point in the music to @code{##f}, which means `false'. This
1409 property controls whether beams are printed automatically:
1411 @lilypond[relative=1,fragment,verbatim]
1413 \property Staff.autoBeaming = ##f
1418 LilyPond includes a built-in programming language, namely, a dialect
1419 of Scheme. The argument to @code{\property}, @code{##f}, is an
1420 expression in that language. The first hash-mark signals that a piece
1421 of Scheme code follows. The second hash character is part of the
1422 boolean value true (@code{#t}). Values of other types may be
1425 @item a string, enclosed in double quotes, for example,
1427 \property Staff.instrument = #"French Horn"
1429 @item a boolean: either @code{#t} or @code{#f}, for true and false
1432 \property Voice.autoBeaming = ##f
1433 \property Score.skipBars = ##t
1436 @item a number, such as
1438 \property Score.currentBarNumber = #20
1441 @item a symbol, which is introduced by a quote character, as in
1443 \property Staff.crescendoSpanner = #'dashed-line
1446 @item a pair, which is also introduced by a quote character, like in
1447 the following statements, which set properties to the pairs (-7.5, 6)
1448 and (3, 4) respectively:
1451 \property Staff.minimumVerticalExtent = #'(-7.5 . 6)
1452 \property Staff.timeSignatureFraction = #'(3 . 4)
1455 @item a list, which is also introduced by a quote character. In the
1456 following example, the @code{breakAlignOrder} property is set to a
1459 \property Score.breakAlignOrder =
1460 #'(left-edge time-signature key-signatures)
1466 There are many different properties, and not all of them are listed in
1467 this manual. However, the program reference lists them all in the
1468 section @internalsref{Context-properties}, and most properties are
1469 demonstrated in one of the
1471 @uref{../../../input/test/out-www/collated-files.html,tips-and-tricks}
1479 @node Fine tuning layout
1480 @section Fine tuning layout
1482 Sometimes it is necessary to change music layout by hand. When music
1483 is formatted, layout objects are created for each symbol. For
1484 example, every clef and every note head is represented by a layout
1485 object. These layout objects also carry variables, which we call
1486 @emph{layout properties}. By changing these variables from their
1487 values, we can alter the look of a formatted score:
1489 @lilypond[verbatim,]
1491 \property Voice.Stem \override #'thickness = #3.0
1496 In the example shown here, the layout property @code{thickness} (a
1497 symbol) is set to 3 in the @code{Stem} layout objects of the current
1498 Voice. As a result, the notes following @code{\property} have thicker
1501 In most cases of manual overrides, only a single object must be
1502 changed. This can be achieved by prefixing @code{\once} to the
1503 @code{\property} statement, i.e.
1506 \once \property Voice.Stem \set #'thickness = #3.0
1511 \once \property Voice.Stem \set #'thickness = #3.0
1516 Some overrides are so common that predefined commands are provided as
1517 a short cut. For example, @code{\slurUp} and @code{\stemDown}. These
1518 commands are described in
1522 @ref{Notation manual}, under the sections for slurs and stems
1525 The exact tuning possibilities for each type of layout object are
1526 documented in the program reference of the respective
1527 object. However, many layout objects share properties, which can be
1528 used to apply generic tweaks. We mention a couple of these:
1531 @item The @code{extra-offset} property, which
1532 @cindex @code{extra-offset}
1533 has a pair of numbers as value, moves around objects in the printout.
1534 The first number controls left-right movement; a positive number will
1535 move the object to the right. The second number controls up-down
1536 movement; a positive number will move it higher. The unit of these
1537 offsets are staff-spaces. The @code{extra-offset} property is a
1538 low-level feature: the formatting engine is completely oblivious to
1541 In the following example, the second fingering is moved a little to
1542 the left, and 1.8 staff space downwards:
1544 @cindex setting object properties
1546 @lilypond[relative=1,verbatim]
1549 \once \property Voice.Fingering
1550 \set #'extra-offset = #'(-0.3 . -1.8)
1555 Setting the @code{transparent} property will make an object be printed
1556 in `invisible ink': the object is not printed, but all its other
1557 behavior is retained. The object still takes space, it takes part in
1558 collisions, and slurs, ties and beams can be attached to it.
1560 @cindex transparent objects
1561 @cindex removing objects
1562 @cindex invisible objects
1563 The following example demonstrates how to connect different voices
1564 using ties. Normally ties only happen between notes of the same
1565 voice. By introducing a tie in a different voice, and blanking a stem
1566 in that voice, the tie appears to cross voices:
1568 @lilypond[fragment,relative=1,verbatim]
1570 \once \property Voice.Stem \set #'transparent = ##t
1578 The @code{padding} property for objects with
1579 @cindex @code{padding}
1580 @code{side-position-interface} can be set to increase distance between
1581 symbols that are printed above or below notes. We only give an
1582 example; a more elaborate explanation is in @ref{Constructing a
1585 @lilypond[relative=1,verbatim]
1587 \property Voice.Script \set #'padding = #3
1593 More specific overrides are also possible. The notation manual
1594 discusses in depth how to figure out these statements for yourself, in
1595 @ref{Tuning output}.
1597 @node Organizing larger pieces
1598 @section Organizing larger pieces
1600 When all of the elements discussed earlier are combined to produce
1601 larger files, the @code{\score} blocks get a lot bigger, because the
1602 music expressions are longer, and, in the case of polyphonic and/or
1603 orchestral pieces, more deeply nested. Such large expressions can
1606 By using variables, also known as identifiers, it is possible to break
1607 up complex music expressions. An identifier is assigned as follows:
1610 namedMusic = \notes @{ @dots{}
1613 The contents of the music expression @code{namedMusic}, can be used
1614 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1615 In the next example, a two note motive is repeated two times by using
1616 variable substitution:
1618 @lilypond[raggedright,verbatim]
1627 The name of an identifier should have alphabetic characters only, and
1628 no numbers, underscores or dashes. The assignment should be outside of
1629 the @code{\score} block.
1631 It is possible to use variables for many other types of objects in the
1636 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1638 Depending on its contents, the identifier can be used in different
1639 places. The following example uses the above variables:
1642 \notes @{ c4^\name @}
1650 More information on the possible uses of identifiers is in the
1651 technical manual, in @ref{Scheme datatypes}.
1654 @node An orchestral part
1655 @section An orchestral part
1657 In orchestral music, all notes are printed twice: both in a part for
1658 the musicians, and in a full score for the conductor. Identifiers can
1659 be used to avoid double work: the music is entered once, and stored in
1660 variable. The contents of that variable is then used to generate
1661 both the part and the score.
1663 It is convenient to define the notes in a special file, for example,
1664 suppose that the @file{horn-music.ly} contains the following part of a
1667 hornNotes = \notes \relative c @{
1673 Then, an individual part is made by putting the following in a file:
1675 \include "horn-music.lyinc"
1677 instrument = "Horn in F"
1680 \notes \transpose f c' \hornNotes
1683 The @code{\include} command substitutes the contents of the file at
1684 this position in the file, so that @code{hornNotes} is defined
1685 afterwards. The code @code{\transpose f c'} indicates that the
1686 argument, being @code{\hornNotes}, should be transposed by a fifth
1687 downwards: sounding @code{f} is denoted by notated @code{c'}, which
1688 corresponds with tuning of a normal French Horn in F. The
1689 transposition can be seen in the following output:
1691 @lilypond[raggedright]
1693 \notes \transpose f c' \notes \relative c {
1700 In ensemble pieces, one of the voices often does not play for many
1701 measures. This is denoted by a special rest, the multi-measure
1702 rest. It is entered with a capital R, and followed by a duration (1
1703 for a whole note, 2 for a half note, etc.) By multiplying the
1704 duration, longer rests can be constructed. For example, the next rest
1705 takes 3 measures in 2/4 time:
1710 When printing the part, the following @code{skipBars} property must be
1711 set to false, to prevent the rest from being expanded in three one bar
1714 \property Score.skipBars = ##t
1716 Prepending the rest and the property setting above, leads to the
1719 @lilypond[raggedright]
1720 \score {\notes { \transpose f c' \relative c { \time 2/4
1721 \property Score.skipBars = ##t
1723 r4 f8 a cis4 f e d } }}
1726 The score is made by combining all of the music in a @code{\score}
1727 block, assuming that the other voice is in @code{bassoonNotes}, in the
1728 file @file{bassoon-music.ly}:
1730 \include "bassoon-music.lyinc"
1731 \include "horn-music.lyinc"
1735 \new Staff \hornNotes
1736 \new Staff \bassoonNotes
1740 This would lead to the simple score depicted below:
1742 @lilypond[raggedright]
1744 \notes \relative c \simultaneous {
1745 \new Staff { \time 2/4
1747 r4 f8 a cis4 f e d }
1748 \new Staff { \clef bass
1749 r4 d,8 f | gis4 c | b bes |
1750 a8 e f4 | g d | gis f }
1754 More in-depth information on preparing parts and scores is in the
1755 notation manual, in @ref{Orchestral music}.
1758 @node Integrating text and music
1759 @section Integrating text and music
1761 @cindex La@TeX{}, music in
1762 @cindex HTML, music in
1763 @cindex Texinfo, music in
1765 Sometimes you might want to use music examples in a text that you are
1766 writing (for example, a musicological treatise, a songbook, or (like us)
1767 the LilyPond manual). You can make such texts by hand, simply by
1768 importing a PostScript figure into your word processor. However,
1769 there is an automated procedure to reduce the amount of work.
1771 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1772 code. A script called @code{lilypond-book} will extract the music
1773 fragments, run LilyPond on them, and put back the resulting notation.
1774 This program is fully described in @ref{lilypond-book manual}. Here
1775 we show a small example; since the example contains also explanatory
1776 text, we will not comment it further:
1779 \documentclass[a4paper]@{article@}
1782 In a lilypond-book document, you can freely mix music and text. For
1785 \score @{ \notes \relative c' @{
1786 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1790 If you have no \verb+\score+ block in the fragment,
1791 \texttt@{lilypond-book@} will supply one:
1797 In the example you see here, two things happened: a
1798 \verb+\score+ block was added, and the line width was set to natural
1799 length. You can specify options by putting them in brackets:
1801 \begin[staffsize=26,verbatim]@{lilypond@}
1805 If you want to include large examples into the text, it is more
1806 convenient to put it in a separate file:
1808 \lilypondfile@{screech-boink.ly@}
1813 Under Unix, you can view the results as follows:
1817 $ lilypond-book --output=out/ lilybook.tex
1818 lilypond-book (GNU LilyPond) 2.1.19
1819 Reading `input/tutorial/lilybook.tex'
1820 Reading `input/screech-boink6.ly'
1821 @var{lots of stuff deleted}
1822 Writing `out/lilybook.latex'
1824 $ latex lilybook.latex
1825 @var{lots of stuff deleted}
1829 To convert the file into a nice PDF document, run the following
1832 $ dvips -Ppdf -u +lilypond lilybook
1833 $ ps2pdf lilybook.ps
1837 Running lilypond-book and running latex creates a lot of temporary
1838 files, and you would not want those to clutter up your working
1839 directory. The @code{outdir} option to lilypond-book creates the
1840 temporary files in a separate subdirectory @file{out}.
1842 The result looks more or less like this:
1846 In a lilypond-book document, you can freely mix music and text. For
1850 \notes \relative c' {
1851 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1859 If you have no @code{\score} block in the fragment,
1860 @code{lilypond-book} will supply one:
1866 In the example you see here, two things happened: a
1867 @code{score} block was added, and the line width was set to natural
1868 length. You can specify options by putting them in brackets:
1870 @lilypond[staffsize=26,verbatim]
1874 If you want to include large examples into the text, it is more
1875 convenient to put it in a separate file:
1877 @lilypondfile{screech-boink.ly}