# url not working in footnotes - seems to require escape characters, but

I use \url which does not require to escape characters in an URL to make them acceptable for latex (specifically LuaLaTex). However when the same reference is included in a footnote, characters (especially _ and % seem to required escaping. Am I missing somehting?

Here a MWE:

\documentclass[]{article}

\usepackage{url}

\begin{document}

Phoenizisch \url{https://de.wikipedia.org/wiki/Unicodeblock_Ph%C3%B6nizisch}
and more text
with the same ref in a footnote%
\footnote{some text with the same url
\url{{https://de.wikipedia.org/wiki/Unicodeblock_Ph%C3%B6nizisch}}
and a closing text.}%
. After the footnote

\end{document}


which does not compile with the error

File ended while scanning use of \@footnotetext.


It does, of course, compile and produce output as expected if the offending url in the footnote is removed. Note that the same url in the body is processed correctly. I assume that there is an interaction between \footnote and \url.

What is the best solution or workaround?

• Have you tried \protect\url otherwise see the manual for the url package, the url command is fragile (afair) Jun 14 '19 at 18:06
• \url changes the category-code-régime (beneath other things it changes the category codes of _ and %) and "hopes" for its argument to be read from the .tex-input-file and tokenized under that changed category-code-régime. But the \url-command is cheated out of this hope in case of \url{...} being part of the argument of a \footnote-command because in this case things already got tokenized under normal/unchanged category-code-régime when the argument of the \footnote-command got read from the .tex-input-file and tokenized. Jun 14 '19 at 19:13

Well, you can use command \urldef{\urlB} to define the url you need and use \urlB to insert the wanted url into the footnote. That is also usable in normal text ...

\documentclass[]{article}

\usepackage{url}
\urldef{\urlA}\url{https://de.wikipedia.org/wiki/Unicodeblock_Ph%C3%B6nizisch} % <========
\urldef{\urlB}\url{https://de.wikipedia.org/wiki/Unicodeblock_Ph%C3%B6nizisch} % <========

\begin{document}

Phoenizisch \urlA\  % <=================================================
and more text
with the same ref in a footnote%
\footnote{some text with the same url
\urlB\  % <===================================================
and a closing text.}%
. After the footnote

\end{document}


and its result:

and the normal text:

• Thank you - I will use this solution, it solves the probem, but I still feel this is not a proper solution for a common problem when writing (putting URLs in footnote seems to strike a decent balance between pointing to your sources and not disturbing the flow of text). Latex should have a "proper" solution! Jun 15 '19 at 9:49

You can simply use "" before the characters like "_,%,#" when you use "\href" and/or "\url" in a footnote. So, you can use the following code,

\documentclass[]{article}

\usepackage{url}

\begin{document}

Phoenizisch \url{https://de.wikipedia.org/wiki/Unicodeblock_Ph%C3%B6nizisch}
and more text
with the same ref in a footnote%  \footnote{some text with the same url
\url{{https://de.wikipedia.org/wiki/Unicodeblock\_Ph\%C3\%B6nizisch}}
and a closing text.}%
. After the footnote

\end{document}