Fontsets do not always have to be created from scratch. If only minor changes are required it may be easier to modify an existing fontset, usually ‘
fontset-default’. Modifying ‘
fontset-default’ will also affect other fontsets that use it as a fallback, so can be an effective way of fixing problems with the fonts that Emacs chooses for a particular script.
Fontsets can be modified using the function
set-fontset-font, specifying a character, a charset, a script, or a range of characters to modify the font for, and a font specification for the font to be used. Some examples are:
;; Prefer a big5 font for han characters.
'han (font-spec :registry "big5")
;; Use MyPrivateFont for the Unicode private use area.
(set-fontset-font "fontset-default" '(#xe000 . #xf8ff)
;; Use Liberation Mono for latin-3 charset.
(set-fontset-font "fontset-default" 'iso-8859-3
;; Use DejaVu Sans Mono as a fallback in fontset-startup
;; before resorting to fontset-default.
(set-fontset-font "fontset-startup" nil "DejaVu Sans Mono"
See Fontsets in GNU Emacs Lisp Reference Manual, for more details about using the
If you don’t know the character’s codepoint or the script to which it belongs, you can ask Emacs. With point at the character, type
C-u C-x = (
what-cursor-position), and this information, together with much more, will be displayed in the
*Help* buffer that Emacs pops up. See Position Info. For example, Japanese characters belong to the ‘
kana’ script, but Japanese text also mixes them with Chinese characters so the following uses the ‘
han’ script to set up Emacs to use the ‘
Kochi Gothic’ font for Japanese text:
(set-fontset-font "fontset-default" 'han "Kochi Gothic")
(For convenience, the ‘
han’ script in Emacs is set up to support all of the Chinese, Japanese, and Korean, a.k.a. CJK, characters, not just Chinese characters.)
For the list of known scripts, see the variable
Fontset settings like those above only affect characters that the default font doesn’t support, so if the ‘
Kochi Gothic’ font covers Latin characters, it will not be used for displaying Latin scripts, since the default font used by Emacs usually covers Basic Latin.
Some fonts installed on your system might be broken, or produce unpleasant results for characters for which they are used, and you may wish to instruct Emacs to completely ignore them while searching for a suitable font required to display a character. You can do that by adding the offending fonts to the value of the variable
face-ignored-fonts, which is a list. Here’s an example to put in your
(add-to-list 'face-ignored-fonts "Some Bad Font")