fontspec

I have encountered something while using fontspec that I do not quite understand. What is the scope of a font feature added using the \addfontfeatures command? For instance, consider the example below using lualatex:

 \documentclass{article}
\usepackage{fontspec,lipsum}
\setmainfont{TeX Gyre Termes}

\begin{document}

1234567890

{%
1234567890%
}

1234567890

Here is some text that is long enough so that it will involve a single proper hyphenation at the end of the first line.

{%
Here is some text that is long enough so that it will involve a single proper hyphenation at the end of the first line.%
}

Here is some text that is long enough so that it will involve a single proper hyphenation at the end of the first line.

\end{document}


The option Numbers=OldStyle is only applied locally and does not exit the braces, but the option HyphenChar=None continues after the braces end. Is there a way to limit the scope of HyphenChar as Numbers is limited above?

Good question!

Some assignments performed by TeX (and also by XeTeX) are always global. You find the list on page 277 of the TeXbook or section 10.2 in TeX by Topic. Among them is setting the \hyphenchar of a font, which is the primitive operation performed by the

HyphenChar=None


option, or any other setting of the same key.

So, no, there is no way to limit the scope of that declaration. Simply declaring a new font family using the same font but changing the hyphenchar will not work, as the value is associated to the memory location relative to the font and fonts loading the same TFM file (standard TeX) or the same OTF file (XeTeX) will share the hyphenchar.

A possible workaround is to define a new font family slightly scaling the font:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Junicode}
\newfontfamily{\mainno}[HyphenChar=None,Scale=.999]{Junicode}

\usepackage{polyglossia}
\setmainlanguage{latin}

\usepackage{lipsum}

\textwidth=5cm

\begin{document}

\hyphenpenalty=-3000

{\mainno\the\hyphenchar\font\lipsum*[2]} \the\hyphenchar\font \lipsum[3]

\end{document}


The settings are just to encourage hyphenation. The first part of the paragraph will have no hyphens and start with -1, while the second part will be hyphenated and start with 45. Of course the first part will have many overfull lines. Here's an image (second part truncated):

It's also possible to say

{\addfontfeatures{Scale=.999,HyphenChar=None}\the\hyphenchar\font\lipsum*[2]}
\the\hyphenchar\font \lipsum[3]