I cannot seem to create a hyperlink to a specific line of a file on GitHub with the \url
or \href
commands. The following returns a 404 page:
\documentclass{article}
\usepackage{url}
\begin{document}
\url{https://github.com/SeSodesa/zeffiro_interface/blob/49fb5f652134e869c93809f05fbd70f0a730bbc4/m/forward_scripts/brain/lead_field_eeg_fem.m#L167}
\end{document}
I've traced this down to the fact that both \url
and \href
seem to replace the line number symbol #
with its URL encoded counterpart %23
, but GitHub does not understand this in the context where it happens. When I replace the %23
with a #
in the generated link, the URL works again.
My question then is, how do I fix this? The link is rather ugly and ends up flowing over page boundaries, so I would like to replace it with a short description via \href
but still have a functioning link.
Edit: I think the problem might be the fact that the link is inside of a footnote. The code
\usepackage{url}
\begin{document}
\footnote{\url{https://github.com/SeSodesa/zeffiro_interface/blob/49fb5f652134e869c93809f05fbd70f0a730bbc4/m/forward_scripts/brain/lead_field_eeg_fem.m#L167}}
\end{document}
produces the error
! Illegal parameter number in definition of \Hy@tempa.
<to be read again>
When the number sign #
is escaped, there is no error, but the link produced by \url
does not function: https://github.com/SeSodesa/zeffiro_interface/blob/49fb5f652134e869c93809f05fbd70f0a730bbc4/m/forward_scripts/brain/lead_field_eeg_fem.m%23L167.
Edit 2: Looks like the link actually works in Adobe Acrobat... I was using Skim to read the document.
xurl
for a better linebreaking. But it also works for me using TL22 and Evince as the PDF viewer. With and withouthyperref
\urldef
: tex.stackexchange.com/q/394807/35864. Related: tex.stackexchange.com/q/12855/35864