1

I've set the font-family and font-size in a few different ways before, one of which was:

(custom-set-faces
 '(default ((t (:family "Liberation Mono" :height 150)))))

However, I learned that if you set it that way, future frames will not be able to use the values and they need something like:

(add-to-list 'default-frame-alist
             '(font . "Liberation Mono"))

But because I add set it from a variable, I do it like:

(add-to-list 'default-frame-alist
             `(font . ,custom-variable-font-family))

I'm not able to find a way to set the font-height using this method. I did try to set height, but it ended up setting the height of the Emacs frame, just like it's mentioned in one of the documentation pages here.

I also tried a few other keywords apart for font (some from the documentation and some from my own wild guesses), just like you can set the background-color, etc. But I haven't been able to do that. I wonder if it's even possible (I know it should be) to set the font-height across frames that way.

1

M-x customize-face default, then set the height attribute to the value you want.


There are several other approaches. Here's one involving default-frame-alist:

Use M-x customize-option default-frame-alist, providing a full font name for the value of frame-parameter font. For example: this value uses a font height of 16 pixels:

"-*-Lucida Console-normal-r-*-*-16-*-*-*-c-*-iso8859-1"

That's an XLFD font name, the traditional method for specifying fonts under X Window. See (emacs) Fonts for a detailed description. In this case, the 16 is the PIXELS entry. That same Emacs-manual node also describes other ways to specify a font name.

Customize is your friend. If you don't want to use it then just do what you were doing, but use a full (e.g., XLFD) font name, which specifies the font size.

  • I've never used customized but only performed customization through scripts, which is something I prefer as it does exactly what I want, is very portable, and I get to learn a thing or two every time I change something. I'll definitely try the XLDF font name though. – myTerminal Nov 13 at 19:20
  • 1
    Customize takes of any :set etc. automatic code that might need to take place when a given option is set. Just using setq does not do that. And it helps you avoid setting an invalid value, and tells you when a value is invalid. Define a separate custom-file, load it in your init file, and using Customize will no longer write to your init file (it will use custom-file). – Drew Nov 13 at 19:40
  • I already have my weird/unusual/super-complicated setup that specifies a custom-file here I did that to prevent Emacs from writing autogenerated code to my init.el file, but never used customize myself. Your suggestion makes sense though. – myTerminal Nov 13 at 19:52
  • I just tried it today with an XLFD font name and it does work as expected. One of the differences is that now I'm using size in pixels instead of (1/10pts) size. – myTerminal Nov 15 at 0:22
  • 1
    Yes, that is a difference. You can also try the other things described in that same Emacs-manual node (Fonts). – Drew Nov 15 at 0:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.