Math and Text Font Size Not the Same

fontsfontsizeluatexmath-fonts

This is a follow-up question to Switching from PDFLaTeX to LuaLaTeX. Using user187802's answer, I have the following setup:

\documentclass{article}

\usepackage{fontspec}
\setmainfont[
  Extension      = .otf,
  UprightFont    = *-regular,
  BoldFont       = *-bold,
  ItalicFont     = *-italic,
  BoldItalicFont = *-bolditalic,
  Ligatures      = {
    TeX,
    CommonOff
  }
]{NewCM10}

\usepackage[
  math-style   = TeX,
  warnings-off = {
    mathtools-colon
  }
]{unicode-math}
\setmathfont{NewCMMath-Regular.otf}
\setmathfont[
  version  = bold,
  FakeBold = 2
]{NewCMMath-Regular.otf}

\usepackage{polyglossia}
\setdefaultlanguage{danish}

\begin{document}

Test.\footnote{`12345' versus `$12345$'}

\end{document}

footnote

As can be seen in the output, neither the font size nor the font boldness in text mode and math mode are the same. (It doesn't just occur in footnotes but elsewhere the difference is more subtle.)

How can I get the exact same font size and font boldness for text mode and math mode when using the NewCM10 font?

Best Answer

Apparently, digits scale differently in NewCM-Math.

You can assign the text font to the digits.

\documentclass{article}

\usepackage{polyglossia}
\usepackage{fontspec}
\setmainfont[
  Extension      = .otf,
  UprightFont    = *-Regular,
  BoldFont       = *-Bold,
  ItalicFont     = *-Italic,
  BoldItalicFont = *-BoldItalic,
  Ligatures = {
    TeX,
    CommonOff
  },
  NFSSFamily=ncm,
]{NewCM10}

\usepackage[
  math-style = TeX,
  warnings-off = {
    mathtools-colon
  }
]{unicode-math}
\setmathfont{NewCMMath-Regular.otf}
\setmathfont[
  version = bold,
  FakeBold = 4,
]{NewCMMath-Regular.otf}

\setdefaultlanguage{danish}

% fix digits
\DeclareSymbolFont{textdigits}{TU}{ncm}{m}{n}
\SetSymbolFont{textdigits}{bold}{TU}{ncm}{b}{n}

\Umathcode`0="7 \symtextdigits `0
\Umathcode`1="7 \symtextdigits `1
\Umathcode`2="7 \symtextdigits `2
\Umathcode`3="7 \symtextdigits `3
\Umathcode`4="7 \symtextdigits `4
\Umathcode`5="7 \symtextdigits `5
\Umathcode`6="7 \symtextdigits `6
\Umathcode`7="7 \symtextdigits `7
\Umathcode`8="7 \symtextdigits `8
\Umathcode`9="7 \symtextdigits `9

\newcommand{\test}{%
  12345 versus $12345$\par
  \sbox0{12345}\the\wd0\ versus \sbox0{$12345$}\the\wd0\par
}


\begin{document}

\test {\bfseries\boldmath\test}

\bigskip

{\footnotesize\test {\bfseries\boldmath\test}}

$a+b=c$

{\boldmath$a+b=c$}

\end{document}

enter image description here

Without the \Umathcode lines, the output is

enter image description here