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