1 @c -*- coding: utf-8; mode: texinfo; -*-
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
6 When revising a translation, copy the HEAD committish of the
7 version that you are working on. See TRANSLATION for details.
12 @node Generating output
13 @chapter Generating output
15 This chapter gives a basic introduction to working with LilyPond.
20 * How to write input files::
21 * How to read the manuals::
24 @node Compiling a file
25 @section Compiling a file
37 @subsection Entering input
41 @cindex example, first
42 @cindex case sensitive
44 @qq{Compiling} is the term used for processing an input file
45 in LilyPond format to produce a file which can be printed and
46 (optionally) a MIDI file which can be played. LilyPond input
47 files are simple text files. The first example
48 shows what a simple input file looks like.
50 To create sheet music, we write an input file that specifies the
51 notation. For example, if we write:
60 the result looks like this:
62 @c in this case we don't want verbatim
69 @warning{Notes and lyrics in LilyPond input must always be
70 surrounded by @strong{@{ curly braces @}}. The braces
71 should also be surrounded by a space unless they are at the
72 beginning or end of a line to avoid ambiguities. The braces may
73 be omitted in some examples in this manual, but don't forget them
74 in your own music! For more information about the display of
75 examples in the manual, see @ref{How to read the manuals}.}
77 In addition, LilyPond input is @strong{case sensitive}.
78 @w{@code{@{ c d e @}}} is valid input; @w{@code{@{ C D E @}}} will
79 produce an error message.
83 @subheading Entering music and viewing output
88 @cindex running LilyPond under MacOS X
89 @cindex MacOS X, running LilyPond
90 @cindex running LilyPond under Windows
91 @cindex Windows, running LilyPond
92 @cindex running LilyPond under Unix
93 @cindex Unix, running LilyPond
95 In this section we will explain what commands to run and how to
96 view or print the output.
98 Note that there are several other text editors available with
99 better support for LilyPond. For more information, see
100 @ref{Alternate editors}.
102 @warning{The first time you ever run LilyPond, it may take a
103 minute or two because all of the system fonts have to be analyzed
104 first. After this, LilyPond will be much faster!}
110 If you double click @command{LilyPond.app}, it will open with an
111 example file. Save it, for example, to @file{test.ly} on your
112 Desktop, and then process it with the menu command
113 @w{@code{Compile > Typeset File}}. The resulting PDF file will be
114 displayed on your screen.
116 For future use of LilyPond, you should begin by selecting @q{New}
117 or @q{Open}. You must save your file before typesetting it. If
118 any errors occur in processing, please see the log window.
124 On Windows, if you double-click in the LilyPond icon on the
125 Desktop, it will open a simple text editor with an example file.
126 Save it, for example, to @file{test.ly} on your Desktop and then
127 double-click on the file to process it (the file icon looks like a
128 note). After some seconds, you will get a file @file{test.pdf} on
129 your desktop. Double-click on this PDF file to view the typeset
130 score. An alternative method to process the @file{test.ly} file
131 is to drag and drop it onto the LilyPond icon using your mouse
134 To edit an existing @file{.ly} file, right-click on it and
135 select @qq{Edit source}. To get an empty file to start from, run
136 the editor as described above and use @qq{New} in
137 the @qq{File} menu, or right-click on the desktop and select
138 @qq{New..Text Document}, change its name to a name of your choice
139 and change the file extension to @code{.ly}. Double-click the
140 icon to type in your LilyPond source code as before.
142 Double-clicking the file does not only result in a PDF file, but
143 also produces a @file{.log} file that contains some information on
144 what LilyPond has done to the file. If any errors occur, please
149 @subsection Command-line
151 Create a text file called @file{test.ly} and enter:
159 To process @file{test.ly}, proceed as follows:
166 You will see something resembling:
170 GNU LilyPond @version{}
173 Interpreting music...
174 Preprocessing graphical objects...
175 Finding the ideal number of pages...
176 Fitting music on 1 page...
178 Layout output to `test.ps'...
179 Converting to `test.pdf'...
184 @node Alternate editors
185 @section Alternate editors
189 @node How to write input files
190 @section How to write input files
194 * Working on input files::
198 @node Simple notation
199 @subsection Simple notation
201 @cindex simple notation
202 @cindex notation, simple
204 LilyPond will add some notation elements automatically. In the
205 next example, we have only specified four pitches, but LilyPond
206 has added a clef, time signature, and rhythms.
208 @lilypond[verbatim,quote]
215 This behavior may be altered, but in most cases these automatic
222 @cindex relative mode
223 @cindex quote, single
225 @cindex accidentals and relative mode
226 @cindex relative mode, and accidentals
233 Music Glossary: @rglos{pitch}, @rglos{interval},
234 @rglos{scale}, @rglos{middle C}, @rglos{octave},
237 The easiest way to enter notes is by using @code{\relative} mode.
238 In this mode, the octave is chosen automatically by assuming the
239 following note is always to be placed closest to the previous
240 note, i.e., it is to be placed in the octave which is within three
241 staff spaces of the previous note. We begin by entering the most
242 elementary piece of music, a @notation{scale}, in which every note
243 is within just one staff space of the previous note.
245 @lilypond[verbatim,quote]
246 % set the starting point to middle C
253 The initial note is @notation{middle C}. Each successive note is
254 placed closest to the previous note -- in other words, the first
255 @code{c} is the closest C to middle C. This is followed by the
256 closest D to the previous note. We can create melodies which have
257 larger intervals, still using only @code{\relative} mode:
259 @lilypond[verbatim,quote]
267 It is not necessary for the first note of the melody to start on
268 the note which specifies the starting pitch. In the previous
269 example, the first note -- the @code{d} -- is the closest D to
272 By adding (or removing) quotes @code{'} or commas @code{,} from
273 the @code{@w{\relative c' @{}} command, we can change the starting
276 @lilypond[verbatim,quote]
277 % one octave above middle C
283 Relative mode can be confusing initially, but is the easiest way
284 to enter most melodies. Let us see how this relative calculation
285 works in practice. Starting from a B, which is on the middle line
286 in a treble clef, you can reach a C, D and E within 3 staff spaces
287 going up, and an A, G and F within 3 staff spaces going down. So
288 if the note following a B is a C, D or E it will be assumed to be
289 above the B, and an A, G or F will be assumed to be below.
291 @lilypond[verbatim,quote]
293 b c % c is 1 staff space up, so is the c above
294 b d % d is 2 up or 5 down, so is the d above
295 b e % e is 3 up or 4 down, so is the e above
296 b a % a is 6 up or 1 down, so is the a below
297 b g % g is 5 up or 2 down, so is the g below
298 b f % f is 4 up or 3 down, so is the f below
302 Exactly the same happens even when any of these notes are
303 sharpened or flattened. @notation{Accidentals} are
304 @strong{totally ignored} in the calculation of relative position.
305 Precisely the same staff space counting is done from a note at any
306 other position on the staff.
308 To add intervals that are larger than three staff spaces, we can
309 raise the @notation{octave} by adding a single quote @code{'} (or
310 apostrophe) to the note name. We can lower the octave by adding a
311 comma @code{,} to the note name.
313 @lilypond[verbatim,quote]
321 To change a note by two (or more!) octaves, we use multiple
322 @code{''} or @code{,,} -- but be careful that you use two single
323 quotes @code{''} and not one double quote @code{"}@tie{}! The
324 initial value in @code{@w{\relative c'}} may also be modified like
326 @c " - keeps quotes in order for context-sensitive editor -td
328 @subheading Durations (rhythms)
330 @cindex note durations
337 @cindex notating durations
339 Music Glossary: @rglos{beam}, @rglos{duration},
340 @rglos{whole note}, @rglos{half note}, @rglos{quarter note},
343 The @notation{duration} of a note is specified by a number after
344 the note name: @code{1} for a @notation{whole note}, @code{2} for
345 a @notation{half note}, @code{4} for a @notation{quarter note} and
346 so on. @notation{Beams} are added automatically.
348 If you do not specify a duration, the previous duration is used
349 for the next note. The duration of the first note defaults to a
352 @lilypond[verbatim,quote]
356 a16 a a a a32 a a a a64 a a a a a a a a2
360 To create @notation{dotted notes}, add a dot @code{.} to the
361 duration number. The duration of a dotted note must be stated
362 explicitly (i.e., with a number).
364 @lilypond[verbatim,quote]
375 @cindex notating rests
377 Music Glossary: @rglos{rest}.
379 A @notation{rest} is entered just like a note with the name
382 @lilypond[verbatim,quote]
390 @subheading Time signature
392 @cindex time signature
397 Music Glossary: @rglos{time signature}.
399 The @notation{time signature} can be set with the @code{\time}
402 @lilypond[verbatim,quote]
425 Music Glossary: @rglos{clef}.
427 The @notation{clef} can be set using the @code{\clef} command:
429 @lilypond[verbatim,quote]
443 @subheading All together
445 Here is a small example showing all these elements together:
447 @lilypond[verbatim,quote]
458 Notation Reference: @ruser{Writing pitches},
459 @ruser{Writing rhythms}, @ruser{Writing rests},
460 @ruser{Time signature}, @ruser{Clef}.
463 @node Working on input files
464 @subsection Working on input files
467 @cindex braces, curly
470 @cindex comment, line
471 @cindex block comment
472 @cindex comment, line
473 @cindex case sensitive
474 @cindex whitespace insensitive
479 @funindex %@{ ... %@}
481 LilyPond input files are similar to source files in many common
482 programming languages. They are case sensitive, and white-space
483 is generally ignored. Expressions are formed with curly braces
484 @{ @}, and comments are denoted with @code{%} or
485 @w{@code{%@{ ... %@}}}.
487 If the previous sentences sound like nonsense, don't worry! We'll
488 explain what all these terms mean:
493 @strong{Case sensitive}:
494 it matters whether you enter a letter in lower case (e.g.
495 @w{@code{a, b, s, t}}) or upper case (e.g. @w{@code{A, B, S, T}}).
496 Notes are lower case: @w{@code{@{ c d e @}}} is valid input;
497 @w{@code{@{ C D E @}}} will produce an error message.
500 @strong{Whitespace insensitive}:
501 it does not matter how many spaces (or tabs or new lines) you add.
502 @w{@code{@{ c d e @}}} means the same thing as
503 @w{@code{@{ c @tie{}} @tie{} @tie{} d e @}} and:
511 Of course, the previous example is hard to read. A good rule of
512 thumb is to indent code blocks with either a tab or two spaces:
520 However, whitespace @emph{is} required to separate many syntactical
521 elements from others. In other words, whitespace can always be
522 @emph{added}, but it cannot be @emph{eliminated}. As missing
523 whitespace can give rise to strange errors it is advisable to
524 always insert whitespace before and after every syntactic element,
525 for example, before and after every curly brace.
528 @strong{Expressions}:
529 every piece of LilyPond input needs to have @strong{@{ curly
530 braces @}} placed around the input. These braces tell LilyPond
531 that the input is a single music expression, just like parentheses
532 @code{()} in mathematics. The braces should be surrounded by a
533 space unless they are at the beginning or end of a line to avoid
536 A LilyPond command followed by a simple expression in braces (such
537 as @w{@code{\relative @{ @}}}) also counts as a single music
542 @cindex block comment
545 a comment is a remark for the human reader of the music input; it
546 is ignored while parsing, so it has no effect on the printed
547 output. There are two types of comments. The percent symbol
548 @code{%} introduces a line comment; anything after @code{%} on
549 that line is ignored. By convention, a line comment is placed
550 @emph{above} the code it refers to.
554 % this comment refers to the Bs
558 A block comment marks a whole section of music input as a comment.
559 Anything that is enclosed in @code{%@{} and @code{%@}} is ignored.
560 However, block comments do not @q{nest}. This means that you
561 cannot place a block comment inside another block comment. If you
562 try, the first @code{%@}} will terminate @emph{both} block
563 comments. The following fragment shows possible uses for
567 % notes for twinkle twinkle follow
571 This line, and the notes below are ignored,
572 since they are in a block comment.
581 @node How to read the manuals
582 @section How to read the manuals
584 @cindex how to read the manual
585 @cindex manual, reading
586 @cindex reading the manual
587 @cindex examples, clickable
588 @cindex clickable examples
589 @cindex tips for constructing files
591 @cindex constructing files, tips
592 @cindex files, tips for constructing
594 LilyPond input must be surrounded by @{ @} marks or a
595 @code{@w{\relative c'' @{ ... @}}}, as we saw in @ref{Working on
596 input files}. For the rest of this manual, most examples will
597 omit this. To replicate the examples, you may copy and paste the
598 displayed input, but you @strong{must} add the
599 @code{@w{\relative c'' @{ @}}} like this:
603 ... example goes here...
607 Why omit the braces? Most examples in this manual can be inserted
608 into the middle of a longer piece of music. For these examples,
609 it does not make sense to add @code{@w{\relative c'' @{ @}}} --
610 you should not place a @code{\relative} inside another
611 @code{\relative}! If we included @code{@w{\relative c'' @{ @}}}
612 around every example, you would not be able to copy a small
613 documentation example and paste it inside a longer piece of your
614 own. Most people want to add material to an existing piece, so we
615 format the manual this way.
618 @subheading Clickable examples
620 Many people learn programs by trying and fiddling around with the
621 program. This is also possible with LilyPond. If you click on a
622 picture in the HTML version of this manual, you will see the exact
623 LilyPond input that was used to generate that image. Try it on
629 c-\markup { \bold \huge { Click here. } }
633 By cutting and pasting everything in the @qq{ly snippet} section,
634 you have a starting template for experiments. To see exactly the
635 same output (line-width and all), copy everything from @qq{Start
636 cut-&-pastable section} to the bottom of the file.
640 There are more tips for constructing input files in
641 @ref{Suggestions for writing LilyPond input files}. But it might be
642 best to read through the rest of the tutorial first.