I'm having trouble with fontconfig recognizing the ui-monospace
font that several websites (including Github and Stack Exchange sites) have recently started using. Firefox doesn't yet have that special CSS reference to system fonts (see FF bug 1226042, the draft spec, and its Can I Use entry), and FF is also fooled by fontconfig, which will satisfy any font with its default assignment for sans-serif.
As a workaround, I'd like to explicitly alias this font name to my preferred monospace font (which is Panic Sans, a tweaked DejaVu Sans Mono variant that nudges the underscore up a little), but since that's so obscure, this question uses DejaVu Sans Mono.
My first attempt at this workaround doesn't work:
<alias>
<family>ui-monospace</family>
<prefer><family>DejaVu Sans Mono</family></prefer>
</alias>
Another attempt that has had more success for other fonts:
<match>
<test name="family"><string>ui-monospace</string></test>
<edit name="family" mode="assign" binding="strong">
<string>DejaVu Sans Mono</string>
</edit>
</match>
When I save that and flush my cache, it doesn't work:
$ grep ui.monospace ~/.config/fontconfig/fonts.conf
<test name="family"><string>ui-monospace</string></test>
$ fc-cache -f
$ fc-match 'ui-monospace'
Carlito-Regular.ttf: "Carlito" "Regular"
$ fc-match sans-serif
Carlito-Regular.ttf: "Carlito" "Regular"
So that doesn't work. Here's the curious part: it works when I use a space instead of a hyphen:
$ sed -i 's/ui-monospace/ui monospace/' ~/.config/fontconfig/fonts.conf
$ grep ui.monospace ~/.config/fontconfig/fonts.conf
<test name="family"><string>ui monospace</string></test>
$ fc-cache -f
$ fc-match 'ui monospace'
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"
So it appears the issue is the hyphen. I don't see any documentation (or bug reports) suggesting this issue; the fontconfig docs for <string>
make no such note of illegal characters or how to escape them. I've tried defining it as <string>ui\-monospace</string>
and <string>ui-monospace</string>
(and -
) but none of those worked.
How do I configure fontconfig to map a font name with a hyphen?