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