fontspec icon indicating copy to clipboard operation
fontspec copied to clipboard

LuaTeX: \addfontfeature resets \prehyphenchar and \posthyphenchar

Open svenper opened this issue 6 years ago • 1 comments

Description

In LuaTEX, \prehyphenchar and \posthyphenchar supposedly affect the current language. However, after changing \addfontfeature, both of those reset to the defaults.

Seems related to #58.

Check/indicate

  • [ ] Relevant for XeTeX
  • [x] Relevant for LuaTeX
  • [x] Issue tracker has been searched for similar issues?
  • [x] Links to <tex.stackexchange.com> discussion if appropriate:
    • https://tex.stackexchange.com/questions/468140/addfontfeature-resets-prehyphenchar-and-posthyphenchar – see comment by @u-fischer

Minimal example demonstrating the issue

\documentclass[a4paper]{article}
\pagestyle{empty}
\setlength{\textwidth}{17em}

\RequirePackage{lipsum}

\RequirePackage{fontspec}
\setmainfont{cmunrm.otf}

\RequirePackage{polyglossia}
\setmainlanguage{english}
\addto\captionsenglish{\prehyphenchar=`¶ \posthyphenchar=`¶}
\prehyphenchar=`¶ \posthyphenchar=`¶

\begin{document}

\begin{english}
\lipsum*[1]\par
{\addfontfeature{Path}---any feature: hyphen reset---}\par
\lipsum*[1]\par
\end{english}

\end{document}

Further details

Probably affects \preexhyphenchar, \postexhyphenchar, etc. as well.

svenper avatar Jan 01 '19 18:01 svenper

\prehyphenchar is always changed globally (like e.g. \hyphenchar):

\documentclass{article}
\begin{document}
\prehyphenchar = 100

{ \prehyphenchar= 200 }

\showthe\prehyphenchar

\end{document}

So using a local set command (\int_set:Nn \luatex_prehyphenchar:D) in \__fontspec_init: looks wrong (and it should be \tex_prehyphenchar:D anyway).

But beside this \prehyphenchar is tied to languages in luatex, so imho font changes shouldn't set it at all in luatex.

u-fischer avatar Jan 01 '19 18:01 u-fischer

I came across this problem again while trying to properly implement a soft hyphen in tagged PDF.

In my opinion these lines in fontspec-code-internals.dtx in the \@@_init: should be deleted asap.

    \int_set:Nn \prehyphenchar { `\- } % fixme
    \int_zero:N \posthyphenchar        % fixme
    \int_zero:N \preexhyphenchar       % fixme
    \int_zero:N \postexhyphenchar      % fixme

I found the commit (in 2010) where these lines where introduced and it says

Hack to reset hyphenchars with font switch. This actually what LuaTeX, per its reference manual p.131, do when it starts a new language.

I cannot understand this commit message. Why is there any need to reset the hyphenchars with a font switch and why such a hard reset? The values are, as the reference to the luatex manual says, language settings. The fontspec code could perhaps at a font switch test if the actuals hyphenchars are in the font and issue a warning (but you would get missing character warning anyway, so it is not clear if there is a benefit) but the current code looks definitively wrong.

(apart from this: as already mentioned these are global variables and \int_set:Nn is wrong anyway)

u-fischer avatar Apr 25 '24 10:04 u-fischer