[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lilypond-user
Subject:    Re: Highlighting lyric words
From:       Walt North <waltnorth () gmail ! com>
Date:       2024-04-25 15:37:19
Message-ID: faf385bd-1281-4502-b862-e1cf2a7fa088 () gmail ! com
[Download RAW message or body]

Thanks, that does seem to work at least in a small test case.  I saved 
the function off to an include file and will try it on a larger set of 
lyrics later.  It does seem like a bit of work to do something that 
could a base lilypond feature since it would seem like background 
highlighting of some words in lyrics wouldn't be that uncommon.  That 
type of feature is currently available for staff notes.

Thanks for the help.

Walt

On 4/24/2024 8:21 PM, Aaron Hill wrote:
> On 2024-04-24 4:05 pm, Walt North wrote:
>> Thanks, that's close enough to what I wanted.  I was originally for 
>> yellow background with back letters... but red (or other bright) font 
>> will suffice.
>
>
> Here is an (over-engineered and probably bug-ridden) approach:
>
> %%%%
> \version "2.25.13"
>
> #(define-markup-command
>   (highlight layout props arg) (markup?)
>   #:category other
>   #:properties ((blot 0.2)
>                 (color yellow)
>                 (padding 0.2))
>   (let* ((stencil (interpret-markup layout props arg))
>          (strut (interpret-markup layout props
>                   #{ \markup qxb #}))
>          (x-extent (ly:stencil-extent stencil X))
>          (y-extent (interval-union
>                      (ly:stencil-extent stencil Y)
>                      (ly:stencil-extent strut Y)))
>          (x-extent-wide (interval-widen x-extent padding))
>          (y-extent-wide (interval-widen y-extent padding)))
>     (interpret-markup layout props #{
>       \markup \combine
>         \with-color #color
>           \with-dimensions #x-extent #y-extent
>           \filled-box #x-extent-wide #y-extent-wide #blot
>         \stencil #stencil
>     #})))
>
> #(define (highlighter blot color padding)
>   (grob-transformer 'stencil
>     (lambda (grob orig)
>       (grob-interpret-markup grob #{
>         \markup
>           \override #`(blot . ,blot)
>           \override #`(color . ,color)
>           \override #`(padding . ,padding)
>           \highlight \stencil #orig
>       #}))))
>
> \markup {
>   \pad-around #1
>   \override #'(blot . 1.5)
>   \override #`(color . ,(x11-color 'orange))
>   \override #'(padding . 0.5)
>   \highlight \line { \bold lorem \italic ipsum }
> }
>
> myHighlight = \override LyricText.stencil =
>   #(highlighter 0.6 (x11-color 'cornflowerblue) 0.1)
>
> \paper { indent = 0 }
> { \repeat unfold 3 { b'4 4 2 } }
> \addlyrics {
>   no high -- light
>   \myHighlight high --
>   \tweak font-family #'sans
>   \tweak font-series #'bold
>   light -- er
>   \undo \myHighlight none
>   \once \myHighlight once
>   done
> }
> %%%%
>
>
> -- Aaron Hill

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic