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