From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christophe Rhodes Subject: Re: [PATCH] customize latex table export Date: Tue, 29 Nov 2011 17:44:26 +0000 Message-ID: <87fwh6escl.fsf@cantab.net> References: <87r57uyim9.fsf@cantab.net> <093BD03D-0067-44CD-BBCE-81A5D7B9FACC@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:59643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVRjf-0005GM-7v for emacs-orgmode@gnu.org; Tue, 29 Nov 2011 12:44:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RVRja-0003GV-Rx for emacs-orgmode@gnu.org; Tue, 29 Nov 2011 12:44:51 -0500 Received: from lo.gmane.org ([80.91.229.12]:51148) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVRja-0003Fx-8j for emacs-orgmode@gnu.org; Tue, 29 Nov 2011 12:44:46 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RVRjV-0005fa-T1 for emacs-orgmode@gnu.org; Tue, 29 Nov 2011 18:44:41 +0100 Received: from 81.174.155.115 ([81.174.155.115]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 29 Nov 2011 18:44:41 +0100 Received: from csr21 by 81.174.155.115 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 29 Nov 2011 18:44:41 +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 --=-=-= Carsten Dominik writes, a long time ago: > On May 19, 2011, at 2:34 PM, Christophe Rhodes wrote: > >> To produce documents in something approaching my organization's house >> style, I need to be able to style the headers of tables. It's nice that >> orgtbl has the functionality for this, but the call to orgtbl-to-latex >> has a hard-coded list of parameters with no possibility for extension. >> With the attached patch, I am able to put e.g. >> >> #+BIND: org-export-latex-tables-orgtbl-extra-parameters (:hfmt "\\multicolumn{1}{c}{\\bf\\color{white}\\cellcolor{blue}%s}") >> >> in the header of my document, and tables throughout the document all >> pick up this style. >> >> I daresay that this is not the optimal way of doing things; while this >> solves my immediate problem there is likely to be a more general way of >> doing things. > > would it be better to be able to set these parameters on a per-table basis with ATTR_LaTeX ? > Would you like to try to prepare a patch to this effect? Find attached a patch to this effect. It is the combination of two changes which I consider tiny: one is the support for hfmt itself as an ATTR_LaTeX attribute; the other is the consolidation of the word-matching on the attributes into local macros, which I needed because my use case (as above) includes the string "multicolumn", which was otherwise confusing the attribute parser into thinking that I needed a table* LaTeX environment. Please let me know if this suits better. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-hfmt-table-attribute-in-LaTeX-export.patch >From aba08346276e558fd7f6aa635e6f1e5081a2d3c3 Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Tue, 29 Nov 2011 17:30:14 +0000 Subject: [PATCH] hfmt table attribute in LaTeX export * org-latex.el (org-export-latex-tables): - new word-match and attr-match local macros to reduce boilerplate. (This is a tiny, mechanical change) - support hfmt LaTeX_ATTR attribute, and if given pass it through to orgtbl-to-latex. (This is a tiny change) --- lisp/org-latex.el | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lisp/org-latex.el b/lisp/org-latex.el index 2ec347a..aebfda5 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -1891,7 +1891,10 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." "\\end{verbatim}\n"))) (apply 'delete-region (list beg end)) (insert (org-export-latex-protect-string tbl))) - (progn + (macrolet ((word-match (string haystack) + `(string-match ,(format "\\(?:\\`\\|\\s-\\)%s\\(?:\\'\\|\\s-\\)" string) ,haystack)) + (attr-match (string) + `(and attr (stringp attr) (word-match ,string attr)))) (setq caption (org-find-text-property-in-string 'org-caption raw-table) shortn (org-find-text-property-in-string @@ -1901,26 +1904,22 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." label (org-find-text-property-in-string 'org-label raw-table) longtblp (and attr (stringp attr) - (string-match "\\" attr)) - tblenv (if (and attr (stringp attr) - (or (string-match (regexp-quote "table*") attr) - (string-match "\\" attr))) + (word-match "longtable" attr)) + tblenv (if (or (attr-match (regexp-quote "table*")) + (attr-match "multicolumn")) "table*" "table") tabular-env - (if (and attr (stringp attr) - (string-match "\\(tabular.\\)" attr)) + (if (attr-match "\\(tabular.\\)") (match-string 1 attr) org-export-latex-tabular-environment) - width (and attr (stringp attr) - (string-match "\\