Revised autobeam settings patch and ran makelsr.py
[lilypond/mpolesky.git] / Documentation / snippets / centering-markup-on-note-heads-automatically.ly
blob36fb7ffc4980efdb14d7c8fb4fa0455741aa829b
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.15
5 \version "2.13.29"
7 \header {
8 lsrtags = "text, tweaks-and-overrides, contexts-and-engravers"
9 texidoc = "
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"
19 } % begin verbatim
22 #(define (Text_align_engraver ctx)
23 (let ((scripts '())
24 (note-column #f))
26 `((acknowledgers
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
39 . ,(lambda (trans)
40 ;; if any TextScript grobs exist,
41 ;; set NoteColumn as X-parent
42 (and (pair? scripts)
43 (for-each (lambda (script)
44 (set! (ly:grob-parent script X) note-column))
45 scripts))
46 ;; clear scripts ready for next timestep
47 (set! scripts '()))))))
49 \layout {
50 \context {
51 \Voice
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
59 \new Staff <<
60 \relative c'' {
61 \override NoteColumn #'force-hshift = #3
62 c1-\markup { \arrow-head #Y #DOWN ##t }
65 \relative c' {
66 a4 a-\markup { \huge ^ } a a