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