Maybe it would be possible to refine harm's function (which at the moment uses stencil-with-color, which simply puts a color-selection command in front of the stencil expression as far as I can see) so that it walks through the page stencil expression and turns any explicit "white" into the selected background color. That could work, but it would mess up any construction where white is being used in a non-background meaning (i.e. for some rehearsal mark with white-on-black design) - which would probably be acceptable as a first approximation.

I just tested this approach: This is possible, but please don't use my terrible proof-of-concept hack (which misses, at the very least, a call to normalize-color which I couldn't make available in \paper, and a thorough cleaning up of the recursion logic) in production work.

\version "2.24.0"

\paper {
  background-color = #(x11-color "gray20")
  print-color = "ivory"

  #(define (page-post-process layout pages)
     (let ((print-color (ly:output-def-lookup $defaultpaper 'print-color #f))
           (background-color
            (ly:output-def-lookup $defaultpaper 'background-color #f)))

       (define (de-white-stencil-expr expr)
         (if (pair? expr)
             (begin
              (if (eq? (car expr) 'color)
                  (if (equal? (cadr expr) white)
                      (set-car! (cdr expr) background-color)))
              (cons (de-white-stencil-expr (car expr))
                    (de-white-stencil-expr (cdr expr))))
             expr))

       (for-each
        (lambda (page)
          (let* ((page-stencil (ly:prob-property page 'stencil))
                 (X-ext (ly:stencil-extent page-stencil X))
                 (Y-ext (ly:stencil-extent page-stencil Y)))
            (set! (ly:prob-property page 'stencil)
                  (if (not background-color)
                      (stencil-with-color page-stencil print-color)
                      (ly:stencil-add
                       (stencil-with-color (make-filled-box-stencil X-ext Y-ext)
                                           background-color)
                       (stencil-with-color
                        (ly:make-stencil
                         (de-white-stencil-expr (ly:stencil-expr page-stencil))
                         X-ext
                         Y-ext)
                        print-color))))))
        pages)))
}

\layout { }

\markup { Here’s an example of \override #'(color . "green") \whiteout \line { whiteout in markup. } }

{ \override Staff.TimeSignature.whiteout = ##t 1 } \addlyrics { test }

Lukas

Reply via email to