Hello William,

the problem here is that a markup may depend on the context it is rendered in. 
For example if you change font size or even font for Staff.InstrumentName then 
the dimensions of the stencil will change.

You can of course render the markup using some "default" settings, as long as 
you make sure these do not change a lot. Once you have a stencil you can 
extract dimensions.

#(display (ly:stencil-extent (interpret-markup $defaultpaper '(()) "test") X))

or with 2.25

#(display (ly:stencil-extent (interpret-markup $defaultpaper (list (ly:output-
def-lookup $defaultpaper 'property-defaults)) "test") X))

I’ve recently posted a thought to the list (which did not get any replies) 
about whether we could actually use the break-alignment interface to allow for 
things like automatic indent (this also matter in case short instrument names 
change).

So your code could do:

version = "2.25.13"

pref = \markup { piece title here longer }

pref_width = #(interval-length
               (ly:stencil-extent
                (interpret-markup
                 $defaultpaper
                 (list (ly:output-def-lookup $defaultpaper 'property-
defaults))
                 pref)
                X))

extra_pad = #(ly:cm 0.5)

\markup \pref
\markup\stencil #(interpret-markup
                 $defaultpaper
                 (list (ly:output-def-lookup $defaultpaper 'property-
defaults))
                 pref)

\score {
   \new Staff \with {instrumentName = \pref } {c'1 \break c'1 }
}

\layout {
   % Indent is in mm, pref_width is in staff spaces (default 1.75mm (7mm / 4)).
   % Adjust by fontsize if staffsize changes
   indent = #(+ (* 1.75 pref_width) extra_pad)
}

Cheers,
Valentin

Am Mittwoch, 5. Juni 2024, 03:15:24 MESZ schrieb William Rehwinkel via 
LilyPond user discussion:
> Dear list,
> 
> In the following example, I am wondering how I can find the measurements 
> of the dimensions, specifically the width, of a markup object. This is 
> so I can automatically indent the first line by the length of the 
> instrumentName.
> 
> Thanks,
> -William
> 
> % --------------------
> \version "2.25.7"
> 
> pref = \markup { piece title here }
> 
> % How can I determine this from the width of \pref
> pref_width = #(ly:inch 1)
> 
> extra_pad = #(ly:cm 0.5)
> 
> \score {
>    \new Staff \with {instrumentName = \pref } {c'1 \break c'1 }
> }
> 
> \layout {
>    #(define indent (+ pref_width extra_pad))
> }
> % --------------------
> 
> -- 
> William Rehwinkel (any pronouns)
> Juilliard School '26 - Oberlin Conservatory '24
> will...@williamrehwinkel.net - https://williamrehwinkel.net
> PGP Public Key: https://ftp.williamrehwinkel.net/pubkey.txt

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to