[Tex/LaTex] How to set lining numbers in math in Beamer (with EB Garamond) under XeLaTeX

beamerfontspecmath-modeoldstylenumsxetex

I'm using EB Garamond with XeLaTeX and Beamer as follows. (I'm not actually sure whether it's all necessary–advice accepted.):

\usepackage[T1]{fontenc}  % not sure why
\usepackage[urw-garamond]{mathdesign} % use URW Garamond rather than Computer Modern in math when EB Garamond is missing a character
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text} % not sure why
\setromanfont[Mapping=tex-text]{EB Garamond}

(I previously loaded EB Garamond as a system font on a Mac using its Font book app.)

EB Garamond uses oldstyle numbers by default. I can easily change to lining numbers in regular text by various means, e.g. by inserting this at the top of the document: \addfontfeatures{Numbers=Lining}. However, none of the methods I've tried has any effect on math in $$, \[\], etc.; the oldstyle numbers remain. This is a Beamer issue–the problem doesn't occur with the article class.

How can I switch to lining numbers in math mode (without resorting to \mbox)? A full minimal working example is below.

Thanks!

\documentclass[12pt]{beamer}

\usepackage[T1]{fontenc}
\usepackage[urw-garamond]{mathdesign}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{EB Garamond}

\usefonttheme{serif}

\begin{document}
\begin{frame}
text (default, oldstyle): 1234567890\\
\addfontfeatures{Numbers=Lining}
text (lining): 1234567890\\
math (why is this oldstyle?): $1234567890$
\end{frame}

\end{document}

Best Answer

I found a solution. It's easy, it's obvious, and though it's not a complete solution, it's good enough for me. The solution is to moveNumbers=Lining from \addfontfeatures to defaultfontfeatures, like this:

\defaultfontfeatures{Mapping=tex-text, Numbers=Lining}

By making lining numbers the default, they penetrate into math mode. (I should have tried that first, but I didn't fully understand what I had in my preamble--I just knew that it worked, apart from the oldstyle/lining problem.)

This isn't a complete solution because it affects math mode throughout the document. I still don't know how to switch back and forth between lining and oldstyle numbers in math mode. Adding additional calls to \addfontfeature or \defaultfontfeature in the document have no effect on math mode. However, using lining numbers everywhere is what I wanted, anyway.

Related Question