# Retrieving the title of a theorem, e.g. "My name" from "Lemma 1 (My name)"

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:

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.

• Possible duplicate of tex.stackexchange.com/questions/301320/… Dec 18, 2016 at 16:25
• @DiegoDias: Even if your question might be a duplicate, please consider to accept the answer below.
– user31729
Jan 18, 2017 at 17:32

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}


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}


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".

• A shame that nobody upvoted this yet (... ;-)) Not even the O.P.!
– user31729
Jan 18, 2017 at 17:31
• Hi Clement, thanks for the answer! I noticed that my preamble includes amsthm. I didn't know that this package was being used to make the magic to happen. Thanks as well for the complement about how to make a single link, instead of two, though I haven't bother much about that :-) Jan 19, 2017 at 18:29

Here is an additional solution that uses amsthm and is indipendent from hyperref. It mimics LaTeXs built in cross-ref-routine:

\documentclass{article}
\usepackage{amsthm}
\usepackage{amssymb}

\newtheorem{law}{Law}

\makeatletter
\let\sv@law\law
\let\sv@label\label
\renewcommand\law[1][]{\sv@law[#1]\def\curr@thmname{#1}}
\renewcommand\label[1]{%
\immediate\write\@auxout{%
\noexpand\global\noexpand\@namedef{#1-thmname}{\curr@thmname}}
\sv@label{#1}
}
\newcommand\nameofthm[1]{\@nameuse{#1-thmname}}
\makeatother

\begin{document}
%Law~\ref{RTA_Ref}~(\nameofthm{RTA_Ref})
%
\begin{law}[Rely-to-Atomic]\label{RTA_Ref}
For any predicate $p$, and relations $r$ and $q$, such that $[p,q]$ tolerates interference $r$,
$\mathbf{rely}\,r\cdot[p,q]\sqsubseteq\langle p,q\rangle$
\end{law}

...

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


• That's impressive. Jan 19, 2017 at 20:47
• @Clément -- thx. I think your thmtools answer is the prefered way of doing this, tho. +1 for your answer (actually it was earlier alredy :) Jan 19, 2017 at 20:51
• This is a quite low level way of achieving that result, I am also impressed. Worth of being aware of, though I didn't fully understood the details of the solution. I also agree that Clément's answer shall continue as the preferred one, especially because people who may get to the same question would be more likely to be looking for the simplest solution. Thanks! Jan 20, 2017 at 19:15
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 2, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7614272832870483, "perplexity": 1454.5541019580319}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2022-21/segments/1652662578939.73/warc/CC-MAIN-20220525023952-20220525053952-00525.warc.gz"}