From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: using export filters to emulate multi-column table cells? Date: Thu, 14 Feb 2013 18:42:52 +0100 Message-ID: <874nhe94gz.fsf@gmail.com> References: <87sj4zbhy5.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:37713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U62q3-0007CY-FS for emacs-orgmode@gnu.org; Thu, 14 Feb 2013 12:43:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U62px-0007ij-C0 for emacs-orgmode@gnu.org; Thu, 14 Feb 2013 12:43:15 -0500 Received: from mail-wi0-f173.google.com ([209.85.212.173]:60715) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U62px-0007iP-5o for emacs-orgmode@gnu.org; Thu, 14 Feb 2013 12:43:09 -0500 Received: by mail-wi0-f173.google.com with SMTP id hq4so190419wib.12 for ; Thu, 14 Feb 2013 09:43:08 -0800 (PST) In-Reply-To: <87sj4zbhy5.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Thu, 14 Feb 2013 13:08:50 +0800") 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: Eric Abrahamsen Cc: emacs-orgmode@gnu.org Hello, Eric Abrahamsen writes: > Is there any way to use the new exporter mechanisms to emulate table > cells that span rows or columns on export? I'm envisioning something > like this: > > | | <2col>Grains | | > | Year | Oats | Wheat | > | 2007 | 10lbs | 40lbs | > > Where an export filter would pick up on the <2col> cookie, replace it > with something backend-specific like \multicolumn{2}{Grains}, and then > somehow remove the following table field from export. You can add a function to `org-export-filter-table-row-functions'. It will be called with three arguments. The first one is the table row, as a string in back-end syntax. If you recognize the pattern "<2col>", you modify the string accordingly and return it as a replacement. E.g: #+begin_src emacs-lisp (defun my-multicolumn-filter (row backend info) (when (and (org-export-derived-backend-p backend 'latex) (string-match "<\\([0-9]+\\)col>" row)) (let ((columns (string-to-number (match-string 1 row))) (start (match-end 0))) (setq row (replace-match "" nil nil row)) (while (and (> columns 1) (string-match "&" row start)) (setq row (replace-match "" nil nil row)) (decf columns)) row))) (add-to-list 'org-export-filter-table-row-functions 'my-multicolumn-filter) #+end_src Regards, -- Nicolas Goaziou