I am working on a document that has a large number of external Lilypond files included. These render quite well and (while a bit of a pain to use) lilypond-book is smart enough to render the music systems at the available width of the host document and add line breaks (and potentially page breaks) between systems.

I can even override the function Lilypond uses between systems to tell latex that I really-really don't want page breaks inside individual scores if it can help it:


This works great for keeping short scores together on a page, but there are a few cases where this is simply not possible. Some scores are simply too long and must span two or more pages. In these cases it much easier on musicians if the score starts on an even (left) page and runs over onto an odd (right) page.

I would like to be able to change the weight of the page-break penalty so that scores tried to stay on a page but that scores starting on even pages shouldn't care much (say \nopagebreak[1]), while ones on odd pages make a big deal out of it (\nopagebreak[3] or even 4). Additionally, it would be nice to have some sort of page-clear inserted before scores that were going to run over such that longer scores always start on even pages.

How could this be accomplished?

  • Have you tried fancyhdr package and \ifodd\thepage statement inserted in the header? It would be a great help if you could add a minimum working example in your post. It would help solvers a lot to start trying their ideas.
    – Malipivo
    Apr 11, 2014 at 11:00
  • 1
    @Malipivo I am using a KOMA documentclass so fancyhdr is not an option. I imagine there might be something similar though... I'll work on a minimal example, but as setting up at minimum several pages of data isn't trivial, I was afraid a live example would actually complicate a simple question.
    – Caleb
    Apr 11, 2014 at 11:06
  • 4
    There might be some packages useful for testing, ctan.org/topic/defer-stuff, but working with an example (even bigger one) is a real deal.
    – Malipivo
    Apr 11, 2014 at 11:16

1 Answer 1


You can try to use the command \ifthispageodd{<true part>}{<false part>}, which is part of KOMA-Script. It uses a label in the .aux file and therefore needs at least two LaTeX passes to function. In your case it could look like:


Without a MWE, however, it is difficult to tell whether this really works or not.

  • Thank you. Amazingly 3.5 years later I am actually still using this code and this is an improvement to it! In one real world usage I've run into an ugly race condition because I'm using multiple passes with incremental adjustments to fit the content to a specified page count and this makes the layout unpredictable between passes and the builder goes into convulsions, but given the situation in the question alone it seems to work as expected and it's nice to know how to get it done.
    – Caleb
    Nov 1, 2017 at 6:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .