5

I would like to be able to add (or remove) a feature from a font shape.

I have read chapter III.3 of the fontspec package manual entitled Different features for different font shapes. So it is possible to use BoldFeatures, ItalicFeatures and so on, which solves my problem for these font shapes.

But what if I have defined custom font shapes? For example, I have created a semi-bold font; how can I define something like SemiboldFeatures or SemiboldItalicFeatures?

Looking for example at the definition of ItalicFeatures doesn't help much...

\@@_keys_define_code:nnn {fontspec-preparse} {ItalicFeatures}
  {
    \clist_put_right:Nn \l_@@_fontfeat_it_clist {#1}
  }

Example:

\documentclass{article}

\usepackage{fontspec}
\setmainfont{LibertinusSerif}[FontFace={sb}{n}{Font=*-Semibold}, FontFace={sb}{it}{Font=*-SemiboldItalic}]

\begin{document}
firefly \textit{firefly}\quad 
{\addfontfeatures{ItalicFeatures={Ligatures=CommonOff}} firefly \textit{firefly}}

firefly {\fontseries{sb}\fontshape{it}\selectfont firefly}\quad 
{\addfontfeatures{SemiboldItalicFeatures={Ligatures=CommonOff}} firefly {\fontseries{sb}\fontshape{it}\selectfont firefly}}
\end{document}

In fact, I need such a feature because I would like to apply kerning in some contexts that would be specific to the semi-bold variant of the font.

However, I suppose it would also be useful in other contexts and with other fonts such as Arial, which has many variants.

1 Answer 1

2
+25

I don't think that

\addfontfeatures{ItalicFeatures={Ligatures=CommonOff}

works.

Anyway, you can specify the features you want after stating the Font:

\documentclass{article}

\usepackage{fontspec}
\setmainfont{LibertinusSerif}[
  UprightFont=*-Regular,
  ItalicFont=*-Italic,
  BoldFont=*-Bold,
  BoldItalicFont=*-BoldItalic,
  FontFace={sb}{n}{Font=*-Semibold,Ligatures=CommonOff},
  FontFace={sb}{it}{Font=*-SemiboldItalic,Ligatures=CommonOff},
]

\begin{document}

With ligatures

firefly \textit{firefly}

Without ligatures

{\addfontfeatures{Ligatures=CommonOff} firefly \textit{firefly}}

Without ligatures

{\fontseries{sb}\fontshape{n}\selectfont firefly}

{\fontseries{sb}\fontshape{it}\selectfont firefly}

\end{document}

enter image description here

2
  • \addfontfeatures{ItalicFeatures={Ligatures=CommonOff} is missing a }, but otherwise it does work (as can be seen by the example in the question). I think the question was specifically about a way to do this at \addfontfeature time and not while declaring the font. Sep 28, 2021 at 23:39
  • @egreg thank you for your answer. As @Marcel Krüger says, I would like to be able to do this within a \addfontfeature command, as the kerning would not be effective all the time but just in certain contexts where I would then call \addfontfeature{SemiboldItalicFeatures={...}}. But after doing some research on the subject, I really don't know how to create a key like SemiboldItalicFeatures.
    – Bastien
    Sep 29, 2021 at 6:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .