On 2020-12-10 3:35 pm, Valentin Petzel wrote:
Hello,

I’m trying to calculate the width of a InstrumentName markup to automatically set the indent. Some time ago I somewhat managed to do an interpretMarkup by
looking up layout and parser, but I cannot remember, how I did it.

So maybe someone of you guys has a decent way of doing this?

This seems to work:

%%%%
\version "2.20.0"

measureMarkup =
#(define-scheme-function
  (axis text)
  ((number? X) markup?)
  (let* ((layout (ly:parser-lookup '$defaultpaper))
         (props (ly:output-def-lookup layout 'text-font-defaults))
         (sten (interpret-markup layout (list props) text)))
    (* (interval-length (ly:stencil-extent sten axis))
       (ly:output-def-lookup layout 'staff-space))))

foo = \markup \box \pad-x #2 \italic "Lorem ipsum"
\paper { indent = \measureMarkup \foo }
\new Staff \with { instrumentName = \foo }
{ \repeat unfold 16 { b'4 4 2 } \bar "|." }
%%%%


-- Aaron Hill

Reply via email to