9

In Portuguese, many words are explicitly hyphenated, such as "anti-inflamatório".

According to Portuguese hyphenation rules, if the line is broken at the hyphen, another hyphen should be added to be beginning of the next line (otherwise we do as everyone else…).

Example 1: An example of "normal" hyphenation:

Necessito de pensar em tomar um anti-infla-
matório e bem depressa.

Example 2: An example of hyphenation at the hyphen (notice the extra hyphen in the next line):

Necessito de pensar em tomar um anti-
-inflamatório e bem depressa.

How can I achieve the behaviour of Example 2? (Babel does not add the extra hyphen in the next line by default…)

Thank you.

João Lourenço

6
  • I just noticed that the line breaks in the examples didn't show as expected! :( Below, <NL> represents a line break! NORMAL: Necessito de pensar em tomar um anti-infla-<NL>matório e bem depressa. HYPHEN: Necessito de pensar em tomar um anti-<NL>-inflamatório e bem depressa. Oct 6, 2016 at 15:53
  • 1
    do you need this to work from a normal - as in anti-inflamatório or would it be OK to introduce a new command as in anti\myhyphen inflamatório which would be a lot less likely to break other uses of - for example in lengths and numbers. Oct 6, 2016 at 16:03
  • 1
    Hi João, nice finding! :) Out of curiosity, I decided to investigate about our line wrapping rules (for Portuguese speakers, the term is coined as translineação, in case one wants to search about it) and was shocked to discover the 2009 reform now makes mandatory the redundant hyphen in the beginning of the new line! Personally, I'd rather rewrite my sentence in order to avoid this situation than use another hyphen (I am definitely not used with this notation). Oh my. Oct 6, 2016 at 16:51
  • @David Carlisle, the best would be for it to work for normal hyphen, as for long documents (e.g., a PhD thesis written in Portuguese) a solution based in a macro is admissible but very inconvenient. Oct 6, 2016 at 21:37
  • as you will have seen I left it with a macro, you could make - active \catcode`\-=\active\def-{\disccretionary...} but then \hspace{-2pt} will fail, as would \input{foo-bar} you could make the code more complicated to avoid those failures but something else would break. It should be easy in any text editor to occasionally do a global replace of [letter]-[letter] to \1\\x-\2 so really you don't need to worry about this while doing the main typing. Oct 7, 2016 at 11:24

4 Answers 4

2

A recent babel (>=3.37) with luatex can do it for you:

\documentclass{article}

\usepackage[portuguese]{babel}

\babelposthyphenation{portuguese}{.=.}{
  {},
  { no = -, pre = -, post = -, data = 1 },
  {}
}

\begin{document}

Necessito de pensar em tomar um anti-inflamatório e bem depressa.

zzz zzz zzz zzz zzz zzz zzz zzz zzz
Necessito de pensar em tomar um anti-inflamatório e bem depressa.

\end{document}

Here, \babelposthyphenation defines a non-standard hyphenation rule. Currently the code is not very efficient, but in many cases it's hardly noticed. For further details, see Non–standard hyphenation with luatex.

Edit. Now babel provides a predefined transform for this task, which can be enabled with the following preamble:

\documentclass{article}
\usepackage[portuguese]{babel}
\babelprovide[transforms = hyphen.repeat]{portuguese}
2
  • hi @Javier. I add your code to the preamble but I am getting this error "Undefined control sequence. \babelposthyphenation". Any idea why? Thanks! (P.S. I am using XeLaTex, not LuaLaTex)
    – JPMD
    Dec 11, 2021 at 16:15
  • 1
    @JPMD This feature requires luatex. Dec 11, 2021 at 20:47
7

enter image description here

\documentclass{article}

\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\newcommand\x[1]{\discretionary{#1}{#1}{#1}}
\begin{document}

Necessito de pensar em tomar um anti\x-inflamatório e bem depressa.

zzz zzz zzz zzz zzz zzz zzz zzz zzz
Necessito de pensar em tomar um anti\x-inflamatório e bem depressa.

\end{document}
1

For those that use hyphenat package, after the clues from previous answers (thanks!), I came up with the following hack to implement double hyphen at \hyp command (for hyphenat 2009/09/02 v2.3c):

\documentclass{article}

\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{hyphenat}

%% hacking \hyp command from hyphenat to double hyphen
\makeatletter
\renewcommand{\BreakableHyphen}{\leavevmode%
  \prw@zbreak-\discretionary{}{-}{}\prw@zbreak}
\makeatother

\begin{document}

Necessito de pensar em tomar um anti\hyp{}inflamatório e bem depressa.

zzz zzz zzz zzz zzz zzz zzz zzz 
Necessito de pensar em tomar um anti\hyp{}inflamatório e bem depressa.

zzz zzz zzz zzz zzz zzz zzz zzz zzz
Necessito de pensar em tomar um anti\hyp{}inflamatório e bem depressa.

\end{document}

Output from code above

2
  • This works, and doesn't require luatex.
    – n.r.
    Aug 25, 2022 at 8:19
  • If this happens to fail at some random places with words with multiple hyphens (cor-de-rosa, explicar-se-lhes-á, o-que-nunca-se-ri), one may resort to \discretionary{-}{-}{-}, which enforces two hyphens no matter what.
    – n.r.
    Aug 25, 2022 at 10:41
0

The \discretionary solution works fine, but I found kind of cumbersome having to type a \command{} every time. So when I was writing my dissertation I did some hacking to allow using '- as a shortcut:

\documentclass{article}
\usepackage[utf8]{inputenc}
    
%\usepackage[brazil]{babel}    % works for both
\usepackage[portuguese]{babel} % works for both
    
\begin{document}
    
\defineshorthand{"-}{\nobreak\hskip0pt\discretionary{-}{-}{-}\nobreak\hskip0pt}
\chardef\singlequote=`\'
\catcode`\'=\active
\def'#1{\ifmmode\text{\singlequote}\else\ifx#1-"-\else\singlequote#1\fi\fi}
    
Anti'-inflamatório. Circum'-navegação. xxxxxxx xxxxxx xxxx xxxxxx
Pré'-industrial. nononononon no Anti'-inflamatório. Circum'-navegação.
Pré'-industrial. 
    
\end{document}

And by "hacking" I mean someone showed me how to use "- as a shortcut and by trial and error I changed it to '-. I'm not sure how it works, but I was able to complete my dissertation with this. Suggestions to improve are welcome.

Here's how the snippet above renders:

enter image description here

You must log in to answer this question.

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