Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

I just found out I can use xstring to test for string prefixes. This version of my workaround seems more robust:

\documentclass[12pt,a4paper]{article}
\usepackage{fontspec}
\usepackage{xstring}
\setmainfont[%
SizeFeatures={%
  {Size=-10, Font={Georgia}}, %
  {Size=10-}%
}]{Times}

\newfontfamily\boldface[%
BoldFont={Times Bold}, %
SizeFeatures={%
  {Size=-10, Font={Georgia Bold}}, %
  {Size=10-}%
}]{Times Bold}

\newfontfamily\italicface[%
ItalicFont={Times Italic}, %
SizeFeatures={%
  {Size=-10, Font={Georgia Italic}}, %
  {Size=10-}%
}]{Times Italic}

\newfontfamily\bolditalicface[%
BoldItalicFont={Times Bold Italic}, %
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
\let\int@upshape\upshape

\renewcommand{\bfseries}{\IfBeginWith{\f@family}{Times}
  {\str_if_eq_x:nnTF \f@shape \itdefault
    {\bolditalicface \int@bfseries\int@itshape}
    {\boldface \int@bfseries}
  }{\int@bfseries}
}
\renewcommand{\itshape}{\IfBeginWith{\f@family}{Times}
  {\str_if_eq_x:nnTF \f@series \bfdefault
    {\bolditalicface \int@bfseries\int@itshape}
    {\italicface \int@itshape}
  }{\int@itshape}
}
\renewcommand{\upshape}{\IfBeginWith{\f@family}{Times}
  {\str_if_eq_x:nnTF \f@series \bfdefault
    {\boldface \int@bfseries\int@upshape}
    {\normalfont \int@upshape}
  }{\int@itshape}
}

\let\emshape\itshape
\let\eminnershape\upshape
\makeatother
\ExplSyntaxOff

\begin{document}
\emph{Emphasis with \emph{inner emphasis and \emph{inner-inner emphasis}}, plus {\upshape upright}.}

{\scriptsize \emph{Emphasis with \emph{inner emphasis and \emph{inner-inner emphasis}}, plus {\upshape upright}.}}

\bigskip\noindent
{\normalfont Roman: Normal \textit{Italic} \textbf{Bold} \textbfit{Bold Italic} \textit{\bfseries Italic Bold}}

\noindent
{\scriptsize Roman: Normal \textit{Italic} \textbf{Bold} \textbfit{Bold Italic} \textit{\bfseries Italic Bold}}

\noindent
{\sffamily Sans: Normal \textit{Italic} \textbf{Bold} \textbfit{Bold Italic} \textit{\bfseries Italic Bold}}

\noindent
{\sffamily\scriptsize Sans: Normal \textit{Italic} \textbf{Bold} \textbfit{Bold Italic} \textit{\bfseries Italic Bold}}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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