# Is there a system to generate ODT documents from a markup-like language?

I would like (well, am forced by my work environment) to create ODT documents (really MS Word docs, but we can get there from ODT). However, I don't like the WYSIWYG document creation paradigm. I like proper control over my styles and document structure. I am a LaTeX user, but while LaTeX→ODT is possible, it is difficult and fragile, and I don't expect the tools to do this to mature any time soon.

Therefore, I would like to know, is there a script-like environment for generating ODT documents, that is similar in principle to the LaTeX workflow, and lets you easily control the style and formatting of documents (for example, to match a company document template)?

Ideally the system will have support for:

• Writing nicely formatted equations
• Firmly controlling the document structure
• Control of the style of the document, such as fonts, formatting of headings at different levels, header and footers sections of pages etc. i.e. everything that makes up a normal word-processed document
• Inserting figures and images
• you may try Pandoc (johnmacfarlane.net/pandoc/index.html) – wmz Apr 2 '15 at 8:35
• I'm aware of Pandoc, but does it do what I'm asking? – crobar Apr 2 '15 at 12:56
• You are asking for DOCX, but would accept a workaround via ODT. So Pandoc can create ODT -- but Pandoc can also directly create DOCX from Markdown source text, and the output can by directly styled with the same styles as a --reference-docx=mydocx file you refer to on the command line. That's about as good as you ever can get -- before you switch over to 'DOCX-from-dictation' ! – Kurt Pfeifle Apr 21 '15 at 10:51

pandoc has already been mentioned... it is also my favorite tool for this kind of task.

But missing in the previous answer was the following important fact about Pandoc:

• command line parameter: --reference-odt=...
for example: --reference-odt=myref.odt

Pandoc will read the styles defined in myref.odt and apply them to the ODT output document it generates.

It may not work perfectly, or not work well for very-very-very weird custom company styles. But helps a lot when it comes to easily get styles which are different from the defaults into your output ODT documents.

The OP wrote in a comment: "I'm aware of Pandoc, but does it do what I'm asking? "

Yes it does:

• "Writing nicely formatted equations?"
Yes, just insert the LaTeX equation into the Markdown sources in between $ characters without any spaces, like this: $\cos (2\theta) = \cos^2 \theta - \sin^2 \theta\$.

• "Firmly controlling the document structure?"
Yes, it does. (Well, I didn't really fully understand what exactly you mean by this, but I'm going to confirm it anyway! :)

• "Control of the style of the document...?"
Yes, see above --reference-odt=myref.odt parameter explained above.

• "Inserting figures and images?"
Yes! -- Insert an image like this (on a line of its own, separated by blank lines):

![image description](./path/to/image.png)

• ok, yes, but doesn't creating a style effectively require that you understand the ODT file format already? I don't have time to learn this, I want things like this specified easily in my input file. By firmly controlling the document structure I mean sections levels of the document are firmly controlled by commands or similar, rather than by 'style' as they are in, say, LibreOffice. Markdown and LaTeX allow firm control over the document structure, so yes, Pandoc does it to an extent. – crobar Apr 20 '15 at 10:40
• No, creating a style document for use with the --reference-odt parameter is different from creating a new template for the ODT output. A style document only requires that you understand the LibreOffice or OpenOffice GUI, know how to create, edit and change document, paragraph and character styles in the LO/OO "Styles and Formatting" dialog and save that document... – Kurt Pfeifle Apr 20 '15 at 11:56
• Section levels in Markdown are controlled by #  at the line start for Heading of first order, ##  for heading of second order, etc. Pandoc translates that to the style Heading 1, Heading 2, etc. This isn't just a style in LibreOffice, it is also a structural element! – Kurt Pfeifle Apr 20 '15 at 11:59
• "This isn't just a style in LibreOffice, it is also a structural element!", yes, and that's what I don't like about LibreOffice/Word etc., I want style separated as much as possible from content and structure! So if I understand right (looking at the docx example on the pandoc website), the --reference-odt would just be a minimal example document with Heading 1, Heading 2 etc. styles defined. Is there a reference anywhere for exactly what styles can be defined? – crobar Apr 21 '15 at 7:48
• @crobar: In any case, this is not the place to put up a full-scale tutorial about using Pandoc, Markdown and --reference-odt=... or --reference-docx=... for ODT and DOCX output. It is, however, amazing, just how much customized and precise styling is possible with Pandoc's ODT output (and even better now with DOCX) from simple Markdown. Think of it as similar to HTML/CSS. There you also have a a "separation of content, structure and style". But is it a clean separation? Which system/format has a really clean separation? Can you tell me one? – Kurt Pfeifle Apr 21 '15 at 9:08

I think that it would be a good idea to take a look at using Markdown or ReStructuredText + Pandoc - You can use markdown/rst just like you do on SO and then convert it to any of a number of document formats, including ODT and MS .docx while the extended markdown is very flexible and powerful.

Pandoc input and output formats:

Input formats:  docbook, haddock, html, json, latex, markdown, markdown_github,
markdown_mmd, markdown_phpextra, markdown_strict, mediawiki,
native, opml, org, rst, textile
Output formats: asciidoc, beamer, context, docbook, docx, dzslides, epub,
epub3, fb2, html, html5, icml, json, latex, man, markdown,
markdown_github, markdown_mmd, markdown_phpextra,
markdown_strict, mediawiki, native, odt, opendocument,
opml,org, pdf*, plain, revealjs, rst, rtf, s5, slideous,
slidy, texinfo, textile

• Having looked at Pandoc, it does not seem very easy to modify your document style, to make it conform to a company template. It seems you have to have a good understanding of the ODT file format, and create a template in this format. This is a serious limitation as I don't know the ODT file format and don't have time to learn it. – crobar Apr 6 '15 at 18:22
• @crobar: Have you seen the command line parameter --reference-odt=myref.odt?? Pandoc will read the styles defined in myref.odt and apply them to the ODT output document it generates. May not work perfectly, or for very-very-very weird custom company styles, but helps a lot! – Kurt Pfeifle Apr 18 '15 at 10:43
• @crobar: Gimme your company template with the styles you need, pay me my standard rate (I'm a Freelancer), and I'll give you back a Pandoc command line, a Pandoc ODT template an a Pandoc reference-odt that you can use! Deal? :-) – Kurt Pfeifle Apr 20 '15 at 12:01
• @crobar: Since you want to (finally) convert to Word docs, I can do it for Word too -- directly usable to convert Markdown to DOCX. – Kurt Pfeifle Apr 20 '15 at 12:03