0

In Portuguese, we are supposed to add an hyphen at the beginning of the following line when hyphenation happened where there was already an hyphen. This is quite common because we use hyphens for enclitics (faz-se, for instance) and prefixes (e.g. pós-moderno), this rule was optional and is now coming back as a requirement.

To clarify, if faz-se gets hyphenated, one line will end in faz- and the following one will begin with -se.

All solutions I found call for either reverting back to Babel, or migrating to LuaLaΤεχ, or search and replacing existing hyphens, or some combination thereof. Is there a way to customize Polyglossia, or XəLaΤεχ, to just do the right thing?

Tried:

\documentclass {scrbook}

\usepackage {interchar, polyglossia}

\setlength\textwidth{8cm}

\setmainlanguage {brazil}

\begin {document}

\newintercharclass {\myclass}
\intercharclass {`\-} {\myclass}
\interchartoks {\myclass} {0} {\discretionary {} {-} {}}
\intercharstate {1}

intimidá-la-emos intimidá-la-emos intimidá-la-emos intimidá-la-emos
intimidá-la-emos intimidá-la-emos intimidá-la-emos intimidá-la-emos

\end {document}

Error, presumably because interchar does not like XəΤεχ:

Runaway argument?
! Forbidden control sequence found while scanning use of \cs_generate_variant:N
n.
<inserted text>
            \par
l.31 \cs_generate_variant:Nn \int_to_hexadecimal:n
                                               { V }

interchartoks:

\documentclass {scrbook}

\usepackage {polyglossia}

\setlength\textwidth{8cm}

\setmainlanguage {brazil}

\begin {document}

\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\hyphclass
\newXeTeXintercharclass\letterclass
\XeTeXcharclass`\-=\hyphclass
\newcount\zz
\zz=`\A
\loop
\XeTeXcharclass\zz=\letterclass
\advance\zz 1
\unless\ifnum\zz>`\z
\repeat

\def\zzz-{\discretionary{-}}{-}{-}}

\XeTeXinterchartoks\letterclass\hyphclass{\zzz}

intimidá-la-emos intimidá-la-emos intimidá-la-emos intimidá-la-emos
intimidá-la-emos intimidá-la-emos intimidá-la-emos intimidá-la-emos

\end {document}

Result:

Only the first line break gets the additional hyphen. Presumably because á is not included between A and z. How could I include accented characters in the loop?

  • do you just need to repeat if you hyphenate at an explicit hyphen, or do you want all hyphens to double (which might be very hard to do in xetex) – David Carlisle Dec 1 '18 at 16:22
  • Only in hyphenation. For instance, if faz-se gets hyphenated, one line will end in faz- and the following would beging with -se. – lfd Dec 1 '18 at 16:24
  • oh that's a lot easier, basically you just need to count a - as a normnal letter and then have hyphenation rules that allow hyphenation following -, or make - active and expanding to a discretionary with two - - or use xetex interchartoks to insert a discretionary hyphen after - – David Carlisle Dec 1 '18 at 16:58
  • I have no inkling about the first two, but will research starting from the third, which seems easy to track down. – lfd Dec 1 '18 at 17:17
  • 1
    if you edit partial solutions into the question it makes the question.answer format very hard for later readers to follow. Also please always post complete documents as in my answer not fragments. The fragment you posted does not produce the error that you show, it produces ! Undefined control sequence. l.3 \newintercharclass – David Carlisle Dec 1 '18 at 17:59
2

This shows one possible approach, using XeTeX character classes to replace a lower case ascii letter followed by a hyphen by a discretionary that repeats the hyphen just a to z are done here but you can add any other letters to the \lettersclass

enter image description here

The same text set with and without the setting.

\documentclass{article}

\setlength\textwidth{8cm}

\begin{document}

abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long
verylongword verylongword verylongword verylongword verylongword 
abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long
verylongword verylongword verylongword verylongword verylongword 
abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long
verylongword verylongword verylongword verylongword verylongword 
abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long
abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long

\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\hyphclass
\newXeTeXintercharclass\letterclass
\XeTeXcharclass`\-=\hyphclass
\newcount\zz
\zz=`\a
\loop
\XeTeXcharclass\zz=\letterclass
\advance\zz 1
\unless\ifnum\zz>`\z
\repeat

\def\zzz-{\discretionary{\textbf{-}}{\textbf{-}}{-}}

\XeTeXinterchartoks\letterclass\hyphclass{\zzz}

abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long
verylongword verylongword verylongword verylongword verylongword 
abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long
verylongword verylongword verylongword verylongword verylongword 
abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long
verylongword verylongword verylongword verylongword verylongword 
abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long
abcd-efg  foo-bar zzz-zz-zz somethinglong some-thing-long

\end{document}
  • The luatex version is shorter \postexhyphenchar= `\- – Ulrike Fischer Dec 1 '18 at 17:41
  • The LuaΤεχ version seems seriously tempting, I wonder how much of an effort would be to port a quite already developed document to it. – lfd Dec 1 '18 at 17:43
  • The issue seems to be that I am having trouble finding documentation on the XəΤεχ solution, so as to be able to understand and adapt it. – lfd Dec 1 '18 at 17:46
  • 1
    @lfd the xetex manual has a section on interchartoks usage texdoc xetex or texdoc.net/texmf-dist/doc/xetex/xetexref/xetex-reference.pdf (section 3) – David Carlisle Dec 1 '18 at 17:55
  • LuaΤεχ is out of bonds for me, it seems Polyglossia in LuaΤεχ does not cover Brazilian Portuguese. Go figure. – lfd Dec 1 '18 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.