# how to select math font in document

I want to show in one document different font examples of math fonts, for example Latin Modern, Times and Charter.

I know the command \usefont{T1}{lmr}{m}{n}, but have no idea how to combine that with a math environment.

-
You would have to define math versions. But depending on the fonts involved this can be quite complex. Better make external graphics/documents and import them. – Ulrike Fischer Sep 30 '11 at 12:20

## 2 Answers

That's a bit complex in LaTeX. Note that the definitions of math symbols are complex. Math fonts are quite different with text fonts.

You may want to read the document of NFSS: LaTeX2𝜀 font selection, section 3; and the documented source code of LaTeX2e: The LaTeX 2𝜀 Sources, section 42.

For examples, any math font package is OK. I suggest mathptmx.sty, it is typical and relatively simple. e.g.

\DeclareSymbolFont{letters}{OML}{ztmcm}{m}{it}


This (re)defines the letter math family. And the command

\DeclareSymbolFontAlphabet{\mathnormal}{letters}


in LaTeX2e kernel makes letters family to be default alphabet font.

People usually don't use many font families in one document. For an example of mixed math fonts, see also my previous answer.

It is not only annoying, but also impossilbe to define many math fonts in one document. In TeX, the number of math alphabet fonts is limited to 16. As Ulrike Fischer said, if you just want to show the results of a few math font packages, just produce some graphics and import them into the document. It is much easier.

-

Remark: Since posting the initial version of this answer, back in Sept. 2011, (at least) two more unicode math fonts have joined the TeX/LaTeX scene: TeX Gyre Termes Math (to go with TeX Gyre Termes, a Times Roman clone) and Tex Gyre Pagella Math (to go with TeX Gyre Pagella, a Palatino clone). I've edited the example code below to include these two math fonts; the total of math fonts shown is now up to six [6].

As the other answers and comments have already pointed out, it's not easy in pdfLaTeX to switch from one math font group (say, Computer/Latin Modern) to another. The packages I'm familiar with which have matching text and math fonts are the default Computer/Latin Modern group (loaded if no other font group is specified), mathptmx (Times Roman look), and mathpazo (Palatino). There are also the txfonts and pxfonts packages, which give you Times and Palatino, but the hinting and glyph substitution isn't as good as with mathptmx and mathpazo. Within just the last few months, the newtxmath (and newtxtext) packages have come along; they correct virtually all of the shortcomings of the txfonts package and add quite a bit of new functionality as well. I'm not familiar with math fonts designed specifically to go with Charter text fonts.

See the web page A Survey of Free Math Fonts for TeX and LaTeX for a comparison of various free math fonts available for (pdf)LaTeX users.

Even though it's not straightforward (or even possible?!) to switch between entire math font families within the same document if you use pdfLaTeX, it's actually quite easy to do so in XeLaTeX and LuaLaTeX. The following MWE gives a demonstration of six different matched text and math fonts: Latin Modern, XITS/XITS Math, Palatino/Asana Math, and Cambria Math.

% !TeX program = lualatex
\documentclass{article}
\usepackage[vmargin=1in]{geometry}
\usepackage{xfrac,fontspec,unicode-math}

\setmathfont[version=lm]{Latin Modern Math}
\setmathfont[version=xits]{XITS Math}
\setmathfont[version=termes]{TeX Gyre Termes Math}
\setmathfont[version=asana]{Asana Math}
\setmathfont[version=pagella]{TeX Gyre Pagella Math}
\setmathfont[version=cambria]{Cambria Math}

\newcommand{\abc}{abcdefghijklmnopqrstuvwxyz}
\newcommand{\abctextrm}{Text roman: \abc}
\newcommand{\abctextit}{Text italic: \ \ \emph{\abc}}
\newcommand{\abcmathit}{Math italic: \ \ensuremath{\abc}}
\newcommand{\formulas}{%
\ensuremath{\displaystyle
\int_{0}^{1} x^{2}\,\mathrm{d}x = \sfrac{1}{3} \qquad
\sum_{k=0}^{\infty} \frac{1}{k^{2}} = \frac{\pi^{2}}{6}}}
\newcommand{\doall}{\abctextrm\\ \abctextit\\ \abcmathit\\ \medskip \formulas}
\begin{document}

\setmainfont{Latin Modern Roman}
\mathversion{lm}
\section*{Latin Modern}
\doall

\setmainfont{XITS}
\mathversion{xits}
\section*{XITS, XITS Math}
\doall

\setmainfont{TeX Gyre Termes}
\mathversion{termes}
\section*{Termes, Termes Math}
\doall

\setmainfont{Palatino nova}
\mathversion{asana}
\section*{Palatino nova, Asana Math}
\doall

\setmainfont{TeX Gyre Pagella}
\mathversion{pagella}
\section*{Pagella, Pagella Math}
\doall

\setmainfont{Cambria}
\mathversion{cambria}
\section*{Cambria, Cambria Math}
\doall

\end{document}

-
It's been already pointed out that unicode-math has the concept of \mathversion that's more efficient than stating \setmathfont anew. You may wish to update your answer after looking at page 8 of the documentation. – egreg Sep 30 '11 at 13:50
@egreg: Thanks for this suggestion. I've updated the code and provided an additional paragraph to highlight the use of this facility. – Mico Sep 30 '11 at 14:04
Now there are only a few opentype math fonts. Only 4 for free: Latin Modern Math, XITS Math, Asana Math, Neo Euler; 2 commercial: Cambria Math, Minion Pro; and some in development: Lucida Math, TeX Gyre(?). – Leo Liu Sep 30 '11 at 14:16
The concept of math versions is in LaTeX2e's NFSS, say, normal and bold. You can use \mathversion in pdfLaTeX. unicode-math inherits the concept and makes it easier to use. – Leo Liu Sep 30 '11 at 14:23
@LeoLiu -- thanks for this. I've inserted a sentence in the answer noting the relative paucity of OpenType-based math fonts, and I've also inserted a sentence linking to a survey of free math fonts for pdflatex users. About Cambria Math: It's not free, but seems to be standard on Windows distributions; it's not free for others, but since it costs only \$35 (for text and math fonts), it's a real bargain compared with the cost of the soon-to-be-released Minion Pro math font package. – Mico Sep 30 '11 at 14:29