TransWikia.com

Problem with custom font feature for addition kerning in OpenType font

TeX - LaTeX Asked on December 18, 2020

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}

One Answer

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
RenewDocumentCommandtextsuperscript{m}{#1}
begin{document}
   ītextsuperscript{12}

ī¹ 
end{document}

Correct answer by Ulrike Fischer on December 18, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP