4 @c * more details about running lilypond; error messages,
5 @c compiling/viewing (emacs?)
6 @c * where to go from First steps+More basics?
12 <!--- @@WEB-TITLE@@=Tutorial --->
16 * First steps:: Music language of LilyPond.
17 * Running LilyPond:: Printing music.
18 * More about pitches and accidentals::
20 * Relative octave entry::
21 * Combining music into compound expressions::
22 * Adding articulation marks to notes ::
23 * Combining notes into chords::
26 * Listening to output::
28 * Single staff polyphony ::
31 * Fine tuning layout::
32 * Organizing larger pieces::
33 * An orchestral part::
34 * Integrating text and music:: Integrating text and music.
37 Using LilyPond comes down to encoding music in an input file. After
38 entering the music, the program is run on the file producing output
39 which can be viewed or printed. In this tutorial, we will show step
40 by step how to enter such files, by showing fragments of input and the
41 corresponding output. At the end of every section, a paragraph will
42 list where to find further information on the topics discussed.
44 Many people learn programs by trying and fiddling around with the
45 program. This is also possible with LilyPond. If you click on a
46 picture in the HTML version of this manual, you will see the exact
47 LilyPond input that was used to generate that image.
50 @lilypond[relative 1,verbatim,singleline]
51 c'^\markup { \bold \huge { Click on this image! } }
53 As you can see, most of input shown is simplified a little. This has
54 been done for reasons of space and clarity.
56 By cutting and pasting that into your own files, you have a starting
57 template for experiments. If you like learning in this way, you will
58 probably want to print out or bookmark
62 @ref{Cheat sheet}, which is a table listing all commands for quick
66 This tutorial starts with a short introduction to the LilyPond music
67 language. After this first contact, we will show you how to to
68 produce printed output, normally using the program @code{ly2dvi}. You
69 should then be able to create and print your first sheets of music.
75 We start off by showing how very simple music is entered in LilyPond:
76 you get a note simply by typing its @htmlref{note name}, from @samp{a}
77 through @samp{g}. So if you enter
84 then the result looks like this:
87 @c \transpose c c' { c d e f g a b }
89 @c \property Score.timing = ##f
90 @lilypond[notime, relative=2]
94 The length of a note is specified by adding a number, @samp{1} for a
95 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
102 \property Score.timing = ##f
103 \property Staff.autoBeaming = ##f
104 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
107 If you do not specify a @rglos{duration}, the previous one is used:
114 \property Score.timing = ##f
115 \transpose c c' { a a a2 a s16_" " }
119 Rests are entered just like notes, but with the name ``@code{r}'':
128 \property Score.timing = ##f
129 \property Staff.Clef = \turnOff
130 \property Staff.TimeSignature = \turnOff
138 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
145 \property Score.timing = ##f
146 \transpose c c' { a2. a4 a8. a16 s16_" " }
150 The @rglos{meter} (or @rglos{time signature}) can be set with the
151 @code{\time} command:
159 @c a clef here may lead to confusion
161 \property Staff.Clef \set #'transparent = ##t
171 The @rglos{clef} can be set using the @code{\clef} command:
173 @c what is more common name treble or violin?
174 @c in Dutch, its violin.
175 @c in English its definitely treble.
184 \property Score.timing = ##f
195 Notes and commands like @code{\clef} and @code{\time} , are enclosed
196 in @code{\notes @{@dots{}@}}. This indicates that music (as opposed
197 to @rglos{lyrics}) follows:
207 Now the piece of music is almost ready to be printed. The final step is to
208 combine the music with a printing command.
210 The printing command is the so-called @code{\paper} block. The
211 @code{\paper} block is used to customize printing specifics, but we
212 accept the defaults for now. The music and the @code{\paper} block
213 are combined by enclosing them in @code{\score @{ ... @}}. The
214 following is a complete and valid input file.
237 linewidth = 55 * \staffspace
242 During the rest of the tutorial, we will often leave out @code{\score}
243 and @code{\paper}, for clarity. However, both must be present when
244 feeding the file to LilyPond.
246 More elaborate information on entering pitches and durations is in
247 @ref{Pitches} and @ref{Durations}. Clefs are fully explained in
248 @ref{Clef}. Time signatures and other timing commands are described
249 in @ref{Time signature}.
252 @node Running LilyPond
253 @section Running LilyPond
255 In the last section we explained what kind of things you could enter
256 in a LilyPond file. In this section we explain what commands to run
257 and how to view or print the output. If you have not used LilyPond
258 before, want to test your setup, or want to run an example file
259 yourself, read this section. The instructions that follow are for
260 Unix-like systems. Some additional instructions for Microsoft Windows
261 are given at the end of this section.
263 Begin by opening a terminal window and starting a text editor.
264 For example, you could open an xterm and execute @code{joe}. In your
265 text editor, enter the following input and save the file as
271 \notes @{ c'4 e' g' @}
278 @c now this is weird, running ly2dvi to run LilyPond
279 @c (therefore name change proposal)
281 LilyPond is the program that computes the sheet music. All other
282 things, such as adding titles, page breaking and other page layout,
283 are done by a small wrapper program called
284 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
285 then adds the titling and page layout instructions. To process
286 @file{test.ly} with @code{ly2dvi}, proceed as follows:
294 You will see something resembling:
299 Now processing: `/home/fred/ly/test.ly'
301 Interpreting music...[1]
302 @emph{ ... more interesting stuff ... }
303 PDF output to `test.pdf'...
304 DVI output to `test.dvi'...
308 @cindex Viewing music
311 The result of the ly2dvi is the file @file{test.pdf}.@footnote{ For
312 @TeX{} afficionados, there is also a (@file{test.dvi}) file. It can be
313 viewed with @code{xdvi}. The DVI uses a lot of PostScript specials,
314 which do not show up in the magnifying glass. The specials also mean
315 that the DVI file cannot be processed with @code{dvilj}. Use
316 @code{dvips} for printing.
320 } One the following commands should put the PDF on your
334 If the music on your screen looks good, you can print it by clicking
335 File/Print inside your viewing program.
339 @cindex Printing output
344 On Windows, the terminal is started by clicking on the LilyPond or
345 Cygwin icon. Any text editor (such as NotePad, Emacs or Vim) may be
346 used to edit the LilyPond file. If you have a PDF viewer installed,
347 use that for viewing the PDF
348 @c where on file system for double-click people?
349 If you have no viewer, then you can download @code{GSView} from
350 @uref{http://www.cs.wisc.edu/~ghost}. With @code{GSView},
351 the PDF file can viewed with
354 @code{gsview32 test.pdf}
357 Printing may be done with
360 @code{gsview32 /s test.pdf}
364 The commands for formatting and printing music are detailed in
365 @ref{Invoking LilyPond}.
367 @node More about pitches and accidentals
368 @section More about pitches and accidentals
370 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
371 @rglos{flat} (@texiflat{}) by adding @samp{es}. As you might expect,
372 a @rglos{double sharp} or @rglos{double flat} is made by adding
373 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
374 naming conventions in Nordic and Germanic languages, like German and
382 \property Score.timing = ##f
383 \transpose c c' { cis1 ees fisis aeses s16_" " }
387 @cindex key signature, setting
389 The key signature is set with the command ``@code{\key}'', followed by
390 a pitch and @code{\major} or @code{\minor}:
400 \property Staff.TimeSignature = \turnOff
410 A tie is created by adding a tilde ``@code{~}'' to the first note
413 @lilypond[fragment,verbatim,relative 2]
419 This example shows the key signature, accidentals and ties in action.
430 fis4 fis8 fis8 eis4 a8 gis-~
439 \notes { \transpose c c' {
445 fis4 fis8 fis8 eis4 a8 gis-~
448 \paper { linewidth = #(* 50 staffspace) }
454 There are some interesting points to note in this example. Bar lines
455 and beams are drawn automatically. Line breaks are calculated
456 automatically; it does not matter where the lines breaks are in the
457 source file. Finally, the order of time, key and clef changes is not
458 relevant: in the printout, these are ordered according to standard
459 notation conventions.
461 Accidentals (sharps and flats) do not have to be marked explicitly:
462 you just enter the pitch of the note, and an accidental is printed
463 only when necessary. The flip side of this mechanism, is that you have
464 to mark notes as sharp or flat, even when they do not get accidentals.
465 For example, in the key of C-sharp major, no note gets an explicit
466 accidental, but still you enter
467 @lilypond[fragment,verbatim]
470 cis dis eis fis gis ais bis
473 Adding all alterations explicitly might require some more effort when
474 typing, but the advantage is that transposing is easier. It also makes
475 it possible to use different conventions for when to print
479 @section Octave entry
482 @c Tim wants to move this quotes example just before the: quotes-do not-work
483 @c score, but we'd need to remove quotes from the other two (key and
486 @c better to have this just before the `octaves are bad' snipped
487 @c but we'd need to remove the ', from \key and tie
488 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
489 the note name, to lower a note one octave, add a ``low quote'' @code{,}
490 (a comma). Middle C is @code{c'}:
494 c'4 c'' c''' \clef bass c c,
498 \property Score.timing = ##f
499 \property Staff.TimeSignature = \turnOff
500 c'4 c'' c''' \clef bass c c,
505 An example of the use of quotes is in the following Mozart fragment.
506 @lilypond[singleline,fragment,verbatim]
509 cis''8. d''16 cis''8 e''4 e''8
510 b'8. cis''16 b'8 d''4 d''8
513 This example shows that music in a high register needs lots of quotes.
514 This makes the input less readable, and it is a source of errors. The
515 solution is to use ``relative octave'' mode. In practice, this is the
516 most convenient way to copy existing music. To use relative mode, add
517 @code{\relative} before the piece of music. You must also give a note
518 from which relative starts, in this case @code{c''}. If you do not
519 use octavation quotes (i.e. do not add ' or , after a note), relative
520 mode chooses the note that is closest to the previous one.
521 For example, @code{c f} goes up while @code{c g} goes down.
531 \property Score.timing = ##f
532 \property Staff.TimeSignature = \turnOff
541 Since most music has small intervals, in relative mode pieces can be
542 written almost without using octavation quotes. In relative mode, the
543 Mozart example is entered as
545 @lilypond[singleline,fragment,verbatim]
555 @c needed better, maybe even redundant explanation
556 @c added another example below.
557 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
558 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
559 Larger intervals are made by adding octavation quotes. Quotes or
560 commas do not determine the absolute height of a note; the height of a
561 note is relative to the previous one.
562 @c do not use commas or quotes in this sentence
563 For example: @code{c f,} goes down; @code{f, f} are both the same;
564 @code{c' c} are the same; and @code{c g'} goes up:
574 \property Score.timing = ##f
575 \property Staff.TimeSignature = \turnOff
584 Here is an example of the difference between relative mode and
585 ``normal'' (non-relative) mode:
596 \property Score.timing = ##f
597 \property Staff.TimeSignature = \turnOff
613 \property Score.timing = ##f
614 \property Staff.TimeSignature = \turnOff
624 @node Relative octave entry
625 @section Relative octave entry
629 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
630 @c chromatic thing pasted in front. (admittedly the original does not
631 @c have a phrasing slur. The problem is that we do not want the slur
632 @c and the Phrasing slur to collide. We are trying to make a good
636 @lilypond[fragment,relative 1, verbatim]
637 a8-(-\( ais b c-) cis2 b'2 a4 cis, c-\)
642 @cindex beams, by hand
643 Beams are drawn automatically, but if you do not like where they are
644 put, they can be entered by hand. Mark the first note to be beamed
645 with @code{[} and the last one with @code{]}:
647 @lilypond[fragment,relative 1, verbatim]
648 a8-[ ais-] d-[ es r d-]
653 Rests are described in full detail in @ref{Rests}.
655 The notation manual discusses ties in @ref{Ties}.
660 @node Combining music into compound expressions
661 @section Combining music into compound expressions
663 To print more than one staff, each piece of music that makes up a staff
664 is marked by adding @code{\context Staff} before it. These
665 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and @code{@}}, as is
669 @lilypond[fragment,verbatim]
671 \context Staff = staffA { \clef violin c'' }
672 \context Staff = staffB { \clef bass c }
677 In this example, @code{staffA} and @code{staffB} are names that are
678 given to the staves. It does not matter what names you give, as long
679 as each staff has a different name. If you give them the same name,
680 they are assumed to belong on the same staff, and will be printed like
681 that. @code{\simultaneous } indicates that both fragments happen at
682 the same time, and must be printed stacked vertically. The notation
683 @code{< .. >} can also be used as a shorthand for @code{\simultaneous
688 We can now typeset a melody with two staves:
691 @lilypond[verbatim,singleline]
694 < \context Staff = staffA {
698 e2-( d4 c2 b4 a8-[ a-]
699 b-[ b-] g-[ g-] a2.-) }
701 \context Staff = staffB {
712 The example shows how small chunks of music, for example the notes
713 @code{c2}, @code{e4}, etc. of the second staff, are combined to form a
714 larger chunk by enclosing it in braces. Again, a larger chunk is
715 formed by prefix @code{\context Staff} to it, and that chunk is
716 combined with @code{< >}. This mechanism is similar with mathematical
717 formulas: in a formula, a so-called expression is formed by combining
718 simpler expressions into larger expressions. For example,
727 ((1 + 2) * 3) / (4 * 5)
730 @cindex music expression
731 is a sequence of expressions, where each expression is contained in
732 the next one. The simplest expressions are numbers and operators
733 (like +, * and /). Parentheses are used to group expressions. In
734 LilyPond input, a similar mechanism is used. Here, the simplest
735 expressions are notes and rests. By enclosing expressions in @code{<
736 >} and @code{@{ @}}, more complex music is formed. The @code{\context}
737 also forms new expressions; it is prepended to a music expression.
740 When spreading expressions over multiple lines, it is customary to use
741 an indent that indicates the nesting level. Formatting music like this
742 eases reading, and helps you insert the right amount of closing
743 braces at the end of an expression. For example
757 @node Adding articulation marks to notes
758 @section Adding articulation marks to notes
764 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
766 @lilypond[verbatim,relative 1]
773 Similarly, fingering indications can be added to a note using @code{-}
774 and the digit to be printed.
775 @lilypond[verbatim,relative 1]
780 Dynamic signs are made by adding the markings to the note:
782 @lilypond[verbatim,relative 1]
792 Crescendi and decrescendi are started with the commands @code{\<} and
793 @code{\>}. The command @code{\!} finishes a crescendo on the note it
796 @lilypond[verbatim,relative 1]
797 c2-\< c2-\!-\ff c2-\> c2-\!
806 A slur is drawn across many notes, and indicates bound articulation
807 (legato). The starting note and ending note are marked with a
808 ``@code{(}'' and a ``@code{)}'' respectively:
811 @lilypond[fragment,relative 1, verbatim]
812 d4-( c16-)-( cis d e c cis d e-)-( d4-)
816 @cindex slurs versus ties
817 A slur is different from a tie. A tie simply makes the first note
818 sound longer, and can only be used on pairs of notes with the same
819 pitch. Slurs indicate the articulations of notes, and can be used on
820 larger groups of notes. Slurs and ties are also nested in practice:
821 @lilypond[fragment, relative=1]
822 c2-~-( c8 fis fis4 ~ fis2 g2-)
825 @cindex phrasing slurs
826 If you need two slurs at the same time (one for articulation, one for
827 phrasing), you can also make a phrasing slur with @code{\(} and
832 @node Combining notes into chords
833 @section Combining notes into chords
836 Chords can be made by
837 surrounding pitches with @code{<<} and @code{>}>:
839 @lilypond[relative 0, fragment,verbatim]
840 r4 <<c e g>>4 <<c f a>>8
846 You can combine beams and ties with chords. Beam and tie markings
847 must be placed outside the chord markers:
849 @lilypond[relative 0, fragment,verbatim]
850 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
856 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
858 @lilypond[relative 0, fragment]
860 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
868 * Basic rhythmical commands::
869 * Commenting input files::
872 @node Basic rhythmical commands
873 @subsection Basic rhythmical commands
878 @cindex partial measure
879 A pickup (or upstep) is entered with the keyword @code{\partial}. It
880 is followed by a duration: @code{\partial 4} is a quarter note upstep
881 and @code{\partial 8} an eighth note.
882 @lilypond[relative 1,verbatim,fragment]
889 Tuplets are made with the @code{\times} keyword. It takes two
890 arguments: a fraction and a piece of music. The duration of the piece
891 of music is multiplied by the fraction. Triplets make notes occupy
892 2/3 of their notated duration, so a triplet has 2/3 as its fraction.
894 @lilypond[relative 0,verbatim,fragment]
895 \times 2/3 { f8 g a }
901 Grace notes are also made by prefixing a note, or a set of notes with
902 a keyword. In this case, the keyword is @code{\grace}.
903 @lilypond[relative 1, verbatim,fragment]
905 \grace { d16-( e } d4-)
909 More information on the use of grace notes is in @ref{Grace notes}.
912 @node Commenting input files
913 @subsection Commenting input files
917 @cindex block comment
918 Comments are pieces of the input that are ignored. There are two
919 types of comments. A line comments are introduced by @code{%}: after
920 that, the rest of that line is ignored. Block comments span larger
921 sections of input. Anything that is enclosed in @code{%@{} and
922 @code{%@}} is ignored too. The following fragment shows possible uses
926 % notes for twinkle twinkle follow:
931 This line, and the notes below
932 are ignored, since they are in a
942 @node Printing lyrics
943 @section Printing lyrics
948 Lyrics are entered by separating each syllable with a space, and
949 surrounding them with @code{\lyrics @{ @dots{} @}}, for example
951 \lyrics @{ I want to break free @}
954 Like notes, lyrics are also a form of music, but they must not be
955 printed on a staff, which is the default way to print music. To print
956 them as lyrics, they must be marked with @code{ \context Lyrics}:
958 \context Lyrics \lyrics @{ I want to break free @}
960 The melody for this song is as follows
962 @lilypond[fragment,relative=1]
965 \times 2/3 { f4 g g } \times 2/3 { g4-( a2-) }
968 The lyrics can be set to these notes, combining both with the
969 @code{\addlyrics} keyword:
973 \context Lyrics @dots{}
977 @lilypond[verbatim,linewidth=6.0cm]
984 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
986 \context Lyrics \lyrics { I want to break free }
993 @cindex extender line
995 This melody ends on a @rglos{melisma}, a single syllable (``free'')
996 sung to more than one note. This is indicated with a @emph{extender
997 line}. It is entered as two underscores, i.e.,
999 \lyrics @{ I want to break free __ @}
1008 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
1010 %% ugh, this is to deal with bugs in the extender implementation
1014 \context Lyrics \lyrics { I want to break free __ }
1016 \paper{ linewidth = 9.0 \cm }
1020 Similarly, hyphens between words can be entered as two dashes,
1021 resulting in a centered hyphen between two syllables.
1023 Twin -- kle twin -- kle
1025 @lilypond[singleline]
1027 \addlyrics \notes \relative f' { \time 2/4
1029 \context Lyrics \lyrics { Twin -- kle twin -- kle
1031 \paper { linewidth = 6.0 \cm }
1036 More options, like putting multiple lines of lyrics below a melody are
1037 discussed in @ref{Vocal music}.
1041 TODO: discuss contexts.
1045 @section A lead sheet
1051 In popular music, it is common to denote accompaniment as chord-names.
1052 Using them in LilyPond has two parts, just like lyrics: entering the
1053 chords (with @code{\chords}), and printing them (with @code{\context
1056 Chord names are entered by starting chords mode (with @code{\chords}).
1057 In chords mode, you can enter chords with a letter (indicating the
1058 root of the chord), and a durations following that.
1061 \chords { c2 f4. g8 }
1065 The result of @code{\chords} is a list of chords, and is equivalent
1066 to entering chords with @code{<<@dots{}>>}.
1068 Other chords can be created by adding modifiers, after a colon. The
1069 following example shows a few common modifiers
1072 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1075 Printing chords is done by adding @code{\context ChordNames}
1076 before the chords thus entered:
1079 \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1082 A complete list of modifiers, and other options for layout are in the
1083 reference manual section @ref{Chords}.
1086 When put together, chord names, lyrics and a melody form
1087 a lead sheet, for example,
1092 \context ChordNames \chords @{ @emph{chords} @}
1094 \notes @emph{the melody}
1095 \context Lyrics \lyrics @{ @emph{the text} @}
1103 \context ChordNames \chords { r8 c2:sus4 f }
1105 \notes \relative c' {
1108 \times 2/3 { f g g } \times 2/3 { g4-( a2-) } }
1109 \context Lyrics \lyrics { I want to break free __ }
1111 \paper{ raggedright = ##t }
1116 @node Listening to output
1117 @section Listening to output
1122 MIDI (Musical Instrument Digital Interface) is a standard for
1123 connecting and recording digital instruments. A MIDI file is like a
1124 tape recording of a MIDI instrument. The @code{\midi} block makes the
1125 music go to a MIDI file, so you can listen to the music you entered.
1126 It is great for checking the music: octaves that are off, or
1127 accidentals that were mistyped, stand out very much when listening to
1128 the musical transcription.
1130 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
1135 \midi @{ \tempo 4=72 @}
1140 Here, the tempo is specified using the @code{\tempo} command. In this
1141 case the tempo of quarter notes is set to 72 beats per minute. More
1142 information on auditory output is in the @ref{Sound} section in the
1149 Bibliographic information is entered in a separate block, the
1150 @code{\header} block. The name of the piece, its composer, etc. are
1151 entered as assignment within @code{\header @{ @dots{} @}}. For
1155 title = "Eight miniatures"
1156 composer = "Igor Stravinsky"
1157 tagline = "small is beautiful"
1160 \score @{ @dots{} @}
1163 @cindex bibliographic information
1169 When the file is processed by @code{ly2dvi}, the title and composer
1170 specified are printed above the music. The `tagline' is a short line
1171 printed at bottom of the last page, which normally says ``Lily was
1172 here, version @dots{}''. In the example above, it is replaced by the
1173 line ``small is beautiful.''
1175 Normally, the @code{\header} is put at the top of the file. However,
1176 for a document that contains multiple pieces (e.g. a etude book, or
1177 part with multiple movements), then the header can be put into the
1178 @code{\score} block as follows In this case, the name of each piece
1179 will be printed before each movement.
1182 @cindex Lily was here
1183 @cindex signature line
1188 title = "Eight miniatures"
1189 composer = "Igor Stravinsky"
1190 tagline = "small is beautiful"
1194 \header @{ piece = "Adagio" @}
1197 \header @{ piece = "Menuetto" @}
1201 More information on titling can be found in @ref{Invoking ly2dvi}.
1204 @node Single staff polyphony
1205 @section Single staff polyphony
1208 @cindex multiple voices
1209 @cindex voices, more -- on a staff
1211 When different melodic lines are combined on a single staff, these are
1212 printed as polyphonic voices: each voice has its own stems, slurs
1213 and beams, and the top voice has the stems up, while the bottom voice
1216 Entering such parts is done by entering each voice as a sequence (with
1217 @code{@{ .. @}}), and combing those simultaneously, separating the
1218 voices with @code{\\}:
1221 < @{ a4 g2 f4-~ f4 @} \\
1224 @lilypond[relative 1]
1225 \context Staff < { a4 g2 f4-~ f4 } \\
1229 For polyphonic typesetting spacer rests can also be convenient: these
1230 are rests that do not print. It is useful for filling up voices that
1231 temporarily do not play:
1233 < @{ a4 g2 f4-~ f4 @} \\
1236 @lilypond[relative 1]
1237 \context Staff < { a4 g2 f4-~ f4 } \\
1241 More features of polyphonic typesetting are in the notation manual
1245 @section Piano staffs
1247 @cindex staff switch, manual
1248 @cindex cross staff voice, manual
1249 @cindex @code{\translator}
1251 Piano music is always typeset in two staffs connected by a brace.
1252 Printing such a staff is done similar to the polyphonic example in
1253 @ref{Combining music into compound expressions}:
1255 < \context Staff = up @{ @dots{} @}
1256 \context Staff = down @{ @dots{} @}
1259 but now this entire expression must be interpreted as a
1262 \context PianoStaff < \context Staff @dots{} >
1265 Here is a full-fledged example:
1267 @lilypond[relative 0,fragment]
1269 < \context Staff = up {
1271 \context Staff = down {
1272 \clef bass c,, c' e c }
1276 More information on formatting piano music is in @ref{Piano music}.
1278 @node Setting variables
1279 @section Setting variables
1281 When the music is converted from notes to print, it is interpreted
1282 from left-to-right order, similar to what happens when we read
1283 music. During this step, context-sensitive information, such as the
1284 accidentals to print, and where barlines must be placed, are stored in
1285 variables. These variables are called @emph{translation properties}.
1286 The properties can also be manipulated from input files: for example,
1288 \property Staff.autoBeaming = ##f
1290 sets the property named @code{autoBeaming} in the current staff to
1291 @code{##f} which means `false'. This property controls whether beams
1292 are printed automatically:
1293 @lilypond[relative 1,fragment,verbatim]
1295 \property Staff.autoBeaming = ##f
1300 LilyPond includes a built-in programming language, namely, a dialect
1301 of Scheme. The argument to @code{\property}, @code{##f}, is an
1302 expression in that language. The first hash-mark signals that a piece
1303 of Scheme code follows. The second hash character is part of the
1304 boolean value true (@code{#t}). Values of other types may be
1307 @item a string, enclosed in double quotes, for example
1309 \property Staff.instrument = #"French Horn"
1311 @item a boolean: either @code{#t} or @code{#f}, for true and false
1314 \property Voice.autoBeaming = ##f
1315 \property Score.skipBars = ##t
1320 \property Score.currentBarNumber = #20
1323 @item a symbol, which is introduced by a quote character,
1325 \property Staff.crescendoSpanner = #'dashed-line
1328 @item a pair, which is also introduced by a quote character.
1329 The following statements set properties to the pairs (-7.5, 6) and
1330 (3, 4) respectively.
1333 \property Staff.minimumVerticalExtent = #'(-7.5 . 6)
1334 \property Staff.timeSignatureFraction = #'(3 . 4)
1340 There are many different properties, and not all of them are listed in
1341 this manual. However, the internal documentation lists them all in the
1342 @internalsref{All translation properties}, and almost all properties
1343 are demonstrated in one of the
1345 @uref{../../../input/test/out-www/collated-files.html,tips-and-tricks}
1353 @node Fine tuning layout
1354 @section Fine tuning layout
1356 Sometimes it is necessary to change music layout by hand. When music
1357 is formatted, layout objects are created for each symbol. For
1358 example, every clef and every note head is represented by a layout
1359 object. These layout objects also carry variables, which we call
1360 @emph{layout properties}. By changing these variables from their
1361 values, we can alter the look of a formatted score.
1363 @lilypond[verbatim,relative 0]
1365 \property Voice.Stem \override #'thickness = #3.0
1370 In the example shown here, the layout property @code{thickness} (a
1371 symbol) is set to 3 in the @code{Stem} layout objects of the current
1372 Voice. As a result, the notes following @code{\property} have thicker
1375 In most cases of manual overrides, only a single object must be
1376 changed. This can be achieved by prefix @code{\once} to the
1377 @code{\property} statement, i.e.,
1380 \once \property Voice.Stem \set #'thickness = #3.0
1383 @lilypond[relative 0]
1385 \once \property Voice.Stem \set #'thickness = #3.0
1390 Some overrides are so common that predefined commands are provided as
1391 a short cut. For example, @code{\slurUp} and @code{\stemDown}. These
1392 commands are described in the @ref{Notation manual}, under the
1393 sections for slurs and stems respectively.
1395 The exact tuning possibilities for each type of layout object are
1396 documented in the internal documentation of the respective
1397 object. However, many layout objects share properties, which can be
1398 used to apply generic tweaks. We mention a couple of these:
1401 @cindex @code{extra-offset}
1402 @item The @code{extra-offset} property
1403 moves around objects in the printout. The unit of these offsets are
1404 staff-spaces. The first number controls left-right movement; a
1405 positive number will move the object to the right. The second number
1406 controls up-down movement; a positive number will move it higher. The
1407 @code{extra-offset} is a low-level feature: the formatting engine is
1408 completely oblivious to these offsets.
1410 In the following example example, the second fingering is moved a
1411 little to the left, and 1.8 staff space downwards.
1413 @cindex setting object properties
1415 @lilypond[relative 1,verbatim]
1418 \once \property Voice.Fingering
1419 \set #'extra-offset = #'(-0.3 . -1.8)
1424 Setting the @code{transparent} property will make an object be
1425 printed in `invisible ink': the object is not printed, but all its
1426 other behavior is retained. The object still takes space, takes part
1427 in collisions, and slurs, ties and beams can be attached to it.
1429 @cindex transparent objects
1430 @cindex removing objects
1431 @cindex invisible objects
1432 The following example demonstrates how to connect different voices
1433 using ties. Normally ties only happen between notes of the same
1434 voice. By introducing a tie in a different voice, and blanking a stem
1435 in that voice, the tie appears to cross voices.
1437 @lilypond[fragment,relative 1]
1439 \once \property Voice.Stem \set #'transparent = ##t
1447 The @code{padding} property for objects with
1448 @code{side-position-interface} can be set to increase distance between
1449 symbols that are printed above or below notes. An example of the use
1450 of padding is in @ref{Constructing a tweak}.
1453 More specific overrides are also possible. The notation manual
1454 discusses in depth how to figure out these statements for yourself, in
1455 @ref{Tuning output}.
1457 @node Organizing larger pieces
1458 @section Organizing larger pieces
1460 When all of the elements discussed earlier are combined to produce
1461 larger files, the @code{\score} blocks get a lot bigger, because the
1462 music expressions are longer, and, in the case of polyphonic and/or
1463 orchestral pieces, more deeply nested.
1465 By using variables, also known as identifiers, it is possible to break
1466 up complex music expressions.
1467 An identifier is assigned as follows
1469 namedMusic = \notes @{ @dots{}
1472 The contents of the music expression @code{namedMusic}, can be used
1473 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1476 @lilypond[singleline,verbatim]
1485 The name of an identifier should only have alphabetic characters only,
1486 and no numbers, underscores or dashes. The assignment should be
1487 outside of the @code{\score} block.
1489 It is possible to use variables for many other types of objects in the
1494 aFivePaper = \paper @{ paperheight = 22.7 \cm @}
1496 Depending on its contents, the identifier can be used in different
1497 places. The following example uses the above variables:
1500 \notes @{ c4^\name @}
1508 More information on the possible uses of identifiers is in the
1509 technical manual, in @ref{Scheme datatypes}.
1512 @node An orchestral part
1513 @section An orchestral part
1515 In orchestral music, all notes are printed twice: both in a part for
1516 the musicians, and in a full score for the which is printed both in
1517 parts as in full score. Identifiers can be used to avoid double work:
1518 the music is entered once, and stored in an variables. The contents of
1519 that variable is then used to generate both the part and the score.
1521 It is convenient to define the notes in a special file, for example,
1522 suppose that the following is in @file{horn-music.ly}:
1524 hornNotes = \notes \relative c @{
1530 Then, an individual part is made by putting the following in a file
1532 \include "horn-music.ly"
1534 instrument = "Horn in F"
1537 \notes \transpose c' f \hornNotes
1540 The @code{\include} command substitutes the contents of the file at
1541 this position in the file, so that @code{hornNotes} is defined
1542 afterwards. Since the horn is tuned in F, the @code{\transpose}
1543 command is used. The code @code{\transpose c' f} indicates that the
1544 argument, being @code{\hornNotes} should be transposed by a fifth
1545 downwards: the @code{c'} becomes a @code{f}. The transposition can be
1546 seen in the following output:
1548 @lilypond[singleline]
1550 \notes \transpose c' f \notes \relative c' {
1557 In ensemble pieces, one of the voices often does not play for many
1558 measures. This is denoted by a special rest, the multi-measure
1559 rest. It is entered with a capital R, and followed by a duration (1
1560 for a whole note, 2 for a half note, etc.) By multiplying the
1561 duration, longer rests can be constructed. For example, the next rest
1562 takes 3 measures in 2/4 time.
1567 When printing the part, the following @code{skipBars} property must be
1568 set to false, to prevent the rest from being expanded in three one bar
1571 \property Score.skipBars = ##t
1574 The result would look like
1576 @lilypond[singleline]
1577 \score {\notes { \transpose c' f \relative c' { \time 2/4
1578 \property Score.skipBars = ##t
1580 r4 f8 a cis4 f e d } }}
1583 The score is made by combining all of the music in a @code{\score}
1584 block, assuming that the other voice is in @code{hornNotes}, in the
1585 file @file{horn-music.ly}:
1587 \include "fagot-music.ly"
1588 \include "horn-music.ly"
1592 \context Staff = hornStaff \hornNotes
1593 \context Staff = fagStaff \fagottoNotes
1597 This would lead to the following output:
1599 @lilypond[singleline]
1601 \notes \relative c \simultaneous {
1602 \context Staff = hornStaff { \time 2/4
1604 r4 f8 a cis4 f e d }
1605 \context Staff = fagStaff { \clef bass
1606 r4 d,8 f | gis4 c | b bes |
1607 a8 e f4 | g d | gis f }
1611 More in depth information is in the notation manual, in
1612 @ref{Orchestral music}.
1615 @node Integrating text and music
1616 @section Integrating text and music
1620 @cindex La@TeX{}, music in
1621 @cindex HTML, music in
1622 @cindex Texinfo, music in
1624 Sometimes you might want to use music examples in a text that you are
1625 writing (for example a musicological treatise, a songbook, or (like us)
1626 the LilyPond manual). You can make such texts by hand, simply by
1627 importing a PostScript figure into your word processor. However,
1628 there is an automated procedure to reduce the amount of work.
1630 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1631 code. A script called @code{lilypond-book} will extract the music
1632 fragments, run LilyPond on them, and put back the resulting notation.
1633 This program is fully described in @ref{lilypond-book manual}. Here
1634 we show a small example. Since the example also contains explanatory
1635 text, we will not comment it further.
1638 \documentclass[a4paper]@{article@}
1641 In a lilypond-book document, you can freely mix music and text. For
1644 \score @{ \notes \relative c' @{
1645 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1649 Notice that the music line length matches the margin settings of the
1652 If you have no \verb+\score+ block in the fragment,
1653 \texttt@{lilypond-book@} will supply one:
1659 In the example you see here, two things happened: a
1660 \verb+\score+ block was added, and the line width was set to natural
1661 length. You can specify many more options using \LaTeX style options
1664 \begin[verbatim,11pt,singleline,
1665 fragment,relative,intertext="hi there!"]@{lilypond@}
1669 The option \texttt@{verbatim@} prints the LilyPond code in addition to
1670 the graphical score, \texttt@{11pt@} selects the default music size,
1671 \texttt@{fragment@} adds a score block, \texttt@{relative@} uses
1672 relative mode for the fragment, and \texttt@{intertext@} specifies
1673 what to print between the \texttt@{verbatim@} code and the music.
1675 If you want to include large examples into the text, it may be more
1676 convenient to put the example in a separate file:
1678 \lilypondfile[printfilename]@{screech-boink.ly@}
1680 The \texttt@{printfilename@} option adds the file name to the output.
1685 Under Unix, you can view the results as follows.
1689 $ lilypond-book --outdir=out/ lilbook.tex
1690 lilypond-book (GNU LilyPond) 1.7.23
1691 Reading `input/tutorial/lilbook.tex'
1692 Reading `input/screech-boink6.ly'
1693 @var{lots of stuff deleted}
1694 Writing `out/lilbook.latex'
1696 $ latex lilbook.latex
1697 @var{lots of stuff deleted}
1701 Running lilypond-book and running latex creates a lot of temporary
1702 files, and you would not want those to clutter up your working
1703 directory. The @code{outdir} option to lilypond-book creates the
1704 temporary files in a separate subdirectory @file{out}.
1706 The result looks more or less like this:
1710 In a lilypond-book document, you can freely mix music and text. For
1714 \notes \relative c' {
1715 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1723 Notice that the music line length matches the margin settings of the
1726 If you have no @code{\score} block in the fragment,
1727 @code{lilypond-book} will supply one:
1733 In the example you see here, a number of things happened: a
1734 @code{\score} block was added, and the line width was set to natural
1735 length. You can specify many more options using La@TeX{} style options
1738 @lilypond[verbatim,11pt,singleline,
1739 fragment,relative,intertext="hi there!"]
1743 The option @code{verbatim} also shows the LilyPond code, @code{11pt} selects
1744 the default music size, @code{fragment} adds a score block,
1745 @code{relative} uses relative mode for the fragment, and
1746 @code{intertext} specifies what to print between the
1747 @code{verbatim} code and the music.
1749 If you include large examples into the text, it may be more convenient
1750 to put the example in a separate file:
1752 @lilypondfile[printfilename]{screech-boink.ly}
1754 The @code{printfilename} option adds the file name to the output.