11

I am trying to set [Inconsolata-dz][1] as my default font to Emacs. Regular Inconsolata works fine, but the dz version is not working properly. Most functions I use keep throwing this error (followed all the instructions online on how to set Emacs font):

set-face-attribute: Invalid font name: "-*-Inconsolata-dz-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1"

I finally got it to work by doing this in my init.el:

(setq initial-frame-alist '((font . "Inconsolata-dz-13")))
(setq default-frame-alist '((font . "Inconsolata-dz-13")))

I also have this in init.el, which was generated by customize-faces, but it seems to change the font to Helvetica (unless overridden by the code above):

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-safe-themes
   (quote
    ("e16a771a13a202ee6e276d06098bc77f008b73bbac4d526f160faa2d76c1dd0e"
     "d677ef584c6dfc0697901a44b885cc18e206f05114c8a3b7fde674fce6180879"
     "8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4"
     default))))

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :inverse-video nil
             :box nil :strike-through nil :overline nil
             :underline nil :slant normal
             :weight normal :height 140 :width normal
             :foundry "nil" :family "Inconsolata-dz")))))

Now the issue with the first code above is that doing a Ctrl+N, to create a new window will throw the same Invalid font name error.

I installed Inconsolata and Inconsolata-dz the same way on my Mac. Just the regular, default way of installing fonts on OS X.

Does anyone know what I'm doing wrong and how I can use Inconsolata-dz properly?

darksky
  • 275
  • 1
  • 7
  • 1
    To see what fonts are available, evaluate the following in a `*Scratch*` buffer: `(insert (prin1-to-string (x-list-fonts "*")))` If it is not there, then it's not available. – lawlist Sep 23 '15 at 18:30
  • @lawlist I see it there but it is a very long name. When I pasted it into set-face-attribute, `((set-face-attribute 'default nil :family "-*-Inconsolata-g-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1"))`, I get 'Invalid face foundry'. Any ideas why? What exactly is the name suppose to be? Inconsolata works but Inconsolata-g and Inconsolata-dz do not work, even though they're all available and installed the same way. I suspect it's the dash in the name? – darksky Sep 24 '15 at 14:40

1 Answers1

10

Emacs doesn't allow fonts that have hyphens in them. I would rename the font to something that doesn't contain hyphens.

You can do this using ttx. For example, assuming you have a font named Inconsolata-dz for Powerline.otf in your current working directory:

# Convert the font to ttx format (an xml-like font format)
ttx "Inconsolata-dz for Powerline.otf"

# Replace all instances of "Inconsolata-dz" with "InconsolataDZ" in the ttx file
sed -i 's/Inconsolata-dz/InconsolataDZ/g' "Inconsolata-dz for Powerline.ttx"

# Convert the resulting ttx file back to an otf file. 
# (Will create a file called "Inconsolata-dz for Powerline#1.otf".)
ttx "Inconsolata-dz for Powerline.ttx"

You can then rename the produced otf file to whatever you want and move it to your fonts directory.

sid-kap
  • 544
  • 1
  • 6
  • 13
  • Do you have an example or a link to some documentation to support your belief that "*Emacs doesn't allow fonts that have hyphens in them.*"? – lawlist Dec 19 '16 at 00:29
  • 5
    My specific problem was that I was seeing the error "Invalid font name: Inconsolata-g for Powerline". I searched the Emacs source code for "Invalid font name:" and found [this function](https://github.com/emacs-mirror/emacs/blob/88fefc3291060f18503738aaa4e81b98f1970a55/src/font.c#L3937). I believe that if you look carefully at the `font_parse_name` function, you'll find that parses the XFT string by splitting it at the hyphens, assuming that the entire font name is contained between two hyphens. – sid-kap Dec 19 '16 at 00:33
  • 1
    Thanks so much @sid-kap, finally an answer! I've never figured this one out. – darksky Dec 20 '16 at 15:32
  • 3
    You can rename the font without using `ttx` nor converting the font files. I visited the font files `Inconsolata-g.otf`, `Inconsolata-g.sfd`, and `Inconsolata-g.ttf` with `Emacs` and replaced every occurrence of "Inconsolata-g" and "Inconsolata-d" with "Inconsolata_g" and "Inconsolata_d". This text also appears intermingled with "^@" as in "I^@n^@c^@o^@n^@s^@o^@l^@a^@t^@a^@-^@g^@Inconsolata-g" which I have replaced as "I^@n^@c^@o^@n^@s^@o^@l^@a^@t^@a^@_^@g^@Inconsolata_g". I have then renamed the filenames as `Inconsolata_g.*` and drag-and-drop'd them into `Font Book.app`, which worked. – armando.sano Mar 22 '17 at 13:24
  • @sid-kap Thank you, your instructions were very clear. Great answer. – Harsh Vardhan Apr 02 '18 at 16:27
  • @armando.sano This also worked for me with the fixed-9x15 dfont on the Mac. Works great now. – dar512 Dec 03 '19 at 20:02