2

Is there a simple way to set the font used when viewing an .org file, so that it applies to that file every time you open it? I'm imagining something with the properties, like the imagined example below.

I'm sure there is a way to do this with Emacs Lisp, adding to org-mode-hook and programmatically setting the face text property or something like that. But before I do that, I wanted to check if there was a simple way, without writing Lisp code.

I understand that typical users of Emacs do not care about this kind of thing. Like most people, I use it primarily as a code editor, but sometimes I care what my text looks like on screen and want to play with different fonts.

#+FONT Helvetica Neue, 14pt

* Uno
* Dos
* Tres
6
  • Do you want to affect only a particular file or all *.org files, that is, all files opened in Org mode? Guessing the latter, I edited the question slightly. If I'm wrong, feel free to edit it again or roll back my edit.
    – Drew
    Feb 7, 2023 at 23:00
  • I want to set it just for a particular file. I'd like to have different .org files with different fonts, just like I can do with a standard word processor application. I'm not sure what a "buffer-mode" property is, so I'm not sure if your edit fits my meaning or not. It sounds like it does. (?) I get sick of staring at the same font. Sometimes I like to pick a new font because I like the way it looks, and it helps me think. But I do this on a per-file basis; it depends on the content.
    – Rob N
    Feb 7, 2023 at 23:03
  • "... just like I can do with a standard word processor application..." - Emacs is not a word processor and certainly not a "standard" one, so if you insist on treating it like one, you are going to be disappointed. In particular, there is no #+FONT: facility in Org mode and it is extremely unlikely that something like it will ever be implemented.
    – NickD
    Feb 8, 2023 at 1:59
  • OK, sorry for my edit then. Please roll it back or edit it further, to express what you meant. I made a (wrong) guess that you wanted to do the same for all *.org files.
    – Drew
    Feb 8, 2023 at 3:11
  • Yes, I use Emacs all day, for everything from C++ to Emacs Lisp to org mode. I know it's a unique and awesome system, not a word processor. I said that just to describe what I want to do. If there is no 'easy' feature, I'm sure there is a way to write something in lisp and add it to org-mode-hook.
    – Rob N
    Feb 8, 2023 at 3:15

1 Answer 1

2

Buffer local faces (including the font family) can be set using the function face-remap-add-relative, which sets the variable face-remapping-alist. org-mode files can have file-local settings such as placing a snippet like this at the top of the file:

# -*- eval: (face-remap-add-relative 'default '(:family "Courier" :height 160 :background "yellow")); -*-

OR

# -*- eval: (face-remap-add-relative 'default '(:family "Monospace" :height 160 :background "yellow")); -*-

NOTE: Emacs expects :family, not :font, in this particular example.

See the manual for other file-local settings: https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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