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
22 * Listening to output::
24 * Single staff polyphony ::
27 * Fine tuning layout::
28 * Organising larger pieces::
29 * An orchestral part::
30 * Integrating text and music:: Integrating text and music
33 Operating is done through text files: To print a piece of music, you
34 enter the music in a file. When LilyPond is run (normally using the
35 program @code{ly2dvi}) on that file, another file containing formatted
36 sheet music, is produced. That file may be printed or viewed.
38 This tutorial starts with a small introduction to the LilyPond music
39 language. After this first contact, we will show which commands to
40 run to produce printed output, so you should then be able to create
41 your first sheets of music. When starting out, it will be convenient
46 @ref{Cheat sheet}, which is a table listing all commands for
54 We start off by showing how very simple music is entered in LilyPond:
55 you get a note simply by typing its @htmlref{note name}, from @samp{a}
56 through @samp{g}. So if you enter
63 then the result looks like this:
66 @c \transpose c c' { c d e f g a b }
68 @c \property Score.timing = ##f
69 @lilypond[notime, relative=2]
73 We will continue with this format: First we show a snippet of input,
74 then the resulting output.
76 The length of a note is specified by adding a number, @samp{1} for a
77 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
84 \property Score.timing = ##f
85 \property Staff.autoBeaming = ##f
86 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
89 If you do not specify a @rglos{duration}, the previous one is used:
96 \property Score.timing = ##f
97 \transpose c c' { a a a2 a s16_" " }
100 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
101 @rglos{flat} (@texiflat{}) by adding @samp{es}. As you might expect,
102 a @rglos{double sharp} or @rglos{double flat} is made by adding
103 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
104 naming conventions in Nordic and Germanic languages, like German and
112 \property Score.timing = ##f
113 \transpose c c' { cis1 ees fisis aeses s16_" " }
116 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
123 \property Score.timing = ##f
124 \transpose c c' { a2. a4 a8. a16 s16_" " }
127 Entering pitches and durations is fully explained in @ref{Pitches} and
131 The @rglos{meter} (or @rglos{time signature}) can be set with the
132 @code{\time} command:
140 @c a clef here may lead to confusion
142 \property Staff.Clef \set #'transparent = ##t
151 Time signatures and other timing commands are described in @ref{Time
155 The @rglos{clef} can be set using the @code{\clef} command:
157 @c what is more common name treble or violin?
158 @c in Dutch, its violin.
159 @c in English its definitely treble.
168 \property Score.timing = ##f
179 Clefs are fully explained in @ref{Clef}.
182 When you enter these commands in a file, you must to enclose them in
183 @code{\notes @{@dots{}@}}. This lets LilyPond know that music (as
184 opposed to @rglos{lyrics}) follows:
194 Now the piece of music is almost ready to be printed. The final step is to
195 combine the music with a printing command.
197 The printing command is the so-called @code{\paper} block. Later on
198 you will see that the @code{\paper} block is used to customize
199 printing specifics. The music and the @code{\paper} block are combined by
200 enclosing them in @code{\score @{ ... @}}. This is what a full source file looks like:
223 linewidth = 55 * \staffspace
229 @node Running LilyPond
230 @section Running LilyPond
232 In the last section we explained what kind of things you could enter
233 in a LilyPond file. In this section we explain what commands to run
234 and how to view or print the output. If you have not used LilyPond
235 before, want to test your setup, or want to run an example file
236 yourself, read this section. The instructions that follow are for
237 Unix-like systems. Some additional instructions for Microsoft Windows are given
238 at the end of this section.
240 Begin by opening a terminal window and starting a text editor.
241 For example, you could open an xterm and execute @code{joe}. In your
242 text editor, enter the following input and save the file as
248 \notes @{ c'4 e' g' @}
255 @c now this is weird, running ly2dvi to run LilyPond
256 @c (therefore name change proposal)
258 LilyPond is the program that computes the sheet music. All other
259 things, such as adding titles, page breaking and other page layout,
260 are done by a small wrapper program called
261 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
262 then adds the titling and page layout instructions. To process
263 @file{test.ly} with @code{ly2dvi}, proceed as follows:
271 You will see the following on your screen:
276 Now processing: `/home/fred/ly/test.ly'
278 Interpreting music...[1]
279 @emph{ ... more interesting stuff ... }
280 PDF output to `test.pdf'...
281 DVI output to `test.dvi'...
285 @cindex Viewing music
288 The results of the ly2dvi run are two files, @file{test.dvi} and
289 @file{test.pdf}. The PDF file (@file{test.pdf}) is the one you can
290 print or view. For example, viewing PDF can be done with ghostview.
291 If a version of ghostview is installed on your system, one of these
292 commands will produce a window with some music notation on your
305 If the music on your screen looks good, you can print it by clicking
306 File/Print inside ghostview.
308 The DVI file (@file{test.dvi}) contains the same sheet music in a
309 different format. DVI files are more easily processed by the computer,
310 so viewing them usually is quicker. You can run @code{xdvi test.dvi}
311 @c KDVI doesn't grok the PS specials.
313 @c @code{kdvi test.dvi}
315 to view the DVI file. In Xdvi, the mouse buttons
316 activate magnifying glasses. Unfortunately, variable symbols (such as
317 beams and slurs) are not displayed in the magnifying glasses.
322 @cindex Printing output
326 If you are familiar with @TeX{}, be warned: do not use other DVI
327 drivers like @code{dvilj}. LilyPond DVI use embedded PostScript code
328 and will not render correctly with other DVI drivers besides
336 Various commands for formatting and printing music are detailed in
337 @ref{Invoking LilyPond}.
340 @unnumberedsubsec Windows users
342 On Windows, the terminal is started by clicking on the LilyPond or
343 Cygwin icon. Any text editor (such as NotePad, Emacs or Vim) may be
344 used to edit the LilyPond file. When Cygwin's @code{XFree86} X11
345 window system is installed along with @code{tetex-x11} and
346 @code{ghostscript-x11} packages, then the @code{dvi} output may be
347 viewed with @code{xdvi test.dvi} as described above. If you have
348 installed a PostScript/PDF viewer, such as @code{GSView} from
349 @uref{http://www.cs.wisc.edu/~ghost}, viewing the PDF file can be done
353 @code{gsview32 test.pdf}
356 Printing may be done by executing
359 @code{gsview32 /s test.pdf}
367 We continue with the introduction of more musical constructs. Normal
368 rests are entered just like notes with the name ``@code{r}'':
376 \property Score.timing = ##f
377 \property Staff.Clef = \turnOff
378 \property Staff.TimeSignature = \turnOff
385 Rests are described in full detail in @ref{Rests}.
388 @c Tim wants to move this quotes example just before the: quotes-do not-work
389 @c score, but we'd need to remove quotes from the other two (key and
392 @c better to have this just before the `octaves are bad' snipped
393 @c but we'd need to remove the ', from \key and tie
394 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
395 the note name, to lower a note one octave, add a ``low quote'' @code{,}
396 (a comma). Middle C is @code{c'}:
400 c'4 c'' c''' \clef bass c c,
404 \property Score.timing = ##f
405 \property Staff.TimeSignature = \turnOff
406 c'4 c'' c''' \clef bass c c,
411 A tie is created by adding a tilde ``@code{~}'' to the first note
414 @lilypond[fragment,verbatim]
419 A tie is different from a slur. A tie simply makes the first note
420 sound longer, and can only be used on pairs of notes with the same
421 pitch. Slurs indicate the articulations of notes, and can be used on
422 larger groups of notes. Slurs and ties are also nested in practice:
423 @lilypond[fragment, relative=1]
424 c2-~-( c8 fis fis4 ~ fis2 g2-)
427 The notation manual discusses ties in @ref{Ties}.
429 The key signature is set with the command ``@code{\key}'', followed by
430 a pitch and @code{\major} or @code{\minor}:
440 \property Staff.TimeSignature = \turnOff
450 @c bit on the long/complex/scary taste
451 @c cheating a bit: two lines makes for a friendlier look
452 This example shows notes, ties, octave marks, and rests in action.
461 r4 r8 d''8 cis''4 e''
463 cis''4 cis''8 cis'' bis'4 d''8 cis''-~
476 r4 r8 d''8 cis''4 e''
478 cis''4 cis''8 cis'' bis'4 d''8 cis''-~
481 \paper { linewidth = 50*\staffspace }
487 There are some interesting points to note in this example.
488 Accidentals (sharps and flats) do not have to be marked explicitly:
489 you just enter the note name, and an accidental is printed
490 automatically, only when necessary. Bar lines and beams are drawn
491 automatically. Line breaks are calculated automatically; it does not
492 matter where the lines breaks are in the source file. Finally, the
493 order of time, key and clef changes is not relevant: in the printout,
494 these are ordered using standard notation conventions.
496 The example also indicates that a piece of music written in a high
497 register needs lots of quotes. This makes the input less readable,
498 and is also a potential source of errors.
500 The solution is to use ``relative octave'' mode. In practice, this is
501 the most convenient way to copy existing music. To use relative mode,
502 add @code{\relative} before the piece of music. You must also give a
503 note from which relative starts, in this case @code{c''}. If you do
504 not use octavation quotes (i.e. do not add ' or , after a note),
505 relative mode chooses the note that is closest to the previous one.
506 @c do not use commas or quotes in this sentence
507 For example: @code{c f} goes up; @code{c g} goes down:
517 \property Score.timing = ##f
518 \property Staff.TimeSignature = \turnOff
527 Since most music has small intervals, in relative mode pieces can be
528 written almost without using octavation quotes.
530 @c needed better, maybe even redundant explanation
531 @c added another example below.
532 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
533 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
534 Larger intervals are made by adding octavation quotes. Quotes or
535 commas do not determine the absolute height of a note; the height of a
536 note is relative to the previous one.
537 @c do not use commas or quotes in this sentence
538 For example: @code{c f,} goes down; @code{f, f} are both the same;
539 @code{c' c} are the same; and @code{c g'} goes up:
549 \property Score.timing = ##f
550 \property Staff.TimeSignature = \turnOff
559 Here is an example of the difference between relative mode and
560 ``normal'' (non-relative) mode:
571 \property Score.timing = ##f
572 \property Staff.TimeSignature = \turnOff
588 \property Score.timing = ##f
589 \property Staff.TimeSignature = \turnOff
596 A slur is drawn across many notes, and indicates bound articulation
597 (legato). The starting note and ending note are marked with a
598 ``@code{(}'' and a ``@code{)}'' respectively:
601 @lilypond[fragment,relative 1, verbatim]
602 d4-( c16-)-( cis d e c cis d e-)-( d4-)
607 If you need two slurs at the same time (one for articulation, one for
608 phrasing), you can also make a phrasing slur with @code{\(} and
613 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
614 @c chromatic thing pasted in front. (admittedly the original does not
615 @c have a phrasing slur. The problem is that we do not want the slur
616 @c and the Phrasing slur to collide. We are trying to make a good
620 @lilypond[fragment,relative 1, verbatim]
621 a8-(-\( ais b c-) cis2 b'2 a4 cis, c-\)
626 Beams are drawn automatically, but if you do not like where they are
627 put, they can be entered by hand. Mark the first note to be beamed
628 with @code{[} and the last one with @code{]}:
630 @lilypond[fragment,relative 1, verbatim]
631 a8-[ ais-] d-[ es r d-]
636 To print more than one staff, each piece of music that makes up a staff
637 is marked by adding @code{\context Staff} before it. These
638 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and @code{@}}, as is
642 @lilypond[fragment,verbatim]
644 \context Staff = staffA { \clef violin c'' }
645 \context Staff = staffB { \clef bass c }
650 In this example, @code{staffA} and @code{staffB} are names that are
651 given to the staves. It does not matter what names you give, as long
652 as each staff has a different name. If you give them the same name,
653 they are assumed to belong on the same staff, and will be printed like
654 that. @code{\simultaneous } indicates that both fragments happen at
655 the same time, and must be printed stacked vertically.
659 We can now typeset a melody with two staves:
662 @lilypond[verbatim,singleline]
665 < \context Staff = staffA {
669 e2-( d4 c2 b4 a8-[ a-]
670 b-[ b-] g-[ g-] a2.-) }
672 \context Staff = staffB {
683 The time signature is specified in one melody staff only
684 (the top staff), but is printed on both, since common practice
685 dictates that all staves have the same time signature.
689 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
691 @lilypond[verbatim,relative 1]
697 Similarly, fingering indications can be added to a note using @code{-}
698 and the digit to be printed.
699 @lilypond[verbatim,relative 1]
707 Dynamic signs are made by adding the markings to the note:
709 @lilypond[verbatim,relative 1]
715 Crescendi and decrescendi are started with the commands @code{\<} and
716 @code{\>}. The command @code{\!} finishes a crescendo on the note it
719 @lilypond[verbatim,relative 1]
720 c2-\< c2-\!-\ff c2-\> c2-\!
725 Chords can be made by
726 surrounding pitches with @code{<<} and @code{>}>:
728 @lilypond[relative 0, fragment,verbatim]
729 r4 <<c e g>>4 <<c f a>>8
735 You can combine beams and ties with chords. Beam and tie markings
736 must be placed outside the chord markers:
738 @lilypond[relative 0, fragment,verbatim]
739 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
745 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
747 @lilypond[relative 0, fragment]
749 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
755 A pickup (or upstep) is entered with the keyword @code{\partial}. It
756 is followed by a duration: @code{\partial 4} is a quarter note upstep
757 and @code{\partial 8} an eighth note.
758 @lilypond[relative 1,verbatim,fragment]
763 Tuplets are made with the @code{\times} keyword. It takes two
764 arguments: a fraction and a piece of music. The duration of the piece
765 of music is multiplied by the fraction. Triplets make notes occupy
766 2/3 of their notated duration, so a triplet has 2/3 as its fraction.
768 @lilypond[relative 0,verbatim,fragment]
769 \times 2/3 { f8 g a }
773 Grace notes are also made by prefixing a note, or a set of notes with
774 a keyword. In this case, the keyword is @code{\grace}.
775 @lilypond[relative 1, verbatim,fragment]
777 \grace { d16-( e } d4-)
781 More information on the use of grace notes is in @ref{Grace notes}.
784 Comments are pieces of the input that are ignored. There are two
785 types of comments. A line comments are introduced by @code{%}: after
786 that, the rest of that line is ignored. Block comments span larger
787 sections of input. Anything that is enclosed in @code{%@{} and
788 @code{%@}} is ignored too. The following fragment shows possible uses
792 % notes for twinkle twinkle follow:
797 This line, and the notes below
798 are ignored, since they are in a
808 @node Printing lyrics
809 @section Printing lyrics
812 Lyrics are entered by separating each syllable with a space, and
813 surrounding them with @code{\lyrics @{ @dots{} @}}, for example
815 \lyrics @{ I want to break free @}
818 Like notes, lyrics are also a form of music, but they must not be
819 printed on a staff, which is the default way to print music. To print
820 them as lyrics, they must be marked with @code{ \context Lyrics}:
822 \context Lyrics \lyrics @{ I want to break free @}
824 The melody for this song is as follows
826 @lilypond[fragment,relative=1]
829 \times 2/3 { f4 g g } \times 2/3 { g4-( a2-) }
832 The lyrics can be set to these notes, combining both with the
833 @code{\addlyrics} keyword:
837 \context Lyrics @dots{}
841 @lilypond[singleline,verbatim]
848 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
850 \context Lyrics \lyrics { I want to break free }
856 This melody ends on a @rglos{melisma}, a single syllable (``free'')
857 sung to more than one note. This is indicated with a @emph{extender
858 line}. It is entered as two underscores, i.e.,
860 \lyrics @{ I want to break free __ @}
869 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
871 %% ugh, this is to deal with bugs in the extender implementation
875 \context Lyrics \lyrics { I want to break free __ }
877 \paper{ linewidth = 9.0 \cm }
881 Similarly, hyphens between words can be entered as two dashes,
882 resulting in a centered hyphen between two syllables.
884 Twin -- kle twin -- kle
886 @lilypond[singleline]
888 \addlyrics \notes \relative f' { \time 2/4
890 \context Lyrics \lyrics { Twin -- kle twin -- kle
892 \paper { linewidth = 6.0 \cm }
897 More options, like putting multiple lines of lyrics below a melody are
898 discussed in @ref{Vocal music}.
902 @section A lead sheet
904 In popular music, it is common to denote accompaniment as chord-names.
905 Using them in LilyPond has two parts, just like lyrics: entering the
906 chords (with @code{\chords}), and printing them (with @code{\context
909 Chord names are entered by starting chords mode (with @code{\chords}).
910 In chords mode, you can enter chords with a letter (indicating the
911 root of the chord), and a durations following that.
914 \chords { c2 f4. g8 }
918 The result of @code{\chords} is a list of chords, and is equivalent
919 to entering chords with @code{<<@dots{}>>}.
921 Other chords can be created by adding modifiers, after a colon. The
922 following example shows a few common modifiers
925 \chords { c2 f4:m g4:maj7 gis1:dim7 }
928 Printing chords is done by adding @code{\context ChordNames}
929 before the chords thus entered:
932 \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
935 A complete list of modifiers, and other options for layout are in the
936 reference manual section @ref{Chords}.
939 When put together, chord names, lyrics and a melody form
940 a lead sheet, for example,
945 \context ChordNames \chords @{ @emph{chords} @}
947 \notes @emph{the melody}
948 \context Lyrics \lyrics @{ @emph{the text} @}
956 \context ChordNames \chords { r8 c2:sus4 f }
958 \notes \relative c' {
961 \times 2/3 { f g g } \times 2/3 { g4-( a2-) } }
962 \context Lyrics \lyrics { I want to break free __ }
964 \paper{ raggedright = ##t }
969 @node Listening to output
970 @section Listening to output
972 MIDI (Musical Instrument Digital Interface) is a standard for
973 connecting and recording digital instruments. A MIDI file is like a
974 tape recording of a MIDI instrument. The @code{\midi} block makes the
975 music go to a MIDI file, so you can listen to the music you entered.
976 It is great for checking the music: octaves that are off, or
977 accidentals that were mistyped, stand out very much when listening to
978 the musical transcription.
980 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
985 \midi @{ \tempo 4=72 @}
990 Here, the tempo is specified using the @code{\tempo} command. In this
991 case the tempo of quarter notes is set to 72 beats per minute. More
992 information on auditory output is in the @ref{Sound} section in the
999 Bibliographic information is entered in a separate block, the
1000 @code{\header} block. The name of the piece, its composer, etc. are
1001 entered as assignment within @code{\header @{ @dots{} @}}. For
1005 title = "Eight miniatures"
1006 composer = "Igor Stravinsky"
1007 tagline = "small is beautiful"
1010 \score @{ @dots{} @}
1013 @cindex bibliographic information
1019 When the file is processed by @code{ly2dvi}, the title and composer
1020 specified are printed above the music. The `tagline' is a short line
1021 printed at bottom of the last page, which normally says ``Lily was
1022 here, version @dots{}''. In the example above, it is replaced by the
1023 line ``small is beautiful.''
1025 Normally, the @code{\header} is put at the top of the file. However,
1026 for a document that contains multiple pieces (e.g. a etude book, or
1027 part with multiple movements), then the header can be put into the
1028 @code{\score} block as follows In this case, the name of each piece
1029 will be printed before each movement.
1032 @cindex Lily was here
1033 @cindex signature line
1038 title = "Eight miniatures"
1039 composer = "Igor Stravinsky"
1040 tagline = "small is beautiful"
1044 \header @{ piece = "Adagio" @}
1047 \header @{ piece = "Menuetto" @}
1051 More information on titling can be found in @ref{Invoking ly2dvi}.
1054 @node Single staff polyphony
1055 @section Single staff polyphony
1057 When different melodic lines are combined on a single staff, these are
1058 printed as polyphonic voices: each voice has its own stems, slurs
1059 and beams, and the top voice has the stems up, while the bottom voice
1062 Entering such parts is done by entering each voice as a sequence (with
1063 @code{@{ .. @}}), and combing those simultaneously, separating the
1064 voices with @code{\\}:
1067 < @{ a4 g2 f4-~ f4 @} \\
1071 \context Staff < { a4 g2 f4-~ f4 } \\
1074 The notation @code{< .. >} is a shorthand for @code{\simultaneous @{
1077 For polyphonic typesetting spacer rests can also be convenient: these
1078 are rests that do not print. It is useful for filling up voices that
1079 temporarily do not play:
1081 < @{ a4 g2 f4-~ f4 @} \\
1085 < { a4 g2 f4-~ f4 } \\
1089 More features of polyphonic typesetting are in the notation manual
1093 @section Piano staffs
1095 @cindex staff switch, manual
1096 @cindex cross staff voice, manual
1097 @cindex @code{\translator}
1099 Piano music is always typeset in two staffs connected by a brace.
1100 Printing such a staff is done similar to the polyphonic example in
1103 < \context Staff = up @{ @dots{} @}
1104 \context Staff = down @{ @dots{} @}
1107 but now this entire expression must be interpreted as a
1110 \context PianoStaff < \context Staff @dots{} >
1113 Here is a full-fledged example:
1115 @lilypond[relative 0,fragment]
1117 < \context Staff = up {
1119 \context Staff = down {
1120 \clef bass c, c' e c }
1124 More information on formatting piano music is in @ref{Piano music}.
1126 @node Setting variables
1127 @section Setting variables
1129 When the music is converted from notes to print, it is interpreted
1130 from left-to-right order, similar to what happens when we read
1131 music. During this step, context-sensitive information, such as the
1132 accidentals to print, and where barlines must be placed, are stored in
1133 variables. These variables are called @emph{translation properties}.
1134 The properties can also be manipulated from input files: for example,
1136 \property Staff.autoBeaming = ##f
1138 sets the property named @code{autoBeaming} in the current staff to
1139 @code{##f} which means `false'. This property controls whether beams
1140 are printed automatically:
1141 @lilypond[relative 1,fragment,verbatim]
1143 \property Staff.autoBeaming = ##f
1148 LilyPond includes a built-in programming language, namely, a dialect
1149 of Scheme. The argument to @code{\property}, @code{##f}, is an
1150 expression in that language. The first hash-mark signals that a piece
1151 of Scheme code follows. The second hash character is part of the
1152 boolean value true (@code{#t}). Values of other types may be
1155 @item a string, enclosed in double quotes, for example
1157 \property Staff.instrument = #"French Horn"
1159 @item a boolean: either @code{#t} or @code{#f}, for true and false
1162 \property Voice.autoBeaming = ##f
1163 \property Score.skipBars = ##t
1168 \property Score.currentBarNumber = #20
1171 @item a symbol, which is introduced by a quote character,
1173 \property Staff.crescendoSpanner = #'dashed-line
1176 @item a pair, which is also introduced by a quote character.
1177 The following statements set properties to the pairs (-7.5, 6) and
1178 (3, 4) respectively.
1181 \property Staff.minimumVerticalExtent = #'(-7.5 . 6)
1182 \property Staff.timeSignatureFraction = #'(3 . 4)
1188 There are many different properties, and not all of them are listed in
1189 this manual. However, the internal documentation lists them all in the
1190 @internalsref{All translation properties}, and almost all properties
1191 are demonstrated in one of the
1193 @uref{../../../input/test/out-www/collated-files.html,tips-and-tricks}
1201 @node Fine tuning layout
1202 @section Fine tuning layout
1204 Sometimes it is necessary to change music layout by hand. When music
1205 is formatted, layout objects are created for each symbol. For
1206 example, every clef and every note head is represented by a layout
1207 object. These layout objects also carry variables, which
1208 we call @emph{layout properties}. By changing these variables, we can
1209 alter the look of a formatted score.
1211 @lilypond[verbatim,relative 0]
1213 \property Voice.Stem \override #'thickness = #3.0
1218 In the example shown here, the layout property @code{thickness} (a
1219 symbol) is set to 3 in the @code{Stem} layout objects of the current
1220 Voice. As a result, the notes following @code{\property} have thicker
1223 In most cases of manual overrides, only a single object must be
1224 changed. This can be achieved by prefix @code{\once} to the
1225 @code{\property} statement, i.e.,
1228 \once \property Voice.Stem \set #'thickness = #3.0
1231 @lilypond[relative 0]
1233 \once \property Voice.Stem \set #'thickness = #3.0
1238 Some overrides are so common that predefined commands are provided as
1239 a short cut. For example, @code{\slurUp} and @code{\stemDown}. These
1240 commands are described in the @ref{Notation manual}.
1246 @node Organising larger pieces
1247 @section Organising larger pieces
1249 TODO: discuss identifiers, p&c, .
1254 In this section we show some ways to fine tune the final output of a
1255 piece. We do so using a single measure of a moderately complex piano
1256 piece: a Brahms intermezzo (opus 119, no. 1). Both fragments (the
1257 tuned and the untuned versions) are in @file{input/tutorial/}.
1259 The code for the untuned example shows us some new things.
1261 @lilypondfile[verbatim]{brahms-original.ly}
1272 Now that we have the basic piece of music entered, we want to fine
1273 tune it so that we get something that resembles the original printed
1274 edition by Schott/Universal Edition:
1276 @lilypondfile{brahms-tweaked.ly}
1278 @cindex tuning graphical objects
1280 Fine tuning involves overriding the defaults of the printing system.
1281 We do this by setting variables which control how Lilypond prints
1282 symbols. Printed symbols are called graphical objects (often
1283 abbreviated to @emph{grob}). Each object is described by a bunch of
1284 settings. Every setting is a variable: it has a name and a value
1285 which you can change. These values determine the fonts, offsets,
1286 sub-routines to be called on the object, etc. The initial values of
1287 these settings are set in the Scheme file
1288 @file{scm/grob-description.scm}.
1290 @cindex slur attachments
1292 We start with the slur in the upper part, running from F sharp to A. In
1293 the printed edition, this slur runs from stem to stem; in our version,
1294 the slur begins at the note head of the F sharp. The following property
1295 setting forces all slurs to run from stem to stem (not from or to note
1299 \property Voice.Slur \set #'attachment = #'(stem . stem)
1302 More precisely, this command modifies the definition of the @code{Slur}
1303 object in the current @code{Voice}. The variable @code{attachment} is
1304 set to the pair of symbols @code{'(stem . stem)}.
1306 @cindex internal documentation
1307 @cindex finding graphical objects
1308 @cindex graphical object descriptions
1310 This command fixes one particular problem with a slur. The rest of
1311 this section explains how to figure out which properties to tune for
1312 your own scores. To discover this, you must have a copy of the
1313 internals document. This is a set of HTML pages which should be
1314 included if you installed a binary distribution. [TODO: revise for
1315 new site.] These HTML pages are also available on the web: go to the
1316 LilyPond website, click ``Documentation: Index'' on the side bar, look
1317 in the ``Information for users'' section, and click on ``Documentation
1320 You might want to bookmark either the HTML files on your disk, or the
1321 one on the web (the HTML on your hard drive will load much faster than
1322 the ones on the web!). One word of caution: the internals
1323 documentation is generated from the definitions that the program uses.
1324 Hence, the internals documentation is strongly tied to the version you
1325 use. Before you proceed, make sure that the program and documentation
1326 have matching version numbers.
1328 @c TODO: the quote is incorrect, although that shouldn't be a big
1329 @c problem for the reader.
1330 Suppose that you wanted to tune the behavior of the slur. The first
1331 step is to get some general information on slurs in LilyPond. Turn to
1332 the index, and look up ``slur''. The section on slurs says
1334 The grob for this object is @internalsref{Slur}, generally in
1335 @internalsref{Voice} context.
1338 So the graphical object for this object is called @code{Slur}, and
1339 slurs are created in the @code{Voice} context. If you are reading
1340 this tutorial in the HTML version, then you can simply click Slur,
1341 otherwise, you should look it up the internal documentation: click
1342 ``grob overview'' and select ``slur'' (the list is alphabetical).
1344 Now you get a list of all the properties that the slur object
1345 supports, along with their default values. Among the properties we
1346 find the @code{attachment} property with its default setting.
1347 The property documentation explains that the following setting will
1348 produce the desired effect:
1350 \property Voice.Slur \set #'attachment = #'(stem . stem)
1353 @c this is a long section, and adding an extra space here helps to
1354 @c break it into smaller subsections and thus is easier to understand.
1357 Next we want to move the fingering `3'. In the printed edition it is
1358 not above the stem, but a little lower and slightly left of the stem.
1359 From the user manual we find that the associated graphical object is
1360 called @code{Fingering}, but how do we know if we should use
1361 @code{Voice} or @code{Staff}? In many cases, @code{Voice} is a safe
1362 bet, but you can also deduce this information from the internals
1363 documentation: if you visit the documentation of @code{Fingering}, you
1366 Fingering grobs are created by: Fingering_engraver
1369 Clicking @code{Fingering_engraver} will show you the documentation of
1370 the module responsible for interpreting the fingering instructions and
1371 translating them to a @code{Fingering} object. Such a module is called
1372 an @emph{engraver}. The documentation of the @code{Fingering_engraver}
1375 Fingering_engraver is part of contexts: Voice and TabVoice
1377 so tuning the settings for Fingering should be done using either
1379 \property Voice.Fingering \set @dots{}
1383 \property TabVoice.Fingering \set @dots{}
1386 Since the @code{TabVoice} is only used for tab notation, we see that
1387 the first guess @code{Voice} was indeed correct.
1389 @cindex setting object properties
1390 @cindex @code{extra-offset}
1392 For shifting the fingering, we use the property @code{extra-offset}.
1393 The following command manually adds an offset to the object. We move
1394 it a little to the left, and 1.8 staff space downwards.
1396 \once \property Voice.Fingering \set #'extra-offset = #'(-0.3 . -1.8)
1398 The @code{extra-offset} is a low-level feature: it moves around
1399 objects in the printout; the formatting engine is completely oblivious
1400 to these offsets. The unit of these offsets are staff-spaces. The
1401 first number controls left-right movement; a positive number will move
1402 the object to the right. The second number controls up-down movement;
1403 a positive number will move it higher.
1404 We only want to offset a single object, so this statement is adorned
1407 @cindex property types
1408 @cindex translator properties
1409 @cindex grob properties
1410 @cindex music properties
1413 There are three different types of variables in LilyPond, something
1414 which can be confusing at first (and for some people it stays
1415 confusing). Variables such as @code{extra-offset} and
1416 @code{attachment} are called grob properties. They are not the same
1417 as translator properties, like @code{autoBeaming}. Finally, music
1418 expressions are internally stored using properties (so-called music
1419 properties). You will encounter music properties if you run Scheme
1420 functions on music using @code{\apply}.
1422 The second fingering instruction should be moved up a little to avoid
1423 a collision with the slur. This could be achieved with
1424 @code{extra-offset}, but in this case, a simpler mechanism also
1425 works. We insert an empty text between the 5 and the note. The empty
1426 text pushes the fingering instruction away:
1428 a-)^" "^\markup @{ \finger "5" @}
1431 A fingering instruction, which would be entered as @code{^5}, is put
1432 as close to the notes as possible, closer than the space entered to
1433 push away the 5. Hence, the 5 is entered as a normal text, with the
1434 formatting of fingering instructions.
1438 Normally one would specify all dynamics in the same voice, so that
1439 dynamics (such as @b{f} and @b{p}) will be aligned with hairpins. But
1440 in this case, we do not want the decrescendo to be aligned with the
1441 piano sign. We achieve this by putting the dynamic markings in different
1442 voices. The crescendo should be above the upper staff. This can be
1443 forced by using the precooked command
1448 However, if you do that the decrescendo will be too close to the upper
1449 voice and collide with the stems. Looking at the manual for dynamics,
1450 we notice that ``Vertical positioning of these symbols is handled by
1451 the @internalsref{DynamicLineSpanner} grob.''. If we turn to the
1452 documentation of @code{DynamicLineSpanner}, we find that
1453 @code{DynamicLineSpanner} supports several so-called `interfaces'.
1454 This object not only puts objects next to the staff
1455 (@code{side-position-interface}), but it also groups dynamic objects
1456 (@code{axis-group-interface}), is considered a dynamic sign itself
1457 (@code{dynamic-interface}), and is an spanning object
1458 (@code{spanner-interface}). It also has the standard
1459 @code{grob-interface} with all the variables that come with it.
1461 For the moment we are interested in side positioning:
1463 side-position-interface
1465 Position a victim object (this one) next to other objects (the
1466 support). In this case, the direction signifies where to put the
1467 victim object relative to the support (left or right, up or down?)
1469 Between the object and its support (in this case, the descending
1470 notes), there should be more space. This space is controlled by
1471 @code{padding}, so we increase it.
1473 \property Voice.DynamicLineSpanner \override #'padding = #5.0
1479 Brahms uses music notation is a slightly unorthodox way. Ties
1480 usually happen only within one voice. In this piece, the composer
1481 gladly produces ties that jump voices. We deal with this by faking
1482 these ties: whenever we need such a tie, we insert a notehead in a
1483 different voice, and blank the stem. This is done in the following
1486 @cindex transparent objects
1487 @cindex removing objects
1488 @cindex invisible objects
1490 \property Voice.Stem \set #'transparent = ##t
1493 Blanking the stem should be done for only one object. One of the ways
1494 to achieve that, is by setting the property before a note. Reverting
1495 it afterwards is tedious, so for setting a property only once, we have
1496 the syntax @code{\once}: it reverts the property directly before
1497 proceeding to the next step in time.
1499 The @code{\once} keyword is added to @code{\property}.
1502 Finally, the last tie is forced up using @code{\tieUp}.
1506 Here is the complete ``fine tuned'' version, which includes all the
1507 modifications we discussed in this section:
1509 @lilypondfile[verbatim]{brahms-tweaked.ly}
1512 @node An orchestral part
1513 @section An orchestral part
1518 \markup, mmrest, transposing, cue notes, identifiers?.
1524 Lilypond and its language are still under development, and
1525 occasionally details of the syntax are changed. The @code{version}
1526 fragment indicates which LilyPond version the input file was written
1527 for. When you compile this file, the version number will be
1528 checked. When the file is too old, a warning is issued. The version
1529 number is also used by the @code{convert-ly} program (See
1530 @ref{Invoking convert-ly}), which updates the file to the latest
1531 version automatically.
1533 @node Integrating text and music
1534 @section Integrating text and music
1537 @cindex La@TeX{}, music in
1538 @cindex HTML, music in
1539 @cindex Texinfo, music in
1541 Sometimes you might want to use music examples in a text that you are
1542 writing (for example a musicological treatise, a songbook, or (like us)
1543 the LilyPond manual). You can make such texts by hand, simply by
1544 importing a PostScript figure into your word processor. However,
1545 there is an automated procedure to reduce the amount of work.
1547 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1548 code. A script called @code{lilypond-book} will extract the music
1549 fragments, run LilyPond on them, and put back the resulting notation.
1550 This program is fully described in @ref{lilypond-book manual}. Here
1551 we show a small example. Since the example also contains explanatory
1552 text, we will not comment it further.
1555 \documentclass[a4paper]@{article@}
1558 In a lilypond-book document, you can freely mix music and text. For
1561 \score @{ \notes \relative c' @{
1562 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1566 Notice that the music line length matches the margin settings of the
1569 If you have no \verb+\score+ block in the fragment,
1570 \texttt@{lilypond-book@} will supply one:
1576 In the example you see here, two things happened: a
1577 \verb+\score+ block was added, and the line width was set to natural
1578 length. You can specify many more options using \LaTeX style options
1581 \begin[verbatim,11pt,singleline,
1582 fragment,relative,intertext="hi there!"]@{lilypond@}
1586 The option \texttt@{verbatim@} prints the LilyPond code in addition to
1587 the graphical score, \texttt@{11pt@} selects the default music size,
1588 \texttt@{fragment@} adds a score block, \texttt@{relative@} uses
1589 relative mode for the fragment, and \texttt@{intertext@} specifies
1590 what to print between the \texttt@{verbatim@} code and the music.
1592 If you want to include large examples into the text, it may be more
1593 convenient to put the example in a separate file:
1595 \lilypondfile[printfilename]@{screech-boink.ly@}
1597 The \texttt@{printfilename@} option adds the file name to the output.
1602 Under Unix, you can view the results as follows.
1606 $ lilypond-book --outdir=out/ lilbook.tex
1607 lilypond-book (GNU LilyPond) 1.7.16
1608 Reading `input/tutorial/lilbook.tex'
1609 Reading `input/screech-boink6.ly'
1610 @var{lots of stuff deleted}
1611 Writing `out/lilbook.latex'
1613 $ latex lilbook.latex
1614 @var{lots of stuff deleted}
1618 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
1619 and running latex creates a lot of temporary files, and you would not want
1620 those to clutter up your working directory. Hence, we have them created
1621 in a separate subdirectory.
1623 The result looks more or less like this:
1627 In a lilypond-book document, you can freely mix music and text. For
1631 \notes \relative c' {
1632 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1640 Notice that the music line length matches the margin settings of the
1643 If you have no @code{\score} block in the fragment,
1644 @code{lilypond-book} will supply one:
1650 In the example you see here, a number of things happened: a
1651 @code{\score} block was added, and the line width was set to natural
1652 length. You can specify many more options using La@TeX{} style options
1655 @lilypond[verbatim,11pt,singleline,
1656 fragment,relative,intertext="hi there!"]
1660 The option @code{verbatim} also shows the LilyPond code, @code{11pt} selects
1661 the default music size, @code{fragment} adds a score block,
1662 @code{relative} uses relative mode for the fragment, and
1663 @code{intertext} specifies what to print between the
1664 @code{verbatim} code and the music.
1666 If you include large examples into the text, it may be more convenient
1667 to put the example in a separate file:
1669 @lilypondfile[printfilename]{screech-boink.ly}
1671 The @code{printfilename} option adds the file name to the output.