8

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.

  • 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 Aug 17 '13 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). – O. R. Mapper Sep 21 '15 at 13:28
10

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{_}]
    }
  }
}
  • Worked perfectly. I just changed {\_}->{\}, {_}->{}, so that all backslashes are stripped. – Clayton Stanley Aug 16 '13 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.