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