# XeLaTeX/beamer/fontspec/unicode-math: Change font of all math digits

\documentclass{beamer}
\usepackage{unicode-math}
\usepackage{fontspec}
\setsansfont{some-font.otf}
\usefonttheme[onlymath]{serif}

\begin{document}
\begin{frame}
Some text with the number \textit{two} in text mode (2) and math mode ($2$).
\begin{equation*}
\vec{s}(t) = \frac{\vec{a}}{2} t^2 + \vec{v}_0 t + \vec{s}_0
\end{equation*}
\end{frame}
\end{document}


How to change the font of all math digits to the sans font defined with fontspec's \setsansfont command (font-independent)?

I tried to experiment with the \Umathcode XeTeX primitive as well as with \setmathfont provided by unicode-math, however, I had no success.

I am aware of the package mathspec and its \setmathfont(digits) command, but I realized that the combination of a beamer class document and fontspec/mathspec causes misplaced math elements (see figures 1 and 2 for a comparison; for figure 2, \usepackage{unicode-math} package has been commented out in the MWE).

Update:
This MWE compiles without any error in my setup. However, if the line \setmainfont{Arial} is commented out, an error will be thrown. The same is true if I specify a font as a file (*.ttf or *.otf) instead of a system-installed font.

\documentclass{beamer}
\usefonttheme{professionalfonts}
\usepackage{unicode-math}
\usepackage{fontspec}
\setmainfont{Arial}
\setmathfont[range={\mathup}]{Lucida Sans}

\begin{document}
\begin{frame}
$$x = \int\limits_0^\infty f(q) \,\mathrm{d} q$$
\end{frame}
\end{document}

• – Werner Apr 28 '14 at 17:17

Disable the font setting of beamer:

\documentclass{beamer}
\usefonttheme{professionalfonts}% use own font handling
\usepackage{unicode-math}
\setmainfont{Lucida Sans}
\setmathfont{XITS Math}
\setmathfont[range={\mathit}]{Lucida Sans Italic}
\setmathfont[range={\mathup}]{Lucida Sans}

\begin{document}
\begin{frame}
Some text with the number \textit{two} in text mode (2) and math mode ($2$).
\begin{equation*}
\vec{s}(t) = \frac{\vec{a}}{2} t^2 + \vec{v}_0 t + \vec{s}_0
\end{equation*}
\end{frame}
\end{document}


• Thanks for your answer. I think your solution is a first step in the right direction, however, I am missing three important things: (i) The math font should be the default LaTeX one and I don't know how to set this with \setmathfont. (ii) Only math digits shall be set to the main font defined with fontspec, without recalling the font name manually. (iii) Additionally, the equation seems misplaced (distance of elements), which I do not want. – DigNative Apr 30 '14 at 10:29
• If you didn't define a math font Computer Modern will be used. The range option can also be used for defining the sequence 0..9. – user2478 Apr 30 '14 at 17:25
• Not defining a main font does not work for me in some cases. Please try the MWE in the Update section of my original question. – DigNative Apr 30 '14 at 18:00
• \setmathfont{latinmodern-math.otf} for the default setting, which is like Computer Modern Math – user2478 Apr 30 '14 at 18:12
• When I use this setting, my document compiles. However, (i) using Latin Modern Math, despite it is quite similar to Computer Modern, causes misplaced limits for integrals with 8pt as beamer option, (ii) this solution still throws an error if I want to use font files instead of system-installed fonts. – DigNative Apr 30 '14 at 18:57