5.4.10 Modifying stencils

All layout objects have a stencil property which is part of the grob-interface. By default, this property is usually set to a function specific to the object that is tailor-made to render the symbol which represents it in the output. For example, the standard setting for the stencil property of the MultiMeasureRest object is ly:multi-measure-rest::print.

The standard symbol for any object can be replaced by modifying the stencil property to reference a different, specially-written, procedure. This requires a high level of knowledge of the internal workings of LilyPond, but there is an easier way which can often produce adequate results.

This is to set the stencil property to the procedure which prints text – ly:text-interface::print – and to add a text property to the object which is set to contain the markup text which produces the required symbol. Due to the flexibility of markup, much can be achieved – see in particular Graphic notation inside markup.

The following example demonstrates this by changing the note head symbol to a cross within a circle.

XinO = {
  \once \override NoteHead.stencil = #ly:text-interface::print
  \once \override NoteHead.text = \markup {
    \combine
      \halign #-0.7 \draw-circle #0.85 #0.2 ##f
      \musicglyph "noteheads.s2cross"
  }
}
\relative {
  a' a \XinO a a
}

[image of music]

Any of the Feta glyphs used in the Emmentaler font can be supplied to the \musicglyph markup command – see The Emmentaler font.

EPS files and Postscript commands can both be inserted inline using the \epsfile and \postscript markup commands respectively – see Graphical markup.

See also

Notation Reference: Graphic notation inside markup, Formatting text, Text markup commands, The Emmentaler font, Graphical markup.


LilyPond Notation Reference v2.25.21 (development-branch).