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