I would like to configure the default Emacs font in my init.el (as opposed to using M-x customize that a lot of other questions here on Emacs Stack Exchange has already explained).
I have tried the following;
(when (eq system-type 'gnu/linux)
(set-default-font "-unknown-Hack-normal-normal-normal-*-14-*-*-*-m-0-iso10646-1"))
This works, the result is what I want, the font size is correct. If I place point on a char and do C-u C-x = I get the following;
position: 171 of 841 (20%), column: 0
character: R (displayed as R) (codepoint 82, #o122, #x52)
preferred charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x52
script: latin
syntax: w which means: word
category: .:Base, L:Left-to-right (strong), a:ASCII, l:Latin, r:Roman
to input: type "C-x 8 RET 52" or "C-x 8 RET LATIN CAPITAL LETTER R"
buffer code: #x52
file code: #x52 (encoded by coding system utf-8-unix)
display: by this font (glyph code)
xft:-unknown-Hack-normal-normal-normal-*-14-*-*-*-m-0-iso10646-1 (#x4E)
But I have a feeling this is a somewhat temporary way of doing this.
Another way I tried was;
(when (eq system-type 'gnu/linux)
(add-to-list 'default-frame-alist '(font . "Hack-10")))
This works so far as to set the font but the font size is just a bit to small;
position: 15130 of 22797 (66%), column: 4
character: d (displayed as d) (codepoint 100, #o144, #x64)
preferred charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x64
script: latin
syntax: w which means: word
category: .:Base, L:Left-to-right (strong), a:ASCII, l:Latin, r:Roman
to input: type "C-x 8 RET 64" or "C-x 8 RET LATIN SMALL LETTER D"
buffer code: #x64
file code: #x64 (encoded by coding system prefer-utf-8-unix)
display: by this font (glyph code)
xft:-unknown-Hack-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1 (#x87)
Now the font size is said to be 13 instead of 14 which is what I want. The numbers used when setting the default font using set-default-font
and using default-frame-alist
seems to have different meaning, that is the "14" and the "10".
Can I use default-frame-alist
to set my default font to Hack with size 14 or is there a better way of doing this in the init file?