When all of the elements discussed earlier are combined to produce
larger files, the \score
blocks get a lot bigger, because the
music expressions are longer, and, in the case of polyphonic and/or
orchestral pieces, more deeply nested. Such large expressions can
become unwieldy.
By using variables, also known as identifiers, it is possible to break up complex music expressions. An identifier is assigned as follows:
namedMusic = \notes { ...
The contents of the music expression namedMusic
, can be used
later by preceding the name with a backslash, i.e. \namedMusic
.
In the next example, a two note motive is repeated two times by using
variable substitution:
seufzer = \notes { dis'8 e'8 } \score { \notes { \seufzer \seufzer } }
The name of an identifier should have alphabetic characters only, and
no numbers, underscores or dashes. The assignment should be outside of
the \score
block.
It is possible to use variables for many other types of objects in the input. For example,
width = 4.5\cm name = "Wendy" aFivePaper = \paper { paperheight = 21.0 \cm }Depending on its contents, the identifier can be used in different places. The following example uses the above variables:
\score { \notes { c4^\name } \paper { \aFivePaper linewidth = \width } }
More information on the possible uses of identifiers is in the technical manual, in Scheme datatypes.
This page is for LilyPond-2.0.0 (stable-branch).