25

I'm writing a master thesis (Sociology) and I'm really penalized by distractions. I would happily shift to a markdown full-screen environment but I wrote an half of the thesis in .odt via LibreOffice, so I would like to know if it's possible to convert from .odt to Markdown, maintaining the footnotes (which are the most important thing in my work) and also the formatting of the bibliographical notes.

Maybe It could be useful to revert the process and, at the end of the work, go back to .odt file to reformat pages, line height and other things.

Is there a way to do so?

Alternatively, there is a way to write full-screen directly in a .odt file maintaining footnotes (because FocusWriter and TextRoom doesn't have this feature)?

5
  • 4
    If this is the direction you're heading, I hope you've heard of Pandoc. Conversion will not be flawless--you'll definitely have to do a bit of cleanup. But the reward you'll get is being able to output to a variety of formats very easily. I would suggest converting the .odt to an HTML file and converting the HTML file to markdown using Pandoc as a starting point. Oct 1, 2013 at 16:40
  • @AnandaMahto thank you for your comment. I've heard of Pandoc, but I didn't know a way to convert from .odt to markdown. Actually, I'll try the intermediate step you suggest and report if It works.
    – Kropot
    Oct 2, 2013 at 14:25
  • Are the bibliographical notes separable (like in an appendix at the end), or interspersed (like footnotes are)? If the former, you might be able to just leave that in .odt and work on the rest in Markdown (assuming you can convert the rest without losing your footnotes). Oct 3, 2013 at 0:28
  • The various suggested solutions are probably much easier and better, but it's worthwhile to point out that an odt file is essentially a multi-part zipped file with the plain text as one part. You can just unzip it and take the text only component of it and do whatever you want with it. However, this approach loses all formatting, so you would have to add that from scratch in whatever new format you choose.
    – Joe
    Sep 16, 2015 at 2:15
  • Ctrl+Shift+j = LibreOffice Full Screen.
    – user15984
    Nov 24, 2015 at 10:49

4 Answers 4

29

Your first option is, really, Pandoc, which was already mentioned. Its usage is quite straightforward. I've done some converting along these lines myself, and it's brilliant. It's included in Debian repositories, so I'd think acquiring an installation wouldn't be a problem.

You indeed want to convert to HTML first:

pandoc OdtFile.odt -o HtmlFile.html

and then proceed to create markdown file the same way:

pandoc HtmlFile.html -o MarkDown.text

and yes, you could go back from markdown to odt the same way. You also could enforce your own style set by mentioning style template odt file, the README will tell you, how.

You may also find it useful to preserve paragraphs with the flag --wrap=none - i.e. prevent pandoc breaking pars with newlines every 72 chars.

To prevent odd HTML formatting (such as you get where the original doc has embedded links: pandoc endows those in the output markdown text with underline html tags), specify the markdown version as markdown_github-raw_html with -t markdown_github-raw_html. (Might be preferable to change the source doc's default link formatting in the Office app that created it, if you can).

Another option is to forego markdown for some kind of TeX solution (to which format you also could convert your already written text with Pandoc), the advantages being the abilities to insert images, tables and math equations in text, though, I'm afraid, that will close the way back to odt.

5
  • 2
    The first command results in pandoc: Cannot decode byte '\xc6': Data.Text.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream, at least in the ubuntu version (1.12.2.1). What version are you using to do that? There is another program, odt2html, in the unoconv package that works well though.
    – naught101
    Jun 20, 2014 at 13:06
  • I get a similar error: pandoc: Cannot decode byte '\x9d': Data.Text.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream.
    – Nordlöw
    Aug 20, 2014 at 20:04
  • What version of the program do you use? Can you send me an example file which produces such an error? Aug 21, 2014 at 21:28
  • 1
    Pandoc only works in utf8 mode. If you have other codification in your writing, you must to convert it well using your editor or using iconv. Also, you should use before file on your texts to know the codification.
    – user13768
    May 13, 2015 at 14:48
  • Have just tried this option and works great, except for the fact that images and tables from ODT are not converted to md (even though I am using images as links).
    – ccamara
    Mar 15, 2017 at 11:53
2

I've been playing around with odt2txt. It strips out all formatting, leaving just plain text, perfect for diffs, and an acceptable starting place for doing your markup, and if you combine it with @AnandaMahto's suggestion to use Pandoc to convert it back, I have some ugly papers to try this on.

1

Have you looked into WriteMonkey? There doesn't seem to be a plug-in to do what you want, but it is a robust distraction free markdown environment.

If converting to html and then to MD works, this might be the ideal editing environment for you. WriteMonkey will export MD to MS Word, which could then be opened in LibreOffice when you're done.

1

To augment Undespairable's answer, these commands from the command line convert from markdown to HTML and then HTML to ODT.

pandoc .\some-file.md -f markdown -t html -s -o .\some-file.html    

pandoc .\some-file.html -f html -t odt -o .\some-file.odt

See also: https://www.pandoc.org/getting-started.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.