Tuesday, February 16, 2010

Matching fonts in Keynote and LaTeX

LaTeX is great if you want to typeset documents with lots of mathematics in them, but what if you want to make presentations with lots of math? Sure, there are LaTeX packages like Beamer with which you can straightforwardly make decent looking presentations using nothing but LaTeX. But none of those packages lets you easily control where items end up on a page, make subtle changes to overall lay-out, or add some motion to your slides.

Keynote does all of those things, and a bit more. Here's for example a slide of presentation I gave some time ago:


The things in the image are all created within Keynote (not in a separate drawing program like Adobe Illustrator), and some of them are even animated. This is simply impossible to do solely with LaTeX, and that's why I've been using Keynote for quite some time now for all my presentations.

However, there was always something annoying me: the fonts in formulae I got from LaTeXiT (a small program that lets you insert LaTeX formula in Keynote) didn't match the font over the overall presentation. And if you're a typesetting nerd like me, that's pretty annoying. Luckily, I found a solution. Here's an example with both type of fonts:


The difference is subtle, but certainly noticable. The greek letters haven't changed, but the others are in the same font in the second equation. Here is how you change fonts:

  1. First, go to the LaTeXiT preferences, and change the default configuration to use xelatex instead of pdflatex:

  2. Next, add the following to the LaTeXiT preamble:

    \usepackage{mathspec}
    \usepackage{xunicode}
    \usepackage{xltxtra}
    \setmainfont{Gill Sans}
    \setmathsfont(Digits,Latin,Greek){Gill Sans}


    Be sure to change the "Gill Sans" to match whatever font you're using in Keynote.

And that's it! After restarting LaTeXiT, all new equations you'll typeset will be in the correct font. Enjoy!