2

I've used hyphenrules to add custom hyphenation to the languages I write in. I once asked how to do this, and the accepted answer (MWE below) no longer compiles, but gives the error message Environment hyphenrules undefined.

So the question is, how should one add language specific custom hyphenation rules with polyglossia now? I'm using version 1.49 of polyglossia.

\documentclass{article}

\usepackage{polyglossia} \setmainlanguage{nynorsk}

\begin{hyphenrules}{nynorsk} \hyphenation{fram-halds-skulen} \end{hyphenrules}

\begin{document}

\parbox{0pt}{\hspace{0pt}framhaldsskulen}

\end{document}

EDIT

Following Ulrike's comment, I've tried to follow section 5.1 in the polyglossia documentation, where it says we can use the command \xpghyphenation. Doing so, however, only gives me the error message Undefined control sequence. l.6 \xpghyphenation.

\documentclass{article}

\usepackage{polyglossia} \setmainlanguage{nynorsk}

\xpghyphenation{nynorsk}{fram-halds-skulen}

\begin{document}

\parbox{0pt}{\hspace{0pt}framhaldsskulen}

\end{document}

Sverre
  • 20,729
  • see the documentation. Section "Adapting hyphenation". – Ulrike Fischer Jun 24 '20 at 17:57
  • @UlrikeFischer It says that we should use \xpghyphenation. I've tried, but only get the error Undefined control sequence. l.6 \xpghyphenation. – Sverre Jun 24 '20 at 18:05
  • 1
    Ok, I've found that \xpghyphenation is a typo, see https://github.com/reutenauer/polyglossia/issues/413. It has for some reason still not been corrected in the documentation. – Sverre Jun 24 '20 at 18:15
  • https://github.com/reutenauer/polyglossia/issues/427 (though in my head at least the point of hyphenrules was not to give hyphenation exceptions in the preamble, it is to use only the hyphenation patterns of the specified language) – moewe Jun 24 '20 at 19:19

3 Answers3

1

The environment hyphenrules is deprecated in newer versions of polyglossia. To add language specific hyphenations, use \pghyphenation[(options)]{(language)}{(hyphenations)}. The current documentation (v. 1.49) states incorrectly in section 5.1 that the command is \xpghyphenation. This is a mistake for \pghyphenation which has yet to be corrected.

\documentclass{article}

\usepackage{polyglossia} \setmainlanguage[variant = nynorsk]{norwegian}

\pghyphenation[variant = nynorsk]{norwegian}{fram-halds-skulen}

\begin{document}

\parbox{0pt}{\hspace{0pt}framhaldsskulen}

\end{document}

enter image description here

Sverre
  • 20,729
  • Given https://github.com/reutenauer/polyglossia/issues/427 I think the first sentence is misleading. It might be true though that it is deprecated for this particular use case. – moewe Jun 24 '20 at 19:22
1

From TeX primitive point of view you needs only to use \heyphenation primitive when \language primitive register is set to the selected language. So, you can write:

{\language=lang.number \hyphenation{fram-halds-skulen}}

A little problem is that if you are using LaTeX then you don't know the lang.number because it is auto-generated by macros. You can set the \language register using LaTeX's command:

\selectlanguage{nynorsk}

This command does \language=lang.number internally. So, you can use the \hyphenation primitive by:

{\selectlanguage{nynorsk} \hyphenation{fram-halds-skulen}}

Of course, you can give hyphenation exceptions for all declared languages:

 {\selectlanguage{nynorsk} \hyphenation{fram-halds-skulen}}
 {\selectlanguage{czech}   \hyphenation{výjme-čné dě-lení}}
 ...

For sake of complexity: if you are using csplain or OpTeX format then you know the number of your language, see hyphen.lan file. Norwegian Nynorsk in Unicode has language 136. So, you can do your task at primitive level only:

{\language=136 \hyphenation{fram-halds-skulen}}
wipet
  • 74,238
1

The hyphenrules trick was a hack. Since version 1.45, polyglossia has a specific method for defining language specific hyphenation exceptions, namely

\pghyphenation[<options>]{<language>}{<exception list>}

The <options> are for the particular language to set a variant. The <exception list> has the same syntax as the argument to \hyphenation, so words separated by spaces with hyphens at the chosen break points.

As of version 1.50a, the documentation about hyphenation exceptions is inaccurate, because it is claimed that \hyphenation acts globally for all language, but this is not true: the exceptions are just for the current language which, in the preamble is still language 0 (American English).

Thus \hyphenation should actually never be used (unless the main language is American English).

The hyphenrules environment has not been deprecated, but it should only be used in the document body. On the other hand, as of version 1.50a the hyphenrules trick still works. This doesn't mean it should be used, but older documents using it will work.

\documentclass{article}

\usepackage{polyglossia} \setmainlanguage[variant=nynorsk]{norwegian}

\pghyphenation[variant=nynorsk]{norwegian}{fram-halds-skulen}

\begin{document}

\parbox{0pt}{\hspace{0pt}framhaldsskulen}

\end{document}

enter image description here

egreg
  • 1,121,712