Stevebook - [ blog:using_markdown_for_beamer_presentations ]

# Using Markdown for Beamer Presentations

I've recently had to make another presentation, and since I'm now fully into a LaTeX-oriented workflow when it comes to documents, Beamer is my choice.

However, one thing I hate is the verbosity of the markup. Fortunately there are a bunch of “minimalized” markup languages that can help resolve this problem. One is the well-known Markdown. I actually think it's one of the less powerful textual markup languages, but it's somehow one of the most popular.

It is used on reddit and Stack Overflow, and so I've gotten quite used to it. Fortunately there is an awesome tool called Pandoc that can be used to translate Markdown into other formats. Primarily this is for HTML and LaTeX.

While writing articles in LaTeX is not that verbose, I definitely find structures such as \emph{..} less intuitive than just surrounding text with underscores. But for Beamer, I find the itemize environment just has far too low a markup-to-content ratio for my tastes. I really like the idea of a text document looking as similar as possible to how you'd write it naturally in a raw text file. Sticking to Markdown also means not needing to memorize yet another markup language… I'm even considering moving to a Markdown-based system for this site, just because I'm constantly forgetting the DokuWiki syntax.

It is the list syntax of Markdown that really makes using it for Beamer a huge advantage over straight LaTeX. Of course, there are downsides as well: you can't control columns, you can't specify image sizes, etc. Fortunately Pandoc essentially solves this by rote copying any unrecognized LaTeX or HTML markup it sees.

This means you can use Markdown for headings, formatting, and lists, and just drop in citations, \includegraphics and math wherever you please.

The result is being able to specify a presentation (unrelated images and math shamelessly stolen from Wikipedia) like:

% Stephen Sinclair
% My presentation
% \today

Introduction
============

This is _my_ presentation.

* It is awesome.
* And has pretty math:

$\hat{f}(\xi) = \int_{-\infty}^{\infty} f(x)\ e^{- 2\pi i x \xi}\,dx$

Conclusion
==========

* Pandoc **rocks**.

\centerline{\includegraphics[height=2in]{Sinc.pdf}}

To me, this is a huge improvement over:

\title{Stephen Sinclair}
\author{My presentation}
\date{\today}

\begin{frame}{}
\titlepage
\end{frame}

\begin{frame}{Introduction}

This is \emph{my} presentation.

\begin{itemize}
\item
It is awesome.
\item
And has pretty math:
\end{itemize}
$\hat{f}(\xi) = \int_{-\infty}^{\infty} f(x)\ e^{- 2\pi i x \xi}\,dx$
\end{frame}

\begin{frame}{Conclusion}
\begin{itemize}
\item
Pandoc \textbf{rocks}.
\end{itemize}
\centerline{\includegraphics[height=2in]{Sinc.pdf}}

\end{frame}

The Markdown syntax is just easier to look at, and easier to think about. Being able to see the content instead of having so much markup staring you in the face really helps to get an idea of the overall picture of the document.

I should mention that it is even easier to look at if you use markdown-mode in Emacs, or something similar that can do syntax highlighting.

## To use it

To get Pandoc-generated LaTeX working with Beamer, I just had to specify a template specifying the Beamer document class, with a couple of other header items. Lastly I couldn't get around a tiny bit of post-processing using Perl regexes. I needed this to convert \section markings to \begin{frame} and \end{frame}.

With the template, which you can download here, you can use the following steps to produce a Beamer presentation:

pandoc --template beamer.template \
-i presentation.markdown -o presentation.tex
perl -pe 's/\\section/\\end{frame}\n\\begin{frame}/' -i presentation.tex
perl -pe 's/\\end{document}/\\end{frame}\n\\end{document}/' -i presentation.tex
pdflatex presentation.tex </dev/null
bibtex presentation
pdflatex presentation.tex </dev/null

I usually stick these commands into a simple Makefile. The bibtex step is only needed if you have any citations, and of course you should modify the template to taste. Note that the template imports natbib, which isn't necessarily everyone's cup of tea—feel free to exclude it. My favorite Beamer style is “Berlin”, so that is what is specified in it.