ox-latex: Fix references to src block results without #+name

* lisp/ox-latex.el (org-latex--label): Consider :results property in
addition to :name property of the datum.  For datums that are results
of evaluation, the label may not only come from #+name keyword, but
can also be duplicated from the generating src block.
(org-latex--wrap-label): Do not limit label to elements with #+name.
Rely on `org-latex--label' to return appropriate label (or nil).

Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/6d9db4be5d42236391d5c4e530250ee1@posteo.net
This commit is contained in:
Ihor Radchenko 2024-02-05 13:29:05 +01:00
parent 0938795fd7
commit f4414f5dbb
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 10 additions and 11 deletions

View File

@ -1552,12 +1552,11 @@ this case always return a unique label.
Eventually, if FULL is non-nil, wrap label within \"\\label{}\"."
(let* ((type (org-element-type datum))
(user-label
(org-element-property
(cl-case type
((headline inlinetask) :CUSTOM_ID)
(target :value)
(otherwise :name))
datum))
(cl-case type
((headline inlinetask) (org-element-property :CUSTOM_ID datum))
(target (org-element-property :value datum))
(otherwise (or (org-element-property :name datum)
(car (org-element-property :results datum))))))
(label
(and (or user-label force)
(if (and user-label (plist-get info :latex-prefer-user-labels))
@ -1818,11 +1817,11 @@ nil."
INFO is the current export state, as a plist. This function
should not be used for floats. See
`org-latex--caption/label-string'."
(if (not (and (org-string-nw-p output) (org-element-property :name element)))
output
(concat (format "\\phantomsection\n\\label{%s}\n"
(org-latex--label element info))
output)))
(let ((label (org-latex--label element info)))
(if (not (and (org-string-nw-p output) label))
output
(concat (format "\\phantomsection\n\\label{%s}\n" label)
output))))
(defun org-latex--protect-text (text)
"Protect special characters in string TEXT and return it."