5

My reference manager escapes all underscores in URLs. I thought that was OK until I noticed it prints %5c in front of all URL underscores. How can I avoid this while still having the escaped underscores in the bib file? -- I can't change what my reference manager output, unfortunately.

MWE:

test.bib

@online{testref,
author = {Some Author},
title = {{Some Title}},
url = {http://www.example.com/some\_file.zip}
}

test.tex

\documentclass{article}
\usepackage[uniquelist=false,maxcitenames=2,backend=biber,style=authoryear,natbib=true]{biblatex}
\addbibresource{test.bib}

\begin{document}
Hello you \citep{testref}.

\printbibliography
\end{document}

Output:

enter image description here

4
  • Just type _ and not \_.
    – egreg
    Apr 5, 2014 at 20:03
  • The translation of \_ into %5C_ is done by Biber, apparently.
    – egreg
    Apr 5, 2014 at 20:10
  • @egreg I stated that it is my reference software that exports the urls with escaped underscores, not me. Therefore I cannot change it.
    – johnrl
    Apr 5, 2014 at 20:28
  • I understand, that's why I added the second comment. I'm afraid it's built in Biber. Let's see if some expert in the internals can find a solution.
    – egreg
    Apr 5, 2014 at 20:32

1 Answer 1

7

You can use the biber ability to manipulate the bib entries on the fly with \DeclareSourcemap

\documentclass{article}
\usepackage[uniquelist=false,maxcitenames=2,backend=biber,style=authoryear,natbib=true]{biblatex}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@online{testref,
author = {Some Author},
title = {{Some Title}},
url = {http://www.example.com/some\_file.zip}
}
\end{filecontents}

\DeclareSourcemap{
 \maps[datatype=bibtex]{
   \map{
     \step[fieldsource=url,
       match=\regexp{\\_},
       replace=\regexp{_}]
   }
 }
}

\addbibresource{\jobname.bib}

\begin{document}
Hello you \citep{testref}.

\printbibliography
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .