1

I'm new to Emacs, and would like to know how to append my init.el file to use specific fonts for different languages. Specifically, for English (and other Latin-based languages, I guess) I would like Emacs to use DeJaVu Mono, but for Thai I would like it to use TH Sarabun

I have read https://www.gnu.org/software/emacs/manual/html_node/emacs/Fontsets.html and will admit that I understand nothing on that page.

I'm actually trying to set up emacs to be an environment to write linguistic documentation, and am not a programmer, though I am willing to learn, though perhaps I need some hand holding, as I've never attempted something like this before.

Thanks

  • Please consider filing a doc bug (enhancement request), mentioning specifics as much as possible (just which parts are unclear to you etc.). To do that: M-x report-emacs-bug. This could help a lot of people. – Drew Mar 20 '17 at 0:41
1

I used the following function to set Latin characters and Japanese characters separately.

Full configuration: https://github.com/kaz-yos/emacs/blob/5fe90b4256de8d85c1c85fa39139a7ba944ea073/init.d/200_language-and-font-related.el#L33-L65

(defun update-current-frame-fontset-mac ()
  "Update current frame fontset with Japanese font setting (macOS)"
  (let* (;; Ascii font name (pick from (font-family-list))
         (my-ascii-font "Menlo")
         ;; Japanese font name (pick from (font-family-list))
         (my-jp-font    "Hiragino Maru Gothic ProN")
         ;; Create :family-only font specifications (use later)
         ;; #<font-spec nil nil Menlo nil nil nil nil nil nil nil nil nil nil>
         (my-ascii-fontspec (font-spec :family my-ascii-font))
         ;; #<font-spec nil nil Hiragino\ Maru\ Gothic\ ProN nil nil nil nil nil nil nil nil nil nil>
         (my-jp-fontspec    (font-spec :family my-jp-font)))
    ;;
    ;; Return the value of FACE’s ATTRIBUTE on (current) FRAME.
    ;; (face-attribute 'default :fontset) returns the current frame's fontset,
    ;; which can be updated for some letters via set-fontset-font

    ;; For these Japanese character sets, use my-jp-fontspec
    (set-fontset-font (face-attribute 'default :fontset)
                      'japanese-jisx0213.2004-1 my-jp-fontspec    nil 'append)
    (set-fontset-font (face-attribute 'default :fontset)
                      'japanese-jisx0213-2      my-jp-fontspec    nil 'append)
    ;; For Half-sized katakana characters, use my-jp-fontspec
    (set-fontset-font (face-attribute 'default :fontset)
                      'katakana-jisx0201        my-jp-fontspec    nil 'append)
    ;;
    ;; For the characters in the range #x0080 - #x024F, use my-ascii-fontspec
    ;; Latin with pronounciation annotations
    (set-fontset-font (face-attribute 'default :fontset)
                      '(#x0080 . #x024F)        my-ascii-fontspec nil 'append)
    ;; For the characters in the range #x0370 - #x03FF, use my-ascii-fontspec
    ;; Greek characters
    (set-fontset-font (face-attribute 'default :fontset)
                      '(#x0370 . #x03FF)        my-ascii-fontspec nil 'append)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.