]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
Tutorial formatting fixes from Ralph, thanks!
[lilypond.git] / Documentation / user / tutorial.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.tely
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @ignore
11
12 Tutorial Specification:
13
14 The LM is written in a tutorial style which introduces the most
15 important concepts, structure and syntax of the elements of a
16 LilyPond score in a carefully graded sequence of steps.
17 Explanations of all musical concepts used in the Manual can be
18 found in the Music Glossary, and readers are assumed to have no
19 prior knowledge of LilyPond.  The objective is to take readers to
20 a level where the Notation Reference can be understood and
21 employed to both adapt the templates in the Appendix to their
22 needs and to begin to construct their own scores.  Commonly used
23 tweaks are introduced and explained.  Examples are provided
24 throughout which, while being focussed on the topic being
25 introduced, are long enough to seem real in order to retain the
26 readers' interest.  Each example builds on the previous material,
27 and comments are used liberally.  Every new aspect is thoroughly
28 explained before it is used.
29
30 @end ignore
31
32 @ignore
33 Tutorial guidelines:  (different from policy.txt!)
34 - unless you have a really good reason, use either
35     @lilypond[verbatim,quote,ragged-right]
36   or
37     @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
38
39   Don't use any other relative=X commands (make it a non-fragment
40   example), and don't use fragment without relative=2.
41
42 - use "aes" and "ees" instead of "as" and "es".  I know it's not
43   correct Dutch naming, but let's not confuse people with this
44   until we get to the Basic notation chapter.
45
46 - Add "Music Glossary: @rglos{foo}" to the _top_ of the relevant
47   portions of the tutorial.
48
49 @end ignore
50
51
52 @node Tutorial
53 @chapter Tutorial
54
55 This tutorial starts with an introduction to the LilyPond music
56 language and how to produce printed music.  After this first
57 contact we will explain how to create common musical notation.
58
59 @menu
60 * First steps::                 
61 * Single staff notation::       
62 * Multiple notes at once::      
63 * Songs::                       
64 * Final touches::               
65 @end menu
66
67
68 @node First steps
69 @section First steps
70
71 This section gives a basic introduction to working with LilyPond.
72
73 @menu
74 * Compiling a file::            
75 * Simple notation::             
76 * Working on text files::       
77 * How to read the tutorial::    
78 @end menu
79
80
81 @node Compiling a file
82 @subsection Compiling a file
83
84 The first example demonstrates how to start working with LilyPond.
85 To create sheet music, we write a text file that specifies the
86 notation.  For example, if we write:
87
88 @example
89 @{
90   c' e' g' e'
91 @}
92 @end example
93
94 @noindent
95 the result looks like this:
96
97 @c  in this case we don't want verbatim
98 @lilypond[quote,ragged-right]
99 {
100   c' e' g' e'
101 }
102 @end lilypond
103
104 @warning{Every piece of LilyPond input needs to have
105 @strong{@{ curly braces @}} placed around the input.  The braces
106 should also be surrounded by a space unless they are at the
107 beginning or end of a line to avoid ambiguities.  The braces may
108 be omitted in some examples in this manual, but don't forget them
109 in your own music!  For more information about the display of
110 examples in the manual, see @ref{How to read the tutorial}.}
111
112 @cindex case sensitive
113 In addition, LilyPond input is @strong{case sensitive}.  @code{
114 @{ c d e @}} is valid input; @code{@{ C D E @}} will produce an
115 error message.
116
117 @smallspace
118
119 @subheading Entering music and viewing output
120
121 @cindex PDF file
122 @cindex viewing music
123
124 In this section we will explain what commands to run and how to
125 view or print the output.
126
127 Note that there are several other text editors available with
128 better support for LilyPond.  For more information, see
129 @rprogram{Text editor support}.
130
131 @warning{the first time you ever run LilyPond, it may take a
132 minute or two because all of the system fonts have to be analyzed
133 first.  After this, LilyPond will be much faster!}
134
135 @subsubheading MacOS X
136
137 If you double click @code{LilyPond.app}, it will open with an
138 example file.  Save it, for example, to @file{test.ly} on your
139 Desktop, and then process it with the menu command @code{Compile >
140 Typeset File}.  The resulting PDF file will be displayed on your
141 screen.
142
143 For future use of LilyPond, you should begin by selecting @q{New}
144 or @q{Open}.  You must save your file before typesetting it.  If
145 any errors occur in processing, please see the log window.
146
147
148 @subsubheading Windows
149
150 On Windows, if you double-click in the LilyPond icon on the
151 Desktop, it will open a simple text editor with an example file.
152 Save it, for example, to @file{test.ly} on your Desktop and then
153 double-click on the file to process it (the file icon looks like a
154 note).  After some seconds, you will get a file @file{test.pdf} on
155 your desktop.  Double-click on this PDF file to view the typeset
156 score.  An alternative method to process the @file{test.ly} file
157 is to drag and drop it onto the LilyPond icon using your mouse
158 pointer.
159
160 To edit an existing @file{.ly} file, right-click on it and
161 select @qq{Edit source}.  To get an empty file to start from, run
162 the editor as described above and use @qq{New} in
163 the @qq{File} menu.
164
165 Double-clicking the file does not only result in a PDF file, but
166 also produces a @file{.log} file that contains some information on
167 what LilyPond has done to the file.  If any errors occur, please
168 examine this file.
169
170 @subsubheading Unix
171
172 Create a file (such as @file{test.ly}) and enter:
173
174 @example
175 @{
176   c' e' g' e'
177 @}
178 @end example
179
180 To process @file{test.ly}, proceed as follows:
181
182 @example
183 lilypond test.ly
184 @end example
185
186 @noindent
187 You will see something resembling:
188
189 @example
190 lilypond test.ly
191 GNU LilyPond 2.12.0
192 Processing `test.ly'
193 Parsing...
194 Interpreting music...
195 Preprocessing graphical objects...
196 Finding the ideal number of pages...
197 Fitting music on 1 page...
198 Drawing systems...
199 Layout output to `test.ps'...
200 Converting to `test.pdf'...
201 @end example
202
203
204 @node Simple notation
205 @subsection Simple notation
206
207 LilyPond will add some notation elements automatically.  In the
208 next example, we have only specified four pitches, but LilyPond
209 has added a clef, time signature, and rhythms.
210
211 @lilypond[verbatim,quote,ragged-right]
212 {
213   c' e' g' e'
214 }
215 @end lilypond
216
217 @noindent
218 This behavior may be altered, but in most cases these automatic
219 values are useful.
220
221
222 @subheading Pitches
223
224 Music Glossary: @rglos{pitch}, @rglos{interval},
225 @rglos{scale}, @rglos{middle C}, @rglos{octave},
226 @rglos{accidental}.
227
228 The easiest way to enter notes is by using @code{\relative} mode.
229 In this mode, the octave is chosen automatically by assuming the 
230 following note is always to be placed closest to the previous note,
231 i.e., it is to be placed in the octave which is within three 
232 staff spaces of the previous note.  We begin by entering the most 
233 elementary piece of music, a @notation{scale}, in which every note
234 is within just one staff space of the previous note.
235
236 @lilypond[verbatim,quote,ragged-right]
237 \relative c' {  % set the starting point to middle C
238   c d e f
239   g a b c
240 }
241 @end lilypond
242
243 The initial note is @notation{middle C}.  Each successive note is
244 placed closest to the previous note -- in other words, the first
245 @code{c} is the closest C to middle C.  This is followed by the
246 closest D to the previous note.  We can create melodies which
247 have larger intervals, still using only @code{\relative} mode:
248
249 @lilypond[verbatim,quote,ragged-right]
250 \relative c' {
251   d f a g
252   c b f d
253 }
254 @end lilypond
255
256 @noindent
257 It is not necessary for the first note of the melody to start on
258 the note which specifies the starting pitch.  In the previous
259 example, the first note -- the @code{d} -- is the closest D to
260 middle C.
261
262 By adding (or removing) quotes @code{'} or commas @code{,} from
263 the @code{\relative c' @{} command, we can change the starting
264 octave:
265
266 @lilypond[verbatim,quote,ragged-right]
267 \relative c'' {  % one octave above middle C
268   e c a c
269 }
270 @end lilypond
271
272 Relative mode can be confusing initially, but is the easiest way
273 to enter most melodies.  Let us see how this relative calculation
274 works in practice.  Starting from a B, which is on the middle line
275 in a treble clef, you can reach a C, D and E within 3 staff spaces
276 going up, and an A, G and F within 3 staff spaces going down.  So
277 if the note following a B is a C, D or F it will be assumed to be
278 above the B, and an A, G or F will be assumed to be below.
279
280 @lilypond[verbatim,quote,ragged-right]
281 \relative c'' {
282   b c  % c is 1 staff space up, so is the c above
283   b d  % d is 2 up or 5 down, so is the d above
284   b e  % e is 3 up or 4 down, so is the e above
285   b a  % a is 4 up or 3 down, so is the a below
286   b g  % g is 5 up or 2 down, so is the g below
287   b f  % f is 6 up or 1 down, so is the f below
288 }
289 @end lilypond
290
291 Exactly the same happens even when any of these notes are
292 sharpened or flattened.  @notation{Accidentals} are @strong{totally
293 ignored} in the calculation of relative position.  Precisely the
294 same staff space counting is done from a note at any other
295 position on the staff.
296
297 To add intervals that are larger than three staff spaces, we can
298 raise the @notation{octave} by adding a single quote @code{'} (or
299 apostrophe) to the note name.  We can lower the octave by adding a
300 comma @code{,} to the note name.
301
302 @lilypond[verbatim,quote,ragged-right]
303 \relative c'' {
304   a a, c' f,
305   g g'' a,, f'
306 }
307 @end lilypond
308
309 @noindent
310 To change a note by two (or more!) octaves, we use multiple
311 @code{''} or @code{,,} -- but be careful that you use two single
312 quotes @code{''} and not one double quote @code{"}@tie{}!  The
313 initial value in @code{\relative c'} may also be modified like
314 this.
315
316
317 @subheading Durations (rhythms)
318
319 Music Glossary: @rglos{beam}, @rglos{duration}, @rglos{whole note},
320 @rglos{half note}, @rglos{quarter note}, @rglos{dotted note}.
321
322 The @notation{duration} of a note is specified by a number after
323 the note name.  @code{1} for a @notation{whole note}, @code{2} for
324 a @notation{half note}, @code{4} for a @notation{quarter note} and
325 so on.  @notation{Beams} are added automatically.
326
327 If you do not specify a duration, the previous duration is used
328 for the next note.  The duration of the first note defaults to a
329 quarter.
330
331 @lilypond[verbatim,quote,ragged-right]
332 \relative c'' {
333   a1
334   a2 a4 a8 a
335   a16 a a a a32 a a a a64 a a a a a a a a2
336 }
337 @end lilypond
338
339 To create @notation{dotted notes}, add a dot @code{.} to the
340 duration number.  The duration of a dotted note must be stated
341 explicitly (i.e., with a number).
342
343 @lilypond[verbatim,quote,ragged-right]
344 \relative c'' {
345   a a a4. a8
346   a8. a16 a a8. a8 a4.
347 }
348 @end lilypond
349
350
351 @subheading Rests
352
353 Music Glossary: @rglos{rest}.
354
355 A @notation{rest} is entered just like a note with the name @code{r}:
356
357 @lilypond[verbatim,quote,ragged-right]
358 \relative c'' {
359   a r r2
360   r8 a r4 r4. r8
361 }
362 @end lilypond
363
364
365 @subheading Time signature
366
367 Music Glossary: @rglos{time signature}.
368
369 The @notation{time signature} can be set with the @code{\time}
370 command:
371
372 @lilypond[verbatim,quote,ragged-right]
373 \relative c'' {
374   \time 3/4
375   a4 a a
376   \time 6/8
377   a4. a
378   \time 4/4
379   a4 a a a
380 }
381 @end lilypond
382
383
384 @subheading Clef
385
386 Music Glossary: @rglos{clef}.
387
388 The @notation{clef} can be set using the @code{\clef} command:
389
390 @lilypond[verbatim,quote,ragged-right]
391 \relative c' {
392   \clef treble
393   c1
394   \clef alto
395   c1
396   \clef tenor
397   c1
398   \clef bass
399   c1
400 }
401 @end lilypond
402
403
404 @subheading All together
405
406 Here is a small example showing all these elements together:
407
408 @lilypond[verbatim,quote,ragged-right]
409 \relative c, {
410   \time 3/4
411   \clef bass
412   c2 e8 c' g'2.
413   f4 e d c4 c, r4
414 }
415 @end lilypond
416
417
418 @seealso
419
420 Notation Reference: @ruser{Writing pitches}, @ruser{Writing rhythms},
421 @ruser{Writing rests}, @ruser{Time signature}, @ruser{Clef}.
422
423
424 @c HERE's where I started
425
426 @node Working on text files
427 @subsection Working on text files
428
429 LilyPond input files are similar to source files in many common
430 programming languages.  They are case sensitive, and white-space
431 is generally equivalent.  Expressions are formed with curly braces
432 @{ @}, and comments are denoted with @code{%} or @code{%@{ ...
433 %@}}.
434
435 If the previous sentences sound like nonsense, don't worry!  We'll
436 explain what all these terms mean:
437
438 @itemize
439
440 @cindex case sensitive
441 @item
442 @strong{Case sensitive}:
443 it matters whether you enter a letter in lower case (e.g. @code{a,
444 b, s, t}) or upper case (e.g.  @code{A, B, S, T}).  Notes are
445 lower case: @code{@{ c d e @}} is valid input; @code{@{ C D E @}}
446 will produce an error message.
447
448 @item
449 @strong{Whitespace insensitive}:
450 it does not matter how many spaces (or new lines) you add.
451 @code{@{ c d e @}} means the same thing as @code{@{ c @tie{}
452 @tie{} @tie{} d e @}} and:
453
454 @example
455 @{ c                        d
456                    e   @}
457 @end example
458
459 @noindent
460 Of course, the previous example is hard to read.  A good rule of
461 thumb is to indent code blocks with either a tab or two spaces:
462
463 @example
464 @{
465   c d e
466 @}
467 @end example
468
469 @item
470 @strong{Expressions}:
471 every piece of LilyPond input needs to have @strong{@{ curly
472 braces @}} placed around the input.  These braces tell LilyPond
473 that the input is a single music expression, just like parentheses
474 @code{()} in mathematics.  The braces should be surrounded by a
475 space unless they are at the beginning or end of a line to avoid
476 ambiguities.
477
478 A function (such as @code{\relative @{ @}}) also counts as a
479 single music expression.
480
481 @cindex comments
482 @cindex line comment
483 @cindex block comment
484 @item
485 @strong{Comments}:
486 a comment is a remark for the human reader of the music input; it
487 is ignored while parsing, so it has no effect on the printed
488 output.  There are two types of comments.  The percent symbol
489 @code{%} introduces a line comment; anything after @code{%} on
490 that line is ignored.  A block comment marks a whole section of
491 music input as a comment.  Anything that is enclosed in @code{%@{}
492 and @code{%@}} is ignored.  (Comments do not nest.)  The following
493 fragment shows possible uses for comments:
494
495 @example
496 % notes for twinkle twinkle follow
497   c4 c g' g a a g2
498
499 %@{
500   This line, and the notes below
501   are ignored, since they are in a
502   block comment.
503
504   g g f f e e d d c2
505 %@}
506 @end example
507
508 @end itemize
509
510
511 @node How to read the tutorial
512 @subsection How to read the tutorial
513
514 LilyPond input must be surrounded by @{ @} marks or a
515 @code{\relative c'' @{ ... @}}, as we saw in @ref{Working on text
516 files}.  For the rest of this manual, most examples will omit
517 this.  To replicate the examples, you may copy and paste the
518 displayed input but you @strong{must} add the @code{\relative c''
519 @{ @}} like this:
520
521 @example
522 \relative c'' @{
523   ... example goes here...
524 @}
525 @end example
526
527 Why omit the braces?  Most examples in this manual can be inserted
528 into the middle of a longer piece of music.  For these examples,
529 it does not make sense to add @code{\relative c'' @{ @}} -- you
530 should not place a @code{\relative} inside another
531 @code{\relative}!  If we included @code{\relative c'' @{ @}}
532 around every example, you would not be able to copy a small
533 documentation example and paste it inside a longer piece of your
534 own.  Most people want to add material to an existing piece, so we
535 format the manual this way.
536
537
538 @subheading Clickable examples
539
540 Many people learn programs by trying and fiddling around with the
541 program.  This is also possible with LilyPond.  If you click on a
542 picture in the HTML version of this manual, you will see the exact
543 LilyPond input that was used to generate that image.  Try it on
544 this image:
545
546 @c no verbatim here
547 @lilypond[quote,ragged-right]
548 \relative c'' {
549   c-\markup { \bold \huge { Click here.  } }
550 }
551 @end lilypond
552
553 By cutting and pasting everything in the @qq{ly snippet} section,
554 you have a starting template for experiments.  To see exactly the
555 same output (line-width and all), copy everything from @qq{Start
556 cut-&-pastable section} to the bottom of the file.
557
558 @seealso
559
560
561 There are more tips for constructing input files in
562 @ref{Suggestions for writing LilyPond files}.
563
564
565
566 @node Single staff notation
567 @section Single staff notation
568
569 This section introduces common notation that is used for one voice
570 on one staff.
571
572 @menu
573 * Accidentals and key signatures::  
574 * Ties and slurs::              
575 * Articulation and dynamics::   
576 * Adding text::                 
577 * Automatic and manual beams::  
578 * Advanced rhythmic commands::  
579 @end menu
580
581
582 @node Accidentals and key signatures
583 @subsection Accidentals and key signatures
584
585 @subheading Accidentals
586
587 Music Glossary: @rglos{sharp}, @rglos{flat}, @rglos{double sharp},
588 @rglos{double flat}, @rglos{accidental}.
589
590 A @notation{sharp} pitch is made by adding @code{is} to the name, and
591 a @notation{flat} pitch by adding @code{es}.  As you might expect, a
592 @notation{double sharp} or @notation{double flat} is made by adding
593 @code{isis} or @code{eses}.  This syntax is derived from note
594 naming conventions in Nordic and Germanic languages, like German
595 and Dutch.  To use other names for @notation{accidentals}, see
596 @ruser{Note names in other languages}.
597
598 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
599 cis1 ees fisis, aeses
600 @end lilypond
601
602 @cindex key signature, setting
603 @subheading Key signatures
604
605 Music Glossary: @rglos{key signature}, @rglos{major}, @rglos{minor}.
606
607 The @notation{key signature} is set with the command @code{\key}
608 followed by a pitch and @code{\major} or @code{\minor}.
609
610 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
611 \key d \major
612 a1
613 \key c \minor
614 a
615 @end lilypond
616
617 @smallspace
618
619 @subheading Warning: key signatures and pitches
620
621 Music Glossary: @rglos{accidental}, @rglos{key signature},
622 @rglos{pitch}, @rglos{flat}, @rglos{natural}, @rglos{sharp},
623 @rglos{transposition}.
624
625 To determine whether to print an @notation{accidental}, LilyPond
626 examines the pitches and the @notation{key signature}.  The key
627 signature only affects the @emph{printed} accidentals, not the note's
628 @notation{pitch}!  This is a feature that often causes confusion to
629 newcomers, so let us explain it in more detail.
630
631 LilyPond makes a sharp distinction between musical content and
632 layout.  The alteration (@notation{flat}, @notation{natural} or
633 @notation{sharp}) of a note is part of the pitch, and is therefore
634 musical content.  Whether an accidental (a @emph{printed} flat, natural
635 or sharp sign) is printed in front of the corresponding note is a
636 question of layout.  Layout is something that follows rules, so
637 accidentals are printed automatically according to those rules.  The
638 pitches in your music are works of art, so they will not be added
639 automatically, and you must enter what you want to hear.
640
641 In this example:
642
643 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
644 \key d \major
645 d cis fis
646 @end lilypond
647
648 @noindent
649 No note has a printed accidental, but you must still add the
650 @code{is} to @code{cis} and @code{fis}.
651
652 The code @code{e} does not mean @qq{print a black dot just below
653 the first line of the staff.}  Rather, it means @qq{there is a
654 note with pitch E-natural.}  In the key of A-flat major, it
655 @emph{does} get an accidental:
656
657 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
658 \key aes \major
659 e
660 @end lilypond
661
662 Adding all alterations explicitly might require a little more
663 effort when typing, but the advantage is that
664 @notation{transposing} is easier, and accidentals can be printed
665 according to different conventions.  For some examples how
666 accidentals can be printed according to different rules, see
667 @ruser{Automatic accidentals}.
668
669 @seealso
670
671 Notation Reference: @ruser{Note names in other languages}, @ruser{Accidentals},
672 @ruser{Automatic accidentals}, @ruser{Key signature}.
673
674 Music Glossary: @rglos{Pitch names}.
675
676
677 @node Ties and slurs
678 @subsection Ties and slurs
679
680 @cindex ties
681 @subheading Ties
682
683 Music Glossary: @rglos{tie}.
684
685 A @notation{tie} is created by appending a tilde @code{~} to the
686 first note being tied.
687
688 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
689 g4~ g c2~
690 c4 ~ c8 a8 ~ a2
691 @end lilypond
692
693 @cindex slurs
694 @subheading Slurs
695
696 Music Glossary: @rglos{slur}.
697
698 A @notation{slur} is a curve drawn across many notes.  The starting
699 note and ending note are marked with @code{(} and @code{)}
700 respectively.
701
702 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
703 d4( c16) cis( d e c cis d) e( d4)
704 @end lilypond
705
706 @cindex slurs, phrasing
707 @cindex phrasing slurs
708 @subheading Phrasing slurs
709
710 Music Glossary: @rglos{phrasing}, @rglos{legato}.
711
712 Slurs to indicate longer @notation{phrasing} can be entered with
713 @code{\(} and @code{\)}.  You can have both @notation{legato} slurs and
714 phrasing slurs at the same time, but you cannot have simultaneous legato
715 slurs or simultaneous phrasing slurs.
716
717 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
718 a8(\( ais b c) cis2 b'2 a4 cis,\)
719 @end lilypond
720
721 @smallspace
722
723 @cindex slurs versus ties
724 @subheading Warnings: slurs vs. ties
725
726 Music Glossary: @rglos{articulation}, @rglos{slur}, @rglos{tie}.
727
728 A @notation{slur} looks like a @notation{tie}, but it has a different
729 meaning.  A tie simply makes the first note longer, and can only be
730 used on pairs of notes with the same pitch.  Slurs indicate the
731 @notation{articulation} of notes, and can be used on larger groups of
732 notes.  Slurs and ties can be nested.
733
734 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
735 c2~( c8 fis fis4 ~ fis2 g2)
736 @end lilypond
737
738 @seealso
739
740 Notation Reference: @ruser{Ties}, @ruser{Slurs},
741 @ruser{Phrasing slurs}.
742
743
744 @node Articulation and dynamics
745 @subsection Articulation and dynamics
746
747 @cindex articulation
748 @cindex accents
749 @cindex staccato
750 @subheading Articulations
751
752 Music Glossary: @rglos{articulation}.
753
754 Common @notation{articulations} can be added to a note using a
755 dash @code{-} and a single character:
756
757 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
758 c-. c-- c-> c-^ c-+ c-_
759 @end lilypond
760
761 @cindex fingering
762 @subheading Fingerings
763
764 Music Glossary: @rglos{fingering}.
765
766
767 Similarly, @notation{fingering} indications can be added to a note using
768 a dash (@code{-}) and the digit to be printed:
769
770 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
771 c-3 e-5 b-2 a-1
772 @end lilypond
773
774 Articulations and fingerings are usually placed automatically, but
775 you can specify a direction by replacing the dash (@code{-}) with @code{^} (up) or @code{_}
776 (down).  You can also use multiple articulations on the same note.
777 However, in most cases it is best to let LilyPond determine the
778 articulation directions.
779
780 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
781 c_-^1 d^. f^4_2-> e^-_+
782 @end lilypond
783
784 @subheading Dynamics
785
786 Music Glossary: @rglos{dynamics}, @rglos{crescendo},
787 @rglos{decrescendo}.
788
789 @notation{Dynamic} signs are made by adding the markings (with a
790 backslash) to the note:
791
792 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
793 c\ff c\mf c\p c\pp
794 @end lilypond
795
796 @cindex dynamics
797 @cindex decrescendo
798 @cindex crescendo
799
800 @notation{Crescendi} and @notation{decrescendi} are started with
801 the commands @code{\<} and @code{\>}.  An ending dynamic, for
802 example @code{\f}, will finish the (de)crescendo, or the command
803 @code{\!} can be used:
804
805 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
806 c2\< c2\ff\> c2 c2\!
807 @end lilypond
808
809 @seealso
810
811 Notation Reference: @ruser{Articulations},
812 @ruser{Fingering instructions}, @ruser{Dynamics}.
813
814
815 @node Adding text
816 @subsection Adding text
817
818 Text may be added to your scores:
819
820 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
821 c1^"espr" a_"legato"
822 @end lilypond
823
824 Extra formatting may be added with the @code{\markup} command:
825
826 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
827 c1^\markup{ \bold espr}
828 a1_\markup{
829   \dynamic f \italic \small { 2nd } \hspace #0.1 \dynamic p
830 }
831 @end lilypond
832
833
834 @seealso
835
836 Notation Reference: @ruser{Writing text}.
837
838
839 @node Automatic and manual beams
840 @subsection Automatic and manual beams
841
842 Music Glossary: @rglos{beam}.
843
844 @cindex beams, by hand
845 All @notation{beams} are drawn automatically:
846
847 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
848 a8 ais d ees r d c16 b a8
849 @end lilypond
850
851 @noindent
852 If you do not like the automatic beams, they may be overridden
853 manually.  Mark the first note to be beamed with @code{[} and the
854 last one with @code{]}.
855
856 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
857 a8[ ais] d[ ees r d] a b
858 @end lilypond
859
860 @seealso
861
862 Notation Reference: @ruser{Automatic beams}, @ruser{Manual beams}.
863
864
865 @node Advanced rhythmic commands
866 @subsection Advanced rhythmic commands
867
868 @cindex pickup
869 @cindex anacrusis
870 @cindex partial measure
871 @subheading Partial measure
872
873 Music Glossary: @rglos{anacrusis}.
874
875 A pickup (or @notation{anacrusis}) is entered with the keyword
876 @code{\partial}.  It is followed by a duration: @code{\partial 4}
877 is a quarter note pickup and @code{\partial 8} an eighth note.
878
879 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
880 \partial 8
881 f8 c2 d
882 @end lilypond
883
884 @cindex tuplets
885 @cindex triplets
886 @subheading Tuplets
887
888 Music Glossary: @rglos{note value}, @rglos{triplet}.
889
890 @notation{Tuplets} are made with the @code{\times} keyword.  It
891 takes two arguments: a fraction and a piece of music.  The
892 duration of the piece of music is multiplied by the fraction.
893 Triplets make notes occupy 2/3 of their notated duration, so a
894 @notation{triplet} has 2/3 as its fraction
895
896 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
897 \times 2/3 { f8 g a }
898 \times 2/3 { c r c }
899 \times 2/3 { f,8 g16[ a g a] }
900 \times 2/3 { d4 a8 }
901 @end lilypond
902
903 @cindex grace notes
904 @cindex acciaccatura
905 @cindex appoggiatura
906 @subheading Grace notes
907
908 Music Glossary: @rglos{grace notes}, @rglos{acciacccatura}, @rglos{appoggiatura}.
909
910 @notation{Grace notes} are created with the @code{\grace} command,
911 although they can also be created by prefixing a music expression
912 with the keyword @code{\appoggiatura} or @code{\acciaccatura}:
913
914 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
915 c2 \grace { a32[ b] } c2
916 c2 \appoggiatura b16 c2
917 c2 \acciaccatura b16 c2
918 @end lilypond
919
920 @seealso
921
922 Notation Reference: @ruser{Grace notes}, @ruser{Tuplets},
923 @ruser{Upbeats}.
924
925
926 @node Multiple notes at once
927 @section Multiple notes at once
928
929 This section introduces having more than one note at the same
930 time: multiple instruments, multiple staves for a single
931 instrument (i.e. piano), and chords.
932
933 Polyphony in music refers to having more than one voice occurring
934 in a piece of music.  Polyphony in LilyPond refers to having more
935 than one voice on the same staff.
936
937 @menu
938 * Music expressions explained::  
939 * Multiple staves::             
940 * Piano staves::                
941 * Combining notes into chords::  
942 * Single staff polyphony::      
943 @end menu
944
945
946 @node Music expressions explained
947 @subsection Music expressions explained
948
949 In LilyPond input files, music is represented by @emph{music
950 expressions}.  A single note is a music expression:
951
952 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
953 a4
954 @end lilypond
955
956 Enclosing a note in braces creates a @emph{compound music
957 expression}.  Here we have created a compound music expression
958 with two notes:
959
960 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
961 { a4 g4 }
962 @end lilypond
963
964 Putting a group of music expressions (e.g. notes) in braces means
965 that they are in sequence (i.e. each one follows the previous
966 one).  The result is another music expression:
967
968 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
969 { { a4 g } f g }
970 @end lilypond
971
972 @subheading Simultaneous music expressions: multiple staves
973
974 Music Glossary: @rglos{polyphony}.
975
976 This technique is useful for @notation{polyphonic} music.  To
977 enter music with more voices or more staves, we combine
978 expressions in parallel.  To indicate that two voices should play
979 at the same time, simply enter a simultaneous combination of music
980 expressions.  A @q{simultaneous} music expression is formed by
981 enclosing expressions inside @code{<<} and @code{>>}.  In the
982 following example, three sequences (all containing two separate
983 notes) are combined simultaneously:
984
985 @lilypond[verbatim,quote,ragged-right]
986 \relative c'' {
987   <<
988     { a4 g }
989     { f e }
990     { d b }
991   >>
992 }
993 @end lilypond
994
995 Note that we have indented each level of the input with a
996 different amount of space.  LilyPond does not care how much (or
997 little) space there is at the beginning of a line, but indenting
998 LilyPond code like this makes it much easier for humans to read.
999
1000 @warning{each note is relative to the previous note in
1001 the input, not relative to the @code{c''} in the initial
1002 @code{\\relative} command.}
1003
1004
1005 @subheading Simultaneous music expressions: single staff
1006
1007 To determine the number of staves in a piece, LilyPond looks at
1008 the first expression.  If it is a single note, there is one staff;
1009 if there is a simultaneous expression, there is more than one
1010 staff.
1011
1012 @lilypond[verbatim,quote,ragged-right]
1013 \relative c'' {
1014   c2 <<c e>>
1015   << { e f } { c <<b d>> } >>
1016 }
1017 @end lilypond
1018
1019 @cindex expression
1020 @cindex music expression
1021 @subheading Analogy: mathematical expressions
1022
1023 This mechanism is similar to mathematical formulas: a big formula
1024 is created by composing small formulas.  Such formulas are called
1025 expressions, and they can contain other music expressions, so you
1026 can make arbitrarily complex and large expressions.  For example,
1027
1028 @example
1029 1
1030
1031 1 + 2
1032
1033 (1 + 2) * 3
1034
1035 ((1 + 2) * 3) / (4 * 5)
1036 @end example
1037
1038 This is a sequence of expressions, where each expression is
1039 contained in the next (larger) one.  The simplest expressions are
1040 numbers, and larger ones are made by combining expressions with
1041 operators (like @code{+}, @code{*} and @code{/}) and parentheses.
1042 Like mathematical expressions, music expressions can be nested
1043 arbitrarily deep, which is necessary for complex music like
1044 polyphonic scores.
1045
1046
1047 @node Multiple staves
1048 @subsection Multiple staves
1049
1050 LilyPond input files are constructed out of music expressions, as
1051 we saw in @ref{Music expressions explained}.  If the score begins
1052 with simultaneous music expressions, LilyPond creates multiples
1053 staves.  However, it is easier to see what happens if we create
1054 each staff explicitly.
1055
1056 To print more than one staff, each piece of music that makes up a
1057 staff is marked by adding @code{\new Staff} before it.  These
1058 @code{Staff} elements are then combined in parallel with @code{<<}
1059 and @code{>>}:
1060
1061 @lilypond[verbatim,quote,ragged-right]
1062 \relative c'' {
1063   <<
1064     \new Staff { \clef treble c }
1065     \new Staff { \clef bass c,, }
1066   >>
1067 }
1068 @end lilypond
1069
1070 The command @code{\new} introduces a @q{notation context.}  A
1071 notation context is an environment in which musical events (like
1072 notes or @code{\clef} commands) are interpreted.  For simple
1073 pieces, such notation contexts are created automatically.  For
1074 more complex pieces, it is best to mark contexts explicitly.
1075
1076 There are several types of contexts.  @code{Score}, @code{Staff},
1077 and @code{Voice} handle melodic notation, while @code{Lyrics} sets
1078 lyric texts and @code{ChordNames} prints chord names.
1079
1080 In terms of syntax, prepending @code{\new} to a music expression
1081 creates a bigger music expression.  In this way it resembles the
1082 minus sign in mathematics.  The formula @math{(4+5)} is an
1083 expression, so @math{-(4+5)} is a bigger expression.
1084
1085 Time signatures entered in one staff affect all other
1086 staves@footnote{This behavior may be changed if desired; for
1087 details, see @ruser{Polymetric notation}.}.  On the other hand,
1088 the key signature of one staff does @emph{not} affect other
1089 staves.
1090
1091 @lilypond[verbatim,quote,ragged-right]
1092 \relative c'' {
1093   <<
1094     \new Staff { \clef treble \key d \major \time 3/4 c }
1095     \new Staff { \clef bass c,, }
1096   >>
1097 }
1098 @end lilypond
1099
1100
1101
1102
1103 @node Piano staves
1104 @subsection Piano staves
1105
1106 @cindex staff switch, manual
1107 @cindex cross staff voice, manual
1108
1109 Music Glossary: @rglos{brace}.
1110
1111 Piano music is typeset in two staves connected by a
1112 @notation{brace}.
1113 Printing such a staff is similar to the polyphonic example in
1114 @ref{Multiple staves}.  However, now this entire expression is
1115 inserted inside a @code{PianoStaff}:
1116
1117 @example
1118 \new PianoStaff <<
1119   \new Staff @dots{}
1120   \new Staff @dots{}
1121 >>
1122 @end example
1123
1124 Here is a small example:
1125
1126 @lilypond[verbatim,quote,ragged-right]
1127 \relative c'' {
1128   \new PianoStaff <<
1129     \new Staff { \time 2/4 c4 e g g, }
1130     \new Staff { \clef bass c,, c' e c }
1131   >>
1132 }
1133 @end lilypond
1134
1135 @seealso
1136
1137 Notation Reference: @ruser{Piano music}.
1138
1139
1140 @node Combining notes into chords
1141 @subsection Combining notes into chords
1142
1143 @cindex chords
1144
1145 Music Glossary: @rglos{chord}.
1146
1147 @notation{Chords} can be made by surrounding pitches with single
1148 angle brackets.  Angle brackets are the symbols @code{<} and
1149 @code{>}.
1150
1151 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1152 r4 <c e g>4 <c f a>2
1153 @end lilypond
1154
1155 You can combine markings like beams and ties with chords.  They
1156 must be placed outside the angle brackets.
1157
1158 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1159 r4 <c e g>8[ <c f a>]~ <c f a>2
1160 @end lilypond
1161
1162 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1163 r4 <c e g>8\>( <c e g> <c e g>4 <c f a>\!)
1164 @end lilypond
1165
1166
1167 @node Single staff polyphony
1168 @subsection Single staff polyphony
1169
1170 @cindex polyphony
1171 @cindex multiple voices
1172 @cindex voices, more -- on a staff
1173 When different melodic lines are combined on a single staff they
1174 are printed as polyphonic voices; each voice has its own stems,
1175 slurs and beams, and the top voice has the stems up, while the
1176 bottom voice has them down.
1177
1178 Entering such parts is done by entering each voice as a sequence
1179 (with @code{@{...@}}) and combining these simultaneously,
1180 separating the voices with @code{\\}
1181
1182 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1183 <<
1184   { a4 g2 f4~ f4 } \\
1185   { r4 g4 f2 f4 }
1186 >>
1187 @end lilypond
1188
1189 For polyphonic music typesetting, spacer rests can also be
1190 convenient; these are rests that do not print.  They are useful
1191 for filling up voices that temporarily do not play.  Here is the
1192 same example with a spacer rest (@code{s}) instead of a normal
1193 rest (@code{r}),
1194
1195 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1196 <<
1197   { a4 g2 f4~ f4 } \\
1198   { s4 g4 f2 f4 }
1199 >>
1200 @end lilypond
1201
1202 @noindent
1203 Again, these expressions can be nested arbitrarily.
1204
1205 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1206 <<
1207   \new Staff <<
1208     { a4 g2 f4~ f4 } \\
1209     { s4 g4 f2 f4 }
1210   >>
1211   \new Staff <<
1212     \clef bass
1213     { <c g>1 ~ <c g>4 } \\
1214     { e,,4 d e2 ~ e4}
1215   >>
1216 >>
1217 @end lilypond
1218
1219 @seealso
1220
1221 Notation Reference: @ruser{Simultaneous notes}.
1222
1223
1224 @node Songs
1225 @section Songs
1226
1227 This section introduces vocal music and simple song sheets.
1228
1229 @menu
1230 * Setting simple songs::        
1231 * Aligning lyrics to a melody::  
1232 * Lyrics to multiple staves::   
1233 @end menu
1234
1235
1236 @node Setting simple songs
1237 @subsection Setting simple songs
1238
1239 @cindex lyrics
1240 @cindex songs
1241
1242 Music Glossary: @rglos{lyrics}.
1243
1244 Here is the start of the melody to a nursery
1245 rhyme, @qq{Girls and boys come out to play}:
1246
1247 @lilypond[verbatim,quote,ragged-right]
1248 \relative c'' {
1249   \key g \major
1250   \time 6/8
1251   d4 b8 c4 a8 d4 b8 g4
1252 }
1253 @end lilypond
1254
1255 The @notation{lyrics} can be set to these notes, combining both
1256 with the @code{\addlyrics} keyword.  Lyrics are entered by
1257 separating each syllable with a space.
1258
1259 @lilypond[verbatim,quote,ragged-right]
1260 <<
1261   \relative c'' {
1262     \key g \major
1263     \time 6/8
1264     d4 b8 c4 a8 d4 b8 g4
1265   }
1266   \addlyrics {
1267     Girls and boys come out to play,
1268   }
1269 >>
1270 @end lilypond
1271
1272 Note the curly brackets delimiting both the music and the lyrics,
1273 and the angle brackets @code{<< ... >>} around the whole piece to
1274 show that the music and lyrics are to occur at the same time.
1275
1276 @node Aligning lyrics to a melody
1277 @subsection Aligning lyrics to a melody
1278
1279 Music Glossary: @rglos{melisma}, @rglos{extender line}.
1280
1281 @cindex melisma
1282 @cindex extender line
1283 @cindex hyphens
1284 @cindex underscore
1285
1286 The next line in the nursery rhyme is @q{The moon doth shine as
1287 bright as day}.  Let's extend it:
1288
1289 @lilypond[verbatim,quote,ragged-right]
1290 <<
1291   \relative c'' {
1292     \key g \major
1293     \time 6/8
1294     d4 b8 c4 a8 d4 b8 g4 
1295     g8 a4 b8 c b a d4 b8 g4.
1296   }
1297   \addlyrics {
1298     Girls and boys come out to play,
1299     The moon doth shine as bright as day;
1300   }
1301 >>
1302 @end lilypond
1303
1304 We see the extra lyrics do not align properly with the notes.  The
1305 word @q{shine} should be sung on two notes, not one.  This is
1306 called a @notation{melisma}, a single syllable sung to more than one
1307 note.  There are several ways to spread a syllable over multiple
1308 notes, the simplest being to add a slur across them (see @ref{Ties
1309 and slurs}):
1310
1311 @lilypond[verbatim,quote,ragged-right]
1312 <<
1313   \relative c'' {
1314     \key g \major
1315     \time 6/8
1316     d4 b8 c4 a8 d4 b8 g4 
1317     g8 a4 b8 c([ b)] a d4 b8 g4.
1318   }
1319   \addlyrics {
1320     Girls and boys come out to play,
1321     The moon doth shine as bright as day;
1322   }
1323 >> 
1324 @end lilypond
1325
1326 Here we have also used manual beaming (the square brackets @code{[
1327 ]} ) to generate the beaming which is customarily used with lyrics
1328 (see @ref{Automatic and manual beams}).
1329
1330 If a syllable extends over several notes or a single very long
1331 note an @notation{extender line} is usually drawn from the syllable
1332 extending under all the notes for that syllable.  It is entered as
1333 two underscores @code{__}.  Here is an example from the first
1334 three bars of Dido's Lament, from Purcell's Dido and Ă†neas:
1335
1336 @lilypond[verbatim,quote,ragged-right]
1337 <<
1338   \relative c'' {
1339     \key g \minor
1340     \time 3/2
1341     g2 a bes bes( a) 
1342     b c4.( bes8 a4. g8 fis4.) g8 fis1
1343   }
1344   \addlyrics {
1345     When I am laid, 
1346     am laid __ in earth,
1347   }
1348 >>
1349 @end lilypond
1350
1351 None of the examples so far have involved words containing more
1352 than one syllable.  Such words are usually split one syllable to a
1353 note, with hyphens between syllables.  Such hyphens are entered as
1354 two dashes, resulting in a centered hyphen between the syllables.
1355 Here is an example showing this and everything we have learned so
1356 far about aligning lyrics to notes.
1357
1358 @c no ragged-right here because otherwise the hyphens get lost,
1359 @c but the example is long enough to avoid looking strange.
1360 @lilypond[verbatim,quote]
1361 <<
1362   \relative c' {
1363     \key g \major
1364     \time 3/4
1365     \partial 4
1366     d4 g4 g a8( b) g4 g4 
1367     b8( c) d4 d e4 c2
1368   }
1369   \addlyrics {
1370     A -- way in a __ man -- ger, 
1371     no __ crib for a bed, __
1372   }
1373 >>
1374 @end lilypond
1375
1376 Some lyrics, especially those in Italian, require the opposite:
1377 setting more than one syllable to a single note.  This is
1378 achieved by linking the syllables together with a single
1379 underscore @code{_} (with no spaces), or enclosing them in
1380 quotes.  Here's an example from Rossini's Figaro, where
1381 @q{al} has to be sung on the same note as the @q{go} of 
1382 @q{Largo} in Figaro's aria @q{Largo al factotum}:
1383
1384 @c no ragged-right here because otherwise the hyphens get lost,
1385 @c but the example is long enough to avoid looking strange.
1386 @lilypond[verbatim,quote]
1387 <<
1388   \relative c' {
1389     \clef bass
1390     \key c \major
1391     \time 6/8
1392     c4.~ c8 d b c([ d)] b c d b c
1393   }
1394   \addlyrics {
1395     Lar -- go_al fac -- to -- tum del -- la cit -- tĂ 
1396   }
1397 >>
1398 @end lilypond
1399
1400
1401 @seealso
1402
1403 Notation Reference: @ruser{Vocal music}.
1404
1405
1406 @node Lyrics to multiple staves
1407 @subsection Lyrics to multiple staves
1408
1409 The simple approach using @code{\addlyrics} can be used for
1410 placing lyrics under more than one staff.  Here is an
1411 example from Handel's Judas Maccabæus:
1412
1413 @lilypond[verbatim,quote,ragged-right]
1414 <<
1415   {
1416     \time 6/8
1417     \partial 8
1418   }
1419   \relative c'' {
1420     \key f \major
1421     c8 c([ bes)] a a([ g)] f f'4. b, c4.~ c4
1422   }
1423   \addlyrics {
1424     Let flee -- cy flocks the hills a -- dorn, __
1425   }
1426   \relative c' {
1427     \key f \major
1428     r8 r4. r4 c8 a'([ g)] f f([ e)] d e([ d)] c bes'4
1429   }
1430   \addlyrics {
1431     Let flee -- cy flocks the hills a -- dorn,
1432   }
1433 >>
1434 @end lilypond
1435
1436 but scores any more complex than this simple example are
1437 better produced by separating out the staff structure
1438 from the notes and lyrics with variables.  These are
1439 discussed later (see @ref{Organizing pieces with variables}).
1440
1441 @seealso
1442
1443 Notation Reference: @ruser{Vocal music}.
1444
1445
1446 @node Final touches
1447 @section Final touches
1448
1449 This is the final section of the tutorial; it demonstrates how to
1450 add the final touches to simple pieces, and provides an
1451 introduction to the rest of the manual.
1452
1453 @menu
1454 * Version number::              
1455 * Adding titles::               
1456 * Absolute note names::         
1457 * Organizing pieces with variables::  
1458 * After the tutorial::          
1459 * How to read the manual::      
1460 @end menu
1461
1462
1463 @node Version number
1464 @subsection Version number
1465
1466 @cindex versioning
1467 The @code{\version} statement records the version of LilyPond that
1468 was used to write the file:
1469
1470 @example
1471 \version "2.11.23"
1472 @end example
1473
1474 @noindent
1475 By convention, this is placed at the top of your LilyPond file.
1476
1477 These annotations make future upgrades of LilyPond go more
1478 smoothly.  Changes in the syntax are handled with a special
1479 program, @file{convert-ly}, and it uses @code{\version} to
1480 determine what rules to apply.  For details, see
1481 @rprogram{Updating files with convert-ly}.
1482
1483
1484 @node Adding titles
1485 @subsection Adding titles
1486
1487 The title, composer, opus number, and similar information are
1488 entered in the @code{\header} block.  This exists outside of the
1489 main music expression; the @code{\header} block is usually placed
1490 underneath the @ref{Version number}.
1491
1492 @example
1493 \version "2.11.23"
1494 \header @{
1495   title = "Symphony"
1496   composer = "Me"
1497   opus = "Op. 9"
1498 @}
1499
1500 @{
1501   @dots{} music @dots{}
1502 @}
1503 @end example
1504
1505 When the file is processed, the title and composer are printed
1506 above the music.  More information on titling can be found in
1507 @ruser{Creating titles}.
1508
1509
1510 @node Absolute note names
1511 @subsection Absolute note names
1512
1513 So far we have always used @code{\relative} to define pitches.
1514 This is the easiest way to enter most music, but another way of
1515 defining pitches exists: absolute mode.
1516
1517 If you omit the @code{\relative}, LilyPond treats all pitches as
1518 absolute values.  A @code{c'} will always mean middle C, a
1519 @code{b} will always mean the note one step below middle C, and a
1520 @code{g,} will always mean the note on the bottom staff of the
1521 bass clef.
1522
1523 @lilypond[verbatim,quote,ragged-right]
1524 {
1525   \clef bass
1526   c' b g, g,
1527   g, f, f c'
1528 }
1529 @end lilypond
1530
1531 Here is a four-octave scale:
1532
1533 @lilypond[verbatim,quote,ragged-right]
1534 {
1535   \clef bass
1536   c, d, e, f,
1537   g, a, b, c
1538   d e f g
1539   a b c' d'
1540   \clef treble
1541   e' f' g' a'
1542   b' c'' d'' e''
1543   f'' g'' a'' b''
1544   c'''1
1545 }
1546 @end lilypond
1547
1548 As you can see, writing a melody in the treble clef involves a lot
1549 of quote @code{'} marks.  Consider this fragment from Mozart:
1550
1551 @lilypond[verbatim,quote,ragged-right]
1552 {
1553   \key a \major
1554   \time 6/8
1555   cis''8. d''16 cis''8 e''4 e''8
1556   b'8. cis''16 b'8 d''4 d''8
1557 }
1558 @end lilypond
1559
1560 All these quotes makes the input less readable and it is a source
1561 of errors.  With @code{\relative}, the previous example is much
1562 easier to read:
1563
1564 @lilypond[verbatim,quote,ragged-right]
1565 \relative c'' {
1566   \key a \major
1567   \time 6/8
1568   cis8. d16 cis8 e4 e8
1569   b8. cis16 b8 d4 d8
1570 }
1571 @end lilypond
1572
1573 If you make a mistake with an octave mark (@code{'} or @code{,})
1574 while working in @code{\relative} mode, it is very obvious -- many
1575 notes will be in the wrong octave.  When working in absolute mode,
1576 a single mistake will not be as visible, and will not be as easy
1577 to find.
1578
1579 However, absolute mode is useful for music which has large
1580 intervals, and is extremely useful for computer-generated LilyPond
1581 files.
1582
1583
1584 @node Organizing pieces with variables
1585 @subsection Organizing pieces with variables
1586
1587 When all of the elements discussed earlier are combined to produce
1588 larger files, the music expressions get a lot bigger.  In
1589 polyphonic music with many staves, the input files can become very
1590 confusing.  We can reduce this confusion by using
1591 @emph{variables}.
1592
1593 With variables (also known as identifiers or macros), we can break
1594 up complex music expressions.  A variable is assigned as
1595 follows:
1596
1597 @example
1598 namedMusic = @{ @dots{} @}
1599 @end example
1600
1601 The contents of the music expression @code{namedMusic} can be used
1602 later by placing a backslash in front of the name
1603 (@code{\namedMusic}, just like a normal LilyPond command).
1604 Variables must be defined @emph{before} the main music
1605 expression.
1606
1607 @lilypond[verbatim,quote,ragged-right]
1608 violin = \new Staff { \relative c'' {
1609   a4 b c b
1610 }}
1611 cello = \new Staff { \relative c {
1612   \clef bass
1613   e2 d
1614 }}
1615 {
1616   <<
1617     \violin
1618     \cello
1619   >>
1620 }
1621 @end lilypond
1622
1623 @noindent
1624 The name of a variable must have alphabetic characters only, no
1625 numbers, underscores, or dashes.
1626
1627 It is possible to use variables for many other types of objects in
1628 the input.  For example,
1629
1630 @example
1631 width = 4.5\cm
1632 name = "Wendy"
1633 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1634 @end example
1635
1636 Depending on its contents, the variable can be used in different
1637 places.  The following example uses the above variables:
1638
1639 @example
1640 \paper @{
1641   \aFivePaper
1642   line-width = \width
1643 @}
1644 @{ c4^\name @}
1645 @end example
1646
1647
1648 @node After the tutorial
1649 @subsection After the tutorial
1650
1651 After finishing the tutorial, you should probably try writing a
1652 piece or two.  Start by adding notes to one of the @ref{Templates}.
1653 If you need any notation that was not covered in the
1654 tutorial, look at the Notation Reference, starting with
1655 @ruser{Musical notation}.  If you want to write for an instrument
1656 ensemble that is not covered in the templates, take a look at
1657 @ref{Extending the templates}.
1658
1659 Once you have written a few short pieces, read the rest of the
1660 Learning Manual (chapters 3-5).  There's nothing wrong with
1661 reading it now, of course!  However, the rest of the Learning
1662 Manual assumes that you are familiar with LilyPond input.  You may
1663 wish to skim these chapters right now, and come back to them after
1664 you have more experience.
1665
1666
1667 @node How to read the manual
1668 @subsection How to read the manual
1669
1670 Many examples in the tutorial omitted a @code{\relative c'' @{
1671 ... @}} around the printed example, as we saw in
1672 @ref{How to read the tutorial}.
1673
1674 In the rest of the manual, we are much more lax about the printed
1675 examples: sometimes they may have omitted a @code{\relative c'' @{
1676 ... @}}, but other times a different initial pitch may be used
1677 (such as @code{c'} or @code{c,,}), and in some cases the whole
1678 example is in absolute note mode!  However, ambiguities like this
1679 only exist where the pitches are not important.  In any example
1680 where the pitch matters, we have explicitly stated
1681 @code{\relative} or absolute-mode @code{@{ @}}.
1682
1683 If you are still confused about the exact LilyPond input that was
1684 used in an example, read the HTML version (if you are not already
1685 doing so) and click on the picture of the music.  This will
1686 display the exact input that LilyPond used to generate this
1687 manual.
1688
1689 For information about the structure of the rest of the manual, see
1690 @ref{About this manual}.
1691