This returns a pair of extents, and the difference of the cdr and car is the width. This works great, but requires one to have the 'layout' and 'props' context, which one does not inside a music function. Is there some way to combine the two approaches? Or another way to get the width of a markup?
Some background: I'm working on a piece that includes narration. This is notated in the score with a full measure rest and some text above the staff. I need to give the rest enough horizontal space that the text doesn't collide with other objects. I'm already using \textLengthOn, but this isn't quite enough when there is a rehearsal mark on the barline before or after the narration. In this case Lilypond frequently places the rehearsal mark above the text, which looks unsightly (see  for an example image). I did try setting the text's outside-staff-priority equal to that of the RehearsalMark (1500), but this doesn't appear to change anything. My current idea is to add extra space to the rest, using X-extent or some such, so that the bar is a little wider than the text and gives the rehearsal mark space to fall down to its normal height. However, I'd certainly welcome suggestions for other ways to attack the problem!