10

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 0 \myalt = {\begingroup\addfontfeature{Style=Alternate}}
\XeTeXinterchartoks \myalt 0 = {\endgroup}
\XeTeXinterchartoks 255 \myalt = {\begingroup\addfontfeature{Style=Alternate}}
\XeTeXinterchartoks \myalt 255 = {\endgroup}

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

This example is shown here:

enter image description here

3
  • 1
    XeTeX can't apply kerning between characters in different fonts.
    – egreg
    Jan 12, 2013 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, 2013 at 15:33
  • Note that the word boundary class currently has the number 4095 (since 2016) instead of 255.
    – Marijn
    Mar 10, 2023 at 22:03

1 Answer 1

8

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{%
  \ifx\f@shape\it@shape@string\addfontfeatures{Style=Alternate}\fi}

\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
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .