That's quite handy to know, thanks for your response Carl. Cheers, Matt.
On Wed, Jun 30, 2021 at 2:35 AM Carl Sorensen <[email protected]> wrote: > > > > On 6/29/21, 2:43 AM, "lilypond-user on behalf of Matt Hood" > <[email protected] on behalf of > [email protected]> wrote: > > 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 > > Matt, I'm not an expert on \applyOutput, but it appears to me these are all > grobs created by engravers that live in the Score context by default. > > You may wish to try \applyOutput to Staff and Voice as well. > > Haven't tried it, and don't know if it will work, but it's an idea. > > HTH, > > Carl > >
