0

I have the following in my init.el:

(add-to-list 'default-frame-alist
             '(font . "Monaco-10"))

The above does the job, but Emacs uses some other fonts when displaying headlines in org files or words enclosed in ‘’ quotes in Emacs info (C-h i). I would like to have a way to set up those fonts myself as well. Is there a way?

Here is an image denoting the different fonts used for different parts. You can see that the fonts used for the headline and the fonts used for text between ‘’ quotes (denoted by pink highlight) are different than the default Monaco font used otherwise. It's pretty easy to see the differences, I hope. Emacs info page

  • FYI: you can put your cursor on (just before) a character and hit C-u C-x = to see just what font is used there. – Drew Apr 19 at 15:30
  • Headline is DejaVu Sans and text inside quotes is bitstream-Courier – klaus Apr 19 at 15:44
  • Using C-u C-x = you can see the name of the face and also the name of the font family. To change which font family is used for a face, (set-face-attribute 'facename nil :family "fontname"). For example, the headline can be set with (set-face-attribute 'info-title-2 nil :family "Comic Sans MS") You can also use :height to set the font height. – amitp Apr 19 at 16:16
  • @amitp, I want to change all fonts to Monaco. I don't want to set each of the info-title-3 etc. separately. How do I do that? – klaus Apr 19 at 16:22
  • They are separate faces to let you (anyone), well, give them different appearances. So yes, you "have to" customize each face separately. But you can of course define one and customize the others to just inherit from it. That way, if you want to change all 3 at once in the future you can just customize the one that is inherited. – Drew Apr 19 at 18:02
1

Emacs uses/defines/handles fonts in ways that you might not be used to. Fonts are treated as attributes of Faces (Emacs Manual: Faces). A Face has several attributes (Emacs Manual: Face Attributes), colors, over/under line, strike-through, size, generic font specification, specific font specification, etc. For your purposes I think you want the :font attribute. In fact, this is what your doing (under the hood) when you specify a font in default-frame-alist; your setting the :font attribute of the default face, default-face.

To see a list of all (currently defined) faces do: Meta-x list-faces-display RET. You'll get a list of face names on the left, and abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ styled according to the face on the right. Clicking on the face name will bring you to the customize facility where you can view or edit the face to your whims.

I recommend against doing that for every. Single. Face. You'll go mad. Instead, if you find a stray face that you don't like, use the key-chord that @Drew recommended (C-u C-x =) to find the face name and its current font. You can then use M-x customize-face RET "face name" to customize that face.

If I was in your current situation though I'd do the following.

  • Make sure the generic fonts ("serif" "sans" (or "sans serif") and "monospace") for your OS/desktop are set to fonts you like. Emacs will uses these if other more specific fonts aren't defined.
  • Using X11? Make sure there's nothing screwy in your user and system Xdefaults or Xresources
  • Make sure you're getting your font everywhere.

In macOS I use Aquamacs. Boiling down the font stuff in my init file I have:

(set-frame-font "Menlo:size=12")
(setq default-frame-alist nil)
(load-theme 'sanityinc-tomorrow-bright t)

This will:

  1. set the default font
  2. clear the default-frame-alist (Aquamacs does (did?) some stuff there that I don't like)
  3. load my chosen theme, which then sets faces as it needs

Of the 350 or so faces defined in my current session, almost all are Menlo derived.

Your specific example

Note, I worked through the following with emacs 26.1 built from source with GTK3 and fontconfig support on Ubuntu 18.04

You list two specific points in your example. The first, the pink-highlighted-quoted text. If you C-u C-x =, you'll see this text is in the Info-quoted face. Drilling into the Info-quoted face, you'll see it inherits from fixed-pitch-serif. In turn, you'll find that fixed-pitch-serif is defined as using the Monospace Serif family. This generic font family (a la "monospace", "sans serif" and "serif") is an Emacs-ism. This defined in a a customizable variable face-font-family-alternatives in faces.el. Manipulating this variable to redefine Monospace Serif to include your choice of Monaco gave me no results. Setting fixed-pitch-serif to use the :family of Monaco worked perfectly fine.

The second example (from your comment) was the header. Doing C-u C-x = again we get info-title-1. From here we get info-title-2 -> info-title-3 -> info-title-4 -> variable-pitch. The face variable-pitch is defined in as the font family "Sans Serif". This is a fontconfig generic font family that your system should set. (Locally, I have "Sans Serif" set to "DejaVu Sans".) This should be set to your liking in your DE so that you have a consistent look across your DE. If you want to change it in Emacs, set the face variable-pitch. (I don't recommend setting it to a monospace font, like Monaco, but it's your Emacs.)

These faces, fixed-pitch-serif and variable-pitch are not defined in terms of the default face, but can be set like any other face, via the customize facility (M-x customize-face RET <facename>) or directly. There are two functions you can use to set faces directly. The first is set-face-attribute. You could put the following in your init file.

(set-face-attribute 'fixed-pitch-serif nil :family  "Monaco")
(set-face-attribute 'variable-pitch :family "Liberation Sans")

Note that the documentation of set-face-attribute states that it is intended for internal use.

The second, set-face-font is a specialization of set-face-attribute. It uses the attributes of the given font to define the given face. The more specific the font, the more specific the attributes of the face.

(set-face-font 'fixed-pitch-serif "Monaco")
(set-face-font 'variable-pitch "Liberation Sans")

Additionally, I still recommend using set-frame-font to set your default font. Setting its third argument to t will set the font for all subsequent frames, in addition to the initial frame.

(set-frame-font "Monaco-10" nil t)

See it's documentation via C-h f set-frame-font RET for more details. Putting it all together you could do the followng:

(set-frame-font "Monaco-10" nil t)
(set-face-font 'fixed-pitch-serif "Monaco")
(set-face-font 'variable-pitch "Liberation Sans")

To get something more to your liking. In fact I have that in a trial ~/.emacs and it's working fine, even with emacsclient -c.

tl;dr

No. There is no magic command, or setting, that will allow you to change all of the fonts in Emacs at once. As pointed out by @drew and @amitp in their comments, you'll need to set faces that don't derive from the default face yourself. In order to set as many as possible, you need to do the following:

  • Make sure your system generic fonts ("monospace", "sans serif", "serif") are set to your liking
  • Use set-frame-font or default-frame-alist to set the default font (or more specifically the font of the default face)
  • Figure out the "root" face that non-conforming faces inherit from, and set that to your liking (a la the fixed-pitch-serif and variable-pitch examples above)
  • a little long winded, but hopefully helpful :) – nega Apr 19 at 16:50
  • When specifying fonts I recommend you always do it the same way. ie always use Monaco-10, or Monaco:size=10 or -*-Monaco-normal-normal-normal-*-10-*-*-*-m-0-iso10646-1. Pick one and stick with it. (Obvious pick one that your font engine supports.) – nega Apr 19 at 17:01
  • This answer doesn't work. Also, I need default-frame-alist for emacsclient. Otherewise, emacsclient -c doesn't care for only set-frame-font part. – klaus Apr 19 at 17:06
  • Ok so what version of Emacs, on what OS and DE? Is it pkg’d or built from source? – nega Apr 21 at 15:10
  • Built from source, version 26.1, the stable one that I can download from gnu ftp site. DE is dwm, OS is ubuntu 18.04. – klaus Apr 22 at 3:51

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.