org-latex-preview: Avoid duplicate latex fragments

* lisp/org-latex-preview.el (org-latex-preview-collect-fragments): This
function was collecting duplicate org-elements when handling nested
latex environments (For instance, a matrix env inside an equation env).
Fix by comparing the current element with the previously collected one.
This commit is contained in:
Karthik Chikmagalur 2023-01-01 16:42:18 -08:00 committed by TEC
parent a1f2f6806d
commit f02c40835b
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 6 additions and 2 deletions

View File

@ -669,8 +669,12 @@ fragments in the buffer."
(goto-char (or beg (point-min)))
(while (re-search-forward org-latex-preview--tentative-math-re end t)
(let ((obj (org-element-context)))
(when (memq (org-element-type obj)
'(latex-fragment latex-environment))
(when (and (memq (org-element-type obj)
'(latex-fragment latex-environment))
;; Avoid duplicating nested latex environments
(not (and fragments
(= (org-element-property :begin obj)
(org-element-property :begin (car fragments))))))
(push obj fragments)))))
(nreverse fragments)))