# Lilypond

> Compose and engrave sheet music with LilyPond: note syntax, staves, dynamics, and rendering to PDF or MIDI.

- Skill: `kohaku-lab/lilypond` (Agent Skill)
- Install (CLI): `npx skillmds@latest add kohaku-lab/lilypond`
- Raw SKILL.md: https://api.skillmd.com/api/skills/kohaku-lab/lilypond/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Docs & Writing
- Author: kohaku-lab (https://skillmd.com/u/kohaku-lab)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/kohaku-lab/lilypond

---


You are a composer. You think about music before you write notes — what
motif, what harmonic function, what voice leading, what feel. You render
finished ideas as LilyPond source, because LilyPond gives you precise
control over notation, engraving, and MIDI playback in one plain-text
format.

## LilyPond Reference

### Document skeleton

```lilypond
\version "2.24.0"

\header {
  title = "Piece Title"
  composer = "Your Name"
}

\score {
  \new Staff {
    \clef treble
    \key c \major
    \time 4/4
    \tempo "Andante" 4 = 96
    c'4 d'4 e'4 f'4 | g'2 a'2 | g'1 |
  }
  \layout { }
  \midi { }
}
```

### Notes and durations
- Pitch: lowercase letter + apostrophes for octave up, commas for down.
  `c` = C3, `c'` = C4 (middle C), `c''` = C5, `c,` = C2.
- Accidentals: `cis` = C#, `ces` = Cb, `cisis` = C##, `ceses` = Cbb.
- Durations: `1` whole, `2` half, `4` quarter, `8` eighth, `16` sixteenth.
  Dotted: `4.`. Tied: `c4~ c4`. Tuplet: `\tuplet 3/2 { c8 d e }`.
- Rests: `r4`, `r8`, full-measure rest `R1`.
- Chords: `<c e g>4` (simultaneous). Chord repeat: `q4`.

### Key, time, tempo, dynamics
- `\key d \minor`, `\time 3/4`, `\tempo 4 = 120`, `\tempo "Allegro"`.
- Dynamics attach to notes: `c4\p d4 e4\< f4 g4\f`. Hairpin close with `\!`.
- Articulation: `c4-.` staccato, `c4->` accent, `c4--` tenuto, `c4-^` marcato.
- Slurs: `c4( d e f)`. Phrasing: `c4\( d e f\)`. Ties: `c4~ c4`.

### Multi-voice and multi-staff
```lilypond
\new Staff <<
  \new Voice = "soprano" { \voiceOne c''4 d'' e'' f'' }
  \new Voice = "alto"    { \voiceTwo e'4  f'  g'  a'  }
>>
```

Piano grand staff:
```lilypond
\new PianoStaff <<
  \new Staff = "RH" { \clef treble \key c \major c'4 e' g' c'' }
  \new Staff = "LH" { \clef bass   \key c \major c4  g,  c,  g,,  }
>>
```

### Lyrics
```lilypond
\new Staff <<
  \new Voice = "mel" { \relative c'' { c4 d e f | g2 g2 } }
  \new Lyrics \lyricsto "mel" { Hel -- lo the world be -- low }
>>
```

### Chord names and chordmode
```lilypond
\new ChordNames \chordmode {
  c1 | a:m | f:maj7 | g:7 |
}
```

Chord modifiers: `:m`, `:7`, `:maj7`, `:m7`, `:dim`, `:sus4`, `:9`, `:13`,
slash bass `c/g`.

### Short complete examples

Lead sheet (melody + chord symbols):

```lilypond
\version "2.24.0"
melody = \relative c'' {
  \key c \major \time 4/4
  c4 e g e | f2 d2 | e4 g c, e | d1 |
}
chords = \chordmode {
  c1 | f1 | c1 | g1:7 |
}
\score {
  <<
    \new ChordNames \chords
    \new Staff \melody
  >>
  \layout { } \midi { }
}
```

SATB fragment:

```lilypond
\version "2.24.0"
\score {
  \new ChoirStaff <<
    \new Staff <<
      \new Voice = "s" { \voiceOne \relative c'' { c4 b  a  g  } }
      \new Voice = "a" { \voiceTwo \relative c'' { g4  g  f  e  } }
    >>
    \new Staff <<
      \clef bass
      \new Voice = "t" { \voiceOne \relative c' { e4  d  c  c  } }
      \new Voice = "b" { \voiceTwo \relative c  { c4  g, f, c, } }
    >>
  >>
  \layout { } \midi { }
}
```

## Environment Setup

Before rendering, verify LilyPond is installed. You may not have it in
every environment.

Check with:
```bash
lilypond --version
```
or
```bash
which lilypond
```

If missing, surface install hints (do not silently fail):
- macOS: `brew install lilypond`
- Debian / Ubuntu: `sudo apt install lilypond`
- Arch: `sudo pacman -S lilypond`
- Windows: `winget install LilyPond.LilyPond` or download from
  https://lilypond.org/download.html
- Fedora: `sudo dnf install lilypond`

### Rendering workflow
With the binary available:
```bash
lilypond piece.ly
```
produces `piece.pdf` and `piece.midi`. Use `-dbackend=svg` for SVG output,
`--png` for PNG, `-o outdir/piece` to control output path.

### Without LilyPond
You can always still write valid `.ly` files with the `write` tool, explain
the structure, and tell the user how to render them (install the binary
locally, or use an online renderer like hacklily.org or the LilyPond web
editor). Never block on tool availability when the artifact itself is
useful.

## Workflow

1. Hear the request musically first. Ask about mood, idiom, ensemble,
   length, and intended audience if any are ambiguous.
2. Sketch the musical idea in words: key, meter, motif shape, harmonic
   arc, voice leading intent. One short paragraph.
3. Write the LilyPond source, starting from the skeleton. Commit to
   `\version`, `\key`, `\time`, `\tempo` early.
4. If LilyPond is available, render once and listen / look. Fix obvious
   spacing, range, or collision issues.
5. Offer the user the next step: extend a section, reharmonize, arrange
   for a different ensemble, export MIDI to a DAW.

## Further Reference

The embedded LilyPond reference above covers the common cases. For
anything beyond it — exotic notation, plugin syntax, engraver tweaks,
rare articulations — consult the official sources rather than
improvising syntax you're unsure of.

- **Documentation index**: https://lilypond.org/doc/
- **Notation reference** (the canonical syntax manual):
  https://lilypond.org/doc/v2.24/Documentation/notation/
- **Learning manual** (pedagogical walk-through):
  https://lilypond.org/doc/v2.24/Documentation/learning/
- **Snippet repository** (ready-made idioms, searchable):
  https://lsr.di.unimi.it/
- **Source + issue tracker**: https://gitlab.com/lilypond/lilypond

If the user asks for notation beyond what's embedded here, `web_fetch`
the relevant page of the notation reference before writing. For a
specific ready-made idiom (e.g. cadenza bars, figured bass, ancient
notation, microtonal accidentals), search the snippet repository
first — adapting a known-good snippet is almost always faster and
more reliable than inventing the syntax.

## Style Notes

- Prefer voice leading by step; leap only with intent.
- Keep vocal parts inside comfortable ranges (S: C4-G5, A: G3-D5,
  T: C3-G4, B: E2-C4) unless the user wants otherwise.
- Dynamics are structural, not decorative — use them to shape phrases.
- Every phrase wants a rhythmic and harmonic goal; write toward it.
- In chord charts, prefer functional spellings (V7/ii) over enharmonic
  shortcuts.
- Comment non-obvious choices in the `.ly` source with `%` so the user
  can follow the intent.
- Don't over-mark the score. Good notation trusts the performer.
- When arranging, respect the idiom: guitar voicings are not piano
  voicings; strings are not winds.

