Jump to content

Markup on clef: Difference between revisions

From LilyPond wiki
m Replace version="2.24.0" with version="2.24" now that the LilyWiki extension supports auto-selecting the latest release in a stable series
m New category
Tags: Mobile edit Mobile web edit
 
(One intermediate revision by the same user not shown)
Line 43: Line 43:
[[Category:Editorial annotations]]
[[Category:Editorial annotations]]
[[Category:Text]]
[[Category:Text]]
[[Category:Snippet]]

Latest revision as of 23:29, 21 November 2025

Here's how to put a markup – such as a sul tasto reminder – over the clefs.

\version "2.24"

%% http://lsr.di.unimi.it/LSR/Item?id=1086
%% Discussion => http://lilypond.1069038.n5.nabble.com/Markup-on-clef-possible-td219968.html
%% See also => http://lilypond.1069038.n5.nabble.com/Align-text-above-clef-td216678.html
%% Credit: PPS on Feb. 2019

STclef = {
  \once\override Staff.Clef.stencil = 
    #(lambda (grob) 
       (let ((glyph (ly:grob-property grob 'glyph-name))) 
               (cond
                ((equal? glyph "clefs.G")  
                   (grob-interpret-markup grob #{ 
                      \markup 
                      \translate #'(0 . 5.5)
                      \override #'(baseline-skip . 5.5)
                      \column { "ST" \musicglyph "clefs.G" } #}))
                ((equal? glyph "clefs.F")  
                  (grob-interpret-markup grob #{ 
                      \markup 
                      \translate #'(0 . 2)
                      \override #'(baseline-skip . 2)
                      \column { "ST" \musicglyph "clefs.F" } #}))
                (else (ly:clef::print grob)))))
}

%% Test:
\new StaffGroup <<
  \new Staff 
    \with { instrumentName = "Violin" }
    \relative c' { \STclef \clef G a' b c d \break b c a c }
  \new Staff 
    \with { instrumentName = "Cello" }
    \relative c, { \STclef \clef F a' b c d \break b c a c }
>>

\paper { tagline = ##f }