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