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