# Packages hyperref together with subfig break when \renewcommand{\thefigure}{…} is used

The following code compiles and acts as you would expect:

\documentclass[12pt]{report}

%\usepackage{hyperref}
\usepackage{subfig}

\begin{document}

\begin{figure}
\centering
\renewcommand{\thefigure}{$\dag$}
\subfloat[Sub-dagger]
{
\label{subfloat:first}
Hello there my good sport
}%
\subfloat[Sub-dagger the other]
{
Hello again nice to see you
}
\caption{Daggered figure}
\label{fig:dag}
\end{figure}

Figure \ref{fig:dag} shows two things... one of them is sub-figure \ref{subfloat:first}.

\listoffigures

\end{document}


However, when %\usepackage{hyperref} is uncommented, the following error is given:

! TeX capacity exceeded, sorry [input stack size=5000].
\curr@fontshape ->\f@encoding
/\f@family /\f@series /\f@shape
l.11 \subfloat
[Sub-dagger]
!  ==> Fatal error occurred, no output PDF file produced!


No error occurs if no subfloats are in the figure, either. The error occurs even if \listoffigures is commented out.

A remark: if $\dag$ is replaced by $a$, or by ABC, the code compiles fine. It seems like there is some issue with the amount of memory $\dag$ takes, which is strange to me.

-
Welcome to TeX.sx! A tip: You can use backticks  to mark your inline code as I did in my edit. –  doncherry Jun 11 '12 at 23:11

Instead of using subfig you could use the subcaption package:

\documentclass[12pt]{report}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{hyperref}

\begin{document}

\begin{figure}
\centering
\renewcommand{\thefigure}{$\dag$}
\subcaptionbox{First subfigure\label{subfloat:first}}{Hello there my good sport}\qquad
\subcaptionbox{Second subfigure\label{subfloat:second}}{Hello again nice to see you}
\caption{Daggered figure}
\label{fig:dag}
\end{figure}

Figure \ref{fig:dag} shows two things... one of them is sub-figure \ref{subfloat:first}.

\listoffigures

\end{document}


On a side note, except for some exceptions, hyperref should be the last package to load.

If switching to subcaption is not an option, then you can use the following:

\documentclass[12pt]{report}
\usepackage{subfig}
\usepackage{hyperref}

\makeatletter
\newcommand\specialcaption[1]{%
\@namedef{the\@captype}{#1}%
\makeatother

\begin{document}

\begin{figure}
\centering
\makeatletter
\def\p@subfigure{$\dag$}
\makeatother
\subfloat[Sub-dagger]
{%
\label{subfloat:first}
Hello there my good sport
}%
\subfloat[Sub-dagger the other]
{%
Hello again nice to see you
}
\specialcaption{$\dag$}{Daggered figure}
\label{fig:dag}
\end{figure}

Figure \ref{fig:dag} shows two things... one of them is sub-figure \ref{subfloat:first}.

\listoffigures

\end{document}


Notice the spurious blank spaces that I removed by using the % character.

-
My whole thesis is already formatted with subfig, and it is a daunting thought to go through and change all of it... do you know why this problem is happening? –  Andrey Jun 11 '12 at 23:22
@Andrey I see. Please see my updated answer for a work-around using subfig`. –  Gonzalo Medina Jun 11 '12 at 23:27
@Andrey I had initially forgotten some code; now I've corrected the example. –  Gonzalo Medina Jun 11 '12 at 23:40