0

I'm trying to set a fallback font for variable-pitch face.

More specifically, my current setup is:

  • Default font set to JuliaMono with size 15 via (set-frame-font "JuliaMono 15" nil t).
  • Fallback font for hangul (Korean) via (set-fontset-font t 'hangul (font-spec :name "D2Coding")).
  • Variable pitch face set to EB Garamond with size 19 via (set-face-attribute 'variable-pitch nil :font "EB Garamond" :height 190).

Is there a way to specifically add a new font used for Korean for variable pitch face (I'm trying to use Noto Serif CJK KR)? https://idiocy.org/emacs-fonts-and-fontsets.html only points to setting fallback fonts for different languages, and not face-specific.


Edit I spent the whole afternoon trying this--it is driving me mad!

I'm setting the default fonts following this and this:

(add-to-list 'after-make-frame-functions #'set-default-fonts)
(defun set-default-fonts (_)
  (set-face-attribute 'default nil :font "JuliaMono 15")
  (set-fontset-font "fontset-default" 'hangul (font-spec :family "D2Coding"))
  (setq face-font-rescale-alist '(("D2Coding" . 1.2))))

Rescaling "D2Coding" is to make a single monospaced Korean letter correspond to two monospaced alphabets. The (add-to-list ...) part is to make it work with emacs --daemon.

I'm trying to use mixed-pitch package to achieve variable pitch mode default in Org mode, so:

(use-package mixed-pitch
  :ensure t
  :hook
  (org-mode . mixed-pitch-mode)
  :config
  (setq mixed-pitch-set-height t)
  (set-face-attribute
   'variable-pitch nil :font "fontset-myvariable"))

where the custom fontset "fontset-myvariable" is set via:

(create-fontset-from-fontset-spec
 (font-xlfd-name
  (font-spec :family "EB Garamond"
         :size 19
         :registry "fontset-myvariable")))
(set-fontset-font
 "fontset-myvariable"
 'hangul (font-spec :family "Noto Serif CJK KR" :size 19))

With this, (EB Garamond in variable pitch face + English) & (D2Coding in fixed with + Korean) works great, but (variable pitch face + Korean) is in D2Coding not Noto Serif CJK KR.

1 Answer 1

1

You can create your own fontset with EB Garamond as the default font and Noto Serif CJK KR as the hangul font, and then assign that to the :font attribute of variable-pitch.

According to the docs:

‘:font’
     The font used to display the face.  Its value should be a font
     object or a fontset.  [...]

What strangely seems to work for me is setting both :font and :fonset:

(create-fontset-from-fontset-spec
 (font-xlfd-name
  (font-spec :family "EB Garamond"
             :size 19
             :registry "fontset-variable")))

(set-fontset-font "fontset-variable" 'hangul
                  (font-spec :family "Noto Serif CJK KR"
                             :size 19
                             :registry "iso10646-1"))

(set-face-attribute 'variable-pitch nil
                    :font "fontset-variable" :fontset "fontset-variable")

My Emacs is:

GNU Emacs 29.0.50 (build 1, x86_64-apple-darwin21.5.0, NS appkit-2113.50 Version 12.4 (Build 21F79)) of 2022-07-25
7
  • Thank you for the help, but I can't make Noto Serif CJK KR as the hangul font--it only shows in D2Coding. I updated the post to show my setup...
    – Jay Lee
    Jul 25 at 15:34
  • What happens if you use (set-face-attribute 'variable-pitch nil :fontset "fontset-myvariable") (i.e., :fontset instead of :font)?
    – d125q
    Jul 25 at 16:23
  • Unfortunately, EB Garamond won't show up as well with :fontset.
    – Jay Lee
    Jul 25 at 17:55
  • The problem even happens when I try to set-fontset-font to other languages, e.g., 'greek. So basically the font is stuck with the one created with (create-fontset-... (font-xlfd-name (font-spec ...).
    – Jay Lee
    Jul 25 at 18:00
  • Please try setting both :font and :fontset, as per my edit.
    – d125q
    Jul 25 at 19:39

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.