XeTeX and Mac OS X fonts

I don’t actually know of anyone who read this blog that uses LaTeX (the joys of which I have blogged of in the past), but after spending way too much time today trying to figure out how to use XeTeX, which lets you use Mac OS X’s built-in fonts with LaTeX, I figured I’d post my really, really simple results here. Maybe someone will find this in a Google search someday and I can save them some headaches. (I’m assuming you’ve used the MacTeX distribution of LaTeX for Mac, which includes all the things you need by default in your LaTeX installation. If you used a different distribution, you may or may not have what you need — I know nothing about the others.)

Anyway, like many things LaTeX, it’s very easy once you finally get it, but finding good, clear documentation not written by and for people who are already TeX experts is not so easy. Additionally, one of the benefits of LaTeX is that you can forget about formatting and focus on your writing. Of course, in practice, most people anal enough about their typesetting to use LaTeX end up spending hours “fetishizing the text” and tweaking everything to be just right. So here you go:

In your preamble, comment out whatever you use to normally specify your font (for me this is \usepackage{palatino}) and then add this:

\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\defaultfontfeatures{Scale=MatchLowercase}
\setromanfont[Mapping=tex-text]{Garamond}
\setsansfont[Mapping=tex-text]{Lucida Grande}
\setmonofont{Monaco}

For \setromanfont and \setsansfont pick any font on your system! That’s it! Nothing else has to change in your TeX file. If you ever need to give your .tex file to someone not on a Mac or without XeTeX, just comment out those lines and uncomment your normal font package specification. You can do more obviously, such as specify specific fonts throughout the whole document, but to do that I refer you to the fontspec manual.

If you’re using TeXShop, make these changes.

Wednesday, April 25, 2007