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}
4
  • see the documentation. Section "Adapting hyphenation". Jun 24, 2020 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, 2020 at 18:05
  • 1
    Ok, I've found that \xpghyphenation is a typo, see github.com/reutenauer/polyglossia/issues/413. It has for some reason still not been corrected in the documentation.
    – Sverre
    Jun 24, 2020 at 18:15
  • 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, 2020 at 19:19

3 Answers 3

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

1
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}}
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .