Last week I wrote about a new edition of Saint-Saëns’ famous “Swan” for which I prepared a new piano arrangement. In the closing of the article I showed the exception to the rule, namely an issue where LilyPond did not serve me well right from the start, with this example of particularly ugly horizontal spacing:
Of course there is a piano part in addition to that cello line, but nevertheless it seemed more than strange that LilyPond should be doing that badly, and I had to find a solution (and more urgently, a cause) for the issue. As it turned out, my spacing issue is an ugly side-effect of a major LilyPond strength: optical spacing. Today I will show you in some detail what this is about – and why it is a limitation in this special case.
LilyPond works very hard to avoid the mechanical appearance of many computer-engraved scores, actually this has been of the main incentives to create the program in the first place. One of the “secrets” of LilyPond’s outstanding readability and “vintage” appearance is the technique of optical spacing. The horizontal position of notes (and other items) is not only calculated through mathematical proportions of their rhythmic value, instead other factors such as the actual outline with remaining whitespace or the perceived weight of objects are taken into account as well.
Looking closely at the right hand of the piano one can see that the semiquavers are spaced out technically irregularly (consider the absolute distance between adjacent stems) but appearing extremely balanced:
While the second and third notes of each group have stems next to their left side there is some empty (or “white”) space to the left of the fourth note. In order to produce a balanced impression LilyPond now pulls the fourth note slightly to the left, as if that empty space had some gravity. This is a somewhat similar approach to what kerning does in text typography and something that a hand engraver would do as well. It is interesting to compare that with output from other programs, Sibelius, SCORE and Amadeus. While the notes are spaced “perfectly“ in these programs they look irregularly because the white space between the third and fourth notes has more weight than the one before the third note.
This may seem like a tiny detail, and you may ask why this should matter. But this sort of microtyphography really makes a difference and is one of the reasons why LilyPond scores are so beautiful by default. I can tell you from experience that this difference has direct impact on the readability of the music on the music stand and therefore also affects the actual performance. It is well worth (re-)reading the chapters in LilyPond’s introductory essay on Engraving Details and The LilyPond Story on LilyPond’s website.
So obviously LilyPond is doing “The Right Thing” for that right hand, and in a way it really provides the best result of the competition. But unfortunately it is obviously not the appropriate approach for the whole score, as it causes an unacceptable irregularity in the quavers of the left hand and the cello part. LilyPond should have realized (or been told to do so) that the spacing of the slower notes is more important than that of the faster figuration, and acted accordingly. If you compare LilyPond’s default engraving with solutions by Durand (1886) and Henle (2009) you can see that both publishers prioritize the quavers’ spacing over the semiquavers. But while Henle doesn’t show any optical spacing at all (well, presumably their notation program doesn’t know what this is) the hand-engraved Durand score slightly shifts the fourth semiquaver to the left, leaving more space to the right. The oldest rendering is definitely the best, preserving both regular quavers and optical spacing, while that resulting extra space between the groups even supports the structure and helps the eye.
Fortunately LilyPond can use the same approach as Henle, which is as simple as inserting
\override Score.SpacingSpanner.uniform-stretching = ##t in a stylesheet:
Do you realize how great that is? LilyPond does not only have a spacing engine that is clearly superior to the competition but it also provides a trivial switch to deactivate it when not appropriate! Do you think one of the other mentioned programs can deliver this? If I’m not mistaken they don’t even have a notion at all of a thing like optical spacing, let alone the option to conveniently switch back and forth between the modes.
But while I’m pretty happy with the rendering of this measure now our journey isn’t over yet. The lack of advanced features makes the competition produce better default results in this case – and that constellation isn’t really extravagant, so LilyPond should actually do better than this. What we need and would want LilyPond to do by default is Durand’s solution: space the quavers regularly but still apply optical improvements to the semiquavers. Or put the other way round: perform that optical spacing magic but notice when side-effects should limit its effect. As LilyPond isn’t able to do that yet we have opened a feature request, but this is probably a pretty involved task and can’t be expected to be implemented very soon. So for now I will have to look for an interim solution that doesn’t get too hacky and is somewhat future-proof. In the third and last part of this series I will demonstrate a number of techniques of separating content from presentation that will hopefully achieve that goal.