3 \header { texidoc=" You can write molecule callbacks in Scheme, thus
4 providing custom glyphs for notation elements. A simple example is
5 adding parentheses to existing molecule callbacks.
7 The parenthesized beam is less successful due to implementation of the
8 Beam. The note head is also rather naive, since the extent of the
9 parens are also not seen by accidentals.
14 #(define (parenthesize-callback callback)
15 "Construct a function that will do CALLBACK and add parentheses.
18 \property Voice.NoteHead \\override #'molecule-callback
20 #(parenthesize-callback Note_head::brew_molecule)
25 (define (parenthesize-molecule grob)
26 "This function adds parentheses to the original callback for
27 GROB. The dimensions of the molecule is not affected.
31 (fn (ly-get-default-font grob))
32 (pclose (ly-find-glyph-by-name fn "accidentals-)"))
33 (popen (ly-find-glyph-by-name fn "accidentals-("))
34 (subject (callback grob))
37 (subject-dims (ly-get-molecule-extent subject 0))
42 (ly-combine-molecule-at-edge
43 (ly-combine-molecule-at-edge subject 0 1 pclose 0.2)
47 (ly-set-molecule-extent! subject 0 subject-dims)
57 \notes \relative c' { c4 e
59 \property Voice.NoteHead \override #'molecule-callback
61 #(parenthesize-callback Note_head::brew_molecule)
63 \property Voice.NoteHead \revert #'molecule-callback
64 \property Voice.Beam \override #'molecule-callback
66 #(parenthesize-callback Beam::brew_molecule)
72 \paper { linewidth = -1. }