# hash-tag in \href causes error

I'm creating a beamer presentation. I want to put a link to a source which has a hash-tag in it (#). When I try to compile this I get an error:

! Illegal parameter number in definition of \test.
}
l.91 \end{itemize}
% ends low level
? x


This is the line I'm using:

\href{http://highered.mcgrew-hill.com/classware/ala.do?isbn=0072956208&alaid=ala_1500202&showSelfStudyTree=true#}{source}


Is there a way around this?

• This \href line is ok. Find out which piece of code actually causes the error and post that here. Feb 16, 2012 at 9:43
• The frame should be marked as fragile: \begin{frame}[fragile]. On the other hand, a hash symbol at the end of a link appears to be ignored. Feb 16, 2012 at 11:17
• @egreg: That is hyperref's rule, for good reason. \href@ $1->\expandafter \href@split$1##\$1<-http://example.com/ala.do?foo=bar&showSelfStudyTree=true# {\expandafter} \href@split$1#$2#$3\\$4->\hyper@@link {$1}{$2}{$4}\endgroup $1<-http://example.com/ala.do?foo=bar&showSelfStudyTree=true$2<- $3<-#$4<-source Feb 16, 2012 at 19:04

Be careful to escape the hash character #:

\href{http://example.com/ala.do?foo=bar&showSelfStudyTree=true\#}{source} % # truncated


I have to admit that in this case (hash at the very end of the link), this achieves successful compilation, but the hash character is lost upon opening the link from my pdf-viewer (evince). If the hash is somewhere inside the link, it is preserved:

\href{http://example.com/ala.do?showSelfStudyTree=true\#&foo=bar}{source} % # perserved

• Thanks. Turns out that I can simply remove the has and the link still works Feb 16, 2012 at 11:40

I created a normal article (not a beamer presentation), and for some reasons could not use \href with a hash (even with escaping). A LaTeX forum suggested that \url can be used instead (which worked for me):

\url{http://highered.mcgrew-hill.com/classware/ala.do?blahblah=true#}


I had an URL with two # signs in it (a matrix server link). The second one was ignored even with escaping. What worked for me: replace the second occurrence with its urlencoding value:

\href{https://example.com/foo\#bar\%23baz}{https://example.com/foo\#bar\#baz}