Function: LaTeX-keyval-caption-reftex-context-function

LaTeX-keyval-caption-reftex-context-function is a byte-compiled function defined in latex.el.

Signature

(LaTeX-keyval-caption-reftex-context-function ENV)

Documentation

Extract and return a key=val caption context string for RefTeX in ENV.

ENV is the name of current environment passed to this function by RefTeX. The context string is the value given to the caption key. If no caption key is found, an error is issued. See also the docstring of reftex-label-alist and its description for CONTEXT-METHOD.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-keyval-caption-reftex-context-function (env)
  "Extract and return a key=val caption context string for RefTeX in ENV.
ENV is the name of current environment passed to this function by
RefTeX.  The context string is the value given to the caption key.  If
no caption key is found, an error is issued.  See also the docstring of
`reftex-label-alist' and its description for CONTEXT-METHOD."
  (let* ((envstart (save-excursion
                     (re-search-backward (concat "\\\\begin{" env "}")
                                         nil t)))
         (capt-key (save-excursion
                     (re-search-backward "\\<caption[ \t\n\r%]*=[ \t\n\r%]*"
                                         envstart t)))
         capt-start capt-end)
    (if capt-key
        (save-excursion
          (goto-char (match-end 0))
          (cond ((looking-at-p (regexp-quote (concat TeX-grop LaTeX-optop)))
                 ;; Short caption inside [] is available, extract it only
                 (forward-char)
                 (setq capt-start (1+ (point)))
                 (setq capt-end (1- (progn (forward-sexp) (point)))))
                ;; Extract the entire caption which is enclosed in braces
                ((looking-at-p TeX-grop)
                 (setq capt-start (1+ (point)))
                 (setq capt-end (1- (progn (forward-sexp) (point)))))
                ;; Extract everything to next comma ,
                (t
                 (setq capt-start (point))
                 (setq capt-end (progn (skip-chars-forward "^,") (point)))))
          ;; Return the extracted string
          (buffer-substring-no-properties capt-start capt-end))
      (error "%s" "No caption found"))))