LilyPond snippets: Tweaks and overrides

# Tweaks and overrides

Changing defaults

Tweaking output

## Adjusting grace note spacing

The space given to grace notes can be adjusted using the `spacing-increment` property of `Score.GraceSpacing`.

    graceNotes = {
      \grace { c4 c8 c16 c32 }
      c8
    }

    \relative c'' {
      c8
      \graceNotes
      \override Score.GraceSpacing #'spacing-increment = #2.0
      \graceNotes
      \revert Score.GraceSpacing #'spacing-increment
      \graceNotes
    }

## Altering the length of beamed stems

Stem lengths on beamed notes can be varied by overriding the `beamed-lengths` property of the `details` of the `Stem`. If a single value is used as an argument, the length applies to all stems. When multiple arguments are used, the first applies to eighth notes, the second to sixteenth notes and so on. The final argument also applies to all notes shorter than the note length of the final argument. Non-integer arguments may also be used.

    \relative c'' {
      \override Stem #'(details beamed-lengths) = #'(2)
      a8[ a] a16[ a] a32[ a]
      \override Stem #'(details beamed-lengths) = #'(8 10 12)
      a8[ a] a16[ a] a32[ a] r8
      \override Stem #'(details beamed-lengths) = #'(8)
      a8[ a]
      \override Stem #'(details beamed-lengths) = #'(8.5)
      a8[ a]
      \revert Stem #'details
      a8[ a] a16[ a] a32[ a] r16
    }

## Analysis brackets above the staff

Simple horizontal analysis brackets are added below the staff by default. The following example shows a way to place them above the staff instead.

    \layout {
      \context {
        \Voice
        \consists "Horizontal_bracket_engraver"
      }
    }
    \relative c'' {
      \once \override HorizontalBracket #'direction = #UP
      c2\startGroup
      d2\stopGroup
    }

## 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
    }

## Avoiding collisions with chord fingerings

Fingerings and string numbers applied to individual notes will automatically avoid beams and stems, but this is not true by default for fingerings and string numbers applied to the individual notes of chords. The following example shows how this default behavior can be overridden.

    \relative c' {
      \set fingeringOrientations = #'(up)
      \set stringNumberOrientations = #'(up)
      \set strokeFingerOrientations = #'(up)

      % Default behavior
      r8
      <f c'-5>8
      <f c'\5>8
      <f c'-\rightHandFinger #2 >8

      % Corrected to avoid collisions
      r8
      \override Fingering #'add-stem-support = ##t
      <f c'-5>8
      \override StringNumber #'add-stem-support = ##t
      <f c'\5>8
      \override StrokeFinger #'add-stem-support = ##t
      <f c'-\rightHandFinger #2 >8
    }

## 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 {
        \line {
          \musicglyph #"scripts.caesura.curved"
          \translate #'(-1.75 . 1.6)
          \musicglyph #"scripts.ufermata"
        }
      }
      \breathe c4
      % set the breathe mark back to normal
      \revert BreathingSign #'text
      c2. \breathe c4
      \bar "|."
    }

## Centering markup on note heads automatically

For technical reasons, text scripts attached to note heads cannot easily be centered on a note head’s width, unlike articulations.

Instead of using trial-and-error offset tweaks, this snippet uses a Scheme engraver to reset the horizontal parent of each markup to a `NoteColumn`. This also allows text to follow note heads which have been shifted via `force-hshift`.

    #(define (Text_align_engraver ctx)
      (let ((scripts '())
            (note-column #f))

        `((acknowledgers
           (note-column-interface
            . ,(lambda (trans grob source)
                 ;; cache NoteColumn in this Voice context
                 (set! note-column grob)))

           (text-script-interface
            . ,(lambda (trans grob source)
                 ;; whenever a TextScript is acknowledged,
                 ;; add it to `scripts' list
                 (set! scripts (cons grob scripts)))))

          (stop-translation-timestep
           . ,(lambda (trans)
                ;; if any TextScript grobs exist,
                ;; set NoteColumn as X-parent
                (and (pair? scripts)
                     (for-each (lambda (script)
                                 (set! (ly:grob-parent script X) note-column))
                               scripts))
                ;; clear scripts ready for next timestep
                (set! scripts '()))))))

    \layout {
      \context {
        \Voice
        \consists #Text_align_engraver
        \override TextScript #'X-offset =
          #ly:self-alignment-interface::aligned-on-x-parent
        \override TextScript #'self-alignment-X = #CENTER
      }
    }

    \new Staff <<
      \relative c'' {
        \override NoteColumn #'force-hshift = #3
        c1-\markup { \arrow-head #Y #DOWN ##t }
      }
      \\
      \relative c' {
        a4 a-\markup { \huge ^ } a a
      }
    >>

## Changing a single note’s size in a chord

Individual note heads in a chord can be modified with the `\tweak` command inside a chord, by altering the `font-size` property.

Inside the chord (within the brackets `< >`), before the note to be altered, place the `\tweak` command, followed by `#'font-size` and define the proper size like `#-2` (a tiny note head).

    \relative c' {
      <\tweak #'font-size #+2 c e g c \tweak #'font-size #-2 e>1^\markup { A tiny e }_\markup { A big c }
    }

## Changing form of multi-measure rests

If there are ten or fewer measures of rests, a series of longa and breve rests (called in German “Kirchenpausen” - church rests) is printed within the staff; otherwise a simple line is shown. This default number of ten may be changed by overriding the `expand-limit` property.

    \relative c'' {
      \compressFullBarRests
      R1*2 | R1*5 | R1*9
      \override MultiMeasureRest #'expand-limit = #3
      R1*2 | R1*5 | R1*9
    }

## Changing properties for individual grobs

The `\applyOutput` command allows the tuning of any layout object, in any context. It requires a Scheme function with three arguments.

    #(define (mc-squared grob grob-origin context)
      (let ((sp (ly:grob-property grob 'staff-position)))
        (if (grob::has-interface grob 'note-head-interface)
          (begin
            (ly:grob-set-property! grob 'stencil
              (grob-interpret-markup grob
                (make-lower-markup 0.5
                  (case sp
                    ((-5) "m")
                    ((-3) "c ")
                    ((-2) (make-smaller-markup (make-bold-markup "2")))
                    (else "bla")))))))))

    \relative c' {
      <d f g b>2
      \applyOutput #'Voice #mc-squared
      <d f g b>2
    }

## Changing the default text font family

The default font families for text can be overridden with `make-pango-font-tree`.

    \paper {
      % change for other default global staff size.
      myStaffSize = #20
      %{
         run
             lilypond -dshow-available-fonts blabla
         to show all fonts available in the process log.
      %}

      #(define fonts
        (make-pango-font-tree "Times New Roman"
                              "Nimbus Sans"
                              "Luxi Mono"
    ;;                        "Helvetica"
    ;;                        "Courier"
         (/ myStaffSize 20)))
    }

    \relative c'' {
      c4^\markup {
        roman: foo \bold bla \italic bar \italic \bold baz
      }
      c'4_\markup {
        \override #'(font-family . sans)
        {
          sans: foo \bold bla \italic bar \italic \bold baz
        }
      }
      c'2^\markup {
        \override #'(font-family . typewriter)
        {
          mono: foo \bold bla \italic bar \italic \bold baz
        }
      }
    }

## Changing the staff size

Though the simplest way to resize staves is to use `#(set-global-staff-size xx)`, an individual staff’s size can be changed by scaling the properties `'staff-space` and `fontSize`.

    <<
      \new Staff {
        \relative c'' {
          \dynamicDown
          c8\ff c c c c c c c
        }
      }
      \new Staff \with {
        fontSize = #-3
        \override StaffSymbol #'staff-space = #(magstep -3)
      } {
        \clef bass
        c8 c c c c\f c c c
      }
    >>

## Changing the tempo without a metronome mark

To change the tempo in MIDI output without printing anything, make the metronome mark invisible.

    \score {
      \new Staff \relative c' {
        \tempo 4 = 160
        c4 e g b
        c4 b d c
        \set Score.tempoHideNote = ##t
        \tempo 4 = 96
        d,4 fis a cis
        d4 cis e d
      }
      \layout { }
      \midi { }
    }

## Changing the text for sustain markings

`Staff.pedalSustainStrings` can be used to set the text used for pedal down and up. Note that the only valid strings are those found in the list of pedal glyphs - the values used this snippet constitute an exhaustive list.

    sustainNotes = { c4\sustainOn d e\sustainOff\sustainOn f\sustainOff }

    \relative c' {
      \sustainNotes
      \set Staff.pedalSustainStrings = #'("P" "P-" "-")
      \sustainNotes
      \set Staff.pedalSustainStrings = #'("d" "de" "e")
      \sustainNotes
      \set Staff.pedalSustainStrings = #'("M" "M-" "-")
      \sustainNotes
      \set Staff.pedalSustainStrings = #'("Ped" "*Ped" "*")
      \sustainNotes
    }

## 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 }
    }

## Controlling tuplet bracket visibility

The default behavior of tuplet-bracket visibility is to print a bracket unless there is a beam of the same length as the tuplet. To control the visibility of tuplet brackets, set the property `'bracket-visibility` to either `#t` (always print a bracket), `#f` (never print a bracket) or `#'if-no-beam` (only print a bracket if there is no beam).

    music = \relative c'' {
      \times 2/3 { c16[ d e } f8]
      \times 2/3 { c8 d e }
      \times 2/3 { c4 d e }
    }

    \new Voice {
      \relative c' {
        << \music s4^"default" >>
        \override TupletBracket #'bracket-visibility = #'if-no-beam
        << \music s4^"'if-no-beam" >>
        \override TupletBracket #'bracket-visibility = ##t
        << \music s4^"#t" >>
        \override TupletBracket #'bracket-visibility = ##f
        << \music s4^"#f" >>
      }
    }

## 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`. The value of `halign` is used to position the turn horizontally.

    \relative c'' {
      \once \override TextScript #'avoid-slur = #'inside
      \once \override TextScript #'outside-staff-priority = ##f
      c2(^\markup \tiny \override #'(baseline-skip . 1) {
        \halign #-4
        \center-column {
          \sharp
          \musicglyph #"scripts.turn"
        }
      }
      d4.) c8
    }

## 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 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
    }

## Custodes

Custodes may be engraved in various styles.

    \layout { ragged-right = ##t }

    \new Staff \with { \consists "Custos_engraver" } \relative c' {
      \override Staff.Custos #'neutral-position = #4

      \override Staff.Custos #'style = #'hufnagel
      c1^"hufnagel" \break
      <d a' f'>1

      \override Staff.Custos #'style = #'medicaea
      c1^"medicaea" \break
      <d a' f'>1

      \override Staff.Custos #'style = #'vaticana
      c1^"vaticana" \break
      <d a' f'>1

      \override Staff.Custos #'style = #'mensural
      c1^"mensural" \break
      <d a' f'>1
    }

## Customizing fretboard fret diagrams

Fret diagram properties can be set through `'fret-diagram-details`. For FretBoard fret diagrams, overrides are applied to the `FretBoards.FretBoard` object. Like `Voice`, `FretBoards` is a bottom level context, therefore can be omitted in property overrides.

    \include "predefined-guitar-fretboards.ly"
    \storePredefinedDiagram #default-fret-table \chordmode { c' }
                            #guitar-tuning
                            #"x;1-1-(;3-2;3-3;3-4;1-1-);"
    <<
      \new ChordNames {
        \chordmode { c1 | c | c | d }
      }
      \new FretBoards {
        % Set global properties of fret diagram
        \override FretBoards.FretBoard #'size = #'1.2
        \override FretBoard
          #'(fret-diagram-details finger-code) = #'in-dot
        \override FretBoard
          #'(fret-diagram-details dot-color) = #'white
        \chordmode {
          c
          \once \override FretBoard #'size = #'1.0
          \once \override FretBoard
            #'(fret-diagram-details barre-type) = #'straight
          \once \override FretBoard
            #'(fret-diagram-details dot-color) = #'black
          \once \override FretBoard
            #'(fret-diagram-details finger-code) = #'below-string
          c'
          \once \override FretBoard
            #'(fret-diagram-details barre-type) = #'none
          \once \override FretBoard
            #'(fret-diagram-details number-type) = #'arabic
          \once \override FretBoard
            #'(fret-diagram-details orientation) = #'landscape
          \once \override FretBoard
            #'(fret-diagram-details mute-string) = #"M"
          \once \override FretBoard
            #'(fret-diagram-details label-dir) = #LEFT
          \once \override FretBoard
            #'(fret-diagram-details dot-color) = #'black
          c'
          \once \override FretBoard
            #'(fret-diagram-details finger-code) = #'below-string
          \once \override FretBoard
            #'(fret-diagram-details dot-radius) = #0.35
          \once \override FretBoard
            #'(fret-diagram-details dot-position) = #0.5
          \once \override FretBoard
            #'(fret-diagram-details fret-count) = #3
          d
        }
      }
      \new Voice {
        c'1 | c' | c' | d'
      }
    >>

## Customizing markup fret diagrams

Fret diagram properties can be set through `'fret-diagram-details`. For markup fret diagrams, overrides can be applied to the `Voice.TextScript` object or directly to the markup.

    <<
      \chords { c1 | c | c | d }

      \new Voice = "mel" {
        \textLengthOn
        % Set global properties of fret diagram
        \override TextScript #'size = #'1.2
        \override TextScript
          #'(fret-diagram-details finger-code) = #'in-dot
        \override TextScript
          #'(fret-diagram-details dot-color) = #'white

        %% C major for guitar, no barre, using defaults
           % terse style
        c'1^\markup { \fret-diagram-terse #"x;3-3;2-2;o;1-1;o;" }

        %% C major for guitar, barred on third fret
           % verbose style
           % size 1.0
           % roman fret label, finger labels below string, straight barre
        c'1^\markup {
          % standard size
          \override #'(size . 1.0) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-lower)
                         (finger-code . in-dot)
                         (barre-type . straight))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, barred on third fret
           % verbose style
           % landscape orientation, arabic numbers, M for mute string
           % no barre, fret label down or left, small mute label font
        c'1^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (number-type . arabic)
                       (label-dir . -1)
                       (mute-string . "M")
                       (orientation . landscape)
                       (barre-type . none)
                       (xo-font-magnification . 0.4)
                       (xo-padding . 0.3))) {
            \fret-diagram-verbose #'((mute 6)
                                     (place-fret 5 3 1)
                                     (place-fret 4 5 2)
                                     (place-fret 3 5 3)
                                     (place-fret 2 5 4)
                                     (place-fret 1 3 1)
                                     (barre 5 1 3))
          }
        }

        %% simple D chord
           % terse style
           % larger dots, centered dots, fewer frets
           % label below string
        d'1^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }
      }
    >>

## Display bracket with only one staff in a system

If there is only one staff in one of the staff types `ChoirStaff` or `StaffGroup`, the bracket and the starting bar line will not be displayed as standard behavior. This can be changed by overriding the relevant properties.

Note that in contexts such as `PianoStaff` and `GrandStaff` where the systems begin with a brace instead of a bracket, another property has to be set, as shown on the second system in the example.

    \markup \left-column {
      \score {
        \new StaffGroup <<
          % Must be lower than the actual number of staff lines
          \override StaffGroup.SystemStartBracket #'collapse-height = #1
          \override Score.SystemStartBar #'collapse-height = #1
          \new Staff {
            c'1
          }
        >>
        \layout { }
      }
      \null
      \score {
        \new PianoStaff <<
          \override PianoStaff.SystemStartBrace #'collapse-height = #1
          \override Score.SystemStartBar #'collapse-height = #1
          \new Staff {
            c'1
          }
        >>
        \layout { }
      }
    }

## Displaying grob ancestry

When working with grob callbacks, it can be helpful to understand a grob’s “ancestry”. Most grobs have “parents” which influence the positioning of the grob. X- and Y-parents influence the horizontal and vertical positions for the grob, respectively. Additionally, each parent may have parents of its own.

Unfortunately, there are several aspects of a grob’s ancestry that can lead to confusion:

- The types of parents a grob has may depend on context.
- For some grobs, the X- and Y-parents are the same.
- A particular “ancestor” may be related to a grob in multiple ways.
- The concept of “generations” is misleading.

For example, the `System` grob can be both parent (on the Y-side) and grandparent (twice on the X-side) to a `VerticalAlignment` grob.

This macro prints (to the console) a textual representation of a grob’s ancestry.

When called this way

>     {
>        \once \override NoteHead #'before-line-breaking = #display-ancestry
>        c4
>     }

The following output is generated:

>     ------------------------------------

>     NoteHead X,Y: NoteColumn
>         X: PaperColumn
>            X,Y: System
>         Y: VerticalAxisGroup
>            X: NonMusicalPaperColumn
>               X,Y: System
>            Y: VerticalAlignment
>               X: NonMusicalPaperColumn
>                  X,Y: System
>               Y: System

    #(define (grob-name grob)
       (if (ly:grob? grob)
           (assoc-ref (ly:grob-property grob 'meta) 'name)
           #f))

    #(define (get-ancestry grob)
       (if (not (null? (ly:grob-parent grob X)))
           (list (grob-name grob)
                 (get-ancestry (ly:grob-parent grob X))
                 (get-ancestry (ly:grob-parent grob Y)))
           (grob-name grob)))

    #(define (format-ancestry lst padding)
       (string-append
        (symbol->string (car lst))
        "\n"
        (let ((X-ancestry
               (if (list? (cadr lst))
                   (format-ancestry (cadr lst) (+ padding 3))
                   (symbol->string (cadr lst))))
              (Y-ancestry
               (if (list? (caddr lst))
                   (format-ancestry (caddr lst) (+ padding 3))
                   (symbol->string (caddr lst)))))
          (if (equal? X-ancestry Y-ancestry)
              (string-append
               (format #f "~&")
               (make-string padding #\space)
               "X,Y: "
               (if (list? (cadr lst))
                   (format-ancestry (cadr lst) (+ padding 5))
                   (symbol->string (cadr lst))))
              (string-append
               (format #f "~&")
               (make-string padding #\space)
               "X: " X-ancestry
               "\n"
               (make-string padding #\space)
               "Y: " Y-ancestry
               (format #f "~&"))))
        (format #f "~&")))

    #(define (display-ancestry grob)
       (display
        (string-append
         (format #f "~3&~a~2%" (make-string 36 #\-))
         (format-ancestry (get-ancestry grob) 0)
         (format #f "~2&"))))

    \relative c' {
      \once \override NoteHead #'before-line-breaking = #display-ancestry
      f4
      \once \override Accidental #'before-line-breaking = #display-ancestry
      \once \override Arpeggio #'before-line-breaking = #display-ancestry
      <f as c>4\arpeggio
    }

## Dotted harmonics

Artificial harmonics using `\harmonic` do not show dots. To override this behavior, set the context property `harmonicDots`.

    \relative c''' {
      \time 3/4
      \key f \major
      \set harmonicDots = ##t
      <bes f'\harmonic>2. ~
      <bes f'\harmonic>4. <a e'\harmonic>8( <gis dis'\harmonic> <g d'\harmonic>)
      <fis cis'\harmonic>2.
      <bes f'\harmonic>2.
    }

## Drawing boxes around grobs

The `print-function` can be overridden to draw a box around an arbitrary grob.

    \relative c'' {
      \override TextScript #'stencil =
        #(make-stencil-boxer 0.1 0.3 ly:text-interface::print)
      c'4^"foo"

      \override Stem #'stencil =
        #(make-stencil-boxer 0.05 0.25 ly:stem::print)
      \override Score.RehearsalMark  #'stencil =
        #(make-stencil-boxer 0.15 0.3 ly:text-interface::print)
      b8

      \revert Stem #'stencil
      c4. c4
      \mark "F"
      c1
    }

## Drawing circles around various objects

The `\circle` markup command draws circles around various objects, for example fingering indications. For other objects, specific tweaks may be required: this example demonstrates two strategies for rehearsal marks and measure numbers.

    \relative c' {
      c1
      \set Score.markFormatter =
        #(lambda (mark context)
                 (make-circle-markup (format-mark-numbers mark context)))
      \mark \default

      c2 d^\markup {
        \override #'(thickness . 3) {
          \circle \finger 2
        }
      }
      \override Score.BarNumber #'break-visibility = #all-visible
      \override Score.BarNumber #'stencil =
        #(make-stencil-circler 0.1 0.25 ly:text-interface::print)
    }

## 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 (parser location mymarkup) (markup?)
       (make-music 'CrescendoEvent
                   'span-direction START
                   'span-type 'text
                   'span-text mymarkup))
    mydecresc =
    #(define-music-function (parser location 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\!
    }

## Fine-tuning pedal brackets

The appearance of pedal brackets may be altered in different ways.

    \paper { ragged-right = ##f }
    \relative c'' {
      c2\sostenutoOn c
      c2\sostenutoOff c
      \once \override Staff.PianoPedalBracket #'shorten-pair = #'(-7 . -2)
      c2\sostenutoOn c
      c2\sostenutoOff c
      \once \override Staff.PianoPedalBracket #'edge-height = #'(0 . 3)
      c2\sostenutoOn c
      c2\sostenutoOff c
    }

## Forcing horizontal shift of notes

When the typesetting engine cannot cope, the following syntax can be used to override typesetting decisions. The units of measure used here are staff spaces.

    \relative c' <<
      {
        <d g>2 <d g>
      }
      \\
      {
        <b f'>2
        \once \override NoteColumn #'force-hshift = #1.7
        <b f'>2
      }
    >>

## Fret diagrams explained and developed

This snippet shows many possibilities for obtaining and tweaking fret diagrams.

    <<
      \chords {
        a2 a
        \repeat unfold 3 {
          c c c d d
        }
      }

      \new Voice = "mel" {
        \textLengthOn
        % Set global properties of fret diagram
        \override TextScript #'size = #1.2
        \override TextScript
          #'fret-diagram-details #'finger-code = #'below-string
        \override TextScript #'fret-diagram-details #'dot-color = #'black

        %% A chord for ukulele
        a'2^\markup {
          \override #'(fret-diagram-details . (
                       (string-count . 4)
                       (dot-color . white)
                       (finger-code . in-dot))) {
            \fret-diagram #"4-2-2;3-1-1;2-o;1-o;"
          }
        }

        %% A chord for ukulele, with formatting defined in definition string
        %  1.2 * size, 4 strings, 4 frets, fingerings below string
        %  dot radius .35 of fret spacing, dot position 0.55 of fret spacing
        a'2^\markup {
          \override #'(fret-diagram-details . (
                       (dot-color . white)
                       (open-string . "o"))) {
            \fret-diagram #"s:1.2;w:4;h:3;f:2;d:0.35;p:0.55;4-2-2;3-1-1;2-o;1-o;"
          }
        }

          %% These chords will be in normal orientation

        %% C major for guitar, barred on third fret
        %  verbose style
        %  roman fret label, finger labels below string, straight barre
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-lower)
                         (finger-code . below-string)
                         (barre-type . straight))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, barred on third fret
        %% Double barre used to test barre function
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . arabic)
                         (dot-label-font-mag . 0.9)
                         (finger-code . in-dot)
                         (fret-label-font-mag . 0.6)
                         (fret-label-vertical-offset . 0)
                         (label-dir . -1)
                         (mute-string . "M")
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 4 2 5)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, with capo on third fret
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-upper)
                         (dot-label-font-mag . 0.9)
                         (finger-code . none)
                         (fret-label-vertical-offset . 0.5)
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (capo 3)
                                       (open 5)
                                       (place-fret 4 5 1)
                                       (place-fret 3 5 2)
                                       (place-fret 2 5 3)
                                       (open 1))
            }
          }
        }

        %% simple D chord
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (string-thickness-factor . 0.3)
                       (dot-position . 0.5)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

        %% simple D chord, large top fret thickness
        d'2^\markup  {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (top-fret-thickness . 7)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

          % These chords will be in landscape orientation
        \override TextScript
           #'fret-diagram-details #'orientation = #'landscape

        %% C major for guitar, barred on third fret
        %  verbose style
        %  roman fret label, finger labels below string, straight barre
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-lower)
                         (finger-code . below-string)
                         (barre-type . straight))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, barred on third fret
        %% Double barre used to test barre function
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . arabic)
                         (dot-label-font-mag . 0.9)
                         (finger-code . in-dot)
                         (fret-label-font-mag . 0.6)
                         (fret-label-vertical-offset . 0)
                         (label-dir . -1)
                         (mute-string . "M")
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 4 2 5)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, with capo on third fret
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-upper)
                         (dot-label-font-mag . 0.9)
                         (finger-code . none)
                         (fret-label-vertical-offset . 0.5)
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (capo 3)
                                       (open 5)
                                       (place-fret 4 5 1)
                                       (place-fret 3 5 2)
                                       (place-fret 2 5 3)
                                       (open 1))
            }
          }
        }

        %% simple D chord
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

        %% simple D chord, large top fret thickness
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (top-fret-thickness . 7)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

          % These chords will be in opposing-landscape orientation
        \override TextScript #'fret-diagram-details
                               #'orientation = #'opposing-landscape

        %% C major for guitar, barred on third fret
        %  verbose style
        %  roman fret label, finger labels below string, straight barre
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-lower)
                         (finger-code . below-string)
                         (barre-type . straight))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, barred on third fret
        %% Double barre used to test barre function
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . arabic)
                         (dot-label-font-mag . 0.9)
                         (finger-code . in-dot)
                         (fret-label-font-mag . 0.6)
                         (fret-label-vertical-offset . 0)
                         (label-dir . -1)
                         (mute-string . "M")
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 4 2 5)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, with capo on third fret
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-upper)
                         (dot-label-font-mag . 0.9)
                         (finger-code . none)
                         (fret-label-vertical-offset . 0.5)
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (capo 3)
                                       (open 5)
                                       (place-fret 4 5 1)
                                       (place-fret 3 5 2)
                                       (place-fret 2 5 3)
                                       (open 1))
            }
          }
        }

        %% simple D chord
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

        %% simple D chord, large top fret thickness
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (top-fret-thickness . 7)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }
      }
    >>

## Generating custom flags

The `flag` property of the Stem grob can be set to a custom scheme function to generate the glyph for the flag.

    #(define-public (weight-flag stem-grob)
       (let* ((log (- (ly:grob-property stem-grob 'duration-log) 2))
              (is-up? (eqv? (ly:grob-property stem-grob 'direction) UP))
              (yext (if is-up? (cons (* log -0.8) 0) (cons 0 (* log 0.8))))
              (flag-stencil (make-filled-box-stencil '(-0.4 . 0.4) yext))
              (stroke-style (ly:grob-property stem-grob 'stroke-style))
              (stroke-stencil (if (equal? stroke-style "grace")
                                  (make-line-stencil 0.2 -0.9 -0.4 0.9 -0.4)
                                  empty-stencil)))
         (ly:stencil-add flag-stencil stroke-stencil)))

    % Create a flag stencil by looking up the glyph from the font
    #(define (inverted-flag stem-grob)
       (let* ((dir (if (eqv? (ly:grob-property stem-grob 'direction) UP) "d" "u"))
              (flag (retrieve-glyph-flag "" dir "" stem-grob))
              (line-thickness (ly:staff-symbol-line-thickness stem-grob))
              (stem-thickness (ly:grob-property stem-grob 'thickness))
              (stem-width (* line-thickness stem-thickness))
              (stroke-style (ly:grob-property stem-grob 'stroke-style))
              (stencil (if (null? stroke-style)
                           flag
                           (add-stroke-glyph flag stem-grob dir stroke-style "")))
              (rotated-flag (ly:stencil-rotate-absolute stencil 180 0 0)))
         (ly:stencil-translate rotated-flag (cons (- (/ stem-width 2)) 0))))

    snippetexamplenotes = { \autoBeamOff c'8 d'16 c'32 d'64 \acciaccatura {c'8} d'64 }

    {
      \override Score.RehearsalMark #'self-alignment-X = #LEFT
      \time 1/4
      \mark "Normal flags"
      \snippetexamplenotes

      \mark "Custom flag: inverted"
      \override Stem #'flag = #inverted-flag
      \snippetexamplenotes

      \mark "Custom flag: weight"
      \override Stem #'flag = #weight-flag
      \snippetexamplenotes

      \mark "Revert to normal"
      \revert Stem #'flag
      \snippetexamplenotes
    }

## 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\!
    }

## 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.

    \header { title = "Horizontally aligning custom dynamics" }

    \paper { ragged-right = ##f }

    % 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")))

    \context StaffGroup <<
      \context Staff = "s" <<
        \set Staff.instrumentName = #"Normal"
        \relative c'' {
          \key es \major
          c4\pp c\p c c | c\ff c c\pp c
        }
      >>
      \context Staff = "sMarkup" <<
        \set Staff.instrumentName = \markup \column { Normal markup }
        \relative c'' {
          \key es \major
          c4-\semppMarkup c\p c c | c\ff c c-\semppMarkup c
        }
      >>
      \context Staff = "sK" <<
        \set Staff.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
        }
      >>
      \context Staff = "sT" <<
        \set Staff.instrumentName = \markup \column { Right padding }
        \relative c'' {
          \key es \major
          c4\semppT c\p c c | c\ff c c\semppT c
        }
      >>
      \context Staff = "sM" <<
        \set Staff.instrumentName = \markup \column { Setting dimension "to zero" }
        \relative c'' {
          \key es \major
          c4\semppM c\p c c | c\ff c c\semppM c
        }
      >>
      \context Staff = "sG" <<
        \set Staff.instrumentName = \markup \column { Shifting inside dynamics }
        \relative c'' {
          \key es \major
          c4\semppG c\p c c | c\ff c c\semppG c
        }
      >>
      \context Staff = "sMII" <<
        \set Staff.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
        }
      >>
    >>

## How to change fret diagram position

If you want to move the position of a fret diagram, for example, to avoid collision, or to place it between two notes, you have various possibilities:

1) modify #’padding or #’extra-offset values (as shown in the first snippet)

2) you can add an invisible voice and attach the fret diagrams to the invisible notes in that voice (as shown in the second example).

If you need to move the fret according with a rythmic position inside the bar (in the example, the third beat of the measure) the second example is better, because the fret is aligned with the third beat itself.

    harmonies = \chordmode
    {
      a8:13
    % THE FOLLOWING IS THE COMMAND TO MOVE THE CHORD NAME
      \once \override ChordNames.ChordName #'extra-offset = #'(10 . 0)
      b8:13 s2.
    % THIS LINE IS THE SECOND METHOD
        s4 s4  b4:13
    }

    \score
    {
      <<
        \context ChordNames \harmonies
        \context Staff
        {a8^\markup { \fret-diagram  #"6-x;5-0;4-2;3-0;2-0;1-2;"  }
    % THE FOLLOWING IS THE COMMAND TO MOVE THE FRET DIAGRAM
         \once \override TextScript #'extra-offset = #'(10 . 0)
         b4.~^\markup { \fret-diagram  #"6-x;5-2;4-4;3-2;2-2;1-4;"  } b4. a8\break
    % HERE IS THE SECOND METHOD
         <<
           { a8 b4.~ b4. a8}
           { s4 s4 s4^\markup { \fret-diagram  #"6-x;5-2;4-4;3-2;2-2;1-4;"  }
           }
         >>
       }
      >>
    }

## 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 { \musicglyph #"scripts.ufermata" \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
    }

## Keep change clefs full sized

When a clef is changed, the clef sign displayed is smaller than the initial clef. This can be overridden with `full-size-change`.

    \relative c' {
      \clef "treble"
      c1
      \clef "bass"
      c1
      \clef "treble"
      c1
      \override Staff.Clef #'full-size-change = ##t
      \clef "bass"
      c1
      \clef "treble"
      c1
      \revert Staff.Clef #'full-size-change
      \clef "bass"
      c1
      \clef "treble"
      c1
    }

## 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 an object invisible with the ’transparent property

Setting the `transparent` property will cause an object to be printed in “invisible ink”: the object is not printed, but all its other behavior is retained. The object still takes up space, it takes part in collisions, and slurs, ties and beams can be attached to it.

This snippet demonstrates how to connect different voices using ties. Normally, ties only connect two notes in the same voice. By introducing a tie in a different voice, and blanking the first up-stem in that voice, the tie appears to cross voices.

    \relative c'' {
      \time 2/4
      <<
        {
          \once \override Stem #'transparent = ##t
          \once \override Stem #'length = #8
          b8 ~ b\noBeam
          \once \override Stem #'transparent = ##t
          \once \override Stem #'length = #8
          g8 ~ g\noBeam
        }
        \\
        {
          b8 g g e
        }
      >>
    }

## Manually controlling beam positions

Beam positions may be controlled manually, by overriding the `positions` setting of the `Beam` grob.

    \relative c' {
      \time 2/4
      % from upper staff-line (position 2) to center (position 0)
      \override Beam #'positions = #'(2 . 0)
      c8 c
      % from center to one above center (position 1)
      \override Beam #'positions = #'(0 . 1)
      c8 c
    }

## Mensurstriche layout (bar lines between the staves)

The mensurstriche-layout where the bar lines do not show on the staves but between staves can be achieved with a `StaffGroup` instead of a `ChoirStaff`. The bar line on staves is blanked out by setting the `transparent` property.

    global = {
      \override Staff.BarLine #'transparent = ##t
      s1 s
      % the final bar line is not interrupted
      \revert Staff.BarLine #'transparent
      \bar "|."
    }
    \new StaffGroup \relative c'' {
      <<
        \new Staff { << \global { c1 c } >> }
        \new Staff { << \global { c c } >> }
      >>
    }

## Moving dotted notes in polyphony

When a dotted note in the upper voice is moved to avoid a collision with a note in another voice, the default is to move the upper note to the right. This behaviour can be over-ridden by using the `prefer-dotted-right` property of `NoteCollision`.

    \new Staff \relative c' <<
      { f2. f4
        \override Staff.NoteCollision #'prefer-dotted-right = ##f
        f2. f4
        \override Staff.NoteCollision #'prefer-dotted-right = ##t
        f2. f4
      }
      \\
      { e4 e e e e e e e e e e e}
    >>

## 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)
    }

## Nesting staves

The property `systemStartDelimiterHierarchy` can be used to make more complex nested staff groups. The command `\set StaffGroup.systemStartDelimiterHierarchy` takes an alphabetical list of the number of staves produced. Before each staff a system start delimiter can be given. It has to be enclosed in brackets and takes as much staves as the brackets enclose. Elements in the list can be omitted, but the first bracket takes always the complete number of staves. The possibilities are `SystemStartBar`, `SystemStartBracket`, `SystemStartBrace`, and `SystemStartSquare`.

    \new StaffGroup
    \relative c'' <<
      \set StaffGroup.systemStartDelimiterHierarchy
        = #'(SystemStartSquare (SystemStartBrace (SystemStartBracket a
                                 (SystemStartSquare b)  ) c ) d)
      \new Staff { c1 }
      \new Staff { c1 }
      \new Staff { c1 }
      \new Staff { c1 }
      \new Staff { c1 }
    >>

## Percent repeat count visibility

Percent repeat counters can be shown at regular intervals by setting the context property `repeatCountVisibility`.

    \relative c'' {
      \set countPercentRepeats = ##t
      \set repeatCountVisibility = #(every-nth-repeat-count-visible 5)
      \repeat percent 10 { c1 } \break
      \set repeatCountVisibility = #(every-nth-repeat-count-visible 2)
      \repeat percent 6 { c1 d1 }
    }

## 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 multi-measure rests

Unlike ordinary rests, there is no predefined command to change the staff position of a multi-measure rest symbol of either form by attaching it to a note. However, in polyphonic music multi-measure rests in odd-numbered and even-numbered voices are vertically separated. The positioning of multi-measure rests can be controlled as follows:

    \relative c'' {
      % MMR - Multi-Measure Rest
      % MMRs by default are set under the fourth line
      R1
      % They can be moved with an override
      \override MultiMeasureRest #'staff-position = #-2
      R1
      % A value of 0 is the default position;
      % the following trick moves the rest to the center line
      \override MultiMeasureRest #'staff-position = #-0.01
      R1
      % MMRs in odd-numbered voices are under the top line
      << { R1 } \\ { a1 } >>
      % MMRs in even-numbered voices are under the bottom line
      << { c1 } \\ { R1 } >>
      % They remain separated even in empty measures
      << { R1 } \\ { R1 } >>
      % This brings them together even though there are two voices
      \compressFullBarRests
      <<
        \revert MultiMeasureRest #'staff-position
        { R1*3 }
        \\
        \revert MultiMeasureRest #'staff-position
        { R1*3 }
      >>
    }

## 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 a repeat sign at the beginning of a piece

A `|:` bar line can be printed at the beginning of a piece, by overriding the relevant property:

    \relative c'' {
      \once \override Score.BreakAlignment #'break-align-orders =
        #(make-vector 3 '(instrument-name
                          left-edge
                          ambitus
                          breathing-sign
                          clef
                          key-signature
                          time-signature
                          staff-bar
                          custos))
      \once \override Staff.TimeSignature #'space-alist =
        #'((first-note . (fixed-space . 2.0))
           (right-edge . (extra-space . 0.5))
           ;; free up some space between time signature
           ;; and repeat bar line
           (staff-bar . (extra-space . 1)))
      \bar "|:"
      c1
      d1
      d4 e f g
    }

## Printing bar numbers inside boxes or circles

Bar numbers can also be printed inside boxes or circles.

    \relative c' {
      % Prevent bar numbers at the end of a line and permit them elsewhere
      \override Score.BarNumber #'break-visibility = #end-of-line-invisible
      \set Score.barNumberVisibility = #(every-nth-bar-number-visible 4)

      % Increase the size of the bar number by 2
      \override Score.BarNumber #'font-size = #2

      % Draw a box round the following bar number(s)
      \override Score.BarNumber #'stencil
        = #(make-stencil-boxer 0.1 0.25 ly:text-interface::print)
      \repeat unfold 5 { c1 }

      % Draw a circle round the following bar number(s)
      \override Score.BarNumber #'stencil
        = #(make-stencil-circler 0.1 0.25 ly:text-interface::print)
      \repeat unfold 4 { c1 } \bar "|."
    }

## 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 { 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
    }

## Printing note names with and without an octave marker

The `NoteNames` context can be used to print the text value of notes. The `printOctaveNames` property turns on or off the representation of the octave of the note.

    scale = \relative c' {
      a4 b c d
      e4 f g a
    }

    \new Staff {
      <<
        \scale
        \context NoteNames {
          \set printOctaveNames = ##f
          \scale
        }
      >>
      R1
      <<
        \scale
        \context NoteNames {
          \set printOctaveNames = ##t
          \scale
        }
      >>
    }

## Proportional strict notespacing

If `strict-note-spacing` is set spacing of notes is not influenced by bars or clefs within a system. Rather, they are placed just before the note that occurs at the same time. This may cause collisions.

    \relative c'' <<
      \override Score.SpacingSpanner #'strict-note-spacing = ##t
      \set Score.proportionalNotationDuration = #(ly:make-moment 1 16)
      \new Staff {
        c8[ c \clef alto c c \grace { d16 } c8 c] c4
        c2 \grace { c16[ c16] } c2
      }
      \new Staff {
        c2 \times 2/3 { c8 \clef bass cis,, c } c4
        c1
      }
    >>

## Removing connecting bar lines on StaffGroup PianoStaff or GrandStaff

By default, bar lines in StaffGroup, PianoStaff, or GrandStaff groups are connected between the staves. This behaviour can be overridden on a staff-by-staff basis.

    \relative c' {
      \new StaffGroup <<
        \new Staff {
          e1 | e
          \once \override Staff.BarLine #'allow-span-bar = ##f
          e1 | e | e
        }
        \new Staff {
          c1 | c | c
          \once \override Staff.BarLine #'allow-span-bar = ##f
          c1 | c
        }
        \new Staff {
          a1 | a | a | a | a
        }
      >>
    }

## Removing the first empty line

The first empty staff can also be removed from the score by setting the `VerticalAxisGroup` property `remove-first`. This can be done globally inside the `\layout` block, or locally inside the specific staff that should be removed. In the latter case, you have to specify the context (`Staff` applies only to the current staff) in front of the property.

The lower staff of the second staff group is not removed, because the setting applies only to the specific staff inside of which it is written.

    \layout {
      \context {
        \Staff \RemoveEmptyStaves
        % To use the setting globally, uncomment the following line:
        % \override VerticalAxisGroup #'remove-first = ##t
      }
    }
    \new StaffGroup <<
      \new Staff \relative c' {
        e4 f g a \break
        c1
      }
      \new Staff {
        % To use the setting globally, comment this line,
        % uncomment the line in the \layout block above
        \override Staff.VerticalAxisGroup #'remove-first = ##t
        R1 \break
        R
      }
    >>
    \new StaffGroup <<
      \new Staff \relative c' {
        e4 f g a \break
        c1
      }
      \new Staff {
        R1 \break
        R
      }
    >>

## Rest styles

Rests may be used in various styles.

    \layout {
      indent = 0
      \context {
        \Staff
        \remove "Time_signature_engraver"
      }
    }

    \new Staff \relative c {
      \cadenzaOn
      \override Staff.Rest #'style = #'mensural
      r\maxima^\markup \typewriter { mensural }
      r\longa r\breve r1 r2 r4 r8 r16 s32 s64 s128 s128
      \bar ""

      \override Staff.Rest #'style = #'neomensural
      r\maxima^\markup \typewriter { neomensural }
      r\longa r\breve r1 r2 r4 r8 r16 s32 s64 s128 s128
      \bar ""

      \override Staff.Rest #'style = #'classical
      r\maxima^\markup \typewriter { classical }
      r\longa r\breve r1 r2 r4 r8 r16 r32 r64 r128 s128
      \bar ""

      \override Staff.Rest  #'style = #'default
      r\maxima^\markup \typewriter { default }
      r\longa r\breve r1 r2 r4 r8 r16 r32 r64 r128 s128
    }

## Rhythmic slashes

In “simple” lead-sheets, sometimes no actual notes are written, instead only “rhythmic patterns” and chords above the measures are notated giving the structure of a song. Such a feature is for example useful while creating/transcribing the structure of a song and also when sharing lead sheets with guitarists or jazz musicians. The standard support for this using `\repeat percent` is unsuitable here since the first beat has to be an ordinary note or rest. This example shows two solutions to this problem, by redefining ordinary rests to be printed as slashes. (If the duration of each beat is not a quarter note, replace the `r4` in the definitions with a rest of the appropriate duration).

    % Macro to print single slash
    rs = {
      \once \override Rest #'stencil = #ly:percent-repeat-item-interface::beat-slash
      \once \override Rest #'thickness = #0.48
      \once \override Rest #'slope = #1.7
      r4
    }

    % Function to print a specified number of slashes
    comp = #(define-music-function (parser location count) (integer?)
      #{
        \override Rest #'stencil = #ly:percent-repeat-item-interface::beat-slash
        \override Rest #'thickness = #0.48
        \override Rest #'slope = #1.7
        \repeat unfold $count { r4 }
        \revert Rest #'stencil
      #}
    )

    \score {
      \relative c' {
        c4 d e f |
        \rs \rs \rs \rs |
        \comp #4 |
      }
    }

## Separating key cancellations from key signature changes

By default, the accidentals used for key cancellations are placed adjacent to those for key signature changes. This behavior can be changed by overriding the `'break-align-orders` property of the `BreakAlignment` grob.

The value of `'break-align-orders` is a vector of length 3, with quoted lists of breakable items as elements. This example only modifies the second list, moving `key-cancellation` before `staff-bar`; by modifying the second list, break alignment behavior only changes in the middle of a system, not at the beginning or the end.

    \new Staff {
      \override Score.BreakAlignment #'break-align-orders =
        #'#((left-edge ambitus breathing-sign clef staff-bar
                       key-cancellation key-signature time-signature custos)

            (left-edge ambitus breathing-sign clef key-cancellation
                       staff-bar key-signature time-signature custos)

            (left-edge ambitus breathing-sign clef key-cancellation
                       key-signature staff-bar time-signature custos))

      \key des \major
      c'1
      \bar "||"
      \key bes \major
      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 system separators

System separators can be inserted between systems. Any markup can be used, but `\slashSeparator` has been provided as a sensible default.

    \paper {
      system-separator-markup = \slashSeparator
    }

    notes = \relative c' {
      c1 | c \break
      c1 | c \break
      c1 | c
    }

    \book {
      \score {
        \new GrandStaff <<
          \new Staff \notes
          \new Staff \notes
        >>
      }
    }

## 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, ignoring the fermata above. However, one can stick scripts (just like fingerings) inside a chord, which means it is possible to have as many articulations as desired. So, the solution is to write the note as a chord and add the articulations inside the `<…>`.

    % The same as \flageolet, just a little smaller
    smallFlageolet =
    #(let ((m (make-articulation "flageolet")))
       (set! (ly:music-property m 'tweaks)
             (acons 'font-size -2
                    (ly:music-property m 'tweaks)))
       m)

    \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
    }

## String number extender lines

Make an extender line for string number indications, showing that a series of notes is supposed to be played all on the same string.

    stringNumberSpanner =
    #(define-music-function (parser location StringNumber) (string?)
      #{
        \override TextSpanner #'style = #'solid
        \override TextSpanner #'font-size = #-5
        \override TextSpanner #'(bound-details left stencil-align-dir-y) = #CENTER
        \override TextSpanner #'(bound-details left text) = \markup { \circle \number $StringNumber }
      #})

    \relative c {
      \clef "treble_8"
      \stringNumberSpanner "5"
      \textSpannerDown
      a8\startTextSpan
      b c d e f\stopTextSpan
      \stringNumberSpanner "4"
      g\startTextSpan a
      bes4 a g2\stopTextSpan
    }

## Suppressing warnings for clashing note columns

If notes from two voices with stems in the same direction are placed at the same position, and both voices have no shift or the same shift specified, the error message ‘`warning: ignoring too many clashing note columns`’ will appear when compiling the LilyPond file. This message can be suppressed by setting the `'ignore-collision` property of the `NoteColumn` object to `#t`.

    ignore = \override NoteColumn #'ignore-collision = ##t

    \relative c' {
      <<
        \ignore
        { \stemDown f2 g }
        \\
        { c2 c, }
      >>
    }

## Time signature in parentheses

The time signature can be enclosed within parentheses.

    \relative c'' {
      \override Staff.TimeSignature #'stencil = #(lambda (grob)
        (bracketify-stencil (ly:time-signature::print grob) Y 0.1 0.2 0.1))
      \time 2/4
      a4 b8 c
    }

## Time signature printing only the numerator as a number (instead of the fraction)

Sometimes, a time signature should not print the whole fraction (e.g. 7/4), but only the numerator (7 in this case). This can be easily done by using `\override Staff.TimeSignature #'style = #'single-digit` to change the style permanently. By using `\revert Staff.TimeSignature #'style`, this setting can be reversed. To apply the single-digit style to only one time signature, use the `\override` command and prefix it with a `\once`.

    \relative c'' {
      \time 3/4
      c4 c c
      % Change the style permanently
      \override Staff.TimeSignature #'style = #'single-digit
      \time 2/4
      c4 c
      \time 3/4
      c4 c c
      % Revert to default style:
      \revert Staff.TimeSignature #'style
      \time 2/4
      c4 c
      % single-digit style only for the next time signature
      \once \override Staff.TimeSignature #'style = #'single-digit
      \time 5/4
      c4 c c c c
      \time 2/4
      c4 c
    }

## Transcription of Ancient music with incipit

As a workaround to get real incipits which are independent from the main score these are included as a markup into the field normally used for the instrument name. As for now lyrics can only be added as a direct markup. It doesn’t unfortunately conform with the spacing of the main lyrics.

    global = {
      \set Score.skipBars = ##t
      \key g \major
      \time 4/4
      %make the staff lines invisible on staves
      \override Staff.BarLine #'transparent = ##t
      \skip 1*8 % the actual music
      % let finis bar go through all staves
      \override Staff.BarLine #'transparent = ##f
      % finis bar
      \bar "|."
    }

    discantusNotes = {
      \transpose c' c'' {
        \clef treble
        d'2. d'4 |
        b e' d'2 |
        c'4 e'4.( d'8 c' b |
        a4) b a2 |
        b4.( c'8 d'4) c'4 |
        \once \override NoteHead #'transparent = ##t c'1 |
        b\breve |
      }
    }

    discantusLyrics = \lyricmode {
      Ju -- bi -- |
      la -- te De -- |
      o, om --
      nis ter -- |
      ra, __ om- |
      "..." |
      -us. |
    }

    altusNotes = {
      \transpose c' c'' {
        \clef treble
        r2 g2. e4 fis g | % two bars
        a2 g4 e |
        fis g4.( fis16 e fis4) |
        g1 |
        \once \override NoteHead #'transparent = ##t g1 |
        g\breve |
      }
    }

    altusLyrics = \lyricmode {
      Ju -- bi -- la -- te | % two bars
      De -- o, om -- |
      nis ter -- ra, |
      "..." |
      -us. |
    }

    tenorNotes = {
      \transpose c' c' {
        \clef "treble_8"
        R1 |
        R1 |
        R1 |
        r2 d'2. d'4 b e' | % two bars
        \once \override NoteHead #'transparent = ##t e'1 |
        d'\breve |
      }
    }

    tenorLyrics = \lyricmode {
      Ju -- bi -- la -- te | % two bars
      "..." |
      -us.
    }

    bassusNotes = {
      \transpose c' c' {
        \clef bass
        R1 |
        R1 |
        R1 |
        R1 |
        g2. e4 |
        \once \override NoteHead #'transparent = ##t e1 |
        g\breve |
      }
    }

    bassusLyrics = \lyricmode {
      Ju -- bi- |
      "..." |
      -us.
    }

    incipitDiscantus = \markup {
      \score {
        {
          \set Staff.instrumentName = #"Discantus "
          \override NoteHead #'style = #'neomensural
          \override Rest #'style = #'neomensural
          \override Staff.TimeSignature #'style = #'neomensural
          \cadenzaOn
          \clef "neomensural-c1"
          \key f \major
          \time 2/2
          c''1._"IV-" s2  %two bars
          \skip 1*8 % eight bars
        }
        \layout {
          \context {
            \Voice
            \remove "Ligature_bracket_engraver"
            \consists "Mensural_ligature_engraver"
          }
          line-width = 4.5\cm
        }
      }
    }

    incipitAltus = \markup {
      \score {
        {
          \set Staff.instrumentName = #"Altus "
          \override NoteHead #'style = #'neomensural
          \override Rest #'style = #'neomensural
          \override Staff.TimeSignature #'style = #'neomensural
          \cadenzaOn
          \clef "neomensural-c3"
          \key f \major
          \time 2/2
          r1        % one bar
          f'1._"IV-" s2   % two bars
          \skip 1*7 % seven bars
        }
        \layout {
          \context {
            \Voice
            \remove "Ligature_bracket_engraver"
            \consists "Mensural_ligature_engraver"
          }
          line-width = 4.5\cm
        }
      }
    }

    incipitTenor = \markup {
      \score {
        {
          \set Staff.instrumentName = #"Tenor  "
          \override NoteHead #'style = #'neomensural
          \override Rest #'style = #'neomensural
          \override Staff.TimeSignature #'style = #'neomensural
          \cadenzaOn
          \clef "neomensural-c4"
          \key f \major
          \time 2/2
          r\longa   % four bars
          r\breve   % two bars
          r1        % one bar
          c'1._"IV-" s2   % two bars
          \skip 1   % one bar
        }
        \layout {
          \context {
            \Voice
            \remove "Ligature_bracket_engraver"
            \consists "Mensural_ligature_engraver"
          }
          line-width = 4.5\cm
        }
      }
    }

    incipitBassus = \markup {
      \score {
        {
          \set Staff.instrumentName = #"Bassus  "
          \override NoteHead #'style = #'neomensural
          \override Rest #'style = #'neomensural
          \override Staff.TimeSignature #'style = #'neomensural
          \cadenzaOn
          \clef "bass"
          \key f \major
          \time 2/2
          % incipit
          r\maxima  % eight bars
          f1._"IV-" s2    % two bars
        }
        \layout {
          \context {
            \Voice
            \remove "Ligature_bracket_engraver"
            \consists "Mensural_ligature_engraver"
          }
          line-width = 4.5\cm
        }
      }
    }

    %StaffGroup is used instead of ChoirStaff to get bar lines between systems
    \score {
      <<
        \new StaffGroup = choirStaff <<
          \new Voice = "discantusNotes" <<
            \global
            \set Staff.instrumentName = \incipitDiscantus
            \discantusNotes
          >>
          \new Lyrics = "discantusLyrics" \lyricsto discantusNotes { \discantusLyrics }

          \new Voice = "altusNotes" <<
            \global
            \set Staff.instrumentName = \incipitAltus
            \altusNotes
          >>
          \new Lyrics = "altusLyrics" \lyricsto altusNotes { \altusLyrics }

          \new Voice = "tenorNotes" <<
            \global
            \set Staff.instrumentName = \incipitTenor
            \tenorNotes
          >>
          \new Lyrics = "tenorLyrics" \lyricsto tenorNotes { \tenorLyrics }

          \new Voice = "bassusNotes" <<
            \global
            \set Staff.instrumentName = \incipitBassus
            \bassusNotes
          >>
        >>
        \new Lyrics = "bassusLyrics" \lyricsto bassusNotes { \bassusLyrics }
        %Keep the bass lyrics outside of the staff group to avoid bar lines
        %between the lyrics.
      >>

      \layout {
        \context {
          \Score
          % no bars in staves
          \override BarLine #'transparent = ##t
        }
        % the next three instructions keep the lyrics between the bar lines
        \context {
          \Lyrics
          \consists "Bar_engraver"
          \override BarLine #'transparent = ##t
        }
        \context {
          \StaffGroup
          \consists "Separating_line_group_engraver"
        }
        \context {
          \Voice
          % no slurs
          \override Slur #'transparent = ##t
          % Comment in the below "\remove" command to allow line
          % breaking also at those barlines where a note overlaps
          % into the next bar.  The command is commented out in this
          % short example score, but especially for large scores, you
          % will typically yield better line breaking and thus improve
          % overall spacing if you comment in the following command.
          %\remove "Forbid_line_break_engraver"
        }
        indent = 5\cm
      }
    }

## Tweaking clef properties

The command `\clef "treble_8"` is equivalent to setting `clefGlyph`, `clefPosition` (which controls the vertical position of the clef), `middleCPosition` and `clefOctavation`. A clef is printed when any of the properties except `middleCPosition` are changed.

Note that changing the glyph, the position of the clef, or the octavation does not in itself change the position of subsequent notes on the staff: the position of middle C must also be specified to do this. The positional parameters are relative to the staff center line, positive numbers displacing upwards, counting one for each line and space. The `clefOctavation` value would normally be set to 7, -7, 15 or -15, but other values are valid.

When a clef change takes place at a line break the new clef symbol is printed at both the end of the previous line and the beginning of the new line by default. If the warning clef at the end of the previous line is not required it can be suppressed by setting the `Staff` property `explicitClefVisibility` to the value `end-of-line-invisible`. The default behavior can be recovered with `\unset Staff.explicitClefVisibility`.

The following examples show the possibilities when setting these properties manually. On the first line, the manual changes preserve the standard relative positioning of clefs and notes, whereas on the second line, they do not.

    \layout { ragged-right = ##t }

    {
      % The default treble clef
      c'1
      % The standard bass clef
      \set Staff.clefGlyph = #"clefs.F"
      \set Staff.clefPosition = #2
      \set Staff.middleCPosition = #6
      c'1
      % The baritone clef
      \set Staff.clefGlyph = #"clefs.C"
      \set Staff.clefPosition = #4
      \set Staff.middleCPosition = #4
      c'1
      % The standard choral tenor clef
      \set Staff.clefGlyph = #"clefs.G"
      \set Staff.clefPosition = #-2
      \set Staff.clefOctavation = #-7
      \set Staff.middleCPosition = #1
      c'1
      % A non-standard clef
      \set Staff.clefPosition = #0
      \set Staff.clefOctavation = #0
      \set Staff.middleCPosition = #-4
      c'1 \break

      % The following clef changes do not preserve
      % the normal relationship between notes and clefs:

      \set Staff.clefGlyph = #"clefs.F"
      \set Staff.clefPosition = #2
      c'1
      \set Staff.clefGlyph = #"clefs.G"
      c'1
      \set Staff.clefGlyph = #"clefs.C"
      c'1
      \set Staff.clefOctavation = #7
      c'1
      \set Staff.clefOctavation = #0
      \set Staff.clefPosition = #0
      c'1

      % Return to the normal clef:

      \set Staff.middleCPosition = #0
      c'1
    }

## Tweaking grace layout within music

The layout of grace expressions can be changed throughout the music using the functions `add-grace-property` and `remove-grace-property`. The following example undefines the `Stem` direction for this grace, so that stems do not always point up, and changes the default note heads to crosses.

    \relative c'' {
      \new Staff {
        #(remove-grace-property 'Voice 'Stem 'direction)
        #(add-grace-property 'Voice 'NoteHead 'style 'cross)
        \new Voice {
           \acciaccatura { f16 } g4
           \grace { d16[ e] } f4
           \appoggiatura { f,32[ g a] } e2
        }
      }
    }

## Using alternative flag styles

Alternative styles of flag on eighth and shorter notes can be displayed by overriding the `flag` property of `Stem`. Valid values are `modern-straight-flag` and `old-straight-flag`.

    testnotes = {
      \autoBeamOff
      c8 d16 c32 d64 \acciaccatura { c8 } d64 r4
    }

    \relative c' {
      \time 2/4
      \testnotes

      \override Stem #'flag = #modern-straight-flag
      \testnotes

      \override Stem #'flag = #old-straight-flag
      \testnotes

      \revert Stem #'flag
      \testnotes
    }

## Using ly:grob-object to access grobs with \tweak

Some grobs can be accessed “laterally” from within another grob’s callback. These are usually listed as “layout objects” in the “Internal properties” section of a grob-interface. The function `ly:grob-object` is used to access these grobs.

Demonstrated below are some ways of accessing grobs from within a NoteHead callback, but the technique is not limited to NoteHeads. However, the NoteHead callback is particularly important, since it is the implicit callback used by the `\tweak` command.

The example function defined below ("display-grobs") is probably not that useful, but it demonstrates that the grobs are indeed being accessed.

Example console output:

>     --------------------
>     #-Grob Accidental -
>     #-Grob Arpeggio -
>     #-Grob Stem -

    #(define (notehead-get-accidental notehead)
       ;; notehead is grob
       (ly:grob-object notehead 'accidental-grob))

    #(define (notehead-get-arpeggio notehead)
       ;; notehead is grob
       (let ((notecolumn (notehead-get-notecolumn notehead)))
         (ly:grob-object notecolumn 'arpeggio)))

    #(define (notehead-get-notecolumn notehead)
       ;; notehead is grob
       (ly:grob-parent notehead X))

    #(define (notehead-get-stem notehead)
       ;; notehead is grob
       (let ((notecolumn (notehead-get-notecolumn notehead)))
         (ly:grob-object notecolumn 'stem)))

    #(define (display-grobs notehead)
       ;; notehead is grob
       (let ((accidental (notehead-get-accidental notehead))
             (arpeggio (notehead-get-arpeggio notehead))
             (stem (notehead-get-stem notehead)))
         (format #t "~2&~a\n" (make-string 20 #\-))
         (for-each
          (lambda (x) (format #t "~a\n" x))
          (list accidental arpeggio stem))))

    \relative c' {
      %% display grobs for each note head:
      %\override NoteHead #'before-line-breaking = #display-grobs
      <c
      %% or just for one:
      \tweak #'before-line-breaking #display-grobs
      es
      g>1\arpeggio
    }

## Using PostScript to generate special note head shapes

When a note head with a special shape cannot easily be generated with graphic markup, PostScript code can be used to generate the shape. This example shows how a parallelogram-shaped note head is generated.

    parallelogram =
      #(ly:make-stencil (list 'embedded-ps
        "gsave
          currentpoint translate
          newpath
          0 0.25 moveto
          1.3125 0.75 lineto
          1.3125 -0.25 lineto
          0 -0.75 lineto
          closepath
          fill
          grestore" )
        (cons 0 1.3125)
        (cons 0 0))

    myNoteHeads = \override NoteHead #'stencil = \parallelogram
    normalNoteHeads = \revert NoteHead #'stencil

    \relative c'' {
      \myNoteHeads
      g4 d'
      \normalNoteHeads
      <f, \tweak #'stencil \parallelogram b e>4 d
    }

## Using the \tweak command to tweak individual grobs

With the `\tweak` command, every grob can be tuned directly. Here are some examples of available tweaks.

    \relative c' {
      \time 2/4
      \set fingeringOrientations = #'(right)
      <
        \tweak #'font-size #3 c
        \tweak #'color #red d-\tweak #'font-size #8 -4
        \tweak #'style #'cross g
        \tweak #'duration-log #2 a
      >2
    }

## Vertically aligned dynamics and textscripts

By setting the `'Y-extent` property to a suitable value, all `DynamicLineSpanner` objects (hairpins and dynamic texts) can be aligned to a common reference point, regardless of their actual extent. This way, every element will be vertically aligned, thus producing a more pleasing output.

The same idea is used to align the text scripts along their baseline.

    music = \relative c' {
      a'2\p b\f
      e4\p f\f\> g, b\p
      c2^\markup { \huge gorgeous } c^\markup { \huge fantastic }
    }

    {
      \music
      \break
      \override DynamicLineSpanner #'staff-padding = #2.0
      \override DynamicLineSpanner #'Y-extent = #'(-1.5 . 1.5)
      \override TextScript #'Y-extent = #'(-1.5 . 1.5)
      \music
    }

## Vertically aligning ossias and lyrics

This snippet demonstrates the use of the context properties `alignBelowContext` and `alignAboveContext` to control the positioning of lyrics and ossias.

    \paper {
      ragged-right = ##t
    }

    \relative c' <<
      \new Staff = "1" { c4 c s2 }
      \new Staff = "2" { c4 c s2 }
      \new Staff = "3" { c4 c s2 }
      { \skip 2
        <<
          \lyrics {
            \set alignBelowContext = #"1"
            lyrics4 below
          }
          \new Staff \with {
            alignAboveContext = #"3"
            fontSize = #-2
            \override StaffSymbol #'staff-space = #(magstep -2)
            \remove "Time_signature_engraver"
          } {
            \times 4/6 {
              \override TextScript #'padding = #3
              c8[^"ossia above" d e d e f]
            }
          }
        >>
      }
    >>

## Vertically centering paired figured bass extenders

Where figured bass extender lines are being used by setting `useBassFigureExtenders` to true, pairs of congruent figured bass extender lines are vertically centered if `figuredBassCenterContinuations` is set to true.

    <<
      \relative c' {
        c8 c b b a a c16 c b b
        c8 c b b a a c16 c b b
        c8 c b b a a c c b b
      }
      \figures {
        \set useBassFigureExtenders = ##t
        <6+ 4 3>4 <6 4 3>8 r
        <6+ 4 3>4 <6 4 3>8 <4 3+>16 r
        \set figuredBassCenterContinuations = ##t
        <6+ 4 3>4 <6 4 3>8 r
        <6+ 4 3>4 <6 4 3>8 <4 3+>16 r
        \set figuredBassCenterContinuations = ##f
        <6+ 4 3>4 <6 4 3>8 r
        <6+ 4 3>4 <6 4 3>8 <4 3+>8
      }
    >>

#### LilyPond — Snippets