Creating Songbooks with LilyPond and LaTeX

Some time ago Jeremy Boor asked on the lilypond-user mailing list for help with integrating complete LilyPond scores in a LaTeX document. It turned out that lilypond-book, which Jeremy tried to use, wasn’t exactly the right solution for this task – the answer was to use \includepdf from LaTeX pdfpages package.

In the excellent Open Source spirit Jeremy decided to write a tutorial explaining how to achieve what he wanted, which is now included in our series of tutorials.

We will be extremely happy if it would become a common practice to write a tutorial or a documentation section explaining how to solve a problem “in return” for community help in finding such a solution 🙂

Download PDF

16 thoughts on “Creating Songbooks with LilyPond and LaTeX

  1. Rachael

    Thank you for sharing this! It is a great little document. There are a couple of typos:
    pg.5 first bullet of 1.1 Preparing your LilyPond Scores should read: “and the resulting PDFs must be in hand”
    Same section next sentence: “scores in the same directory as our”.

    To me the second sentence of section 1.2 should use the actual syntax that you would use in the preamble: \usepackage{pdfpages}

    Thank you Jeremy. And Thank you Janek.

    1. Janek Warchoł

      You’re welcome, Rachael! And actually, it’s Urs who should receive more credit for this one, since it was he who guided the tutorial from conception to publication here 🙂

  2. Holland Hopson

    Thanks for this tutorial! It was exactly what I was looking for and showed up at just the right time. I had started reading about the lilypond-book script thinking it might be the best way for me, but this tutorial matches my needs exactly.

  3. Carl Peterson

    Excellent tutorial, and it gives me a possible angle on my work. So, a couple of follow-ups on this.

    What about a songbook/hymnal where we allow a song to wrap pages on a spread Two cases:
    1) A song taking up 1.5 pages paired with a song taking up 0.5 pages, on the same spread. In this case, except for the extra space at the bottom of each song, the two songs are paginated correctly by LP.
    2) Three songs that together take up 2 pages, but are each individually less than one page. This would result in LP outputting each song as 1 page and we would need to manually break the songs.

    Then there is the matter of song numbering. Since LP is generating titles and we’re generating independent documents, there would be no way to number the songs sequentially, correct? So if we wanted that, would we not use titles in the LP document and instead put the titles in the TEX document?

    Would these be situations where LP-book is a better option? Or is there another approach? I suppose my default is to output a multi-score LP document and compile it, but this seems less than ideal if I want to include text, etc. I’m also trying to figure out a way to allow page breaks within scores across a spread but not between spreads.


    1. Urs Liska

      Quite a few questions/ideas at once, Carl. Nevertheless a few thoughts.
      If you have a spread as a unit I think it actually is a quite natural approach to compile one two-page LilyPond file with the appropriate number of scores in it.

      Apart from lilypond-book you could consider using musicexamples which might be of help.
      With it you can include single-system, multi-system and full-page scores in LaTeX documents. It is quite similar to lilypond-book except for the fact that it does not included the source in the LaTeX document and therefore can be compiled directly without an intermediate file.
      For a case like yours you could either use the scores split up to individual systems (that LaTeX can wrap around page breaks) or create the partial scores as entities to use on the different pages.

      Development is far from finished. What is missing (i.e. aimed at) is a mechanism to auto-generate the LilyPond scores on demand (like lilypond-book does. And I hope to someday implement a way to manage LilyPond source code from the LaTeX file with the help of Lua. This would combine the advantage of storing examples in the main document and not having to use intermediate files.

  4. Mark D. Blackwell

    > We will be extremely happy if it would become a common practice
    > to write a tutorial or a documentation section explaining how to solve a problem
    > “in return” for community help in finding such a solution

    This is a truly wonderful and helpful idea!

    A quick search on lilypond-user (for keywords: tutorial, deal, exchange, bargain) didn’t turn up (for me) any discussion of this idea.

    IHMO, acceptance in principle of such offers (writing a tutorial on a problem solution, in exchange for community help to solve that problem) would be useful in several ways (with several levels of tutorial)—if such problems were focused and vetted:

    1. Expanding LilyPond’s documentation aimed at newbies;

    2. Improving solution findability, where the solution is documented, yet not easily findable by new users (perhaps true in a few cases); and

    3. Programming where yet there is no easy solution for the user’s request, thus some Bison, Guile, etc., programming would be required to make the user’s task easy. For instance, converting Guile calls to LilyPond calls, like \doMyThing.

  5. Anonymous

    When I click on “Download PDF” it just takes me to a blank page with the message “404 not found”. What happened? Am I doing something wrong here?

    1. Urs Liska

      Thank you for reporting. This was due to moving to a new server. It should be fixed now.

      1. Peter Hiltz

        I can’t see the example latex code in the downloaded pdf. E.g. In Section 1.1 where it says “This is done in the block:” I just see a blank line then it starts Section 1.2. …. and so on down the page. Unfortunately, without those code examples, I don’t understand.

        1. Urs Liska

          I saw this comment only now due to vacations. Obviously the monospace font wasn’t compiled into the document. I’ve uploaded a new version of the file which should now be correct.

  6. Michales Michaloudes

    Great info, some addition.

    You write:
    ‘By default, \section and \chapter are numbered, both in their titles and in their TOC entries. \addcontentsline entries are not numbered. To turn off numbering for all TOC entries for the sake of uniformity, include this line the body of your LATEX document:

    To have correct numbering, you have to add \protect command.
    \addcontentsline{toc}{section}{\protect\numberline{\thesection}Your Song}
    ^ notice \protect…. but it adds the previous numbering, so here is the correction



    I had problems with lilypond-book. When I include .ly files I can’t control the page layout. Shame 🙁

    But your solution seems ok.

  7. Ti Crossman

    I am intending to use Lilypond and LaTeX to make a Celtic tunebook. Such tunebooks usually have several short tunes on a single page. Sometimes they have text between tunes. The Lilypond-LaTeX solution you describe here in the tutorial (VERY nice BTW) seems perfect for me, except for one thing: you mention that, when using \includepdf, each pdf will start on its own page. That is rather a deal-breaker for me. Tunes are usually 2-5 staves long, not consuming anywhere near a whole page, and several are usually set on one page.

    So, is there a way in pdfpages to turn off the page break that you say happens with \includepdf?

    1. Urs Liska

      Well, there might be a solution with \includepdf, but it’s primary purpose is to include pages

      So you’d be better off by simply including your scores as images, using \includegraphics. However, it might also be worth checking out my musicexamples package (manual). It is not mature yet, but it offers some functions that may be of interest to you. Plus: I’ve always been willing to continue development, so any opportunity might be the incentive to do so …

  8. Pingback: Latex and Lilypond Hymnal Volume Two | Mad haPPy

Comments are closed.