4

I'm including a short except in a LaTeX document using lilypond-book, but you can see how bad the vertical spacing is. How do I fix this?

Problematic music

As a background, lilypond-book is a preprocessor for latex, which reads any \lilypondfile{...} or \lilypond{...} blocks, typesets those into music (one pdf/eps for each line/system), and then generates a *.tex file which replaces the \lilypondfile{} command with some commands that will include each file. Usage is something like this:

\documentclass{book}

\begin{document}
Some text

\lilypondfile{short-excerpt.ly}

More text
\end{document}
0

1 Answer 1

3

lilypond-book generates each line/system as an independent PDF. Those PDFs contain no padding, and so if you have no dynamics, staff-text or ledger lines, the staffs can get crammed together like this.

single system with bounding box

Vertical space needs to be manually added between the staffs. But you don't want to manually edit lilypond-book's auto-generated *.tex because that change will get overwritten next time you run lilypond-book.

Instead, define \betweenLilyPondSystem. This macro is used in the generated *.tex between each system, and the first argument (#1) describes the number of systems that came before it.

In the question above, we need extra space after the first two lines, so we can use \ifnum#1<3 ... \fi to add something that only applies to the first two gaps:

\def\betweenLilyPondSystem#1{
  \ifnum#1<3\vspace{\baselineskip}\fi
  \newline
}

Don't forget to reset the macro, so it doesn't affect anything you may include later:

\let\betweenLilyPondSystem\undefined

The full solution therefore looks like this:

\documentclass{book}

\begin{document}
Some text

\def\betweenLilyPondSystem#1{\newline\ifnum#1<3\vspace{1.5\baselineskip}\fi}
\lilypondfile{short-excerpt.ly}
\let\betweenLilyPondSystem\undefined

More text
\end{document}

And the output looks a lot better. You could play with the gain in-front of \baselineskip to try to make the spacing "even", but I don't think "even-ness" is something we need to strive for.

improved spacing

There's some info about that here:

https://lilypond.org/doc/v2.23/Documentation/usage/latex


A couple of other hints for spacing:

\def\betweenLilyPondSystem#1{\par}

will add a paragraph between each line. Normally, a \pagebreak will cause the space between paragraphs to increase to fill the page, and this will have an effect on this too.

Alternatively, the following will force as much space as needed between systems to fill the page.

\def\betweenLilyPondSystem#1{\vspace{\fill}\newline}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.