Referencing a theorem-like environment by its [name]

I think the following may do what you want.

\makeatletter
\def\namedlabel#1#2{\begingroup
   \def\@currentlabel{#2}%
   \label{#1}\endgroup
}
\makeatother

Then you use it as

\begin{theorem}
  \namedlabel{thm:seamus}{Seamus' Theorem}
  Here is Seamus' Theorem.
\end{theorem}

Here I reference~\ref{thm:seamus}.

Unfortunately, it can then only be referenced by name, though I suppose you could use a normal \label as well (with a different key of course).

For the amsthm environments you can use

\makeatletter
\let\@old@begintheorem=\@begintheorem
\def\@begintheorem#1#2[#3]{%
  \gdef\@thm@name{#3}%
  \@old@begintheorem{#1}{#2}[#3]%
}
\def\namedthmlabel#1{\begingroup
   \edef\@currentlabel{\@thm@name}%
   \label{#1}\endgroup
}
\makeatother

nameref doesn't work: it references the title of the SECTION the theorem-like environment appears in.

This is a nameref bug that was already fixed a while ago: http://web.archiveorange.com/archive/v/9uUx5EuqoCGynIvx3om7#lY2MJxvge2oMgOi

Unfortunately some Linux distros like Debian/Ubuntu ship with horribly old versions of the packages (Ubuntu 11.04 still ships TeX Live 2009 although the latest version is TeX Live 2011). If you're using such a Linux distro stop using the Tex Live package in the distro, and install TeX Live directly from here: http://www.tug.org/texlive/ You can then update packages using tlmgr (a really cool tool that doesn't ship with Debian/Ubuntu).


you may want to check out the nameref package, which is distributed with hyperref. There is a section in the nameref documentation about referencing "stuff".

More on referencing can be found in the TeX FAQ item Referring to things by their name.

Tags:

Latex