]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
Numerous editorial and stylistic changes to manual.
[lilypond.git] / Documentation / user / tutorial.itely
1 @c -*-texinfo-*-
2 @c This file is part of lilypond.tely
3
4 @c TODO:
5 @c   * more details about running lilypond; error messages,
6 @c     compiling/viewing (emacs?)
7 @c   * where to go from First steps+More basics?
8
9 @c Your first LilyPond score in 10 minutes?
10
11 @node Tutorial
12 @chapter Tutorial
13
14 This tutorial starts with a short introduction to the LilyPond music
15 language.  After this first contact we will show you how to produce
16 printed output.  Then you will be able to create and print your own
17 sheets of music.
18
19 @ifhtml
20 Many people learn programs by trying and fiddling around with the
21 program.  This is also possible with LilyPond.  If you click on a
22 picture in the HTML version of this manual, you will see the exact
23 LilyPond input that was used to generate that image.
24 Try it on this image
25
26 @lilypond[fragment,quote,raggedright,relative=2]
27 c-\markup { \bold \huge { Click here.  } }
28 @end lilypond
29 @end ifhtml
30
31 By cutting and pasting the full input into a test file, you have a
32 starting template for experiments.  If you like learning in this way,
33 you will probably want to print out or bookmark
34 @ifhtml
35 the
36 @end ifhtml
37 @ref{Cheat sheet}, which is a table listing all commands for quick
38 reference.
39
40 @menu
41 * First steps::                 
42 * Running LilyPond for the first time::  
43 * More about pitches::          
44 * Entering ties::               
45 * Automatic and manual beams::  
46 * Octave entry::                
47 * Music expressions explained::  
48 * More staves::                 
49 * Adding articulation marks to notes::  
50 * Combining notes into chords::  
51 * Advanced rhythmic commands::   
52 * Commenting input files::      
53 * Printing lyrics::             
54 * A lead sheet::                
55 * Adding titles::               
56 * Single staff polyphony::      
57 * Piano staves::                
58 * Organizing larger pieces::    
59 * An orchestral part::          
60 @end menu
61
62
63 @node First steps
64 @section First steps
65
66 The first example demonstrates how to enter the most elementary piece
67 of music, a scale.  A note can be entered by typing its name, from
68 @samp{a} through @samp{g}.  So, if you enter
69
70 @example
71 c d e f g a b
72 @end example
73
74 @noindent
75 the result looks like this
76
77 @lilypond[fragment,quote,notime,relative=1]
78 c d e f g a b
79 @end lilypond
80
81 The duration of a note is specified by a number after the note name.
82 @samp{1} for a @rglos{whole note}, @samp{2} for a @rglos{half note},
83 @samp{4} for a @rglos{quarter note} and so on
84
85 @example
86 a1 a2 a4 a16 a32
87 @end example
88
89 @c FIXME: have NOTIME also remove Score.timing?
90 @lilypond[fragment,quote,notime,relative=2]
91 \set Score.timing = ##f
92 \set Staff.autoBeaming = ##f
93 { a1 a2 a4 a16 a32 s16_" " }
94 @end lilypond
95
96 If you do not specify a @rglos{duration}, the duration last entered is
97 used for the next notes.  The duration of the first note in input
98 defaults to a quarter
99
100 @example
101 a a8 a a2 a
102 @end example
103
104 @lilypond[fragment,quote,notime,relative=2]
105 \set Score.timing = ##f
106 { a a8 a a2 a s16_" " }
107 @end lilypond
108
109
110 Rests are entered just like notes, but with the name @samp{r}
111
112 @cindex rests
113 @example
114 r2 r4 r8 r16
115 @end example
116
117 @lilypond[fragment,quote,notime]
118 \set Score.timing = ##f
119 r2 r4 r8 r16 s16_" "
120 @end lilypond
121
122 Add a dot @samp{.} after the duration to get a @rglos{dotted note}
123
124 @example
125 a2. a4 a8. a16
126 @end example
127
128 @lilypond[fragment,quote,notime,relative=1]
129 \set Score.timing = ##f
130 { a2. a4 a8. a16 s16_" " }
131 @end lilypond
132
133 The @rglos{meter} (or @rglos{time signature}) can be set with the
134 @code{\time} command
135
136 @example
137 \time 3/4
138 \time 6/8
139 \time 4/4
140 @end example
141
142 @c A clef here may lead to confusion, remove it.
143 @lilypond[fragment,quote]
144 \override Staff.Clef #'transparent = ##t 
145 \time 3/4
146 s4_" "
147 \time 6/8
148 s4_" "
149 \time 4/4
150 s16_" "
151 @end lilypond
152
153 The @rglos{clef} can be set using the @code{\clef} command
154
155 @c what is more common name treble or violin?
156 @c in Dutch, it is violin.
157 @c in English it is definitely treble.
158 @example
159 \clef treble
160 \clef bass
161 \clef alto
162 \clef tenor
163 @end example
164
165 @lilypond[fragment,quote,notime]
166 \set Score.timing = ##f
167 \clef violin
168 s4_" "
169 \clef bass
170 s4_" "
171 \clef alto
172 s4_" "
173 \clef tenor
174 s16_" "
175 @end lilypond
176
177
178 Remember to enclose the notes and commands in curly braces
179 @code{@{@tie{}@dots{}@tie{}@}} to convert it to printable output.
180
181 @lilypond[fragment,quote,noindent,linewidth=55\staffspace]
182 {
183   \time 3/4
184   \clef bass
185   c2 e4 g2.
186   f4 e d c2 r4
187 }
188 @end lilypond
189
190 For more elaborate information on
191
192 @quotation
193 @table @asis
194 @item Entering pitches and durations
195 see 
196 @ref{Pitches}, and @ref{Durations}.
197 @item Clefs
198 see @ref{Clef}.
199 @item Rests
200 see @ref{Rests}.  
201 @item Time signatures and other timing commands
202 see @ref{Time signature}.
203 @end table
204 @end quotation
205
206
207 @node Running LilyPond for the first time
208 @section Running LilyPond for the first time
209
210 @c cheesy title to avoid clash with chapter name.
211
212 @c FIXME: let's not be so casual about Emacs and VIM, but rather
213 @c instruct (how) to use them; let advanced user figure-out what
214 @c commands to type?
215
216 @c
217 @c We don't have enough space to explain either VIM
218 @c or Emacs non-advanced users, and I fear that both editors will only
219 @c confuse newbies.  I vote for keeping the material in footnotes.
220 @c 
221 @c --hwn 
222
223 In the last section we explained what kind of things you could enter
224 in a LilyPond file.  In this section we will explain what commands to
225 run and how to view or print the output.  If you have not used
226 LilyPond before, want to test your setup, or want to run an example
227 file yourself, read this section.  The instructions that follow are
228 for Unix-like systems.  Some additional instructions for Microsoft
229 Windows are given at the end of this section.
230
231 Begin by opening a terminal window and starting a text editor.  For
232 example, you could open an xterm and execute
233 @code{joe}.@footnote{There are macro files for VIM addicts, and there
234 is a @code{LilyPond-mode} for Emacs addicts.  If they have not been
235 installed already, refer to
236 @c FIXME lousy reference.
237 the file @file{INSTALL.txt}.}  In your text editor, enter the following
238 input and save the file as @file{test.ly}
239
240 @example
241 @{ c'4 e' g' @}
242 @end example
243
244 @noindent
245 To process @file{test.ly}, proceed as follows
246
247 @example
248 lilypond test.ly
249 @end example
250
251 @noindent
252 You will see something resembling
253
254 @example
255 lilypond (GNU LilyPond) 2.2.0
256 Running lilypond...
257 Now processing `/home/fred/ly/test.ly'
258 Parsing...
259 Interpreting music...[1]
260 @emph{... more interesting stuff ... }
261 DVI output to `test.dvi'...
262 PDF output to `test.pdf'...
263 PS output to `test.ps'...
264 @end example
265
266 @cindex DVI file
267 @cindex Viewing music
268 @cindex xdvi
269 @noindent
270 The result is the file @file{test.pdf}@footnote{For @TeX{}
271 aficionados: there is also a @file{test.dvi} file.  It can be viewed
272 with @code{xdvi}.  The DVI uses a lot of PostScript specials, which do
273 not show up in the magnifying glass.  The specials also mean that the
274 DVI file cannot be processed with @code{dvilj}.  Use @code{dvips} for
275 printing.
276 @cindex dvips
277 @cindex dvilj
278 @cindex DVI driver
279 } which you can print or with the standard facilities of your
280 operating system.@footnote{If your system does not have any tools
281 installed, you can try
282 @uref{http://www.cs.wisc.edu/~ghost/,Ghostscript}, a freely available
283 package for viewing and printing PDF and PostScript files.}
284
285 On Windows, start up a text-editor@footnote{Any simple or
286 programmer-oriented editor will do, for example Notepad.  Do not use a
287 word processor, since these insert formatting codes that will confuse
288 LilyPond.} and enter
289
290 @example
291 @{ c'4 e' g' @}
292 @end example
293
294 Save it on the desktop as @file{test.ly} and make sure that it is not
295 called @file{test.ly.TXT}.  Double clicking @file{test.ly} will process
296 the file and show the resulting PDF file.
297
298
299 @node More about pitches
300 @section More about pitches 
301
302 A @rglos{sharp} (@texisharp{}) pitch is made by adding @samp{is} to
303 the name, a @rglos{flat} (@texiflat{}) pitch by adding @samp{es}.  As
304 you might expect, a @rglos{double sharp} or @rglos{double flat} is
305 made by adding @samp{isis} or @samp{eses}@footnote{This syntax
306 derived from note naming conventions in Nordic and Germanic languages,
307 like German and Dutch.}
308
309 @example
310 cis1 ees fisis aeses
311 @end example
312
313 @lilypond[fragment,quote,notime]
314 \set Score.timing = ##f
315 \transpose c c' { cis1 ees fisis aeses s16_" " }
316 @end lilypond
317
318 @cindex key signature, setting
319 The key signature is set with the command @code{\key}, followed by
320 a pitch and @code{\major} or @code{\minor}
321
322 @example
323 \key d \major
324 g1
325 \key c \minor
326 g
327 @end example
328
329 @lilypond[fragment,quote,notime,fragment]
330 \key d \major
331 g'1
332 \key c \minor
333 g'
334 @end lilypond
335
336 @noindent
337 Key signatures together with the pitches (including alterations) are
338 used to determine when to print accidentals.  This is a
339 feature that often causes confusion to newcomers, so let us explain it
340 in more detail.
341
342
343 LilyPond makes a sharp distinction between musical content and
344 layout.  The alteration (flat, natural or sharp) of a note is part of
345 the pitch, and is therefore musical content.  Whether an accidental (a
346 flat, natural or sharp @emph{sign}) is printed in front of the
347 corresponding note is a question of layout.  Layout is something that
348 follows rules, so accidentals are printed automatically according to
349 those rules.  The pitches in your music are works of art, so they will
350 not be added automatically, and you must enter what you want to hear.
351
352 In this example
353
354 @lilypond[quote,notime,fragment]
355 \key d \major
356 d' cis' fis'
357 @end lilypond
358
359 @noindent
360 no note has an explicit accidental, but you still must enter
361
362 @example
363 \key d \major
364 d cis fis
365 @end example
366
367 @noindent
368 The code @samp{d} does not mean `print a black dot just below the
369 staff.'  Rather, it means: `a note with pitch D-natural.'  In the key
370 of A-flat, it does get an accidental
371
372 @lilypond[quote,notime,fragment]
373 \key as \major
374 d'
375 @end lilypond
376
377 @example
378 \key as \major
379 d
380 @end example
381
382 Adding all alterations explicitly might require a little more effort
383 when typing, but the advantage is that transposing is easier, and
384 accidentals can be printed according to different conventions.  See
385 @ref{Accidentals}, for some examples how accidentals can be printed
386 according to different rules.
387
388
389 For more information on
390
391 @quotation
392 @table @asis
393 @item Accidentals
394 see @ref{Accidentals}.
395
396 @item Key signature
397 see @ref{Key signature}.
398 @end table
399 @end quotation
400
401 @node Entering ties
402 @section Entering ties
403
404 @cindex tie
405 A tie is created by appending a tilde @samp{~} to the first note
406 being tied
407
408 @lilypond[quote,notime,fragment,verbatim,relative=3]
409 g4~ g a2~ a4
410 @end lilypond
411
412 For more information on Ties see @ref{Ties}.
413
414
415
416 @node Automatic and manual beams
417 @section Automatic and manual beams
418
419 @cindex beams, by hand 
420 Beams are drawn automatically
421
422 @lilypond[quote,fragment,relative=2,verbatim]
423 a8 ais d es r d
424 @end lilypond
425
426 @noindent
427 If you do not like where beams are put, they can be entered by
428 hand.  Mark the first note to be beamed with @samp{[} and the last one
429 with @samp{]}.
430
431 @lilypond[quote,fragment,relative=2,verbatim]
432 a8[ ais] d[ es r d]
433 @end lilypond
434
435 For more information on beams, see @ref{Beaming}.
436
437
438 Here are key signatures, accidentals and ties in action
439
440 @example
441 @{
442   \time 4/4
443   \key g \minor
444   \clef violin
445   r4 r8 a8 gis4 b
446   a8 d4.~ d e8
447   fis4 fis8 fis8 eis4 a8 gis~
448   gis2 r2
449 @}
450 @end example
451
452 @ignore
453 FIXME
454 ugr: removing the ignore block, leaving the comment line below
455 @c TODO: use relative mode, verbatim, junk \transpose and above @example
456 @end ignore
457
458
459 @lilypond[fragment,quote,noindent,linewidth=50\staffspace]
460 \transpose c c' {
461   \time 4/4
462   \key g \minor
463   \clef violin
464   r4 r8 a8 gis4 b
465   a8 d4.~ d e8
466   fis4 fis8 fis8 eis4 a8 gis~
467   gis2 r2
468 }
469 @end lilypond
470
471 @cindex accidentals
472
473
474 @noindent
475 There are some interesting points to note in this example.  Bar lines
476 and beams are drawn automatically.  Line breaks are calculated
477 automatically; it does not matter where the line breaks are in the
478 source file.  Finally, the order in which time, key and clef changes
479 are entered is not relevant: in the printout, these are ordered
480 according to standard notation conventions.
481
482
483
484 @node Octave entry
485 @section Octave entry
486
487
488 @c Tim wants to move this quotes example just before the: quotes-do not-work
489 @c score, but we'd need to remove quotes from the other two (key and
490 @c tie) examples...
491
492 @c better to have this just before the `octaves are bad' snipped
493 @c but we'd need to remove the ', from \key and tie 
494 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
495 the note name, to lower a note one octave, add a `low quote' @code{,}
496 (a comma).  Middle C is @code{c'}
497
498 @example
499 c'4 c'' c''' \clef bass c c,
500 @end example
501
502 @lilypond[quote,notime,fragment]
503 c'4 c'' c''' \clef bass c c,
504 @end lilypond
505
506 An example of the use of quotes is in the following Mozart fragment
507
508 @lilypond[quote,raggedright,fragment,verbatim]
509 \key a \major
510 \time 6/8
511 cis''8. d''16 cis''8 e''4 e''8
512 b'8. cis''16 b'8 d''4 d''8 
513 @end lilypond
514
515 @noindent
516 The last example shows that music in a high register needs lots of quotes.
517 This makes the input less readable, and it is a source of errors.  The
518 solution is to use `relative octave' mode.   This is the
519 most convenient way to copy existing music.
520
521 In relative mode, a note without octavation quotes (i.e.  the @code{'}
522 or @code{,} after a note) is chosen so it it is closest to the
523 previous one.  For example, @samp{c f} goes up while @samp{c g} goes
524 down
525
526 To use relative mode, add @code{\relative} before the piece of
527 music.  The first note is taken relative to the middle C
528 @c no , for this sentence
529 (i.e. @code{c'})
530
531
532
533 @lilypond[quote,notime,fragment,verbatim]
534 \relative {
535   c' f c g c
536 }
537 @end lilypond
538
539
540 Since most music has small intervals, pieces can be written almost
541 without octavation quotes in relative mode.  The previous example is
542 entered as
543
544 @lilypond[quote,raggedright,verbatim]
545 \relative {
546   \key a \major
547   \time 6/8
548   cis'8. d16 cis8 e4 e8
549   b8. cis16 b8 d4 d8
550 }
551 @end lilypond
552
553 @c needed better, maybe even redundant explanation
554 @c   added another example below.
555 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
556 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
557 Larger intervals are made by adding octavation quotes.
558
559 @lilypond[quote,notime,verbatim,fragment]
560 \relative c {
561   c'' f, f c' c g' c,
562 }
563 @end lilypond
564
565 In summary, quotes or commas no longer determine the absolute height
566 of a note in @code{\relative} mode.  Rather, the height of a note is
567 relative to the previous one, and changing the octave of a single note
568 shifts all following notes an octave up or down.
569
570 For more information on Relative octaves see @ref{Relative octaves},
571 and @ref{Octave check}.
572
573
574 @node Music expressions explained
575 @section Music expressions explained
576
577
578 In input files, music is represent by so-called @emph{music
579 expression}.  We have already seen in the previous examples; 
580 a single note is a music expression
581
582 @lilypond[fragment,quote,verbatim,relative=3]
583 a4
584 @end lilypond
585
586 Enclosing group of notes in braces creates a new music
587 expression
588
589 @lilypond[fragment,quote,verbatim,relative=3]
590 { a4 g4 }
591 @end lilypond
592
593 Putting a bunch of music expressions (notes) in braces, means that
594 they should be played in sequence.  The result again is a music
595 expression, which can be grouped with other expressions sequentially.
596 Here, the expression from the previous example is combined with two
597 notes
598
599 @lilypond[fragment,quote,verbatim,relative=3]
600 { { a4 g } f g } 
601 @end lilypond
602
603 This technique is useful for non-monophonic music.  To enter music
604 with more voices or more staves, we also combine expressions in
605 parallel.  Two voices that should play at the same time, are entered
606 as a simultaneous combination of two sequences.  A `simultaneous'
607 music expression is formed by enclosing expressions in @code{<<} and
608 @code{>>}.  In the following example, three sequences (all containing
609 two other notes) are combined simultaneously
610
611 @lilypond[fragment,quote,verbatim,relative=3]
612 <<
613    { a4 g }
614    { f e }
615    { d b }
616 >>
617 @end lilypond
618
619 This mechanism is similar to mathematical
620 formulas: a big formula is created by composing small formulas.  Such
621 formulas are called expressions, and their definition is recursive, so
622 you can make arbitrarily complex and large expressions.  For example,
623
624 @example
625 1
626
627 1 + 2
628
629 (1 + 2) * 3
630
631 ((1 + 2) * 3) / (4 * 5)
632 @end example
633
634 @cindex expression
635 @cindex music expression
636 This is a sequence of expressions, where each expression is contained
637 in the next one.  The simplest expressions are numbers, and larger
638 ones are made by combining expressions with operators (like @samp{+},
639 @samp{*} and @samp{/}) and parentheses.  Like mathematical expressions,
640 music expressions can be nested arbitrarily deep, which is necessary
641 for complex music like polyphonic scores.
642
643 Note that this example only has one staff, whereas
644 the previous example had three seperate staves.  That is because this
645 example begins with a single note.  To determine the number of staves,
646 LilyPond looks at the first element.  If it's a single note, there's one
647 staff; if there's a simultaneous expression, there's more than one staff.
648
649 @lilypond[fragment,quote,verbatim,relative=2] 
650 {
651   c <<c e>>
652   << { e f } { c <<b d>> } >>
653 }
654 @end lilypond
655
656 Music files with deep nesting can be confusing to enter and
657 maintain.  One convention that helps against this confusion is
658 indenting.  When entering a file with deep nesting of braces and
659 angles, it is customary to use an indent that indicates the nesting
660 level.  Formatting music like this eases reading and helps you insert
661 the right number of closing braces at the end of an expression.  For
662 example,
663
664 @example
665 <<
666   @{
667     @dots{}
668   @}
669   @{
670     @dots{}
671   @}
672 >>
673 @end example
674
675 Some editors have special support for entering LilyPond, and can help
676 indenting source files.  See @ref{Editor support} for more information.
677
678 @node More staves
679 @section More staves
680
681 To print more than one staff, each piece of music that makes up a
682 staff is marked by adding @code{\new Staff} before it.  These
683 @code{Staff} elements are then combined parallel with @code{<<} and
684 @code{>>}, as demonstrated here
685
686 @lilypond[quote,fragment,verbatim]
687 <<
688   \new Staff { \clef treble c'' }
689   \new Staff { \clef bass c }
690 >>
691 @end lilypond
692
693
694 The command @code{\new} introduces a `notation context.'  A notation
695 context is an environment in which musical events (like notes or
696 @code{\clef} commands) are interpreted.  For simple pieces, such
697 notation contexts are created automatically.  For more complex pieces, it
698 is best to mark contexts explicitly.  This ensures that each fragment
699 gets its own stave.
700
701 There are several types of contexts: @code{Staff}, @code{Voice} and
702 @code{Score} handle melodic notation.  Other contexts are also
703 @code{Lyrics} (for setting lyric texts) and @code{ChordNames} (for
704 printing chord names).
705
706
707 In terms of syntax, prepending @code{\new} to a music expression
708 creates a bigger music expression.  In this way it resembles the minus
709 sign in mathematics.  The formula @math{(4+5)} is an expression, so
710 @math{-(4+5)} is a bigger expression.
711
712 We can now typeset a melody with two staves
713
714 @c TODO: (c) status of this Paul McCartney (?) song (let's all stand together)
715
716 @lilypond[fragment,quote,verbatim,raggedright]
717 \relative <<
718   \new Staff {
719     \time 3/4
720     \clef treble 
721     
722     e'2 d4 c2 b4 a8[ a]
723     b[ b] g[ g] a2. 
724   }
725   \new Staff {
726      \clef bass
727      c,,2 e4 g2.
728      f4 e d c2.
729   }
730 >>
731 @end lilypond
732
733 For more information on context see the description in
734 @ref{Interpretation contexts}.
735
736
737
738 @node Adding articulation marks to notes
739 @section Adding articulation marks to notes
740
741 @cindex articulation
742 @cindex accents
743 @cindex staccato
744
745 Common accents can be added to a note using a dash (@samp{-}) and a
746 single character
747
748 @lilypond[fragment,quote,verbatim,relative=2]
749 c-.  c-- c-> c-^ c-+ c-_
750 @end lilypond
751
752 @cindex fingering
753 Similarly, fingering indications can be added to a note using a dash
754 (@samp{-}) and the digit to be printed
755
756 @lilypond[fragment,quote,verbatim,relative=2]
757 c-3 e-5 b-2 a-1
758 @end lilypond
759
760 Articulations and fingerings are usually placed automatically, but you
761 can specify a direction using @samp{^} (up) or @samp{_} (down).  You can
762 also use multiple articulations on the same note.  In most cases, it's
763 best to let LilyPond determine the articulation directions.
764
765 @lilypond[fragment,quote,verbatim,relative=2]
766 c_-^1 d^. f^4_2-> e^-_+
767 @end lilypond
768
769 Dynamic signs are made by adding the markings (with a backslash) to
770 the note
771
772 @lilypond[fragment,quote,verbatim,relative=2]
773 c\ff c\mf
774 @end lilypond
775
776 @cindex dynamics
777 @cindex decrescendo
778 @cindex crescendo
779
780 Crescendi and decrescendi are started with the commands @code{\<} and
781 @code{\>}.  An ending dynamic, for example @code{\f}, will finish the
782 crescendo, or the command @code{\!} can be used
783
784 @lilypond[fragment,quote,verbatim,relative=2]
785 c2\< c2\ff\> c2 c2\!
786 @end lilypond
787
788
789
790 @cindex slur
791
792 A slur is a curve drawn across many notes, and indicates legato
793 articulation.  The starting note and ending note are marked with
794 @samp{(} and @samp{)}, respectively
795
796 @lilypond[fragment,quote,fragment,relative=2,verbatim]
797 d4( c16) cis( d e c cis d) e( d4)
798 @end lilypond
799
800 @cindex slurs versus ties
801 A slur looks like a tie, but it has a different meaning.  A tie simply
802 makes the first note sound longer, and can only be used on pairs of
803 notes with the same pitch.  Slurs indicate the articulations of notes,
804 and can be used on larger groups of notes.  Slurs and ties can be
805 nested
806
807 @lilypond[quote,fragment,relative=2]
808 c2~( c8 fis fis4 ~ fis2 g2)
809 @end lilypond
810
811 @cindex phrasing slurs
812 Slurs to indicate phrasing can be entered with @code{\(} and
813 @code{\)}, so you can have both legato slurs and phrasing slurs at the
814 same time.
815
816 @lilypond[quote,fragment,relative=2,verbatim]
817 a8(\( ais b c) cis2 b'2 a4 cis, c\)
818 @end lilypond
819
820
821 For more information on
822
823 @quotation
824 @table @asis
825 @item Fingering
826 see @ref{Fingering instructions}.
827 @item Articulations
828 see @ref{Articulations}.
829 @item Slurs
830 see @ref{Slurs}.
831 @item Phrasing slurs
832 see @ref{Phrasing slurs}.
833 @item Dynamics
834 see @ref{Dynamics}.
835 @end table
836 @end quotation
837
838
839 @node Combining notes into chords
840 @section Combining notes into chords
841
842 @cindex chords
843 Chords can be made by surrounding pitches with angle brackets.
844 Angle brackets are the symbols @samp{<} and @samp{>}.
845
846 @lilypond[quote,relative=1,fragment,verbatim]
847 r4 <c e g>4 <c f a>8
848 @end lilypond
849
850
851 You can combine markings like beams and ties with chords.  They must
852 be placed outside the angled brackets
853
854 @lilypond[quote,relative=1,fragment,verbatim]
855 r4 <c e g>8[ <c f a>]~ <c f a>
856 @end lilypond
857
858 @example
859 r4 <c e g>8\>( <c e g> <c e g> <c f a>\!)
860 @end example
861
862 @lilypond[quote,relative=1,fragment]
863 \slurUp
864 r4 <c e g>8\>( <c e g> <c e g> <c f a>\!)
865 @end lilypond
866
867
868 @node Advanced rhythmic commands
869 @section Advanced rhythmic commands
870
871 @cindex pickup
872 @cindex anacruse
873 @cindex partial measure
874 A pickup is entered with the keyword @code{\partial}.  It
875 is followed by a duration: @code{\partial 4} is a quarter note upstep
876 and @code{\partial 8} an eighth note
877
878 @lilypond[quote,relative=2,verbatim,fragment]
879 \partial 8
880 f8 c2 d e
881 @end lilypond
882
883 @cindex tuplets
884 @cindex triplets
885 Tuplets are made with the @code{\times} keyword.  It takes two
886 arguments: a fraction and a piece of music.  The duration of the piece
887 of music is multiplied by the fraction.  Triplets make notes occupy
888 2/3 of their notated duration, so a triplet has 2/3 as its fraction
889
890 @lilypond[quote,relative=1,verbatim,fragment]
891 \times 2/3 { f8 g a }
892 \times 2/3 { c r c }
893 @end lilypond
894
895 @cindex grace notes
896 @cindex acciaccatura
897 Grace notes are also made by prefixing a music expression with the
898 keyword @code{\appoggiatura} or @code{\acciaccatura}
899 @cindex appoggiatura
900 @cindex acciaccatura
901
902 @lilypond[quote,relative=2,verbatim,fragment]
903 c4 \appoggiatura b16 c4
904 c4 \acciaccatura b16 c4
905 @end lilypond
906
907 @noindent
908
909 For more information on
910
911 @quotation
912 @table @asis
913 @item Grace notes
914 see @ref{Grace notes},
915 @item Tuplets
916 see @ref{Tuplets},
917 @item Pickups
918 see @ref{Partial measures}.
919 @end table
920 @end quotation
921
922
923 @node Commenting input files
924 @section Commenting input files
925
926 @cindex comments
927 @cindex line comment
928 @cindex block comment
929 A comment is a remark for the human reader of the music input; it is
930 ignored while parsing, so it has no effect on the printed output.
931 There are two types of comments.  The percent symbol @samp{%}
932 introduces a line comment; after  @code{%} the rest of the line   is
933 ignored.  A block comments marks a whole section of music
934 input.  Anything that is enclosed in @code{%@{} and @code{%@}} is
935 ignored.  The following fragment shows possible uses for comments
936
937 @example
938 % notes for twinkle twinkle follow
939 c4 c g' g a a g2
940
941 %@{
942     This line, and the notes below
943     are ignored, since they are in a
944     block comment.
945
946     g g f f e e d d c2 
947 %@}
948 @end example
949
950 @c  FIXME
951 @c   This is good info, but I wouldn't call it a comment.  IMO it should
952 @c   be moved somewhere else.  I don't know exactly where yet, but I'll
953 @c   resolve it soon.  -GP
954
955 @cindex versioning
956
957 There is a special statement that is a kind of comment.  The @code{\version}
958 statement marks for which version of LilyPond the file was written.
959 To mark a file for version 2.1.17, use
960
961 @example
962 \version "2.1.17"
963 @end example
964
965 @noindent
966 These annotations make future upgrades of LilyPond go more
967 smoothly.  Changes in the syntax are handled with a special program,
968 @file{convert-ly} (see @ref{Invoking convert-ly}), and it uses
969 @code{\version} to determine what rules to apply.
970
971
972 @node Printing lyrics
973 @section Printing lyrics
974 @cindex lyrics
975
976 @c TODO: (c) status of the Queen fragment.
977
978 @cindex Lyrics
979 @cindex Songs
980 Lyrics are entered by separating each syllable with a space
981
982 @example
983 I want to break free
984 @end example
985
986 Consider the melody
987
988 @lilypond[quote,verbatim,fragment,raggedright]
989 \relative {
990     r4 c \times 2/3 { f g g }
991     \times 2/3 { g4( a2) }
992 }
993 @end lilypond
994
995 The lyrics can be set to these notes, combining both with the
996 @code{\addlyrics} keyword
997
998 @lilypond[quote,verbatim,fragment,raggedright]
999 <<
1000   \relative {
1001     r4 c \times 2/3 { f g g }
1002     \times 2/3 { g4( a2) }
1003   }
1004   \addlyrics { I want to break free }
1005 >>
1006 @end lilypond
1007
1008 @cindex melisma
1009 @cindex extender line
1010 @c synonyms?
1011 This melody ends on a @rglos{melisma}, a single syllable (`free')
1012 sung to more than one note.  This is indicated with an @emph{extender
1013 line}.  It is entered as two underscores, i.e.,
1014
1015 @example
1016 @{ I want to break free __ @}
1017 @end example 
1018
1019 @lilypond[fragment,quote,raggedright]
1020 <<
1021   \relative {
1022     r4 c \times 2/3 { f g g }
1023     \times 2/3 { g4( a2) }
1024   }
1025   \addlyrics { I want to break free __ }
1026 >>
1027 @end lilypond
1028
1029 Similarly, hyphens between words can be entered as two dashes,
1030 resulting in a centered hyphen between two syllables
1031
1032 @example
1033 Twin -- kle twin -- kle
1034 @end example
1035
1036 @lilypond[fragment,quote,raggedright]
1037 <<
1038   \relative {
1039      \time 2/4
1040      f4 f c' c
1041    }
1042    \addlyrics { Twin -- kle twin -- kle }
1043 >>
1044 @end lilypond
1045
1046 More options, like putting multiple lines of lyrics below a melody are
1047 discussed in @ref{Vocal music}.
1048
1049
1050 @node A lead sheet
1051 @section A lead sheet
1052
1053 @cindex Lead sheets
1054 @cindex chords
1055 @cindex chord names
1056
1057 In popular music, it is common to denote accompaniment with chord names.
1058 Such chords can be entered like notes,
1059
1060 @lilypond[quote,verbatim,raggedright]
1061 \chords { c2 f4. g8 }
1062 @end lilypond
1063
1064 @noindent
1065 Now each pitch is read as the root of a chord instead of a note.
1066 This mode is switched on with @code{\chords}
1067
1068
1069 Other chords can be created by adding modifiers after a colon.  The
1070 following example shows a few common modifiers
1071
1072 @lilypond[quote,verbatim]
1073 \chords { c2 f4:m g4:maj7 gis1:dim7 }
1074 @end lilypond
1075
1076 For lead sheets, chords are not printed on staves, but as names on a
1077 line of themselves.  Hence, we have to override the context with
1078 @code{\new}, rendering the music expression in a @code{ChordNames}
1079 context
1080
1081 @lilypond[quote,verbatim]
1082 \new ChordNames \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1083 @end lilypond
1084
1085 @cindex lead sheet
1086 When put together, chord names, lyrics and a melody form
1087 a lead sheet, for example,
1088
1089 @example
1090 <<
1091   \new ChordNames \chords @{ @emph{chords} @}
1092   @emph{the melody}
1093   \addlyrics @{ @emph{the text} @}
1094 >>
1095 @}
1096 @end example
1097
1098 @lilypond[quote,raggedright]
1099 <<
1100   \new ChordNames \chords { r2 c:sus4 f } 
1101   \relative {
1102     r4 c' \times 2/3 { f g g }
1103     \times 2/3 { g4( a2) }
1104   }
1105  \addlyrics { I want to break free __ }
1106 >>
1107 @end lilypond
1108
1109 A complete list of modifiers and other options for layout can be found
1110 in @ref{Chords}.
1111
1112
1113 @node Adding titles
1114 @section Adding titles
1115
1116 Bibliographic information is entered in a separate block, the
1117 @code{\header} block.  The name of the piece, its composer, etc., are
1118 entered as an assignment, within @code{\header
1119 @{@tie{}@dots{}@tie{}@}}.  The @code{\header} block is usually put at
1120 the top of the file.  For example,
1121
1122 @example 
1123 \header @{
1124   title = "Miniature" 
1125   composer = "Igor Stravinsky"
1126 @}
1127
1128 @{ @dots{} @}
1129 @end example
1130
1131
1132 When the file is processed the title and composer are printed above
1133 the music.  More information on titling can be found in @ref{Creating
1134 titles}.
1135
1136
1137 @node Single staff polyphony
1138 @section Single staff polyphony
1139
1140 @cindex polyphony
1141 @cindex multiple voices
1142 @cindex voices, more -- on a staff
1143 When different melodic lines are combined on a single staff they are
1144 printed as polyphonic voices; each voice has its own stems, slurs and
1145 beams, and the top voice has the stems up, while the bottom voice has
1146 them down.
1147
1148 Entering such parts is done by entering each voice as a sequence (with
1149 @code{@{...@}}), and combining those simultaneously, separating the
1150 voices with @code{\\}
1151
1152 @lilypond[quote,verbatim,relative=2,fragment]
1153 << { a4 g2 f4~ f4 } \\
1154    { r4 g4 f2 f4 } >>
1155 @end lilypond
1156
1157 For polyphonic music typesetting, spacer rests can also be convenient;
1158 these are rests that do not print.  They are useful for filling up
1159 voices that temporarily do not play.  Here is the same example with a
1160 spacer rest (@code{s}) instead of a normal rest (@code{r}),
1161
1162 @lilypond[quote,verbatim,relative=2,fragment]
1163 << { a4 g2 f4~ f4 } \\
1164    { s4 g4 f2 f4 } >>
1165 @end lilypond
1166
1167 @noindent
1168 Again, these expressions can be nested arbitrarily
1169
1170 @lilypond[quote,fragment,verbatim,relative=2,fragment]
1171 <<
1172   \new Staff <<
1173     { a4 g2 f4~ f4 } \\
1174     { s4 g4 f2 f4 }
1175   >>
1176   \new Staff <<
1177     \clef bass
1178     { <c, g>1 ~ <c g>4 } \\
1179     { f4 d e2 ~ e4}
1180   >>
1181 >>
1182 @end lilypond
1183
1184 More features of polyphonic typesetting in the notation manual are
1185 described in @ref{Polyphony}.
1186
1187
1188 @node Piano staves
1189 @section Piano staves
1190
1191 @cindex staff switch, manual
1192 @cindex cross staff voice, manual
1193 @cindex @code{\context}
1194 Piano music is typeset in two staves connected by a brace.  Printing
1195 such a staff is similar to the polyphonic example in @ref{More staves},
1196
1197 @example
1198 << \new Staff @{ @dots{} @}
1199    \new Staff @{ @dots{} @} >>
1200 @end example
1201
1202 @noindent
1203 but now this entire expression must be interpreted as a
1204 @code{PianoStaff}
1205
1206 @example
1207 \new PianoStaff << \new Staff @dots{} >>
1208 @end example
1209
1210 Here is a small example
1211
1212 @lilypond[quote,verbatim,relative=1,fragment]
1213 \new PianoStaff <<
1214   \new Staff { \time 2/4 c4 c g' g }
1215   \new Staff { \clef bass c,, c' e c }
1216 >>
1217 @end lilypond
1218
1219 More information on formatting piano music is in @ref{Piano music}.  
1220
1221
1222 @node Organizing larger pieces
1223 @section Organizing larger pieces
1224
1225 When all of the elements discussed earlier are combined to produce
1226 larger files, the @code{\score} blocks get a lot bigger, because the
1227 music expressions are longer, and, in the case of polyphonic pieces,
1228 more deeply nested.  Such large expressions can become unwieldy.
1229
1230 By using variables, also known as identifiers, it is possible to break
1231 up complex music expressions.  An identifier is assigned as follows
1232
1233 @example
1234 namedMusic = @{ @dots{} @}
1235 @end example
1236
1237 @noindent
1238 The contents of the music expression @code{namedMusic}, can be used
1239 later by preceding the name with a backslash, i.e., @code{\namedMusic}.
1240 In the next example, a two-note motive is repeated two times by using
1241 variable substitution
1242
1243 @lilypond[quote,raggedright,verbatim,nofragment]
1244 seufzer = {
1245   e'4( dis'4)
1246 }
1247 { \seufzer \seufzer }
1248 @end lilypond
1249
1250 The name of an identifier should have alphabetic characters only; no
1251 numbers, underscores or dashes.  The assignment should be outside of
1252 running music.
1253
1254 It is possible to use variables for many other types of objects in the
1255 input.  For example,
1256
1257 @example
1258 width = 4.5\cm
1259 name = "Wendy"
1260 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1261 @end example
1262
1263 Depending on its contents, the identifier can be used in different
1264 places.  The following example uses the above variables
1265
1266 @example
1267   \paper @{
1268     \aFivePaper
1269     linewidth = \width
1270   @}
1271   @{ c4^\name @}
1272 @end example
1273
1274 More information on the possible uses of identifiers is in the
1275 technical manual, in @ref{Input variables and Scheme}.
1276 @c fixme: the ref is too technical.
1277
1278
1279 @node An orchestral part
1280 @section An orchestral part
1281
1282 In orchestral music, all notes are printed twice.  Once in a part for
1283 the musicians, and once in a full score for the conductor.  Identifiers can
1284 be used to avoid double work.  The music is entered once, and stored in
1285 a variable.  The contents of that variable is then used to generate
1286 both the part and the score.
1287
1288 It is convenient to define the notes in a special file.  For example,
1289 suppose that the file @file{horn-music.ly} contains the following part
1290 of a horn/bassoon duo
1291
1292 @example
1293 hornNotes =  \relative c @{
1294   \time 2/4
1295   r4 f8 a cis4 f e d
1296 @}
1297 @end example
1298
1299 @noindent
1300 Then, an individual part is made by putting the following in a file
1301
1302 @example
1303 \include "horn-music.ly"
1304 \header @{
1305   instrument = "Horn in F"
1306 @}
1307
1308 @{
1309  \transpose f c' \hornNotes
1310 @}
1311 @end example
1312
1313 The line
1314
1315 @example
1316 \include "horn-music.ly"
1317 @end example
1318
1319 @noindent
1320 substitutes the contents of @file{horn-music.ly} at this position in
1321 the file, so @code{hornNotes} is defined afterwards.  The command
1322 @code{\transpose f@tie{}c'} indicates that the argument, being
1323 @code{\hornNotes}, should be transposed by a fifth downwards.  Sounding
1324 @samp{f} is denoted by notated @code{c'}, which corresponds with
1325 tuning of a normal French Horn in@tie{}F.  The transposition can be seen
1326 in the following output
1327
1328 @lilypond[quote,raggedright]
1329   \transpose f c' \relative c {
1330     \time 2/4
1331     r4 f8 a cis4 f e d
1332   }
1333 @end lilypond
1334
1335 In ensemble pieces, one of the voices often does not play for many
1336 measures.  This is denoted by a special rest, the multi-measure
1337 rest.  It is entered with a capital @samp{R} followed by a duration
1338 (1@tie{}for a whole note, 2@tie{}for a half note, etc.).  By multiplying the
1339 duration, longer rests can be constructed.  For example, this rest
1340 takes 3@tie{}measures in 2/4 time
1341
1342 @example
1343 R2*3
1344 @end example
1345
1346 When printing the part, multi-rests
1347 must be condensed.  This is done by setting a run-time variable
1348
1349 @example
1350 \set Score.skipBars = ##t
1351 @end example
1352
1353 @noindent
1354 This command sets the property @code{skipBars} in the
1355 @code{Score} context to true (@code{##t}).  Prepending the rest and
1356 this option to the music above, leads to the following result
1357
1358 @lilypond[quote,raggedright]
1359 \transpose f c' \relative c {
1360     \time 2/4
1361     \set Score.skipBars = ##t 
1362     R2*3
1363     r4 f8 a cis4 f e d
1364   }
1365 @end lilypond
1366
1367
1368 The score is made by combining all of the music together.  Assuming
1369 that the other voice is in @code{bassoonNotes} in the file
1370 @file{bassoon-music.ly}, a score is made with
1371
1372 @example
1373 \include "bassoon-music.ly"
1374 \include "horn-music.ly"
1375
1376   <<
1377     \new Staff \hornNotes
1378     \new Staff \bassoonNotes
1379   >>
1380 @end example
1381
1382 @noindent
1383 leading to 
1384
1385 @lilypond[quote,raggedright]
1386   \relative c <<
1387     \new Staff {
1388       \time 2/4 R2*3
1389       r4 f8 a cis4 f e d
1390     }
1391     \new Staff {
1392       \clef bass
1393       r4 d,8 f | gis4 c | b bes |
1394       a8 e f4 | g d | gis f
1395     }
1396   >>
1397 @end lilypond
1398
1399 More in-depth information on preparing parts and scores can be found
1400 in the notation manual; see @ref{Orchestral music}.
1401
1402 Setting run-time variables (`properties') is discussed in
1403 @ref{Changing context properties on the fly}.
1404
1405
1406 @ignore
1407
1408 * longer example
1409
1410 * discuss expectations (?)
1411
1412 * conclude tutorial
1413
1414 * overview of chapters?
1415
1416 @end ignore