5.4.4 Spanners

Many objects of musical notation extend over several notes or even several bars. Examples are slurs, beams, tuplet brackets, volta repeat brackets, crescendi, trills, and glissandi. Such objects are collectively called “spanners”, and have special properties to control their appearance and behavior, as well as special tweaking methods related to the fact that they can be broken across systems.


Modifying broken spanners

When a spanner crosses a line break or breaks, each piece inherits the attributes of the original spanner. Thus, ordinary tweaking of a broken spanner applies the same modifications to each of its segments. In the example below, overriding thickness affects the slur on either side of the line break.

\relative c'' {
  r2
  \once\override Slur.thickness = 10
  c8( d e f
  \break
  g8 f e d) r2
}

[image of music]

Independently modifying the appearance of individual pieces of a broken spanner is possible with the \alterBroken command. This command can produce either an \override or a \tweak of a spanner property.

The syntax for \alterBroken is

[-]\alterBroken property values target

The argument values is a list of values, one for each broken piece. If target is a grob name like Slur or Staff.PianoPedalBracket, the result is an \override of the specified grob type. If target is a music expression such as ‘(’ or ‘[’ the result is the same music expression with an appropriate tweak applied.

The leading hyphen must be used with the \tweak form. Do not add it when \alterBroken is used as an \override.

In its \override usage, \alterBroken may be prefaced by \once or \temporary and reverted by using \revert with property (see substitution functions Intermediate substitution functions).

The following code applies an independent \override to each of the slur segments in the previous example:

\relative c'' {
  r2
  \alterBroken thickness #'(10 1) Slur
  c8( d e f
  \break
  g8 f e d) r2
}

[image of music]

The \alterBroken command may be used with any spanner object, including Tie, PhrasingSlur, Beam and TextSpanner. For example, an editor preparing a scholarly edition may wish to indicate the absence of part of a phrasing slur in a source by dashing only the segment which has been added. The following example illustrates how this can be done, in this case using the \tweak form of the command:

% The empty list is conveniently used below, because it is the
% default setting of dash-definition, resulting in a solid curve.
\relative {
  c''2-\alterBroken dash-definition #'(() ((0 1.0 0.4 0.75))) \(e
  \break
  g2 e\)
}

[image of music]

It is important to understand that \alterBroken sets each piece of a broken spanner to the corresponding value in values. When there are fewer values than pieces, any additional piece will be assigned the empty list. This may lead to undesired results if the layout property is not set to the empty list by default. In such cases, each segment should be assigned an appropriate value.

Known issues and warnings

Line breaks may occur in different places following changes in layout. Settings chosen for \alterBroken may be unsuitable for a spanner that is no longer broken or is split into more segments than before. Explicit use of \break can guard against this situation.

The \alterBroken command is ineffective for spanner properties accessed before line breaking such as direction.

See also

Extending LilyPond: Difficult tweaks.


Setting minimum lengths for spanners

The spanner-interface interface provides three properties that apply to several spanners.

The minimum-length property

The minimum length of the spanner is specified by the minimum-length property. Increasing this usually has the necessary effect of increasing the spacing of the notes between the two end points. However, this override has no effect on many spanners, as their length is determined by other considerations. A few examples where it is effective are shown below.

a'~ a'
a'
% increase the length of the tie
-\tweak minimum-length #5
~ a'

[image of music]

\relative \compressMMRests {
  a'1
  R1*23
  % increase the length of the rest bar
  \once \override MultiMeasureRest.minimum-length = #20
  R1*23
  a1
}

[image of music]

\relative {
  a' \< a a a \!
  % increase the length of the hairpin
  \override Hairpin.minimum-length = #20
  a \< a a a \!
}

[image of music]

This override can also be used to increase the length of slurs and phrasing slurs:

\relative {
  a'( g)
  a
  -\tweak minimum-length #5
  ( g)

  a\( g\)
  a
  -\tweak minimum-length #5
  \( g\)
}

[image of music]

For some layout objects, the minimum-length property becomes effective only if the set-spacing-rods procedure is called explicitly. To do this, the springs-and-rods property should be set to ly:spanner::set-spacing-rods. For example, the minimum length of a glissando has no effect unless the springs-and-rods property is set:

% default
e' \glissando c''

% not effective alone
\once \override Glissando.minimum-length = #20
e' \glissando c''

% effective only when both overrides are present
\once \override Glissando.minimum-length = #20
\once \override Glissando.springs-and-rods =
                  #ly:spanner::set-spacing-rods
e' \glissando c''

[image of music]

The same is true of the Beam object:

% not effective alone
\once \override Beam.minimum-length = #20
e'8 e' e' e'

% effective only when both overrides are present
\once \override Beam.minimum-length = #20
\once \override Beam.springs-and-rods =
                  #ly:spanner::set-spacing-rods
e'8 e' e' e'

[image of music]

The minimum-length-after-break property

The property minimum-length-after-break can be used to stretch broken spanners starting after a line break. As for the minimum-length property, it is often needed to set the springs-and-rods property to ly:spanner::set-spacing-rods.

{
  \once \override Tie.minimum-length-after-break = 20
  a1~
  \break
  a1

  \once \override Slur.minimum-length-after-break = 20
  a1(
  \break
  d'1)

  \once \override TextSpanner.springs-and-rods =
    #ly:spanner::set-spacing-rods
  \once \override TextSpanner.minimum-length-after-break = 20
  a1\startTextSpan
  \break
  a1\stopTextSpan

  \once \override Hairpin.after-line-breaking = ##t
  \once \override Hairpin.to-barline = ##f
  \once \override Hairpin.minimum-length-after-break = 20
  a1\<
  \break
  a1\!

  \once \override Glissando.springs-and-rods =
    #ly:spanner::set-spacing-rods
  \once \override Glissando.breakable = ##t
  \once \override Glissando.after-line-breaking = ##t
  \once \override Glissando.minimum-length-after-break = 20
  a1\glissando
  \break
  d'1
}

[image of music]


Controlling spanner end points

The to-barline property of the spanner-interface, usually defaulting to true, causes hairpins and other spanners that are terminated on the first note of a measure to end instead on the immediately preceding bar line. If set to false, the spanner extends beyond the bar line and end on the note itself:

\relative {
  a' \< a a a a \! a a a \break
  \override Hairpin.to-barline = ##f
  a \< a a a a \! a a a
}

[image of music]

This property is not effective for all spanners. For example, setting it to #t has no effect on slurs or phrasing slurs or on other spanners for which terminating on the bar line would not be meaningful.


LilyPond — Notation Reference v2.24.4 (stable-branch).