Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Please consider the following MWE:

\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).

Figure 1: With <code>unicode-math</code> loaded. Figure 2: Without <code>unicode-math</code>.

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}
        \begin{equation}
            x = \int\limits_0^\infty f(q) \,\mathrm{d} q
        \end{equation}
    \end{frame}
\end{document}
share|improve this question
1  

1 Answer 1

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}

output

share|improve this answer
    
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 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. –  Herbert Apr 30 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 at 18:00
    
\setmathfont{latinmodern-math.otf} for the default setting, which is like Computer Modern Math –  Herbert Apr 30 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 at 18:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.