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:

\piecesetup

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>