jperon / lyluatex

Alternative à lilypond-book pour lualatex
MIT License
58 stars 12 forks source link

Discuss the alignment of scores to the text area #36

Closed uliska closed 6 years ago

uliska commented 6 years ago

Now that #31 has been merged lyluatex applies protrusion and correctly determines the correct line width. But this raises further questions, on a typographical, technical, and interface level. Attached is a detailed PDF* demonstrating the issues. The questions to be discussed in order to allow further development are (additions welcome):

*(the source code used to produce this can be found as test-alignment.tex)

uliska commented 6 years ago

In absence of discussion I think I'll start with one part:

rpspringuel commented 6 years ago

Having finally had a chance to look at this, here are my comments:

protrusion should not be a yes/no property, but rather a max amount, and probably two of them (left and right). Elements which extend beyond the ends of the staff lines are allowed to extend into the margin by up to given maximum. If they're larger than that, then the line width should be shrunk so that the score fits within the available space (left protrusion + textwidth + right protrusion). If that takes a two pass system, then so be it. There are plenty of LaTeX packages that require multiple passes.

I would try to support package option, command, and keyword argument abilities for setting the protrusion.

I'm going to have to think about the shorter stuff some more.

uliska commented 6 years ago

protrusion should not be a yes/no property, but rather a max amount, and probably two of them (left and right).

Good point. I've just checked that it is possible to infer also the right "natural" protusion amount from the EPS file. One - minor - issue with this is that the bounding box LilyPond is written as integers (in points), so there are rounding errors of +/- 0.5pt (= +/- 0.18mm). This is not much but still not ideal ...

It will take a two-pass system, but as you say that's OK. However, I suggest to have a way to avoid that check. It may be desirable to always have the staff lines align with the text and do arbitrary protrusion (i.e. the author has to ensure that margin text aren't too long). This may either be through yet another option or some special value. For example:

max-protrusion could have a default behaviour of 50% of the current margins.


When the line-width is set to be less than the available line width protrusion should be calculated from that given line width, and not from the available line width because multiple scores are also considered in relation to each other and not only to the text area. However, if the line is ragged because it contains less music protrusion should also only be limited if it reaches the border of the given line-width. I think the following is a good visualization:

Score protruding to 3 "units" left and 2 "units" right

Regular/unlimited protrusion

   ================
   |==============|
---xxxxxxxxxxxxxxxx--
   |==============|

Protrusion limited to 1 "unit" on both sides, shrinks score's line width

   ================
   |==============|
  ---xxxxxxxxxxxxx--
   |==============|

Protrusion limited to 1 "unit" on both sides, but line isn't filled (8 "units"),
protrusion doesn't have any effect.

   ================
    ---xxxxxxxx--
   ================

line-width set to 8 "units", line filled completely.
Unlimited and limited protrusion.
First and fourth score have protrusion that naturally fits into the limits

   ================
      -xxxxxxxx
   ====|======|====
    ---xxxxxxxx--
   ====|======|====
      ---xxxxx--
   ====|======|====
      -xxxxxxxx
   ====|======|====
jperon commented 6 years ago

Just a point about that, when you implement it : make sure the protrusion is taken in account in the temporary file name, either by modifying line-width before calling hash_output_filename, or by adding it to the name. Otherwise, if one changes this option, the score won't get recompiled.

rpspringuel commented 6 years ago

However, I suggest to have a way to avoid that check. It may be desirable to always have the staff lines align with the text and do arbitrary protrusion (i.e. the author has to ensure that margin text aren't too long). This may either be through yet another option or some special value.

The check itself won't be terribly costly in terms of time or computational resources, so I'm don't think there is any real need to avoid it. All that's needed is the ability to avoid the second pass, which the user can do by simply set the max amount to a ridiculously large amount, there is no need for the package to specially handle it.

The other thing that could be done is to work out the procedure so that a single pass of LuaLaTeX only ever invokes a single pass of LilyPond. The information needed to determine the parameters are written to the aux file so that a second pass of LuaLaTeX has access to that information and makes the adjustments to the run of LilyPond. In this case if a second pass is needed, the first pass should raise a warning indicating such (with the wording chosen so that latexmk can see it).

Further, the negative protrusion values could, effectively, be "indentation" of the score. We probably don't want to do things that way, but I thought I should point out what the likely behavior is if we don't check explicitly for negative values.

When the line-width is set to be less than the available line width protrusion should be calculated from that given line width, and not from the available line width because multiple scores are also considered in relation to each other and not only to the text area.

That's a given. Sorry if my previous comments said otherwise.

uliska commented 6 years ago

Also consider lilypond-book options. https://github.com/jperon/lyluatex/issues/72

uliska commented 6 years ago

@jperon I don't quite understand how protrusion is supposed to work as you have implemented it:

  1. as @rpspringuel pointed out "protrusion" should not be an absolute value but a “max” protrusion amount
  2. currently it doesn't work properly at all:
    • when no protrusion is set the scores is aligned to the image border and the right edge sticks out into the margin
    • when a protrusion value is defined it is applied in the wrong direction.

I'd actually rewrite the functionality from scratch, using max-protrusion as the option name, but I'd wanted to first ask about your original intentions.

jperon commented 6 years ago

I didn't think about protrusion as something definitive anyway, but only "touched" it to enhance the behaviour of fragments: feel free to change it as you like, as I think you have a better insight on it than I do.

uliska commented 6 years ago

OK, I'll see where I'll get to. I think this is the last major issue before we can do a release. So apart from that area we'll have to complete the manual and then go through it quite thoroughly to see if all the descriptions are correct in the first place and if they are still up-to-date with the current behaviour.

I suggest we first complete the manual and then ask a few people to test the package together with the manual.

uliska commented 6 years ago

OK, I've once more skimmed through the document that is attached to this issue's initial description and also through the discussion. Here's what I think I'll implement:

I think all this is not complicated and can easily be implemented. The only thing I'm not fully clear about is the process of re-compiling if max-protrusion is exceeded by a score. I'll have to think about it when I'm at that point. I'm not sure what is more complicated: implementing an instant LilyPond-re-run or an auxiliary file approach that will hook into the next LaTeX run.