Hi, With the current org-do-latex-and-related function, fontification of a region before a LaTeX fragment repeatedly adds the 'org-latex-and-related face to the fragment.
You can reproduce with an org buffer with the following content. #+BEGIN_SRC org Foo $a^2 + b^2 = c^2$ #+END_SRC - Use (setq org-highlight-latex-and-related '(latex)) - Write some text at the end of the first line, triggering refonfication of the line - For each character inserted, the org-latex-and-related face is added (as a duplicate) to the fragment, as you can check using describe-text-properties. The attached patch fixes this. -- Sébastien Miquel
>From ccce24e08b903e0e955a6b22f6c7321851ec5750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= <sebastien.miq...@posteo.eu> Date: Fri, 19 Mar 2021 16:55:27 +0100 Subject: [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex faces * lisp/org.el (org-do-latex-and-related): Do not add a 'org-latex-and-related face beyond the fontification limit --- lisp/org.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/org.el b/lisp/org.el index 4db2dbe04..a0c703630 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5502,6 +5502,8 @@ highlighting was done, nil otherwise." (while (and (< (point) limit) (re-search-forward org-latex-and-related-regexp nil t)) (cond + ((>= (match-beginning 0) limit) + (throw 'found nil)) ((cl-some (lambda (f) (memq f '(org-code org-verbatim underline org-special-keyword))) -- 2.30.2