I found LilyPond code to place a hairpin between parenthesis like this:


You can see that the result overlaps with the bar line. The code that does it is some hard-core Scheme hackery. One obviously has to know Scheme and the guts LilyPond to write it. I don't know how to modify it to avoid overlapping. Can somebody help?

\version "2.22.1"
\language "italiano"

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

hairpinBetweenText =
#(define-music-function (parser location leftText rightText) (markup? markup?)  
        \once \override Hairpin.stencil =
        #(lambda (grob)
                    (ly:stencil-aligned-to (grob-interpret-markup grob leftText) Y CENTER)
                    X RIGHT
                    (ly:stencil-aligned-to (ly:hairpin::print grob) Y CENTER)
                X RIGHT
                (ly:stencil-aligned-to (grob-interpret-markup grob rightText) Y CENTER)

parenthesizedHairpin = \hairpinBetweenText \markup{\larger\larger "("} \markup{\larger\larger ")"}

right = \relative do'' {
    \key sol \minor
    re8 mib re do sib la sol sib |
    mib, re fa mib re4. la8 |
    re8 mib re sib' re, fad la re |

left = \relative do' {
    \key sol \minor
    sib,8 (sib')  <fad la re>4 sol,8 (re') <sol sib re>4 |
    do,,8 (sol') <mib' sol>4 re,8 (re') <fad la re>4~ |
    8 r8 r4 r2 |

dynamics = {
    s8 s8 s8 \parenthesizedHairpin s8 \> s8 s8 s8 s8 \! |

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

2 Answers 2


Just adjust the hairpin's span as needed using shorten-pair.

dynamics = {
    s8 s8 s8 \parenthesizedHairpin s8\tweak shorten-pair #'(0 . 0.9)\> s8 s8 s8 s8 \! |

See the snippet "Moving the ends of hairpins" in the documentation at http://lilypond.org/doc/v2.23/Documentation/notation/expressive-marks-attached-to-notes.html#dynamics.

By the way, note that out-of-the-box support for parenthesizing spanners is currently being added (https://gitlab.com/lilypond/lilypond/-/merge_requests/839). It does not solve the collision, though (even with the pending change https://gitlab.com/lilypond/lilypond/-/merge_requests/842, and it is not a problem with span bars specifically but spanners in general).

  • How am I supposed to extract the syntax of "out-of-the-box parenthesizing spanners" from a merge request? Is it supported in LilyPond 2.22.1?
    – facetus
    Commented Aug 5, 2021 at 6:17
  • A merge request is a proposed change to the source code by a developer, namely me in this case. The merge request was just merged (i.e. accepted). So, in the next version that will be released (2.23.4), you will be able to parenthesize hairpins with just \parenthesize\< without needing this Scheme function. Commented Aug 5, 2021 at 21:14
  • I know what a merge request is. I am just puzzled, why I need a link to it.
    – facetus
    Commented Aug 6, 2021 at 6:25

This is a very "low tech" fix (it maybe even is worthy of the name "kludge") but what about fooling with the spacer rests in the dynamics context?

dynamics = {
    s8 s8 s8 \parenthesizedHairpin s8 \> s8 s8 s16 s32 s64 \! s64 s8 |
  • It will do. Meanwhile, I started reading the Scheme tutorial.
    – facetus
    Commented Jul 30, 2021 at 16:46
  • I don't know which Scheme tutorial you're using, but this is a good place to start with extending LIlyPond once you know the basics.
    – ksnortum
    Commented Jul 31, 2021 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.