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
23 . ,(lambda (trans grob source)
24 ;; cache NoteColumn in this Voice context
25 (set! note-column grob)))
27 (text-script-interface
28 . ,(lambda (trans grob source)
29 ;; whenever a TextScript is acknowledged,
30 ;; add it to `scripts' list
31 (set! scripts (cons grob scripts)))))
33 (stop-translation-timestep
35 ;; if any TextScript grobs exist,
36 ;; set NoteColumn as X-parent
38 (for-each (lambda (script)
39 (set! (ly:grob-parent script X) note-column))
41 ;; clear scripts ready for next timestep
42 (set! scripts '()))))))
47 \consists #Text_align_engraver
48 \override TextScript #'X-offset =
49 #ly:self-alignment-interface::aligned-on-x-parent
50 \override TextScript #'self-alignment-X = #CENTER
56 \override NoteColumn #'force-hshift = #3
57 c1-\markup { \arrow-head #Y #DOWN ##t }
61 a4 a-\markup { \huge ^ } a a