# 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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9634233117103577, "perplexity": 11152.21417733448}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-42/segments/1414119658961.52/warc/CC-MAIN-20141024030058-00055-ip-10-16-133-185.ec2.internal.warc.gz"}