Turning off antialiasing for specific fonts only

I like antialiased fonts for many things, such as web surfing or reading on my iPad, in fact, I could not imagine reading on the iPad without antialiasing. However, one application where the invent of antialiased fonts has always bugged me is text editors for programming. This is perhaps a relic of the past as I grew up with pixelated editor fonts, or simply because I use pixelated fonts for working on the console. I’m not actually sure myself.

To cut a long story short: I’ve been trying to tell emacs for quite some time to disable antialiased fonts, but to no avail. Apparently in Aqua-emacs on the Macintosh, one can set a flag in the emacs preferences, which is not available under Linux. The reason, apparently, is that emacs doesn’t really do much in terms of font handling on Linux and uses pretty much what X, or rather X’s font server provides it with.

Today, I found a solution to my dilemma, which I think makes a neat first post on this blog. Most Linux distributions will use a file called fonts.conf which is either located in /etc/fonts or under the name .fonts.conf inside a user’s home directory. (A good way to get a useful .fonts.conf is to copy the one from /etc/fonts to $HOME/.fonts.conf.) Inside this file, you need to add something along the lines of

<match target="pattern" name="family">
    <test name="family" qual="any"><string>Envy Code R</string></test>
    <edit name="antialias" mode="assign">
        <bool>false</bool>
    </edit>
</match>

This turns off antialising for the Envy Code R programming font, but ensures that other fonts remain antialiased (if antialising was the default behaviour before, otherwise you need to add a statement to enable it). So you get the best of both worlds, sharp, readable fonts in emacs, and polished fonts in your browser. Note that there are quite a number of fonts, specifically designed for programming, such as ProFont or Proggy, which are unusable when antialiased.

To see the result of the above addition to the configuration file, take a look at this screenshot which features a pixelated programming font Envy Code R in the left frame, and an antialised Arial in the right: