Music Engraving with Lilypond
This article concerns the
macOS
app.
See other variants:
Windows

Lilypond is a system for music engraving . It was originally developed as part of TeX, but it has long been split to a separate project . It can nevertheless be integrated with a TeX document using the lilypond-book tool. An example is shown below, and this article describes how to typeset it with Texifier.

docs/apps/typesetting/examples/music-lilypond-pdf-only_macos.png

This is generated using a the following LaTeX source,

An example of lilypond-book usage within LaTeX
\documentclass{article}

\begin{document}

\section*{Typesetting Lilypond from within Texifier}

\begin{lilypond}[quote,fragment,staffsize=26]
	\clef treble
	\time 2/4
	\key c \minor
	r8 g'8 g'8 g'8 ees'2\fermata
\end{lilypond}

\end{document}

You can download this using the button above the example, or if you have Texifier installed, click on the button above the example to open it directly in the app.

Installing lilypond-book on macOS

lilypond-book is not generally distributed as part of a TeX distribution and most likely you will need to install it. On macOS this can be done most easily with brew by running brew install lilypond on the command line.

Creating a lilypond-book Custom Build Script

As lilypond-book is not by default part of a TeX distributions, the support for it is not built into Texifier. You can however run the typeset from within Texifier by using a Custom Build Script apps/typesetting/typesetters/external/custom-typesetting .

A simple example for lilypond is shown below.

An example Custom Build Script for lilypond-book
#!/bin/bash

 # A Texifier build script to run lilypond-book and generate a pdf

BareName="$(basename $TEXPAD_ROOTFILE_NO_EXT)"

mkdir -p "$TEXPAD_TEMPDIR"
lilypond-book "$TEXPAD_ROOTFILE" --output "$TEXPAD_TEMPDIR/$BareName.lytex" || {
    exit 1
}
cd "$TEXPAD_TEMPDIR/$BareName.lytex" || {
    echo "fatal: lilypond-book did not generate the output in the expected location"
    exit 1
}
latex "$BareName.tex"
dvips "$BareName.dvi"
ps2pdf "$BareName.ps" || {
    echo "fatal: ghostscript step failed"
    exit 1
}
mv "$BareName.pdf" ../..

This is intended as a starting point for simple documents. It is possible that you require further features such as indices, bibliographies, etc that it does not cover and you should extend it for them.

To install the build script please follow the instructions here apps/typesetting/typesetters/external/custom-typesetting#4-local-and-global-scripts . We suggest that you download this script using the button and install it as a Global Build Script. After rebooting Texifier you will be able to use it for any document on your computer.

docs/apps/typesetting/examples/music-lilypond_macos.png