LaTeX forum ⇒ BibTeX, biblatex and biberUnderscore 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

Postby esong_98 » Sun Jan 19, 2014 1:35 am

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:

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


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:

  1. \usepackage{url}


Then I type:

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


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

  1. \newcommand\typopath{EconEpsilon}
  2. \documentclass[12pt,a4paper,english,fleqn]{article}
  3. \usepackage{mathptmx}
  4. \usepackage[scaled=0.86]{helvet}
  5. \renewcommand{\familydefault}{\rmdefault}
  6. \usepackage[T1]{fontenc}
  7. \usepackage[utf8]{inputenc}
  8. \usepackage{fancyhdr}
  9. \pagestyle{fancy}
  10. \setcounter{secnumdepth}{2}
  11. \usepackage{graphicx}
  12. \usepackage[authoryear]{natbib}
  13. %Define EconEJ colors
  14. \usepackage{xcolor}
  15. \definecolor{EconomicsGray}{RGB}{198,212,225}
  16. \definecolor{EconomicsLightBlue}{RGB}{127,191,192}
  17. \definecolor{EconomicsBlue}{RGB}{0,63,138}
  18. \definecolor{EconomicsDarkBlue}{RGB}{0,63,117}
  19.  
  20. % You need this for the headers:
  21. \usepackage{graphicx}
  22.  
  23. % Headers and footers for Economics E-Journal
  24. \fancyhf{}
  25. \fancyhead[C]{{{\raisebox{-1.5pt}{\includegraphics[scale=.05]{EconEpsilon}}}\hspace{-.2ex}\small{\hskip -1pt\textcolor{EconomicsDarkBlue}{\textsf{\textbf{Economics}\textmd{~Discussion~Paper}}}}}}
  26.  
  27. \renewcommand\headrulewidth{0pt}
  28. \renewcommand\headheight{17pt}
  29.  
  30. \fancyfoot[R]{{\small \sf\thepage}}
  31. \fancyfoot[L]{{\small\sf{{www.economics-ejournal.org}}}}
  32.  
  33. % Caption formatting
  34. \usepackage[font=footnotesize,labelfont=bf]{caption}
  35.  
  36.  
  37. % Reduce font size for section
  38. \makeatletter
  39. \renewcommand\section{\@startsection{section}{1}{\z@}
  40. {-5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus.2ex}{\normalfont\large\bf}}
  41.  
  42. %Reduce font size for subsection
  43. \renewcommand\subsection{\@startsection{subsection}{2}
  44. {\z@}{-3.25ex\@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}{\normalfont\bf}}
  45.  
  46.  
  47. % Enforce proper line breaks and avoid widows and orphans
  48. \tolerance 1414
  49. \hbadness 1414
  50. \emergencystretch 1.5em
  51. \hfuzz 0.3pt
  52. \widowpenalty = 10000
  53. \clubpenalty=10000
  54. \vfuzz \hfuzz
  55. \raggedbottom
  56. % Format footnotes
  57.  
  58. % Footnote formatting
  59. \usepackage[hang]{footmisc}
  60. \renewcommand{\hangfootparindent}{1em}
  61. \renewcommand{\hangfootparskip}{0em}
  62. \renewcommand{\footnotemargin}{0.00001pt}
  63. \def\footnotelayout{\hspace{1em}}%
  64.  
  65. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  66.  
  67. % Place your own additions to the preable HERE, that is, BEFORE the following
  68. % call to hyperref
  69.  
  70. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  71.  
  72. %Hyperlink settings for linkcolors and initial view
  73. \usepackage[%
  74. colorlinks=true,%
  75. linkcolor=black,%
  76. citecolor=black,%
  77. urlcolor=EconomicsDarkBlue,%
  78. pdfstartview=FitH,%
  79. pdfview=FitH,%
  80. pdfpagemode=UseNone]{hyperref}
  81. \hypersetup{pdftitle={Economics: The Open Access, Open Assessment E-Journal}}
  82.  
  83. % Define font for hyperlinks
  84. \def\UrlFont{\normalfont}
  85.  
  86. % Some fine-tuning of layout
  87. \usepackage{microtype}
  88.  
  89. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  90.  
  91. % Put your additions to the preable above the call to hyperref, not here, unless you
  92. % want to modify hyperref settings, as is the case with the precvious two commands
  93.  
  94. \@ifundefined{showcaptionsetup}{}{%
  95. \PassOptionsToPackage{caption=false}{subfig}}
  96. \usepackage{subfig}
  97. \AtBeginDocument{
  98. \def\labelitemi{\tiny\(\bullet\)}
  99. }
  100. \makeindex
  101. \makeatother
  102. \usepackage{babel}
  103. \usepackage{graphicx}
  104. \usepackage{setspace}
Last edited by Stefan Kottwitz on Sun Jan 19, 2014 6:21 pm, edited 1 time in total.
Reason: code marked

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 9157
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sun Jan 19, 2014 6:24 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
Site admin

Orange_Rubber_Band
Posts: 1
Joined: Sun Jul 15, 2018 6:13 pm

Postby Orange_Rubber_Band » Sun Jul 15, 2018 6:24 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:

  1. 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...


Return to “BibTeX, biblatex and biber”

Who is online

Users browsing this forum: No registered users and 5 guests