LilyPond snippets: Expressive marks

# Expressive marks

Expressive marks

## Adding beams, slurs, ties etc. when using tuplet and non-tuplet rhythms

LilyPond syntax can involve many unusual placements for parentheses, brackets etc., which might sometimes have to be interleaved.

For example, when entering a manual beam, the left square bracket has to be placed after the starting note and its duration, not before. Similarly, the right square bracket should directly follow the note which is to be at the end of the requested beaming, even if this note happens to be inside a tuplet section.

This snippet demonstrates how to combine manual beaming, manual slurs, ties and phrasing slurs with tuplet sections (enclosed within curly braces).

    {
      r16[ g16 \tuplet 3/2 { r16 e'8] }
      g16( a \tuplet 3/2 { b d e') }
      g8[( a \tuplet 3/2 { b d') e'] ~ }
      \time 2/4
      \tuplet 5/4 { e'32\( a b d' e' } a'4.\)
    }

## Adding parentheses around an expressive mark or chordal note

The `\parenthesize` function is a special tweak that encloses objects in parentheses. The associated grob is `ParenthesesItem`.

    \relative c' {
      c2-\parenthesize ->
      \override ParenthesesItem.padding = #0.1
      \override ParenthesesItem.font-size = #-4
      <d \parenthesize f a>2
    }

## Adding timing marks to long glissandi

Skipped beats in very long glissandi are sometimes indicated by timing marks, often consisting of stems without noteheads. Such stems can also be used to carry intermediate expression markings.

If the stems do not align well with the glissando, they may need to be repositioned slightly.

    glissandoSkipOn = {
      \override NoteColumn.glissando-skip = ##t
      \hide NoteHead
      \override NoteHead.no-ledgers = ##t
    }

    glissandoSkipOff = {
      \revert NoteColumn.glissando-skip
      \undo \hide NoteHead
      \revert NoteHead.no-ledgers
    }

    \relative c'' {
      r8 f8\glissando
      \glissandoSkipOn
      f4 g a a8\noBeam
      \glissandoSkipOff
      a8

      r8 f8\glissando
      \glissandoSkipOn
      g4 a8
      \glissandoSkipOff
      a8 |

      r4 f\glissando \<
      \glissandoSkipOn
      a4\f \>
      \glissandoSkipOff
      b8\! r |
    }

## Adjusting the shape of falls and doits

The `shortest-duration-space` property may be tweaked to adjust the shape of falls and doits.

    \relative c'' {
      \override Score.SpacingSpanner.shortest-duration-space = #4.0
      c2-\bendAfter #5
      c2-\bendAfter #-4.75
      c2-\bendAfter #8.5
      c2-\bendAfter #-6
    }

## Alternative breve notes

Breve notes are also available with two vertical lines on each side of the notehead instead of one line and in baroque style.

    \relative c'' {
      \time 4/2
      c\breve |
      \override Staff.NoteHead.style = #'altdefault
      b\breve
      \override Staff.NoteHead.style = #'baroque
      b\breve
      \revert Staff.NoteHead.style
      a\breve
    }

## Asymmetric slurs

Slurs can be made asymmetric to match an asymmetric pattern of notes better.

    slurNotes = { d,8( a' d f a f' d, a) }

    \relative c' {
      \stemDown
      \slurUp
      \slurNotes
      \once \override Slur.eccentricity = #3.0
      \slurNotes
    }

## Breathing signs

Breathing signs are available in different tastes: commas (default), ticks, vees and “railroad tracks” (caesura).

    \new Staff \relative c'' {
      \key es \major
      \time 3/4
      % this bar contains no \breathe
      << { g4 as g } \\ { es4 bes es } >> |
      % Modern notation:
      % by default, \breathe uses the rcomma, just as if saying:
      % \override BreathingSign.text = #(make-musicglyph-markup "scripts.rcomma")
      << { g4 as g } \\ { es4 \breathe bes es } >> |

      % rvarcomma and lvarcomma are variations of the default rcomma and lcomma
      % N.B.: must use Staff context here, since we start a Voice below
      \override Staff.BreathingSign.text =
        \markup { \musicglyph "scripts.rvarcomma" }
      << { g4 as g } \\ { es4 \breathe bes es } >> |

      % vee
      \override BreathingSign.text = \markup { \musicglyph "scripts.upbow" }
      es8[ d es f g] \breathe f |

      % caesura
      \override BreathingSign.text =
        \markup { \musicglyph "scripts.caesura.curved" }
      es8[ d] \breathe es[ f g f] |
      es2 r4 \bar "||"
    }

## Broken Crescendo Hairpin

In order to make parts of a crescendo hairpin invisible, the following method is used: A white rectangle is drawn on top of the respective part of the crescendo hairpin, making it invisible. The rectangle is defined as postscript code within a text markup.

The markup command `with-dimensions` tells LilyPond to consider only the bottom edge of the rectangle when spacing it against the hairpin. The property `staff-padding` prevents the rectangle from fitting between the hairpin and staff.

Make sure the hairpin is in a lower layer than the text markup to draw the rectangle over the hairpin.

    \relative c' {
      <<
        {
          \dynamicUp
          r2 r16 c'8.\pp r4
        }
        \\
        {
          \override DynamicLineSpanner.layer = #0
          des,2\mf\< ~
          \override TextScript.layer = #2
          \once\override TextScript.staff-padding = #6
          \once\override TextScript.vertical-skylines = #'()
          des16_\markup \with-dimensions #'(2 . 7) #'(0 . 0)
                        \with-color #white
                        \filled-box #'(2 . 7) #'(0 . 2) #0
          r8. des4 ~ des16->\sff r8.
        }
      >>
    }

## Caesura ("railtracks") with fermata

A caesura is sometimes denoted by a double “railtracks” breath mark with a fermata sign positioned above. This snippet shows an optically pleasing combination of railtracks and fermata.

    \relative c'' {
      c2.
      % construct the symbol
      \override BreathingSign.text = \markup {
        \override #'(direction . 1)
        \override #'(baseline-skip . 1.8)
        \dir-column {
          \translate #'(0.155 . 0)
            \center-align \musicglyph "scripts.caesura.curved"
          \center-align \musicglyph "scripts.ufermata"
        }
      }
      \breathe c4
      % set the breathe mark back to normal
      \revert BreathingSign.text
      c2. \breathe c4
      \bar "|."
    }

## Center text below hairpin dynamics

This example provides a function to typeset a hairpin (de)crescendo with some additional text below it, such as “molto” or “poco”. The added text will change the direction according to the direction of the hairpin. The Hairpin is aligned to DynamicText.

The example also illustrates how to modify the way an object is normally printed, using some Scheme code.

    hairpinWithCenteredText =
    #(define-music-function (text) (markup?)
      #{
        \once \override Voice.Hairpin.after-line-breaking =
          #(lambda (grob)
            (let* ((stencil (ly:hairpin::print grob))
                   (par-y (ly:grob-parent grob Y))
                   (dir (ly:grob-property par-y 'direction))
                   (new-stencil (ly:stencil-aligned-to
                     (ly:stencil-combine-at-edge
                       (ly:stencil-aligned-to stencil X CENTER)
                       Y dir
                       (ly:stencil-aligned-to
                         (grob-interpret-markup grob text) X CENTER))
                     X LEFT))
                   (staff-space (ly:output-def-lookup
                     (ly:grob-layout grob) 'staff-space))
                   (staff-line-thickness
                     (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
                   (par-x (ly:grob-parent grob X))
                   (dyn-text (grob::has-interface par-x 'dynamic-text-interface))
                   (dyn-text-stencil-x-length
                     (if dyn-text
                       (interval-length
                         (ly:stencil-extent (ly:grob-property par-x 'stencil) X))
                       0))
                   (x-shift
                     (if dyn-text
                       (-
                         (+ staff-space dyn-text-stencil-x-length)
                         (* 0.5 staff-line-thickness)) 0)))

            (ly:grob-set-property! grob 'Y-offset 0)
            (ly:grob-set-property! grob 'stencil
               (ly:stencil-translate-axis
                new-stencil
                x-shift X))))
      #})

    hairpinMolto =
    \hairpinWithCenteredText \markup { \italic molto }

    hairpinMore =
    \hairpinWithCenteredText \markup { \larger moltissimo }

    \layout { ragged-right = ##f }

    \relative c' {
      \hairpinMolto
      c2\< c\f
      \hairpinMore
      c2\ppppp\< c\f
      \break
      \hairpinMolto
      c2^\< c\f
      \hairpinMore
      c2\ppppp\< c\f
    }

## Changing \flageolet mark size

To make the `\flageolet` circle smaller use the following tweak.

    smallFlageolet = \tweak font-size -3 \flageolet

    \layout { ragged-right = ##f }

    \relative c'' {
      d4^\flageolet_\markup { default size } d_\flageolet
      c4^\smallFlageolet_\markup { smaller } c_\smallFlageolet
    }

## Changing text and spanner styles for text dynamics

The text used for crescendos and decrescendos can be changed by modifying the context properties `crescendoText` and `decrescendoText`.

The style of the spanner line can be changed by modifying the `'style` property of `DynamicTextSpanner`. The default value is `'dashed-line`, and other possible values include `'line`, `'dotted-line` and `'none`.

    \relative c'' {
      \set crescendoText = \markup { \italic { cresc. poco } }
      \set crescendoSpanner = #'text
      \override DynamicTextSpanner.style = #'dotted-line
      a2\< a
      a2 a
      a2 a
      a2 a\mf
    }

## Changing the appearance of a slur from solid to dotted or dashed

The appearance of slurs may be changed from solid to dotted or dashed.

    \relative c' {
      c4( d e c)
      \slurDotted
      c4( d e c)
      \slurSolid
      c4( d e c)
      \slurDashed
      c4( d e c)
      \slurSolid
      c4( d e c)
    }

## Changing the breath mark symbol

The glyph of the breath mark can be tuned by overriding the `text` property of the `BreathingSign` layout object with any markup text.

    \relative c'' {
      c2
      \override BreathingSign.text =
        \markup { \musicglyph "scripts.rvarcomma" }
      \breathe
      d2
    }

## Changing the number of augmentation dots per note

The number of augmentation dots on a single note can be changed independently of the dots placed after the note.

    \relative c' {
      c4.. a16 r2 |
      \override Dots.dot-count = #4
      c4.. a16 r2 |
      \override Dots.dot-count = #0
      c4.. a16 r2 |
      \revert Dots.dot-count
      c4.. a16 r2 |
    }

## Combining dynamics with markup texts

Some dynamics may involve text indications (such as “più forte” or “piano subito”). These can be produced using a `\markup` block.

    piuF = \markup { \italic più \dynamic f }

    \layout { ragged-right = ##f }

    \relative c'' {
      c2\f c-\piuF
    }

## Contemporary glissando

A contemporary glissando without a final note can be typeset using a hidden note and cadenza timing.

    \relative c'' {
      \time 3/4
      \override Glissando.style = #'zigzag
      c4 c
      \cadenzaOn
      c4\glissando
      \hideNotes
      c,,4
      \unHideNotes
      \cadenzaOff
      \bar "|"
    }

## Controlling spanner visibility after a line break

The visibility of spanners which end on the first note following a line break is controlled by the `after-line-breaking` callback `ly:spanner::kill-zero-spanned-time`.

For objects such as glissandos and hairpins, the default behaviour is to hide the spanner after a break; disabling the callback will allow the left-broken span to be shown.

Conversely, spanners which are usually visible, such as text spans, can be hidden by enabling the callback.

    \paper { ragged-right = ##t }

    \relative c'' {
      \override Hairpin.to-barline = ##f
      \override Glissando.breakable = ##t
      % show hairpin
      \override Hairpin.after-line-breaking = ##t
      % hide text span
      \override TextSpanner.after-line-breaking =
        #ly:spanner::kill-zero-spanned-time
      e2\<\startTextSpan
      % show glissando
      \override Glissando.after-line-breaking = ##t
      f2\glissando
      \break
      f,1\!\stopTextSpan
    }

## Controlling the vertical ordering of scripts

The vertical ordering of scripts is controlled with the `'script-priority` property. The lower this number, the closer it will be put to the note. In this example, the `TextScript` (the sharp symbol) first has the lowest priority, so it is put lowest in the first example. In the second, the prall trill (the `Script`) has the lowest, so it is on the inside. When two objects have the same priority, the order in which they are entered determines which one comes first.

    \relative c''' {
      \once \override TextScript.script-priority = #-100
      a2^\prall^\markup { \sharp }

      \once \override Script.script-priority = #-100
      a2^\prall^\markup { \sharp }
    }

## Creating a delayed turn

Creating a delayed turn, where the lower note of the turn uses the accidental, requires several overrides. The `outside-staff-priority` property must be set to `#f`, as otherwise this would take precedence over the `avoid-slur property`. Changing the fractions `2/3` and `1/3` adjusts the horizontal position.

    \relative c'' {
      c2*2/3 ( s2*1/3\turn d4) r
      <<
        { c4.( d8) }
        { s4 s\turn }
      >>
      \transpose c d \relative c'' <<
        { c4.( d8) }
        {
          s4
          \once \set suggestAccidentals = ##t
          \once \override AccidentalSuggestion.outside-staff-priority = ##f
          \once \override AccidentalSuggestion.avoid-slur = #'inside
          \once \override AccidentalSuggestion.font-size = -3
          \once \override AccidentalSuggestion.script-priority = -1
          \single \hideNotes
          b8-\turn \noBeam
          s8
        }
      >>
    }

## Creating arpeggios across notes in different voices

An arpeggio can be drawn across notes in different voices on the same staff if the `Span_arpeggio_engraver` is added to the `Staff` context:

    \new Staff \with {
      \consists "Span_arpeggio_engraver"
    }
    \relative c' {
      \set Staff.connectArpeggios = ##t
      <<
        { <e' g>4\arpeggio <d f> <d f>2 }
        \\
        { <d, f>2\arpeggio <g b>2 }
      >>
    }

## Creating cross-staff arpeggios in a piano staff

In a `PianoStaff`, it is possible to let an arpeggio cross between the staves by setting the property `PianoStaff.connectArpeggios`.

    \new PianoStaff \relative c'' <<
      \set PianoStaff.connectArpeggios = ##t
      \new Staff {
        <c e g c>4\arpeggio
        <g c e g>4\arpeggio
        <e g c e>4\arpeggio
        <c e g c>4\arpeggio
      }
      \new Staff {
        \clef bass
        \repeat unfold 4 {
          <c,, e g c>4\arpeggio
        }
      }
    >>

## Creating cross-staff arpeggios in other contexts

Cross-staff arpeggios can be created in contexts other than `GrandStaff`, `PianoStaff` and `StaffGroup` if the `Span_arpeggio_engraver` is included in the `Score` context.

    \score {
      \new ChoirStaff {
        \set Score.connectArpeggios = ##t
        <<
          \new Voice \relative c' {
            <c e>2\arpeggio
            <d f>2\arpeggio
            <c e>1\arpeggio
          }
          \new Voice \relative c {
            \clef bass
            <c g'>2\arpeggio
            <b g'>2\arpeggio
            <c g'>1\arpeggio
          }
        >>
      }
      \layout {
        \context {
          \Score
          \consists "Span_arpeggio_engraver"
        }
      }
    }

## Creating double-digit fingerings

Creating fingerings larger than 5 is possible.

    \relative c' {
      c1-10
      c1-50
      c1-36
      c1-29
    }

## Creating "real" parenthesized dynamics

Although the easiest way to add parentheses to a dynamic mark is to use a `\markup` block, this method has a downside: the created objects will behave like text markups, and not like dynamics.

However, it is possible to create a similar object using the equivalent Scheme code (as described in the Notation Reference), combined with the `make-dynamic-script` function. This way, the markup will be regarded as a dynamic, and therefore will remain compatible with commands such as `\dynamicUp` or `\dynamicDown`.

    paren =
    #(define-event-function (dyn) (ly:event?)
       (make-dynamic-script
        #{ \markup \concat {
             \normal-text \italic \fontsize #2 (
    	 \pad-x #0.2 #(ly:music-property dyn 'text)
    	 \normal-text \italic \fontsize #2 )
           }
        #}))

    \relative c'' {
      c4\paren\f c c \dynamicUp c\paren\p
    }

## Creating simultaneous rehearsal marks

Unlike text scripts, rehearsal marks cannot be stacked at a particular point in a score: only one `RehearsalMark` object is created. Using an invisible measure and bar line, an extra rehearsal mark can be added, giving the appearance of two marks in the same column.

This method may also prove useful for placing rehearsal marks at both the end of one system and the start of the following system.

    {
      \key a \major
      \set Score.markFormatter = #format-mark-box-letters
      \once \override Score.RehearsalMark.outside-staff-priority = #5000
      \once \override Score.RehearsalMark.self-alignment-X = #LEFT
      \once \override Score.RehearsalMark.break-align-symbols = #'(key-signature)
      \mark \markup { \bold { Senza denti } }

      % the hidden measure and bar line
      % \cadenzaOn turns off automatic calculation of bar numbers
      \cadenzaOn
      \once \override Score.TimeSignature.stencil = ##f
      \time 1/16
      s16 \bar ""
      \cadenzaOff

      \time 4/4
      \once \override Score.RehearsalMark.self-alignment-X = #LEFT
      \mark \markup { \box \bold Intro }
      d'1
      \mark \default
      d'1
    }

## Creating slurs across voices

In some situations, it may be necessary to create slurs between notes from different voices. The solution is to add invisible notes to one of the voices, using `\hideNotes`.

This example is measure 235 of the Ciaconna from Bach’s 2nd Partita for solo violin, BWV 1004.

    \relative c' {
      <<
        {
          d16( a') s a s a[ s a] s a[ s a]
        }
        \\
        {
          \slurUp
          bes,16[ s e](
          \hideNotes a)
          \unHideNotes f[(
          \hideNotes a)
          \unHideNotes fis](
          \hideNotes a)
          \unHideNotes g[(
          \hideNotes a)
          \unHideNotes gis](
          \hideNotes a)
        }
      >>
    }

## Creating text spanners

The `\startTextSpan` and `\stopTextSpan` commands allow the creation of text spanners as easily as pedal indications or octavations. Override some properties of the `TextSpanner` object to modify its output.

    \paper { ragged-right = ##f }

    \relative c'' {
      \override TextSpanner.bound-details.left.text = #"bla"
      \override TextSpanner.bound-details.right.text = #"blu"
      a4 \startTextSpan
      b4 c
      a4 \stopTextSpan

      \override TextSpanner.style = #'line
      \once \override TextSpanner.bound-details.left.stencil-align-dir-y = #CENTER
      a4 \startTextSpan
      b4 c
      a4 \stopTextSpan

      \override TextSpanner.style = #'dashed-line
      \override TextSpanner.bound-details.left.text =
        \markup { \draw-line #'(0 . 1) }
      \override TextSpanner.bound-details.right.text =
        \markup { \draw-line #'(0 . -2) }
      \once \override TextSpanner.bound-details.right.padding = #-2

      a4 \startTextSpan
      b4 c
      a4 \stopTextSpan

      \set Staff.middleCPosition = #-13
      \override TextSpanner.dash-period = #10
      \override TextSpanner.dash-fraction = #0.5
      \override TextSpanner.thickness = #10
      a4 \startTextSpan
      b4 c
      a4 \stopTextSpan
    }

## Dynamics custom text spanner postfix

Postfix functions for custom crescendo text spanners. The spanners should start on the first note of the measure. One has to use `-\mycresc`, otherwise the spanner start will rather be assigned to the next note.

    % Two functions for (de)crescendo spanners where you can explicitly
    % give the spanner text.
    mycresc =
    #(define-music-function (mymarkup) (markup?)
       (make-music 'CrescendoEvent
                   'span-direction START
                   'span-type 'text
                   'span-text mymarkup))
    mydecresc =
    #(define-music-function (mymarkup) (markup?)
       (make-music 'DecrescendoEvent
                   'span-direction START
                   'span-type 'text
                   'span-text mymarkup))

    \relative c' {
      c4-\mycresc "custom cresc" c4 c4 c4 |
      c4 c4 c4 c4 |
      c4-\mydecresc "custom decresc" c4 c4 c4 |
      c4 c4\! c4 c4
    }

## Dynamics text spanner postfix

Custom text spanners can be defined and used with hairpin and text crescendos. `\<` and `\>` produce hairpins by default, `\cresc` etc. produce text spanners by default.

    % Some sample text dynamic spanners, to be used as postfix operators
    crpoco =
    #(make-music 'CrescendoEvent
                 'span-direction START
                 'span-type 'text
                 'span-text "cresc. poco a poco")

    \relative c' {
      c4\cresc d4 e4 f4 |
      g4 a4\! b4\crpoco c4 |
      c4 d4 e4 f4 |
      g4 a4\! b4\< c4 |
      g4\dim a4 b4\decresc c4\!
    }

## Glissandi can skip grobs

`NoteColumn` grobs can be skipped over by glissandi.

    \relative c' {
      a2 \glissando
      \once \override NoteColumn.glissando-skip = ##t
      f''4 d,
    }

## Hairpins with different line styles

Hairpins can take any style from `line-interface` - dashed-line, dotted-line, line, trill or zigzag.

    \relative c' {
      c2\< c\!
      \override Hairpin.style = #'dashed-line
      c2\< c\!
      \override Hairpin.style = #'dotted-line
      c2\< c\!
      \override Hairpin.style = #'line
      c2\< c\!
      \override Hairpin.style = #'trill
      c2\< c\!
      \override Hairpin.style = #'zigzag
      c2\< c\!
      \revert Hairpin.style
      c2\< c\!
    }

## Hiding the extender line for text dynamics

Text style dynamic changes (such as cresc. and dim.) are printed with a dashed line showing their extent. This line can be suppressed in the following way:

    \relative c'' {
      \override DynamicTextSpanner.style = #'none
      \crescTextCresc
      c1\< | d | b | c\!
    }

## Horizontally aligning custom dynamics (e.g. "sempre pp" "piu f" "subito p")

Some dynamic expressions involve additional text, like “sempre pp”. Since dynamics are usually centered under the note, the \pp would be displayed way after the note it applies to.

To correctly align the “sempre pp” horizontally, so that it is aligned as if it were only the \pp, there are several approaches:

* Simply use `\once\override DynamicText.X-offset = #-9.2` before the note with the dynamics to manually shift it to the correct position. Drawback: This has to be done manually each time you use that dynamic markup...

* Add some padding (`#:hspace 7.1`) into the definition of your custom dynamic mark, so that after lilypond center-aligns it, it is already correctly aligned. Drawback: The padding really takes up that space and does not allow any other markup or dynamics to be shown in that position.

* Shift the dynamic script `\once\override ... .X-offset = ..`. Drawback: `\once\override` is needed for every invocation!

* Set the dimensions of the additional text to 0 (using `#:with-dimensions '(0 . 0) '(0 . 0)`). Drawback: To LilyPond “sempre” has no extent, so it might put other stuff there and create collisions (which are not detected by the collision detection!). Also, there seems to be some spacing, so it’s not exactly the same alignment as without the additional text

* Add an explicit shifting directly inside the scheme function for the dynamic-script.

* Set an explicit alignment inside the dynamic-script. By default, this won’t have any effect, only if one sets X-offset! Drawback: One needs to set `DynamicText.X-offset`, which will apply to all dynamic texts! Also, it is aligned at the right edge of the additional text, not at the center of pp.

    \paper {
      ragged-right = ##f
      indent = 2.5\cm
    }

    % Solution 1: Using a simple markup with a particular halign value
    % Drawback: It's a markup, not a dynamic command, so \dynamicDown
    %           etc. will have no effect
    semppMarkup = \markup { \halign #1.4 \italic "sempre" \dynamic "pp" }

    % Solution 2: Using a dynamic script & shifting with
    %             \once \override ...X-offset = ..
    % Drawback: \once \override needed for every invocation
    semppK =
    #(make-dynamic-script
      (markup #:line
              (#:normal-text
               #:italic "sempre"
               #:dynamic "pp")))

    % Solution 3: Padding the dynamic script so the center-alignment
    %             puts it at the correct position
    % Drawback: the padding really reserves the space, nothing else can be there
    semppT =
    #(make-dynamic-script
      (markup #:line
              (#:normal-text
               #:italic "sempre"
               #:dynamic "pp"
               #:hspace 7.1)))

    % Solution 4: Dynamic, setting the dimensions of the additional text to 0
    % Drawback: To lilypond "sempre" has no extent, so it might put
    %           other stuff there => collisions
    % Drawback: Also, there seems to be some spacing, so it's not exactly the
    %           same alignment as without the additional text
    semppM =
    #(make-dynamic-script
      (markup #:line
              (#:with-dimensions '(0 . 0) '(0 . 0)
                                 #:right-align
                                 #:normal-text
                                 #:italic "sempre"
                                 #:dynamic "pp")))

    % Solution 5: Dynamic with explicit shifting inside the scheme function
    semppG =
    #(make-dynamic-script
      (markup #:hspace 0
              #:translate '(-18.85 . 0)
              #:line (#:normal-text
                      #:italic "sempre"
                      #:dynamic "pp")))

    % Solution 6: Dynamic with explicit alignment. This has only effect
    %             if one sets X-offset!
    % Drawback: One needs to set DynamicText.X-offset!
    % Drawback: Aligned at the right edge of the additional text,
    %           not at the center of pp
    semppMII =
    #(make-dynamic-script
      (markup #:line (#:right-align
                      #:normal-text
                      #:italic "sempre"
                      #:dynamic "pp")))

    \new StaffGroup <<
      \new Staff = "s" \with { instrumentName = \markup \column { Normal } }
      <<
        \relative c'' {
          \key es \major
          c4\pp c\p c c | c\ff c c\pp c
        }
      >>
      \new Staff = "sMarkup" \with {
        instrumentName = \markup \column { Normal markup }
      }
      <<
        \relative c'' {
          \key es \major
          c4-\semppMarkup c\p c c | c\ff c c-\semppMarkup c
        }
      >>
      \new Staff = "sK" \with {
        instrumentName = \markup \column { Explicit shifting }
      }
      <<
        \relative c'' {
          \key es \major
          \once \override DynamicText.X-offset = #-9.2
          c4\semppK c\p c c
          c4\ff c
          \once \override DynamicText.X-offset = #-9.2
          c4\semppK c
        }
      >>
      \new Staff = "sT" \with {
        instrumentName = \markup \column { Right padding }
      }
      <<
        \relative c'' {
          \key es \major
          c4\semppT c\p c c | c\ff c c\semppT c
        }
      >>
      \new Staff = "sM" \with {
        instrumentName = \markup \column { Set dimension "to zero" }
      }
      <<
        \relative c'' {
          \key es \major
          c4\semppM c\p c c | c\ff c c\semppM c
        }
      >>
      \new Staff = "sG" \with {
        instrumentName = \markup \column { Shift inside dynamics}
      }
      <<
        \relative c'' {
          \key es \major
          c4\semppG c\p c c | c\ff c c\semppG c
        }
      >>
      \new Staff = "sMII" \with {
        instrumentName = \markup \column { Alignment inside dynamics }
      }
      <<
        \relative c'' {
          \key es \major
          % Setting to ##f (false) gives the same result
          \override DynamicText.X-offset = #0
          c4\semppMII c\p c c | c\ff c c\semppMII c
        }
      >>
    >>

    \layout { \override Staff.InstrumentName.self-alignment-X = #LEFT }

## How to print two rehearsal marks above and below the same barline (method 1)

This method prints two ’rehearsal marks’, one on top of the other. It shifts the lower rehearsal mark below the staff and then adds padding above it in order to place the upper rehearsal mark above the staff.

By adjusting the extra-offset and baseline-skip values you can increase or decrease the overall space between the rehearsal mark and the staff.

Because nearly every type of glyph or string can be made to behave like a rehearsal mark it is possible to centre those above and below a bar line.

Adding the appropriate ’break visibility’ as shown in snippet 1 will allow you to position two marks at the end of a line as well.

Note: Method 1 is less complex than Method 2 but does not really allow for fine tuning of placement of one of the rehearsal marks without affecting the other. It may also give some problems with vertical spacing, since using `extra-offset` does not change the bounding box of the mark from its original value.

    \relative c'{
      c d e f |
      \once \override Score.RehearsalMark.extra-offset = #'(0 . -8.5)
      \once \override Score.RehearsalMark.baseline-skip = #9
      \mark \markup \center-column { \circle 1 \box A }
      g f e d |
      \once \override Score.RehearsalMark.extra-offset = #'(0 . -8.5)
      \once \override Score.RehearsalMark.baseline-skip = #9
      \mark \markup \center-column { \flat { \bold \small \italic Fine. } }
      g f e d |
      \once \override Score.RehearsalMark.extra-offset = #'(0 . -8.5)
      \once \override Score.RehearsalMark.baseline-skip = #9
      \override Score.RehearsalMark.break-visibility = #begin-of-line-invisible
      \mark \markup \center-column { \fermata \box z }
    }

## How to print two rehearsal marks above and below the same barline (method 2)

This method prints two ’rehearsal marks’ - one above the stave and one below, by creating two voices, adding the Rehearsal Mark engraver to each voice - without this no rehearsal mark is printed - and then placing each rehearsal mark UP and DOWN in each voice respectively.

This method (as opposed to method 1) is more complex, but allows for more flexibility, should it be needed to tweak each rehearsal mark independently of the other.

    \score {
      \relative c'
      <<
        \new Staff {
          <<
            \new Voice \with {
              \consists Mark_engraver
              \consists "Staff_collecting_engraver"
            }
            { c4 d e f
              \mark \markup { \box A }
              c4 d e f
            }
            \new Voice \with {
              \consists Mark_engraver
              \consists "Staff_collecting_engraver"
              \override RehearsalMark.direction = #DOWN
            }
            { s4 s s s
              \mark \markup { \circle 1 }
              s4 s s s
            }
          >>
        }
      >>
      \layout {
        \context {
          \Score
          \remove "Mark_engraver"
          \remove "Staff_collecting_engraver"
        }
      }
    }

## Inserting a caesura

Caesura marks can be created by overriding the `'text` property of the `BreathingSign` object.

A curved caesura mark is also available.

    \relative c'' {
      \override BreathingSign.text = \markup {
        \musicglyph "scripts.caesura.straight"
      }
      c8 e4. \breathe g8. e16 c4

      \override BreathingSign.text = \markup {
        \musicglyph "scripts.caesura.curved"
      }
      g8 e'4. \breathe g8. e16 c4
    }

## Laissez vibrer ties

Laissez vibrer ties have a fixed size. Their formatting can be tuned using `'tie-configuration`.

    \relative c' {
      <c e g>4\laissezVibrer r <c f g>\laissezVibrer r
      <c d f g>4\laissezVibrer r <c d f g>4.\laissezVibrer r8

      <c d e f>4\laissezVibrer r
      \override LaissezVibrerTieColumn.tie-configuration
         = #`((-7 . ,DOWN)
              (-5 . ,DOWN)
              (-3 . ,UP)
              (-1 . ,UP))
      <c d e f>4\laissezVibrer r
    }

## Line arrows

Arrows can be applied to text-spanners and line-spanners (such as the Glissando).

    \relative c'' {
      \override TextSpanner.bound-padding = #1.0
      \override TextSpanner.style = #'line
      \override TextSpanner.bound-details.right.arrow = ##t
      \override TextSpanner.bound-details.left.text = #"fof"
      \override TextSpanner.bound-details.right.text = #"gag"
      \override TextSpanner.bound-details.right.padding = #0.6

      \override TextSpanner.bound-details.right.stencil-align-dir-y = #CENTER
      \override TextSpanner.bound-details.left.stencil-align-dir-y = #CENTER

      \override Glissando.bound-details.right.arrow = ##t
      \override Glissando.arrow-length = #0.5
      \override Glissando.arrow-width = #0.25

      a8\startTextSpan gis a4 b\glissando b,
      g'4 c\stopTextSpan c2
    }

## Making slurs with complex dash structure

Slurs can be made with complex dash patterns by defining the `dash-definition` property. `dash-definition` is a list of `dash-elements`. A `dash-element` is a list of parameters defining the dash behavior for a segment of the slur.

The slur is defined in terms of the bezier parameter t which ranges from 0 at the left end of the slur to 1 at the right end of the slur. `dash-element` is a list `(start-t stop-t dash-fraction dash-period)`. The region of the slur from `start-t` to `stop-t` will have a fraction `dash-fraction` of each `dash-period` black. `dash-period` is defined in terms of staff spaces. `dash-fraction` is set to 1 for a solid slur.

    \relative c' {
      \once \override
        Slur.dash-definition = #'((0 0.3 0.1 0.75)
                                    (0.3 0.6 1 1)
                                    (0.65 1.0 0.4 0.75))
      c4( d e f)
      \once \override
        Slur.dash-definition = #'((0 0.25 1 1)
                                    (0.3 0.7 0.4 0.75)
                                    (0.75 1.0 1 1))
      c4( d e f)
    }

## Modifying default values for articulation shorthand notation

The shorthands are defined in ‘`ly/script-init.ly`’, where the variables `dashHat`, `dashPlus`, `dashDash`, `dashBang`, `dashLarger`, `dashDot`, and `dashUnderscore` are assigned default values. The default values for the shorthands can be modified. For example, to associate the `-+` (`dashPlus`) shorthand with the trill symbol instead of the default + symbol, assign the value `trill` to the variable `dashPlus`:

    \relative c'' { c1-+ }

    dashPlus = "trill"

    \relative c'' { c1-+ }

## Moving slur positions vertically

The vertical position of a slur can be adjusted using the `positions` property of `Slur`. The property has 2 parameters, the first referring to the left end of the slur and the second to the right. The values of the parameters are not used by LilyPond to make an exact movement of the slur - instead it selects what placement of the slur looks best, taking into account the parameter values. Positive values move the slur up, and are appropriate for notes with stems down. Negative values move downward slurs further down.

    \relative c' {
      \stemDown
      e4( a)
      \override Slur.positions = #'(1 . 1)
      e4( a)
      \override Slur.positions = #'(2 . 2)
      e4( a)
      \override Slur.positions = #'(3 . 3)
      e4( a)
      \override Slur.positions = #'(4 . 4)
      e4( a)
      \override Slur.positions = #'(5 . 5)
      e4( a)
      \override Slur.positions = #'(0 . 5)
      e4( a)
      \override Slur.positions = #'(5 . 0)
      e4( a)
      \stemUp
      \override Slur.positions = #'(-5 . -5)
      e4( a)
      \stemDown
      \revert Slur.positions
      e4( a)
    }

## Moving the ends of hairpins

The ends of hairpins may be offset by setting the `shorten-pair` property of the `Hairpin` object. Positive values move endpoints to the right, negative to the left. Unlike the `minimum-length` property, this property only affects the appearance of the hairpin; it does not adjust horizontal spacing (including the position of bounding dynamics). This method is thus suitable for fine-tuning a hairpin within its allotted space.

    {
      c'1~\<
      c'2~ c'\!
      \once \override Hairpin.shorten-pair = #'(2 . 2)
      c'1~\<
      c'2~ c'\!
      \once \override Hairpin.shorten-pair = #'(-2 . -2)
      c'1~\<
      c'2~ c'\!
      c'1~\p-\tweak shorten-pair #'(2 . 0)\<
      c'2~ c'\ffff
    }

## Positioning arpeggios

If you need to extend or shorten an arpeggio, you can modify the upper and lower start positions independently.

    \relative c' {
      <c e g b>1\arpeggio
      \once \override Arpeggio.positions = #'(-5 . 0)
      <c e g b>1\arpeggio
      \once \override Arpeggio.positions = #'(0 . 5)
      <c e g b>1\arpeggio
      \once \override Arpeggio.positions = #'(-5 . 5)
      <c e g b>1\arpeggio
    }

## Positioning text markups inside slurs

Text markups need to have the `outside-staff-priority` property set to false in order to be printed inside slurs.

    \relative c'' {
      \override TextScript.avoid-slur = #'inside
      \override TextScript.outside-staff-priority = ##f
      c2(^\markup { \halign #-10 \natural } d4.) c8
    }

## Printing hairpins in various styles

Hairpin dynamics may be created in a variety of styles.

    \relative c'' {
      \override Hairpin.stencil = #flared-hairpin
      a4\< a a a\f
      a4\p\< a a a\ff
      a4\sfz\< a a a\!
      \override Hairpin.stencil = #constante-hairpin
      a4\< a a a\f
      a4\p\< a a a\ff
      a4\sfz\< a a a\!
      \override Hairpin.stencil = #flared-hairpin
      a4\> a a a\f
      a4\p\> a a a\ff
      a4\sfz\> a a a\!
      \override Hairpin.stencil = #constante-hairpin
      a4\> a a a\f
      a4\p\> a a a\ff
      a4\sfz\> a a a\!
    }

## Printing hairpins using al niente notation

Hairpin dynamics may be printed with a circled tip (“al niente” notation) by setting the `circled-tip` property of the `Hairpin` object to `#t`.

    \relative c'' {
      \override Hairpin.circled-tip = ##t
      c2\< c\!
      c4\> c\< c2\!
    }

## Printing metronome and rehearsal marks below the staff

By default, metronome and rehearsal marks are printed above the staff. To place them below the staff simply set the `direction` property of `MetronomeMark` or `RehearsalMark` appropriately.

    \layout {
      indent = 0
      ragged-right = ##f
    }

    {
      % Metronome marks below the staff
      \override Score.MetronomeMark.direction = #DOWN
      \tempo 8. = 120
      c''1

      % Rehearsal marks below the staff
      \override Score.RehearsalMark.direction = #DOWN
      \mark \default
      c''1
    }

## Setting hairpin behavior at bar lines

If the note which ends a hairpin falls on a downbeat, the hairpin stops at the bar line immediately preceding. This behavior can be controlled by overriding the `'to-barline` property.

    \relative c'' {
      e4\< e2.
      e1\!
      \override Hairpin.to-barline = ##f
      e4\< e2.
      e1\!
    }

## Setting the minimum length of hairpins

If hairpins are too short, they can be lengthened by modifying the `minimum-length` property of the `Hairpin` object.

    \relative c'' {
      c4\< c\! d\> e\!
      << f1 { s4 s\< s\> s\! } >>
      \override Hairpin.minimum-length = #5
      << f1 { s4 s\< s\> s\! } >>
    }

## Showing the same articulation above and below a note or chord

By default, LilyPond does not allow the same articulation (e.g., an accent, a fermata, a flageolet, etc.) to be displayed above and below a note. For example, `c4_\fermata^\fermata` will only show a fermata below. The fermata above will simply be ignored.

However, one can stick scripts (just like fingerings) inside a chord, which means it is possible to have as many articulations as desired. This approach has the advantage that it ignores the stem and positions the articulation relative to the note head. This can be seen in the case of the flageolets in the snippet. To mimic the behaviour of scripts outside a chord, ’add-stem-support would be required.

So, the solution is to write the note as a chord and add the articulations inside the `<...>`. The direction will always be above, but one can tweak this via a \tweak: `<c-\tweak direction #DOWN-\fermata^\fermata>`

    % The same as \flageolet, just a little smaller
    smallFlageolet = \tweak font-size #-2 \flageolet

    \relative c' {
      s4^"Wrong:"
      c4_\fermata^\fermata % The second fermata is ignored!
      <e d'>4^\smallFlageolet_\smallFlageolet

      s4^"Works if written inside a chord:"
      <e_\smallFlageolet d'^\smallFlageolet>4
      <e_\flageolet d'^\flageolet>4
      <e_\smallFlageolet^\smallFlageolet>4
      <e_\fermata^\fermata>4
    }

## Snap-pizzicato or Bartok pizzicato

A snap-pizzicato (also known as “Bartok pizzicato”) is a “strong pizzicato where the string is plucked vertically by snapping and rebounds off the fingerboard of the instrument” (Wikipedia). It is denoted by a circle with a vertical line going from the center upwards outside the circle.

    \relative c' {
      c4\snappizzicato
      <c' e g>4\snappizzicato
      <c' e g>4^\snappizzicato
      <c, e g>4_\snappizzicato
    }

## Using a tick as the breath mark symbol

Vocal and wind music frequently uses a tick mark as a breathing sign. This indicates a breath that subtracts a little time from the previous note rather than causing a short pause, which is indicated by the comma breath mark. The mark can be moved up a little to take it away from the stave.

    \relative c'' {
      c2
      \breathe
      d2
      \override BreathingSign.Y-offset = #2.6
      \override BreathingSign.text =
        \markup { \musicglyph "scripts.tickmark" }
      c2
      \breathe
      d2
    }

## Using arpeggioBracket to make divisi more visible

The `arpeggioBracket` can be used to indicate the division of voices where there are no stems to provide the information. This is often seen in choral music.

    \include "english.ly"

    \score {
      \relative c'' {
        \key a \major
        \time 2/2
        <<
          \new Voice = "upper"
          <<
            { \voiceOne \arpeggioBracket
              a2( b2
              <b d>1\arpeggio)
              <cs e>\arpeggio ~
              <cs e>4
            }
            \addlyrics { \lyricmode { A -- men. } }
          >>
          \new Voice = "lower"
          { \voiceTwo
            a1 ~
            a
            a ~
            a4 \bar "|."
          }
        >>
      }
      \layout { ragged-right = ##t }
    }

## Using double slurs for legato chords

Some composers write two slurs when they want legato chords. This can be achieved by setting `doubleSlurs`.

    \relative c' {
      \set doubleSlurs = ##t
      <c e>4( <d f> <c e> <d f>)
    }

## Using the whiteout property

Any graphical object can be printed over a white background to mask parts of objects that lie beneath. This can be useful to improve the appearance of collisions in complex situations when repositioning objects is impractical. It is necessary to explicitly set the `layer` property to control which objects are masked by the white background.

In this example the collision of the tie with the time signature is improved by masking out the part of the tie that crosses the time signature by setting the `whiteout` property of `TimeSignature`. To do this `TimeSignature` is moved to a layer above `Tie`, which is left in the default layer of 1, and `StaffSymbol` is moved to a layer above `TimeSignature` so it is not masked.

    {
      \override Score.StaffSymbol.layer = #4
      \override Staff.TimeSignature.layer = #3
      b'2 b'~
      \once \override Staff.TimeSignature.whiteout = ##t
      \time 3/4
      b' r4
    }

## Vertical line as a baroque articulation mark

This short vertical line placed above the note is commonly used in baroque music. Its meaning can vary, but generally indicates notes that should be played with more “weight”. The following example demonstrates how to achieve such a notation.

    upline =
    \tweak stencil
      #(lambda (grob)
        (grob-interpret-markup grob #{ \markup \draw-line #'(0 . 1) #}))
      \stopped

    \relative c' {
      a'4^\upline a( c d')_\upline
    }

## Vertically aligning dynamics across multiple notes

Dynamics that occur at, begin on, or end on the same note will be vertically aligned. To ensure that dynamics are aligned when they do not occur on the same note, increase the `staff-padding` property of the `DynamicLineSpanner` object.

    \relative c' {
      \override DynamicLineSpanner.staff-padding = #4
      c2\p f\mf
      g2\< b4\> c\!
    }

#### LilyPond — Snippets v2.22.2 (stable-branch).