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