Emacs: Font Setup

By Xah Lee. Date: . Last updated: .

This page shows you how to set font for emacs.

Change Current Buffer Font Size Interactively by Command

Alt+x text-scale-increase
Make font size larger in current buffer.
Alt+x text-scale-decrease
Make font size smaller in current buffer.
Alt+x text-scale-adjust
Changes font size in current buffer. Call it, then press + to increase, - to decrease. You can press them repeatedly. Press 0 to set it back to default size. Press any key to exit.

Change Font/Size Globally by Menu

Chose the menu [Options ▸ Set Default Font…], then menu [Options ▸ Save Options].

emacs font size menu 2021-03-18
emacs font size menu 2021-03-18
emacs font size dialog 2021-03-18
emacs font size dialog 2021-03-18

Find the Current Font Used

Alt+x describe-char, then look at the line in “display:”. It shows the font used for the character under cursor.

emacs describe-char 2021-09-25 TyYb
emacs Alt+x describe-char

Set Default Font/Size Globally in Init File

Use set-frame-font to set default font and size.

(when (member "Consolas" (font-family-list))
  (set-frame-font "Consolas" t t))

You can add a font size:

(when (member "Consolas" (font-family-list))
  (set-frame-font "Consolas-14" t t))

or

;; set default font
(cond
 ((string-equal system-type "windows-nt") ; Microsoft Windows
  (when (member "Consolas" (font-family-list))
    (set-frame-font "Consolas" t t)))
 ((string-equal system-type "darwin") ; macOS
  (when (member "Menlo" (font-family-list))
    (set-frame-font "Menlo" t t)))
 ((string-equal system-type "gnu/linux") ; linux
  (when (member "DejaVu Sans Mono" (font-family-list))
    (set-frame-font "DejaVu Sans Mono" t t))))

See also: Elisp: Determine OS, Emacs Version, Machine Host Name

List available fonts

(print (font-family-list))

Select the elisp code, then Alt+x eval-region. [see Evaluate Emacs Lisp Code]

You can see the result in “*Messages*” buffer. view-echo-area-messagesCtrl+h e】.

For linux, see Standard Fonts on Linuxes

Check if a font exist

;; returns true if Symbola exists
(member "Symbola" (font-family-list))

[see Emacs: Evaluate Elisp Code]

Set Font for Emoji

;; set font for emoji
(set-fontset-font
 t
 '(#x1f300 . #x1fad0)
 (cond
  ((member "Noto Color Emoji" (font-family-list)) "Noto Color Emoji")
  ((member "Noto Emoji" (font-family-list)) "Noto Emoji")
  ((member "Segoe UI Emoji" (font-family-list)) "Segoe UI Emoji")
  ((member "Symbola" (font-family-list)) "Symbola")
  ((member "Apple Color Emoji" (font-family-list)) "Apple Color Emoji"))
 ;; Apple Color Emoji should be before Symbola, but Richard Stallman disabled it.
 ;; GNU Emacs Removes Color Emoji Support on the Mac
 ;; http://ergoemacs.org/misc/emacs_macos_emoji.html
 ;;
 )

[see Unicode Emoji 😄 😱 😸 👸 👽 🙋]

[see Download Free Unicode Fonts]

Set Font for Chinese

;; set font for chinese
(set-fontset-font
 t
 'han
 (cond
  ((string-equal system-type "windows-nt")
   (cond
    ((member "Microsoft YaHei" (font-family-list)) "Microsoft YaHei")
    ((member "Microsoft JhengHei" (font-family-list)) "Microsoft JhengHei")
    ((member "SimHei" (font-family-list)) "SimHei")))
  ((string-equal system-type "darwin")
   (cond
    ((member "Hei" (font-family-list)) "Hei")
    ((member "Heiti SC" (font-family-list)) "Heiti SC")
    ((member "Heiti TC" (font-family-list)) "Heiti TC")))
  ((string-equal system-type "gnu/linux")
   (cond
    ((member "WenQuanYi Micro Hei" (font-family-list)) "WenQuanYi Micro Hei")))))

Note: 2020-05-28, in emacs 26 or before, on Microsoft Windows 10, if you don't set font for Chinese, and if a buffer has Chinese character, then emacs operation such as moving cursor will be super slow, like 1/3 of a second when you press arrow key. See also: Chinese Font

Set Font for Symbols

;; set font for symbols
(set-fontset-font
 t
 'symbol
 (cond
  ((string-equal system-type "windows-nt")
   (cond
    ((member "Segoe UI Symbol" (font-family-list)) "Segoe UI Symbol")))
  ((string-equal system-type "darwin")
   (cond
    ((member "Apple Symbols" (font-family-list)) "Apple Symbols")))
  ((string-equal system-type "gnu/linux")
   (cond
    ((member "Symbola" (font-family-list)) "Symbola")))))

Set Font for Other Languages

Use the code similar to symbol above, except, change the 'symbol to a script name that's listed by the variable script-representative-chars. Alt+x describe-variable to see its value. Then, find out what's the font name in your operating system that supports that script.

;; set font for cuneiform
(set-fontset-font
 t
 'cuneiform
 (cond
  ((string-equal system-type "windows-nt")
   (cond
    ((member "Segoe UI Historic" (font-family-list)) "Segoe UI Historic")))
  ((string-equal system-type "darwin")
   (cond
    ((member "Noto Sans Cuneiform Regular" (font-family-list)) "Noto Sans Cuneiform Regular")))
  ((string-equal system-type "gnu/linux")
   (cond
    ((member "Noto Sans Cuneiform Regular" (font-family-list)) "Noto Sans Cuneiform Regular")))))

(set-fontset-font
 t
 'phoenician
 (cond
  ((string-equal system-type "windows-nt")
   (cond
    ((member "Segoe UI Historic" (font-family-list)) "Segoe UI Historic")))
  ((string-equal system-type "darwin")
   (cond
    ((member "Noto Sans Phoenician Regular" (font-family-list)) "Noto Sans Phoenician Regular")))
  ((string-equal system-type "gnu/linux")
   (cond
    ((member "Noto Sans Phoenician Regular" (font-family-list)) "Noto Sans Phoenician Regular")))))

(set-fontset-font
 t
 'deseret
 (cond
  ((string-equal system-type "windows-nt")
   (cond
    ((member "Segoe UI Symbol" (font-family-list)) "Segoe UI Symbol")))
  ((string-equal system-type "darwin")
   (cond
    ((member "Apple Symbols" (font-family-list)) "Apple Symbols")))
  ((string-equal system-type "gnu/linux")
   (cond
    ((member "Noto Sans Deseret" (font-family-list)) "Noto Sans Deseret")))))

(set-fontset-font
 t
 'shavian
 (cond
  ((string-equal system-type "windows-nt")
   (cond
    ((member "Segoe UI Historic" (font-family-list)) "Segoe UI Historic")))
  ((string-equal system-type "darwin")
   (cond
    ((member "Apple Symbols" (font-family-list)) "Apple Symbols")))
  ((string-equal system-type "gnu/linux")
   (cond
    ((member "Noto Sans Shavian Regular" (font-family-list)) "Noto Sans Shavian Regular")))))

(set-fontset-font
 t
 'egyptian
 (cond
  ((string-equal system-type "windows-nt")
   (cond
    ((member "Segoe UI Historic" (font-family-list)) "Segoe UI Historic")))
  ((string-equal system-type "darwin")
   (cond
    ((member "Noto Sans Egyptian Hieroglyphs" (font-family-list)) "Noto Sans Egyptian Hieroglyphs")))
  ((string-equal system-type "gnu/linux")
   (cond
    ((member "Aegyptus" (font-family-list)) "Aegyptus")))))

How to Display Emoji on MacOS

emacs on macOS unicode 2017 09 22 44951
Emacs on macOS does not do emoji by default, 2017-09-22

FSF GNU emacs disabled displaying color emoji on Mac, so that Mac won't work better than linux. See GNU Emacs Removes Color Emoji Support on the Mac

Solution:

download font “symbola” at Download Free Unicode Fonts

Put this in your emacs init file:

;; specify font for all unicode characters
(when (member "Symbola" (font-family-list))
  (set-fontset-font t 'unicode "Symbola" nil 'prepend))
emacs on macOS unicode fixed 2017 09 22 25437
Emacs on MacOS, displaying emoji using font Symbola, 2017-09-22

How to install font

Restart emacs. Emacs should see it.

Reference

Unicode and Font

Put $5 at https://www.patreon.com/xahlee , or goto paypal.com and pay to Xah@XahLee.org . Message me on XahLee discord, say so, ask me questions.
Or Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


Emacs Init

Init Basics

packages

text editing

file

appearance

misc