]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
release: 1.3.153
[lilypond.git] / Documentation / user / tutorial.itely
1 @c -*-texinfo-*-
2
3 @c TODO: LilyPond Lilypond lilypond
4
5
6 @node Tutorial
7 @chapter Tutorial
8   
9 @menu
10 * Running LilyPond::            Getting started
11 * First steps::                 
12 * The first tune::              The first tune
13 * Lyrics and chords::           Lyrics and chords
14 * More movements ::             
15 * A piano excerpt::             Piano music
16 * An orchestral score::         
17 * Other ways to run LilyPond::  
18 * Integrating text and music::  
19 * end of tutorial::             The end
20 @end menu
21
22
23 @node Running LilyPond
24 @section Running LilyPond
25
26 You make music notation with LilyPond as follows: first you edit a text
27 file containing a description of the notes. Then you run LilyPond on the
28 file. This leaves you with an output file, which you can view or print.
29
30 In this section we explain how to run LilyPond, and view or print the
31 output.  If you want to test your setup of LilyPond, or try to run an
32 example file yourself, then read this section. Otherwise, you can skip
33 to the next section, which explains how to
34 write LilyPond input.
35
36 The instructions that follow are for Unix. Windows instructions are
37 given at the end of this section. Start with opening a terminal window,
38 and start up a text editor.  For example, start an xterm and execute
39 @code{joe}.   Enter the following
40 input, and save the file as @file{test.ly}.
41 @example
42 \score @{
43   \notes @{ c'4 e' g' @}
44 @} 
45 @end example
46 If this code looks intimidating you, then don't worry, we explain all
47 about it in the next section.
48
49 @cindex ly2dvi
50
51 @c dit is dus raar, dat je ly2dvi draait om lelie te draaien
52 @c (therefore name change proposal) 
53
54 Invoke the program  @code{ly2dvi} to run lilypond on your source file:
55 @example
56 ly2dvi -P test
57 @end example
58
59 You will see the following on your screen:
60 @example
61 GNU LilyPond 1.4.0
62 Now processing: `/home/fred/ly/test.ly'
63 Parsing...
64 Interpreting music...[1]
65  @emph{ ... more interesting stuff ... }
66 PS output to `test.ps'...
67 DVI output to `test.dvi'...
68 @end example
69
70 @cindex DVI file
71 @cindex Viewing music
72 @cindex xdvi
73
74 The results of the ly2dvi run are two files, @file{test.dvi} and
75 @file{test.ps}.  The PS file (@file{test.ps}) is the one you can
76 print. You can view the PS file using the program ghostview.  If a
77 version of ghostview is installed on your system, one of these commands
78 will produce a window with some music notation on your screen.
79 @example
80 kghostview test.ps
81 ggv test.ps
82 ghostview test.ps
83 gv test.ps
84 @end example
85 When you're satisfied with the result, you can print the PS file by
86 clicking File/Print inside ghostview.
87
88 The DVI file (@file{test.dvi}) contains the same sheet music in a
89 different format. DVI files are more easily processed by the computer,
90 so viewing them usually is quicker. Execute @code{xdvi test}
91 to view the DVI file.
92
93 If your DVI viewer does not have a "Print" button, you can print the
94 file by executing @code{lpr test.ps}.
95
96 @c volgende alinea schrappen?  
97
98 If you can't get the examples to print, then you should look into
99 installing and configuring ghostscript.  Refer to GhostScript's website
100 at @uref{http://www.ghostscript.com}.
101
102 @cindex GhostScript
103 @cindex @code{lpr}
104 @cindex Printing output
105 @cindex PostScript
106
107
108 Windows users start the terminal by clicking on the lilypond icon.
109 Notepad is sufficient for editing the lilypond file. Viewing the PS file
110 can be done with @code{gsview32 test.ps}. Viewing DVI files can be done
111 with @code{yap test}. The "print" button in Yap will print files.  You
112 can also print from the command line by executing @code{gsview32 /s
113 test.ps}
114
115
116 @c titel?
117
118 @node First steps
119 @section First steps
120
121 The basics of any piece of music are notes.  Notes are entered 
122 with letters @code{a} to @code{g}, followed by a
123 number that represents the duration: a @code{2} is a half note, a
124 @code{4} is a quarter note. A period adds a dot to the note, so
125 entering @code{2.} gives a dotted half note. 
126 @example
127      c2 e4 g2.
128 @end example
129 @lilypond[fragment]
130 \property Score.timing  = ##f
131 \property Staff.TimeSignature  = \turnOff
132 \property Staff.Clef  = \turnOff
133 \clef bass c2 e4 g2.
134 @end lilypond
135 If you don't specify a duration, then the duration last entered is used:
136 @c
137 @example
138   f4 e d c2.
139 @end example
140 @lilypond[fragment]
141 \property Score.timing  = ##f
142 \property Staff.TimeSignature  = \turnOff
143 \property Staff.Clef  = \turnOff
144 \clef bass  f4 e d c2.
145 @end lilypond
146 The time signature can be set with a command of the form @code{\time},
147 and the clef with @code{\clef} as follows:
148 @example
149      \time 3/4
150      \clef bass
151 @end example
152 @lilypond[fragment]
153         \time 3/4
154         \clef bass
155         s2_" "
156 @end lilypond
157
158 The commands together with the notes are combined to form a snippet of
159 music. They are combined by enclosing them with @code{\notes @{ @}}.
160 @example
161   \notes @{
162      \time 3/4
163      \clef bass
164      c2 e4 g2.
165      f4 e d c2.
166   @}
167 @end example
168
169 This snippet is ready to be printed. This is done by combining the music
170 with a printing command. The printing command is the so-called
171 @code{\paper} block.  You will see later that the \paper block is
172 necessary to customize all kinds of printing specifics.  The music and
173 paper block are combined by enclosing them in @code{\score}.
174
175 @lilypond[verbatim]
176 \score {
177   \notes {
178      \time 3/4
179      \clef bass
180      c2 e4  g2.
181      f4 e d c2.
182   }
183   \paper { }
184 }
185 @end lilypond
186
187 @ignore
188 The @code{\paper} block looks empty, which means that we get default. That is because we did not contains page layout settings, such as the linewidth and
189 the staff size. For now, we'll use standard settings, hence the paper
190 block is empty (its braces enclose a blank space).
191 @end ignore
192
193 Rests are entered just like notes with the name @code{r}
194 @lilypond[fragment,verbatim]
195 r4 r8 r16
196 @end lilypond
197
198 Octaves are entered by adding apostrophes or commas to note names. For
199 example, the central C is entered as @code{c'}.
200
201 Pitches can be octaviated by adding  apostrophes or commas. The central C is
202 @code{c'}. Going up octave by octave we get @code{c''},
203 @code{c'''}. Going down from central C, we get @code{c} @code{c,}
204 @code{c,,} etc.
205
206 @lilypond[verbatim,fragment]
207 c'4 c'' c''' c c,
208 @end lilypond
209
210 LilyPond uses Dutch note names: you can make a note sharp by appending
211 @code{is} to the name, and flat by appending @code{es} to the name.
212 @lilypond[verbatim,fragment]
213 fis'4 bes'4 aeses'4
214 @end lilypond
215
216 Ties are created by entering a tilde (@code{~}) between the notes to be
217 tied:
218 @lilypond[fragment,verbatim]
219   g'4 ~ g' a'2 ~ a'4
220 @end lilypond
221 Ties look almost the same as slurs, but they are different. Ties can
222 only indicate the extension of a note. Ties connect two note heads with
223 the same pitch.  Slurs on the other hand, can be drawn across many
224 notes, and indicate bound articulation.
225  
226 The key signature is set with the command @code{\key}:
227 @lilypond[fragment,verbatim]
228   \key d \major
229   g'1
230   \key c \minor
231   g'
232 @end lilypond
233
234 The next example shows octave marks, ties, and rests in action. 
235 @lilypond[verbatim]
236 \score {
237   \notes {
238     \time 4/4
239     \clef treble
240     \key d \minor
241     r4 r8 d''8 cis''4 e''
242     d''8 a'4. ~ a'  b'8
243     cis''4 cis''8 cis'' bis'4 d''8 cis'' ~
244     cis''2 r2
245   }
246   \paper { }
247 }
248 @end lilypond
249 There is one interesting point to note in this example: accidentals
250 don't have to be marked explicitly. You just enter the pitch, and
251 LilyPond determines wether or not to print an accidental.
252
253 If you look at the last piece, it is already apparent that entering
254 octaves using quotes is not very convenient. A score written in high
255 register will be encoded using lots quotes. This makes the input file
256 unreadable, and it also is a source of many errors.
257
258 This problem is solved by relative octave mode. In this mode, the quotes
259 are used to mark large jumps in the melody. Without any quotes or
260 commas, the interval between a note and its predecessor is assumed to be
261 a fourth or less. Quotes and commas add octaves in up and down
262 direction.
263 @lilypond[fragment,verbatim]
264 \relative c'' { c4 d4 b4 e4 a,4 f'4 g,4 a'4 }
265 @end lilypond
266 You can enter a piece in relative mode, by putting @code{\relative} in
267 front. You also have to enter a starting pitch, in this case @code{c''}.
268
269
270 Slurs (not to be confused with ties) are entered with parentheses. You
271 mark the starting note and ending note with a @code{(} and a
272 @code{)} respectively.
273
274 @lilypond[fragment,relative 1, verbatim]
275 c8( cis d ) e 
276 @end lilypond
277
278 If you need two slurs at the same time (one for articulation, one for
279 phrasing), you can also make a phrasing slur with @code{\(} and
280 @code{\)}.
281
282 @c lousy example
283 @lilypond[fragment,relative 1, verbatim]
284 a8(\( ais b ) c cis2 b'2 a4 cis, \) c
285 @end lilypond
286
287 Beams are drawn automatically, but if you don't like the choices, you
288 can enter beams by hand. Surround the notes to be grouped with @code{[}
289 and @code{]}:
290 @lilypond[fragment,relative 1, verbatim]
291 [a8 ais] [d es r d]
292 @end lilypond
293
294 You can make more than one staff, by specifying @code{\context Staff} before 
295 snippets of music, and combining those snippets in @code{<} and
296 @code{>}, as is demonstrated here:
297
298 @lilypond[fragment,verbatim]
299 < \context Staff = staffA { \clef treble c'' }
300   \context Staff = staffB { \clef bass c }
301 >
302 @end lilypond
303 Here, @code{staffA} and @code{staffB} are names that you give them to
304 the staff. For now, it doesn't matter what names you give them, as long
305 as they are different.
306
307 We can typeset a melody with two staffs now:
308
309 @lilypond[verbatim]
310 \score {
311   \notes 
312   < \context Staff = staffA {
313       \time 3/4
314       \clef treble
315       \relative c'' { e2 ( d4 c2 b4 [a8 a] [b b] [g g] )a2. }  
316     }
317     \context Staff = staffB {
318        \clef bass
319        c2 e4  g2.
320        f4 e d c2.
321     }
322   >
323   \paper {} 
324 }
325 @end lilypond
326
327 Notice that the time signature is specified in one melody staff only
328 (the top staff), but is printed on both. LilyPond knows that the time
329 signature should be the same for all staffs.
330
331 Dynamic signs are made by adding the markings after the note
332 @lilypond[verbatim,relative 1]
333 c-\ff c-\mf
334 @end lilypond
335
336 Crescendi are started with the commands @code{\<}  and @code{\>}. The
337 command @code{\!} finishes a crescendo on the following.
338 @lilypond[verbatim,relative 1]
339 c2  \< \! c2-\ff \> c2  \! c2
340 @end lilypond
341
342 Chords can be made by surrounding notes with @code{<} and @code{>}:
343 @lilypond[relative 0, fragment,verbatim]
344   r4  <c e g> <c f a> 
345 @end lilypond
346
347 @c te diepzinnig?
348
349 In general, @code{ < @var{stuff} > } is used when @var{stuff} all
350 happens at the same time, like in chords, or (like in the two-staff
351 example above) in a bunch of stacked staffs.
352
353 Of course, you can combine beams and ties with chords:
354 @lilypond[relative 0, fragment,verbatim]
355  r4  [<c8 e g>   <c8 f a>] ~ <c8 f a>
356 @end lilypond
357
358 When you want to combine chords with slurs and dynamics, an annoying
359 technical detail crops up: you have type these commands next to the
360 notes, which means that they have to be inside the @code{< >}:
361
362 @lilypond[relative 0, fragment,verbatim]
363  r4     <c8 e g \> ( > <c e g> <c e g>  < ) \! c8 f a>
364 @end lilypond
365
366 A nasty technical detail also crops up when you start a score with a
367 chord:
368 @lilypond[verbatim,singleline]
369 \score { \notes <c'1 e'1> }
370 @end lilypond
371 The program can not guess that you want the notes on only one staff. To
372 force the chord on a staff, add @code{\context Staff} like this:
373 @lilypond[verbatim,singleline]
374 \score { \notes \context Staff <c'1 e'1> }
375 @end lilypond
376
377
378
379
380 @ignore
381 [TODO add some more here
382
383 * lyrics, chords (?)
384
385 * \header
386
387 * identifiers?
388
389 ]
390 @end ignore
391
392 This is the end of the simple tutorial. You know the basic ingredients
393 of a music file, so this is the right moment to try your at hand at
394 doing it yourself: try to type some simple examples, and experiment a
395 little.
396
397 When you're comfortable with the basics, then you might want to read the
398 rest of this chapter. It also a manual in tutorial-style, but it is much
399 more in-depth. It will also be very intimidating if you're not familiar
400 with the basics.  It deals with some of the more advanced features of
401 lilypond. Topics include lyrics, chords, orchestral scores and parts,
402 fine tuning output, polyphonic music, and integrating text and music.
403
404
405
406 @node The first tune
407 @section The first tune
408
409
410 This tutorial will demonstrate how to use Lilypond by presenting
411 examples of input along with resulting output.  We will use English
412 terms for notation.  In case you are not familiar with those, you may
413 consult the glossary that is distributed with LilyPond.
414
415 The examples discussed are included in the distribution, in the
416 subdirectory @file{input/tutorial/}@footnote{When we refer to filenames,
417 they are relative to the top directory of the source package. }
418
419 To demonstrate what LilyPond input looks like, we start off with a
420 full-fledged, yet simple example. It is a convoluted version
421 of the famous minuet in J. S. Bach's @emph{Klavierb@"uchlein}. The file
422 is included in the distribution as  @file{minuet.ly}.
423 @cindex Bach, Johann Sebastian 
424
425 @lilypond[verbatim]
426 % all text after a percent sign is a comment
427 % and is ignored by Lilypond
428 \include "paper16.ly"
429 \score {
430     \notes                        
431     \relative c'' \sequential {
432             \time 3/4                
433             \key g \major
434
435         \repeat "volta" 2 {
436             d4 g,8 a b c d4 g, g |
437             e'4 c8 d e fis g4 g, g |
438             c4 d8( )c b a( )b4 c8 b a g |
439             a4 [b8 a] [g fis] g2.  |
440         }
441
442         b'4 g8 a b g
443         a4 d,8 e fis d |
444         g4 e8 fis g d cis4 b8 cis a4 |
445         a8-. b-. cis-. d-. e-. fis-.
446         g4 fis e |
447         fis a,  r8 cis8
448         d2.-\fermata
449         \bar "|."
450     }
451     \paper {
452        % standard settings are too wide for a book
453        linewidth = 14.0 \cm
454    }
455 }
456 @end lilypond
457
458 We will analyse the input, line by line.
459 @separate
460 @example
461         % all text after a percent sign is a comment
462         % and is ignored by Lilypond
463 @end example 
464 Percent signs introduce comments: everything after a percent sign is
465 ignored. You can use this to write down mental notes to yourself.  You
466 can also make longer comments by enclosing text in @code{%@{} and
467 @code{%@}}.
468 @cindex comment
469 @cindex block comment
470 @cindex line comment
471 @separate
472 @example 
473
474         \include "paper16.ly"
475  
476 @end example
477 @cindex @code{\include}
478 @cindex point, printer's
479 @cindex staff size setting 
480 By default, LilyPond will typeset the music in a size such that each
481 staff is 20 point (0.7 cm, or 0.27 inch) high.  We want smaller output
482 (16 point staff height), so we must import the settings for that size,
483 which is done here.
484 @separate
485 @example 
486
487         \score @{
488  
489 @end example 
490 Music is printed by combining a piece of music with directions for
491 outputting it.  This combination is formed in the @code{\score} block.
492 @separate
493 @example 
494
495         \notes                
496  
497 @end example 
498 Prepare LilyPond for accepting notes.
499 @cindex octaves, choosing
500 @cindex pitch
501 @separate
502 @example 
503
504         \relative c''
505  
506 @end example
507 @cindex relative
508 As we will see, each note is described by its note name, duration,
509 octave and possibly a chromatic alteration.  In this setup, the octave
510 is indicated by using high quotes (@code{'}) and ``lowered quotes''
511 (commas: @code{,}).  The central C is denoted by @code{c'}.  The C one
512 octave higher is @code{c''}.  One and two octaves below the central C is
513 denoted by @code{c} and @code{c,} respectively.
514
515 Even though a piece of music often spans a range of several octaves, it
516 mostly moves in small intervals.  LilyPond has a special entry mode to
517 save typing in this situation.  In this ``relative'' octave mode,
518 octaves of notes without quotes are chosen such that a note is as close
519 as possible (graphically, on the staff) to the preceding note.  If you
520 add a high-quote an extra octave is added.  A lowered quote (a comma)
521 will subtract an extra octave.
522
523 Because the first note has no predecessor,
524 you have to give the (absolute) pitch of the note to start with.
525 @separate
526 @example 
527
528         \sequential @{
529  
530 @end example 
531 What follows is sequential music, i.e.,
532 @cindex sequential music
533 notes that are to be played and printed after each other.
534 @separate
535 @example 
536
537         \time 3/4
538  
539 @end example
540 @cindex time signature, setting
541 @cindex @code{\time}
542 Set (or change) the time signature of the current piece: a 3/4 sign is
543 printed.  The time signature setting is also used to generate bar lines
544 at the right spots.
545 @separate
546 @example 
547
548         \key g \major
549  
550 @end example
551 @cindex key signature, setting
552 @cindex @code{\key}
553 Set (or change) the current key signature to G-major.  Although in this
554 example, the @code{\key} command happened to be entered after the
555 @code{\time} command, in the output the time signature will be printed
556 after the key signature; LilyPond knows about music typesetting
557 conventions.
558 @separate
559 @example 
560
561         \repeat "volta" 2
562  
563 @end example 
564 The following piece of music is played twice.  The first argument
565 indicates the type of repeat.  In this case, @code{"volta"} means that
566 prima volta/secunda volta brackets are used for the alternative
567 endings---if there were any.
568 @separate
569 @example 
570
571         @{
572  
573 @end example 
574 The subject of the repeat is again sequential music.  Since
575 @code{\sequential} is such a common construct, a shorthand is provided:
576 just leave off @code{\sequential}, and the result is the same.
577 @separate
578 @example 
579
580         d4 g,8
581  
582 @end example 
583 Two notes.  The first note is a quarter note with relative pitch
584 @code{d}.  The relative music was started with a @code{c''}, so the real
585 pitch of this note is @code{d''}.  The duration of a note is designated
586 by a number; the @code{4} here represents a quarter note.
587
588 The second note is an eight note with relative pitch @code{g,}.  The
589 pitch is taken relative to the previous @code{d''}, making this
590 note have real pitch @code{g'}.  The @code{8} represents an eight note.
591 @separate
592 @example 
593
594         a b
595  
596 @end example 
597 Two more notes, with pitch @code{a} and @code{b}.  Because their
598 duration is the same as the @code{g,8}, there is no need to enter the
599 duration, but you may enter it anyway, i.e., @code{a4 b4}
600 @separate
601 @example 
602
603         d4 g, g |
604  
605 @end example
606 @cindex bar check
607 @cindex @code{|}
608 @cindex errors, finding 
609 Three more notes.  The @code{|} character is a ``bar check''.  LilyPond
610 will verify that bar checks are found at the start of a measure.  This can
611 help you track down typing errors.
612
613 @cindex alteration, chromatic
614 @cindex chromatic alteration
615 @separate
616 @example 
617
618         c8 d e fis
619
620 @end example 
621 So far, no notes were chromatically altered.  Here is the first one that
622 is: @code{fis}.  Lilypond by default uses Dutch@footnote{Note names are
623 available in several languages, but we find the Dutch names quite
624 convenient.} note names, and ``Fis'' is the Dutch note name for ``F
625 sharp''.  However, there is no sharp sign in the output. The program
626 keeps track of key signatures, and will only print accidentals if they
627 are needed.
628
629 For groups of eighth notes and shorter, LilyPond can determine how the
630 notes should form a beam.  In this case, the 4 eights are automatically
631 printed as a beam.
632 @separate
633 @example 
634
635         c4 d8( )c b a( )b4 c8 b a g |
636  
637 @end example 
638 The beginning and ending notes of a slur are marked with parentheses,
639 @code{(} and @code{)} for start and end respectively.  The line above
640 indicates two slurs.  These slur markers (parentheses) are entered
641 between the slurred notes.
642 @separate
643 @example 
644
645         a4 [b8 a] [g fis] 
646  
647 @end example 
648 Automatic beaming can be overridden by inserting beam marks, @code{[}
649 and @code{]}.  These beam markers (brackets) are put around the notes
650 you want beamed.
651 @separate
652 @example 
653
654         g2.  |
655  
656 @end example
657 @cindex augmentation dot
658 @cindex dotted note
659 A period adds a dot to the note.
660 @separate
661 @example 
662
663         @}
664  
665 @end example 
666 The end of the sequential music to be repeated.  LilyPond will typeset a
667 repeat bar.
668 @separate
669 @example 
670
671         cis'4 b8 cis a4 |
672  
673 @end example 
674 Accidentals are printed whenever necessary: the first C sharp of the bar
675 will be printed with an accidental, the second one without.
676 @separate
677 @example 
678
679         a8-. b-. cis-. d-. e-. fis-.
680  
681 @end example
682 @cindex articulation
683 You can enter articulation signs either in a verbose form or using a
684 shorthand.  Here we demonstrate the shorthand: it is formed by a dash
685 and the character for the articulation to use, e.g. @code{-.} for
686 staccato as shown above.
687 @separate
688 @example 
689
690         fis a, r8 cis8
691  
692 @end example 
693  
694 Rests are denoted by the special notename @code{r}.  
695 @separate
696 @example 
697
698         d2.-\fermata
699  
700 @end example 
701 All articulations have a verbose form, like @code{\fermata}.  The
702 command @code{\fermata} is not part of the core of the language, but it
703 is a shorthand for a more complicated description of a fermata symbol.
704 @code{\fermata} names that description and is therefore called an
705 identifier.
706 @cindex identifier
707 @cindex @code{\fermata}
708 @separate
709 @example
710         \bar "|."
711         @}
712 @end example 
713 Here the music ends.  LilyPond does not automatically typeset and end
714 bar, we must explicitely request one, using @code{"|."}.
715
716 @separate
717 @example 
718
719         \paper @{
720                 linewidth = 14.0\cm
721         @}
722  
723 @end example 
724 The @code{\paper} block specifies how entered music should be converted
725 to notation output.  Most of the details of the conversion (font sizes,
726 dimensions, etc.) have been taken care of, but to fit the output in this
727 document, it has to be narrower.  We do this by setting the line width
728 to 14 centimeters (approximately 5.5 inches).
729 @separate
730 @example 
731
732         @}
733  
734 @end example 
735 The last brace ends the @code{\score} block.
736
737
738
739
740 @node Lyrics and chords
741 @section Lyrics and chords
742
743 In this section we show how to typeset a song. This file is
744 included as @file{flowing.ly}.
745
746 @example 
747 \header @{
748         title = "The river is flowing"
749         composer = "Traditional"
750 @}
751 \include "paper16.ly"
752 melody = \notes \relative c' @{
753         \partial 8
754         \key c \minor
755         g8 |
756         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
757         c4 c8 d [es () d] c4 | d4 es8 d c4.
758         \bar "|."
759 @}
760
761 text = \lyrics @{
762         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
763         ri -- ver is flo -- wing down to the sea.
764 @}
765
766 accompaniment =\chords @{
767         r8
768         c2:3- f:3-.7 d:min es4 c8:min r8
769         c2:min f:min7 g:7^3.5 c:min @}
770
771 \score @{
772         \simultaneous @{
773           %\accompaniment
774           \context ChordNames \accompaniment
775
776           \addlyrics
777             \context Staff = mel @{        
778               \property Staff.noAutoBeaming = ##t
779               \property Staff.automaticMelismata = ##t
780               \melody 
781             @}
782             \context Lyrics \text
783         @}
784         \midi  @{ \tempo 4=72 @}
785         \paper @{ linewidth = 10.0\cm @}
786 @} 
787 @end example 
788
789
790 The result would look this.@footnote{The titling and font size shown
791 may differ, since the titling in this document is not generated by
792 @code{ly2dvi}.}
793
794 @center @strong{The river is flowing}
795 @center Traditional 
796
797 @lilypond[center]
798 \header {
799         title = "The river is flowing"
800         composer = "Traditional"
801 }
802 \include "paper16.ly"
803 melody = \notes \relative c' {
804         \partial 8
805         \key c \minor
806         g8 |
807         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
808         c4 c8 d [es () d] c4 | d4 es8 d c4.
809         \bar "|."
810 }
811
812 text = \lyrics {
813         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
814         ri -- ver is flo -- wing down to the sea.
815 }
816
817 accompaniment =\chords {
818         r8
819         c2:3- f:3-.7 d:min es4 c8:min r8
820         c2:min f:min7 g:7^3.5 c:min }
821
822 \score {
823         \simultaneous {
824           %\accompaniment
825           \context ChordNames \accompaniment
826
827           \addlyrics
828             \context Staff = mel {
829               \property Staff.noAutoBeaming = ##t
830               \property Staff.automaticMelismata = ##t
831               \melody 
832             }
833             \context Lyrics \text
834         }
835         \midi  { \tempo 4=72 }
836         \paper { linewidth = 10.0\cm }
837 }
838 @end lilypond
839
840 Again, we will dissect the file line by line.
841 @separate
842 @example 
843
844         \header @{
845  
846 @end example
847 @cindex @code{\header}
848 Information about the music you are about to typeset goes into a
849 @code{\header} block.  The information in this block is not used by
850 LilyPond, but it is passed into the output.  @file{ly2dvi} uses this
851 information to print titles above the music.
852 @separate
853 @example 
854
855         title = "The river is flowing"
856         composer = "Traditional (?)"
857 @end example
858 @cindex assignments
859 @cindex identifier assignment
860 the @code{\header} block contains assignments.  In each assignment, a
861 variable is set to a value. Lexically, both the variable name and the
862 assigned value are strings. The values have to be quoted here, because
863 they contain spaces, the variable names could also be put within quotes
864 but it is not necessary. 
865 @separate
866 @example 
867
868         \include "paper16.ly"
869  
870 @end example
871 Smaller size for inclusion in a book.
872 @separate
873 @example 
874
875         melody = \notes \relative c' @{
876  
877 @end example 
878 The structure of the file will be the same as the previous one, a
879 @code{\score} block with music in it.  To keep things readable, we will
880 give names to the different parts of music, and use the names to
881 construct the music within the score block.
882
883 @separate
884 @example 
885         \partial 8
886 @end example 
887
888 @cindex @code{\partial}
889 @cindex anacrusis
890 The piece starts with an anacrusis of one eighth.
891 @separate
892 @example
893         \key c \minor
894 @end example
895 The key is C minor: we have three flats.
896
897 @separate
898 @example 
899
900         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
901         c4 c8 d [es () d] c4 | d4 es8 d c4.
902         \bar "|."
903  
904 @end example 
905
906 @cindex manual beaming
907 @cindex automatic beaming, turning off
908 We use explicit beaming.  Since this is a song,  we turn automatic
909 beams off, and use explicit beaming where needed.
910 @separate
911 @example 
912
913         @}
914  
915 @end example 
916 This ends the definition of @code{melody}.  
917
918 @separate
919 @example 
920
921         text = \lyrics @{
922  
923 @end example
924 @cindex lyrics
925 @cindex identifier assignment
926 @cindex syllables, entering
927 Another identifier assignment.  This one is for the lyrics. 
928 Lyrics are formed by syllables that have duration, and not by
929 notes. To make LilyPond parse words as syllables,  switch it  into
930 lyrics mode with @code{\lyrics}.  Again, the brace after @code{\lyrics}
931 is a shorthand for @code{\sequential @{}.
932 @separate
933 @example 
934
935   The4 ri -- ver is flo- __ wing,  flo -- wing and gro -- wing, the
936   ri- ver is flo- __ wing down to the sea.
937 @}
938  
939 @end example
940 @cindex extenders, lyric
941 @cindex hyphens, lyric 
942 The syllables  themselves are  separated by spaces.  You can get syllable
943 extenders by entering @code{__}, and centered hyphens with
944 @code{-}@code{-}.  We enter the syllables as if they are all quarter notes
945 in length (hence the @code{4}), and use a feature to align the
946 syllables to the music, which obviously isn't all quarter notes.
947 @separate
948 @example 
949
950         accompaniment =\chords @{
951  
952 @end example
953 @cindex chords
954 @cindex mode, chords
955 We'll put chords over the music. To enter them, there is a special mode
956 analogous to @code{\lyrics} and @code{\notes} mode, where you can give
957 the names of the chords you want, instead of listing the notes
958 comprising the chord.
959 @separate
960 @example 
961
962         r8
963  
964 @end example 
965 There is no accompaniment during the anacrusis.
966 @separate
967 @example 
968
969         c2:3- f:3-.7
970  
971 @end example
972
973 @cindex tonic
974 @cindex chord modifier
975 @cindex modifier, chord 
976 A chord is started by  the tonic of the chord. The
977 first one lasts a half note.  An unadorned note creates a major
978 triad. Since a minor triad is wanted, @code{3-} is added to modify the
979 third to be small. @code{7} modifies (adds) a seventh, which is small by
980 default to create the @code{f a c es} chord.  Multiple modifiers must be
981 separated by dots.
982 @separate
983 @example 
984
985         d:min es4 c8:min r8
986  
987 @end example
988
989 Some modifiers have predefined names, eg. @code{min} is  the same as
990 @code{3-}, so @code{d-min} is a minor @code{d} chord.
991 @separate
992 @example 
993
994         c2:min f:min7 g:7^3.5 c:min @}
995  
996 @end example
997 @cindex named modifier
998
999 A named modifier @code{min} and a normal modifier @code{7} do not have
1000 to be separated by a dot.  Tones from a chord are removed with chord
1001 subtractions.  Subtractions are started with a caret, and they are
1002 also separated by dots.  In this example, @code{g:7^3.5} produces a
1003 minor seventh.  The brace ends the sequential music.
1004 @separate
1005 @example 
1006
1007         \score @{
1008                 \simultaneous @{
1009  
1010 @end example 
1011 We assemble the music in the @code{\score} block.  Melody, lyrics and
1012 accompaniment have to sound at the same time, so they should be
1013 @code{\simultaneous}.
1014 @cindex @code{\simultaneous}
1015 @separate
1016 @example 
1017
1018         %\accompaniment
1019  
1020 @end example 
1021 Chord mode generates notes grouped in @code{\simultaneous} music.  If
1022 you remove the comment sign, you can see the chords in normal
1023 notation: they will be printed as note heads on a separate
1024 staff. To print them as chords names, they have to be interpreted as
1025 being chords, not notes. This is done with the following command:  
1026 @separate
1027 @example 
1028
1029         \context ChordNames \accompaniment
1030  
1031 @end example
1032 @cindex context
1033 @cindex interpretation context
1034 @cindex notation context
1035
1036
1037 Normally, the notes that you enter are transformed into note heads.
1038 Note heads alone make no sense, they need surrounding information: a key
1039 signature, a clef, staff lines, etc.  They need @emph{context}.  In
1040 LilyPond, these symbols are created by objects called `interpretation
1041 contexts'.  Interpretation contexts exist for generating notation
1042 (`notation context') and for generating sound (`performance
1043 context'). These objects only exist during a run of LilyPond.
1044
1045 By default, LilyPond will create a Staff context for you.  If you would
1046 remove the @code{%} sign in the previous line, you would see that
1047 mechanism in action.
1048
1049 We don't want that default here, because we want chord names.  The
1050 command above explicitly creates an interpretation context of 
1051 @code{ChordNames} type to interpret the music @code{\accompaniment}. 
1052 @separate
1053 @example 
1054
1055         \addlyrics
1056  
1057 @end example
1058 @cindex @code{\addlyrics}
1059 @cindex lyrics and melody, combining
1060 @cindex combining lyrics and melody
1061
1062 The lyrics should be aligned with the melody.  This is done by
1063 combining both with @code{\addlyrics}.  @code{\addlyrics} takes two
1064 pieces of music (usually a melody and lyrics, in that order) and
1065 aligns the syllables of the second piece under the notes of the
1066 first piece.  If you would reverse the order, the notes would be
1067 aligned on the lyrics, which is not very useful, and looks
1068 silly.
1069 @separate
1070 @example 
1071
1072         \context Staff = mel @{
1073  
1074 @end example
1075
1076 The second argument of @code{\addlyrics} is the melody.  We instantiate
1077 a @code{Staff} context explicitly: should you choose to remove the
1078 comment before the ``note heads'' version of the accompaniment, the
1079 accompaniment will be on a nameless staff.  The melody has to be on
1080 staff different from the accompaniment.  This is accomplished by giving
1081 the melody and accompaniment staffs different names.
1082 @separate
1083 @example 
1084
1085         \property Staff.noAutoBeaming = ##t
1086  
1087 @end example
1088 @cindex \property
1089 @cindex context variables
1090 @cindex setting context variables
1091 An interpretation context has variables, called properties, that tune
1092 its behaviour.  One of the variables is @code{noAutoBeaming}.  Setting
1093 this Staff's property to @code{##t}, which is the boolean value @var{true},
1094 turns the automatic beaming mechanism off for the current staff.
1095 @cindex GUILE
1096 @cindex Scheme
1097 @cindex accessing Scheme
1098 @cindex evaluating Scheme
1099 @cindex LISP
1100
1101 LilyPond internally uses GUILE, a Scheme-interpreter. Scheme is a
1102 language from the LISP family. You can learn more about Scheme at
1103 @uref{http://www.scheme.org}. It is used to represent data throughout
1104 the whole program. The hash-sign (@code{#}) accesses GUILE directly: the
1105 code following the hash-sign is evaluated as Scheme.  The boolean value
1106 @var{true} is @code{#t} in Scheme, so for LilyPond @var{true} looks like
1107 @code{##t}.
1108
1109 If Scheme scares you, don't worry. You don't need to know Scheme to
1110 create beautiful sheet music.
1111
1112
1113
1114 @separate
1115 @example 
1116
1117         \property Staff.automaticMelismata = ##t
1118  
1119 @end example
1120 @cindex automaticMelismata
1121 @cindex melismata
1122 @cindex @code{\addlyrics} and slurs
1123 Similarly, we  don't want to print a  syllable when there is
1124 a slur. This sets up @code{\addlyrics} to not put lyrics under each
1125 separate note while there is a slur.
1126 @separate
1127 @example 
1128
1129           \melody
1130         @}
1131  
1132 @end example 
1133 Finally, we put the melody on the current staff.  Note that the
1134 @code{\property} directives and @code{\melody} are grouped in sequential
1135 music,  so the property settings are done before the melody is
1136 processed.
1137 @separate
1138 @example 
1139
1140         \context Lyrics \text
1141  
1142 @end example 
1143 The second argument of @code{\addlyrics} is the text. The text also
1144 should not land on a Staff, but on a interpretation context for
1145 syllables, extenders, hyphens etc.  This context is called
1146 Lyrics.
1147 @separate
1148 @example 
1149
1150         \midi  @{ \tempo 4=72@}
1151  
1152 @end example 
1153 MIDI (Musical Instrument Digital Interface) is a standard for
1154 connecting and recording digital instruments. So a MIDI file is like a
1155 tape recording of an instrument. The @code{\midi} block causes makes the
1156 music go to a MIDI file, so you can listen to the music you entered.  It
1157 is great for checking the music.  Whenever you hear something weird, you
1158 probably hear a typing error.
1159
1160 Syntactically, @code{\midi} is similar to @code{\paper @{ @}}, since it
1161 also specifies an output method. You can specify the tempo using the
1162 @code{\tempo} command, in this case the tempo of quarter notes is set to
1163 72 beats per minute.
1164 @separate
1165 @example 
1166
1167         \paper @{ linewidth = 10.0\cm @}
1168  
1169 @end example 
1170 We also want notation output.  The linewidth is short so the piece
1171 will be set in two lines.
1172
1173 @node More movements 
1174 @section More movements
1175
1176 [FIXME: merge here with, or move this to: Other ways to run LilyPond]
1177
1178 You probably ran @file{ly2dvi} on the last example, and ended up with a
1179 viewable @file{.dvi} file.  However, between there are a few steps of
1180 which LilyPond is only one. To enhance your understanding of what's
1181 happening under the hood when you run @code{ly2dvi}, we explain what
1182 programs are run.
1183
1184 @code{ly2dvi} is a program that calls a number of programs  in sequence.
1185 The first thing it does, is running LilyPond on the input file. After
1186 some calculations, a @file{.tex} is produced. The contents
1187 of this file are very  low-level instructions.
1188
1189 For example,  the following file (@file{miniatures.ly}) 
1190
1191 @example
1192 \version "1.3.124"
1193 \header @{
1194   title = "Two miniatures"
1195   tagline = "small is beautiful"
1196 @}
1197
1198 #(set! point-and-click line-column-location)
1199
1200 \paper @{ linewidth = -1.0 @}
1201
1202 \score @{
1203     \notes @{ c'4 d'4 @}
1204     \header @{
1205         opus = "Opus 1."
1206         piece = "Up" @}
1207 @}
1208 \score @{
1209     \notes @{ d'4 c'4 @}
1210     \header @{
1211         opus = "Opus 2."
1212         piece = "Down" @}
1213 @}
1214 @end example
1215
1216 The titling in this manual was not generated by ly2dvi, so we can't
1217 exactly show it would look, but the result should resemble this:
1218
1219 @center @strong{Two miniatures}
1220 @flushright
1221 Opus 1.
1222 @end flushright
1223 @flushleft
1224 @var{Up}
1225 @end flushleft
1226 @lilypond
1227   \score {
1228     \notes { c'4 d'4 }
1229     \paper { linewidth = -1.0 }
1230   }
1231 @end lilypond
1232 @flushright
1233 Opus 2.
1234 @end flushright
1235 @flushleft
1236 @var{Down}
1237 @end flushleft
1238 @lilypond
1239   \score {
1240     \notes { d'4 c'4 }
1241     \paper { linewidth = -1.0 }
1242   }
1243 @end lilypond
1244
1245 This file is produced by ly2dvi in a few stages, with the help of text
1246 formatting tools. LilyPond produces two output files,
1247 @file{miniatures.tex} and @file{miniatures-1.tex}.  Both files contain
1248 only graphical music notation. @file{ly2dvi} looks at what output
1249 LilyPond produces, and adds page layout and titling to those files.  The
1250 result is a DVI file called @file{miniatures.dvi}.
1251
1252 Next, now we'll look at the example line by line to explain new things.
1253
1254 @separate
1255 @example 
1256 \version "1.3.124"
1257 @end example 
1258 Lilypond and its language are still under development, and occasionally,
1259 details of the syntax are changed. This fragment indicates for which
1260 version the input file was written. When you compile this file, the
1261 version number will be checked, and you will get a warning when the file
1262 is too old.
1263
1264 This version number is also used by the @code{convert-ly} program (See
1265 @ref{convert-ly}), which uses it to update the file to the latest lily
1266 version.
1267
1268 @separate
1269 @example
1270   \header @{
1271     title = "Two miniatures"  @}
1272 @end example
1273 This sets the titling information for the entire file.
1274 @separate
1275 @example
1276     tagline = "small is beautiful" 
1277 @end example
1278 A signature line is printed at the bottom of the last page.
1279  This signature is produced from the @code{tagline} field of
1280 @code{\header}.  Many people find the default "Lily was here,
1281 @var{version number}" too droll. If that is the case,  assign
1282 something else to @code{tagline}, as shown above.
1283 @separate
1284 @example
1285         #(set! point-and-click line-column-location)
1286 @end example
1287
1288 This piece of Scheme code sets the Scheme variable
1289 @code{point-and-click} to the value @var{line-column-location} (which
1290 itself is a Scheme procedure).
1291
1292 Editing input files can be quite complicated if you're working with
1293 large files: if you're digitizing existing music, you have to
1294 synchronize the .ly file, the sheet music on your lap and the sheet
1295 music on the screen.  The point-and-click mechanism makes it easy to
1296 find the origin of an error in the LY file: when you view the file with
1297 Xdvi and click on a note, your editor will jump to the spot where that
1298 note was entered.  For more information, see @ref{Point and click}.
1299
1300 @separate
1301 @example
1302   \paper @{ 
1303 @end example
1304
1305 The @code{\score} blocks that follow in the file don't have
1306 @code{\paper} sections, so the settings of this block are substituted: A
1307 paper block, at top-level, i.e. not in a @code{\score} block sets the
1308 default page layout.
1309
1310 @separate
1311 @example
1312   linewidth = -1.0 @}
1313 @end example
1314
1315
1316
1317 The variable @code{linewidth} normally sets the length of the systems on
1318 the page. However, a negative value has a special meaning. If
1319 @code{linewidth} is less than 0, no line breaks are inserted into the
1320 score, and the spacing is set to natural length: a short phrase takes up
1321 little space, a longer phrase more space.
1322
1323 @separate
1324 @example
1325   \score @{
1326     \notes @{ c'4 d'4 @}
1327 @end example
1328
1329 In previous examples, notes were specified in relative octaves,
1330 i.e. each note was put in the octave that would put it closest to its
1331 predecessor. Besides relative, there is also absolute octave
1332 specification, which you get when you don't specify @code{\relative}. In
1333 this input mode, the central C is denoted by @code{c'}. Going down, you
1334 get @code{c} @code{c,} @code{c,,} etc.  Going up, you get @code{c''}
1335 @code{c'''} etc.
1336
1337 When you're copying music from existing sheet music, relative octaves
1338 are probably the easiest to use: it's less typing work and errors are
1339 easily spotted. However, if you write LilyPond input directly, either by
1340 hand (i.e. composing) or by computer, absolute octaves are easier to use.
1341
1342
1343 @separate
1344 @example
1345     \header @{
1346 @end example
1347
1348 The @code{\header} is normally at the top of the file, where it sets
1349 values for the rest of the file. If you want to typeset different pieces
1350 from one file (for example, if there are multiple movements, or if
1351 you're making an exercise book), you can put different @code{\score}
1352 blocks into the input file. ly2dvi will assemble all LilyPond output
1353 files into a big document. The contents of \header blocks specified
1354 within each score, are used for the titling of each movement.
1355 @separate
1356 @example
1357         opus = "Opus 1."
1358         piece = "Up" @}
1359 @end example
1360 For example, the Opus number is put at the right, and the piece string
1361 will be at the left.
1362
1363
1364
1365 @node A piano excerpt
1366 @section A piano excerpt
1367
1368 Our fourth subject is a piece of piano music.  The fragment in the input
1369 file is a piano reduction of the G major Sinfonia by Giovanni Battista
1370 Sammartini.  It was composed around 1740.  It's in the source package
1371 under  the name @file{sammartini.ly}.
1372
1373 @lilypond[verbatim]
1374 \include "paper16.ly"
1375
1376 stemDown = \property Voice.Stem \override #'direction = #-1
1377 stemUp = \property Voice.Stem \override #'direction = #1
1378 stemBoth = \property Voice.Stem \revert #'direction  
1379
1380 viola = \notes \relative c' \context Voice = viola {
1381     <c4-\f-\arpeggio g' c>
1382     \stemDown g'8. b,16
1383     s1 s2. r4
1384     g
1385 }
1386
1387 oboes = \notes \relative c'' \context Voice = oboe {
1388     \stemUp s4  g8. b,16 c8 r <e'8.^\p g> <f16 a>
1389     \grace <e8( g> <d4 )f> <c2 e>
1390     \times 2/3 { <d8 \< f> <e g> <f a> }
1391     <
1392         { \times 2/3 { a8 g c } \! c2 }
1393         \context Voice = oboeTwo {
1394             \stemDown
1395             \grace {
1396                 \property Grace.Stem \override #'direction = #-1
1397                 [f,16 g] }
1398             f8 e e2
1399         }
1400     >
1401     \stemBoth
1402     \grace <c,8( e> <)b8. d8.-\trill> <c16 e> | 
1403     [<d ( f> < )f8. a>] <)b,8 d> r [<d16( f> <f8. )a>] <b,8 d> r  |
1404     [<c16( e>  < )e8. g>] <c8 e,>
1405 }
1406
1407 hoomPah = \repeat unfold 8 \notes
1408     \transpose c' { \stemUp c8 \stemBoth \stemDown c'8 \stemBoth }
1409
1410 bassvoices = \notes \relative c' {
1411     c4 g8. b,16
1412     \autochange Staff \hoomPah
1413     \translator Staff = down
1414     \stemDown [c8 c'8] r4
1415     <g d'> r4
1416     < {\stemUp r2 <e4 c'> <c8 g'> }
1417         \context Voice = reallyLow  {\stemDown g2 ~ | g4 c8 } >
1418 }
1419
1420 \score {
1421     \context PianoStaff \notes <
1422         \context Staff = up < \time 2/2
1423             \viola
1424             \oboes
1425         >
1426         \context Staff = down < \time 2/2 \clef bass
1427             \bassvoices
1428         >
1429     >
1430     \midi { }
1431     \paper {
1432         indent = 0.0
1433         linewidth = 15.0 \cm }
1434 }
1435 @end lilypond
1436
1437 If this looks like incomprehensible gibberish to you, you are right.
1438 This example has been doctored to have as many quirks as possible.
1439
1440 As you can see, this example features multiple voices on one staff.  To
1441 make room for those voices, their notes have to be stemmed in opposite
1442 directions.
1443
1444 Printed symbols are internally represented by so-called Graphical
1445 Objects (more colloquially: Grobs).  These statements concern the
1446 grob called `Stem'. Each grob is described by a bunch of settings. These
1447 setting determine the fonts, offsets, sub-routines to be called on the
1448 grob, etc.  The initial values of these settings are set in the Scheme
1449 file @file{scm/grob-description.scm}.
1450
1451 @separate
1452 @example
1453   stemDown = \property Voice.Stem \override #'direction = #-1
1454 @end example
1455
1456 Set a proprerty for all Stem grobs in the current Voice:
1457 @code{direction} is set to @code{-1}, which encodes down.  The setting
1458 remains in effect until it is reverted.
1459
1460 @separate
1461 @example
1462  \property Voice.Stem \revert #'direction  
1463 @end example
1464
1465 Revert the to the previous setting.  The effect of precisely one
1466 @code{\stemDown} or @code{\stemUp} is neutralised.
1467
1468
1469 LilyPond includes the identifiers @code{\stemUp}, @code{\stemDown} along
1470 with some other commonly used formatting instructions, but to explain how
1471 it works, we wrote our own here.  Of course, you should use predefined
1472 identifiers like these if possible: then you will be affected less by
1473 the implementation changes we occasionally make.
1474
1475 @separate
1476 @example 
1477 viola = \notes \relative c'  \context Voice = viola @{ 
1478 @end example 
1479 In this example, you can see multiple parts on a staff.  Each part is
1480 associated with one notation context.  This notation context handles
1481 stems and dynamics (among others).  The name of this context is
1482 @code{Voice}.  For each part we have to make sure that there is
1483 precisely one @code{Voice} context, so we give it an unique name
1484 (`@code{viola}').
1485
1486 @separate
1487 @example 
1488 <c4-\f-\arpeggio g' c>
1489 @end example 
1490 The delimiters @code{<} and @code{>} are shorthands for
1491 @code{\simultaneous @{} and @code{@}}. The expression enclosed in
1492 @code{<} and @code{>} is a chord.
1493
1494 @cindex dynamics
1495 @cindex loudness
1496 @cindex forte
1497 @cindex arpeggio
1498
1499 @code{\f} places a forte symbol under the chord. The forte applies to
1500 the whole chord, but the syntax requires that commands like forte and
1501 arpeggio are attached to a note, so here we attach them to the first
1502 note.
1503
1504 @code{\arpeggio} typesets an arpeggio sign (a wavy vertical line) before
1505 the chord.
1506
1507 @separate
1508 @example 
1509    \stemDown
1510 @end example 
1511
1512
1513 @separate
1514 @example 
1515         g'8. b,16 
1516 @end example 
1517 Relative octaves work a little differently with chords.  The starting
1518 point for the note following a chord is the first note of the chord.  So
1519 the @code{g} gets an octave up quote: it is a fifth above the starting
1520 note of the previous chord (the central C).
1521
1522 @separate
1523 @example 
1524 s1 s2. r4 
1525 @end example 
1526 @code{s} is a spacer rest.  It does not print anything, but it does have
1527 the duration of a rest. It is useful for filling up voices that
1528 temporarily don't play. In this case, the viola doesn't come until one
1529 and a half measure later.
1530
1531 @separate
1532 @example 
1533 oboes = \notes \relative c'' \context Voice = oboe @{ 
1534 @end example 
1535 Now comes a part for two oboes.  They play homophonically, so we
1536 print the notes as one voice that makes chords. Again, we insure that
1537 these notes are indeed processed by precisely one context with
1538 @code{\context}.
1539 @separate
1540 @example 
1541 \stemUp s4  g8. b,16 c8 r <e'8.-\p g> <f16 a> 
1542 @end example 
1543 @code{\stemUp} is a reference to the @code{\property \override} command
1544 defined above. 
1545 @separate
1546 @example 
1547 \grace <e8 g> < d4 f> <c2 e> 
1548 @end example
1549 @cindex @code{\grace}
1550 @cindex ornaments
1551 @cindex grace notes
1552
1553 @code{\grace} introduces grace notes.  It takes one argument, in this
1554 case a chord.
1555
1556 @ignore
1557 The slur started on the @code{e} of the chord
1558 will be attached to the next note.@footnote{LilyPond will squirm
1559 about unended Slurs.  In this case, you can ignore the warning}.
1560 @end ignore
1561 @separate
1562 @example 
1563 \times 2/3 
1564 @end example
1565 @cindex tuplet
1566 @cindex triplets
1567 Tuplets are made with the @code{\times} keyword.  It takes two
1568 arguments: a fraction and a piece of music.  The duration of the piece
1569 of music is multiplied by the fraction.  Triplets make notes occupy 2/3
1570 of their notated duration, so in this case the fraction is 2/3.
1571 @separate
1572 @example 
1573 @{ <d8 \< f> <e g> <f a> @} 
1574 @end example 
1575 The piece of music to be `tripletted' is sequential music containing
1576 three notes.  On the first chord, a crescendo is started with
1577 @code{\<}. To be precise, the crescendo start is syntactically attached
1578 to the preceding note, the @code{d}.
1579
1580 @cindex dynamics
1581 @cindex crescendo
1582 @cindex @code{\<}
1583
1584 @separate
1585 @example 
1586
1587 @end example 
1588 At this point, the homophonic music splits into two rhythmically
1589 different parts.  We can't use a sequence of chords to enter this, so
1590 we make a `chord' of sequences to do it.  We start with the upper
1591 voice, which continues with upward stems:
1592 @separate
1593 @example 
1594  @{ \times 2/3 @{ a8 g c @} \! c2 @} 
1595 @end example
1596
1597 @cindex @code{\!}
1598
1599 The crescendo is ended at the half note by the escaped exclamation
1600 mark @code{\!}.
1601 @separate
1602 @example 
1603 \context Voice = oboeTwo @{
1604 \stemDown 
1605 @end example 
1606 We can't share stems with the other voice, so we have to create a new
1607 @code{Voice} context.  We give it the name @code{oboeTwo} to distinguish
1608 it from the other context.  Stems go down in this voice.
1609 @separate
1610 @example 
1611 \grace @{  
1612 @end example
1613 @cindex Grace context
1614 When a grace section is processed, a @code{Grace} context is
1615 created. This context acts like a miniature score of its own.  It has
1616 its own time bookkeeping, and you can make notes, beams, slurs
1617 etc. Here we fiddle with a property and make a beam.  The argument of
1618 @code{\grace} is sequential music.
1619
1620 @separate
1621 @example 
1622 \property Grace.Stem \override #'direction = #-1
1623 [f,16 g] @}
1624 @end example 
1625
1626 Normally, grace notes are always stem up, but in this case, the upper
1627 voice interferes. We set the stems down here.
1628
1629 As far as relative mode is concerned, the previous note is the
1630 @code{c'''2} of the upper voice, so we have to go an octave down for
1631 the @code{f}.
1632 @separate
1633 @example 
1634
1635   f8 e e2
1636 @} > 
1637 @end example 
1638 This ends the two-part section.
1639 @separate
1640 @example 
1641 \stemBoth
1642 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |  
1643 @end example
1644 @cindex trill
1645 @cindex stemBoth
1646
1647 @code{\stemBoth} ends the forced stem directions. From here, stems are
1648 positioned as if it were single part music.
1649
1650 The bass has a little hoom-pah melody to demonstrate parts switching
1651 between staffs.  Since it is repetitive, we use repeats:
1652 @separate
1653 @example 
1654 hoomPah  =  \repeat unfold 8
1655 @end example
1656 @cindex unfolded @code{\repeat}
1657 The unfolded repeat prints the notes in its argument as if they were
1658 written out in full eight times.
1659 @separate
1660 @example
1661 \notes \transpose c' @{
1662 @end example
1663 @cindex transposing
1664 @cindex relative mode and transposing
1665
1666 Transposing can be done with @code{\transpose}.  It takes two arguments
1667 the first specifies what central C should be transposed to.  The second
1668 is the to-be-transposed music.  As you can see, in this case, the
1669 transposition has no effect, as central C stays at central C.
1670
1671 The purpose of this no-op is circumventing relative mode.  Relative mode
1672 can not be used together with transposition, so @code{\relative} will
1673 leave the contents of @code{\hoomPah} alone.  We can use it without
1674 having to worry about getting the motive in a wrong octave.
1675 @separate
1676 @example 
1677 bassvoices = \notes \relative c' @{
1678 c4 g8. b,16
1679 \autochange Staff \hoomPah 
1680 @end example
1681 @cindex staff switch, automatic
1682 @cindex cross staff voice, automatic
1683 @cindex @code{\autochange}
1684
1685 Voices can switch between staffs. The easiest way to get this, is to use
1686 @code{\autochange}. This command looks at the pitch of each note, and if
1687 necessary, will cross to the other staff. For this to work, the two
1688 staffs must be called @code{"up"} and @code{"down"}.
1689 @separate
1690 @example
1691         \translator Staff = down
1692 @end example
1693 @cindex staff switch
1694 @cindex cross staff voice
1695 We want the remaining part of this melody on the lower staff, so we do a
1696 manual staff switch here.
1697
1698
1699 @separate
1700 @example 
1701 \context Voice = reallyLow  @{\stemDown g2 ~ | g4 c8 @} > 
1702 @end example
1703 @cindex tie
1704 @cindex @code{~}
1705 After skipping some lines, we see @code{~}.  This mark makes ties.  Note
1706 that ties and slurs are different things.  A tie can only connect two
1707 note heads of the same pitch, whereas a slur can connect many chords
1708 with one curve.
1709
1710 @separate
1711 @example 
1712 \context PianoStaff 
1713 @end example 
1714  A special context is needed to get cross staff beaming right.  This
1715 context is called @code{PianoStaff}.
1716 @separate
1717 @example 
1718 \context Staff = bottom < \time 2/2 \clef bass 
1719 @end example 
1720 The bottom staff must have a different clef.
1721 @separate
1722 @example 
1723 indent = 0.0 
1724 @end example 
1725 To make some more room on the line, the first (in this case the only)
1726 line is not indented.  The line still looks very cramped, but that is due
1727 to the page layout of this document.
1728
1729
1730 @ignore
1731 [TODO:
1732
1733 * font-size, multi-stanza.
1734
1735 * Simple part combining in a Hymn
1736 @end ignore
1737
1738
1739 @node An orchestral score
1740 @section An orchestral score
1741
1742 @menu
1743 * The full score::              
1744 * Extracting an individual part::  
1745 @end menu
1746
1747
1748 Our last two examples show a way to setup the music for an orchestral
1749 score.  When typesetting a piece for several instruments, you'll want to
1750 create a conductor's full score, alongside several individual parts.
1751
1752 LilyPond is well suited for this task.  We will declare the music for
1753 each instrument individually, giving the music of each instrument its
1754 own name.  These pieces of music are then combined in different
1755 @code{\score} blocks to produce different combinations of the score.
1756
1757 This orchestral score example consists of three input files.  In the
1758 first file, @file{os-music.ly}, we define the music for all instruments.
1759 This file will be used both for producing the score and the separate
1760 parts.
1761
1762 If you were to run lilypond on this file, no printable output would be
1763 produced.
1764
1765 @example
1766 % os-music.ly
1767 \header @{
1768   title = "Zo, goed lieverd?"
1769   subtitle = "How's, this babe?"
1770   composer = "JCN"
1771   opus = "1"
1772   piece = "Laid back"
1773 @}
1774 global = @{
1775   \time 2/4
1776   \skip 2*4 \bar "|."
1777 @}
1778 Key = \notes \key as \major
1779 flautoI = \notes\relative c'' @{
1780   f8 g f g f g f g
1781   bes as bes as bes as bes as
1782 @}
1783 flautoII = \notes\relative c'' @{
1784   as8 bes as bes R1 d4 ~ d
1785 @}
1786 tromboI = \notes\relative c'' @{
1787   c4. c8 c8 c4. es4 r as, r
1788 @}
1789 tromboII = \notes\relative c'' @{
1790   as4. as8 as8 as4. R1*1/2 as4 es'
1791 @}
1792 timpani = \notes\relative c, @{
1793   \times 2/3 @{ f4 f f @}
1794   \times 4/5 @{ as8 as as as as @}
1795   R1
1796 @}
1797 corno = \notes\relative c' @{
1798    bes4 d f, bes d f, bes d
1799 @}
1800 @end example
1801
1802 We will not go through the input line by line, but only indicate and
1803 explain the new elements.
1804
1805
1806 @separate
1807 @example
1808 global = @{
1809   \time 2/4
1810   \skip 2*4 \bar "|.";
1811 @}
1812 @end example
1813
1814 Declare setting to be used globally.  The @code{\skip} command produces
1815 no output, but moves forward in time: in this case, the duration of a
1816 half note (@code{2}), and that four times (@code{*4}).  This brings us
1817 to the end of the piece, and we can set the end bar.
1818
1819 @separate
1820 @example
1821 Key = \notes \key as \major
1822 @end example
1823 Declare the key signature of the piece and assign it to the identifier
1824 @var{Key}.  Lateron, we'll use @code{\Key} for all staffs except those
1825 for transposing instruments.
1826
1827 @node The full score
1828 @subsection The full score
1829
1830
1831 The second file, @file{os-score.ly} reads the definitions of the first
1832 (@file{os-music.ly}), and defines the @code{\score} block for the full
1833 conductor's score.
1834
1835
1836 @example
1837 % os-score.ly
1838 \include "os-music.ly"
1839 \include "paper13.ly"
1840
1841 #(set! point-and-click line-column-location)
1842 #(define text-flat '((font-relative-size . -2)
1843          (music "accidentals--1")))
1844
1845 \score @{
1846   <
1847     \global
1848     \property Score.BarNumber \override #'padding = #3
1849     \context StaffGroup = woodwind <
1850       \context Staff = flauti <
1851         \property Staff.midiInstrument = #"flute"
1852         \property Staff.instrument = "2 Flauti"
1853         \property Staff.instr = "Fl."
1854         \Key
1855         \context Voice=one @{ \voiceOne \flautoI @}
1856         \context Voice=two @{ \voiceTwo \flautoII @}
1857       >
1858     >
1859     \context StaffGroup = timpani <
1860       \context Staff = timpani <
1861         \property Staff.midiInstrument = #"timpani"
1862         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
1863         \property Staff.instr = #"Timp."
1864         \clef bass
1865         \Key
1866         \timpani
1867       >
1868     >
1869     \context StaffGroup = brass <
1870       \context Staff = trombe <
1871         \property Staff.midiInstrument = #"trumpet"
1872         \property Staff.instrument = #`(lines "2 Trombe" "(C)")
1873         \property Staff.instr = #`(lines "Tbe." "(C)")
1874         \Key
1875         \context Voice=one \partcombine Voice
1876           \context Thread=one \tromboI
1877           \context Thread=two \tromboII
1878       >
1879       \context Staff = corni <
1880         \property Staff.midiInstrument = #"french horn"
1881         \property Staff.instrument = #`(lines "Corno"
1882           (columns "(E" ,text-flat ")"))
1883         \property Staff.instr = #`(lines "Cor."
1884           (columns "(E" ,text-flat ")"))
1885         \property Staff.transposing = #3
1886         \notes \key bes \major
1887         \context Voice=one \corno
1888       >
1889     >
1890   >
1891   \paper @{
1892     indent = 15 * \staffspace
1893     linewidth = 60 * \staffspace
1894     textheight = 90 * \staffspace
1895     \translator@{
1896       \VoiceContext
1897       \consists "Multi_measure_rest_engraver"
1898     @}
1899     \translator@{
1900       \HaraKiriStaffContext
1901       \remove "Multi_measure_rest_engraver"
1902     @}
1903   @}
1904   \midi @{
1905     \tempo 4 = 75
1906   @}
1907 @}
1908 @end example
1909
1910 @center @strong{Zo, goed lieverd?}
1911 @sp 1
1912 @center How's, this babe?
1913 @flushright
1914 Opus 1.
1915 @end flushright
1916 @flushleft
1917 @sc{Laid back}
1918 @end flushleft
1919
1920 @lilypondfile{os-score.ly}
1921
1922 @separate
1923 @example
1924 \include "os-music.ly"
1925 @end example
1926 First, we need to include the music definitions we made in
1927 @file{os-music.ly}.
1928
1929 @separate
1930 @example
1931 #(set! point-and-click line-column-location)
1932 @end example
1933 In a large orchestral score like this you're bound to make some small
1934 mistakes, so we enable point and click (See @ref{Point and click})
1935 editing.
1936
1937 @separate
1938 @example
1939 #(define text-flat '((font-relative-size . -2)
1940          (music "accidentals--1")))
1941 @end example
1942
1943 When naming the tuning of the french horn, we'll need a piece of text
1944 with a flat sign.  LilyPond has a mechanism for font selection and
1945 kerning called Scheme markup text (See @ref{Text markup}).  The flat
1946 sign is taken from the music font, and its name is @code{accidentals--1}
1947 (The sharp sign is called @code{accidentals-+1}).  The default font is
1948 too big for text, so we select a relative size of @code{-2}.
1949
1950 @separate
1951 @example
1952   <
1953     \global
1954 @end example
1955 Of course, all staffs are simultaneous and use the same global settings.
1956
1957 @separate
1958 @example
1959     \property Score.BarNumber \override #'padding = #3
1960 @end example
1961 LilyPond prints bar numbers at the start of each line, but
1962 unfortunately, they end up a bit too close to the staff in this example.
1963 A bar number internally is a Grob called @var{BarNumber}.  BarNumber
1964 Grobs can be manipulated through their @var{side-position-interface}.  One
1965 of the properties of a @var{side-position-interface} that can be tweaked
1966 is the @var{padding}: the amount of extra space that is put between this
1967 Grob and other Grobs.  We set the padding to three staff spaces.
1968
1969 You can find all this kind of information in LilyPond's automatically
1970 generated documentation in
1971 @ifnottex
1972 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}.
1973 @end ifnottex
1974 @iftex
1975 the online documentation.
1976 @end iftex
1977
1978 @separate
1979 @example
1980     \context StaffGroup = woodwind <
1981       \context Staff = flauti <
1982 @end example
1983 A new notation context: the StaffGroup.  StaffGroup can hold one or more
1984 Staffs, and will print a big bracket at the left of the score.  Start a
1985 new staff group for the woodwind section (just the flutes in this case).
1986 Immediately after that, we start the staff for the two flutes, that also
1987 play simultaneously.
1988
1989 @separate
1990 @example
1991         \property Staff.midiInstrument = #"flute"
1992 @end example
1993 Specify the instrument for MIDI output (see @ref{MIDI instrument
1994 names}).
1995
1996 @separate
1997 @example
1998         \property Staff.instrument = "2 Flauti"
1999         \property Staff.instr = "Fl."
2000 @end example
2001 And define the instrument names to be printed in the margin,
2002 @code{instrument} for the first line of the score, @code{instr} for the
2003 rest of the score.
2004
2005 @separate
2006 @example
2007         \Key
2008 @end example
2009 The flutes play in the default key.
2010
2011 @separate
2012 @example
2013         \context Voice=one @{ \voiceOne \flautoI @}
2014         \context Voice=two @{ \voiceTwo \flautoII @}
2015 @end example
2016 Last come the actual flute parts.  Remember that we're still in
2017 simultaneous mode.  We name both voices differently, so that LilyPond
2018 will actually create two Voice contexts.  The flute parts are simple, so
2019 we specify manually which voice is which: @code{\voiceOne} forces the
2020 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
2021 directions down.
2022
2023 @separate
2024 @example
2025       >
2026     >
2027 @end example
2028 Close the flutes staff and woodwind staff group.
2029
2030 @separate
2031 @example
2032         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2033 @end example
2034 The timpani staff only shows a new piece of scheme markup, it sets two
2035 lines of text.
2036
2037 @separate
2038 @example
2039         \context Voice=one \partcombine Voice
2040           \context Thread=one \tromboI
2041           \context Thread=two \tromboII
2042 @end example
2043 You have seen the notation contexts Staff and Voice, but here's a new
2044 one: Thread.  One or more Threads can be part of a Voice.  The Thread
2045 takes care of note heads and rests, the Voice combine note heads onto a
2046 stem.
2047
2048 For the trumpets we use the automatic part combiner (see @ref{Automatic
2049 part combining}) to combine the two simultaneous trumpet parts onto the
2050 trumpet staff.  Each trumpet gets its own Thread context, which must be
2051 named @code{one} and @code{two}).  The part combiner makes these two
2052 threads share a Voice when they're similar, and splits the threads up
2053 when they're different.
2054
2055 @separate
2056 @example
2057         \property Staff.instrument = #`(lines "Corno"
2058           (columns "(E" ,text-flat ")"))
2059 @end example
2060 The french horn has the most complex scheme markup name, made up of two
2061 lines of text.  The second line has two elements (columns), the @code{E}
2062 and the flat sign @code{text-flat} that we defined before.
2063
2064 @separate
2065 @example
2066         \property Staff.transposing = #3
2067 @end example
2068 The french horn is to be tuned in E-flat, so we tell the MIDI backend to
2069 transpose this staff by three steps.
2070
2071 Note how we can choose different tuning for entering, printing and
2072 playing, using @code{\transpose} and the MIDI Staff proprerty
2073 @var{transposing}.
2074
2075 @separate
2076 @example
2077         \notes \key bes \major
2078 @end example
2079 Therefore, it has a different key.
2080
2081 @separate
2082 @example
2083     indent = 15 * \staffspace
2084     linewidth = 60 * \staffspace
2085 @end example
2086 We specify a big indent for the first line and a small linewidth for this
2087 tutorial.
2088
2089 @separate
2090
2091 Usually, LilyPond's predefined setup of notation contexts (Thread,
2092 Voice, Staff, Staffgroup, Score) is just fine.  But in this case, we
2093 want a different type of Staff context.
2094
2095 In orchestral scores, it often happens that one instrument has only
2096 rests during one line of the score.  The @code{HaraKiriStaffContext} can
2097 be used as a regular @code{StaffContext} drop-in and will take care of
2098 the automatic removing of empty staffs.
2099
2100 @node Extracting an individual part
2101 @subsection Extracting an individual part
2102
2103 The third file, @file{os-flute-2.ly} also reads the definitions of the
2104 first (@file{os-music.ly}), and defines the @code{\score} block for the
2105 second flute part.
2106
2107 @example
2108 \include "os-music.ly"
2109 \include "paper16.ly"
2110
2111 \score @{
2112   \context Staff <
2113     \property Score.skipBars = ##t
2114     \property Staff.midiInstrument = #"flute"
2115     \global
2116     \Key
2117     \flautoII
2118   >
2119   \header @{
2120     instrument = "Flauto II"
2121   @}
2122   \paper @{
2123     linewidth = 80 * \staffspace
2124     textheight = 200 * \staffspace
2125   @}
2126   \midi @{
2127     \tempo 4 = 75
2128   @}
2129 @}
2130 @end example
2131
2132 @center @strong{Zo, goed lieverd?}
2133 @sp 1
2134 @center How's, this babe?
2135 @center @emph{Flauto II}
2136 @flushright
2137 Opus 1.
2138 @end flushright
2139 @flushleft
2140 @sc{Laid back}
2141 @end flushleft
2142 @lilypondfile{os-flute-2.ly}
2143
2144
2145 Because we separated the music definitions from the @code{\score}
2146 instantiations, we can easily define a second score from the music of
2147 the second flute.  This then is the part for the second flute player.
2148 Of course, we make separate parts for all individual instruments.
2149
2150 @separate
2151 @example
2152     \flautoII
2153 @end example
2154 In this individual part the second flute has a whole staff for itself,
2155 so we don't want to force stem or tie directions.
2156
2157 @separate
2158 @example
2159   \header @{
2160     instrument = "Flauto II"
2161   @}
2162 @end example
2163 The @code{\header} definitions were also read from @file{os-music.ly},
2164 but we need to set the instrument for this particular score.
2165
2166 @separate
2167 @example
2168     \property Score.skipBars = ##t
2169 @end example
2170 In the conductor's full score, all bars with rests are printed, but for
2171 the individual parts, we want to contract pieces of consecutive empty
2172 bars.  LilyPond will do this if Score's @var{skipBars} property to
2173 true. 
2174
2175
2176 @node Other ways to run LilyPond
2177 @section Other ways to run LilyPond
2178
2179 Until now, you have been using @file{ly2dvi} to invoke LilyPond.
2180 There are three other routes.  Firstly, there is a script called
2181 @code{lilypond-book}, that allows you to freely mix LilyPond input with
2182 Texinfo or LaTeX input. For example, this manual was written using
2183 @code{lilypond-book}. It is discussed in @ref{lilypond-book}.
2184
2185
2186 Secondly, you can generate PostScript directly. This is useful if you
2187 can not or do not want to run @TeX{} on your system.  To obtain direct
2188 PostScript output, invoke LilyPond as follows:
2189 @cindex PostScript output
2190 @example
2191 lilypond -f ps test.ly
2192 @end example
2193 You have to set some environment variables to view or print this
2194 output. More information can be found in @ref{Invoking
2195 LilyPond}.
2196
2197
2198 Thirdly, if you want to do special things with your output, you can run
2199 invoke lilypond directly:
2200 @example
2201 lilypond test.ly
2202 @end example
2203 to produce plain @TeX{} output.  Note that La@TeX{} will not work on the
2204 resulting @file{test.tex}.  You must run plain @TeX{} on it.
2205
2206 @cindex @TeX{}
2207
2208
2209
2210
2211
2212 @node Integrating text and music
2213 @section Integrating text and music
2214
2215 Sometimes, you might want to use music examples in a text that you are
2216 writing. For example, if you are writing a musicological treatise, a
2217 songbook, or (like us) the LilyPond manual.  You can make such texts by
2218 hand, simply by importing a PostScript figure into your wordprocessor.
2219 However, there is a also an automated procedure:
2220
2221 If you use La@TeX{} or texinfo, you can mix text and lilypond code. A
2222 script called @code{lilypond-book} will extract the music fragments, run
2223 lilypond on them, and put back the resulting notation.  lilypond-book is
2224 described fully in @ref{lilypond-book}, but here we show a small
2225 example. Since the example also contains explanatory text, we won't
2226 comment on the contents.
2227
2228 @example
2229 \documentclass[a4paper]@{article@}
2230 \begin@{document@}
2231
2232 In a lilypond-book document, you can freely mix music and text. For
2233 example:
2234 \begin@{lilypond@}
2235   \score @{ \notes \relative c' @{
2236      c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
2237   @} @}
2238 \end@{lilypond@}
2239 Notice that the music line length matches the margin settings of the
2240 document.
2241
2242 If you have no \verb+\score+ block in the fragment,
2243 \texttt@{lilypond-book@} will supply one:
2244
2245 \begin@{lilypond@}
2246   c'4
2247 \end@{lilypond@}
2248
2249 In the example you see here, a number of things happened: a
2250 \verb+\score+ block was added, and the line width was set to natural
2251 length. You can specify many more options using  \LaTeX style options
2252 in brackets:
2253
2254 \begin[verbatim,11pt,singleline,
2255   fragment,relative,intertext="hi there!"]@{lilypond@}
2256   c'4 f bes es
2257 \end@{lilypond@}
2258
2259 \texttt@{verbatim@} also shows the lilypond code, \texttt@{11pt@} selects
2260 the default music size, \texttt@{fragment@} adds a score block,
2261 \texttt@{relative@} uses relative mode for the fragment, and
2262 \texttt@{intertext@} specifies what to print between the
2263 \texttt@{verbatim@} code and the music.
2264
2265 If you include large examples into the text, it may be more convenient
2266 to put the example in a separate file:
2267
2268 \lilypondfile[printfilename]@{sammartini.ly@}
2269
2270 The \texttt@{printfilename@} option adds the file name to the output.
2271
2272 \end@{document@}
2273 @end example
2274
2275 Under Unix, you can view the results as follows.
2276 @example
2277 $ cd input/tutorial
2278 $ lilypond-book --outdir=out/ lilbook.tex
2279 lilypond-book (GNU LilyPond) 1.3.146
2280 Reading `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/lilbook.tex'
2281 Reading
2282 `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/sammartini.ly'
2283 @var{lots of stuff deleted}
2284 Writing `out/lilbook.latex'
2285 $ cd out
2286 $ latex lilbook.latex
2287 @var{lots of stuff deleted}
2288 $ xdvi lilbook 
2289 @end example
2290
2291 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
2292 and running latex creates a lot of temporary files, and you wouldn't
2293 those to clutter up your working directory. Hence, we have them created
2294 in a separate subdirectory.
2295
2296 The result more or less looks like this: 
2297
2298 @separate
2299
2300 In a lilypond-book document, you can freely mix music and text. For
2301 example:
2302 @lilypond
2303   \score { \notes \relative c' {
2304      c2 g'2 \times 2/3 { f8 e d } c'2 g4
2305   } }
2306 @end lilypond
2307 Notice that the music line length matches the margin settings of the
2308 document.
2309
2310 If you have no @code{\score} block in the fragment,
2311 @code{lilypond-book} will supply one:
2312
2313 @lilypond
2314   c'4
2315 @end lilypond
2316
2317 In the example you see here, a number of things happened: a
2318 @code{\score} block was added, and the line width was set to natural
2319 length. You can specify many more options using  La@TeX{} style options
2320 in brackets:
2321
2322 @lilypond[verbatim,11pt,singleline,
2323   fragment,relative,intertext="hi there!"]
2324   c'4 f bes es
2325 @end lilypond
2326
2327 @code{verbatim} also shows the lilypond code, @code{11pt} selects
2328 the default music size, @code{fragment} adds a score block,
2329 @code{relative} uses relative mode for the fragment, and
2330 @code{intertext} specifies what to print between the
2331 @code{verbatim} code and the music.
2332
2333 If you include large examples into the text, it may be more convenient
2334 to put the example in a separate file:
2335
2336 @lilypondfile[printfilename]{sammartini.ly}
2337
2338 The @code{printfilename} option adds the file name to the output.
2339 @node  end of tutorial
2340 @section The end        
2341          
2342 That's all folks.  From here, you can either try fiddling with input
2343 files, or you can read the reference manual.  You can find more example
2344 files in @file{input} and @file{input/test}.  You can also look at some
2345 real music.  The website @uref{http://www.mutopiaproject.org} has many
2346 examples of real music typeset by LilyPond.
2347
2348
2349
2350 @ignore
2351
2352 [TODO
2353
2354 this should be on mutopia website.
2355
2356 ]
2357
2358
2359 @c waar deze info?  is uiteindelijk wel handig, schat ik.
2360 [TODO: cut blabla]
2361
2362 If you have a big music project, or just a lot of LilyPond input files,
2363 all generated output from LilyPond, @TeX{} and metafont will clutter
2364 your working directory.  LilyPond comes with a one-size-fits-all
2365 pre-cooked makefile that helps you manage producing output.  It will
2366 produce all output in the directory @file{out} , generate and track
2367 dependencies. Also, it helps in preparing your submission to @ref{Mutopia
2368 project}.
2369
2370 @file{make/ly.make}
2371 @example
2372 mkdir my-project
2373 cd my-project
2374 cp /usr/share/lilypond/make/ly.make GNUmakefile
2375 cp /usr/share/doc/lilypond/examples/input/tutorial/minuet.ly .
2376 make minuet
2377 [..]
2378 Generated out/minuet.ps for target minuet.
2379 @end example
2380
2381 Type @samp{make help} to see possible targets.
2382
2383 [TODO]
2384 @file{/usr/share/lilypond/doc/lilypond/examples/input/mutopia-header.ly}
2385
2386
2387
2388
2389
2390 [TODO: rewrite completely.]
2391
2392 @menu
2393 * Songs with additional verses::  
2394 @end menu
2395
2396 @end ignore
2397