The \override command

We have already met the commands \set and \with, used to change the properties of contexts and to remove and add engravers, in Modifying context properties, and Adding and removing engravers. We must now introduce some more important commands.

The command to change the properties of layout objects is \override. Because this command has to modify internal properties deep within LilyPond its syntax is not as simple as the commands you have used so far. It needs to know precisely which property of which object in which context has to be modified, and what its new value is to be. Let’s see how this is done.

The general syntax of this command is:

\override Context.LayoutObject.layout-property = value

This sets the property with the name layout-property of the layout object with the name LayoutObject, which is a member of the Context context, to the value value.

The Context may be omitted (and usually is) when the required context is unambiguously implied and is one of lowest level contexts, i.e., Voice, ChordNames or Lyrics, and we shall omit it in many of the following examples. We shall see later when it must be specified.

Later sections deal comprehensively with properties and their values, see Types of properties. But in this section we shall use just a few simple properties and values which are easily understood in order to illustrate the format and use of these commands.

LilyPond’s primary expressions are musical items like notes and durations, as well as strings and markups. More specific expressions like symbols and lists are processed in ‘Scheme mode’, which is invoked by prefixing the value with ‘#’. A special case are numbers, which must be prefixed with ‘#’ only if used as arguments to a markup function (i.e., within \markup).1

For more information about Scheme mode, see LilyPond Scheme syntax.

\override is the most common command used in tweaking, and most of the rest of this chapter will be directed to presenting examples of how it is used. Here is a simple example to change the color of the note head:

\relative {
  c'4 d
  \override NoteHead.color = "red"
  e4 f |
  \override NoteHead.color = "green"
  g4 a b c |
}

[image of music]


Footnotes

(1)

Note, however, that for LilyPond a number must start with a digit or a minus sign followed by a digit if not in Scheme mode. In other words, ‘0.2’ or ‘-0.2’ are valid numbers, while ‘.2’ or ‘-.2’ are not. If really necessary you can write ‘#.2’ or ‘#-.2’ instead – Scheme supports a much broader range of number representations.


LilyPond 学习手册 v2.25.21 (开发分支).