4

In a document I want to do a reference to a specific section of an online documentation. Here is the link:

\documentclass{report}

\usepackage{hyperref}

\begin{document}

\href{https://raytracing-docs.nvidia.com/optix_6_0/guide_6_0/index.html\#host\#graph-nodes}{NVidia}

\end{document}

As you can see there is two #. If don't escape both of them I've got this error:
! Illegal parameter number in definition of \Hy@tempa.

But if I escape both, the part of the link after second one is not taken into account.

How can I make the link works properly?

5
  • Dpn't show only a snippet. Make a complete example that can be used for tests. Apr 23, 2020 at 9:09
  • @UlrikeFischer done
    – Phantom
    Apr 23, 2020 at 9:15
  • Hi @Phantom, your working example is successfully compiling without errors for me. (even after i have deleted the escapes. by the way, you may delete them in your MWE so people have the code producing your problem and not containing your hotfix)
    – katexochen
    Apr 23, 2020 at 9:22
  • 2
    Oh well. Why do people do this and use such reserved chars? Well hyperref drops the second part somewhere. Add an issue to the github tracker of hyperref. Apr 23, 2020 at 9:49
  • If you link to ...html#graph-nodes instead of ...html#host#graph-nodes you will land on the exact same spot in the documentation. This is also true for every other section or subsection of that page.
    – katexochen
    Apr 23, 2020 at 10:15

2 Answers 2

5

Try this (hopefully there is nowhere a link with two consecutive hashes)

Addition: while with the patch the "correct" link is in the pdf, the comments suggest that not every pdf viewer is able to handle this. So better look for an alternative link which doesn't use two hashes.

\documentclass{report}
\usepackage{hyperref}
\makeatletter
\begingroup
  \catcode`\$=6 %
  \catcode`\#=12 %
  \gdef\href@$1{\expandafter\href@split$1###\\}%
  \gdef\href@split$1#$2##$3\\$4{%
    \hyper@@link{$1}{$2}{$4}%
    \endgroup
  }%
\endgroup
\makeatother
\begin{document}
\makeatother
\href{https://raytracing-docs.nvidia.com/optix_6_0/guide_6_0/index.html#host#graph-nodes}{NVidia}

\end{document}

6
  • Doesn't work for me.
    – egreg
    Apr 23, 2020 at 10:03
  • Works fine for me, thanks
    – Phantom
    Apr 23, 2020 at 10:03
  • @egreg what do you mean by doesn't work? If I uncompress the pdf (l3pdf + \pdf_uncompress I get the link with both hashes in the pdf URI(https://raytracing-docs.nvidia.com/optix_6_0/guide_6_0/index.html#host#graph-nodes). And in adobe reader the link works. Apr 23, 2020 at 10:06
  • I tried with Skim and Acrobat Reader, both point to incorrect links. Acrobat Reader shows the correct link, but upon clicking it takes me to another page. With Skim I get the %23 notation, but again, this is interpreted incorrectly.
    – egreg
    Apr 23, 2020 at 10:07
  • @egreg does the link work if you use it directly in your browser? Apr 23, 2020 at 10:58
0

Since I stumbled upon the same problem and opened a hyperref issue, I wanted to share the developer's reply here:

Apparently, more than one # character is not a correct URI and the solution is to replace all but the first # by %23, i.e., in your example

\href{https://raytracing-docs.nvidia.com/optix_6_0/guide_6_0/index.html\#host\%23graph-nodes}{NVidia}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .