5.3.4 The \tweak command

In some cases, it is possible to take a short-cut for tuning graphical objects. For objects that are created directly from an item in the input file, you can use the \tweak command. For example:

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

[image of music]

But the main use of the \tweak command is to modify just one of a number of notation elements which start at the same musical moment, like the notes of a chord, or tuplet brackets which start at the same time.

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

The \tweak command sets a property in the following object directly, without requiring the grob name or context to be specified. For this to work, it is necessary for the \tweak command to remain immediately adjacent to the object to which it is to apply after the input file has been converted to a music stream. This is often not the case, as many additional elements are inserted into the music stream implicitly. For example, when a note which is not part of a chord is processed, Lilypond implicitly inserts a ChordEvent event before the note, so separating the tweak from the note. However, if chord symbols are placed round the tweak and the note, the \tweak command comes after the ChordEvent in the music stream, so remaining adjacent to the note, and able to modify it.

So, this works:

<\tweak #'color #red c>4

[image of music]

but this does not:

\tweak #'color #red c4

[image of music]

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:

and \tweak may be used to modify any single occurrence of these items.

Notably the \tweak command cannot be used to modify stems, beams or accidentals, since these are generated later by note heads, rather than by music elements in the input stream. Nor can a \tweak command 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.

But the \tweak command can be used as an alternative to the \override command to modify those notational elements that do not cause any additional implicit elements to be added before them in the music stream. For example, slurs may be modified in this way:

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

[image of music]

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

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

See also

Learning Manual: Tweaking methods.

Notation Reference: Displaying music expressions.

Known issues and warnings

The \tweak command cannot be used inside a variable.

The \tweak commands cannot be used in \lyricmode.

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.

Other languages: français, español.

Notation Reference