“Necessity is the mother of invention”
I’m typesetting a piece for 2 guitars and in the end I want to print off individual parts and a score. This can easily be achieved in Lilypond using the following method:
- First I create a file called “notes.ly” this is the file which will contain all the music. I make 2 variables called “classicalguitara” and “classicalguitarb” being the notes for each part
- next I make a file called “classicalguitar1.ly” and inside this file I include a statement to load the file with the notes in it and then I call for the first guitar part by it’s variable name:
\include “notes.ly”
{ \classicalguitara } - I then repeat the process for the guitar 2 part with a file name “classicalguitar2.ly” containing the following code:
\include “notes.ly”
{ \classicalguitarb } - And finally for the score I create a file called “score.ly” containing:
\include “notes.ly”
{ << \new Staff { \guitara } \new Staff { \guitarb } >> }
Now for the real problem….I need to have logical page breaks (which will happen in different places for the 2 guitar parts and the score). Now if I put in a page break into a single guitar part using the command:
\pageBreak
then the score will break in the same place….this will really be a problem when it comes to different page break locations for each of the parts…..there has got to be a good way to deal with this without constantly changing code for each individual part! And that’s when it came to me….wonderful variables can save the day…..here’s the low down:
Instead of using the page break command in the parts I use a variable called “partpagebreak”
then in the individual guitar files (classicalguitar1.ly and classicalguitar2.ly) I add the following line:
partpagebreak = { \pageBreak }
And in the score file (score.ly) I add the following line:
partpagebreak = { }
Now when I print the individual parts the command \partpagebreak will be replaced with the command for a page break and when I print the score the same variable will be converted into an empty space…problem fixed….different page layouts using the same code. Very cool!
Note: If I actually wanted to have specified page breaks in the score I could easily create a variable called “scorepagebreaks” and that would do the trick
That works perfectly. Thank you for saving me! 😉