My problem arises from trying to work around the issue described in question 26276: I want to use SizeFeatures to explicitly select another family for small sizes, but this causes bold / italic / etc. to stop working in small sizes. My solution was to redefine \bfseries
and \itshape
to actually use a new font face for each variant, but this workaround is applied no matter what family is actually in use ... which causes problems if I want to use more than one (real) font family in my document.
Question. How do I reliably test what the current font family is, so that my code can decide whether to apply the workaround or not?
Here some sample code:
\documentclass[12pt,a4paper]{article}
\usepackage{fontspec}
\usepackage{etoolbox}
\setmainfont[%
SizeFeatures={%
{Size=-10, Font={Georgia}}, %
{Size=10-}%
}]{Times}
\newfontface\boldface[%
SizeFeatures={%
{Size=-10, Font={Georgia Bold}}, %
{Size=10-}%
}]{Times Bold}
\newfontface\italicface[%
SizeFeatures={%
{Size=-10, Font={Georgia Italic}}, %
{Size=10-}%
}]{Times Italic}
\newfontface\bolditalicface[%
SizeFeatures={%
{Size=-10, Font={Georgia Bold Italic}}, %
{Size=10-}%
}]{Times Bold Italic}
\setsansfont{Helvetica}
\DeclareTextFontCommand{\textbfit}{\bfseries\itshape}
\ExplSyntaxOn
\makeatletter
\let\int@bfseries\bfseries
\let\int@itshape\itshape
\renewcommand{\bfseries}{\str_if_eq_x:nnTF \f@shape \itdefault
{\bolditalicface \int@bfseries\int@itshape}
{\boldface \int@bfseries}
}
\renewcommand{\itshape}{\str_if_eq_x:nnTF \f@series \bfdefault
{\bolditalicface \int@bfseries\int@itshape}
{\italicface \int@itshape}
}
\makeatother
\ExplSyntaxOff
\begin{document}
\noindent
{\normalfont Roman: Normal \textit{Italic} \textbf{Bold} \textbfit{Bold Italic} \textit{\bfseries Italic Bold}} \newline
{\scriptsize Roman: Normal \textit{Italic} \textbf{Bold} \textbfit{Bold Italic} \textit{\bfseries Italic Bold}} \newline
{\sffamily Sans: Normal \textit{Italic} \textbf{Bold} \textbfit{Bold Italic} \textit{\bfseries Italic Bold}} \newline
{\sffamily\scriptsize Sans: Normal \textit{Italic} \textbf{Bold} \textbfit{Bold Italic} \textit{\bfseries Italic Bold}} \newline
\end{document}