Emacs

Make beautiful documents from Emacs ORG-Mode

Word processors are sometimes too heavy. When you write documents for more formal occasions you might need to deliver in a special format. You may think that you must use a word processor for this reason. This is not always the case. In fact, making Open Document Text (odt) files are available right there in the default configuration. To export to other formats, you need a few more packages and a few settings.

Nice settings for meta-data.

For a really nice document, you want to have a heading, your name, a date and some other information. You put this on the top of the document, using tags and special notation. You can see a few examples below.

Your name

#+author: Mats TageAxelsson

Date

#+date<2019-06-13 Thu>

Title

#+title This beautiful document!

As you can see, the names of the tags are mostly clear and simple to understand. The more complex ones are the options you have for the export and some other values. These values control your final output. You can use the headings in our org file, to decide if they make a heading in the real document.

Control your document structure

The other values, usually put in the top of the document, control the structure for your document. You can change what is shown and what is not. When you write in Org- mode you will probably use tags, tasks and links. All the mentioned features may be only for your own use. Most users of org-mode uses tasks for scheduling their own agenda. In this case you exclude them with options.

#+options tags: nil creator: nil tasks: nil todo: t

In the above example, you can see that the tags are ‘nil’ and should not be exported. You can keep all tags but only from headings by using the not-in-toc value. The creator tag is nil, which hides the fact that you are using Emacs to create your document. Next, all tasks will not be exported at all. Last, all keywords used by the TODO system is kept in the exported text.

Regarding the tags, if you are still working with a draft, you may have sections that have not finished yet. In this case you can tag that section by setting a tag to the branch. It looks like this:

***Heading for later :noexport:

Tags can be used for many other things but that is for another time. Another important setting you need to know is the H setting. This controls how many levels of your document becomes a heading. Most likely you do not want deeper levels than 3. In Emacs, you can set the H value to treat only those top levels as headings. By default Emacs will treat all lower levels as list items.

#+options: H: 3 toc: 2

Since we are on the subject of headers, you may want to have a table of contents. In the example above the level of the toc is set to 2. This makes Emacs create a toc with level 2, while adding three levels of headings in the document.

The most common cases

Exporting to ODT

When you want to use ODT as the output format, you simple hit C-c C-e, a new buffer shows up and you can choose any of the red options. In the case of ODT you will choose ‘o’ and then ‘o’ to export it. Or you can choose a capital ‘O’ the second time to see your result.

This procedure is simple and looks similar for all formats but you have options. If you want to export to another format, docx is common then you need to set that. The value is org-odt-preferred-output-format. To set this you can either call customize-varaible with M-x or set it in your .emacs file.

setq  org-odt-preferred-output-format docx

There are many more formats to choose from in case you have other needs. Do not give up Emacs easily!

Exporting to PDF

When you want to export to PDF, you do the same thing. There is only one small oddity, it starts with latex. So the key chord goes ‘C-c C-e l p’ or the last one ‘O’ to open up a viewer to inspect your results. The reason PDF is under LATEX is that the formats were used by similar people historically. You can actually choose PDF for your ODT output. This can be useful if you always put out PDF. Since we are in the Latex realm, you may need Latex later, it is very common. You can export your document to a Latex buffer in Emacs, if there are things in Latex you are uncertain about you can use this as a trick to learn.

Exporting to HTML

Exporting to html follows the same pattern. With the addition that you can open in an Emacs buffer as well as your favourite web browser.

Combining with pandoc

If you have more formats you may want to export to, you need to combine Emacs with Pandoc. Pandoc converts documents of almost any kind. With Pandoc you can convert HTML to org-mode documents and this is only one of many functions. If you want to use it inside Emacs, find the pandoc package in the MELPA repositories.

Conclusion

Since you love Emacs, you will want to stick to it as much as possible. With the different options available you can both export and import many document formats. Thanks to this you can stay with your favorite editor.

About the author

Mats Tage Axelsson

Mats Tage Axelsson

I am a freelance writer for Linux magazines. I enjoy finding out what is possible under Linux and how we can all chip in to improve it. I also cover renewable energy and the new way the grid operates. You can find more of my writing on my blog.