1.8.1 Writing text
This section introduces different ways of adding text to a score.
Note: To write accented and special text (such as characters from other languages), simply insert the characters directly into the LilyPond file. The file must be saved as UTF-8. For more information, see Text encoding.
Text objects overview
Text objects are entered either as simple strings between
double quotes, or as \markup
blocks that can accept
a variety of advanced text formatting and graphical enhancements,
as detailed in Formatting text.
As such, markup blocks may be used:
-
in any
TextScript
object (attached to notes with-
,^
or_
); see Text scripts; - as ‘spanners’, when some indications are prolonged over several beats or bars; see Text spanners;
-
in any mark printed above the score, such as
RehearsalMark
orMetronomeMark
objects respectively introduced with the\mark
or\tempo
keywords; see Text marks; -
as standalone markup blocks, entered at the top level
outside of any
\score
block (in this specific case the\markup {...}
command is mandatory, and cannot be omitted in favor of a simple text string between double quotes); see Separate text; -
in any definition inside the
\header
block (e.g.,title
,subtitle
,composer
), or in specific elements defined inside the\paper
block such asevenHeaderMarkup
for page numbers. This is explained in Titles and headers.
Many other text-based objects may be entered as markup blocks, even if that is not their primary use.
-
Fingerings may easily be replaced with markup blocks, if
introduced with the
\finger
command; see Fingering instructions. -
Lyric syllables may be formatted through the
\markup
command; see Common notation for vocal music. - Chord names are in fact defined as markup blocks, and therefore may be redefined in the same way for customizing chord modifiers or chord exceptions; see Displaying chords.
-
Dynamics are usually entered in a simple way; however it is possible
to define New dynamic marks as markup objects. Some dynamics
such as crescendo are printed as spanners and may be redefined
through properties such as
crescendoText
; see Dynamics. - Less common objects are also made of markup blocks, such as Balloon help indications.
In fact, it is possible to use \markup
to customize the appearance of
virtually any graphical object (or ‘grob’), by overriding either its
text
property if it has one, or its stencil
property. Some of
the logic that makes this a possibility is explained in
Flexible architecture.
The following example illustrates the ubiquity of markup blocks, not only as some of the objects listed above, but also by replacing musical objects with text objects through various methods.
\header { title = \markup "Header" } dyn = #(make-dynamic-script #{ \markup \text "DynamicText" #}) \markup \box "Top-level markup" \score { << \new ChordNames \with { majorSevenSymbol = \markup "majorSevenSymbol" } \chordmode { c1:maj7 } \new Staff { \tempo \markup "MetronomeMark" \mark \markup \smaller "RehearsalMark" \once \override TupletNumber.text = \markup "TupletNumber" \tuplet 3/2 { \once \override NoteHead.stencil = #ly:text-interface::print \once \override NoteHead.text = \markup \lower #0.5 "NoteHead" c''8^\markup \italic "TextScript" a'\finger \markup \text "Fingering" \once \override Rest.stencil = #(lambda (grob) (grob-interpret-markup grob #{ \markup "Rest" #})) r } } \new Lyrics \lyricmode { \markup \smallCaps "LyricText" 1 } \new Dynamics { s1\dyn } >> }
See also
Notation Reference: Formatting text, Text scripts, Text spanners, Text marks, Separate text, Fingering instructions, Common notation for vocal music, Displaying chords, New dynamic marks, Dynamics, Balloon help.
Essay on automated music engraving: Flexible architecture.
Snippets: Text.
Text scripts
Simple “quoted text” indications may be added to a score, as demonstrated in the following example. Such indications may be manually placed above or below the staff, using the syntax described in Direction and placement.
\relative { a'8^"pizz." g f e a4-"scherz." f }
This syntax is actually a shorthand; more complex text formatting may be
added to a note by explicitly using a \markup
block, as described
in Formatting text.
\relative { a'8^\markup { \italic pizz. } g f e a4_\markup { \tiny scherz. \bold molto } f }
By default, text indications do not influence the note spacing. However, their widths can be taken into account: in the following example, the first text string does not affect spacing, whereas the second one does.
\relative { a'8^"pizz." g f e \textLengthOn a4_"scherzando" f }
In addition to text scripts, articulations can be attached to notes. For more information, see Articulations and ornamentations.
For more information about the relative ordering of text scripts and articulations, see Placement of objects.
Predefined commands
\textLengthOn
,
\textLengthOff
.
See also
Learning Manual: Placement of objects.
Notation Reference: Formatting text, Direction and placement, Articulations and ornamentations.
Snippets: Text.
Internals Reference: TextScript.
Known issues and warnings
Checking to make sure that text scripts and lyrics are within the margins requires additional calculations. In cases where slightly faster performance is desired, use
\override Score.PaperColumn.keep-inside-line = ##f
Text spanners
Some performance indications, e.g., rallentando or accelerando, are written as text and are extended over multiple notes with dotted lines. Such objects, called “spanners”, may be created from one note to another using the following syntax:
\relative { \override TextSpanner.bound-details.left.text = "rit." b'1\startTextSpan e,\stopTextSpan }
The string to be printed is set through object properties. By default
it is printed in italic characters, but different formatting can be
obtained using \markup
blocks, as described in
Formatting text.
\relative { \override TextSpanner.bound-details.left.text = \markup { \upright "rit." } b'1\startTextSpan c e,\stopTextSpan }
The line style, as well as the text string, can be defined as an object property. This syntax is described in Line styles.
Predefined commands
\textSpannerUp
,
\textSpannerDown
,
\textSpannerNeutral
.
Known issues and warnings
LilyPond is only able to handle one text spanner per voice.
Selected Snippets
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\! }
Dynamics custom text spanner postfix
Postfix functions for custom crescendo text spanners. The spanners
should start on the first note of the measure. One has to use
-\mycresc
, otherwise the spanner start will rather be assigned
to the next note.
% Two functions for (de)crescendo spanners where you can explicitly % give the spanner text. mycresc = #(define-music-function (mymarkup) (markup?) (make-music 'CrescendoEvent 'span-direction START 'span-type 'text 'span-text mymarkup)) mydecresc = #(define-music-function (mymarkup) (markup?) (make-music 'DecrescendoEvent 'span-direction START 'span-type 'text 'span-text mymarkup)) \relative c' { c4-\mycresc "custom cresc" c4 c4 c4 | c4 c4 c4 c4 | c4-\mydecresc "custom decresc" c4 c4 c4 | c4 c4\! c4 c4 }
See also
Notation Reference: Line styles, Dynamics, Formatting text.
Snippets: Text, Expressive marks.
Internals Reference: TextSpanner.
Text marks
Various text elements may be added to a score using the syntax described in Rehearsal marks:
\relative { \mark "Verse" c'2 g' \bar "||" \mark "Chorus" g2 c, \bar "|." }
This syntax makes it possible to put any text on a bar line;
more complex text formatting may be added using a \markup
block, as described in Formatting text:
\relative { <c' e>1 \mark \markup { \italic { colla parte } } <d f>2 <e g> <c f aes>1 }
This syntax also allows to print special signs, like coda, segno or fermata, by specifying the appropriate symbol name as explained in Music notation inside markup:
\relative { <bes' f>2 <aes d> \mark \markup { \musicglyph "scripts.ufermata" } <e g>1 }
Such objects are only typeset above the top staff of the score; depending on whether they are specified at the end or the middle of a bar, they can be placed above the bar line or between notes. When specified at a line break, the mark will be printed at the beginning of the next line.
\relative c'' { \mark "Allegro" c1 c \mark "assai" \break c c }
Predefined commands
\markLengthOn
,
\markLengthOff
.
Selected Snippets
Printing marks at the end of a line
Marks can be printed at the end of the current line, instead of the beginning of the following line. In such cases, it might be preferable to align the right end of the mark with the bar line.
\relative c'' { g2 c d,2 a' \once \override Score.RehearsalMark.break-visibility = #end-of-line-visible \once \override Score.RehearsalMark.self-alignment-X = #RIGHT \mark "D.C. al Fine" \break g2 b, c1 \bar "||" }
Printing marks on every staff
Although text marks are normally only printed above the topmost staff, they may also be printed on every staff.
\score { << \new Staff { c''1 \mark "molto" c'' } \new Staff { c'1 \mark "molto" c' } >> \layout { \context { \Score \remove "Mark_engraver" \remove "Staff_collecting_engraver" } \context { \Staff \consists "Mark_engraver" \consists "Staff_collecting_engraver" } } }
See also
Notation Reference: Rehearsal marks, Formatting text, Music notation inside markup, The Emmentaler font.
Snippets: Text.
Internals Reference: MarkEvent, Mark_engraver, RehearsalMark.
Separate text
A \markup
block can exist by itself, outside of any
\score
block, as a “top-level expression”. This syntax
is described in File structure.
\markup { Tomorrow, and tomorrow, and tomorrow... }
This allows printing text separately from the music, which is particularly useful when the input file contains several music pieces, as described in Multiple scores in a book.
\score { c'1 } \markup { Tomorrow, and tomorrow, and tomorrow... } \score { c'1 }
Separate text blocks can be spread over multiple pages, making it possible to print text documents or books entirely within LilyPond. This feature, and the specific syntax it requires, are described in Multi-page markup.
Predefined commands
\markup
,
\markuplist
.
Selected Snippets
Stand-alone two-column markup
Stand-alone text may be arranged in several columns using
\markup
commands:
\markup { \fill-line { \hspace #1 \column { \line { O sacrum convivium } \line { in quo Christus sumitur, } \line { recolitur memoria passionis ejus, } \line { mens impletur gratia, } \line { futurae gloriae nobis pignus datur. } \line { Amen. } } \hspace #2 \column \italic { \line { O sacred feast } \line { in which Christ is received, } \line { the memory of His Passion is renewed, } \line { the mind is filled with grace, } \line { and a pledge of future glory is given to us. } \line { Amen. } } \hspace #1 } }
See also
Notation Reference: Formatting text, File structure, Multiple scores in a book, Multi-page markup.
Snippets: Text.
Internals Reference: TextScript.