LilyPond Notation Reference: 5.1.2 Creating contexts

### 5.1.2 Creating contexts

For scores with only one voice and one staff, contexts are created automatically. For more complex scores, it is necessary to create them by hand. There are three commands that do this.

- The easiest command is `\new`, and it also the quickest to type. 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 with that.

  A practical application of `\new` is a score with many staves. Each part that should be on its own staff, is preceded with `\new Staff`.

  >     <<
  >       \new Staff { c4 c }
  >       \new Staff { d4 d }
  >     >>

  The `\new` command may also give a name to the context,

  >     \new type = id music

  However, this user specified name is only used if there is no other context already earlier with the same name.

- Like `\new`, the `\context` command also directs a music expression to a context object, but gives the context an explicit name. The syntax is

  >     \context type = id music

  This form will search for an existing context of type type called id. If that context does not exist yet, a new context with the specified name is created. This is useful if the context is referred to later on. For example, when setting lyrics the melody is in a named context

  >     \context Voice = "tenor" music

  so the texts can be properly aligned to its notes,

  >     \new Lyrics \lyricsto "tenor" lyrics

  Another possible use of named contexts is funneling two different music expressions into one context. In the following example, articulations and notes are entered separately,

  >     music = { c4 c4 }
  >     arts = { s4-. s4-> }

  They are combined by sending both to the same `Voice` context,

  >     <<
  >       \new Staff \context Voice = "A" \music
  >       \context Voice = "A" \arts
  >     >>

  With this mechanism, it is possible to define an Urtext (original edition), with the option to put several distinct articulations on the same notes.

- The third command for creating contexts is

  >     \context type music

  This is similar to `\context` with `= id`, but matches any context of type type, regardless of its given name.

  This variant is used with music expressions that can be interpreted at several levels. For example, the `\applyOutput` command (see Running a function on all layout objects). Without an explicit `\context`, it is usually applied to `Voice`

  >     \applyOutput #'context #function   % apply to Voice

  To have it interpreted at the `Score` or `Staff` level use these forms

  >     \applyOutput #'Score #function
  >     \applyOutput #'Staff #function

Other languages: deutsch, español, 日本語.

#### LilyPond — Notation Reference