emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Add :caption attribute to #+ATTR_LATEX property
@ 2013-06-29 15:17 feng shu
  0 siblings, 0 replies; only message in thread
From: feng shu @ 2013-06-29 15:17 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 211 bytes --]

This feature is very useful when you export org to latex with custom
caption command, for example:

#+ATTR_LATEX: :caption \BiTableCaption{caption 1}{caption 2}
|---+---|
| x | y |
|---+---|
| 1 | 2 |
|---+---|

[-- Attachment #1.2: Type: text/html, Size: 269 bytes --]

[-- Attachment #2: 0001-Add-caption-attribute-to-ATTR_LATEX-property.patch --]
[-- Type: application/octet-stream, Size: 2563 bytes --]

From ab718ca89c41318ab449d47802c2b2f7ecbca597 Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@gmail.com>
Date: Sat, 29 Jun 2013 23:04:03 +0800
Subject: [PATCH] Add `:caption' attribute to #+ATTR_LATEX property

* lisp/ox-latex.el (org-latex--caption/label-string): Add ability,
  which can build a caption string from `:caption' attribute of #+ATTR_LATEX.
(org-latex--inline-image): Tiny change.
(org-latex--org-table): Tiny change.

This feature is very useful when you export org to latex with custom
caption command, for example:

\#+ATTR_LATEX: :caption \BiTableCaption{caption 1}{caption 2}
|---+---|
| x | y |
|---+---|
| 1 | 2 |
|---+---|
---
 lisp/ox-latex.el |   11 ++++++-----
 1 个文件被修改,插入 6 行(+),删除 5 行(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 09928a4..830fdf7 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -881,10 +881,11 @@ For non-floats, see `org-latex--wrap-label'."
 		      (format "\\label{%s}"
 			      (org-export-solidify-link-text label))))
 	 (main (org-export-get-caption element))
-	 (short (org-export-get-caption element t)))
+	 (short (org-export-get-caption element t))
+	 (caption-from-latex-attr (plist-get (org-export-read-attribute :attr_latex element) :caption)))
     (cond
-     ((and (not main) (equal label-str "")) "")
-     ((not main) (concat label-str "\n"))
+     ((and (not main) (equal label-str "")) (concat caption-from-latex-attr "\n"))
+     ((not main) (concat caption-from-latex-attr "\n" label-str "\n"))
      ;; Option caption format with short name.
      (short (format "\\caption[%s]{%s%s}\n"
 		    (org-export-data short info)
@@ -1655,7 +1656,7 @@ used as a communication channel."
 		  (cond ((and (not float) (plist-member attr :float)) nil)
 			((string= float "wrap") 'wrap)
 			((string= float "multicolumn") 'multicolumn)
-			((or float (org-element-property :caption parent))
+			((or float (org-element-property :caption parent) (plist-get attr :caption))
 			 'figure))))
 	 (placement
 	  (let ((place (plist-get attr :placement)))
@@ -2333,7 +2334,7 @@ This function assumes TABLE has `org' as its `:type' property and
 			 ((and (not float) (plist-member attr :float)) nil)
 			 ((string= float "sidewaystable") "sidewaystable")
 			 ((string= float "multicolumn") "table*")
-			 ((or float (org-element-property :caption table))
+			 ((or float (org-element-property :caption table) (plist-get attr :caption))
 			  "table")))))
 	 ;; Extract others display options.
 	 (fontsize (let ((font (plist-get attr :font)))
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-06-29 15:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-29 15:17 [PATCH] Add :caption attribute to #+ATTR_LATEX property feng shu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).