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