# LilyPond Quick Guide

## Introduction

LilyPond is a powerful and versatile typesetting program for musical scores. Authors prepare a source file, with suffix .ly, and run the lilypond executable to create a musical score in both .pdf and .ps formats.
LilyPond is available at http://lilypond.org/web/. The documentation can be found at http://lilypond.org/doc/v2.12/Documentation/; good luck with that.
The documentation is voluminous, but difficult to penetrate. I found it difficult to find out about such simple features as the overall structure of a LilyPond source file. Many commands and features are described without any context whatsoever, and it becomes a matter of trial and error to determine exactly how they should be integrated into a source file. And some features that one would expect to be quite simple, seem to be achievable only by complex and obscure "commands" or "variables". One is frequently tempted to attach multiple features to a single note (e.g. sharp/flat, duration, pitch, slur start or end, phrase start or end, dynamic mark, crescendo/decrescendo start or end and text are a few examples!), and it typically requires trial and error to determine which of the particular orders is the only one that LilyPond accepts. LilyPond source files appear to be written in a custom programming language whose grammar is never discussed.
In spite of these difficulties, LilyPond is astoundingly powerful, and produces very beautiful output. It's therefore worth the trouble to get to know it. This document summarizes the techniques which were for me the essentials for creating simple musical scores using LilyPond.

## Running LilyPond

Running LilyPond is quite simple. First create the source file, with suffix .ly, using a text editor. Then, in a command window, run the following:
"c:\Program Files\LilyPond\usr\bin\lilypond.exe" source.ly
You may of course need to modify the path to the executable, depending on how you installed LilyPond. You might like to make a batch file that runs the command on an arbitrary file.
Assuming that your lilypond source file compiles properly, the result will be two files, source.pdf and source.ps, which you can then open using whatever viewer is appropriate.

## Program Structure

This produces a main title centered, and a sequences of sections. The music in each section is defined in a \score.
#(set-default-paper-size "letter") \version "2.10.33" \header{ title = "Main Title" composer="The Composer" } \include "english.ly" \layout { indent = 0.0\cm } \markup { Subsection 1 } \score { ... } \markup { Subsection 2 } \score { ... } \markup { Subsection 3 } \score { ... }
The title is displayed centered at the top of the page, with the composer below it to the right. The include of english.ly allows us to use English names for sharps and flats ("s" and "f"), instead of the default Dutch names ("is" and "es"). The layout instruction tells Lilypond to not indent the first line of each score in a very annoying fashion. The markup texts are left justified on the page.

## The Score

The score defines a section of music.
\score { \relative c' { \clef treble \time 3/4 \key c \major c d e f g a b c d e f g } }
The \relative command specifies the pitch of the initial note (within a 4th): see the next section.
The \clef command defines the clef (naturally), with "treble" and "base" being the most common values. Treble is assumed if no \clef command is provided.
The \time command defines the time signature: 3/4, 4/4, 3/2, 6/8, etc.
The \key command defines the key signature: \c major, \a minor, etc.
The clef, time and key commands can appear in the middle of a section if it is needed to change any of these values.
\score { \relative c' { \clef treble \time 4/4 \key c \major c c c c \clef bass \time 3/4 \key d \major c c c \clef treble \time 5/4 \key 3 \major c c c c c } }

## Notes

Notes are defined using letter notation a, b, c, d, e, f, g. The actual pitch of the first note is defined via the \relative command; the first note will be within a fourth up or down from the relative note.
\relative c' = middle C
\relative d' = D above middle C
\relative c'' = C above middle C
\relative c''' = second C above middle C
Rests are indicated by the letter 'r'.
\score { \relative a' { \time 4/4 \key f \minor a b c d e d c b r b c d } }
Note that the note "a" is interpreted as A natural, even though the key signature has been specified as F minor, in which A would normally be flat.
Notes are separated by spaces. Lines can be broken anywhere.

## Sharps and Flats

All sharps and flat MUST be indicated, even if they are implied by the key signature.
If english.ly is included, sharps are indicated by appending "s" to the note name, and flats are indicated by appending "f". Without english.ly included, Dutch seems to be the default, and the appends are the rather foreign looking "is" and "es".
The flat or sharp won't be printed, if it is implied by the key signature. On the other hand, if you forget an "s" or "f" that is in the key signature, then LilyPond will print a natural for you, as seen in the previous example.
For example, the D minor scale:
\score { \relative a' { \time 4/4 \key d \minor d e f g a bf cs d } }
Note how the B-flat (written "bf") appears without an accidental, since the flat is implied by the key signature.

## Note pitches

When writing a sequence of notes, the pitch of each note is interpreted relative to the preceding note. If the note is within a fourth of the preceding note, no special notation is required. If the note is more than a fourth above the preceding note, append an apostrophe ('). If the note is more than a fourth below the preceding note, append a comma (,).
\score { \relative c'' { \time 6/8 \key g \major c d c e c f c g' c, a' c, b' c, a' c, g' c, f c e c b c c } }
The pitch indicator follows the sharp or flat indicator.

## Note durations

Note durations are indicated by appending a numerical value after the note, AFTER the pitch shift indicator (apostrophe or comma) if there is one.
1 = whole note
2 = half note
4 = quarter note
8 = eighth note
16 = sixteenth note
etc.
For example, here's four bars in 4/4 time:
\score { \relative c'' { \time 4/4 \key g \major c4 d4 e4 fs8 g8 a2 c,4 f,4 f4 g8 f16 e16 d1 } }
It's possible to omit the duration if the note is the same duration as the preceding note. For example:
\score { \relative c'' { \time 4/4 \key g \major c4 c d d e8 f e d c4 c } }
However, it's easy to make a mistake this way!
For dotted notes, append a period '.':
\score { \relative c'' { \time 4/4 \key g \major c4 c4 c8. c16 c4 d4. d8 d2 } }
The duration indicator follows the pitch indicator:
fs,4