3 Using Writer2LaTeX and Writer2BibTeX

Writer2LaTeX is quite flexible: It can take advantage of several LaTeX packages, such as hyperref, pifont, ulem. It can create customized LaTeX code based on the styles and text in the document. Also it supports 25 different languages, latin, greek and cyrillic scripts and 8 inputencodings.

The flexibility makes it possible to use Writer2LaTeX from several philosophies:

3.1 The LaTeX package ooomath.sty

OOo Math has a few features that are not available in standard LaTeX packages. Hence Writer2LaTeX uses an optional package ooomath.sty2 which implements these constructions. This packages is only needed for documents containing formulas. If it is not available, Writer2LaTeX will insert the necessary definitions in the LaTeX preamble.

It is sufficient to place ooomath.sty in the same directory as the converted LaTeX document. It will however be more convenient if you install it in your TeX distribution. The proper place will usually be the “local texmf tree”, please see the documentation of your TeX distribution. Below are specific instructions for teTeX and MikTeX:

Instructions for teTeX (unix)

If you use teTeX you can install ooomath.sty as follows:

Open a shell and type

texconfig conf

This will list the configuration details for teTeX. Under the heading “Kpathsea” you will see a list of directories searched by TeX. You can put ooomath.sty in the subdirectory tex of any of these directories. Usually the directory

/home/<user name>/texmf/tex

can be used (you can create it if it doesn't exist).

Next you should type

texconfig rehash

to make teTeX refresh it's filename database.

Instructions for MikTeX (Windows)

If you use MikTeX you can install ooomath.sty as follows:

Copy ooomath.sty to the tex subdirectory in the local texmf tree. With a standard installation this will be the directory

c:\localtexmf\tex

If this directory does not exist you should start “MikTeX Options” (you can find this in the Start Menu). On the tab page Roots you can see the location of the local texmf tree.

If the subdirectory tex does not exist, you can create it.

Next you should start “MikTeX Options”. On the tab page General, click the button Refresh Now to make MikTeX refresh it's filename database.

3.2 Converting to LaTeX from the command line

To convert a file to LaTeX use the command line

w2l [-latex] [-config <configfile>] [options] <document to convert> [<output path and/or file name>]

The parts in square brackets are optional.

This will produce a LaTeX file with the specified name. If no output file is specified, Writer2LaTeX will use the same name as the original document, but change the extension to .tex.

Examples:

w2l mydocument.sxw mypath/myoutputdocument.tex

or

w2l -config clean.xml mydocument.sxw

If you specify the -config option, Writer2LaTeX will load this configuration file before converting your document. You can read more about configuration in section 3.5. You can also specify any simple option described in this section directly on the command line, eg. to produce a file suitable for processing with pdfLaTeX:

w2l -backend pdftex mydocument.sxw

The script w2l also provides a shorthand notation to use the sample configuration files included in writer2latex05.zip. The command line is

w2l [-ultraclean|-clean|-pdfscreen|-pdfprint|-article] <writer document to convert> [<output path and/or file name>]

For example to produce a clean LaTeX file (ie. ignoring most of the formatting from the source document):

w2l -clean mydocument.sxw

It is recommended that you create your own scripts to support your own configuration file(s).

3.3 Converting to BibTeX from the command line

Writer2BibTeX extracts bibliography data to a BibTeX file. To do this use the commandline

w2l -bibtex <writer document to convert> [<output path and/or file name>]

You can also extract the data as part of the conversion to LaTeX, see section 3.5.

3.4 Using Writer2LaTeX and Writer2BibTeX as export filters

If you choose File – Export in Writer you should be able to choose LaTeX 2e, BibTeX as file type.

Note: You have to use the export menu because there is no import filter for LaTeX/BibTeX. You should always save in the native format of OOo as well!

3.5 Configuration

LaTeX export can be configured with a configuration file. Where the configuration is read from depends on how you use Writer2LaTeX:

If you use Writer2LaTeX as an export filter in OOo, the configuration is handled as follows:

If, on the other hand, you use Writer2LaTeX from the command line, you will have to specify on the command line which configuration file to use.

The configuration is a file in xml format. Here is a sample configuration file for producing a document of class book, converting only basic formatting and optimizing for pdfTeX.

<?xml version="1.0" encoding="UTF-8" ?>

<config>

  <option name="backend" value="pdftex" />

  <option name="documentclass" value="book" />

  <option name="inputencoding" value="latin1" />

  <option name="use_pifont" value="false" />

  <option name="use_bibtex" value="false" />

  <option name="bibtex_style" value="plain" />

  <option name="formatting" value="convert_basic" />

  <option name="page_formatting" value="convert_all" />

  <option name="debug" value="false" />

  <heading-map max-level="6">

    <heading-level-map writer-level="1" name="chapter" level="0" />

    <heading-level-map writer-level="2" name="section" level="1" />

    <heading-level-map writer-level="3" name="subsection"

      level="2" />

    <heading-level-map writer-level="4" name="subsubsection"

      level="3" />

    <heading-level-map writer-level="5" name="paragraph"

      level="4" />

    <heading-level-map writer-level="6" name="subparagraph"

    level="5" />

  </heading-map>

  <custom-preamble />

  <style-map name="Quotations" class="paragraph"

    before="\begin{quote}" after=\end{quote} />

  <string-replace input="LaTeX" latex-code="{\LaTeX}" />

</config>

The meaning of each part is explained in the following sections. Writer2LaTeX comes with five sample configuration files:

Basic options

Options for document structure

Table options

Graphics options

Font and symbol options

Options for various packages

Various options

Options for BibTeX

Options to control export of page formatting

Options to control export of other formatting

In Writer, formatting is controlled by styles. You can control how much formatting is exported using the following options3. Note that these options has a major impact on the structure of the LaTeX document created.

Options for strict handling of content

The following options can be used if you want a very strict control with the content allowed in the document. The options

Can all have the values accept (default), ignore, warning and error.

This controls how various content should be handled by Writer2LaTeX. The option other_styles controls paragraph and text content, for which there is no style map (see below). The other options control images and tables.

If the value of this option is accept, the content is handled as normal. If the value is ignore, the content is ignored silently. The values warning and error issues a message on the terminal resp. in the generated LaTeX code.

Style maps

In addition you can specify maps from styles in Writer to your own LaTeX styles in the configuration. Currently this is possible for text styles, paragraph styles and list styles. The following examples are from the sample configuration file article.xml.

This is a simple rule, that maps text formatted with the text style Emphasis to the LaTeX code \emph{...}:

 <style-map name="Emphasis" class="text" before="\emph{" after="}" />

This is another simple rule, that maps paragraphs formatted with the paragraph style part to the LaTeX code \part{...}. The attribute line-break ensures that no line breaks are inserted between the code and the text.

<style-map name="part" class="paragraph" before="\part{" after="}" line-break="false" />

This is a rule, that maps paragraph formatted with style Preformatted Text to the LaTeX environment verbatim. The attribute verbatim ensures that the content of the paragraph is exported verbatim (this implies that characters not available in the inputenc are converted to question marks and that other content is discarded, eg. footnotes). The paragraph-block entry specifies code to go before and after an entire block of paragraphs. The name attribute specifies the style of the first paragraph; the next attribute specifies the style(s) of subsequent paragraphs in the block.

  <style-map name="Preformatted Text" class="paragraph-block" next="Preformatted Text" before="\begin{verbatim}" after="\end{verbatim}" />

<style-map name="Preformatted Text" class="paragraph" before="" after="" verbatim="true" />

This is a more elaborate set of rules, that maps paragraphs formatted with styles Title, author and date (in any order) to \maketitle in LaTeX.

<style-map name="Title" class="paragraph" before="\title{" after="}" line-break="false" />
 <style-map name="author" class="paragraph" before="\author{" after="}" line-break="false" />
 <style-map name="date" class="paragraph" before="\date{" after="}" line-break="false" />
 <style-map name="Title" class="paragraph-block" next="author;date" before="" after="\maketitle" />
 <style-map name="author" class="paragraph-block" next="Title;date" before="" after="\maketitle" />
 <style-map name="date" class="paragraph-block" next="Title;author" before="" after="\maketitle" />

This will produce code like this:

\title{Configuration}

\author{Henrik Just}

\date{2006}

\maketitle

The last example maps a paragraph formatted with the theorem list style to a LaTeX environment named theorem. Note that there are two entries for a list style: The first one to specify the LaTeX code to put before and after the entire list. The second one to specify the LaTeX code to put before and after each list item.

<style-map name="theorem" class="paragraph" before="" after="" />
<style-map name="theorem" class="list" before="" after="" />
<style-map name="theorem" class="listitem" before="\begin{theorem}" after="\end{theorem}" />

When you override a style, all formatting specified in the original document will be igored.

String replace

Often LaTeX requires special care to typeset certain constructions. For example according to german typografical rules, an abbreviation like z.B. should be typeset with a small space before the B. You can specify this in the configuration:

<string-replace input="z.B." latex-code="z.\,B." />

The input is the text in the OOo document, the latex-code is the LaTeX code to export for this text.

Math symbols

In OOo Math you can add user-defined symbols. Writer2LaTeX already understands the predefined symbols such as %alpha. If you define your own symbols, you can add an entry in the configuration that specifies LaTeX code to use. The math-symbol-map element is used for this:

<math-symbol-map name=”ddarrow” latex=”\Downarrow” />

This example will map the symbol %ddarrow to the LaTeX code \Downarrow.

Custom preamble

The text you specify in the element custom-preamble will be copied verbatim into the LaTeX preamble. For example:

<custom-preamble>\usepackage{palatino}</custom-preamble>

to typeset your document using the postscript font palatino.

3.6 Using OpenOffice.org as a frontend for LaTeX

Writer2LaTeX has some simple support for using OOo as a frontend for LaTeX. The long term goal of this is to turn Writer into a near-wysiwyg LaTeX editor somewhat like LyX.

Here is a short description:

Create a new document based on the template LaTeX-article.stw.

This template contains a number of styles that corresponds to LaTeX code:

OOo Writer style

OOo Writer class

LaTeX code

Title 4

paragraph

\title{...} 5

author

paragraph

\author{...}

date

paragraph

\date{...}

abstract title

paragraph

renews \abstractname

abstract

paragraph

abstract environment

part

paragraph

\part{...}

Heading 2

paragraph

\section{...}

Heading 3

paragraph

\subsection{...}

Heading 4

paragraph

\subsubsection{...}

Heading 5

paragraph

\paragraph{...}

Heading 6

paragraph

\subparagraph{...}

flushleft

paragraph

flushleft environment

flushright

paragraph

flushright environment

center

paragraph

center environment

verse

paragraph

verse environment

quote

paragraph

quote environment

quotation

paragraph

quotation environment

Preformatted text

paragraph

verbatim environment6

theorem

paragraph

theorem environment

itemize

paragraph

itemize list

enumerate

paragraph

enurerate list

List Heading

paragraph

description list (item label)

List Contents

paragraph

description list (item text)

verb

text

\verb|...|

Emphasis

text

\emph{...}

Strong Emphasis

text

\textbf{...}

textrm

text

\textrm{...}

textsf

text

\textsf{...}

texttt

text

\texttt{...}

textup

text

\textup{...}

textsl

text

\textsl{...}

textit

text

\textit{...}

textsc

text

\textsc{...}

textmd

text

\textmd{...}

textbf

text

\textbf{...}

tiny

text

{\tiny ...}

scriptsize

text

{\sciptsize ...}

footnotesize

text

{\footnotesize ...}

small

text

{\small ...}

normalsize

text

{\normalsize ...}

large

text

{\large ...}

Large

text

{\Large ...}

LARGE

text

{\LARGE ...}

huge

text

{\huge ...}

Huge

text

{\Huge ...}

If you use these styles and uses the configuration file article.xml when you convert your document with Writer2LaTeX, you will get a result that resembles a handwritten LaTeX file. Note that hard formatting and any other styles will be ignored.

Roundtrip editing

Writer2LaTeX does not provide a filter, that converts LaTeX files back into OOo Writer format. This is however possible with Eitan M. Gurari's TeX4ht system (http://www.cse.ohio-state.edu/~gurari/TeX4ht/mn.html). If you use Writer2LaTeX (with article.xml) together with TeX4ht's OOo mode (oolatex), simple roundtrip edition LaTeX ↔ OOo Writer is supported. Beware of information loss if you do this – do not use this roundtrip for existing LaTeX or Writer documents!

As a genereal rule, you should save your document in the native OOo Writer format and convert to LaTeX when you are finished (or want to see the result).

2 This pakcage replaces writer.sty used by older versions of Writer2LaTeX.

3 Note that these options have changed a lot since version 0.3.2.

4 The use of italics in this table indicates styles that are predefined in OOo. The names of these styles will be localized if you use a non-english version of OOo.

5 Also \maketitle is added at the end of a sequence of Title, author and date.

6 Only characters available in the inputenc are accepted. Other characters are converted to question marks and other content is discarded, eg. footnotes.