]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
updates.
[lilypond.git] / Documentation / user / tutorial.itely
1 @c -*-texinfo-*-
2
3 @c TODO:
4 @c   * LilyPond Lilypond lilypond (sometimes: the program)
5 @c   * more details about running lilypond; error messages,
6 @c     compiling/viewing (emacs?)
7 @c   * where to go from  First steps+More basics?
8
9 @node Tutorial
10 @chapter Tutorial
11
12 @html
13 <!--- @@WEB-TITLE@@=Tutorial --->
14 @end html
15
16 @menu
17 * First steps::                 Music language of LilyPond
18 * Running LilyPond::            Printing music
19 * More basics::                 
20 * Printing lyrics::             
21 * A melody with chords ::       
22 * More stanzas::                
23 * More movements ::             Joining separate pieces of music
24 * A piano excerpt::             Piano music
25 * Fine tuning a piece::         
26 * An orchestral score::         Conductor's score and individual parts
27 * Integrating text and music::  Integrating text and music
28 @end menu
29
30 Operating is done through text files: To print a piece of music, you
31 enter the music in a file.  When LilyPond is run (normally using the
32 program @code{ly2dvi}) on that file, another file containing formatted
33 sheet music, is produced. That file may be printed or viewed.
34
35 This tutorial starts with a small introduction to the LilyPond music
36 language.  After this first contact, we will show which commands to
37 run to produce printed output, so you should then be able to create
38 your first sheets of music.  The tutorial continues with more and more
39 complex examples.
40
41
42 @node First steps
43 @section First steps
44
45 We start off by showing how very simple music is entered in LilyPond:
46 you get a note simply by typing its @htmlref{note name}, from @samp{a}
47 through @samp{g}.  So if you enter
48
49 @example
50 c d e f g a b
51 @end example
52
53 @noindent
54 then the result looks like this:
55
56 @c ?
57 @c \transpose c c' { c d e f g a b }
58 @c @lily pond[notime]
59 @c \property Score.timing = ##f
60 @lilypond[notime, relative=2]
61 c d e f g a b
62 @end lilypond
63
64 We will continue with this format: First we show a snippet of input,
65 then the resulting output.
66
67 The length of a note is specified by adding a number, @samp{1} for a
68 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
69
70 @example
71 a1 a2 a4 a16 a32
72 @end example
73
74 @lilypond[notime]
75 \property Score.timing = ##f
76 \property Staff.autoBeaming = ##f
77 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
78 @end lilypond
79
80 If you do not specify a @rglos{duration}, the previous one is used: 
81
82 @example
83 a4 a a2 a
84 @end example
85
86 @lilypond[notime]
87 \property Score.timing = ##f
88 \transpose c c' { a a a2 a s16_" " }
89 @end lilypond
90
91 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
92 @rglos{flat} (@texiflat{}) by adding @samp{es}.  As you might expect,
93 a @rglos{double sharp} or @rglos{double flat} is made by adding
94 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
95 naming conventions in Nordic and Germanic languages, like German and
96 Dutch}
97
98 @example
99 cis1 ees fisis aeses
100 @end example
101
102 @lilypond[notime]
103 \property Score.timing = ##f
104 \transpose c c' { cis1 ees fisis aeses s16_" " }
105 @end lilypond
106
107 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
108
109 @example
110 a2. a4 a8. a16
111 @end example
112
113 @lilypond[notime]
114 \property Score.timing = ##f
115 \transpose c c' { a2. a4 a8. a16 s16_" " }
116 @end lilypond
117
118 Entering pitches and durations is fully explained in @ref{Pitches} and
119 @ref{Durations}.
120
121
122 The @rglos{meter} (or @rglos{time signature}) can be set with the
123 @code{\time} command:
124
125 @example
126 \time 3/4
127 \time 6/8
128 \time 4/4
129 @end example
130
131 @c a clef here may lead to confusion
132 @lilypond
133 \property Staff.Clef \set #'transparent = ##t 
134 \time 3/4
135 s4_" "
136 \time 6/8
137 s4_" "
138 \time 4/4
139 s16_" "
140 @end lilypond
141
142 Time signatures and other timing commands are described in @ref{Time
143 signature}.
144
145
146 The @rglos{clef} can be set using the @code{\clef} command:
147
148 @c what is more common name treble or violin?
149 @c in Dutch, its violin.
150 @c in English its definitely treble.
151 @example
152 \clef treble
153 \clef bass
154 \clef alto
155 \clef tenor
156 @end example
157
158 @lilypond[notime]
159 \property Score.timing = ##f
160 \clef violin
161 s4_" "
162 \clef bass
163 s4_" "
164 \clef alto
165 s4_" "
166 \clef tenor
167 s16_" "
168 @end lilypond
169
170 Clefs are fully explained in @ref{Clef}.
171
172
173 When you enter these commands in a file, you must to enclose them in
174 @code{\notes @{@dots{}@}}.  This lets LilyPond know that music (as
175 opposed to @rglos{lyrics}) follows:
176
177 @example
178 \notes @{
179   \time 3/4
180   \clef bass
181   c2 e4 g2.
182   f4 e d c2.
183 @}
184 @end example
185 Now the piece of music is almost ready to be printed.  The final step is to
186 combine the music with a printing command.
187
188 The printing command is the so-called @code{\paper} block.  Later on
189 you will see that the @code{\paper} block is used to customize
190 printing specifics.  The music and the @code{\paper} block are combined by
191 enclosing them in @code{\score @{ ... @}}.  This is what a full source file looks like:
192
193 @example
194 \score @{
195   \notes @{
196     \time 3/4
197     \clef bass
198     c2 e4 g2.
199     f4 e d c2.
200   @}
201   \paper @{ @}
202 @}
203 @end example
204
205 @lilypond[noindent]
206 \score {
207   \notes {
208      \time 3/4
209      \clef bass
210      c2 e4 g2.
211      f4 e d c2.
212   }
213   \paper {
214     linewidth = 55 * \staffspace
215   }
216 }
217 @end lilypond
218
219
220 @node Running LilyPond
221 @section Running LilyPond
222
223 In the last section we explained what kind of things you could enter
224 in a LilyPond file.  In this section we explain what commands to run
225 and how to view or print the output.  If you have not used LilyPond
226 before, want to test your setup, or want to run an example file
227 yourself, read this section.  The instructions that follow are for
228 Unix-like systems.  Some additional instructions for MS Windows are given
229 at the end of this section.
230
231 Begin by opening a terminal window and starting a text editor.
232 For example, you could open an xterm and execute @code{joe}.  In your
233 text editor, enter the following input and save the file as
234 @file{test.ly}:
235
236 @quotation
237 @example
238 \score @{
239   \notes @{ c'4 e' g' @}
240 @} 
241 @end example
242 @end quotation
243
244 @cindex ly2dvi
245
246 @c now this is weird, running ly2dvi to run LilyPond
247 @c (therefore name change proposal) 
248
249 LilyPond is the program that computes the sheet music. All other
250 things, such as adding titles, page breaking and other page layout,
251 are done by a small wrapper program called
252 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
253 then adds the titling and page layout instructions.  To process
254 @file{test.ly} with @code{ly2dvi}, proceed as follows:
255
256 @quotation
257 @example
258 ly2dvi -p test.ly
259 @end example
260 @end quotation
261
262 You will see the following on your screen:
263
264 @quotation
265 @example
266 GNU LilyPond 1.7.16
267 Now processing: `/home/fred/ly/test.ly'
268 Parsing...
269 Interpreting music...[1]
270  @emph{ ... more interesting stuff ... }
271 PDF output to `test.pdf'...
272 DVI output to `test.dvi'...
273 @end example
274 @end quotation
275 @cindex DVI file
276 @cindex Viewing music
277 @cindex xdvi
278
279 The results of the ly2dvi run are two files, @file{test.dvi} and
280 @file{test.pdf}.  The PDF file (@file{test.pdf}) is the one you can
281 print or view.  For example, viewing PDF can be done with ghostview.
282 If a version of ghostview is installed on your system, one of these
283 commands will produce a window with some music notation on your
284 screen:
285 @c eeek
286 @quotation
287 @example
288   gv test.pdf
289   ghostview test.pdf
290   ggv test.pdf
291   kghostview test.pdf
292   xpdf test.pdf
293   gpdf test.pdf
294 @end example
295 @end quotation
296 If the music on your screen looks good, you can print it by clicking
297 File/Print inside ghostview.
298
299 The DVI file (@file{test.dvi}) contains the same sheet music in a
300 different format. DVI files are more easily processed by the computer,
301 so viewing them usually is quicker.  You can run @code{xdvi test.dvi}
302 @c KDVI doesn't grok the PS specials.
303 @c or
304 @c @code{kdvi test.dvi}
305 @c
306 to view the DVI file. In Xdvi, the mouse buttons
307 activate magnifying glasses.  Unfortunately, variable symbols (such as
308 beams and slurs) are not displayed in the magnifying glasses.
309
310
311 @cindex Ghostscript
312 @cindex @code{lpr}
313 @cindex Printing output
314 @cindex PostScript
315 @cindex PDF
316
317 If you are familiar with @TeX{}, be warned: do not use other DVI
318 drivers like @code{dvilj}.  LilyPond DVI use embedded PostScript code
319 and will not render correctly with other DVI drivers besides
320 @code{dvips}.
321
322 @cindex dvips
323 @cindex dvilj
324 @cindex DVI driver
325
326
327 Various commands for formatting and printing music are detailed in
328 @ref{Invoking LilyPond}.
329
330
331 @unnumberedsubsec Windows users
332
333 Windows users can start the terminal by clicking on the LilyPond or
334 Cygwin icon.  Any text editor (such as NotePad, Emacs or Vim) may be
335 used to edit the LilyPond file.  When Cygwin's @code{XFree86} X11
336 window system is installed along with @code{tetex-x11} and
337 @code{ghostscript-x11} packages, then the @code{dvi} output may be
338 viewed with @code{xdvi test.dvi} as described above.  If you have
339 installed a PostScript/PDF viewer, such as @code{GSView} from
340 @uref{http://www.cs.wisc.edu/~ghost}, viewing the PDF file can be done
341 with:
342 @quotation
343 @example
344 @code{gsview32 test.pdf}
345 @end example
346 @end quotation
347 Printing may be done by executing
348 @quotation
349 @example
350 @code{gsview32 /s test.pdf}
351 @end example
352 @end quotation
353
354
355 @node More basics
356 @section More basics 
357
358 We continue with the introduction of more musical constructs.  Normal
359 rests are entered just like notes with the name ``@code{r}'':
360
361 @quotation
362 @example
363 r2 r4 r8 r16
364 @end example
365
366 @lilypond[fragment]
367 \property Score.timing = ##f
368 \property Staff.Clef = \turnOff
369 \property Staff.TimeSignature = \turnOff
370 r2 r4 r8 r16
371 s16_" "
372 @end lilypond
373 @end quotation
374 @separate
375
376 Rests are described in full detail in @ref{Rests}. 
377
378
379 @c Tim wants to move this quotes example just before the: quotes-do not-work
380 @c score, but we'd need to remove quotes from the other two (key and
381 @c tie) examples...
382
383 @c better to have this just before the `octaves are bad' snipped
384 @c but we'd need to remove the ', from \key and tie 
385 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
386 the note name, to lower a note one octave, add a ``low quote'' @code{,}
387 (a comma).  Middle C is @code{c'}:
388
389 @quotation
390 @example
391 c'4 c'' c''' \clef bass c c,
392 @end example
393
394 @lilypond[fragment]
395 \property Score.timing = ##f
396 \property Staff.TimeSignature = \turnOff
397 c'4 c'' c''' \clef bass c c,
398 @end lilypond
399 @end quotation
400 @separate
401
402 A tie is created by adding a tilde ``@code{~}'' to the first note
403 being tied.
404 @quotation
405 @lilypond[fragment,verbatim]
406 g'4-~ g' a'2-~ a'4
407 @end lilypond
408 @end quotation
409 @separate
410 A tie is different from a slur. A tie simply makes the first note
411 sound longer, and can only be used on pairs of notes with the same
412 pitch. Slurs indicate the articulations of notes, and can be used on
413 larger groups of notes. Slurs and ties are also nested in practice:
414 @lilypond[fragment, relative=1]
415 c2-~-( c8 fis fis4 ~ fis2 g2-)
416 @end lilypond
417
418 The notation manual discusses ties in @ref{Ties}.
419
420 The key signature is set with the command ``@code{\key}'', followed by
421 a pitch and  @code{\major} or @code{\minor}:
422 @quotation
423 @example
424 \key d \major
425 g'1
426 \key c \minor
427 g'
428 @end example
429
430 @lilypond[fragment]
431 \property Staff.TimeSignature = \turnOff
432 \key d \major
433 g'1
434 \key c \minor
435 g'
436 @end lilypond
437 @end quotation
438
439
440
441 @c bit on the long/complex/scary taste
442 @c cheating a bit: two lines makes for a friendlier look
443 This example shows notes, ties, octave marks, and rests in action.
444
445 @quotation
446 @example
447 \score @{
448   \notes @{
449     \time 4/4
450     \key d \minor
451     \clef violin
452     r4 r8 d''8 cis''4 e''
453     d''8 a'4.-~ a' b'8
454     cis''4 cis''8 cis'' bis'4 d''8 cis''-~
455     cis''2 r2
456   @}
457   \paper @{ @}
458 @}
459 @end example
460
461 @lilypond
462 \score {
463   \notes {
464     \time 4/4
465     \clef violin
466     \key d \minor
467     r4 r8 d''8 cis''4 e''
468     d''8 a'4.-~ a' b'8
469     cis''4 cis''8 cis'' bis'4 d''8 cis''-~
470     cis''2 r2
471   }
472   \paper { linewidth = 50*\staffspace }
473 }
474 @end lilypond
475 @end quotation
476
477 @c accidentals...
478 There are some interesting points to note in this example.
479 Accidentals (sharps and flats) do not have to be marked explicitly:
480 you just enter the note name, and an accidental is printed
481 automatically, only when necessary.  Bar lines and beams are drawn
482 automatically.  Line breaks are calculated automatically; it does not
483 matter where the lines breaks are in the source file. Finally, the
484 order of time, key and clef changes is not relevant: in the printout,
485 these are ordered using standard notation conventions.
486
487 The example also indicates that a piece of music written in a high
488 register needs lots of quotes.  This makes the input less readable,
489 and is also a potential source of errors.
490
491 The solution is to use ``relative octave'' mode.  In practice, this is
492 the most convenient way to copy existing music.  To use relative mode,
493 add @code{\relative} before the piece of music.  You must also give a
494 note from which relative starts, in this case @code{c''}.  If you do
495 not use octavation quotes (i.e. do not add ' or , after a note),
496 relative mode chooses the note that is closest to the previous one.
497 @c do not use commas or quotes in this sentence
498 For example: @code{c f} goes up; @code{c g} goes down:
499
500 @quotation
501 @example
502 \relative c'' @{
503   c f c g c
504 @}
505 @end example
506
507 @lilypond[fragment]
508 \property Score.timing = ##f
509 \property Staff.TimeSignature = \turnOff
510 \relative c'' {
511   c f c g c
512 }
513 @end lilypond
514 @end quotation
515 @separate
516
517
518 Since most music has small intervals, in relative mode pieces can be
519 written almost without using octavation quotes.
520
521 @c needed better, maybe even redundant explanation
522 @c   added another example below.
523 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
524 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
525 Larger intervals are made by adding octavation quotes.  Quotes or
526 commas do not determine the absolute height of a note; the height of a
527 note is relative to the previous one.
528 @c do not use commas or quotes in this sentence
529 For example: @code{c f,} goes down; @code{f, f} are both the same;
530 @code{c' c} are the same; and @code{c g'} goes up:
531
532 @quotation
533 @example
534 \relative c'' @{
535   c f, f c' c g' c,
536 @}
537 @end example
538
539 @lilypond[fragment]
540 \property Score.timing = ##f
541 \property Staff.TimeSignature = \turnOff
542 \relative c'' {
543   c f, f c' c g' c,
544 }
545 @end lilypond
546 @end quotation
547 @separate
548
549
550 Here is an example of the difference between relative mode and
551 ``normal'' (non-relative) mode:
552
553 @quotation
554 @example
555 \relative a @{
556 \clef bass
557   a d a e d c' d'
558 @}
559 @end example
560
561 @lilypond[fragment]
562 \property Score.timing = ##f
563 \property Staff.TimeSignature = \turnOff
564 \relative a {
565 \clef bass
566   a d a e d c' d'
567 }
568 @end lilypond
569 @end quotation
570 @separate
571
572 @quotation
573 @example
574 \clef bass
575   a d a e d c' d'
576 @end example
577
578 @lilypond[fragment]
579 \property Score.timing = ##f
580 \property Staff.TimeSignature = \turnOff
581 \clef bass
582   a d a e d c' d'
583 @end lilypond
584 @end quotation
585 @separate
586
587 A slur is drawn across many notes, and indicates bound articulation
588 (legato).  The starting note and ending note are marked with a
589 ``@code{(}'' and a ``@code{)}'' respectively:
590
591 @quotation
592 @lilypond[fragment,relative 1, verbatim]
593 d4-( c16-)-( cis d e c cis d e-)-( d4-)
594 @end lilypond
595 @end quotation
596 @separate
597
598 If you need two slurs at the same time (one for articulation, one for
599 phrasing), you can also make a phrasing slur with @code{\(} and
600 @code{\)}.
601
602 @c lousy example
603 @c ? --hwn
604 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
605 @c chromatic thing pasted in front.  (admittedly the original does not
606 @c have a phrasing slur. The problem is that we do not want the slur
607 @c and the Phrasing slur to collide. We are trying to make a good
608 @c impression here.
609
610 @quotation
611 @lilypond[fragment,relative 1, verbatim]
612 a8-(-\( ais b  c-) cis2 b'2 a4 cis,  c-\)
613 @end lilypond
614 @end quotation
615 @separate
616
617 Beams are drawn automatically, but if you do not like the choices, you
618 can enter beams by hand. Mark the first note to be beamed with
619 @code{[} and the last one with @code{]}:
620 @quotation
621 @lilypond[fragment,relative 1, verbatim]
622 a8-[ ais-] d-[ es r d-]
623 @end lilypond
624 @end quotation
625 @separate
626
627 To print more than one staff, each piece of music that makes up a staff
628 is marked by adding @code{\context Staff} before it.  These
629 @code{Staff}'s are then grouped inside @code{<} and @code{>}, as is
630 demonstrated here:
631
632 @quotation
633 @lilypond[fragment,verbatim]
634 <
635   \context Staff = staffA { \clef violin c'' }
636   \context Staff = staffB { \clef bass c }
637 >
638 @end lilypond
639 @end quotation
640
641 In this example, @code{staffA} and @code{staffB} are names that are
642 given to the staves.  It does not matter what names you give, as long
643 as each staff has a different name. If you give them the same name,
644 they are assumed to belong on the same staff, and will be printed like
645 that.
646
647 @separate
648
649 We can now typeset a melody with two staves:
650
651 @quotation
652 @lilypond[verbatim,singleline]
653 \score {
654   \notes 
655   < \context Staff = staffA {
656       \time 3/4
657       \clef violin
658       \relative c'' {
659         e2-( d4 c2 b4 a8-[ a-]
660         b-[ b-] g-[ g-] a2.-) }  
661     }
662     \context Staff = staffB {
663        \clef bass
664        c2 e4  g2.
665        f4 e d c2.
666     }
667   >
668   \paper {} 
669 }
670 @end lilypond
671 @end quotation
672
673 Notice that the time signature is specified in one melody staff only
674 (the top staff), but is printed on both.  LilyPond knows that the time
675 signature should be the same for all staves.
676
677 @separate
678
679 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
680 @quotation
681 @lilypond[verbatim,relative 1]
682 c-. c-- c->
683 @end lilypond
684 @end quotation
685 @separate
686
687 Dynamic signs are made by adding the markings to the note:
688 @quotation
689 @lilypond[verbatim,relative 1]
690 c-\ff c-\mf
691 @end lilypond
692 @end quotation
693 @separate
694
695 Crescendi and decrescendi are started with the commands @code{\<} and
696 @code{\>}. The command @code{\!} finishes a crescendo on the note it
697 is attached to.
698 @quotation
699 @lilypond[verbatim,relative 1]
700 c2-\<  c2-\!-\ff  c2-\>  c2-\!
701 @end lilypond
702 @end quotation
703 @separate
704
705 Chords can be made by
706 surrounding pitches with @code{<<} and @code{>}>:
707 @quotation
708 @lilypond[relative 0, fragment,verbatim]
709 r4 <<c e g>>4 <<c f a>>8
710 @end lilypond
711 @end quotation
712 @separate
713
714
715 You can combine beams and ties with chords.  Beam and tie markings
716 must be placed outside the chord markers:
717 @quotation
718 @lilypond[relative 0, fragment,verbatim]
719 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
720 @end lilypond
721 @end quotation
722
723 @quotation
724 @example
725 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>>  <<c f a>>8-\!-)
726 @end example
727 @lilypond[relative 0, fragment]
728 \slurUp
729 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>>  <<c f a>>8-\!-)
730 @end lilypond
731 @end quotation
732 @separate
733
734
735 TODO: triplets, partial 
736
737 Now you know the basic ingredients of a music file, so this is the
738 right moment to experiment and try your at hand typing some simple
739 files.
740
741 When you are comfortable with the basics, you might want to read the
742 rest of this chapter.  It continues in tutorial-style, but it is much
743 more in-depth, dealing with more advanced topics such as lyrics,
744 chords, orchestral scores and parts, fine tuning of output, polyphonic
745 music, and integrating text and music.
746
747
748
749 @node Printing lyrics
750 @section Printing lyrics
751 @cindex lyrics
752
753 Lyrics are entered by separating each syllable with a space, and
754 surrounding them with @code{\lyrics @{ @dots{} @}}, for example
755 @example
756   \lyrics @{ I want to break free @}
757 @end example
758
759 Like notes, lyrics are also a form of music, but they must not be
760 printed on a staff, which is the default way to print music. To print
761 them as lyrics, they must be marked with @code{ \context Lyrics}:
762 @example
763   \context Lyrics  \lyrics @{ I want to break free @}
764 @end example
765 The melody for this song is as follows
766 @lilypond[fragment,relative=1]
767    \partial 8
768      c8
769    \times 2/3 {  f g g } \times 2/3 { g4-( a2-) }
770 @end lilypond
771
772 The lyrics can be set to these notes, combining both with the
773 @code{\addlyrics} keyword:
774 @example
775  \addlyrics
776     \notes @{ @dots{} @}
777     \context Lyrics @dots{}
778 @end example
779
780 The final result is 
781 @lilypond[singleline,verbatim]
782 \score  {
783  \notes {
784   \addlyrics
785    \relative c' {
786      \partial 8
787      c8
788      \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
789    }
790    \context Lyrics  \lyrics { I want to break free }
791  }
792  \paper{ }
793 }
794 @end lilypond
795
796 This melody ends on a @rglos{melisma}, a single syllable (``free'')
797 sung to more than one note. This is indicated with a @emph{extender
798 line}. It is entered as two  underscores, i.e.,
799 @example
800   \lyrics @{ I want to break free __ @}
801 @end example 
802 @lilypond[singleline]
803 \score  {
804  \notes {
805   \addlyrics
806    \relative c' {
807    \partial 8
808      c8
809      \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
810    }
811    \context Lyrics  \lyrics { I want to break free __ }
812  }
813  \paper{ }
814 }
815 @end lilypond
816
817 Similarly, hyphens between words can be entered as two dashes,
818 resulting in a centered hyphen between two syllables.
819 @example
820   Twin -- kle twin -- kle
821 @end example
822 @lilypond[singleline]
823 \score {
824   \addlyrics \notes \relative f' { \time 2/4
825     f4 f c' c' }
826     \lyrics { Twin -- kle twin -- kle
827  }}
828 @end lilypond
829
830
831 @node A melody with chords 
832 @section A melody with chords
833
834
835 @ignore
836
837 @separate
838 @example 
839         \partial 8
840 @end example 
841
842 @cindex @code{\partial}
843 @cindex anacrusis
844 The piece starts with an anacrusis (or ``pickup'') of one eighth.
845 @separate
846
847 @separate
848 @example 
849
850         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
851         c4 c8 d [es () d] c4 | d4 es8 d c4.
852         \bar "|."
853  
854 @end example 
855
856 @cindex manual beaming
857 @cindex automatic beaming, turning off
858 We use explicit beaming.  Since this is a song, we turn automatic
859 beams off and use explicit beaming where needed.
860 @separate
861 @example 
862
863         @}
864  
865 @end example 
866 This ends the definition of @code{melody}.  
867
868 @separate
869 @example 
870
871         text = \lyrics @{
872  
873 @end example
874 @cindex lyrics
875 @cindex identifier assignment
876 @cindex syllables, entering
877 This defines the lyrics, similar to what we have seen before.
878
879 @separate
880 @example 
881
882         accompaniment =\chords @{
883  
884 @end example
885 @cindex chords
886 @cindex mode, chords
887 We will put chords over the music. To enter them, we use a special mode
888 analogous to @code{\lyrics} and @code{\notes} mode, where you can give
889 the names of the chords you want instead of listing the notes
890 comprising the chord.
891 @separate
892 @example 
893
894         r8
895  
896 @end example 
897 There is no accompaniment during the anacrusis.
898 @separate
899 @example 
900
901         c2:3- 
902  
903 @end example
904
905 @cindex tonic
906 @cindex chord modifier
907 @cindex modifier, chord 
908 This is a c minor chord, lasting for a half note. Chords are entered using
909 the tonic.  Notes can be changed to create different chords.  In this case,
910 a lowered third is used (making a C major chord into a C minor chord).
911 The code for this is @code{3-}. 
912
913 @separate
914 @example
915 f:3-.7
916 @end example
917 Similarly, @code{7} modifies (adds) a seventh, which is small by
918 default to create the @code{f a c es} chord.  Multiple modifiers must be
919 separated by dots.
920 @separate
921 @example 
922
923         d:min es4 c8:min r8
924  
925 @end example
926 Some modifiers have predefined names, e.g. @code{min} is  the same as
927 @code{3-}, so @code{d-min} is a minor @code{d} chord.
928 @separate
929 @example 
930
931         c2:min f:min7 g:7^3.5 c:min @}
932  
933 @end example
934 @cindex named modifier
935
936 A named modifier @code{min} and a normal modifier @code{7} do not have
937 to be separated by a dot.  Tones from a chord are removed with chord
938 subtractions.  Subtractions are started with a caret, and they are
939 also separated by dots.  In this example, @code{g:7^3.5} produces a
940 minor seventh (a G7 chord without the third or the fifth).  The
941 brace ends the sequential music.
942 @separate
943 @example 
944
945         \score @{
946                 \simultaneous @{
947  
948 @end example 
949 We assemble the music in the @code{\score} block.  Melody, lyrics and
950 accompaniment have to sound at the same time, so they should be
951 @code{\simultaneous}.
952 @cindex @code{\simultaneous}
953 @separate
954 To print chords as chords names, they have to be interpreted as
955 such. This is done with the following command: The following command
956 explicitly creates an interpretation context of @code{ChordNames} type
957 to interpret the music @code{\accompaniment}.
958 @example 
959
960         \context ChordNames \accompaniment
961  
962 @end example
963
964 @separate
965 @example 
966
967         \context Staff @{
968  
969 @end example
970
971 We place the melody on a staff. 
972 @separate
973 @example 
974
975         \property Staff.autoBeaming = ##f
976  
977 @end example
978 @cindex \property
979 @cindex context variables
980 @cindex setting context variables
981 An interpretation context has variables that tune its behavior.  These
982 variables are also called @emph{properties}.  The @code{autoBeaming}
983 variable in a @code{Staff} controls whether 8th and shorter notes are
984 beamed automatically. Setting the variable to @code{##f}, which is the
985 boolean value @var{false}, turns it off.
986
987
988 @separate
989 @example 
990
991           \melody
992         @}
993  
994 @end example 
995 Finally, we put the melody on the current staff.   The
996 @code{\property} directives and @code{\melody} are grouped in sequential
997 music,  so the property settings are done before the melody is
998 processed.
999
1000 @separate
1001 @example 
1002
1003         \midi  @{ \tempo 4=72@}
1004  
1005 @end example 
1006 MIDI (Musical Instrument Digital Interface) is a standard for
1007 connecting and recording digital instruments.  A MIDI file is like a
1008 tape recording of a MIDI instrument. The @code{\midi} block makes the
1009 music go to a MIDI file, so you can listen to the music you entered.
1010 It is great for checking the music.  Whenever you hear something
1011 weird, you probably hear a typing error.
1012
1013 @code{\midi} is similar to @code{\paper @{ @}}, since it also
1014 specifies an output method.  You can specify the tempo using the
1015 @code{\tempo} command, in this case the tempo of quarter notes is set
1016 to 72 beats per minute.
1017 @separate
1018 @example 
1019
1020         \paper @{ linewidth = 10.0\cm @}
1021  
1022 @end example 
1023 We also want notation output.  The linewidth is short so that the piece
1024 will be set in two lines.
1025
1026 @end ignore 
1027
1028
1029 @node More stanzas
1030 @section More stanzas
1031
1032
1033 @cindex phrasing
1034
1035 If you have multiple stanzas printed underneath each other, the vertical
1036 groups of syllables should be aligned around punctuation.  LilyPond can
1037 do this if you tell it which lyric lines belong to which melody.
1038 We show how you can do this by showing how you could print a frivolous
1039 fragment of a fictional Sesame Street duet. 
1040
1041 @lilypond[singleline,verbatim]
1042 \score {
1043 \addlyrics
1044   \notes \relative c'' \context Voice = duet { \time 3/4
1045      g2 e4 a2 f4 g2.  }
1046   \lyrics \context Lyrics <
1047   \context LyricsVoice = "duet-1" {
1048     \property LyricsVoice . stanza = "Bert"
1049     Hi, my name is bert.    }
1050   \context LyricsVoice = "duet-2" {
1051     \property LyricsVoice . stanza = "Ernie" 
1052     Ooooo, ch\'e -- ri, je t'aime. }
1053   >
1054 }
1055 @end lilypond
1056
1057 To this end, give the Voice context an identity, and set the
1058 LyricsVoice to a name starting with that identity followed by a dash.
1059 In the following example, the Voice identity is @code{duet},
1060 @example
1061 \context Voice = duet @{
1062      \time 3/4
1063      g2 e4 a2 f4 g2.  @}
1064 @end example
1065 and the
1066 identities of the LyricsVoices are @code{duet-1} and @code{duet-2}.
1067 @example
1068   \context LyricsVoice = "duet-1" @{
1069     Hi, my name is bert. @}
1070   \context LyricsVoice = "duet-2" @{
1071     Ooooo, ch\'e -- ri, je t'aime. @}
1072 @end example
1073 The convention for naming @code{LyricsVoice} and @code{Voice} must
1074 also be used to get melismata on rests correct.
1075
1076
1077 We add the names of the singers.  This can be done by setting
1078 @code{LyricsVoice.Stanza} (for the first system) and
1079 @code{LyricsVoice.stz} for the following systems.   You must
1080 surround dots with spaces in @code{\lyrics} mode.
1081
1082 @example
1083     \property LyricsVoice . stanza = "Bert"
1084     @dots{}
1085     \property LyricsVoice . stanza = "Ernie" 
1086 @end example
1087
1088
1089 @node More movements 
1090 @section More movements
1091
1092 The program @code{lilypond} only produces sheet music.  Titles,
1093 subtitles, and the composer's name are created by a separate program,
1094 called use @code{ly2dvi}.  @code{ly2dvi} creates the titles, then
1095 calls @code{lilypond} to format the sheet music.  In this section, we
1096 show you how to create titles like this:
1097
1098 @center @strong{Two miniatures}
1099 @flushright
1100 Opus 1.
1101 @end flushright
1102 @flushleft
1103 @var{Up}
1104 @end flushleft
1105 @lilypond
1106   \score {
1107     \notes { c'4 d'4 }
1108     \paper { raggedright = ##t }
1109   }
1110 @end lilypond
1111 @flushright
1112 Opus 2.
1113 @end flushright
1114 @flushleft
1115 @var{Down}
1116 @end flushleft
1117 @lilypond
1118   \score {
1119     \notes { d'4 c'4 }
1120     \paper { linewidth = -1.0 }
1121   }
1122 @end lilypond
1123
1124 For example, consider the following file (@file{miniatures.ly}) 
1125
1126 @example
1127 \version "1.5.72"
1128 \header @{
1129   title = "Two miniatures"
1130   composer = "F. Bar Baz" 
1131   tagline = "small is beautiful" @}
1132
1133 \paper @{ raggedright = ##t @}
1134
1135 %@{
1136
1137 Mental note: discuss Schenkerian analysis of these key pieces.
1138
1139 %@}
1140
1141 \score @{
1142     \notes @{ c'4 d'4 @}
1143     \header @{
1144         opus = "Opus 1."
1145         piece = "Up" @}
1146 @}
1147 \score @{
1148     \notes @{ d'4 c'4 @}
1149     \header @{
1150         opus = "Opus 2."
1151         piece = "Down" @}
1152 @}
1153 @end example
1154
1155
1156 The information for the global titling is in a so-called header block.
1157 The information in this block is not used by LilyPond, but it is
1158 passed into @code{ly2dvi}, which uses this information to print titles
1159 above the music.
1160 @cindex assignments
1161 @cindex identifier assignment
1162 the @code{\header} block contains assignments.  In each assignment, a
1163 variable is set to a value. The header block for this file looks like
1164 this
1165 @cindex @code{\header}
1166 @example 
1167   \header @{
1168     title = "Two miniatures" 
1169     composer = "F. Bar Baz"
1170     tagline = "small is beautiful"
1171   @}
1172 @end example
1173
1174 When you process a file with ly2dvi, a signature line is printed at
1175 the bottom of the last page.  Many people find the default (``Lily was
1176 here'' with a version number) too droll.  If that is the case, you can
1177 change @code{tagline} in the @code{\header}, as shown above.
1178
1179 @cindex Lily was here
1180 @cindex signature line
1181 @cindex tag line
1182
1183 @separate
1184 @example
1185   \paper @{ 
1186     raggedright = ##t @}
1187 @end example
1188
1189 A paper block at top level (i.e. not in a @code{\score} block) sets
1190 the default page layout.  The following @code{\score} blocks do not
1191 have @code{\paper} sections so the settings of this block are used.
1192
1193 When @code{raggedright} is set, the spacing is set to natural length:
1194 a short phrase takes up little space, a longer phrase takes more
1195 space, all on the same line.
1196
1197 @example
1198 %@{
1199
1200 Mental note: discuss Schenkerian analysis of these key pieces.
1201
1202 %@}
1203 @end example
1204
1205 Mental notes to yourself can be put into comments. There are two types
1206 of comments. Line comments are introduced by @code{%}, and block
1207 comments are delimited by @code{%@{} and @code{%@}}.
1208
1209 @separate
1210 @example
1211   \score @{
1212     \notes @{ c'4 d'4 @}
1213 @end example
1214
1215 In previous examples, most notes were specified in relative octaves
1216 (i.e. each note was put in the octave that is closest to its preceding
1217 note).  This is convenient when copying existing music: you have to do
1218 less typing, and errors are easily spotted.
1219
1220 There is also absolute octave specification, which you get when you do
1221 not include @code{\relative} in your input file.  In this input mode,
1222 the middle C is denoted by @code{c'}. Going down, you get @code{c}
1223 @code{c,} @code{c,,} etc.  Going up, you get @code{c''} @code{c'''}
1224 etc.  Absolute octaves are convenient when you write LilyPond input
1225 directly, either by hand (i.e. composing) or by computer.
1226
1227 @separate
1228 @example
1229     \header @{
1230 @end example
1231
1232 The @code{\header} is normally at the top of the file, where it sets
1233 values for the rest of the file.  If you want to typeset different
1234 pieces from one file (for example, if there are multiple movements, or
1235 if you are making an exercise book), you can put different
1236 @code{\score} blocks into the input file.  @code{ly2dvi} will assemble
1237 all LilyPond output files into a one document.  The contents of
1238 @code{\header} blocks specified within each score is used for the
1239 title of that movement.
1240 @separate
1241 @example
1242         opus = "Opus 1."
1243         piece = "Up" @}
1244 @end example
1245 For example, the Opus number is put at the right, and the "piece" string
1246 will be at the left.
1247
1248
1249
1250 @example
1251 \version "1.5.72"
1252 \header @{
1253   title = "Two miniatures"
1254   composer = "F. Bar Baz" 
1255   tagline = "small is beautiful" @}
1256
1257 \paper @{ raggedright = ##t @}
1258
1259 \score @{
1260     \notes @{ c'4 d'4 @}
1261     \header @{
1262         opus = "Opus 1."
1263         piece = "Up" @}
1264 @}
1265 \score @{
1266     \notes @{ d'4 c'4 @}
1267     \header @{
1268         opus = "Opus 2."
1269         piece = "Down" @}
1270 @}
1271 @end example
1272
1273 TODO:
1274 @example
1275
1276 scoreA = \score @{ \deelA  @}
1277 scoreB = \score @{ \deelA  @}
1278
1279 % \score @{ \scoreA @}
1280 \score @{ \scoreB @}
1281
1282 @end example
1283
1284 @separate
1285 @example 
1286 \version "1.5.72"
1287 @end example 
1288 Lilypond and its language are still under development, and
1289 occasionally details of the syntax are changed.  The @code{version}
1290 fragment indicates which version of LilyPond the input file was written
1291 for.  When you compile this file, the version number will be checked
1292 and you will get a warning when the file is too old.  This version
1293 number is also used by the @code{convert-ly} program (See
1294 @ref{Invoking convert-ly}), which can used to update the file to the
1295 latest lily version.
1296
1297
1298 @node A piano excerpt
1299 @section A piano excerpt
1300
1301 Our eighth subject is a piece of piano music.  The fragment in the
1302 input file is a piano reduction of the G major Sinfonia by Giovanni
1303 Battista Sammartini, composed around 1740.  It's in the source
1304 package under the name @inputfileref{input/tutorial,sammartini.ly}.
1305
1306 @lilypondfile[smallverbatim]{sammartini.ly}
1307
1308 As you can see, this example features multiple voices on one staff.  To
1309 make room for those voices, their notes should be stemmed in opposite
1310 directions.
1311
1312
1313
1314 @separate
1315 @example 
1316 viola = \notes \relative c'  \context Voice = viola @{ 
1317 @end example 
1318 In this example you see multiple parts on a staff.  Each part is
1319 associated with one notation context.  This notation context handles
1320 stems and dynamics (among other things).  The type name of this
1321 context is @code{Voice}.  For each part we have to make sure that
1322 there is precisely one @code{Voice} context, so we give it a unique
1323 name (`@code{viola}').
1324
1325 @separate
1326 @example 
1327 <<c g' c>>4-\arpeggio
1328 @end example 
1329 The delimiters @code{<<} and @code{>>} enclose the pitches of a chord.
1330 @code{\arpeggio} typesets an arpeggio sign (a wavy vertical line)
1331 before the chord.
1332
1333 @cindex arpeggio
1334
1335
1336
1337
1338
1339 @separate
1340 @example 
1341         g'8. b,16 
1342 @end example 
1343 Relative octaves work a little differently with chords.  The starting
1344 point for the note following a chord is the first note of the chord.  So
1345 the @code{g} gets an octave up quote: it is a fifth above the starting
1346 note of the previous chord (the central C).
1347
1348 @separate
1349 @example 
1350 s1 s2. r4 
1351 @end example 
1352 @code{s} is a spacer rest.  It does not print anything, but it does have
1353 the duration of a rest. It is useful for filling up voices that
1354 temporarily do not play. In this case, the viola does not come until one
1355 and a half measure later.
1356
1357 @separate
1358 @example 
1359 oboes = \notes \relative c'' \context Voice = oboe @{ 
1360 @end example 
1361 Now comes a part for two oboes.  They play homophonically, so we
1362 print the notes as one voice that makes chords. Again, we insure that
1363 these notes are indeed processed by precisely one context with
1364 @code{\context}.
1365 @separate
1366 @example 
1367   s4  g8. b,16 c8 r <<e' g>>8. <<f a>>16
1368 @end example
1369
1370 The oboes should have stems up to keep them from interfering with
1371 the staff-jumping bass figure.  To do that, we use @code{\voiceOne}.
1372
1373 @separate
1374 @example 
1375 \grace <<e g>>-( <<d f>>4-) <<c e>>2 
1376 @end example
1377 @cindex @code{\grace}
1378 @cindex ornaments
1379 @cindex grace notes
1380 @code{\grace} introduces grace notes.  It takes one argument, in this
1381 case a chord. A slur is introduced starting from the @code{\grace}
1382 ending on the following chord.
1383
1384 @separate
1385 @example 
1386 \times 2/3 
1387 @end example
1388 @cindex tuplet
1389 @cindex triplets
1390 Tuplets are made with the @code{\times} keyword.  It takes two
1391 arguments: a fraction and a piece of music.  The duration of the piece
1392 of music is multiplied by the fraction.  Triplets make notes occupy 2/3
1393 of their notated duration, so in this case the fraction is 2/3.
1394 @separate
1395 @example 
1396 @{ <<d f>>8 <<e g>> <<f a>> @} 
1397 @end example 
1398 The piece of music to be `tripletted' is sequential music containing
1399 three chords.
1400
1401 @separate
1402 @example 
1403
1404 @end example 
1405 At this point, the homophonic music splits into two rhythmically
1406 different parts.  We cannot use a sequence of chords to enter this, so
1407 we make a "chord of sequences" to do it.  We start with the upper
1408 voice, which continues with upward stems:
1409 @separate
1410 @example 
1411  @{ \times 2/3 @{ a8 g c @} c2 @} 
1412 @end example
1413
1414 @separate
1415 @example
1416 \\
1417 @end example
1418 The easiest way to enter multiple voices is demonstrated
1419 here. Separate the components of the voice (single notes or entire
1420 sequences) with @code{\\} in a simultaneous music expression. The
1421 @code{\\} separators split first voice, second voice, third voice, and
1422 so on.
1423
1424 As far as relative mode is concerned, the previous note is the
1425 @code{c'''2} of the upper voice, so we have to go an octave down for
1426 the @code{f}.
1427 @separate
1428 @example 
1429
1430   f,8 e e2
1431 @} > 
1432 @end example 
1433 This ends the two-part section.
1434 @separate
1435 @example 
1436 \grace <<c, e>>8-( <<b d>>8.-\trill <<c e>>16 |  
1437 @end example
1438 @cindex trill
1439 @cindex stemBoth
1440
1441 The bass has a little hoom-pah melody to demonstrate parts switching
1442 between staves.  Since it is repetitive, we use repeats:
1443 @separate
1444 @example 
1445 hoomPah  =  \repeat unfold 8
1446 @end example
1447 @cindex unfolded @code{\repeat}
1448 The unfolded repeat prints the notes in its argument as if they were
1449 written out in full eight times.
1450 @separate
1451 @example
1452 \notes \transpose c c' @{
1453 @end example
1454 @cindex transposing
1455 @cindex relative mode and transposing
1456
1457 Transposing can be done with @code{\transpose}, which takes two arguments.
1458 The first specifies what central C should be transposed to.  The second
1459 is the to-be-transposed music.  As you can see, in this case, the
1460 transposition has no effect, as central C stays at central C.
1461
1462 The purpose of this no-op is to protect it from being interpreted as
1463 relative notes.  Relative mode cannot be used together with
1464 transposition, so @code{\relative} will leave the contents of
1465 @code{\hoomPah} alone.  We can use it without having to worry about
1466 getting the motive in a wrong octave. Conversely, if you want to
1467 transpose a fragment of music entered with @code{\relative}, then you
1468 should make sure that @code{\transpose} comes before @code{\relative}.
1469
1470 @separate
1471 @cindex staff switch, manual
1472 @cindex cross staff voice, manual
1473 @cindex @code{\translator}
1474
1475 @example
1476 \translator Staff = down
1477 \stemUp
1478 c8
1479 \translator Staff = up
1480 \stemDown
1481 c'8 @}
1482 @end example
1483 Voices can switch between staves.  Here you see two staff switching
1484 commands.  The first one moves to the lower staff, the second one to
1485 the lower one.  If you set the stem directions explicitly
1486 (using the identifiers @code{\stemUp} and @code{\stemDown}, the notes
1487 can be beamed together (despite jumping between staffs).
1488
1489 @separate
1490 @example 
1491 bassvoices = \notes \relative c' @{
1492 c4 g8. b,16
1493 \autochange Staff \hoomPah \context Voice
1494 @end example
1495
1496 @separate
1497 @example
1498         \translator Staff = down
1499 @end example
1500 @cindex staff switch
1501 @cindex cross staff voice
1502 We want the remaining part of this melody on the lower staff, so we do a
1503 manual staff switch here.
1504
1505
1506
1507
1508 @separate
1509 @example 
1510 \context PianoStaff 
1511 @end example 
1512  A special context is needed to get cross staff beaming right.  This
1513 context is called @code{PianoStaff}.
1514 @separate
1515 @example 
1516 \context Staff = bottom < \time 2/2 \clef bass 
1517 @end example 
1518 The bottom staff must have a different clef.
1519 @separate
1520 @example 
1521 indent = 0.0 
1522 @end example 
1523 To make some more room on the line, the first (in this case the only)
1524 line is not indented.  The line still looks very cramped, but that is due
1525 to the page layout of this document.
1526
1527
1528 @ignore
1529 [TODO:
1530
1531 * font-size, multi-stanza.
1532
1533 * Simple part combining in a Hymn
1534 @end ignore
1535
1536
1537 @node Fine tuning a piece
1538 @section  Fine tuning a piece
1539
1540 In this section we show some ways to fine tune the final output of a
1541 piece.  We do so using a single measure of a moderately complex piano
1542 piece: a Brahms intermezzo (opus 119, no. 1).  Both fragments (the
1543 tuned and the untuned versions) are in @file{input/tutorial/}.
1544
1545 The code for the untuned example shows us some new things.
1546
1547 @lilypondfile[verbatim]{brahms-original.ly}
1548
1549
1550 @cindex dynamics
1551 @cindex loudness
1552 @cindex forte
1553 @cindex crescendo
1554
1555
1556 @cindex fingering instructions
1557 [TODO: moveme]
1558
1559 Fingering indications are entered with @code{-@var{N}}, where
1560 @var{N} is a digit.
1561
1562 Now that we have the basic piece of music entered, we want to fine
1563 tune it so that we get something that resembles the original printed
1564 edition by Schott/Universal Edition:
1565
1566 @lilypondfile{brahms-tweaked.ly}
1567
1568 @cindex tuning graphical objects
1569
1570 Fine tuning involves overriding the defaults of the printing system.
1571 We do this by setting variables which control how Lilypond prints
1572 symbols.  Printed symbols are called graphical objects (often
1573 abbreviated to @emph{grob}). Each object is described by a bunch of
1574 settings.  Every setting is a variable: it has a name and a value
1575 which you can change.  These values determine the fonts, offsets,
1576 sub-routines to be called on the object, etc.  The initial values of
1577 these settings are set in the Scheme file
1578 @file{scm/grob-description.scm}.
1579
1580 @cindex slur attachments
1581
1582 We start with the slur in the upper part, running from F sharp to A.  In
1583 the printed edition, this slur runs from stem to stem; in our version,
1584 the slur begins at the note head of the F sharp.  The following property
1585 setting forces all slurs to run from stem to stem (not from or to note
1586 heads!).
1587
1588 @example
1589   \property Voice.Slur \set #'attachment = #'(stem . stem)
1590 @end example
1591
1592 More precisely, this command modifies the definition of the @code{Slur}
1593 object in the current @code{Voice}.  The variable @code{attachment} is
1594 set to the pair of symbols @code{'(stem . stem)}. 
1595
1596 @cindex internal documentation
1597 @cindex finding graphical objects
1598 @cindex graphical object descriptions 
1599
1600 This command fixes one particular problem with a slur. The rest of
1601 this section explains how to figure out which properties to tune for
1602 your own scores. To discover this, you must have a copy of the
1603 internals document. This is a set of HTML pages which should be
1604 included if you installed a binary distribution.  [TODO: revise for
1605 new site.]  These HTML pages are also available on the web: go to the
1606 LilyPond website, click ``Documentation: Index'' on the side bar, look
1607 in the ``Information for uses'' section, and click on ``Documentation
1608 of internals''.
1609
1610 You might want to bookmark either the HTML files on your disk, or the
1611 one on the web (the HTML on your hard drive will load much faster than
1612 the ones on the web!).  One word of caution: the internals
1613 documentation is generated from the definitions that the program uses.
1614 Hence, the internals documentation is strongly tied to the version you
1615 use.  Before you proceed, make sure that the program and documentation
1616 have matching version numbers.
1617
1618 @c  TODO: the quote is incorrect, although that shouldn't be a big
1619 @c    problem for the reader.
1620 Suppose that you wanted to tune the behavior of the slur.  The first
1621 step is to get some general information on slurs in LilyPond.  Turn to
1622 the index, and look up ``slur''. The section on slurs says
1623 @quotation
1624 The grob for this object is @internalsref{Slur}, generally in
1625 @internalsref{Voice} context.
1626 @end quotation
1627
1628 So the graphical object for this object is called @code{Slur}, and
1629 slurs are created in the @code{Voice} context.  If you are reading
1630 this tutorial in the HTML version, then you can simply click Slur,
1631 otherwise, you should look it up the internal documentation: click
1632 ``grob overview'' and select ``slur'' (the list is alphabetical).
1633
1634 Now you get a list of all the properties that the slur object
1635 supports, along with their default values.  Among the properties we
1636 find the @code{attachment} property with its default setting.  
1637 The property documentation explains that the following setting will
1638 produce the desired effect:
1639 @example 
1640  \property Voice.Slur \set #'attachment = #'(stem . stem)
1641 @end example
1642
1643 @c this is a long section, and adding an extra space here helps to
1644 @c break it into smaller subsections and thus is easier to understand.
1645 @separate
1646
1647 Next we want to move the fingering `3'.  In the printed edition it is
1648 not above the stem, but a little lower and slightly left of the stem.
1649 From the user manual we find that the associated graphical object is
1650 called @code{Fingering}, but how do we know if we should use
1651 @code{Voice} or @code{Staff}?  In many cases, @code{Voice} is a safe
1652 bet, but you can also deduce this information from the internals
1653 documentation: if you visit the documentation of @code{Fingering}, you
1654 will notice
1655 @example
1656 Fingering grobs are created by: Fingering_engraver
1657 @end example
1658
1659 Clicking @code{Fingering_engraver} will show you the documentation of
1660 the module responsible for interpreting the fingering instructions and
1661 translating them to a @code{Fingering} object.  Such a module is called
1662 an @emph{engraver}.  The documentation of the @code{Fingering_engraver}
1663 says
1664 @example
1665 Fingering_engraver is part of contexts: Voice and TabVoice
1666 @end example
1667 so tuning the settings for Fingering should be done using either
1668 @example
1669   \property Voice.Fingering \set @dots{}
1670 @end example
1671 or
1672 @example
1673   \property TabVoice.Fingering \set @dots{}
1674 @end example
1675
1676 Since the @code{TabVoice} is only used for tab notation, we see that
1677 the first guess @code{Voice} was indeed correct.
1678
1679 @cindex setting object properties
1680 @cindex @code{extra-offset}
1681
1682 For shifting the fingering, we use the property @code{extra-offset}.
1683 The following command manually adds an offset to the object.  We move
1684 it a little to the left, and 1.8 staff space downwards.
1685 @example
1686  \once \property Voice.Fingering \set #'extra-offset = #'(-0.3 . -1.8) 
1687 @end example   
1688 The @code{extra-offset} is a low-level feature: it moves around
1689 objects in the printout; the formatting engine is completely oblivious
1690 to these offsets.  The unit of these offsets are staff-spaces.  The
1691 first number controls left-right movement; a positive number will move
1692 the object to the right.  The second number controls up-down movement;
1693 a positive number will move it higher.
1694 We only want to offset a single object, so this statement is adorned
1695 with @code{\once}.
1696
1697 @cindex property types
1698 @cindex translator properties
1699 @cindex grob properties
1700 @cindex music properties
1701 @separate
1702
1703 There are three different types of variables in LilyPond, something
1704 which can be confusing at first (and for some people it stays
1705 confusing).  Variables such as @code{extra-offset} and
1706 @code{attachment} are called grob properties.  They are not the same
1707 as translator properties, like @code{autoBeaming}.  Finally, music
1708 expressions are internally stored using properties (so-called music
1709 properties).  You will encounter music properties if you run Scheme
1710 functions on music using @code{\apply}.
1711
1712 The second fingering instruction should be moved up a little to avoid
1713 a collision with the slur.  This could be achieved with
1714 @code{extra-offset}, but in this case, a simpler mechanism also
1715 works.  We insert an empty text between the 5 and the note. The empty
1716 text pushes the fingering instruction away:
1717 @example
1718   a-)^" "^\markup @{ \finger "5" @} 
1719 @end example
1720
1721 A fingering instruction, which would be entered as @code{^5}, is put
1722 as close to the notes as possible, closer than the space entered to
1723 push away the 5. Hence, the 5 is entered as a normal text, with the
1724 formatting of fingering instructions.
1725  
1726 @separate
1727
1728 Normally one would specify all dynamics in the same voice, so that
1729 dynamics (such as @b{f} and @b{p}) will be aligned with hairpins.  But
1730 in this case, we do not want the decrescendo to be aligned with the
1731 piano sign.  We achieve this by putting the dynamic markings in different
1732 voices.  The crescendo should be above the upper staff.  This can be
1733 forced by using the precooked command 
1734 @example
1735   \dynamicsUp
1736 @end example
1737
1738 However, if you do that the decrescendo will be too close to the upper
1739 voice and collide with the stems.  Looking at the manual for dynamics,
1740 we notice that ``Vertical positioning of these symbols is handled by
1741 the @internalsref{DynamicLineSpanner} grob.''.  If we turn to the
1742 documentation of @code{DynamicLineSpanner}, we find that
1743 @code{DynamicLineSpanner} supports several so-called `interfaces'.
1744 This object not only puts objects next to the staff
1745 (@code{side-position-interface}), but it also groups dynamic objects
1746 (@code{axis-group-interface}), is considered a dynamic sign itself
1747 (@code{dynamic-interface}), and is an spanning object
1748 (@code{spanner-interface}).  It also has the standard
1749 @code{grob-interface} with all the variables that come with it.
1750
1751 For the moment we are interested in side positioning:
1752 @quotation
1753  side-position-interface
1754
1755   Position a victim object (this one) next to other objects (the
1756   support).  In this case, the direction signifies where to put the
1757   victim object relative to the support (left or right, up or down?)
1758 @end quotation
1759 Between the object and its support (in this case, the descending
1760 notes), there should be more space.  This space is controlled by
1761 @code{padding}, so we increase it.
1762 @example
1763  \property Voice.DynamicLineSpanner \override #'padding = #5.0
1764 @end example
1765
1766 This command resembles the one for setting slur attachments, but
1767 subtly differs in its details.  Grob properties can be manipulated
1768 with two commands: @code{\override} extends the definition of a grob
1769 with one setting, and @code{\revert} releases this setting.  This has
1770 a theoretical appeal: the operations are simple and symmetric.  For
1771 practical use, it can be cumbersome.  The commands act like
1772 parentheses: you should carefully balance the use of @code{\override}
1773 and @code{\revert}.  The @code{\set} command is more friendly: it
1774 first does a @code{\revert} followed by @code{\override}.
1775
1776 @separate
1777
1778 Brahms uses music notation is a slightly unorthodox way.  Ties
1779 usually happen only within one voice.  In this piece, the composer
1780 gladly produces ties that jump voices.  We deal with this by faking
1781 these ties: whenever we need such a tie, we insert a notehead in a
1782 different voice, and blank the stem.  This is done in the following
1783 snippet of code.
1784
1785 @cindex transparent objects
1786 @cindex removing objects
1787 @cindex invisible objects
1788 @example
1789 \property Voice.Stem \set #'transparent = ##t
1790 d'
1791 @end example
1792 Blanking the stem should be done for only one object. One of the ways
1793 to achieve that, is by setting the property before a note. Reverting
1794 it afterwards is tedious, so for setting a property only once, we have
1795 the syntax @code{\once}: it reverts the property directly before
1796 proceeding to the next step in time.
1797
1798 The @code{\once} keyword is added to @code{\property}.
1799
1800
1801 Finally, the last tie is forced up using @code{\tieUp}.
1802
1803 @separate
1804
1805 Here is the complete ``fine tuned'' version, which includes all the
1806 modifications we discussed in this section:
1807
1808 @lilypondfile[verbatim]{brahms-tweaked.ly}
1809
1810
1811 @node An orchestral score
1812 @section An orchestral score
1813
1814 @menu
1815 * The full score::              
1816 * Extracting an individual part::  
1817 @end menu
1818
1819
1820 Our next two examples demonstrate one way to create an orchestral score
1821 in LilyPond.  When typesetting a piece for several instruments, you'll
1822 want to create a full score (for the conductor) along with several
1823 individual parts (for the players).
1824
1825   We will declare the music for each instrument individually, giving
1826 the music of each instrument its own name.  These pieces of music are
1827 then combined in different @code{\score} blocks to produce different
1828 combinations of instruments (for example, one @code{\score} block may
1829 only include the cello part; another @code{\score} block may be for
1830 all the strings, and yet another @code{\score} block may be for all
1831 parts together).
1832
1833 This orchestral score example consists of three input files.  In the
1834 first file, @file{os-music.ly}, we define the music for all
1835 instruments.  This file will be used for producing the score and the
1836 separate parts, but the file does not produce any sheet music itself.
1837 Other files reference it by stating @code{\include "os-music.ly"}.
1838
1839 @example
1840 % os-music.ly
1841 \header @{
1842   title = "Zo, goed lieverd?"
1843   subtitle = "How's, this babe?"
1844   composer = "JCN"
1845   opus = "1"
1846   piece = "Laid back"
1847 @}
1848 global = @{
1849   \time 2/4
1850   \skip 2*4 \bar "|."
1851 @}
1852 Key = \notes \key as \major
1853 flautoI = \notes\relative c'' @{
1854   f8 g f g f g f g
1855   bes as bes as bes as bes as
1856 @}
1857 flautoII = \notes\relative c'' @{
1858   as8 bes as bes R1 d4 ~ d
1859 @}
1860 tromboI = \notes\relative c'' @{
1861   c4. c8 c8 c4. es4 r as, r
1862 @}
1863 tromboII = \notes\relative c'' @{
1864   as4. as8 as8 as4. R1*1/2 as4 es'
1865 @}
1866 timpani = \notes\relative c, @{
1867   \times 2/3 @{ f4 f f @}
1868   \times 4/5 @{ as8 as as as as @}
1869   R1
1870 @}
1871 corno = \notes\relative c' @{
1872    bes4 d f, bes d f, bes d
1873 @}
1874 @end example
1875
1876 We will not examine this example line by line, since you already know
1877 most of it.  We'll examine a few lines which contain new elements.
1878
1879
1880 @separate
1881 @example
1882 global = @{
1883   \time 2/4
1884   \skip 2*4 \bar "|."
1885 @}
1886 @end example
1887
1888 This declares settings to be used globally.  The @code{\skip} command
1889 produces no output, but moves forward in time: in this case, the
1890 duration of a half note (@code{2}), and that four times (@code{*4}).
1891 This brings us to the end of the piece, and we can set the end bar.
1892 You can use @code{s} as a shortcut for @code{\skip} (the last line of
1893 this section would be @code{s2*4 \bar"|."}).
1894
1895 @separate
1896 @example
1897 Key = \notes \key as \major
1898 @end example
1899 This declares the key signature of the piece and assign it to the
1900 identifier @var{Key}.  Later on we will use @code{\Key} for all staves
1901 except those for transposing instruments.
1902
1903 @node The full score
1904 @subsection The full score
1905
1906
1907 The second file, @inputfileref{input/tutorial,os-score.ly}, reads the
1908 definitions of the first (@inputfileref{input/tutorial,os-music.ly}), and
1909 defines the @code{\score} block for the full conductor's score.
1910
1911 @example
1912 \version "1.7.6"
1913
1914 \include "os-music.ly"
1915 \include "paper13.ly"
1916
1917 textFlat = \markup @{\smaller \musicglyph #"accidentals--1"@}
1918 \score @{
1919   <
1920     \global
1921     \property Score.BarNumber \override #'padding = #3
1922     \context StaffGroup = woodwind <
1923       \context Staff = flauti <
1924         \property Staff.midiInstrument = #"flute"
1925         \property Staff.instrument = "2 Flauti"
1926         \property Staff.instr = "Fl."
1927         \Key
1928         \context Voice=one @{ \voiceOne \flautoI @}
1929         \context Voice=two @{ \voiceTwo \flautoII @}
1930       >
1931     >
1932     \context StaffGroup = timpani <
1933       \context Staff = timpani <
1934         \property Staff.midiInstrument = #"timpani"
1935         \property Staff.instrument = \markup @{ \column <<  "Timpani" "(C-G)" >> @}
1936         \property Staff.instr = #"Timp."
1937         \clef bass
1938         \Key
1939         \timpani
1940       >
1941     >
1942     \context StaffGroup = brass <
1943       \context Staff = trombe <
1944         \property Staff.midiInstrument = #"trumpet"
1945         \property Staff.instrument = \markup @{ \column << "2 Trombe" "(C)" >> @}
1946         \property Staff.instr = \markup@{ \column << "Tbe." "(C)">> @}
1947         \Key
1948         \context Voice=one \partcombine Voice
1949           \context Thread=one \tromboI
1950           \context Thread=two \tromboII
1951       >
1952       \context Staff = corni <
1953         \property Staff.midiInstrument = #"french horn"
1954         \property Staff.instrument
1955         = \markup @{ \column << "Corno" @{ "(E"  \textFlat ")" @} >> @}
1956         \property Staff.instr =
1957         \markup @{ \column << "Cor." @{ "(E"  \textFlat ")" @} >> @}
1958         \property Staff.transposing = #3
1959         \notes \key bes \major
1960         \context Voice=one \corno
1961       >
1962     >
1963   >
1964   \paper @{
1965     indent = 15 * \staffspace
1966     linewidth = 60 * \staffspace
1967     textheight = 90 * \staffspace
1968     \translator@{
1969       \VoiceContext
1970       \consists "Multi_measure_rest_engraver"
1971     @}
1972     \translator@{
1973       \HaraKiriStaffContext
1974       \remove "Multi_measure_rest_engraver"
1975     @}
1976   @}
1977   \midi @{
1978     \tempo 4 = 75
1979   @}
1980 @}
1981 @end example
1982
1983 @center @strong{Zo, goed lieverd?}
1984 @sp 1
1985 @center How's, this babe?
1986 @flushright
1987 Opus 1.
1988 @end flushright
1989 @flushleft
1990 @sc{Laid back}
1991 @end flushleft
1992
1993 @lilypondfile{os-score.ly}
1994
1995 @separate
1996 @example
1997 \include "os-music.ly"
1998 @end example
1999 First we need to include the music definitions we made in
2000 @file{os-music.ly}.
2001
2002 @ignore
2003
2004 [TODO: mention in a more relevant place]
2005   
2006 @separate
2007 @example
2008 #(ly:set-point-and-click 'line-column)
2009 @end example
2010
2011 This piece of Scheme code executes the function
2012 @code{ly:set-point-and-click} with the argument
2013 @code{line-column}.  Editing input files can be complicated if you are
2014 working with large files: if you are digitizing existing music, you have
2015 to synchronize the .ly file, the sheet music on your lap and the sheet
2016 music on the screen.  The point-and-click mechanism makes it easy to
2017 find the origin of an error in the LY file: when you view the file with
2018 Xdvi and click on a note, your editor will jump to the spot where that
2019 note was entered.  For more information, see @ref{Point and click}.
2020 @end ignore
2021
2022
2023 @separate
2024 @example
2025 #(define text-flat '((font-relative-size . -2)
2026          (music "accidentals--1")))
2027 @end example
2028
2029 To name the transposition of the french horn, we will need a piece of
2030 text with a flat sign.  LilyPond has a mechanism for font selection and
2031 kerning called Scheme markup text (See @ref{Text markup}).  The flat
2032 sign is taken from the music font, and its name is @code{accidentals--1}
2033 (The natural sign is called @code{accidentals-0}).  The default font is
2034 too big for text, so we select a relative size of @code{-2}.
2035
2036 @separate
2037 @example
2038   <
2039     \global
2040 @end example
2041 All staves are simultaneous and use the same global settings.
2042
2043 @separate
2044 @example
2045     \property Score.BarNumber \override #'padding = #3
2046 @end example
2047 LilyPond prints bar numbers at the start of each line, but
2048 unfortunately they end up a bit too close to the staff in this
2049 example.  In LilyPond, a bar number is called @var{BarNumber}.
2050 BarNumber objects can be manipulated through their
2051 @var{side-position-interface}.  One of the properties of a
2052 @var{side-position-interface} that can be tweaked is @var{padding}:
2053 the amount of extra space that is put between this and other objects.
2054 We set the padding to three staff spaces.
2055
2056 You can find information on all these kind of properties in LilyPond's
2057 automatically generated documentation in
2058 @ifnottex
2059 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}
2060 or in @ref{Fine tuning a piece}.
2061 @end ifnottex
2062 @iftex
2063 the online documentation or in the previous section of the tutorial.
2064 @end iftex
2065
2066 @c  REFERENCE MAO
2067
2068 @separate
2069 @example
2070     \context StaffGroup = woodwind <
2071       \context Staff = flauti <
2072 @end example
2073 A new notation context: the @code{StaffGroup}.  @code{StaffGroup} can
2074 hold one or more @code{Staff}s, and will print a big bracket at the
2075 left of the score.  This starts a new staff group for the woodwind
2076 section (just the flutes in this case).  Immediately after that, we
2077 start the staff for the two flutes, who also play simultaneously.
2078
2079 @separate
2080 @example
2081         \property Staff.midiInstrument = #"flute"
2082 @end example
2083 Specify the instrument for MIDI output (see @ref{MIDI instrument
2084 names}).
2085
2086 @separate
2087 @example
2088         \property Staff.instrument = "2 Flauti"
2089         \property Staff.instr = "Fl."
2090 @end example
2091 This defines the instrument names to be printed in the
2092 margin.  @code{instrument} specifies the name for the first line
2093 of the score, @code{instr} is used for the rest of the score.
2094
2095 @separate
2096 @example
2097         \Key
2098 @end example
2099 The flutes play in the default key.
2100
2101 @separate
2102 @example
2103         \context Voice=one @{ \voiceOne \flautoI @}
2104         \context Voice=two @{ \voiceTwo \flautoII @}
2105 @end example
2106 Last come the actual flute parts.  Remember that we are still in
2107 simultaneous mode.  We name both voices differently, so that LilyPond
2108 will create two Voice contexts.  The flute parts are simple, so
2109 we specify manually which voice is which: @code{\voiceOne} forces the
2110 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
2111 directions down.
2112
2113 @separate
2114 @example
2115       >
2116     >
2117 @end example
2118 Close the flutes staff and woodwind staff group.
2119
2120 @separate
2121 @example
2122         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2123 @end example
2124 The timpani staff demonstrates a new piece of scheme markup, it sets two
2125 lines of text.
2126
2127 @separate
2128 @example
2129         \context Voice=one \partcombine Voice
2130           \context Thread=one \tromboI
2131           \context Thread=two \tromboII
2132 @end example
2133 You have seen the notation contexts Staff and Voice, but here is a new
2134 one: Thread.  One or more Threads can be part of a Voice.  Thread
2135 takes care of note heads and rests; Voice combine note heads onto a
2136 stem.
2137
2138 For the trumpets we use the automatic part combiner (see @ref{Automatic
2139 part combining}) to combine the two simultaneous trumpet parts onto the
2140 trumpet staff.  Each trumpet gets its own Thread context, which must be
2141 named @code{one} and @code{two}).  The part combiner makes these two
2142 threads share a Voice when they are similar, and splits the threads up
2143 when they are different.
2144
2145 @separate
2146 @example
2147 \property Staff.instrument = #`(lines "Corno"
2148   (columns "(E" ,text-flat ")"))
2149 @end example
2150 The french horn (``Corno'') has the most complex scheme markup name, made
2151 up of two lines of text.  The second line has three elements (columns) --
2152 the @code{(E}, the flat sign @code{text-flat} that we defined previously,
2153 and a final @code{")"}.  We use a backquote instead of an
2154 ordinary quote at the beginning of the Scheme expression to be able to
2155 access the @code{text-flat} identifier, `unquoting' it with a ``@code{,}''.
2156
2157 @separate
2158 @example
2159         \property Staff.transposing = #3
2160 @end example
2161 The french horn is to be tuned in E-flat, so we tell the MIDI back-end to
2162 transpose this staff by three steps.
2163
2164 Note how we can choose different tunings for the text input, sheet music
2165 output and, and MIDI output, using @code{\transpose} and the MIDI Staff
2166 property @var{transposing}.
2167
2168 @separate
2169 @example
2170         \notes \key bes \major
2171 @end example
2172 Since the horn is transposing, it is in a different key.
2173
2174 @separate
2175 @example
2176     indent = 15 * \staffspace
2177     linewidth = 55 * \staffspace
2178 @end example
2179 We specify a big indent for the first line and a small linewidth for this
2180 tutorial.
2181
2182 @separate
2183
2184 Usually the default setup of notation contexts (Thread, Voice, Staff,
2185 Staffgroup, Score) is just fine.  But in this case we want a different
2186 type of Staff context.
2187
2188 @example
2189     \translator@{
2190       \HaraKiriStaffContext
2191     @}
2192 @end example
2193
2194 In orchestral scores it often happens that one instrument only has
2195 rests during one line of the score.  @code{HaraKiriStaffContext} can
2196 be used as a regular @code{StaffContext} drop-in and will take care of
2197 the automatic removing of empty staves -- so if the strings are the
2198 only instruments playing for a line, LilyPond will only print the string
2199 parts for that line of the score.  This reduces the number of page turns
2200 (and the number of dead trees!) required in a score.
2201
2202 @node Extracting an individual part
2203 @subsection Extracting an individual part
2204
2205 The third file, @file{os-flute-2.ly} also reads the definitions of the
2206 first (@file{os-music.ly}), and defines the @code{\score} block for the
2207 second flute part.
2208
2209 @example
2210 \include "os-music.ly"
2211 \include "paper16.ly"
2212
2213 \score @{
2214   \context Staff <
2215     \property Score.skipBars = ##t
2216     \property Staff.midiInstrument = #"flute"
2217     \global
2218     \Key
2219     \flautoII
2220   >
2221   \header @{
2222     instrument = "Flauto II"
2223   @}
2224   \paper @{
2225     linewidth = 80 * \staffspace
2226     textheight = 200 * \staffspace
2227   @}
2228   \midi @{
2229     \tempo 4 = 75
2230   @}
2231 @}
2232 @end example
2233
2234 @center @strong{Zo, goed lieverd?}
2235 @sp 1
2236 @center How's, this babe?
2237 @center @emph{Flauto II}
2238 @flushright
2239 Opus 1.
2240 @end flushright
2241 @flushleft
2242 @sc{Laid back}
2243 @end flushleft
2244 @lilypondfile{os-flute-2.ly}
2245
2246
2247 Because we separated the music definitions from the @code{\score}
2248 instantiations, we can easily define a second score with the music of
2249 the second flute.  This is the part for the second flute player.  Of
2250 course, we would make separate parts for all individual instruments if
2251 we were preparing the score for an orchestra.
2252
2253 @separate
2254 @example
2255     \flautoII
2256 @end example
2257 In this individual part the second flute has a whole staff for itself,
2258 so we do not want to force stem or tie directions.
2259
2260 @separate
2261 @example
2262   \header @{
2263     instrument = "Flauto II"
2264   @}
2265 @end example
2266 The @code{\header} definitions were also read from @file{os-music.ly},
2267 but we need to set the instrument for this particular score.
2268
2269 @separate
2270 @example
2271     \property Score.skipBars = ##t
2272 @end example
2273 In the conductor's full score, all bars with rests are printed, but for
2274 the individual parts, we want to print one multimeasure rest instead of
2275 many consecutive empty bars.  LilyPond will do this if
2276 @code{Score.skipBars} is set to true (@code{##t}).
2277
2278
2279 @node Integrating text and music
2280 @section Integrating text and music
2281
2282
2283 @cindex La@TeX{}, music in
2284 @cindex HTML, music in
2285 @cindex Texinfo, music in
2286
2287 Sometimes you might want to use music examples in a text that you are
2288 writing (for example a musicological treatise, a songbook, or (like us)
2289 the LilyPond manual).  You can make such texts by hand, simply by
2290 importing a PostScript figure into your word processor.  However,
2291 there is an automated procedure to reduce the amount of work.
2292
2293 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
2294 code.  A script called @code{lilypond-book} will extract the music
2295 fragments, run LilyPond on them, and put back the resulting notation.
2296 This program is fully described in @ref{lilypond-book manual}.  Here
2297 we show a small example.  Since the example also contains explanatory
2298 text, we will not comment it further.
2299
2300 @example
2301 \documentclass[a4paper]@{article@}
2302 \begin@{document@}
2303
2304 In a lilypond-book document, you can freely mix music and text. For
2305 example:
2306 \begin@{lilypond@}
2307   \score @{ \notes \relative c' @{
2308      c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
2309   @} @}
2310 \end@{lilypond@}
2311
2312 Notice that the music line length matches the margin settings of the
2313 document.
2314
2315 If you have no \verb+\score+ block in the fragment,
2316 \texttt@{lilypond-book@} will supply one:
2317
2318 \begin@{lilypond@}
2319   c'4
2320 \end@{lilypond@}
2321
2322 In the example you see here, two things happened: a
2323 \verb+\score+ block was added, and the line width was set to natural
2324 length. You can specify many more options using  \LaTeX style options
2325 in brackets:
2326
2327 \begin[verbatim,11pt,singleline,
2328   fragment,relative,intertext="hi there!"]@{lilypond@}
2329   c'4 f bes es
2330 \end@{lilypond@}
2331
2332 The option \texttt@{verbatim@} prints the LilyPond code in addition to
2333 the graphical score, \texttt@{11pt@} selects the default music size,
2334 \texttt@{fragment@} adds a score block, \texttt@{relative@} uses
2335 relative mode for the fragment, and \texttt@{intertext@} specifies
2336 what to print between the \texttt@{verbatim@} code and the music.
2337
2338 If you want to include large examples into the text, it may be more
2339 convenient to put the example in a separate file:
2340
2341 \lilypondfile[printfilename]@{sammartini.ly@}
2342
2343 The \texttt@{printfilename@} option adds the file name to the output.
2344
2345 \end@{document@}
2346 @end example
2347
2348 Under Unix, you can view the results as follows.
2349 @example
2350 $ cd input/tutorial
2351 $ mkdir -p out/
2352 $ lilypond-book --outdir=out/ lilbook.tex
2353 lilypond-book (GNU LilyPond) 1.7.16
2354 Reading `input/tutorial/lilbook.tex'
2355 Reading `input/tutorial/sammartini.ly'
2356 @var{lots of stuff deleted}
2357 Writing `out/lilbook.latex'
2358 $ cd out
2359 $ latex lilbook.latex
2360 @var{lots of stuff deleted}
2361 $ xdvi lilbook 
2362 @end example
2363
2364 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
2365 and running latex creates a lot of temporary files, and you would not want
2366 those to clutter up your working directory. Hence, we have them created
2367 in a separate subdirectory.
2368
2369 The result looks more or less like this: 
2370
2371 @separate
2372
2373 In a lilypond-book document, you can freely mix music and text. For
2374 example:
2375 @lilypond
2376 \score {
2377   \notes \relative c' {
2378     c2 g'2 \times 2/3 { f8 e d } c'2 g4
2379   }
2380   \paper {
2381     raggedright = ##t
2382   }
2383 }
2384 @end lilypond
2385
2386 Notice that the music line length matches the margin settings of the
2387 document.
2388
2389 If you have no @code{\score} block in the fragment,
2390 @code{lilypond-book} will supply one:
2391
2392 @lilypond
2393   c'4
2394 @end lilypond
2395
2396 In the example you see here, a number of things happened: a
2397 @code{\score} block was added, and the line width was set to natural
2398 length. You can specify many more options using  La@TeX{} style options
2399 in brackets:
2400
2401 @lilypond[verbatim,11pt,singleline,
2402   fragment,relative,intertext="hi there!"]
2403   c'4 f bes es
2404 @end lilypond
2405
2406 The option @code{verbatim} also shows the LilyPond code, @code{11pt} selects
2407 the default music size, @code{fragment} adds a score block,
2408 @code{relative} uses relative mode for the fragment, and
2409 @code{intertext} specifies what to print between the
2410 @code{verbatim} code and the music.
2411
2412 If you include large examples into the text, it may be more convenient
2413 to put the example in a separate file:
2414
2415 @lilypondfile[printfilename]{sammartini.ly}
2416
2417 The @code{printfilename} option adds the file name to the output.
2418
2419 [TODO: include excercises? ]