]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/centering-markup-on-note-heads-automatically.ly
Web-hu: updated Easier editing
[lilypond.git] / Documentation / snippets / centering-markup-on-note-heads-automatically.ly
1 %% Do not edit this file; it is automatically
2 %% generated from LSR http://lsr.dsi.unimi.it
3 %% This file is in the public domain.
4 \version "2.13.20"
5
6 \header {
7   lsrtags = "text, tweaks-and-overrides"
8
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.
12
13 Instead of using trial-and-error offset tweaks, this snippet accesses a
14 note head (or rest) from the @code{TextScript} object's horizontal
15 parent (a paper column), using its extent to correct the positioning.
16
17
18
19 "
20   doctitle = "Centering markup on note heads automatically"
21 } % begin verbatim
22
23 textScriptCenterOnNote = \override TextScript #'X-offset =
24 #(lambda (grob)
25    (let* ((paper-col (ly:grob-parent grob X))
26           (elts (ly:grob-object paper-col 'elements))
27           (rhythmic-head grob))
28
29      (for-each
30       (lambda (idx)
31         (let ((elt (ly:grob-array-ref elts idx)))
32           (if (grob::has-interface elt
33                                    'rhythmic-grob-interface)
34               (set! rhythmic-head elt))))
35       (reverse (iota (ly:grob-array-length elts))))
36
37      (+
38       (ly:self-alignment-interface::x-aligned-on-self grob)
39       (interval-center
40        (ly:grob-robust-relative-extent rhythmic-head rhythmic-head X)))))
41
42 \relative c' {
43   \override TextScript #'self-alignment-X = #CENTER
44   \textScriptCenterOnNote
45   <c e g c>1-\markup \arrow-head #Y #UP ##t
46   <c e g c>1-\markup \huge "^"
47 }
48