[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How do I set up font fallback in a robust way?

From: Clément Pit--Claudel
Subject: How do I set up font fallback in a robust way?
Date: Sat, 9 Apr 2016 15:14:50 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0

Hi emacs-devel,

I'm cross-posting this from https://emacs.stackexchange.com/questions/17205 
following Eli's suggestion; I couldn't figure this out from reading the manual.

TL;DR: What's a simple way to reliably say: use Ubuntu Mono as the default 
font, FreeMono for the characters unsupported by Ubuntu Mono, and Symbola for 
characters unsupported by both?

Since my main programming font does not cover all the mathematical symbols I 
need, I initially set up font fallback as shown below:

    (set-fontset-font t 'unicode (font-spec :name "FreeMono") nil 'append)
    (set-fontset-font t 'unicode (font-spec :name "Symbola") nil 'append)

Unfortunately this also changed the font for some of the character that my main 
font (Ubuntu Mono) supports, so I changed it to

    (set-fontset-font t 'unicode (font-spec :name "Ubuntu Mono") nil)
    (set-fontset-font t 'unicode (font-spec :name "FreeMono") nil 'append)
    (set-fontset-font t 'unicode (font-spec :name "Symbola") nil 'append)

If my understanding is correct, this should ensure that characters that Ubuntu 
Mono cannot handle are handled by FreeMono, unless FreeMono doesn't have them, 
in which case they should be displayed using Symbola. It is also my 
understanding that `t` does the same as `"fontset-default"` above.

Unfortunately, there were still cases where the right font wasn't selected; I 
found that changing to

    (set-fontset-font t 'unicode (font-spec :name "Ubuntu Mono") nil)
    (set-fontset-font t 'unicode (font-spec :name "FreeMono") nil 'append)
    (set-fontset-font t 'unicode (font-spec :name "Symbola") nil 'append)
    (set-fontset-font "fontset-startup" 'unicode (font-spec :name "Ubuntu 
Mono") nil)
    (set-fontset-font "fontset-startup" 'unicode (font-spec :name "FreeMono") 
nil 'append)
    (set-fontset-font "fontset-startup" 'unicode (font-spec :name "Symbola") 
nil 'append)

worked better, but not always: changing the font size using

    (set-face-attribute 'default nil :height some-size)

caused the fallbacks to be ignored, due to new fontsets being created.

My current solution is to do

    (set-fontset-font fontset 'unicode (font-spec :name "Ubuntu Mono") nil)
    (set-fontset-font fontset 'unicode (font-spec :name "FreeMono") nil 'append)
    (set-fontset-font fontset 'unicode (font-spec :name "Symbola") nil 'append)

on each fontset (`fontset-list`), after each font size change. This is 
cumbersome, and I have trouble imagining that it's the right solution.

What's the proper way to configure font fallback?

*Note*: for testing purposes, here are a few math characters: 

*References*: Emacs manual on 
 and on [modifying 


Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]