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