This is my first question here, so apologies if I miss any conventions.

I'm writing a dissertation in LaTeX. My sources are in Mendeley, which is generating a BibTeX file. I'm using the natbib package with the plainnat style.

The first problem that I faced with this was that most of the URLs in the bibliography went off the edge of the page because TeX didn't know how to linebreak them. The natbib documentation suggested that if the url package was loaded, this would Just Work. It mostly did, but it left me with a more subtle problem:

With the url package loaded, URLs are treated similarly to \verb environments - in particular, it is no longer necessary to escape special characters such as _. This means that I have two options:

  1. I can turn on the Mendeley option that escapes special characters in its BibTeX export. This means that my printed URLs contain things like url\_with\_underscore.
  2. I can turn off that Mendeley option so that it doesn't escape the special characters. This means that all the other fields in the bibliography have trouble (e.g. & characters getting lost as they're not escaped).

So, ways that occur to me to go about fixing this: (a) Find a way to stop the url package from treating things like \_ as verbatim (b) Find a different way to get URLs to linebreak in the bibliography (c) Manually edit my .bib file before compiling for the last time, removing escapes from URLs.

I would really love to not do (c) ;-) Any ideas?

3 Answers 3


I'm using biber to automatically remove the escapes (the option (c) in the question, which I seem unable to avoid) as follows:

biber --tool library.bib

and a biber.conf with the following simple regex map:

    <map_step map_field_source="url" map_match="\\" map_replace="" />

Not ideal, but until Mendeley starts providing the option to not LaTeX-escape for the URL field in particular (or at least make it optional), it will do. See also the Mendeley bug report.

  • 1
    That's a good idea - and it could be incorporated into a makefile or similar to automate the process. I'm not using Mendeley any more, but if I were, then I'd definitely persue this route!
    – Flyto
    Jul 15, 2014 at 8:59
  • Could you please write me how to modify your code to change $\sim$ to ~? I tried map_match="$\sim$" map_replace="~" without success. Mendeley really causes so many problems that could be easily fixed.
    – wondering
    May 31, 2015 at 11:31
  • You should check the biber documentation for things like the regex syntax. I expect you'll need to escape the backslash character, for example. Maybe "$\\sim$".
    – npdoty
    Jun 1, 2015 at 15:07
  • This doesn't work any more. After adding the lines in the ~/.biber.conf I get this error "Not a HASH reference at /usr/share/perl5/Biber/Config.pm line 590"
    – lefterav
    Oct 14, 2020 at 19:26

Not sure if it helps regarding your URL problem but you should give biblatex+biber a try:


Works for me, not escaping anything, using a bibfile exported from Mendeley. URLs are broken nicely even if they contain characters like :: or - or ; or # or & or _


Using the hyperref package instead of url removed the escapes and gave better overall results for me:

  • It works for me perfectly. Thanks a lot. Aug 24, 2021 at 6:29

You must log in to answer this question.

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