4

How can I get a dotted URL underline with line breaking?

I found this solution: Having all links underlined with dotted line but this TIKZ one does not work with line breaking.

I also tried a simpler solution. This results in a dotted line, but also no line breaking.

\documentclass{article} 
\usepackage[hidelinks]{hyperref}  
\usepackage{ulem}
\makeatother
\AtBeginDocument{
   \let\oldurl=\url
   \renewcommand\url[1]{\dotuline{\oldurl{#1}}}
}
\begin{document}
Desired dotted line, but no linebreaking:\\
\url{http://www.very.very.very,very.very.very.very.very.very.very.long.url.com/a/b/c/d/e/df/sadasd/asdasda}
\par Line breaking but no dotted line\\
\oldurl{http://www.very.very.very,very.very.very.very.very.very.very.long.url.com/a/b/c/d/e/df/sadasd/asdasda}
\end{document}

This outputs this:

enter image description here

How to get linebreaking working in combination with dotted (or more in general: customized) underline?

  • 1
    You can use Martin's code here tex.stackexchange.com/a/24279/2388 and then \tikzul[dashed]{\url{http://www.very.very.very,very.very.very.very.very.very.very.long.url.com/a/b/c/d/e/df/sadasd/asdasda}}. (If your url contains special chars, you will have to store the url first with \urldef). You must compile twice. – Ulrike Fischer May 13 '15 at 15:40
  • This solution of Ulrike does not work: this: "\tikzul[dashed]{\url{A}}" results in "! Undefined control sequence. l.135 \tikzul[dashed]{\url" however without URL it is working (so "\tikzul[dashed]{A}" does work but off course no URL). – robert May 14 '15 at 11:52
  • Well you naturally should load the url or hyperref package if you want to use the command \url. – Ulrike Fischer May 14 '15 at 12:00
  • Thanks Ulrike that did the trick. Is this TIKZUL already packaged up? – robert May 14 '15 at 12:32
  • Repeated question: tex.stackexchange.com/questions/236337/… – Carlos Viegas May 14 '15 at 13:43
1

With the commands \href and \allowbreak I was able to get the desired output. Dotted line and line break. Unfortunately I have no idea how it would be possible to add the \allowbreaks automatically after every /.

\documentclass{article} 
\usepackage[hidelinks]{hyperref} 
\usepackage{ulem}
\makeatother
\AtBeginDocument{
   \let\oldurl=\url
   \renewcommand\url[1]{\dotuline{\oldurl{#1}}}
}
\begin{document}
Desired dotted line, but no linebreaking:\\
\url{http://www.very.very.very,very.very.very.very.very.very.very.long.url.com/a/b/c/d/e/df/sadasd/asdasda}
\par Line breaking but no dotted line\\
\oldurl{http://www.very.very.very,very.very.very.very.very.very.very.long.url.com/a/b/c/d/e/df/sadasd/asdasda}\\
\href{http://www.very.very.very,very.very.very.very.very.very.very.long.url.com/a/b/c/d/e/df/sadasd/asdasda}{\dotuline{http://www.very.very.very,very.very.very.very.very.very.very.long.url.com/\allowbreak{}a/\allowbreak{}b/\allowbreak{}c/\allowbreak{}d/\allowbreak{}e/\allowbreak{}df/\allowbreak{}sadasd/\allowbreak{}asdasda}}
\end{document}

Output: enter image description here

  • Thanks Richard for your answer, but breakurl is not for pdflatex. Also I cannot store this allowbreak inside the URL entry of Bib(la)tex. – robert May 14 '15 at 12:34
  • Hi jos, I'm sorry, but I forgot to remove the breakurl package from the solution (I'll edit the code). This however changes nothing regarding the output. Unfortunately you are right, that das not work with BiB(La)TeX. – Richard May 14 '15 at 12:52

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.