From 0d28e6ef727ad408166c86c422b5ae8a02642d60 Mon Sep 17 00:00:00 2001 From: TEC Date: Sat, 4 Mar 2023 01:02:55 +0800 Subject: [PATCH] org: Update LaTeX overlay during fontification * lisp/org.el (org-do-latex-and-related, org-latex-preview-options): To ensure that LaTeX preview overlays update as the face changes (for instance, when in a heading that changes level), the face used is updated during fontification when applicable. This also ensures that the correct face is used when JIT fontification is active. --- lisp/org.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lisp/org.el b/lisp/org.el index f816bbfb0..09640f9e1 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5529,6 +5529,9 @@ Result depends on variable `org-highlight-latex-and-related'." (append re-latex re-entities re-sub) "\\|")))) +(defvar org-latex-preview-options) ; Defined in org-latex-preview.el. +(declare-function org-latex-preview--face-around "org-latex-preview" (start end)) + (defun org-do-latex-and-related (limit) "Highlight LaTeX snippets and environments, entities and sub/superscript. Stop at first highlighted object, if any. Return t if some @@ -5569,6 +5572,17 @@ highlighting was done, nil otherwise." 'face 'org-latex-and-related)) (add-text-properties (+ offset (match-beginning 0)) (match-end 0) '(font-lock-multiline t)) + ;; Refresh the face of LaTeX previews (when applicable). + (when (eq (plist-get org-latex-preview-options :foreground) + 'auto) + (dolist (ov (overlays-at start)) + (when (and (eq (overlay-get ov 'org-overlay-type) + 'org-latex-overlay) + (overlay-get ov 'face) + (not (eq (overlay-get ov 'face) 'error))) + (overlay-put ov 'face + (org-latex-preview--face-around + (overlay-start ov) (overlay-end ov)))))) (throw 'found t))))) nil))))