1\version "2.21.0"
2
3\header {
4  texidoc = "Incipits can be printed using an @code{InstrumentName}
5grob.  In the second line of the second score the @code{InstrumentName}
6grob should appear left-aligned."
7}
8
9\score {
10  \new Staff {
11    %% All this would be shortcuted by an appropriate music function:
12    \override Staff.InstrumentName.self-alignment-X = #RIGHT
13    \override Staff.InstrumentName.self-alignment-Y = ##f
14    \override Staff.InstrumentName.padding = #0
15    \override Staff.InstrumentName.stencil =
16      #(lambda (grob)
17         (let* ((instrument-name (ly:grob-property grob 'long-text))
18                (layout (ly:output-def-clone (ly:grob-layout grob)))
19                (music
20                  #{
21                    \new MensuralStaff
22                      \with { instrumentName = #instrument-name }
23                      { \clef "petrucci-c1" c'4 d' e' f' }
24                  #})
25                (score (ly:make-score music))
26                (indent (ly:output-def-lookup layout 'indent))
27                (incipit-width
28                  (ly:output-def-lookup layout 'incipit-width (* indent 0.5))))
29           (ly:output-def-set-variable! layout 'indent (- indent incipit-width))
30           (ly:output-def-set-variable! layout 'line-width indent)
31           (ly:output-def-set-variable! layout 'ragged-right #f)
32           (ly:score-add-output-def! score layout)
33           (set! (ly:grob-property grob 'long-text)
34                 (markup #:score score))
35           (system-start-text::print grob)))
36
37    %% the instrument name definition is separated:
38    \set Staff.instrumentName = "Instrument"
39    c'4 d' e' f'
40    g'1
41  }
42  \layout {
43    indent = 5\cm
44    incipit-width = 3\cm
45  }
46}
47
48\score {
49  \new Staff
50    \with { instrumentName = "Instrument" shortInstrumentName = "Instrument" }
51  {
52    \incipit { \clef "petrucci-c1" c'4 d' e' f' }
53    c'4 d' e' f' \break g'1
54  }
55  \layout {
56    \override Staff.InstrumentName.self-alignment-X = #LEFT
57    indent = 5\cm
58    short-indent = 5\cm
59    incipit-width = 3\cm
60  }
61}
62