Posted by: sureshamrita | March 19, 2011

LaTeX + new fonts = XeLaTeX

I was fascinated when I saw that xelatex can use all the new fonts like Asana Math, Cambria (for text and math), Calibri etc, and I need not learn anything new apart from my existing latex understanding. This blog is the summary of my efforts in installing xelatex and the new fonts and making them work on my Ubuntu 10.04 machine!

First of all, for xelatex and the new fonts to work, one should have the latest tex distribution. Unfortunately Ubuntu 10.04 still have only texlive 2009. So the first step would be to acquire texlive 2010 and install it. Once it is done, the rest is trivial. Again installing texlive 2010 is also very easy – straightforward for at least Ubuntu.

1 (a). Installing TeXLive 2010 from a CD

One can get an iso image of TeXLive 2010 from the TeXLive Site. Once the iso image is burned into a DVD, you can do the following for installation.

  • You may need the perl-tk package before you start. You can install this on ubuntu by the command sudo aptitude install perl-tk . I got this information from the blog How to install TeXLive 2010 on Ubuntu 10.10
  • Once  you have installed perl-tk, and the DVD ready, you can follow the detailed instructions on the blog How to install Vanilla TexLive 2010 on Ubuntu 10.04.
  • Make sure to rename your local texmf tree if you have one. I forgot to do this and it created lot of difficulties for me.

1(b) Installing TeXLive 2010 from Internet

Go to this site.

2. Updating TeXLive 2010

  • First you have change the repository from which tlmgr would do the updates. It is done by the command,

tlmgr option repository http://mirror.ctan.org/systems/texlive/tlnet

  • Now you have to update tlmgr itself, if needed. Run the command tlmgr update --self to update the tlmgr itself.
  • Once tlmgr is updated, you can run tlmgr update -all to install all updates. Beware, it will take some time, even to start dumping messages on the screen.

3. Where to put microsoft/other fonts in texlive?

If your platform is windows, you can skip this step and go to section 4. If you are on a Ubuntu machine, you will not have access to the Microsoft fonts in the machine. You need to have the ttf files of the microsoft windows if you want to use them with latex.  Once  you get the font files, this is how you would install them. Getting the font files is described in the next section.

  • TeXlive will have a texmf-local folder inside your texlive installation. Inside that a fonts directory is present. Whatever ttf files you get hold of, you can create a directory inside the texmf-local/fonts/ and store the ttf files. For example I have the following directories there: texlive/texmf-local/fonts/vista, texlive/texmf-local/fonts/comic, texlive/texmf-local/fonts/Bergamo, texlive/texmf-local/fonts/sorts-mill-goudy, texlive/texmf-local/fonts/sorts-mill-goudy, texlive/texmf-local/fonts/STIXv1.0.0 etc.
  • After installing new fonts, you have to run the command fc-cache -fv from your home directory.

4. How to get the microsoft fonts for use in Ubuntu/LaTeX?

You may use any of the method described below:

5. You are done! Ready to test the comic font now

\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage{amsmath}
\usepackage{unicode-math}
\usepackage{lipsum}
\setromanfont{Comic Sans MS}
\setmathfont{XITS}
\begin{document}
\begin{equation}
x = \frac{-b \pm \sqrt{b^2 – 4ac}}{2a}
\end{equation}
\lipsum[1]
\end{document}

You can copy the above code from here

\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage{amsmath}
\usepackage{unicode-math}
\usepackage{lipsum}
\setromanfont{Comic Sans MS}
\setmathfont{XITS}
\begin{document}
\begin{equation}
    x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\end{equation}
\lipsum[1]
\end{document}

This is the output on my machine!

6. How to compile the above code?

  • Save the above file as test.tex
  • xelatex test.tex
  • View the pdf file in your favourite pdf viewer!

7. Some Explanations for the LaTeX code

  • \usepackage{fontspec}: Allows  you to put arbitrary fonts using the command \setromanfont{font family name} . For example \setromanfont{Comic Sans MS}
  • \usepackage{unicode-math}: Allows you to put arbitrary math font using the command, for example,\setmathfont{XITS}

8. How to find the Font Family name?

In windows, this is easy, but in Ubuntu, you can use the command otfinfo. For example, otfinfo --family STIXVarBol.otf gave me the family name as STIXVariants which I can use in the setromanfont or setmathfont commands.

9. Acknowledgement

When I got stuck, many in the comp.text.tex and xetex mailing list helped me. I want to particularly thank, Will Robertson, who is the author of the fontspec and unicode-math packages.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: