lilypond-user
[Top][All Lists]
Advanced

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

Re: Highlighting lyric words


From: Aaron Hill
Subject: Re: Highlighting lyric words
Date: Wed, 24 Apr 2024 20:21:03 -0700

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

Attachment: highlight.cropped.png
Description: PNG image


reply via email to

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