Browse Source

ox-latex: Fix f1548e11fe2972819bc48b88c6094b11150e5c8a

* lisp/ox-latex.el (org-latex-prefer-user-labels): Fix docstring.
(org-latex--label): Fix docstring.  Do not add a spurious newline
character when generating "\\label" macro for a target.
(org-latex-link):
(org-latex-radio-target): Radio targets always use internal labelling
scheme.

Radio targets are visible in the document so they can contain
forbidden characters, and user cannot adapt them to naming
restrictions from a given back-end.
Nicolas Goaziou 10 years ago
parent
commit
88108f652f
1 changed files with 18 additions and 15 deletions
  1. 18 15
      lisp/ox-latex.el

+ 18 - 15
lisp/ox-latex.el

@@ -241,8 +241,8 @@ symbols are: `image', `table', `src-block' and `special-block'."
    "Use user-provided labels instead of internal ones when non-nil.
    "Use user-provided labels instead of internal ones when non-nil.
 
 
 When this variable is non-nil, Org will use the value of
 When this variable is non-nil, Org will use the value of
-a headline's CUSTOM_ID property and NAME values as the key for
-the \\label commands generated.
+CUSTOM_ID property, NAME keyword or Org target as the key for the
+\\label commands generated.
 
 
 By default, Org generates its own internal labels during LaTeX
 By default, Org generates its own internal labels during LaTeX
 export.  This process ensures that the \\label keys are unique
 export.  This process ensures that the \\label keys are unique
@@ -1045,29 +1045,32 @@ INFO is a plist holding contextual information."
       (let ((type (org-element-type element)))
       (let ((type (org-element-type element)))
 	(memq (if (eq type 'link) 'image type) above)))))
 	(memq (if (eq type 'link) 'image type) above)))))
 
 
-(defun org-latex--label (element info &optional force full)
-  "Return an appropriate label for ELEMENT.
-INFO is the current export state, as a plist.
+(defun org-latex--label (datum info &optional force full)
+  "Return an appropriate label for DATUM.
+DATUM is an element or a `target' type object.  INFO is the
+current export state, as a plist.
 
 
-Return nil if ELEMENT has no NAME or VALUE affiliated keyword or
-no CUSTOM_ID property, unless FORCE is non-nil.  In this case
-always return a unique label.
+Return nil if element DATUM has no NAME or VALUE affiliated
+keyword or no CUSTOM_ID property, unless FORCE is non-nil.  In
+this case always return a unique label.
 
 
 Eventually, if FULL is non-nil, wrap label within \"\\label{}\"."
 Eventually, if FULL is non-nil, wrap label within \"\\label{}\"."
-  (let* ((user-label
+  (let* ((type (org-element-type datum))
+	 (user-label
 	  (org-element-property
 	  (org-element-property
-	   (case (org-element-type element)
+	   (case type
 	     ((headline inlinetask) :CUSTOM_ID)
 	     ((headline inlinetask) :CUSTOM_ID)
 	     (target :value)
 	     (target :value)
 	     (otherwise :name))
 	     (otherwise :name))
-	   element))
+	   datum))
 	 (label
 	 (label
 	  (and (or user-label force)
 	  (and (or user-label force)
 	       (if (and user-label (plist-get info :latex-prefer-user-labels))
 	       (if (and user-label (plist-get info :latex-prefer-user-labels))
 		   user-label
 		   user-label
-		 (org-export-get-reference element info)))))
+		 (org-export-get-reference datum info)))))
     (cond ((not full) label)
     (cond ((not full) label)
-	  (label (format "\\label{%s}\n" label))
+	  (label (concat (format "\\label{%s}" label)
+			 (and (not (eq type 'target)) "\n")))
 	  (t ""))))
 	  (t ""))))
 
 
 (defun org-latex--caption/label-string (element info)
 (defun org-latex--caption/label-string (element info)
@@ -2089,7 +2092,7 @@ INFO is a plist holding contextual information.  See
       (let ((destination (org-export-resolve-radio-link link info)))
       (let ((destination (org-export-resolve-radio-link link info)))
 	(if (not destination) desc
 	(if (not destination) desc
 	  (format "\\hyperref[%s]{%s}"
 	  (format "\\hyperref[%s]{%s}"
-		  (org-latex--label destination info)
+		  (org-export-get-reference destination info)
 		  desc))))
 		  desc))))
      ;; Links pointing to a headline: Find destination and build
      ;; Links pointing to a headline: Find destination and build
      ;; appropriate referencing command.
      ;; appropriate referencing command.
@@ -2417,7 +2420,7 @@ holding contextual information."
   "Transcode a RADIO-TARGET object from Org to LaTeX.
   "Transcode a RADIO-TARGET object from Org to LaTeX.
 TEXT is the text of the target.  INFO is a plist holding
 TEXT is the text of the target.  INFO is a plist holding
 contextual information."
 contextual information."
-  (format "\\label{%s}%s" (org-latex--label radio-target info) text))
+  (format "\\label{%s}%s" (org-export-get-reference radio-target info) text))
 
 
 
 
 ;;;; Section
 ;;;; Section