[ << Text ] | [Top][Contents][Index] | [ Vocal music >> ] |
[ < Music notation inside markup ] | [ Up: Text ] | [ Unsupported font formats > ] |
8.3 Fonts
Fonts in LilyPond are handled by several libraries; two of them are of relevance to the user: FontConfig is used to detect available fonts, and selected fonts are then rendered by Pango to display text strings.
This section shows how to access fonts in LilyPond, and how to change them in scores.
8.3.1 Unsupported font formats | ||
8.3.2 Finding fonts | ||
8.3.3 Font families | ||
8.3.4 Font features | ||
8.3.5 Changing fonts |
[ << Text ] | [Top][Contents][Index] | [ Vocal music >> ] |
[ < Fonts ] | [ Up: Fonts ] | [ Finding fonts > ] |
8.3.1 Unsupported font formats
A word of caution at the beginning: LilyPond creates its final PDF output using an intermediate PostScript file. As a consequence, some font formats cannot be used because PostScript, being an old standard and no longer receiving any updates, lacks support for them. Here is a list of font formats that won’t work.
- CFF2 ¶
-
In the last years this font format became the default for OpenType (.otf) fonts. While its predecessor (CFF, also using the extension .otf) is supported, the more compact CFF2 is not. LilyPond warns on the console if it encounters such a font, and the conversion to a PDF will either fail or the PDF will miss glyphs from this font.
- Font Variations ¶
-
Such fonts usually have ‘VF’ somewhere in their name; unfortunately, they are not supported regardless of whether they are TrueType or OpenType Font Variations, and consequently filtered out in advance.
- color fonts ¶
-
Not supported; this affects in particular scalable Emoji fonts. Some fonts, however, also contain B/W versions of the Emojis (as normal outline glyphs), and these should work just fine – provided they come in a supported font format.
- OpenType collections ¶
-
This is a container format (usually with extension .otc) that holds multiple fonts in a single file. Today, it is often used as a last resort font, i.e., it gets used by the OS if no other font fits, for whatever reason.
- bitmap fonts ¶
-
Not supported at all and automatically filtered out before LilyPond sees the list of available fonts. This includes some older Emoji color fonts.
Many fonts are available in both the TrueType and the OpenType format; if the .otf version fails, try the .ttf one. If you cannot find an alternative to a CFF2 font, try LilyPond’s -dbackend=cairo command line option; this currently experimental backend bypasses the PostScript step and directly creates PDF output, thus being able to support CFF2 (and also OpenType collections).
[ << Text ] | [Top][Contents][Index] | [ Vocal music >> ] |
[ < Unsupported font formats ] | [ Up: Fonts ] | [ Font families > ] |
8.3.2 Finding fonts
In addition to any font already installed on the operating system, more fonts may be added to the ones detected by FontConfig (and thus available in LilyPond scores) by the following commands:
#(ly:font-config-add-font "path/to/font-file") #(ly:font-config-add-directory "path/to/directory/")
Both commands accept either absolute or relative paths, which makes it possible to compile a score on any system by simply distributing the relevant font files together with the LilyPond input files.
To verify that the desired fonts are found by FontConfig, use the
command #(ly:font-config-display-fonts)
, which prints the
complete list of available fonts to the console log. It also
shows the actual font names to be used with LilyPond; these may
differ from the file names themselves. Alternatively, running
lilypond -dshow-available-fonts
in a terminal has the
same effect.
[ << Text ] | [Top][Contents][Index] | [ Vocal music >> ] |
[ < Finding fonts ] | [ Up: Fonts ] | [ Font features > ] |
8.3.3 Font families
Three generic aliases for text font families2 are available: ‘serif’, ‘sans’, and ‘typewriter’. Depending on the backend, these families get mapped to different font family aliases.
For the svg
backend:
generic family SVG font family serif serif sans sans-serif typewriter monospace
‘serif’, ‘sans-serif’, and ‘monospace’ are ‘generic-family’ in SVG and CSS specifications.
For other backends:
generic family default font family alias font families contained in alias serif LilyPond Serif C059, Century SchoolBook URW, Century Schoolbook L, TeX Gyre Schola, DejaVu Serif, …, serif sans LilyPond Sans Serif Nimbus Sans, Nimbus Sans L, TeX Gyre Heros, DejaVu Sans, …, sans-serif typewriter LilyPond Monospace Nimbus Mono PS, Nimbus Mono, Nimbus Mono L, TeX Gyre Cursor, DejaVu Sans Mono, …, monospace
If a character does not exist in the appropriate font of the first listed family, the appropriate font of the next listed family gets used instead for that character.
Note that the URW font families distributed with LilyPond (‘C059’, ‘Nimbus Sans’, and ‘Nimbus Mono PS’) have a peculiarity: By default, in addition to the standard ligatures like ‘fl’ or ‘ffi’, they substitute the string ‘Nr.’ with the Numero Sign (U+2116) if the ‘latn’ script is selected. To circumvent this locally, insert a zero-width non-joiner character (ZWNJ, U+200C) between the ‘N’ and ‘r’ characters. To circumvent this globally, use the following code to make LilyPond always insert a ZWNJ character.
\paper { #(add-text-replacements! `(("Nr." . ,(format #f "N~ar." (ly:wide-char->utf-8 #x200C))))) }
‘LilyPond Serif’, ‘LilyPond Sans Serif’, and ‘LilyPond Monospace’ are font family aliases defined in the additional FontConfig configuration file 00-lilypond-fonts.conf, which can be usually found in directory /usr/local/share/lilypond/2.25.28/fonts, and which is used exclusively by LilyPond.
Each font family may include different shapes and series. The
following example demonstrates that, including code to also change
the size. The value supplied to font-size
is taken
relative to the default font size.
\override Score.TextMark.font-family = #'typewriter \textMark "Ouverture" \override Voice.TextScript.font-shape = #'italic \override Voice.TextScript.font-series = #'bold d''2.^\markup "Allegro" \override Voice.TextScript.font-size = -3 c''4^"smaller"![]()
A similar syntax may be used in markup mode; however, in most cases it is preferable to use the simpler syntax explained in Selecting font and font size:
\markup { \column { \line { \override #'((font-shape . italic) (font-size . 4)) Idomeneo, } \line { \override #'(font-family . typewriter) { \override #'(font-series . bold) re di } \override #'(font-family . sans) Creta } } }![]()
[ << Text ] | [Top][Contents][Index] | [ Vocal music >> ] |
[ < Font families ] | [ Up: Fonts ] | [ Changing fonts > ] |
8.3.4 Font features
When using OpenType fonts, font features can be used.3 Note that not all OpenType fonts have all features. If you request a feature that does not exist in the chosen font, the feature is simply ignored. The example below uses the font ‘TeX Gyre Schola’ (this is, the roman style of the family).
\paper { property-defaults.fonts.serif = "TeX Gyre Schola" } \markup "normal style: Hello HELLO" \markup \caps "small caps: Hello" \markup \override #'(font-features . ("smcp")) "true small caps: Hello" \markup "normal number style: 0123456789" \markup \override #'(font-features . ("onum")) "old number style: 0123456789" \markup \override #'(font-features . ("salt 0")) "stylistic alternate 0: εφπρθ" \markup \override #'(font-features . ("salt 1")) "stylistic alternate 1: εφπρθ" \markup \override #'(font-features . ("onum" "smcp" "salt 1")) "multiple features: Hello 0123456789 εφπρθ"![]()
For the full OpenType font feature list see https://www.microsoft.com/typography/otspec/featurelist.htm; for identifying features of OpenType fonts see https://lists.gnu.org/archive/html/lilypond-devel/2017-08/msg00004.html.
See also
Notation Reference: The Emmentaler font, Music notation inside markup, Rotating objects, Selecting font and font size, Font markup. Finding fonts, Font families, Changing fonts.
Snippets: Text.
[ << Text ] | [Top][Contents][Index] | [ Vocal music >> ] |
[ < Font features ] | [ Up: Fonts ] | [ Vocal music > ] |
8.3.5 Changing fonts
It is possible to change the fonts used in LilyPond’s default font families.
\paper { property-defaults.fonts.serif = "Linux Libertine O" property-defaults.fonts.sans = "DejaVu Sans" property-defaults.fonts.typewriter = "DejaVu Sans Mono" } \relative c'{ c1-\markup { serif, \sans sans, \typewriter typewriter. } }![]()
The same syntax can be used to change the music font; see Replacing the notation font.
To change the fonts used for one specific grob, or one specific
part of a markup, override the fonts
property. The
following example changes the font for normal tablature “note
heads” (which use the serif
family) while keeping the
default font for those that are drawn as a cross (which use the
music
family).
\layout { \override TabVoice.TabNoteHead.property-defaults.fonts.serif = "Linux Libertine O" } \new TabStaff { c' d' e' \deadNote c' }![]()
Below is an example for overriding fonts
in markup:
\markup \override #'(fonts . ((serif . "Linux Libertine O") (typewriter . "DejaVu Sans Mono"))) { Copyright © John Doe \typewriter john@doe.org }![]()
See also
Notation Reference: Finding fonts, Font families, Selecting font and font size, Font markup, Replacing the notation font.
Footnotes
(2)
In its simplest form, a font family usually contains fonts in roman, italic, bold, and bold italic styles.
(3)
Selecting OpenType font scripts and languages is not supported yet.
[Top][Contents][Index] |