4 \header { texidoc=" You can write stencil callbacks in Scheme, thus
5 providing custom glyphs for notation elements. A simple example is
6 adding parentheses to existing stencil callbacks.
8 The parenthesized beam is less successful due to implementation of the
9 Beam. The note head is also rather naive, since the extent of the
10 parens are also not seen by accidentals.
15 #(define (parenthesize-callback callback)
16 "Construct a function that will do CALLBACK and add parentheses.
19 \\property NoteHead \\override #'print-function
21 #(parenthesize-callback Note_head::print)
26 (define (parenthesize-stencil grob)
27 "This function adds parentheses to the original callback for
28 GROB. The dimensions of the stencil is not affected.
32 (fn (ly:get-default-font grob))
33 (pclose (ly:find-glyph-by-name fn "accidentals-rightparen"))
34 (popen (ly:find-glyph-by-name fn "accidentals-leftparen"))
35 (subject (callback grob))
38 (subject-dim-x (ly:stencil-get-extent subject 0))
39 (subject-dim-y (ly:stencil-get-extent subject 1))
44 (ly:stencil-combine-at-edge
45 (ly:stencil-combine-at-edge subject 0 1 pclose 0.2)
49 (ly:stencil-set-extent! subject 0 subject-dim-x)
50 (ly:stencil-set-extent! subject 1 subject-dim-y)
60 \notes \relative c' { c4 e
62 \override NoteHead #'print-function
64 #(parenthesize-callback Note_head::print)
66 \revert NoteHead #'print-function
67 \override Beam #'print-function
69 #(parenthesize-callback Beam::print)
75 \paper { raggedright = ##t}