# Use variant glyphs from Mac OS X fonts under Linux

I would like to get the variant option from fontspec working under Linux. Unfortunately, this option which works with the AAT font system is not compatible with the OpenType font mechanism used under Linux.

However, I dumped one of the Mac OS X fonts which contains such variant glyphs and I found that these variant glyphs can be easily got by using their name. Indeed their name are composed like this: "<name of the standard glyph>.<variant number>". For instance to get the second variant of a "d", just use the: \XeTeXglyph\XeTeXglyphindex "d.2". For a "é", it would be: \XeTeXglyph\XeTeXglyphindex "eacute.2" etc.

Thus I developed a little command to get the corresponding variant if present or use the default one otherwise:

\newcommand\variantChar[2]{%
\@tempcnta=\XeTeXglyphindex "#1.#2"\relax
\ifnum\@tempcnta>0
\XeTeXglyph\@tempcnta
\else
#1
\fi}


Right now I would like to construct a command which takes two arguments: the first one would be the variant number and the second one the sentence to write by using that variant. Unfortunately I don't know exactly how can I parse character by character the second argument and call the \variantChar command.

Last but not least, I would be interested by knowing a way to get the name of a glyph in order to take into account complexe glyphs name like "eacute" or ligature glyphs like "ft" etc. Is there a such command which takes as argument the glyph and returns the glyph name?

Otherwise do you know an other way to use variant glyphs available in MacOS X fonts under Linux?

-
Welcome to tex.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. –  Seamus Mar 11 '11 at 13:16

I once implemented a similar thing using TeX's tail recursion. Adapted to your situation, my macro definition would look like this:

\def\varianttext{%
\begingroup
\obeyspaces
\@varianttext}
\def\@varianttext#1#2{%
\endgroup
\def\tempa{#1}
\@@varianttext#2\end}
\def\@@varianttext#1#2{%
\variantchar{#1}{\tempa}%
\ifx#2\end%
\let\next\@gobble%
\else%
\let\next\@@varianttext%
\fi%
\next#2}

The macro \@@varianttext just iterates over the input and applies \variantchar to each character.

Edit: I updated the solution to handle spaces correctly.

-
Thank you very much for your code! I used the "|" character which is not often used for test. It works pretty well. The only problem is that it eats space characters.. I guess it is a bug in my \variantChar command.. I will investigate. –  Adesuray Mar 11 '11 at 14:21
It's not a bug in \variantChar command.. The space character is really eaten. Does someone have an idea to get it back? Thank you in advance. –  Adesuray Mar 11 '11 at 14:31
It seems that TeX discards the spaces when it scans arguments. For example, if you define \def\test#1#2{#1,#2}, then \test ab gives the same result as \test a b. –  Michael Ummels Mar 11 '11 at 14:38
I really don't know how to preserve the space.. I tried to play with the catcodes but it seems that it doesn't work... :( –  Adesuray Mar 11 '11 at 15:34
@Michael: because otherwise the macro parameters are read before \obeyspaces is processed. –  Andrey Vihrov Mar 11 '11 at 17:17