Graphics, Figures & Tablesnatbib+hyperref citation in caption image float error

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mihai_niculita
Posts: 5
Joined: Fri Sep 14, 2012 12:42 pm

natbib+hyperref citation in caption image float error

Post by mihai_niculita »

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:

Code: Select all

Extra }, or forgotten \ endgroup.

<argument> ... \IeC {\c s}i dreapta D=2.9\relax }}
                                              \hyper@linkend 
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:

Code: Select all

\documentclass[romanian]{article}
\usepackage[]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{float}
\usepackage[unicode=true,pdfusetitle,
  bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
  breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=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}
\phantomsection\addcontentsline{toc}{section}{\refname}\bibliography{D:/JURNALE/a}

\end{document}
The bib entry is:

Code: Select all

@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}
}
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

Code: Select all

\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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

natbib+hyperref citation in caption image float error

Post by cgnieder »

Hi Mihai,

Welcome to the LaTeX community!

Your MWE is not complete! It is at least missing the packages etoolbox (for \pretocmd) and natbib. Also it loads fontenc and hyperref twice. Then ucs complains that you're using »utf8« instead of »utf8x« so you should consider using \usepackage[utf8x]{inputenc}.

The issue you're asking about is fixed by using \protect in front of \cite.

Code: Select all

\caption{Suprafete fractale Brown-iene obinute cu funcia \emph{r.surf.fractal}
\protect\cite{Wood1996} din GRASS GIS: stanga - D=2.1, centru D=2.5 si dreapta D=2.9}
In a caption it is usually necessary to use robust commands since captions have moving arguments which usually means they're written to the aux file. \protect makes the \cite robust here. Alternatively (since you're loading etoolbox already) you can add

Code: Select all

\robustify\cite
to your preamble.

Regards
site moderator & package author
mihai_niculita
Posts: 5
Joined: Fri Sep 14, 2012 12:42 pm

natbib+hyperref citation in caption image float error

Post by mihai_niculita »

You are right! Using \robustify\cite works. I have duplicates because i use Lyx and I mae some settings, but then needed optimizations on them, and used TeX code as preamble.

Thank you!
Last edited by cgnieder on Fri Sep 14, 2012 2:14 pm, edited 1 time in total.
Post Reply