# Link with multiple # does not work properly

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?

• Dpn't show only a snippet. Make a complete example that can be used for tests. Apr 23 '20 at 9:09
• @UlrikeFischer done Apr 23 '20 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) Apr 23 '20 at 9:22
• 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 '20 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. Apr 23 '20 at 10:15

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}


• Doesn't work for me. Apr 23 '20 at 10:03
• Works fine for me, thanks Apr 23 '20 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 '20 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. Apr 23 '20 at 10:07
• @egreg does the link work if you use it directly in your browser? Apr 23 '20 at 10:58