10

Alan Munn explined in Use stylistic set variations only for certain glyphs how to enable glyph alternates for a certain subset of glyphs.

I'm using the second method he described (the other method isn't viable for me) and it seems to break automatic hyphenation.

Consider this example:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\usepackage[paperwidth =   6 em,right=   1 em,left=    1 em,]{geometry}
\begin{document}
A a h coherence 
\end{document}

Here coherence is correctly hyphenated. correct

Now the same with alernates switched on:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\usepackage[paperwidth =   6 em,right=   1 em,left=    1 em,]{geometry}
% Now the more complicated version:
\XeTeXinterchartokenstate=1 % enable character classes
\newXeTeXintercharclass\myalt % create a new class
\XeTeXcharclass `\h \myalt % add h to the class
% between any character of class 0 and \myalt add the alternate feature
\XeTeXinterchartoks 0 \myalt = {\begingroup\addfontfeature{Alternate=0}}
% between \myalt and any character end the group
\XeTeXinterchartoks  \myalt 0 = {\endgroup}
% between a word boundary and \myalt add the alternate feature
\XeTeXinterchartoks 255 \myalt = {\begingroup\addfontfeature{Alternate=0}}
% between \myalt and the word boundary end the group
\XeTeXinterchartoks  \myalt 255 = {\endgroup}
\begin{document}
A a h coherence 
\end{document}

Now hyphenation is broken. broken

Note that this is not an artifact of the specific example, I also tried it with a longer text.

Is this a bug?

EDIT: egreg explained that this is indeed not a bug.

Is a workaround possible? One obvious possibility is to mark hyphenation points explicitly (e.g. co-herence), but that is unpractical in a longer document.

  • 7
    It's not a bug: TeX and XeTeX don't try hyphenation on sequences of letters interrupted by font changes. Can't you apply the "alternation" to the whole word? – egreg Mar 24 '12 at 15:45
  • Unfortunately that's not viable: I want to globally use alternates for a certain subset of glyphs. – Emerson Mar 25 '12 at 12:17
  • So the answer is: it's not a bug. I believe that this restriction can be lifted with Lua(La)TeX, which unfortunately hasn't the "interchartoks" feature. – egreg Mar 25 '12 at 12:22
6

It's not a bug. What you get when typesetting "coherence", after the interchartoks feature has acted, is equivalent to

co\begingroup\addfontfeature{Alternate=0}h\endgroup erence

and the problem is exactly here: XeTeX won't try hyphenation past a font change.

You may "solve" it with a nasty trick:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}

\makeatletter
\providecommand{\allowhyphens}{\nobreak\hskip\z@skip}
\makeatother
% Now the more complicated version:
\XeTeXinterchartokenstate=1 % enable character classes
\newXeTeXintercharclass\myalt % create a new class
\XeTeXcharclass `\h \myalt % add h to the class
% between any character of class 0 and \myalt add the alternate feature
\XeTeXinterchartoks 0 \myalt = {\begingroup\addfontfeature{Alternate=0}}
% between \myalt and any character end the group
\XeTeXinterchartoks  \myalt 0 = {\endgroup\allowhyphens}
% between a word boundary and \myalt add the alternate feature
\XeTeXinterchartoks 255 \myalt = {\begingroup\addfontfeature{Alternate=0}}
% between \myalt and the word boundary end the group
\XeTeXinterchartoks  \myalt 255 = {\endgroup\allowhyphens}
\begin{document}
\parbox{3pt}{A a h coherence}
\end{document}

I put "solve" in quote marks because the word that is tried for hyphenation is actually "erence" and not "coherence", so the result (on different words) may be incorrect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.