[XeTeX] fontspec and sans-serif math fonts

Stefan Solbrig stefan.solbrig at gmail.com
Tue Jun 26 23:59:00 CEST 2007


> > I noticed that when using beamer in its standard font configuration,
> > it would switch the math fonts to a sans-serif version (cmss).
>
> Really? That's a bit weird :) I haven't used beamer too much... I've
> just started on it for a presentation I have to give in a couple of
> weeks and it's real nice.

Yes, that's the default behavior in beamer.
If you don't like it, you can use the font theme "serif" and
pass "onlymath". Then beamer will use serif fonts in
formulae and sans fonts elsewhere:

\documentclass[onlymath]{beamer}
\usefonttheme{serif}

> > When
> > using fontspec, though, they would always be reverted to the standard
> > CM math font. Generally I found it a bit difficult to predict what
> > fontspec would do to my maths font, i.e., when loading the 'euler'
> > package, fontspec would change some of the math fonts back to CM,
> > unless I used the 'cm-default' switch.
>
> This was probably caused by the inclusion of maths in the Latin
> Modern fonts in the latest TeXLive. This took me by surprise, and
> fontspec had no idea -- this should be fixed now.
>
> > To get around the sans/con serif problem, I patched fontspec a bit to
> > include a 'sans' option, which makes it choose the cmss math fonts
> > instead. That's a bit crude, though, and I'm wondering if I
> > overlooked anything obvious there.
>
> The latest version of fontspec has a [no-math] option to not mess
> around with those things. Depending exactly what beamer does, that
> may or may not solve your problem satisfactorily...
>
> Hope this helps,
> Will

I'm not sure if I fully understand that issue.
Do you want to use sans fonts in math or would you prefer
to have serif fonts in math with beamer?
I think the problem with the math fonts is the following:
the default behavior of the beamer package is to set the
fonts for letters and operators in formulae to the default font
of the normal text.

Example:
\documentclass[dvipdfm,onlymath]{beamer}
%\usefonttheme{professionalfonts}
\usepackage[lm-default]{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{amsmath}
\setmainfont{Handwriting - Dakota}
\setsansfont{Handwriting - Dakota}
\begin{document}
\begin{gather}
f(x)\to C'x+\sin(x)
\end{gather}
\fontspec{Handwriting - Dakota}
Some font!
\end{document}

The above example uses "Handwriting - Dakota"
for letters and operators inside the formula.
That's the default behavior of beamer.
If you want "lmr" for letters and operators,
uncomment the second line.

Beamer then doesn't touch the math fonts, and you
can use other packages e.g., euler, to set the math fonts.

It is also necessary to use the "professionalfonts" theme
if you use  \usepackage[lm-default]{fontspec}:
consider this minimal example:

\documentclass[dvipdfm,onlymath]{beamer}
%\usefonttheme{professionalfonts}
\usepackage[lm-default]{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{amsmath}
\begin{document}
\begin{gather}
f(x)\to C'x+\sin(x)
\end{gather}
\fontspec{Handwriting - Dakota}
Woo! What a font.
\end{document}

In this case, beamer tries to match the default font of
the normal text with the font inside formulae, and somehow
the italics correction is lost.

However, if you comment back in the second line
\usefonttheme{professionalfonts}
everything works just fine.

To sum it up: If you prefer to set fonts yourself, even inside
a math enviroment, use \setfonttheme{professionalfonts}.
If you don't set a math font, the default is used. ( latin modern
if you load the lmodern package, cmr otherwise).
The "professionalfonts" theme just tells beamer not to
change any fonts, and leave it to the (professional) user.

best regards,
Stefan


More information about the XeTeX mailing list