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.

7
  • Works fine for me … PDF compiles and links correctly. If # actually works as an anchor, it must not be written as %23. Since it's working for me, perhaps your PDF reader does it?
    – Ingmar
    Commented Jun 3, 2022 at 8:28
  • 1
    I would probably use xurl for a better linebreaking. But it also works for me using TL22 and Evince as the PDF viewer. With and without hyperref
    – daleif
    Commented Jun 3, 2022 at 8:35
  • Looks like footnotes might have something to do with the issue. I've edited the post with more details.
    – sesodesa
    Commented Jun 3, 2022 at 9:31
  • 1
    you are on mac aren't you? It is a bug in some of their viewers and hyperref can do nothing about it. See github.com/latex3/hyperref/issues/110 Commented Jun 3, 2022 at 9:54
  • 1
    The safest way to use URLs in footnotes is via \urldef: tex.stackexchange.com/q/394807/35864. Related: tex.stackexchange.com/q/12855/35864
    – moewe
    Commented Jun 3, 2022 at 10:11

1 Answer 1

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}
1
  • 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
    Commented Jun 3, 2022 at 9:44

You must log in to answer this question.

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