2.1.2 Accidentals and key signatures

Note: New users are often confused by these – please read the warning at the bottom of this page, especially if you are not familiar with music theory!


Music Glossary: sharp, flat, double sharp, double flat, accidental.

A sharp pitch is made by adding is to the name, and a flat pitch by adding es. As you might expect, a double sharp or double flat is made by adding isis or eses. This syntax is derived from note naming conventions in Nordic and Germanic languages, like German and Dutch. To use other names for accidentals, see Note names in other languages.

cis4 ees fisis, aeses

[image of music]

Key signatures

Music Glossary: key signature, major, minor.

The key signature is set with the command \key followed by a pitch and \major or \minor.

\key d \major
a1 |
\key c \minor
a1 |

[image of music]

Warning: key signatures and pitches

Music Glossary: accidental, key signature, pitch, flat, natural, sharp, transposition, Pitch names.

To determine whether to print an accidental, LilyPond examines the pitches and the key signature. The key signature only affects the printed accidentals, not the note’s pitch! This is a feature that often causes confusion to newcomers, so let us explain it in more detail.

LilyPond makes a clear distinction between musical content and layout. The alteration (flat, natural sign or sharp) of a note is part of the pitch, and is therefore musical content. Whether an accidental (a printed flat, natural or sharp sign) is printed in front of the corresponding note is a question of layout. Layout is something that follows rules, so accidentals are printed automatically according to those rules. The pitches in your music are works of art, so they will not be added automatically, and you must enter what you want to hear.

In this example:

\key d \major
cis4 d e fis

[image of music]

No note has a printed accidental, but you must still add is and type cis and fis in the input file.

The code b does not mean “print a black dot just on the middle line of the staff.” Rather, it means “there is a note with pitch B-natural.” In the key of A-flat major, it does get an accidental:

\key aes \major
aes4 c b c

[image of music]

If the above seems confusing, consider this: if you were playing a piano, which key would you hit? If you would press a black key, then you must add -is or -es to the note name!

Adding all alterations explicitly might require a little more effort when typing, but the advantage is that transposing is easier, and accidentals can be printed according to different conventions. For some examples of how accidentals can be printed according to different rules, see Automatic accidentals.

See also

Notation Reference: Note names in other languages, Accidentals, Automatic accidentals, Key signature.

Other languages: česky, deutsch, español, français, magyar, italiano, 日本語, nederlands.
About automatic language selection.

LilyPond — Learning Manual v2.17.97 (development-branch).