(Text markup): add note about
[lilypond.git] / Documentation / user / tutorial.itely
blob0070b0031969cda4e0f474cd47167314d3684c2d
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
16 Using LilyPond comes down to encoding music in an input file. After
17 entering the music, the program is run on the file producing output
18 which can be viewed or printed.  In this tutorial, we will show step
19 by step how to enter such files, by showing fragments of input and the
20 corresponding output.  At the end of every section, a paragraph will
21 list where to find further information on the topics discussed.
23 Many people learn programs by trying and fiddling around with the
24 program.  This is also possible with LilyPond. If you click on a
25 picture in the HTML version of this manual, you will see the exact
26 LilyPond input that was used to generate that image.
27 @ifhtml
28 For example, consider the following input:
29 @c TODO: intertext fixme
30 @lilypond[relative 1,singleline,verbatim,intertext="with the following output:"]
31   c'^\markup { \bold \huge { Click on this image! } }
32 @end lilypond
34 @end ifhtml
35 By cutting and pasting the full input into a test file, you have a
36 starting template for experiments. If you like learning in this way,
37 you will probably want to print out or bookmark
38 @ifhtml
39 the
40 @end ifhtml
41 @ref{Cheat sheet}, which is a table listing all commands for quick
42 reference.
45 This tutorial starts with a short introduction to the LilyPond music
46 language.  After this first contact, we will show you how to to
47 produce printed output, normally using the program @code{ly2dvi}.  You
48 should then be able to create and print your first sheets of music.
50 @menu
51 * First steps::                 Music language of LilyPond.
52 * Running LilyPond::            Printing music.
53 * More about pitches and accidentals::  
54 * Octave entry::                
55 * Relative octave entry::       
56 * Combining music into compound expressions::  
57 * Adding articulation marks to notes::  
58 * Combining notes into chords::  
59 * Printing lyrics::             
60 * A lead sheet::                
61 * Listening to output::         
62 * Titling::                     
63 * Single staff polyphony::      
64 * Piano staffs::                
65 * Setting variables::           
66 * Fine tuning layout::          
67 * Organizing larger pieces::    
68 * An orchestral part::          
69 * Integrating text and music::  Integrating text and music.
70 @end menu
73 @node First steps
74 @section First steps
76 We start off by showing how very simple music is entered in LilyPond:
77 you get a note simply by typing its note name, from @samp{a}
78 through @samp{g}.  So if you enter
80 @example
81 c d e f g a b
82 @end example
84 @noindent
85 then the result looks like this:
87 @c ?
88 @c \transpose c c' { c d e f g a b }
89 @c @lily pond[notime]
90 @c \property Score.timing = ##f
91 @lilypond[notime, relative=2]
92 c d e f g a b
93 @end lilypond
95 The length of a note is specified by adding a number, @samp{1} for a
96 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
98 @example
99 a1 a2 a4 a16 a32
100 @end example
102 @lilypond[notime]
103 \property Score.timing = ##f
104 \property Staff.autoBeaming = ##f
105 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
106 @end lilypond
108 If you do not specify a @rglos{duration}, the previous one is used: 
110 @example
111 a4 a a2 a
112 @end example
114 @lilypond[notime]
115 \property Score.timing = ##f
116 \transpose c c' { a a a2 a s16_" " }
117 @end lilypond
120 Rests are entered just like notes, but with the name ``@code{r}'':
122 @cindex rests
123 @quotation
124 @example
125 r2 r4 r8 r16
126 @end example
128 @lilypond[fragment]
129 \property Score.timing = ##f
130 \property Staff.Clef = \turnOff
131 \property Staff.TimeSignature = \turnOff
132 r2 r4 r8 r16
133 s16_" "
134 @end lilypond
135 @end quotation
136 @separate
139 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
141 @example
142 a2. a4 a8. a16
143 @end example
145 @lilypond[notime]
146 \property Score.timing = ##f
147 \transpose c c' { a2. a4 a8. a16 s16_" " }
148 @end lilypond
151 The @rglos{meter} (or @rglos{time signature}) can be set with the
152 @code{\time} command:
154 @example
155 \time 3/4
156 \time 6/8
157 \time 4/4
158 @end example
160 @c a clef here may lead to confusion
161 @lilypond
162 \property Staff.Clef \set #'transparent = ##t 
163 \time 3/4
164 s4_" "
165 \time 6/8
166 s4_" "
167 \time 4/4
168 s16_" "
169 @end lilypond
172 The @rglos{clef} can be set using the @code{\clef} command:
174 @c what is more common name treble or violin?
175 @c in Dutch, its violin.
176 @c in English its definitely treble.
177 @example
178 \clef treble
179 \clef bass
180 \clef alto
181 \clef tenor
182 @end example
184 @lilypond[notime]
185 \property Score.timing = ##f
186 \clef violin
187 s4_" "
188 \clef bass
189 s4_" "
190 \clef alto
191 s4_" "
192 \clef tenor
193 s16_" "
194 @end lilypond
196 Notes and commands like @code{\clef} and @code{\time} , are enclosed
197 in @code{\notes @{@dots{}@}}.  This indicates that music (as opposed
198 to @rglos{lyrics}) follows:
200 @example
201 \notes @{
202   \time 3/4
203   \clef bass
204   c2 e4 g2.
205   f4 e d c2 r4
207 @end example
208 Now the piece of music is almost ready to be printed.  The final step is to
209 combine the music with a printing command.
211 The printing command is the so-called @code{\paper} block.  The
212 @code{\paper} block is used to customize printing specifics, but we
213 accept the defaults for now.  The music and the @code{\paper} block
214 are combined by enclosing them in @code{\score @{ ... @}}.  The
215 following is a complete and valid input file.
217 @example
218 \score @{
219   \notes @{
220     \time 3/4
221     \clef bass
222     c2 e4 g2.
223     f4 e d c2 r4
224   @}
225   \paper @{ @}
227 @end example
229 @lilypond[noindent]
230 \score {
231   \notes {
232      \time 3/4
233      \clef bass
234      c2 e4 g2.
235      f4 e d c2 r4
236   }
237   \paper {
238     linewidth = 55 * \staffspace
239   }
241 @end lilypond
243 During the rest of the tutorial, we will often leave out @code{\score}
244 and @code{\paper}, for clarity. However, both must be present when
245 feeding the file to LilyPond.
247 More elaborate information on entering pitches and durations is in
248 @ref{Pitches} and @ref{Durations}.  Clefs are fully explained in
249 @ref{Clef}.  Time signatures and other timing commands are described
250 in @ref{Time signature}.
253 @node Running LilyPond
254 @section Running LilyPond
256 In the last section we explained what kind of things you could enter
257 in a LilyPond file.  In this section we explain what commands to run
258 and how to view or print the output.  If you have not used LilyPond
259 before, want to test your setup, or want to run an example file
260 yourself, read this section.  The instructions that follow are for
261 Unix-like systems.  Some additional instructions for Microsoft Windows
262 are given at the end of this section.
264 Begin by opening a terminal window and starting a text editor.  For
265 example, you could open an xterm and execute
266 @code{joe}.@footnote{There are macro files for VIM addicts, and there
267 is a @code{LilyPond-mode} for Emacs addicts. If it has not been
268 installed already, then refer to the file @file{INSTALL.txt}}.  In
269 your text editor, enter the following input and save the file as
270 @file{test.ly}:
272 @quotation
273 @example
274 \score @{
275   \notes @{ c'4 e' g' @}
276 @} 
277 @end example
278 @end quotation
280 @cindex ly2dvi
282 @c now this is weird, running ly2dvi to run LilyPond
283 @c (therefore name change proposal) 
285 LilyPond is the program that computes the sheet music. All other
286 things, such as adding titles, page breaking and other page layout,
287 are done by a small wrapper program called
288 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
289 then adds the titling and page layout instructions.  To process
290 @file{test.ly} with @code{ly2dvi}, proceed as follows:
292 @quotation
293 @example
294 ly2dvi -p test.ly
295 @end example
296 @end quotation
298 You will see something resembling:
300 @quotation
301 @example
302 GNU LilyPond 1.8.0
303 Now processing: `/home/fred/ly/test.ly'
304 Parsing...
305 Interpreting music...[1]
306  @emph{ ... more interesting stuff ... }
307 PDF output to `test.pdf'...
308 DVI output to `test.dvi'...
309 @end example
310 @end quotation
311 @cindex DVI file
312 @cindex Viewing music
313 @cindex xdvi
315 The result of the ly2dvi is the file @file{test.pdf}.@footnote{For
316 @TeX{} afficionados, there is also a @file{test.dvi} file. It can be
317 viewed with @code{xdvi}. The DVI uses a lot of PostScript specials,
318 which do not show up in the magnifying glass. The specials also mean
319 that the DVI file cannot be processed with @code{dvilj}. Use
320 @code{dvips} for printing.
321 @cindex dvips
322 @cindex dvilj
323 @cindex DVI driver
324 }  One of the following commands should put the PDF on your
325 screen:
326 @quotation
327 @example
328   gv test.pdf
329   ghostview test.pdf
330   ggv test.pdf
331   kghostview test.pdf
332   xpdf test.pdf
333   gpdf test.pdf
334   acroread test.pdf
335   gsview32 test.pdf
336 @end example
337 @end quotation
338 If the music on your screen looks good, you can print it by clicking
339 File/Print inside your viewing program.
341 @cindex Ghostscript
342 @cindex @code{lpr}
343 @cindex Printing output
344 @cindex PostScript
345 @cindex PDF
348 On Windows, the same procedure should work, the terminal is started by
349 clicking on the LilyPond or Cygwin icon.  Any text editor (such as
350 NotePad, Emacs or Vim) may be used to edit the LilyPond file.
352 To view the PDF file, try the following:
353 @itemize
354 @item
355 If your system has a PDF viewer installed, open
356 @file{C:\Cygwin\home\@var{your-name}} in the explorer and double-click
357 @file{test.pdf}.
358 @item
359 If you prefer the keyboard, you can also try the list of commands
360 shown before. If none work, go to
361 @uref{http://www.cs.wisc.edu/~ghost/} to install the proper software.
362 @end itemize
364 The commands for formatting and printing music on all platforms are
365 detailed in @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
375 Dutch.}
377 @example
378 cis1 ees fisis aeses
379 @end example
381 @lilypond[notime]
382 \property Score.timing = ##f
383 \transpose c c' { cis1 ees fisis aeses s16_" " }
384 @end lilypond
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}:
391 @quotation
392 @example
393 \key d \major
395 \key c \minor
397 @end example
399 @lilypond[fragment]
400 \property Staff.TimeSignature = \turnOff
401 \key d \major
403 \key c \minor
405 @end lilypond
406 @end quotation
409 @cindex tie
410 A tie is created by adding a tilde ``@code{~}'' to the first note
411 being tied:
412 @quotation
413 @lilypond[fragment,verbatim,relative 2]
414 g4-~ g a2-~ a4
415 @end lilypond
416 @end quotation
417 @separate
419 This example shows the key signature, accidentals and ties in action:
421 @quotation
422 @example
423 \score @{
424   \notes @{
425     \time 4/4
426     \key g \minor
427     \clef violin
428     r4 r8 a8 gis4 b
429     g8 d4.-~ d' e'8
430     fis4 fis8 fis8 eis4  a8 gis-~
431     gis2 r2
432   @}
433   \paper @{ @}
435 @end example
437 @lilypond
438 \score {
439   \notes { \transpose c c' { 
440     \time 4/4
441     \key g \minor
442     \clef violin
443     r4 r8 a8 gis4 b
444     g8 d4.-~ d e8
445     fis4 fis8 fis8 eis4  a8 gis-~
446     gis2 r2
447   }}
448   \paper { linewidth = #(* 50 staffspace) }
450 @end lilypond
451 @end quotation
452 @cindex accidentals
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 this example:
466 @lilypond[fragment]
467 \clef bass
468 \property Staff.TimeSignature = #'()
469 \key cis \major
470 cis dis eis fis gis ais bis 
471 @end lilypond
472 no note gets an explicit accidental, but still you enter
473 @example
474 \clef bass
475 \key cis \major
476 cis dis eis fis gis ais bis 
477 @end example
479 Adding all alterations explicitly might require some more effort when
480 typing, but the advantage is that transposing is easier. It also makes
481 it possible to use different conventions for when to print
482 accidentals.
484 @node  Octave entry
485 @section Octave entry
488 @c Tim wants to move this quotes example just before the: quotes-do not-work
489 @c score, but we'd need to remove quotes from the other two (key and
490 @c tie) examples...
492 @c better to have this just before the `octaves are bad' snipped
493 @c but we'd need to remove the ', from \key and tie 
494 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
495 the note name, to lower a note one octave, add a ``low quote'' @code{,}
496 (a comma).  Middle C is @code{c'}:
498 @quotation
499 @example
500 c'4 c'' c''' \clef bass c c,
501 @end example
503 @lilypond[fragment]
504 \property Score.timing = ##f
505 \property Staff.TimeSignature = \turnOff
506 c'4 c'' c''' \clef bass c c,
507 @end lilypond
508 @end quotation
509 @separate
511 An example of the use of quotes is in the following Mozart fragment:
512 @lilypond[singleline,fragment,verbatim]
513   \key a \major
514   \time 6/8
515   cis''8. d''16 cis''8 e''4 e''8
516   b'8. cis''16 b'8 d''4 d''8 
517 @end lilypond 
519 This example shows that music in a high register needs lots of quotes.
520 This makes the input less readable, and it is a source of errors.  The
521 solution is to use ``relative octave'' mode.  In practice, this is the
522 most convenient way to copy existing music.  To use relative mode, add
523 @code{\relative} before the piece of music.  You must also give a note
524 from which relative starts, in this case @code{c''}.  If you do not
525 use octavation quotes (i.e. do not add ' or , after a note), relative
526 mode chooses the note that is closest to the previous one.
527 For example, @code{c f} goes up while @code{c g} goes down:
529 @quotation
530 @example
531 \relative c'' @{
532   c f c g c
534 @end example
536 @lilypond[fragment]
537 \property Score.timing = ##f
538 \property Staff.TimeSignature = \turnOff
539 \relative c'' {
540   c f c g c
542 @end lilypond
543 @end quotation
544 @separate
547 Since most music has small intervals, in relative mode pieces can be
548 written almost without using octavation quotes.  In relative mode, the
549 Mozart example is entered as
551 @lilypond[singleline,fragment,verbatim]
552 \relative c'' {
553   \key a \major
554   \time 6/8
555   cis8. d16 cis8 e4 e8
556   b8. cis16 b8 d4 d8
558 @end lilypond 
561 @c needed better, maybe even redundant explanation
562 @c   added another example below.
563 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
564 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
565 Larger intervals are made by adding octavation quotes.  Quotes or
566 commas do not determine the absolute height of a note; the height of a
567 note is relative to the previous one.
568 @c do not use commas or quotes in this sentence
569 For example: @code{c f,} goes down; @code{f, f} are both the same;
570 @code{c' c} are the same; and @code{c g'} goes up:
572 @quotation
573 @example
574 \relative c'' @{
575   c f, f c' c g' c,
577 @end example
579 @lilypond[fragment]
580 \property Score.timing = ##f
581 \property Staff.TimeSignature = \turnOff
582 \relative c'' {
583   c f, f c' c g' c,
585 @end lilypond
586 @end quotation
587 @separate
590 Here is an example of the difference between relative mode and
591 ``normal'' (non-relative) mode:
593 @quotation
594 @example
595 \relative a @{
596 \clef bass
597   a d a e d c' d'
599 @end example
601 @lilypond[fragment]
602 \property Score.timing = ##f
603 \property Staff.TimeSignature = \turnOff
604 \relative a {
605 \clef bass
606   a d a e d c' d'
608 @end lilypond
609 @end quotation
610 @separate
612 @quotation
613 @example
614 \clef bass
615   a d a e d c' d'
616 @end example
618 @lilypond[fragment]
619 \property Score.timing = ##f
620 \property Staff.TimeSignature = \turnOff
621 \clef bass
622   a d a e d c' d'
623 @end lilypond
624 @end quotation
625 @separate
630 @node  Relative octave entry
631 @section Relative octave entry
633 @c lousy example
634 @c ? --hwn
635 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
636 @c chromatic thing pasted in front.  (admittedly the original does not
637 @c have a phrasing slur. The problem is that we do not want the slur
638 @c and the Phrasing slur to collide. We are trying to make a good
639 @c impression here.
641 @quotation
642 @lilypond[fragment,relative 1, verbatim]
643 a8-(-\( ais b  c-) cis2 b'2 a4 cis,  c-\)
644 @end lilypond
645 @end quotation
646 @separate
648 @cindex beams, by hand 
649 Beams are drawn automatically, but if you do not like where they are
650 put, they can be entered by hand. Mark the first note to be beamed
651 with @code{[} and the last one with @code{]}:
652 @quotation
653 @lilypond[fragment,relative 1, verbatim]
654 a8-[ ais-] d-[ es r d-]
655 @end lilypond
656 @end quotation
657 @separate
659 Rests are described in full detail in @ref{Rests}. 
661 The notation manual discusses ties in @ref{Ties}.
666 @node Combining music into compound expressions
667 @section Combining music into compound expressions
669 To print more than one staff, each piece of music that makes up a
670 staff is marked by adding @code{\context Staff} before it.  These
671 @code{Staff}'s are then grouped inside @code{\simultaneous @{} and
672 @code{@}}, as is demonstrated here:
674 @quotation
675 @lilypond[fragment,verbatim]
676 \simultaneous {
677   \context Staff = staffA { \clef violin c'' }
678   \context Staff = staffB { \clef bass c }
680 @end lilypond
681 @end quotation
684 In this example, @code{\simultaneous } indicates that both music
685 fragments happen at the same time, and must be printed stacked
686 vertically.  The notation @code{< .. >} can also be used as a
687 shorthand for @code{\simultaneous @{ .. @}}.
689 @code{\context} introduces a ``notation context''.  To understand this
690 concept, imagine that you are performing a piece of music. When you
691 perform the music, you combine the symbols printed at a certain point
692 with contextual information. For example, without knowing the current
693 clef, and the accidentals in the last measure, it would be impossible
694 to determine the pitch of a note. In other words, this information
695 forms context that helps you decipher a score. LilyPond produces
696 notation from music, so in effect, it does the inverse of reading
697 scores. Therefore, it also needs to keep track of contextual
698 information. This information is maintained in ``notation contexts.''
699 There are several types of contexts, e.g. @code{Staff}, @code{Voice}
700 and @code{Score}, but also @code{Lyrics} and
701 @code{ChordNames}. Prepending @code{\context} to a chunk of music
702 indicates what kind of context to use for interpreting it.
704 By specifying different names (in this case @code{staffA} and
705 @code{staffB}), two different contexts are created, leading to two
706 staves. It does not matter which names they are given, as long as they
707 are different. If they get the same name, the chunks of music are
708 assumed to belong on the same staff, and will be printed like that.
710 @separate
712 We can now typeset a melody with two staves:
714 @quotation
715 @lilypond[verbatim,singleline]
716 \score {
717   \notes 
718   < \context Staff = staffA {
719       \time 3/4
720       \clef violin
721       \relative c'' {
722         e2-( d4 c2 b4 a8-[ a-]
723         b-[ b-] g-[ g-] a2.-) }  
724     }
725     \context Staff = staffB {
726        \clef bass
727        c2 e4  g2.
728        f4 e d c2.
729     }
730   >
731   \paper {} 
733 @end lilypond
734 @end quotation
736 The example shows how small chunks of music, for example, the notes
737 @code{c2}, @code{e4}, etc. of the second staff, are combined to form a
738 larger chunk by enclosing it in braces. Again, a larger chunk is
739 formed by prefix @code{\context Staff} to it, and that chunk is
740 combined with @code{< >}. This mechanism is similar with mathematical
741 formulas: in a formula, a so-called expression is formed by combining
742 simpler expressions into larger expressions. For example, 
744 @quotation
745   1
747   1 + 2
748   
749   (1 + 2) * 3
750   
751   ((1 + 2) * 3) / (4 * 5)
752 @end quotation
753 @cindex expression
754 @cindex music expression
755 is a sequence of expressions, where each expression is contained in
756 the next one.  The simplest expressions are numbers and operators
757 (like +, * and /). Parentheses are used to group expressions.  In
758 LilyPond input, a similar mechanism is used. Here, the simplest
759 expressions are notes and rests.  By enclosing expressions in @code{<
760 >} and @code{@{ @}}, more complex music is formed. The @code{\context}
761 also forms new expressions; prepending it to a music expression yields
762 a new expression.
764 Like mathematical expressions, music expressions can be nested
765 arbitrarily deep, e.g.
766 @lilypond[verbatim,relative 1] 
767   { c <c e>
768       < { e f } { c <b d> }
769       >
770   }
771 @end lilypond 
774 @cindex indent
775 When spreading expressions over multiple lines, it is customary to use
776 an indent that indicates the nesting level. Formatting music like this
777 eases reading, and helps you  insert the right amount of closing
778 braces at the end of an expression. For example,
779 @example
780 \score @{
781   \notes <
782     @{
783       @dots{}
784     @}
785     @{
786       @dots{}
787     @}
788   >
790 @end example
795 @node Adding articulation marks to notes
796 @section Adding articulation marks to notes
798 @cindex articulation
799 @cindex accents
800 @cindex staccato
802 Common accents can be added to a note using a dash (`@code{-}') and a
803 single character:
804 @quotation
805 @lilypond[verbatim,relative 1]
806 c-. c-- c-> c-^ c-+ c-_
807 @end lilypond
808 @end quotation
809 @separate
811 @cindex fingering
812 Similarly, fingering indications can be added to a note using a dash
813 (`@code{-}') and the digit to be printed:
815 @lilypond[verbatim,relative 1]
816   c-3 e-5 b-2 a-1
817 @end lilypond
820 Dynamic signs are made by adding the markings to the note:
821 @quotation
822 @lilypond[verbatim,relative 1]
823 c-\ff c-\mf
824 @end lilypond
825 @end quotation
826 @separate
828 @cindex dynamics
829 @cindex decrescendo
830 @cindex crescendo
832 Crescendi and decrescendi are started with the commands @code{\<} and
833 @code{\>}. The command @code{\!} finishes a crescendo on the note it
834 is attached to:
835 @quotation
836 @lilypond[verbatim,relative 1]
837 c2-\<  c2-\!-\ff  c2-\>  c2-\!
838 @end lilypond
839 @end quotation
840 @separate
844 @cindex slur
846 A slur is drawn across many notes, and indicates bound articulation
847 (legato).  The starting note and ending note are marked with a
848 ``@code{(}'' and a ``@code{)}'' respectively:
850 @quotation
851 @lilypond[fragment,relative 1, verbatim]
852 d4-( c16-)-( cis d e c cis d e-)-( d4-)
853 @end lilypond
854 @end quotation
855 @separate
856 @cindex slurs versus ties
857 A slur is different from a tie. A tie simply makes the first note
858 sound longer, and can only be used on pairs of notes with the same
859 pitch. Slurs indicate the articulations of notes, and can be used on
860 larger groups of notes. Slurs and ties are also nested in practice:
861 @lilypond[fragment, relative=1]
862 c2-~-( c8 fis fis4 ~ fis2 g2-)
863 @end lilypond
865 @cindex phrasing slurs
866 If you need two slurs at the same time (one for articulation, one for
867 phrasing), you can also make a phrasing slur with @code{\(} and
868 @code{\)}.
870 More information on fingering, articulation, slurs, phrasing slurs,
871 and dynamics can be found in @ref{Fingering instructions},
872 @ref{Articulations}, @ref{Slurs}, @ref{Phrasing slurs}, and @ref{Dynamics},
873 respectively.
875 @node Combining notes into chords
876 @section Combining notes into chords
878 @cindex chords
879 Chords can be made by
880 surrounding pitches with @code{<<} and @code{>}>:
881 @quotation
882 @lilypond[relative 0, fragment,verbatim]
883 r4 <<c e g>>4 <<c f a>>8
884 @end lilypond
885 @end quotation
886 @separate
889 You can combine beams and ties with chords.  Beam and tie markings
890 must be placed outside the chord markers:
891 @quotation
892 @lilypond[relative 0, fragment,verbatim]
893 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
894 @end lilypond
895 @end quotation
897 @quotation
898 @example
899 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>>  <<c f a>>8-\!-)
900 @end example
901 @lilypond[relative 0, fragment]
902 \slurUp
903 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>>  <<c f a>>8-\!-)
904 @end lilypond
905 @end quotation
906 @separate
910 @menu
911 * Basic rhythmical commands::   
912 * Commenting input files::      
913 @end menu
915 @node Basic rhythmical commands
916 @subsection  Basic rhythmical commands
918 @cindex pickup
919 @cindex anacruse
920 @cindex upstep
921 @cindex partial measure
922 A pickup (or upstep) is entered with the keyword @code{\partial}. It
923 is followed by a duration: @code{\partial 4} is a quarter note upstep
924 and @code{\partial 8} an eighth note:
925 @lilypond[relative 1,verbatim,fragment]
926   \partial 8
927   f8 c2 d e
928 @end lilypond
930 @cindex tuplets
931 @cindex triplets
932 Tuplets are made with the @code{\times} keyword.  It takes two
933 arguments: a fraction and a piece of music.  The duration of the piece
934 of music is multiplied by the fraction.  Triplets make notes occupy
935 2/3 of their notated duration, so  a triplet has  2/3 as its fraction:
937 @lilypond[relative 0,verbatim,fragment]
938   \times 2/3 { f8 g a }
939   \times 2/3 { c r c }
940 @end lilypond 
942 @cindex grace notes
943 @cindex accacciatura
944 Grace notes are also made by prefixing a note, or a set of notes with
945 a keyword. In this case, the keyword is @code{\grace}:
946 @lilypond[relative 1, verbatim,fragment]
947   c4 \grace b16-( c4-)
948   \grace { d16-( e } d4-)
949 @end lilypond
951 @noindent
952 More information on grace notes, tuplets and upsteps are in @ref{Grace
953 notes}, @ref{Tuplets} and @ref{Partial measures}.
957 @node Commenting input files
958 @subsection Commenting input files
960 @cindex comments
961 @cindex line comment
962 @cindex block comment
963 Comments are pieces of the input that are ignored.  There are two
964 types of comments. A line comments is introduced by @code{%}: after
965 that, the rest of that line is ignored.  Block comments span larger
966 sections of input.  Anything that is enclosed in @code{%@{} and
967 @code{%@}} is ignored too. The following fragment shows possible uses
968 for comments:
970 @example
971   % notes for twinkle twinkle follow:
972   c4 c   g' g  a a
973   
974   %@{
975   
976     This line, and the notes below
977     are ignored, since they are in a
978     block comment.
980     g g f f e e d d c2 
981   %@}
982 @end example
987 @node Printing lyrics
988 @section Printing lyrics
989 @cindex lyrics
991 @cindex Lyrics
992 @cindex Songs
993 Lyrics are entered by separating each syllable with a space, and
994 surrounding them with @code{\lyrics @{ @dots{} @}}, for example,
995 @example
996   \lyrics @{ I want to break free @}
997 @end example
999 Like notes, lyrics are also a form of music, but they must not be
1000 printed on a staff, which is the default way to print music. To print
1001 them as lyrics, they must be marked with @code{ \context Lyrics}:
1002 @example
1003   \context Lyrics  \lyrics @{ I want to break free @}
1004 @end example
1005 The melody for this song is as follows:
1007 @lilypond[fragment,relative=1]
1008    \partial 8
1009      c8
1010    \times 2/3 {  f4 g g } \times 2/3 { g4-( a2-) }
1011 @end lilypond
1013 The lyrics can be set to these notes, combining both with the
1014 @code{\addlyrics} keyword:
1015 @example
1016  \addlyrics
1017     \notes @{ @dots{} @}
1018     \context Lyrics @dots{}
1019 @end example
1021 The final result is 
1022 @lilypond[verbatim,linewidth=6.0cm]
1023 \score  {
1024  \notes {
1025   \addlyrics
1026    \relative c' {
1027      \partial 8
1028      c8
1029      \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
1030    }
1031    \context Lyrics  \lyrics { I want to break free }
1033  \paper{ }
1035 @end lilypond
1037 @cindex melisma
1038 @cindex extender line
1039 @c synonyms?
1040 This melody ends on a @rglos{melisma}, a single syllable (``free'')
1041 sung to more than one note. This is indicated with a @emph{extender
1042 line}. It is entered as two underscores, i.e.
1043 @example
1044   \lyrics @{ I want to break free __ @}
1045 @end example 
1046 @lilypond[]
1047 \score  {
1048  \notes {
1049   \addlyrics
1050    \relative c' {
1051    \partial 8
1052      c8
1053      \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
1055      %% ugh, this is to deal with bugs in the extender implementation
1056      \hideNotes
1057      c32
1058    }
1059    \context Lyrics  \lyrics { I want to break free __ }
1061  \paper{ linewidth = 9.0 \cm }
1063 @end lilypond
1065 Similarly, hyphens between words can be entered as two dashes,
1066 resulting in a centered hyphen between two syllables:
1067 @example
1068   Twin -- kle twin -- kle
1069 @end example
1070 @lilypond[singleline]
1071 \score {
1072   \addlyrics \notes \relative f' { \time 2/4
1073     f4 f c' c' }
1074     \context Lyrics \lyrics { Twin -- kle twin -- kle
1076 \paper { linewidth = 6.0 \cm }
1079 @end lilypond
1081 More options, like putting multiple lines of lyrics below a melody are
1082 discussed in @ref{Vocal music}.
1086 @node A lead sheet
1087 @section A lead sheet
1089 @cindex Lead sheets
1090 @cindex chords
1091 @cindex chord names
1093 In popular music, it is common to denote accompaniment as chord-names.
1094 Using them in LilyPond has two parts, just like lyrics: entering the
1095 chords (with @code{\chords}), and printing them (with @code{\context
1096 ChordNames}).
1098 Chord names are entered by starting chords mode (with @code{\chords}).
1099 In chords mode, you can enter chords with a letter (indicating the
1100 root of the chord), and a durations following that:
1102 @lilypond[verbatim]
1103   \chords { c2 f4. g8 } 
1104 @end lilypond
1106 @noindent
1107 The result of @code{\chords} is a list of chords, and is  equivalent
1108 to entering chords with @code{<<@dots{}>>}.
1110 Other chords can be created by adding modifiers, after a colon.  The
1111 following example shows a few common modifiers:
1113 @lilypond[verbatim]
1114   \chords { c2 f4:m g4:maj7 gis1:dim7 }
1115 @end lilypond
1117 Printing chords is done by adding @code{\context ChordNames}
1118 before the chords thus entered:
1120 @lilypond[verbatim]
1121  \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1122 @end lilypond
1124 @cindex lead sheet 
1125 When put together,  chord names, lyrics and a melody form
1126 a lead sheet, for example,
1128 @example
1129 \score @{
1130   <
1131     \context ChordNames \chords @{ @emph{chords} @}
1132     \addlyrics
1133       \notes @emph{the melody}
1134       \context Lyrics \lyrics @{ @emph{the text} @}
1135   >
1136   \paper @{ @}
1138 @end example
1139 @lilypond[]
1140 \score  {
1141   < 
1142    \context ChordNames \chords { r8 c2:sus4 f } 
1143    \addlyrics
1144     \notes \relative c' {
1145      \partial 8
1146      c8
1147      \times 2/3 { f g g } \times 2/3 { g4-( a2-) } }
1148    \context Lyrics  \lyrics { I want to break free __ }
1149   >
1150  \paper{ raggedright = ##t }
1152 @end lilypond
1155 A complete list of modifiers, and other options for layout are in the
1156 reference manual section @ref{Chords}.
1158 @node Listening to output
1159 @section Listening to output
1161 @cindex sound
1162 @cindex MIDI
1164 MIDI (Musical Instrument Digital Interface) is a standard for
1165 connecting and recording digital instruments.  A MIDI file is like a
1166 tape recording of a MIDI instrument. The @code{\midi} block makes the
1167 music go to a MIDI file, so you can listen to the music you entered.
1168 It is great for checking the music: octaves that are off, or
1169 accidentals that were mistyped, stand out very much when listening to
1170 the musical transcription.
1172 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
1173 example
1174 @example 
1175 \score @{
1176     @var{..music..}
1177     \midi  @{ \tempo 4=72 @}
1178     \paper  @{ @}
1180 @end example 
1182 Here, the tempo is specified using the @code{\tempo} command.  In this
1183 case the tempo of quarter notes is set to 72 beats per minute. More
1184 information on auditory output is in the @ref{Sound} section in the
1185 notation manual.
1189 @node Titling
1190 @section Titling
1192 Bibliographic information is entered in a separate block, the
1193 @code{\header} block. The name of the piece, its composer, etc. are
1194 entered as assignment, within @code{\header @{ @dots{} @}}. For
1195 example,
1196 @example 
1197   \header @{
1198     title = "Eight miniatures" 
1199     composer = "Igor Stravinsky"
1200     tagline = "small is beautiful"
1201   @}
1202   
1203   \score @{ @dots{} @}
1204 @end example
1206 @cindex bibliographic information
1207 @cindex titles
1208 @cindex composer
1209 @cindex ly2dvi
1212 When the file is processed by @code{ly2dvi}, the title and composer
1213 specified are printed above the music. The `tagline' is a short line
1214 printed at bottom of the last page, which normally says ``Lily was
1215 here, version @dots{}''. In the example above, it is replaced by the
1216 line ``small is beautiful''.
1218 Normally, the @code{\header} is put at the top of the file. However,
1219 for a document that contains multiple pieces (e.g. a etude book, or
1220 part with multiple movements), then the header can be put into the
1221 @code{\score} block as follows; in this case, the name of each piece
1222 will be printed before each movement:
1225 @cindex Lily was here
1226 @cindex signature line
1227 @cindex tag line
1229 @example 
1230   \header @{
1231     title = "Eight miniatures" 
1232     composer = "Igor Stravinsky"
1233     tagline = "small is beautiful"
1234   @}
1235   
1236   \score @{ @dots{}
1237     \header @{ piece = "Adagio" @}
1238   @}
1239   \score @{ @dots{}
1240     \header @{ piece = "Menuetto" @}
1241   @}
1242 @end example
1244 More information on titling can be found in @ref{Invoking ly2dvi}.
1247 @node Single staff polyphony
1248 @section Single staff polyphony
1250 @cindex polyphony
1251 @cindex multiple voices
1252 @cindex voices, more -- on a staff
1254 When different melodic lines are combined on a single staff, these are
1255 printed as polyphonic voices: each voice has its own stems, slurs
1256 and beams, and the top voice has the stems up, while the bottom voice
1257 has stems down.
1259 Entering such parts is done by entering each voice as a sequence (with
1260 @code{@{ .. @}}), and combining those simultaneously, separating the
1261 voices with @code{\\}:
1263 @example
1264   < @{ a4 g2 f4-~ f4 @} \\
1265     @{ r4 g4 f2 f4 @} >
1266 @end example
1267 @lilypond[relative 1]
1268 \context Staff   < { a4 g2 f4-~ f4 } \\
1269     { r4 g4 f2 f4 } >
1270 @end lilypond
1272 For polyphonic music typesetting, spacer rests can also be convenient: these
1273 are rests that do not print.  It is useful for filling up voices that
1274 temporarily do not play:
1275 @example
1276   < @{ a4 g2 f4-~ f4 @} \\
1277     @{ s4 g4 f2 f4 @} >
1278 @end example
1279 @lilypond[relative 1]
1280 \context Staff  < { a4 g2 f4-~ f4 } \\
1281     { s4 g4 f2 f4 } >
1282 @end lilypond
1284 Again, these expressions can be nested arbitrarily:
1286 @lilypond[fragment]
1288  \context Staff = staffA 
1289   \relative c''
1290     < { a4 g2 f4-~ f4 } \\
1291       { s4 g4 f2 f4 } >
1292  \context Staff = staffB 
1293   <  { \clef bass <<c g>>1  } \\
1294      { f4 d e2 }
1295   >
1297 @end lilypond
1300 More features of polyphonic typesetting are in the notation manual
1301 in @ref{Polyphony}.
1303 @node Piano staffs
1304 @section Piano staffs
1306 @cindex staff switch, manual
1307 @cindex cross staff voice, manual
1308 @cindex @code{\translator}
1310 Piano music is always typeset in two staffs connected by a brace.
1311 Printing such a staff is done similar to the polyphonic example in
1312 @ref{Combining music into compound expressions}:
1313 @example
1314  < \context Staff = up @{ @dots{} @}
1315    \context Staff = down @{ @dots{} @}
1317 @end example
1318 but now this entire expression must be interpreted as a
1319 @code{PianoStaff}:
1320 @example
1321  \context PianoStaff < \context Staff @dots{} >
1322 @end example
1324 Here is a full-fledged example:
1326 @lilypond[relative 0,fragment]
1327 \context PianoStaff
1328  < \context Staff = up { \time 2/4
1329      c4 c g' g  }
1330    \context Staff = down {
1331      \clef bass c,, c' e c }
1333 @end lilypond
1335 More information on formatting piano music is in @ref{Piano music}. 
1337 @node Setting variables
1338 @section Setting variables
1340 When the music is converted from notes to print, it is interpreted
1341 from left-to-right order, similar to what happens when we read
1342 music. During this step, context-sensitive information, such as the
1343 accidentals to print, and where barlines must be placed, are stored in
1344 variables. These variables are called @emph{translation properties}.
1345 The properties can also be manipulated from input files. Consider this input:
1346 @example
1347 \property Staff.autoBeaming = ##f
1348 @end example 
1349 It sets the property named @code{autoBeaming} in the current staff to
1350 @code{##f}, which means `false'. This property controls whether beams
1351 are printed automatically:
1352 @lilypond[relative 1,fragment,verbatim]
1353   c8 c c c
1354   \property Staff.autoBeaming = ##f
1355   c8 c c c  
1356 @end lilypond
1358 @noindent
1359 LilyPond includes a built-in programming language, namely, a dialect
1360 of Scheme.  The argument to @code{\property}, @code{##f}, is an
1361 expression in that language.  The first hash-mark signals that a piece
1362 of Scheme code follows. The second hash character is part of the
1363 boolean value true (@code{#t}).  Values of other types may be
1364 entered as follows:
1365 @itemize @bullet
1366 @item a string, enclosed in double quotes, for example,
1367 @example
1368   \property Staff.instrument = #"French Horn"
1369 @end example
1370 @item a boolean: either @code{#t} or @code{#f}, for true and false
1371 respectively, e.g.
1372 @example
1373   \property Voice.autoBeaming = ##f
1374   \property Score.skipBars = ##t
1375 @end example
1377 @item a number, such as
1378 @example
1379   \property Score.currentBarNumber = #20
1380 @end example
1382 @item a symbol, which is introduced by a quote character, as in 
1383 @example
1384   \property Staff.crescendoSpanner = #'dashed-line
1385 @end example
1387 @item a pair, which is also introduced by a quote character, like in
1388 the following statements, which set properties to the pairs (-7.5, 6) 
1389 and (3, 4) respectively:
1391 @example
1392   \property Staff.minimumVerticalExtent  = #'(-7.5 . 6)
1393   \property Staff.timeSignatureFraction  = #'(3 . 4)
1394 @end example
1397 @end itemize
1399 There are many different properties, and not all of them are listed in
1400 this manual. However, the internal documentation lists them all in the
1401 @internalsref{All translation properties}, and most properties
1402 are demonstrated in one of the
1403 @ifhtml
1404 @uref{../../../input/test/out-www/collated-files.html,tips-and-tricks}
1405 @end ifhtml
1406 @ifnothtml
1407 tips-and-tricks
1408 @end ifnothtml
1409 examples.
1412 @node Fine tuning layout
1413 @section Fine tuning layout
1415 Sometimes it is necessary to change music layout by hand.  When music
1416 is formatted, layout objects are created for each symbol.  For
1417 example, every clef and every note head is represented by a layout
1418 object.  These layout objects also carry variables, which we call
1419 @emph{layout properties}. By changing these variables from their
1420 values, we can alter the look of a formatted score:
1422 @lilypond[verbatim,relative 0]
1423   c4
1424   \property Voice.Stem \override #'thickness = #3.0
1425   c4 c4 c4 
1426 @end lilypond
1428 @noindent
1429 In the example shown here, the layout property @code{thickness} (a
1430 symbol) is set to 3 in the @code{Stem} layout objects of the current
1431 Voice.  As a result, the notes following @code{\property} have thicker
1432 stems.
1434 In most cases of manual overrides, only a single object must be
1435 changed. This can be achieved by prefixing @code{\once} to the
1436 @code{\property} statement, i.e.
1438 @example
1439  \once \property Voice.Stem \set #'thickness = #3.0
1440 @end example
1442 @lilypond[relative 0]
1443   c4
1444   \once \property Voice.Stem \set #'thickness = #3.0
1445   c4 c4 c4 
1446 @end lilypond
1448 @noindent
1449 Some overrides are so common that predefined commands are provided as
1450 a short cut.  For example, @code{\slurUp} and @code{\stemDown}. These
1451 commands are described in
1452 @ifhtml
1454 @end ifhtml
1455 @ref{Notation manual}, under the sections for slurs and stems
1456 respectively.
1458 The exact tuning possibilities for each type of layout object are
1459 documented in the internal documentation of the respective
1460 object. However, many layout objects share properties, which can be
1461 used to apply generic tweaks.  We mention a couple of these:
1463 @itemize @bullet
1464 @item The @code{extra-offset} property, which
1465 @cindex @code{extra-offset}
1466 has a pair of numbers as value, moves around objects in the printout.
1467 The first number controls left-right movement; a positive number will
1468 move the object to the right.  The second number controls up-down
1469 movement; a positive number will move it higher.  The unit of these
1470 offsets are staff-spaces.  The @code{extra-offset} property is a
1471 low-level feature: the formatting engine is completely oblivious to
1472 these offsets.
1474 In the following example example, the second fingering is moved a
1475 little to the left, and 1.8 staff space downwards:
1477 @cindex setting object properties
1479 @lilypond[relative 1,verbatim]
1480 \stemUp
1482 \once \property Voice.Fingering
1483   \set #'extra-offset = #'(-0.3 . -1.8) 
1485 @end lilypond
1487 @item
1488 Setting the @code{transparent} property will make an object be printed
1489 in `invisible ink': the object is not printed, but all its other
1490 behavior is retained. The object still takes space, it takes part in
1491 collisions, and slurs, ties and beams can be attached to it.
1493 @cindex transparent objects
1494 @cindex removing objects
1495 @cindex invisible objects
1496 The following example demonstrates how to connect different voices
1497 using ties. Normally ties only happen between notes of the same
1498 voice. By introducing a tie in a different voice, and blanking a stem
1499 in that voice, the tie appears to cross voices:
1501 @lilypond[fragment,relative 1,verbatim]
1502 \context Staff < {
1503       \once \property Voice.Stem \set #'transparent = ##t
1504       b8~ b8
1505   } \\ {
1506        b-[ g8-]
1507   } >
1508 @end lilypond
1510 @item
1511 The @code{padding} property for objects with
1512 @cindex @code{padding}
1513 @code{side-position-interface} can be set to increase distance between
1514 symbols that are printed above or below notes. We only give an
1515 example; a more elaborate explanation is in @ref{Constructing a
1516 tweak}:
1518 @lilypond[relative 1]
1519   c2-\fermata
1520   \property Voice.Script \set #'padding = #3
1521   b2-\fermata
1522 @end lilypond
1524 @end itemize
1526 More specific overrides are also possible.  The notation manual
1527 discusses in depth how to figure out these statements for yourself, in
1528 @ref{Tuning output}.
1530 @node Organizing larger pieces
1531 @section Organizing larger pieces
1533 When all of the elements discussed earlier are combined to produce
1534 larger files, the @code{\score} blocks get a lot bigger, because the
1535 music expressions are longer, and, in the case of polyphonic and/or
1536 orchestral pieces, more deeply nested.
1538 By using variables, also known as identifiers, it is possible to break
1539 up complex music expressions.
1540 An identifier is assigned as follows:
1541 @example
1542   namedMusic = \notes @{ @dots{}
1543 @end example
1545 The contents of the music expression @code{namedMusic}, can be used
1546 later by preceding the name with a backslash, i.e. @code{\namedMusic}.
1547 In the next example, a two note motive is repeated thrice by using
1548 variable substitution:
1550 @lilypond[singleline,verbatim]
1551 seufzer  = \notes {
1552   dis'8 e'8
1554 \score { \notes {
1555   \seufzer \seufzer \seufzer
1556 } }
1557 @end lilypond
1559 The name of an identifier should only have alphabetic characters only,
1560 and no numbers, underscores or dashes. The assignment should be
1561 outside of the @code{\score} block.
1563 It is possible to use variables for many other types of objects in the
1564 input.  For example,
1565 @example
1566   width = 4.5\cm
1567   name = "Wendy"
1568   aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1569 @end example
1570 Depending on its contents, the identifier can be used in different
1571 places. The following example uses the above variables:
1572 @example
1573   \score @{
1574     \notes @{ c4^\name @}
1575     \paper @{
1576       \aFivePaper
1577       linewidth = \width
1578     @}
1579   @}
1580 @end example
1582 More information on the possible uses of identifiers is in the
1583 technical manual, in @ref{Scheme datatypes}.
1586 @node An orchestral part
1587 @section An orchestral part
1589 In orchestral music, all notes are printed twice: both in a part for
1590 the musicians, and in a full score for the conductor. Identifiers can
1591 be used to avoid double work: the music is entered once, and stored in
1592 variable. The contents of that variable is then used to generate
1593 both the part and the score.
1595 It is convenient  to define the notes in a  special file, for example,
1596 suppose that the @file{horn-music.ly} contains the following part of a
1597 horn/bassoon duo.
1598 @example
1599 hornNotes = \notes \relative c @{
1600   \time 2/4
1601   r4 f8 a cis4 f e d
1603 @end example
1605 Then, an individual part is made by putting the following in a file:
1606 @example
1607 \include "horn-music.ly"
1608 \header @{
1609   instrument = "Horn in F"
1611 \score @{
1612   \notes \transpose c' f \hornNotes
1614 @end example
1615 The @code{\include} command substitutes the contents of the file at
1616 this position in the file, so that @code{hornNotes} is defined
1617 afterwards.  Since the horn is tuned in F, the @code{\transpose}
1618 command is used. The code @code{\transpose c' f} indicates that the
1619 argument, being @code{\hornNotes}, should be transposed by a fifth
1620 downwards: the @code{c'} becomes a @code{f}. The transposition can be
1621 seen in the following output:
1623 @lilypond[singleline]
1624 \score {
1625   \notes \transpose c' f  \notes \relative c' {
1626   \time 2/4
1627   r4 f8 a cis4 f e d
1630 @end lilypond
1632 In ensemble pieces, one of the voices often does not play for many
1633 measures. This is denoted by a special rest, the multi-measure
1634 rest. It is entered with a capital R, and followed by a duration (1
1635 for a whole note, 2 for a half note, etc.) By multiplying the
1636 duration, longer rests can be constructed. For example, the next rest
1637 takes 3 measures in 2/4 time:
1638 @example
1639   R2*3
1640 @end example
1642 When printing the part, the following @code{skipBars} property must be
1643 set to false, to prevent the rest from being expanded in three one bar
1644 rests:
1645 @example
1646   \property Score.skipBars = ##t
1647 @end example
1648 Prepending the rest and the property setting above, leads to the
1649 following result:
1651 @lilypond[singleline]
1652 \score {\notes { \transpose c' f \relative c' { \time 2/4
1653 \property Score.skipBars = ##t 
1654         R2*3
1655     r4 f8 a cis4 f e d } }}
1656 @end lilypond
1658 The score is made by combining all of the music in a @code{\score}
1659 block, assuming that the other voice is in @code{bassoonNotes}, in the
1660 file @file{bassoon-music.ly}:
1661 @example
1662 \include "bassoon-music.ly"
1663 \include "horn-music.ly"
1665 \score @{
1666   \simultaneous @{
1667     \context Staff = hornStaff \hornNotes
1668     \context Staff = bsnStaff \bassoonNotes
1669   @} @}
1670 @end example
1672 This would lead to the simple score depicted below:
1674 @lilypond[singleline]
1675 \score {
1676   \notes \relative c \simultaneous {
1677     \context Staff = hornStaff { \time 2/4
1678         R2*3
1679     r4 f8 a cis4 f e d }
1680     \context Staff = fagStaff { \clef bass
1681       r4 d,8 f | gis4 c |  b bes |
1682       a8 e f4 |  g d | gis f }
1683   } }
1684 @end lilypond 
1686 More in-depth information on preparing parts and scores is in the
1687 notation manual, in @ref{Orchestral music}.
1690 @node Integrating text and music
1691 @section Integrating text and music
1693 @cindex La@TeX{}, music in
1694 @cindex HTML, music in
1695 @cindex Texinfo, music in
1697 Sometimes you might want to use music examples in a text that you are
1698 writing (for example, a musicological treatise, a songbook, or (like us)
1699 the LilyPond manual).  You can make such texts by hand, simply by
1700 importing a PostScript figure into your word processor.  However,
1701 there is an automated procedure to reduce the amount of work.
1703 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1704 code.  A script called @code{lilypond-book} will extract the music
1705 fragments, run LilyPond on them, and put back the resulting notation.
1706 This program is fully described in @ref{lilypond-book manual}.  Here
1707 we show a small example;  since the example contains also explanatory
1708 text, we will not comment it further:
1710 @example
1711 \documentclass[a4paper]@{article@}
1712 \begin@{document@}
1714 In a lilypond-book document, you can freely mix music and text. For
1715 example:
1716 \begin@{lilypond@}
1717   \score @{ \notes \relative c' @{
1718      c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1719   @} @}
1720 \end@{lilypond@}
1722 Notice that the music line length matches the margin settings of the
1723 document.
1725 If you have no \verb+\score+ block in the fragment,
1726 \texttt@{lilypond-book@} will supply one:
1728 \begin@{lilypond@}
1729   c'4
1730 \end@{lilypond@}
1732 In the example you see here, two things happened: a
1733 \verb+\score+ block was added, and the line width was set to natural
1734 length. You can specify  options by putting them in brackets:
1736 \begin[26pt,verbatim]@{lilypond@}
1737   c'4 f16
1738 \end@{lilypond@}
1740 If you want to include large examples into the text, it is more
1741 convenient to put it in a separate file:
1743 \lilypondfile@{screech-boink.ly@}
1745 \end@{document@}
1746 @end example
1748 Under Unix, you can view the results as follows:
1749 @example
1750 $ cd input/tutorial
1751 $ mkdir -p out/
1752 $ lilypond-book --outdir=out/ lilbook.tex
1753 lilypond-book (GNU LilyPond) 1.7.23
1754 Reading `input/tutorial/lilbook.tex'
1755 Reading `input/screech-boink6.ly'
1756 @var{lots of stuff deleted}
1757 Writing `out/lilbook.latex'
1758 $ cd out
1759 $ latex lilbook.latex
1760 @var{lots of stuff deleted}
1761 $ xdvi lilbook 
1762 @end example
1764 Running lilypond-book and running latex creates a lot of temporary
1765 files, and you would not want those to clutter up your working
1766 directory.  The @code{outdir} option to lilypond-book creates the
1767 temporary files in a separate subdirectory @file{out}.
1769 The result looks more or less like this: 
1771 @separate
1773 In a lilypond-book document, you can freely mix music and text. For
1774 example:
1775 @lilypond
1776 \score {
1777   \notes \relative c' {
1778     c2 g'2 \times 2/3 { f8 e d } c'2 g4
1779   }
1780   \paper {
1781     raggedright = ##t
1782   }
1784 @end lilypond
1786 Notice that the music line length matches the margin settings of the
1787 document.
1789 If you have no @code{\score} block in the fragment,
1790 @code{lilypond-book} will supply one:
1792 @lilypond
1793   c'4
1794 @end lilypond
1796 In the example you see here, two things happened: a
1797 @code{score} block was added, and the line width was set to natural
1798 length. You can specify  options by putting them in brackets:
1800 @lilypond[26pt,verbatim]
1801   c'4 f16
1802 @end lilypond
1804 If you want to include large examples into the text, it is more
1805 convenient to put it in a separate file:
1807 @lilypondfile{screech-boink.ly}