By default, Emacs displays text on graphical displays using a 10-point monospace font. There are several different ways to specify a different font:
default-frame-alistto specify the
fontparameter (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.
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.
t(the default is
nil). For this to work, Emacs must have been compiled with support for Gsettings (or the older Gconf).
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.
On X, there are four different ways to express a font name. The first is to use a Fontconfig pattern. Fontconfig patterns have the following form:
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:
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.
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:
Here are some examples of GTK font patterns:
Monospace 12 Monospace Bold Italic 12
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. Each XLFD consists of fourteen words or numbers, separated by dashes, like this:
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:
The entries have the following meanings:
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
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).