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}
Best Answer
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{\_}
.Addendum: I just noticed that you load the
apacite
citation management package (with the optionnatbibapa
) along with theapacite
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: