4 @c * more details about running lilypond; error messages,
5 @c compiling/viewing (emacs?)
6 @c * where to go from First steps+More basics?
12 <!--- @@WEB-TITLE@@=Tutorial --->
16 Using LilyPond comes down to encoding music in an input file. After
17 entering the music, the program is run on the file producing output
18 which can be viewed or printed. In this tutorial, we will show step
19 by step how to enter such files, by showing fragments of input and the
20 corresponding output. At the end of every section, a paragraph will
21 list where to find further information on the topics discussed.
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:
29 @c TODO: intertext fixme
30 @lilypond[relative 1,singleline,verbatim,intertext="with the following output:"]
31 c'^\markup { \bold \huge { Click on this image! } }
35 By cutting and pasting the full input into a test file, you have a
36 starting template for experiments. If you like learning in this way,
37 you will probably want to print out or bookmark
41 @ref{Cheat sheet}, which is a table listing all commands for quick
45 This tutorial starts with a short introduction to the LilyPond music
46 language. After this first contact, we will show you how to to
47 produce printed output, normally using the program @code{ly2dvi}. You
48 should then be able to create and print your first sheets of music.
51 * First steps:: Music language of LilyPond.
52 * Running LilyPond:: Printing music.
53 * More about pitches and accidentals::
55 * Combining music into compound expressions::
56 * Adding articulation marks to notes::
57 * Combining notes into chords::
60 * Listening to output::
62 * Single staff polyphony::
65 * Fine tuning layout::
66 * Organizing larger pieces::
67 * An orchestral part::
68 * Integrating text and music:: Integrating text and music.
75 We start off by showing how very simple music is entered in LilyPond:
76 you get a note simply by typing its note name, from @samp{a}
77 through @samp{g}. So if you enter
84 then the result looks like this:
87 @c \transpose c c' { c d e f g a b }
89 @c \property Score.timing = ##f
90 @lilypond[notime, relative=2]
94 The length of a note is specified by adding a number, @samp{1} for a
95 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
102 \property Score.timing = ##f
103 \property Staff.autoBeaming = ##f
104 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
107 If you do not specify a @rglos{duration}, the previous one is used:
114 \property Score.timing = ##f
115 \transpose c c' { a a a2 a s16_" " }
119 Rests are entered just like notes, but with the name ``@code{r}'':
128 \property Score.timing = ##f
129 \property Staff.Clef = \turnOff
130 \property Staff.TimeSignature = \turnOff
138 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
145 \property Score.timing = ##f
146 \transpose c c' { a2. a4 a8. a16 s16_" " }
150 The @rglos{meter} (or @rglos{time signature}) can be set with the
151 @code{\time} command:
159 @c a clef here may lead to confusion
161 \property Staff.Clef \set #'transparent = ##t
171 The @rglos{clef} can be set using the @code{\clef} command:
173 @c what is more common name treble or violin?
174 @c in Dutch, its violin.
175 @c in English its definitely treble.
184 \property Score.timing = ##f
195 Notes and commands like @code{\clef} and @code{\time} , are enclosed
196 in @code{\notes @{@dots{}@}}. This indicates that music (as opposed
197 to @rglos{lyrics}) follows:
207 Now the piece of music is almost ready to be printed. The final step is to
208 combine the music with a printing command.
210 The printing command is the so-called @code{\paper} block. The
211 @code{\paper} block is used to customize printing specifics, but we
212 accept the defaults for now. The music and the @code{\paper} block
213 are combined by enclosing them in @code{\score @{ ... @}}. The
214 following is a complete and valid input file.
237 linewidth = 55 * \staffspace
242 During the rest of the tutorial, we will often leave out @code{\score}
243 and @code{\paper}, for clarity. However, both must be present when
244 feeding the file to LilyPond.
246 More elaborate information on entering pitches and durations is in
247 @ref{Pitches} and @ref{Durations}. Clefs are fully explained in
248 @ref{Clef}. Time signatures and other timing commands are described
249 in @ref{Time signature}.
252 @node Running LilyPond
253 @section Running LilyPond
255 In the last section we explained what kind of things you could enter
256 in a LilyPond file. In this section we explain what commands to run
257 and how to view or print the output. If you have not used LilyPond
258 before, want to test your setup, or want to run an example file
259 yourself, read this section. The instructions that follow are for
260 Unix-like systems. Some additional instructions for Microsoft Windows
261 are given at the end of this section.
263 Begin by opening a terminal window and starting a text editor. For
264 example, you could open an xterm and execute
265 @code{joe}.@footnote{There are macro files for VIM addicts, and there
266 is a @code{LilyPond-mode} for Emacs addicts. If it has not been
267 installed already, then refer to the file @file{INSTALL.txt}}. In
268 your text editor, enter the following input and save the file as
274 \notes @{ c'4 e' g' @}
281 @c now this is weird, running ly2dvi to run LilyPond
282 @c (therefore name change proposal)
284 LilyPond is the program that computes the sheet music. All other
285 things, such as adding titles, page breaking and other page layout,
286 are done by a small wrapper program called
287 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
288 then adds the titling and page layout instructions. To process
289 @file{test.ly} with @code{ly2dvi}, proceed as follows:
297 You will see something resembling:
302 Now processing: `/home/fred/ly/test.ly'
304 Interpreting music...[1]
305 @emph{ ... more interesting stuff ... }
306 PDF output to `test.pdf'...
307 DVI output to `test.dvi'...
311 @cindex Viewing music
314 The result of the ly2dvi is the file @file{test.pdf}.@footnote{For
315 @TeX{} afficionados, there is also a @file{test.dvi} file. It can be
316 viewed with @code{xdvi}. The DVI uses a lot of PostScript specials,
317 which do not show up in the magnifying glass. The specials also mean
318 that the DVI file cannot be processed with @code{dvilj}. Use
319 @code{dvips} for printing.
323 } One of the following commands should put the PDF on your
337 If the music on your screen looks good, you can print it by clicking
338 File/Print inside your viewing program.
342 @cindex Printing output
347 On Windows, the same procedure should work, the terminal is started by
348 clicking on the LilyPond or Cygwin icon. Any text editor (such as
349 NotePad, Emacs or Vim) may be used to edit the LilyPond file.
351 To view the PDF file, try the following:
354 If your system has a PDF viewer installed, open
355 @file{C:\Cygwin\home\@var{your-name}} in the explorer and double-click
358 If you prefer the keyboard, you can also try the list of commands
359 shown before. If none work, go to
360 @uref{http://www.cs.wisc.edu/~ghost/} to install the proper software.
363 The commands for formatting and printing music on all platforms are
364 detailed in @ref{Invoking LilyPond}.
366 @node More about pitches and accidentals
367 @section More about pitches and accidentals
369 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
370 @rglos{flat} (@texiflat{}) by adding @samp{es}. As you might expect,
371 a @rglos{double sharp} or @rglos{double flat} is made by adding
372 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
373 naming conventions in Nordic and Germanic languages, like German and
381 \property Score.timing = ##f
382 \transpose c c' { cis1 ees fisis aeses s16_" " }
386 @cindex key signature, setting
388 The key signature is set with the command ``@code{\key}'', followed by
389 a pitch and @code{\major} or @code{\minor}:
399 \property Staff.TimeSignature = \turnOff
409 A tie is created by adding a tilde ``@code{~}'' to the first note
412 @lilypond[fragment,verbatim,relative 2]
418 This example shows the key signature, accidentals and ties in action:
429 fis4 fis8 fis8 eis4 a8 gis-~
438 \notes { \transpose c c' {
444 fis4 fis8 fis8 eis4 a8 gis-~
447 \paper { linewidth = #(* 50 staffspace) }
453 There are some interesting points to note in this example. Bar lines
454 and beams are drawn automatically. Line breaks are calculated
455 automatically; it does not matter where the lines breaks are in the
456 source file. Finally, the order of time, key and clef changes is not
457 relevant: in the printout, these are ordered according to standard
458 notation conventions.
460 Accidentals (sharps and flats) do not have to be marked explicitly:
461 you just enter the pitch of the note, and an accidental is printed
462 only when necessary. The flip side of this mechanism, is that you have
463 to mark notes as sharp or flat, even when they do not get accidentals.
464 For example, in this example:
467 \property Staff.TimeSignature = #'()
469 cis dis eis fis gis ais bis
471 no note gets an explicit accidental, but still you enter
475 cis dis eis fis gis ais bis
478 Adding all alterations explicitly might require some more effort when
479 typing, but the advantage is that transposing is easier. It also makes
480 it possible to use different conventions for when to print
483 @cindex beams, by hand
484 Beams are drawn automatically, but if you do not like where they are
485 put, they can be entered by hand. Mark the first note to be beamed
486 with @code{[} and the last one with @code{]}:
488 @lilypond[fragment,relative 1, verbatim]
489 a8-[ ais-] d-[ es r d-]
494 Rests are described in full detail in @ref{Rests}.
496 The notation manual discusses ties in @ref{Ties}.
500 @section Octave entry
503 @c Tim wants to move this quotes example just before the: quotes-do not-work
504 @c score, but we'd need to remove quotes from the other two (key and
507 @c better to have this just before the `octaves are bad' snipped
508 @c but we'd need to remove the ', from \key and tie
509 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
510 the note name, to lower a note one octave, add a ``low quote'' @code{,}
511 (a comma). Middle C is @code{c'}:
515 c'4 c'' c''' \clef bass c c,
519 \property Score.timing = ##f
520 \property Staff.TimeSignature = \turnOff
521 c'4 c'' c''' \clef bass c c,
526 An example of the use of quotes is in the following Mozart fragment:
527 @lilypond[singleline,fragment,verbatim]
530 cis''8. d''16 cis''8 e''4 e''8
531 b'8. cis''16 b'8 d''4 d''8
534 This example shows that music in a high register needs lots of quotes.
535 This makes the input less readable, and it is a source of errors. The
536 solution is to use ``relative octave'' mode. In practice, this is the
537 most convenient way to copy existing music. To use relative mode, add
538 @code{\relative} before the piece of music. You must also give a note
539 from which relative starts, in this case @code{c''}. If you do not
540 use octavation quotes (i.e. do not add ' or , after a note), relative
541 mode chooses the note that is closest to the previous one.
542 For example, @code{c f} goes up while @code{c g} goes down:
552 \property Score.timing = ##f
553 \property Staff.TimeSignature = \turnOff
562 Since most music has small intervals, in relative mode pieces can be
563 written almost without using octavation quotes. In relative mode, the
564 Mozart example is entered as
566 @lilypond[singleline,fragment,verbatim]
576 @c needed better, maybe even redundant explanation
577 @c added another example below.
578 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
579 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
580 Larger intervals are made by adding octavation quotes. Quotes or
581 commas do not determine the absolute height of a note; the height of a
582 note is relative to the previous one.
583 @c do not use commas or quotes in this sentence
584 For example: @code{c f,} goes down; @code{f, f} are both the same;
585 @code{c' c} are the same; and @code{c g'} goes up:
595 \property Score.timing = ##f
596 \property Staff.TimeSignature = \turnOff
605 Here is an example of the difference between relative mode and
606 ``normal'' (non-relative) mode:
617 \property Score.timing = ##f
618 \property Staff.TimeSignature = \turnOff
634 \property Score.timing = ##f
635 \property Staff.TimeSignature = \turnOff
650 @node Combining music into compound expressions
651 @section Combining music into compound expressions
653 To print more than one staff, each piece of music that makes up a
654 staff is marked by adding @code{\context Staff} before it. These
655 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and
656 @code{@}}, as is demonstrated here:
659 @lilypond[fragment,verbatim]
661 \context Staff = staffA { \clef violin c'' }
662 \context Staff = staffB { \clef bass c }
668 In this example, @code{\simultaneous } indicates that both music
669 fragments happen at the same time, and must be printed stacked
670 vertically. The notation @code{< .. >} can also be used as a
671 shorthand for @code{\simultaneous @{ .. @}}.
673 @code{\context} introduces a ``notation context''. To understand this
674 concept, imagine that you are performing a piece of music. When you
675 perform the music, you combine the symbols printed at a certain point
676 with contextual information. For example, without knowing the current
677 clef, and the accidentals in the last measure, it would be impossible
678 to determine the pitch of a note. In other words, this information
679 forms context that helps you decipher a score. LilyPond produces
680 notation from music, so in effect, it does the inverse of reading
681 scores. Therefore, it also needs to keep track of contextual
682 information. This information is maintained in ``notation contexts.''
683 There are several types of contexts, e.g. @code{Staff}, @code{Voice}
684 and @code{Score}, but also @code{Lyrics} and
685 @code{ChordNames}. Prepending @code{\context} to a chunk of music
686 indicates what kind of context to use for interpreting it.
688 By specifying different names (in this case @code{staffA} and
689 @code{staffB}), two different contexts are created, leading to two
690 staves. It does not matter which names they are given, as long as they
691 are different. If they get the same name, the chunks of music are
692 assumed to belong on the same staff, and will be printed like that.
696 We can now typeset a melody with two staves:
699 @lilypond[verbatim,singleline]
702 < \context Staff = staffA {
706 e2-( d4 c2 b4 a8-[ a-]
707 b-[ b-] g-[ g-] a2.-) }
709 \context Staff = staffB {
720 The example shows how small chunks of music, for example, the notes
721 @code{c2}, @code{e4}, etc. of the second staff, are combined to form a
722 larger chunk by enclosing it in braces. Again, a larger chunk is
723 formed by prefix @code{\context Staff} to it, and that chunk is
724 combined with @code{< >}. This mechanism is similar with mathematical
725 formulas: in a formula, a so-called expression is formed by combining
726 simpler expressions into larger expressions. For example,
735 ((1 + 2) * 3) / (4 * 5)
738 @cindex music expression
739 is a sequence of expressions, where each expression is contained in
740 the next one. The simplest expressions are numbers and operators
741 (like +, * and /). Parentheses are used to group expressions. In
742 LilyPond input, a similar mechanism is used. Here, the simplest
743 expressions are notes and rests. By enclosing expressions in @code{<
744 >} and @code{@{ @}}, more complex music is formed. The @code{\context}
745 also forms new expressions; prepending it to a music expression yields
748 Like mathematical expressions, music expressions can be nested
749 arbitrarily deep, e.g.
750 @lilypond[verbatim,relative 1]
752 < { e f } { c <b d> }
759 When spreading expressions over multiple lines, it is customary to use
760 an indent that indicates the nesting level. Formatting music like this
761 eases reading, and helps you insert the right amount of closing
762 braces at the end of an expression. For example,
779 @node Adding articulation marks to notes
780 @section Adding articulation marks to notes
786 Common accents can be added to a note using a dash (`@code{-}') and a
789 @lilypond[verbatim,relative 1]
790 c-. c-- c-> c-^ c-+ c-_
796 Similarly, fingering indications can be added to a note using a dash
797 (`@code{-}') and the digit to be printed:
799 @lilypond[verbatim,relative 1]
804 Dynamic signs are made by adding the markings to the note:
806 @lilypond[verbatim,relative 1]
816 Crescendi and decrescendi are started with the commands @code{\<} and
817 @code{\>}. The command @code{\!} finishes a crescendo on the note it
820 @lilypond[verbatim,relative 1]
821 c2-\< c2-\!-\ff c2-\> c2-\!
830 A slur is drawn across many notes, and indicates bound articulation
831 (legato). The starting note and ending note are marked with a
832 ``@code{(}'' and a ``@code{)}'' respectively:
835 @lilypond[fragment,relative 1, verbatim]
836 d4-( c16-)-( cis d e c cis d e-)-( d4-)
840 @cindex slurs versus ties
841 A slur is different from a tie. A tie simply makes the first note
842 sound longer, and can only be used on pairs of notes with the same
843 pitch. Slurs indicate the articulations of notes, and can be used on
844 larger groups of notes. Slurs and ties are also nested in practice:
845 @lilypond[fragment, relative=1]
846 c2-~-( c8 fis fis4 ~ fis2 g2-)
849 @cindex phrasing slurs
850 If you need two slurs at the same time (one for articulation, one for
851 phrasing), you can also make a phrasing slur with @code{\(} and
855 @lilypond[fragment,relative 1, verbatim]
856 a8-(-\( ais b c-) cis2 b'2 a4 cis, c-\)
861 More information on fingering, articulation, slurs, phrasing slurs,
862 and dynamics can be found in @ref{Fingering instructions},
863 @ref{Articulations}, @ref{Slurs}, @ref{Phrasing slurs}, and @ref{Dynamics},
866 @node Combining notes into chords
867 @section Combining notes into chords
870 Chords can be made by
871 surrounding pitches with @code{<<} and @code{>}>:
873 @lilypond[relative 0, fragment,verbatim]
874 r4 <<c e g>>4 <<c f a>>8
880 You can combine beams and ties with chords. Beam and tie markings
881 must be placed outside the chord markers:
883 @lilypond[relative 0, fragment,verbatim]
884 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
890 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
892 @lilypond[relative 0, fragment]
894 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
902 * Basic rhythmical commands::
903 * Commenting input files::
906 @node Basic rhythmical commands
907 @subsection Basic rhythmical commands
912 @cindex partial measure
913 A pickup (or upstep) is entered with the keyword @code{\partial}. It
914 is followed by a duration: @code{\partial 4} is a quarter note upstep
915 and @code{\partial 8} an eighth note:
916 @lilypond[relative 1,verbatim,fragment]
923 Tuplets are made with the @code{\times} keyword. It takes two
924 arguments: a fraction and a piece of music. The duration of the piece
925 of music is multiplied by the fraction. Triplets make notes occupy
926 2/3 of their notated duration, so a triplet has 2/3 as its fraction:
928 @lilypond[relative 0,verbatim,fragment]
929 \times 2/3 { f8 g a }
935 Grace notes are also made by prefixing a note, or a set of notes with
936 a keyword. In this case, the keyword is @code{\grace}:
937 @lilypond[relative 1, verbatim,fragment]
939 \grace { d16-( e } d4-)
943 More information on grace notes, tuplets and upsteps are in @ref{Grace
944 notes}, @ref{Tuplets} and @ref{Partial measures}.
948 @node Commenting input files
949 @subsection Commenting input files
953 @cindex block comment
954 Comments are pieces of the input that are ignored. There are two
955 types of comments. A line comments is introduced by @code{%}: after
956 that, the rest of that line is ignored. Block comments span larger
957 sections of input. Anything that is enclosed in @code{%@{} and
958 @code{%@}} is ignored too. The following fragment shows possible uses
962 % notes for twinkle twinkle follow:
967 This line, and the notes below
968 are ignored, since they are in a
978 @node Printing lyrics
979 @section Printing lyrics
984 Lyrics are entered by separating each syllable with a space, and
985 surrounding them with @code{\lyrics @{ @dots{} @}}, for example,
987 \lyrics @{ I want to break free @}
990 Like notes, lyrics are also a form of music, but they must not be
991 printed on a staff, which is the default way to print music. To print
992 them as lyrics, they must be marked with @code{ \context Lyrics}:
994 \context Lyrics \lyrics @{ I want to break free @}
996 The melody for this song is as follows:
998 @lilypond[fragment,relative=1]
1001 \times 2/3 { f4 g g } \times 2/3 { g4-( a2-) }
1004 The lyrics can be set to these notes, combining both with the
1005 @code{\addlyrics} keyword:
1008 \notes @{ @dots{} @}
1009 \context Lyrics @dots{}
1013 @lilypond[verbatim,linewidth=6.0cm]
1020 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
1022 \context Lyrics \lyrics { I want to break free }
1029 @cindex extender line
1031 This melody ends on a @rglos{melisma}, a single syllable (``free'')
1032 sung to more than one note. This is indicated with a @emph{extender
1033 line}. It is entered as two underscores, i.e.
1035 \lyrics @{ I want to break free __ @}
1044 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
1046 %% ugh, this is to deal with bugs in the extender implementation
1050 \context Lyrics \lyrics { I want to break free __ }
1052 \paper{ linewidth = 9.0 \cm }
1056 Similarly, hyphens between words can be entered as two dashes,
1057 resulting in a centered hyphen between two syllables:
1059 Twin -- kle twin -- kle
1061 @lilypond[singleline]
1063 \addlyrics \notes \relative f' { \time 2/4
1065 \context Lyrics \lyrics { Twin -- kle twin -- kle
1067 \paper { linewidth = 6.0 \cm }
1072 More options, like putting multiple lines of lyrics below a melody are
1073 discussed in @ref{Vocal music}.
1078 @section A lead sheet
1084 In popular music, it is common to denote accompaniment as chord-names.
1085 Using them in LilyPond has two parts, just like lyrics: entering the
1086 chords (with @code{\chords}), and printing them (with @code{\context
1089 Chord names are entered by starting chords mode (with @code{\chords}).
1090 In chords mode, you can enter chords with a letter (indicating the
1091 root of the chord), and a durations following that:
1094 \chords { c2 f4. g8 }
1098 The result of @code{\chords} is a list of chords, and is equivalent
1099 to entering chords with @code{<<@dots{}>>}.
1101 Other chords can be created by adding modifiers, after a colon. The
1102 following example shows a few common modifiers:
1105 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1108 Printing chords is done by adding @code{\context ChordNames}
1109 before the chords thus entered:
1112 \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1116 When put together, chord names, lyrics and a melody form
1117 a lead sheet, for example,
1122 \context ChordNames \chords @{ @emph{chords} @}
1124 \notes @emph{the melody}
1125 \context Lyrics \lyrics @{ @emph{the text} @}
1133 \context ChordNames \chords { r8 c2:sus4 f }
1135 \notes \relative c' {
1138 \times 2/3 { f g g } \times 2/3 { g4-( a2-) } }
1139 \context Lyrics \lyrics { I want to break free __ }
1141 \paper{ raggedright = ##t }
1146 A complete list of modifiers, and other options for layout are in the
1147 reference manual section @ref{Chords}.
1149 @node Listening to output
1150 @section Listening to output
1155 MIDI (Musical Instrument Digital Interface) is a standard for
1156 connecting and recording digital instruments. A MIDI file is like a
1157 tape recording of a MIDI instrument. The @code{\midi} block makes the
1158 music go to a MIDI file, so you can listen to the music you entered.
1159 It is great for checking the music: octaves that are off, or
1160 accidentals that were mistyped, stand out very much when listening to
1161 the musical transcription.
1163 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
1168 \midi @{ \tempo 4=72 @}
1173 Here, the tempo is specified using the @code{\tempo} command. In this
1174 case the tempo of quarter notes is set to 72 beats per minute. More
1175 information on auditory output is in the @ref{Sound} section in the
1183 Bibliographic information is entered in a separate block, the
1184 @code{\header} block. The name of the piece, its composer, etc. are
1185 entered as assignment, within @code{\header @{ @dots{} @}}. For
1189 title = "Eight miniatures"
1190 composer = "Igor Stravinsky"
1191 tagline = "small is beautiful"
1194 \score @{ @dots{} @}
1197 @cindex bibliographic information
1203 When the file is processed by @code{ly2dvi}, the title and composer
1204 specified are printed above the music. The `tagline' is a short line
1205 printed at bottom of the last page, which normally says ``Lily was
1206 here, version @dots{}''. In the example above, it is replaced by the
1207 line ``small is beautiful''.
1209 Normally, the @code{\header} is put at the top of the file. However,
1210 for a document that contains multiple pieces (e.g. a etude book, or
1211 part with multiple movements), then the header can be put into the
1212 @code{\score} block as follows; in this case, the name of each piece
1213 will be printed before each movement:
1216 @cindex Lily was here
1217 @cindex signature line
1222 title = "Eight miniatures"
1223 composer = "Igor Stravinsky"
1224 tagline = "small is beautiful"
1228 \header @{ piece = "Adagio" @}
1231 \header @{ piece = "Menuetto" @}
1235 More information on titling can be found in @ref{Invoking ly2dvi}.
1238 @node Single staff polyphony
1239 @section Single staff polyphony
1242 @cindex multiple voices
1243 @cindex voices, more -- on a staff
1245 When different melodic lines are combined on a single staff, these are
1246 printed as polyphonic voices: each voice has its own stems, slurs
1247 and beams, and the top voice has the stems up, while the bottom voice
1250 Entering such parts is done by entering each voice as a sequence (with
1251 @code{@{ .. @}}), and combining those simultaneously, separating the
1252 voices with @code{\\}:
1255 < @{ a4 g2 f4-~ f4 @} \\
1258 @lilypond[relative 1]
1259 \context Staff < { a4 g2 f4-~ f4 } \\
1263 For polyphonic music typesetting, spacer rests can also be convenient: these
1264 are rests that do not print. It is useful for filling up voices that
1265 temporarily do not play:
1267 < @{ a4 g2 f4-~ f4 @} \\
1270 @lilypond[relative 1]
1271 \context Staff < { a4 g2 f4-~ f4 } \\
1275 Again, these expressions can be nested arbitrarily:
1279 \context Staff = staffA
1281 < { a4 g2 f4-~ f4 } \\
1283 \context Staff = staffB
1284 < { \clef bass <<c g>>1 } \\
1291 More features of polyphonic typesetting are in the notation manual
1295 @section Piano staffs
1297 @cindex staff switch, manual
1298 @cindex cross staff voice, manual
1299 @cindex @code{\translator}
1301 Piano music is always typeset in two staffs connected by a brace.
1302 Printing such a staff is done similar to the polyphonic example in
1303 @ref{Combining music into compound expressions}:
1305 < \context Staff = up @{ @dots{} @}
1306 \context Staff = down @{ @dots{} @}
1309 but now this entire expression must be interpreted as a
1312 \context PianoStaff < \context Staff @dots{} >
1315 Here is a full-fledged example:
1317 @lilypond[relative 0,fragment]
1319 < \context Staff = up { \time 2/4
1321 \context Staff = down {
1322 \clef bass c,, c' e c }
1326 More information on formatting piano music is in @ref{Piano music}.
1328 @node Setting variables
1329 @section Setting variables
1331 When the music is converted from notes to print, it is interpreted
1332 from left-to-right order, similar to what happens when we read
1333 music. During this step, context-sensitive information, such as the
1334 accidentals to print, and where barlines must be placed, are stored in
1335 variables. These variables are called @emph{translation properties}.
1336 The properties can also be manipulated from input files. Consider this input:
1338 \property Staff.autoBeaming = ##f
1340 It sets the property named @code{autoBeaming} in the current staff to
1341 @code{##f}, which means `false'. This property controls whether beams
1342 are printed automatically:
1343 @lilypond[relative 1,fragment,verbatim]
1345 \property Staff.autoBeaming = ##f
1350 LilyPond includes a built-in programming language, namely, a dialect
1351 of Scheme. The argument to @code{\property}, @code{##f}, is an
1352 expression in that language. The first hash-mark signals that a piece
1353 of Scheme code follows. The second hash character is part of the
1354 boolean value true (@code{#t}). Values of other types may be
1357 @item a string, enclosed in double quotes, for example,
1359 \property Staff.instrument = #"French Horn"
1361 @item a boolean: either @code{#t} or @code{#f}, for true and false
1364 \property Voice.autoBeaming = ##f
1365 \property Score.skipBars = ##t
1368 @item a number, such as
1370 \property Score.currentBarNumber = #20
1373 @item a symbol, which is introduced by a quote character, as in
1375 \property Staff.crescendoSpanner = #'dashed-line
1378 @item a pair, which is also introduced by a quote character, like in
1379 the following statements, which set properties to the pairs (-7.5, 6)
1380 and (3, 4) respectively:
1383 \property Staff.minimumVerticalExtent = #'(-7.5 . 6)
1384 \property Staff.timeSignatureFraction = #'(3 . 4)
1390 There are many different properties, and not all of them are listed in
1391 this manual. However, the internal documentation lists them all in the
1392 @internalsref{All translation properties}, and most properties
1393 are demonstrated in one of the
1395 @uref{../../../input/test/out-www/collated-files.html,tips-and-tricks}
1403 @node Fine tuning layout
1404 @section Fine tuning layout
1406 Sometimes it is necessary to change music layout by hand. When music
1407 is formatted, layout objects are created for each symbol. For
1408 example, every clef and every note head is represented by a layout
1409 object. These layout objects also carry variables, which we call
1410 @emph{layout properties}. By changing these variables from their
1411 values, we can alter the look of a formatted score:
1413 @lilypond[verbatim,relative 0]
1415 \property Voice.Stem \override #'thickness = #3.0
1420 In the example shown here, the layout property @code{thickness} (a
1421 symbol) is set to 3 in the @code{Stem} layout objects of the current
1422 Voice. As a result, the notes following @code{\property} have thicker
1425 In most cases of manual overrides, only a single object must be
1426 changed. This can be achieved by prefixing @code{\once} to the
1427 @code{\property} statement, i.e.
1430 \once \property Voice.Stem \set #'thickness = #3.0
1433 @lilypond[relative 0]
1435 \once \property Voice.Stem \set #'thickness = #3.0
1440 Some overrides are so common that predefined commands are provided as
1441 a short cut. For example, @code{\slurUp} and @code{\stemDown}. These
1442 commands are described in
1446 @ref{Notation manual}, under the sections for slurs and stems
1449 The exact tuning possibilities for each type of layout object are
1450 documented in the internal documentation of the respective
1451 object. However, many layout objects share properties, which can be
1452 used to apply generic tweaks. We mention a couple of these:
1455 @item The @code{extra-offset} property, which
1456 @cindex @code{extra-offset}
1457 has a pair of numbers as value, moves around objects in the printout.
1458 The first number controls left-right movement; a positive number will
1459 move the object to the right. The second number controls up-down
1460 movement; a positive number will move it higher. The unit of these
1461 offsets are staff-spaces. The @code{extra-offset} property is a
1462 low-level feature: the formatting engine is completely oblivious to
1465 In the following example example, the second fingering is moved a
1466 little to the left, and 1.8 staff space downwards:
1468 @cindex setting object properties
1470 @lilypond[relative 1,verbatim]
1473 \once \property Voice.Fingering
1474 \set #'extra-offset = #'(-0.3 . -1.8)
1479 Setting the @code{transparent} property will make an object be printed
1480 in `invisible ink': the object is not printed, but all its other
1481 behavior is retained. The object still takes space, it takes part in
1482 collisions, and slurs, ties and beams can be attached to it.
1484 @cindex transparent objects
1485 @cindex removing objects
1486 @cindex invisible objects
1487 The following example demonstrates how to connect different voices
1488 using ties. Normally ties only happen between notes of the same
1489 voice. By introducing a tie in a different voice, and blanking a stem
1490 in that voice, the tie appears to cross voices:
1492 @lilypond[fragment,relative 1,verbatim]
1494 \once \property Voice.Stem \set #'transparent = ##t
1502 The @code{padding} property for objects with
1503 @cindex @code{padding}
1504 @code{side-position-interface} can be set to increase distance between
1505 symbols that are printed above or below notes. We only give an
1506 example; a more elaborate explanation is in @ref{Constructing a
1509 @lilypond[relative 1]
1511 \property Voice.Script \set #'padding = #3
1517 More specific overrides are also possible. The notation manual
1518 discusses in depth how to figure out these statements for yourself, in
1519 @ref{Tuning output}.
1521 @node Organizing larger pieces
1522 @section Organizing larger pieces
1524 When all of the elements discussed earlier are combined to produce
1525 larger files, the @code{\score} blocks get a lot bigger, because the
1526 music expressions are longer, and, in the case of polyphonic and/or
1527 orchestral pieces, more deeply nested.
1529 By using variables, also known as identifiers, it is possible to break
1530 up complex music expressions.
1531 An identifier is assigned as follows:
1533 namedMusic = \notes @{ @dots{}
1536 The contents of the music expression @code{namedMusic}, can be used
1537 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1538 In the next example, a two note motive is repeated thrice by using
1539 variable substitution:
1541 @lilypond[singleline,verbatim]
1546 \seufzer \seufzer \seufzer
1550 The name of an identifier should only have alphabetic characters only,
1551 and no numbers, underscores or dashes. The assignment should be
1552 outside of the @code{\score} block.
1554 It is possible to use variables for many other types of objects in the
1559 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1561 Depending on its contents, the identifier can be used in different
1562 places. The following example uses the above variables:
1565 \notes @{ c4^\name @}
1573 More information on the possible uses of identifiers is in the
1574 technical manual, in @ref{Scheme datatypes}.
1577 @node An orchestral part
1578 @section An orchestral part
1580 In orchestral music, all notes are printed twice: both in a part for
1581 the musicians, and in a full score for the conductor. Identifiers can
1582 be used to avoid double work: the music is entered once, and stored in
1583 variable. The contents of that variable is then used to generate
1584 both the part and the score.
1586 It is convenient to define the notes in a special file, for example,
1587 suppose that the @file{horn-music.ly} contains the following part of a
1590 hornNotes = \notes \relative c @{
1596 Then, an individual part is made by putting the following in a file:
1598 \include "horn-music.ly"
1600 instrument = "Horn in F"
1603 \notes \transpose c' f \hornNotes
1606 The @code{\include} command substitutes the contents of the file at
1607 this position in the file, so that @code{hornNotes} is defined
1608 afterwards. Since the horn is tuned in F, the @code{\transpose}
1609 command is used. The code @code{\transpose c' f} indicates that the
1610 argument, being @code{\hornNotes}, should be transposed by a fifth
1611 downwards: the @code{c'} becomes a @code{f}. The transposition can be
1612 seen in the following output:
1614 @lilypond[singleline]
1616 \notes \transpose c' f \notes \relative c' {
1623 In ensemble pieces, one of the voices often does not play for many
1624 measures. This is denoted by a special rest, the multi-measure
1625 rest. It is entered with a capital R, and followed by a duration (1
1626 for a whole note, 2 for a half note, etc.) By multiplying the
1627 duration, longer rests can be constructed. For example, the next rest
1628 takes 3 measures in 2/4 time:
1633 When printing the part, the following @code{skipBars} property must be
1634 set to false, to prevent the rest from being expanded in three one bar
1637 \property Score.skipBars = ##t
1639 Prepending the rest and the property setting above, leads to the
1642 @lilypond[singleline]
1643 \score {\notes { \transpose c' f \relative c' { \time 2/4
1644 \property Score.skipBars = ##t
1646 r4 f8 a cis4 f e d } }}
1649 The score is made by combining all of the music in a @code{\score}
1650 block, assuming that the other voice is in @code{bassoonNotes}, in the
1651 file @file{bassoon-music.ly}:
1653 \include "bassoon-music.ly"
1654 \include "horn-music.ly"
1658 \context Staff = hornStaff \hornNotes
1659 \context Staff = bsnStaff \bassoonNotes
1663 This would lead to the simple score depicted below:
1665 @lilypond[singleline]
1667 \notes \relative c \simultaneous {
1668 \context Staff = hornStaff { \time 2/4
1670 r4 f8 a cis4 f e d }
1671 \context Staff = fagStaff { \clef bass
1672 r4 d,8 f | gis4 c | b bes |
1673 a8 e f4 | g d | gis f }
1677 More in-depth information on preparing parts and scores is in the
1678 notation manual, in @ref{Orchestral music}.
1681 @node Integrating text and music
1682 @section Integrating text and music
1684 @cindex La@TeX{}, music in
1685 @cindex HTML, music in
1686 @cindex Texinfo, music in
1688 Sometimes you might want to use music examples in a text that you are
1689 writing (for example, a musicological treatise, a songbook, or (like us)
1690 the LilyPond manual). You can make such texts by hand, simply by
1691 importing a PostScript figure into your word processor. However,
1692 there is an automated procedure to reduce the amount of work.
1694 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1695 code. A script called @code{lilypond-book} will extract the music
1696 fragments, run LilyPond on them, and put back the resulting notation.
1697 This program is fully described in @ref{lilypond-book manual}. Here
1698 we show a small example; since the example contains also explanatory
1699 text, we will not comment it further:
1702 \documentclass[a4paper]@{article@}
1705 In a lilypond-book document, you can freely mix music and text. For
1708 \score @{ \notes \relative c' @{
1709 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1713 Notice that the music line length matches the margin settings of the
1716 If you have no \verb+\score+ block in the fragment,
1717 \texttt@{lilypond-book@} will supply one:
1723 In the example you see here, two things happened: a
1724 \verb+\score+ block was added, and the line width was set to natural
1725 length. You can specify options by putting them in brackets:
1727 \begin[26pt,verbatim]@{lilypond@}
1731 If you want to include large examples into the text, it is more
1732 convenient to put it in a separate file:
1734 \lilypondfile@{screech-boink.ly@}
1739 Under Unix, you can view the results as follows:
1743 $ lilypond-book --outdir=out/ lilbook.tex
1744 lilypond-book (GNU LilyPond) 1.7.23
1745 Reading `input/tutorial/lilbook.tex'
1746 Reading `input/screech-boink6.ly'
1747 @var{lots of stuff deleted}
1748 Writing `out/lilbook.latex'
1750 $ latex lilbook.latex
1751 @var{lots of stuff deleted}
1755 Running lilypond-book and running latex creates a lot of temporary
1756 files, and you would not want those to clutter up your working
1757 directory. The @code{outdir} option to lilypond-book creates the
1758 temporary files in a separate subdirectory @file{out}.
1760 The result looks more or less like this:
1764 In a lilypond-book document, you can freely mix music and text. For
1768 \notes \relative c' {
1769 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1777 Notice that the music line length matches the margin settings of the
1780 If you have no @code{\score} block in the fragment,
1781 @code{lilypond-book} will supply one:
1787 In the example you see here, two things happened: a
1788 @code{score} block was added, and the line width was set to natural
1789 length. You can specify options by putting them in brackets:
1791 @lilypond[26pt,verbatim]
1795 If you want to include large examples into the text, it is more
1796 convenient to put it in a separate file:
1798 @lilypondfile{screech-boink.ly}