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