From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: allow table* specification with #+ATTR_LaTeX: Date: Thu, 16 Dec 2010 17:57:59 -0700 Message-ID: <874oadxlk8.fsf@gmail.com> References: <8739pyraaq.fsf@cs.unm.edu> <49811CBB-F1B1-4031-B26D-A7E9709F1661@tsdye.com> <87aak5q29i.fsf@gmail.com> <87oc8ln5gn.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=59840 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PTOeA-000599-Js for emacs-orgmode@gnu.org; Thu, 16 Dec 2010 19:58:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PTOe8-00066J-E4 for emacs-orgmode@gnu.org; Thu, 16 Dec 2010 19:58:10 -0500 Received: from mail-vw0-f41.google.com ([209.85.212.41]:40572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PTOe8-000662-5n for emacs-orgmode@gnu.org; Thu, 16 Dec 2010 19:58:08 -0500 Received: by vws10 with SMTP id 10so60412vws.0 for ; Thu, 16 Dec 2010 16:58:07 -0800 (PST) In-Reply-To: (Thomas S. Dye's message of "Thu, 16 Dec 2010 05:42:48 -1000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "Thomas S. Dye" Cc: Org Mode --=-=-= Content-Type: text/plain Hi Tom, Thanks for the pointer, how about this revised version of the patch. It takes the following inputs #+begin_src org #+CAPTION: A wide table with tabulary #+LABEL: tbl:wide #+ATTR_LaTeX: table* tabulary[\textwidth] align=l|lp{3cm}r|l | 1 | 2 | 3 | | 4 | 5 | 6 | #+CAPTION: A normal table with tabularx #+LABEL: tbl:wide #+ATTR_LaTeX: table tabularx[\textwidth] align=l|lp{3cm}r|l | 1 | 2 | 3 | | 4 | 5 | 6 | #+end_src and yields the following output #+begin_src latex \begin{table*}[htb] \caption{A wide table with tabulary} \label{tbl:wide} \begin{center} \begin{tabulary}{\textwidth}{l|lp{3cm}r|l} 1 & 2 & 3 \\ 4 & 5 & 6 \\ \end{tabulary} \end{center} \end{table*} \begin{table}[htb] \caption{A normal table with tabularx} \label{tbl:wide} \begin{center} \begin{tabularx}{\textwidth}{l|lp{3cm}r|l} 1 & 2 & 3 \\ 4 & 5 & 6 \\ \end{tabularx} \end{center} \end{table} #+end_src I'm not sure about the square bracket syntax, maybe curly would be preferable. Definitely open to suggestions. Should this be applied? Are there any obvious areas for improvement? Thanks -- Eric --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=tables.patch diff --git a/lisp/org-latex.el b/lisp/org-latex.el index a261171..af0a15d 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -1741,7 +1741,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (org-table-last-column-widths (copy-sequence org-table-last-column-widths)) fnum fields line lines olines gr colgropen line-fmt align - caption shortn label attr floatp placement longtblp) + caption shortn label attr floatp placement longtblp tblenv) (if org-export-latex-tables-verbatim (let* ((tbl (concat "\\begin{verbatim}\n" raw-table "\\end{verbatim}\n"))) @@ -1758,6 +1758,16 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." 'org-label raw-table) longtblp (and attr (stringp attr) (string-match "\\" attr)) + tblenv (if (and attr (stringp attr) + (string-match (regexp-quote "table*") attr)) + "table*" "table") + org-export-latex-tabular-environment + (progn + (message "attr:%s" attr) + (if (and attr (stringp attr) + (string-match "\\(tabular.*\\)\\[\\(.+\\)\\]" attr)) + (list (match-string 1 attr) (match-string 2 attr)) + org-export-latex-tabular-environment)) align (and attr (stringp attr) (string-match "\\ writes: > Hi Eric, > > The syntax for tabularx and tabulary includes a width specification > that is a required argument: > > \begin{tabulary}{}{} ... \end{tabulary} > \begin{tabularx}{}{} ... \end{tabularx} > > This is typically set to something like \linewidth, \colwidth, or > \textwidth, but might also take an absolute length like 250pt, 5in, > etc. > > All the best, > Tom > > On Dec 16, 2010, at 4:43 AM, Eric Schulte wrote: > >> The attached patch implements the behavior described previously, so >> for >> example the following org >> >> #+begin_src org >> #+CAPTION: A wide table with tabulary >> #+LABEL: tbl:wide >> #+ATTR_LaTeX: table* tabulary align=l|lp{3cm}r|l >> | 1 | 2 | 3 | >> | 4 | 5 | 6 | >> >> #+CAPTION: A normal table with tabularx >> #+LABEL: tbl:wide >> #+ATTR_LaTeX: table tabularx align=l|lp{3cm}r|l >> | 1 | 2 | 3 | >> | 4 | 5 | 6 | >> #+end_src >> >> exports to the following latex >> >> #+begin_src latex >> \begin{table*}[htb] >> \caption{A wide table with tabulary} \label{tbl:wide} >> \begin{center} >> \begin{tabulary}{l|lp{3cm}r|l} >> 1 & 2 & 3 \\ >> 4 & 5 & 6 \\ >> \end{tabulary} >> \end{center} >> \end{table*} >> >> >> \begin{table}[htb] >> \caption{A normal table with tabularx} \label{tbl:wide} >> \begin{center} >> \begin{tabularx}{l|lp{3cm}r|l} >> 1 & 2 & 3 \\ >> 4 & 5 & 6 \\ >> \end{tabularx} >> \end{center} >> \end{table} >> #+end_src >> >> Does this behavior and patch look reasonable? If I don't hear by the >> end of the day I will apply this patch, I just wanted to check first >> on >> list as the export mechanisms aren't my personal area of expertise. >> >> Thanks -- Eric >> >> diff --git a/lisp/org-latex.el b/lisp/org-latex.el >> index a261171..66541de 100644 >> --- a/lisp/org-latex.el >> +++ b/lisp/org-latex.el >> @@ -1741,7 +1741,7 @@ The conversion is made depending of STRING- >> BEFORE and STRING-AFTER." >> (org-table-last-column-widths (copy-sequence >> org-table-last-column- >> widths)) >> fnum fields line lines olines gr colgropen line-fmt align >> - caption shortn label attr floatp placement longtblp) >> + caption shortn label attr floatp placement longtblp >> tblenv tblrenv) >> (if org-export-latex-tables-verbatim >> (let* ((tbl (concat "\\begin{verbatim}\n" raw-table >> "\\end{verbatim}\n"))) >> @@ -1758,6 +1758,15 @@ The conversion is made depending of STRING- >> BEFORE and STRING-AFTER." >> 'org-label raw-table) >> longtblp (and attr (stringp attr) >> (string-match "\\" attr)) >> + tblenv (if (and attr (stringp attr) >> + (string-match (regexp-quote "table*") attr)) >> + "table*" "table") >> + org-export-latex-tabular-environment >> + (if (and attr (stringp attr) >> + (string-match (regexp-quote "tabularx") attr)) >> + "tabularx" >> + (if (string-match (regexp-quote "tabulary") attr) >> + "tabulary" org-export-latex-tabular-environment)) >> align (and attr (stringp attr) >> (string-match "\\> \)" attr) >> (match-string 1 attr)) >> @@ -1821,7 +1830,8 @@ The conversion is made depending of STRING- >> BEFORE and STRING-AFTER." >> (concat >> (if longtblp >> (concat "\\begin{longtable}{" align "}\n") >> - (if floatp (format "\\begin{table}%s\n" >> placement))) >> + (if floatp >> + (format "\\begin{%s}%s\n" tblenv placement))) >> (if floatp >> (format >> "\\caption%s{%s} %s" >> @@ -1852,7 +1862,7 @@ The conversion is made depending of STRING- >> BEFORE and STRING-AFTER." >> "\n\\end{center}\n" >> "\n")) >> (if longtblp >> "\\end{longtable}" >> - (if floatp "\\end{table}")))) >> + (if floatp (format "\\end{%s}" tblenv))))) >> "\n\n")))))))) >> >> (defun org-export-latex-convert-table.el-table () >> >> "Eric Schulte" writes: >> >>> Hi Tom, >>> >>> Thanks for the informative list. I had no idea LaTeX supported so >>> many >>> table options. How about I update the patch so that is supports the >>> following sets of mutually exclusive options... >>> - longtable :: wraps the table in a longtable with no table or >>> tabular >>> wrappers -- already implemented >>> - table* :: replaces =table= wrapper with =table*= wrapper, >>> contains an >>> inner tabular wrapper >>> - tabular[xy] :: specifies the inner tabular wrapping environment, >>> only >>> one can be specified >>> >>> so for example, the following >>> >>> #+begin_src org >>> #+CAPTION: A wide table >>> #+LABEL: tbl:wide >>> #+ATTR_LaTeX: table* tabulary align=l|lp{3cm}r|l >>> | ... | ... | >>> | ... | ... | >>> #+end_src >>> >>> results in the following >>> >>> #+begin_src latex >>> \begin{table*}[htb] >>> \caption{A wide table} \label{tbl:wide} >>> \begin{center} >>> \begin{tabulary}{l|lp{3cm}r|l} >>> 1 & 2 & 3 \\ >>> 4 & 5 & 6 \\ >>> \end{tabulary} >>> \end{center} >>> \end{table*} >>> #+end_src >>> >>> Then the next question would be how to insert a =figure*= instead >>> of a >>> simple =figure= environment. >>> >>> Thanks -- Eric >>> >>> Thomas S. Dye writes: >>> >>>> Hi Eric, >>>> >>>> It would be great to have a more general solution. Tables are >>>> hard to >>>> typeset, so it might take a while to come up with a good >>>> specification. Here is what I know about the LaTeX side of things. >>>> >>>> ** LaTeX destinations for an Org-mode table >>>> *** Environments for typesetting a table >>>> - table placed in the output where it occurs in the input >>>> - all of these environments can be used on their own >>>> **** tabular >>>> standard LaTeX environment, doesn't break across pages, no >>>> caption >>>> **** tabularx >>>> extended environment that can automatically calculate column >>>> widths and wrap text within table cells, doesn't break across >>>> pages, no caption >>>> **** tabulary >>>> like tabularx, but tries harder to come up with optimal column >>>> widths >>>> **** supertabular >>>> extended tabular environment that breaks across pages, includes >>>> caption >>>> **** supertabular* >>>> like supertabular, but for wide tables in a multicolumn page >>>> layout >>>> **** mpsupertabular >>>> like supertabular, but also handles footnotes within the table >>>> **** mpsupertabular* >>>> like mpsupertabular, but for multicolumn page layouts >>>> **** longtable >>>> extended tabular environment that breaks across pages and >>>> includes a caption, but can't be used in a multicolumn page >>>> layout >>>> *** Environment for floating a table and adding a caption >>>> floats a table typeset by some other environment to a place in >>>> the >>>> output that LaTeX determines appropriate, probably not where it >>>> occurs in the input >>>> **** =table=, single column document >>>> typically wraps a =tabular=, =tabularx=, or =tabulary= >>>> environment >>>> **** =table*=, multi-column document >>>> typically wraps a =tabular=, =tabularx=, or =tabulary= >>>> environment >>>> *** "Typical" uses >>>> In our report production work we regularly use seven setups: >>>> - table or table* wrapped around tabularx or tabular >>>> - longtable >>>> - tabular or tabularx on their own >>>> >>>> hth, >>>> Tom >>>> On Dec 15, 2010, at 11:33 AM, Eric Schulte wrote: >>>> >>>>> Hi, >>>>> >>>>> The attached patch allows the use of table* latex tables from >>>>> within >>>>> Org >>>>> mode documents using the attr_latex lines, for example >>>>> >>>>> #+CAPTION: A wide table >>>>> #+LABEL: tbl:wide >>>>> #+ATTR_LaTeX: table* align=l|lp{3cm}r|l >>>>> | ... | ... | >>>>> | ... | ... | >>>>> >>>>> Should this be added, or should we put together a more general >>>>> solution >>>>> for different types of table environments? Currently only >>>>> longtable >>>>> is >>>>> supported. Also, is there already a way to do this that I have >>>>> missed? >>>>> >>>>> Thanks -- Eric >>>>> >>>>> diff --git a/lisp/org-latex.el b/lisp/org-latex.el >>>>> index a261171..b7f48d3 100644 >>>>> --- a/lisp/org-latex.el >>>>> +++ b/lisp/org-latex.el >>>>> @@ -1741,7 +1741,7 @@ The conversion is made depending of STRING- >>>>> BEFORE and STRING-AFTER." >>>>> (org-table-last-column-widths (copy-sequence >>>>> org-table-last-column- >>>>> widths)) >>>>> fnum fields line lines olines gr colgropen line-fmt >>>>> align >>>>> - caption shortn label attr floatp placement longtblp) >>>>> + caption shortn label attr floatp placement longtblp >>>>> tblenv) >>>>> (if org-export-latex-tables-verbatim >>>>> (let* ((tbl (concat "\\begin{verbatim}\n" raw-table >>>>> "\\end{verbatim}\n"))) >>>>> @@ -1758,6 +1758,9 @@ The conversion is made depending of STRING- >>>>> BEFORE and STRING-AFTER." >>>>> 'org-label raw-table) >>>>> longtblp (and attr (stringp attr) >>>>> (string-match "\\" >>>>> attr)) >>>>> + tblenv (if (and attr (stringp attr) >>>>> + (string-match (regexp-quote "table*") attr)) >>>>> + "table*" "table") >>>>> align (and attr (stringp attr) >>>>> (string-match "\\>>>> \)" attr) >>>>> (match-string 1 attr)) >>>>> @@ -1821,7 +1824,8 @@ The conversion is made depending of STRING- >>>>> BEFORE and STRING-AFTER." >>>>> (concat >>>>> (if longtblp >>>>> (concat "\\begin{longtable}{" align "} >>>>> \n") >>>>> - (if floatp (format "\\begin{table}%s\n" >>>>> placement))) >>>>> + (if floatp >>>>> + (format "\\begin{%s}%s\n" tblenv placement))) >>>>> (if floatp >>>>> (format >>>>> "\\caption%s{%s} %s" >>>>> @@ -1852,7 +1856,7 @@ The conversion is made depending of STRING- >>>>> BEFORE and STRING-AFTER." >>>>> "\n\\end{center}\n" >>>>> "\n")) >>>>> (if longtblp >>>>> "\\end{longtable}" >>>>> - (if floatp "\\end{table}")))) >>>>> + (if floatp (format "\\end{%s}" >>>>> tblenv))))) >>>>> "\n\n")))))))) >>>>> >>>>> (defun org-export-latex-convert-table.el-table () >>>>> _______________________________________________ >>>>> Emacs-orgmode mailing list >>>>> Please use `Reply All' to send replies to the list. >>>>> Emacs-orgmode@gnu.org >>>>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--