5.1.7 Context layout order

Contexts are normally positioned in a system from top to bottom in the order in which they are encountered in the input file. When contexts are nested, the outer context will include inner nested contexts as specified in the input file, provided the inner contexts are included in the outer context’s “accepts” list. Nested contexts which are not included in the outer context’s “accepts” list will be repositioned below the outer context rather than nested within it.

The “accepts” list of a context can be changed with the \accepts and \denies commands. \accepts adds a context to the “accepts” list and \denies removes a context from the list. For example, it would not normally be desirable for chord names to be nested within a Staff context, so the ChordNames context is not included by default in the “accepts” list of the Staff context, but if this were to be required it can be done:

\score {
  \new Staff {
    c' d' e' f'
    \chords { d1:m7 b1:min7.5- }
  }
}

[image of music]

\score {
  \new Staff {
    c' d' e' f'
    \chords { d1:m7 b1:min7.5- }
  }
  \layout {
    \context {
      \Staff
      \accepts "ChordNames"
    }
  }
}

[image of music]

\denies is mainly used when a new context is being based on another, but the required nesting differs. For example, the VaticanaStaff context is based on the Staff context, but with the VaticanaVoice context substituted for the Voice context in the “accepts” list.

Note that a context will be silently created implicitly if a command is encountered when there is no suitable context available to contain it.

Within a context definition, the type of subcontext to be implicitly created is specified using \defaultchild. A number of music events require a ‘Bottom’ context: when such an event is encountered, subcontexts are created recursively until reaching a context with no ‘defaultchild’ setting.

Implicit context creation can at times give rise to unexpected new staves or scores. Using \new to create contexts explicitly avoids those problems.

Sometimes a context is required to exist for just a brief period, a good example being the staff context for an ossia. This is usually achieved by introducing the context definition at the appropriate place in parallel with corresponding section of the main music. By default, the temporary context will be placed below all the existing contexts. To reposition it above the context called “main”, it should be defined like this:

\new Staff \with { alignAboveContext = #"main" } 

A similar situation arises when positioning a temporary lyrics context within a multi-staved layout such as a ChoirStaff, for example, when adding a second verse to a repeated section. By default the temporary lyrics context will be placed beneath the lower staves. By defining the temporary lyrics context with alignBelowContext it can be positioned correctly beneath the (named) lyrics context containing the first verse.

Examples showing this repositioning of temporary contexts can be found elsewhere — see Nesting music expressions, Modifying single staves and Techniques specific to lyrics.

See also

Learning Manual: Nesting music expressions.

Notation Reference: Modifying single staves, Techniques specific to lyrics.

Application Usage: An extra staff appears.

Installed Files: ‘ly/engraver-init.ly’.


Other languages: deutsch, español, français, italiano, 日本語.
About automatic language selection.

LilyPond — Notation Reference v2.17.97 (development-branch).