# natbib, hyperref and citation inside a float figure

I use Lyx and MikTeX 2.9 to write my thesis based on book KOMA-script. Right at the finish I have an error at pdflatex run:

Extra }, or forgotten \ endgroup.

<argument> ... \IeC {\c s}i dreapta D=2.9\relax }}
l.25 ...apta D=2.9\relax }}{32}{figure.caption.25}

I've deleted a group-closing symbol because it seems to be
spurious, as in $x}$'. But perhaps the } is legitimate and
you forgot something else, as in \hbox{$x}'. In such cases the way to recover is to insert both the forgotten and the deleted material, e.g., by typing I$}'.


Here is my code:

\documentclass[romanian]{article}
\usepackage[]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{float}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
{hyperref}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{type1ec}
\usepackage[T1]{fontenc}
\usepackage{ucs}
\usepackage{hyperref}
\makeatletter
\newcommand\bibstyle@comma{\bibpunct(),a,,}
\newcommand\bibstyle@semicolon{\bibpunct();a,,}
\makeatother
\pretocmd\citet{\citestyle{comma}}\relax\relax
\pretocmd\Citet{\citestyle{comma}}\relax\relax
\pretocmd\citep{\citestyle{semicolon}}\relax\relax
\pretocmd\Citep{\citestyle{semicolon}}\relax\relax

\makeatother

\begin{document}
\begin{figure}[H]
\begin{centering}
aaaa
\par\end{centering}

\caption{Suprafete fractale Brown-iene obinute cu funcia \emph{r.surf.fractal}
\cite{Wood1996} din GRASS GIS: stanga - D=2.1, centru D=2.5 si dreapta
D=2.9}
\end{figure}

\bibliographystyle{chicago}

\end{document}


The bib entry is:

@phdthesis{Wood1996,
author = {Wood, Jo},
booktitle = {Advances in cancer research},
file = {:D$\backslash$:/JURNALE/Bettuzzi\_2009.pdf:pdf},
issn = {0065-230X},
month = jan,
pmid = {19878769},
school = {University of Leicester},
title = {{The geomorphological characterisation of digital elevation models}},
volume = {104},
year = {1996}
}


and the a.bib file.

I use a modification of chicago bibtex style.

While the code contains a lot of optimisation, the error was in when i added the code

\newcommand\bibstyle@comma{\bibpunct(),a,,}
\newcommand\bibstyle@semicolon{\bibpunct();a,,}
\makeatother
\pretocmd\citet{\citestyle{comma}}\relax\relax
\pretocmd\Citet{\citestyle{comma}}\relax\relax
\pretocmd\citep{\citestyle{semicolon}}\relax\relax
\pretocmd\Citep{\citestyle{semicolon}}\relax\relax


This is required for me to obtain coma and colon separated citations.

The error is localized in relation to some citations included in float figure captions. I read it on the web that some times natbib and hyperref does not like each other, and indeed when I comment the code above the document compile.

Any clue regarding this issue would help! Thanks in advance!

Mihai

-
Please use a minimal working example (MWE)/ –  Guido Sep 14 '12 at 10:01
Well, I tried that, but my knowledge of LaTeX beside trowing in Lyx code, is limited. What should i include? –  mihai niculita Sep 14 '12 at 10:14
I edited for MWE. Thanks! –  mihai niculita Sep 14 '12 at 10:32

Your example is missing two pieces:

\usepackage{natbib}
\usepackage{etoolbox}


The first is to get the commands \citet and similar ones; the second provides \pretocmd. However, patching those commands in that way is wrong, as they are "robust commands".

\usepackage{xpatch}
\xpretocmd\citet{\citestyle{comma}}{}{}
\xpretocmd\Citet{\citestyle{comma}}{}{}
\xpretocmd\citep{\citestyle{semicolon}}{}{}
\xpretocmd\Citep{\citestyle{semicolon}}{}{}


so that the patches will be to the correct internal macro. You still need natbib, of course. Loading etoolbox is not necessary.

In case xpatch is not available in your TeX distribution, you can still do the correct patch:

\usepackage{etoolbox}
\expandafter\pretocmd\csname citet \endcsname{\citestyle{comma}}{}{}
`

(similarly for the other three commands).

-
Your indication with xpatch works! Natbib is missing cause I added using LyX menu, not as TeX code. Thank you! –  mihai niculita Sep 14 '12 at 12:01
@mihainiculita Please, have a read to the FAQ, particularly How to ask –  egreg Sep 14 '12 at 15:54