When I export from Mendeley to Sharelatex, some references contain url fields like this:

    title = {{Lista de contactos de los nodos de la Plataforma DRY - 15Mpedia}},
    year = {2014},
    author = {{15MPEDIA}},
    url = {https://15mpedia.org/wiki/Lista{\_}de{\_}contactos{\_}de{\_}los{\_}nodos{\_}de{\_}la{\_}Plataforma{\_}DRY}

If you see the url, instead of having _ it has {\_} which obviously breaks the link. Maybe it is a problem of Sharelatex. They told me they don't know what's happening... :-(

So, in this case, with this kind of 'urls', is there any way to correct these incorrect bib entries in order to have links working properly? For example, coding to change always {\_} to _ inside url = ... strings.


%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\captionsetup{labelfont=\rmdefault, textfont=\rmdefault }


This is the reference \cite{15MPEDIA2014}


enter image description here

  • Try simply _, without braces and backslash. – egreg Dec 9 '16 at 20:30
  • But the question is: how to make this change automatically for a lot of entries, which I am constantly updating from Mendeley, not one to one? – Juan Linares Dec 9 '16 at 20:50
  • 2
    It's a Mendeley problem, so off topic for the site, I'm afraid. – egreg Dec 9 '16 at 20:51
  • I take it you're using XeLaTeX; is switching to LuaLaTeX an option for you? – Mico Dec 9 '16 at 20:56
  • With LuaLatex the compiler is having troubles and no 'pdf' is done. A lot of errors – Juan Linares Dec 9 '16 at 21:02

Here's a LuaLaTeX-based solution. It defines a Lua function that scans all input lines -- including those in the file \jobname.bbl, which is created by BibTeX -- and looks for \url{...} strings. For every such string, all instances of {\_} within the string are replaced with _. This happens at a very early stage of processing, i.e., before LaTeX starts its usual operations.

The only input requirement is that the string containing a URL, along with its encasing macro "\url{...}`, be on one line. No linebreaks allowed.

A separate comment: You should really try to figure out how to set all Mendeley parameters. It shouldn't be that difficult to instruct Mendeley not to encase all instances of _ in a URL with {\_}.

enter image description here

    title = {{Lista de contactos de los nodos de la Plataforma DRY--\mbox{15Mpedia}}},
    year = {2014},
    author = {{15MPEDIA}},
    url = {https://15mpedia.org/wiki/Lista{\_}de{\_}contactos{\_}de{\_}los{\_}nodos{\_}de{\_}la{\_}Plataforma{\_}DRY}

%%% Lua-related code begins here
function clean_underscore ( s )
    return ( string.gsub ( s , "{\\_}" , "_" ) )
function clean_url ( s ) 
    return ( string.gsub ( s , "\\url%b{}" , clean_underscore ) )
\AtBeginDocument{\luadirect{luatexbase.add_to_callback ( 
    "process_input_buffer", clean_url, "clean_url" )}}
%%% Lua-related code ends here


\usepackage[colorlinks,urlcolor=blue]{hyperref} % just for this example


Addendum: I just noticed that you load the apacite citation management package (with the option natbibapa) along with the apacite bibliography style. Using these pieces of information, the formatted bib entry looks like this -- note that the Lua function continues to get the job done:

enter image description here

|improve this answer|||||

Just disable Escape LaTeX special characters in your Mendeley preferences.

enter image description here

Disadvantage: will fail if e.g. the title contains special characters like &.

My personal opinion: Don't use such automatically generated bib files, they are far from perfect. Instead take the entries and copy them to your own bib file. There you can clean up.

Some flaws from your automatic bib file:

  • Alexa is repeated two times in its entry
  • in dataanlysis15m: two times 2014
  • should DENZIN be in caps?
|improve this answer|||||
  • +1. I knew it shouldn't be that difficult to instruct Mendeley to do the right thing... – Mico Dec 9 '16 at 22:04
  • About DENZIN, this is other issue, I don't know wich one is better: all references names in caps or not..and how to change all of them – Juan Linares Dec 10 '16 at 14:48
  • 1
    @JuanLinares A matter of taste, but I would not do it as I find it uncomfortable to read caps. – samcarter_is_at_topanswers.xyz Dec 10 '16 at 15:47

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.