7

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.}}
%
% \author{The Author\thanks{Author's website with bad link:
%     \href{http://example.com/~user/} {foo}. Working link:
%     \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?

6

\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}
7

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:
%     \href{http://example.com/\textasciitilde user/}{foo}. Working link:
%     \href{http://example.com/user}{foo}} }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.