One argument that I keep hearing from people is that they can’t use plain text or Markdown because they need to produce formatted word processor documents — documents created with Microsoft Word or LibreOffice Writer. An interesting argument, but not one I buy.
Why? With Markdown, you can generate a word processor document. Well, with a little help from a tool called Pandoc.
As I discussed in a previous article in this space, Pandoc is a very powerful utility that can convert between various markup languages. It also has some extensions to Markdown, which makes it quite useful for converting Markdown to a word processor format.
Now the important reminder: Pandoc is a command line application with a large number of options. But don’t let that intimidate you. I use Pandoc a lot and only touch a half dozen or so of those options at the most.
Anyway, for what I’m going demonstrate, you just need to remember a few commands.
Creating a Simple Word Processor File
Let’s assume you have a Markdown file that you want to convert to a LibreOffice Writer file. Open a terminal window, navigate to the directory in which the Markdown file resides, and then type:
pandoc -o filename.odt filename.md
Where filename is the name of your document.
If you want to create a Word file instead, change the extension .docx to .odt.
Simple, but effective.
Going a Step Beyond
The file that Pandoc spits out looks OK. It’s a tad bland, though. What if you need to have your documents with a certain look and feel? Pandoc can help, but it takes a little bit of setup.
Here’s what to do. At least under Linux. I don’t do Windows, so I can’t help you there. These instructions should work with MacOS, though.
First, run this command:
pandoc --print-default-data-file reference.odt > custom-reference.odt
That command creates a LibreOffice Writer file called custom-reference.odt which contains the styles Pandoc uses. If you use Word, change the .odt in the command to .docx. Then, move the file to a folder somewhere in your /home directory.
As I mentioned a few paragraphs ago, Pandoc’s stock word processor output is bland. Why not customize it a bit? Open the file custom-reference.odt in a word processor and:
- Modify the styles, like headings, body text, and list
- Change the page size (living in New Zealand, I use A4 paper)
- Add headers and footers
Do whatever you want to spice up the look of your document. I’m not going to explain how to do that here. Check your word processor’s help if you need guidance. There are also good tutorials online, which you can find with your favourite search engine.
Now you’re ready use the custom-reference.odt file. To do that, run this command:
pandoc -t odt filename.md -o filename.odt --custom-reference [path-to]/custom-reference.odt
Here’s what this article looks like, converted to a LibreOffice Writer document:
There’s a lot more I can do to tweak the output, but that works well enough. And it looks better than the stock output from Pandoc. All it took was a bit of tweaking.
In an upcoming article, I’ll show you a few ways to make that conversion a little more efficient (along with a few other Pandoc tricks).