# Use stylistic set variations only for certain glyphs

Some fonts include stylistic variations of certain glyphs. But it seems like there is only a global switch for these alternates, as in this example from the fontspec manual:

\fontspec{Linux Libertine}
\textsc{a} \& h \\
\textsc{a} \& h


Is it possible to use stylistic alternates only for individual glyphs, e.g. only for the '&'-glyph?

-
Hopefully in the long run these sorts of fonts move towards using CharacterVariants so that they can be toggled individually. The fontspec CharacterVariant feature corresponds to the cv(xx) OpenType tag, where (xx) is 00 to 99. –  Will Robertson Sep 12 '11 at 11:23

For the specific example you have in mind, the simplest solution is simply to redefine \& as the alternate version. This is especially true of \&, since it's already a macro. For the occasional other character, this route might also be best, i.e. simply define a macro to introduce the alternate.

There is a more complicated version using \XeTeXintercharclass that might be useful for choosing alternates for more characters. The basic technique is explained in the XeTeX documentation (texdoc xetex). Note that this solution will not work for LuaLaTeX, which does not support these interchar classes.

I've worked both methods in the following sample document:

% !TEX TS-program = XeLaTeX

\documentclass{article}
\usepackage{fontspec}
\setmainfont[]{Linux Libertine O}
\begin{document}

This is an \& not alternate

% First the simple version
\let\oldand\&

This is the alternate \& after redefinition.

\renewcommand\&{\oldand}

This is back to the old \&

% Now the more complicated version:
\XeTeXinterchartokenstate=1 % enable character classes
\newXeTeXintercharclass\myalt % create a new class
\XeTeXcharclass \& \myalt % add & to the class
% between any character of class 0 and \myalt add the alternate feature
`