1 % Do not edit this file; it is automatically
2 % generated from Documentation/snippets/new
3 % This file is in the public domain.
4 %% Note: this file works from version 2.13.36
8 lsrtags = "text, tweaks-and-overrides, contexts-and-engravers"
10 For technical reasons, text scripts attached to note heads cannot
11 easily be centered on a note head's width, unlike articulations.
13 Instead of using trial-and-error offset tweaks, this snippet uses a
14 Scheme engraver to reset the horizontal parent of each markup to a
15 @code{NoteColumn}. This also allows text to follow note heads which have
16 been shifted via @code{force-hshift}.
18 doctitle = "Centering markup on note heads automatically"
22 #(define (Text_align_engraver ctx)
27 (note-column-interface
28 . ,(lambda (trans grob source)
29 ;; cache NoteColumn in this Voice context
30 (set! note-column grob)))
32 (text-script-interface
33 . ,(lambda (trans grob source)
34 ;; whenever a TextScript is acknowledged,
35 ;; add it to `scripts' list
36 (set! scripts (cons grob scripts)))))
38 (stop-translation-timestep
40 ;; if any TextScript grobs exist,
41 ;; set NoteColumn as X-parent
43 (for-each (lambda (script)
44 (set! (ly:grob-parent script X) note-column))
46 ;; clear scripts ready for next timestep
47 (set! scripts '()))))))
52 \consists #Text_align_engraver
53 \override TextScript #'X-offset =
54 #ly:self-alignment-interface::aligned-on-x-parent
55 \override TextScript #'self-alignment-X = #CENTER
61 \override NoteColumn #'force-hshift = #3
62 c1-\markup { \arrow-head #Y #DOWN ##t }
66 a4 a-\markup { \huge ^ } a a