0

When I try to put

 (set-face-attribute 'font-latex-italic-face nil :foreground green)
 (set-face-attribute 'font-latex-math-face nil :foreground orange)
 (set-face-attribute 'font-latex-script-char-face nil :foreground red)
 (set-face-attribute 'font-latex-string-face nil :foreground red)

into my init.el (green & are variables I have given values), I am told that 'font-latex-... are 'invalid faces'. this also happens if i try to evaluate the expressions before having opened a latex buffer. how am i suppsed to customize these faces in my init.el? (i don't want to use custom-set-faces.)

2

The standard method to do this sort of thing, given that the faces are defined in the font-latex library:

(with-eval-after-load 'font-latex
  (set-face-attribute 'font-latex-italic-face nil :foreground green)
  (set-face-attribute 'font-latex-math-face nil :foreground orange)
  (set-face-attribute 'font-latex-script-char-face nil :foreground red)
  (set-face-attribute 'font-latex-string-face nil :foreground red))

This way, you don't force the loading of font-latex before you need it. If the file has already been loaded, the commands will be run immediately; otherwise, they will be run after the file is loaded, as the name indicates. (Strictly speaking, they will be run after the loading of any file that runs (provide 'font-latex). But no other file should do that.)

  • Do you mean with-eval-after-load? Your example will not work as eval-after-load expects FORM as argument and needs a quoted '(progn ...) for multiple forms. – Arash Esbati Feb 3 at 19:20
  • @ArashEsbati Indeed, I was a bit quick there. Thanks; edited. Looking at my own init file, I see that I made my own equivalent of the with-eval-after-load macro once, probably before that macro made it into the emacs source. I use both my home brewed macro and the official one – time to go clean that up. – Harald Hanche-Olsen Feb 3 at 19:55
0

You have to load or autoload a symbol before you can customize it. The easiest way is to insert

(require 'font-latex)

before the set-face-attribute commands.

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.