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