### 5.1.5 Changing context default settings

Context and grob properties can be changed with `\set` and `\override` commands, as described in Modifying properties. These commands create music events, making the changes take effect at the point in time the music is being processed.

In contrast, this section explains how to change the default values of context and grob properties at the time the context is created. There are two ways of doing this. One modifies the default values in all contexts of a particular type, the other modifies the default values in just one particular instance of a context.

#### Changing all contexts of the same type

The default context settings which are to be used for typesetting in `Score`, `Staff`, `Voice` and other contexts may be specified in a `\context` block within any `\layout` block.

Settings for Midi output as opposed to typesetting will have to be separately specified in `\midi` blocks (see Output definitions - blueprints for contexts).

The `\layout` block should be placed within the `\score` block to which it is to apply, after the music.

>     \layout {
>       \context {
>         \Voice
>         [context settings for all Voice contexts]
>       }
>       \context {
>         \Staff
>         [context settings for all Staff contexts]
>       }
>     }

The following types of settings may be specified:

- An `\override` command, but with the context name omitted

  >     \score {
  >       \relative c'' {
  >         a4^"Thicker stems" a a a
  >         a4 a a\ff a
  >       }
  >       \layout {
  >         \context {
  >           \Staff
  >           \override Stem.thickness = #4.0
  >         }
  >       }
  >     }

- Directly setting a context property

  >     \score {
  >       \relative c'' {
  >         a4^"Smaller font" a a a
  >         a4 a a\ff a
  >       }
  >       \layout {
  >         \context {
  >           \Staff
  >           fontSize = #-4
  >         }
  >       }
  >     }

- A predefined command such as `\dynamicUp` or a music expression like `\accidentalStyle dodecaphonic`

  >     \score {
  >       \relative c'' {
  >         a4^"Dynamics above" a a a
  >         a4 a a\ff a
  >       }
  >       \layout {
  >         \context {
  >           \Voice
  >           \dynamicUp
  >         }
  >         \context {
  >           \Staff
  >           \accidentalStyle dodecaphonic
  >         }
  >       }
  >     }

- A user-defined variable containing a `\with` block; for details of the `\with` block see Changing just one specific context.

  >     StaffDefaults = \with {
  >       fontSize = #-4
  >     }

  >     \score {
  >       \new Staff {
  >         \relative c'' {
  >           a4^"Smaller font" a a a
  >           a4 a a a
  >         }
  >       }
  >       \layout {
  >         \context {
  >           \Staff
  >           \StaffDefaults
  >         }
  >       }
  >     }

Property-setting commands can be placed in a `\layout` block without being enclosed in a `\context` block. Such settings are equivalent to including the same property-setting commands at the start of every context of the type specified. If no context is specified every bottom-level context is affected, see Bottom-level contexts - voices. The syntax of a property-setting command in a `\layout` block is the same as the same command written in the music stream.

>     \score {
>       \new Staff {
>         \relative c'' {
>           a4^"Smaller font" a a a
>           a4 a a a
>         }
>       }
>       \layout {
>         \accidentalStyle dodecaphonic
>         \set fontSize = #-4
>         \override Voice.Stem.thickness = #4.0
>       }
>     }

#### Changing just one specific context

The context properties of just one specific context instance can be changed in a `\with` block. All other context instances of the same type retain the default settings built into LilyPond and modified by any `\layout` block within scope. The `\with` block must be placed immediately after the `\new` context-type command:

>     \new Staff \with { [context settings for this context instance only] }
>     {
>       …
>     }

Since such a ‘context modification’ is specified inside of music, it will affect all outputs (typesetting and Midi) as opposed to changes within an output definition.

The following types of settings may be specified:

- An `\override` command, but with the context name omitted

  >     \score {
  >       \new Staff {
  >         \new Voice \with { \override Stem.thickness = #4.0 }
  >         {
  >           \relative c'' {
  >             a4^"Thick stems" a a a
  >             a4 a a a
  >           }
  >         }
  >       }
  >     }

- Directly setting a context property

  >     \score {
  >       <<
  >         \new Staff {
  >           \relative c'' {
  >             a4^"Default font" a a a
  >             a4 a a a
  >           }
  >         }
  >         \new Staff \with { fontSize = #-4 }
  >         {
  >           \relative c'' {
  >             a4^"Smaller font" a a a
  >             a4 a a a
  >           }
  >         }
  >       >>
  >     }

- A predefined command such as `\dynamicUp`

  >     \score {
  >       <<
  >         \new Staff {
  >           \new Voice {
  >             \relative c'' {
  >               a4^"Dynamics below" a a a
  >               a4 a a\ff a
  >             }
  >           }
  >         }
  >         \new Staff \with { \accidentalStyle dodecaphonic }
  >         {
  >           \new Voice \with { \dynamicUp }
  >           {
  >             \relative c'' {
  >               a4^"Dynamics above" a a a
  >               a4 a a\ff a
  >             }
  >           }
  >         }
  >       >>
  >     }

#### Order of precedence

The value of a property which applies at a particular time is determined as follows:

- if an `\override` or `\set` command in the input stream is in effect that value is used,
- otherwise the default value taken from a `\with` statement on the context initiation statement is used,
- otherwise the default value taken from the most recent appropriate `\context` block in the `\layout` or `\midi` blocks is used,
- otherwise the LilyPond built-in default is used.

#### See also

Learning Manual: Modifying context properties.

Notation Reference: Contexts explained, Bottom-level contexts - voices, The `\set` command, The `\override` command, The `\layout` block.

其他语言：deutsch, español, français, italiano, 日本語。
About automatic language selection.

#### LilyPond — Notation Reference v2.18.2 (稳定分支).