# How to include a # sign in a url using the \endnotes package

I am trying to include a URL in my Latex document which contains a pound sign, #, in it. If I run it without escaping the # sign, I get an error. If I escape it, then the escape character is printed out in the URL also. ("\#" instead of "#") Any ideas on how to fix this?

\documentclass[12pt, a4paper, twoside]{article}
\usepackage[T1]{fontenc}
\usepackage{endnotes}
\usepackage{url}
\begin{document}
\end{document}

-
Your code works OK in my system. What error do you get? What version of LaTeX system are you using? – Gonzalo Medina Jul 21 '12 at 19:26
I am using TexStudio and I get "Illegal Parameter number in definition of" then url string. The log file says "you meant to type ## instead of # right?" – Mike Stumpf Jul 21 '12 at 19:55
Did you get that error with the exact code you posted in your question? – Gonzalo Medina Jul 21 '12 at 19:59
add \listfiles and see what you get, it works for me and I get: File List article.cls 2007/10/19 v1.4h Standard LaTeX document class size12.clo 2007/10/19 v1.4h Standard LaTeX file (size option) fontenc.sty t1enc.def 2005/09/27 v1.99g Standard LaTeX file url.sty 2006/04/12 ver 3.3 Verb mode for urls, etc. t1cmtt.fd 1999/05/25 v2.5h Standard LaTeX font definitions – David Carlisle Jul 21 '12 at 20:07
In case it turns out that it's something TeXStudio does to the \footnote command, say, then defining a command for typesetting the url first using \urldef might help. – Harald Hanche-Olsen Jul 21 '12 at 20:25

As you noticed, the # confuses TeX, because the endnotes are eventually read in as a macro replacement text.

Use \urldef for the problematic entry:

\documentclass[12pt, a4paper, twoside]{article}
\usepackage[T1]{fontenc}
\usepackage{endnotes}
\usepackage{url}

\begin{document}
Hello World\endnote{\rossetti}
\end{document}


Alternative way: put this in the preamble

\newcommand\specialendnote{\begingroup\catcode\#=12 \specialendnoteaux}
\newcommand\specialendnoteaux[1]{\endnote{#1}\endgroup}


and call

\specialendnote{\url{http://www.rossettiarchive.org/docs/nb0005.duke.rad.html#0.1.19}}
`
-
Thank you, it worked perfectly! – Mike Stumpf Jul 22 '12 at 20:52