I typeset a book containing musical pieces using LaTeX and LilyPond (using lilypond-book
). Each piece starts in a new page, and can be from less than a single page up to several pages long.
I want each piece to fill the required number of pages fully, so no space is left in the bottom part of the last page of the piece and the staves in all pages are evenly spaced. This can be achieved in LilyPond by setting ragged-last-bottom
to ##f
. Here is a simple example (music.ly
):
#(set-global-staff-size 32)
\paper {
paper-width = 18.5\cm
ragged-last-bottom = ##f
}
\header{
tagline = ##f
}
{
c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c
c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c
c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c
c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c
c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c
}
This will produce this output:
Page 1/2:
Page 2/2:
Now, when I try to use this in LaTeX, it doesn’t work, since lilypond-book
splits the LilyPond output into .eps
files each containing a single line and these files are included one after another by the generated .tex
file.
So, this LaTeX file produces an output which does not fill the pages fully with evenly spaced staves (as you can easily see by looking on the last page):
\documentclass[a4paper]{article}
\usepackage{geometry}
\begin{document}
hello world
\lilypondfile{music.ly}
\end{document}
Page 1/3:
Page 2/3:
Page 3/3:
So my question is simple: how do I make LaTeX behave like LilyPond does with ragged-last-bottom
set to ##f
?
Thank you very much! ☺
Best Answer
Interesting problem! Ultimately, lots of figuring out and legwork, but the solution ends up being very simple.
Thanks for introducing me to lillypond—cool stuff.
I'm still a bit confused because I've only been using it for about 5 minutes, but here's what I found.
You make this file, I called mine lillypond.ly:
I took this straight from the your question.
Also straight from the your question is this file, I called mine lillypondtex.lytex (The .lytex extension is important and was difficult to figure out.)
This file gets compiled with the command
Applications/LilyPond.app/Contents/Resources/bin/lilypond-book --output=out --pdf lillypondtex.lytex
at least, if you're on a mac and too lazy to follow the installation instructions. On a normal installation I think this command would be justlilypond-book --output=out --pdf lillypondtex.lytex
.That command generates a new directory, called
out
, which contains a directory called5a
(important later) and the files:Now we're getting somewhere, finally an extension I know and love!
Running
pdflatex
onlillypondtex.tex
gives the same output you saw and didn't like.The
lillypondtex.tex
file contains this:Still a little obfuscated, but the line
\input{5a/lily-66b633c5-systems.tex}
is the key.Now, going into the
5a
directory, we have the file calledlily-66b633c5-systems.tex
which is finally the layout code for the document.These
\linebreak
commands are the problem, that's why LaTeX is treating the music as a single paragraph and not spreading it out evenly.Any changes made here will effect the output of
lillypond.tex
. From here, I'm sure there are more experienced people here who can tweak this further than I can.However, a couple simple solutions:
Simply find-replacing all cases of
\linebreak
with\par
will allow\flushbottom
to be used as expected inlillypond.tex
. output:This fixes spacing between all the lines and text. Making each line of music a paragraph is the solution I would choose if I were writing a book using this, as it would work with
\flushbottom
and flow around text well. Also, at this point, David Carlisle's asnwer of pasting\setlength\parskip{\fill}
into thelillypond.tex
file will work as he intended.Another option is to replace each
\linebreak
with\vfill
, which gets us closer to OP's desired outcome by filling the full last page.From here it's just a matter of shrinking the margins to make them similar to lillypond's output. A margin of .75" top and bottom gives this output:
Even spacing, pages fully filled, I believe this is what you're asking for.
Final
lillypond.tex
file:Another option I just thought of is to use
\pagebreaks
in conjunction with\vfill
to explicitly declare how many lines to show per page.If you want default
Article
margins:How to space out lines so they're evenly distributed with
article
class default margins: Use\par
between the lines of music and then define\parskip
like this:This tells LaTeX that each line must have 26pt in between, and it's allowed to satisfy
\flushbottom
by stretching each line by 36pt but not allowed to compress the lines closer together.Here's the result:
LaTeX breaks it up into two pages of five lines and one page of four lines.
Here's the code I used to make it: