3

I have two requirements. I can achieve each one of these two requirements separately but I have not been able to combine them.

First, I need to allow the hyphenation of dashed words (eg: "entendendo-se"), which by default it isn't possible. Example:

enten-
dendo-se

or

en-
tendendo-se

Then, when a word is hyphenated, if the line break occurs on the dash, it should add another dash in the following line (this is a portuguese language rule). Example:

entendendo-
-se

I know that I can achieve the first one by using the extdash package with \-/ and I can achieve the second one by defining a macro that will replace the dashes with \discretionary{-}{-}{-}.

But how can I combine both requirements in a solution?

And finally, but not required, would it be possible to apply the solution to all the dashes throughout some part of the text (so that I don't need to replace every dash with a command [or whatever would be used])?

PS: I am currently using the XeLaTeX compiler.

EDIT with more information

Minimal working example

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

\begin{document}

\chapter{Exemplo}
Texto completamente aleatório, foi feito para demonstrar o porquê de entendendo-se não ser hifenizado corretamente.

\end{document}

In this example, the word entendendo-se breaks on the dash but it could have been broken sooner.

  • The solution for my first requirement would be to add \usepackage[shortcuts]{extdash} and replace entendendo-se with entendendo\-/se. This is needed because LaTeX doesn't break dashed words by default. You will see that the word breaks sooner (because LaTeX believes it makes the first line prettier) and this is one of the things I want to achieve. The word appears like this: enten- dendo-se
  • The solution for my second requirement would be to replace entendendo-se with entendendo\discretionary{-}{-}{-}se. You will see that, when the word breaks on the dash, another dash is added in the next line (which is a portuguese rule) and this is my second requirement. The word appears like this: entendendo- -se. Please note that if the word does not break on the dash, no additional dash should be added!

However, I have not been able to combine both...

  • 1
    Welcome to TeX.SE! Please show us a short compilable TeX code resulting in your issue! Then we do not have to guess what you are doing, for example which documentclass you use, which packages (babel, which option) etc. – Mensch Mar 19 at 2:35
1

After some trial and error, I found a way to achieve both requirements:

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

\begin{document}

\chapter{Exemplo}
Texto completamente aleatório, foi feito para demonstrar o porquê de entendendo\babelhyphen{repeat}se não ser hifenizado corretamente.

\end{document}

For more convenience, we could add \defineshorthand{"-}{\babelhyphen{repeat}} to the preamble and replace entendendo-se with entendendo"-se

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.