emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] customize latex table export
@ 2011-05-19 12:34 Christophe Rhodes
  2011-05-24 11:02 ` Carsten Dominik
  0 siblings, 1 reply; 9+ messages in thread
From: Christophe Rhodes @ 2011-05-19 12:34 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-allow-customization-of-table-headers-in-latex-export.patch --]
[-- Type: text/x-diff, Size: 2040 bytes --]

From 68160f0c7c54309e76d882f871ad01a019e9acab Mon Sep 17 00:00:00 2001
From: Christophe Rhodes <csr21@cantab.net>
Date: Thu, 19 May 2011 13:20:43 +0100
Subject: [PATCH 2/2] allow customization of table headers in latex export

* lisp/org-latex.el (org-export-latex-tables-orgtbl-extra-parameters): New
variable.
(org-export-latex-tables): Use it in call to orgtbl-to-latex.
---
 lisp/org-latex.el |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index 516ee12..243cf84 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -325,6 +325,11 @@ When nil, grouping causes only separation lines between groups."
   :group 'org-export-latex
   :type 'boolean)
 
+(defcustom org-export-latex-tables-orgtbl-extra-parameters nil
+  "Extra parameters to pass to orgtbl-to-latex."
+  :group 'org-export-latex
+  :type 'plist)
+
 (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
@@ -1929,15 +1934,16 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 				    align))
                         (orgtbl-to-latex
                          lines
-                         `(:tstart nil :tend nil
-                                   :hlend ,(if longtblp
-                                               (format "\\\\
+			 (append org-export-latex-tables-orgtbl-extra-parameters
+				 `(:tstart nil :tend nil
+					   :hlend ,(if longtblp
+						       (format "\\\\
 \\hline
 \\endhead
 \\hline\\multicolumn{%d}{r}{Continued on next page}\\
 \\endfoot
 \\endlastfoot" (length org-table-last-alignment))
-                                             nil)))
+						     nil))))
                         (if (not longtblp) (format "\n\\end{%s}" tabular-env))
                         (if longtblp "\n" (if org-export-latex-tables-centered
                                               "\n\\end{center}\n" "\n"))
-- 
1.7.2.5


[-- Attachment #3: Type: text/plain, Size: 19 bytes --]


Best,

Christophe

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] customize latex table export
  2011-05-19 12:34 [PATCH] customize latex table export Christophe Rhodes
@ 2011-05-24 11:02 ` Carsten Dominik
  2011-11-29 17:44   ` Christophe Rhodes
  0 siblings, 1 reply; 9+ messages in thread
From: Carsten Dominik @ 2011-05-24 11:02 UTC (permalink / raw)
  To: Christophe Rhodes; +Cc: emacs-orgmode

Hi Christophe,

On May 19, 2011, at 2:34 PM, Christophe Rhodes wrote:

> Hi,
> 
> 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?

- Carsten

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] customize latex table export
  2011-05-24 11:02 ` Carsten Dominik
@ 2011-11-29 17:44   ` Christophe Rhodes
  2011-12-02  9:59     ` Niels Giesen
  2011-12-07 15:43     ` Christophe Rhodes
  0 siblings, 2 replies; 9+ messages in thread
From: Christophe Rhodes @ 2011-11-29 17:44 UTC (permalink / raw)
  To: emacs-orgmode

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

Carsten Dominik <carsten.dominik@gmail.com> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-hfmt-table-attribute-in-LaTeX-export.patch --]
[-- Type: text/x-diff, Size: 3545 bytes --]

From aba08346276e558fd7f6aa635e6f1e5081a2d3c3 Mon Sep 17 00:00:00 2001
From: Christophe Rhodes <csr21@cantab.net>
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 "\\<longtable\\>" attr))
-		  tblenv (if (and attr (stringp attr)
-				  (or (string-match (regexp-quote "table*") attr)
-				      (string-match "\\<multicolumn\\>" 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 "\\<width=\\([^ \t\n\r]+\\)" attr)
+		  width (and (attr-match "width=\\(\\S-+\\)")
                              (match-string 1 attr))
-                  align (and attr (stringp attr)
-                             (string-match "\\<align=\\([^ \t\n\r]+\\)" attr)
+                  align (and (attr-match "align=\\(\\S-+\\)")
                              (match-string 1 attr))
+		  hfmt (and (attr-match "hfmt=\\(\\S-+\\)")
+			    (match-string 1 attr))
                   floatp (or caption label (string= "table*" tblenv))
-		  placement     (if (and attr
-					 (stringp attr)
-					 (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
+		  placement     (if (attr-match "placement=\\(\\S-+\\)")
 				    (match-string 1 attr)
 				  (concat
 				   "[" org-latex-default-figure-position "]")))
@@ -1999,6 +1998,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
                         (orgtbl-to-latex
                          lines
                          `(:tstart nil :tend nil
+				   ,@(and hfmt `(:hfmt ,hfmt))
                                    :hlend ,(if longtblp
                                                (format "\\\\
 \\hline
-- 
1.7.7.1


[-- Attachment #3: Type: text/plain, Size: 12 bytes --]


Christophe

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] customize latex table export
  2011-11-29 17:44   ` Christophe Rhodes
@ 2011-12-02  9:59     ` Niels Giesen
  2011-12-02 10:21       ` Christophe Rhodes
  2011-12-07 15:43     ` Christophe Rhodes
  1 sibling, 1 reply; 9+ messages in thread
From: Niels Giesen @ 2011-12-02  9:59 UTC (permalink / raw)
  To: Christophe Rhodes; +Cc: emacs-orgmode

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

Hi Christophe,

Could you provide us with a minimal example of how this new functionality
can be used?

I am trying to test it and see if there are any conflicts with my patch of
late to supports the booktabs package @
http://patchwork.newartisans.com/patch/1016/  (aside from one of the two
patches not applying without some minor human intervention around line
1998).

Besides that, it would in general be good to have an example for
documentation purposes.

On Tue, Nov 29, 2011 at 6:44 PM, Christophe Rhodes <csr21@cantab.net> wrote:

> Carsten Dominik <carsten.dominik@gmail.com> 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.
>
>
>
> Christophe
>
>


-- 
http://pft.github.com

[-- Attachment #2: Type: text/html, Size: 2903 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] customize latex table export
  2011-12-02  9:59     ` Niels Giesen
@ 2011-12-02 10:21       ` Christophe Rhodes
  0 siblings, 0 replies; 9+ messages in thread
From: Christophe Rhodes @ 2011-12-02 10:21 UTC (permalink / raw)
  To: emacs-orgmode

Niels Giesen <niels.giesen@gmail.com> writes:

> Could you provide us with a minimal example of how this new functionality
> can be used?

Sure, sorry.  Here we go:

--- start here ---
#+TITLE: Example of using hfmt
#+AUTHOR: Christophe Rhodes

* Introduction
  This document shows the use of the =hfmt= tag in =#+LaTeX_ATTR=
  lines to customize table headings.  Analgous functionality is
  available in HTML export by customizing the style of =th= tags.
* Example table

#+ATTR_LaTeX: hfmt=\multicolumn{1}{c}{\textbf{%s}}
| table       | headings  |
|-------------+-----------|
| body        | cells     |
| have        | unchanged |
| formatting. |           |
---  end here  ---

> I am trying to test it and see if there are any conflicts with my patch of
> late to supports the booktabs package @
> http://patchwork.newartisans.com/patch/1016/  (aside from one of the two
> patches not applying without some minor human intervention around line
> 1998).

Apart from the code conflict itself, I don't see why it shouldn't work:
this patch only changes the export of individual cells, while the
booktabs one alters the export of lines :-).  Your patch took the
approach I originally took too, with a customization variable; Carsten
(in May, aeons ago) suggested that an attribute might be preferable,
which is why I've reworked it in this way.  (It might be sensible for my
patch to have a configuration variable so that there could be a
document-wide default, too; I don't know whether it would be sensible
for yours to be customizeable using ATTR_LaTeX...

> Besides that, it would in general be good to have an example for
> documentation purposes.

I hope this helps,

Christophe

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] customize latex table export
  2011-11-29 17:44   ` Christophe Rhodes
  2011-12-02  9:59     ` Niels Giesen
@ 2011-12-07 15:43     ` Christophe Rhodes
  2011-12-14  9:01       ` Christophe Rhodes
  1 sibling, 1 reply; 9+ messages in thread
From: Christophe Rhodes @ 2011-12-07 15:43 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Christophe Rhodes <csr21@cantab.net> writes:

> Carsten Dominik <carsten.dominik@gmail.com> writes, a long time ago:
>
>>
>> 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.

Is there anything else that I can do to encourage this patch into the
upstream org-mode?

Thanks,

Christophe

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] customize latex table export
  2011-12-07 15:43     ` Christophe Rhodes
@ 2011-12-14  9:01       ` Christophe Rhodes
  2011-12-14 10:19         ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Christophe Rhodes @ 2011-12-14  9:01 UTC (permalink / raw)
  To: emacs-orgmode

Christophe Rhodes <csr21@cantab.net> writes:

> Christophe Rhodes <csr21@cantab.net> writes:
>
>> Carsten Dominik <carsten.dominik@gmail.com> writes, a long time ago:
>>
>>>
>>> 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.
>
> Is there anything else that I can do to encourage this patch into the
> upstream org-mode?

Again, is there anything more I can do to get this functionality
(customizing header lines of tables in LaTeX export, in case everyone
has lost the context) into org-mode?

Best,

Christophe

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] customize latex table export
  2011-12-14  9:01       ` Christophe Rhodes
@ 2011-12-14 10:19         ` Bastien
  2012-04-23 12:59           ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2011-12-14 10:19 UTC (permalink / raw)
  To: Christophe Rhodes; +Cc: emacs-orgmode

Hi Christophe,

Christophe Rhodes <csr21@cantab.net> writes:

> Again, is there anything more I can do to get this functionality
> (customizing header lines of tables in LaTeX export, in case everyone
> has lost the context) into org-mode?

I saw your patch, thanks for it.

I'm willing to apply it, but I will do when I have a good idea of how it
interacts with Niels proposal, and maybe a generalization of Niels idea,
where it would be possible to set a default #+ATTR for tables, images,
etc.

Best,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] customize latex table export
  2011-12-14 10:19         ` Bastien
@ 2012-04-23 12:59           ` Bastien
  0 siblings, 0 replies; 9+ messages in thread
From: Bastien @ 2012-04-23 12:59 UTC (permalink / raw)
  To: Christophe Rhodes; +Cc: emacs-orgmode

Hi Christophe,

Bastien <bzg@altern.org> writes:

> Hi Christophe,
>
> Christophe Rhodes <csr21@cantab.net> writes:
>
>> Again, is there anything more I can do to get this functionality
>> (customizing header lines of tables in LaTeX export, in case everyone
>> has lost the context) into org-mode?
>
> I saw your patch, thanks for it.
>
> I'm willing to apply it, but I will do when I have a good idea of how it
> interacts with Niels proposal, and maybe a generalization of Niels idea,
> where it would be possible to set a default #+ATTR for tables, images,
> etc.

I applied an updated version of your patch, without macrolet.

Thanks for your patchience*,

* The ability to wait for a patch to be applied.

-- 
 Bastien

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-04-23 13:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-19 12:34 [PATCH] customize latex table export Christophe Rhodes
2011-05-24 11:02 ` Carsten Dominik
2011-11-29 17:44   ` Christophe Rhodes
2011-12-02  9:59     ` Niels Giesen
2011-12-02 10:21       ` Christophe Rhodes
2011-12-07 15:43     ` Christophe Rhodes
2011-12-14  9:01       ` Christophe Rhodes
2011-12-14 10:19         ` Bastien
2012-04-23 12:59           ` Bastien

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).