[Tex/LaTex] beamer hyperref url with %20 runaway argument


I want to use a URL in beamer notes. If the URL includes a %20 it seems to cause xelatex trouble.



 \note{\href{http://www.example.com/A%20B%20C.pdf}{some text}}


Gives the following error:

Runaway argument?
\note {\href {http://www.example.com/A\end {frame} \par \end {documen\ETC.
! File ended while scanning use of \frame.
<inserted text>
<*> test


Looking at other questions on this site seems to suggest that the use of %20 is OK in a link, so I am not sure what to do. I want a %20 rather than a space.

Best Answer

There is no problem, generally, when

\href{http://www.example.com/A%20B%20C.pdf}{some text}

appears by itself, that is, not in the argument to a macro, because \href suspends the usual TeX's reading rules when absorbing the URL. However, something like

\mbox{\href{http://www.example.com/A%20B%20C.pdf}{some text}}

would give troubles (\mbox is used to stand for any command with argument) because TeX's reading rules are not suspended when \mbox absorbs its argument.

In this case, you can escape the percent character:

\mbox{\href{http://www.example.com/A\%20B\%20C.pdf}{some text}}

because \href knows how to transform \% in a real percent character when making the internal URL.

On the other hand, with beamer you cannot use the “naked” form, because the contents of a frame environment is absorbed as if it were the argument to a macro, so it would be the same as in the \mbox situation. Nevertheless, the input

\note{\href{http://www.example.com/A\%20B\%20C.pdf}{some text}}

should work.

As an aside, take the habit of typing \end{frame} without any space before it in the same line, because if you add the fragile option to \begin{frame}, a space before \end{frame} would produce weird errors.