Turning on Your High-Beams: Using Beamer with Org-mode

Written by J David Smith
Published on 18 April 2014

What is Beamer?

Beamer's official site sums up the advantages and disadvantages of using Beamer fairly well, so I'll let it speak for itself:

Beamer is a LaTeX class for creating presentations that are held using a projector, but it can also be used to create transparency slides. Preparing presentations with Beamer is different from preparing them with WYSIWYG programs like OpenOffice.org's Impress, Apple's Keynote, or KOffice's KPresenter. A Beamer presentation is created like any other LaTeX document. … The obvious disadvantage of this approach is that you have to know LaTeX in order to use Beamer. The advantage is that if you know LaTeX, you can use your knowledge of LaTeX also when creating a presentation, not only when writing papers.

If you are familiar with the advantages and disadvantages of Microsoft Word versus LaTeX, then you are familiar with them for PowerPoint versus Beamer. Beamer is not well-suited to every presentation. However, it is very powerful for math-heavy or code-oriented presentations because of how the equations and source can be embedded into LaTeX.

What is Org-mode?

According to the official site, Org-mode is an Emacs major mode for "keeping notes, maintaining TODO lists, and doing project planning with a fast and effective plain-text system." It has a ton of features, but the ones I use most are:

Org-mode is a successor to things like <code>outline-mode</code>, which (as the name
suggests) was/is used for outlining. Org-mode extends it in many, many
ways. I won't list them all. You can find a feature list [here](http://orgmode.org/features.html).
Being an Emacs major mode, Org-mode also packs quite the editing punch. It
comes loaded with utility functions, syntax highlighting, outline folding,
and a bevy of other features. For example, I can re-order headlines (or
slides) using `M-S-<up>/<down>` (that's `Meta-Shift-<up>` or
`Meta-Shift-<down>` for those unused to Emacs-style key-chords). If I want
to focus on a particular section, `C-x n s` will narrow the buffer to only
that section (`C-x n w` will widen the buffer back to the entire file).
![img](//atlanis.net/media/blog/org-mode-screen.jpg)
LaTeX is a wonderful, wonderful thing. Unfortunately, it is also
*incredibly verbose!* As a markup language, this level of explicitness is
necessary to remove ambiguity and give fine-grained control over
output. However, in my every-day use-case I really just want to write up my
homework assignments with pretty-printed math without having to worry about
all of that. Org-mode fills this gap by providing a much less verbose
markup that has well-defined semantics. It also allows embedded LaTeX code
so that if Org-mode is lacking support in some area, you're not out of
luck.
While HTML is a bit less "wonderful" than LaTeX, it is still quite
important. Org-mode documents can be exported to HTML in much the same
way as LaTeX is. In fact, [this blog post](https://github.com/emallson/atlanis.net-blog/blob/master/resources/posts/org-beamer.org) was written as an Org document and
then exported into HTML! You can read more about how this is done in a
[previous post](http://atlanis.net/blog/posts/new-site-stasis.html).

Of course, there are many other things it can do. I myself have only barely scratched the surface of its capabilities. However, these functions are sufficient for our usage: writing Beamer presentations in Org-mode.

Why Org-mode on top of Beamer?

The primary reason I use Org-mode over Beamer rather than just Beamer is reduced verbosity. For example, here is a comparison of a simple presentation and the resulting LaTeX output:

Org-mode

#+TITLE: A Presentation
#+AUTHOR: John Doe
#+DATE: 18 April 2014
#+OPTIONS: toc:nil num:nil
#+STARTUP: beamer
* What is Beamer?
  - LaTeX styles for presentations
  - Exports to PowerPoint-style presentation format
* What is Org-mode?
  - Emacs major-mode for organized thought
  - Spiritual successor to =outline-mode=
  - Supports wide variety of markup
    - /italic/, *bold*, =code=, ~verbatim~, etc.
    - Inline LaTeX (including math!)
  - Can export to LaTeX, HTML, and other formats
* How Do I Work This Thing?
  - Edit text
  - Export to PDF
    - Intermediate LaTeX file is created and saved
    - This allows all the fine-grained tweaking of LaTeX -- optionally
  - Unfortunately, the difficult bit remains: giving the presentation

LaTeX with Beamer

(***Note:** indentation was added after generation by me to make the LaTeX more readable*)

% Created 2014-04-18 Fri 21:26
\documentclass[presentation]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{minted}
\usepackage{microtype}
\usetheme{default}
\author{John Doe}
\date{18 April 2014}
\title{A Presentation}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs 24.3.1 (Org mode 8.2.5h)}}
\begin{document}
\maketitle
\begin{frame}[label=sec-1]{What is Beamer?}
  \begin{itemize}
  \item \LaTeX{} styles for presentations
  \item Exports to PowerPoint-style presentation format
  \end{itemize}
\end{frame}
\begin{frame}[fragile,label=sec-2]{What is Org-mode?}
  \begin{itemize}
  \item Emacs major-mode for organized thought
  \item Spiritual successor to \texttt{outline-mode}
  \item Supports wide variety of markup
    \begin{itemize}
    \item \emph{italic}, \alert{bold}, \texttt{code}, \verb~verbatim~, etc.
    \item Inline \LaTeX{} (including math!)
    \end{itemize}
  \item Can export to \LaTeX{}, HTML, and other formats
  \end{itemize}
\end{frame}
\begin{frame}[label=sec-3]{How Do I Work This Thing?}
  \begin{itemize}
  \item Edit text
  \item Export to PDF
    \begin{itemize}
    \item Intermediate \LaTeX{} file is created and saved
    \item This allows all the fine-grained tweaking of \LaTeX{} -- optionally
    \end{itemize}
  \item Unfortunately, the difficult bit remains: giving the presentation
  \end{itemize}
\end{frame}
% Emacs 24.3.1 (Org mode 8.2.5h)
\end{document}

Dunno about you, dear reader, but to me the Org-mode file looks significantly easier to read/write/maintain than the LaTeX one. Org-mode used in this context is fundamentally a quality-of-life change from Beamer. However, it is a powerful tool in its own right.

Using Org-mode with Emacs

Now then, with the reasoning for why you'd use Org-mode out of the way I can move onto how to actually use the damn thing! If you're already comfortable with Emacs, it is very, very simple. If you aren't, then you will have a bit more difficulty due to the learning curve imposed by Emacs.

Start by opening a new file for the presentation (that's C-x C-f for the uninitiated). Provided you chose a file-name ending in .org, org-mode will already be on. You will also need to turn on org-beamer-mode using M-x org-beamer-mode RET. An attribute can be added to the file which will inform Org to start Beamer mode every time this file is opened:

#+STARTUP: beamer

Though no further attributes need to be set, there are a few others that are useful in most cases:

This attribute sets the title of your presentation. If it is not set, it
defaults to the name of the file.
Sets the author's name. If it is not set, it defaults to your username.
Sets the date used by the title slide. If unset, defaults to export date.
Sets export options. Some useful ones are <code>toc</code> and <code>num</code>, which specify
whether to create a Table of Contents and whether to number sections.
Boolean options use lisp-y style. For example: `toc:nil` disables the ToC,
while `toc:t` enables it (analogous to `nil` and `t` in both Common and
Emacs Lisp). These options override the user's Emacs configuration. Both
`toc` and `num` default to `t`.

After that, start writing! Beginning a line with *'s creates a new heading. In a LaTeX export, these are sections. Increasing the number of stars creates sub-sections. For Beamer, the top-most headings are slides (unless #+OPTIONS has H:x specifying another level x to start at) and the sub-headings are treated as sub-sections of individual slides.

Once you've written for a while, you probably want to see what your work looks like! Use C-c C-e to display all export options. From there, l P will export a PDF version of the presentation. You can view the output either by opening it manually or using the C-c C-e l O command (which creates and opens the file). Many PDF viewers automatically reload when you regenerate the PDF, which is often preferable to continuously opening and closing the viewer.

More content can be written, and presentation regeneration is just a key chord away.

So…What's My Setup?

This is all well and good, but John asked about my setup, not how to use Org mode! My workflow can be summarized like this:

Very simple and straightforward, just the way I like it. While it is not quite as simple as a WYSIWYG editor like PowerPoint (which lacks the export step), it integrates much better into my usual environment.

But Can I Use Org-mode for Presentations Without Emacs?

In theory, it is possible to use Org-mode outside of Emacs. Org documents are plain text and pretty straightforward to parse. The format has parsers written in other languages (Common Lisp, PHP and Python are all listed on the community tools page) and there are vim plugins for Org files (VimOrganizer and vim-orgmode).

In practice, it isn't really a good idea. The parsers are geared towards reading org documents into data structures for manipulation, and the vim plugins implement only a subset of Org-mode's functionality. If you want to use Org mode it is best to use Emacs along with it, even if you just edit in vim and fall back to Emacs for exporting.

If you're a vim user who is on the road to recovery interested in trying Emacs, you should check out bling's Emacs->Vim Survival Guide and [Emacs bootstrapping](https://bling.github.io/blog/2013/09/09/vim-in-emacs-bootstrap/) posts.

Example Time!

Of course, all of this is moot unless you can actually generate decent-looking presentations with it, right? Since I've done a some presentations recently, I'll pull two from my stock.

I wrote code and slides for last week's BoF presentation. The PDF output of
the slides can be downloaded [here](https://atlanis.net/media/blog/org-beamer-example-output/bof.pdf). This presentation demonstrates both
using LaTeX commands to override default behavior and displaying inline
code with syntax highlighting.
Note: the code in this presentation could have been included using
`#+INCLUDE`, however it was longer than the slide width and I wasn't sure
of a good way to do wrapping without either modifying the code directly or
copying it into the org file. I opted for the latter to preserve proper
formatting in the code itself.
I also wrote slides (and code, but not included in the presentation) for a
Keeping Current presentation. The PDF output of the slides can be
downloaded [here](https://atlanis.net/media/blog/org-beamer-example-output/keeping-current.pdf). This Org file demonstrates inline LaTeX (optional
`#+BEGIN/END_LaTeX` commands can be used to make it explicit) as well as
preventing certain parts of the document from being exported (note that the
*Abstract* subtree is not exported because it has the `:noexport:`
tag). This feature can be used for storing speech notes with the slides
without having them exported alongside them.
As part of my upcoming summer internship, I was asked to put together a
slide giving a brief biography. This was done [as an Org document](https://atlanis.net/media/blog/ibm_bio_slide.org). The PDF
output can be viewed [here](https://atlanis.net/media/blog/org-beamer-example-output/ibm_bio_slide.pdf). This example demonstrates using columns and
embedding images.

You might note that neither of these presentations are particularly pretty. However, this is because in both cases I had very little time available when they were written and so used the default Beamer template. You can see many better-looking examples by searching for beamer presentation on Google Images.

So Should I Use Org-mode?

Yes! At least give it a try! Org-mode has come bundled with Emacs since version 22, but you can also optionally install the latest version via `M-x package-install RET org RET`.

While I have no doubts that many people will continue to prefer PowerPoint for their presentations, using Beamer with Org-mode is an effective and in many cases superior alternative – especially in Math- and Code-heavy fields like Computer Science.