From 7767f8eae1328530f624b04e625a4643dbe5d9b5 Mon Sep 17 00:00:00 2001 From: Feng Shu 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 | 34 ++++++++++++++++++++++++++++++++++ lisp/ox-latex.el | 13 ++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 427b583c4..6f2aa36cd 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,16 @@ 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 +#+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 +11687,14 @@ 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 +#+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 +11791,17 @@ 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 +#+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 09928a416..dcbed54d5 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))) -- 2.11.4.GIT