lilypond-user
[Top][All Lists]
Advanced

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

Re: automatic line-breaking in markup


From: Thomas Morley
Subject: Re: automatic line-breaking in markup
Date: Wed, 3 Feb 2016 23:43:10 +0100

2016-02-03 19:40 GMT+01:00 Simon Albrecht <address@hidden>:
> On 03.02.2016 19:24, Jonathan Scholbach wrote:
>>
>> I want to create a template for a cover page. I do that by redefining
>> bookTitleMarkup. The title of the piece is stored as string in a variable
>
>
> If there’s no particular need for that, I’d use a normal header block and
> \fromproperty.
>
>> and I want to print it relatively tall on the cover page. It works.
>> But sadly when the title is too long it runs off the page, because
>> LilyPond does not automatically break the line. How can I get LilyPond to
>> break the line automatically when the title runs off page?
>
>
> Try this:
>
> %%%%%%%%%%%%%%
> \version "2.19.22"
>
> \paper {
>   bookTitleMarkup = \markup {
>     \fontsize #15 \wordwrap-field #'header:title
>   }
> }
>
> \book {
>   \header {
>     title = "Many many words may result in a title that is too long for one
> line"
>   }
>   \relative c' { c d e f }
> }
> %%%%%%%%%%%%%%%
>
> I don’t know how to center-align the wrapped lines, though… Anyone?
>
> Best, Simon



/wordwrap-field puts out a single stencil. You can't align the lines
you see after the stencil is created. At least you wouldn't want ...
;)

How about below, description should make clear what's happening (hopefully).

#(define-markup-command (my-wordwrap-field layout props align symbol)
  (number? symbol?)
  #:properties ((baseline-skip))
  #:category align
  "Same as @code{wordwrap-field}, but internally a stencil-list is produced
first, which will aligned according to @var{align}, putting out a single
stencil."

  ;; c/p from define-markup-commands.scm, because it's not public
  (define (general-column align-dir baseline mols)
    "Stack @var{mols} vertically, aligned to  @var{align-dir} horizontally."
    (let* ((aligned-mols
             (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
           (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
           (stacked-extent (ly:stencil-extent stacked-stencil X)))
      (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X)))

  (let* ((m (chain-assoc-get symbol props)))
    (if (string? m)
        (general-column
          align
          baseline-skip
          (wordwrap-string-internal-markup-list layout props #f m))
        empty-stencil)))


\paper {
  bookTitleMarkup = \markup \fill-line {
    \fontsize #15 \my-wordwrap-field #CENTER #'header:title
  }
}

\header {
  title = "Many many words may result in a title that is too long for one line"
}
\relative c' { c d e f }


HTH,
  Harm



reply via email to

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