4

I need to break a url at both '_' and '-':

http://www.domain.org/word/word-word_(word-word)/.

Thanks to this thread, by using \RequirePackage[hyphens]{url} and \usepackage[hyphens]{url}, I get line break at '-', but it does not seem to work at '_'. Your advise is welcome.

UPDATE

\RequirePackage[hyphens]{url}
\documentclass[a4paper,12pt]{article}
\usepackage[hyphens]{url}

\makeatletter
\def\do@url@hyp{\do\-\do\_}
\makeatother

\begin{document}

\url{http://www.dom.it/aaaa/word-word\_word-word\_word-word\_word-word\_word-word\_word-word\_word-word------------------------------------------------------------------------------------------------------------------(xyz)}

\url{http://www.dom.it/aaaa/word-word\_word-word\_word-word/word-word\_word-word\_word-word\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_(xyz)}

\end{document}

output

So, it seems that it works with '_', and it does not with many '-'. Your comment is welcome.

mario
  • 761

1 Answers1

3

The hyphens option executes

\def\do@url@hyp{\do\-}

and you just want to add \do\_ to this.

\documentclass{article}
\usepackage{url}

\makeatletter
\def\do@url@hyp{\do\-\do\_}
\makeatother

\begin{document}

\begin{minipage}{0pt}
\hspace{0pt}\url|http://www.domain.org/word/word-word_(word-word)/|
\end{minipage}

\end{document}

The minipage is just to force as much splitting as possible.

enter image description here

egreg
  • 1,121,712