# Why is docstrip putting extra macro calls in a hyperlink inside a footnote that has a tilde?

Here's a minimal example of Docstrip putting extra macro bits into a \href call inside a footnote when the URL has a tilde:


% \iffalse
\documentclass[a4paper]{ltxdoc}
\usepackage{hyperref}
\begin{document}
\DocInput{foo.dtx}
\end{document}
% \fi

% \title{The foo package\thanks{This document corresponds to
%     foo version, dated date.}}
%
%     \href{http://example.com/user}{foo}} }
%
% \maketitle
%
% \section{Introduction}
%
% a link that works: \href{http://example.com/~user}
%     {foo}.


In the resulting PDF, the tilde in the URL in the footnote has some TeX macros in it you get:

http://example.com/\protect \unhbox \voidb@x \penalty \@M \ {}user/


so something is wrong with the tilde. How can I fix this?

-

\href and friends have to do some magic to make special characters like # or ~ work. This magic works only if the commands are used outside of any other commands. But the hyperref package accepts “escaped” versions as well: \#, \~ and so on. They work in any case and are a bit easier to remember than commands like \textasciitilde.

This is actually independent of docstrip, the following example exhibits the same behavior:

\documentclass{article}
\usepackage{hyperref}
\title{Test}
\author{Me\footnote{\url{http://example.com/~}}}
\begin{document}
\maketitle
\url{http://example.com/~}
\end{document}

-

I have to admit that I have no idea why this is happening. However, replacing the literal tilde with \textasciitilde will fix your problem.

% \author{The Author\thanks{Author's website with bad link: