all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [need help] How to add a caption to table with #+attr_latex :caption \bicaption{...}{...}
@ 2013-06-29  1:08 feng shu
  2013-06-29 13:41 ` Rasmus
  0 siblings, 1 reply; 3+ messages in thread
From: feng shu @ 2013-06-29  1:08 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1555 bytes --]

HI:

In my thesie, I need add a caption to table or figure with
\bicaption{中文标题}{English title}

I can't find the easy way to do this in org-mode ,so  I add :caption  to
#+attr_latex:

for example:

#+attr_latex:  :caption \bicaption{...}{....}


But the below function doesn't work as expected, someone can help me?
thanks!

#+begin_src emacs-lisp
(defun org-latex--caption/label-string (element info)
  "Return caption and label LaTeX string for ELEMENT.

INFO is a plist holding contextual information.  If there's no
caption nor label, return the empty string.

For non-floats, see `org-latex--wrap-label'."
  (let* ((label (org-element-property :name element))
     (label-str (if (not (org-string-nw-p label)) ""
              (format "\\label{%s}"
                  (org-export-solidify-link-text label))))
     (main (org-export-get-caption element))
     (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 "")) (format "%s"
caption-from-latex-attr))
     ((not main) (concat label-str "\n" (format "%s"
caption-from-latex-attr)))
     ;; 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))))))

#+end_src

[-- Attachment #2: Type: text/html, Size: 1964 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [need help] How to add a caption to table with #+attr_latex :caption \bicaption{...}{...}
  2013-06-29  1:08 [need help] How to add a caption to table with #+attr_latex :caption \bicaption{...}{...} feng shu
@ 2013-06-29 13:41 ` Rasmus
  2013-06-29 23:32   ` Feng Shu
  0 siblings, 1 reply; 3+ messages in thread
From: Rasmus @ 2013-06-29 13:41 UTC (permalink / raw)
  To: emacs-orgmode

Hi Feng,

> In my thesie, I need add a caption to table or figure with
> \bicaption{中文标题}{English title}

I assume you'd still want to use the #+CAPTION-cookie, no?  If so, one
solution that comes to mind is writing captions like

#+CAPTION:  my-Asian-string (sorry about my ignorance)  MYSPLIT  my-English-string

and write a filter using (org-split-string text MYSPLIT) and format it
as (format "\bicaption{%s}{%s}" LIST) if the length is two.  

Org perhaps regexps could be used to identify 'my-Asian-string'.

I'm not sure where to apply the filter, though, but a better solution
than the one below would use `org-export-get-caption' on the correct
elements at the correct time. . .

Here's a dirty, inelegant regexp filter that's run on the final
tex-string.

#+begin_src emacs-lisp
(defun org-latex-filter-split-caption (text backend info)
  "When ## is present in a string make a bicaption."
  (when (org-export-derived-backend-p backend 'latex 'beamer)
    (replace-regexp-in-string "\\\\caption{\\(.*?\\)[ \t]*\\\\#\\\\#[ \t]+?\\(.*\\)}"
			      "\\\\bicaption{\\1}{\\2}" text)
    ))

  (add-to-list 'org-export-filter-final-output-functions
               'org-latex-filter-split-caption)
#+end_src

It will export this document 'correctly':

#+begin_src org
#+TITLE: my test doc
#+CAPTION: 中文标题 ## english title
| 1 | 2 | 3 |

#+CAPTION: english title
| 2 | 3 |
#+end_src

Hope this inspires you to solve the problem in a more elegant manner.

–Rasmus

-- 
Enough with the bla bla!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [need help] How to add a caption to table with #+attr_latex :caption \bicaption{...}{...}
  2013-06-29 13:41 ` Rasmus
@ 2013-06-29 23:32   ` Feng Shu
  0 siblings, 0 replies; 3+ messages in thread
From: Feng Shu @ 2013-06-29 23:32 UTC (permalink / raw)
  To: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> Hi Feng,
>
>> In my thesie, I need add a caption to table or figure with
>> \bicaption{中文标题}{English title}
>
> I assume you'd still want to use the #+CAPTION-cookie, no?  If so, one
> solution that comes to mind is writing captions like
> #+CAPTION:  my-Asian-string (sorry about my ignorance)  MYSPLIT  my-English-string
>
> and write a filter using (org-split-string text MYSPLIT) and format it
> as (format "\bicaption{%s}{%s}" LIST) if the length is two.  
>
> Org perhaps regexps could be used to identify 'my-Asian-string'.
>
> I'm not sure where to apply the filter, though, but a better solution
> than the one below would use `org-export-get-caption' on the correct
> elements at the correct time. . .

---------------------------
#+caption: 中文标题
#+caption: English Title
| 1 | 2  |

---------------------------

I think this is the best document construct, simple and  intuitive.

But, realizing this feature need some dirty hack, the main reason is
that \bicaption often a custom latex command, fig caption and table
caption are different in option, for example:

\bicaption[图]{...}[fig]{...}
\bicaption{图}{fig}{...}{...}
\bicaption{...}{...}

\bicaption[表]{...}[Table]{}

...

>
> Here's a dirty, inelegant regexp filter that's run on the final
> tex-string.
> #+begin_src emacs-lisp
> (defun org-latex-filter-split-caption (text backend info)
>   "When ## is present in a string make a bicaption."
>   (when (org-export-derived-backend-p backend 'latex 'beamer)
>     (replace-regexp-in-string "\\\\caption{\\(.*?\\)[ \t]*\\\\#\\\\#[ \t]+?\\(.*\\)}"
> 			      "\\\\bicaption{\\1}{\\2}" text)
>     ))
>
>   (add-to-list 'org-export-filter-final-output-functions
>                'org-latex-filter-split-caption)
> #+end_src

It is a very useful tip, thanks!
>
> It will export this document 'correctly':
> #+begin_src org
> #+TITLE: my test doc
> #+CAPTION: -‡\a˜ ## english title
> | 1 | 2 | 3 |
>
> #+CAPTION: english title
> | 2 | 3 |
> #+end_src
>
> Hope this inspires you to solve the problem in a more elegant manner.
>
> –Rasmus

-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-06-30  2:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-29  1:08 [need help] How to add a caption to table with #+attr_latex :caption \bicaption{...}{...} feng shu
2013-06-29 13:41 ` Rasmus
2013-06-29 23:32   ` Feng Shu

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.