# fontspec + amsmath - problem with kerning in math-mode

I have a file that loads a Times-like font and then a package that use the font in math-mode. Everything works fine under pdflatex including proper kerning of \operatorname{}

% To be processed with pdflatex
\documentclass{report}

\usepackage{mathptmx}
\usepackage{amsmath}
\usepackage[lite]{mtpro2}

\begin{document}
$\operatorname{Diff}^r \quad \mathrm{f}^r \quad {f}^r \quad \mathcal{C}^r$
\end{document}


but when I try the same set-up under xelatex with a file like:

% To be processed with xe-lua-latex:
\documentclass{report}

%\usepackage[no-math]{fontspec}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Times New Roman}
\usepackage{amsmath}
\usepackage{mtpro2}

\begin{document}
$\operatorname{Diff}^r \quad \mathrm{f}^r \quad {f}^r \quad \mathcal{C}^r$
\end{document}


the kerning of what is inside \operatorname{} and \mathrm{} are lost, even when other kernings are fine.

I would like to understand the reasons for \mathrm{} messing things up.

Your pdflatex example doesn't compile without errors for me - it is imho not a good idea to load both mathptmx and mtpro2.

But beside this:

• there is no kerning involved: the chars are from different fonts.
• You only need to compare the pdflatex times font and Times New Roman to understand why e.g. the f spacing is different:
\documentclass{report}
\usepackage{ifxetex}
\ifxetex
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Times New Roman}
\else
\usepackage{mathptmx}
\fi

\begin{document}
\fboxsep0pt
\fbox{f}

\end{document}


You could try TeX Gyre Termes instead of Times New Roman, its f doesn't stick out of the bounding box so much:

• I edit the code slightly so it now runs on TL.... but I am curious on why you say it is not a good idea to load mathptmax and mtpro2 together. Is it on aesthetic grounds or technical ones? MTPro2 needs a Times-like font and mathptmx looked like a good option. TeX Gyre Termes looks good, but it is not acceptable because it does not have Cyrillic characters. Feb 28 '19 at 1:30
• mathptmx as the name indicates changes also math. You should change only the text font. Feb 28 '19 at 7:26