GNU LilyPond Learning Manual: 3.3.2 Creating contexts

### 3.3.2 Creating contexts

There can be only one top level context: the `Score` context. This is created with the `\score` command, or, in simple scores, it is created automatically.

For scores with only one voice and one staff, the `Voice` and `Staff` contexts may be left to be created automatically, but for more complex scores it is necessary to create them by hand. The simplest command that does this is `\new`. It is prepended to a music expression, for example

>     \new type music-expression

where type is a context name (like `Staff` or `Voice`). This command creates a new context, and starts interpreting the music-expression within that context.

Note that there is no `\new Score` command; the single top-level `Score` context is introduced with `\score`.

You have seen many practical examples which created new `Staff` and `Voice` contexts in earlier sections, but to remind you how these commands are used in practice, here’s an annotated real-music example:

>     \score {  % start of single compound music expression
>       <<  % start of simultaneous staves section
>         \time 2/4
>         \new Staff {  % create RH staff
>           \key g \minor
>           \clef "treble"
>           \new Voice {  % create voice for RH notes
>             \relative c'' {  % start of RH notes
>               d4 ees16 c8. |
>               d4 ees16 c8. |
>             }  % end of RH notes
>           }  % end of RH voice
>         }  % end of RH staff
>         \new Staff <<  % create LH staff; needs two simultaneous voices
>           \key g \minor
>           \clef "bass"
>           \new Voice {  % create LH voice one
>             \voiceOne
>             \relative g {  % start of LH voice one notes
>               g8 <bes d> ees, <g c> |
>               g8 <bes d> ees, <g c> |
>             }  % end of LH voice one notes
>           }  % end of LH voice one
>           \new Voice {  % create LH voice two
>             \voiceTwo
>             \relative g {  % start of LH voice two notes
>               g4 ees |
>               g4 ees |
>             }  % end of LH voice two notes
>           }  % end of LH voice two
>         >>  % end of LH staff
>       >>  % end of simultaneous staves section
>     }  % end of single compound music expression

(Note how all the statements which open a block with either a curly bracket, `{`, or double angle brackets, `<<`, are indented by two further spaces, and the corresponding closing bracket is indented by exactly the same amount. While this is not required, following this practice will greatly reduce the number of ‘unmatched bracket’ errors, and is strongly recommended. It enables the structure of the music to be seen at a glance, and any unmatched brackets will be obvious. Note too how the LH staff is created using double angle brackets because it requires two voices for its music, whereas the RH staff is created with a single music expression surrounded by curly brackets because it requires only one voice.)

The `\new` command may also give a identifying name to the context to distinguish it from other contexts of the same type,

>     \new type = id music-expression

Note the distinction between the name of the context type, `Staff`, `Voice`, etc, and the identifying name of a particular instance of that type, which can be any sequence of letters invented by the user. Digits and spaces can also be used in the identifying name, but then it has to be placed in quotes, i.e. `\new Staff = "MyStaff 1" music-expression`. The identifying name is used to refer back to that particular instance of a context. We saw this in use in the section on lyrics, see Voices and vocals.

#### See also

Notation Reference: Creating contexts.

Other languages: français, español, deutsch.

#### Learning Manual