# replicate beamer math font settings

I'm wondering how to replicate beamer math font settings for a non-beamer document class? there was similar question answered, but that solution is not as good as what beamer is actually doing with math fonts. you can see the difference with the two MWE below:

beamer MWE:

\documentclass{beamer}

\usepackage[no-math]{fontspec}
\setsansfont{Arial}
\begin{document}
\begin{frame}
\Huge
a e f 1 2 3 \\ $a e f 1 2 3$
\end{frame}
\end{document}


article MWE:

\documentclass{article}

\usepackage{sfmath}
\renewcommand{\familydefault}{\sfdefault}

\usepackage[no-math]{fontspec}
\setsansfont{Arial}
\begin{document}
\Huge\noindent
a e f 1 2 3 \\ $a e f 1 2 3$
\end{document}


so can I get same math typesetting from the two MWE?

beamer basically uses the normal text font for math. You could borrow the corresponding code from beamerbasefont.sty or, maybe easier, use the mathastext package to get a similar result:

% !TeX TS-program = xelatex

\documentclass{article}

%\usepackage{sfmath}
\renewcommand{\familydefault}{\sfdefault}

\usepackage[no-math]{fontspec}
\setsansfont{Arial}

\usepackage[italic]{mathastext}

\begin{document}
\Huge\noindent
a e f 1 2 3 \\ $a e f 1 2 3$
\end{document}


• mathastext doesn't change the font metrics (at least not for helvet), so you'd get suboptimal placements of accents like $hat{f}$. Sep 26 '18 at 20:14
• @Skillmon Yes, just like using beamer with xelatex. The OP did ask for the same output as beamer, not for good results :) Sep 26 '18 at 20:28
• I wrote a package to move the accent based on the height of the contents \mathaccentV is used on. This provides a suboptimal fix for the accent placement if amsmath and mathastext is loaded which is independent of the used engine. The package is not on CTAN though. If one is interested, it is hosted here: gitlass.de/jonathan/MRTbundle/src/branch/master/MRTsfacc it also needs gitlass.de/jonathan/MRTbundle/src/branch/master/MRTif to work. Sep 27 '18 at 8:26
• @Skillmon Can you write add an answer? I think this package would be interesting to see in action! Sep 27 '18 at 8:55
• done, see below :) Sep 27 '18 at 9:40

# The following is primarily not an answer, more an extended comment

As noted in the comments under @samcarter's answer, I wrote a package which does shift the accents placed with \mathaccentV (which is part of amsmath) based on the height of the contents it is used on. This does improve the placement of the accents for most cases. The patch is engine independent but there certainly are better approaches (e.g., what beamer does when used with its standard fonts and pdfTeX). Also the patch can be used with different fonts and the placement can be adjusted.

You'll need the package which is not published on CTAN, but hosted here: MRTsfacc. It also needs the package MRTif. Documentation for both packages is available in this PDF. The packages are part of my MRTbundle which I wrote as a template for the institute where I wrote my bachelor's thesis.

The following is a comparison which is also included in the documentation of MRTsfacc (font in use is helvet with mathastext loaded with the options italic and defaultmathsizes; compiled with pdfTeX):

Usage with the two packages above installed (I don't have Arial, so I used DejaVu Sans; compiled with XeTeX):

\documentclass{article}

\usepackage[no-math]{fontspec}
\setsansfont{DejaVu Sans}

\usepackage[]{amsmath} % not necessarily needed, MRTsfacc loads amsmath with \RequirePackage

\renewcommand{\familydefault}{\sfdefault}
\usepackage{MRTsfacc}
% if the used shift isn't just right you can use the following to redefine the
% width
\MRTsfaccSet{.22} % default is .25
\usepackage[italic]{mathastext}

\newcount\foocount

\begin{document}
\Huge\noindent
a e f 1 2 3 \\ $\hat{a} e f 1 2 3$

% a loop creating every upper case letter in a \hat
\foocount65
\loop\ifnum\foocount<91
% using \hat* results in a \hat with the accent moved regardless of the
% argument, this is used as the test to see whether the argument is a letter
% does fail for \char\foocount
$\hat*{\char\foocount}$
\repeat

% a loop creating every lower case letter in a \hat
\foocount97
\loop\ifnum\foocount<123
$\hat*{\char\foocount}$

The package does only automatically apply the shift, if the argument to such macros using \mathaccentV internally is a letter (so has catcode 11). You can enforce the shift with a * after the macro, or disallow such shift with !, so \hat* always uses the shift, \hat! never does.