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