[Tex/LaTex] Retrieving the title of a theorem, e.g. “My name” from “Lemma 1 (My name)”

cross-referencingntheoremtheorems

How can I retrieve the name of a theorem?

I know how to refer to theorems using labels and take the responsibility of giving the title "Theorem" or "Lemma" myself. I also know that packages such as ntheorem can go further, and put the name "Theorem" or "Lemma" and then keep the consistency for me. However, I could not find a package that allows me to define a theorem and recover its title.

For example, take the following snippet:

\begin{theorem}[Rely-to-Atomic] For any predicate @{term "p"}, and relations @{term "r"}
and @{term "q"}, such that @{term "❙[p,q❙]"} tolerates interference @{term "r"},
\begin{IEEEeqnarray*}{c}
@{thm (concl) Law_7_4_Rely_To_Atomic_Ref}
\end{IEEEeqnarray*}\label{RTA_Ref}
\end{theorem}

After the system processing the funny quotations within @ blocks, this generates the corresponding latex and compiles to:

enter image description here

What I want is a way of retrieving the string "Rely-to-Atomic" from the label RTA_Ref. If I have that, I can reference theorems including the title for the convenience of my reader. For example, by typing:

Law~\ref{RTA_Ref}~(\nameofthm{RTA_Ref}) 

To obtain:

Law 3.95 (Rely-to-Atomic)

Since I know that some packages are able to provide a table of theorems, I believe that there should be a way of accessing the title of a theorem or then a package that fits this purpose.

Best Answer

The thmtools package allows to do that easily:

\documentclass{article}
\usepackage{hyperref}
\usepackage{thmtools}
\declaretheorem{Theorem}
\begin{document}

\begin{Theorem}[My Theorem]\label{thm}
  $1 + 3 = 4$
\end{Theorem}

As we saw in Theorem~\ref{thm} (\nameref{thm})

\end{document}

Referring to the Theorem by its name

You can obtain the same using amsthm:

\documentclass{article}
\usepackage{hyperref}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\begin{document}

\begin{thm}[My Theorem]\label{thm}
  $1 + 3 = 4$
\end{thm}

As we saw in Theorem~\ref{thm} (\nameref{thm})

\end{document}

Finally, if you want to have a signle link instead of two, you can use the following:

\documentclass{article}
\usepackage{hyperref}
\usepackage{thmtools}
\declaretheorem{Theorem}

\begin{document}

\begin{Theorem}[My Theorem]\label{thm}
  $1 + 3 = 4$
\end{Theorem}

As we saw in \hyperref[thm]{Theorem~\ref*{thm} (\nameref*{thm})}.

\end{document}

The same, with a single link.

And if you don't want any link, just use \nameref*{thm}.

I guess you'll be able to adapt the code to print "Law" instead of "Theorem".