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.
You have to do \setmathrm
; here I use TeX Gyre Termes, but what font you're using is irrelevant.
\documentclass[a4paper,12pt]{article}
\usepackage{mathspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{TeX Gyre Termes}
\setmathsfont(Digits){TeX Gyre Termes}
\setmathsfont(Latin){TeX Gyre Termes}
\setmathrm{TeX Gyre Termes}
\begin{document}
Some text digits 1, 2, 3 and some math digits $1, 2, 3$.
Some italic text \textit{text}, and some math text $text$.
Also $\sin x$ and $\arctan x$.
\end{document}
If you have a recent and updated TeX Live, you can also use the new TG Termes Math font with unicode-math
:
\documentclass[a4paper,12pt]{article}
\usepackage{unicode-math}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{TeX Gyre Termes}
\setmathfont{TG Termes Math}
\begin{document}
Some text digits 1, 2, 3 and some math digits $1, 2, 3$.
Some italic text \textit{text}, and some math text $text$.
Also $\sin x$ and $\arctan x$.
\end{document}
This is actually much better than mathspec
, because the math font has the right parameters for being used in formulas.
Best Answer
Font selection in math mode works differently from that in text mode. While in text mode you have a "current font", you don't necessarily have in math mode. In math mode TeX uses one of at most 16 font families, where each family has three variants
\textfont
,\scriptfont
and\scriptscriptfont
, used for the various positions characters can occur in in math formulas.When TeX sets a character in math mode, it first of all checks the math code associated with that character. You can check the math code e.g. for the letter
a
with\showthe\mathcode`a
. TeX will then printwhich in hexadecimal form is
7161
. The fist digit stands for the math class associated with the math character, the second digit for the font family and the third and fourth for the position of the character in the font table. So in this case, the letter fora
has the default font family 1.However, it's more complicated than just using this font family because the character also has class 7. Class 7 means that TeX first checks if the value of the font family register
\fam
is in the range 0-15. If so, TeX assumes the class to be 0 instead (an ordinary math character/symbol), and uses the font family\fam
instead for typesetting this character. If\fam
isn't in said range (as it is by default when math mode is started), TeX uses the associated font family for the letter, 1 in this case.Now that we know at which font family to look at, we can finally check the font names for each of the three family variants in math mode. If we put
in a simple LaTeX document, the output will look like
which are the standard Computer Modern italic math font variants.
The font families are only set in math mode, so if you need the value in text mode, use something like
and similarily for the script and scriptscript variants.
Edit: Here is a small macro
\printmathfont
that prints the fontname of the given math font variant (#1
) and a (possibly implicit) math character (#2
):The output looks like this: