While you can create and save documents in the OpenDocument format using OpenOffice.org, KWord, or AbiWord, there are other ways to generate ODF files. odtwriter, for example, can help you to quickly convert plain text files formatted using reStructured Text markup into odt (OpenOffice.org Writer-compatible ODF) documents. You might wonder why you’d want to create ODF documents this way, but odtwriter does offer a few important advantages:
The main drawback of using odtwriter to produce ODF documents is that you need to learn a new markup language. This is, however, not as bad as it might sound. Markup used in reStructured Text looks a lot like wiki markup, so you can pick up the basics in no time. The markup is also well-documented, with reStrecutured Text Primer, Quick Reference, and a cheat sheet available for your reading pleasure.
To make odtwriter work on your machine, you have to install two packages: docutils and pygments. The latter is required only if you want the syntax highlighting functionality. On Ubuntu, installing both packages is as easy as running the sudo apt-get install python-docutils python-pygments command. To install odtwriter, download its latest release, unpack it, and run the following commands:
python setup.py build sudo python setup.py install
Using odtwriter is equally straightforward: the rst2odt.py command converts the specified source text file into an odt document:
rst2odt.py text.txt document.odt
Like any command-line tool, odtwriter supports flags; and at least two of them can come in rather handy. By default, the syntax highlight feature in odtwriter is disabled, and you need to use the –add-syntax-highlighting flag to turn it on:
rst2odt.py --add-syntax-highlighting text.txt document.odt
This applies Python syntax highlighting to the code blocks (marked as literal blocks) in the source text. For code blocks in other programming languages, you have to add so-called directives to the source text that activate alternative language (or lexer) highlighting:
.. sourcecode:: on .. sourcecode:: Java
Since odtwriter relies on Pygments for syntax highlighting, you can use any language supported by this software. You can find a list of all supported languages and their short names on the Pygments Web site.
Related articles:
| Create ODF documents without OpenOffice.org | 2009/03/14 16:24 | Dmitri Popov |