Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

\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}
share|improve this answer
add comment

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}} }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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