Lilypond - Latex PDF
Lilypond - Latex PDF
Joe McCool
Southern Regional College, Ireland
mccoolj (at) src dot ac dot uk
http://benburb.demon.co.uk/apache2-default/joe.html
Abstract
The author is an active Irish traditional musician. He is also a keen inland boater.
He is having a lot of fun composing a book on “Traditional Music for Boaters”.
In this paper he describes his successes and frustrations using Lilypond,
Lilypond-book, LATEX and ABC musical notation. Lilypond and LATEX have a lot
in common. Neither are WYSIWYG, neither demand GUI’s. Both compile simple
flat files to produce beautiful graphical output.
Lilypond’s original manifestations produced output directly for LATEX, but of
late users writing books have been encouraged to use Lilypond-book. This looks
for Lilypond code within LATEX source files and produces graphics and associated
instructions which can then be processed by LATEX.
Most joy has come from automating these processes via GNU/Linux and Perl.
376 TUGboat, Volume 29 (2008), No. 3 — Proceedings of the 2008 Annual Meeting
A newbie’s experiences with Lilypond, Lilypond-book, LATEX and Perl
will do the job, use a horse!” 10 though midi support is regrettably not good in Lilypond.
TUGboat, Volume 29 (2008), No. 3 — Proceedings of the 2008 Annual Meeting 377
Joe McCool
378 TUGboat, Volume 29 (2008), No. 3 — Proceedings of the 2008 Annual Meeting
A newbie’s experiences with Lilypond, Lilypond-book, LATEX and Perl
If LATEX can fit the snippet into a page in its but lilypond-book complained about not being able
entirety it uses the whole graphic, otherwise it uses to find files. It is just not that clever. It is not able
individual lines, placing some of the lines on the fol- to process my \newcommand.
lowing page. This breaks my first requirement: pages
should contain only an integer number of snippets. 6 Source collections
Ironically the largest collections of traditional music
4 Overcoming the first limitation from all over the world are held in ABC files and there
My first approach to this problem was to wrap the are quite a few search engines tuned specifically for
snippet in a Figure environment: searching ABC sites.12 There is also a Python script
\begin{figure} available that converts ABC to Lilypond (abc2ly).
.... Again, possibly because of the lack of ABC stan-
lilypond code dards, abc2ly does not produce very tidy code and
.... sometimes gets the repeats plain wrong. It is often
\end{figure} brought to its knees by idiosyncratic ABC.
An integer number of tunes then appeared on a
7 And then there was Perl
page, but I found that the positioning of the graphics
was inconsistent, particularly at the end of chapters. Perl is ideal for processing text. Both LATEX and
Google reported that lots of people had suffered from Lilypond are text based, so the marriage is obvi-
this same problem, but I could find no solutions. ous. My collecting of ABC files and their subsequent
Indeed the suggestion was that I abandon LATEX placement in my book is now almost completely au-
altogether and use only lilypond and a particular tomatic:
stylesheet.11 • ABC file arrives in target folder (often via email)
I also tried using the standard utility grep to • A Perl daemon:
find a relation between my LATEX file, the Lilypond
1. makes a backup
file and the lilypond-book -generated eps files. I in-
tended then to use conventional \includegraphics 2. cleans up ABC code
commands to position the graphics manually. This 3. creates an index entry
proved too cumbersome. 4. merges text to precede or follow this item
My final code ended up as: 5. runs abc2ly
\noindent 6. adds name of lily file to compilation list
\begin{minipage}{\columnwidth} • a make invocation puts together book version
\index{mytune:reels}
\lilypondfile{mytune.ly}\\\\ I think of this process as resembling a trout: the
\include{mytune.tex} Perl daemon watches for an ABC file arriving as a
\end{minipage} result of an Internet search — just as a trout watches
Here mytune.tex contains notes pertaining to for minnows! It is not perfect, but I have good error
this particular piece. Wrapped within the minipage, reporting in place and mistakes are easily fixed by
it was guaranteed to appear on the same page. It hand.
might also contain footnotes. When sufficient new tunes have been added to
This example also shows that if the Lilypond the repository, another Perl script employs lilypond-
script is long, it can be stored in a file and referred to book, latex, dvips and ps2pdf to produce the final
with \lilypondfile; lilypond-book then processes copy.
its argument. 8 Subversion
5 Clever includes Small changes are made to this project daily and
Ideally I would have liked code such as: sometimes the editing is done using machines on
different sites. A small change can have a disastrous
\newcommand{\lily}[1]{ effect on the end product. For this reason the whole
\lilypondfile{#1}{#1}}
project is controlled using the Subversion 13 version
.....
\lily{lilys/my.tune.ly}
control system.
TUGboat, Volume 29 (2008), No. 3 — Proceedings of the 2008 Annual Meeting 379