I sent this to the lilypond-devel list, because I'm about 90% sure it's a
bug in LilyPond, not a mistake on my part. I've been wrong many times
before, so I'm leaving myself 10% 🙂

I'm posting this to the user list hoping to get some fresh eyes on it.

I have a large collection of lead sheets in LilyPond I've been working on
for several years. I believe I may have stumbled upon a strange bug. I had
been engraving these individually and assembling PDFs using LaTeX, but the
resulting files were huge because each separate PDF has its own separate
copy of its fonts. Combining PDFs this way doesn't offer any way to combine
fonts. I finally broke down and figured out how to compile these books
entirely within LilyPond, so the largest native-buit PDF is now about 10%
of the size of the assembled PDF.

Anyway, in the process of building these books I encountered a strange
problem. There is a particular song that causes the engraving to either go
past the right edge and bottom edge of the page, or shrink both margins so
that it uses a smaller part of the page. This condition persists in the
book until it engraves a different particular song that sets it back to the
correct size. I use a somewhat complicated system of include files to
enable these songs to be typeset in different keys. There is one key for
the "wrong size" song that makes it get too large. All the other keys that
I've tried make it get too small. The song is written in D, but if I
transpose it to C it spills over the limits of the page. If I keep it in D
or transpose to some other key it shrinks to a smaller portion of the page.
This new page size stays until the "right size" song gets engraved, then
the rest of the book uses the correct size.

Unfortunately, it isn't easy for me to isolate this to a simple example. My
project has gotten quite large and I have a somewhat complicated system of
\include files that I use to enable transpositions and to keep the layout
separate from the core music description. Fortunately a two- or three-song
book is enough to illustrate the problem. I keep my source code in a public
repository on GitHub, so it wouldn't be too hard for a LilyPond maintainer
to set up the environment. I have some shell scripts and Python scripts
that I use, but I believe I have created a test case that would work with
this GitHub repository using only LilyPond itself.

I would be happy to find a workaround to avoid this problem, but I would
also like to do what I can to fix a bug that, although perhaps rare, is
something I'm sure you would like to see fixed.

My GitHub repository is

https://github.com/neonscribe/lilypond-lead-sheets

I put some files in GitHub to show the problem. In this folder:

https://github.com/neonscribe/lilypond-lead-sheets/tree/main/TeX

there are four files, AV.ly, AV.pdf, AVX.ly and AVX.pdf. The AV files show
the layout spilling past the edges, while the AVX files show the layout
shrinking.

A couple of days have passed since I composed this message, and I've done
some more research. I've tried a lot of different sequences of files.
Remember, if I compile any of these individually the margins and page
layout are correct. However, if I create a book with a sequence of files,
they almost always start out wth the page shrunk and the right and bottom
margins too large. That shrunken page layout continues in the book until it
hits one of the songs that somehow resets it to normal, then all the songs
from there to the end will have normal margins. If I put one of those
"normal size" songs at the beginning of the book then the whole book will
have normal margins. Except there's this one file in one key that always
pushes the margins over the limits of the page and cuts off the right side
of the score. If LilyPond hits that magic file in a sequence, then every
file after that one will have the same too-large margins, until it
encounters one of the "normal size" files, which resets the margins
correctly for the rest of the book.

Am I correct in thinking this is probably a bug in LilyPond? I don't think
there's anything I'm doing that would change the size of the page, and it
certainly doesn't seem right that changing the order of songs in a book
would cause them to have different margins. I was using 2.26.0, but I tried
it in 2.27.1 and observed exactly the same behavior.

Reply via email to