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.
This commit is contained in:
TEC 2023-03-04 01:02:55 +08:00
parent febabadb99
commit 0d28e6ef72
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 14 additions and 0 deletions

View File

@ -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))))