1

I try to add some custom kerning to an OpenType font used with fontspec under lualatex. The real-world example uses the Brill fonts, but as they are not part of TeX Live I use Libertinus in the example below.

I want to add some kerning between specific characters with diacritics and superscript numbers. The only combination which works is the direct usage of the unicode superscript numbers. As soon as I use \textsuperscript, which is redefined by realscripts to use the correct figures, the extra kerning is not applied.

Is there any way to achieve what I want while using \textsuperscript?

% !TeX TS-program = lualatex
\documentclass{article}

\usepackage{fontspec}
% Values below are for demonstration purposes only
\directlua {
   fonts.handlers.otf.addfeature {
      name = "supkern",
      type = "kern",
      data = {
         ["ī"] = {
            ["¹"] = 500,%
            ["two.sups"] = 500,%
         },
         ["š"] = {%
            ["one.sups"] = 500,%
            ["two.sups"] = 500,%
         },
      },
   }
}
\usepackage[defaultfeatures={RawFeature={+supkern}}]{libertinus} %Brill in real life
\usepackage{realscripts}

\begin{document}
   ī\textsuperscript{12}
   
   ī¹
   
   ī{\addfontfeatures{VerticalPosition=Superior}2}
   
   {\addfontfeatures{RawFeature={+supkern}}ī\addfontfeatures{VerticalPosition=Superior}12}
   
   š\textsuperscript{2}
   
\end{document}

1 Answer 1

3

The realscripts code adds an \addfontfeature command. And this basically means that you have two different fonts. Something like this should work, but one should add some tests, so that is doesn't fail if a font doesn't have the superscripts. Look in the realscript code.

\documentclass{article}

\usepackage{fontspec}
% Values below are for demonstration purposes only
\directlua {
   fonts.handlers.otf.addfeature {
      name = "supkern",
      type = "kern",
      data = {
         ["ī"] = {
            ["¹"] = 500,%
            ["two.sups"] = 500,%
         },
         ["š"] = {%
            ["one.sups"] = 500,%
            ["two.sups"] = 500,%
         },
      },
   }
}
\usepackage[defaultfeatures={RawFeature={+sups,+supkern}}]{libertinus} %Brill in real life
\RenewDocumentCommand\textsuperscript{m}{#1}
\begin{document}
   ī\textsuperscript{12}

ī¹ 
\end{document}
3
  • Thank you Ulrike for the explanation. I looked at the realscripts code, but thought, that adding the feature VerticalPosition=Superior wouldn't create a new font internally.
    – Martin
    Sep 10, 2020 at 13:55
  • As far as I can see, one.sups and the other .sups have to be replaced with the Unicode glyphs in the definition of the new feature.
    – Martin
    Sep 10, 2020 at 13:57
  • In my real-world problem I do of course have normal numbers as well, not only superscript numbers. So setting the sups feature globally is not what I want. Moreover if I want to use the old definition of \textsuperscript as well (similiar to \textsuperscript* defined by realscripts) I need to add some more complex definitions I guess. Anyway, thanks again for your answer, which shows me the correct path to follow.
    – Martin
    Sep 10, 2020 at 14:03

You must log in to answer this question.

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