emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] using export filters to emulate multi-column table cells?


From: Nicolas Goaziou
Subject: Re: [O] using export filters to emulate multi-column table cells?
Date: Thu, 14 Feb 2013 18:42:52 +0100

Hello,

Eric Abrahamsen <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]