[Tex/LaTex] Unwanted extra space after hyperlink with biblatex

biblatexhyperrefspacing

I am using biblatex for my references, and I found the chem-angew style which I appreciate very much.

I found out how to add an hypertext link under the journal title, and it works fine.
But there is one slight problem: I do not know how to remove the extra space caused by the hypertext link (if I remove the hyperlink, the extra space disappears).
Note that if the link is followed by a comma, there is no problem… But in the chem-angew style, there is no comma between the journal title and the year. And I want the hypertext link to be under the journal title.

Does anyone know what to do?
Do I have to define completely my own biblatex style?

Here is my code:

\documentclass{book}

\usepackage[backend=biber,
        style=chem-angew,
        firstinits=true,
        maxbibnames=99]{biblatex}
\renewbibmacro{in:}{}
\addbibresource{library2.bib}

\usepackage{hyperref}
\hypersetup{urlcolor=black, colorlinks=true}

%*************Hyperlink on title****************
\newbibmacro{string+doiurlisbn}[1]{%
  \iffieldundef{doi}{%
    \iffieldundef{url}{%
      \iffieldundef{isbn}{%
        \iffieldundef{issn}{%
          #1%
         }{%
          \href{http://books.google.com/books?vid=ISSN\thefield{issn}}{#1}%
        }%
      }{%
        \href{http://books.google.com/books?vid=ISBN\thefield{isbn}}{#1}%
      }%
     }{%
      \href{\thefield{url}}{#1}%
    }%
  }{%
    \href{http://dx.doi.org/\thefield{doi}}{#1}%
  }%
}
\DeclareFieldFormat[article]{journaltitle}%
    {\usebibmacro{string+doiurlisbn}% 
    {\mkbibemph{#1}}%
    }
\DeclareFieldFormat[manual]{title}%
    {\usebibmacro{string+doiurlisbn} 
    {\mkbibemph{#1}}
    }
\begin{document}
I really wonder why there is an extra space in the bibliography \cite{Bocquet2010}!
I wish I could erase it \cite{Nicholls2012}. 
However, it depends on what type of document you cite \cite{Palacci2010}.
\label{Bibliography}
\printbibliography
\end{document}  

And here is the .bib:

@article{Bocquet2010,
author = {Bocquet, Lyd\'{e}ric and Charlaix, Elisabeth},
doi = {10.1039/B909366B},
journal = {Chemical Society Reviews},
number = {3},
pages = {1073--1095},
title = {{Nanofluidics, from bulk to interfaces.}},
url = {http://www.ncbi.nlm.nih.gov/pubmed/20179826},
volume = {39},
year = {2010}
}
@article{Nicholls2012,
author = {Nicholls, William D. and Borg, Matthew K. and Lockerby, Duncan A. and Reese, Jason M.},
doi = {10.1007/s10404-011-0869-3},
journal = {Microfluidics and Nanofluidics},
number = {1-4},
pages = {257--264},
title = {{Water transport through (7,7) carbon nanotubes of different lengths using molecular dynamics}},
url = {http://dx.doi.org/10.1007/s10404-011-0869-3},
volume = {12},
year = {2012}
}
@manual{Palacci2010,
author = {Palacci, J\'{e}r\'{e}mie},
organization = {Universit\'{e} Claude-Bernard},
title = {{Manipulation of colloids by osmotic forces}},
url = {https://tel.archives-ouvertes.fr/tel-00597477/fr/},
type = {phdthesis},
urldate = {09-22-2015},
location = {Lyon, France},
year = {2010}
}

And finally here is what I get with this code:
enter image description here

Thanks a lot to whom may take some time to answer.

Best Answer

Joseph Wright has just fixed the issue properly.


This is due to the special field format removecomma used in \renewbibmacro*{journal} and defined as \DeclareFieldFormat{removecomma}{\mkbibnocomma{#1}}.

Specifically, the space is introduced by the \scantokens command in

\newcommand*\mkbibnocomma[1]{%
  \begingroup
    \catcode`\, = 9\relax
    \scantokens{#1}%
  \endgroup
}

Refer also to @egreg's answer to Could someone further elucidate expansion, catcodes, and scantokens…?

Normally that space is eaten up by \unspaces that are issued by the punctuation commands, but once the space is inside the hyperref command it seems to late.

A temporary redefinition is

\renewcommand*\mkbibnocomma[1]{%
  \begingroup
    \catcode`\, = 9\relax
    \scantokens{#1\empty}%
  \endgroup
}

We get the correct output.

MWE

\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber,
        style=chem-angew,
        firstinits=true,
        maxbibnames=99]{biblatex}
\renewbibmacro{in:}{}
\begin{filecontents*}{\jobname.bib}
@article{Bocquet2010,
author = {Bocquet, Lyd\'{e}ric and Charlaix, Elisabeth},
doi = {10.1039/B909366B},
journal = {Chemical Society Reviews},
number = {3},
pages = {1073--1095},
title = {{Nanofluidics, from bulk to interfaces.}},
url = {http://www.ncbi.nlm.nih.gov/pubmed/20179826},
volume = {39},
year = {2010}
}
@article{Nicholls2012,
author = {Nicholls, William D. and Borg, Matthew K. and Lockerby, Duncan A. and Reese, Jason M.},
doi = {10.1007/s10404-011-0869-3},
journal = {Microfluidics and Nanofluidics},
number = {1-4},
pages = {257--264},
title = {{Water transport through (7,7) carbon nanotubes of different lengths using molecular dynamics}},
url = {http://dx.doi.org/10.1007/s10404-011-0869-3},
volume = {12},
year = {2012}
}
@manual{Palacci2010,
author = {Palacci, J\'{e}r\'{e}mie},
organization = {Universit\'{e} Claude-Bernard},
title = {{Manipulation of colloids by osmotic forces}},
url = {https://tel.archives-ouvertes.fr/tel-00597477/fr/},
type = {phdthesis},
urldate = {2015-09-22},
location = {Lyon, France},
year = {2010}
}
\end{filecontents*}


\addbibresource{\jobname.bib}

\usepackage{hyperref}

%*************Hyperlink on title****************
\newbibmacro{string+doiurlisbn}[1]{%
  \iffieldundef{doi}{%
    \iffieldundef{url}{%
      \iffieldundef{isbn}{%
        \iffieldundef{issn}{%
          #1%
         }{%
          \href{http://books.google.com/books?vid=ISSN\thefield{issn}}{#1}%
        }%
      }{%
        \href{http://books.google.com/books?vid=ISBN\thefield{isbn}}{#1}%
      }%
     }{%
      \href{\thefield{url}}{#1}%
    }%
  }{%
    \href{http://dx.doi.org/\thefield{doi}}{#1}%
  }%
}
\DeclareFieldFormat[article]{journaltitle}%
    {\usebibmacro{string+doiurlisbn}% 
    {\mkbibemph{#1}}}
\DeclareFieldFormat[manual]{title}%
    {\usebibmacro{string+doiurlisbn} 
    {\mkbibemph{#1}}}

\renewcommand*\mkbibnocomma[1]{%
  \begingroup
    \catcode`\, = 9\relax
    \scantokens{#1\empty}%
  \endgroup
}

\begin{document}
I really wonder why there is an extra space in the bibliography \cite{Bocquet2010}!
I wish I could erase it \cite{Nicholls2012}. 
However, it depends on what type of document you cite \cite{Palacci2010}.
\label{Bibliography}
\printbibliography
\end{document}  
Related Question