# LilyPond: auto horizontal space for dynamic text

I am missing something basic, I spent hours searching for docs for no avail. Sometimes LilyPond can be really frustrating.

Look at this picture:

Obviously, ppp overlaps with the bar line. According to documentation, I tried using DynamicText.extra-spacing-width, but it has zero effect. Here's the code:

\version "2.22.1"
\language "italiano"

common = {
\key sol \minor
\time 4/4
\tempo "Largo [Широко]"
}

right = \relative do'' {
\key sol \major
}

left = \relative do' {
\key sol \major
sol,8 (re' si' re,) sol, (re' do' re,) |
sol, (re' sib' re,) sol, (re' do' re,) |
}

dynamics = {
s1 |
\override DynamicText.extra-spacing-width = #'(-1 . 1)
s8 \ppp s8 s8 s8 s8 s8 s4
}

\score {
\new PianoStaff <<
\new Staff = "right" \right
\new Dynamics \dynamics
\new Staff = "left" { \clef bass \left }
>>
}


If I move \override ... right in the front of \ppp, it doesn't overlap, but LilyPond complains then with "Unattached AbsoluteDynamicEvent".

I run into this a lot. I find that using an X-offset works:

dynamics = {
s1 |
\override DynamicText.X-offset = 0
s8 \ppp s8 s8 s8 s8 s8 s4
}

• Very intuitive :) Jul 30, 2021 at 16:32

This looks like a bug to me. For extra-spacing-width to work, both of the objects that should avoid each other must have some width and some height. You can visualize the "skylines" that LilyPond uses for distancing using

#(ly:set-option 'debug-skylines)
\layout {
\context {
\Score
\override PaperColumn.stencil = #ly:separation-item::print
\override NonMusicalPaperColumn.stencil = #ly:separation-item::print
}
}


(it's expected that the ones from the lower staff are vertically off by some amount; horizontal skylines are built before line breaking, when we only have an estimation of the distance between the two staves).

This gives:

You can see that the problem is the SpanBar not receiving skylines; this is because it has no height, so the interval on which it is considered to collide is not known.

For now a workaround seems to be

\layout {
\context {
\Score
\override SpanBar.Y-extent = #axis-group-interface::height
\override SpanBar.meta.object-callbacks.pure-Y-common =
#ly:axis-group-interface::calc-pure-y-common
\override SpanBar.meta.object-callbacks.pure-relevant-grobs =
#ly:axis-group-interface::calc-pure-relevant-grobs
}
}


(there must be a reason why it is not in the current code, so be aware that it could have bad effects in cases that I have no considered).

• Would this same SpanBar issue explain the problem is this question?: LilyPond: parenthesized hairpin. Aug 1, 2021 at 7:52
• Not fully. Spanners do not participate in horizontal spacing the same way as items with skylines, only via minimum-distance and minimum-distance-after-break as far as I can see. At least, my pending merge request gitlab.com/lilypond/lilypond/-/merge_requests/842 does not solve the case\version "2.23.4" \layout { \context { \Score \override BarLine.bar-extent = #'(-10 . 10) \override Parentheses.font-size = 10 } } \new StaffGroup << { c1\parenthesize\< 1\! } { c1 1 } >> Aug 1, 2021 at 13:52
• I don't understand practically anything in this post. I don't understand the code, the term "skylines", how to interpret the picture, and what is SpanBar. Aug 5, 2021 at 5:59
• Ok, - SpanBar is the grob that draws the part of the bar line between staves. To understand, try \version "2.22.1" \new StaffGroup \with { \override SpanBar.color = red } << { c1 } { c1 } >> - Skylines are outlines of objects. They are used to resolve collisions. You can view them as pieces of metal in the score, with space between them; LilyPond could compress the score until the pieces are touching each other. This applies to horizontal and vertical spacing. - The code is not supposed to be understandable. It's a horrible low-level hack. Aug 5, 2021 at 21:19