reddit / emacs

Color theme is changing the font heights

premsri · 2022-03-17 12:13
The color theme that I am currently using, appears to change the font heights for titles, headings etc. in some modes (ex: latex mode, info mode). How do I force these elements to have the same height as normal text? I found this piece of code somewhere on the internet, which works: (mapc (lambda (face) (set-face-attribute face nil :height 170)) (face-list)) However, placing this in my `.emacs` is not effective. I have to evaluate the above expression after starting emacs each time. Is there a way to do this automatically? Thanks in advance for the help!
corgito · 2022-03-17 15:50
Dealing with this exact same problem as an emacs noob. Have to reload my config each time I start emacs but it’s fine afterwards.
graduale · 2022-03-18 18:56
Presumably you want that code to run after the theme is set, otherwise the theme will override the relevant attributes. If you use eg `use-package` you can add the code in the `config` section of the declaration for your theme. If not you can use `with-eval-after-load`. (with-eval-after-load 'your-theme (mapc (lambda (face) (set-face-attribute face nil :height 170)) (face-list))) (Away from computer so haven’t really tested this.) Alternatively you can advice `load-theme` to run that code so that switching themes doesn’t require you to reset the height attribute again, using something like (defun my/set-face-height () "Set height properties for all faces to 170" (mapc (lambda (face) (set-face-attribute face nil :height 170)) (face-list))) (advice-add #'load-theme :after #'my/set-face-height)
premsri · 2022-03-20 11:30
Thank you! Your suggestions works, but not quite. When I place it within `use-package` or use `with-eval-after-load`, the font height is correctly set in some modes (like info-mode and org-mode), but not in latex-mode. The `advice-add` method does not work outright. This could possibly have something to do with latex-mode/auctex, or something else in my `.emacs`. Thanks for the help!
graduale · 2022-03-21 21:58
I suspect, though I'm no expert here, that some of the faces are being defined by packages that are loaded after you specify the height property for all faces. As a result, the mapping over `(face-list)` is not applying to those faces. Essentially, if you use `my/set-face-height` for example, that function will set the height property of any face that is listed in `(face-list)` *at the time the function is called*. If you then load a package that defines a new face and specifies a height property for it, the new face will have whatever height your theme specified for that face. Try e.g. adding (mapc (lambda (face) (set-face-attribute face nil :height 170)) (face-list)) to the `:config` section of your `use-package` declaration for `latex-mode`. A possible solution here would be to run the `my/set-face-height` function as a hook when enabling any mode, say with something like: (add-hook 'prog-mode-hook #'my/set-face-height) (add-hook 'text-mode-hook #'my/set-face-height) I haven't tested this, though. There may be a way of applying `set-face-attribute` to all faces that your theme is aware of (see e.g. the variable `modus-faces` defined in the `modus-*` themes), but I don't know whether there is a 'theme neutral' way of doing so. **EDIT**: Another, no more elegant option may be to use `after-change-major-mode-hook`. It all depends I guess on the order in which hooks are run and faces are added to `face-list`---[this](https://stackoverflow.com/questions/19280851/how-to-keep-dir-local-variables-when-switching-major-modes/19295380#19295380) may be relevant.