I wish to convert a .tex file into an .odt file.
Can you suggest a good step-by-step solution?
-
3@Naruto: I assume it's a LaTeX document.– Nathan OsmanNov 25, 2011 at 20:33
-
4Note that for all answers below: your success rate will depend on the latex packages used, and math will never be typeset as nicely as in latex.– David LeBauerNov 26, 2011 at 3:03
5 Answers
There is a tool in the repositories that changes LaTeX to openoffice.org's XML format: tex4ht
TeX4ht is a highly configurable TeX-based authoring system for producing hypertext. It interacts with TeX-based applications through style files and postprocessors, leaving the processing of the source files to the native TeX compiler. Consequently, TeX4ht can handle the features of TeX-based systems in general, and of LaTeX in particular.
TeX4ht can be used both for authoring HTML using TeX/LaTeX input files, or for converting existing TeX input files (in any format) into HTML, with (usually) only minor modifications. Other varieties of hypertext can also be produced, including XML, XHTML, MathML and the Openoffice.org format of XML.
Command line...
latex filename.tex
bibtex filename.aux
mk4ht oolatex filename.tex
Should end up with an openoffice.org/libreoffice compatible file.
-
2Thank you. BTW, it appears the main maintainer of the package has sadly died two years ago. Nov 25, 2011 at 19:27
-
2
-
I agree - I wish a more active community would have taken upon itself to continue this work... Nov 27, 2011 at 2:57
-
+1 for command line example. I did not have time to read the documentation, but the example above is quite easy to follow. Jun 5, 2013 at 13:39
-
Believe it or not, with complex documents and lots of packages included, I got much better results with LaTeX2HTML than with LaTeX2RTF, Pandoc or TeX4ht.
latex2html texfile.tex -split 0 -no_navigation -info "" -address "" -html_version 4.0,unicode
This will generate a folder with the same texfile
name, so you'll be able to convert the generated HTML to ODT:
libreoffice --headless --convert-to odt:"OpenDocument Text Flat XML" texfile/index.html
This will produce a index.odt
file. Take a look at this answer to check how to use LibreOffice's convert filters.
Edit from comment discussion:
Although the method above works, it is very disappointing that the only way I found to generate a trully reliable document is using the PDF output from LaTeX on Adobe Acrobat Pro.
-
1For complex documents with lots of additional packages, files and commands LaTeX2HTML fails. I'm trying to convert my thesis to HTML and than to ODT in order to give it to someone for comments and correction, who is not familiar with LaTeX. Even without custom commands this tool fails. Tikz package for some reason is one of the main culprits. Jul 18, 2014 at 8:10
-
There's no ideal solution @rbaleksandar, specially depending of the packages you're using. I would suggest Pandoc for you. It won't keep all formats, but it is capable of ignoring some structures and build a final document, at least. Jul 18, 2014 at 11:28
-
-
Documents are never perfect with the presented solutions in this question. It is very disappointing that the only way I found to generate a perfect document is using the PDF output from LaTeX with Adobe Acrobat Pro. Aug 6, 2015 at 22:50
-
This command gave me nonsense HTML, and nonsense ODT. Pandoc was much better.– jdpipeJul 2, 2018 at 3:01
Another solution is provided from the package pandoc
As an example, you can do:
pandoc -f latex -t odt -o output.odt input.tex
If the input file is latin1
encoded, like my tex files, the solution is:
iconv -f ISO-8859-1 input.tex | pandoc -f latex -t odt -o output.odt
I report part of the description of the package:
Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. It can read
- markdown and
- subsets of
- reStructuredText,
- HTML, and
- LaTeX
and it can write
- plain text,
- markdown,
- reStructuredText,
- HTML, -LaTeX, -ConTeXt,
- RTF,
- DocBook XML,
- OpenDocument XML,
- ODT,
- GNU Texinfo,
- MediaWiki markup,
- EPUB,
- Textile,
- groff man pages,
- Emacs Org-mode, and
- Slidy or
- S5 HTML slide shows.
-
-
This one worked pretty well for me... I got figures, headings but no bibliography, and variously mixed-up equations/symbols. But at least I quickly got some text that I could start cleaning up manually.– jdpipeJul 2, 2018 at 2:58
It can be done in 2-steps. Go to http://latex2rtf.sourceforge.net/ and use the tools provided to convert first from Latex to RTF and then from RTF to ODT.
Hope it helps.
-
Doesn't work at all 😂 With the minimal example it was hanging for a minute with 100% CPU usage. I don't think it would ever end the work, so I interrupted it.– Hi-AngelJul 26, 2015 at 10:15
-
Okay, I managed it to work — perhaps it doesn't work well with macros — and found that it also doesn't e.g. work with a table of contents. So no, not an option.– Hi-AngelJul 26, 2015 at 17:29
If you've the tex4ht package installed, the command oolatex filename
converts the .tex into .odt (for more on tex4ht, see here).
Another way would be the latex2rtf package, using RTF as intermediate format.
-
-
Not a problem since you added a link to latex2rtf and that was not in any of the other 2 answers ;)– RinzwindNov 25, 2011 at 16:59