* [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property
@ 2013-06-29 23:10 feng shu
2013-06-30 11:46 ` Nicolas Goaziou
0 siblings, 1 reply; 9+ messages in thread
From: feng shu @ 2013-06-29 23:10 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 575 bytes --]
This is the updated patch of "Add :caption attribute to #+ATTR_LATEX
property"
If possible, please include it to master
------------------------------------------------------------------------------------------------------------------------
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: 696 bytes --]
[-- Attachment #2: 0001-Add-caption-attribute-to-ATTR_LATEX-property.patch --]
[-- Type: application/octet-stream, Size: 3238 bytes --]
From eb8b665ba1e2717c40b86048f3edb3495b9c628e 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 | 29 ++++++++++++++++-------------
1 个文件被修改,插入 16 行(+),删除 13 行(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 09928a4..36c2565 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -881,17 +881,20 @@ 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)))
- (cond
- ((and (not main) (equal label-str "")) "")
- ((not main) (concat label-str "\n"))
- ;; Option caption format with short name.
- (short (format "\\caption[%s]{%s%s}\n"
- (org-export-data short info)
- label-str
- (org-export-data main info)))
- ;; Standard caption format.
- (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
+ (short (org-export-get-caption element t))
+ (caption-from-attr-latex (plist-get (org-export-read-attribute :attr_latex element) :caption)))
+ (if (and caption-from-attr-latex (not (equal caption-from-attr-latex "")))
+ (concat caption-from-attr-latex "\n")
+ (cond
+ ((and (not main) (equal label-str "")))
+ ((not main) (concat label-str "\n"))
+ ;; Option caption format with short name.
+ (short (format "\\caption[%s]{%s%s}\n"
+ (org-export-data short info)
+ label-str
+ (org-export-data main info)))
+ ;; Standard caption format.
+ (t (format "\\caption{%s%s}\n" label-str (org-export-data main info)))))))
(defun org-latex-guess-inputenc (header)
"Set the coding system in inputenc to what the buffer is.
@@ -1655,7 +1658,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 +2336,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] 9+ messages in thread
* Re: [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property
2013-06-29 23:10 [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property feng shu
@ 2013-06-30 11:46 ` Nicolas Goaziou
2013-06-30 14:27 ` feng shu
0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2013-06-30 11:46 UTC (permalink / raw)
To: feng shu; +Cc: emacs-orgmode
Hello,
feng shu <tumashu@gmail.com> writes:
> This is the updated patch of "Add :caption attribute to #+ATTR_LATEX
> property"
> If possible, please include it to master
Thanks for your patch.
I agree that #+CAPTION isn't ready for complex caption commands (nor
that it should), so a :caption attribute may be useful. Though, it must
be documented in the manual (see "12.7.4 LaTeX specific attributes"). In
particular, documentation should insist on the fact that:
1. :caption attribute has precedence over #+caption keyword
2. :caption attribute is only meaningful special caption commands,
i.e., this isn't the standard way to set a caption in Org.
3. This is a raw command, nothing in it will be interpreted by Org.
Here are some comments about the code:
> + (caption-from-attr-latex (plist-get (org-export-read-attribute :attr_latex element) :caption)))
You can use the following slightly shorter sexp:
(caption-from-attr-latex (org-export-read-attribute :attr_latex element :caption))
> + (if (and caption-from-attr-latex (not (equal caption-from-attr-latex "")))
> + (concat caption-from-attr-latex "\n")
> + (cond
> + ((and (not main) (equal label-str "")))
> + ((not main) (concat label-str "\n"))
> + ;; Option caption format with short name.
> + (short (format "\\caption[%s]{%s%s}\n"
> + (org-export-data short info)
> + label-str
> + (org-export-data main info)))
> + ;; Standard caption format.
> + (t (format "\\caption{%s%s}\n" label-str (org-export-data main info)))))))
Here you can include the "then" part in the `cond', and use
`org-string-nw-p':
(cond ((org-string-nw-p caption-from-attr-latex)
(concat caption-from-attr-latex "\n"))
((and (not main) (equal label-str "")) "")
...)
> (defun org-latex-guess-inputenc (header)
> "Set the coding system in inputenc to what the buffer is.
> @@ -1655,7 +1658,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))
Be careful here: (plist-get attr :caption) will be non-nil if :caption
is set to the empty string. It may be bulkier to use:
(org-string-nw-p (plist-get attr :caption))
> 'figure))))
> (placement
> (let ((place (plist-get attr :placement)))
> @@ -2333,7 +2336,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))
Ditto.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property
2013-06-30 11:46 ` Nicolas Goaziou
@ 2013-06-30 14:27 ` feng shu
2013-06-30 20:27 ` Bastien
0 siblings, 1 reply; 9+ messages in thread
From: feng shu @ 2013-06-30 14:27 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 3503 bytes --]
Hi
version 3 patch, add document about :caption attribute.
On Sun, Jun 30, 2013 at 7:46 PM, Nicolas Goaziou <n.goaziou@gmail.com>wrote:
> Hello,
>
> feng shu <tumashu@gmail.com> writes:
>
> > This is the updated patch of "Add :caption attribute to #+ATTR_LATEX
> > property"
> > If possible, please include it to master
>
> Thanks for your patch.
>
> I agree that #+CAPTION isn't ready for complex caption commands (nor
> that it should), so a :caption attribute may be useful. Though, it must
> be documented in the manual (see "12.7.4 LaTeX specific attributes"). In
> particular, documentation should insist on the fact that:
>
> 1. :caption attribute has precedence over #+caption keyword
> 2. :caption attribute is only meaningful special caption commands,
> i.e., this isn't the standard way to set a caption in Org.
> 3. This is a raw command, nothing in it will be interpreted by Org.
>
> Here are some comments about the code:
> > + (caption-from-attr-latex (plist-get (org-export-read-attribute
> :attr_latex element) :caption)))
>
> You can use the following slightly shorter sexp:
>
> (caption-from-attr-latex (org-export-read-attribute :attr_latex element
> :caption))
>
> > + (if (and caption-from-attr-latex (not (equal
> caption-from-attr-latex "")))
> > + (concat caption-from-attr-latex "\n")
> > + (cond
> > + ((and (not main) (equal label-str "")))
> > + ((not main) (concat label-str "\n"))
> > + ;; Option caption format with short name.
> > + (short (format "\\caption[%s]{%s%s}\n"
> > + (org-export-data short info)
> > + label-str
> > + (org-export-data main info)))
> > + ;; Standard caption format.
> > + (t (format "\\caption{%s%s}\n" label-str (org-export-data main
> info)))))))
>
> Here you can include the "then" part in the `cond', and use
> `org-string-nw-p':
>
> (cond ((org-string-nw-p caption-from-attr-latex)
> (concat caption-from-attr-latex "\n"))
> ((and (not main) (equal label-str "")) "")
> ...)
>
> > (defun org-latex-guess-inputenc (header)
> > "Set the coding system in inputenc to what the buffer is.
> > @@ -1655,7 +1658,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))
>
> Be careful here: (plist-get attr :caption) will be non-nil if :caption
> is set to the empty string. It may be bulkier to use:
>
> (org-string-nw-p (plist-get attr :caption))
>
> > 'figure))))
> > (placement
> > (let ((place (plist-get attr :placement)))
> > @@ -2333,7 +2336,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))
>
> Ditto.
>
>
> Regards,
>
> --
> Nicolas Goaziou
>
[-- Attachment #1.2: Type: text/html, Size: 4689 bytes --]
[-- Attachment #2: 0001-Add-caption-attribute-to-ATTR_LATEX-property.patch --]
[-- Type: application/octet-stream, Size: 5609 bytes --]
From e2410352c8a270ce173908f55fdf5376ac331272 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.
* doc/org.texi (@LaTeX{} specific attributes): Add `:caption' attribute document.
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 |
|---+---|
---
doc/org.texi | 32 +++++++++++++++++++++++++++++---
lisp/ox-latex.el | 32 +++++++++++++++++++-------------
2 个文件被修改,插入 48 行(+),删除 16 行(-)
diff --git a/doc/org.texi b/doc/org.texi
index 9e47a17..7d378db 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -11599,6 +11599,12 @@ Environment used for the table. It can be set to any @LaTeX{} table
environment, like @code{tabularx}, @code{longtable}, @code{array},
@code{tabu}, @code{bmatrix}@enddots{} It defaults to
@code{org-latex-default-table-environment} value.
+@item :caption
+By default, you should use @code{#+caption} keyword to add a table caption.
+If you want to add caption with complex or special latex commands, you can use
+@code{:caption} attribute. It will precedence over @code{#+caption} keyword.
+It should be set with raw latex command and nothing in it will be
+interpreted by Org.
@item :float
@itemx :placement
Float environment for the table. Possible values are @code{sidewaystable},
@@ -11651,6 +11657,18 @@ a table that will span over multiple pages, or a matrix product:
| 3 | 4 |
@end example
+
+When export the below example to latex, the table caption will be set
+with latex command @code{\bicaption@{Heading A@}@{Heading B@}} instead of
+@code{#+CAPTION} keywords.
+
+@example
+#+CAPTION: Heading C
+#+ATTR_LATEX: :caption \bicaption@{Heading A@}@{Heading B@}
+| ..... | ..... |
+| ..... | ..... |
+@end example
+
@subsubheading Images in @LaTeX{} export
@cindex images, inline in @LaTeX{}
@cindex inlining images in @LaTeX{}
@@ -11663,9 +11681,17 @@ TikZ (@url{http://sourceforge.net/projects/pgf/}) images, it will become an
@code{\input} macro wrapped within a @code{tikzpicture} environment.}.
You can specify specify image width or height with, respectively,
-@code{:width} and @code{:height} attributes. It is also possible to add any
-other option with the @code{:options} attribute, as shown in the following
-example:
+@code{:width} and @code{:height} attributes. If you want to set image
+caption with special latex command, you can use @code{:caption} attribute,
+for example:
+
+@example
+#+ATTR_LATEX: :caption \bicaption@{Heading A@}@{Heading B@}
+[[./img/sed-hr4049.pdf]]
+@end example
+
+It is also possible to add any other option with the @code{:options}
+attribute, as shown in the following example:
@example
#+ATTR_LATEX: :width 5cm :options angle=90
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 09928a4..ce04d57 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -881,17 +881,19 @@ 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)))
- (cond
- ((and (not main) (equal label-str "")) "")
- ((not main) (concat label-str "\n"))
- ;; Option caption format with short name.
- (short (format "\\caption[%s]{%s%s}\n"
- (org-export-data short info)
- label-str
- (org-export-data main info)))
- ;; Standard caption format.
- (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
+ (short (org-export-get-caption element t))
+ (caption-from-attr-latex (org-export-read-attribute :attr_latex element :caption)))
+ (cond ((org-string-nw-p caption-from-attr-latex)
+ (concat caption-from-attr-latex "\n"))
+ ((and (not main) (equal label-str "")))
+ ((not main) (concat label-str "\n"))
+ ;; Option caption format with short name.
+ (short (format "\\caption[%s]{%s%s}\n"
+ (org-export-data short info)
+ label-str
+ (org-export-data main info)))
+ ;; Standard caption format.
+ (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
(defun org-latex-guess-inputenc (header)
"Set the coding system in inputenc to what the buffer is.
@@ -1655,7 +1657,9 @@ 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)
+ (org-string-nw-p (plist-get attr :caption)))
'figure))))
(placement
(let ((place (plist-get attr :placement)))
@@ -2333,7 +2337,9 @@ 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)
+ (org-string-nw-p (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] 9+ messages in thread
* Re: [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property
2013-06-30 14:27 ` feng shu
@ 2013-06-30 20:27 ` Bastien
2013-06-30 23:08 ` feng shu
0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2013-06-30 20:27 UTC (permalink / raw)
To: feng shu; +Cc: emacs-orgmode, Nicolas Goaziou
Hi Feng,
feng shu <tumashu@gmail.com> writes:
> (org-latex--inline-image): Tiny change.
> org-latex--org-table): Tiny change.
The Emacs usage is to write it like this:
(org-latex--inline-image, org-latex--org-table): Tiny change.
Thanks!
--
Bastien, nitpicking again :)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property
2013-06-30 20:27 ` Bastien
@ 2013-06-30 23:08 ` feng shu
2013-07-01 13:10 ` Bastien
2013-07-01 21:38 ` Nicolas Goaziou
0 siblings, 2 replies; 9+ messages in thread
From: feng shu @ 2013-06-30 23:08 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 409 bytes --]
Thanks for your help. This is V4 patch.
On Mon, Jul 1, 2013 at 4:27 AM, Bastien <bzg@gnu.org> wrote:
> Hi Feng,
>
> feng shu <tumashu@gmail.com> writes:
>
> > (org-latex--inline-image): Tiny change.
> > org-latex--org-table): Tiny change.
>
> The Emacs usage is to write it like this:
>
> (org-latex--inline-image, org-latex--org-table): Tiny change.
>
> Thanks!
>
> --
> Bastien, nitpicking again :)
>
[-- Attachment #1.2: Type: text/html, Size: 863 bytes --]
[-- Attachment #2: 0001-Add-caption-attribute-to-ATTR_LATEX-property.patch --]
[-- Type: application/octet-stream, Size: 5603 bytes --]
From c0b2a29c912d8e054c6062cc3bd63e0b4b5d907d 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,org-latex--org-table): Tiny change.
* doc/org.texi (@LaTeX{} specific attributes): Document `:caption'
attribute of #+ATTR_LATEX.
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 |
|---+---|
---
doc/org.texi | 32 +++++++++++++++++++++++++++++---
lisp/ox-latex.el | 32 +++++++++++++++++++-------------
2 个文件被修改,插入 48 行(+),删除 16 行(-)
diff --git a/doc/org.texi b/doc/org.texi
index 9e47a17..7d378db 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -11599,6 +11599,12 @@ Environment used for the table. It can be set to any @LaTeX{} table
environment, like @code{tabularx}, @code{longtable}, @code{array},
@code{tabu}, @code{bmatrix}@enddots{} It defaults to
@code{org-latex-default-table-environment} value.
+@item :caption
+By default, you should use @code{#+caption} keyword to add a table caption.
+If you want to add caption with complex or special latex commands, you can use
+@code{:caption} attribute. It will precedence over @code{#+caption} keyword.
+It should be set with raw latex command and nothing in it will be
+interpreted by Org.
@item :float
@itemx :placement
Float environment for the table. Possible values are @code{sidewaystable},
@@ -11651,6 +11657,18 @@ a table that will span over multiple pages, or a matrix product:
| 3 | 4 |
@end example
+
+When export the below example to latex, the table caption will be set
+with latex command @code{\bicaption@{Heading A@}@{Heading B@}} instead of
+@code{#+CAPTION} keywords.
+
+@example
+#+CAPTION: Heading C
+#+ATTR_LATEX: :caption \bicaption@{Heading A@}@{Heading B@}
+| ..... | ..... |
+| ..... | ..... |
+@end example
+
@subsubheading Images in @LaTeX{} export
@cindex images, inline in @LaTeX{}
@cindex inlining images in @LaTeX{}
@@ -11663,9 +11681,17 @@ TikZ (@url{http://sourceforge.net/projects/pgf/}) images, it will become an
@code{\input} macro wrapped within a @code{tikzpicture} environment.}.
You can specify specify image width or height with, respectively,
-@code{:width} and @code{:height} attributes. It is also possible to add any
-other option with the @code{:options} attribute, as shown in the following
-example:
+@code{:width} and @code{:height} attributes. If you want to set image
+caption with special latex command, you can use @code{:caption} attribute,
+for example:
+
+@example
+#+ATTR_LATEX: :caption \bicaption@{Heading A@}@{Heading B@}
+[[./img/sed-hr4049.pdf]]
+@end example
+
+It is also possible to add any other option with the @code{:options}
+attribute, as shown in the following example:
@example
#+ATTR_LATEX: :width 5cm :options angle=90
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 09928a4..ce04d57 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -881,17 +881,19 @@ 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)))
- (cond
- ((and (not main) (equal label-str "")) "")
- ((not main) (concat label-str "\n"))
- ;; Option caption format with short name.
- (short (format "\\caption[%s]{%s%s}\n"
- (org-export-data short info)
- label-str
- (org-export-data main info)))
- ;; Standard caption format.
- (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
+ (short (org-export-get-caption element t))
+ (caption-from-attr-latex (org-export-read-attribute :attr_latex element :caption)))
+ (cond ((org-string-nw-p caption-from-attr-latex)
+ (concat caption-from-attr-latex "\n"))
+ ((and (not main) (equal label-str "")))
+ ((not main) (concat label-str "\n"))
+ ;; Option caption format with short name.
+ (short (format "\\caption[%s]{%s%s}\n"
+ (org-export-data short info)
+ label-str
+ (org-export-data main info)))
+ ;; Standard caption format.
+ (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
(defun org-latex-guess-inputenc (header)
"Set the coding system in inputenc to what the buffer is.
@@ -1655,7 +1657,9 @@ 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)
+ (org-string-nw-p (plist-get attr :caption)))
'figure))))
(placement
(let ((place (plist-get attr :placement)))
@@ -2333,7 +2337,9 @@ 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)
+ (org-string-nw-p (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] 9+ messages in thread
* Re: [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property
2013-06-30 23:08 ` feng shu
@ 2013-07-01 13:10 ` Bastien
2013-07-01 21:38 ` Nicolas Goaziou
1 sibling, 0 replies; 9+ messages in thread
From: Bastien @ 2013-07-01 13:10 UTC (permalink / raw)
To: feng shu; +Cc: emacs-orgmode
Hi Feng,
feng shu <tumashu@gmail.com> writes:
> Thanks for your help. This is V4 patch.
Thanks for the updated patch -- there are more knowledgeable people
for this area of the code, I'll let them apply/rework it or not.
Best,
--
Bastien
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property
2013-06-30 23:08 ` feng shu
2013-07-01 13:10 ` Bastien
@ 2013-07-01 21:38 ` Nicolas Goaziou
2013-07-01 23:58 ` feng shu
1 sibling, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2013-07-01 21:38 UTC (permalink / raw)
To: feng shu; +Cc: Bastien, emacs-orgmode
Hello,
feng shu <tumashu@gmail.com> writes:
> Thanks for your help. This is V4 patch.
Thanks for the update. More comments below.
> +@item :caption
> +By default, you should use @code{#+caption} keyword to add a table caption.
> +If you want to add caption with complex or special latex commands, you can use
> +@code{:caption} attribute. It will precedence over @code{#+caption} keyword.
> +It should be set with raw latex command and nothing in it will be
> +interpreted by Org.
You need to use upper cases for keywords: @code{#+CAPTION}. Also,
sentences are expected to end with two spaces and latex should be typed
@LaTeX{}. Here is a suggestion (note that I'm not a wording expert):
@code{#+CAPTION} keyword is the simplest way to set a caption for
a table (@pxref{Images and tables}). If you need more advanced commands
for that task, you can use @code{:caption} attribute instead. Its value
should be raw @LaTeX{} code. It has precedence over @code{#+CAPTION}.
> +When export the below example to latex, the table caption will be set
> +with latex command @code{\bicaption@{Heading A@}@{Heading B@}} instead of
> +@code{#+CAPTION} keywords.
In the example below, @LaTeX{} command @code{\bicaption@{Heading
A@}@{Heading B@}} will set the caption. (I think you can drop the rest
of the sentence).
> -@code{:width} and @code{:height} attributes. It is also possible to add any
> -other option with the @code{:options} attribute, as shown in the following
> -example:
> +@code{:width} and @code{:height} attributes. If you want to set image
> +caption with special latex command, you can use @code{:caption} attribute,
> +for example:
Besides the missing two spaces at the end of the sentence, I suggest the
following:
You can specify specify image width or height with, respectively,
@code{:width} and @code{:height} attributes. It is also possible to add any
other option with the @code{:options} attribute, as shown in the following
example:
EXAMPLE
If you need a specific command for the caption, use @code{:caption}
attribute. It will override standard @code{#+CAPTION} value, if any.
EXAMPLE?
Also, you don't seem to document the feature for special blocks.
> - (short (org-export-get-caption element t)))
> - (cond
> - ((and (not main) (equal label-str "")) "")
> - ((not main) (concat label-str "\n"))
> - ;; Option caption format with short name.
> - (short (format "\\caption[%s]{%s%s}\n"
> - (org-export-data short info)
> - label-str
> - (org-export-data main info)))
> - ;; Standard caption format.
> - (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
> + (short (org-export-get-caption element t))
> + (caption-from-attr-latex (org-export-read-attribute :attr_latex element :caption)))
> + (cond ((org-string-nw-p caption-from-attr-latex)
> + (concat caption-from-attr-latex "\n"))
> + ((and (not main) (equal label-str "")))
Why do you drop the return value (empty string) here?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property
2013-07-01 21:38 ` Nicolas Goaziou
@ 2013-07-01 23:58 ` feng shu
2013-07-02 17:03 ` Nicolas Goaziou
0 siblings, 1 reply; 9+ messages in thread
From: feng shu @ 2013-07-01 23:58 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Bastien, emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 3502 bytes --]
Thanks all the people! This is V5!
On Tue, Jul 2, 2013 at 5:38 AM, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
> Hello,
>
> feng shu <tumashu@gmail.com> writes:
>
> > Thanks for your help. This is V4 patch.
>
> Thanks for the update. More comments below.
>
> > +@item :caption
> > +By default, you should use @code{#+caption} keyword to add a table
> caption.
> > +If you want to add caption with complex or special latex commands, you
> can use
> > +@code{:caption} attribute. It will precedence over @code{#+caption}
> keyword.
> > +It should be set with raw latex command and nothing in it will be
> > +interpreted by Org.
>
> You need to use upper cases for keywords: @code{#+CAPTION}. Also,
> sentences are expected to end with two spaces and latex should be typed
> @LaTeX{}. Here is a suggestion (note that I'm not a wording expert):
>
>
> @code{#+CAPTION} keyword is the simplest way to set a caption for
> a table (@pxref{Images and tables}). If you need more advanced commands
> for that task, you can use @code{:caption} attribute instead. Its value
> should be raw @LaTeX{} code. It has precedence over @code{#+CAPTION}.
>
> I think it's much good than mine. For me, writing documentation is a painful
thing.
> > +When export the below example to latex, the table caption will be set
> > +with latex command @code{\bicaption@{Heading A@}@{Heading B@}} instead
> of
> > +@code{#+CAPTION} keywords.
>
> In the example below, @LaTeX{} command @code{\bicaption@{Heading
> A@}@{Heading B@}} will set the caption. (I think you can drop the rest
> of the sentence).
>
> > -@code{:width} and @code{:height} attributes. It is also possible to
> add any
> > -other option with the @code{:options} attribute, as shown in the
> following
> > -example:
> > +@code{:width} and @code{:height} attributes. If you want to set image
> > +caption with special latex command, you can use @code{:caption}
> attribute,
> > +for example:
>
> Besides the missing two spaces at the end of the sentence, I suggest the
> following:
>
> You can specify specify image width or height with, respectively,
> @code{:width} and @code{:height} attributes. It is also possible to add
> any
> other option with the @code{:options} attribute, as shown in the
> following
> example:
>
> EXAMPLE
>
> If you need a specific command for the caption, use @code{:caption}
> attribute. It will override standard @code{#+CAPTION} value, if any.
>
> EXAMPLE?
>
> Also, you don't seem to document the feature for special blocks.
>
> > - (short (org-export-get-caption element t)))
> > - (cond
> > - ((and (not main) (equal label-str "")) "")
> > - ((not main) (concat label-str "\n"))
> > - ;; Option caption format with short name.
> > - (short (format "\\caption[%s]{%s%s}\n"
> > - (org-export-data short info)
> > - label-str
> > - (org-export-data main info)))
> > - ;; Standard caption format.
> > - (t (format "\\caption{%s%s}\n" label-str (org-export-data main
> info))))))
> > + (short (org-export-get-caption element t))
> > + (caption-from-attr-latex (org-export-read-attribute :attr_latex
> element :caption)))
> > + (cond ((org-string-nw-p caption-from-attr-latex)
> > + (concat caption-from-attr-latex "\n"))
> > + ((and (not main) (equal label-str "")))
>
> Why do you drop the return value (empty string) here?
>
> It's my mistake!
>
> Regards,
>
> --
> Nicolas Goaziou
>
[-- Attachment #1.2: Type: text/html, Size: 5144 bytes --]
[-- Attachment #2: 0001-Add-caption-attribute-to-ATTR_LATEX-property.patch --]
[-- Type: application/octet-stream, Size: 4984 bytes --]
From 2908d9d7998161f1022c1a16b911a5f2ae38a6b3 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,org-latex--org-table): Tiny change.
* doc/org.texi (@LaTeX{} specific attributes): Document `:caption'
attribute of #+ATTR_LATEX.
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 |
|---+---|
---
doc/org.texi | 45 +++++++++++++++++++++++++++++++++++++++++++++
lisp/ox-latex.el | 13 ++++++++++---
2 个文件被修改,插入 55 行(+),删除 3 行(-)
diff --git a/doc/org.texi b/doc/org.texi
index 427b583..5978aee 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -11599,6 +11599,11 @@ Environment used for the table. It can be set to any @LaTeX{} table
environment, like @code{tabularx}, @code{longtable}, @code{array},
@code{tabu}, @code{bmatrix}@enddots{} It defaults to
@code{org-latex-default-table-environment} value.
+@item :caption
+@code{#+CAPTION} keyword is the simplest way to set a caption for a table
+(@pxref{Images and tables}). If you need more advanced commands for that
+task, you can use @code{:caption} attribute instead. Its value should be
+raw @LaTeX{} code. It has precedence over @code{#+CAPTION}.
@item :float
@itemx :placement
Float environment for the table. Possible values are @code{sidewaystable},
@@ -11651,6 +11656,19 @@ a table that will span over multiple pages, or a matrix product:
| 3 | 4 |
@end example
+
+In the example below, @LaTeX{} command @code{\bicaption@{HeadingA@}@{HeadingB@}}
+will set the caption.
+
+
+@example
+#+CAPTION: HeadingC
+#+ATTR_LATEX: :caption \bicaption@{HeadingA@}@{HeadingB@}
+| ..... | ..... |
+| ..... | ..... |
+@end example
+
+
@subsubheading Images in @LaTeX{} export
@cindex images, inline in @LaTeX{}
@cindex inlining images in @LaTeX{}
@@ -11672,6 +11690,18 @@ example:
[[./img/sed-hr4049.pdf]]
@end example
+
+If you need a specific command for the caption, use @code{:caption}
+attribute. It will override standard @code{#+CAPTION} value, if any.
+
+
+@example
+#+CAPTION: HeadingC
+#+ATTR_LATEX: :caption \bicaption@{HeadingA@}@{HeadingB@}
+[[./img/sed-hr4049.pdf]]
+@end example
+
+
If you have specified a caption as described in @ref{Images and tables}, the
picture will be wrapped into a @code{figure} environment and thus become
a floating element. You can also ask Org to export an image as a float
@@ -11768,6 +11798,21 @@ Therefore, any even number greater than 2 is the sum of two primes.
\end@{proof@}
@end example
+
+If you need to insert a specific caption command, use @code{:caption}
+attribute. It will override standard @code{#+CAPTION} value, if any.
+For example:
+
+
+@example
+#+CAPTION: HeadingB
+#+ATTR_LATEX: :caption \MyCaption@{HeadingA@}
+#+BEGIN_PROOF
+...
+#+END_PROOF
+@end example
+
+
@subsubheading Horizontal rules
@cindex horizontal rules, in @LaTeX{} export
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 09928a4..dcbed54 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -881,8 +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-attr-latex (org-export-read-attribute :attr_latex element :caption)))
(cond
+ ((org-string-nw-p caption-from-attr-latex)
+ (concat caption-from-attr-latex "\n"))
((and (not main) (equal label-str "")) "")
((not main) (concat label-str "\n"))
;; Option caption format with short name.
@@ -1655,7 +1658,9 @@ 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)
+ (org-string-nw-p (plist-get attr :caption)))
'figure))))
(placement
(let ((place (plist-get attr :placement)))
@@ -2333,7 +2338,9 @@ 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)
+ (org-string-nw-p (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] 9+ messages in thread
* Re: [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property
2013-07-01 23:58 ` feng shu
@ 2013-07-02 17:03 ` Nicolas Goaziou
0 siblings, 0 replies; 9+ messages in thread
From: Nicolas Goaziou @ 2013-07-02 17:03 UTC (permalink / raw)
To: feng shu; +Cc: Bastien, emacs-orgmode
Hello,
feng shu <tumashu@gmail.com> writes:
> Thanks all the people! This is V5!
Applied. Thank you!
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-07-02 17:03 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-29 23:10 [PATCH] (update) Add :caption attribute to #+ATTR_LATEX property feng shu
2013-06-30 11:46 ` Nicolas Goaziou
2013-06-30 14:27 ` feng shu
2013-06-30 20:27 ` Bastien
2013-06-30 23:08 ` feng shu
2013-07-01 13:10 ` Bastien
2013-07-01 21:38 ` Nicolas Goaziou
2013-07-01 23:58 ` feng shu
2013-07-02 17:03 ` Nicolas Goaziou
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).