[XeTeX] Change Math font

Bruno Voisin bvoisin at mac.com
Sat Mar 15 12:10:07 CET 2008


Le 15 mars 08 à 11:20, Sven Siegmund a écrit :

> I would like to change the font used for maths. I thought this would
> be done with the \setmathrm command. But It seems that \setmathrm has
> no effect on my document.

Yes. What \setmathrm does is changing the font used for explicit  
\mathrm comands, as in \mathrm{x}. It does not affect the fonts used  
implicitly in maths for operators (like "sin"), letters (like "x") and  
symbols (like \alpha).

In standard LateX, these are defined in fontmath.ltx, one of the files  
read when building the LaTeX format. On your setup it should be at  
something like:

D:\MiKTeX\tex\latex\base\fontmath.ltx

If I'm not mistaken, the default [math] option (and its opposite [no- 
math]) of fontspec affects the font used for operators but not those  
used for letters.

Specifically, to achieve what you want you must add to the preamble of  
your document:

\SetSymbolFont{letters}{normal}{\encodingdefault}{\rmdefault}{m}{it}
\SetSymbolFont{letters}{bold}{\encodingdefault}{\rmdefault}{b}{it}

Beware though: by doing this, you're in for future trouble, since the  
fonts used for letters in maths are not exactly the same as those used  
for text: they are expected to have different characters at different  
places.

> I can outquote it and it gets typeset the
> same:
>
> ---------
> \documentclass[a4paper,oneside]{article}
>
> \usepackage{xunicode} %handle unicode
> \usepackage{xltxtra} %XeTeX extras
> \usepackage{fontspec} %use OTF/TTF fonts
> \usepackage[ngerman]{babel} %german hyphenation
>
> \setmainfont{Adobe Garamond Pro} %use this font
> \setmathrm{Adobe Garamond Pro} %use this font for math
>
> \begin{document}
>
> $\sin{x}$
>
> sin {\textit x}
>
> $\sqrt{\sin{x}^2}$
>
> \end{document}
> ---------
>
> The argument of \sin is not set in Adobe Garamond Pro and how can I  
> change that?
> What causes the \setmathrm command?
>
> I tried to fiddle with the [no-math] option described for fontspec
> package 1.14, but when I change the respective line in the preamble to
> \usepackage[no-math]{fontspec}, I get this error when compiling
> (MiKTeX, Windows XP):

That's because xltxtra loads already the fontspec package, hence you  
can't reload afterwards the fontspec package with options different  
from those used when it was loaded the first time. Just invert the  
order in which the packages are loaded:

\usepackage{xunicode} %handle unicode

\usepackage{fontspec} %use OTF/TTF fonts
\usepackage{xltxtra} %XeTeX extras

Hope this helps,

Bruno Voisin


More information about the XeTeX mailing list