Beauty contests (Essay on automated music engraving)

#### Beauty contests

How do we actually make formatting decisions? In other words, which of the three configurations should we choose for the following slur?

There are a few books on the art of music engraving available. Unfortunately, they contain simple rules of thumb and some examples. Such rules can be instructive, but they are a far cry from an algorithm that we could readily implement in a computer. Following the instructions from literature leads to algorithms with lots of hand-coded exceptions. Doing all this case analysis is a lot of work, and often not all cases are covered completely:

(Image source: Ted Ross, The Art of Music Engraving)

Rather than trying to write detailed layout rules for every possible scenario, we only have to describe the objectives well enough that LilyPond can judge the attractiveness of several alternatives. Then, for each possible configuration we compute an ugliness score and we choose the least ugly configuration.

For example, here are three possible slur configurations, and LilyPond has given each one a score in ‘ugly points’. The first example gets 15.39 points for grazing one of the noteheads:

The second one is nicer, but the slur doesn’t start or end on the note heads. It gets 1.71 points for the left side and 9.37 points for the right side, plus another 2 points because the slur ascends while the melody descends for a total of 13.08 ugly points:

The final slur gets 10.04 points for the gap on the right and 2 points for the upward slope, but it is the most attractive of the three configurations, so LilyPond selects this one:

This technique is quite general, and is used to make optimal decisions for beam configurations, ties and dots in chords, line breaks, and page breaks. The results of these decisions can be judged by comparison to real engravings.

#### Essay on automated music engraving v2.26.0 (stable-branch).

- 1 Music engraving
  - 1.1 The LilyPond story
  - 1.2 Engraving details
    - Music fonts
    - Optical spacing
    - Ledger lines
    - Optical sizing
    - Why work so hard?
  - 1.3 Automated engraving
    - Beauty contests
    - Improvement by benchmarking
    - Getting things right
  - 1.4 Building software
    - Music representation
    - What symbols to engrave?
    - Flexible architecture
  - 1.5 Putting LilyPond to work
  - 1.6 Engraved examples (BWV 861)
- 2 Literature list
  - 2.1 Short literature list
  - 2.2 Long literature list
- Appendix A GNU Free Documentation License
- Appendix B Index