2

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.

A 404 page generated by the command \url.

Edit 2: Looks like the link actually works in Adobe Acrobat... I was using Skim to read the document.

Ingmar
  • 6,690
  • 5
  • 26
  • 47
sesodesa
  • 753

1 Answers1

1

According to the docs, the \url argument cannot contain any %, #, or ^^, or end with \ if used in the argument to another command.

That said, this actually worked for me (Sumatra PDF Reader):

\documentclass{article}

\usepackage{xurl,hyperref}

\begin{document} Test\footnote{\url{https://github.com/SeSodesa/zeffiro_interface/blob/49fb5f652134e869c93809f05fbd70f0a730bbc4/m/forward_scripts/brain/lead_field_eeg_fem.m#L167}}

\end{document}

Ingmar
  • 6,690
  • 5
  • 26
  • 47
  • 1
    It occurred to me to try another reader instead of Skim, and it turns out that Adobe Acrobat generates a functioning link, when I escape the # with a backslash. I guess I need to file a bug report to Skim developers. – sesodesa Jun 03 '22 at 09:44