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 ::
26 * Organising larger pieces::
27 * Fine tuning a piece::
28 * An orchestral score:: Conductor's score and individual parts
29 * Integrating text and music:: Integrating text and music
32 Operating is done through text files: To print a piece of music, you
33 enter the music in a file. When LilyPond is run (normally using the
34 program @code{ly2dvi}) on that file, another file containing formatted
35 sheet music, is produced. That file may be printed or viewed.
37 This tutorial starts with a small introduction to the LilyPond music
38 language. After this first contact, we will show which commands to
39 run to produce printed output, so you should then be able to create
40 your first sheets of music. When starting out, it will be convenient
45 @ref{Cheat sheet}, which is a table listing all commands for
53 We start off by showing how very simple music is entered in LilyPond:
54 you get a note simply by typing its @htmlref{note name}, from @samp{a}
55 through @samp{g}. So if you enter
62 then the result looks like this:
65 @c \transpose c c' { c d e f g a b }
67 @c \property Score.timing = ##f
68 @lilypond[notime, relative=2]
72 We will continue with this format: First we show a snippet of input,
73 then the resulting output.
75 The length of a note is specified by adding a number, @samp{1} for a
76 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
83 \property Score.timing = ##f
84 \property Staff.autoBeaming = ##f
85 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
88 If you do not specify a @rglos{duration}, the previous one is used:
95 \property Score.timing = ##f
96 \transpose c c' { a a a2 a s16_" " }
99 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
100 @rglos{flat} (@texiflat{}) by adding @samp{es}. As you might expect,
101 a @rglos{double sharp} or @rglos{double flat} is made by adding
102 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
103 naming conventions in Nordic and Germanic languages, like German and
111 \property Score.timing = ##f
112 \transpose c c' { cis1 ees fisis aeses s16_" " }
115 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
122 \property Score.timing = ##f
123 \transpose c c' { a2. a4 a8. a16 s16_" " }
126 Entering pitches and durations is fully explained in @ref{Pitches} and
130 The @rglos{meter} (or @rglos{time signature}) can be set with the
131 @code{\time} command:
139 @c a clef here may lead to confusion
141 \property Staff.Clef \set #'transparent = ##t
150 Time signatures and other timing commands are described in @ref{Time
154 The @rglos{clef} can be set using the @code{\clef} command:
156 @c what is more common name treble or violin?
157 @c in Dutch, its violin.
158 @c in English its definitely treble.
167 \property Score.timing = ##f
178 Clefs are fully explained in @ref{Clef}.
181 When you enter these commands in a file, you must to enclose them in
182 @code{\notes @{@dots{}@}}. This lets LilyPond know that music (as
183 opposed to @rglos{lyrics}) follows:
193 Now the piece of music is almost ready to be printed. The final step is to
194 combine the music with a printing command.
196 The printing command is the so-called @code{\paper} block. Later on
197 you will see that the @code{\paper} block is used to customize
198 printing specifics. The music and the @code{\paper} block are combined by
199 enclosing them in @code{\score @{ ... @}}. This is what a full source file looks like:
222 linewidth = 55 * \staffspace
228 @node Running LilyPond
229 @section Running LilyPond
231 In the last section we explained what kind of things you could enter
232 in a LilyPond file. In this section we explain what commands to run
233 and how to view or print the output. If you have not used LilyPond
234 before, want to test your setup, or want to run an example file
235 yourself, read this section. The instructions that follow are for
236 Unix-like systems. Some additional instructions for Microsoft Windows are given
237 at the end of this section.
239 Begin by opening a terminal window and starting a text editor.
240 For example, you could open an xterm and execute @code{joe}. In your
241 text editor, enter the following input and save the file as
247 \notes @{ c'4 e' g' @}
254 @c now this is weird, running ly2dvi to run LilyPond
255 @c (therefore name change proposal)
257 LilyPond is the program that computes the sheet music. All other
258 things, such as adding titles, page breaking and other page layout,
259 are done by a small wrapper program called
260 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
261 then adds the titling and page layout instructions. To process
262 @file{test.ly} with @code{ly2dvi}, proceed as follows:
270 You will see the following on your screen:
275 Now processing: `/home/fred/ly/test.ly'
277 Interpreting music...[1]
278 @emph{ ... more interesting stuff ... }
279 PDF output to `test.pdf'...
280 DVI output to `test.dvi'...
284 @cindex Viewing music
287 The results of the ly2dvi run are two files, @file{test.dvi} and
288 @file{test.pdf}. The PDF file (@file{test.pdf}) is the one you can
289 print or view. For example, viewing PDF can be done with ghostview.
290 If a version of ghostview is installed on your system, one of these
291 commands will produce a window with some music notation on your
304 If the music on your screen looks good, you can print it by clicking
305 File/Print inside ghostview.
307 The DVI file (@file{test.dvi}) contains the same sheet music in a
308 different format. DVI files are more easily processed by the computer,
309 so viewing them usually is quicker. You can run @code{xdvi test.dvi}
310 @c KDVI doesn't grok the PS specials.
312 @c @code{kdvi test.dvi}
314 to view the DVI file. In Xdvi, the mouse buttons
315 activate magnifying glasses. Unfortunately, variable symbols (such as
316 beams and slurs) are not displayed in the magnifying glasses.
321 @cindex Printing output
325 If you are familiar with @TeX{}, be warned: do not use other DVI
326 drivers like @code{dvilj}. LilyPond DVI use embedded PostScript code
327 and will not render correctly with other DVI drivers besides
335 Various commands for formatting and printing music are detailed in
336 @ref{Invoking LilyPond}.
339 @unnumberedsubsec Windows users
341 On Windows, the terminal is started by clicking on the LilyPond or
342 Cygwin icon. Any text editor (such as NotePad, Emacs or Vim) may be
343 used to edit the LilyPond file. When Cygwin's @code{XFree86} X11
344 window system is installed along with @code{tetex-x11} and
345 @code{ghostscript-x11} packages, then the @code{dvi} output may be
346 viewed with @code{xdvi test.dvi} as described above. If you have
347 installed a PostScript/PDF viewer, such as @code{GSView} from
348 @uref{http://www.cs.wisc.edu/~ghost}, viewing the PDF file can be done
352 @code{gsview32 test.pdf}
355 Printing may be done by executing
358 @code{gsview32 /s test.pdf}
366 We continue with the introduction of more musical constructs. Normal
367 rests are entered just like notes with the name ``@code{r}'':
375 \property Score.timing = ##f
376 \property Staff.Clef = \turnOff
377 \property Staff.TimeSignature = \turnOff
384 Rests are described in full detail in @ref{Rests}.
387 @c Tim wants to move this quotes example just before the: quotes-do not-work
388 @c score, but we'd need to remove quotes from the other two (key and
391 @c better to have this just before the `octaves are bad' snipped
392 @c but we'd need to remove the ', from \key and tie
393 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
394 the note name, to lower a note one octave, add a ``low quote'' @code{,}
395 (a comma). Middle C is @code{c'}:
399 c'4 c'' c''' \clef bass c c,
403 \property Score.timing = ##f
404 \property Staff.TimeSignature = \turnOff
405 c'4 c'' c''' \clef bass c c,
410 A tie is created by adding a tilde ``@code{~}'' to the first note
413 @lilypond[fragment,verbatim]
418 A tie is different from a slur. A tie simply makes the first note
419 sound longer, and can only be used on pairs of notes with the same
420 pitch. Slurs indicate the articulations of notes, and can be used on
421 larger groups of notes. Slurs and ties are also nested in practice:
422 @lilypond[fragment, relative=1]
423 c2-~-( c8 fis fis4 ~ fis2 g2-)
426 The notation manual discusses ties in @ref{Ties}.
428 The key signature is set with the command ``@code{\key}'', followed by
429 a pitch and @code{\major} or @code{\minor}:
439 \property Staff.TimeSignature = \turnOff
449 @c bit on the long/complex/scary taste
450 @c cheating a bit: two lines makes for a friendlier look
451 This example shows notes, ties, octave marks, and rests in action.
460 r4 r8 d''8 cis''4 e''
462 cis''4 cis''8 cis'' bis'4 d''8 cis''-~
475 r4 r8 d''8 cis''4 e''
477 cis''4 cis''8 cis'' bis'4 d''8 cis''-~
480 \paper { linewidth = 50*\staffspace }
486 There are some interesting points to note in this example.
487 Accidentals (sharps and flats) do not have to be marked explicitly:
488 you just enter the note name, and an accidental is printed
489 automatically, only when necessary. Bar lines and beams are drawn
490 automatically. Line breaks are calculated automatically; it does not
491 matter where the lines breaks are in the source file. Finally, the
492 order of time, key and clef changes is not relevant: in the printout,
493 these are ordered using standard notation conventions.
495 The example also indicates that a piece of music written in a high
496 register needs lots of quotes. This makes the input less readable,
497 and is also a potential source of errors.
499 The solution is to use ``relative octave'' mode. In practice, this is
500 the most convenient way to copy existing music. To use relative mode,
501 add @code{\relative} before the piece of music. You must also give a
502 note from which relative starts, in this case @code{c''}. If you do
503 not use octavation quotes (i.e. do not add ' or , after a note),
504 relative mode chooses the note that is closest to the previous one.
505 @c do not use commas or quotes in this sentence
506 For example: @code{c f} goes up; @code{c g} goes down:
516 \property Score.timing = ##f
517 \property Staff.TimeSignature = \turnOff
526 Since most music has small intervals, in relative mode pieces can be
527 written almost without using octavation quotes.
529 @c needed better, maybe even redundant explanation
530 @c added another example below.
531 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
532 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
533 Larger intervals are made by adding octavation quotes. Quotes or
534 commas do not determine the absolute height of a note; the height of a
535 note is relative to the previous one.
536 @c do not use commas or quotes in this sentence
537 For example: @code{c f,} goes down; @code{f, f} are both the same;
538 @code{c' c} are the same; and @code{c g'} goes up:
548 \property Score.timing = ##f
549 \property Staff.TimeSignature = \turnOff
558 Here is an example of the difference between relative mode and
559 ``normal'' (non-relative) mode:
570 \property Score.timing = ##f
571 \property Staff.TimeSignature = \turnOff
587 \property Score.timing = ##f
588 \property Staff.TimeSignature = \turnOff
595 A slur is drawn across many notes, and indicates bound articulation
596 (legato). The starting note and ending note are marked with a
597 ``@code{(}'' and a ``@code{)}'' respectively:
600 @lilypond[fragment,relative 1, verbatim]
601 d4-( c16-)-( cis d e c cis d e-)-( d4-)
606 If you need two slurs at the same time (one for articulation, one for
607 phrasing), you can also make a phrasing slur with @code{\(} and
612 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
613 @c chromatic thing pasted in front. (admittedly the original does not
614 @c have a phrasing slur. The problem is that we do not want the slur
615 @c and the Phrasing slur to collide. We are trying to make a good
619 @lilypond[fragment,relative 1, verbatim]
620 a8-(-\( ais b c-) cis2 b'2 a4 cis, c-\)
625 Beams are drawn automatically, but if you do not like where they are
626 put, they can be entered by hand. Mark the first note to be beamed
627 with @code{[} and the last one with @code{]}:
629 @lilypond[fragment,relative 1, verbatim]
630 a8-[ ais-] d-[ es r d-]
635 To print more than one staff, each piece of music that makes up a staff
636 is marked by adding @code{\context Staff} before it. These
637 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and @code{@}}, as is
641 @lilypond[fragment,verbatim]
643 \context Staff = staffA { \clef violin c'' }
644 \context Staff = staffB { \clef bass c }
649 In this example, @code{staffA} and @code{staffB} are names that are
650 given to the staves. It does not matter what names you give, as long
651 as each staff has a different name. If you give them the same name,
652 they are assumed to belong on the same staff, and will be printed like
653 that. @code{\simultaneous } indicates that both fragments happen at
654 the same time, and must be printed stacked vertically.
658 We can now typeset a melody with two staves:
661 @lilypond[verbatim,singleline]
664 < \context Staff = staffA {
668 e2-( d4 c2 b4 a8-[ a-]
669 b-[ b-] g-[ g-] a2.-) }
671 \context Staff = staffB {
682 The time signature is specified in one melody staff only
683 (the top staff), but is printed on both, since common practice
684 dictates that all staves have the same time signature.
688 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
690 @lilypond[verbatim,relative 1]
696 Similarly, fingering indications can be added to a note using @code{-}
697 and the digit to be printed.
698 @lilypond[verbatim,relative 1]
706 Dynamic signs are made by adding the markings to the note:
708 @lilypond[verbatim,relative 1]
714 Crescendi and decrescendi are started with the commands @code{\<} and
715 @code{\>}. The command @code{\!} finishes a crescendo on the note it
718 @lilypond[verbatim,relative 1]
719 c2-\< c2-\!-\ff c2-\> c2-\!
724 Chords can be made by
725 surrounding pitches with @code{<<} and @code{>}>:
727 @lilypond[relative 0, fragment,verbatim]
728 r4 <<c e g>>4 <<c f a>>8
734 You can combine beams and ties with chords. Beam and tie markings
735 must be placed outside the chord markers:
737 @lilypond[relative 0, fragment,verbatim]
738 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
744 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
746 @lilypond[relative 0, fragment]
748 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
754 A pickup (or upstep) is entered with the keyword @code{\partial}. It
755 is followed by a duration: @code{\partial 4} is a quarter note upstep
756 and @code{\partial 8} an eighth note.
757 @lilypond[relative 1,verbatim,fragment]
762 Tuplets are made with the @code{\times} keyword. It takes two
763 arguments: a fraction and a piece of music. The duration of the piece
764 of music is multiplied by the fraction. Triplets make notes occupy
765 2/3 of their notated duration, so a triplet has 2/3 as its fraction.
767 @lilypond[relative 0,verbatim,fragment]
768 \times 2/3 { f8 g a }
775 Comments are pieces of the input that are ignored. There are two
776 types of comments. A line comments are introduced by @code{%}: after
777 that, the rest of that line is ignored. Block comments span larger
778 sections of input. Anything that is enclosed in @code{%@{} and
779 @code{%@}} is ignored too. The following fragment shows possible uses
783 % notes for twinkle twinkle follow:
788 This line, and the notes below
789 are ignored, since they are in a
799 @node Printing lyrics
800 @section Printing lyrics
803 Lyrics are entered by separating each syllable with a space, and
804 surrounding them with @code{\lyrics @{ @dots{} @}}, for example
806 \lyrics @{ I want to break free @}
809 Like notes, lyrics are also a form of music, but they must not be
810 printed on a staff, which is the default way to print music. To print
811 them as lyrics, they must be marked with @code{ \context Lyrics}:
813 \context Lyrics \lyrics @{ I want to break free @}
815 The melody for this song is as follows
817 @lilypond[fragment,relative=1]
820 \times 2/3 { f4 g g } \times 2/3 { g4-( a2-) }
823 The lyrics can be set to these notes, combining both with the
824 @code{\addlyrics} keyword:
828 \context Lyrics @dots{}
832 @lilypond[singleline,verbatim]
839 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
841 \context Lyrics \lyrics { I want to break free }
847 This melody ends on a @rglos{melisma}, a single syllable (``free'')
848 sung to more than one note. This is indicated with a @emph{extender
849 line}. It is entered as two underscores, i.e.,
851 \lyrics @{ I want to break free __ @}
853 @lilypond[singleline]
860 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
862 \context Lyrics \lyrics { I want to break free __ }
868 TODO: fix extender lines here.
870 Similarly, hyphens between words can be entered as two dashes,
871 resulting in a centered hyphen between two syllables.
873 Twin -- kle twin -- kle
875 @lilypond[singleline]
877 \addlyrics \notes \relative f' { \time 2/4
879 \context Lyrics \lyrics { Twin -- kle twin -- kle
881 \paper { linewidth = 6.0 \cm }
886 More options, like putting multiple lines of lyrics below a melody are
887 discussed in @ref{Vocal music}.
891 @section A lead sheet
893 In popular music, it is common to denote accompaniment as chord-names.
894 Using them in LilyPond has two parts, just like lyrics: entering the
895 chords (with @code{\chords}), and printing them (with @code{\context
898 Chord names are entered by starting chords mode (with @code{\chords}).
899 In chords mode, you can enter chords with a letter (indicating the
900 root of the chord), and a durations following that.
903 \chords { c2 f4. g8 }
907 The result of @code{\chords} is a list of chords, and is equivalent
908 to entering chords with @code{<<@dots{}>>}.
910 Other chords can be created by adding modifiers, after a colon. The
911 following example shows a few common modifiers
914 \chords { c2 f4:m g4:maj7 gis1:dim7 }
917 Printing chords is done by adding @code{\context ChordNames}
918 before the chords thus entered:
921 \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
924 A complete list of modifiers, and other options for layout are in the
925 reference manual section @ref{Chords}.
928 When put together, chord names, lyrics and a melody form
929 a lead sheet, for example,
934 \context ChordNames \chords @{ @emph{chords} @}
936 \notes @emph{the melody}
937 \context Lyrics \lyrics @{ @emph{the text} @}
945 \context ChordNames \chords { r8 c2:sus4 f }
947 \notes \relative c' {
950 \times 2/3 { f g g } \times 2/3 { g4-( a2-) } }
951 \context Lyrics \lyrics { I want to break free __ }
953 \paper{ raggedright = ##t }
958 @node Listening to output
959 @section Listening to output
961 MIDI (Musical Instrument Digital Interface) is a standard for
962 connecting and recording digital instruments. A MIDI file is like a
963 tape recording of a MIDI instrument. The @code{\midi} block makes the
964 music go to a MIDI file, so you can listen to the music you entered.
965 It is great for checking the music: octaves that are off, or
966 accidentals that were mistyped, stand out very much when listening to
967 the musical transcription.
969 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
974 \midi @{ \tempo 4=72 @}
979 Here, the tempo is specified using the @code{\tempo} command. In this
980 case the tempo of quarter notes is set to 72 beats per minute. More
981 information on auditory output is in the @ref{Sound} section in the
988 Bibliographic information is entered in a separate block, the
989 @code{\header} block. The name of the piece, its composer, etc. are
990 entered as assignment within @code{\header @{ @dots{} @}}. For
994 title = "Eight miniatures"
995 composer = "Igor Stravinsky"
996 tagline = "small is beautiful"
1002 @cindex bibliographic information
1008 When the file is processed by @code{ly2dvi}, the title and composer
1009 specified are printed above the music. The `tagline' is a short line
1010 printed at bottom of the last page, which normally says ``Lily was
1011 here, version @dots{}''. In the example above, it is replaced by the
1012 line ``small is beautiful.''
1014 Normally, the @code{\header} is put at the top of the file. However,
1015 for a document that contains multiple pieces (e.g. a etude book, or
1016 part with multiple movements), then the header can be put into the
1017 @code{\score} block as follows In this case, the name of each piece
1018 will be printed before each movement.
1021 @cindex Lily was here
1022 @cindex signature line
1027 title = "Eight miniatures"
1028 composer = "Igor Stravinsky"
1029 tagline = "small is beautiful"
1033 \header @{ piece = "Adagio" @}
1036 \header @{ piece = "Menuetto" @}
1040 More information on titling can be found in @ref{Invoking ly2dvi}.
1043 @node Single staff polyphony
1044 @section Single staff polyphony
1046 When different melodic lines are combined on a single staff, these are
1047 printed as polyphonic voices: each voice has its own stems, slurs
1048 and beams, and the top voice has the stems up, while the bottom voice
1051 Entering such parts is done by entering each voice as a sequence (with
1052 @code{@{ .. @}}), and combing those simultaneously, separating the
1053 voices with @code{\\}:
1055 @lilypond[verbatim,relative]
1056 < { a4 g2 f4-~ f4 } \\
1059 The notation @code{< .. >} is a shorthand for @code{\simultaneous @{
1060 .. @}}. More features of polyphonic typesetting are in the notation
1061 manual, @ref{Polyphony}.
1064 @section Piano staffs
1066 @cindex staff switch, manual
1067 @cindex cross staff voice, manual
1068 @cindex @code{\translator}
1073 @node Organising larger pieces
1074 @section Organising larger pieces
1076 TODO: discuss identifiers, p&c, .
1082 Lilypond and its language are still under development, and
1083 occasionally details of the syntax are changed. The @code{version}
1084 fragment indicates which LilyPond version the input file was written
1085 for. When you compile this file, the version number will be
1086 checked. When the file is too old, a warning is issued. The version
1087 number is also used by the @code{convert-ly} program (See
1088 @ref{Invoking convert-ly}), which updates the file to the latest
1089 version automatically.
1096 @code{s} is a spacer rest. It does not print anything, but it does have
1097 the duration of a rest. It is useful for filling up voices that
1098 temporarily do not play. In this case, the viola does not come until one
1099 and a half measure later.
1103 \grace <<e g>>-( <<d f>>4-) <<c e>>2
1105 @cindex @code{\grace}
1108 @code{\grace} introduces grace notes. It takes one argument, in this
1109 case a chord. A slur is introduced starting from the @code{\grace}
1110 ending on the following chord.
1121 @{ <<d f>>8 <<e g>> <<f a>> @}
1123 The piece of music to be `tripletted' is sequential music containing
1127 The bass has a little hoom-pah melody to demonstrate parts switching
1128 between staves. Since it is repetitive, we use repeats:
1131 hoomPah = \repeat unfold 8
1133 @cindex unfolded @code{\repeat}
1134 The unfolded repeat prints the notes in its argument as if they were
1135 written out in full eight times.
1138 @node Fine tuning a piece
1139 @section Fine tuning a piece
1141 In this section we show some ways to fine tune the final output of a
1142 piece. We do so using a single measure of a moderately complex piano
1143 piece: a Brahms intermezzo (opus 119, no. 1). Both fragments (the
1144 tuned and the untuned versions) are in @file{input/tutorial/}.
1146 The code for the untuned example shows us some new things.
1148 @lilypondfile[verbatim]{brahms-original.ly}
1159 Now that we have the basic piece of music entered, we want to fine
1160 tune it so that we get something that resembles the original printed
1161 edition by Schott/Universal Edition:
1163 @lilypondfile{brahms-tweaked.ly}
1165 @cindex tuning graphical objects
1167 Fine tuning involves overriding the defaults of the printing system.
1168 We do this by setting variables which control how Lilypond prints
1169 symbols. Printed symbols are called graphical objects (often
1170 abbreviated to @emph{grob}). Each object is described by a bunch of
1171 settings. Every setting is a variable: it has a name and a value
1172 which you can change. These values determine the fonts, offsets,
1173 sub-routines to be called on the object, etc. The initial values of
1174 these settings are set in the Scheme file
1175 @file{scm/grob-description.scm}.
1177 @cindex slur attachments
1179 We start with the slur in the upper part, running from F sharp to A. In
1180 the printed edition, this slur runs from stem to stem; in our version,
1181 the slur begins at the note head of the F sharp. The following property
1182 setting forces all slurs to run from stem to stem (not from or to note
1186 \property Voice.Slur \set #'attachment = #'(stem . stem)
1189 More precisely, this command modifies the definition of the @code{Slur}
1190 object in the current @code{Voice}. The variable @code{attachment} is
1191 set to the pair of symbols @code{'(stem . stem)}.
1193 @cindex internal documentation
1194 @cindex finding graphical objects
1195 @cindex graphical object descriptions
1197 This command fixes one particular problem with a slur. The rest of
1198 this section explains how to figure out which properties to tune for
1199 your own scores. To discover this, you must have a copy of the
1200 internals document. This is a set of HTML pages which should be
1201 included if you installed a binary distribution. [TODO: revise for
1202 new site.] These HTML pages are also available on the web: go to the
1203 LilyPond website, click ``Documentation: Index'' on the side bar, look
1204 in the ``Information for uses'' section, and click on ``Documentation
1207 You might want to bookmark either the HTML files on your disk, or the
1208 one on the web (the HTML on your hard drive will load much faster than
1209 the ones on the web!). One word of caution: the internals
1210 documentation is generated from the definitions that the program uses.
1211 Hence, the internals documentation is strongly tied to the version you
1212 use. Before you proceed, make sure that the program and documentation
1213 have matching version numbers.
1215 @c TODO: the quote is incorrect, although that shouldn't be a big
1216 @c problem for the reader.
1217 Suppose that you wanted to tune the behavior of the slur. The first
1218 step is to get some general information on slurs in LilyPond. Turn to
1219 the index, and look up ``slur''. The section on slurs says
1221 The grob for this object is @internalsref{Slur}, generally in
1222 @internalsref{Voice} context.
1225 So the graphical object for this object is called @code{Slur}, and
1226 slurs are created in the @code{Voice} context. If you are reading
1227 this tutorial in the HTML version, then you can simply click Slur,
1228 otherwise, you should look it up the internal documentation: click
1229 ``grob overview'' and select ``slur'' (the list is alphabetical).
1231 Now you get a list of all the properties that the slur object
1232 supports, along with their default values. Among the properties we
1233 find the @code{attachment} property with its default setting.
1234 The property documentation explains that the following setting will
1235 produce the desired effect:
1237 \property Voice.Slur \set #'attachment = #'(stem . stem)
1240 @c this is a long section, and adding an extra space here helps to
1241 @c break it into smaller subsections and thus is easier to understand.
1244 Next we want to move the fingering `3'. In the printed edition it is
1245 not above the stem, but a little lower and slightly left of the stem.
1246 From the user manual we find that the associated graphical object is
1247 called @code{Fingering}, but how do we know if we should use
1248 @code{Voice} or @code{Staff}? In many cases, @code{Voice} is a safe
1249 bet, but you can also deduce this information from the internals
1250 documentation: if you visit the documentation of @code{Fingering}, you
1253 Fingering grobs are created by: Fingering_engraver
1256 Clicking @code{Fingering_engraver} will show you the documentation of
1257 the module responsible for interpreting the fingering instructions and
1258 translating them to a @code{Fingering} object. Such a module is called
1259 an @emph{engraver}. The documentation of the @code{Fingering_engraver}
1262 Fingering_engraver is part of contexts: Voice and TabVoice
1264 so tuning the settings for Fingering should be done using either
1266 \property Voice.Fingering \set @dots{}
1270 \property TabVoice.Fingering \set @dots{}
1273 Since the @code{TabVoice} is only used for tab notation, we see that
1274 the first guess @code{Voice} was indeed correct.
1276 @cindex setting object properties
1277 @cindex @code{extra-offset}
1279 For shifting the fingering, we use the property @code{extra-offset}.
1280 The following command manually adds an offset to the object. We move
1281 it a little to the left, and 1.8 staff space downwards.
1283 \once \property Voice.Fingering \set #'extra-offset = #'(-0.3 . -1.8)
1285 The @code{extra-offset} is a low-level feature: it moves around
1286 objects in the printout; the formatting engine is completely oblivious
1287 to these offsets. The unit of these offsets are staff-spaces. The
1288 first number controls left-right movement; a positive number will move
1289 the object to the right. The second number controls up-down movement;
1290 a positive number will move it higher.
1291 We only want to offset a single object, so this statement is adorned
1294 @cindex property types
1295 @cindex translator properties
1296 @cindex grob properties
1297 @cindex music properties
1300 There are three different types of variables in LilyPond, something
1301 which can be confusing at first (and for some people it stays
1302 confusing). Variables such as @code{extra-offset} and
1303 @code{attachment} are called grob properties. They are not the same
1304 as translator properties, like @code{autoBeaming}. Finally, music
1305 expressions are internally stored using properties (so-called music
1306 properties). You will encounter music properties if you run Scheme
1307 functions on music using @code{\apply}.
1309 The second fingering instruction should be moved up a little to avoid
1310 a collision with the slur. This could be achieved with
1311 @code{extra-offset}, but in this case, a simpler mechanism also
1312 works. We insert an empty text between the 5 and the note. The empty
1313 text pushes the fingering instruction away:
1315 a-)^" "^\markup @{ \finger "5" @}
1318 A fingering instruction, which would be entered as @code{^5}, is put
1319 as close to the notes as possible, closer than the space entered to
1320 push away the 5. Hence, the 5 is entered as a normal text, with the
1321 formatting of fingering instructions.
1325 Normally one would specify all dynamics in the same voice, so that
1326 dynamics (such as @b{f} and @b{p}) will be aligned with hairpins. But
1327 in this case, we do not want the decrescendo to be aligned with the
1328 piano sign. We achieve this by putting the dynamic markings in different
1329 voices. The crescendo should be above the upper staff. This can be
1330 forced by using the precooked command
1335 However, if you do that the decrescendo will be too close to the upper
1336 voice and collide with the stems. Looking at the manual for dynamics,
1337 we notice that ``Vertical positioning of these symbols is handled by
1338 the @internalsref{DynamicLineSpanner} grob.''. If we turn to the
1339 documentation of @code{DynamicLineSpanner}, we find that
1340 @code{DynamicLineSpanner} supports several so-called `interfaces'.
1341 This object not only puts objects next to the staff
1342 (@code{side-position-interface}), but it also groups dynamic objects
1343 (@code{axis-group-interface}), is considered a dynamic sign itself
1344 (@code{dynamic-interface}), and is an spanning object
1345 (@code{spanner-interface}). It also has the standard
1346 @code{grob-interface} with all the variables that come with it.
1348 For the moment we are interested in side positioning:
1350 side-position-interface
1352 Position a victim object (this one) next to other objects (the
1353 support). In this case, the direction signifies where to put the
1354 victim object relative to the support (left or right, up or down?)
1356 Between the object and its support (in this case, the descending
1357 notes), there should be more space. This space is controlled by
1358 @code{padding}, so we increase it.
1360 \property Voice.DynamicLineSpanner \override #'padding = #5.0
1366 Brahms uses music notation is a slightly unorthodox way. Ties
1367 usually happen only within one voice. In this piece, the composer
1368 gladly produces ties that jump voices. We deal with this by faking
1369 these ties: whenever we need such a tie, we insert a notehead in a
1370 different voice, and blank the stem. This is done in the following
1373 @cindex transparent objects
1374 @cindex removing objects
1375 @cindex invisible objects
1377 \property Voice.Stem \set #'transparent = ##t
1380 Blanking the stem should be done for only one object. One of the ways
1381 to achieve that, is by setting the property before a note. Reverting
1382 it afterwards is tedious, so for setting a property only once, we have
1383 the syntax @code{\once}: it reverts the property directly before
1384 proceeding to the next step in time.
1386 The @code{\once} keyword is added to @code{\property}.
1389 Finally, the last tie is forced up using @code{\tieUp}.
1393 Here is the complete ``fine tuned'' version, which includes all the
1394 modifications we discussed in this section:
1396 @lilypondfile[verbatim]{brahms-tweaked.ly}
1399 @node An orchestral part
1400 @section An orchestral part
1405 \markup, mmrest, transposing, cue notes, identifiers?.
1408 @node Integrating text and music
1409 @section Integrating text and music
1412 @cindex La@TeX{}, music in
1413 @cindex HTML, music in
1414 @cindex Texinfo, music in
1416 Sometimes you might want to use music examples in a text that you are
1417 writing (for example a musicological treatise, a songbook, or (like us)
1418 the LilyPond manual). You can make such texts by hand, simply by
1419 importing a PostScript figure into your word processor. However,
1420 there is an automated procedure to reduce the amount of work.
1422 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1423 code. A script called @code{lilypond-book} will extract the music
1424 fragments, run LilyPond on them, and put back the resulting notation.
1425 This program is fully described in @ref{lilypond-book manual}. Here
1426 we show a small example. Since the example also contains explanatory
1427 text, we will not comment it further.
1430 \documentclass[a4paper]@{article@}
1433 In a lilypond-book document, you can freely mix music and text. For
1436 \score @{ \notes \relative c' @{
1437 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1441 Notice that the music line length matches the margin settings of the
1444 If you have no \verb+\score+ block in the fragment,
1445 \texttt@{lilypond-book@} will supply one:
1451 In the example you see here, two things happened: a
1452 \verb+\score+ block was added, and the line width was set to natural
1453 length. You can specify many more options using \LaTeX style options
1456 \begin[verbatim,11pt,singleline,
1457 fragment,relative,intertext="hi there!"]@{lilypond@}
1461 The option \texttt@{verbatim@} prints the LilyPond code in addition to
1462 the graphical score, \texttt@{11pt@} selects the default music size,
1463 \texttt@{fragment@} adds a score block, \texttt@{relative@} uses
1464 relative mode for the fragment, and \texttt@{intertext@} specifies
1465 what to print between the \texttt@{verbatim@} code and the music.
1467 If you want to include large examples into the text, it may be more
1468 convenient to put the example in a separate file:
1470 \lilypondfile[printfilename]@{screech-boink.ly@}
1472 The \texttt@{printfilename@} option adds the file name to the output.
1477 Under Unix, you can view the results as follows.
1481 $ lilypond-book --outdir=out/ lilbook.tex
1482 lilypond-book (GNU LilyPond) 1.7.16
1483 Reading `input/tutorial/lilbook.tex'
1484 Reading `input/screech-boink6.ly'
1485 @var{lots of stuff deleted}
1486 Writing `out/lilbook.latex'
1488 $ latex lilbook.latex
1489 @var{lots of stuff deleted}
1493 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
1494 and running latex creates a lot of temporary files, and you would not want
1495 those to clutter up your working directory. Hence, we have them created
1496 in a separate subdirectory.
1498 The result looks more or less like this:
1502 In a lilypond-book document, you can freely mix music and text. For
1506 \notes \relative c' {
1507 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1515 Notice that the music line length matches the margin settings of the
1518 If you have no @code{\score} block in the fragment,
1519 @code{lilypond-book} will supply one:
1525 In the example you see here, a number of things happened: a
1526 @code{\score} block was added, and the line width was set to natural
1527 length. You can specify many more options using La@TeX{} style options
1530 @lilypond[verbatim,11pt,singleline,
1531 fragment,relative,intertext="hi there!"]
1535 The option @code{verbatim} also shows the LilyPond code, @code{11pt} selects
1536 the default music size, @code{fragment} adds a score block,
1537 @code{relative} uses relative mode for the fragment, and
1538 @code{intertext} specifies what to print between the
1539 @code{verbatim} code and the music.
1541 If you include large examples into the text, it may be more convenient
1542 to put the example in a separate file:
1544 @lilypondfile[printfilename]{screech-boink.ly}
1546 The @code{printfilename} option adds the file name to the output.