1

I want to list som URLs within an itemize-environment. I would like to break long URLs into several lines, either anywhere in the link, or at locations I specify.

I've tried using the breaklinks option for the hyperref package, and I've tried manually specifying locations where line breaks would be accepable. However, the former only seems to break links around punctuation, and the latter inserts TeX commands in the final PDF (see below). Example code:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage[breaklinks=true]{hyperref}
\begin{document}
    \lipsum[1]
\begin{itemize}
    \item \nolinkurl{www.someshorturl.com}, \nolinkurl{yetanotherurlthatislongandshouldbebrokenintoseverallines.com}, \nolinkurl{www.averyveryveryverylongurl.com}
\end{itemize}
\lipsum[2]
\begin{itemize}
    \item Maybe this helps? \nolinkurl{www.line\-break.com}
\end{itemize}
\end{document}

The issues with this are shown below. Does anyone know a way to achieve what I want, or a clever workaround?

issues

  • Add \usepackage{xurl} to your preamble. – leandriis Jul 12 at 18:28
2

The xurl package allows urls to be broken between any character. Adding it to the preamble results in the following output:

enter image description here

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{xurl}
\usepackage[breaklinks=true]{hyperref}
\begin{document}
    \lipsum[1]
\begin{itemize}
    \item \nolinkurl{www.someshorturl.com}, \nolinkurl{yetanotherurlthatislongandshouldbebrokenintoseverallines.com}, \nolinkurl{www.averyveryveryverylongurl.com}
\end{itemize}
\lipsum[2]
\begin{itemize}
    \item Maybe this helps? \nolinkurl{www.line\-break.com}
\end{itemize}
\end{document}
| improve this answer | |

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.