3 @c TODO: LilyPond Lilypond lilypond
8 LilyPond prints music from a specification that you, the user, supply.
9 You have to give that specification using a textual @emph{language}.
10 This chapter is a gentle introduction to that language.
14 @c the first section is gentle
15 @c the later sections get rather high-brow, deep, detailed, thorough
18 This tutorial will demonstrate how to use Lilypond by presenting
19 examples of input along with resulting output. We will use English
20 terms for notation. In case you are not familiar with those, you may
21 consult the glossary that is distributed with LilyPond.
24 * Music language of LilyPond::
25 * Running LilyPond:: Getting started
26 * The first tune:: The first tune
27 * Lyrics and chords:: Lyrics and chords
29 * A piano excerpt:: Piano music
30 * An orchestral score::
31 * Other ways to run LilyPond::
32 * Integrating text and music::
33 * end of tutorial:: The end
36 @node Music language of LilyPond
37 @section Music language of LilyPond
41 @lilypond[verbatim, relative 1]
46 @lilypond[verbatim, relative 0]
51 @lilypond[verbatim, relative 1]
52 a1 a2 a8 a4 a16 a8. a16
55 octaves: high quote, low quote (comma)
56 @lilypond[verbatim, relative 1]
60 @c normal use of LilyPond is \relative note entry
61 @c so let's just show/explain that and make smart
62 @c people look for non-\relative
64 lilypond chooses nearest note
65 @lilypond[verbatim, relative 1]
69 to go other way: add octaviation quote
70 @lilypond[verbatim, relative 1]
75 @lilypond[verbatim, relative 1]
82 @lilypond[verbatim, relative 1]
83 \time 3/4 c c c | R1 * 3/4
87 @lilypond[verbatim, relative 0]
88 \key f \major es as bes
91 slur, tie, phrasing slur
92 @lilypond[verbatim, relative 1]
97 @lilypond[verbatim, relative 1]
101 suddenly lilypond gets really difficult:
102 [explain about score -> \score and \notes]
104 long chords; simultaneous music
108 % \paper { \singleLine }
109 \paper { linewidth = -1.0 }
111 \context Staff \notes \relative c'' <
119 \paper { linewidth = -1.0 }
121 \context GrandStaff \notes \relative c' <
129 @node Running LilyPond
130 @section Running LilyPond
132 Before we dive into describing the input language of LilyPond, we first
133 show you through the procedure for getting notes on your screen and out
136 The first step is creating an input file. Using your favorite
137 text-editor, create @file{test.ly} containing
141 NOTE: if you're reading this, ie, the Texinfo source itself, test.ly
142 should of course contain:
152 \notes @{ c'4 e' g' @}
156 @unnumberedsubsec Unix
157 @cindex Unix, Running lilypond on
160 On unix, you invoke ly2dvi to compile your lilypond source file (you can
161 omit the @code{.ly}):
167 You will see the following on your screen:
171 Now processing: `/home/fred/ly/test.ly'
173 Interpreting music...[1]
174 Preprocessing elements...
175 Calculating column positions... [2]
176 paper output to test.tex...
178 Analyzing test.tex...
181 PS output to test.ps...
182 DVI output to test.dvi...
185 The results of the ly2dvi run are a ``DeVice Independent'' file
186 (@file{test.dvi}) and a PostScript file (@file{test.ps}).
190 @cindex Viewing music
194 To view the @code{test.dvi} output, run Xdvi (you may omit the
201 @c FIXME: should we say anything on xdvi-gs interaction?
203 You should see the following in a window next to some buttons.
210 When you're satisfied with the result, you can print the
216 If this does not make your printer produce a page of music, you should
217 look into installing and configuring ghostscript. Refer to
218 GhostScript's website at @uref{http://www.ghostscript.com}.
221 @cindex Printing output
227 @unnumberedsubsec Windows
230 On windows, you open a LilyPond shell, and then you invoke ly2dvi
231 compile your lilypond source file, just like on Unix:
237 You will see the following on your screen:
239 @c FIXME: leave this out, just refer to unix section?
240 @c FIXME: commands run in dos shell: we can't redirect output
243 Now processing: `/home/tim/ly/test.ly'
245 Interpreting music...[1]
246 Preprocessing elements...
247 Calculating column positions... [2]
248 paper output to test.tex...
250 This is TeX, Version 3.14159 (MiKTeX 2)
252 Babel <v3.6Z> and hyphenation patterns for english, french, german, ngerman, du
253 mylang, nohyphenation, loaded.
255 (test.latex (C:\cygwin\usr\windows\MiKTeX\tex\latex\base\article.cls
256 Document Class: article 2000/05/19 v1.4b Standard LaTeX document class
257 (C:\cygwin\usr\windows\MiKTeX\tex\latex\base\size10.clo))
258 (C:\cygwin\usr\lilypond-1.3.150.jcn2\share\lilypond\tex\geometry.sty
259 (C:\cygwin\usr\windows\MiKTeX\tex\latex\graphics\keyval.sty))
260 (C:\cygwin\usr\windows\MiKTeX\tex\latex\base\inputenc.sty
261 (C:\cygwin\usr\windows\MiKTeX\tex\latex\base\latin1.def))
262 (C:\cygwin\usr\lilypond-1.3.150.jcn2\share\lilypond\tex\titledefs.tex)
265 (C:\cygwin\usr\lilypond-1.3.150.jcn2\share\lilypond\tex\lilyponddefs.tex
266 (C:\cygwin\usr\lilypond-1.3.150.jcn2\share\lilypond\tex\lilypond-latex.tex
268 (C:\cygwin\usr\lilypond-1.3.150.jcn2\share\lilypond\tex\feta20.tex)
269 (C:\cygwin\usr\lilypond-1.3.150.jcn2\share\lilypond\tex\lily-ps-defs.tex)
271 Overfull \hbox (15.0pt too wide) in paragraph at lines 20--24
274 Overfull \vbox (0.7539pt too high) has occurred while \output is active
276 (see the transcript file for additional information)
277 Output written on test.dvi (1 page, 4292 bytes).
278 Transcript written on test.log.
279 This is dvips(k) 5.86 Copyright 1999 Radical Eye Software (www.radicaleye.com)
280 ' TeX output 2001.04.25:0015' -> test.ps
281 <texc.pro><special.pro>. [1]
283 Analyzing test.tex...
284 PS output to test.ps...
285 DVI output to test.dvi...
288 To view the @code{test.dvi} output, run Yap
294 You should see the following in a window
301 @c FIXME: talk about newer Yap versions, proper gs installation?
302 When you're satisfied with the result, you can print from within Yap
303 (File/Print). Note that Yap may not display embedded PostScript symbols
304 such as beams and slurs. Don't worry, they'll be printed anyway.
306 You can also print the PostScript file directly from the
307 command line using GSview:
316 @section The first tune
319 @cindex examples, tutorial
321 The examples discussed are included in the distribution, in the
322 subdirectory @file{input/tutorial/}@footnote{When we refer
323 to filenames, they are relative to the top directory of the source
324 package. In binary installations you should look in your doc section,
325 eg, @code{/usr/share/doc/lilypond1.3/examples/input/tutorial}
327 }. We recommend that you experiment with writing Lilypond input
328 yourself, to get a feel for how the program behaves.
332 To demonstrate what LilyPond input looks like, we start off with a
333 full-fledged, yet simple example. It is a convoluted version
334 of the famous minuet in J. S. Bach's @emph{Klavierb@"uchlein}. The file
335 is included in the distribution as @file{minuet.ly}.
336 @cindex Bach, Johann Sebastian
339 % all text after a percent sign is a comment
340 % and is ignored by Lilypond
341 \include "paper16.ly"
344 \relative c'' \sequential {
349 d4 g,8 a b c d4 g, g |
350 e'4 c8 d e fis g4 g, g |
351 c4 d8( )c b a( )b4 c8 b a g |
352 a4 [b8 a] [g fis] g2. |
357 g4 e8 fis g d cis4 b8 cis a4 |
358 a8-. b-. cis-. d-. e-. fis-.
365 % standard settings are too wide for a book
371 We will analyse the input, line by line.
374 % all text after a percent sign is a comment
375 % and is ignored by Lilypond
377 The percent sign, @code{%}, introduces a line comment. You can also
378 comment out a block of several lines, by enclosing them in
379 @code{%@{} and @code{%@}}.
381 @cindex block comment
386 \include "paper16.ly"
389 @cindex @code{\include}
390 @cindex point, printer's
391 @cindex staff size setting
392 By default, LilyPond will typeset the music in a size such that each
393 staff is 20 point@footnote{A point is the standard measure of length for
394 printing; one point is 1/72.27 inch.} high. We want smaller
395 output (16 point staff height), so we must import the settings for that
396 size, which is done here.
403 Music is printed by combining a piece of music with directions for
404 outputting it. This combination is formed in the @code{\score} block.
411 Prepare LilyPond for accepting notes.
412 @cindex octaves, choosing
421 As we will see, each note is described by its note name, duration,
422 octave and possibly a chromatic alteration. In this setup, the octave
423 is indicated by using high quotes (@code{'}) and ``lowered quotes''
424 (commas: @code{,}). The central C is denoted by @code{c'}. The C one
425 octave higher is @code{c''}. One and two octaves below the central C is
426 denoted by @code{c} and @code{c,} respectively.
428 Even though a piece of music often spans a range of several octaves, it
429 mostly moves in small intervals. LilyPond has a special entry mode to
430 save typing in this situation. In this ``relative'' octave mode,
431 octaves of notes without quotes are chosen such that a note is as close
432 as possible (graphically, on the staff) to the preceding note. If you
433 add a high-quote an extra octave is added. A lowered quote (a comma)
434 will subtract an extra octave.
436 Because the first note has no predecessor,
437 you have to give the (absolute) pitch of the note to start with.
444 What follows is sequential music, i.e.,
445 @cindex sequential music
446 notes that are to be played and printed after each other.
453 @cindex time signature, setting
455 Set (or change) the time signature of the current piece: a 3/4 sign is
456 printed. The time signature setting is also used to generate bar lines
464 @cindex key signature, setting
466 Set (or change) the current key signature to G-major. Although in this
467 example, the @code{\key} command happened to be entered after the
468 @code{\time} command, in the output the time signature will be printed
469 after the key signature; LilyPond knows about music typesetting
477 The following piece of music is played twice. The first argument
478 indicates the type of repeat. In this case, @code{"volta"} means that
479 prima volta/secunda volta brackets are used for the alternative
480 endings---if there were any.
487 The subject of the repeat is again sequential music. Since
488 @code{\sequential} is such a common construct, a shorthand is provided:
489 just leave off @code{\sequential}, and the result is the same.
496 Two notes. The first note is a quarter note with relative pitch
497 @code{d}. The relative music was started with a @code{c''}, so the real
498 pitch of this note is @code{d''}. The duration of a note is designated
499 by a number; the @code{4} here represents a quarter note.
501 The second note is an eight note with relative pitch @code{g,}. The
502 pitch is taken relative to the previous @code{d''}, making this
503 note have real pitch @code{g'}. The @code{8} represents an eight note.
510 Two more notes, with pitch @code{a} and @code{b}. Because their
511 duration is the same as the @code{g,8}, there is no need to enter the
512 duration, but you may enter it anyway, i.e., @code{a4 b4}
521 @cindex errors, finding
522 Three more notes. The @code{|} character is a ``bar check''. LilyPond
523 will verify that bar checks are found at the start of a measure. This can
524 help you track down typing errors.
526 @cindex alteration, chromatic
527 @cindex chromatic alteration
534 So far, no notes were chromatically altered. Here is the first one that
535 is: @code{fis}. Lilypond by default uses Dutch@footnote{Note names are
536 available in several languages, but we find the Dutch names quite
537 convenient.} note names, and ``Fis'' is the Dutch note name for ``F
538 sharp''. However, there is no sharp sign in the output. The program
539 keeps track of key signatures, and will only print accidentals if they
542 For groups of eighth notes and shorter, LilyPond can determine how the
543 notes should form a beam. In this case, the 4 eights are automatically
548 c4 d8( )c b a( )b4 c8 b a g |
551 The beginning and ending notes of a slur are marked with parentheses,
552 @code{(} and @code{)} for start and end respectively. The line above
553 indicates two slurs. These slur markers (parentheses) are entered
554 between the slurred notes.
561 Automatic beaming can be overridden by inserting beam marks, @code{[}
562 and @code{]}. These beam markers (brackets) are put around the notes
570 @cindex augmentation dot
572 A period adds an augmentation dot to the note.
579 The end of the sequential music to be repeated. LilyPond will typeset a
587 Accidentals are printed whenever necessary: the first C sharp of the bar
588 will be printed with an accidental, the second one without.
592 a8-. b-. cis-. d-. e-. fis-.
596 You can enter articulation signs either in a verbose form or using a
597 shorthand. Here we demonstrate the shorthand: it is formed by a dash
598 and the character for the articulation to use, e.g. @code{-.} for
599 staccato as shown above.
607 Rests are denoted by the special notename @code{r}.
614 All articulations have a verbose form, like @code{\fermata}. The
615 command @code{\fermata} is not part of the core of the language, but it
616 is a shorthand for a more complicated description of a fermata symbol.
617 @code{\fermata} names that description and is therefore called an
620 @cindex @code{\fermata}
626 Here the music ends. LilyPond does not automatically typeset and end
627 bar, we must explicitely request one, using @code{"|."}.
637 The @code{\paper} block specifies how entered music should be converted
638 to notation output. Most of the details of the conversion (font sizes,
639 dimensions, etc.) have been taken care of, but to fit the output in this
640 document, it has to be narrower. We do this by setting the line width
641 to 14 centimeters (approximately 5.5 inches).
648 The last brace ends the @code{\score} block.
653 @node Lyrics and chords
654 @section Lyrics and chords
656 In this section we show how to typeset a song. This file is
657 included as @file{flowing.ly}.
661 title = "The river is flowing"
662 composer = "Traditional"
664 \include "paper16.ly"
665 melody = \notes \relative c' @{
669 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
670 c4 c8 d [es () d] c4 | d4 es8 d c4.
675 The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
676 ri -- ver is flo -- wing down to the sea.
679 accompaniment =\chords @{
681 c2:3- f:3-.7 d:min es4 c8:min r8
682 c2:min f:min7 g:7^3.5 c:min @}
687 \context ChordNames \accompaniment
690 \context Staff = mel @{
691 \property Staff.noAutoBeaming = ##t
692 \property Staff.automaticMelismata = ##t
695 \context Lyrics \text
697 \midi @{ \tempo 4=72 @}
698 \paper @{ linewidth = 10.0\cm @}
703 The result would look this.@footnote{The titling and font size shown
704 may differ, since the titling in this document is not generated by
707 @center @strong{The river is flowing}
712 title = "The river is flowing"
713 composer = "Traditional"
715 \include "paper16.ly"
716 melody = \notes \relative c' {
720 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
721 c4 c8 d [es () d] c4 | d4 es8 d c4.
726 The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
727 ri -- ver is flo -- wing down to the sea.
730 accompaniment =\chords {
732 c2:3- f:3-.7 d:min es4 c8:min r8
733 c2:min f:min7 g:7^3.5 c:min }
738 \context ChordNames \accompaniment
741 \context Staff = mel {
742 \property Staff.noAutoBeaming = ##t
743 \property Staff.automaticMelismata = ##t
746 \context Lyrics \text
748 \midi { \tempo 4=72 }
749 \paper { linewidth = 10.0\cm }
753 Again, we will dissect the file line by line.
760 @cindex @code{\header}
761 Information about the music you are about to typeset goes into a
762 @code{\header} block. The information in this block is not used by
763 LilyPond, but it is passed into the output. @file{ly2dvi} uses this
764 information to print titles above the music.
768 title = "The river is flowing"
769 composer = "Traditional (?)"
772 @cindex identifier assignment
773 the @code{\header} block contains assignments. In each assignment, a
774 variable is set to a value. Lexically, both the variable name and the
775 assigned value are strings. The values have to be quoted here, because
776 they contain spaces, the variable names could also be put within quotes
777 but it is not necessary.
781 \include "paper16.ly"
784 Smaller size for inclusion in a book.
788 melody = \notes \relative c' @{
791 The structure of the file will be the same as the previous one, a
792 @code{\score} block with music in it. To keep things readable, we will
793 give names to the different parts of music, and use the names to
794 construct the music within the score block.
801 @cindex @code{\partial}
803 The piece starts with an anacrusis of one eighth.
808 The key is C minor: we have three flats.
813 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
814 c4 c8 d [es () d] c4 | d4 es8 d c4.
819 @cindex manual beaming
820 @cindex automatic beaming, turning off
821 We use explicit beaming. Since this is a song, we turn automatic
822 beams off, and use explicit beaming where needed.
829 This ends the definition of @code{melody}.
838 @cindex identifier assignment
839 @cindex syllables, entering
840 Another identifier assignment. This one is for the lyrics.
841 Lyrics are formed by syllables that have duration, and not by
842 notes. To make LilyPond parse words as syllables, switch it into
843 lyrics mode with @code{\lyrics}. Again, the brace after @code{\lyrics}
844 is a shorthand for @code{\sequential @{}.
848 The4 ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
849 ri- ver is flo- __ wing down to the sea.
853 @cindex extenders, lyric
854 @cindex hyphens, lyric
855 The syllables themselves are separated by spaces. You can get syllable
856 extenders by entering @code{__}, and centered hyphens with
857 @code{-}@code{-}. We enter the syllables as if they are all quarter notes
858 in length (hence the @code{4}), and use a feature to align the
859 syllables to the music, which obviously isn't all quarter notes.
863 accompaniment =\chords @{
868 We'll put chords over the music. To enter them, there is a special mode
869 analogous to @code{\lyrics} and @code{\notes} mode, where you can give
870 the names of the chords you want, instead of listing the notes
871 comprising the chord.
878 There is no accompaniment during the anacrusis.
887 @cindex chord modifier
888 @cindex modifier, chord
889 A chord is started by the tonic of the chord. The
890 first one lasts a half note. An unadorned note creates a major
891 triad. Since a minor triad is wanted, @code{3-} is added to modify the
892 third to be small. @code{7} modifies (adds) a seventh, which is small by
893 default to create the @code{f a c es} chord. Multiple modifiers must be
902 Some modifiers have predefined names, eg. @code{min} is the same as
903 @code{3-}, so @code{d-min} is a minor @code{d} chord.
907 c2:min f:min7 g:7^3.5 c:min @}
910 @cindex named modifier
912 A named modifier @code{min} and a normal modifier @code{7} do not have
913 to be separated by a dot. Tones from a chord are removed with chord
914 subtractions. Subtractions are started with a caret, and they are
915 also separated by dots. In this example, @code{g:7^3.5} produces a
916 minor seventh. The brace ends the sequential music.
924 We assemble the music in the @code{\score} block. Melody, lyrics and
925 accompaniment have to sound at the same time, so they should be
926 @code{\simultaneous}.
927 @cindex @code{\simultaneous}
934 Chord mode generates notes grouped in @code{\simultaneous} music. If
935 you remove the comment sign, you can see the chords in normal
936 notation: they will be printed as note heads on a separate
937 staff. To print them as chords names, they have to be interpreted as
938 being chords, not notes. This is done with the following command:
942 \context ChordNames \accompaniment
946 @cindex interpretation context
947 @cindex notation context
950 Normally, the notes that you enter are transformed into note heads.
951 Note heads alone make no sense, they need surrounding information: a key
952 signature, a clef, staff lines, etc. They need @emph{context}. In
953 LilyPond, these symbols are created by objects called `interpretation
954 contexts'. Interpretation contexts exist for generating notation
955 (`notation context') and for generating sound (`performance
956 context'). These objects only exist during a run of LilyPond.
958 By default, LilyPond will create a Staff context for you. If you would
959 remove the @code{%} sign in the previous line, you would see that
962 We don't want that default here, because we want chord names. The
963 command above explicitly creates an interpretation context of
964 @code{ChordNames} type to interpret the music @code{\accompaniment}.
971 @cindex @code{\addlyrics}
972 @cindex lyrics and melody, combining
973 @cindex combining lyrics and melody
975 The lyrics should be aligned with the melody. This is done by
976 combining both with @code{\addlyrics}. @code{\addlyrics} takes two
977 pieces of music (usually a melody and lyrics, in that order) and
978 aligns the syllables of the second piece under the notes of the
979 first piece. If you would reverse the order, the notes would be
980 aligned on the lyrics, which is not very useful, and looks
985 \context Staff = mel @{
989 The second argument of @code{\addlyrics} is the melody. We instantiate
990 a @code{Staff} context explicitly: should you choose to remove the
991 comment before the ``note heads'' version of the accompaniment, the
992 accompaniment will be on a nameless staff. The melody has to be on
993 staff different from the accompaniment. This is accomplished by giving
994 the melody and accompaniment staffs different names.
998 \property Staff.noAutoBeaming = ##t
1002 @cindex context variables
1003 @cindex setting context variables
1004 An interpretation context has variables, called properties, that tune
1005 its behaviour. One of the variables is @code{noAutoBeaming}. Setting
1006 this Staff's property to @code{##t}, which is the boolean value @var{true},
1007 turns the automatic beaming mechanism off for the current staff.
1010 @cindex accessing Scheme
1011 @cindex evaluating Scheme
1014 LilyPond internally uses GUILE, a Scheme-interpreter. Scheme is a
1015 language from the LISP family. You can learn more about Scheme at
1016 @uref{http://www.scheme.org}. It is used to represent data throughout
1017 the whole program. The hash-sign (@code{#}) accesses GUILE directly: the
1018 code following the hash-sign is evaluated as Scheme. The boolean value
1019 @var{true} is @code{#t} in Scheme, so for LilyPond @var{true} looks like
1022 If Scheme scares you, don't worry. You don't need to know Scheme to
1023 create beautiful sheet music.
1030 \property Staff.automaticMelismata = ##t
1033 @cindex automaticMelismata
1035 @cindex @code{\addlyrics} and slurs
1036 Similarly, we don't want to print a syllable when there is
1037 a slur. This sets up @code{\addlyrics} to not put lyrics under each
1038 separate note while there is a slur.
1046 Finally, we put the melody on the current staff. Note that the
1047 @code{\property} directives and @code{\melody} are grouped in sequential
1048 music, so the property settings are done before the melody is
1053 \context Lyrics \text
1056 The second argument of @code{\addlyrics} is the text. The text also
1057 should not land on a Staff, but on a interpretation context for
1058 syllables, extenders, hyphens etc. This context is called
1063 \midi @{ \tempo 4=72@}
1066 MIDI (Musical Instrument Digital Interface) is a standard for
1067 connecting and recording digital instruments. So a MIDI file is like a
1068 tape recording of an instrument. The @code{\midi} block causes makes the
1069 music go to a MIDI file, so you can listen to the music you entered. It
1070 is great for checking the music. Whenever you hear something weird, you
1071 probably hear a typing error.
1073 Syntactically, @code{\midi} is similar to @code{\paper @{ @}}, since it
1074 also specifies an output method. You can specify the tempo using the
1075 @code{\tempo} command, in this case the tempo of quarter notes is set to
1076 72 beats per minute.
1080 \paper @{ linewidth = 10.0\cm @}
1083 We also want notation output. The linewidth is short so the piece
1084 will be set in two lines.
1086 @node More movements
1087 @section More movements
1089 [FIXME: merge here with, or move this to: Other ways to run LilyPond]
1091 You probably ran @file{ly2dvi} on the last example, and ended up with a
1092 viewable @file{.dvi} file. However, between there are a few steps of
1093 which LilyPond is only one. To enhance your understanding of what's
1094 happening under the hood when you run @code{ly2dvi}, we explain what
1097 @code{ly2dvi} is a program that calls a number of programs in sequence.
1098 The first thing it does, is running LilyPond on the input file. After
1099 some calculations, a @file{.tex} is produced. The contents
1100 of this file are very low-level instructions.
1102 For example, the following file (@file{miniatures.ly})
1106 \header @{ title = "Two miniatures" @}
1108 #(set! point-and-click line-column-location)
1110 \paper @{ linewidth = -1.0 @}
1113 \notes @{ c'4 d'4 @}
1119 \notes @{ d'4 c'4 @}
1126 The titling in this manual was not generated by ly2dvi, so we can't
1127 exactly show it would look, but the result should resemble this:
1129 @center @strong{Two miniatures}
1139 \paper { linewidth = -1.0 }
1151 \paper { linewidth = -1.0 }
1155 This file is produced by ly2dvi in a few stages, with the help of text
1156 formatting tools. LilyPond produces two output files, @file{miniatures.tex}
1157 and @file{miniatures-1.tex}. They both look like this:
1161 \placebox@{-5 \outputscale @}%
1162 @{ 8.7229 \outputscale @}%
1163 @{\magfontWXGEomMMBo\char90 @}%
1165 \placebox@{-4 \outputscale @}%
1166 @{ 81.0647 \outputscale @}%
1170 @file{ly2dvi} looks at what output LilyPond produces, and generates a
1171 file called @file{ly2dvi.out.tex}. This file contains formatting
1172 instructions for the title and page layout. A fragment might look like
1176 \def\lilypondopus@{Opus 1.@}
1177 \def\lilypondpiece@{Up@}
1178 \def\mustmakelilypondtitle@{@}
1179 \input miniatures.tex
1180 \def\lilypondtitle@{Two miniatures@}
1184 @file{ly2dvi} runs it through LaTeX. LaTeX is a text-formatting system
1185 built on top of @TeX{}. It's very popular in the academic world. If LaTeX
1186 is successful, this will produce a @file{.dvi} file, containing both the
1187 titling and the actual music. @code{ly2dvi} completes its task by
1188 deleting the two temporary files, leaving only @file{miniatures.dvi}.
1190 Next, now we'll look at the example line by line to explain new things.
1196 Lilypond and its language are still under development, and occasionally,
1197 details of the syntax are changed. This fragment indicates for which
1198 version the input file was written. When you compile this file, the
1199 version number will be checked, and you will get a warning when the file
1202 This version number is also used by the @code{convert-ly} program (See
1203 @ref{convert-ly}), which uses it to update the file to the latest lily
1208 \header @{ title = "Two miniatures" @}
1210 This sets the titling information for the entire file.
1214 #(set! point-and-click line-column-location)
1217 This piece of Scheme code sets the Scheme variable
1218 @code{point-and-click} to the value @var{line-column-location} (which
1219 itself is a Scheme procedure).
1221 Editing input files can be quite complicated if you're working with
1222 large files: if you're digitizing existing music, you have to
1223 synchronize the .ly file, the sheet music on your lap and the sheet
1224 music on the screen. The point-and-click mechanism makes it easy to
1225 find the origin of an error in the .ly file: when you view the file with
1226 Xdvi and click on a note, your editor will jump to the spot where that
1227 note was entered. For more information, see @ref{Point and click}.
1234 The @code{\score} blocks that follow in the file don't have
1235 @code{\paper} sections, so the settings of this block are substituted: A
1236 paper block, at top-level, i.e. not in a @code{\score} block sets the
1237 default page layout.
1246 The variable @code{linewidth} normally sets the length of the systems on
1247 the page. However, a negative value has a special meaning. If
1248 @code{linewidth} is less than 0, no line breaks are inserted into the
1249 score, and the spacing is set to natural length: a short phrase takes up
1250 little space, a longer phrase more space.
1255 \notes @{ c'4 d'4 @}
1258 In previous examples, notes were specified in relative octaves,
1259 i.e. each note was put in the octave that would put it closest to its
1260 predecessor. Besides relative, there is also absolute octave
1261 specification, which you get when you don't specify @code{\relative}. In
1262 this input mode, the central C is denoted by @code{c'}. Going down, you
1263 get @code{c} @code{c,} @code{c,,} etc. Going up, you get @code{c''}
1266 When you're copying music from existing sheet music, relative octaves
1267 are probably the easiest to use: it's less typing work and errors are
1268 easily spotted. However, if you write LilyPond input, either by hand
1269 (ie. composing) or by computer, absolute octaves are probably less work.
1277 The @code{\header} is normally at the top of the file, where it sets
1278 values for the rest of the file. If you want to typeset different pieces
1279 from one file (for example, if there are multiple movements, or if
1280 you're making an exercise book), you can put different @code{\score}
1281 blocks into the input file. ly2dvi will assemble all LilyPond output
1282 files into a big document. The contents of \header blocks specified
1283 within each score, are used for the titling of each movement.
1289 For example, the Opus number is put at the right, and the piece string
1290 will be at the left.
1294 @node A piano excerpt
1295 @section A piano excerpt
1297 Our fourth subject is a piece of piano music. The fragment in the input
1298 file is a piano reduction of the G major Sinfonia by Giovanni Battista
1299 Sammartini. It was composed around 1740. It's in the source package
1300 under the name @file{sammartini.ly}.
1303 \include "paper16.ly"
1305 stemDown = \property Voice.Stem \override #'direction = #-1
1306 stemUp = \property Voice.Stem \override #'direction = #1
1307 stemBoth = \property Voice.Stem \revert #'direction
1309 viola = \notes \relative c' \context Voice = viola {
1310 <c4-\f-\arpeggio g' c>
1316 oboes = \notes \relative c'' \context Voice = oboe {
1317 \stemUp s4 g8. b,16 c8 r <e'8.^\p g> <f16 a>
1318 \grace <e8( g> <d4 )f> <c2 e>
1319 \times 2/3 { <d8 \< f> <e g> <f a> }
1321 { \times 2/3 { a8 g c } \! c2 }
1322 \context Voice = oboeTwo {
1325 \property Grace.Stem \override #'direction = #-1
1331 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |
1332 [<d ( f> < )f8. a>] <)b,8 d> r [<d16( f> <f8. )a>] <b,8 d> r |
1333 [<c16( e> < )e8. g>] <c8 e,>
1336 hoomPah = \repeat unfold 8 \notes
1337 \transpose c' { \stemUp c8 \stemBoth \stemDown c'8 \stemBoth }
1339 bassvoices = \notes \relative c' {
1341 \autochange Staff \hoomPah
1342 \translator Staff = down
1343 \stemDown [c8 c'8] r4
1345 < {\stemUp r2 <e4 c'> <c8 g'> }
1346 \context Voice = reallyLow {\stemDown g2 ~ | g4 c8 } >
1350 \context PianoStaff \notes <
1351 \context Staff = up < \time 2/2
1355 \context Staff = down < \time 2/2 \clef bass
1362 linewidth = 15.0 \cm }
1366 If this looks like incomprehensible gibberish to you, you are right.
1367 This example has been doctored to have as many quirks as possible.
1369 As you can see, this example features multiple voices on one staff. To
1370 make room for those voices, their notes have to be stemmed in opposite
1373 Printed symbols are internally represented by so-called Graphical
1374 Objects (more colloquially: Grobs). These statements concern the
1375 grob called `Stem'. Each grob is described by a bunch of settings. These
1376 setting determine the fonts, offsets, sub-routines to be called on the
1377 grob, etc. The initial values of these settings are set in the Scheme
1378 file @file{scm/grob-description.scm}.
1382 stemDown = \property Voice.Stem \override #'direction = #-1
1385 Set a proprerty for all Stem grobs in the current Voice:
1386 @code{direction} is set to @code{-1}, which encodes down. The setting
1387 remains in effect until it is reverted.
1391 \property Voice.Stem \revert #'direction
1394 Revert the to the previous setting. The effect of precisely one
1395 @code{\stemDown} or @code{\stemUp} is neutralised.
1398 LilyPond includes the identifiers @code{\stemUp}, @code{\stemDown} along
1399 with some other commonly used formatting instructions, but to explain how
1400 it works, we wrote our own here. Of course, you should use predefined
1401 identifiers like these if possible: then you will be affected less by
1402 the implementation changes we occasionally make.
1406 viola = \notes \relative c' \context Voice = viola @{
1408 In this example, you can see multiple parts on a staff. Each part is
1409 associated with one notation context. This notation context handles
1410 stems and dynamics (among others). The name of this context is
1411 @code{Voice}. For each part we have to make sure that there is
1412 precisely one @code{Voice} context, so we give it an unique name
1417 <c4-\f-\arpeggio g' c>
1419 The delimiters @code{<} and @code{>} are shorthands for
1420 @code{\simultaneous @{} and @code{@}}. The expression enclosed in
1421 @code{<} and @code{>} is a chord.
1428 @code{\f} places a forte symbol under the chord. The forte applies to
1429 the whole chord, but the syntax requires that commands like forte and
1430 arpeggio are attached to a note, so here we attach them to the first
1433 @code{\arpeggio} typesets an arpeggio sign (a wavy vertical line) before
1446 Relative octaves work a little differently with chords. The starting
1447 point for the note following a chord is the first note of the chord. So
1448 the @code{g} gets an octave up quote: it is a fifth above the starting
1449 note of the previous chord (the central C).
1455 @code{s} is a spacer rest. It does not print anything, but it does have
1456 the duration of a rest. It is useful for filling up voices that
1457 temporarily don't play. In this case, the viola doesn't come until one
1458 and a half measure later.
1462 oboes = \notes \relative c'' \context Voice = oboe @{
1464 Now comes a part for two oboes. They play homophonically, so we
1465 print the notes as one voice that makes chords. Again, we insure that
1466 these notes are indeed processed by precisely one context with
1470 \stemUp s4 g8. b,16 c8 r <e'8.-\p g> <f16 a>
1472 @code{\stemUp} is a reference to the @code{\property \override} command
1476 \grace <e8 g> < d4 f> <c2 e>
1478 @cindex @code{\grace}
1482 @code{\grace} introduces grace notes. It takes one argument, in this
1486 The slur started on the @code{e} of the chord
1487 will be attached to the next note.@footnote{LilyPond will squirm
1488 about unended Slurs. In this case, you can ignore the warning}.
1496 Tuplets are made with the @code{\times} keyword. It takes two
1497 arguments: a fraction and a piece of music. The duration of the piece
1498 of music is multiplied by the fraction. Triplets make notes occupy 2/3
1499 of their notated duration, so in this case the fraction is 2/3.
1502 @{ <d8 \< f> <e g> <f a> @}
1504 The piece of music to be `tripletted' is sequential music containing
1505 three notes. On the first chord, a crescendo is started with
1506 @code{\<}. To be precise, the crescendo start is syntactically attached
1507 to the preceding note, the @code{d}.
1517 At this point, the homophonic music splits into two rhythmically
1518 different parts. We can't use a sequence of chords to enter this, so
1519 we make a `chord' of sequences to do it. We start with the upper
1520 voice, which continues with upward stems:
1523 @{ \times 2/3 @{ a8 g c @} \! c2 @}
1528 The crescendo is ended at the half note by the escaped exclamation
1532 \context Voice = oboeTwo @{
1535 We can't share stems with the other voice, so we have to create a new
1536 @code{Voice} context. We give it the name @code{oboeTwo} to distinguish
1537 it from the other context. Stems go down in this voice.
1542 @cindex Grace context
1543 When a grace section is processed, a @code{Grace} context is
1544 created. This context acts like a miniature score of its own. It has
1545 its own time bookkeeping, and you can make notes, beams, slurs
1546 etc. Here we fiddle with a property and make a beam. The argument of
1547 @code{\grace} is sequential music.
1551 \property Grace.Stem \override #'direction = #-1
1555 Normally, grace notes are always stem up, but in this case, the upper
1556 voice interferes. We set the stems down here.
1558 As far as relative mode is concerned, the previous note is the
1559 @code{c'''2} of the upper voice, so we have to go an octave down for
1567 This ends the two-part section.
1571 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |
1576 @code{\stemBoth} ends the forced stem directions. From here, stems are
1577 positioned as if it were single part music.
1579 The bass has a little hoom-pah melody to demonstrate parts switching
1580 between staffs. Since it is repetitive, we use repeats:
1583 hoomPah = \repeat unfold 8
1585 @cindex unfolded @code{\repeat}
1586 The unfolded repeat prints the notes in its argument as if they were
1587 written out in full eight times.
1590 \notes \transpose c' @{
1593 @cindex relative mode and transposing
1595 Transposing can be done with @code{\transpose}. It takes two arguments
1596 the first specifies what central C should be transposed to. The second
1597 is the to-be-transposed music. As you can see, in this case, the
1598 transposition has no effect, as central C stays at central C.
1600 The purpose of this no-op is circumventing relative mode. Relative mode
1601 can not be used together with transposition, so @code{\relative} will
1602 leave the contents of @code{\hoomPah} alone. We can use it without
1603 having to worry about getting the motive in a wrong octave.
1606 bassvoices = \notes \relative c' @{
1608 \autochange Staff \hoomPah
1610 @cindex staff switch, automatic
1611 @cindex cross staff voice, automatic
1612 @cindex @code{\autochange}
1614 Voices can switch between staffs. The easiest way to get this, is to use
1615 @code{\autochange}. This command looks at the pitch of each note, and if
1616 necessary, will cross to the other staff. For this to work, the two
1617 staffs must be called @code{"up"} and @code{"down"}.
1620 \translator Staff = down
1622 @cindex staff switch
1623 @cindex cross staff voice
1624 We want the remaining part of this melody on the lower staff, so we do a
1625 manual staff switch here.
1630 \context Voice = reallyLow @{\stemDown g2 ~ | g4 c8 @} >
1634 After skipping some lines, we see @code{~}. This mark makes ties. Note
1635 that ties and slurs are different things. A tie can only connect two
1636 note heads of the same pitch, whereas a slur can connect many chords
1643 A special context is needed to get cross staff beaming right. This
1644 context is called @code{PianoStaff}.
1647 \context Staff = bottom < \time 2/2 \clef bass
1649 The bottom staff must have a different clef.
1654 To make some more room on the line, the first (in this case the only)
1655 line is not indented. The line still looks very cramped, but that is due
1656 to the page layout of this document.
1662 * font-size, multi-stanza.
1664 * Simple part combining in a Hymn
1668 @node An orchestral score
1669 @section An orchestral score
1673 * Extracting an individual part::
1677 Our last two examples show a way to setup the music for an orchestral
1678 score. When typesetting a piece for several instruments, you'll want to
1679 create a conductor's full score, alongside several individual parts.
1681 LilyPond is well suited for this task. We will declare the music for
1682 each instrument individually, giving the music of each instrument its
1683 own name. These pieces of music are then combined in different
1684 @code{\score} blocks to produce different combinations of the score.
1686 This orchestral score example consists of three input files. In the
1687 first file, @file{os-music.ly}, we define the music for all instruments.
1688 This file will be used both for producing the score and the separate
1691 If you were to run lilypond on this file, no printable output would be
1697 title = "Zo, goed lieverd?"
1698 subtitle = "How's, this babe?"
1707 Key = \notes \key as \major
1708 flautoI = \notes\relative c'' @{
1710 bes as bes as bes as bes as
1712 flautoII = \notes\relative c'' @{
1713 as8 bes as bes R1 d4 ~ d
1715 tromboI = \notes\relative c'' @{
1716 c4. c8 c8 c4. es4 r as, r
1718 tromboII = \notes\relative c'' @{
1719 as4. as8 as8 as4. R1*1/2 as4 es'
1721 timpani = \notes\relative c, @{
1722 \times 2/3 @{ f4 f f @}
1723 \times 4/5 @{ as8 as as as as @}
1726 corno = \notes\relative c' @{
1727 bes4 d f, bes d f, bes d
1731 We will not go through the input line by line, but only indicate and
1732 explain the new elements.
1739 \skip 2*4 \bar "|.";
1743 Declare setting to be used globally. The @code{\skip} command produces
1744 no output, but moves forward in time: in this case, the duration of a
1745 half note (@code{2}), and that four times (@code{*4}). This brings us
1746 to the end of the piece, and we can set the end bar.
1750 Key = \notes \key as \major
1752 Declare the key signature of the piece and assign it to the identifier
1753 @var{Key}. Lateron, we'll use @code{\Key} for all staffs except those
1754 for transposing instruments.
1756 @node The full score
1757 @subsection The full score
1760 The second file, @file{os-score.ly} reads the definitions of the first
1761 (@file{os-music.ly}), and defines the @code{\score} block for the full
1767 \include "os-music.ly"
1768 \include "paper13.ly"
1770 #(set! point-and-click line-column-location)
1771 #(define text-flat '((font-relative-size . -2)
1772 (music "accidentals--1")))
1777 \property Score.BarNumber \override #'padding = #3
1778 \context StaffGroup = woodwind <
1779 \context Staff = flauti <
1780 \property Staff.midiInstrument = #"flute"
1781 \property Staff.instrument = "2 Flauti"
1782 \property Staff.instr = "Fl."
1784 \context Voice=one @{ \voiceOne \flautoI @}
1785 \context Voice=two @{ \voiceTwo \flautoII @}
1788 \context StaffGroup = timpani <
1789 \context Staff = timpani <
1790 \property Staff.midiInstrument = #"timpani"
1791 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
1792 \property Staff.instr = #"Timp."
1798 \context StaffGroup = brass <
1799 \context Staff = trombe <
1800 \property Staff.midiInstrument = #"trumpet"
1801 \property Staff.instrument = #`(lines "2 Trombe" "(C)")
1802 \property Staff.instr = #`(lines "Tbe." "(C)")
1804 \context Voice=one \partcombine Voice
1805 \context Thread=one \tromboI
1806 \context Thread=two \tromboII
1808 \context Staff = corni <
1809 \property Staff.midiInstrument = #"french horn"
1810 \property Staff.instrument = #`(lines "Corno"
1811 (columns "(E" ,text-flat ")"))
1812 \property Staff.instr = #`(lines "Cor."
1813 (columns "(E" ,text-flat ")"))
1814 \property Staff.transposing = #3
1815 \notes \key bes \major
1816 \context Voice=one \corno
1821 indent = 15 * \staffspace
1822 linewidth = 60 * \staffspace
1823 textheight = 90 * \staffspace
1826 \consists "Multi_measure_rest_engraver"
1829 \HaraKiriStaffContext
1830 \remove "Multi_measure_rest_engraver"
1839 @center @strong{Zo, goed lieverd?}
1841 @center How's, this babe?
1849 @lilypondfile{os-score.ly}
1853 \include "os-music.ly"
1855 First, we need to include the music definitions we made in
1860 #(set! point-and-click line-column-location)
1862 In a large orchestral score like this you're bound to make some small
1863 mistakes, so we enable point and click (See @ref{Point and click})
1868 #(define text-flat '((font-relative-size . -2)
1869 (music "accidentals--1")))
1872 When naming the tuning of the french horn, we'll need a piece of text
1873 with a flat sign. LilyPond has a mechanism for font selection and
1874 kerning called Scheme markup text (See @ref{Text markup}). The flat
1875 sign is taken from the music font, and its name is @code{accidentals--1}
1876 (The sharp sign is called @code{accidentals-+1}). The default font is
1877 too big for text, so we select a relative size of @code{-2}.
1884 Of course, all staffs are simultaneous and use the same global settings.
1888 \property Score.BarNumber \override #'padding = #3
1890 LilyPond prints bar numbers at the start of each line, but
1891 unfortunately, they end up a bit too close to the staff in this example.
1892 A bar number internally is a Grob called @var{BarNumber}. BarNumber
1893 Grobs can be manipulated through their @var{side-position-interface}. One
1894 of the properties of a @var{side-position-interface} that can be tweaked
1895 is the @var{padding}: the amount of extra space that is put between this
1896 Grob and other Grobs. We set the padding to three staff spaces.
1898 You can find all this kind of information in LilyPond's automatically
1899 generated documentation in
1901 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}.
1904 the online documentation.
1909 \context StaffGroup = woodwind <
1910 \context Staff = flauti <
1912 A new notation context: the StaffGroup. StaffGroup can hold one or more
1913 Staffs, and will print a big bracket at the left of the score. Start a
1914 new staff group for the woodwind section (just the flutes in this case).
1915 Immediately after that, we start the staff for the two flutes, that also
1916 play simultaneously.
1920 \property Staff.midiInstrument = #"flute"
1922 Specify the instrument for MIDI output (see @ref{MIDI instrument
1927 \property Staff.instrument = "2 Flauti"
1928 \property Staff.instr = "Fl."
1930 And define the instrument names to be printed in the margin,
1931 @code{instrument} for the first line of the score, @code{instr} for the
1938 The flutes play in the default key.
1942 \context Voice=one @{ \voiceOne \flautoI @}
1943 \context Voice=two @{ \voiceTwo \flautoII @}
1945 Last come the actual flute parts. Remember that we're still in
1946 simultaneous mode. We name both voices differently, so that LilyPond
1947 will actually create two Voice contexts. The flute parts are simple, so
1948 we specify manually which voice is which: @code{\voiceOne} forces the
1949 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
1957 Close the flutes staff and woodwind staff group.
1961 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
1963 The timpani staff only shows a new piece of scheme markup, it sets two
1968 \context Voice=one \partcombine Voice
1969 \context Thread=one \tromboI
1970 \context Thread=two \tromboII
1972 You have seen the notation contexts Staff and Voice, but here's a new
1973 one: Thread. One or more Threads can be part of a Voice. The Thread
1974 takes care of note heads and rests, the Voice combine note heads onto a
1977 For the trumpets we use the automatic part combiner (see @ref{Automatic
1978 part combining}) to combine the two simultaneous trumpet parts onto the
1979 trumpet staff. Each trumpet gets its own Thread context, which must be
1980 named @code{one} and @code{two}). The part combiner makes these two
1981 threads share a Voice when they're similar, and splits the threads up
1982 when they're different.
1986 \property Staff.instrument = #`(lines "Corno"
1987 (columns "(E" ,text-flat ")"))
1989 The french horn has the most complex scheme markup name, made up of two
1990 lines of text. The second line has two elements (columns), the @code{E}
1991 and the flat sign @code{text-flat} that we defined before.
1995 \property Staff.transposing = #3
1997 The french horn is to be tuned in E-flat, so we tell the MIDI backend to
1998 transpose this staff by three steps.
2000 Note how we can choose different tuning for entering, printing and
2001 playing, using @code{\transpose} and the MIDI Staff proprerty
2006 \notes \key bes \major
2008 Therefore, it has a different key.
2012 indent = 15 * \staffspace
2013 linewidth = 60 * \staffspace
2015 We specify a big indent for the first line and a small linewidth for this
2020 Usually, LilyPond's predefined setup of notation contexts (Thread,
2021 Voice, Staff, Staffgroup, Score) is just fine. But in this case, we
2022 want a different type of Staff context.
2024 In orchestral scores, it often happens that one instrument has only
2025 rests during one line of the score. The @code{HaraKiriStaffContext} can
2026 be used as a regular @code{StaffContext} drop-in and will take care of
2027 the automatic removing of empty staffs.
2029 @node Extracting an individual part
2030 @subsection Extracting an individual part
2032 The third file, @file{os-flute-2.ly} also reads the definitions of the
2033 first (@file{os-music.ly}), and defines the @code{\score} block for the
2037 \include "os-music.ly"
2038 \include "paper16.ly"
2042 \property Score.skipBars = ##t
2043 \property Staff.midiInstrument = #"flute"
2049 instrument = "Flauto II"
2052 linewidth = 80 * \staffspace
2053 textheight = 200 * \staffspace
2061 @center @strong{Zo, goed lieverd?}
2063 @center How's, this babe?
2064 @center @emph{Flauto II}
2071 @lilypondfile{os-flute-2.ly}
2074 Because we separated the music definitions from the @code{\score}
2075 instantiations, we can easily define a second score from the music of
2076 the second flute. This then is the part for the second flute player.
2077 Of course, we make separate parts for all individual instruments.
2083 In this individual part the second flute has a whole staff for itself,
2084 so we don't want to force stem or tie directions.
2089 instrument = "Flauto II"
2092 The @code{\header} definitions were also read from @file{os-music.ly},
2093 but we need to set the instrument for this particular score.
2097 \property Score.skipBars = ##t
2099 In the conductor's full score, all bars with rests are printed, but for
2100 the individual parts, we want to contract pieces of consecutive empty
2101 bars. LilyPond will do this if Score's @var{skipBars} property to
2105 @node Other ways to run LilyPond
2106 @section Other ways to run LilyPond
2108 Until now, you have been using @file{ly2dvi} to invoke LilyPond.
2109 There are three other routes. Firstly, there is a script called
2110 @code{lilypond-book}, that allows you to freely mix LilyPond input with
2111 Texinfo or LaTeX input. For example, this manual was written using
2112 @code{lilypond-book}. It is discussed in @ref{lilypond-book}.
2115 Secondly, you can generate PostScript directly. This is useful if you
2116 can not or do not want to run @TeX{} on your system. To obtain direct
2117 PostScript output, invoke LilyPond as follows:
2118 @cindex PostScript output
2120 lilypond -f ps test.ly
2122 You have to set some environment variables to view or print this
2123 output. More information can be found in @ref{Invoking
2127 Thirdly, if you want to do special things with your output, you can run
2128 invoke lilypond directly:
2132 to produce plain @TeX{} output. Note that La@TeX{} will not work on the
2133 resulting @file{test.tex}. You must run plain @TeX{} on it.
2141 @node Integrating text and music
2142 @section Integrating text and music
2144 Sometimes, you might want to use music examples in a text that you are
2145 writing. For example, if you are writing a musicological treatise, a
2146 songbook, or (like us) the LilyPond manual. You can make such texts by
2147 hand, simply by importing a PostScript figure into your wordprocessor.
2148 However, there is a also an automated procedure:
2150 If you use La@TeX{} or texinfo, you can mix text and lilypond code. A
2151 script called @code{lilypond-book} will extract the music fragments, run
2152 lilypond on them, and put back the resulting notation. lilypond-book is
2153 described fully in @ref{lilypond-book}, but here we show a small
2154 example. Since the example also contains explanatory text, we won't
2155 comment on the contents.
2158 \documentclass[a4paper]@{article@}
2161 In a lilypond-book document, you can freely mix music and text. For
2164 \score @{ \notes \relative c' @{
2165 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
2168 Notice that the music line length matches the margin settings of the
2171 If you have no \verb+\score+ block in the fragment,
2172 \texttt@{lilypond-book@} will supply one:
2178 In the example you see here, a number of things happened: a
2179 \verb+\score+ block was added, and the line width was set to natural
2180 length. You can specify many more options using \LaTeX style options
2183 \begin[verbatim,11pt,singleline,
2184 fragment,relative,intertext="hi there!"]@{lilypond@}
2188 \texttt@{verbatim@} also shows the lilypond code, \texttt@{11pt@} selects
2189 the default music size, \texttt@{fragment@} adds a score block,
2190 \texttt@{relative@} uses relative mode for the fragment, and
2191 \texttt@{intertext@} specifies what to print between the
2192 \texttt@{verbatim@} code and the music.
2194 If you include large examples into the text, it may be more convenient
2195 to put the example in a separate file:
2197 \lilypondfile[printfilename]@{sammartini.ly@}
2199 The \texttt@{printfilename@} option adds the file name to the output.
2204 Under Unix, you can view the results as follows.
2207 $ lilypond-book --outdir=out/ lilbook.tex
2208 lilypond-book (GNU LilyPond) 1.3.146
2209 Reading `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/lilbook.tex'
2211 `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/sammartini.ly'
2212 @var{lots of stuff deleted}
2213 Writing `out/lilbook.latex'
2215 $ latex lilbook.latex
2216 @var{lots of stuff deleted}
2220 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
2221 and running latex creates a lot of temporary files, and you wouldn't
2222 those to clutter up your working directory. Hence, we have them created
2223 in a separate subdirectory.
2225 The result more or less looks like this:
2229 In a lilypond-book document, you can freely mix music and text. For
2232 \score { \notes \relative c' {
2233 c2 g'2 \times 2/3 { f8 e d } c'2 g4
2236 Notice that the music line length matches the margin settings of the
2239 If you have no @code{\score} block in the fragment,
2240 @code{lilypond-book} will supply one:
2246 In the example you see here, a number of things happened: a
2247 @code{\score} block was added, and the line width was set to natural
2248 length. You can specify many more options using La@TeX{} style options
2251 @lilypond[verbatim,11pt,singleline,
2252 fragment,relative,intertext="hi there!"]
2256 @code{verbatim} also shows the lilypond code, @code{11pt} selects
2257 the default music size, @code{fragment} adds a score block,
2258 @code{relative} uses relative mode for the fragment, and
2259 @code{intertext} specifies what to print between the
2260 @code{verbatim} code and the music.
2262 If you include large examples into the text, it may be more convenient
2263 to put the example in a separate file:
2265 @lilypondfile[printfilename]{sammartini.ly}
2267 The @code{printfilename} option adds the file name to the output.
2268 @node end of tutorial
2271 That's all folks. From here, you can either try fiddling with input
2272 files, or you can read the reference manual. You can find more example
2273 files in @file{input} and @file{input/test}. You can also look at some
2274 real music. Have a look at the @uref{Mutopia project,
2275 http://www.mutopiaproject.org}.
2283 this should be on mutopia website.
2288 @c waar deze info? is uiteindelijk wel handig, schat ik.
2291 If you have a big music project, or just a lot of LilyPond input files,
2292 all generated output from LilyPond, @TeX{} and metafont will clutter
2293 your working directory. LilyPond comes with a one-size-fits-all
2294 pre-cooked makefile that helps you manage producing output. It will
2295 produce all output in the directory @file{out} , generate and track
2296 dependencies. Also, it helps in preparing your submission to @ref{Mutopia
2303 cp /usr/share/lilypond/make/ly.make GNUmakefile
2304 cp /usr/share/doc/lilypond/examples/input/tutorial/minuet.ly .
2307 Generated out/minuet.ps for target minuet.
2310 Type @samp{make help} to see possible targets.
2313 @file{/usr/share/lilypond/doc/lilypond/examples/input/mutopia-header.ly}
2319 [TODO: rewrite completely.]
2322 * Songs with additional verses::