Jump to content

Drawing boxes around grobs: Difference between revisions

From LilyPond wiki
m New category
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
The <code>print-function</code> can be overridden to draw a box around an arbitrary grob.
The <code>stencil</code> property can be overridden to draw a box around arbitrary grobs, either using <code>\override</code> or <code>\tweak</code>.


<lilypond version="2.24">
<lilypond version="2.24">
\relative c'' {
\relative c'' {
   \override TextScript.stencil =
   \once \override TextScript.stencil =
     #(make-stencil-boxer 0.1 0.3 ly:text-interface::print)
     #(make-stencil-boxer 0.1 0.3 ly:text-interface::print)
   c'4^"foo"
   c'4^"foo"


   \override Stem.stencil =
   \tweak Stem.stencil
     #(make-stencil-boxer 0.05 0.25 ly:stem::print)
     #(make-stencil-boxer 0.05 0.25 ly:stem::print)
  b8
  c4.^"bar" c4
   \override Score.RehearsalMark.stencil =
   \override Score.RehearsalMark.stencil =
     #(make-stencil-boxer 0.15 0.3 ly:text-interface::print)
     #(make-stencil-boxer 0.15 0.3 ly:text-interface::print)
  b8
 
  \revert Stem.stencil
  \revert Flag.stencil
  c4. c4
   \mark \default
   \mark \default
   c1
   c1
Line 23: Line 22:
[[Category:Editorial annotations]]
[[Category:Editorial annotations]]
[[Category:Tweaks and overrides]]
[[Category:Tweaks and overrides]]
[[Category:Scheme]]
[[Category:Included in the official documentation]]
[[Category:Included in the official documentation]]
[[Category:Snippet]]
[[Category:Snippet]]

Latest revision as of 06:46, 12 December 2025

The stencil property can be overridden to draw a box around arbitrary grobs, either using \override or \tweak.

\version "2.24"

\relative c'' {
  \once \override TextScript.stencil =
    #(make-stencil-boxer 0.1 0.3 ly:text-interface::print)
  c'4^"foo"

  \tweak Stem.stencil
    #(make-stencil-boxer 0.05 0.25 ly:stem::print)
  b8

  c4.^"bar" c4

  \override Score.RehearsalMark.stencil =
    #(make-stencil-boxer 0.15 0.3 ly:text-interface::print)
  \mark \default
  c1
}