latex3 / fontspec

Font selection in LaTeX for XeTeX and LuaTeX
http://latex3.github.io/fontspec/
LaTeX Project Public License v1.3c
277 stars 34 forks source link

Problem with default `bx` series: Name and font substitution #360

Open RuixiZhang42 opened 5 years ago

RuixiZhang42 commented 5 years ago

Description

The mtpro2 math package (and also the newtxmath math package, etc.) assumes that text font has a b series. Most traditional text font packages either provide the b series or make sure that font substitutions from b to bx and vice versa happen. This is not the case with fontspec.

Check/indicate

Minimal example demonstrating the issue

\documentclass{article}
\usepackage{fontspec}
\setmainfont{texgyretermes}[
  Extension=.otf,
  UprightFont=*-regular,
  ItalicFont=*-italic,
  BoldFont=*-bold,
  BoldItalicFont=*-bolditalic,
]
\usepackage[lite]{mtpro2}
%%% or
%\usepackage{newtxmath}
\begin{document}
\verb|      \mathnormal|: $012abc$\par
\verb|          \mathit|: $\mathit{012abc}$\par
\verb|          \mathbf|: $\mathbf{012abc}$\par
\verb|\boldmath+\mathit|: \boldmath$\mathit{012abc}$
\end{document}

a

Further details

One of the default font series set by fontspec is bx.

RuixiZhang42 commented 5 years ago

Take t1ntxtlf.fd from the newtx collection for example, we find the following declarations:

\DeclareFontFamily{T1}{ntxtlf}{\ntx@spacing}
\DeclareFontShape{T1}{ntxtlf}{b}{sc}{<-> \ntx@scaled ntx-Bold-tlf-sc\ntx@lsfx-t1}{}
\DeclareFontShape{T1}{ntxtlf}{b}{n}{<-> \ntx@scaled ntx-Bold-tlf-t1}{}
...
\DeclareFontShape{T1}{ntxtlf}{bx}{sc}{<->ssub * ntxtlf/b/sc}{}
\DeclareFontShape{T1}{ntxtlf}{bx}{n}{<->ssub * ntxtlf/b/n}{}
...

i.e., newtxtext naturally only has bold. For compatibility reason, e.g., in case other packages do, say, \SetSymbolFont{operators}{bold}{\encodingdefault}{\rmdefault}{bx}{n}, then it will fall back from the non-existing bold extended to bold.

RuixiZhang42 commented 5 years ago

A different point of view, as mentioned in your comment here, is to move the following code block:

  \DeclareSymbolFont{operators}\g_fontspec_encoding_tl\g_@@_mathrm_tl\mddefault\updefault
  \SetSymbolFont{operators}{normal}\g_fontspec_encoding_tl\g_@@_mathrm_tl\mddefault\updefault
  ...

to follow

  \bool_if:NT \g_@@_math_bool
   {
    \@@_info:n {setup-math}
    \fontspec_setup_maths:
   }
  % Add block here:

Thus, the \mathXX declarations are always executed regardless of the no-math option.

BTW, in the true branch of \tl_if_empty:NTF \g_@@_bfmathrm_tl, I think it is still necessary to set up

    \SetMathAlphabet\mathrm{bold}\g_fontspec_encoding_tl\g_@@_mathrm_tl\bfdefault\updefault % This line may be redundant
    \SetMathAlphabet\mathbf{bold}\g_fontspec_encoding_tl\g_@@_mathrm_tl\bfdefault\updefault

and in the false branch, the \mddefault choice is… debatable…

RuixiZhang42 commented 5 years ago

It appears that only a few number of fonts (e.g., Computer Modern) provides the bx series.

An excerpt from the documentation: https://github.com/wspr/fontspec/blob/c1fdf6d52c75017656c4d99ca5b4711353da125d/fontspec-doc-fontsel.tex#L486-L487

RuixiZhang42 commented 4 years ago

@wspr Just noticed a large scale of bx -> b changes in the test files in https://github.com/wspr/fontspec/commit/74c6917a13faa3aef57a68820ebaa222d51e4b42 and https://github.com/wspr/fontspec/commit/1b3596ce63db3ed73592144ffec5e42d17000c59 and https://github.com/wspr/fontspec/commit/19fa825a56c144ad478cc9f42bf2c0ff80e7fd4e. Are these changes coming from the LaTeX2e kernel? I cannot find the code change in fontspec

wspr commented 4 years ago

@RuixiZhang42 — yes, that's right, the new default in LaTeX2e will be b. Sorry for my silence on this issue... I will be adding bx↔︎b substitution some time soon...