latex3 / fontspec

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

\addfontfeature relaxes font faces when NFSSfamily was used #417

Open mrpiggi opened 4 years ago

mrpiggi commented 4 years ago

Description

When a font family is defined with NFSSfamily and several FontFace, using \addfontfeature relaxes all defined font shapes except that one currently used.

I came across this because of an error with package microtype due to this behavior. The package stores all used font shapes in \MT@font@list by hooking into \pickup@font but can not execute a specific \font@name as it is undefined after using \addfontfeature.

Check/indicate

Minimal example demonstrating the issue

\documentclass{article}
\usepackage{fontspec}

\usepackage{microtype}
\newcommand*\printMTlist{microtype not loaded\par}
\makeatletter
\@ifpackageloaded{microtype}{%
  \renewcommand*\printMTlist{
    \begingroup
      \string\MT@font@list:\par\smallskip
      \@for\@tempa:={\MT@font@list}\do{%
        \detokenize\expandafter{\@tempa}\par
      }%
    \endgroup
  }
}{}
\makeatother

\newif\ifnfss
% TODO toggle me :)
\nfsstrue

\ifnfss
\def\testfamily{nfsstest}
\else
\def\testfamily{LinLibertine(0)}
\fi
\newcommand*\usetestfont[3]{%
  {\usefont{TU}{\testfamily}{#1}{#2}TU/\testfamily/#1/#2 (#3)}\par%
}
\setmainfont[%
  \ifnfss NFSSFamily=\testfamily,\fi
  Extension      = .otf,
  UprightFont    = *_R,
  ItalicFont     = *_RI,
  BoldFont       = *_RB, 
  BoldItalicFont = *_RBI,
  FontFace={m}{n}{*_R},%
  FontFace={m}{it}{*_RI},%
  FontFace={sb}{n}{*_RZ},%
  FontFace={sb}{it}{*_RZI},%
  FontFace={b}{n}{*_RB},%
  FontFace={b}{it}{*_RBI},%
]{LinLibertine}

\begin{document}
\usefont{TU}{\testfamily}{sb}{n}
\makeatletter
\meaning\font@name\bigskip
\makeatother

\usetestfont{m}{n}{Regular}
\usetestfont{sb}{n}{Semi-Bold}
\usetestfont{b}{n}{Bold}
\bigskip

\expandafter\meaning\csname TU/\testfamily/m/n/10\endcsname\par
\expandafter\meaning\csname TU/\testfamily/sb/n/10\endcsname\par
\expandafter\meaning\csname TU/\testfamily/b/n/10\endcsname\par
\bigskip

%\oldstylenums{0123456789}
\addfontfeature{Color=0000FF99}

\printMTlist\bigskip

\expandafter\meaning\csname TU/\testfamily/m/n/10\endcsname\par
\expandafter\meaning\csname TU/\testfamily/sb/n/10\endcsname\par
\expandafter\meaning\csname TU/\testfamily/b/n/10\endcsname\par
\end{document}

Further details

 *File List*
 article.cls    2019/12/20 v1.4l Standard LaTeX document class
  size10.clo    2019/12/20 v1.4l Standard LaTeX file (size option)
fontspec.sty    2020/02/21 v2.7i Font selection for XeLaTeX and LuaLaTeX
  xparse.sty    2020-02-25 L3 Experimental document command parser
   expl3.sty    2020-02-25 L3 programming layer (loader) 
l3backend-pdfmode.def    2020-02-23 L3 backend support: PDF mode
fontspec-luatex.sty    2020/02/21 v2.7i Font selection for XeLaTeX and LuaLaTeX
 fontenc.sty
fontspec.cfg
microtype.sty    2019/11/18 v2.7d Micro-typographical refinements (RS)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
microtype-luatex.def    2019/11/18 v2.7d Definitions specific to luatex (RS)
microtype.cfg    2019/11/18 v2.7d microtype main configuration file (RS)
  ts1cmr.fd    2019/12/16 v2.5j Standard LaTeX font definitions
 ***********