I'm using XeLaTeX and OpenType fonts.
I would like to use a glyph with a given name, that may be assigned to different Unicode characters in different fonts (or may not exist in a font, or may exist in the font but may not be assigned to any character).
XeTeX provides the \XeTeXglyphindex command that will tell me if the glyph exists in the font, and if yes, will return its index.
The \XeTeXcharglyph command takes a character slot as input an provides the index of the glyph representing it, if any.
What I need is code that will
- check if the glyph exists through
\XeTeXglyphindexand store the index in a variable - run a loop through a given (potentially long) range of Unicode characters, apply
\XeTeXcharglyphto each one, and compare it with the memorized index - if the loop finds the corresponding character, supply it to
\hyphenchar - if not, supply a different character slot to
\hyphenchar.
Do you know where I can find such code (potentially using LaTeX's new expl3 package?
(2 hours later) On the demand of Ulrike, here is some code for a single Unicode slot and a single glyph name. In font Amiri-Regular there is a (very nice) glyph called uni0606 for Unicode character U+0606. Here is a minimal XeLaTeX file providing the glyph index out of the name and out of the character slot:
\documentclass{article}
\usepackage{fontspec}
\newfontfamily{\arabicfont}[Script=Arabic,Extension=.ttf,Scale=1.2]{Amiri-Regular}
\begin{document}
\arabicfont
The glyph of name uni0606 is \the\XeTeXglyphindex "uni0606"
The glyph of character uni0606 is \the\XeTeXcharglyph"0606
If they are the same, assign this to hyphenchar
\end{document}
I need a loop where the second operation (\the\XeTeXcharglyph"0606) is applied, e.g., to all slots between "0000 and "FFFE, until one of them provides a glyph index equal to the one of the first operation. Notice that when a slot is not the font, the command \the\XeTeXcharglyph takes values 0.

expl3expert will say "this is trivial" and write down the code in a few seconds. I knowexpl3has tremenduous potential, you just need to master its syntax. – yannis Apr 29 '21 at 19:58\loopbut isn't the answer always going to be it's not there or it is in slot hex 606? surely no font designer is going to give a glyph name uni0606 to a character assigned a different unicode? – David Carlisle Apr 29 '21 at 22:17\hyphenchar, so we have to assign it to some other slot, and find it among all glyphs/chars of the font. – yannis Apr 30 '21 at 07:28