lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Access the first/last line of a markup


From: Urs Liska
Subject: Re: Access the first/last line of a markup
Date: Wed, 13 Mar 2019 09:34:09 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1


Am 12.03.19 um 15:10 schrieb Urs Liska:
Hi Aaron,

thank you for this example.

Am 11.03.19 um 17:20 schrieb Aaron Hill:
On 2019-03-11 2:49 am, Urs Liska wrote:
Hi,
...

A *hack* using transparent glyphs to force alignment:

%%%%
\version "2.19.82"

#(define-markup-command (ascender-descender-placeholder layout props) ()
  (let* ((sten (interpret-markup layout props #{
            \markup \transparent \overlay { d p } #} ))
         (yex (ly:stencil-extent sten Y)))
    (ly:make-stencil (ly:stencil-expr sten) empty-interval yex)))

#(define-markup-command (apply-hack layout props arg) (markup?)
  (interpret-markup layout props #{ \markup \concat {
    \ascender-descender-placeholder $arg } #} ))

bad = -\tweak color #(rgb-color 0.9 0 0) \etc
good = -\tweak color #(rgb-color 0 0.8 0) \etc

{ \time 3/4
  f'4\bad^"d" _"d" f'4\bad^"x" \bad_"x" f'4^"p" \bad_"p"
  f'4\good^\markup \apply-hack "d" _\markup \apply-hack "d"
  f'4\good^\markup \apply-hack "x" \good_\markup \apply-hack "x"
  f'4^\markup \apply-hack "p" \good_\markup \apply-hack "p"
  f'2.^\markup \override #'(line-width . 35) \wordwrap \apply-hack
    { raucous racoon commune consume cocoa-cream macaroons }
  _\markup \override #'(line-width . 35) \wordwrap \apply-hack
    { museum owner unaware wax moose wears mauve mascara }
}
%%%%

This presumes that "d" and "p" are suitable exemplars of ascenders and descenders in the font being used.

If you want to visualize what is happening, replace "\transparent" in the markup command definition with something like "\with-color #blue".


Actually I don't find this that hacky, and it seems to do exactly what I want. I just have to integrate it into a different context, which didn't work out at the first attempt ...


Well, I *thought* I'd managed to integrate it in my project infrastructure, but as often the devil is in the details.

The solution works only if \apply-hack is basically the last markup command:

% This works
\markup \column \apply-hack { a column }
% but not this
\markup \apply-hack \column { a column }

In the first example the placeholder is overlaid over *every* column (or word in a \wordwrap context), but in the second example it is only attached to the *first* element.

The problem is that I have a function that takes markup? arguments - which of course may include all sorts of markup constructs. I have no idea how I could solve this. I'm afraid I would have to somehow parse the markup? argument recursively and use \apply-hack on *every* sub-element of the markup.

Well, I'll try further to get to grips with how markups are handled ...

Urs



Best
Urs


_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user

reply via email to

[Prev in Thread] Current Thread [Next in Thread]