Am Mi., 30. Juli 2025 um 17:11 Uhr schrieb Rip _Mus
<ripetizioni.mus...@gmail.com>:
>
> Hello,
> about markup, is there a solution similar \fill-line but for the Y axis? I'm 
> trying to perfectly center a markup on a page.
>
> Thank you,
> RipMus

\fill-line does not know what is to left (or right) of it.
See:
\markup \column {
  \line { \box \fill-line { foo bar buzz } }
  \line { fooooooooooo \box \fill-line { foo bar buzz } }
}

If you're fine with similar behaviour for Y-axis, then:

#(define
  (justify-column-helper
    layout props args text-direction word-space column-height constant-space?)
  (let* ((orig-stencils (interpret-markup-list layout props args))
         (stencils
          (map (lambda (stc)
                 (if (ly:stencil-empty? stc Y)
                     (ly:make-stencil (ly:stencil-expr stc)
                                      (ly:stencil-extent stc X) '(0 . 0))
                     stc))
               orig-stencils))
         (text-widths
          (map (lambda (stc)
                 (interval-length (ly:stencil-extent stc Y)))
               stencils))
         (text-width (apply + text-widths))
         (word-count (length stencils))
         (top-margin (ly:output-def-lookup layout 'top-margin 0))
         (bottom-margin (ly:output-def-lookup layout 'bottom-margin 0))
         (paper-height (ly:output-def-lookup layout 'paper-height))
         (last-bottom-padding
           (assoc-get 'padding
                      (ly:output-def-lookup layout 'last-bottom-spacing) 0))
         (top-markup-padding
           (assoc-get 'padding
                      (ly:output-def-lookup layout 'top-markup-spacing) 0))
         (column-height
           (or column-height
               (- paper-height
                  top-margin
                  bottom-margin
                  top-markup-padding
                  last-bottom-padding)))
         (fill-space
          (cond
           ((= word-count 1)
            (list
             (/ (- column-height  text-width) 2)
             (/ (- column-height  text-width) 2)))
           ((= word-count 2)
            (list
             (- column-height  text-width)))
           (else
            ((@@ (lily) get-fill-space)
             word-count column-height word-space text-widths
             constant-space?))))
         (column-contents (if (= word-count 1)
                              (list
                               point-stencil
                               (car stencils)
                               point-stencil)
                              stencils)))
    (if (null? (remove ly:stencil-empty? orig-stencils))
        empty-stencil
        (begin
          (if (= text-direction DOWN)
              (set! column-contents (reverse column-contents)))
          (set! column-contents
                (stack-stencils-padding-list
                 Y DOWN fill-space column-contents))
          (if (> word-count 1)
              (set! column-contents
                    (ly:stencil-translate-axis
                     column-contents
                     (- (car (ly:stencil-extent (car stencils) Y)))
                     Y)))
          column-contents))))

#(define-markup-command (fill-column layout props args)(markup-list?)
  #:properties ((text-direction DOWN)
                (word-space 0)
                (column-height #f))
  (justify-column-helper
     layout props args text-direction word-space column-height #t))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\paper { tagline = ##f }

%\header { title = "TITLE" subtitle = "SUBTITLE" }

\markup
  \override #'(box-padding . 0)
  \box
  \fill-line {
    \fill-column
      \vcenter
      \override #'(box-padding . 8)
      \box
      \bold { foo bar buzz }
  }

Though, be warned, it's very easy to exceed the printed area (the \box
in the example already do so and a warning is issued).
To see more of it set tagline ##t or uncomment the \header.
I see no way how a markup-command could get the remaining space on a
page to fit in that space.

Cheers,
  Harm

Reply via email to