5.3.6 \tweak and \single

When multiple grobs occur at the same musical moment the \override command cannot be used to modify just one of them. In this case the \tweak command is used.

The \tweak command has the following syntax

\tweak [layout-object.]grob-property value

and applies to the music expression that immediately follows value in the music stream. Specifying layout-object is necessary for disambiguation if the music expression causes the indirect creation of grobs with different types (for example, NoteHead causes Stem).

For an introduction to the syntax and uses of the tweak command see Tweaking methods.

Items that may appear more than once at the same musical moment include, but are not limited to, the following:

In this example, the color of one note head and the type of another note head are modified within a single chord:

< c''
  \tweak color #red
  \tweak duration-log 1
> 4

[image of music]

\tweak can also be used to modify slurs:

\relative { c'-\tweak thickness 5 ( d e f) }

[image of music]

Tweaking a whole chord tweaks all the contained notes:

{ \tweak color #red <c'' e''>4 }

[image of music]

As mentioned above, the simple \tweak command syntax form cannot be used to modify any object that is not directly created from the input. In particular, it will not affect stems, automatic beams, or accidentals, since these are generated later by NoteHead layout objects rather than by music elements in the input stream.

Such indirectly created layout objects can be tweaked using the form of the \tweak command in which the grob name is specified explicitly:

\tweak Stem.color #(universal-color 'orange)
\tweak Beam.color #(universal-color 'skyblue) c''8 e''
<c'' e'' \tweak Accidental.font-size -3 ges''>4

[image of music]

\tweak cannot be used to modify clefs or time signatures, since these become separated from any preceding \tweak command in the input stream by the automatic insertion of extra elements required to specify the context.

Multiple \tweak commands placed before a music expression all affect the grob(s) created at this musical moment.

  -\tweak springs-and-rods #ly:spanner::set-spacing-rods
  -\tweak minimum-length 15
  -\tweak style #'dashed-line
  -\tweak dash-fraction 0.2
  -\tweak thickness 3
  -\tweak color #red

[image of music]

The music stream which is generated from a section of an input file, including any automatically inserted elements, may be examined, see Displaying music expressions. This may be helpful in determining what may be modified by a \tweak command, or in determining how to adjust the input to make a \tweak apply.

The \single command takes one or more \override commands (which are intended to apply at a given musical moment or beyond) and converts them effectively into a single ‘tweak’ that now applies to the specific grobs created.

The file ly/property-init.ly contains many definitions of multiple \override commands and so can be used in conjunction with the \single command. For example, the function \easyHeadsOn can be used with \single to affect just one note head in a chord;

< \single \easyHeadsOn c' g' >2

[image of music]

See also

Learning Manual: Tweaking methods.

Extending LilyPond: Displaying music expressions.

Known issues and warnings

The \tweak command cannot be used to modify the control points of just one of several ties in a chord, other than the first one encountered in the input file.

LilyPond Notation Reference v2.25.13 (development-branch).