2009-10-18

[Updated:fixed an error in the template]
Things have been a bit quiet at Emacs-Fu lately; this is mostly because I
have been very busy with work, traveling, traveling for work
etc. Emacs-wise, this has been a very intensive time, and I have been able
to move more and more task to emacs – both professionally and
privately. This is mostly because thing become easier when I can do all my
things in one place.

Anyhow, one of the tricks I picked up recently is to write presentations
with the combination of org-mode and a LaTeX-package called beamer. The
most common tool for doing presentations is Microsoft's Powerpoint
program. It gets a lot of criticism, most famously from prof. Tufte in his
Powerpoint is Evil essay. Of course, the problem is in misuse of the tool,
not so much the tool itself.

Still, I didn't want to use Powerpoint (or Powerpoint-wannabees, like
OpenOffice's Impress). For the technically-inclined, the knee-jerk
reaction to this kind of problem is to shout 'LaTeX!'. Indeed - the LaTeX
text-processing system offers a package called Beamer, which allows you to
write presentations with LaTeX. It is quite powerful, and even allows for
all kinds of fancy graphical bling (fade-in, fade out etc.); even better, it
generates PDF-files, which can be viewed just about anywhere. The various
themes and color settings it offers are quite nice, even though they tend to
fill only a small corner of the design-universe…

beamer and org-mode

Now, while I am no stranger to LaTeX, especially for writing a quick
presentation, it can be a painful to remember the various directives and
options. I am not really a daily LaTeX-user, so I tend to forget these
things. I am a daily org-mode user though, and org-mode can export to
LaTeX (which then, in turn, are translated into PDFs). So why not use
org-mode to generate presentations?

It turns out that that is quite easy.

First, we need to define some of the LaTeX-boilerplate, and tell org-mode
about it, so we never need to think about it again. Put the following in
your .emacs:

This is based on the template by Thomas S. Dye on the org-mode mailing
list. You can of course add other packages to it with \usepackage. In my
version, I have add the Listings-package for including syntax-highlighted
snippets of source code in my presentations. Importantly, I added the
[fragile] options to the frame-settings, otherwise you cannot include
such source code fragments without LaTeX complaining in various unhelpful
ways.

Note, you can customize the way the Listings package works by changing the
template above; or by setting the options in the org-file; this involves
some 'raw LaTeX' though. It might make sense to define some macros for
that.

Now, we can easily make a presentation in org-mode; simply start the file
with something like:

In other words, we include some 'raw' LaTeX to do this. Now, the
org-mode-way of doing this, would be to use something like

#+BEGIN_SRC c
/* code */
#+END_SRC

as discussed before. This works well when exporting to HTML, but at this
moment this will simply translate into a verbatim environment in LaTeX - so
we use lstlisting to get some syntax-highlighting.

including pictures

Of course, the full arsenal of org-mode tools is available as well, for
example Ditaa, as discussed before. Ditaa is now shipped as part of
org-mode, and you can use it to create picture which are then included in
your presentation. Very nice.

For including existing images (PNGs, JPGs etc.), it's probably easiest to
put use some raw LaTeX for that, e.g., something like

#+LaTeX:\includegraphics{/some/path/emacs.png}

putting it together

Now, let's put it all together. Below is an example presentation. Assuming
you have everything installed (ie., LaTeX with the listings package, a
fairly recent org-mode, ditaa), you create your presentation.org and
then press C-c C-e d and your presentation (presentation.pdf) is
generated and automatically shown in your PDF-viewer. Easy!

The intermediate files (such as presentation.tex) are there as well, so
you can check them if something went wrong.

I have uploaded the resulting PDF to Slideshare, so you can see what it
looks like. However, the Slideshare-converted version is extremely
blurry, unlike the crisp PDF I actually created. I'd be happy to upload
the file somewhere else if someone can point me to a good place, thanks!

So hopefully this shows that you can quite easily make presentations with
org-mode, with some help from Beamer, LaTeX etc. Beamer actually provides
a lot more, such as funky slide-transitions and other tricks – but the
things here should give you a good starting point.

djcb: i see. yes long list aren't too practical, but the great thing about latex and org-mode is you don't have to worry about formatting and layout, yet with beamer, u have to gauge the number of bullets on a slide. it'd be nice if i don't have to worry about this and have it decide how many bullets go on a slide and continue to the next if there isn't any more room.

Nice- I've been working all day on a presentation with beamer and org-mode, and now I find this. Even though I'm a heavy latex user, I must say that this way of doing things is *much* more efficient.

Regarding long slides: maybe you can try the allowframebreaks option, which will give things like:\begin{frame}[allowframebreaks]{the title}I don't know if there are any real disadvantages to setting this for all frames- I've only used this option for frames containing a list of references.

One more thing that I do differently is to define frame titles to be level 3 headings in org export, not level 2; this works well for large presentations in which having more structure is important. The downside is that I need to always have level 2 headings, which is awkward for short sections.

@vinhdizzo: fair enough; beamer is a bit 'special' in this regard. You might want to try Prosper instead -- you'd have to change the template a bit for that, but it should be straightforward (I suppose...)

@Anonymous: hope it's useful. About allowframebreaks -- I had to remove them or for some reason there as a vertical bar next to the level-2 headings for some reason. I couldn't quite figure out why; it might something with my setup.

I followed this post, and found 2 things I needed to work around:1. the default org package does not have ditaa, but the newest org version (6.31a) has this tool and integrated pretty well2. For the 3rd slice (Overview):** Overview

djcb:Thanks for the reply. My situation is, I noticed in your pdf online the (1) (2) (3) are itemized by icons showing correct number; in my case, the are also itemized by icons, but all the 3 icons are (1) (1) (1). I tried** Overview*** Introduction*** Main part*** Questionsthen it works. But I looked into your code, your code is

@Mark Scala: definitely that is possible; Beamer has support for that -- youwill need to go down to the Beamer/LaTeX level though(using #+begin/end_LaTeX/#+begin/end_LaTeX). It be nice if it were a biteasier using 'normal' org-mode though...

Here are the details: When using an older version of org-mode (version 6.14) (with djcb's corrected .emacs snippet) it still wasn't working quite right - the title page was coming up blank (save the date). None of the MACRO parameters were being passed to the .tex file. Apparently 6.14 org to tex translation function doesn't pick up MACROs.

So I picked up the latest 6.33c version of org-mode and everything seems to be working now!

Although... I don't understand why the -s option doesn't scale my image larger? From the ditaa website, the syntax section lists '-s' as "-s,--scale A natural number that determines the size of the rendered image. The units are fractions of the default size (2.5 renders 1.5 times bigger than the default)."

Does that must mean in terms of image quality? What if I did want my image to actually be 1.5 the size (width/height) larger than the default?

Recent org-mode has integrated support for exporting to Beamer. See the tutorial at http://orgmode.org/worg/org-tutorials/org-beamer/tutorial.htmlIt has some nice features like support for columns environment.