Character spacing in math mode in metropolis theme

beamerbeamer-metropolismath-modespacing

I'm having trouble with the way the characters are spaced in the Metropolis Beamer theme, while using the serif font for math mode. Here's a MWE:

\documentclass[10pt]{beamer}


\usetheme[progressbar = frametitle,
block = fill,
background = light
]{metropolis}



\usepackage{appendixnumberbeamer}

\usepackage{booktabs}
\usepackage[scale=2]{ccicons}

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}

\usepackage{xspace}
\newcommand{\themename}{\textbf{\textsc{metropolis}}\xspace}


\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{tikz-cd}
\usepackage{tikz}
\usepackage{bm}
\usepackage{mathbbol}
\usepackage{caption}
\usepackage{bbm}
\usepackage{graphicx}
\usepackage{scalerel}
\usepackage{accents}
\usepackage{soul}
\usepackage{mathtools}
\usepackage{dirtytalk}
\usepackage{shuffle}
\usepackage{tensor}
\DeclareSymbolFontAlphabet{\mathbb}{AMSb}
\DeclareSymbolFontAlphabet{\mathbbl}{bbold}
\usepackage[utf8]{inputenc}
\usefonttheme[onlymath]{serif}

\begin{document}
    \begin{frame}
        \[
        \mathbb E[Y]
        \]
    \end{frame}
\end{document}

I've compiled this with XeTeX, MacTeX distribution (I had to install the fira sans font system-wide to get the theme to work). As you can see, the character spacing is way off:
enter image description here This seems to happen with some characters and not others, but is pervasive throughout the document, and looks quite bad.

I would be grateful for any advice for how to fix this without changing the theme or font. Perhaps there is some way of requiring the math font switch within the .sty file, in a way that results in the spacing being correct. Thank you.

Best Answer

If I ask for \showoutput, I get

......\hbox(7.5+2.5)x19.65225, shifted 143.81882, display
.......\U/msb/m/n/10 E
.......\OT1/cmr/m/n/10 [
.......\TU/lmr/m/it/10 glyph#117
.......\OT1/cmr/m/n/10 ]

and this is the cause: there is no kerning between characters in different fonts. With your setup.

If I also load \usefonttheme{professionalfonts}, the tracing becomes

......\hbox(7.5+2.5)x20.25005, shifted 143.51991, display
.......\U/msb/m/n/10 E
.......\OT1/cmr/m/n/10 [
.......\OML/cmm/m/it/10 Y
.......\kern2.22223
.......\OT1/cmr/m/n/10 ]

and the kern is present.

enter image description here