3 @c This file is part of lilypond.tely
6 @c * more details about running lilypond; error messages,
7 @c compiling/viewing (emacs?)
8 @c * where to go from First steps+More basics?
15 Using LilyPond comes down to encoding music in an input file. After
16 entering the music, the program is run on the file producing output
17 which can be viewed or printed. In this tutorial, we will show step
18 by step how to enter such files, and illustrate the process with
19 fragments of input and the corresponding output. At the end of every
20 section, a paragraph will list where to find further information on
23 Many people learn programs by trying and fiddling around with the
24 program. This is also possible with LilyPond. If you click on a
25 picture in the HTML version of this manual, you will see the exact
26 LilyPond input that was used to generate that image.
28 For example, consider the following input:
30 c'^\markup @{ \bold \huge @{ Click on this image! @} @}
32 @c @lily pond[relative=1,raggedright,with the following output:]
33 with the following output:
34 @lilypond[relative=1,raggedright]
35 c'^\markup { \bold \huge { Click on this image! } }
39 By cutting and pasting the full input into a test file, you have a
40 starting template for experiments. If you like learning in this way,
41 you will probably want to print out or bookmark
45 @ref{Cheat sheet}, which is a table listing all commands for quick
49 This tutorial starts with a short introduction to the LilyPond music
50 language. After this first contact, we will show you how to to
51 produce printed output. You should then be able to create and print
52 your first sheets of music.
57 * More about pitches::
59 * Combining music into compound expressions::
60 * Adding articulation marks to notes::
61 * Combining notes into chords::
62 * Basic rhythmical commands::
63 * Commenting input files::
66 * Listening to output::
68 * Single staff polyphony::
71 * Fine tuning layout::
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 you get a note simply by typing its note name, from @samp{a}
83 through @samp{g}. So if you enter
90 then the result looks like this:
92 @lilypond[notime,relative]
96 The length of a note is specified by adding a number, @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 previous one is used:
116 \set Score.timing = ##f
117 \transpose c c' { a a a2 a s16_" " }
121 Rests are entered just like notes, but with the name ``@code{r}'':
130 \set Score.timing = ##f
131 \set Staff.Clef = \turnOff
132 \set Staff.TimeSignature = \turnOff
140 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
147 \set Score.timing = ##f
148 \transpose c c' { a2. a4 a8. a16 s16_" " }
152 The @rglos{meter} (or @rglos{time signature}) can be set with the
153 @code{\time} command:
161 @c a clef here may lead to confusion
163 \override Staff.Clef #'transparent = ##t
173 The @rglos{clef} can be set using the @code{\clef} command:
175 @c what is more common name treble or violin?
176 @c in Dutch, its violin.
177 @c in English its definitely treble.
186 \set Score.timing = ##f
197 Notes and commands like @code{\clef} and @code{\time}, are enclosed
198 in @code{\notes @{@dots{}@}}. This indicates that music (as opposed
199 to @rglos{lyrics}) follows:
209 Now the piece of music is almost ready to be printed. The final step is to
210 combine the music with a printing command.
212 The printing command is the so-called @code{\paper} block:
218 The @code{\paper} block is used to customize printing specifics. The
219 customization commands go between @code{@{} and @code{@}}, but for
220 now, we accept the defaults. The music and the @code{\paper} block
221 are combined by enclosing them in @code{\score @{ ... @}}, so the
222 following is a complete and valid input file:
245 linewidth = 55 * \staffspace
250 In the rest of the tutorial we will often leave out @code{\score}
251 and @code{\paper} for clarity. However, both must be present when
252 feeding the file to LilyPond.
254 For more elaborate information on
257 @item entering pitches and durations
259 @ref{Pitches} and @ref{Durations}.
262 @item Time signatures and other timing commands
263 see @ref{Time signature}.
266 @node Running LilyPond
267 @section Running LilyPond
269 In the last section we explained what kind of things you could enter
270 in a LilyPond file. In this section we explain what commands to run
271 and how to view or print the output. If you have not used LilyPond
272 before, want to test your setup, or want to run an example file
273 yourself, read this section. The instructions that follow are for
274 Unix-like systems. Some additional instructions for Microsoft Windows
275 are given at the end of this section.
277 Begin by opening a terminal window and starting a text editor. For
278 example, you could open an xterm and execute
279 @code{joe}.@footnote{There are macro files for VIM addicts, and there
280 is a @code{LilyPond-mode} for Emacs addicts. If it has not been
281 installed already, then refer to the file @file{INSTALL.txt}}. In
282 your text editor, enter the following input and save the file as
288 \notes @{ c'4 e' g' @}
293 To process @file{test.ly}, proceed as follows:
301 You will see something resembling:
306 Now processing: `/home/fred/ly/test.ly'
308 Interpreting music...[1]
309 @emph{ ... more interesting stuff ... }
310 PDF output to `test.pdf'...
311 DVI output to `test.dvi'...
315 @cindex Viewing music
318 The result is the file @file{test.pdf}.@footnote{For @TeX{}
319 afficionados: there is also a @file{test.dvi} file. It can be viewed
320 with @code{xdvi}. The DVI uses a lot of PostScript specials, which do
321 not show up in the magnifying glass. The specials also mean that the
322 DVI file cannot be processed with @code{dvilj}. Use @code{dvips} for
327 } One of the following commands should put the PDF on your
343 If the music on your screen looks good, you can print it by clicking
344 File/Print inside your viewing program.
348 @cindex Printing output
353 On Windows, the same procedure should work, the terminal is started by
354 clicking on the LilyPond or Cygwin icon. Any text editor (such as
355 NotePad, Emacs or Vim) may be used to edit the LilyPond file.
357 To view the PDF file, try the following:
360 If your system has a PDF viewer installed, open
361 @file{C:\Cygwin\home\@var{your-name}} in the explorer and double-click
364 If you prefer the keyboard, you can try to enter one of the commands
365 from the list shown before in the terminal. If none work, go to
366 @uref{http://www.cs.wisc.edu/~ghost/} to install the proper software.
369 The commands for formatting and printing music on all platforms are
370 detailed in @ref{Invoking LilyPond}.
372 @node More about pitches
373 @section More about pitches
375 A @rglos{sharp} (@texisharp{}) pitch is made by adding @samp{is} to
376 the name, a @rglos{flat} (@texiflat{}) pitch by adding @samp{es}. As
377 you might expect, a @rglos{double sharp} or @rglos{double flat} is
378 made by adding @samp{isis} or @samp{eses}:@footnote{This syntax
379 derived from note naming conventions in Nordic and Germanic languages,
380 like German and Dutch.}
387 \set Score.timing = ##f
388 \transpose c c' { cis1 ees fisis aeses s16_" " }
392 @cindex key signature, setting
394 The key signature is set with the command ``@code{\key}'', followed by
395 a pitch and @code{\major} or @code{\minor}:
405 \set Staff.TimeSignature = \turnOff
414 Key signatures together with the pitch (including alterations) are
415 used together to determine when to print accidentals. This is a
416 feature that often causes confusion to newcomers, so let us explain it
420 LilyPond has a sharp distinction between musical content and
421 layout. The alteration (flat, natural or sharp) of a note is part of
422 the pitch, and is therefore musical content. Whether an accidental (a
423 flat, natural or sharp @emph{sign}) is a printed in front of the
424 corresponding note is a question of layout. Layout is something that
425 follows rules, so accidentals are printed automatically according to
426 those rules. The pitches in your music are works of art, so they will
427 not be added automatically, and you must enter what you want to hear.
429 For example, in this example:
431 \set Staff.TimeSignature = \turnOff
437 no note gets an explicit accidental, but still you enter
444 The code @code{d} does not mean ``print a black dot just below the
445 staff.'' Rather, it means: ``a note with pitch D-natural.'' In the key
446 of A-flat, it gets an accidental:
449 \set Staff.TimeSignature = \turnOff
460 Adding all alterations explicitly might require some more effort when
461 typing, but the advantage is that transposing is easier, and music can
462 be printed according to different conventions. See @ref{Accidentals}
463 for some examples how accidentals can be printed according to
468 A tie is created by adding a tilde ``@code{~}'' to the first note
471 @lilypond[fragment,verbatim,relative=2]
477 This example shows the key signature, accidentals and ties in action:
488 fis4 fis8 fis8 eis4 a8 gis~
497 \notes { \transpose c c' {
503 fis4 fis8 fis8 eis4 a8 gis~
506 \paper { linewidth = #(* 50 staffspace) }
512 There are some interesting points to note in this example. Bar lines
513 and beams are drawn automatically. Line breaks are calculated
514 automatically; it does not matter where the lines breaks are in the
515 source file. Finally, the order of time, key and clef changes is not
516 relevant: in the printout, these are ordered according to standard
517 notation conventions.
520 @cindex beams, by hand
521 Beams are drawn automatically, but if you do not like where they are
522 put, they can be entered by hand. Mark the first note to be beamed
523 with @code{[} and the last one with @code{]}:
525 @lilypond[fragment,relative=1,verbatim]
531 For more information on
540 see @ref{Accidentals}
543 see @ref{Key signature}
551 @section Octave entry
554 @c Tim wants to move this quotes example just before the: quotes-do not-work
555 @c score, but we'd need to remove quotes from the other two (key and
558 @c better to have this just before the `octaves are bad' snipped
559 @c but we'd need to remove the ', from \key and tie
560 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
561 the note name, to lower a note one octave, add a ``low quote'' @code{,}
562 (a comma). Middle C is @code{c'}:
566 c'4 c'' c''' \clef bass c c,
570 \set Score.timing = ##f
571 \set Staff.TimeSignature = \turnOff
572 c'4 c'' c''' \clef bass c c,
577 An example of the use of quotes is in the following Mozart fragment:
578 @lilypond[raggedright,fragment,verbatim]
581 cis''8. d''16 cis''8 e''4 e''8
582 b'8. cis''16 b'8 d''4 d''8
585 This example shows that music in a high register needs lots of quotes.
586 This makes the input less readable, and it is a source of errors. The
587 solution is to use ``relative octave'' mode. In practice, this is the
588 most convenient way to copy existing music. To use relative mode, add
589 @code{\relative} before the piece of music. You must also give a note
590 from which relative starts, in this case @code{c''}. If you do not
591 use octavation quotes (i.e. do not add @code{'} or @code{,} after a
592 note), relative mode chooses the note that is closest to the previous
593 one. For example, @code{c f} goes up while @code{c g} goes down:
603 \set Score.timing = ##f
604 \set Staff.TimeSignature = \turnOff
613 Since most music has small intervals, pieces can be written almost
614 without octavation quotes in relative mode. The previous example is
617 @lilypond[raggedright,fragment,verbatim]
627 @c needed better, maybe even redundant explanation
628 @c added another example below.
629 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
630 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
631 Larger intervals are made by adding octavation quotes.
640 \set Score.timing = ##f
641 \set Staff.TimeSignature = \turnOff
649 Quotes or commas do not determine the absolute height of a note; the
650 height of a note is relative to the previous one.
651 @c do not use commas or quotes in this sentence
652 For example: @code{c f,} goes down; @code{f, f} are both the same;
653 @code{c' c} are the same; and @code{c g'} goes up:
657 Here is an example of the difference between relative mode and
658 ``normal'' (non-relative) mode:
669 \set Score.timing = ##f
670 \set Staff.TimeSignature = \turnOff
686 \set Score.timing = ##f
687 \set Staff.TimeSignature = \turnOff
695 For more information on Relative octaves see @ref{Relative octaves}
696 and @ref{Octave check}.
703 @node Combining music into compound expressions
704 @section Combining music into compound expressions
706 To print more than one staff, each piece of music that makes up a
707 staff is marked by adding @code{\context Staff} before it. These
708 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and
709 @code{@}}, as is demonstrated here:
712 @lilypond[fragment,verbatim]
714 \new Staff { \clef violin c'' }
715 \new Staff { \clef bass c }
721 In this example, @code{\simultaneous } indicates that both music
722 fragments happen at the same time, and must be printed stacked
723 vertically. The notation @code{<< .. >>} can also be used as a
724 shorthand for @code{\simultaneous @{ .. @}}.
726 The command @code{\new} introduces a ``notation context''. To
727 understand this concept, imagine that you are performing a piece of
728 music. When you are playing, you combine the symbols printed at a
729 certain point with contextual information. For example, without
730 knowing the current clef, and the accidentals in the last measure, it
731 would be impossible to determine the pitch of a note. In other words,
732 this information forms context that helps you decipher a
733 score. LilyPond produces notation from music, so in effect, it does
734 the inverse of reading scores. Therefore, it also needs to keep track
735 of contextual information. This information is maintained in
736 ``notation contexts.'' There are several types of contexts,
737 e.g. @code{Staff}, @code{Voice} and @code{Score}, but also
738 @code{Lyrics} and @code{ChordNames}. Prepending @code{\new} to a chunk
739 of music indicates what kind of context to use for interpreting it,
740 and ensures that the argument is interpreted with a fresh instance of
741 the context indicated.
746 We can now typeset a melody with two staves:
749 @lilypond[verbatim,raggedright]
770 The example shows how small chunks of music, for example, the notes
771 @code{c2}, @code{e4}, etc. of the second staff, are combined to form a
772 larger chunk by enclosing it in braces. Again, a larger chunk is
773 formed by prefix @code{\new Staff} to it, and that chunk is combined
774 with @code{<< >>}. This mechanism is similar with mathematical
775 formulas: a big formula is created by composing small formulas. Such
776 formulas are called expressions, and their definition is recursive, so
777 you can make arbitrarily complex and large expressions. For example,
786 ((1 + 2) * 3) / (4 * 5)
789 @cindex music expression
790 This example shows a sequence of expressions, where each expression is
791 contained in the next one. The simplest expressions are numbers and
792 operators (like +, * and /). Parentheses are used to group
793 expressions. In LilyPond input, a similar mechanism is used. Here,
794 the simplest expressions are notes and rests. By enclosing
795 expressions in @code{<< >>} and @code{@{ @}}, more complex music is
796 formed. The @code{\new} command also forms new expressions; prepending
797 it to a music expression yields a new expression.
799 Like mathematical expressions, music expressions can be nested
800 arbitrarily deep, e.g.
801 @lilypond[verbatim,relative=1]
803 << { e f } { c <<b d>> }
810 When spreading expressions over multiple lines, it is customary to use
811 an indent that indicates the nesting level. Formatting music like this
812 eases reading, and helps you insert the right amount of closing
813 braces at the end of an expression. For example,
828 For more information on context see the Technical manual description
829 in @ref{Interpretation context}.
833 @node Adding articulation marks to notes
834 @section Adding articulation marks to notes
840 Common accents can be added to a note using a dash (`@code{-}') and a
843 @lilypond[verbatim,relative=1]
844 c-. c-- c-> c-^ c-+ c-_
850 Similarly, fingering indications can be added to a note using a dash
851 (`@code{-}') and the digit to be printed:
853 @lilypond[verbatim,relative=1]
858 Dynamic signs are made by adding the markings to the note:
860 @lilypond[verbatim,relative=1]
870 Crescendi and decrescendi are started with the commands @code{\<} and
871 @code{\>}. The command @code{\!} finishes a crescendo on the note it
874 @lilypond[verbatim,relative=1]
875 c2\< c2\!\ff\> c2 c2\!
884 A slur is drawn across many notes, and indicates bound articulation
885 (legato). The starting note and ending note are marked with a
886 ``@code{(}'' and a ``@code{)}'' respectively:
889 @lilypond[fragment,relative=1,verbatim]
890 d4( c16)( cis d e c cis d e)( d4)
894 @cindex slurs versus ties
895 A slur looks like a tie, but it has a different meaning. A tie simply
896 makes the first note sound longer, and can only be used on pairs of
897 notes with the same pitch. Slurs indicate the articulations of notes,
898 and can be used on larger groups of notes. Slurs and ties are also
901 @lilypond[fragment,relative=1]
902 c2~( c8 fis fis4 ~ fis2 g2)
905 @cindex phrasing slurs
906 If you need two slurs at the same time (one for articulation, one for
907 phrasing), you can also make a phrasing slur with @code{\(} and
911 @lilypond[fragment,relative=1,verbatim]
912 a8(\( ais b c) cis2 b'2 a4 cis, c\)
917 For more information on
920 see @ref{Fingering instructions}
922 see @ref{Articulations}
926 see @ref{Phrasing slurs}
932 @node Combining notes into chords
933 @section Combining notes into chords
936 Chords can be made by
937 surrounding pitches with @code{<} and @code{>}:
939 @lilypond[relative,fragment,verbatim]
946 You can combine beams and ties with chords. Beam and tie markings
947 must be placed outside the chord markers:
949 @lilypond[relative,fragment,verbatim]
950 r4 <c e g>8[ <c f a>]~ <c f a>
956 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
958 @lilypond[relative,fragment]
960 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
968 @node Basic rhythmical commands
969 @section Basic rhythmical commands
974 @cindex partial measure
975 A pickup (or upstep) is entered with the keyword @code{\partial}. It
976 is followed by a duration: @code{\partial 4} is a quarter note upstep
977 and @code{\partial 8} an eighth note:
978 @lilypond[relative=1,verbatim,fragment]
985 Tuplets are made with the @code{\times} keyword. It takes two
986 arguments: a fraction and a piece of music. The duration of the piece
987 of music is multiplied by the fraction. Triplets make notes occupy
988 2/3 of their notated duration, so a triplet has 2/3 as its fraction:
990 @lilypond[relative,verbatim,fragment]
991 \times 2/3 { f8 g a }
997 Grace notes are also made by prefixing a note, or a set of notes with
998 a keyword. In this case, the keywords are @code{\appoggiatura}
999 and @code{\acciaccatura}
1000 @cindex appoggiatura
1001 @cindex acciaccatura
1003 @lilypond[relative=1,verbatim,fragment]
1004 c4 \appoggiatura b16 c4
1005 c4 \acciaccatura b16 c4
1010 For more information on
1013 see @ref{Grace notes},
1017 see @ref{Partial measures}.
1022 @node Commenting input files
1023 @section Commenting input files
1026 @cindex line comment
1027 @cindex block comment
1028 Comments are pieces of the input that are ignored. There are two
1029 types of comments. A line comments is introduced by @code{%}: after
1030 that, the rest of that line is ignored. Block comments span larger
1031 sections of input. Anything that is enclosed in @code{%@{} and
1032 @code{%@}} is ignored too. The following fragment shows possible uses
1036 % notes for twinkle twinkle follow:
1041 This line, and the notes below
1042 are ignored, since they are in a
1052 @node Printing lyrics
1053 @section Printing lyrics
1058 Lyrics are entered by separating each syllable with a space, and
1059 surrounding them with @code{\lyrics @{ @dots{} @}}, for example,
1061 \lyrics @{ I want to break free @}
1064 Like notes, lyrics are also a form of music, but they must not be
1065 printed on a staff, which is the default way to print music. To print
1066 them as lyrics, they must be marked with @code{ \new Lyrics}:
1068 \new Lyrics \lyrics @{ I want to break free @}
1070 The melody for this song is as follows:
1072 @lilypond[fragment,relative=1]
1075 \times 2/3 { f4 g g } \times 2/3 { g4( a2) }
1078 The lyrics can be set to these notes, combining both with the
1079 @code{\lyricsto} keyword:
1081 \lyricsto "@var{name}" \new Lyrics @dots{}
1083 where @var{name} identifies to which melody the lyrics should be
1084 aligned. In this case, there is only one melody, so we can leave it
1088 @lilypond[verbatim,fragment]
1091 \relative c' \new Voice {
1094 \times 2/3 { f g g } \times 2/3 { g4( a2) }
1096 \lyricsto "" \new Lyrics \lyrics { I want to break free }
1103 @cindex extender line
1105 This melody ends on a @rglos{melisma}, a single syllable (``free'')
1106 sung to more than one note. This is indicated with an @emph{extender
1107 line}. It is entered as two underscores, i.e.
1109 \lyrics @{ I want to break free __ @}
1111 @lilypond[raggedright]
1114 \relative c' \new Voice {
1117 \times 2/3 { f g g } \times 2/3 { g4( a2) } }
1118 \lyricsto "" \new Lyrics \lyrics { I want to break free __ }
1124 Similarly, hyphens between words can be entered as two dashes,
1125 resulting in a centered hyphen between two syllables:
1127 Twin -- kle twin -- kle
1129 @lilypond[raggedright]
1131 << \notes \relative f' { \time 2/4
1133 \new Lyrics \lyrics { Twin -- kle twin -- kle }
1135 \paper { raggedright = ##t }
1139 More options, like putting multiple lines of lyrics below a melody are
1140 discussed in @ref{Vocal music}.
1145 @section A lead sheet
1151 In popular music, it is common to denote accompaniment as chord-names.
1152 Using them in LilyPond has two parts, just like lyrics: entering the
1153 chords (with @code{\chords}), and printing them (with @code{\new
1156 Chord names are entered by starting chords mode (with @code{\chords}).
1157 In chords mode, you can enter chords with a letter (indicating the
1158 root of the chord), and a durations following that:
1161 \chords { c2 f4. g8 }
1165 The result of @code{\chords} is a list of chords, and is equivalent
1166 to entering chords with @code{<@dots{}>}.
1168 Other chords can be created by adding modifiers, after a colon. The
1169 following example shows a few common modifiers:
1172 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1175 Printing chords is done by adding @code{\context ChordNames}
1176 before the chords thus entered:
1179 \context ChordNames \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1184 When put together, chord names, lyrics and a melody form
1185 a lead sheet, for example,
1190 \context ChordNames \chords @{ @emph{chords} @}
1191 \notes @emph{the melody}
1192 \lyricsto "" \new Lyrics \lyrics @{ @emph{the text} @}
1200 \context ChordNames \chords { r8 c2:sus4 f }
1201 \notes \relative c' {
1204 \times 2/3 { f g g } \times 2/3 { g4( a2) } }
1205 \new Lyrics \lyricsto "" \lyrics { I want to break free __ }
1207 \paper{ raggedright = ##t }
1212 A complete list of modifiers, and other options for layout are in the
1213 reference manual section @ref{Chords}.
1215 @node Listening to output
1216 @section Listening to output
1221 MIDI (Musical Instrument Digital Interface) is a standard for
1222 connecting and recording digital instruments. A MIDI file is like a
1223 tape recording of a MIDI instrument. The @code{\midi} block makes the
1224 music go to a MIDI file, so you can listen to the music you entered.
1225 It is great for checking the music: octaves that are off, or
1226 accidentals that were mistyped, stand out very much when listening to
1227 the musical transcription.
1229 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
1234 \midi @{ \tempo 4=72 @}
1239 Here, the tempo is specified using the @code{\tempo} command. In this
1240 case the tempo of quarter notes is set to 72 beats per minute. More
1241 information on auditory output is in the @ref{Sound} section in the
1249 Bibliographic information is entered in a separate block, the
1250 @code{\header} block. The name of the piece, its composer, etc. are
1251 entered as an assignment, within @code{\header @{ @dots{} @}}. For
1255 title = "Eight miniatures"
1256 composer = "Igor Stravinsky"
1257 tagline = "small is beautiful"
1260 \score @{ @dots{} @}
1263 @cindex bibliographic information
1266 @cindex Engraved by LilyPond
1268 When the file is processed by the @code{lilypond} wrapper script, then
1269 the title and composer specified are printed above the music. The
1270 `tagline' is a short line printed at bottom of the last page, which
1271 normally says ``Engraved by LilyPond, version @dots{}''. In the
1272 example above, it is replaced by the line ``small is
1273 beautiful.''@footnote{Nicely printed parts are good PR for us, so do
1274 us a favor, and leave the tagline if you can.}
1276 Normally, the @code{\header} is put at the top of the file. However,
1277 for a document that contains multiple pieces (e.g. an etude book, or
1278 an orchestral part with multiple movements), then the header can be
1279 put into the @code{\score} block as follows; in this case, the name of
1280 each piece will be printed before each movement:
1283 @cindex Engraved by LilyPond
1284 @cindex signature line
1289 title = "Eight miniatures"
1290 composer = "Igor Stravinsky"
1291 tagline = "small is beautiful"
1295 \header @{ piece = "Adagio" @}
1298 \header @{ piece = "Menuetto" @}
1302 More information on titling can be found in @ref{Invoking lilypond}.
1305 @node Single staff polyphony
1306 @section Single staff polyphony
1309 @cindex multiple voices
1310 @cindex voices, more -- on a staff
1312 When different melodic lines are combined on a single staff, these are
1313 printed as polyphonic voices: each voice has its own stems, slurs and
1314 beams, and the top voice has the stems up, while the bottom voice has
1317 Entering such parts is done by entering each voice as a sequence (with
1318 @code{@{ .. @}}), and combining those simultaneously, separating the
1319 voices with @code{\\}:
1322 << @{ a4 g2 f4~ f4 @} \\
1323 @{ r4 g4 f2 f4 @} >>
1325 @lilypond[relative=1]
1326 \context Staff << { a4 g2 f4~ f4 } \\
1330 For polyphonic music typesetting, spacer rests can also be convenient: these
1331 are rests that do not print. It is useful for filling up voices that
1332 temporarily do not play:
1334 << @{ a4 g2 f4~ f4 @} \\
1335 @{ s4 g4 f2 f4 @} >>
1337 @lilypond[relative=1]
1338 \context Staff << { a4 g2 f4~ f4 } \\
1342 Again, these expressions can be nested arbitrarily:
1348 << { a4 g2 f4~ f4 } \\
1351 << { \clef bass <c g>1 ~ <c g>4 } \\
1358 More features of polyphonic typesetting are in the notation manual
1362 @section Piano staves
1364 @cindex staff switch, manual
1365 @cindex cross staff voice, manual
1366 @cindex @code{\translator}
1368 Piano music is always typeset in two staves connected by a brace.
1369 Printing such a staff is done similar to the polyphonic example in
1370 @ref{Combining music into compound expressions}:
1372 << \new Staff @{ @dots{} @}
1373 \new Staff @{ @dots{} @}
1376 but now this entire expression must be interpreted as a
1379 \new PianoStaff << \new Staff @dots{} >>
1382 Here is a full-fledged example:
1384 @lilypond[relative,fragment]
1386 << \new Staff { \time 2/4
1389 \clef bass c,, c' e c }
1393 More information on formatting piano music is in @ref{Piano music}.
1395 @node Setting variables
1396 @section Setting variables
1398 When the music is converted from notes to print, it is interpreted
1399 from left-to-right order, similar to what happens when we read
1400 music. During this step, context-sensitive information, such as the
1401 accidentals to print, and where barlines must be placed, are stored in
1402 variables. These variables are called @emph{context properties}.
1403 The properties can also be manipulated from input files. Consider this input:
1405 \set Staff.autoBeaming = ##f
1409 It sets the property named @code{autoBeaming} in the current staff at
1410 this point in the music to @code{##f}, which means `false'. This
1411 property controls whether beams are printed automatically:
1413 @lilypond[relative=1,fragment,verbatim]
1415 \set Staff.autoBeaming = ##f
1420 LilyPond includes a built-in programming language, namely, a dialect
1421 of Scheme. The argument to @code{\property}, @code{##f}, is an
1422 expression in that language. The first hash-mark signals that a piece
1423 of Scheme code follows. The second hash character is part of the
1424 boolean value true (@code{#t}). Values of other types may be
1427 @item a string, enclosed in double quotes, for example,
1429 \set Staff.instrument = #"French Horn"
1431 @item a boolean: either @code{#t} or @code{#f}, for true and false
1434 \set autoBeaming = ##f
1435 \set Score.skipBars = ##t
1438 @item a number, such as
1440 \set Score.currentBarNumber = #20
1443 @item a symbol, which is introduced by a quote character, as in
1445 \set Staff.crescendoSpanner = #'dashed-line
1448 @item a pair, which is also introduced by a quote character, like in
1449 the following statements, which set properties to the pairs (-7.5, 6)
1450 and (3, 4) respectively:
1453 \set Staff.minimumVerticalExtent = #'(-7.5 . 6)
1454 \set Staff.timeSignatureFraction = #'(3 . 4)
1457 @item a list, which is also introduced by a quote character. In the
1458 following example, the @code{breakAlignOrder} property is set to a
1461 \set Score.breakAlignOrder =
1462 #'(left-edge time-signature key-signatures)
1468 There are many different properties, and not all of them are listed in
1469 this manual. However, the program reference lists them all in the
1470 section @internalsref{Context-properties}, and most properties are
1471 demonstrated in one of the
1473 @uref{../../../input/test/out-www/collated-files.html,tips-and-tricks}
1481 @node Fine tuning layout
1482 @section Fine tuning layout
1484 Sometimes it is necessary to change music layout by hand. When music
1485 is formatted, layout objects are created for each symbol. For
1486 example, every clef and every note head is represented by a layout
1487 object. These layout objects also carry variables, which we call
1488 @emph{layout properties}. By changing these variables from their
1489 values, we can alter the look of a formatted score:
1491 @lilypond[verbatim,relative]
1493 \override Stem #'thickness = #3.0
1498 In the example shown here, the layout property @code{thickness} (a
1499 symbol) is set to 3 in the @code{Stem} layout objects of the current
1500 As a result, the notes following @code{\property} have thicker
1503 In most cases of manual overrides, only a single object must be
1504 changed. This can be achieved by prefixing @code{\once} to the
1505 @code{\property} statement, i.e.
1508 \once \override Stem #'thickness = #3.0
1513 \once \override Stem #'thickness = #3.0
1518 Some overrides are so common that predefined commands are provided as
1519 a short cut. For example, @code{\slurUp} and @code{\stemDown}. These
1520 commands are described in
1524 @ref{Notation manual}, under the sections for slurs and stems
1527 The exact tuning possibilities for each type of layout object are
1528 documented in the program reference of the respective
1529 object. However, many layout objects share properties, which can be
1530 used to apply generic tweaks. We mention a couple of these:
1533 @item The @code{extra-offset} property, which
1534 @cindex @code{extra-offset}
1535 has a pair of numbers as value, moves around objects in the printout.
1536 The first number controls left-right movement; a positive number will
1537 move the object to the right. The second number controls up-down
1538 movement; a positive number will move it higher. The unit of these
1539 offsets are staff-spaces. The @code{extra-offset} property is a
1540 low-level feature: the formatting engine is completely oblivious to
1543 In the following example, the second fingering is moved a little to
1544 the left, and 1.8 staff space downwards:
1546 @cindex setting object properties
1548 @lilypond[relative=1,verbatim]
1551 \once \override Fingering
1552 #'extra-offset = #'(-0.3 . -1.8)
1557 Setting the @code{transparent} property will make an object be printed
1558 in `invisible ink': the object is not printed, but all its other
1559 behavior is retained. The object still takes space, it takes part in
1560 collisions, and slurs, ties and beams can be attached to it.
1562 @cindex transparent objects
1563 @cindex removing objects
1564 @cindex invisible objects
1565 The following example demonstrates how to connect different voices
1566 using ties. Normally ties only happen between notes of the same
1567 voice. By introducing a tie in a different voice, and blanking a stem
1568 in that voice, the tie appears to cross voices:
1570 @lilypond[fragment,relative=1,verbatim]
1572 \once \override Stem #'transparent = ##t
1580 The @code{padding} property for objects with
1581 @cindex @code{padding}
1582 @code{side-position-interface} can be set to increase distance between
1583 symbols that are printed above or below notes. We only give an
1584 example; a more elaborate explanation is in @ref{Constructing a
1587 @lilypond[relative=1,verbatim]
1589 \override Script #'padding = #3
1595 More specific overrides are also possible. The notation manual
1596 discusses in depth how to figure out these statements for yourself, in
1597 @ref{Tuning output}.
1599 @node Organizing larger pieces
1600 @section Organizing larger pieces
1602 When all of the elements discussed earlier are combined to produce
1603 larger files, the @code{\score} blocks get a lot bigger, because the
1604 music expressions are longer, and, in the case of polyphonic and/or
1605 orchestral pieces, more deeply nested. Such large expressions can
1608 By using variables, also known as identifiers, it is possible to break
1609 up complex music expressions. An identifier is assigned as follows:
1612 namedMusic = \notes @{ @dots{}
1615 The contents of the music expression @code{namedMusic}, can be used
1616 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1617 In the next example, a two note motive is repeated two times by using
1618 variable substitution:
1620 @lilypond[raggedright,verbatim]
1629 The name of an identifier should have alphabetic characters only, and
1630 no numbers, underscores or dashes. The assignment should be outside of
1631 the @code{\score} block.
1633 It is possible to use variables for many other types of objects in the
1638 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1640 Depending on its contents, the identifier can be used in different
1641 places. The following example uses the above variables:
1644 \notes @{ c4^\name @}
1652 More information on the possible uses of identifiers is in the
1653 technical manual, in @ref{Scheme datatypes}.
1656 @node An orchestral part
1657 @section An orchestral part
1659 In orchestral music, all notes are printed twice: both in a part for
1660 the musicians, and in a full score for the conductor. Identifiers can
1661 be used to avoid double work: the music is entered once, and stored in
1662 variable. The contents of that variable is then used to generate
1663 both the part and the score.
1665 It is convenient to define the notes in a special file, for example,
1666 suppose that the @file{horn-music.ly} contains the following part of a
1669 hornNotes = \notes \relative c @{
1675 Then, an individual part is made by putting the following in a file:
1677 \include "horn-music.lyinc"
1679 instrument = "Horn in F"
1682 \notes \transpose f c' \hornNotes
1685 The @code{\include} command substitutes the contents of the file at
1686 this position in the file, so that @code{hornNotes} is defined
1687 afterwards. The code @code{\transpose f c'} indicates that the
1688 argument, being @code{\hornNotes}, should be transposed by a fifth
1689 downwards: sounding @code{f} is denoted by notated @code{c'}, which
1690 corresponds with tuning of a normal French Horn in F. The
1691 transposition can be seen in the following output:
1693 @lilypond[raggedright]
1695 \notes \transpose f c' \notes \relative c {
1702 In ensemble pieces, one of the voices often does not play for many
1703 measures. This is denoted by a special rest, the multi-measure
1704 rest. It is entered with a capital R, and followed by a duration (1
1705 for a whole note, 2 for a half note, etc.) By multiplying the
1706 duration, longer rests can be constructed. For example, the next rest
1707 takes 3 measures in 2/4 time:
1712 When printing the part, the following @code{skipBars} property must be
1713 set to false, to prevent the rest from being expanded in three one bar
1716 \set Score.skipBars = ##t
1718 Prepending the rest and the property setting above, leads to the
1721 @lilypond[raggedright]
1722 \score {\notes { \transpose f c' \relative c { \time 2/4
1723 \set Score.skipBars = ##t
1725 r4 f8 a cis4 f e d } }}
1728 The score is made by combining all of the music in a @code{\score}
1729 block, assuming that the other voice is in @code{bassoonNotes}, in the
1730 file @file{bassoon-music.ly}:
1732 \include "bassoon-music.lyinc"
1733 \include "horn-music.lyinc"
1737 \new Staff \hornNotes
1738 \new Staff \bassoonNotes
1742 This would lead to the simple score depicted below:
1744 @lilypond[raggedright]
1746 \notes \relative c \simultaneous {
1747 \new Staff { \time 2/4
1749 r4 f8 a cis4 f e d }
1750 \new Staff { \clef bass
1751 r4 d,8 f | gis4 c | b bes |
1752 a8 e f4 | g d | gis f }
1756 More in-depth information on preparing parts and scores is in the
1757 notation manual, in @ref{Orchestral music}.
1760 @node Integrating text and music
1761 @section Integrating text and music
1763 @cindex La@TeX{}, music in
1764 @cindex HTML, music in
1765 @cindex Texinfo, music in
1767 Sometimes you might want to use music examples in a text that you are
1768 writing (for example, a musicological treatise, a songbook, or (like us)
1769 the LilyPond manual). You can make such texts by hand, simply by
1770 importing a PostScript figure into your word processor. However,
1771 there is an automated procedure to reduce the amount of work.
1773 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1774 code. A script called @code{lilypond-book} will extract the music
1775 fragments, run LilyPond on them, and put back the resulting notation.
1776 This program is fully described in @ref{lilypond-book manual}. Here
1777 we show a small example. The example contains also explanatory text,
1778 so we will not comment it further:
1781 \documentclass[a4paper]@{article@}
1784 In a lilypond-book document, you can freely mix music and text. For
1787 \score @{ \notes \relative c' @{
1788 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1792 If you have no \verb+\score+ block in the fragment,
1793 \texttt@{lilypond-book@} will supply one:
1799 In the example you see here, two things happened: a
1800 \verb+\score+ block was added, and the line width was set to natural
1801 length. You can specify options by putting them in brackets:
1803 \begin[staffsize=26,verbatim]@{lilypond@}
1807 If you want to include large examples into the text, it is more
1808 convenient to put it in a separate file:
1810 \lilypondfile@{screech-boink.ly@}
1815 Under Unix, you can view the results as follows:
1819 $ lilypond-book --output=out/ lilybook.tex
1820 lilypond-book (GNU LilyPond) 2.1.19
1821 Reading `input/tutorial/lilybook.tex'
1822 Reading `input/screech-boink.ly'
1823 @var{lots of stuff deleted}
1824 Writing `out/lilybook.latex'
1826 $ latex lilybook.latex
1827 @var{lots of stuff deleted}
1831 To convert the file into a nice PDF document, run the following
1834 $ dvips -Ppdf -u +lilypond lilybook
1835 $ ps2pdf lilybook.ps
1839 Running lilypond-book and running latex creates a lot of temporary
1840 files, and you would not want those to clutter up your working
1841 directory. The @code{outdir} option to lilypond-book creates the
1842 temporary files in a separate subdirectory @file{out}.
1844 The result looks more or less like this:
1848 In a lilypond-book document, you can freely mix music and text. For
1852 \notes \relative c' {
1853 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1861 If you have no @code{\score} block in the fragment,
1862 @code{lilypond-book} will supply one:
1868 In the example you see here, two things happened: a
1869 @code{score} block was added, and the line width was set to natural
1870 length. You can specify options by putting them in brackets:
1872 @lilypond[staffsize=26,verbatim]
1876 If you want to include large examples into the text, it is more
1877 convenient to put it in a separate file:
1879 @lilypondfile{screech-boink.ly}