6

I'm trying to detect the presence of certain font Open Type font features with fontspec but it fails as soon as a main language is specified with babel.

I have two questions:

  1. Am I missing something?
  2. Is this actually a big deal? Can I safely apply Kerning=Uppercase even if a font doesn't support it without any weird side effects?

MWE

%! TeX Program = lualatex

\documentclass{article}
\usepackage{fontspec}
%\usepackage{babel} % works
\usepackage[american]{babel} % doesn't work
\babelfont{rm}{Baskervaldx}

\begin{document}
\ExplSyntaxOn
\fontspec_if_feature:nTF {cpsp}
  {Feature ~ detected! \addfontfeature{Kerning = Uppercase}}
  {Feature ~ NOT ~ detected.}
\ExplSyntaxOff

THIS SHOULD USE UPPERCASE KERNING
\end{document}
1
  • features can change if a language is set, try \babelfont{rm}[Language=Default]{Baskervaldx} Commented yesterday

1 Answer 1

4

It’s a bug in the Node rendered, not directly related to babel. It works as expected with the Harfbuzz renderer. If a language is requested and there are no specific features for it, there should be a fallback to the default language.

Sadly, the Harfbuzz renderer is somewhat buggy in hyphenated scripts, so the solution is to set explicitly the language to Default, as suggested by @UlrikeFischer, with:

\babelfont{rm}[Language=Default]{Baskervaldx}

Edit. However, note this is not a general solution. It may work in some cases, but if a fonts defines features for a mixture of languages, with several fallbacks, you are at a loss, because it might be impossible to select all of them for a certain language.

1
  • Thanks Javier, super helpful. What about my second question? Can I just bypass the test in this case and turn on uppercase kerning without side effects? This would simplify the logic for this particular feature. Commented yesterday

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.