Next: , Up: Display


19.1 Using Multiple Typefaces

You can specify various styles for displaying text using faces. Each face can specify various face attributes, such as the font family, the height, weight and slant of the characters, the foreground and background color, and underlining or overlining. A face does not have to specify all of these attributes; often it inherits most of them from another face.

On a window system, all the Emacs face attributes are meaningful. On a character terminal, only some of them work. Some character terminals support inverse video, bold, and underline attributes; some support colors. Character terminals generally do not support changing the height and width or the font family.

The easiest way to use faces is to turn on Font Lock mode. See Font Lock, for more information about Font Lock mode and syntactic highlighting. You can print out the buffer with the highlighting that appears on your screen using the command ps-print-buffer-with-faces. See PostScript.

Features which rely on text in multiple faces (such as Font Lock mode) will also work on non-windowed terminals that can display more than one face, whether by colors or underlining and emboldening. This includes the console on GNU/Linux, an xterm which supports colors, the MS-DOS display (see MS-DOS), and the MS-Windows version invoked with the -nw option. Emacs determines automatically whether the terminal has this capability.

You control the appearance of a part of the text in the buffer by specifying the face or faces to use for it. The style of display used for any given character is determined by combining the attributes of all the applicable faces specified for that character. Any attribute that isn't specified by these faces is taken from the default face, whose attributes reflect the default settings of the frame itself.

Enriched mode, the mode for editing formatted text, includes several commands and menus for specifying faces for text in the buffer. See Format Faces, for how to specify the font for text in the buffer. See Format Colors, for how to specify the foreground and background color.

To alter the appearance of a face, use the customization buffer. See Face Customization. You can also use X resources to specify attributes of particular faces (see Resources). Alternatively, you can change the foreground and background colors of a specific face with M-x set-face-foreground and M-x set-face-background. These commands prompt in the minibuffer for a face name and a color name, with completion, and then set that face to use the specified color. Changing the colors of the default face also changes the foreground and background colors on all frames, both existing and those to be created in the future. (You can also set foreground and background colors for the current frame only; see Frame Parameters.)

Emacs can correctly display variable-width fonts, but Emacs commands that calculate width and indentation do not know how to calculate variable widths. This can sometimes lead to incorrect results when you use variable-width fonts. In particular, indentation commands can give inconsistent results, so we recommend you avoid variable-width fonts for editing program source code. Filling will sometimes make lines too long or too short. We plan to address these issues in future Emacs versions.