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