From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: [patch] LaTeX export using tabu tables Date: Tue, 26 Mar 2013 10:54:04 +0800 Message-ID: <87y5daan1v.fsf@ericabrahamsen.net> References: <87li9e4u7q.fsf@ericabrahamsen.net> <87ehf5ywqn.fsf@gmail.com> <878v5cdotv.fsf@ericabrahamsen.net> <87y5dbxnbp.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:41465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKJwE-0005Vd-5h for emacs-orgmode@gnu.org; Mon, 25 Mar 2013 22:48:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKJw8-0005Pn-M8 for emacs-orgmode@gnu.org; Mon, 25 Mar 2013 22:48:38 -0400 Received: from plane.gmane.org ([80.91.229.3]:50909) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKJw8-0005Pb-C4 for emacs-orgmode@gnu.org; Mon, 25 Mar 2013 22:48:32 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UKJwU-0002wt-VH for emacs-orgmode@gnu.org; Tue, 26 Mar 2013 03:48:54 +0100 Received: from 114.250.124.55 ([114.250.124.55]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 26 Mar 2013 03:48:54 +0100 Received: from eric by 114.250.124.55 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 26 Mar 2013 03:48:54 +0100 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 --=-=-= Content-Type: text/plain Nicolas Goaziou writes: I'll get this right eventually... >> + (spread (plist-member attr :spread)) > > I think you mean (plist-get attr :spread), otherwise ":spread nil" will > still activate spread. Also, since it's a predicate, I suggest to name > the variable "spreadp". Me being clever again -- I misunderstood how that would work. [...] > "longtabu" gets its own cond branch, but not "tabu". I think that > defeats the purpose of the separation, which is to be able to add > support for features of this rich table environment without cluttering > the rest of the code. Doing it partially isn't worth the code > duplication it implies. > > IOW, either we separate both "tabu" and "longtabu" completely, or we > separate none of them. Your call. I've kept the separation. There was no need to duplicate all the float environment stuff, so there's not too much extra code. Thanks for all the pointers! Eric --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ox-latex-Allow-use-of-the-tabu-and-longtabu-table-en.patch >From 675c33c7939795758ae6d1c2b33201bd25a6ac6e Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Tue, 26 Mar 2013 10:45:30 +0800 Subject: [PATCH] ox-latex: Allow use of the "tabu" and "longtabu" table environments * lisp/ox-latex.el (org-latex--org-table, org-latex-table-row): New table attribute :spread handles the width specification syntax of "tabu" and "longtabu" table environments. --- lisp/ox-latex.el | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 310fa14..7ca1f94 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -48,7 +48,7 @@ ;; - The second most important attribute is `:environment'. It is the ;; environment used for the table and defaults to ;; `org-latex-default-table-environment' value. It can be set to -;; anything, including "tabularx", "longtable", "array", +;; anything, including "tabularx", "longtable", "array", "tabu", ;; "bmatrix"... ;; ;; - `:float' attribute defines a float environment for the table. @@ -61,6 +61,12 @@ ;; alignment string of the table, its font size and its width. They ;; only apply on regular tables. ;; +;; - `:spread' is a boolean attribute specific to the "tabu" and +;; "longtabu" environments, and only takes effect when used in +;; conjunction with the `:width' attribute. When `:spread' is +;; present, the table will be spread or shrunk by the value of +;; `:width'. +;; ;; - `:booktabs', `:center' and `:rmlines' values are booleans. They ;; toggle, respectively "booktabs" usage (assuming the package is ;; properly loaded), table centering and removal of every horizontal @@ -2429,7 +2435,7 @@ This function assumes TABLE has `org' as its `:type' property and org-latex-default-table-environment)) ;; If table is a float, determine environment: table, table* ;; or sidewaystable. - (float-env (unless (equal "longtable" table-env) + (float-env (unless (member table-env '("longtable" "longtabu")) (let ((float (plist-get attr :float))) (cond ((string= float "sidewaystable") "sidewaystable") @@ -2441,6 +2447,7 @@ This function assumes TABLE has `org' as its `:type' property and (fontsize (let ((font (plist-get attr :font))) (and font (concat font "\n")))) (width (plist-get attr :width)) + (spreadp (plist-get attr :spread)) (placement (or (plist-get attr :placement) (format "[%s]" org-latex-default-figure-position))) (centerp (if (plist-member attr :center) (plist-get attr :center) @@ -2460,6 +2467,23 @@ This function assumes TABLE has `org' as its `:type' property and (concat caption "\\\\\n")) "\\end{longtable}\n" (and fontsize "}"))) + ;; Longtabu + ((equal "longtabu" table-env) + (concat (and fontsize (concat "{" fontsize)) + (format "\\begin{longtabu}%s{%s}\n" + (if width + (format " %s %s " + (if spreadp "spread" "to") width) "") + alignment) + (and org-latex-table-caption-above + (org-string-nw-p caption) + (concat caption "\\\\\n")) + contents + (and (not org-latex-table-caption-above) + (org-string-nw-p caption) + (concat caption "\\\\\n")) + "\\end{longtabu}\n" + (and fontsize "}"))) ;; Others. (t (concat (cond (float-env @@ -2469,12 +2493,19 @@ This function assumes TABLE has `org' as its `:type' property and fontsize)) (centerp (concat "\\begin{center}\n" fontsize)) (fontsize (concat "{" fontsize))) - (format "\\begin{%s}%s{%s}\n%s\\end{%s}" - table-env - (if width (format "{%s}" width) "") - alignment - contents - table-env) + (cond ((equal "tabu" table-env) + (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}" + (if width (format + (if spreadp " spread %s " " to %s ") + width) "") + alignment + contents)) + (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}" + table-env + (if width (format "{%s}" width) "") + alignment + contents + table-env))) (cond (float-env (concat (if org-latex-table-caption-above "" caption) @@ -2634,9 +2665,9 @@ a communication channel." (when (eq (org-element-property :type table-row) 'standard) (let* ((attr (org-export-read-attribute :attr_latex (org-export-get-parent table-row))) - (longtablep (string= (or (plist-get attr :environment) + (longtablep (member (or (plist-get attr :environment) org-latex-default-table-environment) - "longtable")) + '("longtable" "longtabu"))) (booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs) org-latex-tables-booktabs)) -- 1.8.2 --=-=-=--