5.3.4 The \tweak command

Changing grob properties with \override causes the changes to apply to all of the given grobs in the context at the moment the change applies. Sometimes, however, it is desirable to have changes apply to just one grob, rather than to all grobs in the affected context. This is accomplished with the \tweak command, which has the following syntax:

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

Specifying layout-object is optional. The \tweak command applies to the music object that immediately follows value in the music stream.

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

When several similar items are placed at the same musical moment, the \override command cannot be used to modify just one of them – this is where the \tweak command must be used. Items which may appear more than once at the same musical moment include 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
  d''
  g''
  \tweak duration-log #1
  a''
> 4

[image of music]

\tweak can be used to modify slurs:

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

[image of music]

For the \tweak command to work, it must remain immediately adjacent to the object to which it is to apply after the input file has been converted to a music stream. Tweaking a whole chord does not do anything since its music event only acts as a container, and all layout objects are created from events inside of the EventChord:

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

[image of music]

The simple \tweak command 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.

Several \tweak commands may be placed before a notational element – all affect it:

c'
  -\tweak style #'dashed-line
  -\tweak dash-fraction #0.2
  -\tweak thickness #3
  -\tweak color #red
  \glissando
f''

[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.

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.24.4 (stable-branch).