5.3.3 Length and thickness of objects

Distances and lengths in LilyPond are generally measured in staff spaces, i.e., the distance between adjacent lines in the staff (or occasionally half staff spaces), while most thickness properties are measured as multiples of the current staff-line thickness (which is given by the thickness property of the StaffSymbol grob). For example, by default, the lines of hairpins are given a thickness of 1 unit of the staff-line thickness, while the thickness of a note stem is 1.3 units. Note, though, that some thickness properties are different; for example, the thickness of beams is controlled by the value of the beam-thickness property, which is measured in staff spaces.

So how are lengths to be scaled in proportion to the font size? This can be done with the help of a special function called magstep provided for exactly this purpose. It takes one argument, the change in font size (value -2 in the example above) and returns a scaling factor suitable for reducing other objects in proportion. The trick is now not to actually change the lengths of stems and other grobs but to rather change the unit on which the length values are based – it is the staff-space property of the StaffSymbol grob.

\new Staff ="main" {
  \relative {
    r4 g'8 g c4 c8 d |
    e4 r8
    <<
      { f8 c c }
      \new Staff \with {
        alignAboveContext = "main"
        \omit Clef
        \omit TimeSignature
        fontSize = -2
        % Reduce stem length and line spacing to match
        \override StaffSymbol.staff-space = #(magstep -2)
      }
      { f8 f c }
    >>
    r4 |
  }
}

[image of music]

While changing staff-space affects the scale of the ossia, it does not affect the horizontal spacing – this is determined by the layout of the main music in order to remain synchronized with it, so it is not affected by any of these changes in size. Of course, if the scale of all the main music were changed in this way then the horizontal spacing would be affected. This is discussed later in the layout section.

This, then, completes the creation of an ossia. The sizes and lengths of all other objects may be modified in analogous ways.

For small changes in scale, as in the example above, the thickness of the various drawn lines such as bar lines, beams, hairpins, slurs, etc., does not usually require global adjustment. If the thickness of any particular layout object needs to be adjusted this can be best achieved by overriding its thickness property. An example of changing the thickness of slurs was shown above in Properties of layout objects. The thickness of all drawn objects (i.e., those not produced from a font) may be changed in the same way.


LilyPond Learning Manual v2.25.20 (development-branch).