[XeTeX] substitutions for missing or wrong glyphs

Rik Kabel rik at panix.com
Thu Feb 3 16:01:48 CET 2011


Fr. Michael Gilmary, mma <frmichaelgilmary at ...> scribed:

> On Feb 2 AD 2011, at 4:40 AM, Susan Dittmar wrote:
>
> > I would like to use a font (several in fact, some of which are true
> > type, others open type) which does not include all glyphs I need.
> > For example the endash and emdash are missing, as are the german
> > quotation marks. Is there a way, other than hacking the font file
> > itself, to tell xetex to take those glyphs from another font? I know
> > that might look ugly, but it's still less ugly than the 'missing
> > glyph' glyph or another completely wrong glyph.
>
> Hi Susan:
>
> This seems to be a perfect case for XeTeX interchartoks!
>
> This works, but you'll want to change the Scale for the \tgb font I've
> used here (I made an exaggerated example so it could be seen to work).
>
> %%%%%%%%%%%%%%%%%%%%%
> \documentclass[11pt]{article}
>
> \XeTeXinterchartokenstate = 1
>
> \usepackage{fontspec, realscripts}
> \usepackage{polyglossia}
> \setdefaultlanguage[variant=us]{english}
> \defaultfontfeatures{Ligatures=TeX}
> \setmainfont[Numbers={OldStyle,Proportional}, Contextuals=NoAlternate]
> {Garamond Premier Pro}
>
> \newfontfamily\tgb[Scale=2]{TeX Gyre Bonum}
>
> \XeTeXinterchartoks 0 4 = {\tgb}
> \XeTeXinterchartoks 4 0 = {\normalfont}
> \XeTeXcharclass `\– 4
> \XeTeXcharclass `\— 4
> \XeTeXinterchartoks 255 0 = {\normalfont}
> \XeTeXinterchartoks 0 255 = {\normalfont}
> \XeTeXinterchartoks 255 4 = {\tgb}
> \XeTeXinterchartoks 4 255 = {\normalfont}
>
> \begin{document}
> Try this — I mean does it really work from 2–3 times?
> \end{document}
> %%%%%%%%%%%%%%%%%%%%%

Well, it works fine for mono-font documents, or documents in which the
substitution can be assured to always within the main font, but it fails
horribly in other cases. The OP indicated that she wants to work with
several fonts.

Consider what would happen if additionally the preamble defined a Greek
font, and an en- or em-dash appeared in the body within Greek text: the
text following the en- or em-dash would now be in the document's main
font (defined by \normalfont).

Researching this, I saw that somebody asked (in 2007) if there is a way
to save and restore the current font. That was never answered. Perhaps
it would be useful here. It wouldn't be completely foolproof as many
character classes are defined, but saving the font on transitions from 0
and 255 to 4 (in this example), and restoring it on transitions from 4,
would go a long way towards addressing this.

-- 
Rik Kabel




More information about the XeTeX mailing list