## LaTeX forum ⇒ BibTeX, biblatex and biber ⇒ Underscore in URL

Information and discussion about BiBTeX - the bibliography tool for LaTeX documents.
esong_98
Posts: 16
Joined: Tue Jan 14, 2014 9:34 am

### Underscore in URL

I am constructing in TXC a reference list in a file called Mybib.bib. For the most part, the references are showing up fine in the output without error, except for references that have an underscore in the url. Specifically, I have been using this code:

@unpublished{Bayraktar11,         author = " Bayraktar, Erhan ... ",         title = "Minimizing the Probability of...",         note = "preprint (2011), available at          \texttt{http://www.academia.edu/275940/Minimizing_the_Lifetime_Shortfall_or_Shortfall_at_Death}"}

Unfortunately, the program makes the next letter after the underscore a subscript - although the formatting is otherwise correct and doesn't run off the page in the output. I've tried to solve this problem by making all underscores \_. Unfortunately, the computer doesn't like this, too and that just makes the compiler quit before the references can be printed. I've also tried putting this in my preamble after the \usepackage{setspace} shown below:

\usepackage{url}

Then I type:

@unpublished{Bayraktar11,         author = " Bayraktar, Erhan ... ",         title = "Minimizing the Probability of...",         note = "preprint (2011), available at          \url{\texttt{http://www.academia.edu/275940/Minimizing_the_Lifetime_Shortfall_or_Shortfall_at_Death}}"}

This solves the problem of printing the underscore correctly, but now the citation runs off the page in the output and the font and style is off.

Does anyone have any other ideas? I could just drop the citation since this is an unpublished manuscript. But I would still like to see a solution offered for future purposes.

By the way, my preamble looks like this (if it helps):

Last edited by Stefan Kottwitz on Sun Jan 19, 2014 6:21 pm, edited 1 time in total.
Reason: code marked

Tags:

Stefan Kottwitz
Posts: 9157
Joined: Mon Mar 10, 2008 9:44 pm
Remove \texttt{} within \url. The latter already produces typewriter text. URLs will be broken at certain places, not all places are allowed to keep it readable, because a link should be exact. See url manual. Where should a breakpoint be?

Stefan

Orange_Rubber_Band
Posts: 1
Joined: Sun Jul 15, 2018 6:13 pm
I had this problem and solved it. The bib file that my reference manager created substituted {\_} whenever it saw an underscore. So Missing_Link became Missing{\_}Link. Latex didn't like this and ruined my bibliography - it inserted a 7B%5C_%7D string instead.

My solution was to run a bash script on the bib file before I ran Latex; the script contained this line:

sed -i 's/{\\_}/_/g' library.bib

Where my bib file was called library.bib. This removed the {\_} and replaced with an underscore.

My reference manager (Mendeley) would overwrite the bib file with the erroneous version everytime it ran, but this wasn't a problem as I had automated the process of running the bash script (I ran it from within vim and it also did some other functions like backing up the previous version and running a word count).

Hope this helps. Eight years too late mind you...