Function: org-odt-format-label

org-odt-format-label is a byte-compiled function defined in ox-odt.el.gz.

Signature

(org-odt-format-label ELEMENT INFO OP)

Documentation

Return a label for ELEMENT.

ELEMENT is a link, table, src-block or paragraph type element. INFO is a plist used as a communication channel. OP is either definition or reference, depending on the purpose of the generated string.

Return value is a string if OP is set to reference or a cons cell like CAPTION . SHORT-CAPTION) where CAPTION and SHORT-CAPTION are strings.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-odt.el.gz
(defun org-odt-format-label (element info op)
  "Return a label for ELEMENT.

ELEMENT is a `link', `table', `src-block' or `paragraph' type
element.  INFO is a plist used as a communication channel.  OP is
either `definition' or `reference', depending on the purpose of
the generated string.

Return value is a string if OP is set to `reference' or a cons
cell like CAPTION . SHORT-CAPTION) where CAPTION and
SHORT-CAPTION are strings."
  (cl-assert (org-element-type-p element '(link table src-block paragraph)))
  (let* ((element-or-parent
	  (cl-case (org-element-type element)
	    (link (org-element-parent-element element))
	    (t element)))
	 ;; Get label and caption.
	 (label (and (or (org-element-property :name element)
			 (org-element-property :name element-or-parent))
		     (org-export-get-reference element-or-parent info)))
	 (caption (let ((c (org-export-get-caption element-or-parent)))
		    (and c (org-export-data c info))))
	 ;; FIXME: We don't use short-caption for now
	 ;; (short-caption nil)
	 )
    (when (or label caption)
      (let* ((default-category
	       (cl-case (org-element-type element)
		 (table "__Table__")
		 (src-block "__Listing__")
		 ((link paragraph)
		  (cond
		   ((org-odt--enumerable-latex-image-p element info)
		    "__DvipngImage__")
		   ((org-odt--enumerable-image-p element info)
		    "__Figure__")
		   ((org-odt--enumerable-formula-p element info)
		    "__MathFormula__")
		   (t (error "Don't know how to format label for link: %S"
			     element))))
		 (t (error "Don't know how to format label for element type: %s"
			   (org-element-type element)))))
	     seqno)
	(cl-assert default-category)
	(pcase-let
	    ((`(,counter ,label-style ,category ,predicate)
	      (assoc-default default-category org-odt-category-map-alist)))
	  ;; Compute sequence number of the element.
	  (setq seqno (org-odt--enumerate element info predicate))
	  ;; Localize category string.
	  (setq category (org-export-translate category :utf-8 info))
	  (cl-case op
	    ;; Case 1: Handle Label definition.
	    (definition
	      (cons
	       (concat
		;; Sneak in a bookmark.  The bookmark is used when the
		;; labeled element is referenced with a link that
		;; provides its own description.
		(format "\n<text:bookmark text:name=\"%s\"/>" label)
		;; Label definition: Typically formatted as below:
		;;     CATEGORY SEQ-NO: LONG CAPTION
		;; with translation for correct punctuation.
		(format-spec
		 (org-export-translate
		  (cadr (assoc-string label-style org-odt-label-styles t))
		  :utf-8 info)
		 `((?e . ,category)
		   (?n . ,(format
			   "<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">%s</text:sequence>"
			   label counter counter seqno))
		   (?c . ,(or caption "")))))
	       nil)) ;; short-caption
	    ;; Case 2: Handle Label reference.
	    (reference
	     (let* ((fmt (cddr (assoc-string label-style org-odt-label-styles t)))
		    (fmt1 (car fmt))
		    (fmt2 (cadr fmt)))
	       (format "<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">%s</text:sequence-ref>"
		       fmt1
		       label
		       (format-spec fmt2 `((?e . ,category) (?n . ,seqno))))))
	    (t (error "Unknown %S on label" op))))))))