10

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}
Hello World\endnote{\url{http://www.rossettiarchive.org/docs/nb0005.duke.rad.html#0.1.19}}
\end{document}
6
  • 4
    Your code works OK in my system. What error do you get? What version of LaTeX system are you using? Commented Jul 21, 2012 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?" Commented Jul 21, 2012 at 19:55
  • Did you get that error with the exact code you posted in your question? Commented Jul 21, 2012 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 Commented Jul 21, 2012 at 20:07
  • 1
    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. Commented Jul 21, 2012 at 20:25

1 Answer 1

9

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}
\urldef\rossetti\url|http://www.rossettiarchive.org/docs/nb0005.duke.rad.html#0.1.19|


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .