# biblatex, hyperref and punctuation issue

And a little bit more biblatex stuff: I've noticed that, when using hyperref, there is an issue in form of an ugly space between the citation and the punctuation (be it comma or period). Please, take a look at the following example code:

\begin{filecontents}{mybib.bib}
@book{JSmith,
author = {Smith, John},
title = {A book of}
}
\end{filecontents}

\documentclass{article}

\usepackage[style=authortitle]{biblatex}
\bibliography{mybib.bib}

\begin{document}
Test~\cite*{JSmith}. Test~\footcite{JSmith}

Test~\emph{A book of}. Test\footnote{Smith, \emph{A book of}.}
\end{document}


Any ideas?

I'll keep them both in sync.

EDIT 2: Heiko Oberdiek kindly provided the answer "why" this happens (on comp.text.tex):

\cite* uses \emph and \emph suppresses the italic correction at the right end if a comma or period follows (\nocorrlist). However adding a link implies that whatits are added in between (in case of hpdftex.def there are two whatits, the end of the link and restoring the color. Therefore the period is hidden from \emph.

Example without biblatex:

\documentclass[12pt]{article}
\showboxdepth=\maxdimen

\begin{document}
\section{Foo}\label{sec:foo}
\huge
\noindent
Test~\emph{Smith of}.\\
Test~\hyperref[sec:foo]{\emph{Smith of}}.

\tracingonline=1
\showlists
\end{document}


EDIT 3: Ulrike Fischer proposed a local fix:

You can locally reset the definition of \citetitle (if you do it globally it will perhaps remove the italic correction also in places where you want it):

{\DeclareFieldFormat{citetitle}{\mkbibemph{#1\nocorr}}\cite*{JSmith}.}

-
Does this still happen if you include all the mandatory fields for the book class? (i.e. publisher and year, I think...) –  Seamus Dec 12 '10 at 17:00
author, title, year/date. Yes, it happens no matter what fields are present. –  Meho R. Dec 12 '10 at 22:29
In case somebody on the comp.text.tex group gives you a good enough answer before anybody here can, would you mind posting it here as well? We try to have complete answers to the questions here instead of simply linking to them, in case those links become dead one day. –  Martin Tapankov Dec 13 '10 at 12:27
No worries, I'll sync them: everything that comes in there will arrive here too and vice versa. –  Meho R. Dec 13 '10 at 14:38

I got a response from Philipp Lehman on comp.text.tex:

meho_r wrote:

So, what can we (users) do about it?

Not much, I'm afraid, short of manual workarounds.

\emph and friends use a rather simple look-ahead routine to decide whether or not italic correction is required. A simple \relax will confuse it. Compare this:

\emph{of}.
\emph{of}\relax.


Once the italic correction has been added, all you can do is remove it manually. It's a \kern, hence you may use \unkern:

\emph{of}\relax\unkern.


In fact, biblatex does precisely that automatically. If you comment out hyperref, your example will be fine.

Unfortunately, this won't work if the text in italics is a link while the punctuation is not part of the link:

\href{http://www.foobar.com}{\emph{of}}.
\href{http://www.foobar.com}{\emph{of}}\unkern.


The \unkern kicks in too late. It would need to move inside the link group to do its job:

\href{http://www.foobar.com}{\emph{of}\unkern}.


Trouble is: you need to remove the italic correction inside the link group but you don't know if you need to remove it until after the link.

I don't see any way to deal with that automatically. These are potentially deeply nested structures. There could be dozens of tokens and multiple groups between the end of the link and the punctuation.

You can either disable links (hyperref=false) or set up a special \cite command with a decicated format definition suppressing the italic correction. So, along the lines of what Ulrike has suggested, here's my take:

\DeclareFieldFormat{nocorremph}{\mkbibemph{#1\nocorr}}
\newrobustcmd{\nccite}{%
\AtNextCite{\DeclareFieldAlias{citetitle}{nocorremph}}
\cite}


Now compare:

\cite*{JSmith}.
\nccite*{JSmith}.


Not nice, but it works.

-