9

The problem I'm having is that urls with backslashes in the .bib file are not linking correctly.

I'm using Mendeley to generate a .bib file that gets imported and used in the references section of a document via the biblatex package.

Mendeley escapes some special characters in the url field with a backslash (so _ turns to \_). As I understand it, biblatex wants those urls without escaped characters, as is. This is most likely what's causing the problem.

So I'm figuring there isn't a clean package option that tells biblatex to do something proper with the backslashes in url fields. If there is, that would be an ideal solution to the problem.

If there's not, I was thinking of doing a for loop over the url fields within LaTeX and stripping any '\'. But I'm not yet familiar enough with LaTeX programming to do this.

2
  • The answer below is correct, but really Mendeley is in the wrong here: in the url field, no escaping should be done, biblatex or not.
    – Joseph Wright
    Commented Aug 17, 2013 at 5:29
  • @JosephWright: Maybe so, but the doi field will need to be escaped for BibTeX, whereas by default, BibLatex wants to have it unescaped (as otherwise, the escaping `` will be printed as a part of the DOI). Commented Sep 21, 2015 at 13:28

2 Answers 2

11

If biber is used as a backend the solution is to use \DeclareSourcemap to clean the url.

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url,
        match=\regexp{\\_},
        replace=\regexp{_}]
    }
  }
}
1
  • Worked perfectly. I just changed {\_}->{\}, {_}->{}, so that all backslashes are stripped. Commented Aug 16, 2013 at 20:29
0

To do it via a command line (for inclusion in other processing tool) you can do a short python script:

f=open("in.bib", "r")
for line in f:
    if "url" in line:
        print line.replace("\\_","_"),
    else:
        print line,

and launch it like this:

python filter.py > out.bib

You must log in to answer this question.

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