4 @c * LilyPond Lilypond lilypond (sometimes: the program)
5 @c * more details about running lilypond; error messages,
6 @c compiling/viewing (emacs?)
7 @c * where to go from First steps+More basics?
13 <!--- @@WEB-TITLE@@=Tutorial --->
17 * First steps:: Music language of LilyPond
18 * Running LilyPond:: Printing music
23 * Listening to output::
24 * More movements :: Joining separate pieces of music
25 * A piano excerpt:: Piano music
26 * Fine tuning a piece::
27 * An orchestral score:: Conductor's score and individual parts
28 * Integrating text and music:: Integrating text and music
31 Operating is done through text files: To print a piece of music, you
32 enter the music in a file. When LilyPond is run (normally using the
33 program @code{ly2dvi}) on that file, another file containing formatted
34 sheet music, is produced. That file may be printed or viewed.
36 This tutorial starts with a small introduction to the LilyPond music
37 language. After this first contact, we will show which commands to
38 run to produce printed output, so you should then be able to create
39 your first sheets of music. The tutorial continues with more and more
46 We start off by showing how very simple music is entered in LilyPond:
47 you get a note simply by typing its @htmlref{note name}, from @samp{a}
48 through @samp{g}. So if you enter
55 then the result looks like this:
58 @c \transpose c c' { c d e f g a b }
60 @c \property Score.timing = ##f
61 @lilypond[notime, relative=2]
65 We will continue with this format: First we show a snippet of input,
66 then the resulting output.
68 The length of a note is specified by adding a number, @samp{1} for a
69 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
76 \property Score.timing = ##f
77 \property Staff.autoBeaming = ##f
78 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
81 If you do not specify a @rglos{duration}, the previous one is used:
88 \property Score.timing = ##f
89 \transpose c c' { a a a2 a s16_" " }
92 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
93 @rglos{flat} (@texiflat{}) by adding @samp{es}. As you might expect,
94 a @rglos{double sharp} or @rglos{double flat} is made by adding
95 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
96 naming conventions in Nordic and Germanic languages, like German and
104 \property Score.timing = ##f
105 \transpose c c' { cis1 ees fisis aeses s16_" " }
108 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
115 \property Score.timing = ##f
116 \transpose c c' { a2. a4 a8. a16 s16_" " }
119 Entering pitches and durations is fully explained in @ref{Pitches} and
123 The @rglos{meter} (or @rglos{time signature}) can be set with the
124 @code{\time} command:
132 @c a clef here may lead to confusion
134 \property Staff.Clef \set #'transparent = ##t
143 Time signatures and other timing commands are described in @ref{Time
147 The @rglos{clef} can be set using the @code{\clef} command:
149 @c what is more common name treble or violin?
150 @c in Dutch, its violin.
151 @c in English its definitely treble.
160 \property Score.timing = ##f
171 Clefs are fully explained in @ref{Clef}.
174 When you enter these commands in a file, you must to enclose them in
175 @code{\notes @{@dots{}@}}. This lets LilyPond know that music (as
176 opposed to @rglos{lyrics}) follows:
186 Now the piece of music is almost ready to be printed. The final step is to
187 combine the music with a printing command.
189 The printing command is the so-called @code{\paper} block. Later on
190 you will see that the @code{\paper} block is used to customize
191 printing specifics. The music and the @code{\paper} block are combined by
192 enclosing them in @code{\score @{ ... @}}. This is what a full source file looks like:
215 linewidth = 55 * \staffspace
221 @node Running LilyPond
222 @section Running LilyPond
224 In the last section we explained what kind of things you could enter
225 in a LilyPond file. In this section we explain what commands to run
226 and how to view or print the output. If you have not used LilyPond
227 before, want to test your setup, or want to run an example file
228 yourself, read this section. The instructions that follow are for
229 Unix-like systems. Some additional instructions for MS Windows are given
230 at the end of this section.
232 Begin by opening a terminal window and starting a text editor.
233 For example, you could open an xterm and execute @code{joe}. In your
234 text editor, enter the following input and save the file as
240 \notes @{ c'4 e' g' @}
247 @c now this is weird, running ly2dvi to run LilyPond
248 @c (therefore name change proposal)
250 LilyPond is the program that computes the sheet music. All other
251 things, such as adding titles, page breaking and other page layout,
252 are done by a small wrapper program called
253 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
254 then adds the titling and page layout instructions. To process
255 @file{test.ly} with @code{ly2dvi}, proceed as follows:
263 You will see the following on your screen:
268 Now processing: `/home/fred/ly/test.ly'
270 Interpreting music...[1]
271 @emph{ ... more interesting stuff ... }
272 PDF output to `test.pdf'...
273 DVI output to `test.dvi'...
277 @cindex Viewing music
280 The results of the ly2dvi run are two files, @file{test.dvi} and
281 @file{test.pdf}. The PDF file (@file{test.pdf}) is the one you can
282 print or view. For example, viewing PDF can be done with ghostview.
283 If a version of ghostview is installed on your system, one of these
284 commands will produce a window with some music notation on your
297 If the music on your screen looks good, you can print it by clicking
298 File/Print inside ghostview.
300 The DVI file (@file{test.dvi}) contains the same sheet music in a
301 different format. DVI files are more easily processed by the computer,
302 so viewing them usually is quicker. You can run @code{xdvi test.dvi}
303 @c KDVI doesn't grok the PS specials.
305 @c @code{kdvi test.dvi}
307 to view the DVI file. In Xdvi, the mouse buttons
308 activate magnifying glasses. Unfortunately, variable symbols (such as
309 beams and slurs) are not displayed in the magnifying glasses.
314 @cindex Printing output
318 If you are familiar with @TeX{}, be warned: do not use other DVI
319 drivers like @code{dvilj}. LilyPond DVI use embedded PostScript code
320 and will not render correctly with other DVI drivers besides
328 Various commands for formatting and printing music are detailed in
329 @ref{Invoking LilyPond}.
332 @unnumberedsubsec Windows users
334 Windows users can start the terminal by clicking on the LilyPond or
335 Cygwin icon. Any text editor (such as NotePad, Emacs or Vim) may be
336 used to edit the LilyPond file. When Cygwin's @code{XFree86} X11
337 window system is installed along with @code{tetex-x11} and
338 @code{ghostscript-x11} packages, then the @code{dvi} output may be
339 viewed with @code{xdvi test.dvi} as described above. If you have
340 installed a PostScript/PDF viewer, such as @code{GSView} from
341 @uref{http://www.cs.wisc.edu/~ghost}, viewing the PDF file can be done
345 @code{gsview32 test.pdf}
348 Printing may be done by executing
351 @code{gsview32 /s test.pdf}
359 We continue with the introduction of more musical constructs. Normal
360 rests are entered just like notes with the name ``@code{r}'':
368 \property Score.timing = ##f
369 \property Staff.Clef = \turnOff
370 \property Staff.TimeSignature = \turnOff
377 Rests are described in full detail in @ref{Rests}.
380 @c Tim wants to move this quotes example just before the: quotes-do not-work
381 @c score, but we'd need to remove quotes from the other two (key and
384 @c better to have this just before the `octaves are bad' snipped
385 @c but we'd need to remove the ', from \key and tie
386 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
387 the note name, to lower a note one octave, add a ``low quote'' @code{,}
388 (a comma). Middle C is @code{c'}:
392 c'4 c'' c''' \clef bass c c,
396 \property Score.timing = ##f
397 \property Staff.TimeSignature = \turnOff
398 c'4 c'' c''' \clef bass c c,
403 A tie is created by adding a tilde ``@code{~}'' to the first note
406 @lilypond[fragment,verbatim]
411 A tie is different from a slur. A tie simply makes the first note
412 sound longer, and can only be used on pairs of notes with the same
413 pitch. Slurs indicate the articulations of notes, and can be used on
414 larger groups of notes. Slurs and ties are also nested in practice:
415 @lilypond[fragment, relative=1]
416 c2-~-( c8 fis fis4 ~ fis2 g2-)
419 The notation manual discusses ties in @ref{Ties}.
421 The key signature is set with the command ``@code{\key}'', followed by
422 a pitch and @code{\major} or @code{\minor}:
432 \property Staff.TimeSignature = \turnOff
442 @c bit on the long/complex/scary taste
443 @c cheating a bit: two lines makes for a friendlier look
444 This example shows notes, ties, octave marks, and rests in action.
453 r4 r8 d''8 cis''4 e''
455 cis''4 cis''8 cis'' bis'4 d''8 cis''-~
468 r4 r8 d''8 cis''4 e''
470 cis''4 cis''8 cis'' bis'4 d''8 cis''-~
473 \paper { linewidth = 50*\staffspace }
479 There are some interesting points to note in this example.
480 Accidentals (sharps and flats) do not have to be marked explicitly:
481 you just enter the note name, and an accidental is printed
482 automatically, only when necessary. Bar lines and beams are drawn
483 automatically. Line breaks are calculated automatically; it does not
484 matter where the lines breaks are in the source file. Finally, the
485 order of time, key and clef changes is not relevant: in the printout,
486 these are ordered using standard notation conventions.
488 The example also indicates that a piece of music written in a high
489 register needs lots of quotes. This makes the input less readable,
490 and is also a potential source of errors.
492 The solution is to use ``relative octave'' mode. In practice, this is
493 the most convenient way to copy existing music. To use relative mode,
494 add @code{\relative} before the piece of music. You must also give a
495 note from which relative starts, in this case @code{c''}. If you do
496 not use octavation quotes (i.e. do not add ' or , after a note),
497 relative mode chooses the note that is closest to the previous one.
498 @c do not use commas or quotes in this sentence
499 For example: @code{c f} goes up; @code{c g} goes down:
509 \property Score.timing = ##f
510 \property Staff.TimeSignature = \turnOff
519 Since most music has small intervals, in relative mode pieces can be
520 written almost without using octavation quotes.
522 @c needed better, maybe even redundant explanation
523 @c added another example below.
524 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
525 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
526 Larger intervals are made by adding octavation quotes. Quotes or
527 commas do not determine the absolute height of a note; the height of a
528 note is relative to the previous one.
529 @c do not use commas or quotes in this sentence
530 For example: @code{c f,} goes down; @code{f, f} are both the same;
531 @code{c' c} are the same; and @code{c g'} goes up:
541 \property Score.timing = ##f
542 \property Staff.TimeSignature = \turnOff
551 Here is an example of the difference between relative mode and
552 ``normal'' (non-relative) mode:
563 \property Score.timing = ##f
564 \property Staff.TimeSignature = \turnOff
580 \property Score.timing = ##f
581 \property Staff.TimeSignature = \turnOff
588 A slur is drawn across many notes, and indicates bound articulation
589 (legato). The starting note and ending note are marked with a
590 ``@code{(}'' and a ``@code{)}'' respectively:
593 @lilypond[fragment,relative 1, verbatim]
594 d4-( c16-)-( cis d e c cis d e-)-( d4-)
599 If you need two slurs at the same time (one for articulation, one for
600 phrasing), you can also make a phrasing slur with @code{\(} and
605 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
606 @c chromatic thing pasted in front. (admittedly the original does not
607 @c have a phrasing slur. The problem is that we do not want the slur
608 @c and the Phrasing slur to collide. We are trying to make a good
612 @lilypond[fragment,relative 1, verbatim]
613 a8-(-\( ais b c-) cis2 b'2 a4 cis, c-\)
618 Beams are drawn automatically, but if you do not like the choices, you
619 can enter beams by hand. Mark the first note to be beamed with
620 @code{[} and the last one with @code{]}:
622 @lilypond[fragment,relative 1, verbatim]
623 a8-[ ais-] d-[ es r d-]
628 To print more than one staff, each piece of music that makes up a staff
629 is marked by adding @code{\context Staff} before it. These
630 @code{Staff}'s are then grouped inside @code{<} and @code{>}, as is
634 @lilypond[fragment,verbatim]
636 \context Staff = staffA { \clef violin c'' }
637 \context Staff = staffB { \clef bass c }
642 In this example, @code{staffA} and @code{staffB} are names that are
643 given to the staves. It does not matter what names you give, as long
644 as each staff has a different name. If you give them the same name,
645 they are assumed to belong on the same staff, and will be printed like
650 We can now typeset a melody with two staves:
653 @lilypond[verbatim,singleline]
656 < \context Staff = staffA {
660 e2-( d4 c2 b4 a8-[ a-]
661 b-[ b-] g-[ g-] a2.-) }
663 \context Staff = staffB {
674 Notice that the time signature is specified in one melody staff only
675 (the top staff), but is printed on both. LilyPond knows that the time
676 signature should be the same for all staves.
680 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
682 @lilypond[verbatim,relative 1]
688 Similarly, fingering indications can be added to a note using @code{-}
689 and the digit to be printed.
690 @lilypond[verbatim,relative 1]
698 Dynamic signs are made by adding the markings to the note:
700 @lilypond[verbatim,relative 1]
706 Crescendi and decrescendi are started with the commands @code{\<} and
707 @code{\>}. The command @code{\!} finishes a crescendo on the note it
710 @lilypond[verbatim,relative 1]
711 c2-\< c2-\!-\ff c2-\> c2-\!
716 Chords can be made by
717 surrounding pitches with @code{<<} and @code{>}>:
719 @lilypond[relative 0, fragment,verbatim]
720 r4 <<c e g>>4 <<c f a>>8
726 You can combine beams and ties with chords. Beam and tie markings
727 must be placed outside the chord markers:
729 @lilypond[relative 0, fragment,verbatim]
730 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
736 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
738 @lilypond[relative 0, fragment]
740 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
746 A pickup (or upstep) is entered with the keyword @code{\partial}. It
747 is followed by a duration: @code{\partial 4} is a quarter note upstep.
748 @lilypond[relative 1,verbatim,fragment]
753 Tuplets are made with the @code{\times} keyword. It takes two
754 arguments: a fraction and a piece of music. The duration of the piece
755 of music is multiplied by the fraction. Triplets make notes occupy
756 2/3 of their notated duration, so for a triplet, the fraction is 2/3.
758 @lilypond[relative 0,verbatim,fragment]
759 \times 2/3 { f8 g a }
766 Comments are pieces of the input that are ignored. There are two
767 types of comments. A line comments are introduced by @code{%}: after
768 that, the rest of that line is ignored. Block comments span larger
769 sections of input. Anything that is enclosed in @code{%@{} and
770 @code{%@}} is ignored too. The following fragment shows possible uses
774 % notes for twinkle twinkle follow:
779 This line, and the notes below
780 are ignored, since they are in a
791 @node Printing lyrics
792 @section Printing lyrics
795 Lyrics are entered by separating each syllable with a space, and
796 surrounding them with @code{\lyrics @{ @dots{} @}}, for example
798 \lyrics @{ I want to break free @}
801 Like notes, lyrics are also a form of music, but they must not be
802 printed on a staff, which is the default way to print music. To print
803 them as lyrics, they must be marked with @code{ \context Lyrics}:
805 \context Lyrics \lyrics @{ I want to break free @}
807 The melody for this song is as follows
808 @lilypond[fragment,relative=1]
811 \times 2/3 { f4 g g } \times 2/3 { g4-( a2-) }
814 The lyrics can be set to these notes, combining both with the
815 @code{\addlyrics} keyword:
819 \context Lyrics @dots{}
823 @lilypond[singleline,verbatim]
830 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
832 \context Lyrics \lyrics { I want to break free }
838 This melody ends on a @rglos{melisma}, a single syllable (``free'')
839 sung to more than one note. This is indicated with a @emph{extender
840 line}. It is entered as two underscores, i.e.,
842 \lyrics @{ I want to break free __ @}
844 @lilypond[singleline]
851 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
853 \context Lyrics \lyrics { I want to break free __ }
859 Similarly, hyphens between words can be entered as two dashes,
860 resulting in a centered hyphen between two syllables.
862 Twin -- kle twin -- kle
864 @lilypond[singleline]
866 \addlyrics \notes \relative f' { \time 2/4
868 \context Lyrics \lyrics { Twin -- kle twin -- kle
872 More options, like putting multiple lines of lyrics below a melody are
873 discussed in @ref{Vocal music}.
878 In popular music, it is common to denote accompaniment as chord-names.
879 Using them in LilyPond has two parts, just like lyrics: entering the
880 chords (with @code{\chords}), and printing them (with @code{\context
883 Chord names are entered by starting chords mode (with @code{\chords}).
884 In chords mode, you can enter chords with a letter (indicating the
885 root of the chord), and a durations following that.
888 \chords { c2 f4. g8 }
890 The result of @code{\chords} is a list of chords, and is equivalent
891 to entering chords with @code{<<@dots{}>>}.
893 Other chords can be created by adding modifiers, after a colon. The
894 following example shows a few common modifiers
897 \chords { c2 f4:m g4:maj7 gis1:dim7 }
900 Printing chords is done by adding @code{\context ChordNames}
901 before the chords thus entered:
904 \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
907 A complete list of modifiers, and other options for layout are in the
908 reference manual section @ref{Chords}.
911 @section A lead sheet
914 TODO: template example with chord names, lyrics and staff.
917 @node Listening to output
918 @section Listening to output
922 \midi @{ \tempo 4=72@}
925 MIDI (Musical Instrument Digital Interface) is a standard for
926 connecting and recording digital instruments. A MIDI file is like a
927 tape recording of a MIDI instrument. The @code{\midi} block makes the
928 music go to a MIDI file, so you can listen to the music you entered.
929 It is great for checking the music: octaves that are off, or
930 accidentals that were mistyped, stand out very much when listening to
931 the musical transcription.
933 @code{\midi} is similar to @code{\paper @{ @}}, since it also
934 specifies an output method. You can specify the tempo using the
935 @code{\tempo} command, in this case the tempo of quarter notes is set
936 to 72 beats per minute.
942 @section More movements
944 The program @code{lilypond} only produces sheet music. Titles,
945 subtitles, and the composer's name are created by a separate program,
946 called use @code{ly2dvi}. @code{ly2dvi} creates the titles, then
947 calls @code{lilypond} to format the sheet music. In this section, we
948 show you how to create titles like this:
950 @center @strong{Two miniatures}
962 \paper { raggedright = ##t }
974 \paper { linewidth = -1.0 }
978 For example, consider the following file (@file{miniatures.ly})
982 title = "Two miniatures"
983 composer = "F. Bar Baz"
984 tagline = "small is beautiful" @}
1001 The information for the global titling is in a so-called header block.
1002 The information in this block is not used by LilyPond, but it is
1003 passed into @code{ly2dvi}, which uses this information to print titles
1006 @cindex identifier assignment
1007 the @code{\header} block contains assignments. In each assignment, a
1008 variable is set to a value. The header block for this file looks like
1010 @cindex @code{\header}
1013 title = "Two miniatures"
1014 composer = "F. Bar Baz"
1015 tagline = "small is beautiful"
1019 When you process a file with ly2dvi, a signature line is printed at
1020 the bottom of the last page. Many people find the default (``Lily was
1021 here'' with a version number) too droll. If that is the case, you can
1022 change @code{tagline} in the @code{\header}, as shown above.
1024 @cindex Lily was here
1025 @cindex signature line
1034 The @code{\header} is normally at the top of the file, where it sets
1035 values for the rest of the file. If you want to typeset different
1036 pieces from one file (for example, if there are multiple movements, or
1037 if you are making an exercise book), you can put different
1038 @code{\score} blocks into the input file. @code{ly2dvi} will assemble
1039 all LilyPond output files into a one document. The contents of
1040 @code{\header} blocks specified within each score is used for the
1041 title of that movement.
1047 For example, the Opus number is put at the right, and the "piece" string
1048 will be at the left.
1052 @node Organising larger pieces
1053 @sections Organising larger pieces
1055 TODO: discuss identifiers, p&c, .
1061 Lilypond and its language are still under development, and
1062 occasionally details of the syntax are changed. The @code{version}
1063 fragment indicates which LilyPond version the input file was written
1064 for. When you compile this file, the version number will be checked
1065 and you will get a warning when the file is too old. This version
1066 number is also used by the @code{convert-ly} program (See
1067 @ref{Invoking convert-ly}), which can used to update the file to the
1068 latest lily version.
1071 @node A piano excerpt
1072 @section A piano excerpt
1074 Our eighth subject is a piece of piano music. The fragment in the
1075 input file is a piano reduction of the G major Sinfonia by Giovanni
1076 Battista Sammartini, composed around 1740. It's in the source
1077 package under the name @inputfileref{input/tutorial,sammartini.ly}.
1079 @lilypondfile[smallverbatim]{sammartini.ly}
1081 As you can see, this example features multiple voices on one staff. To
1082 make room for those voices, their notes should be stemmed in opposite
1089 viola = \notes \relative c' \context Voice = viola @{
1091 In this example you see multiple parts on a staff. Each part is
1092 associated with one notation context. This notation context handles
1093 stems and dynamics (among other things). The type name of this
1094 context is @code{Voice}. For each part we have to make sure that
1095 there is precisely one @code{Voice} context, so we give it a unique
1096 name (`@code{viola}').
1110 Relative octaves work a little differently with chords. The starting
1111 point for the note following a chord is the first note of the chord. So
1112 the @code{g} gets an octave up quote: it is a fifth above the starting
1113 note of the previous chord (the central C).
1119 @code{s} is a spacer rest. It does not print anything, but it does have
1120 the duration of a rest. It is useful for filling up voices that
1121 temporarily do not play. In this case, the viola does not come until one
1122 and a half measure later.
1126 oboes = \notes \relative c'' \context Voice = oboe @{
1128 Now comes a part for two oboes. They play homophonically, so we
1129 print the notes as one voice that makes chords. Again, we insure that
1130 these notes are indeed processed by precisely one context with
1134 s4 g8. b,16 c8 r <<e' g>>8. <<f a>>16
1137 The oboes should have stems up to keep them from interfering with
1138 the staff-jumping bass figure. To do that, we use @code{\voiceOne}.
1142 \grace <<e g>>-( <<d f>>4-) <<c e>>2
1144 @cindex @code{\grace}
1147 @code{\grace} introduces grace notes. It takes one argument, in this
1148 case a chord. A slur is introduced starting from the @code{\grace}
1149 ending on the following chord.
1160 @{ <<d f>>8 <<e g>> <<f a>> @}
1162 The piece of music to be `tripletted' is sequential music containing
1169 At this point, the homophonic music splits into two rhythmically
1170 different parts. We cannot use a sequence of chords to enter this, so
1171 we make a "chord of sequences" to do it. We start with the upper
1172 voice, which continues with upward stems:
1175 @{ \times 2/3 @{ a8 g c @} c2 @}
1182 Entering multiple voices is demonstrated here. Separate the
1183 components of the voice (single notes or entire sequences) with
1184 @code{\\} in a simultaneous music expression. The @code{\\} separators
1185 split first voice, second voice, third voice, and so on.
1187 As far as relative mode is concerned, the previous note is the
1188 @code{c'''2} of the upper voice, so we have to go an octave down for
1196 This ends the two-part section.
1199 \grace <<c, e>>8-( <<b d>>8.-\trill <<c e>>16 |
1204 The bass has a little hoom-pah melody to demonstrate parts switching
1205 between staves. Since it is repetitive, we use repeats:
1208 hoomPah = \repeat unfold 8
1210 @cindex unfolded @code{\repeat}
1211 The unfolded repeat prints the notes in its argument as if they were
1212 written out in full eight times.
1215 @cindex staff switch, manual
1216 @cindex cross staff voice, manual
1217 @cindex @code{\translator}
1220 \translator Staff = down
1223 \translator Staff = up
1227 Voices can switch between staves. Here you see two staff switching
1228 commands. The first one moves to the lower staff, the second one to
1229 the lower one. If you set the stem directions explicitly
1230 (using the identifiers @code{\stemUp} and @code{\stemDown}, the notes
1231 can be beamed together (despite jumping between staffs).
1235 bassvoices = \notes \relative c' @{
1237 \autochange Staff \hoomPah \context Voice
1242 \translator Staff = down
1244 @cindex staff switch
1245 @cindex cross staff voice
1246 We want the remaining part of this melody on the lower staff, so we do a
1247 manual staff switch here.
1256 A special context is needed to get cross staff beaming right. This
1257 context is called @code{PianoStaff}.
1260 \context Staff = bottom < \time 2/2 \clef bass
1262 The bottom staff must have a different clef.
1267 To make some more room on the line, the first (in this case the only)
1268 line is not indented. The line still looks very cramped, but that is due
1269 to the page layout of this document.
1277 * Simple part combining in a Hymn
1281 @node Fine tuning a piece
1282 @section Fine tuning a piece
1284 In this section we show some ways to fine tune the final output of a
1285 piece. We do so using a single measure of a moderately complex piano
1286 piece: a Brahms intermezzo (opus 119, no. 1). Both fragments (the
1287 tuned and the untuned versions) are in @file{input/tutorial/}.
1289 The code for the untuned example shows us some new things.
1291 @lilypondfile[verbatim]{brahms-original.ly}
1302 Now that we have the basic piece of music entered, we want to fine
1303 tune it so that we get something that resembles the original printed
1304 edition by Schott/Universal Edition:
1306 @lilypondfile{brahms-tweaked.ly}
1308 @cindex tuning graphical objects
1310 Fine tuning involves overriding the defaults of the printing system.
1311 We do this by setting variables which control how Lilypond prints
1312 symbols. Printed symbols are called graphical objects (often
1313 abbreviated to @emph{grob}). Each object is described by a bunch of
1314 settings. Every setting is a variable: it has a name and a value
1315 which you can change. These values determine the fonts, offsets,
1316 sub-routines to be called on the object, etc. The initial values of
1317 these settings are set in the Scheme file
1318 @file{scm/grob-description.scm}.
1320 @cindex slur attachments
1322 We start with the slur in the upper part, running from F sharp to A. In
1323 the printed edition, this slur runs from stem to stem; in our version,
1324 the slur begins at the note head of the F sharp. The following property
1325 setting forces all slurs to run from stem to stem (not from or to note
1329 \property Voice.Slur \set #'attachment = #'(stem . stem)
1332 More precisely, this command modifies the definition of the @code{Slur}
1333 object in the current @code{Voice}. The variable @code{attachment} is
1334 set to the pair of symbols @code{'(stem . stem)}.
1336 @cindex internal documentation
1337 @cindex finding graphical objects
1338 @cindex graphical object descriptions
1340 This command fixes one particular problem with a slur. The rest of
1341 this section explains how to figure out which properties to tune for
1342 your own scores. To discover this, you must have a copy of the
1343 internals document. This is a set of HTML pages which should be
1344 included if you installed a binary distribution. [TODO: revise for
1345 new site.] These HTML pages are also available on the web: go to the
1346 LilyPond website, click ``Documentation: Index'' on the side bar, look
1347 in the ``Information for uses'' section, and click on ``Documentation
1350 You might want to bookmark either the HTML files on your disk, or the
1351 one on the web (the HTML on your hard drive will load much faster than
1352 the ones on the web!). One word of caution: the internals
1353 documentation is generated from the definitions that the program uses.
1354 Hence, the internals documentation is strongly tied to the version you
1355 use. Before you proceed, make sure that the program and documentation
1356 have matching version numbers.
1358 @c TODO: the quote is incorrect, although that shouldn't be a big
1359 @c problem for the reader.
1360 Suppose that you wanted to tune the behavior of the slur. The first
1361 step is to get some general information on slurs in LilyPond. Turn to
1362 the index, and look up ``slur''. The section on slurs says
1364 The grob for this object is @internalsref{Slur}, generally in
1365 @internalsref{Voice} context.
1368 So the graphical object for this object is called @code{Slur}, and
1369 slurs are created in the @code{Voice} context. If you are reading
1370 this tutorial in the HTML version, then you can simply click Slur,
1371 otherwise, you should look it up the internal documentation: click
1372 ``grob overview'' and select ``slur'' (the list is alphabetical).
1374 Now you get a list of all the properties that the slur object
1375 supports, along with their default values. Among the properties we
1376 find the @code{attachment} property with its default setting.
1377 The property documentation explains that the following setting will
1378 produce the desired effect:
1380 \property Voice.Slur \set #'attachment = #'(stem . stem)
1383 @c this is a long section, and adding an extra space here helps to
1384 @c break it into smaller subsections and thus is easier to understand.
1387 Next we want to move the fingering `3'. In the printed edition it is
1388 not above the stem, but a little lower and slightly left of the stem.
1389 From the user manual we find that the associated graphical object is
1390 called @code{Fingering}, but how do we know if we should use
1391 @code{Voice} or @code{Staff}? In many cases, @code{Voice} is a safe
1392 bet, but you can also deduce this information from the internals
1393 documentation: if you visit the documentation of @code{Fingering}, you
1396 Fingering grobs are created by: Fingering_engraver
1399 Clicking @code{Fingering_engraver} will show you the documentation of
1400 the module responsible for interpreting the fingering instructions and
1401 translating them to a @code{Fingering} object. Such a module is called
1402 an @emph{engraver}. The documentation of the @code{Fingering_engraver}
1405 Fingering_engraver is part of contexts: Voice and TabVoice
1407 so tuning the settings for Fingering should be done using either
1409 \property Voice.Fingering \set @dots{}
1413 \property TabVoice.Fingering \set @dots{}
1416 Since the @code{TabVoice} is only used for tab notation, we see that
1417 the first guess @code{Voice} was indeed correct.
1419 @cindex setting object properties
1420 @cindex @code{extra-offset}
1422 For shifting the fingering, we use the property @code{extra-offset}.
1423 The following command manually adds an offset to the object. We move
1424 it a little to the left, and 1.8 staff space downwards.
1426 \once \property Voice.Fingering \set #'extra-offset = #'(-0.3 . -1.8)
1428 The @code{extra-offset} is a low-level feature: it moves around
1429 objects in the printout; the formatting engine is completely oblivious
1430 to these offsets. The unit of these offsets are staff-spaces. The
1431 first number controls left-right movement; a positive number will move
1432 the object to the right. The second number controls up-down movement;
1433 a positive number will move it higher.
1434 We only want to offset a single object, so this statement is adorned
1437 @cindex property types
1438 @cindex translator properties
1439 @cindex grob properties
1440 @cindex music properties
1443 There are three different types of variables in LilyPond, something
1444 which can be confusing at first (and for some people it stays
1445 confusing). Variables such as @code{extra-offset} and
1446 @code{attachment} are called grob properties. They are not the same
1447 as translator properties, like @code{autoBeaming}. Finally, music
1448 expressions are internally stored using properties (so-called music
1449 properties). You will encounter music properties if you run Scheme
1450 functions on music using @code{\apply}.
1452 The second fingering instruction should be moved up a little to avoid
1453 a collision with the slur. This could be achieved with
1454 @code{extra-offset}, but in this case, a simpler mechanism also
1455 works. We insert an empty text between the 5 and the note. The empty
1456 text pushes the fingering instruction away:
1458 a-)^" "^\markup @{ \finger "5" @}
1461 A fingering instruction, which would be entered as @code{^5}, is put
1462 as close to the notes as possible, closer than the space entered to
1463 push away the 5. Hence, the 5 is entered as a normal text, with the
1464 formatting of fingering instructions.
1468 Normally one would specify all dynamics in the same voice, so that
1469 dynamics (such as @b{f} and @b{p}) will be aligned with hairpins. But
1470 in this case, we do not want the decrescendo to be aligned with the
1471 piano sign. We achieve this by putting the dynamic markings in different
1472 voices. The crescendo should be above the upper staff. This can be
1473 forced by using the precooked command
1478 However, if you do that the decrescendo will be too close to the upper
1479 voice and collide with the stems. Looking at the manual for dynamics,
1480 we notice that ``Vertical positioning of these symbols is handled by
1481 the @internalsref{DynamicLineSpanner} grob.''. If we turn to the
1482 documentation of @code{DynamicLineSpanner}, we find that
1483 @code{DynamicLineSpanner} supports several so-called `interfaces'.
1484 This object not only puts objects next to the staff
1485 (@code{side-position-interface}), but it also groups dynamic objects
1486 (@code{axis-group-interface}), is considered a dynamic sign itself
1487 (@code{dynamic-interface}), and is an spanning object
1488 (@code{spanner-interface}). It also has the standard
1489 @code{grob-interface} with all the variables that come with it.
1491 For the moment we are interested in side positioning:
1493 side-position-interface
1495 Position a victim object (this one) next to other objects (the
1496 support). In this case, the direction signifies where to put the
1497 victim object relative to the support (left or right, up or down?)
1499 Between the object and its support (in this case, the descending
1500 notes), there should be more space. This space is controlled by
1501 @code{padding}, so we increase it.
1503 \property Voice.DynamicLineSpanner \override #'padding = #5.0
1507 (TODO: huh? what's this: )
1509 This command resembles the one for setting slur attachments, but
1510 subtly differs in its details. Grob properties can be manipulated
1511 with two commands: @code{\override} extends the definition of a grob
1512 with one setting, and @code{\revert} releases this setting. This has
1513 a theoretical appeal: the operations are simple and symmetric. For
1514 practical use, it can be cumbersome. The commands act like
1515 parentheses: you should carefully balance the use of @code{\override}
1516 and @code{\revert}. The @code{\set} command is more friendly: it
1517 first does a @code{\revert} followed by @code{\override}.
1521 Brahms uses music notation is a slightly unorthodox way. Ties
1522 usually happen only within one voice. In this piece, the composer
1523 gladly produces ties that jump voices. We deal with this by faking
1524 these ties: whenever we need such a tie, we insert a notehead in a
1525 different voice, and blank the stem. This is done in the following
1528 @cindex transparent objects
1529 @cindex removing objects
1530 @cindex invisible objects
1532 \property Voice.Stem \set #'transparent = ##t
1535 Blanking the stem should be done for only one object. One of the ways
1536 to achieve that, is by setting the property before a note. Reverting
1537 it afterwards is tedious, so for setting a property only once, we have
1538 the syntax @code{\once}: it reverts the property directly before
1539 proceeding to the next step in time.
1541 The @code{\once} keyword is added to @code{\property}.
1544 Finally, the last tie is forced up using @code{\tieUp}.
1548 Here is the complete ``fine tuned'' version, which includes all the
1549 modifications we discussed in this section:
1551 @lilypondfile[verbatim]{brahms-tweaked.ly}
1554 @node An orchestral score
1555 @section An orchestral score
1559 * Extracting an individual part::
1563 Our next two examples demonstrate one way to create an orchestral score
1564 in LilyPond. When typesetting a piece for several instruments, you'll
1565 want to create a full score (for the conductor) along with several
1566 individual parts (for the players).
1568 We will declare the music for each instrument individually, giving
1569 the music of each instrument its own name. These pieces of music are
1570 then combined in different @code{\score} blocks to produce different
1571 combinations of instruments (for example, one @code{\score} block may
1572 only include the cello part; another @code{\score} block may be for
1573 all the strings, and yet another @code{\score} block may be for all
1576 This orchestral score example consists of three input files. In the
1577 first file, @file{os-music.ly}, we define the music for all
1578 instruments. This file will be used for producing the score and the
1579 separate parts, but the file does not produce any sheet music itself.
1580 Other files reference it by stating @code{\include "os-music.ly"}.
1585 title = "Zo, goed lieverd?"
1586 subtitle = "How's, this babe?"
1595 Key = \notes \key as \major
1596 flautoI = \notes\relative c'' @{
1598 bes as bes as bes as bes as
1600 flautoII = \notes\relative c'' @{
1601 as8 bes as bes R1 d4 ~ d
1603 tromboI = \notes\relative c'' @{
1604 c4. c8 c8 c4. es4 r as, r
1606 tromboII = \notes\relative c'' @{
1607 as4. as8 as8 as4. R1*1/2 as4 es'
1609 timpani = \notes\relative c, @{
1610 \times 2/3 @{ f4 f f @}
1611 \times 4/5 @{ as8 as as as as @}
1614 corno = \notes\relative c' @{
1615 bes4 d f, bes d f, bes d
1619 We will not examine this example line by line, since you already know
1620 most of it. We'll examine a few lines which contain new elements.
1631 This declares settings to be used globally. The @code{\skip} command
1632 produces no output, but moves forward in time: in this case, the
1633 duration of a half note (@code{2}), and that four times (@code{*4}).
1634 This brings us to the end of the piece, and we can set the end bar.
1635 You can use @code{s} as a shortcut for @code{\skip} (the last line of
1636 this section would be @code{s2*4 \bar"|."}).
1640 Key = \notes \key as \major
1642 This declares the key signature of the piece and assign it to the
1643 identifier @var{Key}. Later on we will use @code{\Key} for all staves
1644 except those for transposing instruments.
1646 @node The full score
1647 @subsection The full score
1650 The second file, @inputfileref{input/tutorial,os-score.ly}, reads the
1651 definitions of the first (@inputfileref{input/tutorial,os-music.ly}), and
1652 defines the @code{\score} block for the full conductor's score.
1657 \include "os-music.ly"
1658 \include "paper13.ly"
1660 textFlat = \markup @{\smaller \musicglyph #"accidentals--1"@}
1664 \property Score.BarNumber \override #'padding = #3
1665 \context StaffGroup = woodwind <
1666 \context Staff = flauti <
1667 \property Staff.midiInstrument = #"flute"
1668 \property Staff.instrument = "2 Flauti"
1669 \property Staff.instr = "Fl."
1671 \context Voice=one @{ \voiceOne \flautoI @}
1672 \context Voice=two @{ \voiceTwo \flautoII @}
1675 \context StaffGroup = timpani <
1676 \context Staff = timpani <
1677 \property Staff.midiInstrument = #"timpani"
1678 \property Staff.instrument = \markup @{ \column << "Timpani" "(C-G)" >> @}
1679 \property Staff.instr = #"Timp."
1685 \context StaffGroup = brass <
1686 \context Staff = trombe <
1687 \property Staff.midiInstrument = #"trumpet"
1688 \property Staff.instrument = \markup @{ \column << "2 Trombe" "(C)" >> @}
1689 \property Staff.instr = \markup@{ \column << "Tbe." "(C)">> @}
1691 \context Voice=one \partcombine Voice
1692 \context Thread=one \tromboI
1693 \context Thread=two \tromboII
1695 \context Staff = corni <
1696 \property Staff.midiInstrument = #"french horn"
1697 \property Staff.instrument
1698 = \markup @{ \column << "Corno" @{ "(E" \textFlat ")" @} >> @}
1699 \property Staff.instr =
1700 \markup @{ \column << "Cor." @{ "(E" \textFlat ")" @} >> @}
1701 \property Staff.transposing = #3
1702 \notes \key bes \major
1703 \context Voice=one \corno
1708 indent = 15 * \staffspace
1709 linewidth = 60 * \staffspace
1710 textheight = 90 * \staffspace
1713 \consists "Multi_measure_rest_engraver"
1716 \HaraKiriStaffContext
1717 \remove "Multi_measure_rest_engraver"
1726 @center @strong{Zo, goed lieverd?}
1728 @center How's, this babe?
1736 @lilypondfile{os-score.ly}
1740 \include "os-music.ly"
1742 First we need to include the music definitions we made in
1747 [TODO: mention in a more relevant place]
1751 #(ly:set-point-and-click 'line-column)
1754 This piece of Scheme code executes the function
1755 @code{ly:set-point-and-click} with the argument
1756 @code{line-column}. Editing input files can be complicated if you are
1757 working with large files: if you are digitizing existing music, you have
1758 to synchronize the .ly file, the sheet music on your lap and the sheet
1759 music on the screen. The point-and-click mechanism makes it easy to
1760 find the origin of an error in the LY file: when you view the file with
1761 Xdvi and click on a note, your editor will jump to the spot where that
1762 note was entered. For more information, see @ref{Point and click}.
1768 #(define text-flat '((font-relative-size . -2)
1769 (music "accidentals--1")))
1772 To name the transposition of the french horn, we will need a piece of
1773 text with a flat sign. LilyPond has a mechanism for font selection and
1774 kerning called Scheme markup text (See @ref{Text markup}). The flat
1775 sign is taken from the music font, and its name is @code{accidentals--1}
1776 (The natural sign is called @code{accidentals-0}). The default font is
1777 too big for text, so we select a relative size of @code{-2}.
1784 All staves are simultaneous and use the same global settings.
1788 \property Score.BarNumber \override #'padding = #3
1790 LilyPond prints bar numbers at the start of each line, but
1791 unfortunately they end up a bit too close to the staff in this
1792 example. In LilyPond, a bar number is called @var{BarNumber}.
1793 BarNumber objects can be manipulated through their
1794 @var{side-position-interface}. One of the properties of a
1795 @var{side-position-interface} that can be tweaked is @var{padding}:
1796 the amount of extra space that is put between this and other objects.
1797 We set the padding to three staff spaces.
1799 You can find information on all these kind of properties in LilyPond's
1800 automatically generated documentation in
1802 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}
1803 or in @ref{Fine tuning a piece}.
1806 the online documentation or in the previous section of the tutorial.
1813 \context StaffGroup = woodwind <
1814 \context Staff = flauti <
1816 A new notation context: the @code{StaffGroup}. @code{StaffGroup} can
1817 hold one or more @code{Staff}s, and will print a big bracket at the
1818 left of the score. This starts a new staff group for the woodwind
1819 section (just the flutes in this case). Immediately after that, we
1820 start the staff for the two flutes, who also play simultaneously.
1824 \property Staff.midiInstrument = #"flute"
1826 Specify the instrument for MIDI output (see @ref{MIDI instrument
1831 \property Staff.instrument = "2 Flauti"
1832 \property Staff.instr = "Fl."
1834 This defines the instrument names to be printed in the
1835 margin. @code{instrument} specifies the name for the first line
1836 of the score, @code{instr} is used for the rest of the score.
1842 The flutes play in the default key.
1846 \context Voice=one @{ \voiceOne \flautoI @}
1847 \context Voice=two @{ \voiceTwo \flautoII @}
1849 Last come the actual flute parts. Remember that we are still in
1850 simultaneous mode. We name both voices differently, so that LilyPond
1851 will create two Voice contexts. The flute parts are simple, so
1852 we specify manually which voice is which: @code{\voiceOne} forces the
1853 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
1861 Close the flutes staff and woodwind staff group.
1865 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
1867 The timpani staff demonstrates a new piece of scheme markup, it sets two
1872 \context Voice=one \partcombine Voice
1873 \context Thread=one \tromboI
1874 \context Thread=two \tromboII
1876 You have seen the notation contexts Staff and Voice, but here is a new
1877 one: Thread. One or more Threads can be part of a Voice. Thread
1878 takes care of note heads and rests; Voice combine note heads onto a
1881 For the trumpets we use the automatic part combiner (see @ref{Automatic
1882 part combining}) to combine the two simultaneous trumpet parts onto the
1883 trumpet staff. Each trumpet gets its own Thread context, which must be
1884 named @code{one} and @code{two}). The part combiner makes these two
1885 threads share a Voice when they are similar, and splits the threads up
1886 when they are different.
1890 \property Staff.instrument = #`(lines "Corno"
1891 (columns "(E" ,text-flat ")"))
1893 The french horn (``Corno'') has the most complex scheme markup name, made
1894 up of two lines of text. The second line has three elements (columns) --
1895 the @code{(E}, the flat sign @code{text-flat} that we defined previously,
1896 and a final @code{")"}. We use a backquote instead of an
1897 ordinary quote at the beginning of the Scheme expression to be able to
1898 access the @code{text-flat} identifier, `unquoting' it with a ``@code{,}''.
1902 \property Staff.transposing = #3
1904 The french horn is to be tuned in E-flat, so we tell the MIDI back-end to
1905 transpose this staff by three steps.
1907 Note how we can choose different tunings for the text input, sheet music
1908 output and, and MIDI output, using @code{\transpose} and the MIDI Staff
1909 property @var{transposing}.
1913 \notes \key bes \major
1915 Since the horn is transposing, it is in a different key.
1919 indent = 15 * \staffspace
1920 linewidth = 55 * \staffspace
1922 We specify a big indent for the first line and a small linewidth for this
1927 Usually the default setup of notation contexts (Thread, Voice, Staff,
1928 Staffgroup, Score) is just fine. But in this case we want a different
1929 type of Staff context.
1933 \HaraKiriStaffContext
1937 In orchestral scores it often happens that one instrument only has
1938 rests during one line of the score. @code{HaraKiriStaffContext} can
1939 be used as a regular @code{StaffContext} drop-in and will take care of
1940 the automatic removing of empty staves -- so if the strings are the
1941 only instruments playing for a line, LilyPond will only print the string
1942 parts for that line of the score. This reduces the number of page turns
1943 (and the number of dead trees!) required in a score.
1945 @node Extracting an individual part
1946 @subsection Extracting an individual part
1948 The third file, @file{os-flute-2.ly} also reads the definitions of the
1949 first (@file{os-music.ly}), and defines the @code{\score} block for the
1953 \include "os-music.ly"
1954 \include "paper16.ly"
1958 \property Score.skipBars = ##t
1959 \property Staff.midiInstrument = #"flute"
1965 instrument = "Flauto II"
1968 linewidth = 80 * \staffspace
1969 textheight = 200 * \staffspace
1977 @center @strong{Zo, goed lieverd?}
1979 @center How's, this babe?
1980 @center @emph{Flauto II}
1987 @lilypondfile{os-flute-2.ly}
1990 Because we separated the music definitions from the @code{\score}
1991 instantiations, we can easily define a second score with the music of
1992 the second flute. This is the part for the second flute player. Of
1993 course, we would make separate parts for all individual instruments if
1994 we were preparing the score for an orchestra.
2000 In this individual part the second flute has a whole staff for itself,
2001 so we do not want to force stem or tie directions.
2006 instrument = "Flauto II"
2009 The @code{\header} definitions were also read from @file{os-music.ly},
2010 but we need to set the instrument for this particular score.
2014 \property Score.skipBars = ##t
2016 In the conductor's full score, all bars with rests are printed, but for
2017 the individual parts, we want to print one multimeasure rest instead of
2018 many consecutive empty bars. LilyPond will do this if
2019 @code{Score.skipBars} is set to true (@code{##t}).
2022 @node Integrating text and music
2023 @section Integrating text and music
2026 @cindex La@TeX{}, music in
2027 @cindex HTML, music in
2028 @cindex Texinfo, music in
2030 Sometimes you might want to use music examples in a text that you are
2031 writing (for example a musicological treatise, a songbook, or (like us)
2032 the LilyPond manual). You can make such texts by hand, simply by
2033 importing a PostScript figure into your word processor. However,
2034 there is an automated procedure to reduce the amount of work.
2036 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
2037 code. A script called @code{lilypond-book} will extract the music
2038 fragments, run LilyPond on them, and put back the resulting notation.
2039 This program is fully described in @ref{lilypond-book manual}. Here
2040 we show a small example. Since the example also contains explanatory
2041 text, we will not comment it further.
2044 \documentclass[a4paper]@{article@}
2047 In a lilypond-book document, you can freely mix music and text. For
2050 \score @{ \notes \relative c' @{
2051 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
2055 Notice that the music line length matches the margin settings of the
2058 If you have no \verb+\score+ block in the fragment,
2059 \texttt@{lilypond-book@} will supply one:
2065 In the example you see here, two things happened: a
2066 \verb+\score+ block was added, and the line width was set to natural
2067 length. You can specify many more options using \LaTeX style options
2070 \begin[verbatim,11pt,singleline,
2071 fragment,relative,intertext="hi there!"]@{lilypond@}
2075 The option \texttt@{verbatim@} prints the LilyPond code in addition to
2076 the graphical score, \texttt@{11pt@} selects the default music size,
2077 \texttt@{fragment@} adds a score block, \texttt@{relative@} uses
2078 relative mode for the fragment, and \texttt@{intertext@} specifies
2079 what to print between the \texttt@{verbatim@} code and the music.
2081 If you want to include large examples into the text, it may be more
2082 convenient to put the example in a separate file:
2084 \lilypondfile[printfilename]@{sammartini.ly@}
2086 The \texttt@{printfilename@} option adds the file name to the output.
2091 Under Unix, you can view the results as follows.
2095 $ lilypond-book --outdir=out/ lilbook.tex
2096 lilypond-book (GNU LilyPond) 1.7.16
2097 Reading `input/tutorial/lilbook.tex'
2098 Reading `input/tutorial/sammartini.ly'
2099 @var{lots of stuff deleted}
2100 Writing `out/lilbook.latex'
2102 $ latex lilbook.latex
2103 @var{lots of stuff deleted}
2107 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
2108 and running latex creates a lot of temporary files, and you would not want
2109 those to clutter up your working directory. Hence, we have them created
2110 in a separate subdirectory.
2112 The result looks more or less like this:
2116 In a lilypond-book document, you can freely mix music and text. For
2120 \notes \relative c' {
2121 c2 g'2 \times 2/3 { f8 e d } c'2 g4
2129 Notice that the music line length matches the margin settings of the
2132 If you have no @code{\score} block in the fragment,
2133 @code{lilypond-book} will supply one:
2139 In the example you see here, a number of things happened: a
2140 @code{\score} block was added, and the line width was set to natural
2141 length. You can specify many more options using La@TeX{} style options
2144 @lilypond[verbatim,11pt,singleline,
2145 fragment,relative,intertext="hi there!"]
2149 The option @code{verbatim} also shows the LilyPond code, @code{11pt} selects
2150 the default music size, @code{fragment} adds a score block,
2151 @code{relative} uses relative mode for the fragment, and
2152 @code{intertext} specifies what to print between the
2153 @code{verbatim} code and the music.
2155 If you include large examples into the text, it may be more convenient
2156 to put the example in a separate file:
2158 @lilypondfile[printfilename]{sammartini.ly}
2160 The @code{printfilename} option adds the file name to the output.
2162 [TODO: include excercises? ]