How do I set fonts on Emacs for Mac?

MacOS

Question or issue on macOS:

I downloaded Carbon emacs 23.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.35) from http://emacsformacosx.com/. It defaults to using Monaco, and I would like to change it to use Inconsolata-dz. So I added:

(set-default-font "-apple-Inconsolata-dz-medium-normal-normal-*-10-*-*-*-m-0-iso10646-1")

to my ~/.emacs file. However, after I restart, it is still Monaco. It discovered that Option-T (or maybe Command-T) brings up a font dialog, and if I select Inconsolata-dz from that, it works great. But if I restart, it is back to Monaco. So I tried setting the font from the menu, and then going to Customize Faces and saving it, but still it does not work. The interesting thing is that if I do M-x describe-font after changing the font from the Option-T dialog, it says -apple-Inconsolata-dz-medium-normal-normal–10–*-*-m-0-iso10646-1.

So it looks like Emacs is simply ignoring this font for some reason. Why is that, and what can I do to get it to use this font?

Update: I tried Donkopotamus and Joost Diepenaat’s recommendations and they also did not work, although I ended up getting Times as my font, instead of Monaco. However, they work great if I just use the Inconsolata (not Inconsolata-dz). So I’m wondering if there is some problem with fonts with a dash in their name?

Update2: Why is this off-topic? The close message says “questions [should …] relate to programming or software development in some way”; many developers use emacs, and getting settings right is important. The top two entries on a search for “programming fonts” have a combined 150; so font configs seem to be important to programmers. Anyway, if it is off-topic, where is the appropriate place to post it?

How to solve this problem?

Solution no. 1:

I use plain Inconsolata. From my emacs.d/init.el:

(set-face-attribute 'default nil
                    :family "Inconsolata" :height (case system-type
                                                    ('gnu/linux 130)
                                                    ('darwin 145)) :weight 'normal)

If you’re only running on OSX, you can simplify that to

(set-face-attribute 'default nil
                    :family "Inconsolata" :height 145 :weight 'normal)

Solution no. 2:

I use Inconsolata. In my .emacs I simply set the default font to Inconsolata using

; check if we're on OSX
(when (featurep 'ns-win)
  (custom-set-faces
   '(default ((t (:height 140 :width normal :family "Inconsolata")))))
  )

Solution no. 3:

I’ve seen this behavior on Mac, and now I do this in my emacs init file:

(set-face-attribute 'default nil :foundry "apple" :family "Anonymous_Pro")

That works nicely for me, but note that I’m using a newer (HEAD) version of Emacs. You would presumably need to use "Inconsolata-dz" as the value for :family.

Without this, new frames would always pop up using the system-wide default monospaced font (Monaco), which is likely what’s happening for you.

P.S. Your Emacs version is a Cocoa Emacs, not a Carbon Emacs.

Solution no. 4:

Are you sure your .emacs is being read in? For example, are other things in there taking effect?

Assuming that is okay, I use this in my init file:

;; (insert "\n(set-default-font \"" (cdr (assoc 'font (frame-parameters))) "\")\n")

Note that it is intentionally commented out. Now set your font using Command-T, then go to the end of the above line and do C-x C-e . It will insert a command to set your font to whatever it is now. Save/exit/enter Emacs and you should have your font.

Hope this helps!