ox-latex: Support caption for latex-environment
* lisp/ox-latex.el (org-latex--environment-type): New function determining type of a latex-environment. (org-latex-latex-environment): Add support for caption. (org-latex--caption/label-string): Use correct type for non-floating latex-environments. * etc/ORG-NEWS: Add entry.
This commit is contained in:
parent
8a7fe3c219
commit
9faf000e6a
|
@ -183,7 +183,7 @@ user to specify the name of the output file upon exporting the
|
||||||
document. This also has an effect on publishing.
|
document. This also has an effect on publishing.
|
||||||
**** Horizontal rules are no longer ignored in LaTeX table math mode
|
**** Horizontal rules are no longer ignored in LaTeX table math mode
|
||||||
**** Use ~compilation-mode~ for compilation output
|
**** Use ~compilation-mode~ for compilation output
|
||||||
|
**** ~latex-environment~ elements support ~caption~ keywords for LaTeX export
|
||||||
*** ~org-edit-special~ can edit LaTeX environments
|
*** ~org-edit-special~ can edit LaTeX environments
|
||||||
|
|
||||||
Using ~C-c '~ on a LaTeX environment opens a sub-editing buffer. By
|
Using ~C-c '~ on a LaTeX environment opens a sub-editing buffer. By
|
||||||
|
|
|
@ -1312,14 +1312,19 @@ For non-floats, see `org-latex--wrap-label'."
|
||||||
(t
|
(t
|
||||||
(format (if nonfloat "\\captionof{%s}%s{%s%s}\n"
|
(format (if nonfloat "\\captionof{%s}%s{%s%s}\n"
|
||||||
"\\caption%s%s{%s%s}\n")
|
"\\caption%s%s{%s%s}\n")
|
||||||
|
(let ((type* (if (eq type 'latex-environment)
|
||||||
|
(org-latex--environment-type element)
|
||||||
|
type)))
|
||||||
(if nonfloat
|
(if nonfloat
|
||||||
(cl-case type
|
(cl-case type*
|
||||||
(paragraph "figure")
|
(paragraph "figure")
|
||||||
|
(image "figure")
|
||||||
|
(special-block "figure")
|
||||||
(src-block (if (plist-get info :latex-listings)
|
(src-block (if (plist-get info :latex-listings)
|
||||||
"listing"
|
"listing"
|
||||||
"figure"))
|
"figure"))
|
||||||
(t (symbol-name type)))
|
(t (symbol-name type*)))
|
||||||
"")
|
""))
|
||||||
(if short (format "[%s]" (org-export-data short info)) "")
|
(if short (format "[%s]" (org-export-data short info)) "")
|
||||||
label
|
label
|
||||||
(org-export-data main info))))))
|
(org-export-data main info))))))
|
||||||
|
@ -2250,24 +2255,62 @@ CONTENTS is nil. INFO is a plist holding contextual information."
|
||||||
|
|
||||||
;;;; Latex Environment
|
;;;; Latex Environment
|
||||||
|
|
||||||
|
(defun org-latex--environment-type (latex-environment)
|
||||||
|
"Return the TYPE of LATEX-ENVIRONMENT.
|
||||||
|
|
||||||
|
The TYPE is determined from the actual latex environment, and
|
||||||
|
could be a member of `org-latex-caption-above' or `math'."
|
||||||
|
(let* ((latex-begin-re "\\\\begin{\\([A-Za-z0-9*]+\\)}")
|
||||||
|
(value (org-remove-indentation
|
||||||
|
(org-element-property :value latex-environment)))
|
||||||
|
(env (or (and (string-match latex-begin-re value)
|
||||||
|
(match-string 1 value))
|
||||||
|
"")))
|
||||||
|
(cond
|
||||||
|
((string-match-p org-latex-math-environments-re value) 'math)
|
||||||
|
((string-match-p
|
||||||
|
(eval-when-compile
|
||||||
|
(regexp-opt '("table" "longtable" "tabular" "tabu" "longtabu")))
|
||||||
|
env)
|
||||||
|
'table)
|
||||||
|
((string-match-p "figure" env) 'image)
|
||||||
|
((string-match-p
|
||||||
|
(eval-when-compile
|
||||||
|
(regexp-opt '("lstlisting" "listing" "verbatim" "minted")))
|
||||||
|
env)
|
||||||
|
'src-block)
|
||||||
|
(t 'special-block))))
|
||||||
|
|
||||||
(defun org-latex-latex-environment (latex-environment _contents info)
|
(defun org-latex-latex-environment (latex-environment _contents info)
|
||||||
"Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
|
"Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
|
||||||
CONTENTS is nil. INFO is a plist holding contextual information."
|
CONTENTS is nil. INFO is a plist holding contextual information."
|
||||||
(when (plist-get info :with-latex)
|
(when (plist-get info :with-latex)
|
||||||
(let ((value (org-remove-indentation
|
(let* ((value (org-remove-indentation
|
||||||
(org-element-property :value latex-environment))))
|
(org-element-property :value latex-environment)))
|
||||||
(if (not (org-element-property :name latex-environment)) value
|
(type (org-latex--environment-type latex-environment))
|
||||||
|
(caption (if (eq type 'math)
|
||||||
|
(org-latex--label latex-environment info nil t)
|
||||||
|
(org-latex--caption/label-string latex-environment info)))
|
||||||
|
(caption-above-p
|
||||||
|
(memq type (append (plist-get info :latex-caption-above) '(math)))))
|
||||||
|
(if (not (or (org-element-property :name latex-environment)
|
||||||
|
(org-element-property :caption latex-environment)))
|
||||||
|
value
|
||||||
;; Environment is labeled: label must be within the environment
|
;; Environment is labeled: label must be within the environment
|
||||||
;; (otherwise, a reference pointing to that element will count
|
;; (otherwise, a reference pointing to that element will count
|
||||||
;; the section instead).
|
;; the section instead). Also insert caption if `latex-environment'
|
||||||
|
;; is not a math environment.
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert value)
|
(insert value)
|
||||||
|
(if caption-above-p
|
||||||
|
(progn
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(forward-line)
|
(forward-line))
|
||||||
(insert (org-latex--label latex-environment info nil t))
|
(goto-char (point-max))
|
||||||
|
(forward-line -1))
|
||||||
|
(insert caption)
|
||||||
(buffer-string))))))
|
(buffer-string))))))
|
||||||
|
|
||||||
|
|
||||||
;;;; Latex Fragment
|
;;;; Latex Fragment
|
||||||
|
|
||||||
(defun org-latex-latex-fragment (latex-fragment _contents _info)
|
(defun org-latex-latex-fragment (latex-fragment _contents _info)
|
||||||
|
|
Loading…
Reference in New Issue