4 lsrtags = "text, tweaks-and-overrides, contexts-and-engravers"
6 For technical reasons, text scripts attached to note heads cannot
7 easily be centered on a note head's width, unlike articulations.
9 Instead of using trial-and-error offset tweaks, this snippet uses a
10 Scheme engraver to reset the horizontal parent of each markup to a
11 @code{NoteColumn}. This also allows text to follow note heads which have
12 been shifted via @code{force-hshift}.
14 doctitle = "Centering markup on note heads automatically"
17 #(define (Text_align_engraver ctx)
22 ((note-column-interface trans grob source)
23 ;; cache NoteColumn in this Voice context
24 (set! note-column grob))
25 ((text-script-interface trans grob source)
26 ;; whenever a TextScript is acknowledged,
27 ;; add it to `scripts' list
28 (set! scripts (cons grob scripts))))
29 ((stop-translation-timestep trans)
30 ;; if any TextScript grobs exist,
31 ;; set NoteColumn as X-parent
32 (for-each (lambda (script)
33 (set! (ly:grob-parent script X) note-column))
35 ;; clear scripts ready for next timestep
36 (set! scripts '())))))
41 \consists #Text_align_engraver
42 \override TextScript #'X-offset =
43 #ly:self-alignment-interface::aligned-on-x-parent
44 \override TextScript #'self-alignment-X = #CENTER
50 \override NoteColumn #'force-hshift = #3
51 c1-\markup { \arrow-head #Y #DOWN ##t }
55 a4 a-\markup { \huge ^ } a a