21

I'm trying to include a link to some code on OneDrive; the link includes an underscore, which is causing a lot of trouble.

I tried adding the entry like this:

@misc{code,
    title = {Code},
    url = {https://1drv.ms/link_link}
}

I use \usepackage{url} and \bibliographystyle{IEEEtran}. Everything compiles fine and the bibliography shows the correct entry. However, if you click the link, it opens a page at https://1drv.ms/link - so ignoring the underscore and everything after it, which leads to a wrong page. Even copy and paste from the PDF doesn't work since the underscore is copied as space, which again is a broken link.

How can I add the link such that it can be clicked and copied properly? I tried \_, \usepackage{underscore}, {{link}}, different bibtex entries but nothing worked. Also all the related questions/answers don't answer mine.

8
  • 4
    You need hyperref to get correct links. And if you are not using biblatex, then you will have to add the \url command to the bib. – Ulrike Fischer Jul 28 '17 at 11:42
  • 2
    \usepackage{hyperref} fixed it! However, I did not need \url even using bibtex; it seems like the url field in misc directly expects a URL. – CGFoX Jul 28 '17 at 12:11
  • 1
    It depends on the style. It could be that you have one that add the \url command. – Ulrike Fischer Jul 28 '17 at 12:17
  • It fixes the problem of the link being broken when you click it. However, it does not fix the other problem that the underscore is replaced by a space when copied and pasted. But I guess, that's not a problem of latex/bibtex? – CGFoX Jul 28 '17 at 12:17
  • 2
    Without a minimal example it is difficult to say, but I would guess that you are missing \usepackage[T1]{fontenc}. – Ulrike Fischer Jul 28 '17 at 12:26
21

Just to formally answer and close this question: As Ulrike Fischer answered in the comments, the solution was to use \usepackage{hyperref} (or \usepackage[hidelinks]{hyperref} to avoid the ugly boxes) and \usepackage[T1]{fontenc}. This allows properly clicking and copy-&-pasting URLs with underscores.

However, it turned out, using package hyperref wasn't allowed when trying to submit the paper to IEEE. So I ended up simply changing the URL to something without underscore using goo.gl (or bitly since goo.gl is down).

1
  • 3
    This /has/ to be the hackiest solution ever, and I love it! – inspectorG4dget May 22 '19 at 14:39
15

In case of IEEE templates, when using the file bib, replacing the underscore with {\_} should solve the problem. In the case of the question:

@misc{code,
    title = {Code},
    url = {https://1drv.ms/link{\_}link}
}
1
  • 2
    Sometimes {\_} is converted by some latex preprocessing so it will not converted properly. In these cases, try just to replace _ by \_ in the bibtex. – Agile Bean Nov 1 '20 at 7:22
0

I do not know why, but the other solutions did not work for me, this did however:

  1. Delete auxiliary files (.bbl)

  2. In the bib file, replace the url by:

    url = {{https://doi.org.123345\_6789}}

Note, the double curly braces and non arround \_.

New contributor
Nyps is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Deleting the .bbl file is always a good idea when you have a problem with the bibliography. But I'm sceptical about the second point. The double braces should normally not be any better than single braces. It will depend on your bibliography style, but usually styles that support a dedicated url field can also interface with the url or hyperref package so that they can deal with unescaped _s when you load \usepackage{hyperref} or \usepackage{url}. If at all possible I'd always prefer url = {https://doi.org.123345_6789} over escaping with backslashes. – moewe 2 days ago

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.