Hi everyone,

I'm working with lilypond output in the browser, using its SVG export
function. Lilypond permits attaching attributes to particular kinds of
grobs, e.g.:

{
  \override NoteHead.output-attributes =
  #'((class . "NoteHead"))
  c
}

The above will cause all NoteHead objects to have the following SVG:

<g class="NoteHead">
  ...NoteHead grob SVG elements...
</g>

My question is: how can I make it so that all graphical objects have
their name in the class attribute?

I've tried using the following scheme function:

#(define (add-class grob grob-origin context)
         (let (name (cdr (assoc 'name
                                (ly:grob-property grob 'meta))))
            (set! (ly:grob-property grob 'output-attributes) '((class
. name)))))

This successfully (I believe) extracts the correct name, and assigns
it to the output-attributes field. As per the instructions in the
lilypond documentation, I then attempted to use \applyOutput Score
#add-class to apply this function to all graphical objects, but it
didn't supply all of the required objects. My attempted code is below:

\applyOutput Score #add-class
\score {
    \new RhythmicStaff {
      c'2 c'16 c' c' c' \tuplet 5/4 { c'16 c' c' c' c' }
    }
}

If I add a print call to the add-class function, I can see that it was
called for the objects with the following names from which crucial
objects such as NoteHead are missing:

NonMusicalPaperColumn
PaperColumn
Clef
TimeSignature
LedgerLineSpanner
StaffSymbol
VerticalAxisGroup
SystemStartBar
SpacingSpanner
VerticalAlignment
StaffSpacing
BreakAlignment
LeftEdge
BreakAlignGroup
BreakAlignGroup
BreakAlignGroup

If there were a way to run add-class on all graphical objects, that
might be a good solution to the problem.

Any help would be much appreciated!

Thanks,
Matt.

Reply via email to