emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How do I convert org to OpenOffice?
@ 2010-09-29 17:01 Lennart Borgman
  2010-09-29 17:52 ` Charles Philip Chan
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Lennart Borgman @ 2010-09-29 17:01 UTC (permalink / raw)
  To: Org Mode

There is a way, isn't there? ;-)

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 17:01 How do I convert org to OpenOffice? Lennart Borgman
@ 2010-09-29 17:52 ` Charles Philip Chan
  2010-09-29 18:20   ` Lennart Borgman
  2010-09-30 12:41 ` Matt Lundin
  2010-10-06 15:21 ` Eric S Fraga
  2 siblings, 1 reply; 28+ messages in thread
From: Charles Philip Chan @ 2010-09-29 17:52 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 353 bytes --]

Lennart Borgman <lennart.borgman@gmail.com> writes:

> There is a way, isn't there? ;-)

Export to LaTeX and use mk4ht:

http://linuxsagas.wordpress.com/2008/12/08/latex-to-openoffice/

Charles

-- 
Running Windows on a Pentium is like having a brand new Porsche but only
be able to drive backwards with the handbrake on.
(Unknown source)

[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 17:52 ` Charles Philip Chan
@ 2010-09-29 18:20   ` Lennart Borgman
  2010-09-29 18:34     ` Charles Philip Chan
  2010-09-29 18:39     ` Charles Philip Chan
  0 siblings, 2 replies; 28+ messages in thread
From: Lennart Borgman @ 2010-09-29 18:20 UTC (permalink / raw)
  To: Charles Philip Chan; +Cc: Org Mode

Thanks Charles, but I am using Windows. I guess that this solution is
not cross platform, or?


On Wed, Sep 29, 2010 at 7:52 PM, Charles Philip Chan
<cpchan@sympatico.ca> wrote:
> Lennart Borgman <lennart.borgman@gmail.com> writes:
>
>> There is a way, isn't there? ;-)
>
> Export to LaTeX and use mk4ht:
>
> http://linuxsagas.wordpress.com/2008/12/08/latex-to-openoffice/
>
> Charles
>
> --
> Running Windows on a Pentium is like having a brand new Porsche but only
> be able to drive backwards with the handbrake on.
> (Unknown source)
>

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 18:20   ` Lennart Borgman
@ 2010-09-29 18:34     ` Charles Philip Chan
  2010-09-29 18:39     ` Charles Philip Chan
  1 sibling, 0 replies; 28+ messages in thread
From: Charles Philip Chan @ 2010-09-29 18:34 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 368 bytes --]

Lennart Borgman <lennart.borgman@gmail.com> writes:

> Thanks Charles, but I am using Windows. I guess that this solution is
> not cross platform, or?

It is cross platform- tex4ht is written in JAVA. More info:

http://en.wikipedia.org/wiki/TeX4ht

Charles

-- 
"Never make any mistaeks."
(Anonymous, in a mail discussion about to a kernel bug report.)

[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 18:20   ` Lennart Borgman
  2010-09-29 18:34     ` Charles Philip Chan
@ 2010-09-29 18:39     ` Charles Philip Chan
  2010-09-29 19:43       ` Nick Dokos
  1 sibling, 1 reply; 28+ messages in thread
From: Charles Philip Chan @ 2010-09-29 18:39 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 213 bytes --]

Sorry I was looking at the wrong file- it is actually written in pearl.

Charles

-- 
"...[Linux's] capacity to talk via any medium except smoke signals."
(By Dr. Greg Wettstein, Roger Maris Cancer Center)

[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 18:39     ` Charles Philip Chan
@ 2010-09-29 19:43       ` Nick Dokos
  2010-09-29 20:12         ` Charles Philip Chan
  0 siblings, 1 reply; 28+ messages in thread
From: Nick Dokos @ 2010-09-29 19:43 UTC (permalink / raw)
  To: Charles Philip Chan; +Cc: Org Mode, nicholas.dokos, Lennart Borgman

Charles Philip Chan <cpchan@sympatico.ca> wrote:


> Sorry I was looking at the wrong file- it is actually written in pearl.
> 

It is not just one file and afaik, *none* of it is written in Perl. Some
of it is C, some of it is TeX, some of it is Java (apparently: I haven't
looked at tex4ht for some years and I don't remember any Java in there
before, but there is some now), a large amount is just text config files.

Installation is (apparently) still a bear. Here are (ca. 2006)
MikTeX/Win32 instructions from Phillip Viton

     http://facweb.knowlton.ohio-state.edu/pviton/support/tex4ht.html

and the main URL is

     http://www.tug.org/tex4ht/

Nick

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 19:43       ` Nick Dokos
@ 2010-09-29 20:12         ` Charles Philip Chan
  2010-09-29 20:59           ` Nick Dokos
  0 siblings, 1 reply; 28+ messages in thread
From: Charles Philip Chan @ 2010-09-29 20:12 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: Org Mode, Lennart Borgman


[-- Attachment #1.1: Type: text/plain, Size: 764 bytes --]

Nick Dokos <nicholas.dokos@hp.com> writes:

> It is not just one file and afaik, *none* of it is written in
> Perl. Some of it is C, some of it is TeX, some of it is Java
> (apparently: I haven't looked at tex4ht for some years and I don't
> remember any Java in there before, but there is some now), a large
> amount is just text config files.

I didn't take a look at the code, but mk4ht is written in perl:

,----
| ls -la /usr/share/texmf/bin/noarch/mk4ht
| lrwxrwxrwx 1 root root 47 2010-09-07 02:10 /usr/share/texmf/bin/noarch/mk4ht -> ../../../../share/texmf/scripts/tex4ht/mk4ht.pl
`----

Charles

-- 
"Are [Linux users] lemmings collectively jumping off of the cliff of
reliable, well-engineered commercial software?"
(By Matt Welsh)

[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 20:12         ` Charles Philip Chan
@ 2010-09-29 20:59           ` Nick Dokos
  2010-09-29 21:33             ` Matt Price
  0 siblings, 1 reply; 28+ messages in thread
From: Nick Dokos @ 2010-09-29 20:59 UTC (permalink / raw)
  To: Charles Philip Chan; +Cc: Lennart Borgman, nicholas.dokos, Org Mode

Charles Philip Chan <cpchan@sympatico.ca> wrote:


> Nick Dokos <nicholas.dokos@hp.com> writes:
> 
> > It is not just one file and afaik, *none* of it is written in
> > Perl. Some of it is C, some of it is TeX, some of it is Java
> > (apparently: I haven't looked at tex4ht for some years and I don't
> > remember any Java in there before, but there is some now), a large
> > amount is just text config files.
> 
> I didn't take a look at the code, but mk4ht is written in perl:
> 
> ,----
> | ls -la /usr/share/texmf/bin/noarch/mk4ht
> | lrwxrwxrwx 1 root root 47 2010-09-07 02:10 /usr/share/texmf/bin/noarch/mk=
> 4ht -> ../../../../share/texmf/scripts/tex4ht/mk4ht.pl
> `----
> 

Oh, OK, I stand corrected: there is *one* Perl file in there. The rest
is as I described it, except that there's also a ton of shell
scripts. This in particular is perhaps a little worrisome for Win32,
unless one is running cygwin. Not sure whether Vitton's notes address
this.

In any case, without much supporting evidence[1], I'd say that if you
are trying to get to OpenOffice this way, the road is probably paved
with thorns.

Nick

[1] I just tried a simple org->latex->oo transformation on Ubuntu 8.10,
with the default tex4ht distribution for this platform that synaptic
gave me: I tried for a few minutes without success. But I am a complete
ignoramus as far as OO goes, so it may very well have been my error.

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 20:59           ` Nick Dokos
@ 2010-09-29 21:33             ` Matt Price
  2010-09-29 22:40               ` Alan L Tyree
  2010-11-02 17:53               ` Lennart Borgman
  0 siblings, 2 replies; 28+ messages in thread
From: Matt Price @ 2010-09-29 21:33 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: Org Mode, Lennart Borgman


[-- Attachment #1.1: Type: text/plain, Size: 2870 bytes --]

> In any case, without much supporting evidence[1], I'd say that if you
> are trying to get to OpenOffice this way, the road is probably paved
> with thorns.
>
> Nick
>
> [1] I just tried a simple org->latex->oo transformation on Ubuntu 8.10,
> with the default tex4ht distribution for this platform that synaptic
> gave me: I tried for a few minutes without success. But I am a complete
> ignoramus as far as OO goes, so it may very well have been my error.\
>

On Wed, Sep 29, 2010 at 4:59 PM, Nick Dokos <nicholas.dokos@hp.com> wrote:

> Charles Philip Chan <cpchan@sympatico.ca> wrote:
>
>
> > Nick Dokos <nicholas.dokos@hp.com> writes:
> >
> > > It is not just one file and afaik, *none* of it is written in
> > > Perl. Some of it is C, some of it is TeX, some of it is Java
> > > (apparently: I haven't looked at tex4ht for some years and I don't
> > > remember any Java in there before, but there is some now), a large
> > > amount is just text config files.
> >
> > I didn't take a look at the code, but mk4ht is written in perl:
> >
> > ,----
> > | ls -la /usr/share/texmf/bin/noarch/mk4ht
> > | lrwxrwxrwx 1 root root 47 2010-09-07 02:10
> /usr/share/texmf/bin/noarch/mk=
> > 4ht -> ../../../../share/texmf/scripts/tex4ht/mk4ht.pl
> > `----
> >
>
> Oh, OK, I stand corrected: there is *one* Perl file in there. The rest
> is as I described it, except that there's also a ton of shell
> scripts. This in particular is perhaps a little worrisome for Win32,
> unless one is running cygwin. Not sure whether Vitton's notes address
> this.
>
> In any case, without much supporting evidence[1], I'd say that if you
> are trying to get to OpenOffice this way, the road is probably paved
> with thorns.
>
> Nick
>
> [1] I just tried a simple org->latex->oo transformation on Ubuntu 8.10,
> with the default tex4ht distribution for this platform that synaptic
> gave me: I tried for a few minutes without success. But I am a complete
> ignoramus as far as OO goes, so it may very well have been my error.
>
I've had mixed results depending on the complexity of the original org
document.  one of us should really write a proper direct exporter, but I am
such a slow (and rotten) coder, and so behind on so many projects, that it
is not going to be me.   There is a rudimentary muse-mode exporter that
might serve as a partial inspiration:
http://osdir.com/ml/emacs.muse.general/2008-02/msg00009.html
also the new rewritten export engine (what is that called again) looks a
little easier to work with than what's in current org...

if someone does do this please let us all know, I think there are plenty of
people who would really like to use it.
Matt


>
> _______________________________________________
> 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
>

[-- Attachment #1.2: Type: text/html, Size: 4345 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 21:33             ` Matt Price
@ 2010-09-29 22:40               ` Alan L Tyree
  2010-11-02 17:53               ` Lennart Borgman
  1 sibling, 0 replies; 28+ messages in thread
From: Alan L Tyree @ 2010-09-29 22:40 UTC (permalink / raw)
  To: emacs-orgmode

On Wed, 29 Sep 2010 17:33:32 -0400
Matt Price <moptop99@gmail.com> wrote:

> > In any case, without much supporting evidence[1], I'd say that if
> > you are trying to get to OpenOffice this way, the road is probably
> > paved with thorns.
> >
> > Nick
> >
> > [1] I just tried a simple org->latex->oo transformation on Ubuntu
> > 8.10, with the default tex4ht distribution for this platform that
> > synaptic gave me: I tried for a few minutes without success. But I
> > am a complete ignoramus as far as OO goes, so it may very well have
> > been my error.\
> >
> 
> On Wed, Sep 29, 2010 at 4:59 PM, Nick Dokos <nicholas.dokos@hp.com>
> wrote:
> 
> > Charles Philip Chan <cpchan@sympatico.ca> wrote:
> >
> >
> > > Nick Dokos <nicholas.dokos@hp.com> writes:
> > >
> > > > It is not just one file and afaik, *none* of it is written in
> > > > Perl. Some of it is C, some of it is TeX, some of it is Java
> > > > (apparently: I haven't looked at tex4ht for some years and I
> > > > don't remember any Java in there before, but there is some
> > > > now), a large amount is just text config files.
> > >
> > > I didn't take a look at the code, but mk4ht is written in perl:
> > >
> > > ,----
> > > | ls -la /usr/share/texmf/bin/noarch/mk4ht
> > > | lrwxrwxrwx 1 root root 47 2010-09-07 02:10
> > /usr/share/texmf/bin/noarch/mk=
> > > 4ht -> ../../../../share/texmf/scripts/tex4ht/mk4ht.pl
> > > `----
> > >
> >
> > Oh, OK, I stand corrected: there is *one* Perl file in there. The
> > rest is as I described it, except that there's also a ton of shell
> > scripts. This in particular is perhaps a little worrisome for Win32,
> > unless one is running cygwin. Not sure whether Vitton's notes
> > address this.
> >
> > In any case, without much supporting evidence[1], I'd say that if
> > you are trying to get to OpenOffice this way, the road is probably
> > paved with thorns.
> >
> > Nick
> >
<SNIP>

There was a thread on this a while back. One of the suggestions
was to export to XHTML. Edit the XHTML file by chopping off the initial
declaration, then import into OO. I have found that Abiword will import
directly the XHTML file w/o editing.

I have found that this works well with simple documents. Don't know
about complex things.

tex4ht contains a script, oolatex, that directly converts the tex file
to OO. At least on my Debian system, it is not in the execution path by
default.

HTH,
Alan


-- 
Alan L Tyree                    http://www2.austlii.edu.au/~alan
Tel:  04 2748 6206

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

* Re: How do I convert org to OpenOffice?
@ 2010-09-30  3:25 Rustom Mody
  0 siblings, 0 replies; 28+ messages in thread
From: Rustom Mody @ 2010-09-30  3:25 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 272 bytes --]

Surely there must be some path like: org -> docbook -> (any-of)rtf,doc,odf
etc??

Here are some links but they all seem old and half done

http://wiki.services.openoffice.org/wiki/Xml
http://xml.openoffice.org/xmerge/docbook/
http://ebellot.chez.com/ooo2sdbk/ (in french)

[-- Attachment #1.2: Type: text/html, Size: 467 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 17:01 How do I convert org to OpenOffice? Lennart Borgman
  2010-09-29 17:52 ` Charles Philip Chan
@ 2010-09-30 12:41 ` Matt Lundin
  2010-09-30 14:26   ` Christian Egli
  2010-10-06 15:21 ` Eric S Fraga
  2 siblings, 1 reply; 28+ messages in thread
From: Matt Lundin @ 2010-09-30 12:41 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: Org Mode

Lennart Borgman <lennart.borgman@gmail.com> writes:

> There is a way, isn't there? ;-)

I've had great success with LaTeX2rtf (i..e, org->LaTeX->rtf). As long
as you are not using too many exotic packages, it works like a charm.

The website indicates that there are Windows binaries available:

http://latex2rtf.sourceforge.net/
http://sourceforge.net/projects/latex2rtf/files/

Best,
Matt

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

* Re: How do I convert org to OpenOffice?
  2010-09-30 12:41 ` Matt Lundin
@ 2010-09-30 14:26   ` Christian Egli
  2010-09-30 16:43     ` Matt Lundin
  0 siblings, 1 reply; 28+ messages in thread
From: Christian Egli @ 2010-09-30 14:26 UTC (permalink / raw)
  To: emacs-orgmode

Matt Lundin <mdl@imapmail.org> writes:

> Lennart Borgman <lennart.borgman@gmail.com> writes:
>
>> There is a way, isn't there? ;-)
>
> I've had great success with LaTeX2rtf (i..e, org->LaTeX->rtf). As long
> as you are not using too many exotic packages, it works like a charm.

It works fairly well with LaTeX2rtf. Cross references didn't work
though.

A colleague just showed me PyODConverter[1] which seems to be some kind
of command line remote control for OO.o. So what you do is to export org
to html and then use PyODConverter to convert html to doc. According to
him it works well.

HTH
Christian

Footnotes: 
[1]  http://www.artofsolving.com/opensource/pyodconverter
-- 
Christian Egli
Swiss Library for the Blind, Visually Impaired and Print Disabled
Grubenstrasse 12, CH-8045 Zürich, Switzerland

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

* Re: How do I convert org to OpenOffice?
  2010-09-30 14:26   ` Christian Egli
@ 2010-09-30 16:43     ` Matt Lundin
  0 siblings, 0 replies; 28+ messages in thread
From: Matt Lundin @ 2010-09-30 16:43 UTC (permalink / raw)
  To: Christian Egli; +Cc: emacs-orgmode

Christian Egli <christian.egli@sbszh.ch> writes:

> Matt Lundin <mdl@imapmail.org> writes:
>
>> Lennart Borgman <lennart.borgman@gmail.com> writes:
>>
>>> There is a way, isn't there? ;-)
>>
>> I've had great success with LaTeX2rtf (i..e, org->LaTeX->rtf). As long
>> as you are not using too many exotic packages, it works like a charm.
>
> It works fairly well with LaTeX2rtf. Cross references didn't work
> though.

The manual suggests that cross-references work, but that their
functionality depends on the office suite:

http://latex2rtf.sourceforge.net/docu_1_9_14.html#Cross%20References

I've found both section references and page references to work well with
Open Office. 

> A colleague just showed me PyODConverter[1] which seems to be some kind
> of command line remote control for OO.o. So what you do is to export org
> to html and then use PyODConverter to convert html to doc. According to
> him it works well.

Thanks for pointing this out.

Best,
Matt

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 17:01 How do I convert org to OpenOffice? Lennart Borgman
  2010-09-29 17:52 ` Charles Philip Chan
  2010-09-30 12:41 ` Matt Lundin
@ 2010-10-06 15:21 ` Eric S Fraga
  2010-10-06 21:10   ` Henri-Paul Indiogine
  2 siblings, 1 reply; 28+ messages in thread
From: Eric S Fraga @ 2010-10-06 15:21 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: Org Mode

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

On Wed, 29 Sep 2010 19:01:26 +0200, Lennart Borgman <lennart.borgman@gmail.com> wrote:
> 
> There is a way, isn't there? ;-)

I do this a lot because, unfortunately, most of my collaborators
insist on word processors such as OO and Word.  What works for me
(with structure, emphasis, tables, figures and footnotes) is:

org document
 -> export as HTML (C-c e h)
 -> open in OOo 
 -> select and copy all (C-a C-c)
 -> open new document in OOo (A-f n t [I believe]) 
 -> paste selection (C-v)
 -> save (in my case, often as MS Word)
 -> go and cry because you have to degrade org mode so much ;-)

Most things work okay for me.   I then ask collaborators to track
changes and I incorporate those changes manually (yech -- but there's
no other way yet) into my org document.

I have also customised 

: org-export-html-xml-declaration (quote (("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>")))
  
to avoid the problem with OOo not understanding the first line of the
HTML created by org html export.

HTH,
eric

[-- Attachment #2: Type: text/plain, Size: 75 bytes --]

-- 
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29  570D C891 93D8 FFFC F67D

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

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-10-06 15:21 ` Eric S Fraga
@ 2010-10-06 21:10   ` Henri-Paul Indiogine
  2010-10-07  7:08     ` Eric S Fraga
  0 siblings, 1 reply; 28+ messages in thread
From: Henri-Paul Indiogine @ 2010-10-06 21:10 UTC (permalink / raw)
  To: emacs-org

Hi Eric!

Eric S Fraga <ucecesf@ucl.ac.uk> writes:
> org document
>  -> export as HTML (C-c e h)
>  -> open in OOo 
>  -> select and copy all (C-a C-c)
>  -> open new document in OOo (A-f n t [I believe]) 
>  -> paste selection (C-v)
>  -> save (in my case, often as MS Word)
>  -> go and cry because you have to degrade org mode so much ;-)

1. export should be "C-c C-e h"

2. My BibTeX references are not exported.  Am I missing something or is
it not possible this way?

3. How could I have some sort of version control?  My advisor uses the
accursed MS Word and that is all he knows.

Thanks,
HP


-- 
Henri-Paul Indiogine
Email: hindiogine@gmail.com
Skype: hindiogine
Website: http://people.cehd.tamu.edu/~sindiogine

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

* Re: How do I convert org to OpenOffice?
  2010-10-06 21:10   ` Henri-Paul Indiogine
@ 2010-10-07  7:08     ` Eric S Fraga
  0 siblings, 0 replies; 28+ messages in thread
From: Eric S Fraga @ 2010-10-07  7:08 UTC (permalink / raw)
  To: hindiogine; +Cc: emacs-org

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

On Wed, 06 Oct 2010 14:10:30 -0700, Henri-Paul Indiogine <hindiogine@gmail.com> wrote:
> 
> Hi Eric!
> 
> Eric S Fraga <ucecesf@ucl.ac.uk> writes:
> > org document
> >  -> export as HTML (C-c e h)
> >  -> open in OOo 
> >  -> select and copy all (C-a C-c)
> >  -> open new document in OOo (A-f n t [I believe]) 
> >  -> paste selection (C-v)
> >  -> save (in my case, often as MS Word)
> >  -> go and cry because you have to degrade org mode so much ;-)
> 
> 1. export should be "C-c C-e h"

Yes, sorry, typo.

> 2. My BibTeX references are not exported.  Am I missing something or is
> it not possible this way?

Not possible this way.  If you need bibtex then latex2rtf, as
mentioned by others, is what I have used in the past.

> 3. How could I have some sort of version control?  My advisor uses the
> accursed MS Word and that is all he knows.

I am not sure what you are asking.  I use version control (git/hg/rcs)
for all of my org files regardless of whether I export them or not.

[-- Attachment #2: Type: text/plain, Size: 75 bytes --]

-- 
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29  570D C891 93D8 FFFC F67D

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

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-09-29 21:33             ` Matt Price
  2010-09-29 22:40               ` Alan L Tyree
@ 2010-11-02 17:53               ` Lennart Borgman
  2010-11-02 19:08                 ` Jambunathan K
  1 sibling, 1 reply; 28+ messages in thread
From: Lennart Borgman @ 2010-11-02 17:53 UTC (permalink / raw)
  To: Matt Price; +Cc: nicholas.dokos, Org Mode

On Wed, Sep 29, 2010 at 11:33 PM, Matt Price <moptop99@gmail.com> wrote:
>
>
> I've had mixed results depending on the complexity of the original org
> document.  one of us should really write a proper direct exporter, but I am
> such a slow (and rotten) coder, and so behind on so many projects, that it
> is not going to be me.   There is a rudimentary muse-mode exporter that
> might serve as a partial inspiration:
> http://osdir.com/ml/emacs.muse.general/2008-02/msg00009.html
> also the new rewritten export engine (what is that called again) looks a
> little easier to work with than what's in current org...
>
> if someone does do this please let us all know, I think there are plenty of
> people who would really like to use it.
> Matt

I have struggled a bit with various ways to export from org-mode to
odt. (Thanks for all the tips here.)

And it was not that fun when things gots complicated so I wonder if it
is better with a direct export. I took the rudimentary exporter in
muse and started to work a bit on it. I have not done very much yet,
just the part that puts all things together once the pieces (for
example content.xml) are there. You can find what I have done so far
in util/org-odt.el in the nXhtml repository.

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

* Re: How do I convert org to OpenOffice?
  2010-11-02 17:53               ` Lennart Borgman
@ 2010-11-02 19:08                 ` Jambunathan K
  2010-11-02 19:31                   ` Matt Price
  2010-11-02 20:10                   ` Lennart Borgman
  0 siblings, 2 replies; 28+ messages in thread
From: Jambunathan K @ 2010-11-02 19:08 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: nicholas.dokos, Org Mode

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


Lennart

Interesting that two people are working on org->OpenOffice exporter. The
other person is me. 

I made this announcement roughly one week in to the project.
- http://lists.gnu.org/archive/html/emacs-orgmode/2010-10/msg00372.html

> I have struggled a bit with various ways to export from org-mode to
> odt. (Thanks for all the tips here.)
>
> And it was not that fun when things gots complicated so I wonder if it
> is better with a direct export. I took the rudimentary exporter in
> muse and started to work a bit on it. I have not done very much yet,
> just the part that puts all things together once the pieces (for
> example content.xml) are there. You can find what I have done so far
> in util/org-odt.el in the nXhtml repository.

I started with org-html.el.

I am attaching a test.org and test.odt from my work area (*as it
is*). You will see that following things are taking shape:

1. Table Of Contents (Still not a 'native' Table Of Contents)
2. Various Character Styles
3. Various Paragraph Styles
4. Lists - Numbered, Bulleted, Description
5. Links - Internet Links, Internal Links as Bookmark/Xref
6. An embedded image
7. A simple table with a caption and numbering (you can see that xref to
   table has apparently broken)
8. Various kinds of Footnotes

If you look inside the odt file you will see that meta.xml also taking
shape.

I have adopted an approach of scanning various features rather than
solidifying the given feature. So the appearance could be flattering.

Jambunathan K.

Attachments: test.org (as plain), test.odt (as zip)


[-- Attachment #2: test.org --]
[-- Type: text/plain, Size: 14058 bytes --]

#+TITLE: OpenDocument MetaData Usecases and Requirements
#+AUTHOR:    Jambunathan K
#+EMAIL:     kjambunathan@gmail.com
#+DATE:      2010-10-26 Sat
#+LANGUAGE:  en
#+OPTIONS:   H:3 num:t  \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
  
* Character Styles
  
** Bold
   *This is bold text*
   
** Italic
   /This is an italicized text/
   
** Underline
   
   _This is an underlined text_
   
** Code
   
   =This is a code text=
   
** Verbatim
   
   ~This is a verbatim text~
   
** Strikethrough
   
   +This is a strikethorugh text+

* Paragraph Styles

** Quotation
   
   There is a quote below.
#+BEGIN_QUOTE
  Everything should be made as simple as possible,
  but not any simpler -- Albert Einstein
#+END_QUOTE
  

** Verse
  There is a verse below.
#+BEGIN_VERSE
  Great clouds overhead
  Tiny black birds rise and fall
  Snow covers Emacs
 
      -- AlexSchroeder
#+END_VERSE
      
** Centered
   
  Here is a centered paragraph.
#+BEGIN_CENTER
  Everything should be made as simple as possible, \\
  but not any simpler
#+END_CENTER
  
** Example
  
   There is an example below
#+srcname:
#+begin_example
  First line of the example.
  Second line of the example.
#+end_example  
  
** Source Block
   
   There is a source block below.
   
#+srcname:
#+begin_src emacs-lisp
  (defun helloworld () 
    ""
    (message "hello world"))
#+end_src  

* Lists

** Simple Lists

*** Numbered List
    
    This is a numbered list.
    
    1. L1N1
    2. L1N2
    3. L1N3
       
    
       


    
*** Bulleted List
    
    This is a bulleted list.
    
    - L1B1
    - L1B2
    - L1B3
    
*** A Complex List
    
    1. L1N1
       1. L2N2
       2. L2N3
    2. L1N4
       * L2B1
       * L2B2
	 - L3B3
	   
	   First paragraph.
	   
	   Second paragraph.
	   
	 - L3B4
    3. L1N5
       1. L2N6
          1. L3N7

** A Very Complex List
   
*** Lord of the Rings
    My favorite scenes are (in this order)
    1. The attack of the Rohirrim
    2. Eowyn's fight with the witch king
       + this was already my favorite scene in the book
       + I really like Miranda Otto.
         - Definition-1 :: Description-1
         - Definition-2 :: Description-2
# * 
			   
			   
    3. Peter Jackson being shot by Legolas
	- on DVD only
       He makes a really funny face when it happens.
    But in the end, no individual scenes matter but the film as a whole.
    Important actors in this film are:
    - Elijah Wood :: He plays Frodo
    - Sean Austin :: He plays Sam, Frodo's friend.  I still remember
		     him very well from his role as Mikey Walsh in
		     The Goonies
		     
      - Embedded Definition 1 :: Embedded Description 1
      - Embedded Definition 2 :: Embedded Description 2
	      

    

* Links
** Targets
   
*** Fuzzy Target
    
*** Target with CUSTOMID
    :PROPERTIES:
    :CUSTOM_ID: aabbccddeeff
    :END:
    
*** Dedicated Target
#   <<Dedicated Target>>    
    
*** <<<Radioed Target>>>
    
** References

*** References to Fuzzy Target
    This is a link to [[Fuzzy Target]].
    
*** References to CUSTOMID links
    
    This is a link to [[#aabbccddeeff][Target with CUSTOMID]]. This is nodesc link to [[#aabbccddeeff]].
    
*** References to Dedicated Target
    There is a link to nodesc [[Dedicated Target]] here. There is a link
    to [[Dedicated%20Target][Jump to Dedicated Target]] here.
    
*** References to Radioed Links
    This section has references to Radioed Target. One more reference
    to Radioed Target.
* Images
  
#+CAPTION: figure-caption
#+LABEL: fig:figure-label
#+ATTR_LaTeX: width=12cm, height=8cm placement=[H]
  [[./001.png]]
  
* Tables
  
#+CAPTION: An Example Table
#+LABEL:   table:10

  | Labels | Column1 | Column2 | Column3 |
  |--------+---------+---------+---------|
  | /      | <       | >       | <>      |
  | Row1   | R1C1    | R1C2    | R1C3    |
  | Row2   | R2C1    | R2C2    | R2C3    |
  |--------+---------+---------+---------|

* Table Referenced
  Please refer to \ref{table:10} for further information.

* Footnote Definitions
  
[1] One
[fn:XYZ] XYZ

* Footnote Usage
  
# Also see org-footnote-autolabel, org-footnote-define-inline,
# org-footnote-section, org-footnote-auto-adjust. [C-u] C-c C-x f.
  

** Plain Footnotes
   
   Footnote [1]. One more reference to footnote [1].
   
** Named Footnotes
   
   Footnote named XYZ [fn:XYZ].

** Inlined Footnote
   Inlined footnote [fn:: inline definition]
   
** Named and Inlined Footnote
   
   Named and Inlined footnote [fn:name: named definition]
  

   
* Pending Items
  
#+ODT
  
#+BEGIN_ODT

#+END_ODT
  
#+ATTR_ODT  
  
  http://www.w3.org/2003/entities/2007/xhtml1-symbol.ent
   
* Introduction

  While existing OpenDocument metadata offers support for the
  widely-used Dublin Core vocabulary, it is limited in the following
  ways:
  
  1. It provides no rules for extension. 
  2. It only allows descriptions of the document as a whole.

  This document was prepared by the OpenDocument Metadata
  Subcommittee, and includes representative use cases and requirements
  for enhancing this metadata support.
  
** What is Metadata?

  The SVG metadata specification defines metadata as structured data
  about data. This structured data describes, explains, locates, or
  otherwise makes it easier to retrieve, use, or manage an information
  resource [NISO-META]. It is the sort of content one typically uses
  to describe documents, images, contacts, events, and so forth.
  
# - Item11
# - Item12
#   - Item121
#   - Item122

** Why is Metadata Important?  
   
   Metadata allows the document author to encode more of his/her human
   intelligence into the document. Document metadata in electronic
   documents is the natural evolution of the marginal comment or the
   footnote in paper documents. Moreover, this enhanced metadata can
   also enable powerful automated solutions. When customers and
   developers ask for support for custom content functionality, then,
   it is often in order to provide domain-specific metadata support.
  
* Use Cases 
  
  The following use cases have been consolidated from a more
  comprehensive list collected by the OpenDocument Metadata
  Subcommittee.

** Accessibility

   Enhanced metadata about document content can be particularly useful
   for accessibility purposes. This use case imagines a blind user who
   is having software read back an ODF document to them. Upon getting
   to an image, the software could optionally present descriptive
   information about the image, such as its creator, title, and so
   forth. The same would apply to any included metadata descriptions
   (see below).  
   
   
** Bibliographies and Citations 
   
   Citations can be thought of as dynamic fields whose formatting is
   generated from separate metadata, based on the requirements of a
   given citation style. A common use case is collaborative editing,
   where each author may use a different editing application and/or
   bibliographic database. ODF metadata should make it possible for
   this sort of collaborative roundtrip editing scenario to work, and
   for the citation fields to remain "live" across applications. This
   might involve also the ability for database applications to store
   their own application-specific metadata along with the more generic
   bibliographic metadata.  
   
** Content Tagging 
   
   User wants to add richerCon metadata to in-document content. In the
   simple case, they highlight text and tag it with some term. In a
   more complex case, they associate more structured metadata with
   content; for example a contact record for a participant in a
   meeting. A similar example might involve a doctor who wishes to
   record diagnostic information about a patient in a structured
   way. In this case, they might invoke a contextual menu item that
   brings up a custom inline field that allows them to choose the
   patient and the diagnosis. The displayed text is then human
   readable, but behind it lies more structured metadata that allows a
   user to access additional information about the patient, or for
   tools to later extract the information for other purposes.

** Enhanced Search 
   
   Effective document search requires richer description than simply
   plain-text content. While basic default metadata such as title or
   creator can be helpful, there is need for the possibility of
   richer, custom, metadata. A legal office may want to include case
   information about a document, information about the plaintiffs, and
   so forth, all of which can facilitate enhanced search. They may
   also want to track relations among documents; for example, that
   between a final version and its draft original.  
   
** Workflow 
   
   Workflow and collaboration solutions depend on portable metadata
   embedded in files. This may include information about who edited a
   document, its status, the rights associated with its use, its
   relationships to other documents or to a collection of documents,
   and so forth.  
   
* Design Goals and Principles 
  
  The following design goals and principles have been extracted from
  the use cases, and are used to frame the requirements.  
  
** Balance Expressiveness and Ease-of-Implementation 
   
   Enhanced metadata support should allow for complex metadata
   description where necessary, but should be designed with
   ease-of-implementation in mind for both third-party and primary
   application developers.  
   
** Enable Extensibility 
   
   Enhanced metadata should provide a strategic innovation opportunity
   for OpenDocument by allowing developers to build compelling
   solutions independent of the OpenDocument standardization process.

** Ensure Interoperability 
   
   Enhanced metadata should provide an infrastructure that assures
   round-tripping interoperability among compliant OpenDocument
   applications.  
   
* Requirements 
  
  The OpenDocument enhanced metadata proposal shall address the
  following requirements:
  
** Standard Model

   Beyond standard core support, there should be clear rules for
   custom extension metadata. These rules must be based on a clearly
   specified formal model, such that metadata extensions: 
   
   1. may be at least displayed without any particular programming
      logic
   2. may reference other resource descriptions1, including across
      partitions of user functionality (a document description or
      bibliographic citation, say, to reference a contact record)
     
   This model may involve adopting all or part of RDF for a general
   extensible description framework, and may include compatibility or
   interoperability with similar RDF-based metadata formats such as
   RSS 1.0, XHTML 2.0 metainformation or XMP.  
   
   This requirement facilitates the following goals: Enable
   Extensibility and Ensure Interoperability.
   
** Default Vocabularies 
   
   OpenDocument should provide a rich set of default properties and
   classes for describing resources that go beyond the current
   support. The proposal should seek to reuse or define mappings to
   existing vocabularies, which may include deepening support for
   Dublin Core and/or adding support for vCard and/or Creative Commons
   to describe specific content of general applicability to office
   documents.  
   
   This requirement facilitates the following goals: Balance
   Expressiveness and Ease-of-Implementation and Ensure
   Interoperability.
   
** Mechanism to Associate Content with Metadata 
   
   Proposal should define valid document objects that can be described
   using enhanced metadata (for example, words, sentences, paragraphs,
   tables, pictures, etc.), as well as a mechanism to associate those
   objects with their descriptions.  
   
   This requirement facilitates the following goals: Enable
   Extensibility and Ensure Interoperability.

** Consistent Identification Scheme 
   
   IRIs provide a well-developed infrastructure for globally unique
   identification which also facilitates integration with
   network-based solutions, and so should be used to identify
   resources. These identifiers can then be used to link document
   content with descriptions, or resource descriptions with other
   resource descriptions.
   
   This requirement facilitates the following goals: Enable
   Extensibility and Ensure Interoperability.
   
** Separate Processing 
   
   Metadata must be able to be processed, extracted, removed and so
   forth independently of the document content.  
   
   This requirement facilitates the following goals: Balance
   Expressiveness and Ease-of-Implementation, Enable Extensibility and
   Ensure Interoperability.
   
** Levels of Conformance 
   
   The enhanced metadata proposal should define levels of conformance
   so that users and developers have expectations about the level of
   support to expect in a given application. At minimum, all
   OpenDocument applications must preserve foreign content, but other
   levels of conformance might relate to display and/or editing of
   such foreign content.  
   
   This requirement facilitates the following goals: Ensure
   Interoperability.
   
** Ability to Add Multiple Annotations to the Same Content 
   
   This requirement falls out of the need to support collaborative
   editing, where the same document can be edited by multiple users,
   either synchronously or asynchronously. Since these users may also
   be applying metadata, the same words, paragraphs, etc., may see the
   same class of metadata applied multiple times. A practical
   consideration is that XML does not allow the same attribute name to
   be applied multiple times to the same element. So a metadata scheme
   which relied exclusively on metadata via attributes would have
   difficulty meeting this requirement.  
   
   This requirement facilitates the following goals: Enable
   Extensibility.

* Bibliography

  [NISO-META] NISO (2004) Understanding Metadata, NISO Press:Bethesda, MD, http://www.niso.org/standards/resources/UnderstandingMetadata.pdf

[-- Attachment #3: test.odt --]
[-- Type: application/zip, Size: 51872 bytes --]

[-- Attachment #4: org-odt.el --]
[-- Type: text/plain, Size: 97391 bytes --]

;;; org-odt.el --- Opendocument export for Org-mode

;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
;;   Free Software Foundation, Inc.

;; Author: Jambunathan K (kjambunathan at gmail dot com)
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 7.01trans
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:

;;; Code:

(require 'org-exp)

(eval-when-compile (require 'cl))

(declare-function org-id-find-id-file "org-id" (id))
(declare-function odtize-region "ext:odtize" (beg end))

(defgroup org-export-odt nil
  "Options specific for ODT export of Org-mode files."
  :tag "Org Export ODT"
  :group 'org-export)

(defcustom org-export-odt-coding-system nil
  "Coding system for ODT export, defaults to `buffer-file-coding-system'."
  :group 'org-export-odt
  :type 'coding-system)

(defcustom org-export-odt-extension "odt"
  "The extension for exported ODT files."
  :group 'org-export-odt
  :type 'string)

(defcustom org-export-odt-xml-declaration
  '(("odt" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
    ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  "The extension for exported ODT files.
%s will be replaced with the charset of the exported file.
This may be a string, or an alist with export extensions
and corresponding declarations."
  :group 'org-export-odt
  :type '(choice
	  (string :tag "Single declaration")
	  (repeat :tag "Dependent on extension"
		  (cons (string :tag "Extension")
			(string :tag "Declaration")))))

(defcustom org-export-odt-tag-class-prefix ""
  "Prefix to class names for TODO keywords.
Each tag gets a class given by the tag itself, with this prefix.
The default prefix is empty because it is nice to just use the keyword
as a class name.  But if you get into conflicts with other, existing
CSS classes, then this prefix can be very useful."
  :group 'org-export-odt
  :type 'string)

(defcustom org-export-odt-todo-kwd-class-prefix ""
  "Prefix to class names for TODO keywords.
Each TODO keyword gets a class given by the keyword itself, with this prefix.
The default prefix is empty because it is nice to just use the keyword
as a class name.  But if you get into conflicts with other, existing
CSS classes, then this prefix can be very useful."
  :group 'org-export-odt
  :type 'string)

(defcustom org-export-odt-title-format
  "\n<text:p text:style-name=\"%s\">%s</text:p>\n"
  "Format for typesetting the document title in ODT export."
  :group 'org-export-odt
  :type 'string)

(defcustom org-export-odt-toplevel-hlevel 2
  "The <H> level for level 1 headings in ODT export.
This is also important for the classes that will be wrapped around headlines
and outline structure.  If this variable is 1, the top-level headlines will
be <h1>, and the corresponding classes will be outline-1, section-number-1,
and outline-text-1.  If this is 2, all of these will get a 2 instead.
The default for this variable is 2, because we use <h1> for formatting the
document title."
  :group 'org-export-odt
  :type 'string)

(defcustom org-export-odt-link-org-files-as-odt t
  "Non-nil means make file links to `file.org' point to `file.odt'.
When org-mode is exporting an org-mode file to ODT, links to
non-odt files are directly put into a href tag in ODT.
However, links to other Org-mode files (recognized by the
extension `.org.) should become links to the corresponding odt
file, assuming that the linked org-mode file will also be
converted to ODT.
When nil, the links still point to the plain `.org' file."
  :group 'org-export-odt
  :type 'boolean)

(defcustom org-export-odt-inline-images 'maybe
  "Non-nil means inline images into exported ODT pages.
This is done using an <img> tag.  When nil, an anchor with href is used to
link to the image.  If this option is `maybe', then images in links with
an empty description will be inlined, while images with a description will
be linked only."
  :group 'org-export-odt
  :type '(choice (const :tag "Never" nil)
		 (const :tag "Always" t)
		 (const :tag "When there is no description" maybe)))

(defcustom org-export-odt-inline-image-extensions
  '("png" "jpeg" "jpg" "gif")
  "Extensions of image files that can be inlined into ODT."
  :group 'org-export-odt
  :type '(repeat (string :tag "Extension")))

(defcustom org-odt-table-tag
  "<table:table table:name=\"%s\" table:style-name=\"%s\">"
  "The ODT tag that is used to start a table.
This must be a <table> tag, but you may change the options like
borders and spacing."
  :group 'org-export-odt
  :type 'string)

(defcustom org-odt-table-header-tags
  '("<table:table-cell table:style-name=\"OrgTblHdrCell%s\"> <text:p>" .
    "</text:p></table:table-cell>")  
  "The opening tag for table header fields.
This is customizable so that alignment options can be specified.
%s will be filled with the scope of the field, either row or col.
See also the variable `org-export-odt-table-use-header-tags-for-first-column'."
  :group 'org-export-tables
  :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))

(defcustom org-odt-table-data-tags
  '("<table:table-cell  table:style-name=\"OrgTblCell%s\"> <text:p>" .
    "</text:p></table:table-cell>")
  "The opening tag for table data fields.
This is customizable so that alignment options can be specified."
  :group 'org-export-tables
  :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))

(defcustom org-odt-table-row-tags
  '("<table:table-row>" . "</table:table-row>")
  "The opening tag for table data fields.
This is customizable so that alignment options can be specified.
Instead of strings, these can be Lisp forms that will be evaluated
for each row in order to construct the table row tags.  During evaluation,
the variable `head' will be true when this is a header line, nil when this
is a body line.  And the variable `nline' will contain the line number,
starting from 1 in the first header line.  For example

  (setq org-odt-table-row-tags
        (cons '(if head
                   \"<tr>\"
                 (if (= (mod nline 2) 1)
                     \"<tr class=\\\"tr-odd\\\">\"
                   \"<tr class=\\\"tr-even\\\">\"))
              \"</tr>\"))

will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  :group 'org-export-tables
  :type '(cons
	  (choice :tag "Opening tag"
		  (string :tag "Specify")
		  (sexp))
	  (choice :tag "Closing tag"
		  (string :tag "Specify")
		  (sexp))))

(defconst org-odt-table-header-rows-tags
  '("<table:table-header-rows>" . "</table:table-header-rows>"))

(defconst org-odt-table-rows-tags
  '("<table:table-rows>" . "</table:table-rows>"))

(defconst org-odt-table-column-tags
  '("<table:table-column table:number-columns-repeated=\"%d\"/>" .
    "</table:table-column"))

(defcustom org-export-odt-table-use-header-tags-for-first-column nil
  "Non-nil means format column one in tables with header tags.
When nil, also column one will use data tags."
  :group 'org-export-tables
  :type 'boolean)

(defgroup org-export-odtize nil
  "Options for processing examples with odtize.el."
  :tag "Org Export Odtize"
  :group 'org-export-odt)

(defcustom org-export-odtize-output-type 'inline-css
  "Output type to be used by odtize when formatting code snippets.
We use as default  `inline-css', in order to make the resulting
ODT self-containing.
However, this will fail when using Emacs in batch mode for export, because
then no rich font definitions are in place.  It will also not be good if
people with different Emacs setup contribute ODT files to a website,
because the fonts will represent the individual setups.  In these cases,
it is much better to let Org/Odtize assign classes only, and to use
a style file to define the look of these classes.
To get a start for your css file, start Emacs session and make sure that
all the faces you are interested in are defined, for example by loading files
in all modes you want.  Then, use the command
\\[org-export-odtize-generate-css] to extract class definitions."
  :group 'org-export-odtize
  :type '(choice (const css) (const inline-css)))

(defcustom org-export-odtize-css-font-prefix "org-"
  "The prefix for CSS class names for odtize font specifications."
  :group 'org-export-odtize
  :type 'string)

(defcustom org-export-odtized-org-css-url nil
  "URL pointing to a CSS file defining text colors for odtized Emacs buffers.
Normally when creating an odtized version of an Org buffer, odtize will
create CSS to define the font colors.  However, this does not work when
converting in batch mode, and it also can look bad if different people
with different fontification setup work on the same website.
When this variable is non-nil, creating an odtized version of an Org buffer
using `org-export-as-org' will remove the internal CSS section and replace it
with a link to this URL."
  :group 'org-export-odtize
  :type '(choice
	  (const :tag "Keep internal css" nil)
	  (string :tag "URL or local href")))

;;; Variables, constants, and parameter plists

(defvar org-export-odt-preamble nil
  "Preamble, to be inserted just after <body>.  Set by publishing functions.
This may also be a function, building and inserting the preamble.")
(defvar org-export-odt-postamble nil
  "Postamble, to be inserted just before </body>.  Set by publishing functions.
This may also be a function, building and inserting the postamble.")
(defvar org-export-odt-auto-preamble t
  "Should default preamble be inserted?  Set by publishing functions.")
(defvar org-export-odt-auto-postamble t
  "Should default postamble be inserted?  Set by publishing functions.")

;;; Hooks

(defvar org-export-odt-after-blockquotes-hook nil
  "Hook run during ODT export, after blockquote, verse, center are done.")

(defvar org-export-odt-final-hook nil
  "Hook run at the end of ODT export, in the new buffer.")

;;; ODT export

(defconst org-odt-sequence-ref-format
  "<text:sequence-ref text:reference-format=\"caption\" text:ref-name=\"%s\">%s</text:sequence-ref>")

(defun org-export-odt-preprocess (parameters)
  "Convert LaTeX fragments to images."
  (when (and org-current-export-file
	     (plist-get parameters :LaTeX-fragments))
    (org-format-latex
     (concat "ltxpng/" (file-name-sans-extension
			(file-name-nondirectory
			 org-current-export-file)))
     org-current-export-dir nil "Creating LaTeX image %s"
     nil nil
     (cond
      ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
      ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
      ((eq (plist-get parameters :LaTeX-fragments) t        ) 'mathjax)
      ((eq (plist-get parameters :LaTeX-fragments) 'dvipng  ) 'dvipng)
      (t nil))))
  (goto-char (point-min))
  (let (label l1)
    (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
      (org-if-unprotected-at (match-beginning 1)
	(setq label (match-string 1))
	(save-match-data
	  (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
	      (setq l1 (substring label (match-beginning 1)))
	    (setq l1 label)))
	;; (replace-match (format "[[#%s][%s]]" label l1) t t)
	
	(replace-match
	 (format org-odt-sequence-ref-format label l1)  t t)))))

;;;###autoload
(defun org-export-as-odt-and-open (arg)
  "Export the outline as ODT and immediately open it with a browser.
If there is an active region, export only the region.
The prefix ARG specifies how many levels of the outline should become
headlines.  The default is 3.  Lower levels will become bulleted lists."
  (interactive "P")
  (org-export-as-odt arg 'hidden)
  (org-open-file buffer-file-name)
  (when org-export-kill-product-buffer-when-displayed
    (kill-buffer (current-buffer))))

;;;###autoload
(defun org-export-as-odt-batch ()
  "Call the function `org-export-as-odt'.
This function can be used in batch processing as:
emacs   --batch
        --load=$HOME/lib/emacs/org.el
        --eval \"(setq org-export-headline-levels 2)\"
        --visit=MyFile --funcall org-export-as-odt-batch"
  (org-export-as-odt org-export-headline-levels 'hidden))

;;;###autoload
(defun org-export-as-odt-to-buffer (arg)
  "Call `org-export-as-odt` with output to a temporary buffer.
No file is created.  The prefix ARG is passed through to `org-export-as-odt'."
  (interactive "P")
  (org-export-as-odt arg nil nil "*Org ODT Export*")
  (when org-export-show-temporary-export-buffer
    (switch-to-buffer-other-window "*Org ODT Export*")))

;;;###autoload
(defun org-replace-region-by-odt (beg end)
  "Assume the current region has org-mode syntax, and convert it to ODT.
This can be used in any buffer.  For example, you could write an
itemized list in org-mode syntax in an ODT buffer and then use this
command to convert it."
  (interactive "r")
  (let (reg odt buf pop-up-frames)
    (save-window-excursion
      (if (org-mode-p)
	  (setq odt (org-export-region-as-odt
		      beg end t 'string))
	(setq reg (buffer-substring beg end)
	      buf (get-buffer-create "*Org tmp*"))
	(with-current-buffer buf
	  (erase-buffer)
	  (insert reg)
	  (org-mode)
	  (setq odt (org-export-region-as-odt
		      (point-min) (point-max) t 'string)))
	(kill-buffer buf)))
    (delete-region beg end)
    (insert odt)))

;;;###autoload
(defun org-export-region-as-odt (beg end &optional body-only buffer)
  "Convert region from BEG to END in org-mode buffer to ODT.
If prefix arg BODY-ONLY is set, omit file header, footer, and table of
contents, and only produce the region of converted text, useful for
cut-and-paste operations.
If BUFFER is a buffer or a string, use/create that buffer as a target
of the converted ODT.  If BUFFER is the symbol `string', return the
produced ODT as a string and leave not buffer behind.  For example,
a Lisp program could call this function in the following way:

  (setq odt (org-export-region-as-odt beg end t 'string))

When called interactively, the output buffer is selected, and shown
in a window.  A non-interactive call will only return the buffer."
  (interactive "r\nP")
  (when (interactive-p)
    (setq buffer "*Org ODT Export*"))
  (let ((transient-mark-mode t) (zmacs-regions t)
	ext-plist rtn)
    (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
    (goto-char end)
    (set-mark (point)) ;; to activate the region
    (goto-char beg)
    (setq rtn (org-export-as-odt
	       nil nil ext-plist
	       buffer body-only))
    (if (fboundp 'deactivate-mark) (deactivate-mark))
    (if (and (interactive-p) (bufferp rtn))
	(switch-to-buffer-other-window rtn)
      rtn)))

(defvar odt-table-tag nil) ; dynamically scoped into this.
(defvar org-par-open nil)

;;; org-odt-cvt-link-fn
(defconst org-odt-cvt-link-fn
   nil
   "Function to convert link URLs to exportable URLs.
Takes two arguments, TYPE and PATH.
Returns exportable url as (TYPE PATH), or nil to signal that it
didn't handle this case.
Intended to be locally bound around a call to `org-export-as-odt'." )

(defun org-odt-cvt-org-as-odt (opt-plist type path)
   "Convert an org filename to an equivalent odt filename.
If TYPE is not file, just return `nil'.
See variable `org-export-odt-link-org-files-as-odt'"

   (save-match-data
      (and
	 org-export-odt-link-org-files-as-odt
	 (string= type "file")
	 (string-match "\\.org$" path)
	 (progn
	    (list
	       "file"
	       (concat
		  (substring path 0 (match-beginning 0))
		  "."
		  (plist-get opt-plist :odt-extension)))))))


;;; org-odt-should-inline-p
(defun org-odt-should-inline-p (filename descp)
   "Return non-nil if link FILENAME should be inlined.
The decision to inline the FILENAME link is based on the current
settings.  DESCP is the boolean of whether there was a link
description.  See variables `org-export-odt-inline-images' and
`org-export-odt-inline-image-extensions'."
   (declare (special
	     org-export-odt-inline-images
	     org-export-odt-inline-image-extensions))
   (and (or (eq t org-export-odt-inline-images)
	    (and org-export-odt-inline-images (not descp)))
	(org-file-image-p
	 filename org-export-odt-inline-image-extensions)))

;;; org-odt-make-link
(defun org-odt-make-link (opt-plist type path fragment
				    desc attr may-inline-p &optional xref)
  "Make an ODT link.
OPT-PLIST is an options list.
TYPE is the device-type of the link (THIS://foo.odt)
PATH is the path of the link (http://THIS#locationx)
FRAGMENT is the fragment part of the link, if any (foo.odt#THIS)
DESC is the link description, if any.
ATTR is a string of other attributes of the a element.
MAY-INLINE-P allows inlining it as an image."

  (setq xref (and org-export-odt-use-bookmarks-for-internal-links xref))

  (declare (special org-par-open))
  (save-match-data
    (let* ((filename path)
	   ;;First pass.  Just sanity stuff.
	   (components-1
	    (cond
	     ((string= type "file")
	      (list
	       type
	       ;;Substitute just if original path was absolute.
	       ;;(Otherwise path must remain relative)
	       (if (file-name-absolute-p path)
		   (concat "file://" (expand-file-name path))
		 path)))
	     ((string= type "")
	      (list nil path))
	     (t (list type path))))

	   ;;Second pass.  Components converted so they can refer
	   ;;to a remote site.
	   (components-2
	    (or
	     (and org-odt-cvt-link-fn
		  (apply org-odt-cvt-link-fn
			 opt-plist components-1))
	     (apply #'org-odt-cvt-org-as-odt
		    opt-plist components-1)
	     components-1))
	   (type    (first  components-2))
	   (thefile (second components-2)))


      ;;Third pass.  Build final link except for leading type
      ;;spec.
      (cond
       ;; FIXME: for internal links assumes thefile as empty
       ((and (or (not type)) fragment)
	(setq thefile
	      (let ((prefix (if xref org-export-odt-bookmark-prefix "#")))
		(concat prefix fragment))))
       
       ((or (string= type "http") (string= type "https"))
	(setq xref nil)
	(if fragment (setq thefile (concat thefile "#" fragment))))
       (t (setq xref nil)))

      ;;Final URL-build, for all types.
      (setq thefile
	    (let
		((str (org-export-odt-format-href thefile)))
	      (if (and type (not (string= "file" type)))
		  (concat type ":" str)
		str)))

      (if (and
	   may-inline-p
	   ;;Can't inline a URL with a fragment.
	   (not fragment))
	  (progn
	    (message "image %s %s" thefile org-par-open)
	    (org-export-odt-format-image thefile org-par-open))

	;; FIXME: how to handle attr in xref case. For now it is
	;; ignored
	(org-odt-format-internal-link
	 thefile (org-export-odt-format-desc desc) xref
	 (and (not xref) (or attr "")))))))


(defconst org-odt-document-content-header
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<office:document-content
    xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
    xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"
    xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"
    xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"
    xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"
    xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"
    xmlns:xlink=\"http://www.w3.org/1999/xlink\"
    xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
    xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
    xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"
    xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"
    xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"
    xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"
    xmlns:math=\"http://www.w3.org/1998/Math/MathML\"
    xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"
    xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"
    xmlns:ooo=\"http://openoffice.org/2004/office\"
    xmlns:ooow=\"http://openoffice.org/2004/writer\"
    xmlns:oooc=\"http://openoffice.org/2004/calc\"
    xmlns:dom=\"http://www.w3.org/2001/xml-events\"
    xmlns:xforms=\"http://www.w3.org/2002/xforms\"
    xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
    xmlns:rpt=\"http://openoffice.org/2005/report\"
    xmlns:of=\"urn:oasis:names:tc:opendocument:xmlns:of:1.2\"
    xmlns:xodt=\"http://www.w3.org/1999/xodt\"
    xmlns:field=\"urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0\"    office:version=\"1.2\">
  <office:scripts/>
  <office:font-face-decls>
    <style:font-face style:name=\"Tahoma1\" svg:font-family=\"Tahoma\"/>
    <style:font-face style:name=\"courier\" svg:font-family=\"courier, monospace\"/>
    <style:font-face style:name=\"Arial Unicode MS\" svg:font-family=\"&apos;Arial Unicode MS&apos;\" style:font-pitch=\"variable\"/>
    <style:font-face style:name=\"HG Mincho Light J\" svg:font-family=\"&apos;HG Mincho Light J&apos;\" style:font-pitch=\"variable\"/>
    <style:font-face style:name=\"Thorndale\" svg:font-family=\"Thorndale\" style:font-family-generic=\"roman\" style:font-pitch=\"variable\"/>
    <style:font-face style:name=\"Times New Roman\" svg:font-family=\"&apos;Times New Roman&apos;\" style:font-family-generic=\"roman\" style:font-pitch=\"variable\"/>
    <style:font-face style:name=\"Albany\" svg:font-family=\"Albany\" style:font-family-generic=\"swiss\" style:font-pitch=\"variable\"/>
    <style:font-face style:name=\"SimSun\" svg:font-family=\"SimSun\" style:font-family-generic=\"system\" style:font-pitch=\"variable\"/>
    <style:font-face style:name=\"Tahoma\" svg:font-family=\"Tahoma\" style:font-family-generic=\"system\" style:font-pitch=\"variable\"/>
  </office:font-face-decls>
  <office:automatic-styles>

  <style:style style:name=\"OrgTblCellDefault\" style:family=\"table-cell\">
   <style:table-cell-properties style:vertical-align=\"middle\" fo:padding=\"0.159cm\" fo:border-left=\"none\" fo:border-right=\"none\" fo:border-top=\"none\" fo:border-bottom=\"none\"/>
  </style:style>

  <style:style style:name=\"OrgTblCellFirstCol\" style:family=\"table-cell\">
   <style:table-cell-properties  style:vertical-align=\"middle\" fo:padding=\"0.159cm\" fo:border-right=\"none\" fo:border-top=\"none\" fo:border-bottom=\"none\" fo:border-left=\"0.035cm solid #808080\"/>
  </style:style>

  <style:style style:name=\"OrgTblCellFirstLastCol\" style:family=\"table-cell\">
   <style:table-cell-properties  style:vertical-align=\"middle\" fo:padding=\"0.159cm\" fo:border-left=\"0.035cm solid #808080\" fo:border-top=\"none\" fo:border-bottom=\"none\" fo:border-right=\"0.035cm solid #808080\"/>
  </style:style>

  <style:style style:name=\"OrgTblHdrCellDefault\" style:family=\"table-cell\">
   <style:table-cell-properties style:vertical-align=\"middle\" fo:padding=\"0.159cm\" fo:border-left=\"none\" fo:border-right=\"none\" fo:border-top=\"0.035cm solid #808080\" fo:border-bottom=\"0.035cm solid #808080\"/>
  </style:style>

  <style:style style:name=\"OrgTblHdrCellFirstCol\" style:family=\"table-cell\">
   <style:table-cell-properties style:vertical-align=\"middle\" fo:padding=\"0.159cm\" fo:border-right=\"none\" fo:border-left=\"0.035cm solid #808080\"  fo:border-top=\"0.035cm solid #808080\" fo:border-bottom=\"0.035cm solid #808080\"/>
  </style:style>

  <style:style style:name=\"OrgTblHdrCellFirstLastCol\" style:family=\"table-cell\">
   <style:table-cell-properties style:vertical-align=\"middle\" fo:padding=\"0.159cm\" fo:border-left=\"0.035cm solid #808080\" fo:border-right=\"0.035cm solid #808080\"  fo:border-top=\"0.035cm solid #808080\" fo:border-bottom=\"0.035cm solid #808080\"/>
  </style:style>

  </office:automatic-styles>
  <office:body>
    <office:text>
      <text:sequence-decls>
	<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Illustration\"/>
	<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Table\"/>
	<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Text\"/>
	<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Drawing\"/>
      </text:sequence-decls>
      <text:section text:style-name=\"Sect1\" text:name=\"content\">")

(defun org-odt-fill-tabs-and-spaces (line)
  (replace-regexp-in-string
   "\\([\t]\\|\\([ ]+\\)\\)" (lambda (s)
	    (cond
	     ((string= s "\t") "<text:tab>")
	     ((> (length s) 1)
	      (format "<text:s text:c=\"%d\"/>" (length s)))
	     (t " "))) line))

;; ODT: FOOTNOTES
(defun org-odt-get-footnote-definitions (lines)
  "Given a list of LINES, return a list of alist footnotes."
  (let ((list nil) line)
    (while (setq line (pop lines))
      (if (string-match "^[ \t]*\\[\\([0-9]+\\)\\] \\(.+\\)" line)
	  (push (cons (match-string 1 line) (match-string 2 line))
		list))) list))

(defun org-odt-format-footnote (n def) 
  (format
   "<text:note text:id=\"fn%s\" text:note-class=\"footnote\">
      <text:note-citation>%s</text:note-citation>
      <text:note-body>
        <text:p text:style-name=\"Footnote\">
         %s
        </text:p>
      </text:note-body>
    </text:note>" n n def))

(defun org-odt-format-footnote-ref (n) 
  (format 
   "<text:span text:style-name=\"OrgSuperscript\"> <text:note-ref text:note-class=\"footnote\" text:reference-format=\"text\" text:ref-name=\"fn%s\"> %s </text:note-ref> </text:span>" n n))



;; email
;; (when (and org-export-email-info email (string-match "\\S-" email))
;; 	(if (listp (split-string email ",+ *"))
;; 	    (mapc (lambda(e))
;; 		  (split-string email ",+ *"))))

;; lang-words: ("en" "Author" "Date" "Table of Contents" "Footnotes")


;; ODT: META FILE
(defun org-export-odt-update-meta-file (opt-plist)
  (with-current-buffer
      (find-file-noselect "meta.xml" (file-name-directory buffer-file-name))
    (let ((date (plist-get opt-plist :date))
	  (author (plist-get opt-plist :author))
	  (language (plist-get opt-plist :language))
	  (email (plist-get opt-plist :email))
	  (keywords (plist-get opt-plist :keywords))
	  (description (plist-get opt-plist :description))
	  (title (plist-get opt-plist :title)))

      (cond
       ((and date (string-match "%" date))
	(setq date (format-time-string date)))
       (date)
       (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))

      ;; FIXME: Revisit these two lines. Seems bogus to me
      (setq date (and org-export-time-stamp-file date))
      (setq author (and org-export-author-info author))

      (insert
       (format "<dc:creator> %s </dc:creator>\n" (or author ""))
       (format "<dc:initial-creator> %s </dc:initial-creator>\n" (or author ""))
       (format "<dc:date> %s </dc:date>\n" (or date ""))
       (format  "<meta:creation-date> %s </meta:creation-date>\n" (or date ""))

       (when org-export-creator-info
	 (format "<meta:generator> Org-%s/Emacs-%s </meta:generator>\n"
		 org-version emacs-version))
       (format "<meta:keyword> %s </meta:keyword>\n" (or keywords ""))

       ;; FIXME: Is subject same as description
       (format "<dc:subject> %s </dc:subject>\n" (or description ""))
       (format "<dc:title> %s </dc:title>\n" (or title ""))))))

;; ODT: TABLE OF CONTENTS
(defcustom org-export-odt-use-bookmarks-for-toc t
  "Export Internal links as bookmarks?.")

(defun org-odt-toc-parse-headline (line level-offset umax-toc lines org-last-level)
  (when (and (string-match org-todo-line-regexp line)
	     (not (get-text-property 0 'org-protected line)))
    (let (level txt todo)
      (setq level
	    (org-tr-level (- (match-end 1) (match-beginning 1) level-offset))

	    txt
	    (save-match-data
	      (org-odt-expand
	       (org-export-cleanup-toc-line (match-string 3 line))))

	    todo
	    (when org-export-mark-todo-in-toc
	      (or (and (match-beginning 2)
		       (not (member (match-string 2 line)
				    org-done-keywords)))
		  ;; TODO, not DONE
		  (and (= level umax-toc)
		       (org-search-todo-below line lines level)))))
      
      (when (<= level umax-toc)
	(org-odt-toc-ascend-descend-levels (- level org-last-level))
	(org-odt-toc-insert-item todo txt (org-section-number level)) level))))

(defun org-odt-toc-check-any-target (line) 
  (while (string-match org-any-target-regexp line)
    (setq line
	  (replace-match
	   (concat "@<span class=\"target\">"
		   (match-string 1 line) "@</span> ") t t line))) line)

(defun org-odt-toc-ascend-descend-levels (cnt) 
  (cond
   ((> cnt 0)
    (while (>= (setq cnt (1- cnt)) 0)
      (org-odt-open-list "OrgBulletedList")
      (org-odt-open-list-item))
    (insert "\n"))
   ((< cnt 0) (setq cnt (- cnt))
    (while (>= (setq cnt (1- cnt)) 0)
      (org-odt-close-list-item)
      (org-odt-close-list)
      (org-odt-close-list-item)
      (org-odt-open-list-item)
      (insert "\n")))
   (t (org-odt-close-list-item) (org-odt-open-list-item))))

(defun org-odt-toc-insert-item (todo txt snumber)
  (when (string-match
	 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
    (setq txt (replace-match  "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>"
			      t nil txt)))
  
  (when (string-match quote-re0 txt)
    (setq txt (replace-match "" t t txt)))
    
  (when org-export-with-section-numbers
    (setq txt (concat snumber " " txt)))

  (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
    (setq txt (replace-match "" t t txt)))

  (org-odt-open-par)
  (let* ((href (replace-regexp-in-string "\\." "_" (format "sec-%s" snumber)))
	 (href (or (cdr (assoc href org-export-preferred-target-alist))  href))
	 (prefix (if org-export-odt-use-bookmarks-for-toc
		     org-export-odt-bookmark-prefix "#"))
	 (href (format "%s%s"  prefix href)))
	 

    ;; FIXME: todo case is not handled right now
    (when todo (setq txt (format "<span class=\"todo\">%s</span>" txt)))

    (insert (org-odt-format-internal-link
	     href txt org-export-odt-use-bookmarks-for-toc "")))
  (org-odt-close-par))

(defun org-odt-insert-toc (the-toc first-heading-pos) 
  (when thetoc
    (goto-char (point-min))
    (if (or (re-search-forward
	     "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
	    (re-search-forward
	     "\\[TABLE-OF-CONTENTS\\]" nil t))
	(progn
	  (goto-char (match-beginning 0))
	  (replace-match ""))
      (goto-char first-heading-pos)
      (when (looking-at "\\s-*</p>")
	(goto-char (match-end 0))
	(insert "\n")))

    (org-odt-open-section "table-of-contents")
    (mapc 'insert thetoc)
    (org-odt-close-section)))

(defun org-odt-do-toc (h lines level-offset umax-toc)
  (let ((org-min-level (org-get-min-level lines level-offset))
	(org-last-level org-min-level))
    (with-temp-buffer
      (org-odt-insert-heading h org-export-odt-toplevel-hlevel)
      (org-odt-open-section "text-table-of-contents")

      ;; FIXME: This shouldn't be zero
      (setq org-last-level 0)
      (setq lines
	    (mapcar
	     '(lambda (line)
		(let ((l (org-odt-toc-parse-headline
			  line level-offset umax-toc lines org-last-level)))

		  (when l
		    (setq org-last-level l)
		    (setq line (org-odt-toc-check-any-target line))))
		line) lines))

      (while (> org-last-level (1- org-min-level))
	(setq org-last-level (1- org-last-level))
	(org-odt-close-list-item)
	(org-odt-close-list))

      (org-odt-close-section)
      (buffer-string))))

;; FINAL CLEANUP
(defun org-odt-delete-empty-paragraphs ()
  (interactive)
  (goto-char (point-min))
  (let ((open "<text:p text:style-name=\"Text_20_body\">")
	(close "</text:p>"))
    (while (re-search-forward (format "%s[ \r\n\t]*%s" open close) nil t)
      ;; (read-string "Enter:")
      (replace-match ""))))

(defun org-odt-delete-empty-lists () 
  (goto-char (point-min))
  (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
    (replace-match "")))

(defun org-odt-fixup-whitespace-placeholders () 
  (goto-char (point-min))
  (let (beg end n)
    (while (setq beg (next-single-property-change (point) 'org-whitespace))
      (setq n (get-text-property beg 'org-whitespace)
	    end (next-single-property-change beg 'org-whitespace))
      (goto-char beg)
      (delete-region beg end)
      (insert (format "<span style=\"visibility:hidden;\">%s</span>"
		      (make-string n ?x))))))

(defun org-odt-misc-cleanup () 
  ;; Remove empty lines at the beginning of the file.
  (goto-char (point-min)) (when (looking-at "\\s-+\n") (replace-match ""))
  ;; Remove display properties
  (remove-text-properties (point-min) (point-max) '(display t)))

(defun org-odt-final-cleanup () 
  (org-odt-delete-empty-paragraphs)
  (org-odt-delete-empty-lists)
  (org-odt-fixup-whitespace-placeholders)
  (org-odt-misc-cleanup))

;;; org-export-as-odt
;;;###autoload
(defun org-export-as-odt (arg &optional hidden ext-plist
			      to-buffer body-only pub-dir)
  "Export the outline as a pretty ODT file.
If there is an active region, export only the region.  The prefix
ARG specifies how many levels of the outline should become
headlines.  The default is 3.  Lower levels will become bulleted
lists.  HIDDEN is obsolete and does nothing.
EXT-PLIST is a property list with external parameters overriding
org-mode's default settings, but still inferior to file-local
settings.  When TO-BUFFER is non-nil, create a buffer with that
name and export to that buffer.  If TO-BUFFER is the symbol
`string', don't leave any buffer behind but just return the
resulting ODT as a string.  When BODY-ONLY is set, don't produce
the file header and footer, simply return the content of
<body>...</body>, without even the body tags themselves.  When
PUB-DIR is set, use this as the publishing directory."
  (interactive "P")
  (run-hooks 'org-export-first-hook)

  ;; Make sure we have a file name when we need it.
  (when (and (not (or to-buffer body-only))
	     (not buffer-file-name))
    (if (buffer-base-buffer)
	(org-set-local 'buffer-file-name
		       (with-current-buffer (buffer-base-buffer)
			 buffer-file-name))
      (error "Need a file name to be able to export")))

  (message "Exporting...")
  (setq-default org-todo-line-regexp org-todo-line-regexp)
  (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  (setq-default org-done-keywords org-done-keywords)
  (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  (let* ((opt-plist
	  (org-export-process-option-filters
	   (org-combine-plists (org-default-export-plist)
			       ext-plist
			       (org-infile-export-plist))))
	 (body-only (or body-only (plist-get opt-plist :body-only)))
	 (odt-extension (plist-get opt-plist :odt-extension))
	 (link-validate (plist-get opt-plist :link-validation-function))
	 valid thetoc first-heading-pos
	 (odd org-odd-levels-only)
	 (region-p (org-region-active-p))
	 (rbeg (and region-p (region-beginning)))
	 (rend (and region-p (region-end)))
	 (subtree-p
	  (if (plist-get opt-plist :ignore-subtree-p)
	      nil
	    (when region-p
	      (save-excursion
		(goto-char rbeg)
		(and (org-at-heading-p)
		     (>= (org-end-of-subtree t t) rend))))))
	 (level-offset (if subtree-p
			   (save-excursion
			     (goto-char rbeg)
			     (+ (funcall outline-level)
				(if org-odd-levels-only 1 0)))
			 0))
	 (opt-plist (setq org-export-opt-plist
			  (if subtree-p
			      (org-export-add-subtree-options opt-plist rbeg)
			    opt-plist)))
	 ;; The following two are dynamically scoped into other
	 ;; routines below.
	 (org-current-export-dir
	  (or pub-dir (org-export-directory :odt opt-plist)))
	 (org-current-export-file buffer-file-name)
	 (level 0) (line "") (origline "") txt todo
	 (umax nil)
	 (umax-toc nil)
	 (target (if to-buffer nil
		   (expand-file-name
		    (concat
		     (file-name-sans-extension
		      (or (and subtree-p
			       (org-entry-get (region-beginning)
					      "EXPORT_FILE_NAME" t))
			  (file-name-nondirectory buffer-file-name)))
		     "." (or "odt" odt-extension))
		    (file-name-as-directory
		     (or pub-dir (org-export-directory :odt opt-plist))))))

	 (current-dir (if buffer-file-name
	 		  (file-name-directory buffer-file-name)
	 		default-directory))
	 
	 (outdir (org-export-odt-outdir-init))
	 (filename (expand-file-name "content.xml" outdir))
	 (buffer (if to-buffer
		     (cond
		      ((eq to-buffer 'string) (get-buffer-create "*Org ODT Export*"))
		      (t (get-buffer-create to-buffer)))
		   (find-file-noselect filename)))
	 (org-levels-open (make-vector org-level-max nil))
	 (language    (plist-get opt-plist :language))
	 (title       (or (and subtree-p (org-export-get-title-from-subtree))
			  (plist-get opt-plist :title)
			  (and (not body-only)
			       (not
				(plist-get opt-plist :skip-before-1st-heading))
			       (org-export-grab-title-from-buffer))
			  (and buffer-file-name
			       (file-name-sans-extension
				(file-name-nondirectory buffer-file-name)))
			  "UNTITLED"))
	 (dummy (setq opt-plist (plist-put opt-plist :title title)))
	 ;; ODT FIXME: figure this out
	 ;; (odt-table-tag (plist-get opt-plist :odt-table-tag))
	 (quote-re0   (concat "^[ \t]*" org-quote-string "\\>"))
	 (quote-re    (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
	 (inquote     nil)
	 (infixed     nil)
	 (inverse     nil)
	 (in-local-list nil)
	 (local-list-type nil)
	 (local-list-indent nil)
	 (llt org-plain-list-ordered-item-terminator)
	 (lang-words  nil)
	 (head-count  0) 
	 (start       0)
	 (coding-system (and (boundp 'buffer-file-coding-system)
			     buffer-file-coding-system))
	 (coding-system-for-write (or org-export-odt-coding-system
				      coding-system))
	 (save-buffer-coding-system (or org-export-odt-coding-system
					coding-system))
	 (charset (and coding-system-for-write
		       (fboundp 'coding-system-get)
		       (coding-system-get coding-system-for-write
					  'mime-charset)))
	 (region
	  (buffer-substring
	   (if region-p (region-beginning) (point-min))
	   (if region-p (region-end) (point-max))))
	 (org-export-have-math nil)
	 (lines
	  (org-split-string
	   (org-export-preprocess-string
	    region
	    :emph-multiline t
	    :for-odt t
	    :skip-before-1st-heading
	    (plist-get opt-plist :skip-before-1st-heading)
	    :drawers (plist-get opt-plist :drawers)
	    :todo-keywords (plist-get opt-plist :todo-keywords)
	    :tags (plist-get opt-plist :tags)
	    :priority (plist-get opt-plist :priority)
	    :footnotes (plist-get opt-plist :footnotes)
	    :timestamps (plist-get opt-plist :timestamps)
	    :archived-trees
	    (plist-get opt-plist :archived-trees)
	    :select-tags (plist-get opt-plist :select-tags)
	    :exclude-tags (plist-get opt-plist :exclude-tags)
	    :add-text
	    (plist-get opt-plist :text)
	    :LaTeX-fragments
	    (plist-get opt-plist :LaTeX-fragments))
	   "[\r\n]"))
	 (mathjax "")
	 table-open type
	 table-buffer table-orig-buffer
	 ind item-type starter
	 rpl path attr desc descp desc1 desc2 link nodesc
	 snumber fnc item-tag item-number
	 footnotes footref-seen
	 id-file href
	 footnote-def footnote-list
	 )

    (setq footnote-list
	  (org-odt-get-footnote-definitions lines))

    (let ((inhibit-read-only t))
      (org-unmodified
       (remove-text-properties (point-min) (point-max)
			       '(:org-license-to-kill t))))

    (message "Exporting...")

    (org-init-section-numbers)

    ;; Get the language-dependent settings
    (setq lang-words (or (assoc language org-export-language-setup)
			 (assoc "en" org-export-language-setup)))

    ;; Switch to the output buffer
    (set-buffer buffer)
    (let ((inhibit-read-only t)) (erase-buffer))
    (fundamental-mode)
    (org-install-letbind)

    (and (fboundp 'set-buffer-file-coding-system)
	 (set-buffer-file-coding-system coding-system-for-write))

    (let (style (case-fold-search nil)
		(org-odd-levels-only odd))
      ;; create local variables for all options, to make sure all called
      ;; functions get the correct information
      (mapc (lambda (x)
	      (set (make-local-variable (nth 2 x))
		   (plist-get opt-plist (car x))))
	    org-export-plist-vars)
      (setq umax (if arg (prefix-numeric-value arg)
		   org-export-headline-levels))
      (setq umax-toc (if (integerp org-export-with-toc)
			 (min org-export-with-toc umax)
		       umax))
      (unless body-only
	(insert org-odt-document-content-header)
        (org-export-odt-insert-plist-item opt-plist :preamble opt-plist)

	;; FIXME: (plist-get opt-plist :auto-preamble)?
	(when (and org-export-odt-auto-preamble title)
	  (insert (format org-export-odt-title-format
			  "Heading_20_1.title" (org-odt-expand title)))))

      (setq thetoc
	    (and org-export-with-toc (not body-only)
		 (org-odt-do-toc (nth 3 lang-words)
				 lines level-offset umax-toc)))

      (setq head-count 0)
      (org-init-section-numbers)

      (org-odt-do-open-par)

      (while (setq line (pop lines) origline line)
	(catch 'nextline

	  ;; end of quote section?
	  (when (and inquote (string-match "^\\*+ " line))
	    (insert "</pre>\n")
	    (org-odt-do-open-par)
	    (setq inquote nil))
	  ;; inside a quote section?
	  (when inquote
	    (insert (org-odt-protect line) "\n")
	    (throw 'nextline nil))

	  ;; Fixed-width, verbatim lines (examples)
	  (when (and org-export-with-fixed-width
		     (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
	    (when (not infixed)
	      (setq infixed t)
	      (org-odt-do-open-par "Example"))
	    (insert (org-odt-protect (match-string 3 line)) "\n")
	    (when (or (not lines)
		      (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
					 (car lines))))
	      (setq infixed nil)
	      (org-odt-do-open-par))
	    (throw 'nextline nil))

	  ;; Explicit list closure
	  (when (equal "ORG-LIST-END" line)
	    (while local-list-indent
	      (org-odt-do-close-list-item (car local-list-type))
	      ;; (insert (format "</%sl>\n" (car local-list-type)))
	      (org-odt-close-list)
	      (pop local-list-type)
	      (pop local-list-indent))
	    (setq in-local-list nil)
	    (org-odt-do-open-par)
	    (throw 'nextline nil))

	  ;; Protected ODT

	  ;; FIXME: take care of leading spaces? Or better still
	  ;; find a better textual environment
	  (when (get-text-property 0 'org-protected line)
	    (let (par (ind (get-text-property 0 'original-indentation line)))
	      (when (re-search-backward
		     "\\(<text:p text:style-name=\"Text_20_body\">\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
		(setq par (match-string 1))
		(replace-match "\\2\n"))
	      ;; (insert line "\n")

	      (insert  (org-odt-fill-tabs-and-spaces line) "</text:p>")
	      (while (and lines
			  (or (= (length (car lines)) 0)
			      (not ind)
			      (equal ind (get-text-property 0 'original-indentation (car lines))))
			  (or (= (length (car lines)) 0)
			      (get-text-property 0 'org-protected (car lines))))
		(org-odt-open-par  "OrgSourceBlock")
		(insert (org-odt-fill-tabs-and-spaces (pop lines)))
		(org-odt-close-par))
	      
	      ;; this terminates the example section
	      (and par (org-odt-open-par  "Text_20_body")))
	    (throw 'nextline nil))

	  ;; Blockquotes, verse, and center

	  (setq style nil)
	  (cond
	   ((equal "ORG-BLOCKQUOTE-START" line)
	    (setq style "Quotations"))
	   ((equal "ORG-CENTER-START" line)
	    (setq style "Orgmode-Center"))
	   ((equal "ORG-VERSE-START" line)
	    (setq inverse t)
	    (setq style "Orgmode-Verse")))

	  (when style
	    (org-odt-do-open-par style)
	    (throw 'nextline nil))


	  (when (or (equal "ORG-BLOCKQUOTE-END" line)
		    (equal "ORG-CENTER-END" line)
		    (equal "ORG-VERSE-END" line))
	    (org-odt-do-open-par)
	    (setq inverse nil)
	    (throw 'nextline nil))

	  (run-hooks 'org-export-odt-after-blockquotes-hook)
	  (when inverse
	    (let ((i (org-get-string-indentation line)))
	      (if (> i 0)
		  ;; (setq line (concat (mapconcat 'identity
		  ;; 				(make-list (* 2 i) "\\nbsp") "")
		  ;; 		     " " (org-trim line)))
		  (setq line (concat
			      (format "<text:s text:c=\"%d\"/>" (* 2 i))
			      " " (org-trim line))))
	      (unless (string-match "\\\\\\\\[ \t]*$" line)
		(setq line (concat line "\\\\")))))

	  ;; make targets to anchors
	  (setq start 0)
	  (while (string-match
		  "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
	    (cond
	     ((get-text-property (match-beginning 1) 'org-protected line)
	      (setq start (match-end 1)))
	     ((match-end 2)
	      (setq line (replace-match
			  (format
			   "@<a name=\"%s\" id=\"%s\">@</a>"
			   (org-solidify-link-text (match-string 1 line))
			   (org-solidify-link-text (match-string 1 line)))
			  t t line)))
	     ((and org-export-with-toc (equal (string-to-char line) ?*))
	      ;; FIXME: NOT DEPENDENT on TOC?????????????????????
	      ;; headline that is radioed
	      (setq line (replace-match (match-string 1 line) t t line)))
	     (t
	      (setq line (replace-match
			  (concat "@<a name=\""
				  (org-solidify-link-text (match-string 1 line))
				  "\" class=\"target\">" (match-string 1 line)
				  "@</a> ")
			  t t line)))))

	  (setq line (org-odt-handle-time-stamps line))

	  ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
	  ;; handle @<..> ODT tags (replace "@&gt;..&lt;" by "<..>")
	  ;; Also handle sub_superscripts and checkboxes
	  (or (string-match org-table-hline-regexp line)
	      (setq line (org-odt-expand line)))

	  ;; Format the links
	  (setq start 0)
	  (while (string-match org-bracket-link-analytic-regexp++ line start)
	    (setq start (match-beginning 0))
	    (setq path (save-match-data (org-link-unescape
					 (match-string 3 line))))
	    (setq type (cond
			((match-end 2) (match-string 2 line))
			((save-match-data
			   (or (file-name-absolute-p path)
			       (string-match "^\\.\\.?/" path)))
			 "file")
			(t "internal")))
	    (setq path (org-extract-attributes (org-link-unescape path)))
	    (setq nodesc (get-text-property 0 'org-no-description path))
	    (setq attr (get-text-property 0 'org-attributes path))
	    (setq desc1 (if (match-end 5) (match-string 5 line))
		  desc2 (if (match-end 2) (concat type ":" path) path)
		  descp (and desc1 (not (equal desc1 desc2)))
		  desc (or desc1 desc2))
	    ;; Make an image out of the description if that is so wanted
	    (when (and descp (org-file-image-p
			      desc org-export-odt-inline-image-extensions))
	      (save-match-data
		(if (string-match "^file:" desc)
		    (setq desc (substring desc (match-end 0)))))
	      (setq desc (org-add-props
			     (concat "<img src=\"" desc "\"/>")
			     '(org-protected t))))
	    (cond
	     ((equal type "internal")
	      (let
		  ((frag-0
		    (if (= (string-to-char path) ?#) (substring path 1) path))
		   (xref nodesc))
		(setq rpl
		      (org-odt-make-link
		       opt-plist
		       ""
		       ""
		       (org-solidify-link-text
			(save-match-data (org-link-unescape frag-0))
			nil)
		       desc attr nil xref))))
	     ((and (equal type "id")
		   (setq id-file (org-id-find-id-file path)))
	      ;; This is an id: link to another file (if it was the same file,
	      ;; it would have become an internal link...)
	      (save-match-data
		(setq id-file (file-relative-name
			       id-file
			       (file-name-directory org-current-export-file)))
		(setq rpl
		      (org-odt-make-link opt-plist
					 "file" id-file
					 (concat (if (org-uuidgen-p path) "ID-") path)
					 desc
					 attr
					 nil))))
	     ((member type '("http" "https"))
	      ;; standard URL, can inline as image
	      (setq rpl
		    (org-odt-make-link opt-plist
				       type path nil
				       desc
				       attr
				       (org-odt-should-inline-p path descp))))
	     ((member type '("ftp" "mailto" "news"))
	      ;; standard URL, can't inline as image
	      (setq rpl
		    (org-odt-make-link opt-plist
				       type path nil
				       desc
				       attr
				       nil)))

	     ((string= type "coderef")
	      (let*
		  ((coderef-str (format "coderef-%s" path))
		   (attr-1
		    (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
			    coderef-str coderef-str)))
		(setq rpl
		      (org-odt-make-link opt-plist
					 type "" coderef-str
					 (format
					  (org-export-get-coderef-format
					   path
					   (and descp desc))
					  (cdr (assoc path org-export-code-refs)))
					 attr-1
					 nil))))

	     ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
	      ;; The link protocol has a function for format the link
	      (setq rpl
		    (save-match-data
		      (funcall fnc (org-link-unescape path) desc1 'odt))))

	     ((string= type "file")
	      ;; FILE link
	      (save-match-data
		(let*
		    ((components
		      (if
			  (string-match "::\\(.*\\)" path)
			  (list
			   (replace-match "" t nil path)
			   (match-string 1 path))
			(list path nil)))

		     ;;The proper path, without a fragment
		     (path-1
		      (first components))

		     ;;The raw fragment
		     (fragment-0
		      (second components))

		     ;;Check the fragment.  If it can't be used as
		     ;;target fragment we'll pass nil instead.
		     (fragment-1
		      (if
			  (and fragment-0
			       (not (string-match "^[0-9]*$" fragment-0))
			       (not (string-match "^\\*" fragment-0))
			       (not (string-match "^/.*/$" fragment-0)))
			  (org-solidify-link-text
			   (org-link-unescape fragment-0))
			nil))
		     (desc-2
		      ;;Description minus "file:" and ".org"
		      (if (string-match "^file:" desc)
			  (let
			      ((desc-1 (replace-match "" t t desc)))
			    (if (string-match "\\.org$" desc-1)
				(replace-match "" t t desc-1)
			      desc-1))
			desc)))

		  (setq rpl
			(if
			    (and
			     (functionp link-validate)
			     (not (funcall link-validate path-1 current-dir)))
			    desc
			  (org-odt-make-link opt-plist
					     "file" path-1 fragment-1 desc-2 attr
					     (org-odt-should-inline-p path-1 descp)))))))

	     (t
	      ;; just publish the path, as default
	      (setq rpl (concat "<i>&lt;" type ":"
				(save-match-data (org-link-unescape path))
				"&gt;</i>"))))
	    (setq line (replace-match rpl t t line)
		  start (+ start (length rpl))))

	  ;; TODO items
	  (if (and (string-match org-todo-line-regexp line)
		   (match-beginning 2))

	      (setq line
		    (concat (substring line 0 (match-beginning 2))
			    "<span class=\""
			    (if (member (match-string 2 line)
					org-done-keywords)
				"done" "todo")
			    " " (match-string 2 line)
			    "\"> " (org-export-odt-get-todo-kwd-class-name
				    (match-string 2 line))
			    "</span>" (substring line (match-end 2)))))

	  ;; Does this contain a reference to a footnote?
	  (when org-export-with-footnotes
	    (setq start 0)
	    (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
	      (if (get-text-property (match-beginning 2) 'org-protected line)
		  (setq start (match-end 2))
		(let* ((n (match-string 2 line))
		       (def (cdr (assoc n footnote-list))))
		  (cond
		   ((assoc n footref-seen)
		    (setq line (replace-match
				(format "%s%s" (or (match-string 1 line) "")
					(org-odt-format-footnote-ref n)) t t line)))
		   (t
		    (push (cons n 1) footref-seen)
		    (setq
		     line (replace-match
			   (format "%s%s" (or (match-string 1 line) "")
				   (org-odt-format-footnote n def))
			   t t line))))))))

	  (cond
	   ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
	    ;; This is a headline
	    (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
					 level-offset))
		  txt (match-string 2 line))
	    (if (string-match quote-re0 txt)
		(setq txt (replace-match "" t t txt)))
	    (if (<= level (max umax umax-toc))
		(setq head-count (+ head-count 1)))

	    ;; FIXME: Empty lines before the first headline creates a
	    ;; paragraph. Unless they are closed, it interferes with
	    ;; the placement of table of contents. For now just close
	    ;; such paragraphs.
	    (org-odt-close-par-maybe)
	    (setq first-heading-pos (or first-heading-pos (point)))
	    (org-odt-level-start level txt umax
				 (and org-export-with-toc (<= level umax))
				 head-count)

	    ;; QUOTES
	    (when (string-match quote-re line)
	      (org-odt-close-par-maybe)
	      (insert "<pre>")
	      (setq inquote t)))

	   ((and org-export-with-tables
		 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
	    (when (not table-open)
	      ;; New table starts
	      (setq table-open t table-buffer nil table-orig-buffer nil))

	    ;; Accumulate lines
	    (setq table-buffer (cons line table-buffer)
		  table-orig-buffer (cons origline table-orig-buffer))
	    (when (or (not lines)
		      (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
					 (car lines))))
	      (setq table-open nil
		    table-buffer (nreverse table-buffer)
		    table-orig-buffer (nreverse table-orig-buffer))
	      (org-odt-close-par-maybe)
	      (insert (org-format-table-odt table-buffer table-orig-buffer))))
	   (t
	    ;; Normal lines
	    (when (string-match
		   (cond
		    ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
		    ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
		    ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
		    (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
		   line)
	      (setq ind (or (get-text-property 0 'original-indentation line)
			    (org-get-string-indentation line))
		    item-type (if (match-beginning 4) "o" "u")
		    starter (if (match-beginning 2)
				(substring (match-string 2 line) 0 -1))
		    line (substring line (match-beginning 5))
		    item-number nil
		    item-tag nil)
	      (if (string-match "\\[@\\(?:start:\\)?\\([0-9]+\\)\\][ \t]?" line)
		  (setq item-number (match-string 1 line)
			line (replace-match "" t t line)))
	      (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
		  (setq item-type "d"
			item-tag (match-string 1 line)
			line (substring line (match-end 0))))
	      (cond
	       ((and starter
		     (or (not in-local-list)
			 (> ind (car local-list-indent))))
		;; Start new (level of) list


		(org-odt-close-par-maybe)

		(cond
		 ((equal item-type "u") (org-odt-do-open-list item-type))
		 ((equal item-type "o") (org-odt-do-open-list item-type))

		 ;; TODO
		 ((and (equal item-type "o") item-number)
		  (format "<ol>\n<li value=\"%s\">\n" item-number))
		 
		 
		 ((equal item-type "d")
		  (org-odt-do-open-description-list item-tag)))

		(push item-type local-list-type)
		(push ind local-list-indent)
		(setq in-local-list t))
	       ;; Continue list
	       (starter
		;; terminate any previous sublist but first ensure
		;; list is not ill-formed.
		(let ((min-ind (apply 'min local-list-indent)))
		  (when (< ind min-ind) (setq ind min-ind)))
		(while (< ind (car local-list-indent))

		  (org-odt-do-close-list-item (car local-list-type))
		  (org-odt-close-list)
		  (pop local-list-type) (pop local-list-indent)
		  (setq in-local-list local-list-indent))

		;; insert new item
		(org-odt-do-close-list-item (car local-list-type))

		(cond
		 ((equal (car local-list-type) "d")
		  (org-odt-do-open-description-list-item item-tag))

		 ;; TODO
		 ((and (equal item-type "o") item-number)
		  (format "<li value=\"%s\">\n" item-number))
		 
		 (t (org-odt-do-open-list-item)))))
	      (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
		  (setq line
			(replace-match
			 (if (equal (match-string 1 line) "X")
			     "<b>[X]</b>"
			   "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
			 t t line))))

	    ;; Horizontal line
	    (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
	      (if org-par-open
		  (insert "\n</p>\n<hr/>\n<p>\n")
		(insert "\n<hr/>\n"))
	      (throw 'nextline nil))

	    ;; Empty lines start a new paragraph.  If hand-formatted lists
	    ;; are not fully interpreted, lines starting with "-", "+", "*"
	    ;; also start a new paragraph.
	    (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-odt-do-open-par))

	    ;; Is this the start of a footnote?
	    (when org-export-with-footnotes
	      (when (and (boundp 'footnote-section-tag-regexp)
			 (string-match (concat "^" footnote-section-tag-regexp)
				       line))
		;; ignore this line
		(throw 'nextline nil))
	      (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
		(org-odt-close-par-maybe)
		;; ignore this line
		(throw 'nextline nil)))
	    ;; Check if the line break needs to be conserved
	    (cond
	     ((string-match "\\\\\\\\[ \t]*$" line)
	      (setq line (replace-match "<text:line-break/>" t t line)))
	     (org-export-preserve-breaks
	      (setq line (concat line "<text:line-break/>"))))

	    ;; Check if a paragraph should be started
	    (let ((start 0))
	      (while (and org-par-open
			  (string-match "\\\\par\\>" line start))
		;; Leave a space in the </p> so that the footnote matcher
		;; does not see this.
		(if (not (get-text-property (match-beginning 0)
					    'org-protected line))
		    (setq line (replace-match "</p ><p >" t t line)))
		(setq start (match-end 0))))

	    (insert line "\n")))))

      ;; Properly close all local lists and other lists
      (when inquote
	(insert "</pre>\n")
	(org-odt-do-open-par))

      (org-odt-level-start 1 nil umax
			   (and org-export-with-toc (<= level umax))
			   head-count)
      ;; the </div> to close the last text-... div.
      (when (and (> umax 0) first-heading-pos) (insert "</text:section>\n"))

      (let ((bib (org-export-odt-get-bibliography)))
	(when bib
	  (insert "\n" bib "\n")))

      (unless body-only
	(org-export-odt-update-meta-file opt-plist)

        (org-export-odt-insert-plist-item opt-plist :postamble opt-plist)

	;; odt code
	;; (insert "\n</div>")
	(org-odt-close-section)

	;; odt code
	;; (insert "\n</body>")
	;; (insert "\n</odt>\n")

	(insert "\n</office:text>")
	(insert "\n</office:body>")
	(insert "\n</office:document-content>\n"))

      (unless (plist-get opt-plist :buffer-will-be-killed)
	(normal-mode)
	(if (eq major-mode (default-value 'major-mode))
	    (odt-mode)))

      (org-odt-insert-toc thetoc first-heading-pos)

      (org-odt-final-cleanup)

      ;; Run the hook
      (run-hooks 'org-export-odt-final-hook)
      (or to-buffer
	  (progn
	    (org-export-odt-zip outdir target)
	    ;; FIXME: use find-file-noselect?
	    (find-file target)))
      (goto-char (point-min))
      (or (org-export-push-to-kill-ring "ODT")
	  (message "Exporting... done"))
      (if (eq to-buffer 'string)
	  (prog1 (buffer-substring (point-min) (point-max))
	    (kill-buffer (current-buffer)))
	(current-buffer)))))

(defun org-export-odt-insert-plist-item (plist key &rest args)
  (let ((item (plist-get plist key)))
    (cond ((functionp item)
           (apply item args))
          (item
           (insert item)))))

(defun org-export-odt-format-href (s)
  "Make sure the S is valid as a href reference in an XODT document."
  (save-match-data
    (let ((start 0))
      (while (string-match "&" s start)
	(setq start (+ (match-beginning 0) 3)
	      s (replace-match "&amp;" t t s)))))
  s)

(defun org-export-odt-format-desc (s)
  "Make sure the S is valid as a description in a link."
  (if (and s (not (get-text-property 1 'org-protected s)))
      (save-match-data
	(org-odt-do-expand s))
    s))

;; DON'T DISTURB
;; (defun org-export-odt-format-image (src par-open)
;;   "Create image tag with source and attributes."
;;   (save-match-data
;;     (if (string-match "^ltxpng/" src)
;; 	(format "<img src=\"%s\" alt=\"%s\"/>"
;;                 src (org-find-text-property-in-string 'org-latex-src src))
;;       (let* ((caption (org-find-text-property-in-string 'org-caption src))
;; 	     (attr (org-find-text-property-in-string 'org-attributes src))
;; 	     (label (org-find-text-property-in-string 'org-label src)))
;; 	(setq caption (and caption (org-odt-do-expand caption)))
;; 	(concat
;; 	(if caption
;; 	    (format "%s<div %sclass=\"figure\">
;; <p>"
;; 		    (if org-par-open "</p>\n" "")
;; 		    (if label (format "id=\"%s\" " label) "")))
;; 	(format "<img src=\"%s\"%s />"
;; 		src
;; 		(if (string-match "\\<alt=" (or attr ""))
;; 		    (concat " " attr )
;; 		  (concat " " attr " alt=\"" src "\"")))
;; 	(if caption
;; 	    (format "</p>%s
;; </div>%s"
;; 		(concat "\n<p>" caption "</p>")
;; 		(if org-par-open "\n<p>" ""))))))))

(defun org-export-odt-format-image (src par-open)
  "Create image tag with source and attributes."
  (save-match-data
    (if (string-match "^ltxpng/" src)
	(format "<img src=\"%s\" alt=\"%s\"/>"
                src (org-find-text-property-in-string 'org-latex-src src))
      (let* ((caption (org-find-text-property-in-string 'org-caption src))
	     (attr (org-find-text-property-in-string 'org-attributes src))
	     (label (org-find-text-property-in-string 'org-label src)))
	(setq caption (and caption (org-odt-do-expand caption)))

	(org-odt-embed-image src)))))

(defun org-export-odt-get-bibliography ()
  "Find bibliography, cut it out and return it."
  (catch 'exit
    (let (beg end (cnt 1) bib)
      (save-excursion
	(goto-char (point-min))
	(when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
	  (setq beg (match-beginning 0))
	  (while (re-search-forward "</?div\\>" nil t)
	    (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
	    (when (= cnt 0)
	      (and (looking-at ">") (forward-char 1))
	      (setq bib (buffer-substring beg (point)))
	      (delete-region beg (point))
	    (throw 'exit bib))))
	nil))))

(defvar org-table-number-regexp) ; defined in org-table.el
(defun org-format-table-odt (lines olines)
  "Find out which ODT converter to use and return the ODT code."
  (if (stringp lines)
      (setq lines (org-split-string lines "\n")))
  (if (string-match "^[ \t]*|" (car lines))
      ;; A normal org table
      (org-format-org-table-odt lines)
    ;; Table made by table.el - test for spanning
    (let* ((hlines (delq nil (mapcar
			      (lambda (x)
				(if (string-match "^[ \t]*\\+-" x) x
				  nil))
			      lines)))
	   (first (car hlines))
	   (ll (and (string-match "\\S-+" first)
		    (match-string 0 first)))
	   (re (concat "^[ \t]*" (regexp-quote ll)))
	   (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
				       hlines))))
      (if (and (not spanning)
	       (not org-export-prefer-native-exporter-for-tables))
	  ;; We can use my own converter with ODT conversions
	  (org-format-table-table-odt lines)
	;; Need to use the code generator in table.el, with the original text.
	(org-format-table-table-odt-using-table-generate-source olines)))))

(defvar org-table-number-fraction) ; defined in org-table.el


(defconst org-odt-table-caption-format
    "<text:p text:style-name=\"Table\">Table <text:sequence text:ref-name=\"%s\" text:name=\"Table\" text:formula=\"ooow:Table+1\" style:num-format=\"1\">%s </text:sequence>%s</text:p>")

(defun org-format-org-table-odt (lines &optional splice)
  "Format a table into ODT."
  (require 'org-table)
  ;; Get rid of hlines at beginning and end
  (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  (setq lines (nreverse lines))
  (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  (setq lines (nreverse lines))
  (when org-export-table-remove-special-lines
    ;; Check if the table has a marking column.  If yes remove the
    ;; column and the special lines
    (setq lines (org-table-clean-before-export lines)))

  (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
	 (label (org-find-text-property-in-string 'org-label (car lines)))

	 ;; ODT FIXME: Attributes
	 ;; (attributes (org-find-text-property-in-string 'org-attributes
	 ;; 					       (car lines)))
	 ;; (odt-table-tag (org-export-splice-attributes
	 ;; 		 odt-table-tag attributes))
	 (head (and org-export-highlight-first-table-line
		    (delq nil (mapcar
			       (lambda (x) (string-match "^[ \t]*|-" x))
			       (cdr lines)))))

	 (nline 0) fnum nfields i
	 tbopen line fields odt gr colgropen rowstart rowend
	 (style '()))
    (setq caption (and caption (org-odt-do-expand caption)))
    (if splice (setq head nil))
    (unless splice
      (push (if head
		(car org-odt-table-header-rows-tags)
	      (car org-odt-table-rows-tags)) odt))
    (setq tbopen t)
    (while (setq line (pop lines))
      (catch 'next-line
	(if (string-match "^[ \t]*|-" line)
	    (progn
	      (unless splice
		(push (if head
			  (cdr org-odt-table-header-rows-tags)
			(cdr org-odt-table-rows-tags))
		      odt)
		(if lines
		    (push (car org-odt-table-rows-tags) odt)
		  (setq tbopen nil)))
	      (setq head nil) ;; head ends here, first time around
	      ;; ignore this line
	      (throw 'next-line t)))
	;; Break the line into fields
	(setq fields (org-split-string line "[ \t]*|[ \t]*"))
	(unless fnum (setq fnum (make-vector (length fields) 0)
			   nfields (length fnum)))
	(setq nline (1+ nline) i -1
	      rowstart (eval (car org-odt-table-row-tags))
	      rowend (eval (cdr org-odt-table-row-tags)))
	(push
	 (concat
	  rowstart
	  (mapconcat
	   (lambda (x)
	     (setq i (1+ i))
	     (if (and (< i nfields) ; make sure no rogue line causes an error here
		      (string-match org-table-number-regexp x))
		 (incf (aref fnum i)))
	     (cond
	      ;; ODT FIXME
	      (head
	       (concat
	      	(format (car org-odt-table-header-tags)
			(or (nth i style) "Default"))
	      	x
	      	(cdr org-odt-table-header-tags)))
	      ;; ((and (= i 0) org-export-odt-table-use-header-tags-for-first-column)
	      ;;  (concat
	      ;; 	(format (car org-odt-table-header-tags) "row")
	      ;; 	x
	      ;; 	(cdr org-odt-table-header-tags)))
	      (t
	       (concat
		(format (car org-odt-table-data-tags)
			(or (nth i style) "Default")) x
		       (cdr org-odt-table-data-tags)))))
	   fields "")
	  rowend)
	 odt)))
    (unless splice
      (if tbopen (push (cdr org-odt-table-rows-tags) odt)))
    (unless splice
      (push "</table:table>\n" odt))
    (setq odt (nreverse odt))
    (unless splice
      ;; ODT FIXME: colgroups
      ;; Put in col tags with the alignment (unfortunately often ignored...)
      (unless (car org-table-colgroup-info)
      	(setq org-table-colgroup-info
      	      (cons :start (cdr org-table-colgroup-info))))

      ;; (push (mapconcat
      ;; 	     (lambda (x)
      ;; 	       (setq gr (pop org-table-colgroup-info))
      ;; 	       (format "%s<col align=\"%s\" />%s"
      ;; 	       	       (if (memq gr '(:start :startend))
      ;; 	       		   (prog1
      ;; 	       		       (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
      ;; 	       		     (setq colgropen t))
      ;; 	       		 "")
      ;; 	       	       (if (> (/ (float x) nline) org-table-number-fraction)
      ;; 	       		   "right" "left")
      ;; 	       	       (if (memq gr '(:end :startend))
      ;; 	       		   (progn (setq colgropen nil) "</colgroup>")
      ;; 	       		 ""))
      ;; 	       )
      ;; 	     fnum "")
      ;; 	    odt)
      ;; (if colgropen (setq odt (cons (car odt) (cons "</colgroup>" (cdr odt)))))

      ;; ODT FIXME: Revisit table:table-column
      (push (format (car org-odt-table-column-tags)  (length fnum)) odt)

      ;; Since the output of ODT table formatter can also be used in
      ;; DocBook document, we want to always include the caption to make
      ;; DocBook XML file valid.

      ;; ODT FIXME: caption and labels

      (push (format org-odt-table-tag  "TableName" "TableStyle") odt)
      (if label
      	  (push (format org-odt-table-caption-format
      			label label (or caption "")) odt)
      	(push (format org-odt-table-caption-format
      		      "FIXME" "FIXME" (or caption "")) odt))
      )
    (concat (mapconcat 'identity odt "\n") "\n")))

(defun org-export-splice-attributes (tag attributes)
  "Read attributes in string ATTRIBUTES, add and replace in ODT tag TAG."
  (if (not attributes)
      tag
    (let (oldatt newatt)
      (setq oldatt (org-extract-attributes-from-string tag)
	    tag (pop oldatt)
	    newatt (cdr (org-extract-attributes-from-string attributes)))
      (while newatt
	(setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
      (if (string-match ">" tag)
	  (setq tag
		(replace-match (concat (org-attributes-to-string oldatt) ">")
			       t t tag)))
      tag)))

(defun org-format-table-table-odt (lines)
  "Format a table generated by table.el into ODT.
This conversion does *not* use `table-generate-source' from table.el.
This has the advantage that Org-mode's ODT conversions can be used.
But it has the disadvantage, that no cell- or row-spanning is allowed."
  (let (line field-buffer
	     (head org-export-highlight-first-table-line)
	     fields odt empty i)
    (setq odt (concat odt-table-tag "\n"))
    (while (setq line (pop lines))
      (setq empty "&nbsp;")
      (catch 'next-line
	(if (string-match "^[ \t]*\\+-" line)
	    (progn
	      (if field-buffer
		  (progn
		    (setq
		     odt
		     (concat
		      odt
		      "<tr>"
		      (mapconcat
		       (lambda (x)
			 (if (equal x "") (setq x empty))
			 (if head
			     (concat
			      (format (car org-odt-table-header-tags) "col")
			      x
			      (cdr org-odt-table-header-tags))
			   (concat (car org-odt-table-data-tags) x
				   (cdr org-odt-table-data-tags))))
		       field-buffer "\n")
		      "</tr>\n"))
		    (setq head nil)
		    (setq field-buffer nil)))
	      ;; Ignore this line
	      (throw 'next-line t)))
	;; Break the line into fields and store the fields
	(setq fields (org-split-string line "[ \t]*|[ \t]*"))
	(if field-buffer
	    (setq field-buffer (mapcar
				(lambda (x)
				  (concat x "<br/>" (pop fields)))
				field-buffer))
	  (setq field-buffer fields))))
    (setq odt (concat odt "</table>\n"))
    odt))

(defun org-format-table-table-odt-using-table-generate-source (lines)
  "Format a table into odt, using `table-generate-source' from table.el.
This has the advantage that cell- or row-spanning is allowed.
But it has the disadvantage, that Org-mode's ODT conversions cannot be used."
  (require 'table)
  (with-current-buffer (get-buffer-create " org-tmp1 ")
    (erase-buffer)
    (insert (mapconcat 'identity lines "\n"))
    (goto-char (point-min))
    (if (not (re-search-forward "|[^+]" nil t))
	(error "Error processing table"))
    (table-recognize-table)
    (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
    (table-generate-source 'odt " org-tmp2 ")
    (set-buffer " org-tmp2 ")
    (buffer-substring (point-min) (point-max))))

(defun org-odt-handle-time-stamps (s)
  "Format time stamps in string S, or remove them."
  (catch 'exit
    (let (r b)
      (while (string-match org-maybe-keyword-time-regexp s)
	(or b (setq b (substring s 0 (match-beginning 0))))
	(setq r (concat
		 r (substring s 0 (match-beginning 0))
		 " @<span class=\"timestamp-wrapper\">"
		 (if (match-end 1)
		     (format "@<span class=\"timestamp-kwd\">%s @</span>"
			     (match-string 1 s)))
		 (format " @<span class=\"timestamp\">%s@</span>"
			 (substring
			  (org-translate-time (match-string 3 s)) 1 -1))
		 "@</span>")
	      s (substring s (match-end 0))))
      ;; Line break if line started and ended with time stamp stuff
      (if (not r)
	  s
	(setq r (concat r s))
	(unless (string-match "\\S-" (concat b s))
	  (setq r (concat r "@<br/>")))
	r))))

(defvar odtize-buffer-places)  ; from odtize.el
(defun org-export-odtize-region-for-paste (beg end)
  "Convert the region to ODT, using odtize.el.
This is much like `odtize-region-for-paste', only that it uses
the settings define in the org-... variables."
  (let* ((odtize-output-type org-export-odtize-output-type)
	 (odtize-css-name-prefix org-export-odtize-css-font-prefix)
	 (odtbuf (odtize-region beg end)))
    (unwind-protect
	(with-current-buffer odtbuf
	  (buffer-substring (plist-get odtize-buffer-places 'content-start)
			    (plist-get odtize-buffer-places 'content-end)))
      (kill-buffer odtbuf))))

;;;###autoload
(defun org-export-odtize-generate-css ()
  "Create the CSS for all font definitions in the current Emacs session.
Use this to create face definitions in your CSS style file that can then
be used by code snippets transformed by odtize.
This command just produces a buffer that contains class definitions for all
faces used in the current Emacs session.  You can copy and paste the ones you
need into your CSS file.

If you then set `org-export-odtize-output-type' to `css', calls to
the function `org-export-odtize-region-for-paste' will produce code
that uses these same face definitions."
  (interactive)
  (require 'odtize)
  (and (get-buffer "*odt*") (kill-buffer "*odt*"))
  (with-temp-buffer
    (let ((fl (face-list))
	  (odtize-css-name-prefix "org-")
	  (odtize-output-type 'css)
	  f i)
      (while (setq f (pop fl)
		   i (and f (face-attribute f :inherit)))
	(when (and (symbolp f) (or (not i) (not (listp i))))
	  (insert (org-add-props (copy-sequence "1") nil 'face f))))
      (odtize-region (point-min) (point-max))))
  (switch-to-buffer "*odt*")
  (goto-char (point-min))
  (if (re-search-forward "<style" nil t)
      (delete-region (point-min) (match-beginning 0)))
  (if (re-search-forward "</style>" nil t)
      (delete-region (1+ (match-end 0)) (point-max)))
  (beginning-of-line 1)
  (if (looking-at " +") (replace-match ""))
  (goto-char (point-min)))

(defun org-odt-protect (s)
  "convert & to &amp;, < to &lt; and > to &gt;"
  ;; FIXME: Messes with verse element. Disable it for now
  ;; FIXME: If Disabled creates <<<>>> in TOC for Radioed Headlines,
  ;; so enable it Naturally verse environment is right now broken
  (when t
    (let ((start 0))
      (while (string-match "&" s start)
	(setq s (replace-match "&amp;" t t s)
	      start (1+ (match-beginning 0))))
      (while (string-match "<" s)
	(setq s (replace-match "&lt;" t t s)))
      (while (string-match ">" s)
	(setq s (replace-match "&gt;" t t s)))
      ;; (while (string-match "\"" s)
      ;;   (setq s (replace-match "&quot;" t t s)))
      )    
    )
  s)

(defun org-odt-expand (string)
  "Prepare STRING for ODT export.  Apply all active conversions.
If there are links in the string, don't modify these."
  (let* ((re (concat org-bracket-link-regexp "\\|"
		     (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
	 m s l res)
    (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string)
	string
      (while (setq m (string-match re string))
	(setq s (substring string 0 m)
	      l (match-string 0 string)
	      string (substring string (match-end 0)))
	(push (org-odt-do-expand s) res)
	(push l res))
      (push (org-odt-do-expand string) res)
      (apply 'concat (nreverse res)))))


(defcustom org-export-odt-emphasis-alist
  `(("*" "<text:span text:style-name=\"Bold\">" "</text:span>")
    ("/" "<text:span text:style-name=\"Emphasis\">" "</text:span>")
    ("_" "<text:span text:style-name=\"Underline\">" "</text:span>")
    ("=" "<text:span text:style-name=\"OrgCode\">" "</text:span>")
    ("~" "<text:span text:style-name=\"OrgCode\">" "</text:span>")
    ("+" "<text:span text:style-name=\"Strikethrough\">" "</text:span>"))
  "A list of DocBook expressions to convert emphasis fontifiers.
Each element of the list is a list of three elements.
The first element is the character used as a marker for fontification.
The second element is a formatting string to wrap fontified text with.
The third element decides whether to protect converted text from other
conversions."
  :group 'org-export-odt
  :type 'alist)

;; FIXME: rename, this is a general variable
(defcustom org-export-odt-expand t
  "Non-nil means for ODT export, treat @<...> as ODT tag.
When nil, these tags will be exported as plain text and therefore
not be interpreted by a browser.

This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
  :group 'org-export-odt
  :type 'boolean)

(defun org-odt-do-expand (s)
  "Apply all active conversions to translate special ASCII to ODT."
  (setq s (org-odt-protect s))
  (if org-export-odt-expand
      (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
	(setq s (replace-match "<\\1>" t nil s))))
  (if org-export-with-emphasize
      (setq s (org-export-odt-convert-emphasize s)))
  ;; FIXME: -- to ndash conversion happens here. Disable it for now.
  (if (and nil org-export-with-special-strings)
      (setq s (org-export-odt-convert-special-strings s)))
  (if org-export-with-sub-superscripts
      (setq s (org-export-odt-convert-sub-super s)))
  (if org-export-with-TeX-macros
      (let ((start 0) wd rep)
	(while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
					 s start))
	  (if (get-text-property (match-beginning 0) 'org-protected s)
	      (setq start (match-end 0))
	    (setq wd (match-string 1 s))
	    (if (setq rep (org-entity-get-representation wd 'odt))
		(setq s (replace-match rep t t s))
	      (setq start (+ start (length wd))))))))
  s)

(defun org-export-odt-convert-special-strings (string)
  "Convert special characters in STRING to ODT."
  (let ((all org-export-odt-special-string-regexps)
	e a re rpl start)
    (while (setq a (pop all))
      (setq re (car a) rpl (cdr a) start 0)
      (while (string-match re string start)
	(if (get-text-property (match-beginning 0) 'org-protected string)
	    (setq start (match-end 0))
	  (setq string (replace-match rpl t nil string)))))
    string))

(defun org-export-odt-convert-sub-super (string)
  "Convert sub- and superscripts in STRING to ODT."
  (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
    (while (string-match org-match-substring-regexp string s)
      (cond
       ((and requireb (match-end 8)) (setq s (match-end 2)))
       ((get-text-property  (match-beginning 2) 'org-protected string)
	(setq s (match-end 2)))
       (t
	(setq s (match-end 1)
	      key (if (string= (match-string 2 string) "_") "sub" "sup")
	      c (or (match-string 8 string)
		    (match-string 6 string)
		    (match-string 5 string))
	      string (replace-match
		      (concat (match-string 1 string)
			      "<" key ">" c "</" key ">")
		      t t string)))))
    (while (string-match "\\\\\\([_^]\\)" string)
      (setq string (replace-match (match-string 1 string) t t string)))
    string))

(defun org-export-odt-convert-emphasize (string)
  "Apply emphasis for opendocument exporting."
  (let ((s 0) rpl)
    (while (string-match org-emph-re string s)
      (if (not (equal
		(substring string (match-beginning 3) (1+ (match-beginning 3)))
		(substring string (match-beginning 4) (1+ (match-beginning 4)))))
	  (setq s (match-beginning 0)
		rpl
		(concat
		 (match-string 1 string)
		 (nth 1 (assoc (match-string 3 string)
			       org-export-odt-emphasis-alist))
		 (match-string 4 string)
		 (nth 2 (assoc (match-string 3 string)
			       org-export-odt-emphasis-alist))
		 (match-string 5 string))
		string (replace-match rpl t t string)
		s (+ s (- (length rpl) 2)))
	(setq s (1+ s))))
    string))

(defun org-odt-do-open-par (&optional style)
  "Insert <p>, but first close previous paragraph if any."
  (org-odt-close-par-maybe)
  (org-odt-open-par (or style "Text_20_body"))
  (setq org-par-open t))

(defun org-odt-close-par-maybe ()
  "Close paragraph if there is one open."
  (when org-par-open
    (org-odt-close-par)
    (setq org-par-open nil)))

;; debugging utilities
(defun org-odt-insert-comment (comment)
  (when t
    (insert  (format "\n<!-- %s -->\n"  comment))))

(defun org-odt-throw-error (msg) 
  (throw 'error msg))


;; headings
(defun org-odt-open-section (name) 
  (let ((style "Sect1"))
    (insert (format "<text:section text:style-name=\"%s\" text:name=\"%s\">\n"
		    style name))))

(defun org-odt-close-section () 
  (insert  "\n</text:section>\n"))

(defun org-odt-insert-heading (heading outline-level)
  (insert
   (format "<text:h text:style-name=\"Heading_20_%s\" text:outline-level=\"%s\">\n"
	   outline-level outline-level) heading "\n</text:h>\n"))

;; primitives begin
(defun org-odt-open-par (&optional style)
  (setq style (or style "Text_20_body"))
  (insert (format "\n<text:p text:style-name=\"%s\">\n" style)))

(defun org-odt-close-par () 
  (insert  "\n</text:p>\n"))

(defun org-odt-open-list (&optional style)
  (if style
      (insert (format "<text:list text:style-name=\"%s\">\n" style))
    (insert  "<text:list>")))

(defun org-odt-close-list () 
  (insert  "</text:list>\n"))

(defun org-odt-open-list-item () 
  (insert "<text:list-item>\n"))

(defun org-odt-close-list-item ()
  (insert "</text:list-item>\n"))
;; primitives end

;; compounds begin
(defun org-odt-do-open-list (&optional item-type) 
  (let (style-name)

    (cond
     ((equal item-type "u")
      (setq style-name "OrgBulletedList"))
     ((equal item-type "o")
      (setq style-name "OrgNumberedList"))
     ((equal item-type "d")
      (setq style-name "OrgDescriptionList")))

    (org-odt-close-par-maybe)
    (org-odt-open-list style-name)
    (org-odt-do-open-list-item)))

(defun org-odt-do-open-list-item (&optional style)
  (org-odt-open-list-item)
  (org-odt-do-open-par style))

(defun org-odt-do-open-description-list (item-tag) 
  ;; (format "<dl>\n<dt>%s</dt><dd>\n" item-tag)

  (org-odt-open-list "OrgDescriptionList")
  (org-odt-do-open-description-list-item item-tag))

(defun org-odt-do-open-description-list-item (item-tag) 
  ""
  ;; (format "<dt>%s</dt><dd>\n" item-tag)

  (org-odt-do-open-list-item "Text_20_body_20_bold")
  (insert item-tag)
  (org-odt-do-close-list-item)

  (org-odt-open-list-item)
  (org-odt-do-open-list))

(defun org-odt-do-close-list-item (&optional type)
  "Close <li> if necessary."
  ;; (insert (if (equal type "d") "</dd>\n" "</li>\n"))
  
  (org-odt-close-par-maybe)
  (org-odt-close-list-item)

  (when (equal type "d")
    (org-odt-close-list)
    (org-odt-close-list-item)))

;; compounds end

(defvar in-local-list)
(defvar local-list-indent)
(defvar local-list-type)

(defvar body-only) ; dynamically scoped into this.
(defun org-odt-level-start (level title umax with-toc head-count)
  "Insert a new level in ODT export.
When TITLE is nil, just close all open levels."
  (org-odt-close-par-maybe)
  (let* ((target (and title (org-get-text-property-any 0 'target title)))
	 (extra-targets (and target
			     (assoc target org-export-target-aliases)))
	 (extra-class (and title (org-get-text-property-any 0 'odt-container-class title)))
	 (preferred (and target
			 (cdr (assoc target org-export-preferred-target-alist))))
	 (remove (or preferred target))
	 (l org-level-max)
	 snumber snu href suffix)
    (setq extra-targets (remove remove extra-targets))
    (setq extra-targets
	  (mapconcat (lambda (x)
		       (if (org-uuidgen-p x) (setq x (concat "ID-" x)))
		       (format "<a name=\"%s\" id=\"%s\"></a>"
			       x x))
		     extra-targets
		     ""))
    (while (>= l level)
      (if (aref org-levels-open (1- l))
	  (progn
	    (org-odt-level-close l umax)
	    (aset org-levels-open (1- l) nil)))
      (setq l (1- l)))
    (when title
      ;; If title is nil, this means this function is called to close
      ;; all levels, so the rest is done only if title is given
      (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
	(setq title (replace-match
		     (if org-export-with-tags
			 (save-match-data
			   (concat
			    "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
			    (mapconcat
			     (lambda (x)
			       (format "<span class=\"%s\">%s</span>"
				       (org-export-odt-get-tag-class-name x)
				       x))
			     (org-split-string (match-string 1 title) ":")
			     "&nbsp;")
			    "</span>"))
		       "")
		     t t title)))
      (if (> level umax)
	  (progn
	    (if (aref org-levels-open (1- level))
		(progn
		  (org-odt-close-li)
		  (if target
		      (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
		    (insert "<li>" title "<br/>\n")))
	      (aset org-levels-open (1- level) t)
	      (org-odt-close-par-maybe)
	      (if target
		  (insert (format "<ul>\n<li id=\"%s\">" target)
			  extra-targets title "<br/>\n")
		(insert "<ul>\n<li>" title "<br/>\n"))))
	(aset org-levels-open (1- level) t)
	(setq snumber (org-section-number level)
	      snu (replace-regexp-in-string "\\." "_" snumber))
	(setq level (+ level org-export-odt-toplevel-hlevel -1))
	(if (and org-export-with-section-numbers (not body-only))
	    (setq title (concat
			 ;; interfering in bookmarks
			 ;; (format "<span class=\"section-number-%d\">%s</span>"
			 ;; 	 level snumber)
			 " " title)))
	(unless (= head-count 1) (insert "\n</text:section>\n"))
	(setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
	(setq suffix (or href snu))
	(setq href (or href (concat "sec-" snu)))

	;; suffix: 1.2 & href sec-1.2
	;; suffix: aabb & href aabb

	(insert
	 (format
	  "<text:section text:style-name=\"%s\" text:name=\"outline-container-%s\">"
	  "Sect1" suffix))

	(org-odt-insert-heading
	 (concat

	  (format "%s" snumber) ;; (format "%s%s" snumber title)
	  (let* ((frag href)
		 (txt (concat (format org-odt-bookmark-tag frag) title)))

	    (if (or org-export-odt-use-bookmarks-for-internal-links
		    org-export-odt-use-bookmarks-for-toc)
		(setq txt (org-odt-bookmark-text-range frag txt))) txt))
	 level)
	
	(insert
	 (format "<text:section text:style-name=\"%s\" text:name=\"text-%s\">"
		 "Sect1" suffix))

	(org-odt-do-open-par)))))

(defun org-export-odt-get-tag-class-name (tag)
  "Turn tag into a valid class name.
Replaces invalid characters with \"_\" and then prepends a prefix."
  (save-match-data
    (while (string-match "[^a-zA-Z0-9_]" tag)
      (setq tag (replace-match "_" t t tag))))
  (concat org-export-odt-tag-class-prefix tag))

(defun org-export-odt-get-todo-kwd-class-name (kwd)
  "Turn todo keyword into a valid class name.
Replaces invalid characters with \"_\" and then prepends a prefix."
  (save-match-data
    (while (string-match "[^a-zA-Z0-9_]" kwd)
      (setq kwd (replace-match "_" t t kwd))))
  (concat org-export-odt-todo-kwd-class-prefix kwd))

(defun org-odt-level-close (level max-outline-level)
  "Terminate one level in ODT export."
  (if (<= level max-outline-level)
      (insert "</text:section>\n")
    (org-odt-close-li)
    (insert "</ul>\n")))

;; Zip and Unzipping of ODT files
(defconst  org-export-odt-tmpdir-prefix "odt-")

;; xml files generated on-the-fly
(setq org-export-odt-save-list
      '("META-INF/manifest.xml"
	"content.xml"
	"meta.xml"))

;; xml files that are copied
(setq org-export-odt-nosave-list
      '("styles.xml"))

;; xml files that contribute to the final odt file
(setq org-export-odt-file-list
      (append org-export-odt-save-list org-export-odt-nosave-list))

(defun org-export-odt-outdir-init ()
  (interactive)
  (let* ((outdir (make-temp-file org-export-odt-tmpdir-prefix t))
	 (content-file (expand-file-name "content.xml" outdir))
	 (manifest-file (expand-file-name "META-INF/manifest.xml" outdir))
	 (meta-file (expand-file-name "meta.xml" outdir))
	 (styles-file (expand-file-name "styles.xml" outdir))
	 (pictures-dir (expand-file-name "Pictures" outdir)))

    ;; manifest file
    (make-directory (file-name-directory manifest-file))
    (with-current-buffer (find-file-noselect manifest-file)
      (erase-buffer)
      (insert (mapconcat 'identity (car org-export-odt-manifest-lines) "\n"))
      (insert "\n")
      (save-excursion
	(insert (mapconcat 'identity (cdr org-export-odt-manifest-lines) "\n"))))
   
    ;; meta file
    (with-current-buffer (find-file-noselect meta-file)
      (erase-buffer)
      (insert (mapconcat 'identity (car org-export-odt-meta-lines) "\n"))
      (insert "\n")
      (save-excursion
	(insert (mapconcat 'identity (cdr org-export-odt-meta-lines) "\n"))))

    ;; styles file
    (copy-file org-export-odt-styles-file styles-file t)

    ;; Pictures dir
    (make-directory pictures-dir)
    
    ;; content file
    (with-current-buffer (find-file-noselect content-file)
      (erase-buffer))
    outdir))


;; INLINE IMAGES

;; FIXME: Handle case where the same image is embedded multiple times
;; in the document


(defconst org-odt-manifest-file-entry-tag
  "<manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"/>")

(defun org-odt-update-manifest-file (media-type full-path) 
  (with-current-buffer
      (find-file-noselect "META-INF/manifest.xml" outdir)
    (insert (format org-odt-manifest-file-entry-tag media-type full-path))))



;;     <style:style style:name="Graphics" style:family="graphic">
;;       <style:graphic-properties text:anchor-type="paragraph" svg:x="0cm" svg:y="0cm" style:wrap="none" style:vertical-pos="top" style:vertical-rel="paragraph" style:horizontal-pos="center" style:horizontal-rel="paragraph"/>
;; </style:style>

    ;; <style:style style:name="fr1" style:family="graphic" style:parent-style-name="Graphics">
    ;;   <style:graphic-properties style:horizontal-pos="center" style:horizontal-rel="paragraph" style:mirror="none" fo: clip="rect(0cm, 0cm, 0cm, 0cm)" draw:luminance="0%" draw:contrast="0%" draw:red="0%" draw:green="0%" draw:blue="0%" draw:gamma="100%" draw:color-inversion="false" draw:image-opacity="100%" draw:color-mode="standard"/>
    ;; </style:style>

;; style-name => fr1 (inherits from Graphics)
;; name => graphics1 (possibly could be skipped)
;; anchor-type => paragraph
;; width => 12.435cm (can this be varied)
;; height => 10.054cm (can this be varied)
;; z-index => 0 (can this be varied)


;; INLINE IMAGES WITH CAPTIONS (SIMPLIFIED)
      ;; <text:p text:style-name="Text_20_body">
      ;; 	<draw:frame draw:style-name="Frame" text:anchor-type="paragraph" svg:width="12cm" draw:z-index="0">
      ;; 	  <draw:text-box fo:min-height="9.999cm">
      ;; 	    <text:p text:style-name="Illustration">
      ;; 	      <draw:frame draw:style-name="Graphics" text:anchor-type="paragraph" svg:x="0.004cm" svg:y="0.002cm" svg:width="12cm" style:rel-width="100%" svg:height="9.999cm" style:rel-height="scale" draw:z-index="1">
      ;; 		<draw:image xlink:href="Pictures/10000000000001D60000017C198B588A.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
      ;; 	    </draw:frame>Illustration <text:sequence text:ref-name="refIllustration0" text:name="Illustration" text:formula="ooow:Illustration+1" style:num-format="1">1</text:sequence>: FigureCaption</text:p>
      ;; 	  </draw:text-box>
      ;; 	</draw:frame> 
      ;; </text:p>


;; INLINE IMAGES (TRUE FORM)

;; <text:p text:style-name="Text_20_body"><draw:frame draw:style-name="fr1" draw:name="Frame1" text:anchor-type="paragraph" svg:width="12cm" draw:z-index="0">
;;         <draw:text-box fo:min-height="9.999cm">
;;          <text:p text:style-name="Illustration"><draw:frame draw:style-name="fr2" draw:name="graphics1" text:anchor-type="paragraph" svg:x="0.004cm" svg:y="0.002cm" svg:width="12cm" style:rel-width="100%" svg:height="9.999cm" style:rel-height="scale" draw:z-index="1"><draw:image xlink:href="Pictures/10000000000001D60000017C198B588A.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
;;           </draw:frame>Illustration <text:sequence text:ref-name="refIllustration0" text:name="Illustration" text:formula="ooow:Illustration+1" style:num-format="1">1</text:sequence>: FigureCaption</text:p>
;;         </draw:text-box>
;;        </draw:frame> </text:p>


(defconst org-odt-frame-tag
  '("<draw:frame draw:style-name=\"%s\" draw:name=\"%s\" text:anchor-type=\"%s\" svg:width=\"%dcm\" svg:height=\"%dcm\" draw:z-index=\"%d\">"
      . "</draw:frame>"))

(defconst org-odt-image-tag
    "<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>")

(defun org-odt-embed-image (path &optional width height)
  (with-temp-buffer
    (let* ((image-type (file-name-extension path))
	   (media-type (format "image/%s" type))
	   (full-path  (format "Pictures/%s"  (file-name-nondirectory path)))
	   (width (or width 12)) (height (or height 10)) ;; in cms
	   (z-index 0))

      ;; copy the image to pictures dir
      ;; current-dir is dyanmically bound

      (message "current-dir: %s" current-dir)
      (copy-file (expand-file-name path current-dir) "Pictures" nil)
    
      ;; (org-odt-do-open-par  "Standard")
      (insert (format (car org-odt-frame-tag)
		      "Graphics" "graphics1" "paragraph" width height z-index))
      (insert  (format org-odt-image-tag full-path))
      (insert  (format (cdr org-odt-frame-tag)))
      ;; (org-odt-close-par)

      ;; add it to the save list
      (push full-path org-export-odt-file-list)

      (message "file-list: %s" org-export-odt-file-list)
      
      ;; update manifest file
      (org-odt-update-manifest-file media-type full-path))
    
    (buffer-substring-no-properties (point-min) (point-max))))

;; ODT: ANCHORS and LINKS
(defconst org-odt-a-tag
  "<text:a xlink:type=\"simple\" xlink:href=\"%s\" %s> %s </text:a>")

;; ODT: BOOKMARKS AND XREFS

;; Either marks a point or a marks a range
;; When it marks a point, it can be referenced using internet-style
;; link that are prefixed with a #
;; When it marks a range, it can be referenced using a OpenOffice
;; style xref

(defconst org-odt-bookmark-tag
  "<text:bookmark text:name=\"%s\"/>")

(defconst org-odt-bookmark-start-end-tag
  '("<text:bookmark-start text:name=\"%s\"/>" .
    "<text:bookmark-end text:name=\"%s\"/>"))

(defconst org-odt-bookmark-ref-tag
  "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"%s\"> %s </text:bookmark-ref>")

(defcustom org-export-odt-use-bookmarks-for-internal-links t
  "Export Internal links as bookmarks?.")

(defconst org-export-odt-bookmark-prefix "__OrgXref_")

(defun org-odt-bookmark-text-range (bmk-name text)
  (setq bmk-name (concat org-export-odt-bookmark-prefix bmk-name))
  (concat (format (car org-odt-bookmark-start-end-tag) bmk-name)
	  text (format (cdr org-odt-bookmark-start-end-tag) bmk-name)))

(defun org-odt-bookmark-ref-begin (label) 
  (insert (format (car org-odt-bookmark-ref-tag) label)))

(defun org-odt-bookmark-ref-end () 
  (insert (format (cdr org-odt-bookmark-ref-tag))))

(defun org-odt-format-internal-link (href desc xref &optional attr)
  (if xref (format org-odt-bookmark-ref-tag href desc)
    (format org-odt-a-tag href (or attr "") desc)))

;; PACKAGING
(defun org-export-odt-zip (outdir target)
  ;; save all xml files
  (mapc (lambda (file)
	  (with-current-buffer (find-file-noselect (expand-file-name file outdir))
	    ;; prettify output
	    (indent-region (point-min) (point-max)) (save-buffer)))
	org-export-odt-save-list)
  
  (let* ((target-name (file-name-nondirectory target))
	 (target-dir (file-name-directory target))
	 (cmd (format "zip -r %s %s" target-name
		      (mapconcat 'identity org-export-odt-file-list " "))))

    (when (file-exists-p target)
      ;; FIXME: If the file is locked this throws an error
      (delete-file target))

    ;; FIXME: check exit status
    (shell-command cmd nil)

    ;; move the file from outdir to target-dir
    (rename-file target-name target-dir)

    ;; kill all xml buffers
    (mapc (lambda (file)
	    (kill-buffer (find-file-noselect (expand-file-name file outdir))))
	  org-export-odt-save-list)

    ;; delete the temporary directory created for zipping
    (delete-directory outdir)))

;; FIXME: Rationalize the path for styles file
(defcustom org-export-odt-styles-file
  "~/src/base/org-mode/contrib/odt/styles.xml"
  "Default style file for use with ODT exporter."
  :group 'org-export-odt
  :type 'file)

(defconst org-export-odt-manifest-lines
  '(("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
     "<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">"
     "<manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.text\" manifest:version=\"1.2\" manifest:full-path=\"/\"/>"
     "<manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>"
     "<manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>"
     "<manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>"
     "<manifest:file-entry manifest:media-type=\"\" manifest:full-path=\"Pictures/\"/>") . ("</manifest:manifest>")))

(defconst org-export-odt-meta-lines
  '(("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
     "<office:document-meta"
     "    xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\""
     "    xmlns:xlink=\"http://www.w3.org/1999/xlink\""
     "    xmlns:dc=\"http://purl.org/dc/elements/1.1/\""
     "    xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\""
     "    xmlns:ooo=\"http://openoffice.org/2004/office\" "
     "    office:version=\"1.2\">"
     "  <office:meta>") . ("  </office:meta>" "</office:document-meta>")))

(provide 'org-odt)

;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
;;; org-odt.el ends here

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: org-exp.el.diff --]
[-- Type: text/x-patch, Size: 2917 bytes --]

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index ae18ad3..bf94899 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -893,6 +893,8 @@ value of `org-export-run-in-background'."
 
 \[D] export as DocBook   [V] export as DocBook, process to PDF, and open
 
+\[o] export as ODT   [O] export as ODT and open
+
 \[j] export as TaskJuggler                         [J] ... and open
 
 \[m] export as Freemind mind map
@@ -921,6 +923,8 @@ value of `org-export-run-in-background'."
 	    (?g org-export-generic t)
 	    (?D org-export-as-docbook t)
 	    (?V org-export-as-docbook-pdf-and-open t)
+	    (?o org-export-as-odt t)
+	    (?O org-export-as-odt-and-open nil)
 	    (?j org-export-as-taskjuggler t)
 	    (?J org-export-as-taskjuggler-and-open t)
 	    (?m org-export-as-freemind t)
@@ -1020,10 +1024,12 @@ on this string to produce the exported version."
 	 (asciip (plist-get parameters :for-ascii))
 	 (latexp (plist-get parameters :for-LaTeX))
 	 (docbookp (plist-get parameters :for-docbook))
+	 (odtp (plist-get parameters :for-odt))
 	 (backend (cond (htmlp 'html)
 			(latexp 'latex)
 			(asciip 'ascii)
-			(docbookp 'docbook)))
+			(docbookp 'docbook)
+			(odtp 'odt)))
 	 (archived-trees (plist-get parameters :archived-trees))
 	 (inhibit-read-only t)
 	 (drawers org-drawers)
@@ -1193,6 +1199,12 @@ on this string to produce the exported version."
 	(require 'org-docbook nil)
 	(org-export-docbook-preprocess parameters))
 
+      ;; ODT-specific preprocessing
+      ;; Table References are inserted here
+      (when odtp
+	(require 'org-odt nil)
+	(org-export-odt-preprocess parameters))
+
       ;; Remove or replace comments
       (org-export-handle-comments (plist-get parameters :comments))
 
@@ -1650,7 +1662,7 @@ These special cookies will later be interpreted by the backend.
    ((memq backend '(latex))
     nil)
    ;; 2. Line-processing backends need to be told where lists end.
-   ((memq backend '(html docbook))
+   ((memq backend '(html docbook odt))
     (funcall process-buffer "ORG-LIST-END\n"))
    ;; 3. Others backends do not need to know this: clean list enders.
    (t
@@ -2292,6 +2304,22 @@ INDENT was the original indentation of the block."
 					     "]]></programlisting>\n")
 			  '(org-protected t org-example t))
 		      "#+END_DOCBOOK\n"))
+
+	     ;; FIXME: backend should really be odt. Use html for
+	     ;; now. The test short-circuits html specific processing
+	     ;; that happens later. Not sure whether we need any of it
+	     ;; later.
+	     
+	     ((eq backend 'odt)
+	      (setq rtn (org-export-number-lines
+			 rtn 'docbook 0 0 num cont rpllbl fmt))
+	      (concat "\n#+BEGIN_ODT\n"
+		      (org-add-props
+			  (concat
+			   "<text:p text:style-name=\"OrgSourceBlock\">"
+			   rtn "\n") '(org-protected t org-example t))
+		      "#+END_ODT\n"))
+	     
 	     ((eq backend 'html)
 	      ;; We are exporting to HTML
 	      (when lang

[-- Attachment #6: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-11-02 19:08                 ` Jambunathan K
@ 2010-11-02 19:31                   ` Matt Price
  2010-11-03  5:37                     ` Jambunathan K
  2010-11-02 20:10                   ` Lennart Borgman
  1 sibling, 1 reply; 28+ messages in thread
From: Matt Price @ 2010-11-02 19:31 UTC (permalink / raw)
  To: Jambunathan K; +Cc: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 1709 bytes --]

On Tue, Nov 2, 2010 at 3:08 PM, Jambunathan K <kjambunathan@gmail.com>wrote:

>
> Lennart
>
> Interesting that two people are working on org->OpenOffice exporter. The
> other person is me.
>
> I'm glad of it though!  Jambunathan, would you be willing to put your code
up on github?  Then we can perhaps all help out in a co-ordinated manner.



> >  took the rudimentary exporter in
> > muse and started to work a bit on it. I have not done very much yet,
> > just the part that puts all things together once the pieces (for
> > example content.xml) are there. You can find what I have done so far
> > in util/org-odt.el in the nXhtml repository.
>

just adding a link:
http://bazaar.launchpad.net/~nxhtml/nxhtml/main/annotate/head%3A/util/org-odt.el


> I started with org-html.el.
>
> I am attaching a test.org and test.odt from my work area (*as it
> is*). You will see that following things are taking shape:
>
> 1. Table Of Contents (Still not a 'native' Table Of Contents)
> 2. Various Character Styles
> 3. Various Paragraph Styles
> 4. Lists - Numbered, Bulleted, Description
> 5. Links - Internet Links, Internal Links as Bookmark/Xref
> 6. An embedded image
> 7. A simple table with a caption and numbering (you can see that xref to
>   table has apparently broken)
> 8. Various kinds of Footnotes
>
> If you look inside the odt file you will see that meta.xml also taking
> shape.
>
> this is further along than I'd thought it would be!  thanks for this!

If you od put it on github, maybe you can suggest minor features for people
to work on -- i'm a lousy coder (& v. busy for about 3 more weeks) but maybe
I and others on the list could help with some of the more tedious elements.


Best,
Matt

[-- Attachment #1.2: Type: text/html, Size: 2675 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-11-02 19:08                 ` Jambunathan K
  2010-11-02 19:31                   ` Matt Price
@ 2010-11-02 20:10                   ` Lennart Borgman
  2010-11-03  1:06                     ` Lennart Borgman
  1 sibling, 1 reply; 28+ messages in thread
From: Lennart Borgman @ 2010-11-02 20:10 UTC (permalink / raw)
  To: Jambunathan K; +Cc: nicholas.dokos, Org Mode

On Tue, Nov 2, 2010 at 8:08 PM, Jambunathan K <kjambunathan@gmail.com> wrote:
>
> Lennart

Hi Jambunathan,


> Interesting that two people are working on org->OpenOffice exporter. The
> other person is me.
>
> I made this announcement roughly one week in to the project.
> - http://lists.gnu.org/archive/html/emacs-orgmode/2010-10/msg00372.html

Ah, very good. I missed that one. I started this thread a month ago
and hoped there where more people interested.


>> I have struggled a bit with various ways to export from org-mode to
>> odt. (Thanks for all the tips here.)
>>
>> And it was not that fun when things gots complicated so I wonder if it
>> is better with a direct export. I took the rudimentary exporter in
>> muse and started to work a bit on it. I have not done very much yet,
>> just the part that puts all things together once the pieces (for
>> example content.xml) are there. You can find what I have done so far
>> in util/org-odt.el in the nXhtml repository.
>
> I started with org-html.el.
>
> I am attaching a test.org and test.odt from my work area (*as it
> is*). You will see that following things are taking shape:
>
> 1. Table Of Contents (Still not a 'native' Table Of Contents)
> 2. Various Character Styles
> 3. Various Paragraph Styles
> 4. Lists - Numbered, Bulleted, Description
> 5. Links - Internet Links, Internal Links as Bookmark/Xref
> 6. An embedded image
> 7. A simple table with a caption and numbering (you can see that xref to
>   table has apparently broken)
> 8. Various kinds of Footnotes
>
> If you look inside the odt file you will see that meta.xml also taking
> shape.
>
> I have adopted an approach of scanning various features rather than
> solidifying the given feature. So the appearance could be flattering.
>
> Jambunathan K.
>
> Attachments: test.org (as plain), test.odt (as zip)

It seems like we started from opposite corners so we can perhaps just
combine what we have done. I have just done a small part, the zipping
part, a bit more carefully (though it still need more work to be
coordinated with what we already have in Emacs).

Can we coordinate what we do in some way? Maybe a temporary repository?

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

* Re: How do I convert org to OpenOffice?
  2010-11-02 20:10                   ` Lennart Borgman
@ 2010-11-03  1:06                     ` Lennart Borgman
  2010-11-03  4:58                       ` Jambunathan K
  0 siblings, 1 reply; 28+ messages in thread
From: Lennart Borgman @ 2010-11-03  1:06 UTC (permalink / raw)
  To: Jambunathan K; +Cc: nicholas.dokos, Org Mode

>> Interesting that two people are working on org->OpenOffice exporter. The
>> other person is me.
>>
>> I made this announcement roughly one week in to the project.
>> - http://lists.gnu.org/archive/html/emacs-orgmode/2010-10/msg00372.html
>
> Ah, very good. I missed that one. I started this thread a month ago
> and hoped there where more people interested.


Hi again Jambunathan,


I just tried to test what you have written. Then I noticed that you
have a separate file styles.xml.

You have to place the styles somewhere, but I wonder if I do not like
the idea used in muse-odt.el by Paul Rivier better. He instead uses a
default.odt file from which he grabs the styles.xml.

If you do it Paul's way the user can easily edit the styles from
within LibreOffice (or OpenOffice.org if someone still wants to use
that - when LibreOffice is released).

I rewrote the zipping together from Paul's file in a way that should
be easy to use with your solution otherwise.

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

* Re: How do I convert org to OpenOffice?
  2010-11-03  1:06                     ` Lennart Borgman
@ 2010-11-03  4:58                       ` Jambunathan K
  0 siblings, 0 replies; 28+ messages in thread
From: Jambunathan K @ 2010-11-03  4:58 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: nicholas.dokos, Org Mode


Hello Lennart

I uploaded a snapshot of org-7.3 and committed my workarea files to
repo.or.cz. For now, rely on the commits and the logs to get started
with what I have done till now.

Web Interface:
- http://repo.or.cz/w/org-mode/oo.git/

Push URL:
- ssh://repo.or.cz/srv/git/org-mode/oo.git

Read-only URL:
- git://repo.or.cz/org-mode/oo.git
- http://repo.or.cz/r/org-mode/oo.git

Admin URL:
- http://repo.or.cz/editproj.cgi?name=org-mode/oo

I will send the admin password separately to you (Lennart) and Matt
separately so that you can add yourself to committers.

>>> Interesting that two people are working on org->OpenOffice exporter. The
>>> other person is me.
>>>
>>> I made this announcement roughly one week in to the project.
>>> - http://lists.gnu.org/archive/html/emacs-orgmode/2010-10/msg00372.html
>>
>> Ah, very good. I missed that one. I started this thread a month ago
>> and hoped there where more people interested.
>
>
> Hi again Jambunathan,
>
>
> I just tried to test what you have written. Then I noticed that you
> have a separate file styles.xml.

> You have to place the styles somewhere, but I wonder if I do not like
> the idea used in muse-odt.el by Paul Rivier better. He instead uses a
> default.odt file from which he grabs the styles.xml.

> If you do it Paul's way the user can easily edit the styles from
> within LibreOffice (or OpenOffice.org if someone still wants to use
> that - when LibreOffice is released).

> I rewrote the zipping together from Paul's file in a way that should
> be easy to use with your solution otherwise.

I agree that working with a template file is more user-friendly than
working with an xml file.

Which codebase should we start from?

I started with org-html.el because it assured me a stable and
feature-rich base that is also XMLish. 

One of the problems that I see with org-html.el route is that it is a
bit monolithic - there is a one big blob that does everything. The
side-effect of this is that our merges are most likely to conflict (even
if we work on two independent functional pieces)

If you look at org-odt.el, you will see that I have siphoned off the
Table Of Contents in to smaller routines, partly for my own
understanding and mostly because I wanted to break up the monolithic
structure of org-export-as-odt.

I also have a feeling that (my) org-odt.el has started becoming a beast
of it's own resembling less and less like org-html.el that it started
with.

Jambunathan K.

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

* Re: How do I convert org to OpenOffice?
  2010-11-02 19:31                   ` Matt Price
@ 2010-11-03  5:37                     ` Jambunathan K
  2010-11-04 21:32                       ` Matt Price
  2010-11-05 13:32                       ` J. David Boyd
  0 siblings, 2 replies; 28+ messages in thread
From: Jambunathan K @ 2010-11-03  5:37 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode


> I'm glad of it though!  Jambunathan, would you be willing to put your code up
> on github?  Then we can perhaps all help out in a co-ordinated manner. 

I put it up on repo.or.cz as I already had an account there. Here is the
URL:

- http://repo.or.cz/w/org-mode/oo.git/

> If you od put it on github, maybe you can suggest minor features for people to
> work on -- i'm a lousy coder (& v. busy for about 3 more weeks) but maybe I and
> others on the list could help with some of the more tedious elements. 

Anyone curious about the odt exporter can download a snapshot anytime
and export or report problems.

contrib/odt/  directory is the best place to get started. 

1. README.org 
   - 'The one file' for jotting down TODOs, FIXMEs or any useful ideas.

2. setup.el
   - Useful elisp stuff that can go in to a user's .emacs

3. files/ and files/test.org
   - Unit Test file for feeding to the exporter.

I have currently bound C-c C-e o and C-c C-e O for OpenOffice export.

As I write now, things are in very early stages (as in 'Jurassic
Times'). So it is not really meant to be used by anyone other than the
committers. Needless to say it will mature as time progresses.

Jambunathan K.

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

* Re: How do I convert org to OpenOffice?
  2010-11-03  5:37                     ` Jambunathan K
@ 2010-11-04 21:32                       ` Matt Price
  2010-11-05  6:03                         ` Jambunathan K
  2010-11-05 13:32                       ` J. David Boyd
  1 sibling, 1 reply; 28+ messages in thread
From: Matt Price @ 2010-11-04 21:32 UTC (permalink / raw)
  To: Jambunathan K; +Cc: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 888 bytes --]

On Wed, Nov 3, 2010 at 1:37 AM, Jambunathan K <kjambunathan@gmail.com>wrote:

>
>
> Anyone curious about the odt exporter can download a snapshot anytime
> and export or report problems.
>
> contrib/odt/  directory is the best place to get started.
>
> 1. README.org
>   - 'The one file' for jotting down TODOs, FIXMEs or any useful ideas.
>
> 2. setup.el
>   - Useful elisp stuff that can go in to a user's .emacs
>
> 3. files/ and files/test.org
>   - Unit Test file for feeding to the exporter.
>
> I have currently bound C-c C-e o and C-c C-e O for OpenOffice export.
>
>
hi jambunathan,

i'm probably being a bit stupid, but
1) couldn't get setup.el to load until changing require 'archive to require
'archive-mode
2) I even so i get this message
get-setf-method: No setf-method known for quote

this is with a recent org-mode, but my emacs-snapshot is over a year old.
thanks,
matt

[-- Attachment #1.2: Type: text/html, Size: 1352 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: How do I convert org to OpenOffice?
  2010-11-04 21:32                       ` Matt Price
@ 2010-11-05  6:03                         ` Jambunathan K
  0 siblings, 0 replies; 28+ messages in thread
From: Jambunathan K @ 2010-11-05  6:03 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode


Hello Matt

> On Wed, Nov 3, 2010 at 1:37 AM, Jambunathan K <kjambunathan@gmail.com> wrote:
>
>
>
>     Anyone curious about the odt exporter can download a snapshot anytime
>     and export or report problems.
>
>     contrib/odt/  directory is the best place to get started.
>
>     1. README.org
>       - 'The one file' for jotting down TODOs, FIXMEs or any useful ideas.
>
>     2. setup.el
>       - Useful elisp stuff that can go in to a user's .emacs
>
>     3. files/ and files/test.org
>       - Unit Test file for feeding to the exporter.
>
>     I have currently bound C-c C-e o and C-c C-e O for OpenOffice export.
>
>
>
> hi jambunathan,
>
> i'm probably being a bit stupid, but
> 1) couldn't get setup.el to load until changing require 'archive to require
> 'archive-mode
> 2) I even so i get this message
> get-setf-method: No setf-method known for quote
>

I have (hopefully) addressed the above two issues.

> this is with a recent org-mode, but my emacs-snapshot is over a year
> old. 

FYI, You don't need to checkout the whole repo:
1. Download the 2 elisp files - org-exp.el and org-odt.el
2. Download the whole of contrib/odt and modify the setting of
   org-odt-contrib-dir in setup.el to point to the above directory.

Thanks,
Jambunathan K.

> thanks,
> matt

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

* Re: How do I convert org to OpenOffice?
  2010-11-03  5:37                     ` Jambunathan K
  2010-11-04 21:32                       ` Matt Price
@ 2010-11-05 13:32                       ` J. David Boyd
  2010-11-05 13:49                         ` Jambunathan K
  1 sibling, 1 reply; 28+ messages in thread
From: J. David Boyd @ 2010-11-05 13:32 UTC (permalink / raw)
  To: emacs-orgmode

Jambunathan K <kjambunathan@gmail.com> writes:

>> I'm glad of it though!  Jambunathan, would you be willing to put your code up
>> on github?  Then we can perhaps all help out in a co-ordinated manner. 
>
> I put it up on repo.or.cz as I already had an account there. Here is the
> URL:
>
> - http://repo.or.cz/w/org-mode/oo.git/
>


When I try to clone from this, using

> git clone  http://repo.or.cz/w/org-mode/oo.git/ myoo


I get:

> warning: remote HEAD refers to nonexistent ref, unable to checkout.

I must be doing something wrong?


Dave

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

* Re: How do I convert org to OpenOffice?
  2010-11-05 13:32                       ` J. David Boyd
@ 2010-11-05 13:49                         ` Jambunathan K
  0 siblings, 0 replies; 28+ messages in thread
From: Jambunathan K @ 2010-11-05 13:49 UTC (permalink / raw)
  To: J. David Boyd; +Cc: emacs-orgmode

david@adboyd.com (J. David Boyd) writes:

>> I put it up on repo.or.cz as I already had an account there. Here is the
>> URL:
>>
>> - http://repo.or.cz/w/org-mode/oo.git/
>>
>
>
> When I try to clone from this, using
>
>> git clone  http://repo.or.cz/w/org-mode/oo.git/ myoo
>
>
> I get:
>
>> warning: remote HEAD refers to nonexistent ref, unable to checkout.
>

Try this URL http://repo.or.cz/r/org-mode/oo.git?

Jambunathan K.

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

end of thread, other threads:[~2010-11-05 13:51 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-29 17:01 How do I convert org to OpenOffice? Lennart Borgman
2010-09-29 17:52 ` Charles Philip Chan
2010-09-29 18:20   ` Lennart Borgman
2010-09-29 18:34     ` Charles Philip Chan
2010-09-29 18:39     ` Charles Philip Chan
2010-09-29 19:43       ` Nick Dokos
2010-09-29 20:12         ` Charles Philip Chan
2010-09-29 20:59           ` Nick Dokos
2010-09-29 21:33             ` Matt Price
2010-09-29 22:40               ` Alan L Tyree
2010-11-02 17:53               ` Lennart Borgman
2010-11-02 19:08                 ` Jambunathan K
2010-11-02 19:31                   ` Matt Price
2010-11-03  5:37                     ` Jambunathan K
2010-11-04 21:32                       ` Matt Price
2010-11-05  6:03                         ` Jambunathan K
2010-11-05 13:32                       ` J. David Boyd
2010-11-05 13:49                         ` Jambunathan K
2010-11-02 20:10                   ` Lennart Borgman
2010-11-03  1:06                     ` Lennart Borgman
2010-11-03  4:58                       ` Jambunathan K
2010-09-30 12:41 ` Matt Lundin
2010-09-30 14:26   ` Christian Egli
2010-09-30 16:43     ` Matt Lundin
2010-10-06 15:21 ` Eric S Fraga
2010-10-06 21:10   ` Henri-Paul Indiogine
2010-10-07  7:08     ` Eric S Fraga
  -- strict thread matches above, loose matches on Subject: below --
2010-09-30  3:25 Rustom Mody

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