Hi James, This comes up so frequently it puzzles me why it is not considered for addition to the lilypond baseline.
Here's my function. Andrew === snip \version "2.19.39" % Annotation bracket with centred text. % Andrew Bernard and Thomas Morley TextSpannerCentredText = #(define-music-function (text extra-length) (string? pair?) "Use TextSpanner semantics to create spanner brackets with centred text" #{ \once \override TextSpanner.after-line-breaking = #(lambda (grob) (let* ( ;; get stencil of grob (stil (ly:grob-property grob 'stencil)) ;; get spanner length (spanner-len (interval-length (ly:stencil-extent stil X))) ;; make stencil from text arg (text-stil (grob-interpret-markup grob (markup #:sans #:upright text))) ;; get text length (text-len (interval-length (ly:stencil-extent text-stil X)))) ;; if text length exceeds the spanner length we cannot really proceed. ;; do nothing - make an ordinary text spanner and warn. (if (>= text-len spanner-len) (begin (ly:warning "text length longer than spanner") #f ) (let* ( ;; get direction, up or down (dir (ly:grob-property grob 'direction)) ;; some padding (padding 1) ;; line thickness (thickness 0.25) ;; extra length on left, negative values shorten (left-ext (car extra-length)) ;; extra length on right, negative values shorten (right-ext (cdr extra-length)) ;; calculate length considering text length (path-part-len (/ (- spanner-len text-len) 2)) ;; make left bracket stencil (path-left-part-stil (make-path-stencil `( moveto ,(- left-ext) ,(* -1 dir) lineto ,(- left-ext) 0 lineto ,path-part-len 0 ) thickness 1 1 #f)) ;; make right bracket stencil (path-right-part-stil (make-path-stencil `( moveto ,(+ path-part-len right-ext) ,(* -1 dir) lineto ,(+ path-part-len right-ext) 0 lineto 0 0 ) thickness 1 1 #f)) ;; make complete stencil combining left and right parts ;; and text (full-stil (stack-stencils X RIGHT padding (list path-left-part-stil (centered-stencil text-stil) path-right-part-stil))) ) ;; set grob stencil to fully constructed stencil (ly:grob-set-property! grob 'stencil full-stil) )))) #} ) { c' d' ees' fis' \once \override TextSpanner.direction = #DOWN \TextSpannerCentredText "6\"" #'(0 . 0) g' \startTextSpan a' bes' c'' \stopTextSpan \TextSpannerCentredText "x3" #'(2 . 1) bes'\startTextSpan a' g' c'\stopTextSpan \TextSpannerCentredText "x3" #'(2 . 3.5) c''1\startTextSpan c''1\stopTextSpan \break c''1\startTextSpan c''1\stopTextSpan } === snip _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user