TeX - LaTeX Asked on January 3, 2022
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}
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}
Answered by egreg on January 3, 2022
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}}
Answered by wipet on January 3, 2022
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}
Answered by Sverre on January 3, 2022
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP