2

I'm trying to customize fonts on Emacs with

(custom-theme-set-faces
 'user
 `(org-level-1 ((t (:font "STIXIntegralsUp")))))

but it says "Font not available", despite STIXIntegralsUp being one of the fonts listed by (font-family-list). It only seems to work when I pass it the name or XLFD string of a font visible to xfontsel, but that excludes a lot of fonts installed on my system. In fact, if I go to the GUI menu and click Options > Set Default Font... and pick any named font (I tried about a dozen of them), it will say "Font not available". How can this be? Emacs can't use the output of a font selection dialog that it created?

I'm at a loss here. Does this sound like a Emacs config problem? OS font subsystem problem? Or am I just misusing font specs? I'm a long-time Emacs user, but I've always avoided its messy font subsystem, so I might be just missing something really basic.

I'm on Ubuntu 21.10 with Emacs installed through apt. I did try invoking emacs with --no-init. system-configuration-options is

--build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
  --libexecdir=/usr/lib --localstatedir=/var/lib
  --infodir=/usr/share/info --mandir=/usr/share/man
  --enable-libsystemd --with-pop=yes
  --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/27.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/27.1/site-lisp:/usr/share/emacs/site-lisp
  --with-sound=alsa --without-gconf --with-mailutils --build
  x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
  --libexecdir=/usr/lib --localstatedir=/var/lib
  --infodir=/usr/share/info --mandir=/usr/share/man
  --enable-libsystemd --with-pop=yes
  --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/27.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/27.1/site-lisp:/usr/share/emacs/site-lisp
  --with-sound=alsa --without-gconf --with-mailutils --with-cairo
  --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
  'CFLAGS=-g -O2
  -ffile-prefix-map=/build/emacs-P5Mppj/emacs-27.1+1=. -fstack-protector-strong
  -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
  -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions
  -Wl,-z,relro'
9
  • Does the font name you provide perhaps need to be a complete name? It looks like you're passing only the name of a font family, not the name of a font. Is that what :font expects? (I don't know, but that's where I'd start looking...)
    – Drew
    Commented Jan 3, 2022 at 16:08
  • By "complete name", you mean ones like "STIXIntegralsUp Regular", right? That's basically the name I pick from Options > Set Default Font. I don't know which type of name :font expects either, but both of them give "Font not available".
    – Jun Inoue
    Commented Jan 4, 2022 at 10:13
  • I meant a font name like this: "-*-Lucida Console-normal-r-*-*-14-*-*-*-c-*-iso8859-1". But I'm only guessing at what the function expects. (What does its doc or code tell you?) In general, a font family name is not the same as a font name, I believe.
    – Drew
    Commented Jan 4, 2022 at 16:48
  • 2
    What does M-: (frame-parameter nil 'font-backend) give you? If it's only 'x', then you have something disabling the FreeType font backend, maybe something in .Xdefaults. You can try emacs -Q, that will disable loading X resources as well.
    – rpluim
    Commented Jan 4, 2022 at 18:39
  • @rpluim You're spot on! I had an ancient setting in my .Xresources that I added a decade ago without a clue about what I was doing, and then completely forgot about. Do you mind writing a proper answer so I can accept it?
    – Jun Inoue
    Commented Jan 6, 2022 at 14:33

2 Answers 2

3

This is a symptom of something overriding Emacs' default font backend. If the result of

M-: (frame-parameter nil 'font-backend)

is something like (x), then that's what happening, since it should be something like (ftcrhb x) for recent versions of Emacs under X11.

The cause is usually an old FontBackend specification in either your personal or system xresources file, or a site-lisp file setting it. If

emacs --no-x-resources

fixes the issue, then it's a FontBackend specification (often in "~/.Xdefaults" or "~/.Xresources"). If that doesn't fix it, but running without any config at all, ie:

emacs -Q

fixes it instead, then it's a lisp file loaded by Emacs that's at fault.

0

After upgrading emacs 26 to 28, fonts only worked properly after I deleted the following font-backend line from init.el :

(setq default-frame-alist
      '((width . 180) (height . 52)
        (background-color . "black")
        (foreground-color . "white")
        (font . "Noto Sans Mono-9")
        (font-backend xft x) ;; this line has to go !!
 ))
1
  • 1
    How does this answer relate to the question? Was the symptom of not-working-properly in your case the same error message as in the question? If so, maybe add that info to your answer. Thx.
    – Drew
    Commented Jun 3, 2022 at 16:53

Your Answer

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

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