emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org->odt/html table export: adjusting default behaviour?
@ 2011-08-25 15:12 Matt Price
  2011-08-25 15:36 ` Matt Price
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Matt Price @ 2011-08-25 15:12 UTC (permalink / raw)
  To: Org Mode, Jambunathan K

The attached test file shows  an org file with tables whose columns
include substantial amounts of text.  The default export to odt is
pretty ugly in this case, and even in html (where things work to some
extent) I would rather be able to control to some extent the way that
long fields wrap.  is there a recommended way to do set values like
table and column width for these two exports? I guess I am
particularly concerned with the odt export -- can I e.g. adjust a
default value somewhere in the styles.xml file? I doubt the problem
will be easily solved but if someone can point me in the right
direction I'd really appreciate it.

thanks,
Matt

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

* Re: org->odt/html table export: adjusting default behaviour?
  2011-08-25 15:12 org->odt/html table export: adjusting default behaviour? Matt Price
@ 2011-08-25 15:36 ` Matt Price
  2011-08-25 21:40 ` Jambunathan K
  2011-08-25 22:01 ` org->odt/html table export: adjusting default behaviour? Jambunathan K
  2 siblings, 0 replies; 10+ messages in thread
From: Matt Price @ 2011-08-25 15:36 UTC (permalink / raw)
  To: Org Mode, Jambunathan K

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

this time I've actually attached the file...

On Thu, Aug 25, 2011 at 11:12 AM, Matt Price <moptop99@gmail.com> wrote:
> The attached test file shows  an org file with tables whose columns
> include substantial amounts of text.  The default export to odt is
> pretty ugly in this case, and even in html (where things work to some
> extent) I would rather be able to control to some extent the way that
> long fields wrap.  is there a recommended way to do set values like
> table and column width for these two exports? I guess I am
> particularly concerned with the odt export -- can I e.g. adjust a
> default value somewhere in the styles.xml file? I doubt the problem
> will be easily solved but if someone can point me in the right
> direction I'd really appreciate it.
>
> thanks,
> Matt
>

[-- Attachment #2: test.org --]
[-- Type: application/octet-stream, Size: 4394 bytes --]

#+TITLE:     test.org
#+AUTHOR:    Matt Price
#+EMAIL:     matt.price@utoronto.ca
#+DATE:      2011-08-23 Tue
#+DESCRIPTION:
#+KEYWORDS:
#+LANGUAGE:  en
#+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS:   TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+LINK_UP:   
#+LINK_HOME: 
#+XSLT:

* heading1

** heading2
| table | 1 | 2 |
|       |   |   |
** heading2 -2
some text.
* Outline

| Week | Date       | Topic                          | Description                         | Tech Topics               | Assignments               | Readings | Notes                               |
|------+------------+--------------------------------+-------------------------------------+---------------------------+---------------------------+----------+-------------------------------------|
|      |            | <30>                           | <35>                                | <25>                      | <25>                      |          | <35>                                |
|    1 | 9/12/2011  | Intro:What is History For?     | The uses of history; engagement and objectivity; etc | Intro to Website          | --                        |          |                                     |
|    2 | 9/19/2011  | History and the Public Sphere  | "What is the Public Sphere, & what role does history play in it?" | HTML Workshop             |                           |          |                                     |
|    3 | 9/26/2011  | What is the Canadian Public Sphere | "Multiculturalism, Immigration, and National Identity as questions of mediality" |                           |                           |          |                                     |
|    4 | 10/3/2011  | History From Below             | "History from below,' oral history, & implications for the practice of history" | Audio Workshop            | Oral History Interview    |          |                                     |
|    6 | 10/10/2011 | Th Wisdom of the Crowd?        | "Crowdsourcing, Wikipedia, Citizen Science & Collaborative history" | Collective Bibliographies | Zotero Assignment         |          | Transcription of Interview          |
|    5 | 10/17/2011 | Language of The Web            | From Memex to HTML5; the Web as a Utopian project | google maps/jsbin workshop? maybe not. |                           |          | Visits to Archive                   |
|    7 | 10/24/2011 | Engaged History                |                                     |                           |                           |          | Background Research                 |
|    8 | 10/31/2011 | Recursive Publics              | Open Source/Open Access/Open standards | Timelines                 | Timeline Assignment -- needs a lab |          | Open Access Week. Peer review of audio stories. |
|    9 | 11/7/2011  | Information Abundance          |                                     |                           |                           |          |                                     |
|   10 | 11/14/2011 | Thinking with Pictures         | Maps and the visual Representation of Information | GIS                       | GIS Assignment            |          |                                     |
|   11 | 11/21/2011 | Making Sense of copyright      |                                     |                           |                           |          |                                     |
|   12 | 11/28/2011 | Digital Divides                |                                     |                           |                           |          |                                     |
|   13 | 12/5/2011  | Review                         |                                     |                           | Final Assignment          |          |                                     |
|      |            | Authorship                     |                                     |                           |                           |          |                                     |
|      |            |                                |                                     |                           |                           |          |                                     |

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

* Re: org->odt/html table export: adjusting default behaviour?
  2011-08-25 15:12 org->odt/html table export: adjusting default behaviour? Matt Price
  2011-08-25 15:36 ` Matt Price
@ 2011-08-25 21:40 ` Jambunathan K
  2011-08-26 14:24   ` Matt Price
  2011-09-14  9:56   ` [odt] Support for table templates (was Re: org->odt/html table export: adjusting default behaviour?) Jambunathan K
  2011-08-25 22:01 ` org->odt/html table export: adjusting default behaviour? Jambunathan K
  2 siblings, 2 replies; 10+ messages in thread
From: Jambunathan K @ 2011-08-25 21:40 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

Matt Price <moptop99@gmail.com> writes:

> The attached test file shows  an org file with tables whose columns
> include substantial amounts of text.  The default export to odt is
> pretty ugly in this case, and even in html (where things work to some
> extent) I would rather be able to control to some extent the way that
> long fields wrap.  is there a recommended way to do set values like
> table and column width for these two exports? I guess I am
> particularly concerned with the odt export -- can I e.g. adjust a
> default value somewhere in the styles.xml file? I doubt the problem
> will be easily solved but if someone can point me in the right
> direction I'd really appreciate it.

The issue is not that fields don't wrap well but that the table is big
for the width of the paper and columns are as a result getting
congested.

I have pushed a fix whereby tables now occupy bigger space [1]. 

I also noticed that columns are unevenly spaced. Now I have updated the
styles so that columns are equally spaced [2].

Orgmode exporters can never be layout engines. They are also typically
useful for personal (as opposed to professional) production. In some
sense they are good for handouts, pamphlets and drafts etc. So some
amount of hand fixing and finer adjustments would always be required. 

You choose a smaller font for text in the table with:

F11->Paragraph Styles->OrgTableContents->Choose a smaller (say 10 pt)
   font.

This will affect the text in all the tables.

For the sake of documentation,

Vertical and horizontal grid lines in the exported table correspond to
colgroups (specified in table cookie lines) and by horizontal rulers in
the org table [3]. You can use these grid lines in the Org file and
automatically the exporter will create the grid lines for you.

If you need really prettier tables you can rely on Table->Autoformat.

Footnotes: 
[1] So there is now a reverse problem of tables with less number of
columns and not having copious text looking too big. But big is better
even if it is ugly.

The workaround is to rely on Table Properties->Table->Width

[2] Pre-processor in org-exp.el groks l, r, c cookies but ignores the
colwidth directives. With some changes these colwidth directives could
be used for controlling the relative width of columns on a per-table
basis. This has to wait. If there is sufficient demand I can consider
adding this support.

The workaround is to rely on Table Properties->Columns->Column Width

[3] The exporter wouldn't still create vertical lines on the extreme
ends. I believe the default style of tables is so selected based on some
standard styling manual. 

-- 

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

* Re: org->odt/html table export: adjusting default behaviour?
  2011-08-25 15:12 org->odt/html table export: adjusting default behaviour? Matt Price
  2011-08-25 15:36 ` Matt Price
  2011-08-25 21:40 ` Jambunathan K
@ 2011-08-25 22:01 ` Jambunathan K
  2011-08-26 14:13   ` Matt Price
  2 siblings, 1 reply; 10+ messages in thread
From: Jambunathan K @ 2011-08-25 22:01 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

Matt Price <moptop99@gmail.com> writes:

> The attached test file shows  an org file with tables whose columns
> include substantial amounts of text.  The default export to odt is
> pretty ugly in this case, and even in html (where things work to some
> extent) I would rather be able to control to some extent the way that
> long fields wrap.  is there a recommended way to do set values like
> table and column width for these two exports? I guess I am
> particularly concerned with the odt export -- can I e.g. adjust a
> default value somewhere in the styles.xml file? I doubt the problem
> will be easily solved but if someone can point me in the right
> direction I'd really appreciate it.

If you are creating big tables a better alternative would be to create
ods/xls spreadsheets from Orgmode tables. So

1. Export the table to csv format using M-x org-table-export RET etc etc
2. C-x C-f test.csv
3. C-u M-x org-lparse-convert RET 

4. When prompted for output format use TAB for completion to see the
   available formats. Pick ods or xls. (Hint: For a superior completion
   experience enable ido mode)

5. You will see the ods file opening up automagically under writer. (If
   you have not used C-u in step 4, only conversion will happen. The
   resulting file will not be opened)

Jambunathan K.

-- 

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

* Re: org->odt/html table export: adjusting default behaviour?
  2011-08-25 22:01 ` org->odt/html table export: adjusting default behaviour? Jambunathan K
@ 2011-08-26 14:13   ` Matt Price
  0 siblings, 0 replies; 10+ messages in thread
From: Matt Price @ 2011-08-26 14:13 UTC (permalink / raw)
  To: Matt Price, Org Mode

On Thu, Aug 25, 2011 at 6:01 PM, Jambunathan K <kjambunathan@gmail.com> wrote:
> Matt Price <moptop99@gmail.com> writes:
>
>> The attached test file shows  an org file with tables whose columns
>> include substantial amounts of text.  The default export to odt is
>> pretty ugly in this case, and even in html (where things work to some
>> extent) I would rather be able to control to some extent the way that
>> long fields wrap.  is there a recommended way to do set values like
>> table and column width for these two exports? I guess I am
>> particularly concerned with the odt export -- can I e.g. adjust a
>> default value somewhere in the styles.xml file? I doubt the problem
>> will be easily solved but if someone can point me in the right
>> direction I'd really appreciate it.
>
> If you are creating big tables a better alternative would be to create
> ods/xls spreadsheets from Orgmode tables. So
>
> 1. Export the table to csv format using M-x org-table-export RET etc etc
> 2. C-x C-f test.csv
> 3. C-u M-x org-lparse-convert RET
>
> 4. When prompted for output format use TAB for completion to see the
>   available formats. Pick ods or xls. (Hint: For a superior completion
>   experience enable ido mode)
>
> 5. You will see the ods file opening up automagically under writer. (If
>   you have not used C-u in step 4, only conversion will happen. The
>   resulting file will not be opened)

that's great, thanks J.
Matt

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

* Re: org->odt/html table export: adjusting default behaviour?
  2011-08-25 21:40 ` Jambunathan K
@ 2011-08-26 14:24   ` Matt Price
  2011-08-28 22:33     ` Jambunathan K
  2011-09-14  9:56   ` [odt] Support for table templates (was Re: org->odt/html table export: adjusting default behaviour?) Jambunathan K
  1 sibling, 1 reply; 10+ messages in thread
From: Matt Price @ 2011-08-26 14:24 UTC (permalink / raw)
  To: Matt Price, Org Mode

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

On Thu, Aug 25, 2011 at 5:40 PM, Jambunathan K <kjambunathan@gmail.com>
wrote:
> Matt Price <moptop99@gmail.com> writes:
>
>> The attached test file shows  an org file with tables whose columns
>> include substantial amounts of text.  The default export to odt is
>> pretty ugly in this case, and even in html (where things work to some
>> extent) I would rather be able to control to some extent the way that
>> long fields wrap.  is there a recommended way to do set values like
>> table and column width for these two exports? I guess I am
>> particularly concerned with the odt export -- can I e.g. adjust a
>> default value somewhere in the styles.xml file? I doubt the problem
>> will be easily solved but if someone can point me in the right
>> direction I'd really appreciate it.
>
> The issue is not that fields don't wrap well but that the table is big
> for the width of the paper and columns are as a result getting
> congested.

yes, that's a better description.

>
> I have pushed a fix whereby tables now occupy bigger space [1].
>
> I also noticed that columns are unevenly spaced. Now I have updated the
> styles so that columns are equally spaced [2].
>
> Orgmode exporters can never be layout engines. They are also typically
> useful for personal (as opposed to professional) production. In some
> sense they are good for handouts, pamphlets and drafts etc. So some
> amount of hand fixing and finer adjustments would always be required.
That makes sense, of course. My issue in this case is that I update this
particular file quite frequently & store it online in a repository. It would
be nice if I could code the table formatting into the org file so that I
don't have to hand-fix the formatting on each iteration.  But on the other
hand, maybe a table isn't really the right tool in such a case -- as you
suggest, a spreadsheet (or perhaps a structured outline, which org excels
at) might be better.

>
> You choose a smaller font for text in the table with:
>
> F11->Paragraph Styles->OrgTableContents->Choose a smaller (say 10 pt)
>   font.
that's helpful, and I can presumably save this change to my styles.xml file
for future use.
>
> This will affect the text in all the tables.
>
> For the sake of documentation,
>
> Vertical and horizontal grid lines in the exported table correspond to
> colgroups (specified in table cookie lines) and by horizontal rulers in
> the org table [3]. You can use these grid lines in the Org file and
> automatically the exporter will create the grid lines for you.
>
> If you need really prettier tables you can rely on Table->Autoformat.
>
> Footnotes:
> [1] So there is now a reverse problem of tables with less number of
> columns and not having copious text looking too big. But big is better
> even if it is ugly.
>
> The workaround is to rely on Table Properties->Table->Width
>
> [2] Pre-processor in org-exp.el groks l, r, c cookies but ignores the
> colwidth directives. With some changes these colwidth directives could
> be used for controlling the relative width of columns on a per-table
> basis. This has to wait. If there is sufficient demand I can consider
> adding this support.
>
> The workaround is to rely on Table Properties->Columns->Column Width
>
> [3] The exporter wouldn't still create vertical lines on the extreme
> ends. I believe the default style of tables is so selected based on some
> standard styling manual.

In my view the problem here is that Openoffie is difficult to work with for
some of these formatting tasks -- so really this is an issue that's hard for
you to fix.  But for instance, I have had a lot of difficulty trying to
change the colour of the timestamps -- in fact for now I've given up! But I
think the issue might just be that LibreOffice/Openoffice doesn't redraw the
document properly after certain style changes, so I can't actually tell
whether my style changes (to OrgTimestamp and ORgTimestampWrapper character
styles in the style manager, F11) have been effective.

sorry that was a digression.  Thanks so much for your help on this issue.
matt

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

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

* Re: org->odt/html table export: adjusting default behaviour?
  2011-08-26 14:24   ` Matt Price
@ 2011-08-28 22:33     ` Jambunathan K
  2011-08-28 22:40       ` [PATCH 1/2] Parse and store both col align and col width spec for later use Jambunathan K
  2011-08-28 22:41       ` [PATCH 2/2] org-odt.el: Put table style and col sizes under direct user control Jambunathan K
  0 siblings, 2 replies; 10+ messages in thread
From: Jambunathan K @ 2011-08-28 22:33 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

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


Matt

>  It would be nice if I could code the table formatting into the org
> file so that I don't have to hand-fix the formatting on each
> iteration.

Thanks for your feedback. 

I have worked up a patch which intends to give users more control over
how tables are formatted. The patch modifies files that I don't own so
the changes will take sometime to hit the repo.

With this patch applied one can
1. Choose the style of the table (Is the table wide or narrow?)
2. Control relative size of the individual columns

The new feature is best illustrated by an example. If you look at the
attached file you will see that:

1. The first table which has only 2 columns and less text has the
   following attribute.

,----
|    #+ATTR_ODT: OrgTableSmall
`----

   The intention is to format the table so that it occupies lesser
   width. 

   The table styles are stored in
   contrib/odt/styles/OrgOdtAutomaticStyles.xml. Visit this file and
   look for "OrgTable" property and you will that it occupies 90% of
   page width. 

,---- OrgTable
|   <style:style style:name="OrgTable" style:family="table">
|    <style:table-properties style:rel-width="90%" table:align="center"/>
|   </style:style>
`----

   Now I add another entry "OrgTableSmall" which occupies 30% of page
   width as below

,---- OrgTableSmall
|   <style:style style:name="OrgTableSmall" style:family="table">
|    <style:table-properties style:rel-width="30%" table:align="center"/>
|   </style:style>
`----

2. Modify the bigger table as below
   - specify no #+ATTR_ODT
     This will ensure that the default 90% style is used for the table
   - indicate colgroups (Note the new row full of "<>" as field entries)
     This will ensure that exported table will have vertical grid lines
   - horizontal separators
     This will ensure that exported table has horizontal grid lines
   - The width specifier has been adjusted so that exported table is
     well-balanced. Note that the "Readings" columns which has no
     entries is given very negligible weightage and other columns has
     fairly good weightage.

3. Export the file to Odt.

4. Now you will have a resonably good looking Table. To make it more
   pleasing you need to reduce the font size of the table entries. This
   you can do by F11->Paragraph Styles->OrgTableContents-><set font size
   to 10 pt> 

   Or 

   If you are imaptient you can grok the
   contrib/odt/styles/OrgOdtStyles.xml file for "OrgTableContents" and
   fix the font-size there.

I am attaching the resulting file at the end of step 4. 

Hope these adjustments make the export of table more flexible. Let me
know what you know think.

Rant: The only way to customize Tables in LibreOffice is through the
Autoformat utility. The OASIS specification clearly outlines ways to
create custom table-related styles. Unfortunately, the state of affairs
with LibreOffice is such that such styles are ignored when used. So one
has to really rely on automatic styles for formatting of tables going
forward. This makes styling of tables a bit more involved for me - the
developer and you - the user.

Thanks, 
Jambunathan K.

-- 

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: table.org --]
[-- Type: text/x-org, Size: 6480 bytes --]

#+TITLE:     test.org
#+AUTHOR:    Matt Price
#+EMAIL:     matt.price@utoronto.ca
#+DATE:      2011-08-23 Tue
#+DESCRIPTION:
#+KEYWORDS:
#+LANGUAGE:  en
#+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS:   TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+LINK_UP:   
#+LINK_HOME: 
#+XSLT:

* heading1
** heading2

#+ATTR_ODT: OrgTableSmall
| table | 1 | 2 |
|       |   |   |

** heading2 -2
some text.

* Outline

|       Week | Date                 | Topic                          | Description                         | Tech Topics          | Assignments          | Readings | Notes                |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|          / | <>                   | <>                             | <>                                  | <>                   | <>                   | <>    | <>                   |
|       <10> | <20>                 | <30>                           | <35>                                | <20>                 | <20>                 | <5>   | <20>                 |
|          1 | 9/12/2011            | Intro:What is History For?     | The uses of history; engagement and objectivity; etc | Intro to Website     | --                   |       |                      |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|          2 | 9/19/2011            | History and the Public Sphere  | "What is the Public Sphere, & what role does history play in it?" | HTML Workshop        |                      |       |                      |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|          3 | 9/26/2011            | What ais the Canadian Public Sphere | "Multiculturalism, Immigration, and National Identity as questions of mediality" |                      |                      |       |                      |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|          4 | 10/3/2011            | History From Below             | "History from below,' oral history, & implications for the practice of history" | Audio Workshop       | Oral History Interview |       |                      |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|          6 | 10/10/2011           | Th Wisdom of the Crowd?        | "Crowdsourcing, Wikipedia, Citizen Science & Collaborative history" | Collective Bibliographies | Zotero Assignment    |       | Transcription of Interview |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|          5 | 10/17/2011           | Language of The Web            | From Memex to HTML5; the Web as a Utopian project | google maps/jsbin workshop? maybe not. |                      |       | Visits to Archive    |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|          7 | 10/24/2011           | Engaged History                |                                     |                      |                      |       | Background Research  |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|          8 | 10/31/2011           | Recursive Publics              | Open Source/Open Access/Open standards | Timelines            | Timeline Assignment -- needs a lab |       | Open Access Week. Peer review of audio stories. |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|          9 | 11/7/2011            | Information Abundance          |                                     |                      |                      |       |                      |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|         10 | 11/14/2011           | Thinking with Pictures         | Maps and the visual Representation of Information | GIS                  | GIS Assignment       |       |                      |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|         11 | 11/21/2011           | Making Sense of copyright      |                                     |                      |                      |       |                      |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|         12 | 11/28/2011           | Digital Divides                |                                     |                      |                      |       |                      |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|
|         13 | 12/5/2011            | Review Authorship              |                                     |                      | Final Assignment     |       |                      |
|------------+----------------------+--------------------------------+-------------------------------------+----------------------+----------------------+-------+----------------------|

[-- Attachment #3: table.odt --]
[-- Type: application/vnd.oasis.opendocument.text, Size: 18646 bytes --]

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

* [PATCH 1/2] Parse and store both col align and col width spec for later use
  2011-08-28 22:33     ` Jambunathan K
@ 2011-08-28 22:40       ` Jambunathan K
  2011-08-28 22:41       ` [PATCH 2/2] org-odt.el: Put table style and col sizes under direct user control Jambunathan K
  1 sibling, 0 replies; 10+ messages in thread
From: Jambunathan K @ 2011-08-28 22:40 UTC (permalink / raw)
  To: Org Mode

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


> I have worked up a patch which intends to give users more control over
> how tables are formatted. The patch modifies files that I don't own so
> the changes will take sometime to hit the repo.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Parse-and-store-both-col-align-and-col-width-spec-fo.patch --]
[-- Type: text/x-patch, Size: 4655 bytes --]

From 8bae4b059a3063a866260ed2958e6c1e05365901 Mon Sep 17 00:00:00 2001
From: Jambunathan K <kjambunathan@gmail.com>
Date: Mon, 29 Aug 2011 02:00:24 +0530
Subject: [PATCH 1/2] Parse and store both col align and col width spec for later use

* lisp/org-exp.el (org-store-forced-table-alignment): Parse
the column cookie for both alignment and width specification.
Store the resulting value in `org-col-cookies' property.
Retire the previously used `org-forced-aligns' property for
consistency.  Renamed local variable `aligns' to `cookies'.
* lisp/org-html.el (org-format-org-table-html): Use
`org-col-cookies'.  Renamed local variable forced-aligns to
col-cookies.

This is a preparatory patch.  A backend can look at the colwidth
specification and (at it's discretion) use it to control relative
sizes of individual columns in a table.  At this moment, it is unclear
whether the widths used to control the display of table in Org buffer
can be overloaded to also control the formatting of table in a
backend.

Refer following discussion with Matt Price:
http://lists.gnu.org/archive/html/emacs-orgmode/2011-08/msg01053.html
---
 lisp/org-exp.el  |   17 +++++++++++------
 lisp/org-html.el |   14 +++++++-------
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index f795fbd..7d6bd38 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -1995,23 +1995,28 @@ When it is nil, all comments will be removed."
 
 (defun org-store-forced-table-alignment ()
   "Find table lines which force alignment, store the results in properties."
-  (let (line cnt aligns)
+  (let (line cnt cookies)
     (goto-char (point-min))
-    (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t)
+    (while (re-search-forward "|[ \t]*<\\([lrc]?[0-9]+\\|[lrc]\\)>[ \t]*|"
+			      nil t)
       ;; OK, this looks like a table line with an alignment cookie
       (org-if-unprotected
        (setq line (buffer-substring (point-at-bol) (point-at-eol)))
        (when (and (org-at-table-p)
 		  (org-table-cookie-line-p line))
-	 (setq cnt 0 aligns nil)
+	 (setq cnt 0 cookies nil)
 	 (mapc
 	  (lambda (x)
 	    (setq cnt (1+ cnt))
-	    (if (string-match "\\`<\\([lrc]\\)" x)
-		(push (cons cnt (downcase (match-string 1 x))) aligns)))
+	    (when (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'" x)
+	      (let ((align (and (match-end 1)
+				(downcase (match-string 1 x))))
+		    (width (and (match-end 2)
+				(string-to-number (match-string 2 x)))))
+		(push (cons cnt (list align width)) cookies))))
 	  (org-split-string line "[ \t]*|[ \t]*"))
 	 (add-text-properties (org-table-begin) (org-table-end)
-			      (list 'org-forced-aligns aligns))))
+			      (list 'org-col-cookies cookies))))
       (goto-char (point-at-eol)))))
 
 (defun org-export-remove-special-table-lines ()
diff --git a/lisp/org-html.el b/lisp/org-html.el
index 28a0e8f..a6e748a 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -1979,8 +1979,8 @@ for formatting.  This is required for the DocBook exporter."
 
   (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
 	 (label (org-find-text-property-in-string 'org-label (car lines)))
-	 (forced-aligns (org-find-text-property-in-string 'org-forced-aligns
-							  (car lines)))
+	 (col-cookies (org-find-text-property-in-string 'org-col-cookies
+							(car lines)))
 	 (attributes (org-find-text-property-in-string 'org-attributes
 						       (car lines)))
 	 (html-table-tag (org-export-splice-attributes
@@ -1993,9 +1993,9 @@ for formatting.  This is required for the DocBook exporter."
 	 tbopen line fields html gr colgropen rowstart rowend
 	 ali align aligns n)
     (setq caption (and caption (org-html-do-expand caption)))
-    (when (and forced-aligns org-table-clean-did-remove-column)
-    (setq forced-aligns
-	  (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
+    (when (and col-cookies org-table-clean-did-remove-column)
+      (setq col-cookies
+	    (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) col-cookies)))
     (if splice (setq head nil))
     (unless splice (push (if head "<thead>" "<tbody>") html))
     (setq tbopen t)
@@ -2056,8 +2056,8 @@ for formatting.  This is required for the DocBook exporter."
 	     (lambda (x)
 	       (setq gr (pop org-table-colgroup-info)
 		     i (1+ i)
-		     align (if (assoc i forced-aligns)
-			       (cdr (assoc (cdr (assoc i forced-aligns))
+		     align (if (nth 1 (assoc i col-cookies))
+			       (cdr (assoc (nth 1 (assoc i col-cookies))
 					   '(("l" . "left") ("r" . "right")
 					     ("c" . "center"))))
 			     (if (> (/ (float x) nline)
-- 
1.7.2.3


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

* [PATCH 2/2] org-odt.el: Put table style and col sizes under direct user control
  2011-08-28 22:33     ` Jambunathan K
  2011-08-28 22:40       ` [PATCH 1/2] Parse and store both col align and col width spec for later use Jambunathan K
@ 2011-08-28 22:41       ` Jambunathan K
  1 sibling, 0 replies; 10+ messages in thread
From: Jambunathan K @ 2011-08-28 22:41 UTC (permalink / raw)
  To: Org Mode

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


> I have worked up a patch which intends to give users more control over
> how tables are formatted. The patch modifies files that I don't own so
> the changes will take sometime to hit the repo.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-org-odt.el-Put-table-style-and-col-sizes-under-direc.patch --]
[-- Type: text/x-patch, Size: 8418 bytes --]

From 046a2d1793c50c99b5b58b3874540632513e4562 Mon Sep 17 00:00:00 2001
From: Jambunathan K <kjambunathan@gmail.com>
Date: Mon, 29 Aug 2011 02:33:17 +0530
Subject: [PATCH 2/2] org-odt.el: Put table style and col sizes under direct user control

* contrib/lisp/org-lparse.el
(org-lparse-table-get-colalign-info): Renamed
`org-forced-aligns' to `org-col-cookies'.  Renamed local
variable `forced-aligns' to `col-cookies'.
(org-lparse-format-table-row): With the introduction of
`org-col-cookies' property the internal structure of
`org-lparse-table-colalign-info' has changed.  Do the right
thing while setting up col alignment.  Pass on the colwidth
property as horiz-span arg of `TABLE-CELL' callback.
* contrib/lisp/org-odt.el (org-odt-begin-table): Let the table
style be settable throught #+ATTR_ODT line.  By default tables
are configured to occupy 90% of paper width.  This is too big
for smaller tables.  For aesthetic reasons, a user might
prefer that such tables of shorter width and thus specify a
different style.
(org-odt-end-table, org-odt-format-table-cell): Honor colwidth
specification.
* contrib/lisp/org-xhtml.el (org-xhtml-format-table-cell): Fix
signature as mandated by changes in TABLE-CELL callback.

See comments in the earlier patch. See also
http://lists.gnu.org/archive/html/emacs-orgmode/2011-08/msg01053.html
---
 contrib/lisp/org-lparse.el |   36 ++++++++++++---------
 contrib/lisp/org-odt.el    |   75 ++++++++++++++++++++++++++-----------------
 contrib/lisp/org-xhtml.el  |    2 +-
 3 files changed, 66 insertions(+), 47 deletions(-)

diff --git a/contrib/lisp/org-lparse.el b/contrib/lisp/org-lparse.el
index fd0488b..b176378 100755
--- a/contrib/lisp/org-lparse.el
+++ b/contrib/lisp/org-lparse.el
@@ -1301,13 +1301,12 @@ version."
 	(org-lparse-format-table-table lines))))
 
 (defun org-lparse-table-get-colalign-info (lines)
-  (let ((forced-aligns (org-find-text-property-in-string
-			'org-forced-aligns (car lines))))
-    (when (and forced-aligns org-table-clean-did-remove-column)
-      (setq forced-aligns
-	    (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
-
-    forced-aligns))
+  (let ((col-cookies (org-find-text-property-in-string
+			'org-col-cookies (car lines))))
+    (when (and col-cookies org-table-clean-did-remove-column)
+      (setq col-cookies
+	    (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) col-cookies)))
+    col-cookies))
 
 (defvar org-lparse-table-style)
 (defvar org-lparse-table-ncols)
@@ -1945,12 +1944,13 @@ See `org-xhtml-entity-format-callbacks-alist' for more information."
 	    (make-vector org-lparse-table-ncols nil))
       (let ((c -1))
 	(while  (< (incf c) org-lparse-table-ncols)
-	  (let ((cookie (cdr (assoc (1+ c) org-lparse-table-colalign-info))))
+	  (let* ((col-cookie (cdr (assoc (1+ c) org-lparse-table-colalign-info)))
+		 (align (nth 0 col-cookie)))
 	    (setf (aref org-lparse-table-colalign-vector c)
 		  (cond
-		   ((string= cookie "l") "left")
-		   ((string= cookie "r") "right")
-		   ((string= cookie "c") "center")
+		   ((string= align "l") "left")
+		   ((string= align "r") "right")
+		   ((string= align "c") "center")
 		   (t nil))))))))
   (incf org-lparse-table-rownum)
   (let ((i -1))
@@ -1961,11 +1961,15 @@ See `org-xhtml-entity-format-callbacks-alist' for more information."
 	(when (and (string= x "") text-for-empty-fields)
 	  (setq x text-for-empty-fields))
 	(incf i)
-	(and org-lparse-table-is-styled
-	     (< i org-lparse-table-ncols)
-	     (string-match org-table-number-regexp x)
-	     (incf (aref org-lparse-table-num-numeric-items-per-column i)))
-	(org-lparse-format 'TABLE-CELL x org-lparse-table-rownum i))
+	(let (col-cookie horiz-span)
+	  (when org-lparse-table-is-styled
+	    (when (and (< i org-lparse-table-ncols)
+		       (string-match org-table-number-regexp x))
+	      (incf (aref org-lparse-table-num-numeric-items-per-column i)))
+	    (setq col-cookie (cdr (assoc (1+ i) org-lparse-table-colalign-info))
+		  horiz-span (nth 1 col-cookie)))
+	  (org-lparse-format
+	   'TABLE-CELL x org-lparse-table-rownum i (or horiz-span 0))))
       fields "\n"))))
 
 (defun org-lparse-get (what &optional opt-plist)
diff --git a/contrib/lisp/org-odt.el b/contrib/lisp/org-odt.el
index a5b2d96..491ed44 100644
--- a/contrib/lisp/org-odt.el
+++ b/contrib/lisp/org-odt.el
@@ -644,15 +644,22 @@ PUB-DIR is set, use this as the publishing directory."
 
   (org-lparse-insert-tag
    "<table:table table:name=\"%s\" table:style-name=\"%s\">"
-   (or label "") "OrgTable")
+   (or label "") (or attributes "OrgTable"))
   (setq org-lparse-table-begin-marker (point)))
 
 (defun org-odt-end-table ()
   (goto-char org-lparse-table-begin-marker)
   (loop for level from 0 below org-lparse-table-ncols
-	do (insert
-	    (org-odt-format-tags
-	     "<table:table-column table:style-name=\"OrgTableColumn\"/>"  "")))
+	do (let* ((col-cookie (and org-lparse-table-is-styled
+				   (cdr (assoc (1+ level)
+					       org-lparse-table-colalign-info))))
+		  (extra-columns (or (nth 1 col-cookie) 0)))
+	     (dotimes (i (1+ extra-columns))
+	       (insert
+		(org-odt-format-tags
+		 "\n<table:table-column table:style-name=\"OrgTableColumn\"/>"
+		 "")))
+	     (insert "\n")))
 
   ;; fill style attributes for table cells
   (when org-lparse-table-is-styled
@@ -708,32 +715,40 @@ PUB-DIR is set, use this as the publishing directory."
 (defun org-odt-get-paragraph-style-for-table-cell (r c)
   (capitalize (aref org-lparse-table-colalign-vector c)))
 
-(defun org-odt-format-table-cell (data r c)
-  (if (not org-lparse-table-is-styled)
-      (org-odt-format-tags
-       '("<table:table-cell>" . "</table:table-cell>")
-       (org-odt-format-stylized-paragraph
-	(cond
-	 (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading")
-	 ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS))
-	  "OrgTableHeading")
-	 (t "OrgTableContents"))
-	data))
-    (let* ((style-name-cookie
-	    (format "@@table-cell:style-name@@%03d@@%03d@@" r c))
-	   (paragraph-style-cookie
-	    (concat
-	     (cond
-	      (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading")
-	      ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS))
-	       "OrgTableHeading")
-	      (t "OrgTableContents"))
-	     (format "@@table-cell:p@@%03d@@%03d@@" r c))))
-      (org-odt-format-tags
-       '("<table:table-cell table:style-name=\"%s\">" .
-	 "</table:table-cell>")
-       (org-odt-format-stylized-paragraph paragraph-style-cookie data)
-       style-name-cookie))))
+(defun org-odt-format-table-cell (data r c horiz-span)
+  (concat
+   (if (not org-lparse-table-is-styled)
+       (org-odt-format-tags
+	'("<table:table-cell>" . "</table:table-cell>")
+	(org-odt-format-stylized-paragraph
+	 (cond
+	  (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading")
+	  ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS))
+	   "OrgTableHeading")
+	  (t "OrgTableContents"))
+	 data))
+     (let* ((style-name-cookie
+	     (format "@@table-cell:style-name@@%03d@@%03d@@" r c))
+	    (paragraph-style-cookie
+	     (concat
+	      (cond
+	       (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading")
+	       ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS))
+		"OrgTableHeading")
+	       (t "OrgTableContents"))
+	      (format "@@table-cell:p@@%03d@@%03d@@" r c)))
+	    (extra (concat (and (> horiz-span 0)
+				(format " table:number-columns-spanned=\"%d\""
+					(1+ horiz-span))))))
+       (org-odt-format-tags
+	'("<table:table-cell table:style-name=\"%s\"%s>" .
+	  "</table:table-cell>")
+	(org-odt-format-stylized-paragraph paragraph-style-cookie data)
+	style-name-cookie extra)))
+   (let (s)
+     (dotimes (i horiz-span)
+       (setq s (concat s "\n<table:covered-table-cell/>"))) s)
+   "\n"))
 
 (defun org-odt-begin-footnote-definition (n)
   (org-lparse-begin-paragraph 'footnote))
diff --git a/contrib/lisp/org-xhtml.el b/contrib/lisp/org-xhtml.el
index 8a8f4ca..07f9493 100644
--- a/contrib/lisp/org-xhtml.el
+++ b/contrib/lisp/org-xhtml.el
@@ -1558,7 +1558,7 @@ lang=\"%s\" xml:lang=\"%s\">
    (cons (eval (car org-export-table-row-tags))
 	 (eval (cdr org-export-table-row-tags))) row))
 
-(defun org-xhtml-format-table-cell (text r c)
+(defun org-xhtml-format-table-cell (text r c horiz-span)
   (let ((cell-style-cookie (or (and org-lparse-table-is-styled
 				    (format "@@class%03d@@" c)) "")))
     (cond
-- 
1.7.2.3


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

* [odt] Support for table templates (was Re: org->odt/html table export: adjusting default behaviour?)
  2011-08-25 21:40 ` Jambunathan K
  2011-08-26 14:24   ` Matt Price
@ 2011-09-14  9:56   ` Jambunathan K
  1 sibling, 0 replies; 10+ messages in thread
From: Jambunathan K @ 2011-09-14  9:56 UTC (permalink / raw)
  To: Org Mode

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


> If you need really prettier tables you can rely on Table->Autoformat.

I felt some sort of templating mechanism would be useful for odt
tables[1]. To this end, I have pushed some changes which honors ODF-1.2
spec[2].

The attached table-template.org and table-template.odt should serve as
an illustrative example of what is possible with the odt exporter. 

Note that you need to modify automatic-styles that are in
contrib/odt/styles/OrgOdtContentTemplate.xml. (Please consult the
comments in the attached org file.)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: table-template.org --]
[-- Type: text/x-org, Size: 4150 bytes --]

#+TITLE:     table-template.org
#+AUTHOR:    Jambunathan K
#+EMAIL:     kjambunathan@gmail.com
#+DESCRIPTION:
#+KEYWORDS:
#+LANGUAGE:  en
#+OPTIONS:   H:3 num:t toc:t \n:nil @:t ::t |:t ^:nil -:t f:t *:t <:t
#+OPTIONS:   TeX:t LaTeX:dvipng skip:nil d:nil todo:t pri:nil tags:not-in-toc

#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+LINK_UP:   
#+LINK_HOME: 
#+XSLT:


* Customization

#+begin_src emacs-lisp
  (setq org-export-odt-table-styles
        '(("TableWithHeaderRowAndColumn" "Custom"
           ((use-first-row-styles . t)
            (use-first-column-styles . t)))
          ("TableWithFirstRowandLastRow" "Custom"
           ((use-first-row-styles . t)
            (use-last-row-styles . t)))))
#+end_src

  See docstring of =org-export-odt-table-styles= for more
  information. Also unzip the exported odt file and inspect the
  _content.xml_ for _automatic-styles_ starting with keyword _Custom_.

* Table Templates Illustrated

** Regular Org Table
   This table has no *#+ATTR_ODT:* associated with it.


    |     Labels | C1          | C2            |           C3 |
    |------------+-------------+---------------+--------------|
    |          / | <           | >             |           <> |
    |        <r> | <l>         | <c>           |          <r> |
    | R1 (Right) | R1C1 (Left) | R1C2 (Center) | R1C3 (Right) |
    |         R2 | R2C1        | R2C2          |         R2C3 |
    |------------+-------------+---------------+--------------|
    |         R3 | R3C1        | R3C2          |         R3C3 |
    |         R4 | R4C1        | R4C2          |         R4C3 |
    |------------+-------------+---------------+--------------|
    |         R5 | R5C1        | R5C2          |         R5C3 |
    |         R6 | R6C1        | R6C2          |         R6C3 |
    |         R7 | R7C1        | R7C2          |              |
    |------------+-------------+---------------+--------------|


** Table using header row and column styles
   This table uses table template named _Custom_ and selects the
   following styles:
   - first row
   - first column

#+ATTR_ODT: TableWithHeaderRowAndColumn
    |     Labels | C1          | C2            |           C3 |
    |------------+-------------+---------------+--------------|
    |          / | <           | >             |           <> |
    |        <r> | <l>         | <c>           |          <r> |
    | R1 (Right) | R1C1 (Left) | R1C2 (Center) | R1C3 (Right) |
    |         R2 | R2C1        | R2C2          |         R2C3 |
    |------------+-------------+---------------+--------------|
    |         R3 | R3C1        | R3C2          |         R3C3 |
    |         R4 | R4C1        | R4C2          |         R4C3 |
    |------------+-------------+---------------+--------------|
    |         R5 | R5C1        | R5C2          |         R5C3 |
    |         R6 | R6C1        | R6C2          |         R6C3 |
    |         R7 | R7C1        | R7C2          |              |
    |------------+-------------+---------------+--------------|

** Table using first row and last row styles
   This table also uses the same table template named _Custom_ and
   selects the following styles:
   - first row
   - last row

#+ATTR_ODT: TableWithFirstRowandLastRow
    |     Labels | C1          | C2            |           C3 |
    |------------+-------------+---------------+--------------|
    |          / | <           | >             |           <> |
    |        <r> | <l>         | <c>           |          <r> |
    | R1 (Right) | R1C1 (Left) | R1C2 (Center) | R1C3 (Right) |
    |         R2 | R2C1        | R2C2          |         R2C3 |
    |------------+-------------+---------------+--------------|
    |         R3 | R3C1        | R3C2          |         R3C3 |
    |         R4 | R4C1        | R4C2          |         R4C3 |
    |------------+-------------+---------------+--------------|
    |         R5 | R5C1        | R5C2          |         R5C3 |
    |         R6 | R6C1        | R6C2          |         R6C3 |
    |         R7 | R7C1        | R7C2          |              |
    |------------+-------------+---------------+--------------|

[-- Attachment #3: table-template.odt --]
[-- Type: application/vnd.oasis.opendocument.text, Size: 9841 bytes --]

[-- Attachment #4: Type: text/plain, Size: 889 bytes --]



Footnotes: 

[1] I find the Org's regular way of drawing the grid lines a bit out of
the normal (scholarly?). Internally, I needed some control over the
table cells for supporting numbered equations (which uses tables). Also
a user will prefer "Top-aligned" content for text-intensive tables and
"Centre-aligned" content for text-sparse tables.

[2] LibreOffice's Autoformat facility for tables is richer than what
ODF-1.2 templating mechanism provides for. Unfortunately it is difficult
to configure by hand (as is required for the odt exporter). Honestly
speaking, I had to spend quite a good amount of time tinkering with
automatic styles used with the attached files and I am certain that any
sort of in-built advanced templating mechanism within the odt exporter
would be, what to say, utter madness. I really wish LibreOffice
supported custom styles for table related components.


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

end of thread, other threads:[~2011-09-14  9:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-25 15:12 org->odt/html table export: adjusting default behaviour? Matt Price
2011-08-25 15:36 ` Matt Price
2011-08-25 21:40 ` Jambunathan K
2011-08-26 14:24   ` Matt Price
2011-08-28 22:33     ` Jambunathan K
2011-08-28 22:40       ` [PATCH 1/2] Parse and store both col align and col width spec for later use Jambunathan K
2011-08-28 22:41       ` [PATCH 2/2] org-odt.el: Put table style and col sizes under direct user control Jambunathan K
2011-09-14  9:56   ` [odt] Support for table templates (was Re: org->odt/html table export: adjusting default behaviour?) Jambunathan K
2011-08-25 22:01 ` org->odt/html table export: adjusting default behaviour? Jambunathan K
2011-08-26 14:13   ` Matt Price

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