13.12.12 Advanced topics in ODT export
The ODT export back-end has extensive features useful for power users and frequent uses of ODT formats.
Configuring a document converterβ
The ODT export back-end works with popular converters with little or no extra configuration. See Extending ODT export. The following is for unsupported converters or tweaking existing defaults.
Register the converterβ
Add the name of the converter to the org-odt-convert-processes
variable. Note that it also requires how the converter is invoked on the command line. See the variableβs docstring for details.
Configure its capabilitiesβ
Specify which formats the converter can handle by customizing the variable org-odt-convert-capabilities
. Use the entry for the default values in this variable for configuring the new converter. Also see its docstring for details.
Choose the converterβ
Select the newly added converter as the preferred one by customizing the option org-odt-convert-process
.
Working with OpenDocument style filesβ
This section explores the internals of the ODT exporter; the means by which it produces styled documents; the use of automatic and custom OpenDocument styles.
The ODT exporter relies on two files for generating its output. These files are bundled with the distribution under the directory pointed to by the variable org-odt-styles-dir
. The two files are:
βOrgOdtStyles.xml
ββ
This file contributes to the βstyles.xml
β file of the final ODT document. This file gets modified for the following purposes:
- To control outline numbering based on user settings;
- To add styles generated by β
htmlfontify.el
β for fontification of code blocks.
βOrgOdtContentTemplate.xml
ββ
This file contributes to the βcontent.xml
β file of the final ODT document. The contents of the Org outline are inserted between the β<office:text>
β β¦ β</office:text>
β elements of this file.
Apart from serving as a template file for the final βcontent.xml
β, the file serves the following purposes:
- It contains automatic styles for formatting of tables which are referenced by the exporter;
- It contains β
<text:sequence-decl>
β β¦ β</text:sequence-decl>
β elements that control numbering of tables, images, equations, and similar entities.
The following two variables control the location from where the ODT exporter picks up the custom styles and content template files. Customize these variables to override the factory styles used by the exporter.
org-odt-styles-file
β
The ODT export back-end uses the file pointed to by this variable, such as βstyles.xml
β, for the final output. It can take one of the following values:
βFILE.xml
ββ
Use this file instead of the default βstyles.xml
β
βFILE.odt
β or βFILE.ott
ββ
Use the βstyles.xml
β contained in the specified OpenDocument Text or Template file
βFILE.odt
β or βFILE.ott
β and a subset of included filesβ
Use the βstyles.xml
β contained in the specified OpenDocument Text or Template file. Additionally extract the specified member files and embed those within the final ODT document.
Use this option if the βstyles.xml
β file references additional files like header and footer images.
nil
β
Use the default βstyles.xml
β.
org-odt-content-template-file
β
Use this variable to specify the blank βcontent.xml
β used in the final output.
Creating one-off stylesβ
The ODT export back-end can read embedded raw OpenDocument XML from the Org file. Such direct formatting is useful for one-off instances.
Embedding ODT tags as part of regular textβ
Enclose OpenDocument syntax in β@@odt:...@@
β for inline markup. For example, to highlight a region of text do the following:
@@odt:<text:span text:style-name="Highlight">This is highlighted
text</text:span>@@. But this is regular text.
Hint: To see the above example in action, edit the βstyles.xml
β (see Factory styles) and add a custom Highlight style as shown below:
<style:style style:name="Highlight" style:family="text">
<style:text-properties fo:background-color="#ff0000"/>
</style:style>
Embedding a one-line OpenDocument XMLβ
The ODT export back-end can read one-liner options with β#+ODT:
β in the Org file. For example, to force a page break:
#+ODT: <text:p text:style-name="PageBreak"/>
Hint: To see the above example in action, edit your βstyles.xml
β (see Factory styles) and add a custom βPageBreak
β style as shown below.
<style:style style:name="PageBreak" style:family="paragraph"
style:parent-style-name="Text_20_body">
<style:paragraph-properties fo:break-before="page"/>
</style:style>
Embedding a block of OpenDocument XMLβ
The ODT export back-end can also read ODT export blocks for OpenDocument XML. Such blocks use the β#+BEGIN_EXPORT odt
β β¦ β#+END_EXPORT
β constructs.
For example, to create a one-off paragraph that uses bold text, do the following:
#+BEGIN_EXPORT odt
<text:p text:style-name="Text_20_body_20_bold">
This paragraph is specially formatted and uses bold text.
</text:p>
#+END_EXPORT
Customizing tables in ODT exportβ
Override the default table format by specifying a custom table style with the β#+ATTR_ODT
β line. For a discussion on default formatting of tables, see Tables in ODT export.
This feature closely mimics the way table templates are defined in the OpenDocument-v1.2 specification1.
For quick preview of this feature, install the settings below and export the table that follows:
(setq org-export-odt-table-styles
(append org-export-odt-table-styles
'(("TableWithHeaderRowAndColumn" "Custom"
((use-first-row-styles . t)
(use-first-column-styles . t)))
("TableWithFirstRowandLastRow" "Custom"
((use-first-row-styles . t)
(use-last-row-styles . t))))))
#+ATTR_ODT: :style TableWithHeaderRowAndColumn
| Name | Phone | Age |
| Peter | 1234 | 17 |
| Anna | 4321 | 25 |
The example above used βCustom
β template and installed two table styles βTableWithHeaderRowAndColumn
β and βTableWithFirstRowandLastRow
β. Important: The OpenDocument styles needed for producing the above template were pre-defined. They are available in the section marked βCustom Table Template
β in βOrgOdtContentTemplate.xml
β (see Factory styles). For adding new templates, define new styles there.
To use this feature proceed as follows:
Create a table template2.
A table template is set of β
table-cell
β and βparagraph
β styles for each of the following table cell categories:- Body
- First column
- Last column
- First row
- Last row
- Even row
- Odd row
- Even column
- Odd Column
The names for the above styles must be chosen based on the name of the table template using a well-defined convention.
The naming convention is better illustrated with an example. For a table template with the name β
Custom
β, the needed style names are listed in the following table.Cell type Cell style Paragraph style Body β CustomTableCell
ββ CustomTableParagraph
βFirst column β CustomFirstColumnTableCell
ββ CustomFirstColumnTableParagraph
βLast column β CustomLastColumnTableCell
ββ CustomLastColumnTableParagraph
βFirst row β CustomFirstRowTableCell
ββ CustomFirstRowTableParagraph
βLast row β CustomLastRowTableCell
ββ CustomLastRowTableParagraph
βEven row β CustomEvenRowTableCell
ββ CustomEvenRowTableParagraph
βOdd row β CustomOddRowTableCell
ββ CustomOddRowTableParagraph
βEven column β CustomEvenColumnTableCell
ββ CustomEvenColumnTableParagraph
βOdd column β CustomOddColumnTableCell
ββ CustomOddColumnTableParagraph
βTo create a table template with the name β
Custom
β, define the above styles in the β<office:automatic-styles>
β β¦ β</office:automatic-styles>
β element of the content template file (see Factory styles).Define a table style3.
To define a table style, create an entry for the style in the variable
org-odt-table-styles
and specify the following:- the name of the table template created in step (1),
- the set of cell styles in that template that are to be activated.
For example, the entry below defines two different table styles β
TableWithHeaderRowAndColumn
β and βTableWithFirstRowandLastRow
β based on the same template βCustom
β. The styles achieve their intended effect by selectively activating the individual cell styles in that template.(setq org-export-odt-table-styles
(append org-export-odt-table-styles
'(("TableWithHeaderRowAndColumn" "Custom"
((use-first-row-styles . t)
(use-first-column-styles . t)))
("TableWithFirstRowandLastRow" "Custom"
((use-first-row-styles . t)
(use-last-row-styles . t))))))Associate a table with the table style.
To do this, specify the table style created in step (2) as part of the β
ATTR_ODT
β line as shown below.#+ATTR_ODT: :style TableWithHeaderRowAndColumn
| Name | Phone | Age |
| Peter | 1234 | 17 |
| Anna | 4321 | 25 |
Validating OpenDocument XMLβ
Sometimes ODT format files may not open due to β.odt
β file corruption. To verify if such a file is corrupt, validate it against the OpenDocument Relax NG Compact (RNC) syntax schema. But first the β.odt
β files have to be decompressed using βzip
β. Note that β.odt
β files are ZIP archives: (emacs)File Archives. The contents of ODT files are in XML. For general help with validationβand schema-sensitive editingβof XML files: (nxml-mode)Introduction.
Customize org-odt-schema-dir
to point to a directory with OpenDocument RNC files and the needed schema-locating rules. The ODT export back-end takes care of updating the rng-schema-locating-files
.
- OpenDocument-v1.2 Specificationβ©
- See the β
<table:table-template>
β element of the OpenDocument-v1.2 specification.β© - See the attributes β
table:template-name
β, βtable:use-first-row-styles
β, βtable:use-last-row-styles
β, βtable:use-first-column-styles
β, βtable:use-last-column-styles
β, βtable:use-banding-rows-styles
β, and βtable:use-banding-column-styles
β of the β<table:table>
β element in the OpenDocument-v1.2 specification.β©