6

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?

3
  • 1
    do you want to change math fonts at all? Nov 14, 2022 at 13:51
  • @DavidCarlisle Hmm ... Not really. Nov 14, 2022 at 14:05
  • 1
    By default, if you don't load uncode-math, you would get the same math fonts as pdflatex lmodern package, or you could re-instate the computer modern fonts. Nov 14, 2022 at 15:02

2 Answers 2

3

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

5
  • Nice! Is there a reason for loading \setmathfont[ version = bold, FakeBold = 2 ]{NewCMMath-Regular.otf} twice? Also, is the loading order of the packages of any importance? Nov 14, 2022 at 14:10
  • 1
    @SvendTveskæg No, leftover… Anyway, I find that FakeBold=4 is better.
    – egreg
    Nov 14, 2022 at 14:21
  • Thank you very much, Enrico! I was also wondering why the \ifffalse \if code was there but I see that it was not intended. :-) Nov 14, 2022 at 14:31
  • 1
    @SvendTveskæg I tried with loading fontsetup instead of directly choosing the fonts; there are some differences, because fontsetup selects optically scaled fonts to some extent; for instance, with \footnotesize NewCM08-* is used.
    – egreg
    Nov 14, 2022 at 14:49
  • "Apparently, digits scale differently in NewCM-Math." No it is not the font that does something strange here, it is LaTeX. Another thing: with this solution one will not get ssty variants in superscripts like $x^2$.
    – mickep
    Nov 16, 2022 at 6:58
6

The problem is that LaTeX's Unicode math sets the math Unicode font with ssty font feature by very specific way. It uses +ssty=0 for textstyle, +ssty=1 for script style etc. I used in OpTeX only ssty=0, ssty=1 etc., without the + sign. I am unable to find the documentation of the plus sign in this font feature (the https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt#ssty doesn't mention this) but I see that if it is used then the definitive variant of letters are selected not by the number specified for this feature, but by the size used for the font.

Compare:

LaTeX: [NewCMMath-Regular.otf]:mode=base;script=math;language=dflt;+ssty=0; at 8.0pt
OpTeX: [NewCMMath-Regular]:mode=base;script=math;ssty=0;mathsize=1; at 8.0pt

LaTeX selects script alternative shapes for the digits 1234 in loaded font, OpTeX selects basic shapes scaled to 8pt, which looks better in the footnote size. OpTeX selects script alternative shapes when ssty=1, i.e. only when scriptstyle in math mode is used.

11
  • ssty=0; is ignored by luaotfload, so you could also simply remove it. Nov 14, 2022 at 18:49
  • 1
    The question is why there is +ssty=0. If this is the same as ssty=1 why isn't here this explicit syntax. And why LaTeX needs the ssty=1 here in \textstyle math. It seems like puzzlement.
    – wipet
    Nov 14, 2022 at 19:20
  • 1
    @SvendTveskæg integrating this in latex is non trivial as latex assumes there is only one mapping of size to font features, not separate maps for textstyle and scriptstyle Nov 14, 2022 at 19:43
  • 2
    @SvendTveskæg One chance is to use something different than LaTeX:).
    – wipet
    Nov 14, 2022 at 19:45
  • 1
    @wipet latex is using ssty at small sizes independently of the context, so a 7pt superscript at 10pt base but also a 7pt \textstyle in 7pt footnotes. It has always done this but classcally the footnote text would be using cmr7 so also using wider glyphs so does not show the difference in the question. Nov 14, 2022 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .