21.8 Fonts
By default, Emacs displays text on graphical displays using a 10-point monospace font, and the font size can be changed interactively (see Text Scale).
There are several different ways to specify a different font:
Click on β
Set Default Font
β in the βOptions
β menu. This makes the selected font the default on all existing graphical frames. To save this for future sessions, click on βSave Options
β in the βOptions
β menu.Add a line to your init file, modifying the variable
default-frame-alist
to specify thefont
parameter (see Frame Parameters), like this:(add-to-list 'default-frame-alist
'(font . "DejaVu Sans Mono-10"))This makes the font the default on all graphical frames created after restarting Emacs with that init file.
Add an β
emacs.font
β X resource setting to your X resource file, like this:emacs.font: DejaVu Sans Mono-12
You must restart X, or use the
xrdb
command, for the X resources file to take effect. See Resources. Do not quote font names in X resource files.If you are running Emacs on the GNOME desktop, you can tell Emacs to use the default system font by setting the variable
font-use-system-font
tot
(the default isnil
). For this to work, Emacs must have been compiled with support for Gsettings (or the older Gconf).Use the command line option β
-fn
β (or β--font
β). See Font X.
To check what font youβre currently using, the C-u C-x =
command can be helpful. It describes the character at point, and names the font that itβs rendered in.
There are four different ways to express a font name. The first is to use a Fontconfig pattern. Fontconfig patterns have the following form:
fontname[-fontsize][:name1=values1][:name2=values2]...
Within this format, any of the elements in brackets may be omitted. Here, fontname
is the family name of the font, such as βMonospace
β or βDejaVu Sans Mono
β; fontsize
is the point size of the font (one printerβs point is about 1/72 of an inch); and the βname=values
β entries specify settings such as the slant and weight of the font. Each values
may be a single value, or a list of values separated by commas. In addition, some property values are valid with only one kind of property name, in which case the βname=
β part may be omitted.
Here is a list of common font properties:
βslant
ββ
One of βitalic
β, βoblique
β, or βroman
β.
βweight
ββ
One of βlight
β, βmedium
β, βdemibold
β, βbold
β or βblack
β.
βstyle
ββ
Some fonts define special styles which are a combination of slant and weight. For instance, βDejavu Sans
β defines the βbook
β style, which overrides the slant and weight properties.
βwidth
ββ
One of βcondensed
β, βnormal
β, or βexpanded
β.
βspacing
ββ
One of βmonospace
β, βproportional
β, βdual-width
β, or βcharcell
β.
Here are some examples of Fontconfig patterns:
Monospace
Monospace-12
Monospace-12:bold
DejaVu Sans Mono:bold:italic
Monospace-12:weight=bold:slant=italic
For a more detailed description of Fontconfig patterns, see the Fontconfig manual, which is distributed with Fontconfig and available online at https://fontconfig.org/fontconfig-user.html.
On MS-Windows, only the subset of the form fontname
[-fontsize
] is supported for all fonts; the full Fontconfig pattern might not work for all of them.
The second way to specify a font is to use a GTK font pattern. These have the syntax
fontname [properties] [fontsize]
where fontname
is the family name, properties
is a list of property values separated by spaces, and fontsize
is the point size. The properties that you may specify for GTK font patterns are as follows:
- Slant properties: β
Italic
β or βOblique
β. If omitted, the default (roman) slant is implied. - Weight properties: β
Bold
β, βBook
β, βLight
β, βMedium
β, βSemi-bold
β, or βUltra-light
β. If omitted, βMedium
β weight is implied. - Width properties: β
Semi-Condensed
β or βCondensed
β. If omitted, a default width is used.
Here are some examples of GTK font patterns:
Monospace 12
Monospace Bold Italic 12
On MS-Windows, only the subset fontname
is supported.
The third way to specify a font is to use an XLFD (X Logical Font Description). This is the traditional method for specifying fonts under X, and is also supported on MS-Windows. Each XLFD consists of fourteen words or numbers, separated by dashes, like this:
-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1
A wildcard character (β*
β) in an XLFD matches any sequence of characters (including none), and β?
β matches any single character. However, matching is implementation-dependent, and can be inaccurate when wildcards match dashes in a long name. For reliable results, supply all 14 dashes and use wildcards only within a field. Case is insignificant in an XLFD. The syntax for an XLFD is as follows:
-maker-family-weight-slant-widthtype-styleβ¦
β¦-pixels-height-horiz-vert-spacing-width-registry-encoding
The entries have the following meanings:
maker
β
The name of the font manufacturer.
family
β
The name of the font family (e.g., βcourier
β).
weight
β
The font weightβnormally either βbold
β, βmedium
β or βlight
β. Some font names support other values.
slant
β
The font slantβnormally βr
β (roman), βi
β (italic), βo
β (oblique), βri
β (reverse italic), or βot
β (other). Some font names support other values.
widthtype
β
The font widthβnormally βnormal
β, βcondensed
β, βsemicondensed
β, or βextended
β. Some font names support other values.
style
β
An optional additional style name. Usually it is emptyβmost XLFDs have two hyphens in a row at this point. The style name can also specify a two-letter ISO-639 language name, like βja
β or βko
β; some fonts that support CJK scripts have that spelled out in the style name part.
pixels
β
The font height, in pixels.
height
β
The font height on the screen, measured in tenths of a printerβs point. This is the point size of the font, times ten. For a given vertical resolution, height
and pixels
are proportional; therefore, it is common to specify just one of them and use β*
β for the other.
horiz
β
The horizontal resolution, in pixels per inch, of the screen for which the font is intended.
vert
β
The vertical resolution, in pixels per inch, of the screen for which the font is intended. Normally the resolution of the fonts on your system is the right value for your screen; therefore, you normally specify β*
β for this and horiz
.
spacing
β
This is βm
β (monospace), βp
β (proportional) or βc
β (character cell).
width
β
The average character width, in pixels, multiplied by ten.
registry
β
encoding
β
The X font character set that the font depicts. (X font character sets are not the same as Emacs character sets, but they are similar.) You can use the xfontsel
program to check which choices you have. Normally you should use βiso8859
β for registry
and β1
β for encoding
.
The fourth and final method of specifying a font is to use a font nickname. Certain fonts have shorter nicknames, which you can use instead of a normal font specification. For instance, β6x13
β is equivalent to
-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1
This form is not supported on MS-Windows.
On X, Emacs recognizes two types of fonts: client-side fonts, which are provided by the Xft and Fontconfig libraries, and server-side fonts, which are provided by the X server itself. Most client-side fonts support advanced font features such as antialiasing and subpixel hinting, while server-side fonts do not. Fontconfig and GTK patterns match only client-side fonts.
You will probably want to use a fixed-width default fontβthat is, a font in which all characters have the same width. For Xft and Fontconfig fonts, you can use the fc-list
command to list the available fixed-width fonts, like this:
fc-list :spacing=mono
fc-list :spacing=charcell
For server-side X fonts, you can use the xlsfonts
program to list the available fixed-width fonts, like this:
xlsfonts -fn '*x*' | grep -E '^[0-9]+x[0-9]+'
xlsfonts -fn '*-*-*-*-*-*-*-*-*-*-*-m*'
xlsfonts -fn '*-*-*-*-*-*-*-*-*-*-*-c*'
Any font with βm
β or βc
β in the spacing
field of the XLFD is a fixed-width font. To see what a particular font looks like, use the xfd
command. For example:
xfd -fn 6x13
displays the entire font β6x13
β.
While running Emacs, you can also set the font of a specific kind of text (see Faces), or a particular frame (see Frame Parameters).