emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: Re: [patch] LaTeX export using tabu tables
Date: Mon, 25 Mar 2013 13:35:08 +0800	[thread overview]
Message-ID: <878v5cdotv.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 87ehf5ywqn.fsf@gmail.com

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

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Thanks for your patch. I didn't know about "tabu" package, but it looks
> interesting.

It's definitely my new go-to table environment, though I'm struggling to
ignore the fact that it's got the ugliest documentation of any LaTeX
package I've ever seen.

> You could also add another attribute, :spread, which would used "spread"
> instead of "to" when non-nil. This way, users can have the best of both
> worlds.

[...]

> You need to list each modified function in the commit message.

[...]

> IMO, it's cleaner (as in more explicit) to use:
>
>   (unless (member table-env '("longtable" "longtabu")) ...)
>
> You may also use another branch in the `cond', in order to clearly
> separate "tabu" and "longtabu" environments from other packages. It
> would lead to some code duplication, but would allow for easier
> development of tabu specific features (e.g. :spread keyword), if ever
> needed.

I was trying to be too clever! Attached is a non-clever version that
includes a :spread keyword, and a (hopefully) correctly-written commit
message.

Thanks for the pointers,
Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0008-ox-latex.el-org-latex-org-table-org-latex-table-row-.patch --]
[-- Type: text/x-patch, Size: 4423 bytes --]

From d4daaff48978958b788d4dd3f7434b7db276e4ac Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Mon, 25 Mar 2013 13:27:33 +0800
Subject: [PATCH 8/8] ox-latex.el (org-latex--org-table, org-latex-table-row):
 Allow use of the "tabu" table environment when exporting tables to LaTeX.

* ox-latex.el (org-latex--org-table): New latex export attribute
  :spread accommodates weird width specification syntax of the tabu
  package.
---
 lisp/ox-latex.el | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 310fa14..49463ca 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 '("longtabu" "longtable"))
 		      (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))
+	 (spread (plist-member 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 spread "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
@@ -2471,7 +2495,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)
+				       (if spread " spread %s " " to %s")
+				     "{%s}") width) "")
 			alignment
 			contents
 			table-env)
@@ -2634,9 +2661,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 (member (or (plist-get attr :environment)
+				   org-latex-default-table-environment)
+			       '("longtable" "longtabu")))
 	   (booktabsp (if (plist-member attr :booktabs)
 			  (plist-get attr :booktabs)
 			org-latex-tables-booktabs))
-- 
1.8.2


  reply	other threads:[~2013-03-25  5:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-23  4:26 [patch] LaTeX export using tabu tables Eric Abrahamsen
2013-03-24  0:18 ` Vikas Rawal
2013-03-24  9:26 ` Nicolas Goaziou
2013-03-25  5:35   ` Eric Abrahamsen [this message]
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=878v5cdotv.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).