Biblatex – Forcing Linebreaks in \url Does Not Work with Biblatex and Menukeys

biblatexhyperrefurls

This question is related to “Forcing linebreaks in \url. One of its answer is to pass the hyphens option to the url package:

\PassOptionsToPackage{hyphens}{url}
\usepackage{hyperref}

As I have my own class file, I adapted the commands to be:

\PassOptionsToPackage{hyphens}{url}
\RequirePackage{hyperref}

However, the line \PassOptionsToPackage{hyphens}{url} is clashing on my side and I got this error message: Option clash for package url. \let.

Then, I tried to replace that line with \requirePackage[hyphens]{url}, but since hyperref already defines implicitly url, I got the error Option clash for package url. \RequirePackage.

I even tried the hyperref package option breaklinks=true but this did not help and the latter is reported to only work with slashes not dashes like I want.

Any idea? What could be the issue, where do I need to look for? I don't understand, the aforementioned command is reported to work fine by others, while on my side this is not working.

Best Answer

After some time of debug, I finally found what was wrong or actually the package responsible for that malfunction. I was using BibLaTeX, and as the following minimal working examples prove it, we have to declare the line \PassOptionsToPackage{hyphens}{url} before BibLaTeX is declared.

Working example, links packages are declared before :

\documentclass[twoside]{report}
\usepackage[margin=2cm]{geometry}
\usepackage{parskip}
\PassOptionsToPackage{hyphens}{url}
\usepackage[backend=biber,sorting=none,alldates=short]{biblatex}
\addbibresource{references.bib}
\usepackage{hyperref}
\begin{document}
Some very long URL: \url{http://subdomain.example.org/thread/Some-Great-Products/A-super-great-product-with-a-dedicated-page/number/322866/highlight/true\#M8821}
\end{document}

Non working one, links packages are declared after :

\documentclass[twoside]{report}
\usepackage[margin=2cm]{geometry}
\usepackage{parskip}
\usepackage[backend=biber,sorting=none,alldates=short]{biblatex}
\addbibresource{references.bib}
\PassOptionsToPackage{hyphens}{url}
\usepackage{hyperref}
\begin{document}
Some very long URL: \url{http://subdomain.example.org/thread/Some-Great-Products/A-super-great-product-with-a-dedicated-page/number/322866/highlight/true\#M8821}
\end{document}

Also, I was using menukeys and I realized the compilation was failing on the line \PassOptionsToPackage{hyphens}{url} if menukeys was declared before hyperref. Moving menukeys after hyperref solved the issue.

Hope this could help others.