2 @c This file is part of lilypond.tely
5 @c * more details about running lilypond; error messages,
6 @c compiling/viewing (emacs?)
7 @c * where to go from First steps+More basics?
9 @c Your first LilyPond score in 10 minutes?
14 This tutorial starts with a short introduction to the LilyPond music
15 language. After this first contact we will show you how to produce
16 printed output. Then you will be able to create and print your own
20 Many people learn programs by trying and fiddling around with the
21 program. This is also possible with LilyPond. If you click on a
22 picture in the HTML version of this manual, you will see the exact
23 LilyPond input that was used to generate that image.
26 @lilypond[quote,raggedright,relative=2]
27 c-\markup { \bold \huge { Click here. } }
31 By cutting and pasting the full input into a test file, you have a
32 starting template for experiments. If you like learning in this way,
33 you will probably want to print out or bookmark
37 @ref{Cheat sheet}, which is a table listing all commands for quick
43 * More about pitches::
45 * Automatic and manual beams::
47 * Music expressions explained::
49 * Adding articulation marks to notes::
50 * Combining notes into chords::
51 * Basic rhythmical commands::
52 * Commenting input files::
55 * Listening to output::
57 * Single staff polyphony::
59 * Organizing larger pieces::
60 * An orchestral part::
61 * Integrating text and music::
68 The first example demonstrates how to enter the most elementary piece
69 of music, a scale. A note can be entered by typing its name, from
70 @samp{a} through @samp{g}. So, if you enter
77 the result looks like this
79 @lilypond[quote,notime,relative=1]
83 The duration of a note is specified by a number after the note name.
84 @samp{1} for a @rglos{whole note}, @samp{2} for a @rglos{half note},
85 @samp{4} for a @rglos{quarter note} and so on
91 @c FIXME: have NOTIME also remove Score.timing?
92 @lilypond[quote,notime,relative=1]
93 \set Score.timing = ##f
94 \set Staff.autoBeaming = ##f
95 { a1 a2 a4 a16 a32 s16_" " }
98 If you do not specify a @rglos{duration}, the duration last entered is
99 used for the next notes. The duration of the first note in input
100 defaults to a quarter
106 @lilypond[quote,notime,relative=1]
107 \set Score.timing = ##f
108 { a a8 a a2 a s16_" " }
112 Rests are entered just like notes, but with the name @samp{r}
119 @lilypond[quote,notime]
120 \set Score.timing = ##f
124 Add a dot @samp{.} after the duration to get a @rglos{dotted note}
130 @lilypond[quote,notime,relative=1]
131 \set Score.timing = ##f
132 { a2. a4 a8. a16 s16_" " }
135 The @rglos{meter} (or @rglos{time signature}) can be set with the
144 @c A clef here may lead to confusion, remove it.
146 \override Staff.Clef #'transparent = ##t
155 The @rglos{clef} can be set using the @code{\clef} command
157 @c what is more common name treble or violin?
158 @c in Dutch, it is violin.
159 @c in English it is definitely treble.
167 @lilypond[quote,notime]
168 \set Score.timing = ##f
180 To recognize names like @samp{c} and @samp{d} as pitches, they have to
181 be entered inside a so-called @code{\notes} block. This block is
182 formed by enclosing notes and commands are enclosed in curly braces
183 @code{@{@tie{}@dots{}@tie{}@}} and adding the keyword @code{\notes} before
195 Now the piece of music is almost ready to be printed. Enclose
196 the @code{\notes} block in a @code{\score} block
210 and the music will be converted to printable output.
213 Remember to enclose the notes and commands in curly braces
214 @code{@{@tie{}@dots{}@tie{}@}} to convert it to printable output.
216 @lilypond[quote,noindent,linewidth=55\staffspace]
225 For more elaborate information on
229 @item Entering pitches and durations
231 @ref{Pitches}, and @ref{Durations}.
236 @item Time signatures and other timing commands
237 see @ref{Time signature}.
242 @node Running LilyPond
243 @section Running LilyPond
245 @c FIXME: let's not be so casual about Emacs and VIM, but rather
246 @c instruct (how) to use them; let advanced user figure-out what
250 @c We don't have enough space to explain either VIM
251 @c or Emacs non-advanced users, and I fear that both editors will only
252 @c confuse newbies. I vote for keeping the material in footnotes.
256 In the last section we explained what kind of things you could enter
257 in a LilyPond file. In this section we will explain what commands to
258 run and how to view or print the output. If you have not used
259 LilyPond before, want to test your setup, or want to run an example
260 file yourself, read this section. The instructions that follow are
261 for Unix-like systems. Some additional instructions for Microsoft
262 Windows are given at the end of this section.
264 Begin by opening a terminal window and starting a text editor. For
265 example, you could open an xterm and execute
266 @code{joe}.@footnote{There are macro files for VIM addicts, and there
267 is a @code{LilyPond-mode} for Emacs addicts. If it has not been
268 installed already, refer to
269 @c FIXME lousy reference.
270 the file @file{INSTALL.txt}.} In your text editor, enter the following
271 input and save the file as @file{test.ly}
278 To process @file{test.ly}, proceed as follows
285 You will see something resembling
288 lilypond (GNU LilyPond) 2.2.0
289 Running lilypond-bin...
290 Now processing `/home/fred/ly/test.ly'
292 Interpreting music...[1]
293 @emph{... more interesting stuff ... }
294 DVI output to `test.dvi'...
295 PDF output to `test.pdf'...
296 PS output to `test.ps'...
300 @cindex Viewing music
303 The result is the file @file{test.pdf}@footnote{For @TeX{}
304 aficionados: there is also a @file{test.dvi} file. It can be viewed
305 with @code{xdvi}. The DVI uses a lot of PostScript specials, which do
306 not show up in the magnifying glass. The specials also mean that the
307 DVI file cannot be processed with @code{dvilj}. Use @code{dvips} for
312 } which you can print or with the standard facilities of your
313 operating system.@footnote{If your system does not have any tools
314 installed, you can try @uref{Ghostscript,
315 http://www.cs.wisc.edu/~ghost/}, a freely available package for
316 viewing and printing PDF and PostScript files.}
318 On Windows, start up a text-editor@footnote{Any simple or
319 programmer-oriented editor will do, for example Notepad. Do not use a
320 word processor, its formatting codes will confuse LilyPond.} and enter
326 Save it on the desktop as @file{test.ly} and make sure that it is not
327 called @file{test.ly.TXT}. Double clicking @file{test.ly} will process
328 the file and show the resulting PDF file.
331 @node More about pitches
332 @section More about pitches
334 A @rglos{sharp} (@texisharp{}) pitch is made by adding @samp{is} to
335 the name, a @rglos{flat} (@texiflat{}) pitch by adding @samp{es}. As
336 you might expect, a @rglos{double sharp} or @rglos{double flat} is
337 made by adding @samp{isis} or @samp{eses}@footnote{This syntax
338 derived from note naming conventions in Nordic and Germanic languages,
339 like German and Dutch.}
345 @lilypond[quote,notime]
346 \set Score.timing = ##f
347 \transpose c c' { cis1 ees fisis aeses s16_" " }
350 @cindex key signature, setting
351 The key signature is set with the command @code{\key}, followed by
352 a pitch and @code{\major} or @code{\minor}
361 @lilypond[quote,notime,fragment]
369 Key signatures together with the pitches (including alterations) are
370 used to determine when to print accidentals. This is a
371 feature that often causes confusion to newcomers, so let us explain it
375 LilyPond makes a sharp distinction between musical content and
376 layout. The alteration (flat, natural or sharp) of a note is part of
377 the pitch, and is therefore musical content. Whether an accidental (a
378 flat, natural or sharp @emph{sign}) is printed in front of the
379 corresponding note is a question of layout. Layout is something that
380 follows rules, so accidentals are printed automatically according to
381 those rules. The pitches in your music are works of art, so they will
382 not be added automatically, and you must enter what you want to hear.
386 @lilypond[quote,notime,fragment]
392 no note gets an explicit accidental, but you still must enter
400 The code @samp{d} does not mean `print a black dot just below the
401 staff.' Rather, it means: `a note with pitch D-natural.' In the key
402 of A-flat, it does get an accidental
404 @lilypond[quote,notime,fragment]
414 Adding all alterations explicitly might require a little more effort
415 when typing, but the advantage is that transposing is easier, and
416 music can be printed according to different conventions. See
417 @ref{Accidentals}, for some examples how accidentals can be printed
418 according to different rules.
421 For more information on
426 see @ref{Accidentals}.
429 see @ref{Key signature}.
434 @section Entering ties
437 A tie is created by appending a tilde @samp{~} to the first note
440 @lilypond[quote,notime,fragment,verbatim,relative=3]
444 For more information on Ties see @ref{Ties}.
448 @node Automatic and manual beams
449 @section Automatic and manual beams
451 @cindex beams, by hand
452 Beams are drawn automatically
454 @lilypond[quote,fragment,relative=2,verbatim]
459 If you do not like where beams are put, they can be entered by
460 hand. Mark the first note to be beamed with @samp{[} and the last one
463 @lilypond[quote,fragment,relative=2,verbatim]
467 For more information on beams, see @ref{Beaming}.
470 Here are key signatures, accidentals and ties in action
479 fis4 fis8 fis8 eis4 a8 gis~
484 @c TODO: use relative mode, verbatim, junk \transpose and above @example
485 @lilypond[quote,noindent,linewidth=50\staffspace]
492 fis4 fis8 fis8 eis4 a8 gis~
499 There are some interesting points to note in this example. Bar lines
500 and beams are drawn automatically. Line breaks are calculated
501 automatically; it does not matter where the line breaks are in the
502 source file. Finally, the order in which time, key and clef changes
503 are entered is not relevant: in the printout, these are ordered
504 according to standard notation conventions.
509 @section Octave entry
512 @c Tim wants to move this quotes example just before the: quotes-do not-work
513 @c score, but we'd need to remove quotes from the other two (key and
516 @c better to have this just before the `octaves are bad' snipped
517 @c but we'd need to remove the ', from \key and tie
518 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
519 the note name, to lower a note one octave, add a `low quote' @code{,}
520 (a comma). Middle C is @code{c'}
523 c'4 c'' c''' \clef bass c c,
526 @lilypond[quote,notime,fragment]
527 c'4 c'' c''' \clef bass c c,
530 An example of the use of quotes is in the following Mozart fragment
532 @lilypond[quote,raggedright,fragment,verbatim]
535 cis''8. d''16 cis''8 e''4 e''8
536 b'8. cis''16 b'8 d''4 d''8
540 The last example shows that music in a high register needs lots of quotes.
541 This makes the input less readable, and it is a source of errors. The
542 solution is to use `relative octave' mode. In practice, this is the
543 most convenient way to copy existing music. To use relative mode, add
544 @code{\relative} before the piece of music.
546 FIXME: move to notation manual?
547 You must also give a note
548 from which relative mode starts, in this case @code{c''}.
551 use octavation quotes (i.e., do not add @code{'} or @code{,} after a
552 note), relative mode chooses the note that is closest to the previous
553 one. For example, @samp{c f} goes up while @samp{c g} goes down
555 @lilypond[quote,notime,fragment,verbatim]
562 Since most music has small intervals, pieces can be written almost
563 without octavation quotes in relative mode. The previous example is
566 @lilypond[quote,raggedright,fragment,verbatim]
570 cis''8. d16 cis8 e4 e8
575 @c needed better, maybe even redundant explanation
576 @c added another example below.
577 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
578 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
579 Larger intervals are made by adding octavation quotes.
581 @lilypond[quote,notime,verbatim,fragment]
587 In summary, quotes or commas no longer determine the absolute height
588 of a note in @code{\relative} mode. Rather, the height of a note is
589 relative to the previous one, and changing the octave of a single note
590 shifts all following notes an octave up or down.
592 For more information on Relative octaves see @ref{Relative octaves},
593 and @ref{Octave check}.
596 @node Music expressions explained
597 @section Music expressions explained
600 In input files, music is represent by so-called @emph{music
601 expression}. We have already seen in the previous examples;
602 a single note is a music expression
604 @lilypond[quote,verbatim,relative=3]
608 Enclosing group of notes in braces creates a new music
611 @lilypond[quote,verbatim,relative=3]
615 Putting a bunch of music expressions (notes) in braces, means that
616 they should be played in sequence. The result again is a music
617 expression, which can be grouped with other expressions sequentially.
618 Here, the expression from the previous example is combined with two
621 @lilypond[quote,verbatim,relative=3]
625 This technique is useful for non-monophonic music. To enter music
626 with more voices or more staves, we also combine expressions in
627 parallel. Two voices that should play at the same time, are entered
628 as a simultaneous combination of two sequences. A `simultaneous'
629 music expression is formed by enclosing expressions in @code{<<} and
630 @code{>>}. In the following example, three sequences (all containing
631 two notes) are combined simultaneously
633 @lilypond[quote,verbatim,relative=3]
641 This mechanism is similar to mathematical
642 formulas: a big formula is created by composing small formulas. Such
643 formulas are called expressions, and their definition is recursive, so
644 you can make arbitrarily complex and large expressions. For example,
653 ((1 + 2) * 3) / (4 * 5)
657 @cindex music expression
658 This example shows a sequence of expressions, where each expression is
659 contained in the next one. The simplest expressions are numbers and
660 operators (like @samp{+}, @samp{*} and @samp{/}). Parentheses are used
661 to group expressions.
663 Like mathematical expressions, music expressions can be nested
664 arbitrarily deep@footnote{The reason for getting three staves in the
665 previous example but just a single staff in current one will be explained
668 @lilypond[quote,verbatim,relative=2]
671 << { e f } { c <<b d>> } >>
677 When spreading expressions over multiple lines, it is customary to use
678 an indent that indicates the nesting level. Formatting music like this
679 eases reading, and helps you insert the right number of closing
680 braces at the end of an expression. For example,
700 Some editors have special support for entering LilyPond, and can help
701 indenting source files. See @ref{Editor support}, for more information.
706 To print more than one staff, each piece of music that makes up a
707 staff is marked by adding @code{\new Staff} before it. These
708 @code{Staff} elements are then combined parallel with @code{<<} and
709 @code{>>}, as demonstrated here
711 @lilypond[quote,fragment,verbatim]
713 \new Staff { \clef violin c'' }
714 \new Staff { \clef bass c }
719 The command @code{\new} introduces a `notation context.' A notation
720 context is an environment in which musical events (like notes or
721 @code{\clef} commands) are interpreted. For simple pieces, such
722 notation contexts are created implicitly. For more complex pieces, it
723 is best to mark contexts explicitly. This ensures that each fragment
726 There are several types of contexts: @code{Staff}, @code{Voice} and
727 @code{Score} handle normal music notation. Other contexts are also
728 @code{Lyrics} (for setting lyric texts) and @code{ChordNames} (for
729 printing chord names).
732 In terms of syntax, prepending @code{\new} to a music expression
733 creates a bigger music expression. In this way it resembles the minus
734 sign in mathematics. The formula @math{(4+5)} is an expression, so
735 @math{-(4+5)} is a bigger expression.
737 We can now typeset a melody with two staves
739 @c TODO: (c) status of this Paul McCartney (?) song (let's all stand together)
741 @lilypond[quote,verbatim,raggedright]
758 For more information on context see the description in
759 @ref{Interpretation contexts}.
763 @node Adding articulation marks to notes
764 @section Adding articulation marks to notes
770 Common accents can be added to a note using a dash (@samp{-}) and a
773 @lilypond[quote,verbatim,relative=2]
774 c-. c-- c-> c-^ c-+ c-_
778 Similarly, fingering indications can be added to a note using a dash
779 (@samp{-}) and the digit to be printed
781 @lilypond[quote,verbatim,relative=2]
786 Dynamic signs are made by adding the markings (with a backslash) to
789 @lilypond[quote,verbatim,relative=2]
797 Crescendi and decrescendi are started with the commands @code{\<} and
798 @code{\>}. An ending dynamic, for example @code{\f}, will finish the
799 crescendo, or the command @code{\!} can be used
801 @lilypond[quote,verbatim,relative=2]
809 A slur is a curve drawn across many notes, and indicates legato
810 articulation. The starting note and ending note are marked with
811 @samp{(} and @samp{)}, respectively
813 @lilypond[quote,fragment,relative=2,verbatim]
814 d4( c16)( cis d e c cis d e)( d4)
817 @cindex slurs versus ties
818 A slur looks like a tie, but it has a different meaning. A tie simply
819 makes the first note sound longer, and can only be used on pairs of
820 notes with the same pitch. Slurs indicate the articulations of notes,
821 and can be used on larger groups of notes. Slurs and ties are also
824 @lilypond[quote,fragment,relative=2]
825 c2~( c8 fis fis4 ~ fis2 g2)
828 @cindex phrasing slurs
829 Slurs to indicate phrasing can be entered with @code{\(} and
830 @code{\)}, so you can have both legato slurs and phrasing slurs at the
833 @lilypond[quote,fragment,relative=2,verbatim]
834 a8(\( ais b c) cis2 b'2 a4 cis, c\)
838 For more information on
843 see @ref{Fingering instructions}.
845 see @ref{Articulations}.
849 see @ref{Phrasing slurs}.
856 @node Combining notes into chords
857 @section Combining notes into chords
860 Chords can be made by surrounding pitches with angle brackets.
861 Angle brackets are the symbols @samp{<} and @samp{>}.
863 @lilypond[quote,relative=1,fragment,verbatim]
868 You can combine markings like beams and ties with chords. They must
869 be placed outside the angled brackets
871 @lilypond[quote,relative=1,fragment,verbatim]
872 r4 <c e g>8[ <c f a>]~ <c f a>
876 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
879 @lilypond[quote,relative=1,fragment]
881 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
887 @node Basic rhythmical commands
888 @section Basic rhythmical commands
892 @cindex partial measure
893 A pickup is entered with the keyword @code{\partial}. It
894 is followed by a duration: @code{\partial 4} is a quarter note upstep
895 and @code{\partial 8} an eighth note
897 @lilypond[quote,relative=2,verbatim,fragment]
904 Tuplets are made with the @code{\times} keyword. It takes two
905 arguments: a fraction and a piece of music. The duration of the piece
906 of music is multiplied by the fraction. Triplets make notes occupy
907 2/3 of their notated duration, so a triplet has 2/3 as its fraction
909 @lilypond[quote,relative=1,verbatim,fragment]
910 \times 2/3 { f8 g a }
916 Grace notes are also made by prefixing a music expression with the
917 keyword @code{\appoggiatura} or @code{\acciaccatura}
921 @lilypond[quote,relative=2,verbatim,fragment]
922 c4 \appoggiatura b16 c4
923 c4 \acciaccatura b16 c4
928 For more information on
933 see @ref{Grace notes},
937 see @ref{Partial measures}.
942 @node Commenting input files
943 @section Commenting input files
947 @cindex block comment
948 A comment is a remark for the human reader of the music input; it is
949 ignored and has no effect on the printed output. There are two types
950 of comments. The percent symbol @samp{%} introduces a line comment;
951 the rest of the line is ignored. A block comments marks a whole
952 section of music input---anything that is enclosed in @code{%@{} and
953 @code{%@}} is ignored. The following fragment shows possible uses for
957 % notes for twinkle twinkle follow
961 This line, and the notes below
962 are ignored, since they are in a
969 There is a special statement that really is a kind of comment. The
970 version statement marks for which version of LilyPond the file was
971 written. To mark a file for version 2.1.17, use
978 These annotations make future upgrades of LilyPond go more
979 smoothly. Changes in the syntax are handled with a special program,
980 @file{convert-ly} (see @ref{Invoking convert-ly}), and it uses
981 @code{\version} to determine what rules to apply.
984 @node Printing lyrics
985 @section Printing lyrics
988 @c TODO: (c) status of the Queen fragment.
992 Lyrics are entered by separating each syllable with a space
1000 @lilypond[quote,verbatim,fragment,raggedright]
1002 r4 c \times 2/3 { f g g }
1003 \times 2/3 { g4( a2) }
1007 @c FIXME: when/how/to what rename newlyrics?
1008 The lyrics can be set to these notes, combining both with the
1009 @code{\newlyrics} keyword
1011 @lilypond[quote,verbatim,fragment,raggedright]
1014 r4 c \times 2/3 { f g g }
1015 \times 2/3 { g4( a2) }
1017 \newlyrics { I want to break free }
1022 @cindex extender line
1024 This melody ends on a @rglos{melisma}, a single syllable (`free')
1025 sung to more than one note. This is indicated with an @emph{extender
1026 line}. It is entered as two underscores, i.e.,
1029 @{ I want to break free __ @}
1032 @lilypond[quote,raggedright]
1035 r4 c \times 2/3 { f g g }
1036 \times 2/3 { g4( a2) }
1038 \newlyrics { I want to break free __ }
1042 Similarly, hyphens between words can be entered as two dashes,
1043 resulting in a centered hyphen between two syllables
1046 Twin -- kle twin -- kle
1049 @lilypond[quote,raggedright]
1055 \newlyrics { Twin -- kle twin -- kle }
1059 More options, like putting multiple lines of lyrics below a melody are
1060 discussed in @ref{Vocal music}.
1062 @c FIXME: too geeky, for notation manual?
1063 @c or introduce using foo = \lyrics { a b c } ?
1065 When using variables for a piece of lyrics
1066 To prevent certain words (for example `as') as being read as a
1067 pitch, the input-mode must be switched. This is done with
1068 @code{\lyrics}. In @code{\lyrics} mode, all words are read as lyric
1072 myText = \lyrics @{ I want to break free @}
1076 The braces @code{@{@}} signify that the syllables are sung in
1080 By default, music expressions are interpreted in @code{Staff} context. For
1081 lyrics, this is obviously not desirable, so it is necessary
1082 to explicitly specify a @code{Lyrics} context,
1085 \lyrics @{ I want to break free @}
1088 The melody for this song is as follows
1090 @lilypond[quote,fragment,relative=2]
1091 r4 c \times 2/3 { f4 g g }
1092 \times 2/3 { g4( a2) }
1099 @section A lead sheet
1105 In popular music, it is common to denote accompaniment as chord names.
1106 Such chords can be entered like notes,
1113 but now, each pitch is read as the root of a chord instead of a note.
1114 This mode is switched on with @code{\chords}
1116 @lilypond[quote,verbatim,raggedright]
1117 \chords { c2 f4. g8 }
1120 Other chords can be created by adding modifiers after a colon. The
1121 following example shows a few common modifiers
1123 @lilypond[quote,verbatim]
1124 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1127 For lead sheets, chords are not printed on staves, but as names on a
1128 line of themselves. Hence, we have to override the context with
1129 @code{\new}, rendering the music expression in a @code{ChordNames}
1132 @lilypond[quote,verbatim]
1133 \new ChordNames \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1137 When put together, chord names, lyrics and a melody form
1138 a lead sheet, for example,
1142 \new ChordNames \chords @{ @emph{chords} @}
1144 \newlyrics @{ @emph{the text} @}
1149 @lilypond[quote,raggedright]
1151 \new ChordNames \chords { r2 c:sus4 f }
1153 r4 c' \times 2/3 { f g g }
1154 \times 2/3 { g4( a2) }
1156 \newlyrics { I want to break free __ }
1160 A complete list of modifiers and other options for layout can be found
1163 @c FIXME: we talk about \midi before mentioning \paper (or \layout?)
1164 @node Listening to output
1165 @section Listening to output
1170 MIDI (Musical Instrument Digital Interface) is a standard for
1171 connecting and controlling digital instruments. A MIDI file is like a
1172 tape recording of a MIDI instrument.
1174 To create a MIDI from a music piece of music, add a
1175 @code{\midi} block causes LilyPond to create a MIDI file, so you
1176 can listen to the music you entered. It is great for checking the
1177 music: octaves that are off or accidentals that were mistyped stand
1178 out very much when listening to the musical transcription.
1180 The @code{\midi} block is added to @code{\score}, for example,
1185 \midi @{ \tempo 4=72 @}
1189 Here, the tempo is specified using the @code{\tempo} command. In this
1190 case the tempo of quarter notes is set to 72 beats per minute. More
1191 information on auditory output in the notation manual can be found in
1194 If there is a @code{\midi} command in a @code{\score}, only MIDI will
1195 be produced. If notation is needed too, a @code{\paper} block must be
1201 \midi @{ \tempo 4=72 @}
1211 Bibliographic information is entered in a separate block, the
1212 @code{\header} block. The name of the piece, its composer, etc., are
1213 entered as an assignment, within @code{\header
1214 @{@tie{}@dots{}@tie{}@}}. The @code{\header} block is usually put at
1215 the top of the file. For example,
1219 title = "Eight miniatures"
1220 composer = "Igor Stravinsky"
1221 tagline = "small is beautiful"
1227 @cindex bibliographic information
1230 @cindex Engraved by LilyPond
1232 When the file is processed the title and composer are printed above
1233 the music. The `tagline' is a short line printed at bottom of the last
1234 page which normally says `Engraved by LilyPond, version @dots{}'. In
1235 the example above it is replaced by the line `small is
1236 beautiful.'@footnote{Nicely printed parts are good PR for us, so
1237 please leave the tagline if you can.}
1240 The @code{\header} block is usually put at the top of the file.
1242 A document may contains multiple pieces of music, examples are an
1243 etude book, or an orchestral part with multiple movements.
1244 @c FIXME: ugh. \header can only live at toplevel, or inside \score.
1245 @c If we allow it also to live inside \book, we do not need \score here?
1246 The @code{\book} block is used to group the individual @code{\score}
1249 The header for each piece of music can be put inside the @code{\score}
1250 block. The @code{piece} name from the header will be printed before
1253 @c FIXME: introduce \BOOK
1255 @c FIXME: Using "Adagio" as a name is confusing, it's more common to be
1256 @c a plain tempo indication.
1258 @cindex Engraved by LilyPond
1259 @cindex signature line
1264 title = "Eight miniatures"
1265 composer = "Igor Stravinsky"
1266 tagline = "small is beautiful"
1272 \header @{ piece = "Adagio" @}
1276 \header @{ piece = "Menuetto" @}
1281 More information on titling can be found in @ref{Invoking lilypond}.
1284 @node Single staff polyphony
1285 @section Single staff polyphony
1288 @cindex multiple voices
1289 @cindex voices, more -- on a staff
1290 When different melodic lines are combined on a single staff they are
1291 printed as polyphonic voices: each voice has its own stems, slurs and
1292 beams, and the top voice has the stems up, while the bottom voice has
1295 Entering such parts is done by entering each voice as a sequence (with
1296 @code{@{...@}}), and combining those simultaneously, separating the
1297 voices with @code{\\}
1299 @lilypond[quote,verbatim,relative=3]
1300 << { a4 g2 f4~ f4 } \\
1304 For polyphonic music typesetting, spacer rests can also be convenient: these
1305 are rests that do not print. It is useful for filling up voices that
1306 temporarily do not play. Here is the same example with a spacer rest
1307 instead of a normal rest---just use @samp{s} instead of @samp{r}
1309 @lilypond[quote,verbatim,relative=3]
1310 << { a4 g2 f4~ f4 } \\
1315 Again, these expressions can be nested arbitrarily
1317 @lilypond[quote,fragment,verbatim,relative=3]
1325 { <c, g>1 ~ <c g>4 } \\
1331 More features of polyphonic typesetting in the notation manual are
1332 described in @ref{Polyphony}.
1336 @section Piano staves
1338 @cindex staff switch, manual
1339 @cindex cross staff voice, manual
1340 @cindex @code{\context}
1341 Piano music is typeset in two staves connected by a brace. Printing
1342 such a staff is similar to the polyphonic example in @ref{More staves},
1345 << \new Staff @{ @dots{} @}
1346 \new Staff @{ @dots{} @} >>
1350 but now this entire expression must be interpreted as a
1354 \new PianoStaff << \new Staff @dots{} >>
1357 Here is a full-fledged example
1359 @lilypond[quote,verbatim,relative=1,fragment]
1361 \new Staff { \time 2/4 c4 c g' g }
1362 \new Staff { \clef bass c,, c' e c }
1366 More information on formatting piano music is in @ref{Piano music}.
1369 @node Organizing larger pieces
1370 @section Organizing larger pieces
1372 When all of the elements discussed earlier are combined to produce
1373 larger files, the @code{\score} blocks get a lot bigger, because the
1374 music expressions are longer, and, in the case of polyphonic pieces,
1375 more deeply nested. Such large expressions can become unwieldy.
1377 By using variables, also known as identifiers, it is possible to break
1378 up complex music expressions. An identifier is assigned as follows
1381 namedMusic = \notes @{ @dots{} @}
1385 The contents of the music expression @code{namedMusic}, can be used
1386 later by preceding the name with a backslash, i.e., @code{\namedMusic}.
1387 In the next example, a two-note motive is repeated two times by using
1388 variable substitution
1390 @lilypond[quote,raggedright,verbatim,nofragment]
1394 { \seufzer \seufzer }
1397 The name of an identifier should have alphabetic characters only;
1398 no numbers, underscores or dashes. The assignment should be outside of
1399 the @code{\score} block.
1401 It is possible to use variables for many other types of objects in the
1407 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1410 Depending on its contents, the identifier can be used in different
1411 places. The following example uses the above variables
1415 \notes @{ c4^\name @}
1423 More information on the possible uses of identifiers is in the
1424 technical manual, in TODO.
1427 @node An orchestral part
1428 @section An orchestral part
1430 In orchestral music, all notes are printed twice: in a part for
1431 the musicians, and in a full score for the conductor. Identifiers can
1432 be used to avoid double work: the music is entered once, and stored in
1433 a variable. The contents of that variable is then used to generate
1434 both the part and the score.
1436 It is convenient to define the notes in a special file. For example,
1437 suppose that the file @file{horn-music.ly} contains the following part
1438 of a horn/bassoon duo
1441 hornNotes = \notes \relative c @{
1448 Then, an individual part is made by putting the following in a file
1451 \include "horn-music.ly"
1453 instrument = "Horn in F"
1456 \notes \transpose f c' \hornNotes
1463 \include "horn-music.ly"
1467 substitutes the contents of @file{horn-music.ly} at this position in
1468 the file, so @code{hornNotes} is defined afterwards. The command
1469 @code{\transpose f@tie{}c'} indicates that the argument, being
1470 @code{\hornNotes}, should be transposed by a fifth downwards: sounding
1471 @samp{f} is denoted by notated @code{c'}, which corresponds with
1472 tuning of a normal French Horn in@tie{}F. The transposition can be seen
1473 in the following output
1475 @lilypond[quote,raggedright]
1477 \notes \transpose f c' \notes \relative c {
1484 In ensemble pieces, one of the voices often does not play for many
1485 measures. This is denoted by a special rest, the multi-measure
1486 rest. It is entered with a capital @samp{R} followed by a duration
1487 (1@tie{}for a whole note, 2@tie{}for a half note, etc.). By multiplying the
1488 duration, longer rests can be constructed. For example, this rest
1489 takes 3@tie{}measures in 2/4 time
1495 When printing the part, multi-rests
1496 must be condensed. This is done by setting a run-time variable
1499 \set Score.skipBars = ##t
1503 This command sets the property @code{skipBars} in the
1504 @code{Score} context to true (@code{##t}). Prepending the rest and
1505 this option to the music above, leads to the following result
1507 @lilypond[quote,raggedright]
1509 \notes \transpose f c' \relative c {
1511 \set Score.skipBars = ##t
1519 The score is made by combining all of the music in a @code{\score}
1520 block. Assuming that the other voice is in @code{bassoonNotes} in the
1521 file @file{bassoon-music.ly}, a score is made with
1524 \include "bassoon-music.ly"
1525 \include "horn-music.ly"
1529 \new Staff \hornNotes
1530 \new Staff \bassoonNotes
1538 @lilypond[quote,raggedright]
1540 \notes \relative c \simultaneous {
1547 r4 d,8 f | gis4 c | b bes |
1548 a8 e f4 | g d | gis f
1554 More in-depth information on preparing parts and scores can be found
1555 in the notation manual; see @ref{Orchestral music}.
1557 Setting run-time variables (`properties') is discussed in ref-TODO.
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
1566 Some texts include music examples. Examples are musicological
1567 treatises, songbooks or manuals like this. Such texts can be made by
1568 hand, simply by importing a PostScript figure into the word processor.
1569 However, there is an automated procedure to reduce the amount of work
1570 involved HTML, La@TeX{}, and Texinfo documents.
1572 A script called @code{lilypond-book} will extract the music fragments,
1573 run format them, and put back the resulting notation. This program is
1574 fully described in @ref{lilypond-book manual}. Here we show a small
1575 example. The example also contains explanatory text, so we will not
1576 comment on it further
1579 \documentclass[a4paper]@{article@}
1582 Documents for lilypond-book may freely mix music and text. For
1586 \score @{ \notes \relative c' @{
1587 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1591 If there is no \verb+\score+ block in the fragment,
1592 \texttt@{lilypond-book@} will supply one
1594 \begin[quote]@{lilypond@}
1599 In this example two things happened: a
1600 \verb+\score+ block was added, and the line width was set to natural
1603 Options are put in brackets.
1605 \begin[quote,staffsize=26,verbatim]@{lilypond@}
1609 Larger examples can be put in a separate file, and introduced with
1610 \verb+\lilypondfile+.
1612 \lilypondfile[quote,noindent]@{screech-boink.ly@}
1617 Under Unix, you can view the results as follows
1622 $ lilypond-book --output=out/ lilybook.tex
1623 lilypond-book (GNU LilyPond) 2.1.19
1624 Reading `input/tutorial/lilybook.tex'
1625 Reading `input/screech-boink.ly'
1626 @var{lots of stuff deleted}
1627 Writing `out/lilybook.tex'
1630 @var{lots of stuff deleted}
1634 To convert the file into a nice PDF document, run the following
1638 $ dvips -Ppdf -u +lilypond lilybook
1639 $ ps2pdf lilybook.ps
1642 Running lilypond-book and running latex creates a lot of temporary
1643 files, which would clutter up the working directory. To remedy this,
1644 use the @code{--output=@var{dir}} option. It will create the files in
1645 a separate subdirectory @file{dir}.
1647 Finally the result of the La@TeX{} example shown above.@footnote{Note
1648 that in this tutorial the example is processed with Texinfo. This gives
1649 slightly different results in layout.} This finishes the tutorial
1654 Documents for lilypond-book may freely mix music and text. For
1658 \score { \notes \relative c' {
1659 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1663 If there is no @code{\score} block in the fragment,
1664 @code{lilypond-book} will supply one
1671 In this example two things happened: a
1672 @code{score} block was added, and the line width was set to natural
1675 Options are put in brackets.
1677 @lilypond[quote,staffsize=26,verbatim]
1681 Larger examples can be put in a separate file, and introduced with
1682 @code{\lilypondfile}.
1684 @lilypondfile[quote,noindent]{screech-boink.ly}