Beamer is a great way to make slides for presentations. It relieves us of the burden of worrying about the exact placement of elements present in the slides.
But LaTeX commands can get in the way of the actual content while we are making the slides (especially when you are in a hurry to finish it). Org mode of emacs is a cool way to make notes in an organized way that lets us focus on the content. Writing the initial draft of the presentation in org mode, then converting it to a beamer tex file and finally adding finishing touches can greatly accelerate the time in which the presentation can be created.
This post gives a broad outline of how to get started with using org mode for writing beamer presentations.
Versions of software used:
We can use the export options to do stuff like setting the theme used for the beamer presentation.
For example, we can use the 'Berlin' theme with
#+LATEX_HEADER: \mode<beamer>{\usetheme{Berlin}}
Things we include in LATEX_HEADER
(and
LATEX_HEADER_EXTRA
) will get appended to the preamble of
the tex file.
LATEX_HEADER
can we specified more than once if we got
multiple lines to include.
Note: Export option names are case insensitive.
#+LATEX_HEADER
and #+latex_header
are
same.
We can use other export options like TITLE
,
AUTHOR
, DATE
whose purposes are evident from
their names.
I use something like this as a template for the presentations that I make in org mode for use with beamer:
#+TITLE: My org-beamer presentation
#+AUTHOR: My name
#+EMAIL: my@email.com
#+DATE: 2022-Feb-19
#+SUBTITLE: org-beamer: subtitle
#+DESCRIPTION: org-beamer: description
#+OPTIONS: H:2
#+LATEX_HEADER: \mode<beamer>{\usetheme{Berlin}}
#+LATEX_HEADER: \AtBeginSection[]{\begin{frame}<beamer>\frametitle{Topic}\tableofcontents[currentsection]\end{frame}}
H: 2
was given as an option to mention the number of
heading levels to export. Headings with level greater than 2 will be
exported differently (I didn't want too many levels. Cleaner that
way).
Org-export to pdf for beamer presentations is done by ox-beamer. It's the beamer backend for the org-export engine (ox stands for org-export, I guess). So load it by adding the following to the emacs config file:
(require 'ox-beamer)
Now upon C-c C-e
for exporting from an org file, we
should see a few option with '(Beamer)' as well.
[l] Export to LaTeX
[L] As LaTeX buffer [l] As LaTeX file
[p] As PDF file [o] As PDF file and open
[B] As LaTeX buffer (Beamer) [b] As LaTeX file (Beamer)
[P] As PDF file (Beamer) [O] As PDF file and open (Beamer)
The Beamer options would not show up if ox-beamer isn't there.
Note that the key combination to export an org file to beamer pdf is
C-c C-e l P
(upper case 'P') and not
C-c C-e l p
(which is for exporting to non-beamer pdf).
The variable that has the command used for producing pdf from org
files is org-latex-pdf-process
. In old versions of emacs
this was org-latex-to-pdf
(notice the extra 'to' in the
name)¹. There are
many old blog posts mentioning this older variable name. I got confused
at first.
I'm using xelatex with latexmk:
(setq org-latex-pdf-process (list "latexmk -xelatex %f"))
By default the pdflatex is used. We can set xelatex as the default latex compiler with
(setq org-latex-compiler "xelatex")
and then if we export the org file as beamer latex, it will show
% Intended LaTeX compiler: xelatex
at the beginning, instead of naming 'pdflatex'.
LATEX_CLASS
export option is used to choose the class
that we would choose using \documentclass
in the tex
source. For me, I didn't have to specify
#+LATEX_CLASS: beamer
but in the output tex file it was
showing up as \documentclass[presentation]{beamer}
.
(I tried using #+LATEX_CLASS: report
and the tex file
got \documentclass[11pt]{report}
.)
We can make our own latex class to control how our org file's contents get inserted into the corresponding latex file.
The name of such custom-made latex classes should be included in the
org-latex-classes
variable before using it with
LATEX_CLASS
. ⁴
'beamer' is defined as a latex class that is added to
org-latex-classes
by ox-beamer itself. ⁶
Current value of org-latex-classes
can be found out like
any other variable in emacs. Following are two ways:
M-x describe-variable org-latex-classes
C-h v org-latex-classes
We can add a new latex class with name, say "mybeamer", like:
(add-to-list 'org-latex-classes
`("mybeamer" ; the name that will be used in LATEX_CLASS export option
,(concat "\\documentclass[presentation]{beamer}\n"
"[DEFAULT-PACKAGES]"
"[PACKAGES]\n")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
Here, contents of [DEFAULT-PACKAGES]
,
[PACKAGES]
are determined by
org-latex-default-packages-alist
,
org-latex-packages-alist
respectively.
The last three lines specify how to treat heading levels 1,2 and 3 respectively.