Pygments, a syntax highlighter written in Python,
just received support for LilyPond. This means that,
using the latest version of Pygments, you can get
highlighted LilyPond source in LaTeX documents,
Sphinx documentation, Wordpress sites, the output
of various other tools, and any format you like.
(It's also used on Wikipedia, but we'll have to
wait until a release.) To get the latest Pygments,
the short story is

python3 -m pip install --user https://github.com/pygments/pygments/archive/master.zip

The long story is that you should start by installing
Python. On most GNU/Linux systems, it comes out of the
box or in package managers. On macOS or Windows, download
it from https://www.python.org/downloads/. Then, you need
pip to install packages. If you don't have pip yet, do
'sudo apt install python3-pip' on Debian/Ubuntu, or
'python3 -m ensurepip --user' pretty much anywhere. Finally,
run the command above to let pip install Pygments.

Importantly, you must use the 'lilypond' style. Other styles
(such as the default one) will not produce good-looking
output because they don't know about LilyPond's concepts
(grobs, engravers, etc.).

To use with Sphinx, add to your conf.py:

highlight_language = "lilypond"
pygments_style = "lilypond"


Here is an example of how to use it in LaTeX with the
minted package:


\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{minted}
\usemintedstyle{lilypond}

\begin{document}

\begin{minted}{lilypond}
\version "2.23.4"

\header {
  title = \markup \bold "Yes!"
}

\relative { c' }
\addlyrics { Oh! }
\end{minted}
\end{document}


Please report any issues at
https://github.com/pygments/pygments/issues
and mention me (@Jean-Abou-Samra).

Thanks go to Matthaüs G. Chajdas, one of the two Pygments
maintainers, for reviewing the code, and to Dan Eble and
Jonas Hahnfeld for their feedback.

Reply via email to