Next: , Previous: Piano staves, Up: Tutorial


2.18 Organizing larger pieces

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 music, 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 = { ... }

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 = {
       e'4( dis'4)
     }
     { \seufzer \seufzer }

[image of music]

The name of an identifier should have alphabetic characters only: no numbers, underscores, or dashes. The assignment should be outside of running music.

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

\paper {
  \aFivePaper
  line-width = \width
}
{ c4^\name }

More information on the possible uses of identifiers is given in the technical manual, in Input variables and Scheme.

This page is for LilyPond-2.10.13 (stable-branch).

Report errors to http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs.

Other languages: French.
Using automatic language selection.