views:

395

answers:

2

In the interest of making my emacs setup more portable, I'd like to be able to set the current font by specifying a file rather than a font name, i.e. "Load ~/config/myfont.ttf and use size 12". Is there a way to do that in my .emacs? All the instructions I've found assume the font is already installed on the system. I'm using the XFT support on Linux, so a linux specific hack would be OK but I'd prefer something that would work on all targets.

Update: To be clear, I'm using a font that isn't standard on Windows / OS X / Linux. I'm not just looking to set a different font based on platform, but to specify a specific font file that I have (TTFs work on Windows and Linux, if not on Mac I'll get another version of the file but I still want to specify the font via file rather than name).

A: 

Emacs uses platform-specific widgets on every platform, so you should use system routines to setup concrete fonts. I have system-dependent configurations in different files, that are loaded from .emacs with something like

(load (concat "~/.emacs.d/rc-" system-type))
Alex Ott
Thanks for the tip, but this isn't quite what I'm looking for, see my edit above.
Joseph Garvin
I'm not sure, that it possible, as Emacs doesn't works with fonts directly
Alex Ott
+2  A: 

Unfortunately, you can't.

Emacs on different platforms uses different windowing toolkits, all of which take care of font handling for it. I don't believe you can specify a font filename in Emacs on any platform - it just doesn't work that way.

As for how to find the font:

  • On Linux, you could use XFT's support for a user-specific font config file which is usually ~/.fonts.conf (but check /etc/fonts/font.conf to be sure) to add whatever directory you place your fonts into.

  • On a Mac, you can add the font into ~/Library/Fonts. TTFs work fine on Macs, BTW.

  • On Windows, I think you'd just have to add it to the system fonts directory.

From there, you then go and tell Emacs (through customize or not) to use your font. You'll find the naming schemes to be different on each platform (not sure what Windows looks like), but customize should help take care of this for you - just keep a separate customize file per machine if need be.

...so basically your portable Emacs setup has to encompass more than just an Emacs config file (which, given that you're carrying a font file around, it already does).

Cos