From mboxrd@z Thu Jan 1 00:00:00 1970 From: Niels Giesen Subject: Patch to customize output of tables in LaTeX exporter. Date: Fri, 28 Oct 2011 19:09:46 +0200 Message-ID: <87ipn911r9.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:56810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJpwG-0004j2-SA for emacs-orgmode@gnu.org; Fri, 28 Oct 2011 13:09:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJpwF-0003EX-3n for emacs-orgmode@gnu.org; Fri, 28 Oct 2011 13:09:52 -0400 Received: from mail-ey0-f169.google.com ([209.85.215.169]:52682) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJpwE-0003ET-QE for emacs-orgmode@gnu.org; Fri, 28 Oct 2011 13:09:51 -0400 Received: by eye4 with SMTP id 4so4217373eye.0 for ; Fri, 28 Oct 2011 10:09:49 -0700 (PDT) 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: Orgmode --=-=-= Content-Type: text/plain Dear list, Attached is a patch that allows some customization of tables in LaTeX export. It adds three new customizable with default values: org-export-latex-tables-tstart : nil org-export-latex-tables-hline : "\\hline" org-export-latex-tables-tend : nil These variables allows users to use e.g. the booktabs package (use \\toprule, \\midrule and \\bottomrule for the respective variables above - these are options you'll find in the defcustoms too) and create more beautiful tables in LaTeX documents. The patch also fixes the double rule after the table head when using a longtable environment, as this 1) is ugly and 2) caused booktabs longtables to go quite awry. The patch does - save for the longtable fix - bring no change to the export of existing code as long as the defaults are not changed. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-defcustoms-for-LaTeX-export-of-table-rules-tstar.patch Content-Description: [PATCH] to customize LaTeX output of tables (e.g. to use booktabs package) >From f2d9cf34b1b95c7e6941c8f9129ae9e32ba33444 Mon Sep 17 00:00:00 2001 From: Niels Giesen Date: Thu, 27 Oct 2011 09:23:16 +0200 Subject: [PATCH] Add defcustoms for LaTeX export of table rules :tstart, :hline and :tend Fix double rule in longtable. This allows users to use e.g. the booktabs package and create more beautiful tables in LaTeX documents. Also fix double headline rules when using a longtable environment, as this caused booktabs longtables to go quite awry. * lisp/org-latex.el: New defcustoms and default values: org-export-latex-tables-tstart : nil org-export-latex-tables-hline : "\\hline" org-export-latex-tables-tend : nil * lisp/org-table.el (orgtbl-to-generic): add check for :skipheadrule. When present, the :hline following the head will be skipped. This is necessary to avoid doubling of horizontal rules in LaTeX longtable environments and consequent width problems. --- lisp/org-latex.el | 38 ++++++++++++++++++++++++++++++++++---- lisp/org-table.el | 3 ++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/lisp/org-latex.el b/lisp/org-latex.el index 649e4a7..3e47359 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -369,6 +369,30 @@ When nil, grouping causes only separation lines between groups." :group 'org-export-latex :type 'boolean) +(defcustom org-export-latex-tables-tstart nil + "LaTeX command for top rule for tables." + :group 'org-export-latex + :type '(choice + (const :tag "Nothing" nil) + (string :tag "String") + (const :tag "Booktabs default: \\toprule" "\\toprule"))) + +(defcustom org-export-latex-tables-hline "\\hline" + "LaTeX command to use for a rule somewhere in the middle of a table." + :group 'org-export-latex + :type '(choice + (string :tag "String") + (const :tag "Standard: \\hline" "\\hline") + (const :tag "Booktabs default: \\midrule" "\\midrule"))) + +(defcustom org-export-latex-tables-tend nil + "LaTeX command for bottom rule for tables." + :group 'org-export-latex + :type '(choice + (const :tag "Nothing" nil) + (string :tag "String") + (const :tag "Booktabs default: \\bottomrule" "\\bottomrule"))) + (defcustom org-export-latex-low-levels 'itemize "How to convert sections below the current level of sectioning. This is specified by the `org-export-headline-levels' option or the @@ -1998,14 +2022,20 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." align)) (orgtbl-to-latex lines - `(:tstart nil :tend nil + `(:tstart ,org-export-latex-tables-tstart + :tend ,org-export-latex-tables-tend + :hline ,org-export-latex-tables-hline + :skipheadrule ,longtblp :hlend ,(if longtblp (format "\\\\ -\\hline +%s \\endhead -\\hline\\multicolumn{%d}{r}{Continued on next page}\\ +%s\\multicolumn{%d}{r}{Continued on next page}\\ \\endfoot -\\endlastfoot" (length org-table-last-alignment)) +\\endlastfoot" + org-export-latex-tables-hline + org-export-latex-tables-hline + (length org-table-last-alignment)) nil))) (if (not longtblp) (format "\n\\end{%s}" tabular-env)) (if longtblp "\n" (if org-export-latex-tables-centered diff --git a/lisp/org-table.el b/lisp/org-table.el index edcdbe1..247f585 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -4460,6 +4460,7 @@ directly by `orgtbl-send-table'. See manual." (let* ((splicep (plist-get params :splice)) (hline (plist-get params :hline)) + (skipheadrule (plist-get params :skipheadrule)) (remove-nil-linesp (plist-get params :remove-nil-lines)) (remove-newlines (plist-get params :remove-newlines)) (*orgtbl-hline* hline) @@ -4505,7 +4506,7 @@ directly by `orgtbl-send-table'. See manual." (*orgtbl-sep* (or (plist-get params :hlsep) *orgtbl-sep*)) (*orgtbl-fmt* (or (plist-get params :hfmt) *orgtbl-fmt*))) (orgtbl-format-section 'hline)) - (if hline (push hline *orgtbl-rtn*)) + (if (and hline (not skipheadrule)) (push hline *orgtbl-rtn*)) (pop *orgtbl-table*))) ;; Now format the main section. -- 1.7.4.1 --=-=-= Content-Type: text/plain Regards, Niels. -- http://pft.github.com/ --=-=-=--