0

I have a link that has a # sign in it. If I typeset it using \url{...} it throws an "Illegal parameter..." error. But if I put a backslash in front of \#, even though it would typeset correctly, the URL would no longer work. The page that is opened actually has a %23 where the # in the link should be and therefore leads me to the wrong page.

Here's is a MWE, I had to use the xurl package as my URL is too long but does not have hyphens in it to allow for breaks at hyphens with just [hyphens]{url}. Also, if I don't include the hyperref package, somehow LaTex does not recognize the links after the line break as part of the entire link.

\documentclass[12pt,letterpaper]{article}
\usepackage[hyphens,spaces,obeyspaces]{url}
\usepackage{xurl}
\usepackage{hyperref}

\begin{document} here is the site: \url{https://github.com/openjdk/jdk/blob/de54eb15130848d4efc266891e41b978f444f9f3/src/java.base/share/classes/java/util/DualPivotQuicksort.java#L216} \end{document}

After typesetting, you can click on the URL to see that it leads to a 404 page, but if you replace the %23 toward the end of the link with a #, you can see the actual page I am trying to get to. So somehow when I click on the link, the \# gets interpreted to be %23 in the web browser. I am using Chrome if this matters, and am compiling with TeXSHop on MacOS.

Any fixes for this bug?

Carina Chen
  • 103
  • 6
  • 3
    In the MWE it would be possible (and better) not to escape # to \#. \url{https://github.com/openjdk/jdk/blob/de54eb15130848d4efc266891e41b978f444f9f3/src/java.base/share/classes/java/util/DualPivotQuicksort.java#L216} should work just as well. – moewe Oct 30 '20 at 19:36
  • 2
    Your MWE (with # or with \#) works fine for me in TeXworks' PDF viewer and SumatraPDF (Win 10). Which viewer did you use? Do use use Mac OS? (There are some bugs with some PDF readers on Mac OS that don't properly deal with some special characters in URLs.) – moewe Oct 30 '20 at 19:37
  • @moewe In the MWE, indeed not escaping # does not cause a problem. However, in my original document which is very long, it does throw an illegal parameter error possibly clashing with other preambles. Regardless of escaping or not escaping, the link gets opened to the wrong page with %23 replacing where the # should be. and Indeed I am using Mac OS. It's the pdf viewer that comes with TeXShop. Is there a way of fixing the viewer? – Carina Chen Oct 30 '20 at 19:41
  • Apart from reporting the bug to Apple and hoping they fix it, there is little you can do. See also https://github.com/latex3/hyperref/issues/110, https://tex.stackexchange.com/q/526207/35864, https://tex.stackexchange.com/q/555559/35864. – moewe Oct 30 '20 at 19:45
  • @moewe many thanks! – Carina Chen Oct 30 '20 at 19:50

0 Answers0