5

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

@misc{15MPEDIA2014,
    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.

MWE:

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

\documentclass{DissertateB5}
\captionsetup{labelfont=\rmdefault, textfont=\rmdefault }
\usepackage[natbibapa]{apacite}
\bibliographystyle{apacite}

\begin{document}

This is the reference \cite{15MPEDIA2014}

\end{document}

enter image description here

6
  • Try simply _, without braces and backslash.
    – egreg
    Dec 9, 2016 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? Dec 9, 2016 at 20:50
  • 2
    It's a Mendeley problem, so off topic for the site, I'm afraid.
    – egreg
    Dec 9, 2016 at 20:51
  • I take it you're using XeLaTeX; is switching to LuaLaTeX an option for you?
    – Mico
    Dec 9, 2016 at 20:56
  • With LuaLatex the compiler is having troubles and no 'pdf' is done. A lot of errors Dec 9, 2016 at 21:02

2 Answers 2

6

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

\RequirePackage{filecontents}
\begin{filecontents}{mybib.bib}
@misc{15MPEDIA2014,
    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}
}
\end{filecontents}

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

\usepackage{natbib}
\bibliographystyle{plainnat}

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

\begin{document}
\nocite{*}
\bibliography{mybib}
\end{document}

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

7

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?
3
  • +1. I knew it shouldn't be that difficult to instruct Mendeley to do the right thing...
    – Mico
    Dec 9, 2016 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 Dec 10, 2016 at 14:48
  • 1
    @JuanLinares A matter of taste, but I would not do it as I find it uncomfortable to read caps. Dec 10, 2016 at 15:47

You must log in to answer this question.

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