Fonts in LaTeX, Part One: XeLaTeX

Now and then I get asked about how to use some TrueType or OpenType font with LaTeX, so I figured I would take the time to write up some simple tutorials on how to do so. The first part will focus on the easiest route to making use of TrueType and OpenType fonts in LaTeX: XeTeX and XeLaTeX.

XeLaTeX also has the advantage of not only giving easy access to modern fonts, but also accepting Unicode input files.

The first thing you need to do is find out if you have XeLaTeX installed, and if it is a sufficiently up to date version. This is easiest to do from the command-line:

% xelatex
This is XeTeXk, Version 3.141592-2.2-0.996 (Web2C 7.5.6)
%&-line parsing enabled.

This is the version that I am using for the tutorial, and is what comes with TeX Live 2007. I highly recommend just installing and using the entire TeX Live CD/DVD, even if you're using a Linux system that offers TeX Live packages, because, in particular for Debian/Ubuntu, I've found that the default installation often doesn't install some important packages, and it can be a pain sort through all the available packages using Synaptics or whatnot to find what it didn't install.

I am also assuming that you are using a (modern) Unix or MacOS X system. I assume that most of this material should also apply when using Windows, but if someone can comment, let me know.

Now, as an example, say you want to use the Pagella font from the TeX Gyre project. First download them and install the fonts (the otf files) as you normally would on your computer. Under MacOS X, this means using Font Book. If you double-click on an otf file it will load Font Book for you and there will be dialog with a button to install the font. If you load Font Book yourself, you can use the "Add Fonts..." menu item under the File menu to select the files. Under a modern Unix, I would recommend just placing the otf files in your ~/.fonts folder, though I think file managers like Nautilus also understand how to install fonts.

And that was all the installation work necessary; as I said, XeLaTeX is the easiest solution unless you have specialized needs. Now just create a small LaTeX document:

  2. \documentclass{article}
  3. \usepackage{fontspec}
  4. \setromanfont{TeX Gyre Pagella}
  5. \begin{document}
  6. Testing XeLaTeX!
  8. Greek: τεχ.
  9. \end{document}

The fontspec package isn't necessary, but it makes dealing with fonts in XeLaTeX much easier, for example it defines the convenient \setromanfont command. You can learn more about all of its great features from its beautifully formatted manual.

The other thing you might need to know is what XeLaTeX thinks your font is called. If you're using TeX Live, like I suggest, you will have the program otfinfo at your disposal that can do that for you:

% otfinfo --family texgyrepagella-regular.otf
TeX Gyre Pagella

Note that despite its name, otfinfo will also work on ttf files, assuming that they include OpenType data in them. The other option is to use Font Book on MacOS X or fc-list from the command-line in Unix.

Now you just run xelatex:

% xelatex test.tex
This is XeTeXk, Version 3.141592-2.2-0.996 (Web2C 7.5.6)
%&-line parsing enabled.
entering extended mode
Output written on test.pdf (1 page).
Transcript written on test.log.

And you have your document:

XeLaTeX test

I think that is about everything you need to know, but if you try this tutorial out and find that something doesn't work, let me know.  If you have more specialized or demanding typographical needs, you may want to use pdfTeX and pdfLaTeX, and part two of the tutorial will explain how to do the necessary configuration to use TrueType and OpenType fonts with them.


  1. Alan Schmitt said,

    July 12, 2008 @ 1:33 pm

    Maybe you could expand on the font installation bit, saying that only the otf files are necessary.

    Thanks a lot for this great tutorial, it worked out of the box here (I’m using TeX Live 2007).

  2. Patrick Hall said,

    July 12, 2008 @ 11:04 pm

    I would *love* to figure out how to get utf-8 input files working with LaTeX under Ubuntu; I’ve been trying to do so for some time, with no success. I have a bunch of links to various things I’ve tried at .

    Do you know what exactly does it takes to install the whole Texlive CD under Ubuntu? I’ve installed so many TeX packages with apt-get by now that I’m afraid I’ve lost track; I do have xelatex installed, though.

    When I run your example document, I get:
    $ xelatex gyre.tex
    This is XeTeXk, Version 3.141592-2.2-0.996-patch1 (Web2C 7.5.6)
    %&-line parsing enabled.
    entering extended mode
    Babel and hyphenation patterns for english, usenglishmax, dumylang, noh
    yphenation, pinyin, loaded.
    Document Class: article 2005/09/16 v1.4f Standard LaTeX document class

    ! LaTeX Error: File `lmodern.sty’ not found.

  3. Greg said,

    July 13, 2008 @ 9:58 am

    @ Patrick: sudo apt-get install lmodern

    Thanks for the tips! I didn’t know about XeTaTeX, and it’s awesome.

  4. washburn said,

    July 13, 2008 @ 5:33 pm

    @Alan: Thanks! I just revised it a little to hopefully be clearer about installing the fonts.

  5. washburn said,

    July 13, 2008 @ 5:35 pm

    @Patrick: No, offhand I do not know what set of packages you would need to install to be sure you have installed the entirety of TeX Live. This is why I just recommend installing it yourself than using the package manager. As Greg pointed out, you probably need to at least install the lmodern package.

  6. washburn said,

    July 13, 2008 @ 5:36 pm

    @Greg: Thanks! I’m glad that so many people seem to be benefiting from this information.

  7. Patrick Hall said,

    July 13, 2008 @ 9:16 pm

    Hi guys,

    Thanks Greg and washburn, I seem to be making some progress here!

    So my goal is to get the extremely multilingual file

    Into a pdf; I have had partial success:

    Next I’ll trying install the whole cd with the package manager as you recommend.

    Thanks again

  8. washburn said,

    July 13, 2008 @ 9:22 pm

    @Patrick: It looks like the problem is that you are not using a font that includes all of the necessary glyphs. It is pretty rare for a single font to include glyphs for all of those languages. So to typeset that document you are going to need to switch between multiple fonts.

  9. Dario said,

    July 18, 2008 @ 12:26 am

    I thought you might enjoy a short article I wrote on expert font features using XeTeX:

  10. Hector said,

    February 13, 2009 @ 8:08 pm

    Thanks for great info!
    Just noticed a little typo:


    is missing the leading “\”, as in:


  11. washburn said,

    February 13, 2009 @ 8:47 pm

    @Hector: Thanks, the leading backslash is actually there when I edit the article, so it must be some strangeness with how WordPress is rendering it that I need to figure out.

  12. plgx said,

    March 5, 2009 @ 9:26 pm

    Maybe \\

  13. washburn said,

    March 9, 2009 @ 2:24 pm

    @plgx: No, the problem seems to be that if I write



    the first character gets eaten. If I just put in a newline



    It seems okay.

  14. John Jason Jordan said,

    April 6, 2009 @ 7:39 am

    Thanks a lot for this how-to. I finally got Lyx using my Junicode font. However, there is problem. The main reason I need my Junicode font is for linguistics work, that is, I need all 150 or so of the IPA characters that the Junicode font has. The problem is that all text comes out in Junicode *except* the IPA characters. For some reason it is using some weird font. And the weird font is not taking attributes like bold or italic.

    I think I need a way to enter the IPA characters by Unicode code point instead of from the Insert > Special Character menu.

  15. washburn said,

    April 6, 2009 @ 9:32 pm

    @John: I’ve never really used Lyx, so I am not sure how much useful advice I can provide. I would first check whether it is indeed saving files in UTF8 format, as by default XeTeX expects that the input uses a UTF8 encoding of the text. Based upon my interpretation of, Lyx does not save in UTF8 by default, so I am going to guess that is the most probable cause.

    If that isn’t the problem, I would recommend opening your document in another Unicode aware editor or viewer (I can’t really suggest one without knowing what platform you are using) and check whether IPA symbols in the document look correct. Then I would try running XeTeX manually and see what happens.

  16. John Jason Jordan said,

    April 7, 2009 @ 2:40 am

    Thanks for the response. Since my first post above I have made progress. That is, I have discovered the main source of the problem.

    I have been using the Junicode face (on Sourceforge) for years for linguistics work. I guess in all that time I never used anything but the regular font. I was trying to set the title of a book in Lyx, and I wanted it bold. There were IPA characters in the title and they were dropping out.

    Today it dawned on me to verify that the glyphs actually existed in the fonts. I opened each of the four fonts in Fontforge and, guess what? Most of the IPA and combining diacriticals glyphs were missing in the bold and bold-italic fonts.

    All this time I was relying on Gnome Character Map. It shows the characters as present in all the fonts. But what Character Map is actually doing is taking the regular version of the font (since all you can select is the family name). When the user clicks on the italic button it slants it, and when the user clicks on the bold button it makes it fatter. After discovering the truth with Fontforge I observed that the a in the regular-italic and bold-italic was really just a slanted regular a, not the script a that it is really supposed to be.

    So Gnome Character Map is a shameless liar.

  17. John Jason Jordan said,

    April 7, 2009 @ 2:52 am

    I should have added that I did figure out how to enter IPA directly in LyX. And I also figured out about UTF-8. However, it is still messing up on the double breve (0×0361). This glyph is available in Junicode only in the regular font. However, what I am getting from LyX/XeTeX is a single short mark that covers just one letter, and it appears for all the fonts, not just regular. Somewhere a glyph from a different font is being substituted.

    But I am not going to pursue it further. TeX/LaTeX/LyX/XeTeX are not good solutions for my work. I need much more design freedom. InDesign works much better for me, although I dislike intensely the corporate bs. I need to see what it looks like as I work.

    Thanks again for the response.

  18. washburn said,

    April 8, 2009 @ 11:04 am

    @John: I think part of the issue with Gnome Character Map is that the underlying font engine it uses tries to be smart about substituting glyphs from other fonts if the font you have requested does not include the glyph.

    I expect your problems could be resolved, but I don’t really have enough information to go on. In any event, TeX’s strength is typesetting mathematics and its macro capabilities. Given that you are interested in typesetting linguistics, InDesign may indeed be the better choice for your needs.

  19. Swift Arrow said,

    April 17, 2009 @ 4:43 pm

    Where’s part two of this article?

  20. Swift Arrow said,

    April 17, 2009 @ 4:46 pm

    I find Scribus to be very good. Just converted my student’s association to it from publisher. And it’s quite like indesign.

  21. Using Unicode Character in LyX or LaTeX: XeTeX | 小石头工作室 . Stone Studio . said,

    January 25, 2010 @ 12:31 am

    [...] [...]

  22. Ron Bannon said,

    May 19, 2010 @ 4:25 am

    Thanks. Works like a charm. I just can’t figure how to typeset the XeLaTeX logo.

  23. Jaspreet said,

    March 19, 2013 @ 4:53 am

    Hello, I am using ubuntu 12.04. I have installed the LaTeX using sudo apt-get install texlive-full. Now I want to write a document in punjabi with font style gurmukhiwebthick. I have installed this font using gurmukhiwebthick.ttf file. Then I write the following code:

    \usepackage[T1]{fontenc} %allows you to specify the font encoding

    \usepackage{fontspec,xltxtra,xunicode, multicol} % Support Unicode fonts
    \defaultfontfeatures{Mapping=tex-text} % For archaic input (e.g. convert — to en-dash)

    \newfontfamily{\Pl}[Scale=1.5]{Lohit Punjabi}

    {\gg ਸੋਮਵਾਰ} Monday

    after compilation I got following error:
    ! fontspec error: “font-not-found”
    ! The font “gurbaniwebthick” cannot be found.

    Please help me.

RSS feed for comments on this post · TrackBack URI

Leave a Comment