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