Font and encoding (in a broad sense, internationalization) are causing problems in many software scenarios, like web browser and editor.

The Unicode U+201C and U+201D are double quotation marks. These two marks are covered by most (if not all) fonts. There are no different code points of double quotation mark for different languages.

What I want to achieve in Emacs is the following. Set the default font to English monospace font (Font A) and use other fonts for characters in certain Unicode range. For example, use Font B for Han characters and Font C for Cyrillic characters.

In my ~/.emacs, I have the following Elisp code.

(set-face-attribute 'default nil :family "Lucida Sans Typewriter" :height 120)

(set-fontset-font "fontset-default" '(#x2000 . #x206f)   ; doesn't work
          "Microsoft YaHei" nil 'prepend)

(set-fontset-font "fontset-default" 'han                 ; works
          "Microsoft YaHei" nil 'prepend)

(set-fontset-font "fontset-default" 'cjk-misc            ; works
          "Microsoft YaHei" nil 'prepend)

(set-fontset-font "fontset-default" 'cyrillic            ; works
          "Consolas" nil 'prepend)

All calls to set-fontset-font work fine except the first that tries to use Microsoft YaHei for General Punctuation section in Unicode. I have also tried changing the order of these set-fontset-font calls, but to no avail.

The reason why it doesn't work, I suspect, is that Emacs only use fallback fonts only if the default font doesn't have the glyphs for the corresponding code points. Since the double quotation marks exist in many languages and thus many fonts have the glyphs for them. Consolas, Lucida Console, Courier, etc. all have the glyphs for them.

Is there any way in Emacs to force to use the specified fonts even if the default font has the glyphs for them?

When coding HTML for Firefox, I have encountered similar situation. I can easily walk around by using the lang="zh" attribute in the body or html tag to tell the browser the document is in Chinese. Is there an Emacs counterpart?

My environment is Emacs 25.1.1 on Windows 7 (en-US).

  • Good question...
    – Drew
    Commented Jan 3, 2017 at 22:37
  • I'm pretty sure this used to work – I had (set-fontset-font t (cons ?– ?–) (font-spec :family "Ubuntu Mono") nil 'prepend) in order to distinguish en and em dashes, and remember looking at how it messed up monospacing. Anyone got Emacs 24 lying around to test with?
    – unhammer
    Commented Jan 5, 2017 at 12:19
  • 3
    NEWS for Emacs 25.2 says: "New variable 'use-default-font-for-symbols', for backward compatibility. This variable allows you to get back pre-Emacs 25 behavior where the font for displaying symbol and punctuation characters was always selected according to your fontset setup. By default, Emacs 25 tries to use the default face's font for such characters, if it supports them, disregarding the fontsets. Set this variable to nil to disable this and get back the old behavior."
    – unhammer
    Commented Apr 22, 2017 at 11:39


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.