org-latex-preview: Fix element start positions

* lisp/org-latex-preview.el (org-latex-preview--place-from-elements,
org-latex-preview-auto--maybe-track-element-here): The org-element
property `:begin' includes any Org keyword text associated with the
element, such as "#+RESULTS:" or "#+ATTR_LATEX:" and these are swallowed
up in the created preview overlays.  Fix by using the `:post-affiliated'
property over `:begin' when it is available.  Note that some
calculations, such as equation numbering, still use the `:begin'
keyword.  These calculations don't involve creating overlays and thus
this is not (expected to be) an issue.
This commit is contained in:
Karthik Chikmagalur 2023-01-29 19:20:36 -08:00 committed by TEC
parent 36d1b5d3b2
commit 716e32492b
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 6 additions and 3 deletions

View File

@ -668,7 +668,8 @@ If an org-latex-overlay is already present, nothing is done."
'org-latex-overlay))
(when-let* ((element (org-element-context))
((eq (org-element-type element) type))
(elem-beg (org-element-property :begin element))
(elem-beg (or (org-element-property :post-affiliated element)
(org-element-property :begin element)))
(elem-end (- (org-element-property :end element)
(or (org-element-property :post-blank element) 0)
(if (eq (char-before (org-element-property :end element))
@ -1044,7 +1045,8 @@ Some of the options can be changed using the variable
(entries
(mapcar
(lambda (element)
(list (org-element-property :begin element)
(list (or (org-element-property :post-affiliated element)
(org-element-property :begin element))
(- (org-element-property :end element)
(or (org-element-property :post-blank element) 0)
(if (eq (char-before (org-element-property :end element))
@ -1957,7 +1959,8 @@ the *entire* preview cache will be cleared, and `org-persist-gc' run."
(and org-latex-preview-numbered
(org-latex-preview--environment-numbering-table))))
(dolist (element (org-latex-preview-collect-fragments beg end))
(pcase-let* ((begin (org-element-property :begin element))
(pcase-let* ((begin (or (org-element-property :post-affiliated element)
(org-element-property :begin element)))
(`(,fg ,bg) (org-latex-preview--colors-at begin))
(value (org-element-property :value element))
(number (and numbering-table