BibTeX, biblatex and biberUnderscore in URL

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

Underscore in URL

Post by esong_98 »

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:

Code: Select all

@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:

Code: Select all

\usepackage{url}
Then I type:

Code: Select all

@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):

Code: Select all

\newcommand\typopath{EconEpsilon}
\documentclass[12pt,a4paper,english,fleqn]{article}
\usepackage{mathptmx}
\usepackage[scaled=0.86]{helvet}
\renewcommand{\familydefault}{\rmdefault}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setcounter{secnumdepth}{2}
\usepackage{graphicx}
\usepackage[authoryear]{natbib}
%Define EconEJ colors
\usepackage{xcolor}
\definecolor{EconomicsGray}{RGB}{198,212,225}
\definecolor{EconomicsLightBlue}{RGB}{127,191,192}
\definecolor{EconomicsBlue}{RGB}{0,63,138}
\definecolor{EconomicsDarkBlue}{RGB}{0,63,117}

% You need this for the headers:
\usepackage{graphicx}

% Headers and footers for Economics E-Journal
\fancyhf{}
\fancyhead[C]{{{\raisebox{-1.5pt}{\includegraphics[scale=.05]{EconEpsilon}}}\hspace{-.2ex}\small{\hskip -1pt\textcolor{EconomicsDarkBlue}{\textsf{\textbf{Economics}\textmd{~Discussion~Paper}}}}}}

\renewcommand\headrulewidth{0pt}
\renewcommand\headheight{17pt}

\fancyfoot[R]{{\small \sf\thepage}}
\fancyfoot[L]{{\small\sf{{www.economics-ejournal.org}}}}

% Caption formatting
\usepackage[font=footnotesize,labelfont=bf]{caption}


% Reduce font size for section
\makeatletter
\renewcommand\section{\@startsection{section}{1}{\z@}
{-5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus.2ex}{\normalfont\large\bf}}

%Reduce font size for subsection
\renewcommand\subsection{\@startsection{subsection}{2}
{\z@}{-3.25ex\@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}{\normalfont\bf}}


% Enforce proper line breaks and avoid widows and orphans
\tolerance 1414
\hbadness 1414
\emergencystretch 1.5em
\hfuzz 0.3pt
\widowpenalty = 10000
\clubpenalty=10000
\vfuzz \hfuzz
\raggedbottom
% Format footnotes

% Footnote formatting
\usepackage[hang]{footmisc}
\renewcommand{\hangfootparindent}{1em}
\renewcommand{\hangfootparskip}{0em}
\renewcommand{\footnotemargin}{0.00001pt}
\def\footnotelayout{\hspace{1em}}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Place your own additions to the preable HERE, that is, BEFORE the following
% call to hyperref

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Hyperlink settings for linkcolors and initial view
\usepackage[%
colorlinks=true,%
linkcolor=black,%
citecolor=black,%
urlcolor=EconomicsDarkBlue,%
pdfstartview=FitH,%
pdfview=FitH,%
pdfpagemode=UseNone]{hyperref}
\hypersetup{pdftitle={Economics: The Open Access, Open Assessment E-Journal}}

% Define font for hyperlinks
\def\UrlFont{\normalfont}

% Some fine-tuning of layout
\usepackage{microtype}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Put your additions to the preable above the call to hyperref, not here, unless you
% want to modify hyperref settings, as is the case with the precvious two commands

\@ifundefined{showcaptionsetup}{}{%
 \PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\AtBeginDocument{
  \def\labelitemi{\tiny\(\bullet\)}
}
\makeindex
\makeatother
\usepackage{babel}
\usepackage{graphicx}
\usepackage{setspace}
Last edited by Stefan Kottwitz on Sun Jan 19, 2014 6:21 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Underscore in URL

Post by Stefan Kottwitz »

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
LaTeX.org admin
Orange_Rubber_Band
Posts: 1
Joined: Sun Jul 15, 2018 6:13 pm

Underscore in URL

Post by Orange_Rubber_Band »

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:

Code: Select all

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...
Post Reply