2 \header { texidoc=" You can write molecule callbacks in Scheme, thus
3 providing custom glyphs for notation elements. A simple example is
4 adding parentheses to existing molecule callbacks.
6 The parenthesized beam is less successful due to implementation of the
7 Beam. The note head is also rather naive, since the extent of the
8 parens are also not seen by accidentals.
13 #(define (parenthesize-callback callback)
14 "Construct a function that will do CALLBACK and add parentheses.
17 \property Voice.NoteHead \\override #'molecule-callback
19 #(parenthesize-callback Note_head::brew_molecule)
24 (define (parenthesize-molecule grob)
25 "This function adds parentheses to the original callback for
26 GROB. The dimensions of the molecule is not affected.
30 (fn (ly-get-default-font grob))
31 (pclose (ly-find-glyph-by-name fn "accidentals-)"))
32 (popen (ly-find-glyph-by-name fn "accidentals-("))
33 (subject (callback grob))
36 (subject-dims (ly-get-molecule-extent subject 0))
41 (ly-combine-molecule-at-edge
42 (ly-combine-molecule-at-edge subject 0 1 pclose 0.2)
46 (ly-set-molecule-extent! subject 0 subject-dims)
56 \notes \relative c' { c4 e
58 \property Voice.NoteHead \override #'molecule-callback
60 #(parenthesize-callback Note_head::brew_molecule)
62 \property Voice.NoteHead \revert #'molecule-callback
63 \property Voice.Beam \override #'molecule-callback
65 #(parenthesize-callback Beam::brew_molecule)
71 \paper { linewidth = -1.; }