This guide explains how to generate music notation using LilyPond, export it as SVG, and display it in an HTML file.
Install Lilypond using a package manager.
MacOS:
brew install lilypond
Create a new file called notation.ly
and add the following content:
\version "2.24.0"
\relative c' {
\key c \major
\time 4/4
c d e f | g a b c
}
Run the following command in your terminal to generate an SVG file:
lilypond --svg notation.ly
Create a pdf by passing --pdf
instead.
This will output a file called notation.svg
in the same directory.
Create an index.html
file and include the SVG:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Music Notation</title>
</head>
<body>
<h1>LilyPond Notation</h1>
<img src="notation.svg" alt="Generated Music Notation">
</body>
</html>
To view the file in a browser without CORS issues, start a simple local server:
python3 -m http.server 8000
Then, open http://localhost:8000/index.html
in your browser.