Wednesday, September 16, 2009

Beamer + Ipe + views...

At this point, mostly everyone is aware of how to use beamer to make presentations in LaTeX. However, many fewer people (mostly only geometry folk) are aware of Ipe, a kind of next-generation xfig.

You may stop reading right now if
  • you always use powerpoint for slides OR
  • you rarely have to use LaTeX in slides OR
  • you really hate non-WYSIWYG presentation software
Still here ? ok...

I wanted to share a workflow tip that I found quite useful when making slides with step-through animations. Suppose you have a sequence of slides in a presentation that unfold a figure step by step, or animate some algorithm execution etc. Ipe, coupled with a few LaTeX commands, provides a really nifty way of rendering the animation without jumps, misalignments, or misdrawings.

Ipe (and many other drawing programs) has the notion of a layer. More powerfully, Ipe also has the notion of a 'view', which you can think of as a (sub)set of layers. For example, if you have a drawing with layers 1,2,3,4,5, then view 1 might consist of {1,2,3}, and view 2 might consist of {1,2,5}, and so on.

What this means is that when you want to do step-animation, it's really easy. Each time you move to a new step, you create a new view in Ipe (which also usually creates a new layer), and you can select whichever subset of the current set of layers you want to render, as well as drawing new ones.

Ipe stores all the views as separate pages in a PDF file, so your final animation consists of a multi-page PDF file. And now comes the cool part.

Suppose you want to include this sequence of views in a beamer slide, with each view appearing after the next in response to a mouse click. You need two things:
  • pdftk (which comes standard in most linux installations), which allows you to split a PDF file into multiple files (one per page), with any format for the filename that you specify. For example, I have a command called 'splitpdf' that does this:
    pdftk $1.pdf burst output $1-%d.pdf

    which takes a file name.pdf and splits it into name-1.pdf, name-2.pdf and so on.

  • Next, you need the (standard) LaTeX package 'xmpmulti' which gives you the command \multiinclude. It allows you to include multiple figures that share a common prefix. So for example, to include all the figures created by the previous pdftk command, you merely write
    \multiinclude[start=1,format=pdf]{name}
    .The 'start=1' starts counting from 1 instead of 0, and you can also specify an end-counter.

But the best part is when you instead use
\multiinclude[<+>][start=1,format=pdf]{name}
Now, the files are included with an automatic 'replace each by the next' mode (<+> is standard beamer notation for this). At this point, you have a sequence of animations ready to go. In fact, when I give lectures, I have a number of slides that just look like this:
\begin{frame}
\frametitle{Title}
\mi{name}
\end{frame}

where \mi is a macro I defined for the above multiinclude. Ipe does all the layering and viewing work for me, and multiinclude takes care of the rest. This has made making complicated animations really simple and fast.

p.s if you're still wondering why one should use Ipe instead of xfig, the LaTeX integration in Ipe is superb. No nonsense with special flags, and pstex_t and craziness like that. You get WYSIWYG LaTeX inside Ipe, you can use whatever macros you have in your text, and the various nifty alignment tools make an Ipe drawing look really clean.

13 comments:

  1. You dont have to split the ipe pdf file - you can just use the page command.
    Example:

    \includegraphics<1>{figs/pol}
    \includegraphics[page=2]<2>{figs/pol}
    \includegraphics[page=3]<3->{figs/pol}

    I do split and convert ipe into ps, so that I can still use latex (and not pdflatex) for regular papers. That requires some macros...

    --S

    ReplyDelete
  2. \includegraphics in pdflatex has an optional argument called "page"
    so you can write something like
    \includegraphics[page=5]{filename}
    to present the fifth page in filename.
    This allows you to retain all the views in one pdf file instead of
    split them to many pdf files.
    I don't know whether this approach
    can be combined with \multiinclude.

    Manor

    ReplyDelete
  3. Have you tried inkscape instead of ipe? I have never used ipe so far... but just from a first glace, inkscape looks better to me.

    ReplyDelete
  4. It's even better than that.

    If you use the pgf library (which seems to related to beamer in some way, although I'm not sure), you can use multipage pdfs directly. Simply use the command

    \pgfimage[page=xx]{filename}

    ReplyDelete
  5. Great tip! But is the pdftk step necessary? When using pdflatex one can already use multipage PDFs like this:
    \includegraphics[page=1]{foo}
    \includegraphics[page=2]{foo}
    Is there no way to do some Beamer magic on that?

    Personally, I've made my last few presentations fully in Ipe (one page per slide, with views for animations). Apart from the lack of the visually nice Beamer themes, I've been pretty happy with that approach.

    ReplyDelete
  6. I was wondering in class yesterday how you were doing that so effectively.

    ReplyDelete
  7. Sariel, Manor, Neil and Dirk: all true, and that's what I was doing before, but if I have 10 slides, I really don't want to do 10 lines of manually typed includegraphics or pgfimage. That's why I like multiinclude.

    Ideally, I'd combine them both and say something like
    \includegraphics[page=1-10]{name}, but includegraphics doesn't support that.

    ReplyDelete
  8. I assumed you know about it. The thing is that in most of my figures I have extra junk (hidden on other views/layers). And your solution seems to imply that such junk pages would be visible. No?

    ReplyDelete
  9. HA ! Nothing I create is junk !!

    more seriously, that's true. multiinclude can't select a non-contiguous user specified set of views, in which case it's better to use includegraphics in the manner you suggest.

    What would really be good is if multiinclude inherited the pages= option from pdfpages, so you could specify an arbitrary set of views to use.

    ReplyDelete
  10. If you haven't heard of it the powerdot package is really nice for creating presentations. It has a nice \onslide*{1-5}{data} command which makes data appear on slides 1 through 5 and the '*' makes it take no space on the 6... slides. I use powerdot for all my presentations.

    Cheers!

    ReplyDelete
  11. Doesn't TikZ integrate well with beamer for this?

    ex: http://www.texample.net/tikz/examples/beamer-arrows/

    ReplyDelete
  12. FWIW, powerpoint also effectively has layers: grouping and selection pane let you do essentially everything you can do with layers.

    ReplyDelete
  13. Is there any mac love for this tool?

    ReplyDelete

Disqus for The Geomblog