By default, Lilypond's \parenthesize function (to put parentheses around notes,
articulations, etc.) only works on notes if they are written inside a chord.
In particular, \parenthesize c4 will not work, only <\parenthesize c>4 will.
Similarly, trying to parenthesize a rest will fail. The reason is that
internally, Lilypond understands c4 as <c>4, so the first example is
internally the same as \parenthesize <c>4. The apparent solution is to make
\parenthesize apply to all elements inside a chord instead of the chord
itself (which the current implementation does).
In fact, one can simply redefine the \parenthesize function, which sets
the parenthesize property of a music expression to ##t, so that if applied
to a chord, it will set this property for all note and rest children of a
chord. This immediately solves the problem of parenthesizing rests, as well
as allowing the parenthesizing of all notes inside a chord at once. All
other uses of \parenthesize continue working as usual. So, using the
redefinition of \parenthesize from the snippet, finally the following
commands work as expected:
\parenthesize c4-. \parenthesize r4 \parenthesize <c e g>4->
#(define-music-function (parser loc arg) (ly:music?)
(_i "Tag @var{arg} to be parenthesized.")
#(define-music-function (parser loc arg) (ly:music?)
(_i "Tag @var{arg} to be parenthesized.")
- (set! (ly:music-property arg 'parenthesize) #t)
+ (if (memq 'event-chord (ly:music-property arg 'types))
+ ; arg is an EventChord -> set the parenthesize property on all child notes and rests
+ (map
+ (lambda (ev)
+ (if (or (memq 'note-event (ly:music-property ev 'types))
+ (memq 'rest-event (ly:music-property ev 'types)))
+ (set! (ly:music-property ev 'parenthesize) #t)))
+ (ly:music-property arg 'elements))
+ ; No chord, simply set property for this expression:
+ (set! (ly:music-property arg 'parenthesize) #t))