1

I have a footnote with a long url containing an underscore, like this:

\footnote{\url{http://www.example.com/somethinglong_somethingotherlong}}

The link appears in the pdf, but it is broken off after the underscore and redirects to http://www.example.com/somethinglong_, which of course gives a page not found error.

How do I solve this? Adding a \ before the underscore doesn't do anything (the backslash just shows up in the pdf). It seems that the same problem was encountered here

URL linebreak in footnote

but I see no answer here as well.

EDIT: I can't use hyperref. Added MWE below.

\documentclass{article}
\usepackage{ismir,amsmath,cite,url}
\usepackage{graphicx}
\usepackage{color}
\usepackage[capitalise]{cleveref}
\usepackage{array}
\usepackage{alltt}
\usepackage{fixltx2e}

\begin{document}

Some text with a footnote.\footnote{\url{https://en.wikipedia.org/wiki/Hidden_Markov_model}}

\end{document}
  • 5
    Please provide a full minimal example? Are you using hyperref or not? If not then it is a previewer problem, where the previewer is trying to interpret the contents of the PDF and attempts to parse the URL and perhaps not doing a good job. In any case it helps if you provide a full minimal example that others can copy and test as is. – daleif Jun 18 '18 at 11:56
  • 1
    Also it would be useful to have an actual working URL, so that we know when it's not working... – Phelype Oleinik Jun 18 '18 at 12:00
  • 1
    @rdv - I've posted a new answer to the query URL linebreak in footnote, to mention the use of "defined URLs" for URL strings that occur in the arguments of \footnote and similar directives. (\thanks is such a directive.) – Mico Jun 18 '18 at 13:50
  • 1
    1. What is ismir package? 2. Without hyperref the issue you see was explained by @daleif hours ago: there is no hyperlink in the PDF, and it is entirely up to the PDF viewer to detect it. I can reproduce your issue by shifting the \url so that it breaks at the underscore. – user4686 Jun 18 '18 at 17:01
  • 2
    Are you aware of the hidelinks option for hyperref? – Teepeemm Jun 18 '18 at 17:49
5

Typesetting URL strings in footnotes is known to be tricky at times. It's best to use a defined-URL macro in such cases, using the \urldef machinery of the url package.

enter image description here

Feel free to load the hyperref package as well, so that clicking on the URL string (in a suitable pdf browser, naturally) takes you to the URL in question.

\documentclass{article}
\usepackage[hyphens,spaces,obeyspaces]{url}
\urldef{\footurl}\url{http://www.example.com/somethinglong_somethingotherlong}

\begin{document}
\footnote{\footurl}  % Use a "defined-URL macro" in the argument of "\footnote"
\end{document} 
  • 1
    Tried this, but unfortunately with the same result. – rdv Jun 18 '18 at 15:21
  • 1
    @Mico, yes thanks. It does address exactly my question. – user4686 Jun 18 '18 at 19:05
  • 2
    @rdv - If you can click on URLs in your LaTeX-produced pdf file without having loaded the hyperref package, it must be because your pdf browser can recognize URLs on its own and make them "active", i.e., clickable. But that's clearly a pdf browser capability, quite separate from LaTeX and any packages which may (or may not) have been loaded. – Mico Jun 18 '18 at 19:20
  • 1
    @rdv - Do you load hyperref before or after url? (Hint: hyperref must be loaded after url.) Separately, instead of hidelinks, try colorlinks,allcolors=black. Finally, if \footurl isn't a recognized command, it's almost certainly because you didn't run the \urldef instruction exactly as I showed in my answer. – Mico Jun 19 '18 at 7:08
  • 1
    @rdv - FWIW, it's been rather difficult to figure out what you actually do. In fact, I'm quite sure that I still don't understand what's going on in your document. In retrospect, my mistake was to even attempt to provide an answer without having made you provide all relevant information. Given these failures to communicate, I'm not surprised that you weren't able to resolve the issue that led to you to post this query. Sorry. – Mico Jun 20 '18 at 1:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.