How to force a page break in LilyPond

I'm trying to force a page break by using the manual page breaking mode in LilyPond. Yet, I cannot make a working example. Consider this snippet (main.ly)

\version "2.22.2"
\include "lilypond-book-preamble.ly"

RightHand = {
<e g c>4 <e g c> <b d g> <b d g> |
<a c e> <a c e>8 <a c e> <a c e>4 <a c d> |
<e' g c>4 <e g c> <b d g> <b d g> |
<f' a>4 <e g>8 <d f> <c e g>4 <c e g> \bar "|."
}
LeftHand = {
c8 c'4 c16 f,16 g8 g,4 g'8 |
a,8 a'4 <g, g'>8 <f f'>8 f'4 f8 |
c8 c'4 c16 f,16 g8 g,4 g8 |
f8 f'4. c8 c'4 c8 \bar "|."
}

\paper {
page-breaking = #ly:page-turn-breaking
}

\score {
\new PianoStaff
<<
\new Staff {
\relative c' {
\clef G
\RightHand
\pageBreak
\RightHand
}
}
\new Staff {
\relative c, {
\clef F
\LeftHand
\pageBreak
\LeftHand
}
}
>>
}


How would I force a page break between the two lines? I tried replacing the \pageBreak command with \pageTurn, and also tried different ways to structure the score. None of them work, by which I mean that the resulting pdf is a one-page document with all the music on the same page.

I compile this example with

lilypond-book --pdf main.lytex


where the content of main.lytex is

\documentclass[letterpaper,12pt]{article}
\begin{document}
\lilypondfile{main.ly}
\end{document}


and the resulting main.tex is compiled with LaTeX.

• \pageBreak is the way to go. Could you elaborate on how exactly it doesn't work? I tried your snippet with v2.22.1 and it does work. It's not pretty but the \pageBreak does what it should do. // By the way, you can get rid of one of those \pageBreaks — as soon as a \pageBreak is encountered in any single voice and staff, the whole system is broken off and it continues at the next page. Apr 3, 2022 at 10:39
• @Ramillies are you running normal LilyPond or LilyPond-book? Apr 3, 2022 at 11:00
• @ElementsinSpace — normal Lilypond. lilypond-book would have to be used on a HTML or LaTeX file with Lilypond snippets inlined in it. I wonder if the OP wants to break a page e. g. in LaTeX from within such a snippet? Apr 3, 2022 at 11:06
• @Ramillies I think they are trying to something like that because they are including the book preamble. It will be helpful if they can explain this with an edit to the question. Apr 3, 2022 at 11:20
• I've edited the question to describe my workflow. Yes, I want to break a page in the same way I would do with \clearpage in LaTeX. Apr 3, 2022 at 11:56

lilypond-book is not really intended for what you appear to be trying to do. lilypond-book intended for embedding short pieces of music into a LaTeX-document. This means that lilypond-book hands all of the page spacing decisions to LaTeX. This is done by splitting the score into individual systems and passing these to LaTeX, which allows LaTeX to make it’s own decisions about spacing and page breaking.

This means that you need to do page breaks from withing LaTeX, not Lilypond. While you can use \betweenLilyPondSystem to have lilypond-book somehow manage this the easiest way would be to use multiple LilyPond-Sections with page breaks in between.

If you want to include a longer example of music with multiple pages it would be adviseable to create the score in Lilypond and embed this into the LaTeX file.

• Thanks for the clear answer. So if I split main.ly in two distinct files, how would I share the variables between these two files, e.g. commands \RightHand and \LeftHand in the example? Apr 3, 2022 at 20:21
• @Antonius Put eveything you want to keep in common in a separate file and use \include.
– Lazy
Apr 3, 2022 at 20:42

You try a forced marriage between lilypond and LaTeX. But it is already a difficult relationship. I don't know, if you saw it, but lilypond-book creates pdf-snippets, which are inserted after. I switched to creating them manually very early. For this purpose I wrote a LaTeX package. I will publish it hopefully in the next weeks. You can find it here: https://github.com/MaestroGlanz/Lieder-Package

You should have a look into that. Maybe it solves your problem.

• Could you explain a bit more on what this does? Does is create the PDF scores separately, and then include them in the LaTeX file automatically?
– Richard
May 8, 2022 at 13:02
• @Richard You create the pdf manually and create a songbook manually in the preamble. For creating the lilypond pdf, you can use the lilypond file from the demo project. Once you have these, the Lieder-Package gives you environments and commands to fit text to the notes and align the lines and everything. It is robust against different line length. 1. Write the lilypond snippets, 2. Write the song in the preamble of the LaTeX document, 3. Include the whole song with one command. May 8, 2022 at 13:09
• I'm not sure, if it really is clearer. Look at the resulting lilypond pdf in the demo project. May 8, 2022 at 13:11