* scripts/lilypond-book.py (option_definitions): typo
[lilypond.git] / Documentation / user / tutorial.itely
blob977264ec609a4bc6b40b333c9e0347ceb97fe3d9
1 @c -*-texinfo-*-
3 @c TODO:
4 @c   * more details about running lilypond; error messages,
5 @c     compiling/viewing (emacs?)
6 @c   * where to go from  First steps+More basics?
8 @node Tutorial
9 @chapter Tutorial
11 @html
12 <!--- @@WEB-TITLE@@=Tutorial --->
13 @end html
15 @menu
16 * First steps::                 Music language of LilyPond.
17 * Running LilyPond::            Printing music.
18 * More about pitches and accidentals::  
19 * Octave entry ::               
20 * Relative octave entry::       
21 * Combining music into compound expressions::  
22 * Adding articulation marks to notes ::  
23 * Combining notes into  chords::  
24 * Printing lyrics::             
25 * A lead sheet::                
26 * Listening to output::         
27 * Titling ::                    
28 * Single staff polyphony  ::    
29 * Piano staffs::                
30 * Setting variables::           
31 * Fine tuning layout::          
32 * Organizing larger pieces::    
33 * An orchestral part::          
34 * Integrating text and music::  Integrating text and music.
35 @end menu
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.
48 @ifhtml
49 For example, consider the following input
50 @c TODO: intertext fixme
51 @lilypond[relative 1,singleline,verbatim,intertext="with the following output"]
52   c'^\markup { \bold \huge { Click on this image! } }
53 @end lilypond
54 If you click it, you can see that the input shown is simplified a
55 little. This has been done for reasons of space and clarity. If you
56 want to fiddle, you need the full input, otherwise LilyPond will not
57 accept it.
58 @end ifhtml
59 By cutting and pasting the full input into a test file, you have a
60 starting template for experiments. If you like learning in this way,
61 you will probably want to print out or bookmark
62 @ifhtml
63 the
64 @end ifhtml
65 @ref{Cheat sheet}, which is a table listing all commands for quick
66 reference.
69 This tutorial starts with a short introduction to the LilyPond music
70 language.  After this first contact, we will show you how to to
71 produce printed output, normally using the program @code{ly2dvi}.  You
72 should then be able to create and print your first sheets of music.
75 @node First steps
76 @section First steps
78 We start off by showing how very simple music is entered in LilyPond:
79 you get a note simply by typing its @htmlref{note name}, from @samp{a}
80 through @samp{g}.  So if you enter
82 @example
83 c d e f g a b
84 @end example
86 @noindent
87 then the result looks like this:
89 @c ?
90 @c \transpose c c' { c d e f g a b }
91 @c @lily pond[notime]
92 @c \property Score.timing = ##f
93 @lilypond[notime, relative=2]
94 c d e f g a b
95 @end lilypond
97 The length of a note is specified by adding a number, @samp{1} for a
98 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
100 @example
101 a1 a2 a4 a16 a32
102 @end example
104 @lilypond[notime]
105 \property Score.timing = ##f
106 \property Staff.autoBeaming = ##f
107 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
108 @end lilypond
110 If you do not specify a @rglos{duration}, the previous one is used: 
112 @example
113 a4 a a2 a
114 @end example
116 @lilypond[notime]
117 \property Score.timing = ##f
118 \transpose c c' { a a a2 a s16_" " }
119 @end lilypond
122 Rests are entered just like notes, but with the name ``@code{r}'':
124 @cindex rests
125 @quotation
126 @example
127 r2 r4 r8 r16
128 @end example
130 @lilypond[fragment]
131 \property Score.timing = ##f
132 \property Staff.Clef = \turnOff
133 \property Staff.TimeSignature = \turnOff
134 r2 r4 r8 r16
135 s16_" "
136 @end lilypond
137 @end quotation
138 @separate
141 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
143 @example
144 a2. a4 a8. a16
145 @end example
147 @lilypond[notime]
148 \property Score.timing = ##f
149 \transpose c c' { a2. a4 a8. a16 s16_" " }
150 @end lilypond
153 The @rglos{meter} (or @rglos{time signature}) can be set with the
154 @code{\time} command:
156 @example
157 \time 3/4
158 \time 6/8
159 \time 4/4
160 @end example
162 @c a clef here may lead to confusion
163 @lilypond
164 \property Staff.Clef \set #'transparent = ##t 
165 \time 3/4
166 s4_" "
167 \time 6/8
168 s4_" "
169 \time 4/4
170 s16_" "
171 @end lilypond
174 The @rglos{clef} can be set using the @code{\clef} command:
176 @c what is more common name treble or violin?
177 @c in Dutch, its violin.
178 @c in English its definitely treble.
179 @example
180 \clef treble
181 \clef bass
182 \clef alto
183 \clef tenor
184 @end example
186 @lilypond[notime]
187 \property Score.timing = ##f
188 \clef violin
189 s4_" "
190 \clef bass
191 s4_" "
192 \clef alto
193 s4_" "
194 \clef tenor
195 s16_" "
196 @end lilypond
198 Notes and commands like @code{\clef} and @code{\time} , are enclosed
199 in @code{\notes @{@dots{}@}}.  This indicates that music (as opposed
200 to @rglos{lyrics}) follows:
202 @example
203 \notes @{
204   \time 3/4
205   \clef bass
206   c2 e4 g2.
207   f4 e d c2 r4
209 @end example
210 Now the piece of music is almost ready to be printed.  The final step is to
211 combine the music with a printing command.
213 The printing command is the so-called @code{\paper} block.  The
214 @code{\paper} block is used to customize printing specifics, but we
215 accept the defaults for now.  The music and the @code{\paper} block
216 are combined by enclosing them in @code{\score @{ ... @}}.  The
217 following is a complete and valid input file.
219 @example
220 \score @{
221   \notes @{
222     \time 3/4
223     \clef bass
224     c2 e4 g2.
225     f4 e d c2 r4
226   @}
227   \paper @{ @}
229 @end example
231 @lilypond[noindent]
232 \score {
233   \notes {
234      \time 3/4
235      \clef bass
236      c2 e4 g2.
237      f4 e d c2 r4
238   }
239   \paper {
240     linewidth = 55 * \staffspace
241   }
243 @end lilypond
245 During the rest of the tutorial, we will often leave out @code{\score}
246 and @code{\paper}, for clarity. However, both must be present when
247 feeding the file to LilyPond.
249 More elaborate information on entering pitches and durations is in
250 @ref{Pitches} and @ref{Durations}.  Clefs are fully explained in
251 @ref{Clef}.  Time signatures and other timing commands are described
252 in @ref{Time signature}.
255 @node Running LilyPond
256 @section Running LilyPond
258 In the last section we explained what kind of things you could enter
259 in a LilyPond file.  In this section we explain what commands to run
260 and how to view or print the output.  If you have not used LilyPond
261 before, want to test your setup, or want to run an example file
262 yourself, read this section.  The instructions that follow are for
263 Unix-like systems.  Some additional instructions for Microsoft Windows
264 are given at the end of this section.
266 Begin by opening a terminal window and starting a text editor.  For
267 example, you could open an xterm and execute
268 @code{joe}.@footnote{There are macro files for VIM addicts, and there
269 is a @code{LilyPond-mode} for Emacs addicts. If it has not been
270 installed already, then refer to the file @file{INSTALL.txt}}.  In
271 your text editor, enter the following input and save the file as
272 @file{test.ly}:
274 @quotation
275 @example
276 \score @{
277   \notes @{ c'4 e' g' @}
278 @} 
279 @end example
280 @end quotation
282 @cindex ly2dvi
284 @c now this is weird, running ly2dvi to run LilyPond
285 @c (therefore name change proposal) 
287 LilyPond is the program that computes the sheet music. All other
288 things, such as adding titles, page breaking and other page layout,
289 are done by a small wrapper program called
290 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
291 then adds the titling and page layout instructions.  To process
292 @file{test.ly} with @code{ly2dvi}, proceed as follows:
294 @quotation
295 @example
296 ly2dvi -p test.ly
297 @end example
298 @end quotation
300 You will see something resembling:
302 @quotation
303 @example
304 GNU LilyPond 1.8.0
305 Now processing: `/home/fred/ly/test.ly'
306 Parsing...
307 Interpreting music...[1]
308  @emph{ ... more interesting stuff ... }
309 PDF output to `test.pdf'...
310 DVI output to `test.dvi'...
311 @end example
312 @end quotation
313 @cindex DVI file
314 @cindex Viewing music
315 @cindex xdvi
317 The result of the ly2dvi is the file @file{test.pdf}.@footnote{ For
318 @TeX{} afficionados, there is also a (@file{test.dvi}) file. It can be
319 viewed with @code{xdvi}. The DVI uses a lot of PostScript specials,
320 which do not show up in the magnifying glass. The specials also mean
321 that the DVI file cannot be processed with @code{dvilj}. Use
322 @code{dvips} for printing.
323 @cindex dvips
324 @cindex dvilj
325 @cindex DVI driver
326 }  One the following commands should put the PDF on your
327 screen.
328 @c eeek
329 @quotation
330 @example
331   gv test.pdf
332   ghostview test.pdf
333   ggv test.pdf
334   kghostview test.pdf
335   xpdf test.pdf
336   gpdf test.pdf
337   acroread test.pdf
338 @end example
339 @end quotation
340 If the music on your screen looks good, you can print it by clicking
341 File/Print inside your viewing program.
343 @cindex Ghostscript
344 @cindex @code{lpr}
345 @cindex Printing output
346 @cindex PostScript
347 @cindex PDF
350 On Windows,  the terminal is started by clicking on the LilyPond or
351 Cygwin icon.  Any text editor (such as NotePad, Emacs or Vim) may be
352 used to edit the LilyPond file.  If you have a PDF viewer installed,
353 use that for viewing the PDF
354 @c where on file system for double-click people?
355 If you have no viewer, then  you can download @code{GSView}  from
356 @uref{http://www.cs.wisc.edu/~ghost}. With @code{GSView},
357 the PDF file can viewed with
358 @quotation
359 @example
360 @code{gsview32 test.pdf}
361 @end example
362 @end quotation
363 Printing may be done with
364 @quotation
365 @example
366 @code{gsview32 /s test.pdf}
367 @end example
368 @end quotation
370 The commands for formatting and printing music are detailed in
371 @ref{Invoking LilyPond}.
373 @node More about pitches and accidentals
374 @section More about pitches and accidentals
376 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
377 @rglos{flat} (@texiflat{}) by adding @samp{es}.  As you might expect,
378 a @rglos{double sharp} or @rglos{double flat} is made by adding
379 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
380 naming conventions in Nordic and Germanic languages, like German and
381 Dutch.}
383 @example
384 cis1 ees fisis aeses
385 @end example
387 @lilypond[notime]
388 \property Score.timing = ##f
389 \transpose c c' { cis1 ees fisis aeses s16_" " }
390 @end lilypond
393 @cindex key signature, setting
395 The key signature is set with the command ``@code{\key}'', followed by
396 a pitch and  @code{\major} or @code{\minor}:
397 @quotation
398 @example
399 \key d \major
401 \key c \minor
403 @end example
405 @lilypond[fragment]
406 \property Staff.TimeSignature = \turnOff
407 \key d \major
409 \key c \minor
411 @end lilypond
412 @end quotation
415 @cindex tie
416 A tie is created by adding a tilde ``@code{~}'' to the first note
417 being tied.
418 @quotation
419 @lilypond[fragment,verbatim,relative 2]
420 g4-~ g a2-~ a4
421 @end lilypond
422 @end quotation
423 @separate
425 This example shows the key signature, accidentals and ties in action.
427 @quotation
428 @example
429 \score @{
430   \notes @{
431     \time 4/4
432     \key g \minor
433     \clef violin
434     r4 r8 a8 gis4 b
435     g8 d4.-~ d' e'8
436     fis4 fis8 fis8 eis4  a8 gis-~
437     gis2 r2
438   @}
439   \paper @{ @}
441 @end example
443 @lilypond
444 \score {
445   \notes { \transpose c c' { 
446     \time 4/4
447     \key g \minor
448     \clef violin
449     r4 r8 a8 gis4 b
450     g8 d4.-~ d e8
451     fis4 fis8 fis8 eis4  a8 gis-~
452     gis2 r2
453   }}
454   \paper { linewidth = #(* 50 staffspace) }
456 @end lilypond
457 @end quotation
458 @cindex accidentals
460 There are some interesting points to note in this example.  Bar lines
461 and beams are drawn automatically.  Line breaks are calculated
462 automatically; it does not matter where the lines breaks are in the
463 source file. Finally, the order of time, key and clef changes is not
464 relevant: in the printout, these are ordered according to standard
465 notation conventions.
467 Accidentals (sharps and flats) do not have to be marked explicitly:
468 you just enter the pitch of the note, and an accidental is printed
469 only when necessary. The flip side of this mechanism, is that you have
470 to mark notes as sharp or flat, even when they do not get accidentals.
471 For example, in this example,
472 @lilypond[fragment]
473 \clef bass
474 \property Staff.TimeSignature = #'()
475 \key cis \major
476 cis dis eis fis gis ais bis 
477 @end lilypond
478 no note gets an explicit accidental, but still you enter
479 @example
480 \clef bass
481 \key cis \major
482 cis dis eis fis gis ais bis 
483 @end example
485 Adding all alterations explicitly might require some more effort when
486 typing, but the advantage is that transposing is easier. It also makes
487 it possible to use different conventions for when to print
488 accidentals.
490 @node  Octave entry 
491 @section Octave entry
494 @c Tim wants to move this quotes example just before the: quotes-do not-work
495 @c score, but we'd need to remove quotes from the other two (key and
496 @c tie) examples...
498 @c better to have this just before the `octaves are bad' snipped
499 @c but we'd need to remove the ', from \key and tie 
500 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
501 the note name, to lower a note one octave, add a ``low quote'' @code{,}
502 (a comma).  Middle C is @code{c'}:
504 @quotation
505 @example
506 c'4 c'' c''' \clef bass c c,
507 @end example
509 @lilypond[fragment]
510 \property Score.timing = ##f
511 \property Staff.TimeSignature = \turnOff
512 c'4 c'' c''' \clef bass c c,
513 @end lilypond
514 @end quotation
515 @separate
517 An example of the use of quotes is in the following Mozart fragment.
518 @lilypond[singleline,fragment,verbatim]
519   \key a \major
520   \time 6/8
521   cis''8. d''16 cis''8 e''4 e''8
522   b'8. cis''16 b'8 d''4 d''8 
523 @end lilypond 
525 This example shows that music in a high register needs lots of quotes.
526 This makes the input less readable, and it is a source of errors.  The
527 solution is to use ``relative octave'' mode.  In practice, this is the
528 most convenient way to copy existing music.  To use relative mode, add
529 @code{\relative} before the piece of music.  You must also give a note
530 from which relative starts, in this case @code{c''}.  If you do not
531 use octavation quotes (i.e. do not add ' or , after a note), relative
532 mode chooses the note that is closest to the previous one.
533 For example, @code{c f} goes up while @code{c g} goes down.
535 @quotation
536 @example
537 \relative c'' @{
538   c f c g c
540 @end example
542 @lilypond[fragment]
543 \property Score.timing = ##f
544 \property Staff.TimeSignature = \turnOff
545 \relative c'' {
546   c f c g c
548 @end lilypond
549 @end quotation
550 @separate
553 Since most music has small intervals, in relative mode pieces can be
554 written almost without using octavation quotes.  In relative mode, the
555 Mozart example is entered as
557 @lilypond[singleline,fragment,verbatim]
558 \relative c'' {
559   \key a \major
560   \time 6/8
561   cis8. d16 cis8 e4 e8
562   b8. cis16 b8 d4 d8
564 @end lilypond 
567 @c needed better, maybe even redundant explanation
568 @c   added another example below.
569 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
570 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
571 Larger intervals are made by adding octavation quotes.  Quotes or
572 commas do not determine the absolute height of a note; the height of a
573 note is relative to the previous one.
574 @c do not use commas or quotes in this sentence
575 For example: @code{c f,} goes down; @code{f, f} are both the same;
576 @code{c' c} are the same; and @code{c g'} goes up:
578 @quotation
579 @example
580 \relative c'' @{
581   c f, f c' c g' c,
583 @end example
585 @lilypond[fragment]
586 \property Score.timing = ##f
587 \property Staff.TimeSignature = \turnOff
588 \relative c'' {
589   c f, f c' c g' c,
591 @end lilypond
592 @end quotation
593 @separate
596 Here is an example of the difference between relative mode and
597 ``normal'' (non-relative) mode:
599 @quotation
600 @example
601 \relative a @{
602 \clef bass
603   a d a e d c' d'
605 @end example
607 @lilypond[fragment]
608 \property Score.timing = ##f
609 \property Staff.TimeSignature = \turnOff
610 \relative a {
611 \clef bass
612   a d a e d c' d'
614 @end lilypond
615 @end quotation
616 @separate
618 @quotation
619 @example
620 \clef bass
621   a d a e d c' d'
622 @end example
624 @lilypond[fragment]
625 \property Score.timing = ##f
626 \property Staff.TimeSignature = \turnOff
627 \clef bass
628   a d a e d c' d'
629 @end lilypond
630 @end quotation
631 @separate
636 @node  Relative octave entry
637 @section Relative octave entry
639 @c lousy example
640 @c ? --hwn
641 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
642 @c chromatic thing pasted in front.  (admittedly the original does not
643 @c have a phrasing slur. The problem is that we do not want the slur
644 @c and the Phrasing slur to collide. We are trying to make a good
645 @c impression here.
647 @quotation
648 @lilypond[fragment,relative 1, verbatim]
649 a8-(-\( ais b  c-) cis2 b'2 a4 cis,  c-\)
650 @end lilypond
651 @end quotation
652 @separate
654 @cindex beams, by hand 
655 Beams are drawn automatically, but if you do not like where they are
656 put, they can be entered by hand. Mark the first note to be beamed
657 with @code{[} and the last one with @code{]}:
658 @quotation
659 @lilypond[fragment,relative 1, verbatim]
660 a8-[ ais-] d-[ es r d-]
661 @end lilypond
662 @end quotation
663 @separate
665 Rests are described in full detail in @ref{Rests}. 
667 The notation manual discusses ties in @ref{Ties}.
672 @node Combining music into compound expressions
673 @section Combining music into compound expressions
675 To print more than one staff, each piece of music that makes up a
676 staff is marked by adding @code{\context Staff} before it.  These
677 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and
678 @code{@}}, as is demonstrated here:
680 @quotation
681 @lilypond[fragment,verbatim]
682 \simultaneous {
683   \context Staff = staffA { \clef violin c'' }
684   \context Staff = staffB { \clef bass c }
686 @end lilypond
687 @end quotation
690 In this example, @code{\simultaneous } indicates that both music
691 fragments happen at the same time, and must be printed stacked
692 vertically.  The notation @code{< .. >} can also be used as a
693 shorthand for @code{\simultaneous @{ .. @}}.
695 @code{\context} introduces a ``notation context''.  To understand this
696 concept, imagine that you are performing a piece of music. When you
697 perform the music, you combine the symbols printed at a certain point
698 with contextual information. For example, without knowing the current
699 clef, and the accidentals in the last measure, it would be impossible
700 to determine the pitch of a note. In other words, this information
701 forms context that helps you decipher a score. LilyPond produces
702 notation from music, so in effect, it does the inverse of reading
703 scores. Therefore, it also needs to keep track of contextual
704 information. This information is maintained in ``notation contexts.''
705 There are several types of contexts, e.g. @code{Staff}, @code{Voice}
706 and @code{Score}, but also @code{Lyrics} and
707 @code{ChordNames}. Prepending @code{\context} to a chunk of music
708 indicates what kind of context to use for interpreting it.
710 By specifying different names (in this case @code{staffA} and
711 @code{staffB}), two different contexts are created, leading to two
712 staves. It does not matter which names they are given, as long as they
713 are different. If they get the same name, the chunks of music are
714 assumed to belong on the same staff, and will be printed like that.
716 @separate
718 We can now typeset a melody with two staves:
720 @quotation
721 @lilypond[verbatim,singleline]
722 \score {
723   \notes 
724   < \context Staff = staffA {
725       \time 3/4
726       \clef violin
727       \relative c'' {
728         e2-( d4 c2 b4 a8-[ a-]
729         b-[ b-] g-[ g-] a2.-) }  
730     }
731     \context Staff = staffB {
732        \clef bass
733        c2 e4  g2.
734        f4 e d c2.
735     }
736   >
737   \paper {} 
739 @end lilypond
740 @end quotation
742 The example shows how small chunks of music, for example the notes
743 @code{c2}, @code{e4}, etc. of the second staff, are combined to form a
744 larger chunk by enclosing it in braces. Again, a larger chunk is
745 formed by prefix @code{\context Staff} to it, and that chunk is
746 combined with @code{< >}. This mechanism is similar with mathematical
747 formulas: in a formula, a so-called expression is formed by combining
748 simpler expressions into larger expressions. For example, 
750 @quotation
751   1
753   1 + 2
754   
755   (1 + 2) * 3
756   
757   ((1 + 2) * 3) / (4 * 5)
758 @end quotation
759 @cindex expression
760 @cindex music expression
761 is a sequence of expressions, where each expression is contained in
762 the next one.  The simplest expressions are numbers and operators
763 (like +, * and /). Parentheses are used to group expressions.  In
764 LilyPond input, a similar mechanism is used. Here, the simplest
765 expressions are notes and rests.  By enclosing expressions in @code{<
766 >} and @code{@{ @}}, more complex music is formed. The @code{\context}
767 also forms new expressions; prepending it to a music expression yields
768 a new expression.
770 Like mathematical expressions, music expressions can be nested
771 arbitrarily deep, e.g.
772 @lilypond[verbatim,relative 1] 
773   { c <c e>
774       < { e f } { c <b d> }
775       >
776   }
777 @end lilypond 
780 @cindex indent
781 When spreading expressions over multiple lines, it is customary to use
782 an indent that indicates the nesting level. Formatting music like this
783 eases reading, and helps you  insert the right amount of closing
784 braces at the end of an expression. For example
785 @example
786 \score @{
787   \notes <
788     @{
789       @dots{}
790     @}
791     @{
792       @dots{}
793     @}
794   >
796 @end example
801 @node Adding articulation marks to notes 
802 @section Adding articulation marks to notes
804 @cindex articulation
805 @cindex accents
806 @cindex staccato
808 Common accents can be added to a note using a dash (`@code{-}') and a
809 single character:
810 @quotation
811 @lilypond[verbatim,relative 1]
812 c-. c-- c-> c-^ c-+ c-_
813 @end lilypond
814 @end quotation
815 @separate
817 @cindex fingering
818 Similarly, fingering indications can be added to a note using a dash
819 (`@code{-}') and the digit to be printed.
821 @lilypond[verbatim,relative 1]
822   c-3 e-5 b-2 a-1
823 @end lilypond
826 Dynamic signs are made by adding the markings to the note:
827 @quotation
828 @lilypond[verbatim,relative 1]
829 c-\ff c-\mf
830 @end lilypond
831 @end quotation
832 @separate
834 @cindex dynamics
835 @cindex decrescendo
836 @cindex crescendo
838 Crescendi and decrescendi are started with the commands @code{\<} and
839 @code{\>}. The command @code{\!} finishes a crescendo on the note it
840 is attached to.
841 @quotation
842 @lilypond[verbatim,relative 1]
843 c2-\<  c2-\!-\ff  c2-\>  c2-\!
844 @end lilypond
845 @end quotation
846 @separate
850 @cindex slur
852 A slur is drawn across many notes, and indicates bound articulation
853 (legato).  The starting note and ending note are marked with a
854 ``@code{(}'' and a ``@code{)}'' respectively:
856 @quotation
857 @lilypond[fragment,relative 1, verbatim]
858 d4-( c16-)-( cis d e c cis d e-)-( d4-)
859 @end lilypond
860 @end quotation
861 @separate
862 @cindex slurs versus ties
863 A slur is different from a tie. A tie simply makes the first note
864 sound longer, and can only be used on pairs of notes with the same
865 pitch. Slurs indicate the articulations of notes, and can be used on
866 larger groups of notes. Slurs and ties are also nested in practice:
867 @lilypond[fragment, relative=1]
868 c2-~-( c8 fis fis4 ~ fis2 g2-)
869 @end lilypond
871 @cindex phrasing slurs
872 If you need two slurs at the same time (one for articulation, one for
873 phrasing), you can also make a phrasing slur with @code{\(} and
874 @code{\)}.
876 More information on fingering, articulation, slurs, phrasing slurs,
877 and dynamics can be found in @ref{Fingering instructions},
878 @ref{Articulations}, @ref{Slurs}, @ref{Phrasing slurs} @ref{Dynamics}
879 respectively.
881 @node Combining notes into chords
882 @section Combining notes into chords
884 @cindex chords
885 Chords can be made by
886 surrounding pitches with @code{<<} and @code{>}>:
887 @quotation
888 @lilypond[relative 0, fragment,verbatim]
889 r4 <<c e g>>4 <<c f a>>8
890 @end lilypond
891 @end quotation
892 @separate
895 You can combine beams and ties with chords.  Beam and tie markings
896 must be placed outside the chord markers:
897 @quotation
898 @lilypond[relative 0, fragment,verbatim]
899 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
900 @end lilypond
901 @end quotation
903 @quotation
904 @example
905 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>>  <<c f a>>8-\!-)
906 @end example
907 @lilypond[relative 0, fragment]
908 \slurUp
909 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>>  <<c f a>>8-\!-)
910 @end lilypond
911 @end quotation
912 @separate
916 @menu
917 * Basic rhythmical commands::   
918 * Commenting input files::      
919 @end menu
921 @node Basic rhythmical commands
922 @subsection  Basic rhythmical commands
924 @cindex pickup
925 @cindex anacruse
926 @cindex upstep
927 @cindex partial measure
928 A pickup (or upstep) is entered with the keyword @code{\partial}. It
929 is followed by a duration: @code{\partial 4} is a quarter note upstep
930 and @code{\partial 8} an eighth note.
931 @lilypond[relative 1,verbatim,fragment]
932   \partial 8
933   f8 c2 d e
934 @end lilypond
936 @cindex tuplets
937 @cindex triplets
938 Tuplets are made with the @code{\times} keyword.  It takes two
939 arguments: a fraction and a piece of music.  The duration of the piece
940 of music is multiplied by the fraction.  Triplets make notes occupy
941 2/3 of their notated duration, so  a triplet has  2/3 as its fraction.
943 @lilypond[relative 0,verbatim,fragment]
944   \times 2/3 { f8 g a }
945   \times 2/3 { c r c }
946 @end lilypond 
948 @cindex grace notes
949 @cindex accacciatura
950 Grace notes are also made by prefixing a note, or a set of notes with
951 a keyword. In this case, the keyword is @code{\grace}. 
952 @lilypond[relative 1, verbatim,fragment]
953   c4 \grace b16-( c4-)
954   \grace { d16-( e } d4-)
955 @end lilypond
957 @noindent
958 More information on grace notes, tuplets and upsteps are in @ref{Grace
959 notes}, @ref{Tuplets} and @ref{Partial measures}.
963 @node Commenting input files
964 @subsection Commenting input files
966 @cindex comments
967 @cindex line comment
968 @cindex block comment
969 Comments are pieces of the input that are ignored.  There are two
970 types of comments. A line comments is introduced by @code{%}: after
971 that, the rest of that line is ignored.  Block comments span larger
972 sections of input.  Anything that is enclosed in @code{%@{} and
973 @code{%@}} is ignored too. The following fragment shows possible uses
974 for comments.
976 @example
977   % notes for twinkle twinkle follow:
978   c4 c   g' g  a a
979   
980   %@{
981   
982     This line, and the notes below
983     are ignored, since they are in a
984     block comment.
986     g g f f e e d d c2 
987   %@}
988 @end example
993 @node Printing lyrics
994 @section Printing lyrics
995 @cindex lyrics
997 @cindex Lyrics
998 @cindex Songs
999 Lyrics are entered by separating each syllable with a space, and
1000 surrounding them with @code{\lyrics @{ @dots{} @}}, for example
1001 @example
1002   \lyrics @{ I want to break free @}
1003 @end example
1005 Like notes, lyrics are also a form of music, but they must not be
1006 printed on a staff, which is the default way to print music. To print
1007 them as lyrics, they must be marked with @code{ \context Lyrics}:
1008 @example
1009   \context Lyrics  \lyrics @{ I want to break free @}
1010 @end example
1011 The melody for this song is as follows
1013 @lilypond[fragment,relative=1]
1014    \partial 8
1015      c8
1016    \times 2/3 {  f4 g g } \times 2/3 { g4-( a2-) }
1017 @end lilypond
1019 The lyrics can be set to these notes, combining both with the
1020 @code{\addlyrics} keyword:
1021 @example
1022  \addlyrics
1023     \notes @{ @dots{} @}
1024     \context Lyrics @dots{}
1025 @end example
1027 The final result is 
1028 @lilypond[verbatim,linewidth=6.0cm]
1029 \score  {
1030  \notes {
1031   \addlyrics
1032    \relative c' {
1033      \partial 8
1034      c8
1035      \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
1036    }
1037    \context Lyrics  \lyrics { I want to break free }
1039  \paper{ }
1041 @end lilypond
1043 @cindex melisma
1044 @cindex extender line
1045 @c synonyms?
1046 This melody ends on a @rglos{melisma}, a single syllable (``free'')
1047 sung to more than one note. This is indicated with a @emph{extender
1048 line}. It is entered as two  underscores, i.e.,
1049 @example
1050   \lyrics @{ I want to break free __ @}
1051 @end example 
1052 @lilypond[]
1053 \score  {
1054  \notes {
1055   \addlyrics
1056    \relative c' {
1057    \partial 8
1058      c8
1059      \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
1061      %% ugh, this is to deal with bugs in the extender implementation
1062      \hideNotes
1063      c32
1064    }
1065    \context Lyrics  \lyrics { I want to break free __ }
1067  \paper{ linewidth = 9.0 \cm }
1069 @end lilypond
1071 Similarly, hyphens between words can be entered as two dashes,
1072 resulting in a centered hyphen between two syllables.
1073 @example
1074   Twin -- kle twin -- kle
1075 @end example
1076 @lilypond[singleline]
1077 \score {
1078   \addlyrics \notes \relative f' { \time 2/4
1079     f4 f c' c' }
1080     \context Lyrics \lyrics { Twin -- kle twin -- kle
1082 \paper { linewidth = 6.0 \cm }
1085 @end lilypond
1087 More options, like putting multiple lines of lyrics below a melody are
1088 discussed in @ref{Vocal music}.
1092 @node A lead sheet
1093 @section A lead sheet
1095 @cindex Lead sheets
1096 @cindex chords
1097 @cindex chord names
1099 In popular music, it is common to denote accompaniment as chord-names.
1100 Using them in LilyPond has two parts, just like lyrics: entering the
1101 chords (with @code{\chords}), and printing them (with @code{\context
1102 ChordNames}).
1104 Chord names are entered by starting chords mode (with @code{\chords}).
1105 In chords mode, you can enter chords with a letter (indicating the
1106 root of the chord), and a durations following that.
1108 @lilypond[verbatim]
1109   \chords { c2 f4. g8 } 
1110 @end lilypond
1112 @noindent
1113 The result of @code{\chords} is a list of chords, and is  equivalent
1114 to entering chords with @code{<<@dots{}>>}.
1116 Other chords can be created by adding modifiers, after a colon.  The
1117 following example shows a few common modifiers
1119 @lilypond[verbatim]
1120   \chords { c2 f4:m g4:maj7 gis1:dim7 }
1121 @end lilypond
1123 Printing chords is done by adding @code{\context ChordNames}
1124 before the chords thus entered:
1126 @lilypond[verbatim]
1127  \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1128 @end lilypond
1130 @cindex lead sheet 
1131 When put together,  chord names, lyrics and a melody form
1132 a lead sheet, for example,
1134 @example
1135 \score @{
1136   <
1137     \context ChordNames \chords @{ @emph{chords} @}
1138     \addlyrics
1139       \notes @emph{the melody}
1140       \context Lyrics \lyrics @{ @emph{the text} @}
1141   >
1142   \paper @{ @}
1144 @end example
1145 @lilypond[]
1146 \score  {
1147   < 
1148    \context ChordNames \chords { r8 c2:sus4 f } 
1149    \addlyrics
1150     \notes \relative c' {
1151      \partial 8
1152      c8
1153      \times 2/3 { f g g } \times 2/3 { g4-( a2-) } }
1154    \context Lyrics  \lyrics { I want to break free __ }
1155   >
1156  \paper{ raggedright = ##t }
1158 @end lilypond
1161 A complete list of modifiers, and other options for layout are in the
1162 reference manual section @ref{Chords}.
1164 @node Listening to output
1165 @section Listening to output
1167 @cindex sound
1168 @cindex MIDI
1170 MIDI (Musical Instrument Digital Interface) is a standard for
1171 connecting and recording digital instruments.  A MIDI file is like a
1172 tape recording of a MIDI instrument. The @code{\midi} block makes the
1173 music go to a MIDI file, so you can listen to the music you entered.
1174 It is great for checking the music: octaves that are off, or
1175 accidentals that were mistyped, stand out very much when listening to
1176 the musical transcription.
1178 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
1179 example
1180 @example 
1181 \score @{
1182     @var{..music..}
1183     \midi  @{ \tempo 4=72 @}
1184     \paper  @{ @}
1186 @end example 
1188 Here, the tempo is specified using the @code{\tempo} command.  In this
1189 case the tempo of quarter notes is set to 72 beats per minute. More
1190 information on auditory output is in the @ref{Sound} section in the
1191 notation manual.
1195 @node Titling 
1196 @section Titling
1198 Bibliographic information is entered in a separate block, the
1199 @code{\header} block. The name of the piece, its composer, etc. are
1200 entered as assignment, within @code{\header @{ @dots{} @}}. For
1201 example,
1202 @example 
1203   \header @{
1204     title = "Eight miniatures" 
1205     composer = "Igor Stravinsky"
1206     tagline = "small is beautiful"
1207   @}
1208   
1209   \score @{ @dots{} @}
1210 @end example
1212 @cindex bibliographic information
1213 @cindex titles
1214 @cindex composer
1215 @cindex ly2dvi
1218 When the file is processed by @code{ly2dvi}, the title and composer
1219 specified are printed above the music. The `tagline' is a short line
1220 printed at bottom of the last page, which normally says ``Lily was
1221 here, version @dots{}''. In the example above, it is replaced by the
1222 line ``small is beautiful.'' 
1224 Normally, the @code{\header} is put at the top of the file. However,
1225 for a document that contains multiple pieces (e.g. a etude book, or
1226 part with multiple movements), then the header can be put into the
1227 @code{\score} block as follows In this case, the name of each piece
1228 will be printed before each movement.
1231 @cindex Lily was here
1232 @cindex signature line
1233 @cindex tag line
1235 @example 
1236   \header @{
1237     title = "Eight miniatures" 
1238     composer = "Igor Stravinsky"
1239     tagline = "small is beautiful"
1240   @}
1241   
1242   \score @{ @dots{}
1243     \header @{ piece = "Adagio" @}
1244   @}
1245   \score @{ @dots{}
1246     \header @{ piece = "Menuetto" @}
1247   @}
1248 @end example
1250 More information on titling can be found in @ref{Invoking ly2dvi}.
1253 @node Single staff polyphony  
1254 @section Single staff polyphony
1256 @cindex polyphony
1257 @cindex multiple voices
1258 @cindex voices, more -- on a staff
1260 When different melodic lines are combined on a single staff, these are
1261 printed as polyphonic voices: each voice has its own stems, slurs
1262 and beams, and the top voice has the stems up, while the bottom voice
1263 has stems down.
1265 Entering such parts is done by entering each voice as a sequence (with
1266 @code{@{ .. @}}), and combining those simultaneously, separating the
1267 voices with @code{\\}:
1269 @example
1270   < @{ a4 g2 f4-~ f4 @} \\
1271     @{ r4 g4 f2 f4 @} >
1272 @end example
1273 @lilypond[relative 1]
1274 \context Staff   < { a4 g2 f4-~ f4 } \\
1275     { r4 g4 f2 f4 } >
1276 @end lilypond
1278 For polyphonic music typesetting, spacer rests can also be convenient: these
1279 are rests that do not print.  It is useful for filling up voices that
1280 temporarily do not play:
1281 @example
1282   < @{ a4 g2 f4-~ f4 @} \\
1283     @{ s4 g4 f2 f4 @} >
1284 @end example
1285 @lilypond[relative 1]
1286 \context Staff  < { a4 g2 f4-~ f4 } \\
1287     { s4 g4 f2 f4 } >
1288 @end lilypond
1290 Again, these expressions can be nested arbitrarily.
1292 @lilypond[fragment]
1294  \context Staff = staffA 
1295   \relative c''
1296     < { a4 g2 f4-~ f4 } \\
1297       { s4 g4 f2 f4 } >
1298  \context Staff = staffB 
1299   <  { \clef bass <<c g>>1  } \\
1300      { f4 d e2 }
1301   >
1303 @end lilypond
1306 More features of polyphonic typesetting are in the notation manual
1307 in @ref{Polyphony}.
1309 @node Piano staffs
1310 @section Piano staffs
1312 @cindex staff switch, manual
1313 @cindex cross staff voice, manual
1314 @cindex @code{\translator}
1316 Piano music is always typeset in two staffs connected by a brace.
1317 Printing such a staff is done similar to the polyphonic example in
1318 @ref{Combining music into compound expressions}:
1319 @example
1320  < \context Staff = up @{ @dots{} @}
1321    \context Staff = down @{ @dots{} @}
1323 @end example
1324 but now this entire expression must be interpreted as a
1325 @code{PianoStaff}:
1326 @example
1327  \context PianoStaff < \context Staff @dots{} >
1328 @end example
1330 Here is a full-fledged example:
1332 @lilypond[relative 0,fragment]
1333 \context PianoStaff
1334  < \context Staff = up { \time 2/4
1335      c4 c g' g  }
1336    \context Staff = down {
1337      \clef bass c,, c' e c }
1339 @end lilypond
1341 More information on formatting piano music is in @ref{Piano music}. 
1343 @node Setting variables
1344 @section Setting variables
1346 When the music is converted from notes to print, it is interpreted
1347 from left-to-right order, similar to what happens when we read
1348 music. During this step, context-sensitive information, such as the
1349 accidentals to print, and where barlines must be placed, are stored in
1350 variables. These variables are called @emph{translation properties}.
1351 The properties can also be manipulated from input files. Consider this input:
1352 @example
1353 \property Staff.autoBeaming = ##f
1354 @end example 
1355 It sets the property named @code{autoBeaming} in the current staff to
1356 @code{##f}, which means `false'. This property controls whether beams
1357 are printed automatically:
1358 @lilypond[relative 1,fragment,verbatim]
1359   c8 c c c
1360   \property Staff.autoBeaming = ##f
1361   c8 c c c  
1362 @end lilypond
1364 @noindent
1365 LilyPond includes a built-in programming language, namely, a dialect
1366 of Scheme.  The argument to @code{\property}, @code{##f}, is an
1367 expression in that language.  The first hash-mark signals that a piece
1368 of Scheme code follows. The second hash character is part of the
1369 boolean value true (@code{#t}).  Values of other types may be
1370 entered as follows
1371 @itemize @bullet
1372 @item a string, enclosed in double quotes, for example
1373 @example
1374   \property Staff.instrument = #"French Horn"
1375 @end example
1376 @item a boolean: either @code{#t} or @code{#f}, for true and false
1377 respectively, e.g.
1378 @example
1379   \property Voice.autoBeaming = ##f
1380   \property Score.skipBars = ##t
1381 @end example
1383 @item a number
1384 @example
1385   \property Score.currentBarNumber = #20
1386 @end example
1388 @item a symbol, which is introduced by a quote character,
1389 @example
1390   \property Staff.crescendoSpanner = #'dashed-line
1391 @end example
1393 @item a pair, which is also introduced by a quote character.
1394 The following statements set properties to the pairs (-7.5, 6)  and
1395 (3, 4) respectively.
1397 @example
1398   \property Staff.minimumVerticalExtent  = #'(-7.5 . 6)
1399   \property Staff.timeSignatureFraction  = #'(3 . 4)
1400 @end example
1403 @end itemize
1405 There are many different properties, and not all of them are listed in
1406 this manual. However, the internal documentation lists them all in the
1407 @internalsref{All translation properties}, and most properties
1408 are demonstrated in one of the
1409 @ifhtml
1410 @uref{../../../input/test/out-www/collated-files.html,tips-and-tricks}
1411 @end ifhtml
1412 @ifnothtml
1413 tips-and-tricks
1414 @end ifnothtml
1415 examples.
1418 @node Fine tuning layout
1419 @section Fine tuning layout
1421 Sometimes it is necessary to change music layout by hand.  When music
1422 is formatted, layout objects are created for each symbol.  For
1423 example, every clef and every note head is represented by a layout
1424 object.  These layout objects also carry variables, which we call
1425 @emph{layout properties}. By changing these variables from their
1426 values, we can alter the look of a formatted score.
1428 @lilypond[verbatim,relative 0]
1429   c4
1430   \property Voice.Stem \override #'thickness = #3.0
1431   c4 c4 c4 
1432 @end lilypond
1434 @noindent
1435 In the example shown here, the layout property @code{thickness} (a
1436 symbol) is set to 3 in the @code{Stem} layout objects of the current
1437 Voice.  As a result, the notes following @code{\property} have thicker
1438 stems.
1440 In most cases of manual overrides, only a single object must be
1441 changed. This can be achieved by prefixing @code{\once} to the
1442 @code{\property} statement, i.e.,
1444 @example
1445  \once \property Voice.Stem \set #'thickness = #3.0
1446 @end example
1448 @lilypond[relative 0]
1449   c4
1450   \once \property Voice.Stem \set #'thickness = #3.0
1451   c4 c4 c4 
1452 @end lilypond
1454 @noindent
1455 Some overrides are so common that predefined commands are provided as
1456 a short cut.  For example, @code{\slurUp} and @code{\stemDown}. These
1457 commands are described in
1458 @ifhtml
1460 @end ifhtml
1461 @ref{Notation manual}, under the sections for slurs and stems
1462 respectively.
1464 The exact tuning possibilities for each type of layout object are
1465 documented in the internal documentation of the respective
1466 object. However, many layout objects share properties, which can be
1467 used to apply generic tweaks.  We mention a couple of these:
1469 @itemize @bullet
1470 @cindex @code{extra-offset}
1471 @item The @code{extra-offset} property, which
1472 has a pair of numbers as value, moves around objects in the printout.
1473 The first number controls left-right movement; a positive number will
1474 move the object to the right.  The second number controls up-down
1475 movement; a positive number will move it higher.  The unit of these
1476 offsets are staff-spaces.  The @code{extra-offset} property is a
1477 low-level feature: the formatting engine is completely oblivious to
1478 these offsets.
1480 In the following example example, the second fingering is moved a
1481 little to the left, and 1.8 staff space downwards.
1483 @cindex setting object properties
1485 @lilypond[relative 1,verbatim]
1486 \stemUp
1488 \once \property Voice.Fingering
1489   \set #'extra-offset = #'(-0.3 . -1.8) 
1491 @end lilypond
1493 @item
1494 Setting the @code{transparent} property will make an object be printed
1495 in `invisible ink': the object is not printed, but all its other
1496 behavior is retained. The object still takes space, it takes part in
1497 collisions, and slurs, ties and beams can be attached to it.
1499 @cindex transparent objects
1500 @cindex removing objects
1501 @cindex invisible objects
1502 The following example demonstrates how to connect different voices
1503 using ties. Normally ties only happen between notes of the same
1504 voice. By introducing a tie in a different voice, and blanking a stem
1505 in that voice, the tie appears to cross voices.
1507 @lilypond[fragment,relative 1,verbatim]
1508 \context Staff < {
1509       \once \property Voice.Stem \set #'transparent = ##t
1510       b8~ b8
1511   } \\ {
1512        b-[ g8-]
1513   } >
1514 @end lilypond
1516 @item
1517 The @code{padding} property for objects with
1518 @code{side-position-interface} can be set to increase distance between
1519 symbols that are printed above or below notes. We only give an
1520 example; a more elaborate explanation is in @ref{Constructing a
1521 tweak}.
1523 @lilypond[relative 1]
1524   c2-\fermata
1525   \property Voice.Script \set #'padding = #3
1526   b2-\fermata
1527 @end lilypond
1529 @end itemize
1531 More specific overrides are also possible.  The notation manual
1532 discusses in depth how to figure out these statements for yourself, in
1533 @ref{Tuning output}.
1535 @node Organizing larger pieces
1536 @section Organizing larger pieces
1538 When all of the elements discussed earlier are combined to produce
1539 larger files, the @code{\score} blocks get a lot bigger, because the
1540 music expressions are longer, and, in the case of polyphonic and/or
1541 orchestral pieces, more deeply nested.
1543 By using variables, also known as identifiers, it is possible to break
1544 up complex music expressions.
1545 An identifier is assigned as follows
1546 @example
1547   namedMusic = \notes @{ @dots{}
1548 @end example
1550 The contents of the music expression @code{namedMusic}, can be used
1551 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1552 In the next example, a two note motive is repeated thrice by using
1553 variable substitution:
1555 @lilypond[singleline,verbatim]
1556 seufzer  = \notes {
1557   dis'8 e'8
1559 \score { \notes {
1560   \seufzer \seufzer \seufzer
1561 } }
1562 @end lilypond
1564 The name of an identifier should only have alphabetic characters only,
1565 and no numbers, underscores or dashes. The assignment should be
1566 outside of the @code{\score} block.
1568 It is possible to use variables for many other types of objects in the
1569 input.  For example,
1570 @example
1571   width = 4.5\cm
1572   name = "Wendy"
1573   aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1574 @end example
1575 Depending on its contents, the identifier can be used in different
1576 places. The following example uses the above variables:
1577 @example
1578   \score @{
1579     \notes @{ c4^\name @}
1580     \paper @{
1581       \aFivePaper
1582       linewidth = \width
1583     @}
1584   @}
1585 @end example
1587 More information on the possible uses of identifiers is in the
1588 technical manual, in @ref{Scheme datatypes}.
1591 @node An orchestral part
1592 @section An orchestral part
1594 In orchestral music, all notes are printed twice: both in a part for
1595 the musicians, and in a full score for the conductor. Identifiers can
1596 be used to avoid double work: the music is entered once, and stored in
1597 variable. The contents of that variable is then used to generate
1598 both the part and the score.
1600 It is convenient  to define the notes in a  special file, for example,
1601 suppose that the @file{horn-music.ly} contains the following part of a
1602 horn/bassoon duo.
1603 @example
1604 hornNotes = \notes \relative c @{
1605   \time 2/4
1606   r4 f8 a cis4 f e d
1608 @end example
1610 Then, an individual part is made by putting the following in a file
1611 @example
1612 \include "horn-music.ly"
1613 \header @{
1614   instrument = "Horn in F"
1616 \score @{
1617   \notes \transpose c' f \hornNotes
1619 @end example
1620 The @code{\include} command substitutes the contents of the file at
1621 this position in the file, so that @code{hornNotes} is defined
1622 afterwards.  Since the horn is tuned in F, the @code{\transpose}
1623 command is used. The code @code{\transpose c' f} indicates that the
1624 argument, being @code{\hornNotes}, should be transposed by a fifth
1625 downwards: the @code{c'} becomes a @code{f}. The transposition can be
1626 seen in the following output:
1628 @lilypond[singleline]
1629 \score {
1630   \notes \transpose c' f  \notes \relative c' {
1631   \time 2/4
1632   r4 f8 a cis4 f e d
1635 @end lilypond
1637 In ensemble pieces, one of the voices often does not play for many
1638 measures. This is denoted by a special rest, the multi-measure
1639 rest. It is entered with a capital R, and followed by a duration (1
1640 for a whole note, 2 for a half note, etc.) By multiplying the
1641 duration, longer rests can be constructed. For example, the next rest
1642 takes 3 measures in 2/4 time.
1643 @example
1644   R2*3
1645 @end example
1647 When printing the part, the following @code{skipBars} property must be
1648 set to false, to prevent the rest from being expanded in three one bar
1649 rests.
1650 @example
1651   \property Score.skipBars = ##t
1652 @end example
1653 Prepending the rest and the property setting above, leads to the
1654 following result.
1656 @lilypond[singleline]
1657 \score {\notes { \transpose c' f \relative c' { \time 2/4
1658 \property Score.skipBars = ##t 
1659         R2*3
1660     r4 f8 a cis4 f e d } }}
1661 @end lilypond
1663 The score is made by combining all of the music in a @code{\score}
1664 block, assuming that the other voice is in @code{bassoonNotes}, in the
1665 file @file{bassoon-music.ly}:
1666 @example
1667 \include "bassoon-music.ly"
1668 \include "horn-music.ly"
1670 \score @{
1671   \simultaneous @{
1672     \context Staff = hornStaff \hornNotes
1673     \context Staff = bsnStaff \bassoonNotes
1674   @} @}
1675 @end example
1677 This would lead to the simple score depicted below.
1679 @lilypond[singleline]
1680 \score {
1681   \notes \relative c \simultaneous {
1682     \context Staff = hornStaff { \time 2/4
1683         R2*3
1684     r4 f8 a cis4 f e d }
1685     \context Staff = fagStaff { \clef bass
1686       r4 d,8 f | gis4 c |  b bes |
1687       a8 e f4 |  g d | gis f }
1688   } }
1689 @end lilypond 
1691 More in-depth information on preparing parts and scores is in the
1692 notation manual, in @ref{Orchestral music}.
1695 @node Integrating text and music
1696 @section Integrating text and music
1698 @cindex La@TeX{}, music in
1699 @cindex HTML, music in
1700 @cindex Texinfo, music in
1702 Sometimes you might want to use music examples in a text that you are
1703 writing (for example a musicological treatise, a songbook, or (like us)
1704 the LilyPond manual).  You can make such texts by hand, simply by
1705 importing a PostScript figure into your word processor.  However,
1706 there is an automated procedure to reduce the amount of work.
1708 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1709 code.  A script called @code{lilypond-book} will extract the music
1710 fragments, run LilyPond on them, and put back the resulting notation.
1711 This program is fully described in @ref{lilypond-book manual}.  Here
1712 we show a small example.  Since the example also contains explanatory
1713 text, we will not comment it further.
1715 @example
1716 \documentclass[a4paper]@{article@}
1717 \begin@{document@}
1719 In a lilypond-book document, you can freely mix music and text. For
1720 example:
1721 \begin@{lilypond@}
1722   \score @{ \notes \relative c' @{
1723      c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1724   @} @}
1725 \end@{lilypond@}
1727 Notice that the music line length matches the margin settings of the
1728 document.
1730 If you have no \verb+\score+ block in the fragment,
1731 \texttt@{lilypond-book@} will supply one:
1733 \begin@{lilypond@}
1734   c'4
1735 \end@{lilypond@}
1737 In the example you see here, two things happened: a
1738 \verb+\score+ block was added, and the line width was set to natural
1739 length. You can specify  options by putting them in brackets:
1741 \begin[26pt,verbatim]@{lilypond@}
1742   c'4 f16
1743 \end@{lilypond@}
1745 If you want to include large examples into the text, it is more
1746 convenient to put it in a separate file:
1748 \lilypondfile@{screech-boink.ly@}
1750 \end@{document@}
1751 @end example
1753 Under Unix, you can view the results as follows.
1754 @example
1755 $ cd input/tutorial
1756 $ mkdir -p out/
1757 $ lilypond-book --outdir=out/ lilbook.tex
1758 lilypond-book (GNU LilyPond) 1.7.23
1759 Reading `input/tutorial/lilbook.tex'
1760 Reading `input/screech-boink6.ly'
1761 @var{lots of stuff deleted}
1762 Writing `out/lilbook.latex'
1763 $ cd out
1764 $ latex lilbook.latex
1765 @var{lots of stuff deleted}
1766 $ xdvi lilbook 
1767 @end example
1769 Running lilypond-book and running latex creates a lot of temporary
1770 files, and you would not want those to clutter up your working
1771 directory.  The @code{outdir} option to lilypond-book creates the
1772 temporary files in a separate subdirectory @file{out}.
1774 The result looks more or less like this: 
1776 @separate
1778 In a lilypond-book document, you can freely mix music and text. For
1779 example:
1780 @lilypond
1781 \score {
1782   \notes \relative c' {
1783     c2 g'2 \times 2/3 { f8 e d } c'2 g4
1784   }
1785   \paper {
1786     raggedright = ##t
1787   }
1789 @end lilypond
1791 Notice that the music line length matches the margin settings of the
1792 document.
1794 If you have no @code{\score} block in the fragment,
1795 @code{lilypond-book} will supply one:
1797 @lilypond
1798   c'4
1799 @end lilypond
1801 In the example you see here, two things happened: a
1802 @code{score} block was added, and the line width was set to natural
1803 length. You can specify  options by putting them in brackets:
1805 @lilypond[26pt,verbatim]
1806   c'4 f16
1807 @end lilypond
1809 If you want to include large examples into the text, it is more
1810 convenient to put it in a separate file:
1812 @lilypondfile{screech-boink.ly}