5

Here's a minimal example that does something on Linux (Ubuntu 16.04) that doesn't seem right to me:

M-: (set-frame-font "Ubuntu") M-x describe-font <RET>

The first couple of lines that Emacs 25.1 (-Q) reports are:

name (opened by): -DAMA-Ubuntu-normal-normal-normal-*-16-*-*-*-*-0-iso10646-1
  full name: Ubuntu:pixelsize=16:foundry=DAMA:weight=normal:slant=normal:width=normal:scalable=true
  file name: /usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-M.ttf

It's the bottom line of this that's wrong (Ubuntu-M.ttf) - Emacs is selecting the "Medium" font weight variant, instead of the "Regular". Like many fonts, the Ubuntu font has weight variants beyond the well-known "Regular" and "Bold". Such additional weights can include "Light", "Book", "Demi-Bold", "Black", "Medium".

I would like to use the Ubuntu Regular font for variable-pitch-mode, but the Medium weight isn't suitable. I've tried various different Emacs ways of specifying a font, including "Ubuntu", "Ubuntu-11:weight=Regular", "-DAMA-Ubuntu-normal-normal-normal-*-15-*-*-*-*-0-iso10646-1".

All of these display text in emacs in the wrong, medium weight. Some apps allow selecting font weight by numbers (e.g. 200=Bold), but not, I believe, Emacs. Still, the system's font selection appears to be correct, and I don't understand why Emacs isn't using this

alex@Lucifer:~$ fc-match "Ubuntu"
Ubuntu-R.ttf: "Ubuntu" "Regular"
alex@Lucifer:~$ fc-list "Ubuntu" file family style weight
[correct output]

Can anyone confirm that this problem exists on Linux (it works fine on my Windows machine)? And, even better, can anyone point me to how to get Emacs to pick the correct weight of font?

  • Have you tried to set it like this "Ubuntu-11:weight=book"? That helped me with Roboto Mono. – contemplator May 19 '17 at 19:20
  • From the code in Emacs' font.c that looks more promising. It looks like Emacs turns the weight names into a number, but treats "regular", "medium" etc. all as 100, which is nearest the Ubuntu font's "medium" weight. "book" should be 75, but sadly this still ends up rendering in Medium. – Reign of Error May 22 '17 at 16:46
  • And I found out that even adjusting the font size with text-scale-adjust will break my workaround. Hope someone more knowledgeable than me can answer this question. – contemplator May 22 '17 at 19:20
  • For some fonts (and, sadly, for others not) it is possible to denote the internal font file name; eg. to use SourceCodePro-regular.ttf I can use :font "xft:SourceCodePro Regular:size=8". Maybe this works for your font, too. – user17303 Oct 24 '17 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.