# nameref does not work with LLNCS

I'm trying to use the very practicle nameref package with lncs (sty file downloaded here). Unfortunately, instead of displaying the actual name of the definition, it displays the name of last section. Any idea why?

\documentclass{llncs}
%\documentclass{article} %% <== works with article/below definitions
%% Already defined in LLNCS
% \usepackage{amssymb, amsthm, amsmath}
% \newtheorem{definition}{Definition}
\providecommand*\definitionautorefname{Definition}

\usepackage{nameref}
\usepackage{hyperref}

\begin{document}

\section{The name of the section}

\begin{definition}[Nice name for my definition]\label{def:propertiesF}
I am a nice definition with a nice name
\end{definition}

\section{Use of nameref}

The following nameref should display Nice name for my definition''. But the display is \nameref{def:propertiesF}.
\end{document}


## 1 Answer

The llncs class defines theorem-like environments with \spnewtheorem and nameref is unable to hook into them as it does when amsthm (or the vanilla LaTeX \newtheorem).

You have to make a hook yourself.

\documentclass{llncs}

\providecommand*\definitionautorefname{Definition}

\usepackage{nameref}
\usepackage{hyperref}

\makeatletter
\let\ORIGINAL@spythm\@spythm
\def\@spythm#1#2#3#4[#5]{%
\NR@gettitle{#5}%
\ORIGINAL@spythm{#1}{#2}{#3}{#4}[#5]%
}
\makeatother

\begin{document}

\section{The name of the section}

\begin{definition}[Nice name for my definition]\label{def:propertiesF}
I am a nice definition with a nice name
\end{definition}

\section{Use of nameref}

The following nameref should display Nice name for my definition''.
And it does: \nameref{def:propertiesF}.

\end{document}