From mboxrd@z Thu Jan 1 00:00:00 1970 From: Feng Shu Subject: Re: [need help] How to add a caption to table with #+attr_latex :caption \bicaption{...}{...} Date: Sun, 30 Jun 2013 07:32:06 +0800 Message-ID: <87mwq88pe1.fsf@gmail.com> References: <874nchnif0.fsf@pank.eu> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ut765-0008MK-Ub for emacs-orgmode@gnu.org; Sat, 29 Jun 2013 22:10:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ut764-0007N4-Nn for emacs-orgmode@gnu.org; Sat, 29 Jun 2013 22:10:37 -0400 Received: from plane.gmane.org ([80.91.229.3]:39366) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ut764-0007Mx-Gj for emacs-orgmode@gnu.org; Sat, 29 Jun 2013 22:10:36 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Ut75X-0002VB-NF for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 04:10:34 +0200 Received: from 183.202.108.1 ([183.202.108.1]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 30 Jun 2013 04:10:03 +0200 Received: from tumashu by 183.202.108.1 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 30 Jun 2013 04:10:03 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Rasmus 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: -‡˜ ## 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 --