From f4414f5dbbbe310ae2576e1f3706b2f43de19493 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Mon, 5 Feb 2024 13:29:05 +0100 Subject: [PATCH] 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 --- lisp/ox-latex.el | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 2b44679c7..e3edef3bd 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -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."