Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#3860 Improve spacing of \fill-line - user word length not just distribute along centers of objects


Originally created by: *anonymous

Originally created by: pkx1...@gmail.com
Originally owned by: david.na...@gmail.com

edited thread (taken from http://lilypond.1069038.n5.nabble.com/fill-line-while-respecting-natural-widths-td158967.html)

Reported initially by Mike Solomon

If I have

\markup \fill-line {
foooooooooooooo baaaar hi

The line will be filled irrespective of the widths of the elements, meaning
that the middle element will always be on the center of the page.


David Nalesnik said:

See the attached.  (I just changed a line or two of the definition of \fill-line from scm/define-markup-commands.scm.) Hopefully this gives you what you want!


Ed Gordjin

That's interesting, see the result of the two markups:

\version "2.18.0"

\markup \fill-line {
  This line has got even spaces, or is it a bit different?
\markup \fill-line-two {
  And this line has different spacing, it uses word length!

Is this a bug in the original \fill-line?


Mike Solomon:

It’s a feature - \fill-line evenly distributes the centers of objects along a line irrespective of their widths.


On 02/08/2014 11:22 PM, Kieren MacMillan wrote:
> Hi David,
>> Hmm--do you think it should be added as an option to \fill-line?
> As just one example: I’m going to use it in the musical theatre scores I’m engraving right now, to [evenly] space two columns of dialogue above a system of underscore music.
> But maybe it should be its own separate function, e.g., \spaced-line, or some such thing?

Alexander Kobel said:

Agreed.  What about \equispaced-line?

The rationale for \fill-line IMHO is only to be used for one, two or
three arguments, which is the common case in headings.  One for
center-aligned (which should be available as \center-line on it's
own...), two for left-right-aligned, three for
left-center-right-aligned.  That's it.  Everything else gives highly
unintuitive results.  It's the analogue of one of the rare features I
miss in OpenOffice vs. Word:  In the latter, you can specify the
horizontal alignment for groups of words in a single line, separated by
\fill-line might not be the best name for that, but it's late to change
it.  (\equicentered-line?  Leftmost and rightmost element don't fit in,
though...)  And it's description is really bad, now that I read it again...
BTW, I'd like to see collision avoidance there (and there should be a
comment in the code on what's necessary), but probably it's overkill for
what it's used for.

On the other hand, especially for two-column-dialogues or verses, I
always end up to use manually spaced columns:  I want a consistent
column separation, I (usually) want columns of consistent width, and I
(usually) want the columns to start at the same horizontal position.  At
least if you have several of those places.  Then, it's almost no
difference whether you use \spaced-line (\equispaced-line?) or simply a
\fill-line (as \center-line) of $stuff to autocalculate left and right


1 Attachments


  • Originally posted by: david.na...@gmail.com

    Here's a proposal to enhance \fill-line by adding a property 'constant-space, set by default to #f.  This selects the familiar behavior: words spaced evenly by their X-centers and thus with variable whitespace.  The behavior Mike wanted would be selected by setting constant-space to #t.

    I like this option.  Even though there would be more typing involved, we save having yet another command (which is bound to have an odd name!) and avoid code duplication.

    What do you think?

    See attached file.

  • Originally posted by: janek.li...@gmail.com

    Hmm.  I think i have a slight preference for having two separate commands (they can use one function internally to avoid code duplication) - this would be more <strikeout>pythonic</strikeout> elegant imo.

    But either way will be fine as long as the enhancement makes it to official lily :)

  • Originally posted by: david.na...@gmail.com

    Re #2:

    That's fine by me.  I just worked something up.

    The issue I can foresee is the one which plagues all such discussions -- naming.

    I called the new command fill-line-constant-padding.  It's long, but cutting down on
    the letters might lead to confusion.

    In the attached I added "collision detection" so to speak.  The words won't come closer than word-space.  Look what happens when you run the string with \fill-line.

    Perhaps I should put this up as a patch once I check through it a bit more?

  • Originally posted by: janek.li...@gmail.com

    Please add "collision detection" to the "ordinary" \fill-line, that would be very nice :)

    Btw, i have just realized that what your function does is very similar to what \justify does - there may be a possibility for further code reuse.

    As for the names, i know it's hard - maybe just make a poll on -user.  My suggestion is \fill-line-evenly, but it's not very accurate.

    And, of course please put this as a patch!

  • Originally posted by: david.na...@gmail.com

    >>Please add "collision detection" to the "ordinary" \fill-line, that would be very nice :)

    I think that this would warrant a new issue--for documentation, but not for correction.  Collisions arise with \fill-line because of a misuse of the command: trying to stuff more into the line than can be accommodated.  To "fix" the problem, the only option would be to lengthen the line, and there you will probably spill off the side of the page with the default line length. I think perhaps that a warning should be put into the docs about overstuffing lines.

    In fact, I wonder if the correction I added shouldn't be removed for the above reason.

    >Btw, i have just realized that what your function does is very similar to what \justify does - there may be a possibility for further code reuse

    Nice idea, but I don't see how this can work since \justify will create multiple lines when spacing gets tight.  Really, though, I'm just adding a few lines :)

    >As for the names, i know it's hard - maybe just make a poll on -user.  My suggestion is \fill-line-evenly, but it's not very accurate.

    Isn't there some typesetting term that covers this situation, a verb? A LaTex command?  If there is, that's what it would be.

    Naming is the primary reason why something like
    \markup \override #'(constant-space . ##t) \fill-line { ... }
    makes a lot of sense to me.

    But I'm happy to put a patch up with a separate patch named anything you like, and let the fighting begin...

    What about \fill-line-even-space?  Can't imagine how you'd describe what the command does accurately with fewer characters, unless, as I say, there's some verb out there.

  • Originally posted by: david.na...@gmail.com


    But I'm happy to put a patch up with a separate *command* named anything you like, and let the fighting begin...

  • Originally posted by: david.na...@gmail.com


  • Originally posted by: janek.li...@gmail.com

    \justify-line seems perfect to me!
    as for the other things, I'm not really sure - please decide yourself (sorry no time to elaborate :( )

  • Originally posted by: david.na...@gmail.com

    Issue 3860: Add command \justify-line

    The command \fill-line spaces words taking word length into account
    such that the following distances are equal: outside edge of outside
    markup to center of adjoining markup; center to center of
    neighboring interior markups.  As a consequence, the space between
    words is unequal when the lengths of the markups vary and/or there
    are more than three markups in the line.

    The following patch creates the command \justify-line, which spaces
    markups to fill a line such that the space in between each pair is
    constant.  Collisions are prevented by ensuring that this distance
    does not fall below the current setting of word-space.


    Labels: Patch-new

  • Originally posted by: pkx1...@gmail.com

    Patchy the autobot says: passes make, make check and a full make docs.

    Labels: -Patch-new Patch-review

  • Originally posted by: pkx1...@gmail.com

    Patch on countdown for Feb 26th - 06:00 GMT

    Labels: -Patch-review Patch-countdown
    Owner: david.na...@gmail.com

  • Originally posted by: pkx1...@gmail.com

    Patch counted down - please push

    Labels: -Patch-countdown Patch-push

  • Originally posted by: david.na...@gmail.com

    Pushed as commit [rd3e856b31301bc6e67a13118ad432d22897d9f8b].

    Labels: -Patch-push Fixed_2_19_3
    Status: Fixed

  • Originally posted by: fedel...@gmail.com

    (No comment was entered for this change.)

    Status: Verified