Tip: Download our Emacs keyboard shortcuts cheatsheet to increase your productivity.

What is LaTeX and Org Mode?

LaTeX is a staple in academic writing. Its beautiful typography and near magic way of tracking references makes it attractive for both students and professors that want to have print-ready publications right from the comfort of their keyboard. However, LaTeX often disregards the fact that the TeX code behind it is complex and hard to use. For example, creating a table through LaTeX requires you to know a code which involves creating a sub-environment with a syntax that only applies to it. Because of this, LaTeX is often seen as a difficult program to use especially for users that do not have any background in writing code. Despite that, it is possible to write a LaTeX document without knowing any LaTeX code by using Emacs with Org Mode. Org Mode is an add-on that you can install in your vanilla Emacs installation. At its core, it allows you to manage bullet-organized documents. You can then use this to track tasks and create outlines for those tasks. Aside from that, Org Mode also allows you to use its outlining format to create custom documents that you can export to any format you want. This can be useful for those that want to maintain a single file format for their documents. For example, you can create a document using Org Mode’s bullet syntax and easily convert it to HTML.

How to Install LaTeX and Org Mode

Starting with LaTeX in Emacs is incredibly easy. That’s because it is a highly popular software that almost all Linux distributions carry in their repositories. After that, you can check whether you have installed the program properly by running the following: This will bring up a prompt where you can give the name of the package that you want to install. Type “org-mode”. From there, Emacs will download, compile then install the source code for Org to your machine.

Create Your First LaTeX Document in Emacs

Add Sections and Subsections

With that done, you can now start creating the structure of your document. For example, this is a simple Org file with two first-level and one second-level bullet headings. Under each heading, I wrote a brief paragraph to provide some length to the document: Now, you can immediately run this exact document through the Export Menu (as shown above). In doing so, it will use this exact syntax, convert it to LaTeX and then process it to a printable PDF. The way this works is that Org makes a number of assumptions about how you want your document to look. In this case, it converts each bullet point as a LaTeX section with a corresponding section number. From there, Org then assumes that any text directly under a bullet point are paragraphs that belong to that section. This intelligent approach, in turn, allows you to continue writing in Org syntax and use that to seamlessly convert to LaTeX code.

Use Special Symbols

Another brilliant feature of LaTeX in Org Mode is its ability to easily write special characters from inside Emacs. In traditional LaTeX, writing special symbols for math formulae will require you to know the control command for rendering symbols. For example, in order to write the Greek letter “τ” you need write the following line of code: This approach can be cumbersome especially for articles and documents that make extensive use of these special symbols. Knowing this, Org can help alleviate this problem through two things: in-editor rendering and tab completion.

Add Images

Further, it is also possible to directly include figures and graphics to your LaTeX documents through Org Mode. Unlike traditional LaTeX, inserting images in Org only requires you provide a link for the file that you want to add. Knowing that, consider the following example: In this, I included two images in my LaTeX document file. The first is an absolute link that points to a specific image file in my machine. This can be helpful if you want to include images that are located in different parts of your system. On the other hand, the second one uses a relative link which takes the current directory and looks for a file named “img2.jpg”. Unlike an absolute link, this allows your LaTeX document to be both portable and flexible to changes in file structure.

Create Tables

Another great feature of Org Mode is that you can create tables in it which you can convert to LaTeX. This can be helpful for users that want to create print-ready tables but are not familiar with LaTeX’s table syntax and environment.

How to Customize LaTeX’s Preamble in Org Mode

The “Header Field” is a special Org Mode value that you can insert at the start of your document. With this, you can change almost any value on any variable for your LaTeX document. In that regard, the “Header Field” is similar to setting the preamble of your LaTeX document.

How to Use LaTeX Plugins in Org Mode

Lastly, it is also possible to include external LaTeX plugins through Org Mode. These include bibliography management utilities such as BibTeX as well as advanced plugins such as Geometry. As such, this can be especially useful if you rely on these plugins to create your custom documents. For example, this is an Org document that uses the BibTeX plugin for bibliography management. That’s a wrap! You now know how to use Org Mode to create and publish LaTeX PDF documents straight from Emacs. Not only that, you also know how Org can allow you to easily create and maintain LaTeX documents without knowing a lot of LaTeX code. If all this talk made you more curious about LaTeX. You can check this article where we talk about some of the best LaTeX editors that you can install in Linux. Image credit: Unsplash. All screenshots by Ramces Red