emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: [patch] LaTeX export using tabu tables
Date: Sat, 23 Mar 2013 12:26:49 +0800	[thread overview]
Message-ID: <87li9e4u7q.fsf@ericabrahamsen.net> (raw)

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

There are about forty different table environments for latex, all of
which do slightly different things, and none of them seem to do it all.
I found the "tabu" package recently, and thought "oh god another one",
but it seems to do it all: clever column alignment, longtable
functionality, all that good stuff.

Attached is a patch that lets you use the "tabu" and "longtabu" table
environments. Mostly the patch is necessary because tabu has its own
annoying syntax for table width declarations. Where everyone else does
something like:

\begin{tabular}{\textwidth}{cllr}

tabu does this:

\begin{tabu} to \textwidth {cllr}

Where you're allowed to use either "to" or "spread". Annoying, but in my
case still worth it. Since table plists can handle spaces, this works
with the attached patch:

#+ATTR_LATEX: :environment tabu :width to \textwidth :font \scriptsize :align rXrXrr

Actually I've just set `org-latex-default-table-environment' to tabu.

Dunno if this is worth it for other people, but there's the patch. If
access to the "spread" keyword isn't worth the trouble I can hard-code
"to": that would at least mean you could switch between table and tabu
without having to edit your ATTR_LATEX lines.

Yrs,
Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0008-Allow-LaTeX-export-of-tables-using-the-tabu-package.patch --]
[-- Type: text/x-patch, Size: 2901 bytes --]

From ff2635d43509481ea4b72596a325a6f155dc0cfe Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Sat, 23 Mar 2013 12:15:29 +0800
Subject: [PATCH 8/8] Allow LaTeX export of tables using the tabu package

---
 lisp/ox-latex.el | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 310fa14..1410b49 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2429,7 +2429,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 (string-match-p "longtab" table-env)
 		      (let ((float (plist-get attr :float)))
 			(cond
 			 ((string= float "sidewaystable") "sidewaystable")
@@ -2447,10 +2447,12 @@ This function assumes TABLE has `org' as its `:type' property and
 		    org-latex-tables-centered)))
     ;; Prepare the final format string for the table.
     (cond
-     ;; Longtable.
-     ((equal "longtable" table-env)
+     ;; Longtable or longtabu.
+     ((string-match-p "longtab" table-env)
       (concat (and fontsize (concat "{" fontsize))
-	      (format "\\begin{longtable}{%s}\n" alignment)
+	      (format "\\begin{%s}%s{%s}\n" table-env
+		      (if (and width (equal "longtabu" table-env))
+			  (format " %s " width) "") alignment)
 	      (and org-latex-table-caption-above
 		   (org-string-nw-p caption)
 		   (concat caption "\\\\\n"))
@@ -2458,7 +2460,7 @@ This function assumes TABLE has `org' as its `:type' property and
 	      (and (not org-latex-table-caption-above)
 		   (org-string-nw-p caption)
 		   (concat caption "\\\\\n"))
-	      "\\end{longtable}\n"
+	      (format "\\end{%s}\n" table-env)
 	      (and fontsize "}")))
      ;; Others.
      (t (concat (cond
@@ -2471,7 +2473,10 @@ This function assumes TABLE has `org' as its `:type' property and
 		 (fontsize (concat "{" fontsize)))
 		(format "\\begin{%s}%s{%s}\n%s\\end{%s}"
 			table-env
-			(if width (format "{%s}" width) "")
+			(if width (format
+				   (if (equal "tabu" table-env)
+				       " %s "
+				     "{%s}") width) "")
 			alignment
 			contents
 			table-env)
@@ -2634,9 +2639,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)
-				    org-latex-default-table-environment)
-				"longtable"))
+	   (longtablep (string-match-p "longtab"
+				       (or (plist-get attr :environment)
+					   org-latex-default-table-environment)))
 	   (booktabsp (if (plist-member attr :booktabs)
 			  (plist-get attr :booktabs)
 			org-latex-tables-booktabs))
-- 
1.8.2


             reply	other threads:[~2013-03-23  4:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-23  4:26 Eric Abrahamsen [this message]
2013-03-24  0:18 ` [patch] LaTeX export using tabu tables Vikas Rawal
2013-03-24  9:26 ` Nicolas Goaziou
2013-03-25  5:35   ` Eric Abrahamsen
2013-03-25  5:54     ` Bastien
2013-03-25  6:54       ` Eric Abrahamsen
2013-03-25  6:51         ` Bastien
2013-03-25 19:59     ` Nicolas Goaziou
2013-03-26  2:54       ` Eric Abrahamsen
2013-03-27 14:29         ` Nicolas Goaziou
2013-03-26 20:05     ` Marcin Borkowski
2013-03-27  1:59       ` Eric Abrahamsen
2013-04-07 13:15         ` Marcin Borkowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87li9e4u7q.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).