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[fragment,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[fragment,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[fragment,quote,notime,relative=2]
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[fragment,quote,notime,relative=2]
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[fragment,quote,notime]
120 \set Score.timing = ##f
124 Add a dot @samp{.} after the duration to get a @rglos{dotted note}
130 @lilypond[fragment,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.
145 @lilypond[fragment,quote]
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[fragment,quote,notime]
168 \set Score.timing = ##f
180 Remember to enclose the notes and commands in curly braces
181 @code{@{@tie{}@dots{}@tie{}@}} to convert it to printable output.
183 @lilypond[fragment,quote,noindent,linewidth=55\staffspace]
192 For more elaborate information on
196 @item Entering pitches and durations
198 @ref{Pitches}, and @ref{Durations}.
203 @item Time signatures and other timing commands
204 see @ref{Time signature}.
209 @node Running LilyPond
210 @section Running LilyPond
212 @c FIXME: let's not be so casual about Emacs and VIM, but rather
213 @c instruct (how) to use them; let advanced user figure-out what
217 @c We don't have enough space to explain either VIM
218 @c or Emacs non-advanced users, and I fear that both editors will only
219 @c confuse newbies. I vote for keeping the material in footnotes.
223 In the last section we explained what kind of things you could enter
224 in a LilyPond file. In this section we will explain what commands to
225 run and how to view or print the output. If you have not used
226 LilyPond before, want to test your setup, or want to run an example
227 file yourself, read this section. The instructions that follow are
228 for Unix-like systems. Some additional instructions for Microsoft
229 Windows are given at the end of this section.
231 Begin by opening a terminal window and starting a text editor. For
232 example, you could open an xterm and execute
233 @code{joe}.@footnote{There are macro files for VIM addicts, and there
234 is a @code{LilyPond-mode} for Emacs addicts. If they have not been
235 installed already, refer to
236 @c FIXME lousy reference.
237 the file @file{INSTALL.txt}.} In your text editor, enter the following
238 input and save the file as @file{test.ly}
245 To process @file{test.ly}, proceed as follows
252 You will see something resembling
255 lilypond (GNU LilyPond) 2.2.0
257 Now processing `/home/fred/ly/test.ly'
259 Interpreting music...[1]
260 @emph{... more interesting stuff ... }
261 DVI output to `test.dvi'...
262 PDF output to `test.pdf'...
263 PS output to `test.ps'...
267 @cindex Viewing music
270 The result is the file @file{test.pdf}@footnote{For @TeX{}
271 aficionados: there is also a @file{test.dvi} file. It can be viewed
272 with @code{xdvi}. The DVI uses a lot of PostScript specials, which do
273 not show up in the magnifying glass. The specials also mean that the
274 DVI file cannot be processed with @code{dvilj}. Use @code{dvips} for
279 } which you can print or with the standard facilities of your
280 operating system.@footnote{If your system does not have any tools
281 installed, you can try
282 @uref{http://www.cs.wisc.edu/~ghost/,Ghostscript}, a freely available
283 package for viewing and printing PDF and PostScript files.}
285 On Windows, start up a text-editor@footnote{Any simple or
286 programmer-oriented editor will do, for example Notepad. Do not use a
287 word processor, since these insert formatting codes that will confuse
294 Save it on the desktop as @file{test.ly} and make sure that it is not
295 called @file{test.ly.TXT}. Double clicking @file{test.ly} will process
296 the file and show the resulting PDF file.
299 @node More about pitches
300 @section More about pitches
302 A @rglos{sharp} (@texisharp{}) pitch is made by adding @samp{is} to
303 the name, a @rglos{flat} (@texiflat{}) pitch by adding @samp{es}. As
304 you might expect, a @rglos{double sharp} or @rglos{double flat} is
305 made by adding @samp{isis} or @samp{eses}@footnote{This syntax
306 derived from note naming conventions in Nordic and Germanic languages,
307 like German and Dutch.}
313 @lilypond[fragment,quote,notime]
314 \set Score.timing = ##f
315 \transpose c c' { cis1 ees fisis aeses s16_" " }
318 @cindex key signature, setting
319 The key signature is set with the command @code{\key}, followed by
320 a pitch and @code{\major} or @code{\minor}
329 @lilypond[fragment,quote,notime,fragment]
337 Key signatures together with the pitches (including alterations) are
338 used to determine when to print accidentals. This is a
339 feature that often causes confusion to newcomers, so let us explain it
343 LilyPond makes a sharp distinction between musical content and
344 layout. The alteration (flat, natural or sharp) of a note is part of
345 the pitch, and is therefore musical content. Whether an accidental (a
346 flat, natural or sharp @emph{sign}) is printed in front of the
347 corresponding note is a question of layout. Layout is something that
348 follows rules, so accidentals are printed automatically according to
349 those rules. The pitches in your music are works of art, so they will
350 not be added automatically, and you must enter what you want to hear.
354 @lilypond[quote,notime,fragment]
360 no note has an explicit accidental, but you still must enter
368 The code @samp{d} does not mean `print a black dot just below the
369 staff.' Rather, it means: `a note with pitch D-natural.' In the key
370 of A-flat, it does get an accidental
372 @lilypond[quote,notime,fragment]
382 Adding all alterations explicitly might require a little more effort
383 when typing, but the advantage is that transposing is easier, and
384 accidentals can be printed according to different conventions. See
385 @ref{Accidentals}, for some examples how accidentals can be printed
386 according to different rules.
389 For more information on
394 see @ref{Accidentals}.
397 see @ref{Key signature}.
402 @section Entering ties
405 A tie is created by appending a tilde @samp{~} to the first note
408 @lilypond[quote,notime,fragment,verbatim,relative=3]
412 For more information on Ties see @ref{Ties}.
416 @node Automatic and manual beams
417 @section Automatic and manual beams
419 @cindex beams, by hand
420 Beams are drawn automatically
422 @lilypond[quote,fragment,relative=2,verbatim]
427 If you do not like where beams are put, they can be entered by
428 hand. Mark the first note to be beamed with @samp{[} and the last one
431 @lilypond[quote,fragment,relative=2,verbatim]
435 For more information on beams, see @ref{Beaming}.
438 Here are key signatures, accidentals and ties in action
447 fis4 fis8 fis8 eis4 a8 gis~
454 ugr: removing the ignore block, leaving the comment line below
455 @c TODO: use relative mode, verbatim, junk \transpose and above @example
459 @lilypond[fragment,quote,noindent,linewidth=50\staffspace]
466 fis4 fis8 fis8 eis4 a8 gis~
475 There are some interesting points to note in this example. Bar lines
476 and beams are drawn automatically. Line breaks are calculated
477 automatically; it does not matter where the line breaks are in the
478 source file. Finally, the order in which time, key and clef changes
479 are entered is not relevant: in the printout, these are ordered
480 according to standard notation conventions.
485 @section Octave entry
488 @c Tim wants to move this quotes example just before the: quotes-do not-work
489 @c score, but we'd need to remove quotes from the other two (key and
492 @c better to have this just before the `octaves are bad' snipped
493 @c but we'd need to remove the ', from \key and tie
494 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
495 the note name, to lower a note one octave, add a `low quote' @code{,}
496 (a comma). Middle C is @code{c'}
499 c'4 c'' c''' \clef bass c c,
502 @lilypond[quote,notime,fragment]
503 c'4 c'' c''' \clef bass c c,
506 An example of the use of quotes is in the following Mozart fragment
508 @lilypond[quote,raggedright,fragment,verbatim]
511 cis''8. d''16 cis''8 e''4 e''8
512 b'8. cis''16 b'8 d''4 d''8
516 The last example shows that music in a high register needs lots of quotes.
517 This makes the input less readable, and it is a source of errors. The
518 solution is to use `relative octave' mode. This is the
519 most convenient way to copy existing music.
521 In relative mode, a note without octavation quotes (i.e. the @code{'}
522 or @code{,} after a note) is chosen so it it is closest to the
523 previous one. For example, @samp{c f} goes up while @samp{c g} goes
526 To use relative mode, add @code{\relative} before the piece of
527 music. The first note is taken relative to the middle C
528 @c no , for this sentence
533 @lilypond[quote,notime,fragment,verbatim]
540 Since most music has small intervals, pieces can be written almost
541 without octavation quotes in relative mode. The previous example is
544 @lilypond[quote,raggedright,verbatim]
548 cis'8. d16 cis8 e4 e8
553 @c needed better, maybe even redundant explanation
554 @c added another example below.
555 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
556 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
557 Larger intervals are made by adding octavation quotes.
559 @lilypond[quote,notime,verbatim,fragment]
565 In summary, quotes or commas no longer determine the absolute height
566 of a note in @code{\relative} mode. Rather, the height of a note is
567 relative to the previous one, and changing the octave of a single note
568 shifts all following notes an octave up or down.
570 For more information on Relative octaves see @ref{Relative octaves},
571 and @ref{Octave check}.
574 @node Music expressions explained
575 @section Music expressions explained
578 In input files, music is represent by so-called @emph{music
579 expression}. We have already seen in the previous examples;
580 a single note is a music expression
582 @lilypond[fragment,quote,verbatim,relative=3]
586 Enclosing group of notes in braces creates a new music
589 @lilypond[fragment,quote,verbatim,relative=3]
593 Putting a bunch of music expressions (notes) in braces, means that
594 they should be played in sequence. The result again is a music
595 expression, which can be grouped with other expressions sequentially.
596 Here, the expression from the previous example is combined with two
599 @lilypond[fragment,quote,verbatim,relative=3]
603 This technique is useful for non-monophonic music. To enter music
604 with more voices or more staves, we also combine expressions in
605 parallel. Two voices that should play at the same time, are entered
606 as a simultaneous combination of two sequences. A `simultaneous'
607 music expression is formed by enclosing expressions in @code{<<} and
608 @code{>>}. In the following example, three sequences (all containing
609 two other notes) are combined simultaneously
611 @lilypond[fragment,quote,verbatim,relative=3]
619 This mechanism is similar to mathematical
620 formulas: a big formula is created by composing small formulas. Such
621 formulas are called expressions, and their definition is recursive, so
622 you can make arbitrarily complex and large expressions. For example,
631 ((1 + 2) * 3) / (4 * 5)
635 @cindex music expression
636 This is a sequence of expressions, where each expression is contained
637 in the next one. The simplest expressions are numbers, and larger
638 ones are made by combining expressions with operators (like @samp{+},
639 @samp{*} and @samp{/}) and parentheses.
641 Like mathematical expressions, music expressions can be nested
642 arbitrarily deep,@footnote{The reason for getting three staves in the
643 previous example but just a single staff in the current one will be
644 explained in @ref{TODO}.} which is necessary for complex music like
647 @lilypond[fragment,quote,verbatim,relative=2]
650 << { e f } { c <<b d>> } >>
654 Music files with deep nesting can be confusing to enter and
655 maintain. One convention that helps against this confusion, is
656 indenting. When entering a file with deep nesting of braces and
657 angles, it is customary to use an indent that indicates the nesting
658 level. Formatting music like this eases reading, and helps you insert
659 the right number of closing braces at the end of an expression. For
673 Some editors have special support for entering LilyPond, and can help
674 indenting source files. See @ref{Editor support}, for more information.
679 To print more than one staff, each piece of music that makes up a
680 staff is marked by adding @code{\new Staff} before it. These
681 @code{Staff} elements are then combined parallel with @code{<<} and
682 @code{>>}, as demonstrated here
684 @lilypond[quote,fragment,verbatim]
686 \new Staff { \clef violin c'' }
687 \new Staff { \clef bass c }
692 The command @code{\new} introduces a `notation context.' A notation
693 context is an environment in which musical events (like notes or
694 @code{\clef} commands) are interpreted. For simple pieces, such
695 notation contexts are created implicitly. For more complex pieces, it
696 is best to mark contexts explicitly. This ensures that each fragment
699 There are several types of contexts: @code{Staff}, @code{Voice} and
700 @code{Score} handle melodic notation. Other contexts are also
701 @code{Lyrics} (for setting lyric texts) and @code{ChordNames} (for
702 printing chord names).
705 In terms of syntax, prepending @code{\new} to a music expression
706 creates a bigger music expression. In this way it resembles the minus
707 sign in mathematics. The formula @math{(4+5)} is an expression, so
708 @math{-(4+5)} is a bigger expression.
710 We can now typeset a melody with two staves
712 @c TODO: (c) status of this Paul McCartney (?) song (let's all stand together)
714 @lilypond[fragment,quote,verbatim,raggedright]
731 For more information on context see the description in
732 @ref{Interpretation contexts}.
736 @node Adding articulation marks to notes
737 @section Adding articulation marks to notes
743 Common accents can be added to a note using a dash (@samp{-}) and a
746 @lilypond[fragment,quote,verbatim,relative=2]
747 c-. c-- c-> c-^ c-+ c-_
751 Similarly, fingering indications can be added to a note using a dash
752 (@samp{-}) and the digit to be printed
754 @lilypond[fragment,quote,verbatim,relative=2]
759 Dynamic signs are made by adding the markings (with a backslash) to
762 @lilypond[fragment,quote,verbatim,relative=2]
770 Crescendi and decrescendi are started with the commands @code{\<} and
771 @code{\>}. An ending dynamic, for example @code{\f}, will finish the
772 crescendo, or the command @code{\!} can be used
774 @lilypond[fragment,quote,verbatim,relative=2]
782 A slur is a curve drawn across many notes, and indicates legato
783 articulation. The starting note and ending note are marked with
784 @samp{(} and @samp{)}, respectively
786 @lilypond[fragment,quote,fragment,relative=2,verbatim]
787 d4( c16) cis( d e c cis d) e( d4)
790 @cindex slurs versus ties
791 A slur looks like a tie, but it has a different meaning. A tie simply
792 makes the first note sound longer, and can only be used on pairs of
793 notes with the same pitch. Slurs indicate the articulations of notes,
794 and can be used on larger groups of notes. Slurs and ties can be
797 @lilypond[quote,fragment,relative=2]
798 c2~( c8 fis fis4 ~ fis2 g2)
801 @cindex phrasing slurs
802 Slurs to indicate phrasing can be entered with @code{\(} and
803 @code{\)}, so you can have both legato slurs and phrasing slurs at the
806 @lilypond[quote,fragment,relative=2,verbatim]
807 a8(\( ais b c) cis2 b'2 a4 cis, c\)
811 For more information on
816 see @ref{Fingering instructions}.
818 see @ref{Articulations}.
822 see @ref{Phrasing slurs}.
829 @node Combining notes into chords
830 @section Combining notes into chords
833 Chords can be made by surrounding pitches with angle brackets.
834 Angle brackets are the symbols @samp{<} and @samp{>}.
836 @lilypond[quote,relative=1,fragment,verbatim]
841 You can combine markings like beams and ties with chords. They must
842 be placed outside the angled brackets
844 @lilypond[quote,relative=1,fragment,verbatim]
845 r4 <c e g>8[ <c f a>]~ <c f a>
849 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
852 @lilypond[quote,relative=1,fragment]
854 r4 <c e g>8\>( <c e g> <c e g> <c f a>8\!)
860 @node Basic rhythmical commands
861 @section Basic rhythmical commands
865 @cindex partial measure
866 A pickup is entered with the keyword @code{\partial}. It
867 is followed by a duration: @code{\partial 4} is a quarter note upstep
868 and @code{\partial 8} an eighth note
870 @lilypond[quote,relative=2,verbatim,fragment]
877 Tuplets are made with the @code{\times} keyword. It takes two
878 arguments: a fraction and a piece of music. The duration of the piece
879 of music is multiplied by the fraction. Triplets make notes occupy
880 2/3 of their notated duration, so a triplet has 2/3 as its fraction
882 @lilypond[quote,relative=1,verbatim,fragment]
883 \times 2/3 { f8 g a }
889 Grace notes are also made by prefixing a music expression with the
890 keyword @code{\appoggiatura} or @code{\acciaccatura}
894 @lilypond[quote,relative=2,verbatim,fragment]
895 c4 \appoggiatura b16 c4
896 c4 \acciaccatura b16 c4
901 For more information on
906 see @ref{Grace notes},
910 see @ref{Partial measures}.
915 @node Commenting input files
916 @section Commenting input files
920 @cindex block comment
921 A comment is a remark for the human reader of the music input; it is
922 ignored while parsing, so it has no effect on the printed output.
923 There are two types of comments. The percent symbol @samp{%}
924 introduces a line comment; after @code{%} the rest of the line is
925 ignored. A block comments marks a whole section of music
926 input. Anything that is enclosed in @code{%@{} and @code{%@}} is
927 ignored. The following fragment shows possible uses for comments
930 % notes for twinkle twinkle follow
934 This line, and the notes below
935 are ignored, since they are in a
944 There is a special statement that is a kind of comment. The @code{\version}
945 statement marks for which version of LilyPond the file was written.
946 To mark a file for version 2.1.17, use
953 These annotations make future upgrades of LilyPond go more
954 smoothly. Changes in the syntax are handled with a special program,
955 @file{convert-ly} (see @ref{Invoking convert-ly}), and it uses
956 @code{\version} to determine what rules to apply.
959 @node Printing lyrics
960 @section Printing lyrics
963 @c TODO: (c) status of the Queen fragment.
967 Lyrics are entered by separating each syllable with a space
975 @lilypond[quote,verbatim,fragment,raggedright]
977 r4 c \times 2/3 { f g g }
978 \times 2/3 { g4( a2) }
982 The lyrics can be set to these notes, combining both with the
983 @code{\addlyrics} keyword
985 @lilypond[quote,verbatim,fragment,raggedright]
988 r4 c \times 2/3 { f g g }
989 \times 2/3 { g4( a2) }
991 \addlyrics { I want to break free }
996 @cindex extender line
998 This melody ends on a @rglos{melisma}, a single syllable (`free')
999 sung to more than one note. This is indicated with an @emph{extender
1000 line}. It is entered as two underscores, i.e.,
1003 @{ I want to break free __ @}
1006 @lilypond[fragment,quote,raggedright]
1009 r4 c \times 2/3 { f g g }
1010 \times 2/3 { g4( a2) }
1012 \addlyrics { I want to break free __ }
1016 Similarly, hyphens between words can be entered as two dashes,
1017 resulting in a centered hyphen between two syllables
1020 Twin -- kle twin -- kle
1023 @lilypond[fragment,quote,raggedright]
1029 \addlyrics { Twin -- kle twin -- kle }
1033 More options, like putting multiple lines of lyrics below a melody are
1034 discussed in @ref{Vocal music}.
1038 @section A lead sheet
1044 In popular music, it is common to denote accompaniment with chord names.
1045 Such chords can be entered like notes,
1047 @lilypond[quote,verbatim,raggedright]
1048 \chords { c2 f4. g8 }
1052 Now each pitch is read as the root of a chord instead of a note.
1053 This mode is switched on with @code{\chords}
1056 Other chords can be created by adding modifiers after a colon. The
1057 following example shows a few common modifiers
1059 @lilypond[quote,verbatim]
1060 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1063 For lead sheets, chords are not printed on staves, but as names on a
1064 line of themselves. Hence, we have to override the context with
1065 @code{\new}, rendering the music expression in a @code{ChordNames}
1068 @lilypond[quote,verbatim]
1069 \new ChordNames \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1073 When put together, chord names, lyrics and a melody form
1074 a lead sheet, for example,
1078 \new ChordNames \chords @{ @emph{chords} @}
1080 \addlyrics @{ @emph{the text} @}
1085 @lilypond[quote,raggedright]
1087 \new ChordNames \chords { r2 c:sus4 f }
1089 r4 c' \times 2/3 { f g g }
1090 \times 2/3 { g4( a2) }
1092 \addlyrics { I want to break free __ }
1096 A complete list of modifiers and other options for layout can be found
1101 @section Adding titles
1103 Bibliographic information is entered in a separate block, the
1104 @code{\header} block. The name of the piece, its composer, etc., are
1105 entered as an assignment, within @code{\header
1106 @{@tie{}@dots{}@tie{}@}}. The @code{\header} block is usually put at
1107 the top of the file. For example,
1112 composer = "Igor Stravinsky"
1119 When the file is processed the title and composer are printed above
1120 the music. More information on titling can be found in @ref{Titling}.
1123 @node Single staff polyphony
1124 @section Single staff polyphony
1127 @cindex multiple voices
1128 @cindex voices, more -- on a staff
1129 When different melodic lines are combined on a single staff they are
1130 printed as polyphonic voices; each voice has its own stems, slurs and
1131 beams, and the top voice has the stems up, while the bottom voice has
1134 Entering such parts is done by entering each voice as a sequence (with
1135 @code{@{...@}}), and combining those simultaneously, separating the
1136 voices with @code{\\}
1138 @lilypond[quote,verbatim,relative=2,fragment]
1139 << { a4 g2 f4~ f4 } \\
1143 For polyphonic music typesetting, spacer rests can also be convenient; these
1144 are rests that do not print. It is useful for filling up voices that
1145 temporarily do not play. Here is the same example with a spacer rest
1146 instead of a normal rest---just use @samp{s} instead of @samp{r}
1148 @lilypond[quote,verbatim,relative=2,fragment]
1149 << { a4 g2 f4~ f4 } \\
1154 Again, these expressions can be nested arbitrarily
1156 @lilypond[quote,fragment,verbatim,relative=2,fragment]
1164 { <c, g>1 ~ <c g>4 } \\
1170 More features of polyphonic typesetting in the notation manual are
1171 described in @ref{Polyphony}.
1175 @section Piano staves
1177 @cindex staff switch, manual
1178 @cindex cross staff voice, manual
1179 @cindex @code{\context}
1180 Piano music is typeset in two staves connected by a brace. Printing
1181 such a staff is similar to the polyphonic example in @ref{More staves},
1184 << \new Staff @{ @dots{} @}
1185 \new Staff @{ @dots{} @} >>
1189 but now this entire expression must be interpreted as a
1193 \new PianoStaff << \new Staff @dots{} >>
1196 Here is a full-fledged example
1198 @lilypond[quote,verbatim,relative=1,fragment]
1200 \new Staff { \time 2/4 c4 c g' g }
1201 \new Staff { \clef bass c,, c' e c }
1205 More information on formatting piano music is in @ref{Piano music}.
1208 @node Organizing larger pieces
1209 @section Organizing larger pieces
1211 When all of the elements discussed earlier are combined to produce
1212 larger files, the @code{\score} blocks get a lot bigger, because the
1213 music expressions are longer, and, in the case of polyphonic pieces,
1214 more deeply nested. Such large expressions can become unwieldy.
1216 By using variables, also known as identifiers, it is possible to break
1217 up complex music expressions. An identifier is assigned as follows
1220 namedMusic = @{ @dots{} @}
1224 The contents of the music expression @code{namedMusic}, can be used
1225 later by preceding the name with a backslash, i.e., @code{\namedMusic}.
1226 In the next example, a two-note motive is repeated two times by using
1227 variable substitution
1229 @lilypond[quote,raggedright,verbatim,nofragment]
1233 { \seufzer \seufzer }
1236 The name of an identifier should have alphabetic characters only;
1237 no numbers, underscores or dashes. The assignment should be outside of
1240 It is possible to use variables for many other types of objects in the
1246 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1249 Depending on its contents, the identifier can be used in different
1250 places. The following example uses the above variables
1260 More information on the possible uses of identifiers is in the
1261 technical manual, in TODO.
1264 @node An orchestral part
1265 @section An orchestral part
1267 In orchestral music, all notes are printed twice; in a part for
1268 the musicians, and in a full score for the conductor. Identifiers can
1269 be used to avoid double work. The music is entered once, and stored in
1270 a variable. The contents of that variable is then used to generate
1271 both the part and the score.
1273 It is convenient to define the notes in a special file. For example,
1274 suppose that the file @file{horn-music.ly} contains the following part
1275 of a horn/bassoon duo
1278 hornNotes = \relative c @{
1285 Then, an individual part is made by putting the following in a file
1288 \include "horn-music.ly"
1290 instrument = "Horn in F"
1294 \transpose f c' \hornNotes
1301 \include "horn-music.ly"
1305 substitutes the contents of @file{horn-music.ly} at this position in
1306 the file, so @code{hornNotes} is defined afterwards. The command
1307 @code{\transpose f@tie{}c'} indicates that the argument, being
1308 @code{\hornNotes}, should be transposed by a fifth downwards. Sounding
1309 @samp{f} is denoted by notated @code{c'}, which corresponds with
1310 tuning of a normal French Horn in@tie{}F. The transposition can be seen
1311 in the following output
1313 @lilypond[quote,raggedright]
1314 \transpose f c' \relative c {
1320 In ensemble pieces, one of the voices often does not play for many
1321 measures. This is denoted by a special rest, the multi-measure
1322 rest. It is entered with a capital @samp{R} followed by a duration
1323 (1@tie{}for a whole note, 2@tie{}for a half note, etc.). By multiplying the
1324 duration, longer rests can be constructed. For example, this rest
1325 takes 3@tie{}measures in 2/4 time
1331 When printing the part, multi-rests
1332 must be condensed. This is done by setting a run-time variable
1335 \set Score.skipBars = ##t
1339 This command sets the property @code{skipBars} in the
1340 @code{Score} context to true (@code{##t}). Prepending the rest and
1341 this option to the music above, leads to the following result
1343 @lilypond[quote,raggedright]
1344 \transpose f c' \relative c {
1346 \set Score.skipBars = ##t
1353 The score is made by combining all of the music together. Assuming
1354 that the other voice is in @code{bassoonNotes} in the file
1355 @file{bassoon-music.ly}, a score is made with
1358 \include "bassoon-music.ly"
1359 \include "horn-music.ly"
1362 \new Staff \hornNotes
1363 \new Staff \bassoonNotes
1370 @lilypond[quote,raggedright]
1378 r4 d,8 f | gis4 c | b bes |
1379 a8 e f4 | g d | gis f
1384 More in-depth information on preparing parts and scores can be found
1385 in the notation manual; see @ref{Orchestral music}.
1387 Setting run-time variables (`properties') is discussed in ref-TODO.
1390 @node Musicological essays
1391 @section Musicological essays
1394 @cindex La@TeX{}, music in
1395 @cindex HTML, music in
1396 @cindex Texinfo, music in
1397 Some texts contain music examples. These texts are musicological
1398 treatises, songbooks or manuals like this. Such texts can be made by
1399 hand, simply by importing a PostScript figure into the word processor.
1400 However, there is an automated procedure to reduce the amount of work
1401 involved HTML, La@TeX{}, and Texinfo documents.
1403 A script called @code{lilypond-book} will extract the music fragments,
1404 run format them, and put back the resulting notation. This program is
1405 fully described in @ref{lilypond-book manual}. Here we show a small
1406 example. The example also contains explanatory text, so we will not
1407 comment on it further
1410 \documentclass[a4paper]@{article@}
1413 Documents for lilypond-book may freely mix music and text. For
1418 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1422 Options are put in brackets.
1424 \begin[fragment,quote,staffsize=26,verbatim]@{lilypond@}
1428 Larger examples can be put in a separate file, and introduced with
1429 \verb+\lilypondfile+.
1431 \lilypondfile[quote,noindent]@{screech-boink.ly@}
1436 Under Unix, you can view the results as follows
1441 $ lilypond-book --output=out/ lilybook.tex
1442 lilypond-book (GNU LilyPond) 2.1.19
1443 Reading `input/tutorial/lilybook.tex'
1444 Reading `input/screech-boink.ly'
1445 @var{lots of stuff deleted}
1446 Writing `out/lilybook.tex'
1449 @var{lots of stuff deleted}
1453 To convert the file into a nice PDF document, run the following
1457 $ dvips -Ppdf -u+lilypond -u+ec-mftrace lilybook
1458 $ ps2pdf lilybook.ps
1461 Running lilypond-book and running latex creates a lot of temporary
1462 files, which would clutter up the working directory. To remedy this,
1463 use the @code{--output=@var{dir}} option. It will create the files in
1464 a separate subdirectory @file{dir}.
1466 Finally the result of the La@TeX{} example shown above.@footnote{ This
1467 tutorial is processed with Texinfo, so the example is as well. This
1468 gives slightly different results in layout.} This finishes the
1473 Documents for lilypond-book may freely mix music and text. For
1478 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1482 Options are put in brackets.
1484 @lilypond[fragment,quote,staffsize=26,verbatim]
1488 Larger examples can be put in a separate file, and introduced with
1489 @code{\lilypondfile}.
1491 @lilypondfile[quote,noindent]{screech-boink.ly}