6

Let's compile this file with LuaLaTeX (or XeLaTeX):

\documentclass{article}
\usepackage{fontspec}
%\setmainfont{Latin Modern Roman} % (or any other font)

\newfontfamily\myfont{texgyreheros}[
   Extension =      .otf,
   UprightFont =    *-regular,
   BoldFont =       *-bold,
   ItalicFont =     *-italic,
   BoldItalicFont = *-bolditalic,
   Ligatures=TeX
  ]

\begin{document}
\showoutput

\section{\myfont Bold and \textit{italic} \bfdefault}
AAA
\end{document}

The .log file says:

LaTeX Font Warning: Font shape `TU/texgyreheros(0)/bx/n' undefined
(Font)              using `TU/texgyreheros(0)/m/n' instead on input line 17.


 LaTeX Font Warning: Font shape `TU/texgyreheros(0)/bx/it' undefined
 (Font)              using `TU/texgyreheros(0)/bx/n' instead on input line 17.

and the PDF output is not correct (no bold, no bolditalic):

enter image description here

Two questions:

  1. LaTeX complains about a TU/texgyreheros(0)/bx/n missing font while \bfdefault is b, not bx in the section title, why?

    Please note that the same document compiles as expected with LaTeX <2019-10-01> patch level 3, \bfdefault being expanded as bx.

  2. When uncommenting the \setmainfont{...} line (with any font), the output is correct, \bfdefault expands again as b and no warning appears in the .log file. The section title is printed as expected in \TU/texgyreheros(0)/b/n/14.4.

Is a \setmainfont{...} statement necessary even if the output is to be printed with the default LMR fonts? I see that the .log file differs if an explicit \setmainfont{LaTin Modern Roman} is added: \TU/lmr/m/n/10 AAA versus \TU/LatinModernRoman(0)/m/n/10 AAA.

4
4

It is not really a bug but a behavior that could be improved on in one way or the other.

The point is, the document has LMR as it is document font with "bx" as the bold \rmfamily. So \section calls \bfseries and that makes the series attribute become "bx" (remember we are still in \rmfamilyat this point).

Now \myfont comes along and only changes the family name, thus requesting texgyreheros(0)/bx which hasn't been set up by fontspec. Thus normal NFSS substitution happens and you get texgyreheros(0)/n.

The reason why \setmainfont appears to work is because it changes the document font to a "b" font (in case of of Latin Modern Roman actually incorrectly).

Here is an example for pdftex that shows the different behaviors and causes:

\documentclass{article}

\DeclareFontFamily{OT1}{ptm}{}
\DeclareFontShape{OT1}{ptm}{m}{n}{<-> ptmr7t}{}
\DeclareFontShape{OT1}{ptm}{m}{sc}{<-> ptmrc7t}{}
\DeclareFontShape{OT1}{ptm}{m}{sl}{<-> ptmro7t}{}
\DeclareFontShape{OT1}{ptm}{m}{it}{<-> ptmri7t}{}
\DeclareFontShape{OT1}{ptm}{b}{n}{<-> ptmb7t}{}
\DeclareFontShape{OT1}{ptm}{b}{sc}{<-> ptmbc7t}{}
\DeclareFontShape{OT1}{ptm}{b}{sl}{<-> ptmbo7t}{}
\DeclareFontShape{OT1}{ptm}{b}{it}{ <-> ptmbi7t}{}

\def\test{0}      % ok
\def\test{1}      % ????
\def\test{2}      % ok - typical pdftex case

\ifcase \test\relax
  \renewcommand\rmdefault{ptm}
\or  % 1
\or  % 2
  \DeclareFontShape{OT1}{ptm}{bx}{n}{<->ssub * ptm/b/n}{}
\fi

\showoutput

\begin{document}

\sffamily     Text ``cmss/m/n''

\bfseries     Text ``cmss/bx/n''

\ifcase \test\relax
  \rmfamily
\else
  \fontfamily{ptm}\selectfont
\fi

Text ``ptm/bx/n'' changed to ``ptm/b/n''?


\bigskip \mdseries

Summary: \LaTeX\ understands about fonts with different ``boldness'' if they
are assigned to the metafamilies ``rm'' ``sf'' or ``tt''.

However, if you change to an arbitrary family then the current
``boldness'' remains (e.g., bx) and it depends on the family setup
having a substitution rule for ``bx'' to ``b'' (which nearly all fonts
for pdfTeX have) to work.

\end{document}

Thus short term, one solution would be that fontspec adds the necessary substitution rules, e.g. in this case

\DeclareFontShape{TU}{texgyreheros(0)}{bx}{n}{<->ssub * texgyreheros(0)/b/n}{}
\DeclareFontShape{TU}{texgyreheros(0)}{bx}{it}{<->ssub * texgyreheros(0)/b/it}{}

Midterm NFSS should probably more generally support different "boldness" per family. I have opened an issue for that on our tracker: https://github.com/latex3/latex2e/issues/275

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.