I want to use the following footnote:
\footnote{http://msdn.microsoft.com/en-us/library/ee804826%28Surface.10%29.aspx}
But the problem is since there are % symbols in the link, it is recognized as a comment. How can I avoid that?
footnotes
I want to use the following footnote:
\footnote{http://msdn.microsoft.com/en-us/library/ee804826%28Surface.10%29.aspx}
But the problem is since there are % symbols in the link, it is recognized as a comment. How can I avoid that?
The trick is to move code used by hyperref
for setting the footnote anchor/target as part of the footnote text (so after the footnote mark has been 'drawn') into the code for defining the 'footnote' part of the footnote mark! (The footnote mark is used twice for every footnote, once in the text and once in the footnote itself; I am referring to the latter here.)
Default LaTeX makes no distinction between the two footnote marks, which may be why hyperref
originally does things this way around. footnotebackref
does make the distinction in some sense, but not in a way we can cleanly patch, so we undo their changes and patch them back in using our method (I copied the code for this from the current version of footnotebackref
, so this may get out of sync).
The following code should work whether or not footnotebackref
is used (but if it is used, it must be loaded before this patch). hyperref
must also be loaded before this patch. Original definitions of \@makefnmark
are preserved except when footnotebackref
is used, which clobbers them anyway.
\documentclass{article}
% comment/uncomment various combinations of these for testing
%\PassOptionsToPackage{symbol=$\wedge$}{footnotebackref}
%\PassOptionsToPackage{numberlinked=false}{footnotebackref}
\usepackage{footnotebackref}
\usepackage{hyperref}
\makeatletter
% distinguish between footnote marks in the text and in the footnotes themselves!
\let\hyperfoot@oldmakefntext\@makefntext
\renewcommand*{\@makefntext}{%
\let\hyperfoot@base@makefnmark\@makefnmark
\let\@makefnmark\hyperfoot@infootnote@makefnmark
\hyperfoot@oldmakefntext}
% set the hypertarget (through \hyper@@anchor) before placing \@thefnmark
\newcommand*{\hyperfoot@infootnote@makefnmark}{%
\fn@settarget
\hyperfoot@base@makefnmark
}
\@ifpackageloaded{footnotebackref}{%
\ifFootnoteBackref@numberlinked
\let\hyperfoot@oldmakefntext\BHFN@OldMakefntext% undo their patch
\renewcommand\hyperfoot@infootnote@makefnmark{%... and merge with ours
\fn@settarget
\mbox{\textsuperscript{\normalfont%
\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}\,}%
\fi
}{}
% reset hyperref's overriding of \@footnotetext, which basically just adds the \hyper@@anchor as part of the footnote text
\long\def\@footnotetext#1{%
\H@@footnotetext{#1}}
% and put the hyperref magic into \fn@settarget instead
% note that we set the anchor text to be \relax. previously, it was sometimes (=when allowing links to be nested) the footnote text. I don't actually know what the effect is of having anchor text... but apparently no drivers support nesting at the moment anyway.
\newcommand\fn@settarget{% a form of this was previously part of hyperref's \@footnotetext
%\message{^^J^^J**setting target!**^^J^^J}% we should only see as many 'setting target' messages in the log as there are footnotes!
\ifHy@nesting
\expandafter\ltx@firstoftwo
\else
\expandafter\ltx@secondoftwo
\fi
{%
\expandafter\hyper@@anchor\expandafter{%
\Hy@footnote@currentHref
}{\relax}%
}{%
\Hy@raisedlink{%
\expandafter\hyper@@anchor\expandafter{%
\Hy@footnote@currentHref
}{\relax}%
}%
\let\@currentHref\Hy@footnote@currentHref
\let\@currentlabelname\@empty
}%
}
% following makes testing slightly easier on my monitor
\hypersetup{pdfstartview={XYZ null null 4}}
\textheight=3cm
\begin{document}
Text\footnote{The first footnote.} Text.
Let's have more than one footnote!\footnote{For better testing!}
\end{document}
You can't use \footnote
inside a box. For example, the following won't produce the footnote text:
\fbox{Some text\footnote{with a footnote}}.
Instead you need to use a combination of \footnotemark
and \footnotetext
like this:
\fbox{Some text\footnotemark}\footnotetext{with a footnote}
Applying this to a glossary entry is complicated but can be done:
\documentclass[11pt]{report}
\usepackage[pdftex,pagebackref]{hyperref}
\usepackage[acronym,toc,section=chapter,style=indexgroup,sanitize={name=false,description=false,symbol=true}]{glossaries}
\glsdisablehyper
\defglsdisplayfirst[main]{#1#4\protect\footnote{#2}}
\makeglossaries
\newglossaryentry{Y2K}{name=Y2K,description={Bla bla bla}}
\begin{document}
\fbox{Bla bla \glstext{Y2K}\ifglsused{Y2K}{}{\footnotemark} bla
bla}\ifglsused{Y2K}{}{\footnotetext{\glsentrydesc{Y2K}}\glsunset{Y2K}}
\newpage
\printglossaries
\end{document}
For a more automated solution you could do:
\documentclass[11pt]{report}
\usepackage{etoolbox}
\usepackage[pdftex,pagebackref]{hyperref}
\usepackage[acronym,toc,section=chapter,style=indexgroup,sanitize={name=false,description=false,symbol=true}]{glossaries}
\glsdisablehyper
\defglsdisplayfirst[main]{#1#4\protect\footnote{#2}}
\makeglossaries
\newglossaryentry{Y2K}{name=Y2K,description={Bla bla bla}}
\newcommand\glsdoafterbox{}
\let\orgfbox\fbox
\def\fbox#1{\orgfbox{#1}\glsdoafterbox\def\glsdoafterbox{}}
\newcommand{\boxedgls}[1]{%
\glstext{#1}%
\ifglsused{#1}{}%
{%
\footnotemark
\gappto\glsdoafterbox{\footnotetext{\glsentrydesc{#1}}\glsunset{#1}}%
}%
}
\begin{document}
\fbox{Bla bla \boxedgls{Y2K} bla bla}
\newpage
\printglossaries
\end{document}
Best Answer
Isn't it enough to simple escape the % with \ or am I missing something here? That is: