Before trying to emulate this, first try VerticalPosition=ScientificSuperior
. I have seen quite some fonts not providing "normal", but providing "scientific" superiors. This would explain why the characters are present but not accessuble through the lookup.
Also if you bought a font providing these characters but there is no lookup table for them, I would complain at the font vendor.
Anyway, while I do not recommend it, it is possible to write a macro as you described. This works in multiple steps:
- The macro receives a character argument, we have to get the codepoint. This is easy, TeX provides the codepoint through a backtick. But then we have to translate this into a font specific glyph slot before applying XeTeX's font commands, so we need
\XeTeXcharglyph
.
For example, the glyph code of the forst argument can be queried with (Later we will not use \the
because we work with TeX commands reading a number)
\the\XeTeXcharglyph`#1
- Now we need the glyphname. Luckily, XeTeX provides the
\XeTeXglyphname
primitive to access the glyphname of a glyph slot in a specific font. Here \font
represents the current font, so we can expand the example above and get
\XeTeXglyphname\font\XeTeXcharglyph`#1
- Of course appending
.sup
is easy, here we will use .superior
instead because this works with Linux Libertine.
Then we have to get the glyph index of the new glyph: The \XeTeXglyphindex
primitive comes to our rescue: Given a glyph name, it provides us with the index:
\XeTeXglyphindex"\XeTeXglyphname\font\XeTeXcharglyph`#1.superior"\relax
- Now we know the index of the required glyph, so we can insert it with
\XeTeXglyph
:
\XeTeXglyph\XeTeXglyphindex"\XeTeXglyphname\font\XeTeXcharglyph`#1.superior"\relax
Together, we get
% WARNING: This is a purely academic example, if you actually want to use
% superiors with Linux Libertine, just activate the `sups` feature instead,
% e.g. with `\addfontfeature{VerticalPosition=Superior}`
\documentclass{article}
\usepackage{fontspec}
\setmainfont{LinLibertine_R.otf}
\begin{document}
\newcommand\mysup[1]{%
\XeTeXglyph
\XeTeXglyphindex"\XeTeXglyphname\font\XeTeXcharglyph`#1.superior"
}
abc\mysup a\mysup b\mysup 9XXX
\end{document}
