]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/learning/tutorial.itely
Issue 4894: Remove unescaped @funindex entries
[lilypond.git] / Documentation / learning / tutorial.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
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.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @include included/generating-output.itexi
12
13 @c \version "2.19.21"
14
15 @node Tutorial
16 @chapter Tutorial
17
18 This chapter gives a basic introduction to working with LilyPond.
19
20 @menu
21 * Compiling a file::
22 * How to write input files::
23 * Dealing with errors::
24 * How to read the manuals::
25 @end menu
26
27 @node Compiling a file
28 @section Compiling a file
29
30 This section introduces @qq{compiling}---the processing of
31 LilyPond input files (written by you) to produce output files.
32
33 @menu
34 * Entering input::
35 * MacOS X::
36 * Windows::
37 * Command-line::
38 @end menu
39
40 @node Entering input
41 @subsection Entering input
42
43 @cindex compiling
44 @cindex first example
45 @cindex example, first
46 @cindex case sensitive
47
48 @menu
49 * Producing output::
50 @end menu
51
52 @qq{Compiling} is the term used for processing an input file in
53 LilyPond format to produce output file(s).  Output files are
54 generally PDF (for printing or viewing), MIDI (for playing), and
55 PNG (for online use).  LilyPond input files are simple text files.
56
57 This example shows a simple input file:
58
59 @example
60 \version "@w{@version{}}"
61 @{
62   c' e' g' e'
63 @}
64 @end example
65
66 The graphical output is:
67
68 @c  in this case we don't want verbatim
69 @lilypond[quote]
70 {
71   c' e' g' e'
72 }
73 @end lilypond
74
75 @warning{Notes and lyrics in LilyPond input must always be
76 surrounded by @w{@strong{@{ curly braces @}}}.  The braces
77 should also be surrounded by a space unless they are at the
78 beginning or end of a line to avoid ambiguities.  They may
79 be omitted in some examples in this manual, but don't forget them
80 in your own music!  For more information about the display of
81 examples in the manual, see @ref{How to read the manuals}.}
82
83 In addition, LilyPond input is @strong{case sensitive}.
84 @w{@samp{@{ c d e @}}} is valid input; @w{@samp{@{ C D E @}}} will
85 produce an error message.
86
87
88 @smallspace
89
90 @node Producing output
91 @unnumberedsubsubsec Producing output
92
93 @cindex PDF file
94 @cindex viewing music
95 @cindex text editors
96
97 The method of producing output depends on your operating system
98 and the program(s) you use.
99
100 @itemize
101
102 @item
103 @ref{MacOS X, @sourceimage{logo-macosx,,,}}
104 @ref{MacOS X, MacOS X} (graphical)
105
106 @item
107 @ref{Windows, @sourceimage{logo-windows,,,}}
108 @ref{Windows, Microsoft Windows} (graphical)
109
110 @item
111 @ref{Command-line, @sourceimage{logo-linux,,,}
112 @sourceimage{logo-freebsd,,,}
113 @sourceimage{logo-macosx,,,}
114 @sourceimage{logo-windows,,,}
115 }
116 @ref{Command-line, All operating systems} (command-line)
117
118 @end itemize
119
120 There are several other text editors available with specific
121 support for LilyPond.  For more information, see
122 @rweb{Easier editing}.
123
124 @warning{The first time you ever run LilyPond, it may take a
125 minute or two because all of the system fonts have to be analyzed
126 first.  After this, LilyPond will be much faster!}
127
128
129 @node MacOS X
130 @subsection MacOS X
131
132 @cindex running LilyPond under MacOS X
133 @cindex MacOS X, running LilyPond
134
135 @lilypadOSX
136
137
138 @node Windows
139 @subsection Windows
140
141 @cindex running LilyPond under Windows
142 @cindex Windows, running LilyPond
143
144 @lilypadWindows
145
146
147 @node Command-line
148 @subsection Command-line
149
150 @cindex running LilyPond under Unix
151 @cindex Unix, running LilyPond
152
153 @lilypadCommandLine
154
155 @node How to write input files
156 @section How to write input files
157
158 This section introduces some basic LilyPond syntax to help get you
159 started writing input files.
160
161 @menu
162 * Simple notation::
163 * Working on input files::
164 @end menu
165
166
167 @node Simple notation
168 @subsection Simple notation
169
170 @cindex simple notation
171 @cindex notation, simple
172
173 @menu
174 * Pitches::
175 * Durations (rhythms)::
176 * Rests::
177 * Time signature::
178 * Tempo marks::
179 * Clef::
180 * All together::
181 @end menu
182
183 LilyPond will add some notation elements automatically.  In the
184 next example, we have only specified four pitches, but LilyPond
185 has added a clef, time signature, and rhythms.
186
187 @lilypond[verbatim,quote]
188 {
189   c' e' g' e'
190 }
191 @end lilypond
192
193 @noindent
194 This behavior may be altered, but in most cases these automatic
195 values are useful.
196
197
198 @node Pitches
199 @unnumberedsubsubsec Pitches
200
201 @cindex pitches
202 @cindex relative mode
203 @cindex quote, single
204 @cindex comma
205 @cindex accidentals and relative mode
206 @cindex relative mode, and accidentals
207
208 @funindex \relative
209 @funindex '
210 @funindex ,
211
212 Music Glossary: @rglos{pitch}, @rglos{interval},
213 @rglos{scale}, @rglos{middle C}, @rglos{octave},
214 @rglos{accidental}.
215
216 LilyPond uses lower-case letters for pitches.  The letters
217 @code{c} through@tie{}@code{b} denote pitches in the
218 @q{small octave} below @notation{middle C}.  Added @code{'}
219 or@tie{}@code{,} suffixes indicate higher or lower octaves.
220 Here is a scale starting on @notation{middle C}, and an arpeggio:
221
222 @lilypond[verbatim,quote]
223 { c' d' e' f' g' a' b' c'' g c' e' g' c'' e'' g'' c''' }
224 @end lilypond
225
226 The easiest way to enter notes is by using @code{\relative} mode.
227 In this mode, the octave is chosen automatically by assuming the
228 following note is always to be placed closest to the previous
229 note, i.e., it is to be placed in the octave which is within three
230 staff spaces of the previous note.  We begin by entering the most
231 elementary piece of music, a @notation{scale}, in which every note
232 is within just one staff space of the previous note.
233
234 @lilypond[verbatim,quote]
235 \relative {
236   c' d e f
237   g a b c
238 }
239 @end lilypond
240
241 The initial note is @notation{middle C}, denoted by @code{c'}.
242 Each successive note is
243 placed closest to the previous note -- in other words, the first
244 @code{c} is the closest C to middle C.  This is followed by the
245 closest D to the previous note.  We can create melodies which have
246 larger intervals, still using only @code{\relative} mode:
247
248 @lilypond[verbatim,quote]
249 \relative {
250   d' f a g
251   c b f d
252 }
253 @end lilypond
254
255 @noindent
256 In the previous example, the first note -- the @code{d'} with one
257 @code{'}-mark -- is the D in the octave starting from middle C
258 and going up to B.
259
260 By adding (or removing) quotes @code{'} or commas @code{,} from
261 the first note, we can change the starting octave:
262
263 @lilypond[verbatim,quote]
264 \relative {
265   e'' c a c
266 }
267 @end lilypond
268
269 Relative mode can be confusing initially, but is the easiest way
270 to enter most melodies.  Let us see how this relative calculation
271 works in practice.  Starting from a B, which is on the middle line
272 in a treble clef, you can reach a C, D and E within 3 staff spaces
273 going up, and an A, G and F within 3 staff spaces going down.  So
274 if the note following a B is a C, D or E it will be assumed to be
275 above the B, and an A, G or F will be assumed to be below.
276
277 @lilypond[verbatim,quote]
278 \relative {
279   b' c % c is 1 staff space up, so is the c above
280   b d  % d is 2 up or 5 down, so is the d above
281   b e  % e is 3 up or 4 down, so is the e above
282   b a  % a is 6 up or 1 down, so is the a below
283   b g  % g is 5 up or 2 down, so is the g below
284   b f  % f is 4 up or 3 down, so is the f below
285 }
286 @end lilypond
287
288 Exactly the same happens even when any of these notes are
289 sharpened or flattened.  @notation{Accidentals} are
290 @strong{totally ignored} in the calculation of relative position.
291 Precisely the same staff space counting is done from a note at any
292 other position on the staff.
293
294 To add intervals that are larger than three staff spaces, we can
295 raise the @notation{octave} by adding a single quote @code{'} (or
296 apostrophe) to the note name.  We can lower the octave by adding a
297 comma @code{,} to the note name.
298
299 @lilypond[verbatim,quote]
300 \relative {
301   a' a, c' f,
302   g g'' a,, f'
303 }
304 @end lilypond
305
306 @noindent
307 To change a note by two (or more!) octaves, we use multiple
308 @code{''} or @code{,,} -- but be careful that you use two single
309 quotes @code{''} and not one double quote @code{"}@tie{}!
310 @c " - keeps quotes in order for context-sensitive editor -td
311
312 @node Durations (rhythms)
313 @unnumberedsubsubsec Durations (rhythms)
314
315 @cindex note durations
316 @cindex durations
317 @cindex rhythms
318 @cindex whole note
319 @cindex half note
320 @cindex quarter note
321 @cindex dotted note
322 @cindex notating durations
323
324 Music Glossary: @rglos{beam}, @rglos{duration},
325 @rglos{whole note}, @rglos{half note}, @rglos{quarter note},
326 @rglos{dotted note}.
327
328 The @notation{duration} of a note is specified by a number after
329 the note name:  @code{1} for a @notation{whole note}, @code{2} for
330 a @notation{half note}, @code{4} for a @notation{quarter note} and
331 so on.  @notation{Beams} are added automatically.
332
333 If you do not specify a duration, the previous duration is used
334 for the next note.  The duration of the first note defaults to a
335 quarter note.
336
337 @lilypond[verbatim,quote]
338 \relative {
339   a'1
340   a2 a4 a8 a
341   a16 a a a a32 a a a a64 a a a a a a a a2
342 }
343 @end lilypond
344
345 To create @notation{dotted notes}, add a dot @code{.} to the
346 duration number.  The duration of a dotted note must be stated
347 explicitly (i.e., with a number).
348
349 @lilypond[verbatim,quote]
350 \relative {
351   a'4 a a4. a8
352   a8. a16 a a8. a8 a4.
353 }
354 @end lilypond
355
356 @node Rests
357 @unnumberedsubsubsec Rests
358
359 @cindex rest
360 @cindex notating rests
361
362 Music Glossary: @rglos{rest}.
363
364 A @notation{rest} is entered just like a note with the name
365 @code{r}@tie{}:
366
367 @lilypond[verbatim,quote]
368 \relative {
369   a'4 r r2
370   r8 a r4 r4. r8
371 }
372 @end lilypond
373
374
375 @node Time signature
376 @unnumberedsubsubsec Time signature
377
378 @cindex time signature
379
380 @funindex \time
381
382 Music Glossary: @rglos{time signature}.
383
384 The @notation{time signature} can be set with the @code{\time}
385 command:
386
387 @lilypond[verbatim,quote]
388 \relative {
389   \time 3/4
390   a'4 a a
391   \time 6/8
392   a4. a
393   \time 4/4
394   a4 a a a
395 }
396 @end lilypond
397
398 @node Tempo marks
399 @unnumberedsubsubsec Tempo marks
400
401 @cindex tempo marks
402 @cindex metronome marks
403
404 @funindex \tempo
405
406 Music Glossary: @rglos{tempo indication}, @rglos{metronome}.
407
408 The @notation{tempo indication} and @notation{metronome mark} can be
409 set with the @code{\tempo} command:
410
411 @lilypond[verbatim,quote]
412 \relative {
413   \time 3/4
414   \tempo "Andante"
415   a'4 a a
416   \time 6/8
417   \tempo 4. = 96
418   a4. a
419   \time 4/4
420   \tempo  "Presto" 4 = 120
421   a4 a a a
422 }
423 @end lilypond
424
425
426 @node Clef
427 @unnumberedsubsubsec Clef
428
429 @cindex clef
430 @cindex treble
431 @cindex alto
432 @cindex tenor
433 @cindex bass
434
435 @funindex \clef
436
437 Music Glossary: @rglos{clef}.
438
439 The @notation{clef} can be set using the @code{\clef} command:
440
441 @lilypond[verbatim,quote]
442 \relative {
443   \clef "treble"
444   c'1
445   \clef "alto"
446   c1
447   \clef "tenor"
448   c1
449   \clef "bass"
450   c1
451 }
452 @end lilypond
453
454
455 @node All together
456 @unnumberedsubsubsec All together
457
458 Here is a small example showing all these elements together:
459
460 @lilypond[verbatim,quote]
461 \relative {
462   \clef "bass"
463   \time 3/4
464   \tempo "Andante" 4 = 120
465   c,2 e8 c'
466   g'2.
467   f4 e d
468   c4 c, r
469 }
470 @end lilypond
471
472
473 @seealso
474 Notation Reference: @ruser{Writing pitches},
475 @ruser{Writing rhythms}, @ruser{Writing rests},
476 @ruser{Time signature}, @ruser{Clef}.
477
478
479 @node Working on input files
480 @subsection Working on input files
481
482 @cindex curly braces
483 @cindex braces, curly
484 @cindex comments
485 @cindex line comment
486 @cindex comment, line
487 @cindex block comment
488 @cindex comment, line
489 @cindex case sensitive
490 @cindex whitespace insensitive
491 @cindex expressions
492 @cindex versioning
493 @cindex version
494 @cindex version number
495
496 @funindex \version
497 @funindex { ... }
498 @funindex %
499 @funindex %@{ ... %@}
500
501 LilyPond input files are similar to source files in many common
502 programming languages.  They contain a version statement, are case
503 sensitive, and white-space is generally ignored.  Expressions are
504 formed with curly braces @w{@code{@{ @}}}, and comments are
505 denoted with @code{%} or @w{@code{%@{ @dots{} %@}}}@tie{}.
506
507 If the previous sentences sound like nonsense, don't worry!  We'll
508 explain what all these terms mean:
509
510 @itemize
511
512 @item
513 @strong{Version statement}:
514 Every LilyPond file should contain a version statement.  A version
515 statement is a line that describes the version of LilyPond for which
516 the file was written, as in the following example:
517
518 @example
519 \version "@w{@version{}}"
520 @end example
521
522 By convention, the version statement is placed at the top of the
523 LilyPond file.
524
525 The version statement is important for at least two reasons.  First,
526 it allows automatic updating of the input file as LilyPond syntax
527 changes.  Second, it describes the version of LilyPond needed to
528 compile the file.
529
530 If the version statement is omitted from an input file, LilyPond will print
531 a warning during the compilation of the file.
532
533 @item
534 @strong{Case sensitive}:
535 it matters whether you enter a letter in lower case (e.g.
536 @w{@code{a, b, s, t}}) or upper case (e.g. @w{@code{A, B, S, T}}).
537 Notes are lower case: @w{@samp{@{ c d e @}}} is valid input;
538 @w{@samp{@{ C D E @}}} will produce an error message.
539
540 @item
541 @strong{Whitespace insensitive}:
542 it does not matter how many spaces (or tabs or new lines) you add.
543 @w{@samp{@{ c4 d e @}}} means the same thing as
544 @w{@samp{@{ c4 @tie{} @tie{} @tie{} d e @}}} and:
545
546 @example
547 @{ c4                       d
548                    e   @}
549 @end example
550
551 @noindent
552 Of course, the previous example is hard to read.  A good rule of
553 thumb is to indent code blocks with two spaces:
554
555 @example
556 @{
557   c4 d e
558 @}
559 @end example
560
561 However, whitespace @emph{is} required to separate many
562 syntactical elements from others.  In other words, whitespace can
563 always be @emph{added}, but not always @emph{eliminated}.  Since
564 missing whitespace can give rise to strange errors, it is
565 advisable to always insert whitespace before and after every
566 syntactic element, for example, before and after every curly
567 brace.
568
569 @item
570 @strong{Expressions}:
571 every piece of LilyPond input needs to have
572 @strong{@{@tie{}curly@tie{}braces@tie{}@}} placed around the
573 input.  These braces tell LilyPond that the input is a single
574 music expression, just like parentheses @code{()} in mathematics.
575 The braces should be surrounded by a space unless they are at the
576 beginning or end of a line to avoid ambiguities.
577
578 A LilyPond command followed by a simple expression in braces (such
579 as @q{@w{@code{@bs{}relative @{ @dots{} @}}}}) also counts as a
580 single music expression.
581
582 @cindex comments
583 @cindex line comment
584 @cindex block comment
585 @item
586 @strong{Comments}:
587 a comment is a remark for the human reader of the music input; it
588 is ignored while parsing, so it has no effect on the printed
589 output.  There are two types of comments.  The percent symbol
590 @code{%} introduces a line comment; anything after @code{%} on
591 that line is ignored.  By convention, a line comment is placed
592 @emph{above} the code it refers to.
593
594 @example
595 a4 a a a
596 % this comment refers to the Bs
597 b2 b
598 @end example
599
600 A block comment marks a whole section of music input as a comment.
601 Anything that is enclosed in @code{%@{} and @code{%@}} is ignored.
602 However, block comments do not @q{nest}.  This means that you
603 cannot place a block comment inside another block comment.  If you
604 try, the first @code{%@}} will terminate @emph{both} block
605 comments.  The following fragment shows possible uses for
606 comments:
607
608 @example
609 % notes for twinkle twinkle follow
610   c4 c g' g a a g2
611
612 %@{
613   This line, and the notes below are ignored,
614   since they are in a block comment.
615
616   f4 f e e d d c2
617 %@}
618 @end example
619
620 @end itemize
621
622
623 @node Dealing with errors
624 @section Dealing with errors
625
626 @cindex troubleshooting
627
628 Sometimes LilyPond doesn't produce the output you expect.  This
629 section provides some links to help you solve the problems you
630 might encounter.
631
632
633 @menu
634 * General troubleshooting tips::
635 * Some common errors::
636 @end menu
637
638 @node General troubleshooting tips
639 @subsection General troubleshooting tips
640
641 Troubleshooting LilyPond problems can be challenging for
642 people who are used to a graphical interface, because invalid
643 input files can be created.  When this happens, a logical approach
644 is the best way to identify and solve the problem.  Some guidelines
645 to help you learn to do this are provided in @rprogram{Troubleshooting}.
646
647
648 @node Some common errors
649 @subsection Some common errors
650
651 @cindex common errors
652 @cindex errors, common
653
654 There are a few common errors that are difficult to troubleshoot
655 based simply on the error messages that are displayed.  These are
656 described in @rprogram{Common errors}.
657
658
659
660 @node How to read the manuals
661 @section How to read the manuals
662
663 This section shows how to read the documentation efficiently, and
664 also introduces some useful interactive features available in the
665 online version.
666
667 @menu
668 * Omitted material::
669 * Clickable examples::
670 * Overview of manuals::
671 @end menu
672
673
674 @node Omitted material
675 @subsection Omitted material
676
677
678 @cindex how to read the manual
679 @cindex manual, reading
680 @cindex reading the manual
681 @cindex examples, clickable
682 @cindex clickable examples
683 @cindex tips for constructing files
684 @cindex templates
685 @cindex constructing files, tips
686 @cindex files, tips for constructing
687
688 LilyPond input must be surrounded by @code{@{ @}} marks or a
689 @q{@w{@code{@bs{}relative @{ @dots{} @}}}}, as we saw in
690 @ref{Working on input files}.  For the rest of this manual,
691 some short examples will omit this.  To replicate these examples,
692 you can copy displayed input, but paste it between @code{@{}
693 and @code{@}} in your input file.
694
695 @example
696 @{
697   @dots{}example goes here@dots{}
698 @}
699 @end example
700
701 Also, remember that every LilyPond file should have a
702 @code{\version} statement.  Because the examples in the manuals
703 are snippets, not files, the @code{\version} statement is omitted.
704 But you should make a practice of including them in your files.
705
706 @node Clickable examples
707 @subsection Clickable examples
708
709 @warning{This feature is only available in the HTML manuals.}
710
711 Many people learn programs by trying and fiddling around with the
712 program.  This is also possible with LilyPond.  If you click on a
713 picture in the HTML version of this manual, you will see the exact
714 LilyPond input that was used to generate that image.  Try it on
715 this image:
716
717 @c no verbatim here
718 @lilypond[quote]
719 \relative {
720   c''4-\markup { \bold \huge { Click here. } }
721 }
722 @end lilypond
723
724 By cutting and pasting everything in the @qq{ly snippet} section,
725 you have a starting template for experiments.  To see exactly the
726 same output (line-width and all), copy everything from @qq{Start
727 cut-&-pastable section} to the bottom of the file.
728
729
730 @ignore
731 This is item 825
732
733 @n ode Keyboard navigation
734 @s ubsection Keyboard navigation
735
736 @warning{This features is only available in the HTML manuals.}
737
738 @c TODO: once this is figured out, insert it here.
739
740 We are currently working on this feature.
741 @end ignore
742
743 @node Overview of manuals
744 @subsection Overview of manuals
745
746 There is a lot of documentation for LilyPond.  New users are
747 sometimes confused about what part(s) they should read, and
748 occasionally skip over reading vital portions.
749
750 @warning{Please do not skip over important parts of the
751 documentation.  You will find it much harder to understand later
752 sections.}
753
754 @itemize
755
756 @item
757 @strong{Before trying to do @emph{anything}}: read the Learning
758 manual's @ref{Tutorial}, and @ref{Common notation}.  If you
759 encounter musical terms which you do not recognize, please look
760 them up in the @rglosnamed{Top, Glossary}.
761
762 @item
763 @strong{Before trying to write a complete piece of music}: read
764 the Learning manual's @ref{Fundamental concepts}.  After that, you
765 may want to look in relevant sections of the
766 @rusernamed{Top, Notation reference}.
767
768 @item
769 @strong{Before trying to change the default output}: read the
770 Learning manual's @ref{Tweaking output}.
771
772 @item
773 @strong{Before undertaking a large project}: read the Usage
774 document's @rprogram{Suggestions for writing files}.
775
776 @end itemize
777
778
779