1

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.

  • I'm not sure why it should be better to use the package options than to just use \g@addto@macro{\UrlBreaks}{\UrlOrds} as described in this post, which can be placed anywhere and doesn't need complicated package ordering. I'm not an expert, but just another user trying to figure out the most robust way of doing this. – user21820 Aug 9 '19 at 1:47
  • @user21820 Good remark. Actually I have never considered that option. Good to know it could be working for this use case. Have you been able to test it successfully for this example? – wget Aug 10 '19 at 13:39
  • I did not test your example, but it worked for me after \usepackage{hyperref}. I have a ton of packages so I like to minimize the ordering constraints needed. I hope never to come to a day when the ordering required is not a linear order. – user21820 Aug 10 '19 at 15:51
6

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.

  • 2
    You don't have to move hyperref before biblatex. It is enough to move the \PassOptionsToPackage{hyphens}{url}. – Ulrike Fischer Apr 9 '15 at 10:10
  • @UlrikeFischer Yes, you were right. On my side, I needed to put it before because I was using menukeys and the compilation fails if hyperref is declared after menukeys. – wget Apr 9 '15 at 10:30
  • 1
    Then it is better to move menukeys. It is always better not to move hyperref before another package if it is not really needed. – Ulrike Fischer Apr 9 '15 at 10:47
  • 1
    Just so future visitors reading the above know: menukeys is no longer required to be loaded after hyperref. – Skillmon Dec 19 '20 at 15:29
  • 1
    @wget yes (but no). It loads xparse, xstring, etoolbox, tikz, xcolor, adjustbox, relsize, kvoptions. If you need any of those packages (or their dependencies) with specific options you have to load them earlier. But else the load order shouldn't matter. – Skillmon Dec 20 '20 at 16:54

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.