Exporting documents using templates

Now is the moment you’ve been waiting for. In this article, you will learn how you can send your Org Mode documents out into the world as market-acceptable manuscripts.

Most markets do not accept plain text files, let alone Org Mode files—unfortunately. So this is a necessary milestone in your Emacs for Writers journey.

Important note: In order to follow this tutorial, you will need to have LibreOffice Writer installed on your computer. This is a free, open source alternative to Microsoft Word.

Some theory – filename separation

It’s important to keep your files organized. You will have many files, but when it comes to writing there are two critical file types at the top of the heap: your origin files (a plain text Org Mode file, for example) and the deliverable files (a PDF or Word document, for example).

If you are coming over from the world of conventional Word Processors you are probably accustomed to your file and deliverable being all-in-one. This is not the case now. No publisher or editor will accept your plain text Org Mode file, so you will need to export the Org Mode file to something your editor wants.

There are many different ways to organize this workflow, as you can imagine. Because you will always be working from the Org Mode file, and exporting new documents when needed, the exported files are incidental. You can declare a destination file path for your exported documents by placing the “export file name” keyword in your Org Mode file:

#+EXPORT_FILE_NAME: ~/path/to/document

You may be wondering, why does that matter? By default, Org Mode will export your new document to the same directory as the originating document. To avoid clutter, I have all my Org Mode documents in one folder, and I send exports to a separate “export” directory. This way, my Org Mode files are in one directory with other .org files and not cluttered up with PDFs, Word documents, and any other extraneous deliverable formats I may use at any given time. This helps keep things organized.

Using the export dispatcher

To engage the Org Mode exporter, you can use the existing keybinding: C-c C-e.

A bunch of export options will appear in a new buffer. Each export option is mapped to a key. The “Open Office” exporter, which we will be using, is mapped to the o key.

If you proceed to export your Org Mode document as is you will get an Open Office document that you can save as Microsoft Word. However, the default export styles will not be in standard manuscript format.

You will need to give Org Mode instructions on how you want the document formatted by using a template. The easiest way to do this is edit an Open Office document exported from Org Mode to match standard manuscript format and save it out of LibreOffice as a template file: my-template.ott, for example. (You can name it whatever you want.)

Then, you will just need to tell Org Mode to use that template by putting this line in your Org Mode file:

#+ODT_STYLES_FILE: "/path/to/my-template.ott"

Now, when you open the Org Mode dispatcher again with C-c C-e, you can choose Open Office as the export vehicle, and your styles will be used.

I demonstrated this whole process in a video.

Using my custom function

If you are feeling adventurous, you could add my custom function into your configuration. All you need to do is update the titles and file paths.

This function (run independently from the export dispatcher) will prompt you for different hard-coded templates for export. This is helpful if you have different templates for different purposes and don’t want to have to update the styles file keyword each time you export.

Exporting your documents like a probably

In summary, you should now have a clearer idea of how you can take an Org Mode file and export it out to a variety of different formats accepted by the writer’s market.

Remember that different editors and publishers may have their own unique standards. Always be sure to read submission guidelines closely to make sure you format your document correctly. With Emacs and LibreOffice you have everything you would need to meet the specifications of the marketplace.

Now, all you have to do is come up with great ideas and write. And that’s the hard part.