# URL - linebreak

I'm using luatatex 1.0.4 and I already found some solutions for breaking urls. Nevertheless I have special cases for which I didn't find a solution. My sample code looks like:

\documentclass[a4paper,11pt]{article}
\usepackage{fontspec}
\usepackage[english, ngerman]{babel}
\usepackage{hyperref}
\def\UrlBreaks{\do\/\do-\do\_\do\%} % for breaking long URLS additonally
\begin{document}

\end{document}


I'm aware that the sample looks somehow weird nevertheless its a good one.

My first problem I have is that the line break does not kick in. I'm aware that I should define chars for breaking long URLs.

• I tried to do so with UrlBreaks for the char % but this does NOT work.
• The line break works fine if I would use \url but than I have no idea how to specifiy the name differently from the link.
• I read that the package url is not useful as soon as I use lualatex. Therefore I did not include it.
• Re your third bullet point: I don't think that is true. If you load hyperref url will be loaded automatically anyway, so usually there is little point in loading url if one also loads hyperref. But this should have nothing to do with LuaLaTeX. Where did you read that? – moewe Jan 17 at 15:49

\documentclass[a4paper,11pt]{article}
\usepackage{fontspec}
\usepackage[english, ngerman]{babel}
\usepackage{hyperref}
\def\UrlBreaks{\do\/\do-\do\_\do\%} % for breaking long URLS additonally
\begin{document}

\end{document}

• Just to emphasise what is said here between the lines: \href does not process its (second) text argument like a URL, that has to be requested explicitly with \nolinkurl (which prints its argument like \url does, but does not add a link). – moewe Jan 17 at 15:47
• Seems like this fixes this problem. Does it have any kind of 'negative' side effect if I add it in all the tags as name? Cause from the docu I wouldn't have concluded that this option helps here. Just wanna know if this might be a generic solution. – LeO Jan 17 at 15:49
• \nolinkurl is for url's not for arbitrary text. – Ulrike Fischer Jan 17 at 15:51
• ahhh... so there is a parser which checks for urls and than won't break. Am I right? – LeO Jan 17 at 15:52
• Sorry I don't understand what you mean. If you want the rule for url breaking to be applied you have to tell latex that there is an url, either with \url or nolinkurl if you don't want a link. – Ulrike Fischer Jan 17 at 15:54

There's a new xurl package that takes care of line breaks in URLs, introduced in TeX Live 2018:

\documentclass{article}
\usepackage{hyperref}
\usepackage{xurl}
\urlstyle{same}  % don't use monospace font for urls

\begin{document}

\url{http://www.darinews.com/\%D8\%A7\%D8\%B2-\%D8\%B3\%D8\%B1\%DA\%AF\%DB\%8C\%D8\%B1\%DB\%8C-\%D9\%BE\%D8\%B1\%D9\%88\%D8\%A7\%D8\%B2-\%D9\%87\%D8\%A7\%DB\%8C-\%D8\%AE\%D8\%A7\%D8\%B1\%D8\%AC\%DB\%8C-\%D8\%A7\%D8\%B2-\%D9\%85\%DB\%8C\%D8\%AF\%D8\%A7\%D9\%86-\%D8\%A8\%DB\%8C\%D9\%86-\%D8\%A7/}

\href{http://www.darinews.com}{Darinews}

\end{document}