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.

I want to footnote a URL which contains mathematical signs such as = and LaTeX asks me for a $ sign to take it to mathematical space (and therefore changing the font which is not suitable). How should I overcome this situation, i.e. put url in footnotes without using a $ sign and evading mathematical space?

share|improve this question
5  
Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Nicola Talbot May 24 at 17:44
2  
Please indicate whether you're loading package such as url and/or hyperref that provide a macro called \url. –  Mico May 24 at 17:59

2 Answers 2

The most straightforward and flexible approach to typesetting URL strings is to use the \url macro that's provided by the url and hyperref packages. I use the word "flexible" in part because \url{...} can usually find good line breaks -- an important consideration when dealing with long URL strings (which occur quite frequently, right?). Outside of footnotes, just about any and all of TeX's "special characters" (including %) can feature in a URL string that's encased by \url{...}.

However, due to some fairly deep-seated restrictions on what can be typeset by LaTeX in a footnote, you'll find that you cannot use \url inside footnotes if the URL string contains the % (comment) character.

You have two options if the URL string does contain one or more % characters:

  • Load the fancyvrb package, execute \VerbatimFootnotes after \begin{document}, and typeset the URL stringin the footnote using the \Verb (note the uppercase V) macro.

    Upside: pretty much all characters are allowed. Downsides: automatic line breaking of long URL strings not possible, and URL string won't be made into a hyperlink if the hyperref package is loaded.

  • Use the \urldef directive (also provided by the url package) outside the footnote to define a "robust" macro that contains the URL string, and then use this robust macro inside the footnote itself.

    Upsides: can use just about all characters, and preserve ability to break lines automatically. Downside: must remember to use \urldef before getting to the footnote.

enter image description here

\documentclass{article} 
\usepackage{url,fancyvrb}
\setlength\textheight{3cm} % just for this example
\begin{document}
\VerbatimFootnotes % enable use of \Verb in footnotes

%% specify a URL string that contains '%' characters
\urldef{\myurl}\url{http://!@#$^&*%_=+<>%}

Some text.\footnote{Using \Verb+\url+: \url{http://!@#$^&*_=+<>}.}

More text.\footnote{Using \Verb+\Verb+: \Verb|http://!@#$^&*%_=+<>%|.}

Yet more text.\footnote{Using \Verb+\urldef+: \myurl.}
\end{document}
share|improve this answer
1  
+1 I would stick to \urldef, it's the clear and consistent way IMHO. –  tohecz May 24 at 19:33
1  
@tohecz - The advantages of \urldef would certainly seem to outweigh its disadvantage of having to remember to use it before entering the footnote material. –  Mico May 24 at 19:38

As Trefex pointed out, you can use the special symbols by escaping them with \. Nevertheless, a most elegant solution would be to load the url package.

Once you have called it in your preamble (\usepackage{url}) you should be able to use urls anywhere with any special characters (_, $, #, etc.)

share|improve this answer
1  
A limitation of using \url is that you can't have URL strings containing % (comment) characters if they need to be typeset in footnotes -- as is the case with the OP's issue. Two workarounds: \Verb (from the fancyvrb package), or pre-define a "robust" macro that contains the URL string using \urldef before entering the footnote zone. –  Mico May 24 at 19:24
    
Really? Thanks for the head's up :) I'll exclude % from the answer –  Mario S. E. May 24 at 21:20

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.