Lilypond variables part 2 – different page layouts for parts and scores

“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 “” 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 “” 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 “”
    { \classicalguitara }

  • I then repeat the process for the guitar 2 part with a file name “” containing the following code:

    \include “”
    { \classicalguitarb }

  • And finally for the score I create a file called “” containing:

    \include “”
    { << \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:


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…’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 ( and I add the following line:

partpagebreak = { \pageBreak }

And in the score file ( 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

Lilypond Template

With Lilypond each time I start a new project I start with a template file….here is the code:

%% Headers
\version “2.10.33”
\header {
title = “”
subtitle = “”
tagline = “Eugene Cormier – 2008”
\paper {
print-page-number = ##f
ragged-last-bottom = ##t
ragged-right = ##f
indent = 0\in
#(set-global-staff-size 20)

%% Variables

% Time
notimesig = { \override Staff.TimeSignature #’transparent = ##t }
numbertimesig = { \override Staff.TimeSignature #’style = #'() }

% Key
nokeysig = { \override Staff.KeySignature #’transparent = ##t }
nokeycancel = { \set Staff.printKeyCancellation = ##f }

% Barlines
nobarlines = { \override Staff.BarLine #’transparent = ##t }
nobarlinenumbers = { \override Score.BarNumber #’transparent = ##t }

% Clefs
noclefresize = { \override Staff.Clef #’full-size-change = ##t }
noclef = { \override Staff.Clef #’transparent = ##t }

% notes
nonoteheads = { \override NoteHead #’transparent = ##t }
nostems = { \override Stem #’transparent = ##t }
nobeams = { \override Beam #’transparent = ##t }

%% Body

After this all I need to do is put in the code for the music I want to enter and I have variables defined for most of the most common changes I need to make.

Note: before using this code you should:

  • change the \version # to match whichever version of lilypond you are using….remember this number is very important for down the road when new versions of Lilypond are released….if some of the code is different in newer versions, this number will help Lilypond automatically update your code to work with the new version
  • change the tagline to your own name

Lilypond variables

I use Lilypond quite a lot, and over time I’ve realized the usefulness of variables.

In Lilypond you can easily make a variable by doing the following:

variablename = { whatever you want your variable to contain }

let me give an example….If I want to typeset a piece for guitar quartet (or any collection of instruments) there is certain information that will be used for each instrument:

\time 4/4
\key e \major
\partial 8

each of these lines would be nesseary for each individual part….the first line defines the time signature as 4/4, the second line defines the key signature and the last line tells Lilypond to have a pickup measure or partial measure) which is an eighth note duration.

to put this in a variable all I need to do is this:

piecesetup = {
\time 4/4
\key e \major
\partial 8

now in each of the individual guitar parts all I have to enter to get all those is:


Note: when you define the variable, you don’t put a \ in front, but when you call for the variable in a part you must put the \ before the variable name (also be careful, you can’t use numbers or special characters in your variable name….just letters)

One nice aspect of this is after you’ve created all 4 guitar parts using the \piecesetup variable if you realize the key signature was wrong, you only need to change it once in the variable and all the parts are automatically fixed.

Guitar Tip #1 – Practicing

Obviously people fill tomes about different “practice” methods, and it’s a very complex topic. In this post I just want to write about what I find works for me right now (over the years I’ve tried many different ways of practicing).

Most of the time when I pick up a new piece (or even something I haven’t played in a long time) I find that I can sight read through at least 80-90% of the piece (this is often slow reading at times). With this in mind, I approach the challenge in the following way:

  • I take any sections that I can’t read through and play them over a few times each until I can keep it up to tempo with the rest of the piece (I mean slower sight reading tempo, not performance tempo)
    *this usually takes me 3-4 days depending on the difficulty of the work
  • Once that’s done, I’m ready to start playing through the piece as a whole (in the beginning stages it may take me an hour or so to get through it all if it’s a big work). From this point I start doing 2 things:
    • (1) making mental notes of problem areas, that is:
      • anything that doesn’t sound good in terms of phrasing, lines, buzz, position leaps, etc… -Remember you are looking for the “consistent” mistakes
      • anything that doesn’t feel good in the hands (this can be due to: bad fingerings and/or lack of technique, in which case I have 2 options:
        • change the fingering to utilize another technique in which I am strong (if possible)
        • if another fingering is not possible, like if the fingering change worsens legato or phrase lines, then I will take the technique, and based on how well I can already execute it, I will: start with extremely slow practice always trying to perform the action with as little effort as possible…..try to find “comfort” in the new technique; once I have the main idea of how to do it, I design a number of exercises to strengthen and improve the speed/accuracy of the technique (all the while trying it out in the context of the music)
    • (2) As I play through the piece at slow tempos I start trying out different musical ideas (interpretation). At first I find many passages are not sounding their best, but over time I come up with many good ideas…..and each time I think of a good idea, I play the passage a few times so that I wont forget it
  • At this point practice for me becomes, rehearsing the piece from top to bottom and each time I hit a section that isn’t working as well as the rest, I stop for 5-15 minutes to work on making that section more comfortable (mentally and physically)

I could write so much more on this topic, but I’ll leave my first post moderately short

Combine noteheads of different values in Lilypond

I’ve been recently typesetting some classical guitar notation into Lilypond and wanting to get as close to the original as possible I noticed that Lilypond was handling doubled notes with different values incorrectly (for my purposes).

Here is some example code to demonstrate what I mean:

\relative c”{
<<{ g8 c g c g2 } \\{ g4. c8 g2 }>>



To get around this use the “Staff.NoteCollision” command like this:

\relative c”{
\override Staff.NoteCollision #’merge-differently-dotted = ##t
<<{ g8 c g c g2 } \\{ g4. c8 g2 }>>

And the resulting output:


Please note: this is how it works on my Lilypond which is an older version (2.10.33) which ships with Ubuntu 8.10. If you are using the newest stable version (2.12.1) the command looks a little different:

\relative c”{
<<{ g8 c g c g2 } \\{ g4. c8 g2 }>>

How to recover data from a damaged cd/dvd

EDIT: see my new post about this here:
Linux DVD conversion to h264 aac mp4

Simply use ddrescue…to install in Ubuntu:
sudo apt-get install gddrescue

To use:
ddrescue -d /dev/cdrom output.iso

It is by far the best/easiest program I’ve seen for rescuing data and it will recover everything possible. (It works great on CDs and DVDs)