3

Consider the following MWE (borrowed from this question):

\documentclass{beamer}

\begin{document}

\begin{frame}

\href{http://tex.stackexchange.com/q/20800/5701}{Link}

\end{frame}

\end{document}

Such a MWE compiles without errors, yielding the expected output. Consider now this MWE, in which I have only changed the link for a Google Scholar link:

\documentclass{beamer}

\begin{document}

\begin{frame}

\href{https://scholar.google.com/scholar?q=equilibrium+points+in+n-person+games&hl=en&as_sdt=0,5#}{Link}

\end{frame}

\end{document}

Now, the MWE compiles with a few errors. Why does changing the link break href? How to stop this from happening?

EDIT! I see two options proposed in the answers: one is to escape the character # and the other one is to add [fragile] to my frame. Can any TeX expert tip the balance in favour of either option? What is the most Tex-y to do?

EoDmnFOr3q
  • 2,299
  • 3
    use \begin{frame}[fragile] – Ulrike Fischer Dec 21 '22 at 10:22
  • 1
    my argument is that this happens very often with many links due to anchor using # in the url. So, to me, this question isn't strictly beamer dependant. – anis Dec 21 '22 at 10:28
  • 2
    @anis It is strictly beamer dependent due to the way beamer parses the frame environment. It will work without error in normal classes in which the link isn't enclosed in an environment which is parsed multiple times, e.g. `\documentclass{article} \usepackage{hyperref}

    \begin{document} \href{https://scholar.google.com/scholar?q=equilibrium+points+in+n-person+games&hl=en&as_sdt=0,5#}{Link} \end{document} `

    – samcarter_is_at_topanswers.xyz Dec 21 '22 at 10:31
  • 1
    @Hector What's not clear to me is why you need the # at the end at all? The link seems to give the same result with or without it. – samcarter_is_at_topanswers.xyz Dec 21 '22 at 10:34
  • 1
    @anis: hyperref handles links with # fine as long as you don't use such links in the argument of another command (as is done here in \frame). – Ulrike Fischer Dec 21 '22 at 10:46
  • 2
    @Hector: escaping is faster, but handles only the #. Using fragile will also allow you to use % in the link, and to use verbatim and listings in the frame. – Ulrike Fischer Dec 21 '22 at 10:49
  • I just realised that I do not need the # at the end of my link as it works just fine without it; but I did not know this when I copied-pasted the Google Scholar link from the address bar. – EoDmnFOr3q Dec 21 '22 at 11:05
  • In a nutshell, escaping is faster and more general. right? – anis Dec 21 '22 at 12:18

2 Answers2

4

The problem is the # at the end of your link. You can work around it by using a fragile frame:

\documentclass{beamer}

\begin{document}

\begin{frame}[fragile]

\href{https://scholar.google.com/scholar?q=equilibrium+points+in+n-person+games&hl=en&as_sdt=0,5#}{Link}

\end{frame}

\end{document}

1

There is a # in the second link. Escaping that character solves it : \#

anis
  • 1,510
  • 5
  • 13