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 * Relative octave entry::
56 * Combining music into compound expressions::
57 * Adding articulation marks to notes::
58 * Combining notes into chords::
61 * Listening to output::
63 * Single staff polyphony::
66 * Fine tuning layout::
67 * Organizing larger pieces::
68 * An orchestral part::
69 * Integrating text and music:: Integrating text and music.
76 We start off by showing how very simple music is entered in LilyPond:
77 you get a note simply by typing its note name, from @samp{a}
78 through @samp{g}. So if you enter
85 then the result looks like this:
88 @c \transpose c c' { c d e f g a b }
90 @c \property Score.timing = ##f
91 @lilypond[notime, relative=2]
95 The length of a note is specified by adding a number, @samp{1} for a
96 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
103 \property Score.timing = ##f
104 \property Staff.autoBeaming = ##f
105 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
108 If you do not specify a @rglos{duration}, the previous one is used:
115 \property Score.timing = ##f
116 \transpose c c' { a a a2 a s16_" " }
120 Rests are entered just like notes, but with the name ``@code{r}'':
129 \property Score.timing = ##f
130 \property Staff.Clef = \turnOff
131 \property Staff.TimeSignature = \turnOff
139 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
146 \property Score.timing = ##f
147 \transpose c c' { a2. a4 a8. a16 s16_" " }
151 The @rglos{meter} (or @rglos{time signature}) can be set with the
152 @code{\time} command:
160 @c a clef here may lead to confusion
162 \property Staff.Clef \set #'transparent = ##t
172 The @rglos{clef} can be set using the @code{\clef} command:
174 @c what is more common name treble or violin?
175 @c in Dutch, its violin.
176 @c in English its definitely treble.
185 \property Score.timing = ##f
196 Notes and commands like @code{\clef} and @code{\time} , are enclosed
197 in @code{\notes @{@dots{}@}}. This indicates that music (as opposed
198 to @rglos{lyrics}) follows:
208 Now the piece of music is almost ready to be printed. The final step is to
209 combine the music with a printing command.
211 The printing command is the so-called @code{\paper} block. The
212 @code{\paper} block is used to customize printing specifics, but we
213 accept the defaults for now. The music and the @code{\paper} block
214 are combined by enclosing them in @code{\score @{ ... @}}. The
215 following is a complete and valid input file.
238 linewidth = 55 * \staffspace
243 During the rest of the tutorial, we will often leave out @code{\score}
244 and @code{\paper}, for clarity. However, both must be present when
245 feeding the file to LilyPond.
247 More elaborate information on entering pitches and durations is in
248 @ref{Pitches} and @ref{Durations}. Clefs are fully explained in
249 @ref{Clef}. Time signatures and other timing commands are described
250 in @ref{Time signature}.
253 @node Running LilyPond
254 @section Running LilyPond
256 In the last section we explained what kind of things you could enter
257 in a LilyPond file. In this section we explain what commands to run
258 and how to view or print the output. If you have not used LilyPond
259 before, want to test your setup, or want to run an example file
260 yourself, read this section. The instructions that follow are for
261 Unix-like systems. Some additional instructions for Microsoft Windows
262 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, then refer to the file @file{INSTALL.txt}}. In
269 your text editor, enter the following input and save the file as
275 \notes @{ c'4 e' g' @}
282 @c now this is weird, running ly2dvi to run LilyPond
283 @c (therefore name change proposal)
285 LilyPond is the program that computes the sheet music. All other
286 things, such as adding titles, page breaking and other page layout,
287 are done by a small wrapper program called
288 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
289 then adds the titling and page layout instructions. To process
290 @file{test.ly} with @code{ly2dvi}, proceed as follows:
298 You will see something resembling:
303 Now processing: `/home/fred/ly/test.ly'
305 Interpreting music...[1]
306 @emph{ ... more interesting stuff ... }
307 PDF output to `test.pdf'...
308 DVI output to `test.dvi'...
312 @cindex Viewing music
315 The result of the ly2dvi is the file @file{test.pdf}.@footnote{For
316 @TeX{} afficionados, there is also a @file{test.dvi} file. It can be
317 viewed with @code{xdvi}. The DVI uses a lot of PostScript specials,
318 which do not show up in the magnifying glass. The specials also mean
319 that the DVI file cannot be processed with @code{dvilj}. Use
320 @code{dvips} for printing.
324 } One of the following commands should put the PDF on your
338 If the music on your screen looks good, you can print it by clicking
339 File/Print inside your viewing program.
343 @cindex Printing output
348 On Windows, the same procedure should work, the terminal is started by
349 clicking on the LilyPond or Cygwin icon. Any text editor (such as
350 NotePad, Emacs or Vim) may be used to edit the LilyPond file.
352 To view the PDF file, try the following:
355 If your system has a PDF viewer installed, open
356 @file{C:\Cygwin\home\@var{your-name}} in the explorer and double-click
359 If you prefer the keyboard, you can also try the list of commands
360 shown before. If none work, go to
361 @uref{http://www.cs.wisc.edu/~ghost/} to install the proper software.
364 The commands for formatting and printing music on all platforms are
365 detailed in @ref{Invoking LilyPond}.
367 @node More about pitches and accidentals
368 @section More about pitches and accidentals
370 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
371 @rglos{flat} (@texiflat{}) by adding @samp{es}. As you might expect,
372 a @rglos{double sharp} or @rglos{double flat} is made by adding
373 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
374 naming conventions in Nordic and Germanic languages, like German and
382 \property Score.timing = ##f
383 \transpose c c' { cis1 ees fisis aeses s16_" " }
387 @cindex key signature, setting
389 The key signature is set with the command ``@code{\key}'', followed by
390 a pitch and @code{\major} or @code{\minor}:
400 \property Staff.TimeSignature = \turnOff
410 A tie is created by adding a tilde ``@code{~}'' to the first note
413 @lilypond[fragment,verbatim,relative 2]
419 This example shows the key signature, accidentals and ties in action:
430 fis4 fis8 fis8 eis4 a8 gis-~
439 \notes { \transpose c c' {
445 fis4 fis8 fis8 eis4 a8 gis-~
448 \paper { linewidth = #(* 50 staffspace) }
454 There are some interesting points to note in this example. Bar lines
455 and beams are drawn automatically. Line breaks are calculated
456 automatically; it does not matter where the lines breaks are in the
457 source file. Finally, the order of time, key and clef changes is not
458 relevant: in the printout, these are ordered according to standard
459 notation conventions.
461 Accidentals (sharps and flats) do not have to be marked explicitly:
462 you just enter the pitch of the note, and an accidental is printed
463 only when necessary. The flip side of this mechanism, is that you have
464 to mark notes as sharp or flat, even when they do not get accidentals.
465 For example, in this example:
468 \property Staff.TimeSignature = #'()
470 cis dis eis fis gis ais bis
472 no note gets an explicit accidental, but still you enter
476 cis dis eis fis gis ais bis
479 Adding all alterations explicitly might require some more effort when
480 typing, but the advantage is that transposing is easier. It also makes
481 it possible to use different conventions for when to print
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'}:
500 c'4 c'' c''' \clef bass c c,
504 \property Score.timing = ##f
505 \property Staff.TimeSignature = \turnOff
506 c'4 c'' c''' \clef bass c c,
511 An example of the use of quotes is in the following Mozart fragment:
512 @lilypond[singleline,fragment,verbatim]
515 cis''8. d''16 cis''8 e''4 e''8
516 b'8. cis''16 b'8 d''4 d''8
519 This example shows that music in a high register needs lots of quotes.
520 This makes the input less readable, and it is a source of errors. The
521 solution is to use ``relative octave'' mode. In practice, this is the
522 most convenient way to copy existing music. To use relative mode, add
523 @code{\relative} before the piece of music. You must also give a note
524 from which relative starts, in this case @code{c''}. If you do not
525 use octavation quotes (i.e. do not add ' or , after a note), relative
526 mode chooses the note that is closest to the previous one.
527 For example, @code{c f} goes up while @code{c g} goes down:
537 \property Score.timing = ##f
538 \property Staff.TimeSignature = \turnOff
547 Since most music has small intervals, in relative mode pieces can be
548 written almost without using octavation quotes. In relative mode, the
549 Mozart example is entered as
551 @lilypond[singleline,fragment,verbatim]
561 @c needed better, maybe even redundant explanation
562 @c added another example below.
563 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
564 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
565 Larger intervals are made by adding octavation quotes. Quotes or
566 commas do not determine the absolute height of a note; the height of a
567 note is relative to the previous one.
568 @c do not use commas or quotes in this sentence
569 For example: @code{c f,} goes down; @code{f, f} are both the same;
570 @code{c' c} are the same; and @code{c g'} goes up:
580 \property Score.timing = ##f
581 \property Staff.TimeSignature = \turnOff
590 Here is an example of the difference between relative mode and
591 ``normal'' (non-relative) mode:
602 \property Score.timing = ##f
603 \property Staff.TimeSignature = \turnOff
619 \property Score.timing = ##f
620 \property Staff.TimeSignature = \turnOff
630 @node Relative octave entry
631 @section Relative octave entry
635 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
636 @c chromatic thing pasted in front. (admittedly the original does not
637 @c have a phrasing slur. The problem is that we do not want the slur
638 @c and the Phrasing slur to collide. We are trying to make a good
642 @lilypond[fragment,relative 1, verbatim]
643 a8-(-\( ais b c-) cis2 b'2 a4 cis, c-\)
648 @cindex beams, by hand
649 Beams are drawn automatically, but if you do not like where they are
650 put, they can be entered by hand. Mark the first note to be beamed
651 with @code{[} and the last one with @code{]}:
653 @lilypond[fragment,relative 1, verbatim]
654 a8-[ ais-] d-[ es r d-]
659 Rests are described in full detail in @ref{Rests}.
661 The notation manual discusses ties in @ref{Ties}.
666 @node Combining music into compound expressions
667 @section Combining music into compound expressions
669 To print more than one staff, each piece of music that makes up a
670 staff is marked by adding @code{\context Staff} before it. These
671 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and
672 @code{@}}, as is demonstrated here:
675 @lilypond[fragment,verbatim]
677 \context Staff = staffA { \clef violin c'' }
678 \context Staff = staffB { \clef bass c }
684 In this example, @code{\simultaneous } indicates that both music
685 fragments happen at the same time, and must be printed stacked
686 vertically. The notation @code{< .. >} can also be used as a
687 shorthand for @code{\simultaneous @{ .. @}}.
689 @code{\context} introduces a ``notation context''. To understand this
690 concept, imagine that you are performing a piece of music. When you
691 perform the music, you combine the symbols printed at a certain point
692 with contextual information. For example, without knowing the current
693 clef, and the accidentals in the last measure, it would be impossible
694 to determine the pitch of a note. In other words, this information
695 forms context that helps you decipher a score. LilyPond produces
696 notation from music, so in effect, it does the inverse of reading
697 scores. Therefore, it also needs to keep track of contextual
698 information. This information is maintained in ``notation contexts.''
699 There are several types of contexts, e.g. @code{Staff}, @code{Voice}
700 and @code{Score}, but also @code{Lyrics} and
701 @code{ChordNames}. Prepending @code{\context} to a chunk of music
702 indicates what kind of context to use for interpreting it.
704 By specifying different names (in this case @code{staffA} and
705 @code{staffB}), two different contexts are created, leading to two
706 staves. It does not matter which names they are given, as long as they
707 are different. If they get the same name, the chunks of music are
708 assumed to belong on the same staff, and will be printed like that.
712 We can now typeset a melody with two staves:
715 @lilypond[verbatim,singleline]
718 < \context Staff = staffA {
722 e2-( d4 c2 b4 a8-[ a-]
723 b-[ b-] g-[ g-] a2.-) }
725 \context Staff = staffB {
736 The example shows how small chunks of music, for example, the notes
737 @code{c2}, @code{e4}, etc. of the second staff, are combined to form a
738 larger chunk by enclosing it in braces. Again, a larger chunk is
739 formed by prefix @code{\context Staff} to it, and that chunk is
740 combined with @code{< >}. This mechanism is similar with mathematical
741 formulas: in a formula, a so-called expression is formed by combining
742 simpler expressions into larger expressions. For example,
751 ((1 + 2) * 3) / (4 * 5)
754 @cindex music expression
755 is a sequence of expressions, where each expression is contained in
756 the next one. The simplest expressions are numbers and operators
757 (like +, * and /). Parentheses are used to group expressions. In
758 LilyPond input, a similar mechanism is used. Here, the simplest
759 expressions are notes and rests. By enclosing expressions in @code{<
760 >} and @code{@{ @}}, more complex music is formed. The @code{\context}
761 also forms new expressions; prepending it to a music expression yields
764 Like mathematical expressions, music expressions can be nested
765 arbitrarily deep, e.g.
766 @lilypond[verbatim,relative 1]
768 < { e f } { c <b d> }
775 When spreading expressions over multiple lines, it is customary to use
776 an indent that indicates the nesting level. Formatting music like this
777 eases reading, and helps you insert the right amount of closing
778 braces at the end of an expression. For example,
795 @node Adding articulation marks to notes
796 @section Adding articulation marks to notes
802 Common accents can be added to a note using a dash (`@code{-}') and a
805 @lilypond[verbatim,relative 1]
806 c-. c-- c-> c-^ c-+ c-_
812 Similarly, fingering indications can be added to a note using a dash
813 (`@code{-}') and the digit to be printed:
815 @lilypond[verbatim,relative 1]
820 Dynamic signs are made by adding the markings to the note:
822 @lilypond[verbatim,relative 1]
832 Crescendi and decrescendi are started with the commands @code{\<} and
833 @code{\>}. The command @code{\!} finishes a crescendo on the note it
836 @lilypond[verbatim,relative 1]
837 c2-\< c2-\!-\ff c2-\> c2-\!
846 A slur is drawn across many notes, and indicates bound articulation
847 (legato). The starting note and ending note are marked with a
848 ``@code{(}'' and a ``@code{)}'' respectively:
851 @lilypond[fragment,relative 1, verbatim]
852 d4-( c16-)-( cis d e c cis d e-)-( d4-)
856 @cindex slurs versus ties
857 A slur is different from a tie. A tie simply makes the first note
858 sound longer, and can only be used on pairs of notes with the same
859 pitch. Slurs indicate the articulations of notes, and can be used on
860 larger groups of notes. Slurs and ties are also nested in practice:
861 @lilypond[fragment, relative=1]
862 c2-~-( c8 fis fis4 ~ fis2 g2-)
865 @cindex phrasing slurs
866 If you need two slurs at the same time (one for articulation, one for
867 phrasing), you can also make a phrasing slur with @code{\(} and
870 More information on fingering, articulation, slurs, phrasing slurs,
871 and dynamics can be found in @ref{Fingering instructions},
872 @ref{Articulations}, @ref{Slurs}, @ref{Phrasing slurs}, and @ref{Dynamics},
875 @node Combining notes into chords
876 @section Combining notes into chords
879 Chords can be made by
880 surrounding pitches with @code{<<} and @code{>}>:
882 @lilypond[relative 0, fragment,verbatim]
883 r4 <<c e g>>4 <<c f a>>8
889 You can combine beams and ties with chords. Beam and tie markings
890 must be placed outside the chord markers:
892 @lilypond[relative 0, fragment,verbatim]
893 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
899 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
901 @lilypond[relative 0, fragment]
903 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
911 * Basic rhythmical commands::
912 * Commenting input files::
915 @node Basic rhythmical commands
916 @subsection Basic rhythmical commands
921 @cindex partial measure
922 A pickup (or upstep) is entered with the keyword @code{\partial}. It
923 is followed by a duration: @code{\partial 4} is a quarter note upstep
924 and @code{\partial 8} an eighth note:
925 @lilypond[relative 1,verbatim,fragment]
932 Tuplets are made with the @code{\times} keyword. It takes two
933 arguments: a fraction and a piece of music. The duration of the piece
934 of music is multiplied by the fraction. Triplets make notes occupy
935 2/3 of their notated duration, so a triplet has 2/3 as its fraction:
937 @lilypond[relative 0,verbatim,fragment]
938 \times 2/3 { f8 g a }
944 Grace notes are also made by prefixing a note, or a set of notes with
945 a keyword. In this case, the keyword is @code{\grace}:
946 @lilypond[relative 1, verbatim,fragment]
948 \grace { d16-( e } d4-)
952 More information on grace notes, tuplets and upsteps are in @ref{Grace
953 notes}, @ref{Tuplets} and @ref{Partial measures}.
957 @node Commenting input files
958 @subsection Commenting input files
962 @cindex block comment
963 Comments are pieces of the input that are ignored. There are two
964 types of comments. A line comments is introduced by @code{%}: after
965 that, the rest of that line is ignored. Block comments span larger
966 sections of input. Anything that is enclosed in @code{%@{} and
967 @code{%@}} is ignored too. The following fragment shows possible uses
971 % notes for twinkle twinkle follow:
976 This line, and the notes below
977 are ignored, since they are in a
987 @node Printing lyrics
988 @section Printing lyrics
993 Lyrics are entered by separating each syllable with a space, and
994 surrounding them with @code{\lyrics @{ @dots{} @}}, for example,
996 \lyrics @{ I want to break free @}
999 Like notes, lyrics are also a form of music, but they must not be
1000 printed on a staff, which is the default way to print music. To print
1001 them as lyrics, they must be marked with @code{ \context Lyrics}:
1003 \context Lyrics \lyrics @{ I want to break free @}
1005 The melody for this song is as follows:
1007 @lilypond[fragment,relative=1]
1010 \times 2/3 { f4 g g } \times 2/3 { g4-( a2-) }
1013 The lyrics can be set to these notes, combining both with the
1014 @code{\addlyrics} keyword:
1017 \notes @{ @dots{} @}
1018 \context Lyrics @dots{}
1022 @lilypond[verbatim,linewidth=6.0cm]
1029 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
1031 \context Lyrics \lyrics { I want to break free }
1038 @cindex extender line
1040 This melody ends on a @rglos{melisma}, a single syllable (``free'')
1041 sung to more than one note. This is indicated with a @emph{extender
1042 line}. It is entered as two underscores, i.e.
1044 \lyrics @{ I want to break free __ @}
1053 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
1055 %% ugh, this is to deal with bugs in the extender implementation
1059 \context Lyrics \lyrics { I want to break free __ }
1061 \paper{ linewidth = 9.0 \cm }
1065 Similarly, hyphens between words can be entered as two dashes,
1066 resulting in a centered hyphen between two syllables:
1068 Twin -- kle twin -- kle
1070 @lilypond[singleline]
1072 \addlyrics \notes \relative f' { \time 2/4
1074 \context Lyrics \lyrics { Twin -- kle twin -- kle
1076 \paper { linewidth = 6.0 \cm }
1081 More options, like putting multiple lines of lyrics below a melody are
1082 discussed in @ref{Vocal music}.
1087 @section A lead sheet
1093 In popular music, it is common to denote accompaniment as chord-names.
1094 Using them in LilyPond has two parts, just like lyrics: entering the
1095 chords (with @code{\chords}), and printing them (with @code{\context
1098 Chord names are entered by starting chords mode (with @code{\chords}).
1099 In chords mode, you can enter chords with a letter (indicating the
1100 root of the chord), and a durations following that:
1103 \chords { c2 f4. g8 }
1107 The result of @code{\chords} is a list of chords, and is equivalent
1108 to entering chords with @code{<<@dots{}>>}.
1110 Other chords can be created by adding modifiers, after a colon. The
1111 following example shows a few common modifiers:
1114 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1117 Printing chords is done by adding @code{\context ChordNames}
1118 before the chords thus entered:
1121 \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1125 When put together, chord names, lyrics and a melody form
1126 a lead sheet, for example,
1131 \context ChordNames \chords @{ @emph{chords} @}
1133 \notes @emph{the melody}
1134 \context Lyrics \lyrics @{ @emph{the text} @}
1142 \context ChordNames \chords { r8 c2:sus4 f }
1144 \notes \relative c' {
1147 \times 2/3 { f g g } \times 2/3 { g4-( a2-) } }
1148 \context Lyrics \lyrics { I want to break free __ }
1150 \paper{ raggedright = ##t }
1155 A complete list of modifiers, and other options for layout are in the
1156 reference manual section @ref{Chords}.
1158 @node Listening to output
1159 @section Listening to output
1164 MIDI (Musical Instrument Digital Interface) is a standard for
1165 connecting and recording digital instruments. A MIDI file is like a
1166 tape recording of a MIDI instrument. The @code{\midi} block makes the
1167 music go to a MIDI file, so you can listen to the music you entered.
1168 It is great for checking the music: octaves that are off, or
1169 accidentals that were mistyped, stand out very much when listening to
1170 the musical transcription.
1172 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
1177 \midi @{ \tempo 4=72 @}
1182 Here, the tempo is specified using the @code{\tempo} command. In this
1183 case the tempo of quarter notes is set to 72 beats per minute. More
1184 information on auditory output is in the @ref{Sound} section in the
1192 Bibliographic information is entered in a separate block, the
1193 @code{\header} block. The name of the piece, its composer, etc. are
1194 entered as assignment, within @code{\header @{ @dots{} @}}. For
1198 title = "Eight miniatures"
1199 composer = "Igor Stravinsky"
1200 tagline = "small is beautiful"
1203 \score @{ @dots{} @}
1206 @cindex bibliographic information
1212 When the file is processed by @code{ly2dvi}, the title and composer
1213 specified are printed above the music. The `tagline' is a short line
1214 printed at bottom of the last page, which normally says ``Lily was
1215 here, version @dots{}''. In the example above, it is replaced by the
1216 line ``small is beautiful''.
1218 Normally, the @code{\header} is put at the top of the file. However,
1219 for a document that contains multiple pieces (e.g. a etude book, or
1220 part with multiple movements), then the header can be put into the
1221 @code{\score} block as follows; in this case, the name of each piece
1222 will be printed before each movement:
1225 @cindex Lily was here
1226 @cindex signature line
1231 title = "Eight miniatures"
1232 composer = "Igor Stravinsky"
1233 tagline = "small is beautiful"
1237 \header @{ piece = "Adagio" @}
1240 \header @{ piece = "Menuetto" @}
1244 More information on titling can be found in @ref{Invoking ly2dvi}.
1247 @node Single staff polyphony
1248 @section Single staff polyphony
1251 @cindex multiple voices
1252 @cindex voices, more -- on a staff
1254 When different melodic lines are combined on a single staff, these are
1255 printed as polyphonic voices: each voice has its own stems, slurs
1256 and beams, and the top voice has the stems up, while the bottom voice
1259 Entering such parts is done by entering each voice as a sequence (with
1260 @code{@{ .. @}}), and combining those simultaneously, separating the
1261 voices with @code{\\}:
1264 < @{ a4 g2 f4-~ f4 @} \\
1267 @lilypond[relative 1]
1268 \context Staff < { a4 g2 f4-~ f4 } \\
1272 For polyphonic music typesetting, spacer rests can also be convenient: these
1273 are rests that do not print. It is useful for filling up voices that
1274 temporarily do not play:
1276 < @{ a4 g2 f4-~ f4 @} \\
1279 @lilypond[relative 1]
1280 \context Staff < { a4 g2 f4-~ f4 } \\
1284 Again, these expressions can be nested arbitrarily:
1288 \context Staff = staffA
1290 < { a4 g2 f4-~ f4 } \\
1292 \context Staff = staffB
1293 < { \clef bass <<c g>>1 } \\
1300 More features of polyphonic typesetting are in the notation manual
1304 @section Piano staffs
1306 @cindex staff switch, manual
1307 @cindex cross staff voice, manual
1308 @cindex @code{\translator}
1310 Piano music is always typeset in two staffs connected by a brace.
1311 Printing such a staff is done similar to the polyphonic example in
1312 @ref{Combining music into compound expressions}:
1314 < \context Staff = up @{ @dots{} @}
1315 \context Staff = down @{ @dots{} @}
1318 but now this entire expression must be interpreted as a
1321 \context PianoStaff < \context Staff @dots{} >
1324 Here is a full-fledged example:
1326 @lilypond[relative 0,fragment]
1328 < \context Staff = up { \time 2/4
1330 \context Staff = down {
1331 \clef bass c,, c' e c }
1335 More information on formatting piano music is in @ref{Piano music}.
1337 @node Setting variables
1338 @section Setting variables
1340 When the music is converted from notes to print, it is interpreted
1341 from left-to-right order, similar to what happens when we read
1342 music. During this step, context-sensitive information, such as the
1343 accidentals to print, and where barlines must be placed, are stored in
1344 variables. These variables are called @emph{translation properties}.
1345 The properties can also be manipulated from input files. Consider this input:
1347 \property Staff.autoBeaming = ##f
1349 It sets the property named @code{autoBeaming} in the current staff to
1350 @code{##f}, which means `false'. This property controls whether beams
1351 are printed automatically:
1352 @lilypond[relative 1,fragment,verbatim]
1354 \property Staff.autoBeaming = ##f
1359 LilyPond includes a built-in programming language, namely, a dialect
1360 of Scheme. The argument to @code{\property}, @code{##f}, is an
1361 expression in that language. The first hash-mark signals that a piece
1362 of Scheme code follows. The second hash character is part of the
1363 boolean value true (@code{#t}). Values of other types may be
1366 @item a string, enclosed in double quotes, for example,
1368 \property Staff.instrument = #"French Horn"
1370 @item a boolean: either @code{#t} or @code{#f}, for true and false
1373 \property Voice.autoBeaming = ##f
1374 \property Score.skipBars = ##t
1377 @item a number, such as
1379 \property Score.currentBarNumber = #20
1382 @item a symbol, which is introduced by a quote character, as in
1384 \property Staff.crescendoSpanner = #'dashed-line
1387 @item a pair, which is also introduced by a quote character, like in
1388 the following statements, which set properties to the pairs (-7.5, 6)
1389 and (3, 4) respectively:
1392 \property Staff.minimumVerticalExtent = #'(-7.5 . 6)
1393 \property Staff.timeSignatureFraction = #'(3 . 4)
1399 There are many different properties, and not all of them are listed in
1400 this manual. However, the internal documentation lists them all in the
1401 @internalsref{All translation properties}, and most properties
1402 are demonstrated in one of the
1404 @uref{../../../input/test/out-www/collated-files.html,tips-and-tricks}
1412 @node Fine tuning layout
1413 @section Fine tuning layout
1415 Sometimes it is necessary to change music layout by hand. When music
1416 is formatted, layout objects are created for each symbol. For
1417 example, every clef and every note head is represented by a layout
1418 object. These layout objects also carry variables, which we call
1419 @emph{layout properties}. By changing these variables from their
1420 values, we can alter the look of a formatted score:
1422 @lilypond[verbatim,relative 0]
1424 \property Voice.Stem \override #'thickness = #3.0
1429 In the example shown here, the layout property @code{thickness} (a
1430 symbol) is set to 3 in the @code{Stem} layout objects of the current
1431 Voice. As a result, the notes following @code{\property} have thicker
1434 In most cases of manual overrides, only a single object must be
1435 changed. This can be achieved by prefixing @code{\once} to the
1436 @code{\property} statement, i.e.
1439 \once \property Voice.Stem \set #'thickness = #3.0
1442 @lilypond[relative 0]
1444 \once \property Voice.Stem \set #'thickness = #3.0
1449 Some overrides are so common that predefined commands are provided as
1450 a short cut. For example, @code{\slurUp} and @code{\stemDown}. These
1451 commands are described in
1455 @ref{Notation manual}, under the sections for slurs and stems
1458 The exact tuning possibilities for each type of layout object are
1459 documented in the internal documentation of the respective
1460 object. However, many layout objects share properties, which can be
1461 used to apply generic tweaks. We mention a couple of these:
1464 @item The @code{extra-offset} property, which
1465 @cindex @code{extra-offset}
1466 has a pair of numbers as value, moves around objects in the printout.
1467 The first number controls left-right movement; a positive number will
1468 move the object to the right. The second number controls up-down
1469 movement; a positive number will move it higher. The unit of these
1470 offsets are staff-spaces. The @code{extra-offset} property is a
1471 low-level feature: the formatting engine is completely oblivious to
1474 In the following example example, the second fingering is moved a
1475 little to the left, and 1.8 staff space downwards:
1477 @cindex setting object properties
1479 @lilypond[relative 1,verbatim]
1482 \once \property Voice.Fingering
1483 \set #'extra-offset = #'(-0.3 . -1.8)
1488 Setting the @code{transparent} property will make an object be printed
1489 in `invisible ink': the object is not printed, but all its other
1490 behavior is retained. The object still takes space, it takes part in
1491 collisions, and slurs, ties and beams can be attached to it.
1493 @cindex transparent objects
1494 @cindex removing objects
1495 @cindex invisible objects
1496 The following example demonstrates how to connect different voices
1497 using ties. Normally ties only happen between notes of the same
1498 voice. By introducing a tie in a different voice, and blanking a stem
1499 in that voice, the tie appears to cross voices:
1501 @lilypond[fragment,relative 1,verbatim]
1503 \once \property Voice.Stem \set #'transparent = ##t
1511 The @code{padding} property for objects with
1512 @cindex @code{padding}
1513 @code{side-position-interface} can be set to increase distance between
1514 symbols that are printed above or below notes. We only give an
1515 example; a more elaborate explanation is in @ref{Constructing a
1518 @lilypond[relative 1]
1520 \property Voice.Script \set #'padding = #3
1526 More specific overrides are also possible. The notation manual
1527 discusses in depth how to figure out these statements for yourself, in
1528 @ref{Tuning output}.
1530 @node Organizing larger pieces
1531 @section Organizing larger pieces
1533 When all of the elements discussed earlier are combined to produce
1534 larger files, the @code{\score} blocks get a lot bigger, because the
1535 music expressions are longer, and, in the case of polyphonic and/or
1536 orchestral pieces, more deeply nested.
1538 By using variables, also known as identifiers, it is possible to break
1539 up complex music expressions.
1540 An identifier is assigned as follows:
1542 namedMusic = \notes @{ @dots{}
1545 The contents of the music expression @code{namedMusic}, can be used
1546 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1547 In the next example, a two note motive is repeated thrice by using
1548 variable substitution:
1550 @lilypond[singleline,verbatim]
1555 \seufzer \seufzer \seufzer
1559 The name of an identifier should only have alphabetic characters only,
1560 and no numbers, underscores or dashes. The assignment should be
1561 outside of the @code{\score} block.
1563 It is possible to use variables for many other types of objects in the
1568 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1570 Depending on its contents, the identifier can be used in different
1571 places. The following example uses the above variables:
1574 \notes @{ c4^\name @}
1582 More information on the possible uses of identifiers is in the
1583 technical manual, in @ref{Scheme datatypes}.
1586 @node An orchestral part
1587 @section An orchestral part
1589 In orchestral music, all notes are printed twice: both in a part for
1590 the musicians, and in a full score for the conductor. Identifiers can
1591 be used to avoid double work: the music is entered once, and stored in
1592 variable. The contents of that variable is then used to generate
1593 both the part and the score.
1595 It is convenient to define the notes in a special file, for example,
1596 suppose that the @file{horn-music.ly} contains the following part of a
1599 hornNotes = \notes \relative c @{
1605 Then, an individual part is made by putting the following in a file:
1607 \include "horn-music.ly"
1609 instrument = "Horn in F"
1612 \notes \transpose c' f \hornNotes
1615 The @code{\include} command substitutes the contents of the file at
1616 this position in the file, so that @code{hornNotes} is defined
1617 afterwards. Since the horn is tuned in F, the @code{\transpose}
1618 command is used. The code @code{\transpose c' f} indicates that the
1619 argument, being @code{\hornNotes}, should be transposed by a fifth
1620 downwards: the @code{c'} becomes a @code{f}. The transposition can be
1621 seen in the following output:
1623 @lilypond[singleline]
1625 \notes \transpose c' f \notes \relative c' {
1632 In ensemble pieces, one of the voices often does not play for many
1633 measures. This is denoted by a special rest, the multi-measure
1634 rest. It is entered with a capital R, and followed by a duration (1
1635 for a whole note, 2 for a half note, etc.) By multiplying the
1636 duration, longer rests can be constructed. For example, the next rest
1637 takes 3 measures in 2/4 time:
1642 When printing the part, the following @code{skipBars} property must be
1643 set to false, to prevent the rest from being expanded in three one bar
1646 \property Score.skipBars = ##t
1648 Prepending the rest and the property setting above, leads to the
1651 @lilypond[singleline]
1652 \score {\notes { \transpose c' f \relative c' { \time 2/4
1653 \property Score.skipBars = ##t
1655 r4 f8 a cis4 f e d } }}
1658 The score is made by combining all of the music in a @code{\score}
1659 block, assuming that the other voice is in @code{bassoonNotes}, in the
1660 file @file{bassoon-music.ly}:
1662 \include "bassoon-music.ly"
1663 \include "horn-music.ly"
1667 \context Staff = hornStaff \hornNotes
1668 \context Staff = bsnStaff \bassoonNotes
1672 This would lead to the simple score depicted below:
1674 @lilypond[singleline]
1676 \notes \relative c \simultaneous {
1677 \context Staff = hornStaff { \time 2/4
1679 r4 f8 a cis4 f e d }
1680 \context Staff = fagStaff { \clef bass
1681 r4 d,8 f | gis4 c | b bes |
1682 a8 e f4 | g d | gis f }
1686 More in-depth information on preparing parts and scores is in the
1687 notation manual, in @ref{Orchestral music}.
1690 @node Integrating text and music
1691 @section Integrating text and music
1693 @cindex La@TeX{}, music in
1694 @cindex HTML, music in
1695 @cindex Texinfo, music in
1697 Sometimes you might want to use music examples in a text that you are
1698 writing (for example, a musicological treatise, a songbook, or (like us)
1699 the LilyPond manual). You can make such texts by hand, simply by
1700 importing a PostScript figure into your word processor. However,
1701 there is an automated procedure to reduce the amount of work.
1703 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1704 code. A script called @code{lilypond-book} will extract the music
1705 fragments, run LilyPond on them, and put back the resulting notation.
1706 This program is fully described in @ref{lilypond-book manual}. Here
1707 we show a small example; since the example contains also explanatory
1708 text, we will not comment it further:
1711 \documentclass[a4paper]@{article@}
1714 In a lilypond-book document, you can freely mix music and text. For
1717 \score @{ \notes \relative c' @{
1718 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1722 Notice that the music line length matches the margin settings of the
1725 If you have no \verb+\score+ block in the fragment,
1726 \texttt@{lilypond-book@} will supply one:
1732 In the example you see here, two things happened: a
1733 \verb+\score+ block was added, and the line width was set to natural
1734 length. You can specify options by putting them in brackets:
1736 \begin[26pt,verbatim]@{lilypond@}
1740 If you want to include large examples into the text, it is more
1741 convenient to put it in a separate file:
1743 \lilypondfile@{screech-boink.ly@}
1748 Under Unix, you can view the results as follows:
1752 $ lilypond-book --outdir=out/ lilbook.tex
1753 lilypond-book (GNU LilyPond) 1.7.23
1754 Reading `input/tutorial/lilbook.tex'
1755 Reading `input/screech-boink6.ly'
1756 @var{lots of stuff deleted}
1757 Writing `out/lilbook.latex'
1759 $ latex lilbook.latex
1760 @var{lots of stuff deleted}
1764 Running lilypond-book and running latex creates a lot of temporary
1765 files, and you would not want those to clutter up your working
1766 directory. The @code{outdir} option to lilypond-book creates the
1767 temporary files in a separate subdirectory @file{out}.
1769 The result looks more or less like this:
1773 In a lilypond-book document, you can freely mix music and text. For
1777 \notes \relative c' {
1778 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1786 Notice that the music line length matches the margin settings of the
1789 If you have no @code{\score} block in the fragment,
1790 @code{lilypond-book} will supply one:
1796 In the example you see here, two things happened: a
1797 @code{score} block was added, and the line width was set to natural
1798 length. You can specify options by putting them in brackets:
1800 @lilypond[26pt,verbatim]
1804 If you want to include large examples into the text, it is more
1805 convenient to put it in a separate file:
1807 @lilypondfile{screech-boink.ly}