# Alternates for specific characters & kerning

I am trying to change the stylistic set used for italic y in my document. I used Alan Munn's method, explained here: Use stylistic set variations only for certain glyphs.

It works properly, except that it interferes with the kerning. (I believe this problem may be related to Emerson's: Glyph alternates break hyphenation.)

Is there a fix?

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Arno Pro}
\begin{document}

\textit{y} -- \textit{y.} -- y. % Proper kerning.

\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\myalt
\XeTeXcharclass y \myalt
\XeTeXinterchartoks \myalt 0 = {\endgroup}
\XeTeXinterchartoks \myalt 255 = {\endgroup}

\textit{y} -- \textit{y.} -- y. % No kerning (esp. after the upright y).
\end{document}


This example is shown here:

-
XeTeX can't apply kerning between characters in different fonts. –  egreg Jan 12 '13 at 13:51
But is there a way around this problem? For instance, could the interchar class apply only to the italicised character and not its upright counterpart? I would not mind losing kerning as far as the italic y is concerned (there is very little anyway), but it is upsetting otherwise. –  Luca B. Jan 12 '13 at 15:33

If you need the "Alternate" style only for italics, you can do like this:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Arno Pro}

\makeatletter
\def\it@shape@string{it}
\def\check@italics{%

\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\myalt
\XeTeXcharclass y \myalt
\XeTeXinterchartoks 0 \myalt = {\begingroup\check@italics}
\XeTeXinterchartoks \myalt 0 = {\endgroup}
\XeTeXinterchartoks 255 \myalt = {\begingroup\check@italics}
\XeTeXinterchartoks \myalt 255 = {\endgroup}
\makeatletter

\begin{document}

\begingroup\XeTeXinterchartokenstate=0 % disable for testing

\textit{y} -- \textit{y.} -- y. % Proper kerning.

\endgroup

\textit{y} -- \textit{y.} -- y. % Kerning is good after Roman y

\end{document}


I haven't the Arno Pro font, so I tested it with another font (which hasn't different y's), but the kerning was proper.

Note that the "modern" way for enabling the standard TeX ligatures is

Ligatures=TeX

-
Thank you! It works like a charm! –  Luca B. Jan 12 '13 at 16:31