Andreas Matthias <[email protected]> writes:

> I noticed that it is necessary to run (font-latex-update-sectioning-faces)
> if I load a theme like doom-themes.
>
> Currently I'm updating the faces in LaTeX-mode-hook which works fine.
> But it seems unnecessary to update the faces each time I load a .tex file.
> Is there a better (recommended) place where to run
> (font-latex-update-sectioning-faces)?
>
> Here is a file "start.el". Run it with "emacs -Q -l start.el":
>
> (package-initialize)
> (use-package doom-themes
>   :config (load-theme 'doom-nova t))
> (use-package auctex
>   :custom (font-latex-fontify-sectioning 2.0)
>   ;; :hook (LaTeX-mode . (lambda () (font-latex-update-sectioning-faces)))
>   )

Actually, I wonder if this is a bug in AUCTeX.  In theory, you shouldn't
need to run `font-latex-update-sectioning-faces' at all with the setup
above.  Can you apply the attached change to font-latex.el, restart
Emacs and see if it works?

@Tassilo: I wonder why the user option `font-latex-fontify-sectioning'
uses this:

 :initialize #'custom-initialize-default

I.e., why using `set-default-toplevel-value'?  I'd say
`custom-initialize-reset' (which is the default :initialize function)
fits better, or am I missing something?

Best, Arash
diff --git a/font-latex.el b/font-latex.el
index 7873a4a5..b4aaab4e 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -153,48 +153,7 @@ correct value from document properties."
   "Face for sectioning commands at level 5."
   :group 'font-latex-highlighting-faces)
 
-(defcustom font-latex-fontify-sectioning 1.1
-  "Whether to fontify sectioning macros with varying height or a color face.
-
-If it is a number, use varying height faces.  The number is used
-for scaling starting from `font-latex-sectioning-5-face'.  Typically
-values from 1.05 to 1.3 give best results, depending on your font
-setup.  If it is the symbol `color', use `font-lock-type-face'.
-
-Caveats: Customizing the scaling factor applies to all sectioning
-faces unless those face have been saved by customize.  Setting
-this variable directly does not take effect unless you call
-`font-latex-update-sectioning-faces' or restart Emacs.
-
-Switching from `color' to a number or vice versa does not take
-effect unless you call \\[font-lock-fontify-buffer] or restart
-Emacs."
-  :type '(choice (number :tag "Scale factor")
-                 (const color))
-  :initialize #'custom-initialize-default
-  :set (lambda (symbol value)
-         (set-default symbol value)
-         (unless (eq value 'color)
-           (font-latex-update-sectioning-faces font-latex-sectioning-max value)))
-  :group 'font-latex)
-
-(defun font-latex-update-sectioning-faces (&optional max height-scale)
-  "Update sectioning commands faces."
-  (unless height-scale
-    (setq height-scale (if (numberp font-latex-fontify-sectioning)
-                           ;; Make sure `height-scale' is a floating point
-                           ;; number because `set-face-attribute' treats
-                           ;; integers differently from floating points.
-                           (float font-latex-fontify-sectioning)
-                         1.1)))
-  (unless max
-    (setq max font-latex-sectioning-max))
-  (dotimes (num max)
-    (let* (;; reverse for XEmacs:
-           (num (- max (1+ num)))
-           (face-name (intern (format "font-latex-sectioning-%s-face" num))))
-      (unless (get face-name 'saved-face) ; Do not touch customized faces.
-        (set-face-attribute face-name nil :height  height-scale)))))
+(defvar font-latex-fontify-sectioning)
 
 (defun font-latex-make-sectioning-faces (max &optional height-scale)
   "Build the faces used to fontify sectioning commands."
@@ -223,6 +182,48 @@ variable `font-latex-fontify-sectioning'." ',num)
 
 (font-latex-make-sectioning-faces font-latex-sectioning-max)
 
+(defun font-latex-update-sectioning-faces (&optional max height-scale)
+  "Update sectioning commands faces."
+  (unless height-scale
+    (setq height-scale (if (numberp font-latex-fontify-sectioning)
+                           ;; Make sure `height-scale' is a floating point
+                           ;; number because `set-face-attribute' treats
+                           ;; integers differently from floating points.
+                           (float font-latex-fontify-sectioning)
+                         1.1)))
+  (unless max
+    (setq max font-latex-sectioning-max))
+  (dotimes (num max)
+    (let* (;; reverse for XEmacs:
+           (num (- max (1+ num)))
+           (face-name (intern (format "font-latex-sectioning-%s-face" num))))
+      (unless (get face-name 'saved-face) ; Do not touch customized faces.
+        (set-face-attribute face-name nil :height  height-scale)))))
+
+(defcustom font-latex-fontify-sectioning 1.1
+  "Whether to fontify sectioning macros with varying height or a color face.
+
+If it is a number, use varying height faces.  The number is used
+for scaling starting from `font-latex-sectioning-5-face'.  Typically
+values from 1.05 to 1.3 give best results, depending on your font
+setup.  If it is the symbol `color', use `font-lock-type-face'.
+
+Caveats: Customizing the scaling factor applies to all sectioning
+faces unless those face have been saved by customize.  Setting
+this variable directly does not take effect unless you call
+`font-latex-update-sectioning-faces' or restart Emacs.
+
+Switching from `color' to a number or vice versa does not take
+effect unless you call \\[font-lock-fontify-buffer] or restart
+Emacs."
+  :type '(choice (number :tag "Scale factor")
+                 (const color))
+  ;; :initialize #'custom-initialize-default
+  :set (lambda (symbol value)
+         (set-default symbol value)
+         (unless (eq value 'color)
+           (font-latex-update-sectioning-faces font-latex-sectioning-max value)))
+  :group 'font-latex)
 
 ;;; Keywords
 

Reply via email to