5.5.3 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 c'' {
  a a \XinO a a
}

[image of music]

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

See also

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


Other languages: deutsch, español, français, italiano, 日本語.
About automatic language selection.

LilyPond — Notation Reference v2.18.2 (stable-branch).