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